@focus.matters/diagrams 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/INTEGRATION.md +40 -0
  2. package/LIFECYCLE.md +117 -0
  3. package/dist/{DirectedPoint-BSGh_PUt.js → DirectedPoint-DNhrnCXr.js} +2 -2
  4. package/dist/diagrams.css +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.es.js +16509 -26
  7. package/dist/index.umd.js +6 -6
  8. package/dist/src/Diagrams/components/objects/RenderEdge/types.d.ts +6 -3
  9. package/dist/src/Diagrams/components/objects/edgeLabelPlacement.d.ts +4 -1
  10. package/dist/src/Diagrams/components/objects/useEdgeLabelMeasurement.d.ts +4 -0
  11. package/dist/src/Diagrams/components/stopDiagramControlEvent.d.ts +11 -0
  12. package/dist/src/Diagrams/components/useDiagramPointerCapture.d.ts +14 -0
  13. package/dist/src/Diagrams/custom/agent/edges/AgentEdge.d.ts +6 -6
  14. package/dist/src/Diagrams/custom/agent/nodes/AgentNode.d.ts +7 -7
  15. package/dist/src/Diagrams/custom/bpmn/edges/BPMNEdge.d.ts +6 -6
  16. package/dist/src/Diagrams/custom/bpmn/extensions/BPMNModelerExtension.d.ts +2 -2
  17. package/dist/src/Diagrams/custom/bpmn/nodes/DocumentNode.d.ts +7 -7
  18. package/dist/src/Diagrams/custom/bpmn/nodes/EventNode.d.ts +7 -7
  19. package/dist/src/Diagrams/custom/bpmn/nodes/GateNode.d.ts +7 -7
  20. package/dist/src/Diagrams/custom/bpmn/nodes/Lanes/index.d.ts +8 -8
  21. package/dist/src/Diagrams/custom/bpmn/nodes/TaskNode.d.ts +7 -7
  22. package/dist/src/Diagrams/custom/bpmn/nodes/TextAnnotationNode.d.ts +7 -7
  23. package/dist/src/Diagrams/custom/bpmn/nodes/UnknownBPMNNode.d.ts +7 -7
  24. package/dist/src/Diagrams/custom/bpmnExecution/BPMNExecutionEdge.d.ts +6 -6
  25. package/dist/src/Diagrams/custom/bpmnExecution/BPMNExecutionExtension.d.ts +1 -1
  26. package/dist/src/Diagrams/custom/bpmnExecution/nodes/BPMNExecutionBlackBoxPoolNode.d.ts +7 -7
  27. package/dist/src/Diagrams/custom/bpmnExecution/nodes/BPMNExecutionDataStoreNode.d.ts +7 -7
  28. package/dist/src/Diagrams/custom/bpmnExecution/nodes/BPMNExecutionDocumentAnnotationNode.d.ts +7 -7
  29. package/dist/src/Diagrams/custom/bpmnExecution/nodes/BPMNExecutionDocumentNode.d.ts +7 -7
  30. package/dist/src/Diagrams/custom/bpmnExecution/nodes/BPMNExecutionEventNode.d.ts +7 -7
  31. package/dist/src/Diagrams/custom/bpmnExecution/nodes/BPMNExecutionGateNode.d.ts +7 -7
  32. package/dist/src/Diagrams/custom/bpmnExecution/nodes/BPMNExecutionTaskNode.d.ts +7 -7
  33. package/dist/src/Diagrams/custom/bpmnExecution/nodes/BPMNExecutionTextAnnotationNode.d.ts +7 -7
  34. package/dist/src/Diagrams/custom/bpmnExecution/nodes/BPMNExecutionUnknownNode.d.ts +7 -7
  35. package/dist/src/Diagrams/custom/communication/CommunicationDiagram.d.ts +2 -2
  36. package/dist/src/Diagrams/custom/editable/EditableNode.d.ts +2 -2
  37. package/dist/src/Diagrams/custom/mr/bindAttributeRelationshipHover.d.ts +3 -0
  38. package/dist/src/Diagrams/custom/mr/edges/MRForeignKeyEdge.d.ts +6 -6
  39. package/dist/src/Diagrams/custom/mr/extensions/MRModelerExtension.d.ts +1 -1
  40. package/dist/src/Diagrams/custom/mr/nodes/MRTableNode.d.ts +7 -7
  41. package/dist/src/Diagrams/store/Canvas.d.ts +45 -0
  42. package/dist/src/Diagrams/store/Diagram.d.ts +7 -1
  43. package/dist/src/Diagrams/store/revealDiagramNode.d.ts +10 -0
  44. package/dist/src/index.d.ts +40 -0
  45. package/package.json +11 -7
  46. package/dist/DirectedPoint-BSGh_PUt.js.map +0 -1
  47. package/dist/index-y4Eon_hl.js +0 -16196
  48. package/dist/index-y4Eon_hl.js.map +0 -1
  49. package/dist/index.es.js.map +0 -1
  50. package/dist/index.umd.js.map +0 -1
package/dist/index.umd.js CHANGED
@@ -1,7 +1,7 @@
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
- a ${t},${t} 0 1,0 ${2*t},0
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"})}));
1
+ (function(E,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):(E=typeof globalThis<"u"?globalThis:E||self,f(E.FocusMattersDiagrams={},E.mobx,E.React,E.mobxReactLite))})(this,(function(E,f,S,A){"use strict";var uc=Object.defineProperty;var Nf=(E,f,S)=>f in E?uc(E,f,{enumerable:!0,configurable:!0,writable:!0,value:S}):E[f]=S;var o=(E,f)=>uc(E,"name",{value:f,configurable:!0});var $e=(E,f,S)=>Nf(E,typeof f!="symbol"?f+"":f,S);var Vt,Wt,Yt,Zt,Kt,Ut,qt,Xt;const On=class On{showDragHints=!1;constructor(){f.makeAutoObservable(this)}};o(On,"ToolsStates"),$e(On,"instance",new On);let Hn=On;var zi={exports:{}},Jt={};var no;function gc(){if(no)return Jt;no=1;var n=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function t(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(t,"jsxProd"),Jt.Fragment=e,Jt.jsx=t,Jt.jsxs=t,Jt}o(gc,"requireReactJsxRuntime_production");var io;function pc(){return io||(io=1,zi.exports=gc()),zi.exports}o(pc,"requireJsxRuntime");var d=pc();const Ee=class Ee{_data=[];constructor(e,t=!0){if(e||(e=[0,0,0,0]),Array.isArray(e)){if(e.length!==4)throw new Error("Invalid coordinates length");this._data=[...e]}else this._data=[...e._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}t&&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(e){this.set(0,e)}set y(e){this.set(1,e)}set height(e){this.set(3,e)}set width(e){this.set(2,e)}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 Ee([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(e){if(e.length!==4)throw new Error("Invalid number of Dimensions");const t=e instanceof Ee?e:new Ee(e);return this.set(0,t.get(0)),this.set(1,t.get(1)),this.set(2,t.get(2)),this.set(3,t.get(3)),this}assignCoordinates(e){if(e.length!==2)throw new Error("Invalid number of Coordinates");const t=e instanceof y?e:new y(e);return this.set(0,t.get(0)),this.set(1,t.get(1)),this}assignDimensions(e){if(e.length!==2)throw new Error("Invalid number of Coordinates");const t=e instanceof y?e:new y(e);return this.set(2,t.get(0)),this.set(3,t.get(1)),this}bound(e){this.x=Math.min(e.x+e.width-this.width,Math.max(e.x,this.x)),this.y=Math.min(e.y+e.height-this.height,Math.max(e.y,this.y))}collides(e,t=!1){if(e instanceof Ee){const i=this.x-(t?1:0),s=this.x+this.width+(t?1:0),r=this.y-(t?1:0),a=this.y+this.height+(t?1:0),l=e.x,c=e.x+e.width,h=e.y,u=e.y+e.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 e.x>=i&&e.x<=s&&e.y>=r&&e.y<=a}}copy(){return new Ee([this.x,this.y,this.width,this.height])}divide(e){return this.set(0,this.get(0)/e),this.set(1,this.get(1)/e),this.set(2,this.get(2)/e),this.set(3,this.get(3)/e),this}edgeDistanceX(e){return this.x>e.x+e.width?-(this.x-e.x-e.width):e.x>this.x+this.width?e.x-this.x-this.width:0}edgeDistanceY(e){return this.y>e.y+e.height?-(this.y-e.y-e.height):e.y>this.y+this.height?e.y-this.y-this.height:0}get(e){return this._data[e]}inflate(e){return this.copy().translate(new y([-e,-e])).assignDimensions(this.size.sum(new y([2*e,2*e])))}multiply(e){return this.set(0,this.get(0)*e),this.set(1,this.get(1)*e),this.set(2,this.get(2)*e),this.set(3,this.get(3)*e),this}scale(e){return this.set(2,this.get(2)+e.get(0)),this.set(3,this.get(3)+e.get(1)),this}set(e,t){this._data[e]=t}substract(e){if(e.length!==4)throw new Error("Invalid number of Dimensions");const t=e instanceof Ee?e:new Ee(e);return this.set(0,this.get(0)-t.get(0)),this.set(1,this.get(1)-t.get(1)),this.set(2,this.get(2)-t.get(2)),this.set(3,this.get(3)-t.get(3)),this}sum(e){if(e instanceof y)this.set(0,this.get(0)+e.get(0)),this.set(1,this.get(1)+e.get(1));else{if(e.length!==4)throw new Error("Invalid number of Dimensions");const t=e instanceof Ee?e:new Ee(e);this.set(0,this.get(0)+t.get(0)),this.set(1,this.get(1)+t.get(1)),this.set(2,this.get(2)+t.get(2)),this.set(3,this.get(3)+t.get(3))}return this}toString(){return`(${this.x}, ${this.y}, ${this.width}, ${this.height})`}translate(e){return this.set(0,this.get(0)+e.get(0)),this.set(1,this.get(1)+e.get(1)),this}};o(Ee,"Dimensions");let M=Ee;const Bs=class Bs{constructor(e){this.originalEvent=e}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(Bs,"MouseInformation");let Fi=Bs;const Rs=class Rs{constructor(e){this.src=e}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(e){return this._cancellable=e,this}cancel(){this._cancellable&&(this._cancelled=!0)}stopPropagation(){this._bubbles=!1}stopImmediatePropagation(){this._spreads=!1,this.stopPropagation()}};o(Rs,"DEvent");let Qt=Rs;const Gs=class Gs extends Qt{};o(Gs,"DUIEvent");let et=Gs;const Vs=class Vs extends et{constructor(e,t){super(e),this.src=e,this.originalEvent=t,this.mouse=new Fi(t)}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 e=this.originalEvent.target,t=e&&typeof e.closest=="function"?e:null,i=t?.closest(".diagram__node, .node__screenHitArea")?.dataset.id,s=t?.closest("[data-gateway-parent]")?.dataset.gatewayParent;if(i||s)return this.src.diagram?.getNodeById(i||s);if(t?.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(Vs,"DMouseEvent");let je=Vs;const Ws=class Ws extends je{};o(Ws,"DClickEvent");let en=Ws;const Ys=class Ys extends je{};o(Ys,"DDoubleClickEvent");let tn=Ys;const Zs=class Zs extends je{};o(Zs,"DMouseDownEvent");let Pe=Zs;const Ks=class Ks extends je{};o(Ks,"DMouseUpEvent");let ne=Ks;const Us=class Us extends je{};o(Us,"DMouseMoveEvent");let Ne=Us;const qs=class qs extends je{constructor(e,t){super(e,t),this.originalEvent=t}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(qs,"DWheelEvent");let Bn=qs;const Xs=class Xs extends et{constructor(e,t){super(e),this.originalEvent=t}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 yt=Xs;const Js=class Js extends yt{constructor(e,t){super(e,t),this.originalEvent=t}originalEvent};o(Js,"DKeyDownEvent");let Ue=Js;const Qs=class Qs extends yt{constructor(e,t){super(e,t),this.originalEvent=t}originalEvent};o(Qs,"DKeyUpEvent");let bt=Qs;const er=class er extends yt{constructor(e,t){super(e,t),this.orignalEvent=t}orignalEvent};o(er,"DKeyPressEvent");let Rn=er;const tr=class tr extends et{};o(tr,"DCanvasEvent");let xt=tr;const nr=class nr extends xt{constructor(e,t,i,s){super(e),this.displacement=t,this.newScale=i,this.previousScale=s}displacement;newScale;previousScale};o(nr,"DScaleEvent");let vt=nr;const ir=class ir extends xt{constructor(e,t,i){super(e),this.previousDisplacement=t,this.displacement=i}previousDisplacement;displacement};o(ir,"DDisplaceEvent");let Gn=ir;const sr=class sr extends Qt{};o(sr,"DChangeEvent");let ee=sr;const rr=class rr extends ee{constructor(e,t){super(e),t(this.resolve.bind(this))}callbacks=[];defer(e){this.callbacks.push(e)}async resolve(){return(await Promise.all(this.callbacks.map(e=>e()))).every(e=>e)}};o(rr,"DResetGraphEvent");let Vn=rr;const ar=class ar extends ee{};o(ar,"DNodesConnectionEvent");let wt=ar;const or=class or extends wt{constructor(e,t){super(e),this.origin=t}origin};o(or,"DNodeConnectionIntentEvent");let Wn=or;const lr=class lr extends wt{constructor(e,t,i,s){super(e),this.origin=t,this.target=i,this.edge=s}origin;target;edge};o(lr,"DNodesConnectActionEvent");let Et=lr;const cr=class cr extends ee{};o(cr,"DNodeChangeTypeEvent");let pe=cr;const dr=class dr extends ee{constructor(e,t){super(e),this.src=e,this.node=t}src;node};o(dr,"DDeleteNodeEvent");let tt=dr;const hr=class hr extends ee{constructor(e,t){super(e),this.src=e,this.edge=t}src;edge};o(hr,"DDeleteEdgeEvent");let nn=hr;const ur=class ur extends et{constructor(e,t){super(e),this.src=e,this.selected=t}src;selected};o(ur,"DSelectionEvent");let _t=ur;const gr=class gr extends _t{constructor(e,t){super(e,t),this.src=e}src};o(gr,"DNodeSelectionEvent");let kt=gr;const pr=class pr extends _t{constructor(e,t){super(e,t),this.src=e}src};o(pr,"DEdgeSelectionEvent");let sn=pr;const fr=class fr extends ee{constructor(e,t){super(e),this.src=e,this.originalEvent=t}src;originalEvent};o(fr,"DDragEvent");let He=fr;const mr=class mr extends He{constructor(e,t,i){super(e,i),this.src=e,this.midPoint=t,this.originalEvent=i}src;midPoint;originalEvent};o(mr,"DEdgeDragStartEvent");let rn=mr;const yr=class yr extends He{constructor(e,t,i){super(e,i),this.src=e,this.endpoint=t,this.originalEvent=i}src;endpoint;originalEvent};o(yr,"DEdgeEndpointDragStartEvent");let an=yr;const br=class br{constructor(e,t){this.node=e,this.newBox=t,this._updated=t.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(e){this._updated=e,this._lockX!==null&&(this._updated.x=this._lockX),this._lockY!==null&&(this._updated.y=this._lockY)}updateX(e){this._lockX===null&&(this._updated.x=e)}updateY(e){this._lockY===null&&(this._updated.y=e)}};o(br,"NodePositionProposal");let St=br;const xr=class xr extends He{constructor(e,t,i){super(e,i),this.src=e,this.proposals=t}src;proposals};o(xr,"DDragNodeEvent");let fe=xr;const vr=class vr{constructor(e,t){this.point=e,this.movedAxis=t,this._updated=e.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(e){this._updated=e.copy(),this._lockX!==null&&(this._updated.x=this._lockX),this._lockY!==null&&(this._updated.y=this._lockY)}updateX(e){this._lockX===null&&(this._updated.x=e)}updateY(e){this._lockY===null&&(this._updated.y=e)}};o(vr,"EdgePointPositionProposal");let on=vr;const wr=class wr extends He{constructor(e,t,i,s){super(e,s),this.src=e,this.proposals=t,this.movedAxis=i}src;proposals;movedAxis};o(wr,"DDragEdgeSegmentEvent");let ln=wr;async function fc(){return(await Promise.resolve().then(()=>jf)).DirectedPoint}o(fc,"getDirectedClass");let $i=null;const Q=class Q{_data=[];constructor(e,t=!0){if(e||(e=[0,0]),Array.isArray(e)){if(e.length!==2)throw new Error("Invalid coordinates length");this._data=[...e]}else e instanceof Q?this._data=[...e._data]:e instanceof je||e instanceof He?this._data=[e.originalEvent.clientX,e.originalEvent.clientY]:e.clientX!==void 0?this._data=[e.clientX,e.clientY]:this._data=[0,0];t&&f.makeObservable(this,{_data:f.observable,set:f.action})}bound(e){return this.x=Math.min(e.get(2),Math.max(e.get(0),this.x)),this.y=Math.min(e.get(3),Math.max(e.get(1),this.y)),this}get abs(){return new Q([Math.abs(this.x),Math.abs(this.y)])}assign(e){if(e.length!==2)throw new Error("Invalid number of coordinates");const t=e instanceof Q?e:new Q(e);return this.set(0,t.get(0)),this.set(1,t.get(1)),this}copy(e=!0){return new Q(this,e)}distance(e){return this.copy().substract(e).norm}distanceManhattan(e){return Math.abs(this.x-e.x)+Math.abs(this.y-e.y)}divide(e){const t=e instanceof Q?e.x:e,i=e instanceof Q?e.y:e;return this.set(0,this.get(0)/t),this.set(1,this.get(1)/i),this}equals(e){return this.copy().substract(e).norm===0}get(e){return this._data[e]}get length(){return this._data.length}max(e){return new Q([Math.max(e,this.x),Math.max(e,this.y)])}get nonObserved(){return new Q(this,!1)}get raw(){return f.toJS([...this._data])}get round(){return new Q([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(e){return typeof e=="number"?(this.set(0,this.get(0)*e),this.set(1,this.get(1)*e)):e instanceof Q&&(this.set(0,this.get(0)*e.get(0)),this.set(1,this.get(1)*e.get(1))),this}set(e,t){return this._data[e]=t,this}snapToGrid(e,t="both"){return t!=="y"&&(this.x=Math.round(this.x/e)*e),t!=="x"&&(this.y=Math.round(this.y/e)*e),this}substract(e){if(e.length!==2)throw new Error("Invalid number of coordinates");const t=e instanceof Q?e:new Q(e);return this.set(0,this.get(0)-t.get(0)),this.set(1,this.get(1)-t.get(1)),this}sum(e){if(typeof e=="number")this.set(0,this.get(0)+e),this.set(1,this.get(1)+e);else{if(e.length!==2)throw new Error("Invalid number of coordinates");const t=e instanceof Q?e:new Q(e);this.set(0,this.get(0)+t.get(0)),this.set(1,this.get(1)+t.get(1))}return this}toDirectedPoint(e){if($i===null){fc().then(s=>{$i=s});const i=this.copy(!1);return i.direction=e,i}const t=new $i(this);return t.direction=e,t}toDimensions(e){return new M([...this.raw,...e.raw])}get x(){return this.get(0)}get y(){return this.get(1)}set x(e){this.set(0,e)}set y(e){this.set(1,e)}toString(){return`(${this.x}, ${this.y})`}};o(Q,"Coordinates");let y=Q;const zn=class zn{static getInstance(){return this.instance||(this.instance=new zn),this.instance}x=0;y=0;get coordinates(){return new y([this.x,this.y])}constructor(){f.makeAutoObservable(this),document.addEventListener("mousemove",e=>{f.runInAction(()=>{this.x=e.clientX,this.y=e.clientY})})}};o(zn,"Mouse"),$e(zn,"instance",null);let Mt=zn;const so={};function At(n,e,t=[]){let i=so[e]||0;for(;t.includes(`${e}${i}`)||n.getNodeById(`${e}${i}`);)i++;return so[e]=i+1,`${e}${i}`}o(At,"getIdForNode");function mc(n){const e=[];let t=n;for(;t&&t!==Object;)e.push(t),t=Object.getPrototypeOf(t);return e}o(mc,"getClassHierarchy");let qe=(Vt=class{constructor(e){this.parent=e,f.makeObservable(this,{parent:f.observable,diagram:f.computed})}parent;callbacks=new Map;emit(e){const t=[];for(const i of mc(e.constructor)){const s=this.callbacks.get(i);s&&t.push(...s)}t.sort((i,s)=>s.priority-i.priority);for(const{cb:i}of t)if(i(e),!e.spreads)return e;return e.bubbles&&this.parent?.emit(e),e}get diagram(){let e=this.parent;for(;e?.parent;)e=e.parent;return e}onEvent(e,t,i=0){let s=this.callbacks.get(e);return s||(s=[],this.callbacks.set(e,s)),s.push({cb:t,priority:i}),()=>this.offEvent(e,t)}offEvent(e,t){const i=this.callbacks.get(e);i&&this.callbacks.set(e,i.filter(s=>s.cb!==t))}},o(Vt,"Element"),Vt);function yc(n,e,t="text/plain"){const i=new Blob([n],{type:t}),s=URL.createObjectURL(i),r=document.createElement("a");r.href=s,r.download=e,r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(s)}o(yc,"downloadFile");const Er=class Er extends qe{constructor(e){super(e),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(e=!this._enable,t=!0){this._enable=e,t&&localStorage.setItem(`enable_${this.constructor.name}`,String(this._enable))}};o(Er,"DiagramExtension");let F=Er;const Hi=new WeakMap;let bc=0;const me={mark(n,e){const t=Hi.get(n)??{};t[e]===void 0&&(t[e]=bc++,Hi.set(n,t))},get(n,e){return Hi.get(n)?.[e]}};function ro(n,e){return!n||e.score<n.score?e:n}o(ro,"nearest");const _r=class _r extends F{gridSize=25;proposals=[];clear(){this.proposals=[]}init(){f.makeObservable(this,{clear:f.action,proposals:f.observable}),this.diagram.onEvent(ne,()=>this.clear()),this.diagram.onEvent(fe,e=>this.balance(e),this.diagram.priorities.Drag_Node_Distances_Balancer)}balance(e){if(this.clear(),!this.enabled||e.proposals.length===0)return;const t=new Set(e.proposals.map(({node:l})=>l.id)),i=this.diagram.canvas.frameDimensions.norm/2;let s=null,r=null;for(const l of e.proposals){if(l.cancelled)continue;const c=l.get(),h=this.findNeighbors(c,t,i);if(h.top&&h.bottom){const u=-c.edgeDistanceY(h.top.box),p=c.edgeDistanceY(h.bottom.box),g=Math.abs(u-p);g<this.gridSize&&(r=ro(r,{proposal:l,score:g,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),p=c.edgeDistanceX(h.right.box),g=Math.abs(p-u);g<this.gridSize&&(s=ro(s,{proposal:l,score:g,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(e,t,i){let s=null,r=null,a=null,l=null,c=1/0,h=1/0,u=1/0,p=1/0;for(const g of this.diagram.nodes){if(t.has(g.id))continue;const m=e.edgeDistanceX(g.box),x=e.edgeDistanceY(g.box);x===0&&m<0&&-m<u&&(u=-m,a=g),x===0&&m>0&&m<p&&(p=m,l=g),m===0&&x<0&&-x<c&&(c=-x,s=g),m===0&&x>0&&x<h&&(h=x,r=g)}return{top:c<i?s:null,bottom:h<i?r:null,left:u<i?a:null,right:p<i?l:null}}applyCandidate(e,t){if(e){if(t==="x"){e.proposal.updateX(e.target),me.mark(e.proposal,"x"),e.proposal.lockX();return}e.proposal.updateY(e.target),me.mark(e.proposal,"y"),e.proposal.lockY()}}};o(_r,"DistancesBalancer");let Ct=_r;const kr=class kr extends F{gridSize=50;init(){f.makeObservable(this,{gridSize:f.observable}),this.diagram.onEvent(fe,e=>{if(this._enable)for(const t of e.proposals){const i=new y([Math.round(t.newBox.coordinates.x/this.gridSize)*this.gridSize,Math.round(t.newBox.coordinates.y/this.gridSize)*this.gridSize]);t.update(new M([...i.raw,...t.newBox.size.raw])),t.lockX(),t.lockY()}},this.diagram.priorities.Drag_Node_Snap_To_Grid),this.diagram.onEvent(ln,e=>{if(this._enable)for(const t of e.proposals){const i=t.get().copy();i.snapToGrid(this.gridSize,e.movedAxis),t.update(i),e.movedAxis==="x"?t.lockY():t.lockX()}},this.diagram.priorities.Drag_Edge_Snap_To_Grid)}};o(kr,"GridSnap");let B=kr;const Sr=class Sr extends F{windowTime=20;maxSize=50;index=-1;snapshots=[];draggingNodes=!1;async avoidEvents(e){this.disable();try{await e()}finally{this.enable()}}restoreSnapshot(e){return this.avoidEvents(async()=>{this.clearTransientExtensions(),this.draggingNodes=!1;const t=JSON.parse(e);t.position=this.checkpointPosition(),await this.diagram.reset(),this.diagram.import(JSON.stringify(t))})}clearTransientExtensions(){this.diagram.extensions.forEach(e=>{e.clear?.()})}checkpointPosition(){const e=this.diagram.canvas.displacement;return{x:e.x,y:e.y,scale:this.diagram.canvas.scale}}unbind=o(()=>{},"unbind");window(){this.enabled&&(this.unbind(),this.unbind=Me(Wc(()=>{f.runInAction(()=>{const e=this.diagram.serialize();this.snapshots.splice(this.index+1),this.snapshots.push(JSON.stringify(e)),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(ee,e=>{if(e instanceof fe){this.draggingNodes=!0;return}e.cancelled||this.window()},this.diagram.priorities.Change_History),this.diagram.onEvent(ne,()=>{this.draggingNodes&&(this.draggingNodes=!1,this.window())}),this.window()}};o(Sr,"History");let It=Sr;const Mr=class Mr extends F{init(){f.makeObservable(this,{_enabled:f.observable,endPoint:f.observable,startPoint:f.observable}),this.diagram.canvas.onEvent(Pe,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(e){this._enabled&&(e.cancel(),e.stopImmediatePropagation(),this.u(),this.u=Me(Y(this,"mousemove",this.handleMouseMove),Y(this,"mouseup",this.handleMouseUp)),this.startPoint=this.diagram.canvas.inverseFit(new y(e)),this.endPoint=this.diagram.canvas.inverseFit(new y(e)))}handleMouseMove(e){this.startPoint&&this._enabled&&(this.endPoint=this.diagram.canvas.inverseFit(new y(e)))}handleMouseUp(){this.endPoint=null,this.startPoint=null}};o(Mr,"Measurer");let jt=Mr;const Yn=new Map;function nt(n){Yn.has(n)||Yn.set(n,Number.MIN_SAFE_INTEGER);const e=Yn.get(n);return Yn.set(n,e+1),`${n}_${e}`}o(nt,"getUniqueId");function Pt(n,e){return n<=e?[n,e]:[e,n]}o(Pt,"orderedRange$1");function Xe(n,e){return Number.isFinite(e.distance)&&(!n||e.distance<n.distance)?e:n}o(Xe,"closer$1");const Ar=class Ar extends F{gridSize=50;horizontalSuggestionProviders=[];verticalSuggestionProviders=[];proposals=[];registerHorizontalSuggestionProvider(e){return this.horizontalSuggestionProviders.push(e),()=>{this.horizontalSuggestionProviders=this.horizontalSuggestionProviders.filter(t=>t!==e)}}registerVerticalSuggestionProvider(e){return this.verticalSuggestionProviders.push(e),()=>{this.verticalSuggestionProviders=this.verticalSuggestionProviders.filter(t=>t!==e)}}clear(){this.proposals=[]}init(){f.makeObservable(this,{clear:f.action,proposals:f.observable}),Y(this,"keydown",e=>{e.ctrlKey&&this.clear()}),this.diagram.onEvent(ne,()=>this.clear()),this.diagram.onEvent(fe,e=>this.align(e),this.diagram.priorities.Drag_Node_Aligner)}align(e){if(this.clear(),!this.enabled||e.proposals.length===0)return;const t=this.diagram.canvas.frameDimensions.norm/2,i=this.gridSize/5*2,s=this.gridSize/3,r=new Set(e.proposals.map(({node:p})=>p.id)),a=e.proposals.some(p=>me.get(p,"x")!==void 0),l=e.proposals.some(p=>me.get(p,"y")!==void 0);let c=null,h=null;for(const p of e.proposals){if(p.cancelled)continue;const g=p.get();for(const m of this.diagram.nodes){if(r.has(m.id))continue;const x=Math.abs(g.edgeDistanceX(m.box)),b=Math.abs(g.edgeDistanceY(m.box));!l&&x<t&&(h=Xe(h,this.verticalCandidate(p,Math.abs(m.box.middle.y-g.middle.y),m.box.middle.y-g.height/2,m.box.middle.y,Pt(m.box.rightMiddle.x,g.x),i)),h=Xe(h,this.verticalCandidate(p,Math.abs(m.box.y-g.y),m.box.y,m.box.y,Pt(m.box.rightMiddle.x,g.x),i)),h=Xe(h,this.verticalCandidate(p,Math.abs(m.box.bottomMiddle.y-g.bottomMiddle.y),m.box.bottomMiddle.y-g.height,m.box.bottomMiddle.y,Pt(m.box.rightMiddle.x,g.x),i))),!a&&b<t&&(c=Xe(c,this.horizontalCandidate(p,Math.abs(m.box.x-g.x),m.box.x,m.box.x,Pt(m.box.bottomMiddle.y,g.y),i)),c=Xe(c,this.horizontalCandidate(p,Math.abs(m.box.middle.x-g.middle.x),m.box.middle.x-g.width/2,m.box.middle.x,Pt(m.box.bottomMiddle.y,g.y),i)),c=Xe(c,this.horizontalCandidate(p,Math.abs(m.box.rightMiddle.x-g.rightMiddle.x),m.box.rightMiddle.x-g.width,m.box.rightMiddle.x,Pt(m.box.bottomMiddle.y,g.y),i)))}if(!l)for(const m of this.verticalSuggestionProviders.flatMap(x=>x(p.node,g)))h=Xe(h,this.verticalCandidate(p,Math.abs(m.nodeY-g.y),m.nodeY,m.guideY,m.range,i));if(!a)for(const m of this.horizontalSuggestionProviders.flatMap(x=>x(p.node,g)))c=Xe(c,this.horizontalCandidate(p,Math.abs(m.nodeX-g.x),m.nodeX,m.guideX,m.range,i))}const u=[c?.guide,h?.guide].filter(p=>!!p);f.runInAction(()=>{this.proposals=u}),this.applyCandidate(c,"x",s),this.applyCandidate(h,"y",s)}verticalCandidate(e,t,i,s,r,a){return{proposal:e,distance:t<a?t:1/0,target:i,guide:{type:"v",y:s,range:r,id:nt("alignment-proposal")}}}horizontalCandidate(e,t,i,s,r,a){return{proposal:e,distance:t<a?t:1/0,target:i,guide:{type:"h",x:s,range:r,id:nt("alignment-proposal")}}}applyCandidate(e,t,i){if(!(!e||e.distance>=i)){if(t==="x"){if(e.proposal.updateX(e.target),Math.abs(e.proposal.get().x-e.target)>.001)return;me.mark(e.proposal,"x"),e.proposal.lockX();return}e.proposal.updateY(e.target),!(Math.abs(e.proposal.get().y-e.target)>.001)&&(me.mark(e.proposal,"y"),e.proposal.lockY())}}};o(Ar,"NodesAligner");let Be=Ar;const mt=class mt{constructor(e){this.diagram=e}diagram;displace(e){if(!this.diagram.rules.displaceWhenDragOnEdges)return new y;const t=this.diagram.canvas.frameDimensions,i=new y([this.axisDisplacement(e.x,t.x,t.width),this.axisDisplacement(e.y,t.y,t.height)]);return i.norm>0&&this.diagram.canvas.displace(i),i}axisDisplacement(e,t,i){const s=e-t;if(s<mt.edgeThreshold)return this.step(s);const r=t+i-e;return r<mt.edgeThreshold?-this.step(r):0}step(e){const t=Math.max(e,0);return((mt.edgeThreshold-t)/10)**2}};o(mt,"Autopan"),$e(mt,"edgeThreshold",100);let _e=mt;const Cr=class Cr extends ee{};o(Cr,"DEdgeLabelChangeEvent");let it=Cr;const Ir=class Ir extends qe{id;text;alignment;size;position;isEditing;draft;isNew;constructor(e,t,i=!1){super(e),this.id=t.id??nt("edge-label"),this.text=t.text??"",this.alignment=t.alignment??"left",this.size=t.size??{height:30,width:i?16:180},this.position=t.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(e){this.text=e,this.draft=e,this.isNew=!1}setAlignment(e){this.alignment!==e&&(this.alignment=e,this.emit(new it(this)))}setSize(e){this.size=e}beginEdit(){this.draft=this.text,this.isEditing=!0}setDraft(e){this.draft=e}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 e=this.isNew||this.draft!==this.text;this.text=this.draft,this.isNew=!1,this.isEditing=!1,e&&this.emit(new it(this))}setPosition(e){this.position.assign(e)}commitPosition(){this.emit(new it(this))}serialize(){return{alignment:this.alignment,id:this.id,size:this.size,text:this.text,position:this.position.raw}}};o(Ir,"EdgeLabel");let Nt=Ir;const Fn=class Fn extends y{constructor(e,t){super(Array.isArray(t)?t.slice(0,2):t),this.parent=e,f.makeObservable(this,{manualAxes:f.observable,mode:f.observable}),t instanceof Fn?(this.mode=t.mode,this.manualAxes=t.manualAxes):Array.isArray(t)&&t.length===3?(this.mode=t[2],this.manualAxes=this.mode==="manual"||this.mode==="static"?"both":"none"):Array.isArray(t)&&t.length>=4&&(this.mode=t[2],this.manualAxes=t[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(e){return this.mode==="static"?this:(this.mode="manual",e==="both"||this.manualAxes==="both"?this.manualAxes="both":this.manualAxes==="none"?this.manualAxes=e:this.manualAxes!==e&&(this.manualAxes="both"),this)}hasManualAxis(e){return e==="x"?this.manualX:this.manualY}markStatic(){return this.mode="static",this.manualAxes="both",this}copy(){return new Fn(this.parent,[this.x,this.y,this.mode,this.manualAxes])}toString(e=!1){return e?`(${this.x}, ${this.y}): ${this.mode}/${this.manualAxes}`:super.toString()}};o(Fn,"EdgePoint");let R=Fn,xc=Number.MIN_SAFE_INTEGER;function ao(n){return n==="straight"||n==="curved"?n:"orthogonal"}o(ao,"normalizePathType");function vc(n,e){if(!n)return{mode:"fixed"};const t=n.parent.box,i=n.coordinates.copy().sum(e??new y);return{mode:"fixed",position:new y([(i.x-t.x)/Math.max(t.width,.001),(i.y-t.y)/Math.max(t.height,.001)])}}o(vc,"fixedAnchorForGateway");function Zn(n,e,t){return n?.mode==="automatic"?{mode:"automatic"}:n?.position?{mode:"fixed",position:n.position instanceof y?n.position:new y(n.position)}:vc(e,t)}o(Zn,"normalizeAnchor");function wc(n,e){return n?n.copy(!1).substract(e.relativePosition).norm<.001:!0}o(wc,"isGatewayAnchorPosition");const jr=class jr extends qe{constructor(e,t){super(e),this.state=t,this.state.pathType=ao(this.state.pathType),this.state.startAnchor=Zn(this.state.startAnchor,this.state.from,this.state.displacementStart),this.state.endAnchor=Zn(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(xc++);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(e=>e.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(e){const t=new Nt(this,{position:e},!0);return this.state.labels.push(t),t}removeLabel(e,t=!0){const i=this.state.labels.indexOf(e);i<0||(this.state.labels.splice(i,1),t&&this.emit(new it(this)))}setPrimaryLabel(e){const t=this.state.labels[0];if(!e)return t&&this.removeLabel(t,!1),null;if(t)return t.setText(e),t;const i=new Nt(this,{text:e,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 e=this.steps.slice(0,-1).map((s,r)=>s.distance(this.steps[r+1])),t=e.reduce((s,r)=>s+r,0)/2;let i=0;for(let s=0;s<e.length;s+=1){if(i+e[s]>=t){const r=(t-i)/Math.max(e[s],.001);return this.steps[s].copy().sum(this.steps[s+1].copy().substract(this.steps[s]).multiply(r))}i+=e[s]}return this.steps.at(-1).copy()}collides(e){for(let t=0;t<this.steps.length-1;t++){const i=this.steps[t],s=this.steps[t+1];if(new M([...i.raw,...s.copy().substract(i).raw]).collides(e))return!0}return!1}setState(e,t){this.state[e]=t}setSteps(e){this.state.steps=e.map(t=>t instanceof R?t:new R(this,t)),this.state.steps[0].markStatic(),this.state.steps.at(-1).markStatic()}setPathType(e){this.state.pathType=e,this.diagram&&this.state.to&&this.from.recomputeConnectedEdge(this,"from")}resolveEndpointAnchor(e){const t=e==="from"?this.from:this.to,i=e==="from"?this.startAnchor:this.endAnchor,s=e==="from"?this.state.displacementStart??new y:this.state.displacementEnd??new y;if(!t.parent.edgesAsGateways){const r=t.coordinates.copy().sum(s),a=t.parent.box;return{gateway:t,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 wc(i.position,t)&&s.norm<.001?{gateway:t,point:t.coordinates.copy(),relativePosition:t.relativePosition,displacement:new y}:t.parent.findRelativeConnectionAnchor(i.position??t.relativePosition)}setEndpointAnchor(e,t,i=!0){e==="from"?this.state.startAnchor=t:this.state.endAnchor=t,i&&this.diagram&&this.from.recomputeConnectedEdge(this,e)}setResolvedEndpoint(e,t,i,s=!0){const r=this.resolveEndpointAnchor(e==="from"?"to":"from");e==="from"?(this.state.startAnchor=i,this.applyResolvedAnchors(t,r)):(this.state.endAnchor=i,this.applyResolvedAnchors(r,t)),s&&this.diagram&&this.from.recomputeConnectedEdge(this,e)}applyResolvedAnchors(e,t){const i=this.state.from,s=this.state.to,r=i?.outgoingEdges.includes(this)??!1,a=s?.incomingEdges.includes(this)??!1;i!==e.gateway&&(r&&i.removeOutgoingEdge(this),this.state.from=e.gateway,r&&e.gateway.addOutgoingEdge(this,!1)),s!==t.gateway&&(a&&s.removeIncomingEdge(this),this.state.to=t.gateway,a&&t.gateway.addIncomingEdge(this,!1)),this.state.displacementStart=e.displacement,this.state.displacementEnd=t.displacement}get to(){return this.state.to}deserialize(e){if(!Array.isArray(e.labels))throw new TypeError("Invalid serialized edge: 'labels' must be an array.");this.state.arrowHeadEnd=e.arrowHeadEnd,this.state.arrowHeadStart=e.arrowHeadStart,this.state.lineStyle=e.lineStyle,this.state.pathType=ao(e.pathType),this.state.stroke=e.stroke,this.state.strokeWidth=e.strokeWidth,this.state.labels=e.labels.map(t=>new Nt(this,{alignment:t.alignment,id:t.id,text:t.text,position:new y(t.position),size:t.size})),this.state.displacementEnd=e.displacementEnd?new y(e.displacementEnd):void 0,this.state.displacementStart=e.displacementStart?new y(e.displacementStart):void 0,this.state.steps=e.steps.map(t=>new R(this,t)),this.state.to=this.state.from.diagram.getNodeById(e.toParentId).getGateway(e.to),this.state.startAnchor=Zn(e.startAnchor,this.state.from,this.state.displacementStart),this.state.endAnchor=Zn(e.endAnchor,this.state.to,this.state.displacementEnd),this.state.from.diagram.addEdge(this)}serialize(){const{arrowHeadEnd:e,arrowHeadStart:t,lineStyle:i,pathType:s,startAnchor:r,endAnchor:a,steps:l,stroke:c,strokeWidth:h,to:{id:u,parent:{id:p}}}=this;return{arrowHeadEnd:e,arrowHeadStart:t,displacementEnd:this.state.displacementEnd?.raw,displacementStart:this.state.displacementStart?.raw,lineStyle:i,labels:this.state.labels.map(g=>g.serialize()),pathType:s,startAnchor:{mode:r.mode,position:r.position?.raw},endAnchor:{mode:a.mode,position:a.position?.raw},steps:l.map(g=>[...g.raw,g.mode,g.manualAxes]),stroke:c,strokeWidth:h,to:u,toParentId:p,class:this.constructor.name}}dragStart(e,t){t.button===0&&this.pathType==="orthogonal"&&(t.nativeEvent.stopImmediatePropagation(),this.emit(new rn(this,e,t)))}dragEndpoint(e,t){t.button===0&&(t.nativeEvent.stopImmediatePropagation(),this.emit(new an(this,e,t)))}};o(jr,"Edge");let Re=jr;const Pr=class Pr{_data=new Set;constructor(){f.makeAutoObservable(this)}add(...e){for(const t of e)this._data.add(t)}delete(e){this._data.delete(e)}toggle(e){this._data.has(e)?this.delete(e):this.add(e)}get string(){return[...this._data].join(" ")}};o(Pr,"ClassList");let Bi=Pr;const Nr=class Nr{route(e,t){const i=t.from.parent.edgesAsGateways&&t.startAnchor.mode==="automatic"?this.findAutomaticStartPoint(t):t.resolveEndpointAnchor("from"),s=t.to.parent.edgesAsGateways&&t.endAnchor.mode==="automatic"?this.findAutomaticEndPoint(t):t.resolveEndpointAnchor("to");return t.applyResolvedAnchors(i,s),this.findRoute(e,t,i,s)}};o(Nr,"EdgesRouter");let cn=Nr;const Tr=class Tr extends cn{findAutomaticStartPoint(e){return e.from.parent.findAutomaticGatewayAnchor(e.to.parent.box.middle)}findAutomaticEndPoint(e){return e.to.parent.findAutomaticGatewayAnchor(e.from.parent.box.middle)}findRoute(e,t,i,s){return[i.point,s.point]}};o(Tr,"CurvedRouter");let Ri=Tr;const G=.001,Ec=3;function U(n,e,t=Ec){return Math.abs(n-e)<=t}o(U,"almostEqual");function Kn(n,e){return Math.abs(n-e)<=G}o(Kn,"strictlyEqual");function st(n,e){return U(n.x,e.x)&&U(n.y,e.y)}o(st,"samePoint");function ue(n,e){return U(n.x,e.x)||U(n.y,e.y)}o(ue,"axisAligned");function _c(n,e){return Kn(n.x,e.x)&&Kn(n.y,e.y)}o(_c,"strictlySamePoint");function Gi(n,e){return Kn(n.x,e.x)||Kn(n.y,e.y)}o(Gi,"strictlyAxisAligned");function Te(n,e){return st(n,e)||!ue(n,e)?null:U(n.y,e.y)?"horizontal":"vertical"}o(Te,"segmentDirection");function Vi(n,e,t){if(U(n.x,e.x)&&U(e.x,t.x)||U(n.y,e.y)&&U(e.y,t.y))return!0;const i=(e.x-n.x)*(t.y-e.y)-(e.y-n.y)*(t.x-e.x);return Math.abs(i)<G}o(Vi,"collinear");function kc(n){return n instanceof R?n.mode:"auto"}o(kc,"pointMode");function ie(n,e){return new y([n,e],!1)}o(ie,"rawPoint");function oo(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(oo,"vectorFor");function Tt(n,e){const t=oo(e);return n.x*t.x+n.y*t.y}o(Tt,"dot");function Sc(n,e,t=kc(e)){return e instanceof R?(e.mode=t,e):new R(n,[e.x,e.y,t])}o(Sc,"asEdgePoint");function ke(n,e,t,i="auto"){return new R(n,[e,t,i])}o(ke,"makePoint");function lo(n){return n.getExtension(B)?.gridSize??50}o(lo,"getGridSize");function dn(n,e){const t=n.parent.state.box,i=n.state.position;return ie(t.x+i.x*t.width+(e?.x??0),t.y+i.y*t.height+(e?.y??0))}o(dn,"endpointPoint");function ye(n,e){const t=n.parent.state.box;return new M([t.x-e,t.y-e,t.width+e*2,t.height+e*2],!1)}o(ye,"routingBox");function co(n,e,t){return n>=e-G&&n<=t+G}o(co,"coordinateWithinSpan");function Mc(n,e,t,i){let s=Number.POSITIVE_INFINITY;for(const r of t){if(e==="right"||e==="left"){if(!co(n.y,r.y-i,r.y+r.height+i))continue;const l=e==="right"?r.x-n.x:n.x-(r.x+r.width);l>G&&l<s&&(s=l);continue}if(!co(n.x,r.x-i,r.x+r.width+i))continue;const a=e==="down"?r.y-n.y:n.y-(r.y+r.height);a>G&&a<s&&(s=a)}return Number.isFinite(s)?s:null}o(Mc,"blockingDistance");function Un(n,e,t,i,s){const r=Mc(e,t,s,i),a=r!==null&&r<i*2?r/2:i,l=oo(t);return ke(n,e.x+l.x*a,e.y+l.y*a)}o(Un,"adaptiveLeadPoint");function Ac(n,e,t,i,s){if(i.orientation==="right"&&s.orientation==="left"&&t.x>e.x||i.orientation==="left"&&s.orientation==="right"&&t.x<e.x){const r=(e.x+t.x)/2;return[ke(n,r,e.y),ke(n,r,t.y)]}if(i.orientation==="down"&&s.orientation==="up"&&t.y>e.y||i.orientation==="up"&&s.orientation==="down"&&t.y<e.y){const r=(e.y+t.y)/2;return[ke(n,e.x,r),ke(n,t.x,r)]}return null}o(Ac,"facingLeadPoints");function Cc(n,e,t,i){if(!Gi(n,e)||_c(n,e))return!1;const s={x:e.x-n.x,y:e.y-n.y};return Tt(s,t)>G&&Tt(s,i)<-G}o(Cc,"directRouteIsValid");function ho(n){const e=[],t=new Set;for(const i of n){const s=i.toFixed(3);t.has(s)||(t.add(s),e.push(i))}return e}o(ho,"uniqueNumbers");function Ic(n){const e=[];for(const t of n){const i=e.at(-1);i&&st(i,t)||e.push(t)}return e}o(Ic,"compactRawPoints");function uo(n,e,t){if(!ue(n,e))return 1;if(U(n.x,e.x)){const c=n.x,h=Math.min(n.y,e.y),u=Math.max(n.y,e.y),p=c>t.x+G&&c<t.x+t.width-G,g=u>t.y+G&&h<t.y+t.height-G;return p&&g?1:0}const i=n.y,s=Math.min(n.x,e.x),r=Math.max(n.x,e.x),a=i>t.y+G&&i<t.y+t.height-G,l=r>t.x+G&&s<t.x+t.width-G;return a&&l?1:0}o(uo,"segmentCollisionPenalty");function jc(n,e,t){if(!ue(n,e))return 1;if(U(n.x,e.x)){const c=n.x,h=Math.min(n.y,e.y),u=Math.max(n.y,e.y),p=U(c,t.x)||U(c,t.x+t.width),g=Math.min(u,t.y+t.height)-Math.max(h,t.y);return p&&g>G?1:0}const i=n.y,s=Math.min(n.x,e.x),r=Math.max(n.x,e.x),a=U(i,t.y)||U(i,t.y+t.height),l=Math.min(r,t.x+t.width)-Math.max(s,t.x);return a&&l>G?1:0}o(jc,"segmentBorderOverlapPenalty");function Pc(n,e,t={}){let i=0,s=0,r=0,a=0,l=0,c=t.incomingDirection??null;for(let h=0;h<n.length-1;h++){const u=n[h],p=n[h+1];if(!ue(u,p))return null;const g=Te(u,p);if(h===0&&t.avoidFirstDirection&&g===t.avoidFirstDirection&&(r+=1),h===0&&t.avoidFirstBacktrack){const m={x:p.x-u.x,y:p.y-u.y};if(Tt(m,t.avoidFirstBacktrack)<-G)return null}if(h===n.length-2&&t.avoidLastDirection&&g===t.avoidLastDirection&&(r+=1),h===n.length-2&&t.avoidLastBacktrack){const m={x:u.x-p.x,y:u.y-p.y};if(Tt(m,t.avoidLastBacktrack)<-G)return null}l+=Math.abs(u.x-p.x)+Math.abs(u.y-p.y),c&&g&&c!==g&&(a+=1),c=g;for(const m of e.obstacleBoxes)i+=uo(u,p,m),s+=jc(u,p,m)}return c&&t.outgoingDirection&&c!==t.outgoingDirection&&(a+=1),[i,s,r,a,l,n.length]}o(Pc,"routeScore");function Nc(n,e){if(!e)return!0;for(let t=0;t<n.length;t+=1)if(n[t]!==e[t])return n[t]<e[t];return!1}o(Nc,"routeScoreIsBetter");function qn(n,e,t){return t.obstacleBoxes.some(i=>uo(n,e,i)>0)}o(qn,"segmentHitsAnyBox");function go(n,e,t){return Gi(n,e)&&!qn(n,e,t)}o(go,"canCollapseToSegment");function Xn(n,e,t,i={}){if(st(n,e))return[n];let s=null,r=null;const a=o(h=>{const u=Ic(h),p=Pc(u,t,i);p&&Nc(p,r)&&(s=u,r=p)},"push");ue(n,e)&&a([n,e]),a([n,ie(e.x,n.y),e]),a([n,ie(n.x,e.y),e]);const l=ho([n.x,e.x,(n.x+e.x)/2,...t.laneBoxes.flatMap(h=>[h.x,h.x-t.gridSize,h.x+h.width,h.x+h.width+t.gridSize])]),c=ho([n.y,e.y,(n.y+e.y)/2,...t.laneBoxes.flatMap(h=>[h.y,h.y-t.gridSize,h.y+h.height,h.y+h.height+t.gridSize])]);for(const h of l)a([n,ie(h,n.y),ie(h,e.y),e]);for(const h of c)a([n,ie(n.x,h),ie(e.x,h),e]);for(const h of l)for(const u of c)a([n,ie(h,n.y),ie(h,u),ie(e.x,u),e]),a([n,ie(n.x,u),ie(h,u),ie(h,e.y),e]);return s??[n,e]}o(Xn,"routeBridge");function Tc(n){const e=[];for(let t=0;t<n.length;t++){const i=n[t],s=n[t+1];if(i.manualAxes==="x"){const r=s?.manualAxes==="x"&&U(i.x,s.x)?[i,s]:[i];e.push({type:"line",direction:"vertical",coordinate:i.x,points:r}),t+=r.length-1;continue}if(i.manualAxes==="y"){const r=s?.manualAxes==="y"&&U(i.y,s.y)?[i,s]:[i];e.push({type:"line",direction:"horizontal",coordinate:i.y,points:r}),t+=r.length-1;continue}e.push({type:"point",point:i})}return e}o(Tc,"manualRouteConstraints");function Dc(n,e){return n?n.type==="point"?n.point:n.direction==="vertical"?ie(n.coordinate,e.y):ie(e.x,n.coordinate):e}o(Dc,"constraintReferencePoint");function po(n,e,t){return n>e+G&&n<t-G}o(po,"valueInside");function Jn(n,e,t,i,s,r){let a=t;const l=n==="x"?"y":"x",c=r.gridSize/2;for(const h of r.obstacleBoxes){const u=l==="x"?h.x:h.y,p=l==="x"?h.x+h.width:h.y+h.height,g=n==="x"?h.x:h.y,m=n==="x"?h.x+h.width:h.y+h.height;if(!po(e,u,p)||!po(a,g,m))continue;const x=s!==void 0?s-a:0,b=i-a,v=(g+m)/2;a=(Math.abs(x)>G?Math.sign(x):Math.abs(b)>G?Math.sign(b):a<v?-1:1)<0?g-c:m+c}return a}o(Jn,"safeLineEndpointCoordinate");function Lc(n,e,t,i,s){const r=n.points[0],a=n.points.at(-1),l=r?.copy()??ke(i,0,0),c=a?.copy()??ke(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=e.y,c.x=n.coordinate,c.y=t.y,s&&(l.y=Jn("y",n.coordinate,l.y,t.y,r?.y,s),c.y=Jn("y",n.coordinate,c.y,e.y,a?.y,s))):(l.addManualAxis("y"),c.addManualAxis("y"),l.x=e.x,l.y=n.coordinate,c.x=t.x,c.y=n.coordinate,s&&(l.x=Jn("x",n.coordinate,l.x,t.x,r?.x,s),c.x=Jn("x",n.coordinate,c.x,e.x,a?.x,s))),[l,c]}o(Lc,"lineConstraintEndpoints");function Oc(n,e){const t=new Map;return{copies:n.map(s=>{const r=s.copy();return r.parent=e,t.set(s,r),r}),copiesByOriginal:t}}o(Oc,"copyRouteManualPoints");function zc(n,e,t){const i=e.get(n);if(i)return i;const s=n.copy();return s.parent=t,s}o(zc,"routePointCopy");function Fc(n,e){return n.find(t=>t.mode==="static")??n.find(t=>e.has(t)&&t.mode==="manual")??n.find(t=>e.has(t))??n.find(t=>t.mode==="manual")??n[0]}o(Fc,"pickPointFromDuplicateRun");function Wi(n,e){const t=[];for(let i=0;i<n.length;){let s=i+1;for(;s<n.length&&st(n[i],n[s]);)s+=1;t.push(Fc(n.slice(i,s),e)),i=s}return t}o(Wi,"removeAdjacentDuplicates");function fo(n,e,t,i){return n.mode==="static"?n[t]:e.mode==="static"?e[t]:i.has(n)?n[t]:i.has(e)?e[t]:n[t]}o(fo,"coordinateAnchor");function hn(n,e){for(let t=0;t<n.length-1;t++){const i=n[t],s=n[t+1];if(U(i.x,s.x)){const r=fo(i,s,"x",e);i.x=r,s.x=r}if(U(i.y,s.y)){const r=fo(i,s,"y",e);i.y=r,s.y=r}}return n}o(hn,"snapNearlyAlignedPairs");function mo(n,e,t){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=Vi(i[r-1],a,i[r+1]),c=a.mode==="manual"&&e.has(a)&&s>t;if(a.mode==="manual"&&l&&s<=t){const h=i[r+1];if(r+2<i.length&&h.mode==="auto"&&!e.has(h)){i.splice(r+1,1);continue}const u=i[r-1];if(r-2>=0&&u.mode==="auto"&&!e.has(u)){i.splice(r-1,1),r=Math.max(1,r-1);continue}}if(a.mode==="static"||e.has(a)&&!c||!l){r+=1;continue}if(a.mode==="manual"&&s<=t){r+=1;continue}a.mode==="manual"&&(s-=1),i.splice(r,1)}return i}o(mo,"removeRedundantCollinearPoints");function Yi(n,e,t){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(!(ue(r,a)&&ue(a,l)&&ue(l,c))||!go(r,c,e)){s+=1;continue}if(a.mode!=="auto"||l.mode!=="auto"||t.has(a)||t.has(l)){s+=1;continue}i.splice(s+1,2)}return i}o(Yi,"collapseAutoDetours");function yo(n,e,t){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"&&!t.has(l)&&!t.has(c)&&ue(a,l)&&ue(l,c)&&ue(c,h)&&go(a,h,e)){i.splice(r+1,2),s=!0;break}}}return i}o(yo,"collapseAnyAutoRectangles");function $c(n,e,t,i){const s=new R(null,[e.x,n.y,"auto"]),r=new R(null,[n.x,e.y,"auto"]),a=o(l=>{let c=0;return t&&ue(t,l)&&(c+=1),i&&ue(l,i)&&(c+=1),n.mode==="manual"&&t&&Te(t,n)===Te(n,l)&&(c-=2),e.mode==="manual"&&i&&Te(l,e)===Te(e,i)&&(c-=2),c},"score");return a(s)>=a(r)?s:r}o($c,"chooseCorner");function Zi(n,e){if(n.length<2)return n;const t=[n[0]];for(let i=1;i<n.length;i++){const s=t.at(-1),r=n[i];if(!Gi(s,r)){const a=t.length>=2?t[t.length-2]:void 0,l=i+1<n.length?n[i+1]:void 0,c=$c(s,r,a,l);c.parent=e,t.push(c)}t.push(r)}return t}o(Zi,"ensureOrthogonalAdjacency");function bo(n,e,t=new Set){let i=n.map(r=>Sc(e.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=hn(i,t),i=Zi(i,e.parent),i=hn(i,t),i=Wi(i,t),i=mo(i,t,s),i=Yi(i,e,t),i.length===a)break}return i=hn(i,t),i=Zi(i,e.parent),i=Wi(i,t),i=Yi(i,e,t),i=yo(i,e,t),i=mo(i,t,s),i.length>0&&(i[0].markStatic(),i.at(-1).markStatic()),i}o(bo,"normalizeEdgePoints");function xo(n,e){const t=n.findIndex((i,s)=>s>0&&s<n.length-1&&st(i,e));t>=0&&n.splice(t,1)}o(xo,"removeSameCoordinateInteriorPoint");function vo(n,e,t,i){let s=[...n];if(s.length<2)return s;st(s[1],t)?s[1]=t:(xo(s,t),s.splice(1,0,t));const r=s.length-2;if(r<1)return s;st(s[r],i)?s[r]=i:(xo(s,i),s.splice(s.length-1,0,i));const a=new Set([t,i]);return s=hn(s,a),s=Zi(s,e.parent),s=hn(s,a),s=Wi(s,a),s=Yi(s,e,a),s=yo(s,e,a),s.length>0&&(s[0].markStatic(),s.at(-1).markStatic()),s}o(vo,"ensureEndpointLeadPresence");function Hc(n,e,t,i,s){if(!t||!Vi(n,e,t))return!1;const r={x:t.x-n.x,y:t.y-n.y};return Tt(r,i)>G&&!qn(n,t,s)}o(Hc,"canRemoveSourceLead");function Bc(n,e,t,i,s){if(!n||!Vi(n,e,t))return!1;const r={x:t.x-n.x,y:t.y-n.y};return Tt(r,i)<-G&&!qn(n,t,s)}o(Bc,"canRemoveTargetLead");function wo(n,e,t,i){const s=[...n];return s.length>2&&Hc(s[0],s[1],s[2],e,i)&&s.splice(1,1),s.length>2&&Bc(s.at(-3),s.at(-2),s.at(-1),t,i)&&s.splice(s.length-2,1),s.length>0&&(s[0].markStatic(),s.at(-1).markStatic()),s}o(wo,"compactRedundantEndpointLeads");function Ki(n,e,t,i,s){const r=ke(s.parent,dn(n,t).x,dn(n,t).y,"static"),a=dn(e,i),l=ke(s.parent,a.x,a.y,"static");if(Cc(r,l,n.orientation,e.orientation))return[r,l];const c=Ac(s.parent,r,l,n,e),h=c?.[0]??Un(s.parent,r,n.orientation,s.gridSize,[ye(e,0)]),u=c?.[1]??Un(s.parent,l,e.orientation,s.gridSize,[ye(n,0)]),p=new Set([h,u]),g=Xn(h,u,s,{avoidFirstBacktrack:n.orientation,avoidLastBacktrack:e.orientation,incomingDirection:Te(r,h)??void 0,outgoingDirection:Te(u,l)??void 0}),m=bo([r,...g,l],s,p);return wo(vo(m,s,h,u),n.orientation,e.orientation,s)}o(Ki,"routeAuto");function Rc(n,e,t,i,s,r=null){const a=lo(n),l={gridSize:a,obstacleBoxes:[ye(e,0),ye(t,0)],laneBoxes:[ye(e,a/2),ye(t,a/2)],parent:r};return Ki(e,t,i,s,l)}o(Rc,"routeOrthogonalBetweenGateways");function Gc(n,e,t=[],i){const s=lo(n),r={gridSize:s,obstacleBoxes:[ye(e.from,0),ye(e.to,0)],laneBoxes:[ye(e.from,s/2),ye(e.to,s/2)],parent:e},a=e.steps.filter((T,V)=>V>0&&V<e.steps.length-1&&T.mode==="manual");if(a.length===0)return Ki(e.from,e.to,e.state.displacementStart,e.state.displacementEnd,r);const l=dn(e.from,e.state.displacementStart),c=dn(e.to,e.state.displacementEnd),h=ke(r.parent,l.x,l.y,"static"),u=ke(r.parent,c.x,c.y,"static"),p=Un(r.parent,h,e.from.orientation,s,[ye(e.to,0)]),g=Un(r.parent,u,e.to.orientation,s,[ye(e.from,0)]),{copies:m,copiesByOriginal:x}=Oc(a,r.parent),b=t.map(T=>zc(T,x,r.parent)),v=new Set([p,g,...b]),w=Tc(m),_=[h,p];let k=p;for(let T=0;T<w.length;T++){const V=w[T],X=k instanceof R&&k.mode==="manual"?Te(_.at(-2),k)??void 0:void 0;if(V.type==="point"){const to=Xn(k,V.point,r,{avoidFirstDirection:X,avoidFirstBacktrack:T===0?e.from.orientation:void 0});_.push(...to.slice(1)),k=V.point;continue}const K=Dc(w[T+1],g);let[he,Ke]=Lc(V,k,K,r.parent,r);if(qn(he,Ke,r))continue;const Oi=Xn(k,he,r,{avoidFirstDirection:X,avoidFirstBacktrack:T===0?e.from.orientation:void 0});_.push(...Oi.slice(1),Ke),k=Ke}const C=k instanceof R&&k.mode==="manual"?Te(_.at(-2),k)??void 0:void 0,P=Xn(k,g,r,{avoidFirstDirection:C,avoidLastDirection:Te(g,u)??void 0,avoidLastBacktrack:e.to.orientation});_.push(...P.slice(1),u);const D=bo(_,r,v),N=wo(vo(D,r,p,g),e.from.orientation,e.to.orientation,r);return N.some(T=>T.mode==="manual")?N:Ki(e.from,e.to,e.state.displacementStart,e.state.displacementEnd,r)}o(Gc,"routeOrthogonalEdge");const Dr=class Dr extends cn{findAutomaticStartPoint(e){return e.from.parent.findAutomaticGatewayAnchor(e.to.parent.box.middle)}findAutomaticEndPoint(e){return e.to.parent.findAutomaticGatewayAnchor(e.from.parent.box.middle)}findRoute(e,t,i,s){return Gc(e,t)}findRouteBetween(e,t,i,s=new y,r=new y){return Rc(e,t,i,s,r)}};o(Dr,"OrthogonalRouter");let Qn=Dr;const Lr=class Lr extends cn{findAutomaticStartPoint(e){return e.from.parent.findAutomaticConnectionAnchor(e.to.parent.box.middle)}findAutomaticEndPoint(e){return e.to.parent.findAutomaticConnectionAnchor(e.from.parent.box.middle)}findRoute(e,t,i,s){return[i.point,s.point]}};o(Lr,"StraightRouter");let Ui=Lr;const Vc={orthogonal:new Qn,straight:new Ui,curved:new Ri};function Eo(n){return Vc[n]}o(Eo,"getEdgesRouter");const Or=class Or extends qe{state;constructor(e,t){super(e),this.state={allowDisplace:!0,stroke:"transparent",strokeWidth:10,radius:5,incomingEdges:[],outgoingEdges:[],position:new y,...t},f.makeObservable(this,{addIncomingEdge:f.action,addOutgoingEdge:f.action,state:f.observable,removeIncomingEdge:f.action,removeOutgoingEdge:f.action})}addIncomingEdge(e,t=!0){this.state.incomingEdges.find(i=>i.id===e.id)||this.state.incomingEdges.push(e)}addOutgoingEdge(e,t=!0){this.state.outgoingEdges.find(i=>i.id===e.id)||(this.state.outgoingEdges.push(e),t&&e.steps.length===0&&this.updateEdges())}canConnect(e,t){const i=this.state.incomingEdges.filter(s=>s!==t);return(this.state.maxIncomingConnections===void 0||this.state.maxIncomingConnections>i.length)&&!i.find(s=>s.from===e)}canStartConnection(e,t){const i=this.state.outgoingEdges.filter(s=>s!==t);return(this.state.maxOutgoingConnections===void 0||this.state.maxOutgoingConnections>i.length)&&!i.find(s=>s.to===e)}connectionDisplacement(e){return this.direction==="horizontal"&&Math.abs(e.y-this.coordinates.y)>10?new y([0,e.y-this.coordinates.y]):this.direction==="vertical"&&Math.abs(e.x-this.coordinates.x)>10?new y([e.x-this.coordinates.x,0]):new y([0,0])}connectionDistance(e){if(this.direction==="vertical"){const i=Math.abs(this.coordinates.y-e.y);return i<20?Math.abs(this.coordinates.x-e.x)+i**5:1/0}const t=Math.abs(this.coordinates.x-e.x);return t<20?Math.abs(this.coordinates.y-e.y)+t**5:1/0}removeIncomingEdge(e){for(let t=this.state.incomingEdges.length-1;t>=0;t--)this.state.incomingEdges[t].id===e.id&&this.state.incomingEdges.splice(t,1)}removeOutgoingEdge(e){for(let t=this.state.outgoingEdges.length-1;t>=0;t--)this.state.outgoingEdges[t].id===e.id&&this.state.outgoingEdges.splice(t,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(e,t){e.setSteps(Eo(e.pathType).route(this.diagram,e))}updateEdges(){for(const e of this.state.incomingEdges)this.recomputeConnectedEdge(e,"to");for(const e of this.state.outgoingEdges)this.recomputeConnectedEdge(e,"from")}get remainingSlots(){return this.state.maxOutgoingConnections-this.state.outgoingEdges.length}deserialize(e){this.state.fill=e.fill,this.state.id=e.id,this.state.orientation=e.orientation,this.state.radius=e.radius,this.state.stroke=e.stroke,this.state.strokeWidth=e.strokeWidth,this.state.position.assign(e.coordinates),e.outEdges.forEach(t=>{const i=this.diagram.getClass(t.class);if(!i)throw new Error(`Unknown edge class '${t.class}' on gateway '${this.id}'.`);const s=new i(this,{from:this});this.diagram.getNodeById(t.toParentId)&&s.deserialize(t)})}serialize(){const{fill:e,id:t,orientation:i,radius:s,stroke:r,strokeWidth:a,state:{position:{raw:l}}}=this,c=this.outgoingEdges.map(h=>h.serialize());return{coordinates:l,fill:e,id:t,orientation:i,radius:s,stroke:r,strokeWidth:a,outEdges:c,class:this.constructor.name}}};o(Or,"Gateway");let Se=Or;const ei=250;let Dt=(Wt=class extends qe{_gateways=new Map;state;classList=new Bi;edgesAsGateways=!1;requiredEdgePathType=null;edgeGatewayShape="rectangle";get selected(){return this.state.selected}get hovered(){return this.diagram?.hoveredNode===this}constructor(e,t){super(e),this.state={...t,box:t.box??new M([0,0,100,80]),hover:!1,zIndex:t.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(e){const t=this.diagram;t&&t!==e&&t.setNodeHover(this,!1),this.parent=e}setState(e,t){if(e==="hover"){this.setHovered(t===!0);return}this.state[e]=t}setHovered(e){this.diagram?.setNodeHover(this,e)}initializeGateways(){this._gateways.set("left",new Se(this,{maxIncomingConnections:1/0,maxOutgoingConnections:1/0,id:"left",orientation:"left",position:new y([0,.5])})),this._gateways.set("right",new Se(this,{maxIncomingConnections:1/0,maxOutgoingConnections:1/0,id:"right",orientation:"right",position:new y([1,.5])})),this._gateways.set("up",new Se(this,{maxIncomingConnections:1/0,maxOutgoingConnections:1/0,id:"up",orientation:"up",position:new y([.5,0])})),this._gateways.set("down",new Se(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(e){this.state.box.sum([...e.raw,0,0])}get id(){return this.state.id}get labelOffset(){const e=this.state.labelOffset;return!Array.isArray(e)||e.length!==2||!Number.isFinite(e[0])||!Number.isFinite(e[1])?new y:new y(e)}setLabelOffset(e){const t=e instanceof y?e:new y(e);this.state.labelOffset=[Math.max(-ei,Math.min(ei,t.x)),Math.max(-ei,Math.min(ei,t.y))]}get gateways(){return[...this._gateways.values()]}dragEventMouseStartPosition=null;dragEventStartPosition=null;getGateway(e){return this._gateways.get(e)}boundaryPoint(e,t){const i=this.box,s=i.middle,r=Math.max(i.width/2,.001),a=Math.max(i.height/2,.001);let l=e.x-s.x,c=e.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(!t||!i.collides(e)){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(e.x-i.x),point:[i.x,e.y]},{value:Math.abs(e.x-(i.x+i.width)),point:[i.x+i.width,e.y]},{value:Math.abs(e.y-i.y),point:[e.x,i.y]},{value:Math.abs(e.y-(i.y+i.height)),point:[e.x,i.y+i.height]}];return new y(h.reduce((u,p)=>p.value<u.value?p:u).point)}anchorForBoundaryPoint(e){const t=this.box,i=t.middle,s=(e.x-i.x)/Math.max(t.width/2,.001),r=(e.y-i.y)/Math.max(t.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([(e.x-t.x)/Math.max(t.width,.001),(e.y-t.y)/Math.max(t.height,.001)]);return{gateway:l,point:e,relativePosition:c,displacement:e.copy().substract(l.coordinates)}}findFixedConnectionAnchor(e){return this.anchorForBoundaryPoint(this.boundaryPoint(e,!0))}findAxisAlignedConnectionAnchor(e,t){const i=this.box,s=i.middle,r=Math.max(i.width/2,.001),a=Math.max(i.height/2,.001),l=t==="horizontal",c=l?(e.y-s.y)/a:(e.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?e.x<=s.x?-1:1:e.y<=s.y?-1:1,p=l?new y([s.x+u*h,e.y]):new y([e.x,s.y+u*h]);return this.anchorForBoundaryPoint(p)}findAutomaticConnectionAnchor(e){return this.anchorForBoundaryPoint(this.boundaryPoint(e,!1))}findAutomaticGatewayAnchor(e){const t=this.gateways.filter(s=>{const r=s.relativePosition;return r.x<=0||r.x>=1||r.y<=0||r.y>=1}),i=(t.length?t:this.gateways).map(s=>({candidate:s,distance:s.coordinates.distance(e)})).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(e)}findRelativeConnectionAnchor(e){const t=this.box,i=new y([t.x+e.x*t.width,t.y+e.y*t.height]);return this.anchorForBoundaryPoint(this.boundaryPoint(i,!0))}usesAutomaticConnectionPoint(e){if(!this.edgesAsGateways||!this.box.collides(e))return!1;const t=this.boundaryPoint(e,!0),i=Math.min(24,Math.min(this.box.width,this.box.height)/4);return e.distance(t)>i}get connectionBoundaryPath(){const e=this.box;if(this.edgeGatewayShape==="ellipse"){const t=e.width/2,i=e.y+e.height/2;return`M ${e.x} ${i} A ${t} ${e.height/2} 0 1 0 ${e.x+e.width} ${i} A ${t} ${e.height/2} 0 1 0 ${e.x} ${i}`}return this.edgeGatewayShape==="diamond"?`M ${e.x+e.width/2} ${e.y} L ${e.x+e.width} ${e.y+e.height/2} L ${e.x+e.width/2} ${e.y+e.height} L ${e.x} ${e.y+e.height/2} Z`:`M ${e.x} ${e.y} H ${e.x+e.width} V ${e.y+e.height} H ${e.x} Z`}setDimentions(e){this.state.box.assignDimensions(e)}updateConnectedEdges(){const e=new Set;for(const t of this._gateways.values())t.incomingEdges.forEach(i=>e.add(i)),t.outgoingEdges.forEach(i=>e.add(i));e.forEach(t=>t.from.recomputeConnectedEdge(t,"from"))}setPosition(e,t){const i=new M(this.state.box.raw,!1);this.state.box.assignCoordinates(e).bound(new M([0,0,...this.diagram.canvas.size.raw],!1)),t?.updateConnectedEdges!==!1&&i.substract(this.state.box).norm&&this.updateConnectedEdges()}deserialize(e){this.state.box.assign(e.box),this.state.id=e.id,this.state.label=e.label,this.state.movable=e.movable,this.state.selectable=e.selectable,this.state.fill=e.fill,this.state.labelFontSize=e.labelFontSize,this.setLabelOffset(e.labelOffset??[0,0]),this.state.stroke=e.stroke,this.state.strokewWidth=e.strokewWidth,e.gateways.forEach(t=>{const i=this._gateways.get(t.id)?.incomingEdges||[],s=this.diagram?.getClass(t.class);if(!s)throw new Error(`Unknown gateway class '${t.class}' on node '${this.id}'.`);const r=new s(this,{id:t.id});this._gateways.set(t.id,r);for(const a of i)a.setState("to",r),r.addIncomingEdge(a)}),e.gateways.forEach(t=>{this._gateways.get(t.id)?.deserialize(t)}),this._gateways.forEach(t=>t.outgoingEdges.forEach(i=>{this.diagram?.connectWithEdge(i.from,i.to,i)}))}serialize(){const{box:{raw:e},id:t,label:i,movable:s,selectable:r,fill:a,labelFontSize:l,labelOffset:c,selected:h,stroke:u,strokewWidth:p}=this.state,g=this.gateways.map(m=>m.serialize());return{box:e,id:t,label:i,movable:s,selectable:r,selected:h,gateways:g,fill:a,labelFontSize:l,labelOffset:c?[...c]:void 0,stroke:u,strokewWidth:p,class:this.constructor.name}}remapSerializedReferences(e,t){return e}RenderOverlay=null;RenderScreen=null},o(Wt,"Node"),Wt);const zr=class zr extends F{selectionMode="element";_selection=new Set;_edgesSelection=new Set;autopan=new _e(this.diagram);pointerPoint=null;endPoint=null;startPoint=null;copy(){const e=[],t=new Map,i=[];for(const s of this._selection){const r=At(this.diagram,"node",i);t.set(s.id,r),i.push(r)}for(const s of this._selection){const r=s.remapSerializedReferences(s.serialize(),t);r.id=t.get(r.id),r.gateways.forEach(a=>{a.outEdges.forEach(l=>{l.toParentId=t.get(l.toParentId)})}),e.push(r)}return JSON.stringify({nodes:e})}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(Pe,this.handleMouseDown.bind(this),this.diagram.priorities.Mouse_Down_Selector),this.diagram.onEvent(tt,e=>{f.runInAction(()=>this._selection.delete(e.node))}),this.diagram.onEvent(nn,e=>{f.runInAction(()=>this._edgesSelection.delete(e.edge))}),f.runInAction(()=>{for(const e of this.diagram.nodes)e.selected&&this._selection.add(e)})}toggleSelectionMode(e=this.selectionMode==="area"?"element":"area"){this.selectionMode=e}get selectedNodes(){return[...this._selection]}get selectedEdges(){return[...this._edgesSelection]}get box(){return!this.startPoint||!this.endPoint?new M:new M([...this.startPoint.raw,...this.endPoint.copy().substract(this.startPoint).raw])}clearSelection(e=()=>!0){for(const t of this._selection)e(t)&&this.unselectNode(t);for(const t of this._edgesSelection)this.unselectEdge(t)}selectEdge(e){this.emit(new sn(e,!0)).cancelled||(e.setState("selected",!0),this._edgesSelection.add(e))}selectNode(e){e.canSelect()&&!this.emit(new kt(e,!0)).cancelled&&(e.setState("selected",!0),this._selection.add(e))}unselectEdge(e){this.emit(new sn(e,!1)).cancelled||(e.setState("selected",!1),e.setState("hover",!1),this._edgesSelection.delete(e))}unselectNode(e){e.canUnselect()&&!this.emit(new kt(e,!1)).cancelled&&(e.setState("selected",!1),this._selection.delete(e))}unbind=o(()=>{},"unbind");handleMouseDown=o(e=>{if(this.unbind(),e.originalEvent.button!==1)if(this.selectionMode==="area"){const t=new y(e.originalEvent);f.runInAction(()=>{this.startPoint=this.diagram.canvas.inverseFit(t)}),e.cancel(),this.unbind=Me(Ge(this,ne,this.handleMouseUp),Ge(this,Ne,this.handleMouseMove),ni(this.handleSelectionInterval.bind(this),30))}else{const t=e.edge,i=e.node,s=t?.state.selected??i?.selected;!e.ctrl&&!e.shift&&!s&&(t||i?this.clearSelection():e.originalEvent.button===0&&this.bindEmptyCanvasGesture(e)),t?this.selectEdge(t):i&&this.selectNode(i)}},"handleMouseDown");bindEmptyCanvasGesture(e){const t=new y(e.originalEvent);let i=!1;const s=o(a=>{i||=!new y(a.originalEvent).equals(t)},"handleMove"),r=o(()=>{const a=this.unbind;this.unbind=()=>{},a(),i||this.clearSelection()},"handleUp");this.unbind=Me(Ge(this,Ne,s),Ge(this,ne,r))}handleMouseMove=o(e=>{f.runInAction(()=>{this.pointerPoint=new y(e.originalEvent)}),this.updateAreaSelection(!1)},"handleMouseMove");handleSelectionInterval(){this.updateAreaSelection(!0)}updateAreaSelection(e){if(!this.pointerPoint||!this.startPoint)return;const t=this.pointerPoint;e&&this.autopan.displace(t),f.runInAction(()=>{this.endPoint=this.diagram.canvas.inverseFit(t)});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(e=>{this.unbind(),this.endPoint=null,this.startPoint=null,this.pointerPoint=null},"handleMouseUp")};o(zr,"Selector");let $=zr;const Fr=class Fr extends F{hotkeys=[];isEditableTarget(e){return e instanceof HTMLElement?e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement||e instanceof HTMLButtonElement||e.isContentEditable:!1}shouldIgnoreHotkeys(e){return this.isEditableTarget(e.originalEvent.target)}get measurer(){return this.diagram.getExtension(jt)}get selector(){return this.diagram.getExtension($)}match(e,t){return!(t.ctrl!==void 0&&e.ctrl!==t.ctrl||t.shift!==void 0&&e.shift!==t.shift||t.alt!==void 0&&e.alt!==t.alt||t.code!==void 0&&e.code!==t.code)}init(){this.diagram.onEvent(Ue,async e=>{if(!this.shouldIgnoreHotkeys(e)&&!this.revertHotkey.has(e.code)){for(const t of this.hotkeys)if(this.match(e,t)&&(t.cb(e),!e.spreads))return;switch(e.code){case"Space":{const t=this.measurer.enabled,i=!t&&this.selector.selectionMode==="area";t||this.selector.toggleSelectionMode(i?"element":"area"),this.revertHotkey.set(e.code,()=>{t?this.measurer.toggle():this.selector.toggleSelectionMode(i?"area":"element")});break}case"KeyC":e.ctrl&&navigator.clipboard.writeText(this.selector.copy());break;case"KeyV":e.ctrl&&this.diagram.rules.allowEdition&&this.diagram.paste(await navigator.clipboard.readText());break;case"KeyM":this.selector.toggleSelectionMode("element");break;case"KeyS":e.ctrl?(e.originalEvent.preventDefault(),yc(this.diagram.export(),"diagram-save.json","application/json")):this.selector.toggleSelectionMode("area");break;case"KeyZ":e.ctrl&&this.diagram.rules.allowEdition&&this.diagram.getExtension(It).undo();break;case"KeyY":e.ctrl&&this.diagram.rules.allowEdition&&this.diagram.getExtension(It).redo();break;case"ControlLeft":case"ControlRight":e.cancel();{const t=this.diagram.getExtension(B),i=this.diagram.getExtension(Be),s=this.diagram.getExtension(Ct),r=t?.enabled,a=i?.enabled,l=s?.enabled;t?.toggle(!r,!1),i?.toggle(!a,!1),s?.toggle(!l,!1),this.revertHotkey.set(e.code,()=>{r!==void 0&&t?.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 t=this.diagram.getExtension($);t.selectedNodes.forEach(i=>{this.diagram.delete(i)}),t.selectedEdges.forEach(i=>{this.diagram.disconnect(i)})}}}}),document.addEventListener("keyup",()=>{for(const e of this.revertHotkey.keys())this.revertHotkey.get(e)?.(),this.revertHotkey.delete(e)})}register(e){return this.hotkeys.push(e),()=>{this.hotkeys=this.hotkeys.filter(t=>t!==e)}}revertHotkey=new Map};o(Fr,"Hotkeys");let ti=Fr;function Ge(n,e,t,i){if(n.diagram){const s=t.bind(n);return n.diagram.onEvent(e,s,i),()=>{n.diagram?.offEvent(e,s)}}throw new Error("Cannot bind to unexistent diagram")}o(Ge,"bindDiagram");function Y(n,e,t,i){const s=t.bind(n);return document.addEventListener(e,s,i),()=>{document.removeEventListener(e,s,i)}}o(Y,"bindDocument");function ni(n,e){const t=setInterval(n,e);return()=>{clearInterval(t)}}o(ni,"bindInterval");function Wc(n,e){const t=setTimeout(n,e);return()=>{clearTimeout(t)}}o(Wc,"bindTimeout");function Me(...n){return()=>{n.forEach(e=>e())}}o(Me,"bind");let _o=(Yt=class extends qe{unbindDocumentEvents=[];detachHandlers=new Set;mouseSessionStartedInFrame=!1;keyboardSessionActive=!1;centerAnimationFrame=null;_displacement=new y([-5e3,-5e3]);_scale=1;gridSize=50;minimumScale=.3;maximumScale=3;wheelSensitivity=5e-4;animatedZoom=!0;zoomFrame=null;zoomTarget=null;zoomDeadline=0;zoomLastFrame=0;zoomCenter=new y;applyingZoomFrame=!1;size=new y([1e6,1e6]);get scale(){return this._scale}element=null;get elementPosition(){if(!this.element)return new y([0,0]);const e=this.element.getBoundingClientRect();return new y([e.x,e.y])}get elementDimensions(){if(!this.element)return new M([0,0,0,0]);const e=this.element.getBoundingClientRect();return new M([e.x,e.y,e.width,e.height])}get displacement(){return this._displacement.copy()}get framePosition(){if(!this.element)return new y([0,0]);const e=this.element.parentElement.getBoundingClientRect();return new y([e.x,e.y])}get frameDimensions(){if(!this.element)return new M([0,0,0,0]);const e=this.element.parentElement.getBoundingClientRect();return new M([e.x,e.y,e.width,e.height])}constructor(e){super(e),f.makeObservable(this,{_scale:f.observable,setScale:f.action,setGridSize: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,"focusin",this.handleFocusIn),Y(this,"keyup",this.handleKeyUp),Y(this,"keypress",this.handleKeyPress),Y(this,"keydown",this.handleKeyDown))}dispose(){this.detachHandlers.forEach(e=>e()),this.detachHandlers.clear(),this.keyboardSessionActive=!1,this.cancelCenterAnimation(),this.cancelZoomAnimation();for(const e of this.unbindDocumentEvents.splice(0))e()}onDetach(e){return this.detachHandlers.add(e),()=>{this.detachHandlers.delete(e)}}markMouseSessionStartedInFrame(){this.mouseSessionStartedInFrame=!0}get dragging(){return this._dragging}_dragging=!1;displacementStart=null;eventStart=null;bound(){const e=this.element?.parentElement?.getBoundingClientRect(),t=e?new y([e.width,e.height]).divide(this.scale):new y,i=new M([...this.size.copy().multiply(-1).raw,...t.raw]).multiply(.9);this._displacement.bound(i)}centerOnPoint(e,t=!1){const i=this.frameDimensions,s=new y([i.width/(2*this.scale)-e.x,i.height/(2*this.scale)-e.y]);if(!t||typeof requestAnimationFrame>"u"){this.setDisplacement(s);return}this.animateDisplacement(s)}ensureVisible(e,t=0,i=!1){const s=this.frameDimensions;if(s.width<=0||s.height<=0)return!1;const r=s.width/this.scale,a=s.height/this.scale,l=this.displacement,c=-l.x,h=-l.y,u=this.visibleOriginForInterval(c,r,e.x,e.width,t),p=this.visibleOriginForInterval(h,a,e.y,e.height,t),g=new y([-u,-p]);return g.copy(!1).substract(l).norm<.001?!1:(i&&typeof requestAnimationFrame<"u"?this.animateDisplacement(g):this.setDisplacement(g),!0)}visibleOriginForInterval(e,t,i,s,r){const a=Math.max(0,r);return s+a*2>t?i+s/2-t/2:i<e+a?i-a:i+s>e+t-a?i+s+a-t:e}animateDisplacement(e){this.cancelCenterAnimation();const t=this.displacement,i=e.copy(!1).substract(t);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(t.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(e){this._displacement.assign(e),this.bound(),this.setDisplacementStyles()}displace(e){this.cancelCenterAnimation(),this._displacement.sum(e);const t=this._displacement.copy();return this.bound(),this.setDisplacementStyles(),e.copy().substract(this._displacement.copy().substract(t))}setDisplacement(e){this.cancelCenterAnimation(),this.applyDisplacement(e)}configureZoom(e){const t=e.minimumScale??this.minimumScale,i=e.maximumScale??this.maximumScale,s=e.wheelSensitivity??this.wheelSensitivity;if(![t,i,s].every(Number.isFinite)||t<=0||i<t||s<=0)throw new Error("Invalid zoom limits or sensitivity.");this.minimumScale=t,this.maximumScale=i,this.wheelSensitivity=s,this.animatedZoom=e.animated??this.animatedZoom,this.setScale(this.scale)}clampScale(e){return Math.max(this.minimumScale,Math.min(this.maximumScale,e))}getCamera(){return{x:this.displacement.x,y:this.displacement.y,scale:this.scale}}restoreCamera(e){if(![e.x,e.y,e.scale].every(Number.isFinite))throw new Error("Invalid camera snapshot.");this.setScale(e.scale),this.setDisplacement(new y([e.x,e.y]))}setScale(e,t=new y([0,0])){this.cancelCenterAnimation(),this.applyingZoomFrame||this.cancelZoomAnimation();const i=this.inverseFit(t),s=i.copy(),r=this.displacement,a=this.clampScale(e);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 vt(this,l.copy().substract(this.displacement),a,this.scale)).cancelled||(this._scale=a,this._displacement.assign(l),this.bound(),this.setDisplacementStyles())}}fit(e){return e instanceof y?this._displacement.copy().sum([e.x,e.y]).multiply(this.scale):e instanceof M?new M([...this._displacement.copy().sum([e.x,e.y]).multiply(this.scale).raw,...e.size.multiply(this.scale).raw]):e*this.scale}inverseFit(e){return e instanceof y?e.copy().substract(this.framePosition).divide(this.scale).substract([this._displacement.x,this._displacement.y]):e.copy().substract(this.framePosition.toDimensions(new y([0,0]))).divide(this.scale).substract([this._displacement.x,this._displacement.y,0,0])}getDisplacementStyles(){const e=this._displacement.copy(!1).multiply(this.scale);return{position:"relative",width:`${this.size.x}px`,height:`${this.size.y}px`,transform:`translate(${e.x}px, ${e.y}px) scale(${this.scale})`,transformOrigin:"0 0",willChange:"transform"}}setDisplacementStyles(e=this.element){if(e){const t=this._displacement.copy(!1).multiply(this.scale),i=e.parentElement;if(e.dataset.setStyles="true",e.style.position="relative",e.style.width=`${this.size.x}px`,e.style.height=`${this.size.y}px`,e.style.transform=`translate(${t.x}px, ${t.y}px) scale(${this.scale})`,e.style.transformOrigin="0 0",e.style.zoom="",e.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",`${t.x}px`),i.style.setProperty("--diagram-canvas-translate-y",`${t.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",`${t.x}px`),i.style.setProperty("--diagram-grid-offset-y",`${t.y}px`)}}}setGridSize(e){this.gridSize=e,this.setDisplacementStyles()}useRef=o(e=>{this.element=e,e||(this.cancelZoomAnimation(),this.detachHandlers.forEach(t=>t()),this.keyboardSessionActive=!1),e instanceof HTMLElement&&this.setDisplacementStyles()},"useRef");isInsideFrameFromTarget(e){const t=this.element?.parentElement;return!!(t&&e instanceof Node&&(t===e||t.contains(e)))}isInsideFrameEvent(e){const t=this.element?.parentElement;if(!t||e.target instanceof globalThis.Element&&e.target.closest('.diagram__extension_ui, [data-diagram-interactive-ui="true"]'))return!1;const i=typeof e.composedPath=="function"?e.composedPath():[];if(i.length>0&&i.some(s=>s===t||s instanceof Node&&t.contains(s))||this.isInsideFrameFromTarget(e.target)||e.type==="wheel"&&t.matches(":hover"))return!0;if("clientX"in e&&"clientY"in e){const s=t.getBoundingClientRect(),r=Number(e.clientX),a=Number(e.clientY);return r>=s.left&&r<=s.right&&a>=s.top&&a<=s.bottom}return!1}handleMouseMove(e){if(!this.isInsideFrameEvent(e)&&!this.eventStart&&!this.mouseSessionStartedInFrame)return;if(!this.emit(new Ne(this,e)).cancelled&&this.displacementStart&&this.eventStart){const i=this.displacement.substract(new y(e));this.emit(new Gn(this,this.displacement,i)).cancelled||(this._dragging=!0,this._displacement.assign(this.displacementStart.copy().substract(this.eventStart.copy().substract([e.clientX,e.clientY]).divide(this.scale))),this.bound(),this.setDisplacementStyles())}}handleDoubleClick(e){this.isInsideFrameEvent(e)&&this.emit(new tn(this,e))}handleClick(e){this.isInsideFrameEvent(e)&&this.emit(new en(this,e))}handleMouseUp(e){!this.isInsideFrameEvent(e)&&!this.eventStart&&!this.mouseSessionStartedInFrame||(this.emit(new ne(this,e)),this._dragging=!1,this.eventStart=null,this.mouseSessionStartedInFrame=!1)}handleMouseDown(e){const t=this.isInsideFrameEvent(e);if(this.keyboardSessionActive=t,!t)return;if(this.mouseSessionStartedInFrame=!0,this.cancelCenterAnimation(),e.button===1){e.preventDefault(),this.displacementStart=this._displacement.copy(),this.eventStart=new y(e);return}!this.emit(new Pe(this,e)).cancelled&&e.button===0&&(this.displacementStart=this._displacement.copy(),this.eventStart=new y(e))}handleFocusIn(e){this.isInsideFrameFromTarget(e.target)||(this.keyboardSessionActive=!1)}handleKeyDown(e){this.keyboardSessionActive&&this.emit(new Ue(this,e))}handleKeyUp(e){this.keyboardSessionActive&&this.emit(new bt(this,e))}handleKeyPress(e){this.keyboardSessionActive&&this.emit(new Rn(this,e))}cancelZoomAnimation(){this.zoomFrame!==null&&cancelAnimationFrame(this.zoomFrame),this.zoomFrame=null,this.zoomTarget=null}animateWheelZoom(e,t){if(!this.animatedZoom||typeof requestAnimationFrame>"u"){this.setScale(e,t);return}const i=performance.now();this.zoomTarget!==null&&this.applyWheelZoom(i),this.zoomTarget=e,this.zoomCenter=t,this.zoomDeadline=i+200,this.zoomFrame===null&&(this.zoomLastFrame=i,this.zoomFrame=requestAnimationFrame(this.advanceWheelZoom))}advanceWheelZoom=o(e=>{if(this.zoomTarget===null)return;this.applyWheelZoom(e)<1?this.zoomFrame=requestAnimationFrame(this.advanceWheelZoom):(this.zoomFrame=null,this.zoomTarget=null)},"advanceWheelZoom");applyWheelZoom(e){const t=this.zoomDeadline-this.zoomLastFrame,i=t<=0?1:Math.min(1,Math.max(0,(e-this.zoomLastFrame)/t));this.applyingZoomFrame=!0;try{this.setScale(this.scale+(this.zoomTarget-this.scale)*i,this.zoomCenter)}finally{this.applyingZoomFrame=!1}return this.zoomLastFrame=e,i}handleWheel(e){if(!this.isInsideFrameEvent(e))return;if(!this.emit(new Bn(this,e)).cancelled){const i=e.deltaMode===1?16:e.deltaMode===2?this.frameDimensions.height:1,s=this.clampScale((this.zoomTarget??this.scale)-e.deltaY*i*this.wheelSensitivity);this.animateWheelZoom(s,new y(e))}}},o(Yt,"Canvas"),Yt);const $r=class $r extends Dt{initializeGateways(){}};o($r,"TextNode");let ii=$r;const Hr=class Hr extends F{creationMode="none";init(){this.diagram.onEvent(en,e=>{this.handleClick(e)}),f.makeObservable(this,{creationMode:f.observable})}getId(){let e=String(Date.now()),t=0;for(;this.diagram.getNodeById(e);)e=String(Date.now())+String(t++);return e}handleClick(e){if(!e.cancelled&&this.creationMode!=="none"&&(e.cancel(),this.creationMode==="text")){const t=this.diagram.add(new ii(null,{id:this.getId(),label:"No label",box:new M([...this.diagram.canvas.inverseFit(new y(e.originalEvent)).raw,100,100])}));this.diagram.getExtension($).selectNode(t)}f.runInAction(()=>{this.creationMode="none"})}};o(Hr,"Creator");let si=Hr;const Br=class Br extends F{dragThreshold=10;autopan=new _e(this.diagram);autopanReady=!0;dragStarted=!1;draggingLabel=null;primaryNodeId=null;groupedChildren=new Map;init(){this.diagram.onEvent(Pe,this.handleMouseDown.bind(this),this.diagram.priorities.Mouse_Down_Dragger),this.diagram.onEvent(ne,this.handleMouseUp.bind(this),this.diagram.priorities.Mouse_Up_Dragger),this.diagram.onEvent(Ne,this.handleMouseMove.bind(this),this.diagram.priorities.Mouse_Move_Selector-1),this.diagram.onEvent(vt,this.handleScale.bind(this),this.diagram.priorities.Scale_Dragger),this.diagram.onEvent(tt,e=>{this.draggingNodes.delete(e.node.id),this.draggingLabel?.node===e.node&&(this.draggingLabel=null)})}constructor(e){super(e)}draggingNodes=new Map;startPoint=new y;startPointScaled=new y;mousePoint=new y;unsubscribe=o(()=>{},"unsubscribe");startDrag(e,t=Mt.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=e.id,this.draggingNodes.set(e.id,{node:e,startPoint:e.coordinates.copy()}),this.mousePoint=t.copy(),this.startPoint=t.copy(),this.startPointScaled=this.diagram.canvas.inverseFit(this.startPoint),this.handleDragAction()}originalEvent=null;labelDragHandle(e){return e.originalEvent.target?.closest?.('[data-node-label-drag-handle="true"]')??null}createLabelDragState(e,t){if(!t)return null;const i=Number(t.dataset?.nodeLabelWidth),s=Number(t.dataset?.nodeLabelHeight),r=Number(t.dataset?.nodeLabelGap);return{gap:Number.isFinite(r)&&r>=0?r:5,labelSize:new y([Number.isFinite(i)&&i>0?i:e.box.width,Number.isFinite(s)&&s>0?s:e.box.height]),node:e,startOffset:e.labelOffset}}snapLabelOffset(e,t){const i=t.node.box,s=i.middle,r=i.width/2+t.gap+t.labelSize.x/2,a=i.height/2+t.gap+t.labelSize.y/2,l=s.copy().sum([0,a]),c=[[0,-1],[-1,0],[1,0],[0,1]].map(([p,g])=>s.copy().sum([p*r,g*a])),h=l.copy().sum(e),u=c.map(p=>({anchor:p,distance:p.distance(h)})).sort((p,g)=>p.distance-g.distance)[0];return u?u.anchor.copy().substract(l):e}handleMouseDown(e){this.originalEvent=e;const t=e.node;!e.cancelled&&t&&t.selected&&(e.cancel(),this.draggingNodes.clear(),this.groupedChildren.clear(),this.draggingLabel=this.createLabelDragState(t,this.labelDragHandle(e)),this.autopanReady=!0,this.dragStarted=!1,this.primaryNodeId=t.id,this.mousePoint=new y(e.originalEvent),this.startPoint=this.mousePoint.copy(),this.startPointScaled=this.diagram.canvas.inverseFit(this.mousePoint),this.handleDragAction())}handleMouseMove(e){this.mousePoint=new y(e.originalEvent)}handleDragAction(){this.unsubscribe(),this.unsubscribe=Me(Ge(this,vt,({newScale:e,previousScale:t})=>{this.startPoint.divide(t).multiply(e)}),ni(this.handleDragInterval.bind(this),30))}isFullyContained(e,t){return t.x>=e.x&&t.y>=e.y&&t.x+t.width<=e.x+e.width&&t.y+t.height<=e.y+e.height}collectConnectedEdges(e){const t=new Set;return e.forEach(i=>{i.gateways.forEach(s=>{s.incomingEdges.forEach(r=>t.add(r)),s.outgoingEdges.forEach(r=>t.add(r))})}),t}translateEdge(e,t){e.steps.forEach(i=>{i.sum(t)}),e.labels.forEach(i=>{i.position.sum(t)})}updateEdgesAfterBatchMove(e,t){const i=new Map,s=[];t.forEach(r=>{const a=e.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(e){const t=new Set(this.groupedChildren.keys()),i=e.filter(v=>!v.cancelled&&!t.has(v.node.id));if(i.length<2)return null;const s=i.find(v=>v.node.id===this.primaryNodeId)??i[0],r=[...i].sort((v,w)=>(me.get(v,"x")??1/0)-(me.get(w,"x")??1/0))[0],a=[...i].sort((v,w)=>(me.get(v,"y")??1/0)-(me.get(w,"y")??1/0))[0],l=me.get(r,"x")===void 0?s:r,c=me.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 p=new y([l.get().x-h.x,c.get().y-u.y]);let g=Number.NEGATIVE_INFINITY,m=Number.POSITIVE_INFINITY,x=Number.NEGATIVE_INFINITY,b=Number.POSITIVE_INFINITY;return i.forEach(v=>{const w=this.draggingNodes.get(v.node.id)?.startPoint;w&&(g=Math.max(g,-w.x),m=Math.min(m,this.diagram.canvas.size.x-w.x-v.node.box.width),x=Math.max(x,-w.y),b=Math.min(b,this.diagram.canvas.size.y-w.y-v.node.box.height))}),p.x=Math.min(m,Math.max(g,p.x)),p.y=Math.min(b,Math.max(x,p.y)),p}applyNodePositionProposals(e){const t=new Map(e.map(c=>[c.node.id,c])),i=new Set(this.groupedChildren.keys()),s=new Map,r=this.rigidSelectionDisplacement(e);e.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()]));e.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=t.get(c),p=this.draggingNodes.get(h),g=this.draggingNodes.get(c);if(!p||!g)return;const x=(u?.cancelled?g.startPoint:u?.node.coordinates??g.startPoint).copy().substract(g.startPoint),b=p.startPoint.copy().sum(x);p.node.setPosition(b,{updateConnectedEdges:!1})}),this.updateEdgesAfterBatchMove(l,a)}includeGroupedChildren(){const e=[...this.draggingNodes.values()].filter(({node:i})=>i.state.groupChildren);if(!e.length)return;const t=new Set(this.draggingNodes.keys());this.diagram.nodes.forEach(i=>{if(t.has(i.id)||i.state.movable===!1)return;let s=null,r=Number.POSITIVE_INFINITY;const a=i.box;e.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 e=this.mousePoint;if(this.draggingLabel){if(this.dragStarted||(this.dragStarted=e.copy().substract(this.startPoint).norm>this.dragThreshold),!this.dragStarted)return;const t=e.copy().substract(this.startPoint).divide(this.diagram.canvas.scale),i=this.draggingLabel.startOffset.copy().sum(t);this.draggingLabel.node.setLabelOffset(this.snapLabelOffset(i,this.draggingLabel));return}if(this.draggingNodes.size||(this.diagram.getExtension($).selectedNodes.forEach(t=>{this.draggingNodes.set(t.id,{node:t,startPoint:t.coordinates.copy()})}),this.includeGroupedChildren(),this.draggingNodes.size||this.unsubscribe()),this.draggingNodes.size){if(this.dragStarted||(this.dragStarted=e.copy().substract(this.startPoint).norm>this.dragThreshold),!this.dragStarted)return;this.autopanReady||(this.autopanReady=this.pointerIsInsideSafeViewport(e)),this.autopanReady&&this.autopan.displace(e);const t=this.diagram.canvas.inverseFit(this.startPoint),i=this.startPointScaled.copy().substract(t),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 St(a.node,new M([...a.startPoint.copy().sum(e.copy().substract(this.startPoint).divide(this.diagram.canvas.scale).substract(i)).raw,...a.node.box.size.raw])));this.emit(new fe(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(e){const t=this.diagram.canvas.frameDimensions,i=Math.min(_e.edgeThreshold,t.width/2),s=Math.min(_e.edgeThreshold,t.height/2);return e.x>=t.x+i&&e.x<=t.x+t.width-i&&e.y>=t.y+s&&e.y<=t.y+t.height-s}handleScale(e){this.draggingNodes.size}};o(Br,"Dragger");let ri=Br;function un(n,e){const t=Math.abs(e.x-n.x)>=Math.abs(e.y-n.y);return{axis:t?"horizontal":"vertical",origin:n,point:t?new y([e.x,n.y]):new y([n.x,e.y])}}o(un,"cardinalAxisConstraint");const ko=22,ai=25;function So(n,e,t){const i=n.nodes.filter(u=>u!==t.excludeNode).filter(u=>u.box.translate(new y([-ai,-ai])).sum([0,0,ai*2,ai*2]).collides(e));if(t.axisConstraint){const u=i.filter(g=>g.edgesAsGateways&&g.box.collides(e)).sort((g,m)=>g.box.middle.distance(e)-m.box.middle.distance(e)).map(g=>({anchor:g.findAxisAlignedConnectionAnchor(t.axisConstraint.origin,t.axisConstraint.axis),node:g})).find(g=>g.anchor);if(u?.anchor)return{anchor:u.anchor,anchorState:{mode:"fixed",position:u.anchor.relativePosition},node:u.node,snappedToGateway:!1};const p=i.flatMap(g=>g.gateways).map(g=>({distance:g.coordinates.distance(e),gateway:g})).filter(({gateway:g})=>t.axisConstraint.axis==="horizontal"?Math.abs(g.coordinates.y-t.axisConstraint.origin.y)<.001:Math.abs(g.coordinates.x-t.axisConstraint.origin.x)<.001).filter(g=>g.distance<=ko).sort((g,m)=>g.distance-m.distance)[0]?.gateway;if(p){const g={gateway:p,point:p.coordinates.copy(),relativePosition:p.relativePosition,displacement:new y};return{anchor:g,anchorState:{mode:"fixed",position:g.relativePosition},node:p.parent,snappedToGateway:!0}}return null}const s=i.flatMap(u=>u.gateways).map(u=>({gateway:u,distance:u.coordinates.distance(e)})).filter(u=>u.distance<=ko).sort((u,p)=>u.distance-p.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(e)).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,p)=>u.box.middle.distance(e)-p.box.middle.distance(e))[0];if(a){const u=a.usesAutomaticConnectionPoint(e),p=u?a.findAutomaticGatewayAnchor(t.oppositePoint):a.findFixedConnectionAnchor(e);return{anchor:p,anchorState:u?{mode:"automatic"}:{mode:"fixed",position:p.relativePosition},node:a,snappedToGateway:!1}}const l=i.flatMap(u=>u.gateways).map(u=>({gateway:u,distance:u.connectionDistance(e)})).filter(u=>Number.isFinite(u.distance)).sort((u,p)=>u.distance-p.distance)[0]?.gateway;if(!l)return null;const c=l.connectionDisplacement(e);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(So,"resolveConnectionCandidate");const gn=.001,Ve=3,Rr=class Rr extends F{autopan=new _e(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(rn,this.startDrag.bind(this)),this.diagram.onEvent(an,this.startEndpointDrag.bind(this))}almostEqual(e,t){return Math.abs(e-t)<gn}pointMatches(e,t){return this.almostEqual(e.x,t.x)&&this.almostEqual(e.y,t.y)}axisAligned(e,t){return this.almostEqual(e.x,t.x)||this.almostEqual(e.y,t.y)}pointsNear(e,t,i=Ve){return Math.abs(e.x-t.x)<=i&&Math.abs(e.y-t.y)<=i}isActivePoint(e){return!!(this.drag&&(e===this.drag.pointA||e===this.drag.pointB))}getGridSize(){return this.diagram.getExtension(B)?.gridSize??50}orientationVector(e){switch(e){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(e){return e==="left"||e==="right"?"y":"x"}expectedLeadPoint(e,t){const i=t==="from"?e.steps[0]:e.steps.at(-1),s=t==="from"?e.from.orientation:e.to.orientation,r=this.orientationVector(s),a=this.getGridSize();return new y([i.x+r.x*a,i.y+r.y*a])}leadMatchesGatewaySide(e,t,i){const s=this.orientationVector(i),r=(t.x-e.x)*s.x+(t.y-e.y)*s.y;return Math.abs(i==="left"||i==="right"?t.y-e.y:t.x-e.x)<=Ve&&r>gn&&r<=this.getGridSize()+Ve}endpointLeadPoint(e,t){const i=t==="from"?e.steps[0]:e.steps.at(-1),s=t==="from"?e.from.orientation:e.to.orientation,r=t==="from"?1:e.steps.length-2,a=e.steps[r];return a&&a.mode!=="manual"&&!this.isActivePoint(a)&&this.leadMatchesGatewaySide(i,a,s)?a:this.expectedLeadPoint(e,t)}ensureEndpointLeadPoint(e,t){const i=this.expectedLeadPoint(e,t),s=t==="from",r=s?1:e.steps.length-2,a=e.steps[r];if(a&&this.leadMatchesGatewaySide(s?e.steps[0]:e.steps.at(-1),a,s?e.from.orientation:e.to.orientation))return r;const l=new R(e,[i.x,i.y,"auto"]);return s?(e.state.steps.splice(1,0,l),1):(e.state.steps.splice(e.steps.length-1,0,l),e.steps.length-2)}ensureEndpointLeads(e){this.ensureEndpointLeadPoint(e,"from"),this.ensureEndpointLeadPoint(e,"to")}isProtectedLeadPoint(e,t){return t<=0||t>=e.steps.length-1?!1:t===1&&e.steps[t].mode!=="manual"&&this.leadMatchesGatewaySide(e.steps[0],e.steps[t],e.from.orientation)||t===e.steps.length-2&&e.steps[t].mode!=="manual"&&this.leadMatchesGatewaySide(e.steps.at(-1),e.steps[t],e.to.orientation)}segmentMovedAxis(e,t){return this.almostEqual(e.y,t.y)?"y":this.almostEqual(e.x,t.x)?"x":Math.abs(e.x-t.x)>=Math.abs(e.y-t.y)?"y":"x"}segmentDirection(e,t){return!this.axisAligned(e,t)||this.pointMatches(e,t)?null:this.almostEqual(e.y,t.y)?"horizontal":"vertical"}segmentIsParallelToDraggedAxis(e,t){return this.drag?this.drag.movedAxis==="y"?Math.abs(e.y-t.y)<=Ve:Math.abs(e.x-t.x)<=Ve:!1}perpendicularAxis(e){return e==="x"?"y":"x"}pointAxis(e,t){return t==="x"?e.x:e.y}setPointAxis(e,t,i){t==="x"?e.x=i:e.y=i}crossesStaticBoundary(e,t,i,s,r=Ve){const a=this.pointAxis(i,t),l=this.pointAxis(s,t);switch(e){case"right":case"down":return a<l-r;case"left":case"up":return a>l+r}}copyAsManual(e,t="both"){const i=e.copy();return i.parent=e.parent,i.addManualAxis(t),i}markManual(e,t="both"){e.mode!=="static"&&e.addManualAxis(t)}clampPointPastLead(e,t,i){switch(i){case"left":e.x=Math.min(e.x,t.x);break;case"right":e.x=Math.max(e.x,t.x);break;case"up":e.y=Math.min(e.y,t.y);break;case"down":e.y=Math.max(e.y,t.y);break}}movedAxisMatchesOrientation(e,t){return(t==="left"||t==="right")&&e==="x"||(t==="up"||t==="down")&&e==="y"}edgePointAt(e,t,i,s="auto"){return new R(e,[t,i,s])}guardCoordinate(e,t,i,s,r){const a=this.pointAxis(s,r)-this.pointAxis(i,r),l=Math.abs(a)>gn?Math.sign(a):1,c=t==="from"?e.from.parent.box:e.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(e,t,i,s){const r=this.perpendicularAxis(s),a=this.edgePointAt(e,t.x,t.y,"auto");return this.setPointAxis(a,s,this.pointAxis(t,s)),this.setPointAxis(a,r,i),a}insertStaticBoundaryGuard(e){if(!this.drag)return!1;const{edge:t,movedAxis:i}=this.drag,s=e==="from"?t.from.orientation:t.to.orientation;if(!this.movedAxisMatchesOrientation(i,s))return!1;const r=t.state.steps,a=r.findIndex(N=>N===this.drag.pointA),l=r.findIndex(N=>N===this.drag.pointB);if(a<0||l<0)return!1;const c=e==="from"?a<=l?"pointA":"pointB":a>=l?"pointA":"pointB",h=c==="pointA"?"pointB":"pointA",u=this.drag[c],p=this.drag[h],g=r.findIndex(N=>N===u),m=this.endpointLeadPoint(t,e),x=e==="from"?1:r.length-2,b=r[x],v=!!(b&&this.pointMatches(b,m)),w=e==="from"?g===1:g===r.length-2,_=e==="from"?g===2&&v:g===r.length-3&&v,k=this.crossesStaticBoundary(s,i,u,m,Ve);if(g<0||!w&&!_||!k)return!1;const C=this.perpendicularAxis(i),P=this.guardCoordinate(t,e,m,p,C);this.setPointAxis(u,C,P),this.markManual(u,i),this.rebaseDraggedEndpointFixedAxis(c,u);const D=this.makeGuardCorner(t,m,P,i);if(e==="from"){if(w){const N=this.edgePointAt(t,m.x,m.y,"auto");r.splice(g,0,N,D)}else r.splice(g,0,D);return this.drag.sourceLeadAdjacent=!1,this.drag.staticBoundaryGuarded=!0,!0}if(w){const N=this.edgePointAt(t,m.x,m.y,"auto");r.splice(g+1,0,D,N)}else r.splice(g+1,0,D);return this.drag.targetLeadAdjacent=!1,this.drag.staticBoundaryGuarded=!0,!0}insertStaticBoundaryGuards(){const e=this.insertStaticBoundaryGuard("from"),t=this.insertStaticBoundaryGuard("to");return e||t}clampDraggedSegmentAgainstEndpointLeads(){if(!this.drag)return;const{edge:e,pointA:t,pointB:i,movedAxis:s,sourceLeadAdjacent:r,targetLeadAdjacent:a}=this.drag,l=e.steps.findIndex(h=>h===t),c=e.steps.findIndex(h=>h===i);if(this.movedAxisMatchesOrientation(s,e.from.orientation)){const u=e.steps[1]??this.expectedLeadPoint(e,"from");u&&(r||l>=0&&c>=0&&this.isProtectedLeadPoint(e,1)&&(l===2||c===2))&&(this.clampPointPastLead(t,u,e.from.orientation),this.clampPointPastLead(i,u,e.from.orientation))}if(this.movedAxisMatchesOrientation(s,e.to.orientation)){const h=e.steps.length-2,u=e.steps[h]??this.expectedLeadPoint(e,"to");u&&(a||l>=0&&c>=0&&this.isProtectedLeadPoint(e,h)&&(l===h-1||c===h-1))&&(this.clampPointPastLead(t,u,e.to.orientation),this.clampPointPastLead(i,u,e.to.orientation))}}mergeDraggedSegmentWithManualNeighbors(){if(!this.drag)return!1;let e=!1;const t=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,e=!0)},"mergePoint");return t("pointA",-1),t("pointB",1),e}rebaseDraggedEndpointFixedAxis(e,t){if(!this.drag)return;const i=e==="pointA"?this.drag.startPointA:this.drag.startPointB;this.drag.movedAxis==="y"?i.x=t.x:i.y=t.y}replaceDraggedEndpointWithProtectedLeadDuplicate(e,t,i){if(!this.drag)return;const s=this.drag[e],r=this.copyAsManual(t,this.drag.movedAxis);this.drag.movedAxis==="y"?r.y=s.y:r.x=s.x,this.drag.edge.state.steps[i]=r,this.drag[e]=r,this.rebaseDraggedEndpointFixedAxis(e,r)}absorbCollinearSegmentsIntoDraggedSegment(){if(!this.drag)return!1;let e=!1;const t=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),e=!0;return}if(h.mode==="static")return;r.splice(l,1),this.drag[i]=h,this.rebaseDraggedEndpointFixedAxis(i,h),e=!0}},"absorbSide");return t("pointA",-1),t("pointB",1),e}removeAdjacentDuplicates(e){if(!this.drag)return!1;const t=this.drag.edge.state.steps;let i=!1;for(let s=0;s<t.length-1;){const r=t[s],a=t[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>=t.length-1||e&&this.isActivePoint(t[l])){s+=1;continue}t.splice(l,1),i=!0,s=Math.max(0,s-1)}return i}coordinateAnchorForPair(e,t,i,s){return this.drag?e.mode==="static"?this.pointAxis(e,i):t.mode==="static"?this.pointAxis(t,i):this.isProtectedLeadPoint(this.drag.edge,s)?this.pointAxis(e,i):this.isProtectedLeadPoint(this.drag.edge,s+1)?this.pointAxis(t,i):this.isActivePoint(e)?this.pointAxis(e,i):this.isActivePoint(t)?this.pointAxis(t,i):e.mode==="manual"?this.pointAxis(e,i):t.mode==="manual"?this.pointAxis(t,i):this.pointAxis(e,i):this.pointAxis(e,i)}snapNearlyAlignedDraggedPairs(){if(!this.drag)return!1;const e=this.drag.edge.state.steps;let t=!1;for(let i=0;i<e.length-1;i++){const s=e[i],r=e[i+1];if(Math.abs(s.x-r.x)>gn&&Math.abs(s.x-r.x)<=Ve){const a=this.coordinateAnchorForPair(s,r,"x",i);s.x=a,r.x=a,t=!0}if(Math.abs(s.y-r.y)>gn&&Math.abs(s.y-r.y)<=Ve){const a=this.coordinateAnchorForPair(s,r,"y",i);s.y=a,r.y=a,t=!0}}return t}chooseOrthogonalCorner(e,t,i,s){const r=new R(this.drag?.edge??null,[t.x,e.y,"auto"]),a=new R(this.drag?.edge??null,[e.x,t.y,"auto"]),l=o(c=>{let h=0;const u=i?this.segmentDirection(i,e):null,p=this.segmentDirection(e,c),g=s?this.segmentDirection(t,s):null,m=this.segmentDirection(c,t);return u&&p!==u&&(h+=2),g&&m!==g&&(h+=2),this.axisAligned(i??e,c)&&(h+=1),this.axisAligned(c,s??t)&&(h+=1),h},"score");return l(r)>=l(a)?r:a}ensureOrthogonalAdjacency(){if(!this.drag)return!1;const e=this.drag.edge.state.steps;let t=!1;for(let i=0;i<e.length-1;i++){const s=e[i],r=e[i+1];if(this.axisAligned(s,r))continue;const a=i>0?e[i-1]:void 0,l=i+2<e.length?e[i+2]:void 0;e.splice(i+1,0,this.chooseOrthogonalCorner(s,r,a,l)),t=!0,i+=1}return t}normalizeDraggedEdge(){if(!this.drag)return!1;const e=this.snapNearlyAlignedDraggedPairs(),t=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()),e||t||i||s||r||a||l}finalizeDraggedEdge(){this.drag&&(this.normalizeDraggedEdge(),this.ensureOrthogonalAdjacency(),this.removeAdjacentDuplicates(!1),this.drag.staticBoundaryGuarded||this.drag.edge.setSteps(Eo("orthogonal").route(this.diagram,this.drag.edge)))}prepareStraightLeadSegment(e,t){const i=this.copyAsManual(e.steps[1],t),s=this.copyAsManual(e.steps[2],t);return e.state.steps.splice(2,0,i,s),{pointA:i,pointB:s,movedAxis:t}}prepareSourceSegment(e){this.ensureEndpointLeads(e);const t=this.axisPerpendicularToGateway(e.from.orientation);if(e.steps.length===4&&this.isProtectedLeadPoint(e,1)&&this.isProtectedLeadPoint(e,2))return this.prepareStraightLeadSegment(e,t);const i=this.copyAsManual(e.steps[1],t);e.state.steps.splice(2,0,i);const s=e.steps[3];return s instanceof R?(this.markManual(s,t),{pointA:i,pointB:s,movedAxis:t}):null}prepareTargetSegment(e){this.ensureEndpointLeads(e);const t=this.axisPerpendicularToGateway(e.to.orientation);if(e.steps.length===4&&this.isProtectedLeadPoint(e,1)&&this.isProtectedLeadPoint(e,2))return this.prepareStraightLeadSegment(e,t);const i=e.steps.length-2,s=this.copyAsManual(e.steps[i],t);e.state.steps.splice(i,0,s);const r=e.steps[i-1];return r instanceof R?(this.markManual(r,t),{pointA:r,pointB:s,movedAxis:t}):null}prepareSegmentAfterProtectedSourceLead(e,t){const i=this.segmentMovedAxis(e.steps[t],e.steps[t+1]),s=this.copyAsManual(e.steps[t],i);e.state.steps.splice(t+1,0,s);const r=e.steps[t+2];return r instanceof R?(this.markManual(r,i),{pointA:s,pointB:r,movedAxis:i}):null}prepareSegmentBeforeProtectedTargetLead(e,t){const i=this.segmentMovedAxis(e.steps[t-1],e.steps[t]),s=this.copyAsManual(e.steps[t],i);e.state.steps.splice(t,0,s);const r=e.steps[t-1];return r instanceof R?(this.markManual(r,i),{pointA:r,pointB:s,movedAxis:i}):null}prepareInteriorSegment(e,t,i,s){this.ensureEndpointLeads(e);let r=e.steps.findIndex(u=>u===t),a=e.steps.findIndex(u=>u===i);if((r<0||a<0||Math.abs(r-a)!==1)&&(r=Math.max(0,Math.min(s,e.steps.length-2)),a=r+1),r>a&&([r,a]=[a,r]),r===0)return this.prepareSourceSegment(e);if(a===e.steps.length-1)return this.prepareTargetSegment(e);if(this.isProtectedLeadPoint(e,r))return this.prepareSegmentAfterProtectedSourceLead(e,r);if(this.isProtectedLeadPoint(e,a))return this.prepareSegmentBeforeProtectedTargetLead(e,a);const l=e.steps[r],c=e.steps[a],h=this.segmentMovedAxis(l,c);return this.markManual(l,h),this.markManual(c,h),{pointA:l,pointB:c,movedAxis:h}}restoreOriginalSteps(e,t){e.setSteps(t.map(i=>i.copy()))}startDrag(e){if(e.cancelled||e.src.pathType!=="orthogonal")return;e.stopImmediatePropagation(),this.uns();const t=e.src,i=t.steps.map(b=>b.copy()),s=t.steps.length-1,r=Number(e.midPoint.id),a=r===0,l=r===s-1,c=e.midPoint.points[0],h=e.midPoint.points[1],u=f.runInAction(()=>{t.state.dragging=!0;const b=a?this.prepareSourceSegment(t):l?this.prepareTargetSegment(t):this.prepareInteriorSegment(t,c,h,r);return b||(t.state.dragging=!1),b});if(!u)return;const p=t.steps.findIndex(b=>b===u.pointA),g=t.steps.findIndex(b=>b===u.pointB),m=p===2||g===2,x=p===t.steps.length-3||g===t.steps.length-3;this.drag={edge:t,midpoint:e.midPoint,pointA:u.pointA,pointB:u.pointB,movedAxis:u.movedAxis,startMouseCanvas:this.diagram.canvas.inverseFit(new y(e)),startPointA:u.pointA.copy().nonObserved,startPointB:u.pointB.copy().nonObserved,originalSteps:i,sourceLeadAdjacent:m,targetLeadAdjacent:x,staticBoundaryGuarded:!1,changed:!1},this.uns=Me(Y(this,"mousemove",this.handleMouseMove),Y(this,"pointermove",this.handleMouseMove))}startEndpointDrag(e){if(e.cancelled)return;e.stopImmediatePropagation(),this.uns(),f.runInAction(()=>{e.src.state.dragging=!0}),this.drag=null,this.endpointDragActive=!0,this.endpointCandidatePoint=null;const t=e.src.steps[0],i=e.src.steps.at(-1),s=e.src.from.parent.box,r=e.src.to.parent.box;this.endpointDrag={edge:e.src,endpoint:e.endpoint,originalStart:{gateway:e.src.from,point:t.copy(),displacement:t.copy().substract(e.src.from.coordinates),relativePosition:new y([(t.x-s.x)/Math.max(s.width,.001),(t.y-s.y)/Math.max(s.height,.001)])},originalEnd:{gateway:e.src.to,point:i.copy(),displacement:i.copy().substract(e.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:e.src.startAnchor.mode,position:e.src.startAnchor.position?.copy()},originalEndState:{mode:e.src.endAnchor.mode,position:e.src.endAnchor.position?.copy()},candidate:null},this.uns=Me(Y(this,"mousemove",this.handleMouseMove),Y(this,"pointermove",this.handleMouseMove))}restoreEndpointDrag(){if(!this.endpointDrag)return;const e=this.endpointDrag,t=e.endpoint==="from"?e.originalStart:e.originalEnd,i=e.endpoint==="from"?e.originalStartState:e.originalEndState;e.edge.setResolvedEndpoint(e.endpoint,t,i,!0)}handleEndpointMouseMove(e){if(!this.endpointDrag)return;const{edge:t,endpoint:i}=this.endpointDrag,s=this.diagram.canvas.inverseFit(new y(e)),r=i==="from"?t.to.parent:t.from.parent,a=i==="from"?t.steps.at(-1):t.steps[0],l=e.shiftKey?un(a,s):null,c=l?.point??s,h=So(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:t.from,p=i==="to"?h.anchor.gateway:t.to;if(!u.canStartConnection(p,t)||!p.canConnect(u,t)){this.endpointDrag.candidate=null,this.endpointCandidatePoint=null,this.restoreEndpointDrag();return}this.endpointDrag.candidate=h,this.endpointCandidatePoint=h.anchor.point,f.runInAction(()=>{t.setResolvedEndpoint(i,h.anchor,h.anchorState,!0)})}moveDraggedSegment(e){if(!this.drag)return;const{pointA:t,pointB:i}=this.drag,r=this.diagram.canvas.inverseFit(new y(e)).nonObserved.substract(this.drag.startMouseCanvas);this.drag.movedAxis==="x"?r.y=0:r.x=0,f.runInAction(()=>{if(!this.drag)return;t.assign(this.drag.startPointA.copy().sum(r)),i.assign(this.drag.startPointB.copy().sum(r));const a=[new on(t,this.drag.movedAxis),new on(i,this.drag.movedAxis)];this.emit(new ln(this,a,this.drag.movedAxis,e));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(e){if((e.type==="pointermove"||typeof PointerEvent>"u")&&this.autopan.displace(new y(e)),this.endpointDrag){this.handleEndpointMouseMove(e);return}this.moveDraggedSegment(e)}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:e,candidate:t}=this.endpointDrag;(!t||this.emit(new Et(this,e.from.parent,e.to.parent,e)).cancelled)&&this.restoreEndpointDrag(),e.state.dragging=!1,this.endpointDragActive=!1,this.endpointCandidatePoint=null}this.drag=null,this.endpointDrag=null}),this.uns())}};o(Rr,"EdgesDragger");let rt=Rr;const Gr=class Gr extends F{proposals=[];snapDistance=10;clear(){this.proposals=[]}init(){f.makeObservable(this,{clear:f.action,proposals:f.observable})}align(e,t,i){if(!this.enabled||!this.diagram.getExtension(Be).enabled)return this.clear(),i;const s=t.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},p={distance:Number.POSITIVE_INFINITY,guide:h,target:i.y};const g=o((b,v)=>{const w=Math.abs(i.x-b);w<=a&&w<u.distance&&(u={distance:w,guide:v,target:b})},"chooseX"),m=o((b,v)=>{const w=Math.abs(i.y-b);w<=a&&w<p.distance&&(p={distance:w,guide:v,target:b})},"chooseY");for(const b of this.diagram.edges.flatMap(v=>v.labels)){if(b===t)continue;const v=b.position.x+b.size.width/2,w=b.position.y+b.size.height/2,_=b.position.y+b.size.height,k=b.position.x+b.size.width,C=Math.min(i.y,b.position.y),P=Math.max(i.y+s.height,_),D=Math.min(i.x,b.position.x),N=Math.max(i.x+s.width,k);g(b.position.x,{from:new y([b.position.x,C]),id:`label-left-${b.id}`,to:new y([b.position.x,P])}),g(k-s.width,{from:new y([k,C]),id:`label-right-${b.id}`,to:new y([k,P])}),g(v-s.width/2,{from:new y([v,C]),id:`label-center-x-${b.id}`,to:new y([v,P])}),m(b.position.y,{from:new y([D,b.position.y]),id:`label-top-${b.id}`,to:new y([N,b.position.y])}),m(_-s.height,{from:new y([D,_]),id:`label-bottom-${b.id}`,to:new y([N,_])}),m(w-s.height/2,{from:new y([D,w]),id:`label-center-y-${b.id}`,to:new y([N,w])})}Number.isFinite(u.distance)&&(l=u.target),Number.isFinite(p.distance)&&(c=p.target);for(let b=0;b<e.steps.length-1;b+=1){const v=e.steps[b],w=e.steps[b+1],_=Math.abs(v.x-w.x)<.001,k=Math.abs(v.y-w.y)<.001;if(_&&c+s.height>=Math.min(v.y,w.y)-a&&c<=Math.max(v.y,w.y)+a){const C=Math.min(v.y,w.y),P=Math.max(v.y,w.y);g(v.x+r,{from:new y([v.x+r,C]),id:`edge-left-${b}`,to:new y([v.x+r,P])}),g(v.x-r-s.width,{from:new y([v.x-r,C]),id:`edge-right-${b}`,to:new y([v.x-r,P])})}if(k&&l+s.width>=Math.min(v.x,w.x)-a&&l<=Math.max(v.x,w.x)+a){const C=Math.min(v.x,w.x),P=Math.max(v.x,w.x);m(v.y+r,{from:new y([C,v.y+r]),id:`edge-top-${b}`,to:new y([P,v.y+r])}),m(v.y-r-s.height,{from:new y([C,v.y-r]),id:`edge-bottom-${b}`,to:new y([P,v.y-r])})}}Number.isFinite(u.distance)&&(l=u.target),Number.isFinite(p.distance)&&(c=p.target);const x=[u,p].filter(b=>Number.isFinite(b.distance)).map(b=>b.guide);return f.runInAction(()=>{this.proposals=x}),new y([l,c])}};o(Gr,"LabelsAligner");let De=Gr;function Yc(n,e,t){switch(t){case"down":return e.copy().sum([0,n]);case"left":return e.copy().sum([-n,0]);case"up":return e.copy().sum([0,-n]);case"right":return e.copy().sum([+n,0])}}o(Yc,"stepFromGateway");const Zc=5,Vr=class Vr extends F{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(Pe,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 Qn;pendingConnection=null;unbindPendingConnection=o(()=>{},"unbindPendingConnection");_arrowSteps=[];get arrowSteps(){return this._arrowSteps}get previewPathType(){const e=this.startGateway?.parent.requiredEdgePathType==="straight",t=this.candidateGateway?.parent.requiredEdgePathType==="straight";return e||t?"straight":"orthogonal"}get candidatePoint(){return this.candidateAnchor?.point??null}get snap(){return this.diagram.getExtension(B)}resolveStartAnchor(e,t=!1){return this.startGateway?this.startAnchorMode==="automatic"&&!t?this.startGateway.parent.findAutomaticGatewayAnchor(e):this.startAnchor:null}calculateArrowSteps(){if(!this.startGateway||!this.arrowTo)return;const e=this.startGateway,t=this.candidateGateway,i=this.candidateAnchor,s=this.arrowTo.copy(),r=this.previewRequestVersion;if(!s||t&&!i){f.runInAction(()=>{this._arrowSteps=[]});return}try{const a=this.diagram.canvas.inverseFit(s),l=this.axisConstrained&&this.startAnchor?un(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 g=un(this.startAnchor.point,l);g.axis==="horizontal"?h.y=g.point.y:h.x=g.point.x}const u=this.resolveStartAnchor(t?.parent.box.middle??l,this.axisConstrained);if(!u)return;let p=[];if(t)p=this.previewRouter.findRouteBetween(this.diagram,u.gateway,i.gateway,u.displacement,i.displacement);else{const g=new Dt(null,{id:"fake",label:"",box:new M([...h.raw,0,0])}),m=u.gateway.coordinates.substract(g.getGateway("down").coordinates).x,x=u.gateway.coordinates.substract(g.getGateway("down").coordinates).y,b=Math.abs(m)>Math.abs(x)?m>=0?"right":"left":x>=0?"down":"up";p=this.previewRouter.findRouteBetween(this.diagram,u.gateway,g.getGateway(b),u.displacement)}f.runInAction(()=>{this.startGateway===e&&r===this.previewRequestVersion&&(this._arrowSteps=p.map(g=>new y([g.x,g.y])),this.hasRoutedPreview=this._arrowSteps.length>1)})}catch{}}orthogonalMousePreview(e,t){const i=this.snap.gridSize/2,s=t.copy().divide(i).round.multiply(i);if(this.axisConstrained&&this.startAnchor){const g=un(this.startAnchor.point,t);g.axis==="horizontal"?s.y=g.point.y:s.x=g.point.x}const r=e.point.copy(),a=Yc(this.snap.gridSize,r,e.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),p=Math.abs(s.y-a.y);return l.push(u>=p?h:c,s),this.compactPreviewPoints(l)}compactPreviewPoints(e){const t=[];for(const i of e){const s=t.at(-1);if(!(s&&Math.abs(s.x-i.x)<.001&&Math.abs(s.y-i.y)<.001))for(t.push(i);t.length>=3;){const r=t.at(-3),a=t.at(-2),l=t.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)t.splice(t.length-2,1);else break}}return t}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(e){const t=e.originalEvent.target;if(!t||typeof t.closest!="function")return null;const i=t.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(e));return s.findFixedConnectionAnchor(l)}handleGatewayMouseDown(e){if(e.cancelled||e.originalEvent.button!==0||this.connecting)return;const t=this.connectionAnchorFromEvent(e);t&&(this.cancelPendingConnection(),this.pendingConnection={anchor:t,pointer:new y(e)},e.cancel(),this.unbindPendingConnection=Me(Ge(this,Ne,this.handlePendingMouseMove),Ge(this,ne,this.cancelPendingConnection)))}handlePendingMouseMove(e){const t=this.pendingConnection;!t||t.pointer.distance(new y(e))<Zc||(this.cancelPendingConnection(),this.startAnchorMode="fixed",this.beginConnection(t.anchor,e)&&this.handleMouseMove(e))}cancelPendingConnection(){this.pendingConnection=null,this.unbindPendingConnection(),this.unbindPendingConnection=()=>{}}startConnectionFrom(e,t){this.startAnchorMode="fixed";const i={gateway:e,point:e.coordinates.copy(),relativePosition:e.relativePosition,displacement:new y};this.beginConnection(i,t)}startConnectionFromNode(e,t,i="fixed"){const s=this.diagram.canvas.inverseFit(new y(t));this.startAnchorMode=i,this.beginConnection(e.findFixedConnectionAnchor(s),t)}get connecting(){return this.startGateway!==null}beginConnection(e,t){const i=e.gateway;if(this.emit(new Wn(this,i.parent)).cancelled)return!1;const s="originalEvent"in t?t.originalEvent:t.nativeEvent;return"originalEvent"in t&&t.stopImmediatePropagation(),s.stopImmediatePropagation?.(),this.diagram.canvas.markMouseSessionStartedInFrame(),this.startGateway=i,this.startAnchor=e,this.arrowTo=new y(s),this.hasRoutedPreview=!1,this.axisConstrained=!1,this.previewRequestVersion=0,this._arrowSteps=[e.point.copy(),e.point.copy()],this.u(),this.u=Me(Ge(this,Ne,this.handleMouseMove),Ge(this,ne,this.handleMouseUp)),!0}handleMouseMove(e){this.previewRequestVersion+=1;const t=this.diagram.canvas.frameDimensions;this.arrowTo=new y(e);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>t.width-100?s.substract([(100-Math.abs(i.x-t.width))*.1,0]):i.y<100?s.sum([0,(100-i.y)*.1]):i.y>t.height-100&&s.substract([0,(100-Math.abs(i.y-t.height))*.1]),s.norm>0&&this.diagram.canvas.displace(s);const r=this.diagram.canvas.inverseFit(this.arrowTo),a=e.shift&&this.startAnchor?un(this.startAnchor.point,r):null;this.axisConstrained=!!a;const l=a?.point??r,c=So(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 e=this.candidateAnchor,t=this.candidateAnchorState,i=this.candidateGateway?this.resolveStartAnchor(this.candidateGateway.parent.box.middle,this.axisConstrained):null;this.candidateGateway&&e&&t&&i&&this.candidateGateway.canConnect(i.gateway)&&i.gateway.canStartConnection(this.candidateGateway)&&(this.emit(new Et(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:e.displacement,endAnchor:t})))}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(Vr,"NodesConnector");let at=Vr;const Wr=class Wr extends F{init(){this.diagram.onEvent(kt,()=>{},this.diagram.priorities.Node_Selection_Nodes_Resizer)}};o(Wr,"NodesResizer");let oi=Wr,qi=(Zt=class extends F{grid=null;points=null;highlighted=new Set;init(){f.makeObservable(this,{grid:f.observable,setGrid:f.action,points:f.observable,highlighted:f.observable})}setGrid(e,t){this.grid=e,this.points=t}},o(Zt,"PathFindingRenderer"),Zt);const pn=1e3,Yr=class Yr{Canvas_Rules=pn;Change_History=0;Click_Node=100;Drag_Rules=pn;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=pn;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=pn;Node_Selection_Nodes_Resizer=200;Node_Selection_Selector=200;Scale_Dragger=100;Selection_Rules=pn};o(Yr,"Priorities");let Xi=Yr;const Mo="diagram-grid-visible",Zr=class Zr{constructor(e){this.d=e,e.onEvent(ee,this.check(()=>this.allowEdition),e.priorities.Mouse_Down_Rules),e.onEvent(_t,this.check(()=>this.allowSelection),e.priorities.Selection_Rules),e.onEvent(He,this.check(()=>this.allowEdition),e.priorities.Drag_Rules),e.onEvent(wt,this.check(()=>this.allowEdition),e.priorities.Nodes_Connection_Rules),e.onEvent(xt,this.check(()=>this.allowZoom),e.priorities.Drag_Rules),f.makeAutoObservable(this)}d;allowEdition=!0;allowSelection=!0;allowZoom=!0;displaceWhenDragOnEdges=!0;_toggleGrid=localStorage.getItem(Mo)!=="false";get toggleGrid(){return this._toggleGrid}set toggleGrid(e){this._toggleGrid=e,localStorage.setItem(Mo,String(e))}check=o(e=>t=>{e()||(t.cancel(),t.stopImmediatePropagation())},"check")};o(Zr,"Rules");let Ji=Zr;const Kr=class Kr extends F{straight="none";startCoordinates=null;startProposals=[];shiftHeld=!1;reset(){this.straight="none",this.startCoordinates=null,this.startProposals=[],this.shiftHeld=!1}init(){this.diagram.onEvent(Ue,e=>{e.shift&&(this.shiftHeld=!0,this.startCoordinates=Mt.getInstance().coordinates)}),this.diagram.onEvent(bt,e=>{e.shift||this.reset()}),this.diagram.onEvent(Pe,e=>{e.shift&&!this.startCoordinates&&(this.shiftHeld=!0,this.startCoordinates=new y(e.originalEvent))}),this.diagram.onEvent(Ne,e=>{if(!this.shiftHeld||!this.startCoordinates)return;const t=Math.abs(e.mouse.x-this.startCoordinates.x),i=Math.abs(e.mouse.y-this.startCoordinates.y);(t||i)&&(this.straight=t>=i?"x":"y")},this.diagram.priorities.Mouse_Move_Straight_Drag),this.diagram.onEvent(ne,()=>{this.reset()},this.diagram.priorities.Mouse_Up_Straight_Drag),this.diagram.onEvent(fe,e=>{if(this.straight!=="none"){this.startProposals.length===0&&(this.startProposals=e.proposals.map(t=>new St(t.node,t.node.box)));for(const t of e.proposals){const i=this.startProposals.find(s=>s.node.id===t.node.id);switch(this.straight){case"x":t.updateY(i.newBox.y),t.lockY();break;case"y":t.updateX(i.newBox.x),t.lockX();break}}}},this.diagram.priorities.Drag_Node_Straight_Drag)}};o(Kr,"StraightDrag");let li=Kr;const Ur=class Ur extends F{shiftHeld=!1;init(){this.diagram.onEvent(Ue,e=>{e.shift&&(this.shiftHeld=!0)}),this.diagram.onEvent(bt,e=>{e.shift||(this.shiftHeld=!1)})}constrain(e,t,i=t){if(!this.enabled||!this.shiftHeld)return t;const s=Math.abs(i.x-e.x),r=Math.abs(i.y-e.y),a=t.copy();return s>=r?a.y=e.y:a.x=e.x,a}};o(Ur,"StraightLabelsDrag");let Lt=Ur;const Ao=S.createContext(null),Kc=o(()=>({Creator:si,DistancesBalancer:Ct,StraightDrag:li,StraightLabelsDrag:Lt,Dragger:ri,EdgesDragger:rt,GridSnap:B,History:It,Hotkeys:ti,LabelsAligner:De,Measurer:jt,NodesAligner:Be,NodesConnector:at,NodesResizer:oi,PathFindingRenderer:qi,Selector:$}),"getDefaultExtensions"),Di=class Di extends qe{priorities=new Xi;rules=new Ji(this);focusContentTimer=null;knownClasses=new Map;getClass(e){return this.knownClasses.get(e)}registerClass(e,t=e.name){this.knownClasses.set(t,e)}edgeClass=Re;setDefaultEdge(e){this.edgeClass=e}_extensions=new Map;_nodes=new Map;_edges=new Map;_hoveredNode=null;canvas=new _o(this);constructor(e){super(null),e?.zoom&&this.canvas.configureZoom(e.zoom),this.registerClass(Dt),this.registerClass(Re),this.registerClass(Se),this.registerClass(ii),Object.entries(Kc()).forEach(([t,i])=>{e?.extensions?.[t]!==!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(e,t){e.diagram===this&&(t?(this._hoveredNode&&this._hoveredNode!==e&&(this._hoveredNode.state.hover=!1),this._hoveredNode=e,e.state.hover=!0):this._hoveredNode===e?(e.state.hover=!1,this._hoveredNode=null):e.state.hover=!1)}clearNodeHover(){this._hoveredNode&&(this._hoveredNode.state.hover=!1),this._hoveredNode=null}getUniqueNodeId(e){if(!this._nodes.has(e))return e;let t=1,i=`${e}-${t}`;for(;this._nodes.has(i);)t++,i=`${e}-${t}`;return i}add(e){return f.runInAction(()=>{const t=this.getUniqueNodeId(e.id);t!==e.id&&e.setState("id",t),e.setDiagram(this),this._nodes.set(e.id,e)}),e}addEdge(e){e.from.addOutgoingEdge(e),e.to.addIncomingEdge(e)}connect(e,t,i){const s=i?.startAnchor??{mode:"fixed",position:e.parent.findFixedConnectionAnchor(e.coordinates.copy().sum(i?.fromDisplacement??new y)).relativePosition},r=i?.endAnchor??{mode:"fixed",position:t.parent.findFixedConnectionAnchor(t.coordinates.copy().sum(i?.toDisplacement??new y)).relativePosition},a=new this.edgeClass(this,{hover:!1,dragging:!1,selected:!1,from:e,to:t,labels:[],pathType:i?.pathType??"orthogonal",displacementStart:i?.fromDisplacement,displacementEnd:i?.toDisplacement,startAnchor:s,endAnchor:r,steps:[]});return this.connectWithEdge(e,t,a)}connectWithEdge(e,t,i){const s=i;return s.from.addOutgoingEdge(s),s.to.addIncomingEdge(s),this._edges.set(s.id,s),s}delete(e){this.emit(new tt(this,e)).cancelled||f.runInAction(()=>{e.gateways.forEach(t=>{t.incomingEdges.forEach(this.disconnect.bind(this)),t.outgoingEdges.forEach(this.disconnect.bind(this))}),this._hoveredNode===e&&(e.state.hover=!1,this._hoveredNode=null),this._nodes.delete(e.id),e.parent=null})}disconnect(e){this.emit(new nn(this,e)).cancelled||f.runInAction(()=>{for(const t of this.nodes)for(const i of t.gateways)i.removeIncomingEdge(e),i.removeOutgoingEdge(e);this._edges.delete(e.id),e.parent=null})}Context=o(({children:e})=>d.jsx(Ao.Provider,{value:this,children:e}),"Context");getEdgeById(e){return this._edges.get(e)}getNodeById(e){return this._nodes.get(e)}get showGrid(){return this.rules.toggleGrid}getExtension(e){return this._extensions.get(e)}registerExtension(e){const t=new e(this);t.init(),this._extensions.set(e,t)}toggleGrid(){this.rules.toggleGrid=!this.rules.toggleGrid}export(){return JSON.stringify(this.serialize())}async reset(){let e=this._nodes.size===0;if(!e){let t=null;const i=this.emit(new Vn(this,s=>{t=s}));e=await t()&&!i.cancelled}if(e){for(const t of this._nodes.values())this.delete(t);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(e=>e.serialize())}}import(e){f.runInAction(()=>{const t=JSON.parse(e),i=t.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]))),t.nodes){const r=new Map;t.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)}),t.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(p=>({...p,toParentId:r.get(p.toParentId)||p.toParentId}))}))},r);c.deserialize(h)})}s||this.focusContentInViewportWithRetry()})}paste(e){f.runInAction(()=>{const t=JSON.parse(e);if(t.position&&(this.canvas.setScale(t.position.scale),this.canvas.setDisplacement(new y([t.position.x,t.position.y]))),t.nodes?.length){const i=new Map,s=[];t.nodes.forEach(c=>{const h=At(this,"node",s);i.set(c.id,h),s.push(h)});let r=new y([1/0,1/0]);t.nodes.forEach(c=>{const h=new y([c.box[0],c.box[1]]);h.norm<r.norm&&(r=h)});const l=this.canvas.inverseFit(Mt.getInstance().coordinates).substract(r);t.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)}),t.nodes.forEach(c=>{const h=i.get(c.id),u=this.getNodeById(h),p=u.remapSerializedReferences({...c,id:h,gateways:c.gateways.map(g=>({...g,outEdges:g.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(p)})}})}focusContentInViewport(e=80){if(!this.nodes.length)return!1;const t=this.canvas.frameDimensions;if(t.width<=0||t.height<=0)return!1;let i=1/0,s=1/0,r=-1/0,a=-1/0;for(const u of this.nodes){const p=u.box;i=Math.min(i,p.x),s=Math.min(s,p.y),r=Math.max(r,p.x+p.width),a=Math.max(a,p.y+p.height)}if(!Number.isFinite(i)||!Number.isFinite(s)||!Number.isFinite(r)||!Number.isFinite(a))return!1;const l=Math.max(1,r-i+e*2),c=Math.max(1,a-s+e*2),h=this.canvas.clampScale(Math.min(t.width/l,t.height/c));return this.canvas.setScale(h),this.canvas.centerOnPoint(new y([(i+r)/2,(s+a)/2])),!0}focusContentInViewportWithRetry(e=8,t=32){this.focusContentInViewport()||e<=0||(this.focusContentTimer&&clearTimeout(this.focusContentTimer),this.focusContentTimer=setTimeout(()=>{this.focusContentInViewportWithRetry(e-1,t)},t))}};o(Di,"Diagram"),$e(Di,"use",o(()=>S.useContext(Ao),"use"));let J=Di;function Le(n,e){return{"data-id":n.id,onMouseEnter:o(()=>n.setHovered(!0),"onMouseEnter"),onMouseLeave:o(t=>{const i=t.relatedTarget;i instanceof Element&&i.closest(`[data-id="${n.id}"], [data-gateway-parent="${n.id}"]`)||n.setHovered(!1)},"onMouseLeave"),style:{"--screen-renderer-x":`${e.x}px`,"--screen-renderer-y":`${e.y}px`,"--screen-renderer-width":`${e.width}px`,"--screen-renderer-height":`${e.height}px`,"--screen-renderer-z-index":n.state.hover?(n.state.zIndex??100)+1:n.state.zIndex??100}}}o(Le,"screenRendererProps");function ci(n){return["Enter","Escape"].includes(n.code)}o(ci,"allowEventInEdition");const qr=class qr extends F{inEdition=new Set;cancel(){this.inEdition.forEach(e=>e.cancel()),this.inEdition.clear()}confirm(){this.inEdition.forEach(e=>e.confirm()),this.inEdition.clear()}editNode(e){e.edit(),this.inEdition.add(e)}init(){this.diagram.onEvent(Ue,e=>{switch(e.code){case"F2":{const t=this.diagram.getExtension($).selectedNodes[0];t instanceof Oe&&this.editNode(t);break}case"Escape":{this.cancel();break}case"Enter":e.shift||this.confirm()}}),this.diagram.onEvent(Pe,e=>{(!e.node||e.node instanceof Oe&&!this.inEdition.has(e.node))&&this.confirm()},this.diagram.priorities.Mouse_Down_Dragger+1),this.diagram.onEvent(tn,e=>{e.node instanceof Oe&&!this.inEdition.has(e.node)&&(this.confirm(),this.editNode(e.node))})}};o(qr,"EditionMode");let di=qr;function Uc(n,e){const t=n.box.middle,i=e.middle,s=i.x-t.x,r=i.y-t.y;return Math.abs(s)>Math.abs(r)?s<0?"left":"right":r<0?"top":"bottom"}o(Uc,"externalLabelPosition");const Co=A.observer(({node:n,box:e})=>{const t=S.useRef(!1),i=Le(n,e),s=/(?:^| )(?:bpmn__event|bpmn__gate|bpmn__data_store|bpmn__document)(?: |$)/.test(n.classList.string),r=s?e.y-n.labelOffset.y-(n.box.y+n.box.height):void 0,a=s?Uc(n,e):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 p=n.diagram?.rules.allowEdition!==!1;return n.editionMode&&p?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(g=>{f.runInAction(()=>{n.state.label=g.target.value})},"onChange"),onKeyDownCapture:o(g=>{n.editionMode&&!ci(g.nativeEvent)&&g.nativeEvent.stopImmediatePropagation()},"onKeyDownCapture"),ref:o(g=>{g instanceof HTMLTextAreaElement&&!t.current&&(t.current=!0,g.select())},"ref")}):(t.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?e.height:void 0,"data-node-label-width":s?e.width:void 0,className:`node__screenLabel node__screenHitArea${c}${h}${u}${n.selected?" selected":""}`,children:n.state.label}):null)}),Xr=class Xr extends ee{constructor(e,t,i){super(e),this.src=e,this.previousLabel=t,this.nextLabel=i}src;previousLabel;nextLabel};o(Xr,"DEditNodeEvent");let Qi=Xr;const Jr=class Jr extends Dt{editionMode=!1;constructor(e,t){super(e,t),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 Qi(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(Co,{node:this,box:this.screenLabelBox}))};o(Jr,"EditableNode");let Oe=Jr;const Qr=class Qr extends J{constructor(e){super(e),this.registerClass(Oe),this.registerExtension(di)}};o(Qr,"EditableDiagram");let ot=Qr;const ea=class ea extends Re{kind="default";constructor(e,t){super(e,t),f.makeObservable(this,{kind:f.observable,setKind:f.action}),this.setKind(t.kind??"default")}setKind(e){switch(this.kind=e,e){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(e){super.deserialize(e),this.setKind(e.kind??"default")}};o(ea,"AgentEdge");let hi=ea;function qc(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(qc,"customRendererStyles");function q(n){const e=qc(n);return n.state.fill&&(e["--node-fill"]=n.state.fill),n.state.stroke&&(e["--node-stroke"]=n.state.stroke),{onMouseOver:o(()=>n.setState("hover",!0),"onMouseOver"),onMouseOut:o(t=>{const i=t.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:e,className:`${n.classList.string} ${n.selected?"selected":""}`}}o(q,"customRendererProps");function fn(n){return typeof n=="object"&&n?Array.isArray(n)?n.map(e=>fn(e)):Object.fromEntries(Object.entries(n).map(([e,t])=>[e,fn(t)])):n}o(fn,"cloneDeep");const ta=class ta extends Oe{payload;constructor(e,t){super(e,t),this.classList.add("agent__node","diagram__node"),this.payload=this.mergePayload(t.payload),f.makeObservable(this,{payload:f.observable.ref,replacePayload:f.action,updatePayload:f.action})}mergePayload(e){return{...this.defaultPayload(),...e??{}}}replacePayload(e){this.payload=this.mergePayload(e)}updatePayload(e){this.payload={...this.payload,...e}}serialize(){return{...super.serialize(),kind:this.kind,payload:fn(this.payload)}}deserialize(e){super.deserialize(e),this.payload=this.mergePayload(e.payload)}};o(ta,"AgentNode");let lt=ta;const na=class na extends lt{kind="action";constructor(e,t){super(e,{...t,box:t.box??new M([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(na,"ActionNode");let es=na;const ia=class ia extends lt{kind="condition";constructor(e,t){super(e,{...t,box:t.box??new M([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(ia,"ConditionNode");let ts=ia;const sa=class sa extends lt{kind="outcome";constructor(e,t){super(e,{...t,box:t.box??new M([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(sa,"OutcomeNode");let ns=sa;const ra=class ra extends lt{kind="trigger";constructor(e,t){super(e,{...t,box:t.box??new M([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(ra,"TriggerNode");let is=ra;const aa=class aa extends ot{constructor(e){super(e),this.registerClass(lt),this.registerClass(is),this.registerClass(es),this.registerClass(ts),this.registerClass(ns),this.registerClass(hi),this.setDefaultEdge(hi)}};o(aa,"AgentDiagram");let ss=aa;const oa=class oa extends Oe{edgesAsGateways=!0;occupiesGridSquare=!1;constructor(e,t){super(e,{...t,labelFontSize:t.labelFontSize??16}),this.classList.add("bpm__node","diagram__node")}fitToGridSquare(){if(!this.occupiesGridSquare)return;const e=this.diagram?.getExtension(B)?.gridSize??50;this.state.box.assignDimensions([e,e])}setDiagram(e){super.setDiagram(e),this.fitToGridSquare()}deserialize(e){super.deserialize(e),this.state.labelFontSize=e.labelFontSize,this.fitToGridSquare()}};o(oa,"BPMNode");let ae=oa;var Io={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},jo=S.createContext&&S.createContext(Io),Xc=["attr","size","title"];function Jc(n,e){if(n==null)return{};var t,i,s=Qc(n,e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(n);for(i=0;i<r.length;i++)t=r[i],e.indexOf(t)===-1&&{}.propertyIsEnumerable.call(n,t)&&(s[t]=n[t])}return s}o(Jc,"_objectWithoutProperties");function Qc(n,e){if(n==null)return{};var t={};for(var i in n)if({}.hasOwnProperty.call(n,i)){if(e.indexOf(i)!==-1)continue;t[i]=n[i]}return t}o(Qc,"_objectWithoutPropertiesLoose");function ui(){return ui=Object.assign?Object.assign.bind():function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var i in t)({}).hasOwnProperty.call(t,i)&&(n[i]=t[i])}return n},ui.apply(null,arguments)}o(ui,"_extends");function Po(n,e){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(n);e&&(i=i.filter(function(s){return Object.getOwnPropertyDescriptor(n,s).enumerable})),t.push.apply(t,i)}return t}o(Po,"ownKeys");function gi(n){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?Po(Object(t),!0).forEach(function(i){ed(n,i,t[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):Po(Object(t)).forEach(function(i){Object.defineProperty(n,i,Object.getOwnPropertyDescriptor(t,i))})}return n}o(gi,"_objectSpread");function ed(n,e,t){return(e=td(e))in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}o(ed,"_defineProperty");function td(n){var e=nd(n,"string");return typeof e=="symbol"?e:e+""}o(td,"_toPropertyKey");function nd(n,e){if(typeof n!="object"||!n)return n;var t=n[Symbol.toPrimitive];if(t!==void 0){var i=t.call(n,e);if(typeof i!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(n)}o(nd,"_toPrimitive");function No(n){return n&&n.map((e,t)=>S.createElement(e.tag,gi({key:t},e.attr),No(e.child)))}o(No,"Tree2Element");function z(n){return e=>S.createElement(id,ui({attr:gi({},n.attr)},e),No(n.child))}o(z,"GenIcon");function id(n){var e=o(t=>{var i=n.attr,s=n.size,r=n.title,a=Jc(n,Xc),l=s||t.size||"1em",c;return t.className&&(c=t.className),n.className&&(c=(c?c+" ":"")+n.className),S.createElement("svg",ui({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},t.attr,i,a,{className:c,style:gi(gi({color:n.color||t.color},t.style),n.style),height:l,width:l,xmlns:"http://www.w3.org/2000/svg"}),r&&S.createElement("title",null,r),n.children)},"elem");return jo!==void 0?S.createElement(jo.Consumer,null,t=>e(t)):e(Io)}o(id,"IconBase");function sd(n){return z({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(sd,"PiUser");function To(n){return z({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(To,"PiTrash");function rd(n){return z({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(rd,"PiTextAlignRight");function ad(n){return z({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(ad,"PiTextAlignLeft");function od(n){return z({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(od,"PiTextAlignCenter");function ld(n){return z({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(ld,"PiTable");function cd(n){return z({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(cd,"PiRows");function dd(n){return z({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(dd,"PiRowsPlusTop");function hd(n){return z({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(hd,"PiRowsPlusBottom");function Do(n){return z({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(Do,"PiPlusSquare");function ud(n){return z({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(ud,"PiPencilSimple");function gd(n){return z({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(gd,"PiNoteBlank");function pd(n){return z({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(pd,"PiMinusCircle");function fd(n){return z({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(fd,"PiHand");function md(n){return z({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(md,"PiGitBranch");function Lo(n){return z({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(Lo,"PiGearSix");function yd(n){return z({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(yd,"PiFile");function bd(n){return z({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(bd,"PiDatabase");function xd(n){return z({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 vd(n){return z({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(vd,"PiClock");function Oo(n){return z({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(Oo,"PiCircle");function wd(n){return z({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(wd,"PiArrowsOutCardinal");function Ed(n){return z({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(Ed,"PiArrowsLeftRight");function _d(n){return z({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(_d,"PiPlusSquareBold");function kd(n){return z({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(kd,"PiClockBold");function Sd(n){return z({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(Sd,"PiCircleBold");function Md(n){return z({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(Md,"PiCheckBold");function Ad(n){return z({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(Ad,"PiArrowRightBold");function Cd(n){return z({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(Cd,"PiArrowCounterClockwiseBold");const Id={task:sd,serviceTask:Lo,scriptTask:xd,manualTask:fd,businessRuleTask:ld,callActivity:_d,subprocess:Do,eventSubprocess:Do,event:Oo,start:Oo,end:Sd,timer:vd,lanes:cd,dataStore:bd,document:yd,textAnnotation:gd,connect:Ad,settings:Lo};function jd({id:n,className:e}){const t=n==="messageThrow"||n==="sendTask";return d.jsxs("svg",{className:`${e??""} bpmn__message_icon bpmn__message_icon--${t?"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(jd,"MessageIcon");function Pd({id:n,className:e}){return d.jsxs("svg",{className:e,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(Pd,"EventDefinitionIcon");function Nd({id:n,className:e}){return d.jsxs("svg",{className:e,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(Nd,"SupportIcon");function Td({id:n,className:e,markerOnly:t}){const i=t?n==="eventBased"?"6 6 12 12":"5 5 14 14":"0 0 24 24";return d.jsxs("svg",{className:[e,`bpmn__gate_marker--${n}`].filter(Boolean).join(" "),viewBox:i,"aria-hidden":"true",children:[!t&&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:t?1:1.35}),d.jsx("circle",{cx:"12",cy:"12",r:"3.8",fill:"none",stroke:"currentColor",strokeWidth:t?.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:t?.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(Td,"GatewayIcon");function We({id:n,className:e,markerOnly:t}){const i=Id[n];return i?d.jsx(i,{"aria-hidden":"true",className:e}):n==="messageCatch"||n==="messageThrow"||n==="message"||n==="receiveTask"||n==="sendTask"?d.jsx(jd,{className:e,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(Pd,{className:e,id:n}):n==="blackBoxPool"||n==="documentAnnotation"||n==="dataInput"||n==="dataOutput"?d.jsx(Nd,{className:e,id:n}):n==="exclusive"||n==="inclusive"||n==="parallel"||n==="eventBased"||n==="complex"?d.jsx(Td,{className:e,id:n,markerOnly:t}):d.jsxs("svg",{className:e,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(We,"BPMNIcon");var j=(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))(j||{});const pi={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"}},Dd=new Set(["start","intermediate","end"]),Ld=new Set(["none","timer","message","signal","compensation","error","conditional","terminate","cancel","escalation","link","multiple","parallelMultiple"]),Od=new Set(["catch","throw"]),zd={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"])},Fd={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 ct(n){if(!n||typeof n!="object")return!1;const e=n;if(!Dd.has(e.stage)||!Ld.has(e.kind)||!Od.has(e.direction))return!1;const{stage:t,kind:i,direction:s}=e;return zd[i].has(t)&&Fd[i].has(s)}o(ct,"isValidEventDefinition");const $d=5,Hd=3,Bd=1.18,Rd=["bpmn__event__start","bpmn__event__intermediate","bpmn__event__end"],Gd=["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"],Vd=["bpmn--catch","bpmn--throw"],fi=new Set(["timer","message","signal","compensation","error","conditional","cancel","escalation","multiple","parallelMultiple"]),rs=new Set(["message","timer","error","escalation","compensation","conditional","signal","multiple"]),Wd=Object.values(j).filter(n=>typeof n=="string").map(n=>`bpmn--${n}`);function mn(n){return{...n}}o(mn,"copyDefinition");function zo(n){return ct(n.eventDefinition)?mn(n.eventDefinition):typeof n.type=="number"&&pi[n.type]?mn(pi[n.type]):mn(pi[j.start])}o(zo,"resolveDefinition");function Fo(n){return!Array.isArray(n)||n.length!==2||!Number.isFinite(n[0])||!Number.isFinite(n[1])?null:[n[0],n[1]]}o(Fo,"resolveAttachmentOffset");function Yd(n,e){return n.stage===e.stage&&n.kind===e.kind&&n.direction===e.direction}o(Yd,"sameDefinition");const la=class la extends ae{definition;attachedToTaskId;attachmentOffset;interrupting;subprocessStart;subprocessId;edgesAsGateways=!0;occupiesGridSquare=!0;constructor(e,t){super(e,t),this.definition=zo(t),this.attachedToTaskId=t.attachedToTaskId&&fi.has(this.definition.kind)?t.attachedToTaskId:null,this.attachmentOffset=this.attachedToTaskId?Fo(t.attachmentOffset):null,this.interrupting=t.interrupting??!0,this.subprocessId=t.subprocessStart===!0&&rs.has(this.definition.kind)&&!this.attachedToTaskId&&typeof t.subprocessId=="string"&&t.subprocessId.length>0?t.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"?j.start:this.stage==="end"?j.end:j.intermediate:this.kind==="timer"?j.timer:this.kind==="message"?this.isCatching?j.messageCatch:j.messageThrow:this.kind==="signal"?this.isCatching?j.signalCatch:j.signalThrow:this.kind==="compensation"?this.isCatching?j.compensationCatch:j.compensationThrow:this.kind==="error"?this.isCatching?j.errorCatch:j.errorThrow:this.kind==="conditional"?j.conditional:this.kind==="cancel"?this.isCatching?j.cancelCatch:j.cancelThrow:this.kind==="escalation"?this.isCatching?j.escalationCatch:j.escalationThrow:this.kind==="link"?this.isCatching?j.linkCatch:j.linkThrow:this.kind==="multiple"?this.isCatching?j.multipleCatch:j.multipleThrow:this.kind==="parallelMultiple"?j.parallelMultiple:j.terminate}get isStart(){return this.stage==="start"}get isEnd(){return this.stage==="end"}get isCatching(){return this.direction==="catch"}get canAttach(){return fi.has(this.kind)&&!this.subprocessStart}get canStartSubprocess(){return rs.has(this.kind)&&!this.attachedToTaskId}setDefinition(e){return!ct(e)||this.attachedToTaskId&&!fi.has(e.kind)||this.subprocessStart&&!rs.has(e.kind)?!1:Yd(this.definition,e)?!0:this.emit(new pe(this)).cancelled?!1:(this.definition=mn(e),this.isEnd?this._gateways.forEach(t=>t.outgoingEdges.forEach(i=>this.diagram?.disconnect(i))):this.isStart&&this._gateways.forEach(t=>t.incomingEdges.forEach(i=>this.diagram?.disconnect(i))),this.refreshSemanticClasses(),this.refreshAttachmentPresentation(),!0)}setType(e){const t=pi[e];return t?this.setDefinition(t):!1}setAttachment(e,t=null,i=!0){e&&!fi.has(this.kind)||(this.attachedToTaskId=e,this.attachmentOffset=e?Fo(t):null,this.interrupting=i,e&&(this.subprocessStart=!1,this.subprocessId=null),this.refreshAttachmentPresentation())}setInterrupting(e){this.interrupting=e,this.refreshAttachmentPresentation()}setSubprocessStart(e,t=null){return e?!this.canStartSubprocess||!t?!1:(this.subprocessStart=!0,this.subprocessId=t,this.refreshAttachmentPresentation(),!0):(this.subprocessStart=!1,this.subprocessId=null,this.refreshAttachmentPresentation(),!0)}serialize(){return{...super.serialize(),type:this.type,eventDefinition:mn(this.definition),attachedToTaskId:this.attachedToTaskId,attachmentOffset:this.attachmentOffset?[...this.attachmentOffset]:null,interrupting:this.interrupting,subprocessStart:this.subprocessStart,subprocessId:this.subprocessId}}deserialize(e){this.setAttachment(null),this.setSubprocessStart(!1),this.definition=zo(e),this.setAttachment(e.attachedToTaskId??null,e.attachmentOffset??null,e.interrupting??!0),this.setSubprocessStart(e.subprocessStart??!1,e.subprocessId??null),super.deserialize(e),this.refreshSemanticClasses(),this.refreshAttachmentPresentation()}remapSerializedReferences(e,t){const i=e;if(!i.attachedToTaskId&&!i.subprocessId)return e;const s=i.attachedToTaskId?t.get(i.attachedToTaskId)??null:null,r=i.subprocessId?t.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 e=this.box,i=(this.diagram?.getExtension(B)?.gridSize??50)*2,s=Math.max(this.state.labelFontSize??14,14);return new M([e.x+e.width/2-i/2,e.y+e.height+$d,i,s*Bd*Hd]).sum(this.labelOffset)}refreshSemanticClasses(){[...Rd,...Gd,...Vd,...Wd].forEach(e=>this.classList.delete(e)),this.classList.add(`bpmn__event__${this.stage}`,`bpmn--${this.kind}`,`bpmn--${this.direction}`,`bpmn--${j[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 e=this.markerIconId;return d.jsx("div",{...q(this),children:e&&d.jsx(We,{className:`bpmn__node_marker bpmn__event_marker bpmn__event_marker--${this.direction}`,id:e})})})};o(la,"EventNode");let I=la;function Ot(n,e){return`bpmn__event__${n[e]}`}o(Ot,"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[n.complex=4]="complex",n))(H||{});const Zd=5,Kd=2,Ud=1.18;function qd(n){return typeof n?.setDefault=="function"}o(qd,"canSetDefaultFlow");const ca=class ca extends ae{type=-1;edgesAsGateways=!0;occupiesGridSquare=!0;constructor(e,t){super(e,t),f.makeObservable(this,{type:f.observable,setType:f.action}),this.setType(t.type??1),this.fitToGridSquare(),this.classList.add("bpmn__gate")}setType(e){if(this.type!==e&&!this.emit(new pe(this)).cancelled){this.type=e,e!==1&&e!==0&&this.gateways.forEach(t=>t.outgoingEdges.forEach(i=>{qd(i)&&i.setDefault(!1)}));for(const t of Object.values(H))this.classList.delete(Ot(H,t));switch(e){case 1:this.classList.add(Ot(H,1));break;case 0:this.classList.add(Ot(H,0));break;case 2:this.classList.add(Ot(H,2));break;case 3:this.classList.add(Ot(H,3));break;case 4:this.classList.add(Ot(H,4));break}}}serialize(){return{...super.serialize(),type:this.type}}deserialize(e){this.setType(e.type??1),super.deserialize(e)}get screenLabelBox(){const e=this.box,i=(this.diagram?.getExtension(B)?.gridSize??50)*2,s=Math.max(this.state.labelFontSize??14,14);return new M([e.x+e.width/2-i/2,e.y+e.height+Zd,i,s*Ud*Kd]).sum(this.labelOffset)}RenderOverlay=A.observer(()=>{const e=this.state.box.width,t=this.state.box.height;return d.jsx("div",{...q(this),children:d.jsxs("svg",{viewBox:`0 0 ${e} ${t}`,style:{width:`${e}px`,height:`${t}px`},children:[d.jsx("polygon",{points:`${e/2} 0 ${e} ${t/2} ${e/2} ${t} 0 ${t/2}`}),d.jsx("foreignObject",{width:e,height:t,children:d.jsx(We,{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(ca,"GateNode");let W=ca;const Ae={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(Ae).forEach(Object.freeze),Object.freeze(Ae);function as(n={},e=Ae){return{sections:{...e.sections,...n.sections},elements:{...e.elements,...n.elements},eventOptions:{...e.eventOptions,...n.eventOptions},actions:{...e.actions,...n.actions},properties:{...e.properties,...n.properties},edges:{...e.edges,...n.edges},routing:{...e.routing,...n.routing},inputs:{...e.inputs,...n.inputs},resizeDirections:{...e.resizeDirections,...n.resizeDirections},lanes:{...e.lanes,...n.lanes}}}o(as,"configureBPMNLabels");const da=class da extends ee{};o(da,"BPMNPropertyChangeEvent");let Z=da;const $o=50;function mi(n,e){return n<=e?[n,e]:[e,n]}o(mi,"orderedRange");function os(n,e){return Number.isFinite(e.distance)&&(!n||e.distance<n.distance)?e:n}o(os,"closer");const ha=class ha extends F{alignmentProposals=[];init(){f.makeObservable(this,{alignmentProposals:f.observable,clear:f.action})}clear(){this.alignmentProposals=[]}suggest(e,t,i,s=t,r){this.clear();const a=this.diagram.getExtension(Be);if(!this.enabled||a?.enabled!==!0||e.diagram!==this.diagram)return s;const l=r??e.minimumResizeSize;if(!l)return s;const c=$o/5*2,h=$o/3,u=this.diagram.canvas.frameDimensions.norm,p=u>0?u/2:1/0,g=i.includes("w"),m=i.includes("e"),x=i.includes("n"),b=i.includes("s");let v=null,w=null;for(const k of this.diagram.nodes){if(k===e||!(k instanceof ae))continue;const C=k.box;(g||m)&&Math.abs(t.edgeDistanceY(C))<p&&(v=os(v,this.sideCandidate(l,t,C,g?"w":"e",c)),v=os(v,this.widthCandidate(l,t,C,g,c))),(x||b)&&Math.abs(t.edgeDistanceX(C))<p&&(w=os(w,this.sideCandidate(l,t,C,x?"n":"s",c)))}f.runInAction(()=>{this.alignmentProposals=[...v?.guides??[],...w?.guides??[]]});const _=s.copy();return v&&v.distance<h&&(_.x=v.box.x,_.width=v.box.width),w&&w.distance<h&&(_.y=w.box.y,_.height=w.box.height),_}sideCandidate(e,t,i,s,r){const a=t.copy();let l,c;return s==="w"?(l=Math.abs(t.x-i.x),a.x=i.x,a.width=t.rightMiddle.x-i.x,c=[this.verticalGuide(i.x,a,i)]):s==="e"?(l=Math.abs(t.rightMiddle.x-i.rightMiddle.x),a.width=i.rightMiddle.x-t.x,c=[this.verticalGuide(i.rightMiddle.x,a,i)]):s==="n"?(l=Math.abs(t.y-i.y),a.y=i.y,a.height=t.bottomMiddle.y-i.y,c=[this.horizontalGuide(i.y,a,i)]):(l=Math.abs(t.bottomMiddle.y-i.bottomMiddle.y),a.height=i.bottomMiddle.y-t.y,c=[this.horizontalGuide(i.bottomMiddle.y,a,i)]),this.candidate(e,a,l,c,r)}widthCandidate(e,t,i,s,r){const a=t.copy(),l=Math.abs(t.width-i.width);return a.width=i.width,s&&(a.x=t.rightMiddle.x-i.width),this.candidate(e,a,l,this.widthGuides(a,i),r)}candidate(e,t,i,s,r){return{box:t,distance:i<r&&this.isValid(e,t)?i:1/0,guides:s}}isValid(e,t){const i=this.diagram.canvas.size;return t.width>=e.x&&t.height>=e.y&&t.x>=0&&t.y>=0&&t.rightMiddle.x<=i.x&&t.bottomMiddle.y<=i.y}verticalGuide(e,t,i){return{type:"h",x:e,range:mi(Math.min(t.y,i.y),Math.max(t.bottomMiddle.y,i.bottomMiddle.y)),id:nt("bpmn-resize-suggestion")}}horizontalGuide(e,t,i){return{type:"v",y:e,range:mi(Math.min(t.x,i.x),Math.max(t.rightMiddle.x,i.rightMiddle.x)),id:nt("bpmn-resize-suggestion")}}widthGuides(e,t){return[{type:"v",y:e.y,range:mi(e.x,e.rightMiddle.x),id:nt("bpmn-resize-suggestion")},{type:"v",y:t.y,range:mi(t.x,t.rightMiddle.x),id:nt("bpmn-resize-suggestion")}]}};o(ha,"BPMNResizeSuggester");let Je=ha;const ua=class ua extends F{autopan=new _e(this.diagram);session=null;unbindSession=o(()=>{},"unbindSession");init(){}startResize(e,t,i){if(t.button!==0||e.diagram!==this.diagram)return;t.preventDefault(),t.stopImmediatePropagation(),this.endSession();const s=new y(t);this.session={changed:!1,direction:i,initialBox:new M(e.box.raw,!1),node:e,pointer:s,startPosition:this.diagram.canvas.inverseFit(s)},this.unbindSession=Me(Y(this,"pointermove",this.handlePointerMove),Y(this,"pointerup",this.endSession),Y(this,"pointercancel",this.endSession),ni(this.handleAutopan,30))}resizeNode(e,t){if(e.diagram!==this.diagram)return!1;const i=t instanceof y?t:new y(t,!1),s=this.diagram.getExtension(B),r=s?.enabled===!0?s.gridSize:null,a=Math.max(0,this.diagram.canvas.size.x-e.box.x),l=Math.max(0,this.diagram.canvas.size.y-e.box.y),c=this.constrain(i.x,e.minimumResizeSize.x,a,r),h=this.constrain(i.y,e.minimumResizeSize.y,l,r);return this.applyBox(e,new M([e.box.x,e.box.y,c,h],!1))}resizeNodeFromDirection(e,t,i,s){if(e.diagram!==this.diagram)return!1;const r=this.diagram.getExtension(B),a=r?.enabled===!0?r.gridSize:null,l=i.includes("w"),c=i.includes("e"),h=i.includes("n"),u=i.includes("s"),p=l?t.x+t.width:this.diagram.canvas.size.x-t.x,g=h?t.y+t.height:this.diagram.canvas.size.y-t.y,m=t.width+(c?s.x:l?-s.x:0),x=t.height+(u?s.y:h?-s.y:0),b=l||c?this.constrain(m,e.minimumResizeSize.x,p,null):t.width,v=h||u?this.constrain(x,e.minimumResizeSize.y,g,null):t.height,w=l?t.x+t.width-b:t.x,_=h?t.y+t.height-v:t.y,k=new M([w,_,b,v],!1),C=a?this.snapDirectionalBoxToGrid(e,t,k,i,a):k,P=this.diagram.getExtension(Je)?.suggest(e,k,i,C)??C;return this.applyBox(e,P)}snapDirectionalBoxToGrid(e,t,i,s,r){const a=i.copy(),l=t.rightMiddle.x,c=t.bottomMiddle.y;if(s.includes("w"))a.x=this.snapCoordinate(i.x,0,l-e.minimumResizeSize.x,r,t.x),a.width=l-a.x;else if(s.includes("e")){const h=this.snapCoordinate(i.rightMiddle.x,t.x+e.minimumResizeSize.x,this.diagram.canvas.size.x,r,l);a.width=h-t.x}if(s.includes("n"))a.y=this.snapCoordinate(i.y,0,c-e.minimumResizeSize.y,r,t.y),a.height=c-a.y;else if(s.includes("s")){const h=this.snapCoordinate(i.bottomMiddle.y,t.y+e.minimumResizeSize.y,this.diagram.canvas.size.y,r,c);a.height=h-t.y}return a}snapCoordinate(e,t,i,s,r){const a=Math.ceil(t/s)*s,l=Math.floor(i/s)*s;if(a>l)return r;const c=Math.round(e/s)*s;return Math.min(l,Math.max(a,c))}applyBox(e,t){return e.box.x===t.x&&e.box.y===t.y&&e.box.width===t.width&&e.box.height===t.height?!1:(f.runInAction(()=>{e.state.box.assign(t)}),this.rerouteConnectedEdges(e),!0)}constrain(e,t,i,s){const r=Number.isFinite(e)?e:t,a=Math.min(t,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(e){const t=new Set;e.gateways.forEach(i=>{i.incomingEdges.forEach(s=>t.add(s)),i.outgoingEdges.forEach(s=>t.add(s))}),t.forEach(i=>i.from.recomputeConnectedEdge(i,"from"))}handlePointerMove(e){this.session&&(this.session.pointer=new y(e),this.resizeFromPointer())}handleAutopan=o(()=>{this.session&&(this.autopan.displace(this.session.pointer),this.resizeFromPointer())},"handleAutopan");resizeFromPointer(){if(!this.session)return;const t=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,t);this.session.changed=this.session.changed||i}endSession(){const e=this.session?.changed===!0;this.session=null;const t=this.unbindSession;this.unbindSession=()=>{},t(),this.diagram.getExtension(Je)?.clear(),e&&this.emit(new Z(this))}};o(ua,"BPMNNodeResizer");let yi=ua;const Xd=["n","ne","e","se","s","sw","w","nw"],Jd={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 bi({node:n}){const e=n.diagram?.getExtension(yi);if(!n.selected||!e||n.diagram?.rules.allowEdition===!1)return null;const t=n.diagram?.bpmnLabels??Ae,i=o((r,a)=>{r.button===0&&(r.preventDefault(),r.stopPropagation(),r.nativeEvent.stopImmediatePropagation(),e.startResize(n,r.nativeEvent,a))},"beginResize"),s=Le(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:Xd.map(r=>d.jsx("button",{"aria-label":`${t.actions.resizeElement} ${t.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",...Jd[r]},tabIndex:-1,title:`${t.actions.resize} ${t.resizeDirections[r]}`,type:"button"},r))})}o(bi,"BPMNResizeHandle");var O=(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))(O||{});const eh={0:"task",1:"serviceTask",4:"sendTask",5:"receiveTask",6:"scriptTask",7:"manualTask",9:"businessRuleTask"},Ho=new Set(Object.values(O).filter(n=>typeof n=="number"));function Bo(n){return n==="parallel"?"parallel":"none"}o(Bo,"normalizeMultiInstance");function Ye(n){return n===3||n===8}o(Ye,"isSubprocessType");function ls(n){return n===3||n===2}o(ls,"supportsTransaction");function th(n){return Ye(n)?new M([0,0,400,250]):new M([0,0,150,100])}o(th,"defaultTaskBox");const ga=class ga extends ae{type=-1;minimumResizeSize=new y([300,200],!1);multiInstance;loop;compensation;adHoc;transaction;edgesAsGateways=!0;constructor(e,t){super(e,{...t,box:t.box||th(t.type),groupChildren:Ye(t.type),zIndex:t.zIndex??(Ye(t.type)?50:100)}),this.classList.add("bpmn__task"),this.multiInstance=Bo(t.multiInstance),this.loop=t.loop===!0,this.compensation=t.compensation===!0,this.adHoc=t.adHoc===!0&&t.type===3,this.transaction=t.transaction===!0&&ls(t.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(t.type??0)}fitWidthToGrid(e=!1){if(Ye(this.type))return;const i=(this.diagram?.getExtension(B)?.gridSize??50)*3;e&&(this.state.box.x+=(this.state.box.width-i)/2),this.state.box.width=i}applySubprocessState(e){const t=Ye(this.type);if(this.state.groupChildren=t,this.state.zIndex=t?50:100,t){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(e){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"),!e)return;const i=this.diagram?.getExtension(B)?.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(e){super.setDiagram(e),this.fitWidthToGrid()}setType(e){if(!Ho.has(e))return!1;if(this.type===e)return!0;if(this.emit(new pe(this)).cancelled)return!1;const t=Ye(this.type);return Ho.has(this.type)&&this.classList.delete(`bpmn--${O[this.type]}`),this.type=e,e!==3&&(this.adHoc=!1),ls(e)||(this.transaction=!1),this.classList.add(`bpmn--${O[e]}`),this.refreshTransactionPresentation(),this.applySubprocessState(t),!0}setMultiInstance(e){return e!=="none"&&e!=="parallel"?!1:this.multiInstance===e?!0:this.emit(new pe(this)).cancelled?!1:(this.multiInstance=e,!0)}setLoop(e){return this.loop===e?!0:this.emit(new pe(this)).cancelled?!1:(this.loop=e,!0)}setCompensation(e){return this.compensation===e?!0:this.emit(new pe(this)).cancelled?!1:(this.compensation=e,!0)}setAdHoc(e){return this.type!==3?!1:this.adHoc===e?!0:this.emit(new pe(this)).cancelled?!1:(this.adHoc=e,!0)}setTransaction(e){return ls(this.type)?this.transaction===e?!0:this.emit(new pe(this)).cancelled?!1:(this.transaction=e,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(e){this.setType(e.type??0),this.setMultiInstance(Bo(e.multiInstance)),this.setLoop(e.loop===!0),this.setCompensation(e.compensation===!0),this.setAdHoc(e.adHoc===!0),this.setTransaction(e.transaction===!0),super.deserialize(e),this.applySubprocessState(Ye(this.type)),this.fitWidthToGrid(!0)}get screenLabelBox(){if(!Ye(this.type))return this.box;const e=this.box;return new M([e.x+16,e.y+8,Math.max(0,e.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(Co,{node:this,box:this.screenLabelBox}),Ye(this.type)&&d.jsx(bi,{node:this})]}));RenderOverlay=A.observer(()=>{const e=eh[this.type],t=this.type===2||this.type===3,i=this.type===3&&this.adHoc;return d.jsxs("div",{...q(this),children:[e&&d.jsx(We,{className:"bpmn__node_marker bpmn__task_marker",id:e}),(t||this.multiInstance==="parallel"||this.loop||this.compensation||i)&&d.jsxs("span",{className:"bpmn__task_bottom_markers",children:[this.loop&&d.jsx(Cd,{"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"})}),t&&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(ga,"TaskNode");let L=ga;const pa=class pa extends ae{sourceType="unknown";constructor(e,t){super(e,{...t,box:t.box||new M([0,0,200,100])}),this.sourceType=t.sourceType||"unknown",this.classList.add("bpmn__unknown")}serialize(){return{...super.serialize(),sourceType:this.sourceType}}deserialize(e){super.deserialize(e),this.sourceType=e.sourceType||"unknown"}RenderOverlay=A.observer(()=>d.jsx("div",{...q(this),children:d.jsx("div",{className:"bpmn__unknown__marker",children:"?"})}))};o(pa,"UnknownBPMNNode");let zt=pa;const Ro="bpmn--event-drop-inside",Go="bpmn--event-drop-attach";function nh(n){return n.canAttach}o(nh,"canAttach");function ih(n){return n.type===O.subprocess||n.type===O.eventSubprocess}o(ih,"canContainEvent");function Vo(n,e){const t=n.middle,i=e.x,s=e.x+e.width,r=e.y,a=e.y+e.height,l=new y([Math.min(s,Math.max(i,t.x)),Math.min(a,Math.max(r,t.y))]);if(e.collides(t)){const u=[{distance:Math.abs(t.x-i),x:i,y:t.y},{distance:Math.abs(s-t.x),x:s,y:t.y},{distance:Math.abs(t.y-r),x:t.x,y:r},{distance:Math.abs(a-t.y),x:t.x,y:a}].reduce((p,g)=>g.distance<p.distance?g:p);l.assign([u.x,u.y])}else l.x>i&&l.x<s?l.y=t.y<r?r:a:l.y>r&&l.y<a&&(l.x=t.x<i?i:s);return new M([l.x-n.width/2,l.y-n.height/2,n.width,n.height])}o(Vo,"projectToTaskBoundary");function sh(n,e){const t=e.x+e.width-n.width,i=e.y+e.height-n.height,s=t<e.x?e.x+(e.width-n.width)/2:Math.min(t,Math.max(e.x,n.x)),r=i<e.y?e.y+(e.height-n.height)/2:Math.min(i,Math.max(e.y,n.y));return new M([s,r,n.width,n.height])}o(sh,"clampInsideContainer");const fa=class fa extends F{draggedEventIds=new Set;init(){this.diagram.onEvent(fe,e=>this.handleDrag(e),this.diagram.priorities.Drag_Node_Snap_To_Grid-1),this.diagram.onEvent(ne,()=>{this.finishEventDrags(),this.clearDropPresentations()},this.diagram.priorities.Mouse_Up_Selector-1),this.diagram.onEvent(tt,e=>{e.cancelled||!(e.node instanceof L)||[...this.attachedEvents(e.node.id),...this.subprocessEvents(e.node.id)].forEach(t=>this.diagram.delete(t))},-100)}attachedEvents(e){return this.diagram.nodes.filter(t=>t instanceof I&&t.attachedToTaskId===e)}subprocessEvents(e){return this.diagram.nodes.filter(t=>t instanceof I&&t.subprocessId===e)}handleDrag(e){this.clearDropPresentations();const t=[...e.proposals],i=new Map(t.map(s=>[s.node.id,s]));t.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()))}),t.forEach(s=>{s.node instanceof L&&this.moveAttachedEvents(s.node,s.get(),i,e.proposals)})}clearDropPresentations(){this.diagram.nodes.forEach(e=>{e instanceof L&&(e.classList.delete(Ro),e.classList.delete(Go))})}presentDropTarget(e,t){const i=this.findInternalDropTarget(t);if(i){i.classList.add(Ro);return}e.canAttach&&this.findAttachmentDropTarget(t)?.classList.add(Go)}findInternalDropTarget(e){return this.diagram.nodes.filter(t=>t instanceof L&&ih(t)&&t.box.x<=e.x&&t.box.y<=e.y&&t.box.x+t.box.width>=e.x+e.width&&t.box.y+t.box.height>=e.y+e.height).sort((t,i)=>t.box.width*t.box.height-i.box.width*i.box.height)[0]??null}findAttachmentDropTarget(e){return this.diagram.nodes.filter(t=>t instanceof L&&t.box.collides(e,!0)).sort((t,i)=>t.box.middle.distance(e.middle)-i.box.middle.distance(e.middle))[0]??null}constrainAttachedEvent(e,t){if(!e.attachedToTaskId)return;const i=this.diagram.getNodeById(e.attachedToTaskId);if(!(i instanceof L)){e.setAttachment(null);return}const s=t.get();if(this.findInternalDropTarget(s)||!i.box.collides(s,!0)){e.setAttachment(null);return}t.update(Vo(s,i.box))}constrainSubprocessEvent(e,t,i){if(!e.subprocessStart||!e.subprocessId)return!1;const s=this.diagram.getNodeById(e.subprocessId);if(!(s instanceof L)||s.type!==O.eventSubprocess)return e.setSubprocessStart(!1),!1;const r=i.get(s.id)?.get()??s.box;return t.update(sh(t.get(),r)),!0}moveAttachedEvents(e,t,i,s){this.attachedEvents(e.id).forEach(r=>{const a=r.attachmentOffset??r.coordinates.copy(!1).substract(e.coordinates).raw,l=new M([t.x+a[0],t.y+a[1],r.box.width,r.box.height]),c=i.get(r.id);if(c)c.update(l);else{const h=new St(r,l);i.set(r.id,h),s.push(h)}})}finishEventDrags(){const e=[...this.draggedEventIds];this.draggedEventIds.clear(),e.forEach(t=>{const i=this.diagram.getNodeById(t);if(!(i instanceof I)||!nh(i))return;const s=i.attachedToTaskId?this.diagram.getNodeById(i.attachedToTaskId):null,r=s instanceof L?s:this.findDropTask(i);if(!r)return;const a=Vo(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(e){return this.findInternalDropTarget(e.box)?null:this.findAttachmentDropTarget(e.box)}};o(fa,"BPMNEventAttachments");let cs=fa;function Wo(n){return n.children.length?n.children.reduce((e,t)=>e+Wo(t),0):1}o(Wo,"leafCount$1");const ma=class ma extends F{init(){this.diagram.onEvent(fe,t=>this.snapOneGridNodes(t),this.diagram.priorities.Drag_Node_Snap_To_Grid+1);const e=this.diagram.getExtension(Be);e?.registerVerticalSuggestionProvider((t,i)=>this.enabled&&e.enabled?this.getLaneSuggestions(t,i):[]),e?.registerHorizontalSuggestionProvider((t,i)=>this.enabled&&e.enabled?this.getHorizontalLaneSuggestions(t,i):[])}snapOneGridNodes(e){const t=this.diagram.getExtension(B);if(!this.enabled||t?.enabled!==!0)return;const i=this.diagram.getClass("EventNode"),s=this.diagram.getClass("GateNode"),r=this.diagram.getClass("DocumentNode");for(const a of e.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/t.gridSize)*t.gridSize,l.y=Math.round(l.middle.y/t.gridSize)*t.gridSize-l.height/2,a.update(l),a.lockX(),a.lockY()}}resize(e,t){const i=this.diagram.getExtension(B),s=i?.gridSize??50,r=e.constructor;if("width"in t){const x=s*r.minimumWidthInGrids,b=e.box,v=this.constrain(t.width,x,null),w=new M([b.x,b.y,v,b.height],!1),_=w.copy();i?.enabled===!0&&(_.width=this.snapGrowingEdge(w.rightMiddle.x,b.x+x,s)-b.x);const k=this.diagram.getExtension(Je)?.suggest(e,w,"e",_,new y([x,b.height],!1)).width??_.width;return e.state.box.width===k?!1:(e.state.box.width=k,!0)}const a=e.laneLayouts.find(({lane:x})=>x.name===t.laneId);if(!a)return!1;const l=Wo(a.lane)*r.minimumLaneHeight,c=e.box,h=c.y+a.y,u=Math.max(l,t.height),p=new M([c.x,h,c.width,u],!1),g=p.copy();i?.enabled===!0&&(g.height=this.snapGrowingEdge(p.bottomMiddle.y,h+l,s)-h);const m=this.diagram.getExtension(Je)?.suggest(e,p,"s",g,new y([c.width,l],!1)).height??g.height;return e.resizeLane(t.laneId,m)}snapGrowingEdge(e,t,i){const s=Math.ceil(t/i)*i,r=Math.round(e/i)*i;return Math.max(s,r)}constrain(e,t,i){const s=i?Math.ceil(t/i)*i:t,r=i?Math.round(e/i)*i:e;return Math.max(s,r)}getLaneSuggestions(e,t){const i=this.diagram.getClass("Lanes");if(!i||e instanceof i)return[];const s=this.diagram.nodes.filter(g=>g instanceof i).flatMap(g=>{const m=g.box;return g.laneLayouts.filter(({lane:x})=>x.children.length===0).map(x=>({lanes:g,laneBox:m,layout:x}))}).filter(({laneBox:g,layout:m})=>{const x=g.x+(m.depth+1)*i.laneHeaderWidth,b=g.y+m.y;return t.middle.x>=x&&t.middle.x<=g.x+g.width&&t.middle.y>=b&&t.middle.y<=b+m.height}).sort((g,m)=>m.layout.depth-g.layout.depth)[0];if(!s)return[];const r=this.diagram.getExtension(B)?.gridSize??50,{laneBox:a,layout:l}=s,c=a.y+l.y,u=[a.x+(l.depth+1)*i.laneHeaderWidth,a.x+a.width],p=[{nodeY:c+(l.height-t.height)/2,guideY:c+l.height/2,range:u}];if(l.height>r*3){const g=r/2;p.push({nodeY:c+g,guideY:c+g,range:u},{nodeY:c+l.height-g-t.height,guideY:c+l.height-g,range:u})}return p}getHorizontalLaneSuggestions(e,t){const i=this.diagram.getClass("Lanes");if(!i||e instanceof i)return[];const s=this.diagram.nodes.filter(m=>m instanceof i).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)*i.laneHeaderWidth,v=m.y+x.y;return t.middle.x>=b&&t.middle.x<=m.x+m.width&&t.middle.y>=v&&t.middle.y<=v+x.height}).sort((m,x)=>x.layout.depth-m.layout.depth)[0];if(!s)return[];const a=(this.diagram.getExtension(B)?.gridSize??50)/2,{laneBox:l,layout:c}=s,h=l.y+c.y,u=l.x+(c.depth+1)*i.laneHeaderWidth,p=l.x+l.width,g=[h,h+c.height];return[{nodeX:u+a,guideX:u+a,range:g},{nodeX:p-a-t.width,guideX:p-a,range:g}]}};o(ma,"BPMNGridSnap");let yn=ma;const ya=class ya extends ee{};o(ya,"BPMNLaneChangeEvent");let Qe=ya;const ba=class ba extends F{autopan=new _e(this.diagram);session=null;unbindSession=o(()=>{},"unbindSession");init(){}resizeWidth(e,t){if(t.button!==0)return;t.stopImmediatePropagation();const i=this.diagram.canvas.inverseFit(new y(t)),s=e.state.box.width;this.startSession(t,r=>{const a=this.diagram.canvas.inverseFit(r);return this.diagram.getExtension(yn).resize(e,{width:s+a.x-i.x})})}resizeHeight(e,t,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(yn).resize(e,{laneId:t,height:i+l.y-r.y})})}startSession(e,t){this.endSession(),this.session={changed:!1,pointer:new y(e),resize:t},this.unbindSession=Me(Y(this,"mousemove",this.handleMouseMove),Y(this,"mouseup",this.endSession),ni(this.handleAutopan,30))}handleMouseMove(e){this.session&&(this.session.pointer=new y(e),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 e=this.session;this.session=null;const t=this.unbindSession;this.unbindSession=()=>{},t(),this.diagram?.getExtension?.(Je)?.clear(),e?.changed&&this.emit(new Qe(this))}};o(ba,"BPMNLaneResizer");let Ft=ba;const xa=class xa extends ae{minimumResizeSize=new y([300,100],!1);edgesAsGateways=!0;constructor(e,t){super(e,{...t,box:t.box||new M([0,0,500,150]),groupChildren:!1}),this.classList.add("bpmn__black_box_pool","bpmn__resizable_node")}RenderScreen=rh;RenderOverlay=A.observer(()=>{const e=this.box,t=q(this),i=1.5;return d.jsx("div",{...t,style:{...t.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 ${e.width} ${e.height}`,children:d.jsx("rect",{fill:"var(--node-fill)",height:Math.max(0,e.height-i*2),stroke:"var(--node-stroke)",strokeWidth:"2",vectorEffect:"non-scaling-stroke",width:Math.max(0,e.width-i*2),x:i,y:i})})})})};o(xa,"BlackBoxPoolNode");let ge=xa;const rh=A.observer(({node:n})=>{const e=n.diagram?.bpmnLabels??Ae,t=S.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 M([i.x+s,i.y+(i.height-a)/2,Math.max(0,i.width-s*2),a]),c=Le(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"},p=n.diagram?.rules.allowEdition!==!1;return(!n.editionMode||!p)&&(t.current=!1),d.jsxs(d.Fragment,{children:[(!n.editionMode||!p)&&n.state.label&&d.jsx("pre",{...c,className:h,style:u,children:n.state.label}),n.editionMode&&p&&d.jsx("textarea",{...c,"aria-label":e.inputs.blackBoxPoolName,autoFocus:!0,className:h,onChange:o(g=>{f.runInAction(()=>{n.state.label=g.target.value})},"onChange"),onKeyDownCapture:o(g=>{ci(g.nativeEvent)||g.nativeEvent.stopImmediatePropagation()},"onKeyDownCapture"),onMouseDown:o(g=>g.nativeEvent.stopImmediatePropagation(),"onMouseDown"),ref:o(g=>{g&&!t.current&&(t.current=!0,g.select())},"ref"),rows:1,style:{...u,outline:0,resize:"none"},value:n.state.label,wrap:"off"}),d.jsx(bi,{node:n})]})}),va=class va extends ae{requiredEdgePathType="straight";occupiesGridSquare=!0;constructor(e,t){super(e,t),this.fitToGridSquare(),this.classList.add("bpmn__data_store")}get screenLabelBox(){const e=this.box,t=Math.max(e.width,120),i=Math.max(this.state.labelFontSize??14,14);return new M([e.x+e.width/2-t/2,e.y+e.height+5,t,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(va,"DataStoreNode");let be=va;const wa=class wa extends ae{minimumResizeSize=new y([0,0],!1);edgesAsGateways=!0;constructor(e,t){super(e,{...t,box:t.box||new M([0,0,180,120])}),this.classList.add("bpmn__document_annotation","bpmn__resizable_node")}findAutomaticGatewayAnchor(e){return this.findAutomaticConnectionAnchor(e)}RenderScreen=ah;RenderOverlay=A.observer(()=>{const e=this.box,t=q(this),i=1.5,s=Math.min(24,e.width/4,e.height/3),r=Math.max(i,e.width-i),a=Math.max(i,e.height-i),l=Math.max(i,r-s),c=Math.min(a,i+s);return d.jsx("div",{...t,style:{...t.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 ${e.width} ${e.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 oe=wa;const ah=A.observer(({node:n})=>{const e=n.diagram?.bpmnLabels??Ae,t=S.useRef(!1),i=n.box,s=Math.min(8,i.width/6,i.height/6),r=new M([i.x+s,i.y+s,Math.max(0,i.width-s*2),Math.max(0,i.height-s*2)]),a=Le(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)&&(t.current=!1),n.editionMode&&c?d.jsxs(d.Fragment,{children:[d.jsx("textarea",{...a,"aria-label":e.inputs.documentAnnotationText,autoFocus:!0,className:`${l} editable__label`,onChange:o(h=>{f.runInAction(()=>{n.state.label=h.target.value})},"onChange"),onKeyDownCapture:o(h=>{ci(h.nativeEvent)||h.nativeEvent.stopImmediatePropagation()},"onKeyDownCapture"),onMouseDown:o(h=>h.nativeEvent.stopImmediatePropagation(),"onMouseDown"),ref:o(h=>{h&&!t.current&&(t.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(bi,{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(bi,{node:n})]})});var Ce=(n=>(n[n.normal=0]="normal",n[n.input=1]="input",n[n.output=2]="output",n))(Ce||{});const Yo=new Set(Object.values(Ce).filter(n=>typeof n=="number")),Ea=class Ea extends ae{type=-1;requiredEdgePathType="straight";occupiesGridSquare=!0;constructor(e,t){super(e,t),this.fitToGridSquare(),this.classList.add("bpmn__document"),f.makeObservable(this,{type:f.observable,setType:f.action}),this.setType(t.type??0)}setType(e){return Yo.has(e)?this.type===e?!0:this.emit(new pe(this)).cancelled?!1:(Yo.has(this.type)&&this.classList.delete(`bpmn--dataObject-${Ce[this.type]}`),this.type=e,this.classList.add(`bpmn--dataObject-${Ce[e]}`),!0):!1}serialize(){return{...super.serialize(),type:this.type}}deserialize(e){this.setType(e.type??0),super.deserialize(e)}get screenLabelBox(){const e=this.box,t=Math.max(e.width,120),i=Math.max(this.state.labelFontSize??16,16);return new M([e.x+e.width/2-t/2,e.y+e.height+5,t,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(Ea,"DocumentNode");let se=Ea;function oh(n){n.preventDefault(),n.stopPropagation(),n.nativeEvent.stopImmediatePropagation()}o(oh,"stopToolEvent$1");const lh=A.observer(({node:n})=>{const e=n.diagram?.bpmnLabels??Ae,t=n.box,i=n.diagram?.rules.allowEdition!==!1,s=S.useRef(null),r=n.laneLayouts;return d.jsxs(d.Fragment,{children:[r.map(({lane:a,depth:l,y:c,height:h,siblingCount:u})=>{const p=new M([t.x+l*le.laneHeaderWidth,t.y+c,le.laneHeaderWidth,h]),g=Le(n,p),m=i&&n.editingLaneId===a.name,x=l===0?u>1:u>2;return S.createElement("div",{...g,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(${le.laneHeaderFontSize}px * var(--diagram-canvas-scale, 1))`},children:a.label}),m&&d.jsx("input",{"aria-label":e.inputs.laneName,className:"lane__screenLabelInput",autoFocus:!0,value:a.label,onMouseDown:o(b=>b.nativeEvent.stopImmediatePropagation(),"onMouseDown"),onKeyDownCapture:o(b=>{n.editionMode&&!ci(b.nativeEvent)&&b.nativeEvent.stopImmediatePropagation()},"onKeyDownCapture"),onKeyDown:o(b=>{if(b.code!=="Tab")return;b.preventDefault();const v=r.findIndex(({lane:k})=>k.name===a.name),w=b.shiftKey?-1:1,_=r[(v+w+r.length)%r.length];n.renameLane(_.lane.name)},"onKeyDown"),onChange:o(b=>{f.runInAction(()=>{a.label=b.target.value})},"onChange"),ref:o(b=>{b&&s.current!==a.name&&(s.current=a.name,b.select())},"ref")}),i&&d.jsxs("div",{className:"lane__headerTools",onMouseDown:oh,children:[d.jsx("button",{title:e.lanes.rename,"aria-label":e.lanes.rename,onClick:o(()=>n.renameLane(a.name),"onClick"),children:d.jsx(ud,{})}),d.jsx("button",{title:e.lanes.insertBefore,"aria-label":e.lanes.insertBefore,onClick:o(()=>n.insertLane(a.name,"before"),"onClick"),children:d.jsx(dd,{})}),d.jsx("button",{title:a.children.length?e.lanes.removeSubdivision:e.lanes.subdivide,"aria-label":a.children.length?e.lanes.removeSubdivision:e.lanes.subdivide,onClick:o(()=>a.children.length?n.removeSubdivision(a.name):n.subdivideLane(a.name),"onClick"),children:a.children.length?d.jsx(pd,{}):d.jsx(md,{})}),x&&d.jsx("button",{title:e.lanes.removeLane,"aria-label":e.lanes.removeLane,onClick:o(()=>n.removeLane(a.name),"onClick"),children:d.jsx(To,{})}),d.jsx("button",{title:e.lanes.insertAfter,"aria-label":e.lanes.insertAfter,onClick:o(()=>n.insertLane(a.name,"after"),"onClick"),children:d.jsx(hd,{})})]}))}),i&&d.jsxs(d.Fragment,{children:[d.jsx("div",{...Le(n,new M([t.x+t.width-4,t.y,8,t.height])),className:"lane__screenWidthResizeBar",onMouseDown:o(a=>n.diagram.getExtension(Ft).resizeWidth(n,a.nativeEvent),"onMouseDown")}),d.jsx("div",{...Le(n,new M([t.x+t.width-5,t.y+t.height/2-5,10,10])),className:"lane__screenWidthResize",onMouseDown:o(a=>n.diagram.getExtension(Ft).resizeWidth(n,a.nativeEvent),"onMouseDown")}),r.map(({lane:a,y:l,height:c})=>S.createElement("div",{...Le(n,new M([t.x,t.y+l+c-3,t.width,6])),key:`resize-${a.name}`,className:"lane__screenHeightResize",onMouseDown:o(h=>n.diagram.getExtension(Ft).resizeHeight(n,a.name,c,h.nativeEvent),"onMouseDown")}))]})]})});function dt(n){return n.children.length?n.children.reduce((e,t)=>e+dt(t),0):n.height}o(dt,"laneHeight");function ds(n){return n.children.length?n.children.reduce((e,t)=>e+ds(t),0):1}o(ds,"leafCount");function Zo(n,e=0,t=0){const i=[];let s=t;return n.forEach(r=>{const a=dt(r);i.push({lane:r,depth:e,y:s,height:a,siblingCount:n.length}),r.children.length&&i.push(...Zo(r.children,e+1,s)),s+=a}),i}o(Zo,"flattenLanes");function ht(n,e,t=null){for(let i=0;i<n.length;i++){const s=n[i];if(s.name===e)return{lane:s,siblings:n,index:i,parent:t};const r=ht(s.children,e,s);if(r)return r}return null}o(ht,"findLane");function Ko(n){const e=n.children.map(Ko);if(e.length!==1)return{...n,children:e};const[t]=e;return{...n,height:dt(t),children:t.children}}o(Ko,"normalizeLane");function ch(n){return n.map(Ko)}o(ch,"normalizeLanes");function Uo(n,e){if(!n.children.length){const s=Math.max(le.minimumLaneHeight,e);return n.height===s?!1:(n.height=s,!0)}let t=!1,i=e-dt(n);for(let s=n.children.length-1;s>=0;s--){const r=n.children[s],a=dt(r),l=ds(r)*le.minimumLaneHeight,c=Math.max(l-a,i);if(t=Uo(r,a+c)||t,i-=c,i>=0)break}return t}o(Uo,"resizeLaneLeaves");const te=class te extends ae{edgesAsGateways=!1;pools;constructor(e,t){super(e,{...t,label:"",zIndex:50,groupChildren:!0}),this.pools=[{label:this.labels.lanes.defaultLane,name:"default",height:te.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=te.minimumWidthInGrids*50,this._gateways.clear()}setDiagram(e){const t=this.pools.length===1&&this.pools[0].name==="default"&&this.pools[0].label===Ae.lanes.defaultLane;super.setDiagram(e),t&&(this.pools[0].label=this.labels.lanes.defaultLane),this.state.box.width=Math.max(this.state.box.width,e.getExtension(B).gridSize*te.minimumWidthInGrids)}get box(){const e=this.pools.reduce((t,i)=>t+dt(i),0);return new M([this.state.box.x,this.state.box.y,this.state.box.width,e])}get laneLayouts(){return Zo(this.pools)}get editingLaneId(){return this.editionLaneId}get labels(){return this.diagram?.bpmnLabels??Ae}nextPool(e=[]){const t=new Set([...this.laneLayouts.map(({lane:s})=>s.name),...e]);let i=0;for(;t.has(`pool${i}`);)i++;return{label:`${this.labels.lanes.pool} ${i}`,name:`pool${i}`,height:te.laneHeight,children:[]}}addPool(){if(this.emit(new Qe(this)).cancelled)return this.pools.at(-1);const e=this.nextPool();return this.pools.push(e),e}insertLane(e,t){const i=ht(this.pools,e);!i||this.emit(new Qe(this)).cancelled||i.siblings.splice(i.index+(t==="after"?1:0),0,this.nextPool())}subdivideLane(e){const t=ht(this.pools,e);if(!t||t.lane.children.length||this.emit(new Qe(this)).cancelled)return;const i=this.nextPool(),s=this.nextPool([i.name]),r=Math.max(t.lane.height,te.minimumLaneHeight*2);i.height=r/2,s.height=r/2,t.lane.children=[i,s]}removeSubdivision(e){const t=ht(this.pools,e);!t||!t.lane.children.length||this.emit(new Qe(this)).cancelled||(t.lane.height=dt(t.lane),t.lane.children=[])}removeLane(e){const t=ht(this.pools,e);!t||t.siblings.length<=1||t.parent&&t.siblings.length<=2||this.emit(new Qe(this)).cancelled||t.siblings.splice(t.index,1)}resizeLane(e,t,i){const s=ht(this.pools,e);if(!s)return!1;const r=ds(s.lane)*te.minimumLaneHeight,a=i?Math.ceil(r/i)*i:r;return Uo(s.lane,Math.max(t,a))}renameLane(e){if(ht(this.pools,e)){if(!this.editionMode){const t=this.diagram?.getExtension(di);t?t.editNode(this):this.edit()}this.editionLaneId=e}}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=fn(this.pools)}resetPools(){this.pools=[]}deserialize(e){super.deserialize(e),this.pools=ch(e.pools)}serialize(){return{...super.serialize(),pools:fn(this.pools)}}RenderScreen=lh;RenderOverlay=A.observer(()=>{const e=this.laneLayouts,t=this.box;return d.jsx("div",{...q(this),children:d.jsxs("svg",{className:"lane__svg",viewBox:`0 0 ${t.width} ${t.height}`,preserveAspectRatio:"none",children:[d.jsx("rect",{className:"lane__background",width:t.width,height:t.height}),e.map(({lane:i,depth:s,y:r,height:a})=>{const l=s*te.laneHeaderWidth,c=l+te.laneHeaderWidth,h=r;return d.jsxs("g",{children:[d.jsx("rect",{className:"lane__head",x:l,y:h,width:te.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,t.width-c),height:a})]},i.name)})]})})})};o(te,"Lanes"),$e(te,"laneHeaderWidth",50),$e(te,"laneHeight",250),$e(te,"laneHeaderFontSize",16),$e(te,"minimumLaneHeight",150),$e(te,"minimumWidthInGrids",10);let le=te;const _a=class _a extends ae{edgesAsGateways=!0;requiredEdgePathType="straight";constructor(e,t){super(e,{...t,box:t.box||new M([0,0,180,90])}),this.classList.add("bpmn__text_annotation"),this._gateways.clear(),this._gateways.set("left",new Se(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 e=this.state.box,i=(this.diagram?.getExtension(B)?.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(g=>g.length),1),c=Math.min(i,Math.max(e.width,l*r+28)),h=Math.max(1,Math.floor((c-28)/r)),u=a.reduce((g,m)=>g+Math.max(1,Math.ceil(m.length/h)),0),p=Math.min(i,Math.max(e.height,u*s*1.35+24));return new M([e.x,e.y,c,p])}serialize(){return{...super.serialize(),box:this.box.raw}}findAutomaticGatewayAnchor(e){return this.findAutomaticConnectionAnchor(e)}RenderOverlay=A.observer(()=>d.jsx("div",{...q(this),children:d.jsx("span",{className:"bpmn__annotation_bracket"})}))};o(_a,"TextAnnotationNode");let ce=_a;const $t=[{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}],dh={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"}},qo={task:O.task,serviceTask:O.service,sendTask:O.send,receiveTask:O.receive,scriptTask:O.script,manualTask:O.manual,businessRuleTask:O.businessRule,callActivity:O.callActivity,subprocess:O.subprocess,eventSubprocess:O.eventSubprocess},hh=new Map(Object.entries(qo).map(([n,e])=>[e,n]));function uh(n,e){const t=dh[e];if(!t)return null;if(e==="start"||e==="intermediate"||e==="end")return t;const i=ct({...t,stage:n.stage})?n.stage:t.stage,s=ct({...t,direction:n.direction})?n.direction:t.direction;return{...t,stage:i,direction:s}}o(uh,"eventDefinitionForTarget");const ka=class ka{static enabled(){return $t.filter(e=>e.enabled).sort((e,t)=>e.priority-t.priority)}static forNode(e){const t=this.idForNode(e);return $t.find(i=>i.id===t)}static idForNode(e){if(e instanceof L)return hh.get(e.type)??"task";if(e instanceof I)return e.kind==="none"?e.stage:e.kind==="message"?e.isCatching?"messageCatch":"messageThrow":e.kind;if(e instanceof W)return e.type===H.inclusive?"inclusive":e.type===H.parallel?"parallel":e.type===H.eventBased?"eventBased":e.type===H.complex?"complex":"exclusive";if(e instanceof le)return"lanes";if(e instanceof ge)return"blackBoxPool";if(e instanceof be)return"dataStore";if(e instanceof se)return e.type===Ce.input?"dataInput":e.type===Ce.output?"dataOutput":"document";if(e instanceof oe)return"documentAnnotation";if(e instanceof ce)return"textAnnotation"}static create(e,t,i){const s={id:t,label:i,movable:!0};switch(e){case"task":return new L(null,{...s,type:O.task});case"serviceTask":return new L(null,{...s,type:O.service});case"sendTask":return new L(null,{...s,type:O.send});case"receiveTask":return new L(null,{...s,type:O.receive});case"scriptTask":return new L(null,{...s,type:O.script});case"manualTask":return new L(null,{...s,type:O.manual});case"businessRuleTask":return new L(null,{...s,type:O.businessRule});case"callActivity":return new L(null,{...s,type:O.callActivity});case"subprocess":return new L(null,{...s,type:O.subprocess});case"eventSubprocess":return new L(null,{...s,type:O.eventSubprocess});case"start":return new I(null,{...s,type:j.start});case"intermediate":return new I(null,{...s,type:j.intermediate});case"end":return new I(null,{...s,type:j.end});case"timer":return new I(null,{...s,type:j.timer});case"messageCatch":return new I(null,{...s,type:j.messageCatch});case"messageThrow":return new I(null,{...s,type:j.messageThrow});case"signal":return new I(null,{...s,type:j.signalCatch});case"compensation":return new I(null,{...s,type:j.compensationCatch});case"error":return new I(null,{...s,type:j.errorCatch});case"conditional":return new I(null,{...s,type:j.conditional});case"cancel":return new I(null,{...s,type:j.cancelCatch});case"escalation":return new I(null,{...s,type:j.escalationCatch});case"link":return new I(null,{...s,type:j.linkCatch});case"multiple":return new I(null,{...s,type:j.multipleCatch});case"parallelMultiple":return new I(null,{...s,type:j.parallelMultiple});case"terminate":return new I(null,{...s,type:j.terminate});case"inclusive":return new W(null,{...s,type:H.inclusive});case"parallel":return new W(null,{...s,type:H.parallel});case"eventBased":return new W(null,{...s,type:H.eventBased});case"complex":return new W(null,{...s,type:H.complex});case"lanes":return new le(null,{id:t});case"blackBoxPool":return new ge(null,s);case"dataStore":return new be(null,s);case"document":return new se(null,s);case"dataInput":return new se(null,{...s,type:Ce.input});case"dataOutput":return new se(null,{...s,type:Ce.output});case"documentAnnotation":return new oe(null,s);case"textAnnotation":return new ce(null,s);default:return new W(null,{...s,type:H.exclusive})}}static transform(e,t){const i=this.forNode(e),s=$t.find(r=>r.id===t);if(!i||!s||i.family!==s.family||!s.enabled)return!1;if(e instanceof L){const r=qo[t];return r===void 0?!1:e.setType(r)}if(e instanceof I){const r=uh(e,t);return!r||e.attachedToTaskId&&!["timer","message","signal","compensation","error","conditional"].includes(r.kind)?!1:e.setDefinition(r)}if(e instanceof W)return e.setType(t==="inclusive"?H.inclusive:t==="parallel"?H.parallel:t==="eventBased"?H.eventBased:t==="complex"?H.complex:H.exclusive),!0;if(e instanceof se){const r=t==="dataInput"?Ce.input:t==="dataOutput"?Ce.output:t==="document"?Ce.normal:null;return r===null?!1:e.setType(r)}return!1}};o(ka,"BPMNElementCatalog");let de=ka;function gh(n){return n instanceof I&&n.attachedToTaskId!==null&&n.kind==="compensation"}o(gh,"isBoundaryCompensationEvent");const $n=class $n extends Re{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 e=this.state.from?.parent;return this.kind==="sequenceFlow"&&!!this.state.to&&e instanceof W&&(e.type===H.exclusive||e.type===H.inclusive)}constructor(e,t){super(e,t),this.kind=t.kind??(t.to?$n.inferKind(t.from.parent,t.to.parent):null)??"sequenceFlow",this.condition=t.condition??"",this.defaultFlow=!1,this.directedFlow=t.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(t.isDefault===!0)}static inferKind(e,t){return e instanceof ce||t instanceof ce||e instanceof oe||t instanceof oe?"association":gh(e)?t instanceof L&&t.compensation?"association":null:(e instanceof be||e instanceof se)&&t instanceof L?"inputDataAssociation":e instanceof L&&(t instanceof be||t instanceof se)?"outputDataAssociation":e instanceof ge&&(t instanceof ge||t instanceof L||t instanceof I||t instanceof W)||t instanceof ge&&(e instanceof L||e instanceof I||e instanceof W)||e instanceof I&&e.kind==="message"&&!e.isCatching&&(t instanceof I||t instanceof W)?"messageFlow":(e instanceof L||e instanceof I||e instanceof W)&&(t instanceof L||t instanceof I||t instanceof W)?e instanceof I&&e.isEnd||t instanceof I&&(t.isStart||t.attachedToTaskId)||e instanceof W&&e.type===H.eventBased&&!(t instanceof I&&t.isCatching&&["message","timer","signal","conditional"].includes(t.kind)||t instanceof L&&t.type===O.receive)?null:"sequenceFlow":null}setKind(e){const t=this.supportsDirection;this.kind=e,!t&&this.supportsDirection&&(this.directedFlow=!0),this.supportsDefaultFlow||(this.defaultFlow=!1),this.applyStyle()}setDefault(e){const t=e&&this.supportsDefaultFlow;return t&&this.clearOtherDefaultFlows(),this.defaultFlow=t,this.applyStyle(),t===e}setDirected(e){return this.supportsDirection?(this.directedFlow=e,this.applyStyle(),!0):!1}applyResolvedAnchors(e,t){const i=this.defaultFlow;super.applyResolvedAnchors(e,t),i&&this.setDefault(!0)}reverseDirection(){const e=this.defaultFlow;this.defaultFlow=!1;const t=this.state.from,i=this.state.to;t.removeOutgoingEdge(this),i.removeIncomingEdge(this),this.state.from=i,this.state.to=t,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),t.addIncomingEdge(this),this.kind==="inputDataAssociation"?this.kind="outputDataAssociation":this.kind==="outputDataAssociation"&&(this.kind="inputDataAssociation"),e?this.setDefault(!0):this.applyStyle()}clearOtherDefaultFlows(){const e=this.from.parent;e instanceof W&&e.gateways.forEach(t=>t.outgoingEdges.forEach(i=>{i instanceof $n&&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(e){super.deserialize(e),this.kind=e.kind,this.condition=e.condition,this.defaultFlow=!1,this.directedFlow=e.isDirected??this.supportsDirection,this.setDefault(e.isDefault===!0)}};o($n,"BPMNEdge");let xe=$n;function Xo(n){return n.normalize("NFD").replace(new RegExp("\\p{Diacritic}","gu"),"").toLowerCase()}o(Xo,"normalizeSearchValue");function Jo({autoFocus:n,items:e,labels:t,onSelect:i,selectedId:s}){const[r,a]=S.useState(""),l=S.useRef(null),c=Xo(r.trim()),h=c?e.filter(u=>Xo(t.elements[u.id]).includes(c)):e;return S.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":t.inputs.elementSearch,className:"bpmn__element_menu_search",onChange:o(u=>a(u.target.value),"onChange"),onMouseDown:o(u=>u.stopPropagation(),"onMouseDown"),placeholder:t.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(We,{id:u.id}),d.jsx("span",{children:t.elements[u.id]})]},u.id))})]})}o(Jo,"BPMNElementMenu");const ut=8;function ph(n,e,t,i){const s=t.width-n.right,r=n.left,a=s<e.width+ut&&r>s,l=a?n.left-e.width:n.right,c=l+e.width;let h=t.height-e.height-ut;i&&c>i.left-ut&&l<i.right+ut&&(h=Math.min(h,i.top-e.height-ut));const u=Math.min(Math.max(n.top-4,ut),Math.max(ut,h));return{left:a,top:u-n.top}}o(ph,"resolveToolbarMenuPlacement");function fh(n,e,t){const i=t.copy(!1).substract(e),s=i.x**2+i.y**2;if(s<.001)return e.copy(!1);const r=n.copy(!1).substract(e),a=Math.max(0,Math.min(1,(r.x*i.x+r.y*i.y)/s));return e.copy(!1).sum(i.multiply(a))}o(fh,"closestPointOnSegment");function mh(n,e,t){const i=e.middle;let s=n[0]?.copy(!1)??i,r=s.distance(i);for(let c=0;c<n.length-1;c+=1){const h=fh(i,n[c],n[c+1]),u=h.distance(i);u<r&&(s=h,r=u)}const a=Math.min(t,e.width/2),l=Math.min(t,e.height/2);return s.x=Math.max(e.x+a,Math.min(e.x+e.width-a,s.x)),s.y=Math.max(e.y+l,Math.min(e.y+e.height-l,s.y)),s}o(mh,"resolveVisibleEdgeToolbarAnchor");function Qo(n){n.preventDefault(),n.stopPropagation(),n.nativeEvent.stopImmediatePropagation()}o(Qo,"stopToolEvent");function yh(n){if(!/(?:^| )(?:bpmn__event|bpmn__gate|bpmn__data_store|bpmn__document)(?: |$)/.test(n.classList.string))return!1;const e=n.box.middle,t=n.labelScreenBox.middle,i=t.x-e.x,s=t.y-e.y;return i>0&&Math.abs(i)>Math.abs(s)}o(yh,"isRightExternalLabel");function hs({children:n,focusSearchOnClick:e=!1,icon:t,label:i,onDragStart:s}){const[r,a]=S.useState(!1),[l,c]=S.useState(!1),[h,u]=S.useState({left:!1,top:-4}),p=S.useRef(null),g=S.useRef(null),m=S.useRef(()=>{}),x=S.useRef(!1),b=S.useRef(null);S.useEffect(()=>()=>{p.current!==null&&window.clearTimeout(p.current),g.current!==null&&window.clearTimeout(g.current),m.current()},[]),S.useLayoutEffect(()=>{if(!r||!b.current)return;const N=b.current.querySelector(".bpmn__element_menu");if(!N)return;const T=b.current.getBoundingClientRect(),V=N.getBoundingClientRect(),X=document.querySelector(".toolbar")?.getBoundingClientRect();u(ph(T,V,{width:window.innerWidth,height:window.innerHeight},X))},[r]),S.useEffect(()=>{r&&l&&c(!1)},[l,r]);const v=o(()=>{p.current!==null&&window.clearTimeout(p.current),g.current!==null&&window.clearTimeout(g.current),p.current=null,g.current=null},"clearTimers"),w=o(()=>{v(),a(!0)},"show"),_=o(()=>{r||p.current!==null||(g.current!==null&&window.clearTimeout(g.current),g.current=null,p.current=window.setTimeout(()=>{p.current=null,a(!0)},250))},"showAfterDelay"),k=o(()=>{v(),g.current=window.setTimeout(()=>a(!1),180)},"hideSoon"),C=o(N=>{if(!s||N.button!==0)return;m.current();const T=N.clientX,V=N.clientY,X=N,K=o(()=>{document.removeEventListener("mousemove",he),document.removeEventListener("mouseup",K),m.current=()=>{}},"cleanup"),he=o(Ke=>{if((Ke.buttons&1)===0){K();return}Math.hypot(Ke.clientX-T,Ke.clientY-V)<5||(K(),x.current=!0,s(X))},"handleMouseMove");m.current=K,document.addEventListener("mousemove",he),document.addEventListener("mouseup",K)},"prepareDrag"),P=o(()=>{if(x.current){x.current=!1;return}e&&c(!0),w()},"handleClick"),D=l&&S.isValidElement(n)?S.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:k,onFocusCapture:w,onMouseEnter:_,onMouseLeave:k,ref:b,style:{"--bpmn-menu-top":`${h.top}px`},children:[d.jsx("button",{"aria-expanded":r,"aria-label":i,onClick:P,onMouseDown:C,title:i,type:"button",children:t}),r&&D]})}o(hs,"ToolbarGroup");const el=A.observer(({extension:n})=>{const e=n.labels;return d.jsx("div",{className:"bpmn__toolbar_group",children:d.jsx("button",{"aria-label":e.actions.settings,"aria-pressed":n.propertiesPanelOpen,className:`tool${n.propertiesPanelOpen?" selected":""}`,onClick:o(()=>n.togglePropertiesPanel(),"onClick"),title:e.actions.settings,type:"button",children:d.jsx(We,{id:"settings"})})})}),bh=A.observer(({diagram:n,extension:e})=>{const t=e.labels,i=n.getExtension($),s=i.selectedNodes,r=i.selectedEdges,a=n.rules?.allowEdition!==!1,[l,c]=S.useState({edgeId:"",x:0,y:0}),h=S.useRef(null),u=o((p,g)=>{if(p.button!==0)return;p.preventDefault(),p.stopPropagation(),p.nativeEvent.stopImmediatePropagation();const m=l.edgeId===g?l:{x:0,y:0};h.current={edgeId:g,offsetX:m.x,offsetY:m.y,pointerId:p.pointerId,startX:p.clientX,startY:p.clientY};const x=o(w=>{const _=h.current;!_||_.pointerId!==w.pointerId||(w.preventDefault(),c({edgeId:_.edgeId,x:_.offsetX+w.clientX-_.startX,y:_.offsetY+w.clientY-_.startY}))},"move"),b=o(()=>{document.removeEventListener("pointermove",x),document.removeEventListener("pointerup",v),document.removeEventListener("pointercancel",v),h.current=null},"cleanup"),v=o(w=>{w.pointerId===p.pointerId&&b()},"finish");document.addEventListener("pointermove",x,{passive:!1}),document.addEventListener("pointerup",v,{once:!0}),document.addEventListener("pointercancel",v,{once:!0})},"startEdgeToolbarDrag");return e.dragging||e.connecting||s.length+r.length!==1?null:d.jsxs(d.Fragment,{children:[s.map(p=>{if(p instanceof le)return null;const g=a?e.transformTargets(p):[],m=de.forNode(p),x=a?e.shapeOptions(p):[],b=a?e.connectionTargets(p):[],v=p instanceof Oe&&yh(p),w=v?p.labelScreenBox:null,_=w?new M([w.x+w.width/2,w.y+w.height+8,1,1]):new M([p.box.x+p.box.width+10,p.box.y+p.box.height/2,1,1]);return S.createElement("div",{...Le(p,_),className:`bpmn__selection_toolbar${v?" bpmn__selection_toolbar--below-external-label":""}`,"data-diagram-interactive-ui":"true",key:p.id,onMouseDown:Qo},g.length>0&&d.jsx(hs,{icon:d.jsx(We,{id:"transform"}),label:t.actions.transform,children:d.jsx(Jo,{items:x,labels:t,onSelect:o(k=>e.transform(p,k.id),"onSelect"),selectedId:m?.id})}),b.length>0&&d.jsx(hs,{focusSearchOnClick:!0,icon:d.jsx(We,{id:"connect"}),label:t.actions.connect,onDragStart:o(k=>e.startToolbarConnection(p,k),"onDragStart"),children:d.jsx(Jo,{items:b,labels:t,onSelect:o(k=>e.appendConnected(p,k.id),"onSelect")})}),d.jsx(el,{extension:e}))}),r.map(p=>{if(!(p instanceof xe)||p.steps.length===0)return null;const g=n.canvas.inverseFit(n.canvas.frameDimensions),m=mh(p.steps,g,48/Math.max(n.canvas.scale,.001)),x={"--bpmn-edge-toolbar-offset-x":`${l.edgeId===p.id?l.x:0}px`,"--bpmn-edge-toolbar-offset-y":`${l.edgeId===p.id?l.y:0}px`,"--screen-renderer-x":`${m.x}px`,"--screen-renderer-y":`${m.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:x,children:[d.jsx("button",{"aria-label":"Move edge toolbar",className:"bpmn__selection_toolbar_drag_handle",onPointerDown:o(b=>u(b,p.id),"onPointerDown"),title:"Move toolbar",type:"button",children:d.jsx("span",{"aria-hidden":"true",children:"•••"})}),a&&d.jsxs(d.Fragment,{children:[d.jsx(hs,{icon:d.jsx(We,{id:"transform"}),label:t.actions.transform,children:d.jsx("div",{className:"bpmn__element_menu",role:"menu",children:e.edgeKindOptions(p).filter(b=>b!==p.kind).map(b=>d.jsxs("button",{className:"bpmn__element_menu_item",onClick:o(()=>e.changeEdgeKind(p,b),"onClick"),role:"menuitem",type:"button",children:[d.jsx(We,{id:"connect"}),d.jsx("span",{children:t.edges[b]})]},b))})}),d.jsx("div",{className:"bpmn__toolbar_group",children:d.jsx("button",{"aria-label":t.actions.reverseDirection,onClick:o(()=>e.reverseEdge(p),"onClick"),title:t.actions.reverseDirection,type:"button",children:d.jsx(Ed,{"aria-hidden":"true"})})})]}),d.jsx(el,{extension:e})]},p.id)})]})}),xh=["orthogonal","straight","curved"],vh=["message","timer","error","conditional","escalation","compensation","signal","multiple"];function tl({children:n,title:e}){const[t,i]=S.useState(!0),s=S.useId();return d.jsxs("section",{className:"bpmn__properties_section",children:[d.jsxs("button",{"aria-controls":s,"aria-expanded":t,className:"bpmn__properties_section_toggle",onClick:o(()=>i(r=>!r),"onClick"),type:"button",children:[d.jsx("span",{children:e}),d.jsx("span",{"aria-hidden":"true",className:"bpmn__properties_section_icon"})]}),d.jsx("div",{"aria-hidden":!t,className:`bpmn__properties_section_collapsible${t?" bpmn__properties_section_collapsible--open":""}`,id:s,inert:t?void 0:!0,children:d.jsx("div",{className:"bpmn__properties_section_clip",children:d.jsx("div",{className:"bpmn__properties_section_content",children:n})})})]})}o(tl,"PropertiesSection");function wh({children:n,sections:e}){return e?d.jsxs("div",{className:"bpmn__properties_sections",children:[d.jsx(tl,{title:e.generalTitle,children:n}),d.jsx(tl,{title:e.additionalTitle,children:e.additionalContent})]}):d.jsx(d.Fragment,{children:n})}o(wh,"PropertiesSections");const nl=A.observer(({diagram:n,extension:e,sections:t})=>{const i=n.getExtension($),s=i.selectedNodes.length===1?i.selectedNodes[0]:null,r=i.selectedEdges.length===1?i.selectedEdges[0]:null,a=e.propertiesPanelOpen&&!!(s||r)&&!e.dragging,l=s?de.forNode(s):void 0,c=s?e.shapeOptions(s):[],h=e.labels,u=n.rules?.allowEdition!==!1,p=u||t?.additionalEditable===!0;return d.jsxs("aside",{"aria-hidden":!a,"aria-readonly":!p,className:`bpmn__properties_panel${a?" bpmn__properties_panel--open":""}${p?"":" 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 xe?h.edges[r.kind]:""})]}),d.jsx("button",{"aria-label":h.actions.close,onClick:o(()=>e.closePropertiesPanel(),"onClick"),title:h.actions.close,type:"button",children:"×"})]}),d.jsxs(wh,{sections:t,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(g=>e.renameNode(s,g.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(g=>e.transform(s,g.target.value),"onChange"),value:l.id,children:c.map(g=>g&&d.jsx("option",{value:g.id,children:h.elements[g.id]},g.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(g=>e.changeEventKind(s,g.target.value),"onChange"),value:s.kind,children:e.eventKindOptions(s).map(g=>d.jsx("option",{value:g,children:h.elements[g==="none"?"event":g]},g))})]}),d.jsxs("label",{children:[d.jsx("span",{children:h.properties.eventStage}),d.jsx("select",{onChange:o(g=>e.changeEventStage(s,g.target.value),"onChange"),value:s.stage,children:e.eventStageOptions(s).map(g=>d.jsx("option",{value:g,children:h.eventOptions[g]},g))})]}),s.kind!=="none"&&d.jsxs("label",{children:[d.jsx("span",{children:h.properties.eventDirection}),d.jsx("select",{onChange:o(g=>e.changeEventDirection(s,g.target.value),"onChange"),value:s.direction,children:e.eventDirectionOptions(s).map(g=>d.jsx("option",{value:g,children:h.eventOptions[g]},g))})]}),s.attachedToTaskId&&d.jsxs("label",{className:"bpmn__properties_checkbox",children:[d.jsx("input",{checked:s.interrupting,onChange:o(g=>e.changeEventInterrupting(s,g.target.checked),"onChange"),type:"checkbox"}),d.jsx("span",{children:h.properties.interrupting})]})]}),s instanceof L&&d.jsxs(d.Fragment,{children:[s.type===O.eventSubprocess&&d.jsxs("label",{children:[d.jsx("span",{children:h.properties.eventSubprocessStartType}),d.jsxs("select",{onChange:o(g=>e.changeEventSubprocessStartKind(s,g.target.value),"onChange"),value:e.eventSubprocessStartKind(s),children:[d.jsx("option",{disabled:!0,value:"",children:h.eventOptions.none}),vh.map(g=>d.jsx("option",{value:g,children:h.elements[g]},g))]})]}),d.jsxs("label",{className:"bpmn__properties_checkbox",children:[d.jsx("input",{checked:s.loop,onChange:o(g=>e.changeTaskLoop(s,g.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(g=>e.changeTaskMultiInstance(s,g.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(g=>e.changeTaskCompensation(s,g.target.checked),"onChange"),type:"checkbox"}),d.jsx("span",{children:h.properties.compensation})]}),s.type===O.subprocess&&d.jsxs("label",{className:"bpmn__properties_checkbox",children:[d.jsx("input",{checked:s.adHoc,onChange:o(g=>e.changeTaskAdHoc(s,g.target.checked),"onChange"),type:"checkbox"}),d.jsx("span",{children:h.properties.adHoc})]}),[O.subprocess,O.callActivity].includes(s.type)&&d.jsxs("label",{className:"bpmn__properties_checkbox",children:[d.jsx("input",{checked:s.transaction,onChange:o(g=>e.changeTaskTransaction(s,g.target.checked),"onChange"),type:"checkbox"}),d.jsx("span",{children:h.properties.transaction})]})]})]}),r instanceof xe&&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(g=>e.renameEdge(r,g.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(g=>e.changeEdgeKind(r,g.target.value),"onChange"),value:r.kind,children:e.edgeKindOptions(r).map(g=>d.jsx("option",{value:g,children:h.edges[g]},g))})]}),d.jsxs("label",{children:[d.jsx("span",{children:h.properties.routingType}),d.jsx("select",{onChange:o(g=>e.changeEdgePathType(r,g.target.value),"onChange"),value:r.pathType,children:xh.map(g=>d.jsx("option",{value:g,children:h.routing[g]},g))})]}),e.supportsCondition(r)&&d.jsxs("label",{children:[d.jsx("span",{children:h.properties.condition}),d.jsx("textarea",{onChange:o(g=>e.changeEdgeCondition(r,g.target.value),"onChange"),rows:4,value:r.condition})]}),e.supportsDefaultFlow(r)&&d.jsxs("label",{className:"bpmn__properties_checkbox",children:[d.jsx("input",{checked:r.isDefault,onChange:o(g=>e.changeEdgeDefault(r,g.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(g=>e.changeEdgeDirected(r,g.target.checked),"onChange"),type:"checkbox"}),d.jsx("span",{children:h.properties.directed})]})]})]})]})});function Eh(n,e,t){if(!(e instanceof ce||e instanceof oe)||!(e instanceof ce&&t==="documentAnnotation"||e instanceof oe&&t==="textAnnotation"))return null;const i=new Set(e.gateways.flatMap(r=>[...r.incomingEdges,...r.outgoingEdges])),s=de.create(t,e.id,e.state.label);return f.runInAction(()=>{s.state={...e.state,box:e.box,selected:!1},n.delete(e),n.add(s),i.forEach(r=>{const a=r.from.parent===e?s.findAutomaticGatewayAnchor(r.to.parent===e?s.box.middle:r.to.parent.box.middle):r.resolveEndpointAnchor("from"),l=r.to.parent===e?s.findAutomaticGatewayAnchor(r.from.parent===e?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(Eh,"transformBPMNArtifact");const bn=new Set(["task","event","gateway"]),_h=["sequenceFlow","messageFlow","inputDataAssociation","outputDataAssociation","association"],il=["start","intermediate","end"],sl=["catch","throw"],kh=["none","message","timer","error","signal","compensation","conditional","cancel","escalation","link","multiple","parallelMultiple","terminate"],rl={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"}},al=new Set(["message","timer","error","signal","compensation","conditional","cancel","escalation","multiple","parallelMultiple"]),us=new Set(["message","timer","error","conditional","escalation","compensation","signal","multiple"]),gs="bpmn-properties-panel-open",Sh=24,Sa=class Sa extends F{dragging=!1;propertiesPanelOpen=!1;RenderDiagram=bh;RenderUI=nl;labelConfiguration=as();get labels(){return this.labelConfiguration??Ae}configureLabels(e){this.labelConfiguration=as(e,this.labels)}init(){f.makeObservable(this,{dragging:f.observable,labelConfiguration:f.observable.ref,propertiesPanelOpen:f.observable,appendConnected:f.action,configureLabels:f.action}),typeof window<"u"&&(this.propertiesPanelOpen=window.localStorage.getItem(gs)==="true"),this.diagram.registerClass(xe),this.diagram.setDefaultEdge(xe),this.diagram.onEvent(Et,e=>{(!xe.inferKind(e.origin,e.target)||e.origin instanceof I&&e.origin.attachedToTaskId&&e.origin.kind==="compensation"&&e.origin.gateways.some(t=>t.outgoingEdges.some(i=>i!==e.edge)))&&e.cancel()}),this.diagram.onEvent(fe,()=>{f.runInAction(()=>{this.dragging=!0})}),this.diagram.onEvent(ne,()=>{f.runInAction(()=>{this.dragging=!1})})}transformTargets(e){const t=de.forNode(e);if(!t)return[];const i=e.gateways.some(r=>r.incomingEdges.length),s=e.gateways.some(r=>r.outgoingEdges.length);return de.enabled().filter(r=>!(r.family!==t.family||r.id===t.id||r.id==="start"&&i||(r.id==="end"||r.id==="terminate")&&s||e instanceof I&&e.attachedToTaskId&&!["timer","messageCatch","signal","compensation","error","conditional"].includes(r.id)))}shapeOptions(e){const t=de.forNode(e);if(!t)return[];const i=new Set([t.id,...this.transformTargets(e).map(s=>s.id)]);return de.enabled().filter(s=>i.has(s.id))}transform(e,t){if(!this.transformTargets(e).some(r=>r.id===t))return!1;this.emit(new Z(this));const i=Eh(this.diagram,e,t);if(i)return e.selected&&this.diagram.getExtension($).selectNode(i),!0;const s=de.transform(e,t);return s&&e instanceof W&&e.gateways.forEach(r=>r.outgoingEdges.forEach(a=>{a instanceof xe&&!a.supportsDefaultFlow&&a.setDefault(!1)})),s}connectionTargets(e){if(e instanceof I&&e.attachedToTaskId&&e.kind==="compensation")return e.gateways.some(i=>i.outgoingEdges.length)?[]:de.enabled().filter(({id:i})=>i==="task");const t=de.idForNode(e);return t?de.enabled().filter(i=>{const s=i.connectable&&this.inferDefinitionKind(t,i.id);return!!s&&!(e instanceof I&&e.isEnd&&s==="sequenceFlow")}):[]}inferDefinitionKind(e,t){const i=$t.find(r=>r.id===e),s=$t.find(r=>r.id===t);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":e==="blackBoxPool"&&(t==="blackBoxPool"||bn.has(s.family))||t==="blackBoxPool"&&bn.has(i.family)||e==="messageThrow"&&s.family!=="task"&&bn.has(s.family)?"messageFlow":!bn.has(i.family)||!bn.has(s.family)||e==="end"||e==="terminate"||t==="start"||e==="eventBased"&&!["messageCatch","timer","signal","conditional","receiveTask"].includes(t)?null:"sequenceFlow"}appendConnected(e,t){if(!this.connectionTargets(e).some(g=>g.id===t))return null;const i=At(this.diagram,t),r=e instanceof I&&e.attachedToTaskId&&e.kind==="compensation"?new L(null,{id:i,label:this.labels.elements.task,movable:!0,type:O.task,compensation:!0}):de.create(t,i,["event","gateway"].includes($t.find(g=>g.id===t)?.family??"")?"":this.labels.elements[t]);this.diagram.add(r);const a=this.diagram.getExtension(B).gridSize,l=new y([e.box.x+e.box.width+a,e.box.y+e.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=e.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 p=this.diagram.getExtension($);return p.clearSelection(),p.selectNode(r),this.diagram.canvas.ensureVisible(r.box,a*3,!0),r}nearestAvailablePosition(e,t){const i=this.diagram.getExtension(B).gridSize,s=this.diagram.nodes.filter(l=>l!==e&&l.state.groupChildren!==!0).map(l=>l.box.inflate(i));let r=null,a=Number.POSITIVE_INFINITY;for(let l=0;l<=Sh;l+=1){const c=[];for(let u=-l;u<=l;u+=1)for(let p=-l;p<=l;p+=1)Math.max(Math.abs(u),Math.abs(p))===l&&c.push([u,p]);c.sort((u,p)=>{const g=u[0]**2+u[1]**2,m=p[0]**2+p[1]**2;return g!==m?g-m:this.placementDirectionRank(u)-this.placementDirectionRank(p)}),c.forEach(([u,p])=>{const g=t.copy(!1).sum([u*i,p*i]),m=g.toDimensions(e.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(v=>v.collides(m)))return;const b=(u*i)**2+(p*i)**2;b<a&&(r=g,a=b)});const h=(l+1)*i;if(r&&h**2>a)return r}return r}placementDirectionRank([e,t]){return t===0&&e>=0?0:e===0&&t>0?1:e===0&&t<0?2:e>=0?3:4}startToolbarConnection(e,t){this.diagram.getExtension(at).startConnectionFromNode(e,t,"automatic")}get connecting(){return this.diagram.getExtension(at).connecting}renameNode(e,t){this.emit(new Z(this)),f.runInAction(()=>e.setState("label",t))}acceptsEventDefinition(e,t){return!ct(t)||e.attachedToTaskId&&!al.has(t.kind)?!1:!e.subprocessStart||us.has(t.kind)}eventKindOptions(e){return kh.filter(t=>e.attachedToTaskId&&!al.has(t)?!1:!e.subprocessStart||us.has(t))}eventDefinitionForKind(e,t){const i=rl[t],s=sl.some(a=>ct({kind:t,stage:e.stage,direction:a}))?e.stage:i.stage,r=il.some(a=>ct({kind:t,stage:a,direction:e.direction}))?e.direction:i.direction;return{kind:t,stage:s,direction:r}}changeEventKind(e,t){if(!this.eventKindOptions(e).includes(t))return!1;const i=this.eventDefinitionForKind(e,t);return this.acceptsEventDefinition(e,i)?(this.emit(new Z(this)),e.setDefinition(i)):!1}eventStageOptions(e){return il.filter(t=>this.acceptsEventDefinition(e,{...e.definition,stage:t}))}eventDirectionOptions(e){return sl.filter(t=>this.acceptsEventDefinition(e,{...e.definition,direction:t}))}changeEventStage(e,t){const i={...e.definition,stage:t};return this.acceptsEventDefinition(e,i)?(this.emit(new Z(this)),e.setDefinition(i)):!1}changeEventDirection(e,t){const i={...e.definition,direction:t};return this.acceptsEventDefinition(e,i)?(this.emit(new Z(this)),e.setDefinition(i)):!1}changeEventInterrupting(e,t){e.attachedToTaskId&&(this.emit(new Z(this)),f.runInAction(()=>e.setInterrupting(t)))}eventSubprocessStart(e){return this.diagram.nodes.find(t=>t instanceof I&&t.subprocessStart&&t.subprocessId===e.id)??null}containedEventCandidate(e){return this.diagram.nodes.find(t=>t instanceof I&&!t.attachedToTaskId&&!t.subprocessStart&&e.box.x<=t.box.x&&e.box.y<=t.box.y&&e.box.x+e.box.width>=t.box.x+t.box.width&&e.box.y+e.box.height>=t.box.y+t.box.height)??null}eventSubprocessStartKind(e){return this.eventSubprocessStart(e)?.kind??""}changeEventSubprocessStartKind(e,t){if(e.type!==O.eventSubprocess||!us.has(t))return null;const i=this.eventSubprocessStart(e)??this.containedEventCandidate(e);if(this.emit(new Z(this)),i)return i.setDefinition(this.eventDefinitionForKind(i,t))&&i.setSubprocessStart(!0,e.id)?i:null;const s=new I(null,{eventDefinition:rl[t],id:At(this.diagram,"eventSubprocessStart"),label:"",subprocessId:e.id,subprocessStart:!0});return this.diagram.add(s),s.setPosition(new y([Math.min(e.box.x+25,e.box.x+e.box.width-s.box.width),Math.min(e.box.y+50,e.box.y+e.box.height-s.box.height)]),{updateConnectedEdges:!1}),s}changeTaskMultiInstance(e,t){return this.emit(new Z(this)),e.setMultiInstance(t)}changeTaskLoop(e,t){return this.emit(new Z(this)),e.setLoop(t)}changeTaskCompensation(e,t){return!t&&e.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 Z(this)),e.setCompensation(t))}changeTaskAdHoc(e,t){return this.emit(new Z(this)),e.setAdHoc(t)}changeTaskTransaction(e,t){return this.emit(new Z(this)),e.setTransaction(t)}renameEdge(e,t){this.emit(new Z(this)),f.runInAction(()=>e.setPrimaryLabel(t))}edgeKindOptions(e){const t=e.from.parent,i=e.to.parent;return t instanceof ce||i instanceof ce||t instanceof oe||i instanceof oe?["association"]:t instanceof ge||i instanceof ge?["messageFlow"]:t instanceof be||t instanceof se?["inputDataAssociation"]:i instanceof be||i instanceof se?["outputDataAssociation"]:_h}changeEdgeKind(e,t){this.edgeKindOptions(e).includes(t)&&(this.emit(new Z(this)),f.runInAction(()=>e.setKind(t)))}reverseEdge(e){this.emit(new Z(this)),f.runInAction(()=>e.reverseDirection())}changeEdgePathType(e,t){this.emit(new Z(this)),f.runInAction(()=>e.setPathType(t))}changeEdgeCondition(e,t){this.emit(new Z(this)),f.runInAction(()=>{e.condition=t})}changeEdgeDefault(e,t){return e.isDefault===t?!0:t&&!this.supportsDefaultFlow(e)?!1:(this.emit(new Z(this)),e.setDefault(t))}changeEdgeDirected(e,t){!e.supportsDirection||e.isDirected===t||(this.emit(new Z(this)),f.runInAction(()=>e.setDirected(t)))}supportsDefaultFlow(e){return e.supportsDefaultFlow}supportsCondition(e){if(e.kind!=="sequenceFlow")return!1;const t=e.from.parent;return!(t instanceof W&&(t.type===H.parallel||t.type===H.eventBased))}togglePropertiesPanel(){f.runInAction(()=>{this.propertiesPanelOpen=!this.propertiesPanelOpen}),typeof window<"u"&&window.localStorage.setItem(gs,String(this.propertiesPanelOpen))}closePropertiesPanel(){f.runInAction(()=>{this.propertiesPanelOpen=!1}),typeof window<"u"&&window.localStorage.setItem(gs,"false")}};o(Sa,"BPMNModelerExtension");let gt=Sa;const Ma=class Ma extends ot{constructor(e){super(e),this.registerExtension(yn),this.registerExtension(Ft),this.registerExtension(Je),this.registerExtension(yi),this.registerExtension(gt),this.getExtension(gt).configureLabels(e?.labels??{}),this.registerExtension(cs),this.registerClass(ae),this.registerClass(L),this.registerClass(I),this.registerClass(W),this.registerClass(le),this.registerClass(zt),this.registerClass(ge),this.registerClass(be),this.registerClass(se),this.registerClass(oe),this.registerClass(ce)}get bpmnLabels(){return this.getExtension(gt).labels}configureLabels(e){this.getExtension(gt).configureLabels(e)}};o(Ma,"BPMDiagram");let xi=Ma;const Aa=class Aa extends xe{executionId;visited=!1;visitCount=0;visitedAt=null;constructor(e,t){super(e,t),this.executionId=t.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(t.execution)}get stroke(){return this.visited?this.diagram?.executionSettings?.visitedEdgeColor??"#2563eb":super.stroke}applyExecution(e){this.visited=e?.visited===!0,this.visitCount=typeof e?.visitCount=="number"&&Number.isFinite(e.visitCount)?Math.max(0,Math.floor(e.visitCount)):this.visited?1:0,this.visitedAt=typeof e?.visitedAt=="string"?e.visitedAt:null}resetExecution(){this.visited=!1,this.visitCount=0,this.visitedAt=null}setExecutionId(e){const t=e.trim();t&&(this.executionId=t)}serialize(){return{...super.serialize(),executionId:this.executionId,execution:{visited:this.visited,visitCount:this.visitCount,visitedAt:this.visitedAt}}}deserialize(e){super.deserialize(e),this.executionId=e.executionId??this.id,this.applyExecution(e.execution)}};o(Aa,"BPMNExecutionEdge");let ze=Aa,Mh=0;const Ca=class Ca{id;kind;value;message;color;constructor(e){this.id=e.id??`execution-marker-${Mh++}`,this.kind=e.kind,this.value=e.value??null,this.message=e.message??"",this.color=e.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(Ca,"BPMNExecutionMarker");let xn=Ca;const ol=new Set(["idle","active","waiting","completed","failed"]),ps=new Set(["token","error","waiting","completed"]);function ll(n){return typeof n=="number"&&Number.isFinite(n)?Math.max(0,Math.floor(n)):0}o(ll,"normalizeCount");const Ia=class Ia{currentStatus="idle";activeTokenCount=0;errorMessage="";markers=[];constructor(e){f.makeAutoObservable(this),this.apply(e)}get status(){return this.currentStatus}set status(e){this.setStatus(e)}get tokenCount(){return this.activeTokenCount}get error(){return this.errorMessage}setStatus(e){this.currentStatus=ol.has(e)?e:"idle",this.currentStatus!=="failed"&&(this.errorMessage=""),this.synchronizeStatusMarker()}setTokenCount(e){this.activeTokenCount=ll(e),this.synchronizeStatusMarker()}setError(e){this.errorMessage=e?.trim()??"",this.errorMessage&&(this.currentStatus="failed"),this.synchronizeStatusMarker()}apply(e){const t=e??{};this.currentStatus=t.status&&ol.has(t.status)?t.status:"idle",this.activeTokenCount=ll(t.tokenCount),this.errorMessage=t.error?.trim()??"",this.errorMessage&&(this.currentStatus="failed"),this.markers=(t.markers??[]).filter(({kind:i})=>!ps.has(i)).map(i=>new xn(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:e})=>!ps.has(e)).map(e=>e.serialize())}}synchronizeStatusMarker(){this.markers=this.markers.filter(t=>!ps.has(t.kind));let e=null;this.currentStatus==="active"?(this.activeTokenCount===0&&(this.activeTokenCount=1),e={id:"execution-status-active",kind:"token",value:this.activeTokenCount}):this.currentStatus==="waiting"?e={id:"execution-status-waiting",kind:"waiting"}:this.currentStatus==="completed"?e={id:"execution-status-completed",kind:"completed"}:this.currentStatus==="failed"&&(e={id:"execution-status-failed",kind:"error",message:this.errorMessage,value:"!"}),e&&this.markers.push(new xn(e))}};o(Ia,"BPMNNodeExecutionState");let re=Ia;function vi(n){return"execution"in n&&n.execution instanceof re}o(vi,"isBPMNExecutionNode");const Ah=A.observer(({diagram:n})=>{const e=n;return d.jsx(d.Fragment,{children:n.nodes.filter(vi).map(t=>{if(!t.execution.markers.length)return null;const i=Le(t,t.box);return d.jsx("div",{className:"bpmn-execution__markers","data-execution-node-id":t.id,style:i.style,children:t.execution.markers.map(s=>{const r=s.kind==="error",a=s.kind==="waiting",l=s.kind==="completed",c=`execution-marker-${t.id}-${s.id}`,h=r?s.message||"Execution failed":s.message,u=!!h,p=r?e.executionSettings.errorColor:a?"#d97706":l?"#16a34a":e.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??p},tabIndex:u?0:void 0,title:u?void 0:s.kind,children:[r?"!":a?d.jsx(kd,{"aria-hidden":"true"}):l?d.jsx(Md,{"aria-hidden":"true"}):s.value??"•",u&&d.jsx("span",{className:"bpmn-execution__marker_tooltip",id:c,role:"tooltip",children:h})]},s.id)})},t.id)})})}),ja=class ja extends F{RenderDiagram=Ah;init(){}};o(ja,"BPMNExecutionExtension");let fs=ja;const Pa=class Pa extends ge{execution;constructor(e,t){super(e,t),this.execution=new re(t.execution)}serialize(){return{...super.serialize(),execution:this.execution.serialize()}}deserialize(e){super.deserialize(e),this.execution.apply(e.execution)}};o(Pa,"BPMNExecutionBlackBoxPoolNode");let vn=Pa;const Na=class Na extends be{execution;constructor(e,t){super(e,t),this.execution=new re(t.execution)}serialize(){return{...super.serialize(),execution:this.execution.serialize()}}deserialize(e){super.deserialize(e),this.execution.apply(e.execution)}};o(Na,"BPMNExecutionDataStoreNode");let wn=Na;const Ta=class Ta extends oe{execution;constructor(e,t){super(e,t),this.execution=new re(t.execution)}serialize(){return{...super.serialize(),execution:this.execution.serialize()}}deserialize(e){super.deserialize(e),this.execution.apply(e.execution)}};o(Ta,"BPMNExecutionDocumentAnnotationNode");let En=Ta;const Da=class Da extends se{execution;constructor(e,t){super(e,t),this.execution=new re(t.execution)}serialize(){return{...super.serialize(),execution:this.execution.serialize()}}deserialize(e){super.deserialize(e),this.execution.apply(e.execution)}};o(Da,"BPMNExecutionDocumentNode");let _n=Da;const La=class La extends I{execution;constructor(e,t){super(e,t),this.execution=new re(t.execution)}serialize(){return{...super.serialize(),execution:this.execution.serialize()}}deserialize(e){super.deserialize(e),this.execution.apply(e.execution)}};o(La,"BPMNExecutionEventNode");let kn=La;const Oa=class Oa extends W{execution;constructor(e,t){super(e,t),this.execution=new re(t.execution)}serialize(){return{...super.serialize(),execution:this.execution.serialize()}}deserialize(e){super.deserialize(e),this.execution.apply(e.execution)}};o(Oa,"BPMNExecutionGateNode");let Sn=Oa;const za=class za extends le{execution;constructor(e,t){super(e,t),this.execution=new re(t.execution)}serialize(){return{...super.serialize(),execution:this.execution.serialize()}}deserialize(e){super.deserialize(e),this.execution.apply(e.execution)}};o(za,"BPMNExecutionLanes");let Mn=za;const Fa=class Fa extends L{execution;constructor(e,t){super(e,t),this.execution=new re(t.execution)}serialize(){return{...super.serialize(),execution:this.execution.serialize()}}deserialize(e){super.deserialize(e),this.execution.apply(e.execution)}};o(Fa,"BPMNExecutionTaskNode");let An=Fa;const $a=class $a extends ce{execution;constructor(e,t){super(e,t),this.execution=new re(t.execution)}serialize(){return{...super.serialize(),execution:this.execution.serialize()}}deserialize(e){super.deserialize(e),this.execution.apply(e.execution)}};o($a,"BPMNExecutionTextAnnotationNode");let Cn=$a;const Ha=class Ha extends zt{execution;constructor(e,t){super(e,t),this.execution=new re(t.execution)}serialize(){return{...super.serialize(),execution:this.execution.serialize()}}deserialize(e){super.deserialize(e),this.execution.apply(e.execution)}};o(Ha,"BPMNExecutionUnknownNode");let In=Ha;function Ch(n){const e=n.id;if(n instanceof ze||n.constructor!==xe)return n;Object.setPrototypeOf(n,ze.prototype);const t=n;return t.executionId=e,t.visited=!1,t.visitCount=0,t.visitedAt=null,n}o(Ch,"promoteBPMNExecutionEdge");const Ih=new Map([[L,An.prototype],[I,kn.prototype],[W,Sn.prototype],[le,Mn.prototype],[ge,vn.prototype],[be,wn.prototype],[se,_n.prototype],[oe,En.prototype],[ce,Cn.prototype],[zt,In.prototype]]);function jh(n){if("execution"in n)return n;const e=Ih.get(n.constructor);return e&&(Object.setPrototypeOf(n,e),n.execution=new re),n}o(jh,"promoteBPMNExecutionNode");const Ph=["idle","active","waiting","completed","failed"];function Nh(n,e){try{const t=JSON.parse(n);Array.isArray(t)&&e(t)}catch{}}o(Nh,"applyCustomMarkers");const Th=A.observer(({diagram:n,extension:e})=>{const t=n.getExtension($),i=t.selectedNodes.length===1?t.selectedNodes[0]:null,s=t.selectedEdges.length===1?t.selectedEdges[0]:null,r=i&&vi(i)?i:null,a=s instanceof ze?s:null,l=n;return d.jsx(nl,{diagram:n,extension:e,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:Ph.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=>Nh(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})]})]})}})}),Dh={visitedEdgeColor:"#2563eb",tokenColor:"#2563eb",errorColor:"#dc2626"},Ba=class Ba extends xi{executionSettings;restoringSerializedState=!1;constructor(e){super(e),this.rules.allowEdition=!1,f.intercept(this.rules,"allowEdition",t=>({...t,newValue:!1})),this.onEvent(ee,t=>{this.restoringSerializedState&&t.stopImmediatePropagation()},this.priorities.Mouse_Down_Rules+1),this.executionSettings=f.observable({...Dh,...e?.execution}),this.registerExecutionClasses(),this.setDefaultEdge(ze),this.registerExtension(fs),this.getExtension(gt).RenderUI=Th}import(e){const t=this.restoringSerializedState;this.restoringSerializedState=!0;try{super.import(e)}finally{this.restoringSerializedState=t}}async replaceReadonlyContent(e){const t=this.restoringSerializedState;this.restoringSerializedState=!0;try{return await super.reset()?(await e(),!0):!1}finally{this.restoringSerializedState=t}}add(e){return super.add(jh(e))}connectWithEdge(e,t,i){return super.connectWithEdge(e,t,Ch(i))}configureExecution(e){f.runInAction(()=>{Object.assign(this.executionSettings,e)})}applyExecutionSnapshot(e){const t=e.nodes??{},i=e.edges??{},s=e.replace!==!1,r=[],a=[];let l=0,c=0;return f.runInAction(()=>{s&&this.clearExecution(),Object.entries(t).forEach(([h,u])=>{const p=this.getNodeById(h);if(!p||!vi(p)){r.push(h);return}p.execution.apply(u),l+=1}),Object.entries(i).forEach(([h,u])=>{const p=this.resolveExecutionEdge(h);if(!p){a.push(h);return}p.applyExecution(u),c+=1})}),{appliedNodes:l,appliedEdges:c,unresolvedNodeIds:r,unresolvedEdgeIds:a}}clearExecution(){this.nodes.forEach(e=>{vi(e)&&e.execution.reset()}),this.edges.forEach(e=>{e instanceof ze&&e.resetExecution()})}resolveExecutionEdge(e){return this.edges.find(t=>t instanceof ze&&(t.executionId===e||t.id===e||`${t.from.parent.id}->${t.to.parent.id}`===e))??null}registerExecutionClasses(){[[L,An],[I,kn],[W,Sn],[le,Mn],[zt,In],[ge,vn],[be,wn],[se,_n],[oe,En],[ce,Cn],[xe,ze]].forEach(([t,i])=>{this.registerClass(i),this.registerClass(i,t.name)})}};o(Ba,"BPMNExecutionDiagram");let ms=Ba;const Ra=class Ra extends Re{constructor(e,t){super(e,t),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(Ra,"CommunicationEdge");let wi=Ra;const Ga=class Ga extends Oe{constructor(e,t){super(e,{...t,box:t.box??new M([0,0,180,96]),fill:t.fill,stroke:t.stroke,label:t.label??""}),this.classList.add("communication__node","diagram__node")}};o(Ga,"CommunicationNode");let jn=Ga;const Va=class Va extends jn{communicationNodeType="actor";constructor(e,t){super(e,{...t,box:t.box??new M([0,0,170,90]),fill:t.fill??"#0f2230",stroke:t.stroke??"#7dd3fc",label:t.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(Va,"CommunicationActorNode");let Ei=Va;const Wa=class Wa extends jn{communicationNodeType="object";constructor(e,t){super(e,{...t,box:t.box??new M([0,0,190,96]),fill:t.fill??"#182412",stroke:t.stroke??"#bef264",label:t.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(Wa,"CommunicationObjectNode");let _i=Wa;const Ya=class Ya extends jn{communicationNodeType="controller";constructor(e,t){super(e,{...t,box:t.box??new M([0,0,200,100]),fill:t.fill??"#2b1618",stroke:t.stroke??"#fda4af",label:t.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(Ya,"CommunicationControllerNode");let ki=Ya;const Za=class Za extends ot{constructor(e){super(e),this.registerClass(Ei),this.registerClass(_i),this.registerClass(ki),this.registerClass(wi),this.setDefaultEdge(wi)}get selectedNodes(){return this.getExtension($).selectedNodes}get selectedEdges(){return this.getExtension($).selectedEdges}createNodeFromClientPoint(e,t,i){const s=this.canvas.inverseFit(new y([t,i]));return this.createNodeAtCanvasPoint(e,s.x,s.y)}createNodeAtCanvasPoint(e,t,i){const s=this.instantiateNode(e);this.add(s);const r=new y([t-s.box.width/2,i-s.box.height/2]);return s.setPosition(r),this.getExtension($).clearSelection(),this.getExtension($).selectNode(s),s}createNodeInViewportCenter(e){const t=this.canvas.frameDimensions,i=new y([t.x+t.width/2,t.y+t.height/2]);return this.createNodeFromClientPoint(e,i.x,i.y)}instantiateNode(e){const t={id:At(this,"node"),label:Lh(e),box:new M([0,0,180,96])};return e==="actor"?new Ei(this,t):e==="controller"?new ki(this,t):new _i(this,t)}};o(Za,"CommunicationDiagram");let ys=Za;function Lh(n){return n==="actor"?"Actor":n==="controller"?"Controller":"Object"}o(Lh,"defaultLabelForType");let cl=0;function dl(){return cl+=1,`foreign-key-${cl}`}o(dl,"nextForeignKeyId");function hl(n){return/^attribute:(.+):(left|right)$/.exec(n??"")?.[1]??null}o(hl,"attributeIdFromGateway");function Oh(n){if(!n)return[];const e=n.model.attributes.filter(i=>i.primaryKey).map(i=>i.id),t=n.model.constraints.find(i=>i.kind==="primary-key");return t?.attributeIds.length?[...t.attributeIds]:e}o(Oh,"firstPrimaryKey");const Ka=class Ka extends Re{constraintId;mappingIndex;name;sourceAttributeIds;targetAttributeIds;sourceCardinality;targetCardinality;onDelete;onUpdate;matchType;identifying;deferrable;initiallyDeferred;constructor(e,t){super(e,t);const i=t.from?.parent,s=t.to?.parent,r=hl(t.from?.id),a=hl(t.to?.id);this.constraintId=t.constraintId??dl(),this.mappingIndex=t.mappingIndex??0,this.name=t.name??(i&&s?`fk_${i.state.label}_${s.state.label}`:"foreign_key"),this.sourceAttributeIds=t.sourceAttributeIds??(r?[r]:void 0)??i?.model.attributes.filter(l=>!l.primaryKey).slice(0,1).map(l=>l.id)??[],this.targetAttributeIds=t.targetAttributeIds??(a?[a]:void 0)??Oh(s),this.sourceCardinality=t.sourceCardinality??"zero-many",this.targetCardinality=t.targetCardinality??"one",this.onDelete=t.onDelete??"no-action",this.onUpdate=t.onUpdate??"no-action",this.matchType=t.matchType??"simple",this.identifying=t.identifying??!1,this.deferrable=t.deferrable??!1,this.initiallyDeferred=t.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(e){Object.assign(this,e),this.deferrable||(this.initiallyDeferred=!1),this.applyStyle()}setSteps(e){const t=this.steps.length===0;super.setSteps(e),t&&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(e){super.deserialize(e),this.constraintId=e.constraintId??dl(),this.mappingIndex=e.mappingIndex??0,this.name=e.name,this.sourceAttributeIds=[...e.sourceAttributeIds],this.targetAttributeIds=[...e.targetAttributeIds],this.sourceCardinality=e.sourceCardinality,this.targetCardinality=e.targetCardinality,this.onDelete=e.onDelete,this.onUpdate=e.onUpdate,this.matchType=e.matchType,this.identifying=e.identifying,this.deferrable=e.deferrable,this.initiallyDeferred=e.initiallyDeferred,this.applyStyle()}};o(Ka,"MRForeignKeyEdge");let ve=Ka,ul=0;function bs(n){return ul+=1,`${n}-${ul}`}o(bs,"nextElementId");function xs(n={}){return{id:bs("attribute"),name:"column",dataType:"VARCHAR",length:"255",nullable:!0,primaryKey:!1,unique:!1,autoIncrement:!1,defaultValue:"",generatedExpression:"",checkExpression:"",comment:"",...n}}o(xs,"defaultAttribute");function gl(n){return{schemaName:"public",tableKind:"table",description:"",...n,attributes:n?.attributes?.map(e=>xs(e))??[xs({name:"id",dataType:"BIGINT",length:"",nullable:!1,primaryKey:!0,autoIncrement:!0})],constraints:n?.constraints?.map(e=>({id:e.id??bs("constraint"),kind:e.kind??"unique",name:e.name??"",attributeIds:[...e.attributeIds??[]],expression:e.expression??"",indexMethod:e.indexMethod??"btree"}))??[]}}o(gl,"defaultModel");function zh(n){return n==="primary-key"?"PK":n==="unique"?"UQ":n==="check"?"CK":"IX"}o(zh,"constraintBadge");const Ua=class Ua extends Dt{model;constructor(e,t){super(e,{...t,label:t.label??"table",box:t.box??new M([0,0,310,196])}),this.model=gl(t.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(e){super.setDiagram(e),this.fitHeightToContent(),this.syncAttributeGateways()}addAttribute(e={}){const t=xs(e);return this.model.attributes.push(t),this.fitHeightToContent(),this.syncAttributeGateways(),t}updateAttribute(e,t){const i=this.model.attributes.find(s=>s.id===e);i&&(Object.assign(i,t),i.primaryKey&&(i.nullable=!1))}removeAttribute(e){this.model.attributes=this.model.attributes.filter(t=>t.id!==e),this.model.constraints.forEach(t=>{t.attributeIds=t.attributeIds.filter(i=>i!==e)}),this.fitHeightToContent(),this.syncAttributeGateways(!0)}moveAttribute(e,t){if(e===t)return;const i=this.model.attributes.findIndex(a=>a.id===e);if(i<0||t!==null&&!this.model.attributes.some(a=>a.id===t))return;const[s]=this.model.attributes.splice(i,1),r=t===null?this.model.attributes.length:this.model.attributes.findIndex(a=>a.id===t);this.model.attributes.splice(r,0,s),this.syncAttributeGatewayPositions(!0)}addConstraint(e,t={}){const i={id:bs("constraint"),kind:e,name:`${this.state.label}_${e.replace("-","_")}`,attributeIds:[],expression:"",indexMethod:"btree",...t};return this.model.constraints.push(i),this.fitHeightToContent(),i}updateConstraint(e,t){const i=this.model.constraints.find(s=>s.id===e);i&&Object.assign(i,t)}removeConstraint(e){this.model.constraints=this.model.constraints.filter(t=>t.id!==e),this.fitHeightToContent()}updateModel(e){const t=this.model.tableKind;Object.assign(this.model,e),e.tableKind&&e.tableKind!==t&&(this.classList.delete(`mr__table--${t}`),this.classList.add(`mr__table--${e.tableKind}`))}fitHeightToContent(){const e=Math.max(1,this.model.attributes.length),t=this.model.constraints.length>0?34:0;this.state.box.height=58+e*this.attributeRowHeight+t,this.syncAttributeGatewayPositions()}get attributeRowHeight(){return this.diagram?.getExtension(B)?.gridSize??50}syncAttributeGateways(e=!1){const t=new Map(this._gateways);this._gateways.clear(),this.model.attributes.forEach(i=>{["left","right"].forEach(s=>{const r=`attribute:${i.id}:${s}`,a=t.get(r)??new Se(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(e)}syncAttributeGatewayPositions(e=!1){this.model?.attributes.forEach((t,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:${t.id}:${r}`);a?.state.position.assign([r==="left"?0:1,s]),e&&a&&(a.incomingEdges.length>0||a.outgoingEdges.length>0)&&a.updateEdges()})})}gatewayForAttribute(e,t){return this._gateways.get(`attribute:${e}:${t}`)}getGateway(e){const t=super.getGateway(e);if(t)return t;const i=/^attribute:(.+):(left|right)$/.exec(String(e));if(!i)return;const s=i[2],r=new Se(this,{id:String(e),orientation:s,maxIncomingConnections:1/0,maxOutgoingConnections:1/0});return r.state.position.assign([s==="left"?0:1,.5]),this._gateways.set(String(e),r),r}serialize(){return{...super.serialize(),model:f.toJS(this.model)}}deserialize(e){super.deserialize(e),this.model=gl(e.model),this.fitHeightToContent(),this.syncAttributeGateways()}RenderOverlay=A.observer(()=>{const e=this.state.label||"unnamed_table",t=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:e}),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","data-attribute-id":s.id,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)})}),t.length>0&&d.jsx("footer",{className:"mr__constraint_badges",children:t.map(s=>d.jsxs("span",{title:s.name,children:[zh(s.kind)," ",s.name]},s.id))})]})});RenderScreen=null};o(Ua,"MRTableNode");let Ze=Ua;const Fh=["BIGINT","INTEGER","SMALLINT","DECIMAL","NUMERIC","REAL","DOUBLE PRECISION","BOOLEAN","CHAR","VARCHAR","TEXT","DATE","TIME","TIMESTAMP","TIMESTAMPTZ","UUID","JSON","JSONB","BINARY","BLOB"],$h=[{value:"primary-key",label:"Primary key"},{value:"unique",label:"Unique key"},{value:"check",label:"CHECK"},{value:"index",label:"Index"}],pl=[{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"}],fl=[{value:"zero-one",label:"0..1"},{value:"one",label:"1"},{value:"zero-many",label:"0..*"},{value:"one-many",label:"1..*"}],Hh=["orthogonal","straight","curved"],ml="mr-properties-panel-width",yl=420,bl=620;function vs(n){return Array.from(n.target.selectedOptions,e=>e.value)}o(vs,"selectedValues");function Bh(){if(typeof window>"u")return bl;const n=Number(window.localStorage.getItem(ml)),e=Number.isFinite(n)&&n>0?n:bl,t=Math.min(yl,window.innerWidth-28);return Math.max(t,Math.min(window.innerWidth-56,e))}o(Bh,"initialPanelWidth");function Rh(){const[n,e]=S.useState(Bh);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(yl,window.innerWidth-28),p=Math.max(u,window.innerWidth-56);a=Math.max(u,Math.min(p,r+s-h.clientX)),e(a)},"move"),c=o(()=>{window.removeEventListener("pointermove",l),window.removeEventListener("pointerup",c),window.localStorage.setItem(ml,String(a))},"finish");window.addEventListener("pointermove",l),window.addEventListener("pointerup",c,{once:!0})},"startResize")}}o(Rh,"useResizablePanelWidth");function ws({checked:n,label:e,onChange:t}){return d.jsxs("label",{className:"mr__property_checkbox",children:[d.jsx("input",{checked:n,onChange:o(i=>t(i.target.checked),"onChange"),type:"checkbox"}),d.jsx("span",{children:e})]})}o(ws,"Checkbox");const Gh=A.observer(o(function({editable:e,extension:t,node:i}){const[s,r]=S.useState(null),a=o((l,c)=>{if(l.preventDefault(),!s)return;const h=l.currentTarget,u=l.clientY>h.getBoundingClientRect().top+h.clientHeight/2,p=i.model.attributes.findIndex(m=>m.id===c),g=u?i.model.attributes[p+1]?.id??null:c;t.moveAttribute(i,s,g),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=>t.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:!e,draggable:e,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:!e,onClick:o(()=>t.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:!e,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:!e,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:!e,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:!e,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:!e,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:!e,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:!e,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:!e,onChange:o(u=>c({autoIncrement:u.target.checked}),"onChange"),type:"checkbox"})}),d.jsx("td",{children:d.jsx("input",{"aria-label":h("Generated expression"),disabled:!e,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:!e,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:!e,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")),Vh=A.observer(o(function({constraint:e,editable:t,extension:i,node:s}){const r=o(a=>i.updateConstraint(s,e.id,a),"update");return d.jsxs("details",{className:"mr__property_card",children:[d.jsx("summary",{children:d.jsxs("span",{children:[e.kind.toUpperCase()," · ",e.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:!t,onChange:o(a=>r({kind:a.target.value}),"onChange"),value:e.kind,children:$h.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:!t,onChange:o(a=>r({name:a.target.value}),"onChange"),type:"text",value:e.name})]})]}),e.kind!=="check"&&d.jsxs("label",{children:[d.jsx("span",{children:"Columns (Ctrl/Cmd for multiple)"}),d.jsx("select",{disabled:!t,multiple:!0,onChange:o(a=>r({attributeIds:vs(a)}),"onChange"),value:e.attributeIds,children:s.model.attributes.map(a=>d.jsx("option",{value:a.id,children:a.name},a.id))})]}),e.kind==="check"&&d.jsxs("label",{children:[d.jsx("span",{children:"Expression"}),d.jsx("textarea",{disabled:!t,onChange:o(a=>r({expression:a.target.value}),"onChange"),rows:3,value:e.expression})]}),e.kind==="index"&&d.jsxs("label",{children:[d.jsx("span",{children:"Index method"}),d.jsx("input",{disabled:!t,onChange:o(a=>r({indexMethod:a.target.value}),"onChange"),placeholder:"btree, hash, gin…",type:"text",value:e.indexMethod})]}),d.jsx("button",{className:"mr__danger_button",disabled:!t,onClick:o(()=>i.removeConstraint(s,e.id),"onClick"),type:"button",children:"Remove constraint"})]})]})},"ConstraintEditor2")),Wh=A.observer(o(function({editable:e,extension:t,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:!e,onChange:o(s=>t.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:!e,onChange:o(s=>t.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:!e,onChange:o(s=>t.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:!e,onChange:o(s=>t.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:!e,onClick:o(()=>t.addAttribute(i),"onClick"),type:"button",children:"+ Attribute"})]}),d.jsx(Gh,{editable:e,extension:t,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:!e,onClick:o(()=>t.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(Vh,{constraint:s,editable:e,extension:t,node:i},s.id))]})]})},"TableProperties2")),Yh=A.observer(o(function({edge:e,editable:t,extension:i}){const s=e.from.parent,r=e.to.parent,a=o(l=>i.updateForeignKey(e,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:!t,onChange:o(l=>a({name:l.target.value}),"onChange"),type:"text",value:e.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:!t,multiple:!0,onChange:o(l=>a({sourceAttributeIds:vs(l)}),"onChange"),value:e.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:!t,multiple:!0,onChange:o(l=>a({targetAttributeIds:vs(l)}),"onChange"),value:e.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:!t,onChange:o(l=>a({sourceCardinality:l.target.value}),"onChange"),value:e.sourceCardinality,children:fl.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:!t,onChange:o(l=>a({targetCardinality:l.target.value}),"onChange"),value:e.targetCardinality,children:fl.map(l=>d.jsx("option",{value:l.value,children:l.label},l.value))})]})]}),e.sourceAttributeIds.length!==e.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:!t,onChange:o(l=>a({onDelete:l.target.value}),"onChange"),value:e.onDelete,children:pl.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:!t,onChange:o(l=>a({onUpdate:l.target.value}),"onChange"),value:e.onUpdate,children:pl.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:!t,onChange:o(l=>a({matchType:l.target.value}),"onChange"),value:e.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:!t,onChange:o(l=>i.updateForeignKeyPath(e,l.target.value),"onChange"),value:e.pathType,children:Hh.map(l=>d.jsx("option",{value:l,children:l},l))})]})]}),d.jsxs("div",{className:"mr__property_checks",children:[d.jsx(ws,{checked:e.identifying,label:"Identifying relationship",onChange:o(l=>a({identifying:l}),"onChange")}),d.jsx(ws,{checked:e.deferrable,label:"Deferrable",onChange:o(l=>a({deferrable:l}),"onChange")}),d.jsx(ws,{checked:e.initiallyDeferred,label:"Initially deferred",onChange:o(l=>a({initiallyDeferred:l}),"onChange")})]})]})]})},"ForeignKeyProperties2")),Zh=A.observer(({diagram:n,extension:e})=>{const t=n.getExtension($),i=t.selectedNodes.length===1?t.selectedNodes[0]:null,s=t.selectedEdges.length===1?t.selectedEdges[0]:null,r=i instanceof Ze?i:null,a=s instanceof ve?s:null,l=e.enabled&&!!(r||a),c=n.rules.allowEdition!==!1,{panelWidth:h,startResize:u}=Rh();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(Wh,{editable:c,extension:e,node:r}),a&&d.jsx(Yh,{edge:a,editable:c,extension:e})]}),d.jsx("datalist",{id:"mr-data-types",children:Fh.map(p=>d.jsx("option",{value:p},p))})]})}),qa=class qa extends ee{};o(qa,"MRPropertyChangeEvent");let Si=qa;function Mi(n,e=0){const t=n.canvas.frameDimensions;return n.canvas.inverseFit(new y([t.x+t.width/2+e,t.y+t.height/2]))}o(Mi,"tablePosition");const Xa=class Xa extends F{RenderUI=Zh;init(){}createTable(e,t="table",i){const s=new Ze(null,{id:At(this.diagram,t),label:i??(t==="view"?"new_view":t==="junction"?"junction_table":"new_table"),model:{tableKind:t}});if(t==="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([e.x-s.box.width/2,e.y-s.box.height/2]));const r=this.diagram.getExtension($);return r.clearSelection(),r.selectNode(s),s}addShowcaseElement(e){if(e==="table"||e==="view"||e==="junction")return this.createTable(Mi(this.diagram),e);if(e==="foreign-key")return this.createForeignKeyExample();const t=this.selectedTable??this.createTable(Mi(this.diagram));if(e==="attribute")this.addAttribute(t,{name:"new_column"});else if(e==="primary-key"){const i=t.model.attributes.find(s=>!s.primaryKey)??this.addAttribute(t,{name:`${t.state.label}_id`,dataType:"BIGINT",length:""});this.updateAttribute(t,i.id,{primaryKey:!0,nullable:!1})}else if(e==="unique"){const i=t.model.attributes.at(-1);this.addConstraint(t,"unique",{name:`uq_${t.state.label}_${i?.name??"column"}`,attributeIds:i?[i.id]:[]})}else if(e==="check")this.addConstraint(t,"check",{name:`ck_${t.state.label}_value`,expression:"value >= 0"});else if(e==="index"){const i=t.model.attributes.at(-1);this.addConstraint(t,"index",{name:`ix_${t.state.label}_${i?.name??"column"}`,attributeIds:i?[i.id]:[]})}return t}get selectedTable(){const e=this.diagram.getExtension($).selectedNodes.filter(t=>t instanceof Ze);return e.length===1?e[0]:null}renameTable(e,t){this.recordChange(),e.setState("label",t)}updateTable(e,t){this.recordChange(),e.updateModel(t)}addAttribute(e,t={}){return this.recordChange(),e.addAttribute(t)}updateAttribute(e,t,i){this.recordChange(),e.updateAttribute(t,i)}removeAttribute(e,t){this.recordChange(),this.diagram.edges.filter(i=>i instanceof ve&&(i.sourceAttributeIds.includes(t)||i.targetAttributeIds.includes(t))).forEach(i=>this.diagram.disconnect(i)),e.removeAttribute(t)}moveAttribute(e,t,i){this.recordChange(),e.moveAttribute(t,i)}addConstraint(e,t,i={}){return this.recordChange(),e.addConstraint(t,i)}updateConstraint(e,t,i){this.recordChange(),e.updateConstraint(t,i)}removeConstraint(e,t){this.recordChange(),e.removeConstraint(t)}updateForeignKey(e,t){this.recordChange();const i=e.from.parent,s=e.to.parent,r=t.sourceAttributeIds?.length?[...t.sourceAttributeIds]:[...e.sourceAttributeIds],a=t.targetAttributeIds?.length?[...t.targetAttributeIds]:[...e.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 ve&&m.constraintId===e.constraintId).sort((m,x)=>m.mappingIndex-x.mappingIndex),p={constraintId:e.constraintId,mappingIndex:0,name:t.name??e.name,sourceAttributeIds:r,targetAttributeIds:a,sourceCardinality:t.sourceCardinality??e.sourceCardinality,targetCardinality:t.targetCardinality??e.targetCardinality,onDelete:t.onDelete??e.onDelete,onUpdate:t.onUpdate??e.onUpdate,matchType:t.matchType??e.matchType,identifying:t.identifying??e.identifying,deferrable:t.deferrable??e.deferrable,initiallyDeferred:t.initiallyDeferred??e.initiallyDeferred};for(let m=0;m<l;m+=1){const x=r[Math.min(m,r.length-1)],b=a[Math.min(m,a.length-1)],v=i.gatewayForAttribute(x,c),w=s.gatewayForAttribute(b,h);if(!v||!w)continue;const _=u[m]??this.diagram.connect(v,w);this.rewireForeignKey(_,v,w),_.updateModel({...p,mappingIndex:m}),u[m]=_}u.slice(l).forEach(m=>this.diagram.disconnect(m));const g=this.diagram.getExtension($);g.selectedEdges.includes(e)&&u[0]&&(g.clearSelection(),g.selectEdge(u[0]))}updateForeignKeyPath(e,t){this.recordChange(),this.diagram.edges.filter(i=>i instanceof ve&&i.constraintId===e.constraintId).forEach(i=>i.setPathType(t))}createForeignKeyExample(){const e=this.diagram.getExtension($),t=e.selectedNodes.filter(u=>u instanceof Ze);let i=t[0],s=t[1];s||(s=this.createTable(Mi(this.diagram,t.length?250:-180),"table","customers")),(!i||i===s)&&(i=this.createTable(Mi(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]}),e.clearSelection(),e.selectEdge(h),h}rewireForeignKey(e,t,i){e.from===t&&e.to===i||(e.from.removeOutgoingEdge(e),e.to.removeIncomingEdge(e),e.setState("from",t),e.setState("to",i),e.setState("displacementStart",void 0),e.setState("displacementEnd",void 0),e.setState("startAnchor",{mode:"fixed",position:t.relativePosition}),e.setState("endAnchor",{mode:"fixed",position:i.relativePosition}),t.addOutgoingEdge(e,!1),i.addIncomingEdge(e,!1),t.recomputeConnectedEdge(e,"from"))}recordChange(){this.emit(new Si(this))}};o(Xa,"MRModelerExtension");let Ht=Xa;var xl=Object.defineProperty,Kh=o((n,e,t)=>e in n?xl(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,"hn"),Uh=o((n,e)=>{for(var t in e)xl(n,t,{get:e[t],enumerable:!0})},"fn"),qh=o((n,e,t)=>Kh(n,e+"",t),"pe"),Xh={};Uh(Xh,{Graph:o(()=>we,"Graph"),alg:o(()=>_s,"alg"),json:o(()=>_l,"json"),version:o(()=>eu,"version")});var Jh=Object.defineProperty,vl=o((n,e)=>{for(var t in e)Jh(n,t,{get:e[t],enumerable:!0})},"Le"),we=(Kt=class{constructor(e){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=()=>{},e&&(this._isDirected="directed"in e?e.directed:!0,this._isMultigraph="multigraph"in e?e.multigraph:!1,this._isCompound="compound"in e?e.compound:!1),this._isCompound&&(this._parent={},this._children={},this._children["\0"]={})}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(e){return this._label=e,this}graph(){return this._label}setDefaultNodeLabel(e){return typeof e!="function"?this._defaultNodeLabelFn=()=>e:this._defaultNodeLabelFn=e,this}nodeCount(){return this._nodeCount}nodes(){return Object.keys(this._nodes)}sources(){return this.nodes().filter(e=>Object.keys(this._in[e]).length===0)}sinks(){return this.nodes().filter(e=>Object.keys(this._out[e]).length===0)}setNodes(e,t){return e.forEach(i=>{t!==void 0?this.setNode(i,t):this.setNode(i)}),this}setNode(e,t){return e in this._nodes?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]="\0",this._children[e]={},this._children["\0"][e]=!0),this._in[e]={},this._preds[e]={},this._out[e]={},this._sucs[e]={},++this._nodeCount,this)}node(e){return this._nodes[e]}hasNode(e){return e in this._nodes}removeNode(e){if(e in this._nodes){let t=o(i=>this.removeEdge(this._edgeObjs[i]),"n");delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],this.children(e).forEach(i=>{this.setParent(i)}),delete this._children[e]),Object.keys(this._in[e]).forEach(t),delete this._in[e],delete this._preds[e],Object.keys(this._out[e]).forEach(t),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,t){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(t===void 0)t="\0";else{t+="";for(let i=t;i!==void 0;i=this.parent(i))if(i===e)throw new Error("Setting "+t+" as parent of "+e+" would create a cycle");this.setNode(t)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=t,this._children[t][e]=!0,this}parent(e){if(this._isCompound){let t=this._parent[e];if(t!=="\0")return t}}children(e="\0"){if(this._isCompound){let t=this._children[e];if(t)return Object.keys(t)}else{if(e==="\0")return this.nodes();if(this.hasNode(e))return[]}return[]}predecessors(e){let t=this._preds[e];if(t)return Object.keys(t)}successors(e){let t=this._sucs[e];if(t)return Object.keys(t)}neighbors(e){let t=this.predecessors(e);if(t){let i=new Set(t);for(let s of this.successors(e))i.add(s);return Array.from(i.values())}}isLeaf(e){let t;return this.isDirected()?t=this.successors(e):t=this.neighbors(e),t.length===0}filterNodes(e){let t=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph()),Object.entries(this._nodes).forEach(([r,a])=>{e(r)&&t.setNode(r,a)}),Object.values(this._edgeObjs).forEach(r=>{t.hasNode(r.v)&&t.hasNode(r.w)&&t.setEdge(r,this.edge(r))});let i={},s=o(r=>{let a=this.parent(r);return!a||t.hasNode(a)?(i[r]=a??void 0,a??void 0):a in i?i[a]:s(a)},"r");return this._isCompound&&t.nodes().forEach(r=>t.setParent(r,s(r))),t}setDefaultEdgeLabel(e){return typeof e!="function"?this._defaultEdgeLabelFn=()=>e:this._defaultEdgeLabelFn=e,this}edgeCount(){return this._edgeCount}edges(){return Object.values(this._edgeObjs)}setPath(e,t){return e.reduce((i,s)=>(t!==void 0?this.setEdge(i,s,t):this.setEdge(i,s),s)),this}setEdge(e,t,i,s){let r,a,l,c,h=!1;typeof e=="object"&&e!==null&&"v"in e?(r=e.v,a=e.w,l=e.name,arguments.length===2&&(c=t,h=!0)):(r=e,a=t,l=s,arguments.length>2&&(c=i,h=!0)),r=""+r,a=""+a,l!==void 0&&(l=""+l);let u=Pn(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 p=Qh(this._isDirected,r,a,l);return r=p.v,a=p.w,Object.freeze(p),this._edgeObjs[u]=p,wl(this._preds[a],r),wl(this._sucs[r],a),this._in[a][u]=p,this._out[r][u]=p,this._edgeCount++,this}edge(e,t,i){let s=arguments.length===1?Es(this._isDirected,e):Pn(this._isDirected,e,t,i);return this._edgeLabels[s]}edgeAsObj(e,t,i){let s=arguments.length===1?this.edge(e):this.edge(e,t,i);return typeof s!="object"?{label:s}:s}hasEdge(e,t,i){return(arguments.length===1?Es(this._isDirected,e):Pn(this._isDirected,e,t,i))in this._edgeLabels}removeEdge(e,t,i){let s=arguments.length===1?Es(this._isDirected,e):Pn(this._isDirected,e,t,i),r=this._edgeObjs[s];if(r){let a=r.v,l=r.w;delete this._edgeLabels[s],delete this._edgeObjs[s],El(this._preds[l],a),El(this._sucs[a],l),delete this._in[l][s],delete this._out[a][s],this._edgeCount--}return this}inEdges(e,t){return this.isDirected()?this.filterEdges(this._in[e],e,t):this.nodeEdges(e,t)}outEdges(e,t){return this.isDirected()?this.filterEdges(this._out[e],e,t):this.nodeEdges(e,t)}nodeEdges(e,t){if(e in this._nodes)return this.filterEdges({...this._in[e],...this._out[e]},e,t)}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}filterEdges(e,t,i){if(!e)return;let s=Object.values(e);return i?s.filter(r=>r.v===t&&r.w===i||r.v===i&&r.w===t):s}},o(Kt,"p"),Kt);function wl(n,e){n[e]?n[e]++:n[e]=1}o(wl,"me");function El(n,e){n[e]!==void 0&&!--n[e]&&delete n[e]}o(El,"Ee");function Pn(n,e,t,i){let s=""+e,r=""+t;if(!n&&s>r){let a=s;s=r,r=a}return s+""+r+""+(i===void 0?"\0":i)}o(Pn,"C");function Qh(n,e,t,i){let s=""+e,r=""+t;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 Es(n,e){return Pn(n,e.v,e.w,e.name)}o(Es,"Y");var eu="4.0.1",_l={};vl(_l,{read:o(()=>su,"read"),write:o(()=>tu,"write")});function tu(n){let e={options:{directed:n.isDirected(),multigraph:n.isMultigraph(),compound:n.isCompound()},nodes:nu(n),edges:iu(n)},t=n.graph();return t!==void 0&&(e.value=structuredClone(t)),e}o(tu,"mn");function nu(n){return n.nodes().map(e=>{let t=n.node(e),i=n.parent(e),s={v:e};return t!==void 0&&(s.value=t),i!==void 0&&(s.parent=i),s})}o(nu,"En");function iu(n){return n.edges().map(e=>{let t=n.edge(e),i={v:e.v,w:e.w};return e.name!==void 0&&(i.name=e.name),t!==void 0&&(i.value=t),i})}o(iu,"Ln");function su(n){let e=new we(n.options);return n.value!==void 0&&e.setGraph(n.value),n.nodes.forEach(t=>{e.setNode(t.v,t.value),t.parent&&e.setParent(t.v,t.parent)}),n.edges.forEach(t=>{e.setEdge({v:t.v,w:t.w,name:t.name},t.value)}),e}o(su,"yn");var _s={};vl(_s,{CycleException:o(()=>Ci,"CycleException"),bellmanFord:o(()=>kl,"bellmanFord"),components:o(()=>ou,"components"),dijkstra:o(()=>Ai,"dijkstra"),dijkstraAll:o(()=>du,"dijkstraAll"),findCycles:o(()=>hu,"findCycles"),floydWarshall:o(()=>gu,"floydWarshall"),isAcyclic:o(()=>fu,"isAcyclic"),postorder:o(()=>yu,"postorder"),preorder:o(()=>bu,"preorder"),prim:o(()=>xu,"prim"),shortestPaths:o(()=>vu,"shortestPaths"),tarjan:o(()=>Ml,"tarjan"),topsort:o(()=>Al,"topsort")});var ru=o(()=>1,"wn");function kl(n,e,t,i){return au(n,String(e),t||ru,i||function(s){return n.outEdges(s)})}o(kl,"we");function au(n,e,t,i){let s={},r,a=0,l=n.nodes(),c=o(function(p){let g=t(p);s[p.v].distance+g<s[p.w].distance&&(s[p.w]={distance:s[p.v].distance+g,predecessor:p.v},r=!0)},"d"),h=o(function(){l.forEach(function(p){i(p).forEach(function(g){let m=g.v===p?g.v:g.w,x=m===g.v?g.w:g.v;c({v:m,w:x})})})},"l");l.forEach(function(p){let g=p===e?0:Number.POSITIVE_INFINITY;s[p]={distance:g,predecessor:""}});let u=l.length;for(let p=1;p<u&&(r=!1,a++,h(),!!r);p++);if(a===u-1&&(r=!1,h(),r))throw new Error("The graph contains a negative weight cycle");return s}o(au,"Nn");function ou(n){let e={},t=[],i;function s(r){r in e||(e[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&&t.push(i)}),t}o(ou,"Gn");var Sl=(Ut=class{constructor(){this._arr=[],this._keyIndices={}}size(){return this._arr.length}keys(){return this._arr.map(e=>e.key)}has(e){return e in this._keyIndices}priority(e){let t=this._keyIndices[e];if(t!==void 0)return this._arr[t].priority}min(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key}add(e,t){let i=this._keyIndices,s=String(e);if(!(s in i)){let r=this._arr,a=r.length;return i[s]=a,r.push({key:s,priority:t}),this._decrease(a),!0}return!1}removeMin(){this._swap(0,this._arr.length-1);let e=this._arr.pop();return delete this._keyIndices[e.key],this._heapify(0),e.key}decrease(e,t){let i=this._keyIndices[e];if(i===void 0)throw new Error(`Key not found: ${e}`);let s=this._arr[i].priority;if(t>s)throw new Error(`New priority is greater than current priority. Key: ${e} Old: ${s} New: ${t}`);this._arr[i].priority=t,this._decrease(i)}_heapify(e){let t=this._arr,i=2*e,s=i+1,r=e;i<t.length&&(r=t[i].priority<t[r].priority?i:r,s<t.length&&(r=t[s].priority<t[r].priority?s:r),r!==e&&(this._swap(e,r),this._heapify(r)))}_decrease(e){let t=this._arr,i=t[e].priority,s;for(;e!==0&&(s=e>>1,!(t[s].priority<i));)this._swap(e,s),e=s}_swap(e,t){let i=this._arr,s=this._keyIndices,r=i[e],a=i[t];i[e]=a,i[t]=r,s[a.key]=e,s[r.key]=t}},o(Ut,"Ne"),Ut),lu=o(()=>1,"kn");function Ai(n,e,t,i){let s=o(function(r){return n.outEdges(r)},"o");return cu(n,String(e),t||lu,i||s)}o(Ai,"F");function cu(n,e,t,i){let s={},r=new Sl,a,l,c=o(function(h){let u=h.v!==a?h.v:h.w,p=s[u],g=t(h),m=l.distance+g;if(g<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+h+" Weight: "+g);m<p.distance&&(p.distance=m,p.predecessor=a,r.decrease(u,m))},"d");for(n.nodes().forEach(function(h){let u=h===e?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(cu,"vn");function du(n,e,t){return n.nodes().reduce(function(i,s){return i[s]=Ai(n,s,e,t),i},{})}o(du,"_n");function Ml(n){let e=0,t=[],i={},s=[];function r(a){let l=i[a]={onStack:!0,lowlink:e,index:e++};if(t.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=t.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(Ml,"Ge");function hu(n){return Ml(n).filter(function(e){return e.length>1||e.length===1&&n.hasEdge(e[0],e[0])})}o(hu,"xn");var uu=o(()=>1,"Tn");function gu(n,e,t){return pu(n,e||uu,t||function(i){return n.outEdges(i)})}o(gu,"On");function pu(n,e,t){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:""})}),t(r).forEach(function(a){let l=a.v===r?a.w:a.v,c=e(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],p=a[h],g=c[h],m=u.distance+p.distance;m<g.distance&&(g.distance=m,g.predecessor=p.predecessor)})})}),i}o(pu,"In");var Ci=(qt=class extends Error{constructor(...e){super(...e)}},o(qt,"D"),qt);function Al(n){let e={},t={},i=[];function s(r){if(r in t)throw new Ci;r in e||(t[r]=!0,e[r]=!0,n.predecessors(r).forEach(s),delete t[r],i.push(r))}if(o(s,"o"),n.sinks().forEach(s),Object.keys(e).length!==n.nodeCount())throw new Ci;return i}o(Al,"ke");function fu(n){try{Al(n)}catch(e){if(e instanceof Ci)return!1;throw e}return!0}o(fu,"Cn");function mu(n,e,t,i,s){Array.isArray(e)||(e=[e]);let r=o((l=>{var c;return(c=n.isDirected()?n.successors(l):n.neighbors(l))!=null?c:[]}),"i"),a={};return e.forEach(function(l){if(!n.hasNode(l))throw new Error("Graph does not have node: "+l);s=Cl(n,l,t==="post",a,r,i,s)}),s}o(mu,"Rn");function Cl(n,e,t,i,s,r,a){return e in i||(i[e]=!0,t||(a=r(a,e)),s(e).forEach(function(l){a=Cl(n,l,t,i,s,r,a)}),t&&(a=r(a,e))),a}o(Cl,"ve");function Il(n,e,t){return mu(n,e,t,function(i,s){return i.push(s),i},[])}o(Il,"_e");function yu(n,e){return Il(n,e,"post")}o(yu,"Pn");function bu(n,e){return Il(n,e,"pre")}o(bu,"Mn");function xu(n,e){let t=new we,i={},s=new Sl,r;function a(c){let h=c.v===r?c.w:c.v,u=s.priority(h);if(u!==void 0){let p=e(c);p<u&&(i[h]=r,s.decrease(h,p))}}if(o(a,"s"),n.nodeCount()===0)return t;n.nodes().forEach(function(c){s.add(c,Number.POSITIVE_INFINITY),t.setNode(c)}),s.decrease(n.nodes()[0],0);let l=!1;for(;s.size()>0;){if(r=s.removeMin(),r in i)t.setEdge(r,i[r]);else{if(l)throw new Error("Input graph is not connected: "+n);l=!0}n.nodeEdges(r).forEach(a)}return t}o(xu,"jn");function vu(n,e,t,i){return wu(n,e,t,i??(s=>{let r=n.outEdges(s);return r??[]}))}o(vu,"Sn");function wu(n,e,t,i){if(t===void 0)return Ai(n,e,t,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,p=u===h.v?h.w:h.v;t({v:u,w:p})<0&&(s=!0)}if(s)return kl(n,e,t,i)}return Ai(n,e,t,i)}o(wu,"Fn");function Bt(n,e,t,i){let s=i;for(;n.hasNode(s);)s=ks(i);return t.dummy=e,n.setNode(s,t),s}o(Bt,"w");function Eu(n){let e=new we().setGraph(n.graph());return n.nodes().forEach(t=>e.setNode(t,n.node(t))),n.edges().forEach(t=>{let i=e.edge(t.v,t.w)||{weight:0,minlen:1},s=n.edge(t);e.setEdge(t.v,t.w,{weight:i.weight+s.weight,minlen:Math.max(i.minlen,s.minlen)})}),e}o(Eu,"xe");function jl(n){let e=new we({multigraph:n.isMultigraph()}).setGraph(n.graph());return n.nodes().forEach(t=>{n.children(t).length||e.setNode(t,n.node(t))}),n.edges().forEach(t=>{e.setEdge(t,n.edge(t))}),e}o(jl,"A");function Pl(n,e){let t=n.x,i=n.y,s=e.x-t,r=e.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:t+c,y:i+h}}o(Pl,"H");function Ii(n){let e=Nn(Dl(n)+1).map(()=>[]);return n.nodes().forEach(t=>{let i=n.node(t),s=i.rank;s!==void 0&&(e[s]||(e[s]=[]),e[s][i.order]=t)}),e}o(Ii,"N");function _u(n){let e=n.nodes().map(i=>{let s=n.node(i).rank;return s===void 0?Number.MAX_VALUE:s}),t=Fe(Math.min,e);n.nodes().forEach(i=>{let s=n.node(i);Object.hasOwn(s,"rank")&&(s.rank-=t)})}o(_u,"Te");function ku(n){let e=n.nodes().map(a=>n.node(a).rank).filter(a=>a!==void 0),t=Fe(Math.min,e),i=[];n.nodes().forEach(a=>{let l=n.node(a).rank-t;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(ku,"Oe");function Nl(n,e,t,i){let s={width:0,height:0};return arguments.length>=4&&(s.rank=t,s.order=i),Bt(n,"border",s,e)}o(Nl,"q");function Su(n,e=Tl){let t=[];for(let i=0;i<n.length;i+=e){let s=n.slice(i,i+e);t.push(s)}return t}o(Su,"Dn");var Tl=65535;function Fe(n,e){if(e.length>Tl){let t=Su(e);return n(...t.map(i=>n(...i)))}else return n(...e)}o(Fe,"L");function Dl(n){let e=n.nodes().map(t=>{let i=n.node(t).rank;return i===void 0?Number.MIN_VALUE:i});return Fe(Math.max,e)}o(Dl,"X");function Mu(n,e){let t={lhs:[],rhs:[]};return n.forEach(i=>{e(i)?t.lhs.push(i):t.rhs.push(i)}),t}o(Mu,"Ce");function Au(n,e){let t=Date.now();try{return e()}finally{console.log(n+" time: "+(Date.now()-t)+"ms")}}o(Au,"P");function Cu(n,e){return e()}o(Cu,"M");var Iu=0;function ks(n){let e=++Iu;return n+(""+e)}o(ks,"j");function Nn(n,e,t=1){e==null&&(e=n,n=0);let i=o(r=>r<e,"r");t<0&&(i=o(r=>e<r,"r"));let s=[];for(let r=n;i(r);r+=t)s.push(r);return s}o(Nn,"k");function ji(n,e){let t={};for(let i of e)n[i]!==void 0&&(t[i]=n[i]);return t}o(ji,"T");function Pi(n,e){let t;return typeof e=="string"?t=o(i=>i[e],"t"):t=e,Object.entries(n).reduce((i,[s,r])=>(i[s]=t(r,s),i),{})}o(Pi,"O");function ju(n,e){return n.reduce((t,i,s)=>(t[i]=e[s],t),{})}o(ju,"Re");var Ni="\0",Pu=(Xt=class{constructor(){qh(this,"_sentinel");let e={};e._next=e._prev=e,this._sentinel=e}dequeue(){let e=this._sentinel,t=e._prev;if(t!==e)return Ll(t),t}enqueue(e){let t=this._sentinel;e._prev&&e._next&&Ll(e),e._next=t._next,t._next._prev=e,t._next=e,e._prev=t}toString(){let e=[],t=this._sentinel,i=t._prev;for(;i!==t;)e.push(JSON.stringify(i,Nu)),i=i._prev;return"["+e.join(", ")+"]"}},o(Xt,"K"),Xt);function Ll(n){n._prev._next=n._next,n._next._prev=n._prev,delete n._next,delete n._prev}o(Ll,"Pe");function Nu(n,e){if(n!=="_next"&&n!=="_prev")return e}o(Nu,"Vn");var Tu=Pu,Du=o(()=>1,"Wn");function Lu(n,e){if(n.nodeCount()<=1)return[];let t=zu(n,e||Du);return Ou(t.graph,t.buckets,t.zeroIdx).flatMap(i=>n.outEdges(i.v,i.w)||[])}o(Lu,"Q");function Ou(n,e,t){var i;let s=[],r=e[e.length-1],a=e[0],l;for(;n.nodeCount();){for(;l=a.dequeue();)Ss(n,e,t,l);for(;l=r.dequeue();)Ss(n,e,t,l);if(n.nodeCount()){for(let c=e.length-2;c>0;--c)if(l=(i=e[c])==null?void 0:i.dequeue(),l){s=s.concat(Ss(n,e,t,l,!0)||[]);break}}}return s}o(Ou,"Bn");function Ss(n,e,t,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,Ms(e,t,h)}),(n.outEdges(i.v)||[]).forEach(l=>{let c=n.edge(l),h=l.w,u=n.node(h);u.in-=c,Ms(e,t,u)}),n.removeNode(i.v),a}o(Ss,"$");function zu(n,e){let t=new we,i=0,s=0;n.nodes().forEach(l=>{t.setNode(l,{v:l,in:0,out:0})}),n.edges().forEach(l=>{let c=t.edge(l.v,l.w)||0,h=e(l),u=c+h;t.setEdge(l.v,l.w,u);let p=t.node(l.v),g=t.node(l.w);s=Math.max(s,p.out+=h),i=Math.max(i,g.in+=h)});let r=Fu(s+i+3).map(()=>new Tu),a=i+1;return t.nodes().forEach(l=>{Ms(r,a,t.node(l))}),{graph:t,buckets:r,zeroIdx:a}}o(zu,"Yn");function Ms(n,e,t){var i,s,r;t.out?t.in?(r=n[t.out-t.in+e])==null||r.enqueue(t):(s=n[n.length-1])==null||s.enqueue(t):(i=n[0])==null||i.enqueue(t)}o(Ms,"J");function Fu(n){let e=[];for(let t=0;t<n;t++)e.push(t);return e}o(Fu,"zn");function $u(n){(n.graph().acyclicer==="greedy"?Lu(n,e(n)):Hu(n)).forEach(t=>{let i=n.edge(t);n.removeEdge(t),i.forwardName=t.name,i.reversed=!0,n.setEdge(t.w,t.v,i,ks("rev"))});function e(t){return i=>t.edge(i).weight}o(e,"t")}o($u,"je");function Hu(n){let e=[],t={},i={};function s(r){Object.hasOwn(i,r)||(i[r]=!0,t[r]=!0,n.outEdges(r).forEach(a=>{Object.hasOwn(t,a.w)?e.push(a):s(a.w)}),delete t[r])}return o(s,"o"),n.nodes().forEach(s),e}o(Hu,"Hn");function Bu(n){n.edges().forEach(e=>{let t=n.edge(e);if(t.reversed){n.removeEdge(e);let i=t.forwardName;delete t.reversed,delete t.forwardName,n.setEdge(e.w,e.v,t,i)}})}o(Bu,"Se");function Ru(n){n.graph().dummyChains=[],n.edges().forEach(e=>Gu(n,e))}o(Ru,"Fe");function Gu(n,e){let t=e.v,i=n.node(t).rank,s=e.w,r=n.node(s).rank,a=e.name,l=n.edge(e),c=l.labelRank;if(r===i+1)return;n.removeEdge(e);let h,u,p;for(p=0,++i;i<r;++p,++i)l.points=[],u={width:0,height:0,edgeLabel:l,edgeObj:e,rank:i},h=Bt(n,"edge",u,"_d"),i===c&&(u.width=l.width,u.height=l.height,u.dummy="edge-label",u.labelpos=l.labelpos),n.setEdge(t,h,{weight:l.weight},a),p===0&&n.graph().dummyChains.push(h),t=h;n.setEdge(t,s,{weight:l.weight},a)}o(Gu,"Xn");function Vu(n){n.graph().dummyChains.forEach(e=>{let t=n.node(e),i=t.edgeLabel,s;for(n.setEdge(t.edgeObj,i);t.dummy;)s=n.successors(e)[0],n.removeNode(e),i.points.push({x:t.x,y:t.y}),t.dummy==="edge-label"&&(i.x=t.x,i.y=t.y,i.width=t.width,i.height=t.height),e=s,t=n.node(e)})}o(Vu,"De");function As(n){let e={};function t(i){let s=n.node(i);if(Object.hasOwn(e,i))return s.rank;e[i]=!0;let r=n.outEdges(i),a=r?r.map(c=>c==null?Number.POSITIVE_INFINITY:t(c.w)-n.edge(c).minlen):[],l=Fe(Math.min,a);return l===Number.POSITIVE_INFINITY&&(l=0),s.rank=l}o(t,"t"),n.sources().forEach(t)}o(As,"S");function Rt(n,e){return n.node(e.w).rank-n.node(e.v).rank-n.edge(e).minlen}o(Rt,"v");var Ol=Wu;function Wu(n){let e=new we({directed:!1}),t=n.nodes();if(t.length===0)throw new Error("Graph must have at least one node");let i=t[0],s=n.nodeCount();e.setNode(i,{});let r,a;for(;Yu(e,n)<s&&(r=Zu(e,n),!!r);)a=e.hasNode(r.v)?Rt(n,r):-Rt(n,r),Ku(e,n,a);return e}o(Wu,"Kn");function Yu(n,e){function t(i){let s=e.nodeEdges(i);s&&s.forEach(r=>{let a=r.v,l=i===a?r.w:a;!n.hasNode(l)&&!Rt(e,r)&&(n.setNode(l,{}),n.setEdge(i,l,{}),t(l))})}return o(t,"t"),n.nodes().forEach(t),n.nodeCount()}o(Yu,"$n");function Zu(n,e){return e.edges().reduce((t,i)=>{let s=Number.POSITIVE_INFINITY;return n.hasNode(i.v)!==n.hasNode(i.w)&&(s=Rt(e,i)),s<t[0]?[s,i]:t},[Number.POSITIVE_INFINITY,null])[1]}o(Zu,"Jn");function Ku(n,e,t){n.nodes().forEach(i=>e.node(i).rank+=t)}o(Ku,"Qn");var{preorder:Uu,postorder:qu}=_s,Xu=pt;pt.initLowLimValues=Is,pt.initCutValues=Cs,pt.calcCutValue=zl,pt.leaveEdge=$l,pt.enterEdge=Hl,pt.exchangeEdges=Bl;function pt(n){n=Eu(n),As(n);let e=Ol(n);Is(e),Cs(e,n);let t,i;for(;t=$l(e);)i=Hl(e,n,t),Bl(e,n,t,i)}o(pt,"x");function Cs(n,e){let t=qu(n,n.nodes());t=t.slice(0,t.length-1),t.forEach(i=>Ju(n,e,i))}o(Cs,"Z");function Ju(n,e,t){let i=n.node(t).parent,s=n.edge(t,i);s.cutvalue=zl(n,e,t)}o(Ju,"nt");function zl(n,e,t){let i=n.node(t).parent,s=!0,r=e.edge(t,i),a=0;r||(s=!1,r=e.edge(i,t)),a=r.weight;let l=e.nodeEdges(t);return l&&l.forEach(c=>{let h=c.v===t,u=h?c.w:c.v;if(u!==i){let p=h===s,g=e.edge(c).weight;if(a+=p?g:-g,eg(n,t,u)){let m=n.edge(t,u).cutvalue;a+=p?-m:m}}}),a}o(zl,"We");function Is(n,e){arguments.length<2&&(e=n.nodes()[0]),Fl(n,{},1,e)}o(Is,"ee");function Fl(n,e,t,i,s){let r=t,a=n.node(i);e[i]=!0;let l=n.neighbors(i);return l&&l.forEach(c=>{Object.hasOwn(e,c)||(t=Fl(n,e,t,c,i))}),a.low=r,a.lim=t++,s?a.parent=s:delete a.parent,t}o(Fl,"Be");function $l(n){return n.edges().find(e=>n.edge(e).cutvalue<0)}o($l,"Ye");function Hl(n,e,t){let i=t.v,s=t.w;e.hasEdge(i,s)||(i=t.w,s=t.v);let r=n.node(i),a=n.node(s),l=r,c=!1;return r.lim>a.lim&&(l=a,c=!0),e.edges().filter(h=>c===Rl(n,n.node(h.v),l)&&c!==Rl(n,n.node(h.w),l)).reduce((h,u)=>Rt(e,u)<Rt(e,h)?u:h)}o(Hl,"ze");function Bl(n,e,t,i){let s=t.v,r=t.w;n.removeEdge(s,r),n.setEdge(i.v,i.w,{}),Is(n),Cs(n,e),Qu(n,e)}o(Bl,"He");function Qu(n,e){let t=n.nodes().find(s=>!n.node(s).parent);if(!t)return;let i=Uu(n,[t]);i=i.slice(1),i.forEach(s=>{let r=n.node(s).parent,a=e.edge(s,r),l=!1;a||(a=e.edge(r,s),l=!0),e.node(s).rank=e.node(r).rank+(l?a.minlen:-a.minlen)})}o(Qu,"tt");function eg(n,e,t){return n.hasEdge(e,t)}o(eg,"rt");function Rl(n,e,t){return t.low<=e.lim&&e.lim<=t.lim}o(Rl,"Ae");var tg=ng;function ng(n){let e=n.graph().ranker;if(typeof e=="function")return e(n);switch(e){case"network-simplex":Gl(n);break;case"tight-tree":sg(n);break;case"longest-path":ig(n);break;case"none":break;default:Gl(n)}}o(ng,"ot");var ig=As;function sg(n){As(n),Ol(n)}o(sg,"st");function Gl(n){Xu(n)}o(Gl,"qe");var rg=ag;function ag(n){let e=lg(n);n.graph().dummyChains.forEach(t=>{let i=n.node(t),s=i.edgeObj,r=og(n,e,s.v,s.w),a=r.path,l=r.lca,c=0,h=a[c],u=!0;for(;t!==s.w;){if(i=n.node(t),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(t,h),t=n.successors(t)[0]}})}o(ag,"at");function og(n,e,t,i){let s=[],r=[],a=Math.min(e[t].low,e[i].low),l=Math.max(e[t].lim,e[i].lim),c;c=t;do c=n.parent(c),s.push(c);while(c&&(e[c].low>a||l>e[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(og,"dt");function lg(n){let e={},t=0;function i(s){let r=t;n.children(s).forEach(i),e[s]={low:r,lim:t++}}return o(i,"r"),n.children(Ni).forEach(i),e}o(lg,"lt");function cg(n){let e=Bt(n,"root",{},"_root"),t=dg(n),i=Object.values(t),s=Fe(Math.max,i)-1,r=2*s+1;n.graph().nestingRoot=e,n.edges().forEach(l=>n.edge(l).minlen*=r);let a=hg(n)+1;n.children(Ni).forEach(l=>Vl(n,e,r,a,s,t,l)),n.graph().nodeRankFactor=r}o(cg,"Ke");function Vl(n,e,t,i,s,r,a){var l;let c=n.children(a);if(!c.length){a!==e&&n.setEdge(e,a,{weight:0,minlen:t});return}let h=Nl(n,"_bt"),u=Nl(n,"_bb"),p=n.node(a);n.setParent(h,a),p.borderTop=h,n.setParent(u,a),p.borderBottom=u,c.forEach(g=>{var m;Vl(n,e,t,i,s,r,g);let x=n.node(g),b=x.borderTop?x.borderTop:g,v=x.borderBottom?x.borderBottom:g,w=x.borderTop?i:2*i,_=b!==v?1:s-((m=r[a])!=null?m:0)+1;n.setEdge(h,b,{weight:w,minlen:_,nestingEdge:!0}),n.setEdge(v,u,{weight:w,minlen:_,nestingEdge:!0})}),n.parent(a)||n.setEdge(e,h,{weight:0,minlen:s+((l=r[a])!=null?l:0)})}o(Vl,"$e");function dg(n){let e={};function t(i,s){let r=n.children(i);r&&r.length&&r.forEach(a=>t(a,s+1)),e[i]=s}return o(t,"t"),n.children(Ni).forEach(i=>t(i,1)),e}o(dg,"ut");function hg(n){return n.edges().reduce((e,t)=>e+n.edge(t).weight,0)}o(hg,"ct");function ug(n){let e=n.graph();n.removeNode(e.nestingRoot),delete e.nestingRoot,n.edges().forEach(t=>{n.edge(t).nestingEdge&&n.removeEdge(t)})}o(ug,"Je");var gg=pg;function pg(n){function e(t){let i=n.children(t),s=n.node(t);if(i.length&&i.forEach(e),Object.hasOwn(s,"minRank")){s.borderLeft=[],s.borderRight=[];for(let r=s.minRank,a=s.maxRank+1;r<a;++r)Wl(n,"borderLeft","_bl",t,s,r),Wl(n,"borderRight","_br",t,s,r)}}o(e,"n"),n.children(Ni).forEach(e)}o(pg,"ft");function Wl(n,e,t,i,s,r){let a={width:0,height:0,rank:r,borderType:e},l=s[e][r-1],c=Bt(n,"border",a,t);s[e][r]=c,n.setParent(c,i),l&&n.setEdge(l,c,{weight:1})}o(Wl,"Qe");function fg(n){var e;let t=(e=n.graph().rankdir)==null?void 0:e.toLowerCase();(t==="lr"||t==="rl")&&Yl(n)}o(fg,"nn");function mg(n){var e;let t=(e=n.graph().rankdir)==null?void 0:e.toLowerCase();(t==="bt"||t==="rl")&&yg(n),(t==="lr"||t==="rl")&&(bg(n),Yl(n))}o(mg,"tn");function Yl(n){n.nodes().forEach(e=>Zl(n.node(e))),n.edges().forEach(e=>Zl(n.edge(e)))}o(Yl,"rn");function Zl(n){let e=n.width;n.width=n.height,n.height=e}o(Zl,"en");function yg(n){n.nodes().forEach(e=>js(n.node(e))),n.edges().forEach(e=>{var t;let i=n.edge(e);(t=i.points)==null||t.forEach(js),Object.hasOwn(i,"y")&&js(i)})}o(yg,"bt");function js(n){n.y=-n.y}o(js,"ne");function bg(n){n.nodes().forEach(e=>Ps(n.node(e))),n.edges().forEach(e=>{var t;let i=n.edge(e);(t=i.points)==null||t.forEach(Ps),Object.hasOwn(i,"x")&&Ps(i)})}o(bg,"gt");function Ps(n){let e=n.x;n.x=n.y,n.y=e}o(Ps,"te");function xg(n){let e={},t=n.nodes().filter(l=>!n.children(l).length),i=t.map(l=>n.node(l).rank),s=Fe(Math.max,i),r=Nn(s+1).map(()=>[]);function a(l){if(e[l])return;e[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"),t.sort((l,c)=>n.node(l).rank-n.node(c).rank).forEach(a),r}o(xg,"re");function vg(n,e){let t=0;for(let i=1;i<e.length;++i)t+=wg(n,e[i-1],e[i]);return t}o(vg,"oe");function wg(n,e,t){let i=ju(t,t.map((h,u)=>u)),s=e.flatMap(h=>{let u=n.outEdges(h);return u?u.map(p=>({pos:i[p.w],weight:n.edge(p).weight})).sort((p,g)=>p.pos-g.pos):[]}),r=1;for(;r<t.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 p=0;for(;u>0;)u%2&&(p+=l[u+1]),u=u-1>>1,l[u]+=h.weight;c+=h.weight*p}),c}o(wg,"mt");function Eg(n,e=[]){return e.map(t=>{let i=n.inEdges(t);if(!i||!i.length)return{v:t};{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:t,barycenter:s.sum/s.weight,weight:s.weight}}})}o(Eg,"ie");function _g(n,e){let t={};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),t[s.v]=a}),e.edges().forEach(s=>{let r=t[s.v],a=t[s.w];r!==void 0&&a!==void 0&&(a.indegree++,r.out.push(a))});let i=Object.values(t).filter(s=>!s.indegree);return kg(i)}o(_g,"se");function kg(n){let e=[];function t(s){return r=>{r.merged||(r.barycenter===void 0||s.barycenter===void 0||r.barycenter>=s.barycenter)&&Sg(s,r)}}o(t,"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();e.push(s),s.in.reverse().forEach(t(s)),s.out.forEach(i(s))}return e.filter(s=>!s.merged).map(s=>ji(s,["vs","i","barycenter","weight"]))}o(kg,"Et");function Sg(n,e){let t=0,i=0;n.weight&&(t+=n.barycenter*n.weight,i+=n.weight),e.weight&&(t+=e.barycenter*e.weight,i+=e.weight),n.vs=e.vs.concat(n.vs),n.barycenter=t/i,n.weight=i,n.i=Math.min(e.i,n.i),e.merged=!0}o(Sg,"Lt");function Mg(n,e){let t=Mu(n,u=>Object.hasOwn(u,"barycenter")),i=t.lhs,s=t.rhs.sort((u,p)=>p.i-u.i),r=[],a=0,l=0,c=0;i.sort(Ag(!!e)),c=Kl(r,s,c),i.forEach(u=>{c+=u.vs.length,r.push(u.vs),a+=u.barycenter*u.weight,l+=u.weight,c=Kl(r,s,c)});let h={vs:r.flat(1)};return l&&(h.barycenter=a/l,h.weight=l),h}o(Mg,"ae");function Kl(n,e,t){let i;for(;e.length&&(i=e[e.length-1]).i<=t;)e.pop(),n.push(i.vs),t++;return t}o(Kl,"on");function Ag(n){return(e,t)=>e.barycenter<t.barycenter?-1:e.barycenter>t.barycenter?1:n?t.i-e.i:e.i-t.i}o(Ag,"yt");function Ul(n,e,t,i){let s=n.children(e),r=n.node(e),a=r?r.borderLeft:void 0,l=r?r.borderRight:void 0,c={};a&&(s=s.filter(g=>g!==a&&g!==l));let h=Eg(n,s);h.forEach(g=>{if(n.children(g.v).length){let m=Ul(n,g.v,t,i);c[g.v]=m,Object.hasOwn(m,"barycenter")&&Ig(g,m)}});let u=_g(h,t);Cg(u,c);let p=Mg(u,i);if(a&&l){p.vs=[a,p.vs,l].flat(1);let g=n.predecessors(a);if(g&&g.length){let m=n.node(g[0]),x=n.predecessors(l),b=n.node(x[0]);Object.hasOwn(p,"barycenter")||(p.barycenter=0,p.weight=0),p.barycenter=(p.barycenter*p.weight+m.order+b.order)/(p.weight+2),p.weight+=2}}return p}o(Ul,"W");function Cg(n,e){n.forEach(t=>{t.vs=t.vs.flatMap(i=>e[i]?e[i].vs:i)})}o(Cg,"wt");function Ig(n,e){n.barycenter!==void 0?(n.barycenter=(n.barycenter*n.weight+e.barycenter*e.weight)/(n.weight+e.weight),n.weight+=e.weight):(n.barycenter=e.barycenter,n.weight=e.weight)}o(Ig,"Nt");function jg(n,e,t,i){i||(i=n.nodes());let s=Pg(n),r=new we({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===e||l.minRank<=e&&e<=l.maxRank){r.setNode(a),r.setParent(a,c||s);let h=n[t](a);h&&h.forEach(u=>{let p=u.v===a?u.w:u.v,g=r.edge(p,a),m=g!==void 0?g.weight:0;r.setEdge(p,a,{weight:n.edge(u).weight+m})}),Object.hasOwn(l,"minRank")&&r.setNode(a,{borderLeft:l.borderLeft[e],borderRight:l.borderRight[e]})}}),r}o(jg,"de");function Pg(n){let e;for(;n.hasNode(e=ks("_root")););return e}o(Pg,"Gt");function Ng(n,e,t){let i={},s;t.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){e.setEdge(c,a);return}a=l}})}o(Ng,"le");function ql(n,e={}){if(typeof e.customOrder=="function"){e.customOrder(n,ql);return}let t=Dl(n),i=Xl(n,Nn(1,t+1),"inEdges"),s=Xl(n,Nn(t-1,-1,-1),"outEdges"),r=xg(n);if(Jl(n,r),e.disableOptimalOrderHeuristic)return;let a=Number.POSITIVE_INFINITY,l,c=e.constraints||[];for(let h=0,u=0;u<4;++h,++u){Tg(h%2?i:s,h%4>=2,c),r=Ii(n);let p=vg(n,r);p<a?(u=0,l=Object.assign({},r),a=p):p===a&&(l=structuredClone(r))}Jl(n,l)}o(ql,"B");function Xl(n,e,t){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 e.map(function(r){return jg(n,r,t,i.get(r)||[])})}o(Xl,"sn");function Tg(n,e,t){let i=new we;n.forEach(function(s){t.forEach(l=>i.setEdge(l.left,l.right));let r=s.graph().root,a=Ul(s,r,i,e);a.vs.forEach((l,c)=>s.node(l).order=c),Ng(s,i,a.vs)})}o(Tg,"kt");function Jl(n,e){Object.values(e).forEach(t=>t.forEach((i,s)=>n.node(i).order=s))}o(Jl,"an");function Dg(n,e){let t={};function i(s,r){let a=0,l=0,c=s.length,h=r[r.length-1];return r.forEach((u,p)=>{let g=Og(n,u),m=g?n.node(g).order:c;(g||u===h)&&(r.slice(l,p+1).forEach(x=>{let b=n.predecessors(x);b&&b.forEach(v=>{let w=n.node(v),_=w.order;(_<a||m<_)&&!(w.dummy&&n.node(x).dummy)&&Ql(t,v,x)})}),l=p+1,a=m)}),r}return o(i,"r"),e.length&&e.reduce(i),t}o(Dg,"vt");function Lg(n,e){let t={};function i(r,a,l,c,h){Nn(a,l).forEach(u=>{let p=r[u];if(p!==void 0&&n.node(p).dummy){let g=n.predecessors(p);g&&g.forEach(m=>{if(m===void 0)return;let x=n.node(m);x.dummy&&(x.order<c||x.order>h)&&Ql(t,m,p)})}})}o(i,"r");function s(r,a){let l=-1,c=-1,h=0;return a.forEach((u,p)=>{if(n.node(u).dummy==="border"){let g=n.predecessors(u);if(g&&g.length){let m=g[0];if(m===void 0)return;c=n.node(m).order,i(a,h,p,l,c),h=p,l=c}}i(a,h,a.length,c,r.length)}),a}return o(s,"o"),e.length&&e.reduce(s),t}o(Lg,"_t");function Og(n,e){if(n.node(e).dummy){let t=n.predecessors(e);if(t)return t.find(i=>n.node(i).dummy)}}o(Og,"xt");function Ql(n,e,t){if(e>t){let s=e;e=t,t=s}let i=n[e];i||(n[e]=i={}),i[t]=!0}o(Ql,"dn");function zg(n,e,t){if(e>t){let s=e;e=t,t=s}let i=n[e];return i!==void 0&&Object.hasOwn(i,t)}o(zg,"Tt");function Fg(n,e,t,i){let s={},r={},a={};return e.forEach(l=>{l.forEach((c,h)=>{s[c]=c,r[c]=c,a[c]=h})}),e.forEach(l=>{let c=-1;l.forEach(h=>{let u=i(h);if(u&&u.length){let p=u.sort((m,x)=>{let b=a[m],v=a[x];return(b!==void 0?b:0)-(v!==void 0?v:0)}),g=(p.length-1)/2;for(let m=Math.floor(g),x=Math.ceil(g);m<=x;++m){let b=p[m];if(b===void 0)continue;let v=a[b];if(v!==void 0&&r[h]===h&&c<v&&!zg(t,h,b)){let w=s[b];w!==void 0&&(r[b]=h,r[h]=s[h]=w,c=v)}}}})}),{root:s,align:r}}o(Fg,"Ot");function $g(n,e,t,i,s=!1){let r={},a=Hg(n,e,t,s),l=s?"borderLeft":"borderRight";function c(m,x){let b=a.nodes().slice(),v={},w=b.pop();for(;w;){if(v[w])m(w);else{v[w]=!0,b.push(w);for(let _ of x(w))b.push(_)}w=b.pop()}}o(c,"d");function h(m){let x=a.inEdges(m);x?r[m]=x.reduce((b,v)=>{var w;let _=(w=r[v.v])!=null?w:0,k=a.edge(v);return Math.max(b,_+(k!==void 0?k:0))},0):r[m]=0}o(h,"l");function u(m){let x=a.outEdges(m),b=Number.POSITIVE_INFINITY;x&&(b=x.reduce((w,_)=>{let k=r[_.w],C=a.edge(_);return Math.min(w,(k!==void 0?k:0)-(C!==void 0?C:0))},Number.POSITIVE_INFINITY));let v=n.node(m);b!==Number.POSITIVE_INFINITY&&v.borderType!==l&&(r[m]=Math.max(r[m]!==void 0?r[m]:0,b))}o(u,"u");function p(m){return a.predecessors(m)||[]}o(p,"c");function g(m){return a.successors(m)||[]}return o(g,"h"),c(h,p),c(u,g),Object.keys(i).forEach(m=>{var x;let b=t[m];b!==void 0&&(r[m]=(x=r[b])!=null?x:0)}),r}o($g,"It");function Hg(n,e,t,i){let s=new we,r=n.graph(),a=Wg(r.nodesep,r.edgesep,i);return e.forEach(l=>{let c;l.forEach(h=>{let u=t[h];if(u!==void 0){if(s.setNode(u),c!==void 0){let p=t[c];if(p!==void 0){let g=s.edge(p,u);s.setEdge(p,u,Math.max(a(n,h,c),g||0))}}c=h}})}),s}o(Hg,"Ct");function Bg(n,e){return Object.values(e).reduce((t,i)=>{let s=Number.NEGATIVE_INFINITY,r=Number.POSITIVE_INFINITY;Object.entries(i).forEach(([l,c])=>{let h=Yg(n,l)/2;s=Math.max(c+h,s),r=Math.min(c-h,r)});let a=s-r;return a<t[0]&&(t=[a,i]),t},[Number.POSITIVE_INFINITY,null])[1]}o(Bg,"Rt");function Rg(n,e){let t=Object.values(e),i=Fe(Math.min,t),s=Fe(Math.max,t);["u","d"].forEach(r=>{["l","r"].forEach(a=>{let l=r+a,c=n[l];if(!c||c===e)return;let h=Object.values(c),u=i-Fe(Math.min,h);a!=="l"&&(u=s-Fe(Math.max,h)),u&&(n[l]=Pi(c,p=>p+u))})})}o(Rg,"Pt");function Gg(n,e=void 0){let t=n.ul;return t?Pi(t,(i,s)=>{var r,a;if(e){let c=e.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(Gg,"Mt");function Vg(n){let e=Ii(n),t=Object.assign(Dg(n,e),Lg(n,e)),i={},s;["u","d"].forEach(a=>{s=a==="u"?e:Object.values(e).reverse(),["l","r"].forEach(l=>{l==="r"&&(s=s.map(u=>Object.values(u).reverse()));let c=Fg(n,s,t,u=>(a==="u"?n.predecessors(u):n.successors(u))||[]),h=$g(n,s,c.root,c.align,l==="r");l==="r"&&(h=Pi(h,u=>-u)),i[a+l]=h})});let r=Bg(n,i);return Rg(i,r),Gg(i,n.graph().align)}o(Vg,"ln");function Wg(n,e,t){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+=t?h:-h),h=void 0,c+=(a.dummy?e:n)/2,c+=(l.dummy?e: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+=t?h:-h),c}}o(Wg,"jt");function Yg(n,e){return n.node(e).width}o(Yg,"St");function Zg(n){n=jl(n),Kg(n),Object.entries(Vg(n)).forEach(([e,t])=>n.node(e).x=t)}o(Zg,"un");function Kg(n){let e=Ii(n),t=n.graph(),i=t.ranksep,s=t.rankalign,r=0;e.forEach(a=>{let l=a.reduce((c,h)=>{var u;let p=(u=n.node(h).height)!=null?u:0;return c>p?c:p},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(Kg,"Ft");function Ug(n,e={}){let t=e.debugTiming?Au:Cu;return t("layout",()=>{let i=t(" buildLayoutGraph",()=>rp(n));return t(" runLayout",()=>qg(i,t,e)),t(" updateInputGraph",()=>Xg(n,i)),i})}o(Ug,"he");function qg(n,e,t){e(" makeSpaceForEdgeLabels",()=>ap(n)),e(" removeSelfEdges",()=>fp(n)),e(" acyclic",()=>$u(n)),e(" nestingGraph.run",()=>cg(n)),e(" rank",()=>tg(jl(n))),e(" injectEdgeLabelProxies",()=>op(n)),e(" removeEmptyRanks",()=>ku(n)),e(" nestingGraph.cleanup",()=>ug(n)),e(" normalizeRanks",()=>_u(n)),e(" assignRankMinMax",()=>lp(n)),e(" removeEdgeLabelProxies",()=>cp(n)),e(" normalize.run",()=>Ru(n)),e(" parentDummyChains",()=>rg(n)),e(" addBorderSegments",()=>gg(n)),e(" order",()=>ql(n,t)),e(" insertSelfEdges",()=>mp(n)),e(" adjustCoordinateSystem",()=>fg(n)),e(" position",()=>Zg(n)),e(" positionSelfEdges",()=>yp(n)),e(" removeBorderNodes",()=>pp(n)),e(" normalize.undo",()=>Vu(n)),e(" fixupEdgeLabelCoords",()=>up(n)),e(" undoCoordinateSystem",()=>mg(n)),e(" translateGraph",()=>dp(n)),e(" assignNodeIntersects",()=>hp(n)),e(" reversePoints",()=>gp(n)),e(" acyclic.undo",()=>Bu(n))}o(qg,"Dt");function Xg(n,e){n.nodes().forEach(t=>{let i=n.node(t),s=e.node(t);i&&(i.x=s.x,i.y=s.y,i.order=s.order,i.rank=s.rank,e.children(t).length&&(i.width=s.width,i.height=s.height))}),n.edges().forEach(t=>{let i=n.edge(t),s=e.edge(t);i.points=s.points,Object.hasOwn(s,"x")&&(i.x=s.x,i.y=s.y)}),n.graph().width=e.graph().width,n.graph().height=e.graph().height}o(Xg,"At");var Jg=["nodesep","edgesep","ranksep","marginx","marginy"],Qg={ranksep:50,edgesep:20,nodesep:50,rankdir:"TB",rankalign:"center"},ep=["acyclicer","ranker","rankdir","align","rankalign"],tp=["width","height","rank"],ec={width:0,height:0},np=["minlen","weight","width","height","labeloffset"],ip={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},sp=["labelpos"];function rp(n){let e=new we({multigraph:!0,compound:!0}),t=Ts(n.graph());return e.setGraph(Object.assign({},Qg,Ns(t,Jg),ji(t,ep))),n.nodes().forEach(i=>{let s=Ts(n.node(i)),r=Ns(s,tp);Object.keys(ec).forEach(l=>{r[l]===void 0&&(r[l]=ec[l])}),e.setNode(i,r);let a=n.parent(i);a!==void 0&&e.setParent(i,a)}),n.edges().forEach(i=>{let s=Ts(n.edge(i));e.setEdge(i,Object.assign({},ip,Ns(s,np),ji(s,sp)))}),e}o(rp,"Xt");function ap(n){let e=n.graph();e.ranksep/=2,n.edges().forEach(t=>{let i=n.edge(t);i.minlen*=2,i.labelpos.toLowerCase()!=="c"&&(e.rankdir==="TB"||e.rankdir==="BT"?i.width+=i.labeloffset:i.height+=i.labeloffset)})}o(ap,"Ut");function op(n){n.edges().forEach(e=>{let t=n.edge(e);if(t.width&&t.height){let i=n.node(e.v),s={rank:(n.node(e.w).rank-i.rank)/2+i.rank,e};Bt(n,"edge-proxy",s,"_ep")}})}o(op,"Kt");function lp(n){let e=0;n.nodes().forEach(t=>{let i=n.node(t);i.borderTop&&(i.minRank=n.node(i.borderTop).rank,i.maxRank=n.node(i.borderBottom).rank,e=Math.max(e,i.maxRank))}),n.graph().maxRank=e}o(lp,"$t");function cp(n){n.nodes().forEach(e=>{let t=n.node(e);if(t.dummy==="edge-proxy"){let i=t;n.edge(i.e).labelRank=t.rank,n.removeNode(e)}})}o(cp,"Jt");function dp(n){let e=Number.POSITIVE_INFINITY,t=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,p=h.y,g=h.width,m=h.height;e=Math.min(e,u-g/2),t=Math.max(t,u+g/2),i=Math.min(i,p-m/2),s=Math.max(s,p+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)}),e-=a,i-=l,n.nodes().forEach(h=>{let u=n.node(h);u.x-=e,u.y-=i}),n.edges().forEach(h=>{let u=n.edge(h);u.points.forEach(p=>{p.x-=e,p.y-=i}),Object.hasOwn(u,"x")&&(u.x-=e),Object.hasOwn(u,"y")&&(u.y-=i)}),r.width=t-e+a,r.height=s-i+l}o(dp,"Qt");function hp(n){n.edges().forEach(e=>{let t=n.edge(e),i=n.node(e.v),s=n.node(e.w),r,a;t.points?(r=t.points[0],a=t.points[t.points.length-1]):(t.points=[],r=s,a=i),t.points.unshift(Pl(i,r)),t.points.push(Pl(s,a))})}o(hp,"Zt");function up(n){n.edges().forEach(e=>{let t=n.edge(e);if(Object.hasOwn(t,"x"))switch((t.labelpos==="l"||t.labelpos==="r")&&(t.width-=t.labeloffset),t.labelpos){case"l":t.x-=t.width/2+t.labeloffset;break;case"r":t.x+=t.width/2+t.labeloffset;break}})}o(up,"er");function gp(n){n.edges().forEach(e=>{let t=n.edge(e);t.reversed&&t.points.reverse()})}o(gp,"nr");function pp(n){n.nodes().forEach(e=>{if(n.children(e).length){let t=n.node(e),i=n.node(t.borderTop),s=n.node(t.borderBottom),r=n.node(t.borderLeft[t.borderLeft.length-1]),a=n.node(t.borderRight[t.borderRight.length-1]);t.width=Math.abs(a.x-r.x),t.height=Math.abs(s.y-i.y),t.x=r.x+t.width/2,t.y=i.y+t.height/2}}),n.nodes().forEach(e=>{n.node(e).dummy==="border"&&n.removeNode(e)})}o(pp,"tr");function fp(n){n.edges().forEach(e=>{if(e.v===e.w){let t=n.node(e.v);t.selfEdges||(t.selfEdges=[]),t.selfEdges.push({e,label:n.edge(e)}),n.removeEdge(e)}})}o(fp,"rr");function mp(n){Ii(n).forEach(e=>{let t=0;e.forEach((i,s)=>{let r=n.node(i);r.order=s+t,(r.selfEdges||[]).forEach(a=>{Bt(n,"selfedge",{width:a.label.width,height:a.label.height,rank:r.rank,order:s+ ++t,e:a.e,label:a.label},"_se")}),delete r.selfEdges})})}o(mp,"or");function yp(n){n.nodes().forEach(e=>{let t=n.node(e);if(t.dummy==="selfedge"){let i=t,s=n.node(i.e.v),r=s.x+s.width/2,a=s.y,l=t.x-r,c=s.height/2;n.setEdge(i.e,i.label),n.removeNode(e),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=t.x,i.label.y=t.y}})}o(yp,"ir");function Ns(n,e){return Pi(ji(n,e),Number)}o(Ns,"ue");function Ts(n){let e={};return n&&Object.entries(n).forEach(([t,i])=>{typeof t=="string"&&(t=t.toLowerCase()),e[t]=i}),e}o(Ts,"ce");function bp(n){return n.nodes.filter(e=>e instanceof Ze)}o(bp,"relationalNodes");function xp(n){return n.edges.filter(e=>e instanceof ve)}o(xp,"relationalEdges");function vp(n,e,t){n.from===e&&n.to===t||(n.from.removeOutgoingEdge(n),n.to.removeIncomingEdge(n),n.setState("from",e),n.setState("to",t),n.setState("displacementStart",void 0),n.setState("displacementEnd",void 0),n.setState("startAnchor",{mode:"fixed",position:e.relativePosition}),n.setState("endAnchor",{mode:"fixed",position:t.relativePosition}),e.addOutgoingEdge(n,!1),t.addIncomingEdge(n,!1))}o(vp,"rewire");function wp(n){n.forEach(e=>{const t=e.from.parent,i=e.to.parent,s=Math.max(0,e.mappingIndex),r=e.sourceAttributeIds[Math.min(s,e.sourceAttributeIds.length-1)],a=e.targetAttributeIds[Math.min(s,e.targetAttributeIds.length-1)],l=t.box.middle.x<=i.box.middle.x?"right":"left",c=l==="right"?"left":"right",h=t.gatewayForAttribute(r,l),u=i.gatewayForAttribute(a,c);h&&u&&vp(e,h,u)})}o(wp,"alignForeignKeyGateways");function Ep(n,e){n.forEach(t=>{t.from.recomputeConnectedEdge(t,"from");const i=t.labels[0];if(!i)return;const s=t instanceof ve?e.get(t.constraintId):void 0;i.setPosition(s?new y([s.x-s.width/2,s.y-s.height/2]):t.defaultLabelPosition())})}o(Ep,"reroute");function _p(n){const e=bp(n);if(e.length===0)return!1;const t=xp(n),i=n.getExtension(B)?.gridSize??50,s=new we({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(()=>({}));e.forEach(c=>{s.setNode(c.id,{width:c.box.width,height:c.box.height})});const r=new Set;t.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 p=c.labels[0];s.setEdge(u.id,h.id,{height:p?.size.height??0,labelpos:"c",minlen:1,weight:2,width:p?.size.width??0},c.constraintId)}),Ug(s);const a=new Map;t.forEach(c=>{if(c.mappingIndex!==0||!c.labels[0])return;const h=c.from.parent,u=c.to.parent;if(h===u)return;const p=s.edge(u.id,h.id,c.constraintId);p?.x!==void 0&&p.y!==void 0&&p.width!==void 0&&p.height!==void 0&&a.set(c.constraintId,p)});let l=!1;return e.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})}),wp(t),Ep(t,a),l}o(_p,"applyMRAutoLayout");function kp(n){return n.model.constraints.find(t=>t.kind==="primary-key"&&t.attributeIds.length>0)?.attributeIds??n.model.attributes.filter(t=>t.primaryKey).map(t=>t.id)}o(kp,"primaryKeyAttributes");function tc(n,e){return n[Math.min(e,n.length-1)]}o(tc,"mappingValue");const Ja=class Ja extends ot{constructor(e){super(e),this.registerClass(Ze),this.registerClass(ve),this.registerExtension(Ht),this.setDefaultEdge(ve)}createTableFromClientPoint(e,t,i,s){const r=this.canvas.inverseFit(new y([t,i]));return this.getExtension(Ht).createTable(r,e,s)}createTableAtCanvasPoint(e,t,i,s){return this.getExtension(Ht).createTable(new y([t,i]),e,s)}autoLayout(){return this.emit(new Si(this)),_p(this)}connectForeignKey(e,t,i={}){const s=i.sourceAttributeIds?.length?[...i.sourceAttributeIds]:[e.model.attributes.find(p=>!p.primaryKey)?.id??e.model.attributes[0]?.id].filter(Boolean),r=i.targetAttributeIds?.length?[...i.targetAttributeIds]:kp(t);if(!s.length||!r.length)throw new Error("Foreign keys require source and referenced attributes.");const a=e.box.middle.x<=t.box.middle.x?"right":"left",l=a==="right"?"left":"right",c=Math.max(s.length,r.length),h=[];let u=i.constraintId;for(let p=0;p<c;p+=1){const g=tc(s,p),m=tc(r,p),x=e.gatewayForAttribute(g,a),b=t.gatewayForAttribute(m,l);if(!x||!b)throw new Error("Unable to resolve a foreign-key attribute gateway.");const v=this.connect(x,b);u??=v.constraintId,v.updateModel({...i,constraintId:u,mappingIndex:p,sourceAttributeIds:s,targetAttributeIds:r}),h.push(v)}return h[0]}};o(Ja,"MRDiagram");let Ds=Ja;function ft(n){return n&&(Object.assign(n,{__scalable:!0}),n)}o(ft,"makeScalableComponent");function Sp(n){return n&&(Object.assign(n,{__scalableBack:!0}),n)}o(Sp,"makeBackScalableComponent");const Ls=ft(({coordinates:n,size:e=20,strokeWidth:t=2,rounded:i=!0,stroke:s="#ff0000"})=>{const r=e/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:t,strokeLinecap:a}),d.jsx("line",{x1:n.x,y1:n.y-r,x2:n.x,y2:n.y+r,stroke:s,strokeWidth:t,strokeLinecap:a})]})}),Mp=10,Ap={height:30,width:16},nc=32;function ic(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(ic,"orientationVector$1");function Cp(n,e,t,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+e.x*l+t.x*c+i.x*h,n.y*a+e.y*l+t.y*c+i.y*h],!1)}o(Cp,"cubicPoint");function Ip(n){const e=n.steps;if(e.length<2||n.pathType==="orthogonal")return[...e];const t=e[0],i=e.at(-1);if(n.pathType==="straight")return[t,i];const s=t.distance(i),r=Math.max(40,Math.min(160,s/2)),a=ic(n.from.orientation),l=ic(n.to.orientation),c=new y([t.x+a[0]*r,t.y+a[1]*r],!1),h=new y([i.x+l[0]*r,i.y+l[1]*r],!1);return Array.from({length:nc+1},(u,p)=>Cp(t,c,h,i,p/nc))}o(Ip,"routePolyline");function jp(n,e,t,i){const s=Math.abs(e[0])*t.width/2+Math.abs(e[1])*t.height/2,r=i+s;return new y([n.x+e[0]*r-t.width/2,n.y+e[1]*r-t.height/2])}o(jp,"candidatePosition");function Pp(n){const e=n.diagram?.canvas;if(!e)return null;const t=e.frameDimensions;return t.width<=0||t.height<=0?null:e.inverseFit(t)}o(Pp,"visibleViewport");function Np(n,e){return Math.max(0,e.x-n.x)+Math.max(0,e.y-n.y)+Math.max(0,n.x+n.width-(e.x+e.width))+Math.max(0,n.y+n.height-(e.y+e.height))}o(Np,"viewportOverflow");function Tp(n,e,t){const i=[];return e[0]>0?i.push((t.x+t.width-n.x)/e[0]):e[0]<0&&i.push((t.x-n.x)/e[0]),e[1]>0?i.push((t.y+t.height-n.y)/e[1]):e[1]<0&&i.push((t.y-n.y)/e[1]),Math.min(...i.filter(s=>s>=0))}o(Tp,"availableRayDistance");function sc(n,e,t,i,s,r){const a=new M([e.x,e.y,s.width,s.height]);return[n.diagram?.nodes.filter(c=>c.box.collides(a)).length??0,Np(a,r),-Tp(t,i,r)]}o(sc,"placementScore");function Dp(n,e,t=Ap,i=Mp){const s=Ip(n);let r=Number.POSITIVE_INFINITY,a=null,l=null;for(let _=0;_<s.length-1;_+=1){const k=s[_],C=s[_+1],P=C.x-k.x,D=C.y-k.y,N=P**2+D**2;if(N<1e-6)continue;const T=Math.max(0,Math.min(1,((e.x-k.x)*P+(e.y-k.y)*D)/N)),V=k.x+P*T,X=k.y+D*T,K=(e.x-V)**2+(e.y-X)**2;K>=r||(r=K,a=[V,X],l=[P,D])}const c=Math.max(n.diagram?.canvas.scale??1,.001),h=i/c;if(!a||!l)return e.copy().sum([-t.width/2,-h-t.height]);const u=Math.hypot(l[0],l[1]);let p=-l[1]/u,g=l[0]/u;(g>1e-6||Math.abs(g)<=1e-6&&p<0)&&(p*=-1,g*=-1);const m=new y(a),x=[p,g],b=[-p,-g],v=[x,b].map(_=>({normal:_,position:jp(m,_,t,h)})),w=Pp(n);return w&&v.sort((_,k)=>{const C=sc(n,_.position,m,_.normal,t,w),P=sc(n,k.position,m,k.normal,t,w);for(let D=0;D<C.length;D+=1)if(C[D]!==P[D])return C[D]-P[D];return 0}),v[0].position}o(Dp,"positionEdgeLabelBesideRoute");function rc(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(rc,"orientationVector");function Lp(n,e,t){const i=n[0],s=n.at(-1),r=e?.pathType??t??"orthogonal";if(r==="orthogonal")return"M "+n.map(x=>`${x.x} ${x.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=rc(e?.from.orientation),h=rc(e?.to.orientation),u=i.x+c[0]*l,p=i.y+c[1]*l,g=s.x+h[0]*l,m=s.y+h[1]*l;return`M ${i.x} ${i.y} C ${u} ${p}, ${g} ${m}, ${s.x} ${s.y}`}o(Lp,"buildEdgePath");const Op={};function zp(){const n=Op;return n.DEBUG_EDGES===!0||n.DEBUG_EDGES==="true"}o(zp,"debugEdgesEnabled");function Fp(n,e){const t=n instanceof R?n.mode:"coordinate",i=n instanceof R?n.manualAxes:"none";return`${e}: x=${n.x}, y=${n.y}, mode=${t}, manualAxes=${i}`}o(Fp,"formatPoint");function $p(n,e){const t=e.points[0],i=e.points[1],s=n.steps.findIndex((a,l)=>a===t&&n.steps[l+1]===i);if(s>=0)return s;const r=Number(e.id);return Number.isFinite(r)?r:null}o($p,"segmentIndexFor");function Hp(n,e){if(e.type==="edge")return"clicked: edge path";if(e.type==="endpoint")return`clicked: endpoint ${e.endpoint}`;const t=$p(n,e.midpoint),i=t===null?"unknown":`${t} -> ${t+1}`;return["clicked: drag point",`dragPoint.midpointId=${e.midpoint.id}`,`dragPoint.renderedIndex=${e.renderedIndex}`,`dragPoint.segment=${i}`,`dragPoint.x=${e.midpoint.x}`,`dragPoint.y=${e.midpoint.y}`].join(`
3
+ `)}o(Hp,"formatClickedTarget");function Bp(n,e){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}`,Hp(n,e),"points:",...n.steps.map(Fp)].join(`
4
+ `)}o(Bp,"formatEdgeDebug");async function Rp(n){if(navigator.clipboard?.writeText){await navigator.clipboard.writeText(n);return}const e=document.createElement("textarea");e.value=n,e.style.position="fixed",e.style.left="-9999px",document.body.appendChild(e),e.focus(),e.select(),document.execCommand("copy"),e.remove()}o(Rp,"writeClipboard");function Tn(n,e){if(!n||!zp())return;const t=Bp(n,e);Rp(t).then(()=>{console.info("[DEBUG_EDGES] copied edge debug to clipboard",t)}).catch(i=>{console.warn("[DEBUG_EDGES] failed to copy edge debug to clipboard",i,t)})}o(Tn,"copyEdgeDebugToClipboard");const ac=o(({id:n,color:e,type:t,width:i,arrowSize:s,flip:r=!1})=>{const a=r?"180":"auto",l="white";switch(t){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:e,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:e,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:e,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:e,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:e,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:e,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:e,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:e,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:e,strokeWidth:3,strokeLinecap:"round",className:"edge_marker_outline"})});default:return null}},"EdgeMarker"),Li=class Li extends y{constructor(e,t,i,s){super(s),this.id=e,this.edge=t,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 Li(this.id,this.edge,this.points,super.copy())}};o(Li,"Midpoint");let Os=Li;function Gp(n,e){const t=[];for(let i=0;i<e.length-1;i++){const s=[e[i],e[i+1]],r=s.filter(l=>l instanceof R&&l.mode==="static").length,a=n.steps.length===2&&e.length===2;r===2&&!a||t.push(new Os(String(i),n,s))}return t}o(Gp,"getSegmentMidpoints");const Vp=o(({edge:n,onMouseDown:e,points:t})=>{const i=Gp(n,t);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&&(Tn(n,{type:"drag-point",midpoint:s,renderedIndex:r}),e(s,c))},"onMouseDownCapture")},s.id)})})},"EdgeMidpoints");function Wp(n){if(n instanceof R)switch(n.mode){case"auto":return"red";case"manual":return"green";case"static":return"yellow"}}o(Wp,"crossColor");const Dn=A.observer(({edge:n,points:e,color:t,width:i=2,arrowSize:s=8,startType:r="none",endType:a="arrow",lineStyle:l="solid",pathType:c,endStroke:h=t,startStroke:u=t,onMidpointMouseDown:p,onEndpointMouseDown:g,className:m,draggable:x,selected:b})=>{const v=o(T=>S.useMemo(()=>`marker-${T}-${Math.random().toString(36).slice(2)}`,[]),"makeId"),w=v("start"),_=v("end");if(!e||e.length<2)return null;const k=Lp(e,n,c),C=l==="dashed"?`${i*3},${i*2}`:l==="dotted"?`${i},${i*2}`:"none",P=b??n?.state.selected??!1,D=!!(n&&x&&n.pathType==="orthogonal"&&(n.state.hover||n.state.dragging||P)),N=!!(n&&x&&(P||n.state.dragging));return d.jsxs("g",{"data-id":n?.id,className:["edge",n?.state.dragging&&"dragging",P&&"selected",n?.state.hover&&"hover",m].filter(Boolean).join(" "),style:t?{"--edge-stroke":t}:void 0,onMouseEnter:o(()=>{f.runInAction(()=>{n&&(n.state.hover=!0)})},"onMouseEnter"),onMouseLeave:o(()=>{f.runInAction(()=>{n&&(n.state.hover=!1)})},"onMouseLeave"),onDoubleClick:o(T=>{if(!n?.diagram||!n.diagram.rules.allowEdition)return;T.stopPropagation();const V=n.diagram.canvas.inverseFit(new y(T.nativeEvent)),X=n.createLabel(V);X.setPosition(Dp(n,V,X.size))},"onDoubleClick"),children:[d.jsxs("defs",{children:[d.jsx(ac,{id:w,color:u,type:r,width:i,arrowSize:s,flip:!1}),d.jsx(ac,{id:_,color:h,type:a,width:i,arrowSize:s,flip:!1})]}),d.jsx("path",{d:k,strokeWidth:i+8,fill:"none",className:"edge-hover-area",onClickCapture:o(()=>{Tn(n,{type:"edge"})},"onClickCapture")}),d.jsx("path",{d:k,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:t,strokeWidth:i,strokeDasharray:C,markerStart:r!=="none"?`url(#${w})`:void 0,markerEnd:a!=="none"?`url(#${_})`:void 0,onClickCapture:o(()=>{Tn(n,{type:"edge"})},"onClickCapture")}),Hn.instance.showDragHints&&e.map((T,V)=>d.jsx(Ls,{coordinates:T,size:15,stroke:Wp(T)},V)),D&&d.jsx(Vp,{edge:n,points:e,onMouseDown:o((T,V)=>{p?.(T,V)},"onMouseDown")}),N&&d.jsxs(d.Fragment,{children:[d.jsxs("g",{className:"edge_endpoint_drag_handle","data-edge-id":n?.id,"data-endpoint":"from",onMouseDownCapture:o(T=>{T.button===0&&(Tn(n,{type:"endpoint",endpoint:"from"}),g?.("from",T))},"onMouseDownCapture"),children:[d.jsx("circle",{cx:e[0].x,cy:e[0].y,r:12,className:"edge_endpoint_drag_hit_area"}),d.jsx("circle",{cx:e[0].x,cy:e[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(T=>{T.button===0&&(Tn(n,{type:"endpoint",endpoint:"to"}),g?.("to",T))},"onMouseDownCapture"),children:[d.jsx("circle",{cx:e.at(-1).x,cy:e.at(-1).y,r:12,className:"edge_endpoint_drag_hit_area"}),d.jsx("circle",{cx:e.at(-1).x,cy:e.at(-1).y,r:6,className:"edge_endpoint_drag_point"})]})]})]})}),Yp=ft(A.observer(()=>{const n=J.use(),e=n.getExtension(at),t=n.getExtension(rt),i=e.arrowSteps;return!i.length&&!t.endpointCandidatePoint?null:d.jsxs(d.Fragment,{children:[e.candidatePoint&&d.jsx(Ls,{coordinates:e.candidatePoint,stroke:"yellow"}),t.endpointCandidatePoint&&d.jsx(Ls,{coordinates:t.endpointCandidatePoint,stroke:"yellow"}),d.jsx(Dn,{points:i,width:2*n.canvas.scale,arrowSize:8*n.canvas.scale,pathType:e.previewPathType})]})})),Zp=ft(A.observer(()=>{const e=J.use().getExtension(jt);return e?.enabled?d.jsx(d.Fragment,{children:d.jsx(Dn,{points:e.get(),startType:"measure",endType:"measure",width:2,arrowSize:12,lineStyle:"dotted",startStroke:"red",endStroke:"red",className:"measurement"})}):null})),Kp=S.forwardRef(({children:n,paths:e,transform:t,selected:i,onClick:s,className:r,roundedBorders:a=!1,label:l,labelColor:c,labelFontSize:h,labelFontFamily:u="sans-serif",labelOffset:p,"data-id":g,...m},x)=>{const b=J.use();return d.jsxs("g",{...m,"data-id":g,className:`${r||""} ${i?"selected":""} base_shape`,transform:t,onClick:s,ref:x,children:[d.jsx("defs",{children:e.map((v,w)=>{if(!v.arrow)return null;const _=6,{size:k=_,color:C=v.stroke??"#111"}=v.arrow,P=`arrow-${w}`;return d.jsx("marker",{id:P,viewBox:"0 0 10 10",refX:_*1.5,refY:"5",markerWidth:k,markerHeight:k,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"})},w)})}),e.map((v,w)=>{const{d:_,fill:k="none",stroke:C="#111",strokeWidth:P=3,strokeStyle:D="solid",animated:N=!1,animationDuration:T=1,nonScalingStroke:V=!0,roundedBorders:X=a,arrow:K}=v;let he;switch(D){case"dashed":he="10 5";break;case"dotted":he="2 6";break}const Ke=N?d.jsx("animate",{attributeName:"stroke-dashoffset",from:"0",to:he?`-${he.split(" ").reduce((to,Pf)=>+to+ +Pf,0)}`:"-15",dur:`${T}s`,repeatCount:"indefinite"}):null,Oi=K?`url(#arrow-${w})`:void 0;return d.jsx("path",{d:_,fill:k,stroke:C,strokeWidth:P,strokeDasharray:he,strokeLinecap:X?"round":"butt",strokeLinejoin:X?"round":"miter",vectorEffect:V?"non-scaling-stroke":void 0,markerStart:K?.position==="start"||K?.position==="both"?Oi:void 0,markerEnd:!K||K.position==="end"||K.position==="both"?Oi:void 0,children:Ke},w)}),l&&d.jsx("text",{x:p?.x??0,y:p?.y??0,textAnchor:"middle",dominantBaseline:"middle",fontFamily:u,fontSize:h,fill:c,pointerEvents:"none",...b.canvas.scale>1?{shapeRendering:"geometricPrecision",style:{paintOrder:"stroke",stroke:"transparent",strokeWidth:.5,WebkitFontSmoothing:"antialiased",transform:"translateZ(0)"}}:{},children:l}),n]})}),Gt=A.observer(Kp),oc=o((n,e=0)=>{const{x:t,y:i,width:s,height:r}=n;if(e<=0)return`M${t},${i} h${s} v${r} h${-s}Z`;const a=Math.min(e,s/2,r/2);return[`M${t+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"),Up=o((n,e)=>`M ${n.x-e}, ${n.y}
5
+ a ${e},${e} 0 1,0 ${2*e},0
6
+ a ${e},${e} 0 1,0 -${2*e},0`,"getCirclePath"),qp=ft(A.observer(()=>{const e=J.use().getExtension($);return e.selectionMode?d.jsx(d.Fragment,{children:d.jsx(Gt,{paths:[{d:oc(e.box,0),strokeWidth:1}],labelOffset:new y,className:"selection_square"})}):null})),Xp=Sp(()=>null);function Jp(n){return Array.isArray(n)?n:[n]}o(Jp,"arrayOrArray");const lc=S.forwardRef(({children:n,className:e,style:t},i)=>d.jsx("svg",{ref:i,className:e,width:"100%",height:"100%",style:{position:"absolute",top:0,left:0,pointerEvents:"none",...t},xmlns:"http://www.w3.org/2000/svg",children:n})),Qp=A.observer(()=>{const n=J.use();return n.extensions.map(e=>{const t=e.RenderDiagram;return t?d.jsx(t,{diagram:n,extension:e},e.constructor.name):null})});function ef(n,e,t){S.useLayoutEffect(()=>{const i=e.current,s=t.current;if(!i||!s)return;const r=o(()=>{const l=s.getBoundingClientRect(),c={height:Math.max(1,l.height),width:Math.max(1,l.width)};i instanceof HTMLTextAreaElement&&(i.style.width=`calc(${Math.ceil(c.width)+2}px * var(--diagram-canvas-scale, 1))`,i.style.height=`calc(${Math.ceil(c.height)+2}px * var(--diagram-canvas-scale, 1))`),(Math.abs(c.width-n.size.width)>.1||Math.abs(c.height-n.size.height)>.1)&&n.setSize(c)},"update");r();const a=typeof ResizeObserver>"u"?null:new ResizeObserver(r);return a?.observe(s),()=>a?.disconnect()},[n,n.draft,n.isEditing,n.text,e,t])}o(ef,"useEdgeLabelMeasurement");const tf=A.observer(({edge:n,label:e})=>{const t=S.useRef(null),i=S.useRef(null),s=S.useRef(null),r={"--edge-label-x":`${e.position.x}px`,"--edge-label-y":`${e.position.y}px`,"--edge-label-text-align":e.alignment},a=n.diagram?.rules.allowEdition!==!1;ef(e,t,i);const l=d.jsx("span",{"aria-hidden":"true",className:"edge-screen-label edge-label-measure",ref:i,children:e.isEditing?e.draft||"M":e.text});if(!a)return d.jsxs(d.Fragment,{children:[l,d.jsx("span",{className:"edge-screen-label","data-edge-id":n.id,"data-edge-label-id":e.id,ref:t,style:r,children:e.text})]});const c=o(()=>{const p=s.current;p&&p.autopanTimer!==null&&(clearInterval(p.autopanTimer),p.autopanTimer=null)},"clearDragAutopan"),h=o(()=>{const p=s.current;if(!p?.moved||!n.diagram)return;p.autopan.displace(p.latestPointer);const m=n.diagram.canvas.inverseFit(p.latestPointer).substract(p.startMouse),x=p.startPosition.copy().sum(m),b=n.diagram.getExtension(De)?.align(n,e,x)??x;e.setPosition(n.diagram.getExtension(Lt)?.constrain(p.startPosition,b,x)??b)},"updateDraggedLabel"),u=o(p=>{if(p.button!==0||!n.diagram)return;p.preventDefault(),p.stopPropagation(),p.nativeEvent.stopImmediatePropagation();const g=n.diagram,m=g.getExtension(De),x=new _e(g),b=new y(p.nativeEvent),v=g.canvas.inverseFit(b),w=e.position.copy();let _=b,k=!1,C=null;const P=o(()=>{if(!k)return;x.displace(_);const X=g.canvas.inverseFit(_).substract(v),K=w.copy().sum(X),he=m?.align(n,e,K)??K;e.setPosition(g.getExtension(Lt)?.constrain(w,he,K)??he)},"update"),D=o(X=>{_=new y(X),!(!k&&_.copy().substract(b).norm<5)&&(k=!0,C===null&&(C=setInterval(P,30)),P())},"move"),N=o(()=>{C!==null&&clearInterval(C),document.removeEventListener("pointermove",D),document.removeEventListener("pointerup",T),document.removeEventListener("pointercancel",V),m?.clear()},"cleanup"),T=o(()=>{N(),k&&e.commitPosition()},"finish"),V=o(()=>{N(),e.setPosition(w)},"cancel");m?.clear(),document.addEventListener("pointermove",D,{passive:!1}),document.addEventListener("pointerup",T,{once:!0}),document.addEventListener("pointercancel",V,{once:!0})},"startEditingDrag");if(e.isEditing){const p=o(()=>e.confirmEdit(),"confirmEdit");return d.jsxs("div",{className:"edge-label-editor","data-edge-id":n.id,"data-edge-label-id":e.id,onPointerDown:o(g=>g.stopPropagation(),"onPointerDown"),style:r,children:[l,d.jsx("textarea",{"aria-label":"Edge label",autoFocus:!0,className:"edge-screen-label edge-screen-label--editing",onBlur:p,onChange:o(g=>e.setDraft(g.target.value),"onChange"),onClick:o(g=>g.stopPropagation(),"onClick"),onDoubleClick:o(g=>g.stopPropagation(),"onDoubleClick"),onPointerDown:o(g=>g.stopPropagation(),"onPointerDown"),ref:t,onKeyDown:o(g=>{if(g.key==="Enter"){if(g.shiftKey){g.stopPropagation();return}g.preventDefault(),p()}else g.key==="Escape"&&(g.preventDefault(),e.cancelEdit());g.stopPropagation()},"onKeyDown"),cols:1,rows:1,value:e.draft,wrap:"off"}),d.jsxs("div",{className:"edge-label-editor__toolbar",children:[d.jsx("button",{"aria-label":"Move label",onPointerDown:u,title:"Move label",type:"button",children:d.jsx(wd,{})}),d.jsx("button",{"aria-label":"Align left","aria-pressed":e.alignment==="left",className:e.alignment==="left"?"selected":"",onMouseDown:o(g=>{g.preventDefault(),g.stopPropagation()},"onMouseDown"),onClick:o(()=>e.setAlignment("left"),"onClick"),title:"Align left",type:"button",children:d.jsx(ad,{})}),d.jsx("button",{"aria-label":"Align center","aria-pressed":e.alignment==="center",className:e.alignment==="center"?"selected":"",onMouseDown:o(g=>{g.preventDefault(),g.stopPropagation()},"onMouseDown"),onClick:o(()=>e.setAlignment("center"),"onClick"),title:"Align center",type:"button",children:d.jsx(od,{})}),d.jsx("button",{"aria-label":"Align right","aria-pressed":e.alignment==="right",className:e.alignment==="right"?"selected":"",onMouseDown:o(g=>{g.preventDefault(),g.stopPropagation()},"onMouseDown"),onClick:o(()=>e.setAlignment("right"),"onClick"),title:"Align right",type:"button",children:d.jsx(rd,{})}),d.jsx("button",{"aria-label":"Delete label",onMouseDown:o(g=>{g.preventDefault(),g.stopPropagation()},"onMouseDown"),onClick:o(()=>e.delete(),"onClick"),title:"Delete label",type:"button",children:d.jsx(To,{})})]})]})}return d.jsxs(d.Fragment,{children:[l,d.jsx("span",{className:"edge-screen-label","data-edge-id":n.id,"data-edge-label-id":e.id,ref:t,style:r,onPointerDown:o(p=>{p.button!==0||!n.diagram||(p.preventDefault(),p.stopPropagation(),p.currentTarget.setPointerCapture(p.pointerId),s.current={autopan:new _e(n.diagram),autopanTimer:null,latestPointer:new y(p.nativeEvent),pointerId:p.pointerId,startMouse:n.diagram.canvas.inverseFit(new y(p.nativeEvent)),startMouseScreen:new y(p.nativeEvent),startPosition:e.position.copy(),moved:!1},n.diagram?.getExtension(De)?.clear())},"onPointerDown"),onPointerMove:o(p=>{const g=s.current;!g||g.pointerId!==p.pointerId||!n.diagram||(g.latestPointer=new y(p.nativeEvent),g.latestPointer.copy().substract(g.startMouseScreen).norm<5&&!g.moved)||(g.moved=!0,g.autopanTimer===null&&(g.autopanTimer=setInterval(h,30)),h())},"onPointerMove"),onPointerUp:o(p=>{const g=s.current;!g||g.pointerId!==p.pointerId||(p.stopPropagation(),c(),p.currentTarget.hasPointerCapture(p.pointerId)&&p.currentTarget.releasePointerCapture(p.pointerId),g.moved&&e.position.copy(!1).substract(g.startPosition).norm>.001&&e.commitPosition(),g.moved||e.beginEdit(),n.diagram?.getExtension(De)?.clear(),s.current=null)},"onPointerUp"),onPointerCancel:o(p=>{const g=s.current;!g||g.pointerId!==p.pointerId||(c(),e.setPosition(g.startPosition),n.diagram?.getExtension(De)?.clear(),s.current=null)},"onPointerCancel"),children:e.text})]})}),nf=A.observer(({edge:n})=>n.labels.map(e=>d.jsx(tf,{edge:n,label:e},e.id))),sf=A.observer(({node:n})=>{const e=n.RenderScreen;return e?d.jsx(e,{node:n,box:n.box,scale:n.diagram?.canvas.scale??1}):null}),rf=A.observer(()=>{const n=J.use();return d.jsxs("div",{className:"screen_renderers",children:[n.nodes.map(e=>d.jsx(sf,{node:e},e.id)),n.edges.map(e=>d.jsx(nf,{edge:e},e.id)),d.jsx(Qp,{})]})}),af=A.observer(({gateway:n})=>{const t=J.use().getExtension(rt);return d.jsx(Gt,{paths:[{d:Up(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:t.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)}),of=A.observer(({node:n})=>{const t=J.use().getExtension(rt);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:t.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")})}),lf=A.observer(({node:n})=>{const e=n.RenderOverlay;return e?d.jsx(e,{node:n,box:n.box}):null}),cf=A.observer(()=>{const n=J.use();return d.jsx("div",{style:{width:`${n.canvas.size.x}px`,height:`${n.canvas.size.y}px`},children:n.nodes.map(e=>d.jsx(lf,{node:e},e.id))})}),df=A.observer(({node:n})=>n.parent?d.jsx(d.Fragment,{children:!n.RenderOverlay&&d.jsx(Gt,{paths:[{d:oc(n.box,10),stroke:n.state.stroke,strokeWidth:n.state.strokewWidth??3,fill:n.state.fill}],onMouseOver:o(()=>n.setHovered(!0),"onMouseOver"),onMouseOut:o(e=>{const t=e.relatedTarget;t instanceof Element&&t.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),cc=A.observer(({edge:n,selected:e,showDragHandles:t})=>d.jsx(Dn,{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,selected:e,onMidpointMouseDown:o((i,s)=>{n.dragStart(i,s)},"onMidpointMouseDown"),onEndpointMouseDown:o((i,s)=>{n.dragEndpoint(i,s)},"onEndpointMouseDown")})),hf=ft(A.observer(()=>{const n=J.use(),e=n.getExtension($),t=e?.selectedNodes??[],i=e?.selectedEdges??[],s=n.rules.allowEdition,r=t.length+i.length>1,a=[...n.nodes.filter(c=>!t.includes(c)),...t],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(df,{node:c},c.id)),s&&a.filter(c=>c.edgesAsGateways).map(c=>d.jsx(of,{node:c},`edge-gateway-${c.id}`)),n.edges.filter(c=>!i.includes(c)).map(c=>d.jsx(cc,{edge:c,selected:!1,showDragHandles:s&&!r},c.id)),l.map(c=>d.jsx(af,{gateway:c},`${c.parent.id}-${c.id}`)),i.map(c=>d.jsx(cc,{edge:c,selected:!0,showDragHandles:s&&!r},c.id))]})}));function uf(){return[d.jsx(hf,{},"ScalableShapes"),d.jsx(cf,{},"RenderNodeOverlays")]}o(uf,"shapes");function gf(n){if(!(n instanceof Element))return null;const e=n.closest("[data-gateway-parent]");return e?e.getAttribute("data-gateway-parent"):n.closest("[data-id]")?.getAttribute("data-id")??null}o(gf,"hoverOwnerId");const pf=A.observer(({children:n})=>{const e=J.use(),t=e.getExtension(B);e.canvas.setGridSize(t?.gridSize??50);const i=[],s=[],r=[];return S.Children.forEach([...Jp(n),...uf()],a=>{a.type.__scalable?i.push(a):a.type.__scalableBack?r.push(a):s.push(a)}),d.jsxs("div",{className:`canvas__frame ${e.showGrid?"canvas__frame--grid":""}`,onPointerLeave:o(()=>e.clearNodeHover(),"onPointerLeave"),onPointerMove:o(a=>{const l=e.getNodeById(gf(a.target)??"");l?l.setHovered(!0):e.clearNodeHover()},"onPointerMove"),children:[d.jsxs("div",{ref:e.canvas.useRef,children:[r.length&&d.jsx(lc,{className:"background",children:r}),s.length&&d.jsx("div",{className:"scalable_components",children:s}),i.length&&d.jsx(lc,{className:"foreground",children:i})]}),d.jsx(rf,{})]})});function ff({children:n,className:e,...t}){return d.jsx("div",{...t,className:["stage",e].filter(Boolean).join(" "),children:n})}o(ff,"Stage");const mf=ft(A.observer(()=>{const n=J.use(),e=n.getExtension(Be),t=n.getExtension(De),i=n.getExtension(Ct),s=[...e?.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(Gt,{className:"alignment_sugestion",paths:[{d:a}]},r.id)}),t?.proposals.map(r=>d.jsx(Gt,{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(Gt,{className:"distance_balance_sugestion",paths:[{d:a,arrow:{position:"both",size:8}}]},a)})]})})),yf=ft(A.observer(()=>{const e=J.use().getExtension(qi);return e?.enabled?d.jsxs(d.Fragment,{children:[e.grid?.edges.map(t=>{const{from:i,to:s}=t,r=`M ${i.x} ${i.y} L ${s.x} ${s.y}`,a=e.highlighted.has(t);return d.jsx(Dn,{className:`path_finding_grid_edge ${a?"highlighted":""}`,points:[i,s],endType:"none"},r)}),e.points?.length&&d.jsx(Dn,{className:"path_finding_grid_edge_chosen",points:e.points})]}):null})),Ie=8,zs=2,bf=120;function xf(n,e){const t=Math.max(Ie,Math.min(n.x,window.innerWidth-e.width-Ie)),i=Math.max(Ie,Math.min(n.y,window.innerHeight-e.height-Ie));return{x:t,y:i}}o(xf,"clampPosition");function vf({item:n,onAction:e}){const t=!!n.submenu?.length,i=S.useRef(null),s=S.useRef(null),r=S.useRef(null),[a,l]=S.useState(!1),[c,h]=S.useState(!1),[u,p]=S.useState({left:0,top:-4,openToLeft:!1}),g=S.useCallback(()=>{if(!i.current||!s.current)return;const _=i.current.getBoundingClientRect(),k=s.current.getBoundingClientRect();let C=_.width-zs,P=!1;_.right-zs+k.width>window.innerWidth-Ie&&(C=-k.width+zs,P=!0),_.left+C<Ie&&(C=Ie-_.left,P=!1);let D=-4,N=_.top+D;N+k.height>window.innerHeight-Ie&&(D-=N+k.height-(window.innerHeight-Ie),N=_.top+D),N<Ie&&(D+=Ie-N),p({left:C,top:D,openToLeft:P}),h(!0)},[]);S.useEffect(()=>{a||h(!1)},[a]),S.useEffect(()=>()=>{r.current!==null&&window.clearTimeout(r.current)},[]),S.useLayoutEffect(()=>{a&&g()},[a,g]),S.useEffect(()=>{if(!a)return;const _=o(()=>{g()},"handleResize");return window.addEventListener("resize",_),()=>{window.removeEventListener("resize",_)}},[a,g]);const m=o(()=>{r.current!==null&&(window.clearTimeout(r.current),r.current=null)},"clearCloseTimeout"),x=o(()=>{t&&(m(),l(!0))},"openSubmenu"),b=o(()=>{m(),l(!1)},"closeSubmenu"),v=o(()=>{t&&(m(),r.current=window.setTimeout(()=>{l(!1),r.current=null},bf))},"scheduleCloseSubmenu"),w=o(_=>{const k=_.relatedTarget;(!k||!_.currentTarget.contains(k))&&b()},"handleBlur");return d.jsxs("li",{ref:i,className:["diagram__context_menu_item",n.disabled&&"disabled",n.danger&&"danger",t&&"has_submenu",a&&"submenu_open"].filter(Boolean).join(" "),onMouseEnter:x,onMouseLeave:v,onFocusCapture:x,onBlurCapture:w,children:[d.jsxs("button",{type:"button",className:"diagram__context_menu_button",disabled:n.disabled,onClick:o(_=>{_.stopPropagation(),_.preventDefault(),e(n)},"onClick"),children:[d.jsx("span",{className:"diagram__context_menu_label",children:n.label}),t&&d.jsx("span",{className:"diagram__context_menu_chevron",children:u.openToLeft?"<":">"})]}),t&&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(dc,{items:n.submenu,onAction:e})})})]})}o(vf,"MenuItem");function dc({items:n,onAction:e}){return d.jsx("ul",{className:"diagram__context_menu_list",children:n.map((t,i)=>d.jsx(vf,{item:t,onAction:e},`${t.label}_${i}`))})}o(dc,"MenuItems");const wf=A.observer(({menu:n})=>{const e=S.useRef(null),[t,i]=S.useState(n.position);return S.useEffect(()=>{n.opened&&i(n.position)},[n.openVersion,n.opened,n.position]),S.useLayoutEffect(()=>{if(!n.opened||!e.current)return;const{width:s,height:r}=e.current.getBoundingClientRect(),{x:a,y:l}=xf(n.position,{width:s,height:r});(a!==t.x||l!==t.y)&&i({x:a,y:l})},[n.openVersion,n.opened,n.position,t.x,t.y]),S.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&&e.current?.contains(h)||n.close()},"closeOnOutsideMouseDown"),a=o(c=>{const h=c.target;if(h&&e.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:e,className:"diagram__context_menu",style:{left:t.x,top:t.y},onMouseDown:o(s=>{s.stopPropagation()},"onMouseDown"),onContextMenu:o(s=>{s.preventDefault(),s.stopPropagation()},"onContextMenu"),children:d.jsx(dc,{items:n.elements,onAction:o(s=>{n.execute(s)},"onAction")})})})}),Qa=class Qa{_elements=[];_opened=!1;_position={x:0,y:0};_openVersion=0;Component=o(()=>d.jsx(wf,{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(e,t={}){if(!e.length){this.close();return}const i=Mt.getInstance().coordinates;this._elements=e,this._position={x:t.x??i.x,y:t.y??i.y},this._openVersion+=1,this._opened=!0}close(){this._opened&&(this._opened=!1,this._elements=[])}execute(e){if(!e.disabled){try{const t=e.onClick();t instanceof Promise&&t.catch(()=>{})}catch{}e.submenu?.length||this.close()}}};o(Qa,"ContextMenuStore");let Fs=Qa;const $s=new Fs,Ln=o(()=>{},"noop");function Ef(){return typeof navigator<"u"&&!!navigator.clipboard?.writeText&&!!navigator.clipboard?.readText}o(Ef,"hasClipboardSupport");function hc(n){return()=>{n().catch(()=>{})}}o(hc,"runAsync");function _f(n,e,t){const i=n.getExtension($),s=e.closest(".diagram__node")?.dataset.id,r=e.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,p=n.rules.allowEdition,g=Ef(),m=g&&c.length>0,x=o(()=>{i.selectedNodes.forEach(_=>{n.delete(_)}),i.selectedEdges.forEach(_=>{n.disconnect(_)})},"deleteSelection"),b=[];a?b.push({label:`Node: ${a.state.label||a.id}`,onClick:Ln,submenu:[{label:"Center node",onClick:o(()=>{n.canvas.centerOnPoint(a.box.middle)},"onClick")},...p?[{label:"Delete node",onClick:o(()=>{n.delete(a)},"onClick"),danger:!0}]:[]]}):l&&p&&b.push({label:"Edge",onClick:Ln,submenu:[{label:"Delete edge",onClick:o(()=>{n.disconnect(l)},"onClick"),danger:!0}]}),u&&p&&b.push({label:"Delete selection",onClick:x,danger:!0});const v=[{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:hc(async()=>{await navigator.clipboard.writeText(i.copy())}),disabled:!m}];p&&v.push({label:"Paste",onClick:hc(async()=>{const _=await navigator.clipboard.readText();_.trim().length&&n.paste(_)}),disabled:!g}),b.push({label:"Selection",onClick:Ln,submenu:v});const w=new y([t.x,t.y]);return b.push({label:"View",onClick:Ln,submenu:[{label:n.showGrid?"Hide grid":"Show grid",onClick:o(()=>{n.toggleGrid()},"onClick")},{label:`Zoom (${Math.round(n.canvas.scale*100)}%)`,onClick:Ln,submenu:[{label:"Zoom in",onClick:o(()=>{n.canvas.setScale(n.canvas.scale+.1,w)},"onClick")},{label:"Zoom out",onClick:o(()=>{n.canvas.setScale(n.canvas.scale-.1,w)},"onClick")},{label:"Reset zoom",onClick:o(()=>{n.canvas.setScale(1,w)},"onClick")}]}]}),b}o(_f,"buildDiagramContextMenu");const kf=A.observer(()=>{const n=J.use();return d.jsx("div",{className:"diagram__extension_ui",children:n.extensions.map(e=>{const t=e.RenderUI;return t?d.jsx(t,{diagram:n,extension:e},e.constructor.name):null})})}),Sf=A.observer(({diagram:n,leftPanel:e,toolbar:t})=>{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(_f(n,r,{x:s.clientX,y:s.clientY}),{x:s.clientX,y:s.clientY})}},"handleContextMenu");return d.jsxs(n.Context,{children:[d.jsxs(ff,{onContextMenu:i,children:[e,d.jsxs(pf,{children:[d.jsx(Xp,{}),d.jsx(Yp,{}),d.jsx(Zp,{}),d.jsx(mf,{}),d.jsx(qp,{}),d.jsx(yf,{})]}),d.jsx(kf,{})]}),d.jsx($s.Component,{}),t]})});function Mf(n){n.currentTarget.contains(n.target)&&(n.stopPropagation(),n.nativeEvent?.stopImmediatePropagation?.())}o(Mf,"stopDiagramControlEvent");function Af(n,e="button,input,select,textarea,[role='menu'],[data-diagram-control],.toolbar,.ui-toolbar,.mr__properties_panel,.shared-modal"){const t=S.useRef(null),i=S.useRef(null),s=S.useCallback(()=>{const r=i.current;i.current=null,r&&t.current?.hasPointerCapture(r.id)&&t.current.releasePointerCapture(r.id),t.current?.classList.remove("diagram-pointer-dragging")},[]);return S.useEffect(()=>{const a=t.current?.ownerDocument?.defaultView;return a?.addEventListener("pointerup",s,!0),a?.addEventListener("pointercancel",s,!0),a?.addEventListener("blur",s,!0),()=>{s(),a?.removeEventListener("pointerup",s,!0),a?.removeEventListener("pointercancel",s,!0),a?.removeEventListener("blur",s,!0)}},[s]),{ref:t,onPointerDownCapture(r){if(r.button!==0||!r.isPrimary||(s(),r.target instanceof Element&&r.target.closest(e)))return;const a=r.target instanceof Element?r.target.closest("[data-id]"):null;i.current={id:r.pointerId,x:r.clientX,y:r.clientY,node:a&&n?n.getNodeById(a.getAttribute("data-id")||""):void 0},r.currentTarget.setPointerCapture(r.pointerId),r.currentTarget.classList.add("diagram-pointer-dragging")},onPointerMove(r){const a=i.current;if(!n||!a||a.id!==r.pointerId)return;const l=[(r.clientX-a.x)/n.canvas.scale,(r.clientY-a.y)/n.canvas.scale];a.x=r.clientX,a.y=r.clientY,a.node?a.node.setPosition(a.node.coordinates.copy().sum(l)):n.canvas.displace(new y(l)),r.preventDefault()},onPointerUp:s,onPointerCancel:s,onLostPointerCapture:s,onDragStart(r){r.preventDefault()}}}o(Af,"useDiagramPointerCapture");function Cf(n,e){const t=o(()=>n.querySelectorAll(".diagram-attribute-edge,.diagram-attribute-related").forEach(a=>a.classList.remove("diagram-attribute-edge","diagram-attribute-related")),"clear"),i=o(a=>a instanceof Element?a.closest("[data-attribute-id]"):null,"row"),s=o(a=>{const l=i(a.target);if(!l||!n.contains(l))return;t();const c=e.edges.filter(g=>g instanceof ve&&(g.sourceAttributeIds.includes(l.dataset.attributeId)||g.targetAttributeIds.includes(l.dataset.attributeId))),h=new Set(c.map(g=>g.id)),u=new Set(c.flatMap(g=>[g.from?.parent?.id,g.to?.parent?.id])),p=l.closest("[data-id]")?.getAttribute("data-id");n.querySelectorAll("[data-id]").forEach(g=>{h.has(g.dataset.id)&&g.classList.add("diagram-attribute-edge"),u.has(g.dataset.id)&&g.dataset.id!==p&&g.classList.add("diagram-attribute-related")})},"over"),r=o(a=>{i(a.target)!==i(a.relatedTarget)&&t()},"out");return n.addEventListener("pointerover",s),n.addEventListener("pointerout",r),()=>{t(),n.removeEventListener("pointerover",s),n.removeEventListener("pointerout",r)}}o(Cf,"bindAttributeRelationshipHover");const Ti=new WeakMap;function If(n,e,t={}){const i=n.canvas.frameDimensions;if(i.width<=0||i.height<=0)return!1;Ti.get(n)?.();const s=n.getExtension($);s?.clearSelection(),s?.selectNode(e);const r=t.padding??24;n.canvas.setScale(Math.min(Math.max(n.canvas.scale,t.preferredScale??.8),(i.width-r*2)/e.box.width,(i.height-r*2)/e.box.height)),n.canvas.centerOnPoint(t.point??e.box.middle),e.classList.add("diagram-reference-highlight");const a=n.canvas.element?.ownerDocument;let l=o(()=>{},"detach");const c=o(()=>{l(),e.classList.delete("diagram-reference-highlight"),a?.removeEventListener("mousedown",h,!0),n.canvas.element?.querySelectorAll(".diagram-reference-attribute").forEach(u=>u.classList.remove("diagram-reference-attribute")),Ti.delete(n)},"clear"),h=o(u=>{(u.target instanceof Element?u.target.closest("[data-id]"):null)?.getAttribute("data-id")!==e.id&&c()},"dismiss");return a?.addEventListener("mousedown",h,!0),l=n.canvas.onDetach(c),t.attributeId&&a&&requestAnimationFrame(()=>{if(Ti.get(n)!==c)return;n.canvas.element?.querySelectorAll("[data-attribute-id]").forEach(p=>{p.dataset.attributeId===t.attributeId&&p.classList.add("diagram-reference-attribute")})}),Ti.set(n,c),!0}o(If,"revealDiagramNode");const eo=class eo 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(eo,"DirectedPoint");let Hs=eo;const jf=Object.freeze(Object.defineProperty({__proto__:null,DirectedPoint:Hs},Symbol.toStringTag,{value:"Module"}));E.AgentDiagram=ss,E.BPMDiagram=xi,E.BPMNExecutionBlackBoxPoolNode=vn,E.BPMNExecutionDataStoreNode=wn,E.BPMNExecutionDiagram=ms,E.BPMNExecutionDocumentAnnotationNode=En,E.BPMNExecutionDocumentNode=_n,E.BPMNExecutionEdge=ze,E.BPMNExecutionEventNode=kn,E.BPMNExecutionGateNode=Sn,E.BPMNExecutionLanes=Mn,E.BPMNExecutionMarker=xn,E.BPMNExecutionTaskNode=An,E.BPMNExecutionTextAnnotationNode=Cn,E.BPMNExecutionUnknownNode=In,E.BPMNNodeExecutionState=re,E.BPMN_LABELS=Ae,E.Canvas=_o,E.CommunicationDiagram=ys,E.Coordinates=y,E.Creator=si,E.DCanvasEvent=xt,E.DChangeEvent=ee,E.DClickEvent=en,E.DDeleteEdgeEvent=nn,E.DDeleteNodeEvent=tt,E.DDisplaceEvent=Gn,E.DDoubleClickEvent=tn,E.DDragEdgeSegmentEvent=ln,E.DDragEvent=He,E.DDragNodeEvent=fe,E.DEdgeDragStartEvent=rn,E.DEdgeEndpointDragStartEvent=an,E.DEdgeLabelChangeEvent=it,E.DEdgeSelectionEvent=sn,E.DEvent=Qt,E.DKeyDownEvent=Ue,E.DKeyPressEvent=Rn,E.DKeyUpEvent=bt,E.DKeyboardEvent=yt,E.DMouseDownEvent=Pe,E.DMouseEvent=je,E.DMouseMoveEvent=Ne,E.DMouseUpEvent=ne,E.DNodeChangeTypeEvent=pe,E.DNodeConnectionIntentEvent=Wn,E.DNodeSelectionEvent=kt,E.DNodesConnectActionEvent=Et,E.DNodesConnectionEvent=wt,E.DResetGraphEvent=Vn,E.DScaleEvent=vt,E.DSelectionEvent=_t,E.DUIEvent=et,E.DWheelEvent=Bn,E.Diagram=J,E.DiagramEditor=Sf,E.DiagramExtension=F,E.Dimensions=M,E.DistancesBalancer=Ct,E.Dragger=ri,E.Edge=Re,E.EdgeLabel=Nt,E.EdgePoint=R,E.EdgePointPositionProposal=on,E.EdgesDragger=rt,E.EditableDiagram=ot,E.Element=qe,E.Gateway=Se,E.GridSnap=B,E.History=It,E.Hotkeys=ti,E.LabelsAligner=De,E.MRDiagram=Ds,E.MRForeignKeyEdge=ve,E.MRModelerExtension=Ht,E.MRTableNode=Ze,E.Measurer=jt,E.Node=Dt,E.NodePositionProposal=St,E.NodesAligner=Be,E.NodesConnector=at,E.NodesResizer=oi,E.PathFindingRenderer=qi,E.Selector=$,E.StraightDrag=li,E.StraightLabelsDrag=Lt,E.ToolsStates=Hn,E.bindAttributeRelationshipHover=Cf,E.configureBPMNLabels=as,E.customRendererProps=q,E.revealDiagramNode=If,E.stopDiagramControlEvent=Mf,E.useDiagramPointerCapture=Af,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})}));
7
7
  //# sourceMappingURL=index.umd.js.map