@memoarchitect/architect 0.6.2 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/assets/ChatPanel-Dp_E5vjj.js +3 -0
- package/dist/assets/{ComplianceWizard-Bi9PLmJH.js → ComplianceWizard-CgtKjuZp.js} +1 -1
- package/dist/assets/{DSMView-DbC_fUKT.js → DSMView-DTUyQHSu.js} +1 -1
- package/dist/assets/{Dashboard-6Dgma4kY.js → Dashboard-CwosozE0.js} +1 -1
- package/dist/assets/DhfDashboard-Dp6ryOII.js +1 -0
- package/dist/assets/{DhfSettingsPanel-jQ5mh_50.js → DhfSettingsPanel-Bx2t0sXQ.js} +1 -1
- package/dist/assets/{DhfWorkbench-CgFdQIts.js → DhfWorkbench-BN3gpDz4.js} +3 -3
- package/dist/assets/DiagramCanvas-O_19DfTS.js +1 -0
- package/dist/assets/DiagramEditor-CNhwdNh3.js +4 -0
- package/dist/assets/ElementDetailView-rciRq5HA.js +2 -0
- package/dist/assets/{ImportView-HCDzL9Xx.js → ImportView-BbzZ5hbB.js} +1 -1
- package/dist/assets/{LayerGrid-DSxAFwPk.js → LayerGrid-DAIv9DZ6.js} +1 -1
- package/dist/assets/{LayerTable-C5VBpm6T.js → LayerTable-BnOya4yd.js} +1 -1
- package/dist/assets/{MaxGraphCanvas-B7tAFvDf.js → MaxGraphCanvas-BaVQOtM7.js} +3 -3
- package/dist/assets/{ModelDiff-MM5NKKXK.js → ModelDiff-Mm8cCWYb.js} +1 -1
- package/dist/assets/OntologyDecompositionDiagram-COmPilyD.js +1 -0
- package/dist/assets/{OntologyViewer-C5ik2Kmi.js → OntologyViewer-esGC-MHX.js} +2 -2
- package/dist/assets/{RelationshipOverlay-DSzjs5U7.js → RelationshipOverlay-B9bqt4zl.js} +1 -1
- package/dist/assets/{RelationshipsSection-2CEoiF6o.js → RelationshipsSection-DttMvF2i.js} +1 -1
- package/dist/assets/{ReviewDashboard-DwlsAVBa.js → ReviewDashboard-CAZFVV_h.js} +1 -1
- package/dist/assets/ScenarioEditor-B68Qn6c9.js +3 -0
- package/dist/assets/{StatisticsDashboard-C67W4pb0.js → StatisticsDashboard-DBs1LLID.js} +1 -1
- package/dist/assets/{SysmlCodeEditor-CGOcUFE7.js → SysmlCodeEditor-Die2RUsz.js} +1 -1
- package/dist/assets/{SysmlGenerator-BwRhtec-.js → SysmlGenerator-C8TebOjb.js} +1 -1
- package/dist/assets/{TabularView-CTQgMG25.js → TabularView-_BN5T3rn.js} +1 -1
- package/dist/assets/{TraceabilityMatrix-Bw5ej-So.js → TraceabilityMatrix-CKZyOf1u.js} +1 -1
- package/dist/assets/{WorkflowWizard-BwGWzMkE.js → WorkflowWizard-DaqQTLpd.js} +1 -1
- package/dist/assets/elk-6l8mIQnQ.js +26 -0
- package/dist/assets/index-C8UZrEP-.js +3277 -0
- package/dist/assets/index-XtCtnAfF.css +1 -0
- package/dist/assets/layout-providers-Dr743WlP.js +1 -0
- package/dist/assets/layout-selection-CpBDhXjU.js +1 -0
- package/dist/assets/{reactflow-CX-HDacK.js → reactflow-CsCqNKB-.js} +1 -1
- package/dist/assets/{zustand-qbFpP9Up.js → zustand-CrhqMOHB.js} +1 -1
- package/dist/index.html +4 -4
- package/lib/bin/memo-architect.js +20 -2
- package/lib/bin/memo-architect.js.map +1 -1
- package/lib/commands/example.d.ts +4 -0
- package/lib/commands/example.d.ts.map +1 -1
- package/lib/commands/example.js +14 -7
- package/lib/commands/example.js.map +1 -1
- package/package.json +6 -4
- package/dist/assets/AskPanel-Dqc6aaqg.js +0 -1
- package/dist/assets/DhfDashboard-BPXIYJnw.js +0 -1
- package/dist/assets/DiagramCanvas-CIfN1ybl.js +0 -1
- package/dist/assets/DiagramEditor-Y4sSx9nO.js +0 -4
- package/dist/assets/ElementDetailView-B946aM3p.js +0 -2
- package/dist/assets/OntologyDecompositionDiagram-CAzu3z_q.js +0 -1
- package/dist/assets/ScenarioEditor-BRWvcD2f.js +0 -3
- package/dist/assets/elk-B75IRfCd.js +0 -1
- package/dist/assets/index-D0i9ua6F.js +0 -3277
- package/dist/assets/index-DPzXL4uF.css +0 -1
- package/dist/assets/layout-providers-BFnfta4Z.js +0 -26
- package/dist/assets/layout-selection-BTId1JyG.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as jsxRuntimeExports}from"./reactflow-
|
|
1
|
+
import{j as jsxRuntimeExports}from"./reactflow-CsCqNKB-.js";import{a as reactExports}from"./zustand-CrhqMOHB.js";import{D as DIAGRAM_TYPE_META,u as useModelStore,g as getDiagram,y as sendDiagramLayoutUpdate,F as FONT,x as getRegistries}from"./index-C8UZrEP-.js";import{c as computeFBSLayout,w as buildFunctionalTree,b as computeContainmentLayout,x as buildDecompositionTree,d as computeUseCaseViewLayout,q as useCaseViewOptions,e as computeContextViewLayout,f as computeInterconnectionLayout,g as computeActionFlowViewLayout,h as computeStateTransitionLayout,i as computeSequenceLayout,r as resolveGeneralMode,j as computeGeneralViewLayout,t as buildGeneralViewTree,k as computeLayout,s as selectedLayoutProviderId,n as commonDisplayLevels,y as GridView,B as BrowserView,R as RelationshipPicker}from"./layout-selection-CpBDhXjU.js";import"./layout-providers-Dr743WlP.js";import"./elk-6l8mIQnQ.js";class ImageBox{constructor(t,e,i){this.src=t,this.width=e,this.height=i}}class EventObject{constructor(t="",...e){if(this.consumed=!1,this.name=t,this.properties={},e[0]&&e[0].constructor===Object)for(const[i,s]of Object.entries(e[0]))this.properties[i]=s;else for(let i=0;i<e.length;i+=2)e[i+1]!==null&&(this.properties[e[i]]=e[i+1])}getName(){return this.name}getProperties(){return this.properties}getProperty(t){return this.properties[t]}isConsumed(){return this.consumed}consume(){this.consumed=!0}}class EventSource{constructor(t=null){this.eventListeners=[],this.eventsEnabled=!0,this.eventSource=null,this.eventSource=t}isEventsEnabled(){return this.eventsEnabled}setEventsEnabled(t){this.eventsEnabled=t}getEventSource(){return this.eventSource}setEventSource(t){this.eventSource=t}addListener(t,e){this.eventListeners.push({name:t,funct:e})}removeListener(t){let e=0;for(;e<this.eventListeners.length;)this.eventListeners[e].funct===t?this.eventListeners.splice(e,1):e+=1}fireEvent(t,e=null){if(this.isEventsEnabled()){t||(t=new EventObject("")),e||(e=this.getEventSource()),e||(e=this);for(const i of this.eventListeners)(i.name===null||i.name===t.getName())&&i.funct.apply(this,[e,t])}}destroy(){this.eventListeners.length=0}}const DEFAULT_HOTSPOT=.3,MIN_HOTSPOT_SIZE=8,MAX_HOTSPOT_SIZE=0,IDENTITY_FIELD_NAME="mxObjectId",NS_SVG="http://www.w3.org/2000/svg",NS_XLINK="http://www.w3.org/1999/xlink",SHADOWCOLOR="gray",SHADOW_OFFSET_X=2,SHADOW_OFFSET_Y=3,SHADOW_OPACITY=1,TOOLTIP_VERTICAL_OFFSET=16,DEFAULT_VALID_COLOR="#00FF00",DEFAULT_INVALID_COLOR="#FF0000",OUTLINE_HIGHLIGHT_COLOR="#00FF00",OUTLINE_HIGHLIGHT_STROKEWIDTH=5,HIGHLIGHT_STROKEWIDTH=3,HIGHLIGHT_SIZE=2,HIGHLIGHT_OPACITY=100,INVALID_CONNECT_TARGET_COLOR="#FF0000",DROP_TARGET_COLOR="#0000FF",VALID_COLOR="#00FF00",INVALID_COLOR="#FF0000",EDGE_SELECTION_COLOR="#00FF00",VERTEX_SELECTION_COLOR="#00FF00",VERTEX_SELECTION_STROKEWIDTH=1,EDGE_SELECTION_STROKEWIDTH=1,VERTEX_SELECTION_DASHED=!0,EDGE_SELECTION_DASHED=!0,GUIDE_COLOR="#FF0000",GUIDE_STROKEWIDTH=1,HANDLE_SIZE=6,LABEL_HANDLE_SIZE=4,HANDLE_FILLCOLOR="#00FF00",HANDLE_STROKECOLOR="black",LABEL_HANDLE_FILLCOLOR="yellow",CONNECT_HANDLE_FILLCOLOR="#0000FF",LOCKED_HANDLE_FILLCOLOR="#FF0000",DEFAULT_FONTFAMILY="Arial,Helvetica,sans-serif",DEFAULT_FONTSIZE=11,DEFAULT_TEXT_DIRECTION="",LINE_HEIGHT=1.2,WORD_WRAP="normal",DEFAULT_FONTSTYLE=0,DEFAULT_STARTSIZE=40,DEFAULT_MARKERSIZE=6,DEFAULT_IMAGESIZE=24,ENTITY_SEGMENT=30,RECTANGLE_ROUNDING_FACTOR=.15,LINE_ARCSIZE=20,ARROW_SPACING=0,ARROW_WIDTH=30,ARROW_SIZE=30,PAGE_FORMAT_A4_PORTRAIT=[0,0,827,1169],NONE="none",FONT_STYLE_MASK={BOLD:1,ITALIC:2,UNDERLINE:4,STRIKETHROUGH:8},DIRECTION_MASK={NONE:0,WEST:1,NORTH:2,SOUTH:4,EAST:8,ALL:15},NODE_TYPE={ELEMENT:1},isWindowObjectAvailable=()=>typeof window<"u",isUserAgentAvailable=()=>!!navigator.userAgent,isUserAgentIncludes=r=>navigator.userAgent.includes(r),isAppVersionAvailable=()=>!!navigator.appVersion,isAppVersionIncludes=r=>navigator.appVersion.includes(r);class Client{}Client.basePath=".";Client.setBasePath=r=>{typeof r<"u"&&r.length>0?(r.substring(r.length-1)==="/"&&(r=r.substring(0,r.length-1)),Client.basePath=r):Client.basePath="."};Client.imageBasePath=".";Client.setImageBasePath=r=>{typeof r<"u"&&r.length>0?(r.substring(r.length-1)==="/"&&(r=r.substring(0,r.length-1)),Client.imageBasePath=r):Client.imageBasePath=`${Client.basePath}/images`};Client.IS_EDGE=isWindowObjectAvailable()&&isUserAgentAvailable()&&!!navigator.userAgent.match(/Edge\//);Client.IS_NS=isWindowObjectAvailable()&&isUserAgentAvailable()&&isUserAgentIncludes("Mozilla/")&&!isUserAgentIncludes("MSIE")&&!isUserAgentIncludes("Edge/");Client.IS_SF=isWindowObjectAvailable()&&/Apple Computer, Inc/.test(navigator.vendor);Client.IS_ANDROID=isWindowObjectAvailable()&&isAppVersionAvailable()&&isAppVersionIncludes("Android");Client.IS_IOS=isWindowObjectAvailable()&&/iP(hone|od|ad)/.test(navigator.platform);Client.IS_GC=isWindowObjectAvailable()&&/Google Inc/.test(navigator.vendor);Client.IS_CHROMEAPP=isWindowObjectAvailable()&&window.chrome!=null&&chrome.app!=null&&chrome.app.runtime!=null;Client.IS_FF=isUserAgentAvailable()&&navigator.userAgent.toLowerCase().includes("firefox");Client.IS_MT=isWindowObjectAvailable()&&isUserAgentAvailable()&&(isUserAgentIncludes("Firefox/")&&!isUserAgentIncludes("Firefox/1.")&&!isUserAgentIncludes("Firefox/2.")||isUserAgentIncludes("Iceweasel/")&&!isUserAgentIncludes("Iceweasel/1.")&&!isUserAgentIncludes("Iceweasel/2.")||isUserAgentIncludes("SeaMonkey/")&&!isUserAgentIncludes("SeaMonkey/1.")||isUserAgentIncludes("Iceape/")&&!isUserAgentIncludes("Iceape/1."));var Tt;Client.IS_SVG=isWindowObjectAvailable()&&((Tt=navigator.appName)==null?void 0:Tt.toUpperCase())!=="MICROSOFT INTERNET EXPLORER";Client.NO_FO=isWindowObjectAvailable()&&(!document.createElementNS||document.createElementNS(NS_SVG,"foreignObject").toString()!=="[object SVGForeignObjectElement]"||isUserAgentIncludes("Opera/"));Client.IS_WIN=isWindowObjectAvailable()&&isAppVersionAvailable()&&isAppVersionIncludes("Win");Client.IS_MAC=isWindowObjectAvailable()&&isAppVersionAvailable()&&isAppVersionIncludes("Mac");Client.IS_CHROMEOS=isWindowObjectAvailable()&&/\bCrOS\b/.test(navigator.appVersion);Client.IS_TOUCH=isWindowObjectAvailable()&&"ontouchstart"in document.documentElement;Client.IS_POINTER=isWindowObjectAvailable()&&!!window.PointerEvent&&isAppVersionAvailable()&&!isAppVersionIncludes("Mac");Client.IS_LOCAL=isWindowObjectAvailable()&&!document.location.href.includes("http://")&&!document.location.href.includes("https://");const getMainEvent=r=>{let t=r;return(t.type==="touchstart"||t.type==="touchmove")&&t.touches&&t.touches[0]?t=t.touches[0]:t.type==="touchend"&&t.changedTouches&&t.changedTouches[0]&&(t=t.changedTouches[0]),t},getClientX=r=>getMainEvent(r).clientX,getClientY=r=>getMainEvent(r).clientY,getSource=r=>r.target,isConsumed=r=>{const t=r;return t.isConsumed!==void 0&&t.isConsumed},isTouchEvent=r=>{const t=r;return t.pointerType?t.pointerType==="touch"||t.pointerType===t.MSPOINTER_TYPE_TOUCH:t.mozInputSource!==void 0?t.mozInputSource===5:t.type.indexOf("touch")===0},isPenEvent=r=>{const t=r;return t.pointerType?t.pointerType=="pen"||t.pointerType===t.MSPOINTER_TYPE_PEN:t.mozInputSource!==void 0?t.mozInputSource===2:t.type.indexOf("pen")===0},isMultiTouchEvent=r=>{const t=r;return t.type&&t.type.indexOf("touch")==0&&t.touches!==void 0&&t.touches.length>1},isMouseEvent=r=>{const t=r;return t.pointerType?t.pointerType=="mouse"||t.pointerType===t.MSPOINTER_TYPE_MOUSE:t.mozInputSource!==void 0?t.mozInputSource===1:t.type.indexOf("mouse")===0},isLeftMouseButton=r=>"buttons"in r&&(r.type==="mousedown"||r.type==="mousemove")?r.buttons===1:r.which!==void 0?r.which===1:r.button===1,isRightMouseButton=r=>r.button===2,isPopupTrigger=r=>isRightMouseButton(r)||Client.IS_MAC&&isControlDown(r)&&!isShiftDown(r)&&!isMetaDown(r)&&!isAltDown(r),isShiftDown=r=>r.shiftKey,isAltDown=r=>r.altKey,isControlDown=r=>r.ctrlKey,isMetaDown=r=>r.metaKey;class NoOpLogger{debug(t){}enter(t){}error(t,...e){}info(t){}leave(t,e){}show(){}trace(t){}warn(t){}}const shallowCopy=(r,t)=>{for(const e in r)if(Object.prototype.hasOwnProperty.call(r,e)){const i=r[e];Array.isArray(i)?t[e]=[...i]:t[e]=i}};class NoOpI18n{isEnabled(){return!1}get(){return null}addResource(){}}const GlobalConfig={i18n:new NoOpI18n,logger:new NoOpLogger},StyleDefaultsConfig={fontFamily:DEFAULT_FONTFAMILY,fontSize:DEFAULT_FONTSIZE,imageSize:DEFAULT_IMAGESIZE,lineArcSize:LINE_ARCSIZE,markerSize:DEFAULT_MARKERSIZE,roundingFactor:RECTANGLE_ROUNDING_FACTOR,shadowColor:SHADOWCOLOR,shadowOffsetX:SHADOW_OFFSET_X,shadowOffsetY:SHADOW_OFFSET_Y,shadowOpacity:SHADOW_OPACITY,startSize:DEFAULT_STARTSIZE},doEval=expression=>eval(expression),isElement=r=>(r==null?void 0:r.nodeType)===NODE_TYPE.ELEMENT,isNullish=r=>r==null,log=()=>GlobalConfig.logger,mixInto=r=>t=>{const e=Reflect.ownKeys(t);try{for(const i of e)Object.defineProperty(r.prototype,i,{value:t[i],writable:!0})}catch(i){log().error("Error while mixing",i)}},matchBinaryMask=(r,t)=>(r&t)===t,blocks=new Set(["BLOCKQUOTE","DIV","H1","H2","H3","H4","H5","H6","OL","P","PRE","TABLE","UL"]),extractTextWithWhitespace=r=>{const t=[];function e(i){if(!(i.length==1&&(i[0].nodeName=="BR"||i[0].innerHTML==`
|
|
2
2
|
`)))for(let s=0;s<i.length;s+=1){const n=i[s];n.nodeName=="BR"||n.innerHTML==`
|
|
3
3
|
`||(i.length==1||s==0)&&n.nodeName=="DIV"&&n.innerHTML.toLowerCase()=="<br>"?t.push(`
|
|
4
4
|
`):(n.nodeType===3||n.nodeType===4?n.nodeValue&&n.nodeValue.length>0&&t.push(n.nodeValue):n.nodeType!==8&&n.childNodes.length>0&&e(Array.from(n.childNodes)),s<i.length-1&&blocks.has(i[s+1].nodeName)&&t.push(`
|
|
@@ -9,5 +9,5 @@ import{j as jsxRuntimeExports}from"./reactflow-CX-HDacK.js";import{a as reactExp
|
|
|
9
9
|
`),r&&r.isEdge()?s+=this.getEdgeValidationError(r,r.getTerminal(!0),r.getTerminal(!1))||"":s+=this.getCellValidationError(r)||"";const n=this.validateCell(r,t);return isNullish(n)||(s+=n),r.getParent()==null&&this.getView().validate(),s.length>0||!e?s:null},getCellValidationError(r){const t=r.getDirectedEdgeCount(!0),e=r.getDirectedEdgeCount(!1),i=r.getValue();let s="";for(let n=0;n<this.multiplicities.length;n+=1){const l=this.multiplicities[n];l.source&&isNode(i,l.type,l.attr,l.value)&&(t>l.max||t<l.min)?s+=`${l.countError}
|
|
10
10
|
`:!l.source&&isNode(i,l.type,l.attr,l.value)&&(e>l.max||e<l.min)&&(s+=`${l.countError}
|
|
11
11
|
`)}return s.length>0?s:null},validateCell(r,t){return null}},VertexMixin={vertexLabelsMovable:!1,allowNegativeCoordinates:!0,isAllowNegativeCoordinates(){return this.allowNegativeCoordinates},setAllowNegativeCoordinates(r){this.allowNegativeCoordinates=r},insertVertex(...r){var u,g,f,p;let t,e,i,s,n,l,o,a,h,d;if(r.length===1&&typeof r[0]=="object"){const y=r[0];t=y.parent,e=y.id,i=y.value,s="x"in y?y.x:(u=y.position)==null?void 0:u[0],n="y"in y?y.y:(g=y.position)==null?void 0:g[1],l="width"in y?y.width:(f=y.size)==null?void 0:f[0],o="height"in y?y.height:(p=y.size)==null?void 0:p[1],a=y.style,h=y.relative,d=y.geometryClass}else[t,e,i,s,n,l,o,a,h,d]=r;const c=this.createVertex(t,e,i,s,n,l,o,a,h,d);return this.addCell(c,t)},createVertex(r,t,e,i,s,n,l,o,a=!1,h=Geometry){const d=new h(i,s,n,l);d.relative=a;const c=new Cell(e,d,o);return c.setId(t),c.setVertex(!0),c.setConnectable(!0),c},getChildVertices(r){return this.getChildCells(r,!0,!1)},isVertexLabelsMovable(){return this.vertexLabelsMovable},setVertexLabelsMovable(r){this.vertexLabelsMovable=r}},ZoomMixin={zoomFactor:1.2,keepSelectionVisibleOnZoom:!1,centerZoom:!0,zoomIn(){this.zoom(this.zoomFactor)},zoomOut(){this.zoom(1/this.zoomFactor)},zoomActual(){this.getView().scale===1?this.getView().setTranslate(0,0):(this.getView().translate.x=0,this.getView().translate.y=0,this.getView().setScale(1))},zoomTo(r,t=!1){this.zoom(r/this.getView().scale,t)},zoom(r,t){t=t??this.centerZoom;const e=Math.round(this.getView().scale*r*100)/100,i=this.getView().getState(this.getSelectionCell()),s=this.getContainer();if(r=e/this.getView().scale,this.keepSelectionVisibleOnZoom&&i!=null){const n=new Rectangle(i.x*r,i.y*r,i.width*r,i.height*r);this.getView().scale=e,this.scrollRectToVisible(n)||(this.getView().revalidate(),this.getView().setScale(e))}else{const n=hasScrollbars(this.getContainer());if(t&&!n){let l=s.offsetWidth,o=s.offsetHeight;if(r>1){const a=(r-1)/(e*2);l*=-a,o*=-a}else{const a=(1/r-1)/(this.getView().scale*2);l*=a,o*=a}this.getView().scaleAndTranslate(e,this.getView().translate.x+l,this.getView().translate.y+o)}else{const l=this.getView().translate.x,o=this.getView().translate.y,a=s.scrollLeft,h=s.scrollTop;if(this.getView().setScale(e),n){let d=0,c=0;t&&(d=s.offsetWidth*(r-1)/2,c=s.offsetHeight*(r-1)/2),s.scrollLeft=(this.getView().translate.x-l)*this.getView().scale+Math.round(a*r+d),s.scrollTop=(this.getView().translate.y-o)*this.getView().scale+Math.round(h*r+c)}}}},zoomToRect(r){const t=this.getContainer(),e=t.clientWidth/r.width,i=t.clientHeight/r.height,s=e/i;r.x=Math.max(0,r.x),r.y=Math.max(0,r.y);let n=Math.min(t.scrollWidth,r.x+r.width),l=Math.min(t.scrollHeight,r.y+r.height);if(r.width=n-r.x,r.height=l-r.y,s<1){const h=r.height/s,d=(h-r.height)/2;r.height=h;const c=Math.min(r.y,d);r.y-=c,l=Math.min(t.scrollHeight,r.y+r.height),r.height=l-r.y}else{const h=r.width*s,d=(h-r.width)/2;r.width=h;const c=Math.min(r.x,d);r.x-=c,n=Math.min(t.scrollWidth,r.x+r.width),r.width=n-r.x}const o=t.clientWidth/r.width,a=this.getView().scale*o;hasScrollbars(this.getContainer())?(this.getView().setScale(a),t.scrollLeft=Math.round(r.x*o),t.scrollTop=Math.round(r.y*o)):this.getView().scaleAndTranslate(a,this.getView().translate.x-r.x/this.getView().scale,this.getView().translate.y-r.y/this.getView().scale)}},applyGraphMixins=r=>{const t=mixInto(r);for(const e of[CellsMixin,ConnectionsMixin,DragDropMixin,EdgeMixin,EditingMixin,EventsMixin,FoldingMixin,GroupingMixin,LabelMixin,OrderMixin,PageBreaksMixin,OverlaysMixin,PanningMixin,PortsMixin,SelectionMixin,SnapMixin,SwimlaneMixin,TerminalMixin,ValidationMixin,VertexMixin,ZoomMixin])t(e)};class AbstractGraph extends EventSource{createEdgeHandlerInstance(t){return new EdgeHandler(t)}createEdgeSegmentHandler(t){return new EdgeSegmentHandler(t)}createElbowEdgeHandler(t){return new ElbowEdgeHandler(t)}createVertexHandler(t){return new VertexHandler(t)}registerDefaults(){}constructor(t){var e;super(),this.destroyed=!1,this.graphModelChangeListener=null,this.paintBackground=null,this.isConstrainedMoving=!1,this.alternateEdgeStyle={},this.cells=[],this.mouseListeners=[],this.multiplicities=[],this.options={foldingEnabled:!0,collapsedImage:new ImageBox(`${Client.imageBasePath}/collapsed.gif`,9,9),expandedImage:new ImageBox(`${Client.imageBasePath}/expanded.gif`,9,9),collapseToPreferredSize:!0},this.plugins=new Map,this.renderHint=null,this.dialect="svg",this.defaultOverlap=.5,this.defaultParent=null,this.backgroundImage=null,this.pageVisible=!1,this.pageBreaksVisible=!1,this.pageBreakColor="gray",this.pageBreakDashed=!0,this.minPageBreakDist=20,this.preferPageSize=!1,this.pageFormat=new Rectangle(...PAGE_FORMAT_A4_PORTRAIT),this.pageScale=1.5,this.enabled=!0,this.exportEnabled=!0,this.importEnabled=!0,this.ignoreScrollbars=!1,this.translateToScrollPosition=!1,this.maximumGraphBounds=null,this.minimumGraphSize=null,this.minimumContainerSize=null,this.maximumContainerSize=null,this.resizeContainer=!1,this.border=0,this.keepEdgesInForeground=!1,this.keepEdgesInBackground=!1,this.recursiveResize=!1,this.resetViewOnRootChange=!0,this.allowLoops=!1,this.defaultLoopStyle=Loop,this.multigraph=!0,this.warningImage=new ImageBox(`${Client.imageBasePath}/warning${Client.IS_MAC?".png":".gif"}`,16,16),this.alreadyConnectedResource=isI18nEnabled()?"alreadyConnected":"",this.containsValidationErrorsResource=isI18nEnabled()?"containsValidationErrors":"",this.getContainer=()=>this.container,this.getPlugin=i=>this.plugins.get(i),this.getCellRenderer=()=>this.cellRenderer,this.getDialect=()=>this.dialect,this.isPageVisible=()=>this.pageVisible,this.isPageBreaksVisible=()=>this.pageBreaksVisible,this.getPageBreakColor=()=>this.pageBreakColor,this.isPageBreakDashed=()=>this.pageBreakDashed,this.getMinPageBreakDist=()=>this.minPageBreakDist,this.isPreferPageSize=()=>this.preferPageSize,this.getPageFormat=()=>this.pageFormat,this.getPageScale=()=>this.pageScale,this.isExportEnabled=()=>this.exportEnabled,this.isImportEnabled=()=>this.importEnabled,this.isIgnoreScrollbars=()=>this.ignoreScrollbars,this.isTranslateToScrollPosition=()=>this.translateToScrollPosition,this.getMinimumGraphSize=()=>this.minimumGraphSize,this.setMinimumGraphSize=i=>this.minimumGraphSize=i,this.getMinimumContainerSize=()=>this.minimumContainerSize,this.setMinimumContainerSize=i=>this.minimumContainerSize=i,this.getAlreadyConnectedResource=()=>this.alreadyConnectedResource,this.getContainsValidationErrorsResource=()=>this.containsValidationErrorsResource,this.registerDefaults(),this.container=(t==null?void 0:t.container)??document.createElement("div"),this.initializeCollaborators(t),this.graphModelChangeListener=(i,s)=>{this.graphModelChanged(s.getProperty("edit").changes)},this.getDataModel().addListener(InternalEvent.CHANGE,this.graphModelChangeListener),this.view.init(),this.sizeDidChange(),(e=t==null?void 0:t.plugins)==null||e.forEach(i=>this.plugins.set(i.pluginId,new i(this))),this.view.revalidate()}getWarningImage(){return this.warningImage}setTooltips(t){const e=this.getPlugin("TooltipHandler");e==null||e.setEnabled(t)}batchUpdate(t){this.getDataModel().batchUpdate(t)}getDataModel(){return this.model}getView(){return this.view}getStylesheet(){return this.stylesheet}setStylesheet(t){this.stylesheet=t}graphModelChanged(t){for(const e of t)this.processChange(e);this.updateSelection(),this.view.validate(),this.sizeDidChange()}processChange(t){if(t instanceof RootChange)this.clearSelection(),this.setDefaultParent(null),t.previous&&this.removeStateForCell(t.previous),this.resetViewOnRootChange&&(this.view.scale=1,this.view.translate.x=0,this.view.translate.y=0),this.fireEvent(new EventObject(InternalEvent.ROOT));else if(t instanceof ChildChange){const e=t.child.getParent();this.view.invalidate(t.child,!0,!0),(!e||!this.getDataModel().contains(e)||e.isCollapsed())&&(this.view.invalidate(t.child,!0,!0),this.removeStateForCell(t.child),this.view.currentRoot==t.child&&this.home()),e!=t.previous&&(e!=null&&this.view.invalidate(e,!1,!1),t.previous!=null&&this.view.invalidate(t.previous,!1,!1))}else if(t instanceof TerminalChange||t instanceof GeometryChange)(t instanceof TerminalChange||t.previous==null&&t.geometry!=null||t.previous!=null&&!t.previous.equals(t.geometry))&&this.view.invalidate(t.cell);else if(t instanceof ValueChange)this.view.invalidate(t.cell,!1,!1);else if(t instanceof StyleChange){this.view.invalidate(t.cell,!0,!0);const e=this.view.getState(t.cell);e!=null&&(e.invalidStyle=!0)}else t.cell!=null&&t.cell instanceof Cell&&this.removeStateForCell(t.cell)}scrollPointToVisible(t,e,i=!1,s=20){const n=this.getPlugin("PanningHandler");if(!this.isTimerAutoScroll()&&(this.ignoreScrollbars||hasScrollbars(this.container))){const l=this.container;if(t>=l.scrollLeft&&e>=l.scrollTop&&t<=l.scrollLeft+l.clientWidth&&e<=l.scrollTop+l.clientHeight){let o=l.scrollLeft+l.clientWidth-t;if(o<s){const h=l.scrollLeft;if(l.scrollLeft+=s-o,i&&h===l.scrollLeft){const d=this.view.getDrawPane().ownerSVGElement,c=l.scrollWidth+s-o;d.style.width=`${c}px`,l.scrollLeft+=s-o}}else o=t-l.scrollLeft,o<s&&(l.scrollLeft-=s-o);let a=l.scrollTop+l.clientHeight-e;if(a<s){const h=l.scrollTop;if(l.scrollTop+=s-a,h==l.scrollTop&&i){const d=this.view.getDrawPane().ownerSVGElement,c=l.scrollHeight+s-a;d.style.height=`${c}px`,l.scrollTop+=s-a}}else a=e-l.scrollTop,a<s&&(l.scrollTop-=s-a)}}else this.isAllowAutoPanning()&&n&&!n.isActive()&&n.getPanningManager().panTo(t+this.getPanDx(),e+this.getPanDy())}getBorderSizes(){const t=getCurrentStyle(this.container);return new Rectangle(parseCssNumber(t.paddingLeft)+(t.borderLeftStyle!="none"?parseCssNumber(t.borderLeftWidth):0),parseCssNumber(t.paddingTop)+(t.borderTopStyle!="none"?parseCssNumber(t.borderTopWidth):0),parseCssNumber(t.paddingRight)+(t.borderRightStyle!="none"?parseCssNumber(t.borderRightWidth):0),parseCssNumber(t.paddingBottom)+(t.borderBottomStyle!="none"?parseCssNumber(t.borderBottomWidth):0))}getPreferredPageSize(t,e,i){const s=this.view.translate,n=this.pageFormat,l=this.pageScale,o=new Rectangle(0,0,Math.ceil(n.width*l),Math.ceil(n.height*l)),a=this.pageBreaksVisible?Math.ceil(e/o.width):1,h=this.pageBreaksVisible?Math.ceil(i/o.height):1;return new Rectangle(0,0,a*o.width+2+s.x,h*o.height+2+s.y)}doResizeContainer(t,e){this.maximumContainerSize!=null&&(t=Math.min(this.maximumContainerSize.width,t),e=Math.min(this.maximumContainerSize.height,e));const i=this.container;i.style.width=`${Math.ceil(t)}px`,i.style.height=`${Math.ceil(e)}px`}createHandler(t){let e=null;if(t.cell.isEdge()){const i=t.getVisibleTerminalState(!0),s=t.getVisibleTerminalState(!1),n=t.cell.getGeometry(),l=this.getView().getEdgeStyle(t,n&&n.points||void 0,i,s);e=this.createEdgeHandler(t,l)}else e=this.createVertexHandler(t);return e}createEdgeHandler(t,e){switch(EdgeStyleRegistry.getHandlerKind(e)){case"elbow":return this.createElbowEdgeHandler(t);case"segment":return this.createEdgeSegmentHandler(t)}return this.createEdgeHandlerInstance(t)}getCurrentRoot(){return this.view.currentRoot}getTranslateForRoot(t){return null}getChildOffsetForCell(t){return null}home(){const t=this.getCurrentRoot();t!=null&&(this.view.setCurrentRoot(null),this.view.getState(t)!=null&&this.setSelectionCell(t))}isValidRoot(t){return!!t}getGraphBounds(){return this.view.getGraphBounds()}getMaximumGraphBounds(){return this.maximumGraphBounds}refresh(t=null){t?this.view.clear(t,!1):this.view.clear(void 0,!0),this.view.validate(),this.sizeDidChange(),this.fireEvent(new EventObject(InternalEvent.REFRESH))}center(t=!0,e=!0,i=.5,s=.5){const n=this.container,l=hasScrollbars(this.container),o=2*this.getBorder(),a=n.clientWidth-o,h=n.clientHeight-o,d=this.getGraphBounds(),c=this.view.translate,u=this.view.scale;let g=t?a-d.width:0,f=e?h-d.height:0;if(!l)this.view.setTranslate(t?Math.floor(c.x-d.x/u+g*i/u):c.x,e?Math.floor(c.y-d.y/u+f*s/u):c.y);else{d.x-=c.x,d.y-=c.y;const p=n.scrollWidth,y=n.scrollHeight;p>a&&(g=0),y>h&&(f=0),this.view.setTranslate(Math.floor(g/2-d.x),Math.floor(f/2-d.y)),n.scrollLeft=(p-a)/2,n.scrollTop=(y-h)/2}}isOrthogonal(t){const e=t.style.orthogonal;if(!isNullish(e))return e;const i=this.view.getEdgeStyle(t);return EdgeStyleRegistry.isOrthogonal(i)}getBackgroundImage(){return this.backgroundImage}setBackgroundImage(t){this.backgroundImage=t}convertValueToString(t){const e=t.getValue();if(e!=null){if(isNode(e))return e.nodeName;if(typeof e.toString=="function")return e.toString()}return""}getLinkForCell(t){return null}getBorder(){return this.border}setBorder(t){this.border=t}isResizeContainer(){return this.resizeContainer}setResizeContainer(t){this.resizeContainer=t}isEnabled(){return this.enabled}setEnabled(t){this.enabled=t}isMultigraph(){return this.multigraph}setMultigraph(t){this.multigraph=t}isAllowLoops(){return this.allowLoops}setAllowLoops(t){this.allowLoops=t}isRecursiveResize(t=null){return this.recursiveResize}setRecursiveResize(t){this.recursiveResize=t}getOverlap(t){return this.isAllowOverlapParent(t)?this.defaultOverlap:0}isAllowOverlapParent(t){return!1}getDefaultParent(){let t=this.getCurrentRoot();return t||(t=this.defaultParent,t||(t=this.getDataModel().getRoot().getChildAt(0))),t}setDefaultParent(t){this.defaultParent=t}destroy(){this.destroyed||(this.destroyed=!0,this.plugins.forEach(t=>t.onDestroy()),this.view.destroy(),this.model&&this.graphModelChangeListener&&(this.getDataModel().removeListener(this.graphModelChangeListener),this.graphModelChangeListener=null),this.container=null,super.destroy())}}applyGraphMixins(AbstractGraph);class UndoableEdit{constructor(t,e=!0){this.changes=[],this.significant=!0,this.undone=!1,this.redone=!1,this.source=t,this.changes=[],this.significant=e}isEmpty(){return this.changes.length===0}isSignificant(){return this.significant}add(t){this.changes.push(t)}notify(){}die(){}undo(){if(!this.undone){this.source.fireEvent(new EventObject(InternalEvent.START_EDIT));const t=this.changes.length;for(let e=t-1;e>=0;e--){const i=this.changes[e];i.execute?i.execute():i.undo&&i.undo(),this.source.fireEvent(new EventObject(InternalEvent.EXECUTED,{change:i}))}this.undone=!0,this.redone=!1,this.source.fireEvent(new EventObject(InternalEvent.END_EDIT))}this.notify()}redo(){if(!this.redone){this.source.fireEvent(new EventObject(InternalEvent.START_EDIT));const t=this.changes.length;for(let e=0;e<t;e+=1){const i=this.changes[e];i.execute!=null?i.execute():i.redo!=null&&i.redo(),this.source.fireEvent(new EventObject(InternalEvent.EXECUTED,{change:i}))}this.undone=!1,this.redone=!0,this.source.fireEvent(new EventObject(InternalEvent.END_EDIT))}this.notify()}}class CollapseChange{constructor(t,e,i){this.model=t,this.cell=e,this.collapsed=i,this.previous=i}execute(){this.collapsed=this.previous,this.previous=this.model.collapsedStateForCellChanged(this.cell,this.previous)}}class VisibleChange{constructor(t,e,i){this.model=t,this.cell=e,this.visible=i,this.previous=i}execute(){this.visible=this.previous,this.previous=this.model.visibleStateForCellChanged(this.cell,this.previous)}}class GraphDataModel extends EventSource{constructor(t=null){super(),this.root=null,this.cells={},this.maintainEdgeParent=!0,this.ignoreRelativeEdgeParent=!0,this.createIds=!0,this.prefix="",this.postfix="",this.nextId=0,this.currentEdit=null,this.updateLevel=0,this.endingUpdate=!1,this.currentEdit=this.createUndoableEdit(),t!=null?this.setRoot(t):this.clear()}clear(){this.setRoot(this.createRoot())}isCreateIds(){return this.createIds}setCreateIds(t){this.createIds=t}createRoot(){const t=new Cell;return t.insert(new Cell),t}getCell(t){return this.cells?this.cells[t]:null}filterCells(t,e){return t.filter(e)}getRoot(t=null){return t?t.getRoot():this.root}setRoot(t){return this.execute(new RootChange(this,t)),t}rootChanged(t){const e=this.root;return this.root=t,this.nextId=0,this.cells=null,this.cellAdded(t),e}isRoot(t=null){return t!=null&&this.root===t}isLayer(t){return t?this.isRoot(t.getParent()):!1}contains(t){return this.root.isAncestor(t)}add(t,e,i=null){if(e!==t&&t!=null&&e!=null){i==null&&(i=t.getChildCount());const s=t!==e.getParent();this.execute(new ChildChange(this,t,e,i)),this.maintainEdgeParent&&s&&this.updateEdgeParents(e)}return e}cellAdded(t){if(t!=null){if(t.getId()==null&&this.createIds&&t.setId(this.createId(t)),t.getId()!=null){let e=this.getCell(t.getId());if(e!==t){for(;e!=null;)t.setId(this.createId(t)),e=this.getCell(t.getId());this.cells==null&&(this.cells={}),this.cells[t.getId()]=t}}isNumeric(String(t.getId()))&&(this.nextId=Math.max(this.nextId,Number.parseInt(t.getId())));for(const e of t.getChildren())this.cellAdded(e)}}createId(t){const e=this.nextId;return this.nextId++,this.prefix+e+this.postfix}updateEdgeParents(t,e=this.getRoot(t)){const i=t.getChildCount();for(let l=0;l<i;l+=1){const o=t.getChildAt(l);this.updateEdgeParents(o,e)}const s=t.getEdgeCount(),n=[];for(let l=0;l<s;l+=1)n.push(t.getEdgeAt(l));for(let l=0;l<n.length;l+=1){const o=n[l];e.isAncestor(o)&&this.updateEdgeParent(o,e)}}updateEdgeParent(t,e){let i=t.getTerminal(!0),s=t.getTerminal(!1),n=null;for(;i!=null&&!i.isEdge()&&i.geometry!=null&&i.geometry.relative;)i=i.getParent();for(;s!=null&&this.ignoreRelativeEdgeParent&&!s.isEdge()&&s.geometry!=null&&s.geometry.relative;)s=s.getParent();if(e.isAncestor(i)&&e.isAncestor(s)&&(i===s?n=i?i.getParent():null:i&&(n=i.getNearestCommonAncestor(s)),n!=null&&(n.getParent()!==this.root||n.isAncestor(t))&&t&&t.getParent()!==n)){let l=t.getGeometry();if(l!=null){const o=t.getParent().getOrigin(),a=n.getOrigin(),h=a.x-o.x,d=a.y-o.y;l=l.clone(),l.translate(-h,-d),this.setGeometry(t,l)}this.add(n,t,n.getChildCount())}}remove(t){return t===this.root?this.setRoot(null):t.getParent()!=null&&this.execute(new ChildChange(this,null,t)),t}cellRemoved(t){if(t!=null&&this.cells!=null){const e=t.getChildCount();for(let i=e-1;i>=0;i--)this.cellRemoved(t.getChildAt(i));this.cells!=null&&t.getId()!=null&&delete this.cells[t.getId()]}}parentForCellChanged(t,e,i){const s=t.getParent();if(e!=null)(e!==s||s.getIndex(t)!==i)&&e.insert(t,i);else if(s!=null){const o=s.getIndex(t);s.remove(o)}const n=e?this.contains(e):null,l=this.contains(s);return n&&!l?this.cellAdded(t):l&&!n&&this.cellRemoved(t),s}setTerminal(t,e,i){const s=e!==t.getTerminal(i);return this.execute(new TerminalChange(this,t,e,i)),this.maintainEdgeParent&&s&&this.updateEdgeParent(t,this.getRoot()),e}setTerminals(t,e,i){this.beginUpdate();try{this.setTerminal(t,e,!0),this.setTerminal(t,i,!1)}finally{this.endUpdate()}}terminalForCellChanged(t,e,i=!1){const s=t.getTerminal(i);return e!=null?e.insertEdge(t,i):s!=null&&s.removeEdge(t,i),s}getEdgesBetween(t,e,i=!1){const s=t.getEdgeCount(),n=e.getEdgeCount();let l=t,o=s;n<s&&(o=n,l=e);const a=[];for(let h=0;h<o;h+=1){const d=l.getEdgeAt(h),c=d.getTerminal(!0),u=d.getTerminal(!1);(c===t&&u===e||!i&&(u===t&&c===e))&&a.push(d)}return a}setValue(t,e){return this.execute(new ValueChange(this,t,e)),e}valueForCellChanged(t,e){return t.valueChanged(e)}setGeometry(t,e){return e!==t.getGeometry()&&this.execute(new GeometryChange(this,t,e)),e}geometryForCellChanged(t,e){const i=t.getGeometry();return t.setGeometry(e),i}setStyle(t,e){e!==t.getStyle()&&this.execute(new StyleChange(this,t,e))}styleForCellChanged(t,e){const i=t.getStyle();return t.setStyle(e),i}setCollapsed(t,e){return e!==t.isCollapsed()&&this.execute(new CollapseChange(this,t,e)),e}collapsedStateForCellChanged(t,e){const i=t.isCollapsed();return t.setCollapsed(e),i}setVisible(t,e){return e!==t.isVisible()&&this.execute(new VisibleChange(this,t,e)),e}visibleStateForCellChanged(t,e){const i=t.isVisible();return t.setVisible(e),i}execute(t){t.execute(),this.beginUpdate(),this.currentEdit.add(t),this.fireEvent(new EventObject(InternalEvent.EXECUTE,{change:t})),this.fireEvent(new EventObject(InternalEvent.EXECUTED,{change:t})),this.endUpdate()}batchUpdate(t){this.beginUpdate();try{t()}finally{this.endUpdate()}}beginUpdate(){this.updateLevel+=1,this.fireEvent(new EventObject(InternalEvent.BEGIN_UPDATE)),this.updateLevel===1&&this.fireEvent(new EventObject(InternalEvent.START_EDIT))}endUpdate(){if(this.updateLevel-=1,this.updateLevel===0&&this.fireEvent(new EventObject(InternalEvent.END_EDIT)),!this.endingUpdate){this.endingUpdate=this.updateLevel===0,this.fireEvent(new EventObject(InternalEvent.END_UPDATE,{edit:this.currentEdit}));try{if(this.endingUpdate&&!this.currentEdit.isEmpty()){this.fireEvent(new EventObject(InternalEvent.BEFORE_UNDO,{edit:this.currentEdit}));const t=this.currentEdit;this.currentEdit=this.createUndoableEdit(),t.notify(),this.fireEvent(new EventObject(InternalEvent.UNDO,{edit:t}))}}finally{this.endingUpdate=!1}}}createUndoableEdit(t=!0){const e=new UndoableEdit(this,t);return e.notify=()=>{e.source.fireEvent(new EventObject(InternalEvent.CHANGE,{edit:e,changes:e.changes})),e.source.fireEvent(new EventObject(InternalEvent.NOTIFY,{edit:e,changes:e.changes}))},e}mergeChildren(t,e,i=!0){this.beginUpdate();try{const s={};this.mergeChildrenImpl(t,e,i,s);for(const n in s){const l=s[n];let o=l.getTerminal(!0);o!=null&&(o=s[CellPath.create(o)],this.setTerminal(l,o,!0)),o=l.getTerminal(!1),o!=null&&(o=s[CellPath.create(o)],this.setTerminal(l,o,!1))}}finally{this.endUpdate()}}mergeChildrenImpl(t,e,i,s={}){this.beginUpdate();try{const n=t.getChildCount();for(let l=0;l<n;l+=1){const o=t.getChildAt(l);if(typeof o.getId=="function"){const a=o.getId();let h=a!=null&&(!o.isEdge()||!i)?this.getCell(a):null;if(h==null){const d=o.clone();d.setId(a),d.setTerminal(o.getTerminal(!0),!0),d.setTerminal(o.getTerminal(!1),!1),h=e.insert(d),this.cellAdded(h)}s[CellPath.create(o)]=h,this.mergeChildrenImpl(o,h,i,s)}}}finally{this.endUpdate()}}}class EdgeMarkerRegistryImpl extends BaseRegistry{createMarker(t,e,i,s,n,l,o,a,h,d){const c=this.get(i);return c?c(t,e,i,s,n,l,o,a,h,d):null}}const EdgeMarkerRegistry=new EdgeMarkerRegistryImpl;class ConnectorShape extends PolylineShape{constructor(t,e,i){super(t,e,i)}updateBoundingBox(){var t;this.useSvgBoundingBox=((t=this.style)==null?void 0:t.curved)??!1,super.updateBoundingBox()}paintEdgeShape(t,e){var n,l,o,a;const i=this.createMarker(t,e,!0),s=this.createMarker(t,e,!1);if(super.paintEdgeShape(t,e),t.setShadow(!1),t.setDashed(!1),i){const h=((n=this.style)==null?void 0:n.startStrokeColor)??this.stroke;t.setStrokeColor(h),t.setFillColor(((l=this.style)==null?void 0:l.startFillColor)??h),i()}if(s){const h=((o=this.style)==null?void 0:o.endStrokeColor)??this.stroke;t.setStrokeColor(h),t.setFillColor(((a=this.style)==null?void 0:a.endFillColor)??h),s()}}createMarker(t,e,i){if(!this.style)return null;let s=null;const n=e.length,l=(i?this.style.startArrow:this.style.endArrow)||NONE;let o=i?e[1]:e[n-2];const a=i?e[0]:e[n-1];if(l!==NONE&&o!==null&&a!==null){let h=1;for(;h<n-1&&Math.round(o.x-a.x)===0&&Math.round(o.y-a.y)===0;)o=i?e[1+h]:e[n-2-h],h++;const d=a.x-o.x,c=a.y-o.y,u=Math.max(1,Math.sqrt(d*d+c*c)),g=d/u,f=c/u,p=(i?this.style.startSize:this.style.endSize)??StyleDefaultsConfig.markerSize,y=(i?this.style.startFill:this.style.endFill)??!0;s=EdgeMarkerRegistry.createMarker(t,this,l,a,g,f,p,i,this.strokeWidth,y)}return s}augmentBoundingBox(t){if(super.augmentBoundingBox(t),!this.style)return;let e=0;(this.style.startArrow??NONE)!==NONE&&(e=(this.style.startSize??StyleDefaultsConfig.markerSize)+1),(this.style.endArrow??NONE)!==NONE&&(e=Math.max(e,this.style.endSize??StyleDefaultsConfig.markerSize)+1),t.grow(e*this.scale)}}class TextShape extends Shape{constructor(t,e,i="center",s="middle",n="black",l=StyleDefaultsConfig.fontFamily,o=StyleDefaultsConfig.fontSize,a=DEFAULT_FONTSTYLE,h=2,d=0,c=0,u=0,g=0,f=!0,p=NONE,y=NONE,v=!1,S=!1,w="visible",C=0,m=DEFAULT_TEXT_DIRECTION){super(),this.margin=null,this.unrotatedBoundingBox=null,this.flipH=!1,this.flipV=!1,this.baseSpacingTop=0,this.baseSpacingBottom=0,this.baseSpacingLeft=0,this.baseSpacingRight=0,this.replaceLinefeeds=!0,this.verticalTextRotation=-90,this.ignoreClippedStringSize=!0,this.ignoreStringSize=!1,this.lastValue=null,this.cacheEnabled=!0,this.value=t,this.bounds=e,this.color=n??"black",this.align=i??"center",this.valign=s??"middle",this.family=l??StyleDefaultsConfig.fontFamily,this.size=o??StyleDefaultsConfig.fontSize,this.fontStyle=a??DEFAULT_FONTSTYLE,this.spacing=h??2,this.spacingTop=this.spacing+(d??0),this.spacingRight=this.spacing+(c??0),this.spacingBottom=this.spacing+(u??0),this.spacingLeft=this.spacing+(g??0),this.horizontal=f??!0,this.background=p,this.border=y,this.wrap=v??!1,this.clipped=S??!1,this.overflow=w??"visible",this.labelPadding=C??0,this.textDirection=m,this.rotation=0,this.updateMargin()}getSvgScreenOffset(){return 0}checkBounds(){return!Number.isNaN(this.scale)&&Number.isFinite(this.scale)&&this.scale>0&&this.bounds&&!Number.isNaN(this.bounds.x)&&!Number.isNaN(this.bounds.y)&&!Number.isNaN(this.bounds.width)&&!Number.isNaN(this.bounds.height)}paint(t,e=!1){const i=this.scale,s=this.bounds.x/i,n=this.bounds.y/i,l=this.bounds.width/i,o=this.bounds.height/i;if(this.updateTransform(t,s,n,l,o),this.configureCanvas(t,s,n,l,o),e)t.updateText(s,n,l,o,this.align,this.valign,this.wrap,this.overflow,this.clipped,this.getTextRotation(),this.node);else{const a=isNode(this.value)||this.dialect==="strictHtml",h=a?"html":"";let d=this.value;!a&&h==="html"&&(d=htmlEntities(d,!1)),h==="html"&&!isNode(this.value)&&(d=replaceTrailingNewlines(d,"<div><br></div>")),d=!isNode(this.value)&&this.replaceLinefeeds&&h==="html"?d.replace(/\n/g,"<br/>"):d;let c=this.textDirection;c==="auto"&&!a&&(c=this.getAutoDirection()),c!=="ltr"&&c!=="rtl"&&(c=""),t.text(s,n,l,o,d,this.align,this.valign,this.wrap,h,this.overflow,this.clipped,this.getTextRotation(),c)}}redraw(){if(this.visible&&this.checkBounds()&&this.cacheEnabled&&this.lastValue===this.value&&(isNode(this.value)||this.dialect==="strictHtml"))if(this.node.nodeName==="DIV")this.redrawHtmlShape(),this.updateBoundingBox();else{const t=this.createCanvas();t&&(t.pointerEvents=this.pointerEvents,this.paint(t,!0),this.destroyCanvas(t),this.updateBoundingBox())}else super.redraw(),isNode(this.value)||this.dialect==="strictHtml"?this.lastValue=this.value:this.lastValue=null}resetStyles(){super.resetStyles(),this.color="black",this.align="center",this.valign="middle",this.family=StyleDefaultsConfig.fontFamily,this.size=StyleDefaultsConfig.fontSize,this.fontStyle=DEFAULT_FONTSTYLE,this.spacing=2,this.spacingTop=2,this.spacingRight=2,this.spacingBottom=2,this.spacingLeft=2,this.horizontal=!0,this.background=NONE,this.border=NONE,this.textDirection=DEFAULT_TEXT_DIRECTION,this.margin=null}apply(t){const e=this.spacing;super.apply(t),this.style&&(this.fontStyle=this.style.fontStyle??this.fontStyle,this.family=this.style.fontFamily??this.family,this.size=this.style.fontSize??this.size,this.color=this.style.fontColor??this.color,this.align=this.style.align??this.align,this.valign=this.style.verticalAlign??this.valign,this.spacing=this.style.spacing??this.spacing,this.spacingTop=(this.style.spacingTop??this.spacingTop-e)+this.spacing,this.spacingRight=(this.style.spacingRight??this.spacingRight-e)+this.spacing,this.spacingBottom=(this.style.spacingBottom??this.spacingBottom-e)+this.spacing,this.spacingLeft=(this.style.spacingLeft??this.spacingLeft-e)+this.spacing,this.horizontal=this.style.horizontal??this.horizontal,this.background=this.style.labelBackgroundColor??this.background,this.border=this.style.labelBorderColor??this.border,this.textDirection=this.style.textDirection??DEFAULT_TEXT_DIRECTION,this.opacity=this.style.textOpacity??100,this.updateMargin()),this.flipV=!1,this.flipH=!1}getAutoDirection(){const t=/[A-Za-z\u05d0-\u065f\u066a-\u06ef\u06fa-\u07ff\ufb1d-\ufdff\ufe70-\ufefc]/.exec(String(this.value));return t&&t.length>0&&t[0]>"z"?"rtl":"ltr"}getContentNode(){let t=this.node;return t&&(t.ownerSVGElement?t=t.firstChild.firstChild.firstChild.firstChild.firstChild:t=this.node.firstChild.firstChild),t}updateBoundingBox(){var n,l,o;let{node:t}=this;this.boundingBox=this.bounds.clone();const e=this.getTextRotation(),i=((n=this.style)==null?void 0:n.labelPosition)??"center",s=((l=this.style)==null?void 0:l.verticalLabelPosition)??"middle";if(!this.ignoreStringSize&&t&&this.overflow!=="fill"&&(!this.clipped||!this.ignoreClippedStringSize||i!=="center"||s!=="middle")){let a=null,h=null;if(t.firstChild&&t.firstChild.firstChild&&t.firstChild.firstChild.nodeName==="foreignObject")t=t.firstChild.firstChild.firstChild.firstChild,h=t.offsetHeight*this.scale,this.overflow==="width"?a=this.boundingBox.width:a=t.offsetWidth*this.scale;else try{const d=t.getBBox();typeof this.value=="string"&&((o=trim(this.value))==null?void 0:o.length)===0?this.boundingBox=null:d.width===0&&d.height===0?this.boundingBox=null:this.boundingBox=new Rectangle(d.x,d.y,d.width,d.height);return}catch{}a&&h&&(this.boundingBox=new Rectangle(this.bounds.x,this.bounds.y,a,h))}if(this.boundingBox){const a=this.margin;if(e!==0){const h=getBoundingBox(new Rectangle(a.x*this.boundingBox.width,a.y*this.boundingBox.height,this.boundingBox.width,this.boundingBox.height),e,new Point(0,0));this.unrotatedBoundingBox=Rectangle.fromRectangle(this.boundingBox),this.unrotatedBoundingBox.x+=a.x*this.unrotatedBoundingBox.width,this.unrotatedBoundingBox.y+=a.y*this.unrotatedBoundingBox.height,this.boundingBox.x+=h.x,this.boundingBox.y+=h.y,this.boundingBox.width=h.width,this.boundingBox.height=h.height}else this.boundingBox.x+=a.x*this.boundingBox.width,this.boundingBox.y+=a.y*this.boundingBox.height,this.unrotatedBoundingBox=null}}getShapeRotation(){return 0}getTextRotation(){return this.state&&this.state.shape?this.state.shape.getTextRotation():0}isPaintBoundsInverted(){return!this.horizontal&&!!this.state&&this.state.cell.isVertex()}configureCanvas(t,e,i,s,n){super.configureCanvas(t,e,i,s,n),t.setFontColor(this.color),t.setFontBackgroundColor(this.background),t.setFontBorderColor(this.border),t.setFontFamily(this.family),t.setFontSize(this.size),t.setFontStyle(this.fontStyle)}getHtmlValue(){let t=this.value;return this.dialect!=="strictHtml"&&(t=htmlEntities(t,!1)),t=replaceTrailingNewlines(t,"<div><br></div>"),t=this.replaceLinefeeds?t.replace(/\n/g,"<br/>"):t,t}getTextCss(){const t=LINE_HEIGHT;let e=`display: inline-block; font-size: ${this.size}px; font-family: ${this.family}; color: ${this.color}; line-height: ${t}; pointer-events: ${this.pointerEvents?"all":"none"}; `;matchBinaryMask(this.fontStyle,FONT_STYLE_MASK.BOLD)&&(e+="font-weight: bold; "),matchBinaryMask(this.fontStyle,FONT_STYLE_MASK.ITALIC)&&(e+="font-style: italic; ");const i=[];return matchBinaryMask(this.fontStyle,FONT_STYLE_MASK.UNDERLINE)&&i.push("underline"),matchBinaryMask(this.fontStyle,FONT_STYLE_MASK.STRIKETHROUGH)&&i.push("line-through"),i.length>0&&(e+=`text-decoration: ${i.join(" ")}; `),e}redrawHtmlShape(){const t=Math.max(0,Math.round(this.bounds.width/this.scale)),e=Math.max(0,Math.round(this.bounds.height/this.scale)),i=`position: absolute; left: ${Math.round(this.bounds.x)}px; top: ${Math.round(this.bounds.y)}px; pointer-events: none; `,s=this.getTextCss(),n=this.margin,l=this.node;SvgCanvas2D.createCss(t+2,e,this.align,this.valign,this.wrap,this.overflow,this.clipped,this.background!==NONE?htmlEntities(this.background,!0):null,this.border!==NONE?htmlEntities(this.border,!0):null,i,s,this.scale,(o,a,h,d,c,u)=>{const g=this.getTextRotation();let f=(this.scale!==1?`scale(${this.scale}) `:"")+(g!==0?`rotate(${g}deg) `:"")+(n.x!==0||n.y!==0?`translate(${n.x*100}%,${n.y*100}%)`:"");f!==""&&(f=`transform-origin: 0 0; transform: ${f}; `),u===""?(h+=d,d=`display:inline-block; min-width: 100%; ${f}`):(d+=f,Client.IS_SF&&(d+="-webkit-clip-path: content-box;")),this.opacity<100&&(c+=`opacity: ${this.opacity/100}; `),l.setAttribute("style",h);const p=isNode(this.value)?this.value.outerHTML:this.getHtmlValue();l.firstChild||(l.innerHTML=`<div><div>${p}</div></div>`),l.firstChild.firstChild.setAttribute("style",c),l.firstChild.setAttribute("style",d)})}updateInnerHtml(t){if(isNode(this.value))t.innerHTML=this.value.outerHTML;else{let e=this.value;this.dialect!=="strictHtml"&&(e=htmlEntities(e,!1)),e=replaceTrailingNewlines(e,"<div> </div>"),e=this.replaceLinefeeds?e.replace(/\n/g,"<br/>"):e,e=`<div style="display:inline-block;_display:inline;">${e}</div>`,t.innerHTML=e}}updateValue(){const t=this.node;if(isNode(this.value))t.innerHTML="",t.appendChild(this.value);else{let e=this.value;this.dialect!=="strictHtml"&&(e=htmlEntities(e,!1)),e=replaceTrailingNewlines(e,"<div><br></div>"),e=this.replaceLinefeeds?e.replace(/\n/g,"<br/>"):e;const i=this.background!==NONE?this.background:null,s=this.border!==NONE?this.border:null;if(this.overflow==="fill"||this.overflow==="width")i&&(t.style.backgroundColor=i),s&&(t.style.border=`1px solid ${s}`);else{let l="";i&&(l+=`background-color:${htmlEntities(i,!0)};`),s&&(l+=`border:1px solid ${htmlEntities(s,!0)};`),e=`<div style="zoom:1;${l}display:inline-block;_display:inline;text-decoration:inherit;padding-bottom:1px;padding-right:1px;line-height:${LINE_HEIGHT}">${e}</div>`}t.innerHTML=e;const n=t.getElementsByTagName("div");if(n.length>0){let l=this.textDirection;l==="auto"&&this.dialect!=="strictHtml"&&(l=this.getAutoDirection()),l==="ltr"||l==="rtl"?n[n.length-1].setAttribute("dir",l):n[n.length-1].removeAttribute("dir")}}}updateFont(t){const{style:e}=t;e.lineHeight=LINE_HEIGHT,e.fontSize=`${this.size}px`,e.fontFamily=this.family,e.verticalAlign="top",e.color=this.color,matchBinaryMask(this.fontStyle,FONT_STYLE_MASK.BOLD)?e.fontWeight="bold":e.fontWeight="",matchBinaryMask(this.fontStyle,FONT_STYLE_MASK.ITALIC)?e.fontStyle="italic":e.fontStyle="";const i=[];matchBinaryMask(this.fontStyle,FONT_STYLE_MASK.UNDERLINE)&&i.push("underline"),matchBinaryMask(this.fontStyle,FONT_STYLE_MASK.STRIKETHROUGH)&&i.push("line-through"),i.length>0&&(e.textDecoration=i.join(" ")),this.align==="center"?e.textAlign="center":this.align==="right"?e.textAlign="right":e.textAlign="left"}updateSize(t,e=!1){const i=Math.max(0,Math.round(this.bounds.width/this.scale)),s=Math.max(0,Math.round(this.bounds.height/this.scale)),{style:n}=t;if(this.clipped?(n.overflow="hidden",n.maxHeight=`${s}px`,n.maxWidth=`${i}px`):this.overflow==="fill"?(n.width=`${i+1}px`,n.height=`${s+1}px`,n.overflow="hidden"):this.overflow==="width"&&(n.width=`${i+1}px`,n.maxHeight=`${s+1}px`,n.overflow="hidden"),this.wrap&&i>0){if(n.wordWrap=WORD_WRAP,n.whiteSpace="normal",n.width=`${i}px`,e&&this.overflow!=="fill"&&this.overflow!=="width"){let l=t;l.firstChild!=null&&l.firstChild.nodeName==="DIV"&&(l=l.firstChild,t.style.wordWrap==="break-word"&&(l.style.width="100%"));let o=l.offsetWidth;if(o===0){const a=t.parentNode;t.style.visibility="hidden",document.body.appendChild(t),o=l.offsetWidth,t.style.visibility="",a.appendChild(t)}o+=3,this.clipped&&(o=Math.min(o,i)),n.width=`${o}px`}}else n.whiteSpace="nowrap"}updateMargin(){this.margin=getAlignmentAsPoint(this.align,this.valign)}getSpacing(){let t=0,e=0;return this.align==="center"?t=(this.spacingLeft-this.spacingRight)/2:this.align==="right"?t=-this.spacingRight-this.baseSpacingRight:t=this.spacingLeft+this.baseSpacingLeft,this.valign==="middle"?e=(this.spacingTop-this.spacingBottom)/2:this.valign==="bottom"?e=-this.spacingBottom-this.baseSpacingBottom:e=this.spacingTop+this.baseSpacingTop,new Point(t,e)}}const ShapeRegistry=new BaseRegistry,StencilShapeRegistry=new BaseRegistry,placeholderStyleValues=["inherit","swimlane","indicated"],placeholderStyleProperties=["fillColor","strokeColor","gradientColor","fontColor"];class CellRenderer{constructor(){this.defaultEdgeShape=ConnectorShape,this.defaultVertexShape=RectangleShape,this.defaultTextShape=TextShape,this.legacyControlPosition=!0,this.legacySpacing=!0,this.antiAlias=!0,this.minSvgStrokeWidth=1,this.forceControlClickHandler=!1}initializeShape(t){t.shape&&(t.shape.dialect=t.view.graph.dialect,this.configureShape(t),t.shape.init(t.view.getDrawPane()))}createShape(t){const e=StencilShapeRegistry.get(t.style.shape);if(e)return new Shape(e);const i=this.getShapeConstructor(t);return new i}createIndicatorShape(t){t.shape&&(t.shape.indicatorShape=this.getShape(t.getIndicatorShape()))}getShape(t){return ShapeRegistry.get(t)}getShapeConstructor(t){let e=this.getShape(t.style.shape);return e||(e=t.cell.isEdge()?this.defaultEdgeShape:this.defaultVertexShape),e}configureShape(t){const e=t.shape;e&&(e.apply(t),e.imageSrc=t.getImageSrc()||null,e.indicatorColor=t.getIndicatorColor()||NONE,e.indicatorStrokeColor=t.style.indicatorStrokeColor||NONE,e.indicatorGradientColor=t.getIndicatorGradientColor()||NONE,t.style.indicatorDirection&&(e.indicatorDirection=t.style.indicatorDirection),e.indicatorImageSrc=t.getIndicatorImageSrc()||null,this.postConfigureShape(t))}postConfigureShape(t){t.shape&&(this.resolveColor(t,"indicatorGradientColor","gradientColor"),this.resolveColor(t,"indicatorColor","fillColor"),this.resolveColor(t,"gradient","gradientColor"),this.resolveColor(t,"stroke","strokeColor"),this.resolveColor(t,"fill","fillColor"))}checkPlaceholderStyles(t){for(const e of placeholderStyleProperties)if(placeholderStyleValues.includes(t.style[e]))return!0;return!1}resolveColor(t,e,i){const s=i==="fontColor"?t.text:t.shape;if(s){const n=t.view.graph,l=s[e];let o=null;if(l==="inherit"?o=t.cell.getParent():l==="swimlane"?(s[e]=i==="strokeColor"||i==="fontColor"?"#000000":"#ffffff",t.cell.getTerminal(!1)?o=t.cell.getTerminal(!1):o=t.cell,o=n.getSwimlane(o),i=n.swimlaneIndicatorColorAttribute):l==="indicated"&&t.shape?s[e]=t.shape.indicatorColor:i!=="fillColor"&&l==="fillColor"&&t.shape?s[e]=t.style.fillColor:i!=="strokeColor"&&l==="strokeColor"&&t.shape&&(s[e]=t.style.strokeColor),o){const a=n.getView().getState(o);if(s[e]=null,a){const h=i==="fontColor"?a.text:a.shape;h&&e!=="indicatorColor"?s[e]=h[e]:s[e]=a.style[i]}}}}getLabelValue(t){return t.view.graph.getLabel(t.cell)}createLabel(t,e){const i=t.view.graph;if((t.style.fontSize||0)>0||t.style.fontSize==null){const s=i.isHtmlLabel(t.cell)||isNode(e);t.text=new this.defaultTextShape(e,new Rectangle,t.style.align??"center",t.getVerticalAlign(),t.style.fontColor,t.style.fontFamily,t.style.fontSize,t.style.fontStyle,t.style.spacing,t.style.spacingTop,t.style.spacingRight,t.style.spacingBottom,t.style.spacingLeft,t.style.horizontal,t.style.labelBackgroundColor,t.style.labelBorderColor,i.isWrapping(t.cell)&&i.isHtmlLabel(t.cell),i.isLabelClipped(t.cell),t.style.overflow,t.style.labelPadding,t.style.textDirection??DEFAULT_TEXT_DIRECTION),t.text.opacity=t.style.textOpacity??100,t.text.dialect=s?"strictHtml":i.dialect,t.text.style=t.style,t.text.state=t,this.initializeLabel(t,t.text);let n=!1;const l=o=>{let a=t;if(Client.IS_TOUCH||n){const h=getClientX(o),d=getClientY(o),c=convertPoint(i.container,h,d);a=i.view.getState(i.getCellAt(c.x,c.y))}return a};InternalEvent.addGestureListeners(t.text.node,o=>{if(this.isLabelEvent(t,o)){i.fireMouseEvent(InternalEvent.MOUSE_DOWN,new InternalMouseEvent(o,t));const a=getSource(o);n=i.dialect!=="svg"&&a.nodeName==="IMG"}},o=>{this.isLabelEvent(t,o)&&i.fireMouseEvent(InternalEvent.MOUSE_MOVE,new InternalMouseEvent(o,l(o)))},o=>{this.isLabelEvent(t,o)&&(i.fireMouseEvent(InternalEvent.MOUSE_UP,new InternalMouseEvent(o,l(o))),n=!1)}),i.isNativeDblClickEnabled()&&InternalEvent.addListener(t.text.node,"dblclick",o=>{this.isLabelEvent(t,o)&&(i.dblClick(o,t.cell),InternalEvent.consume(o))})}}initializeLabel(t,e){if(Client.IS_SVG&&Client.NO_FO&&e.dialect!=="svg"){const i=t.view.graph;e.init(i.container)}else e.init(t.view.getDrawPane())}createCellOverlays(t){const e=t.view.graph,i=e.getCellOverlays(t.cell),s=new Map;for(const n of i){const l=t.overlays.get(n);if(t.overlays.delete(n),l){s.set(n,l);continue}const o=this.createOverlayShape(t,n);o.dialect=e.dialect,o.overlay=n,this.initializeOverlay(t,o),this.installCellOverlayListeners(t,n,o),this.configureOverlayShape(t,n,o),s.set(n,o)}t.overlays.forEach(n=>{n.destroy()}),t.overlays=s}createOverlayShape(t,e){const i=new ImageShape(new Rectangle,e.image.src);return i.preserveImageAspect=!1,i}initializeOverlay(t,e){e.init(t.view.getOverlayPane())}installCellOverlayListeners(t,e,i){const s=t.view.graph;InternalEvent.addListener(i.node,"click",n=>{s.isEditing()&&s.stopEditing(!s.isInvokesStopCellEditing()),e.fireEvent(new EventObject(InternalEvent.CLICK,{event:n,cell:t.cell}))}),InternalEvent.addGestureListeners(i.node,n=>{InternalEvent.consume(n)},n=>{s.fireMouseEvent(InternalEvent.MOUSE_MOVE,new InternalMouseEvent(n,t))}),Client.IS_TOUCH&&InternalEvent.addListener(i.node,"touchend",n=>{e.fireEvent(new EventObject(InternalEvent.CLICK,{event:n,cell:t.cell}))})}configureOverlayShape(t,e,i){e.cursor&&(i.node.style.cursor=e.cursor)}createControl(t){const e=t.view.graph,i=e.getFoldingImage(t);if(e.isFoldingEnabled()&&i){if(!t.control){const s=new Rectangle(0,0,i.width,i.height);t.control=new ImageShape(s,i.src),t.control.preserveImageAspect=!1,t.control.dialect=e.dialect,this.initControl(t,t.control,!0,this.createControlClickHandler(t))}}else t.control&&(t.control.destroy(),t.control=null)}createControlClickHandler(t){const e=t.view.graph;return i=>{if(this.forceControlClickHandler||e.isEnabled()){const s=!t.cell.isCollapsed();e.foldCells(s,!1,[t.cell],!1,i),InternalEvent.consume(i)}}}initControl(t,e,i,s){const n=t.view.graph;n.isHtmlLabel(t.cell)&&Client.NO_FO&&n.dialect==="svg"?(e.dialect="preferHtml",e.init(n.container),e.node.style.zIndex=String(1)):e.init(t.view.getOverlayPane());const o=e.node;if(s&&!Client.IS_IOS&&(n.isEnabled()&&(o.style.cursor="pointer"),InternalEvent.addListener(o,"click",s)),i){let a=null;InternalEvent.addGestureListeners(o,h=>{a=new Point(getClientX(h),getClientY(h)),n.fireMouseEvent(InternalEvent.MOUSE_DOWN,new InternalMouseEvent(h,t)),InternalEvent.consume(h)},h=>{n.fireMouseEvent(InternalEvent.MOUSE_MOVE,new InternalMouseEvent(h,t))},h=>{n.fireMouseEvent(InternalEvent.MOUSE_UP,new InternalMouseEvent(h,t)),InternalEvent.consume(h)}),s&&Client.IS_IOS&&o.addEventListener("touchend",h=>{if(a){const d=n.getEventTolerance();Math.abs(a.x-getClientX(h))<d&&Math.abs(a.y-getClientY(h))<d&&(s.call(s,h),InternalEvent.consume(h))}},!0)}return o}isShapeEvent(t,e){return!0}isLabelEvent(t,e){return!0}installListeners(t){const e=t.view.graph,i=s=>{let n=t;const l=getSource(s);if(l&&e.dialect!=="svg"&&l.nodeName==="IMG"||Client.IS_TOUCH){const o=getClientX(s),a=getClientY(s),h=convertPoint(e.container,o,a),d=e.getCellAt(h.x,h.y);n=d?e.view.getState(d):null}return n};t.shape&&(InternalEvent.addGestureListeners(t.shape.node,s=>{this.isShapeEvent(t,s)&&e.fireMouseEvent(InternalEvent.MOUSE_DOWN,new InternalMouseEvent(s,t))},s=>{this.isShapeEvent(t,s)&&e.fireMouseEvent(InternalEvent.MOUSE_MOVE,new InternalMouseEvent(s,i(s)))},s=>{this.isShapeEvent(t,s)&&e.fireMouseEvent(InternalEvent.MOUSE_UP,new InternalMouseEvent(s,i(s)))}),e.isNativeDblClickEnabled()&&InternalEvent.addListener(t.shape.node,"dblclick",s=>{this.isShapeEvent(t,s)&&(e.dblClick(s,t.cell),InternalEvent.consume(s))}))}redrawLabel(t,e){const i=t.view.graph,s=this.getLabelValue(t),n=i.isWrapping(t.cell),l=i.isLabelClipped(t.cell),a=i.isHtmlLabel(t.cell)||s&&isNode(s)?"strictHtml":i.dialect,h=t.style.overflow??"visible";if(t.text&&(t.text.wrap!==n||t.text.clipped!==l||t.text.overflow!==h||t.text.dialect!==a)&&(t.text.destroy(),t.text=null),t.text==null&&s!=null&&(isNode(s)||s.length>0)?this.createLabel(t,s):t.text!=null&&(s==null||s.length==0)&&(t.text.destroy(),t.text=null),t.text!=null){e&&(t.text.lastValue!=null&&this.isTextShapeInvalid(t,t.text)&&(t.text.lastValue=null),t.text.resetStyles(),t.text.apply(t),t.text.valign=t.getVerticalAlign());const d=this.getLabelBounds(t),c=this.getTextScale(t);if(this.resolveColor(t,"color","fontColor"),e||t.text.value!==s||t.text.wrap!==n||t.text.overflow!==h||t.text.clipped!==l||t.text.scale!==c||t.text.dialect!==a||t.text.bounds==null||!t.text.bounds.equals(d)){t.text.dialect=a,t.text.value=s,t.text.bounds=d,t.text.scale=c,t.text.wrap=n,t.text.clipped=l,t.text.overflow=h;const u=t.text.node.style.visibility;this.redrawLabelShape(t.text),t.text.node.style.visibility=u}}}isTextShapeInvalid(t,e){function i(s,n,l){let o=!1;return n==="spacingTop"||n==="spacingRight"||n==="spacingBottom"||n==="spacingLeft"?o=Number.parseFloat(String(e[s]))-Number.parseFloat(String(e.spacing))!==(t.style[n]||l):o=e[s]!==(t.style[n]||l),o}return i("fontStyle","fontStyle",DEFAULT_FONTSTYLE)||i("family","fontFamily",StyleDefaultsConfig.fontFamily)||i("size","fontSize",StyleDefaultsConfig.fontSize)||i("color","fontColor","black")||i("align","align","")||i("valign","verticalAlign","")||i("spacing","spacing",2)||i("spacingTop","spacingTop",0)||i("spacingRight","spacingRight",0)||i("spacingBottom","spacingBottom",0)||i("spacingLeft","spacingLeft",0)||i("horizontal","horizontal",!0)||i("background","labelBackgroundColor",null)||i("border","labelBorderColor",null)||i("opacity","textOpacity",100)||i("textDirection","textDirection",DEFAULT_TEXT_DIRECTION)}redrawLabelShape(t){t.redraw()}getTextScale(t){return t.view.scale}getLabelBounds(t){const{scale:e}=t.view,i=t.cell.isEdge();let s=new Rectangle(t.absoluteOffset.x,t.absoluteOffset.y);if(i){const l=t.text.getSpacing();s.x+=l.x*e,s.y+=l.y*e;const o=t.cell.getGeometry();o!=null&&(s.width=Math.max(0,o.width*e),s.height=Math.max(0,o.height*e))}else{if(t.text.isPaintBoundsInverted()){const l=s.x;s.x=s.y,s.y=l}s.x+=t.x,s.y+=t.y,s.width=Math.max(1,t.width),s.height=Math.max(1,t.height)}if(t.text.isPaintBoundsInverted()){const l=(t.width-t.height)/2;s.x+=l,s.y-=l;const o=s.width;s.width=s.height,s.height=o}if(t.shape!=null){const l=t.style.labelPosition??"center",o=t.style.verticalLabelPosition??"middle";l==="center"&&o==="middle"&&(s=t.shape.getLabelBounds(s))}const n=t.style.labelWidth??null;return n!=null&&(s.width=n*e),i||this.rotateLabelBounds(t,s),s}rotateLabelBounds(t,e){const i=t.text;if(e.y-=i.margin.y*e.height,e.x-=i.margin.x*e.width,!this.legacySpacing||t.style.overflow!=="fill"&&t.style.overflow!=="width"){const n=t.view.scale,l=i.getSpacing();e.x+=l.x*n,e.y+=l.y*n;const o=t.style.labelPosition??"center",a=t.style.verticalLabelPosition??"middle",h=t.style.labelWidth??null;e.width=Math.max(0,e.width-(o==="center"&&h==null?i.spacingLeft*n+i.spacingRight*n:0)),e.height=Math.max(0,e.height-(a==="middle"?i.spacingTop*n+i.spacingBottom*n:0))}const s=i.getTextRotation();if(s!==0&&t!=null&&t.cell.isVertex()){const n=t.getCenterX(),l=t.getCenterY();if(e.x!==n||e.y!==l){const o=s*(Math.PI/180),a=getRotatedPoint(new Point(e.x,e.y),Math.cos(o),Math.sin(o),new Point(n,l));e.x=a.x,e.y=a.y}}}redrawCellOverlays(t,e=!1){if(this.createCellOverlays(t),t.overlays){const i=mod(t.style.rotation??0,90),s=toRadians(i),n=Math.cos(s),l=Math.sin(s);t.overlays.forEach(o=>{var h;const a=((h=o.overlay)==null?void 0:h.getBounds(t))??null;if(a&&!t.cell.isEdge()&&t.shape&&i!==0){let d=a.getCenterX(),c=a.getCenterY();const u=getRotatedPoint(new Point(d,c),n,l,new Point(t.getCenterX(),t.getCenterY()));d=u.x,c=u.y,a.x=Math.round(d-a.width/2),a.y=Math.round(c-a.height/2)}(e||o.bounds==null||o.scale!==t.view.scale||!o.bounds.equals(a))&&(o.bounds=a,o.scale=t.view.scale,o.redraw())})}}redrawControl(t,e=!1){const i=t.view.graph.getFoldingImage(t);if(t.control!=null&&i!=null){const s=this.getControlBounds(t,i.width,i.height),n=this.legacyControlPosition?t.style.rotation??0:t.shape.getTextRotation(),l=t.view.scale;(e||t.control.scale!==l||!t.control.bounds.equals(s)||t.control.rotation!==n)&&(t.control.rotation=n,t.control.bounds=s,t.control.scale=l,t.control.redraw())}}getControlBounds(t,e,i){if(t.control!=null){const s=t.view.scale;let n=t.getCenterX(),l=t.getCenterY();if(!t.cell.isEdge()&&(n=t.x+e*s,l=t.y+i*s,t.shape!=null)){let o=t.shape.getShapeRotation();if(this.legacyControlPosition)o=t.style.rotation??0;else if(t.shape.isPaintBoundsInverted()){const a=(t.width-t.height)/2;n+=a,l-=a}if(o!==0){const a=toRadians(o),h=Math.cos(a),d=Math.sin(a),c=getRotatedPoint(new Point(n,l),h,d,new Point(t.getCenterX(),t.getCenterY()));n=c.x,l=c.y}}return t.cell.isEdge()?new Rectangle(Math.round(n-e/2*s),Math.round(l-i/2*s),Math.round(e*s),Math.round(i*s)):new Rectangle(Math.round(n-e/2*s),Math.round(l-i/2*s),Math.round(e*s),Math.round(i*s))}return null}insertStateAfter(t,e,i){const s=t.view.graph,n=this.getShapesForState(t);for(let l=0;l<n.length;l+=1)if(n[l]!=null&&n[l].node!=null){const o=n[l].node.parentNode!==t.view.getDrawPane()&&n[l].node.parentNode!==t.view.getOverlayPane(),a=o?i:e;if(a!=null&&a.nextSibling!==n[l].node)a.nextSibling==null?a.parentNode.appendChild(n[l].node):a.parentNode.insertBefore(n[l].node,a.nextSibling);else if(a==null){const h=n[l].node;if(h.parentNode===s.container){let{canvas:d}=t.view;for(;d!=null&&d.parentNode!==s.container;)d=d.parentNode;d!=null&&d.nextSibling!=null?d.nextSibling!==h&&h.parentNode.insertBefore(h,d.nextSibling):h.parentNode.appendChild(h)}else h.parentNode!=null&&h.parentNode.firstChild!=null&&h.parentNode.firstChild!=h&&h.parentNode.insertBefore(h,h.parentNode.firstChild)}o?i=n[l].node:e=n[l].node}return[e,i]}getShapesForState(t){return[t.shape,t.text,t.control]}redraw(t,e=!1,i=!0){const s=this.redrawShape(t,e,i);t.shape!=null&&i&&(this.redrawLabel(t,s),this.redrawCellOverlays(t,s),this.redrawControl(t,s))}redrawShape(t,e=!1,i=!0){let s=!1;const n=t.view.graph;t.shape!=null&&t.shape.style!=null&&t.style!=null&&t.shape.style.shape!==t.style.shape&&(t.shape.destroy(),t.shape=null);const l=n.getPlugin("SelectionCellsHandler");return t.shape==null&&n.container!=null&&t.cell!==t.view.currentRoot&&(t.cell.isVertex()||t.cell.isEdge())?(t.shape=this.createShape(t),t.shape!=null&&(t.shape.minSvgStrokeWidth=this.minSvgStrokeWidth,t.shape.antiAlias=this.antiAlias,this.createIndicatorShape(t),this.initializeShape(t),this.createCellOverlays(t),this.installListeners(t),l==null||l.updateHandler(t))):!e&&t.shape!=null&&(!equalEntries(t.shape.style,t.style)||this.checkPlaceholderStyles(t))&&(t.shape.resetStyles(),this.configureShape(t),l==null||l.updateHandler(t),e=!0),t.shape!=null&&t.shape.indicatorShape!=this.getShape(t.getIndicatorShape())&&(t.shape.indicator!=null&&(t.shape.indicator.destroy(),t.shape.indicator=null),this.createIndicatorShape(t),t.shape.indicatorShape!=null&&(t.shape.indicator=new t.shape.indicatorShape,t.shape.indicator.dialect=t.shape.dialect,t.shape.indicator.init(t.node),e=!0)),t.shape&&(this.createControl(t),(e||this.isShapeInvalid(t,t.shape))&&(t.absolutePoints.length>0?(t.shape.points=t.absolutePoints.slice(),t.shape.bounds=null):(t.shape.points=[],t.shape.bounds=new Rectangle(t.x,t.y,t.width,t.height)),t.shape.scale=t.view.scale,i==null||i?this.doRedrawShape(t):t.shape.updateBoundingBox(),s=!0)),s}doRedrawShape(t){var e;(e=t.shape)==null||e.redraw()}isShapeInvalid(t,e){return e.bounds==null||e.scale!==t.view.scale||t.absolutePoints.length===0&&!e.bounds.equals(t)||t.absolutePoints.length>0&&!equalPoints(e.points,t.absolutePoints)}destroy(t){t.shape&&(t.text&&(t.text.destroy(),t.text=null),t.overlays.forEach(e=>{e.destroy()}),t.overlays=new Map,t.control&&(t.control.destroy(),t.control=null),t.shape.destroy(),t.shape=null)}}class Stylesheet{constructor(){this.styles=new Map,this.putDefaultVertexStyle(this.createDefaultVertexStyle()),this.putDefaultEdgeStyle(this.createDefaultEdgeStyle())}createDefaultVertexStyle(){return{shape:"rectangle",perimeter:"rectanglePerimeter",verticalAlign:"middle",align:"center",fillColor:"#C3D9FF",strokeColor:"#6482B9",fontColor:"#774400"}}createDefaultEdgeStyle(){return{shape:"connector",endArrow:"classic",verticalAlign:"middle",align:"center",strokeColor:"#6482B9",fontColor:"#446299"}}putDefaultVertexStyle(t){this.putCellStyle("defaultVertex",t)}putDefaultEdgeStyle(t){this.putCellStyle("defaultEdge",t)}getDefaultVertexStyle(){return this.styles.get("defaultVertex")}getDefaultEdgeStyle(){return this.styles.get("defaultEdge")}putCellStyle(t,e){this.styles.set(t,e)}getCellStyle(t,e){let i=t.ignoreDefaultStyle?{}:{...e};t.baseStyleNames&&(i=t.baseStyleNames.reduce((s,n)=>({...s,...this.styles.get(n)}),i));for(const s of Object.keys(t))t[s]!==void 0&&(t[s]==NONE?delete i[s]:i[s]=t[s]);return"baseStyleNames"in i&&delete i.baseStyleNames,"ignoreDefaultStyle"in i&&delete i.ignoreDefaultStyle,i}}class SelectionChange{constructor(t,e=[],i=[]){this.graph=t,this.added=e.slice(),this.removed=i.slice()}execute(){const t=this.graph.getSelectionModel();for(const e of this.removed)t.cellRemoved(e);for(const e of this.added)t.cellAdded(e);[this.added,this.removed]=[this.removed,this.added],t.fireEvent(new EventObject(InternalEvent.CHANGE,{added:this.added,removed:this.removed}))}}class GraphSelectionModel extends EventSource{constructor(t){super(),this.doneResource=isI18nEnabled()?"done":"",this.updatingSelectionResource=isI18nEnabled()?"updatingSelection":"",this.singleSelection=!1,this.graph=t,this.cells=[]}isSingleSelection(){return this.singleSelection}setSingleSelection(t){this.singleSelection=t}isSelected(t){return this.cells.includes(t)}isEmpty(){return this.cells.length===0}clear(){this.changeSelection(null,this.cells)}setCell(t){this.setCells(t?[t]:[])}setCells(t){if(this.singleSelection){const i=this.getFirstSelectableCell(t);this.changeSelection(i?[i]:[],this.cells);return}const e=t.filter(i=>this.graph.isCellSelectable(i));this.changeSelection(e,this.cells)}getFirstSelectableCell(t){return t.find(e=>this.graph.isCellSelectable(e))??null}addCell(t){this.addCells([t])}addCells(t){if(this.singleSelection){const i=this.getFirstSelectableCell(t),s=i&&!this.isSelected(i)?[i]:[];this.changeSelection(s,this.cells);return}const e=t.filter(i=>!this.isSelected(i)&&this.graph.isCellSelectable(i));this.changeSelection(e,null)}removeCell(t){this.removeCells([t])}removeCells(t){const e=t.filter(i=>this.isSelected(i));this.changeSelection(null,e)}changeSelection(t=null,e=null){const i=(t??[]).filter(n=>n!=null),s=(e??[]).filter(n=>n!=null);if(i.length>0||s.length>0){const n=new SelectionChange(this.graph,i,s);n.execute();const l=new UndoableEdit(this.graph,!1);l.add(n),this.fireEvent(new EventObject(InternalEvent.UNDO,{edit:l}))}}cellAdded(t){this.isSelected(t)||this.cells.push(t)}cellRemoved(t){const e=this.cells.indexOf(t);e>=0&&this.cells.splice(e,1)}}class CurrentRootChange{constructor(t,e){if(this.view=t,this.root=e,this.previous=e,this.isUp=e===null,!this.isUp){let i=this.view.currentRoot;for(;i;){if(i===e){this.isUp=!0;break}i=i.getParent()}}}execute(){const t=this.view.currentRoot;this.view.currentRoot=this.previous,this.previous=t;const e=this.view.graph.getTranslateForRoot(this.view.currentRoot);e&&(this.view.translate=new Point(-e.x,-e.y)),this.isUp?(this.view.clear(this.view.currentRoot,!0,!0),this.view.validate(null)):this.view.refresh();const i=this.isUp?InternalEvent.UP:InternalEvent.DOWN;this.view.fireEvent(new EventObject(i,{root:this.view.currentRoot,previous:this.previous})),this.isUp=!this.isUp}}const PerimeterRegistry=new BaseRegistry;class GraphView extends EventSource{constructor(t){super(),this.backgroundImage=null,this.backgroundPageShape=null,this.EMPTY_POINT=new Point,this.doneResource=isI18nEnabled()?"done":"",this.updatingDocumentResource=isI18nEnabled()?"updatingDocument":"",this.allowEval=!1,this.captureDocumentGesture=!0,this.rendering=!0,this.currentRoot=null,this.graphBounds=new Rectangle,this.scale=1,this.translate=new Point,this.states=new Map,this.updateStyle=!1,this.lastNode=null,this.lastHtmlNode=null,this.lastForegroundNode=null,this.lastForegroundHtmlNode=null,this.endHandler=null,this.moveHandler=null,this.graph=t}getGraphBounds(){return this.graphBounds}setGraphBounds(t){this.graphBounds=t}getScale(){return this.scale}setScale(t){const e=this.scale;e!==t&&(this.scale=t,this.isEventsEnabled()&&this.viewStateChanged()),this.fireEvent(new EventObject(InternalEvent.SCALE,{scale:t,previousScale:e}))}getTranslate(){return this.translate}isRendering(){return this.rendering}setRendering(t){this.rendering=t}setTranslate(t,e){const i=new Point(this.translate.x,this.translate.y);(this.translate.x!==t||this.translate.y!==e)&&(this.translate.x=t,this.translate.y=e,this.isEventsEnabled()&&this.viewStateChanged()),this.fireEvent(new EventObject(InternalEvent.TRANSLATE,{translate:this.translate,previousTranslate:i}))}isAllowEval(){return this.allowEval}setAllowEval(t){this.allowEval=t}getStates(){return this.states}setStates(t){this.states=t}getCanvas(){return this.canvas}getBackgroundPane(){return this.backgroundPane}getDrawPane(){return this.drawPane}getOverlayPane(){return this.overlayPane}getDecoratorPane(){return this.decoratorPane}getBounds(t){let e=null;if(t.length>0){for(let i=0;i<t.length;i+=1)if(t[i].isVertex()||t[i].isEdge()){const s=this.getState(t[i]);s&&(e?e.add(s):e=Rectangle.fromRectangle(s))}}return e}setCurrentRoot(t){if(this.currentRoot!==t){const e=new CurrentRootChange(this,t);e.execute();const i=new UndoableEdit(this,!0);i.add(e),this.fireEvent(new EventObject(InternalEvent.UNDO,{edit:i})),this.graph.sizeDidChange(),this.currentRoot=t}return t}scaleAndTranslate(t,e,i){const s=this.scale,n=new Point(this.translate.x,this.translate.y);(this.scale!==t||this.translate.x!==e||this.translate.y!==i)&&(this.scale=t,this.translate.x=e,this.translate.y=i,this.isEventsEnabled()&&this.viewStateChanged()),this.fireEvent(new EventObject(InternalEvent.SCALE_AND_TRANSLATE,{scale:t,previousScale:s,translate:this.translate,previousTranslate:n}))}viewStateChanged(){this.revalidate(),this.graph.sizeDidChange()}refresh(){this.currentRoot&&this.clear(),this.revalidate()}revalidate(){this.invalidate(),this.validate()}clear(t,e=!1,i=!0){if(t||(t=this.graph.getDataModel().getRoot()),t)if(this.removeState(t),i&&(e||t!==this.currentRoot)){const s=t.getChildCount();for(let n=0;n<s;n+=1)this.clear(t.getChildAt(n),e)}else this.invalidate(t)}invalidate(t=null,e=!0,i=!0){const s=this.graph.getDataModel();if(t=t??s.getRoot(),t){const n=this.getState(t);if(n&&(n.invalid=!0),!t.invalidating){if(t.invalidating=!0,e){const l=t.getChildCount();for(let o=0;o<l;o+=1){const a=t.getChildAt(o);this.invalidate(a,e,i)}}if(i){const l=t.getEdgeCount();for(let o=0;o<l;o+=1)this.invalidate(t.getEdgeAt(o),e,i)}t.invalidating=!1}}}validate(t=null){const e=log().enter("GraphView.validate");this.resetValidationState();const i=t||(this.currentRoot??this.graph.getDataModel().getRoot());if(i){const s=this.getBoundingBox(this.validateCellState(i?this.validateCell(i):null));this.setGraphBounds(s??this.getEmptyBounds()),this.validateBackground(),this.resetValidationState()}log().leave("GraphView.validate",e)}getEmptyBounds(){return new Rectangle(this.translate.x*this.scale,this.translate.y*this.scale)}getBoundingBox(t=null,e=!0){let i=null;if(t&&(t.shape&&t.shape.boundingBox&&(i=t.shape.boundingBox.clone()),t.text&&t.text.boundingBox&&(i?i.add(t.text.boundingBox):i=t.text.boundingBox.clone()),e)){const s=t.cell.getChildCount();for(let n=0;n<s;n+=1){const l=this.getBoundingBox(this.getState(t.cell.getChildAt(n)));l&&(i?i.add(l):i=l)}}return i}createBackgroundPageShape(t){return new RectangleShape(t,"white","black")}validateBackground(){this.validateBackgroundImage(),this.validateBackgroundPage()}validateBackgroundImage(){const t=this.graph.getBackgroundImage();if(t){if(!this.backgroundImage||this.backgroundImage.imageSrc!==t.src){this.backgroundImage&&this.backgroundImage.destroy();const e=new Rectangle(0,0,1,1);this.backgroundImage=new ImageShape(e,t.src),this.backgroundImage.dialect=this.graph.dialect,this.backgroundImage.init(this.backgroundPane),this.backgroundImage.redraw()}this.redrawBackgroundImage(this.backgroundImage,t)}else this.backgroundImage&&(this.backgroundImage.destroy(),this.backgroundImage=null)}validateBackgroundPage(){const t=this.graph;if(t.pageVisible){const e=this.getBackgroundPageBounds();this.backgroundPageShape==null?(this.backgroundPageShape=this.createBackgroundPageShape(e),this.backgroundPageShape.scale=this.scale,this.backgroundPageShape.isShadow=!0,this.backgroundPageShape.dialect=this.graph.dialect,this.backgroundPageShape.init(this.backgroundPane),this.backgroundPageShape.redraw(),this.backgroundPageShape.node&&(t.isNativeDblClickEnabled()&&InternalEvent.addListener(this.backgroundPageShape.node,"dblclick",(i=>{t.dblClick(i)})),InternalEvent.addGestureListeners(this.backgroundPageShape.node,i=>{t.fireMouseEvent(InternalEvent.MOUSE_DOWN,new InternalMouseEvent(i))},i=>{const s=t.getPlugin("TooltipHandler");s&&s.isHideOnHover()&&s.hide(),t.isMouseDown&&!isConsumed(i)&&t.fireMouseEvent(InternalEvent.MOUSE_MOVE,new InternalMouseEvent(i))},i=>{t.fireMouseEvent(InternalEvent.MOUSE_UP,new InternalMouseEvent(i))}))):(this.backgroundPageShape.scale=this.scale,this.backgroundPageShape.bounds=e,this.backgroundPageShape.redraw())}else this.backgroundPageShape&&(this.backgroundPageShape.destroy(),this.backgroundPageShape=null)}getBackgroundPageBounds(){const t=this.graph.pageFormat,e=this.scale*this.graph.pageScale;return new Rectangle(this.scale*this.translate.x,this.scale*this.translate.y,t.width*e,t.height*e)}redrawBackgroundImage(t,e){if(t.scale=this.scale,t.bounds){const i=t.bounds;i.x=this.scale*this.translate.x,i.y=this.scale*this.translate.y,i.width=this.scale*e.width,i.height=this.scale*e.height}t.redraw()}validateCell(t,e=!0){if(e=e&&t.isVisible(),this.getState(t,e)&&!e)this.removeState(t);else{const s=t.getChildCount();for(let n=0;n<s;n+=1)this.validateCell(t.getChildAt(n),e&&(!t.isCollapsed()||t===this.currentRoot))}return t}validateCellState(t,e=!0){let i=null;if(t&&(i=this.getState(t),i&&(i.invalid&&(i.invalid=!1,(!i.style||i.invalidStyle)&&(i.style=this.graph.getCellStyle(i.cell),i.invalidStyle=!1),t!==this.currentRoot&&this.validateCellState(t.getParent(),!1),i.setVisibleTerminalState(this.validateCellState(this.getVisibleTerminal(t,!0),!1),!0),i.setVisibleTerminalState(this.validateCellState(this.getVisibleTerminal(t,!1),!1),!1),this.updateCellState(i),t!==this.currentRoot&&!i.invalid&&(this.graph.cellRenderer.redraw(i,!1,this.isRendering()),i.updateCachedBounds())),e&&!i.invalid))){i.shape&&this.stateValidated(i);const s=t.getChildCount();for(let n=0;n<s;n+=1)this.validateCellState(t.getChildAt(n))}return i}updateCellState(t){const e=t.absoluteOffset,i=t.origin;if(e.x=0,e.y=0,i.x=0,i.y=0,t.length=0,t.cell!==this.currentRoot){const s=t.cell.getParent(),n=s?this.getState(s):null;n&&n.cell!==this.currentRoot&&(i.x+=n.origin.x,i.y+=n.origin.y);let l=this.graph.getChildOffsetForCell(t.cell);l&&(i.x+=l.x,i.y+=l.y);const o=t.cell.getGeometry();if(o){if(!t.cell.isEdge())if(l=o.offset?o.offset:this.EMPTY_POINT,o.relative&&n)if(n.cell.isEdge()){const a=this.getPoint(n,o);a&&(i.x+=a.x/this.scale-n.origin.x-this.translate.x,i.y+=a.y/this.scale-n.origin.y-this.translate.y)}else i.x+=o.x*n.unscaledWidth+l.x,i.y+=o.y*n.unscaledHeight+l.y;else e.x=this.scale*l.x,e.y=this.scale*l.y,i.x+=o.x,i.y+=o.y;t.x=this.scale*(this.translate.x+i.x),t.y=this.scale*(this.translate.y+i.y),t.width=this.scale*o.width,t.unscaledWidth=o.width,t.height=this.scale*o.height,t.unscaledHeight=o.height,t.cell.isVertex()&&this.updateVertexState(t,o),t.cell.isEdge()&&this.updateEdgeState(t,o)}}t.updateCachedBounds()}updateVertexState(t,e){const i=t.cell.getParent(),s=i?this.getState(i):null;if(e.relative&&s&&!s.cell.isEdge()){const n=toRadians(s.style.rotation??0);if(n!==0){const l=Math.cos(n),o=Math.sin(n),a=new Point(t.getCenterX(),t.getCenterY()),h=new Point(s.getCenterX(),s.getCenterY()),d=getRotatedPoint(a,l,o,h);t.x=d.x-t.width/2,t.y=d.y-t.height/2}}this.updateVertexLabelOffset(t)}updateEdgeState(t,e){const i=t.getVisibleTerminalState(!0),s=t.getVisibleTerminalState(!1);if(t.cell.getTerminal(!0)&&!i||!i&&!e.getTerminalPoint(!0)||t.cell.getTerminal(!1)&&!s||!s&&!e.getTerminalPoint(!1))this.clear(t.cell,!0);else{this.updateFixedTerminalPoints(t,i,s),this.updatePoints(t,e.points,i,s),this.updateFloatingTerminalPoints(t,i,s);const n=t.absolutePoints;t.cell!==this.currentRoot&&(n==null||n.length<2||n[0]==null||n[n.length-1]==null)?this.clear(t.cell,!0):(this.updateEdgeBounds(t),this.updateEdgeLabelOffset(t))}}updateVertexLabelOffset(t){switch(t.style.labelPosition??"center"){case"left":{let s=t.style.labelWidth??null;s!=null?s*=this.scale:s=t.width,t.absoluteOffset.x-=s;break}case"right":{t.absoluteOffset.x+=t.width;break}case"center":{const s=t.style.labelWidth??null;if(s!=null){const n=t.style.align??"center";let l=0;n==="center"?l=.5:n==="right"&&(l=1),l!==0&&(t.absoluteOffset.x-=(s*this.scale-t.width)*l)}break}}const i=t.style.verticalLabelPosition??"middle";i==="top"?t.absoluteOffset.y-=t.height:i==="bottom"&&(t.absoluteOffset.y+=t.height)}resetValidationState(){this.lastNode=null,this.lastHtmlNode=null,this.lastForegroundNode=null,this.lastForegroundHtmlNode=null}stateValidated(t){const e=this.graph,i=t.cell.isEdge()&&e.keepEdgesInForeground||t.cell.isVertex()&&e.keepEdgesInBackground,s=i?this.lastForegroundHtmlNode||this.lastHtmlNode:this.lastHtmlNode,n=i?this.lastForegroundNode||this.lastNode:this.lastNode,l=e.cellRenderer.insertStateAfter(t,n,s);i?(this.lastForegroundHtmlNode=l[1],this.lastForegroundNode=l[0]):(this.lastHtmlNode=l[1],this.lastNode=l[0])}updateFixedTerminalPoints(t,e,i){this.updateFixedTerminalPoint(t,e,!0,this.graph.getConnectionConstraint(t,e,!0)),this.updateFixedTerminalPoint(t,i,!1,this.graph.getConnectionConstraint(t,i,!1))}updateFixedTerminalPoint(t,e,i,s){t.setAbsoluteTerminalPoint(this.getFixedTerminalPoint(t,e,i,s),i)}getFixedTerminalPoint(t,e,i,s){let n=null;if(s&&e&&(n=this.graph.getConnectionPoint(e,s,!1)),!n&&!e){const l=this.scale,o=this.translate,a=t.origin;n=t.cell.getGeometry().getTerminalPoint(i),n&&(n=new Point(l*(o.x+n.x+a.x),l*(o.y+n.y+a.y)))}return n}updateBoundsFromStencil(t){let e=null;if(t&&t.shape&&t.shape.stencil&&t.shape.stencil.aspect==="fixed"){e=Rectangle.fromRectangle(t);const i=t.shape.stencil.computeAspect(null,t.x,t.y,t.width,t.height);t.setRect(i.x,i.y,t.shape.stencil.w0*i.width,t.shape.stencil.h0*i.height)}return e}updatePoints(t,e,i,s){const n=[];n.push(t.absolutePoints[0]);const l=this.getEdgeStyle(t,e,i,s);if(l&&i){const a=this.getTerminalPort(t,i,!0),h=s?this.getTerminalPort(t,s,!1):null,d=this.updateBoundsFromStencil(a),c=this.updateBoundsFromStencil(h);l(t,a,h,e,n),a&&d&&a.setRect(d.x,d.y,d.width,d.height),h&&c&&h.setRect(c.x,c.y,c.width,c.height)}else if(e){for(let a=0;a<e.length;a+=1)if(e[a]){const h=clone(e[a]);n.push(this.transformControlPoint(t,h))}}const o=t.absolutePoints;n.push(o[o.length-1]),t.absolutePoints=n}transformControlPoint(t,e,i=!1){if(t&&e){const s=t.origin,n=i?1:this.scale;return new Point(n*(e.x+this.translate.x+s.x),n*(e.y+this.translate.y+s.y))}return null}isLoopStyleEnabled(t,e=[],i=null,s=null){const n=this.graph.getConnectionConstraint(t,i,!0),l=this.graph.getConnectionConstraint(t,s,!1);return(e==null||e.length<2)&&!((t.style.orthogonalLoop??!1)||(n==null||n.point==null)&&(l==null||l.point==null))?i!=null&&i===s:!1}getEdgeStyle(t,e=[],i=null,s=null){let n=this.isLoopStyleEnabled(t,e,i,s)?t.style.loopStyle??this.graph.defaultLoopStyle:t.style.noEdgeStyle??!1?null:t.style.edgeStyle;if(typeof n=="string"){let l=EdgeStyleRegistry.get(n);!l&&this.isAllowEval()&&(l=doEval(n)),n=l}return typeof n=="function"?n:null}updateFloatingTerminalPoints(t,e,i){const s=t.absolutePoints,n=s[0];!s[s.length-1]&&i&&this.updateFloatingTerminalPoint(t,i,e,!1),!n&&e&&this.updateFloatingTerminalPoint(t,e,i,!0)}updateFloatingTerminalPoint(t,e,i,s){t.setAbsoluteTerminalPoint(this.getFloatingTerminalPoint(t,e,i,s),s)}getFloatingTerminalPoint(t,e,i,s){e=this.getTerminalPort(t,e,s);let n=this.getNextPoint(t,i,s);const l=this.graph.isOrthogonal(t),o=toRadians(e.style.rotation??0),a=new Point(e.getCenterX(),e.getCenterY());if(o!==0){const c=Math.cos(-o),u=Math.sin(-o);n=getRotatedPoint(n,c,u,a)}let h=t.style.perimeterSpacing??0;h+=t.style[s?"sourcePerimeterSpacing":"targetPerimeterSpacing"]??0;let d=this.getPerimeterPoint(e,n,o===0&&l,h);if(d&&o!==0){const c=Math.cos(o),u=Math.sin(o);d=getRotatedPoint(d,c,u,a)}return d}getTerminalPort(t,e,i=!1){const s=i?"sourcePort":"targetPort",n=t.style[s];if(n){const l=this.graph.getDataModel().getCell(n);if(l){const o=this.getState(l,!1);o&&(e=o)}}return e}getPerimeterPoint(t,e,i,s=0){let n=null;if(t!=null){const l=this.getPerimeterFunction(t);if(l!=null&&e!=null){const o=this.getPerimeterBounds(t,s);if(o.width>0||o.height>0){n=new Point(e.x,e.y);let a=!1,h=!1;t.cell.isVertex()&&(a=!!t.style.flipH,h=!!t.style.flipV,a&&(n.x=2*o.getCenterX()-n.x),h&&(n.y=2*o.getCenterY()-n.y)),n=l(o,t,n,i),n!=null&&(a&&(n.x=2*o.getCenterX()-n.x),h&&(n.y=2*o.getCenterY()-n.y))}}n==null&&(n=this.getPoint(t))}return n}getRoutingCenterX(t){const e=t.style?t.style.routingCenterX??0:0;return t.getCenterX()+e*t.width}getRoutingCenterY(t){const e=t.style?t.style.routingCenterY??0:0;return t.getCenterY()+e*t.height}getPerimeterBounds(t,e=0){return e+=t.style.perimeterSpacing??0,t.getPerimeterBounds(e*this.scale)}getPerimeterFunction(t){let e=t.style.perimeter;if(typeof e=="string"){let i=PerimeterRegistry.get(e);i==null&&this.isAllowEval()&&(i=doEval(e)),e=i}return typeof e=="function"?e:null}getNextPoint(t,e,i=!1){const s=t.absolutePoints;let n=null;if(s.length>=2){const l=s.length;n=s[i?Math.min(1,l-1):Math.max(0,l-2)]}return!n&&e&&(n=new Point(e.getCenterX(),e.getCenterY())),n}getVisibleTerminal(t,e){const i=this.graph.getDataModel();let s=t.getTerminal(e),n=s;for(;s&&s!==this.currentRoot;)(n&&!n.isVisible()||s.isCollapsed())&&(n=s),s=s.getParent();return n&&(!i.contains(n)||n.getParent()===i.getRoot()||n===this.currentRoot)&&(n=null),n}updateEdgeBounds(t){const e=t.absolutePoints,i=e[0],s=e[e.length-1];if(i&&s&&(i.x!==s.x||i.y!==s.y)){const a=s.x-i.x,h=s.y-i.y;t.terminalDistance=Math.sqrt(a*a+h*h)}else t.terminalDistance=0;let n=0;const l=[];let o=i;if(o){let a=o.x,h=o.y,d=a,c=h;for(let g=1;g<e.length;g+=1){const f=e[g];if(f){const p=o.x-f.x,y=o.y-f.y,v=Math.sqrt(p*p+y*y);l.push(v),n+=v,o=f,a=Math.min(o.x,a),h=Math.min(o.y,h),d=Math.max(o.x,d),c=Math.max(o.y,c)}}t.length=n,t.segments=l;const u=1;t.x=a,t.y=h,t.width=Math.max(u,d-a),t.height=Math.max(u,c-h)}}getPoint(t,e=null){let i=t.getCenterX(),s=t.getCenterY();if(t.segments!=null&&(e==null||e.relative)){const n=e!=null?e.x/2:0,l=t.absolutePoints.length,o=Math.round((n+.5)*t.length);let a=t.segments[0],h=0,d=1;for(;o>=Math.round(h+a)&&d<l-1;)h+=a,a=t.segments[d++];const c=a===0?0:(o-h)/a,u=t.absolutePoints[d-1],g=t.absolutePoints[d];if(u!=null&&g!=null){let f=0,p=0,y=0;if(e!=null){f=e.y;const{offset:m}=e;m!=null&&(p=m.x,y=m.y)}const v=g.x-u.x,S=g.y-u.y,w=a===0?0:S/a,C=a===0?0:v/a;i=u.x+v*c+(w*f+p)*this.scale,s=u.y+S*c-(C*f-y)*this.scale}}else if(e!=null){const{offset:n}=e;n!=null&&(i+=n.x,s+=n.y)}return new Point(i,s)}getRelativePoint(t,e,i){const s=t.cell.getGeometry();if(s){const n=t.absolutePoints,l=n.length;if(s.relative&&l>1){const o=t.length,{segments:a}=t;let h=n[0],d=n[1],c=ptSegDistSq(h.x,h.y,d.x,d.y,e,i),u=0,g=0,f=0;for(let q=2;q<l;q+=1){h=d,d=n[q];const it=ptSegDistSq(h.x,h.y,d.x,d.y,e,i);f+=a[q-2],it<=c&&(c=it,g=q-1,u=f)}const p=a[g];h=n[g],d=n[g+1];const y=h.x,v=h.y,S=d.x,w=d.y;let C=e,m=i;const M=y-S,b=v-w;C-=S,m-=w;let O=0;C=M-C,m=b-m;const R=C*M+m*b;R<=0?O=0:O=R*R/(M*M+b*b);let H=Math.sqrt(O);H>p&&(H=p);let T=Math.sqrt(ptSegDistSq(h.x,h.y,d.x,d.y,e,i));return relativeCcw(h.x,h.y,d.x,d.y,e,i)===-1&&(T=-T),new Point((o/2-u-H)/o*-2,T/this.scale)}}return new Point}updateEdgeLabelOffset(t){const e=t.absolutePoints,i=t.absoluteOffset;if(i.x=t.getCenterX(),i.y=t.getCenterY(),e.length>0&&t.segments){const s=t.cell.getGeometry();if(s)if(s.relative){const n=this.getPoint(t,s);t.absoluteOffset=n}else{const n=e[0],l=e[e.length-1];if(n&&l){const o=l.x-n.x,a=l.y-n.y;let h=0,d=0;const c=s.offset;c&&(h=c.x,d=c.y);const u=n.x+o/2+h*this.scale,g=n.y+a/2+d*this.scale;i.x=u,i.y=g}}}}getState(t,e=!1){let i=this.states.get(t)??null;return e&&(!i||this.updateStyle)&&t.isVisible()&&(i?i.style=this.graph.getCellStyle(t):(i=this.createState(t),this.states.set(t,i))),i}getCellStates(t=null){if(!t)return Array.from(this.states.values());const e=[];for(const i of t){const s=this.getState(i);s&&e.push(s)}return e}removeState(t){const e=this.states.get(t)??null;return this.states.delete(t),e&&(this.graph.cellRenderer.destroy(e),e.invalid=!0,e.destroy()),e}createState(t){return new CellState(this,t,this.graph.getCellStyle(t))}isContainerEvent(t){const e=getSource(t);return e&&(e===this.graph.container||e.parentNode===this.backgroundPane||e.parentNode&&e.parentNode.parentNode===this.backgroundPane||e===this.canvas.parentNode||e===this.canvas||e===this.backgroundPane||e===this.drawPane||e===this.overlayPane||e===this.decoratorPane)}isScrollEvent(t){const e=this.graph,i=getOffset(e.container),s=t instanceof MouseEvent?[t.clientX,t.clientY]:[t.touches[0].clientX,t.touches[0].clientY],n=new Point(s[0]-i.x,s[1]-i.y),l=e.container,o=l.offsetWidth,a=l.clientWidth;if(o>a&&n.x>a+2&&n.x<=o)return!0;const h=l.offsetHeight,d=l.clientHeight;return h>d&&n.y>d+2&&n.y<=h}init(){this.installListeners(),this.createSvg()}installListeners(){const t=this.graph,{container:e}=t;Client.IS_TOUCH&&(InternalEvent.addListener(e,"gesturestart",(n=>{t.fireGestureEvent(n),InternalEvent.consume(n)})),InternalEvent.addListener(e,"gesturechange",(n=>{t.fireGestureEvent(n),InternalEvent.consume(n)})),InternalEvent.addListener(e,"gestureend",(n=>{t.fireGestureEvent(n),InternalEvent.consume(n)})));let i=null;InternalEvent.addGestureListeners(e,(n=>{this.isContainerEvent(n)&&(!Client.IS_GC&&!Client.IS_SF||!this.isScrollEvent(n))&&(t.fireMouseEvent(InternalEvent.MOUSE_DOWN,new InternalMouseEvent(n)),i=n.pointerId)}),n=>{this.isContainerEvent(n)&&(i===null||n.pointerId===i)&&t.fireMouseEvent(InternalEvent.MOUSE_MOVE,new InternalMouseEvent(n))},n=>{this.isContainerEvent(n)&&t.fireMouseEvent(InternalEvent.MOUSE_UP,new InternalMouseEvent(n)),i=null}),InternalEvent.addListener(e,"dblclick",(n=>{this.isContainerEvent(n)&&t.dblClick(n)}));const s=n=>{let l=null;if(Client.IS_TOUCH){const o=getClientX(n),a=getClientY(n),h=convertPoint(e,o,a),d=t.getCellAt(h.x,h.y);d&&(l=t.view.getState(d))}return l};t.addMouseListener({mouseDown:()=>{const n=t.getPlugin("PopupMenuHandler");n==null||n.hideMenu()},mouseMove:()=>{},mouseUp:()=>{}}),this.moveHandler=n=>{const l=t.getPlugin("TooltipHandler");l&&l.isHideOnHover()&&l.hide(),this.captureDocumentGesture&&t.isMouseDown&&t.container!=null&&!this.isContainerEvent(n)&&t.container.style.display!=="none"&&t.container.style.visibility!=="hidden"&&!isConsumed(n)&&t.fireMouseEvent(InternalEvent.MOUSE_MOVE,new InternalMouseEvent(n,s(n)))},this.endHandler=n=>{this.captureDocumentGesture&&t.isMouseDown&&t.container!=null&&!this.isContainerEvent(n)&&t.container.style.display!=="none"&&t.container.style.visibility!=="hidden"&&t.fireMouseEvent(InternalEvent.MOUSE_UP,new InternalMouseEvent(n))},InternalEvent.addGestureListeners(document,null,this.moveHandler,this.endHandler)}createSvg(){const{container:t}=this.graph,e=this.canvas=document.createElementNS(NS_SVG,"g");this.backgroundPane=document.createElementNS(NS_SVG,"g"),e.appendChild(this.backgroundPane),this.drawPane=document.createElementNS(NS_SVG,"g"),e.appendChild(this.drawPane),this.overlayPane=document.createElementNS(NS_SVG,"g"),e.appendChild(this.overlayPane),this.decoratorPane=document.createElementNS(NS_SVG,"g"),e.appendChild(this.decoratorPane);const i=document.createElementNS(NS_SVG,"svg");i.style.left="0px",i.style.top="0px",i.style.width="100%",i.style.height="100%",i.style.display="block",i.appendChild(this.canvas),t!=null&&(t.appendChild(i),this.updateContainerStyle(t))}createHtml(){const t=this.graph.container;t!=null&&(this.canvas=this.createHtmlPane("100%","100%"),this.canvas.style.overflow="hidden",this.backgroundPane=this.createHtmlPane("1px","1px"),this.drawPane=this.createHtmlPane("1px","1px"),this.overlayPane=this.createHtmlPane("1px","1px"),this.decoratorPane=this.createHtmlPane("1px","1px"),this.canvas.appendChild(this.backgroundPane),this.canvas.appendChild(this.drawPane),this.canvas.appendChild(this.overlayPane),this.canvas.appendChild(this.decoratorPane),t.appendChild(this.canvas),this.updateContainerStyle(t))}updateHtmlCanvasSize(t,e){if(this.graph.container!=null){const i=this.graph.container.offsetWidth,s=this.graph.container.offsetHeight;i<t?this.canvas.style.width=t+"px":this.canvas.style.width="100%",s<e?this.canvas.style.height=e+"px":this.canvas.style.height="100%"}}createHtmlPane(t,e){const i=document.createElement("DIV");return t!=null&&e!=null?(i.style.position="absolute",i.style.left="0px",i.style.top="0px",i.style.width=t,i.style.height=e):i.style.position="relative",i}updateContainerStyle(t){const e=getCurrentStyle(t);e!=null&&e.position=="static"&&(t.style.position="relative"),Client.IS_POINTER&&(t.style.touchAction="none")}destroy(){let t=null;this.canvas&&this.canvas instanceof SVGElement&&(t=this.canvas.ownerSVGElement),t||(t=this.canvas),t&&t.parentNode&&(this.clear(this.currentRoot,!0),InternalEvent.removeGestureListeners(document,null,this.moveHandler,this.endHandler),InternalEvent.release(this.graph.container),t.parentNode.removeChild(t),this.moveHandler=null,this.endHandler=null,this.canvas=null,this.backgroundPane=null,this.drawPane=null,this.overlayPane=null,this.decoratorPane=null,super.destroy())}}class RhombusShape extends Shape{constructor(t,e,i,s=1){super(),this.bounds=t,this.fill=e,this.stroke=i,this.strokeWidth=s}isRoundable(){return!0}paintVertexShape(t,e,i,s,n){const l=s/2,o=n/2,a=this.getBaseArcSize();t.begin(),this.addPoints(t,[new Point(e+l,i),new Point(e+s,i+o),new Point(e+l,i+n),new Point(e,i+o)],this.isRounded,a,!0),t.fillAndStroke()}}class CylinderShape extends Shape{constructor(t,e,i,s=1){super(),this.maxHeight=40,this.svgStrokeTolerance=0,this.bounds=t,this.fill=e,this.stroke=i,this.strokeWidth=s}paintVertexShape(t,e,i,s,n){t.translate(e,i),t.begin(),this.redrawPath(t,e,i,s,n,!1),t.fillAndStroke(),(!this.outline||!this.style||!(this.style.backgroundOutline??!1))&&(t.setShadow(!1),t.begin(),this.redrawPath(t,e,i,s,n,!0),t.stroke())}getCylinderSize(t,e,i,s){return Math.min(this.maxHeight,Math.round(s/5))}redrawPath(t,e,i,s,n,l=!1){const o=this.getCylinderSize(e,i,s,n);(l&&this.fill!==NONE||!l&&this.fill===NONE)&&(t.moveTo(0,o),t.curveTo(0,2*o,s,2*o,s,o),l||(t.stroke(),t.begin())),l||(t.moveTo(0,o),t.curveTo(0,-o/3,s,-o/3,s,o),t.lineTo(s,n-o),t.curveTo(s,n+o/3,0,n+o/3,0,n-o),t.close())}}class AbstractPathShape extends Shape{constructor(t=null,e=NONE,i=NONE,s=1){super(),this.bounds=t,this.fill=e,this.stroke=i,this.strokeWidth=s}paintVertexShape(t,e,i,s,n){t.translate(e,i),t.begin(),this.redrawPath(t,e,i,s,n),t.fillAndStroke()}}class ActorShape extends AbstractPathShape{redrawPath(t,e,i,s,n){const l=s/3;t.moveTo(0,n),t.curveTo(0,3*n/5,0,2*n/5,s/2,2*n/5),t.curveTo(s/2-l,2*n/5,s/2-l,0,s/2,0),t.curveTo(s/2+l,0,s/2+l,2*n/5,s/2,2*n/5),t.curveTo(s,2*n/5,s,3*n/5,s,n),t.close()}}class TriangleShape extends AbstractPathShape{isRoundable(){return!0}redrawPath(t,e,i,s,n){const l=this.getBaseArcSize();this.addPoints(t,[new Point(0,0),new Point(s,.5*n),new Point(0,n)],this.isRounded,l,!0)}}class HexagonShape extends AbstractPathShape{redrawPath(t,e,i,s,n){const l=this.getBaseArcSize();this.addPoints(t,[new Point(.25*s,0),new Point(.75*s,0),new Point(s,.5*n),new Point(.75*s,n),new Point(.25*s,n),new Point(0,.5*n)],this.isRounded,l,!0)}}class CloudShape extends AbstractPathShape{redrawPath(t,e,i,s,n){t.moveTo(.25*s,.25*n),t.curveTo(.05*s,.25*n,0,.5*n,.16*s,.55*n),t.curveTo(0,.66*n,.18*s,.9*n,.31*s,.8*n),t.curveTo(.4*s,n,.7*s,n,.8*s,.8*n),t.curveTo(s,.8*n,s,.6*n,.875*s,.5*n),t.curveTo(s,.3*n,.8*s,.1*n,.625*s,.2*n),t.curveTo(.5*s,.05*n,.3*s,.05*n,.25*s,.25*n),t.close()}}class LineShape extends Shape{constructor(t,e,i=1,s=!1){super(),this.bounds=t,this.stroke=e,this.strokeWidth=i,this.vertical=s}paintVertexShape(t,e,i,s,n){if(t.begin(),this.vertical){const l=e+s/2;t.moveTo(l,i),t.lineTo(l,i+n)}else{const l=i+n/2;t.moveTo(e,l),t.lineTo(e+s,l)}t.stroke()}}class ArrowShape extends Shape{constructor(t,e,i,s=1,n=ARROW_WIDTH,l=ARROW_SPACING,o=ARROW_SIZE){super(),this.points=t,this.fill=e,this.stroke=i,this.strokeWidth=s,this.arrowWidth=n,this.spacing=l,this.endSize=o}augmentBoundingBox(t){super.augmentBoundingBox(t);const e=Math.max(this.arrowWidth,this.endSize);t.grow((e/2+this.strokeWidth)*this.scale)}paintEdgeShape(t,e){const i=ARROW_SPACING,s=ARROW_WIDTH,n=ARROW_SIZE,l=e[0],o=e[e.length-1],a=o.x-l.x,h=o.y-l.y,d=Math.sqrt(a*a+h*h),c=d-2*i-n,u=a/d,g=h/d,f=c*u,p=c*g,y=s*g/3,v=-s*u/3,S=l.x-y/2+i*u,w=l.y-v/2+i*g,C=S+y,m=w+v,M=C+f,b=m+p,O=M+y,R=b+v,H=O-3*y,T=R-3*v;t.begin(),t.moveTo(S,w),t.lineTo(C,m),t.lineTo(M,b),t.lineTo(O,R),t.lineTo(o.x-i*u,o.y-i*g),t.lineTo(H,T),t.lineTo(H+y,T+v),t.close(),t.fillAndStroke()}}class ArrowConnectorShape extends Shape{constructor(t,e,i,s=1,n=ARROW_WIDTH,l=ARROW_SPACING,o=ARROW_SIZE/5){super(),this.useSvgBoundingBox=!0,this.points=t,this.fill=e,this.stroke=i,this.strokeWidth=s,this.arrowWidth=n,this.arrowSpacing=l,this.startSize=ARROW_SIZE/5,this.endSize=o}isRoundable(){return!0}resetStyles(){super.resetStyles(),this.arrowSpacing=ARROW_SPACING}apply(t){super.apply(t),this.style&&this.style.startSize!=null&&this.style.endSize!=null&&(this.startSize=this.style.startSize*3,this.endSize=this.style.endSize*3)}augmentBoundingBox(t){super.augmentBoundingBox(t);let e=this.getEdgeWidth();this.isMarkerStart()&&(e=Math.max(e,this.getStartArrowWidth())),this.isMarkerEnd()&&(e=Math.max(e,this.getEndArrowWidth())),t.grow((e/2+this.strokeWidth)*this.scale)}paintEdgeShape(t,e){var L;let i=this.strokeWidth;this.outline&&(i=Math.max(1,((L=this.style)==null?void 0:L.strokeWidth)??0));const s=this.getStartArrowWidth()+i,n=this.getEndArrowWidth()+i,l=this.outline?this.getEdgeWidth()+i:this.getEdgeWidth(),o=this.isOpenEnded(),a=this.isMarkerStart(),h=this.isMarkerEnd(),d=o?0:this.arrowSpacing+i/2,c=this.startSize+i,u=this.endSize+i,g=this.isArrowRounded(),f=e[e.length-1];let p=1;for(;p<e.length-1&&e[p].x===e[0].x&&e[p].y===e[0].y;)p++;const y=e[p].x-e[0].x,v=e[p].y-e[0].y,S=Math.sqrt(y*y+v*v);if(S===0)return;let w=y/S,C,m=w,M=v/S,b,O=M,R=l*M,H=-l*w;const T=[];g?t.setLineJoin("round"):e.length>2&&t.setMiterLimit(1.42),t.begin();const U=w,q=M;if(a&&!o)this.paintMarker(t,e[0].x,e[0].y,w,M,c,s,l,d,!0);else{const A=e[0].x+R/2+d*w,I=e[0].y+H/2+d*M,B=e[0].x-R/2+d*w,k=e[0].y-H/2+d*M;o?(t.moveTo(A,I),T.push(()=>{t.lineTo(B,k)})):(t.moveTo(B,k),t.lineTo(A,I))}let it=0,x=0,P=0;for(let A=0;A<e.length-2;A+=1){const I=relativeCcw(e[A].x,e[A].y,e[A+1].x,e[A+1].y,e[A+2].x,e[A+2].y);if(it=e[A+2].x-e[A+1].x,x=e[A+2].y-e[A+1].y,P=Math.sqrt(it*it+x*x),P!==0){m=it/P,O=x/P;const B=w*m+M*O,k=Math.max(Math.sqrt((B+1)/2),.04);C=w+m,b=M+O;const V=Math.sqrt(C*C+b*b);if(V!==0){C/=V,b/=V;const Y=Math.max(k,Math.min(this.strokeWidth/200+.04,.35)),N=I!==0&&g?Math.max(.1,Y):Math.max(k,.06),_=e[A+1].x+b*l/2/N,z=e[A+1].y-C*l/2/N,W=e[A+1].x-b*l/2/N,G=e[A+1].y+C*l/2/N;if(I===0||!g)t.lineTo(_,z),((Q,st)=>{T.push(()=>{t.lineTo(Q,st)})})(W,G);else if(I===-1){const Q=W+M*l,st=G-w*l,F=W+O*l,$=G-m*l;t.lineTo(Q,st),t.quadTo(_,z,F,$),((ot,tt)=>{T.push(()=>{t.lineTo(ot,tt)})})(W,G)}else t.lineTo(_,z),((Q,st)=>{const F=_-M*l,$=z+w*l,ot=_-O*l,tt=z+m*l;T.push(()=>{t.quadTo(Q,st,F,$)}),T.push(()=>{t.lineTo(ot,tt)})})(W,G);w=m,M=O}}}if(R=l*O,H=-l*m,h&&!o)this.paintMarker(t,f.x,f.y,-w,-M,u,n,l,d,!1);else{t.lineTo(f.x-d*m+R/2,f.y-d*O+H/2);const A=f.x-d*m-R/2,I=f.y-d*O-H/2;o?(t.moveTo(A,I),T.splice(0,0,()=>{t.moveTo(A,I)})):t.lineTo(A,I)}for(let A=T.length-1;A>=0;A--)T[A]();o?(t.end(),t.stroke()):(t.close(),t.fillAndStroke()),t.setShadow(!1),t.setMiterLimit(4),g&&t.setLineJoin("flat"),e.length>2&&(t.setMiterLimit(4),a&&!o&&(t.begin(),this.paintMarker(t,e[0].x,e[0].y,U,q,c,s,l,d,!0),t.stroke(),t.end()),h&&!o&&(t.begin(),this.paintMarker(t,f.x,f.y,-w,-M,u,n,l,d,!0),t.stroke(),t.end()))}paintMarker(t,e,i,s,n,l,o,a,h,d){const c=a/o,u=a*n/2,g=-a*s/2,f=(h+l)*s,p=(h+l)*n;d?t.moveTo(e-u+f,i-g+p):t.lineTo(e-u+f,i-g+p),t.lineTo(e-u/c+f,i-g/c+p),t.lineTo(e+h*s,i+h*n),t.lineTo(e+u/c+f,i+g/c+p),t.lineTo(e+u+f,i+g+p)}isArrowRounded(){return this.isRounded}getStartArrowWidth(){return ARROW_WIDTH}getEndArrowWidth(){return ARROW_WIDTH}getEdgeWidth(){return ARROW_WIDTH/3}isOpenEnded(){return!1}isMarkerStart(){var t;return(((t=this.style)==null?void 0:t.startArrow)??NONE)!==NONE}isMarkerEnd(){var t;return(((t=this.style)==null?void 0:t.endArrow)??NONE)!==NONE}}class DoubleEllipseShape extends Shape{constructor(t,e,i,s=1){super(),this.bounds=t,this.fill=e,this.stroke=i,this.strokeWidth=s}paintBackground(t,e,i,s,n){t.ellipse(e,i,s,n),t.fillAndStroke()}paintForeground(t,e,i,s,n){var l;if(!this.outline){const o=((l=this.style)==null?void 0:l.margin)??Math.min(3+this.strokeWidth,Math.min(s/5,n/5));e+=o,i+=o,s-=2*o,n-=2*o,s>0&&n>0&&t.ellipse(e,i,s,n),t.stroke()}}getLabelBounds(t){var i;const e=((i=this.style)==null?void 0:i.margin)??Math.min(3+this.strokeWidth,Math.min(t.width/5/this.scale,t.height/5/this.scale))*this.scale;return new Rectangle(t.x+e,t.y+e,t.width-2*e,t.height-2*e)}}class SwimlaneShape extends Shape{constructor(t,e,i,s=1){super(),this.imageSize=16,this.imageSrc=null,this.bounds=t,this.fill=e,this.stroke=i,this.strokeWidth=s}isRoundable(t,e,i,s,n){return!0}getTitleSize(){var t;return Math.max(0,((t=this.style)==null?void 0:t.startSize)??StyleDefaultsConfig.startSize)}getLabelBounds(t){var c,u;const e=this.getTitleSize(),i=new Rectangle(t.x,t.y,t.width,t.height),s=this.isHorizontal(),n=((c=this.style)==null?void 0:c.flipH)??!1,l=((u=this.style)==null?void 0:u.flipV)??!1,o=this.direction==="north"||this.direction==="south",a=s==!o,h=!a&&n!==(this.direction==="south"||this.direction==="west"),d=a&&l!==(this.direction==="south"||this.direction==="west");if(o){const g=Math.min(i.width,e*this.scale);(h||d)&&(i.x+=i.width-g),i.width=g}else{const g=Math.min(i.height,e*this.scale);(h||d)&&(i.y+=i.height-g),i.height=g}return i}getGradientBounds(t,e,i,s,n){let l=this.getTitleSize();return this.isHorizontal()?(l=Math.min(l,n),new Rectangle(e,i,s,l)):(l=Math.min(l,s),new Rectangle(e,i,l,n))}getSwimlaneArcSize(t,e,i){var n,l;if((n=this.style)!=null&&n.absoluteArcSize)return Math.min(this.getBaseArcSize(),Math.min(e,t)/2);const s=(((l=this.style)==null?void 0:l.arcSize)??StyleDefaultsConfig.roundingFactor*100)/100;return i*s*3}isHorizontal(){var t;return((t=this.style)==null?void 0:t.horizontal)??!0}paintVertexShape(t,e,i,s,n){var c,u,g;let l=this.getTitleSize();const o=((c=this.style)==null?void 0:c.swimlaneFillColor)??NONE,a=((u=this.style)==null?void 0:u.swimlaneLine)??!0;let h=0;this.isHorizontal()?l=Math.min(l,n):l=Math.min(l,s),t.translate(e,i),this.isRounded?(h=this.getSwimlaneArcSize(s,n,l),h=Math.min((this.isHorizontal()?n:s)-l,Math.min(l,h)),this.paintRoundedSwimlane(t,e,i,s,n,l,h,o,a)):this.paintSwimlane(t,e,i,s,n,l,o,a);const d=((g=this.style)==null?void 0:g.separatorColor)??NONE;if(this.paintSeparator(t,e,i,s,n,l,d),this.imageSrc){const f=this.getImageBounds(e,i,s,n);t.image(f.x-e,f.y-i,f.width,f.height,this.imageSrc,!1,!1,!1)}this.glass&&(t.setShadow(!1),this.paintGlassEffect(t,0,0,s,l,h))}paintSwimlane(t,e,i,s,n,l,o,a){t.begin();let h=!0;this.style&&this.style.pointerEvents!=null&&(h=this.style.pointerEvents),!h&&this.fill===NONE&&(t.pointerEvents=!1),this.isHorizontal()?(t.moveTo(0,l),t.lineTo(0,0),t.lineTo(s,0),t.lineTo(s,l),t.fillAndStroke(),l<n&&((o===NONE||!h)&&(t.pointerEvents=!1),o!==NONE&&t.setFillColor(o),t.begin(),t.moveTo(0,l),t.lineTo(0,n),t.lineTo(s,n),t.lineTo(s,l),o===NONE?t.stroke():t.fillAndStroke())):(t.moveTo(l,0),t.lineTo(0,0),t.lineTo(0,n),t.lineTo(l,n),t.fillAndStroke(),l<s&&((o===NONE||!h)&&(t.pointerEvents=!1),o!==NONE&&t.setFillColor(o),t.begin(),t.moveTo(l,0),t.lineTo(s,0),t.lineTo(s,n),t.lineTo(l,n),o===NONE?t.stroke():t.fillAndStroke())),a&&this.paintDivider(t,e,i,s,n,l,o===NONE)}paintRoundedSwimlane(t,e,i,s,n,l,o,a,h){t.begin();let d=!0;this.style&&this.style.pointerEvents!=null&&(d=this.style.pointerEvents),!d&&this.fill===NONE&&(t.pointerEvents=!1),this.isHorizontal()?(t.moveTo(s,l),t.lineTo(s,o),t.quadTo(s,0,s-Math.min(s/2,o),0),t.lineTo(Math.min(s/2,o),0),t.quadTo(0,0,0,o),t.lineTo(0,l),t.fillAndStroke(),l<n&&((a===NONE||!d)&&(t.pointerEvents=!1),a!==NONE&&t.setFillColor(a),t.begin(),t.moveTo(0,l),t.lineTo(0,n-o),t.quadTo(0,n,Math.min(s/2,o),n),t.lineTo(s-Math.min(s/2,o),n),t.quadTo(s,n,s,n-o),t.lineTo(s,l),a===NONE?t.stroke():t.fillAndStroke())):(t.moveTo(l,0),t.lineTo(o,0),t.quadTo(0,0,0,Math.min(n/2,o)),t.lineTo(0,n-Math.min(n/2,o)),t.quadTo(0,n,o,n),t.lineTo(l,n),t.fillAndStroke(),l<s&&((a===NONE||!d)&&(t.pointerEvents=!1),a!==NONE&&t.setFillColor(a),t.begin(),t.moveTo(l,n),t.lineTo(s-o,n),t.quadTo(s,n,s,n-Math.min(n/2,o)),t.lineTo(s,Math.min(n/2,o)),t.quadTo(s,0,s-o,0),t.lineTo(l,0),a===NONE?t.stroke():t.fillAndStroke())),h&&this.paintDivider(t,e,i,s,n,l,a===NONE)}paintDivider(t,e,i,s,n,l,o){o||t.setShadow(!1),t.begin(),this.isHorizontal()?(t.moveTo(0,l),t.lineTo(s,l)):(t.moveTo(l,0),t.lineTo(l,n)),t.stroke()}paintSeparator(t,e,i,s,n,l,o){o!==NONE&&(t.setStrokeColor(o),t.setDashed(!0),t.begin(),this.isHorizontal()?(t.moveTo(s,l),t.lineTo(s,n)):(t.moveTo(l,0),t.lineTo(s,0)),t.stroke(),t.setDashed(!1))}getImageBounds(t,e,i,s){return this.isHorizontal()?new Rectangle(t+i-this.imageSize,e,this.imageSize,this.imageSize):new Rectangle(t,e,this.imageSize,this.imageSize)}}class LabelShape extends RectangleShape{constructor(t,e,i,s){super(t,e,i,s),this.imageSize=StyleDefaultsConfig.imageSize,this.imageSrc=null,this.spacing=2,this.indicatorSize=10,this.indicatorSpacing=2,this.indicatorImageSrc=null}init(t){super.init(t),this.indicatorShape&&(this.indicator=new this.indicatorShape,this.indicator.dialect=this.dialect,this.indicator.init(this.node))}redraw(){this.indicator&&(this.indicator.fill=this.indicatorColor,this.indicator.stroke=this.indicatorStrokeColor,this.indicator.gradient=this.indicatorGradientColor,this.indicator.direction=this.indicatorDirection,this.indicator.redraw()),super.redraw()}isHtmlAllowed(){return super.isHtmlAllowed()&&this.indicatorColor===NONE&&!!this.indicatorShape}paintForeground(t,e,i,s,n){this.paintImage(t,e,i,s,n),this.paintIndicator(t,e,i,s,n),super.paintForeground(t,e,i,s,n)}paintImage(t,e,i,s,n){if(this.imageSrc){const l=this.getImageBounds(e,i,s,n);t.image(l.x,l.y,l.width,l.height,this.imageSrc,!1,!1,!1)}}getImageBounds(t,e,i,s){var d,c,u,g,f;const n=((d=this.style)==null?void 0:d.imageAlign)??"left",l=((c=this.style)==null?void 0:c.verticalAlign)??"middle",o=((u=this.style)==null?void 0:u.imageWidth)??StyleDefaultsConfig.imageSize,a=((g=this.style)==null?void 0:g.imageHeight)??StyleDefaultsConfig.imageSize,h=((f=this.style)==null?void 0:f.spacing)??this.spacing+5;return n==="center"?t+=(i-o)/2:n==="right"?t+=i-o-h:t+=h,l==="top"?e+=h:l==="bottom"?e+=s-a-h:e+=(s-a)/2,new Rectangle(t,e,o,a)}paintIndicator(t,e,i,s,n){if(this.indicator)this.indicator.bounds=this.getIndicatorBounds(e,i,s,n),this.indicator.paint(t);else if(this.indicatorImageSrc){const l=this.getIndicatorBounds(e,i,s,n);t.image(l.x,l.y,l.width,l.height,this.indicatorImageSrc,!1,!1,!1)}}getIndicatorBounds(t,e,i,s){var d,c,u,g;const n=((d=this.style)==null?void 0:d.imageAlign)??"left",l=((c=this.style)==null?void 0:c.verticalAlign)??"middle",o=((u=this.style)==null?void 0:u.indicatorWidth)??this.indicatorSize,a=((g=this.style)==null?void 0:g.indicatorHeight)??this.indicatorSize,h=this.spacing+5;return n==="right"?t+=i-o-h:n==="center"?t+=(i-o)/2:t+=h,l==="bottom"?e+=s-a-h:l==="top"?e+=h:e+=(s-a)/2,new Rectangle(t,e,o,a)}redrawHtmlShape(){for(super.redrawHtmlShape();this.node.hasChildNodes();)this.node.removeChild(this.node.lastChild);if(this.imageSrc&&this.bounds){const t=document.createElement("img");t.style.position="relative",t.setAttribute("border","0");const e=this.getImageBounds(this.bounds.x,this.bounds.y,this.bounds.width,this.bounds.height);e.x-=this.bounds.x,e.y-=this.bounds.y,t.style.left=`${Math.round(e.x)}px`,t.style.top=`${Math.round(e.y)}px`,t.style.width=`${Math.round(e.width)}px`,t.style.height=`${Math.round(e.height)}px`,t.src=this.imageSrc,this.node.appendChild(t)}}}let isDefaultElementsRegistered=!1;function registerDefaultShapes(){if(!isDefaultElementsRegistered){const r=[["actor",ActorShape],["arrow",ArrowShape],["arrowConnector",ArrowConnectorShape],["cloud",CloudShape],["connector",ConnectorShape],["cylinder",CylinderShape],["doubleEllipse",DoubleEllipseShape],["ellipse",EllipseShape],["hexagon",HexagonShape],["image",ImageShape],["label",LabelShape],["line",LineShape],["rectangle",RectangleShape],["rhombus",RhombusShape],["swimlane",SwimlaneShape],["triangle",TriangleShape]];for(const[t,e]of r)ShapeRegistry.add(t,e);isDefaultElementsRegistered=!0}}const registerElbowEdgeStyle=()=>{EdgeStyleRegistry.add("elbowEdgeStyle",ElbowConnector,{handlerKind:"elbow",isOrthogonal:!0})},registerEntityRelationEdgeStyle=()=>{EdgeStyleRegistry.add("entityRelationEdgeStyle",EntityRelation,{allowIntermediateHandles:!1,isOrthogonal:!0})},registerLoopEdgeStyle=()=>{EdgeStyleRegistry.add("loopEdgeStyle",Loop,{handlerKind:"elbow",isOrthogonal:!1})},registerManhattanEdgeStyle=()=>{EdgeStyleRegistry.add("manhattanEdgeStyle",ManhattanConnector,{handlerKind:"segment",isOrthogonal:!0})},registerOrthogonalEdgeStyle=()=>{EdgeStyleRegistry.add("orthogonalEdgeStyle",OrthogonalConnector,{handlerKind:"segment",isOrthogonal:!0})},registerSegmentEdgeStyle=()=>{EdgeStyleRegistry.add("segmentEdgeStyle",SegmentConnector,{handlerKind:"segment",isOrthogonal:!0})},registerSideToSideEdgeStyle=()=>{EdgeStyleRegistry.add("sideToSideEdgeStyle",SideToSide,{handlerKind:"elbow",isOrthogonal:!0})},registerTopToBottomEdgeStyle=()=>{EdgeStyleRegistry.add("topToBottomEdgeStyle",TopToBottom,{handlerKind:"elbow",isOrthogonal:!0})};let isDefaultEdgeStylesRegistered=!1;const registerDefaultEdgeStyles=()=>{isDefaultEdgeStylesRegistered||(registerElbowEdgeStyle(),registerEntityRelationEdgeStyle(),registerLoopEdgeStyle(),registerManhattanEdgeStyle(),registerOrthogonalEdgeStyle(),registerSegmentEdgeStyle(),registerSideToSideEdgeStyle(),registerTopToBottomEdgeStyle(),isDefaultEdgeStylesRegistered=!0)};let isDefaultPerimetersRegistered=!1;const registerDefaultPerimeters=()=>{if(!isDefaultPerimetersRegistered){const r=[["ellipsePerimeter",EllipsePerimeter],["hexagonPerimeter",HexagonPerimeter],["rectanglePerimeter",RectanglePerimeter],["rhombusPerimeter",RhombusPerimeter],["trianglePerimeter",TrianglePerimeter]];for(const[t,e]of r)PerimeterRegistry.add(t,e);isDefaultPerimetersRegistered=!0}};let isDefaultMarkersRegistered=!1;const registerDefaultEdgeMarkers=()=>{if(!isDefaultMarkersRegistered){const r=[["classic",createArrow(2)],["classicThin",createArrow(3)],["block",createArrow(2)],["blockThin",createArrow(3)],["open",createOpenArrow(2)],["openThin",createOpenArrow(3)],["oval",oval],["diamond",diamond],["diamondThin",diamond]];for(const[t,e]of r)EdgeMarkerRegistry.add(t,e);isDefaultMarkersRegistered=!0}};class CellEditorHandler{constructor(t){this.clearOnChange=!1,this.bounds=null,this.resizeThread=null,this.textDirection=null,this.textarea=null,this.editingCell=null,this.trigger=null,this.modified=!1,this.autoSize=!0,this.selectText=!0,this.emptyLabelText=Client.IS_FF?"<br>":"",this.escapeCancelsEditing=!0,this.textNode=null,this.zIndex=5,this.minResize=new Rectangle(0,20),this.wordWrapPadding=0,this.blurEnabled=!1,this.initialValue=null,this.align=null,this.graph=t,this.zoomHandler=()=>{this.graph.isEditing()&&this.resize()},this.changeHandler=e=>{this.editingCell&&!this.graph.getView().getState(this.editingCell,!1)&&this.stopEditing(!0)},this.graph.getView().addListener(InternalEvent.SCALE,this.zoomHandler),this.graph.getView().addListener(InternalEvent.SCALE_AND_TRANSLATE,this.zoomHandler),this.graph.getDataModel().addListener(InternalEvent.CHANGE,this.changeHandler)}init(){this.textarea=document.createElement("div"),this.textarea.className="mxCellEditor mxPlainTextEditor",this.textarea.contentEditable=String(!0),Client.IS_GC&&(this.textarea.style.minHeight="1em"),this.textarea.style.position="absolute",this.installListeners(this.textarea)}applyValue(t,e){this.graph.labelChanged(t.cell,e,this.trigger)}setAlign(t){this.textarea&&(this.textarea.style.textAlign=t),this.align=t,this.resize()}getInitialValue(t,e){let i=htmlEntities(this.graph.getEditingValue(t.cell,e),!1);return i=replaceTrailingNewlines(i,"<div><br></div>"),i.replace(/\n/g,"<br>")}getCurrentValue(t){return this.textarea?extractTextWithWhitespace(Array.from(this.textarea.childNodes)):null}isCancelEditingKeyEvent(t){return this.escapeCancelsEditing||isShiftDown(t)||isControlDown(t)||isMetaDown(t)}installListeners(t){InternalEvent.addListener(t,"dragstart",l=>{this.graph.stopEditing(!1),InternalEvent.consume(l)}),InternalEvent.addListener(t,"blur",l=>{this.blurEnabled&&this.focusLost()}),InternalEvent.addListener(t,"keydown",l=>{isConsumed(l)||(this.isStopEditingEvent(l)?(this.graph.stopEditing(!1),InternalEvent.consume(l)):l.keyCode===27&&(this.graph.stopEditing(this.isCancelEditingKeyEvent(l)),InternalEvent.consume(l)))});const e=l=>{this.editingCell!=null&&this.clearOnChange&&t.innerHTML===this.getEmptyLabelText()&&(!Client.IS_FF||l.keyCode!==8&&l.keyCode!==46)&&(this.clearOnChange=!1,t.innerHTML="")};InternalEvent.addListener(t,"keypress",e),InternalEvent.addListener(t,"paste",e);const i=l=>{if(this.editingCell!=null){const o=this.textarea;o.innerHTML.length===0||o.innerHTML==="<br>"?(o.innerHTML=this.getEmptyLabelText(),this.clearOnChange=o.innerHTML.length>0):this.clearOnChange=!1}};InternalEvent.addListener(t,"input",i),InternalEvent.addListener(t,"cut",i),InternalEvent.addListener(t,"paste",i);const s="input",n=l=>{this.editingCell!=null&&this.autoSize&&!isConsumed(l)&&(this.resizeThread!=null&&window.clearTimeout(this.resizeThread),this.resizeThread=window.setTimeout(()=>{this.resizeThread=null,this.resize()},0))};InternalEvent.addListener(t,s,n),InternalEvent.addListener(window,"resize",n),InternalEvent.addListener(t,"cut",n),InternalEvent.addListener(t,"paste",n)}isStopEditingEvent(t){return t.keyCode===113||this.graph.isEnterStopsCellEditing()&&t.keyCode===13&&!isControlDown(t)&&!isShiftDown(t)}isEventSource(t){return getSource(t)===this.textarea}resize(){const t=this.editingCell?this.graph.getView().getState(this.editingCell):null;if(!t)this.stopEditing(!0);else if(this.textarea!=null){const e=t.cell.isEdge(),{scale:i}=this.graph.getView();let s=null;if(!this.autoSize||t.style.overflow==="fill")this.bounds=this.getEditorBounds(t),this.textarea.style.width=`${Math.round(this.bounds.width/i)}px`,this.textarea.style.height=`${Math.round(this.bounds.height/i)}px`,this.textarea.style.left=`${Math.max(0,Math.round(this.bounds.x+1))}px`,this.textarea.style.top=`${Math.max(0,Math.round(this.bounds.y+1))}px`,this.graph.isWrapping(t.cell)&&(this.bounds.width>=2||this.bounds.height>=2)&&this.textarea.innerHTML!==this.getEmptyLabelText()?(this.textarea.style.wordWrap=WORD_WRAP,this.textarea.style.whiteSpace="normal",t.style.overflow!=="fill"&&(this.textarea.style.width=`${Math.round(this.bounds.width/i)+this.wordWrapPadding}px`)):(this.textarea.style.whiteSpace="nowrap",t.style.overflow!=="fill"&&(this.textarea.style.width=""));else{const n=t.style.labelWidth??null;if(s=t.text!=null&&this.align==null?t.text.margin:null,s==null&&(s=getAlignmentAsPoint(this.align??t.style.align??"center",t.style.verticalAlign??"middle")),e){if(this.bounds=new Rectangle(t.absoluteOffset.x,t.absoluteOffset.y,0,0),n!=null){const l=(n+2)*i;this.bounds.width=l,this.bounds.x+=s.x*l}}else{let l=Rectangle.fromRectangle(t),o=t.style.labelPosition??"center",a=t.style.verticalLabelPosition??"middle";if(l=t.shape!=null&&o==="center"&&a==="middle"?t.shape.getLabelBounds(l):l,n!=null&&(l.width=n*i),!t.view.graph.cellRenderer.legacySpacing||t.style.overflow!=="width"){const h=new TextShape,d=(t.style.spacing??2)*i,c=((t.style.spacingTop??0)+h.baseSpacingTop)*i+d,u=((t.style.spacingRight??0)+h.baseSpacingRight)*i+d,g=((t.style.spacingBottom??0)+h.baseSpacingBottom)*i+d,f=((t.style.spacingLeft??0)+h.baseSpacingLeft)*i+d;o=t.style.labelPosition!=null?t.style.labelPosition:"center",a=t.style.verticalLabelPosition!=null?t.style.verticalLabelPosition:"middle",l=new Rectangle(l.x+f,l.y+c,l.width-(o==="center"&&n==null?f+u:0),l.height-(a==="middle"?c+g:0))}this.bounds=new Rectangle(l.x+t.absoluteOffset.x,l.y+t.absoluteOffset.y,l.width,l.height)}if(this.graph.isWrapping(t.cell)&&(this.bounds.width>=2||this.bounds.height>=2)&&this.textarea.innerHTML!==this.getEmptyLabelText()){this.textarea.style.wordWrap=WORD_WRAP,this.textarea.style.whiteSpace="normal";const l=Math.round(this.bounds.width/i)+this.wordWrapPadding;this.textarea.style.position!=="relative"?(this.textarea.style.width=`${l}px`,this.textarea.scrollWidth>l&&(this.textarea.style.width=`${this.textarea.scrollWidth}px`)):this.textarea.style.maxWidth=`${l}px`}else this.textarea.style.whiteSpace="nowrap",this.textarea.style.width="";this.textarea.scrollWidth,this.textarea.scrollHeight,this.textarea.style.left=`${Math.max(0,Math.round(this.bounds.x-s.x*(this.bounds.width-2))+1)}px`,this.textarea.style.top=`${Math.max(0,Math.round(this.bounds.y-s.y*(this.bounds.height-4)+(s.y===-1?3:0))+1)}px`}setPrefixedStyle(this.textarea.style,"transformOrigin","0px 0px"),setPrefixedStyle(this.textarea.style,"transform",`scale(${i},${i})${s==null?"":` translate(${s.x*100}%,${s.y*100}%)`}`)}}focusLost(){this.stopEditing(!this.graph.isInvokesStopCellEditing())}getBackgroundColor(t){return NONE}startEditing(t,e=null){this.stopEditing(!0),this.align=null,this.textarea==null&&this.init();const i=this.graph.getPlugin("TooltipHandler");i==null||i.hideTooltip();const s=this.graph.getView().getState(t);if(s){const n=s.style,l=n.fontSize??StyleDefaultsConfig.fontSize,o=n.fontFamily??StyleDefaultsConfig.fontFamily,a=n.fontColor??"black",h=n.align??"left",d=n.fontStyle??0,c=matchBinaryMask(d,FONT_STYLE_MASK.BOLD),u=matchBinaryMask(d,FONT_STYLE_MASK.ITALIC),g=[];matchBinaryMask(d,FONT_STYLE_MASK.UNDERLINE)&&g.push("underline"),matchBinaryMask(d,FONT_STYLE_MASK.STRIKETHROUGH)&&g.push("line-through");const f=this.textarea,p=f.style;p.lineHeight=String(LINE_HEIGHT),p.backgroundColor=this.getBackgroundColor(s)||"transparent",p.textDecoration=g.join(" "),p.fontWeight=c?"bold":"normal",p.fontStyle=u?"italic":"",p.fontSize=`${Math.round(l)}px`,p.zIndex=String(this.zIndex),p.fontFamily=o,p.textAlign=h,p.outline="none",p.color=a;let y=this.textDirection=n.textDirection??DEFAULT_TEXT_DIRECTION;const v=s.text;y==="auto"&&v!==null&&v.dialect!=="strictHtml"&&!isNode(v.value)&&(y=v.getAutoDirection()),y==="ltr"||y==="rtl"?f.setAttribute("dir",y):f.removeAttribute("dir"),f.innerHTML=this.getInitialValue(s,e)||"",this.initialValue=f.innerHTML,f.innerHTML.length===0||f.innerHTML==="<br>"?(f.innerHTML=this.getEmptyLabelText(),this.clearOnChange=!0):this.clearOnChange=f.innerHTML===this.getEmptyLabelText(),this.graph.container.appendChild(f),this.editingCell=t,this.trigger=e,this.textNode=null,v!==null&&this.isHideLabel(s)&&(this.textNode=v.node,this.textNode.style.visibility="hidden"),this.autoSize&&(s.cell.isEdge()||n.overflow!=="fill")&&window.setTimeout(()=>{this.resize()},0),this.resize();try{f.focus(),this.isSelectText()&&f.innerHTML.length>0&&(f.innerHTML!==this.getEmptyLabelText()||!this.clearOnChange)&&document.execCommand("selectAll",!1)}catch{}}}isSelectText(){return this.selectText}stopEditing(t=!1){if(this.editingCell){this.textNode&&(this.textNode.style.visibility="visible",this.textNode=null);const e=t?null:this.graph.view.getState(this.editingCell),i=this.textarea,s=this.initialValue;if(this.initialValue=null,this.editingCell=null,this.bounds=null,i.blur(),clearSelection(),i.parentNode&&i.parentNode.removeChild(i),this.clearOnChange&&i.innerHTML===this.getEmptyLabelText()&&(i.innerHTML="",this.clearOnChange=!1),e&&(i.innerHTML!==s||this.align!==null)){this.prepareTextarea();const n=this.getCurrentValue(e);this.graph.batchUpdate(()=>{n!==null&&this.applyValue(e,n),this.align!==null&&this.graph.setCellStyles("align",this.align,[e.cell])})}this.trigger=null,this.textarea&&InternalEvent.release(this.textarea),this.textarea=null,this.align=null}}prepareTextarea(){const t=this.textarea;t.lastChild&&t.lastChild.nodeName==="BR"&&t.removeChild(t.lastChild)}isHideLabel(t=null){return!0}getMinimumSize(t){const{scale:e}=this.graph.getView(),i=this.textarea;return new Rectangle(0,0,t.text===null?30:t.text.size*e+20,i.style.textAlign==="left"?120:40)}getEditorBounds(t){const e=t.cell.isEdge(),{scale:i}=this.graph.getView(),s=this.getMinimumSize(t),n=s.width,l=s.height;let o=null;if(!e&&t.view.graph.cellRenderer.legacySpacing&&t.style.overflow==="fill")o=t.shape.getLabelBounds(Rectangle.fromRectangle(t));else{const a=new TextShape,h=(t.style.spacing??0)*i,d=((t.style.spacingTop??0)+a.baseSpacingTop)*i+h,c=((t.style.spacingRight??0)+a.baseSpacingRight)*i+h,u=((t.style.spacingBottom??0)+a.baseSpacingBottom)*i+h,g=((t.style.spacingLeft??0)+a.baseSpacingLeft)*i+h;o=new Rectangle(t.x,t.y,Math.max(n,t.width-g-c),Math.max(l,t.height-d-u));const f=t.style.labelPosition!=null?t.style.labelPosition:"center",p=t.style.verticalLabelPosition!=null?t.style.verticalLabelPosition:"middle";if(o=t.shape!=null&&f==="center"&&p==="middle"?t.shape.getLabelBounds(o):o,e?(o.x=t.absoluteOffset.x,o.y=t.absoluteOffset.y,t.text!=null&&t.text.boundingBox!=null&&(t.text.boundingBox.x>0&&(o.x=t.text.boundingBox.x),t.text.boundingBox.y>0&&(o.y=t.text.boundingBox.y))):t.text!=null&&t.text.boundingBox!=null&&(o.x=Math.min(o.x,t.text.boundingBox.x),o.y=Math.min(o.y,t.text.boundingBox.y)),o.x+=g,o.y+=d,t.text!=null&&t.text.boundingBox!=null&&(e?(o.width=Math.max(n,t.text.boundingBox.width),o.height=Math.max(l,t.text.boundingBox.height)):(o.width=Math.max(o.width,t.text.boundingBox.width),o.height=Math.max(o.height,t.text.boundingBox.height))),t.cell.isVertex()){const y=t.style.labelPosition??"center";y==="left"?o.x-=t.width:y==="right"&&(o.x+=t.width);const v=t.style.verticalLabelPosition!=null?t.style.verticalLabelPosition:"middle";v==="top"?o.y-=t.height:v==="bottom"&&(o.y+=t.height)}}return new Rectangle(Math.round(o.x),Math.round(o.y),Math.round(o.width),Math.round(o.height))}getEmptyLabelText(t=null){return this.emptyLabelText??""}getEditingCell(){return this.editingCell}onDestroy(){this.textarea&&(InternalEvent.release(this.textarea),this.textarea.parentNode&&this.textarea.parentNode.removeChild(this.textarea),this.textarea=null),this.graph.getDataModel().removeListener(this.changeHandler),this.graph.getView().removeListener(this.zoomHandler)}}CellEditorHandler.pluginId="CellEditorHandler";class TooltipHandler{init(){document.body&&(this.div=document.createElement("div"),this.div.className="mxTooltip",this.div.style.visibility="hidden",document.body.appendChild(this.div),InternalEvent.addGestureListeners(this.div,t=>{const e=getSource(t);e&&e.nodeName!=="A"&&this.hideTooltip()}),InternalEvent.addListener(this.graph.getContainer(),"mouseleave",t=>{this.div!==t.relatedTarget&&this.hide()}))}constructor(t){this.zIndex=10005,this.delay=500,this.ignoreTouchEvents=!0,this.hideOnHover=!1,this.destroyed=!1,this.lastX=0,this.lastY=0,this.state=null,this.stateSource=!1,this.thread=null,this.enabled=!1,this.graph=t,this.graph.addMouseListener(this)}isEnabled(){return this.enabled}setEnabled(t){this.enabled=t}isHideOnHover(){return this.hideOnHover}setHideOnHover(t){this.hideOnHover=t}getStateForEvent(t){return t.getState()}mouseDown(t,e){this.reset(e,!1),this.hideTooltip()}mouseMove(t,e){if(e.getX()!==this.lastX||e.getY()!==this.lastY){this.reset(e,!0);const i=this.getStateForEvent(e);(this.isHideOnHover()||i!==this.state||e.getSource()!==this.node&&(!this.stateSource||i!=null&&this.stateSource===(e.isSource(i.shape)||!e.isSource(i.text))))&&this.hideTooltip()}this.lastX=e.getX(),this.lastY=e.getY()}mouseUp(t,e){this.reset(e,!0),this.hideTooltip()}resetTimer(){this.thread&&(window.clearTimeout(this.thread),this.thread=null)}reset(t,e,i=null){if((!this.ignoreTouchEvents||isMouseEvent(t.getEvent()))&&(this.resetTimer(),i=i??this.getStateForEvent(t),e&&this.isEnabled()&&i&&(!this.div||this.div.style.visibility=="hidden"))){const s=t.getSource(),n=t.getX(),l=t.getY(),o=t.isSource(i.shape)||t.isSource(i.text),a=this.graph.getPlugin("PopupMenuHandler");this.thread=window.setTimeout(()=>{if(i&&s&&!this.graph.isEditing()&&!(a!=null&&a.isMenuShowing())&&!this.graph.isMouseDown){const h=this.getTooltip(i,s,n,l);this.show(h,n,l),this.state=i,this.node=s,this.stateSource=o}},this.delay)}}hide(){this.resetTimer(),this.hideTooltip()}hideTooltip(){this.div&&(this.div.style.visibility="hidden",this.div.innerHTML="")}show(t,e,i){if(!this.destroyed&&t&&t!==""){const s=getScrollOrigin();this.div||this.init(),this.div.style.zIndex=String(this.zIndex),this.div.style.left=`${e+s.x}px`,this.div.style.top=`${i+TOOLTIP_VERTICAL_OFFSET+s.y}px`,isNode(t)?(this.div.innerHTML="",this.div.appendChild(t)):this.div.innerHTML=t.replace(/\n/g,"<br>"),this.div.style.visibility="",fit(this.div)}}onDestroy(){var t;this.destroyed||(this.resetTimer(),this.graph.removeMouseListener(this),this.div&&InternalEvent.release(this.div),(t=this.div)!=null&&t.parentNode&&this.div.parentNode.removeChild(this.div),this.destroyed=!0,this.div=null)}getTooltip(t,e,i,s){let n=null;if(t.control&&(e===t.control.node||e.parentNode===t.control.node)&&(n=this.graph.getCollapseExpandResource(),n=htmlEntities(translate(n)||n,!0).replace(/\\n/g,"<br>")),!n&&t.overlays&&t.overlays.forEach(l=>{!n&&(e===l.node||e.parentNode===l.node)&&(n=l.overlay?l.overlay.toString()??null:null)}),!n){const l=this.graph.getPlugin("SelectionCellsHandler"),o=l==null?void 0:l.getHandler(t.cell);o&&"getTooltipForNode"in o&&typeof o.getTooltipForNode=="function"&&(n=o.getTooltipForNode(e))}return n||(n=this.getTooltipForCell(t.cell)),n}getTooltipForCell(t){return t&&"getTooltip"in t&&typeof t.getTooltip=="function"?t.getTooltip():this.graph.convertValueToString(t)}}TooltipHandler.pluginId="TooltipHandler";class SelectionCellsHandler extends EventSource{constructor(t){super(),this.enabled=!0,this.maxHandlers=100,this.graph=t,this.handlers=new Map,this.graph.addMouseListener(this),this.refreshHandler=()=>{this.isEnabled()&&this.refresh()},this.graph.getSelectionModel().addListener(InternalEvent.CHANGE,this.refreshHandler),this.graph.getDataModel().addListener(InternalEvent.CHANGE,this.refreshHandler),this.graph.getView().addListener(InternalEvent.SCALE,this.refreshHandler),this.graph.getView().addListener(InternalEvent.TRANSLATE,this.refreshHandler),this.graph.getView().addListener(InternalEvent.SCALE_AND_TRANSLATE,this.refreshHandler),this.graph.getView().addListener(InternalEvent.DOWN,this.refreshHandler),this.graph.getView().addListener(InternalEvent.UP,this.refreshHandler)}isEnabled(){return this.enabled}setEnabled(t){this.enabled=t}getHandler(t){return this.handlers.get(t)}isHandled(t){return!!this.getHandler(t)}reset(){this.handlers.forEach(t=>{t.reset.apply(t)})}getHandledSelectionCells(){return this.graph.getSelectionCells()}refresh(){const t=this.handlers;this.handlers=new Map;const e=sortCells(this.getHandledSelectionCells(),!1);for(let i=0;i<e.length;i+=1){const s=this.graph.view.getState(e[i]);if(s){let n=t.get(e[i])??null;t.delete(e[i]),n&&(n.state!==s?(n.onDestroy(),n=null):this.isHandlerActive(n)||(n.refresh&&n.refresh(),n.redraw())),n&&this.handlers.set(e[i],n)}}t.forEach(i=>{this.fireEvent(new EventObject(InternalEvent.REMOVE,{state:i.state})),i.onDestroy()});for(let i=0;i<e.length;i+=1){const s=this.graph.view.getState(e[i]);if(s){let n=this.handlers.get(e[i]);n?n.updateParentHighlight():(n=this.graph.createHandler(s),this.fireEvent(new EventObject(InternalEvent.ADD,{state:s})),this.handlers.set(e[i],n))}}}isHandlerActive(t){return t.index!==null}updateHandler(t){let e=this.handlers.get(t.cell);if(this.handlers.delete(t.cell),e){const{index:i}=e,s=e.startX,n=e.startY;e.onDestroy(),e=this.graph.createHandler(t),e&&(this.handlers.set(t.cell,e),i!==null&&e.start(s,n,i))}}mouseDown(t,e){this.graph.isEnabled()&&this.isEnabled()&&this.handlers.forEach(i=>{i.mouseDown(t,e)})}mouseMove(t,e){this.graph.isEnabled()&&this.isEnabled()&&this.handlers.forEach(i=>{i.mouseMove(t,e)})}mouseUp(t,e){this.graph.isEnabled()&&this.isEnabled()&&this.handlers.forEach(i=>{i.mouseUp(t,e)})}onDestroy(){this.graph.removeMouseListener(this),this.graph.getSelectionModel().removeListener(this.refreshHandler),this.graph.getDataModel().removeListener(this.refreshHandler),this.graph.getView().removeListener(this.refreshHandler),super.destroy()}}SelectionCellsHandler.pluginId="SelectionCellsHandler";class MaxPopupMenu extends EventSource{constructor(t){super(),this.activeRow=null,this.eventReceiver=null,this.submenuImage=`${Client.imageBasePath}/submenu.gif`,this.zIndex=10006,this.useLeftButtonForPopup=!1,this.enabled=!0,this.itemCount=0,this.autoExpand=!1,this.smartSeparators=!1,this.labels=!0,this.willAddSeparator=!1,this.containsItems=!1,t&&(this.factoryMethod=t),this.table=document.createElement("table"),this.table.className="mxPopupMenu",this.tbody=document.createElement("tbody"),this.table.appendChild(this.tbody),this.div=document.createElement("div"),this.div.className="mxPopupMenu",this.div.style.display="inline",this.div.style.zIndex=String(this.zIndex),this.div.appendChild(this.table),InternalEvent.disableContextMenu(this.div)}isEnabled(){return this.enabled}setEnabled(t){this.enabled=t}isPopupTrigger(t){return t.isPopupTrigger()||this.useLeftButtonForPopup&&isLeftMouseButton(t.getEvent())}addItem(t,e,i,s=null,n=null,l=!0,o=!0,a=!1){var c;s=s??this,this.itemCount++,s.willAddSeparator&&(s.containsItems&&this.addSeparator(s,!0),s.willAddSeparator=!1),s.containsItems=!0;const h=document.createElement("tr");h.className="mxPopupMenuItem";const d=document.createElement("td");if(d.className="mxPopupMenuIcon",e){const u=document.createElement("img");u.src=e,d.appendChild(u)}else if(n){const u=document.createElement("div");u.className=n,d.appendChild(u)}if(h.appendChild(d),this.labels){const u=document.createElement("td");u.className=`mxPopupMenuItem${l?"":" mxDisabled"}`,write(u,t),u.align="left",h.appendChild(u);const g=document.createElement("td");g.className=`mxPopupMenuItem${l?"":" mxDisabled"}`,g.style.paddingRight="6px",g.style.textAlign="right",h.appendChild(g),s.div==null&&this.createSubmenu(s)}return(c=s.tbody)==null||c.appendChild(h),o&&l&&(InternalEvent.addGestureListeners(h,u=>{this.eventReceiver=h,s&&s.activeRow!=h&&s.activeRow!=s&&(s.activeRow&&s.activeRow.div.parentNode&&this.hideSubmenu(s),h.div&&(this.showSubmenu(s,h),s.activeRow=h)),InternalEvent.consume(u)},u=>{s&&s.activeRow!=h&&s.activeRow!=s&&(s.activeRow&&s.activeRow.div.parentNode&&this.hideSubmenu(s),this.autoExpand&&h.div&&(this.showSubmenu(s,h),s.activeRow=h)),a||(h.className="mxPopupMenuItemHover")},u=>{this.eventReceiver==h&&(s&&s.activeRow!=h&&this.hideMenu(),i==null||i(u)),this.eventReceiver=null,InternalEvent.consume(u)}),a||InternalEvent.addListener(h,"mouseout",u=>{h.className="mxPopupMenuItem"})),h}addCheckmark(t,e){if(t.firstChild){const i=t.firstChild.nextSibling;i.style.backgroundImage=`url('${e}')`,i.style.backgroundRepeat="no-repeat",i.style.backgroundPosition="2px 50%"}}createSubmenu(t){var i,s;t.table=document.createElement("table"),t.table.className="mxPopupMenu",t.tbody=document.createElement("tbody"),t.table.appendChild(t.tbody),t.div=document.createElement("div"),t.div.className="mxPopupMenu",t.div.style.position="absolute",t.div.style.display="inline",t.div.style.zIndex=String(this.zIndex),t.div.appendChild(t.table);const e=document.createElement("img");e.setAttribute("src",this.submenuImage),(s=(i=t.firstChild)==null?void 0:i.nextSibling)!=null&&s.nextSibling&&t.firstChild.nextSibling.nextSibling.appendChild(e)}showSubmenu(t,e){if(e.div){e.div.style.left=`${t.div.offsetLeft+e.offsetLeft+e.offsetWidth-1}px`,e.div.style.top=`${t.div.offsetTop+e.offsetTop}px`,document.body.appendChild(e.div);const i=e.div.offsetLeft,s=e.div.offsetWidth,n=getDocumentScrollOrigin(document),l=document.body,o=document.documentElement,a=n.x+(l.clientWidth||o.clientWidth);i+s>a&&(e.div.style.left=`${Math.max(0,t.div.offsetLeft-s-6)}px`),fit(e.div)}}addSeparator(t=null,e=!1){if(t=t||this,this.smartSeparators&&!e)t.willAddSeparator=!0;else if(t.tbody){t.willAddSeparator=!1;const i=document.createElement("tr"),s=document.createElement("td");s.className="mxPopupMenuIcon",s.style.padding="0 0 0 0px",i.appendChild(s);const n=document.createElement("td");n.style.padding="0 0 0 0px",n.setAttribute("colSpan","2");const l=document.createElement("hr");l.setAttribute("size","1"),n.appendChild(l),i.appendChild(n),t.tbody.appendChild(i)}}popup(t,e,i,s){if(this.div&&this.tbody&&this.factoryMethod){for(this.div.style.left=`${t}px`,this.div.style.top=`${e}px`;this.tbody.firstChild;)InternalEvent.release(this.tbody.firstChild),this.tbody.removeChild(this.tbody.firstChild);this.itemCount=0,this.factoryMethod(this,i,s),this.itemCount>0&&(this.showMenu(),this.fireEvent(new EventObject(InternalEvent.SHOW)))}}isMenuShowing(){return this.div&&this.div.parentNode==document.body}showMenu(){document.body.appendChild(this.div),fit(this.div)}hideMenu(){var t;this.div&&((t=this.div.parentNode)==null||t.removeChild(this.div),this.hideSubmenu(this),this.containsItems=!1,this.fireEvent(new EventObject(InternalEvent.HIDE)))}hideSubmenu(t){var e;t.activeRow&&(this.hideSubmenu(t.activeRow),(e=t.activeRow.div.parentNode)==null||e.removeChild(t.activeRow.div),t.activeRow=null)}destroy(){var t;this.div&&(InternalEvent.release(this.div),(t=this.div.parentNode)==null||t.removeChild(this.div)),super.destroy()}}class PopupMenuHandler extends MaxPopupMenu{constructor(t){super(),this.inTolerance=!1,this.popupTrigger=!1,this.selectOnPopup=!0,this.clearSelectionOnBackground=!0,this.triggerX=null,this.triggerY=null,this.screenX=null,this.screenY=null,this.graph=t,this.graph.addMouseListener(this),this.gestureHandler=(e,i)=>{this.inTolerance=!1},this.graph.addListener(InternalEvent.GESTURE,this.gestureHandler),this.init()}init(){InternalEvent.addGestureListeners(this.div,t=>{const e=this.graph.getPlugin("TooltipHandler");e==null||e.hide()})}isSelectOnPopup(t){return this.selectOnPopup}mouseDown(t,e){this.isEnabled()&&!isMultiTouchEvent(e.getEvent())&&(this.hideMenu(),this.triggerX=e.getGraphX(),this.triggerY=e.getGraphY(),this.screenX=getMainEvent(e.getEvent()).screenX,this.screenY=getMainEvent(e.getEvent()).screenY,this.popupTrigger=this.isPopupTrigger(e),this.inTolerance=!0)}mouseMove(t,e){this.inTolerance&&this.screenX!=null&&this.screenY!=null&&(Math.abs(getMainEvent(e.getEvent()).screenX-this.screenX)>this.graph.getEventTolerance()||Math.abs(getMainEvent(e.getEvent()).screenY-this.screenY)>this.graph.getEventTolerance())&&(this.inTolerance=!1)}mouseUp(t,e){if(this.popupTrigger&&this.inTolerance&&this.triggerX!=null&&this.triggerY!=null){const i=this.getCellForPopupEvent(e);this.graph.isEnabled()&&this.isSelectOnPopup(e)&&i!=null&&!this.graph.isCellSelected(i)?this.graph.setSelectionCell(i):this.clearSelectionOnBackground&&i==null&&this.graph.clearSelection();const s=this.graph.getPlugin("TooltipHandler");s==null||s.hide();const n=getScrollOrigin();this.popup(e.getX()+n.x+1,e.getY()+n.y+1,i,e.getEvent()),e.consume()}this.popupTrigger=!1,this.inTolerance=!1}getCellForPopupEvent(t){return t.getCell()}onDestroy(){this.graph.removeMouseListener(this),this.graph.removeListener(this.gestureHandler),super.destroy()}}PopupMenuHandler.pluginId="PopupMenuHandler";class ConnectionHandler extends EventSource{constructor(t,e=null){super(),this.previous=null,this.iconState=null,this.icons=[],this.cell=null,this.currentPoint=null,this.sourceConstraint=null,this.shape=null,this.icon=null,this.originalPoint=null,this.currentState=null,this.selectedIcon=null,this.waypoints=[],this.factoryMethod=null,this.moveIconFront=!1,this.moveIconBack=!1,this.connectImage=null,this.targetConnectImage=!1,this.enabled=!1,this.select=!0,this.createTarget=!1,this.error=null,this.waypointsEnabled=!1,this.ignoreMouseDown=!1,this.first=null,this.connectIconOffset=new Point(0,TOOLTIP_VERTICAL_OFFSET),this.edgeState=null,this.mouseDownCounter=0,this.movePreviewAway=!1,this.outlineConnect=!1,this.livePreview=!1,this.cursor=null,this.cursorConnect="pointer",this.insertBeforeSource=!1,this.graph=t,this.factoryMethod=e,this.graph.addMouseListener(this),this.marker=this.createMarker(),this.constraintHandler=this.createConstraintHandler(),this.changeHandler=i=>{this.iconState&&(this.iconState=this.graph.getView().getState(this.iconState.cell)),this.iconState?(this.redrawIcons(this.icons,this.iconState),this.constraintHandler.reset()):this.previous&&!this.graph.view.getState(this.previous.cell)&&this.reset()},this.graph.getDataModel().addListener(InternalEvent.CHANGE,this.changeHandler),this.graph.getView().addListener(InternalEvent.SCALE,this.changeHandler),this.graph.getView().addListener(InternalEvent.TRANSLATE,this.changeHandler),this.graph.getView().addListener(InternalEvent.SCALE_AND_TRANSLATE,this.changeHandler),this.drillHandler=i=>{this.reset()},this.graph.addListener(InternalEvent.START_EDITING,this.drillHandler),this.graph.getView().addListener(InternalEvent.DOWN,this.drillHandler),this.graph.getView().addListener(InternalEvent.UP,this.drillHandler),this.escapeHandler=()=>{this.reset()},this.graph.addListener(InternalEvent.ESCAPE,this.escapeHandler)}createConstraintHandler(){return new ConstraintHandler(this.graph)}isEnabled(){return this.enabled}setEnabled(t){this.enabled=t}isInsertBefore(t,e,i,s,n){return this.insertBeforeSource&&e!==i}isCreateTarget(t){return this.createTarget}setCreateTarget(t){this.createTarget=t}createShape(){const t=this.livePreview&&this.edgeState?this.graph.cellRenderer.createShape(this.edgeState):new PolylineShape([],INVALID_COLOR);return t&&t.node&&(t.dialect="svg",t.scale=this.graph.view.scale,t.pointerEvents=!1,t.isDashed=!0,t.init(this.graph.getView().getOverlayPane()),InternalEvent.redirectMouseEvents(t.node,this.graph,null)),t}isConnectableCell(t){return!0}createMarker(){return new ConnectionHandlerCellMarker(this.graph,this)}start(t,e,i,s){this.previous=t,this.first=new Point(e,i),this.edgeState=s??this.createEdgeState(),this.marker.currentColor=this.marker.validColor,this.marker.markedState=t,this.marker.mark(),this.fireEvent(new EventObject(InternalEvent.START,{state:this.previous}))}isConnecting(){return!!this.first&&!!this.shape}isValidSource(t,e){return this.graph.isValidSource(t)}isValidTarget(t){return!0}validateConnection(t,e){return this.isValidTarget(e)?this.graph.getEdgeValidationError(null,t,e):""}getConnectImage(t){return this.connectImage}isMoveIconToFrontForState(t){return t.text&&t.text.node.parentNode===this.graph.container?!0:this.moveIconFront}createIcons(t){const e=this.getConnectImage(t);if(e){this.iconState=t;const i=[],s=new Rectangle(0,0,e.width,e.height),n=new ImageShape(s,e.src,void 0,void 0,0);n.preserveImageAspect=!1,this.isMoveIconToFrontForState(t)?(n.dialect="strictHtml",n.init(this.graph.container)):(n.dialect="svg",n.init(this.graph.getView().getOverlayPane()),this.moveIconBack&&n.node.parentNode&&n.node.previousSibling&&n.node.parentNode.insertBefore(n.node,n.node.parentNode.firstChild)),n.node.style.cursor=this.cursorConnect;const l=()=>this.currentState??t,o=a=>{isConsumed(a)||(this.icon=n,this.graph.fireMouseEvent(InternalEvent.MOUSE_DOWN,new InternalMouseEvent(a,l())))};return InternalEvent.redirectMouseEvents(n.node,this.graph,l,o),i.push(n),this.redrawIcons(i,this.iconState),i}return[]}redrawIcons(t,e){if(t[0]&&t[0].bounds){const i=this.getIconPosition(t[0],e);t[0].bounds.x=i.x,t[0].bounds.y=i.y,t[0].redraw()}}getIconPosition(t,e){const{scale:i}=this.graph.getView();let s=e.getCenterX(),n=e.getCenterY();if(this.graph.isSwimlane(e.cell)){const l=this.graph.getStartSize(e.cell);s=l.width!==0?e.x+l.width*i/2:s,n=l.height!==0?e.y+l.height*i/2:n;const o=toRadians(e.style.rotation??0);if(o!==0){const a=Math.cos(o),h=Math.sin(o),d=new Point(e.getCenterX(),e.getCenterY()),c=getRotatedPoint(new Point(s,n),a,h,d);s=c.x,n=c.y}}return new Point(s-t.bounds.width/2,n-t.bounds.height/2)}destroyIcons(){for(let t=0;t<this.icons.length;t+=1)this.icons[t].destroy();this.icons=[],this.icon=null,this.selectedIcon=null,this.iconState=null}isStartEvent(t){return this.constraintHandler.currentFocus!==null&&this.constraintHandler.currentConstraint!==null||this.previous!==null&&this.error===null&&(this.icons.length===0||this.icon!==null)}mouseDown(t,e){if(this.mouseDownCounter+=1,this.isEnabled()&&this.graph.isEnabled()&&!e.isConsumed()&&!this.isConnecting()&&this.isStartEvent(e)){if(this.constraintHandler.currentConstraint&&this.constraintHandler.currentFocus&&this.constraintHandler.currentPoint?(this.sourceConstraint=this.constraintHandler.currentConstraint,this.previous=this.constraintHandler.currentFocus,this.first=this.constraintHandler.currentPoint.clone()):this.first=new Point(e.getGraphX(),e.getGraphY()),this.edgeState=this.createEdgeState(e),this.mouseDownCounter=1,this.waypointsEnabled&&!this.shape&&(this.waypoints=[],this.shape=this.createShape(),this.edgeState&&this.shape.apply(this.edgeState)),!this.previous&&this.edgeState&&this.edgeState.cell.geometry){const i=this.graph.getPointForEvent(e.getEvent());this.edgeState.cell.geometry.setTerminalPoint(i,!0)}this.fireEvent(new EventObject(InternalEvent.START,{state:this.previous})),e.consume()}this.selectedIcon=this.icon,this.icon=null}isImmediateConnectSource(t){return!this.graph.isCellMovable(t.cell)}createEdgeState(t){return null}isOutlineConnectEvent(t){if(!this.currentPoint)return!1;const e=getOffset(this.graph.container),i=t.getEvent(),s=getClientX(i),n=getClientY(i),l=document.documentElement,o=(window.pageXOffset||l.scrollLeft)-(l.clientLeft||0),a=(window.pageYOffset||l.scrollTop)-(l.clientTop||0),h=this.currentPoint.x-this.graph.container.scrollLeft+e.x-o,d=this.currentPoint.y-this.graph.container.scrollTop+e.y-a;return this.outlineConnect&&!isShiftDown(t.getEvent())&&(t.isSource(this.marker.highlight.shape)||isAltDown(t.getEvent())&&t.getState()!=null||this.marker.highlight.isHighlightAt(s,n)||(h!==s||d!==n)&&t.getState()==null&&this.marker.highlight.isHighlightAt(h,d))}updateCurrentState(t,e){if(this.constraintHandler.update(t,!this.first,!1,!this.first||t.isSource(this.marker.highlight.shape)?null:e),this.constraintHandler.currentFocus!=null&&this.constraintHandler.currentConstraint!=null)this.marker.highlight&&this.marker.highlight.state&&this.marker.highlight.state.cell===this.constraintHandler.currentFocus.cell&&this.marker.highlight.shape?this.marker.highlight.shape.stroke!=="transparent"&&(this.marker.highlight.shape.stroke="transparent",this.marker.highlight.repaint()):this.marker.markCell(this.constraintHandler.currentFocus.cell,"transparent"),this.previous&&(this.error=this.validateConnection(this.previous.cell,this.constraintHandler.currentFocus.cell),this.error||(this.currentState=this.constraintHandler.currentFocus),(this.error||this.currentState&&!this.isCellEnabled(this.currentState.cell))&&this.constraintHandler.reset());else{this.graph.isIgnoreTerminalEvent(t.getEvent())?(this.marker.reset(),this.currentState=null):(this.marker.process(t),this.currentState=this.marker.getValidState()),this.currentState!=null&&!this.isCellEnabled(this.currentState.cell)&&(this.constraintHandler.reset(),this.marker.reset(),this.currentState=null);const i=this.isOutlineConnectEvent(t);if(this.currentState!=null&&i){t.isSource(this.marker.highlight.shape)&&(e=new Point(t.getGraphX(),t.getGraphY()));const s=this.graph.getOutlineConstraint(e,this.currentState,t);this.constraintHandler.setFocus(t,this.currentState,!1),this.constraintHandler.currentConstraint=s,this.constraintHandler.currentPoint=e}if(this.outlineConnect&&this.marker.highlight!=null&&this.marker.highlight.shape!=null){const s=this.graph.view.scale;if(this.constraintHandler.currentConstraint!=null&&this.constraintHandler.currentFocus!=null)this.marker.highlight.shape.stroke=OUTLINE_HIGHLIGHT_COLOR,this.marker.highlight.shape.strokeWidth=OUTLINE_HIGHLIGHT_STROKEWIDTH/s/s,this.marker.highlight.repaint();else if(this.marker.hasValidState()){const n=t.getCell();n&&n.isConnectable()&&this.marker.getValidState()!==t.getState()?(this.marker.highlight.shape.stroke="transparent",this.currentState=null):this.marker.highlight.shape.stroke=VALID_COLOR,this.marker.highlight.shape.strokeWidth=HIGHLIGHT_STROKEWIDTH/s/s,this.marker.highlight.repaint()}}}}isCellEnabled(t){return!0}convertWaypoint(t){const e=this.graph.getView().getScale(),i=this.graph.getView().getTranslate();t.x=t.x/e-i.x,t.y=t.y/e-i.y}snapToPreview(t,e){if(!isAltDown(t.getEvent())&&this.previous){const i=this.graph.getGridSize()*this.graph.view.scale/2,s=this.sourceConstraint&&this.first?this.first:new Point(this.previous.getCenterX(),this.previous.getCenterY());Math.abs(s.x-t.getGraphX())<i&&(e.x=s.x),Math.abs(s.y-t.getGraphY())<i&&(e.y=s.y)}}mouseMove(t,e){if(!e.isConsumed()&&(this.ignoreMouseDown||this.first||!this.graph.isMouseDown)){!this.isEnabled()&&this.currentState&&(this.destroyIcons(),this.currentState=null);const i=this.graph.getView(),{scale:s}=i,n=i.translate;let l=new Point(e.getGraphX(),e.getGraphY());if(this.error=null,this.graph.isGridEnabledEvent(e.getEvent())&&(l=new Point((this.graph.snap(l.x/s-n.x)+n.x)*s,(this.graph.snap(l.y/s-n.y)+n.y)*s)),this.snapToPreview(e,l),this.currentPoint=l,(this.first||this.isEnabled()&&this.graph.isEnabled())&&(this.shape||!this.first||Math.abs(e.getGraphX()-this.first.x)>this.graph.getEventTolerance()||Math.abs(e.getGraphY()-this.first.y)>this.graph.getEventTolerance())&&this.updateCurrentState(e,l),this.first){let o=null,a=l;this.constraintHandler.currentConstraint&&this.constraintHandler.currentFocus&&this.constraintHandler.currentPoint?(o=this.constraintHandler.currentConstraint,a=this.constraintHandler.currentPoint.clone()):this.previous&&!this.graph.isIgnoreTerminalEvent(e.getEvent())&&isShiftDown(e.getEvent())&&(Math.abs(this.previous.getCenterX()-l.x)<Math.abs(this.previous.getCenterY()-l.y)?l.x=this.previous.getCenterX():l.y=this.previous.getCenterY());let h=this.first;if(this.selectedIcon&&this.selectedIcon.bounds){const d=this.selectedIcon.bounds.width,c=this.selectedIcon.bounds.height;if(this.currentState&&this.targetConnectImage){const u=this.getIconPosition(this.selectedIcon,this.currentState);this.selectedIcon.bounds.x=u.x,this.selectedIcon.bounds.y=u.y}else{const u=new Rectangle(e.getGraphX()+this.connectIconOffset.x,e.getGraphY()+this.connectIconOffset.y,d,c);this.selectedIcon.bounds=u}this.selectedIcon.redraw()}if(this.edgeState)this.updateEdgeState(a,o),a=this.edgeState.absolutePoints[this.edgeState.absolutePoints.length-1],h=this.edgeState.absolutePoints[0];else{if(this.currentState&&!this.constraintHandler.currentConstraint){const d=this.getTargetPerimeterPoint(this.currentState,e);d!=null&&(a=d)}if(!this.sourceConstraint&&this.previous){const d=this.waypoints.length>0?this.waypoints[0]:a,c=this.getSourcePerimeterPoint(this.previous,d,e);c&&(h=c)}}if(!this.currentState&&this.movePreviewAway&&a){let d=h;if(this.edgeState&&this.edgeState.absolutePoints.length>=2){const c=this.edgeState.absolutePoints[this.edgeState.absolutePoints.length-2];c&&(d=c)}if(d){const c=a.x-d.x,u=a.y-d.y,g=Math.sqrt(c*c+u*u);if(g===0)return;this.originalPoint=a.clone(),a.x-=c*4/g,a.y-=u*4/g}}else this.originalPoint=null;if(!this.shape){const d=Math.abs(e.getGraphX()-this.first.x),c=Math.abs(e.getGraphY()-this.first.y);(d>this.graph.getEventTolerance()||c>this.graph.getEventTolerance())&&(this.shape=this.createShape(),this.edgeState&&this.shape.apply(this.edgeState),this.updateCurrentState(e,l))}if(this.shape){if(this.edgeState)this.shape.points=this.edgeState.absolutePoints;else{let d=[h];this.waypoints.length>0&&(d=d.concat(this.waypoints)),d.push(a),this.shape.points=d}this.drawPreview()}this.cursor&&(this.graph.container.style.cursor=this.cursor),InternalEvent.consume(e.getEvent()),e.consume()}else!this.isEnabled()||!this.graph.isEnabled()?this.constraintHandler.reset():this.previous!==this.currentState&&!this.edgeState?(this.destroyIcons(),this.currentState&&!this.error&&!this.constraintHandler.currentConstraint&&(this.icons=this.createIcons(this.currentState),this.icons.length===0&&(this.currentState.setCursor(this.cursorConnect),e.consume())),this.previous=this.currentState):this.previous===this.currentState&&this.currentState!=null&&this.icons.length===0&&!this.graph.isMouseDown&&e.consume();if(!this.graph.isMouseDown&&this.currentState!=null&&this.icons!=null){let o=!1;const a=e.getSource();for(let h=0;h<this.icons.length&&!o;h+=1)o=a===this.icons[h].node||!!a&&a.parentNode===this.icons[h].node;o||this.updateIcons(this.currentState,this.icons,e)}}else this.constraintHandler.reset()}updateEdgeState(t,e){var s;if(!this.edgeState)return;(s=this.sourceConstraint)!=null&&s.point&&(this.edgeState.style.exitX=this.sourceConstraint.point.x,this.edgeState.style.exitY=this.sourceConstraint.point.y),e!=null&&e.point?(this.edgeState.style.entryX=e.point.x,this.edgeState.style.entryY=e.point.y):(delete this.edgeState.style.entryX,delete this.edgeState.style.entryY),this.edgeState.absolutePoints=[null,this.currentState!=null?null:t],this.sourceConstraint&&this.graph.view.updateFixedTerminalPoint(this.edgeState,this.previous,!0,this.sourceConstraint),this.currentState!=null&&(e==null&&(e=this.graph.getConnectionConstraint(this.edgeState,this.previous,!1)),this.edgeState.setAbsoluteTerminalPoint(null,!1),this.graph.view.updateFixedTerminalPoint(this.edgeState,this.currentState,!1,e));const i=[];for(let n=0;n<this.waypoints.length;n+=1){const l=this.waypoints[n].clone();this.convertWaypoint(l),i[n]=l}this.graph.view.updatePoints(this.edgeState,i,this.previous,this.currentState),this.graph.view.updateFloatingTerminalPoints(this.edgeState,this.previous,this.currentState)}getTargetPerimeterPoint(t,e){let i=null;const{view:s}=t,n=s.getPerimeterFunction(t);if(n&&this.previous&&this.edgeState){const l=this.waypoints.length>0?this.waypoints[this.waypoints.length-1]:new Point(this.previous.getCenterX(),this.previous.getCenterY()),o=n(s.getPerimeterBounds(t),this.edgeState,l,!1);o&&(i=o)}else i=new Point(t.getCenterX(),t.getCenterY());return i}getSourcePerimeterPoint(t,e,i){let s=null;const{view:n}=t,l=n.getPerimeterFunction(t),o=new Point(t.getCenterX(),t.getCenterY());if(l){const a=t.style.rotation??0,h=-a*(Math.PI/180);a!==0&&(e=getRotatedPoint(new Point(e.x,e.y),Math.cos(h),Math.sin(h),o));let d=l(n.getPerimeterBounds(t),t,e,!1);d&&(a!==0&&(d=getRotatedPoint(new Point(d.x,d.y),Math.cos(-h),Math.sin(-h),o)),s=d)}else s=o;return s}updateIcons(t,e,i){}isStopEvent(t){return!!t.getState()}addWaypointForEvent(t){if(!this.first)return;let e=convertPoint(this.graph.container,t.getX(),t.getY());const i=Math.abs(e.x-this.first.x),s=Math.abs(e.y-this.first.y);if(this.waypoints.length>0||this.mouseDownCounter>1&&(i>this.graph.getEventTolerance()||s>this.graph.getEventTolerance())){const{scale:l}=this.graph.view;e=new Point(this.graph.snap(t.getGraphX()/l)*l,this.graph.snap(t.getGraphY()/l)*l),this.waypoints.push(e)}}checkConstraints(t,e){return!t||!e||!t.point||!e.point||!t.point.equals(e.point)||t.dx!==e.dx||t.dy!==e.dy||t.perimeter!==e.perimeter}mouseUp(t,e){if(!e.isConsumed()&&this.isConnecting()){if(this.waypointsEnabled&&!this.isStopEvent(e)){this.addWaypointForEvent(e),e.consume();return}const i=this.sourceConstraint,s=this.constraintHandler.currentConstraint,n=this.previous?this.previous.cell:null;let l=null;this.constraintHandler.currentConstraint&&this.constraintHandler.currentFocus&&(l=this.constraintHandler.currentFocus.cell),!l&&this.currentState&&(l=this.currentState.cell),!this.error&&(!n||!l||n!==l||this.checkConstraints(i,s))?this.connect(n,l,e.getEvent(),e.getCell()):(this.previous!=null&&this.marker.validState!=null&&this.previous.cell===this.marker.validState.cell&&this.graph.selectCellForEvent(this.marker.validState.cell,e.getEvent()),this.error!=null&&this.error.length>0&&this.graph.validationAlert(this.error)),this.destroyIcons(),e.consume()}this.first!=null&&this.reset()}reset(){this.shape!=null&&(this.shape.destroy(),this.shape=null),this.cursor!=null&&this.graph.container!=null&&(this.graph.container.style.cursor=""),this.destroyIcons(),this.marker.reset(),this.constraintHandler.reset(),this.originalPoint=null,this.currentPoint=null,this.edgeState=null,this.previous=null,this.error=null,this.sourceConstraint=null,this.mouseDownCounter=0,this.first=null,this.fireEvent(new EventObject(InternalEvent.RESET))}drawPreview(){this.updatePreview(this.error===null),this.shape&&this.shape.redraw()}updatePreview(t){this.shape&&(this.shape.strokeWidth=this.getEdgeWidth(t),this.shape.stroke=this.getEdgeColor(t))}getEdgeColor(t){return t?VALID_COLOR:INVALID_COLOR}getEdgeWidth(t){return t?3:1}connect(t,e,i,s=null){var n,l,o,a;if(e||this.isCreateTarget(i)||this.graph.isAllowDanglingEdges()){const h=this.graph.getDataModel();let d=!1,c=null;h.beginUpdate();try{if(t&&!e&&!this.graph.isIgnoreTerminalEvent(i)&&this.isCreateTarget(i)&&(e=this.createTargetVertex(i,t),e)){if(s=this.graph.getDropTarget([e],i,s),d=!0,s==null||!s.isEdge()){const p=s?this.graph.getView().getState(s):null;if(p){const y=e.getGeometry();y&&(y.x-=p.origin.x,y.y-=p.origin.y)}}else s=this.graph.getDefaultParent();this.graph.addCell(e,s)}let u=this.graph.getDefaultParent();t&&e&&t.getParent()===e.getParent()&&((n=t.getParent())==null?void 0:n.getParent())!==h.getRoot()&&(u=t.getParent(),t.geometry&&t.geometry.relative&&e.geometry&&e.geometry.relative&&(u=u.getParent()));let g=null,f={};if((l=this.edgeState)!=null&&l.cell&&(g=this.edgeState.cell.value,f=this.edgeState.cell.style??{}),c=this.insertEdge(u,"",g,t,e,f),c&&t){if(this.graph.setConnectionConstraint(c,t,!0,this.sourceConstraint),this.graph.setConnectionConstraint(c,e,!1,this.constraintHandler.currentConstraint),(a=(o=this.edgeState)==null?void 0:o.cell)!=null&&a.geometry&&h.setGeometry(c,this.edgeState.cell.geometry),u=t.getParent(),this.isInsertBefore(c,t,e,i,s)){let v=t;for(;v&&v.parent!=null&&v.geometry!=null&&v.geometry.relative&&v.parent!==c.parent;)v=v.getParent();v!=null&&v.parent!=null&&v.parent===c.parent&&h.add(u,c,v.parent.getIndex(v))}let p=c.getGeometry();if(p==null&&(p=new Geometry,p.relative=!0,h.setGeometry(c,p)),this.waypoints.length>0){const y=this.graph.view.scale,v=this.graph.view.translate;p.points=[];for(let S=0;S<this.waypoints.length;S+=1){const w=this.waypoints[S];p.points.push(new Point(w.x/y-v.x,w.y/y-v.y))}}if(!e&&this.currentPoint){const y=this.graph.view.translate,v=this.graph.view.scale,S=this.originalPoint!=null?new Point(this.originalPoint.x/v-y.x,this.originalPoint.y/v-y.y):new Point(this.currentPoint.x/v-y.x,this.currentPoint.y/v-y.y);S.x-=this.graph.getPanDx()/this.graph.view.scale,S.y-=this.graph.getPanDy()/this.graph.view.scale,p.setTerminalPoint(S,!1)}this.fireEvent(new EventObject(InternalEvent.CONNECT,"cell",c,"terminal",e,"event",i,"target",s,"terminalInserted",d))}}catch(u){log().show();const g=`Error in ConnectionHandler: ${u instanceof Error?u.message+`
|
|
12
|
-
`+u.stack:"unknown cause"}`;log().debug(g)}finally{h.endUpdate()}this.select&&this.selectCells(c,d?e:null)}}selectCells(t,e){this.graph.setSelectionCell(t)}insertEdge(t,e,i,s,n,l){if(!this.factoryMethod)return this.graph.insertEdge({parent:t,id:e,value:i,source:s,target:n,style:l});let o=this.createEdge(i,s,n,l);return o=this.graph.addEdge(o,t,s,n),o}createTargetVertex(t,e){let i=e.getGeometry();for(;i&&i.relative;)e=e.getParent(),i=e.getGeometry();const s=this.graph.cloneCell(e);if(i=s.getGeometry(),i&&this.currentPoint){const n=this.graph.view.translate,l=this.graph.view.scale,o=new Point(this.currentPoint.x/l-n.x,this.currentPoint.y/l-n.y);i.x=Math.round(o.x-i.width/2-this.graph.getPanDx()/l),i.y=Math.round(o.y-i.height/2-this.graph.getPanDy()/l);const a=this.getAlignmentTolerance();if(a>0){const h=this.graph.view.getState(e);if(h!=null){const d=h.x/l-n.x,c=h.y/l-n.y;Math.abs(d-i.x)<=a&&(i.x=Math.round(d)),Math.abs(c-i.y)<=a&&(i.y=Math.round(c))}}}return s}getAlignmentTolerance(t){return this.graph.isGridEnabled()?this.graph.getGridSize()/2:this.graph.getSnapTolerance()}createEdge(t,e,i,s={}){let n=null;if(this.factoryMethod!=null&&(n=this.factoryMethod(e,i,s)),n==null){n=new Cell(t||""),n.setEdge(!0),n.setStyle(s);const l=new Geometry;l.relative=!0,n.setGeometry(l)}return n}onDestroy(){this.graph.removeMouseListener(this),this.shape&&(this.shape.destroy(),this.shape=null),this.marker&&(this.marker.destroy(),this.marker=null),this.constraintHandler&&this.constraintHandler.onDestroy(),this.changeHandler&&(this.graph.getDataModel().removeListener(this.changeHandler),this.graph.getView().removeListener(this.changeHandler)),this.drillHandler&&(this.graph.removeListener(this.drillHandler),this.graph.getView().removeListener(this.drillHandler)),this.escapeHandler&&this.graph.removeListener(this.escapeHandler)}}ConnectionHandler.pluginId="ConnectionHandler";class ConnectionHandlerCellMarker extends CellMarker{constructor(t,e,i=VALID_COLOR,s=DEFAULT_INVALID_COLOR,n=DEFAULT_HOTSPOT){super(t,i,s,n),this.hotspotEnabled=!0,this.connectionHandler=e}getCell(t){let e=super.getCell(t);if(this.connectionHandler.error=null,!e&&this.connectionHandler.currentPoint&&(e=this.connectionHandler.graph.getCellAt(this.connectionHandler.currentPoint.x,this.connectionHandler.currentPoint.y)),e&&!e.isConnectable()&&this.connectionHandler.cell){const i=this.connectionHandler.cell.getParent();i&&i.isVertex()&&i.isConnectable()&&(e=i)}return e&&(this.connectionHandler.graph.isSwimlane(e)&&this.connectionHandler.currentPoint!=null&&this.connectionHandler.graph.hitsSwimlaneContent(e,this.connectionHandler.currentPoint.x,this.connectionHandler.currentPoint.y)||!this.connectionHandler.isConnectableCell(e))&&(e=null),e?this.connectionHandler.isConnecting()?this.connectionHandler.previous&&(this.connectionHandler.error=this.connectionHandler.validateConnection(this.connectionHandler.previous.cell,e),this.connectionHandler.error!==null&&this.connectionHandler.error.length===0&&(e=null,this.connectionHandler.isCreateTarget(t.getEvent())&&(this.connectionHandler.error=null))):this.connectionHandler.isValidSource(e,t)||(e=null):this.connectionHandler.isConnecting()&&!this.connectionHandler.isCreateTarget(t.getEvent())&&!this.connectionHandler.graph.isAllowDanglingEdges()&&(this.connectionHandler.error=""),e}isValidState(t){return this.connectionHandler.isConnecting()?!this.connectionHandler.error:super.isValidState(t)}getMarkerColor(t,e,i){return!this.connectionHandler.connectImage||this.connectionHandler.isConnecting()?super.getMarkerColor(t,e,i):NONE}intersects(t,e){return this.connectionHandler.connectImage||this.connectionHandler.isConnecting()?!0:super.intersects(t,e)}}class Guide{constructor(t,e){this.states=[],this.horizontal=!0,this.vertical=!0,this.guideX=null,this.guideY=null,this.rounded=!1,this.tolerance=2,this.graph=t,this.setStates(e)}setStates(t){this.states=t}isEnabledForEvent(t){return!0}getGuideTolerance(t=!1){return t&&this.graph.isGridEnabled()?this.graph.getGridSize()/2:this.tolerance}createGuideShape(t=!1){const e=new PolylineShape([],GUIDE_COLOR,GUIDE_STROKEWIDTH);return e.isDashed=!0,e}isStateIgnored(t){return!1}move(t=null,e,i=!1,s=!1){if((this.horizontal||this.vertical)&&t){const{scale:n}=this.graph.getView(),l=this.getGuideTolerance(i)*n,o=t.clone();o.x+=e.x,o.y+=e.y;let a=!1,h=null,d=null,c=!1,u=null,g=null,f=l,p=l;const y=o.x,v=o.x+o.width,S=o.getCenterX(),w=o.y,C=o.y+o.height,m=o.getCenterY(),M=(R,H,T)=>{let U=!1;T&&Math.abs(R-S)<f?(e.x=R-t.getCenterX(),f=Math.abs(R-S),U=!0):T||(Math.abs(R-y)<f?(e.x=R-t.x,f=Math.abs(R-y),U=!0):Math.abs(R-v)<f&&(e.x=R-t.x-t.width,f=Math.abs(R-v),U=!0)),U&&(h=H,d=R,this.guideX||(this.guideX=this.createGuideShape(!0),this.guideX.dialect="svg",this.guideX.pointerEvents=!1,this.guideX.init(this.graph.getView().getOverlayPane()))),a=a||U},b=(R,H,T)=>{let U=!1;T&&Math.abs(R-m)<p?(e.y=R-t.getCenterY(),p=Math.abs(R-m),U=!0):T||(Math.abs(R-w)<p?(e.y=R-t.y,p=Math.abs(R-w),U=!0):Math.abs(R-C)<p&&(e.y=R-t.y-t.height,p=Math.abs(R-C),U=!0)),U&&(u=H,g=R,this.guideY||(this.guideY=this.createGuideShape(!1),this.guideY.dialect="svg",this.guideY.pointerEvents=!1,this.guideY.init(this.graph.getView().getOverlayPane()))),c=c||U};for(let R=0;R<this.states.length;R+=1){const H=this.states[R];H&&!this.isStateIgnored(H)&&(this.horizontal&&(M(H.getCenterX(),H,!0),M(H.x,H,!1),M(H.x+H.width,H,!1),H.cell||M(H.getCenterX(),H,!1)),this.vertical&&(b(H.getCenterY(),H,!0),b(H.y,H,!1),b(H.y+H.height,H,!1),H.cell||b(H.getCenterY(),H,!1)))}this.graph.snapDelta(e,t,!i,a,c),e=this.getDelta(t,h,e.x,u,e.y);const O=this.graph.container;if(!a&&this.guideX)this.guideX.node.style.visibility="hidden";else if(this.guideX){let R=null,H=null;h&&(R=Math.min(t.y+e.y-this.graph.getPanDy(),h.y),H=Math.max(t.y+t.height+e.y-this.graph.getPanDy(),h.y+h.height)),R!==null&&H!==null?this.guideX.points=[new Point(d,R),new Point(d,H)]:this.guideX.points=[new Point(d,-this.graph.getPanDy()),new Point(d,O.scrollHeight-3-this.graph.getPanDy())],this.guideX.stroke=this.getGuideColor(h,!0),this.guideX.node.style.visibility="visible",this.guideX.redraw()}if(!c&&this.guideY!=null)this.guideY.node.style.visibility="hidden";else if(this.guideY!=null){let R=null,H=null;u!=null&&t!=null&&(R=Math.min(t.x+e.x-this.graph.getPanDx(),u.x),H=Math.max(t.x+t.width+e.x-this.graph.getPanDx(),u.x+u.width)),R!=null&&H!=null&&g!==null?this.guideY.points=[new Point(R,g),new Point(H,g)]:g!==null&&(this.guideY.points=[new Point(-this.graph.getPanDx(),g),new Point(O.scrollWidth-3-this.graph.getPanDx(),g)]),this.guideY.stroke=this.getGuideColor(u,!1),this.guideY.node.style.visibility="visible",this.guideY.redraw()}}return e}getDelta(t,e=null,i,s=null,n){const l=this.graph.view.scale;return(this.rounded||e!=null&&e.cell==null)&&(i=Math.round((t.x+i)/l)*l-t.x),(this.rounded||s!=null&&s.cell==null)&&(n=Math.round((t.y+n)/l)*l-t.y),new Point(i,n)}getGuideColor(t,e){return GUIDE_COLOR}hide(){this.setVisible(!1)}setVisible(t){this.guideX&&(this.guideX.node.style.visibility=t?"visible":"hidden"),this.guideY&&(this.guideY.node.style.visibility=t?"visible":"hidden")}destroy(){this.guideX&&(this.guideX.destroy(),this.guideX=null),this.guideY&&(this.guideY.destroy(),this.guideY=null)}}class SelectionHandler{constructor(t){this.refreshThread=null,this.maxCells=50,this.enabled=!0,this.highlightEnabled=!0,this.cloneEnabled=!0,this.moveEnabled=!0,this.guidesEnabled=!1,this.handlesVisible=!0,this.guide=null,this.currentDx=0,this.currentDy=0,this.updateCursor=!0,this.selectEnabled=!0,this.removeCellsFromParent=!0,this.removeEmptyParents=!1,this.connectOnDrop=!1,this.scrollOnMove=!0,this.minimumSize=6,this.previewColor="black",this.htmlPreview=!1,this.shape=null,this.scaleGrid=!1,this.rotationEnabled=!0,this.maxLivePreview=0,this.allowLivePreview=Client.IS_SVG,this.cell=null,this.delayedSelection=!1,this.first=null,this.cells=null,this.bounds=null,this.pBounds=null,this.allCells=new Map,this.cellWasClicked=!1,this.cloning=!1,this.cellCount=0,this.target=null,this.suspended=!1,this.livePreviewActive=!1,this.livePreviewUsed=!1,this.highlight=null,this.graph=t,this.graph.addMouseListener(this),this.panHandler=()=>{this.suspended||(this.updatePreview(),this.updateHint())},this.graph.addListener(InternalEvent.PAN,this.panHandler),this.escapeHandler=(e,i)=>{this.reset()},this.graph.addListener(InternalEvent.ESCAPE,this.escapeHandler),this.refreshHandler=(e,i)=>{this.refreshThread&&window.clearTimeout(this.refreshThread),this.refreshThread=window.setTimeout(()=>{var s;if(this.refreshThread=null,this.first&&!this.suspended&&this.cells){const n=this.currentDx,l=this.currentDy;this.currentDx=0,this.currentDy=0,this.updatePreview(),this.bounds=this.graph.getView().getBounds(this.cells),this.pBounds=this.getPreviewBounds(this.cells),this.pBounds==null&&!this.livePreviewUsed?this.reset():(this.currentDx=n,this.currentDy=l,this.updatePreview(),this.updateHint(),this.livePreviewUsed&&(this.setHandlesVisibleForCells(((s=this.getSelectionCellsHandler())==null?void 0:s.getHandledSelectionCells())??[],!1,!0),this.updatePreview()))}},0)},this.graph.getDataModel().addListener(InternalEvent.CHANGE,this.refreshHandler),this.graph.addListener(InternalEvent.REFRESH,this.refreshHandler),this.keyHandler=e=>{if(this.graph.container!=null&&this.graph.container.style.visibility!=="hidden"&&this.first!=null&&!this.suspended){const i=this.graph.isCloneEvent(e)&&this.graph.isCellsCloneable()&&this.isCloneEnabled();i!==this.cloning&&(this.cloning=i,this.checkPreview(),this.updatePreview())}},typeof document<"u"&&(InternalEvent.addListener(document,"keydown",this.keyHandler),InternalEvent.addListener(document,"keyup",this.keyHandler))}isEnabled(){return this.enabled}setEnabled(t){this.enabled=t}isCloneEnabled(){return this.cloneEnabled}setCloneEnabled(t){this.cloneEnabled=t}isMoveEnabled(){return this.moveEnabled}setMoveEnabled(t){this.moveEnabled=t}isSelectEnabled(){return this.selectEnabled}setSelectEnabled(t){this.selectEnabled=t}isRemoveCellsFromParent(){return this.removeCellsFromParent}setRemoveCellsFromParent(t){this.removeCellsFromParent=t}isPropagateSelectionCell(t,e,i){const s=t.getParent();if(e){const n=t.isEdge()?null:t.getGeometry();return!this.graph.isSiblingSelected(t)&&n&&n.relative||!this.graph.isSwimlane(s)}return(!this.graph.isToggleEvent(i.getEvent())||!this.graph.isSiblingSelected(t)&&!this.graph.isCellSelected(t)&&!this.graph.isSwimlane(s)||this.graph.isCellSelected(s))&&(this.graph.isToggleEvent(i.getEvent())||!this.graph.isCellSelected(s))}getInitialCellForEvent(t){let e=t.getState();if((!this.graph.isToggleEvent(t.getEvent())||!isAltDown(t.getEvent()))&&e&&!this.graph.isCellSelected(e.cell)){let i=e.cell.getParent(),s=i?this.graph.view.getState(i):null;for(;s&&!this.graph.isCellSelected(s.cell)&&(s.cell.isVertex()||s.cell.isEdge())&&this.isPropagateSelectionCell(e.cell,!0,t);)e=s,i=e.cell.getParent(),s=i?this.graph.view.getState(i):null}return e?e.cell:null}isDelayedSelection(t,e){let i=t;const s=this.getSelectionCellsHandler();if(!this.graph.isToggleEvent(e.getEvent())||!isAltDown(e.getEvent()))for(;i;){if(s!=null&&s.isHandled(i)){const n=this.graph.getPlugin("CellEditorHandler");return(n==null?void 0:n.getEditingCell())!==i}i=i.getParent()}return this.graph.isToggleEvent(e.getEvent())&&!isAltDown(e.getEvent())}selectDelayed(t){const e=this.graph.getPlugin("PopupMenuHandler");if(!e||!e.isPopupTrigger(t)){let i=t.getCell();i===null&&(i=this.cell),i&&this.selectCellForEvent(i,t)}}selectCellForEvent(t,e){const i=this.graph.view.getState(t);if(i)if(e.isSource(i.control))this.graph.selectCellForEvent(t,e.getEvent());else{if(!this.graph.isToggleEvent(e.getEvent())||!isAltDown(e.getEvent())){let s=t.getParent();for(;s&&this.graph.view.getState(s)&&(s.isVertex()||s.isEdge())&&this.isPropagateSelectionCell(t,!1,e);)t=s,s=t.getParent()}this.graph.selectCellForEvent(t,e.getEvent())}return t}consumeMouseEvent(t,e){e.consume()}mouseDown(t,e){if(!e.isConsumed()&&this.isEnabled()&&this.graph.isEnabled()&&e.getState()&&!isMultiTouchEvent(e.getEvent())){const i=this.getInitialCellForEvent(e);if(i&&(this.delayedSelection=this.isDelayedSelection(i,e),this.cell=null,this.isSelectEnabled()&&!this.delayedSelection&&this.graph.selectCellForEvent(i,e.getEvent()),this.isMoveEnabled())){const s=i.getGeometry();s&&this.graph.isCellMovable(i)&&(!i.isEdge()||this.graph.getSelectionCount()>1||s.points&&s.points.length>0||!i.getTerminal(!0)||!i.getTerminal(!1)||this.graph.isAllowDanglingEdges()||this.graph.isCloneEvent(e.getEvent())&&this.graph.isCellsCloneable())?this.start(i,e.getX(),e.getY()):this.delayedSelection&&(this.cell=i),this.cellWasClicked=!0,this.consumeMouseEvent(InternalEvent.MOUSE_DOWN,e)}}}getGuideStates(){const t=this.graph.getDefaultParent(),e=i=>{const s=i.getGeometry();return!!this.graph.view.getState(i)&&i.isVertex()&&!!s&&!s.relative};return this.graph.view.getCellStates(t.filterDescendants(e))}getCells(t){return!this.delayedSelection&&this.graph.isCellMovable(t)?[t]:this.graph.getMovableCells(this.graph.getSelectionCells())}getPreviewBounds(t){const e=this.getBoundingBox(t);if(e){if(e.width=Math.max(0,e.width-1),e.height=Math.max(0,e.height-1),e.width<this.minimumSize){const i=this.minimumSize-e.width;e.x-=i/2,e.width=this.minimumSize}else e.x=Math.round(e.x),e.width=Math.ceil(e.width);if(e.height<this.minimumSize){const i=this.minimumSize-e.height;e.y-=i/2,e.height=this.minimumSize}else e.y=Math.round(e.y),e.height=Math.ceil(e.height)}return e}getBoundingBox(t){let e=null;if(t.length>0){for(let i=0;i<t.length;i+=1)if(t[i].isVertex()||t[i].isEdge()){const s=this.graph.view.getState(t[i]);if(s){let n=null;t[i].isVertex()&&s.shape&&s.shape.boundingBox&&(n=s.shape.boundingBox),n&&(e?e.add(n):e=Rectangle.fromRectangle(n))}}}return e}createPreviewShape(t){const e=new RectangleShape(t,NONE,this.previewColor);return e.isDashed=!0,this.htmlPreview?(e.dialect="strictHtml",e.init(this.graph.container)):(e.dialect="svg",e.init(this.graph.getView().getOverlayPane()),e.pointerEvents=!1,Client.IS_IOS&&(e.getSvgScreenOffset=()=>0)),e}createGuide(){return new Guide(this.graph,this.getGuideStates())}start(t,e,i,s){this.cell=t,this.first=convertPoint(this.graph.container,e,i),this.cells=s||this.getCells(this.cell),this.bounds=this.graph.getView().getBounds(this.cells),this.pBounds=this.getPreviewBounds(this.cells),this.cloning=!1,this.cellCount=0;for(let n=0;n<this.cells.length;n+=1)this.cellCount+=this.addStates(this.cells[n],this.allCells);if(this.guidesEnabled){this.guide=this.createGuide();const n=t.getParent(),l=n.getChildCount()<2,o=new Map,a=this.graph.getOpposites(this.graph.getEdges(this.cell),this.cell);for(let h=0;h<a.length;h+=1){const d=this.graph.view.getState(a[h]);d&&!o.get(d)&&o.set(d,!0)}this.guide.isStateIgnored=h=>{const d=h.cell.getParent();return!!h.cell&&(!this.cloning&&!!this.isCellMoving(h.cell)||h.cell!==(this.target||n)&&!l&&!o.get(h)&&(!this.target||this.target.getChildCount()>=2)&&d!==(this.target||n))}}}addStates(t,e){const i=this.graph.view.getState(t);let s=0;if(i&&!e.get(t)){e.set(t,i),s++;const n=t.getChildCount();for(let l=0;l<n;l+=1)s+=this.addStates(t.getChildAt(l),e)}return s}isCellMoving(t){return this.allCells.has(t)}useGuidesForEvent(t){return this.guide?this.guide.isEnabledForEvent(t.getEvent())&&!this.graph.isConstrainedEvent(t.getEvent()):!0}snap(t){const e=this.scaleGrid?this.graph.view.scale:1;return t.x=this.graph.snap(t.x/e)*e,t.y=this.graph.snap(t.y/e)*e,t}getDelta(t){const e=convertPoint(this.graph.container,t.getX(),t.getY());return this.first?new Point(e.x-this.first.x-this.graph.getPanDx(),e.y-this.first.y-this.graph.getPanDy()):new Point}updateHint(t){}removeHint(){}roundLength(t){return Math.round(t*100)/100}isValidDropTarget(t,e){return this.cell?this.cell.getParent()!==t:!1}checkPreview(){this.livePreviewActive&&this.cloning?(this.resetLivePreview(),this.livePreviewActive=!1):this.maxLivePreview>=this.cellCount&&!this.livePreviewActive&&this.allowLivePreview?(!this.cloning||!this.livePreviewActive)&&(this.livePreviewActive=!0,this.livePreviewUsed=!0):!this.livePreviewUsed&&!this.shape&&this.bounds&&(this.shape=this.createPreviewShape(this.bounds))}mouseMove(t,e){const{graph:i}=this;if(!e.isConsumed()&&i.isMouseDown&&this.cell&&this.first&&this.bounds&&!this.suspended){if(isMultiTouchEvent(e.getEvent())){this.reset();return}let s=this.getDelta(e);const n=i.getEventTolerance();if(this.shape||this.livePreviewActive||Math.abs(s.x)>n||Math.abs(s.y)>n){this.highlight||(this.highlight=new CellHighlight(this.graph,DROP_TARGET_COLOR,3));const l=i.isCloneEvent(e.getEvent())&&i.isCellsCloneable()&&this.isCloneEnabled(),o=i.isGridEnabledEvent(e.getEvent()),a=e.getCell();let h=!0,d=null;this.cloning=l,i.isDropEnabled()&&this.highlightEnabled&&this.cells&&(d=i.getDropTarget(this.cells,e.getEvent(),a,l));let c=d?i.getView().getState(d):null,u=!1;if(c&&(l||d&&this.isValidDropTarget(d,e)))this.target!==d&&(this.target=d,this.setHighlightColor(DROP_TARGET_COLOR)),u=!0;else if(this.target=null,this.connectOnDrop&&a&&this.cells&&this.cells.length===1&&a.isVertex()&&a.isConnectable()&&(c=i.getView().getState(a),c)){const f=i.getEdgeValidationError(null,this.cell,a)===null?VALID_COLOR:INVALID_CONNECT_TARGET_COLOR;this.setHighlightColor(f),u=!0}c&&u?this.highlight.highlight(c):this.highlight.hide(),this.guide&&this.useGuidesForEvent(e)?(s=this.guide.move(this.bounds,s,o,l),h=!1):s=this.graph.snapDelta(s,this.bounds,!o,!1,!1),this.guide&&h&&this.guide.hide(),i.isConstrainedEvent(e.getEvent())&&(Math.abs(s.x)>Math.abs(s.y)?s.y=0:s.x=0),this.checkPreview(),(this.currentDx!==s.x||this.currentDy!==s.y)&&(this.currentDx=s.x,this.currentDy=s.y,this.updatePreview())}this.updateHint(e),this.consumeMouseEvent(InternalEvent.MOUSE_MOVE,e),InternalEvent.consume(e.getEvent())}else if((this.isMoveEnabled()||this.isCloneEnabled())&&this.updateCursor&&!e.isConsumed()&&(e.getState()||e.sourceState)&&!i.isMouseDown){let s=i.getCursorForMouseEvent(e);const n=e.getCell();!s&&n&&i.isEnabled()&&i.isCellMovable(n)&&(n.isEdge()?s=EdgeHandlerConfig.cursorMovable:s=VertexHandlerConfig.cursorMovable),s&&e.sourceState&&e.sourceState.setCursor(s)}}updatePreview(t=!1){var e;this.livePreviewUsed&&!t?this.cells&&(this.setHandlesVisibleForCells(((e=this.getSelectionCellsHandler())==null?void 0:e.getHandledSelectionCells())??[],!1),this.updateLivePreview(this.currentDx,this.currentDy)):this.updatePreviewShape()}updatePreviewShape(){this.shape&&this.pBounds&&(this.shape.bounds=new Rectangle(Math.round(this.pBounds.x+this.currentDx),Math.round(this.pBounds.y+this.currentDy),this.pBounds.width,this.pBounds.height),this.shape.redraw())}updateLivePreview(t,e){if(!this.suspended){const i=[];if(this.allCells&&this.allCells.forEach(s=>{const n=s?this.graph.view.getState(s.cell):null;if(n!==s&&s&&(s.destroy(),n?this.allCells.set(s.cell,n):this.allCells.delete(s.cell),s=n),s){const l=s.clone();i.push([s,l]),s.shape&&(s.shape.originalPointerEvents===null&&(s.shape.originalPointerEvents=s.shape.pointerEvents),s.shape.pointerEvents=!1,s.text&&(s.text.originalPointerEvents===null&&(s.text.originalPointerEvents=s.text.pointerEvents),s.text.pointerEvents=!1)),s.cell.isVertex()&&(s.x+=t,s.y+=e,this.cloning?s.text&&(s.text.updateBoundingBox(),s.text.boundingBox&&(s.text.boundingBox.x+=t,s.text.boundingBox.y+=e),s.text.unrotatedBoundingBox&&(s.text.unrotatedBoundingBox.x+=t,s.text.unrotatedBoundingBox.y+=e)):(s.view.graph.cellRenderer.redraw(s,!0),s.view.invalidate(s.cell),s.invalid=!1,s.control&&s.control.node&&(s.control.node.style.visibility="hidden")))}}),i.length===0)this.reset();else{const s=this.graph.view.scale;for(let n=0;n<i.length;n+=1){const l=i[n][0];if(l.cell.isEdge()){const o=l.cell.getGeometry(),a=[];if(o&&o.points)for(let u=0;u<o.points.length;u++)o.points[u]&&a.push(new Point(o.points[u].x+t/s,o.points[u].y+e/s));let h=l.visibleSourceState,d=l.visibleTargetState;const c=i[n][1].absolutePoints;if(h==null||!this.isCellMoving(h.cell)){const u=c[0];u&&(l.setAbsoluteTerminalPoint(new Point(u.x+t,u.y+e),!0),h=null)}else l.view.updateFixedTerminalPoint(l,h,!0,this.graph.getConnectionConstraint(l,h,!0));if(d==null||!this.isCellMoving(d.cell)){const u=c[c.length-1];u&&(l.setAbsoluteTerminalPoint(new Point(u.x+t,u.y+e),!1),d=null)}else l.view.updateFixedTerminalPoint(l,d,!1,this.graph.getConnectionConstraint(l,d,!1));l.view.updatePoints(l,a,h,d),l.view.updateFloatingTerminalPoints(l,h,d),l.view.updateEdgeLabelOffset(l),l.invalid=!1,this.cloning||l.view.graph.cellRenderer.redraw(l,!0)}}this.graph.view.validate(),this.redrawHandles(i),this.resetPreviewStates(i)}}}redrawHandles(t){const e=this.getSelectionCellsHandler();for(let i=0;i<t.length;i+=1){const s=e==null?void 0:e.getHandler(t[i][0].cell);s==null||s.redraw(!0)}}resetPreviewStates(t){for(let e=0;e<t.length;e+=1)t[e][0].setState(t[e][1])}suspend(){this.suspended||(this.livePreviewUsed&&this.updateLivePreview(0,0),this.shape&&(this.shape.node.style.visibility="hidden"),this.guide&&this.guide.setVisible(!1),this.suspended=!0)}resume(){this.suspended&&(this.suspended=!1,this.livePreviewUsed&&(this.livePreviewActive=!0),this.shape&&(this.shape.node.style.visibility="visible"),this.guide&&this.guide.setVisible(!0))}resetLivePreview(){this.allCells.forEach(t=>{t.shape&&t.shape.originalPointerEvents!==null&&(t.shape.pointerEvents=t.shape.originalPointerEvents,t.shape.originalPointerEvents=null,t.shape.bounds=null,t.text&&t.text.originalPointerEvents!==null&&(t.text.pointerEvents=t.text.originalPointerEvents,t.text.originalPointerEvents=null)),t.control&&t.control.node&&t.control.node.style.visibility==="hidden"&&(t.control.node.style.visibility=""),this.cloning||t.text&&t.text.updateBoundingBox(),t.view.invalidate(t.cell)}),this.graph.view.validate()}setHandlesVisibleForCells(t,e,i=!1){if(i||this.handlesVisible!==e){this.handlesVisible=e;const s=this.getSelectionCellsHandler();for(let n=0;n<t.length;n+=1){const l=s==null?void 0:s.getHandler(t[n]);l&&(l.setHandlesVisible(e),e&&l.redraw())}}}setHighlightColor(t){this.highlight&&this.highlight.setHighlightColor(t)}mouseUp(t,e){if(!e.isConsumed())if(this.livePreviewUsed&&this.resetLivePreview(),this.cell&&this.first&&(this.shape||this.livePreviewUsed)&&isNumeric(this.currentDx)&&isNumeric(this.currentDy)){const{graph:i}=this,s=e.getCell();if(this.connectOnDrop&&!this.target&&s&&s.isVertex()&&s.isConnectable()&&i.isEdgeValid(null,this.cell,s)){const n=i.getPlugin("ConnectionHandler");n==null||n.connect(this.cell,s,e.getEvent())}else{const n=i.isCloneEvent(e.getEvent())&&i.isCellsCloneable()&&this.isCloneEnabled(),{scale:l}=i.getView(),o=this.roundLength(this.currentDx/l),a=this.roundLength(this.currentDy/l),h=this.target;h&&i.isSplitEnabled()&&this.cells&&i.isSplitTarget(h,this.cells,e.getEvent())?i.splitEdge(h,this.cells,null,o,a,e.getGraphX(),e.getGraphY()):this.cells&&this.moveCells(this.cells,o,a,n,this.target,e.getEvent())}}else this.isSelectEnabled()&&this.delayedSelection&&this.cell!=null&&this.selectDelayed(e);this.cellWasClicked&&this.consumeMouseEvent(InternalEvent.MOUSE_UP,e),this.reset()}reset(){var t;this.livePreviewUsed&&(this.resetLivePreview(),this.setHandlesVisibleForCells(((t=this.getSelectionCellsHandler())==null?void 0:t.getHandledSelectionCells())??[],!0)),this.destroyShapes(),this.removeHint(),this.delayedSelection=!1,this.livePreviewActive=!1,this.livePreviewUsed=!1,this.cellWasClicked=!1,this.suspended=!1,this.currentDx=0,this.currentDy=0,this.cellCount=0,this.cloning=!1,this.allCells.clear(),this.pBounds=null,this.target=null,this.first=null,this.cells=null,this.cell=null}shouldRemoveCellsFromParent(t,e,i){if(t.isVertex()){const s=this.graph.getView().getState(t);if(s){let n=convertPoint(this.graph.container,getClientX(i),getClientY(i));const l=toRadians(s.style.rotation??0);if(l!==0){const o=Math.cos(-l),a=Math.sin(-l),h=new Point(s.getCenterX(),s.getCenterY());n=getRotatedPoint(n,o,a,h)}return!contains(s,n.x,n.y)}}return!1}moveCells(t,e,i,s,n,l){if(!this.cell)return;s&&(t=this.graph.getCloneableCells(t));const o=this.cell.getParent();!n&&o&&this.isRemoveCellsFromParent()&&this.shouldRemoveCellsFromParent(o,t,l)&&(n=this.graph.getDefaultParent()),s=!!s&&!this.graph.isCellLocked(n||this.graph.getDefaultParent()),this.graph.batchUpdate(()=>{const a=[];if(!s&&n&&this.removeEmptyParents){const d=new Map;for(let c=0;c<t.length;c+=1)d.set(t[c],!0);for(let c=0;c<t.length;c+=1){const u=t[c].getParent();u&&!d.get(u)&&(d.set(u,!0),a.push(u))}}t=this.graph.moveCells(t,e,i,s,n,l);const h=[];for(let d=0;d<a.length;d+=1)this.shouldRemoveParent(a[d])&&h.push(a[d]);this.graph.removeCells(h,!1)}),s&&this.graph.setSelectionCells(t),this.isSelectEnabled()&&this.scrollOnMove&&this.graph.scrollCellToVisible(t[0])}shouldRemoveParent(t){const e=this.graph.view.getState(t);return e!=null&&(e.cell.isEdge()||e.cell.isVertex())&&this.graph.isCellDeletable(e.cell)&&e.cell.getChildCount()===0&&e.isTransparentState()}destroyShapes(){this.shape&&(this.shape.destroy(),this.shape=null),this.guide&&(this.guide.destroy(),this.guide=null),this.highlight&&(this.highlight.destroy(),this.highlight=null)}onDestroy(){this.graph.removeMouseListener(this),this.graph.removeListener(this.panHandler),this.graph.removeListener(this.escapeHandler),this.graph.getDataModel().removeListener(this.refreshHandler),this.graph.removeListener(this.refreshHandler),InternalEvent.removeListener(document,"keydown",this.keyHandler),InternalEvent.removeListener(document,"keyup",this.keyHandler),this.destroyShapes(),this.removeHint()}getSelectionCellsHandler(){return this.graph.getPlugin("SelectionCellsHandler")}}SelectionHandler.pluginId="SelectionHandler";class PanningManager{constructor(t){this.damper=1/6,this.delay=10,this.handleMouseOut=!0,this.border=0,this.thread=null,this.active=!1,this.tdx=0,this.tdy=0,this.t0x=0,this.t0y=0,this.dx=0,this.dy=0,this.scrollbars=!1,this.scrollLeft=0,this.scrollTop=0,this.thread=null,this.active=!1,this.tdx=0,this.tdy=0,this.t0x=0,this.t0y=0,this.dx=0,this.dy=0,this.scrollbars=!1,this.scrollLeft=0,this.scrollTop=0,this.mouseListener={mouseDown:()=>{},mouseMove:()=>{},mouseUp:()=>{this.active&&this.stop()}},t.addMouseListener(this.mouseListener),this.mouseUpListener=()=>{this.active&&this.stop()},InternalEvent.addListener(document,"mouseup",this.mouseUpListener);const e=()=>(this.scrollbars=hasScrollbars(t.container),this.scrollLeft=t.container.scrollLeft,this.scrollTop=t.container.scrollTop,window.setInterval(()=>{if(this.tdx-=this.dx,this.tdy-=this.dy,this.scrollbars){const i=-t.container.scrollLeft-Math.ceil(this.dx),s=-t.container.scrollTop-Math.ceil(this.dy);t.panGraph(i,s),t.setPanDx(this.scrollLeft-t.container.scrollLeft),t.setPanDy(this.scrollTop-t.container.scrollTop),t.fireEvent(new EventObject(InternalEvent.PAN))}else t.panGraph(this.getDx(),this.getDy())},this.delay));this.isActive=()=>this.active,this.getDx=()=>Math.round(this.tdx),this.getDy=()=>Math.round(this.tdy),this.start=()=>{this.t0x=t.view.translate.x,this.t0y=t.view.translate.y,this.active=!0},this.panTo=(i,s,n=0,l=0)=>{this.active||this.start(),this.scrollLeft=t.container.scrollLeft,this.scrollTop=t.container.scrollTop;const o=t.container;this.dx=i+n-o.scrollLeft-o.clientWidth,this.dx<0&&Math.abs(this.dx)<this.border?this.dx=this.border+this.dx:this.handleMouseOut?this.dx=Math.max(this.dx,0):this.dx=0,this.dx==0&&(this.dx=i-o.scrollLeft,this.dx>0&&this.dx<this.border?this.dx-=this.border:this.handleMouseOut?this.dx=Math.min(0,this.dx):this.dx=0),this.dy=s+l-o.scrollTop-o.clientHeight,this.dy<0&&Math.abs(this.dy)<this.border?this.dy=this.border+this.dy:this.handleMouseOut?this.dy=Math.max(this.dy,0):this.dy=0,this.dy==0&&(this.dy=s-o.scrollTop,this.dy>0&&this.dy<this.border?this.dy-=this.border:this.handleMouseOut?this.dy=Math.min(0,this.dy):this.dy=0),this.dx!=0||this.dy!=0?(this.dx*=this.damper,this.dy*=this.damper,this.thread==null&&(this.thread=e())):this.thread!=null&&(window.clearInterval(this.thread),this.thread=null)},this.stop=()=>{if(this.active)if(this.active=!1,this.thread!=null&&(window.clearInterval(this.thread),this.thread=null),this.tdx=0,this.tdy=0,this.scrollbars)t.setPanDx(0),t.setPanDy(0),t.fireEvent(new EventObject(InternalEvent.PAN));else{const i=t.getPanDx(),s=t.getPanDy();(i!=0||s!=0)&&(t.panGraph(0,0),t.view.setTranslate(this.t0x+i/t.view.scale,this.t0y+s/t.view.scale))}},this.destroy=()=>{this.stop(),t.removeMouseListener(this.mouseListener),InternalEvent.removeListener(document,"mouseup",this.mouseUpListener)}}}class PanningHandler extends EventSource{constructor(t){super(),this.getPanningManager=()=>this.panningManager,this.useLeftButtonForPanning=!1,this.usePopupTrigger=!0,this.ignoreCell=!1,this.previewEnabled=!0,this.useGrid=!1,this.panningEnabled=!1,this.pinchEnabled=!0,this.initialScale=0,this.maxScale=8,this.minScale=.01,this.dx=0,this.dy=0,this.startX=0,this.startY=0,this.dx0=0,this.dy0=0,this.panningTrigger=!1,this.active=!1,this.mouseDownEvent=null,this.graph=t,this.graph.addMouseListener(this),this.forcePanningHandler=(e,i)=>{const s=i.getProperty("eventName"),n=i.getProperty("event");s===InternalEvent.MOUSE_DOWN&&this.isForcePanningEvent(n)&&(this.start(n),this.active=!0,this.fireEvent(new EventObject(InternalEvent.PAN_START,{event:n})),n.consume())},this.graph.addListener(InternalEvent.FIRE_MOUSE_EVENT,this.forcePanningHandler),this.gestureHandler=(e,i)=>{if(this.isPinchEnabled()){const s=i.getProperty("event");!isConsumed(s)&&s.type==="gesturestart"?(this.initialScale=this.graph.view.scale,!this.active&&this.mouseDownEvent&&(this.start(this.mouseDownEvent),this.mouseDownEvent=null)):s.type==="gestureend"&&this.initialScale!==0&&(this.initialScale=0),this.initialScale!==0&&this.zoomGraph(s)}},this.graph.addListener(InternalEvent.GESTURE,this.gestureHandler),this.mouseUpListener=()=>{this.active&&this.reset()},InternalEvent.addListener(document,"mouseup",this.mouseUpListener),this.panningManager=new PanningManager(t)}isActive(){return this.active||this.initialScale!==null}isPanningEnabled(){return this.panningEnabled}setPanningEnabled(t){this.panningEnabled=t}isPinchEnabled(){return this.pinchEnabled}setPinchEnabled(t){this.pinchEnabled=t}isPanningTrigger(t){const e=t.getEvent();return this.useLeftButtonForPanning&&!t.getState()&&isLeftMouseButton(e)||isControlDown(e)&&isShiftDown(e)||this.usePopupTrigger&&isPopupTrigger(e)}isForcePanningEvent(t){return this.ignoreCell||isMultiTouchEvent(t.getEvent())}mouseDown(t,e){this.mouseDownEvent=e,!e.isConsumed()&&this.isPanningEnabled()&&!this.active&&this.isPanningTrigger(e)&&(this.start(e),this.consumePanningTrigger(e))}start(t){this.dx0=-this.graph.container.scrollLeft,this.dy0=-this.graph.container.scrollTop,this.startX=t.getX(),this.startY=t.getY(),this.dx=0,this.dy=0,this.panningTrigger=!0}consumePanningTrigger(t){t.consume()}mouseMove(t,e){if(this.dx=e.getX()-this.startX,this.dy=e.getY()-this.startY,this.active)this.previewEnabled&&(this.useGrid&&(this.dx=this.graph.snap(this.dx),this.dy=this.graph.snap(this.dy)),this.graph.panGraph(this.dx+this.dx0,this.dy+this.dy0)),this.fireEvent(new EventObject(InternalEvent.PAN,{event:e}));else if(this.panningTrigger){const i=this.active;this.active=Math.abs(this.dx)>this.graph.getSnapTolerance()||Math.abs(this.dy)>this.graph.getSnapTolerance(),!i&&this.active&&this.fireEvent(new EventObject(InternalEvent.PAN_START,{event:e}))}(this.active||this.panningTrigger)&&e.consume()}mouseUp(t,e){if(this.active){if(this.dx!==0&&this.dy!==0){if(!this.graph.isUseScrollbarsForPanning()||!hasScrollbars(this.graph.container)){const{scale:i}=this.graph.getView(),s=this.graph.getView().translate;this.graph.panGraph(0,0),this.panGraph(s.x+this.dx/i,s.y+this.dy/i)}e.consume()}this.fireEvent(new EventObject(InternalEvent.PAN_END,{event:e}))}this.reset()}zoomGraph(t){let e=Math.round(this.initialScale*t.scale*100)/100;e=Math.max(this.minScale,e),e=Math.min(this.maxScale,e),this.graph.view.scale!==e&&(this.graph.zoomTo(e),InternalEvent.consume(t))}reset(){this.panningTrigger=!1,this.mouseDownEvent=null,this.active=!1,this.dx=0,this.dy=0}panGraph(t,e){this.graph.getView().setTranslate(t,e)}onDestroy(){this.graph.removeMouseListener(this),this.graph.removeListener(this.forcePanningHandler),this.graph.removeListener(this.gestureHandler),InternalEvent.removeListener(document,"mouseup",this.mouseUpListener),this.panningManager.destroy(),super.destroy()}}PanningHandler.pluginId="PanningHandler";function keep2digits(r){return Number(r.toFixed(2))}class FitPlugin{constructor(t){this.graph=t,this.minFitScale=.1,this.maxFitScale=8}fit(t={}){const{border:e=this.graph.getBorder(),keepOrigin:i=!1,margin:s=0,enabled:n=!0,ignoreWidth:l=!1,ignoreHeight:o=!1,maxHeight:a=null}=t,{backgroundImage:h,container:d,view:c}=this.graph;if(!d)return c.scale;let u=c.getGraphBounds();if(!(u.width>0&&u.height>0))return c.scale;const g=this.graph.getBorderSizes();let f=d.offsetWidth-g.x-g.width-1,p=a??d.offsetHeight-g.y-g.height-1;i&&u.x!=null&&u.y!=null&&(u=u.clone(),u.width+=u.x,u.height+=u.y,u.x=0,u.y=0);const y=c.scale;let v=u.width/y,S=u.height/y;h&&(v=Math.max(v,h.width-u.x/y),S=Math.max(S,h.height-u.y/y));const w=(i?e:2*e)+s+1;f-=w,p-=w;let C=l?p/S:o?f/v:Math.min(f/v,p/S);const m=this.minFitScale??0,M=this.maxFitScale??1/0;if(C=Math.max(Math.min(C,M),m),n)if(i)c.scale!=C&&c.setScale(C);else if(hasScrollbars(d)){c.setScale(C);const b=this.graph.getGraphBounds();b.x!=null&&(d.scrollLeft=b.x),b.y!=null&&(d.scrollTop=b.y)}else{const b=u.x!=null?Math.floor(c.translate.x-u.x/y+e/C+s/2):e,O=u.y!=null?Math.floor(c.translate.y-u.y/y+e/C+s/2):e;c.scaleAndTranslate(C,b,O)}else return C;return c.scale}fitCenter(t){const e=(t==null?void 0:t.margin)??2,{container:i,view:s}=this.graph,n=i.clientWidth-2*e,l=i.clientHeight-2*e,o=this.graph.getGraphBounds(),a=s.scale,h=o.width/a,d=o.height/a;let c=Math.min(this.maxFitScale??1/0,n/h,l/d);Number.isFinite(c)||(c=a);const u=Math.floor(s.translate.x+(i.clientWidth-h*c)/(2*c)-o.x/a),g=Math.floor(s.translate.y+(i.clientHeight-d*c)/(2*c)-o.y/a);return c=keep2digits(c),s.scaleAndTranslate(c,u,g),c}onDestroy(){}}FitPlugin.pluginId="fit";class ImageBundlePlugin{constructor(t){this.imageBundles=[]}addImageBundle(t){this.imageBundles.push(t)}removeImageBundle(t){this.imageBundles=this.imageBundles.filter(e=>e!==t)}getImageFromBundles(t){if(t)for(const e of this.imageBundles){const i=e.getImage(t);if(i)return i}return null}onDestroy(){this.imageBundles=[]}}ImageBundlePlugin.pluginId="image-bundle";class RubberBandHandler{constructor(t){this.first=null,this.destroyed=!1,this.dragHandler=null,this.dropHandler=null,this.x=0,this.y=0,this.width=0,this.height=0,this.defaultOpacity=20,this.enabled=!0,this.div=null,this.sharedDiv=null,this.currentX=0,this.currentY=0,this.fadeOut=!1,this.graph=t,this.graph.addMouseListener(this),this.forceRubberbandHandler=(e,i)=>{const s=i.getProperty("eventName"),n=i.getProperty("event");if(s===InternalEvent.MOUSE_DOWN&&this.isForceRubberbandEvent(n)){const l=getOffset(this.graph.container),o=getScrollOrigin(this.graph.container);o.x-=l.x,o.y-=l.y,this.start(n.getX()+o.x,n.getY()+o.y),n.consume(!1)}},this.graph.addListener(InternalEvent.FIRE_MOUSE_EVENT,this.forceRubberbandHandler),this.panHandler=()=>{this.repaint()},this.graph.addListener(InternalEvent.PAN,this.panHandler),this.gestureHandler=(e,i)=>{this.first&&this.reset()},this.graph.addListener(InternalEvent.GESTURE,this.gestureHandler)}isEnabled(){return this.enabled}setEnabled(t){this.enabled=t}isForceRubberbandEvent(t){return isAltDown(t.getEvent())}mouseDown(t,e){if(!e.isConsumed()&&this.isEnabled()&&this.graph.isEnabled()&&!e.getState()&&!isMultiTouchEvent(e.getEvent())){const i=getOffset(this.graph.container),s=getScrollOrigin(this.graph.container);s.x-=i.x,s.y-=i.y,this.start(e.getX()+s.x,e.getY()+s.y),e.consume(!1)}}start(t,e){this.first=new Point(t,e);const{container:i}=this.graph;function s(n){const l=new InternalMouseEvent(n),o=convertPoint(i,l.getX(),l.getY());return l.graphX=o.x,l.graphY=o.y,l}this.dragHandler=n=>{this.mouseMove(this.graph,s(n))},this.dropHandler=n=>{this.mouseUp(this.graph,s(n))},Client.IS_FF&&InternalEvent.addGestureListeners(document,null,this.dragHandler,this.dropHandler)}mouseMove(t,e){if(!e.isConsumed()&&this.first){const i=getScrollOrigin(this.graph.container),s=getOffset(this.graph.container);i.x-=s.x,i.y-=s.y;const n=e.getX()+i.x,l=e.getY()+i.y,o=this.first.x-n,a=this.first.y-l,h=this.graph.getEventTolerance();(this.div||Math.abs(o)>h||Math.abs(a)>h)&&(this.div||(this.div=this.createShape()),clearSelection(),this.update(n,l),e.consume())}}createShape(){this.sharedDiv||(this.sharedDiv=document.createElement("div"),this.sharedDiv.className="mxRubberband",setOpacity(this.sharedDiv,this.defaultOpacity)),this.graph.container.appendChild(this.sharedDiv);const t=this.sharedDiv;return Client.IS_SVG&&this.fadeOut&&(this.sharedDiv=null),t}isActive(t,e){return this.div&&this.div.style.display!=="none"}mouseUp(t,e){const i=this.isActive();this.reset(),i&&(this.execute(e.getEvent()),e.consume())}execute(t){const e=new Rectangle(this.x,this.y,this.width,this.height);this.graph.selectRegion(e,t)}reset(){if(this.div)if(Client.IS_SVG&&this.fadeOut){const t=this.div;setPrefixedStyle(t.style,"transition","all 0.2s linear"),t.style.pointerEvents="none",t.style.opacity=String(0),window.setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t)},200)}else this.div.parentNode&&this.div.parentNode.removeChild(this.div);InternalEvent.removeGestureListeners(document,null,this.dragHandler,this.dropHandler),this.dragHandler=null,this.dropHandler=null,this.currentX=0,this.currentY=0,this.first=null,this.div=null}update(t,e){this.currentX=t,this.currentY=e,this.repaint()}repaint(){if(this.div&&this.first){const t=this.currentX-this.graph.getPanDx(),e=this.currentY-this.graph.getPanDy();this.x=Math.min(this.first.x,t),this.y=Math.min(this.first.y,e),this.width=Math.max(this.first.x,t)-this.x,this.height=Math.max(this.first.y,e)-this.y;const i=0,s=0;this.div.style.left=`${this.x+i}px`,this.div.style.top=`${this.y+s}px`,this.div.style.width=`${Math.max(1,this.width)}px`,this.div.style.height=`${Math.max(1,this.height)}px`}}onDestroy(){this.destroyed||(this.destroyed=!0,this.graph.removeMouseListener(this),this.graph.removeListener(this.forceRubberbandHandler),this.graph.removeListener(this.panHandler),this.graph.removeListener(this.gestureHandler),this.reset(),this.sharedDiv&&(this.sharedDiv=null))}}RubberBandHandler.pluginId="RubberBandHandler";const getDefaultPlugins=()=>[CellEditorHandler,TooltipHandler,SelectionCellsHandler,PopupMenuHandler,ConnectionHandler,SelectionHandler,PanningHandler,FitPlugin,ImageBundlePlugin];class Graph extends AbstractGraph{createCellRenderer(){return new CellRenderer}createGraphDataModel(){return new GraphDataModel}createGraphView(){return new GraphView(this)}createSelectionModel(){return new GraphSelectionModel(this)}createStylesheet(){return new Stylesheet}registerDefaults(){registerDefaultEdgeMarkers(),registerDefaultEdgeStyles(),registerDefaultPerimeters(),registerDefaultShapes()}initializeCollaborators(t){this.cellRenderer=this.createCellRenderer(),this.model=(t==null?void 0:t.model)??this.createGraphDataModel(),this.setSelectionModel(this.createSelectionModel()),this.setStylesheet((t==null?void 0:t.stylesheet)??this.createStylesheet()),this.view=this.createGraphView()}constructor(t,e,i=getDefaultPlugins(),s){super({container:t,model:e,plugins:i,stylesheet:s??void 0})}}const MIN_WIDTH=130,MIN_HEIGHT=52;function toNumber(r){if(typeof r=="number"&&Number.isFinite(r))return r;if(typeof r=="string"){const t=Number.parseFloat(r);if(Number.isFinite(t))return t}}function estimateSize(r,t){return{width:Math.max(r.length*7.5+48,t.length*6.8+48,MIN_WIDTH),height:MIN_HEIGHT}}function nodeSize(r,t,e){var l,o;const i=toNumber(r.width)??toNumber((l=r.style)==null?void 0:l.width),s=toNumber(r.height)??toNumber((o=r.style)==null?void 0:o.height);if(i!==void 0&&s!==void 0)return{width:i,height:s};const n=estimateSize(t,e);return{width:i??n.width,height:s??n.height}}function parentFirst(r){const t=new Map(r.map(n=>[n.id,n])),e=[],i=new Set,s=(n,l)=>{if(i.has(n.id))return;if(l.has(n.id)){i.add(n.id),e.push(n);return}l.add(n.id);const o=n.parentId?t.get(n.parentId):void 0;o&&s(o,l),l.delete(n.id),i.has(n.id)||(i.add(n.id),e.push(n))};for(const n of r)s(n,new Set);return e}function buildScene(r,t){const e=new Set(r.map(n=>n.id)),i=parentFirst(r).map(n=>{var d,c;const l=n.data??{},o=typeof l.label=="string"&&l.label?l.label:n.id,a=typeof l.kind=="string"?l.kind:"",h=[l.bgColor,l.color,l.layerColor].find(u=>typeof u=="string"&&u.length>0)??"#6B7280";return{id:n.id,...n.parentId&&e.has(n.parentId)?{parentId:n.parentId}:{},x:((d=n.position)==null?void 0:d.x)??0,y:((c=n.position)==null?void 0:c.y)??0,...nodeSize(n,o,a),label:o,kind:a,color:h,isFrame:l.isFrame===!0,...Array.isArray(l.memberIds)&&l.memberIds.every(u=>typeof u=="string")?{memberIds:l.memberIds}:{},...l.orientation==="row"||l.orientation==="column"?{orientation:l.orientation}:{}}}),s=t.filter(n=>e.has(n.source)&&e.has(n.target)).map(n=>{var a;const l=n.style??{},o=Array.isArray((a=n.data)==null?void 0:a.points)?n.data.points:[];return{id:n.id,sourceId:n.source,targetId:n.target,...typeof n.label=="string"&&n.label?{label:n.label}:{},color:typeof l.stroke=="string"?l.stroke:"#9CA3AF",strokeWidth:toNumber(l.strokeWidth)??1.5,dashed:typeof l.strokeDasharray=="string"&&l.strokeDasharray.length>0,animated:n.animated===!0,points:o.length>2?o.slice(1,-1):[]}});return{nodes:i,edges:s}}function resolveViewKind(r){if(!r)return"general";const t=DIAGRAM_TYPE_META[r.diagramType];return r.viewKind??(t==null?void 0:t.viewKind)??"general"}function nonCanvasKind(r){return r==="grid"||r==="browser"||r==="geometry"?r:null}function buildViewpointFilter(r){const{model:t,diagram:e,selectedViewpointId:i,hiddenLayers:s}=r,n=(e==null?void 0:e.viewpointId)==="__model"?null:(e==null?void 0:e.viewpointId)||i,l=n&&t.viewpoints,o=s.size>0,a=e!=null&&e.elementIds?new Set(e.elementIds):void 0;if(!l&&!o&&!a)return;const h=l?t.viewpoints.find(u=>u.id===n):void 0,d=h?new Set(h.visibleKinds):void 0,c=h?new Set(h.visibleLayers):void 0;return u=>s.has(u.layer)?!1:a?a.has(u.id):d&&c?d.has(u.kind)||c.has(u.layer):!0}const NO_CALLBACKS={onToggleExpand:()=>{},onToggleDirection:()=>{}};function expandAll(r){const t=new Set,e=i=>{if(!t.has(i)){t.add(i);for(const s of r.childrenMap.get(i)??[])r.elements.has(s)&&e(s)}};for(const i of r.roots)r.elements.has(i)&&e(i);return t}async function computeDiagramScene(r){var c,u,g,f,p,y,v,S,w;const{model:t,diagram:e,layoutProviderId:i}=r,s=resolveViewKind(e);if(nonCanvasKind(s))return null;const n=buildViewpointFilter(r),l=!!((c=e==null?void 0:e.properties)!=null&&c.layoutStyle),o=((u=e==null?void 0:e.properties)==null?void 0:u.layoutStyle)==="fbs",a=s==="general"&&!l&&!o,h=new Map;let d;if(o)d=await computeFBSLayout(t,{expandedNodes:expandAll(buildFunctionalTree(t)),nodeDirections:new Map,callbacks:NO_CALLBACKS,layoutProviderId:i});else if(l)d=computeContainmentLayout(t,{expandedNodes:expandAll(buildDecompositionTree(t)),callbacks:NO_CALLBACKS});else if((e==null?void 0:e.diagramType)==="ucd")d=computeUseCaseViewLayout(t,{systemName:e.name,...useCaseViewOptions(e.properties)});else if((e==null?void 0:e.diagramType)==="context")d=computeContextViewLayout(t,e.name);else if(s==="interconnection")d=await computeInterconnectionLayout(t,{viewpointFilter:n,relationshipTypes:e==null?void 0:e.relationshipTypes,collapsedNodes:new Set,onToggleCollapse:()=>{},portDisplay:"all",onPortMove:()=>{},layoutProviderId:i});else if(s==="actionflow")d=await computeActionFlowViewLayout(t,{viewpointFilter:n,swimlanes:((g=r.actionFlow)==null?void 0:g.swimlanes)??!0,laneGrouping:((f=r.actionFlow)==null?void 0:f.laneGrouping)??"allocation",displayLevel:((p=r.actionFlow)==null?void 0:p.displayLevel)??"all",expandedActionIds:((y=r.actionFlow)==null?void 0:y.expandedActionIds)??new Set,onToggleAction:()=>{},focusActionId:((v=r.actionFlow)==null?void 0:v.focusActionId)??void 0,visibleFlowKinds:((S=r.actionFlow)==null?void 0:S.visibleFlowKinds)??new Set(["control","data","energy","material"]),direction:((w=r.actionFlow)==null?void 0:w.direction)??"horizontal",layoutProviderId:i});else if(s==="statetransition")d=await computeStateTransitionLayout(t,{viewpointFilter:n,layoutProviderId:i});else if(s==="sequence")d=computeSequenceLayout(t,{viewpointFilter:n});else{const C=resolveGeneralMode(e==null?void 0:e.properties);a&&C!=="graph"?d=await computeGeneralViewLayout(t,{mode:C,viewpointFilter:n,expandedNodes:expandAll(buildGeneralViewTree(t,n)),nodeDirections:new Map,callbacks:NO_CALLBACKS,positionCache:h,layoutProviderId:i}):d=await computeLayout(t,{viewpointFilter:n,relationshipTypes:e==null?void 0:e.relationshipTypes,compartments:a,layoutProviderId:i})}return buildScene(d.nodes,d.edges)}const CANVAS_BG="#F7F7F5",SCENE_TIMEOUT_MS=8e3,LAYOUT_PROGRESS_STYLE_ID="memo-layout-progress";if(typeof document<"u"&&!document.getElementById(LAYOUT_PROGRESS_STYLE_ID)){const r=document.createElement("style");r.id=LAYOUT_PROGRESS_STYLE_ID,r.textContent="@keyframes memo-layout-progress { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }",document.head.appendChild(r)}function nodeStyle(r){return r.isFrame?{fillColor:"none",strokeColor:r.color,opacity:35,rounded:!0,fontColor:r.color,fontSize:11,align:"left",verticalAlign:"top",spacingLeft:8,spacingTop:4}:{fillColor:"#FFFFFF",strokeColor:r.color,strokeWidth:1.5,rounded:!0,fontColor:"#1F2937",fontSize:12,whiteSpace:"wrap",verticalAlign:"middle"}}function fitGraph(r){var t;(t=r==null?void 0:r.getPlugin("fit"))==null||t.fit({margin:24})}function fitWhenSized(r,t){let e=!1;const i=()=>e?!0:(t.clientWidth>0&&t.clientHeight>0&&(fitGraph(r),e=!0),e),s=requestAnimationFrame(i);if(i())return()=>cancelAnimationFrame(s);const n=new ResizeObserver(()=>{i()&&n.disconnect()});return n.observe(t),()=>{cancelAnimationFrame(s),n.disconnect()}}function applySavedLayout(r,t){if(!t||Object.keys(t.nodes).length===0&&Object.keys(t.edges).length===0)return r;const e=r.nodes.map(s=>{const n=t.nodes[s.id];return n?{...s,x:n.x,y:n.y,...n.width?{width:n.width}:{},...n.height?{height:n.height}:{}}:s}),i=new Map(e.map(s=>[s.id,s]));return{...r,nodes:e.map(s=>{var c;if(!s.isFrame||!((c=s.memberIds)!=null&&c.length))return s;const n=s.memberIds.map(u=>i.get(u)).filter(Boolean);if(n.length===0)return s;const l=Math.min(...n.map(u=>u.x)),o=Math.min(...n.map(u=>u.y)),a=Math.max(...n.map(u=>u.x+u.width)),h=Math.max(...n.map(u=>u.y+u.height)),d=s.orientation==="column";return{...s,x:d?l-36:l-120,y:d?o-32:o-36,width:a-l+(d?72:156),height:h-o+(d?68:72)}}),edges:r.edges.map(s=>{var l;const n=(l=t.edges[s.id])==null?void 0:l.points;return n?{...s,points:n.length>2?n.slice(1,-1).map(o=>({x:o.x,y:o.y})):[]}:s})}}function MaxGraphCanvas(){var ht;const r=useModelStore(E=>E.model),t=useModelStore(E=>E.selectedDiagramId),e=useModelStore(E=>E.selectedViewpointId),i=useModelStore(E=>E.selectedElementId),s=useModelStore(E=>E.hiddenLayers),n=useModelStore(E=>E.inspectElement),l=useModelStore(E=>E.inspectRelationship),o=useModelStore(E=>E.diagramLayouts),a=useModelStore(E=>E.mergeDiagramLayouts),h=useModelStore(E=>E.createRelationship),d=reactExports.useRef(null),c=reactExports.useRef(null),u=reactExports.useRef(r),g=reactExports.useRef(t),f=reactExports.useRef(null),[p,y]=reactExports.useState(null),[v,S]=reactExports.useState(!1),[w,C]=reactExports.useState(null),[m,M]=reactExports.useState(!0),[b,O]=reactExports.useState("allocation"),[R,H]=reactExports.useState("all"),[T,U]=reactExports.useState("horizontal"),[q,it]=reactExports.useState(new Set(["control","data","energy","material"])),[x,P]=reactExports.useState(new Set),[L,A]=reactExports.useState(null),[I,B]=reactExports.useState(0),[k,V]=reactExports.useState(null),[Y,N]=reactExports.useState(0),_=getDiagram(r,t),z=resolveViewKind(_),W=nonCanvasKind(z),G=t?o[t]:void 0,Q=selectedLayoutProviderId(G),st=reactExports.useMemo(()=>{if(!r||!_)return[];const E=new Set(_.elementIds);return commonDisplayLevels(Object.values(r.elements).filter(D=>E.has(D.id)&&D.allocatedTo).map(D=>D.allocatedTo),r)},[r,_]);reactExports.useEffect(()=>{if(!r||W){y(null);return}const E=c.current;if(u.current!==r&&g.current===t&&E){const et=E.getView();f.current={scale:et.scale,x:et.translate.x,y:et.translate.y}}else f.current=null;u.current=r,g.current=t;let j=!1;S(!0),C(null);const J=new Promise((et,rt)=>{window.setTimeout(()=>rt(new Error(`Layout exceeded ${SCENE_TIMEOUT_MS/1e3}s`)),SCENE_TIMEOUT_MS)});return Promise.race([computeDiagramScene({model:r,diagram:_??null,selectedViewpointId:e,hiddenLayers:s,layoutProviderId:Q,actionFlow:{swimlanes:m,laneGrouping:b,displayLevel:R,expandedActionIds:x,focusActionId:L,visibleFlowKinds:q,direction:T}}),J]).then(et=>{j||(y(et),S(!1))}).catch(et=>{j||(console.error("maxGraph scene error:",et),C("The diagram could not be laid out. Switch to the ReactFlow renderer or reduce the visible hierarchy."),S(!1))}),()=>{j=!0}},[r,_,t,e,s,Q,W,m,b,R,x,L,q,T]);const F=reactExports.useCallback(E=>{if(!t||E.length===0)return;const D=useModelStore.getState().diagramLayouts[t]??{nodes:{},edges:{}},j={};for(const et of E){const rt=et.getId(),nt=et.getGeometry();!rt||!nt||et.isEdge()||(j[rt]={...D.nodes[rt]??{},x:nt.x,y:nt.y,width:nt.width,height:nt.height})}if(Object.keys(j).length===0)return;const J={...D,nodes:{...D.nodes,...j},edges:D.edges??{},canvas:{...D.canvas,autoLayout:!1}};a({[t]:J}),sendDiagramLayoutUpdate(t,J)},[t,a]),$=reactExports.useRef(F);reactExports.useEffect(()=>{$.current=F},[F]);const ot=reactExports.useRef(r);reactExports.useEffect(()=>{ot.current=r},[r]),reactExports.useEffect(()=>{var bt;const E=d.current;if(!E||!p)return;InternalEvent.disableContextMenu(E);const D=new Graph(E,void 0,[...getDefaultPlugins(),RubberBandHandler]);c.current=D,D.setPanning(!0),D.setCellsEditable(!1),D.setCellsResizable(!1),D.setConnectable(!0),D.setAllowDanglingEdges(!1),D.setCellsDisconnectable(!1),D.options.foldingEnabled=!1,D.setGridEnabled(!0),D.setGridSize(20);const j=D.getPlugin("SelectionHandler");j&&(j.guidesEnabled=!0);const J=t?useModelStore.getState().diagramLayouts[t]:void 0,et=applySavedLayout(p,J),rt=D.getDefaultParent(),nt=new Map;D.batchUpdate(()=>{for(const X of et.nodes){const pt=X.parentId?nt.get(X.parentId)??rt:rt,lt=D.insertVertex({parent:pt,id:X.id,value:X.kind&&!X.isFrame?`${X.label}
|
|
13
|
-
«${X.kind}»`:X.label,x:X.x,y:X.y,width:X.width,height:X.height,style:nodeStyle(X)});X.isFrame&<.setConnectable(!1),nt.set(X.id,lt)}for(const X of et.edges){const pt=nt.get(X.sourceId),lt=nt.get(X.targetId);if(!pt||!lt)continue;const ct={strokeColor:X.color,strokeWidth:X.strokeWidth,dashed:X.dashed||X.animated,rounded:!0,endArrow:"block",endFill:!0,fontColor:"#6B7280",fontSize:10,labelBackgroundColor:"#FFFFFF",...X.points.length===0?{edgeStyle:"orthogonalEdgeStyle"}:{}},dt=D.insertEdge({parent:rt,id:X.id,value:X.label??"",source:pt,target:lt,style:ct}).getGeometry();dt&&X.points.length>0&&(dt.points=X.points.map(Ct=>new Point(Ct.x,Ct.y)))}});const vt=f.current;f.current=null;let gt;vt?D.getView().scaleAndTranslate(vt.scale,vt.x,vt.y):((bt=J==null?void 0:J.canvas)==null?void 0:bt.zoom)!==void 0&&J.canvas.pan?(D.getView().setScale(J.canvas.zoom),D.getView().setTranslate(J.canvas.pan.x,J.canvas.pan.y)):gt=fitWhenSized(D,E),D.addListener(InternalEvent.CLICK,(X,pt)=>{var dt,Ct;const lt=pt.getProperty("cell"),ct=lt==null?void 0:lt.getId();if(!ct)return;const St=useModelStore.getState();(dt=St.model)!=null&&dt.elements[ct]?n(ct):(Ct=St.model)!=null&&Ct.relationships.some(wt=>wt.id===ct)&&l(ct)}),D.addListener(InternalEvent.CELLS_MOVED,(X,pt)=>{const lt=pt.getProperty("cells")??[];$.current(lt)});const ft=D.getSelectionModel(),mt=()=>{B(D.getSelectionCells().filter(X=>!X.isEdge()).length)};ft.addListener(InternalEvent.CHANGE,mt);const Et=D.getPlugin("ConnectionHandler");Et==null||Et.addListener(InternalEvent.CONNECT,(X,pt)=>{var Pt,Mt;const lt=pt.getProperty("cell");if(!lt)return;const ct=(Pt=lt.getTerminal(!0))==null?void 0:Pt.getId(),St=(Mt=lt.getTerminal(!1))==null?void 0:Mt.getId();window.setTimeout(()=>{try{D.removeCells([lt],!1)}catch{}},0);const dt=ot.current,Ct=ct?dt==null?void 0:dt.elements[ct]:void 0,wt=St?dt==null?void 0:dt.elements[St]:void 0;Ct&&wt&&ct!==St&&V({sourceElement:Ct,targetElement:wt})});const xt=X=>{X.preventDefault(),X.deltaY<0?D.zoomIn():D.zoomOut()};return E.addEventListener("wheel",xt,{passive:!1}),()=>{gt==null||gt(),E.removeEventListener("wheel",xt),ft.removeListener(mt),B(0),c.current=null,D.destroy(),E.innerHTML=""}},[p,t,Y]),reactExports.useEffect(()=>{const E=c.current;if(!E||E.getSelectionCells().length>1)return;if(!i){E.clearSelection();return}const D=E.getDataModel().getCell(i);D&&E.getSelectionCell()!==D&&E.setSelectionCell(D)},[i,p]);const tt=reactExports.useCallback(E=>{const D=c.current;if(!D)return;const j=D.getSelectionCells().filter(J=>!J.isEdge());j.length<2||(D.alignCells(E,j),$.current(j))},[]),at=reactExports.useCallback(async E=>{const D=k==null?void 0:k.sourceElement.id;if(V(null),!t)return;const j=await h({type:E.type,sourceId:E.sourceId,targetId:E.targetId,direction:E.direction,selectedElementId:D,diagramId:t});j.success||console.warn(`[MEMO] Relationship rejected: ${j.error}`)},[k,t,h]),Z=!!G&&(Object.keys(G.nodes??{}).length>0||((ht=G.canvas)==null?void 0:ht.autoLayout)===!1),yt=reactExports.useCallback(()=>{if(!t)return;const E={nodes:{},edges:{},canvas:{autoLayout:!0}};a({[t]:E}),sendDiagramLayoutUpdate(t,E),N(D=>D+1)},[t,a]),ut=reactExports.useCallback(()=>{var rt;const E=(rt=d.current)==null?void 0:rt.querySelector("svg");if(!E)return;const D=E.cloneNode(!0);D.setAttribute("xmlns","http://www.w3.org/2000/svg"),D.style.backgroundColor=CANVAS_BG;const j=new Blob([new XMLSerializer().serializeToString(D)],{type:"image/svg+xml"}),J=URL.createObjectURL(j),et=document.createElement("a");et.href=J,et.download=`${(_==null?void 0:_.name)??"diagram"}.svg`,et.click(),URL.revokeObjectURL(J)},[_==null?void 0:_.name]);if(_&&r&&W==="grid")return jsxRuntimeExports.jsx(GridView,{diagram:_,model:r,viewpointFilter:buildViewpointFilter({model:r,diagram:_,selectedViewpointId:e,hiddenLayers:s})});if(_&&r&&W==="browser")return jsxRuntimeExports.jsx(BrowserView,{diagram:_,model:r,viewpointFilter:buildViewpointFilter({model:r,diagram:_,selectedViewpointId:e,hiddenLayers:s})});if(W==="geometry")return jsxRuntimeExports.jsx("div",{className:"flex-1 flex items-center justify-center",style:{background:CANVAS_BG,color:"#9CA3AF",fontSize:FONT.sm},children:"Geometry views are deferred (ADR-1-19)."});const K={fontSize:FONT.xs,padding:"4px 10px",background:"#FFFFFF",color:"#374151",border:"1px solid #E5E5E0",borderRadius:6,cursor:"pointer",fontWeight:600};return jsxRuntimeExports.jsxs("div",{className:"relative flex-1 overflow-hidden",style:{background:CANVAS_BG},children:[jsxRuntimeExports.jsx("div",{ref:d,className:"absolute inset-0",style:{cursor:"default"}}),z==="actionflow"&&jsxRuntimeExports.jsxs("div",{className:"absolute top-3 left-3 z-10 flex items-center gap-1.5 rounded-lg p-1.5",style:{background:"#FFFFFF",border:"1px solid #E5E5E0",boxShadow:"0 2px 8px rgba(0,0,0,0.08)"},children:[jsxRuntimeExports.jsx("button",{style:{...K,background:m?"#1B3A4B":"#FFFFFF",color:m?"#FFFFFF":"#374151"},onClick:()=>M(E=>!E),title:"Toggle swimlanes",children:"Lanes"}),m&&jsxRuntimeExports.jsx("button",{style:K,onClick:()=>O(E=>E==="allocation"?"stage":"allocation"),title:"Group lanes by allocation or stage",children:b==="allocation"?"Allocation":"Stage"}),m&&b==="allocation"&&st.length>0&&jsxRuntimeExports.jsxs("select",{value:R,onChange:E=>H(E.target.value==="all"?"all":Number(E.target.value)),style:K,title:"Responsibility hierarchy level",children:[jsxRuntimeExports.jsx("option",{value:"all",children:"All levels"}),st.map(E=>jsxRuntimeExports.jsxs("option",{value:E,children:["L",E]},E))]}),jsxRuntimeExports.jsx("button",{style:{...K,background:T==="horizontal"?"#1B3A4B":"#FFFFFF",color:T==="horizontal"?"#FFFFFF":"#374151"},onClick:()=>U("horizontal"),title:"Left-to-right flow",children:"→"}),jsxRuntimeExports.jsx("button",{style:{...K,background:T==="vertical"?"#1B3A4B":"#FFFFFF",color:T==="vertical"?"#FFFFFF":"#374151"},onClick:()=>U("vertical"),title:"Top-to-bottom flow",children:"↓"}),jsxRuntimeExports.jsx("button",{style:K,onClick:()=>P(new Set(Object.values((r==null?void 0:r.elements)??{}).map(E=>E.parentAction).filter(E=>!!E))),title:"Expand all sub-actions",children:"Expand"}),jsxRuntimeExports.jsx("button",{style:K,onClick:()=>P(new Set),title:"Collapse all sub-actions",children:"Collapse"}),["control","data","energy","material"].map(E=>jsxRuntimeExports.jsx("button",{style:{...K,textTransform:"capitalize",opacity:q.has(E)?1:.45},onClick:()=>it(D=>{const j=new Set(D);return j.has(E)?j.delete(E):j.add(E),j}),title:`Toggle ${E} flows`,children:E},E)),L&&jsxRuntimeExports.jsx("button",{style:K,onClick:()=>A(null),children:"Parent"})]}),jsxRuntimeExports.jsxs("div",{className:"absolute top-3 right-3 z-10 flex items-center gap-1.5",children:[I>=2&&jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsx("button",{style:K,onClick:()=>tt("left"),title:"Align left edges","aria-label":"Align left",children:"⇤"}),jsxRuntimeExports.jsx("button",{style:K,onClick:()=>tt("center"),title:"Align horizontal centres","aria-label":"Align centres",children:"↔"}),jsxRuntimeExports.jsx("button",{style:K,onClick:()=>tt("right"),title:"Align right edges","aria-label":"Align right",children:"⇥"}),jsxRuntimeExports.jsx("button",{style:K,onClick:()=>tt("top"),title:"Align top edges","aria-label":"Align top",children:"⤒"}),jsxRuntimeExports.jsx("button",{style:K,onClick:()=>tt("middle"),title:"Align vertical middles","aria-label":"Align middles",children:"↕"}),jsxRuntimeExports.jsx("button",{style:K,onClick:()=>tt("bottom"),title:"Align bottom edges","aria-label":"Align bottom",children:"⤓"}),jsxRuntimeExports.jsx("span",{style:{color:"#E5E5E0"},children:"|"})]}),jsxRuntimeExports.jsx("button",{style:{...K,background:Z?"#FFFFFF":"#ECFDF5",color:Z?"#374151":"#047857",borderColor:Z?"#E5E5E0":"#A7F3D0"},onClick:yt,disabled:!Z,title:Z?"Re-run automatic layout (discards manual moves)":"Layout is automatic",children:"Auto layout"}),jsxRuntimeExports.jsx("span",{style:{color:"#E5E5E0"},children:"|"}),jsxRuntimeExports.jsx("button",{style:K,onClick:()=>{var E;return(E=c.current)==null?void 0:E.zoomIn()},title:"Zoom in",children:"+"}),jsxRuntimeExports.jsx("button",{style:K,onClick:()=>{var E;return(E=c.current)==null?void 0:E.zoomOut()},title:"Zoom out",children:"-"}),jsxRuntimeExports.jsx("button",{style:K,onClick:()=>fitGraph(c.current),title:"Fit diagram to the viewport",children:"Fit view"}),jsxRuntimeExports.jsx("button",{style:K,onClick:ut,title:"Download this diagram as an SVG image",children:"Export SVG"})]}),v&&jsxRuntimeExports.jsx("div",{className:"absolute inset-x-0 top-0 z-10",style:{height:3,background:"linear-gradient(90deg, transparent, #2DD4A8, transparent)",backgroundSize:"200% 100%",animation:"memo-layout-progress 1.2s linear infinite"}}),w&&jsxRuntimeExports.jsx("div",{className:"absolute inset-x-0 top-0 z-10 px-4 py-2",style:{background:"#FEF2F2",color:"#B91C1C",fontSize:FONT.xs,borderBottom:"1px solid #FECACA"},children:w}),!v&&!w&&p&&p.nodes.length===0&&jsxRuntimeExports.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",style:{color:"#9CA3AF",fontSize:FONT.sm},children:_?"No elements in this view.":"Select a view from the explorer."}),k&&jsxRuntimeExports.jsx(RelationshipPicker,{x:window.innerWidth/2-130,y:window.innerHeight/2-160,sourceElement:k.sourceElement,targetElement:k.targetElement,registries:getRegistries(r),onSelect:at,onCancel:()=>V(null)})]})}export{MaxGraphCanvas};
|
|
12
|
+
`+u.stack:"unknown cause"}`;log().debug(g)}finally{h.endUpdate()}this.select&&this.selectCells(c,d?e:null)}}selectCells(t,e){this.graph.setSelectionCell(t)}insertEdge(t,e,i,s,n,l){if(!this.factoryMethod)return this.graph.insertEdge({parent:t,id:e,value:i,source:s,target:n,style:l});let o=this.createEdge(i,s,n,l);return o=this.graph.addEdge(o,t,s,n),o}createTargetVertex(t,e){let i=e.getGeometry();for(;i&&i.relative;)e=e.getParent(),i=e.getGeometry();const s=this.graph.cloneCell(e);if(i=s.getGeometry(),i&&this.currentPoint){const n=this.graph.view.translate,l=this.graph.view.scale,o=new Point(this.currentPoint.x/l-n.x,this.currentPoint.y/l-n.y);i.x=Math.round(o.x-i.width/2-this.graph.getPanDx()/l),i.y=Math.round(o.y-i.height/2-this.graph.getPanDy()/l);const a=this.getAlignmentTolerance();if(a>0){const h=this.graph.view.getState(e);if(h!=null){const d=h.x/l-n.x,c=h.y/l-n.y;Math.abs(d-i.x)<=a&&(i.x=Math.round(d)),Math.abs(c-i.y)<=a&&(i.y=Math.round(c))}}}return s}getAlignmentTolerance(t){return this.graph.isGridEnabled()?this.graph.getGridSize()/2:this.graph.getSnapTolerance()}createEdge(t,e,i,s={}){let n=null;if(this.factoryMethod!=null&&(n=this.factoryMethod(e,i,s)),n==null){n=new Cell(t||""),n.setEdge(!0),n.setStyle(s);const l=new Geometry;l.relative=!0,n.setGeometry(l)}return n}onDestroy(){this.graph.removeMouseListener(this),this.shape&&(this.shape.destroy(),this.shape=null),this.marker&&(this.marker.destroy(),this.marker=null),this.constraintHandler&&this.constraintHandler.onDestroy(),this.changeHandler&&(this.graph.getDataModel().removeListener(this.changeHandler),this.graph.getView().removeListener(this.changeHandler)),this.drillHandler&&(this.graph.removeListener(this.drillHandler),this.graph.getView().removeListener(this.drillHandler)),this.escapeHandler&&this.graph.removeListener(this.escapeHandler)}}ConnectionHandler.pluginId="ConnectionHandler";class ConnectionHandlerCellMarker extends CellMarker{constructor(t,e,i=VALID_COLOR,s=DEFAULT_INVALID_COLOR,n=DEFAULT_HOTSPOT){super(t,i,s,n),this.hotspotEnabled=!0,this.connectionHandler=e}getCell(t){let e=super.getCell(t);if(this.connectionHandler.error=null,!e&&this.connectionHandler.currentPoint&&(e=this.connectionHandler.graph.getCellAt(this.connectionHandler.currentPoint.x,this.connectionHandler.currentPoint.y)),e&&!e.isConnectable()&&this.connectionHandler.cell){const i=this.connectionHandler.cell.getParent();i&&i.isVertex()&&i.isConnectable()&&(e=i)}return e&&(this.connectionHandler.graph.isSwimlane(e)&&this.connectionHandler.currentPoint!=null&&this.connectionHandler.graph.hitsSwimlaneContent(e,this.connectionHandler.currentPoint.x,this.connectionHandler.currentPoint.y)||!this.connectionHandler.isConnectableCell(e))&&(e=null),e?this.connectionHandler.isConnecting()?this.connectionHandler.previous&&(this.connectionHandler.error=this.connectionHandler.validateConnection(this.connectionHandler.previous.cell,e),this.connectionHandler.error!==null&&this.connectionHandler.error.length===0&&(e=null,this.connectionHandler.isCreateTarget(t.getEvent())&&(this.connectionHandler.error=null))):this.connectionHandler.isValidSource(e,t)||(e=null):this.connectionHandler.isConnecting()&&!this.connectionHandler.isCreateTarget(t.getEvent())&&!this.connectionHandler.graph.isAllowDanglingEdges()&&(this.connectionHandler.error=""),e}isValidState(t){return this.connectionHandler.isConnecting()?!this.connectionHandler.error:super.isValidState(t)}getMarkerColor(t,e,i){return!this.connectionHandler.connectImage||this.connectionHandler.isConnecting()?super.getMarkerColor(t,e,i):NONE}intersects(t,e){return this.connectionHandler.connectImage||this.connectionHandler.isConnecting()?!0:super.intersects(t,e)}}class Guide{constructor(t,e){this.states=[],this.horizontal=!0,this.vertical=!0,this.guideX=null,this.guideY=null,this.rounded=!1,this.tolerance=2,this.graph=t,this.setStates(e)}setStates(t){this.states=t}isEnabledForEvent(t){return!0}getGuideTolerance(t=!1){return t&&this.graph.isGridEnabled()?this.graph.getGridSize()/2:this.tolerance}createGuideShape(t=!1){const e=new PolylineShape([],GUIDE_COLOR,GUIDE_STROKEWIDTH);return e.isDashed=!0,e}isStateIgnored(t){return!1}move(t=null,e,i=!1,s=!1){if((this.horizontal||this.vertical)&&t){const{scale:n}=this.graph.getView(),l=this.getGuideTolerance(i)*n,o=t.clone();o.x+=e.x,o.y+=e.y;let a=!1,h=null,d=null,c=!1,u=null,g=null,f=l,p=l;const y=o.x,v=o.x+o.width,S=o.getCenterX(),w=o.y,C=o.y+o.height,m=o.getCenterY(),M=(R,H,T)=>{let U=!1;T&&Math.abs(R-S)<f?(e.x=R-t.getCenterX(),f=Math.abs(R-S),U=!0):T||(Math.abs(R-y)<f?(e.x=R-t.x,f=Math.abs(R-y),U=!0):Math.abs(R-v)<f&&(e.x=R-t.x-t.width,f=Math.abs(R-v),U=!0)),U&&(h=H,d=R,this.guideX||(this.guideX=this.createGuideShape(!0),this.guideX.dialect="svg",this.guideX.pointerEvents=!1,this.guideX.init(this.graph.getView().getOverlayPane()))),a=a||U},b=(R,H,T)=>{let U=!1;T&&Math.abs(R-m)<p?(e.y=R-t.getCenterY(),p=Math.abs(R-m),U=!0):T||(Math.abs(R-w)<p?(e.y=R-t.y,p=Math.abs(R-w),U=!0):Math.abs(R-C)<p&&(e.y=R-t.y-t.height,p=Math.abs(R-C),U=!0)),U&&(u=H,g=R,this.guideY||(this.guideY=this.createGuideShape(!1),this.guideY.dialect="svg",this.guideY.pointerEvents=!1,this.guideY.init(this.graph.getView().getOverlayPane()))),c=c||U};for(let R=0;R<this.states.length;R+=1){const H=this.states[R];H&&!this.isStateIgnored(H)&&(this.horizontal&&(M(H.getCenterX(),H,!0),M(H.x,H,!1),M(H.x+H.width,H,!1),H.cell||M(H.getCenterX(),H,!1)),this.vertical&&(b(H.getCenterY(),H,!0),b(H.y,H,!1),b(H.y+H.height,H,!1),H.cell||b(H.getCenterY(),H,!1)))}this.graph.snapDelta(e,t,!i,a,c),e=this.getDelta(t,h,e.x,u,e.y);const O=this.graph.container;if(!a&&this.guideX)this.guideX.node.style.visibility="hidden";else if(this.guideX){let R=null,H=null;h&&(R=Math.min(t.y+e.y-this.graph.getPanDy(),h.y),H=Math.max(t.y+t.height+e.y-this.graph.getPanDy(),h.y+h.height)),R!==null&&H!==null?this.guideX.points=[new Point(d,R),new Point(d,H)]:this.guideX.points=[new Point(d,-this.graph.getPanDy()),new Point(d,O.scrollHeight-3-this.graph.getPanDy())],this.guideX.stroke=this.getGuideColor(h,!0),this.guideX.node.style.visibility="visible",this.guideX.redraw()}if(!c&&this.guideY!=null)this.guideY.node.style.visibility="hidden";else if(this.guideY!=null){let R=null,H=null;u!=null&&t!=null&&(R=Math.min(t.x+e.x-this.graph.getPanDx(),u.x),H=Math.max(t.x+t.width+e.x-this.graph.getPanDx(),u.x+u.width)),R!=null&&H!=null&&g!==null?this.guideY.points=[new Point(R,g),new Point(H,g)]:g!==null&&(this.guideY.points=[new Point(-this.graph.getPanDx(),g),new Point(O.scrollWidth-3-this.graph.getPanDx(),g)]),this.guideY.stroke=this.getGuideColor(u,!1),this.guideY.node.style.visibility="visible",this.guideY.redraw()}}return e}getDelta(t,e=null,i,s=null,n){const l=this.graph.view.scale;return(this.rounded||e!=null&&e.cell==null)&&(i=Math.round((t.x+i)/l)*l-t.x),(this.rounded||s!=null&&s.cell==null)&&(n=Math.round((t.y+n)/l)*l-t.y),new Point(i,n)}getGuideColor(t,e){return GUIDE_COLOR}hide(){this.setVisible(!1)}setVisible(t){this.guideX&&(this.guideX.node.style.visibility=t?"visible":"hidden"),this.guideY&&(this.guideY.node.style.visibility=t?"visible":"hidden")}destroy(){this.guideX&&(this.guideX.destroy(),this.guideX=null),this.guideY&&(this.guideY.destroy(),this.guideY=null)}}class SelectionHandler{constructor(t){this.refreshThread=null,this.maxCells=50,this.enabled=!0,this.highlightEnabled=!0,this.cloneEnabled=!0,this.moveEnabled=!0,this.guidesEnabled=!1,this.handlesVisible=!0,this.guide=null,this.currentDx=0,this.currentDy=0,this.updateCursor=!0,this.selectEnabled=!0,this.removeCellsFromParent=!0,this.removeEmptyParents=!1,this.connectOnDrop=!1,this.scrollOnMove=!0,this.minimumSize=6,this.previewColor="black",this.htmlPreview=!1,this.shape=null,this.scaleGrid=!1,this.rotationEnabled=!0,this.maxLivePreview=0,this.allowLivePreview=Client.IS_SVG,this.cell=null,this.delayedSelection=!1,this.first=null,this.cells=null,this.bounds=null,this.pBounds=null,this.allCells=new Map,this.cellWasClicked=!1,this.cloning=!1,this.cellCount=0,this.target=null,this.suspended=!1,this.livePreviewActive=!1,this.livePreviewUsed=!1,this.highlight=null,this.graph=t,this.graph.addMouseListener(this),this.panHandler=()=>{this.suspended||(this.updatePreview(),this.updateHint())},this.graph.addListener(InternalEvent.PAN,this.panHandler),this.escapeHandler=(e,i)=>{this.reset()},this.graph.addListener(InternalEvent.ESCAPE,this.escapeHandler),this.refreshHandler=(e,i)=>{this.refreshThread&&window.clearTimeout(this.refreshThread),this.refreshThread=window.setTimeout(()=>{var s;if(this.refreshThread=null,this.first&&!this.suspended&&this.cells){const n=this.currentDx,l=this.currentDy;this.currentDx=0,this.currentDy=0,this.updatePreview(),this.bounds=this.graph.getView().getBounds(this.cells),this.pBounds=this.getPreviewBounds(this.cells),this.pBounds==null&&!this.livePreviewUsed?this.reset():(this.currentDx=n,this.currentDy=l,this.updatePreview(),this.updateHint(),this.livePreviewUsed&&(this.setHandlesVisibleForCells(((s=this.getSelectionCellsHandler())==null?void 0:s.getHandledSelectionCells())??[],!1,!0),this.updatePreview()))}},0)},this.graph.getDataModel().addListener(InternalEvent.CHANGE,this.refreshHandler),this.graph.addListener(InternalEvent.REFRESH,this.refreshHandler),this.keyHandler=e=>{if(this.graph.container!=null&&this.graph.container.style.visibility!=="hidden"&&this.first!=null&&!this.suspended){const i=this.graph.isCloneEvent(e)&&this.graph.isCellsCloneable()&&this.isCloneEnabled();i!==this.cloning&&(this.cloning=i,this.checkPreview(),this.updatePreview())}},typeof document<"u"&&(InternalEvent.addListener(document,"keydown",this.keyHandler),InternalEvent.addListener(document,"keyup",this.keyHandler))}isEnabled(){return this.enabled}setEnabled(t){this.enabled=t}isCloneEnabled(){return this.cloneEnabled}setCloneEnabled(t){this.cloneEnabled=t}isMoveEnabled(){return this.moveEnabled}setMoveEnabled(t){this.moveEnabled=t}isSelectEnabled(){return this.selectEnabled}setSelectEnabled(t){this.selectEnabled=t}isRemoveCellsFromParent(){return this.removeCellsFromParent}setRemoveCellsFromParent(t){this.removeCellsFromParent=t}isPropagateSelectionCell(t,e,i){const s=t.getParent();if(e){const n=t.isEdge()?null:t.getGeometry();return!this.graph.isSiblingSelected(t)&&n&&n.relative||!this.graph.isSwimlane(s)}return(!this.graph.isToggleEvent(i.getEvent())||!this.graph.isSiblingSelected(t)&&!this.graph.isCellSelected(t)&&!this.graph.isSwimlane(s)||this.graph.isCellSelected(s))&&(this.graph.isToggleEvent(i.getEvent())||!this.graph.isCellSelected(s))}getInitialCellForEvent(t){let e=t.getState();if((!this.graph.isToggleEvent(t.getEvent())||!isAltDown(t.getEvent()))&&e&&!this.graph.isCellSelected(e.cell)){let i=e.cell.getParent(),s=i?this.graph.view.getState(i):null;for(;s&&!this.graph.isCellSelected(s.cell)&&(s.cell.isVertex()||s.cell.isEdge())&&this.isPropagateSelectionCell(e.cell,!0,t);)e=s,i=e.cell.getParent(),s=i?this.graph.view.getState(i):null}return e?e.cell:null}isDelayedSelection(t,e){let i=t;const s=this.getSelectionCellsHandler();if(!this.graph.isToggleEvent(e.getEvent())||!isAltDown(e.getEvent()))for(;i;){if(s!=null&&s.isHandled(i)){const n=this.graph.getPlugin("CellEditorHandler");return(n==null?void 0:n.getEditingCell())!==i}i=i.getParent()}return this.graph.isToggleEvent(e.getEvent())&&!isAltDown(e.getEvent())}selectDelayed(t){const e=this.graph.getPlugin("PopupMenuHandler");if(!e||!e.isPopupTrigger(t)){let i=t.getCell();i===null&&(i=this.cell),i&&this.selectCellForEvent(i,t)}}selectCellForEvent(t,e){const i=this.graph.view.getState(t);if(i)if(e.isSource(i.control))this.graph.selectCellForEvent(t,e.getEvent());else{if(!this.graph.isToggleEvent(e.getEvent())||!isAltDown(e.getEvent())){let s=t.getParent();for(;s&&this.graph.view.getState(s)&&(s.isVertex()||s.isEdge())&&this.isPropagateSelectionCell(t,!1,e);)t=s,s=t.getParent()}this.graph.selectCellForEvent(t,e.getEvent())}return t}consumeMouseEvent(t,e){e.consume()}mouseDown(t,e){if(!e.isConsumed()&&this.isEnabled()&&this.graph.isEnabled()&&e.getState()&&!isMultiTouchEvent(e.getEvent())){const i=this.getInitialCellForEvent(e);if(i&&(this.delayedSelection=this.isDelayedSelection(i,e),this.cell=null,this.isSelectEnabled()&&!this.delayedSelection&&this.graph.selectCellForEvent(i,e.getEvent()),this.isMoveEnabled())){const s=i.getGeometry();s&&this.graph.isCellMovable(i)&&(!i.isEdge()||this.graph.getSelectionCount()>1||s.points&&s.points.length>0||!i.getTerminal(!0)||!i.getTerminal(!1)||this.graph.isAllowDanglingEdges()||this.graph.isCloneEvent(e.getEvent())&&this.graph.isCellsCloneable())?this.start(i,e.getX(),e.getY()):this.delayedSelection&&(this.cell=i),this.cellWasClicked=!0,this.consumeMouseEvent(InternalEvent.MOUSE_DOWN,e)}}}getGuideStates(){const t=this.graph.getDefaultParent(),e=i=>{const s=i.getGeometry();return!!this.graph.view.getState(i)&&i.isVertex()&&!!s&&!s.relative};return this.graph.view.getCellStates(t.filterDescendants(e))}getCells(t){return!this.delayedSelection&&this.graph.isCellMovable(t)?[t]:this.graph.getMovableCells(this.graph.getSelectionCells())}getPreviewBounds(t){const e=this.getBoundingBox(t);if(e){if(e.width=Math.max(0,e.width-1),e.height=Math.max(0,e.height-1),e.width<this.minimumSize){const i=this.minimumSize-e.width;e.x-=i/2,e.width=this.minimumSize}else e.x=Math.round(e.x),e.width=Math.ceil(e.width);if(e.height<this.minimumSize){const i=this.minimumSize-e.height;e.y-=i/2,e.height=this.minimumSize}else e.y=Math.round(e.y),e.height=Math.ceil(e.height)}return e}getBoundingBox(t){let e=null;if(t.length>0){for(let i=0;i<t.length;i+=1)if(t[i].isVertex()||t[i].isEdge()){const s=this.graph.view.getState(t[i]);if(s){let n=null;t[i].isVertex()&&s.shape&&s.shape.boundingBox&&(n=s.shape.boundingBox),n&&(e?e.add(n):e=Rectangle.fromRectangle(n))}}}return e}createPreviewShape(t){const e=new RectangleShape(t,NONE,this.previewColor);return e.isDashed=!0,this.htmlPreview?(e.dialect="strictHtml",e.init(this.graph.container)):(e.dialect="svg",e.init(this.graph.getView().getOverlayPane()),e.pointerEvents=!1,Client.IS_IOS&&(e.getSvgScreenOffset=()=>0)),e}createGuide(){return new Guide(this.graph,this.getGuideStates())}start(t,e,i,s){this.cell=t,this.first=convertPoint(this.graph.container,e,i),this.cells=s||this.getCells(this.cell),this.bounds=this.graph.getView().getBounds(this.cells),this.pBounds=this.getPreviewBounds(this.cells),this.cloning=!1,this.cellCount=0;for(let n=0;n<this.cells.length;n+=1)this.cellCount+=this.addStates(this.cells[n],this.allCells);if(this.guidesEnabled){this.guide=this.createGuide();const n=t.getParent(),l=n.getChildCount()<2,o=new Map,a=this.graph.getOpposites(this.graph.getEdges(this.cell),this.cell);for(let h=0;h<a.length;h+=1){const d=this.graph.view.getState(a[h]);d&&!o.get(d)&&o.set(d,!0)}this.guide.isStateIgnored=h=>{const d=h.cell.getParent();return!!h.cell&&(!this.cloning&&!!this.isCellMoving(h.cell)||h.cell!==(this.target||n)&&!l&&!o.get(h)&&(!this.target||this.target.getChildCount()>=2)&&d!==(this.target||n))}}}addStates(t,e){const i=this.graph.view.getState(t);let s=0;if(i&&!e.get(t)){e.set(t,i),s++;const n=t.getChildCount();for(let l=0;l<n;l+=1)s+=this.addStates(t.getChildAt(l),e)}return s}isCellMoving(t){return this.allCells.has(t)}useGuidesForEvent(t){return this.guide?this.guide.isEnabledForEvent(t.getEvent())&&!this.graph.isConstrainedEvent(t.getEvent()):!0}snap(t){const e=this.scaleGrid?this.graph.view.scale:1;return t.x=this.graph.snap(t.x/e)*e,t.y=this.graph.snap(t.y/e)*e,t}getDelta(t){const e=convertPoint(this.graph.container,t.getX(),t.getY());return this.first?new Point(e.x-this.first.x-this.graph.getPanDx(),e.y-this.first.y-this.graph.getPanDy()):new Point}updateHint(t){}removeHint(){}roundLength(t){return Math.round(t*100)/100}isValidDropTarget(t,e){return this.cell?this.cell.getParent()!==t:!1}checkPreview(){this.livePreviewActive&&this.cloning?(this.resetLivePreview(),this.livePreviewActive=!1):this.maxLivePreview>=this.cellCount&&!this.livePreviewActive&&this.allowLivePreview?(!this.cloning||!this.livePreviewActive)&&(this.livePreviewActive=!0,this.livePreviewUsed=!0):!this.livePreviewUsed&&!this.shape&&this.bounds&&(this.shape=this.createPreviewShape(this.bounds))}mouseMove(t,e){const{graph:i}=this;if(!e.isConsumed()&&i.isMouseDown&&this.cell&&this.first&&this.bounds&&!this.suspended){if(isMultiTouchEvent(e.getEvent())){this.reset();return}let s=this.getDelta(e);const n=i.getEventTolerance();if(this.shape||this.livePreviewActive||Math.abs(s.x)>n||Math.abs(s.y)>n){this.highlight||(this.highlight=new CellHighlight(this.graph,DROP_TARGET_COLOR,3));const l=i.isCloneEvent(e.getEvent())&&i.isCellsCloneable()&&this.isCloneEnabled(),o=i.isGridEnabledEvent(e.getEvent()),a=e.getCell();let h=!0,d=null;this.cloning=l,i.isDropEnabled()&&this.highlightEnabled&&this.cells&&(d=i.getDropTarget(this.cells,e.getEvent(),a,l));let c=d?i.getView().getState(d):null,u=!1;if(c&&(l||d&&this.isValidDropTarget(d,e)))this.target!==d&&(this.target=d,this.setHighlightColor(DROP_TARGET_COLOR)),u=!0;else if(this.target=null,this.connectOnDrop&&a&&this.cells&&this.cells.length===1&&a.isVertex()&&a.isConnectable()&&(c=i.getView().getState(a),c)){const f=i.getEdgeValidationError(null,this.cell,a)===null?VALID_COLOR:INVALID_CONNECT_TARGET_COLOR;this.setHighlightColor(f),u=!0}c&&u?this.highlight.highlight(c):this.highlight.hide(),this.guide&&this.useGuidesForEvent(e)?(s=this.guide.move(this.bounds,s,o,l),h=!1):s=this.graph.snapDelta(s,this.bounds,!o,!1,!1),this.guide&&h&&this.guide.hide(),i.isConstrainedEvent(e.getEvent())&&(Math.abs(s.x)>Math.abs(s.y)?s.y=0:s.x=0),this.checkPreview(),(this.currentDx!==s.x||this.currentDy!==s.y)&&(this.currentDx=s.x,this.currentDy=s.y,this.updatePreview())}this.updateHint(e),this.consumeMouseEvent(InternalEvent.MOUSE_MOVE,e),InternalEvent.consume(e.getEvent())}else if((this.isMoveEnabled()||this.isCloneEnabled())&&this.updateCursor&&!e.isConsumed()&&(e.getState()||e.sourceState)&&!i.isMouseDown){let s=i.getCursorForMouseEvent(e);const n=e.getCell();!s&&n&&i.isEnabled()&&i.isCellMovable(n)&&(n.isEdge()?s=EdgeHandlerConfig.cursorMovable:s=VertexHandlerConfig.cursorMovable),s&&e.sourceState&&e.sourceState.setCursor(s)}}updatePreview(t=!1){var e;this.livePreviewUsed&&!t?this.cells&&(this.setHandlesVisibleForCells(((e=this.getSelectionCellsHandler())==null?void 0:e.getHandledSelectionCells())??[],!1),this.updateLivePreview(this.currentDx,this.currentDy)):this.updatePreviewShape()}updatePreviewShape(){this.shape&&this.pBounds&&(this.shape.bounds=new Rectangle(Math.round(this.pBounds.x+this.currentDx),Math.round(this.pBounds.y+this.currentDy),this.pBounds.width,this.pBounds.height),this.shape.redraw())}updateLivePreview(t,e){if(!this.suspended){const i=[];if(this.allCells&&this.allCells.forEach(s=>{const n=s?this.graph.view.getState(s.cell):null;if(n!==s&&s&&(s.destroy(),n?this.allCells.set(s.cell,n):this.allCells.delete(s.cell),s=n),s){const l=s.clone();i.push([s,l]),s.shape&&(s.shape.originalPointerEvents===null&&(s.shape.originalPointerEvents=s.shape.pointerEvents),s.shape.pointerEvents=!1,s.text&&(s.text.originalPointerEvents===null&&(s.text.originalPointerEvents=s.text.pointerEvents),s.text.pointerEvents=!1)),s.cell.isVertex()&&(s.x+=t,s.y+=e,this.cloning?s.text&&(s.text.updateBoundingBox(),s.text.boundingBox&&(s.text.boundingBox.x+=t,s.text.boundingBox.y+=e),s.text.unrotatedBoundingBox&&(s.text.unrotatedBoundingBox.x+=t,s.text.unrotatedBoundingBox.y+=e)):(s.view.graph.cellRenderer.redraw(s,!0),s.view.invalidate(s.cell),s.invalid=!1,s.control&&s.control.node&&(s.control.node.style.visibility="hidden")))}}),i.length===0)this.reset();else{const s=this.graph.view.scale;for(let n=0;n<i.length;n+=1){const l=i[n][0];if(l.cell.isEdge()){const o=l.cell.getGeometry(),a=[];if(o&&o.points)for(let u=0;u<o.points.length;u++)o.points[u]&&a.push(new Point(o.points[u].x+t/s,o.points[u].y+e/s));let h=l.visibleSourceState,d=l.visibleTargetState;const c=i[n][1].absolutePoints;if(h==null||!this.isCellMoving(h.cell)){const u=c[0];u&&(l.setAbsoluteTerminalPoint(new Point(u.x+t,u.y+e),!0),h=null)}else l.view.updateFixedTerminalPoint(l,h,!0,this.graph.getConnectionConstraint(l,h,!0));if(d==null||!this.isCellMoving(d.cell)){const u=c[c.length-1];u&&(l.setAbsoluteTerminalPoint(new Point(u.x+t,u.y+e),!1),d=null)}else l.view.updateFixedTerminalPoint(l,d,!1,this.graph.getConnectionConstraint(l,d,!1));l.view.updatePoints(l,a,h,d),l.view.updateFloatingTerminalPoints(l,h,d),l.view.updateEdgeLabelOffset(l),l.invalid=!1,this.cloning||l.view.graph.cellRenderer.redraw(l,!0)}}this.graph.view.validate(),this.redrawHandles(i),this.resetPreviewStates(i)}}}redrawHandles(t){const e=this.getSelectionCellsHandler();for(let i=0;i<t.length;i+=1){const s=e==null?void 0:e.getHandler(t[i][0].cell);s==null||s.redraw(!0)}}resetPreviewStates(t){for(let e=0;e<t.length;e+=1)t[e][0].setState(t[e][1])}suspend(){this.suspended||(this.livePreviewUsed&&this.updateLivePreview(0,0),this.shape&&(this.shape.node.style.visibility="hidden"),this.guide&&this.guide.setVisible(!1),this.suspended=!0)}resume(){this.suspended&&(this.suspended=!1,this.livePreviewUsed&&(this.livePreviewActive=!0),this.shape&&(this.shape.node.style.visibility="visible"),this.guide&&this.guide.setVisible(!0))}resetLivePreview(){this.allCells.forEach(t=>{t.shape&&t.shape.originalPointerEvents!==null&&(t.shape.pointerEvents=t.shape.originalPointerEvents,t.shape.originalPointerEvents=null,t.shape.bounds=null,t.text&&t.text.originalPointerEvents!==null&&(t.text.pointerEvents=t.text.originalPointerEvents,t.text.originalPointerEvents=null)),t.control&&t.control.node&&t.control.node.style.visibility==="hidden"&&(t.control.node.style.visibility=""),this.cloning||t.text&&t.text.updateBoundingBox(),t.view.invalidate(t.cell)}),this.graph.view.validate()}setHandlesVisibleForCells(t,e,i=!1){if(i||this.handlesVisible!==e){this.handlesVisible=e;const s=this.getSelectionCellsHandler();for(let n=0;n<t.length;n+=1){const l=s==null?void 0:s.getHandler(t[n]);l&&(l.setHandlesVisible(e),e&&l.redraw())}}}setHighlightColor(t){this.highlight&&this.highlight.setHighlightColor(t)}mouseUp(t,e){if(!e.isConsumed())if(this.livePreviewUsed&&this.resetLivePreview(),this.cell&&this.first&&(this.shape||this.livePreviewUsed)&&isNumeric(this.currentDx)&&isNumeric(this.currentDy)){const{graph:i}=this,s=e.getCell();if(this.connectOnDrop&&!this.target&&s&&s.isVertex()&&s.isConnectable()&&i.isEdgeValid(null,this.cell,s)){const n=i.getPlugin("ConnectionHandler");n==null||n.connect(this.cell,s,e.getEvent())}else{const n=i.isCloneEvent(e.getEvent())&&i.isCellsCloneable()&&this.isCloneEnabled(),{scale:l}=i.getView(),o=this.roundLength(this.currentDx/l),a=this.roundLength(this.currentDy/l),h=this.target;h&&i.isSplitEnabled()&&this.cells&&i.isSplitTarget(h,this.cells,e.getEvent())?i.splitEdge(h,this.cells,null,o,a,e.getGraphX(),e.getGraphY()):this.cells&&this.moveCells(this.cells,o,a,n,this.target,e.getEvent())}}else this.isSelectEnabled()&&this.delayedSelection&&this.cell!=null&&this.selectDelayed(e);this.cellWasClicked&&this.consumeMouseEvent(InternalEvent.MOUSE_UP,e),this.reset()}reset(){var t;this.livePreviewUsed&&(this.resetLivePreview(),this.setHandlesVisibleForCells(((t=this.getSelectionCellsHandler())==null?void 0:t.getHandledSelectionCells())??[],!0)),this.destroyShapes(),this.removeHint(),this.delayedSelection=!1,this.livePreviewActive=!1,this.livePreviewUsed=!1,this.cellWasClicked=!1,this.suspended=!1,this.currentDx=0,this.currentDy=0,this.cellCount=0,this.cloning=!1,this.allCells.clear(),this.pBounds=null,this.target=null,this.first=null,this.cells=null,this.cell=null}shouldRemoveCellsFromParent(t,e,i){if(t.isVertex()){const s=this.graph.getView().getState(t);if(s){let n=convertPoint(this.graph.container,getClientX(i),getClientY(i));const l=toRadians(s.style.rotation??0);if(l!==0){const o=Math.cos(-l),a=Math.sin(-l),h=new Point(s.getCenterX(),s.getCenterY());n=getRotatedPoint(n,o,a,h)}return!contains(s,n.x,n.y)}}return!1}moveCells(t,e,i,s,n,l){if(!this.cell)return;s&&(t=this.graph.getCloneableCells(t));const o=this.cell.getParent();!n&&o&&this.isRemoveCellsFromParent()&&this.shouldRemoveCellsFromParent(o,t,l)&&(n=this.graph.getDefaultParent()),s=!!s&&!this.graph.isCellLocked(n||this.graph.getDefaultParent()),this.graph.batchUpdate(()=>{const a=[];if(!s&&n&&this.removeEmptyParents){const d=new Map;for(let c=0;c<t.length;c+=1)d.set(t[c],!0);for(let c=0;c<t.length;c+=1){const u=t[c].getParent();u&&!d.get(u)&&(d.set(u,!0),a.push(u))}}t=this.graph.moveCells(t,e,i,s,n,l);const h=[];for(let d=0;d<a.length;d+=1)this.shouldRemoveParent(a[d])&&h.push(a[d]);this.graph.removeCells(h,!1)}),s&&this.graph.setSelectionCells(t),this.isSelectEnabled()&&this.scrollOnMove&&this.graph.scrollCellToVisible(t[0])}shouldRemoveParent(t){const e=this.graph.view.getState(t);return e!=null&&(e.cell.isEdge()||e.cell.isVertex())&&this.graph.isCellDeletable(e.cell)&&e.cell.getChildCount()===0&&e.isTransparentState()}destroyShapes(){this.shape&&(this.shape.destroy(),this.shape=null),this.guide&&(this.guide.destroy(),this.guide=null),this.highlight&&(this.highlight.destroy(),this.highlight=null)}onDestroy(){this.graph.removeMouseListener(this),this.graph.removeListener(this.panHandler),this.graph.removeListener(this.escapeHandler),this.graph.getDataModel().removeListener(this.refreshHandler),this.graph.removeListener(this.refreshHandler),InternalEvent.removeListener(document,"keydown",this.keyHandler),InternalEvent.removeListener(document,"keyup",this.keyHandler),this.destroyShapes(),this.removeHint()}getSelectionCellsHandler(){return this.graph.getPlugin("SelectionCellsHandler")}}SelectionHandler.pluginId="SelectionHandler";class PanningManager{constructor(t){this.damper=1/6,this.delay=10,this.handleMouseOut=!0,this.border=0,this.thread=null,this.active=!1,this.tdx=0,this.tdy=0,this.t0x=0,this.t0y=0,this.dx=0,this.dy=0,this.scrollbars=!1,this.scrollLeft=0,this.scrollTop=0,this.thread=null,this.active=!1,this.tdx=0,this.tdy=0,this.t0x=0,this.t0y=0,this.dx=0,this.dy=0,this.scrollbars=!1,this.scrollLeft=0,this.scrollTop=0,this.mouseListener={mouseDown:()=>{},mouseMove:()=>{},mouseUp:()=>{this.active&&this.stop()}},t.addMouseListener(this.mouseListener),this.mouseUpListener=()=>{this.active&&this.stop()},InternalEvent.addListener(document,"mouseup",this.mouseUpListener);const e=()=>(this.scrollbars=hasScrollbars(t.container),this.scrollLeft=t.container.scrollLeft,this.scrollTop=t.container.scrollTop,window.setInterval(()=>{if(this.tdx-=this.dx,this.tdy-=this.dy,this.scrollbars){const i=-t.container.scrollLeft-Math.ceil(this.dx),s=-t.container.scrollTop-Math.ceil(this.dy);t.panGraph(i,s),t.setPanDx(this.scrollLeft-t.container.scrollLeft),t.setPanDy(this.scrollTop-t.container.scrollTop),t.fireEvent(new EventObject(InternalEvent.PAN))}else t.panGraph(this.getDx(),this.getDy())},this.delay));this.isActive=()=>this.active,this.getDx=()=>Math.round(this.tdx),this.getDy=()=>Math.round(this.tdy),this.start=()=>{this.t0x=t.view.translate.x,this.t0y=t.view.translate.y,this.active=!0},this.panTo=(i,s,n=0,l=0)=>{this.active||this.start(),this.scrollLeft=t.container.scrollLeft,this.scrollTop=t.container.scrollTop;const o=t.container;this.dx=i+n-o.scrollLeft-o.clientWidth,this.dx<0&&Math.abs(this.dx)<this.border?this.dx=this.border+this.dx:this.handleMouseOut?this.dx=Math.max(this.dx,0):this.dx=0,this.dx==0&&(this.dx=i-o.scrollLeft,this.dx>0&&this.dx<this.border?this.dx-=this.border:this.handleMouseOut?this.dx=Math.min(0,this.dx):this.dx=0),this.dy=s+l-o.scrollTop-o.clientHeight,this.dy<0&&Math.abs(this.dy)<this.border?this.dy=this.border+this.dy:this.handleMouseOut?this.dy=Math.max(this.dy,0):this.dy=0,this.dy==0&&(this.dy=s-o.scrollTop,this.dy>0&&this.dy<this.border?this.dy-=this.border:this.handleMouseOut?this.dy=Math.min(0,this.dy):this.dy=0),this.dx!=0||this.dy!=0?(this.dx*=this.damper,this.dy*=this.damper,this.thread==null&&(this.thread=e())):this.thread!=null&&(window.clearInterval(this.thread),this.thread=null)},this.stop=()=>{if(this.active)if(this.active=!1,this.thread!=null&&(window.clearInterval(this.thread),this.thread=null),this.tdx=0,this.tdy=0,this.scrollbars)t.setPanDx(0),t.setPanDy(0),t.fireEvent(new EventObject(InternalEvent.PAN));else{const i=t.getPanDx(),s=t.getPanDy();(i!=0||s!=0)&&(t.panGraph(0,0),t.view.setTranslate(this.t0x+i/t.view.scale,this.t0y+s/t.view.scale))}},this.destroy=()=>{this.stop(),t.removeMouseListener(this.mouseListener),InternalEvent.removeListener(document,"mouseup",this.mouseUpListener)}}}class PanningHandler extends EventSource{constructor(t){super(),this.getPanningManager=()=>this.panningManager,this.useLeftButtonForPanning=!1,this.usePopupTrigger=!0,this.ignoreCell=!1,this.previewEnabled=!0,this.useGrid=!1,this.panningEnabled=!1,this.pinchEnabled=!0,this.initialScale=0,this.maxScale=8,this.minScale=.01,this.dx=0,this.dy=0,this.startX=0,this.startY=0,this.dx0=0,this.dy0=0,this.panningTrigger=!1,this.active=!1,this.mouseDownEvent=null,this.graph=t,this.graph.addMouseListener(this),this.forcePanningHandler=(e,i)=>{const s=i.getProperty("eventName"),n=i.getProperty("event");s===InternalEvent.MOUSE_DOWN&&this.isForcePanningEvent(n)&&(this.start(n),this.active=!0,this.fireEvent(new EventObject(InternalEvent.PAN_START,{event:n})),n.consume())},this.graph.addListener(InternalEvent.FIRE_MOUSE_EVENT,this.forcePanningHandler),this.gestureHandler=(e,i)=>{if(this.isPinchEnabled()){const s=i.getProperty("event");!isConsumed(s)&&s.type==="gesturestart"?(this.initialScale=this.graph.view.scale,!this.active&&this.mouseDownEvent&&(this.start(this.mouseDownEvent),this.mouseDownEvent=null)):s.type==="gestureend"&&this.initialScale!==0&&(this.initialScale=0),this.initialScale!==0&&this.zoomGraph(s)}},this.graph.addListener(InternalEvent.GESTURE,this.gestureHandler),this.mouseUpListener=()=>{this.active&&this.reset()},InternalEvent.addListener(document,"mouseup",this.mouseUpListener),this.panningManager=new PanningManager(t)}isActive(){return this.active||this.initialScale!==null}isPanningEnabled(){return this.panningEnabled}setPanningEnabled(t){this.panningEnabled=t}isPinchEnabled(){return this.pinchEnabled}setPinchEnabled(t){this.pinchEnabled=t}isPanningTrigger(t){const e=t.getEvent();return this.useLeftButtonForPanning&&!t.getState()&&isLeftMouseButton(e)||isControlDown(e)&&isShiftDown(e)||this.usePopupTrigger&&isPopupTrigger(e)}isForcePanningEvent(t){return this.ignoreCell||isMultiTouchEvent(t.getEvent())}mouseDown(t,e){this.mouseDownEvent=e,!e.isConsumed()&&this.isPanningEnabled()&&!this.active&&this.isPanningTrigger(e)&&(this.start(e),this.consumePanningTrigger(e))}start(t){this.dx0=-this.graph.container.scrollLeft,this.dy0=-this.graph.container.scrollTop,this.startX=t.getX(),this.startY=t.getY(),this.dx=0,this.dy=0,this.panningTrigger=!0}consumePanningTrigger(t){t.consume()}mouseMove(t,e){if(this.dx=e.getX()-this.startX,this.dy=e.getY()-this.startY,this.active)this.previewEnabled&&(this.useGrid&&(this.dx=this.graph.snap(this.dx),this.dy=this.graph.snap(this.dy)),this.graph.panGraph(this.dx+this.dx0,this.dy+this.dy0)),this.fireEvent(new EventObject(InternalEvent.PAN,{event:e}));else if(this.panningTrigger){const i=this.active;this.active=Math.abs(this.dx)>this.graph.getSnapTolerance()||Math.abs(this.dy)>this.graph.getSnapTolerance(),!i&&this.active&&this.fireEvent(new EventObject(InternalEvent.PAN_START,{event:e}))}(this.active||this.panningTrigger)&&e.consume()}mouseUp(t,e){if(this.active){if(this.dx!==0&&this.dy!==0){if(!this.graph.isUseScrollbarsForPanning()||!hasScrollbars(this.graph.container)){const{scale:i}=this.graph.getView(),s=this.graph.getView().translate;this.graph.panGraph(0,0),this.panGraph(s.x+this.dx/i,s.y+this.dy/i)}e.consume()}this.fireEvent(new EventObject(InternalEvent.PAN_END,{event:e}))}this.reset()}zoomGraph(t){let e=Math.round(this.initialScale*t.scale*100)/100;e=Math.max(this.minScale,e),e=Math.min(this.maxScale,e),this.graph.view.scale!==e&&(this.graph.zoomTo(e),InternalEvent.consume(t))}reset(){this.panningTrigger=!1,this.mouseDownEvent=null,this.active=!1,this.dx=0,this.dy=0}panGraph(t,e){this.graph.getView().setTranslate(t,e)}onDestroy(){this.graph.removeMouseListener(this),this.graph.removeListener(this.forcePanningHandler),this.graph.removeListener(this.gestureHandler),InternalEvent.removeListener(document,"mouseup",this.mouseUpListener),this.panningManager.destroy(),super.destroy()}}PanningHandler.pluginId="PanningHandler";function keep2digits(r){return Number(r.toFixed(2))}class FitPlugin{constructor(t){this.graph=t,this.minFitScale=.1,this.maxFitScale=8}fit(t={}){const{border:e=this.graph.getBorder(),keepOrigin:i=!1,margin:s=0,enabled:n=!0,ignoreWidth:l=!1,ignoreHeight:o=!1,maxHeight:a=null}=t,{backgroundImage:h,container:d,view:c}=this.graph;if(!d)return c.scale;let u=c.getGraphBounds();if(!(u.width>0&&u.height>0))return c.scale;const g=this.graph.getBorderSizes();let f=d.offsetWidth-g.x-g.width-1,p=a??d.offsetHeight-g.y-g.height-1;i&&u.x!=null&&u.y!=null&&(u=u.clone(),u.width+=u.x,u.height+=u.y,u.x=0,u.y=0);const y=c.scale;let v=u.width/y,S=u.height/y;h&&(v=Math.max(v,h.width-u.x/y),S=Math.max(S,h.height-u.y/y));const w=(i?e:2*e)+s+1;f-=w,p-=w;let C=l?p/S:o?f/v:Math.min(f/v,p/S);const m=this.minFitScale??0,M=this.maxFitScale??1/0;if(C=Math.max(Math.min(C,M),m),n)if(i)c.scale!=C&&c.setScale(C);else if(hasScrollbars(d)){c.setScale(C);const b=this.graph.getGraphBounds();b.x!=null&&(d.scrollLeft=b.x),b.y!=null&&(d.scrollTop=b.y)}else{const b=u.x!=null?Math.floor(c.translate.x-u.x/y+e/C+s/2):e,O=u.y!=null?Math.floor(c.translate.y-u.y/y+e/C+s/2):e;c.scaleAndTranslate(C,b,O)}else return C;return c.scale}fitCenter(t){const e=(t==null?void 0:t.margin)??2,{container:i,view:s}=this.graph,n=i.clientWidth-2*e,l=i.clientHeight-2*e,o=this.graph.getGraphBounds(),a=s.scale,h=o.width/a,d=o.height/a;let c=Math.min(this.maxFitScale??1/0,n/h,l/d);Number.isFinite(c)||(c=a);const u=Math.floor(s.translate.x+(i.clientWidth-h*c)/(2*c)-o.x/a),g=Math.floor(s.translate.y+(i.clientHeight-d*c)/(2*c)-o.y/a);return c=keep2digits(c),s.scaleAndTranslate(c,u,g),c}onDestroy(){}}FitPlugin.pluginId="fit";class ImageBundlePlugin{constructor(t){this.imageBundles=[]}addImageBundle(t){this.imageBundles.push(t)}removeImageBundle(t){this.imageBundles=this.imageBundles.filter(e=>e!==t)}getImageFromBundles(t){if(t)for(const e of this.imageBundles){const i=e.getImage(t);if(i)return i}return null}onDestroy(){this.imageBundles=[]}}ImageBundlePlugin.pluginId="image-bundle";class RubberBandHandler{constructor(t){this.first=null,this.destroyed=!1,this.dragHandler=null,this.dropHandler=null,this.x=0,this.y=0,this.width=0,this.height=0,this.defaultOpacity=20,this.enabled=!0,this.div=null,this.sharedDiv=null,this.currentX=0,this.currentY=0,this.fadeOut=!1,this.graph=t,this.graph.addMouseListener(this),this.forceRubberbandHandler=(e,i)=>{const s=i.getProperty("eventName"),n=i.getProperty("event");if(s===InternalEvent.MOUSE_DOWN&&this.isForceRubberbandEvent(n)){const l=getOffset(this.graph.container),o=getScrollOrigin(this.graph.container);o.x-=l.x,o.y-=l.y,this.start(n.getX()+o.x,n.getY()+o.y),n.consume(!1)}},this.graph.addListener(InternalEvent.FIRE_MOUSE_EVENT,this.forceRubberbandHandler),this.panHandler=()=>{this.repaint()},this.graph.addListener(InternalEvent.PAN,this.panHandler),this.gestureHandler=(e,i)=>{this.first&&this.reset()},this.graph.addListener(InternalEvent.GESTURE,this.gestureHandler)}isEnabled(){return this.enabled}setEnabled(t){this.enabled=t}isForceRubberbandEvent(t){return isAltDown(t.getEvent())}mouseDown(t,e){if(!e.isConsumed()&&this.isEnabled()&&this.graph.isEnabled()&&!e.getState()&&!isMultiTouchEvent(e.getEvent())){const i=getOffset(this.graph.container),s=getScrollOrigin(this.graph.container);s.x-=i.x,s.y-=i.y,this.start(e.getX()+s.x,e.getY()+s.y),e.consume(!1)}}start(t,e){this.first=new Point(t,e);const{container:i}=this.graph;function s(n){const l=new InternalMouseEvent(n),o=convertPoint(i,l.getX(),l.getY());return l.graphX=o.x,l.graphY=o.y,l}this.dragHandler=n=>{this.mouseMove(this.graph,s(n))},this.dropHandler=n=>{this.mouseUp(this.graph,s(n))},Client.IS_FF&&InternalEvent.addGestureListeners(document,null,this.dragHandler,this.dropHandler)}mouseMove(t,e){if(!e.isConsumed()&&this.first){const i=getScrollOrigin(this.graph.container),s=getOffset(this.graph.container);i.x-=s.x,i.y-=s.y;const n=e.getX()+i.x,l=e.getY()+i.y,o=this.first.x-n,a=this.first.y-l,h=this.graph.getEventTolerance();(this.div||Math.abs(o)>h||Math.abs(a)>h)&&(this.div||(this.div=this.createShape()),clearSelection(),this.update(n,l),e.consume())}}createShape(){this.sharedDiv||(this.sharedDiv=document.createElement("div"),this.sharedDiv.className="mxRubberband",setOpacity(this.sharedDiv,this.defaultOpacity)),this.graph.container.appendChild(this.sharedDiv);const t=this.sharedDiv;return Client.IS_SVG&&this.fadeOut&&(this.sharedDiv=null),t}isActive(t,e){return this.div&&this.div.style.display!=="none"}mouseUp(t,e){const i=this.isActive();this.reset(),i&&(this.execute(e.getEvent()),e.consume())}execute(t){const e=new Rectangle(this.x,this.y,this.width,this.height);this.graph.selectRegion(e,t)}reset(){if(this.div)if(Client.IS_SVG&&this.fadeOut){const t=this.div;setPrefixedStyle(t.style,"transition","all 0.2s linear"),t.style.pointerEvents="none",t.style.opacity=String(0),window.setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t)},200)}else this.div.parentNode&&this.div.parentNode.removeChild(this.div);InternalEvent.removeGestureListeners(document,null,this.dragHandler,this.dropHandler),this.dragHandler=null,this.dropHandler=null,this.currentX=0,this.currentY=0,this.first=null,this.div=null}update(t,e){this.currentX=t,this.currentY=e,this.repaint()}repaint(){if(this.div&&this.first){const t=this.currentX-this.graph.getPanDx(),e=this.currentY-this.graph.getPanDy();this.x=Math.min(this.first.x,t),this.y=Math.min(this.first.y,e),this.width=Math.max(this.first.x,t)-this.x,this.height=Math.max(this.first.y,e)-this.y;const i=0,s=0;this.div.style.left=`${this.x+i}px`,this.div.style.top=`${this.y+s}px`,this.div.style.width=`${Math.max(1,this.width)}px`,this.div.style.height=`${Math.max(1,this.height)}px`}}onDestroy(){this.destroyed||(this.destroyed=!0,this.graph.removeMouseListener(this),this.graph.removeListener(this.forceRubberbandHandler),this.graph.removeListener(this.panHandler),this.graph.removeListener(this.gestureHandler),this.reset(),this.sharedDiv&&(this.sharedDiv=null))}}RubberBandHandler.pluginId="RubberBandHandler";const getDefaultPlugins=()=>[CellEditorHandler,TooltipHandler,SelectionCellsHandler,PopupMenuHandler,ConnectionHandler,SelectionHandler,PanningHandler,FitPlugin,ImageBundlePlugin];class Graph extends AbstractGraph{createCellRenderer(){return new CellRenderer}createGraphDataModel(){return new GraphDataModel}createGraphView(){return new GraphView(this)}createSelectionModel(){return new GraphSelectionModel(this)}createStylesheet(){return new Stylesheet}registerDefaults(){registerDefaultEdgeMarkers(),registerDefaultEdgeStyles(),registerDefaultPerimeters(),registerDefaultShapes()}initializeCollaborators(t){this.cellRenderer=this.createCellRenderer(),this.model=(t==null?void 0:t.model)??this.createGraphDataModel(),this.setSelectionModel(this.createSelectionModel()),this.setStylesheet((t==null?void 0:t.stylesheet)??this.createStylesheet()),this.view=this.createGraphView()}constructor(t,e,i=getDefaultPlugins(),s){super({container:t,model:e,plugins:i,stylesheet:s??void 0})}}const MIN_WIDTH=130,MIN_HEIGHT=52;function toNumber(r){if(typeof r=="number"&&Number.isFinite(r))return r;if(typeof r=="string"){const t=Number.parseFloat(r);if(Number.isFinite(t))return t}}function estimateSize(r,t){return{width:Math.max(r.length*7.5+48,t.length*6.8+48,MIN_WIDTH),height:MIN_HEIGHT}}function nodeSize(r,t,e){var l,o;const i=toNumber(r.width)??toNumber((l=r.style)==null?void 0:l.width),s=toNumber(r.height)??toNumber((o=r.style)==null?void 0:o.height);if(i!==void 0&&s!==void 0)return{width:i,height:s};const n=estimateSize(t,e);return{width:i??n.width,height:s??n.height}}function parentFirst(r){const t=new Map(r.map(n=>[n.id,n])),e=[],i=new Set,s=(n,l)=>{if(i.has(n.id))return;if(l.has(n.id)){i.add(n.id),e.push(n);return}l.add(n.id);const o=n.parentId?t.get(n.parentId):void 0;o&&s(o,l),l.delete(n.id),i.has(n.id)||(i.add(n.id),e.push(n))};for(const n of r)s(n,new Set);return e}function buildScene(r,t){const e=new Set(r.map(n=>n.id)),i=parentFirst(r).map(n=>{var d,c;const l=n.data??{},o=typeof l.label=="string"&&l.label?l.label:n.id,a=typeof l.kind=="string"?l.kind:"",h=[l.bgColor,l.color,l.layerColor].find(u=>typeof u=="string"&&u.length>0)??"#6B7280";return{id:n.id,...n.parentId&&e.has(n.parentId)?{parentId:n.parentId}:{},x:((d=n.position)==null?void 0:d.x)??0,y:((c=n.position)==null?void 0:c.y)??0,...nodeSize(n,o,a),label:o,kind:a,color:h,isFrame:l.isFrame===!0,...Array.isArray(l.memberIds)&&l.memberIds.every(u=>typeof u=="string")?{memberIds:l.memberIds}:{},...l.orientation==="row"||l.orientation==="column"?{orientation:l.orientation}:{}}}),s=t.filter(n=>e.has(n.source)&&e.has(n.target)).map(n=>{var a,h;const l=n.style??{},o=Array.isArray((a=n.data)==null?void 0:a.points)?n.data.points:[];return{id:n.id,sourceId:n.source,targetId:n.target,...typeof n.label=="string"&&n.label?{label:n.label}:{},color:typeof l.stroke=="string"?l.stroke:"#9CA3AF",strokeWidth:toNumber(l.strokeWidth)??1.5,dashed:typeof l.strokeDasharray=="string"&&l.strokeDasharray.length>0,animated:n.animated===!0,...typeof((h=n.data)==null?void 0:h.routing)=="string"?{routing:n.data.routing}:{},points:o.length>2?o.slice(1,-1):[]}});return{nodes:i,edges:s}}function resolveViewKind(r){if(!r)return"general";const t=DIAGRAM_TYPE_META[r.diagramType];return r.viewKind??(t==null?void 0:t.viewKind)??"general"}function nonCanvasKind(r){return r==="grid"||r==="browser"||r==="geometry"?r:null}function buildViewpointFilter(r){const{model:t,diagram:e,selectedViewpointId:i,hiddenLayers:s}=r,n=(e==null?void 0:e.viewpointId)==="__model"?null:(e==null?void 0:e.viewpointId)||i,l=n&&t.viewpoints,o=s.size>0,a=e!=null&&e.elementIds?new Set(e.elementIds):void 0;if(!l&&!o&&!a)return;const h=l?t.viewpoints.find(u=>u.id===n):void 0,d=h?new Set(h.visibleKinds):void 0,c=h?new Set(h.visibleLayers):void 0;return u=>s.has(u.layer)?!1:a?a.has(u.id):d&&c?d.has(u.kind)||c.has(u.layer):!0}const NO_CALLBACKS={onToggleExpand:()=>{},onToggleDirection:()=>{}};function expandAll(r){const t=new Set,e=i=>{if(!t.has(i)){t.add(i);for(const s of r.childrenMap.get(i)??[])r.elements.has(s)&&e(s)}};for(const i of r.roots)r.elements.has(i)&&e(i);return t}async function computeDiagramScene(r){var c,u,g,f,p,y,v,S,w;const{model:t,diagram:e,layoutProviderId:i}=r,s=resolveViewKind(e);if(nonCanvasKind(s))return null;const n=buildViewpointFilter(r),l=!!((c=e==null?void 0:e.properties)!=null&&c.layoutStyle),o=((u=e==null?void 0:e.properties)==null?void 0:u.layoutStyle)==="fbs",a=s==="general"&&!l&&!o,h=new Map;let d;if(o)d=await computeFBSLayout(t,{expandedNodes:expandAll(buildFunctionalTree(t)),nodeDirections:new Map,callbacks:NO_CALLBACKS,layoutProviderId:i});else if(l)d=computeContainmentLayout(t,{expandedNodes:expandAll(buildDecompositionTree(t)),callbacks:NO_CALLBACKS});else if((e==null?void 0:e.diagramType)==="ucd")d=computeUseCaseViewLayout(t,{systemName:e.name,...useCaseViewOptions(e.properties)});else if((e==null?void 0:e.diagramType)==="context")d=computeContextViewLayout(t,e.name);else if(s==="interconnection")d=await computeInterconnectionLayout(t,{viewpointFilter:n,relationshipTypes:e==null?void 0:e.relationshipTypes,collapsedNodes:new Set,onToggleCollapse:()=>{},portDisplay:"all",onPortMove:()=>{},layoutProviderId:i});else if(s==="actionflow")d=await computeActionFlowViewLayout(t,{viewpointFilter:n,swimlanes:((g=r.actionFlow)==null?void 0:g.swimlanes)??!0,laneGrouping:((f=r.actionFlow)==null?void 0:f.laneGrouping)??"allocation",displayLevel:((p=r.actionFlow)==null?void 0:p.displayLevel)??"all",expandedActionIds:((y=r.actionFlow)==null?void 0:y.expandedActionIds)??new Set,onToggleAction:()=>{},focusActionId:((v=r.actionFlow)==null?void 0:v.focusActionId)??void 0,visibleFlowKinds:((S=r.actionFlow)==null?void 0:S.visibleFlowKinds)??new Set(["control","data","energy","material"]),direction:((w=r.actionFlow)==null?void 0:w.direction)??"horizontal",layoutProviderId:i});else if(s==="statetransition")d=await computeStateTransitionLayout(t,{viewpointFilter:n,layoutProviderId:i});else if(s==="sequence")d=computeSequenceLayout(t,{viewpointFilter:n});else{const C=resolveGeneralMode(e==null?void 0:e.properties);a&&C!=="graph"?d=await computeGeneralViewLayout(t,{mode:C,viewpointFilter:n,expandedNodes:expandAll(buildGeneralViewTree(t,n)),nodeDirections:new Map,callbacks:NO_CALLBACKS,positionCache:h,layoutProviderId:i}):d=await computeLayout(t,{viewpointFilter:n,relationshipTypes:e==null?void 0:e.relationshipTypes,compartments:a,layoutProviderId:i})}return buildScene(d.nodes,d.edges)}const CANVAS_BG="#F7F7F5",SCENE_TIMEOUT_MS=8e3,LAYOUT_PROGRESS_STYLE_ID="memo-layout-progress";if(typeof document<"u"&&!document.getElementById(LAYOUT_PROGRESS_STYLE_ID)){const r=document.createElement("style");r.id=LAYOUT_PROGRESS_STYLE_ID,r.textContent="@keyframes memo-layout-progress { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }",document.head.appendChild(r)}function nodeStyle(r){return r.isFrame?{fillColor:"none",strokeColor:r.color,opacity:35,rounded:!0,fontColor:r.color,fontSize:11,align:"left",verticalAlign:"top",spacingLeft:8,spacingTop:4}:{fillColor:"#FFFFFF",strokeColor:r.color,strokeWidth:1.5,rounded:!0,fontColor:"#1F2937",fontSize:12,whiteSpace:"wrap",verticalAlign:"middle"}}function fitGraph(r){var t;(t=r==null?void 0:r.getPlugin("fit"))==null||t.fit({margin:24})}function fitWhenSized(r,t){let e=!1;const i=()=>e?!0:(t.clientWidth>0&&t.clientHeight>0&&(fitGraph(r),e=!0),e),s=requestAnimationFrame(i);if(i())return()=>cancelAnimationFrame(s);const n=new ResizeObserver(()=>{i()&&n.disconnect()});return n.observe(t),()=>{cancelAnimationFrame(s),n.disconnect()}}function applySavedLayout(r,t){if(!t||Object.keys(t.nodes).length===0&&Object.keys(t.edges).length===0)return r;const e=r.nodes.map(s=>{const n=t.nodes[s.id];return n?{...s,x:n.x,y:n.y,...n.width?{width:n.width}:{},...n.height?{height:n.height}:{}}:s}),i=new Map(e.map(s=>[s.id,s]));return{...r,nodes:e.map(s=>{var c;if(!s.isFrame||!((c=s.memberIds)!=null&&c.length))return s;const n=s.memberIds.map(u=>i.get(u)).filter(Boolean);if(n.length===0)return s;const l=Math.min(...n.map(u=>u.x)),o=Math.min(...n.map(u=>u.y)),a=Math.max(...n.map(u=>u.x+u.width)),h=Math.max(...n.map(u=>u.y+u.height)),d=s.orientation==="column";return{...s,x:d?l-36:l-120,y:d?o-32:o-36,width:a-l+(d?72:156),height:h-o+(d?68:72)}}),edges:r.edges.map(s=>{var l;const n=(l=t.edges[s.id])==null?void 0:l.points;return n?{...s,points:n.length>2?n.slice(1,-1).map(o=>({x:o.x,y:o.y})):[]}:s})}}function MaxGraphCanvas(){var ht;const r=useModelStore(E=>E.model),t=useModelStore(E=>E.selectedDiagramId),e=useModelStore(E=>E.selectedViewpointId),i=useModelStore(E=>E.selectedElementId),s=useModelStore(E=>E.hiddenLayers),n=useModelStore(E=>E.inspectElement),l=useModelStore(E=>E.inspectRelationship),o=useModelStore(E=>E.diagramLayouts),a=useModelStore(E=>E.mergeDiagramLayouts),h=useModelStore(E=>E.createRelationship),d=reactExports.useRef(null),c=reactExports.useRef(null),u=reactExports.useRef(r),g=reactExports.useRef(t),f=reactExports.useRef(null),[p,y]=reactExports.useState(null),[v,S]=reactExports.useState(!1),[w,C]=reactExports.useState(null),[m,M]=reactExports.useState(!0),[b,O]=reactExports.useState("allocation"),[R,H]=reactExports.useState("all"),[T,U]=reactExports.useState("horizontal"),[q,it]=reactExports.useState(new Set(["control","data","energy","material"])),[x,P]=reactExports.useState(new Set),[L,A]=reactExports.useState(null),[I,B]=reactExports.useState(0),[k,V]=reactExports.useState(null),[Y,N]=reactExports.useState(0),_=getDiagram(r,t),z=resolveViewKind(_),W=nonCanvasKind(z),G=t?o[t]:void 0,Q=selectedLayoutProviderId(G),st=reactExports.useMemo(()=>{if(!r||!_)return[];const E=new Set(_.elementIds);return commonDisplayLevels(Object.values(r.elements).filter(D=>E.has(D.id)&&D.allocatedTo).map(D=>D.allocatedTo),r)},[r,_]);reactExports.useEffect(()=>{if(!r||W){y(null);return}const E=c.current;if(u.current!==r&&g.current===t&&E){const et=E.getView();f.current={scale:et.scale,x:et.translate.x,y:et.translate.y}}else f.current=null;u.current=r,g.current=t;let j=!1;S(!0),C(null);const J=new Promise((et,rt)=>{window.setTimeout(()=>rt(new Error(`Layout exceeded ${SCENE_TIMEOUT_MS/1e3}s`)),SCENE_TIMEOUT_MS)});return Promise.race([computeDiagramScene({model:r,diagram:_??null,selectedViewpointId:e,hiddenLayers:s,layoutProviderId:Q,actionFlow:{swimlanes:m,laneGrouping:b,displayLevel:R,expandedActionIds:x,focusActionId:L,visibleFlowKinds:q,direction:T}}),J]).then(et=>{j||(y(et),S(!1))}).catch(et=>{j||(console.error("maxGraph scene error:",et),C("The diagram could not be laid out. Reduce the visible hierarchy or reset the layout."),S(!1))}),()=>{j=!0}},[r,_,t,e,s,Q,W,m,b,R,x,L,q,T]);const F=reactExports.useCallback(E=>{if(!t||E.length===0)return;const D=useModelStore.getState().diagramLayouts[t]??{nodes:{},edges:{}},j={};for(const et of E){const rt=et.getId(),nt=et.getGeometry();!rt||!nt||et.isEdge()||(j[rt]={...D.nodes[rt]??{},x:nt.x,y:nt.y,width:nt.width,height:nt.height})}if(Object.keys(j).length===0)return;const J={...D,nodes:{...D.nodes,...j},edges:D.edges??{},canvas:{...D.canvas,autoLayout:!1}};a({[t]:J}),sendDiagramLayoutUpdate(t,J)},[t,a]),$=reactExports.useRef(F);reactExports.useEffect(()=>{$.current=F},[F]);const ot=reactExports.useRef(r);reactExports.useEffect(()=>{ot.current=r},[r]),reactExports.useEffect(()=>{var bt;const E=d.current;if(!E||!p)return;InternalEvent.disableContextMenu(E);const D=new Graph(E,void 0,[...getDefaultPlugins(),RubberBandHandler]);c.current=D,D.setPanning(!0),D.setCellsEditable(!1),D.setCellsResizable(!1),D.setConnectable(!0),D.setAllowDanglingEdges(!1),D.setCellsDisconnectable(!1),D.options.foldingEnabled=!1,D.setGridEnabled(!0),D.setGridSize(20);const j=D.getPlugin("SelectionHandler");j&&(j.guidesEnabled=!0);const J=t?useModelStore.getState().diagramLayouts[t]:void 0,et=applySavedLayout(p,J),rt=D.getDefaultParent(),nt=new Map;D.batchUpdate(()=>{for(const X of et.nodes){const pt=X.parentId?nt.get(X.parentId)??rt:rt,lt=D.insertVertex({parent:pt,id:X.id,value:X.kind&&!X.isFrame?`${X.label}
|
|
13
|
+
«${X.kind}»`:X.label,x:X.x,y:X.y,width:X.width,height:X.height,style:nodeStyle(X)});X.isFrame&<.setConnectable(!1),nt.set(X.id,lt)}for(const X of et.edges){const pt=nt.get(X.sourceId),lt=nt.get(X.targetId);if(!pt||!lt)continue;const ct={strokeColor:X.color,strokeWidth:X.strokeWidth,dashed:X.dashed||X.animated,rounded:!0,endArrow:"block",endFill:!0,fontColor:"#6B7280",fontSize:10,labelBackgroundColor:"#FFFFFF",...X.points.length===0&&X.routing!=="straight"?{edgeStyle:"orthogonalEdgeStyle"}:{}},dt=D.insertEdge({parent:rt,id:X.id,value:X.label??"",source:pt,target:lt,style:ct}).getGeometry();dt&&X.points.length>0&&(dt.points=X.points.map(Ct=>new Point(Ct.x,Ct.y)))}});const vt=f.current;f.current=null;let gt;vt?D.getView().scaleAndTranslate(vt.scale,vt.x,vt.y):((bt=J==null?void 0:J.canvas)==null?void 0:bt.zoom)!==void 0&&J.canvas.pan?(D.getView().setScale(J.canvas.zoom),D.getView().setTranslate(J.canvas.pan.x,J.canvas.pan.y)):gt=fitWhenSized(D,E),D.addListener(InternalEvent.CLICK,(X,pt)=>{var dt,Ct;const lt=pt.getProperty("cell"),ct=lt==null?void 0:lt.getId();if(!ct)return;const St=useModelStore.getState();(dt=St.model)!=null&&dt.elements[ct]?n(ct):(Ct=St.model)!=null&&Ct.relationships.some(wt=>wt.id===ct)&&l(ct)}),D.addListener(InternalEvent.CELLS_MOVED,(X,pt)=>{const lt=pt.getProperty("cells")??[];$.current(lt)});const ft=D.getSelectionModel(),mt=()=>{B(D.getSelectionCells().filter(X=>!X.isEdge()).length)};ft.addListener(InternalEvent.CHANGE,mt);const Et=D.getPlugin("ConnectionHandler");Et==null||Et.addListener(InternalEvent.CONNECT,(X,pt)=>{var Pt,Mt;const lt=pt.getProperty("cell");if(!lt)return;const ct=(Pt=lt.getTerminal(!0))==null?void 0:Pt.getId(),St=(Mt=lt.getTerminal(!1))==null?void 0:Mt.getId();window.setTimeout(()=>{try{D.removeCells([lt],!1)}catch{}},0);const dt=ot.current,Ct=ct?dt==null?void 0:dt.elements[ct]:void 0,wt=St?dt==null?void 0:dt.elements[St]:void 0;Ct&&wt&&ct!==St&&V({sourceElement:Ct,targetElement:wt})});const xt=X=>{X.preventDefault(),X.deltaY<0?D.zoomIn():D.zoomOut()};return E.addEventListener("wheel",xt,{passive:!1}),()=>{gt==null||gt(),E.removeEventListener("wheel",xt),ft.removeListener(mt),B(0),c.current=null,D.destroy(),E.innerHTML=""}},[p,t,Y]),reactExports.useEffect(()=>{const E=c.current;if(!E||E.getSelectionCells().length>1)return;if(!i){E.clearSelection();return}const D=E.getDataModel().getCell(i);D&&E.getSelectionCell()!==D&&E.setSelectionCell(D)},[i,p]);const tt=reactExports.useCallback(E=>{const D=c.current;if(!D)return;const j=D.getSelectionCells().filter(J=>!J.isEdge());j.length<2||(D.alignCells(E,j),$.current(j))},[]),at=reactExports.useCallback(async E=>{const D=k==null?void 0:k.sourceElement.id;if(V(null),!t)return;const j=await h({type:E.type,sourceId:E.sourceId,targetId:E.targetId,direction:E.direction,selectedElementId:D,diagramId:t});j.success||console.warn(`[MEMO] Relationship rejected: ${j.error}`)},[k,t,h]),Z=!!G&&(Object.keys(G.nodes??{}).length>0||((ht=G.canvas)==null?void 0:ht.autoLayout)===!1),yt=reactExports.useCallback(()=>{if(!t)return;const E={nodes:{},edges:{},canvas:{autoLayout:!0}};a({[t]:E}),sendDiagramLayoutUpdate(t,E),N(D=>D+1)},[t,a]),ut=reactExports.useCallback(()=>{var rt;const E=(rt=d.current)==null?void 0:rt.querySelector("svg");if(!E)return;const D=E.cloneNode(!0);D.setAttribute("xmlns","http://www.w3.org/2000/svg"),D.style.backgroundColor=CANVAS_BG;const j=new Blob([new XMLSerializer().serializeToString(D)],{type:"image/svg+xml"}),J=URL.createObjectURL(j),et=document.createElement("a");et.href=J,et.download=`${(_==null?void 0:_.name)??"diagram"}.svg`,et.click(),URL.revokeObjectURL(J)},[_==null?void 0:_.name]);if(_&&r&&W==="grid")return jsxRuntimeExports.jsx(GridView,{diagram:_,model:r,viewpointFilter:buildViewpointFilter({model:r,diagram:_,selectedViewpointId:e,hiddenLayers:s})});if(_&&r&&W==="browser")return jsxRuntimeExports.jsx(BrowserView,{diagram:_,model:r,viewpointFilter:buildViewpointFilter({model:r,diagram:_,selectedViewpointId:e,hiddenLayers:s})});if(W==="geometry")return jsxRuntimeExports.jsx("div",{className:"flex-1 flex items-center justify-center",style:{background:CANVAS_BG,color:"#9CA3AF",fontSize:FONT.sm},children:"Geometry views are deferred (ADR-1-19)."});const K={fontSize:FONT.xs,padding:"4px 10px",background:"#FFFFFF",color:"#374151",border:"1px solid #E5E5E0",borderRadius:6,cursor:"pointer",fontWeight:600};return jsxRuntimeExports.jsxs("div",{className:"relative flex-1 overflow-hidden",style:{background:CANVAS_BG},children:[jsxRuntimeExports.jsx("div",{ref:d,className:"absolute inset-0",style:{cursor:"default"}}),z==="actionflow"&&jsxRuntimeExports.jsxs("div",{className:"absolute top-3 left-3 z-10 flex items-center gap-1.5 rounded-lg p-1.5",style:{background:"#FFFFFF",border:"1px solid #E5E5E0",boxShadow:"0 2px 8px rgba(0,0,0,0.08)"},children:[jsxRuntimeExports.jsx("button",{style:{...K,background:m?"#1B3A4B":"#FFFFFF",color:m?"#FFFFFF":"#374151"},onClick:()=>M(E=>!E),title:"Toggle swimlanes",children:"Lanes"}),m&&jsxRuntimeExports.jsx("button",{style:K,onClick:()=>O(E=>E==="allocation"?"stage":"allocation"),title:"Group lanes by allocation or stage",children:b==="allocation"?"Allocation":"Stage"}),m&&b==="allocation"&&st.length>0&&jsxRuntimeExports.jsxs("select",{value:R,onChange:E=>H(E.target.value==="all"?"all":Number(E.target.value)),style:K,title:"Responsibility hierarchy level",children:[jsxRuntimeExports.jsx("option",{value:"all",children:"All levels"}),st.map(E=>jsxRuntimeExports.jsxs("option",{value:E,children:["L",E]},E))]}),jsxRuntimeExports.jsx("button",{style:{...K,background:T==="horizontal"?"#1B3A4B":"#FFFFFF",color:T==="horizontal"?"#FFFFFF":"#374151"},onClick:()=>U("horizontal"),title:"Left-to-right flow",children:"→"}),jsxRuntimeExports.jsx("button",{style:{...K,background:T==="vertical"?"#1B3A4B":"#FFFFFF",color:T==="vertical"?"#FFFFFF":"#374151"},onClick:()=>U("vertical"),title:"Top-to-bottom flow",children:"↓"}),jsxRuntimeExports.jsx("button",{style:K,onClick:()=>P(new Set(Object.values((r==null?void 0:r.elements)??{}).map(E=>E.parentAction).filter(E=>!!E))),title:"Expand all sub-actions",children:"Expand"}),jsxRuntimeExports.jsx("button",{style:K,onClick:()=>P(new Set),title:"Collapse all sub-actions",children:"Collapse"}),["control","data","energy","material"].map(E=>jsxRuntimeExports.jsx("button",{style:{...K,textTransform:"capitalize",opacity:q.has(E)?1:.45},onClick:()=>it(D=>{const j=new Set(D);return j.has(E)?j.delete(E):j.add(E),j}),title:`Toggle ${E} flows`,children:E},E)),L&&jsxRuntimeExports.jsx("button",{style:K,onClick:()=>A(null),children:"Parent"})]}),jsxRuntimeExports.jsxs("div",{className:"absolute top-3 right-3 z-10 flex items-center gap-1.5",children:[I>=2&&jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsx("button",{style:K,onClick:()=>tt("left"),title:"Align left edges","aria-label":"Align left",children:"⇤"}),jsxRuntimeExports.jsx("button",{style:K,onClick:()=>tt("center"),title:"Align horizontal centres","aria-label":"Align centres",children:"↔"}),jsxRuntimeExports.jsx("button",{style:K,onClick:()=>tt("right"),title:"Align right edges","aria-label":"Align right",children:"⇥"}),jsxRuntimeExports.jsx("button",{style:K,onClick:()=>tt("top"),title:"Align top edges","aria-label":"Align top",children:"⤒"}),jsxRuntimeExports.jsx("button",{style:K,onClick:()=>tt("middle"),title:"Align vertical middles","aria-label":"Align middles",children:"↕"}),jsxRuntimeExports.jsx("button",{style:K,onClick:()=>tt("bottom"),title:"Align bottom edges","aria-label":"Align bottom",children:"⤓"}),jsxRuntimeExports.jsx("span",{style:{color:"#E5E5E0"},children:"|"})]}),jsxRuntimeExports.jsx("button",{style:{...K,background:Z?"#FFFFFF":"#ECFDF5",color:Z?"#374151":"#047857",borderColor:Z?"#E5E5E0":"#A7F3D0"},onClick:yt,disabled:!Z,title:Z?"Re-run automatic layout (discards manual moves)":"Layout is automatic",children:"Auto layout"}),jsxRuntimeExports.jsx("span",{style:{color:"#E5E5E0"},children:"|"}),jsxRuntimeExports.jsx("button",{style:K,onClick:()=>{var E;return(E=c.current)==null?void 0:E.zoomIn()},title:"Zoom in",children:"+"}),jsxRuntimeExports.jsx("button",{style:K,onClick:()=>{var E;return(E=c.current)==null?void 0:E.zoomOut()},title:"Zoom out",children:"-"}),jsxRuntimeExports.jsx("button",{style:K,onClick:()=>fitGraph(c.current),title:"Fit diagram to the viewport",children:"Fit view"}),jsxRuntimeExports.jsx("button",{style:K,onClick:ut,title:"Download this diagram as an SVG image",children:"Export SVG"})]}),v&&jsxRuntimeExports.jsx("div",{className:"absolute inset-x-0 top-0 z-10",style:{height:3,background:"linear-gradient(90deg, transparent, #2DD4A8, transparent)",backgroundSize:"200% 100%",animation:"memo-layout-progress 1.2s linear infinite"}}),w&&jsxRuntimeExports.jsx("div",{className:"absolute inset-x-0 top-0 z-10 px-4 py-2",style:{background:"#FEF2F2",color:"#B91C1C",fontSize:FONT.xs,borderBottom:"1px solid #FECACA"},children:w}),!v&&!w&&p&&p.nodes.length===0&&jsxRuntimeExports.jsx("div",{className:"absolute inset-0 flex items-center justify-center pointer-events-none",style:{color:"#9CA3AF",fontSize:FONT.sm},children:_?"No elements in this view.":"Select a view from the explorer."}),k&&jsxRuntimeExports.jsx(RelationshipPicker,{x:window.innerWidth/2-130,y:window.innerHeight/2-160,sourceElement:k.sourceElement,targetElement:k.targetElement,registries:getRegistries(r),onSelect:at,onCancel:()=>V(null)})]})}export{MaxGraphCanvas};
|