@focus.matters/diagrams 0.1.1 → 0.2.1
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/dist/{DirectedPoint-BcpEj8ub.js → DirectedPoint-BSGh_PUt.js} +2 -2
- package/dist/DirectedPoint-BSGh_PUt.js.map +1 -0
- package/dist/diagrams.css +1 -1
- package/dist/index-y4Eon_hl.js +16196 -0
- package/dist/{index-hTkL5cDr.js.map → index-y4Eon_hl.js.map} +1 -1
- package/dist/index.es.js +25 -8
- package/dist/index.umd.js +5 -5
- package/dist/index.umd.js.map +1 -1
- package/dist/src/Diagrams/components/objects/RenderEdge/EdgeMidpoints.d.ts +2 -1
- package/dist/src/Diagrams/context-menu/buildDiagramContextMenu.d.ts +1 -0
- package/dist/src/Diagrams/custom/bpmn/config/BPMNLabels.d.ts +1 -1
- package/dist/src/Diagrams/custom/bpmn/extensions/BPMNModelerExtension.d.ts +14 -1
- package/dist/src/Diagrams/custom/bpmn/nodes/BPMNEventDefinition.d.ts +11 -2
- package/dist/src/Diagrams/custom/bpmn/nodes/DocumentNode.d.ts +75 -1
- package/dist/src/Diagrams/custom/bpmn/nodes/GateNode.d.ts +2 -1
- package/dist/src/Diagrams/custom/bpmn/nodes/TaskNode.d.ts +16 -0
- package/dist/src/Diagrams/custom/bpmn/ui/BPMNElementMenu.d.ts +2 -1
- package/dist/src/Diagrams/custom/bpmn/ui/BPMNIcon.d.ts +1 -1
- package/dist/src/Diagrams/custom/bpmn/ui/BPMNPropertiesPanel.d.ts +11 -1
- package/dist/src/Diagrams/custom/bpmnExecution/BPMNExecutionDiagram.d.ts +30 -0
- package/dist/src/Diagrams/custom/bpmnExecution/BPMNExecutionEdge.d.ts +67 -0
- package/dist/src/Diagrams/custom/bpmnExecution/BPMNExecutionExtension.d.ts +9 -0
- package/dist/src/Diagrams/custom/bpmnExecution/BPMNExecutionMarker.d.ts +12 -0
- package/dist/src/Diagrams/custom/bpmnExecution/BPMNNodeExecutionState.d.ts +27 -0
- package/dist/src/Diagrams/custom/bpmnExecution/isBPMNExecutionNode.d.ts +7 -0
- package/dist/src/Diagrams/custom/bpmnExecution/nodes/BPMNExecutionBlackBoxPoolNode.d.ts +70 -0
- package/dist/src/Diagrams/custom/bpmnExecution/nodes/BPMNExecutionDataStoreNode.d.ts +70 -0
- package/dist/src/Diagrams/custom/bpmnExecution/nodes/BPMNExecutionDocumentAnnotationNode.d.ts +70 -0
- package/dist/src/Diagrams/custom/bpmnExecution/nodes/BPMNExecutionDocumentNode.d.ts +71 -0
- package/dist/src/Diagrams/custom/bpmnExecution/nodes/BPMNExecutionEventNode.d.ts +81 -0
- package/dist/src/Diagrams/custom/bpmnExecution/nodes/BPMNExecutionGateNode.d.ts +71 -0
- package/dist/src/Diagrams/custom/bpmnExecution/nodes/BPMNExecutionLanes.d.ts +14 -0
- package/dist/src/Diagrams/custom/bpmnExecution/nodes/BPMNExecutionTaskNode.d.ts +76 -0
- package/dist/src/Diagrams/custom/bpmnExecution/nodes/BPMNExecutionTextAnnotationNode.d.ts +70 -0
- package/dist/src/Diagrams/custom/bpmnExecution/nodes/BPMNExecutionUnknownNode.d.ts +71 -0
- package/dist/src/Diagrams/custom/bpmnExecution/promoteBPMNExecutionEdge.d.ts +3 -0
- package/dist/src/Diagrams/custom/bpmnExecution/promoteBPMNExecutionNode.d.ts +3 -0
- package/dist/src/Diagrams/custom/bpmnExecution/types.d.ts +38 -0
- package/dist/src/Diagrams/custom/bpmnExecution/ui/BPMNExecutionMarkers.d.ts +6 -0
- package/dist/src/Diagrams/custom/bpmnExecution/ui/BPMNExecutionPropertiesPanel.d.ts +6 -0
- package/dist/src/Diagrams/custom/mr/MRDiagram.d.ts +17 -0
- package/dist/src/Diagrams/custom/mr/edges/MRForeignKeyEdge.d.ts +77 -0
- package/dist/src/Diagrams/custom/mr/extensions/MRModelerExtension.d.ts +45 -0
- package/dist/src/Diagrams/custom/mr/extensions/MRPropertyChangeEvent.d.ts +4 -0
- package/dist/src/Diagrams/custom/mr/layout/applyMRAutoLayout.d.ts +3 -0
- package/dist/src/Diagrams/custom/mr/nodes/MRTableNode.d.ts +105 -0
- package/dist/src/Diagrams/custom/mr/types.d.ts +51 -0
- package/dist/src/Diagrams/custom/mr/ui/MRPropertiesPanel.d.ts +6 -0
- package/dist/src/Diagrams/store/elements/Events.d.ts +2 -1
- package/dist/src/index.d.ts +20 -0
- package/package.json +4 -1
- package/dist/DirectedPoint-BcpEj8ub.js.map +0 -1
- package/dist/index-hTkL5cDr.js +0 -12037
package/dist/index.umd.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
(function(F,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("mobx"),require("react"),require("mobx-react-lite"),require("svg-path-bbox")):typeof define=="function"&&define.amd?define(["exports","mobx","react","mobx-react-lite","svg-path-bbox"],g):(F=typeof globalThis<"u"?globalThis:F||self,g(F.FocusMattersDiagrams={},F.mobx,F.React,F.mobxReactLite))})(this,(function(F,g,M,A){"use strict";var Hr=Object.defineProperty;var Ul=(F,g,M)=>g in F?Hr(F,g,{enumerable:!0,configurable:!0,writable:!0,value:M}):F[g]=M;var o=(F,g)=>Hr(F,"name",{value:g,configurable:!0});var kt=(F,g,M)=>Ul(F,typeof g!="symbol"?g+"":g,M);var pe,fe,me,ye;const Ke=class Ke{showDragHints=!1;constructor(){g.makeAutoObservable(this)}};o(Ke,"ToolsStates"),kt(Ke,"instance",new Ke);let es=Ke;var Hs={exports:{}},xe={};var Ia;function Br(){if(Ia)return xe;Ia=1;var n=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function e(s,i,a){var r=null;if(a!==void 0&&(r=""+a),i.key!==void 0&&(r=""+i.key),"key"in i){a={};for(var c in i)c!=="key"&&(a[c]=i[c])}else a=i;return i=a.ref,{$$typeof:n,type:s,key:r,ref:i!==void 0?i:null,props:a}}return o(e,"jsxProd"),xe.Fragment=t,xe.jsx=e,xe.jsxs=e,xe}o(Br,"requireReactJsxRuntime_production");var Da;function Gr(){return Da||(Da=1,Hs.exports=Br()),Hs.exports}o(Gr,"requireJsxRuntime");var d=Gr();const dt=class dt{_data=[];constructor(t,e=!0){if(t||(t=[0,0,0,0]),Array.isArray(t)){if(t.length!==4)throw new Error("Invalid coordinates length");this._data=[...t]}else this._data=[...t._data];if(this.width<0){const s=this.width;this.x+=s,this.width=-s}if(this.height<0){const s=this.height;this.y+=s,this.height=-s}e&&g.makeAutoObservable(this)}get coordinates(){return new y(this.raw.slice(0,2))}get bottomLeft(){return new y([this.x,this.y+this.height])}get bottomMiddle(){return new y([this.x+this.width/2,this.y+this.height])}get bottomRight(){return new y([this.x+this.width,this.y+this.height])}get leftMiddle(){return new y([this.x,this.y+this.height/2])}get middle(){return new y([this.x+this.width/2,this.y+this.height/2])}get rightMiddle(){return new y([this.x+this.width,this.y+this.height/2])}get topLeft(){return this.coordinates}get topMiddle(){return new y([this.x+this.width/2,this.y])}get topRight(){return new y([this.x+this.width,this.y])}get size(){return new y(this.raw.slice(2,4))}get x(){return this.get(0)}get y(){return this.get(1)}get height(){return this.get(3)}get width(){return this.get(2)}set x(t){this.set(0,t)}set y(t){this.set(1,t)}set height(t){this.set(3,t)}set width(t){this.set(2,t)}get norm(){return this.size.substract(this.coordinates).norm}get length(){return this._data.length}get raw(){return g.toJS([...this._data])}get round(){return new dt([Math.round(this.x),Math.round(this.y),Math.round(this.width),Math.round(this.height)])}get style(){return{width:this.width,height:this.height,left:this.x,top:this.y}}assign(t){if(t.length!==4)throw new Error("Invalid number of Dimensions");const e=t instanceof dt?t:new dt(t);return this.set(0,e.get(0)),this.set(1,e.get(1)),this.set(2,e.get(2)),this.set(3,e.get(3)),this}assignCoordinates(t){if(t.length!==2)throw new Error("Invalid number of Coordinates");const e=t instanceof y?t:new y(t);return this.set(0,e.get(0)),this.set(1,e.get(1)),this}assignDimensions(t){if(t.length!==2)throw new Error("Invalid number of Coordinates");const e=t instanceof y?t:new y(t);return this.set(2,e.get(0)),this.set(3,e.get(1)),this}bound(t){this.x=Math.min(t.x+t.width-this.width,Math.max(t.x,this.x)),this.y=Math.min(t.y+t.height-this.height,Math.max(t.y,this.y))}collides(t,e=!1){if(t instanceof dt){const s=this.x-(e?1:0),i=this.x+this.width+(e?1:0),a=this.y-(e?1:0),r=this.y+this.height+(e?1:0),c=t.x,l=t.x+t.width,h=t.y,u=t.y+t.height;return!(i<=c||l<=s||r<=h||u<=a)}else{const s=this.x,i=this.x+this.width,a=this.y,r=this.y+this.height;return t.x>=s&&t.x<=i&&t.y>=a&&t.y<=r}}copy(){return new dt([this.x,this.y,this.width,this.height])}divide(t){return this.set(0,this.get(0)/t),this.set(1,this.get(1)/t),this.set(2,this.get(2)/t),this.set(3,this.get(3)/t),this}edgeDistanceX(t){return this.x>t.x+t.width?-(this.x-t.x-t.width):t.x>this.x+this.width?t.x-this.x-this.width:0}edgeDistanceY(t){return this.y>t.y+t.height?-(this.y-t.y-t.height):t.y>this.y+this.height?t.y-this.y-this.height:0}get(t){return this._data[t]}inflate(t){return this.copy().translate(new y([-t,-t])).assignDimensions(this.size.sum(new y([2*t,2*t])))}multiply(t){return this.set(0,this.get(0)*t),this.set(1,this.get(1)*t),this.set(2,this.get(2)*t),this.set(3,this.get(3)*t),this}scale(t){return this.set(2,this.get(2)+t.get(0)),this.set(3,this.get(3)+t.get(1)),this}set(t,e){this._data[t]=e}substract(t){if(t.length!==4)throw new Error("Invalid number of Dimensions");const e=t instanceof dt?t:new dt(t);return this.set(0,this.get(0)-e.get(0)),this.set(1,this.get(1)-e.get(1)),this.set(2,this.get(2)-e.get(2)),this.set(3,this.get(3)-e.get(3)),this}sum(t){if(t instanceof y)this.set(0,this.get(0)+t.get(0)),this.set(1,this.get(1)+t.get(1));else{if(t.length!==4)throw new Error("Invalid number of Dimensions");const e=t instanceof dt?t:new dt(t);this.set(0,this.get(0)+e.get(0)),this.set(1,this.get(1)+e.get(1)),this.set(2,this.get(2)+e.get(2)),this.set(3,this.get(3)+e.get(3))}return this}toString(){return`(${this.x}, ${this.y}, ${this.width}, ${this.height})`}translate(t){return this.set(0,this.get(0)+t.get(0)),this.set(1,this.get(1)+t.get(1)),this}};o(dt,"Dimensions");let S=dt;const Ln=class Ln{constructor(t){this.originalEvent=t}originalEvent;get button(){switch(this.originalEvent.button){case 1:return"left";case 2:return"right";case 4:return"middle";case 8:return"back";case 16:return"forward"}return"none"}get position(){return new y(this.originalEvent,!1)}get x(){return this.originalEvent.clientX}get y(){return this.originalEvent.clientY}};o(Ln,"MouseInformation");let Bs=Ln;const $n=class $n{constructor(t){this.src=t}src;_cancellable=!0;_cancelled=!1;_bubbles=!0;_spreads=!0;get bubbles(){return this._bubbles}get cancelled(){return this._cancelled}get spreads(){return this._spreads}cancellable(t){return this._cancellable=t,this}cancel(){this._cancellable&&(this._cancelled=!0)}stopPropagation(){this._bubbles=!1}stopImmediatePropagation(){this._spreads=!1,this.stopPropagation()}};o($n,"DEvent");let ss=$n;const zn=class zn extends ss{};o(zn,"DUIEvent");let ne=zn;const On=class On extends ne{constructor(t,e){super(t),this.src=t,this.originalEvent=e,this.mouse=new Bs(e)}src;originalEvent;mouse;get ctrl(){return this.originalEvent.ctrlKey}get edge(){return this.src.diagram?.getEdgeById(this.originalEvent.target?.closest(".edge")?.dataset.id||"")}get node(){const t=this.originalEvent.target,e=t&&typeof t.closest=="function"?t:null,s=e?.closest(".diagram__node, .node__screenHitArea")?.dataset.id,i=e?.closest("[data-gateway-parent]")?.dataset.gatewayParent;if(s||i)return this.src.diagram?.getNodeById(s||i);if(e?.closest(".edge")&&"clientX"in this.originalEvent&&"clientY"in this.originalEvent){const a=document.elementsFromPoint(this.originalEvent.clientX,this.originalEvent.clientY).find(r=>r.closest(".diagram__node"))?.closest(".diagram__node");return this.src.diagram?.getNodeById(a?.dataset.id||"")}}get shift(){return this.originalEvent.shiftKey}get target(){return this.originalEvent.target}};o(On,"DMouseEvent");let At=On;const Fn=class Fn extends At{};o(Fn,"DClickEvent");let ns=Fn;const Hn=class Hn extends At{};o(Hn,"DDoubleClickEvent");let is=Hn;const Bn=class Bn extends At{};o(Bn,"DMouseDownEvent");let Pt=Bn;const Gn=class Gn extends At{};o(Gn,"DMouseUpEvent");let tt=Gn;const Rn=class Rn extends At{};o(Rn,"DMouseMoveEvent");let Ct=Rn;const Vn=class Vn extends At{constructor(t,e){super(t,e),this.originalEvent=e}originalEvent;get directionX(){return this.originalEvent.deltaX<0?"left":this.originalEvent.deltaX>0?"right":"none"}get directionY(){return this.originalEvent.deltaY<0?"up":this.originalEvent.deltaY>0?"down":"none"}};o(Vn,"DWheelEvent");let Gs=Vn;const Yn=class Yn extends ne{constructor(t,e){super(t),this.originalEvent=e}originalEvent;get code(){return this.originalEvent.code}get alt(){return this.originalEvent.altKey}get ctrl(){return this.originalEvent.ctrlKey}get shift(){return this.originalEvent.shiftKey}};o(Yn,"DKeyboardEvent");let be=Yn;const Wn=class Wn extends be{constructor(t,e){super(t,e),this.originalEvent=e}originalEvent};o(Wn,"DKeyDownEvent");let Rt=Wn;const Zn=class Zn extends be{constructor(t,e){super(t,e),this.originalEvent=e}originalEvent};o(Zn,"DKeyUpEvent");let we=Zn;const Xn=class Xn extends be{constructor(t,e){super(t,e),this.orignalEvent=e}orignalEvent};o(Xn,"DKeyPressEvent");let Rs=Xn;const qn=class qn extends ne{};o(qn,"DCanvasEvent");let ve=qn;const Un=class Un extends ve{constructor(t,e,s,i){super(t),this.displacement=e,this.newScale=s,this.previousScale=i}displacement;newScale;previousScale};o(Un,"DScaleEvent");let Ee=Un;const Kn=class Kn extends ve{constructor(t,e,s){super(t),this.previousDisplacement=e,this.displacement=s}previousDisplacement;displacement};o(Kn,"DDisplaceEvent");let Vs=Kn;const Jn=class Jn extends ss{};o(Jn,"DChangeEvent");let et=Jn;const Qn=class Qn extends et{constructor(t,e){super(t),e(this.resolve.bind(this))}callbacks=[];defer(t){this.callbacks.push(t)}async resolve(){return(await Promise.all(this.callbacks.map(t=>t()))).every(t=>t)}};o(Qn,"DResetGraphEvent");let Ys=Qn;const ti=class ti extends et{};o(ti,"DNodesConnectionEvent");let _e=ti;const ei=class ei extends _e{constructor(t,e){super(t),this.origin=e}origin};o(ei,"DNodeConnectionIntentEvent");let Ws=ei;const si=class si extends _e{constructor(t,e,s){super(t),this.origin=e,this.target=s}origin;target};o(si,"DNodesConnectActionEvent");let Se=si;const ni=class ni extends et{};o(ni,"DNodeChangeTypeEvent");let Vt=ni;const ii=class ii extends et{constructor(t,e){super(t),this.src=t,this.node=e}src;node};o(ii,"DDeleteNodeEvent");let ie=ii;const ai=class ai extends et{constructor(t,e){super(t),this.src=t,this.edge=e}src;edge};o(ai,"DDeleteEdgeEvent");let as=ai;const ri=class ri extends ne{constructor(t,e){super(t),this.src=t,this.selected=e}src;selected};o(ri,"DSelectionEvent");let Me=ri;const oi=class oi extends Me{constructor(t,e){super(t,e),this.src=t}src};o(oi,"DNodeSelectionEvent");let ke=oi;const ci=class ci extends Me{constructor(t,e){super(t,e),this.src=t}src};o(ci,"DEdgeSelectionEvent");let rs=ci;const li=class li extends et{constructor(t,e){super(t),this.src=t,this.originalEvent=e}src;originalEvent};o(li,"DDragEvent");let Ot=li;const di=class di extends Ot{constructor(t,e,s){super(t,s),this.src=t,this.midPoint=e,this.originalEvent=s}src;midPoint;originalEvent};o(di,"DEdgeDragStartEvent");let os=di;const hi=class hi extends Ot{constructor(t,e,s){super(t,s),this.src=t,this.endpoint=e,this.originalEvent=s}src;endpoint;originalEvent};o(hi,"DEdgeEndpointDragStartEvent");let cs=hi;const ui=class ui{constructor(t,e){this.node=t,this.newBox=e,this._updated=e.copy()}node;newBox;_cancelled=!1;_updated;_lockX=null;_lockY=null;cancel(){this._cancelled=!0}get current(){return this._updated.copy()}get cancelled(){return this._cancelled}get(){return this._updated}lockX(){this._lockX=this._updated.x}lockY(){this._lockY=this._updated.y}update(t){this._updated=t,this._lockX!==null&&(this._updated.x=this._lockX),this._lockY!==null&&(this._updated.y=this._lockY)}updateX(t){this._lockX===null&&(this._updated.x=t)}updateY(t){this._lockY===null&&(this._updated.y=t)}};o(ui,"NodePositionProposal");let Ae=ui;const gi=class gi extends Ot{constructor(t,e,s){super(t,s),this.src=t,this.proposals=e}src;proposals};o(gi,"DDragNodeEvent");let ht=gi;const pi=class pi{constructor(t,e){this.point=t,this.movedAxis=e,this._updated=t.copy()}point;movedAxis;_updated;_lockX=null;_lockY=null;get current(){return this._updated.copy()}get(){return this._updated}lockX(){this._lockX=this._updated.x}lockY(){this._lockY=this._updated.y}update(t){this._updated=t.copy(),this._lockX!==null&&(this._updated.x=this._lockX),this._lockY!==null&&(this._updated.y=this._lockY)}updateX(t){this._lockX===null&&(this._updated.x=t)}updateY(t){this._lockY===null&&(this._updated.y=t)}};o(pi,"EdgePointPositionProposal");let ls=pi;const fi=class fi extends Ot{constructor(t,e,s,i){super(t,i),this.src=t,this.proposals=e,this.movedAxis=s}src;proposals;movedAxis};o(fi,"DDragEdgeSegmentEvent");let ds=fi;async function Rr(){return(await Promise.resolve().then(()=>Xl)).DirectedPoint}o(Rr,"getDirectedClass");let Zs=null;const U=class U{_data=[];constructor(t,e=!0){if(t||(t=[0,0]),Array.isArray(t)){if(t.length!==2)throw new Error("Invalid coordinates length");this._data=[...t]}else t instanceof U?this._data=[...t._data]:t instanceof At||t instanceof Ot?this._data=[t.originalEvent.clientX,t.originalEvent.clientY]:t.clientX!==void 0?this._data=[t.clientX,t.clientY]:this._data=[0,0];e&&g.makeObservable(this,{_data:g.observable,set:g.action})}bound(t){return this.x=Math.min(t.get(2),Math.max(t.get(0),this.x)),this.y=Math.min(t.get(3),Math.max(t.get(1),this.y)),this}get abs(){return new U([Math.abs(this.x),Math.abs(this.y)])}assign(t){if(t.length!==2)throw new Error("Invalid number of coordinates");const e=t instanceof U?t:new U(t);return this.set(0,e.get(0)),this.set(1,e.get(1)),this}copy(t=!0){return new U(this,t)}distance(t){return this.copy().substract(t).norm}distanceManhattan(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}divide(t){const e=t instanceof U?t.x:t,s=t instanceof U?t.y:t;return this.set(0,this.get(0)/e),this.set(1,this.get(1)/s),this}equals(t){return this.copy().substract(t).norm===0}get(t){return this._data[t]}get length(){return this._data.length}max(t){return new U([Math.max(t,this.x),Math.max(t,this.y)])}get nonObserved(){return new U(this,!1)}get raw(){return g.toJS([...this._data])}get round(){return new U([Math.round(this.x),Math.round(this.y)])}get half(){return this.copy().multiply(.5)}get norm(){return Math.sqrt(this.x**2+this.y**2)}get style(){return{left:this.x,top:this.y}}multiply(t){return typeof t=="number"?(this.set(0,this.get(0)*t),this.set(1,this.get(1)*t)):t instanceof U&&(this.set(0,this.get(0)*t.get(0)),this.set(1,this.get(1)*t.get(1))),this}set(t,e){return this._data[t]=e,this}snapToGrid(t,e="both"){return e!=="y"&&(this.x=Math.round(this.x/t)*t),e!=="x"&&(this.y=Math.round(this.y/t)*t),this}substract(t){if(t.length!==2)throw new Error("Invalid number of coordinates");const e=t instanceof U?t:new U(t);return this.set(0,this.get(0)-e.get(0)),this.set(1,this.get(1)-e.get(1)),this}sum(t){if(typeof t=="number")this.set(0,this.get(0)+t),this.set(1,this.get(1)+t);else{if(t.length!==2)throw new Error("Invalid number of coordinates");const e=t instanceof U?t:new U(t);this.set(0,this.get(0)+e.get(0)),this.set(1,this.get(1)+e.get(1))}return this}toDirectedPoint(t){if(Zs===null){Rr().then(i=>{Zs=i});const s=this.copy(!1);return s.direction=t,s}const e=new Zs(this);return e.direction=t,e}toDimensions(t){return new S([...this.raw,...t.raw])}get x(){return this.get(0)}get y(){return this.get(1)}set x(t){this.set(0,t)}set y(t){this.set(1,t)}toString(){return`(${this.x}, ${this.y})`}};o(U,"Coordinates");let y=U;const Je=class Je{static getInstance(){return this.instance||(this.instance=new Je),this.instance}x=0;y=0;get coordinates(){return new y([this.x,this.y])}constructor(){g.makeAutoObservable(this),document.addEventListener("mousemove",t=>{g.runInAction(()=>{this.x=t.clientX,this.y=t.clientY})})}};o(Je,"Mouse"),kt(Je,"instance",null);let ae=Je;const ja={};function Pe(n,t,e=[]){let s=ja[t]||0;for(;e.includes(`${t}${s}`)||n.getNodeById(`${t}${s}`);)s++;return ja[t]=s+1,`${t}${s}`}o(Pe,"getIdForNode");function Vr(n){const t=[];let e=n;for(;e&&e!==Object;)t.push(e),e=Object.getPrototypeOf(e);return t}o(Vr,"getClassHierarchy");let Yt=(pe=class{constructor(t){this.parent=t,g.makeObservable(this,{parent:g.observable,diagram:g.computed})}parent;callbacks=new Map;emit(t){const e=[];for(const s of Vr(t.constructor)){const i=this.callbacks.get(s);i&&e.push(...i)}e.sort((s,i)=>i.priority-s.priority);for(const{cb:s}of e)if(s(t),!t.spreads)return t;return t.bubbles&&this.parent?.emit(t),t}get diagram(){let t=this.parent;for(;t?.parent;)t=t.parent;return t}onEvent(t,e,s=0){let i=this.callbacks.get(t);return i||(i=[],this.callbacks.set(t,i)),i.push({cb:e,priority:s}),()=>this.offEvent(t,e)}offEvent(t,e){const s=this.callbacks.get(t);s&&this.callbacks.set(t,s.filter(i=>i.cb!==e))}},o(pe,"Element"),pe);function Yr(n,t,e="text/plain"){const s=new Blob([n],{type:e}),i=URL.createObjectURL(s),a=document.createElement("a");a.href=i,a.download=t,a.style.display="none",document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}o(Yr,"downloadFile");const mi=class mi extends Yt{constructor(t){super(t),g.makeObservable(this,{_enable:g.observable,toggle:g.action}),this._enable=localStorage.getItem(`enable_${this.constructor.name}`)!=="false"}RenderUI=null;RenderDiagram=null;get diagram(){return this.parent}_enable=!0;get enabled(){return this._enable}disable(){this._enable=!1}enable(){this._enable=!0}toggle(t=!this._enable,e=!0){this._enable=t,e&&localStorage.setItem(`enable_${this.constructor.name}`,String(this._enable))}};o(mi,"DiagramExtension");let z=mi;const Xs=new WeakMap;let Wr=0;const ct={mark(n,t){const e=Xs.get(n)??{};e[t]===void 0&&(e[t]=Wr++,Xs.set(n,e))},get(n,t){return Xs.get(n)?.[t]}};function Na(n,t){return!n||t.score<n.score?t:n}o(Na,"nearest");const yi=class yi extends z{gridSize=25;proposals=[];clear(){this.proposals=[]}init(){g.makeObservable(this,{clear:g.action,proposals:g.observable}),this.diagram.onEvent(tt,()=>this.clear()),this.diagram.onEvent(ht,t=>this.balance(t),this.diagram.priorities.Drag_Node_Distances_Balancer)}balance(t){if(this.clear(),!this.enabled||t.proposals.length===0)return;const e=new Set(t.proposals.map(({node:c})=>c.id)),s=this.diagram.canvas.frameDimensions.norm/2;let i=null,a=null;for(const c of t.proposals){if(c.cancelled)continue;const l=c.get(),h=this.findNeighbors(l,e,s);if(h.top&&h.bottom){const u=-l.edgeDistanceY(h.top.box),f=l.edgeDistanceY(h.bottom.box),p=Math.abs(u-f);p<this.gridSize&&(a=Na(a,{proposal:c,score:p,target:(h.top.box.bottomMiddle.y+h.bottom.box.topMiddle.y)/2-l.height/2,guides:[{from:l.topMiddle,to:new y([l.topMiddle.x,h.top.box.bottomMiddle.y])},{from:l.bottomMiddle,to:new y([l.bottomMiddle.x,h.bottom.box.topMiddle.y])}]}))}if(h.left&&h.right){const u=-l.edgeDistanceX(h.left.box),f=l.edgeDistanceX(h.right.box),p=Math.abs(f-u);p<this.gridSize&&(i=Na(i,{proposal:c,score:p,target:(h.right.box.leftMiddle.x+h.left.box.rightMiddle.x)/2-l.width/2,guides:[{from:l.rightMiddle,to:new y([h.right.box.leftMiddle.x,l.rightMiddle.y])},{from:l.leftMiddle,to:new y([h.left.box.rightMiddle.x,l.leftMiddle.y])}]}))}}const r=[...i?.guides??[],...a?.guides??[]];g.runInAction(()=>{this.proposals=r}),this.applyCandidate(i,"x"),this.applyCandidate(a,"y")}findNeighbors(t,e,s){let i=null,a=null,r=null,c=null,l=1/0,h=1/0,u=1/0,f=1/0;for(const p of this.diagram.nodes){if(e.has(p.id))continue;const m=t.edgeDistanceX(p.box),x=t.edgeDistanceY(p.box);x===0&&m<0&&-m<u&&(u=-m,r=p),x===0&&m>0&&m<f&&(f=m,c=p),m===0&&x<0&&-x<l&&(l=-x,i=p),m===0&&x>0&&x<h&&(h=x,a=p)}return{top:l<s?i:null,bottom:h<s?a:null,left:u<s?r:null,right:f<s?c:null}}applyCandidate(t,e){if(t){if(e==="x"){t.proposal.updateX(t.target),ct.mark(t.proposal,"x"),t.proposal.lockX();return}t.proposal.updateY(t.target),ct.mark(t.proposal,"y"),t.proposal.lockY()}}};o(yi,"DistancesBalancer");let Ce=yi;const xi=class xi extends z{gridSize=50;init(){g.makeObservable(this,{gridSize:g.observable}),this.diagram.onEvent(ht,t=>{if(this._enable)for(const e of t.proposals){const s=new y([Math.round(e.newBox.coordinates.x/this.gridSize)*this.gridSize,Math.round(e.newBox.coordinates.y/this.gridSize)*this.gridSize]);e.update(new S([...s.raw,...e.newBox.size.raw])),e.lockX(),e.lockY()}},this.diagram.priorities.Drag_Node_Snap_To_Grid),this.diagram.onEvent(ds,t=>{if(this._enable)for(const e of t.proposals){const s=e.get().copy();s.snapToGrid(this.gridSize,t.movedAxis),e.update(s),t.movedAxis==="x"?e.lockY():e.lockX()}},this.diagram.priorities.Drag_Edge_Snap_To_Grid)}};o(xi,"GridSnap");let G=xi;const bi=class bi extends z{windowTime=20;maxSize=50;index=-1;snapshots=[];draggingNodes=!1;async avoidEvents(t){this.disable();try{await t()}finally{this.enable()}}restoreSnapshot(t){return this.avoidEvents(async()=>{this.clearTransientExtensions(),this.draggingNodes=!1;const e=JSON.parse(t);e.position=this.checkpointPosition(),await this.diagram.reset(),this.diagram.import(JSON.stringify(e))})}clearTransientExtensions(){this.diagram.extensions.forEach(t=>{t.clear?.()})}checkpointPosition(){const t=this.diagram.canvas.displacement;return{x:t.x,y:t.y,scale:this.diagram.canvas.scale}}unbind=o(()=>{},"unbind");window(){this.enabled&&(this.unbind(),this.unbind=pt(wo(()=>{g.runInAction(()=>{const t=this.diagram.serialize();this.snapshots.splice(this.index+1),this.snapshots.push(JSON.stringify(t)),this.snapshots.splice(0,Math.max(0,this.snapshots.length-this.maxSize)),this.index=this.snapshots.length-1})},this.windowTime)))}redo(){if(this.hasNext)return this.index=Math.min(this.snapshots.length-1,this.index+1),this.restoreSnapshot(this.snapshots[this.index])}undo(){if(this.hasPrevious)return this.index=Math.max(-1,this.index-1),this.restoreSnapshot(this.snapshots[this.index]||"{}")}get hasNext(){return this.index<this.snapshots.length-1}get hasPrevious(){return this.index>-1}init(){g.makeObservable(this,{index:g.observable,hasNext:g.computed,hasPrevious:g.computed,redo:g.action,undo:g.action}),this.diagram.onEvent(et,t=>{if(t instanceof ht){this.draggingNodes=!0;return}t.cancelled||this.window()},this.diagram.priorities.Change_History),this.diagram.onEvent(tt,()=>{this.draggingNodes&&(this.draggingNodes=!1,this.window())}),this.window()}};o(bi,"History");let Ie=bi;const wi=class wi extends z{init(){g.makeObservable(this,{_enabled:g.observable,endPoint:g.observable,startPoint:g.observable}),this.diagram.canvas.onEvent(Pt,this.handleMouseDown.bind(this),this.diagram.priorities.Mouse_Down_Measurer)}_enabled=!1;toggle(){this._enabled=!this._enabled}get enabled(){return this._enabled}endPoint=null;startPoint=null;get(){return this.startPoint?[this.startPoint,this.endPoint]:[]}getMeassurement(){return this.endPoint?.copy().substract(this.startPoint).norm}u=o(()=>{},"u");handleMouseDown(t){this._enabled&&(t.cancel(),t.stopImmediatePropagation(),this.u(),this.u=pt(R(this,"mousemove",this.handleMouseMove),R(this,"mouseup",this.handleMouseUp)),this.startPoint=this.diagram.canvas.inverseFit(new y(t)),this.endPoint=this.diagram.canvas.inverseFit(new y(t)))}handleMouseMove(t){this.startPoint&&this._enabled&&(this.endPoint=this.diagram.canvas.inverseFit(new y(t)))}handleMouseUp(){this.endPoint=null,this.startPoint=null}};o(wi,"Measurer");let De=wi;const hs=new Map;function Wt(n){hs.has(n)||hs.set(n,Number.MIN_SAFE_INTEGER);const t=hs.get(n);return hs.set(n,t+1),`${n}_${t}`}o(Wt,"getUniqueId");function re(n,t){return n<=t?[n,t]:[t,n]}o(re,"orderedRange$1");function Ft(n,t){return Number.isFinite(t.distance)&&(!n||t.distance<n.distance)?t:n}o(Ft,"closer$1");const vi=class vi extends z{gridSize=50;horizontalSuggestionProviders=[];verticalSuggestionProviders=[];proposals=[];registerHorizontalSuggestionProvider(t){return this.horizontalSuggestionProviders.push(t),()=>{this.horizontalSuggestionProviders=this.horizontalSuggestionProviders.filter(e=>e!==t)}}registerVerticalSuggestionProvider(t){return this.verticalSuggestionProviders.push(t),()=>{this.verticalSuggestionProviders=this.verticalSuggestionProviders.filter(e=>e!==t)}}clear(){this.proposals=[]}init(){g.makeObservable(this,{clear:g.action,proposals:g.observable}),R(this,"keydown",t=>{t.ctrlKey&&this.clear()}),this.diagram.onEvent(tt,()=>this.clear()),this.diagram.onEvent(ht,t=>this.align(t),this.diagram.priorities.Drag_Node_Aligner)}align(t){if(this.clear(),!this.enabled||t.proposals.length===0)return;const e=this.diagram.canvas.frameDimensions.norm/2,s=this.gridSize/5*2,i=this.gridSize/3,a=new Set(t.proposals.map(({node:f})=>f.id)),r=t.proposals.some(f=>ct.get(f,"x")!==void 0),c=t.proposals.some(f=>ct.get(f,"y")!==void 0);let l=null,h=null;for(const f of t.proposals){if(f.cancelled)continue;const p=f.get();for(const m of this.diagram.nodes){if(a.has(m.id))continue;const x=Math.abs(p.edgeDistanceX(m.box)),b=Math.abs(p.edgeDistanceY(m.box));!c&&x<e&&(h=Ft(h,this.verticalCandidate(f,Math.abs(m.box.middle.y-p.middle.y),m.box.middle.y-p.height/2,m.box.middle.y,re(m.box.rightMiddle.x,p.x),s)),h=Ft(h,this.verticalCandidate(f,Math.abs(m.box.y-p.y),m.box.y,m.box.y,re(m.box.rightMiddle.x,p.x),s)),h=Ft(h,this.verticalCandidate(f,Math.abs(m.box.bottomMiddle.y-p.bottomMiddle.y),m.box.bottomMiddle.y-p.height,m.box.bottomMiddle.y,re(m.box.rightMiddle.x,p.x),s))),!r&&b<e&&(l=Ft(l,this.horizontalCandidate(f,Math.abs(m.box.x-p.x),m.box.x,m.box.x,re(m.box.bottomMiddle.y,p.y),s)),l=Ft(l,this.horizontalCandidate(f,Math.abs(m.box.middle.x-p.middle.x),m.box.middle.x-p.width/2,m.box.middle.x,re(m.box.bottomMiddle.y,p.y),s)),l=Ft(l,this.horizontalCandidate(f,Math.abs(m.box.rightMiddle.x-p.rightMiddle.x),m.box.rightMiddle.x-p.width,m.box.rightMiddle.x,re(m.box.bottomMiddle.y,p.y),s)))}if(!c)for(const m of this.verticalSuggestionProviders.flatMap(x=>x(f.node,p)))h=Ft(h,this.verticalCandidate(f,Math.abs(m.nodeY-p.y),m.nodeY,m.guideY,m.range,s));if(!r)for(const m of this.horizontalSuggestionProviders.flatMap(x=>x(f.node,p)))l=Ft(l,this.horizontalCandidate(f,Math.abs(m.nodeX-p.x),m.nodeX,m.guideX,m.range,s))}const u=[l?.guide,h?.guide].filter(f=>!!f);g.runInAction(()=>{this.proposals=u}),this.applyCandidate(l,"x",i),this.applyCandidate(h,"y",i)}verticalCandidate(t,e,s,i,a,r){return{proposal:t,distance:e<r?e:1/0,target:s,guide:{type:"v",y:i,range:a,id:Wt("alignment-proposal")}}}horizontalCandidate(t,e,s,i,a,r){return{proposal:t,distance:e<r?e:1/0,target:s,guide:{type:"h",x:i,range:a,id:Wt("alignment-proposal")}}}applyCandidate(t,e,s){if(!(!t||t.distance>=s)){if(e==="x"){if(t.proposal.updateX(t.target),Math.abs(t.proposal.get().x-t.target)>.001)return;ct.mark(t.proposal,"x"),t.proposal.lockX();return}t.proposal.updateY(t.target),!(Math.abs(t.proposal.get().y-t.target)>.001)&&(ct.mark(t.proposal,"y"),t.proposal.lockY())}}};o(vi,"NodesAligner");let Zt=vi;const se=class se{constructor(t){this.diagram=t}diagram;displace(t){if(!this.diagram.rules.displaceWhenDragOnEdges)return new y;const e=this.diagram.canvas.frameDimensions,s=new y([this.axisDisplacement(t.x,e.x,e.width),this.axisDisplacement(t.y,e.y,e.height)]);return s.norm>0&&this.diagram.canvas.displace(s),s}axisDisplacement(t,e,s){const i=t-e;if(i<se.edgeThreshold)return this.step(i);const a=e+s-t;return a<se.edgeThreshold?-this.step(a):0}step(t){const e=Math.max(t,0);return((se.edgeThreshold-e)/10)**2}};o(se,"Autopan"),kt(se,"edgeThreshold",100);let ut=se;const Ei=class Ei extends et{};o(Ei,"DEdgeLabelChangeEvent");let oe=Ei;const _i=class _i extends Yt{id;text;alignment;size;position;isEditing;draft;isNew;constructor(t,e,s=!1){super(t),this.id=e.id??Wt("edge-label"),this.text=e.text??"",this.alignment=e.alignment??"left",this.size=e.size??{height:30,width:180},this.position=e.position,this.isNew=s,this.isEditing=s,this.draft=this.text,g.makeObservable(this,{text:g.observable,alignment:g.observable,size:g.observable,position:g.observable,isEditing:g.observable,draft:g.observable,setText:g.action,setAlignment:g.action,setSize:g.action,beginEdit:g.action,setDraft:g.action,cancelEdit:g.action,confirmEdit:g.action,setPosition:g.action})}setText(t){this.text=t,this.draft=t,this.isNew=!1}setAlignment(t){this.alignment!==t&&(this.alignment=t,this.emit(new oe(this)))}setSize(t){this.size=t}beginEdit(){this.draft=this.text,this.isEditing=!0}setDraft(t){this.draft=t}cancelEdit(){if(this.isNew){this.parent.removeLabel(this,!1);return}this.draft=this.text,this.isEditing=!1}delete(){this.parent.removeLabel(this,!this.isNew)}confirmEdit(){if(!this.draft){this.parent.removeLabel(this,!this.isNew);return}const t=this.isNew||this.draft!==this.text;this.text=this.draft,this.isNew=!1,this.isEditing=!1,t&&this.emit(new oe(this))}setPosition(t){this.position.assign(t)}commitPosition(){this.emit(new oe(this))}serialize(){return{alignment:this.alignment,id:this.id,size:this.size,text:this.text,position:this.position.raw}}};o(_i,"EdgeLabel");let je=_i;const Qe=class Qe extends y{constructor(t,e){super(Array.isArray(e)?e.slice(0,2):e),this.parent=t,g.makeObservable(this,{manualAxes:g.observable,mode:g.observable}),e instanceof Qe?(this.mode=e.mode,this.manualAxes=e.manualAxes):Array.isArray(e)&&e.length===3?(this.mode=e[2],this.manualAxes=this.mode==="manual"||this.mode==="static"?"both":"none"):Array.isArray(e)&&e.length>=4&&(this.mode=e[2],this.manualAxes=e[3])}parent;mode="auto";manualAxes="none";get manualX(){return this.mode==="manual"&&["x","both"].includes(this.manualAxes)}get manualY(){return this.mode==="manual"&&["y","both"].includes(this.manualAxes)}addManualAxis(t){return this.mode==="static"?this:(this.mode="manual",t==="both"||this.manualAxes==="both"?this.manualAxes="both":this.manualAxes==="none"?this.manualAxes=t:this.manualAxes!==t&&(this.manualAxes="both"),this)}hasManualAxis(t){return t==="x"?this.manualX:this.manualY}markStatic(){return this.mode="static",this.manualAxes="both",this}copy(){return new Qe(this.parent,[this.x,this.y,this.mode,this.manualAxes])}toString(t=!1){return t?`(${this.x}, ${this.y}): ${this.mode}/${this.manualAxes}`:super.toString()}};o(Qe,"EdgePoint");let O=Qe,Zr=Number.MIN_SAFE_INTEGER;function Ta(n){return n==="straight"||n==="curved"?n:"orthogonal"}o(Ta,"normalizePathType");function Xr(n,t){if(!n)return{mode:"fixed"};const e=n.parent.box,s=n.coordinates.copy().sum(t??new y);return{mode:"fixed",position:new y([(s.x-e.x)/Math.max(e.width,.001),(s.y-e.y)/Math.max(e.height,.001)])}}o(Xr,"fixedAnchorForGateway");function us(n,t,e){return n?.mode==="automatic"?{mode:"automatic"}:n?.position?{mode:"fixed",position:n.position instanceof y?n.position:new y(n.position)}:Xr(t,e)}o(us,"normalizeAnchor");function qr(n,t){return n?n.copy(!1).substract(t.relativePosition).norm<.001:!0}o(qr,"isGatewayAnchorPosition");const Si=class Si extends Yt{constructor(t,e){super(t),this.state=e,this.state.pathType=Ta(this.state.pathType),this.state.startAnchor=us(this.state.startAnchor,this.state.from,this.state.displacementStart),this.state.endAnchor=us(this.state.endAnchor,this.state.to,this.state.displacementEnd),g.makeObservable(this,{state:g.observable,setSteps:g.action,setPathType:g.action,setEndpointAnchor:g.action,setResolvedEndpoint:g.action,applyResolvedAnchors:g.action,createLabel:g.action,removeLabel:g.action,setPrimaryLabel:g.action,arrowHeadEnd:g.computed,arrowHeadStart:g.computed,from:g.computed,hasManualSteps:g.computed,pathType:g.computed,steps:g.computed,stroke:g.computed,strokeWidth:g.computed,setState:g.action})}state;id=String(Zr++);get arrowHeadEnd(){return this.state.arrowHeadEnd}get arrowHeadStart(){return this.state.arrowHeadStart}get from(){return this.state.from}get hasManualSteps(){return this.state.steps.find(t=>t.mode==="manual")}get lineStyle(){return this.state.lineStyle}get pathType(){return this.state.pathType}get startAnchor(){return this.state.startAnchor}get endAnchor(){return this.state.endAnchor}get steps(){return this.state.steps}get stroke(){return this.state.stroke}get strokeWidth(){return this.state.strokeWidth}get labels(){return this.state.labels}createLabel(t){const e=new je(this,{position:t},!0);return this.state.labels.push(e),e}removeLabel(t,e=!0){const s=this.state.labels.indexOf(t);s<0||(this.state.labels.splice(s,1),e&&this.emit(new oe(this)))}setPrimaryLabel(t){const e=this.state.labels[0];if(!t)return e&&this.removeLabel(e,!1),null;if(e)return e.setText(t),e;const s=new je(this,{text:t,position:this.defaultLabelPosition()});return this.state.labels.push(s),s}defaultLabelPosition(){if(this.steps.length===0)return this.from.coordinates.copy();if(this.steps.length===1)return this.steps[0].copy();const t=this.steps.slice(0,-1).map((i,a)=>i.distance(this.steps[a+1])),e=t.reduce((i,a)=>i+a,0)/2;let s=0;for(let i=0;i<t.length;i+=1){if(s+t[i]>=e){const a=(e-s)/Math.max(t[i],.001);return this.steps[i].copy().sum(this.steps[i+1].copy().substract(this.steps[i]).multiply(a))}s+=t[i]}return this.steps.at(-1).copy()}collides(t){for(let e=0;e<this.steps.length-1;e++){const s=this.steps[e],i=this.steps[e+1];if(new S([...s.raw,...i.copy().substract(s).raw]).collides(t))return!0}return!1}setState(t,e){this.state[t]=e}setSteps(t){this.state.steps=t.map(e=>e instanceof O?e:new O(this,e)),this.state.steps[0].markStatic(),this.state.steps.at(-1).markStatic()}setPathType(t){this.state.pathType=t,this.diagram&&this.state.to&&this.from.recomputeConnectedEdge(this,"from")}resolveEndpointAnchor(t){const e=t==="from"?this.from:this.to,s=t==="from"?this.startAnchor:this.endAnchor,i=t==="from"?this.state.displacementStart??new y:this.state.displacementEnd??new y;if(!e.parent.edgesAsGateways){const a=e.coordinates.copy().sum(i),r=e.parent.box;return{gateway:e,point:a,displacement:i,relativePosition:new y([(a.x-r.x)/Math.max(r.width,.001),(a.y-r.y)/Math.max(r.height,.001)])}}return qr(s.position,e)&&i.norm<.001?{gateway:e,point:e.coordinates.copy(),relativePosition:e.relativePosition,displacement:new y}:e.parent.findRelativeConnectionAnchor(s.position??e.relativePosition)}setEndpointAnchor(t,e,s=!0){t==="from"?this.state.startAnchor=e:this.state.endAnchor=e,s&&this.diagram&&this.from.recomputeConnectedEdge(this,t)}setResolvedEndpoint(t,e,s,i=!0){const a=this.resolveEndpointAnchor(t==="from"?"to":"from");t==="from"?(this.state.startAnchor=s,this.applyResolvedAnchors(e,a)):(this.state.endAnchor=s,this.applyResolvedAnchors(a,e)),i&&this.diagram&&this.from.recomputeConnectedEdge(this,t)}applyResolvedAnchors(t,e){const s=this.state.from,i=this.state.to,a=s?.outgoingEdges.includes(this)??!1,r=i?.incomingEdges.includes(this)??!1;s!==t.gateway&&(a&&s.removeOutgoingEdge(this),this.state.from=t.gateway,a&&t.gateway.addOutgoingEdge(this,!1)),i!==e.gateway&&(r&&i.removeIncomingEdge(this),this.state.to=e.gateway,r&&e.gateway.addIncomingEdge(this,!1)),this.state.displacementStart=t.displacement,this.state.displacementEnd=e.displacement}get to(){return this.state.to}deserialize(t){if(!Array.isArray(t.labels))throw new TypeError("Invalid serialized edge: 'labels' must be an array.");this.state.arrowHeadEnd=t.arrowHeadEnd,this.state.arrowHeadStart=t.arrowHeadStart,this.state.lineStyle=t.lineStyle,this.state.pathType=Ta(t.pathType),this.state.stroke=t.stroke,this.state.strokeWidth=t.strokeWidth,this.state.labels=t.labels.map(e=>new je(this,{alignment:e.alignment,id:e.id,text:e.text,position:new y(e.position),size:e.size})),this.state.displacementEnd=t.displacementEnd?new y(t.displacementEnd):void 0,this.state.displacementStart=t.displacementStart?new y(t.displacementStart):void 0,this.state.steps=t.steps.map(e=>new O(this,e)),this.state.to=this.state.from.diagram.getNodeById(t.toParentId).getGateway(t.to),this.state.startAnchor=us(t.startAnchor,this.state.from,this.state.displacementStart),this.state.endAnchor=us(t.endAnchor,this.state.to,this.state.displacementEnd),this.state.from.diagram.addEdge(this)}serialize(){const{arrowHeadEnd:t,arrowHeadStart:e,lineStyle:s,pathType:i,startAnchor:a,endAnchor:r,steps:c,stroke:l,strokeWidth:h,to:{id:u,parent:{id:f}}}=this;return{arrowHeadEnd:t,arrowHeadStart:e,displacementEnd:this.state.displacementEnd?.raw,displacementStart:this.state.displacementStart?.raw,lineStyle:s,labels:this.state.labels.map(p=>p.serialize()),pathType:i,startAnchor:{mode:a.mode,position:a.position?.raw},endAnchor:{mode:r.mode,position:r.position?.raw},steps:c.map(p=>[...p.raw,p.mode,p.manualAxes]),stroke:l,strokeWidth:h,to:u,toParentId:f,class:this.constructor.name}}dragStart(t,e){this.pathType==="orthogonal"&&(e.nativeEvent.stopImmediatePropagation(),this.emit(new os(this,t,e)))}dragEndpoint(t,e){e.nativeEvent.stopImmediatePropagation(),this.emit(new cs(this,t,e))}};o(Si,"Edge");let Xt=Si;const Mi=class Mi{_data=new Set;constructor(){g.makeAutoObservable(this)}add(...t){for(const e of t)this._data.add(e)}delete(t){this._data.delete(t)}toggle(t){this._data.has(t)?this.delete(t):this.add(t)}get string(){return[...this._data].join(" ")}};o(Mi,"ClassList");let qs=Mi;const ki=class ki{route(t,e){const s=e.from.parent.edgesAsGateways&&e.startAnchor.mode==="automatic"?this.findAutomaticStartPoint(e):e.resolveEndpointAnchor("from"),i=e.to.parent.edgesAsGateways&&e.endAnchor.mode==="automatic"?this.findAutomaticEndPoint(e):e.resolveEndpointAnchor("to");return e.applyResolvedAnchors(s,i),this.findRoute(t,e,s,i)}};o(ki,"EdgesRouter");let Ne=ki;const Ai=class Ai extends Ne{findAutomaticStartPoint(t){return t.from.parent.findAutomaticGatewayAnchor(t.to.parent.box.middle)}findAutomaticEndPoint(t){return t.to.parent.findAutomaticGatewayAnchor(t.from.parent.box.middle)}findRoute(t,e,s,i){return[s.point,i.point]}};o(Ai,"CurvedRouter");let Us=Ai;const $=.001,Ur=3;function V(n,t,e=Ur){return Math.abs(n-t)<=e}o(V,"almostEqual");function gs(n,t){return Math.abs(n-t)<=$}o(gs,"strictlyEqual");function qt(n,t){return V(n.x,t.x)&&V(n.y,t.y)}o(qt,"samePoint");function it(n,t){return V(n.x,t.x)||V(n.y,t.y)}o(it,"axisAligned");function Kr(n,t){return gs(n.x,t.x)&&gs(n.y,t.y)}o(Kr,"strictlySamePoint");function Ks(n,t){return gs(n.x,t.x)||gs(n.y,t.y)}o(Ks,"strictlyAxisAligned");function Et(n,t){return qt(n,t)||!it(n,t)?null:V(n.y,t.y)?"horizontal":"vertical"}o(Et,"segmentDirection");function Js(n,t,e){if(V(n.x,t.x)&&V(t.x,e.x)||V(n.y,t.y)&&V(t.y,e.y))return!0;const s=(t.x-n.x)*(e.y-t.y)-(t.y-n.y)*(e.x-t.x);return Math.abs(s)<$}o(Js,"collinear");function Jr(n){return n instanceof O?n.mode:"auto"}o(Jr,"pointMode");function Q(n,t){return new y([n,t],!1)}o(Q,"rawPoint");function La(n){switch(n){case"left":return{x:-1,y:0};case"right":return{x:1,y:0};case"up":return{x:0,y:-1};case"down":return{x:0,y:1}}}o(La,"vectorFor");function ce(n,t){const e=La(t);return n.x*e.x+n.y*e.y}o(ce,"dot");function Qr(n,t,e=Jr(t)){return t instanceof O?(t.mode=e,t):new O(n,[t.x,t.y,e])}o(Qr,"asEdgePoint");function gt(n,t,e,s="auto"){return new O(n,[t,e,s])}o(gt,"makePoint");function $a(n){return n.getExtension(G)?.gridSize??50}o($a,"getGridSize");function Te(n,t){const e=n.parent.state.box,s=n.state.position;return Q(e.x+s.x*e.width+(t?.x??0),e.y+s.y*e.height+(t?.y??0))}o(Te,"endpointPoint");function lt(n,t){const e=n.parent.state.box;return new S([e.x-t,e.y-t,e.width+t*2,e.height+t*2],!1)}o(lt,"routingBox");function za(n,t,e){return n>=t-$&&n<=e+$}o(za,"coordinateWithinSpan");function to(n,t,e,s){let i=Number.POSITIVE_INFINITY;for(const a of e){if(t==="right"||t==="left"){if(!za(n.y,a.y-s,a.y+a.height+s))continue;const c=t==="right"?a.x-n.x:n.x-(a.x+a.width);c>$&&c<i&&(i=c);continue}if(!za(n.x,a.x-s,a.x+a.width+s))continue;const r=t==="down"?a.y-n.y:n.y-(a.y+a.height);r>$&&r<i&&(i=r)}return Number.isFinite(i)?i:null}o(to,"blockingDistance");function ps(n,t,e,s,i){const a=to(t,e,i,s),r=a!==null&&a<s*2?a/2:s,c=La(e);return gt(n,t.x+c.x*r,t.y+c.y*r)}o(ps,"adaptiveLeadPoint");function eo(n,t,e,s,i){if(s.orientation==="right"&&i.orientation==="left"&&e.x>t.x||s.orientation==="left"&&i.orientation==="right"&&e.x<t.x){const a=(t.x+e.x)/2;return[gt(n,a,t.y),gt(n,a,e.y)]}if(s.orientation==="down"&&i.orientation==="up"&&e.y>t.y||s.orientation==="up"&&i.orientation==="down"&&e.y<t.y){const a=(t.y+e.y)/2;return[gt(n,t.x,a),gt(n,e.x,a)]}return null}o(eo,"facingLeadPoints");function so(n,t,e,s){if(!Ks(n,t)||Kr(n,t))return!1;const i={x:t.x-n.x,y:t.y-n.y};return ce(i,e)>$&&ce(i,s)<-$}o(so,"directRouteIsValid");function Oa(n){const t=[],e=new Set;for(const s of n){const i=s.toFixed(3);e.has(i)||(e.add(i),t.push(s))}return t}o(Oa,"uniqueNumbers");function no(n){const t=[];for(const e of n){const s=t.at(-1);s&&qt(s,e)||t.push(e)}return t}o(no,"compactRawPoints");function Fa(n,t,e){if(!it(n,t))return 1;if(V(n.x,t.x)){const l=n.x,h=Math.min(n.y,t.y),u=Math.max(n.y,t.y),f=l>e.x+$&&l<e.x+e.width-$,p=u>e.y+$&&h<e.y+e.height-$;return f&&p?1:0}const s=n.y,i=Math.min(n.x,t.x),a=Math.max(n.x,t.x),r=s>e.y+$&&s<e.y+e.height-$,c=a>e.x+$&&i<e.x+e.width-$;return r&&c?1:0}o(Fa,"segmentCollisionPenalty");function io(n,t,e){if(!it(n,t))return 1;if(V(n.x,t.x)){const l=n.x,h=Math.min(n.y,t.y),u=Math.max(n.y,t.y),f=V(l,e.x)||V(l,e.x+e.width),p=Math.min(u,e.y+e.height)-Math.max(h,e.y);return f&&p>$?1:0}const s=n.y,i=Math.min(n.x,t.x),a=Math.max(n.x,t.x),r=V(s,e.y)||V(s,e.y+e.height),c=Math.min(a,e.x+e.width)-Math.max(i,e.x);return r&&c>$?1:0}o(io,"segmentBorderOverlapPenalty");function ao(n,t,e={}){let s=0,i=0,a=0,r=0,c=0,l=e.incomingDirection??null;for(let h=0;h<n.length-1;h++){const u=n[h],f=n[h+1];if(!it(u,f))return null;const p=Et(u,f);if(h===0&&e.avoidFirstDirection&&p===e.avoidFirstDirection&&(a+=1),h===0&&e.avoidFirstBacktrack){const m={x:f.x-u.x,y:f.y-u.y};if(ce(m,e.avoidFirstBacktrack)<-$)return null}if(h===n.length-2&&e.avoidLastDirection&&p===e.avoidLastDirection&&(a+=1),h===n.length-2&&e.avoidLastBacktrack){const m={x:u.x-f.x,y:u.y-f.y};if(ce(m,e.avoidLastBacktrack)<-$)return null}c+=Math.abs(u.x-f.x)+Math.abs(u.y-f.y),l&&p&&l!==p&&(r+=1),l=p;for(const m of t.obstacleBoxes)s+=Fa(u,f,m),i+=io(u,f,m)}return l&&e.outgoingDirection&&l!==e.outgoingDirection&&(r+=1),[s,i,a,r,c,n.length]}o(ao,"routeScore");function ro(n,t){if(!t)return!0;for(let e=0;e<n.length;e+=1)if(n[e]!==t[e])return n[e]<t[e];return!1}o(ro,"routeScoreIsBetter");function fs(n,t,e){return e.obstacleBoxes.some(s=>Fa(n,t,s)>0)}o(fs,"segmentHitsAnyBox");function Ha(n,t,e){return Ks(n,t)&&!fs(n,t,e)}o(Ha,"canCollapseToSegment");function ms(n,t,e,s={}){if(qt(n,t))return[n];let i=null,a=null;const r=o(h=>{const u=no(h),f=ao(u,e,s);f&&ro(f,a)&&(i=u,a=f)},"push");it(n,t)&&r([n,t]),r([n,Q(t.x,n.y),t]),r([n,Q(n.x,t.y),t]);const c=Oa([n.x,t.x,(n.x+t.x)/2,...e.laneBoxes.flatMap(h=>[h.x,h.x-e.gridSize,h.x+h.width,h.x+h.width+e.gridSize])]),l=Oa([n.y,t.y,(n.y+t.y)/2,...e.laneBoxes.flatMap(h=>[h.y,h.y-e.gridSize,h.y+h.height,h.y+h.height+e.gridSize])]);for(const h of c)r([n,Q(h,n.y),Q(h,t.y),t]);for(const h of l)r([n,Q(n.x,h),Q(t.x,h),t]);for(const h of c)for(const u of l)r([n,Q(h,n.y),Q(h,u),Q(t.x,u),t]),r([n,Q(n.x,u),Q(h,u),Q(h,t.y),t]);return i??[n,t]}o(ms,"routeBridge");function oo(n){const t=[];for(let e=0;e<n.length;e++){const s=n[e],i=n[e+1];if(s.manualAxes==="x"){const a=i?.manualAxes==="x"&&V(s.x,i.x)?[s,i]:[s];t.push({type:"line",direction:"vertical",coordinate:s.x,points:a}),e+=a.length-1;continue}if(s.manualAxes==="y"){const a=i?.manualAxes==="y"&&V(s.y,i.y)?[s,i]:[s];t.push({type:"line",direction:"horizontal",coordinate:s.y,points:a}),e+=a.length-1;continue}t.push({type:"point",point:s})}return t}o(oo,"manualRouteConstraints");function co(n,t){return n?n.type==="point"?n.point:n.direction==="vertical"?Q(n.coordinate,t.y):Q(t.x,n.coordinate):t}o(co,"constraintReferencePoint");function Ba(n,t,e){return n>t+$&&n<e-$}o(Ba,"valueInside");function ys(n,t,e,s,i,a){let r=e;const c=n==="x"?"y":"x",l=a.gridSize/2;for(const h of a.obstacleBoxes){const u=c==="x"?h.x:h.y,f=c==="x"?h.x+h.width:h.y+h.height,p=n==="x"?h.x:h.y,m=n==="x"?h.x+h.width:h.y+h.height;if(!Ba(t,u,f)||!Ba(r,p,m))continue;const x=i!==void 0?i-r:0,b=s-r,w=(p+m)/2;r=(Math.abs(x)>$?Math.sign(x):Math.abs(b)>$?Math.sign(b):r<w?-1:1)<0?p-l:m+l}return r}o(ys,"safeLineEndpointCoordinate");function lo(n,t,e,s,i){const a=n.points[0],r=n.points.at(-1),c=a?.copy()??gt(s,0,0),l=r?.copy()??gt(s,0,0);return c.parent=s,l.parent=s,n.direction==="vertical"?(c.addManualAxis("x"),l.addManualAxis("x"),c.x=n.coordinate,c.y=t.y,l.x=n.coordinate,l.y=e.y,i&&(c.y=ys("y",n.coordinate,c.y,e.y,a?.y,i),l.y=ys("y",n.coordinate,l.y,t.y,r?.y,i))):(c.addManualAxis("y"),l.addManualAxis("y"),c.x=t.x,c.y=n.coordinate,l.x=e.x,l.y=n.coordinate,i&&(c.x=ys("x",n.coordinate,c.x,e.x,a?.x,i),l.x=ys("x",n.coordinate,l.x,t.x,r?.x,i))),[c,l]}o(lo,"lineConstraintEndpoints");function ho(n,t){const e=new Map;return{copies:n.map(i=>{const a=i.copy();return a.parent=t,e.set(i,a),a}),copiesByOriginal:e}}o(ho,"copyRouteManualPoints");function uo(n,t,e){const s=t.get(n);if(s)return s;const i=n.copy();return i.parent=e,i}o(uo,"routePointCopy");function go(n,t){return n.find(e=>e.mode==="static")??n.find(e=>t.has(e)&&e.mode==="manual")??n.find(e=>t.has(e))??n.find(e=>e.mode==="manual")??n[0]}o(go,"pickPointFromDuplicateRun");function Qs(n,t){const e=[];for(let s=0;s<n.length;){let i=s+1;for(;i<n.length&&qt(n[s],n[i]);)i+=1;e.push(go(n.slice(s,i),t)),s=i}return e}o(Qs,"removeAdjacentDuplicates");function Ga(n,t,e,s){return n.mode==="static"?n[e]:t.mode==="static"?t[e]:s.has(n)?n[e]:s.has(t)?t[e]:n[e]}o(Ga,"coordinateAnchor");function Le(n,t){for(let e=0;e<n.length-1;e++){const s=n[e],i=n[e+1];if(V(s.x,i.x)){const a=Ga(s,i,"x",t);s.x=a,i.x=a}if(V(s.y,i.y)){const a=Ga(s,i,"y",t);s.y=a,i.y=a}}return n}o(Le,"snapNearlyAlignedPairs");function Ra(n,t,e){const s=[...n];let i=s.filter(a=>a.mode==="manual").length;for(let a=1;a<s.length-1;){const r=s[a],c=Js(s[a-1],r,s[a+1]),l=r.mode==="manual"&&t.has(r)&&i>e;if(r.mode==="manual"&&c&&i<=e){const h=s[a+1];if(a+2<s.length&&h.mode==="auto"&&!t.has(h)){s.splice(a+1,1);continue}const u=s[a-1];if(a-2>=0&&u.mode==="auto"&&!t.has(u)){s.splice(a-1,1),a=Math.max(1,a-1);continue}}if(r.mode==="static"||t.has(r)&&!l||!c){a+=1;continue}if(r.mode==="manual"&&i<=e){a+=1;continue}r.mode==="manual"&&(i-=1),s.splice(a,1)}return s}o(Ra,"removeRedundantCollinearPoints");function tn(n,t,e){const s=[...n];for(let i=0;i<s.length-3;){const a=s[i],r=s[i+1],c=s[i+2],l=s[i+3];if(!(it(a,r)&&it(r,c)&&it(c,l))||!Ha(a,l,t)){i+=1;continue}if(r.mode!=="auto"||c.mode!=="auto"||e.has(r)||e.has(c)){i+=1;continue}s.splice(i+1,2)}return s}o(tn,"collapseAutoDetours");function Va(n,t,e){const s=[...n];for(let i=!0;i;){i=!1;for(let a=0;a<s.length-3;a++){const r=s[a],c=s[a+1],l=s[a+2],h=s[a+3];if(c.mode==="auto"&&l.mode==="auto"&&!e.has(c)&&!e.has(l)&&it(r,c)&&it(c,l)&&it(l,h)&&Ha(r,h,t)){s.splice(a+1,2),i=!0;break}}}return s}o(Va,"collapseAnyAutoRectangles");function po(n,t,e,s){const i=new O(null,[t.x,n.y,"auto"]),a=new O(null,[n.x,t.y,"auto"]),r=o(c=>{let l=0;return e&&it(e,c)&&(l+=1),s&&it(c,s)&&(l+=1),n.mode==="manual"&&e&&Et(e,n)===Et(n,c)&&(l-=2),t.mode==="manual"&&s&&Et(c,t)===Et(t,s)&&(l-=2),l},"score");return r(i)>=r(a)?i:a}o(po,"chooseCorner");function en(n,t){if(n.length<2)return n;const e=[n[0]];for(let s=1;s<n.length;s++){const i=e.at(-1),a=n[s];if(!Ks(i,a)){const r=e.length>=2?e[e.length-2]:void 0,c=s+1<n.length?n[s+1]:void 0,l=po(i,a,r,c);l.parent=t,e.push(l)}e.push(a)}return e}o(en,"ensureOrthogonalAdjacency");function Ya(n,t,e=new Set){let s=n.map(a=>Qr(t.parent,a));const i=s.some(a=>a.mode==="manual"&&a.manualAxes==="both")?1:0;for(let a=0;a<4;a++){const r=s.length;if(s=Le(s,e),s=en(s,t.parent),s=Le(s,e),s=Qs(s,e),s=Ra(s,e,i),s=tn(s,t,e),s.length===r)break}return s=Le(s,e),s=en(s,t.parent),s=Qs(s,e),s=tn(s,t,e),s=Va(s,t,e),s=Ra(s,e,i),s.length>0&&(s[0].markStatic(),s.at(-1).markStatic()),s}o(Ya,"normalizeEdgePoints");function Wa(n,t){const e=n.findIndex((s,i)=>i>0&&i<n.length-1&&qt(s,t));e>=0&&n.splice(e,1)}o(Wa,"removeSameCoordinateInteriorPoint");function Za(n,t,e,s){let i=[...n];if(i.length<2)return i;qt(i[1],e)?i[1]=e:(Wa(i,e),i.splice(1,0,e));const a=i.length-2;if(a<1)return i;qt(i[a],s)?i[a]=s:(Wa(i,s),i.splice(i.length-1,0,s));const r=new Set([e,s]);return i=Le(i,r),i=en(i,t.parent),i=Le(i,r),i=Qs(i,r),i=tn(i,t,r),i=Va(i,t,r),i.length>0&&(i[0].markStatic(),i.at(-1).markStatic()),i}o(Za,"ensureEndpointLeadPresence");function fo(n,t,e,s,i){if(!e||!Js(n,t,e))return!1;const a={x:e.x-n.x,y:e.y-n.y};return ce(a,s)>$&&!fs(n,e,i)}o(fo,"canRemoveSourceLead");function mo(n,t,e,s,i){if(!n||!Js(n,t,e))return!1;const a={x:e.x-n.x,y:e.y-n.y};return ce(a,s)<-$&&!fs(n,e,i)}o(mo,"canRemoveTargetLead");function Xa(n,t,e,s){const i=[...n];return i.length>2&&fo(i[0],i[1],i[2],t,s)&&i.splice(1,1),i.length>2&&mo(i.at(-3),i.at(-2),i.at(-1),e,s)&&i.splice(i.length-2,1),i.length>0&&(i[0].markStatic(),i.at(-1).markStatic()),i}o(Xa,"compactRedundantEndpointLeads");function sn(n,t,e,s,i){const a=gt(i.parent,Te(n,e).x,Te(n,e).y,"static"),r=Te(t,s),c=gt(i.parent,r.x,r.y,"static");if(so(a,c,n.orientation,t.orientation))return[a,c];const l=eo(i.parent,a,c,n,t),h=l?.[0]??ps(i.parent,a,n.orientation,i.gridSize,[lt(t,0)]),u=l?.[1]??ps(i.parent,c,t.orientation,i.gridSize,[lt(n,0)]),f=new Set([h,u]),p=ms(h,u,i,{avoidFirstBacktrack:n.orientation,avoidLastBacktrack:t.orientation,incomingDirection:Et(a,h)??void 0,outgoingDirection:Et(u,c)??void 0}),m=Ya([a,...p,c],i,f);return Xa(Za(m,i,h,u),n.orientation,t.orientation,i)}o(sn,"routeAuto");function yo(n,t,e,s,i,a=null){const r=$a(n),c={gridSize:r,obstacleBoxes:[lt(t,0),lt(e,0)],laneBoxes:[lt(t,r/2),lt(e,r/2)],parent:a};return sn(t,e,s,i,c)}o(yo,"routeOrthogonalBetweenGateways");function xo(n,t,e=[],s){const i=$a(n),a={gridSize:i,obstacleBoxes:[lt(t.from,0),lt(t.to,0)],laneBoxes:[lt(t.from,i/2),lt(t.to,i/2)],parent:t},r=t.steps.filter((B,X)=>X>0&&X<t.steps.length-1&&B.mode==="manual");if(r.length===0)return sn(t.from,t.to,t.state.displacementStart,t.state.displacementEnd,a);const c=Te(t.from,t.state.displacementStart),l=Te(t.to,t.state.displacementEnd),h=gt(a.parent,c.x,c.y,"static"),u=gt(a.parent,l.x,l.y,"static"),f=ps(a.parent,h,t.from.orientation,i,[lt(t.to,0)]),p=ps(a.parent,u,t.to.orientation,i,[lt(t.from,0)]),{copies:m,copiesByOriginal:x}=ho(r,a.parent),b=e.map(B=>uo(B,x,a.parent)),w=new Set([f,p,...b]),v=oo(m),_=[h,f];let E=f;for(let B=0;B<v.length;B++){const X=v[B],wt=E instanceof O&&E.mode==="manual"?Et(_.at(-2),E)??void 0:void 0;if(X.type==="point"){const Ca=ms(E,X.point,a,{avoidFirstDirection:wt,avoidFirstBacktrack:B===0?t.from.orientation:void 0});_.push(...Ca.slice(1)),E=X.point;continue}const rt=co(v[B+1],p);let[nt,ot]=lo(X,E,rt,a.parent,a);if(fs(nt,ot,a))continue;const vt=ms(E,nt,a,{avoidFirstDirection:wt,avoidFirstBacktrack:B===0?t.from.orientation:void 0});_.push(...vt.slice(1),ot),E=ot}const C=E instanceof O&&E.mode==="manual"?Et(_.at(-2),E)??void 0:void 0,k=ms(E,p,a,{avoidFirstDirection:C,avoidLastDirection:Et(p,u)??void 0,avoidLastBacktrack:t.to.orientation});_.push(...k.slice(1),u);const P=Ya(_,a,w),I=Xa(Za(P,a,f,p),t.from.orientation,t.to.orientation,a);return I.some(B=>B.mode==="manual")?I:sn(t.from,t.to,t.state.displacementStart,t.state.displacementEnd,a)}o(xo,"routeOrthogonalEdge");const Pi=class Pi extends Ne{findAutomaticStartPoint(t){return t.from.parent.findAutomaticGatewayAnchor(t.to.parent.box.middle)}findAutomaticEndPoint(t){return t.to.parent.findAutomaticGatewayAnchor(t.from.parent.box.middle)}findRoute(t,e,s,i){return xo(t,e)}findRouteBetween(t,e,s,i=new y,a=new y){return yo(t,e,s,i,a)}};o(Pi,"OrthogonalRouter");let xs=Pi;const Ci=class Ci extends Ne{findAutomaticStartPoint(t){return t.from.parent.findAutomaticConnectionAnchor(t.to.parent.box.middle)}findAutomaticEndPoint(t){return t.to.parent.findAutomaticConnectionAnchor(t.from.parent.box.middle)}findRoute(t,e,s,i){return[s.point,i.point]}};o(Ci,"StraightRouter");let nn=Ci;const bo={orthogonal:new xs,straight:new nn,curved:new Us};function qa(n){return bo[n]}o(qa,"getEdgesRouter");const Ii=class Ii extends Yt{state;constructor(t,e){super(t),this.state={allowDisplace:!0,stroke:"transparent",strokeWidth:10,radius:5,incomingEdges:[],outgoingEdges:[],position:new y,...e},g.makeObservable(this,{addIncomingEdge:g.action,addOutgoingEdge:g.action,state:g.observable,removeIncomingEdge:g.action,removeOutgoingEdge:g.action})}addIncomingEdge(t,e=!0){this.state.incomingEdges.find(s=>s.id===t.id)||this.state.incomingEdges.push(t)}addOutgoingEdge(t,e=!0){this.state.outgoingEdges.find(s=>s.id===t.id)||(this.state.outgoingEdges.push(t),e&&t.steps.length===0&&this.updateEdges())}canConnect(t,e){const s=this.state.incomingEdges.filter(i=>i!==e);return(this.state.maxIncomingConnections===void 0||this.state.maxIncomingConnections>s.length)&&!s.find(i=>i.from===t)}canStartConnection(t,e){const s=this.state.outgoingEdges.filter(i=>i!==e);return(this.state.maxOutgoingConnections===void 0||this.state.maxOutgoingConnections>s.length)&&!s.find(i=>i.to===t)}connectionDisplacement(t){return this.direction==="horizontal"&&Math.abs(t.y-this.coordinates.y)>10?new y([0,t.y-this.coordinates.y]):this.direction==="vertical"&&Math.abs(t.x-this.coordinates.x)>10?new y([t.x-this.coordinates.x,0]):new y([0,0])}connectionDistance(t){if(this.direction==="vertical"){const s=Math.abs(this.coordinates.y-t.y);return s<20?Math.abs(this.coordinates.x-t.x)+s**5:1/0}const e=Math.abs(this.coordinates.x-t.x);return e<20?Math.abs(this.coordinates.y-t.y)+e**5:1/0}removeIncomingEdge(t){for(let e=this.state.incomingEdges.length-1;e>=0;e--)this.state.incomingEdges[e].id===t.id&&this.state.incomingEdges.splice(e,1)}removeOutgoingEdge(t){for(let e=this.state.outgoingEdges.length-1;e>=0;e--)this.state.outgoingEdges[e].id===t.id&&this.state.outgoingEdges.splice(e,1)}get coordinates(){return this.state.position.copy().multiply(this.parent.box.size).sum(this.parent.coordinates)}get fill(){return this.state.fill}get diagram(){return this.parent.diagram}get incomingEdges(){return[...this.state.incomingEdges]}get outgoingEdges(){return[...this.state.outgoingEdges]}get radius(){return this.state.radius}get relativePosition(){return this.state.position.copy()}get stroke(){return this.state.stroke}get strokeWidth(){return this.state.strokeWidth}get id(){return this.state.id}get direction(){return["down","up"].includes(this.state.orientation)?"vertical":"horizontal"}get orientation(){return this.state.orientation}recomputeConnectedEdge(t,e){t.setSteps(qa(t.pathType).route(this.diagram,t))}updateEdges(){for(const t of this.state.incomingEdges)this.recomputeConnectedEdge(t,"to");for(const t of this.state.outgoingEdges)this.recomputeConnectedEdge(t,"from")}get remainingSlots(){return this.state.maxOutgoingConnections-this.state.outgoingEdges.length}deserialize(t){this.state.fill=t.fill,this.state.id=t.id,this.state.orientation=t.orientation,this.state.radius=t.radius,this.state.stroke=t.stroke,this.state.strokeWidth=t.strokeWidth,this.state.position.assign(t.coordinates),t.outEdges.forEach(e=>{const s=this.diagram.getClass(e.class);if(!s)throw new Error(`Unknown edge class '${e.class}' on gateway '${this.id}'.`);const i=new s(this,{from:this});this.diagram.getNodeById(e.toParentId)&&i.deserialize(e)})}serialize(){const{fill:t,id:e,orientation:s,radius:i,stroke:a,strokeWidth:r,state:{position:{raw:c}}}=this,l=this.outgoingEdges.map(h=>h.serialize());return{coordinates:c,fill:t,id:e,orientation:s,radius:i,stroke:a,strokeWidth:r,outEdges:l,class:this.constructor.name}}};o(Ii,"Gateway");let Ht=Ii;const bs=250;let ws=(fe=class extends Yt{_gateways=new Map;state;classList=new qs;edgesAsGateways=!1;requiredEdgePathType=null;edgeGatewayShape="rectangle";get selected(){return this.state.selected}get hovered(){return this.diagram?.hoveredNode===this}constructor(t,e){super(t),this.state={...e,box:e.box??new S([0,0,100,80]),hover:!1,zIndex:e.zIndex??100},this.classList.add("diagram__node"),g.makeObservable(this,{state:g.observable,hovered:g.computed,labelOffset:g.computed,selected:g.computed,_gateways:g.observable,setLabelOffset:g.action,setState:g.action}),this.initializeGateways()}canSelect(){return!this.state.selected&&this.state.selectable!==!1}canUnselect(){return!!this.state.selected}setDiagram(t){const e=this.diagram;e&&e!==t&&e.setNodeHover(this,!1),this.parent=t}setState(t,e){if(t==="hover"){this.setHovered(e===!0);return}this.state[t]=e}setHovered(t){this.diagram?.setNodeHover(this,t)}initializeGateways(){this._gateways.set("left",new Ht(this,{maxIncomingConnections:1/0,maxOutgoingConnections:1/0,id:"left",orientation:"left",position:new y([0,.5])})),this._gateways.set("right",new Ht(this,{maxIncomingConnections:1/0,maxOutgoingConnections:1/0,id:"right",orientation:"right",position:new y([1,.5])})),this._gateways.set("up",new Ht(this,{maxIncomingConnections:1/0,maxOutgoingConnections:1/0,id:"up",orientation:"up",position:new y([.5,0])})),this._gateways.set("down",new Ht(this,{maxIncomingConnections:1/0,maxOutgoingConnections:1/0,id:"down",orientation:"down",position:new y([.5,1])}))}get box(){return this.state.box.copy()}get coordinates(){return this.box.coordinates}displace(t){this.state.box.sum([...t.raw,0,0])}get id(){return this.state.id}get labelOffset(){const t=this.state.labelOffset;return!Array.isArray(t)||t.length!==2||!Number.isFinite(t[0])||!Number.isFinite(t[1])?new y:new y(t)}setLabelOffset(t){const e=t instanceof y?t:new y(t);this.state.labelOffset=[Math.max(-bs,Math.min(bs,e.x)),Math.max(-bs,Math.min(bs,e.y))]}get gateways(){return[...this._gateways.values()]}dragEventMouseStartPosition=null;dragEventStartPosition=null;getGateway(t){return this._gateways.get(t)}boundaryPoint(t,e){const s=this.box,i=s.middle,a=Math.max(s.width/2,.001),r=Math.max(s.height/2,.001);let c=t.x-i.x,l=t.y-i.y;if(Math.abs(c)<.001&&Math.abs(l)<.001&&(c=a,l=0),this.edgeGatewayShape==="ellipse"){const u=1/Math.sqrt(c*c/(a*a)+l*l/(r*r));return new y([i.x+c*u,i.y+l*u])}if(this.edgeGatewayShape==="diamond"){const u=1/(Math.abs(c)/a+Math.abs(l)/r);return new y([i.x+c*u,i.y+l*u])}if(!e||!s.collides(t)){const u=1/Math.max(Math.abs(c)/a,Math.abs(l)/r);return new y([i.x+c*u,i.y+l*u])}const h=[{value:Math.abs(t.x-s.x),point:[s.x,t.y]},{value:Math.abs(t.x-(s.x+s.width)),point:[s.x+s.width,t.y]},{value:Math.abs(t.y-s.y),point:[t.x,s.y]},{value:Math.abs(t.y-(s.y+s.height)),point:[t.x,s.y+s.height]}];return new y(h.reduce((u,f)=>f.value<u.value?f:u).point)}anchorForBoundaryPoint(t){const e=this.box,s=e.middle,i=(t.x-s.x)/Math.max(e.width/2,.001),a=(t.y-s.y)/Math.max(e.height/2,.001),r=Math.abs(i)>=Math.abs(a)?i>=0?"right":"left":a>=0?"down":"up",c=this.getGateway(r)??this.getGateway("center")??this.gateways[0];if(!c)throw new Error(`Node ${this.id} has no gateway for a boundary anchor`);const l=new y([(t.x-e.x)/Math.max(e.width,.001),(t.y-e.y)/Math.max(e.height,.001)]);return{gateway:c,point:t,relativePosition:l,displacement:t.copy().substract(c.coordinates)}}findFixedConnectionAnchor(t){return this.anchorForBoundaryPoint(this.boundaryPoint(t,!0))}findAxisAlignedConnectionAnchor(t,e){const s=this.box,i=s.middle,a=Math.max(s.width/2,.001),r=Math.max(s.height/2,.001),c=e==="horizontal",l=c?(t.y-i.y)/r:(t.x-i.x)/a;if(Math.abs(l)>1)return null;let h=c?a:r;this.edgeGatewayShape==="ellipse"?h*=Math.sqrt(Math.max(0,1-l**2)):this.edgeGatewayShape==="diamond"&&(h*=1-Math.abs(l));const u=c?t.x<=i.x?-1:1:t.y<=i.y?-1:1,f=c?new y([i.x+u*h,t.y]):new y([t.x,i.y+u*h]);return this.anchorForBoundaryPoint(f)}findAutomaticConnectionAnchor(t){return this.anchorForBoundaryPoint(this.boundaryPoint(t,!1))}findAutomaticGatewayAnchor(t){const e=this.gateways.filter(i=>{const a=i.relativePosition;return a.x<=0||a.x>=1||a.y<=0||a.y>=1}),s=(e.length?e:this.gateways).map(i=>({candidate:i,distance:i.coordinates.distance(t)})).sort((i,a)=>i.distance-a.distance)[0]?.candidate;return s?{gateway:s,point:s.coordinates.copy(),relativePosition:s.relativePosition,displacement:new y}:this.findAutomaticConnectionAnchor(t)}findRelativeConnectionAnchor(t){const e=this.box,s=new y([e.x+t.x*e.width,e.y+t.y*e.height]);return this.anchorForBoundaryPoint(this.boundaryPoint(s,!0))}usesAutomaticConnectionPoint(t){if(!this.edgesAsGateways||!this.box.collides(t))return!1;const e=this.boundaryPoint(t,!0),s=Math.min(24,Math.min(this.box.width,this.box.height)/4);return t.distance(e)>s}get connectionBoundaryPath(){const t=this.box;if(this.edgeGatewayShape==="ellipse"){const e=t.width/2,s=t.y+t.height/2;return`M ${t.x} ${s} A ${e} ${t.height/2} 0 1 0 ${t.x+t.width} ${s} A ${e} ${t.height/2} 0 1 0 ${t.x} ${s}`}return this.edgeGatewayShape==="diamond"?`M ${t.x+t.width/2} ${t.y} L ${t.x+t.width} ${t.y+t.height/2} L ${t.x+t.width/2} ${t.y+t.height} L ${t.x} ${t.y+t.height/2} Z`:`M ${t.x} ${t.y} H ${t.x+t.width} V ${t.y+t.height} H ${t.x} Z`}setDimentions(t){this.state.box.assignDimensions(t)}updateConnectedEdges(){const t=new Set;for(const e of this._gateways.values())e.incomingEdges.forEach(s=>t.add(s)),e.outgoingEdges.forEach(s=>t.add(s));t.forEach(e=>e.from.recomputeConnectedEdge(e,"from"))}setPosition(t,e){const s=new S(this.state.box.raw,!1);this.state.box.assignCoordinates(t).bound(new S([0,0,...this.diagram.canvas.size.raw],!1)),e?.updateConnectedEdges!==!1&&s.substract(this.state.box).norm&&this.updateConnectedEdges()}deserialize(t){this.state.box.assign(t.box),this.state.id=t.id,this.state.label=t.label,this.state.movable=t.movable,this.state.selectable=t.selectable,this.state.fill=t.fill,this.state.labelFontSize=t.labelFontSize,this.setLabelOffset(t.labelOffset??[0,0]),this.state.stroke=t.stroke,this.state.strokewWidth=t.strokewWidth,t.gateways.forEach(e=>{const s=this._gateways.get(e.id)?.incomingEdges||[],i=this.diagram?.getClass(e.class);if(!i)throw new Error(`Unknown gateway class '${e.class}' on node '${this.id}'.`);const a=new i(this,{id:e.id});this._gateways.set(e.id,a);for(const r of s)r.setState("to",a),a.addIncomingEdge(r)}),t.gateways.forEach(e=>{this._gateways.get(e.id)?.deserialize(e)}),this._gateways.forEach(e=>e.outgoingEdges.forEach(s=>{this.diagram?.connectWithEdge(s.from,s.to,s)}))}serialize(){const{box:{raw:t},id:e,label:s,movable:i,selectable:a,fill:r,labelFontSize:c,labelOffset:l,selected:h,stroke:u,strokewWidth:f}=this.state,p=this.gateways.map(m=>m.serialize());return{box:t,id:e,label:s,movable:i,selectable:a,selected:h,gateways:p,fill:r,labelFontSize:c,labelOffset:l?[...l]:void 0,stroke:u,strokewWidth:f,class:this.constructor.name}}remapSerializedReferences(t,e){return t}RenderOverlay=null;RenderScreen=null},o(fe,"Node"),fe);const Di=class Di extends z{selectionMode="element";_selection=new Set;_edgesSelection=new Set;autopan=new ut(this.diagram);pointerPoint=null;endPoint=null;startPoint=null;copy(){const t=[],e=new Map,s=[];for(const i of this._selection){const a=Pe(this.diagram,"node",s);e.set(i.id,a),s.push(a)}for(const i of this._selection){const a=i.remapSerializedReferences(i.serialize(),e);a.id=e.get(a.id),a.gateways.forEach(r=>{r.outEdges.forEach(c=>{c.toParentId=e.get(c.toParentId)})}),t.push(a)}return JSON.stringify({nodes:t})}init(){g.makeObservable(this,{_edgesSelection:g.observable,_selection:g.observable,box:g.computed,clearSelection:g.action,endPoint:g.observable,selectEdge:g.action,selectedNodes:g.computed,selectedEdges:g.computed,selectionMode:g.observable,selectNode:g.action,startPoint:g.observable,toggleSelectionMode:g.action,unselectEdge:g.action,unselectNode:g.action,handleMouseUp:g.action}),this.diagram.onEvent(Pt,this.handleMouseDown.bind(this),this.diagram.priorities.Mouse_Down_Selector),this.diagram.onEvent(ie,t=>{g.runInAction(()=>this._selection.delete(t.node))}),this.diagram.onEvent(as,t=>{g.runInAction(()=>this._edgesSelection.delete(t.edge))}),g.runInAction(()=>{for(const t of this.diagram.nodes)t.selected&&this._selection.add(t)})}toggleSelectionMode(t=this.selectionMode==="area"?"element":"area"){this.selectionMode=t}get selectedNodes(){return[...this._selection]}get selectedEdges(){return[...this._edgesSelection]}get box(){return!this.startPoint||!this.endPoint?new S:new S([...this.startPoint.raw,...this.endPoint.copy().substract(this.startPoint).raw])}clearSelection(t=()=>!0){for(const e of this._selection)t(e)&&this.unselectNode(e);for(const e of this._edgesSelection)this.unselectEdge(e)}selectEdge(t){this.emit(new rs(t,!0)).cancelled||(t.setState("selected",!0),this._edgesSelection.add(t))}selectNode(t){t.canSelect()&&!this.emit(new ke(t,!0)).cancelled&&(t.setState("selected",!0),this._selection.add(t))}unselectEdge(t){this.emit(new rs(t,!1)).cancelled||(t.setState("selected",!1),this._edgesSelection.delete(t))}unselectNode(t){t.canUnselect()&&!this.emit(new ke(t,!1)).cancelled&&(t.setState("selected",!1),this._selection.delete(t))}unbind=o(()=>{},"unbind");handleMouseDown=o(t=>{if(this.unbind(),t.originalEvent.button!==1)if(this.selectionMode==="area"){const e=new y(t.originalEvent);g.runInAction(()=>{this.startPoint=this.diagram.canvas.inverseFit(e)}),t.cancel(),this.unbind=pt(It(this,tt,this.handleMouseUp),It(this,Ct,this.handleMouseMove),vs(this.handleSelectionInterval.bind(this),30))}else{const e=t.edge,s=t.node,i=e?.state.selected??s?.selected;!t.ctrl&&!t.shift&&!i&&(e||s?this.clearSelection():t.originalEvent.button===0&&this.bindEmptyCanvasGesture(t)),e?this.selectEdge(e):s&&this.selectNode(s)}},"handleMouseDown");bindEmptyCanvasGesture(t){const e=new y(t.originalEvent);let s=!1;const i=o(r=>{s||=!new y(r.originalEvent).equals(e)},"handleMove"),a=o(()=>{const r=this.unbind;this.unbind=()=>{},r(),s||this.clearSelection()},"handleUp");this.unbind=pt(It(this,Ct,i),It(this,tt,a))}handleMouseMove=o(t=>{g.runInAction(()=>{this.pointerPoint=new y(t.originalEvent)}),this.updateAreaSelection(!1)},"handleMouseMove");handleSelectionInterval(){this.updateAreaSelection(!0)}updateAreaSelection(t){if(!this.pointerPoint||!this.startPoint)return;const e=this.pointerPoint;t&&this.autopan.displace(e),g.runInAction(()=>{this.endPoint=this.diagram.canvas.inverseFit(e)});for(const s of this.diagram.nodes){s.box.collides(this.box)?this.selectNode(s):this.unselectNode(s);for(const i of s.gateways)for(const a of i.outgoingEdges)if(a.collides(this.box)){this.selectEdge(a);break}else this.unselectEdge(a)}}handleMouseUp=o(t=>{this.unbind(),this.endPoint=null,this.startPoint=null,this.pointerPoint=null},"handleMouseUp")};o(Di,"Selector");let Y=Di;const ji=class ji extends z{hotkeys=[];isEditableTarget(t){return t instanceof HTMLElement?t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement||t instanceof HTMLButtonElement||t.isContentEditable:!1}shouldIgnoreHotkeys(t){return this.isEditableTarget(t.originalEvent.target)}get measurer(){return this.diagram.getExtension(De)}get selector(){return this.diagram.getExtension(Y)}match(t,e){return!(e.ctrl!==void 0&&t.ctrl!==e.ctrl||e.shift!==void 0&&t.shift!==e.shift||e.alt!==void 0&&t.alt!==e.alt||e.code!==void 0&&t.code!==e.code)}init(){this.diagram.onEvent(Rt,async t=>{if(!this.shouldIgnoreHotkeys(t)&&!this.revertHotkey.has(t.code)){for(const e of this.hotkeys)if(this.match(t,e)&&(e.cb(t),!t.spreads))return;switch(t.code){case"Space":{const e=this.measurer.enabled,s=!e&&this.selector.selectionMode==="area";e||this.selector.toggleSelectionMode(s?"element":"area"),this.revertHotkey.set(t.code,()=>{e?this.measurer.toggle():this.selector.toggleSelectionMode(s?"area":"element")});break}case"KeyC":t.ctrl&&navigator.clipboard.writeText(this.selector.copy());break;case"KeyV":t.ctrl&&this.diagram.paste(await navigator.clipboard.readText());break;case"KeyM":this.selector.toggleSelectionMode("element");break;case"KeyS":t.ctrl?(t.originalEvent.preventDefault(),Yr(this.diagram.export(),"diagram-save.json","application/json")):this.selector.toggleSelectionMode("area");break;case"KeyZ":t.ctrl&&this.diagram.getExtension(Ie).undo();break;case"KeyY":t.ctrl&&this.diagram.getExtension(Ie).redo();break;case"ControlLeft":case"ControlRight":t.cancel();{const e=this.diagram.getExtension(G),s=this.diagram.getExtension(Zt),i=this.diagram.getExtension(Ce),a=e?.enabled,r=s?.enabled,c=i?.enabled;e?.toggle(!a,!1),s?.toggle(!r,!1),i?.toggle(!c,!1),this.revertHotkey.set(t.code,()=>{a!==void 0&&e?.toggle(a,!1),r!==void 0&&s?.toggle(r,!1),c!==void 0&&i?.toggle(c,!1)})}break;case"Delete":{const e=this.diagram.getExtension(Y);e.selectedNodes.forEach(s=>{this.diagram.delete(s)}),e.selectedEdges.forEach(s=>{this.diagram.disconnect(s)})}}}}),document.addEventListener("keyup",()=>{for(const t of this.revertHotkey.keys())this.revertHotkey.get(t)?.(),this.revertHotkey.delete(t)})}register(t){return this.hotkeys.push(t),()=>{this.hotkeys=this.hotkeys.filter(e=>e!==t)}}revertHotkey=new Map};o(ji,"Hotkeys");let an=ji;function It(n,t,e,s){if(n.diagram){const i=e.bind(n);return n.diagram.onEvent(t,i,s),()=>{n.diagram?.offEvent(t,i)}}throw new Error("Cannot bind to unexistent diagram")}o(It,"bindDiagram");function R(n,t,e,s){const i=e.bind(n);return document.addEventListener(t,i,s),()=>{document.removeEventListener(t,i,s)}}o(R,"bindDocument");function vs(n,t){const e=setInterval(n,t);return()=>{clearInterval(e)}}o(vs,"bindInterval");function wo(n,t){const e=setTimeout(n,t);return()=>{clearTimeout(e)}}o(wo,"bindTimeout");function pt(...n){return()=>{n.forEach(t=>t())}}o(pt,"bind");let vo=(me=class extends Yt{unbindDocumentEvents=[];mouseSessionStartedInFrame=!1;centerAnimationFrame=null;_displacement=new y([-5e3,-5e3]);_scale=1;gridSize=50;size=new y([1e6,1e6]);get scale(){return this._scale}element=null;get elementPosition(){if(!this.element)return new y([0,0]);const t=this.element.getBoundingClientRect();return new y([t.x,t.y])}get elementDimensions(){if(!this.element)return new S([0,0,0,0]);const t=this.element.getBoundingClientRect();return new S([t.x,t.y,t.width,t.height])}get displacement(){return this._displacement.copy()}get framePosition(){if(!this.element)return new y([0,0]);const t=this.element.parentElement.getBoundingClientRect();return new y([t.x,t.y])}get frameDimensions(){if(!this.element)return new S([0,0,0,0]);const t=this.element.parentElement.getBoundingClientRect();return new S([t.x,t.y,t.width,t.height])}constructor(t){super(t),g.makeObservable(this,{_scale:g.observable,setScale:g.action}),this.unbindDocumentEvents.push(R(this,"click",this.handleClick),R(this,"dblclick",this.handleDoubleClick),R(this,"wheel",this.handleWheel),R(this,"mouseup",this.handleMouseUp),R(this,"mousedown",this.handleMouseDown),R(this,"mousemove",this.handleMouseMove),R(this,"keyup",this.handleKeyUp),R(this,"keypress",this.handleKeyPress),R(this,"keydown",this.handleKeyDown))}dispose(){this.cancelCenterAnimation();for(const t of this.unbindDocumentEvents.splice(0))t()}markMouseSessionStartedInFrame(){this.mouseSessionStartedInFrame=!0}get dragging(){return this._dragging}_dragging=!1;displacementStart=null;eventStart=null;bound(){const t=this.element?.parentElement?.getBoundingClientRect(),e=t?new y([t.width,t.height]).divide(this.scale):new y,s=new S([...this.size.copy().multiply(-1).raw,...e.raw]).multiply(.9);this._displacement.bound(s)}centerOnPoint(t,e=!1){const s=this.frameDimensions,i=new y([s.width/(2*this.scale)-t.x,s.height/(2*this.scale)-t.y]);if(!e||typeof requestAnimationFrame>"u"){this.setDisplacement(i);return}this.animateDisplacement(i)}animateDisplacement(t){this.cancelCenterAnimation();const e=this.displacement,s=t.copy(!1).substract(e);let i=null;const a=240,r=o(c=>{i??=c;const l=Math.min(1,(c-i)/a),h=1-(1-l)**3;this.applyDisplacement(e.copy(!1).sum(s.copy(!1).multiply(h))),l<1?this.centerAnimationFrame=requestAnimationFrame(r):this.centerAnimationFrame=null},"update");this.centerAnimationFrame=requestAnimationFrame(r)}cancelCenterAnimation(){this.centerAnimationFrame!==null&&(cancelAnimationFrame(this.centerAnimationFrame),this.centerAnimationFrame=null)}applyDisplacement(t){this._displacement.assign(t),this.bound(),this.setDisplacementStyles()}displace(t){this.cancelCenterAnimation(),this._displacement.sum(t);const e=this._displacement.copy();return this.bound(),this.setDisplacementStyles(),t.copy().substract(this._displacement.copy().substract(e))}setDisplacement(t){this.cancelCenterAnimation(),this.applyDisplacement(t)}setScale(t,e=new y([0,0])){this.cancelCenterAnimation();const s=this.inverseFit(e),i=s.copy(),a=this.displacement,r=Math.max(.3,Math.min(3,t));if(r!==this.scale){const c=s.copy().multiply(this.scale).sum(a.copy().multiply(this.scale)).substract(i.copy().multiply(r)).divide(r);this.emit(new Ee(this,c.copy().substract(this.displacement),r,this.scale)).cancelled||(this._scale=r,this._displacement.assign(c),this.bound(),this.setDisplacementStyles())}}fit(t){return t instanceof y?this._displacement.copy().sum([t.x,t.y]).multiply(this.scale):t instanceof S?new S([...this._displacement.copy().sum([t.x,t.y]).multiply(this.scale).raw,...t.size.multiply(this.scale).raw]):t*this.scale}inverseFit(t){return t instanceof y?t.copy().substract(this.framePosition).divide(this.scale).substract([this._displacement.x,this._displacement.y]):t.copy().substract(this.framePosition.toDimensions(new y([0,0]))).divide(this.scale).substract([this._displacement.x,this._displacement.y,0,0])}getDisplacementStyles(){const t=this._displacement.copy(!1).multiply(this.scale);return{position:"relative",width:`${this.size.x}px`,height:`${this.size.y}px`,transform:`translate(${t.x}px, ${t.y}px) scale(${this.scale})`,transformOrigin:"0 0",willChange:"transform"}}setDisplacementStyles(t=this.element){if(t){const e=this._displacement.copy(!1).multiply(this.scale),s=t.parentElement;if(t.dataset.setStyles="true",t.style.position="relative",t.style.width=`${this.size.x}px`,t.style.height=`${this.size.y}px`,t.style.transform=`translate(${e.x}px, ${e.y}px) scale(${this.scale})`,t.style.transformOrigin="0 0",t.style.zoom="",t.style.willChange="transform",s){const i=this.gridSize*this.scale,a=i*10,c=(Math.max(.3,Math.min(1,this.scale))-.3)/.7;s.style.setProperty("--diagram-canvas-scale",String(this.scale)),s.style.setProperty("--diagram-canvas-translate-x",`${e.x}px`),s.style.setProperty("--diagram-canvas-translate-y",`${e.y}px`),s.style.setProperty("--diagram-grid-zoom-ratio",String(c)),s.style.setProperty("--diagram-grid-size",`${i}px`),s.style.setProperty("--diagram-major-grid-size",`${a}px`),s.style.setProperty("--diagram-grid-offset-x",`${e.x}px`),s.style.setProperty("--diagram-grid-offset-y",`${e.y}px`)}}}setGridSize(t){this.gridSize=t,this.setDisplacementStyles()}useRef=o(t=>{this.element=t,t instanceof HTMLElement&&this.setDisplacementStyles()},"useRef");isInsideFrameFromTarget(t){const e=this.element?.parentElement;return!!(e&&t instanceof Node&&(e===t||e.contains(t)))}isInsideFrameEvent(t){const e=this.element?.parentElement;if(!e||t.target instanceof globalThis.Element&&t.target.closest('.diagram__extension_ui, [data-diagram-interactive-ui="true"]'))return!1;const s=typeof t.composedPath=="function"?t.composedPath():[];if(s.length>0&&s.some(i=>i===e||i instanceof Node&&e.contains(i))||this.isInsideFrameFromTarget(t.target)||t.type==="wheel"&&e.matches(":hover"))return!0;if("clientX"in t&&"clientY"in t){const i=e.getBoundingClientRect(),a=Number(t.clientX),r=Number(t.clientY);return a>=i.left&&a<=i.right&&r>=i.top&&r<=i.bottom}return!1}handleMouseMove(t){if(!this.isInsideFrameEvent(t)&&!this.eventStart&&!this.mouseSessionStartedInFrame)return;if(!this.emit(new Ct(this,t)).cancelled&&this.displacementStart&&this.eventStart){const s=this.displacement.substract(new y(t));this.emit(new Vs(this,this.displacement,s)).cancelled||(this._dragging=!0,this._displacement.assign(this.displacementStart.copy().substract(this.eventStart.copy().substract([t.clientX,t.clientY]).divide(this.scale))),this.bound(),this.setDisplacementStyles())}}handleDoubleClick(t){this.isInsideFrameEvent(t)&&this.emit(new is(this,t))}handleClick(t){this.isInsideFrameEvent(t)&&this.emit(new ns(this,t))}handleMouseUp(t){!this.isInsideFrameEvent(t)&&!this.eventStart&&!this.mouseSessionStartedInFrame||(this.emit(new tt(this,t)),this._dragging=!1,this.eventStart=null,this.mouseSessionStartedInFrame=!1)}handleMouseDown(t){if(!this.isInsideFrameEvent(t))return;if(this.mouseSessionStartedInFrame=!0,this.cancelCenterAnimation(),t.button===1){t.preventDefault(),this.displacementStart=this._displacement.copy(),this.eventStart=new y(t);return}!this.emit(new Pt(this,t)).cancelled&&t.button===0&&(this.displacementStart=this._displacement.copy(),this.eventStart=new y(t))}handleKeyDown(t){this.emit(new Rt(this,t))}handleKeyUp(t){this.emit(new we(this,t))}handleKeyPress(t){this.emit(new Rs(this,t))}handleWheel(t){if(!this.isInsideFrameEvent(t))return;if(!this.emit(new Gs(this,t)).cancelled){const s=t.deltaY<0,i=Math.floor(this.scale*100)/100;this.setScale(this.scale-t.deltaY/(i>=.2&&s||i>.21?1e3:1e4),new y(t))}}},o(me,"Canvas"),me);const Ni=class Ni extends ws{initializeGateways(){}};o(Ni,"TextNode");let Es=Ni;const Ti=class Ti extends z{creationMode="none";init(){this.diagram.onEvent(ns,t=>{this.handleClick(t)}),g.makeObservable(this,{creationMode:g.observable})}getId(){let t=String(Date.now()),e=0;for(;this.diagram.getNodeById(t);)t=String(Date.now())+String(e++);return t}handleClick(t){if(!t.cancelled&&this.creationMode!=="none"&&(t.cancel(),this.creationMode==="text")){const e=this.diagram.add(new Es(null,{id:this.getId(),label:"No label",box:new S([...this.diagram.canvas.inverseFit(new y(t.originalEvent)).raw,100,100])}));this.diagram.getExtension(Y).selectNode(e)}g.runInAction(()=>{this.creationMode="none"})}};o(Ti,"Creator");let rn=Ti;const Li=class Li extends z{dragThreshold=10;autopan=new ut(this.diagram);autopanReady=!0;dragStarted=!1;draggingLabel=null;primaryNodeId=null;groupedChildren=new Map;init(){this.diagram.onEvent(Pt,this.handleMouseDown.bind(this),this.diagram.priorities.Mouse_Down_Dragger),this.diagram.onEvent(tt,this.handleMouseUp.bind(this),this.diagram.priorities.Mouse_Up_Dragger),this.diagram.onEvent(Ct,this.handleMouseMove.bind(this),this.diagram.priorities.Mouse_Move_Selector-1),this.diagram.onEvent(Ee,this.handleScale.bind(this),this.diagram.priorities.Scale_Dragger),this.diagram.onEvent(ie,t=>{this.draggingNodes.delete(t.node.id),this.draggingLabel?.node===t.node&&(this.draggingLabel=null)})}constructor(t){super(t)}draggingNodes=new Map;startPoint=new y;startPointScaled=new y;mousePoint=new y;unsubscribe=o(()=>{},"unsubscribe");startDrag(t,e=ae.getInstance().coordinates,s={}){this.draggingNodes.clear(),this.groupedChildren.clear(),this.draggingLabel=null,this.diagram.canvas.markMouseSessionStartedInFrame(),this.autopanReady=s.deferAutopanUntilSafe!==!0,this.dragStarted=s.startImmediately===!0,this.primaryNodeId=t.id,this.draggingNodes.set(t.id,{node:t,startPoint:t.coordinates.copy()}),this.mousePoint=e.copy(),this.startPoint=e.copy(),this.startPointScaled=this.diagram.canvas.inverseFit(this.startPoint),this.handleDragAction()}originalEvent=null;labelDragHandle(t){return t.originalEvent.target?.closest?.('[data-node-label-drag-handle="true"]')??null}createLabelDragState(t,e){if(!e)return null;const s=Number(e.dataset?.nodeLabelWidth),i=Number(e.dataset?.nodeLabelHeight),a=Number(e.dataset?.nodeLabelGap);return{gap:Number.isFinite(a)&&a>=0?a:5,labelSize:new y([Number.isFinite(s)&&s>0?s:t.box.width,Number.isFinite(i)&&i>0?i:t.box.height]),node:t,startOffset:t.labelOffset}}snapLabelOffset(t,e){const s=e.node.box,i=s.middle,a=s.width/2+e.gap+e.labelSize.x/2,r=s.height/2+e.gap+e.labelSize.y/2,c=i.copy().sum([0,r]),l=[[0,-1],[-1,0],[1,0],[0,1]].map(([f,p])=>i.copy().sum([f*a,p*r])),h=c.copy().sum(t),u=l.map(f=>({anchor:f,distance:f.distance(h)})).sort((f,p)=>f.distance-p.distance)[0];return u?u.anchor.copy().substract(c):t}handleMouseDown(t){this.originalEvent=t;const e=t.node;!t.cancelled&&e&&e.selected&&(t.cancel(),this.draggingNodes.clear(),this.groupedChildren.clear(),this.draggingLabel=this.createLabelDragState(e,this.labelDragHandle(t)),this.autopanReady=!0,this.dragStarted=!1,this.primaryNodeId=e.id,this.mousePoint=new y(t.originalEvent),this.startPoint=this.mousePoint.copy(),this.startPointScaled=this.diagram.canvas.inverseFit(this.mousePoint),this.handleDragAction())}handleMouseMove(t){this.mousePoint=new y(t.originalEvent)}handleDragAction(){this.unsubscribe(),this.unsubscribe=pt(It(this,Ee,({newScale:t,previousScale:e})=>{this.startPoint.divide(e).multiply(t)}),vs(this.handleDragInterval.bind(this),30))}isFullyContained(t,e){return e.x>=t.x&&e.y>=t.y&&e.x+e.width<=t.x+t.width&&e.y+e.height<=t.y+t.height}collectConnectedEdges(t){const e=new Set;return t.forEach(s=>{s.gateways.forEach(i=>{i.incomingEdges.forEach(a=>e.add(a)),i.outgoingEdges.forEach(a=>e.add(a))})}),e}translateEdge(t,e){t.steps.forEach(s=>{s.sum(e)}),t.labels.forEach(s=>{s.position.sum(e)})}updateEdgesAfterBatchMove(t,e){const s=new Map,i=[];e.forEach(a=>{const r=t.get(a.id);if(!r)return;const c=a.coordinates.copy().substract(r);s.set(a.id,c),c.norm>0&&i.push(a)}),i.length&&this.collectConnectedEdges(i).forEach(a=>{const r=s.get(a.from.parent.id),c=s.get(a.to.parent.id);if(r&&c&&r.norm>0&&c.norm>0&&r.copy(!1).substract(c).norm<.001){this.translateEdge(a,r);return}a.from.recomputeConnectedEdge(a,"from")})}rigidSelectionDisplacement(t){const e=new Set(this.groupedChildren.keys()),s=t.filter(w=>!w.cancelled&&!e.has(w.node.id));if(s.length<2)return null;const i=s.find(w=>w.node.id===this.primaryNodeId)??s[0],a=[...s].sort((w,v)=>(ct.get(w,"x")??1/0)-(ct.get(v,"x")??1/0))[0],r=[...s].sort((w,v)=>(ct.get(w,"y")??1/0)-(ct.get(v,"y")??1/0))[0],c=ct.get(a,"x")===void 0?i:a,l=ct.get(r,"y")===void 0?i:r,h=this.draggingNodes.get(c.node.id)?.startPoint,u=this.draggingNodes.get(l.node.id)?.startPoint;if(!h||!u)return null;const f=new y([c.get().x-h.x,l.get().y-u.y]);let p=Number.NEGATIVE_INFINITY,m=Number.POSITIVE_INFINITY,x=Number.NEGATIVE_INFINITY,b=Number.POSITIVE_INFINITY;return s.forEach(w=>{const v=this.draggingNodes.get(w.node.id)?.startPoint;v&&(p=Math.max(p,-v.x),m=Math.min(m,this.diagram.canvas.size.x-v.x-w.node.box.width),x=Math.max(x,-v.y),b=Math.min(b,this.diagram.canvas.size.y-v.y-w.node.box.height))}),f.x=Math.min(m,Math.max(p,f.x)),f.y=Math.min(b,Math.max(x,f.y)),f}applyNodePositionProposals(t){const e=new Map(t.map(l=>[l.node.id,l])),s=new Set(this.groupedChildren.keys()),i=new Map,a=this.rigidSelectionDisplacement(t);t.forEach(l=>{!l.cancelled&&!s.has(l.node.id)&&i.set(l.node.id,l.node)}),this.groupedChildren.forEach((l,h)=>{const u=this.draggingNodes.get(h);u&&i.set(h,u.node)});const r=[...i.values()],c=new Map(r.map(l=>[l.id,l.coordinates.copy()]));t.forEach(l=>{if(!l.cancelled&&!s.has(l.node.id)){const h=this.draggingNodes.get(l.node.id)?.startPoint,u=a&&h?h.copy().sum(a):l.get().coordinates;l.node.setPosition(u,{updateConnectedEdges:!1})}}),this.groupedChildren.size&&this.groupedChildren.forEach((l,h)=>{const u=e.get(l),f=this.draggingNodes.get(h),p=this.draggingNodes.get(l);if(!f||!p)return;const x=(u?.cancelled?p.startPoint:u?.node.coordinates??p.startPoint).copy().substract(p.startPoint),b=f.startPoint.copy().sum(x);f.node.setPosition(b,{updateConnectedEdges:!1})}),this.updateEdgesAfterBatchMove(c,r)}includeGroupedChildren(){const t=[...this.draggingNodes.values()].filter(({node:s})=>s.state.groupChildren);if(!t.length)return;const e=new Set(this.draggingNodes.keys());this.diagram.nodes.forEach(s=>{if(e.has(s.id)||s.state.movable===!1)return;let i=null,a=Number.POSITIVE_INFINITY;const r=s.box;t.forEach(({node:c})=>{if(this.isFullyContained(c.box,r)){const l=c.box.width*c.box.height;l<a&&(a=l,i=c.id)}}),i!==null&&(this.draggingNodes.set(s.id,{node:s,startPoint:s.coordinates.copy()}),this.groupedChildren.set(s.id,i))})}handleDragInterval(){const t=this.mousePoint;if(this.draggingLabel){if(this.dragStarted||(this.dragStarted=t.copy().substract(this.startPoint).norm>this.dragThreshold),!this.dragStarted)return;const e=t.copy().substract(this.startPoint).divide(this.diagram.canvas.scale),s=this.draggingLabel.startOffset.copy().sum(e);this.draggingLabel.node.setLabelOffset(this.snapLabelOffset(s,this.draggingLabel));return}if(this.draggingNodes.size||(this.diagram.getExtension(Y).selectedNodes.forEach(e=>{this.draggingNodes.set(e.id,{node:e,startPoint:e.coordinates.copy()})}),this.includeGroupedChildren(),this.draggingNodes.size||this.unsubscribe()),this.draggingNodes.size){if(this.dragStarted||(this.dragStarted=t.copy().substract(this.startPoint).norm>this.dragThreshold),!this.dragStarted)return;this.autopanReady||(this.autopanReady=this.pointerIsInsideSafeViewport(t)),this.autopanReady&&this.autopan.displace(t);const e=this.diagram.canvas.inverseFit(this.startPoint),s=this.startPointScaled.copy().substract(e),a=[...this.draggingNodes.values()].filter(({node:r})=>!this.groupedChildren.has(r.id)).sort((r,c)=>+(c.node.id===this.primaryNodeId)-+(r.node.id===this.primaryNodeId)).map(r=>new Ae(r.node,new S([...r.startPoint.copy().sum(t.copy().substract(this.startPoint).divide(this.diagram.canvas.scale).substract(s)).raw,...r.node.box.size.raw])));this.emit(new ht(this,a,this.originalEvent?.originalEvent)).cancelled||this.applyNodePositionProposals(a)}}handleMouseUp(){this.draggingNodes.clear(),this.groupedChildren.clear(),this.draggingLabel=null,this.autopanReady=!0,this.dragStarted=!1,this.primaryNodeId=null,this.unsubscribe()}pointerIsInsideSafeViewport(t){const e=this.diagram.canvas.frameDimensions,s=Math.min(ut.edgeThreshold,e.width/2),i=Math.min(ut.edgeThreshold,e.height/2);return t.x>=e.x+s&&t.x<=e.x+e.width-s&&t.y>=e.y+i&&t.y<=e.y+e.height-i}handleScale(t){this.draggingNodes.size}};o(Li,"Dragger");let on=Li;function $e(n,t){const e=Math.abs(t.x-n.x)>=Math.abs(t.y-n.y);return{axis:e?"horizontal":"vertical",origin:n,point:e?new y([t.x,n.y]):new y([n.x,t.y])}}o($e,"cardinalAxisConstraint");const Ua=22,_s=25;function Ka(n,t,e){const s=n.nodes.filter(u=>u!==e.excludeNode).filter(u=>u.box.translate(new y([-_s,-_s])).sum([0,0,_s*2,_s*2]).collides(t));if(e.axisConstraint){const u=s.filter(p=>p.edgesAsGateways&&p.box.collides(t)).sort((p,m)=>p.box.middle.distance(t)-m.box.middle.distance(t)).map(p=>({anchor:p.findAxisAlignedConnectionAnchor(e.axisConstraint.origin,e.axisConstraint.axis),node:p})).find(p=>p.anchor);if(u?.anchor)return{anchor:u.anchor,anchorState:{mode:"fixed",position:u.anchor.relativePosition},node:u.node,snappedToGateway:!1};const f=s.flatMap(p=>p.gateways).map(p=>({distance:p.coordinates.distance(t),gateway:p})).filter(({gateway:p})=>e.axisConstraint.axis==="horizontal"?Math.abs(p.coordinates.y-e.axisConstraint.origin.y)<.001:Math.abs(p.coordinates.x-e.axisConstraint.origin.x)<.001).filter(p=>p.distance<=Ua).sort((p,m)=>p.distance-m.distance)[0]?.gateway;if(f){const p={gateway:f,point:f.coordinates.copy(),relativePosition:f.relativePosition,displacement:new y};return{anchor:p,anchorState:{mode:"fixed",position:p.relativePosition},node:f.parent,snappedToGateway:!0}}return null}const i=s.flatMap(u=>u.gateways).map(u=>({gateway:u,distance:u.coordinates.distance(t)})).filter(u=>u.distance<=Ua).sort((u,f)=>u.distance-f.distance)[0]?.gateway;if(i){const u={gateway:i,point:i.coordinates.copy(),relativePosition:i.relativePosition,displacement:new y};return{anchor:u,anchorState:{mode:"fixed",position:u.relativePosition},node:i.parent,snappedToGateway:!0}}const a=s.filter(u=>u.box.collides(t)).map(u=>u.getGateway("center")).find(Boolean);if(a)return{anchor:{gateway:a,point:a.coordinates.copy(),relativePosition:a.relativePosition,displacement:new y},anchorState:{mode:"fixed",position:a.relativePosition},node:a.parent,snappedToGateway:!0};const r=s.filter(u=>u.edgesAsGateways).sort((u,f)=>u.box.middle.distance(t)-f.box.middle.distance(t))[0];if(r){const u=r.usesAutomaticConnectionPoint(t),f=u?r.findAutomaticGatewayAnchor(e.oppositePoint):r.findFixedConnectionAnchor(t);return{anchor:f,anchorState:u?{mode:"automatic"}:{mode:"fixed",position:f.relativePosition},node:r,snappedToGateway:!1}}const c=s.flatMap(u=>u.gateways).map(u=>({gateway:u,distance:u.connectionDistance(t)})).filter(u=>Number.isFinite(u.distance)).sort((u,f)=>u.distance-f.distance)[0]?.gateway;if(!c)return null;const l=c.connectionDisplacement(t);return{anchor:{gateway:c,point:c.coordinates.copy().sum(l),relativePosition:c.relativePosition,displacement:l},anchorState:{mode:"fixed",position:c.relativePosition},node:c.parent,snappedToGateway:!0}}o(Ka,"resolveConnectionCandidate");const ze=.001,Dt=3,$i=class $i extends z{autopan=new ut(this.diagram);drag=null;endpointDrag=null;uns=o(()=>{},"uns");endpointDragActive=!1;endpointCandidatePoint=null;init(){g.makeObservable(this,{endpointDragActive:g.observable,endpointCandidatePoint:g.observable}),document.addEventListener("mouseup",this.handleMouseUp.bind(this)),this.diagram.onEvent(os,this.startDrag.bind(this)),this.diagram.onEvent(cs,this.startEndpointDrag.bind(this))}almostEqual(t,e){return Math.abs(t-e)<ze}pointMatches(t,e){return this.almostEqual(t.x,e.x)&&this.almostEqual(t.y,e.y)}axisAligned(t,e){return this.almostEqual(t.x,e.x)||this.almostEqual(t.y,e.y)}pointsNear(t,e,s=Dt){return Math.abs(t.x-e.x)<=s&&Math.abs(t.y-e.y)<=s}isActivePoint(t){return!!(this.drag&&(t===this.drag.pointA||t===this.drag.pointB))}getGridSize(){return this.diagram.getExtension(G)?.gridSize??50}orientationVector(t){switch(t){case"left":return{x:-1,y:0};case"right":return{x:1,y:0};case"up":return{x:0,y:-1};case"down":return{x:0,y:1}}}axisPerpendicularToGateway(t){return t==="left"||t==="right"?"y":"x"}expectedLeadPoint(t,e){const s=e==="from"?t.steps[0]:t.steps.at(-1),i=e==="from"?t.from.orientation:t.to.orientation,a=this.orientationVector(i),r=this.getGridSize();return new y([s.x+a.x*r,s.y+a.y*r])}leadMatchesGatewaySide(t,e,s){const i=this.orientationVector(s),a=(e.x-t.x)*i.x+(e.y-t.y)*i.y;return Math.abs(s==="left"||s==="right"?e.y-t.y:e.x-t.x)<=Dt&&a>ze&&a<=this.getGridSize()+Dt}endpointLeadPoint(t,e){const s=e==="from"?t.steps[0]:t.steps.at(-1),i=e==="from"?t.from.orientation:t.to.orientation,a=e==="from"?1:t.steps.length-2,r=t.steps[a];return r&&r.mode!=="manual"&&!this.isActivePoint(r)&&this.leadMatchesGatewaySide(s,r,i)?r:this.expectedLeadPoint(t,e)}ensureEndpointLeadPoint(t,e){const s=this.expectedLeadPoint(t,e),i=e==="from",a=i?1:t.steps.length-2,r=t.steps[a];if(r&&this.leadMatchesGatewaySide(i?t.steps[0]:t.steps.at(-1),r,i?t.from.orientation:t.to.orientation))return a;const c=new O(t,[s.x,s.y,"auto"]);return i?(t.state.steps.splice(1,0,c),1):(t.state.steps.splice(t.steps.length-1,0,c),t.steps.length-2)}ensureEndpointLeads(t){this.ensureEndpointLeadPoint(t,"from"),this.ensureEndpointLeadPoint(t,"to")}isProtectedLeadPoint(t,e){return e<=0||e>=t.steps.length-1?!1:e===1&&t.steps[e].mode!=="manual"&&this.leadMatchesGatewaySide(t.steps[0],t.steps[e],t.from.orientation)||e===t.steps.length-2&&t.steps[e].mode!=="manual"&&this.leadMatchesGatewaySide(t.steps.at(-1),t.steps[e],t.to.orientation)}segmentMovedAxis(t,e){return this.almostEqual(t.y,e.y)?"y":this.almostEqual(t.x,e.x)?"x":Math.abs(t.x-e.x)>=Math.abs(t.y-e.y)?"y":"x"}segmentDirection(t,e){return!this.axisAligned(t,e)||this.pointMatches(t,e)?null:this.almostEqual(t.y,e.y)?"horizontal":"vertical"}segmentIsParallelToDraggedAxis(t,e){return this.drag?this.drag.movedAxis==="y"?Math.abs(t.y-e.y)<=Dt:Math.abs(t.x-e.x)<=Dt:!1}perpendicularAxis(t){return t==="x"?"y":"x"}pointAxis(t,e){return e==="x"?t.x:t.y}setPointAxis(t,e,s){e==="x"?t.x=s:t.y=s}crossesStaticBoundary(t,e,s,i,a=Dt){const r=this.pointAxis(s,e),c=this.pointAxis(i,e);switch(t){case"right":case"down":return r<c-a;case"left":case"up":return r>c+a}}copyAsManual(t,e="both"){const s=t.copy();return s.parent=t.parent,s.addManualAxis(e),s}markManual(t,e="both"){t.mode!=="static"&&t.addManualAxis(e)}clampPointPastLead(t,e,s){switch(s){case"left":t.x=Math.min(t.x,e.x);break;case"right":t.x=Math.max(t.x,e.x);break;case"up":t.y=Math.min(t.y,e.y);break;case"down":t.y=Math.max(t.y,e.y);break}}movedAxisMatchesOrientation(t,e){return(e==="left"||e==="right")&&t==="x"||(e==="up"||e==="down")&&t==="y"}edgePointAt(t,e,s,i="auto"){return new O(t,[e,s,i])}guardCoordinate(t,e,s,i,a){const r=this.pointAxis(i,a)-this.pointAxis(s,a),c=Math.abs(r)>ze?Math.sign(r):1,l=e==="from"?t.from.parent.box:t.to.parent.box,h=a==="y"?l.height:l.width,u=Math.max(this.getGridSize(),h/2+this.getGridSize()/2);return this.pointAxis(s,a)+c*u}makeGuardCorner(t,e,s,i){const a=this.perpendicularAxis(i),r=this.edgePointAt(t,e.x,e.y,"auto");return this.setPointAxis(r,i,this.pointAxis(e,i)),this.setPointAxis(r,a,s),r}insertStaticBoundaryGuard(t){if(!this.drag)return!1;const{edge:e,movedAxis:s}=this.drag,i=t==="from"?e.from.orientation:e.to.orientation;if(!this.movedAxisMatchesOrientation(s,i))return!1;const a=e.state.steps,r=a.findIndex(I=>I===this.drag.pointA),c=a.findIndex(I=>I===this.drag.pointB);if(r<0||c<0)return!1;const l=t==="from"?r<=c?"pointA":"pointB":r>=c?"pointA":"pointB",h=l==="pointA"?"pointB":"pointA",u=this.drag[l],f=this.drag[h],p=a.findIndex(I=>I===u),m=this.endpointLeadPoint(e,t),x=t==="from"?1:a.length-2,b=a[x],w=!!(b&&this.pointMatches(b,m)),v=t==="from"?p===1:p===a.length-2,_=t==="from"?p===2&&w:p===a.length-3&&w,E=this.crossesStaticBoundary(i,s,u,m,Dt);if(p<0||!v&&!_||!E)return!1;const C=this.perpendicularAxis(s),k=this.guardCoordinate(e,t,m,f,C);this.setPointAxis(u,C,k),this.markManual(u,s),this.rebaseDraggedEndpointFixedAxis(l,u);const P=this.makeGuardCorner(e,m,k,s);if(t==="from"){if(v){const I=this.edgePointAt(e,m.x,m.y,"auto");a.splice(p,0,I,P)}else a.splice(p,0,P);return this.drag.sourceLeadAdjacent=!1,this.drag.staticBoundaryGuarded=!0,!0}if(v){const I=this.edgePointAt(e,m.x,m.y,"auto");a.splice(p+1,0,P,I)}else a.splice(p+1,0,P);return this.drag.targetLeadAdjacent=!1,this.drag.staticBoundaryGuarded=!0,!0}insertStaticBoundaryGuards(){const t=this.insertStaticBoundaryGuard("from"),e=this.insertStaticBoundaryGuard("to");return t||e}clampDraggedSegmentAgainstEndpointLeads(){if(!this.drag)return;const{edge:t,pointA:e,pointB:s,movedAxis:i,sourceLeadAdjacent:a,targetLeadAdjacent:r}=this.drag,c=t.steps.findIndex(h=>h===e),l=t.steps.findIndex(h=>h===s);if(this.movedAxisMatchesOrientation(i,t.from.orientation)){const u=t.steps[1]??this.expectedLeadPoint(t,"from");u&&(a||c>=0&&l>=0&&this.isProtectedLeadPoint(t,1)&&(c===2||l===2))&&(this.clampPointPastLead(e,u,t.from.orientation),this.clampPointPastLead(s,u,t.from.orientation))}if(this.movedAxisMatchesOrientation(i,t.to.orientation)){const h=t.steps.length-2,u=t.steps[h]??this.expectedLeadPoint(t,"to");u&&(r||c>=0&&l>=0&&this.isProtectedLeadPoint(t,h)&&(c===h-1||l===h-1))&&(this.clampPointPastLead(e,u,t.to.orientation),this.clampPointPastLead(s,u,t.to.orientation))}}mergeDraggedSegmentWithManualNeighbors(){if(!this.drag)return!1;let t=!1;const e=o((s,i)=>{if(!this.drag)return;const a=this.drag[s],r=this.drag.edge.state.steps,c=r.findIndex(u=>u===a),l=c+i;if(c<0||l<0||l>=r.length)return;const h=r[l];h.mode==="manual"&&this.pointsNear(a,h)&&(h.assign(a),r.splice(c,1),this.drag[s]=h,t=!0)},"mergePoint");return e("pointA",-1),e("pointB",1),t}rebaseDraggedEndpointFixedAxis(t,e){if(!this.drag)return;const s=t==="pointA"?this.drag.startPointA:this.drag.startPointB;this.drag.movedAxis==="y"?s.x=e.x:s.y=e.y}replaceDraggedEndpointWithProtectedLeadDuplicate(t,e,s){if(!this.drag)return;const i=this.drag[t],a=this.copyAsManual(e,this.drag.movedAxis);this.drag.movedAxis==="y"?a.y=i.y:a.x=i.x,this.drag.edge.state.steps[s]=a,this.drag[t]=a,this.rebaseDraggedEndpointFixedAxis(t,a)}absorbCollinearSegmentsIntoDraggedSegment(){if(!this.drag)return!1;let t=!1;const e=o((s,i)=>{if(!this.drag)return;const a=this.drag.edge.state.steps;for(;;){const r=this.drag[s],c=a.findIndex(u=>u===r),l=c+i;if(c<0||l<=0||l>=a.length-1)return;const h=a[l];if(!this.segmentIsParallelToDraggedAxis(r,h))return;if(this.isProtectedLeadPoint(this.drag.edge,l)){this.replaceDraggedEndpointWithProtectedLeadDuplicate(s,h,c),t=!0;return}if(h.mode==="static")return;a.splice(c,1),this.drag[s]=h,this.rebaseDraggedEndpointFixedAxis(s,h),t=!0}},"absorbSide");return e("pointA",-1),e("pointB",1),t}removeAdjacentDuplicates(t){if(!this.drag)return!1;const e=this.drag.edge.state.steps;let s=!1;for(let i=0;i<e.length-1;){const a=e[i],r=e[i+1];if(!this.pointsNear(a,r)){i+=1;continue}const c=this.isActivePoint(a)||a.mode==="static"||this.isProtectedLeadPoint(this.drag.edge,i)?i+1:i;if(c<=0||c>=e.length-1||t&&this.isActivePoint(e[c])){i+=1;continue}e.splice(c,1),s=!0,i=Math.max(0,i-1)}return s}coordinateAnchorForPair(t,e,s,i){return this.drag?t.mode==="static"?this.pointAxis(t,s):e.mode==="static"?this.pointAxis(e,s):this.isProtectedLeadPoint(this.drag.edge,i)?this.pointAxis(t,s):this.isProtectedLeadPoint(this.drag.edge,i+1)?this.pointAxis(e,s):this.isActivePoint(t)?this.pointAxis(t,s):this.isActivePoint(e)?this.pointAxis(e,s):t.mode==="manual"?this.pointAxis(t,s):e.mode==="manual"?this.pointAxis(e,s):this.pointAxis(t,s):this.pointAxis(t,s)}snapNearlyAlignedDraggedPairs(){if(!this.drag)return!1;const t=this.drag.edge.state.steps;let e=!1;for(let s=0;s<t.length-1;s++){const i=t[s],a=t[s+1];if(Math.abs(i.x-a.x)>ze&&Math.abs(i.x-a.x)<=Dt){const r=this.coordinateAnchorForPair(i,a,"x",s);i.x=r,a.x=r,e=!0}if(Math.abs(i.y-a.y)>ze&&Math.abs(i.y-a.y)<=Dt){const r=this.coordinateAnchorForPair(i,a,"y",s);i.y=r,a.y=r,e=!0}}return e}chooseOrthogonalCorner(t,e,s,i){const a=new O(this.drag?.edge??null,[e.x,t.y,"auto"]),r=new O(this.drag?.edge??null,[t.x,e.y,"auto"]),c=o(l=>{let h=0;const u=s?this.segmentDirection(s,t):null,f=this.segmentDirection(t,l),p=i?this.segmentDirection(e,i):null,m=this.segmentDirection(l,e);return u&&f!==u&&(h+=2),p&&m!==p&&(h+=2),this.axisAligned(s??t,l)&&(h+=1),this.axisAligned(l,i??e)&&(h+=1),h},"score");return c(a)>=c(r)?a:r}ensureOrthogonalAdjacency(){if(!this.drag)return!1;const t=this.drag.edge.state.steps;let e=!1;for(let s=0;s<t.length-1;s++){const i=t[s],a=t[s+1];if(this.axisAligned(i,a))continue;const r=s>0?t[s-1]:void 0,c=s+2<t.length?t[s+2]:void 0;t.splice(s+1,0,this.chooseOrthogonalCorner(i,a,r,c)),e=!0,s+=1}return e}normalizeDraggedEdge(){if(!this.drag)return!1;const t=this.snapNearlyAlignedDraggedPairs(),e=this.mergeDraggedSegmentWithManualNeighbors(),s=this.absorbCollinearSegmentsIntoDraggedSegment(),i=this.snapNearlyAlignedDraggedPairs(),a=this.ensureOrthogonalAdjacency(),r=this.snapNearlyAlignedDraggedPairs(),c=this.removeAdjacentDuplicates(!0),l=this.drag.edge.state.steps;return l.length>0&&(l[0].markStatic(),l.at(-1).markStatic()),t||e||s||i||a||r||c}finalizeDraggedEdge(){this.drag&&(this.normalizeDraggedEdge(),this.ensureOrthogonalAdjacency(),this.removeAdjacentDuplicates(!1),this.drag.staticBoundaryGuarded||this.drag.edge.setSteps(qa("orthogonal").route(this.diagram,this.drag.edge)))}prepareStraightLeadSegment(t,e){const s=this.copyAsManual(t.steps[1],e),i=this.copyAsManual(t.steps[2],e);return t.state.steps.splice(2,0,s,i),{pointA:s,pointB:i,movedAxis:e}}prepareSourceSegment(t){this.ensureEndpointLeads(t);const e=this.axisPerpendicularToGateway(t.from.orientation);if(t.steps.length===4&&this.isProtectedLeadPoint(t,1)&&this.isProtectedLeadPoint(t,2))return this.prepareStraightLeadSegment(t,e);const s=this.copyAsManual(t.steps[1],e);t.state.steps.splice(2,0,s);const i=t.steps[3];return i instanceof O?(this.markManual(i,e),{pointA:s,pointB:i,movedAxis:e}):null}prepareTargetSegment(t){this.ensureEndpointLeads(t);const e=this.axisPerpendicularToGateway(t.to.orientation);if(t.steps.length===4&&this.isProtectedLeadPoint(t,1)&&this.isProtectedLeadPoint(t,2))return this.prepareStraightLeadSegment(t,e);const s=t.steps.length-2,i=this.copyAsManual(t.steps[s],e);t.state.steps.splice(s,0,i);const a=t.steps[s-1];return a instanceof O?(this.markManual(a,e),{pointA:a,pointB:i,movedAxis:e}):null}prepareSegmentAfterProtectedSourceLead(t,e){const s=this.segmentMovedAxis(t.steps[e],t.steps[e+1]),i=this.copyAsManual(t.steps[e],s);t.state.steps.splice(e+1,0,i);const a=t.steps[e+2];return a instanceof O?(this.markManual(a,s),{pointA:i,pointB:a,movedAxis:s}):null}prepareSegmentBeforeProtectedTargetLead(t,e){const s=this.segmentMovedAxis(t.steps[e-1],t.steps[e]),i=this.copyAsManual(t.steps[e],s);t.state.steps.splice(e,0,i);const a=t.steps[e-1];return a instanceof O?(this.markManual(a,s),{pointA:a,pointB:i,movedAxis:s}):null}prepareInteriorSegment(t,e,s,i){this.ensureEndpointLeads(t);let a=t.steps.findIndex(u=>u===e),r=t.steps.findIndex(u=>u===s);if((a<0||r<0||Math.abs(a-r)!==1)&&(a=Math.max(0,Math.min(i,t.steps.length-2)),r=a+1),a>r&&([a,r]=[r,a]),a===0)return this.prepareSourceSegment(t);if(r===t.steps.length-1)return this.prepareTargetSegment(t);if(this.isProtectedLeadPoint(t,a))return this.prepareSegmentAfterProtectedSourceLead(t,a);if(this.isProtectedLeadPoint(t,r))return this.prepareSegmentBeforeProtectedTargetLead(t,r);const c=t.steps[a],l=t.steps[r],h=this.segmentMovedAxis(c,l);return this.markManual(c,h),this.markManual(l,h),{pointA:c,pointB:l,movedAxis:h}}restoreOriginalSteps(t,e){t.setSteps(e.map(s=>s.copy()))}startDrag(t){if(t.cancelled||t.src.pathType!=="orthogonal")return;t.stopImmediatePropagation(),this.uns();const e=t.src,s=e.steps.map(b=>b.copy()),i=e.steps.length-1,a=Number(t.midPoint.id),r=a===0,c=a===i-1,l=t.midPoint.points[0],h=t.midPoint.points[1],u=g.runInAction(()=>{e.state.dragging=!0;const b=r?this.prepareSourceSegment(e):c?this.prepareTargetSegment(e):this.prepareInteriorSegment(e,l,h,a);return b||(e.state.dragging=!1),b});if(!u)return;const f=e.steps.findIndex(b=>b===u.pointA),p=e.steps.findIndex(b=>b===u.pointB),m=f===2||p===2,x=f===e.steps.length-3||p===e.steps.length-3;this.drag={edge:e,midpoint:t.midPoint,pointA:u.pointA,pointB:u.pointB,movedAxis:u.movedAxis,startMouseCanvas:this.diagram.canvas.inverseFit(new y(t)),startPointA:u.pointA.copy().nonObserved,startPointB:u.pointB.copy().nonObserved,originalSteps:s,sourceLeadAdjacent:m,targetLeadAdjacent:x,staticBoundaryGuarded:!1,changed:!1},this.uns=pt(R(this,"mousemove",this.handleMouseMove),R(this,"pointermove",this.handleMouseMove))}startEndpointDrag(t){if(t.cancelled)return;t.stopImmediatePropagation(),this.uns(),g.runInAction(()=>{t.src.state.dragging=!0}),this.drag=null,this.endpointDragActive=!0,this.endpointCandidatePoint=null;const e=t.src.steps[0],s=t.src.steps.at(-1),i=t.src.from.parent.box,a=t.src.to.parent.box;this.endpointDrag={edge:t.src,endpoint:t.endpoint,originalStart:{gateway:t.src.from,point:e.copy(),displacement:e.copy().substract(t.src.from.coordinates),relativePosition:new y([(e.x-i.x)/Math.max(i.width,.001),(e.y-i.y)/Math.max(i.height,.001)])},originalEnd:{gateway:t.src.to,point:s.copy(),displacement:s.copy().substract(t.src.to.coordinates),relativePosition:new y([(s.x-a.x)/Math.max(a.width,.001),(s.y-a.y)/Math.max(a.height,.001)])},originalStartState:{mode:t.src.startAnchor.mode,position:t.src.startAnchor.position?.copy()},originalEndState:{mode:t.src.endAnchor.mode,position:t.src.endAnchor.position?.copy()},candidate:null},this.uns=pt(R(this,"mousemove",this.handleMouseMove),R(this,"pointermove",this.handleMouseMove))}restoreEndpointDrag(){if(!this.endpointDrag)return;const t=this.endpointDrag,e=t.endpoint==="from"?t.originalStart:t.originalEnd,s=t.endpoint==="from"?t.originalStartState:t.originalEndState;t.edge.setResolvedEndpoint(t.endpoint,e,s,!0)}handleEndpointMouseMove(t){if(!this.endpointDrag)return;const{edge:e,endpoint:s}=this.endpointDrag,i=this.diagram.canvas.inverseFit(new y(t)),a=s==="from"?e.to.parent:e.from.parent,r=s==="from"?e.steps.at(-1):e.steps[0],c=t.shiftKey?$e(r,i):null,l=c?.point??i,h=Ka(this.diagram,l,{axisConstraint:c?{axis:c.axis,origin:c.origin}:void 0,excludeNode:a,oppositePoint:a.box.middle});if(!h){this.endpointDrag.candidate=null,this.endpointCandidatePoint=null,this.restoreEndpointDrag();return}const u=s==="from"?h.anchor.gateway:e.from,f=s==="to"?h.anchor.gateway:e.to;if(!u.canStartConnection(f,e)||!f.canConnect(u,e)){this.endpointDrag.candidate=null,this.endpointCandidatePoint=null,this.restoreEndpointDrag();return}this.endpointDrag.candidate=h,this.endpointCandidatePoint=h.anchor.point,g.runInAction(()=>{e.setResolvedEndpoint(s,h.anchor,h.anchorState,!0)})}moveDraggedSegment(t){if(!this.drag)return;const{pointA:e,pointB:s}=this.drag,a=this.diagram.canvas.inverseFit(new y(t)).nonObserved.substract(this.drag.startMouseCanvas);this.drag.movedAxis==="x"?a.y=0:a.x=0,g.runInAction(()=>{if(!this.drag)return;e.assign(this.drag.startPointA.copy().sum(a)),s.assign(this.drag.startPointB.copy().sum(a));const r=[new ls(e,this.drag.movedAxis),new ls(s,this.drag.movedAxis)];this.emit(new ds(this,r,this.drag.movedAxis,t));for(const u of r)u.point.assign(u.get());const c=this.insertStaticBoundaryGuards();this.clampDraggedSegmentAgainstEndpointLeads();const l=this.normalizeDraggedEdge();(c||l||!this.pointMatches(this.drag.pointA,this.drag.startPointA)||!this.pointMatches(this.drag.pointB,this.drag.startPointB))&&(this.drag.changed=!0)})}handleMouseMove(t){if((t.type==="pointermove"||typeof PointerEvent>"u")&&this.autopan.displace(new y(t)),this.endpointDrag){this.handleEndpointMouseMove(t);return}this.moveDraggedSegment(t)}handleMouseUp(){!this.drag&&!this.endpointDrag||(g.runInAction(()=>{if(this.drag&&(this.drag.changed?this.finalizeDraggedEdge():this.restoreOriginalSteps(this.drag.edge,this.drag.originalSteps),this.drag.edge.state.dragging=!1),this.endpointDrag){const{edge:t,candidate:e}=this.endpointDrag;(!e||this.emit(new Se(this,t.from.parent,t.to.parent)).cancelled)&&this.restoreEndpointDrag(),t.state.dragging=!1,this.endpointDragActive=!1,this.endpointCandidatePoint=null}this.drag=null,this.endpointDrag=null}),this.uns())}};o($i,"EdgesDragger");let le=$i;const zi=class zi extends z{proposals=[];snapDistance=10;clear(){this.proposals=[]}init(){g.makeObservable(this,{clear:g.action,proposals:g.observable})}align(t,e,s){if(!this.enabled||!this.diagram.getExtension(Zt).enabled)return this.clear(),s;const i=e.size,a=5,r=this.snapDistance;let c=s.x,l=s.y;const h={from:s.copy(),id:"",to:s.copy()};let u={distance:Number.POSITIVE_INFINITY,guide:h,target:s.x},f={distance:Number.POSITIVE_INFINITY,guide:h,target:s.y};const p=o((b,w)=>{const v=Math.abs(s.x-b);v<=r&&v<u.distance&&(u={distance:v,guide:w,target:b})},"chooseX"),m=o((b,w)=>{const v=Math.abs(s.y-b);v<=r&&v<f.distance&&(f={distance:v,guide:w,target:b})},"chooseY");for(const b of this.diagram.edges.flatMap(w=>w.labels)){if(b===e)continue;const w=b.position.x+b.size.width/2,v=b.position.y+b.size.height/2,_=b.position.y+b.size.height,E=b.position.x+b.size.width,C=Math.min(s.y,b.position.y),k=Math.max(s.y+i.height,_),P=Math.min(s.x,b.position.x),I=Math.max(s.x+i.width,E);p(b.position.x,{from:new y([b.position.x,C]),id:`label-left-${b.id}`,to:new y([b.position.x,k])}),p(E-i.width,{from:new y([E,C]),id:`label-right-${b.id}`,to:new y([E,k])}),p(w-i.width/2,{from:new y([w,C]),id:`label-center-x-${b.id}`,to:new y([w,k])}),m(b.position.y,{from:new y([P,b.position.y]),id:`label-top-${b.id}`,to:new y([I,b.position.y])}),m(_-i.height,{from:new y([P,_]),id:`label-bottom-${b.id}`,to:new y([I,_])}),m(v-i.height/2,{from:new y([P,v]),id:`label-center-y-${b.id}`,to:new y([I,v])})}Number.isFinite(u.distance)&&(c=u.target),Number.isFinite(f.distance)&&(l=f.target);for(let b=0;b<t.steps.length-1;b+=1){const w=t.steps[b],v=t.steps[b+1],_=Math.abs(w.x-v.x)<.001,E=Math.abs(w.y-v.y)<.001;if(_&&l+i.height>=Math.min(w.y,v.y)-r&&l<=Math.max(w.y,v.y)+r){const C=Math.min(w.y,v.y),k=Math.max(w.y,v.y);p(w.x+a,{from:new y([w.x+a,C]),id:`edge-left-${b}`,to:new y([w.x+a,k])}),p(w.x-a-i.width,{from:new y([w.x-a,C]),id:`edge-right-${b}`,to:new y([w.x-a,k])})}if(E&&c+i.width>=Math.min(w.x,v.x)-r&&c<=Math.max(w.x,v.x)+r){const C=Math.min(w.x,v.x),k=Math.max(w.x,v.x);m(w.y+a,{from:new y([C,w.y+a]),id:`edge-top-${b}`,to:new y([k,w.y+a])}),m(w.y-a-i.height,{from:new y([C,w.y-a]),id:`edge-bottom-${b}`,to:new y([k,w.y-a])})}}Number.isFinite(u.distance)&&(c=u.target),Number.isFinite(f.distance)&&(l=f.target);const x=[u,f].filter(b=>Number.isFinite(b.distance)).map(b=>b.guide);return g.runInAction(()=>{this.proposals=x}),new y([c,l])}};o(zi,"LabelsAligner");let _t=zi;function Eo(n,t,e){switch(e){case"down":return t.copy().sum([0,n]);case"left":return t.copy().sum([-n,0]);case"up":return t.copy().sum([0,-n]);case"right":return t.copy().sum([+n,0])}}o(Eo,"stepFromGateway");const _o=5,Oi=class Oi extends z{hasRoutedPreview=!1;previewRequestVersion=0;previewRafId=null;init(){g.makeObservable(this,{_arrowSteps:g.observable,arrowTo:g.observable,candidateGateway:g.observable,candidateAnchor:g.observable,startConnectionFrom:g.action,startConnectionFromNode:g.action,handleGatewayMouseDown:g.action,handleMouseMove:g.action,handlePendingMouseMove:g.action,startGateway:g.observable,handleMouseUp:g.action}),this.diagram.onEvent(Pt,this.handleGatewayMouseDown.bind(this),this.diagram.priorities.Mouse_Down_Node)}arrowTo=null;startGateway=null;startAnchor=null;startAnchorMode="fixed";axisConstrained=!1;candidateGateway=null;candidateAnchor=null;candidateAnchorState=null;previewRouter=new xs;pendingConnection=null;unbindPendingConnection=o(()=>{},"unbindPendingConnection");_arrowSteps=[];get arrowSteps(){return this._arrowSteps}get previewPathType(){const t=this.startGateway?.parent.requiredEdgePathType==="straight",e=this.candidateGateway?.parent.requiredEdgePathType==="straight";return t||e?"straight":"orthogonal"}get candidatePoint(){return this.candidateAnchor?.point??null}get snap(){return this.diagram.getExtension(G)}resolveStartAnchor(t,e=!1){return this.startGateway?this.startAnchorMode==="automatic"&&!e?this.startGateway.parent.findAutomaticGatewayAnchor(t):this.startAnchor:null}calculateArrowSteps(){if(!this.startGateway||!this.arrowTo)return;const t=this.startGateway,e=this.candidateGateway,s=this.candidateAnchor,i=this.arrowTo.copy(),a=this.previewRequestVersion;if(!i||e&&!s){g.runInAction(()=>{this._arrowSteps=[]});return}try{const r=this.diagram.canvas.inverseFit(i),c=this.axisConstrained&&this.startAnchor?$e(this.startAnchor.point,r).point:r,l=this.snap.gridSize/2,h=c.copy().divide(l).round.multiply(l);if(this.axisConstrained&&this.startAnchor){const p=$e(this.startAnchor.point,c);p.axis==="horizontal"?h.y=p.point.y:h.x=p.point.x}const u=this.resolveStartAnchor(e?.parent.box.middle??c,this.axisConstrained);if(!u)return;let f=[];if(e)f=this.previewRouter.findRouteBetween(this.diagram,u.gateway,s.gateway,u.displacement,s.displacement);else{const p=new ws(null,{id:"fake",label:"",box:new S([...h.raw,0,0])}),m=u.gateway.coordinates.substract(p.getGateway("down").coordinates).x,x=u.gateway.coordinates.substract(p.getGateway("down").coordinates).y,b=Math.abs(m)>Math.abs(x)?m>=0?"right":"left":x>=0?"down":"up";f=this.previewRouter.findRouteBetween(this.diagram,u.gateway,p.getGateway(b),u.displacement)}g.runInAction(()=>{this.startGateway===t&&a===this.previewRequestVersion&&(this._arrowSteps=f.map(p=>new y([p.x,p.y])),this.hasRoutedPreview=this._arrowSteps.length>1)})}catch{}}orthogonalMousePreview(t,e){const s=this.snap.gridSize/2,i=e.copy().divide(s).round.multiply(s);if(this.axisConstrained&&this.startAnchor){const p=$e(this.startAnchor.point,e);p.axis==="horizontal"?i.y=p.point.y:i.x=p.point.x}const a=t.point.copy(),r=Eo(this.snap.gridSize,a,t.gateway.orientation),c=[a,r];if(Math.abs(r.x-i.x)<.001||Math.abs(r.y-i.y)<.001)return c.push(i),this.compactPreviewPoints(c);const l=new y([r.x,i.y]),h=new y([i.x,r.y]),u=Math.abs(i.x-r.x),f=Math.abs(i.y-r.y);return c.push(u>=f?h:l,i),this.compactPreviewPoints(c)}compactPreviewPoints(t){const e=[];for(const s of t){const i=e.at(-1);if(!(i&&Math.abs(i.x-s.x)<.001&&Math.abs(i.y-s.y)<.001))for(e.push(s);e.length>=3;){const a=e.at(-3),r=e.at(-2),c=e.at(-1),l=Math.abs(a.x-r.x)<.001&&Math.abs(r.x-c.x)<.001,h=Math.abs(a.y-r.y)<.001&&Math.abs(r.y-c.y)<.001;if(l||h)e.splice(e.length-2,1);else break}}return e}cancelScheduledPreview(){this.previewRafId!==null&&(cancelAnimationFrame(this.previewRafId),this.previewRafId=null)}scheduleCalculateArrowSteps(){this.previewRafId===null&&(this.previewRafId=requestAnimationFrame(()=>{this.previewRafId=null,this.calculateArrowSteps()}))}u=o(()=>{},"u");connectionAnchorFromEvent(t){const e=t.originalEvent.target;if(!e||typeof e.closest!="function")return null;const s=e.closest("[data-gateway-parent]"),i=this.diagram.getNodeById(s?.dataset.gatewayParent??"");if(!s||!i)return null;const a=s.dataset.gatewayId,r=a?i.gateways.find(l=>l.id===a):null;if(r)return{gateway:r,point:r.coordinates.copy(),relativePosition:r.relativePosition,displacement:new y};const c=this.diagram.canvas.inverseFit(new y(t));return i.findFixedConnectionAnchor(c)}handleGatewayMouseDown(t){if(t.cancelled||t.originalEvent.button!==0||this.connecting)return;const e=this.connectionAnchorFromEvent(t);e&&(this.cancelPendingConnection(),this.pendingConnection={anchor:e,pointer:new y(t)},t.cancel(),this.unbindPendingConnection=pt(It(this,Ct,this.handlePendingMouseMove),It(this,tt,this.cancelPendingConnection)))}handlePendingMouseMove(t){const e=this.pendingConnection;!e||e.pointer.distance(new y(t))<_o||(this.cancelPendingConnection(),this.startAnchorMode="fixed",this.beginConnection(e.anchor,t)&&this.handleMouseMove(t))}cancelPendingConnection(){this.pendingConnection=null,this.unbindPendingConnection(),this.unbindPendingConnection=()=>{}}startConnectionFrom(t,e){this.startAnchorMode="fixed";const s={gateway:t,point:t.coordinates.copy(),relativePosition:t.relativePosition,displacement:new y};this.beginConnection(s,e)}startConnectionFromNode(t,e,s="fixed"){const i=this.diagram.canvas.inverseFit(new y(e));this.startAnchorMode=s,this.beginConnection(t.findFixedConnectionAnchor(i),e)}get connecting(){return this.startGateway!==null}beginConnection(t,e){const s=t.gateway;if(this.emit(new Ws(this,s.parent)).cancelled)return!1;const i="originalEvent"in e?e.originalEvent:e.nativeEvent;return"originalEvent"in e&&e.stopImmediatePropagation(),i.stopImmediatePropagation?.(),this.diagram.canvas.markMouseSessionStartedInFrame(),this.startGateway=s,this.startAnchor=t,this.arrowTo=new y(i),this.hasRoutedPreview=!1,this.axisConstrained=!1,this.previewRequestVersion=0,this._arrowSteps=[t.point.copy(),t.point.copy()],this.u(),this.u=pt(It(this,Ct,this.handleMouseMove),It(this,tt,this.handleMouseUp)),!0}handleMouseMove(t){this.previewRequestVersion+=1;const e=this.diagram.canvas.frameDimensions;this.arrowTo=new y(t);const s=this.arrowTo.copy().substract(this.diagram.canvas.framePosition),i=new y([0,0]);s.x<100?i.sum([(100-s.x)*.1,0]):s.x>e.width-100?i.substract([(100-Math.abs(s.x-e.width))*.1,0]):s.y<100?i.sum([0,(100-s.y)*.1]):s.y>e.height-100&&i.substract([0,(100-Math.abs(s.y-e.height))*.1]),i.norm>0&&this.diagram.canvas.displace(i);const a=this.diagram.canvas.inverseFit(this.arrowTo),r=t.shift&&this.startAnchor?$e(this.startAnchor.point,a):null;this.axisConstrained=!!r;const c=r?.point??a,l=Ka(this.diagram,c,{axisConstraint:r?{axis:r.axis,origin:r.origin}:void 0,excludeNode:this.startGateway?.parent,oppositePoint:this.startGateway.parent.box.middle});if(l?(this.candidateGateway=l.anchor.gateway,this.candidateAnchor=l.anchor,this.candidateAnchorState=l.anchorState):(this.candidateGateway=null,this.candidateAnchor=null,this.candidateAnchorState=null),!this.candidateGateway){this.hasRoutedPreview=!1;const h=this.resolveStartAnchor(c,this.axisConstrained);this._arrowSteps=h?this.orthogonalMousePreview(h,c):[],this.scheduleCalculateArrowSteps();return}this.calculateArrowSteps()}handleMouseUp(){try{const t=this.candidateAnchor,e=this.candidateAnchorState,s=this.candidateGateway?this.resolveStartAnchor(this.candidateGateway.parent.box.middle,this.axisConstrained):null;this.candidateGateway&&t&&e&&s&&this.candidateGateway.canConnect(s.gateway)&&s.gateway.canStartConnection(this.candidateGateway)&&(this.emit(new Se(this,s.gateway.parent,this.candidateGateway.parent)).cancelled||(this._arrowSteps=[],this.diagram.connect(s.gateway,this.candidateGateway,{fromDisplacement:s.displacement,startAnchor:this.startAnchorMode==="automatic"&&!this.axisConstrained?{mode:"automatic"}:{mode:"fixed",position:s.relativePosition},toDisplacement:t.displacement,endAnchor:e})))}finally{this.cancelPendingConnection(),this._arrowSteps=[],this.hasRoutedPreview=!1,this.startGateway=null,this.startAnchor=null,this.startAnchorMode="fixed",this.axisConstrained=!1,this.arrowTo=null,this.candidateGateway=null,this.candidateAnchor=null,this.candidateAnchorState=null,this.previewRequestVersion=0,this.cancelScheduledPreview(),this.u()}}};o(Oi,"NodesConnector");let de=Oi;const Fi=class Fi extends z{init(){this.diagram.onEvent(ke,()=>{},this.diagram.priorities.Node_Selection_Nodes_Resizer)}};o(Fi,"NodesResizer");let cn=Fi,Ja=(ye=class extends z{grid=null;points=null;highlighted=new Set;init(){g.makeObservable(this,{grid:g.observable,setGrid:g.action,points:g.observable,highlighted:g.observable})}setGrid(t,e){this.grid=t,this.points=e}},o(ye,"PathFindingRenderer"),ye);const Oe=1e3,Hi=class Hi{Canvas_Rules=Oe;Change_History=0;Click_Node=100;Drag_Rules=Oe;Drag_Node_Straight_Drag=500;Drag_Node_Distances_Balancer=400;Drag_Node_Aligner=200;Drag_Node_Snap_To_Grid=100;Drag_Edge_Snap_To_Grid=100;Mouse_Down_Rules=Oe;Mouse_Down_Measurer=400;Mouse_Down_Selector=300;Mouse_Down_Node=200;Mouse_Down_Dragger=100;Mouse_Move_Straight_Drag=500;Mouse_Move_Selector=100;Mouse_Up_Straight_Drag=500;Mouse_Up_Dragger=200;Mouse_Up_Selector=100;Nodes_Connection_Rules=Oe;Node_Selection_Nodes_Resizer=200;Node_Selection_Selector=200;Scale_Dragger=100;Selection_Rules=Oe};o(Hi,"Priorities");let ln=Hi;const Qa="diagram-grid-visible",Bi=class Bi{constructor(t){this.d=t,t.onEvent(et,this.check(()=>this.allowEdition),t.priorities.Mouse_Down_Rules),t.onEvent(Me,this.check(()=>this.allowSelection),t.priorities.Selection_Rules),t.onEvent(Ot,this.check(()=>this.allowEdition),t.priorities.Drag_Rules),t.onEvent(_e,this.check(()=>this.allowEdition),t.priorities.Nodes_Connection_Rules),t.onEvent(ve,this.check(()=>this.allowZoom),t.priorities.Drag_Rules),g.makeAutoObservable(this)}d;allowEdition=!0;allowSelection=!0;allowZoom=!0;displaceWhenDragOnEdges=!0;_toggleGrid=localStorage.getItem(Qa)!=="false";get toggleGrid(){return this._toggleGrid}set toggleGrid(t){this._toggleGrid=t,localStorage.setItem(Qa,String(t))}check=o(t=>e=>{t()||(e.cancel(),e.stopImmediatePropagation())},"check")};o(Bi,"Rules");let dn=Bi;const Gi=class Gi extends z{straight="none";startCoordinates=null;startProposals=[];shiftHeld=!1;reset(){this.straight="none",this.startCoordinates=null,this.startProposals=[],this.shiftHeld=!1}init(){this.diagram.onEvent(Rt,t=>{t.shift&&(this.shiftHeld=!0,this.startCoordinates=ae.getInstance().coordinates)}),this.diagram.onEvent(we,t=>{t.shift||this.reset()}),this.diagram.onEvent(Pt,t=>{t.shift&&!this.startCoordinates&&(this.shiftHeld=!0,this.startCoordinates=new y(t.originalEvent))}),this.diagram.onEvent(Ct,t=>{if(!this.shiftHeld||!this.startCoordinates)return;const e=Math.abs(t.mouse.x-this.startCoordinates.x),s=Math.abs(t.mouse.y-this.startCoordinates.y);(e||s)&&(this.straight=e>=s?"x":"y")},this.diagram.priorities.Mouse_Move_Straight_Drag),this.diagram.onEvent(tt,()=>{this.reset()},this.diagram.priorities.Mouse_Up_Straight_Drag),this.diagram.onEvent(ht,t=>{if(this.straight!=="none"){this.startProposals.length===0&&(this.startProposals=t.proposals.map(e=>new Ae(e.node,e.node.box)));for(const e of t.proposals){const s=this.startProposals.find(i=>i.node.id===e.node.id);switch(this.straight){case"x":e.updateY(s.newBox.y),e.lockY();break;case"y":e.updateX(s.newBox.x),e.lockX();break}}}},this.diagram.priorities.Drag_Node_Straight_Drag)}};o(Gi,"StraightDrag");let hn=Gi;const Ri=class Ri extends z{shiftHeld=!1;init(){this.diagram.onEvent(Rt,t=>{t.shift&&(this.shiftHeld=!0)}),this.diagram.onEvent(we,t=>{t.shift||(this.shiftHeld=!1)})}constrain(t,e,s=e){if(!this.enabled||!this.shiftHeld)return e;const i=Math.abs(s.x-t.x),a=Math.abs(s.y-t.y),r=e.copy();return i>=a?r.y=t.y:r.x=t.x,r}};o(Ri,"StraightLabelsDrag");let Fe=Ri;const tr=M.createContext(null),So=o(()=>({Creator:rn,DistancesBalancer:Ce,StraightDrag:hn,StraightLabelsDrag:Fe,Dragger:on,EdgesDragger:le,GridSnap:G,History:Ie,Hotkeys:an,LabelsAligner:_t,Measurer:De,NodesAligner:Zt,NodesConnector:de,NodesResizer:cn,PathFindingRenderer:Ja,Selector:Y}),"getDefaultExtensions"),Os=class Os extends Yt{priorities=new ln;rules=new dn(this);focusContentTimer=null;knownClasses=new Map;getClass(t){return this.knownClasses.get(t)}registerClass(t,e=t.name){this.knownClasses.set(e,t)}edgeClass=Xt;setDefaultEdge(t){this.edgeClass=t}_extensions=new Map;_nodes=new Map;_edges=new Map;_hoveredNode=null;canvas=new vo(this);constructor(t){super(null),this.registerClass(ws),this.registerClass(Xt),this.registerClass(Ht),this.registerClass(Es),Object.entries(So()).forEach(([e,s])=>{t?.extensions?.[e]!==!1&&this.registerExtension(s)}),g.makeObservable(this,{edges:g.computed,_edges:g.observable,_hoveredNode:g.observable.ref,_nodes:g.observable,clearNodeHover:g.action,hoveredNode:g.computed,setNodeHover:g.action,toggleGrid:g.action})}get edges(){return[...this._edges.values()]}get extensions(){return[...this._extensions.values()]}get nodes(){return[...this._nodes.values()]}get hoveredNode(){return this._hoveredNode}setNodeHover(t,e){t.diagram===this&&(e?(this._hoveredNode&&this._hoveredNode!==t&&(this._hoveredNode.state.hover=!1),this._hoveredNode=t,t.state.hover=!0):this._hoveredNode===t?(t.state.hover=!1,this._hoveredNode=null):t.state.hover=!1)}clearNodeHover(){this._hoveredNode&&(this._hoveredNode.state.hover=!1),this._hoveredNode=null}getUniqueNodeId(t){if(!this._nodes.has(t))return t;let e=1,s=`${t}-${e}`;for(;this._nodes.has(s);)e++,s=`${t}-${e}`;return s}add(t){return g.runInAction(()=>{const e=this.getUniqueNodeId(t.id);e!==t.id&&t.setState("id",e),t.setDiagram(this),this._nodes.set(t.id,t)}),t}addEdge(t){t.from.addOutgoingEdge(t),t.to.addIncomingEdge(t)}connect(t,e,s){const i=s?.startAnchor??{mode:"fixed",position:t.parent.findFixedConnectionAnchor(t.coordinates.copy().sum(s?.fromDisplacement??new y)).relativePosition},a=s?.endAnchor??{mode:"fixed",position:e.parent.findFixedConnectionAnchor(e.coordinates.copy().sum(s?.toDisplacement??new y)).relativePosition},r=new this.edgeClass(this,{hover:!1,dragging:!1,selected:!1,from:t,to:e,labels:[],pathType:s?.pathType??"orthogonal",displacementStart:s?.fromDisplacement,displacementEnd:s?.toDisplacement,startAnchor:i,endAnchor:a,steps:[]});return this.connectWithEdge(t,e,r)}connectWithEdge(t,e,s){const i=s;return i.from.addOutgoingEdge(i),i.to.addIncomingEdge(i),this._edges.set(i.id,i),i}delete(t){this.emit(new ie(this,t)).cancelled||g.runInAction(()=>{t.gateways.forEach(e=>{e.incomingEdges.forEach(this.disconnect.bind(this)),e.outgoingEdges.forEach(this.disconnect.bind(this))}),this._hoveredNode===t&&(t.state.hover=!1,this._hoveredNode=null),this._nodes.delete(t.id),t.parent=null})}disconnect(t){this.emit(new as(this,t)).cancelled||g.runInAction(()=>{for(const e of this.nodes)for(const s of e.gateways)s.removeIncomingEdge(t),s.removeOutgoingEdge(t);this._edges.delete(t.id),t.parent=null})}Context=o(({children:t})=>d.jsx(tr.Provider,{value:this,children:t}),"Context");getEdgeById(t){return this._edges.get(t)}getNodeById(t){return this._nodes.get(t)}get showGrid(){return this.rules.toggleGrid}getExtension(t){return this._extensions.get(t)}registerExtension(t){const e=new t(this);e.init(),this._extensions.set(t,e)}toggleGrid(){this.rules.toggleGrid=!this.rules.toggleGrid}export(){return JSON.stringify(this.serialize())}async reset(){let t=this._nodes.size===0;if(!t){let e=null;const s=this.emit(new Ys(this,i=>{e=i}));t=await e()&&!s.cancelled}if(t){for(const e of this._nodes.values())this.delete(e);return!0}return!1}serialize(){return{position:{x:this.canvas.displacement.x,y:this.canvas.displacement.y,scale:this.canvas.scale},nodes:this.nodes.map(t=>t.serialize())}}import(t){g.runInAction(()=>{const e=JSON.parse(t),s=e.position,i=!!s&&Number.isFinite(s.x)&&Number.isFinite(s.y)&&Number.isFinite(s.scale);if(i&&(this.canvas.setScale(s.scale),this.canvas.setDisplacement(new y([s.x,s.y]))),e.nodes){const a=new Map;e.nodes.forEach(r=>{const c=this.getClass(r.class);if(!c)throw new Error(`Unable to import node: unknown class '${r.class}'.`);const l=new c(this,{id:r.id}),h=this.add(l);a.set(r.id,h.id)}),e.nodes.forEach(r=>{const c=a.get(r.id),l=this.getNodeById(c),h=l.remapSerializedReferences({...r,id:c,gateways:r.gateways.map(u=>({...u,outEdges:u.outEdges.map(f=>({...f,toParentId:a.get(f.toParentId)||f.toParentId}))}))},a);l.deserialize(h)})}i||this.focusContentInViewportWithRetry()})}paste(t){g.runInAction(()=>{const e=JSON.parse(t);if(e.position&&(this.canvas.setScale(e.position.scale),this.canvas.setDisplacement(new y([e.position.x,e.position.y]))),e.nodes?.length){const s=new Map,i=[];e.nodes.forEach(l=>{const h=Pe(this,"node",i);s.set(l.id,h),i.push(h)});let a=new y([1/0,1/0]);e.nodes.forEach(l=>{const h=new y([l.box[0],l.box[1]]);h.norm<a.norm&&(a=h)});const c=this.canvas.inverseFit(ae.getInstance().coordinates).substract(a);e.nodes.forEach(l=>{const h=this.getClass(l.class);if(!h)throw new Error(`Unable to paste node: unknown class '${l.class}'.`);const u=new h(this,{id:s.get(l.id)});this.add(u)}),e.nodes.forEach(l=>{const h=s.get(l.id),u=this.getNodeById(h),f=u.remapSerializedReferences({...l,id:h,gateways:l.gateways.map(p=>({...p,outEdges:p.outEdges.map(m=>({...m,toParentId:s.get(m.toParentId)||m.toParentId}))})),box:[l.box[0]+c.x,l.box[1]+c.y,l.box[2],l.box[3]]},s);u.deserialize(f)})}})}focusContentInViewport(t=80){if(!this.nodes.length)return!1;const e=this.canvas.frameDimensions;if(e.width<=0||e.height<=0)return!1;let s=1/0,i=1/0,a=-1/0,r=-1/0;for(const u of this.nodes){const f=u.box;s=Math.min(s,f.x),i=Math.min(i,f.y),a=Math.max(a,f.x+f.width),r=Math.max(r,f.y+f.height)}if(!Number.isFinite(s)||!Number.isFinite(i)||!Number.isFinite(a)||!Number.isFinite(r))return!1;const c=Math.max(1,a-s+t*2),l=Math.max(1,r-i+t*2),h=Math.max(.3,Math.min(3,Math.min(e.width/c,e.height/l)));return this.canvas.setScale(h),this.canvas.centerOnPoint(new y([(s+a)/2,(i+r)/2])),!0}focusContentInViewportWithRetry(t=8,e=32){this.focusContentInViewport()||t<=0||(this.focusContentTimer&&clearTimeout(this.focusContentTimer),this.focusContentTimer=setTimeout(()=>{this.focusContentInViewportWithRetry(t-1,e)},e))}};o(Os,"Diagram"),kt(Os,"use",o(()=>M.useContext(tr),"use"));let q=Os;function jt(n,t){return{"data-id":n.id,onMouseEnter:o(()=>n.setHovered(!0),"onMouseEnter"),onMouseLeave:o(e=>{const s=e.relatedTarget;s instanceof Element&&s.closest(`[data-id="${n.id}"], [data-gateway-parent="${n.id}"]`)||n.setHovered(!1)},"onMouseLeave"),style:{"--screen-renderer-x":`${t.x}px`,"--screen-renderer-y":`${t.y}px`,"--screen-renderer-width":`${t.width}px`,"--screen-renderer-height":`${t.height}px`,"--screen-renderer-z-index":n.state.hover?(n.state.zIndex??100)+1:n.state.zIndex??100}}}o(jt,"screenRendererProps");function Ss(n){return["Enter","Escape"].includes(n.code)}o(Ss,"allowEventInEdition");const Vi=class Vi extends z{inEdition=new Set;cancel(){this.inEdition.forEach(t=>t.cancel()),this.inEdition.clear()}confirm(){this.inEdition.forEach(t=>t.confirm()),this.inEdition.clear()}editNode(t){t.edit(),this.inEdition.add(t)}init(){this.diagram.onEvent(Rt,t=>{switch(t.code){case"F2":{const e=this.diagram.getExtension(Y).selectedNodes[0];e instanceof St&&this.editNode(e);break}case"Escape":{this.cancel();break}case"Enter":t.shift||this.confirm()}}),this.diagram.onEvent(Pt,t=>{(!t.node||t.node instanceof St&&!this.inEdition.has(t.node))&&this.confirm()},this.diagram.priorities.Mouse_Down_Dragger+1),this.diagram.onEvent(is,t=>{t.node instanceof St&&!this.inEdition.has(t.node)&&(this.confirm(),this.editNode(t.node))})}};o(Vi,"EditionMode");let Ms=Vi;function Mo(n,t){const e=n.box.middle,s=t.middle,i=s.x-e.x,a=s.y-e.y;return Math.abs(i)>Math.abs(a)?i<0?"left":"right":a<0?"top":"bottom"}o(Mo,"externalLabelPosition");const er=A.observer(({node:n,box:t})=>{const e=M.useRef(!1),s=jt(n,t),i=/(?:^| )(?:bpmn__event|bpmn__gate|bpmn__data_store|bpmn__document)(?: |$)/.test(n.classList.string),a=i?t.y-n.labelOffset.y-(n.box.y+n.box.height):void 0,r=i?Mo(n,t):void 0,c=i?{"data-node-label-position":r}:{},l=i?" bpmn__axis-label":"",h=/(?:^| )bpmn__text_annotation(?: |$)/.test(n.classList.string)?" bpmn__text-annotation-label":"",u=/(?:^| )bpm__node(?: |$)/.test(n.classList.string)?" bpmn__node-label":"";return s.style["--screen-label-font-size"]=`${n.state.labelFontSize??14}px`,n.editionMode?d.jsx("textarea",{...s,...c,className:`node__screenLabel node__screenHitArea editable__label${l}${h}${u}${n.selected?" selected":""}`,autoFocus:!0,value:n.state.label,onChange:o(f=>{g.runInAction(()=>{n.state.label=f.target.value})},"onChange"),onKeyDownCapture:o(f=>{n.editionMode&&!Ss(f.nativeEvent)&&f.nativeEvent.stopImmediatePropagation()},"onKeyDownCapture"),ref:o(f=>{f instanceof HTMLTextAreaElement&&!e.current&&(e.current=!0,f.select())},"ref")}):(e.current=!1,n.state.label?d.jsx("pre",{...s,...c,"data-node-label-drag-handle":i?"true":void 0,"data-node-label-gap":a,"data-node-label-height":i?t.height:void 0,"data-node-label-width":i?t.width:void 0,className:`node__screenLabel node__screenHitArea${l}${h}${u}${n.selected?" selected":""}`,children:n.state.label}):null)}),Yi=class Yi extends et{constructor(t,e,s){super(t),this.src=t,this.previousLabel=e,this.nextLabel=s}src;previousLabel;nextLabel};o(Yi,"DEditNodeEvent");let un=Yi;const Wi=class Wi extends ws{editionMode=!1;constructor(t,e){super(t,e),g.makeObservable(this,{editionMode:g.observable,edit:g.action,cancel:g.action,confirm:g.action})}get label(){return this.state.label}previous=null;edit(){this.previous=this.state.label,this.editionMode=!0}cancel(){this.state.label=this.previous,this.editionMode=!1}confirm(){return this.emit(new un(this,this.previous,this.state.label)).cancelled?(this.cancel(),!1):(this.editionMode=!1,!0)}get isChanged(){return this.previous!==this.state.label}get screenLabelBox(){return this.box}get labelScreenBox(){return this.screenLabelBox}RenderScreen=A.observer(()=>d.jsx(er,{node:this,box:this.screenLabelBox}))};o(Wi,"EditableNode");let St=Wi;const Zi=class Zi extends q{constructor(t){super(t),this.registerClass(St),this.registerExtension(Ms)}};o(Zi,"EditableDiagram");let He=Zi;const Xi=class Xi extends Xt{kind="default";constructor(t,e){super(t,e),g.makeObservable(this,{kind:g.observable,setKind:g.action}),this.setKind(e.kind??"default")}setKind(t){switch(this.kind=t,t){case"trigger":this.state.stroke="#38bdf8",this.state.lineStyle="solid",this.state.arrowHeadEnd="triangle-filled";break;case"condition-true":this.state.stroke="#22c55e",this.state.lineStyle="solid",this.state.arrowHeadEnd="triangle-filled";break;case"condition-false":this.state.stroke="#ef4444",this.state.lineStyle="dashed",this.state.arrowHeadEnd="triangle-filled";break;default:this.state.stroke=void 0,this.state.lineStyle="solid",this.state.arrowHeadEnd="arrow";break}}serialize(){return{...super.serialize(),kind:this.kind}}deserialize(t){super.deserialize(t),this.setKind(t.kind??"default")}};o(Xi,"AgentEdge");let ks=Xi;function ko(n){return{position:"absolute",left:`${n.box.x}px`,top:`${n.box.y}px`,zIndex:n.state.hover?n.state.zIndex+1:n.state.zIndex,width:`${n.box.width}px`,height:`${n.box.height}px`}}o(ko,"customRendererStyles");function K(n){const t=ko(n);return n.state.fill&&(t["--node-fill"]=n.state.fill),n.state.stroke&&(t["--node-stroke"]=n.state.stroke),{onMouseOver:o(()=>n.setState("hover",!0),"onMouseOver"),onMouseOut:o(e=>{const s=e.relatedTarget;s instanceof Element&&s.closest(`[data-id="${n.id}"], [data-gateway-parent="${n.id}"]`)||n.setState("hover",!1)},"onMouseOut"),"data-id":n.id,style:t,className:`${n.classList.string} ${n.selected?"selected":""}`}}o(K,"customRendererProps");function Be(n){return typeof n=="object"&&n?Array.isArray(n)?n.map(t=>Be(t)):Object.fromEntries(Object.entries(n).map(([t,e])=>[t,Be(e)])):n}o(Be,"cloneDeep");const qi=class qi extends St{payload;constructor(t,e){super(t,e),this.classList.add("agent__node","diagram__node"),this.payload=this.mergePayload(e.payload),g.makeObservable(this,{payload:g.observable.ref,replacePayload:g.action,updatePayload:g.action})}mergePayload(t){return{...this.defaultPayload(),...t??{}}}replacePayload(t){this.payload=this.mergePayload(t)}updatePayload(t){this.payload={...this.payload,...t}}serialize(){return{...super.serialize(),kind:this.kind,payload:Be(this.payload)}}deserialize(t){super.deserialize(t),this.payload=this.mergePayload(t.payload)}};o(qi,"AgentNode");let Ut=qi;const Ui=class Ui extends Ut{kind="action";constructor(t,e){super(t,{...e,box:e.box??new S([0,0,220,110])}),this.classList.add("agent__action")}defaultPayload(){return{actionType:"task",operation:"",inputRef:"",outputRef:"",metadata:{}}}RenderOverlay=A.observer(()=>d.jsx("div",{...K(this)}))};o(Ui,"ActionNode");let gn=Ui;const Ki=class Ki extends Ut{kind="condition";constructor(t,e){super(t,{...e,box:e.box??new S([0,0,180,120])}),this.classList.add("agent__condition")}defaultPayload(){return{expression:"",language:"rule",trueLabel:"True",falseLabel:"False",metadata:{}}}RenderOverlay=A.observer(()=>d.jsx("div",{...K(this),children:d.jsx("svg",{viewBox:`0 0 ${this.state.box.width} ${this.state.box.height}`,preserveAspectRatio:"none",style:{width:"100%",height:"100%"},children:d.jsx("polygon",{points:`${this.state.box.width/2} 0 ${this.state.box.width} ${this.state.box.height/2} ${this.state.box.width/2} ${this.state.box.height} 0 ${this.state.box.height/2}`})})}))};o(Ki,"ConditionNode");let pn=Ki;const Ji=class Ji extends Ut{kind="outcome";constructor(t,e){super(t,{...e,box:e.box??new S([0,0,180,90])}),this.classList.add("agent__outcome")}defaultPayload(){return{status:"success",code:"",summary:"",metadata:{}}}RenderOverlay=A.observer(()=>d.jsx("div",{...K(this)}))};o(Ji,"OutcomeNode");let fn=Ji;const Qi=class Qi extends Ut{kind="trigger";constructor(t,e){super(t,{...e,box:e.box??new S([0,0,170,90])}),this.classList.add("agent__trigger")}defaultPayload(){return{triggerType:"manual",source:"",eventName:"",schedule:"",metadata:{}}}RenderOverlay=A.observer(()=>d.jsx("div",{...K(this)}))};o(Qi,"TriggerNode");let mn=Qi;const ta=class ta extends He{constructor(t){super(t),this.registerClass(Ut),this.registerClass(mn),this.registerClass(gn),this.registerClass(pn),this.registerClass(fn),this.registerClass(ks),this.setDefaultEdge(ks)}};o(ta,"AgentDiagram");let yn=ta;const ea=class ea extends St{edgesAsGateways=!0;occupiesGridSquare=!1;constructor(t,e){super(t,{...e,labelFontSize:e.labelFontSize??16}),this.classList.add("bpm__node","diagram__node")}fitToGridSquare(){if(!this.occupiesGridSquare)return;const t=this.diagram?.getExtension(G)?.gridSize??50;this.state.box.assignDimensions([t,t])}setDiagram(t){super.setDiagram(t),this.fitToGridSquare()}deserialize(t){super.deserialize(t),this.state.labelFontSize=t.labelFontSize,this.fitToGridSquare()}};o(ea,"BPMNode");let st=ea;var sr={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},nr=M.createContext&&M.createContext(sr),Ao=["attr","size","title"];function Po(n,t){if(n==null)return{};var e,s,i=Co(n,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(n);for(s=0;s<a.length;s++)e=a[s],t.indexOf(e)===-1&&{}.propertyIsEnumerable.call(n,e)&&(i[e]=n[e])}return i}o(Po,"_objectWithoutProperties");function Co(n,t){if(n==null)return{};var e={};for(var s in n)if({}.hasOwnProperty.call(n,s)){if(t.indexOf(s)!==-1)continue;e[s]=n[s]}return e}o(Co,"_objectWithoutPropertiesLoose");function As(){return As=Object.assign?Object.assign.bind():function(n){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var s in e)({}).hasOwnProperty.call(e,s)&&(n[s]=e[s])}return n},As.apply(null,arguments)}o(As,"_extends");function ir(n,t){var e=Object.keys(n);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(n);t&&(s=s.filter(function(i){return Object.getOwnPropertyDescriptor(n,i).enumerable})),e.push.apply(e,s)}return e}o(ir,"ownKeys");function Ps(n){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?ir(Object(e),!0).forEach(function(s){Io(n,s,e[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(e)):ir(Object(e)).forEach(function(s){Object.defineProperty(n,s,Object.getOwnPropertyDescriptor(e,s))})}return n}o(Ps,"_objectSpread");function Io(n,t,e){return(t=Do(t))in n?Object.defineProperty(n,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):n[t]=e,n}o(Io,"_defineProperty");function Do(n){var t=jo(n,"string");return typeof t=="symbol"?t:t+""}o(Do,"_toPropertyKey");function jo(n,t){if(typeof n!="object"||!n)return n;var e=n[Symbol.toPrimitive];if(e!==void 0){var s=e.call(n,t);if(typeof s!="object")return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(n)}o(jo,"_toPrimitive");function ar(n){return n&&n.map((t,e)=>M.createElement(t.tag,Ps({key:e},t.attr),ar(t.child)))}o(ar,"Tree2Element");function L(n){return t=>M.createElement(No,As({attr:Ps({},n.attr)},t),ar(n.child))}o(L,"GenIcon");function No(n){var t=o(e=>{var s=n.attr,i=n.size,a=n.title,r=Po(n,Ao),c=i||e.size||"1em",l;return e.className&&(l=e.className),n.className&&(l=(l?l+" ":"")+n.className),M.createElement("svg",As({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},e.attr,s,r,{className:l,style:Ps(Ps({color:n.color||e.color},e.style),n.style),height:c,width:c,xmlns:"http://www.w3.org/2000/svg"}),a&&M.createElement("title",null,a),n.children)},"elem");return nr!==void 0?M.createElement(nr.Consumer,null,e=>t(e)):t(sr)}o(No,"IconBase");function To(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M230.92,212c-15.23-26.33-38.7-45.21-66.09-54.16a72,72,0,1,0-73.66,0C63.78,166.78,40.31,185.66,25.08,212a8,8,0,1,0,13.85,8c18.84-32.56,52.14-52,89.07-52s70.23,19.44,89.07,52a8,8,0,1,0,13.85-8ZM72,96a56,56,0,1,1,56,56A56.06,56.06,0,0,1,72,96Z"},child:[]}]})(n)}o(To,"PiUser");function rr(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M216,48H176V40a24,24,0,0,0-24-24H104A24,24,0,0,0,80,40v8H40a8,8,0,0,0,0,16h8V208a16,16,0,0,0,16,16H192a16,16,0,0,0,16-16V64h8a8,8,0,0,0,0-16ZM96,40a8,8,0,0,1,8-8h48a8,8,0,0,1,8,8v8H96Zm96,168H64V64H192ZM112,104v64a8,8,0,0,1-16,0V104a8,8,0,0,1,16,0Zm48,0v64a8,8,0,0,1-16,0V104a8,8,0,0,1,16,0Z"},child:[]}]})(n)}o(rr,"PiTrash");function Lo(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M32,64a8,8,0,0,1,8-8H216a8,8,0,0,1,0,16H40A8,8,0,0,1,32,64ZM216,96H88a8,8,0,0,0,0,16H216a8,8,0,0,0,0-16Zm0,40H40a8,8,0,0,0,0,16H216a8,8,0,0,0,0-16Zm0,40H88a8,8,0,0,0,0,16H216a8,8,0,0,0,0-16Z"},child:[]}]})(n)}o(Lo,"PiTextAlignRight");function $o(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M32,64a8,8,0,0,1,8-8H216a8,8,0,0,1,0,16H40A8,8,0,0,1,32,64Zm8,48H168a8,8,0,0,0,0-16H40a8,8,0,0,0,0,16Zm176,24H40a8,8,0,0,0,0,16H216a8,8,0,0,0,0-16Zm-48,40H40a8,8,0,0,0,0,16H168a8,8,0,0,0,0-16Z"},child:[]}]})(n)}o($o,"PiTextAlignLeft");function zo(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M32,64a8,8,0,0,1,8-8H216a8,8,0,0,1,0,16H40A8,8,0,0,1,32,64ZM64,96a8,8,0,0,0,0,16H192a8,8,0,0,0,0-16Zm152,40H40a8,8,0,0,0,0,16H216a8,8,0,0,0,0-16Zm-24,40H64a8,8,0,0,0,0,16H192a8,8,0,0,0,0-16Z"},child:[]}]})(n)}o(zo,"PiTextAlignCenter");function Oo(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M224,48H32a8,8,0,0,0-8,8V192a16,16,0,0,0,16,16H216a16,16,0,0,0,16-16V56A8,8,0,0,0,224,48ZM40,112H80v32H40Zm56,0H216v32H96ZM216,64V96H40V64ZM40,160H80v32H40Zm176,32H96V160H216v32Z"},child:[]}]})(n)}o(Oo,"PiTable");function Fo(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M208,136H48a16,16,0,0,0-16,16v40a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V152A16,16,0,0,0,208,136Zm0,56H48V152H208v40Zm0-144H48A16,16,0,0,0,32,64v40a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V64A16,16,0,0,0,208,48Zm0,56H48V64H208v40Z"},child:[]}]})(n)}o(Fo,"PiRows");function Ho(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M208,160H48a16,16,0,0,0-16,16v24a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V176A16,16,0,0,0,208,160Zm0,40H48V176H208v24Zm0-112H48a16,16,0,0,0-16,16v24a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V104A16,16,0,0,0,208,88Zm0,40H48V104H208v24ZM96,40a8,8,0,0,1,8-8h16V16a8,8,0,0,1,16,0V32h16a8,8,0,0,1,0,16H136V64a8,8,0,0,1-16,0V48H104A8,8,0,0,1,96,40Z"},child:[]}]})(n)}o(Ho,"PiRowsPlusTop");function Bo(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M208,112H48a16,16,0,0,0-16,16v24a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V128A16,16,0,0,0,208,112Zm0,40H48V128H208v24Zm0-112H48A16,16,0,0,0,32,56V80A16,16,0,0,0,48,96H208a16,16,0,0,0,16-16V56A16,16,0,0,0,208,40Zm0,40H48V56H208V80ZM160,216a8,8,0,0,1-8,8H136v16a8,8,0,0,1-16,0V224H104a8,8,0,0,1,0-16h16V192a8,8,0,0,1,16,0v16h16A8,8,0,0,1,160,216Z"},child:[]}]})(n)}o(Bo,"PiRowsPlusBottom");function or(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M208,32H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V48A16,16,0,0,0,208,32Zm0,176H48V48H208V208Zm-32-80a8,8,0,0,1-8,8H136v32a8,8,0,0,1-16,0V136H88a8,8,0,0,1,0-16h32V88a8,8,0,0,1,16,0v32h32A8,8,0,0,1,176,128Z"},child:[]}]})(n)}o(or,"PiPlusSquare");function Go(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M227.31,73.37,182.63,28.68a16,16,0,0,0-22.63,0L36.69,152A15.86,15.86,0,0,0,32,163.31V208a16,16,0,0,0,16,16H92.69A15.86,15.86,0,0,0,104,219.31L227.31,96a16,16,0,0,0,0-22.63ZM92.69,208H48V163.31l88-88L180.69,120ZM192,108.68,147.31,64l24-24L216,84.68Z"},child:[]}]})(n)}o(Go,"PiPencilSimple");function Ro(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M208,32H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H156.69A15.86,15.86,0,0,0,168,219.31L219.31,168A15.86,15.86,0,0,0,224,156.69V48A16,16,0,0,0,208,32ZM48,48H208V152H160a8,8,0,0,0-8,8v48H48ZM196.69,168,168,196.69V168Z"},child:[]}]})(n)}o(Ro,"PiNoteBlank");function Vo(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M176,128a8,8,0,0,1-8,8H88a8,8,0,0,1,0-16h80A8,8,0,0,1,176,128Zm56,0A104,104,0,1,1,128,24,104.11,104.11,0,0,1,232,128Zm-16,0a88,88,0,1,0-88,88A88.1,88.1,0,0,0,216,128Z"},child:[]}]})(n)}o(Vo,"PiMinusCircle");function Yo(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M188,48a27.75,27.75,0,0,0-12,2.71V44a28,28,0,0,0-54.65-8.6A28,28,0,0,0,80,60v64l-3.82-6.13a28,28,0,0,0-48.6,27.82c16,33.77,28.93,57.72,43.72,72.69C86.24,233.54,103.2,240,128,240a88.1,88.1,0,0,0,88-88V76A28,28,0,0,0,188,48Zm12,104a72.08,72.08,0,0,1-72,72c-20.38,0-33.51-4.88-45.33-16.85C69.44,193.74,57.26,171,41.9,138.58a6.36,6.36,0,0,0-.3-.58,12,12,0,0,1,20.79-12,1.76,1.76,0,0,0,.14.23l18.67,30A8,8,0,0,0,96,152V60a12,12,0,0,1,24,0v60a8,8,0,0,0,16,0V44a12,12,0,0,1,24,0v76a8,8,0,0,0,16,0V76a12,12,0,0,1,24,0Z"},child:[]}]})(n)}o(Yo,"PiHand");function Wo(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M232,64a32,32,0,1,0-40,31v17a8,8,0,0,1-8,8H96a23.84,23.84,0,0,0-8,1.38V95a32,32,0,1,0-16,0v66a32,32,0,1,0,16,0V144a8,8,0,0,1,8-8h88a24,24,0,0,0,24-24V95A32.06,32.06,0,0,0,232,64ZM64,64A16,16,0,1,1,80,80,16,16,0,0,1,64,64ZM96,192a16,16,0,1,1-16-16A16,16,0,0,1,96,192ZM200,80a16,16,0,1,1,16-16A16,16,0,0,1,200,80Z"},child:[]}]})(n)}o(Wo,"PiGitBranch");function cr(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,80a48,48,0,1,0,48,48A48.05,48.05,0,0,0,128,80Zm0,80a32,32,0,1,1,32-32A32,32,0,0,1,128,160Zm109.94-52.79a8,8,0,0,0-3.89-5.4l-29.83-17-.12-33.62a8,8,0,0,0-2.83-6.08,111.91,111.91,0,0,0-36.72-20.67,8,8,0,0,0-6.46.59L128,41.85,97.88,25a8,8,0,0,0-6.47-.6A112.1,112.1,0,0,0,54.73,45.15a8,8,0,0,0-2.83,6.07l-.15,33.65-29.83,17a8,8,0,0,0-3.89,5.4,106.47,106.47,0,0,0,0,41.56,8,8,0,0,0,3.89,5.4l29.83,17,.12,33.62a8,8,0,0,0,2.83,6.08,111.91,111.91,0,0,0,36.72,20.67,8,8,0,0,0,6.46-.59L128,214.15,158.12,231a7.91,7.91,0,0,0,3.9,1,8.09,8.09,0,0,0,2.57-.42,112.1,112.1,0,0,0,36.68-20.73,8,8,0,0,0,2.83-6.07l.15-33.65,29.83-17a8,8,0,0,0,3.89-5.4A106.47,106.47,0,0,0,237.94,107.21Zm-15,34.91-28.57,16.25a8,8,0,0,0-3,3c-.58,1-1.19,2.06-1.81,3.06a7.94,7.94,0,0,0-1.22,4.21l-.15,32.25a95.89,95.89,0,0,1-25.37,14.3L134,199.13a8,8,0,0,0-3.91-1h-.19c-1.21,0-2.43,0-3.64,0a8.08,8.08,0,0,0-4.1,1l-28.84,16.1A96,96,0,0,1,67.88,201l-.11-32.2a8,8,0,0,0-1.22-4.22c-.62-1-1.23-2-1.8-3.06a8.09,8.09,0,0,0-3-3.06l-28.6-16.29a90.49,90.49,0,0,1,0-28.26L61.67,97.63a8,8,0,0,0,3-3c.58-1,1.19-2.06,1.81-3.06a7.94,7.94,0,0,0,1.22-4.21l.15-32.25a95.89,95.89,0,0,1,25.37-14.3L122,56.87a8,8,0,0,0,4.1,1c1.21,0,2.43,0,3.64,0a8.08,8.08,0,0,0,4.1-1l28.84-16.1A96,96,0,0,1,188.12,55l.11,32.2a8,8,0,0,0,1.22,4.22c.62,1,1.23,2,1.8,3.06a8.09,8.09,0,0,0,3,3.06l28.6,16.29A90.49,90.49,0,0,1,222.9,142.12Z"},child:[]}]})(n)}o(cr,"PiGearSix");function Zo(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M213.66,82.34l-56-56A8,8,0,0,0,152,24H56A16,16,0,0,0,40,40V216a16,16,0,0,0,16,16H200a16,16,0,0,0,16-16V88A8,8,0,0,0,213.66,82.34ZM160,51.31,188.69,80H160ZM200,216H56V40h88V88a8,8,0,0,0,8,8h48V216Z"},child:[]}]})(n)}o(Zo,"PiFile");function Xo(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24C74.17,24,32,48.6,32,80v96c0,31.4,42.17,56,96,56s96-24.6,96-56V80C224,48.6,181.83,24,128,24Zm80,104c0,9.62-7.88,19.43-21.61,26.92C170.93,163.35,150.19,168,128,168s-42.93-4.65-58.39-13.08C55.88,147.43,48,137.62,48,128V111.36c17.06,15,46.23,24.64,80,24.64s62.94-9.68,80-24.64ZM69.61,53.08C85.07,44.65,105.81,40,128,40s42.93,4.65,58.39,13.08C200.12,60.57,208,70.38,208,80s-7.88,19.43-21.61,26.92C170.93,115.35,150.19,120,128,120s-42.93-4.65-58.39-13.08C55.88,99.43,48,89.62,48,80S55.88,60.57,69.61,53.08ZM186.39,202.92C170.93,211.35,150.19,216,128,216s-42.93-4.65-58.39-13.08C55.88,195.43,48,185.62,48,176V159.36c17.06,15,46.23,24.64,80,24.64s62.94-9.68,80-24.64V176C208,185.62,200.12,195.43,186.39,202.92Z"},child:[]}]})(n)}o(Xo,"PiDatabase");function qo(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M69.12,94.15,28.5,128l40.62,33.85a8,8,0,1,1-10.24,12.29l-48-40a8,8,0,0,1,0-12.29l48-40a8,8,0,0,1,10.24,12.3Zm176,27.7-48-40a8,8,0,1,0-10.24,12.3L227.5,128l-40.62,33.85a8,8,0,1,0,10.24,12.29l48-40a8,8,0,0,0,0-12.29ZM162.73,32.48a8,8,0,0,0-10.25,4.79l-64,176a8,8,0,0,0,4.79,10.26A8.14,8.14,0,0,0,96,224a8,8,0,0,0,7.52-5.27l64-176A8,8,0,0,0,162.73,32.48Z"},child:[]}]})(n)}o(qo,"PiCode");function Uo(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm0,192a88,88,0,1,1,88-88A88.1,88.1,0,0,1,128,216Zm64-88a8,8,0,0,1-8,8H128a8,8,0,0,1-8-8V72a8,8,0,0,1,16,0v48h48A8,8,0,0,1,192,128Z"},child:[]}]})(n)}o(Uo,"PiClock");function lr(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm0,192a88,88,0,1,1,88-88A88.1,88.1,0,0,1,128,216Z"},child:[]}]})(n)}o(lr,"PiCircle");function Ko(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M90.34,61.66a8,8,0,0,1,0-11.32l32-32a8,8,0,0,1,11.32,0l32,32a8,8,0,0,1-11.32,11.32L136,43.31V96a8,8,0,0,1-16,0V43.31L101.66,61.66A8,8,0,0,1,90.34,61.66Zm64,132.68L136,212.69V160a8,8,0,0,0-16,0v52.69l-18.34-18.35a8,8,0,0,0-11.32,11.32l32,32a8,8,0,0,0,11.32,0l32-32a8,8,0,0,0-11.32-11.32Zm83.32-72-32-32a8,8,0,0,0-11.32,11.32L212.69,120H160a8,8,0,0,0,0,16h52.69l-18.35,18.34a8,8,0,0,0,11.32,11.32l32-32A8,8,0,0,0,237.66,122.34ZM43.31,136H96a8,8,0,0,0,0-16H43.31l18.35-18.34A8,8,0,0,0,50.34,90.34l-32,32a8,8,0,0,0,0,11.32l32,32a8,8,0,0,0,11.32-11.32Z"},child:[]}]})(n)}o(Ko,"PiArrowsOutCardinal");function Jo(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M213.66,181.66l-32,32a8,8,0,0,1-11.32-11.32L188.69,184H48a8,8,0,0,1,0-16H188.69l-18.35-18.34a8,8,0,0,1,11.32-11.32l32,32A8,8,0,0,1,213.66,181.66Zm-139.32-64a8,8,0,0,0,11.32-11.32L67.31,88H208a8,8,0,0,0,0-16H67.31L85.66,53.66A8,8,0,0,0,74.34,42.34l-32,32a8,8,0,0,0,0,11.32Z"},child:[]}]})(n)}o(Jo,"PiArrowsLeftRight");function Qo(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M208,28H48A20,20,0,0,0,28,48V208a20,20,0,0,0,20,20H208a20,20,0,0,0,20-20V48A20,20,0,0,0,208,28Zm-4,176H52V52H204ZM76,128a12,12,0,0,1,12-12h28V88a12,12,0,0,1,24,0v28h28a12,12,0,0,1,0,24H140v28a12,12,0,0,1-24,0V140H88A12,12,0,0,1,76,128Z"},child:[]}]})(n)}o(Qo,"PiPlusSquareBold");function tc(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,20A108,108,0,1,0,236,128,108.12,108.12,0,0,0,128,20Zm0,192a84,84,0,1,1,84-84A84.09,84.09,0,0,1,128,212Z"},child:[]}]})(n)}o(tc,"PiCircleBold");function ec(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M224.49,136.49l-72,72a12,12,0,0,1-17-17L187,140H40a12,12,0,0,1,0-24H187L135.51,64.48a12,12,0,0,1,17-17l72,72A12,12,0,0,1,224.49,136.49Z"},child:[]}]})(n)}o(ec,"PiArrowRightBold");function sc(n){return L({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M228,128a100,100,0,0,1-98.66,100H128a99.39,99.39,0,0,1-68.62-27.29,12,12,0,0,1,16.48-17.45,76,76,0,1,0-1.57-109c-.13.13-.25.25-.39.37L54.89,92H72a12,12,0,0,1,0,24H24a12,12,0,0,1-12-12V56a12,12,0,0,1,24,0V76.72L57.48,57.06A100,100,0,0,1,228,128Z"},child:[]}]})(n)}o(sc,"PiArrowCounterClockwiseBold");const nc={task:To,serviceTask:cr,scriptTask:qo,manualTask:Yo,businessRuleTask:Oo,callActivity:Qo,subprocess:or,eventSubprocess:or,event:lr,start:lr,end:tc,timer:Uo,lanes:Fo,dataStore:Xo,document:Zo,textAnnotation:Ro,connect:ec,settings:cr};function ic({id:n,className:t}){const e=n==="messageThrow"||n==="sendTask";return d.jsxs("svg",{className:`${t??""} bpmn__message_icon bpmn__message_icon--${e?"send":"receive"}`,viewBox:"0 0 24 24","aria-hidden":"true",children:[d.jsx("rect",{className:"bpmn__message_body",x:"3.5",y:"5.5",width:"17",height:"13",rx:"1.25"}),d.jsx("path",{className:"bpmn__message_fold",d:"m4.5 7 7.5 6 7.5-6"})]})}o(ic,"MessageIcon");function ac({id:n,className:t}){return d.jsxs("svg",{className:t,viewBox:"0 0 24 24","aria-hidden":"true",children:[n==="intermediate"&&d.jsxs(d.Fragment,{children:[d.jsx("circle",{cx:"12",cy:"12",r:"8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.45"}),d.jsx("circle",{cx:"12",cy:"12",r:"6.1",fill:"none",stroke:"currentColor",strokeWidth:"1.25"})]}),n==="signal"&&d.jsx("path",{className:"bpmn__event_symbol_fillable bpmn__event_symbol--signal",d:"M12 4.6 20 18H4Z",fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:"1.65"}),n==="compensation"&&d.jsx("path",{className:"bpmn__event_symbol_fillable bpmn__event_symbol--compensation",d:"m11.4 6.2-7 5.8 7 5.8Zm8.2 0-7 5.8 7 5.8Z",fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:"1.55"}),n==="error"&&d.jsx("path",{className:"bpmn__event_symbol_fillable bpmn__event_symbol--error",d:"m13.2 3.7-6.1 8.1 4.1-.1-.5 8.6 6.2-9.2-4 .1Z",fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:"1.55"}),n==="conditional"&&d.jsxs(d.Fragment,{children:[d.jsx("path",{className:"bpmn__event_symbol_outline bpmn__event_symbol--conditional-frame",d:"M6.5 4.5h11v15h-11Z",fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:"1.45"}),d.jsx("path",{className:"bpmn__event_symbol_outline bpmn__event_symbol--conditional-lines",d:"M9 8h6m-6 3h6m-6 3h6",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeWidth:"1.25"})]}),n==="terminate"&&d.jsx("circle",{cx:"12",cy:"12",r:"7.2",fill:"currentColor"})]})}o(ac,"EventDefinitionIcon");function rc({id:n,className:t}){return d.jsxs("svg",{className:t,viewBox:"0 0 24 24","aria-hidden":"true",children:[n==="blackBoxPool"&&d.jsxs(d.Fragment,{children:[d.jsx("rect",{x:"2.5",y:"5",width:"19",height:"14",rx:"1",fill:"none",stroke:"currentColor",strokeWidth:"1.5"}),d.jsx("path",{d:"M7 5v14",fill:"none",stroke:"currentColor",strokeWidth:"1.5"})]}),n==="documentAnnotation"&&d.jsxs(d.Fragment,{children:[d.jsx("path",{d:"M5 2.8h9l5 5v13.4H5Z",fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:"1.45"}),d.jsx("path",{d:"M14 2.8v5h5",fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:"1.45"}),d.jsx("path",{d:"M8 12h8m-8 3h6",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeWidth:"1.25"})]})]})}o(rc,"SupportIcon");function oc({id:n,className:t,markerOnly:e}){const s=e?n==="eventBased"?"6 6 12 12":"5 5 14 14":"0 0 24 24";return d.jsxs("svg",{className:[t,`bpmn__gate_marker--${n}`].filter(Boolean).join(" "),viewBox:s,"aria-hidden":"true",children:[!e&&d.jsx("path",{d:"M12 2.7 21.3 12 12 21.3 2.7 12 12 2.7Z",fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:"1.65"}),n==="exclusive"&&d.jsx("path",{d:"m8.5 8.5 7 7m0-7-7 7",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeWidth:"2.2"}),n==="inclusive"&&d.jsx("circle",{cx:"12",cy:"12",r:"4.15",fill:"none",stroke:"currentColor",strokeWidth:"2"}),n==="parallel"&&d.jsx("path",{d:"M12 7v10M7 12h10",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeWidth:"2.2"}),n==="eventBased"&&d.jsxs(d.Fragment,{children:[d.jsx("circle",{cx:"12",cy:"12",r:"5.4",fill:"none",stroke:"currentColor",strokeWidth:e?1:1.35}),d.jsx("circle",{cx:"12",cy:"12",r:"3.8",fill:"none",stroke:"currentColor",strokeWidth:e?.9:1.15}),d.jsx("path",{d:"m12 9.1 2.75 2-1.05 3.2h-3.4l-1.05-3.2 2.75-2Z",fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:e?.82:1.1})]})]})}o(oc,"GatewayIcon");function Nt({id:n,className:t,markerOnly:e}){const s=nc[n];return s?d.jsx(s,{"aria-hidden":"true",className:t}):n==="messageCatch"||n==="messageThrow"||n==="message"||n==="receiveTask"||n==="sendTask"?d.jsx(ic,{className:t,id:n}):n==="intermediate"||n==="signal"||n==="compensation"||n==="error"||n==="conditional"||n==="terminate"?d.jsx(ac,{className:t,id:n}):n==="blackBoxPool"||n==="documentAnnotation"?d.jsx(rc,{className:t,id:n}):n==="exclusive"||n==="inclusive"||n==="parallel"||n==="eventBased"?d.jsx(oc,{className:t,id:n,markerOnly:e}):d.jsxs("svg",{className:t,viewBox:"0 0 24 24","aria-hidden":"true",children:[d.jsx("circle",{cx:"6.5",cy:"6.5",r:"3.25",fill:"none",stroke:"currentColor",strokeWidth:"1.7"}),d.jsx("path",{d:"m9.3 8.8 5.7 5m-1.9 0h2.25v-2.25",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.7"}),d.jsx("rect",{x:"14.1",y:"14.1",width:"6.4",height:"5.6",rx:"1",fill:"none",stroke:"currentColor",strokeWidth:"1.7"})]})}o(Nt,"BPMNIcon");var T=(n=>(n[n.start=0]="start",n[n.end=1]="end",n[n.intermediate=2]="intermediate",n[n.timer=3]="timer",n[n.messageCatch=4]="messageCatch",n[n.messageThrow=5]="messageThrow",n[n.signalCatch=6]="signalCatch",n[n.signalThrow=7]="signalThrow",n[n.compensationCatch=8]="compensationCatch",n[n.compensationThrow=9]="compensationThrow",n[n.errorCatch=10]="errorCatch",n[n.errorThrow=11]="errorThrow",n[n.conditional=12]="conditional",n[n.terminate=13]="terminate",n))(T||{});const Cs={0:{stage:"start",kind:"none",direction:"catch"},1:{stage:"end",kind:"none",direction:"throw"},2:{stage:"start",kind:"none",direction:"throw"},3:{stage:"intermediate",kind:"timer",direction:"catch"},4:{stage:"intermediate",kind:"message",direction:"catch"},5:{stage:"intermediate",kind:"message",direction:"throw"},6:{stage:"intermediate",kind:"signal",direction:"catch"},7:{stage:"intermediate",kind:"signal",direction:"throw"},8:{stage:"intermediate",kind:"compensation",direction:"catch"},9:{stage:"intermediate",kind:"compensation",direction:"throw"},10:{stage:"intermediate",kind:"error",direction:"catch"},11:{stage:"end",kind:"error",direction:"throw"},12:{stage:"intermediate",kind:"conditional",direction:"catch"},13:{stage:"end",kind:"terminate",direction:"throw"}},cc=new Set(["start","intermediate","end"]),lc=new Set(["none","timer","message","signal","compensation","error","conditional","terminate"]),dc=new Set(["catch","throw"]),hc={none:new Set(["start","end"]),message:new Set(["start","intermediate","end"]),timer:new Set(["start","intermediate"]),error:new Set(["intermediate","end"]),signal:new Set(["start","intermediate","end"]),compensation:new Set(["intermediate","end"]),conditional:new Set(["start","intermediate"]),terminate:new Set(["end"])},uc={none:new Set(["catch","throw"]),message:new Set(["catch","throw"]),timer:new Set(["catch"]),error:new Set(["catch","throw"]),signal:new Set(["catch","throw"]),compensation:new Set(["catch","throw"]),conditional:new Set(["catch"]),terminate:new Set(["throw"])};function Kt(n){if(!n||typeof n!="object")return!1;const t=n;if(!cc.has(t.stage)||!lc.has(t.kind)||!dc.has(t.direction))return!1;const{stage:e,kind:s,direction:i}=t;return hc[s].has(e)&&uc[s].has(i)}o(Kt,"isValidEventDefinition");const gc=5,pc=3,fc=1.18,mc=["bpmn__event__start","bpmn__event__intermediate","bpmn__event__end"],yc=["bpmn--none","bpmn--timer","bpmn--message","bpmn--signal","bpmn--compensation","bpmn--error","bpmn--conditional","bpmn--terminate"],xc=["bpmn--catch","bpmn--throw"],Is=new Set(["timer","message","signal","compensation","error","conditional"]),xn=new Set(["timer","message","signal","compensation","error","conditional"]),bc=Object.values(T).filter(n=>typeof n=="string").map(n=>`bpmn--${n}`);function Ge(n){return{...n}}o(Ge,"copyDefinition");function dr(n){return Kt(n.eventDefinition)?Ge(n.eventDefinition):typeof n.type=="number"&&Cs[n.type]?Ge(Cs[n.type]):Ge(Cs[T.start])}o(dr,"resolveDefinition");function hr(n){return!Array.isArray(n)||n.length!==2||!Number.isFinite(n[0])||!Number.isFinite(n[1])?null:[n[0],n[1]]}o(hr,"resolveAttachmentOffset");function wc(n,t){return n.stage===t.stage&&n.kind===t.kind&&n.direction===t.direction}o(wc,"sameDefinition");const sa=class sa extends st{definition;attachedToTaskId;attachmentOffset;interrupting;subprocessStart;subprocessId;edgesAsGateways=!0;occupiesGridSquare=!0;constructor(t,e){super(t,e),this.definition=dr(e),this.attachedToTaskId=e.attachedToTaskId&&Is.has(this.definition.kind)?e.attachedToTaskId:null,this.attachmentOffset=this.attachedToTaskId?hr(e.attachmentOffset):null,this.interrupting=e.interrupting??!0,this.subprocessId=e.subprocessStart===!0&&xn.has(this.definition.kind)&&!this.attachedToTaskId&&typeof e.subprocessId=="string"&&e.subprocessId.length>0?e.subprocessId:null,this.subprocessStart=this.subprocessId!==null,g.makeObservable(this,{definition:g.observable.ref,attachedToTaskId:g.observable,attachmentOffset:g.observable.ref,interrupting:g.observable,subprocessStart:g.observable,subprocessId:g.observable,stage:g.computed,kind:g.computed,direction:g.computed,type:g.computed,isStart:g.computed,isEnd:g.computed,isCatching:g.computed,canAttach:g.computed,canStartSubprocess:g.computed,setDefinition:g.action,setType:g.action,setAttachment:g.action,setInterrupting:g.action,setSubprocessStart:g.action}),this.fitToGridSquare(),this.classList.add("bpmn__event"),this.refreshSemanticClasses(),this.refreshAttachmentPresentation()}get stage(){return this.definition.stage}get kind(){return this.definition.kind}get direction(){return this.definition.direction}get type(){return this.kind==="none"?this.stage==="start"?T.start:this.stage==="end"?T.end:T.intermediate:this.kind==="timer"?T.timer:this.kind==="message"?this.isCatching?T.messageCatch:T.messageThrow:this.kind==="signal"?this.isCatching?T.signalCatch:T.signalThrow:this.kind==="compensation"?this.isCatching?T.compensationCatch:T.compensationThrow:this.kind==="error"?this.isCatching?T.errorCatch:T.errorThrow:this.kind==="conditional"?T.conditional:T.terminate}get isStart(){return this.stage==="start"}get isEnd(){return this.stage==="end"}get isCatching(){return this.direction==="catch"}get canAttach(){return Is.has(this.kind)&&!this.subprocessStart}get canStartSubprocess(){return xn.has(this.kind)&&!this.attachedToTaskId}setDefinition(t){return!Kt(t)||this.attachedToTaskId&&!Is.has(t.kind)||this.subprocessStart&&!xn.has(t.kind)?!1:wc(this.definition,t)?!0:this.emit(new Vt(this)).cancelled?!1:(this.definition=Ge(t),this.isEnd?this._gateways.forEach(e=>e.outgoingEdges.forEach(s=>this.diagram?.disconnect(s))):this.isStart&&this._gateways.forEach(e=>e.incomingEdges.forEach(s=>this.diagram?.disconnect(s))),this.refreshSemanticClasses(),this.refreshAttachmentPresentation(),!0)}setType(t){const e=Cs[t];return e?this.setDefinition(e):!1}setAttachment(t,e=null,s=!0){t&&!Is.has(this.kind)||(this.attachedToTaskId=t,this.attachmentOffset=t?hr(e):null,this.interrupting=s,t&&(this.subprocessStart=!1,this.subprocessId=null),this.refreshAttachmentPresentation())}setInterrupting(t){this.interrupting=t,this.refreshAttachmentPresentation()}setSubprocessStart(t,e=null){return t?!this.canStartSubprocess||!e?!1:(this.subprocessStart=!0,this.subprocessId=e,this.refreshAttachmentPresentation(),!0):(this.subprocessStart=!1,this.subprocessId=null,this.refreshAttachmentPresentation(),!0)}serialize(){return{...super.serialize(),type:this.type,eventDefinition:Ge(this.definition),attachedToTaskId:this.attachedToTaskId,attachmentOffset:this.attachmentOffset?[...this.attachmentOffset]:null,interrupting:this.interrupting,subprocessStart:this.subprocessStart,subprocessId:this.subprocessId}}deserialize(t){this.setAttachment(null),this.setSubprocessStart(!1),this.definition=dr(t),this.setAttachment(t.attachedToTaskId??null,t.attachmentOffset??null,t.interrupting??!0),this.setSubprocessStart(t.subprocessStart??!1,t.subprocessId??null),super.deserialize(t),this.refreshSemanticClasses(),this.refreshAttachmentPresentation()}remapSerializedReferences(t,e){const s=t;if(!s.attachedToTaskId&&!s.subprocessId)return t;const i=s.attachedToTaskId?e.get(s.attachedToTaskId)??null:null,a=s.subprocessId?e.get(s.subprocessId)??null:null;return{...s,attachedToTaskId:i,attachmentOffset:i?s.attachmentOffset??null:null,subprocessId:a,subprocessStart:s.subprocessStart===!0&&a!==null}}get screenLabelBox(){const t=this.box,e=Math.max(t.width,120),s=Math.max(this.state.labelFontSize??14,14);return new S([t.x+t.width/2-e/2,t.y+t.height+gc,e,s*fc*pc]).sum(this.labelOffset)}refreshSemanticClasses(){[...mc,...yc,...xc,...bc].forEach(t=>this.classList.delete(t)),this.classList.add(`bpmn__event__${this.stage}`,`bpmn--${this.kind}`,`bpmn--${this.direction}`,`bpmn--${T[this.type]}`)}refreshAttachmentPresentation(){if(this.classList.delete("bpmn--boundary"),this.classList.delete("bpmn--non-interrupting"),this.classList.delete("bpmn--subprocess-start"),this.subprocessStart&&this.classList.add("bpmn--subprocess-start"),!this.attachedToTaskId){this.state.zIndex=100;return}this.classList.add("bpmn--boundary"),this.interrupting||this.classList.add("bpmn--non-interrupting"),this.state.zIndex=120}get markerIconId(){return this.kind==="none"?null:this.kind==="message"?this.isCatching?"messageCatch":"messageThrow":this.kind}RenderOverlay=A.observer(()=>{const t=this.markerIconId;return d.jsx("div",{...K(this),children:t&&d.jsx(Nt,{className:`bpmn__node_marker bpmn__event_marker bpmn__event_marker--${this.direction}`,id:t})})})};o(sa,"EventNode");let D=sa;function Re(n,t){return`bpmn__event__${n[t]}`}o(Re,"getEnumStr");var H=(n=>(n[n.inclusive=0]="inclusive",n[n.exclusive=1]="exclusive",n[n.parallel=2]="parallel",n[n.eventBased=3]="eventBased",n))(H||{});const vc=5,Ec=3,_c=1.18;function Sc(n){return typeof n?.setDefault=="function"}o(Sc,"canSetDefaultFlow");const na=class na extends st{type=-1;edgesAsGateways=!0;occupiesGridSquare=!0;constructor(t,e){super(t,e),g.makeObservable(this,{type:g.observable,setType:g.action}),this.setType(e.type??1),this.fitToGridSquare(),this.classList.add("bpmn__gate")}setType(t){if(this.type!==t&&!this.emit(new Vt(this)).cancelled){this.type=t,t!==1&&t!==0&&this.gateways.forEach(e=>e.outgoingEdges.forEach(s=>{Sc(s)&&s.setDefault(!1)}));for(const e of Object.values(H))this.classList.delete(Re(H,e));switch(t){case 1:this.classList.add(Re(H,1));break;case 0:this.classList.add(Re(H,0));break;case 2:this.classList.add(Re(H,2));break;case 3:this.classList.add(Re(H,3));break}}}serialize(){return{...super.serialize(),type:this.type}}deserialize(t){this.setType(t.type??1),super.deserialize(t)}get screenLabelBox(){const t=this.box,e=Math.max(t.width,120),s=Math.max(this.state.labelFontSize??14,14);return new S([t.x+t.width/2-e/2,t.y+t.height+vc,e,s*_c*Ec]).sum(this.labelOffset)}RenderOverlay=A.observer(()=>{const t=this.state.box.width,e=this.state.box.height;return d.jsx("div",{...K(this),children:d.jsxs("svg",{viewBox:`0 0 ${t} ${e}`,style:{width:`${t}px`,height:`${e}px`},children:[d.jsx("polygon",{points:`${t/2} 0 ${t} ${e/2} ${t/2} ${e} 0 ${e/2}`}),d.jsx("foreignObject",{width:t,height:e,children:d.jsx(Nt,{className:"bpmn__gate_marker",markerOnly:!0,id:this.type===1?"exclusive":this.type===0?"inclusive":this.type===2?"parallel":"eventBased"})})]})})})};o(na,"GateNode");let W=na;const ft={sections:{activities:"Activities",events:"Events",gateways:"Gateways",support:"Data & context"},elements:{task:"User task",serviceTask:"Service task",sendTask:"Send task",receiveTask:"Receive task",scriptTask:"Script task",manualTask:"Manual task",businessRuleTask:"Business rule task",callActivity:"Call activity",subprocess:"Sub-process",eventSubprocess:"Event sub-process",event:"Regular event",start:"Start event",intermediate:"Intermediate event",end:"End event",timer:"Timer event",message:"Message event",messageCatch:"Catch message",messageThrow:"Throw message",signal:"Signal event",compensation:"Compensation event",error:"Error / exception event",conditional:"Conditional / business rule event",terminate:"Terminate event",exclusive:"Exclusive gateway",inclusive:"Inclusive gateway",parallel:"Parallel gateway",eventBased:"Event-based gateway",lanes:"Lanes",blackBoxPool:"Black-box pool",dataStore:"Data store",document:"Document",documentAnnotation:"Document annotation",textAnnotation:"Text annotation"},eventOptions:{none:"—",start:"Start",intermediate:"Intermediate",end:"End",catch:"Catch",throw:"Throw"},actions:{transform:"Change element type",connect:"Connect to a new element",settings:"Toggle properties",close:"Close properties",delete:"Delete element",reverseDirection:"Reverse direction",resize:"Resize",resizeElement:"Resize BPMN element"},properties:{title:"Properties",name:"Name",type:"Element type",condition:"Condition",defaultFlow:"Default flow",directed:"Directed",edgeType:"Connection type",routingType:"Routing",eventType:"Event type",eventStage:"Event stage",eventDirection:"Event direction",interrupting:"Interrupting",subprocessStart:"Event sub-process start",eventSubprocessStartType:"Start event type",loop:"Conditional loop",multiInstance:"Parallel multi-instance"},edges:{sequenceFlow:"Sequence flow",messageFlow:"Message flow",inputDataAssociation:"Input data association",outputDataAssociation:"Output data association",association:"Association"},routing:{orthogonal:"Orthogonal",straight:"Straight",curved:"Curved"},inputs:{blackBoxPoolName:"Black box pool name",documentAnnotationText:"Document annotation text",elementSearch:"Search elements",laneName:"Lane name"},resizeDirections:{n:"n",ne:"ne",e:"e",se:"se",s:"s",sw:"sw",w:"w",nw:"nw"},lanes:{defaultLane:"Default",pool:"Pool",rename:"Rename lane",insertBefore:"Insert lane before",subdivide:"Subdivide lane",removeSubdivision:"Remove subdivision",removeLane:"Remove lane",insertAfter:"Insert lane after"}};Object.values(ft).forEach(Object.freeze),Object.freeze(ft);function bn(n={},t=ft){return{sections:{...t.sections,...n.sections},elements:{...t.elements,...n.elements},eventOptions:{...t.eventOptions,...n.eventOptions},actions:{...t.actions,...n.actions},properties:{...t.properties,...n.properties},edges:{...t.edges,...n.edges},routing:{...t.routing,...n.routing},inputs:{...t.inputs,...n.inputs},resizeDirections:{...t.resizeDirections,...n.resizeDirections},lanes:{...t.lanes,...n.lanes}}}o(bn,"configureBPMNLabels");const ia=class ia extends et{};o(ia,"BPMNPropertyChangeEvent");let Z=ia;const ur=50;function Ds(n,t){return n<=t?[n,t]:[t,n]}o(Ds,"orderedRange");function wn(n,t){return Number.isFinite(t.distance)&&(!n||t.distance<n.distance)?t:n}o(wn,"closer");const aa=class aa extends z{alignmentProposals=[];init(){g.makeObservable(this,{alignmentProposals:g.observable,clear:g.action})}clear(){this.alignmentProposals=[]}suggest(t,e,s,i=e,a){if(this.clear(),!this.enabled||t.diagram!==this.diagram)return i;const r=a??t.minimumResizeSize;if(!r)return i;const c=ur/5*2,l=ur/3,h=this.diagram.canvas.frameDimensions.norm,u=h>0?h/2:1/0,f=s.includes("w"),p=s.includes("e"),m=s.includes("n"),x=s.includes("s");let b=null,w=null;for(const _ of this.diagram.nodes){if(_===t||!(_ instanceof st))continue;const E=_.box;(f||p)&&Math.abs(e.edgeDistanceY(E))<u&&(b=wn(b,this.sideCandidate(r,e,E,f?"w":"e",c)),b=wn(b,this.widthCandidate(r,e,E,f,c))),(m||x)&&Math.abs(e.edgeDistanceX(E))<u&&(w=wn(w,this.sideCandidate(r,e,E,m?"n":"s",c)))}g.runInAction(()=>{this.alignmentProposals=[...b?.guides??[],...w?.guides??[]]});const v=i.copy();return b&&b.distance<l&&(v.x=b.box.x,v.width=b.box.width),w&&w.distance<l&&(v.y=w.box.y,v.height=w.box.height),v}sideCandidate(t,e,s,i,a){const r=e.copy();let c,l;return i==="w"?(c=Math.abs(e.x-s.x),r.x=s.x,r.width=e.rightMiddle.x-s.x,l=[this.verticalGuide(s.x,r,s)]):i==="e"?(c=Math.abs(e.rightMiddle.x-s.rightMiddle.x),r.width=s.rightMiddle.x-e.x,l=[this.verticalGuide(s.rightMiddle.x,r,s)]):i==="n"?(c=Math.abs(e.y-s.y),r.y=s.y,r.height=e.bottomMiddle.y-s.y,l=[this.horizontalGuide(s.y,r,s)]):(c=Math.abs(e.bottomMiddle.y-s.bottomMiddle.y),r.height=s.bottomMiddle.y-e.y,l=[this.horizontalGuide(s.bottomMiddle.y,r,s)]),this.candidate(t,r,c,l,a)}widthCandidate(t,e,s,i,a){const r=e.copy(),c=Math.abs(e.width-s.width);return r.width=s.width,i&&(r.x=e.rightMiddle.x-s.width),this.candidate(t,r,c,this.widthGuides(r,s),a)}candidate(t,e,s,i,a){return{box:e,distance:s<a&&this.isValid(t,e)?s:1/0,guides:i}}isValid(t,e){const s=this.diagram.canvas.size;return e.width>=t.x&&e.height>=t.y&&e.x>=0&&e.y>=0&&e.rightMiddle.x<=s.x&&e.bottomMiddle.y<=s.y}verticalGuide(t,e,s){return{type:"h",x:t,range:Ds(Math.min(e.y,s.y),Math.max(e.bottomMiddle.y,s.bottomMiddle.y)),id:Wt("bpmn-resize-suggestion")}}horizontalGuide(t,e,s){return{type:"v",y:t,range:Ds(Math.min(e.x,s.x),Math.max(e.rightMiddle.x,s.rightMiddle.x)),id:Wt("bpmn-resize-suggestion")}}widthGuides(t,e){return[{type:"v",y:t.y,range:Ds(t.x,t.rightMiddle.x),id:Wt("bpmn-resize-suggestion")},{type:"v",y:e.y,range:Ds(e.x,e.rightMiddle.x),id:Wt("bpmn-resize-suggestion")}]}};o(aa,"BPMNResizeSuggester");let Bt=aa;const ra=class ra extends z{autopan=new ut(this.diagram);session=null;unbindSession=o(()=>{},"unbindSession");init(){}startResize(t,e,s){if(e.button!==0||t.diagram!==this.diagram)return;e.preventDefault(),e.stopImmediatePropagation(),this.endSession();const i=new y(e);this.session={changed:!1,direction:s,initialBox:new S(t.box.raw,!1),node:t,pointer:i,startPosition:this.diagram.canvas.inverseFit(i)},this.unbindSession=pt(R(this,"pointermove",this.handlePointerMove),R(this,"pointerup",this.endSession),R(this,"pointercancel",this.endSession),vs(this.handleAutopan,30))}resizeNode(t,e){if(t.diagram!==this.diagram)return!1;const s=e instanceof y?e:new y(e,!1),i=this.diagram.getExtension(G),a=i?.enabled===!0?i.gridSize:null,r=Math.max(0,this.diagram.canvas.size.x-t.box.x),c=Math.max(0,this.diagram.canvas.size.y-t.box.y),l=this.constrain(s.x,t.minimumResizeSize.x,r,a),h=this.constrain(s.y,t.minimumResizeSize.y,c,a);return this.applyBox(t,new S([t.box.x,t.box.y,l,h],!1))}resizeNodeFromDirection(t,e,s,i){if(t.diagram!==this.diagram)return!1;const a=this.diagram.getExtension(G),r=a?.enabled===!0?a.gridSize:null,c=s.includes("w"),l=s.includes("e"),h=s.includes("n"),u=s.includes("s"),f=c?e.x+e.width:this.diagram.canvas.size.x-e.x,p=h?e.y+e.height:this.diagram.canvas.size.y-e.y,m=e.width+(l?i.x:c?-i.x:0),x=e.height+(u?i.y:h?-i.y:0),b=c||l?this.constrain(m,t.minimumResizeSize.x,f,null):e.width,w=h||u?this.constrain(x,t.minimumResizeSize.y,p,null):e.height,v=c?e.x+e.width-b:e.x,_=h?e.y+e.height-w:e.y,E=new S([v,_,b,w],!1),C=r?this.snapDirectionalBoxToGrid(t,e,E,s,r):E,k=this.diagram.getExtension(Bt)?.suggest(t,E,s,C)??C;return this.applyBox(t,k)}snapDirectionalBoxToGrid(t,e,s,i,a){const r=s.copy(),c=e.rightMiddle.x,l=e.bottomMiddle.y;if(i.includes("w"))r.x=this.snapCoordinate(s.x,0,c-t.minimumResizeSize.x,a,e.x),r.width=c-r.x;else if(i.includes("e")){const h=this.snapCoordinate(s.rightMiddle.x,e.x+t.minimumResizeSize.x,this.diagram.canvas.size.x,a,c);r.width=h-e.x}if(i.includes("n"))r.y=this.snapCoordinate(s.y,0,l-t.minimumResizeSize.y,a,e.y),r.height=l-r.y;else if(i.includes("s")){const h=this.snapCoordinate(s.bottomMiddle.y,e.y+t.minimumResizeSize.y,this.diagram.canvas.size.y,a,l);r.height=h-e.y}return r}snapCoordinate(t,e,s,i,a){const r=Math.ceil(e/i)*i,c=Math.floor(s/i)*i;if(r>c)return a;const l=Math.round(t/i)*i;return Math.min(c,Math.max(r,l))}applyBox(t,e){return t.box.x===e.x&&t.box.y===e.y&&t.box.width===e.width&&t.box.height===e.height?!1:(g.runInAction(()=>{t.state.box.assign(e)}),this.rerouteConnectedEdges(t),!0)}constrain(t,e,s,i){const a=Number.isFinite(t)?t:e,r=Math.min(e,s),c=i?Math.ceil(r/i)*i:r,l=i?Math.round(a/i)*i:a;return Math.min(s,Math.max(c,l))}rerouteConnectedEdges(t){const e=new Set;t.gateways.forEach(s=>{s.incomingEdges.forEach(i=>e.add(i)),s.outgoingEdges.forEach(i=>e.add(i))}),e.forEach(s=>s.from.recomputeConnectedEdge(s,"from"))}handlePointerMove(t){this.session&&(this.session.pointer=new y(t),this.resizeFromPointer())}handleAutopan=o(()=>{this.session&&(this.autopan.displace(this.session.pointer),this.resizeFromPointer())},"handleAutopan");resizeFromPointer(){if(!this.session)return;const e=this.diagram.canvas.inverseFit(this.session.pointer).copy(!1).substract(this.session.startPosition),s=this.resizeNodeFromDirection(this.session.node,this.session.initialBox,this.session.direction,e);this.session.changed=this.session.changed||s}endSession(){const t=this.session?.changed===!0;this.session=null;const e=this.unbindSession;this.unbindSession=()=>{},e(),this.diagram.getExtension(Bt)?.clear(),t&&this.emit(new Z(this))}};o(ra,"BPMNNodeResizer");let js=ra;const Mc=["n","ne","e","se","s","sw","w","nw"],kc={n:{top:"-5px",left:"50%",transform:"translateX(-50%)"},ne:{top:"-5px",right:"-5px"},e:{top:"50%",right:"-5px",transform:"translateY(-50%)"},se:{right:"-5px",bottom:"-5px"},s:{bottom:"-5px",left:"50%",transform:"translateX(-50%)"},sw:{bottom:"-5px",left:"-5px"},w:{top:"50%",left:"-5px",transform:"translateY(-50%)"},nw:{top:"-5px",left:"-5px"}},Ac={n:"ns-resize",ne:"nesw-resize",e:"ew-resize",se:"nwse-resize",s:"ns-resize",sw:"nesw-resize",w:"ew-resize",nw:"nwse-resize"};function Ns({node:n}){const t=n.diagram?.getExtension(js);if(!n.selected||!t)return null;const e=n.diagram?.bpmnLabels??ft,s=o((a,r)=>{a.button===0&&(a.preventDefault(),a.stopPropagation(),a.nativeEvent.stopImmediatePropagation(),t.startResize(n,a.nativeEvent,r))},"beginResize"),i=jt(n,n.box);return d.jsx("div",{...i,className:"node__screenLabel bpmn__node_resize_handles",style:{...i.style,display:"block",overflow:"visible",pointerEvents:"none"},children:Mc.map(a=>d.jsx("button",{"aria-label":`${e.actions.resizeElement} ${e.resizeDirections[a]}`,className:`bpmn__node_resize_handle bpmn__node_resize_handle--${a}`,"data-diagram-interactive-ui":"true",onClick:o(r=>{r.preventDefault(),r.stopPropagation()},"onClick"),onMouseDownCapture:o(r=>{r.preventDefault(),r.stopPropagation(),r.nativeEvent.stopImmediatePropagation()},"onMouseDownCapture"),onPointerDown:o(r=>s(r,a),"onPointerDown"),style:{position:"absolute",zIndex:2,width:"11px",height:"11px",padding:0,border:"1px solid var(--node-stroke)",borderRadius:"2px",background:"var(--diagram-lane-toolbar-bg, var(--node-fill))",boxSizing:"border-box",cursor:Ac[a],pointerEvents:"auto",touchAction:"none",...kc[a]},tabIndex:-1,title:`${e.actions.resize} ${e.resizeDirections[a]}`,type:"button"},a))})}o(Ns,"BPMNResizeHandle");var N=(n=>(n[n.task=0]="task",n[n.service=1]="service",n[n.callActivity=2]="callActivity",n[n.subprocess=3]="subprocess",n[n.send=4]="send",n[n.receive=5]="receive",n[n.script=6]="script",n[n.manual=7]="manual",n[n.eventSubprocess=8]="eventSubprocess",n[n.businessRule=9]="businessRule",n))(N||{});const Pc={0:"task",1:"serviceTask",4:"sendTask",5:"receiveTask",6:"scriptTask",7:"manualTask",9:"businessRuleTask"},gr=new Set(Object.values(N).filter(n=>typeof n=="number"));function pr(n){return n==="parallel"?"parallel":"none"}o(pr,"normalizeMultiInstance");function Tt(n){return n===3||n===8}o(Tt,"isSubprocessType");function Cc(n){return Tt(n)?new S([0,0,400,250]):new S([0,0,150,100])}o(Cc,"defaultTaskBox");const oa=class oa extends st{type=-1;minimumResizeSize=new y([300,200],!1);multiInstance;loop;edgesAsGateways=!0;constructor(t,e){super(t,{...e,box:e.box||Cc(e.type),groupChildren:Tt(e.type),zIndex:e.zIndex??(Tt(e.type)?50:100)}),this.classList.add("bpmn__task"),this.multiInstance=pr(e.multiInstance),this.loop=e.loop===!0,g.makeObservable(this,{type:g.observable,multiInstance:g.observable,loop:g.observable,setType:g.action,setMultiInstance:g.action,setLoop:g.action}),this.setType(e.type??0)}fitWidthToGrid(t=!1){if(Tt(this.type))return;const s=(this.diagram?.getExtension(G)?.gridSize??50)*3;t&&(this.state.box.x+=(this.state.box.width-s)/2),this.state.box.width=s}applySubprocessState(t){const e=Tt(this.type);if(this.state.groupChildren=e,this.state.zIndex=e?50:100,e){this.classList.add("bpmn__resizable_node");const r=Math.max(this.state.box.width,this.minimumResizeSize.x),c=Math.max(this.state.box.height,this.minimumResizeSize.y);if(t){this.state.box.assignDimensions([r,c]);return}this.state.box.x-=(r-this.state.box.width)/2,this.state.box.y-=(c-this.state.box.height)/2,this.state.box.assignDimensions([r,c]);return}if(this.classList.delete("bpmn__resizable_node"),!t)return;const s=this.diagram?.getExtension(G)?.gridSize??50,i=s*3,a=s*2;this.state.box.x+=(this.state.box.width-i)/2,this.state.box.y+=(this.state.box.height-a)/2,this.state.box.assignDimensions([i,a])}setDiagram(t){super.setDiagram(t),this.fitWidthToGrid()}setType(t){if(!gr.has(t))return!1;if(this.type===t)return!0;if(this.emit(new Vt(this)).cancelled)return!1;const e=Tt(this.type);return gr.has(this.type)&&this.classList.delete(`bpmn--${N[this.type]}`),this.type=t,this.classList.add(`bpmn--${N[t]}`),this.applySubprocessState(e),!0}setMultiInstance(t){return t!=="none"&&t!=="parallel"?!1:this.multiInstance===t?!0:this.emit(new Vt(this)).cancelled?!1:(this.multiInstance=t,!0)}setLoop(t){return this.loop===t?!0:this.emit(new Vt(this)).cancelled?!1:(this.loop=t,!0)}serialize(){return{...super.serialize(),type:this.type,multiInstance:this.multiInstance,loop:this.loop}}deserialize(t){this.setType(t.type??0),this.setMultiInstance(pr(t.multiInstance)),this.setLoop(t.loop===!0),super.deserialize(t),this.applySubprocessState(Tt(this.type)),this.fitWidthToGrid(!0)}get screenLabelBox(){if(!Tt(this.type))return this.box;const t=this.box;return new S([t.x+16,t.y+8,Math.max(0,t.width-32),32])}RenderScreen=A.observer(()=>d.jsxs(d.Fragment,{children:[d.jsx(er,{node:this,box:this.screenLabelBox}),Tt(this.type)&&d.jsx(Ns,{node:this})]}));RenderOverlay=A.observer(()=>{const t=Pc[this.type],e=this.type===2;return d.jsxs("div",{...K(this),children:[t&&d.jsx(Nt,{className:"bpmn__node_marker bpmn__task_marker",id:t}),(e||this.multiInstance==="parallel"||this.loop)&&d.jsxs("span",{className:"bpmn__task_bottom_markers",children:[e&&d.jsx("span",{className:"bpmn__task_plus",children:"+"}),this.loop&&d.jsx(sc,{"aria-hidden":"true",className:"bpmn__task_loop"}),this.multiInstance==="parallel"&&d.jsx("svg",{"aria-hidden":"true",className:"bpmn__task_multi_instance",viewBox:"0 0 24 16",children:d.jsx("path",{d:"M7 2v12M12 2v12M17 2v12",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeWidth:"2"})})]})]})})};o(oa,"TaskNode");let j=oa;const ca=class ca extends st{sourceType="unknown";constructor(t,e){super(t,{...e,box:e.box||new S([0,0,200,100])}),this.sourceType=e.sourceType||"unknown",this.classList.add("bpmn__unknown")}serialize(){return{...super.serialize(),sourceType:this.sourceType}}deserialize(t){super.deserialize(t),this.sourceType=t.sourceType||"unknown"}RenderOverlay=A.observer(()=>d.jsx("div",{...K(this),children:d.jsx("div",{className:"bpmn__unknown__marker",children:"?"})}))};o(ca,"UnknownBPMNNode");let vn=ca;const fr="bpmn--event-drop-inside",mr="bpmn--event-drop-attach";function Ic(n){return n.canAttach}o(Ic,"canAttach");function Dc(n){return n.type===N.subprocess||n.type===N.eventSubprocess}o(Dc,"canContainEvent");function yr(n,t){const e=n.middle,s=t.x,i=t.x+t.width,a=t.y,r=t.y+t.height,c=new y([Math.min(i,Math.max(s,e.x)),Math.min(r,Math.max(a,e.y))]);if(t.collides(e)){const u=[{distance:Math.abs(e.x-s),x:s,y:e.y},{distance:Math.abs(i-e.x),x:i,y:e.y},{distance:Math.abs(e.y-a),x:e.x,y:a},{distance:Math.abs(r-e.y),x:e.x,y:r}].reduce((f,p)=>p.distance<f.distance?p:f);c.assign([u.x,u.y])}else c.x>s&&c.x<i?c.y=e.y<a?a:r:c.y>a&&c.y<r&&(c.x=e.x<s?s:i);return new S([c.x-n.width/2,c.y-n.height/2,n.width,n.height])}o(yr,"projectToTaskBoundary");function jc(n,t){const e=t.x+t.width-n.width,s=t.y+t.height-n.height,i=e<t.x?t.x+(t.width-n.width)/2:Math.min(e,Math.max(t.x,n.x)),a=s<t.y?t.y+(t.height-n.height)/2:Math.min(s,Math.max(t.y,n.y));return new S([i,a,n.width,n.height])}o(jc,"clampInsideContainer");const la=class la extends z{draggedEventIds=new Set;init(){this.diagram.onEvent(ht,t=>this.handleDrag(t),this.diagram.priorities.Drag_Node_Snap_To_Grid-1),this.diagram.onEvent(tt,()=>{this.finishEventDrags(),this.clearDropPresentations()},this.diagram.priorities.Mouse_Up_Selector-1),this.diagram.onEvent(ie,t=>{t.cancelled||!(t.node instanceof j)||[...this.attachedEvents(t.node.id),...this.subprocessEvents(t.node.id)].forEach(e=>this.diagram.delete(e))},-100)}attachedEvents(t){return this.diagram.nodes.filter(e=>e instanceof D&&e.attachedToTaskId===t)}subprocessEvents(t){return this.diagram.nodes.filter(e=>e instanceof D&&e.subprocessId===t)}handleDrag(t){this.clearDropPresentations();const e=[...t.proposals],s=new Map(e.map(i=>[i.node.id,i]));e.forEach(i=>{i.node instanceof D&&(this.draggedEventIds.add(i.node.id),this.constrainSubprocessEvent(i.node,i,s)||this.constrainAttachedEvent(i.node,i),this.presentDropTarget(i.node,i.get()))}),e.forEach(i=>{i.node instanceof j&&this.moveAttachedEvents(i.node,i.get(),s,t.proposals)})}clearDropPresentations(){this.diagram.nodes.forEach(t=>{t instanceof j&&(t.classList.delete(fr),t.classList.delete(mr))})}presentDropTarget(t,e){const s=this.findInternalDropTarget(e);if(s){s.classList.add(fr);return}t.canAttach&&this.findAttachmentDropTarget(e)?.classList.add(mr)}findInternalDropTarget(t){return this.diagram.nodes.filter(e=>e instanceof j&&Dc(e)&&e.box.x<=t.x&&e.box.y<=t.y&&e.box.x+e.box.width>=t.x+t.width&&e.box.y+e.box.height>=t.y+t.height).sort((e,s)=>e.box.width*e.box.height-s.box.width*s.box.height)[0]??null}findAttachmentDropTarget(t){return this.diagram.nodes.filter(e=>e instanceof j&&e.box.collides(t,!0)).sort((e,s)=>e.box.middle.distance(t.middle)-s.box.middle.distance(t.middle))[0]??null}constrainAttachedEvent(t,e){if(!t.attachedToTaskId)return;const s=this.diagram.getNodeById(t.attachedToTaskId);if(!(s instanceof j)){t.setAttachment(null);return}const i=e.get();if(this.findInternalDropTarget(i)||!s.box.collides(i,!0)){t.setAttachment(null);return}e.update(yr(i,s.box))}constrainSubprocessEvent(t,e,s){if(!t.subprocessStart||!t.subprocessId)return!1;const i=this.diagram.getNodeById(t.subprocessId);if(!(i instanceof j)||i.type!==N.eventSubprocess)return t.setSubprocessStart(!1),!1;const a=s.get(i.id)?.get()??i.box;return e.update(jc(e.get(),a)),!0}moveAttachedEvents(t,e,s,i){this.attachedEvents(t.id).forEach(a=>{const r=a.attachmentOffset??a.coordinates.copy(!1).substract(t.coordinates).raw,c=new S([e.x+r[0],e.y+r[1],a.box.width,a.box.height]),l=s.get(a.id);if(l)l.update(c);else{const h=new Ae(a,c);s.set(a.id,h),i.push(h)}})}finishEventDrags(){const t=[...this.draggedEventIds];this.draggedEventIds.clear(),t.forEach(e=>{const s=this.diagram.getNodeById(e);if(!(s instanceof D)||!Ic(s))return;const i=s.attachedToTaskId?this.diagram.getNodeById(s.attachedToTaskId):null,a=i instanceof j?i:this.findDropTask(s);if(!a)return;const r=yr(s.box,a.box);g.runInAction(()=>{s.setPosition(r.coordinates),s.setAttachment(a.id,s.coordinates.copy(!1).substract(a.coordinates).raw,s.interrupting)})})}findDropTask(t){return this.findInternalDropTarget(t.box)?null:this.findAttachmentDropTarget(t.box)}};o(la,"BPMNEventAttachments");let En=la;function xr(n){return n.children.length?n.children.reduce((t,e)=>t+xr(e),0):1}o(xr,"leafCount$1");const da=class da extends z{init(){this.diagram.onEvent(ht,e=>this.snapOneGridNodes(e),this.diagram.priorities.Drag_Node_Snap_To_Grid+1);const t=this.diagram.getExtension(Zt);t?.registerVerticalSuggestionProvider((e,s)=>this.enabled&&t.enabled?this.getLaneSuggestions(e,s):[]),t?.registerHorizontalSuggestionProvider((e,s)=>this.enabled&&t.enabled?this.getHorizontalLaneSuggestions(e,s):[])}snapOneGridNodes(t){const e=this.diagram.getExtension(G);if(!this.enabled||e?.enabled!==!0)return;const s=this.diagram.getClass("EventNode"),i=this.diagram.getClass("GateNode"),a=this.diagram.getClass("DocumentNode");for(const r of t.proposals){if(!(s&&r.node instanceof s)&&!(i&&r.node instanceof i)&&!(a&&r.node instanceof a))continue;const c=r.get().copy();c.x=Math.round(c.x/e.gridSize)*e.gridSize,c.y=Math.round(c.middle.y/e.gridSize)*e.gridSize-c.height/2,r.update(c),r.lockX(),r.lockY()}}resize(t,e){const s=this.diagram.getExtension(G),i=s?.gridSize??50,a=t.constructor;if("width"in e){const x=i*a.minimumWidthInGrids,b=t.box,w=this.constrain(e.width,x,null),v=new S([b.x,b.y,w,b.height],!1),_=v.copy();s?.enabled===!0&&(_.width=this.snapGrowingEdge(v.rightMiddle.x,b.x+x,i)-b.x);const E=this.diagram.getExtension(Bt)?.suggest(t,v,"e",_,new y([x,b.height],!1)).width??_.width;return t.state.box.width===E?!1:(t.state.box.width=E,!0)}const r=t.laneLayouts.find(({lane:x})=>x.name===e.laneId);if(!r)return!1;const c=xr(r.lane)*a.minimumLaneHeight,l=t.box,h=l.y+r.y,u=Math.max(c,e.height),f=new S([l.x,h,l.width,u],!1),p=f.copy();s?.enabled===!0&&(p.height=this.snapGrowingEdge(f.bottomMiddle.y,h+c,i)-h);const m=this.diagram.getExtension(Bt)?.suggest(t,f,"s",p,new y([l.width,c],!1)).height??p.height;return t.resizeLane(e.laneId,m)}snapGrowingEdge(t,e,s){const i=Math.ceil(e/s)*s,a=Math.round(t/s)*s;return Math.max(i,a)}constrain(t,e,s){const i=s?Math.ceil(e/s)*s:e,a=s?Math.round(t/s)*s:t;return Math.max(i,a)}getLaneSuggestions(t,e){const s=this.diagram.getClass("Lanes");if(!s||t instanceof s)return[];const i=this.diagram.nodes.filter(p=>p instanceof s).flatMap(p=>{const m=p.box;return p.laneLayouts.filter(({lane:x})=>x.children.length===0).map(x=>({lanes:p,laneBox:m,layout:x}))}).filter(({laneBox:p,layout:m})=>{const x=p.x+(m.depth+1)*s.laneHeaderWidth,b=p.y+m.y;return e.middle.x>=x&&e.middle.x<=p.x+p.width&&e.middle.y>=b&&e.middle.y<=b+m.height}).sort((p,m)=>m.layout.depth-p.layout.depth)[0];if(!i)return[];const a=this.diagram.getExtension(G)?.gridSize??50,{laneBox:r,layout:c}=i,l=r.y+c.y,u=[r.x+(c.depth+1)*s.laneHeaderWidth,r.x+r.width],f=[{nodeY:l+(c.height-e.height)/2,guideY:l+c.height/2,range:u}];if(c.height>a*3){const p=a/2;f.push({nodeY:l+p,guideY:l+p,range:u},{nodeY:l+c.height-p-e.height,guideY:l+c.height-p,range:u})}return f}getHorizontalLaneSuggestions(t,e){const s=this.diagram.getClass("Lanes");if(!s||t instanceof s)return[];const i=this.diagram.nodes.filter(m=>m instanceof s).flatMap(m=>{const x=m.box;return m.laneLayouts.filter(({lane:b})=>b.children.length===0).map(b=>({laneBox:x,layout:b}))}).filter(({laneBox:m,layout:x})=>{const b=m.x+(x.depth+1)*s.laneHeaderWidth,w=m.y+x.y;return e.middle.x>=b&&e.middle.x<=m.x+m.width&&e.middle.y>=w&&e.middle.y<=w+x.height}).sort((m,x)=>x.layout.depth-m.layout.depth)[0];if(!i)return[];const r=(this.diagram.getExtension(G)?.gridSize??50)/2,{laneBox:c,layout:l}=i,h=c.y+l.y,u=c.x+(l.depth+1)*s.laneHeaderWidth,f=c.x+c.width,p=[h,h+l.height];return[{nodeX:u+r,guideX:u+r,range:p},{nodeX:f-r-e.width,guideX:f-r,range:p}]}};o(da,"BPMNGridSnap");let Ve=da;const ha=class ha extends et{};o(ha,"BPMNLaneChangeEvent");let Gt=ha;const ua=class ua extends z{autopan=new ut(this.diagram);session=null;unbindSession=o(()=>{},"unbindSession");init(){}resizeWidth(t,e){e.stopImmediatePropagation();const s=this.diagram.canvas.inverseFit(new y(e)),i=t.state.box.width;this.startSession(e,a=>{const r=this.diagram.canvas.inverseFit(a);return this.diagram.getExtension(Ve).resize(t,{width:i+r.x-s.x})})}resizeHeight(t,e,s,i){i.stopImmediatePropagation();const a=this.diagram.canvas.inverseFit(new y(i));this.startSession(i,r=>{const c=this.diagram.canvas.inverseFit(r);return this.diagram.getExtension(Ve).resize(t,{laneId:e,height:s+c.y-a.y})})}startSession(t,e){this.endSession(),this.session={changed:!1,pointer:new y(t),resize:e},this.unbindSession=pt(R(this,"mousemove",this.handleMouseMove),R(this,"mouseup",this.endSession),vs(this.handleAutopan,30))}handleMouseMove(t){this.session&&(this.session.pointer=new y(t),this.session.changed=this.session.resize(this.session.pointer)||this.session.changed)}handleAutopan=o(()=>{this.session&&(this.autopan.displace(this.session.pointer),this.session.changed=this.session.resize(this.session.pointer)||this.session.changed)},"handleAutopan");endSession(){const t=this.session;this.session=null;const e=this.unbindSession;this.unbindSession=()=>{},e(),this.diagram?.getExtension?.(Bt)?.clear(),t?.changed&&this.emit(new Gt(this))}};o(ua,"BPMNLaneResizer");let he=ua;const ga=class ga extends st{minimumResizeSize=new y([300,100],!1);edgesAsGateways=!0;constructor(t,e){super(t,{...e,box:e.box||new S([0,0,500,150]),groupChildren:!1}),this.classList.add("bpmn__black_box_pool","bpmn__resizable_node")}RenderScreen=Nc;RenderOverlay=A.observer(()=>{const t=this.box,e=K(this),s=1.5;return d.jsx("div",{...e,style:{...e.style,overflow:"visible",border:0,borderRadius:0,background:"transparent"},children:d.jsx("svg",{"aria-hidden":"true",preserveAspectRatio:"none",style:{display:"block",width:"100%",height:"100%"},viewBox:`0 0 ${t.width} ${t.height}`,children:d.jsx("rect",{fill:"var(--node-fill)",height:Math.max(0,t.height-s*2),stroke:"var(--node-stroke)",strokeWidth:"2",vectorEffect:"non-scaling-stroke",width:Math.max(0,t.width-s*2),x:s,y:s})})})})};o(ga,"BlackBoxPoolNode");let Mt=ga;const Nc=A.observer(({node:n})=>{const t=n.diagram?.bpmnLabels??ft,e=M.useRef(!1),s=n.box,i=Math.min(20,s.width/4,s.height/4),a=n.state.labelFontSize??16,r=Math.min(Math.max(0,s.height-i*2),a*1.18),c=new S([s.x+i,s.y+(s.height-r)/2,Math.max(0,s.width-i*2),r]),l=jt(n,c);l.style["--screen-label-font-size"]=`${a}px`;const h=`node__screenLabel node__screenHitArea bpmn__black_box_pool_label${n.selected?" selected":""}`,u={...l.style,display:"block",margin:0,padding:0,border:0,background:"transparent",boxSizing:"border-box",color:"var(--node-color)",fontFamily:"var(--node-font-family)",fontSize:`calc(${a}px * var(--diagram-canvas-scale, 1))`,fontWeight:n.selected?600:500,fontKerning:"normal",fontVariantLigatures:"contextual",lineHeight:1.18,letterSpacing:0,overflow:"hidden",pointerEvents:"all",textAlign:"center",whiteSpace:"pre"};return n.editionMode||(e.current=!1),d.jsxs(d.Fragment,{children:[!n.editionMode&&n.state.label&&d.jsx("pre",{...l,className:h,style:u,children:n.state.label}),n.editionMode&&d.jsx("textarea",{...l,"aria-label":t.inputs.blackBoxPoolName,autoFocus:!0,className:h,onChange:o(f=>{g.runInAction(()=>{n.state.label=f.target.value})},"onChange"),onKeyDownCapture:o(f=>{Ss(f.nativeEvent)||f.nativeEvent.stopImmediatePropagation()},"onKeyDownCapture"),onMouseDown:o(f=>f.nativeEvent.stopImmediatePropagation(),"onMouseDown"),ref:o(f=>{f&&!e.current&&(e.current=!0,f.select())},"ref"),rows:1,style:{...u,outline:0,resize:"none"},value:n.state.label,wrap:"off"}),d.jsx(Ns,{node:n})]})}),pa=class pa extends st{requiredEdgePathType="straight";occupiesGridSquare=!0;constructor(t,e){super(t,e),this.fitToGridSquare(),this.classList.add("bpmn__data_store")}get screenLabelBox(){const t=this.box,e=Math.max(t.width,120),s=Math.max(this.state.labelFontSize??14,14);return new S([t.x+t.width/2-e/2,t.y+t.height+5,e,s*1.18*3]).sum(this.labelOffset)}RenderOverlay=A.observer(()=>d.jsx("div",{...K(this),children:d.jsxs("svg",{className:"bpmn__data_store_icon",viewBox:"0 0 24 24","aria-hidden":"true",children:[d.jsx("path",{className:"bpmn__data_store_body",d:"M4 6c0-2.21 3.58-4 8-4s8 1.79 8 4v12c0 2.21-3.58 4-8 4s-8-1.79-8-4Z"}),d.jsx("path",{className:"bpmn__data_store_lines",d:"M4 6c0 2.21 3.58 4 8 4s8-1.79 8-4M4 12c0 2.21 3.58 4 8 4s8-1.79 8-4"})]})}))};o(pa,"DataStoreNode");let Lt=pa;const fa=class fa extends st{minimumResizeSize=new y([100,80],!1);edgesAsGateways=!0;constructor(t,e){super(t,{...e,box:e.box||new S([0,0,180,120])}),this.classList.add("bpmn__document_annotation","bpmn__resizable_node")}findAutomaticGatewayAnchor(t){return this.findAutomaticConnectionAnchor(t)}RenderScreen=Tc;RenderOverlay=A.observer(()=>{const t=this.box,e=K(this),s=1.5,i=Math.min(24,t.width/4,t.height/3),a=Math.max(s,t.width-s),r=Math.max(s,t.height-s),c=Math.max(s,a-i),l=Math.min(r,s+i);return d.jsx("div",{...e,style:{...e.style,overflow:"visible",border:0,borderRadius:0,background:"transparent"},children:d.jsxs("svg",{"aria-hidden":"true",preserveAspectRatio:"none",style:{display:"block",width:"100%",height:"100%"},viewBox:`0 0 ${t.width} ${t.height}`,children:[d.jsx("path",{d:`M ${s} ${s} H ${c} L ${a} ${l} V ${r} H ${s} Z`,fill:"var(--node-fill)",stroke:"var(--node-stroke)",strokeLinejoin:"round",strokeWidth:"2",vectorEffect:"non-scaling-stroke"}),d.jsx("path",{d:`M ${c} ${s} V ${l} H ${a}`,fill:"none",stroke:"var(--node-stroke)",strokeLinejoin:"round",strokeWidth:"2",vectorEffect:"non-scaling-stroke"})]})})})};o(fa,"DocumentAnnotationNode");let mt=fa;const Tc=A.observer(({node:n})=>{const t=n.diagram?.bpmnLabels??ft,e=M.useRef(!1),s=n.box,i=Math.min(14,s.width/6,s.height/6),a=Math.min(24,s.width/4,s.height/3),r=Math.max(i,a+8),c=new S([s.x+i,s.y+i,Math.max(0,s.width-i-r),Math.max(0,s.height-i*2)]),l=jt(n,c);l.style["--screen-label-font-size"]=`${n.state.labelFontSize??16}px`;const h=`node__screenLabel node__screenHitArea bpmn__document_annotation_label${n.selected?" selected":""}`;return n.editionMode||(e.current=!1),n.editionMode?d.jsxs(d.Fragment,{children:[d.jsx("textarea",{...l,"aria-label":t.inputs.documentAnnotationText,autoFocus:!0,className:`${h} editable__label`,onChange:o(u=>{g.runInAction(()=>{n.state.label=u.target.value})},"onChange"),onKeyDownCapture:o(u=>{Ss(u.nativeEvent)||u.nativeEvent.stopImmediatePropagation()},"onKeyDownCapture"),onMouseDown:o(u=>u.nativeEvent.stopImmediatePropagation(),"onMouseDown"),ref:o(u=>{u&&!e.current&&(e.current=!0,u.select())},"ref"),style:{...l.style,display:"block",padding:0,border:0,background:"transparent",boxSizing:"border-box",overflow:"auto",outline:0,pointerEvents:"all",resize:"none",textAlign:"left"},value:n.state.label}),d.jsx(Ns,{node:n})]}):d.jsxs(d.Fragment,{children:[n.state.label&&d.jsx("pre",{...l,className:h,style:{...l.style,alignItems:"flex-start",justifyContent:"flex-start",overflow:"hidden",padding:0,pointerEvents:"all",textAlign:"left",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:n.state.label}),d.jsx(Ns,{node:n})]})}),ma=class ma extends st{requiredEdgePathType="straight";constructor(t,e){super(t,e),this.classList.add("bpmn__document")}get screenLabelBox(){const t=this.box,e=Math.max(t.width,120),s=Math.max(this.state.labelFontSize??16,16);return new S([t.x+t.width/2-e/2,t.y+t.height+5,e,s*1.18*3]).sum(this.labelOffset)}RenderOverlay=A.observer(()=>d.jsx("div",{...K(this),children:d.jsxs("svg",{className:"bpmn__document_icon",viewBox:"0 0 24 24","aria-hidden":"true",children:[d.jsx("path",{className:"bpmn__document_body",d:"M5 2.5h9l5 5v14H5Z"}),d.jsx("path",{className:"bpmn__document_fold",d:"M14 2.5v5h5"})]})}))};o(ma,"DocumentNode");let $t=ma;function Lc(n){n.preventDefault(),n.stopPropagation(),n.nativeEvent.stopImmediatePropagation()}o(Lc,"stopToolEvent$1");const $c=A.observer(({node:n})=>{const t=n.diagram?.bpmnLabels??ft,e=n.box,s=M.useRef(null),i=n.laneLayouts;return d.jsxs(d.Fragment,{children:[i.map(({lane:a,depth:r,y:c,height:l,siblingCount:h})=>{const u=new S([e.x+r*yt.laneHeaderWidth,e.y+c,yt.laneHeaderWidth,l]),f=jt(n,u),p=n.editingLaneId===a.name,m=r===0?h>1:h>2;return M.createElement("div",{...f,key:a.name,className:`node__screenHitArea lane__screenHeader${p?" lane__screenHeader--editing":""}${n.selected?" selected":""}`,onDoubleClick:o(()=>n.renameLane(a.name),"onDoubleClick")},!p&&d.jsx("span",{className:"lane__screenLabel",style:{fontSize:`calc(${yt.laneHeaderFontSize}px * var(--diagram-canvas-scale, 1))`},children:a.label}),p&&d.jsx("input",{"aria-label":t.inputs.laneName,className:"lane__screenLabelInput",autoFocus:!0,value:a.label,onMouseDown:o(x=>x.nativeEvent.stopImmediatePropagation(),"onMouseDown"),onKeyDownCapture:o(x=>{n.editionMode&&!Ss(x.nativeEvent)&&x.nativeEvent.stopImmediatePropagation()},"onKeyDownCapture"),onKeyDown:o(x=>{if(x.code!=="Tab")return;x.preventDefault();const b=i.findIndex(({lane:_})=>_.name===a.name),w=x.shiftKey?-1:1,v=i[(b+w+i.length)%i.length];n.renameLane(v.lane.name)},"onKeyDown"),onChange:o(x=>{g.runInAction(()=>{a.label=x.target.value})},"onChange"),ref:o(x=>{x&&s.current!==a.name&&(s.current=a.name,x.select())},"ref")}),d.jsxs("div",{className:"lane__headerTools",onMouseDown:Lc,children:[d.jsx("button",{title:t.lanes.rename,"aria-label":t.lanes.rename,onClick:o(()=>n.renameLane(a.name),"onClick"),children:d.jsx(Go,{})}),d.jsx("button",{title:t.lanes.insertBefore,"aria-label":t.lanes.insertBefore,onClick:o(()=>n.insertLane(a.name,"before"),"onClick"),children:d.jsx(Ho,{})}),d.jsx("button",{title:a.children.length?t.lanes.removeSubdivision:t.lanes.subdivide,"aria-label":a.children.length?t.lanes.removeSubdivision:t.lanes.subdivide,onClick:o(()=>a.children.length?n.removeSubdivision(a.name):n.subdivideLane(a.name),"onClick"),children:a.children.length?d.jsx(Vo,{}):d.jsx(Wo,{})}),m&&d.jsx("button",{title:t.lanes.removeLane,"aria-label":t.lanes.removeLane,onClick:o(()=>n.removeLane(a.name),"onClick"),children:d.jsx(rr,{})}),d.jsx("button",{title:t.lanes.insertAfter,"aria-label":t.lanes.insertAfter,onClick:o(()=>n.insertLane(a.name,"after"),"onClick"),children:d.jsx(Bo,{})})]}))}),d.jsxs(d.Fragment,{children:[d.jsx("div",{...jt(n,new S([e.x+e.width-4,e.y,8,e.height])),className:"lane__screenWidthResizeBar",onMouseDown:o(a=>n.diagram.getExtension(he).resizeWidth(n,a.nativeEvent),"onMouseDown")}),d.jsx("div",{...jt(n,new S([e.x+e.width-5,e.y+e.height/2-5,10,10])),className:"lane__screenWidthResize",onMouseDown:o(a=>n.diagram.getExtension(he).resizeWidth(n,a.nativeEvent),"onMouseDown")}),i.map(({lane:a,y:r,height:c})=>M.createElement("div",{...jt(n,new S([e.x,e.y+r+c-3,e.width,6])),key:`resize-${a.name}`,className:"lane__screenHeightResize",onMouseDown:o(l=>n.diagram.getExtension(he).resizeHeight(n,a.name,c,l.nativeEvent),"onMouseDown")}))]})]})});function Jt(n){return n.children.length?n.children.reduce((t,e)=>t+Jt(e),0):n.height}o(Jt,"laneHeight");function _n(n){return n.children.length?n.children.reduce((t,e)=>t+_n(e),0):1}o(_n,"leafCount");function br(n,t=0,e=0){const s=[];let i=e;return n.forEach(a=>{const r=Jt(a);s.push({lane:a,depth:t,y:i,height:r,siblingCount:n.length}),a.children.length&&s.push(...br(a.children,t+1,i)),i+=r}),s}o(br,"flattenLanes");function Qt(n,t,e=null){for(let s=0;s<n.length;s++){const i=n[s];if(i.name===t)return{lane:i,siblings:n,index:s,parent:e};const a=Qt(i.children,t,i);if(a)return a}return null}o(Qt,"findLane");function wr(n){const t=n.children.map(wr);if(t.length!==1)return{...n,children:t};const[e]=t;return{...n,height:Jt(e),children:e.children}}o(wr,"normalizeLane");function zc(n){return n.map(wr)}o(zc,"normalizeLanes");function vr(n,t){if(!n.children.length){const i=Math.max(yt.minimumLaneHeight,t);return n.height===i?!1:(n.height=i,!0)}let e=!1,s=t-Jt(n);for(let i=n.children.length-1;i>=0;i--){const a=n.children[i],r=Jt(a),c=_n(a)*yt.minimumLaneHeight,l=Math.max(c-r,s);if(e=vr(a,r+l)||e,s-=l,s>=0)break}return e}o(vr,"resizeLaneLeaves");const J=class J extends st{edgesAsGateways=!1;pools;constructor(t,e){super(t,{...e,label:"",zIndex:50,groupChildren:!0}),this.pools=[{label:this.labels.lanes.defaultLane,name:"default",height:J.laneHeight,children:[]}],g.makeObservable(this,{pools:g.observable,laneLayouts:g.computed,addPool:g.action,insertLane:g.action,subdivideLane:g.action,removeSubdivision:g.action,removeLane:g.action,resizeLane:g.action,renameLane:g.action,editionLaneId:g.observable}),this.classList.add("bpm__lanes"),this.state.box.width=J.minimumWidthInGrids*50,this._gateways.clear()}setDiagram(t){const e=this.pools.length===1&&this.pools[0].name==="default"&&this.pools[0].label===ft.lanes.defaultLane;super.setDiagram(t),e&&(this.pools[0].label=this.labels.lanes.defaultLane),this.state.box.width=Math.max(this.state.box.width,t.getExtension(G).gridSize*J.minimumWidthInGrids)}get box(){const t=this.pools.reduce((e,s)=>e+Jt(s),0);return new S([this.state.box.x,this.state.box.y,this.state.box.width,t])}get laneLayouts(){return br(this.pools)}get editingLaneId(){return this.editionLaneId}get labels(){return this.diagram?.bpmnLabels??ft}nextPool(t=[]){const e=new Set([...this.laneLayouts.map(({lane:i})=>i.name),...t]);let s=0;for(;e.has(`pool${s}`);)s++;return{label:`${this.labels.lanes.pool} ${s}`,name:`pool${s}`,height:J.laneHeight,children:[]}}addPool(){if(this.emit(new Gt(this)).cancelled)return this.pools.at(-1);const t=this.nextPool();return this.pools.push(t),t}insertLane(t,e){const s=Qt(this.pools,t);!s||this.emit(new Gt(this)).cancelled||s.siblings.splice(s.index+(e==="after"?1:0),0,this.nextPool())}subdivideLane(t){const e=Qt(this.pools,t);if(!e||e.lane.children.length||this.emit(new Gt(this)).cancelled)return;const s=this.nextPool(),i=this.nextPool([s.name]),a=Math.max(e.lane.height,J.minimumLaneHeight*2);s.height=a/2,i.height=a/2,e.lane.children=[s,i]}removeSubdivision(t){const e=Qt(this.pools,t);!e||!e.lane.children.length||this.emit(new Gt(this)).cancelled||(e.lane.height=Jt(e.lane),e.lane.children=[])}removeLane(t){const e=Qt(this.pools,t);!e||e.siblings.length<=1||e.parent&&e.siblings.length<=2||this.emit(new Gt(this)).cancelled||e.siblings.splice(e.index,1)}resizeLane(t,e,s){const i=Qt(this.pools,t);if(!i)return!1;const a=_n(i.lane)*J.minimumLaneHeight,r=s?Math.ceil(a/s)*s:a;return vr(i.lane,Math.max(e,r))}renameLane(t){if(Qt(this.pools,t)){if(!this.editionMode){const e=this.diagram?.getExtension(Ms);e?e.editNode(this):this.edit()}this.editionLaneId=t}}editionLaneId=null;previousPools=[];cancel(){this.editionLaneId=null,this.pools=this.previousPools,this.previousPools=[],super.cancel()}confirm(){return super.confirm()?(this.editionLaneId=null,this.previousPools=[],!0):!1}edit(){super.edit(),this.previousPools=Be(this.pools)}resetPools(){this.pools=[]}deserialize(t){super.deserialize(t),this.pools=zc(t.pools)}serialize(){return{...super.serialize(),pools:Be(this.pools)}}RenderScreen=$c;RenderOverlay=A.observer(()=>{const t=this.laneLayouts,e=this.box;return d.jsx("div",{...K(this),children:d.jsxs("svg",{className:"lane__svg",viewBox:`0 0 ${e.width} ${e.height}`,preserveAspectRatio:"none",children:[d.jsx("rect",{className:"lane__background",width:e.width,height:e.height}),t.map(({lane:s,depth:i,y:a,height:r})=>{const c=i*J.laneHeaderWidth,l=c+J.laneHeaderWidth,h=a;return d.jsxs("g",{children:[d.jsx("rect",{className:"lane__head",x:c,y:h,width:J.laneHeaderWidth,height:r,onDoubleClick:o(()=>this.renameLane(s.name),"onDoubleClick")}),d.jsx("rect",{className:"lane__content",x:l,y:h,width:Math.max(0,e.width-l),height:r})]},s.name)})]})})})};o(J,"Lanes"),kt(J,"laneHeaderWidth",50),kt(J,"laneHeight",250),kt(J,"laneHeaderFontSize",16),kt(J,"minimumLaneHeight",150),kt(J,"minimumWidthInGrids",10);let yt=J;const ya=class ya extends st{edgesAsGateways=!0;requiredEdgePathType="straight";constructor(t,e){super(t,{...e,box:e.box||new S([0,0,180,90])}),this.classList.add("bpmn__text_annotation"),this._gateways.clear(),this._gateways.set("left",new Ht(this,{id:"left",orientation:"left",position:new y([0,.5]),maxIncomingConnections:1/0,maxOutgoingConnections:0,radius:0,strokeWidth:0,fill:"transparent",stroke:"transparent"}))}get box(){const t=this.state.box,s=(this.diagram?.getExtension(G)?.gridSize??50)*6,i=Math.max(this.state.labelFontSize??14,12),a=i*.58,r=(this.state.label||" ").split(`
|
|
2
|
-
`),c=Math.max(...r.map(p=>p.length),1),l=Math.min(s,Math.max(t.width,c*a+28)),h=Math.max(1,Math.floor((l-28)/a)),u=r.reduce((p,m)=>p+Math.max(1,Math.ceil(m.length/h)),0),f=Math.min(s,Math.max(t.height,u*i*1.35+24));return new S([t.x,t.y,l,f])}serialize(){return{...super.serialize(),box:this.box.raw}}findAutomaticGatewayAnchor(t){return this.findAutomaticConnectionAnchor(t)}RenderOverlay=A.observer(()=>d.jsx("div",{...K(this),children:d.jsx("span",{className:"bpmn__annotation_bracket"})}))};o(ya,"TextAnnotationNode");let xt=ya;const Ye=[{id:"task",family:"task",section:"activities",priority:1,enabled:!0,connectable:!0},{id:"serviceTask",family:"task",section:"activities",priority:1,enabled:!0,connectable:!0},{id:"sendTask",family:"task",section:"activities",priority:4,enabled:!0,connectable:!0},{id:"receiveTask",family:"task",section:"activities",priority:4,enabled:!0,connectable:!0},{id:"scriptTask",family:"task",section:"activities",priority:3,enabled:!0,connectable:!0},{id:"manualTask",family:"task",section:"activities",priority:3,enabled:!0,connectable:!0},{id:"businessRuleTask",family:"task",section:"activities",priority:3,enabled:!0,connectable:!0},{id:"callActivity",family:"task",section:"activities",priority:1,enabled:!0,connectable:!0},{id:"subprocess",family:"task",section:"activities",priority:3,enabled:!0,connectable:!0},{id:"eventSubprocess",family:"task",section:"activities",priority:3,enabled:!0,connectable:!0},{id:"start",family:"event",section:"events",priority:1,enabled:!0,connectable:!0},{id:"intermediate",family:"event",section:"events",priority:1,enabled:!1,connectable:!0},{id:"end",family:"event",section:"events",priority:1,enabled:!0,connectable:!0},{id:"timer",family:"event",section:"events",priority:1,enabled:!0,connectable:!0},{id:"messageCatch",family:"event",section:"events",priority:1,enabled:!0,connectable:!0},{id:"messageThrow",family:"event",section:"events",priority:1,enabled:!0,connectable:!0},{id:"signal",family:"event",section:"events",priority:3,enabled:!0,connectable:!0},{id:"compensation",family:"event",section:"events",priority:4,enabled:!0,connectable:!0},{id:"error",family:"event",section:"events",priority:2,enabled:!0,connectable:!0},{id:"conditional",family:"event",section:"events",priority:3,enabled:!0,connectable:!0},{id:"terminate",family:"event",section:"events",priority:2,enabled:!0,connectable:!0},{id:"exclusive",family:"gateway",section:"gateways",priority:1,enabled:!0,connectable:!0},{id:"inclusive",family:"gateway",section:"gateways",priority:1,enabled:!0,connectable:!0},{id:"parallel",family:"gateway",section:"gateways",priority:1,enabled:!0,connectable:!0},{id:"eventBased",family:"gateway",section:"gateways",priority:1,enabled:!0,connectable:!0},{id:"lanes",family:"lane",section:"support",priority:1,enabled:!0,connectable:!1},{id:"blackBoxPool",family:"lane",section:"support",priority:1,enabled:!0,connectable:!0},{id:"dataStore",family:"data",section:"support",priority:1,enabled:!0,connectable:!0},{id:"document",family:"data",section:"support",priority:1,enabled:!0,connectable:!0},{id:"documentAnnotation",family:"artifact",section:"support",priority:1,enabled:!0,connectable:!0},{id:"textAnnotation",family:"artifact",section:"support",priority:1,enabled:!0,connectable:!0}],Oc={start:{stage:"start",kind:"none",direction:"catch"},intermediate:{stage:"start",kind:"none",direction:"throw"},end:{stage:"end",kind:"none",direction:"throw"},timer:{stage:"intermediate",kind:"timer",direction:"catch"},messageCatch:{stage:"intermediate",kind:"message",direction:"catch"},messageThrow:{stage:"intermediate",kind:"message",direction:"throw"},signal:{stage:"intermediate",kind:"signal",direction:"catch"},compensation:{stage:"intermediate",kind:"compensation",direction:"catch"},error:{stage:"intermediate",kind:"error",direction:"catch"},conditional:{stage:"intermediate",kind:"conditional",direction:"catch"},terminate:{stage:"end",kind:"terminate",direction:"throw"}},Er={task:N.task,serviceTask:N.service,sendTask:N.send,receiveTask:N.receive,scriptTask:N.script,manualTask:N.manual,businessRuleTask:N.businessRule,callActivity:N.callActivity,subprocess:N.subprocess,eventSubprocess:N.eventSubprocess},Fc=new Map(Object.entries(Er).map(([n,t])=>[t,n]));function Hc(n,t){const e=Oc[t];if(!e)return null;if(t==="start"||t==="intermediate"||t==="end")return e;const s=Kt({...e,stage:n.stage})?n.stage:e.stage,i=Kt({...e,direction:n.direction})?n.direction:e.direction;return{...e,stage:s,direction:i}}o(Hc,"eventDefinitionForTarget");const xa=class xa{static enabled(){return Ye.filter(t=>t.enabled).sort((t,e)=>t.priority-e.priority)}static forNode(t){const e=this.idForNode(t);return Ye.find(s=>s.id===e)}static idForNode(t){if(t instanceof j)return Fc.get(t.type)??"task";if(t instanceof D)return t.kind==="none"?t.stage:t.kind==="message"?t.isCatching?"messageCatch":"messageThrow":t.kind;if(t instanceof W)return t.type===H.inclusive?"inclusive":t.type===H.parallel?"parallel":t.type===H.eventBased?"eventBased":"exclusive";if(t instanceof yt)return"lanes";if(t instanceof Mt)return"blackBoxPool";if(t instanceof Lt)return"dataStore";if(t instanceof $t)return"document";if(t instanceof mt)return"documentAnnotation";if(t instanceof xt)return"textAnnotation"}static create(t,e,s){const i={id:e,label:s,movable:!0};switch(t){case"task":return new j(null,{...i,type:N.task});case"serviceTask":return new j(null,{...i,type:N.service});case"sendTask":return new j(null,{...i,type:N.send});case"receiveTask":return new j(null,{...i,type:N.receive});case"scriptTask":return new j(null,{...i,type:N.script});case"manualTask":return new j(null,{...i,type:N.manual});case"businessRuleTask":return new j(null,{...i,type:N.businessRule});case"callActivity":return new j(null,{...i,type:N.callActivity});case"subprocess":return new j(null,{...i,type:N.subprocess});case"eventSubprocess":return new j(null,{...i,type:N.eventSubprocess});case"start":return new D(null,{...i,type:T.start});case"intermediate":return new D(null,{...i,type:T.intermediate});case"end":return new D(null,{...i,type:T.end});case"timer":return new D(null,{...i,type:T.timer});case"messageCatch":return new D(null,{...i,type:T.messageCatch});case"messageThrow":return new D(null,{...i,type:T.messageThrow});case"signal":return new D(null,{...i,type:T.signalCatch});case"compensation":return new D(null,{...i,type:T.compensationCatch});case"error":return new D(null,{...i,type:T.errorCatch});case"conditional":return new D(null,{...i,type:T.conditional});case"terminate":return new D(null,{...i,type:T.terminate});case"inclusive":return new W(null,{...i,type:H.inclusive});case"parallel":return new W(null,{...i,type:H.parallel});case"eventBased":return new W(null,{...i,type:H.eventBased});case"lanes":return new yt(null,{id:e});case"blackBoxPool":return new Mt(null,i);case"dataStore":return new Lt(null,i);case"document":return new $t(null,i);case"documentAnnotation":return new mt(null,i);case"textAnnotation":return new xt(null,i);default:return new W(null,{...i,type:H.exclusive})}}static transform(t,e){const s=this.forNode(t),i=Ye.find(a=>a.id===e);if(!s||!i||s.family!==i.family||!i.enabled)return!1;if(t instanceof j){const a=Er[e];return a===void 0?!1:t.setType(a)}if(t instanceof D){const a=Hc(t,e);return!a||t.attachedToTaskId&&!["timer","message","signal","compensation","error","conditional"].includes(a.kind)?!1:t.setDefinition(a)}return t instanceof W?(t.setType(e==="inclusive"?H.inclusive:e==="parallel"?H.parallel:e==="eventBased"?H.eventBased:H.exclusive),!0):!1}};o(xa,"BPMNElementCatalog");let at=xa;const ts=class ts extends Xt{kind;condition;defaultFlow;directedFlow;get isDefault(){return this.defaultFlow}get isDirected(){return this.kind==="association"||this.directedFlow}get supportsDirection(){return this.kind==="messageFlow"}get supportsDefaultFlow(){const t=this.state.from?.parent;return this.kind==="sequenceFlow"&&!!this.state.to&&t instanceof W&&(t.type===H.exclusive||t.type===H.inclusive)}constructor(t,e){super(t,e),this.kind=e.kind??(e.to?ts.inferKind(e.from.parent,e.to.parent):null)??"sequenceFlow",this.condition=e.condition??"",this.defaultFlow=!1,this.directedFlow=e.isDirected??this.supportsDirection,g.makeObservable(this,{kind:g.observable,condition:g.observable,defaultFlow:g.observable,directedFlow:g.observable,isDefault:g.computed,isDirected:g.computed,supportsDirection:g.computed,supportsDefaultFlow:g.computed,setKind:g.action,setDefault:g.action,setDirected:g.action,reverseDirection:g.action}),this.setDefault(e.isDefault===!0)}static inferKind(t,e){return t instanceof xt||e instanceof xt||t instanceof mt||e instanceof mt?"association":(t instanceof Lt||t instanceof $t)&&e instanceof j?"inputDataAssociation":t instanceof j&&(e instanceof Lt||e instanceof $t)?"outputDataAssociation":t instanceof Mt&&(e instanceof Mt||e instanceof j||e instanceof D||e instanceof W)||e instanceof Mt&&(t instanceof j||t instanceof D||t instanceof W)||t instanceof D&&t.kind==="message"&&!t.isCatching&&(e instanceof j||e instanceof D||e instanceof W)?"messageFlow":(t instanceof j||t instanceof D||t instanceof W)&&(e instanceof j||e instanceof D||e instanceof W)?t instanceof D&&t.isEnd||e instanceof D&&(e.isStart||e.attachedToTaskId)||t instanceof W&&t.type===H.eventBased&&!(e instanceof D&&e.isCatching&&["message","timer","signal","conditional"].includes(e.kind)||e instanceof j&&e.type===N.receive)?null:"sequenceFlow":null}setKind(t){const e=this.supportsDirection;this.kind=t,!e&&this.supportsDirection&&(this.directedFlow=!0),this.supportsDefaultFlow||(this.defaultFlow=!1),this.applyStyle()}setDefault(t){const e=t&&this.supportsDefaultFlow;return e&&this.clearOtherDefaultFlows(),this.defaultFlow=e,this.applyStyle(),e===t}setDirected(t){return this.supportsDirection?(this.directedFlow=t,this.applyStyle(),!0):!1}applyResolvedAnchors(t,e){const s=this.defaultFlow;super.applyResolvedAnchors(t,e),s&&this.setDefault(!0)}reverseDirection(){const t=this.defaultFlow;this.defaultFlow=!1;const e=this.state.from,s=this.state.to;e.removeOutgoingEdge(this),s.removeIncomingEdge(this),this.state.from=s,this.state.to=e,this.state.steps.reverse(),[this.state.startAnchor,this.state.endAnchor]=[this.state.endAnchor,this.state.startAnchor],[this.state.displacementStart,this.state.displacementEnd]=[this.state.displacementEnd,this.state.displacementStart],s.addOutgoingEdge(this,!1),e.addIncomingEdge(this),this.kind==="inputDataAssociation"?this.kind="outputDataAssociation":this.kind==="outputDataAssociation"&&(this.kind="inputDataAssociation"),t?this.setDefault(!0):this.applyStyle()}clearOtherDefaultFlows(){const t=this.from.parent;t instanceof W&&t.gateways.forEach(e=>e.outgoingEdges.forEach(s=>{s instanceof ts&&s!==this&&s.isDefault&&s.setDefault(!1)}))}applyStyle(){this.state.arrowSize=10,this.state.arrowHeadStart="none",this.state.arrowHeadEnd="arrow",this.state.lineStyle="solid",this.kind==="messageFlow"?(this.state.arrowHeadStart="circle-small",this.state.arrowHeadEnd=this.isDirected?"triangle":"none",this.state.lineStyle="dashed"):this.kind==="inputDataAssociation"||this.kind==="outputDataAssociation"?(this.state.arrowHeadEnd="arrow-open",this.state.lineStyle="dashed"):this.kind==="association"&&(this.state.arrowHeadEnd="arrow-open",this.state.lineStyle="dashed"),this.defaultFlow&&this.supportsDefaultFlow&&(this.state.arrowHeadStart="default-flow")}serialize(){return{...super.serialize(),kind:this.kind,condition:this.condition,isDefault:this.isDefault,isDirected:this.isDirected}}deserialize(t){super.deserialize(t),this.kind=t.kind,this.condition=t.condition,this.defaultFlow=!1,this.directedFlow=t.isDirected??this.supportsDirection,this.setDefault(t.isDefault===!0)}};o(ts,"BPMNEdge");let zt=ts;function _r(n){return n.normalize("NFD").replace(new RegExp("\\p{Diacritic}","gu"),"").toLowerCase()}o(_r,"normalizeSearchValue");function Sr({items:n,labels:t,onSelect:e,selectedId:s}){const[i,a]=M.useState(""),r=_r(i.trim()),c=r?n.filter(l=>_r(t.elements[l.id]).includes(r)):n;return d.jsxs("div",{className:"bpmn__element_menu bpmn__element_menu--searchable",children:[d.jsx("input",{"aria-label":t.inputs.elementSearch,className:"bpmn__element_menu_search",onChange:o(l=>a(l.target.value),"onChange"),onMouseDown:o(l=>l.stopPropagation(),"onMouseDown"),placeholder:t.inputs.elementSearch,type:"search",value:i}),d.jsx("div",{className:"bpmn__element_menu_items",role:"menu",children:c.map(l=>d.jsxs("button",{className:"bpmn__element_menu_item","aria-current":l.id===s?"true":void 0,onClick:o(()=>e(l),"onClick"),role:"menuitem",type:"button",children:[d.jsx(Nt,{id:l.id}),d.jsx("span",{children:t.elements[l.id]})]},l.id))})]})}o(Sr,"BPMNElementMenu");const te=8;function Bc(n,t,e,s){const i=e.width-n.right,a=n.left,r=i<t.width+te&&a>i,c=r?n.left-t.width:n.right,l=c+t.width;let h=e.height-t.height-te;s&&l>s.left-te&&c<s.right+te&&(h=Math.min(h,s.top-t.height-te));const u=Math.min(Math.max(n.top-4,te),Math.max(te,h));return{left:r,top:u-n.top}}o(Bc,"resolveToolbarMenuPlacement");function Gc(n,t,e){const s=e.copy(!1).substract(t),i=s.x**2+s.y**2;if(i<.001)return t.copy(!1);const a=n.copy(!1).substract(t),r=Math.max(0,Math.min(1,(a.x*s.x+a.y*s.y)/i));return t.copy(!1).sum(s.multiply(r))}o(Gc,"closestPointOnSegment");function Rc(n,t,e){const s=t.middle;let i=n[0]?.copy(!1)??s,a=i.distance(s);for(let l=0;l<n.length-1;l+=1){const h=Gc(s,n[l],n[l+1]),u=h.distance(s);u<a&&(i=h,a=u)}const r=Math.min(e,t.width/2),c=Math.min(e,t.height/2);return i.x=Math.max(t.x+r,Math.min(t.x+t.width-r,i.x)),i.y=Math.max(t.y+c,Math.min(t.y+t.height-c,i.y)),i}o(Rc,"resolveVisibleEdgeToolbarAnchor");function Mr(n){n.preventDefault(),n.stopPropagation(),n.nativeEvent.stopImmediatePropagation()}o(Mr,"stopToolEvent");function Vc(n){if(!/(?:^| )(?:bpmn__event|bpmn__gate|bpmn__data_store|bpmn__document)(?: |$)/.test(n.classList.string))return!1;const t=n.box.middle,e=n.labelScreenBox.middle,s=e.x-t.x,i=e.y-t.y;return s>0&&Math.abs(s)>Math.abs(i)}o(Vc,"isRightExternalLabel");function Sn({children:n,icon:t,label:e,onDragStart:s}){const[i,a]=M.useState(!1),[r,c]=M.useState({left:!1,top:-4}),l=M.useRef(null),h=M.useRef(null),u=M.useRef(()=>{}),f=M.useRef(!1),p=M.useRef(null);M.useEffect(()=>()=>{l.current!==null&&window.clearTimeout(l.current),h.current!==null&&window.clearTimeout(h.current),u.current()},[]),M.useLayoutEffect(()=>{if(!i||!p.current)return;const E=p.current.querySelector(".bpmn__element_menu");if(!E)return;const C=p.current.getBoundingClientRect(),k=E.getBoundingClientRect(),P=document.querySelector(".toolbar")?.getBoundingClientRect();c(Bc(C,k,{width:window.innerWidth,height:window.innerHeight},P))},[i]);const m=o(()=>{l.current!==null&&window.clearTimeout(l.current),h.current!==null&&window.clearTimeout(h.current),l.current=null,h.current=null},"clearTimers"),x=o(()=>{m(),a(!0)},"show"),b=o(()=>{i||l.current!==null||(h.current!==null&&window.clearTimeout(h.current),h.current=null,l.current=window.setTimeout(()=>{l.current=null,a(!0)},250))},"showAfterDelay"),w=o(()=>{m(),h.current=window.setTimeout(()=>a(!1),180)},"hideSoon"),v=o(E=>{if(!s||E.button!==0)return;u.current();const C=E.clientX,k=E.clientY,P=E,I=o(()=>{document.removeEventListener("mousemove",B),document.removeEventListener("mouseup",I),u.current=()=>{}},"cleanup"),B=o(X=>{if((X.buttons&1)===0){I();return}Math.hypot(X.clientX-C,X.clientY-k)<5||(I(),f.current=!0,s(P))},"handleMouseMove");u.current=I,document.addEventListener("mousemove",B),document.addEventListener("mouseup",I)},"prepareDrag"),_=o(()=>{if(f.current){f.current=!1;return}x()},"handleClick");return d.jsxs("div",{className:`bpmn__toolbar_group${i?" bpmn__toolbar_group--open":""}${r.left?" bpmn__toolbar_group--menu-left":""}`,onBlurCapture:w,onFocusCapture:x,onMouseEnter:b,onMouseLeave:w,ref:p,style:{"--bpmn-menu-top":`${r.top}px`},children:[d.jsx("button",{"aria-expanded":i,"aria-label":e,onClick:_,onMouseDown:v,title:e,type:"button",children:t}),n]})}o(Sn,"ToolbarGroup");const kr=A.observer(({extension:n})=>{const t=n.labels;return d.jsx("div",{className:"bpmn__toolbar_group",children:d.jsx("button",{"aria-label":t.actions.settings,"aria-pressed":n.propertiesPanelOpen,className:`tool${n.propertiesPanelOpen?" selected":""}`,onClick:o(()=>n.togglePropertiesPanel(),"onClick"),title:t.actions.settings,type:"button",children:d.jsx(Nt,{id:"settings"})})})}),Yc=A.observer(({diagram:n,extension:t})=>{const e=t.labels,s=n.getExtension(Y),i=s.selectedNodes,a=s.selectedEdges;return t.dragging||t.connecting||i.length+a.length!==1?null:d.jsxs(d.Fragment,{children:[i.map(r=>{if(r instanceof yt)return null;const c=t.transformTargets(r),l=at.forNode(r),h=t.shapeOptions(r),u=t.connectionTargets(r),f=r instanceof St&&Vc(r),p=f?r.labelScreenBox:null,m=p?new S([p.x+p.width/2,p.y+p.height+8,1,1]):new S([r.box.x+r.box.width+10,r.box.y+r.box.height/2,1,1]);return M.createElement("div",{...jt(r,m),className:`bpmn__selection_toolbar${f?" bpmn__selection_toolbar--below-external-label":""}`,"data-diagram-interactive-ui":"true",key:r.id,onMouseDown:Mr},c.length>0&&d.jsx(Sn,{icon:d.jsx(Nt,{id:"transform"}),label:e.actions.transform,children:d.jsx(Sr,{items:h,labels:e,onSelect:o(x=>t.transform(r,x.id),"onSelect"),selectedId:l?.id})}),u.length>0&&d.jsx(Sn,{icon:d.jsx(Nt,{id:"connect"}),label:e.actions.connect,onDragStart:o(x=>t.startToolbarConnection(r,x),"onDragStart"),children:d.jsx(Sr,{items:u,labels:e,onSelect:o(x=>t.appendConnected(r,x.id),"onSelect")})}),d.jsx(kr,{extension:t}))}),a.map(r=>{if(!(r instanceof zt)||r.steps.length===0)return null;const c=n.canvas.inverseFit(n.canvas.frameDimensions),l=Rc(r.steps,c,48/Math.max(n.canvas.scale,.001)),h={"--screen-renderer-x":`${l.x}px`,"--screen-renderer-y":`${l.y}px`,"--screen-renderer-width":"1px","--screen-renderer-height":"1px","--screen-renderer-z-index":140};return d.jsxs("div",{className:"bpmn__selection_toolbar bpmn__selection_toolbar--edge","data-diagram-interactive-ui":"true",onMouseDown:Mr,style:h,children:[d.jsx(Sn,{icon:d.jsx(Nt,{id:"transform"}),label:e.actions.transform,children:d.jsx("div",{className:"bpmn__element_menu",role:"menu",children:t.edgeKindOptions(r).filter(u=>u!==r.kind).map(u=>d.jsxs("button",{className:"bpmn__element_menu_item",onClick:o(()=>t.changeEdgeKind(r,u),"onClick"),role:"menuitem",type:"button",children:[d.jsx(Nt,{id:"connect"}),d.jsx("span",{children:e.edges[u]})]},u))})}),d.jsx("div",{className:"bpmn__toolbar_group",children:d.jsx("button",{"aria-label":e.actions.reverseDirection,onClick:o(()=>t.reverseEdge(r),"onClick"),title:e.actions.reverseDirection,type:"button",children:d.jsx(Jo,{"aria-hidden":"true"})})}),d.jsx(kr,{extension:t})]},r.id)})]})}),Wc=["orthogonal","straight","curved"],Zc=["message","timer","error","signal","compensation","conditional"],Xc=A.observer(({diagram:n,extension:t})=>{const e=n.getExtension(Y),s=e.selectedNodes.length===1?e.selectedNodes[0]:null,i=e.selectedEdges.length===1?e.selectedEdges[0]:null,a=t.propertiesPanelOpen&&!!(s||i)&&!t.dragging,r=s?at.forNode(s):void 0,c=s?t.shapeOptions(s):[],l=t.labels;return d.jsxs("aside",{"aria-hidden":!a,className:`bpmn__properties_panel${a?" bpmn__properties_panel--open":""}`,children:[d.jsxs("header",{children:[d.jsxs("div",{children:[d.jsx("span",{children:l.properties.title}),d.jsx("strong",{children:r?l.elements[r.id]:i instanceof zt?l.edges[i.kind]:""})]}),d.jsx("button",{"aria-label":l.actions.close,onClick:o(()=>t.closePropertiesPanel(),"onClick"),title:l.actions.close,type:"button",children:"×"})]}),s&&r&&d.jsxs("div",{className:"bpmn__properties_fields",children:[d.jsxs("label",{children:[d.jsx("span",{children:l.properties.name}),d.jsx("textarea",{onChange:o(h=>t.renameNode(s,h.target.value),"onChange"),value:s.state.label})]}),!(s instanceof D)&&c.length>1&&d.jsxs("label",{children:[d.jsx("span",{children:l.properties.type}),d.jsx("select",{onChange:o(h=>t.transform(s,h.target.value),"onChange"),value:r.id,children:c.map(h=>h&&d.jsx("option",{value:h.id,children:l.elements[h.id]},h.id))})]}),s instanceof D&&d.jsxs(d.Fragment,{children:[d.jsxs("label",{children:[d.jsx("span",{children:l.properties.eventType}),d.jsx("select",{onChange:o(h=>t.changeEventKind(s,h.target.value),"onChange"),value:s.kind,children:t.eventKindOptions(s).map(h=>d.jsx("option",{value:h,children:l.elements[h==="none"?"event":h]},h))})]}),d.jsxs("label",{children:[d.jsx("span",{children:l.properties.eventStage}),d.jsx("select",{onChange:o(h=>t.changeEventStage(s,h.target.value),"onChange"),value:s.stage,children:t.eventStageOptions(s).map(h=>d.jsx("option",{value:h,children:l.eventOptions[h]},h))})]}),s.kind!=="none"&&d.jsxs("label",{children:[d.jsx("span",{children:l.properties.eventDirection}),d.jsx("select",{onChange:o(h=>t.changeEventDirection(s,h.target.value),"onChange"),value:s.direction,children:t.eventDirectionOptions(s).map(h=>d.jsx("option",{value:h,children:l.eventOptions[h]},h))})]}),s.attachedToTaskId&&d.jsxs("label",{className:"bpmn__properties_checkbox",children:[d.jsx("input",{checked:s.interrupting,onChange:o(h=>t.changeEventInterrupting(s,h.target.checked),"onChange"),type:"checkbox"}),d.jsx("span",{children:l.properties.interrupting})]})]}),s instanceof j&&d.jsxs(d.Fragment,{children:[s.type===N.eventSubprocess&&d.jsxs("label",{children:[d.jsx("span",{children:l.properties.eventSubprocessStartType}),d.jsxs("select",{onChange:o(h=>t.changeEventSubprocessStartKind(s,h.target.value),"onChange"),value:t.eventSubprocessStartKind(s),children:[d.jsx("option",{disabled:!0,value:"",children:l.eventOptions.none}),Zc.map(h=>d.jsx("option",{value:h,children:l.elements[h]},h))]})]}),d.jsxs("label",{className:"bpmn__properties_checkbox",children:[d.jsx("input",{checked:s.loop,onChange:o(h=>t.changeTaskLoop(s,h.target.checked),"onChange"),type:"checkbox"}),d.jsx("span",{children:l.properties.loop})]}),d.jsxs("label",{className:"bpmn__properties_checkbox",children:[d.jsx("input",{checked:s.multiInstance==="parallel",onChange:o(h=>t.changeTaskMultiInstance(s,h.target.checked?"parallel":"none"),"onChange"),type:"checkbox"}),d.jsx("span",{children:l.properties.multiInstance})]})]})]}),i instanceof zt&&d.jsxs("div",{className:"bpmn__properties_fields",children:[d.jsxs("label",{children:[d.jsx("span",{children:l.properties.name}),d.jsx("input",{onChange:o(h=>t.renameEdge(i,h.target.value),"onChange"),type:"text",value:i.labels[0]?.text??""})]}),d.jsxs("label",{children:[d.jsx("span",{children:l.properties.edgeType}),d.jsx("select",{onChange:o(h=>t.changeEdgeKind(i,h.target.value),"onChange"),value:i.kind,children:t.edgeKindOptions(i).map(h=>d.jsx("option",{value:h,children:l.edges[h]},h))})]}),d.jsxs("label",{children:[d.jsx("span",{children:l.properties.routingType}),d.jsx("select",{onChange:o(h=>t.changeEdgePathType(i,h.target.value),"onChange"),value:i.pathType,children:Wc.map(h=>d.jsx("option",{value:h,children:l.routing[h]},h))})]}),t.supportsCondition(i)&&d.jsxs("label",{children:[d.jsx("span",{children:l.properties.condition}),d.jsx("textarea",{onChange:o(h=>t.changeEdgeCondition(i,h.target.value),"onChange"),rows:4,value:i.condition})]}),t.supportsDefaultFlow(i)&&d.jsxs("label",{className:"bpmn__properties_checkbox",children:[d.jsx("input",{checked:i.isDefault,onChange:o(h=>t.changeEdgeDefault(i,h.target.checked),"onChange"),type:"checkbox"}),d.jsx("span",{children:l.properties.defaultFlow})]}),i.supportsDirection&&d.jsxs("label",{className:"bpmn__properties_checkbox",children:[d.jsx("input",{checked:i.isDirected,onChange:o(h=>t.changeEdgeDirected(i,h.target.checked),"onChange"),type:"checkbox"}),d.jsx("span",{children:l.properties.directed})]})]})]})});function qc(n,t,e){if(!(t instanceof xt||t instanceof mt)||!(t instanceof xt&&e==="documentAnnotation"||t instanceof mt&&e==="textAnnotation"))return null;const s=new Set(t.gateways.flatMap(a=>[...a.incomingEdges,...a.outgoingEdges])),i=at.create(e,t.id,t.state.label);return g.runInAction(()=>{i.state={...t.state,box:t.box,selected:!1},n.delete(t),n.add(i),s.forEach(a=>{const r=a.from.parent===t?i.findAutomaticGatewayAnchor(a.to.parent===t?i.box.middle:a.to.parent.box.middle):a.resolveEndpointAnchor("from"),c=a.to.parent===t?i.findAutomaticGatewayAnchor(a.from.parent===t?i.box.middle:a.from.parent.box.middle):a.resolveEndpointAnchor("to");a.applyResolvedAnchors(r,c),a.setEndpointAnchor("from",a.startAnchor.mode==="automatic"?{mode:"automatic"}:{mode:"fixed",position:r.relativePosition},!1),a.setEndpointAnchor("to",a.endAnchor.mode==="automatic"?{mode:"automatic"}:{mode:"fixed",position:c.relativePosition},!1),a.parent=n,n.connectWithEdge(a.from,a.to,a),a.from.recomputeConnectedEdge(a,"from")})}),i}o(qc,"transformBPMNArtifact");const We=new Set(["task","event","gateway"]),Uc=["sequenceFlow","messageFlow","inputDataAssociation","outputDataAssociation","association"],Ar=["start","intermediate","end"],Pr=["catch","throw"],Kc=["none","message","timer","error","signal","compensation","conditional","terminate"],Cr={none:{stage:"start",kind:"none",direction:"catch"},message:{stage:"intermediate",kind:"message",direction:"catch"},timer:{stage:"intermediate",kind:"timer",direction:"catch"},error:{stage:"intermediate",kind:"error",direction:"catch"},signal:{stage:"intermediate",kind:"signal",direction:"catch"},compensation:{stage:"intermediate",kind:"compensation",direction:"catch"},conditional:{stage:"intermediate",kind:"conditional",direction:"catch"},terminate:{stage:"end",kind:"terminate",direction:"throw"}},Ir=new Set(["message","timer","error","signal","compensation","conditional"]),Mn=new Set(["message","timer","error","signal","compensation","conditional"]),kn="bpmn-properties-panel-open",Jc=24,ba=class ba extends z{dragging=!1;propertiesPanelOpen=!1;RenderDiagram=Yc;RenderUI=Xc;labelConfiguration=bn();get labels(){return this.labelConfiguration??ft}configureLabels(t){this.labelConfiguration=bn(t,this.labels)}init(){g.makeObservable(this,{dragging:g.observable,labelConfiguration:g.observable.ref,propertiesPanelOpen:g.observable,configureLabels:g.action}),typeof window<"u"&&(this.propertiesPanelOpen=window.localStorage.getItem(kn)==="true"),this.diagram.registerClass(zt),this.diagram.setDefaultEdge(zt),this.diagram.onEvent(Se,t=>{zt.inferKind(t.origin,t.target)||t.cancel()}),this.diagram.onEvent(ht,()=>{g.runInAction(()=>{this.dragging=!0})}),this.diagram.onEvent(tt,()=>{g.runInAction(()=>{this.dragging=!1})})}transformTargets(t){const e=at.forNode(t);if(!e)return[];const s=t.gateways.some(a=>a.incomingEdges.length),i=t.gateways.some(a=>a.outgoingEdges.length);return at.enabled().filter(a=>!(a.family!==e.family||a.id===e.id||a.id==="start"&&s||(a.id==="end"||a.id==="terminate")&&i||t instanceof D&&t.attachedToTaskId&&!["timer","messageCatch","signal","compensation","error","conditional"].includes(a.id)))}shapeOptions(t){const e=at.forNode(t);if(!e)return[];const s=new Set([e.id,...this.transformTargets(t).map(i=>i.id)]);return at.enabled().filter(i=>s.has(i.id))}transform(t,e){if(!this.transformTargets(t).some(a=>a.id===e))return!1;this.emit(new Z(this));const s=qc(this.diagram,t,e);if(s)return t.selected&&this.diagram.getExtension(Y).selectNode(s),!0;const i=at.transform(t,e);return i&&t instanceof W&&t.gateways.forEach(a=>a.outgoingEdges.forEach(r=>{r instanceof zt&&!r.supportsDefaultFlow&&r.setDefault(!1)})),i}connectionTargets(t){const e=at.idForNode(t);return e?at.enabled().filter(s=>{if(!s.connectable)return!1;const i=this.inferDefinitionKind(e,s.id);return!(!i||t instanceof D&&t.isEnd&&i==="sequenceFlow")}):[]}inferDefinitionKind(t,e){const s=Ye.find(a=>a.id===t),i=Ye.find(a=>a.id===e);return!s||!i?null:s.family==="artifact"||i.family==="artifact"?"association":s.family==="data"&&i.family==="task"?"inputDataAssociation":s.family==="task"&&i.family==="data"?"outputDataAssociation":t==="blackBoxPool"&&(e==="blackBoxPool"||We.has(i.family))||e==="blackBoxPool"&&We.has(s.family)||t==="messageThrow"&&We.has(i.family)?"messageFlow":!We.has(s.family)||!We.has(i.family)||t==="end"||t==="terminate"||e==="start"||t==="eventBased"&&!["messageCatch","timer","signal","conditional","receiveTask"].includes(e)?null:"sequenceFlow"}appendConnected(t,e){if(!this.connectionTargets(t).some(f=>f.id===e))return null;const s=Pe(this.diagram,e),i=at.create(e,s,this.labels.elements[e]);this.diagram.add(i);const a=this.diagram.getExtension(G).gridSize,r=new y([t.box.x+t.box.width+a,t.box.y+t.box.height/2-i.box.height/2]),c=this.nearestAvailablePosition(i,r);if(!c)return this.diagram.delete(i),null;i.setPosition(c,{updateConnectedEdges:!1});const l=t.getGateway("right"),h=i.getGateway("left");if(!l||!h)return this.diagram.delete(i),null;this.diagram.connect(l,h,{startAnchor:{mode:"automatic",position:l.relativePosition},endAnchor:e==="textAnnotation"||e==="documentAnnotation"?{mode:"automatic"}:void 0});const u=this.diagram.getExtension(Y);return u.clearSelection(),u.selectNode(i),this.diagram.canvas.centerOnPoint(t.box.middle.copy().sum(i.box.middle).divide(2),!0),i}nearestAvailablePosition(t,e){const s=this.diagram.getExtension(G).gridSize,i=this.diagram.nodes.filter(c=>c!==t&&c.state.groupChildren!==!0).map(c=>c.box.inflate(s));let a=null,r=Number.POSITIVE_INFINITY;for(let c=0;c<=Jc;c+=1){const l=[];for(let u=-c;u<=c;u+=1)for(let f=-c;f<=c;f+=1)Math.max(Math.abs(u),Math.abs(f))===c&&l.push([u,f]);l.sort((u,f)=>{const p=u[0]**2+u[1]**2,m=f[0]**2+f[1]**2;return p!==m?p-m:this.placementDirectionRank(u)-this.placementDirectionRank(f)}),l.forEach(([u,f])=>{const p=e.copy(!1).sum([u*s,f*s]),m=p.toDimensions(t.box.size);if(!(m.x>=0&&m.y>=0&&m.x+m.width<=this.diagram.canvas.size.x&&m.y+m.height<=this.diagram.canvas.size.y)||i.some(w=>w.collides(m)))return;const b=(u*s)**2+(f*s)**2;b<r&&(a=p,r=b)});const h=(c+1)*s;if(a&&h**2>r)return a}return a}placementDirectionRank([t,e]){return e===0&&t>=0?0:t===0&&e>0?1:t===0&&e<0?2:t>=0?3:4}startToolbarConnection(t,e){this.diagram.getExtension(de).startConnectionFromNode(t,e,"automatic")}get connecting(){return this.diagram.getExtension(de).connecting}renameNode(t,e){this.emit(new Z(this)),g.runInAction(()=>t.setState("label",e))}acceptsEventDefinition(t,e){return!Kt(e)||t.attachedToTaskId&&!Ir.has(e.kind)?!1:!t.subprocessStart||Mn.has(e.kind)}eventKindOptions(t){return Kc.filter(e=>t.attachedToTaskId&&!Ir.has(e)?!1:!t.subprocessStart||Mn.has(e))}eventDefinitionForKind(t,e){const s=Cr[e],i=Pr.some(r=>Kt({kind:e,stage:t.stage,direction:r}))?t.stage:s.stage,a=Ar.some(r=>Kt({kind:e,stage:r,direction:t.direction}))?t.direction:s.direction;return{kind:e,stage:i,direction:a}}changeEventKind(t,e){if(!this.eventKindOptions(t).includes(e))return!1;const s=this.eventDefinitionForKind(t,e);return this.acceptsEventDefinition(t,s)?(this.emit(new Z(this)),t.setDefinition(s)):!1}eventStageOptions(t){return Ar.filter(e=>this.acceptsEventDefinition(t,{...t.definition,stage:e}))}eventDirectionOptions(t){return Pr.filter(e=>this.acceptsEventDefinition(t,{...t.definition,direction:e}))}changeEventStage(t,e){const s={...t.definition,stage:e};return this.acceptsEventDefinition(t,s)?(this.emit(new Z(this)),t.setDefinition(s)):!1}changeEventDirection(t,e){const s={...t.definition,direction:e};return this.acceptsEventDefinition(t,s)?(this.emit(new Z(this)),t.setDefinition(s)):!1}changeEventInterrupting(t,e){t.attachedToTaskId&&(this.emit(new Z(this)),g.runInAction(()=>t.setInterrupting(e)))}eventSubprocessStart(t){return this.diagram.nodes.find(e=>e instanceof D&&e.subprocessStart&&e.subprocessId===t.id)??null}containedEventCandidate(t){return this.diagram.nodes.find(e=>e instanceof D&&!e.attachedToTaskId&&!e.subprocessStart&&t.box.x<=e.box.x&&t.box.y<=e.box.y&&t.box.x+t.box.width>=e.box.x+e.box.width&&t.box.y+t.box.height>=e.box.y+e.box.height)??null}eventSubprocessStartKind(t){return this.eventSubprocessStart(t)?.kind??""}changeEventSubprocessStartKind(t,e){if(t.type!==N.eventSubprocess||!Mn.has(e))return null;const s=this.eventSubprocessStart(t)??this.containedEventCandidate(t);if(this.emit(new Z(this)),s)return s.setDefinition(this.eventDefinitionForKind(s,e))&&s.setSubprocessStart(!0,t.id)?s:null;const i=new D(null,{eventDefinition:Cr[e],id:Pe(this.diagram,"eventSubprocessStart"),label:this.labels.elements[e],subprocessId:t.id,subprocessStart:!0});return this.diagram.add(i),i.setPosition(new y([Math.min(t.box.x+25,t.box.x+t.box.width-i.box.width),Math.min(t.box.y+50,t.box.y+t.box.height-i.box.height)]),{updateConnectedEdges:!1}),i}changeTaskMultiInstance(t,e){return this.emit(new Z(this)),t.setMultiInstance(e)}changeTaskLoop(t,e){return this.emit(new Z(this)),t.setLoop(e)}renameEdge(t,e){this.emit(new Z(this)),g.runInAction(()=>t.setPrimaryLabel(e))}edgeKindOptions(t){const e=t.from.parent,s=t.to.parent;return e instanceof xt||s instanceof xt||e instanceof mt||s instanceof mt?["association"]:e instanceof Mt||s instanceof Mt?["messageFlow"]:e instanceof Lt||e instanceof $t?["inputDataAssociation"]:s instanceof Lt||s instanceof $t?["outputDataAssociation"]:Uc}changeEdgeKind(t,e){this.edgeKindOptions(t).includes(e)&&(this.emit(new Z(this)),g.runInAction(()=>t.setKind(e)))}reverseEdge(t){this.emit(new Z(this)),g.runInAction(()=>t.reverseDirection())}changeEdgePathType(t,e){this.emit(new Z(this)),g.runInAction(()=>t.setPathType(e))}changeEdgeCondition(t,e){this.emit(new Z(this)),g.runInAction(()=>{t.condition=e})}changeEdgeDefault(t,e){return t.isDefault===e?!0:e&&!this.supportsDefaultFlow(t)?!1:(this.emit(new Z(this)),t.setDefault(e))}changeEdgeDirected(t,e){!t.supportsDirection||t.isDirected===e||(this.emit(new Z(this)),g.runInAction(()=>t.setDirected(e)))}supportsDefaultFlow(t){return t.supportsDefaultFlow}supportsCondition(t){if(t.kind!=="sequenceFlow")return!1;const e=t.from.parent;return!(e instanceof W&&(e.type===H.parallel||e.type===H.eventBased))}togglePropertiesPanel(){g.runInAction(()=>{this.propertiesPanelOpen=!this.propertiesPanelOpen}),typeof window<"u"&&window.localStorage.setItem(kn,String(this.propertiesPanelOpen))}closePropertiesPanel(){g.runInAction(()=>{this.propertiesPanelOpen=!1}),typeof window<"u"&&window.localStorage.setItem(kn,"false")}};o(ba,"BPMNModelerExtension");let ue=ba;const wa=class wa extends He{constructor(t){super(t),this.registerExtension(Ve),this.registerExtension(he),this.registerExtension(Bt),this.registerExtension(js),this.registerExtension(ue),this.getExtension(ue).configureLabels(t?.labels??{}),this.registerExtension(En),this.registerClass(st),this.registerClass(j),this.registerClass(D),this.registerClass(W),this.registerClass(yt),this.registerClass(vn),this.registerClass(Mt),this.registerClass(Lt),this.registerClass($t),this.registerClass(mt),this.registerClass(xt)}get bpmnLabels(){return this.getExtension(ue).labels}configureLabels(t){this.getExtension(ue).configureLabels(t)}};o(wa,"BPMDiagram");let An=wa;const va=class va extends Xt{constructor(t,e){super(t,e),this.state.arrowHeadEnd=this.state.arrowHeadEnd??"arrow",this.state.arrowHeadStart=this.state.arrowHeadStart??"none",this.state.lineStyle=this.state.lineStyle??"solid",this.state.pathType=this.state.pathType??"orthogonal",this.state.strokeWidth=this.state.strokeWidth??2}};o(va,"CommunicationEdge");let Ts=va;const Ea=class Ea extends St{constructor(t,e){super(t,{...e,box:e.box??new S([0,0,180,96]),fill:e.fill,stroke:e.stroke,label:e.label??""}),this.classList.add("communication__node","diagram__node")}};o(Ea,"CommunicationNode");let Ze=Ea;const _a=class _a extends Ze{communicationNodeType="actor";constructor(t,e){super(t,{...e,box:e.box??new S([0,0,170,90]),fill:e.fill??"#0f2230",stroke:e.stroke??"#7dd3fc",label:e.label??"Actor"}),this.classList.add("communication__node--actor")}RenderOverlay=A.observer(()=>d.jsx("div",{...K(this),children:d.jsx("div",{className:"communication__node-badge",children:"Actor"})}))};o(_a,"CommunicationActorNode");let Ls=_a;const Sa=class Sa extends Ze{communicationNodeType="object";constructor(t,e){super(t,{...e,box:e.box??new S([0,0,190,96]),fill:e.fill??"#182412",stroke:e.stroke??"#bef264",label:e.label??"Object"}),this.classList.add("communication__node--object")}RenderOverlay=A.observer(()=>d.jsx("div",{...K(this),children:d.jsx("div",{className:"communication__node-badge",children:"Object"})}))};o(Sa,"CommunicationObjectNode");let $s=Sa;const Ma=class Ma extends Ze{communicationNodeType="controller";constructor(t,e){super(t,{...e,box:e.box??new S([0,0,200,100]),fill:e.fill??"#2b1618",stroke:e.stroke??"#fda4af",label:e.label??"Controller"}),this.classList.add("communication__node--controller")}RenderOverlay=A.observer(()=>d.jsx("div",{...K(this),children:d.jsx("div",{className:"communication__node-badge",children:"Controller"})}))};o(Ma,"CommunicationControllerNode");let zs=Ma;const ka=class ka extends He{constructor(t){super(t),this.registerClass(Ls),this.registerClass($s),this.registerClass(zs),this.registerClass(Ts),this.setDefaultEdge(Ts)}get selectedNodes(){return this.getExtension(Y).selectedNodes}get selectedEdges(){return this.getExtension(Y).selectedEdges}createNodeFromClientPoint(t,e,s){const i=this.canvas.inverseFit(new y([e,s]));return this.createNodeAtCanvasPoint(t,i.x,i.y)}createNodeAtCanvasPoint(t,e,s){const i=this.instantiateNode(t);this.add(i);const a=new y([e-i.box.width/2,s-i.box.height/2]);return i.setPosition(a),this.getExtension(Y).clearSelection(),this.getExtension(Y).selectNode(i),i}createNodeInViewportCenter(t){const e=this.canvas.frameDimensions,s=new y([e.x+e.width/2,e.y+e.height/2]);return this.createNodeFromClientPoint(t,s.x,s.y)}instantiateNode(t){const e={id:Pe(this,"node"),label:Qc(t),box:new S([0,0,180,96])};return t==="actor"?new Ls(this,e):t==="controller"?new zs(this,e):new $s(this,e)}};o(ka,"CommunicationDiagram");let Pn=ka;function Qc(n){return n==="actor"?"Actor":n==="controller"?"Controller":"Object"}o(Qc,"defaultLabelForType");function ee(n){return n&&(Object.assign(n,{__scalable:!0}),n)}o(ee,"makeScalableComponent");function tl(n){return n&&(Object.assign(n,{__scalableBack:!0}),n)}o(tl,"makeBackScalableComponent");const Cn=ee(({coordinates:n,size:t=20,strokeWidth:e=2,rounded:s=!0,stroke:i="#ff0000"})=>{const a=t/2,r=s?"round":"butt";return d.jsxs(d.Fragment,{children:[d.jsx("line",{x1:n.x-a,y1:n.y,x2:n.x+a,y2:n.y,stroke:i,strokeWidth:e,strokeLinecap:r}),d.jsx("line",{x1:n.x,y1:n.y-a,x2:n.x,y2:n.y+a,stroke:i,strokeWidth:e,strokeLinecap:r})]})}),el=0,Dr=32;function jr(n){switch(n){case"left":return[-1,0];case"right":return[1,0];case"up":return[0,-1];case"down":return[0,1];default:return[1,0]}}o(jr,"orientationVector$1");function sl(n,t,e,s,i){const a=1-i,r=a**3,c=3*a**2*i,l=3*a*i**2,h=i**3;return new y([n.x*r+t.x*c+e.x*l+s.x*h,n.y*r+t.y*c+e.y*l+s.y*h],!1)}o(sl,"cubicPoint");function nl(n){const t=n.steps;if(t.length<2||n.pathType==="orthogonal")return[...t];const e=t[0],s=t.at(-1);if(n.pathType==="straight")return[e,s];const i=e.distance(s),a=Math.max(40,Math.min(160,i/2)),r=jr(n.from.orientation),c=jr(n.to.orientation),l=new y([e.x+r[0]*a,e.y+r[1]*a],!1),h=new y([s.x+c[0]*a,s.y+c[1]*a],!1);return Array.from({length:Dr+1},(u,f)=>sl(e,l,h,s,f/Dr))}o(nl,"routePolyline");function il(n,t,e=el){const s=nl(n);let i=Number.POSITIVE_INFINITY,a=null,r=null;for(let u=0;u<s.length-1;u+=1){const f=s[u],p=s[u+1],m=p.x-f.x,x=p.y-f.y,b=m**2+x**2;if(b<1e-6)continue;const w=Math.max(0,Math.min(1,((t.x-f.x)*m+(t.y-f.y)*x)/b)),v=f.x+m*w,_=f.y+x*w,E=(t.x-v)**2+(t.y-_)**2;E>=i||(i=E,a=[v,_],r=[m,x])}if(!a||!r)return t.copy().sum([0,-e]);const c=Math.hypot(r[0],r[1]);let l=-r[1]/c,h=r[0]/c;return(h>1e-6||Math.abs(h)<=1e-6&&l<0)&&(l*=-1,h*=-1),new y([a[0]+l*e,a[1]+h*e])}o(il,"positionEdgeLabelBesideRoute");function Nr(n){switch(n){case"left":return[-1,0];case"right":return[1,0];case"up":return[0,-1];case"down":return[0,1];default:return[1,0]}}o(Nr,"orientationVector");function al(n,t,e){const s=n[0],i=n.at(-1),a=t?.pathType??e??"orthogonal";if(a==="orthogonal")return"M "+n.map(x=>`${x.x} ${x.y}`).join(" L ");if(a==="straight")return`M ${s.x} ${s.y} L ${i.x} ${i.y}`;const r=s.distance(i),c=Math.max(40,Math.min(160,r/2)),l=Nr(t?.from.orientation),h=Nr(t?.to.orientation),u=s.x+l[0]*c,f=s.y+l[1]*c,p=i.x+h[0]*c,m=i.y+h[1]*c;return`M ${s.x} ${s.y} C ${u} ${f}, ${p} ${m}, ${i.x} ${i.y}`}o(al,"buildEdgePath");const rl={};function ol(){const n=rl;return n.DEBUG_EDGES===!0||n.DEBUG_EDGES==="true"}o(ol,"debugEdgesEnabled");function cl(n,t){const e=n instanceof O?n.mode:"coordinate",s=n instanceof O?n.manualAxes:"none";return`${t}: x=${n.x}, y=${n.y}, mode=${e}, manualAxes=${s}`}o(cl,"formatPoint");function ll(n,t){const e=t.points[0],s=t.points[1],i=n.steps.findIndex((r,c)=>r===e&&n.steps[c+1]===s);if(i>=0)return i;const a=Number(t.id);return Number.isFinite(a)?a:null}o(ll,"segmentIndexFor");function dl(n,t){if(t.type==="edge")return"clicked: edge path";if(t.type==="endpoint")return`clicked: endpoint ${t.endpoint}`;const e=ll(n,t.midpoint),s=e===null?"unknown":`${e} -> ${e+1}`;return["clicked: drag point",`dragPoint.midpointId=${t.midpoint.id}`,`dragPoint.renderedIndex=${t.renderedIndex}`,`dragPoint.segment=${s}`,`dragPoint.x=${t.midpoint.x}`,`dragPoint.y=${t.midpoint.y}`].join(`
|
|
3
|
-
`)}o(
|
|
4
|
-
`)}o(hl,"formatEdgeDebug");async function ul(n){if(navigator.clipboard?.writeText){await navigator.clipboard.writeText(n);return}const t=document.createElement("textarea");t.value=n,t.style.position="fixed",t.style.left="-9999px",document.body.appendChild(t),t.focus(),t.select(),document.execCommand("copy"),t.remove()}o(ul,"writeClipboard");function Xe(n,t){if(!n||!ol())return;const e=hl(n,t);ul(e).then(()=>{console.info("[DEBUG_EDGES] copied edge debug to clipboard",e)}).catch(s=>{console.warn("[DEBUG_EDGES] failed to copy edge debug to clipboard",s,e)})}o(Xe,"copyEdgeDebugToClipboard");const Tr=o(({id:n,color:t,type:e,width:s,arrowSize:i,flip:a=!1})=>{const r=a?"180":"auto",c="white";switch(e){case"arrow":return d.jsx("marker",{id:n,markerWidth:i,markerHeight:i,refX:a?0:i*.9,refY:i/2,orient:r,markerUnits:"userSpaceOnUse",children:d.jsx("path",{d:`M0,0 L${i},${i/2} L0,${i} Z`,fill:t,className:"edge_marker_path"})});case"arrow-open":return d.jsx("marker",{id:n,markerWidth:i,markerHeight:i,refX:a?0:i,refY:i/2,orient:r,markerUnits:"userSpaceOnUse",children:d.jsx("path",{d:`M0,0 L${i},${i/2} L0,${i}`,fill:"none",stroke:t,strokeWidth:s,strokeLinecap:"butt",strokeLinejoin:"miter",className:"edge_marker_outline"})});case"triangle":return d.jsx("marker",{id:n,markerWidth:i,markerHeight:i,refX:a?0:i,refY:i/2,orient:r,markerUnits:"userSpaceOnUse",children:d.jsx("path",{d:`M0,0 L${i},${i/2} L0,${i} Z`,fill:c,stroke:t,strokeWidth:s/2,className:"edge_marker_outline"})});case"triangle-filled":return d.jsx("marker",{id:n,markerWidth:i,markerHeight:i,refX:a?0:i,refY:i/2,orient:r,markerUnits:"userSpaceOnUse",children:d.jsx("path",{d:`M0,0 L${i},${i/2} L0,${i} Z`,fill:t,className:"edge_marker_path"})});case"diamond":return d.jsx("marker",{id:n,markerWidth:i,markerHeight:i,refX:a?0:i*.9,refY:i/2,orient:r,markerUnits:"userSpaceOnUse",children:d.jsx("path",{d:`M0,${i/2} L${i/2},0 L${i},${i/2} L${i/2},${i} Z`,fill:"white",stroke:t,strokeWidth:s/2,className:"edge_marker_outline"})});case"circle-small":return d.jsx("marker",{id:n,markerWidth:i,markerHeight:i,refX:i/2,refY:i/2,orient:r,markerUnits:"userSpaceOnUse",children:d.jsx("circle",{cx:i/2,cy:i/2,r:i/4,fill:"white",stroke:t,strokeWidth:s/2,className:"edge_marker_outline"})});case"circle-medium":return d.jsx("marker",{id:n,markerWidth:i*1.5,markerHeight:i*1.5,refX:i*1.5/2,refY:i*1.5/2,orient:r,markerUnits:"userSpaceOnUse",children:d.jsx("circle",{cx:i*1.5/2,cy:i*1.5/2,r:i/2,fill:"white",stroke:t,strokeWidth:s/2,className:"edge_marker_outline"})});case"default-flow":return d.jsx("marker",{id:n,markerWidth:i,markerHeight:i,refX:i*.2-5-s/2,refY:i/2,orient:r,markerUnits:"userSpaceOnUse",children:d.jsx("path",{d:`M${i*.2},${i*.85} L${i*.8},${i*.15}`,fill:"none",stroke:t,strokeLinecap:"round",strokeWidth:s,className:"edge_marker_outline"})});case"measure":return d.jsx("marker",{id:n,markerWidth:i*5,markerHeight:i*5,refX:0,refY:i/2,orient:r,markerUnits:"userSpaceOnUse",children:d.jsx("path",{d:`M0,0 L0,${i/2}`,stroke:t,strokeWidth:3,strokeLinecap:"round",className:"edge_marker_outline"})});default:return null}},"EdgeMarker"),Fs=class Fs extends y{constructor(t,e,s,i){super(i),this.id=t,this.edge=e,this.points=s,this.assign(s[0].copy().sum(s[1]).divide(2)),g.makeObservable(this,{points:g.observable})}id;edge;points;copy(){return new Fs(this.id,this.edge,this.points,super.copy())}};o(Fs,"Midpoint");let In=Fs;function gl(n,t){const e=[];for(let s=0;s<t.length-1;s++){const i=[t[s],t[s+1]],a=i.filter(c=>c instanceof O&&c.mode==="static").length,r=n.steps.length===2&&t.length===2;a===2&&!r||e.push(new In(String(s),n,i))}return e}o(gl,"getSegmentMidpoints");const pl=o(({edge:n,onMouseDown:t,points:e})=>{const s=gl(n,e);return d.jsx(d.Fragment,{children:s.map((i,a)=>{const r=i.x,c=i.y;return d.jsx("rect",{x:r-6,y:c-6,width:12,height:12,rx:4,className:"edge_drag_point","data-edge-id":n.id,"data-midpoint-id":i.id,"data-midpoint-index":a,onMouseDownCapture:o(l=>{Xe(n,{type:"drag-point",midpoint:i,renderedIndex:a}),t(i,l)},"onMouseDownCapture")},i.id)})})},"EdgeMidpoints");function fl(n){if(n instanceof O)switch(n.mode){case"auto":return"red";case"manual":return"green";case"static":return"yellow"}}o(fl,"crossColor");const qe=A.observer(({edge:n,points:t,color:e,width:s=2,arrowSize:i=8,startType:a="none",endType:r="arrow",lineStyle:c="solid",pathType:l,endStroke:h=e,startStroke:u=e,onMidpointMouseDown:f,onEndpointMouseDown:p,className:m,draggable:x})=>{const b=o(P=>M.useMemo(()=>`marker-${P}-${Math.random().toString(36).slice(2)}`,[]),"makeId"),w=b("start"),v=b("end");if(!t||t.length<2)return null;const _=al(t,n,l),E=c==="dashed"?`${s*3},${s*2}`:c==="dotted"?`${s},${s*2}`:"none",C=!!(n&&x&&n.pathType==="orthogonal"&&(n.state.hover||n.state.dragging||n.state.selected)),k=!!(n&&x&&(n.state.selected||n.state.dragging));return d.jsxs("g",{"data-id":n?.id,className:["edge",n?.state.dragging&&"dragging",n?.state.selected&&"selected",n?.state.hover&&"hover",m].filter(Boolean).join(" "),onMouseEnter:o(()=>{g.runInAction(()=>{n&&(n.state.hover=!0)})},"onMouseEnter"),onMouseLeave:o(()=>{g.runInAction(()=>{n&&(n.state.hover=!1)})},"onMouseLeave"),onDoubleClick:o(P=>{if(!n?.diagram)return;P.stopPropagation();const I=n.diagram.canvas.inverseFit(new y(P.nativeEvent));n.createLabel(il(n,I))},"onDoubleClick"),children:[d.jsxs("defs",{children:[d.jsx(Tr,{id:w,color:u,type:a,width:s,arrowSize:i,flip:!1}),d.jsx(Tr,{id:v,color:h,type:r,width:s,arrowSize:i,flip:!1})]}),d.jsx("path",{d:_,strokeWidth:s+8,fill:"none",className:"edge-hover-area",onClickCapture:o(()=>{Xe(n,{type:"edge"})},"onClickCapture")}),d.jsx("path",{d:_,fill:"none",className:"edge-path",style:{"--edge-hover-stroke-width":`${Math.max(s+4,6)}px`,"--edge-selected-stroke-width":`${Math.max(s+2,4)}px`},stroke:e,strokeWidth:s,strokeDasharray:E,markerStart:a!=="none"?`url(#${w})`:void 0,markerEnd:r!=="none"?`url(#${v})`:void 0,onClickCapture:o(()=>{Xe(n,{type:"edge"})},"onClickCapture")}),es.instance.showDragHints&&t.map((P,I)=>d.jsx(Cn,{coordinates:P,size:15,stroke:fl(P)},I)),C&&d.jsx(pl,{edge:n,points:t,onMouseDown:o((P,I)=>{f?.(P,I)},"onMouseDown")}),k&&d.jsxs(d.Fragment,{children:[d.jsxs("g",{className:"edge_endpoint_drag_handle","data-edge-id":n?.id,"data-endpoint":"from",onMouseDownCapture:o(P=>{Xe(n,{type:"endpoint",endpoint:"from"}),p?.("from",P)},"onMouseDownCapture"),children:[d.jsx("circle",{cx:t[0].x,cy:t[0].y,r:12,className:"edge_endpoint_drag_hit_area"}),d.jsx("circle",{cx:t[0].x,cy:t[0].y,r:6,className:"edge_endpoint_drag_point"})]}),d.jsxs("g",{className:"edge_endpoint_drag_handle","data-edge-id":n?.id,"data-endpoint":"to",onMouseDownCapture:o(P=>{Xe(n,{type:"endpoint",endpoint:"to"}),p?.("to",P)},"onMouseDownCapture"),children:[d.jsx("circle",{cx:t.at(-1).x,cy:t.at(-1).y,r:12,className:"edge_endpoint_drag_hit_area"}),d.jsx("circle",{cx:t.at(-1).x,cy:t.at(-1).y,r:6,className:"edge_endpoint_drag_point"})]})]})]})}),ml=ee(A.observer(()=>{const n=q.use(),t=n.getExtension(de),e=n.getExtension(le),s=t.arrowSteps;return!s.length&&!e.endpointCandidatePoint?null:d.jsxs(d.Fragment,{children:[t.candidatePoint&&d.jsx(Cn,{coordinates:t.candidatePoint,stroke:"yellow"}),e.endpointCandidatePoint&&d.jsx(Cn,{coordinates:e.endpointCandidatePoint,stroke:"yellow"}),d.jsx(qe,{points:s,width:2*n.canvas.scale,arrowSize:8*n.canvas.scale,pathType:t.previewPathType})]})})),yl=ee(A.observer(()=>{const t=q.use().getExtension(De);return t?.enabled?d.jsx(d.Fragment,{children:d.jsx(qe,{points:t.get(),startType:"measure",endType:"measure",width:2,arrowSize:12,lineStyle:"dotted",startStroke:"red",endStroke:"red",className:"measurement"})}):null})),xl=M.forwardRef(({children:n,paths:t,transform:e,selected:s,onClick:i,className:a,roundedBorders:r=!1,label:c,labelColor:l,labelFontSize:h,labelFontFamily:u="sans-serif",labelOffset:f,"data-id":p,...m},x)=>{const b=q.use();return d.jsxs("g",{...m,"data-id":p,className:`${a||""} ${s?"selected":""} base_shape`,transform:e,onClick:i,ref:x,children:[d.jsx("defs",{children:t.map((w,v)=>{if(!w.arrow)return null;const _=6,{size:E=_,color:C=w.stroke??"#111"}=w.arrow,k=`arrow-${v}`;return d.jsx("marker",{id:k,viewBox:"0 0 10 10",refX:_*1.5,refY:"5",markerWidth:E,markerHeight:E,orient:"auto-start-reverse",markerUnits:"userSpaceOnUse",children:d.jsx("path",{d:"M 0 0 L 10 5 L 0 10",fill:"none",stroke:C,strokeWidth:Math.max(1,_*.9),strokeLinecap:"round",strokeLinejoin:"round"})},v)})}),t.map((w,v)=>{const{d:_,fill:E="none",stroke:C="#111",strokeWidth:k=3,strokeStyle:P="solid",animated:I=!1,animationDuration:B=1,nonScalingStroke:X=!0,roundedBorders:wt=r,arrow:rt}=w;let nt;switch(P){case"dashed":nt="10 5";break;case"dotted":nt="2 6";break}const ot=I?d.jsx("animate",{attributeName:"stroke-dashoffset",from:"0",to:nt?`-${nt.split(" ").reduce((Ca,ql)=>+Ca+ +ql,0)}`:"-15",dur:`${B}s`,repeatCount:"indefinite"}):null,vt=rt?`url(#arrow-${v})`:void 0;return d.jsx("path",{d:_,fill:E,stroke:C,strokeWidth:k,strokeDasharray:nt,strokeLinecap:wt?"round":"butt",strokeLinejoin:wt?"round":"miter",vectorEffect:X?"non-scaling-stroke":void 0,markerStart:rt?.position==="start"||rt?.position==="both"?vt:void 0,markerEnd:!rt||rt.position==="end"||rt.position==="both"?vt:void 0,children:ot},v)}),c&&d.jsx("text",{x:f?.x??0,y:f?.y??0,textAnchor:"middle",dominantBaseline:"middle",fontFamily:u,fontSize:h,fill:l,pointerEvents:"none",...b.canvas.scale>1?{shapeRendering:"geometricPrecision",style:{paintOrder:"stroke",stroke:"transparent",strokeWidth:.5,WebkitFontSmoothing:"antialiased",transform:"translateZ(0)"}}:{},children:c}),n]})}),ge=A.observer(xl),Lr=o((n,t=0)=>{const{x:e,y:s,width:i,height:a}=n;if(t<=0)return`M${e},${s} h${i} v${a} h${-i}Z`;const r=Math.min(t,i/2,a/2);return[`M${e+r},${s}`,`h${i-2*r}`,`a${r},${r} 0 0 1 ${r},${r}`,`v${a-2*r}`,`a${r},${r} 0 0 1 ${-r},${r}`,`h${-(i-2*r)}`,`a${r},${r} 0 0 1 ${-r},${-r}`,`v${-(a-2*r)}`,`a${r},${r} 0 0 1 ${r},${-r}`,"Z"].join(" ")},"getRectPath"),bl=o((n,t)=>`M ${n.x-t}, ${n.y}
|
|
1
|
+
(function(T,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("mobx"),require("react"),require("mobx-react-lite"),require("svg-path-bbox")):typeof define=="function"&&define.amd?define(["exports","mobx","react","mobx-react-lite","svg-path-bbox"],f):(T=typeof globalThis<"u"?globalThis:T||self,f(T.FocusMattersDiagrams={},T.mobx,T.React,T.mobxReactLite))})(this,(function(T,f,k,A){"use strict";var cc=Object.defineProperty;var wf=(T,f,k)=>f in T?cc(T,f,{enumerable:!0,configurable:!0,writable:!0,value:k}):T[f]=k;var o=(T,f)=>cc(T,"name",{value:f,configurable:!0});var Ft=(T,f,k)=>wf(T,typeof f!="symbol"?f+"":f,k);var je,Pe,Ne,Te,De,Le,Oe,ze;const In=class In{showDragHints=!1;constructor(){f.makeAutoObservable(this)}};o(In,"ToolsStates"),Ft(In,"instance",new In);let Tn=In;var Ai={exports:{}},$e={};var to;function dc(){if(to)return $e;to=1;var n=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function e(i,s,r){var a=null;if(r!==void 0&&(a=""+r),s.key!==void 0&&(a=""+s.key),"key"in s){r={};for(var l in s)l!=="key"&&(r[l]=s[l])}else r=s;return s=r.ref,{$$typeof:n,type:i,key:a,ref:s!==void 0?s:null,props:r}}return o(e,"jsxProd"),$e.Fragment=t,$e.jsx=e,$e.jsxs=e,$e}o(dc,"requireReactJsxRuntime_production");var eo;function hc(){return eo||(eo=1,Ai.exports=dc()),Ai.exports}o(hc,"requireJsxRuntime");var d=hc();const wt=class wt{_data=[];constructor(t,e=!0){if(t||(t=[0,0,0,0]),Array.isArray(t)){if(t.length!==4)throw new Error("Invalid coordinates length");this._data=[...t]}else this._data=[...t._data];if(this.width<0){const i=this.width;this.x+=i,this.width=-i}if(this.height<0){const i=this.height;this.y+=i,this.height=-i}e&&f.makeAutoObservable(this)}get coordinates(){return new y(this.raw.slice(0,2))}get bottomLeft(){return new y([this.x,this.y+this.height])}get bottomMiddle(){return new y([this.x+this.width/2,this.y+this.height])}get bottomRight(){return new y([this.x+this.width,this.y+this.height])}get leftMiddle(){return new y([this.x,this.y+this.height/2])}get middle(){return new y([this.x+this.width/2,this.y+this.height/2])}get rightMiddle(){return new y([this.x+this.width,this.y+this.height/2])}get topLeft(){return this.coordinates}get topMiddle(){return new y([this.x+this.width/2,this.y])}get topRight(){return new y([this.x+this.width,this.y])}get size(){return new y(this.raw.slice(2,4))}get x(){return this.get(0)}get y(){return this.get(1)}get height(){return this.get(3)}get width(){return this.get(2)}set x(t){this.set(0,t)}set y(t){this.set(1,t)}set height(t){this.set(3,t)}set width(t){this.set(2,t)}get norm(){return this.size.substract(this.coordinates).norm}get length(){return this._data.length}get raw(){return f.toJS([...this._data])}get round(){return new wt([Math.round(this.x),Math.round(this.y),Math.round(this.width),Math.round(this.height)])}get style(){return{width:this.width,height:this.height,left:this.x,top:this.y}}assign(t){if(t.length!==4)throw new Error("Invalid number of Dimensions");const e=t instanceof wt?t:new wt(t);return this.set(0,e.get(0)),this.set(1,e.get(1)),this.set(2,e.get(2)),this.set(3,e.get(3)),this}assignCoordinates(t){if(t.length!==2)throw new Error("Invalid number of Coordinates");const e=t instanceof y?t:new y(t);return this.set(0,e.get(0)),this.set(1,e.get(1)),this}assignDimensions(t){if(t.length!==2)throw new Error("Invalid number of Coordinates");const e=t instanceof y?t:new y(t);return this.set(2,e.get(0)),this.set(3,e.get(1)),this}bound(t){this.x=Math.min(t.x+t.width-this.width,Math.max(t.x,this.x)),this.y=Math.min(t.y+t.height-this.height,Math.max(t.y,this.y))}collides(t,e=!1){if(t instanceof wt){const i=this.x-(e?1:0),s=this.x+this.width+(e?1:0),r=this.y-(e?1:0),a=this.y+this.height+(e?1:0),l=t.x,c=t.x+t.width,h=t.y,u=t.y+t.height;return!(s<=l||c<=i||a<=h||u<=r)}else{const i=this.x,s=this.x+this.width,r=this.y,a=this.y+this.height;return t.x>=i&&t.x<=s&&t.y>=r&&t.y<=a}}copy(){return new wt([this.x,this.y,this.width,this.height])}divide(t){return this.set(0,this.get(0)/t),this.set(1,this.get(1)/t),this.set(2,this.get(2)/t),this.set(3,this.get(3)/t),this}edgeDistanceX(t){return this.x>t.x+t.width?-(this.x-t.x-t.width):t.x>this.x+this.width?t.x-this.x-this.width:0}edgeDistanceY(t){return this.y>t.y+t.height?-(this.y-t.y-t.height):t.y>this.y+this.height?t.y-this.y-this.height:0}get(t){return this._data[t]}inflate(t){return this.copy().translate(new y([-t,-t])).assignDimensions(this.size.sum(new y([2*t,2*t])))}multiply(t){return this.set(0,this.get(0)*t),this.set(1,this.get(1)*t),this.set(2,this.get(2)*t),this.set(3,this.get(3)*t),this}scale(t){return this.set(2,this.get(2)+t.get(0)),this.set(3,this.get(3)+t.get(1)),this}set(t,e){this._data[t]=e}substract(t){if(t.length!==4)throw new Error("Invalid number of Dimensions");const e=t instanceof wt?t:new wt(t);return this.set(0,this.get(0)-e.get(0)),this.set(1,this.get(1)-e.get(1)),this.set(2,this.get(2)-e.get(2)),this.set(3,this.get(3)-e.get(3)),this}sum(t){if(t instanceof y)this.set(0,this.get(0)+t.get(0)),this.set(1,this.get(1)+t.get(1));else{if(t.length!==4)throw new Error("Invalid number of Dimensions");const e=t instanceof wt?t:new wt(t);this.set(0,this.get(0)+e.get(0)),this.set(1,this.get(1)+e.get(1)),this.set(2,this.get(2)+e.get(2)),this.set(3,this.get(3)+e.get(3))}return this}toString(){return`(${this.x}, ${this.y}, ${this.width}, ${this.height})`}translate(t){return this.set(0,this.get(0)+t.get(0)),this.set(1,this.get(1)+t.get(1)),this}};o(wt,"Dimensions");let S=wt;const Hs=class Hs{constructor(t){this.originalEvent=t}originalEvent;get button(){switch(this.originalEvent.button){case 1:return"left";case 2:return"right";case 4:return"middle";case 8:return"back";case 16:return"forward"}return"none"}get position(){return new y(this.originalEvent,!1)}get x(){return this.originalEvent.clientX}get y(){return this.originalEvent.clientY}};o(Hs,"MouseInformation");let Ci=Hs;const Bs=class Bs{constructor(t){this.src=t}src;_cancellable=!0;_cancelled=!1;_bubbles=!0;_spreads=!0;get bubbles(){return this._bubbles}get cancelled(){return this._cancelled}get spreads(){return this._spreads}cancellable(t){return this._cancellable=t,this}cancel(){this._cancellable&&(this._cancelled=!0)}stopPropagation(){this._bubbles=!1}stopImmediatePropagation(){this._spreads=!1,this.stopPropagation()}};o(Bs,"DEvent");let Dn=Bs;const Rs=class Rs extends Dn{};o(Rs,"DUIEvent");let pe=Rs;const Gs=class Gs extends pe{constructor(t,e){super(t),this.src=t,this.originalEvent=e,this.mouse=new Ci(e)}src;originalEvent;mouse;get ctrl(){return this.originalEvent.ctrlKey}get edge(){return this.src.diagram?.getEdgeById(this.originalEvent.target?.closest(".edge")?.dataset.id||"")}get node(){const t=this.originalEvent.target,e=t&&typeof t.closest=="function"?t:null,i=e?.closest(".diagram__node, .node__screenHitArea")?.dataset.id,s=e?.closest("[data-gateway-parent]")?.dataset.gatewayParent;if(i||s)return this.src.diagram?.getNodeById(i||s);if(e?.closest(".edge")&&"clientX"in this.originalEvent&&"clientY"in this.originalEvent){const r=document.elementsFromPoint(this.originalEvent.clientX,this.originalEvent.clientY).find(a=>a.closest(".diagram__node"))?.closest(".diagram__node");return this.src.diagram?.getNodeById(r?.dataset.id||"")}}get shift(){return this.originalEvent.shiftKey}get target(){return this.originalEvent.target}};o(Gs,"DMouseEvent");let Ht=Gs;const Vs=class Vs extends Ht{};o(Vs,"DClickEvent");let Ln=Vs;const Ws=class Ws extends Ht{};o(Ws,"DDoubleClickEvent");let On=Ws;const Ys=class Ys extends Ht{};o(Ys,"DMouseDownEvent");let Bt=Ys;const Zs=class Zs extends Ht{};o(Zs,"DMouseUpEvent");let ot=Zs;const Ks=class Ks extends Ht{};o(Ks,"DMouseMoveEvent");let Rt=Ks;const Us=class Us extends Ht{constructor(t,e){super(t,e),this.originalEvent=e}originalEvent;get directionX(){return this.originalEvent.deltaX<0?"left":this.originalEvent.deltaX>0?"right":"none"}get directionY(){return this.originalEvent.deltaY<0?"up":this.originalEvent.deltaY>0?"down":"none"}};o(Us,"DWheelEvent");let Ii=Us;const Xs=class Xs extends pe{constructor(t,e){super(t),this.originalEvent=e}originalEvent;get code(){return this.originalEvent.code}get alt(){return this.originalEvent.altKey}get ctrl(){return this.originalEvent.ctrlKey}get shift(){return this.originalEvent.shiftKey}};o(Xs,"DKeyboardEvent");let Fe=Xs;const qs=class qs extends Fe{constructor(t,e){super(t,e),this.originalEvent=e}originalEvent};o(qs,"DKeyDownEvent");let te=qs;const Js=class Js extends Fe{constructor(t,e){super(t,e),this.originalEvent=e}originalEvent};o(Js,"DKeyUpEvent");let He=Js;const Qs=class Qs extends Fe{constructor(t,e){super(t,e),this.orignalEvent=e}orignalEvent};o(Qs,"DKeyPressEvent");let ji=Qs;const tr=class tr extends pe{};o(tr,"DCanvasEvent");let Be=tr;const er=class er extends Be{constructor(t,e,i,s){super(t),this.displacement=e,this.newScale=i,this.previousScale=s}displacement;newScale;previousScale};o(er,"DScaleEvent");let Re=er;const nr=class nr extends Be{constructor(t,e,i){super(t),this.previousDisplacement=e,this.displacement=i}previousDisplacement;displacement};o(nr,"DDisplaceEvent");let Pi=nr;const ir=class ir extends Dn{};o(ir,"DChangeEvent");let tt=ir;const sr=class sr extends tt{constructor(t,e){super(t),e(this.resolve.bind(this))}callbacks=[];defer(t){this.callbacks.push(t)}async resolve(){return(await Promise.all(this.callbacks.map(t=>t()))).every(t=>t)}};o(sr,"DResetGraphEvent");let Ni=sr;const rr=class rr extends tt{};o(rr,"DNodesConnectionEvent");let Ge=rr;const ar=class ar extends Ge{constructor(t,e){super(t),this.origin=e}origin};o(ar,"DNodeConnectionIntentEvent");let Ti=ar;const or=class or extends Ge{constructor(t,e,i,s){super(t),this.origin=e,this.target=i,this.edge=s}origin;target;edge};o(or,"DNodesConnectActionEvent");let Ve=or;const lr=class lr extends tt{};o(lr,"DNodeChangeTypeEvent");let _t=lr;const cr=class cr extends tt{constructor(t,e){super(t),this.src=t,this.node=e}src;node};o(cr,"DDeleteNodeEvent");let ge=cr;const dr=class dr extends tt{constructor(t,e){super(t),this.src=t,this.edge=e}src;edge};o(dr,"DDeleteEdgeEvent");let zn=dr;const hr=class hr extends pe{constructor(t,e){super(t),this.src=t,this.selected=e}src;selected};o(hr,"DSelectionEvent");let We=hr;const ur=class ur extends We{constructor(t,e){super(t,e),this.src=t}src};o(ur,"DNodeSelectionEvent");let Ye=ur;const pr=class pr extends We{constructor(t,e){super(t,e),this.src=t}src};o(pr,"DEdgeSelectionEvent");let $n=pr;const gr=class gr extends tt{constructor(t,e){super(t),this.src=t,this.originalEvent=e}src;originalEvent};o(gr,"DDragEvent");let Kt=gr;const fr=class fr extends Kt{constructor(t,e,i){super(t,i),this.src=t,this.midPoint=e,this.originalEvent=i}src;midPoint;originalEvent};o(fr,"DEdgeDragStartEvent");let Fn=fr;const mr=class mr extends Kt{constructor(t,e,i){super(t,i),this.src=t,this.endpoint=e,this.originalEvent=i}src;endpoint;originalEvent};o(mr,"DEdgeEndpointDragStartEvent");let Hn=mr;const xr=class xr{constructor(t,e){this.node=t,this.newBox=e,this._updated=e.copy()}node;newBox;_cancelled=!1;_updated;_lockX=null;_lockY=null;cancel(){this._cancelled=!0}get current(){return this._updated.copy()}get cancelled(){return this._cancelled}get(){return this._updated}lockX(){this._lockX=this._updated.x}lockY(){this._lockY=this._updated.y}update(t){this._updated=t,this._lockX!==null&&(this._updated.x=this._lockX),this._lockY!==null&&(this._updated.y=this._lockY)}updateX(t){this._lockX===null&&(this._updated.x=t)}updateY(t){this._lockY===null&&(this._updated.y=t)}};o(xr,"NodePositionProposal");let Ze=xr;const yr=class yr extends Kt{constructor(t,e,i){super(t,i),this.src=t,this.proposals=e}src;proposals};o(yr,"DDragNodeEvent");let Et=yr;const br=class br{constructor(t,e){this.point=t,this.movedAxis=e,this._updated=t.copy()}point;movedAxis;_updated;_lockX=null;_lockY=null;get current(){return this._updated.copy()}get(){return this._updated}lockX(){this._lockX=this._updated.x}lockY(){this._lockY=this._updated.y}update(t){this._updated=t.copy(),this._lockX!==null&&(this._updated.x=this._lockX),this._lockY!==null&&(this._updated.y=this._lockY)}updateX(t){this._lockX===null&&(this._updated.x=t)}updateY(t){this._lockY===null&&(this._updated.y=t)}};o(br,"EdgePointPositionProposal");let Bn=br;const wr=class wr extends Kt{constructor(t,e,i,s){super(t,s),this.src=t,this.proposals=e,this.movedAxis=i}src;proposals;movedAxis};o(wr,"DDragEdgeSegmentEvent");let Rn=wr;async function uc(){return(await Promise.resolve().then(()=>yf)).DirectedPoint}o(uc,"getDirectedClass");let Di=null;const J=class J{_data=[];constructor(t,e=!0){if(t||(t=[0,0]),Array.isArray(t)){if(t.length!==2)throw new Error("Invalid coordinates length");this._data=[...t]}else t instanceof J?this._data=[...t._data]:t instanceof Ht||t instanceof Kt?this._data=[t.originalEvent.clientX,t.originalEvent.clientY]:t.clientX!==void 0?this._data=[t.clientX,t.clientY]:this._data=[0,0];e&&f.makeObservable(this,{_data:f.observable,set:f.action})}bound(t){return this.x=Math.min(t.get(2),Math.max(t.get(0),this.x)),this.y=Math.min(t.get(3),Math.max(t.get(1),this.y)),this}get abs(){return new J([Math.abs(this.x),Math.abs(this.y)])}assign(t){if(t.length!==2)throw new Error("Invalid number of coordinates");const e=t instanceof J?t:new J(t);return this.set(0,e.get(0)),this.set(1,e.get(1)),this}copy(t=!0){return new J(this,t)}distance(t){return this.copy().substract(t).norm}distanceManhattan(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}divide(t){const e=t instanceof J?t.x:t,i=t instanceof J?t.y:t;return this.set(0,this.get(0)/e),this.set(1,this.get(1)/i),this}equals(t){return this.copy().substract(t).norm===0}get(t){return this._data[t]}get length(){return this._data.length}max(t){return new J([Math.max(t,this.x),Math.max(t,this.y)])}get nonObserved(){return new J(this,!1)}get raw(){return f.toJS([...this._data])}get round(){return new J([Math.round(this.x),Math.round(this.y)])}get half(){return this.copy().multiply(.5)}get norm(){return Math.sqrt(this.x**2+this.y**2)}get style(){return{left:this.x,top:this.y}}multiply(t){return typeof t=="number"?(this.set(0,this.get(0)*t),this.set(1,this.get(1)*t)):t instanceof J&&(this.set(0,this.get(0)*t.get(0)),this.set(1,this.get(1)*t.get(1))),this}set(t,e){return this._data[t]=e,this}snapToGrid(t,e="both"){return e!=="y"&&(this.x=Math.round(this.x/t)*t),e!=="x"&&(this.y=Math.round(this.y/t)*t),this}substract(t){if(t.length!==2)throw new Error("Invalid number of coordinates");const e=t instanceof J?t:new J(t);return this.set(0,this.get(0)-e.get(0)),this.set(1,this.get(1)-e.get(1)),this}sum(t){if(typeof t=="number")this.set(0,this.get(0)+t),this.set(1,this.get(1)+t);else{if(t.length!==2)throw new Error("Invalid number of coordinates");const e=t instanceof J?t:new J(t);this.set(0,this.get(0)+e.get(0)),this.set(1,this.get(1)+e.get(1))}return this}toDirectedPoint(t){if(Di===null){uc().then(s=>{Di=s});const i=this.copy(!1);return i.direction=t,i}const e=new Di(this);return e.direction=t,e}toDimensions(t){return new S([...this.raw,...t.raw])}get x(){return this.get(0)}get y(){return this.get(1)}set x(t){this.set(0,t)}set y(t){this.set(1,t)}toString(){return`(${this.x}, ${this.y})`}};o(J,"Coordinates");let y=J;const jn=class jn{static getInstance(){return this.instance||(this.instance=new jn),this.instance}x=0;y=0;get coordinates(){return new y([this.x,this.y])}constructor(){f.makeAutoObservable(this),document.addEventListener("mousemove",t=>{f.runInAction(()=>{this.x=t.clientX,this.y=t.clientY})})}};o(jn,"Mouse"),Ft(jn,"instance",null);let fe=jn;const no={};function me(n,t,e=[]){let i=no[t]||0;for(;e.includes(`${t}${i}`)||n.getNodeById(`${t}${i}`);)i++;return no[t]=i+1,`${t}${i}`}o(me,"getIdForNode");function pc(n){const t=[];let e=n;for(;e&&e!==Object;)t.push(e),e=Object.getPrototypeOf(e);return t}o(pc,"getClassHierarchy");let ee=(je=class{constructor(t){this.parent=t,f.makeObservable(this,{parent:f.observable,diagram:f.computed})}parent;callbacks=new Map;emit(t){const e=[];for(const i of pc(t.constructor)){const s=this.callbacks.get(i);s&&e.push(...s)}e.sort((i,s)=>s.priority-i.priority);for(const{cb:i}of e)if(i(t),!t.spreads)return t;return t.bubbles&&this.parent?.emit(t),t}get diagram(){let t=this.parent;for(;t?.parent;)t=t.parent;return t}onEvent(t,e,i=0){let s=this.callbacks.get(t);return s||(s=[],this.callbacks.set(t,s)),s.push({cb:e,priority:i}),()=>this.offEvent(t,e)}offEvent(t,e){const i=this.callbacks.get(t);i&&this.callbacks.set(t,i.filter(s=>s.cb!==e))}},o(je,"Element"),je);function gc(n,t,e="text/plain"){const i=new Blob([n],{type:e}),s=URL.createObjectURL(i),r=document.createElement("a");r.href=s,r.download=t,r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(s)}o(gc,"downloadFile");const vr=class vr extends ee{constructor(t){super(t),f.makeObservable(this,{_enable:f.observable,toggle:f.action}),this._enable=localStorage.getItem(`enable_${this.constructor.name}`)!=="false"}RenderUI=null;RenderDiagram=null;get diagram(){return this.parent}_enable=!0;get enabled(){return this._enable}disable(){this._enable=!1}enable(){this._enable=!0}toggle(t=!this._enable,e=!0){this._enable=t,e&&localStorage.setItem(`enable_${this.constructor.name}`,String(this._enable))}};o(vr,"DiagramExtension");let z=vr;const Li=new WeakMap;let fc=0;const ft={mark(n,t){const e=Li.get(n)??{};e[t]===void 0&&(e[t]=fc++,Li.set(n,e))},get(n,t){return Li.get(n)?.[t]}};function io(n,t){return!n||t.score<n.score?t:n}o(io,"nearest");const _r=class _r extends z{gridSize=25;proposals=[];clear(){this.proposals=[]}init(){f.makeObservable(this,{clear:f.action,proposals:f.observable}),this.diagram.onEvent(ot,()=>this.clear()),this.diagram.onEvent(Et,t=>this.balance(t),this.diagram.priorities.Drag_Node_Distances_Balancer)}balance(t){if(this.clear(),!this.enabled||t.proposals.length===0)return;const e=new Set(t.proposals.map(({node:l})=>l.id)),i=this.diagram.canvas.frameDimensions.norm/2;let s=null,r=null;for(const l of t.proposals){if(l.cancelled)continue;const c=l.get(),h=this.findNeighbors(c,e,i);if(h.top&&h.bottom){const u=-c.edgeDistanceY(h.top.box),g=c.edgeDistanceY(h.bottom.box),p=Math.abs(u-g);p<this.gridSize&&(r=io(r,{proposal:l,score:p,target:(h.top.box.bottomMiddle.y+h.bottom.box.topMiddle.y)/2-c.height/2,guides:[{from:c.topMiddle,to:new y([c.topMiddle.x,h.top.box.bottomMiddle.y])},{from:c.bottomMiddle,to:new y([c.bottomMiddle.x,h.bottom.box.topMiddle.y])}]}))}if(h.left&&h.right){const u=-c.edgeDistanceX(h.left.box),g=c.edgeDistanceX(h.right.box),p=Math.abs(g-u);p<this.gridSize&&(s=io(s,{proposal:l,score:p,target:(h.right.box.leftMiddle.x+h.left.box.rightMiddle.x)/2-c.width/2,guides:[{from:c.rightMiddle,to:new y([h.right.box.leftMiddle.x,c.rightMiddle.y])},{from:c.leftMiddle,to:new y([h.left.box.rightMiddle.x,c.leftMiddle.y])}]}))}}const a=[...s?.guides??[],...r?.guides??[]];f.runInAction(()=>{this.proposals=a}),this.applyCandidate(s,"x"),this.applyCandidate(r,"y")}findNeighbors(t,e,i){let s=null,r=null,a=null,l=null,c=1/0,h=1/0,u=1/0,g=1/0;for(const p of this.diagram.nodes){if(e.has(p.id))continue;const m=t.edgeDistanceX(p.box),b=t.edgeDistanceY(p.box);b===0&&m<0&&-m<u&&(u=-m,a=p),b===0&&m>0&&m<g&&(g=m,l=p),m===0&&b<0&&-b<c&&(c=-b,s=p),m===0&&b>0&&b<h&&(h=b,r=p)}return{top:c<i?s:null,bottom:h<i?r:null,left:u<i?a:null,right:g<i?l:null}}applyCandidate(t,e){if(t){if(e==="x"){t.proposal.updateX(t.target),ft.mark(t.proposal,"x"),t.proposal.lockX();return}t.proposal.updateY(t.target),ft.mark(t.proposal,"y"),t.proposal.lockY()}}};o(_r,"DistancesBalancer");let Ke=_r;const Er=class Er extends z{gridSize=50;init(){f.makeObservable(this,{gridSize:f.observable}),this.diagram.onEvent(Et,t=>{if(this._enable)for(const e of t.proposals){const i=new y([Math.round(e.newBox.coordinates.x/this.gridSize)*this.gridSize,Math.round(e.newBox.coordinates.y/this.gridSize)*this.gridSize]);e.update(new S([...i.raw,...e.newBox.size.raw])),e.lockX(),e.lockY()}},this.diagram.priorities.Drag_Node_Snap_To_Grid),this.diagram.onEvent(Rn,t=>{if(this._enable)for(const e of t.proposals){const i=e.get().copy();i.snapToGrid(this.gridSize,t.movedAxis),e.update(i),t.movedAxis==="x"?e.lockY():e.lockX()}},this.diagram.priorities.Drag_Edge_Snap_To_Grid)}};o(Er,"GridSnap");let R=Er;const kr=class kr extends z{windowTime=20;maxSize=50;index=-1;snapshots=[];draggingNodes=!1;async avoidEvents(t){this.disable();try{await t()}finally{this.enable()}}restoreSnapshot(t){return this.avoidEvents(async()=>{this.clearTransientExtensions(),this.draggingNodes=!1;const e=JSON.parse(t);e.position=this.checkpointPosition(),await this.diagram.reset(),this.diagram.import(JSON.stringify(e))})}clearTransientExtensions(){this.diagram.extensions.forEach(t=>{t.clear?.()})}checkpointPosition(){const t=this.diagram.canvas.displacement;return{x:t.x,y:t.y,scale:this.diagram.canvas.scale}}unbind=o(()=>{},"unbind");window(){this.enabled&&(this.unbind(),this.unbind=Mt(Rc(()=>{f.runInAction(()=>{const t=this.diagram.serialize();this.snapshots.splice(this.index+1),this.snapshots.push(JSON.stringify(t)),this.snapshots.splice(0,Math.max(0,this.snapshots.length-this.maxSize)),this.index=this.snapshots.length-1})},this.windowTime)))}redo(){if(this.hasNext)return this.index=Math.min(this.snapshots.length-1,this.index+1),this.restoreSnapshot(this.snapshots[this.index])}undo(){if(this.hasPrevious)return this.index=Math.max(-1,this.index-1),this.restoreSnapshot(this.snapshots[this.index]||"{}")}get hasNext(){return this.index<this.snapshots.length-1}get hasPrevious(){return this.index>-1}init(){f.makeObservable(this,{index:f.observable,hasNext:f.computed,hasPrevious:f.computed,redo:f.action,undo:f.action}),this.diagram.onEvent(tt,t=>{if(t instanceof Et){this.draggingNodes=!0;return}t.cancelled||this.window()},this.diagram.priorities.Change_History),this.diagram.onEvent(ot,()=>{this.draggingNodes&&(this.draggingNodes=!1,this.window())}),this.window()}};o(kr,"History");let Ue=kr;const Sr=class Sr extends z{init(){f.makeObservable(this,{_enabled:f.observable,endPoint:f.observable,startPoint:f.observable}),this.diagram.canvas.onEvent(Bt,this.handleMouseDown.bind(this),this.diagram.priorities.Mouse_Down_Measurer)}_enabled=!1;toggle(){this._enabled=!this._enabled}get enabled(){return this._enabled}endPoint=null;startPoint=null;get(){return this.startPoint?[this.startPoint,this.endPoint]:[]}getMeassurement(){return this.endPoint?.copy().substract(this.startPoint).norm}u=o(()=>{},"u");handleMouseDown(t){this._enabled&&(t.cancel(),t.stopImmediatePropagation(),this.u(),this.u=Mt(Y(this,"mousemove",this.handleMouseMove),Y(this,"mouseup",this.handleMouseUp)),this.startPoint=this.diagram.canvas.inverseFit(new y(t)),this.endPoint=this.diagram.canvas.inverseFit(new y(t)))}handleMouseMove(t){this.startPoint&&this._enabled&&(this.endPoint=this.diagram.canvas.inverseFit(new y(t)))}handleMouseUp(){this.endPoint=null,this.startPoint=null}};o(Sr,"Measurer");let Xe=Sr;const Gn=new Map;function ne(n){Gn.has(n)||Gn.set(n,Number.MIN_SAFE_INTEGER);const t=Gn.get(n);return Gn.set(n,t+1),`${n}_${t}`}o(ne,"getUniqueId");function xe(n,t){return n<=t?[n,t]:[t,n]}o(xe,"orderedRange$1");function Ut(n,t){return Number.isFinite(t.distance)&&(!n||t.distance<n.distance)?t:n}o(Ut,"closer$1");const Mr=class Mr extends z{gridSize=50;horizontalSuggestionProviders=[];verticalSuggestionProviders=[];proposals=[];registerHorizontalSuggestionProvider(t){return this.horizontalSuggestionProviders.push(t),()=>{this.horizontalSuggestionProviders=this.horizontalSuggestionProviders.filter(e=>e!==t)}}registerVerticalSuggestionProvider(t){return this.verticalSuggestionProviders.push(t),()=>{this.verticalSuggestionProviders=this.verticalSuggestionProviders.filter(e=>e!==t)}}clear(){this.proposals=[]}init(){f.makeObservable(this,{clear:f.action,proposals:f.observable}),Y(this,"keydown",t=>{t.ctrlKey&&this.clear()}),this.diagram.onEvent(ot,()=>this.clear()),this.diagram.onEvent(Et,t=>this.align(t),this.diagram.priorities.Drag_Node_Aligner)}align(t){if(this.clear(),!this.enabled||t.proposals.length===0)return;const e=this.diagram.canvas.frameDimensions.norm/2,i=this.gridSize/5*2,s=this.gridSize/3,r=new Set(t.proposals.map(({node:g})=>g.id)),a=t.proposals.some(g=>ft.get(g,"x")!==void 0),l=t.proposals.some(g=>ft.get(g,"y")!==void 0);let c=null,h=null;for(const g of t.proposals){if(g.cancelled)continue;const p=g.get();for(const m of this.diagram.nodes){if(r.has(m.id))continue;const b=Math.abs(p.edgeDistanceX(m.box)),x=Math.abs(p.edgeDistanceY(m.box));!l&&b<e&&(h=Ut(h,this.verticalCandidate(g,Math.abs(m.box.middle.y-p.middle.y),m.box.middle.y-p.height/2,m.box.middle.y,xe(m.box.rightMiddle.x,p.x),i)),h=Ut(h,this.verticalCandidate(g,Math.abs(m.box.y-p.y),m.box.y,m.box.y,xe(m.box.rightMiddle.x,p.x),i)),h=Ut(h,this.verticalCandidate(g,Math.abs(m.box.bottomMiddle.y-p.bottomMiddle.y),m.box.bottomMiddle.y-p.height,m.box.bottomMiddle.y,xe(m.box.rightMiddle.x,p.x),i))),!a&&x<e&&(c=Ut(c,this.horizontalCandidate(g,Math.abs(m.box.x-p.x),m.box.x,m.box.x,xe(m.box.bottomMiddle.y,p.y),i)),c=Ut(c,this.horizontalCandidate(g,Math.abs(m.box.middle.x-p.middle.x),m.box.middle.x-p.width/2,m.box.middle.x,xe(m.box.bottomMiddle.y,p.y),i)),c=Ut(c,this.horizontalCandidate(g,Math.abs(m.box.rightMiddle.x-p.rightMiddle.x),m.box.rightMiddle.x-p.width,m.box.rightMiddle.x,xe(m.box.bottomMiddle.y,p.y),i)))}if(!l)for(const m of this.verticalSuggestionProviders.flatMap(b=>b(g.node,p)))h=Ut(h,this.verticalCandidate(g,Math.abs(m.nodeY-p.y),m.nodeY,m.guideY,m.range,i));if(!a)for(const m of this.horizontalSuggestionProviders.flatMap(b=>b(g.node,p)))c=Ut(c,this.horizontalCandidate(g,Math.abs(m.nodeX-p.x),m.nodeX,m.guideX,m.range,i))}const u=[c?.guide,h?.guide].filter(g=>!!g);f.runInAction(()=>{this.proposals=u}),this.applyCandidate(c,"x",s),this.applyCandidate(h,"y",s)}verticalCandidate(t,e,i,s,r,a){return{proposal:t,distance:e<a?e:1/0,target:i,guide:{type:"v",y:s,range:r,id:ne("alignment-proposal")}}}horizontalCandidate(t,e,i,s,r,a){return{proposal:t,distance:e<a?e:1/0,target:i,guide:{type:"h",x:s,range:r,id:ne("alignment-proposal")}}}applyCandidate(t,e,i){if(!(!t||t.distance>=i)){if(e==="x"){if(t.proposal.updateX(t.target),Math.abs(t.proposal.get().x-t.target)>.001)return;ft.mark(t.proposal,"x"),t.proposal.lockX();return}t.proposal.updateY(t.target),!(Math.abs(t.proposal.get().y-t.target)>.001)&&(ft.mark(t.proposal,"y"),t.proposal.lockY())}}};o(Mr,"NodesAligner");let Xt=Mr;const ue=class ue{constructor(t){this.diagram=t}diagram;displace(t){if(!this.diagram.rules.displaceWhenDragOnEdges)return new y;const e=this.diagram.canvas.frameDimensions,i=new y([this.axisDisplacement(t.x,e.x,e.width),this.axisDisplacement(t.y,e.y,e.height)]);return i.norm>0&&this.diagram.canvas.displace(i),i}axisDisplacement(t,e,i){const s=t-e;if(s<ue.edgeThreshold)return this.step(s);const r=e+i-t;return r<ue.edgeThreshold?-this.step(r):0}step(t){const e=Math.max(t,0);return((ue.edgeThreshold-e)/10)**2}};o(ue,"Autopan"),Ft(ue,"edgeThreshold",100);let kt=ue;const Ar=class Ar extends tt{};o(Ar,"DEdgeLabelChangeEvent");let ye=Ar;const Cr=class Cr extends ee{id;text;alignment;size;position;isEditing;draft;isNew;constructor(t,e,i=!1){super(t),this.id=e.id??ne("edge-label"),this.text=e.text??"",this.alignment=e.alignment??"left",this.size=e.size??{height:30,width:180},this.position=e.position,this.isNew=i,this.isEditing=i,this.draft=this.text,f.makeObservable(this,{text:f.observable,alignment:f.observable,size:f.observable,position:f.observable,isEditing:f.observable,draft:f.observable,setText:f.action,setAlignment:f.action,setSize:f.action,beginEdit:f.action,setDraft:f.action,cancelEdit:f.action,confirmEdit:f.action,setPosition:f.action})}setText(t){this.text=t,this.draft=t,this.isNew=!1}setAlignment(t){this.alignment!==t&&(this.alignment=t,this.emit(new ye(this)))}setSize(t){this.size=t}beginEdit(){this.draft=this.text,this.isEditing=!0}setDraft(t){this.draft=t}cancelEdit(){if(this.isNew){this.parent.removeLabel(this,!1);return}this.draft=this.text,this.isEditing=!1}delete(){this.parent.removeLabel(this,!this.isNew)}confirmEdit(){if(!this.draft){this.parent.removeLabel(this,!this.isNew);return}const t=this.isNew||this.draft!==this.text;this.text=this.draft,this.isNew=!1,this.isEditing=!1,t&&this.emit(new ye(this))}setPosition(t){this.position.assign(t)}commitPosition(){this.emit(new ye(this))}serialize(){return{alignment:this.alignment,id:this.id,size:this.size,text:this.text,position:this.position.raw}}};o(Cr,"EdgeLabel");let qe=Cr;const Pn=class Pn extends y{constructor(t,e){super(Array.isArray(e)?e.slice(0,2):e),this.parent=t,f.makeObservable(this,{manualAxes:f.observable,mode:f.observable}),e instanceof Pn?(this.mode=e.mode,this.manualAxes=e.manualAxes):Array.isArray(e)&&e.length===3?(this.mode=e[2],this.manualAxes=this.mode==="manual"||this.mode==="static"?"both":"none"):Array.isArray(e)&&e.length>=4&&(this.mode=e[2],this.manualAxes=e[3])}parent;mode="auto";manualAxes="none";get manualX(){return this.mode==="manual"&&["x","both"].includes(this.manualAxes)}get manualY(){return this.mode==="manual"&&["y","both"].includes(this.manualAxes)}addManualAxis(t){return this.mode==="static"?this:(this.mode="manual",t==="both"||this.manualAxes==="both"?this.manualAxes="both":this.manualAxes==="none"?this.manualAxes=t:this.manualAxes!==t&&(this.manualAxes="both"),this)}hasManualAxis(t){return t==="x"?this.manualX:this.manualY}markStatic(){return this.mode="static",this.manualAxes="both",this}copy(){return new Pn(this.parent,[this.x,this.y,this.mode,this.manualAxes])}toString(t=!1){return t?`(${this.x}, ${this.y}): ${this.mode}/${this.manualAxes}`:super.toString()}};o(Pn,"EdgePoint");let H=Pn,mc=Number.MIN_SAFE_INTEGER;function so(n){return n==="straight"||n==="curved"?n:"orthogonal"}o(so,"normalizePathType");function xc(n,t){if(!n)return{mode:"fixed"};const e=n.parent.box,i=n.coordinates.copy().sum(t??new y);return{mode:"fixed",position:new y([(i.x-e.x)/Math.max(e.width,.001),(i.y-e.y)/Math.max(e.height,.001)])}}o(xc,"fixedAnchorForGateway");function Vn(n,t,e){return n?.mode==="automatic"?{mode:"automatic"}:n?.position?{mode:"fixed",position:n.position instanceof y?n.position:new y(n.position)}:xc(t,e)}o(Vn,"normalizeAnchor");function yc(n,t){return n?n.copy(!1).substract(t.relativePosition).norm<.001:!0}o(yc,"isGatewayAnchorPosition");const Ir=class Ir extends ee{constructor(t,e){super(t),this.state=e,this.state.pathType=so(this.state.pathType),this.state.startAnchor=Vn(this.state.startAnchor,this.state.from,this.state.displacementStart),this.state.endAnchor=Vn(this.state.endAnchor,this.state.to,this.state.displacementEnd),f.makeObservable(this,{state:f.observable,setSteps:f.action,setPathType:f.action,setEndpointAnchor:f.action,setResolvedEndpoint:f.action,applyResolvedAnchors:f.action,createLabel:f.action,removeLabel:f.action,setPrimaryLabel:f.action,arrowHeadEnd:f.computed,arrowHeadStart:f.computed,from:f.computed,hasManualSteps:f.computed,pathType:f.computed,steps:f.computed,stroke:f.computed,strokeWidth:f.computed,setState:f.action})}state;id=String(mc++);get arrowHeadEnd(){return this.state.arrowHeadEnd}get arrowHeadStart(){return this.state.arrowHeadStart}get from(){return this.state.from}get hasManualSteps(){return this.state.steps.find(t=>t.mode==="manual")}get lineStyle(){return this.state.lineStyle}get pathType(){return this.state.pathType}get startAnchor(){return this.state.startAnchor}get endAnchor(){return this.state.endAnchor}get steps(){return this.state.steps}get stroke(){return this.state.stroke}get strokeWidth(){return this.state.strokeWidth}get labels(){return this.state.labels}createLabel(t){const e=new qe(this,{position:t},!0);return this.state.labels.push(e),e}removeLabel(t,e=!0){const i=this.state.labels.indexOf(t);i<0||(this.state.labels.splice(i,1),e&&this.emit(new ye(this)))}setPrimaryLabel(t){const e=this.state.labels[0];if(!t)return e&&this.removeLabel(e,!1),null;if(e)return e.setText(t),e;const i=new qe(this,{text:t,position:this.defaultLabelPosition()});return this.state.labels.push(i),i}defaultLabelPosition(){if(this.steps.length===0)return this.from.coordinates.copy();if(this.steps.length===1)return this.steps[0].copy();const t=this.steps.slice(0,-1).map((s,r)=>s.distance(this.steps[r+1])),e=t.reduce((s,r)=>s+r,0)/2;let i=0;for(let s=0;s<t.length;s+=1){if(i+t[s]>=e){const r=(e-i)/Math.max(t[s],.001);return this.steps[s].copy().sum(this.steps[s+1].copy().substract(this.steps[s]).multiply(r))}i+=t[s]}return this.steps.at(-1).copy()}collides(t){for(let e=0;e<this.steps.length-1;e++){const i=this.steps[e],s=this.steps[e+1];if(new S([...i.raw,...s.copy().substract(i).raw]).collides(t))return!0}return!1}setState(t,e){this.state[t]=e}setSteps(t){this.state.steps=t.map(e=>e instanceof H?e:new H(this,e)),this.state.steps[0].markStatic(),this.state.steps.at(-1).markStatic()}setPathType(t){this.state.pathType=t,this.diagram&&this.state.to&&this.from.recomputeConnectedEdge(this,"from")}resolveEndpointAnchor(t){const e=t==="from"?this.from:this.to,i=t==="from"?this.startAnchor:this.endAnchor,s=t==="from"?this.state.displacementStart??new y:this.state.displacementEnd??new y;if(!e.parent.edgesAsGateways){const r=e.coordinates.copy().sum(s),a=e.parent.box;return{gateway:e,point:r,displacement:s,relativePosition:new y([(r.x-a.x)/Math.max(a.width,.001),(r.y-a.y)/Math.max(a.height,.001)])}}return yc(i.position,e)&&s.norm<.001?{gateway:e,point:e.coordinates.copy(),relativePosition:e.relativePosition,displacement:new y}:e.parent.findRelativeConnectionAnchor(i.position??e.relativePosition)}setEndpointAnchor(t,e,i=!0){t==="from"?this.state.startAnchor=e:this.state.endAnchor=e,i&&this.diagram&&this.from.recomputeConnectedEdge(this,t)}setResolvedEndpoint(t,e,i,s=!0){const r=this.resolveEndpointAnchor(t==="from"?"to":"from");t==="from"?(this.state.startAnchor=i,this.applyResolvedAnchors(e,r)):(this.state.endAnchor=i,this.applyResolvedAnchors(r,e)),s&&this.diagram&&this.from.recomputeConnectedEdge(this,t)}applyResolvedAnchors(t,e){const i=this.state.from,s=this.state.to,r=i?.outgoingEdges.includes(this)??!1,a=s?.incomingEdges.includes(this)??!1;i!==t.gateway&&(r&&i.removeOutgoingEdge(this),this.state.from=t.gateway,r&&t.gateway.addOutgoingEdge(this,!1)),s!==e.gateway&&(a&&s.removeIncomingEdge(this),this.state.to=e.gateway,a&&e.gateway.addIncomingEdge(this,!1)),this.state.displacementStart=t.displacement,this.state.displacementEnd=e.displacement}get to(){return this.state.to}deserialize(t){if(!Array.isArray(t.labels))throw new TypeError("Invalid serialized edge: 'labels' must be an array.");this.state.arrowHeadEnd=t.arrowHeadEnd,this.state.arrowHeadStart=t.arrowHeadStart,this.state.lineStyle=t.lineStyle,this.state.pathType=so(t.pathType),this.state.stroke=t.stroke,this.state.strokeWidth=t.strokeWidth,this.state.labels=t.labels.map(e=>new qe(this,{alignment:e.alignment,id:e.id,text:e.text,position:new y(e.position),size:e.size})),this.state.displacementEnd=t.displacementEnd?new y(t.displacementEnd):void 0,this.state.displacementStart=t.displacementStart?new y(t.displacementStart):void 0,this.state.steps=t.steps.map(e=>new H(this,e)),this.state.to=this.state.from.diagram.getNodeById(t.toParentId).getGateway(t.to),this.state.startAnchor=Vn(t.startAnchor,this.state.from,this.state.displacementStart),this.state.endAnchor=Vn(t.endAnchor,this.state.to,this.state.displacementEnd),this.state.from.diagram.addEdge(this)}serialize(){const{arrowHeadEnd:t,arrowHeadStart:e,lineStyle:i,pathType:s,startAnchor:r,endAnchor:a,steps:l,stroke:c,strokeWidth:h,to:{id:u,parent:{id:g}}}=this;return{arrowHeadEnd:t,arrowHeadStart:e,displacementEnd:this.state.displacementEnd?.raw,displacementStart:this.state.displacementStart?.raw,lineStyle:i,labels:this.state.labels.map(p=>p.serialize()),pathType:s,startAnchor:{mode:r.mode,position:r.position?.raw},endAnchor:{mode:a.mode,position:a.position?.raw},steps:l.map(p=>[...p.raw,p.mode,p.manualAxes]),stroke:c,strokeWidth:h,to:u,toParentId:g,class:this.constructor.name}}dragStart(t,e){e.button===0&&this.pathType==="orthogonal"&&(e.nativeEvent.stopImmediatePropagation(),this.emit(new Fn(this,t,e)))}dragEndpoint(t,e){e.button===0&&(e.nativeEvent.stopImmediatePropagation(),this.emit(new Hn(this,t,e)))}};o(Ir,"Edge");let qt=Ir;const jr=class jr{_data=new Set;constructor(){f.makeAutoObservable(this)}add(...t){for(const e of t)this._data.add(e)}delete(t){this._data.delete(t)}toggle(t){this._data.has(t)?this.delete(t):this.add(t)}get string(){return[...this._data].join(" ")}};o(jr,"ClassList");let Oi=jr;const Pr=class Pr{route(t,e){const i=e.from.parent.edgesAsGateways&&e.startAnchor.mode==="automatic"?this.findAutomaticStartPoint(e):e.resolveEndpointAnchor("from"),s=e.to.parent.edgesAsGateways&&e.endAnchor.mode==="automatic"?this.findAutomaticEndPoint(e):e.resolveEndpointAnchor("to");return e.applyResolvedAnchors(i,s),this.findRoute(t,e,i,s)}};o(Pr,"EdgesRouter");let Je=Pr;const Nr=class Nr extends Je{findAutomaticStartPoint(t){return t.from.parent.findAutomaticGatewayAnchor(t.to.parent.box.middle)}findAutomaticEndPoint(t){return t.to.parent.findAutomaticGatewayAnchor(t.from.parent.box.middle)}findRoute(t,e,i,s){return[i.point,s.point]}};o(Nr,"CurvedRouter");let zi=Nr;const F=.001,bc=3;function K(n,t,e=bc){return Math.abs(n-t)<=e}o(K,"almostEqual");function Wn(n,t){return Math.abs(n-t)<=F}o(Wn,"strictlyEqual");function ie(n,t){return K(n.x,t.x)&&K(n.y,t.y)}o(ie,"samePoint");function pt(n,t){return K(n.x,t.x)||K(n.y,t.y)}o(pt,"axisAligned");function wc(n,t){return Wn(n.x,t.x)&&Wn(n.y,t.y)}o(wc,"strictlySamePoint");function $i(n,t){return Wn(n.x,t.x)||Wn(n.y,t.y)}o($i,"strictlyAxisAligned");function Pt(n,t){return ie(n,t)||!pt(n,t)?null:K(n.y,t.y)?"horizontal":"vertical"}o(Pt,"segmentDirection");function Fi(n,t,e){if(K(n.x,t.x)&&K(t.x,e.x)||K(n.y,t.y)&&K(t.y,e.y))return!0;const i=(t.x-n.x)*(e.y-t.y)-(t.y-n.y)*(e.x-t.x);return Math.abs(i)<F}o(Fi,"collinear");function vc(n){return n instanceof H?n.mode:"auto"}o(vc,"pointMode");function nt(n,t){return new y([n,t],!1)}o(nt,"rawPoint");function ro(n){switch(n){case"left":return{x:-1,y:0};case"right":return{x:1,y:0};case"up":return{x:0,y:-1};case"down":return{x:0,y:1}}}o(ro,"vectorFor");function be(n,t){const e=ro(t);return n.x*e.x+n.y*e.y}o(be,"dot");function _c(n,t,e=vc(t)){return t instanceof H?(t.mode=e,t):new H(n,[t.x,t.y,e])}o(_c,"asEdgePoint");function St(n,t,e,i="auto"){return new H(n,[t,e,i])}o(St,"makePoint");function ao(n){return n.getExtension(R)?.gridSize??50}o(ao,"getGridSize");function Qe(n,t){const e=n.parent.state.box,i=n.state.position;return nt(e.x+i.x*e.width+(t?.x??0),e.y+i.y*e.height+(t?.y??0))}o(Qe,"endpointPoint");function mt(n,t){const e=n.parent.state.box;return new S([e.x-t,e.y-t,e.width+t*2,e.height+t*2],!1)}o(mt,"routingBox");function oo(n,t,e){return n>=t-F&&n<=e+F}o(oo,"coordinateWithinSpan");function Ec(n,t,e,i){let s=Number.POSITIVE_INFINITY;for(const r of e){if(t==="right"||t==="left"){if(!oo(n.y,r.y-i,r.y+r.height+i))continue;const l=t==="right"?r.x-n.x:n.x-(r.x+r.width);l>F&&l<s&&(s=l);continue}if(!oo(n.x,r.x-i,r.x+r.width+i))continue;const a=t==="down"?r.y-n.y:n.y-(r.y+r.height);a>F&&a<s&&(s=a)}return Number.isFinite(s)?s:null}o(Ec,"blockingDistance");function Yn(n,t,e,i,s){const r=Ec(t,e,s,i),a=r!==null&&r<i*2?r/2:i,l=ro(e);return St(n,t.x+l.x*a,t.y+l.y*a)}o(Yn,"adaptiveLeadPoint");function kc(n,t,e,i,s){if(i.orientation==="right"&&s.orientation==="left"&&e.x>t.x||i.orientation==="left"&&s.orientation==="right"&&e.x<t.x){const r=(t.x+e.x)/2;return[St(n,r,t.y),St(n,r,e.y)]}if(i.orientation==="down"&&s.orientation==="up"&&e.y>t.y||i.orientation==="up"&&s.orientation==="down"&&e.y<t.y){const r=(t.y+e.y)/2;return[St(n,t.x,r),St(n,e.x,r)]}return null}o(kc,"facingLeadPoints");function Sc(n,t,e,i){if(!$i(n,t)||wc(n,t))return!1;const s={x:t.x-n.x,y:t.y-n.y};return be(s,e)>F&&be(s,i)<-F}o(Sc,"directRouteIsValid");function lo(n){const t=[],e=new Set;for(const i of n){const s=i.toFixed(3);e.has(s)||(e.add(s),t.push(i))}return t}o(lo,"uniqueNumbers");function Mc(n){const t=[];for(const e of n){const i=t.at(-1);i&&ie(i,e)||t.push(e)}return t}o(Mc,"compactRawPoints");function co(n,t,e){if(!pt(n,t))return 1;if(K(n.x,t.x)){const c=n.x,h=Math.min(n.y,t.y),u=Math.max(n.y,t.y),g=c>e.x+F&&c<e.x+e.width-F,p=u>e.y+F&&h<e.y+e.height-F;return g&&p?1:0}const i=n.y,s=Math.min(n.x,t.x),r=Math.max(n.x,t.x),a=i>e.y+F&&i<e.y+e.height-F,l=r>e.x+F&&s<e.x+e.width-F;return a&&l?1:0}o(co,"segmentCollisionPenalty");function Ac(n,t,e){if(!pt(n,t))return 1;if(K(n.x,t.x)){const c=n.x,h=Math.min(n.y,t.y),u=Math.max(n.y,t.y),g=K(c,e.x)||K(c,e.x+e.width),p=Math.min(u,e.y+e.height)-Math.max(h,e.y);return g&&p>F?1:0}const i=n.y,s=Math.min(n.x,t.x),r=Math.max(n.x,t.x),a=K(i,e.y)||K(i,e.y+e.height),l=Math.min(r,e.x+e.width)-Math.max(s,e.x);return a&&l>F?1:0}o(Ac,"segmentBorderOverlapPenalty");function Cc(n,t,e={}){let i=0,s=0,r=0,a=0,l=0,c=e.incomingDirection??null;for(let h=0;h<n.length-1;h++){const u=n[h],g=n[h+1];if(!pt(u,g))return null;const p=Pt(u,g);if(h===0&&e.avoidFirstDirection&&p===e.avoidFirstDirection&&(r+=1),h===0&&e.avoidFirstBacktrack){const m={x:g.x-u.x,y:g.y-u.y};if(be(m,e.avoidFirstBacktrack)<-F)return null}if(h===n.length-2&&e.avoidLastDirection&&p===e.avoidLastDirection&&(r+=1),h===n.length-2&&e.avoidLastBacktrack){const m={x:u.x-g.x,y:u.y-g.y};if(be(m,e.avoidLastBacktrack)<-F)return null}l+=Math.abs(u.x-g.x)+Math.abs(u.y-g.y),c&&p&&c!==p&&(a+=1),c=p;for(const m of t.obstacleBoxes)i+=co(u,g,m),s+=Ac(u,g,m)}return c&&e.outgoingDirection&&c!==e.outgoingDirection&&(a+=1),[i,s,r,a,l,n.length]}o(Cc,"routeScore");function Ic(n,t){if(!t)return!0;for(let e=0;e<n.length;e+=1)if(n[e]!==t[e])return n[e]<t[e];return!1}o(Ic,"routeScoreIsBetter");function Zn(n,t,e){return e.obstacleBoxes.some(i=>co(n,t,i)>0)}o(Zn,"segmentHitsAnyBox");function ho(n,t,e){return $i(n,t)&&!Zn(n,t,e)}o(ho,"canCollapseToSegment");function Kn(n,t,e,i={}){if(ie(n,t))return[n];let s=null,r=null;const a=o(h=>{const u=Mc(h),g=Cc(u,e,i);g&&Ic(g,r)&&(s=u,r=g)},"push");pt(n,t)&&a([n,t]),a([n,nt(t.x,n.y),t]),a([n,nt(n.x,t.y),t]);const l=lo([n.x,t.x,(n.x+t.x)/2,...e.laneBoxes.flatMap(h=>[h.x,h.x-e.gridSize,h.x+h.width,h.x+h.width+e.gridSize])]),c=lo([n.y,t.y,(n.y+t.y)/2,...e.laneBoxes.flatMap(h=>[h.y,h.y-e.gridSize,h.y+h.height,h.y+h.height+e.gridSize])]);for(const h of l)a([n,nt(h,n.y),nt(h,t.y),t]);for(const h of c)a([n,nt(n.x,h),nt(t.x,h),t]);for(const h of l)for(const u of c)a([n,nt(h,n.y),nt(h,u),nt(t.x,u),t]),a([n,nt(n.x,u),nt(h,u),nt(h,t.y),t]);return s??[n,t]}o(Kn,"routeBridge");function jc(n){const t=[];for(let e=0;e<n.length;e++){const i=n[e],s=n[e+1];if(i.manualAxes==="x"){const r=s?.manualAxes==="x"&&K(i.x,s.x)?[i,s]:[i];t.push({type:"line",direction:"vertical",coordinate:i.x,points:r}),e+=r.length-1;continue}if(i.manualAxes==="y"){const r=s?.manualAxes==="y"&&K(i.y,s.y)?[i,s]:[i];t.push({type:"line",direction:"horizontal",coordinate:i.y,points:r}),e+=r.length-1;continue}t.push({type:"point",point:i})}return t}o(jc,"manualRouteConstraints");function Pc(n,t){return n?n.type==="point"?n.point:n.direction==="vertical"?nt(n.coordinate,t.y):nt(t.x,n.coordinate):t}o(Pc,"constraintReferencePoint");function uo(n,t,e){return n>t+F&&n<e-F}o(uo,"valueInside");function Un(n,t,e,i,s,r){let a=e;const l=n==="x"?"y":"x",c=r.gridSize/2;for(const h of r.obstacleBoxes){const u=l==="x"?h.x:h.y,g=l==="x"?h.x+h.width:h.y+h.height,p=n==="x"?h.x:h.y,m=n==="x"?h.x+h.width:h.y+h.height;if(!uo(t,u,g)||!uo(a,p,m))continue;const b=s!==void 0?s-a:0,x=i-a,w=(p+m)/2;a=(Math.abs(b)>F?Math.sign(b):Math.abs(x)>F?Math.sign(x):a<w?-1:1)<0?p-c:m+c}return a}o(Un,"safeLineEndpointCoordinate");function Nc(n,t,e,i,s){const r=n.points[0],a=n.points.at(-1),l=r?.copy()??St(i,0,0),c=a?.copy()??St(i,0,0);return l.parent=i,c.parent=i,n.direction==="vertical"?(l.addManualAxis("x"),c.addManualAxis("x"),l.x=n.coordinate,l.y=t.y,c.x=n.coordinate,c.y=e.y,s&&(l.y=Un("y",n.coordinate,l.y,e.y,r?.y,s),c.y=Un("y",n.coordinate,c.y,t.y,a?.y,s))):(l.addManualAxis("y"),c.addManualAxis("y"),l.x=t.x,l.y=n.coordinate,c.x=e.x,c.y=n.coordinate,s&&(l.x=Un("x",n.coordinate,l.x,e.x,r?.x,s),c.x=Un("x",n.coordinate,c.x,t.x,a?.x,s))),[l,c]}o(Nc,"lineConstraintEndpoints");function Tc(n,t){const e=new Map;return{copies:n.map(s=>{const r=s.copy();return r.parent=t,e.set(s,r),r}),copiesByOriginal:e}}o(Tc,"copyRouteManualPoints");function Dc(n,t,e){const i=t.get(n);if(i)return i;const s=n.copy();return s.parent=e,s}o(Dc,"routePointCopy");function Lc(n,t){return n.find(e=>e.mode==="static")??n.find(e=>t.has(e)&&e.mode==="manual")??n.find(e=>t.has(e))??n.find(e=>e.mode==="manual")??n[0]}o(Lc,"pickPointFromDuplicateRun");function Hi(n,t){const e=[];for(let i=0;i<n.length;){let s=i+1;for(;s<n.length&&ie(n[i],n[s]);)s+=1;e.push(Lc(n.slice(i,s),t)),i=s}return e}o(Hi,"removeAdjacentDuplicates");function po(n,t,e,i){return n.mode==="static"?n[e]:t.mode==="static"?t[e]:i.has(n)?n[e]:i.has(t)?t[e]:n[e]}o(po,"coordinateAnchor");function tn(n,t){for(let e=0;e<n.length-1;e++){const i=n[e],s=n[e+1];if(K(i.x,s.x)){const r=po(i,s,"x",t);i.x=r,s.x=r}if(K(i.y,s.y)){const r=po(i,s,"y",t);i.y=r,s.y=r}}return n}o(tn,"snapNearlyAlignedPairs");function go(n,t,e){const i=[...n];let s=i.filter(r=>r.mode==="manual").length;for(let r=1;r<i.length-1;){const a=i[r],l=Fi(i[r-1],a,i[r+1]),c=a.mode==="manual"&&t.has(a)&&s>e;if(a.mode==="manual"&&l&&s<=e){const h=i[r+1];if(r+2<i.length&&h.mode==="auto"&&!t.has(h)){i.splice(r+1,1);continue}const u=i[r-1];if(r-2>=0&&u.mode==="auto"&&!t.has(u)){i.splice(r-1,1),r=Math.max(1,r-1);continue}}if(a.mode==="static"||t.has(a)&&!c||!l){r+=1;continue}if(a.mode==="manual"&&s<=e){r+=1;continue}a.mode==="manual"&&(s-=1),i.splice(r,1)}return i}o(go,"removeRedundantCollinearPoints");function Bi(n,t,e){const i=[...n];for(let s=0;s<i.length-3;){const r=i[s],a=i[s+1],l=i[s+2],c=i[s+3];if(!(pt(r,a)&&pt(a,l)&&pt(l,c))||!ho(r,c,t)){s+=1;continue}if(a.mode!=="auto"||l.mode!=="auto"||e.has(a)||e.has(l)){s+=1;continue}i.splice(s+1,2)}return i}o(Bi,"collapseAutoDetours");function fo(n,t,e){const i=[...n];for(let s=!0;s;){s=!1;for(let r=0;r<i.length-3;r++){const a=i[r],l=i[r+1],c=i[r+2],h=i[r+3];if(l.mode==="auto"&&c.mode==="auto"&&!e.has(l)&&!e.has(c)&&pt(a,l)&&pt(l,c)&&pt(c,h)&&ho(a,h,t)){i.splice(r+1,2),s=!0;break}}}return i}o(fo,"collapseAnyAutoRectangles");function Oc(n,t,e,i){const s=new H(null,[t.x,n.y,"auto"]),r=new H(null,[n.x,t.y,"auto"]),a=o(l=>{let c=0;return e&&pt(e,l)&&(c+=1),i&&pt(l,i)&&(c+=1),n.mode==="manual"&&e&&Pt(e,n)===Pt(n,l)&&(c-=2),t.mode==="manual"&&i&&Pt(l,t)===Pt(t,i)&&(c-=2),c},"score");return a(s)>=a(r)?s:r}o(Oc,"chooseCorner");function Ri(n,t){if(n.length<2)return n;const e=[n[0]];for(let i=1;i<n.length;i++){const s=e.at(-1),r=n[i];if(!$i(s,r)){const a=e.length>=2?e[e.length-2]:void 0,l=i+1<n.length?n[i+1]:void 0,c=Oc(s,r,a,l);c.parent=t,e.push(c)}e.push(r)}return e}o(Ri,"ensureOrthogonalAdjacency");function mo(n,t,e=new Set){let i=n.map(r=>_c(t.parent,r));const s=i.some(r=>r.mode==="manual"&&r.manualAxes==="both")?1:0;for(let r=0;r<4;r++){const a=i.length;if(i=tn(i,e),i=Ri(i,t.parent),i=tn(i,e),i=Hi(i,e),i=go(i,e,s),i=Bi(i,t,e),i.length===a)break}return i=tn(i,e),i=Ri(i,t.parent),i=Hi(i,e),i=Bi(i,t,e),i=fo(i,t,e),i=go(i,e,s),i.length>0&&(i[0].markStatic(),i.at(-1).markStatic()),i}o(mo,"normalizeEdgePoints");function xo(n,t){const e=n.findIndex((i,s)=>s>0&&s<n.length-1&&ie(i,t));e>=0&&n.splice(e,1)}o(xo,"removeSameCoordinateInteriorPoint");function yo(n,t,e,i){let s=[...n];if(s.length<2)return s;ie(s[1],e)?s[1]=e:(xo(s,e),s.splice(1,0,e));const r=s.length-2;if(r<1)return s;ie(s[r],i)?s[r]=i:(xo(s,i),s.splice(s.length-1,0,i));const a=new Set([e,i]);return s=tn(s,a),s=Ri(s,t.parent),s=tn(s,a),s=Hi(s,a),s=Bi(s,t,a),s=fo(s,t,a),s.length>0&&(s[0].markStatic(),s.at(-1).markStatic()),s}o(yo,"ensureEndpointLeadPresence");function zc(n,t,e,i,s){if(!e||!Fi(n,t,e))return!1;const r={x:e.x-n.x,y:e.y-n.y};return be(r,i)>F&&!Zn(n,e,s)}o(zc,"canRemoveSourceLead");function $c(n,t,e,i,s){if(!n||!Fi(n,t,e))return!1;const r={x:e.x-n.x,y:e.y-n.y};return be(r,i)<-F&&!Zn(n,e,s)}o($c,"canRemoveTargetLead");function bo(n,t,e,i){const s=[...n];return s.length>2&&zc(s[0],s[1],s[2],t,i)&&s.splice(1,1),s.length>2&&$c(s.at(-3),s.at(-2),s.at(-1),e,i)&&s.splice(s.length-2,1),s.length>0&&(s[0].markStatic(),s.at(-1).markStatic()),s}o(bo,"compactRedundantEndpointLeads");function Gi(n,t,e,i,s){const r=St(s.parent,Qe(n,e).x,Qe(n,e).y,"static"),a=Qe(t,i),l=St(s.parent,a.x,a.y,"static");if(Sc(r,l,n.orientation,t.orientation))return[r,l];const c=kc(s.parent,r,l,n,t),h=c?.[0]??Yn(s.parent,r,n.orientation,s.gridSize,[mt(t,0)]),u=c?.[1]??Yn(s.parent,l,t.orientation,s.gridSize,[mt(n,0)]),g=new Set([h,u]),p=Kn(h,u,s,{avoidFirstBacktrack:n.orientation,avoidLastBacktrack:t.orientation,incomingDirection:Pt(r,h)??void 0,outgoingDirection:Pt(u,l)??void 0}),m=mo([r,...p,l],s,g);return bo(yo(m,s,h,u),n.orientation,t.orientation,s)}o(Gi,"routeAuto");function Fc(n,t,e,i,s,r=null){const a=ao(n),l={gridSize:a,obstacleBoxes:[mt(t,0),mt(e,0)],laneBoxes:[mt(t,a/2),mt(e,a/2)],parent:r};return Gi(t,e,i,s,l)}o(Fc,"routeOrthogonalBetweenGateways");function Hc(n,t,e=[],i){const s=ao(n),r={gridSize:s,obstacleBoxes:[mt(t.from,0),mt(t.to,0)],laneBoxes:[mt(t.from,s/2),mt(t.to,s/2)],parent:t},a=t.steps.filter((G,U)=>U>0&&U<t.steps.length-1&&G.mode==="manual");if(a.length===0)return Gi(t.from,t.to,t.state.displacementStart,t.state.displacementEnd,r);const l=Qe(t.from,t.state.displacementStart),c=Qe(t.to,t.state.displacementEnd),h=St(r.parent,l.x,l.y,"static"),u=St(r.parent,c.x,c.y,"static"),g=Yn(r.parent,h,t.from.orientation,s,[mt(t.to,0)]),p=Yn(r.parent,u,t.to.orientation,s,[mt(t.from,0)]),{copies:m,copiesByOriginal:b}=Tc(a,r.parent),x=e.map(G=>Dc(G,b,r.parent)),w=new Set([g,p,...x]),v=jc(m),_=[h,g];let E=g;for(let G=0;G<v.length;G++){const U=v[G],rt=E instanceof H&&E.mode==="manual"?Pt(_.at(-2),E)??void 0:void 0;if(U.type==="point"){const $t=Kn(E,U.point,r,{avoidFirstDirection:rt,avoidFirstBacktrack:G===0?t.from.orientation:void 0});_.push(...$t.slice(1)),E=U.point;continue}const Z=Pc(v[G+1],p);let[et,at]=Nc(U,E,Z,r.parent,r);if(Zn(et,at,r))continue;const vt=Kn(E,et,r,{avoidFirstDirection:rt,avoidFirstBacktrack:G===0?t.from.orientation:void 0});_.push(...vt.slice(1),at),E=at}const j=E instanceof H&&E.mode==="manual"?Pt(_.at(-2),E)??void 0:void 0,P=Kn(E,p,r,{avoidFirstDirection:j,avoidLastDirection:Pt(p,u)??void 0,avoidLastBacktrack:t.to.orientation});_.push(...P.slice(1),u);const M=mo(_,r,w),C=bo(yo(M,r,g,p),t.from.orientation,t.to.orientation,r);return C.some(G=>G.mode==="manual")?C:Gi(t.from,t.to,t.state.displacementStart,t.state.displacementEnd,r)}o(Hc,"routeOrthogonalEdge");const Tr=class Tr extends Je{findAutomaticStartPoint(t){return t.from.parent.findAutomaticGatewayAnchor(t.to.parent.box.middle)}findAutomaticEndPoint(t){return t.to.parent.findAutomaticGatewayAnchor(t.from.parent.box.middle)}findRoute(t,e,i,s){return Hc(t,e)}findRouteBetween(t,e,i,s=new y,r=new y){return Fc(t,e,i,s,r)}};o(Tr,"OrthogonalRouter");let Xn=Tr;const Dr=class Dr extends Je{findAutomaticStartPoint(t){return t.from.parent.findAutomaticConnectionAnchor(t.to.parent.box.middle)}findAutomaticEndPoint(t){return t.to.parent.findAutomaticConnectionAnchor(t.from.parent.box.middle)}findRoute(t,e,i,s){return[i.point,s.point]}};o(Dr,"StraightRouter");let Vi=Dr;const Bc={orthogonal:new Xn,straight:new Vi,curved:new zi};function wo(n){return Bc[n]}o(wo,"getEdgesRouter");const Lr=class Lr extends ee{state;constructor(t,e){super(t),this.state={allowDisplace:!0,stroke:"transparent",strokeWidth:10,radius:5,incomingEdges:[],outgoingEdges:[],position:new y,...e},f.makeObservable(this,{addIncomingEdge:f.action,addOutgoingEdge:f.action,state:f.observable,removeIncomingEdge:f.action,removeOutgoingEdge:f.action})}addIncomingEdge(t,e=!0){this.state.incomingEdges.find(i=>i.id===t.id)||this.state.incomingEdges.push(t)}addOutgoingEdge(t,e=!0){this.state.outgoingEdges.find(i=>i.id===t.id)||(this.state.outgoingEdges.push(t),e&&t.steps.length===0&&this.updateEdges())}canConnect(t,e){const i=this.state.incomingEdges.filter(s=>s!==e);return(this.state.maxIncomingConnections===void 0||this.state.maxIncomingConnections>i.length)&&!i.find(s=>s.from===t)}canStartConnection(t,e){const i=this.state.outgoingEdges.filter(s=>s!==e);return(this.state.maxOutgoingConnections===void 0||this.state.maxOutgoingConnections>i.length)&&!i.find(s=>s.to===t)}connectionDisplacement(t){return this.direction==="horizontal"&&Math.abs(t.y-this.coordinates.y)>10?new y([0,t.y-this.coordinates.y]):this.direction==="vertical"&&Math.abs(t.x-this.coordinates.x)>10?new y([t.x-this.coordinates.x,0]):new y([0,0])}connectionDistance(t){if(this.direction==="vertical"){const i=Math.abs(this.coordinates.y-t.y);return i<20?Math.abs(this.coordinates.x-t.x)+i**5:1/0}const e=Math.abs(this.coordinates.x-t.x);return e<20?Math.abs(this.coordinates.y-t.y)+e**5:1/0}removeIncomingEdge(t){for(let e=this.state.incomingEdges.length-1;e>=0;e--)this.state.incomingEdges[e].id===t.id&&this.state.incomingEdges.splice(e,1)}removeOutgoingEdge(t){for(let e=this.state.outgoingEdges.length-1;e>=0;e--)this.state.outgoingEdges[e].id===t.id&&this.state.outgoingEdges.splice(e,1)}get coordinates(){return this.state.position.copy().multiply(this.parent.box.size).sum(this.parent.coordinates)}get fill(){return this.state.fill}get diagram(){return this.parent.diagram}get incomingEdges(){return[...this.state.incomingEdges]}get outgoingEdges(){return[...this.state.outgoingEdges]}get radius(){return this.state.radius}get relativePosition(){return this.state.position.copy()}get stroke(){return this.state.stroke}get strokeWidth(){return this.state.strokeWidth}get id(){return this.state.id}get direction(){return["down","up"].includes(this.state.orientation)?"vertical":"horizontal"}get orientation(){return this.state.orientation}recomputeConnectedEdge(t,e){t.setSteps(wo(t.pathType).route(this.diagram,t))}updateEdges(){for(const t of this.state.incomingEdges)this.recomputeConnectedEdge(t,"to");for(const t of this.state.outgoingEdges)this.recomputeConnectedEdge(t,"from")}get remainingSlots(){return this.state.maxOutgoingConnections-this.state.outgoingEdges.length}deserialize(t){this.state.fill=t.fill,this.state.id=t.id,this.state.orientation=t.orientation,this.state.radius=t.radius,this.state.stroke=t.stroke,this.state.strokeWidth=t.strokeWidth,this.state.position.assign(t.coordinates),t.outEdges.forEach(e=>{const i=this.diagram.getClass(e.class);if(!i)throw new Error(`Unknown edge class '${e.class}' on gateway '${this.id}'.`);const s=new i(this,{from:this});this.diagram.getNodeById(e.toParentId)&&s.deserialize(e)})}serialize(){const{fill:t,id:e,orientation:i,radius:s,stroke:r,strokeWidth:a,state:{position:{raw:l}}}=this,c=this.outgoingEdges.map(h=>h.serialize());return{coordinates:l,fill:t,id:e,orientation:i,radius:s,stroke:r,strokeWidth:a,outEdges:c,class:this.constructor.name}}};o(Lr,"Gateway");let Nt=Lr;const qn=250;let en=(Pe=class extends ee{_gateways=new Map;state;classList=new Oi;edgesAsGateways=!1;requiredEdgePathType=null;edgeGatewayShape="rectangle";get selected(){return this.state.selected}get hovered(){return this.diagram?.hoveredNode===this}constructor(t,e){super(t),this.state={...e,box:e.box??new S([0,0,100,80]),hover:!1,zIndex:e.zIndex??100},this.classList.add("diagram__node"),f.makeObservable(this,{state:f.observable,hovered:f.computed,labelOffset:f.computed,selected:f.computed,_gateways:f.observable,setLabelOffset:f.action,setState:f.action}),this.initializeGateways()}canSelect(){return!this.state.selected&&this.state.selectable!==!1}canUnselect(){return!!this.state.selected}setDiagram(t){const e=this.diagram;e&&e!==t&&e.setNodeHover(this,!1),this.parent=t}setState(t,e){if(t==="hover"){this.setHovered(e===!0);return}this.state[t]=e}setHovered(t){this.diagram?.setNodeHover(this,t)}initializeGateways(){this._gateways.set("left",new Nt(this,{maxIncomingConnections:1/0,maxOutgoingConnections:1/0,id:"left",orientation:"left",position:new y([0,.5])})),this._gateways.set("right",new Nt(this,{maxIncomingConnections:1/0,maxOutgoingConnections:1/0,id:"right",orientation:"right",position:new y([1,.5])})),this._gateways.set("up",new Nt(this,{maxIncomingConnections:1/0,maxOutgoingConnections:1/0,id:"up",orientation:"up",position:new y([.5,0])})),this._gateways.set("down",new Nt(this,{maxIncomingConnections:1/0,maxOutgoingConnections:1/0,id:"down",orientation:"down",position:new y([.5,1])}))}get box(){return this.state.box.copy()}get coordinates(){return this.box.coordinates}displace(t){this.state.box.sum([...t.raw,0,0])}get id(){return this.state.id}get labelOffset(){const t=this.state.labelOffset;return!Array.isArray(t)||t.length!==2||!Number.isFinite(t[0])||!Number.isFinite(t[1])?new y:new y(t)}setLabelOffset(t){const e=t instanceof y?t:new y(t);this.state.labelOffset=[Math.max(-qn,Math.min(qn,e.x)),Math.max(-qn,Math.min(qn,e.y))]}get gateways(){return[...this._gateways.values()]}dragEventMouseStartPosition=null;dragEventStartPosition=null;getGateway(t){return this._gateways.get(t)}boundaryPoint(t,e){const i=this.box,s=i.middle,r=Math.max(i.width/2,.001),a=Math.max(i.height/2,.001);let l=t.x-s.x,c=t.y-s.y;if(Math.abs(l)<.001&&Math.abs(c)<.001&&(l=r,c=0),this.edgeGatewayShape==="ellipse"){const u=1/Math.sqrt(l*l/(r*r)+c*c/(a*a));return new y([s.x+l*u,s.y+c*u])}if(this.edgeGatewayShape==="diamond"){const u=1/(Math.abs(l)/r+Math.abs(c)/a);return new y([s.x+l*u,s.y+c*u])}if(!e||!i.collides(t)){const u=1/Math.max(Math.abs(l)/r,Math.abs(c)/a);return new y([s.x+l*u,s.y+c*u])}const h=[{value:Math.abs(t.x-i.x),point:[i.x,t.y]},{value:Math.abs(t.x-(i.x+i.width)),point:[i.x+i.width,t.y]},{value:Math.abs(t.y-i.y),point:[t.x,i.y]},{value:Math.abs(t.y-(i.y+i.height)),point:[t.x,i.y+i.height]}];return new y(h.reduce((u,g)=>g.value<u.value?g:u).point)}anchorForBoundaryPoint(t){const e=this.box,i=e.middle,s=(t.x-i.x)/Math.max(e.width/2,.001),r=(t.y-i.y)/Math.max(e.height/2,.001),a=Math.abs(s)>=Math.abs(r)?s>=0?"right":"left":r>=0?"down":"up",l=this.getGateway(a)??this.getGateway("center")??this.gateways[0];if(!l)throw new Error(`Node ${this.id} has no gateway for a boundary anchor`);const c=new y([(t.x-e.x)/Math.max(e.width,.001),(t.y-e.y)/Math.max(e.height,.001)]);return{gateway:l,point:t,relativePosition:c,displacement:t.copy().substract(l.coordinates)}}findFixedConnectionAnchor(t){return this.anchorForBoundaryPoint(this.boundaryPoint(t,!0))}findAxisAlignedConnectionAnchor(t,e){const i=this.box,s=i.middle,r=Math.max(i.width/2,.001),a=Math.max(i.height/2,.001),l=e==="horizontal",c=l?(t.y-s.y)/a:(t.x-s.x)/r;if(Math.abs(c)>1)return null;let h=l?r:a;this.edgeGatewayShape==="ellipse"?h*=Math.sqrt(Math.max(0,1-c**2)):this.edgeGatewayShape==="diamond"&&(h*=1-Math.abs(c));const u=l?t.x<=s.x?-1:1:t.y<=s.y?-1:1,g=l?new y([s.x+u*h,t.y]):new y([t.x,s.y+u*h]);return this.anchorForBoundaryPoint(g)}findAutomaticConnectionAnchor(t){return this.anchorForBoundaryPoint(this.boundaryPoint(t,!1))}findAutomaticGatewayAnchor(t){const e=this.gateways.filter(s=>{const r=s.relativePosition;return r.x<=0||r.x>=1||r.y<=0||r.y>=1}),i=(e.length?e:this.gateways).map(s=>({candidate:s,distance:s.coordinates.distance(t)})).sort((s,r)=>s.distance-r.distance)[0]?.candidate;return i?{gateway:i,point:i.coordinates.copy(),relativePosition:i.relativePosition,displacement:new y}:this.findAutomaticConnectionAnchor(t)}findRelativeConnectionAnchor(t){const e=this.box,i=new y([e.x+t.x*e.width,e.y+t.y*e.height]);return this.anchorForBoundaryPoint(this.boundaryPoint(i,!0))}usesAutomaticConnectionPoint(t){if(!this.edgesAsGateways||!this.box.collides(t))return!1;const e=this.boundaryPoint(t,!0),i=Math.min(24,Math.min(this.box.width,this.box.height)/4);return t.distance(e)>i}get connectionBoundaryPath(){const t=this.box;if(this.edgeGatewayShape==="ellipse"){const e=t.width/2,i=t.y+t.height/2;return`M ${t.x} ${i} A ${e} ${t.height/2} 0 1 0 ${t.x+t.width} ${i} A ${e} ${t.height/2} 0 1 0 ${t.x} ${i}`}return this.edgeGatewayShape==="diamond"?`M ${t.x+t.width/2} ${t.y} L ${t.x+t.width} ${t.y+t.height/2} L ${t.x+t.width/2} ${t.y+t.height} L ${t.x} ${t.y+t.height/2} Z`:`M ${t.x} ${t.y} H ${t.x+t.width} V ${t.y+t.height} H ${t.x} Z`}setDimentions(t){this.state.box.assignDimensions(t)}updateConnectedEdges(){const t=new Set;for(const e of this._gateways.values())e.incomingEdges.forEach(i=>t.add(i)),e.outgoingEdges.forEach(i=>t.add(i));t.forEach(e=>e.from.recomputeConnectedEdge(e,"from"))}setPosition(t,e){const i=new S(this.state.box.raw,!1);this.state.box.assignCoordinates(t).bound(new S([0,0,...this.diagram.canvas.size.raw],!1)),e?.updateConnectedEdges!==!1&&i.substract(this.state.box).norm&&this.updateConnectedEdges()}deserialize(t){this.state.box.assign(t.box),this.state.id=t.id,this.state.label=t.label,this.state.movable=t.movable,this.state.selectable=t.selectable,this.state.fill=t.fill,this.state.labelFontSize=t.labelFontSize,this.setLabelOffset(t.labelOffset??[0,0]),this.state.stroke=t.stroke,this.state.strokewWidth=t.strokewWidth,t.gateways.forEach(e=>{const i=this._gateways.get(e.id)?.incomingEdges||[],s=this.diagram?.getClass(e.class);if(!s)throw new Error(`Unknown gateway class '${e.class}' on node '${this.id}'.`);const r=new s(this,{id:e.id});this._gateways.set(e.id,r);for(const a of i)a.setState("to",r),r.addIncomingEdge(a)}),t.gateways.forEach(e=>{this._gateways.get(e.id)?.deserialize(e)}),this._gateways.forEach(e=>e.outgoingEdges.forEach(i=>{this.diagram?.connectWithEdge(i.from,i.to,i)}))}serialize(){const{box:{raw:t},id:e,label:i,movable:s,selectable:r,fill:a,labelFontSize:l,labelOffset:c,selected:h,stroke:u,strokewWidth:g}=this.state,p=this.gateways.map(m=>m.serialize());return{box:t,id:e,label:i,movable:s,selectable:r,selected:h,gateways:p,fill:a,labelFontSize:l,labelOffset:c?[...c]:void 0,stroke:u,strokewWidth:g,class:this.constructor.name}}remapSerializedReferences(t,e){return t}RenderOverlay=null;RenderScreen=null},o(Pe,"Node"),Pe);const Or=class Or extends z{selectionMode="element";_selection=new Set;_edgesSelection=new Set;autopan=new kt(this.diagram);pointerPoint=null;endPoint=null;startPoint=null;copy(){const t=[],e=new Map,i=[];for(const s of this._selection){const r=me(this.diagram,"node",i);e.set(s.id,r),i.push(r)}for(const s of this._selection){const r=s.remapSerializedReferences(s.serialize(),e);r.id=e.get(r.id),r.gateways.forEach(a=>{a.outEdges.forEach(l=>{l.toParentId=e.get(l.toParentId)})}),t.push(r)}return JSON.stringify({nodes:t})}init(){f.makeObservable(this,{_edgesSelection:f.observable,_selection:f.observable,box:f.computed,clearSelection:f.action,endPoint:f.observable,selectEdge:f.action,selectedNodes:f.computed,selectedEdges:f.computed,selectionMode:f.observable,selectNode:f.action,startPoint:f.observable,toggleSelectionMode:f.action,unselectEdge:f.action,unselectNode:f.action,handleMouseUp:f.action}),this.diagram.onEvent(Bt,this.handleMouseDown.bind(this),this.diagram.priorities.Mouse_Down_Selector),this.diagram.onEvent(ge,t=>{f.runInAction(()=>this._selection.delete(t.node))}),this.diagram.onEvent(zn,t=>{f.runInAction(()=>this._edgesSelection.delete(t.edge))}),f.runInAction(()=>{for(const t of this.diagram.nodes)t.selected&&this._selection.add(t)})}toggleSelectionMode(t=this.selectionMode==="area"?"element":"area"){this.selectionMode=t}get selectedNodes(){return[...this._selection]}get selectedEdges(){return[...this._edgesSelection]}get box(){return!this.startPoint||!this.endPoint?new S:new S([...this.startPoint.raw,...this.endPoint.copy().substract(this.startPoint).raw])}clearSelection(t=()=>!0){for(const e of this._selection)t(e)&&this.unselectNode(e);for(const e of this._edgesSelection)this.unselectEdge(e)}selectEdge(t){this.emit(new $n(t,!0)).cancelled||(t.setState("selected",!0),this._edgesSelection.add(t))}selectNode(t){t.canSelect()&&!this.emit(new Ye(t,!0)).cancelled&&(t.setState("selected",!0),this._selection.add(t))}unselectEdge(t){this.emit(new $n(t,!1)).cancelled||(t.setState("selected",!1),this._edgesSelection.delete(t))}unselectNode(t){t.canUnselect()&&!this.emit(new Ye(t,!1)).cancelled&&(t.setState("selected",!1),this._selection.delete(t))}unbind=o(()=>{},"unbind");handleMouseDown=o(t=>{if(this.unbind(),t.originalEvent.button!==1)if(this.selectionMode==="area"){const e=new y(t.originalEvent);f.runInAction(()=>{this.startPoint=this.diagram.canvas.inverseFit(e)}),t.cancel(),this.unbind=Mt(Gt(this,ot,this.handleMouseUp),Gt(this,Rt,this.handleMouseMove),Jn(this.handleSelectionInterval.bind(this),30))}else{const e=t.edge,i=t.node,s=e?.state.selected??i?.selected;!t.ctrl&&!t.shift&&!s&&(e||i?this.clearSelection():t.originalEvent.button===0&&this.bindEmptyCanvasGesture(t)),e?this.selectEdge(e):i&&this.selectNode(i)}},"handleMouseDown");bindEmptyCanvasGesture(t){const e=new y(t.originalEvent);let i=!1;const s=o(a=>{i||=!new y(a.originalEvent).equals(e)},"handleMove"),r=o(()=>{const a=this.unbind;this.unbind=()=>{},a(),i||this.clearSelection()},"handleUp");this.unbind=Mt(Gt(this,Rt,s),Gt(this,ot,r))}handleMouseMove=o(t=>{f.runInAction(()=>{this.pointerPoint=new y(t.originalEvent)}),this.updateAreaSelection(!1)},"handleMouseMove");handleSelectionInterval(){this.updateAreaSelection(!0)}updateAreaSelection(t){if(!this.pointerPoint||!this.startPoint)return;const e=this.pointerPoint;t&&this.autopan.displace(e),f.runInAction(()=>{this.endPoint=this.diagram.canvas.inverseFit(e)});for(const i of this.diagram.nodes){i.box.collides(this.box)?this.selectNode(i):this.unselectNode(i);for(const s of i.gateways)for(const r of s.outgoingEdges)if(r.collides(this.box)){this.selectEdge(r);break}else this.unselectEdge(r)}}handleMouseUp=o(t=>{this.unbind(),this.endPoint=null,this.startPoint=null,this.pointerPoint=null},"handleMouseUp")};o(Or,"Selector");let B=Or;const zr=class zr extends z{hotkeys=[];isEditableTarget(t){return t instanceof HTMLElement?t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement||t instanceof HTMLButtonElement||t.isContentEditable:!1}shouldIgnoreHotkeys(t){return this.isEditableTarget(t.originalEvent.target)}get measurer(){return this.diagram.getExtension(Xe)}get selector(){return this.diagram.getExtension(B)}match(t,e){return!(e.ctrl!==void 0&&t.ctrl!==e.ctrl||e.shift!==void 0&&t.shift!==e.shift||e.alt!==void 0&&t.alt!==e.alt||e.code!==void 0&&t.code!==e.code)}init(){this.diagram.onEvent(te,async t=>{if(!this.shouldIgnoreHotkeys(t)&&!this.revertHotkey.has(t.code)){for(const e of this.hotkeys)if(this.match(t,e)&&(e.cb(t),!t.spreads))return;switch(t.code){case"Space":{const e=this.measurer.enabled,i=!e&&this.selector.selectionMode==="area";e||this.selector.toggleSelectionMode(i?"element":"area"),this.revertHotkey.set(t.code,()=>{e?this.measurer.toggle():this.selector.toggleSelectionMode(i?"area":"element")});break}case"KeyC":t.ctrl&&navigator.clipboard.writeText(this.selector.copy());break;case"KeyV":t.ctrl&&this.diagram.rules.allowEdition&&this.diagram.paste(await navigator.clipboard.readText());break;case"KeyM":this.selector.toggleSelectionMode("element");break;case"KeyS":t.ctrl?(t.originalEvent.preventDefault(),gc(this.diagram.export(),"diagram-save.json","application/json")):this.selector.toggleSelectionMode("area");break;case"KeyZ":t.ctrl&&this.diagram.rules.allowEdition&&this.diagram.getExtension(Ue).undo();break;case"KeyY":t.ctrl&&this.diagram.rules.allowEdition&&this.diagram.getExtension(Ue).redo();break;case"ControlLeft":case"ControlRight":t.cancel();{const e=this.diagram.getExtension(R),i=this.diagram.getExtension(Xt),s=this.diagram.getExtension(Ke),r=e?.enabled,a=i?.enabled,l=s?.enabled;e?.toggle(!r,!1),i?.toggle(!a,!1),s?.toggle(!l,!1),this.revertHotkey.set(t.code,()=>{r!==void 0&&e?.toggle(r,!1),a!==void 0&&i?.toggle(a,!1),l!==void 0&&s?.toggle(l,!1)})}break;case"Delete":{if(!this.diagram.rules.allowEdition)break;const e=this.diagram.getExtension(B);e.selectedNodes.forEach(i=>{this.diagram.delete(i)}),e.selectedEdges.forEach(i=>{this.diagram.disconnect(i)})}}}}),document.addEventListener("keyup",()=>{for(const t of this.revertHotkey.keys())this.revertHotkey.get(t)?.(),this.revertHotkey.delete(t)})}register(t){return this.hotkeys.push(t),()=>{this.hotkeys=this.hotkeys.filter(e=>e!==t)}}revertHotkey=new Map};o(zr,"Hotkeys");let Wi=zr;function Gt(n,t,e,i){if(n.diagram){const s=e.bind(n);return n.diagram.onEvent(t,s,i),()=>{n.diagram?.offEvent(t,s)}}throw new Error("Cannot bind to unexistent diagram")}o(Gt,"bindDiagram");function Y(n,t,e,i){const s=e.bind(n);return document.addEventListener(t,s,i),()=>{document.removeEventListener(t,s,i)}}o(Y,"bindDocument");function Jn(n,t){const e=setInterval(n,t);return()=>{clearInterval(e)}}o(Jn,"bindInterval");function Rc(n,t){const e=setTimeout(n,t);return()=>{clearTimeout(e)}}o(Rc,"bindTimeout");function Mt(...n){return()=>{n.forEach(t=>t())}}o(Mt,"bind");let Gc=(Ne=class extends ee{unbindDocumentEvents=[];mouseSessionStartedInFrame=!1;centerAnimationFrame=null;_displacement=new y([-5e3,-5e3]);_scale=1;gridSize=50;size=new y([1e6,1e6]);get scale(){return this._scale}element=null;get elementPosition(){if(!this.element)return new y([0,0]);const t=this.element.getBoundingClientRect();return new y([t.x,t.y])}get elementDimensions(){if(!this.element)return new S([0,0,0,0]);const t=this.element.getBoundingClientRect();return new S([t.x,t.y,t.width,t.height])}get displacement(){return this._displacement.copy()}get framePosition(){if(!this.element)return new y([0,0]);const t=this.element.parentElement.getBoundingClientRect();return new y([t.x,t.y])}get frameDimensions(){if(!this.element)return new S([0,0,0,0]);const t=this.element.parentElement.getBoundingClientRect();return new S([t.x,t.y,t.width,t.height])}constructor(t){super(t),f.makeObservable(this,{_scale:f.observable,setScale:f.action}),this.unbindDocumentEvents.push(Y(this,"click",this.handleClick),Y(this,"dblclick",this.handleDoubleClick),Y(this,"wheel",this.handleWheel),Y(this,"mouseup",this.handleMouseUp),Y(this,"mousedown",this.handleMouseDown),Y(this,"mousemove",this.handleMouseMove),Y(this,"keyup",this.handleKeyUp),Y(this,"keypress",this.handleKeyPress),Y(this,"keydown",this.handleKeyDown))}dispose(){this.cancelCenterAnimation();for(const t of this.unbindDocumentEvents.splice(0))t()}markMouseSessionStartedInFrame(){this.mouseSessionStartedInFrame=!0}get dragging(){return this._dragging}_dragging=!1;displacementStart=null;eventStart=null;bound(){const t=this.element?.parentElement?.getBoundingClientRect(),e=t?new y([t.width,t.height]).divide(this.scale):new y,i=new S([...this.size.copy().multiply(-1).raw,...e.raw]).multiply(.9);this._displacement.bound(i)}centerOnPoint(t,e=!1){const i=this.frameDimensions,s=new y([i.width/(2*this.scale)-t.x,i.height/(2*this.scale)-t.y]);if(!e||typeof requestAnimationFrame>"u"){this.setDisplacement(s);return}this.animateDisplacement(s)}animateDisplacement(t){this.cancelCenterAnimation();const e=this.displacement,i=t.copy(!1).substract(e);let s=null;const r=240,a=o(l=>{s??=l;const c=Math.min(1,(l-s)/r),h=1-(1-c)**3;this.applyDisplacement(e.copy(!1).sum(i.copy(!1).multiply(h))),c<1?this.centerAnimationFrame=requestAnimationFrame(a):this.centerAnimationFrame=null},"update");this.centerAnimationFrame=requestAnimationFrame(a)}cancelCenterAnimation(){this.centerAnimationFrame!==null&&(cancelAnimationFrame(this.centerAnimationFrame),this.centerAnimationFrame=null)}applyDisplacement(t){this._displacement.assign(t),this.bound(),this.setDisplacementStyles()}displace(t){this.cancelCenterAnimation(),this._displacement.sum(t);const e=this._displacement.copy();return this.bound(),this.setDisplacementStyles(),t.copy().substract(this._displacement.copy().substract(e))}setDisplacement(t){this.cancelCenterAnimation(),this.applyDisplacement(t)}setScale(t,e=new y([0,0])){this.cancelCenterAnimation();const i=this.inverseFit(e),s=i.copy(),r=this.displacement,a=Math.max(.3,Math.min(3,t));if(a!==this.scale){const l=i.copy().multiply(this.scale).sum(r.copy().multiply(this.scale)).substract(s.copy().multiply(a)).divide(a);this.emit(new Re(this,l.copy().substract(this.displacement),a,this.scale)).cancelled||(this._scale=a,this._displacement.assign(l),this.bound(),this.setDisplacementStyles())}}fit(t){return t instanceof y?this._displacement.copy().sum([t.x,t.y]).multiply(this.scale):t instanceof S?new S([...this._displacement.copy().sum([t.x,t.y]).multiply(this.scale).raw,...t.size.multiply(this.scale).raw]):t*this.scale}inverseFit(t){return t instanceof y?t.copy().substract(this.framePosition).divide(this.scale).substract([this._displacement.x,this._displacement.y]):t.copy().substract(this.framePosition.toDimensions(new y([0,0]))).divide(this.scale).substract([this._displacement.x,this._displacement.y,0,0])}getDisplacementStyles(){const t=this._displacement.copy(!1).multiply(this.scale);return{position:"relative",width:`${this.size.x}px`,height:`${this.size.y}px`,transform:`translate(${t.x}px, ${t.y}px) scale(${this.scale})`,transformOrigin:"0 0",willChange:"transform"}}setDisplacementStyles(t=this.element){if(t){const e=this._displacement.copy(!1).multiply(this.scale),i=t.parentElement;if(t.dataset.setStyles="true",t.style.position="relative",t.style.width=`${this.size.x}px`,t.style.height=`${this.size.y}px`,t.style.transform=`translate(${e.x}px, ${e.y}px) scale(${this.scale})`,t.style.transformOrigin="0 0",t.style.zoom="",t.style.willChange="transform",i){const s=this.gridSize*this.scale,r=s*10,l=(Math.max(.3,Math.min(1,this.scale))-.3)/.7;i.style.setProperty("--diagram-canvas-scale",String(this.scale)),i.style.setProperty("--diagram-canvas-translate-x",`${e.x}px`),i.style.setProperty("--diagram-canvas-translate-y",`${e.y}px`),i.style.setProperty("--diagram-grid-zoom-ratio",String(l)),i.style.setProperty("--diagram-grid-size",`${s}px`),i.style.setProperty("--diagram-major-grid-size",`${r}px`),i.style.setProperty("--diagram-grid-offset-x",`${e.x}px`),i.style.setProperty("--diagram-grid-offset-y",`${e.y}px`)}}}setGridSize(t){this.gridSize=t,this.setDisplacementStyles()}useRef=o(t=>{this.element=t,t instanceof HTMLElement&&this.setDisplacementStyles()},"useRef");isInsideFrameFromTarget(t){const e=this.element?.parentElement;return!!(e&&t instanceof Node&&(e===t||e.contains(t)))}isInsideFrameEvent(t){const e=this.element?.parentElement;if(!e||t.target instanceof globalThis.Element&&t.target.closest('.diagram__extension_ui, [data-diagram-interactive-ui="true"]'))return!1;const i=typeof t.composedPath=="function"?t.composedPath():[];if(i.length>0&&i.some(s=>s===e||s instanceof Node&&e.contains(s))||this.isInsideFrameFromTarget(t.target)||t.type==="wheel"&&e.matches(":hover"))return!0;if("clientX"in t&&"clientY"in t){const s=e.getBoundingClientRect(),r=Number(t.clientX),a=Number(t.clientY);return r>=s.left&&r<=s.right&&a>=s.top&&a<=s.bottom}return!1}handleMouseMove(t){if(!this.isInsideFrameEvent(t)&&!this.eventStart&&!this.mouseSessionStartedInFrame)return;if(!this.emit(new Rt(this,t)).cancelled&&this.displacementStart&&this.eventStart){const i=this.displacement.substract(new y(t));this.emit(new Pi(this,this.displacement,i)).cancelled||(this._dragging=!0,this._displacement.assign(this.displacementStart.copy().substract(this.eventStart.copy().substract([t.clientX,t.clientY]).divide(this.scale))),this.bound(),this.setDisplacementStyles())}}handleDoubleClick(t){this.isInsideFrameEvent(t)&&this.emit(new On(this,t))}handleClick(t){this.isInsideFrameEvent(t)&&this.emit(new Ln(this,t))}handleMouseUp(t){!this.isInsideFrameEvent(t)&&!this.eventStart&&!this.mouseSessionStartedInFrame||(this.emit(new ot(this,t)),this._dragging=!1,this.eventStart=null,this.mouseSessionStartedInFrame=!1)}handleMouseDown(t){if(!this.isInsideFrameEvent(t))return;if(this.mouseSessionStartedInFrame=!0,this.cancelCenterAnimation(),t.button===1){t.preventDefault(),this.displacementStart=this._displacement.copy(),this.eventStart=new y(t);return}!this.emit(new Bt(this,t)).cancelled&&t.button===0&&(this.displacementStart=this._displacement.copy(),this.eventStart=new y(t))}handleKeyDown(t){this.emit(new te(this,t))}handleKeyUp(t){this.emit(new He(this,t))}handleKeyPress(t){this.emit(new ji(this,t))}handleWheel(t){if(!this.isInsideFrameEvent(t))return;if(!this.emit(new Ii(this,t)).cancelled){const i=t.deltaY<0,s=Math.floor(this.scale*100)/100;this.setScale(this.scale-t.deltaY/(s>=.2&&i||s>.21?1e3:1e4),new y(t))}}},o(Ne,"Canvas"),Ne);const $r=class $r extends en{initializeGateways(){}};o($r,"TextNode");let Qn=$r;const Fr=class Fr extends z{creationMode="none";init(){this.diagram.onEvent(Ln,t=>{this.handleClick(t)}),f.makeObservable(this,{creationMode:f.observable})}getId(){let t=String(Date.now()),e=0;for(;this.diagram.getNodeById(t);)t=String(Date.now())+String(e++);return t}handleClick(t){if(!t.cancelled&&this.creationMode!=="none"&&(t.cancel(),this.creationMode==="text")){const e=this.diagram.add(new Qn(null,{id:this.getId(),label:"No label",box:new S([...this.diagram.canvas.inverseFit(new y(t.originalEvent)).raw,100,100])}));this.diagram.getExtension(B).selectNode(e)}f.runInAction(()=>{this.creationMode="none"})}};o(Fr,"Creator");let Yi=Fr;const Hr=class Hr extends z{dragThreshold=10;autopan=new kt(this.diagram);autopanReady=!0;dragStarted=!1;draggingLabel=null;primaryNodeId=null;groupedChildren=new Map;init(){this.diagram.onEvent(Bt,this.handleMouseDown.bind(this),this.diagram.priorities.Mouse_Down_Dragger),this.diagram.onEvent(ot,this.handleMouseUp.bind(this),this.diagram.priorities.Mouse_Up_Dragger),this.diagram.onEvent(Rt,this.handleMouseMove.bind(this),this.diagram.priorities.Mouse_Move_Selector-1),this.diagram.onEvent(Re,this.handleScale.bind(this),this.diagram.priorities.Scale_Dragger),this.diagram.onEvent(ge,t=>{this.draggingNodes.delete(t.node.id),this.draggingLabel?.node===t.node&&(this.draggingLabel=null)})}constructor(t){super(t)}draggingNodes=new Map;startPoint=new y;startPointScaled=new y;mousePoint=new y;unsubscribe=o(()=>{},"unsubscribe");startDrag(t,e=fe.getInstance().coordinates,i={}){this.draggingNodes.clear(),this.groupedChildren.clear(),this.draggingLabel=null,this.diagram.canvas.markMouseSessionStartedInFrame(),this.autopanReady=i.deferAutopanUntilSafe!==!0,this.dragStarted=i.startImmediately===!0,this.primaryNodeId=t.id,this.draggingNodes.set(t.id,{node:t,startPoint:t.coordinates.copy()}),this.mousePoint=e.copy(),this.startPoint=e.copy(),this.startPointScaled=this.diagram.canvas.inverseFit(this.startPoint),this.handleDragAction()}originalEvent=null;labelDragHandle(t){return t.originalEvent.target?.closest?.('[data-node-label-drag-handle="true"]')??null}createLabelDragState(t,e){if(!e)return null;const i=Number(e.dataset?.nodeLabelWidth),s=Number(e.dataset?.nodeLabelHeight),r=Number(e.dataset?.nodeLabelGap);return{gap:Number.isFinite(r)&&r>=0?r:5,labelSize:new y([Number.isFinite(i)&&i>0?i:t.box.width,Number.isFinite(s)&&s>0?s:t.box.height]),node:t,startOffset:t.labelOffset}}snapLabelOffset(t,e){const i=e.node.box,s=i.middle,r=i.width/2+e.gap+e.labelSize.x/2,a=i.height/2+e.gap+e.labelSize.y/2,l=s.copy().sum([0,a]),c=[[0,-1],[-1,0],[1,0],[0,1]].map(([g,p])=>s.copy().sum([g*r,p*a])),h=l.copy().sum(t),u=c.map(g=>({anchor:g,distance:g.distance(h)})).sort((g,p)=>g.distance-p.distance)[0];return u?u.anchor.copy().substract(l):t}handleMouseDown(t){this.originalEvent=t;const e=t.node;!t.cancelled&&e&&e.selected&&(t.cancel(),this.draggingNodes.clear(),this.groupedChildren.clear(),this.draggingLabel=this.createLabelDragState(e,this.labelDragHandle(t)),this.autopanReady=!0,this.dragStarted=!1,this.primaryNodeId=e.id,this.mousePoint=new y(t.originalEvent),this.startPoint=this.mousePoint.copy(),this.startPointScaled=this.diagram.canvas.inverseFit(this.mousePoint),this.handleDragAction())}handleMouseMove(t){this.mousePoint=new y(t.originalEvent)}handleDragAction(){this.unsubscribe(),this.unsubscribe=Mt(Gt(this,Re,({newScale:t,previousScale:e})=>{this.startPoint.divide(e).multiply(t)}),Jn(this.handleDragInterval.bind(this),30))}isFullyContained(t,e){return e.x>=t.x&&e.y>=t.y&&e.x+e.width<=t.x+t.width&&e.y+e.height<=t.y+t.height}collectConnectedEdges(t){const e=new Set;return t.forEach(i=>{i.gateways.forEach(s=>{s.incomingEdges.forEach(r=>e.add(r)),s.outgoingEdges.forEach(r=>e.add(r))})}),e}translateEdge(t,e){t.steps.forEach(i=>{i.sum(e)}),t.labels.forEach(i=>{i.position.sum(e)})}updateEdgesAfterBatchMove(t,e){const i=new Map,s=[];e.forEach(r=>{const a=t.get(r.id);if(!a)return;const l=r.coordinates.copy().substract(a);i.set(r.id,l),l.norm>0&&s.push(r)}),s.length&&this.collectConnectedEdges(s).forEach(r=>{const a=i.get(r.from.parent.id),l=i.get(r.to.parent.id);if(a&&l&&a.norm>0&&l.norm>0&&a.copy(!1).substract(l).norm<.001){this.translateEdge(r,a);return}r.from.recomputeConnectedEdge(r,"from")})}rigidSelectionDisplacement(t){const e=new Set(this.groupedChildren.keys()),i=t.filter(w=>!w.cancelled&&!e.has(w.node.id));if(i.length<2)return null;const s=i.find(w=>w.node.id===this.primaryNodeId)??i[0],r=[...i].sort((w,v)=>(ft.get(w,"x")??1/0)-(ft.get(v,"x")??1/0))[0],a=[...i].sort((w,v)=>(ft.get(w,"y")??1/0)-(ft.get(v,"y")??1/0))[0],l=ft.get(r,"x")===void 0?s:r,c=ft.get(a,"y")===void 0?s:a,h=this.draggingNodes.get(l.node.id)?.startPoint,u=this.draggingNodes.get(c.node.id)?.startPoint;if(!h||!u)return null;const g=new y([l.get().x-h.x,c.get().y-u.y]);let p=Number.NEGATIVE_INFINITY,m=Number.POSITIVE_INFINITY,b=Number.NEGATIVE_INFINITY,x=Number.POSITIVE_INFINITY;return i.forEach(w=>{const v=this.draggingNodes.get(w.node.id)?.startPoint;v&&(p=Math.max(p,-v.x),m=Math.min(m,this.diagram.canvas.size.x-v.x-w.node.box.width),b=Math.max(b,-v.y),x=Math.min(x,this.diagram.canvas.size.y-v.y-w.node.box.height))}),g.x=Math.min(m,Math.max(p,g.x)),g.y=Math.min(x,Math.max(b,g.y)),g}applyNodePositionProposals(t){const e=new Map(t.map(c=>[c.node.id,c])),i=new Set(this.groupedChildren.keys()),s=new Map,r=this.rigidSelectionDisplacement(t);t.forEach(c=>{!c.cancelled&&!i.has(c.node.id)&&s.set(c.node.id,c.node)}),this.groupedChildren.forEach((c,h)=>{const u=this.draggingNodes.get(h);u&&s.set(h,u.node)});const a=[...s.values()],l=new Map(a.map(c=>[c.id,c.coordinates.copy()]));t.forEach(c=>{if(!c.cancelled&&!i.has(c.node.id)){const h=this.draggingNodes.get(c.node.id)?.startPoint,u=r&&h?h.copy().sum(r):c.get().coordinates;c.node.setPosition(u,{updateConnectedEdges:!1})}}),this.groupedChildren.size&&this.groupedChildren.forEach((c,h)=>{const u=e.get(c),g=this.draggingNodes.get(h),p=this.draggingNodes.get(c);if(!g||!p)return;const b=(u?.cancelled?p.startPoint:u?.node.coordinates??p.startPoint).copy().substract(p.startPoint),x=g.startPoint.copy().sum(b);g.node.setPosition(x,{updateConnectedEdges:!1})}),this.updateEdgesAfterBatchMove(l,a)}includeGroupedChildren(){const t=[...this.draggingNodes.values()].filter(({node:i})=>i.state.groupChildren);if(!t.length)return;const e=new Set(this.draggingNodes.keys());this.diagram.nodes.forEach(i=>{if(e.has(i.id)||i.state.movable===!1)return;let s=null,r=Number.POSITIVE_INFINITY;const a=i.box;t.forEach(({node:l})=>{if(this.isFullyContained(l.box,a)){const c=l.box.width*l.box.height;c<r&&(r=c,s=l.id)}}),s!==null&&(this.draggingNodes.set(i.id,{node:i,startPoint:i.coordinates.copy()}),this.groupedChildren.set(i.id,s))})}handleDragInterval(){const t=this.mousePoint;if(this.draggingLabel){if(this.dragStarted||(this.dragStarted=t.copy().substract(this.startPoint).norm>this.dragThreshold),!this.dragStarted)return;const e=t.copy().substract(this.startPoint).divide(this.diagram.canvas.scale),i=this.draggingLabel.startOffset.copy().sum(e);this.draggingLabel.node.setLabelOffset(this.snapLabelOffset(i,this.draggingLabel));return}if(this.draggingNodes.size||(this.diagram.getExtension(B).selectedNodes.forEach(e=>{this.draggingNodes.set(e.id,{node:e,startPoint:e.coordinates.copy()})}),this.includeGroupedChildren(),this.draggingNodes.size||this.unsubscribe()),this.draggingNodes.size){if(this.dragStarted||(this.dragStarted=t.copy().substract(this.startPoint).norm>this.dragThreshold),!this.dragStarted)return;this.autopanReady||(this.autopanReady=this.pointerIsInsideSafeViewport(t)),this.autopanReady&&this.autopan.displace(t);const e=this.diagram.canvas.inverseFit(this.startPoint),i=this.startPointScaled.copy().substract(e),r=[...this.draggingNodes.values()].filter(({node:a})=>!this.groupedChildren.has(a.id)).sort((a,l)=>+(l.node.id===this.primaryNodeId)-+(a.node.id===this.primaryNodeId)).map(a=>new Ze(a.node,new S([...a.startPoint.copy().sum(t.copy().substract(this.startPoint).divide(this.diagram.canvas.scale).substract(i)).raw,...a.node.box.size.raw])));this.emit(new Et(this,r,this.originalEvent?.originalEvent)).cancelled||this.applyNodePositionProposals(r)}}handleMouseUp(){this.draggingNodes.clear(),this.groupedChildren.clear(),this.draggingLabel=null,this.autopanReady=!0,this.dragStarted=!1,this.primaryNodeId=null,this.unsubscribe()}pointerIsInsideSafeViewport(t){const e=this.diagram.canvas.frameDimensions,i=Math.min(kt.edgeThreshold,e.width/2),s=Math.min(kt.edgeThreshold,e.height/2);return t.x>=e.x+i&&t.x<=e.x+e.width-i&&t.y>=e.y+s&&t.y<=e.y+e.height-s}handleScale(t){this.draggingNodes.size}};o(Hr,"Dragger");let Zi=Hr;function nn(n,t){const e=Math.abs(t.x-n.x)>=Math.abs(t.y-n.y);return{axis:e?"horizontal":"vertical",origin:n,point:e?new y([t.x,n.y]):new y([n.x,t.y])}}o(nn,"cardinalAxisConstraint");const vo=22,ti=25;function _o(n,t,e){const i=n.nodes.filter(u=>u!==e.excludeNode).filter(u=>u.box.translate(new y([-ti,-ti])).sum([0,0,ti*2,ti*2]).collides(t));if(e.axisConstraint){const u=i.filter(p=>p.edgesAsGateways&&p.box.collides(t)).sort((p,m)=>p.box.middle.distance(t)-m.box.middle.distance(t)).map(p=>({anchor:p.findAxisAlignedConnectionAnchor(e.axisConstraint.origin,e.axisConstraint.axis),node:p})).find(p=>p.anchor);if(u?.anchor)return{anchor:u.anchor,anchorState:{mode:"fixed",position:u.anchor.relativePosition},node:u.node,snappedToGateway:!1};const g=i.flatMap(p=>p.gateways).map(p=>({distance:p.coordinates.distance(t),gateway:p})).filter(({gateway:p})=>e.axisConstraint.axis==="horizontal"?Math.abs(p.coordinates.y-e.axisConstraint.origin.y)<.001:Math.abs(p.coordinates.x-e.axisConstraint.origin.x)<.001).filter(p=>p.distance<=vo).sort((p,m)=>p.distance-m.distance)[0]?.gateway;if(g){const p={gateway:g,point:g.coordinates.copy(),relativePosition:g.relativePosition,displacement:new y};return{anchor:p,anchorState:{mode:"fixed",position:p.relativePosition},node:g.parent,snappedToGateway:!0}}return null}const s=i.flatMap(u=>u.gateways).map(u=>({gateway:u,distance:u.coordinates.distance(t)})).filter(u=>u.distance<=vo).sort((u,g)=>u.distance-g.distance)[0]?.gateway;if(s){const u={gateway:s,point:s.coordinates.copy(),relativePosition:s.relativePosition,displacement:new y};return{anchor:u,anchorState:{mode:"fixed",position:u.relativePosition},node:s.parent,snappedToGateway:!0}}const r=i.filter(u=>u.box.collides(t)).map(u=>u.getGateway("center")).find(Boolean);if(r)return{anchor:{gateway:r,point:r.coordinates.copy(),relativePosition:r.relativePosition,displacement:new y},anchorState:{mode:"fixed",position:r.relativePosition},node:r.parent,snappedToGateway:!0};const a=i.filter(u=>u.edgesAsGateways).sort((u,g)=>u.box.middle.distance(t)-g.box.middle.distance(t))[0];if(a){const u=a.usesAutomaticConnectionPoint(t),g=u?a.findAutomaticGatewayAnchor(e.oppositePoint):a.findFixedConnectionAnchor(t);return{anchor:g,anchorState:u?{mode:"automatic"}:{mode:"fixed",position:g.relativePosition},node:a,snappedToGateway:!1}}const l=i.flatMap(u=>u.gateways).map(u=>({gateway:u,distance:u.connectionDistance(t)})).filter(u=>Number.isFinite(u.distance)).sort((u,g)=>u.distance-g.distance)[0]?.gateway;if(!l)return null;const c=l.connectionDisplacement(t);return{anchor:{gateway:l,point:l.coordinates.copy().sum(c),relativePosition:l.relativePosition,displacement:c},anchorState:{mode:"fixed",position:l.relativePosition},node:l.parent,snappedToGateway:!0}}o(_o,"resolveConnectionCandidate");const sn=.001,Vt=3,Br=class Br extends z{autopan=new kt(this.diagram);drag=null;endpointDrag=null;uns=o(()=>{},"uns");endpointDragActive=!1;endpointCandidatePoint=null;init(){f.makeObservable(this,{endpointDragActive:f.observable,endpointCandidatePoint:f.observable}),document.addEventListener("mouseup",this.handleMouseUp.bind(this)),this.diagram.onEvent(Fn,this.startDrag.bind(this)),this.diagram.onEvent(Hn,this.startEndpointDrag.bind(this))}almostEqual(t,e){return Math.abs(t-e)<sn}pointMatches(t,e){return this.almostEqual(t.x,e.x)&&this.almostEqual(t.y,e.y)}axisAligned(t,e){return this.almostEqual(t.x,e.x)||this.almostEqual(t.y,e.y)}pointsNear(t,e,i=Vt){return Math.abs(t.x-e.x)<=i&&Math.abs(t.y-e.y)<=i}isActivePoint(t){return!!(this.drag&&(t===this.drag.pointA||t===this.drag.pointB))}getGridSize(){return this.diagram.getExtension(R)?.gridSize??50}orientationVector(t){switch(t){case"left":return{x:-1,y:0};case"right":return{x:1,y:0};case"up":return{x:0,y:-1};case"down":return{x:0,y:1}}}axisPerpendicularToGateway(t){return t==="left"||t==="right"?"y":"x"}expectedLeadPoint(t,e){const i=e==="from"?t.steps[0]:t.steps.at(-1),s=e==="from"?t.from.orientation:t.to.orientation,r=this.orientationVector(s),a=this.getGridSize();return new y([i.x+r.x*a,i.y+r.y*a])}leadMatchesGatewaySide(t,e,i){const s=this.orientationVector(i),r=(e.x-t.x)*s.x+(e.y-t.y)*s.y;return Math.abs(i==="left"||i==="right"?e.y-t.y:e.x-t.x)<=Vt&&r>sn&&r<=this.getGridSize()+Vt}endpointLeadPoint(t,e){const i=e==="from"?t.steps[0]:t.steps.at(-1),s=e==="from"?t.from.orientation:t.to.orientation,r=e==="from"?1:t.steps.length-2,a=t.steps[r];return a&&a.mode!=="manual"&&!this.isActivePoint(a)&&this.leadMatchesGatewaySide(i,a,s)?a:this.expectedLeadPoint(t,e)}ensureEndpointLeadPoint(t,e){const i=this.expectedLeadPoint(t,e),s=e==="from",r=s?1:t.steps.length-2,a=t.steps[r];if(a&&this.leadMatchesGatewaySide(s?t.steps[0]:t.steps.at(-1),a,s?t.from.orientation:t.to.orientation))return r;const l=new H(t,[i.x,i.y,"auto"]);return s?(t.state.steps.splice(1,0,l),1):(t.state.steps.splice(t.steps.length-1,0,l),t.steps.length-2)}ensureEndpointLeads(t){this.ensureEndpointLeadPoint(t,"from"),this.ensureEndpointLeadPoint(t,"to")}isProtectedLeadPoint(t,e){return e<=0||e>=t.steps.length-1?!1:e===1&&t.steps[e].mode!=="manual"&&this.leadMatchesGatewaySide(t.steps[0],t.steps[e],t.from.orientation)||e===t.steps.length-2&&t.steps[e].mode!=="manual"&&this.leadMatchesGatewaySide(t.steps.at(-1),t.steps[e],t.to.orientation)}segmentMovedAxis(t,e){return this.almostEqual(t.y,e.y)?"y":this.almostEqual(t.x,e.x)?"x":Math.abs(t.x-e.x)>=Math.abs(t.y-e.y)?"y":"x"}segmentDirection(t,e){return!this.axisAligned(t,e)||this.pointMatches(t,e)?null:this.almostEqual(t.y,e.y)?"horizontal":"vertical"}segmentIsParallelToDraggedAxis(t,e){return this.drag?this.drag.movedAxis==="y"?Math.abs(t.y-e.y)<=Vt:Math.abs(t.x-e.x)<=Vt:!1}perpendicularAxis(t){return t==="x"?"y":"x"}pointAxis(t,e){return e==="x"?t.x:t.y}setPointAxis(t,e,i){e==="x"?t.x=i:t.y=i}crossesStaticBoundary(t,e,i,s,r=Vt){const a=this.pointAxis(i,e),l=this.pointAxis(s,e);switch(t){case"right":case"down":return a<l-r;case"left":case"up":return a>l+r}}copyAsManual(t,e="both"){const i=t.copy();return i.parent=t.parent,i.addManualAxis(e),i}markManual(t,e="both"){t.mode!=="static"&&t.addManualAxis(e)}clampPointPastLead(t,e,i){switch(i){case"left":t.x=Math.min(t.x,e.x);break;case"right":t.x=Math.max(t.x,e.x);break;case"up":t.y=Math.min(t.y,e.y);break;case"down":t.y=Math.max(t.y,e.y);break}}movedAxisMatchesOrientation(t,e){return(e==="left"||e==="right")&&t==="x"||(e==="up"||e==="down")&&t==="y"}edgePointAt(t,e,i,s="auto"){return new H(t,[e,i,s])}guardCoordinate(t,e,i,s,r){const a=this.pointAxis(s,r)-this.pointAxis(i,r),l=Math.abs(a)>sn?Math.sign(a):1,c=e==="from"?t.from.parent.box:t.to.parent.box,h=r==="y"?c.height:c.width,u=Math.max(this.getGridSize(),h/2+this.getGridSize()/2);return this.pointAxis(i,r)+l*u}makeGuardCorner(t,e,i,s){const r=this.perpendicularAxis(s),a=this.edgePointAt(t,e.x,e.y,"auto");return this.setPointAxis(a,s,this.pointAxis(e,s)),this.setPointAxis(a,r,i),a}insertStaticBoundaryGuard(t){if(!this.drag)return!1;const{edge:e,movedAxis:i}=this.drag,s=t==="from"?e.from.orientation:e.to.orientation;if(!this.movedAxisMatchesOrientation(i,s))return!1;const r=e.state.steps,a=r.findIndex(C=>C===this.drag.pointA),l=r.findIndex(C=>C===this.drag.pointB);if(a<0||l<0)return!1;const c=t==="from"?a<=l?"pointA":"pointB":a>=l?"pointA":"pointB",h=c==="pointA"?"pointB":"pointA",u=this.drag[c],g=this.drag[h],p=r.findIndex(C=>C===u),m=this.endpointLeadPoint(e,t),b=t==="from"?1:r.length-2,x=r[b],w=!!(x&&this.pointMatches(x,m)),v=t==="from"?p===1:p===r.length-2,_=t==="from"?p===2&&w:p===r.length-3&&w,E=this.crossesStaticBoundary(s,i,u,m,Vt);if(p<0||!v&&!_||!E)return!1;const j=this.perpendicularAxis(i),P=this.guardCoordinate(e,t,m,g,j);this.setPointAxis(u,j,P),this.markManual(u,i),this.rebaseDraggedEndpointFixedAxis(c,u);const M=this.makeGuardCorner(e,m,P,i);if(t==="from"){if(v){const C=this.edgePointAt(e,m.x,m.y,"auto");r.splice(p,0,C,M)}else r.splice(p,0,M);return this.drag.sourceLeadAdjacent=!1,this.drag.staticBoundaryGuarded=!0,!0}if(v){const C=this.edgePointAt(e,m.x,m.y,"auto");r.splice(p+1,0,M,C)}else r.splice(p+1,0,M);return this.drag.targetLeadAdjacent=!1,this.drag.staticBoundaryGuarded=!0,!0}insertStaticBoundaryGuards(){const t=this.insertStaticBoundaryGuard("from"),e=this.insertStaticBoundaryGuard("to");return t||e}clampDraggedSegmentAgainstEndpointLeads(){if(!this.drag)return;const{edge:t,pointA:e,pointB:i,movedAxis:s,sourceLeadAdjacent:r,targetLeadAdjacent:a}=this.drag,l=t.steps.findIndex(h=>h===e),c=t.steps.findIndex(h=>h===i);if(this.movedAxisMatchesOrientation(s,t.from.orientation)){const u=t.steps[1]??this.expectedLeadPoint(t,"from");u&&(r||l>=0&&c>=0&&this.isProtectedLeadPoint(t,1)&&(l===2||c===2))&&(this.clampPointPastLead(e,u,t.from.orientation),this.clampPointPastLead(i,u,t.from.orientation))}if(this.movedAxisMatchesOrientation(s,t.to.orientation)){const h=t.steps.length-2,u=t.steps[h]??this.expectedLeadPoint(t,"to");u&&(a||l>=0&&c>=0&&this.isProtectedLeadPoint(t,h)&&(l===h-1||c===h-1))&&(this.clampPointPastLead(e,u,t.to.orientation),this.clampPointPastLead(i,u,t.to.orientation))}}mergeDraggedSegmentWithManualNeighbors(){if(!this.drag)return!1;let t=!1;const e=o((i,s)=>{if(!this.drag)return;const r=this.drag[i],a=this.drag.edge.state.steps,l=a.findIndex(u=>u===r),c=l+s;if(l<0||c<0||c>=a.length)return;const h=a[c];h.mode==="manual"&&this.pointsNear(r,h)&&(h.assign(r),a.splice(l,1),this.drag[i]=h,t=!0)},"mergePoint");return e("pointA",-1),e("pointB",1),t}rebaseDraggedEndpointFixedAxis(t,e){if(!this.drag)return;const i=t==="pointA"?this.drag.startPointA:this.drag.startPointB;this.drag.movedAxis==="y"?i.x=e.x:i.y=e.y}replaceDraggedEndpointWithProtectedLeadDuplicate(t,e,i){if(!this.drag)return;const s=this.drag[t],r=this.copyAsManual(e,this.drag.movedAxis);this.drag.movedAxis==="y"?r.y=s.y:r.x=s.x,this.drag.edge.state.steps[i]=r,this.drag[t]=r,this.rebaseDraggedEndpointFixedAxis(t,r)}absorbCollinearSegmentsIntoDraggedSegment(){if(!this.drag)return!1;let t=!1;const e=o((i,s)=>{if(!this.drag)return;const r=this.drag.edge.state.steps;for(;;){const a=this.drag[i],l=r.findIndex(u=>u===a),c=l+s;if(l<0||c<=0||c>=r.length-1)return;const h=r[c];if(!this.segmentIsParallelToDraggedAxis(a,h))return;if(this.isProtectedLeadPoint(this.drag.edge,c)){this.replaceDraggedEndpointWithProtectedLeadDuplicate(i,h,l),t=!0;return}if(h.mode==="static")return;r.splice(l,1),this.drag[i]=h,this.rebaseDraggedEndpointFixedAxis(i,h),t=!0}},"absorbSide");return e("pointA",-1),e("pointB",1),t}removeAdjacentDuplicates(t){if(!this.drag)return!1;const e=this.drag.edge.state.steps;let i=!1;for(let s=0;s<e.length-1;){const r=e[s],a=e[s+1];if(!this.pointsNear(r,a)){s+=1;continue}const l=this.isActivePoint(r)||r.mode==="static"||this.isProtectedLeadPoint(this.drag.edge,s)?s+1:s;if(l<=0||l>=e.length-1||t&&this.isActivePoint(e[l])){s+=1;continue}e.splice(l,1),i=!0,s=Math.max(0,s-1)}return i}coordinateAnchorForPair(t,e,i,s){return this.drag?t.mode==="static"?this.pointAxis(t,i):e.mode==="static"?this.pointAxis(e,i):this.isProtectedLeadPoint(this.drag.edge,s)?this.pointAxis(t,i):this.isProtectedLeadPoint(this.drag.edge,s+1)?this.pointAxis(e,i):this.isActivePoint(t)?this.pointAxis(t,i):this.isActivePoint(e)?this.pointAxis(e,i):t.mode==="manual"?this.pointAxis(t,i):e.mode==="manual"?this.pointAxis(e,i):this.pointAxis(t,i):this.pointAxis(t,i)}snapNearlyAlignedDraggedPairs(){if(!this.drag)return!1;const t=this.drag.edge.state.steps;let e=!1;for(let i=0;i<t.length-1;i++){const s=t[i],r=t[i+1];if(Math.abs(s.x-r.x)>sn&&Math.abs(s.x-r.x)<=Vt){const a=this.coordinateAnchorForPair(s,r,"x",i);s.x=a,r.x=a,e=!0}if(Math.abs(s.y-r.y)>sn&&Math.abs(s.y-r.y)<=Vt){const a=this.coordinateAnchorForPair(s,r,"y",i);s.y=a,r.y=a,e=!0}}return e}chooseOrthogonalCorner(t,e,i,s){const r=new H(this.drag?.edge??null,[e.x,t.y,"auto"]),a=new H(this.drag?.edge??null,[t.x,e.y,"auto"]),l=o(c=>{let h=0;const u=i?this.segmentDirection(i,t):null,g=this.segmentDirection(t,c),p=s?this.segmentDirection(e,s):null,m=this.segmentDirection(c,e);return u&&g!==u&&(h+=2),p&&m!==p&&(h+=2),this.axisAligned(i??t,c)&&(h+=1),this.axisAligned(c,s??e)&&(h+=1),h},"score");return l(r)>=l(a)?r:a}ensureOrthogonalAdjacency(){if(!this.drag)return!1;const t=this.drag.edge.state.steps;let e=!1;for(let i=0;i<t.length-1;i++){const s=t[i],r=t[i+1];if(this.axisAligned(s,r))continue;const a=i>0?t[i-1]:void 0,l=i+2<t.length?t[i+2]:void 0;t.splice(i+1,0,this.chooseOrthogonalCorner(s,r,a,l)),e=!0,i+=1}return e}normalizeDraggedEdge(){if(!this.drag)return!1;const t=this.snapNearlyAlignedDraggedPairs(),e=this.mergeDraggedSegmentWithManualNeighbors(),i=this.absorbCollinearSegmentsIntoDraggedSegment(),s=this.snapNearlyAlignedDraggedPairs(),r=this.ensureOrthogonalAdjacency(),a=this.snapNearlyAlignedDraggedPairs(),l=this.removeAdjacentDuplicates(!0),c=this.drag.edge.state.steps;return c.length>0&&(c[0].markStatic(),c.at(-1).markStatic()),t||e||i||s||r||a||l}finalizeDraggedEdge(){this.drag&&(this.normalizeDraggedEdge(),this.ensureOrthogonalAdjacency(),this.removeAdjacentDuplicates(!1),this.drag.staticBoundaryGuarded||this.drag.edge.setSteps(wo("orthogonal").route(this.diagram,this.drag.edge)))}prepareStraightLeadSegment(t,e){const i=this.copyAsManual(t.steps[1],e),s=this.copyAsManual(t.steps[2],e);return t.state.steps.splice(2,0,i,s),{pointA:i,pointB:s,movedAxis:e}}prepareSourceSegment(t){this.ensureEndpointLeads(t);const e=this.axisPerpendicularToGateway(t.from.orientation);if(t.steps.length===4&&this.isProtectedLeadPoint(t,1)&&this.isProtectedLeadPoint(t,2))return this.prepareStraightLeadSegment(t,e);const i=this.copyAsManual(t.steps[1],e);t.state.steps.splice(2,0,i);const s=t.steps[3];return s instanceof H?(this.markManual(s,e),{pointA:i,pointB:s,movedAxis:e}):null}prepareTargetSegment(t){this.ensureEndpointLeads(t);const e=this.axisPerpendicularToGateway(t.to.orientation);if(t.steps.length===4&&this.isProtectedLeadPoint(t,1)&&this.isProtectedLeadPoint(t,2))return this.prepareStraightLeadSegment(t,e);const i=t.steps.length-2,s=this.copyAsManual(t.steps[i],e);t.state.steps.splice(i,0,s);const r=t.steps[i-1];return r instanceof H?(this.markManual(r,e),{pointA:r,pointB:s,movedAxis:e}):null}prepareSegmentAfterProtectedSourceLead(t,e){const i=this.segmentMovedAxis(t.steps[e],t.steps[e+1]),s=this.copyAsManual(t.steps[e],i);t.state.steps.splice(e+1,0,s);const r=t.steps[e+2];return r instanceof H?(this.markManual(r,i),{pointA:s,pointB:r,movedAxis:i}):null}prepareSegmentBeforeProtectedTargetLead(t,e){const i=this.segmentMovedAxis(t.steps[e-1],t.steps[e]),s=this.copyAsManual(t.steps[e],i);t.state.steps.splice(e,0,s);const r=t.steps[e-1];return r instanceof H?(this.markManual(r,i),{pointA:r,pointB:s,movedAxis:i}):null}prepareInteriorSegment(t,e,i,s){this.ensureEndpointLeads(t);let r=t.steps.findIndex(u=>u===e),a=t.steps.findIndex(u=>u===i);if((r<0||a<0||Math.abs(r-a)!==1)&&(r=Math.max(0,Math.min(s,t.steps.length-2)),a=r+1),r>a&&([r,a]=[a,r]),r===0)return this.prepareSourceSegment(t);if(a===t.steps.length-1)return this.prepareTargetSegment(t);if(this.isProtectedLeadPoint(t,r))return this.prepareSegmentAfterProtectedSourceLead(t,r);if(this.isProtectedLeadPoint(t,a))return this.prepareSegmentBeforeProtectedTargetLead(t,a);const l=t.steps[r],c=t.steps[a],h=this.segmentMovedAxis(l,c);return this.markManual(l,h),this.markManual(c,h),{pointA:l,pointB:c,movedAxis:h}}restoreOriginalSteps(t,e){t.setSteps(e.map(i=>i.copy()))}startDrag(t){if(t.cancelled||t.src.pathType!=="orthogonal")return;t.stopImmediatePropagation(),this.uns();const e=t.src,i=e.steps.map(x=>x.copy()),s=e.steps.length-1,r=Number(t.midPoint.id),a=r===0,l=r===s-1,c=t.midPoint.points[0],h=t.midPoint.points[1],u=f.runInAction(()=>{e.state.dragging=!0;const x=a?this.prepareSourceSegment(e):l?this.prepareTargetSegment(e):this.prepareInteriorSegment(e,c,h,r);return x||(e.state.dragging=!1),x});if(!u)return;const g=e.steps.findIndex(x=>x===u.pointA),p=e.steps.findIndex(x=>x===u.pointB),m=g===2||p===2,b=g===e.steps.length-3||p===e.steps.length-3;this.drag={edge:e,midpoint:t.midPoint,pointA:u.pointA,pointB:u.pointB,movedAxis:u.movedAxis,startMouseCanvas:this.diagram.canvas.inverseFit(new y(t)),startPointA:u.pointA.copy().nonObserved,startPointB:u.pointB.copy().nonObserved,originalSteps:i,sourceLeadAdjacent:m,targetLeadAdjacent:b,staticBoundaryGuarded:!1,changed:!1},this.uns=Mt(Y(this,"mousemove",this.handleMouseMove),Y(this,"pointermove",this.handleMouseMove))}startEndpointDrag(t){if(t.cancelled)return;t.stopImmediatePropagation(),this.uns(),f.runInAction(()=>{t.src.state.dragging=!0}),this.drag=null,this.endpointDragActive=!0,this.endpointCandidatePoint=null;const e=t.src.steps[0],i=t.src.steps.at(-1),s=t.src.from.parent.box,r=t.src.to.parent.box;this.endpointDrag={edge:t.src,endpoint:t.endpoint,originalStart:{gateway:t.src.from,point:e.copy(),displacement:e.copy().substract(t.src.from.coordinates),relativePosition:new y([(e.x-s.x)/Math.max(s.width,.001),(e.y-s.y)/Math.max(s.height,.001)])},originalEnd:{gateway:t.src.to,point:i.copy(),displacement:i.copy().substract(t.src.to.coordinates),relativePosition:new y([(i.x-r.x)/Math.max(r.width,.001),(i.y-r.y)/Math.max(r.height,.001)])},originalStartState:{mode:t.src.startAnchor.mode,position:t.src.startAnchor.position?.copy()},originalEndState:{mode:t.src.endAnchor.mode,position:t.src.endAnchor.position?.copy()},candidate:null},this.uns=Mt(Y(this,"mousemove",this.handleMouseMove),Y(this,"pointermove",this.handleMouseMove))}restoreEndpointDrag(){if(!this.endpointDrag)return;const t=this.endpointDrag,e=t.endpoint==="from"?t.originalStart:t.originalEnd,i=t.endpoint==="from"?t.originalStartState:t.originalEndState;t.edge.setResolvedEndpoint(t.endpoint,e,i,!0)}handleEndpointMouseMove(t){if(!this.endpointDrag)return;const{edge:e,endpoint:i}=this.endpointDrag,s=this.diagram.canvas.inverseFit(new y(t)),r=i==="from"?e.to.parent:e.from.parent,a=i==="from"?e.steps.at(-1):e.steps[0],l=t.shiftKey?nn(a,s):null,c=l?.point??s,h=_o(this.diagram,c,{axisConstraint:l?{axis:l.axis,origin:l.origin}:void 0,excludeNode:r,oppositePoint:r.box.middle});if(!h){this.endpointDrag.candidate=null,this.endpointCandidatePoint=null,this.restoreEndpointDrag();return}const u=i==="from"?h.anchor.gateway:e.from,g=i==="to"?h.anchor.gateway:e.to;if(!u.canStartConnection(g,e)||!g.canConnect(u,e)){this.endpointDrag.candidate=null,this.endpointCandidatePoint=null,this.restoreEndpointDrag();return}this.endpointDrag.candidate=h,this.endpointCandidatePoint=h.anchor.point,f.runInAction(()=>{e.setResolvedEndpoint(i,h.anchor,h.anchorState,!0)})}moveDraggedSegment(t){if(!this.drag)return;const{pointA:e,pointB:i}=this.drag,r=this.diagram.canvas.inverseFit(new y(t)).nonObserved.substract(this.drag.startMouseCanvas);this.drag.movedAxis==="x"?r.y=0:r.x=0,f.runInAction(()=>{if(!this.drag)return;e.assign(this.drag.startPointA.copy().sum(r)),i.assign(this.drag.startPointB.copy().sum(r));const a=[new Bn(e,this.drag.movedAxis),new Bn(i,this.drag.movedAxis)];this.emit(new Rn(this,a,this.drag.movedAxis,t));for(const u of a)u.point.assign(u.get());const l=this.insertStaticBoundaryGuards();this.clampDraggedSegmentAgainstEndpointLeads();const c=this.normalizeDraggedEdge();(l||c||!this.pointMatches(this.drag.pointA,this.drag.startPointA)||!this.pointMatches(this.drag.pointB,this.drag.startPointB))&&(this.drag.changed=!0)})}handleMouseMove(t){if((t.type==="pointermove"||typeof PointerEvent>"u")&&this.autopan.displace(new y(t)),this.endpointDrag){this.handleEndpointMouseMove(t);return}this.moveDraggedSegment(t)}handleMouseUp(){!this.drag&&!this.endpointDrag||(f.runInAction(()=>{if(this.drag&&(this.drag.changed?this.finalizeDraggedEdge():this.restoreOriginalSteps(this.drag.edge,this.drag.originalSteps),this.drag.edge.state.dragging=!1),this.endpointDrag){const{edge:t,candidate:e}=this.endpointDrag;(!e||this.emit(new Ve(this,t.from.parent,t.to.parent,t)).cancelled)&&this.restoreEndpointDrag(),t.state.dragging=!1,this.endpointDragActive=!1,this.endpointCandidatePoint=null}this.drag=null,this.endpointDrag=null}),this.uns())}};o(Br,"EdgesDragger");let we=Br;const Rr=class Rr extends z{proposals=[];snapDistance=10;clear(){this.proposals=[]}init(){f.makeObservable(this,{clear:f.action,proposals:f.observable})}align(t,e,i){if(!this.enabled||!this.diagram.getExtension(Xt).enabled)return this.clear(),i;const s=e.size,r=5,a=this.snapDistance;let l=i.x,c=i.y;const h={from:i.copy(),id:"",to:i.copy()};let u={distance:Number.POSITIVE_INFINITY,guide:h,target:i.x},g={distance:Number.POSITIVE_INFINITY,guide:h,target:i.y};const p=o((x,w)=>{const v=Math.abs(i.x-x);v<=a&&v<u.distance&&(u={distance:v,guide:w,target:x})},"chooseX"),m=o((x,w)=>{const v=Math.abs(i.y-x);v<=a&&v<g.distance&&(g={distance:v,guide:w,target:x})},"chooseY");for(const x of this.diagram.edges.flatMap(w=>w.labels)){if(x===e)continue;const w=x.position.x+x.size.width/2,v=x.position.y+x.size.height/2,_=x.position.y+x.size.height,E=x.position.x+x.size.width,j=Math.min(i.y,x.position.y),P=Math.max(i.y+s.height,_),M=Math.min(i.x,x.position.x),C=Math.max(i.x+s.width,E);p(x.position.x,{from:new y([x.position.x,j]),id:`label-left-${x.id}`,to:new y([x.position.x,P])}),p(E-s.width,{from:new y([E,j]),id:`label-right-${x.id}`,to:new y([E,P])}),p(w-s.width/2,{from:new y([w,j]),id:`label-center-x-${x.id}`,to:new y([w,P])}),m(x.position.y,{from:new y([M,x.position.y]),id:`label-top-${x.id}`,to:new y([C,x.position.y])}),m(_-s.height,{from:new y([M,_]),id:`label-bottom-${x.id}`,to:new y([C,_])}),m(v-s.height/2,{from:new y([M,v]),id:`label-center-y-${x.id}`,to:new y([C,v])})}Number.isFinite(u.distance)&&(l=u.target),Number.isFinite(g.distance)&&(c=g.target);for(let x=0;x<t.steps.length-1;x+=1){const w=t.steps[x],v=t.steps[x+1],_=Math.abs(w.x-v.x)<.001,E=Math.abs(w.y-v.y)<.001;if(_&&c+s.height>=Math.min(w.y,v.y)-a&&c<=Math.max(w.y,v.y)+a){const j=Math.min(w.y,v.y),P=Math.max(w.y,v.y);p(w.x+r,{from:new y([w.x+r,j]),id:`edge-left-${x}`,to:new y([w.x+r,P])}),p(w.x-r-s.width,{from:new y([w.x-r,j]),id:`edge-right-${x}`,to:new y([w.x-r,P])})}if(E&&l+s.width>=Math.min(w.x,v.x)-a&&l<=Math.max(w.x,v.x)+a){const j=Math.min(w.x,v.x),P=Math.max(w.x,v.x);m(w.y+r,{from:new y([j,w.y+r]),id:`edge-top-${x}`,to:new y([P,w.y+r])}),m(w.y-r-s.height,{from:new y([j,w.y-r]),id:`edge-bottom-${x}`,to:new y([P,w.y-r])})}}Number.isFinite(u.distance)&&(l=u.target),Number.isFinite(g.distance)&&(c=g.target);const b=[u,g].filter(x=>Number.isFinite(x.distance)).map(x=>x.guide);return f.runInAction(()=>{this.proposals=b}),new y([l,c])}};o(Rr,"LabelsAligner");let Tt=Rr;function Vc(n,t,e){switch(e){case"down":return t.copy().sum([0,n]);case"left":return t.copy().sum([-n,0]);case"up":return t.copy().sum([0,-n]);case"right":return t.copy().sum([+n,0])}}o(Vc,"stepFromGateway");const Wc=5,Gr=class Gr extends z{hasRoutedPreview=!1;previewRequestVersion=0;previewRafId=null;init(){f.makeObservable(this,{_arrowSteps:f.observable,arrowTo:f.observable,candidateGateway:f.observable,candidateAnchor:f.observable,startConnectionFrom:f.action,startConnectionFromNode:f.action,handleGatewayMouseDown:f.action,handleMouseMove:f.action,handlePendingMouseMove:f.action,startGateway:f.observable,handleMouseUp:f.action}),this.diagram.onEvent(Bt,this.handleGatewayMouseDown.bind(this),this.diagram.priorities.Mouse_Down_Node)}arrowTo=null;startGateway=null;startAnchor=null;startAnchorMode="fixed";axisConstrained=!1;candidateGateway=null;candidateAnchor=null;candidateAnchorState=null;previewRouter=new Xn;pendingConnection=null;unbindPendingConnection=o(()=>{},"unbindPendingConnection");_arrowSteps=[];get arrowSteps(){return this._arrowSteps}get previewPathType(){const t=this.startGateway?.parent.requiredEdgePathType==="straight",e=this.candidateGateway?.parent.requiredEdgePathType==="straight";return t||e?"straight":"orthogonal"}get candidatePoint(){return this.candidateAnchor?.point??null}get snap(){return this.diagram.getExtension(R)}resolveStartAnchor(t,e=!1){return this.startGateway?this.startAnchorMode==="automatic"&&!e?this.startGateway.parent.findAutomaticGatewayAnchor(t):this.startAnchor:null}calculateArrowSteps(){if(!this.startGateway||!this.arrowTo)return;const t=this.startGateway,e=this.candidateGateway,i=this.candidateAnchor,s=this.arrowTo.copy(),r=this.previewRequestVersion;if(!s||e&&!i){f.runInAction(()=>{this._arrowSteps=[]});return}try{const a=this.diagram.canvas.inverseFit(s),l=this.axisConstrained&&this.startAnchor?nn(this.startAnchor.point,a).point:a,c=this.snap.gridSize/2,h=l.copy().divide(c).round.multiply(c);if(this.axisConstrained&&this.startAnchor){const p=nn(this.startAnchor.point,l);p.axis==="horizontal"?h.y=p.point.y:h.x=p.point.x}const u=this.resolveStartAnchor(e?.parent.box.middle??l,this.axisConstrained);if(!u)return;let g=[];if(e)g=this.previewRouter.findRouteBetween(this.diagram,u.gateway,i.gateway,u.displacement,i.displacement);else{const p=new en(null,{id:"fake",label:"",box:new S([...h.raw,0,0])}),m=u.gateway.coordinates.substract(p.getGateway("down").coordinates).x,b=u.gateway.coordinates.substract(p.getGateway("down").coordinates).y,x=Math.abs(m)>Math.abs(b)?m>=0?"right":"left":b>=0?"down":"up";g=this.previewRouter.findRouteBetween(this.diagram,u.gateway,p.getGateway(x),u.displacement)}f.runInAction(()=>{this.startGateway===t&&r===this.previewRequestVersion&&(this._arrowSteps=g.map(p=>new y([p.x,p.y])),this.hasRoutedPreview=this._arrowSteps.length>1)})}catch{}}orthogonalMousePreview(t,e){const i=this.snap.gridSize/2,s=e.copy().divide(i).round.multiply(i);if(this.axisConstrained&&this.startAnchor){const p=nn(this.startAnchor.point,e);p.axis==="horizontal"?s.y=p.point.y:s.x=p.point.x}const r=t.point.copy(),a=Vc(this.snap.gridSize,r,t.gateway.orientation),l=[r,a];if(Math.abs(a.x-s.x)<.001||Math.abs(a.y-s.y)<.001)return l.push(s),this.compactPreviewPoints(l);const c=new y([a.x,s.y]),h=new y([s.x,a.y]),u=Math.abs(s.x-a.x),g=Math.abs(s.y-a.y);return l.push(u>=g?h:c,s),this.compactPreviewPoints(l)}compactPreviewPoints(t){const e=[];for(const i of t){const s=e.at(-1);if(!(s&&Math.abs(s.x-i.x)<.001&&Math.abs(s.y-i.y)<.001))for(e.push(i);e.length>=3;){const r=e.at(-3),a=e.at(-2),l=e.at(-1),c=Math.abs(r.x-a.x)<.001&&Math.abs(a.x-l.x)<.001,h=Math.abs(r.y-a.y)<.001&&Math.abs(a.y-l.y)<.001;if(c||h)e.splice(e.length-2,1);else break}}return e}cancelScheduledPreview(){this.previewRafId!==null&&(cancelAnimationFrame(this.previewRafId),this.previewRafId=null)}scheduleCalculateArrowSteps(){this.previewRafId===null&&(this.previewRafId=requestAnimationFrame(()=>{this.previewRafId=null,this.calculateArrowSteps()}))}u=o(()=>{},"u");connectionAnchorFromEvent(t){const e=t.originalEvent.target;if(!e||typeof e.closest!="function")return null;const i=e.closest("[data-gateway-parent]"),s=this.diagram.getNodeById(i?.dataset.gatewayParent??"");if(!i||!s)return null;const r=i.dataset.gatewayId,a=r?s.gateways.find(c=>c.id===r):null;if(a)return{gateway:a,point:a.coordinates.copy(),relativePosition:a.relativePosition,displacement:new y};const l=this.diagram.canvas.inverseFit(new y(t));return s.findFixedConnectionAnchor(l)}handleGatewayMouseDown(t){if(t.cancelled||t.originalEvent.button!==0||this.connecting)return;const e=this.connectionAnchorFromEvent(t);e&&(this.cancelPendingConnection(),this.pendingConnection={anchor:e,pointer:new y(t)},t.cancel(),this.unbindPendingConnection=Mt(Gt(this,Rt,this.handlePendingMouseMove),Gt(this,ot,this.cancelPendingConnection)))}handlePendingMouseMove(t){const e=this.pendingConnection;!e||e.pointer.distance(new y(t))<Wc||(this.cancelPendingConnection(),this.startAnchorMode="fixed",this.beginConnection(e.anchor,t)&&this.handleMouseMove(t))}cancelPendingConnection(){this.pendingConnection=null,this.unbindPendingConnection(),this.unbindPendingConnection=()=>{}}startConnectionFrom(t,e){this.startAnchorMode="fixed";const i={gateway:t,point:t.coordinates.copy(),relativePosition:t.relativePosition,displacement:new y};this.beginConnection(i,e)}startConnectionFromNode(t,e,i="fixed"){const s=this.diagram.canvas.inverseFit(new y(e));this.startAnchorMode=i,this.beginConnection(t.findFixedConnectionAnchor(s),e)}get connecting(){return this.startGateway!==null}beginConnection(t,e){const i=t.gateway;if(this.emit(new Ti(this,i.parent)).cancelled)return!1;const s="originalEvent"in e?e.originalEvent:e.nativeEvent;return"originalEvent"in e&&e.stopImmediatePropagation(),s.stopImmediatePropagation?.(),this.diagram.canvas.markMouseSessionStartedInFrame(),this.startGateway=i,this.startAnchor=t,this.arrowTo=new y(s),this.hasRoutedPreview=!1,this.axisConstrained=!1,this.previewRequestVersion=0,this._arrowSteps=[t.point.copy(),t.point.copy()],this.u(),this.u=Mt(Gt(this,Rt,this.handleMouseMove),Gt(this,ot,this.handleMouseUp)),!0}handleMouseMove(t){this.previewRequestVersion+=1;const e=this.diagram.canvas.frameDimensions;this.arrowTo=new y(t);const i=this.arrowTo.copy().substract(this.diagram.canvas.framePosition),s=new y([0,0]);i.x<100?s.sum([(100-i.x)*.1,0]):i.x>e.width-100?s.substract([(100-Math.abs(i.x-e.width))*.1,0]):i.y<100?s.sum([0,(100-i.y)*.1]):i.y>e.height-100&&s.substract([0,(100-Math.abs(i.y-e.height))*.1]),s.norm>0&&this.diagram.canvas.displace(s);const r=this.diagram.canvas.inverseFit(this.arrowTo),a=t.shift&&this.startAnchor?nn(this.startAnchor.point,r):null;this.axisConstrained=!!a;const l=a?.point??r,c=_o(this.diagram,l,{axisConstraint:a?{axis:a.axis,origin:a.origin}:void 0,excludeNode:this.startGateway?.parent,oppositePoint:this.startGateway.parent.box.middle});if(c?(this.candidateGateway=c.anchor.gateway,this.candidateAnchor=c.anchor,this.candidateAnchorState=c.anchorState):(this.candidateGateway=null,this.candidateAnchor=null,this.candidateAnchorState=null),!this.candidateGateway){this.hasRoutedPreview=!1;const h=this.resolveStartAnchor(l,this.axisConstrained);this._arrowSteps=h?this.orthogonalMousePreview(h,l):[],this.scheduleCalculateArrowSteps();return}this.calculateArrowSteps()}handleMouseUp(){try{const t=this.candidateAnchor,e=this.candidateAnchorState,i=this.candidateGateway?this.resolveStartAnchor(this.candidateGateway.parent.box.middle,this.axisConstrained):null;this.candidateGateway&&t&&e&&i&&this.candidateGateway.canConnect(i.gateway)&&i.gateway.canStartConnection(this.candidateGateway)&&(this.emit(new Ve(this,i.gateway.parent,this.candidateGateway.parent)).cancelled||(this._arrowSteps=[],this.diagram.connect(i.gateway,this.candidateGateway,{fromDisplacement:i.displacement,startAnchor:this.startAnchorMode==="automatic"&&!this.axisConstrained?{mode:"automatic"}:{mode:"fixed",position:i.relativePosition},toDisplacement:t.displacement,endAnchor:e})))}finally{this.cancelPendingConnection(),this._arrowSteps=[],this.hasRoutedPreview=!1,this.startGateway=null,this.startAnchor=null,this.startAnchorMode="fixed",this.axisConstrained=!1,this.arrowTo=null,this.candidateGateway=null,this.candidateAnchor=null,this.candidateAnchorState=null,this.previewRequestVersion=0,this.cancelScheduledPreview(),this.u()}}};o(Gr,"NodesConnector");let ve=Gr;const Vr=class Vr extends z{init(){this.diagram.onEvent(Ye,()=>{},this.diagram.priorities.Node_Selection_Nodes_Resizer)}};o(Vr,"NodesResizer");let Ki=Vr,Eo=(Te=class extends z{grid=null;points=null;highlighted=new Set;init(){f.makeObservable(this,{grid:f.observable,setGrid:f.action,points:f.observable,highlighted:f.observable})}setGrid(t,e){this.grid=t,this.points=e}},o(Te,"PathFindingRenderer"),Te);const rn=1e3,Wr=class Wr{Canvas_Rules=rn;Change_History=0;Click_Node=100;Drag_Rules=rn;Drag_Node_Straight_Drag=500;Drag_Node_Distances_Balancer=400;Drag_Node_Aligner=200;Drag_Node_Snap_To_Grid=100;Drag_Edge_Snap_To_Grid=100;Mouse_Down_Rules=rn;Mouse_Down_Measurer=400;Mouse_Down_Selector=300;Mouse_Down_Node=200;Mouse_Down_Dragger=100;Mouse_Move_Straight_Drag=500;Mouse_Move_Selector=100;Mouse_Up_Straight_Drag=500;Mouse_Up_Dragger=200;Mouse_Up_Selector=100;Nodes_Connection_Rules=rn;Node_Selection_Nodes_Resizer=200;Node_Selection_Selector=200;Scale_Dragger=100;Selection_Rules=rn};o(Wr,"Priorities");let Ui=Wr;const ko="diagram-grid-visible",Yr=class Yr{constructor(t){this.d=t,t.onEvent(tt,this.check(()=>this.allowEdition),t.priorities.Mouse_Down_Rules),t.onEvent(We,this.check(()=>this.allowSelection),t.priorities.Selection_Rules),t.onEvent(Kt,this.check(()=>this.allowEdition),t.priorities.Drag_Rules),t.onEvent(Ge,this.check(()=>this.allowEdition),t.priorities.Nodes_Connection_Rules),t.onEvent(Be,this.check(()=>this.allowZoom),t.priorities.Drag_Rules),f.makeAutoObservable(this)}d;allowEdition=!0;allowSelection=!0;allowZoom=!0;displaceWhenDragOnEdges=!0;_toggleGrid=localStorage.getItem(ko)!=="false";get toggleGrid(){return this._toggleGrid}set toggleGrid(t){this._toggleGrid=t,localStorage.setItem(ko,String(t))}check=o(t=>e=>{t()||(e.cancel(),e.stopImmediatePropagation())},"check")};o(Yr,"Rules");let Xi=Yr;const Zr=class Zr extends z{straight="none";startCoordinates=null;startProposals=[];shiftHeld=!1;reset(){this.straight="none",this.startCoordinates=null,this.startProposals=[],this.shiftHeld=!1}init(){this.diagram.onEvent(te,t=>{t.shift&&(this.shiftHeld=!0,this.startCoordinates=fe.getInstance().coordinates)}),this.diagram.onEvent(He,t=>{t.shift||this.reset()}),this.diagram.onEvent(Bt,t=>{t.shift&&!this.startCoordinates&&(this.shiftHeld=!0,this.startCoordinates=new y(t.originalEvent))}),this.diagram.onEvent(Rt,t=>{if(!this.shiftHeld||!this.startCoordinates)return;const e=Math.abs(t.mouse.x-this.startCoordinates.x),i=Math.abs(t.mouse.y-this.startCoordinates.y);(e||i)&&(this.straight=e>=i?"x":"y")},this.diagram.priorities.Mouse_Move_Straight_Drag),this.diagram.onEvent(ot,()=>{this.reset()},this.diagram.priorities.Mouse_Up_Straight_Drag),this.diagram.onEvent(Et,t=>{if(this.straight!=="none"){this.startProposals.length===0&&(this.startProposals=t.proposals.map(e=>new Ze(e.node,e.node.box)));for(const e of t.proposals){const i=this.startProposals.find(s=>s.node.id===e.node.id);switch(this.straight){case"x":e.updateY(i.newBox.y),e.lockY();break;case"y":e.updateX(i.newBox.x),e.lockX();break}}}},this.diagram.priorities.Drag_Node_Straight_Drag)}};o(Zr,"StraightDrag");let qi=Zr;const Kr=class Kr extends z{shiftHeld=!1;init(){this.diagram.onEvent(te,t=>{t.shift&&(this.shiftHeld=!0)}),this.diagram.onEvent(He,t=>{t.shift||(this.shiftHeld=!1)})}constrain(t,e,i=e){if(!this.enabled||!this.shiftHeld)return e;const s=Math.abs(i.x-t.x),r=Math.abs(i.y-t.y),a=e.copy();return s>=r?a.y=t.y:a.x=t.x,a}};o(Kr,"StraightLabelsDrag");let an=Kr;const So=k.createContext(null),Yc=o(()=>({Creator:Yi,DistancesBalancer:Ke,StraightDrag:qi,StraightLabelsDrag:an,Dragger:Zi,EdgesDragger:we,GridSnap:R,History:Ue,Hotkeys:Wi,LabelsAligner:Tt,Measurer:Xe,NodesAligner:Xt,NodesConnector:ve,NodesResizer:Ki,PathFindingRenderer:Eo,Selector:B}),"getDefaultExtensions"),Si=class Si extends ee{priorities=new Ui;rules=new Xi(this);focusContentTimer=null;knownClasses=new Map;getClass(t){return this.knownClasses.get(t)}registerClass(t,e=t.name){this.knownClasses.set(e,t)}edgeClass=qt;setDefaultEdge(t){this.edgeClass=t}_extensions=new Map;_nodes=new Map;_edges=new Map;_hoveredNode=null;canvas=new Gc(this);constructor(t){super(null),this.registerClass(en),this.registerClass(qt),this.registerClass(Nt),this.registerClass(Qn),Object.entries(Yc()).forEach(([e,i])=>{t?.extensions?.[e]!==!1&&this.registerExtension(i)}),f.makeObservable(this,{edges:f.computed,_edges:f.observable,_hoveredNode:f.observable.ref,_nodes:f.observable,clearNodeHover:f.action,hoveredNode:f.computed,setNodeHover:f.action,toggleGrid:f.action})}get edges(){return[...this._edges.values()]}get extensions(){return[...this._extensions.values()]}get nodes(){return[...this._nodes.values()]}get hoveredNode(){return this._hoveredNode}setNodeHover(t,e){t.diagram===this&&(e?(this._hoveredNode&&this._hoveredNode!==t&&(this._hoveredNode.state.hover=!1),this._hoveredNode=t,t.state.hover=!0):this._hoveredNode===t?(t.state.hover=!1,this._hoveredNode=null):t.state.hover=!1)}clearNodeHover(){this._hoveredNode&&(this._hoveredNode.state.hover=!1),this._hoveredNode=null}getUniqueNodeId(t){if(!this._nodes.has(t))return t;let e=1,i=`${t}-${e}`;for(;this._nodes.has(i);)e++,i=`${t}-${e}`;return i}add(t){return f.runInAction(()=>{const e=this.getUniqueNodeId(t.id);e!==t.id&&t.setState("id",e),t.setDiagram(this),this._nodes.set(t.id,t)}),t}addEdge(t){t.from.addOutgoingEdge(t),t.to.addIncomingEdge(t)}connect(t,e,i){const s=i?.startAnchor??{mode:"fixed",position:t.parent.findFixedConnectionAnchor(t.coordinates.copy().sum(i?.fromDisplacement??new y)).relativePosition},r=i?.endAnchor??{mode:"fixed",position:e.parent.findFixedConnectionAnchor(e.coordinates.copy().sum(i?.toDisplacement??new y)).relativePosition},a=new this.edgeClass(this,{hover:!1,dragging:!1,selected:!1,from:t,to:e,labels:[],pathType:i?.pathType??"orthogonal",displacementStart:i?.fromDisplacement,displacementEnd:i?.toDisplacement,startAnchor:s,endAnchor:r,steps:[]});return this.connectWithEdge(t,e,a)}connectWithEdge(t,e,i){const s=i;return s.from.addOutgoingEdge(s),s.to.addIncomingEdge(s),this._edges.set(s.id,s),s}delete(t){this.emit(new ge(this,t)).cancelled||f.runInAction(()=>{t.gateways.forEach(e=>{e.incomingEdges.forEach(this.disconnect.bind(this)),e.outgoingEdges.forEach(this.disconnect.bind(this))}),this._hoveredNode===t&&(t.state.hover=!1,this._hoveredNode=null),this._nodes.delete(t.id),t.parent=null})}disconnect(t){this.emit(new zn(this,t)).cancelled||f.runInAction(()=>{for(const e of this.nodes)for(const i of e.gateways)i.removeIncomingEdge(t),i.removeOutgoingEdge(t);this._edges.delete(t.id),t.parent=null})}Context=o(({children:t})=>d.jsx(So.Provider,{value:this,children:t}),"Context");getEdgeById(t){return this._edges.get(t)}getNodeById(t){return this._nodes.get(t)}get showGrid(){return this.rules.toggleGrid}getExtension(t){return this._extensions.get(t)}registerExtension(t){const e=new t(this);e.init(),this._extensions.set(t,e)}toggleGrid(){this.rules.toggleGrid=!this.rules.toggleGrid}export(){return JSON.stringify(this.serialize())}async reset(){let t=this._nodes.size===0;if(!t){let e=null;const i=this.emit(new Ni(this,s=>{e=s}));t=await e()&&!i.cancelled}if(t){for(const e of this._nodes.values())this.delete(e);return!0}return!1}serialize(){return{position:{x:this.canvas.displacement.x,y:this.canvas.displacement.y,scale:this.canvas.scale},nodes:this.nodes.map(t=>t.serialize())}}import(t){f.runInAction(()=>{const e=JSON.parse(t),i=e.position,s=!!i&&Number.isFinite(i.x)&&Number.isFinite(i.y)&&Number.isFinite(i.scale);if(s&&(this.canvas.setScale(i.scale),this.canvas.setDisplacement(new y([i.x,i.y]))),e.nodes){const r=new Map;e.nodes.forEach(a=>{const l=this.getClass(a.class);if(!l)throw new Error(`Unable to import node: unknown class '${a.class}'.`);const c=new l(this,{id:a.id}),h=this.add(c);r.set(a.id,h.id)}),e.nodes.forEach(a=>{const l=r.get(a.id),c=this.getNodeById(l),h=c.remapSerializedReferences({...a,id:l,gateways:a.gateways.map(u=>({...u,outEdges:u.outEdges.map(g=>({...g,toParentId:r.get(g.toParentId)||g.toParentId}))}))},r);c.deserialize(h)})}s||this.focusContentInViewportWithRetry()})}paste(t){f.runInAction(()=>{const e=JSON.parse(t);if(e.position&&(this.canvas.setScale(e.position.scale),this.canvas.setDisplacement(new y([e.position.x,e.position.y]))),e.nodes?.length){const i=new Map,s=[];e.nodes.forEach(c=>{const h=me(this,"node",s);i.set(c.id,h),s.push(h)});let r=new y([1/0,1/0]);e.nodes.forEach(c=>{const h=new y([c.box[0],c.box[1]]);h.norm<r.norm&&(r=h)});const l=this.canvas.inverseFit(fe.getInstance().coordinates).substract(r);e.nodes.forEach(c=>{const h=this.getClass(c.class);if(!h)throw new Error(`Unable to paste node: unknown class '${c.class}'.`);const u=new h(this,{id:i.get(c.id)});this.add(u)}),e.nodes.forEach(c=>{const h=i.get(c.id),u=this.getNodeById(h),g=u.remapSerializedReferences({...c,id:h,gateways:c.gateways.map(p=>({...p,outEdges:p.outEdges.map(m=>({...m,toParentId:i.get(m.toParentId)||m.toParentId}))})),box:[c.box[0]+l.x,c.box[1]+l.y,c.box[2],c.box[3]]},i);u.deserialize(g)})}})}focusContentInViewport(t=80){if(!this.nodes.length)return!1;const e=this.canvas.frameDimensions;if(e.width<=0||e.height<=0)return!1;let i=1/0,s=1/0,r=-1/0,a=-1/0;for(const u of this.nodes){const g=u.box;i=Math.min(i,g.x),s=Math.min(s,g.y),r=Math.max(r,g.x+g.width),a=Math.max(a,g.y+g.height)}if(!Number.isFinite(i)||!Number.isFinite(s)||!Number.isFinite(r)||!Number.isFinite(a))return!1;const l=Math.max(1,r-i+t*2),c=Math.max(1,a-s+t*2),h=Math.max(.3,Math.min(3,Math.min(e.width/l,e.height/c)));return this.canvas.setScale(h),this.canvas.centerOnPoint(new y([(i+r)/2,(s+a)/2])),!0}focusContentInViewportWithRetry(t=8,e=32){this.focusContentInViewport()||t<=0||(this.focusContentTimer&&clearTimeout(this.focusContentTimer),this.focusContentTimer=setTimeout(()=>{this.focusContentInViewportWithRetry(t-1,e)},e))}};o(Si,"Diagram"),Ft(Si,"use",o(()=>k.useContext(So),"use"));let X=Si;function Dt(n,t){return{"data-id":n.id,onMouseEnter:o(()=>n.setHovered(!0),"onMouseEnter"),onMouseLeave:o(e=>{const i=e.relatedTarget;i instanceof Element&&i.closest(`[data-id="${n.id}"], [data-gateway-parent="${n.id}"]`)||n.setHovered(!1)},"onMouseLeave"),style:{"--screen-renderer-x":`${t.x}px`,"--screen-renderer-y":`${t.y}px`,"--screen-renderer-width":`${t.width}px`,"--screen-renderer-height":`${t.height}px`,"--screen-renderer-z-index":n.state.hover?(n.state.zIndex??100)+1:n.state.zIndex??100}}}o(Dt,"screenRendererProps");function ei(n){return["Enter","Escape"].includes(n.code)}o(ei,"allowEventInEdition");const Ur=class Ur extends z{inEdition=new Set;cancel(){this.inEdition.forEach(t=>t.cancel()),this.inEdition.clear()}confirm(){this.inEdition.forEach(t=>t.confirm()),this.inEdition.clear()}editNode(t){t.edit(),this.inEdition.add(t)}init(){this.diagram.onEvent(te,t=>{switch(t.code){case"F2":{const e=this.diagram.getExtension(B).selectedNodes[0];e instanceof Lt&&this.editNode(e);break}case"Escape":{this.cancel();break}case"Enter":t.shift||this.confirm()}}),this.diagram.onEvent(Bt,t=>{(!t.node||t.node instanceof Lt&&!this.inEdition.has(t.node))&&this.confirm()},this.diagram.priorities.Mouse_Down_Dragger+1),this.diagram.onEvent(On,t=>{t.node instanceof Lt&&!this.inEdition.has(t.node)&&(this.confirm(),this.editNode(t.node))})}};o(Ur,"EditionMode");let ni=Ur;function Zc(n,t){const e=n.box.middle,i=t.middle,s=i.x-e.x,r=i.y-e.y;return Math.abs(s)>Math.abs(r)?s<0?"left":"right":r<0?"top":"bottom"}o(Zc,"externalLabelPosition");const Mo=A.observer(({node:n,box:t})=>{const e=k.useRef(!1),i=Dt(n,t),s=/(?:^| )(?:bpmn__event|bpmn__gate|bpmn__data_store|bpmn__document)(?: |$)/.test(n.classList.string),r=s?t.y-n.labelOffset.y-(n.box.y+n.box.height):void 0,a=s?Zc(n,t):void 0,l=s?{"data-node-label-position":a}:{},c=s?" bpmn__axis-label":"",h=/(?:^| )bpmn__text_annotation(?: |$)/.test(n.classList.string)?" bpmn__text-annotation-label":"",u=/(?:^| )bpm__node(?: |$)/.test(n.classList.string)?" bpmn__node-label":"";i.style["--screen-label-font-size"]=`${n.state.labelFontSize??14}px`;const g=n.diagram?.rules.allowEdition!==!1;return n.editionMode&&g?d.jsx("textarea",{...i,...l,className:`node__screenLabel node__screenHitArea editable__label${c}${h}${u}${n.selected?" selected":""}`,autoFocus:!0,value:n.state.label,onChange:o(p=>{f.runInAction(()=>{n.state.label=p.target.value})},"onChange"),onKeyDownCapture:o(p=>{n.editionMode&&!ei(p.nativeEvent)&&p.nativeEvent.stopImmediatePropagation()},"onKeyDownCapture"),ref:o(p=>{p instanceof HTMLTextAreaElement&&!e.current&&(e.current=!0,p.select())},"ref")}):(e.current=!1,n.state.label?d.jsx("pre",{...i,...l,"data-node-label-drag-handle":s?"true":void 0,"data-node-label-gap":r,"data-node-label-height":s?t.height:void 0,"data-node-label-width":s?t.width:void 0,className:`node__screenLabel node__screenHitArea${c}${h}${u}${n.selected?" selected":""}`,children:n.state.label}):null)}),Xr=class Xr extends tt{constructor(t,e,i){super(t),this.src=t,this.previousLabel=e,this.nextLabel=i}src;previousLabel;nextLabel};o(Xr,"DEditNodeEvent");let Ji=Xr;const qr=class qr extends en{editionMode=!1;constructor(t,e){super(t,e),f.makeObservable(this,{editionMode:f.observable,edit:f.action,cancel:f.action,confirm:f.action})}get label(){return this.state.label}previous=null;edit(){this.previous=this.state.label,this.editionMode=!0}cancel(){this.state.label=this.previous,this.editionMode=!1}confirm(){return this.emit(new Ji(this,this.previous,this.state.label)).cancelled?(this.cancel(),!1):(this.editionMode=!1,!0)}get isChanged(){return this.previous!==this.state.label}get screenLabelBox(){return this.box}get labelScreenBox(){return this.screenLabelBox}RenderScreen=A.observer(()=>d.jsx(Mo,{node:this,box:this.screenLabelBox}))};o(qr,"EditableNode");let Lt=qr;const Jr=class Jr extends X{constructor(t){super(t),this.registerClass(Lt),this.registerExtension(ni)}};o(Jr,"EditableDiagram");let _e=Jr;const Qr=class Qr extends qt{kind="default";constructor(t,e){super(t,e),f.makeObservable(this,{kind:f.observable,setKind:f.action}),this.setKind(e.kind??"default")}setKind(t){switch(this.kind=t,t){case"trigger":this.state.stroke="#38bdf8",this.state.lineStyle="solid",this.state.arrowHeadEnd="triangle-filled";break;case"condition-true":this.state.stroke="#22c55e",this.state.lineStyle="solid",this.state.arrowHeadEnd="triangle-filled";break;case"condition-false":this.state.stroke="#ef4444",this.state.lineStyle="dashed",this.state.arrowHeadEnd="triangle-filled";break;default:this.state.stroke=void 0,this.state.lineStyle="solid",this.state.arrowHeadEnd="arrow";break}}serialize(){return{...super.serialize(),kind:this.kind}}deserialize(t){super.deserialize(t),this.setKind(t.kind??"default")}};o(Qr,"AgentEdge");let ii=Qr;function Kc(n){return{position:"absolute",left:`${n.box.x}px`,top:`${n.box.y}px`,zIndex:n.state.hover?n.state.zIndex+1:n.state.zIndex,width:`${n.box.width}px`,height:`${n.box.height}px`}}o(Kc,"customRendererStyles");function q(n){const t=Kc(n);return n.state.fill&&(t["--node-fill"]=n.state.fill),n.state.stroke&&(t["--node-stroke"]=n.state.stroke),{onMouseOver:o(()=>n.setState("hover",!0),"onMouseOver"),onMouseOut:o(e=>{const i=e.relatedTarget;i instanceof Element&&i.closest(`[data-id="${n.id}"], [data-gateway-parent="${n.id}"]`)||n.setState("hover",!1)},"onMouseOut"),"data-id":n.id,style:t,className:`${n.classList.string} ${n.selected?"selected":""}`}}o(q,"customRendererProps");function on(n){return typeof n=="object"&&n?Array.isArray(n)?n.map(t=>on(t)):Object.fromEntries(Object.entries(n).map(([t,e])=>[t,on(e)])):n}o(on,"cloneDeep");const ta=class ta extends Lt{payload;constructor(t,e){super(t,e),this.classList.add("agent__node","diagram__node"),this.payload=this.mergePayload(e.payload),f.makeObservable(this,{payload:f.observable.ref,replacePayload:f.action,updatePayload:f.action})}mergePayload(t){return{...this.defaultPayload(),...t??{}}}replacePayload(t){this.payload=this.mergePayload(t)}updatePayload(t){this.payload={...this.payload,...t}}serialize(){return{...super.serialize(),kind:this.kind,payload:on(this.payload)}}deserialize(t){super.deserialize(t),this.payload=this.mergePayload(t.payload)}};o(ta,"AgentNode");let se=ta;const ea=class ea extends se{kind="action";constructor(t,e){super(t,{...e,box:e.box??new S([0,0,220,110])}),this.classList.add("agent__action")}defaultPayload(){return{actionType:"task",operation:"",inputRef:"",outputRef:"",metadata:{}}}RenderOverlay=A.observer(()=>d.jsx("div",{...q(this)}))};o(ea,"ActionNode");let Qi=ea;const na=class na extends se{kind="condition";constructor(t,e){super(t,{...e,box:e.box??new S([0,0,180,120])}),this.classList.add("agent__condition")}defaultPayload(){return{expression:"",language:"rule",trueLabel:"True",falseLabel:"False",metadata:{}}}RenderOverlay=A.observer(()=>d.jsx("div",{...q(this),children:d.jsx("svg",{viewBox:`0 0 ${this.state.box.width} ${this.state.box.height}`,preserveAspectRatio:"none",style:{width:"100%",height:"100%"},children:d.jsx("polygon",{points:`${this.state.box.width/2} 0 ${this.state.box.width} ${this.state.box.height/2} ${this.state.box.width/2} ${this.state.box.height} 0 ${this.state.box.height/2}`})})}))};o(na,"ConditionNode");let ts=na;const ia=class ia extends se{kind="outcome";constructor(t,e){super(t,{...e,box:e.box??new S([0,0,180,90])}),this.classList.add("agent__outcome")}defaultPayload(){return{status:"success",code:"",summary:"",metadata:{}}}RenderOverlay=A.observer(()=>d.jsx("div",{...q(this)}))};o(ia,"OutcomeNode");let es=ia;const sa=class sa extends se{kind="trigger";constructor(t,e){super(t,{...e,box:e.box??new S([0,0,170,90])}),this.classList.add("agent__trigger")}defaultPayload(){return{triggerType:"manual",source:"",eventName:"",schedule:"",metadata:{}}}RenderOverlay=A.observer(()=>d.jsx("div",{...q(this)}))};o(sa,"TriggerNode");let ns=sa;const ra=class ra extends _e{constructor(t){super(t),this.registerClass(se),this.registerClass(ns),this.registerClass(Qi),this.registerClass(ts),this.registerClass(es),this.registerClass(ii),this.setDefaultEdge(ii)}};o(ra,"AgentDiagram");let is=ra;const aa=class aa extends Lt{edgesAsGateways=!0;occupiesGridSquare=!1;constructor(t,e){super(t,{...e,labelFontSize:e.labelFontSize??16}),this.classList.add("bpm__node","diagram__node")}fitToGridSquare(){if(!this.occupiesGridSquare)return;const t=this.diagram?.getExtension(R)?.gridSize??50;this.state.box.assignDimensions([t,t])}setDiagram(t){super.setDiagram(t),this.fitToGridSquare()}deserialize(t){super.deserialize(t),this.state.labelFontSize=t.labelFontSize,this.fitToGridSquare()}};o(aa,"BPMNode");let lt=aa;var Ao={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Co=k.createContext&&k.createContext(Ao),Uc=["attr","size","title"];function Xc(n,t){if(n==null)return{};var e,i,s=qc(n,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(n);for(i=0;i<r.length;i++)e=r[i],t.indexOf(e)===-1&&{}.propertyIsEnumerable.call(n,e)&&(s[e]=n[e])}return s}o(Xc,"_objectWithoutProperties");function qc(n,t){if(n==null)return{};var e={};for(var i in n)if({}.hasOwnProperty.call(n,i)){if(t.indexOf(i)!==-1)continue;e[i]=n[i]}return e}o(qc,"_objectWithoutPropertiesLoose");function si(){return si=Object.assign?Object.assign.bind():function(n){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var i in e)({}).hasOwnProperty.call(e,i)&&(n[i]=e[i])}return n},si.apply(null,arguments)}o(si,"_extends");function Io(n,t){var e=Object.keys(n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(n);t&&(i=i.filter(function(s){return Object.getOwnPropertyDescriptor(n,s).enumerable})),e.push.apply(e,i)}return e}o(Io,"ownKeys");function ri(n){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?Io(Object(e),!0).forEach(function(i){Jc(n,i,e[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(e)):Io(Object(e)).forEach(function(i){Object.defineProperty(n,i,Object.getOwnPropertyDescriptor(e,i))})}return n}o(ri,"_objectSpread");function Jc(n,t,e){return(t=Qc(t))in n?Object.defineProperty(n,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):n[t]=e,n}o(Jc,"_defineProperty");function Qc(n){var t=td(n,"string");return typeof t=="symbol"?t:t+""}o(Qc,"_toPropertyKey");function td(n,t){if(typeof n!="object"||!n)return n;var e=n[Symbol.toPrimitive];if(e!==void 0){var i=e.call(n,t);if(typeof i!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(n)}o(td,"_toPrimitive");function jo(n){return n&&n.map((t,e)=>k.createElement(t.tag,ri({key:e},t.attr),jo(t.child)))}o(jo,"Tree2Element");function O(n){return t=>k.createElement(ed,si({attr:ri({},n.attr)},t),jo(n.child))}o(O,"GenIcon");function ed(n){var t=o(e=>{var i=n.attr,s=n.size,r=n.title,a=Xc(n,Uc),l=s||e.size||"1em",c;return e.className&&(c=e.className),n.className&&(c=(c?c+" ":"")+n.className),k.createElement("svg",si({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},e.attr,i,a,{className:c,style:ri(ri({color:n.color||e.color},e.style),n.style),height:l,width:l,xmlns:"http://www.w3.org/2000/svg"}),r&&k.createElement("title",null,r),n.children)},"elem");return Co!==void 0?k.createElement(Co.Consumer,null,e=>t(e)):t(Ao)}o(ed,"IconBase");function nd(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M230.92,212c-15.23-26.33-38.7-45.21-66.09-54.16a72,72,0,1,0-73.66,0C63.78,166.78,40.31,185.66,25.08,212a8,8,0,1,0,13.85,8c18.84-32.56,52.14-52,89.07-52s70.23,19.44,89.07,52a8,8,0,1,0,13.85-8ZM72,96a56,56,0,1,1,56,56A56.06,56.06,0,0,1,72,96Z"},child:[]}]})(n)}o(nd,"PiUser");function Po(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M216,48H176V40a24,24,0,0,0-24-24H104A24,24,0,0,0,80,40v8H40a8,8,0,0,0,0,16h8V208a16,16,0,0,0,16,16H192a16,16,0,0,0,16-16V64h8a8,8,0,0,0,0-16ZM96,40a8,8,0,0,1,8-8h48a8,8,0,0,1,8,8v8H96Zm96,168H64V64H192ZM112,104v64a8,8,0,0,1-16,0V104a8,8,0,0,1,16,0Zm48,0v64a8,8,0,0,1-16,0V104a8,8,0,0,1,16,0Z"},child:[]}]})(n)}o(Po,"PiTrash");function id(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M32,64a8,8,0,0,1,8-8H216a8,8,0,0,1,0,16H40A8,8,0,0,1,32,64ZM216,96H88a8,8,0,0,0,0,16H216a8,8,0,0,0,0-16Zm0,40H40a8,8,0,0,0,0,16H216a8,8,0,0,0,0-16Zm0,40H88a8,8,0,0,0,0,16H216a8,8,0,0,0,0-16Z"},child:[]}]})(n)}o(id,"PiTextAlignRight");function sd(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M32,64a8,8,0,0,1,8-8H216a8,8,0,0,1,0,16H40A8,8,0,0,1,32,64Zm8,48H168a8,8,0,0,0,0-16H40a8,8,0,0,0,0,16Zm176,24H40a8,8,0,0,0,0,16H216a8,8,0,0,0,0-16Zm-48,40H40a8,8,0,0,0,0,16H168a8,8,0,0,0,0-16Z"},child:[]}]})(n)}o(sd,"PiTextAlignLeft");function rd(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M32,64a8,8,0,0,1,8-8H216a8,8,0,0,1,0,16H40A8,8,0,0,1,32,64ZM64,96a8,8,0,0,0,0,16H192a8,8,0,0,0,0-16Zm152,40H40a8,8,0,0,0,0,16H216a8,8,0,0,0,0-16Zm-24,40H64a8,8,0,0,0,0,16H192a8,8,0,0,0,0-16Z"},child:[]}]})(n)}o(rd,"PiTextAlignCenter");function ad(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M224,48H32a8,8,0,0,0-8,8V192a16,16,0,0,0,16,16H216a16,16,0,0,0,16-16V56A8,8,0,0,0,224,48ZM40,112H80v32H40Zm56,0H216v32H96ZM216,64V96H40V64ZM40,160H80v32H40Zm176,32H96V160H216v32Z"},child:[]}]})(n)}o(ad,"PiTable");function od(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M208,136H48a16,16,0,0,0-16,16v40a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V152A16,16,0,0,0,208,136Zm0,56H48V152H208v40Zm0-144H48A16,16,0,0,0,32,64v40a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V64A16,16,0,0,0,208,48Zm0,56H48V64H208v40Z"},child:[]}]})(n)}o(od,"PiRows");function ld(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M208,160H48a16,16,0,0,0-16,16v24a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V176A16,16,0,0,0,208,160Zm0,40H48V176H208v24Zm0-112H48a16,16,0,0,0-16,16v24a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V104A16,16,0,0,0,208,88Zm0,40H48V104H208v24ZM96,40a8,8,0,0,1,8-8h16V16a8,8,0,0,1,16,0V32h16a8,8,0,0,1,0,16H136V64a8,8,0,0,1-16,0V48H104A8,8,0,0,1,96,40Z"},child:[]}]})(n)}o(ld,"PiRowsPlusTop");function cd(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M208,112H48a16,16,0,0,0-16,16v24a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V128A16,16,0,0,0,208,112Zm0,40H48V128H208v24Zm0-112H48A16,16,0,0,0,32,56V80A16,16,0,0,0,48,96H208a16,16,0,0,0,16-16V56A16,16,0,0,0,208,40Zm0,40H48V56H208V80ZM160,216a8,8,0,0,1-8,8H136v16a8,8,0,0,1-16,0V224H104a8,8,0,0,1,0-16h16V192a8,8,0,0,1,16,0v16h16A8,8,0,0,1,160,216Z"},child:[]}]})(n)}o(cd,"PiRowsPlusBottom");function No(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M208,32H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V48A16,16,0,0,0,208,32Zm0,176H48V48H208V208Zm-32-80a8,8,0,0,1-8,8H136v32a8,8,0,0,1-16,0V136H88a8,8,0,0,1,0-16h32V88a8,8,0,0,1,16,0v32h32A8,8,0,0,1,176,128Z"},child:[]}]})(n)}o(No,"PiPlusSquare");function dd(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M227.31,73.37,182.63,28.68a16,16,0,0,0-22.63,0L36.69,152A15.86,15.86,0,0,0,32,163.31V208a16,16,0,0,0,16,16H92.69A15.86,15.86,0,0,0,104,219.31L227.31,96a16,16,0,0,0,0-22.63ZM92.69,208H48V163.31l88-88L180.69,120ZM192,108.68,147.31,64l24-24L216,84.68Z"},child:[]}]})(n)}o(dd,"PiPencilSimple");function hd(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M208,32H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H156.69A15.86,15.86,0,0,0,168,219.31L219.31,168A15.86,15.86,0,0,0,224,156.69V48A16,16,0,0,0,208,32ZM48,48H208V152H160a8,8,0,0,0-8,8v48H48ZM196.69,168,168,196.69V168Z"},child:[]}]})(n)}o(hd,"PiNoteBlank");function ud(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M176,128a8,8,0,0,1-8,8H88a8,8,0,0,1,0-16h80A8,8,0,0,1,176,128Zm56,0A104,104,0,1,1,128,24,104.11,104.11,0,0,1,232,128Zm-16,0a88,88,0,1,0-88,88A88.1,88.1,0,0,0,216,128Z"},child:[]}]})(n)}o(ud,"PiMinusCircle");function pd(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M188,48a27.75,27.75,0,0,0-12,2.71V44a28,28,0,0,0-54.65-8.6A28,28,0,0,0,80,60v64l-3.82-6.13a28,28,0,0,0-48.6,27.82c16,33.77,28.93,57.72,43.72,72.69C86.24,233.54,103.2,240,128,240a88.1,88.1,0,0,0,88-88V76A28,28,0,0,0,188,48Zm12,104a72.08,72.08,0,0,1-72,72c-20.38,0-33.51-4.88-45.33-16.85C69.44,193.74,57.26,171,41.9,138.58a6.36,6.36,0,0,0-.3-.58,12,12,0,0,1,20.79-12,1.76,1.76,0,0,0,.14.23l18.67,30A8,8,0,0,0,96,152V60a12,12,0,0,1,24,0v60a8,8,0,0,0,16,0V44a12,12,0,0,1,24,0v76a8,8,0,0,0,16,0V76a12,12,0,0,1,24,0Z"},child:[]}]})(n)}o(pd,"PiHand");function gd(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M232,64a32,32,0,1,0-40,31v17a8,8,0,0,1-8,8H96a23.84,23.84,0,0,0-8,1.38V95a32,32,0,1,0-16,0v66a32,32,0,1,0,16,0V144a8,8,0,0,1,8-8h88a24,24,0,0,0,24-24V95A32.06,32.06,0,0,0,232,64ZM64,64A16,16,0,1,1,80,80,16,16,0,0,1,64,64ZM96,192a16,16,0,1,1-16-16A16,16,0,0,1,96,192ZM200,80a16,16,0,1,1,16-16A16,16,0,0,1,200,80Z"},child:[]}]})(n)}o(gd,"PiGitBranch");function To(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,80a48,48,0,1,0,48,48A48.05,48.05,0,0,0,128,80Zm0,80a32,32,0,1,1,32-32A32,32,0,0,1,128,160Zm109.94-52.79a8,8,0,0,0-3.89-5.4l-29.83-17-.12-33.62a8,8,0,0,0-2.83-6.08,111.91,111.91,0,0,0-36.72-20.67,8,8,0,0,0-6.46.59L128,41.85,97.88,25a8,8,0,0,0-6.47-.6A112.1,112.1,0,0,0,54.73,45.15a8,8,0,0,0-2.83,6.07l-.15,33.65-29.83,17a8,8,0,0,0-3.89,5.4,106.47,106.47,0,0,0,0,41.56,8,8,0,0,0,3.89,5.4l29.83,17,.12,33.62a8,8,0,0,0,2.83,6.08,111.91,111.91,0,0,0,36.72,20.67,8,8,0,0,0,6.46-.59L128,214.15,158.12,231a7.91,7.91,0,0,0,3.9,1,8.09,8.09,0,0,0,2.57-.42,112.1,112.1,0,0,0,36.68-20.73,8,8,0,0,0,2.83-6.07l.15-33.65,29.83-17a8,8,0,0,0,3.89-5.4A106.47,106.47,0,0,0,237.94,107.21Zm-15,34.91-28.57,16.25a8,8,0,0,0-3,3c-.58,1-1.19,2.06-1.81,3.06a7.94,7.94,0,0,0-1.22,4.21l-.15,32.25a95.89,95.89,0,0,1-25.37,14.3L134,199.13a8,8,0,0,0-3.91-1h-.19c-1.21,0-2.43,0-3.64,0a8.08,8.08,0,0,0-4.1,1l-28.84,16.1A96,96,0,0,1,67.88,201l-.11-32.2a8,8,0,0,0-1.22-4.22c-.62-1-1.23-2-1.8-3.06a8.09,8.09,0,0,0-3-3.06l-28.6-16.29a90.49,90.49,0,0,1,0-28.26L61.67,97.63a8,8,0,0,0,3-3c.58-1,1.19-2.06,1.81-3.06a7.94,7.94,0,0,0,1.22-4.21l.15-32.25a95.89,95.89,0,0,1,25.37-14.3L122,56.87a8,8,0,0,0,4.1,1c1.21,0,2.43,0,3.64,0a8.08,8.08,0,0,0,4.1-1l28.84-16.1A96,96,0,0,1,188.12,55l.11,32.2a8,8,0,0,0,1.22,4.22c.62,1,1.23,2,1.8,3.06a8.09,8.09,0,0,0,3,3.06l28.6,16.29A90.49,90.49,0,0,1,222.9,142.12Z"},child:[]}]})(n)}o(To,"PiGearSix");function fd(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M213.66,82.34l-56-56A8,8,0,0,0,152,24H56A16,16,0,0,0,40,40V216a16,16,0,0,0,16,16H200a16,16,0,0,0,16-16V88A8,8,0,0,0,213.66,82.34ZM160,51.31,188.69,80H160ZM200,216H56V40h88V88a8,8,0,0,0,8,8h48V216Z"},child:[]}]})(n)}o(fd,"PiFile");function md(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24C74.17,24,32,48.6,32,80v96c0,31.4,42.17,56,96,56s96-24.6,96-56V80C224,48.6,181.83,24,128,24Zm80,104c0,9.62-7.88,19.43-21.61,26.92C170.93,163.35,150.19,168,128,168s-42.93-4.65-58.39-13.08C55.88,147.43,48,137.62,48,128V111.36c17.06,15,46.23,24.64,80,24.64s62.94-9.68,80-24.64ZM69.61,53.08C85.07,44.65,105.81,40,128,40s42.93,4.65,58.39,13.08C200.12,60.57,208,70.38,208,80s-7.88,19.43-21.61,26.92C170.93,115.35,150.19,120,128,120s-42.93-4.65-58.39-13.08C55.88,99.43,48,89.62,48,80S55.88,60.57,69.61,53.08ZM186.39,202.92C170.93,211.35,150.19,216,128,216s-42.93-4.65-58.39-13.08C55.88,195.43,48,185.62,48,176V159.36c17.06,15,46.23,24.64,80,24.64s62.94-9.68,80-24.64V176C208,185.62,200.12,195.43,186.39,202.92Z"},child:[]}]})(n)}o(md,"PiDatabase");function xd(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M69.12,94.15,28.5,128l40.62,33.85a8,8,0,1,1-10.24,12.29l-48-40a8,8,0,0,1,0-12.29l48-40a8,8,0,0,1,10.24,12.3Zm176,27.7-48-40a8,8,0,1,0-10.24,12.3L227.5,128l-40.62,33.85a8,8,0,1,0,10.24,12.29l48-40a8,8,0,0,0,0-12.29ZM162.73,32.48a8,8,0,0,0-10.25,4.79l-64,176a8,8,0,0,0,4.79,10.26A8.14,8.14,0,0,0,96,224a8,8,0,0,0,7.52-5.27l64-176A8,8,0,0,0,162.73,32.48Z"},child:[]}]})(n)}o(xd,"PiCode");function yd(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm0,192a88,88,0,1,1,88-88A88.1,88.1,0,0,1,128,216Zm64-88a8,8,0,0,1-8,8H128a8,8,0,0,1-8-8V72a8,8,0,0,1,16,0v48h48A8,8,0,0,1,192,128Z"},child:[]}]})(n)}o(yd,"PiClock");function Do(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm0,192a88,88,0,1,1,88-88A88.1,88.1,0,0,1,128,216Z"},child:[]}]})(n)}o(Do,"PiCircle");function bd(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M90.34,61.66a8,8,0,0,1,0-11.32l32-32a8,8,0,0,1,11.32,0l32,32a8,8,0,0,1-11.32,11.32L136,43.31V96a8,8,0,0,1-16,0V43.31L101.66,61.66A8,8,0,0,1,90.34,61.66Zm64,132.68L136,212.69V160a8,8,0,0,0-16,0v52.69l-18.34-18.35a8,8,0,0,0-11.32,11.32l32,32a8,8,0,0,0,11.32,0l32-32a8,8,0,0,0-11.32-11.32Zm83.32-72-32-32a8,8,0,0,0-11.32,11.32L212.69,120H160a8,8,0,0,0,0,16h52.69l-18.35,18.34a8,8,0,0,0,11.32,11.32l32-32A8,8,0,0,0,237.66,122.34ZM43.31,136H96a8,8,0,0,0,0-16H43.31l18.35-18.34A8,8,0,0,0,50.34,90.34l-32,32a8,8,0,0,0,0,11.32l32,32a8,8,0,0,0,11.32-11.32Z"},child:[]}]})(n)}o(bd,"PiArrowsOutCardinal");function wd(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M213.66,181.66l-32,32a8,8,0,0,1-11.32-11.32L188.69,184H48a8,8,0,0,1,0-16H188.69l-18.35-18.34a8,8,0,0,1,11.32-11.32l32,32A8,8,0,0,1,213.66,181.66Zm-139.32-64a8,8,0,0,0,11.32-11.32L67.31,88H208a8,8,0,0,0,0-16H67.31L85.66,53.66A8,8,0,0,0,74.34,42.34l-32,32a8,8,0,0,0,0,11.32Z"},child:[]}]})(n)}o(wd,"PiArrowsLeftRight");function vd(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M208,28H48A20,20,0,0,0,28,48V208a20,20,0,0,0,20,20H208a20,20,0,0,0,20-20V48A20,20,0,0,0,208,28Zm-4,176H52V52H204ZM76,128a12,12,0,0,1,12-12h28V88a12,12,0,0,1,24,0v28h28a12,12,0,0,1,0,24H140v28a12,12,0,0,1-24,0V140H88A12,12,0,0,1,76,128Z"},child:[]}]})(n)}o(vd,"PiPlusSquareBold");function _d(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,20A108,108,0,1,0,236,128,108.12,108.12,0,0,0,128,20Zm0,192a84,84,0,1,1,84-84A84.09,84.09,0,0,1,128,212Zm68-84a12,12,0,0,1-12,12H128a12,12,0,0,1-12-12V72a12,12,0,0,1,24,0v44h44A12,12,0,0,1,196,128Z"},child:[]}]})(n)}o(_d,"PiClockBold");function Ed(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M128,20A108,108,0,1,0,236,128,108.12,108.12,0,0,0,128,20Zm0,192a84,84,0,1,1,84-84A84.09,84.09,0,0,1,128,212Z"},child:[]}]})(n)}o(Ed,"PiCircleBold");function kd(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M232.49,80.49l-128,128a12,12,0,0,1-17,0l-56-56a12,12,0,1,1,17-17L96,183,215.51,63.51a12,12,0,0,1,17,17Z"},child:[]}]})(n)}o(kd,"PiCheckBold");function Sd(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M224.49,136.49l-72,72a12,12,0,0,1-17-17L187,140H40a12,12,0,0,1,0-24H187L135.51,64.48a12,12,0,0,1,17-17l72,72A12,12,0,0,1,224.49,136.49Z"},child:[]}]})(n)}o(Sd,"PiArrowRightBold");function Md(n){return O({attr:{viewBox:"0 0 256 256",fill:"currentColor"},child:[{tag:"path",attr:{d:"M228,128a100,100,0,0,1-98.66,100H128a99.39,99.39,0,0,1-68.62-27.29,12,12,0,0,1,16.48-17.45,76,76,0,1,0-1.57-109c-.13.13-.25.25-.39.37L54.89,92H72a12,12,0,0,1,0,24H24a12,12,0,0,1-12-12V56a12,12,0,0,1,24,0V76.72L57.48,57.06A100,100,0,0,1,228,128Z"},child:[]}]})(n)}o(Md,"PiArrowCounterClockwiseBold");const Ad={task:nd,serviceTask:To,scriptTask:xd,manualTask:pd,businessRuleTask:ad,callActivity:vd,subprocess:No,eventSubprocess:No,event:Do,start:Do,end:Ed,timer:yd,lanes:od,dataStore:md,document:fd,textAnnotation:hd,connect:Sd,settings:To};function Cd({id:n,className:t}){const e=n==="messageThrow"||n==="sendTask";return d.jsxs("svg",{className:`${t??""} bpmn__message_icon bpmn__message_icon--${e?"send":"receive"}`,viewBox:"0 0 24 24","aria-hidden":"true",children:[d.jsx("rect",{className:"bpmn__message_body",x:"3.5",y:"5.5",width:"17",height:"13",rx:"1.25"}),d.jsx("path",{className:"bpmn__message_fold",d:"m4.5 7 7.5 6 7.5-6"})]})}o(Cd,"MessageIcon");function Id({id:n,className:t}){return d.jsxs("svg",{className:t,viewBox:"0 0 24 24","aria-hidden":"true",children:[n==="intermediate"&&d.jsxs(d.Fragment,{children:[d.jsx("circle",{cx:"12",cy:"12",r:"8.5",fill:"none",stroke:"currentColor",strokeWidth:"1.45"}),d.jsx("circle",{cx:"12",cy:"12",r:"6.1",fill:"none",stroke:"currentColor",strokeWidth:"1.25"})]}),n==="signal"&&d.jsx("path",{className:"bpmn__event_symbol_fillable bpmn__event_symbol--signal",d:"M12 4.6 20 18H4Z",fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:"1.65"}),n==="compensation"&&d.jsx("path",{className:"bpmn__event_symbol_fillable bpmn__event_symbol--compensation",d:"m11.4 6.2-7 5.8 7 5.8Zm8.2 0-7 5.8 7 5.8Z",fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:"1.55"}),n==="error"&&d.jsx("path",{className:"bpmn__event_symbol_fillable bpmn__event_symbol--error",d:"m13.2 3.7-6.1 8.1 4.1-.1-.5 8.6 6.2-9.2-4 .1Z",fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:"1.55"}),n==="conditional"&&d.jsxs(d.Fragment,{children:[d.jsx("path",{className:"bpmn__event_symbol_outline bpmn__event_symbol--conditional-frame",d:"M6.5 4.5h11v15h-11Z",fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:"1.45"}),d.jsx("path",{className:"bpmn__event_symbol_outline bpmn__event_symbol--conditional-lines",d:"M9 8h6m-6 3h6m-6 3h6",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeWidth:"1.25"})]}),n==="cancel"&&d.jsx("path",{className:"bpmn__event_symbol_outline bpmn__event_symbol--cancel",d:"m7.2 7.2 9.6 9.6m0-9.6-9.6 9.6",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeWidth:"1.8"}),n==="escalation"&&d.jsx("path",{className:"bpmn__event_symbol_fillable bpmn__event_symbol--escalation",d:"M12 4.5 20 19H4Z",fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:"1.55"}),n==="link"&&d.jsx("path",{className:"bpmn__event_symbol_fillable bpmn__event_symbol--link",d:"M4 12h10.2l-2.8-3m2.8 3-2.8 3M15 7l5 5-5 5",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.55"}),n==="multiple"&&d.jsx("path",{className:"bpmn__event_symbol_fillable bpmn__event_symbol--multiple",d:"m12 4.5 7.1 5.15-2.7 8.35H7.6l-2.7-8.35Z",fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:"1.45"}),n==="parallelMultiple"&&d.jsx("path",{className:"bpmn__event_symbol_outline bpmn__event_symbol--parallel-multiple",d:"M12 5v14M5 12h14",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeWidth:"2"}),n==="terminate"&&d.jsx("circle",{cx:"12",cy:"12",r:"7.2",fill:"currentColor"})]})}o(Id,"EventDefinitionIcon");function jd({id:n,className:t}){return d.jsxs("svg",{className:t,viewBox:"0 0 24 24","aria-hidden":"true",children:[n==="blackBoxPool"&&d.jsxs(d.Fragment,{children:[d.jsx("rect",{x:"2.5",y:"5",width:"19",height:"14",rx:"1",fill:"none",stroke:"currentColor",strokeWidth:"1.5"}),d.jsx("path",{d:"M7 5v14",fill:"none",stroke:"currentColor",strokeWidth:"1.5"})]}),(n==="documentAnnotation"||n==="dataInput"||n==="dataOutput")&&d.jsxs(d.Fragment,{children:[d.jsx("path",{d:"M5 2.8h9l5 5v13.4H5Z",fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:"1.45"}),d.jsx("path",{d:"M14 2.8v5h5",fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:"1.45"}),n==="documentAnnotation"&&d.jsx("path",{d:"M8 12h8m-8 3h6",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeWidth:"1.25"}),n==="dataInput"&&d.jsx("path",{d:"m12 10-3 3m3-3 3 3m-3-3v7",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.45"}),n==="dataOutput"&&d.jsx("path",{d:"m12 18 3-3m-3 3-3-3m3 3v-7",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.45"})]})]})}o(jd,"SupportIcon");function Pd({id:n,className:t,markerOnly:e}){const i=e?n==="eventBased"?"6 6 12 12":"5 5 14 14":"0 0 24 24";return d.jsxs("svg",{className:[t,`bpmn__gate_marker--${n}`].filter(Boolean).join(" "),viewBox:i,"aria-hidden":"true",children:[!e&&d.jsx("path",{d:"M12 2.7 21.3 12 12 21.3 2.7 12 12 2.7Z",fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:"1.65"}),n==="exclusive"&&d.jsx("path",{d:"m8.5 8.5 7 7m0-7-7 7",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeWidth:"2.2"}),n==="inclusive"&&d.jsx("circle",{cx:"12",cy:"12",r:"4.15",fill:"none",stroke:"currentColor",strokeWidth:"2"}),n==="parallel"&&d.jsx("path",{d:"M12 7v10M7 12h10",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeWidth:"2.2"}),n==="eventBased"&&d.jsxs(d.Fragment,{children:[d.jsx("circle",{cx:"12",cy:"12",r:"5.4",fill:"none",stroke:"currentColor",strokeWidth:e?1:1.35}),d.jsx("circle",{cx:"12",cy:"12",r:"3.8",fill:"none",stroke:"currentColor",strokeWidth:e?.9:1.15}),d.jsx("path",{d:"m12 9.1 2.75 2-1.05 3.2h-3.4l-1.05-3.2 2.75-2Z",fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:e?.82:1.1})]}),n==="complex"&&d.jsx("path",{d:"m12 5.8 1.8 4.4 4.7-1.9-3.1 3.6 4.2 2.1-4.7.1.3 4.8-3.2-3.4-3.2 3.4.3-4.8-4.7-.1 4.2-2.1-3.1-3.6 4.7 1.9Z",fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:"1.45"})]})}o(Pd,"GatewayIcon");function Wt({id:n,className:t,markerOnly:e}){const i=Ad[n];return i?d.jsx(i,{"aria-hidden":"true",className:t}):n==="messageCatch"||n==="messageThrow"||n==="message"||n==="receiveTask"||n==="sendTask"?d.jsx(Cd,{className:t,id:n}):n==="intermediate"||n==="signal"||n==="compensation"||n==="error"||n==="conditional"||n==="cancel"||n==="escalation"||n==="link"||n==="multiple"||n==="parallelMultiple"||n==="terminate"?d.jsx(Id,{className:t,id:n}):n==="blackBoxPool"||n==="documentAnnotation"||n==="dataInput"||n==="dataOutput"?d.jsx(jd,{className:t,id:n}):n==="exclusive"||n==="inclusive"||n==="parallel"||n==="eventBased"||n==="complex"?d.jsx(Pd,{className:t,id:n,markerOnly:e}):d.jsxs("svg",{className:t,viewBox:"0 0 24 24","aria-hidden":"true",children:[d.jsx("circle",{cx:"6.5",cy:"6.5",r:"3.25",fill:"none",stroke:"currentColor",strokeWidth:"1.7"}),d.jsx("path",{d:"m9.3 8.8 5.7 5m-1.9 0h2.25v-2.25",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.7"}),d.jsx("rect",{x:"14.1",y:"14.1",width:"6.4",height:"5.6",rx:"1",fill:"none",stroke:"currentColor",strokeWidth:"1.7"})]})}o(Wt,"BPMNIcon");var N=(n=>(n[n.start=0]="start",n[n.end=1]="end",n[n.intermediate=2]="intermediate",n[n.timer=3]="timer",n[n.messageCatch=4]="messageCatch",n[n.messageThrow=5]="messageThrow",n[n.signalCatch=6]="signalCatch",n[n.signalThrow=7]="signalThrow",n[n.compensationCatch=8]="compensationCatch",n[n.compensationThrow=9]="compensationThrow",n[n.errorCatch=10]="errorCatch",n[n.errorThrow=11]="errorThrow",n[n.conditional=12]="conditional",n[n.terminate=13]="terminate",n[n.cancelCatch=14]="cancelCatch",n[n.cancelThrow=15]="cancelThrow",n[n.escalationCatch=16]="escalationCatch",n[n.escalationThrow=17]="escalationThrow",n[n.linkCatch=18]="linkCatch",n[n.linkThrow=19]="linkThrow",n[n.multipleCatch=20]="multipleCatch",n[n.multipleThrow=21]="multipleThrow",n[n.parallelMultiple=22]="parallelMultiple",n))(N||{});const ai={0:{stage:"start",kind:"none",direction:"catch"},1:{stage:"end",kind:"none",direction:"throw"},2:{stage:"start",kind:"none",direction:"throw"},3:{stage:"intermediate",kind:"timer",direction:"catch"},4:{stage:"intermediate",kind:"message",direction:"catch"},5:{stage:"intermediate",kind:"message",direction:"throw"},6:{stage:"intermediate",kind:"signal",direction:"catch"},7:{stage:"intermediate",kind:"signal",direction:"throw"},8:{stage:"intermediate",kind:"compensation",direction:"catch"},9:{stage:"intermediate",kind:"compensation",direction:"throw"},10:{stage:"intermediate",kind:"error",direction:"catch"},11:{stage:"end",kind:"error",direction:"throw"},12:{stage:"intermediate",kind:"conditional",direction:"catch"},13:{stage:"end",kind:"terminate",direction:"throw"},14:{stage:"intermediate",kind:"cancel",direction:"catch"},15:{stage:"end",kind:"cancel",direction:"throw"},16:{stage:"intermediate",kind:"escalation",direction:"catch"},17:{stage:"end",kind:"escalation",direction:"throw"},18:{stage:"intermediate",kind:"link",direction:"catch"},19:{stage:"intermediate",kind:"link",direction:"throw"},20:{stage:"intermediate",kind:"multiple",direction:"catch"},21:{stage:"end",kind:"multiple",direction:"throw"},22:{stage:"start",kind:"parallelMultiple",direction:"catch"}},Nd=new Set(["start","intermediate","end"]),Td=new Set(["none","timer","message","signal","compensation","error","conditional","terminate","cancel","escalation","link","multiple","parallelMultiple"]),Dd=new Set(["catch","throw"]),Ld={none:new Set(["start","end"]),message:new Set(["start","intermediate","end"]),timer:new Set(["start","intermediate"]),error:new Set(["intermediate","end"]),signal:new Set(["start","intermediate","end"]),compensation:new Set(["intermediate","end"]),conditional:new Set(["start","intermediate"]),terminate:new Set(["end"]),cancel:new Set(["intermediate","end"]),escalation:new Set(["start","intermediate","end"]),link:new Set(["intermediate"]),multiple:new Set(["start","intermediate","end"]),parallelMultiple:new Set(["start"])},Od={none:new Set(["catch","throw"]),message:new Set(["catch","throw"]),timer:new Set(["catch"]),error:new Set(["catch","throw"]),signal:new Set(["catch","throw"]),compensation:new Set(["catch","throw"]),conditional:new Set(["catch"]),terminate:new Set(["throw"]),cancel:new Set(["catch","throw"]),escalation:new Set(["catch","throw"]),link:new Set(["catch","throw"]),multiple:new Set(["catch","throw"]),parallelMultiple:new Set(["catch"])};function re(n){if(!n||typeof n!="object")return!1;const t=n;if(!Nd.has(t.stage)||!Td.has(t.kind)||!Dd.has(t.direction))return!1;const{stage:e,kind:i,direction:s}=t;return Ld[i].has(e)&&Od[i].has(s)}o(re,"isValidEventDefinition");const zd=5,$d=3,Fd=1.18,Hd=["bpmn__event__start","bpmn__event__intermediate","bpmn__event__end"],Bd=["bpmn--none","bpmn--timer","bpmn--message","bpmn--signal","bpmn--compensation","bpmn--error","bpmn--conditional","bpmn--terminate","bpmn--cancel","bpmn--escalation","bpmn--link","bpmn--multiple","bpmn--parallelMultiple"],Rd=["bpmn--catch","bpmn--throw"],oi=new Set(["timer","message","signal","compensation","error","conditional","cancel","escalation","multiple","parallelMultiple"]),ss=new Set(["message","error","escalation","compensation","conditional","signal","multiple"]),Gd=Object.values(N).filter(n=>typeof n=="string").map(n=>`bpmn--${n}`);function ln(n){return{...n}}o(ln,"copyDefinition");function Lo(n){return re(n.eventDefinition)?ln(n.eventDefinition):typeof n.type=="number"&&ai[n.type]?ln(ai[n.type]):ln(ai[N.start])}o(Lo,"resolveDefinition");function Oo(n){return!Array.isArray(n)||n.length!==2||!Number.isFinite(n[0])||!Number.isFinite(n[1])?null:[n[0],n[1]]}o(Oo,"resolveAttachmentOffset");function Vd(n,t){return n.stage===t.stage&&n.kind===t.kind&&n.direction===t.direction}o(Vd,"sameDefinition");const oa=class oa extends lt{definition;attachedToTaskId;attachmentOffset;interrupting;subprocessStart;subprocessId;edgesAsGateways=!0;occupiesGridSquare=!0;constructor(t,e){super(t,e),this.definition=Lo(e),this.attachedToTaskId=e.attachedToTaskId&&oi.has(this.definition.kind)?e.attachedToTaskId:null,this.attachmentOffset=this.attachedToTaskId?Oo(e.attachmentOffset):null,this.interrupting=e.interrupting??!0,this.subprocessId=e.subprocessStart===!0&&ss.has(this.definition.kind)&&!this.attachedToTaskId&&typeof e.subprocessId=="string"&&e.subprocessId.length>0?e.subprocessId:null,this.subprocessStart=this.subprocessId!==null,f.makeObservable(this,{definition:f.observable.ref,attachedToTaskId:f.observable,attachmentOffset:f.observable.ref,interrupting:f.observable,subprocessStart:f.observable,subprocessId:f.observable,stage:f.computed,kind:f.computed,direction:f.computed,type:f.computed,isStart:f.computed,isEnd:f.computed,isCatching:f.computed,canAttach:f.computed,canStartSubprocess:f.computed,setDefinition:f.action,setType:f.action,setAttachment:f.action,setInterrupting:f.action,setSubprocessStart:f.action}),this.fitToGridSquare(),this.classList.add("bpmn__event"),this.refreshSemanticClasses(),this.refreshAttachmentPresentation()}get stage(){return this.definition.stage}get kind(){return this.definition.kind}get direction(){return this.definition.direction}get type(){return this.kind==="none"?this.stage==="start"?N.start:this.stage==="end"?N.end:N.intermediate:this.kind==="timer"?N.timer:this.kind==="message"?this.isCatching?N.messageCatch:N.messageThrow:this.kind==="signal"?this.isCatching?N.signalCatch:N.signalThrow:this.kind==="compensation"?this.isCatching?N.compensationCatch:N.compensationThrow:this.kind==="error"?this.isCatching?N.errorCatch:N.errorThrow:this.kind==="conditional"?N.conditional:this.kind==="cancel"?this.isCatching?N.cancelCatch:N.cancelThrow:this.kind==="escalation"?this.isCatching?N.escalationCatch:N.escalationThrow:this.kind==="link"?this.isCatching?N.linkCatch:N.linkThrow:this.kind==="multiple"?this.isCatching?N.multipleCatch:N.multipleThrow:this.kind==="parallelMultiple"?N.parallelMultiple:N.terminate}get isStart(){return this.stage==="start"}get isEnd(){return this.stage==="end"}get isCatching(){return this.direction==="catch"}get canAttach(){return oi.has(this.kind)&&!this.subprocessStart}get canStartSubprocess(){return ss.has(this.kind)&&!this.attachedToTaskId}setDefinition(t){return!re(t)||this.attachedToTaskId&&!oi.has(t.kind)||this.subprocessStart&&!ss.has(t.kind)?!1:Vd(this.definition,t)?!0:this.emit(new _t(this)).cancelled?!1:(this.definition=ln(t),this.isEnd?this._gateways.forEach(e=>e.outgoingEdges.forEach(i=>this.diagram?.disconnect(i))):this.isStart&&this._gateways.forEach(e=>e.incomingEdges.forEach(i=>this.diagram?.disconnect(i))),this.refreshSemanticClasses(),this.refreshAttachmentPresentation(),!0)}setType(t){const e=ai[t];return e?this.setDefinition(e):!1}setAttachment(t,e=null,i=!0){t&&!oi.has(this.kind)||(this.attachedToTaskId=t,this.attachmentOffset=t?Oo(e):null,this.interrupting=i,t&&(this.subprocessStart=!1,this.subprocessId=null),this.refreshAttachmentPresentation())}setInterrupting(t){this.interrupting=t,this.refreshAttachmentPresentation()}setSubprocessStart(t,e=null){return t?!this.canStartSubprocess||!e?!1:(this.subprocessStart=!0,this.subprocessId=e,this.refreshAttachmentPresentation(),!0):(this.subprocessStart=!1,this.subprocessId=null,this.refreshAttachmentPresentation(),!0)}serialize(){return{...super.serialize(),type:this.type,eventDefinition:ln(this.definition),attachedToTaskId:this.attachedToTaskId,attachmentOffset:this.attachmentOffset?[...this.attachmentOffset]:null,interrupting:this.interrupting,subprocessStart:this.subprocessStart,subprocessId:this.subprocessId}}deserialize(t){this.setAttachment(null),this.setSubprocessStart(!1),this.definition=Lo(t),this.setAttachment(t.attachedToTaskId??null,t.attachmentOffset??null,t.interrupting??!0),this.setSubprocessStart(t.subprocessStart??!1,t.subprocessId??null),super.deserialize(t),this.refreshSemanticClasses(),this.refreshAttachmentPresentation()}remapSerializedReferences(t,e){const i=t;if(!i.attachedToTaskId&&!i.subprocessId)return t;const s=i.attachedToTaskId?e.get(i.attachedToTaskId)??null:null,r=i.subprocessId?e.get(i.subprocessId)??null:null;return{...i,attachedToTaskId:s,attachmentOffset:s?i.attachmentOffset??null:null,subprocessId:r,subprocessStart:i.subprocessStart===!0&&r!==null}}get screenLabelBox(){const t=this.box,e=this.diagram?.getExtension(R)?.gridSize??50,i=Math.min(e*2,Math.max(t.width,e*2)),s=Math.max(this.state.labelFontSize??14,14);return new S([t.x+t.width/2-i/2,t.y+t.height+zd,i,s*Fd*$d]).sum(this.labelOffset)}refreshSemanticClasses(){[...Hd,...Bd,...Rd,...Gd].forEach(t=>this.classList.delete(t)),this.classList.add(`bpmn__event__${this.stage}`,`bpmn--${this.kind}`,`bpmn--${this.direction}`,`bpmn--${N[this.type]}`)}refreshAttachmentPresentation(){if(this.classList.delete("bpmn--boundary"),this.classList.delete("bpmn--non-interrupting"),this.classList.delete("bpmn--subprocess-start"),this.subprocessStart&&this.classList.add("bpmn--subprocess-start"),!this.attachedToTaskId){this.state.zIndex=100;return}this.classList.add("bpmn--boundary"),this.interrupting||this.classList.add("bpmn--non-interrupting"),this.state.zIndex=120}get markerIconId(){return this.kind==="none"?null:this.kind==="message"?this.isCatching?"messageCatch":"messageThrow":this.kind}RenderOverlay=A.observer(()=>{const t=this.markerIconId;return d.jsx("div",{...q(this),children:t&&d.jsx(Wt,{className:`bpmn__node_marker bpmn__event_marker bpmn__event_marker--${this.direction}`,id:t})})})};o(oa,"EventNode");let I=oa;function Ee(n,t){return`bpmn__event__${n[t]}`}o(Ee,"getEnumStr");var $=(n=>(n[n.inclusive=0]="inclusive",n[n.exclusive=1]="exclusive",n[n.parallel=2]="parallel",n[n.eventBased=3]="eventBased",n[n.complex=4]="complex",n))($||{});const Wd=5,Yd=2,Zd=1.18;function Kd(n){return typeof n?.setDefault=="function"}o(Kd,"canSetDefaultFlow");const la=class la extends lt{type=-1;edgesAsGateways=!0;occupiesGridSquare=!0;constructor(t,e){super(t,e),f.makeObservable(this,{type:f.observable,setType:f.action}),this.setType(e.type??1),this.fitToGridSquare(),this.classList.add("bpmn__gate")}setType(t){if(this.type!==t&&!this.emit(new _t(this)).cancelled){this.type=t,t!==1&&t!==0&&this.gateways.forEach(e=>e.outgoingEdges.forEach(i=>{Kd(i)&&i.setDefault(!1)}));for(const e of Object.values($))this.classList.delete(Ee($,e));switch(t){case 1:this.classList.add(Ee($,1));break;case 0:this.classList.add(Ee($,0));break;case 2:this.classList.add(Ee($,2));break;case 3:this.classList.add(Ee($,3));break;case 4:this.classList.add(Ee($,4));break}}}serialize(){return{...super.serialize(),type:this.type}}deserialize(t){this.setType(t.type??1),super.deserialize(t)}get screenLabelBox(){const t=this.box,e=Math.max(t.width,60),i=Math.max(this.state.labelFontSize??14,14);return new S([t.x+t.width/2-e/2,t.y+t.height+Wd,e,i*Zd*Yd]).sum(this.labelOffset)}RenderOverlay=A.observer(()=>{const t=this.state.box.width,e=this.state.box.height;return d.jsx("div",{...q(this),children:d.jsxs("svg",{viewBox:`0 0 ${t} ${e}`,style:{width:`${t}px`,height:`${e}px`},children:[d.jsx("polygon",{points:`${t/2} 0 ${t} ${e/2} ${t/2} ${e} 0 ${e/2}`}),d.jsx("foreignObject",{width:t,height:e,children:d.jsx(Wt,{className:"bpmn__gate_marker",markerOnly:!0,id:this.type===1?"exclusive":this.type===0?"inclusive":this.type===2?"parallel":this.type===3?"eventBased":"complex"})})]})})})};o(la,"GateNode");let V=la;const At={sections:{activities:"Activities",events:"Events",gateways:"Gateways",support:"Data & context"},elements:{task:"User task",serviceTask:"Service task",sendTask:"Send task",receiveTask:"Receive task",scriptTask:"Script task",manualTask:"Manual task",businessRuleTask:"Business rule task",callActivity:"Call activity",subprocess:"Sub-process",eventSubprocess:"Event sub-process",event:"Regular event",start:"Start event",intermediate:"Intermediate event",end:"End event",timer:"Timer event",message:"Message event",messageCatch:"Catch message",messageThrow:"Throw message",signal:"Signal event",compensation:"Compensation event",error:"Error / exception event",conditional:"Conditional / business rule event",cancel:"Cancel event",escalation:"Escalation event",link:"Link event",multiple:"Multiple event",parallelMultiple:"Parallel multiple event",terminate:"Terminate event",exclusive:"Exclusive gateway",inclusive:"Inclusive gateway",parallel:"Parallel gateway",eventBased:"Event-based gateway",complex:"Complex gateway",lanes:"Lanes",blackBoxPool:"Black-box pool",dataStore:"Data store",document:"Document",dataInput:"Data input",dataOutput:"Data output",documentAnnotation:"Document annotation",textAnnotation:"Text annotation"},eventOptions:{none:"—",start:"Start",intermediate:"Intermediate",end:"End",catch:"Catch",throw:"Throw"},actions:{transform:"Change element type",connect:"Connect to a new element",settings:"Toggle properties",close:"Close properties",delete:"Delete element",reverseDirection:"Reverse direction",resize:"Resize",resizeElement:"Resize BPMN element"},properties:{title:"Properties",name:"Name",type:"Element type",condition:"Condition",defaultFlow:"Default flow",directed:"Directed",edgeType:"Connection type",routingType:"Routing",eventType:"Event type",eventStage:"Event stage",eventDirection:"Event direction",interrupting:"Interrupting",subprocessStart:"Event sub-process start",eventSubprocessStartType:"Start event type",loop:"Conditional loop",multiInstance:"Parallel multi-instance",compensation:"Compensation",adHoc:"Ad hoc",transaction:"Transaction"},edges:{sequenceFlow:"Sequence flow",messageFlow:"Message flow",inputDataAssociation:"Input data association",outputDataAssociation:"Output data association",association:"Association"},routing:{orthogonal:"Orthogonal",straight:"Straight",curved:"Curved"},inputs:{blackBoxPoolName:"Black box pool name",documentAnnotationText:"Document annotation text",elementSearch:"Search elements",laneName:"Lane name"},resizeDirections:{n:"n",ne:"ne",e:"e",se:"se",s:"s",sw:"sw",w:"w",nw:"nw"},lanes:{defaultLane:"Default",pool:"Pool",rename:"Rename lane",insertBefore:"Insert lane before",subdivide:"Subdivide lane",removeSubdivision:"Remove subdivision",removeLane:"Remove lane",insertAfter:"Insert lane after"}};Object.values(At).forEach(Object.freeze),Object.freeze(At);function rs(n={},t=At){return{sections:{...t.sections,...n.sections},elements:{...t.elements,...n.elements},eventOptions:{...t.eventOptions,...n.eventOptions},actions:{...t.actions,...n.actions},properties:{...t.properties,...n.properties},edges:{...t.edges,...n.edges},routing:{...t.routing,...n.routing},inputs:{...t.inputs,...n.inputs},resizeDirections:{...t.resizeDirections,...n.resizeDirections},lanes:{...t.lanes,...n.lanes}}}o(rs,"configureBPMNLabels");const ca=class ca extends tt{};o(ca,"BPMNPropertyChangeEvent");let W=ca;const zo=50;function li(n,t){return n<=t?[n,t]:[t,n]}o(li,"orderedRange");function as(n,t){return Number.isFinite(t.distance)&&(!n||t.distance<n.distance)?t:n}o(as,"closer");const da=class da extends z{alignmentProposals=[];init(){f.makeObservable(this,{alignmentProposals:f.observable,clear:f.action})}clear(){this.alignmentProposals=[]}suggest(t,e,i,s=e,r){this.clear();const a=this.diagram.getExtension(Xt);if(!this.enabled||a?.enabled!==!0||t.diagram!==this.diagram)return s;const l=r??t.minimumResizeSize;if(!l)return s;const c=zo/5*2,h=zo/3,u=this.diagram.canvas.frameDimensions.norm,g=u>0?u/2:1/0,p=i.includes("w"),m=i.includes("e"),b=i.includes("n"),x=i.includes("s");let w=null,v=null;for(const E of this.diagram.nodes){if(E===t||!(E instanceof lt))continue;const j=E.box;(p||m)&&Math.abs(e.edgeDistanceY(j))<g&&(w=as(w,this.sideCandidate(l,e,j,p?"w":"e",c)),w=as(w,this.widthCandidate(l,e,j,p,c))),(b||x)&&Math.abs(e.edgeDistanceX(j))<g&&(v=as(v,this.sideCandidate(l,e,j,b?"n":"s",c)))}f.runInAction(()=>{this.alignmentProposals=[...w?.guides??[],...v?.guides??[]]});const _=s.copy();return w&&w.distance<h&&(_.x=w.box.x,_.width=w.box.width),v&&v.distance<h&&(_.y=v.box.y,_.height=v.box.height),_}sideCandidate(t,e,i,s,r){const a=e.copy();let l,c;return s==="w"?(l=Math.abs(e.x-i.x),a.x=i.x,a.width=e.rightMiddle.x-i.x,c=[this.verticalGuide(i.x,a,i)]):s==="e"?(l=Math.abs(e.rightMiddle.x-i.rightMiddle.x),a.width=i.rightMiddle.x-e.x,c=[this.verticalGuide(i.rightMiddle.x,a,i)]):s==="n"?(l=Math.abs(e.y-i.y),a.y=i.y,a.height=e.bottomMiddle.y-i.y,c=[this.horizontalGuide(i.y,a,i)]):(l=Math.abs(e.bottomMiddle.y-i.bottomMiddle.y),a.height=i.bottomMiddle.y-e.y,c=[this.horizontalGuide(i.bottomMiddle.y,a,i)]),this.candidate(t,a,l,c,r)}widthCandidate(t,e,i,s,r){const a=e.copy(),l=Math.abs(e.width-i.width);return a.width=i.width,s&&(a.x=e.rightMiddle.x-i.width),this.candidate(t,a,l,this.widthGuides(a,i),r)}candidate(t,e,i,s,r){return{box:e,distance:i<r&&this.isValid(t,e)?i:1/0,guides:s}}isValid(t,e){const i=this.diagram.canvas.size;return e.width>=t.x&&e.height>=t.y&&e.x>=0&&e.y>=0&&e.rightMiddle.x<=i.x&&e.bottomMiddle.y<=i.y}verticalGuide(t,e,i){return{type:"h",x:t,range:li(Math.min(e.y,i.y),Math.max(e.bottomMiddle.y,i.bottomMiddle.y)),id:ne("bpmn-resize-suggestion")}}horizontalGuide(t,e,i){return{type:"v",y:t,range:li(Math.min(e.x,i.x),Math.max(e.rightMiddle.x,i.rightMiddle.x)),id:ne("bpmn-resize-suggestion")}}widthGuides(t,e){return[{type:"v",y:t.y,range:li(t.x,t.rightMiddle.x),id:ne("bpmn-resize-suggestion")},{type:"v",y:e.y,range:li(e.x,e.rightMiddle.x),id:ne("bpmn-resize-suggestion")}]}};o(da,"BPMNResizeSuggester");let Jt=da;const ha=class ha extends z{autopan=new kt(this.diagram);session=null;unbindSession=o(()=>{},"unbindSession");init(){}startResize(t,e,i){if(e.button!==0||t.diagram!==this.diagram)return;e.preventDefault(),e.stopImmediatePropagation(),this.endSession();const s=new y(e);this.session={changed:!1,direction:i,initialBox:new S(t.box.raw,!1),node:t,pointer:s,startPosition:this.diagram.canvas.inverseFit(s)},this.unbindSession=Mt(Y(this,"pointermove",this.handlePointerMove),Y(this,"pointerup",this.endSession),Y(this,"pointercancel",this.endSession),Jn(this.handleAutopan,30))}resizeNode(t,e){if(t.diagram!==this.diagram)return!1;const i=e instanceof y?e:new y(e,!1),s=this.diagram.getExtension(R),r=s?.enabled===!0?s.gridSize:null,a=Math.max(0,this.diagram.canvas.size.x-t.box.x),l=Math.max(0,this.diagram.canvas.size.y-t.box.y),c=this.constrain(i.x,t.minimumResizeSize.x,a,r),h=this.constrain(i.y,t.minimumResizeSize.y,l,r);return this.applyBox(t,new S([t.box.x,t.box.y,c,h],!1))}resizeNodeFromDirection(t,e,i,s){if(t.diagram!==this.diagram)return!1;const r=this.diagram.getExtension(R),a=r?.enabled===!0?r.gridSize:null,l=i.includes("w"),c=i.includes("e"),h=i.includes("n"),u=i.includes("s"),g=l?e.x+e.width:this.diagram.canvas.size.x-e.x,p=h?e.y+e.height:this.diagram.canvas.size.y-e.y,m=e.width+(c?s.x:l?-s.x:0),b=e.height+(u?s.y:h?-s.y:0),x=l||c?this.constrain(m,t.minimumResizeSize.x,g,null):e.width,w=h||u?this.constrain(b,t.minimumResizeSize.y,p,null):e.height,v=l?e.x+e.width-x:e.x,_=h?e.y+e.height-w:e.y,E=new S([v,_,x,w],!1),j=a?this.snapDirectionalBoxToGrid(t,e,E,i,a):E,P=this.diagram.getExtension(Jt)?.suggest(t,E,i,j)??j;return this.applyBox(t,P)}snapDirectionalBoxToGrid(t,e,i,s,r){const a=i.copy(),l=e.rightMiddle.x,c=e.bottomMiddle.y;if(s.includes("w"))a.x=this.snapCoordinate(i.x,0,l-t.minimumResizeSize.x,r,e.x),a.width=l-a.x;else if(s.includes("e")){const h=this.snapCoordinate(i.rightMiddle.x,e.x+t.minimumResizeSize.x,this.diagram.canvas.size.x,r,l);a.width=h-e.x}if(s.includes("n"))a.y=this.snapCoordinate(i.y,0,c-t.minimumResizeSize.y,r,e.y),a.height=c-a.y;else if(s.includes("s")){const h=this.snapCoordinate(i.bottomMiddle.y,e.y+t.minimumResizeSize.y,this.diagram.canvas.size.y,r,c);a.height=h-e.y}return a}snapCoordinate(t,e,i,s,r){const a=Math.ceil(e/s)*s,l=Math.floor(i/s)*s;if(a>l)return r;const c=Math.round(t/s)*s;return Math.min(l,Math.max(a,c))}applyBox(t,e){return t.box.x===e.x&&t.box.y===e.y&&t.box.width===e.width&&t.box.height===e.height?!1:(f.runInAction(()=>{t.state.box.assign(e)}),this.rerouteConnectedEdges(t),!0)}constrain(t,e,i,s){const r=Number.isFinite(t)?t:e,a=Math.min(e,i),l=s?Math.ceil(a/s)*s:a,c=s?Math.round(r/s)*s:r;return Math.min(i,Math.max(l,c))}rerouteConnectedEdges(t){const e=new Set;t.gateways.forEach(i=>{i.incomingEdges.forEach(s=>e.add(s)),i.outgoingEdges.forEach(s=>e.add(s))}),e.forEach(i=>i.from.recomputeConnectedEdge(i,"from"))}handlePointerMove(t){this.session&&(this.session.pointer=new y(t),this.resizeFromPointer())}handleAutopan=o(()=>{this.session&&(this.autopan.displace(this.session.pointer),this.resizeFromPointer())},"handleAutopan");resizeFromPointer(){if(!this.session)return;const e=this.diagram.canvas.inverseFit(this.session.pointer).copy(!1).substract(this.session.startPosition),i=this.resizeNodeFromDirection(this.session.node,this.session.initialBox,this.session.direction,e);this.session.changed=this.session.changed||i}endSession(){const t=this.session?.changed===!0;this.session=null;const e=this.unbindSession;this.unbindSession=()=>{},e(),this.diagram.getExtension(Jt)?.clear(),t&&this.emit(new W(this))}};o(ha,"BPMNNodeResizer");let ci=ha;const Ud=["n","ne","e","se","s","sw","w","nw"],Xd={n:{top:"-5px",left:"50%",transform:"translateX(-50%)"},ne:{top:"-5px",right:"-5px"},e:{top:"50%",right:"-5px",transform:"translateY(-50%)"},se:{right:"-5px",bottom:"-5px"},s:{bottom:"-5px",left:"50%",transform:"translateX(-50%)"},sw:{bottom:"-5px",left:"-5px"},w:{top:"50%",left:"-5px",transform:"translateY(-50%)"},nw:{top:"-5px",left:"-5px"}},qd={n:"ns-resize",ne:"nesw-resize",e:"ew-resize",se:"nwse-resize",s:"ns-resize",sw:"nesw-resize",w:"ew-resize",nw:"nwse-resize"};function di({node:n}){const t=n.diagram?.getExtension(ci);if(!n.selected||!t||n.diagram?.rules.allowEdition===!1)return null;const e=n.diagram?.bpmnLabels??At,i=o((r,a)=>{r.button===0&&(r.preventDefault(),r.stopPropagation(),r.nativeEvent.stopImmediatePropagation(),t.startResize(n,r.nativeEvent,a))},"beginResize"),s=Dt(n,n.box);return d.jsx("div",{...s,className:"node__screenLabel bpmn__node_resize_handles",style:{...s.style,display:"block",overflow:"visible",pointerEvents:"none"},children:Ud.map(r=>d.jsx("button",{"aria-label":`${e.actions.resizeElement} ${e.resizeDirections[r]}`,className:`bpmn__node_resize_handle bpmn__node_resize_handle--${r}`,"data-diagram-interactive-ui":"true",onClick:o(a=>{a.preventDefault(),a.stopPropagation()},"onClick"),onMouseDownCapture:o(a=>{a.preventDefault(),a.stopPropagation(),a.nativeEvent.stopImmediatePropagation()},"onMouseDownCapture"),onPointerDown:o(a=>i(a,r),"onPointerDown"),style:{position:"absolute",zIndex:2,width:"11px",height:"11px",padding:0,border:"1px solid var(--node-stroke)",borderRadius:"2px",background:"var(--diagram-lane-toolbar-bg, var(--node-fill))",boxSizing:"border-box",cursor:qd[r],pointerEvents:"auto",touchAction:"none",...Xd[r]},tabIndex:-1,title:`${e.actions.resize} ${e.resizeDirections[r]}`,type:"button"},r))})}o(di,"BPMNResizeHandle");var L=(n=>(n[n.task=0]="task",n[n.service=1]="service",n[n.callActivity=2]="callActivity",n[n.subprocess=3]="subprocess",n[n.send=4]="send",n[n.receive=5]="receive",n[n.script=6]="script",n[n.manual=7]="manual",n[n.eventSubprocess=8]="eventSubprocess",n[n.businessRule=9]="businessRule",n))(L||{});const Jd={0:"task",1:"serviceTask",4:"sendTask",5:"receiveTask",6:"scriptTask",7:"manualTask",9:"businessRuleTask"},$o=new Set(Object.values(L).filter(n=>typeof n=="number"));function Fo(n){return n==="parallel"?"parallel":"none"}o(Fo,"normalizeMultiInstance");function Yt(n){return n===3||n===8}o(Yt,"isSubprocessType");function os(n){return n===3||n===2}o(os,"supportsTransaction");function Qd(n){return Yt(n)?new S([0,0,400,250]):new S([0,0,150,100])}o(Qd,"defaultTaskBox");const ua=class ua extends lt{type=-1;minimumResizeSize=new y([300,200],!1);multiInstance;loop;compensation;adHoc;transaction;edgesAsGateways=!0;constructor(t,e){super(t,{...e,box:e.box||Qd(e.type),groupChildren:Yt(e.type),zIndex:e.zIndex??(Yt(e.type)?50:100)}),this.classList.add("bpmn__task"),this.multiInstance=Fo(e.multiInstance),this.loop=e.loop===!0,this.compensation=e.compensation===!0,this.adHoc=e.adHoc===!0&&e.type===3,this.transaction=e.transaction===!0&&os(e.type),f.makeObservable(this,{type:f.observable,multiInstance:f.observable,loop:f.observable,compensation:f.observable,adHoc:f.observable,transaction:f.observable,setType:f.action,setMultiInstance:f.action,setLoop:f.action,setCompensation:f.action,setAdHoc:f.action,setTransaction:f.action}),this.setType(e.type??0)}fitWidthToGrid(t=!1){if(Yt(this.type))return;const i=(this.diagram?.getExtension(R)?.gridSize??50)*3;t&&(this.state.box.x+=(this.state.box.width-i)/2),this.state.box.width=i}applySubprocessState(t){const e=Yt(this.type);if(this.state.groupChildren=e,this.state.zIndex=e?50:100,e){this.classList.add("bpmn__resizable_node");const a=Math.max(this.state.box.width,this.minimumResizeSize.x),l=Math.max(this.state.box.height,this.minimumResizeSize.y);if(t){this.state.box.assignDimensions([a,l]);return}this.state.box.x-=(a-this.state.box.width)/2,this.state.box.y-=(l-this.state.box.height)/2,this.state.box.assignDimensions([a,l]);return}if(this.classList.delete("bpmn__resizable_node"),!t)return;const i=this.diagram?.getExtension(R)?.gridSize??50,s=i*3,r=i*2;this.state.box.x+=(this.state.box.width-s)/2,this.state.box.y+=(this.state.box.height-r)/2,this.state.box.assignDimensions([s,r])}setDiagram(t){super.setDiagram(t),this.fitWidthToGrid()}setType(t){if(!$o.has(t))return!1;if(this.type===t)return!0;if(this.emit(new _t(this)).cancelled)return!1;const e=Yt(this.type);return $o.has(this.type)&&this.classList.delete(`bpmn--${L[this.type]}`),this.type=t,t!==3&&(this.adHoc=!1),os(t)||(this.transaction=!1),this.classList.add(`bpmn--${L[t]}`),this.refreshTransactionPresentation(),this.applySubprocessState(e),!0}setMultiInstance(t){return t!=="none"&&t!=="parallel"?!1:this.multiInstance===t?!0:this.emit(new _t(this)).cancelled?!1:(this.multiInstance=t,!0)}setLoop(t){return this.loop===t?!0:this.emit(new _t(this)).cancelled?!1:(this.loop=t,!0)}setCompensation(t){return this.compensation===t?!0:this.emit(new _t(this)).cancelled?!1:(this.compensation=t,!0)}setAdHoc(t){return this.type!==3?!1:this.adHoc===t?!0:this.emit(new _t(this)).cancelled?!1:(this.adHoc=t,!0)}setTransaction(t){return os(this.type)?this.transaction===t?!0:this.emit(new _t(this)).cancelled?!1:(this.transaction=t,this.refreshTransactionPresentation(),!0):!1}serialize(){return{...super.serialize(),type:this.type,multiInstance:this.multiInstance,loop:this.loop,compensation:this.compensation,adHoc:this.adHoc,transaction:this.transaction}}deserialize(t){this.setType(t.type??0),this.setMultiInstance(Fo(t.multiInstance)),this.setLoop(t.loop===!0),this.setCompensation(t.compensation===!0),this.setAdHoc(t.adHoc===!0),this.setTransaction(t.transaction===!0),super.deserialize(t),this.applySubprocessState(Yt(this.type)),this.fitWidthToGrid(!0)}get screenLabelBox(){if(!Yt(this.type))return this.box;const t=this.box;return new S([t.x+16,t.y+8,Math.max(0,t.width-32),32])}refreshTransactionPresentation(){this.transaction?this.classList.add("bpmn--transaction"):this.classList.delete("bpmn--transaction")}RenderScreen=A.observer(()=>d.jsxs(d.Fragment,{children:[d.jsx(Mo,{node:this,box:this.screenLabelBox}),Yt(this.type)&&d.jsx(di,{node:this})]}));RenderOverlay=A.observer(()=>{const t=Jd[this.type],e=this.type===2||this.type===3,i=this.type===3&&this.adHoc;return d.jsxs("div",{...q(this),children:[t&&d.jsx(Wt,{className:"bpmn__node_marker bpmn__task_marker",id:t}),(e||this.multiInstance==="parallel"||this.loop||this.compensation||i)&&d.jsxs("span",{className:"bpmn__task_bottom_markers",children:[this.loop&&d.jsx(Md,{"aria-hidden":"true",className:"bpmn__task_loop"}),this.compensation&&d.jsx("svg",{"aria-hidden":"true",className:"bpmn__task_compensation",viewBox:"0 0 24 16",children:d.jsx("path",{d:"m11 2-7 6 7 6Zm9 0-7 6 7 6Z",fill:"none",stroke:"currentColor",strokeLinejoin:"round",strokeWidth:"2"})}),this.multiInstance==="parallel"&&d.jsx("svg",{"aria-hidden":"true",className:"bpmn__task_multi_instance",viewBox:"0 0 24 16",children:d.jsx("path",{d:"M7 2v12M12 2v12M17 2v12",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeWidth:"2"})}),e&&d.jsx("span",{className:"bpmn__task_plus",children:"+"}),i&&d.jsx("svg",{"aria-hidden":"true",className:"bpmn__task_ad_hoc",viewBox:"0 0 26 16",children:d.jsx("path",{d:"M2 9c4-7 8 7 12 0s8 7 12 0"})})]})]})})};o(ua,"TaskNode");let D=ua;const pa=class pa extends lt{sourceType="unknown";constructor(t,e){super(t,{...e,box:e.box||new S([0,0,200,100])}),this.sourceType=e.sourceType||"unknown",this.classList.add("bpmn__unknown")}serialize(){return{...super.serialize(),sourceType:this.sourceType}}deserialize(t){super.deserialize(t),this.sourceType=t.sourceType||"unknown"}RenderOverlay=A.observer(()=>d.jsx("div",{...q(this),children:d.jsx("div",{className:"bpmn__unknown__marker",children:"?"})}))};o(pa,"UnknownBPMNNode");let ke=pa;const Ho="bpmn--event-drop-inside",Bo="bpmn--event-drop-attach";function th(n){return n.canAttach}o(th,"canAttach");function eh(n){return n.type===L.subprocess||n.type===L.eventSubprocess}o(eh,"canContainEvent");function Ro(n,t){const e=n.middle,i=t.x,s=t.x+t.width,r=t.y,a=t.y+t.height,l=new y([Math.min(s,Math.max(i,e.x)),Math.min(a,Math.max(r,e.y))]);if(t.collides(e)){const u=[{distance:Math.abs(e.x-i),x:i,y:e.y},{distance:Math.abs(s-e.x),x:s,y:e.y},{distance:Math.abs(e.y-r),x:e.x,y:r},{distance:Math.abs(a-e.y),x:e.x,y:a}].reduce((g,p)=>p.distance<g.distance?p:g);l.assign([u.x,u.y])}else l.x>i&&l.x<s?l.y=e.y<r?r:a:l.y>r&&l.y<a&&(l.x=e.x<i?i:s);return new S([l.x-n.width/2,l.y-n.height/2,n.width,n.height])}o(Ro,"projectToTaskBoundary");function nh(n,t){const e=t.x+t.width-n.width,i=t.y+t.height-n.height,s=e<t.x?t.x+(t.width-n.width)/2:Math.min(e,Math.max(t.x,n.x)),r=i<t.y?t.y+(t.height-n.height)/2:Math.min(i,Math.max(t.y,n.y));return new S([s,r,n.width,n.height])}o(nh,"clampInsideContainer");const ga=class ga extends z{draggedEventIds=new Set;init(){this.diagram.onEvent(Et,t=>this.handleDrag(t),this.diagram.priorities.Drag_Node_Snap_To_Grid-1),this.diagram.onEvent(ot,()=>{this.finishEventDrags(),this.clearDropPresentations()},this.diagram.priorities.Mouse_Up_Selector-1),this.diagram.onEvent(ge,t=>{t.cancelled||!(t.node instanceof D)||[...this.attachedEvents(t.node.id),...this.subprocessEvents(t.node.id)].forEach(e=>this.diagram.delete(e))},-100)}attachedEvents(t){return this.diagram.nodes.filter(e=>e instanceof I&&e.attachedToTaskId===t)}subprocessEvents(t){return this.diagram.nodes.filter(e=>e instanceof I&&e.subprocessId===t)}handleDrag(t){this.clearDropPresentations();const e=[...t.proposals],i=new Map(e.map(s=>[s.node.id,s]));e.forEach(s=>{s.node instanceof I&&(this.draggedEventIds.add(s.node.id),this.constrainSubprocessEvent(s.node,s,i)||this.constrainAttachedEvent(s.node,s),this.presentDropTarget(s.node,s.get()))}),e.forEach(s=>{s.node instanceof D&&this.moveAttachedEvents(s.node,s.get(),i,t.proposals)})}clearDropPresentations(){this.diagram.nodes.forEach(t=>{t instanceof D&&(t.classList.delete(Ho),t.classList.delete(Bo))})}presentDropTarget(t,e){const i=this.findInternalDropTarget(e);if(i){i.classList.add(Ho);return}t.canAttach&&this.findAttachmentDropTarget(e)?.classList.add(Bo)}findInternalDropTarget(t){return this.diagram.nodes.filter(e=>e instanceof D&&eh(e)&&e.box.x<=t.x&&e.box.y<=t.y&&e.box.x+e.box.width>=t.x+t.width&&e.box.y+e.box.height>=t.y+t.height).sort((e,i)=>e.box.width*e.box.height-i.box.width*i.box.height)[0]??null}findAttachmentDropTarget(t){return this.diagram.nodes.filter(e=>e instanceof D&&e.box.collides(t,!0)).sort((e,i)=>e.box.middle.distance(t.middle)-i.box.middle.distance(t.middle))[0]??null}constrainAttachedEvent(t,e){if(!t.attachedToTaskId)return;const i=this.diagram.getNodeById(t.attachedToTaskId);if(!(i instanceof D)){t.setAttachment(null);return}const s=e.get();if(this.findInternalDropTarget(s)||!i.box.collides(s,!0)){t.setAttachment(null);return}e.update(Ro(s,i.box))}constrainSubprocessEvent(t,e,i){if(!t.subprocessStart||!t.subprocessId)return!1;const s=this.diagram.getNodeById(t.subprocessId);if(!(s instanceof D)||s.type!==L.eventSubprocess)return t.setSubprocessStart(!1),!1;const r=i.get(s.id)?.get()??s.box;return e.update(nh(e.get(),r)),!0}moveAttachedEvents(t,e,i,s){this.attachedEvents(t.id).forEach(r=>{const a=r.attachmentOffset??r.coordinates.copy(!1).substract(t.coordinates).raw,l=new S([e.x+a[0],e.y+a[1],r.box.width,r.box.height]),c=i.get(r.id);if(c)c.update(l);else{const h=new Ze(r,l);i.set(r.id,h),s.push(h)}})}finishEventDrags(){const t=[...this.draggedEventIds];this.draggedEventIds.clear(),t.forEach(e=>{const i=this.diagram.getNodeById(e);if(!(i instanceof I)||!th(i))return;const s=i.attachedToTaskId?this.diagram.getNodeById(i.attachedToTaskId):null,r=s instanceof D?s:this.findDropTask(i);if(!r)return;const a=Ro(i.box,r.box);f.runInAction(()=>{i.setPosition(a.coordinates),i.setAttachment(r.id,i.coordinates.copy(!1).substract(r.coordinates).raw,i.interrupting)})})}findDropTask(t){return this.findInternalDropTarget(t.box)?null:this.findAttachmentDropTarget(t.box)}};o(ga,"BPMNEventAttachments");let ls=ga;function Go(n){return n.children.length?n.children.reduce((t,e)=>t+Go(e),0):1}o(Go,"leafCount$1");const fa=class fa extends z{init(){this.diagram.onEvent(Et,e=>this.snapOneGridNodes(e),this.diagram.priorities.Drag_Node_Snap_To_Grid+1);const t=this.diagram.getExtension(Xt);t?.registerVerticalSuggestionProvider((e,i)=>this.enabled&&t.enabled?this.getLaneSuggestions(e,i):[]),t?.registerHorizontalSuggestionProvider((e,i)=>this.enabled&&t.enabled?this.getHorizontalLaneSuggestions(e,i):[])}snapOneGridNodes(t){const e=this.diagram.getExtension(R);if(!this.enabled||e?.enabled!==!0)return;const i=this.diagram.getClass("EventNode"),s=this.diagram.getClass("GateNode"),r=this.diagram.getClass("DocumentNode");for(const a of t.proposals){if(!(i&&a.node instanceof i)&&!(s&&a.node instanceof s)&&!(r&&a.node instanceof r))continue;const l=a.get().copy();l.x=Math.round(l.x/e.gridSize)*e.gridSize,l.y=Math.round(l.middle.y/e.gridSize)*e.gridSize-l.height/2,a.update(l),a.lockX(),a.lockY()}}resize(t,e){const i=this.diagram.getExtension(R),s=i?.gridSize??50,r=t.constructor;if("width"in e){const b=s*r.minimumWidthInGrids,x=t.box,w=this.constrain(e.width,b,null),v=new S([x.x,x.y,w,x.height],!1),_=v.copy();i?.enabled===!0&&(_.width=this.snapGrowingEdge(v.rightMiddle.x,x.x+b,s)-x.x);const E=this.diagram.getExtension(Jt)?.suggest(t,v,"e",_,new y([b,x.height],!1)).width??_.width;return t.state.box.width===E?!1:(t.state.box.width=E,!0)}const a=t.laneLayouts.find(({lane:b})=>b.name===e.laneId);if(!a)return!1;const l=Go(a.lane)*r.minimumLaneHeight,c=t.box,h=c.y+a.y,u=Math.max(l,e.height),g=new S([c.x,h,c.width,u],!1),p=g.copy();i?.enabled===!0&&(p.height=this.snapGrowingEdge(g.bottomMiddle.y,h+l,s)-h);const m=this.diagram.getExtension(Jt)?.suggest(t,g,"s",p,new y([c.width,l],!1)).height??p.height;return t.resizeLane(e.laneId,m)}snapGrowingEdge(t,e,i){const s=Math.ceil(e/i)*i,r=Math.round(t/i)*i;return Math.max(s,r)}constrain(t,e,i){const s=i?Math.ceil(e/i)*i:e,r=i?Math.round(t/i)*i:t;return Math.max(s,r)}getLaneSuggestions(t,e){const i=this.diagram.getClass("Lanes");if(!i||t instanceof i)return[];const s=this.diagram.nodes.filter(p=>p instanceof i).flatMap(p=>{const m=p.box;return p.laneLayouts.filter(({lane:b})=>b.children.length===0).map(b=>({lanes:p,laneBox:m,layout:b}))}).filter(({laneBox:p,layout:m})=>{const b=p.x+(m.depth+1)*i.laneHeaderWidth,x=p.y+m.y;return e.middle.x>=b&&e.middle.x<=p.x+p.width&&e.middle.y>=x&&e.middle.y<=x+m.height}).sort((p,m)=>m.layout.depth-p.layout.depth)[0];if(!s)return[];const r=this.diagram.getExtension(R)?.gridSize??50,{laneBox:a,layout:l}=s,c=a.y+l.y,u=[a.x+(l.depth+1)*i.laneHeaderWidth,a.x+a.width],g=[{nodeY:c+(l.height-e.height)/2,guideY:c+l.height/2,range:u}];if(l.height>r*3){const p=r/2;g.push({nodeY:c+p,guideY:c+p,range:u},{nodeY:c+l.height-p-e.height,guideY:c+l.height-p,range:u})}return g}getHorizontalLaneSuggestions(t,e){const i=this.diagram.getClass("Lanes");if(!i||t instanceof i)return[];const s=this.diagram.nodes.filter(m=>m instanceof i).flatMap(m=>{const b=m.box;return m.laneLayouts.filter(({lane:x})=>x.children.length===0).map(x=>({laneBox:b,layout:x}))}).filter(({laneBox:m,layout:b})=>{const x=m.x+(b.depth+1)*i.laneHeaderWidth,w=m.y+b.y;return e.middle.x>=x&&e.middle.x<=m.x+m.width&&e.middle.y>=w&&e.middle.y<=w+b.height}).sort((m,b)=>b.layout.depth-m.layout.depth)[0];if(!s)return[];const a=(this.diagram.getExtension(R)?.gridSize??50)/2,{laneBox:l,layout:c}=s,h=l.y+c.y,u=l.x+(c.depth+1)*i.laneHeaderWidth,g=l.x+l.width,p=[h,h+c.height];return[{nodeX:u+a,guideX:u+a,range:p},{nodeX:g-a-e.width,guideX:g-a,range:p}]}};o(fa,"BPMNGridSnap");let cn=fa;const ma=class ma extends tt{};o(ma,"BPMNLaneChangeEvent");let Qt=ma;const xa=class xa extends z{autopan=new kt(this.diagram);session=null;unbindSession=o(()=>{},"unbindSession");init(){}resizeWidth(t,e){if(e.button!==0)return;e.stopImmediatePropagation();const i=this.diagram.canvas.inverseFit(new y(e)),s=t.state.box.width;this.startSession(e,r=>{const a=this.diagram.canvas.inverseFit(r);return this.diagram.getExtension(cn).resize(t,{width:s+a.x-i.x})})}resizeHeight(t,e,i,s){if(s.button!==0)return;s.stopImmediatePropagation();const r=this.diagram.canvas.inverseFit(new y(s));this.startSession(s,a=>{const l=this.diagram.canvas.inverseFit(a);return this.diagram.getExtension(cn).resize(t,{laneId:e,height:i+l.y-r.y})})}startSession(t,e){this.endSession(),this.session={changed:!1,pointer:new y(t),resize:e},this.unbindSession=Mt(Y(this,"mousemove",this.handleMouseMove),Y(this,"mouseup",this.endSession),Jn(this.handleAutopan,30))}handleMouseMove(t){this.session&&(this.session.pointer=new y(t),this.session.changed=this.session.resize(this.session.pointer)||this.session.changed)}handleAutopan=o(()=>{this.session&&(this.autopan.displace(this.session.pointer),this.session.changed=this.session.resize(this.session.pointer)||this.session.changed)},"handleAutopan");endSession(){const t=this.session;this.session=null;const e=this.unbindSession;this.unbindSession=()=>{},e(),this.diagram?.getExtension?.(Jt)?.clear(),t?.changed&&this.emit(new Qt(this))}};o(xa,"BPMNLaneResizer");let Se=xa;const ya=class ya extends lt{minimumResizeSize=new y([300,100],!1);edgesAsGateways=!0;constructor(t,e){super(t,{...e,box:e.box||new S([0,0,500,150]),groupChildren:!1}),this.classList.add("bpmn__black_box_pool","bpmn__resizable_node")}RenderScreen=ih;RenderOverlay=A.observer(()=>{const t=this.box,e=q(this),i=1.5;return d.jsx("div",{...e,style:{...e.style,overflow:"visible",border:0,borderRadius:0,background:"transparent"},children:d.jsx("svg",{"aria-hidden":"true",preserveAspectRatio:"none",style:{display:"block",width:"100%",height:"100%"},viewBox:`0 0 ${t.width} ${t.height}`,children:d.jsx("rect",{fill:"var(--node-fill)",height:Math.max(0,t.height-i*2),stroke:"var(--node-stroke)",strokeWidth:"2",vectorEffect:"non-scaling-stroke",width:Math.max(0,t.width-i*2),x:i,y:i})})})})};o(ya,"BlackBoxPoolNode");let gt=ya;const ih=A.observer(({node:n})=>{const t=n.diagram?.bpmnLabels??At,e=k.useRef(!1),i=n.box,s=Math.min(20,i.width/4,i.height/4),r=n.state.labelFontSize??16,a=Math.min(Math.max(0,i.height-s*2),r*1.18),l=new S([i.x+s,i.y+(i.height-a)/2,Math.max(0,i.width-s*2),a]),c=Dt(n,l);c.style["--screen-label-font-size"]=`${r}px`;const h=`node__screenLabel node__screenHitArea bpmn__black_box_pool_label${n.selected?" selected":""}`,u={...c.style,display:"block",margin:0,padding:0,border:0,background:"transparent",boxSizing:"border-box",color:"var(--node-color)",fontFamily:"var(--node-font-family)",fontSize:`calc(${r}px * var(--diagram-canvas-scale, 1))`,fontWeight:n.selected?600:500,fontKerning:"normal",fontVariantLigatures:"contextual",lineHeight:1.18,letterSpacing:0,overflow:"hidden",pointerEvents:"all",textAlign:"center",whiteSpace:"pre"},g=n.diagram?.rules.allowEdition!==!1;return(!n.editionMode||!g)&&(e.current=!1),d.jsxs(d.Fragment,{children:[(!n.editionMode||!g)&&n.state.label&&d.jsx("pre",{...c,className:h,style:u,children:n.state.label}),n.editionMode&&g&&d.jsx("textarea",{...c,"aria-label":t.inputs.blackBoxPoolName,autoFocus:!0,className:h,onChange:o(p=>{f.runInAction(()=>{n.state.label=p.target.value})},"onChange"),onKeyDownCapture:o(p=>{ei(p.nativeEvent)||p.nativeEvent.stopImmediatePropagation()},"onKeyDownCapture"),onMouseDown:o(p=>p.nativeEvent.stopImmediatePropagation(),"onMouseDown"),ref:o(p=>{p&&!e.current&&(e.current=!0,p.select())},"ref"),rows:1,style:{...u,outline:0,resize:"none"},value:n.state.label,wrap:"off"}),d.jsx(di,{node:n})]})}),ba=class ba extends lt{requiredEdgePathType="straight";occupiesGridSquare=!0;constructor(t,e){super(t,e),this.fitToGridSquare(),this.classList.add("bpmn__data_store")}get screenLabelBox(){const t=this.box,e=Math.max(t.width,120),i=Math.max(this.state.labelFontSize??14,14);return new S([t.x+t.width/2-e/2,t.y+t.height+5,e,i*1.18*3]).sum(this.labelOffset)}RenderOverlay=A.observer(()=>d.jsx("div",{...q(this),children:d.jsxs("svg",{className:"bpmn__data_store_icon",viewBox:"0 0 24 24","aria-hidden":"true",children:[d.jsx("path",{className:"bpmn__data_store_body",d:"M4 6c0-2.21 3.58-4 8-4s8 1.79 8 4v12c0 2.21-3.58 4-8 4s-8-1.79-8-4Z"}),d.jsx("path",{className:"bpmn__data_store_lines",d:"M4 6c0 2.21 3.58 4 8 4s8-1.79 8-4M4 12c0 2.21 3.58 4 8 4s8-1.79 8-4"})]})}))};o(ba,"DataStoreNode");let xt=ba;const wa=class wa extends lt{minimumResizeSize=new y([0,0],!1);edgesAsGateways=!0;constructor(t,e){super(t,{...e,box:e.box||new S([0,0,180,120])}),this.classList.add("bpmn__document_annotation","bpmn__resizable_node")}findAutomaticGatewayAnchor(t){return this.findAutomaticConnectionAnchor(t)}RenderScreen=sh;RenderOverlay=A.observer(()=>{const t=this.box,e=q(this),i=1.5,s=Math.min(24,t.width/4,t.height/3),r=Math.max(i,t.width-i),a=Math.max(i,t.height-i),l=Math.max(i,r-s),c=Math.min(a,i+s);return d.jsx("div",{...e,style:{...e.style,overflow:"visible",border:0,borderRadius:0,background:"transparent"},children:d.jsxs("svg",{"aria-hidden":"true",preserveAspectRatio:"none",style:{display:"block",width:"100%",height:"100%"},viewBox:`0 0 ${t.width} ${t.height}`,children:[d.jsx("path",{d:`M ${i} ${i} H ${l} L ${r} ${c} V ${a} H ${i} Z`,fill:"var(--node-fill)",stroke:"var(--node-stroke)",strokeLinejoin:"round",strokeWidth:"2",vectorEffect:"non-scaling-stroke"}),d.jsx("path",{d:`M ${l} ${i} V ${c} H ${r}`,fill:"none",stroke:"var(--node-stroke)",strokeLinejoin:"round",strokeWidth:"2",vectorEffect:"non-scaling-stroke"})]})})})};o(wa,"DocumentAnnotationNode");let ct=wa;const sh=A.observer(({node:n})=>{const t=n.diagram?.bpmnLabels??At,e=k.useRef(!1),i=n.box,s=Math.min(8,i.width/6,i.height/6),r=new S([i.x+s,i.y+s,Math.max(0,i.width-s*2),Math.max(0,i.height-s*2)]),a=Dt(n,r);a.style["--screen-label-font-size"]=`${n.state.labelFontSize??16}px`;const l=`node__screenLabel node__screenHitArea bpmn__document_annotation_label${n.selected?" selected":""}`,c=n.diagram?.rules.allowEdition!==!1;return(!n.editionMode||!c)&&(e.current=!1),n.editionMode&&c?d.jsxs(d.Fragment,{children:[d.jsx("textarea",{...a,"aria-label":t.inputs.documentAnnotationText,autoFocus:!0,className:`${l} editable__label`,onChange:o(h=>{f.runInAction(()=>{n.state.label=h.target.value})},"onChange"),onKeyDownCapture:o(h=>{ei(h.nativeEvent)||h.nativeEvent.stopImmediatePropagation()},"onKeyDownCapture"),onMouseDown:o(h=>h.nativeEvent.stopImmediatePropagation(),"onMouseDown"),ref:o(h=>{h&&!e.current&&(e.current=!0,h.select())},"ref"),style:{...a.style,display:"block",padding:0,border:0,background:"transparent",boxSizing:"border-box",overflow:"auto",outline:0,pointerEvents:"all",resize:"none",textAlign:"center"},value:n.state.label}),d.jsx(di,{node:n})]}):d.jsxs(d.Fragment,{children:[n.state.label&&d.jsx("pre",{...a,className:l,style:{...a.style,alignItems:"center",justifyContent:"center",overflow:"hidden",padding:0,pointerEvents:"all",textAlign:"center",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:n.state.label}),d.jsx(di,{node:n})]})});var Ct=(n=>(n[n.normal=0]="normal",n[n.input=1]="input",n[n.output=2]="output",n))(Ct||{});const Vo=new Set(Object.values(Ct).filter(n=>typeof n=="number")),va=class va extends lt{type=-1;requiredEdgePathType="straight";occupiesGridSquare=!0;constructor(t,e){super(t,e),this.fitToGridSquare(),this.classList.add("bpmn__document"),f.makeObservable(this,{type:f.observable,setType:f.action}),this.setType(e.type??0)}setType(t){return Vo.has(t)?this.type===t?!0:this.emit(new _t(this)).cancelled?!1:(Vo.has(this.type)&&this.classList.delete(`bpmn--dataObject-${Ct[this.type]}`),this.type=t,this.classList.add(`bpmn--dataObject-${Ct[t]}`),!0):!1}serialize(){return{...super.serialize(),type:this.type}}deserialize(t){this.setType(t.type??0),super.deserialize(t)}get screenLabelBox(){const t=this.box,e=Math.max(t.width,120),i=Math.max(this.state.labelFontSize??16,16);return new S([t.x+t.width/2-e/2,t.y+t.height+5,e,i*1.18*3]).sum(this.labelOffset)}RenderOverlay=A.observer(()=>d.jsx("div",{...q(this),children:d.jsxs("svg",{className:"bpmn__document_icon",viewBox:"0 0 24 24","aria-hidden":"true",children:[d.jsx("path",{className:"bpmn__document_body",d:"M5 2.5h9l5 5v14H5Z"}),d.jsx("path",{className:"bpmn__document_fold",d:"M14 2.5v5h5"}),this.type!==0&&d.jsx("path",{className:"bpmn__data_object_state",d:this.type===1?"m12 11-3.5 3.5m3.5-3.5 3.5 3.5m-3.5-3.5v7":"m12 18 3.5-3.5M12 18l-3.5-3.5m3.5 3.5v-7"})]})}))};o(va,"DocumentNode");let it=va;function rh(n){n.preventDefault(),n.stopPropagation(),n.nativeEvent.stopImmediatePropagation()}o(rh,"stopToolEvent$1");const ah=A.observer(({node:n})=>{const t=n.diagram?.bpmnLabels??At,e=n.box,i=n.diagram?.rules.allowEdition!==!1,s=k.useRef(null),r=n.laneLayouts;return d.jsxs(d.Fragment,{children:[r.map(({lane:a,depth:l,y:c,height:h,siblingCount:u})=>{const g=new S([e.x+l*dt.laneHeaderWidth,e.y+c,dt.laneHeaderWidth,h]),p=Dt(n,g),m=i&&n.editingLaneId===a.name,b=l===0?u>1:u>2;return k.createElement("div",{...p,key:a.name,className:`node__screenHitArea lane__screenHeader${m?" lane__screenHeader--editing":""}${n.selected?" selected":""}`,onDoubleClick:i?()=>n.renameLane(a.name):void 0},!m&&d.jsx("span",{className:"lane__screenLabel",style:{fontSize:`calc(${dt.laneHeaderFontSize}px * var(--diagram-canvas-scale, 1))`},children:a.label}),m&&d.jsx("input",{"aria-label":t.inputs.laneName,className:"lane__screenLabelInput",autoFocus:!0,value:a.label,onMouseDown:o(x=>x.nativeEvent.stopImmediatePropagation(),"onMouseDown"),onKeyDownCapture:o(x=>{n.editionMode&&!ei(x.nativeEvent)&&x.nativeEvent.stopImmediatePropagation()},"onKeyDownCapture"),onKeyDown:o(x=>{if(x.code!=="Tab")return;x.preventDefault();const w=r.findIndex(({lane:E})=>E.name===a.name),v=x.shiftKey?-1:1,_=r[(w+v+r.length)%r.length];n.renameLane(_.lane.name)},"onKeyDown"),onChange:o(x=>{f.runInAction(()=>{a.label=x.target.value})},"onChange"),ref:o(x=>{x&&s.current!==a.name&&(s.current=a.name,x.select())},"ref")}),i&&d.jsxs("div",{className:"lane__headerTools",onMouseDown:rh,children:[d.jsx("button",{title:t.lanes.rename,"aria-label":t.lanes.rename,onClick:o(()=>n.renameLane(a.name),"onClick"),children:d.jsx(dd,{})}),d.jsx("button",{title:t.lanes.insertBefore,"aria-label":t.lanes.insertBefore,onClick:o(()=>n.insertLane(a.name,"before"),"onClick"),children:d.jsx(ld,{})}),d.jsx("button",{title:a.children.length?t.lanes.removeSubdivision:t.lanes.subdivide,"aria-label":a.children.length?t.lanes.removeSubdivision:t.lanes.subdivide,onClick:o(()=>a.children.length?n.removeSubdivision(a.name):n.subdivideLane(a.name),"onClick"),children:a.children.length?d.jsx(ud,{}):d.jsx(gd,{})}),b&&d.jsx("button",{title:t.lanes.removeLane,"aria-label":t.lanes.removeLane,onClick:o(()=>n.removeLane(a.name),"onClick"),children:d.jsx(Po,{})}),d.jsx("button",{title:t.lanes.insertAfter,"aria-label":t.lanes.insertAfter,onClick:o(()=>n.insertLane(a.name,"after"),"onClick"),children:d.jsx(cd,{})})]}))}),i&&d.jsxs(d.Fragment,{children:[d.jsx("div",{...Dt(n,new S([e.x+e.width-4,e.y,8,e.height])),className:"lane__screenWidthResizeBar",onMouseDown:o(a=>n.diagram.getExtension(Se).resizeWidth(n,a.nativeEvent),"onMouseDown")}),d.jsx("div",{...Dt(n,new S([e.x+e.width-5,e.y+e.height/2-5,10,10])),className:"lane__screenWidthResize",onMouseDown:o(a=>n.diagram.getExtension(Se).resizeWidth(n,a.nativeEvent),"onMouseDown")}),r.map(({lane:a,y:l,height:c})=>k.createElement("div",{...Dt(n,new S([e.x,e.y+l+c-3,e.width,6])),key:`resize-${a.name}`,className:"lane__screenHeightResize",onMouseDown:o(h=>n.diagram.getExtension(Se).resizeHeight(n,a.name,c,h.nativeEvent),"onMouseDown")}))]})]})});function ae(n){return n.children.length?n.children.reduce((t,e)=>t+ae(e),0):n.height}o(ae,"laneHeight");function cs(n){return n.children.length?n.children.reduce((t,e)=>t+cs(e),0):1}o(cs,"leafCount");function Wo(n,t=0,e=0){const i=[];let s=e;return n.forEach(r=>{const a=ae(r);i.push({lane:r,depth:t,y:s,height:a,siblingCount:n.length}),r.children.length&&i.push(...Wo(r.children,t+1,s)),s+=a}),i}o(Wo,"flattenLanes");function oe(n,t,e=null){for(let i=0;i<n.length;i++){const s=n[i];if(s.name===t)return{lane:s,siblings:n,index:i,parent:e};const r=oe(s.children,t,s);if(r)return r}return null}o(oe,"findLane");function Yo(n){const t=n.children.map(Yo);if(t.length!==1)return{...n,children:t};const[e]=t;return{...n,height:ae(e),children:e.children}}o(Yo,"normalizeLane");function oh(n){return n.map(Yo)}o(oh,"normalizeLanes");function Zo(n,t){if(!n.children.length){const s=Math.max(dt.minimumLaneHeight,t);return n.height===s?!1:(n.height=s,!0)}let e=!1,i=t-ae(n);for(let s=n.children.length-1;s>=0;s--){const r=n.children[s],a=ae(r),l=cs(r)*dt.minimumLaneHeight,c=Math.max(l-a,i);if(e=Zo(r,a+c)||e,i-=c,i>=0)break}return e}o(Zo,"resizeLaneLeaves");const Q=class Q extends lt{edgesAsGateways=!1;pools;constructor(t,e){super(t,{...e,label:"",zIndex:50,groupChildren:!0}),this.pools=[{label:this.labels.lanes.defaultLane,name:"default",height:Q.laneHeight,children:[]}],f.makeObservable(this,{pools:f.observable,laneLayouts:f.computed,addPool:f.action,insertLane:f.action,subdivideLane:f.action,removeSubdivision:f.action,removeLane:f.action,resizeLane:f.action,renameLane:f.action,editionLaneId:f.observable}),this.classList.add("bpm__lanes"),this.state.box.width=Q.minimumWidthInGrids*50,this._gateways.clear()}setDiagram(t){const e=this.pools.length===1&&this.pools[0].name==="default"&&this.pools[0].label===At.lanes.defaultLane;super.setDiagram(t),e&&(this.pools[0].label=this.labels.lanes.defaultLane),this.state.box.width=Math.max(this.state.box.width,t.getExtension(R).gridSize*Q.minimumWidthInGrids)}get box(){const t=this.pools.reduce((e,i)=>e+ae(i),0);return new S([this.state.box.x,this.state.box.y,this.state.box.width,t])}get laneLayouts(){return Wo(this.pools)}get editingLaneId(){return this.editionLaneId}get labels(){return this.diagram?.bpmnLabels??At}nextPool(t=[]){const e=new Set([...this.laneLayouts.map(({lane:s})=>s.name),...t]);let i=0;for(;e.has(`pool${i}`);)i++;return{label:`${this.labels.lanes.pool} ${i}`,name:`pool${i}`,height:Q.laneHeight,children:[]}}addPool(){if(this.emit(new Qt(this)).cancelled)return this.pools.at(-1);const t=this.nextPool();return this.pools.push(t),t}insertLane(t,e){const i=oe(this.pools,t);!i||this.emit(new Qt(this)).cancelled||i.siblings.splice(i.index+(e==="after"?1:0),0,this.nextPool())}subdivideLane(t){const e=oe(this.pools,t);if(!e||e.lane.children.length||this.emit(new Qt(this)).cancelled)return;const i=this.nextPool(),s=this.nextPool([i.name]),r=Math.max(e.lane.height,Q.minimumLaneHeight*2);i.height=r/2,s.height=r/2,e.lane.children=[i,s]}removeSubdivision(t){const e=oe(this.pools,t);!e||!e.lane.children.length||this.emit(new Qt(this)).cancelled||(e.lane.height=ae(e.lane),e.lane.children=[])}removeLane(t){const e=oe(this.pools,t);!e||e.siblings.length<=1||e.parent&&e.siblings.length<=2||this.emit(new Qt(this)).cancelled||e.siblings.splice(e.index,1)}resizeLane(t,e,i){const s=oe(this.pools,t);if(!s)return!1;const r=cs(s.lane)*Q.minimumLaneHeight,a=i?Math.ceil(r/i)*i:r;return Zo(s.lane,Math.max(e,a))}renameLane(t){if(oe(this.pools,t)){if(!this.editionMode){const e=this.diagram?.getExtension(ni);e?e.editNode(this):this.edit()}this.editionLaneId=t}}editionLaneId=null;previousPools=[];cancel(){this.editionLaneId=null,this.pools=this.previousPools,this.previousPools=[],super.cancel()}confirm(){return super.confirm()?(this.editionLaneId=null,this.previousPools=[],!0):!1}edit(){super.edit(),this.previousPools=on(this.pools)}resetPools(){this.pools=[]}deserialize(t){super.deserialize(t),this.pools=oh(t.pools)}serialize(){return{...super.serialize(),pools:on(this.pools)}}RenderScreen=ah;RenderOverlay=A.observer(()=>{const t=this.laneLayouts,e=this.box;return d.jsx("div",{...q(this),children:d.jsxs("svg",{className:"lane__svg",viewBox:`0 0 ${e.width} ${e.height}`,preserveAspectRatio:"none",children:[d.jsx("rect",{className:"lane__background",width:e.width,height:e.height}),t.map(({lane:i,depth:s,y:r,height:a})=>{const l=s*Q.laneHeaderWidth,c=l+Q.laneHeaderWidth,h=r;return d.jsxs("g",{children:[d.jsx("rect",{className:"lane__head",x:l,y:h,width:Q.laneHeaderWidth,height:a,onDoubleClick:o(()=>{this.diagram?.rules.allowEdition!==!1&&this.renameLane(i.name)},"onDoubleClick")}),d.jsx("rect",{className:"lane__content",x:c,y:h,width:Math.max(0,e.width-c),height:a})]},i.name)})]})})})};o(Q,"Lanes"),Ft(Q,"laneHeaderWidth",50),Ft(Q,"laneHeight",250),Ft(Q,"laneHeaderFontSize",16),Ft(Q,"minimumLaneHeight",150),Ft(Q,"minimumWidthInGrids",10);let dt=Q;const _a=class _a extends lt{edgesAsGateways=!0;requiredEdgePathType="straight";constructor(t,e){super(t,{...e,box:e.box||new S([0,0,180,90])}),this.classList.add("bpmn__text_annotation"),this._gateways.clear(),this._gateways.set("left",new Nt(this,{id:"left",orientation:"left",position:new y([0,.5]),maxIncomingConnections:1/0,maxOutgoingConnections:0,radius:0,strokeWidth:0,fill:"transparent",stroke:"transparent"}))}get box(){const t=this.state.box,i=(this.diagram?.getExtension(R)?.gridSize??50)*6,s=Math.max(this.state.labelFontSize??14,12),r=s*.58,a=(this.state.label||" ").split(`
|
|
2
|
+
`),l=Math.max(...a.map(p=>p.length),1),c=Math.min(i,Math.max(t.width,l*r+28)),h=Math.max(1,Math.floor((c-28)/r)),u=a.reduce((p,m)=>p+Math.max(1,Math.ceil(m.length/h)),0),g=Math.min(i,Math.max(t.height,u*s*1.35+24));return new S([t.x,t.y,c,g])}serialize(){return{...super.serialize(),box:this.box.raw}}findAutomaticGatewayAnchor(t){return this.findAutomaticConnectionAnchor(t)}RenderOverlay=A.observer(()=>d.jsx("div",{...q(this),children:d.jsx("span",{className:"bpmn__annotation_bracket"})}))};o(_a,"TextAnnotationNode");let ht=_a;const Me=[{id:"task",family:"task",section:"activities",priority:1,enabled:!0,connectable:!0},{id:"serviceTask",family:"task",section:"activities",priority:1,enabled:!0,connectable:!0},{id:"sendTask",family:"task",section:"activities",priority:4,enabled:!0,connectable:!0},{id:"receiveTask",family:"task",section:"activities",priority:4,enabled:!0,connectable:!0},{id:"scriptTask",family:"task",section:"activities",priority:3,enabled:!0,connectable:!0},{id:"manualTask",family:"task",section:"activities",priority:3,enabled:!0,connectable:!0},{id:"businessRuleTask",family:"task",section:"activities",priority:3,enabled:!0,connectable:!0},{id:"callActivity",family:"task",section:"activities",priority:1,enabled:!0,connectable:!0},{id:"subprocess",family:"task",section:"activities",priority:3,enabled:!0,connectable:!0},{id:"eventSubprocess",family:"task",section:"activities",priority:3,enabled:!0,connectable:!0},{id:"start",family:"event",section:"events",priority:1,enabled:!0,connectable:!0},{id:"intermediate",family:"event",section:"events",priority:1,enabled:!1,connectable:!0},{id:"end",family:"event",section:"events",priority:1,enabled:!0,connectable:!0},{id:"timer",family:"event",section:"events",priority:1,enabled:!0,connectable:!0},{id:"messageCatch",family:"event",section:"events",priority:1,enabled:!0,connectable:!0},{id:"messageThrow",family:"event",section:"events",priority:1,enabled:!0,connectable:!0},{id:"signal",family:"event",section:"events",priority:3,enabled:!0,connectable:!0},{id:"compensation",family:"event",section:"events",priority:4,enabled:!0,connectable:!0},{id:"error",family:"event",section:"events",priority:2,enabled:!0,connectable:!0},{id:"conditional",family:"event",section:"events",priority:3,enabled:!0,connectable:!0},{id:"cancel",family:"event",section:"events",priority:3,enabled:!0,connectable:!0},{id:"escalation",family:"event",section:"events",priority:3,enabled:!0,connectable:!0},{id:"link",family:"event",section:"events",priority:3,enabled:!0,connectable:!0},{id:"multiple",family:"event",section:"events",priority:3,enabled:!0,connectable:!0},{id:"parallelMultiple",family:"event",section:"events",priority:3,enabled:!0,connectable:!0},{id:"terminate",family:"event",section:"events",priority:2,enabled:!0,connectable:!0},{id:"exclusive",family:"gateway",section:"gateways",priority:1,enabled:!0,connectable:!0},{id:"inclusive",family:"gateway",section:"gateways",priority:1,enabled:!0,connectable:!0},{id:"parallel",family:"gateway",section:"gateways",priority:1,enabled:!0,connectable:!0},{id:"eventBased",family:"gateway",section:"gateways",priority:1,enabled:!0,connectable:!0},{id:"complex",family:"gateway",section:"gateways",priority:1,enabled:!0,connectable:!0},{id:"lanes",family:"lane",section:"support",priority:1,enabled:!0,connectable:!1},{id:"blackBoxPool",family:"lane",section:"support",priority:1,enabled:!0,connectable:!0},{id:"dataStore",family:"data",section:"support",priority:1,enabled:!0,connectable:!0},{id:"document",family:"data",section:"support",priority:1,enabled:!0,connectable:!0},{id:"dataInput",family:"data",section:"support",priority:1,enabled:!0,connectable:!0},{id:"dataOutput",family:"data",section:"support",priority:1,enabled:!0,connectable:!0},{id:"documentAnnotation",family:"artifact",section:"support",priority:1,enabled:!0,connectable:!0},{id:"textAnnotation",family:"artifact",section:"support",priority:1,enabled:!0,connectable:!0}],lh={start:{stage:"start",kind:"none",direction:"catch"},intermediate:{stage:"start",kind:"none",direction:"throw"},end:{stage:"end",kind:"none",direction:"throw"},timer:{stage:"intermediate",kind:"timer",direction:"catch"},messageCatch:{stage:"intermediate",kind:"message",direction:"catch"},messageThrow:{stage:"intermediate",kind:"message",direction:"throw"},signal:{stage:"intermediate",kind:"signal",direction:"catch"},compensation:{stage:"intermediate",kind:"compensation",direction:"catch"},error:{stage:"intermediate",kind:"error",direction:"catch"},conditional:{stage:"intermediate",kind:"conditional",direction:"catch"},cancel:{stage:"intermediate",kind:"cancel",direction:"catch"},escalation:{stage:"intermediate",kind:"escalation",direction:"catch"},link:{stage:"intermediate",kind:"link",direction:"catch"},multiple:{stage:"intermediate",kind:"multiple",direction:"catch"},parallelMultiple:{stage:"start",kind:"parallelMultiple",direction:"catch"},terminate:{stage:"end",kind:"terminate",direction:"throw"}},Ko={task:L.task,serviceTask:L.service,sendTask:L.send,receiveTask:L.receive,scriptTask:L.script,manualTask:L.manual,businessRuleTask:L.businessRule,callActivity:L.callActivity,subprocess:L.subprocess,eventSubprocess:L.eventSubprocess},ch=new Map(Object.entries(Ko).map(([n,t])=>[t,n]));function dh(n,t){const e=lh[t];if(!e)return null;if(t==="start"||t==="intermediate"||t==="end")return e;const i=re({...e,stage:n.stage})?n.stage:e.stage,s=re({...e,direction:n.direction})?n.direction:e.direction;return{...e,stage:i,direction:s}}o(dh,"eventDefinitionForTarget");const Ea=class Ea{static enabled(){return Me.filter(t=>t.enabled).sort((t,e)=>t.priority-e.priority)}static forNode(t){const e=this.idForNode(t);return Me.find(i=>i.id===e)}static idForNode(t){if(t instanceof D)return ch.get(t.type)??"task";if(t instanceof I)return t.kind==="none"?t.stage:t.kind==="message"?t.isCatching?"messageCatch":"messageThrow":t.kind;if(t instanceof V)return t.type===$.inclusive?"inclusive":t.type===$.parallel?"parallel":t.type===$.eventBased?"eventBased":t.type===$.complex?"complex":"exclusive";if(t instanceof dt)return"lanes";if(t instanceof gt)return"blackBoxPool";if(t instanceof xt)return"dataStore";if(t instanceof it)return t.type===Ct.input?"dataInput":t.type===Ct.output?"dataOutput":"document";if(t instanceof ct)return"documentAnnotation";if(t instanceof ht)return"textAnnotation"}static create(t,e,i){const s={id:e,label:i,movable:!0};switch(t){case"task":return new D(null,{...s,type:L.task});case"serviceTask":return new D(null,{...s,type:L.service});case"sendTask":return new D(null,{...s,type:L.send});case"receiveTask":return new D(null,{...s,type:L.receive});case"scriptTask":return new D(null,{...s,type:L.script});case"manualTask":return new D(null,{...s,type:L.manual});case"businessRuleTask":return new D(null,{...s,type:L.businessRule});case"callActivity":return new D(null,{...s,type:L.callActivity});case"subprocess":return new D(null,{...s,type:L.subprocess});case"eventSubprocess":return new D(null,{...s,type:L.eventSubprocess});case"start":return new I(null,{...s,type:N.start});case"intermediate":return new I(null,{...s,type:N.intermediate});case"end":return new I(null,{...s,type:N.end});case"timer":return new I(null,{...s,type:N.timer});case"messageCatch":return new I(null,{...s,type:N.messageCatch});case"messageThrow":return new I(null,{...s,type:N.messageThrow});case"signal":return new I(null,{...s,type:N.signalCatch});case"compensation":return new I(null,{...s,type:N.compensationCatch});case"error":return new I(null,{...s,type:N.errorCatch});case"conditional":return new I(null,{...s,type:N.conditional});case"cancel":return new I(null,{...s,type:N.cancelCatch});case"escalation":return new I(null,{...s,type:N.escalationCatch});case"link":return new I(null,{...s,type:N.linkCatch});case"multiple":return new I(null,{...s,type:N.multipleCatch});case"parallelMultiple":return new I(null,{...s,type:N.parallelMultiple});case"terminate":return new I(null,{...s,type:N.terminate});case"inclusive":return new V(null,{...s,type:$.inclusive});case"parallel":return new V(null,{...s,type:$.parallel});case"eventBased":return new V(null,{...s,type:$.eventBased});case"complex":return new V(null,{...s,type:$.complex});case"lanes":return new dt(null,{id:e});case"blackBoxPool":return new gt(null,s);case"dataStore":return new xt(null,s);case"document":return new it(null,s);case"dataInput":return new it(null,{...s,type:Ct.input});case"dataOutput":return new it(null,{...s,type:Ct.output});case"documentAnnotation":return new ct(null,s);case"textAnnotation":return new ht(null,s);default:return new V(null,{...s,type:$.exclusive})}}static transform(t,e){const i=this.forNode(t),s=Me.find(r=>r.id===e);if(!i||!s||i.family!==s.family||!s.enabled)return!1;if(t instanceof D){const r=Ko[e];return r===void 0?!1:t.setType(r)}if(t instanceof I){const r=dh(t,e);return!r||t.attachedToTaskId&&!["timer","message","signal","compensation","error","conditional"].includes(r.kind)?!1:t.setDefinition(r)}if(t instanceof V)return t.setType(e==="inclusive"?$.inclusive:e==="parallel"?$.parallel:e==="eventBased"?$.eventBased:e==="complex"?$.complex:$.exclusive),!0;if(t instanceof it){const r=e==="dataInput"?Ct.input:e==="dataOutput"?Ct.output:e==="document"?Ct.normal:null;return r===null?!1:t.setType(r)}return!1}};o(Ea,"BPMNElementCatalog");let ut=Ea;function hh(n){return n instanceof I&&n.attachedToTaskId!==null&&n.kind==="compensation"}o(hh,"isBoundaryCompensationEvent");const Nn=class Nn extends qt{kind;condition;defaultFlow;directedFlow;get isDefault(){return this.defaultFlow}get isDirected(){return this.kind==="association"||this.directedFlow}get supportsDirection(){return this.kind==="messageFlow"}get supportsDefaultFlow(){const t=this.state.from?.parent;return this.kind==="sequenceFlow"&&!!this.state.to&&t instanceof V&&(t.type===$.exclusive||t.type===$.inclusive)}constructor(t,e){super(t,e),this.kind=e.kind??(e.to?Nn.inferKind(e.from.parent,e.to.parent):null)??"sequenceFlow",this.condition=e.condition??"",this.defaultFlow=!1,this.directedFlow=e.isDirected??this.supportsDirection,f.makeObservable(this,{kind:f.observable,condition:f.observable,defaultFlow:f.observable,directedFlow:f.observable,isDefault:f.computed,isDirected:f.computed,supportsDirection:f.computed,supportsDefaultFlow:f.computed,setKind:f.action,setDefault:f.action,setDirected:f.action,reverseDirection:f.action}),this.setDefault(e.isDefault===!0)}static inferKind(t,e){return t instanceof ht||e instanceof ht||t instanceof ct||e instanceof ct?"association":hh(t)?e instanceof D&&e.compensation?"association":null:(t instanceof xt||t instanceof it)&&e instanceof D?"inputDataAssociation":t instanceof D&&(e instanceof xt||e instanceof it)?"outputDataAssociation":t instanceof gt&&(e instanceof gt||e instanceof D||e instanceof I||e instanceof V)||e instanceof gt&&(t instanceof D||t instanceof I||t instanceof V)||t instanceof I&&t.kind==="message"&&!t.isCatching&&(e instanceof D||e instanceof I||e instanceof V)?"messageFlow":(t instanceof D||t instanceof I||t instanceof V)&&(e instanceof D||e instanceof I||e instanceof V)?t instanceof I&&t.isEnd||e instanceof I&&(e.isStart||e.attachedToTaskId)||t instanceof V&&t.type===$.eventBased&&!(e instanceof I&&e.isCatching&&["message","timer","signal","conditional"].includes(e.kind)||e instanceof D&&e.type===L.receive)?null:"sequenceFlow":null}setKind(t){const e=this.supportsDirection;this.kind=t,!e&&this.supportsDirection&&(this.directedFlow=!0),this.supportsDefaultFlow||(this.defaultFlow=!1),this.applyStyle()}setDefault(t){const e=t&&this.supportsDefaultFlow;return e&&this.clearOtherDefaultFlows(),this.defaultFlow=e,this.applyStyle(),e===t}setDirected(t){return this.supportsDirection?(this.directedFlow=t,this.applyStyle(),!0):!1}applyResolvedAnchors(t,e){const i=this.defaultFlow;super.applyResolvedAnchors(t,e),i&&this.setDefault(!0)}reverseDirection(){const t=this.defaultFlow;this.defaultFlow=!1;const e=this.state.from,i=this.state.to;e.removeOutgoingEdge(this),i.removeIncomingEdge(this),this.state.from=i,this.state.to=e,this.state.steps.reverse(),[this.state.startAnchor,this.state.endAnchor]=[this.state.endAnchor,this.state.startAnchor],[this.state.displacementStart,this.state.displacementEnd]=[this.state.displacementEnd,this.state.displacementStart],i.addOutgoingEdge(this,!1),e.addIncomingEdge(this),this.kind==="inputDataAssociation"?this.kind="outputDataAssociation":this.kind==="outputDataAssociation"&&(this.kind="inputDataAssociation"),t?this.setDefault(!0):this.applyStyle()}clearOtherDefaultFlows(){const t=this.from.parent;t instanceof V&&t.gateways.forEach(e=>e.outgoingEdges.forEach(i=>{i instanceof Nn&&i!==this&&i.isDefault&&i.setDefault(!1)}))}applyStyle(){this.state.arrowSize=10,this.state.arrowHeadStart="none",this.state.arrowHeadEnd="arrow",this.state.lineStyle="solid",this.kind==="messageFlow"?(this.state.arrowHeadStart="circle-small",this.state.arrowHeadEnd=this.isDirected?"triangle":"none",this.state.lineStyle="dashed"):this.kind==="inputDataAssociation"||this.kind==="outputDataAssociation"?(this.state.arrowHeadEnd="arrow-open",this.state.lineStyle="dashed"):this.kind==="association"&&(this.state.arrowHeadEnd="arrow-open",this.state.lineStyle="dashed"),this.defaultFlow&&this.supportsDefaultFlow&&(this.state.arrowHeadStart="default-flow")}serialize(){return{...super.serialize(),kind:this.kind,condition:this.condition,isDefault:this.isDefault,isDirected:this.isDirected}}deserialize(t){super.deserialize(t),this.kind=t.kind,this.condition=t.condition,this.defaultFlow=!1,this.directedFlow=t.isDirected??this.supportsDirection,this.setDefault(t.isDefault===!0)}};o(Nn,"BPMNEdge");let yt=Nn;function Uo(n){return n.normalize("NFD").replace(new RegExp("\\p{Diacritic}","gu"),"").toLowerCase()}o(Uo,"normalizeSearchValue");function Xo({autoFocus:n,items:t,labels:e,onSelect:i,selectedId:s}){const[r,a]=k.useState(""),l=k.useRef(null),c=Uo(r.trim()),h=c?t.filter(u=>Uo(e.elements[u.id]).includes(c)):t;return k.useLayoutEffect(()=>{n&&l.current?.focus()},[n]),d.jsxs("div",{className:"bpmn__element_menu bpmn__element_menu--searchable",children:[d.jsx("input",{autoFocus:n,"aria-label":e.inputs.elementSearch,className:"bpmn__element_menu_search",onChange:o(u=>a(u.target.value),"onChange"),onMouseDown:o(u=>u.stopPropagation(),"onMouseDown"),placeholder:e.inputs.elementSearch,ref:l,type:"search",value:r}),d.jsx("div",{className:"bpmn__element_menu_items",role:"menu",children:h.map(u=>d.jsxs("button",{className:"bpmn__element_menu_item","aria-current":u.id===s?"true":void 0,onClick:o(()=>i(u),"onClick"),role:"menuitem",type:"button",children:[d.jsx(Wt,{id:u.id}),d.jsx("span",{children:e.elements[u.id]})]},u.id))})]})}o(Xo,"BPMNElementMenu");const le=8;function uh(n,t,e,i){const s=e.width-n.right,r=n.left,a=s<t.width+le&&r>s,l=a?n.left-t.width:n.right,c=l+t.width;let h=e.height-t.height-le;i&&c>i.left-le&&l<i.right+le&&(h=Math.min(h,i.top-t.height-le));const u=Math.min(Math.max(n.top-4,le),Math.max(le,h));return{left:a,top:u-n.top}}o(uh,"resolveToolbarMenuPlacement");function ph(n,t,e){const i=e.copy(!1).substract(t),s=i.x**2+i.y**2;if(s<.001)return t.copy(!1);const r=n.copy(!1).substract(t),a=Math.max(0,Math.min(1,(r.x*i.x+r.y*i.y)/s));return t.copy(!1).sum(i.multiply(a))}o(ph,"closestPointOnSegment");function gh(n,t,e){const i=t.middle;let s=n[0]?.copy(!1)??i,r=s.distance(i);for(let c=0;c<n.length-1;c+=1){const h=ph(i,n[c],n[c+1]),u=h.distance(i);u<r&&(s=h,r=u)}const a=Math.min(e,t.width/2),l=Math.min(e,t.height/2);return s.x=Math.max(t.x+a,Math.min(t.x+t.width-a,s.x)),s.y=Math.max(t.y+l,Math.min(t.y+t.height-l,s.y)),s}o(gh,"resolveVisibleEdgeToolbarAnchor");function qo(n){n.preventDefault(),n.stopPropagation(),n.nativeEvent.stopImmediatePropagation()}o(qo,"stopToolEvent");function fh(n){if(!/(?:^| )(?:bpmn__event|bpmn__gate|bpmn__data_store|bpmn__document)(?: |$)/.test(n.classList.string))return!1;const t=n.box.middle,e=n.labelScreenBox.middle,i=e.x-t.x,s=e.y-t.y;return i>0&&Math.abs(i)>Math.abs(s)}o(fh,"isRightExternalLabel");function ds({children:n,focusSearchOnClick:t=!1,icon:e,label:i,onDragStart:s}){const[r,a]=k.useState(!1),[l,c]=k.useState(!1),[h,u]=k.useState({left:!1,top:-4}),g=k.useRef(null),p=k.useRef(null),m=k.useRef(()=>{}),b=k.useRef(!1),x=k.useRef(null);k.useEffect(()=>()=>{g.current!==null&&window.clearTimeout(g.current),p.current!==null&&window.clearTimeout(p.current),m.current()},[]),k.useLayoutEffect(()=>{if(!r||!x.current)return;const C=x.current.querySelector(".bpmn__element_menu");if(!C)return;const G=x.current.getBoundingClientRect(),U=C.getBoundingClientRect(),rt=document.querySelector(".toolbar")?.getBoundingClientRect();u(uh(G,U,{width:window.innerWidth,height:window.innerHeight},rt))},[r]),k.useEffect(()=>{r&&l&&c(!1)},[l,r]);const w=o(()=>{g.current!==null&&window.clearTimeout(g.current),p.current!==null&&window.clearTimeout(p.current),g.current=null,p.current=null},"clearTimers"),v=o(()=>{w(),a(!0)},"show"),_=o(()=>{r||g.current!==null||(p.current!==null&&window.clearTimeout(p.current),p.current=null,g.current=window.setTimeout(()=>{g.current=null,a(!0)},250))},"showAfterDelay"),E=o(()=>{w(),p.current=window.setTimeout(()=>a(!1),180)},"hideSoon"),j=o(C=>{if(!s||C.button!==0)return;m.current();const G=C.clientX,U=C.clientY,rt=C,Z=o(()=>{document.removeEventListener("mousemove",et),document.removeEventListener("mouseup",Z),m.current=()=>{}},"cleanup"),et=o(at=>{if((at.buttons&1)===0){Z();return}Math.hypot(at.clientX-G,at.clientY-U)<5||(Z(),b.current=!0,s(rt))},"handleMouseMove");m.current=Z,document.addEventListener("mousemove",et),document.addEventListener("mouseup",Z)},"prepareDrag"),P=o(()=>{if(b.current){b.current=!1;return}t&&c(!0),v()},"handleClick"),M=l&&k.isValidElement(n)?k.cloneElement(n,{autoFocus:!0}):n;return d.jsxs("div",{className:`bpmn__toolbar_group${r?" bpmn__toolbar_group--open":""}${h.left?" bpmn__toolbar_group--menu-left":""}`,onBlurCapture:E,onFocusCapture:v,onMouseEnter:_,onMouseLeave:E,ref:x,style:{"--bpmn-menu-top":`${h.top}px`},children:[d.jsx("button",{"aria-expanded":r,"aria-label":i,onClick:P,onMouseDown:j,title:i,type:"button",children:e}),r&&M]})}o(ds,"ToolbarGroup");const Jo=A.observer(({extension:n})=>{const t=n.labels;return d.jsx("div",{className:"bpmn__toolbar_group",children:d.jsx("button",{"aria-label":t.actions.settings,"aria-pressed":n.propertiesPanelOpen,className:`tool${n.propertiesPanelOpen?" selected":""}`,onClick:o(()=>n.togglePropertiesPanel(),"onClick"),title:t.actions.settings,type:"button",children:d.jsx(Wt,{id:"settings"})})})}),mh=A.observer(({diagram:n,extension:t})=>{const e=t.labels,i=n.getExtension(B),s=i.selectedNodes,r=i.selectedEdges,a=n.rules?.allowEdition!==!1;return t.dragging||t.connecting||s.length+r.length!==1?null:d.jsxs(d.Fragment,{children:[s.map(l=>{if(l instanceof dt)return null;const c=a?t.transformTargets(l):[],h=ut.forNode(l),u=a?t.shapeOptions(l):[],g=a?t.connectionTargets(l):[],p=l instanceof Lt&&fh(l),m=p?l.labelScreenBox:null,b=m?new S([m.x+m.width/2,m.y+m.height+8,1,1]):new S([l.box.x+l.box.width+10,l.box.y+l.box.height/2,1,1]);return k.createElement("div",{...Dt(l,b),className:`bpmn__selection_toolbar${p?" bpmn__selection_toolbar--below-external-label":""}`,"data-diagram-interactive-ui":"true",key:l.id,onMouseDown:qo},c.length>0&&d.jsx(ds,{icon:d.jsx(Wt,{id:"transform"}),label:e.actions.transform,children:d.jsx(Xo,{items:u,labels:e,onSelect:o(x=>t.transform(l,x.id),"onSelect"),selectedId:h?.id})}),g.length>0&&d.jsx(ds,{focusSearchOnClick:!0,icon:d.jsx(Wt,{id:"connect"}),label:e.actions.connect,onDragStart:o(x=>t.startToolbarConnection(l,x),"onDragStart"),children:d.jsx(Xo,{items:g,labels:e,onSelect:o(x=>t.appendConnected(l,x.id),"onSelect")})}),d.jsx(Jo,{extension:t}))}),r.map(l=>{if(!(l instanceof yt)||l.steps.length===0)return null;const c=n.canvas.inverseFit(n.canvas.frameDimensions),h=gh(l.steps,c,48/Math.max(n.canvas.scale,.001)),u={"--screen-renderer-x":`${h.x}px`,"--screen-renderer-y":`${h.y}px`,"--screen-renderer-width":"1px","--screen-renderer-height":"1px","--screen-renderer-z-index":140};return d.jsxs("div",{className:"bpmn__selection_toolbar bpmn__selection_toolbar--edge","data-diagram-interactive-ui":"true",onMouseDown:qo,style:u,children:[a&&d.jsxs(d.Fragment,{children:[d.jsx(ds,{icon:d.jsx(Wt,{id:"transform"}),label:e.actions.transform,children:d.jsx("div",{className:"bpmn__element_menu",role:"menu",children:t.edgeKindOptions(l).filter(g=>g!==l.kind).map(g=>d.jsxs("button",{className:"bpmn__element_menu_item",onClick:o(()=>t.changeEdgeKind(l,g),"onClick"),role:"menuitem",type:"button",children:[d.jsx(Wt,{id:"connect"}),d.jsx("span",{children:e.edges[g]})]},g))})}),d.jsx("div",{className:"bpmn__toolbar_group",children:d.jsx("button",{"aria-label":e.actions.reverseDirection,onClick:o(()=>t.reverseEdge(l),"onClick"),title:e.actions.reverseDirection,type:"button",children:d.jsx(wd,{"aria-hidden":"true"})})})]}),d.jsx(Jo,{extension:t})]},l.id)})]})}),xh=["orthogonal","straight","curved"],yh=["message","error","conditional","escalation","compensation","signal","multiple"];function Qo({children:n,title:t}){const[e,i]=k.useState(!0),s=k.useId();return d.jsxs("section",{className:"bpmn__properties_section",children:[d.jsxs("button",{"aria-controls":s,"aria-expanded":e,className:"bpmn__properties_section_toggle",onClick:o(()=>i(r=>!r),"onClick"),type:"button",children:[d.jsx("span",{children:t}),d.jsx("span",{"aria-hidden":"true",className:"bpmn__properties_section_icon"})]}),d.jsx("div",{"aria-hidden":!e,className:`bpmn__properties_section_collapsible${e?" bpmn__properties_section_collapsible--open":""}`,id:s,inert:e?void 0:!0,children:d.jsx("div",{className:"bpmn__properties_section_clip",children:d.jsx("div",{className:"bpmn__properties_section_content",children:n})})})]})}o(Qo,"PropertiesSection");function bh({children:n,sections:t}){return t?d.jsxs("div",{className:"bpmn__properties_sections",children:[d.jsx(Qo,{title:t.generalTitle,children:n}),d.jsx(Qo,{title:t.additionalTitle,children:t.additionalContent})]}):d.jsx(d.Fragment,{children:n})}o(bh,"PropertiesSections");const tl=A.observer(({diagram:n,extension:t,sections:e})=>{const i=n.getExtension(B),s=i.selectedNodes.length===1?i.selectedNodes[0]:null,r=i.selectedEdges.length===1?i.selectedEdges[0]:null,a=t.propertiesPanelOpen&&!!(s||r)&&!t.dragging,l=s?ut.forNode(s):void 0,c=s?t.shapeOptions(s):[],h=t.labels,u=n.rules?.allowEdition!==!1,g=u||e?.additionalEditable===!0;return d.jsxs("aside",{"aria-hidden":!a,"aria-readonly":!g,className:`bpmn__properties_panel${a?" bpmn__properties_panel--open":""}${g?"":" bpmn__properties_panel--readonly"}`,children:[d.jsxs("header",{children:[d.jsxs("div",{children:[d.jsx("span",{children:h.properties.title}),d.jsx("strong",{children:l?h.elements[l.id]:r instanceof yt?h.edges[r.kind]:""})]}),d.jsx("button",{"aria-label":h.actions.close,onClick:o(()=>t.closePropertiesPanel(),"onClick"),title:h.actions.close,type:"button",children:"×"})]}),d.jsxs(bh,{sections:e,children:[s&&l&&d.jsxs("fieldset",{className:"bpmn__properties_fields",disabled:!u,children:[d.jsxs("label",{children:[d.jsx("span",{children:h.properties.name}),d.jsx("textarea",{onChange:o(p=>t.renameNode(s,p.target.value),"onChange"),value:s.state.label})]}),!(s instanceof I)&&c.length>1&&d.jsxs("label",{children:[d.jsx("span",{children:h.properties.type}),d.jsx("select",{onChange:o(p=>t.transform(s,p.target.value),"onChange"),value:l.id,children:c.map(p=>p&&d.jsx("option",{value:p.id,children:h.elements[p.id]},p.id))})]}),s instanceof I&&d.jsxs(d.Fragment,{children:[d.jsxs("label",{children:[d.jsx("span",{children:h.properties.eventType}),d.jsx("select",{onChange:o(p=>t.changeEventKind(s,p.target.value),"onChange"),value:s.kind,children:t.eventKindOptions(s).map(p=>d.jsx("option",{value:p,children:h.elements[p==="none"?"event":p]},p))})]}),d.jsxs("label",{children:[d.jsx("span",{children:h.properties.eventStage}),d.jsx("select",{onChange:o(p=>t.changeEventStage(s,p.target.value),"onChange"),value:s.stage,children:t.eventStageOptions(s).map(p=>d.jsx("option",{value:p,children:h.eventOptions[p]},p))})]}),s.kind!=="none"&&d.jsxs("label",{children:[d.jsx("span",{children:h.properties.eventDirection}),d.jsx("select",{onChange:o(p=>t.changeEventDirection(s,p.target.value),"onChange"),value:s.direction,children:t.eventDirectionOptions(s).map(p=>d.jsx("option",{value:p,children:h.eventOptions[p]},p))})]}),s.attachedToTaskId&&d.jsxs("label",{className:"bpmn__properties_checkbox",children:[d.jsx("input",{checked:s.interrupting,onChange:o(p=>t.changeEventInterrupting(s,p.target.checked),"onChange"),type:"checkbox"}),d.jsx("span",{children:h.properties.interrupting})]})]}),s instanceof D&&d.jsxs(d.Fragment,{children:[s.type===L.eventSubprocess&&d.jsxs("label",{children:[d.jsx("span",{children:h.properties.eventSubprocessStartType}),d.jsxs("select",{onChange:o(p=>t.changeEventSubprocessStartKind(s,p.target.value),"onChange"),value:t.eventSubprocessStartKind(s),children:[d.jsx("option",{disabled:!0,value:"",children:h.eventOptions.none}),yh.map(p=>d.jsx("option",{value:p,children:h.elements[p]},p))]})]}),d.jsxs("label",{className:"bpmn__properties_checkbox",children:[d.jsx("input",{checked:s.loop,onChange:o(p=>t.changeTaskLoop(s,p.target.checked),"onChange"),type:"checkbox"}),d.jsx("span",{children:h.properties.loop})]}),d.jsxs("label",{className:"bpmn__properties_checkbox",children:[d.jsx("input",{checked:s.multiInstance==="parallel",onChange:o(p=>t.changeTaskMultiInstance(s,p.target.checked?"parallel":"none"),"onChange"),type:"checkbox"}),d.jsx("span",{children:h.properties.multiInstance})]}),d.jsxs("label",{className:"bpmn__properties_checkbox",children:[d.jsx("input",{checked:s.compensation,onChange:o(p=>t.changeTaskCompensation(s,p.target.checked),"onChange"),type:"checkbox"}),d.jsx("span",{children:h.properties.compensation})]}),s.type===L.subprocess&&d.jsxs("label",{className:"bpmn__properties_checkbox",children:[d.jsx("input",{checked:s.adHoc,onChange:o(p=>t.changeTaskAdHoc(s,p.target.checked),"onChange"),type:"checkbox"}),d.jsx("span",{children:h.properties.adHoc})]}),[L.subprocess,L.callActivity].includes(s.type)&&d.jsxs("label",{className:"bpmn__properties_checkbox",children:[d.jsx("input",{checked:s.transaction,onChange:o(p=>t.changeTaskTransaction(s,p.target.checked),"onChange"),type:"checkbox"}),d.jsx("span",{children:h.properties.transaction})]})]})]}),r instanceof yt&&d.jsxs("fieldset",{className:"bpmn__properties_fields",disabled:!u,children:[d.jsxs("label",{children:[d.jsx("span",{children:h.properties.name}),d.jsx("input",{onChange:o(p=>t.renameEdge(r,p.target.value),"onChange"),type:"text",value:r.labels[0]?.text??""})]}),d.jsxs("label",{children:[d.jsx("span",{children:h.properties.edgeType}),d.jsx("select",{onChange:o(p=>t.changeEdgeKind(r,p.target.value),"onChange"),value:r.kind,children:t.edgeKindOptions(r).map(p=>d.jsx("option",{value:p,children:h.edges[p]},p))})]}),d.jsxs("label",{children:[d.jsx("span",{children:h.properties.routingType}),d.jsx("select",{onChange:o(p=>t.changeEdgePathType(r,p.target.value),"onChange"),value:r.pathType,children:xh.map(p=>d.jsx("option",{value:p,children:h.routing[p]},p))})]}),t.supportsCondition(r)&&d.jsxs("label",{children:[d.jsx("span",{children:h.properties.condition}),d.jsx("textarea",{onChange:o(p=>t.changeEdgeCondition(r,p.target.value),"onChange"),rows:4,value:r.condition})]}),t.supportsDefaultFlow(r)&&d.jsxs("label",{className:"bpmn__properties_checkbox",children:[d.jsx("input",{checked:r.isDefault,onChange:o(p=>t.changeEdgeDefault(r,p.target.checked),"onChange"),type:"checkbox"}),d.jsx("span",{children:h.properties.defaultFlow})]}),r.supportsDirection&&d.jsxs("label",{className:"bpmn__properties_checkbox",children:[d.jsx("input",{checked:r.isDirected,onChange:o(p=>t.changeEdgeDirected(r,p.target.checked),"onChange"),type:"checkbox"}),d.jsx("span",{children:h.properties.directed})]})]})]})]})});function wh(n,t,e){if(!(t instanceof ht||t instanceof ct)||!(t instanceof ht&&e==="documentAnnotation"||t instanceof ct&&e==="textAnnotation"))return null;const i=new Set(t.gateways.flatMap(r=>[...r.incomingEdges,...r.outgoingEdges])),s=ut.create(e,t.id,t.state.label);return f.runInAction(()=>{s.state={...t.state,box:t.box,selected:!1},n.delete(t),n.add(s),i.forEach(r=>{const a=r.from.parent===t?s.findAutomaticGatewayAnchor(r.to.parent===t?s.box.middle:r.to.parent.box.middle):r.resolveEndpointAnchor("from"),l=r.to.parent===t?s.findAutomaticGatewayAnchor(r.from.parent===t?s.box.middle:r.from.parent.box.middle):r.resolveEndpointAnchor("to");r.applyResolvedAnchors(a,l),r.setEndpointAnchor("from",r.startAnchor.mode==="automatic"?{mode:"automatic"}:{mode:"fixed",position:a.relativePosition},!1),r.setEndpointAnchor("to",r.endAnchor.mode==="automatic"?{mode:"automatic"}:{mode:"fixed",position:l.relativePosition},!1),r.parent=n,n.connectWithEdge(r.from,r.to,r),r.from.recomputeConnectedEdge(r,"from")})}),s}o(wh,"transformBPMNArtifact");const dn=new Set(["task","event","gateway"]),vh=["sequenceFlow","messageFlow","inputDataAssociation","outputDataAssociation","association"],el=["start","intermediate","end"],nl=["catch","throw"],_h=["none","message","timer","error","signal","compensation","conditional","cancel","escalation","link","multiple","parallelMultiple","terminate"],il={none:{stage:"start",kind:"none",direction:"catch"},message:{stage:"intermediate",kind:"message",direction:"catch"},timer:{stage:"intermediate",kind:"timer",direction:"catch"},error:{stage:"intermediate",kind:"error",direction:"catch"},signal:{stage:"intermediate",kind:"signal",direction:"catch"},compensation:{stage:"intermediate",kind:"compensation",direction:"catch"},conditional:{stage:"intermediate",kind:"conditional",direction:"catch"},cancel:{stage:"intermediate",kind:"cancel",direction:"catch"},escalation:{stage:"intermediate",kind:"escalation",direction:"catch"},link:{stage:"intermediate",kind:"link",direction:"catch"},multiple:{stage:"intermediate",kind:"multiple",direction:"catch"},parallelMultiple:{stage:"start",kind:"parallelMultiple",direction:"catch"},terminate:{stage:"end",kind:"terminate",direction:"throw"}},sl=new Set(["message","timer","error","signal","compensation","conditional","cancel","escalation","multiple","parallelMultiple"]),hs=new Set(["message","error","conditional","escalation","compensation","signal","multiple"]),us="bpmn-properties-panel-open",Eh=24,ka=class ka extends z{dragging=!1;propertiesPanelOpen=!1;RenderDiagram=mh;RenderUI=tl;labelConfiguration=rs();get labels(){return this.labelConfiguration??At}configureLabels(t){this.labelConfiguration=rs(t,this.labels)}init(){f.makeObservable(this,{dragging:f.observable,labelConfiguration:f.observable.ref,propertiesPanelOpen:f.observable,configureLabels:f.action}),typeof window<"u"&&(this.propertiesPanelOpen=window.localStorage.getItem(us)==="true"),this.diagram.registerClass(yt),this.diagram.setDefaultEdge(yt),this.diagram.onEvent(Ve,t=>{(!yt.inferKind(t.origin,t.target)||t.origin instanceof I&&t.origin.attachedToTaskId&&t.origin.kind==="compensation"&&t.origin.gateways.some(e=>e.outgoingEdges.some(i=>i!==t.edge)))&&t.cancel()}),this.diagram.onEvent(Et,()=>{f.runInAction(()=>{this.dragging=!0})}),this.diagram.onEvent(ot,()=>{f.runInAction(()=>{this.dragging=!1})})}transformTargets(t){const e=ut.forNode(t);if(!e)return[];const i=t.gateways.some(r=>r.incomingEdges.length),s=t.gateways.some(r=>r.outgoingEdges.length);return ut.enabled().filter(r=>!(r.family!==e.family||r.id===e.id||r.id==="start"&&i||(r.id==="end"||r.id==="terminate")&&s||t instanceof I&&t.attachedToTaskId&&!["timer","messageCatch","signal","compensation","error","conditional"].includes(r.id)))}shapeOptions(t){const e=ut.forNode(t);if(!e)return[];const i=new Set([e.id,...this.transformTargets(t).map(s=>s.id)]);return ut.enabled().filter(s=>i.has(s.id))}transform(t,e){if(!this.transformTargets(t).some(r=>r.id===e))return!1;this.emit(new W(this));const i=wh(this.diagram,t,e);if(i)return t.selected&&this.diagram.getExtension(B).selectNode(i),!0;const s=ut.transform(t,e);return s&&t instanceof V&&t.gateways.forEach(r=>r.outgoingEdges.forEach(a=>{a instanceof yt&&!a.supportsDefaultFlow&&a.setDefault(!1)})),s}connectionTargets(t){if(t instanceof I&&t.attachedToTaskId&&t.kind==="compensation")return t.gateways.some(i=>i.outgoingEdges.length)?[]:ut.enabled().filter(({id:i})=>i==="task");const e=ut.idForNode(t);return e?ut.enabled().filter(i=>{const s=i.connectable&&this.inferDefinitionKind(e,i.id);return!!s&&!(t instanceof I&&t.isEnd&&s==="sequenceFlow")}):[]}inferDefinitionKind(t,e){const i=Me.find(r=>r.id===t),s=Me.find(r=>r.id===e);return!i||!s?null:i.family==="artifact"||s.family==="artifact"?"association":i.family==="data"&&s.family==="task"?"inputDataAssociation":i.family==="task"&&s.family==="data"?"outputDataAssociation":t==="blackBoxPool"&&(e==="blackBoxPool"||dn.has(s.family))||e==="blackBoxPool"&&dn.has(i.family)||t==="messageThrow"&&dn.has(s.family)?"messageFlow":!dn.has(i.family)||!dn.has(s.family)||t==="end"||t==="terminate"||e==="start"||t==="eventBased"&&!["messageCatch","timer","signal","conditional","receiveTask"].includes(e)?null:"sequenceFlow"}appendConnected(t,e){if(!this.connectionTargets(t).some(p=>p.id===e))return null;const i=me(this.diagram,e),r=t instanceof I&&t.attachedToTaskId&&t.kind==="compensation"?new D(null,{id:i,label:this.labels.elements.task,movable:!0,type:L.task,compensation:!0}):ut.create(e,i,["event","gateway"].includes(Me.find(p=>p.id===e)?.family??"")?"":this.labels.elements[e]);this.diagram.add(r);const a=this.diagram.getExtension(R).gridSize,l=new y([t.box.x+t.box.width+a,t.box.y+t.box.height/2-r.box.height/2]),c=this.nearestAvailablePosition(r,l);if(!c)return this.diagram.delete(r),null;r.setPosition(c,{updateConnectedEdges:!1});const h=t.getGateway("right"),u=r.getGateway("left");if(!h||!u)return this.diagram.delete(r),null;this.diagram.connect(h,u,{startAnchor:{mode:"automatic",position:h.relativePosition},endAnchor:{mode:"automatic"}});const g=this.diagram.getExtension(B);return g.clearSelection(),g.selectNode(r),this.diagram.canvas.centerOnPoint(t.box.middle.copy().sum(r.box.middle).divide(2),!0),r}nearestAvailablePosition(t,e){const i=this.diagram.getExtension(R).gridSize,s=this.diagram.nodes.filter(l=>l!==t&&l.state.groupChildren!==!0).map(l=>l.box.inflate(i));let r=null,a=Number.POSITIVE_INFINITY;for(let l=0;l<=Eh;l+=1){const c=[];for(let u=-l;u<=l;u+=1)for(let g=-l;g<=l;g+=1)Math.max(Math.abs(u),Math.abs(g))===l&&c.push([u,g]);c.sort((u,g)=>{const p=u[0]**2+u[1]**2,m=g[0]**2+g[1]**2;return p!==m?p-m:this.placementDirectionRank(u)-this.placementDirectionRank(g)}),c.forEach(([u,g])=>{const p=e.copy(!1).sum([u*i,g*i]),m=p.toDimensions(t.box.size);if(!(m.x>=0&&m.y>=0&&m.x+m.width<=this.diagram.canvas.size.x&&m.y+m.height<=this.diagram.canvas.size.y)||s.some(w=>w.collides(m)))return;const x=(u*i)**2+(g*i)**2;x<a&&(r=p,a=x)});const h=(l+1)*i;if(r&&h**2>a)return r}return r}placementDirectionRank([t,e]){return e===0&&t>=0?0:t===0&&e>0?1:t===0&&e<0?2:t>=0?3:4}startToolbarConnection(t,e){this.diagram.getExtension(ve).startConnectionFromNode(t,e,"automatic")}get connecting(){return this.diagram.getExtension(ve).connecting}renameNode(t,e){this.emit(new W(this)),f.runInAction(()=>t.setState("label",e))}acceptsEventDefinition(t,e){return!re(e)||t.attachedToTaskId&&!sl.has(e.kind)?!1:!t.subprocessStart||hs.has(e.kind)}eventKindOptions(t){return _h.filter(e=>t.attachedToTaskId&&!sl.has(e)?!1:!t.subprocessStart||hs.has(e))}eventDefinitionForKind(t,e){const i=il[e],s=nl.some(a=>re({kind:e,stage:t.stage,direction:a}))?t.stage:i.stage,r=el.some(a=>re({kind:e,stage:a,direction:t.direction}))?t.direction:i.direction;return{kind:e,stage:s,direction:r}}changeEventKind(t,e){if(!this.eventKindOptions(t).includes(e))return!1;const i=this.eventDefinitionForKind(t,e);return this.acceptsEventDefinition(t,i)?(this.emit(new W(this)),t.setDefinition(i)):!1}eventStageOptions(t){return el.filter(e=>this.acceptsEventDefinition(t,{...t.definition,stage:e}))}eventDirectionOptions(t){return nl.filter(e=>this.acceptsEventDefinition(t,{...t.definition,direction:e}))}changeEventStage(t,e){const i={...t.definition,stage:e};return this.acceptsEventDefinition(t,i)?(this.emit(new W(this)),t.setDefinition(i)):!1}changeEventDirection(t,e){const i={...t.definition,direction:e};return this.acceptsEventDefinition(t,i)?(this.emit(new W(this)),t.setDefinition(i)):!1}changeEventInterrupting(t,e){t.attachedToTaskId&&(this.emit(new W(this)),f.runInAction(()=>t.setInterrupting(e)))}eventSubprocessStart(t){return this.diagram.nodes.find(e=>e instanceof I&&e.subprocessStart&&e.subprocessId===t.id)??null}containedEventCandidate(t){return this.diagram.nodes.find(e=>e instanceof I&&!e.attachedToTaskId&&!e.subprocessStart&&t.box.x<=e.box.x&&t.box.y<=e.box.y&&t.box.x+t.box.width>=e.box.x+e.box.width&&t.box.y+t.box.height>=e.box.y+e.box.height)??null}eventSubprocessStartKind(t){return this.eventSubprocessStart(t)?.kind??""}changeEventSubprocessStartKind(t,e){if(t.type!==L.eventSubprocess||!hs.has(e))return null;const i=this.eventSubprocessStart(t)??this.containedEventCandidate(t);if(this.emit(new W(this)),i)return i.setDefinition(this.eventDefinitionForKind(i,e))&&i.setSubprocessStart(!0,t.id)?i:null;const s=new I(null,{eventDefinition:il[e],id:me(this.diagram,"eventSubprocessStart"),label:"",subprocessId:t.id,subprocessStart:!0});return this.diagram.add(s),s.setPosition(new y([Math.min(t.box.x+25,t.box.x+t.box.width-s.box.width),Math.min(t.box.y+50,t.box.y+t.box.height-s.box.height)]),{updateConnectedEdges:!1}),s}changeTaskMultiInstance(t,e){return this.emit(new W(this)),t.setMultiInstance(e)}changeTaskLoop(t,e){return this.emit(new W(this)),t.setLoop(e)}changeTaskCompensation(t,e){return!e&&t.gateways.some(i=>i.incomingEdges.some(s=>s.from.parent instanceof I&&s.from.parent.attachedToTaskId&&s.from.parent.kind==="compensation"))?!1:(this.emit(new W(this)),t.setCompensation(e))}changeTaskAdHoc(t,e){return this.emit(new W(this)),t.setAdHoc(e)}changeTaskTransaction(t,e){return this.emit(new W(this)),t.setTransaction(e)}renameEdge(t,e){this.emit(new W(this)),f.runInAction(()=>t.setPrimaryLabel(e))}edgeKindOptions(t){const e=t.from.parent,i=t.to.parent;return e instanceof ht||i instanceof ht||e instanceof ct||i instanceof ct?["association"]:e instanceof gt||i instanceof gt?["messageFlow"]:e instanceof xt||e instanceof it?["inputDataAssociation"]:i instanceof xt||i instanceof it?["outputDataAssociation"]:vh}changeEdgeKind(t,e){this.edgeKindOptions(t).includes(e)&&(this.emit(new W(this)),f.runInAction(()=>t.setKind(e)))}reverseEdge(t){this.emit(new W(this)),f.runInAction(()=>t.reverseDirection())}changeEdgePathType(t,e){this.emit(new W(this)),f.runInAction(()=>t.setPathType(e))}changeEdgeCondition(t,e){this.emit(new W(this)),f.runInAction(()=>{t.condition=e})}changeEdgeDefault(t,e){return t.isDefault===e?!0:e&&!this.supportsDefaultFlow(t)?!1:(this.emit(new W(this)),t.setDefault(e))}changeEdgeDirected(t,e){!t.supportsDirection||t.isDirected===e||(this.emit(new W(this)),f.runInAction(()=>t.setDirected(e)))}supportsDefaultFlow(t){return t.supportsDefaultFlow}supportsCondition(t){if(t.kind!=="sequenceFlow")return!1;const e=t.from.parent;return!(e instanceof V&&(e.type===$.parallel||e.type===$.eventBased))}togglePropertiesPanel(){f.runInAction(()=>{this.propertiesPanelOpen=!this.propertiesPanelOpen}),typeof window<"u"&&window.localStorage.setItem(us,String(this.propertiesPanelOpen))}closePropertiesPanel(){f.runInAction(()=>{this.propertiesPanelOpen=!1}),typeof window<"u"&&window.localStorage.setItem(us,"false")}};o(ka,"BPMNModelerExtension");let ce=ka;const Sa=class Sa extends _e{constructor(t){super(t),this.registerExtension(cn),this.registerExtension(Se),this.registerExtension(Jt),this.registerExtension(ci),this.registerExtension(ce),this.getExtension(ce).configureLabels(t?.labels??{}),this.registerExtension(ls),this.registerClass(lt),this.registerClass(D),this.registerClass(I),this.registerClass(V),this.registerClass(dt),this.registerClass(ke),this.registerClass(gt),this.registerClass(xt),this.registerClass(it),this.registerClass(ct),this.registerClass(ht)}get bpmnLabels(){return this.getExtension(ce).labels}configureLabels(t){this.getExtension(ce).configureLabels(t)}};o(Sa,"BPMDiagram");let hi=Sa;const Ma=class Ma extends yt{executionId;visited=!1;visitCount=0;visitedAt=null;constructor(t,e){super(t,e),this.executionId=e.executionId??this.id,f.makeObservable(this,{executionId:f.observable,visited:f.observable,visitCount:f.observable,visitedAt:f.observable,applyExecution:f.action,resetExecution:f.action,setExecutionId:f.action}),this.applyExecution(e.execution)}get stroke(){return this.visited?this.diagram?.executionSettings?.visitedEdgeColor??"#2563eb":super.stroke}applyExecution(t){this.visited=t?.visited===!0,this.visitCount=typeof t?.visitCount=="number"&&Number.isFinite(t.visitCount)?Math.max(0,Math.floor(t.visitCount)):this.visited?1:0,this.visitedAt=typeof t?.visitedAt=="string"?t.visitedAt:null}resetExecution(){this.visited=!1,this.visitCount=0,this.visitedAt=null}setExecutionId(t){const e=t.trim();e&&(this.executionId=e)}serialize(){return{...super.serialize(),executionId:this.executionId,execution:{visited:this.visited,visitCount:this.visitCount,visitedAt:this.visitedAt}}}deserialize(t){super.deserialize(t),this.executionId=t.executionId??this.id,this.applyExecution(t.execution)}};o(Ma,"BPMNExecutionEdge");let Ot=Ma,kh=0;const Aa=class Aa{id;kind;value;message;color;constructor(t){this.id=t.id??`execution-marker-${kh++}`,this.kind=t.kind,this.value=t.value??null,this.message=t.message??"",this.color=t.color??null,f.makeAutoObservable(this)}serialize(){return{id:this.id,kind:this.kind,value:this.value,message:this.message,color:this.color??void 0}}};o(Aa,"BPMNExecutionMarker");let hn=Aa;const rl=new Set(["idle","active","waiting","completed","failed"]),ps=new Set(["token","error","waiting","completed"]);function al(n){return typeof n=="number"&&Number.isFinite(n)?Math.max(0,Math.floor(n)):0}o(al,"normalizeCount");const Ca=class Ca{currentStatus="idle";activeTokenCount=0;errorMessage="";markers=[];constructor(t){f.makeAutoObservable(this),this.apply(t)}get status(){return this.currentStatus}set status(t){this.setStatus(t)}get tokenCount(){return this.activeTokenCount}get error(){return this.errorMessage}setStatus(t){this.currentStatus=rl.has(t)?t:"idle",this.currentStatus!=="failed"&&(this.errorMessage=""),this.synchronizeStatusMarker()}setTokenCount(t){this.activeTokenCount=al(t),this.synchronizeStatusMarker()}setError(t){this.errorMessage=t?.trim()??"",this.errorMessage&&(this.currentStatus="failed"),this.synchronizeStatusMarker()}apply(t){const e=t??{};this.currentStatus=e.status&&rl.has(e.status)?e.status:"idle",this.activeTokenCount=al(e.tokenCount),this.errorMessage=e.error?.trim()??"",this.errorMessage&&(this.currentStatus="failed"),this.markers=(e.markers??[]).filter(({kind:i})=>!ps.has(i)).map(i=>new hn(i)),this.synchronizeStatusMarker()}reset(){this.currentStatus="idle",this.activeTokenCount=0,this.errorMessage="",this.markers=[]}serialize(){return{status:this.status,tokenCount:this.tokenCount,error:this.error||null,markers:this.markers.filter(({kind:t})=>!ps.has(t)).map(t=>t.serialize())}}synchronizeStatusMarker(){this.markers=this.markers.filter(e=>!ps.has(e.kind));let t=null;this.currentStatus==="active"?(this.activeTokenCount===0&&(this.activeTokenCount=1),t={id:"execution-status-active",kind:"token",value:this.activeTokenCount}):this.currentStatus==="waiting"?t={id:"execution-status-waiting",kind:"waiting"}:this.currentStatus==="completed"?t={id:"execution-status-completed",kind:"completed"}:this.currentStatus==="failed"&&(t={id:"execution-status-failed",kind:"error",message:this.errorMessage,value:"!"}),t&&this.markers.push(new hn(t))}};o(Ca,"BPMNNodeExecutionState");let st=Ca;function ui(n){return"execution"in n&&n.execution instanceof st}o(ui,"isBPMNExecutionNode");const Sh=A.observer(({diagram:n})=>{const t=n;return d.jsx(d.Fragment,{children:n.nodes.filter(ui).map(e=>{if(!e.execution.markers.length)return null;const i=Dt(e,e.box);return d.jsx("div",{className:"bpmn-execution__markers","data-execution-node-id":e.id,style:i.style,children:e.execution.markers.map(s=>{const r=s.kind==="error",a=s.kind==="waiting",l=s.kind==="completed",c=`execution-marker-${e.id}-${s.id}`,h=r?s.message||"Execution failed":s.message,u=!!h,g=r?t.executionSettings.errorColor:a?"#d97706":l?"#16a34a":t.executionSettings.tokenColor;return d.jsxs("span",{"aria-describedby":u?c:void 0,"aria-label":s.kind==="token"?`${s.value??0} active tokens`:r?"Execution error":a?"Waiting":l?"Completed":s.message||s.kind,className:`bpmn-execution__marker bpmn-execution__marker--${s.kind}${u?" bpmn-execution__marker--has-tooltip":""}`,style:{"--execution-marker-color":s.color??g},tabIndex:u?0:void 0,title:u?void 0:s.kind,children:[r?"!":a?d.jsx(_d,{"aria-hidden":"true"}):l?d.jsx(kd,{"aria-hidden":"true"}):s.value??"•",u&&d.jsx("span",{className:"bpmn-execution__marker_tooltip",id:c,role:"tooltip",children:h})]},s.id)})},e.id)})})}),Ia=class Ia extends z{RenderDiagram=Sh;init(){}};o(Ia,"BPMNExecutionExtension");let gs=Ia;const ja=class ja extends gt{execution;constructor(t,e){super(t,e),this.execution=new st(e.execution)}serialize(){return{...super.serialize(),execution:this.execution.serialize()}}deserialize(t){super.deserialize(t),this.execution.apply(t.execution)}};o(ja,"BPMNExecutionBlackBoxPoolNode");let un=ja;const Pa=class Pa extends xt{execution;constructor(t,e){super(t,e),this.execution=new st(e.execution)}serialize(){return{...super.serialize(),execution:this.execution.serialize()}}deserialize(t){super.deserialize(t),this.execution.apply(t.execution)}};o(Pa,"BPMNExecutionDataStoreNode");let pn=Pa;const Na=class Na extends ct{execution;constructor(t,e){super(t,e),this.execution=new st(e.execution)}serialize(){return{...super.serialize(),execution:this.execution.serialize()}}deserialize(t){super.deserialize(t),this.execution.apply(t.execution)}};o(Na,"BPMNExecutionDocumentAnnotationNode");let gn=Na;const Ta=class Ta extends it{execution;constructor(t,e){super(t,e),this.execution=new st(e.execution)}serialize(){return{...super.serialize(),execution:this.execution.serialize()}}deserialize(t){super.deserialize(t),this.execution.apply(t.execution)}};o(Ta,"BPMNExecutionDocumentNode");let fn=Ta;const Da=class Da extends I{execution;constructor(t,e){super(t,e),this.execution=new st(e.execution)}serialize(){return{...super.serialize(),execution:this.execution.serialize()}}deserialize(t){super.deserialize(t),this.execution.apply(t.execution)}};o(Da,"BPMNExecutionEventNode");let mn=Da;const La=class La extends V{execution;constructor(t,e){super(t,e),this.execution=new st(e.execution)}serialize(){return{...super.serialize(),execution:this.execution.serialize()}}deserialize(t){super.deserialize(t),this.execution.apply(t.execution)}};o(La,"BPMNExecutionGateNode");let xn=La;const Oa=class Oa extends dt{execution;constructor(t,e){super(t,e),this.execution=new st(e.execution)}serialize(){return{...super.serialize(),execution:this.execution.serialize()}}deserialize(t){super.deserialize(t),this.execution.apply(t.execution)}};o(Oa,"BPMNExecutionLanes");let yn=Oa;const za=class za extends D{execution;constructor(t,e){super(t,e),this.execution=new st(e.execution)}serialize(){return{...super.serialize(),execution:this.execution.serialize()}}deserialize(t){super.deserialize(t),this.execution.apply(t.execution)}};o(za,"BPMNExecutionTaskNode");let bn=za;const $a=class $a extends ht{execution;constructor(t,e){super(t,e),this.execution=new st(e.execution)}serialize(){return{...super.serialize(),execution:this.execution.serialize()}}deserialize(t){super.deserialize(t),this.execution.apply(t.execution)}};o($a,"BPMNExecutionTextAnnotationNode");let wn=$a;const Fa=class Fa extends ke{execution;constructor(t,e){super(t,e),this.execution=new st(e.execution)}serialize(){return{...super.serialize(),execution:this.execution.serialize()}}deserialize(t){super.deserialize(t),this.execution.apply(t.execution)}};o(Fa,"BPMNExecutionUnknownNode");let vn=Fa;function Mh(n){const t=n.id;if(n instanceof Ot||n.constructor!==yt)return n;Object.setPrototypeOf(n,Ot.prototype);const e=n;return e.executionId=t,e.visited=!1,e.visitCount=0,e.visitedAt=null,n}o(Mh,"promoteBPMNExecutionEdge");const Ah=new Map([[D,bn.prototype],[I,mn.prototype],[V,xn.prototype],[dt,yn.prototype],[gt,un.prototype],[xt,pn.prototype],[it,fn.prototype],[ct,gn.prototype],[ht,wn.prototype],[ke,vn.prototype]]);function Ch(n){if("execution"in n)return n;const t=Ah.get(n.constructor);return t&&(Object.setPrototypeOf(n,t),n.execution=new st),n}o(Ch,"promoteBPMNExecutionNode");const Ih=["idle","active","waiting","completed","failed"];function jh(n,t){try{const e=JSON.parse(n);Array.isArray(e)&&t(e)}catch{}}o(jh,"applyCustomMarkers");const Ph=A.observer(({diagram:n,extension:t})=>{const e=n.getExtension(B),i=e.selectedNodes.length===1?e.selectedNodes[0]:null,s=e.selectedEdges.length===1?e.selectedEdges[0]:null,r=i&&ui(i)?i:null,a=s instanceof Ot?s:null,l=n;return d.jsx(tl,{diagram:n,extension:t,sections:{generalTitle:"Datos generales",additionalTitle:"Ejecución",additionalEditable:!0,additionalContent:d.jsxs("fieldset",{className:"bpmn__properties_fields",children:[r&&d.jsxs(d.Fragment,{children:[d.jsxs("label",{children:[d.jsx("span",{children:"Status"}),d.jsx("select",{onChange:o(c=>{r.execution.status=c.target.value},"onChange"),value:r.execution.status,children:Ih.map(c=>d.jsx("option",{value:c,children:c},c))})]}),d.jsxs("label",{children:[d.jsx("span",{children:"Active tokens"}),d.jsx("input",{min:"0",onChange:o(c=>r.execution.setTokenCount(Number(c.target.value)),"onChange"),type:"number",value:r.execution.tokenCount})]}),d.jsxs("label",{children:[d.jsx("span",{children:"Exception / error"}),d.jsx("textarea",{onChange:o(c=>r.execution.setError(c.target.value||null),"onChange"),rows:3,value:r.execution.error})]}),d.jsxs("label",{children:[d.jsx("span",{children:"Custom floating markers (JSON)"}),d.jsx("textarea",{defaultValue:JSON.stringify(r.execution.serialize().markers??[],null,2),onBlur:o(c=>jh(c.target.value,h=>{r.execution.apply({...r.execution.serialize(),markers:h})}),"onBlur"),rows:5},`${r.id}-${r.execution.markers.length}`)]})]}),a&&d.jsxs(d.Fragment,{children:[d.jsxs("label",{children:[d.jsx("span",{children:"Execution flow id"}),d.jsx("input",{onChange:o(c=>a.setExecutionId(c.target.value),"onChange"),type:"text",value:a.executionId})]}),d.jsxs("label",{className:"bpmn__properties_checkbox",children:[d.jsx("input",{checked:a.visited,onChange:o(c=>a.applyExecution({visited:c.target.checked,visitCount:a.visitCount,visitedAt:a.visitedAt}),"onChange"),type:"checkbox"}),d.jsx("span",{children:"Visited"})]}),d.jsxs("label",{children:[d.jsx("span",{children:"Visit count"}),d.jsx("input",{min:"0",onChange:o(c=>a.applyExecution({visited:a.visited,visitCount:Number(c.target.value),visitedAt:a.visitedAt}),"onChange"),type:"number",value:a.visitCount})]}),d.jsxs("label",{children:[d.jsx("span",{children:"Last visited at"}),d.jsx("input",{onChange:o(c=>a.applyExecution({visited:a.visited,visitCount:a.visitCount,visitedAt:c.target.value||null}),"onChange"),placeholder:"ISO-8601 timestamp",type:"text",value:a.visitedAt??""})]})]}),d.jsxs("label",{children:[d.jsx("span",{children:"Visited flow color"}),d.jsx("input",{onChange:o(c=>l.configureExecution({visitedEdgeColor:c.target.value}),"onChange"),type:"color",value:l.executionSettings.visitedEdgeColor})]}),d.jsxs("label",{children:[d.jsx("span",{children:"Token marker color"}),d.jsx("input",{onChange:o(c=>l.configureExecution({tokenColor:c.target.value}),"onChange"),type:"color",value:l.executionSettings.tokenColor})]}),d.jsxs("label",{children:[d.jsx("span",{children:"Error marker color"}),d.jsx("input",{onChange:o(c=>l.configureExecution({errorColor:c.target.value}),"onChange"),type:"color",value:l.executionSettings.errorColor})]})]})}})}),Nh={visitedEdgeColor:"#2563eb",tokenColor:"#2563eb",errorColor:"#dc2626"},Ha=class Ha extends hi{executionSettings;restoringSerializedState=!1;constructor(t){super(t),this.rules.allowEdition=!1,f.intercept(this.rules,"allowEdition",e=>({...e,newValue:!1})),this.onEvent(tt,e=>{this.restoringSerializedState&&e.stopImmediatePropagation()},this.priorities.Mouse_Down_Rules+1),this.executionSettings=f.observable({...Nh,...t?.execution}),this.registerExecutionClasses(),this.setDefaultEdge(Ot),this.registerExtension(gs),this.getExtension(ce).RenderUI=Ph}import(t){const e=this.restoringSerializedState;this.restoringSerializedState=!0;try{super.import(t)}finally{this.restoringSerializedState=e}}async replaceReadonlyContent(t){const e=this.restoringSerializedState;this.restoringSerializedState=!0;try{return await super.reset()?(await t(),!0):!1}finally{this.restoringSerializedState=e}}add(t){return super.add(Ch(t))}connectWithEdge(t,e,i){return super.connectWithEdge(t,e,Mh(i))}configureExecution(t){f.runInAction(()=>{Object.assign(this.executionSettings,t)})}applyExecutionSnapshot(t){const e=t.nodes??{},i=t.edges??{},s=t.replace!==!1,r=[],a=[];let l=0,c=0;return f.runInAction(()=>{s&&this.clearExecution(),Object.entries(e).forEach(([h,u])=>{const g=this.getNodeById(h);if(!g||!ui(g)){r.push(h);return}g.execution.apply(u),l+=1}),Object.entries(i).forEach(([h,u])=>{const g=this.resolveExecutionEdge(h);if(!g){a.push(h);return}g.applyExecution(u),c+=1})}),{appliedNodes:l,appliedEdges:c,unresolvedNodeIds:r,unresolvedEdgeIds:a}}clearExecution(){this.nodes.forEach(t=>{ui(t)&&t.execution.reset()}),this.edges.forEach(t=>{t instanceof Ot&&t.resetExecution()})}resolveExecutionEdge(t){return this.edges.find(e=>e instanceof Ot&&(e.executionId===t||e.id===t||`${e.from.parent.id}->${e.to.parent.id}`===t))??null}registerExecutionClasses(){[[D,bn],[I,mn],[V,xn],[dt,yn],[ke,vn],[gt,un],[xt,pn],[it,fn],[ct,gn],[ht,wn],[yt,Ot]].forEach(([e,i])=>{this.registerClass(i),this.registerClass(i,e.name)})}};o(Ha,"BPMNExecutionDiagram");let fs=Ha;const Ba=class Ba extends qt{constructor(t,e){super(t,e),this.state.arrowHeadEnd=this.state.arrowHeadEnd??"arrow",this.state.arrowHeadStart=this.state.arrowHeadStart??"none",this.state.lineStyle=this.state.lineStyle??"solid",this.state.pathType=this.state.pathType??"orthogonal",this.state.strokeWidth=this.state.strokeWidth??2}};o(Ba,"CommunicationEdge");let pi=Ba;const Ra=class Ra extends Lt{constructor(t,e){super(t,{...e,box:e.box??new S([0,0,180,96]),fill:e.fill,stroke:e.stroke,label:e.label??""}),this.classList.add("communication__node","diagram__node")}};o(Ra,"CommunicationNode");let _n=Ra;const Ga=class Ga extends _n{communicationNodeType="actor";constructor(t,e){super(t,{...e,box:e.box??new S([0,0,170,90]),fill:e.fill??"#0f2230",stroke:e.stroke??"#7dd3fc",label:e.label??"Actor"}),this.classList.add("communication__node--actor")}RenderOverlay=A.observer(()=>d.jsx("div",{...q(this),children:d.jsx("div",{className:"communication__node-badge",children:"Actor"})}))};o(Ga,"CommunicationActorNode");let gi=Ga;const Va=class Va extends _n{communicationNodeType="object";constructor(t,e){super(t,{...e,box:e.box??new S([0,0,190,96]),fill:e.fill??"#182412",stroke:e.stroke??"#bef264",label:e.label??"Object"}),this.classList.add("communication__node--object")}RenderOverlay=A.observer(()=>d.jsx("div",{...q(this),children:d.jsx("div",{className:"communication__node-badge",children:"Object"})}))};o(Va,"CommunicationObjectNode");let fi=Va;const Wa=class Wa extends _n{communicationNodeType="controller";constructor(t,e){super(t,{...e,box:e.box??new S([0,0,200,100]),fill:e.fill??"#2b1618",stroke:e.stroke??"#fda4af",label:e.label??"Controller"}),this.classList.add("communication__node--controller")}RenderOverlay=A.observer(()=>d.jsx("div",{...q(this),children:d.jsx("div",{className:"communication__node-badge",children:"Controller"})}))};o(Wa,"CommunicationControllerNode");let mi=Wa;const Ya=class Ya extends _e{constructor(t){super(t),this.registerClass(gi),this.registerClass(fi),this.registerClass(mi),this.registerClass(pi),this.setDefaultEdge(pi)}get selectedNodes(){return this.getExtension(B).selectedNodes}get selectedEdges(){return this.getExtension(B).selectedEdges}createNodeFromClientPoint(t,e,i){const s=this.canvas.inverseFit(new y([e,i]));return this.createNodeAtCanvasPoint(t,s.x,s.y)}createNodeAtCanvasPoint(t,e,i){const s=this.instantiateNode(t);this.add(s);const r=new y([e-s.box.width/2,i-s.box.height/2]);return s.setPosition(r),this.getExtension(B).clearSelection(),this.getExtension(B).selectNode(s),s}createNodeInViewportCenter(t){const e=this.canvas.frameDimensions,i=new y([e.x+e.width/2,e.y+e.height/2]);return this.createNodeFromClientPoint(t,i.x,i.y)}instantiateNode(t){const e={id:me(this,"node"),label:Th(t),box:new S([0,0,180,96])};return t==="actor"?new gi(this,e):t==="controller"?new mi(this,e):new fi(this,e)}};o(Ya,"CommunicationDiagram");let ms=Ya;function Th(n){return n==="actor"?"Actor":n==="controller"?"Controller":"Object"}o(Th,"defaultLabelForType");let ol=0;function ll(){return ol+=1,`foreign-key-${ol}`}o(ll,"nextForeignKeyId");function cl(n){return/^attribute:(.+):(left|right)$/.exec(n??"")?.[1]??null}o(cl,"attributeIdFromGateway");function Dh(n){if(!n)return[];const t=n.model.attributes.filter(i=>i.primaryKey).map(i=>i.id),e=n.model.constraints.find(i=>i.kind==="primary-key");return e?.attributeIds.length?[...e.attributeIds]:t}o(Dh,"firstPrimaryKey");const Za=class Za extends qt{constraintId;mappingIndex;name;sourceAttributeIds;targetAttributeIds;sourceCardinality;targetCardinality;onDelete;onUpdate;matchType;identifying;deferrable;initiallyDeferred;constructor(t,e){super(t,e);const i=e.from?.parent,s=e.to?.parent,r=cl(e.from?.id),a=cl(e.to?.id);this.constraintId=e.constraintId??ll(),this.mappingIndex=e.mappingIndex??0,this.name=e.name??(i&&s?`fk_${i.state.label}_${s.state.label}`:"foreign_key"),this.sourceAttributeIds=e.sourceAttributeIds??(r?[r]:void 0)??i?.model.attributes.filter(l=>!l.primaryKey).slice(0,1).map(l=>l.id)??[],this.targetAttributeIds=e.targetAttributeIds??(a?[a]:void 0)??Dh(s),this.sourceCardinality=e.sourceCardinality??"zero-many",this.targetCardinality=e.targetCardinality??"one",this.onDelete=e.onDelete??"no-action",this.onUpdate=e.onUpdate??"no-action",this.matchType=e.matchType??"simple",this.identifying=e.identifying??!1,this.deferrable=e.deferrable??!1,this.initiallyDeferred=e.initiallyDeferred??!1,f.makeObservable(this,{constraintId:f.observable,mappingIndex:f.observable,name:f.observable,sourceAttributeIds:f.observable,targetAttributeIds:f.observable,sourceCardinality:f.observable,targetCardinality:f.observable,onDelete:f.observable,onUpdate:f.observable,matchType:f.observable,identifying:f.observable,deferrable:f.observable,initiallyDeferred:f.observable,updateModel:f.action}),this.applyStyle()}updateModel(t){Object.assign(this,t),this.deferrable||(this.initiallyDeferred=!1),this.applyStyle()}setSteps(t){const e=this.steps.length===0;super.setSteps(t),e&&this.labels[0]&&this.labels[0].setPosition(this.defaultLabelPosition())}applyStyle(){this.state.arrowHeadStart=this.sourceCardinality.startsWith("zero")?"circle-small":"none",this.state.arrowHeadEnd="arrow-open",this.state.arrowSize=11,this.state.lineStyle="solid",this.state.stroke="#64748b",this.state.strokeWidth=this.identifying?2:1.6,Array.isArray(this.state.labels)&&(this.mappingIndex===0?this.setPrimaryLabel(this.name):this.labels[0]&&this.removeLabel(this.labels[0],!1))}serialize(){return{...super.serialize(),constraintId:this.constraintId,mappingIndex:this.mappingIndex,name:this.name,sourceAttributeIds:[...this.sourceAttributeIds],targetAttributeIds:[...this.targetAttributeIds],sourceCardinality:this.sourceCardinality,targetCardinality:this.targetCardinality,onDelete:this.onDelete,onUpdate:this.onUpdate,matchType:this.matchType,identifying:this.identifying,deferrable:this.deferrable,initiallyDeferred:this.initiallyDeferred}}deserialize(t){super.deserialize(t),this.constraintId=t.constraintId??ll(),this.mappingIndex=t.mappingIndex??0,this.name=t.name,this.sourceAttributeIds=[...t.sourceAttributeIds],this.targetAttributeIds=[...t.targetAttributeIds],this.sourceCardinality=t.sourceCardinality,this.targetCardinality=t.targetCardinality,this.onDelete=t.onDelete,this.onUpdate=t.onUpdate,this.matchType=t.matchType,this.identifying=t.identifying,this.deferrable=t.deferrable,this.initiallyDeferred=t.initiallyDeferred,this.applyStyle()}};o(Za,"MRForeignKeyEdge");let It=Za,dl=0;function xs(n){return dl+=1,`${n}-${dl}`}o(xs,"nextElementId");function ys(n={}){return{id:xs("attribute"),name:"column",dataType:"VARCHAR",length:"255",nullable:!0,primaryKey:!1,unique:!1,autoIncrement:!1,defaultValue:"",generatedExpression:"",checkExpression:"",comment:"",...n}}o(ys,"defaultAttribute");function hl(n){return{schemaName:"public",tableKind:"table",description:"",...n,attributes:n?.attributes?.map(t=>ys(t))??[ys({name:"id",dataType:"BIGINT",length:"",nullable:!1,primaryKey:!0,autoIncrement:!0})],constraints:n?.constraints?.map(t=>({id:t.id??xs("constraint"),kind:t.kind??"unique",name:t.name??"",attributeIds:[...t.attributeIds??[]],expression:t.expression??"",indexMethod:t.indexMethod??"btree"}))??[]}}o(hl,"defaultModel");function Lh(n){return n==="primary-key"?"PK":n==="unique"?"UQ":n==="check"?"CK":"IX"}o(Lh,"constraintBadge");const Ka=class Ka extends en{model;constructor(t,e){super(t,{...e,label:e.label??"table",box:e.box??new S([0,0,310,196])}),this.model=hl(e.model),this.edgesAsGateways=!1,this.requiredEdgePathType="orthogonal",this.classList.add("mr__table",`mr__table--${this.model.tableKind}`),f.makeObservable(this,{model:f.observable,addAttribute:f.action,updateAttribute:f.action,removeAttribute:f.action,moveAttribute:f.action,addConstraint:f.action,updateConstraint:f.action,removeConstraint:f.action,updateModel:f.action}),this.fitHeightToContent(),this.syncAttributeGateways()}initializeGateways(){}setDiagram(t){super.setDiagram(t),this.fitHeightToContent(),this.syncAttributeGateways()}addAttribute(t={}){const e=ys(t);return this.model.attributes.push(e),this.fitHeightToContent(),this.syncAttributeGateways(),e}updateAttribute(t,e){const i=this.model.attributes.find(s=>s.id===t);i&&(Object.assign(i,e),i.primaryKey&&(i.nullable=!1))}removeAttribute(t){this.model.attributes=this.model.attributes.filter(e=>e.id!==t),this.model.constraints.forEach(e=>{e.attributeIds=e.attributeIds.filter(i=>i!==t)}),this.fitHeightToContent(),this.syncAttributeGateways(!0)}moveAttribute(t,e){if(t===e)return;const i=this.model.attributes.findIndex(a=>a.id===t);if(i<0||e!==null&&!this.model.attributes.some(a=>a.id===e))return;const[s]=this.model.attributes.splice(i,1),r=e===null?this.model.attributes.length:this.model.attributes.findIndex(a=>a.id===e);this.model.attributes.splice(r,0,s),this.syncAttributeGatewayPositions(!0)}addConstraint(t,e={}){const i={id:xs("constraint"),kind:t,name:`${this.state.label}_${t.replace("-","_")}`,attributeIds:[],expression:"",indexMethod:"btree",...e};return this.model.constraints.push(i),this.fitHeightToContent(),i}updateConstraint(t,e){const i=this.model.constraints.find(s=>s.id===t);i&&Object.assign(i,e)}removeConstraint(t){this.model.constraints=this.model.constraints.filter(e=>e.id!==t),this.fitHeightToContent()}updateModel(t){const e=this.model.tableKind;Object.assign(this.model,t),t.tableKind&&t.tableKind!==e&&(this.classList.delete(`mr__table--${e}`),this.classList.add(`mr__table--${t.tableKind}`))}fitHeightToContent(){const t=Math.max(1,this.model.attributes.length),e=this.model.constraints.length>0?34:0;this.state.box.height=58+t*this.attributeRowHeight+e,this.syncAttributeGatewayPositions()}get attributeRowHeight(){return this.diagram?.getExtension(R)?.gridSize??50}syncAttributeGateways(t=!1){const e=new Map(this._gateways);this._gateways.clear(),this.model.attributes.forEach(i=>{["left","right"].forEach(s=>{const r=`attribute:${i.id}:${s}`,a=e.get(r)??new Nt(this,{id:r,orientation:s,maxIncomingConnections:1/0,maxOutgoingConnections:1/0,fill:"#2563eb",stroke:"#ffffff",strokeWidth:1.5,radius:4});this._gateways.set(r,a)})}),this.syncAttributeGatewayPositions(t)}syncAttributeGatewayPositions(t=!1){this.model?.attributes.forEach((e,i)=>{const s=Math.min(.96,Math.max(.04,(58+i*this.attributeRowHeight+this.attributeRowHeight/2)/this.state.box.height));["left","right"].forEach(r=>{const a=this._gateways.get(`attribute:${e.id}:${r}`);a?.state.position.assign([r==="left"?0:1,s]),t&&a&&(a.incomingEdges.length>0||a.outgoingEdges.length>0)&&a.updateEdges()})})}gatewayForAttribute(t,e){return this._gateways.get(`attribute:${t}:${e}`)}getGateway(t){const e=super.getGateway(t);if(e)return e;const i=/^attribute:(.+):(left|right)$/.exec(String(t));if(!i)return;const s=i[2],r=new Nt(this,{id:String(t),orientation:s,maxIncomingConnections:1/0,maxOutgoingConnections:1/0});return r.state.position.assign([s==="left"?0:1,.5]),this._gateways.set(String(t),r),r}serialize(){return{...super.serialize(),model:f.toJS(this.model)}}deserialize(t){super.deserialize(t),this.model=hl(t.model),this.fitHeightToContent(),this.syncAttributeGateways()}RenderOverlay=A.observer(()=>{const t=this.state.label||"unnamed_table",e=this.model.constraints,i=q(this);return i.style["--mr-grid-size"]=`${this.attributeRowHeight}px`,d.jsxs("article",{...i,children:[d.jsxs("header",{className:"mr__table_header",children:[d.jsxs("span",{className:"mr__table_stereotype",children:["«",this.model.tableKind,"»"]}),d.jsx("strong",{children:t}),d.jsx("small",{children:this.model.schemaName})]}),d.jsx("div",{className:"mr__attribute_list",children:this.model.attributes.length===0?d.jsx("div",{className:"mr__attribute_empty",children:"No attributes"}):this.model.attributes.map(s=>{const r=this.diagram?.edges.some(a=>a.sourceAttributeIds?.includes(s.id));return d.jsxs("div",{className:"mr__attribute",children:[d.jsxs("span",{className:"mr__attribute_keys",children:[s.primaryKey&&d.jsx("b",{title:"Primary key",children:"PK"}),r&&d.jsx("b",{title:"Foreign key",children:"FK"}),s.unique&&d.jsx("b",{title:"Unique",children:"UQ"})]}),d.jsx("span",{className:"mr__attribute_name",children:s.name}),d.jsxs("code",{children:[s.dataType,s.length?`(${s.length})`:""]}),d.jsx("span",{className:"mr__attribute_null",children:s.nullable?"NULL":"NN"})]},s.id)})}),e.length>0&&d.jsx("footer",{className:"mr__constraint_badges",children:e.map(s=>d.jsxs("span",{title:s.name,children:[Lh(s.kind)," ",s.name]},s.id))})]})});RenderScreen=null};o(Ka,"MRTableNode");let Zt=Ka;const Oh=["BIGINT","INTEGER","SMALLINT","DECIMAL","NUMERIC","REAL","DOUBLE PRECISION","BOOLEAN","CHAR","VARCHAR","TEXT","DATE","TIME","TIMESTAMP","TIMESTAMPTZ","UUID","JSON","JSONB","BINARY","BLOB"],zh=[{value:"primary-key",label:"Primary key"},{value:"unique",label:"Unique key"},{value:"check",label:"CHECK"},{value:"index",label:"Index"}],ul=[{value:"no-action",label:"NO ACTION"},{value:"restrict",label:"RESTRICT"},{value:"cascade",label:"CASCADE"},{value:"set-null",label:"SET NULL"},{value:"set-default",label:"SET DEFAULT"}],pl=[{value:"zero-one",label:"0..1"},{value:"one",label:"1"},{value:"zero-many",label:"0..*"},{value:"one-many",label:"1..*"}],$h=["orthogonal","straight","curved"],gl="mr-properties-panel-width",fl=420,ml=620;function bs(n){return Array.from(n.target.selectedOptions,t=>t.value)}o(bs,"selectedValues");function Fh(){if(typeof window>"u")return ml;const n=Number(window.localStorage.getItem(gl)),t=Number.isFinite(n)&&n>0?n:ml,e=Math.min(fl,window.innerWidth-28);return Math.max(e,Math.min(window.innerWidth-56,t))}o(Fh,"initialPanelWidth");function Hh(){const[n,t]=k.useState(Fh);return{panelWidth:n,startResize:o(i=>{i.preventDefault(),i.stopPropagation();const s=i.clientX,r=n;let a=n;const l=o(h=>{const u=Math.min(fl,window.innerWidth-28),g=Math.max(u,window.innerWidth-56);a=Math.max(u,Math.min(g,r+s-h.clientX)),t(a)},"move"),c=o(()=>{window.removeEventListener("pointermove",l),window.removeEventListener("pointerup",c),window.localStorage.setItem(gl,String(a))},"finish");window.addEventListener("pointermove",l),window.addEventListener("pointerup",c,{once:!0})},"startResize")}}o(Hh,"useResizablePanelWidth");function ws({checked:n,label:t,onChange:e}){return d.jsxs("label",{className:"mr__property_checkbox",children:[d.jsx("input",{checked:n,onChange:o(i=>e(i.target.checked),"onChange"),type:"checkbox"}),d.jsx("span",{children:t})]})}o(ws,"Checkbox");const Bh=A.observer(o(function({editable:t,extension:e,node:i}){const[s,r]=k.useState(null),a=o((l,c)=>{if(l.preventDefault(),!s)return;const h=l.currentTarget,u=l.clientY>h.getBoundingClientRect().top+h.clientHeight/2,g=i.model.attributes.findIndex(m=>m.id===c),p=u?i.model.attributes[g+1]?.id??null:c;e.moveAttribute(i,s,p),r(null)},"dropAttribute");return d.jsxs("div",{className:"mr__attribute_table_scroller",children:[d.jsxs("table",{className:"mr__attribute_table",children:[d.jsx("thead",{children:d.jsxs("tr",{children:[d.jsx("th",{"aria-label":"Row actions"}),d.jsx("th",{children:"Name"}),d.jsx("th",{children:"Data type"}),d.jsx("th",{children:"Length / precision"}),d.jsx("th",{children:"Default"}),d.jsx("th",{title:"Not null",children:"NN"}),d.jsx("th",{title:"Primary key",children:"PK"}),d.jsx("th",{title:"Unique",children:"UQ"}),d.jsx("th",{title:"Identity / auto increment",children:"AI"}),d.jsx("th",{children:"Generated expression"}),d.jsx("th",{children:"Column CHECK"}),d.jsx("th",{children:"Comment"})]})}),d.jsx("tbody",{children:i.model.attributes.map(l=>{const c=o(u=>e.updateAttribute(i,l.id,u),"update"),h=o(u=>`${u} for ${l.name||"column"}`,"fieldLabel");return d.jsxs("tr",{className:s===l.id?"mr__attribute_table_row--dragging":void 0,onDragOver:o(u=>u.preventDefault(),"onDragOver"),onDrop:o(u=>a(u,l.id),"onDrop"),children:[d.jsxs("td",{className:"mr__attribute_actions",children:[d.jsx("button",{"aria-label":`Move attribute ${l.name}`,className:"mr__attribute_drag",disabled:!t,draggable:t,onDragEnd:o(()=>r(null),"onDragEnd"),onDragStart:o(u=>{r(l.id),u.dataTransfer.effectAllowed="move",u.dataTransfer.setData("text/plain",l.id)},"onDragStart"),title:"Drag to reorder attribute",type:"button",children:d.jsxs("svg",{"aria-hidden":!0,viewBox:"0 0 12 18",children:[d.jsx("circle",{cx:"3",cy:"3",r:"1.2"}),d.jsx("circle",{cx:"9",cy:"3",r:"1.2"}),d.jsx("circle",{cx:"3",cy:"9",r:"1.2"}),d.jsx("circle",{cx:"9",cy:"9",r:"1.2"}),d.jsx("circle",{cx:"3",cy:"15",r:"1.2"}),d.jsx("circle",{cx:"9",cy:"15",r:"1.2"})]})}),d.jsx("button",{"aria-label":`Delete attribute ${l.name}`,className:"mr__attribute_delete",disabled:!t,onClick:o(()=>e.removeAttribute(i,l.id),"onClick"),title:"Delete attribute",type:"button",children:d.jsx("svg",{"aria-hidden":!0,viewBox:"0 0 18 18",children:d.jsx("path",{d:"M3.5 5.25h11M7 2.75h4M5.25 5.25l.65 9h6.2l.65-9M7.5 7.5v4.25m3-4.25v4.25"})})})]}),d.jsx("td",{children:d.jsx("input",{"aria-label":h("Name"),disabled:!t,onChange:o(u=>c({name:u.target.value}),"onChange"),type:"text",value:l.name})}),d.jsx("td",{children:d.jsx("input",{"aria-label":h("Data type"),disabled:!t,list:"mr-data-types",onChange:o(u=>c({dataType:u.target.value}),"onChange"),type:"text",value:l.dataType})}),d.jsx("td",{children:d.jsx("input",{"aria-label":h("Length or precision"),disabled:!t,onChange:o(u=>c({length:u.target.value}),"onChange"),placeholder:"255 or 10,2",type:"text",value:l.length})}),d.jsx("td",{children:d.jsx("input",{"aria-label":h("Default"),disabled:!t,onChange:o(u=>c({defaultValue:u.target.value}),"onChange"),placeholder:"CURRENT_TIMESTAMP",type:"text",value:l.defaultValue})}),d.jsx("td",{children:d.jsx("input",{"aria-label":h("Not null"),checked:!l.nullable,disabled:!t,onChange:o(u=>c({nullable:!u.target.checked}),"onChange"),type:"checkbox"})}),d.jsx("td",{children:d.jsx("input",{"aria-label":h("Primary key"),checked:l.primaryKey,disabled:!t,onChange:o(u=>c({primaryKey:u.target.checked}),"onChange"),type:"checkbox"})}),d.jsx("td",{children:d.jsx("input",{"aria-label":h("Unique"),checked:l.unique,disabled:!t,onChange:o(u=>c({unique:u.target.checked}),"onChange"),type:"checkbox"})}),d.jsx("td",{children:d.jsx("input",{"aria-label":h("Auto increment"),checked:l.autoIncrement,disabled:!t,onChange:o(u=>c({autoIncrement:u.target.checked}),"onChange"),type:"checkbox"})}),d.jsx("td",{children:d.jsx("input",{"aria-label":h("Generated expression"),disabled:!t,onChange:o(u=>c({generatedExpression:u.target.value}),"onChange"),type:"text",value:l.generatedExpression})}),d.jsx("td",{children:d.jsx("input",{"aria-label":h("Column check"),disabled:!t,onChange:o(u=>c({checkExpression:u.target.value}),"onChange"),type:"text",value:l.checkExpression})}),d.jsx("td",{children:d.jsx("input",{"aria-label":h("Comment"),disabled:!t,onChange:o(u=>c({comment:u.target.value}),"onChange"),type:"text",value:l.comment})})]},l.id)})})]}),i.model.attributes.length===0&&d.jsx("p",{className:"mr__property_empty",children:"This table has no attributes."})]})},"AttributeTable2")),Rh=A.observer(o(function({constraint:t,editable:e,extension:i,node:s}){const r=o(a=>i.updateConstraint(s,t.id,a),"update");return d.jsxs("details",{className:"mr__property_card",children:[d.jsx("summary",{children:d.jsxs("span",{children:[t.kind.toUpperCase()," · ",t.name]})}),d.jsxs("div",{className:"mr__property_card_body",children:[d.jsxs("div",{className:"mr__property_grid",children:[d.jsxs("label",{children:[d.jsx("span",{children:"Type"}),d.jsx("select",{disabled:!e,onChange:o(a=>r({kind:a.target.value}),"onChange"),value:t.kind,children:zh.map(a=>d.jsx("option",{value:a.value,children:a.label},a.value))})]}),d.jsxs("label",{children:[d.jsx("span",{children:"Name"}),d.jsx("input",{disabled:!e,onChange:o(a=>r({name:a.target.value}),"onChange"),type:"text",value:t.name})]})]}),t.kind!=="check"&&d.jsxs("label",{children:[d.jsx("span",{children:"Columns (Ctrl/Cmd for multiple)"}),d.jsx("select",{disabled:!e,multiple:!0,onChange:o(a=>r({attributeIds:bs(a)}),"onChange"),value:t.attributeIds,children:s.model.attributes.map(a=>d.jsx("option",{value:a.id,children:a.name},a.id))})]}),t.kind==="check"&&d.jsxs("label",{children:[d.jsx("span",{children:"Expression"}),d.jsx("textarea",{disabled:!e,onChange:o(a=>r({expression:a.target.value}),"onChange"),rows:3,value:t.expression})]}),t.kind==="index"&&d.jsxs("label",{children:[d.jsx("span",{children:"Index method"}),d.jsx("input",{disabled:!e,onChange:o(a=>r({indexMethod:a.target.value}),"onChange"),placeholder:"btree, hash, gin…",type:"text",value:t.indexMethod})]}),d.jsx("button",{className:"mr__danger_button",disabled:!e,onClick:o(()=>i.removeConstraint(s,t.id),"onClick"),type:"button",children:"Remove constraint"})]})]})},"ConstraintEditor2")),Gh=A.observer(o(function({editable:t,extension:e,node:i}){return d.jsxs(d.Fragment,{children:[d.jsxs("section",{className:"mr__property_section",children:[d.jsx("h3",{children:"Table"}),d.jsxs("div",{className:"mr__property_grid",children:[d.jsxs("label",{children:[d.jsx("span",{children:"Name"}),d.jsx("input",{disabled:!t,onChange:o(s=>e.renameTable(i,s.target.value),"onChange"),type:"text",value:i.state.label})]}),d.jsxs("label",{children:[d.jsx("span",{children:"Schema"}),d.jsx("input",{disabled:!t,onChange:o(s=>e.updateTable(i,{schemaName:s.target.value}),"onChange"),type:"text",value:i.model.schemaName})]}),d.jsxs("label",{children:[d.jsx("span",{children:"Kind"}),d.jsxs("select",{disabled:!t,onChange:o(s=>e.updateTable(i,{tableKind:s.target.value}),"onChange"),value:i.model.tableKind,children:[d.jsx("option",{value:"table",children:"Table"}),d.jsx("option",{value:"view",children:"View"}),d.jsx("option",{value:"junction",children:"Junction table"})]})]})]}),d.jsxs("label",{children:[d.jsx("span",{children:"Description"}),d.jsx("textarea",{disabled:!t,onChange:o(s=>e.updateTable(i,{description:s.target.value}),"onChange"),rows:3,value:i.model.description})]})]}),d.jsxs("section",{className:"mr__property_section",children:[d.jsxs("div",{className:"mr__property_section_header",children:[d.jsx("h3",{children:"Attributes"}),d.jsx("button",{disabled:!t,onClick:o(()=>e.addAttribute(i),"onClick"),type:"button",children:"+ Attribute"})]}),d.jsx(Bh,{editable:t,extension:e,node:i})]}),d.jsxs("section",{className:"mr__property_section",children:[d.jsxs("div",{className:"mr__property_section_header",children:[d.jsx("h3",{children:"Constraints"}),d.jsx("button",{disabled:!t,onClick:o(()=>e.addConstraint(i,"unique"),"onClick"),type:"button",children:"+ Constraint"})]}),i.model.constraints.length===0&&d.jsx("p",{className:"mr__property_empty",children:"Add composite primary keys, unique keys, CHECK constraints or indexes."}),i.model.constraints.map(s=>d.jsx(Rh,{constraint:s,editable:t,extension:e,node:i},s.id))]})]})},"TableProperties2")),Vh=A.observer(o(function({edge:t,editable:e,extension:i}){const s=t.from.parent,r=t.to.parent,a=o(l=>i.updateForeignKey(t,l),"update");return d.jsxs(d.Fragment,{children:[d.jsxs("section",{className:"mr__property_section",children:[d.jsx("h3",{children:"Foreign key"}),d.jsxs("label",{children:[d.jsx("span",{children:"Constraint name"}),d.jsx("input",{disabled:!e,onChange:o(l=>a({name:l.target.value}),"onChange"),type:"text",value:t.name})]}),d.jsxs("div",{className:"mr__relationship_summary",children:[d.jsxs("span",{children:[s.model.schemaName,".",s.state.label]}),d.jsx("b",{children:"→"}),d.jsxs("span",{children:[r.model.schemaName,".",r.state.label]})]}),d.jsxs("div",{className:"mr__property_grid",children:[d.jsxs("label",{children:[d.jsx("span",{children:"Source columns"}),d.jsx("select",{disabled:!e,multiple:!0,onChange:o(l=>a({sourceAttributeIds:bs(l)}),"onChange"),value:t.sourceAttributeIds,children:s.model.attributes.map(l=>d.jsx("option",{value:l.id,children:l.name},l.id))})]}),d.jsxs("label",{children:[d.jsx("span",{children:"Referenced columns"}),d.jsx("select",{disabled:!e,multiple:!0,onChange:o(l=>a({targetAttributeIds:bs(l)}),"onChange"),value:t.targetAttributeIds,children:r.model.attributes.map(l=>d.jsx("option",{value:l.id,children:l.name},l.id))})]}),d.jsxs("label",{children:[d.jsx("span",{children:"Source cardinality"}),d.jsx("select",{disabled:!e,onChange:o(l=>a({sourceCardinality:l.target.value}),"onChange"),value:t.sourceCardinality,children:pl.map(l=>d.jsx("option",{value:l.value,children:l.label},l.value))})]}),d.jsxs("label",{children:[d.jsx("span",{children:"Target cardinality"}),d.jsx("select",{disabled:!e,onChange:o(l=>a({targetCardinality:l.target.value}),"onChange"),value:t.targetCardinality,children:pl.map(l=>d.jsx("option",{value:l.value,children:l.label},l.value))})]})]}),t.sourceAttributeIds.length!==t.targetAttributeIds.length&&d.jsx("p",{className:"mr__mapping_warning",children:"A composite foreign key should map the same number of source and referenced columns. Until then, the last selected column is reused."})]}),d.jsxs("section",{className:"mr__property_section",children:[d.jsx("h3",{children:"Referential integrity"}),d.jsxs("div",{className:"mr__property_grid",children:[d.jsxs("label",{children:[d.jsx("span",{children:"ON DELETE"}),d.jsx("select",{disabled:!e,onChange:o(l=>a({onDelete:l.target.value}),"onChange"),value:t.onDelete,children:ul.map(l=>d.jsx("option",{value:l.value,children:l.label},l.value))})]}),d.jsxs("label",{children:[d.jsx("span",{children:"ON UPDATE"}),d.jsx("select",{disabled:!e,onChange:o(l=>a({onUpdate:l.target.value}),"onChange"),value:t.onUpdate,children:ul.map(l=>d.jsx("option",{value:l.value,children:l.label},l.value))})]}),d.jsxs("label",{children:[d.jsx("span",{children:"MATCH"}),d.jsxs("select",{disabled:!e,onChange:o(l=>a({matchType:l.target.value}),"onChange"),value:t.matchType,children:[d.jsx("option",{value:"simple",children:"SIMPLE"}),d.jsx("option",{value:"full",children:"FULL"}),d.jsx("option",{value:"partial",children:"PARTIAL"})]})]}),d.jsxs("label",{children:[d.jsx("span",{children:"Routing"}),d.jsx("select",{disabled:!e,onChange:o(l=>i.updateForeignKeyPath(t,l.target.value),"onChange"),value:t.pathType,children:$h.map(l=>d.jsx("option",{value:l,children:l},l))})]})]}),d.jsxs("div",{className:"mr__property_checks",children:[d.jsx(ws,{checked:t.identifying,label:"Identifying relationship",onChange:o(l=>a({identifying:l}),"onChange")}),d.jsx(ws,{checked:t.deferrable,label:"Deferrable",onChange:o(l=>a({deferrable:l}),"onChange")}),d.jsx(ws,{checked:t.initiallyDeferred,label:"Initially deferred",onChange:o(l=>a({initiallyDeferred:l}),"onChange")})]})]})]})},"ForeignKeyProperties2")),Wh=A.observer(({diagram:n,extension:t})=>{const e=n.getExtension(B),i=e.selectedNodes.length===1?e.selectedNodes[0]:null,s=e.selectedEdges.length===1?e.selectedEdges[0]:null,r=i instanceof Zt?i:null,a=s instanceof It?s:null,l=t.enabled&&!!(r||a),c=n.rules.allowEdition!==!1,{panelWidth:h,startResize:u}=Hh();return d.jsxs("aside",{"aria-hidden":!l,"aria-label":"Relational model properties",className:`mr__properties_panel${l?" mr__properties_panel--open":""}`,style:{width:h},children:[d.jsx("div",{"aria-label":"Resize properties panel","aria-orientation":"vertical",className:"mr__properties_resize_handle",onPointerDown:u,role:"separator",title:"Drag to resize properties panel"}),d.jsxs("header",{children:[d.jsxs("div",{children:[d.jsx("span",{children:"Properties"}),d.jsx("strong",{children:r?"Table / class":"Foreign key"})]}),d.jsx("small",{children:c?"Editable model":"Read only"})]}),d.jsxs("div",{className:"mr__properties_content",children:[r&&d.jsx(Gh,{editable:c,extension:t,node:r}),a&&d.jsx(Vh,{edge:a,editable:c,extension:t})]}),d.jsx("datalist",{id:"mr-data-types",children:Oh.map(g=>d.jsx("option",{value:g},g))})]})}),Ua=class Ua extends tt{};o(Ua,"MRPropertyChangeEvent");let xi=Ua;function yi(n,t=0){const e=n.canvas.frameDimensions;return n.canvas.inverseFit(new y([e.x+e.width/2+t,e.y+e.height/2]))}o(yi,"tablePosition");const Xa=class Xa extends z{RenderUI=Wh;init(){}createTable(t,e="table",i){const s=new Zt(null,{id:me(this.diagram,e),label:i??(e==="view"?"new_view":e==="junction"?"junction_table":"new_table"),model:{tableKind:e}});if(e==="junction"){s.model.attributes=[];const a=s.addAttribute({name:"left_id",dataType:"BIGINT",length:"",nullable:!1,primaryKey:!0}),l=s.addAttribute({name:"right_id",dataType:"BIGINT",length:"",nullable:!1,primaryKey:!0});s.addConstraint("primary-key",{name:`pk_${s.state.label}`,attributeIds:[a.id,l.id]})}this.diagram.add(s),s.setPosition(new y([t.x-s.box.width/2,t.y-s.box.height/2]));const r=this.diagram.getExtension(B);return r.clearSelection(),r.selectNode(s),s}addShowcaseElement(t){if(t==="table"||t==="view"||t==="junction")return this.createTable(yi(this.diagram),t);if(t==="foreign-key")return this.createForeignKeyExample();const e=this.selectedTable??this.createTable(yi(this.diagram));if(t==="attribute")this.addAttribute(e,{name:"new_column"});else if(t==="primary-key"){const i=e.model.attributes.find(s=>!s.primaryKey)??this.addAttribute(e,{name:`${e.state.label}_id`,dataType:"BIGINT",length:""});this.updateAttribute(e,i.id,{primaryKey:!0,nullable:!1})}else if(t==="unique"){const i=e.model.attributes.at(-1);this.addConstraint(e,"unique",{name:`uq_${e.state.label}_${i?.name??"column"}`,attributeIds:i?[i.id]:[]})}else if(t==="check")this.addConstraint(e,"check",{name:`ck_${e.state.label}_value`,expression:"value >= 0"});else if(t==="index"){const i=e.model.attributes.at(-1);this.addConstraint(e,"index",{name:`ix_${e.state.label}_${i?.name??"column"}`,attributeIds:i?[i.id]:[]})}return e}get selectedTable(){const t=this.diagram.getExtension(B).selectedNodes.filter(e=>e instanceof Zt);return t.length===1?t[0]:null}renameTable(t,e){this.recordChange(),t.setState("label",e)}updateTable(t,e){this.recordChange(),t.updateModel(e)}addAttribute(t,e={}){return this.recordChange(),t.addAttribute(e)}updateAttribute(t,e,i){this.recordChange(),t.updateAttribute(e,i)}removeAttribute(t,e){this.recordChange(),this.diagram.edges.filter(i=>i instanceof It&&(i.sourceAttributeIds.includes(e)||i.targetAttributeIds.includes(e))).forEach(i=>this.diagram.disconnect(i)),t.removeAttribute(e)}moveAttribute(t,e,i){this.recordChange(),t.moveAttribute(e,i)}addConstraint(t,e,i={}){return this.recordChange(),t.addConstraint(e,i)}updateConstraint(t,e,i){this.recordChange(),t.updateConstraint(e,i)}removeConstraint(t,e){this.recordChange(),t.removeConstraint(e)}updateForeignKey(t,e){this.recordChange();const i=t.from.parent,s=t.to.parent,r=e.sourceAttributeIds?.length?[...e.sourceAttributeIds]:[...t.sourceAttributeIds],a=e.targetAttributeIds?.length?[...e.targetAttributeIds]:[...t.targetAttributeIds],l=Math.max(r.length,a.length),c=i.box.middle.x<=s.box.middle.x?"right":"left",h=c==="right"?"left":"right",u=this.diagram.edges.filter(m=>m instanceof It&&m.constraintId===t.constraintId).sort((m,b)=>m.mappingIndex-b.mappingIndex),g={constraintId:t.constraintId,mappingIndex:0,name:e.name??t.name,sourceAttributeIds:r,targetAttributeIds:a,sourceCardinality:e.sourceCardinality??t.sourceCardinality,targetCardinality:e.targetCardinality??t.targetCardinality,onDelete:e.onDelete??t.onDelete,onUpdate:e.onUpdate??t.onUpdate,matchType:e.matchType??t.matchType,identifying:e.identifying??t.identifying,deferrable:e.deferrable??t.deferrable,initiallyDeferred:e.initiallyDeferred??t.initiallyDeferred};for(let m=0;m<l;m+=1){const b=r[Math.min(m,r.length-1)],x=a[Math.min(m,a.length-1)],w=i.gatewayForAttribute(b,c),v=s.gatewayForAttribute(x,h);if(!w||!v)continue;const _=u[m]??this.diagram.connect(w,v);this.rewireForeignKey(_,w,v),_.updateModel({...g,mappingIndex:m}),u[m]=_}u.slice(l).forEach(m=>this.diagram.disconnect(m));const p=this.diagram.getExtension(B);p.selectedEdges.includes(t)&&u[0]&&(p.clearSelection(),p.selectEdge(u[0]))}updateForeignKeyPath(t,e){this.recordChange(),this.diagram.edges.filter(i=>i instanceof It&&i.constraintId===t.constraintId).forEach(i=>i.setPathType(e))}createForeignKeyExample(){const t=this.diagram.getExtension(B),e=t.selectedNodes.filter(u=>u instanceof Zt);let i=e[0],s=e[1];s||(s=this.createTable(yi(this.diagram,e.length?250:-180),"table","customers")),(!i||i===s)&&(i=this.createTable(yi(this.diagram,210),"table","orders"));const r=s.model.attributes.find(u=>u.primaryKey)??s.addAttribute({name:"id",dataType:"BIGINT",length:"",nullable:!1,primaryKey:!0}),a=i.addAttribute({name:`${s.state.label.replace(/\W+/g,"_")}_id`,dataType:r.dataType,length:r.length,nullable:!1}),l=i.box.middle.x<=s.box.middle.x?"right":"left",c=l==="right"?"left":"right",h=this.diagram.connect(i.gatewayForAttribute(a.id,l),s.gatewayForAttribute(r.id,c));return h.updateModel({name:`fk_${i.state.label}_${s.state.label}`,sourceAttributeIds:[a.id],targetAttributeIds:[r.id]}),t.clearSelection(),t.selectEdge(h),h}rewireForeignKey(t,e,i){t.from===e&&t.to===i||(t.from.removeOutgoingEdge(t),t.to.removeIncomingEdge(t),t.setState("from",e),t.setState("to",i),t.setState("displacementStart",void 0),t.setState("displacementEnd",void 0),t.setState("startAnchor",{mode:"fixed",position:e.relativePosition}),t.setState("endAnchor",{mode:"fixed",position:i.relativePosition}),e.addOutgoingEdge(t,!1),i.addIncomingEdge(t,!1),e.recomputeConnectedEdge(t,"from"))}recordChange(){this.emit(new xi(this))}};o(Xa,"MRModelerExtension");let En=Xa;var xl=Object.defineProperty,Yh=o((n,t,e)=>t in n?xl(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,"hn"),Zh=o((n,t)=>{for(var e in t)xl(n,e,{get:t[e],enumerable:!0})},"fn"),Kh=o((n,t,e)=>Yh(n,t+"",e),"pe"),Uh={};Zh(Uh,{Graph:o(()=>bt,"Graph"),alg:o(()=>_s,"alg"),json:o(()=>vl,"json"),version:o(()=>Jh,"version")});var Xh=Object.defineProperty,yl=o((n,t)=>{for(var e in t)Xh(n,e,{get:t[e],enumerable:!0})},"Le"),bt=(De=class{constructor(t){this._isDirected=!0,this._isMultigraph=!1,this._isCompound=!1,this._nodes={},this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={},this._nodeCount=0,this._edgeCount=0,this._defaultNodeLabelFn=()=>{},this._defaultEdgeLabelFn=()=>{},t&&(this._isDirected="directed"in t?t.directed:!0,this._isMultigraph="multigraph"in t?t.multigraph:!1,this._isCompound="compound"in t?t.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children["\0"]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(t){return this._label=t,this}graph(){return this._label}setDefaultNodeLabel(t){return typeof t!="function"?this._defaultNodeLabelFn=()=>t:this._defaultNodeLabelFn=t,this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){return this.nodes().filter(t=>Object.keys(this._in[t]).length===0)}sinks(){return this.nodes().filter(t=>Object.keys(this._out[t]).length===0)}setNodes(t,e){return t.forEach(i=>{e!==void 0?this.setNode(i,e):this.setNode(i)}),this}setNode(t,e){return t in this._nodes?(arguments.length>1&&(this._nodes[t]=e),this):(this._nodes[t]=arguments.length>1?e:this._defaultNodeLabelFn(t),this._isCompound&&(this._parent[t]="\0",this._children[t]={},this._children["\0"][t]=!0),this._in[t]={},this._preds[t]={},this._out[t]={},this._sucs[t]={},++this._nodeCount,this)}node(t){return this._nodes[t]}hasNode(t){return t in this._nodes}removeNode(t){if(t in this._nodes){let e=o(i=>this.removeEdge(this._edgeObjs[i]),"n");delete this._nodes[t],this._isCompound&&(this._removeFromParentsChildList(t),delete this._parent[t],this.children(t).forEach(i=>{this.setParent(i)}),delete this._children[t]),Object.keys(this._in[t]).forEach(e),delete this._in[t],delete this._preds[t],Object.keys(this._out[t]).forEach(e),delete this._out[t],delete this._sucs[t],--this._nodeCount}return this}setParent(t,e){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(e===void 0)e="\0";else{e+="";for(let i=e;i!==void 0;i=this.parent(i))if(i===t)throw new Error("Setting "+e+" as parent of "+t+" would create a cycle");this.setNode(e)}return this.setNode(t),this._removeFromParentsChildList(t),this._parent[t]=e,this._children[e][t]=!0,this}parent(t){if(this._isCompound){let e=this._parent[t];if(e!=="\0")return e}}children(t="\0"){if(this._isCompound){let e=this._children[t];if(e)return Object.keys(e)}else{if(t==="\0")return this.nodes();if(this.hasNode(t))return[]}return[]}predecessors(t){let e=this._preds[t];if(e)return Object.keys(e)}successors(t){let e=this._sucs[t];if(e)return Object.keys(e)}neighbors(t){let e=this.predecessors(t);if(e){let i=new Set(e);for(let s of this.successors(t))i.add(s);return Array.from(i.values())}}isLeaf(t){let e;return this.isDirected()?e=this.successors(t):e=this.neighbors(t),e.length===0}filterNodes(t){let e=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});e.setGraph(this.graph()),Object.entries(this._nodes).forEach(([r,a])=>{t(r)&&e.setNode(r,a)}),Object.values(this._edgeObjs).forEach(r=>{e.hasNode(r.v)&&e.hasNode(r.w)&&e.setEdge(r,this.edge(r))});let i={},s=o(r=>{let a=this.parent(r);return!a||e.hasNode(a)?(i[r]=a??void 0,a??void 0):a in i?i[a]:s(a)},"r");return this._isCompound&&e.nodes().forEach(r=>e.setParent(r,s(r))),e}setDefaultEdgeLabel(t){return typeof t!="function"?this._defaultEdgeLabelFn=()=>t:this._defaultEdgeLabelFn=t,this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(t,e){return t.reduce((i,s)=>(e!==void 0?this.setEdge(i,s,e):this.setEdge(i,s),s)),this}setEdge(t,e,i,s){let r,a,l,c,h=!1;typeof t=="object"&&t!==null&&"v"in t?(r=t.v,a=t.w,l=t.name,arguments.length===2&&(c=e,h=!0)):(r=t,a=e,l=s,arguments.length>2&&(c=i,h=!0)),r=""+r,a=""+a,l!==void 0&&(l=""+l);let u=kn(this._isDirected,r,a,l);if(u in this._edgeLabels)return h&&(this._edgeLabels[u]=c),this;if(l!==void 0&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(r),this.setNode(a),this._edgeLabels[u]=h?c:this._defaultEdgeLabelFn(r,a,l);let g=qh(this._isDirected,r,a,l);return r=g.v,a=g.w,Object.freeze(g),this._edgeObjs[u]=g,bl(this._preds[a],r),bl(this._sucs[r],a),this._in[a][u]=g,this._out[r][u]=g,this._edgeCount++,this}edge(t,e,i){let s=arguments.length===1?vs(this._isDirected,t):kn(this._isDirected,t,e,i);return this._edgeLabels[s]}edgeAsObj(t,e,i){let s=arguments.length===1?this.edge(t):this.edge(t,e,i);return typeof s!="object"?{label:s}:s}hasEdge(t,e,i){return(arguments.length===1?vs(this._isDirected,t):kn(this._isDirected,t,e,i))in this._edgeLabels}removeEdge(t,e,i){let s=arguments.length===1?vs(this._isDirected,t):kn(this._isDirected,t,e,i),r=this._edgeObjs[s];if(r){let a=r.v,l=r.w;delete this._edgeLabels[s],delete this._edgeObjs[s],wl(this._preds[l],a),wl(this._sucs[a],l),delete this._in[l][s],delete this._out[a][s],this._edgeCount--}return this}inEdges(t,e){return this.isDirected()?this.filterEdges(this._in[t],t,e):this.nodeEdges(t,e)}outEdges(t,e){return this.isDirected()?this.filterEdges(this._out[t],t,e):this.nodeEdges(t,e)}nodeEdges(t,e){if(t in this._nodes)return this.filterEdges({...this._in[t],...this._out[t]},t,e)}_removeFromParentsChildList(t){delete this._children[this._parent[t]][t]}filterEdges(t,e,i){if(!t)return;let s=Object.values(t);return i?s.filter(r=>r.v===e&&r.w===i||r.v===i&&r.w===e):s}},o(De,"p"),De);function bl(n,t){n[t]?n[t]++:n[t]=1}o(bl,"me");function wl(n,t){n[t]!==void 0&&!--n[t]&&delete n[t]}o(wl,"Ee");function kn(n,t,e,i){let s=""+t,r=""+e;if(!n&&s>r){let a=s;s=r,r=a}return s+""+r+""+(i===void 0?"\0":i)}o(kn,"C");function qh(n,t,e,i){let s=""+t,r=""+e;if(!n&&s>r){let l=s;s=r,r=l}let a={v:s,w:r};return i&&(a.name=i),a}o(qh,"gn");function vs(n,t){return kn(n,t.v,t.w,t.name)}o(vs,"Y");var Jh="4.0.1",vl={};yl(vl,{read:o(()=>nu,"read"),write:o(()=>Qh,"write")});function Qh(n){let t={options:{directed:n.isDirected(),multigraph:n.isMultigraph(),compound:n.isCompound()},nodes:tu(n),edges:eu(n)},e=n.graph();return e!==void 0&&(t.value=structuredClone(e)),t}o(Qh,"mn");function tu(n){return n.nodes().map(t=>{let e=n.node(t),i=n.parent(t),s={v:t};return e!==void 0&&(s.value=e),i!==void 0&&(s.parent=i),s})}o(tu,"En");function eu(n){return n.edges().map(t=>{let e=n.edge(t),i={v:t.v,w:t.w};return t.name!==void 0&&(i.name=t.name),e!==void 0&&(i.value=e),i})}o(eu,"Ln");function nu(n){let t=new bt(n.options);return n.value!==void 0&&t.setGraph(n.value),n.nodes.forEach(e=>{t.setNode(e.v,e.value),e.parent&&t.setParent(e.v,e.parent)}),n.edges.forEach(e=>{t.setEdge({v:e.v,w:e.w,name:e.name},e.value)}),t}o(nu,"yn");var _s={};yl(_s,{CycleException:o(()=>wi,"CycleException"),bellmanFord:o(()=>_l,"bellmanFord"),components:o(()=>ru,"components"),dijkstra:o(()=>bi,"dijkstra"),dijkstraAll:o(()=>lu,"dijkstraAll"),findCycles:o(()=>cu,"findCycles"),floydWarshall:o(()=>hu,"floydWarshall"),isAcyclic:o(()=>pu,"isAcyclic"),postorder:o(()=>fu,"postorder"),preorder:o(()=>mu,"preorder"),prim:o(()=>xu,"prim"),shortestPaths:o(()=>yu,"shortestPaths"),tarjan:o(()=>kl,"tarjan"),topsort:o(()=>Sl,"topsort")});var iu=o(()=>1,"wn");function _l(n,t,e,i){return su(n,String(t),e||iu,i||function(s){return n.outEdges(s)})}o(_l,"we");function su(n,t,e,i){let s={},r,a=0,l=n.nodes(),c=o(function(g){let p=e(g);s[g.v].distance+p<s[g.w].distance&&(s[g.w]={distance:s[g.v].distance+p,predecessor:g.v},r=!0)},"d"),h=o(function(){l.forEach(function(g){i(g).forEach(function(p){let m=p.v===g?p.v:p.w,b=m===p.v?p.w:p.v;c({v:m,w:b})})})},"l");l.forEach(function(g){let p=g===t?0:Number.POSITIVE_INFINITY;s[g]={distance:p,predecessor:""}});let u=l.length;for(let g=1;g<u&&(r=!1,a++,h(),!!r);g++);if(a===u-1&&(r=!1,h(),r))throw new Error("The graph contains a negative weight cycle");return s}o(su,"Nn");function ru(n){let t={},e=[],i;function s(r){r in t||(t[r]=!0,i.push(r),n.successors(r).forEach(s),n.predecessors(r).forEach(s))}return o(s,"o"),n.nodes().forEach(function(r){i=[],s(r),i.length&&e.push(i)}),e}o(ru,"Gn");var El=(Le=class{constructor(){this._arr=[],this._keyIndices={}}size(){return this._arr.length}keys(){return this._arr.map(t=>t.key)}has(t){return t in this._keyIndices}priority(t){let e=this._keyIndices[t];if(e!==void 0)return this._arr[e].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(t,e){let i=this._keyIndices,s=String(t);if(!(s in i)){let r=this._arr,a=r.length;return i[s]=a,r.push({key:s,priority:e}),this._decrease(a),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);let t=this._arr.pop();return delete this._keyIndices[t.key],this._heapify(0),t.key}decrease(t,e){let i=this._keyIndices[t];if(i===void 0)throw new Error(`Key not found: ${t}`);let s=this._arr[i].priority;if(e>s)throw new Error(`New priority is greater than current priority. Key: ${t} Old: ${s} New: ${e}`);this._arr[i].priority=e,this._decrease(i)}_heapify(t){let e=this._arr,i=2*t,s=i+1,r=t;i<e.length&&(r=e[i].priority<e[r].priority?i:r,s<e.length&&(r=e[s].priority<e[r].priority?s:r),r!==t&&(this._swap(t,r),this._heapify(r)))}_decrease(t){let e=this._arr,i=e[t].priority,s;for(;t!==0&&(s=t>>1,!(e[s].priority<i));)this._swap(t,s),t=s}_swap(t,e){let i=this._arr,s=this._keyIndices,r=i[t],a=i[e];i[t]=a,i[e]=r,s[a.key]=t,s[r.key]=e}},o(Le,"Ne"),Le),au=o(()=>1,"kn");function bi(n,t,e,i){let s=o(function(r){return n.outEdges(r)},"o");return ou(n,String(t),e||au,i||s)}o(bi,"F");function ou(n,t,e,i){let s={},r=new El,a,l,c=o(function(h){let u=h.v!==a?h.v:h.w,g=s[u],p=e(h),m=l.distance+p;if(p<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+h+" Weight: "+p);m<g.distance&&(g.distance=m,g.predecessor=a,r.decrease(u,m))},"d");for(n.nodes().forEach(function(h){let u=h===t?0:Number.POSITIVE_INFINITY;s[h]={distance:u,predecessor:""},r.add(h,u)});r.size()>0&&(a=r.removeMin(),l=s[a],l.distance!==Number.POSITIVE_INFINITY);)i(a).forEach(c);return s}o(ou,"vn");function lu(n,t,e){return n.nodes().reduce(function(i,s){return i[s]=bi(n,s,t,e),i},{})}o(lu,"_n");function kl(n){let t=0,e=[],i={},s=[];function r(a){let l=i[a]={onStack:!0,lowlink:t,index:t++};if(e.push(a),n.successors(a).forEach(function(c){c in i?i[c].onStack&&(l.lowlink=Math.min(l.lowlink,i[c].index)):(r(c),l.lowlink=Math.min(l.lowlink,i[c].lowlink))}),l.lowlink===l.index){let c=[],h;do h=e.pop(),i[h].onStack=!1,c.push(h);while(a!==h);s.push(c)}}return o(r,"i"),n.nodes().forEach(function(a){a in i||r(a)}),s}o(kl,"Ge");function cu(n){return kl(n).filter(function(t){return t.length>1||t.length===1&&n.hasEdge(t[0],t[0])})}o(cu,"xn");var du=o(()=>1,"Tn");function hu(n,t,e){return uu(n,t||du,e||function(i){return n.outEdges(i)})}o(hu,"On");function uu(n,t,e){let i={},s=n.nodes();return s.forEach(function(r){i[r]={},i[r][r]={distance:0,predecessor:""},s.forEach(function(a){r!==a&&(i[r][a]={distance:Number.POSITIVE_INFINITY,predecessor:""})}),e(r).forEach(function(a){let l=a.v===r?a.w:a.v,c=t(a);i[r][l]={distance:c,predecessor:r}})}),s.forEach(function(r){let a=i[r];s.forEach(function(l){let c=i[l];s.forEach(function(h){let u=c[r],g=a[h],p=c[h],m=u.distance+g.distance;m<p.distance&&(p.distance=m,p.predecessor=g.predecessor)})})}),i}o(uu,"In");var wi=(Oe=class extends Error{constructor(...t){super(...t)}},o(Oe,"D"),Oe);function Sl(n){let t={},e={},i=[];function s(r){if(r in e)throw new wi;r in t||(e[r]=!0,t[r]=!0,n.predecessors(r).forEach(s),delete e[r],i.push(r))}if(o(s,"o"),n.sinks().forEach(s),Object.keys(t).length!==n.nodeCount())throw new wi;return i}o(Sl,"ke");function pu(n){try{Sl(n)}catch(t){if(t instanceof wi)return!1;throw t}return!0}o(pu,"Cn");function gu(n,t,e,i,s){Array.isArray(t)||(t=[t]);let r=o((l=>{var c;return(c=n.isDirected()?n.successors(l):n.neighbors(l))!=null?c:[]}),"i"),a={};return t.forEach(function(l){if(!n.hasNode(l))throw new Error("Graph does not have node: "+l);s=Ml(n,l,e==="post",a,r,i,s)}),s}o(gu,"Rn");function Ml(n,t,e,i,s,r,a){return t in i||(i[t]=!0,e||(a=r(a,t)),s(t).forEach(function(l){a=Ml(n,l,e,i,s,r,a)}),e&&(a=r(a,t))),a}o(Ml,"ve");function Al(n,t,e){return gu(n,t,e,function(i,s){return i.push(s),i},[])}o(Al,"_e");function fu(n,t){return Al(n,t,"post")}o(fu,"Pn");function mu(n,t){return Al(n,t,"pre")}o(mu,"Mn");function xu(n,t){let e=new bt,i={},s=new El,r;function a(c){let h=c.v===r?c.w:c.v,u=s.priority(h);if(u!==void 0){let g=t(c);g<u&&(i[h]=r,s.decrease(h,g))}}if(o(a,"s"),n.nodeCount()===0)return e;n.nodes().forEach(function(c){s.add(c,Number.POSITIVE_INFINITY),e.setNode(c)}),s.decrease(n.nodes()[0],0);let l=!1;for(;s.size()>0;){if(r=s.removeMin(),r in i)e.setEdge(r,i[r]);else{if(l)throw new Error("Input graph is not connected: "+n);l=!0}n.nodeEdges(r).forEach(a)}return e}o(xu,"jn");function yu(n,t,e,i){return bu(n,t,e,i??(s=>{let r=n.outEdges(s);return r??[]}))}o(yu,"Sn");function bu(n,t,e,i){if(e===void 0)return bi(n,t,e,i);let s=!1,r=n.nodes();for(let a=0;a<r.length;a++){let l=i(r[a]);for(let c=0;c<l.length;c++){let h=l[c],u=h.v===r[a]?h.v:h.w,g=u===h.v?h.w:h.v;e({v:u,w:g})<0&&(s=!0)}if(s)return _l(n,t,e,i)}return bi(n,t,e,i)}o(bu,"Fn");function Ae(n,t,e,i){let s=i;for(;n.hasNode(s);)s=Es(i);return e.dummy=t,n.setNode(s,e),s}o(Ae,"w");function wu(n){let t=new bt().setGraph(n.graph());return n.nodes().forEach(e=>t.setNode(e,n.node(e))),n.edges().forEach(e=>{let i=t.edge(e.v,e.w)||{weight:0,minlen:1},s=n.edge(e);t.setEdge(e.v,e.w,{weight:i.weight+s.weight,minlen:Math.max(i.minlen,s.minlen)})}),t}o(wu,"xe");function Cl(n){let t=new bt({multigraph:n.isMultigraph()}).setGraph(n.graph());return n.nodes().forEach(e=>{n.children(e).length||t.setNode(e,n.node(e))}),n.edges().forEach(e=>{t.setEdge(e,n.edge(e))}),t}o(Cl,"A");function Il(n,t){let e=n.x,i=n.y,s=t.x-e,r=t.y-i,a=n.width/2,l=n.height/2;if(!s&&!r)throw new Error("Not possible to find intersection inside of the rectangle");let c,h;return Math.abs(r)*a>Math.abs(s)*l?(r<0&&(l=-l),c=l*s/r,h=l):(s<0&&(a=-a),c=a,h=a*r/s),{x:e+c,y:i+h}}o(Il,"H");function vi(n){let t=Sn(Nl(n)+1).map(()=>[]);return n.nodes().forEach(e=>{let i=n.node(e),s=i.rank;s!==void 0&&(t[s]||(t[s]=[]),t[s][i.order]=e)}),t}o(vi,"N");function vu(n){let t=n.nodes().map(i=>{let s=n.node(i).rank;return s===void 0?Number.MAX_VALUE:s}),e=zt(Math.min,t);n.nodes().forEach(i=>{let s=n.node(i);Object.hasOwn(s,"rank")&&(s.rank-=e)})}o(vu,"Te");function _u(n){let t=n.nodes().map(a=>n.node(a).rank).filter(a=>a!==void 0),e=zt(Math.min,t),i=[];n.nodes().forEach(a=>{let l=n.node(a).rank-e;i[l]||(i[l]=[]),i[l].push(a)});let s=0,r=n.graph().nodeRankFactor;Array.from(i).forEach((a,l)=>{a===void 0&&l%r!==0?--s:a!==void 0&&s&&a.forEach(c=>n.node(c).rank+=s)})}o(_u,"Oe");function jl(n,t,e,i){let s={width:0,height:0};return arguments.length>=4&&(s.rank=e,s.order=i),Ae(n,"border",s,t)}o(jl,"q");function Eu(n,t=Pl){let e=[];for(let i=0;i<n.length;i+=t){let s=n.slice(i,i+t);e.push(s)}return e}o(Eu,"Dn");var Pl=65535;function zt(n,t){if(t.length>Pl){let e=Eu(t);return n(...e.map(i=>n(...i)))}else return n(...t)}o(zt,"L");function Nl(n){let t=n.nodes().map(e=>{let i=n.node(e).rank;return i===void 0?Number.MIN_VALUE:i});return zt(Math.max,t)}o(Nl,"X");function ku(n,t){let e={lhs:[],rhs:[]};return n.forEach(i=>{t(i)?e.lhs.push(i):e.rhs.push(i)}),e}o(ku,"Ce");function Su(n,t){let e=Date.now();try{return t()}finally{console.log(n+" time: "+(Date.now()-e)+"ms")}}o(Su,"P");function Mu(n,t){return t()}o(Mu,"M");var Au=0;function Es(n){let t=++Au;return n+(""+t)}o(Es,"j");function Sn(n,t,e=1){t==null&&(t=n,n=0);let i=o(r=>r<t,"r");e<0&&(i=o(r=>t<r,"r"));let s=[];for(let r=n;i(r);r+=e)s.push(r);return s}o(Sn,"k");function _i(n,t){let e={};for(let i of t)n[i]!==void 0&&(e[i]=n[i]);return e}o(_i,"T");function Ei(n,t){let e;return typeof t=="string"?e=o(i=>i[t],"t"):e=t,Object.entries(n).reduce((i,[s,r])=>(i[s]=e(r,s),i),{})}o(Ei,"O");function Cu(n,t){return n.reduce((e,i,s)=>(e[i]=t[s],e),{})}o(Cu,"Re");var ki="\0",Iu=(ze=class{constructor(){Kh(this,"_sentinel");let t={};t._next=t._prev=t,this._sentinel=t}dequeue(){let t=this._sentinel,e=t._prev;if(e!==t)return Tl(e),e}enqueue(t){let e=this._sentinel;t._prev&&t._next&&Tl(t),t._next=e._next,e._next._prev=t,e._next=t,t._prev=e}toString(){let t=[],e=this._sentinel,i=e._prev;for(;i!==e;)t.push(JSON.stringify(i,ju)),i=i._prev;return"["+t.join(", ")+"]"}},o(ze,"K"),ze);function Tl(n){n._prev._next=n._next,n._next._prev=n._prev,delete n._next,delete n._prev}o(Tl,"Pe");function ju(n,t){if(n!=="_next"&&n!=="_prev")return t}o(ju,"Vn");var Pu=Iu,Nu=o(()=>1,"Wn");function Tu(n,t){if(n.nodeCount()<=1)return[];let e=Lu(n,t||Nu);return Du(e.graph,e.buckets,e.zeroIdx).flatMap(i=>n.outEdges(i.v,i.w)||[])}o(Tu,"Q");function Du(n,t,e){var i;let s=[],r=t[t.length-1],a=t[0],l;for(;n.nodeCount();){for(;l=a.dequeue();)ks(n,t,e,l);for(;l=r.dequeue();)ks(n,t,e,l);if(n.nodeCount()){for(let c=t.length-2;c>0;--c)if(l=(i=t[c])==null?void 0:i.dequeue(),l){s=s.concat(ks(n,t,e,l,!0)||[]);break}}}return s}o(Du,"Bn");function ks(n,t,e,i,s){let r=[],a=s?r:void 0;return(n.inEdges(i.v)||[]).forEach(l=>{let c=n.edge(l),h=n.node(l.v);s&&r.push({v:l.v,w:l.w}),h.out-=c,Ss(t,e,h)}),(n.outEdges(i.v)||[]).forEach(l=>{let c=n.edge(l),h=l.w,u=n.node(h);u.in-=c,Ss(t,e,u)}),n.removeNode(i.v),a}o(ks,"$");function Lu(n,t){let e=new bt,i=0,s=0;n.nodes().forEach(l=>{e.setNode(l,{v:l,in:0,out:0})}),n.edges().forEach(l=>{let c=e.edge(l.v,l.w)||0,h=t(l),u=c+h;e.setEdge(l.v,l.w,u);let g=e.node(l.v),p=e.node(l.w);s=Math.max(s,g.out+=h),i=Math.max(i,p.in+=h)});let r=Ou(s+i+3).map(()=>new Pu),a=i+1;return e.nodes().forEach(l=>{Ss(r,a,e.node(l))}),{graph:e,buckets:r,zeroIdx:a}}o(Lu,"Yn");function Ss(n,t,e){var i,s,r;e.out?e.in?(r=n[e.out-e.in+t])==null||r.enqueue(e):(s=n[n.length-1])==null||s.enqueue(e):(i=n[0])==null||i.enqueue(e)}o(Ss,"J");function Ou(n){let t=[];for(let e=0;e<n;e++)t.push(e);return t}o(Ou,"zn");function zu(n){(n.graph().acyclicer==="greedy"?Tu(n,t(n)):$u(n)).forEach(e=>{let i=n.edge(e);n.removeEdge(e),i.forwardName=e.name,i.reversed=!0,n.setEdge(e.w,e.v,i,Es("rev"))});function t(e){return i=>e.edge(i).weight}o(t,"t")}o(zu,"je");function $u(n){let t=[],e={},i={};function s(r){Object.hasOwn(i,r)||(i[r]=!0,e[r]=!0,n.outEdges(r).forEach(a=>{Object.hasOwn(e,a.w)?t.push(a):s(a.w)}),delete e[r])}return o(s,"o"),n.nodes().forEach(s),t}o($u,"Hn");function Fu(n){n.edges().forEach(t=>{let e=n.edge(t);if(e.reversed){n.removeEdge(t);let i=e.forwardName;delete e.reversed,delete e.forwardName,n.setEdge(t.w,t.v,e,i)}})}o(Fu,"Se");function Hu(n){n.graph().dummyChains=[],n.edges().forEach(t=>Bu(n,t))}o(Hu,"Fe");function Bu(n,t){let e=t.v,i=n.node(e).rank,s=t.w,r=n.node(s).rank,a=t.name,l=n.edge(t),c=l.labelRank;if(r===i+1)return;n.removeEdge(t);let h,u,g;for(g=0,++i;i<r;++g,++i)l.points=[],u={width:0,height:0,edgeLabel:l,edgeObj:t,rank:i},h=Ae(n,"edge",u,"_d"),i===c&&(u.width=l.width,u.height=l.height,u.dummy="edge-label",u.labelpos=l.labelpos),n.setEdge(e,h,{weight:l.weight},a),g===0&&n.graph().dummyChains.push(h),e=h;n.setEdge(e,s,{weight:l.weight},a)}o(Bu,"Xn");function Ru(n){n.graph().dummyChains.forEach(t=>{let e=n.node(t),i=e.edgeLabel,s;for(n.setEdge(e.edgeObj,i);e.dummy;)s=n.successors(t)[0],n.removeNode(t),i.points.push({x:e.x,y:e.y}),e.dummy==="edge-label"&&(i.x=e.x,i.y=e.y,i.width=e.width,i.height=e.height),t=s,e=n.node(t)})}o(Ru,"De");function Ms(n){let t={};function e(i){let s=n.node(i);if(Object.hasOwn(t,i))return s.rank;t[i]=!0;let r=n.outEdges(i),a=r?r.map(c=>c==null?Number.POSITIVE_INFINITY:e(c.w)-n.edge(c).minlen):[],l=zt(Math.min,a);return l===Number.POSITIVE_INFINITY&&(l=0),s.rank=l}o(e,"t"),n.sources().forEach(e)}o(Ms,"S");function Ce(n,t){return n.node(t.w).rank-n.node(t.v).rank-n.edge(t).minlen}o(Ce,"v");var Dl=Gu;function Gu(n){let t=new bt({directed:!1}),e=n.nodes();if(e.length===0)throw new Error("Graph must have at least one node");let i=e[0],s=n.nodeCount();t.setNode(i,{});let r,a;for(;Vu(t,n)<s&&(r=Wu(t,n),!!r);)a=t.hasNode(r.v)?Ce(n,r):-Ce(n,r),Yu(t,n,a);return t}o(Gu,"Kn");function Vu(n,t){function e(i){let s=t.nodeEdges(i);s&&s.forEach(r=>{let a=r.v,l=i===a?r.w:a;!n.hasNode(l)&&!Ce(t,r)&&(n.setNode(l,{}),n.setEdge(i,l,{}),e(l))})}return o(e,"t"),n.nodes().forEach(e),n.nodeCount()}o(Vu,"$n");function Wu(n,t){return t.edges().reduce((e,i)=>{let s=Number.POSITIVE_INFINITY;return n.hasNode(i.v)!==n.hasNode(i.w)&&(s=Ce(t,i)),s<e[0]?[s,i]:e},[Number.POSITIVE_INFINITY,null])[1]}o(Wu,"Jn");function Yu(n,t,e){n.nodes().forEach(i=>t.node(i).rank+=e)}o(Yu,"Qn");var{preorder:Zu,postorder:Ku}=_s,Uu=de;de.initLowLimValues=Cs,de.initCutValues=As,de.calcCutValue=Ll,de.leaveEdge=zl,de.enterEdge=$l,de.exchangeEdges=Fl;function de(n){n=wu(n),Ms(n);let t=Dl(n);Cs(t),As(t,n);let e,i;for(;e=zl(t);)i=$l(t,n,e),Fl(t,n,e,i)}o(de,"x");function As(n,t){let e=Ku(n,n.nodes());e=e.slice(0,e.length-1),e.forEach(i=>Xu(n,t,i))}o(As,"Z");function Xu(n,t,e){let i=n.node(e).parent,s=n.edge(e,i);s.cutvalue=Ll(n,t,e)}o(Xu,"nt");function Ll(n,t,e){let i=n.node(e).parent,s=!0,r=t.edge(e,i),a=0;r||(s=!1,r=t.edge(i,e)),a=r.weight;let l=t.nodeEdges(e);return l&&l.forEach(c=>{let h=c.v===e,u=h?c.w:c.v;if(u!==i){let g=h===s,p=t.edge(c).weight;if(a+=g?p:-p,Ju(n,e,u)){let m=n.edge(e,u).cutvalue;a+=g?-m:m}}}),a}o(Ll,"We");function Cs(n,t){arguments.length<2&&(t=n.nodes()[0]),Ol(n,{},1,t)}o(Cs,"ee");function Ol(n,t,e,i,s){let r=e,a=n.node(i);t[i]=!0;let l=n.neighbors(i);return l&&l.forEach(c=>{Object.hasOwn(t,c)||(e=Ol(n,t,e,c,i))}),a.low=r,a.lim=e++,s?a.parent=s:delete a.parent,e}o(Ol,"Be");function zl(n){return n.edges().find(t=>n.edge(t).cutvalue<0)}o(zl,"Ye");function $l(n,t,e){let i=e.v,s=e.w;t.hasEdge(i,s)||(i=e.w,s=e.v);let r=n.node(i),a=n.node(s),l=r,c=!1;return r.lim>a.lim&&(l=a,c=!0),t.edges().filter(h=>c===Hl(n,n.node(h.v),l)&&c!==Hl(n,n.node(h.w),l)).reduce((h,u)=>Ce(t,u)<Ce(t,h)?u:h)}o($l,"ze");function Fl(n,t,e,i){let s=e.v,r=e.w;n.removeEdge(s,r),n.setEdge(i.v,i.w,{}),Cs(n),As(n,t),qu(n,t)}o(Fl,"He");function qu(n,t){let e=n.nodes().find(s=>!n.node(s).parent);if(!e)return;let i=Zu(n,[e]);i=i.slice(1),i.forEach(s=>{let r=n.node(s).parent,a=t.edge(s,r),l=!1;a||(a=t.edge(r,s),l=!0),t.node(s).rank=t.node(r).rank+(l?a.minlen:-a.minlen)})}o(qu,"tt");function Ju(n,t,e){return n.hasEdge(t,e)}o(Ju,"rt");function Hl(n,t,e){return e.low<=t.lim&&t.lim<=e.lim}o(Hl,"Ae");var Qu=tp;function tp(n){let t=n.graph().ranker;if(typeof t=="function")return t(n);switch(t){case"network-simplex":Bl(n);break;case"tight-tree":np(n);break;case"longest-path":ep(n);break;case"none":break;default:Bl(n)}}o(tp,"ot");var ep=Ms;function np(n){Ms(n),Dl(n)}o(np,"st");function Bl(n){Uu(n)}o(Bl,"qe");var ip=sp;function sp(n){let t=ap(n);n.graph().dummyChains.forEach(e=>{let i=n.node(e),s=i.edgeObj,r=rp(n,t,s.v,s.w),a=r.path,l=r.lca,c=0,h=a[c],u=!0;for(;e!==s.w;){if(i=n.node(e),u){for(;(h=a[c])!==l&&n.node(h).maxRank<i.rank;)c++;h===l&&(u=!1)}if(!u){for(;c<a.length-1&&n.node(a[c+1]).minRank<=i.rank;)c++;h=a[c]}h!==void 0&&n.setParent(e,h),e=n.successors(e)[0]}})}o(sp,"at");function rp(n,t,e,i){let s=[],r=[],a=Math.min(t[e].low,t[i].low),l=Math.max(t[e].lim,t[i].lim),c;c=e;do c=n.parent(c),s.push(c);while(c&&(t[c].low>a||l>t[c].lim));let h=c,u=i;for(;(u=n.parent(u))!==h;)r.push(u);return{path:s.concat(r.reverse()),lca:h}}o(rp,"dt");function ap(n){let t={},e=0;function i(s){let r=e;n.children(s).forEach(i),t[s]={low:r,lim:e++}}return o(i,"r"),n.children(ki).forEach(i),t}o(ap,"lt");function op(n){let t=Ae(n,"root",{},"_root"),e=lp(n),i=Object.values(e),s=zt(Math.max,i)-1,r=2*s+1;n.graph().nestingRoot=t,n.edges().forEach(l=>n.edge(l).minlen*=r);let a=cp(n)+1;n.children(ki).forEach(l=>Rl(n,t,r,a,s,e,l)),n.graph().nodeRankFactor=r}o(op,"Ke");function Rl(n,t,e,i,s,r,a){var l;let c=n.children(a);if(!c.length){a!==t&&n.setEdge(t,a,{weight:0,minlen:e});return}let h=jl(n,"_bt"),u=jl(n,"_bb"),g=n.node(a);n.setParent(h,a),g.borderTop=h,n.setParent(u,a),g.borderBottom=u,c.forEach(p=>{var m;Rl(n,t,e,i,s,r,p);let b=n.node(p),x=b.borderTop?b.borderTop:p,w=b.borderBottom?b.borderBottom:p,v=b.borderTop?i:2*i,_=x!==w?1:s-((m=r[a])!=null?m:0)+1;n.setEdge(h,x,{weight:v,minlen:_,nestingEdge:!0}),n.setEdge(w,u,{weight:v,minlen:_,nestingEdge:!0})}),n.parent(a)||n.setEdge(t,h,{weight:0,minlen:s+((l=r[a])!=null?l:0)})}o(Rl,"$e");function lp(n){let t={};function e(i,s){let r=n.children(i);r&&r.length&&r.forEach(a=>e(a,s+1)),t[i]=s}return o(e,"t"),n.children(ki).forEach(i=>e(i,1)),t}o(lp,"ut");function cp(n){return n.edges().reduce((t,e)=>t+n.edge(e).weight,0)}o(cp,"ct");function dp(n){let t=n.graph();n.removeNode(t.nestingRoot),delete t.nestingRoot,n.edges().forEach(e=>{n.edge(e).nestingEdge&&n.removeEdge(e)})}o(dp,"Je");var hp=up;function up(n){function t(e){let i=n.children(e),s=n.node(e);if(i.length&&i.forEach(t),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let r=s.minRank,a=s.maxRank+1;r<a;++r)Gl(n,"borderLeft","_bl",e,s,r),Gl(n,"borderRight","_br",e,s,r)}}o(t,"n"),n.children(ki).forEach(t)}o(up,"ft");function Gl(n,t,e,i,s,r){let a={width:0,height:0,rank:r,borderType:t},l=s[t][r-1],c=Ae(n,"border",a,e);s[t][r]=c,n.setParent(c,i),l&&n.setEdge(l,c,{weight:1})}o(Gl,"Qe");function pp(n){var t;let e=(t=n.graph().rankdir)==null?void 0:t.toLowerCase();(e==="lr"||e==="rl")&&Vl(n)}o(pp,"nn");function gp(n){var t;let e=(t=n.graph().rankdir)==null?void 0:t.toLowerCase();(e==="bt"||e==="rl")&&fp(n),(e==="lr"||e==="rl")&&(mp(n),Vl(n))}o(gp,"tn");function Vl(n){n.nodes().forEach(t=>Wl(n.node(t))),n.edges().forEach(t=>Wl(n.edge(t)))}o(Vl,"rn");function Wl(n){let t=n.width;n.width=n.height,n.height=t}o(Wl,"en");function fp(n){n.nodes().forEach(t=>Is(n.node(t))),n.edges().forEach(t=>{var e;let i=n.edge(t);(e=i.points)==null||e.forEach(Is),Object.hasOwn(i,"y")&&Is(i)})}o(fp,"bt");function Is(n){n.y=-n.y}o(Is,"ne");function mp(n){n.nodes().forEach(t=>js(n.node(t))),n.edges().forEach(t=>{var e;let i=n.edge(t);(e=i.points)==null||e.forEach(js),Object.hasOwn(i,"x")&&js(i)})}o(mp,"gt");function js(n){let t=n.x;n.x=n.y,n.y=t}o(js,"te");function xp(n){let t={},e=n.nodes().filter(l=>!n.children(l).length),i=e.map(l=>n.node(l).rank),s=zt(Math.max,i),r=Sn(s+1).map(()=>[]);function a(l){if(t[l])return;t[l]=!0;let c=n.node(l);r[c.rank].push(l);let h=n.successors(l);h&&h.forEach(a)}return o(a,"s"),e.sort((l,c)=>n.node(l).rank-n.node(c).rank).forEach(a),r}o(xp,"re");function yp(n,t){let e=0;for(let i=1;i<t.length;++i)e+=bp(n,t[i-1],t[i]);return e}o(yp,"oe");function bp(n,t,e){let i=Cu(e,e.map((h,u)=>u)),s=t.flatMap(h=>{let u=n.outEdges(h);return u?u.map(g=>({pos:i[g.w],weight:n.edge(g).weight})).sort((g,p)=>g.pos-p.pos):[]}),r=1;for(;r<e.length;)r<<=1;let a=2*r-1;r-=1;let l=new Array(a).fill(0),c=0;return s.forEach(h=>{let u=h.pos+r;l[u]+=h.weight;let g=0;for(;u>0;)u%2&&(g+=l[u+1]),u=u-1>>1,l[u]+=h.weight;c+=h.weight*g}),c}o(bp,"mt");function wp(n,t=[]){return t.map(e=>{let i=n.inEdges(e);if(!i||!i.length)return{v:e};{let s=i.reduce((r,a)=>{let l=n.edge(a),c=n.node(a.v);return{sum:r.sum+l.weight*c.order,weight:r.weight+l.weight}},{sum:0,weight:0});return{v:e,barycenter:s.sum/s.weight,weight:s.weight}}})}o(wp,"ie");function vp(n,t){let e={};n.forEach((s,r)=>{let a={indegree:0,in:[],out:[],vs:[s.v],i:r};s.barycenter!==void 0&&(a.barycenter=s.barycenter,a.weight=s.weight),e[s.v]=a}),t.edges().forEach(s=>{let r=e[s.v],a=e[s.w];r!==void 0&&a!==void 0&&(a.indegree++,r.out.push(a))});let i=Object.values(e).filter(s=>!s.indegree);return _p(i)}o(vp,"se");function _p(n){let t=[];function e(s){return r=>{r.merged||(r.barycenter===void 0||s.barycenter===void 0||r.barycenter>=s.barycenter)&&Ep(s,r)}}o(e,"t");function i(s){return r=>{r.in.push(s),--r.indegree===0&&n.push(r)}}for(o(i,"r");n.length;){let s=n.pop();t.push(s),s.in.reverse().forEach(e(s)),s.out.forEach(i(s))}return t.filter(s=>!s.merged).map(s=>_i(s,["vs","i","barycenter","weight"]))}o(_p,"Et");function Ep(n,t){let e=0,i=0;n.weight&&(e+=n.barycenter*n.weight,i+=n.weight),t.weight&&(e+=t.barycenter*t.weight,i+=t.weight),n.vs=t.vs.concat(n.vs),n.barycenter=e/i,n.weight=i,n.i=Math.min(t.i,n.i),t.merged=!0}o(Ep,"Lt");function kp(n,t){let e=ku(n,u=>Object.hasOwn(u,"barycenter")),i=e.lhs,s=e.rhs.sort((u,g)=>g.i-u.i),r=[],a=0,l=0,c=0;i.sort(Sp(!!t)),c=Yl(r,s,c),i.forEach(u=>{c+=u.vs.length,r.push(u.vs),a+=u.barycenter*u.weight,l+=u.weight,c=Yl(r,s,c)});let h={vs:r.flat(1)};return l&&(h.barycenter=a/l,h.weight=l),h}o(kp,"ae");function Yl(n,t,e){let i;for(;t.length&&(i=t[t.length-1]).i<=e;)t.pop(),n.push(i.vs),e++;return e}o(Yl,"on");function Sp(n){return(t,e)=>t.barycenter<e.barycenter?-1:t.barycenter>e.barycenter?1:n?e.i-t.i:t.i-e.i}o(Sp,"yt");function Zl(n,t,e,i){let s=n.children(t),r=n.node(t),a=r?r.borderLeft:void 0,l=r?r.borderRight:void 0,c={};a&&(s=s.filter(p=>p!==a&&p!==l));let h=wp(n,s);h.forEach(p=>{if(n.children(p.v).length){let m=Zl(n,p.v,e,i);c[p.v]=m,Object.hasOwn(m,"barycenter")&&Ap(p,m)}});let u=vp(h,e);Mp(u,c);let g=kp(u,i);if(a&&l){g.vs=[a,g.vs,l].flat(1);let p=n.predecessors(a);if(p&&p.length){let m=n.node(p[0]),b=n.predecessors(l),x=n.node(b[0]);Object.hasOwn(g,"barycenter")||(g.barycenter=0,g.weight=0),g.barycenter=(g.barycenter*g.weight+m.order+x.order)/(g.weight+2),g.weight+=2}}return g}o(Zl,"W");function Mp(n,t){n.forEach(e=>{e.vs=e.vs.flatMap(i=>t[i]?t[i].vs:i)})}o(Mp,"wt");function Ap(n,t){n.barycenter!==void 0?(n.barycenter=(n.barycenter*n.weight+t.barycenter*t.weight)/(n.weight+t.weight),n.weight+=t.weight):(n.barycenter=t.barycenter,n.weight=t.weight)}o(Ap,"Nt");function Cp(n,t,e,i){i||(i=n.nodes());let s=Ip(n),r=new bt({compound:!0}).setGraph({root:s}).setDefaultNodeLabel(a=>n.node(a));return i.forEach(a=>{let l=n.node(a),c=n.parent(a);if(l.rank===t||l.minRank<=t&&t<=l.maxRank){r.setNode(a),r.setParent(a,c||s);let h=n[e](a);h&&h.forEach(u=>{let g=u.v===a?u.w:u.v,p=r.edge(g,a),m=p!==void 0?p.weight:0;r.setEdge(g,a,{weight:n.edge(u).weight+m})}),Object.hasOwn(l,"minRank")&&r.setNode(a,{borderLeft:l.borderLeft[t],borderRight:l.borderRight[t]})}}),r}o(Cp,"de");function Ip(n){let t;for(;n.hasNode(t=Es("_root")););return t}o(Ip,"Gt");function jp(n,t,e){let i={},s;e.forEach(r=>{let a=n.parent(r),l,c;for(;a;){if(l=n.parent(a),l?(c=i[l],i[l]=a):(c=s,s=a),c&&c!==a){t.setEdge(c,a);return}a=l}})}o(jp,"le");function Kl(n,t={}){if(typeof t.customOrder=="function"){t.customOrder(n,Kl);return}let e=Nl(n),i=Ul(n,Sn(1,e+1),"inEdges"),s=Ul(n,Sn(e-1,-1,-1),"outEdges"),r=xp(n);if(Xl(n,r),t.disableOptimalOrderHeuristic)return;let a=Number.POSITIVE_INFINITY,l,c=t.constraints||[];for(let h=0,u=0;u<4;++h,++u){Pp(h%2?i:s,h%4>=2,c),r=vi(n);let g=yp(n,r);g<a?(u=0,l=Object.assign({},r),a=g):g===a&&(l=structuredClone(r))}Xl(n,l)}o(Kl,"B");function Ul(n,t,e){let i=new Map,s=o((r,a)=>{i.has(r)||i.set(r,[]),i.get(r).push(a)},"o");for(let r of n.nodes()){let a=n.node(r);if(typeof a.rank=="number"&&s(a.rank,r),typeof a.minRank=="number"&&typeof a.maxRank=="number")for(let l=a.minRank;l<=a.maxRank;l++)l!==a.rank&&s(l,r)}return t.map(function(r){return Cp(n,r,e,i.get(r)||[])})}o(Ul,"sn");function Pp(n,t,e){let i=new bt;n.forEach(function(s){e.forEach(l=>i.setEdge(l.left,l.right));let r=s.graph().root,a=Zl(s,r,i,t);a.vs.forEach((l,c)=>s.node(l).order=c),jp(s,i,a.vs)})}o(Pp,"kt");function Xl(n,t){Object.values(t).forEach(e=>e.forEach((i,s)=>n.node(i).order=s))}o(Xl,"an");function Np(n,t){let e={};function i(s,r){let a=0,l=0,c=s.length,h=r[r.length-1];return r.forEach((u,g)=>{let p=Dp(n,u),m=p?n.node(p).order:c;(p||u===h)&&(r.slice(l,g+1).forEach(b=>{let x=n.predecessors(b);x&&x.forEach(w=>{let v=n.node(w),_=v.order;(_<a||m<_)&&!(v.dummy&&n.node(b).dummy)&&ql(e,w,b)})}),l=g+1,a=m)}),r}return o(i,"r"),t.length&&t.reduce(i),e}o(Np,"vt");function Tp(n,t){let e={};function i(r,a,l,c,h){Sn(a,l).forEach(u=>{let g=r[u];if(g!==void 0&&n.node(g).dummy){let p=n.predecessors(g);p&&p.forEach(m=>{if(m===void 0)return;let b=n.node(m);b.dummy&&(b.order<c||b.order>h)&&ql(e,m,g)})}})}o(i,"r");function s(r,a){let l=-1,c=-1,h=0;return a.forEach((u,g)=>{if(n.node(u).dummy==="border"){let p=n.predecessors(u);if(p&&p.length){let m=p[0];if(m===void 0)return;c=n.node(m).order,i(a,h,g,l,c),h=g,l=c}}i(a,h,a.length,c,r.length)}),a}return o(s,"o"),t.length&&t.reduce(s),e}o(Tp,"_t");function Dp(n,t){if(n.node(t).dummy){let e=n.predecessors(t);if(e)return e.find(i=>n.node(i).dummy)}}o(Dp,"xt");function ql(n,t,e){if(t>e){let s=t;t=e,e=s}let i=n[t];i||(n[t]=i={}),i[e]=!0}o(ql,"dn");function Lp(n,t,e){if(t>e){let s=t;t=e,e=s}let i=n[t];return i!==void 0&&Object.hasOwn(i,e)}o(Lp,"Tt");function Op(n,t,e,i){let s={},r={},a={};return t.forEach(l=>{l.forEach((c,h)=>{s[c]=c,r[c]=c,a[c]=h})}),t.forEach(l=>{let c=-1;l.forEach(h=>{let u=i(h);if(u&&u.length){let g=u.sort((m,b)=>{let x=a[m],w=a[b];return(x!==void 0?x:0)-(w!==void 0?w:0)}),p=(g.length-1)/2;for(let m=Math.floor(p),b=Math.ceil(p);m<=b;++m){let x=g[m];if(x===void 0)continue;let w=a[x];if(w!==void 0&&r[h]===h&&c<w&&!Lp(e,h,x)){let v=s[x];v!==void 0&&(r[x]=h,r[h]=s[h]=v,c=w)}}}})}),{root:s,align:r}}o(Op,"Ot");function zp(n,t,e,i,s=!1){let r={},a=$p(n,t,e,s),l=s?"borderLeft":"borderRight";function c(m,b){let x=a.nodes().slice(),w={},v=x.pop();for(;v;){if(w[v])m(v);else{w[v]=!0,x.push(v);for(let _ of b(v))x.push(_)}v=x.pop()}}o(c,"d");function h(m){let b=a.inEdges(m);b?r[m]=b.reduce((x,w)=>{var v;let _=(v=r[w.v])!=null?v:0,E=a.edge(w);return Math.max(x,_+(E!==void 0?E:0))},0):r[m]=0}o(h,"l");function u(m){let b=a.outEdges(m),x=Number.POSITIVE_INFINITY;b&&(x=b.reduce((v,_)=>{let E=r[_.w],j=a.edge(_);return Math.min(v,(E!==void 0?E:0)-(j!==void 0?j:0))},Number.POSITIVE_INFINITY));let w=n.node(m);x!==Number.POSITIVE_INFINITY&&w.borderType!==l&&(r[m]=Math.max(r[m]!==void 0?r[m]:0,x))}o(u,"u");function g(m){return a.predecessors(m)||[]}o(g,"c");function p(m){return a.successors(m)||[]}return o(p,"h"),c(h,g),c(u,p),Object.keys(i).forEach(m=>{var b;let x=e[m];x!==void 0&&(r[m]=(b=r[x])!=null?b:0)}),r}o(zp,"It");function $p(n,t,e,i){let s=new bt,r=n.graph(),a=Gp(r.nodesep,r.edgesep,i);return t.forEach(l=>{let c;l.forEach(h=>{let u=e[h];if(u!==void 0){if(s.setNode(u),c!==void 0){let g=e[c];if(g!==void 0){let p=s.edge(g,u);s.setEdge(g,u,Math.max(a(n,h,c),p||0))}}c=h}})}),s}o($p,"Ct");function Fp(n,t){return Object.values(t).reduce((e,i)=>{let s=Number.NEGATIVE_INFINITY,r=Number.POSITIVE_INFINITY;Object.entries(i).forEach(([l,c])=>{let h=Vp(n,l)/2;s=Math.max(c+h,s),r=Math.min(c-h,r)});let a=s-r;return a<e[0]&&(e=[a,i]),e},[Number.POSITIVE_INFINITY,null])[1]}o(Fp,"Rt");function Hp(n,t){let e=Object.values(t),i=zt(Math.min,e),s=zt(Math.max,e);["u","d"].forEach(r=>{["l","r"].forEach(a=>{let l=r+a,c=n[l];if(!c||c===t)return;let h=Object.values(c),u=i-zt(Math.min,h);a!=="l"&&(u=s-zt(Math.max,h)),u&&(n[l]=Ei(c,g=>g+u))})})}o(Hp,"Pt");function Bp(n,t=void 0){let e=n.ul;return e?Ei(e,(i,s)=>{var r,a;if(t){let c=t.toLowerCase(),h=n[c];if(h&&h[s]!==void 0)return h[s]}let l=Object.values(n).map(c=>{let h=c[s];return h!==void 0?h:0}).sort((c,h)=>c-h);return(((r=l[1])!=null?r:0)+((a=l[2])!=null?a:0))/2}):{}}o(Bp,"Mt");function Rp(n){let t=vi(n),e=Object.assign(Np(n,t),Tp(n,t)),i={},s;["u","d"].forEach(a=>{s=a==="u"?t:Object.values(t).reverse(),["l","r"].forEach(l=>{l==="r"&&(s=s.map(u=>Object.values(u).reverse()));let c=Op(n,s,e,u=>(a==="u"?n.predecessors(u):n.successors(u))||[]),h=zp(n,s,c.root,c.align,l==="r");l==="r"&&(h=Ei(h,u=>-u)),i[a+l]=h})});let r=Fp(n,i);return Hp(i,r),Bp(i,n.graph().align)}o(Rp,"ln");function Gp(n,t,e){return(i,s,r)=>{let a=i.node(s),l=i.node(r),c=0,h;if(c+=a.width/2,Object.hasOwn(a,"labelpos"))switch(a.labelpos.toLowerCase()){case"l":h=-a.width/2;break;case"r":h=a.width/2;break}if(h&&(c+=e?h:-h),h=void 0,c+=(a.dummy?t:n)/2,c+=(l.dummy?t:n)/2,c+=l.width/2,Object.hasOwn(l,"labelpos"))switch(l.labelpos.toLowerCase()){case"l":h=l.width/2;break;case"r":h=-l.width/2;break}return h&&(c+=e?h:-h),c}}o(Gp,"jt");function Vp(n,t){return n.node(t).width}o(Vp,"St");function Wp(n){n=Cl(n),Yp(n),Object.entries(Rp(n)).forEach(([t,e])=>n.node(t).x=e)}o(Wp,"un");function Yp(n){let t=vi(n),e=n.graph(),i=e.ranksep,s=e.rankalign,r=0;t.forEach(a=>{let l=a.reduce((c,h)=>{var u;let g=(u=n.node(h).height)!=null?u:0;return c>g?c:g},0);a.forEach(c=>{let h=n.node(c);s==="top"?h.y=r+h.height/2:s==="bottom"?h.y=r+l-h.height/2:h.y=r+l/2}),r+=l+i})}o(Yp,"Ft");function Zp(n,t={}){let e=t.debugTiming?Su:Mu;return e("layout",()=>{let i=e(" buildLayoutGraph",()=>ig(n));return e(" runLayout",()=>Kp(i,e,t)),e(" updateInputGraph",()=>Up(n,i)),i})}o(Zp,"he");function Kp(n,t,e){t(" makeSpaceForEdgeLabels",()=>sg(n)),t(" removeSelfEdges",()=>pg(n)),t(" acyclic",()=>zu(n)),t(" nestingGraph.run",()=>op(n)),t(" rank",()=>Qu(Cl(n))),t(" injectEdgeLabelProxies",()=>rg(n)),t(" removeEmptyRanks",()=>_u(n)),t(" nestingGraph.cleanup",()=>dp(n)),t(" normalizeRanks",()=>vu(n)),t(" assignRankMinMax",()=>ag(n)),t(" removeEdgeLabelProxies",()=>og(n)),t(" normalize.run",()=>Hu(n)),t(" parentDummyChains",()=>ip(n)),t(" addBorderSegments",()=>hp(n)),t(" order",()=>Kl(n,e)),t(" insertSelfEdges",()=>gg(n)),t(" adjustCoordinateSystem",()=>pp(n)),t(" position",()=>Wp(n)),t(" positionSelfEdges",()=>fg(n)),t(" removeBorderNodes",()=>ug(n)),t(" normalize.undo",()=>Ru(n)),t(" fixupEdgeLabelCoords",()=>dg(n)),t(" undoCoordinateSystem",()=>gp(n)),t(" translateGraph",()=>lg(n)),t(" assignNodeIntersects",()=>cg(n)),t(" reversePoints",()=>hg(n)),t(" acyclic.undo",()=>Fu(n))}o(Kp,"Dt");function Up(n,t){n.nodes().forEach(e=>{let i=n.node(e),s=t.node(e);i&&(i.x=s.x,i.y=s.y,i.order=s.order,i.rank=s.rank,t.children(e).length&&(i.width=s.width,i.height=s.height))}),n.edges().forEach(e=>{let i=n.edge(e),s=t.edge(e);i.points=s.points,Object.hasOwn(s,"x")&&(i.x=s.x,i.y=s.y)}),n.graph().width=t.graph().width,n.graph().height=t.graph().height}o(Up,"At");var Xp=["nodesep","edgesep","ranksep","marginx","marginy"],qp={ranksep:50,edgesep:20,nodesep:50,rankdir:"TB",rankalign:"center"},Jp=["acyclicer","ranker","rankdir","align","rankalign"],Qp=["width","height","rank"],Jl={width:0,height:0},tg=["minlen","weight","width","height","labeloffset"],eg={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},ng=["labelpos"];function ig(n){let t=new bt({multigraph:!0,compound:!0}),e=Ns(n.graph());return t.setGraph(Object.assign({},qp,Ps(e,Xp),_i(e,Jp))),n.nodes().forEach(i=>{let s=Ns(n.node(i)),r=Ps(s,Qp);Object.keys(Jl).forEach(l=>{r[l]===void 0&&(r[l]=Jl[l])}),t.setNode(i,r);let a=n.parent(i);a!==void 0&&t.setParent(i,a)}),n.edges().forEach(i=>{let s=Ns(n.edge(i));t.setEdge(i,Object.assign({},eg,Ps(s,tg),_i(s,ng)))}),t}o(ig,"Xt");function sg(n){let t=n.graph();t.ranksep/=2,n.edges().forEach(e=>{let i=n.edge(e);i.minlen*=2,i.labelpos.toLowerCase()!=="c"&&(t.rankdir==="TB"||t.rankdir==="BT"?i.width+=i.labeloffset:i.height+=i.labeloffset)})}o(sg,"Ut");function rg(n){n.edges().forEach(t=>{let e=n.edge(t);if(e.width&&e.height){let i=n.node(t.v),s={rank:(n.node(t.w).rank-i.rank)/2+i.rank,e:t};Ae(n,"edge-proxy",s,"_ep")}})}o(rg,"Kt");function ag(n){let t=0;n.nodes().forEach(e=>{let i=n.node(e);i.borderTop&&(i.minRank=n.node(i.borderTop).rank,i.maxRank=n.node(i.borderBottom).rank,t=Math.max(t,i.maxRank))}),n.graph().maxRank=t}o(ag,"$t");function og(n){n.nodes().forEach(t=>{let e=n.node(t);if(e.dummy==="edge-proxy"){let i=e;n.edge(i.e).labelRank=e.rank,n.removeNode(t)}})}o(og,"Jt");function lg(n){let t=Number.POSITIVE_INFINITY,e=0,i=Number.POSITIVE_INFINITY,s=0,r=n.graph(),a=r.marginx||0,l=r.marginy||0;function c(h){let u=h.x,g=h.y,p=h.width,m=h.height;t=Math.min(t,u-p/2),e=Math.max(e,u+p/2),i=Math.min(i,g-m/2),s=Math.max(s,g+m/2)}o(c,"d"),n.nodes().forEach(h=>c(n.node(h))),n.edges().forEach(h=>{let u=n.edge(h);Object.hasOwn(u,"x")&&c(u)}),t-=a,i-=l,n.nodes().forEach(h=>{let u=n.node(h);u.x-=t,u.y-=i}),n.edges().forEach(h=>{let u=n.edge(h);u.points.forEach(g=>{g.x-=t,g.y-=i}),Object.hasOwn(u,"x")&&(u.x-=t),Object.hasOwn(u,"y")&&(u.y-=i)}),r.width=e-t+a,r.height=s-i+l}o(lg,"Qt");function cg(n){n.edges().forEach(t=>{let e=n.edge(t),i=n.node(t.v),s=n.node(t.w),r,a;e.points?(r=e.points[0],a=e.points[e.points.length-1]):(e.points=[],r=s,a=i),e.points.unshift(Il(i,r)),e.points.push(Il(s,a))})}o(cg,"Zt");function dg(n){n.edges().forEach(t=>{let e=n.edge(t);if(Object.hasOwn(e,"x"))switch((e.labelpos==="l"||e.labelpos==="r")&&(e.width-=e.labeloffset),e.labelpos){case"l":e.x-=e.width/2+e.labeloffset;break;case"r":e.x+=e.width/2+e.labeloffset;break}})}o(dg,"er");function hg(n){n.edges().forEach(t=>{let e=n.edge(t);e.reversed&&e.points.reverse()})}o(hg,"nr");function ug(n){n.nodes().forEach(t=>{if(n.children(t).length){let e=n.node(t),i=n.node(e.borderTop),s=n.node(e.borderBottom),r=n.node(e.borderLeft[e.borderLeft.length-1]),a=n.node(e.borderRight[e.borderRight.length-1]);e.width=Math.abs(a.x-r.x),e.height=Math.abs(s.y-i.y),e.x=r.x+e.width/2,e.y=i.y+e.height/2}}),n.nodes().forEach(t=>{n.node(t).dummy==="border"&&n.removeNode(t)})}o(ug,"tr");function pg(n){n.edges().forEach(t=>{if(t.v===t.w){let e=n.node(t.v);e.selfEdges||(e.selfEdges=[]),e.selfEdges.push({e:t,label:n.edge(t)}),n.removeEdge(t)}})}o(pg,"rr");function gg(n){vi(n).forEach(t=>{let e=0;t.forEach((i,s)=>{let r=n.node(i);r.order=s+e,(r.selfEdges||[]).forEach(a=>{Ae(n,"selfedge",{width:a.label.width,height:a.label.height,rank:r.rank,order:s+ ++e,e:a.e,label:a.label},"_se")}),delete r.selfEdges})})}o(gg,"or");function fg(n){n.nodes().forEach(t=>{let e=n.node(t);if(e.dummy==="selfedge"){let i=e,s=n.node(i.e.v),r=s.x+s.width/2,a=s.y,l=e.x-r,c=s.height/2;n.setEdge(i.e,i.label),n.removeNode(t),i.label.points=[{x:r+2*l/3,y:a-c},{x:r+5*l/6,y:a-c},{x:r+l,y:a},{x:r+5*l/6,y:a+c},{x:r+2*l/3,y:a+c}],i.label.x=e.x,i.label.y=e.y}})}o(fg,"ir");function Ps(n,t){return Ei(_i(n,t),Number)}o(Ps,"ue");function Ns(n){let t={};return n&&Object.entries(n).forEach(([e,i])=>{typeof e=="string"&&(e=e.toLowerCase()),t[e]=i}),t}o(Ns,"ce");function mg(n){return n.nodes.filter(t=>t instanceof Zt)}o(mg,"relationalNodes");function xg(n){return n.edges.filter(t=>t instanceof It)}o(xg,"relationalEdges");function yg(n,t,e){n.from===t&&n.to===e||(n.from.removeOutgoingEdge(n),n.to.removeIncomingEdge(n),n.setState("from",t),n.setState("to",e),n.setState("displacementStart",void 0),n.setState("displacementEnd",void 0),n.setState("startAnchor",{mode:"fixed",position:t.relativePosition}),n.setState("endAnchor",{mode:"fixed",position:e.relativePosition}),t.addOutgoingEdge(n,!1),e.addIncomingEdge(n,!1))}o(yg,"rewire");function bg(n){n.forEach(t=>{const e=t.from.parent,i=t.to.parent,s=Math.max(0,t.mappingIndex),r=t.sourceAttributeIds[Math.min(s,t.sourceAttributeIds.length-1)],a=t.targetAttributeIds[Math.min(s,t.targetAttributeIds.length-1)],l=e.box.middle.x<=i.box.middle.x?"right":"left",c=l==="right"?"left":"right",h=e.gatewayForAttribute(r,l),u=i.gatewayForAttribute(a,c);h&&u&&yg(t,h,u)})}o(bg,"alignForeignKeyGateways");function wg(n,t){n.forEach(e=>{e.from.recomputeConnectedEdge(e,"from");const i=e.labels[0];if(!i)return;const s=e instanceof It?t.get(e.constraintId):void 0;i.setPosition(s?new y([s.x-s.width/2,s.y-s.height/2]):e.defaultLabelPosition())})}o(wg,"reroute");function vg(n){const t=mg(n);if(t.length===0)return!1;const e=xg(n),i=n.getExtension(R)?.gridSize??50,s=new bt({multigraph:!0}).setGraph({rankdir:"LR",ranker:"network-simplex",rankalign:"center",ranksep:i*3,nodesep:i*2,edgesep:i,marginx:i*2,marginy:i*2}).setDefaultEdgeLabel(()=>({}));t.forEach(c=>{s.setNode(c.id,{width:c.box.width,height:c.box.height})});const r=new Set;e.forEach(c=>{if(r.has(c.constraintId))return;r.add(c.constraintId);const h=c.from.parent,u=c.to.parent;if(h===u)return;const g=c.labels[0];s.setEdge(u.id,h.id,{height:g?.size.height??0,labelpos:"c",minlen:1,weight:2,width:g?.size.width??0},c.constraintId)}),Zp(s);const a=new Map;e.forEach(c=>{if(c.mappingIndex!==0||!c.labels[0])return;const h=c.from.parent,u=c.to.parent;if(h===u)return;const g=s.edge(u.id,h.id,c.constraintId);g?.x!==void 0&&g.y!==void 0&&g.width!==void 0&&g.height!==void 0&&a.set(c.constraintId,g)});let l=!1;return t.forEach(c=>{const h=s.node(c.id);if(!h||h.x===void 0||h.y===void 0)return;const u=new y([h.x-c.box.width/2,h.y-c.box.height/2]).snapToGrid(i);l||=!u.equals(c.coordinates),c.setPosition(u,{updateConnectedEdges:!1})}),bg(e),wg(e,a),l}o(vg,"applyMRAutoLayout");function _g(n){return n.model.constraints.find(e=>e.kind==="primary-key"&&e.attributeIds.length>0)?.attributeIds??n.model.attributes.filter(e=>e.primaryKey).map(e=>e.id)}o(_g,"primaryKeyAttributes");function Ql(n,t){return n[Math.min(t,n.length-1)]}o(Ql,"mappingValue");const qa=class qa extends _e{constructor(t){super(t),this.registerClass(Zt),this.registerClass(It),this.registerExtension(En),this.setDefaultEdge(It)}createTableFromClientPoint(t,e,i,s){const r=this.canvas.inverseFit(new y([e,i]));return this.getExtension(En).createTable(r,t,s)}createTableAtCanvasPoint(t,e,i,s){return this.getExtension(En).createTable(new y([e,i]),t,s)}autoLayout(){return this.emit(new xi(this)),vg(this)}connectForeignKey(t,e,i={}){const s=i.sourceAttributeIds?.length?[...i.sourceAttributeIds]:[t.model.attributes.find(g=>!g.primaryKey)?.id??t.model.attributes[0]?.id].filter(Boolean),r=i.targetAttributeIds?.length?[...i.targetAttributeIds]:_g(e);if(!s.length||!r.length)throw new Error("Foreign keys require source and referenced attributes.");const a=t.box.middle.x<=e.box.middle.x?"right":"left",l=a==="right"?"left":"right",c=Math.max(s.length,r.length),h=[];let u=i.constraintId;for(let g=0;g<c;g+=1){const p=Ql(s,g),m=Ql(r,g),b=t.gatewayForAttribute(p,a),x=e.gatewayForAttribute(m,l);if(!b||!x)throw new Error("Unable to resolve a foreign-key attribute gateway.");const w=this.connect(b,x);u??=w.constraintId,w.updateModel({...i,constraintId:u,mappingIndex:g,sourceAttributeIds:s,targetAttributeIds:r}),h.push(w)}return h[0]}};o(qa,"MRDiagram");let Ts=qa;function he(n){return n&&(Object.assign(n,{__scalable:!0}),n)}o(he,"makeScalableComponent");function Eg(n){return n&&(Object.assign(n,{__scalableBack:!0}),n)}o(Eg,"makeBackScalableComponent");const Ds=he(({coordinates:n,size:t=20,strokeWidth:e=2,rounded:i=!0,stroke:s="#ff0000"})=>{const r=t/2,a=i?"round":"butt";return d.jsxs(d.Fragment,{children:[d.jsx("line",{x1:n.x-r,y1:n.y,x2:n.x+r,y2:n.y,stroke:s,strokeWidth:e,strokeLinecap:a}),d.jsx("line",{x1:n.x,y1:n.y-r,x2:n.x,y2:n.y+r,stroke:s,strokeWidth:e,strokeLinecap:a})]})}),kg=0,tc=32;function ec(n){switch(n){case"left":return[-1,0];case"right":return[1,0];case"up":return[0,-1];case"down":return[0,1];default:return[1,0]}}o(ec,"orientationVector$1");function Sg(n,t,e,i,s){const r=1-s,a=r**3,l=3*r**2*s,c=3*r*s**2,h=s**3;return new y([n.x*a+t.x*l+e.x*c+i.x*h,n.y*a+t.y*l+e.y*c+i.y*h],!1)}o(Sg,"cubicPoint");function Mg(n){const t=n.steps;if(t.length<2||n.pathType==="orthogonal")return[...t];const e=t[0],i=t.at(-1);if(n.pathType==="straight")return[e,i];const s=e.distance(i),r=Math.max(40,Math.min(160,s/2)),a=ec(n.from.orientation),l=ec(n.to.orientation),c=new y([e.x+a[0]*r,e.y+a[1]*r],!1),h=new y([i.x+l[0]*r,i.y+l[1]*r],!1);return Array.from({length:tc+1},(u,g)=>Sg(e,c,h,i,g/tc))}o(Mg,"routePolyline");function Ag(n,t,e=kg){const i=Mg(n);let s=Number.POSITIVE_INFINITY,r=null,a=null;for(let u=0;u<i.length-1;u+=1){const g=i[u],p=i[u+1],m=p.x-g.x,b=p.y-g.y,x=m**2+b**2;if(x<1e-6)continue;const w=Math.max(0,Math.min(1,((t.x-g.x)*m+(t.y-g.y)*b)/x)),v=g.x+m*w,_=g.y+b*w,E=(t.x-v)**2+(t.y-_)**2;E>=s||(s=E,r=[v,_],a=[m,b])}if(!r||!a)return t.copy().sum([0,-e]);const l=Math.hypot(a[0],a[1]);let c=-a[1]/l,h=a[0]/l;return(h>1e-6||Math.abs(h)<=1e-6&&c<0)&&(c*=-1,h*=-1),new y([r[0]+c*e,r[1]+h*e])}o(Ag,"positionEdgeLabelBesideRoute");function nc(n){switch(n){case"left":return[-1,0];case"right":return[1,0];case"up":return[0,-1];case"down":return[0,1];default:return[1,0]}}o(nc,"orientationVector");function Cg(n,t,e){const i=n[0],s=n.at(-1),r=t?.pathType??e??"orthogonal";if(r==="orthogonal")return"M "+n.map(b=>`${b.x} ${b.y}`).join(" L ");if(r==="straight")return`M ${i.x} ${i.y} L ${s.x} ${s.y}`;const a=i.distance(s),l=Math.max(40,Math.min(160,a/2)),c=nc(t?.from.orientation),h=nc(t?.to.orientation),u=i.x+c[0]*l,g=i.y+c[1]*l,p=s.x+h[0]*l,m=s.y+h[1]*l;return`M ${i.x} ${i.y} C ${u} ${g}, ${p} ${m}, ${s.x} ${s.y}`}o(Cg,"buildEdgePath");const Ig={};function jg(){const n=Ig;return n.DEBUG_EDGES===!0||n.DEBUG_EDGES==="true"}o(jg,"debugEdgesEnabled");function Pg(n,t){const e=n instanceof H?n.mode:"coordinate",i=n instanceof H?n.manualAxes:"none";return`${t}: x=${n.x}, y=${n.y}, mode=${e}, manualAxes=${i}`}o(Pg,"formatPoint");function Ng(n,t){const e=t.points[0],i=t.points[1],s=n.steps.findIndex((a,l)=>a===e&&n.steps[l+1]===i);if(s>=0)return s;const r=Number(t.id);return Number.isFinite(r)?r:null}o(Ng,"segmentIndexFor");function Tg(n,t){if(t.type==="edge")return"clicked: edge path";if(t.type==="endpoint")return`clicked: endpoint ${t.endpoint}`;const e=Ng(n,t.midpoint),i=e===null?"unknown":`${e} -> ${e+1}`;return["clicked: drag point",`dragPoint.midpointId=${t.midpoint.id}`,`dragPoint.renderedIndex=${t.renderedIndex}`,`dragPoint.segment=${i}`,`dragPoint.x=${t.midpoint.x}`,`dragPoint.y=${t.midpoint.y}`].join(`
|
|
3
|
+
`)}o(Tg,"formatClickedTarget");function Dg(n,t){return[`edge.id=${n.id}`,`from=${n.from.parent.id}.${n.from.id} orientation=${n.from.orientation}`,`to=${n.to.parent.id}.${n.to.id} orientation=${n.to.orientation}`,Tg(n,t),"points:",...n.steps.map(Pg)].join(`
|
|
4
|
+
`)}o(Dg,"formatEdgeDebug");async function Lg(n){if(navigator.clipboard?.writeText){await navigator.clipboard.writeText(n);return}const t=document.createElement("textarea");t.value=n,t.style.position="fixed",t.style.left="-9999px",document.body.appendChild(t),t.focus(),t.select(),document.execCommand("copy"),t.remove()}o(Lg,"writeClipboard");function Mn(n,t){if(!n||!jg())return;const e=Dg(n,t);Lg(e).then(()=>{console.info("[DEBUG_EDGES] copied edge debug to clipboard",e)}).catch(i=>{console.warn("[DEBUG_EDGES] failed to copy edge debug to clipboard",i,e)})}o(Mn,"copyEdgeDebugToClipboard");const ic=o(({id:n,color:t,type:e,width:i,arrowSize:s,flip:r=!1})=>{const a=r?"180":"auto",l="white";switch(e){case"arrow":return d.jsx("marker",{id:n,markerWidth:s,markerHeight:s,refX:r?0:s*.9,refY:s/2,orient:a,markerUnits:"userSpaceOnUse",children:d.jsx("path",{d:`M0,0 L${s},${s/2} L0,${s} Z`,fill:t,className:"edge_marker_path"})});case"arrow-open":return d.jsx("marker",{id:n,markerWidth:s,markerHeight:s,refX:r?0:s,refY:s/2,orient:a,markerUnits:"userSpaceOnUse",children:d.jsx("path",{d:`M0,0 L${s},${s/2} L0,${s}`,fill:"none",stroke:t,strokeWidth:i,strokeLinecap:"butt",strokeLinejoin:"miter",className:"edge_marker_outline"})});case"triangle":return d.jsx("marker",{id:n,markerWidth:s,markerHeight:s,refX:r?0:s,refY:s/2,orient:a,markerUnits:"userSpaceOnUse",children:d.jsx("path",{d:`M0,0 L${s},${s/2} L0,${s} Z`,fill:l,stroke:t,strokeWidth:i/2,className:"edge_marker_outline"})});case"triangle-filled":return d.jsx("marker",{id:n,markerWidth:s,markerHeight:s,refX:r?0:s,refY:s/2,orient:a,markerUnits:"userSpaceOnUse",children:d.jsx("path",{d:`M0,0 L${s},${s/2} L0,${s} Z`,fill:t,className:"edge_marker_path"})});case"diamond":return d.jsx("marker",{id:n,markerWidth:s,markerHeight:s,refX:r?0:s*.9,refY:s/2,orient:a,markerUnits:"userSpaceOnUse",children:d.jsx("path",{d:`M0,${s/2} L${s/2},0 L${s},${s/2} L${s/2},${s} Z`,fill:"white",stroke:t,strokeWidth:i/2,className:"edge_marker_outline"})});case"circle-small":return d.jsx("marker",{id:n,markerWidth:s,markerHeight:s,refX:s/2,refY:s/2,orient:a,markerUnits:"userSpaceOnUse",children:d.jsx("circle",{cx:s/2,cy:s/2,r:s/4,fill:"white",stroke:t,strokeWidth:i/2,className:"edge_marker_outline"})});case"circle-medium":return d.jsx("marker",{id:n,markerWidth:s*1.5,markerHeight:s*1.5,refX:s*1.5/2,refY:s*1.5/2,orient:a,markerUnits:"userSpaceOnUse",children:d.jsx("circle",{cx:s*1.5/2,cy:s*1.5/2,r:s/2,fill:"white",stroke:t,strokeWidth:i/2,className:"edge_marker_outline"})});case"default-flow":return d.jsx("marker",{id:n,markerWidth:s,markerHeight:s,refX:s*.2-5-i/2,refY:s/2,orient:a,markerUnits:"userSpaceOnUse",children:d.jsx("path",{d:`M${s*.2},${s*.85} L${s*.8},${s*.15}`,fill:"none",stroke:t,strokeLinecap:"round",strokeWidth:i,className:"edge_marker_outline"})});case"measure":return d.jsx("marker",{id:n,markerWidth:s*5,markerHeight:s*5,refX:0,refY:s/2,orient:a,markerUnits:"userSpaceOnUse",children:d.jsx("path",{d:`M0,0 L0,${s/2}`,stroke:t,strokeWidth:3,strokeLinecap:"round",className:"edge_marker_outline"})});default:return null}},"EdgeMarker"),Mi=class Mi extends y{constructor(t,e,i,s){super(s),this.id=t,this.edge=e,this.points=i,this.assign(i[0].copy().sum(i[1]).divide(2)),f.makeObservable(this,{points:f.observable})}id;edge;points;copy(){return new Mi(this.id,this.edge,this.points,super.copy())}};o(Mi,"Midpoint");let Ls=Mi;function Og(n,t){const e=[];for(let i=0;i<t.length-1;i++){const s=[t[i],t[i+1]],r=s.filter(l=>l instanceof H&&l.mode==="static").length,a=n.steps.length===2&&t.length===2;r===2&&!a||e.push(new Ls(String(i),n,s))}return e}o(Og,"getSegmentMidpoints");const zg=o(({edge:n,onMouseDown:t,points:e})=>{const i=Og(n,e);return d.jsx(d.Fragment,{children:i.map((s,r)=>{const a=s.x,l=s.y;return d.jsx("rect",{x:a-6,y:l-6,width:12,height:12,rx:4,className:"edge_drag_point","data-edge-id":n.id,"data-midpoint-id":s.id,"data-midpoint-index":r,onMouseDownCapture:o(c=>{c.button===0&&(Mn(n,{type:"drag-point",midpoint:s,renderedIndex:r}),t(s,c))},"onMouseDownCapture")},s.id)})})},"EdgeMidpoints");function $g(n){if(n instanceof H)switch(n.mode){case"auto":return"red";case"manual":return"green";case"static":return"yellow"}}o($g,"crossColor");const An=A.observer(({edge:n,points:t,color:e,width:i=2,arrowSize:s=8,startType:r="none",endType:a="arrow",lineStyle:l="solid",pathType:c,endStroke:h=e,startStroke:u=e,onMidpointMouseDown:g,onEndpointMouseDown:p,className:m,draggable:b})=>{const x=o(M=>k.useMemo(()=>`marker-${M}-${Math.random().toString(36).slice(2)}`,[]),"makeId"),w=x("start"),v=x("end");if(!t||t.length<2)return null;const _=Cg(t,n,c),E=l==="dashed"?`${i*3},${i*2}`:l==="dotted"?`${i},${i*2}`:"none",j=!!(n&&b&&n.pathType==="orthogonal"&&(n.state.hover||n.state.dragging||n.state.selected)),P=!!(n&&b&&(n.state.selected||n.state.dragging));return d.jsxs("g",{"data-id":n?.id,className:["edge",n?.state.dragging&&"dragging",n?.state.selected&&"selected",n?.state.hover&&"hover",m].filter(Boolean).join(" "),style:e?{"--edge-stroke":e}:void 0,onMouseEnter:o(()=>{f.runInAction(()=>{n&&(n.state.hover=!0)})},"onMouseEnter"),onMouseLeave:o(()=>{f.runInAction(()=>{n&&(n.state.hover=!1)})},"onMouseLeave"),onDoubleClick:o(M=>{if(!n?.diagram||!n.diagram.rules.allowEdition)return;M.stopPropagation();const C=n.diagram.canvas.inverseFit(new y(M.nativeEvent));n.createLabel(Ag(n,C))},"onDoubleClick"),children:[d.jsxs("defs",{children:[d.jsx(ic,{id:w,color:u,type:r,width:i,arrowSize:s,flip:!1}),d.jsx(ic,{id:v,color:h,type:a,width:i,arrowSize:s,flip:!1})]}),d.jsx("path",{d:_,strokeWidth:i+8,fill:"none",className:"edge-hover-area",onClickCapture:o(()=>{Mn(n,{type:"edge"})},"onClickCapture")}),d.jsx("path",{d:_,fill:"none",className:"edge-path",style:{"--edge-hover-stroke-width":`${Math.max(i+4,6)}px`,"--edge-selected-stroke-width":`${Math.max(i+2,4)}px`},stroke:e,strokeWidth:i,strokeDasharray:E,markerStart:r!=="none"?`url(#${w})`:void 0,markerEnd:a!=="none"?`url(#${v})`:void 0,onClickCapture:o(()=>{Mn(n,{type:"edge"})},"onClickCapture")}),Tn.instance.showDragHints&&t.map((M,C)=>d.jsx(Ds,{coordinates:M,size:15,stroke:$g(M)},C)),j&&d.jsx(zg,{edge:n,points:t,onMouseDown:o((M,C)=>{g?.(M,C)},"onMouseDown")}),P&&d.jsxs(d.Fragment,{children:[d.jsxs("g",{className:"edge_endpoint_drag_handle","data-edge-id":n?.id,"data-endpoint":"from",onMouseDownCapture:o(M=>{M.button===0&&(Mn(n,{type:"endpoint",endpoint:"from"}),p?.("from",M))},"onMouseDownCapture"),children:[d.jsx("circle",{cx:t[0].x,cy:t[0].y,r:12,className:"edge_endpoint_drag_hit_area"}),d.jsx("circle",{cx:t[0].x,cy:t[0].y,r:6,className:"edge_endpoint_drag_point"})]}),d.jsxs("g",{className:"edge_endpoint_drag_handle","data-edge-id":n?.id,"data-endpoint":"to",onMouseDownCapture:o(M=>{M.button===0&&(Mn(n,{type:"endpoint",endpoint:"to"}),p?.("to",M))},"onMouseDownCapture"),children:[d.jsx("circle",{cx:t.at(-1).x,cy:t.at(-1).y,r:12,className:"edge_endpoint_drag_hit_area"}),d.jsx("circle",{cx:t.at(-1).x,cy:t.at(-1).y,r:6,className:"edge_endpoint_drag_point"})]})]})]})}),Fg=he(A.observer(()=>{const n=X.use(),t=n.getExtension(ve),e=n.getExtension(we),i=t.arrowSteps;return!i.length&&!e.endpointCandidatePoint?null:d.jsxs(d.Fragment,{children:[t.candidatePoint&&d.jsx(Ds,{coordinates:t.candidatePoint,stroke:"yellow"}),e.endpointCandidatePoint&&d.jsx(Ds,{coordinates:e.endpointCandidatePoint,stroke:"yellow"}),d.jsx(An,{points:i,width:2*n.canvas.scale,arrowSize:8*n.canvas.scale,pathType:t.previewPathType})]})})),Hg=he(A.observer(()=>{const t=X.use().getExtension(Xe);return t?.enabled?d.jsx(d.Fragment,{children:d.jsx(An,{points:t.get(),startType:"measure",endType:"measure",width:2,arrowSize:12,lineStyle:"dotted",startStroke:"red",endStroke:"red",className:"measurement"})}):null})),Bg=k.forwardRef(({children:n,paths:t,transform:e,selected:i,onClick:s,className:r,roundedBorders:a=!1,label:l,labelColor:c,labelFontSize:h,labelFontFamily:u="sans-serif",labelOffset:g,"data-id":p,...m},b)=>{const x=X.use();return d.jsxs("g",{...m,"data-id":p,className:`${r||""} ${i?"selected":""} base_shape`,transform:e,onClick:s,ref:b,children:[d.jsx("defs",{children:t.map((w,v)=>{if(!w.arrow)return null;const _=6,{size:E=_,color:j=w.stroke??"#111"}=w.arrow,P=`arrow-${v}`;return d.jsx("marker",{id:P,viewBox:"0 0 10 10",refX:_*1.5,refY:"5",markerWidth:E,markerHeight:E,orient:"auto-start-reverse",markerUnits:"userSpaceOnUse",children:d.jsx("path",{d:"M 0 0 L 10 5 L 0 10",fill:"none",stroke:j,strokeWidth:Math.max(1,_*.9),strokeLinecap:"round",strokeLinejoin:"round"})},v)})}),t.map((w,v)=>{const{d:_,fill:E="none",stroke:j="#111",strokeWidth:P=3,strokeStyle:M="solid",animated:C=!1,animationDuration:G=1,nonScalingStroke:U=!0,roundedBorders:rt=a,arrow:Z}=w;let et;switch(M){case"dashed":et="10 5";break;case"dotted":et="2 6";break}const at=C?d.jsx("animate",{attributeName:"stroke-dashoffset",from:"0",to:et?`-${et.split(" ").reduce(($t,bf)=>+$t+ +bf,0)}`:"-15",dur:`${G}s`,repeatCount:"indefinite"}):null,vt=Z?`url(#arrow-${v})`:void 0;return d.jsx("path",{d:_,fill:E,stroke:j,strokeWidth:P,strokeDasharray:et,strokeLinecap:rt?"round":"butt",strokeLinejoin:rt?"round":"miter",vectorEffect:U?"non-scaling-stroke":void 0,markerStart:Z?.position==="start"||Z?.position==="both"?vt:void 0,markerEnd:!Z||Z.position==="end"||Z.position==="both"?vt:void 0,children:at},v)}),l&&d.jsx("text",{x:g?.x??0,y:g?.y??0,textAnchor:"middle",dominantBaseline:"middle",fontFamily:u,fontSize:h,fill:c,pointerEvents:"none",...x.canvas.scale>1?{shapeRendering:"geometricPrecision",style:{paintOrder:"stroke",stroke:"transparent",strokeWidth:.5,WebkitFontSmoothing:"antialiased",transform:"translateZ(0)"}}:{},children:l}),n]})}),Ie=A.observer(Bg),sc=o((n,t=0)=>{const{x:e,y:i,width:s,height:r}=n;if(t<=0)return`M${e},${i} h${s} v${r} h${-s}Z`;const a=Math.min(t,s/2,r/2);return[`M${e+a},${i}`,`h${s-2*a}`,`a${a},${a} 0 0 1 ${a},${a}`,`v${r-2*a}`,`a${a},${a} 0 0 1 ${-a},${a}`,`h${-(s-2*a)}`,`a${a},${a} 0 0 1 ${-a},${-a}`,`v${-(r-2*a)}`,`a${a},${a} 0 0 1 ${a},${-a}`,"Z"].join(" ")},"getRectPath"),Rg=o((n,t)=>`M ${n.x-t}, ${n.y}
|
|
5
5
|
a ${t},${t} 0 1,0 ${2*t},0
|
|
6
|
-
a ${t},${t} 0 1,0 -${2*t},0`,"getCirclePath"),wl=ee(A.observer(()=>{const t=q.use().getExtension(Y);return t.selectionMode?d.jsx(d.Fragment,{children:d.jsx(ge,{paths:[{d:Lr(t.box,0),strokeWidth:1}],labelOffset:new y,className:"selection_square"})}):null})),vl=tl(()=>null);function El(n){return Array.isArray(n)?n:[n]}o(El,"arrayOrArray");const $r=M.forwardRef(({children:n,className:t,style:e},s)=>d.jsx("svg",{ref:s,className:t,width:"100%",height:"100%",style:{position:"absolute",top:0,left:0,pointerEvents:"none",...e},xmlns:"http://www.w3.org/2000/svg",children:n})),_l=A.observer(()=>{const n=q.use();return n.extensions.map(t=>{const e=t.RenderDiagram;return e?d.jsx(e,{diagram:n,extension:t},t.constructor.name):null})}),Sl=A.observer(({edge:n,label:t})=>{const[e,s]=M.useState(t.size),[i,a]=M.useState({x:0,y:0}),r=M.useRef(null),c=M.useRef(null),l={"--edge-label-x":`${t.position.x}px`,"--edge-label-y":`${t.position.y}px`,"--edge-label-height":`calc(${t.size.height}px * var(--diagram-canvas-scale, 1))`,"--edge-label-text-align":t.alignment,"--edge-label-width":`calc(${t.size.width}px * var(--diagram-canvas-scale, 1))`},h=o(()=>{const m=r.current;m&&m.autopanTimer!==null&&(clearInterval(m.autopanTimer),m.autopanTimer=null)},"clearDragAutopan"),u=o(()=>{const m=r.current;if(!m?.moved||!n.diagram)return;m.autopan.displace(m.latestPointer);const b=n.diagram.canvas.inverseFit(m.latestPointer).substract(m.startMouse),w=m.startPosition.copy().sum(b),v=n.diagram.getExtension(_t)?.align(n,t,w)??w;t.setPosition(n.diagram.getExtension(Fe)?.constrain(m.startPosition,v,w)??v)},"updateDraggedLabel"),f=o(m=>{if(m.button!==0||!n.diagram)return;m.preventDefault(),m.stopPropagation(),m.nativeEvent.stopImmediatePropagation();const x=n.diagram,b=x.getExtension(_t),w=new ut(x),v=new y(m.nativeEvent),_=x.canvas.inverseFit(v),E=t.position.copy();let C=v,k=!1,P=null;const I=o(()=>{if(!k)return;w.displace(C);const nt=x.canvas.inverseFit(C).substract(_),ot=E.copy().sum(nt),vt=b?.align(n,t,ot)??ot;t.setPosition(x.getExtension(Fe)?.constrain(E,vt,ot)??vt)},"update"),B=o(nt=>{C=new y(nt),!(!k&&C.copy().substract(v).norm<5)&&(k=!0,P===null&&(P=setInterval(I,30)),I())},"move"),X=o(()=>{P!==null&&clearInterval(P),document.removeEventListener("pointermove",B),document.removeEventListener("pointerup",wt),document.removeEventListener("pointercancel",rt),b?.clear()},"cleanup"),wt=o(()=>{X(),k&&t.commitPosition()},"finish"),rt=o(()=>{X(),t.setPosition(E)},"cancel");b?.clear(),document.addEventListener("pointermove",B,{passive:!1}),document.addEventListener("pointerup",wt,{once:!0}),document.addEventListener("pointercancel",rt,{once:!0})},"startEditingDrag"),p=o((m,x)=>{const b=m.currentTarget.parentElement;if(!b||!n.diagram)return;m.preventDefault(),m.stopPropagation(),m.nativeEvent.stopImmediatePropagation();const w=b.getBoundingClientRect(),v=Math.max(n.diagram.canvas.scale,.001);c.current={direction:x,height:w.height/v,mouseX:m.clientX,mouseY:m.clientY,offset:{x:0,y:0},position:t.position.copy(),size:e,width:w.width/v};const _=o(C=>{const k=c.current;if(!k)return;C.preventDefault();const P=Math.max(n.diagram.canvas.scale,.001),I=(C.clientX-k.mouseX)/P,B=(C.clientY-k.mouseY)/P,X=k.direction.includes("w"),wt=k.direction.includes("n"),rt=k.direction.includes("e"),nt=k.direction.includes("s"),ot=Math.max(0,k.width+(rt?I:X?-I:0)),vt=Math.max(0,k.height+(nt?B:wt?-B:0));s({height:vt,width:ot}),k.size={height:vt,width:ot},k.offset={x:X?k.width-ot:0,y:wt?k.height-vt:0},a(k.offset)},"move"),E=o(()=>{const C=c.current;if(c.current=null,document.removeEventListener("pointermove",_),document.removeEventListener("pointerup",E),!C||!n.diagram)return;let k=!1;(C.size.width!==t.size.width||C.size.height!==t.size.height)&&(t.setSize(C.size),k=!0);const P=C.offset;(P.x||P.y)&&(t.setPosition(C.position.copy().sum([P.x,P.y])),k=!0,a({x:0,y:0})),k&&t.commitPosition(),n.diagram.getExtension(_t)?.clear()},"finish");document.addEventListener("pointermove",_,{passive:!1}),document.addEventListener("pointerup",E,{once:!0})},"startResize");if(t.isEditing){const m={...l,"--edge-label-editor-height":`calc(${e.height}px * var(--diagram-canvas-scale, 1))`,"--edge-label-editor-offset-x":`calc(${i.x}px * var(--diagram-canvas-scale, 1))`,"--edge-label-editor-offset-y":`calc(${i.y}px * var(--diagram-canvas-scale, 1))`,"--edge-label-editor-width":`calc(${e.width}px * var(--diagram-canvas-scale, 1))`};return d.jsxs("div",{className:"edge-label-editor","data-edge-id":n.id,"data-edge-label-id":t.id,onPointerDown:o(x=>x.stopPropagation(),"onPointerDown"),style:m,children:[d.jsx("textarea",{"aria-label":"Edge label",autoFocus:!0,className:"edge-screen-label edge-screen-label--editing",onBlur:o(()=>t.confirmEdit(),"onBlur"),onChange:o(x=>t.setDraft(x.target.value),"onChange"),onClick:o(x=>x.stopPropagation(),"onClick"),onDoubleClick:o(x=>x.stopPropagation(),"onDoubleClick"),onPointerDown:o(x=>x.stopPropagation(),"onPointerDown"),onKeyDown:o(x=>{if(x.key==="Enter"){if(x.shiftKey){x.stopPropagation();return}x.preventDefault(),t.confirmEdit()}else x.key==="Escape"&&(x.preventDefault(),t.cancelEdit());x.stopPropagation()},"onKeyDown"),cols:30,rows:2,value:t.draft}),["n","ne","e","se","s","sw","w","nw"].map(x=>d.jsx("span",{"aria-hidden":"true",className:`edge-label-editor__resize-handle edge-label-editor__resize-handle--${x}`,onPointerDown:o(b=>p(b,x),"onPointerDown")},x)),d.jsxs("div",{className:"edge-label-editor__toolbar",children:[d.jsx("button",{"aria-label":"Move label",onPointerDown:f,title:"Move label",type:"button",children:d.jsx(Ko,{})}),d.jsx("button",{"aria-label":"Align left","aria-pressed":t.alignment==="left",className:t.alignment==="left"?"selected":"",onMouseDown:o(x=>{x.preventDefault(),x.stopPropagation()},"onMouseDown"),onClick:o(()=>t.setAlignment("left"),"onClick"),title:"Align left",type:"button",children:d.jsx($o,{})}),d.jsx("button",{"aria-label":"Align center","aria-pressed":t.alignment==="center",className:t.alignment==="center"?"selected":"",onMouseDown:o(x=>{x.preventDefault(),x.stopPropagation()},"onMouseDown"),onClick:o(()=>t.setAlignment("center"),"onClick"),title:"Align center",type:"button",children:d.jsx(zo,{})}),d.jsx("button",{"aria-label":"Align right","aria-pressed":t.alignment==="right",className:t.alignment==="right"?"selected":"",onMouseDown:o(x=>{x.preventDefault(),x.stopPropagation()},"onMouseDown"),onClick:o(()=>t.setAlignment("right"),"onClick"),title:"Align right",type:"button",children:d.jsx(Lo,{})}),d.jsx("button",{"aria-label":"Delete label",onMouseDown:o(x=>{x.preventDefault(),x.stopPropagation()},"onMouseDown"),onClick:o(()=>t.delete(),"onClick"),title:"Delete label",type:"button",children:d.jsx(rr,{})})]})]})}return d.jsx("span",{className:"edge-screen-label","data-edge-id":n.id,"data-edge-label-id":t.id,style:l,onPointerDown:o(m=>{m.button!==0||!n.diagram||(m.preventDefault(),m.stopPropagation(),m.currentTarget.setPointerCapture(m.pointerId),r.current={autopan:new ut(n.diagram),autopanTimer:null,latestPointer:new y(m.nativeEvent),pointerId:m.pointerId,startMouse:n.diagram.canvas.inverseFit(new y(m.nativeEvent)),startMouseScreen:new y(m.nativeEvent),startPosition:t.position.copy(),moved:!1},n.diagram?.getExtension(_t)?.clear())},"onPointerDown"),onPointerMove:o(m=>{const x=r.current;!x||x.pointerId!==m.pointerId||!n.diagram||(x.latestPointer=new y(m.nativeEvent),x.latestPointer.copy().substract(x.startMouseScreen).norm<5&&!x.moved)||(x.moved=!0,x.autopanTimer===null&&(x.autopanTimer=setInterval(u,30)),u())},"onPointerMove"),onPointerUp:o(m=>{const x=r.current;!x||x.pointerId!==m.pointerId||(m.stopPropagation(),h(),m.currentTarget.hasPointerCapture(m.pointerId)&&m.currentTarget.releasePointerCapture(m.pointerId),x.moved&&t.position.copy(!1).substract(x.startPosition).norm>.001&&t.commitPosition(),x.moved||t.beginEdit(),n.diagram?.getExtension(_t)?.clear(),r.current=null)},"onPointerUp"),onPointerCancel:o(m=>{const x=r.current;!x||x.pointerId!==m.pointerId||(h(),t.setPosition(x.startPosition),n.diagram?.getExtension(_t)?.clear(),r.current=null)},"onPointerCancel"),children:t.text})}),Ml=A.observer(({edge:n})=>n.labels.map(t=>d.jsx(Sl,{edge:n,label:t},t.id))),kl=A.observer(({node:n})=>{const t=n.RenderScreen;return t?d.jsx(t,{node:n,box:n.box,scale:n.diagram?.canvas.scale??1}):null}),Al=A.observer(()=>{const n=q.use();return d.jsxs("div",{className:"screen_renderers",children:[n.nodes.map(t=>d.jsx(kl,{node:t},t.id)),n.edges.map(t=>d.jsx(Ml,{edge:t},t.id)),d.jsx(_l,{})]})}),Pl=A.observer(({gateway:n})=>{const e=q.use().getExtension(le);return d.jsx(ge,{paths:[{d:bl(n.coordinates,n.radius),fill:n.fill,stroke:n.stroke,strokeWidth:n.strokeWidth}],className:"diagram__node__gateway","data-gateway-parent":n.parent.id,"data-gateway-id":n.id,"data-gateway-orientation":n.orientation,style:{pointerEvents:e.endpointDragActive?"none":void 0},onMouseEnter:o(()=>n.parent.setHovered(!0),"onMouseEnter"),onMouseOut:o(s=>{const i=s.relatedTarget;i instanceof Element&&i.closest(`[data-id="${n.parent.id}"], [data-gateway-parent="${n.parent.id}"]`)||n.parent.setState("hover",!1)},"onMouseOut")},n.id)}),Cl=A.observer(({node:n})=>{const e=q.use().getExtension(le);return d.jsx("path",{className:"diagram__node__edge_gateway",d:n.connectionBoundaryPath,"data-gateway-parent":n.id,fill:"none",stroke:"transparent",strokeWidth:16,vectorEffect:"non-scaling-stroke",style:{pointerEvents:e.endpointDragActive?"none":"stroke"},onMouseEnter:o(()=>n.setState("hover",!0),"onMouseEnter"),onMouseOut:o(s=>{const i=s.relatedTarget;i instanceof Element&&i.closest(`[data-id="${n.id}"], [data-gateway-parent="${n.id}"]`)||n.setState("hover",!1)},"onMouseOut")})}),Il=A.observer(({node:n})=>{const t=n.RenderOverlay;return t?d.jsx(t,{node:n,box:n.box}):null}),Dl=A.observer(()=>{const n=q.use();return d.jsx("div",{style:{width:`${n.canvas.size.x}px`,height:`${n.canvas.size.y}px`},children:n.nodes.map(t=>d.jsx(Il,{node:t},t.id))})}),jl=A.observer(({node:n})=>n.parent?d.jsx(d.Fragment,{children:!n.RenderOverlay&&d.jsx(ge,{paths:[{d:Lr(n.box,10),stroke:n.state.stroke,strokeWidth:n.state.strokewWidth??3,fill:n.state.fill}],onMouseOver:o(()=>n.setHovered(!0),"onMouseOver"),onMouseOut:o(t=>{const e=t.relatedTarget;e instanceof Element&&e.closest(`[data-id="${n.id}"], [data-gateway-parent="${n.id}"]`)||n.setHovered(!1)},"onMouseOut"),className:n.classList.string,label:n.state.label,labelOffset:n.coordinates.sum(n.box.size.half),labelFontSize:n.state.labelFontSize??14,selected:n.selected,"data-id":n.id},n.id)}):null),zr=A.observer(({edge:n,showDragHandles:t})=>d.jsx(qe,{edge:n,points:n.steps,endType:n.arrowHeadEnd??"arrow",startType:n.arrowHeadStart??"none",lineStyle:n.lineStyle??"solid",arrowSize:n.state.arrowSize,color:n.stroke,width:n.strokeWidth??2,draggable:t,onMidpointMouseDown:o((e,s)=>{n.dragStart(e,s)},"onMidpointMouseDown"),onEndpointMouseDown:o((e,s)=>{n.dragEndpoint(e,s)},"onEndpointMouseDown")})),Nl=ee(A.observer(()=>{const n=q.use(),t=n.getExtension(Y),e=t?.selectedNodes??[],s=t?.selectedEdges??[],i=e.length+s.length>1,a=[...n.nodes.filter(c=>!e.includes(c)),...e],r=i?[]:a.filter(c=>c.hovered||c.selected).flatMap(c=>c.gateways);return d.jsxs(d.Fragment,{children:[a.map(c=>d.jsx(jl,{node:c},c.id)),a.filter(c=>c.edgesAsGateways).map(c=>d.jsx(Cl,{node:c},`edge-gateway-${c.id}`)),n.edges.filter(c=>!s.includes(c)).map(c=>d.jsx(zr,{edge:c,showDragHandles:!i},c.id)),r.map(c=>d.jsx(Pl,{gateway:c},`${c.parent.id}-${c.id}`)),s.map(c=>d.jsx(zr,{edge:c,showDragHandles:!i},`selected-${c.id}`))]})}));function Tl(){return[d.jsx(Nl,{},"ScalableShapes"),d.jsx(Dl,{},"RenderNodeOverlays")]}o(Tl,"shapes");function Ll(n){if(!(n instanceof Element))return null;const t=n.closest("[data-gateway-parent]");return t?t.getAttribute("data-gateway-parent"):n.closest("[data-id]")?.getAttribute("data-id")??null}o(Ll,"hoverOwnerId");const $l=A.observer(({children:n})=>{const t=q.use(),e=t.getExtension(G);t.canvas.setGridSize(e?.gridSize??50);const s=[],i=[],a=[];return M.Children.forEach([...El(n),...Tl()],r=>{r.type.__scalable?s.push(r):r.type.__scalableBack?a.push(r):i.push(r)}),d.jsxs("div",{className:`canvas__frame ${t.showGrid?"canvas__frame--grid":""}`,onPointerLeave:o(()=>t.clearNodeHover(),"onPointerLeave"),onPointerMove:o(r=>{const c=t.getNodeById(Ll(r.target)??"");c?c.setHovered(!0):t.clearNodeHover()},"onPointerMove"),children:[d.jsxs("div",{ref:t.canvas.useRef,children:[a.length&&d.jsx($r,{className:"background",children:a}),i.length&&d.jsx("div",{className:"scalable_components",children:i}),s.length&&d.jsx($r,{className:"foreground",children:s})]}),d.jsx(Al,{})]})});function zl({children:n,className:t,...e}){return d.jsx("div",{...e,className:["stage",t].filter(Boolean).join(" "),children:n})}o(zl,"Stage");const Ol=ee(A.observer(()=>{const n=q.use(),t=n.getExtension(Zt),e=n.getExtension(_t),s=n.getExtension(Ce),i=[...t?.proposals??[],...n.extensions.flatMap(a=>a.alignmentProposals??[])];return d.jsxs(d.Fragment,{children:[i.map(a=>{const r=a.type==="h"?`M ${a.x} ${a.range[0]} V ${a.range[1]}`:`M ${a.range[0]} ${a.y} H ${a.range[1]}`;return d.jsx(ge,{className:"alignment_sugestion",paths:[{d:r}]},a.id)}),e?.proposals.map(a=>d.jsx(ge,{className:"alignment_sugestion",paths:[{d:`M ${a.from.x} ${a.from.y} L ${a.to.x} ${a.to.y}`}]},a.id)),s?.proposals.map(a=>{const r=`M ${a.from.x} ${a.from.y} L ${a.to.x} ${a.to.y}`;return d.jsx(ge,{className:"distance_balance_sugestion",paths:[{d:r,arrow:{position:"both",size:8}}]},r)})]})})),Fl=ee(A.observer(()=>{const t=q.use().getExtension(Ja);return t?.enabled?d.jsxs(d.Fragment,{children:[t.grid?.edges.map(e=>{const{from:s,to:i}=e,a=`M ${s.x} ${s.y} L ${i.x} ${i.y}`,r=t.highlighted.has(e);return d.jsx(qe,{className:`path_finding_grid_edge ${r?"highlighted":""}`,points:[s,i],endType:"none"},a)}),t.points?.length&&d.jsx(qe,{className:"path_finding_grid_edge_chosen",points:t.points})]}):null})),bt=8,Dn=2,Hl=120;function Bl(n,t){const e=Math.max(bt,Math.min(n.x,window.innerWidth-t.width-bt)),s=Math.max(bt,Math.min(n.y,window.innerHeight-t.height-bt));return{x:e,y:s}}o(Bl,"clampPosition");function Gl({item:n,onAction:t}){const e=!!n.submenu?.length,s=M.useRef(null),i=M.useRef(null),a=M.useRef(null),[r,c]=M.useState(!1),[l,h]=M.useState(!1),[u,f]=M.useState({left:0,top:-4,openToLeft:!1}),p=M.useCallback(()=>{if(!s.current||!i.current)return;const _=s.current.getBoundingClientRect(),E=i.current.getBoundingClientRect();let C=_.width-Dn,k=!1;_.right-Dn+E.width>window.innerWidth-bt&&(C=-E.width+Dn,k=!0),_.left+C<bt&&(C=bt-_.left,k=!1);let P=-4,I=_.top+P;I+E.height>window.innerHeight-bt&&(P-=I+E.height-(window.innerHeight-bt),I=_.top+P),I<bt&&(P+=bt-I),f({left:C,top:P,openToLeft:k}),h(!0)},[]);M.useEffect(()=>{r||h(!1)},[r]),M.useEffect(()=>()=>{a.current!==null&&window.clearTimeout(a.current)},[]),M.useLayoutEffect(()=>{r&&p()},[r,p]),M.useEffect(()=>{if(!r)return;const _=o(()=>{p()},"handleResize");return window.addEventListener("resize",_),()=>{window.removeEventListener("resize",_)}},[r,p]);const m=o(()=>{a.current!==null&&(window.clearTimeout(a.current),a.current=null)},"clearCloseTimeout"),x=o(()=>{e&&(m(),c(!0))},"openSubmenu"),b=o(()=>{m(),c(!1)},"closeSubmenu"),w=o(()=>{e&&(m(),a.current=window.setTimeout(()=>{c(!1),a.current=null},Hl))},"scheduleCloseSubmenu"),v=o(_=>{const E=_.relatedTarget;(!E||!_.currentTarget.contains(E))&&b()},"handleBlur");return d.jsxs("li",{ref:s,className:["diagram__context_menu_item",n.disabled&&"disabled",n.danger&&"danger",e&&"has_submenu",r&&"submenu_open"].filter(Boolean).join(" "),onMouseEnter:x,onMouseLeave:w,onFocusCapture:x,onBlurCapture:v,children:[d.jsxs("button",{type:"button",className:"diagram__context_menu_button",disabled:n.disabled,onClick:o(_=>{_.stopPropagation(),_.preventDefault(),t(n)},"onClick"),children:[d.jsx("span",{className:"diagram__context_menu_label",children:n.label}),e&&d.jsx("span",{className:"diagram__context_menu_chevron",children:u.openToLeft?"<":">"})]}),e&&r&&d.jsx("div",{ref:i,className:"diagram__context_menu_submenu",style:{left:u.left,top:u.top,opacity:l?1:0},children:d.jsx("div",{className:"diagram__context_menu diagram__context_menu--nested",children:d.jsx(Or,{items:n.submenu,onAction:t})})})]})}o(Gl,"MenuItem");function Or({items:n,onAction:t}){return d.jsx("ul",{className:"diagram__context_menu_list",children:n.map((e,s)=>d.jsx(Gl,{item:e,onAction:t},`${e.label}_${s}`))})}o(Or,"MenuItems");const Rl=A.observer(({menu:n})=>{const t=M.useRef(null),[e,s]=M.useState(n.position);return M.useEffect(()=>{n.opened&&s(n.position)},[n.openVersion,n.opened,n.position]),M.useLayoutEffect(()=>{if(!n.opened||!t.current)return;const{width:i,height:a}=t.current.getBoundingClientRect(),{x:r,y:c}=Bl(n.position,{width:i,height:a});(r!==e.x||c!==e.y)&&s({x:r,y:c})},[n.openVersion,n.opened,n.position,e.x,e.y]),M.useEffect(()=>{if(!n.opened)return;const i=o(l=>{l.code==="Escape"&&n.close()},"closeOnEscape"),a=o(l=>{const h=l.target;h&&t.current?.contains(h)||n.close()},"closeOnOutsideMouseDown"),r=o(l=>{const h=l.target;if(h&&t.current?.contains(h)){l.preventDefault();return}n.close()},"closeOnOutsideContextMenu"),c=o(()=>{n.close()},"closeOnResize");return document.addEventListener("keydown",i),document.addEventListener("mousedown",a,!0),document.addEventListener("contextmenu",r,!0),window.addEventListener("resize",c),()=>{document.removeEventListener("keydown",i),document.removeEventListener("mousedown",a,!0),document.removeEventListener("contextmenu",r,!0),window.removeEventListener("resize",c)}},[n,n.openVersion,n.opened]),!n.opened||!n.elements.length?null:d.jsx("div",{className:"diagram__context_menu_layer",children:d.jsx("div",{ref:t,className:"diagram__context_menu",style:{left:e.x,top:e.y},onMouseDown:o(i=>{i.stopPropagation()},"onMouseDown"),onContextMenu:o(i=>{i.preventDefault(),i.stopPropagation()},"onContextMenu"),children:d.jsx(Or,{items:n.elements,onAction:o(i=>{n.execute(i)},"onAction")})})})}),Aa=class Aa{_elements=[];_opened=!1;_position={x:0,y:0};_openVersion=0;Component=o(()=>d.jsx(Rl,{menu:this}),"Component");constructor(){g.makeAutoObservable(this,{Component:!1},{autoBind:!0})}get elements(){return this._elements}get opened(){return this._opened}get position(){return this._position}get openVersion(){return this._openVersion}open(t,e={}){if(!t.length){this.close();return}const s=ae.getInstance().coordinates;this._elements=t,this._position={x:e.x??s.x,y:e.y??s.y},this._openVersion+=1,this._opened=!0}close(){this._opened&&(this._opened=!1,this._elements=[])}execute(t){if(!t.disabled){try{const e=t.onClick();e instanceof Promise&&e.catch(()=>{})}catch{}t.submenu?.length||this.close()}}};o(Aa,"ContextMenuStore");let jn=Aa;const Nn=new jn,Ue=o(()=>{},"noop");function Vl(){return typeof navigator<"u"&&!!navigator.clipboard?.writeText&&!!navigator.clipboard?.readText}o(Vl,"hasClipboardSupport");function Fr(n){return()=>{n().catch(()=>{})}}o(Fr,"runAsync");function Yl(n,t,e){const s=n.getExtension(Y),i=t.closest(".diagram__node")?.dataset.id,a=t.closest(".edge")?.dataset.id,r=i?n.getNodeById(i):void 0,c=a?n.getEdgeById(a):void 0;r&&!r.selected?(s.clearSelection(),s.selectNode(r)):c&&!c.state.selected&&(s.clearSelection(),s.selectEdge(c));const l=s.selectedNodes,h=s.selectedEdges,u=l.length+h.length>0,f=Vl(),p=f&&l.length>0,m=o(()=>{s.selectedNodes.forEach(w=>{n.delete(w)}),s.selectedEdges.forEach(w=>{n.disconnect(w)})},"deleteSelection"),x=[];r?x.push({label:`Node: ${r.state.label||r.id}`,onClick:Ue,submenu:[{label:"Center node",onClick:o(()=>{n.canvas.centerOnPoint(r.box.middle)},"onClick")},{label:"Delete node",onClick:o(()=>{n.delete(r)},"onClick"),danger:!0}]}):c&&x.push({label:"Edge",onClick:Ue,submenu:[{label:"Delete edge",onClick:o(()=>{n.disconnect(c)},"onClick"),danger:!0}]}),u&&x.push({label:"Delete selection",onClick:m,danger:!0}),x.push({label:"Selection",onClick:Ue,submenu:[{label:s.selectionMode==="element"?"Element mode (active)":"Element mode",onClick:o(()=>{s.toggleSelectionMode("element")},"onClick")},{label:s.selectionMode==="area"?"Area mode (active)":"Area mode",onClick:o(()=>{s.toggleSelectionMode("area")},"onClick")},{label:"Clear selection",onClick:o(()=>{s.clearSelection()},"onClick"),disabled:!u},{label:"Copy selection",onClick:Fr(async()=>{await navigator.clipboard.writeText(s.copy())}),disabled:!p},{label:"Paste",onClick:Fr(async()=>{const w=await navigator.clipboard.readText();w.trim().length&&n.paste(w)}),disabled:!f}]});const b=new y([e.x,e.y]);return x.push({label:"View",onClick:Ue,submenu:[{label:n.showGrid?"Hide grid":"Show grid",onClick:o(()=>{n.toggleGrid()},"onClick")},{label:`Zoom (${Math.round(n.canvas.scale*100)}%)`,onClick:Ue,submenu:[{label:"Zoom in",onClick:o(()=>{n.canvas.setScale(n.canvas.scale+.1,b)},"onClick")},{label:"Zoom out",onClick:o(()=>{n.canvas.setScale(n.canvas.scale-.1,b)},"onClick")},{label:"Reset zoom",onClick:o(()=>{n.canvas.setScale(1,b)},"onClick")}]}]}),x}o(Yl,"buildDiagramContextMenu");const Wl=A.observer(()=>{const n=q.use();return d.jsx("div",{className:"diagram__extension_ui",children:n.extensions.map(t=>{const e=t.RenderUI;return e?d.jsx(e,{diagram:n,extension:t},t.constructor.name):null})})}),Zl=A.observer(({diagram:n,leftPanel:t,toolbar:e})=>{const s=o(i=>{const a=i.target;if(a instanceof HTMLElement){if(a.closest('input, textarea, [contenteditable="true"]')){Nn.close();return}i.preventDefault(),Nn.open(Yl(n,a,{x:i.clientX,y:i.clientY}),{x:i.clientX,y:i.clientY})}},"handleContextMenu");return d.jsxs(n.Context,{children:[d.jsxs(zl,{onContextMenu:s,children:[t,d.jsxs($l,{children:[d.jsx(vl,{}),d.jsx(ml,{}),d.jsx(yl,{}),d.jsx(Ol,{}),d.jsx(wl,{}),d.jsx(Fl,{})]}),d.jsx(Wl,{})]}),d.jsx(Nn.Component,{}),e]})}),Pa=class Pa extends y{direction="left";get rawDirectedPoint(){return{x:this.x,y:this.y,direction:this.direction}}stepBack(){switch(this.direction){case"down":this.y--;break;case"left":this.x++;break;case"right":this.x--;break;case"up":this.y++;break}return this}stepForward(){switch(this.direction){case"down":this.y++;break;case"left":this.x--;break;case"right":this.x++;break;case"up":this.y--;break}return this}};o(Pa,"DirectedPoint");let Tn=Pa;const Xl=Object.freeze(Object.defineProperty({__proto__:null,DirectedPoint:Tn},Symbol.toStringTag,{value:"Module"}));F.AgentDiagram=yn,F.BPMDiagram=An,F.BPMN_LABELS=ft,F.CommunicationDiagram=Pn,F.Diagram=q,F.DiagramEditor=Zl,F.ToolsStates=es,F.configureBPMNLabels=bn,Object.defineProperty(F,Symbol.toStringTag,{value:"Module"})}));
|
|
6
|
+
a ${t},${t} 0 1,0 -${2*t},0`,"getCirclePath"),Gg=he(A.observer(()=>{const t=X.use().getExtension(B);return t.selectionMode?d.jsx(d.Fragment,{children:d.jsx(Ie,{paths:[{d:sc(t.box,0),strokeWidth:1}],labelOffset:new y,className:"selection_square"})}):null})),Vg=Eg(()=>null);function Wg(n){return Array.isArray(n)?n:[n]}o(Wg,"arrayOrArray");const rc=k.forwardRef(({children:n,className:t,style:e},i)=>d.jsx("svg",{ref:i,className:t,width:"100%",height:"100%",style:{position:"absolute",top:0,left:0,pointerEvents:"none",...e},xmlns:"http://www.w3.org/2000/svg",children:n})),Yg=A.observer(()=>{const n=X.use();return n.extensions.map(t=>{const e=t.RenderDiagram;return e?d.jsx(e,{diagram:n,extension:t},t.constructor.name):null})}),Zg=A.observer(({edge:n,label:t})=>{const[e,i]=k.useState(t.size),[s,r]=k.useState({x:0,y:0}),a=k.useRef(null),l=k.useRef(null),c={"--edge-label-x":`${t.position.x}px`,"--edge-label-y":`${t.position.y}px`,"--edge-label-height":`calc(${t.size.height}px * var(--diagram-canvas-scale, 1))`,"--edge-label-text-align":t.alignment,"--edge-label-width":`calc(${t.size.width}px * var(--diagram-canvas-scale, 1))`};if(!(n.diagram?.rules.allowEdition!==!1))return d.jsx("span",{className:"edge-screen-label","data-edge-id":n.id,"data-edge-label-id":t.id,style:c,children:t.text});const u=o(()=>{const b=a.current;b&&b.autopanTimer!==null&&(clearInterval(b.autopanTimer),b.autopanTimer=null)},"clearDragAutopan"),g=o(()=>{const b=a.current;if(!b?.moved||!n.diagram)return;b.autopan.displace(b.latestPointer);const w=n.diagram.canvas.inverseFit(b.latestPointer).substract(b.startMouse),v=b.startPosition.copy().sum(w),_=n.diagram.getExtension(Tt)?.align(n,t,v)??v;t.setPosition(n.diagram.getExtension(an)?.constrain(b.startPosition,_,v)??_)},"updateDraggedLabel"),p=o(b=>{if(b.button!==0||!n.diagram)return;b.preventDefault(),b.stopPropagation(),b.nativeEvent.stopImmediatePropagation();const x=n.diagram,w=x.getExtension(Tt),v=new kt(x),_=new y(b.nativeEvent),E=x.canvas.inverseFit(_),j=t.position.copy();let P=_,M=!1,C=null;const G=o(()=>{if(!M)return;v.displace(P);const at=x.canvas.inverseFit(P).substract(E),vt=j.copy().sum(at),$t=w?.align(n,t,vt)??vt;t.setPosition(x.getExtension(an)?.constrain(j,$t,vt)??$t)},"update"),U=o(at=>{P=new y(at),!(!M&&P.copy().substract(_).norm<5)&&(M=!0,C===null&&(C=setInterval(G,30)),G())},"move"),rt=o(()=>{C!==null&&clearInterval(C),document.removeEventListener("pointermove",U),document.removeEventListener("pointerup",Z),document.removeEventListener("pointercancel",et),w?.clear()},"cleanup"),Z=o(()=>{rt(),M&&t.commitPosition()},"finish"),et=o(()=>{rt(),t.setPosition(j)},"cancel");w?.clear(),document.addEventListener("pointermove",U,{passive:!1}),document.addEventListener("pointerup",Z,{once:!0}),document.addEventListener("pointercancel",et,{once:!0})},"startEditingDrag"),m=o((b,x)=>{const w=b.currentTarget.parentElement;if(!w||!n.diagram)return;b.preventDefault(),b.stopPropagation(),b.nativeEvent.stopImmediatePropagation();const v=w.getBoundingClientRect(),_=Math.max(n.diagram.canvas.scale,.001);l.current={direction:x,height:v.height/_,mouseX:b.clientX,mouseY:b.clientY,offset:{x:0,y:0},position:t.position.copy(),size:e,width:v.width/_};const E=o(P=>{const M=l.current;if(!M)return;P.preventDefault();const C=Math.max(n.diagram.canvas.scale,.001),G=(P.clientX-M.mouseX)/C,U=(P.clientY-M.mouseY)/C,rt=M.direction.includes("w"),Z=M.direction.includes("n"),et=M.direction.includes("e"),at=M.direction.includes("s"),vt=Math.max(0,M.width+(et?G:rt?-G:0)),$t=Math.max(0,M.height+(at?U:Z?-U:0));i({height:$t,width:vt}),M.size={height:$t,width:vt},M.offset={x:rt?M.width-vt:0,y:Z?M.height-$t:0},r(M.offset)},"move"),j=o(()=>{const P=l.current;if(l.current=null,document.removeEventListener("pointermove",E),document.removeEventListener("pointerup",j),!P||!n.diagram)return;let M=!1;(P.size.width!==t.size.width||P.size.height!==t.size.height)&&(t.setSize(P.size),M=!0);const C=P.offset;(C.x||C.y)&&(t.setPosition(P.position.copy().sum([C.x,C.y])),M=!0,r({x:0,y:0})),M&&t.commitPosition(),n.diagram.getExtension(Tt)?.clear()},"finish");document.addEventListener("pointermove",E,{passive:!1}),document.addEventListener("pointerup",j,{once:!0})},"startResize");if(t.isEditing){const b={...c,"--edge-label-editor-height":`calc(${e.height}px * var(--diagram-canvas-scale, 1))`,"--edge-label-editor-offset-x":`calc(${s.x}px * var(--diagram-canvas-scale, 1))`,"--edge-label-editor-offset-y":`calc(${s.y}px * var(--diagram-canvas-scale, 1))`,"--edge-label-editor-width":`calc(${e.width}px * var(--diagram-canvas-scale, 1))`};return d.jsxs("div",{className:"edge-label-editor","data-edge-id":n.id,"data-edge-label-id":t.id,onPointerDown:o(x=>x.stopPropagation(),"onPointerDown"),style:b,children:[d.jsx("textarea",{"aria-label":"Edge label",autoFocus:!0,className:"edge-screen-label edge-screen-label--editing",onBlur:o(()=>t.confirmEdit(),"onBlur"),onChange:o(x=>t.setDraft(x.target.value),"onChange"),onClick:o(x=>x.stopPropagation(),"onClick"),onDoubleClick:o(x=>x.stopPropagation(),"onDoubleClick"),onPointerDown:o(x=>x.stopPropagation(),"onPointerDown"),onKeyDown:o(x=>{if(x.key==="Enter"){if(x.shiftKey){x.stopPropagation();return}x.preventDefault(),t.confirmEdit()}else x.key==="Escape"&&(x.preventDefault(),t.cancelEdit());x.stopPropagation()},"onKeyDown"),cols:30,rows:2,value:t.draft}),["n","ne","e","se","s","sw","w","nw"].map(x=>d.jsx("span",{"aria-hidden":"true",className:`edge-label-editor__resize-handle edge-label-editor__resize-handle--${x}`,onPointerDown:o(w=>m(w,x),"onPointerDown")},x)),d.jsxs("div",{className:"edge-label-editor__toolbar",children:[d.jsx("button",{"aria-label":"Move label",onPointerDown:p,title:"Move label",type:"button",children:d.jsx(bd,{})}),d.jsx("button",{"aria-label":"Align left","aria-pressed":t.alignment==="left",className:t.alignment==="left"?"selected":"",onMouseDown:o(x=>{x.preventDefault(),x.stopPropagation()},"onMouseDown"),onClick:o(()=>t.setAlignment("left"),"onClick"),title:"Align left",type:"button",children:d.jsx(sd,{})}),d.jsx("button",{"aria-label":"Align center","aria-pressed":t.alignment==="center",className:t.alignment==="center"?"selected":"",onMouseDown:o(x=>{x.preventDefault(),x.stopPropagation()},"onMouseDown"),onClick:o(()=>t.setAlignment("center"),"onClick"),title:"Align center",type:"button",children:d.jsx(rd,{})}),d.jsx("button",{"aria-label":"Align right","aria-pressed":t.alignment==="right",className:t.alignment==="right"?"selected":"",onMouseDown:o(x=>{x.preventDefault(),x.stopPropagation()},"onMouseDown"),onClick:o(()=>t.setAlignment("right"),"onClick"),title:"Align right",type:"button",children:d.jsx(id,{})}),d.jsx("button",{"aria-label":"Delete label",onMouseDown:o(x=>{x.preventDefault(),x.stopPropagation()},"onMouseDown"),onClick:o(()=>t.delete(),"onClick"),title:"Delete label",type:"button",children:d.jsx(Po,{})})]})]})}return d.jsx("span",{className:"edge-screen-label","data-edge-id":n.id,"data-edge-label-id":t.id,style:c,onPointerDown:o(b=>{b.button!==0||!n.diagram||(b.preventDefault(),b.stopPropagation(),b.currentTarget.setPointerCapture(b.pointerId),a.current={autopan:new kt(n.diagram),autopanTimer:null,latestPointer:new y(b.nativeEvent),pointerId:b.pointerId,startMouse:n.diagram.canvas.inverseFit(new y(b.nativeEvent)),startMouseScreen:new y(b.nativeEvent),startPosition:t.position.copy(),moved:!1},n.diagram?.getExtension(Tt)?.clear())},"onPointerDown"),onPointerMove:o(b=>{const x=a.current;!x||x.pointerId!==b.pointerId||!n.diagram||(x.latestPointer=new y(b.nativeEvent),x.latestPointer.copy().substract(x.startMouseScreen).norm<5&&!x.moved)||(x.moved=!0,x.autopanTimer===null&&(x.autopanTimer=setInterval(g,30)),g())},"onPointerMove"),onPointerUp:o(b=>{const x=a.current;!x||x.pointerId!==b.pointerId||(b.stopPropagation(),u(),b.currentTarget.hasPointerCapture(b.pointerId)&&b.currentTarget.releasePointerCapture(b.pointerId),x.moved&&t.position.copy(!1).substract(x.startPosition).norm>.001&&t.commitPosition(),x.moved||t.beginEdit(),n.diagram?.getExtension(Tt)?.clear(),a.current=null)},"onPointerUp"),onPointerCancel:o(b=>{const x=a.current;!x||x.pointerId!==b.pointerId||(u(),t.setPosition(x.startPosition),n.diagram?.getExtension(Tt)?.clear(),a.current=null)},"onPointerCancel"),children:t.text})}),Kg=A.observer(({edge:n})=>n.labels.map(t=>d.jsx(Zg,{edge:n,label:t},t.id))),Ug=A.observer(({node:n})=>{const t=n.RenderScreen;return t?d.jsx(t,{node:n,box:n.box,scale:n.diagram?.canvas.scale??1}):null}),Xg=A.observer(()=>{const n=X.use();return d.jsxs("div",{className:"screen_renderers",children:[n.nodes.map(t=>d.jsx(Ug,{node:t},t.id)),n.edges.map(t=>d.jsx(Kg,{edge:t},t.id)),d.jsx(Yg,{})]})}),qg=A.observer(({gateway:n})=>{const e=X.use().getExtension(we);return d.jsx(Ie,{paths:[{d:Rg(n.coordinates,n.radius),fill:n.fill,stroke:n.stroke,strokeWidth:n.strokeWidth}],className:"diagram__node__gateway","data-gateway-parent":n.parent.id,"data-gateway-id":n.id,"data-gateway-orientation":n.orientation,style:{pointerEvents:e.endpointDragActive?"none":void 0},onMouseEnter:o(()=>n.parent.setHovered(!0),"onMouseEnter"),onMouseOut:o(i=>{const s=i.relatedTarget;s instanceof Element&&s.closest(`[data-id="${n.parent.id}"], [data-gateway-parent="${n.parent.id}"]`)||n.parent.setState("hover",!1)},"onMouseOut")},n.id)}),Jg=A.observer(({node:n})=>{const e=X.use().getExtension(we);return d.jsx("path",{className:"diagram__node__edge_gateway",d:n.connectionBoundaryPath,"data-gateway-parent":n.id,fill:"none",stroke:"transparent",strokeWidth:16,vectorEffect:"non-scaling-stroke",style:{pointerEvents:e.endpointDragActive?"none":"stroke"},onMouseEnter:o(()=>n.setState("hover",!0),"onMouseEnter"),onMouseOut:o(i=>{const s=i.relatedTarget;s instanceof Element&&s.closest(`[data-id="${n.id}"], [data-gateway-parent="${n.id}"]`)||n.setState("hover",!1)},"onMouseOut")})}),Qg=A.observer(({node:n})=>{const t=n.RenderOverlay;return t?d.jsx(t,{node:n,box:n.box}):null}),tf=A.observer(()=>{const n=X.use();return d.jsx("div",{style:{width:`${n.canvas.size.x}px`,height:`${n.canvas.size.y}px`},children:n.nodes.map(t=>d.jsx(Qg,{node:t},t.id))})}),ef=A.observer(({node:n})=>n.parent?d.jsx(d.Fragment,{children:!n.RenderOverlay&&d.jsx(Ie,{paths:[{d:sc(n.box,10),stroke:n.state.stroke,strokeWidth:n.state.strokewWidth??3,fill:n.state.fill}],onMouseOver:o(()=>n.setHovered(!0),"onMouseOver"),onMouseOut:o(t=>{const e=t.relatedTarget;e instanceof Element&&e.closest(`[data-id="${n.id}"], [data-gateway-parent="${n.id}"]`)||n.setHovered(!1)},"onMouseOut"),className:n.classList.string,label:n.state.label,labelOffset:n.coordinates.sum(n.box.size.half),labelFontSize:n.state.labelFontSize??14,selected:n.selected,"data-id":n.id},n.id)}):null),ac=A.observer(({edge:n,showDragHandles:t})=>d.jsx(An,{edge:n,points:n.steps,endType:n.arrowHeadEnd??"arrow",startType:n.arrowHeadStart??"none",lineStyle:n.lineStyle??"solid",arrowSize:n.state.arrowSize,color:n.stroke,width:n.strokeWidth??2,draggable:t,onMidpointMouseDown:o((e,i)=>{n.dragStart(e,i)},"onMidpointMouseDown"),onEndpointMouseDown:o((e,i)=>{n.dragEndpoint(e,i)},"onEndpointMouseDown")})),nf=he(A.observer(()=>{const n=X.use(),t=n.getExtension(B),e=t?.selectedNodes??[],i=t?.selectedEdges??[],s=n.rules.allowEdition,r=e.length+i.length>1,a=[...n.nodes.filter(c=>!e.includes(c)),...e],l=r||!s?[]:a.filter(c=>c.hovered||c.selected).flatMap(c=>c.gateways);return d.jsxs(d.Fragment,{children:[a.map(c=>d.jsx(ef,{node:c},c.id)),s&&a.filter(c=>c.edgesAsGateways).map(c=>d.jsx(Jg,{node:c},`edge-gateway-${c.id}`)),n.edges.filter(c=>!i.includes(c)).map(c=>d.jsx(ac,{edge:c,showDragHandles:s&&!r},c.id)),l.map(c=>d.jsx(qg,{gateway:c},`${c.parent.id}-${c.id}`)),i.map(c=>d.jsx(ac,{edge:c,showDragHandles:s&&!r},`selected-${c.id}`))]})}));function sf(){return[d.jsx(nf,{},"ScalableShapes"),d.jsx(tf,{},"RenderNodeOverlays")]}o(sf,"shapes");function rf(n){if(!(n instanceof Element))return null;const t=n.closest("[data-gateway-parent]");return t?t.getAttribute("data-gateway-parent"):n.closest("[data-id]")?.getAttribute("data-id")??null}o(rf,"hoverOwnerId");const af=A.observer(({children:n})=>{const t=X.use(),e=t.getExtension(R);t.canvas.setGridSize(e?.gridSize??50);const i=[],s=[],r=[];return k.Children.forEach([...Wg(n),...sf()],a=>{a.type.__scalable?i.push(a):a.type.__scalableBack?r.push(a):s.push(a)}),d.jsxs("div",{className:`canvas__frame ${t.showGrid?"canvas__frame--grid":""}`,onPointerLeave:o(()=>t.clearNodeHover(),"onPointerLeave"),onPointerMove:o(a=>{const l=t.getNodeById(rf(a.target)??"");l?l.setHovered(!0):t.clearNodeHover()},"onPointerMove"),children:[d.jsxs("div",{ref:t.canvas.useRef,children:[r.length&&d.jsx(rc,{className:"background",children:r}),s.length&&d.jsx("div",{className:"scalable_components",children:s}),i.length&&d.jsx(rc,{className:"foreground",children:i})]}),d.jsx(Xg,{})]})});function of({children:n,className:t,...e}){return d.jsx("div",{...e,className:["stage",t].filter(Boolean).join(" "),children:n})}o(of,"Stage");const lf=he(A.observer(()=>{const n=X.use(),t=n.getExtension(Xt),e=n.getExtension(Tt),i=n.getExtension(Ke),s=[...t?.proposals??[],...n.extensions.flatMap(r=>r.alignmentProposals??[])];return d.jsxs(d.Fragment,{children:[s.map(r=>{const a=r.type==="h"?`M ${r.x} ${r.range[0]} V ${r.range[1]}`:`M ${r.range[0]} ${r.y} H ${r.range[1]}`;return d.jsx(Ie,{className:"alignment_sugestion",paths:[{d:a}]},r.id)}),e?.proposals.map(r=>d.jsx(Ie,{className:"alignment_sugestion",paths:[{d:`M ${r.from.x} ${r.from.y} L ${r.to.x} ${r.to.y}`}]},r.id)),i?.proposals.map(r=>{const a=`M ${r.from.x} ${r.from.y} L ${r.to.x} ${r.to.y}`;return d.jsx(Ie,{className:"distance_balance_sugestion",paths:[{d:a,arrow:{position:"both",size:8}}]},a)})]})})),cf=he(A.observer(()=>{const t=X.use().getExtension(Eo);return t?.enabled?d.jsxs(d.Fragment,{children:[t.grid?.edges.map(e=>{const{from:i,to:s}=e,r=`M ${i.x} ${i.y} L ${s.x} ${s.y}`,a=t.highlighted.has(e);return d.jsx(An,{className:`path_finding_grid_edge ${a?"highlighted":""}`,points:[i,s],endType:"none"},r)}),t.points?.length&&d.jsx(An,{className:"path_finding_grid_edge_chosen",points:t.points})]}):null})),jt=8,Os=2,df=120;function hf(n,t){const e=Math.max(jt,Math.min(n.x,window.innerWidth-t.width-jt)),i=Math.max(jt,Math.min(n.y,window.innerHeight-t.height-jt));return{x:e,y:i}}o(hf,"clampPosition");function uf({item:n,onAction:t}){const e=!!n.submenu?.length,i=k.useRef(null),s=k.useRef(null),r=k.useRef(null),[a,l]=k.useState(!1),[c,h]=k.useState(!1),[u,g]=k.useState({left:0,top:-4,openToLeft:!1}),p=k.useCallback(()=>{if(!i.current||!s.current)return;const _=i.current.getBoundingClientRect(),E=s.current.getBoundingClientRect();let j=_.width-Os,P=!1;_.right-Os+E.width>window.innerWidth-jt&&(j=-E.width+Os,P=!0),_.left+j<jt&&(j=jt-_.left,P=!1);let M=-4,C=_.top+M;C+E.height>window.innerHeight-jt&&(M-=C+E.height-(window.innerHeight-jt),C=_.top+M),C<jt&&(M+=jt-C),g({left:j,top:M,openToLeft:P}),h(!0)},[]);k.useEffect(()=>{a||h(!1)},[a]),k.useEffect(()=>()=>{r.current!==null&&window.clearTimeout(r.current)},[]),k.useLayoutEffect(()=>{a&&p()},[a,p]),k.useEffect(()=>{if(!a)return;const _=o(()=>{p()},"handleResize");return window.addEventListener("resize",_),()=>{window.removeEventListener("resize",_)}},[a,p]);const m=o(()=>{r.current!==null&&(window.clearTimeout(r.current),r.current=null)},"clearCloseTimeout"),b=o(()=>{e&&(m(),l(!0))},"openSubmenu"),x=o(()=>{m(),l(!1)},"closeSubmenu"),w=o(()=>{e&&(m(),r.current=window.setTimeout(()=>{l(!1),r.current=null},df))},"scheduleCloseSubmenu"),v=o(_=>{const E=_.relatedTarget;(!E||!_.currentTarget.contains(E))&&x()},"handleBlur");return d.jsxs("li",{ref:i,className:["diagram__context_menu_item",n.disabled&&"disabled",n.danger&&"danger",e&&"has_submenu",a&&"submenu_open"].filter(Boolean).join(" "),onMouseEnter:b,onMouseLeave:w,onFocusCapture:b,onBlurCapture:v,children:[d.jsxs("button",{type:"button",className:"diagram__context_menu_button",disabled:n.disabled,onClick:o(_=>{_.stopPropagation(),_.preventDefault(),t(n)},"onClick"),children:[d.jsx("span",{className:"diagram__context_menu_label",children:n.label}),e&&d.jsx("span",{className:"diagram__context_menu_chevron",children:u.openToLeft?"<":">"})]}),e&&a&&d.jsx("div",{ref:s,className:"diagram__context_menu_submenu",style:{left:u.left,top:u.top,opacity:c?1:0},children:d.jsx("div",{className:"diagram__context_menu diagram__context_menu--nested",children:d.jsx(oc,{items:n.submenu,onAction:t})})})]})}o(uf,"MenuItem");function oc({items:n,onAction:t}){return d.jsx("ul",{className:"diagram__context_menu_list",children:n.map((e,i)=>d.jsx(uf,{item:e,onAction:t},`${e.label}_${i}`))})}o(oc,"MenuItems");const pf=A.observer(({menu:n})=>{const t=k.useRef(null),[e,i]=k.useState(n.position);return k.useEffect(()=>{n.opened&&i(n.position)},[n.openVersion,n.opened,n.position]),k.useLayoutEffect(()=>{if(!n.opened||!t.current)return;const{width:s,height:r}=t.current.getBoundingClientRect(),{x:a,y:l}=hf(n.position,{width:s,height:r});(a!==e.x||l!==e.y)&&i({x:a,y:l})},[n.openVersion,n.opened,n.position,e.x,e.y]),k.useEffect(()=>{if(!n.opened)return;const s=o(c=>{c.code==="Escape"&&n.close()},"closeOnEscape"),r=o(c=>{if(c.button!==0)return;const h=c.target;h&&t.current?.contains(h)||n.close()},"closeOnOutsideMouseDown"),a=o(c=>{const h=c.target;if(h&&t.current?.contains(h)){c.preventDefault();return}n.close()},"closeOnOutsideContextMenu"),l=o(()=>{n.close()},"closeOnResize");return document.addEventListener("keydown",s),document.addEventListener("mousedown",r,!0),document.addEventListener("contextmenu",a,!0),window.addEventListener("resize",l),()=>{document.removeEventListener("keydown",s),document.removeEventListener("mousedown",r,!0),document.removeEventListener("contextmenu",a,!0),window.removeEventListener("resize",l)}},[n,n.openVersion,n.opened]),!n.opened||!n.elements.length?null:d.jsx("div",{className:"diagram__context_menu_layer",children:d.jsx("div",{ref:t,className:"diagram__context_menu",style:{left:e.x,top:e.y},onMouseDown:o(s=>{s.stopPropagation()},"onMouseDown"),onContextMenu:o(s=>{s.preventDefault(),s.stopPropagation()},"onContextMenu"),children:d.jsx(oc,{items:n.elements,onAction:o(s=>{n.execute(s)},"onAction")})})})}),Ja=class Ja{_elements=[];_opened=!1;_position={x:0,y:0};_openVersion=0;Component=o(()=>d.jsx(pf,{menu:this}),"Component");constructor(){f.makeAutoObservable(this,{Component:!1},{autoBind:!0})}get elements(){return this._elements}get opened(){return this._opened}get position(){return this._position}get openVersion(){return this._openVersion}open(t,e={}){if(!t.length){this.close();return}const i=fe.getInstance().coordinates;this._elements=t,this._position={x:e.x??i.x,y:e.y??i.y},this._openVersion+=1,this._opened=!0}close(){this._opened&&(this._opened=!1,this._elements=[])}execute(t){if(!t.disabled){try{const e=t.onClick();e instanceof Promise&&e.catch(()=>{})}catch{}t.submenu?.length||this.close()}}};o(Ja,"ContextMenuStore");let zs=Ja;const $s=new zs,Cn=o(()=>{},"noop");function gf(){return typeof navigator<"u"&&!!navigator.clipboard?.writeText&&!!navigator.clipboard?.readText}o(gf,"hasClipboardSupport");function lc(n){return()=>{n().catch(()=>{})}}o(lc,"runAsync");function ff(n,t,e){const i=n.getExtension(B),s=t.closest(".diagram__node")?.dataset.id,r=t.closest(".edge")?.dataset.id,a=s?n.getNodeById(s):void 0,l=r?n.getEdgeById(r):void 0;a&&!a.selected?(i.clearSelection(),i.selectNode(a)):l&&!l.state.selected&&(i.clearSelection(),i.selectEdge(l));const c=i.selectedNodes,h=i.selectedEdges,u=c.length+h.length>0,g=n.rules.allowEdition,p=gf(),m=p&&c.length>0,b=o(()=>{i.selectedNodes.forEach(_=>{n.delete(_)}),i.selectedEdges.forEach(_=>{n.disconnect(_)})},"deleteSelection"),x=[];a?x.push({label:`Node: ${a.state.label||a.id}`,onClick:Cn,submenu:[{label:"Center node",onClick:o(()=>{n.canvas.centerOnPoint(a.box.middle)},"onClick")},...g?[{label:"Delete node",onClick:o(()=>{n.delete(a)},"onClick"),danger:!0}]:[]]}):l&&g&&x.push({label:"Edge",onClick:Cn,submenu:[{label:"Delete edge",onClick:o(()=>{n.disconnect(l)},"onClick"),danger:!0}]}),u&&g&&x.push({label:"Delete selection",onClick:b,danger:!0});const w=[{label:i.selectionMode==="element"?"Element mode (active)":"Element mode",onClick:o(()=>{i.toggleSelectionMode("element")},"onClick")},{label:i.selectionMode==="area"?"Area mode (active)":"Area mode",onClick:o(()=>{i.toggleSelectionMode("area")},"onClick")},{label:"Clear selection",onClick:o(()=>{i.clearSelection()},"onClick"),disabled:!u},{label:"Copy selection",onClick:lc(async()=>{await navigator.clipboard.writeText(i.copy())}),disabled:!m}];g&&w.push({label:"Paste",onClick:lc(async()=>{const _=await navigator.clipboard.readText();_.trim().length&&n.paste(_)}),disabled:!p}),x.push({label:"Selection",onClick:Cn,submenu:w});const v=new y([e.x,e.y]);return x.push({label:"View",onClick:Cn,submenu:[{label:n.showGrid?"Hide grid":"Show grid",onClick:o(()=>{n.toggleGrid()},"onClick")},{label:`Zoom (${Math.round(n.canvas.scale*100)}%)`,onClick:Cn,submenu:[{label:"Zoom in",onClick:o(()=>{n.canvas.setScale(n.canvas.scale+.1,v)},"onClick")},{label:"Zoom out",onClick:o(()=>{n.canvas.setScale(n.canvas.scale-.1,v)},"onClick")},{label:"Reset zoom",onClick:o(()=>{n.canvas.setScale(1,v)},"onClick")}]}]}),x}o(ff,"buildDiagramContextMenu");const mf=A.observer(()=>{const n=X.use();return d.jsx("div",{className:"diagram__extension_ui",children:n.extensions.map(t=>{const e=t.RenderUI;return e?d.jsx(e,{diagram:n,extension:t},t.constructor.name):null})})}),xf=A.observer(({diagram:n,leftPanel:t,toolbar:e})=>{const i=o(s=>{const r=s.target;if(r instanceof HTMLElement){if(r.closest('input, textarea, [contenteditable="true"]')){$s.close();return}s.preventDefault(),$s.open(ff(n,r,{x:s.clientX,y:s.clientY}),{x:s.clientX,y:s.clientY})}},"handleContextMenu");return d.jsxs(n.Context,{children:[d.jsxs(of,{onContextMenu:i,children:[t,d.jsxs(af,{children:[d.jsx(Vg,{}),d.jsx(Fg,{}),d.jsx(Hg,{}),d.jsx(lf,{}),d.jsx(Gg,{}),d.jsx(cf,{})]}),d.jsx(mf,{})]}),d.jsx($s.Component,{}),e]})}),Qa=class Qa extends y{direction="left";get rawDirectedPoint(){return{x:this.x,y:this.y,direction:this.direction}}stepBack(){switch(this.direction){case"down":this.y--;break;case"left":this.x++;break;case"right":this.x--;break;case"up":this.y++;break}return this}stepForward(){switch(this.direction){case"down":this.y++;break;case"left":this.x--;break;case"right":this.x++;break;case"up":this.y--;break}return this}};o(Qa,"DirectedPoint");let Fs=Qa;const yf=Object.freeze(Object.defineProperty({__proto__:null,DirectedPoint:Fs},Symbol.toStringTag,{value:"Module"}));T.AgentDiagram=is,T.BPMDiagram=hi,T.BPMNExecutionBlackBoxPoolNode=un,T.BPMNExecutionDataStoreNode=pn,T.BPMNExecutionDiagram=fs,T.BPMNExecutionDocumentAnnotationNode=gn,T.BPMNExecutionDocumentNode=fn,T.BPMNExecutionEdge=Ot,T.BPMNExecutionEventNode=mn,T.BPMNExecutionGateNode=xn,T.BPMNExecutionLanes=yn,T.BPMNExecutionMarker=hn,T.BPMNExecutionTaskNode=bn,T.BPMNExecutionTextAnnotationNode=wn,T.BPMNExecutionUnknownNode=vn,T.BPMNNodeExecutionState=st,T.BPMN_LABELS=At,T.CommunicationDiagram=ms,T.Diagram=X,T.DiagramEditor=xf,T.MRDiagram=Ts,T.MRForeignKeyEdge=It,T.MRTableNode=Zt,T.ToolsStates=Tn,T.configureBPMNLabels=rs,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})}));
|
|
7
7
|
//# sourceMappingURL=index.umd.js.map
|