@memoarchitect/architect 0.6.5 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +45 -4
  2. package/dist/assets/AiWorkspace-Bu9TlIWg.js +7 -0
  3. package/dist/assets/AnalysisWorkspace-CodmoI-v.js +39 -0
  4. package/dist/assets/{ComplianceWizard-DWolzleI.js → ComplianceWizard-CTihkUi-.js} +1 -1
  5. package/dist/assets/DSMView-BiC845df.js +1 -0
  6. package/dist/assets/Dashboard-CgnNLhKq.js +1 -0
  7. package/dist/assets/{DhfDashboard-D9JxRAbD.js → DhfDashboard-w-dJoJHU.js} +1 -1
  8. package/dist/assets/{DhfWorkbench-BQv2WQ9o.js → DhfWorkbench-o6B_MT-0.js} +15 -15
  9. package/dist/assets/DiagramCanvas-CqGqDbgT.js +3 -0
  10. package/dist/assets/DiagramEditor-UJDHcAUF.js +4 -0
  11. package/dist/assets/DiagramToolbarControls-B2gZFJlg.js +1 -0
  12. package/dist/assets/ElementDetailView-10U0rr33.js +2 -0
  13. package/dist/assets/ExplorerTreeRow-DqhF_qoO.js +3 -0
  14. package/dist/assets/{ImportView-33dFwj6A.js → ImportView-D8svP04Q.js} +1 -1
  15. package/dist/assets/{LayerGrid-B3MBWswK.js → LayerGrid-DEe0Ryz-.js} +1 -1
  16. package/dist/assets/{LayerTable-DyIzIt5M.js → LayerTable-CN_b2rDr.js} +2 -2
  17. package/dist/assets/{MaxGraphCanvas-BS5wYazZ.js → MaxGraphCanvas-bo8oPBct.js} +6 -6
  18. package/dist/assets/{ModelDiff-BoFREnpg.js → ModelDiff-xe95oVua.js} +1 -1
  19. package/dist/assets/{OntologyDecompositionDiagram-IG1gj1c3.js → OntologyDecompositionDiagram-BL9R8bdB.js} +1 -1
  20. package/dist/assets/{OntologyViewer-CQTEg-GI.js → OntologyViewer-CtqNkkCn.js} +2 -2
  21. package/dist/assets/{RelationshipOverlay-B9bqt4zl.js → RelationshipOverlay-DL0N8Vmk.js} +1 -1
  22. package/dist/assets/{RelationshipsSection-DttMvF2i.js → RelationshipsSection-BoJ0aUXe.js} +1 -1
  23. package/dist/assets/{ReviewDashboard-BJ_smBGS.js → ReviewDashboard-DeTge2oC.js} +1 -1
  24. package/dist/assets/ScenarioEditor-FAEYTHgP.js +3 -0
  25. package/dist/assets/{StatisticsDashboard-CBYJGUPH.js → StatisticsDashboard-BAZRqIPN.js} +1 -1
  26. package/dist/assets/{SysmlCodeEditor-Die2RUsz.js → SysmlCodeEditor-BBfup_Ni.js} +1 -1
  27. package/dist/assets/TabularView-I4LjHhoH.js +1 -0
  28. package/dist/assets/TraceabilityMatrix-DbrvjqLN.js +3 -0
  29. package/dist/assets/UiScreensWorkspace-DDD_PyJs.js +1 -0
  30. package/dist/assets/{WorkflowWizard-CbkDyd1W.js → WorkflowWizard-VwpEHt3R.js} +1 -1
  31. package/dist/assets/element-options-B7AgTB8R.js +3 -0
  32. package/dist/assets/html2canvas.esm-QH1iLAAe.js +22 -0
  33. package/dist/assets/index-BWMNo4wW.css +1 -0
  34. package/dist/assets/index-Bij8Q4Kg.js +45 -0
  35. package/dist/assets/index.es-ClbJxlAQ.js +18 -0
  36. package/dist/assets/jspdf.es.min-DZ68BGxk.js +170 -0
  37. package/dist/assets/notation-scene-DT8LpWVK.js +1 -0
  38. package/dist/assets/purify.es-DP5U8-sc.js +3 -0
  39. package/dist/assets/{reactflow-CsCqNKB-.js → reactflow-s7jmJtXx.js} +5 -5
  40. package/dist/index.html +3 -3
  41. package/lib/__tests__/compiler-bundling.test.d.ts +2 -0
  42. package/lib/__tests__/compiler-bundling.test.d.ts.map +1 -0
  43. package/lib/__tests__/compiler-bundling.test.js +32 -0
  44. package/lib/__tests__/compiler-bundling.test.js.map +1 -0
  45. package/lib/__tests__/standard-sysml-diagrams-smoke.test.d.ts +2 -0
  46. package/lib/__tests__/standard-sysml-diagrams-smoke.test.d.ts.map +1 -0
  47. package/lib/__tests__/standard-sysml-diagrams-smoke.test.js +22 -0
  48. package/lib/__tests__/standard-sysml-diagrams-smoke.test.js.map +1 -0
  49. package/lib/__tests__/supervised-child-args.test.d.ts +2 -0
  50. package/lib/__tests__/supervised-child-args.test.d.ts.map +1 -0
  51. package/lib/__tests__/supervised-child-args.test.js +35 -0
  52. package/lib/__tests__/supervised-child-args.test.js.map +1 -0
  53. package/lib/bin/memo-architect.js +30 -4
  54. package/lib/bin/memo-architect.js.map +1 -1
  55. package/lib/commands/dev.d.ts +18 -2
  56. package/lib/commands/dev.d.ts.map +1 -1
  57. package/lib/commands/dev.js +56 -8
  58. package/lib/commands/dev.js.map +1 -1
  59. package/lib/commands/example.d.ts +1 -0
  60. package/lib/commands/example.d.ts.map +1 -1
  61. package/lib/commands/example.js +2 -0
  62. package/lib/commands/example.js.map +1 -1
  63. package/lib/feature-grants.d.ts.map +1 -1
  64. package/lib/feature-grants.js +2 -2
  65. package/lib/feature-grants.js.map +1 -1
  66. package/package.json +12 -6
  67. package/dist/assets/AiWorkspace-DHZ6a9HJ.js +0 -3
  68. package/dist/assets/DSMView-TdC3EADB.js +0 -1
  69. package/dist/assets/Dashboard-DBfAOCJv.js +0 -1
  70. package/dist/assets/DhfSettingsPanel-Firov0IF.js +0 -1
  71. package/dist/assets/DiagramCanvas-BfwO8YE5.js +0 -1
  72. package/dist/assets/DiagramEditor-Cp9ORYoN.js +0 -4
  73. package/dist/assets/ElementDetailView-DOrG8v7V.js +0 -2
  74. package/dist/assets/ScenarioEditor-D06nbX4h.js +0 -3
  75. package/dist/assets/TabularView-BLzDtgmK.js +0 -1
  76. package/dist/assets/TraceabilityMatrix-DbL_FkAC.js +0 -1
  77. package/dist/assets/index-B8HDzVLs.css +0 -1
  78. package/dist/assets/index-D0vtjNjX.js +0 -3280
  79. package/dist/assets/layout-selection-DIQaaOIC.js +0 -1
@@ -1,13 +1,13 @@
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-D0vtjNjX.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-DIQaaOIC.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==`
1
+ import{j as jsxRuntimeExports}from"./reactflow-s7jmJtXx.js";import{a as reactExports}from"./zustand-CrhqMOHB.js";import{D as DIAGRAM_TYPE_META,u as useModelStore,g as getDiagram,I as sendDiagramLayoutUpdate,F as FONT,i as getRegistries}from"./index-Bij8Q4Kg.js";import{c as computeFBSLayout,B as buildFunctionalTree,b as computeContainmentLayout,D 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,z as buildGeneralViewTree,k as computeLayout,N as projectLayoutToNotationScene,s as selectedLayoutProviderId,n as commonDisplayLevels,O as notationSceneToSvg,F as GridView,H as BrowserView,R as RelationshipPicker}from"./notation-scene-DT8LpWVK.js";import{S as ScreenLayoutView}from"./ExplorerTreeRow-DqhF_qoO.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 Mt;Client.IS_SVG=isWindowObjectAvailable()&&((Mt=navigator.appName)==null?void 0:Mt.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(`
5
5
  `))}}return e(r),t.join("")},write=(r,t)=>{const i=r.ownerDocument.createTextNode(t);return r&&r.appendChild(i),i},isNode=(r,t=null,e,i)=>!isNullish(r)&&typeof r.nodeType=="number"&&(isNullish(t)||r.nodeName.toLowerCase()==t.toLowerCase())?isNullish(e)||r.getAttribute(e)==i:!1,isAncestorNode=(r,t)=>{let e=t;for(;e!=null;){if(e===r)return!0;e=e.parentNode}return!1},clearSelection=()=>{const r=window.getSelection?window.getSelection():document.selection;r&&(r.removeAllRanges?r.removeAllRanges():r.empty&&r.empty())};class InternalMouseEvent{constructor(t,e=null){this.consumed=!1,this.evt=t,this.state=e,this.sourceState=e,this.graphX=0,this.graphY=0}getEvent(){return this.evt}getSource(){return getSource(this.evt)}isSource(t){return t?isAncestorNode(t.node,this.getSource()):!1}getX(){return getClientX(this.getEvent())}getY(){return getClientY(this.getEvent())}getGraphX(){return this.graphX}getGraphY(){return this.graphY}getState(){return this.state}getCell(){const t=this.getState();return t?t.cell:null}isPopupTrigger(){return isPopupTrigger(this.getEvent())}isConsumed(){return this.consumed}consume(t){t=t||window.TouchEvent&&this.evt instanceof TouchEvent||isMouseEvent(this.evt),t&&this.evt.preventDefault&&this.evt.preventDefault(),this.consumed=!0}}let supportsPassive=!1;try{document.addEventListener("test",()=>{},Object.defineProperty&&Object.defineProperty({},"passive",{get:()=>{supportsPassive=!0}}))}catch(r){}class InternalEvent{static addListener(t,e,i){t.addEventListener(e,i,supportsPassive?{passive:!1}:!1),t.mxListenerList||(t.mxListenerList=[]);const s={name:e,f:i};t.mxListenerList.push(s)}static removeListener(t,e,i){if(t.removeEventListener(e,i,!1),t.mxListenerList){const s=t.mxListenerList.length;for(let n=0;n<s;n+=1)if(t.mxListenerList[n].f===i){t.mxListenerList.splice(n,1);break}}}static removeAllListeners(t){const e=t.mxListenerList;if(e)for(;e.length>0;){const i=e[0];InternalEvent.removeListener(t,i.name,i.f)}}static addGestureListeners(t,e=null,i=null,s=null){e&&InternalEvent.addListener(t,Client.IS_POINTER?"pointerdown":"mousedown",e),i&&InternalEvent.addListener(t,Client.IS_POINTER?"pointermove":"mousemove",i),s&&InternalEvent.addListener(t,Client.IS_POINTER?"pointerup":"mouseup",s),!Client.IS_POINTER&&Client.IS_TOUCH&&(e&&InternalEvent.addListener(t,"touchstart",e),i&&InternalEvent.addListener(t,"touchmove",i),s&&InternalEvent.addListener(t,"touchend",s))}static removeGestureListeners(t,e,i,s){e&&InternalEvent.removeListener(t,Client.IS_POINTER?"pointerdown":"mousedown",e),i&&InternalEvent.removeListener(t,Client.IS_POINTER?"pointermove":"mousemove",i),s&&InternalEvent.removeListener(t,Client.IS_POINTER?"pointerup":"mouseup",s),!Client.IS_POINTER&&Client.IS_TOUCH&&(e&&InternalEvent.removeListener(t,"touchstart",e),i&&InternalEvent.removeListener(t,"touchmove",i),s&&InternalEvent.removeListener(t,"touchend",s))}static redirectMouseEvents(t,e,i=null,s=null,n=null,l=null,o=null){const a=h=>typeof i=="function"?i(h):i;InternalEvent.addGestureListeners(t,h=>{s?s(h):isConsumed(h)||e.fireMouseEvent(InternalEvent.MOUSE_DOWN,new InternalMouseEvent(h,a(h)))},h=>{n?n(h):isConsumed(h)||e.fireMouseEvent(InternalEvent.MOUSE_MOVE,new InternalMouseEvent(h,a(h)))},h=>{l?l(h):isConsumed(h)||e.fireMouseEvent(InternalEvent.MOUSE_UP,new InternalMouseEvent(h,a(h)))}),InternalEvent.addListener(t,"dblclick",h=>{if(o)o(h);else if(!isConsumed(h)){const d=a(h);e.dblClick(h,d==null?void 0:d.cell)}})}static release(t){try{InternalEvent.removeAllListeners(t);const e=t.childNodes;if(e!==void 0){const i=e.length;for(let s=0;s<i;s+=1)InternalEvent.release(e[s])}}catch{}}static addMouseWheelListener(t,e){if(t!=null){const i=s=>{s.ctrlKey&&s.preventDefault(),(Math.abs(s.deltaX)>.5||Math.abs(s.deltaY)>.5)&&t(s,s.deltaY==0?-s.deltaX>0:-s.deltaY>0)};if(e=e??window,Client.IS_SF&&!Client.IS_TOUCH){let s=1;InternalEvent.addListener(e,"gesturestart",n=>{InternalEvent.consume(n),s=1}),InternalEvent.addListener(e,"gesturechange",(n=>{if(InternalEvent.consume(n),typeof n.scale=="number"){const l=s-n.scale;Math.abs(l)>.2&&(t(n,l<0,!0),s=n.scale)}})),InternalEvent.addListener(e,"gestureend",n=>{InternalEvent.consume(n)})}else{let s=[],n=0,l=0;InternalEvent.addGestureListeners(e,(o=>{!isMouseEvent(o)&&o.pointerId!=null&&s.push(o)}),(o=>{if(!isMouseEvent(o)&&s.length==2){for(let u=0;u<s.length;u+=1)if(o.pointerId==s[u].pointerId){s[u]=o;break}const a=Math.abs(s[0].clientX-s[1].clientX),h=Math.abs(s[0].clientY-s[1].clientY),d=Math.abs(a-n),c=Math.abs(h-l);if(d>InternalEvent.PINCH_THRESHOLD||c>InternalEvent.PINCH_THRESHOLD){const u=s[0].clientX+(s[1].clientX-s[0].clientX)/2,g=s[0].clientY+(s[1].clientY-s[0].clientY)/2;t(s[0],d>c?a>n:h>l,!0,u,g),n=a,l=h}}}),o=>{s=[],n=0,l=0})}InternalEvent.addListener(e,"wheel",i)}}static disableContextMenu(t){InternalEvent.addListener(t,"contextmenu",e=>(e.preventDefault&&e.preventDefault(),!1))}static consume(t,e=!0,i=!0){e&&(t.preventDefault?(i&&t.stopPropagation(),t.preventDefault()):i&&(t.cancelBubble=!0)),t.isConsumed=!0,t.preventDefault||(t.returnValue=!1)}}InternalEvent.LABEL_HANDLE=-1;InternalEvent.ROTATION_HANDLE=-2;InternalEvent.CUSTOM_HANDLE=-100;InternalEvent.VIRTUAL_HANDLE=-1e5;InternalEvent.MOUSE_DOWN="mouseDown";InternalEvent.MOUSE_MOVE="mouseMove";InternalEvent.MOUSE_UP="mouseUp";InternalEvent.ACTIVATE="activate";InternalEvent.RESIZE_START="resizeStart";InternalEvent.RESIZE="resize";InternalEvent.RESIZE_END="resizeEnd";InternalEvent.MOVE_START="moveStart";InternalEvent.MOVE="move";InternalEvent.MOVE_END="moveEnd";InternalEvent.PAN_START="panStart";InternalEvent.PAN="pan";InternalEvent.PAN_END="panEnd";InternalEvent.MINIMIZE="minimize";InternalEvent.NORMALIZE="normalize";InternalEvent.MAXIMIZE="maximize";InternalEvent.HIDE="hide";InternalEvent.SHOW="show";InternalEvent.CLOSE="close";InternalEvent.DESTROY="destroy";InternalEvent.REFRESH="refresh";InternalEvent.SIZE="size";InternalEvent.SELECT="select";InternalEvent.FIRED="fired";InternalEvent.FIRE_MOUSE_EVENT="fireMouseEvent";InternalEvent.GESTURE="gesture";InternalEvent.TAP_AND_HOLD="tapAndHold";InternalEvent.GET="get";InternalEvent.RECEIVE="receive";InternalEvent.CONNECT="connect";InternalEvent.DISCONNECT="disconnect";InternalEvent.SUSPEND="suspend";InternalEvent.RESUME="resume";InternalEvent.MARK="mark";InternalEvent.ROOT="root";InternalEvent.POST="post";InternalEvent.OPEN="open";InternalEvent.SAVE="save";InternalEvent.BEFORE_ADD_VERTEX="beforeAddVertex";InternalEvent.ADD_VERTEX="addVertex";InternalEvent.AFTER_ADD_VERTEX="afterAddVertex";InternalEvent.DONE="done";InternalEvent.EXECUTE="execute";InternalEvent.EXECUTED="executed";InternalEvent.BEGIN_UPDATE="beginUpdate";InternalEvent.START_EDIT="startEdit";InternalEvent.END_UPDATE="endUpdate";InternalEvent.END_EDIT="endEdit";InternalEvent.BEFORE_UNDO="beforeUndo";InternalEvent.UNDO="undo";InternalEvent.REDO="redo";InternalEvent.CHANGE="change";InternalEvent.NOTIFY="notify";InternalEvent.LAYOUT_CELLS="layoutCells";InternalEvent.CLICK="click";InternalEvent.SCALE="scale";InternalEvent.TRANSLATE="translate";InternalEvent.SCALE_AND_TRANSLATE="scaleAndTranslate";InternalEvent.UP="up";InternalEvent.DOWN="down";InternalEvent.ADD="add";InternalEvent.REMOVE="remove";InternalEvent.CLEAR="clear";InternalEvent.ADD_CELLS="addCells";InternalEvent.CELLS_ADDED="cellsAdded";InternalEvent.MOVE_CELLS="moveCells";InternalEvent.CELLS_MOVED="cellsMoved";InternalEvent.RESIZE_CELLS="resizeCells";InternalEvent.CELLS_RESIZED="cellsResized";InternalEvent.TOGGLE_CELLS="toggleCells";InternalEvent.CELLS_TOGGLED="cellsToggled";InternalEvent.ORDER_CELLS="orderCells";InternalEvent.CELLS_ORDERED="cellsOrdered";InternalEvent.REMOVE_CELLS="removeCells";InternalEvent.CELLS_REMOVED="cellsRemoved";InternalEvent.GROUP_CELLS="groupCells";InternalEvent.UNGROUP_CELLS="ungroupCells";InternalEvent.REMOVE_CELLS_FROM_PARENT="removeCellsFromParent";InternalEvent.FOLD_CELLS="foldCells";InternalEvent.CELLS_FOLDED="cellsFolded";InternalEvent.ALIGN_CELLS="alignCells";InternalEvent.LABEL_CHANGED="labelChanged";InternalEvent.CONNECT_CELL="connectCell";InternalEvent.CELL_CONNECTED="cellConnected";InternalEvent.SPLIT_EDGE="splitEdge";InternalEvent.FLIP_EDGE="flipEdge";InternalEvent.START_EDITING="startEditing";InternalEvent.EDITING_STARTED="editingStarted";InternalEvent.EDITING_STOPPED="editingStopped";InternalEvent.ADD_OVERLAY="addOverlay";InternalEvent.REMOVE_OVERLAY="removeOverlay";InternalEvent.UPDATE_CELL_SIZE="updateCellSize";InternalEvent.ESCAPE="escape";InternalEvent.DOUBLE_CLICK="doubleClick";InternalEvent.START="start";InternalEvent.RESET="reset";InternalEvent.PINCH_THRESHOLD=10;class Point{constructor(t=0,e=0){this._x=0,this._y=0,this.x=t,this.y=e}get x(){return this._x}set x(t){if(Number.isNaN(t))throw new Error("Invalid x supplied.");this._x=t}get y(){return this._y}set y(t){if(Number.isNaN(t))throw new Error("Invalid y supplied.");this._y=t}equals(t){return t?t.x===this.x&&t.y===this.y:!1}clone(){return new Point(this.x,this.y)}}class Rectangle extends Point{constructor(t=0,e=0,i=0,s=0){super(t,e),this._width=0,this._height=0,this.width=i,this.height=s}get width(){return this._width}set width(t){if(Number.isNaN(t))throw new Error("Invalid width supplied.");this._width=t}get height(){return this._height}set height(t){if(Number.isNaN(t))throw new Error("Invalid height supplied.");this._height=t}setRect(t,e,i,s){this.x=t,this.y=e,this.width=i,this.height=s}getCenterX(){return this.x+this.width/2}getCenterY(){return this.y+this.height/2}add(t){const e=Math.min(this.x,t.x),i=Math.min(this.y,t.y),s=Math.max(this.x+this.width,t.x+t.width),n=Math.max(this.y+this.height,t.y+t.height);this.x=e,this.y=i,this.width=s-e,this.height=n-i}intersect(t){const e=this.x+this.width,i=t.x+t.width,s=this.y+this.height,n=t.y+t.height;this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.width=Math.min(e,i)-this.x,this.height=Math.min(s,n)-this.y}grow(t){this.x-=t,this.y-=t,this.width+=2*t,this.height+=2*t}getPoint(){return new Point(this.x,this.y)}rotate90(){const t=(this.width-this.height)/2;this.x+=t,this.y-=t;const e=this.width;this.width=this.height,this.height=e}equals(t){return t?t.x===this.x&&t.y===this.y&&t.width===this.width&&t.height===this.height:!1}clone(){return new Rectangle(this.x,this.y,this.width,this.height)}}Rectangle.fromRectangle=r=>new Rectangle(r.x,r.y,r.width,r.height);class CellPath{constructor(){throw new Error("Static class can't be instantiated!")}static create(t){let e="",i=t.getParent();for(;i;)e=i.getIndex(t)+CellPath.PATH_SEPARATOR+e,t=i,i=t.getParent();const s=e.length;return s>1&&(e=e.substring(0,s-1)),e}static getParentPath(t){const e=t.lastIndexOf(CellPath.PATH_SEPARATOR);return e>=0?t.substring(0,e):t.length>0?"":null}static resolve(t,e){let i=t;const s=e.split(CellPath.PATH_SEPARATOR);for(let n=0;n<s.length;n+=1)i=i.getChildAt(Number.parseInt(s[n]));return i}static compare(t,e){const i=Math.min(t.length,e.length);let s=0;for(let n=0;n<i;n+=1)if(t[n]!==e[n]){if(t[n].length===0||e[n].length===0)s=t[n]===e[n]?0:t[n]>e[n]?1:-1;else{const l=Number.parseInt(t[n]),o=Number.parseInt(e[n]);s=l===o?0:l>o?1:-1}break}if(s===0){const n=t.length,l=e.length;n!==l&&(s=n>l?1:-1)}return s}}CellPath.PATH_SEPARATOR=".";const getCurrentStyle=r=>!r||r.toString()==="[object ShadowRoot]"?null:window.getComputedStyle(r,""),parseCssNumber=r=>{switch(r){case"thin":{r="2";break}case"medium":{r="4";break}case"thick":{r="6";break}}let t=Number.parseFloat(r);return Number.isNaN(t)&&(t=0),t},setPrefixedStyle=(r,t,e)=>{let i=null;Client.IS_SF||Client.IS_GC?i="Webkit":Client.IS_MT&&(i="Moz"),r.setProperty(t,e),i!==null&&t.length>0&&(t=i+t.substring(0,1).toUpperCase()+t.substring(1),r.setProperty(t,e))},hasScrollbars=r=>{const t=getCurrentStyle(r);return!!t&&(t.overflow==="scroll"||t.overflow==="auto")},getDocumentSize=()=>{const r=document.body,t=document.documentElement;try{return new Rectangle(0,0,r.clientWidth??t.clientWidth,Math.max(r.clientHeight??0,t.clientHeight))}catch{return new Rectangle}},fit=r=>{const t=getDocumentSize(),e=r.offsetLeft,i=r.offsetWidth,s=getDocumentScrollOrigin(r.ownerDocument),n=s.x,l=s.y,o=n+t.width;e+i>o&&(r.style.left=`${Math.max(n,o-i)}px`);const a=r.offsetTop,h=r.offsetHeight,d=l+t.height;a+h>d&&(r.style.top=`${Math.max(l,d-h)}px`)},getOffset=(r,t=!1)=>{let e=0,i=0,s=!1,n=r;const l=document.body,o=document.documentElement;for(;n!=null&&n!=l&&n!=o&&!s;){const h=getCurrentStyle(n);h!=null&&(s=s||h.position=="fixed"),n=n.parentNode}if(!t&&!s){const h=getDocumentScrollOrigin(r.ownerDocument);e+=h.x,i+=h.y}const a=r.getBoundingClientRect();return a!=null&&(e+=a.left,i+=a.top),new Point(e,i)},getDocumentScrollOrigin=r=>{const t=r.defaultView||r.parentWindow,e=t!=null&&window.pageXOffset!==void 0?window.pageXOffset:(document.documentElement||document.body.parentNode||document.body).scrollLeft,i=t!=null&&window.pageYOffset!==void 0?window.pageYOffset:(document.documentElement||document.body.parentNode||document.body).scrollTop;return new Point(e,i)},getScrollOrigin=(r=null,t=!1,e=!0)=>{const i=r!=null?r.ownerDocument:document,s=i.body,n=i.documentElement,l=new Point;let o=!1;for(;r!=null&&r!=s&&r!=n;){!Number.isNaN(r.scrollLeft)&&!Number.isNaN(r.scrollTop)&&(l.x+=r.scrollLeft,l.y+=r.scrollTop);const a=getCurrentStyle(r);a!=null&&(o=o||a.position=="fixed"),r=t?r.parentNode:null}if(!o&&e){const a=getDocumentScrollOrigin(i);l.x+=a.x,l.y+=a.y}return l},convertPoint=(r,t,e)=>{const i=getScrollOrigin(r,!1),s=getOffset(r);return s.x-=i.x,s.y-=i.y,new Point(t-s.x,e-s.y)},setCellStyles=(r,t,e,i)=>{t.length>0&&r.batchUpdate(()=>{for(let s=0;s<t.length;s+=1){const n=t[s];if(n){const l=n.getClonedStyle();l[e]=i,r.setStyle(n,l)}}})},setCellStyleFlags=(r,t,e,i,s)=>{t.length>0&&r.batchUpdate(()=>{for(let n=0;n<t.length;n+=1){const l=t[n];if(l){const o=setStyleFlag(l.getClonedStyle(),e,i,s);r.setStyle(l,o)}}})},setStyleFlag=(r,t,e,i)=>{const s=r[t];return s===void 0?r[t]=i===void 0||i?e:0:i===void 0?r[t]=s^e:i?r[t]=s|e:r[t]=s&~e,r},setOpacity=(r,t)=>{r.style.opacity=String(t/100)},getSizeForString=(r,t=StyleDefaultsConfig.fontSize,e=StyleDefaultsConfig.fontFamily,i=null,s=null)=>{const n=document.createElement("div");if(n.style.fontFamily=e,n.style.fontSize=`${Math.round(t)}px`,n.style.lineHeight=`${Math.round(t*LINE_HEIGHT)}px`,s!==null){matchBinaryMask(s,FONT_STYLE_MASK.BOLD)&&(n.style.fontWeight="bold"),matchBinaryMask(s,FONT_STYLE_MASK.ITALIC)&&(n.style.fontStyle="italic");const o=[];matchBinaryMask(s,FONT_STYLE_MASK.UNDERLINE)&&o.push("underline"),matchBinaryMask(s,FONT_STYLE_MASK.STRIKETHROUGH)&&o.push("line-through"),o.length>0&&(n.style.textDecoration=o.join(" "))}n.style.position="absolute",n.style.visibility="hidden",n.style.display="inline-block",i!==null?(n.style.width=`${i}px`,n.style.whiteSpace="normal"):n.style.whiteSpace="nowrap",n.innerHTML=r,document.body.appendChild(n);const l=new Rectangle(0,0,n.offsetWidth,n.offsetHeight);return document.body.removeChild(n),l},sortCells=(r,t=!0)=>{const e=new Map;return r.sort((i,s)=>{let n=e.get(i);n==null&&(n=CellPath.create(i).split(CellPath.PATH_SEPARATOR),e.set(i,n));let l=e.get(s);l==null&&(l=CellPath.create(s).split(CellPath.PATH_SEPARATOR),e.set(s,l));const o=CellPath.compare(n,l);return o==0?0:o>0==t?1:-1}),r},getAlignmentAsPoint=(r,t)=>{let e=-.5,i=-.5;return r==="left"?e=0:r==="right"&&(e=-1),t==="top"?i=0:t==="bottom"&&(i=-1),new Point(e,i)},ltrim=(r,t="\\s")=>r!=null?r.replace(new RegExp(`^[${t}]+`,"g"),""):null,rtrim=(r,t="\\s")=>r!=null?r.replace(new RegExp(`[${t}]+$`,"g"),""):null,trim=(r,t)=>ltrim(rtrim(r,t),t),getFunctionName=r=>{let t=null;if(r!=null){if(r.name!=null)t=r.name;else if(t=trim(r.toString()),t!==null&&/^function\s/.test(t)&&(t=ltrim(t.substring(9)),t!==null)){const e=t.indexOf("(");e>0&&(t=t.substring(0,e))}}return t},replaceTrailingNewlines=(r,t)=>{let e="";for(;r.length>0&&r.charAt(r.length-1)==`
6
- `;)r=r.substring(0,r.length-1),e+=t;return r+e},htmlEntities=(r,t=!0)=>(r=String(r||""),r=r.replace(/&/g,"&amp;"),r=r.replace(/"/g,"&quot;"),r=r.replace(/'/g,"&#39;"),r=r.replace(/</g,"&lt;"),r=r.replace(/>/g,"&gt;"),t&&(r=r.replace(/\n/g,"&#xa;")),r);class ObjectIdentity{static get(t){if(t){if(t[IDENTITY_FIELD_NAME]===null||t[IDENTITY_FIELD_NAME]===void 0)if(typeof t=="object"){const e=getFunctionName(t.constructor);t[IDENTITY_FIELD_NAME]=`${e}#${ObjectIdentity.counter++}`}else typeof t=="function"&&(t[IDENTITY_FIELD_NAME]=`Function#${ObjectIdentity.counter++}`);return t[IDENTITY_FIELD_NAME]}return null}static clear(t){delete t[IDENTITY_FIELD_NAME]}}ObjectIdentity.FIELD_NAME=IDENTITY_FIELD_NAME;ObjectIdentity.counter=0;const clone=function r(t,e=null,i=!1){i=i??!1;let s=null;if(t!=null&&typeof t.constructor=="function"){s=new t.constructor;for(const n in t)n!=ObjectIdentity.FIELD_NAME&&(e==null||!e.includes(n))&&(!i&&typeof t[n]=="object"?s[n]=r(t[n]):s[n]=t[n])}return s};class Cell{constructor(t=null,e=null,i={}){this.invalidating=!1,this.onInit=null,this.overlays=[],this.id=null,this.value=null,this.geometry=null,this.style={},this.vertex=!1,this.edge=!1,this.connectable=!0,this.visible=!0,this.collapsed=!1,this.parent=null,this.source=null,this.target=null,this.children=[],this.edges=[],this.mxTransient=["id","value","parent","source","target","children","edges"],this.value=t,this.setGeometry(e),this.setStyle(i),this.onInit&&this.onInit()}getChildren(){return this.children||[]}getId(){return this.id}setId(t){this.id=t}getValue(){return this.value}setValue(t){this.value=t}valueChanged(t){const e=this.getValue();return this.setValue(t),e}getGeometry(){return this.geometry}setGeometry(t){this.geometry=t}getStyle(){return this.style}getClonedStyle(){return clone(this.getStyle())}setStyle(t){this.style=t}isVertex(){return this.vertex}setVertex(t){this.vertex=t}isEdge(){return this.edge}setEdge(t){this.edge=t}isConnectable(){return this.connectable}setConnectable(t){this.connectable=t}isVisible(){return this.visible}setVisible(t){this.visible=t}isCollapsed(){return this.collapsed}setCollapsed(t){this.collapsed=t}getParent(){return this.parent}setParent(t){this.parent=t}getTerminal(t=!1){return t?this.source:this.target}setTerminal(t,e){return e?this.source=t:this.target=t,t}getChildCount(){return this.children.length}getIndex(t){return t===null?-1:this.children.indexOf(t)}getChildAt(t){return this.children[t]}insert(t,e){return e===void 0&&(e=this.getChildCount(),t.getParent()===this&&e--),t.removeFromParent(),t.setParent(this),this.children.splice(e,0,t),t}remove(t){let e=null;return t>=0&&(e=this.getChildAt(t),e&&(this.children.splice(t,1),e.setParent(null))),e}removeFromParent(){if(this.parent){const t=this.parent.getIndex(this);this.parent.remove(t)}}getEdgeCount(){return this.edges.length}getEdgeIndex(t){return this.edges.indexOf(t)}getEdgeAt(t){return this.edges[t]}insertEdge(t,e=!1){return t.removeFromTerminal(e),t.setTerminal(this,e),(this.edges.length===0||t.getTerminal(!e)!==this||!this.edges.includes(t))&&this.edges.push(t),t}removeEdge(t,e=!1){if(t!=null){if(t.getTerminal(!e)!==this&&this.edges!=null){const i=this.getEdgeIndex(t);i>=0&&this.edges.splice(i,1)}t.setTerminal(null,e)}return t}removeFromTerminal(t){const e=this.getTerminal(t);e&&e.removeEdge(this,t)}hasAttribute(t){var i;const e=this.getValue();return isElement(e)&&e.hasAttribute?e.hasAttribute(t):!isNullish((i=e.getAttribute)==null?void 0:i.call(e,t))}getAttribute(t,e){var n;const i=this.getValue();return(isElement(i)?(n=i.getAttribute)==null?void 0:n.call(i,t):null)??e}setAttribute(t,e){var s;const i=this.getValue();isElement(i)&&((s=i.setAttribute)==null||s.call(i,t,e))}clone(){const t=clone(this,this.mxTransient);return t.setValue(this.cloneValue()),t}cloneValue(){let t=this.getValue();return isNullish(t)||(typeof t.clone=="function"?t=t.clone():!isNullish(t.nodeType)&&t.cloneNode&&(t=t.cloneNode(!0))),t}getNearestCommonAncestor(t){let e=CellPath.create(t);if(e.length>0){let i=this,s=CellPath.create(i);if(e.length<s.length){i=t;const n=s;s=e,e=n}for(;i&&s;){const n=i.getParent();if(e.indexOf(s+CellPath.PATH_SEPARATOR)===0&&n)return i;s=CellPath.getParentPath(s),i=n}}return null}isAncestor(t){for(;t&&t!==this;)t=t.getParent();return t===this}getChildVertices(){return this.getChildCells(!0,!1)}getChildEdges(){return this.getChildCells(!1,!0)}getChildCells(t=!1,e=!1){const i=this.getChildCount(),s=[];for(let n=0;n<i;n+=1){const l=this.getChildAt(n);(!e&&!t||e&&l.isEdge()||t&&l.isVertex())&&s.push(l)}return s}getDirectedEdgeCount(t,e=null){let i=0;const s=this.getEdgeCount();for(let n=0;n<s;n+=1){const l=this.getEdgeAt(n);l!==e&&l&&l.getTerminal(t)===this&&(i+=1)}return i}getConnections(){return this.getEdges(!0,!0,!1)}getIncomingEdges(){return this.getEdges(!0,!1,!1)}getOutgoingEdges(){return this.getEdges(!1,!0,!1)}getEdges(t=!0,e=!0,i=!0){const s=this.getEdgeCount(),n=[];for(let l=0;l<s;l+=1){const o=this.getEdgeAt(l),a=o.getTerminal(!0),h=o.getTerminal(!1);(i&&a===h||a!==h&&(t&&h===this||e&&a===this))&&n.push(o)}return n}getOrigin(){let t=new Point;const e=this.getParent();if(e&&(t=e.getOrigin(),!this.isEdge())){const i=this.getGeometry();i&&(t.x+=i.x,t.y+=i.y)}return t}getDescendants(){return this.filterDescendants(null)}filterDescendants(t){let e=[];(t===null||t(this))&&e.push(this);const i=this.getChildCount();for(let s=0;s<i;s+=1){const n=this.getChildAt(s);e=e.concat(n.filterDescendants(t))}return e}getRoot(){let t=this,e=t;for(;t;)e=t,t=t.getParent();return e}}class ChildChange{constructor(t,e,i,s=0){this.model=t,this.parent=e,this.previous=e,this.child=i,this.index=s,this.previousIndex=s}execute(){let t=this.child.getParent();const e=t?t.getIndex(this.child):0;this.previous||this.connect(this.child,!1),t=this.model.parentForCellChanged(this.child,this.previous,this.previousIndex),this.previous&&this.connect(this.child,!0),this.parent=this.previous,this.previous=t,this.index=this.previousIndex,this.previousIndex=e}connect(t,e=!0){const i=t.getTerminal(!0),s=t.getTerminal(!1);i&&(e?this.model.terminalForCellChanged(t,i,!0):this.model.terminalForCellChanged(t,null,!0)),s&&(e?this.model.terminalForCellChanged(t,s,!1):this.model.terminalForCellChanged(t,null,!1)),t.setTerminal(i,!0),t.setTerminal(s,!1);const n=t.getChildCount();for(let l=0;l<n;l+=1)this.connect(t.getChildAt(l),e)}}class GeometryChange{constructor(t,e,i){this.model=t,this.cell=e,this.geometry=i,this.previous=i}execute(){this.geometry=this.previous,this.previous=this.model.geometryForCellChanged(this.cell,this.previous)}}class RootChange{constructor(t,e){this.model=t,this.root=e,this.previous=e}execute(){this.root=this.previous,this.previous=this.model.rootChanged(this.previous)}}class StyleChange{constructor(t,e,i){this.model=t,this.cell=e,this.style=i,this.previous=i}execute(){this.style=this.previous,this.previous=this.model.styleForCellChanged(this.cell,this.previous)}}class TerminalChange{constructor(t,e,i,s){this.model=t,this.cell=e,this.terminal=i,this.previous=i,this.source=s}execute(){this.terminal=this.previous,this.previous=this.model.terminalForCellChanged(this.cell,this.previous,this.source)}}class ValueChange{constructor(t,e,i){this.model=t,this.cell=e,this.value=i,this.previous=i}execute(){this.value=this.previous,this.previous=this.model.valueForCellChanged(this.cell,this.previous)}}class CellState extends Rectangle{constructor(t=null,e=null,i=null){super(),this.node=null,this.cellBounds=null,this.paintBounds=null,this.boundingBox=null,this.control=null,this.overlays=new Map,this.invalidStyle=!1,this.invalid=!0,this.absolutePoints=[],this.visibleSourceState=null,this.visibleTargetState=null,this.terminalDistance=0,this.length=0,this.segments=[],this.shape=null,this.text=null,this.unscaledWidth=0,this.unscaledHeight=0,this.parentHighlight=null,this.point=null,t&&(this.view=t),e&&(this.cell=e),this.style=i??{},this.origin=new Point,this.absoluteOffset=new Point}getPerimeterBounds(t=0,e=new Rectangle(this.x,this.y,this.width,this.height)){var i,s;if(((s=(i=this.shape)==null?void 0:i.stencil)==null?void 0:s.aspect)==="fixed"){const n=this.shape.stencil.computeAspect(this.shape,e.x,e.y,e.width,e.height);e.x=n.x,e.y=n.y,e.width=this.shape.stencil.w0*n.width,e.height=this.shape.stencil.h0*n.height}return t!==0&&e.grow(t),e}setAbsoluteTerminalPoint(t,e=!1){e?this.absolutePoints.length===0?this.absolutePoints.push(t):this.absolutePoints[0]=t:this.absolutePoints.length===0?(this.absolutePoints.push(null),this.absolutePoints.push(t)):this.absolutePoints.length===1?this.absolutePoints.push(t):this.absolutePoints[this.absolutePoints.length-1]=t}setCursor(t){this.shape&&this.shape.setCursor(t),this.text&&this.text.setCursor(t)}getVisibleTerminal(t=!1){var e;return((e=this.getVisibleTerminalState(t))==null?void 0:e.cell)??null}getVisibleTerminalState(t=!1){return t?this.visibleSourceState:this.visibleTargetState}setVisibleTerminalState(t,e=!1){e?this.visibleSourceState=t:this.visibleTargetState=t}getCellBounds(){return this.cellBounds}getPaintBounds(){return this.paintBounds}updateCachedBounds(){const t=this.view,e=t.translate,i=t.scale;this.cellBounds=new Rectangle(this.x/i-e.x,this.y/i-e.y,this.width/i,this.height/i),this.paintBounds=Rectangle.fromRectangle(this.cellBounds),this.shape&&this.shape.isPaintBoundsInverted()&&this.paintBounds.rotate90()}setState(t){this.view=t.view,this.cell=t.cell,this.style=t.style,this.absolutePoints=t.absolutePoints,this.origin=t.origin,this.absoluteOffset=t.absoluteOffset,this.boundingBox=t.boundingBox,this.terminalDistance=t.terminalDistance,this.segments=t.segments,this.length=t.length,this.x=t.x,this.y=t.y,this.width=t.width,this.height=t.height,this.unscaledWidth=t.unscaledWidth,this.unscaledHeight=t.unscaledHeight}clone(){const t=new CellState(this.view,this.cell,this.style);for(let e=0;e<this.absolutePoints.length;e+=1){const i=this.absolutePoints[e];t.absolutePoints[e]=i?i.clone():null}return this.origin&&(t.origin=this.origin.clone()),this.absoluteOffset&&(t.absoluteOffset=this.absoluteOffset.clone()),this.boundingBox&&(t.boundingBox=this.boundingBox.clone()),t.terminalDistance=this.terminalDistance,t.segments=this.segments,t.length=this.length,t.x=this.x,t.y=this.y,t.width=this.width,t.height=this.height,t.unscaledWidth=this.unscaledWidth,t.unscaledHeight=this.unscaledHeight,t}destroy(){this.view.graph.cellRenderer.destroy(this)}isLoop(t){const e=this.getVisibleTerminalState(!0);return e&&e===this.getVisibleTerminalState(!1)}getVerticalAlign(){return this.style.verticalAlign??"middle"}isTransparentState(){return(this.style.strokeColor??NONE)===NONE&&(this.style.fillColor??NONE)===NONE&&!this.getImageSrc()}getImageSrc(){return this.style.image||null}getIndicatorColor(){return this.style.indicatorColor||null}getIndicatorGradientColor(){return this.style.gradientColor||null}getIndicatorShape(){return this.style.indicatorShape||null}getIndicatorImageSrc(){return this.style.indicatorImage||null}}const toRadians=r=>Math.PI*r/180,arcToCurves=(r,t,e,i,s,n,l,o,a)=>{if(o-=r,a-=t,e===0||i===0)return[];const h=l,d=s;e=Math.abs(e),i=Math.abs(i);const c=-o/2,u=-a/2,g=Math.cos(d*Math.PI/180),f=Math.sin(d*Math.PI/180),p=g*c+f*u,y=-1*f*c+g*u,v=p*p,S=y*y,w=e*e,C=i*i,m=v/w+S/C;let M;if(m>1)e=Math.sqrt(m)*e,i=Math.sqrt(m)*i,M=0;else{let Q=1;n===h&&(Q=-1),M=Q*Math.sqrt((w*C-w*S-C*v)/(w*S+C*v))}const b=M*e*y/i,O=-1*M*i*p/e,R=g*b-f*O+o/2,H=f*b+g*O+a/2;let T=Math.atan2((y-O)/i,(p-b)/e)-Math.atan2(0,1),U=T>=0?T:2*Math.PI+T;T=Math.atan2((-y-O)/i,(-p-b)/e)-Math.atan2((y-O)/i,(p-b)/e);let q=T>=0?T:2*Math.PI+T;!h&&q>0?q-=2*Math.PI:h&&q<0&&(q+=2*Math.PI);const it=q*2/Math.PI,x=Math.ceil(it<0?-1*it:it),P=q/x,L=8/3*Math.sin(P/4)*Math.sin(P/4)/Math.sin(P/2),A=g*e,I=g*i,B=f*e,k=f*i;let V=Math.cos(U),Y=Math.sin(U),N=-L*(A*Y+k*V),_=-L*(B*Y-I*V),z=0,W=0;const G=[];for(let Q=0;Q<x;++Q){U+=P,V=Math.cos(U),Y=Math.sin(U),z=A*V-k*Y+R,W=B*V+I*Y+H;const st=-L*(A*Y+k*V),F=-L*(B*Y-I*V),$=Q*6;G[$]=Number(N+r),G[$+1]=Number(_+t),G[$+2]=Number(z-st+r),G[$+3]=Number(W-F+t),G[$+4]=Number(z+r),G[$+5]=Number(W+t),N=z+st,_=W+F}return G},getBoundingBox=(r,t,e=null)=>{let i=null;if(r&&t!==0){const s=toRadians(t),n=Math.cos(s),l=Math.sin(s);e=e??new Point(r.x+r.width/2,r.y+r.height/2);let o=new Point(r.x,r.y),a=new Point(r.x+r.width,r.y),h=new Point(a.x,r.y+r.height),d=new Point(r.x,h.y);o=getRotatedPoint(o,n,l,e),a=getRotatedPoint(a,n,l,e),h=getRotatedPoint(h,n,l,e),d=getRotatedPoint(d,n,l,e),i=new Rectangle(o.x,o.y,0,0),i.add(new Rectangle(a.x,a.y,0,0)),i.add(new Rectangle(h.x,h.y,0,0)),i.add(new Rectangle(d.x,d.y,0,0))}return i},getRotatedPoint=(r,t,e,i=new Point)=>{const s=r.x-i.x,n=r.y-i.y,l=s*t-n*e,o=n*t+s*e;return new Point(l+i.x,o+i.y)},getPortConstraints=(r,t,e,i)=>{const s=r.style.portConstraint??(e?t.style.sourcePortConstraint:t.style.targetPortConstraint);if(isNullish(s))return i;const n=s.toString();let l=DIRECTION_MASK.NONE;const a=r.style.portConstraintRotation??!1?r.style.rotation??0:0;let h=0;if(a>45?(h=1,a>=135&&(h=2)):a<-45&&(h=3,a<=-135&&(h=2)),n.includes("north"))switch(h){case 0:l|=DIRECTION_MASK.NORTH;break;case 1:l|=DIRECTION_MASK.EAST;break;case 2:l|=DIRECTION_MASK.SOUTH;break;case 3:l|=DIRECTION_MASK.WEST;break}if(n.includes("west"))switch(h){case 0:l|=DIRECTION_MASK.WEST;break;case 1:l|=DIRECTION_MASK.NORTH;break;case 2:l|=DIRECTION_MASK.EAST;break;case 3:l|=DIRECTION_MASK.SOUTH;break}if(n.includes("south"))switch(h){case 0:l|=DIRECTION_MASK.SOUTH;break;case 1:l|=DIRECTION_MASK.WEST;break;case 2:l|=DIRECTION_MASK.NORTH;break;case 3:l|=DIRECTION_MASK.EAST;break}if(n.includes("east"))switch(h){case 0:l|=DIRECTION_MASK.EAST;break;case 1:l|=DIRECTION_MASK.SOUTH;break;case 2:l|=DIRECTION_MASK.WEST;break;case 3:l|=DIRECTION_MASK.NORTH;break}return l},reversePortConstraints=r=>{let t=0;return t=(r&DIRECTION_MASK.WEST)<<3,t|=(r&DIRECTION_MASK.NORTH)<<1,t|=(r&DIRECTION_MASK.SOUTH)>>1,t|=(r&DIRECTION_MASK.EAST)>>3,t},findNearestSegment=(r,t,e)=>{let i=-1;if(r.absolutePoints.length>0){let s=r.absolutePoints[0],n=null;for(let l=1;l<r.absolutePoints.length;l+=1){const o=r.absolutePoints[l];if(!s||!o)continue;const a=ptSegDistSq(s.x,s.y,o.x,o.y,t,e);(n==null||a<n)&&(n=a,i=l-1),s=o}}return i},getDirectedBounds=(r,t,e,i,s)=>{const n=(e==null?void 0:e.direction)??"east";if(i??(i=(e==null?void 0:e.flipH)??!1),s??(s=(e==null?void 0:e.flipV)??!1),t.x=Math.round(Math.max(0,Math.min(r.width,t.x))),t.y=Math.round(Math.max(0,Math.min(r.height,t.y))),t.width=Math.round(Math.max(0,Math.min(r.width,t.width))),t.height=Math.round(Math.max(0,Math.min(r.height,t.height))),s&&(n==="south"||n==="north")||i&&(n==="east"||n==="west")){const o=t.x;t.x=t.width,t.width=o}if(i&&(n==="south"||n==="north")||s&&(n==="east"||n==="west")){const o=t.y;t.y=t.height,t.height=o}const l=Rectangle.fromRectangle(t);switch(n){case"south":{l.y=t.x,l.x=t.height,l.width=t.y,l.height=t.width;break}case"west":{l.y=t.height,l.x=t.width,l.width=t.x,l.height=t.y;break}case"north":{l.y=t.width,l.x=t.y,l.width=t.height,l.height=t.x;break}}return new Rectangle(r.x+l.x,r.y+l.y,r.width-l.width-l.x,r.height-l.height-l.y)},contains=(r,t,e)=>r.x<=t&&r.x+r.width>=t&&r.y<=e&&r.y+r.height>=e,intersects=(r,t)=>{let e=r.width,i=r.height,s=t.width,n=t.height;if(s<=0||n<=0||e<=0||i<=0)return!1;const l=r.x,o=r.y,a=t.x,h=t.y;return s+=a,n+=h,e+=l,i+=o,(s<a||s>l)&&(n<h||n>o)&&(e<l||e>a)&&(i<o||i>h)},intersectsHotspot=(r,t,e,i,s,n)=>{if(i=i??1,s=s??0,n=n??0,i>0){let l=r.getCenterX(),o=r.getCenterY(),a=r.width,h=r.height;const d=r.style,c=((d==null?void 0:d.startSize)??0)*r.view.scale;c>0&&((d==null?void 0:d.horizontal)??!0?(o=r.y+c/2,h=c):(l=r.x+c/2,a=c)),a=Math.max(s,a*i),h=Math.max(s,h*i),n>0&&(a=Math.min(a,n),h=Math.min(h,n));const u=new Rectangle(l-a/2,o-h/2,a,h),g=toRadians((d==null?void 0:d.rotation)??0);if(g!=0){const f=Math.cos(-g),p=Math.sin(-g),y=new Point(r.getCenterX(),r.getCenterY()),v=getRotatedPoint(new Point(t,e),f,p,y);t=v.x,e=v.y}return contains(u,t,e)}return!0},isNumeric=r=>!Number.isNaN(Number.parseFloat(r))&&Number.isFinite(+r)&&(typeof r!="string"||!r.toLowerCase().includes("0x")),mod=(r,t)=>(r%t+t)%t,intersection=(r,t,e,i,s,n,l,o)=>{const a=(o-n)*(e-r)-(l-s)*(i-t),h=(l-s)*(t-n)-(o-n)*(r-s),d=(e-r)*(t-n)-(i-t)*(r-s),c=h/a,u=d/a;if(c>=0&&c<=1&&u>=0&&u<=1){const g=r+c*(e-r),f=t+c*(i-t);return new Point(g,f)}return null},ptSegDistSq=(r,t,e,i,s,n)=>{e-=r,i-=t,s-=r,n-=t;let l=s*e+n*i,o;l<=0?o=0:(s=e-s,n=i-n,l=s*e+n*i,l<=0?o=0:o=l*l/(e*e+i*i));let a=s*s+n*n-o;return a<0&&(a=0),a},relativeCcw=(r,t,e,i,s,n)=>{e-=r,i-=t,s-=r,n-=t;let l=s*i-n*e;return l==0&&(l=s*e+n*i,l>0&&(s-=e,n-=i,l=s*e+n*i,l<0&&(l=0))),l<0?-1:l>0?1:0},SideToSide=(r,t,e,i,s)=>{const{view:n}=r;let l=i!=null&&i.length>0?i[0]:null;const o=r.absolutePoints,a=o[0],h=o[o.length-1];if(l!=null&&(l=n.transformControlPoint(r,l)),a!=null&&(t=new CellState,t.x=a.x,t.y=a.y),h!=null&&(e=new CellState,e.x=h.x,e.y=h.y),t!=null&&e!=null){const d=Math.max(t.x,e.x),c=Math.min(t.x+t.width,e.x+e.width),u=l!=null?l.x:Math.round(c+(d-c)/2);let g=n.getRoutingCenterY(t),f=n.getRoutingCenterY(e);if(l!=null&&(l.y>=t.y&&l.y<=t.y+t.height&&(g=l.y),l.y>=e.y&&l.y<=e.y+e.height&&(f=l.y)),!contains(e,u,g)&&!contains(t,u,g)&&s.push(new Point(u,g)),!contains(e,u,f)&&!contains(t,u,f)&&s.push(new Point(u,f)),s.length===1)if(l!=null)!contains(e,u,l.y)&&!contains(t,u,l.y)&&s.push(new Point(u,l.y));else{const p=Math.max(t.y,e.y),y=Math.min(t.y+t.height,e.y+e.height);s.push(new Point(u,p+(y-p)/2))}}},TopToBottom=(r,t,e,i,s)=>{const{view:n}=r;let l=i!=null&&i.length>0?i[0]:null;const o=r.absolutePoints,a=o[0],h=o[o.length-1];if(l!=null&&(l=n.transformControlPoint(r,l)),a!=null&&(t=new CellState,t.x=a.x,t.y=a.y),h!=null&&(e=new CellState,e.x=h.x,e.y=h.y),t!=null&&e!=null){const d=Math.max(t.y,e.y),c=Math.min(t.y+t.height,e.y+e.height);let u=n.getRoutingCenterX(t);l!=null&&l.x>=t.x&&l.x<=t.x+t.width&&(u=l.x);const g=l!=null?l.y:Math.round(c+(d-c)/2);if(!contains(e,u,g)&&!contains(t,u,g)&&s.push(new Point(u,g)),l!=null&&l.x>=e.x&&l.x<=e.x+e.width?u=l.x:u=n.getRoutingCenterX(e),!contains(e,u,g)&&!contains(t,u,g)&&s.push(new Point(u,g)),s.length===1)if(l!=null&&s.length===1)!contains(e,l.x,g)&&!contains(t,l.x,g)&&s.push(new Point(l.x,g));else{const f=Math.max(t.x,e.x),p=Math.min(t.x+t.width,e.x+e.width);s.push(new Point(f+(p-f)/2,g))}}},ElbowConnector=(r,t,e,i,s)=>{let n=i!=null&&i.length>0?i[0]:null,l=!1,o=!1;if(t!=null&&e!=null)if(n!=null){const a=Math.min(t.x,e.x),h=Math.max(t.x+t.width,e.x+e.width),d=Math.min(t.y,e.y),c=Math.max(t.y+t.height,e.y+e.height);n=r.view.transformControlPoint(r,n),l=n.y<d||n.y>c,o=n.x<a||n.x>h}else{const a=Math.max(t.x,e.x),h=Math.min(t.x+t.width,e.x+e.width);if(l=a===h,!l){const d=Math.max(t.y,e.y),c=Math.min(t.y+t.height,e.y+e.height);o=d===c}}!o&&(l||r.style.elbow==="vertical")?TopToBottom(r,t,e,i,s):SideToSide(r,t,e,i,s)},EntityRelationConnectorConfig={segment:ENTITY_SEGMENT},OrthogonalConnectorConfig={buffer:10},allDirections=()=>["north","south","east","west"],ManhattanConnectorConfig={maxAllowedDirectionChange:90,maxLoops:2e3,endDirections:allDirections(),startDirections:allDirections(),step:12},originalManhattanConnectorConfig={};shallowCopy(ManhattanConnectorConfig,originalManhattanConnectorConfig);const EntityRelation=(r,t,e,i,s)=>{var u;const{view:n}=r,l=(((u=r.style)==null?void 0:u.segment)??EntityRelationConnectorConfig.segment)*n.scale,o=r.absolutePoints,a=o[0],h=o[o.length-1];let d=!1;if(t!=null){const g=t.cell.getGeometry();g.relative?d=g.x<=.5:e!=null&&(d=(h!=null?h.x:e.x+e.width)<(a!=null?a.x:t.x))}if(a!=null)t=new CellState,t.x=a.x,t.y=a.y;else if(t!=null){const g=getPortConstraints(t,r,!0,DIRECTION_MASK.NONE);g!==DIRECTION_MASK.NONE&&g!==DIRECTION_MASK.WEST+DIRECTION_MASK.EAST&&(d=g===DIRECTION_MASK.WEST)}else return;let c=!0;if(e!=null){const g=e.cell.getGeometry();g.relative?c=g.x<=.5:t!=null&&(c=(a!=null?a.x:t.x+t.width)<(h!=null?h.x:e.x))}if(h!=null)e=new CellState,e.x=h.x,e.y=h.y;else if(e!=null){const g=getPortConstraints(e,r,!1,DIRECTION_MASK.NONE);g!==DIRECTION_MASK.NONE&&g!=DIRECTION_MASK.WEST+DIRECTION_MASK.EAST&&(c=g===DIRECTION_MASK.WEST)}if(t!=null&&e!=null){const g=d?t.x:t.x+t.width,f=n.getRoutingCenterY(t),p=c?e.x:e.x+e.width,y=n.getRoutingCenterY(e),v=l;let S=d?-v:v;const w=new Point(g+S,f);S=c?-v:v;const C=new Point(p+S,y);if(d===c){const m=d?Math.min(g,p)-l:Math.max(g,p)+l;s.push(new Point(m,f)),s.push(new Point(m,y))}else if(w.x<C.x===d){const m=f+(y-f)/2;s.push(w),s.push(new Point(w.x,m)),s.push(new Point(C.x,m)),s.push(C)}else s.push(w),s.push(C)}},Loop=(r,t,e,i,s)=>{var a;const n=r.absolutePoints,l=n[0],o=n[n.length-1];if(l!=null&&o!=null){if(i!=null&&i.length>0)for(let h=0;h<i.length;h+=1){let d=i[h];d=r.view.transformControlPoint(r,d),s.push(new Point(d.x,d.y))}return}if(t!=null){const{view:h}=r,{graph:d}=h;let c=i!=null&&i.length>0?i[0]:null;c!=null&&(c=h.transformControlPoint(r,c),contains(t,c.x,c.y)&&(c=null));let u=0,g=0,f=0,p=0;const y=(r.style.segment??d.gridSize)*h.scale,v=((a=r.style)==null?void 0:a.direction)??"west";if(v==="north"||v==="south"?(u=h.getRoutingCenterX(t),g=y):(f=h.getRoutingCenterY(t),p=y),c==null||c.x<t.x||c.x>t.x+t.width)if(c!=null)u=c.x,p=Math.max(Math.abs(f-c.y),p);else switch(v){case"north":{f=t.y-2*g;break}case"south":{f=t.y+t.height+2*g;break}case"east":{u=t.x-2*p;break}default:u=t.x+t.width+2*p}else c!==null&&(u=h.getRoutingCenterX(t),g=Math.max(Math.abs(u-c.x),p),f=c.y,p=0);s.push(new Point(u-g,f-p)),s.push(new Point(u+g,f+p))}},equalPoints=(r,t)=>{if(!r&&t||r&&!t||r&&t&&r.length!=t.length)return!1;if(r&&t)for(let e=0;e<r.length;e+=1){const i=r[e];if(!i||i&&!i.equals(t[e]))return!1}return!0},equalEntries=(r,t)=>{let e=0;if(!r&&t||r&&!t||r&&t&&r.length!=t.length)return!1;if(r&&t){for(const i in t)e++;for(const i in r)if(e--,(!Number.isNaN(r[i])||!Number.isNaN(t[i]))&&r[i]!==t[i])return!1}return e===0},removeDuplicates=r=>{const t=new Map,e=[];for(let i=0;i<r.length;i+=1)t.get(r[i])||(e.push(r[i]),t.set(r[i],!0));return e};class Geometry extends Rectangle{constructor(t=0,e=0,i=0,s=0){super(t,e,i,s),this.TRANSLATE_CONTROL_POINTS=!0,this.alternateBounds=null,this.sourcePoint=null,this.targetPoint=null,this.points=null,this.offset=null,this.relative=!1}setRelative(t){this.relative=t}swap(){if(this.alternateBounds){const t=new Rectangle(this.x,this.y,this.width,this.height);this.x=this.alternateBounds.x,this.y=this.alternateBounds.y,this.width=this.alternateBounds.width,this.height=this.alternateBounds.height,this.alternateBounds=t}}getTerminalPoint(t){return t?this.sourcePoint:this.targetPoint}setTerminalPoint(t,e){return e?this.sourcePoint=t:this.targetPoint=t,t}rotate(t,e){const i=toRadians(t),s=Math.cos(i),n=Math.sin(i);if(!this.relative){const l=new Point(this.getCenterX(),this.getCenterY()),o=getRotatedPoint(l,s,n,e);this.x=Math.round(o.x-this.width/2),this.y=Math.round(o.y-this.height/2)}if(this.sourcePoint){const l=getRotatedPoint(this.sourcePoint,s,n,e);this.sourcePoint.x=Math.round(l.x),this.sourcePoint.y=Math.round(l.y)}if(this.targetPoint){const l=getRotatedPoint(this.targetPoint,s,n,e);this.targetPoint.x=Math.round(l.x),this.targetPoint.y=Math.round(l.y)}if(this.points){for(let l=0;l<this.points.length;l+=1)if(this.points[l]){const o=getRotatedPoint(this.points[l],s,n,e);this.points[l].x=Math.round(o.x),this.points[l].y=Math.round(o.y)}}}translate(t,e){if(this.relative||(this.x+=t,this.y+=e),this.sourcePoint&&(this.sourcePoint.x=this.sourcePoint.x+t,this.sourcePoint.y=this.sourcePoint.y+e),this.targetPoint&&(this.targetPoint.x=this.targetPoint.x+t,this.targetPoint.y=this.targetPoint.y+e),this.TRANSLATE_CONTROL_POINTS&&this.points)for(let i=0;i<this.points.length;i+=1)this.points[i]&&(this.points[i].x=this.points[i].x+t,this.points[i].y=this.points[i].y+e)}scale(t,e,i){if(this.sourcePoint&&(this.sourcePoint.x=this.sourcePoint.x*t,this.sourcePoint.y=this.sourcePoint.y*e),this.targetPoint&&(this.targetPoint.x=this.targetPoint.x*t,this.targetPoint.y=this.targetPoint.y*e),this.points)for(let s=0;s<this.points.length;s+=1)this.points[s]&&(this.points[s].x=this.points[s].x*t,this.points[s].y=this.points[s].y*e);this.relative||(this.x*=t,this.y*=e,i&&(e=t=Math.min(t,e)),this.width*=t,this.height*=e)}equals(t){var e,i,s,n;return t?super.equals(t)&&this.relative===t.relative&&(this.sourcePoint===null&&t.sourcePoint===null||!!((e=this.sourcePoint)!=null&&e.equals(t.sourcePoint)))&&(this.targetPoint===null&&t.targetPoint===null||!!((i=this.targetPoint)!=null&&i.equals(t.targetPoint)))&&equalPoints(this.points,t.points)&&(this.alternateBounds===null&&t.alternateBounds===null||!!((s=this.alternateBounds)!=null&&s.equals(t.alternateBounds)))&&(this.offset===null&&t.offset===null||!!((n=this.offset)!=null&&n.equals(t.offset))):!1}clone(){return clone(this)}}function scalePointArray(r,t){let e=[];if(r!=null)for(let i=0;i<r.length;i+=1)r[i]!=null?e[i]=new Point(Math.round(r[i].x/t*10)/10,Math.round(r[i].y/t*10)/10):e[i]=null;else e=null;return e}function scaleCellState(r,t){let e=null;return r!=null&&(e=r.clone(),e.setRect(Math.round(r.x/t*10)/10,Math.round(r.y/t*10)/10,Math.round(r.width/t*10)/10,Math.round(r.height/t*10)/10)),e}const SegmentConnector=(r,t,e,i,s)=>{const n=scalePointArray(r.absolutePoints,r.view.scale),l=scaleCellState(t,r.view.scale),o=scaleCellState(e,r.view.scale),a=1;let h=s.length>0?s[0]:null,d=!0,c=null;function u(y){return y.x=Math.round(y.x*r.view.scale*10)/10,y.y=Math.round(y.y*r.view.scale*10)/10,(h==null||Math.abs(h.x-y.x)>=a||Math.abs(h.y-y.y)>=Math.max(1,r.view.scale))&&(s.push(y),h=y),h}let g=n[0];g==null&&l!=null?g=new Point(r.view.getRoutingCenterX(l),r.view.getRoutingCenterY(l)):g!=null&&(g=g.clone());const f=n.length-1;let p=null;if(i!=null&&i.length>0){let y=[];for(let M=0;M<i.length;M+=1){const b=r.view.transformControlPoint(r,i[M],!0);b!=null&&y.push(b)}if(y.length===0)return;g!=null&&y[0]!=null&&(Math.abs(y[0].x-g.x)<a&&(y[0].x=g.x),Math.abs(y[0].y-g.y)<a&&(y[0].y=g.y)),p=n[f],p!=null&&y[y.length-1]!=null&&(Math.abs(y[y.length-1].x-p.x)<a&&(y[y.length-1].x=p.x),Math.abs(y[y.length-1].y-p.y)<a&&(y[y.length-1].y=p.y)),c=y[0];let v=l,S=n[0],w=!1,C=!1,m=c;S!=null&&(v=null);for(let M=0;M<2;M+=1){const b=S!=null&&S.x===m.x,O=S!=null&&S.y===m.y,R=v!=null&&m.y>=v.y&&m.y<=v.y+v.height,H=v!=null&&m.x>=v.x&&m.x<=v.x+v.width;if(w=O||S==null&&R,C=b||S==null&&H,!(M==0&&(w&&C||b&&O))){if(S!=null&&!O&&!b&&(R||H)){d=!R;break}if(C||w){d=w,M===1&&(d=y.length%2===0?w:C);break}}v=o,S=n[f],S!=null&&(v=null),m=y[y.length-1],b&&O&&(y=y.slice(1))}d&&(n[0]!=null&&n[0].y!==c.y||n[0]==null&&l!=null&&(c.y<l.y||c.y>l.y+l.height))?u(new Point(g.x,c.y)):!d&&(n[0]!=null&&n[0].x!==c.x||n[0]==null&&l!=null&&(c.x<l.x||c.x>l.x+l.width))&&u(new Point(c.x,g.y)),d?g.y=c.y:g.x=c.x;for(let M=0;M<y.length;M+=1)d=!d,c=y[M],d?g.y=c.y:g.x=c.x,u(g.clone())}else c=g,d=!0;if(g=n[f],g==null&&o!=null&&(g=new Point(r.view.getRoutingCenterX(o),r.view.getRoutingCenterY(o))),g!=null&&c!=null&&(d&&(n[f]!=null&&n[f].y!==c.y||n[f]==null&&o!=null&&(c.y<o.y||c.y>o.y+o.height))?u(new Point(g.x,c.y)):!d&&(n[f]!=null&&n[f].x!==c.x||n[f]==null&&o!=null&&(c.x<o.x||c.x>o.x+o.width))&&u(new Point(c.x,g.y))),n[0]==null&&l!=null)for(;s.length>1&&s[1]!=null&&contains(l,s[1].x,s[1].y);)s.splice(1,1);if(n[f]==null&&o!=null)for(;s.length>1&&s[s.length-1]!=null&&contains(o,s[s.length-1].x,s[s.length-1].y);)s.splice(s.length-1,1);p!=null&&s[s.length-1]!=null&&Math.abs(p.x-s[s.length-1].x)<=a&&Math.abs(p.y-s[s.length-1].y)<=a&&(s.splice(s.length-1,1),s[s.length-1]!=null&&(Math.abs(s[s.length-1].x-p.x)<a&&(s[s.length-1].x=p.x),Math.abs(s[s.length-1].y-p.y)<a&&(s[s.length-1].y=p.y)))},dirVectors=[[-1,0],[0,-1],[1,0],[0,1],[-1,0],[0,-1],[1,0]],wayPoints1=[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],routePatterns=[[[513,2308,2081,2562],[513,1090,514,2184,2114,2561],[513,1090,514,2564,2184,2562],[513,2308,2561,1090,514,2568,2308]],[[514,1057,513,2308,2081,2562],[514,2184,2114,2561],[514,2184,2562,1057,513,2564,2184],[514,1057,513,2568,2308,2561]],[[1090,514,1057,513,2308,2081,2562],[2114,2561],[1090,2562,1057,513,2564,2184],[1090,514,1057,513,2308,2561,2568]],[[2081,2562],[1057,513,1090,514,2184,2114,2561],[1057,513,1090,514,2184,2562,2564],[1057,2561,1090,514,2568,2308]]],vertexSeparations=[],limits=[[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0]],SIDE_MASK=480,CENTER_MASK=512,SOURCE_MASK=1024,TARGET_MASK=2048;function getJettySize(r,t){const e=OrthogonalConnectorConfig.buffer;let i=(t?r.style.sourceJettySize:r.style.targetJettySize)??r.style.jettySize??e;if(i==="auto")if(((t?r.style.startArrow:r.style.endArrow)??NONE)!==NONE){const n=(t?r.style.startSize:r.style.endSize)??StyleDefaultsConfig.markerSize;i=Math.max(2,Math.ceil((n+e)/e))*e}else i=2*e;return i}const OrthogonalConnector=(r,t,e,i,s)=>{const n=scalePointArray(r.absolutePoints,r.view.scale),l=scaleCellState(t,r.view.scale),o=scaleCellState(e,r.view.scale),a=l==null?!1:l.cell.isEdge(),h=o==null?!1:o.cell.isEdge(),d=n[0],c=n[n.length-1];let u=l!=null?l.x:d.x,g=l!=null?l.y:d.y,f=l!=null?l.width:0,p=l!=null?l.height:0,y=o!=null?o.x:c.x,v=o!=null?o.y:c.y,S=o!=null?o.width:0,w=o!=null?o.height:0,C=getJettySize(r,!0),m=getJettySize(r,!1);l!=null&&o===l&&(m=Math.max(C,m),C=m);const M=m+C;let b=!1;if(d!=null&&c!=null){const E=c.x-d.x,D=c.y-d.y;b=E*E+D*D<M*M}if(b||i!=null&&i.length>0||a||h){SegmentConnector(r,t,e,i,s);return}const O=[DIRECTION_MASK.ALL,DIRECTION_MASK.ALL];let R=0;if(l!=null&&(O[0]=getPortConstraints(l,r,!0,DIRECTION_MASK.ALL),R=l.style.rotation??0,R!==0)){const E=getBoundingBox(new Rectangle(u,g,f,p),R);u=E.x,g=E.y,f=E.width,p=E.height}if(o!=null&&(O[1]=getPortConstraints(o,r,!1,DIRECTION_MASK.ALL),R=o.style.rotation??0,R!==0)){const E=getBoundingBox(new Rectangle(y,v,S,w),R);y=E.x,v=E.y,S=E.width,w=E.height}const H=[0,0],T=[[u,g,f,p],[y,v,S,w]],U=[C,m];for(let E=0;E<2;E+=1)limits[E][1]=T[E][0]-U[E],limits[E][2]=T[E][1]-U[E],limits[E][4]=T[E][0]+T[E][2]+U[E],limits[E][8]=T[E][1]+T[E][3]+U[E];const q=T[0][0]+T[0][2]/2,it=T[0][1]+T[0][3]/2,x=T[1][0]+T[1][2]/2,P=T[1][1]+T[1][3]/2,L=q-x,A=it-P;let I=0;L<0?A<0?I=2:I=1:A<=0&&(I=3,L===0&&(I=2));let B=null;l!=null&&(B=d);const k=[[.5,.5],[.5,.5]];for(let E=0;E<2;E+=1)B!=null&&(k[E][0]=(B.x-T[E][0])/T[E][2],Math.abs(B.x-T[E][0])<=1?H[E]=DIRECTION_MASK.WEST:Math.abs(B.x-T[E][0]-T[E][2])<=1&&(H[E]=DIRECTION_MASK.EAST),k[E][1]=(B.y-T[E][1])/T[E][3],Math.abs(B.y-T[E][1])<=1?H[E]=DIRECTION_MASK.NORTH:Math.abs(B.y-T[E][1]-T[E][3])<=1&&(H[E]=DIRECTION_MASK.SOUTH)),B=null,o!=null&&(B=c);const V=T[0][1]-(T[1][1]+T[1][3]),Y=T[0][0]-(T[1][0]+T[1][2]),N=T[1][1]-(T[0][1]+T[0][3]),_=T[1][0]-(T[0][0]+T[0][2]);vertexSeparations[1]=Math.max(Y-M,0),vertexSeparations[2]=Math.max(V-M,0),vertexSeparations[4]=Math.max(N-M,0),vertexSeparations[3]=Math.max(_-M,0);const z=[],W=[],G=[];W[0]=Y>=_?DIRECTION_MASK.WEST:DIRECTION_MASK.EAST,G[0]=V>=N?DIRECTION_MASK.NORTH:DIRECTION_MASK.SOUTH,W[1]=reversePortConstraints(W[0]),G[1]=reversePortConstraints(G[0]);const Q=Y>=_?Y:_,st=V>=N?V:N,F=[[0,0],[0,0]];let $=!1;for(let E=0;E<2;E+=1)H[E]===0&&((W[E]&O[E])===0&&(W[E]=reversePortConstraints(W[E])),(G[E]&O[E])===0&&(G[E]=reversePortConstraints(G[E])),F[E][0]=G[E],F[E][1]=W[E]);st>0&&Q>0&&((W[0]&O[0])>0&&(G[1]&O[1])>0?(F[0][0]=W[0],F[0][1]=G[0],F[1][0]=G[1],F[1][1]=W[1],$=!0):(G[0]&O[0])>0&&(W[1]&O[1])>0&&(F[0][0]=G[0],F[0][1]=W[0],F[1][0]=W[1],F[1][1]=G[1],$=!0)),st>0&&!$&&(F[0][0]=G[0],F[0][1]=W[0],F[1][0]=G[1],F[1][1]=W[1],$=!0),Q>0&&!$&&(F[0][0]=W[0],F[0][1]=G[0],F[1][0]=W[1],F[1][1]=G[1],$=!0);for(let E=0;E<2;E+=1)H[E]===0&&((F[E][0]&O[E])===0&&(F[E][0]=F[E][1]),z[E]=F[E][0]&O[E],z[E]|=(F[E][1]&O[E])<<8,z[E]|=(F[1-E][E]&O[E])<<16,z[E]|=(F[1-E][1-E]&O[E])<<24,(z[E]&15)===0&&(z[E]=z[E]<<8),(z[E]&3840)===0&&(z[E]=z[E]&15|z[E]>>8),(z[E]&983040)===0&&(z[E]=z[E]&65535|(z[E]&251658240)>>8),H[E]=z[E]&15,(O[E]===DIRECTION_MASK.WEST||O[E]===DIRECTION_MASK.NORTH||O[E]===DIRECTION_MASK.EAST||O[E]===DIRECTION_MASK.SOUTH)&&(H[E]=O[E]));let ot=H[0]===DIRECTION_MASK.EAST?3:H[0],tt=H[1]===DIRECTION_MASK.EAST?3:H[1];ot-=I,tt-=I,ot<1&&(ot+=4),tt<1&&(tt+=4);const at=routePatterns[ot-1][tt-1];switch(wayPoints1[0][0]=T[0][0],wayPoints1[0][1]=T[0][1],H[0]){case DIRECTION_MASK.WEST:wayPoints1[0][0]-=C,wayPoints1[0][1]+=k[0][1]*T[0][3];break;case DIRECTION_MASK.SOUTH:wayPoints1[0][0]+=k[0][0]*T[0][2],wayPoints1[0][1]+=T[0][3]+C;break;case DIRECTION_MASK.EAST:wayPoints1[0][0]+=T[0][2]+C,wayPoints1[0][1]+=k[0][1]*T[0][3];break;case DIRECTION_MASK.NORTH:wayPoints1[0][0]+=k[0][0]*T[0][2],wayPoints1[0][1]-=C;break}let Z=0,yt=(H[0]&(DIRECTION_MASK.EAST|DIRECTION_MASK.WEST))>0?0:1;const ut=yt;let K=0;for(let E=0;E<at.length;E+=1){const D=at[E]&15;let j=D===DIRECTION_MASK.EAST?3:D;j+=I,j>4&&(j-=4);const J=dirVectors[j-1];K=j%2>0?0:1,K!==yt&&(Z++,wayPoints1[Z][0]=wayPoints1[Z-1][0],wayPoints1[Z][1]=wayPoints1[Z-1][1]);const et=(at[E]&TARGET_MASK)>0,rt=(at[E]&SOURCE_MASK)>0;let nt=(at[E]&SIDE_MASK)>>5;nt<<=I,nt>15&&(nt>>=4);const vt=(at[E]&CENTER_MASK)>0;if((rt||et)&&nt<9){let gt=0;const ft=rt?0:1;if(vt&&K===0?gt=T[ft][0]+k[ft][0]*T[ft][2]:vt?gt=T[ft][1]+k[ft][1]*T[ft][3]:gt=limits[ft][nt],K===0){const mt=wayPoints1[Z][0],Et=(gt-mt)*J[0];Et>0&&(wayPoints1[Z][0]+=J[0]*Et)}else{const mt=wayPoints1[Z][1],Et=(gt-mt)*J[1];Et>0&&(wayPoints1[Z][1]+=J[1]*Et)}}else vt&&(wayPoints1[Z][0]+=J[0]*Math.abs(vertexSeparations[j]/2),wayPoints1[Z][1]+=J[1]*Math.abs(vertexSeparations[j]/2));Z>0&&wayPoints1[Z][K]===wayPoints1[Z-1][K]?Z--:yt=K}for(let E=0;E<=Z&&!(E===Z&&(((H[1]&(DIRECTION_MASK.EAST|DIRECTION_MASK.WEST))>0?0:1)===ut?0:1)!==(Z+1)%2);E+=1)s.push(new Point(Math.round(wayPoints1[E][0]*r.view.scale*10)/10,Math.round(wayPoints1[E][1]*r.view.scale*10)/10));let ht=1;for(;ht<s.length;)s[ht-1]==null||s[ht]==null||s[ht-1].x!==s[ht].x||s[ht-1].y!==s[ht].y?ht++:s.splice(ht,1)},ManhattanConnector=(r,t,e,i,s)=>{function n(x,P){return x.x+=P.x||0,x.y+=P.y||0,x.width+=P.width||0,x.height+=P.height||0,x}function l(x,P){return P*Math.round(x/P)}function o(x,P,L){return x.x=l(x.x,P),x.y=l(x.y,P),x}function a(x,P){return P.x>=x.x&&P.x<=x.x+x.width&&P.y>=x.y&&P.y<=x.y+x.height}function h(x){return new Point(x.x+x.width/2,x.y+x.height/2)}function d(x,P){return new Point(x.x-P.x,x.y-P.y)}function c(x,P,L){return x.x+=P||0,x.y+=L||0,x}function u(x,P){const L=P.clone(),A=-(L.y-x.y),I=L.x-x.x,B=10;return 180*(A.toFixed(B)=="0"&&I.toFixed(B)=="0"?0:Math.atan2(A,I))/Math.PI}function g(x){return new Point(x.x===0?0:Math.abs(x.x)/x.x,x.y===0?0:Math.abs(x.y)/x.y)}function f(x,P){return Math.abs(P.x-x.x)+Math.abs(P.y-x.y)}function p(x){const P=x.split(x.includes("@")?"@":" ");return new Point(Number.parseInt(P[0],10),Number.parseInt(P[1],10))}function y(x){return`${x.x}@${x.y}`}function v(x){var _;const P=x.view.graph,L=(_=P.getCellBounds(x.cell,!1,!1))==null?void 0:_.clone();if(!L)return;const A=P.view,{scale:I,translate:B}=A,{x:k,y:V}=B,Y=z=>Math.round(z*10)/10;return new Rectangle(Y(L.x/I-k),Y(L.y/I-V),Y(L.width/I),Y(L.height/I))}const S=ManhattanConnectorConfig.step,w={paddingBox:new Geometry(-S,-S,S*2,S*2),directions:[{offsetX:S,offsetY:0,cost:S,angle:O(u(new Point(0,0),new Point(S,0)))},{offsetX:0,offsetY:S,cost:S,angle:O(u(new Point(0,0),new Point(0,S)))},{offsetX:-S,offsetY:0,cost:S,angle:O(u(new Point(0,0),new Point(-S,0)))},{offsetX:0,offsetY:-S,cost:S,angle:O(u(new Point(0,0),new Point(0,-S)))}],directionMap:{east:{x:1,y:0},south:{x:0,y:1},west:{x:-1,y:0},north:{x:0,y:-1}},penaltiesGenerator:x=>x==45||x==90||x==180?S/2:0,draggingRoute:null,previousDirAngle:0};class C{constructor(P){this.options=P,this.mapGridSize=100,this.map=new Map}build(P,L){const A=(P==null?void 0:P.view.graph)||(L==null?void 0:L.view.graph);if(A)return Array.from(A.getView().getCellStates()).filter(I=>I.cell&&I.cell.isVertex()&&!I.cell.isEdge()).map(I=>v(I)).map(I=>I?n(I,this.options.paddingBox):null).forEach(I=>{if(!I)return;const B=o(new Point(I.x,I.y),this.mapGridSize),k=o(new Point(I.x+I.width,I.y+I.height),this.mapGridSize);for(let V=B.x;V<=k.x;V+=this.mapGridSize)for(let Y=B.y;Y<=k.y;Y+=this.mapGridSize){const N=V+"@"+Y,_=this.map.get(N)||[];this.map.has(N)||this.map.set(N,_),_.push(I)}})}isPointAccessible(P){const L=y(o(P.clone(),this.mapGridSize)),A=this.map.get(L);return A?A.every(I=>!a(I,P)):!0}}class m{constructor(){this.items=[],this.hash=new Map}add(P,L){const A=this.hash.get(P);A?(A.value=L,this.items.splice(this.items.indexOf(P),1)):this.hash.set(P,{value:L,open:!0}),this.items.push(P),this.items.sort((I,B)=>{const k=this.hash.get(I),V=this.hash.get(B);return!k||!V?0:k.value-V.value})}remove(P){const L=this.hash.get(P);L&&(L.open=!1)}isOpen(P){const L=this.hash.get(P);return L&&L.open==!0}isClose(P){const L=this.hash.get(P);return L&&L.open==!1}isEmpty(){return this.items.length==0}pop(){const P=this.items.shift();return P&&this.remove(P),P}}function M(x,P,L,A){const I=[];let B=g(d(A,P)),k=P,V;for(;x[y(k)];){if(V=x[y(k)],!V)continue;const N=g(d(k,V));N.equals(B)||(I.unshift(k),B=N),k=V}return g(d(k,L)).equals(B)||I.unshift(k),I}function b(x,P,L){const A=ManhattanConnectorConfig.step,I=h(x),B=[];for(const k of P){const V=L.directionMap[k],Y=V.x*x.width/2,N=V.y*x.height/2,_=c(I.clone(),Y,N);a(x,_)&&c(_,V.x*A,V.y*A),B.push(o(_,A))}return B}function O(x){return x%360+(x<0?360:0)}function R(x,P,L){const A=360/L;return Math.floor(O(u(x,P)+A/2)/A)*A}function H(x,P){const L=Math.abs(x-P);return L>180?360-L:L}function T(x,P){let L=1/0;for(let A=0,I=P.length;A<I;A++){const B=f(x,P[A]);B<L&&(L=B)}return L}function U(x,P,L,A){const I=v(L),B=A?P.style.exitY:P.style.entryY,k=A?ManhattanConnectorConfig.startDirections.every(N=>N!="north"&&N!="south"):ManhattanConnectorConfig.endDirections.every(N=>N!="north"&&N!="south");if(B!=null&&k){const N=(I==null?void 0:I.height)||0;x.y=(I==null?void 0:I.y)!=null?(I==null?void 0:I.y)+N*B:x.y-N/2+N*B}const V=A?P.style.exitX:P.style.entryX,Y=A?ManhattanConnectorConfig.startDirections.every(N=>N!="west"&&N!="east"):ManhattanConnectorConfig.endDirections.every(N=>N!="west"&&N!="east");if(V!=null&&Y){const N=(I==null?void 0:I.width)||0;x.x=(I==null?void 0:I.x)!=null?(I==null?void 0:I.x)+N*V:x.x-N/2+N*(V||0)}}function q(x,P,L,A){const I=ManhattanConnectorConfig.step,B=b(x,ManhattanConnectorConfig.startDirections,A).filter(N=>L.isPointAccessible(N)),k=o(h(x),I),V=b(P,ManhattanConnectorConfig.endDirections,A).filter(N=>L.isPointAccessible(N)),Y=o(h(P),I);if(B.length>0&&V.length>0){const N=new m,_={},z={};B.forEach(F=>{const $=y(F);N.add($,T(F,V)),z[$]=0});let W=ManhattanConnectorConfig.maxLoops;const G=V.map(F=>y(F));let Q,st;for(;!N.isEmpty()&&W>0;){const F=N.pop();if(F==null)continue;const $=p(F),ot=z[F];if(st=Q,Q=_[F]?R(_[F],$,A.directions.length):A.previousDirAngle!=0?A.previousDirAngle:R(k,$,A.directions.length),G.includes(F)){const tt=H(Q,R($,Y,A.directions.length));if($.equals(Y)||tt<180)return A.previousDirAngle=Q,M(_,$,k,Y)}for(let tt=0;tt<A.directions.length;tt++){const at=A.directions[tt],Z=H(Q,at.angle);if(st&&Z>ManhattanConnectorConfig.maxAllowedDirectionChange)continue;const yt=c($.clone(),at.offsetX,at.offsetY),ut=y(yt);if(N.isClose(ut)||!L.isPointAccessible(yt))continue;const K=ot+at.cost+A.penaltiesGenerator(Z);(!N.isOpen(ut)||K<z[ut])&&(_[ut]=$,z[ut]=K,N.add(ut,K+T(yt,V)))}W--}return null}return null}function it(x,P,L,A,I,B){if(A!=null&&A.length>0||P==null||L==null){SegmentConnector(x,P,L,A,I);return}let k=v(P);k=k?n(k,B.paddingBox):void 0;let V=v(L);V=V?n(V,B.paddingBox):void 0;const Y=new C(B);if(Y.build(P,L),!k||!V)return OrthogonalConnector(x,P,L,A,I);const N=q(k,V,Y,B);if(N==null||N.length==0)return OrthogonalConnector(x,P,L,A,I);x.style&&(x.visibleSourceState&&N.length>0&&U(N[0],x,x.visibleSourceState,!0),x.visibleTargetState&&N.length>1&&U(N[N.length-1],x,x.visibleTargetState,!1));const _=x.view.scale;N.forEach(z=>I.push(new Point(Math.round((z.x+x.view.translate.x)*_*10)/10,Math.round((z.y+x.view.translate.y)*_*10)/10)))}it(r,t,e,i,s,w)},EllipsePerimeter=(r,t,e,i=!1)=>{const{x:s}=r,{y:n}=r,l=r.width/2,o=r.height/2,a=s+l,h=n+o,d=e.x,c=e.y,u=Number.parseInt(String(d-a)),g=Number.parseInt(String(c-h));if(u===0&&g!==0)return new Point(a,h+o*g/Math.abs(g));if(u===0&&g===0)return new Point(d,c);if(i){if(c>=n&&c<=n+r.height){const U=c-h;let q=Math.sqrt(l*l*(1-U*U/(o*o)))||0;return d<=s&&(q=-q),new Point(a+q,c)}if(d>=s&&d<=s+r.width){const U=d-a;let q=Math.sqrt(o*o*(1-U*U/(l*l)))||0;return c<=n&&(q=-q),new Point(d,h+q)}}const f=g/u,p=h-f*a,y=l*l*f*f+o*o,v=-2*a*y,S=l*l*f*f*a*a+o*o*a*a-l*l*o*o,w=Math.sqrt(v*v-4*y*S),C=(-v+w)/(2*y),m=(-v-w)/(2*y),M=f*C+p,b=f*m+p,O=Math.sqrt(Math.pow(C-d,2)+Math.pow(M-c,2)),R=Math.sqrt(Math.pow(m-d,2)+Math.pow(b-c,2));let H=0,T=0;return O<R?(H=C,T=M):(H=m,T=b),new Point(H,T)},HexagonPerimeter=(r,t,e,i=!1)=>{var M;const{x:s}=r,{y:n}=r,l=r.width,o=r.height,a=r.getCenterX(),h=r.getCenterY(),d=e.x,c=e.y,u=d-a,g=c-h,f=-Math.atan2(g,u),p=Math.PI,y=Math.PI/2;let v=new Point(a,h);const S=((M=t==null?void 0:t.style)==null?void 0:M.direction)??"east",w=S==="north"||S==="south";let C=new Point,m=new Point;if((d<s&&c<n||d<s&&c>n+o||d>s+l&&c<n||d>s+l&&c>n+o)&&(i=!1),i){if(w){if(d===a){if(c<=n)return new Point(a,n);if(c>=n+o)return new Point(a,n+o)}else if(d<s){if(c===n+o/4)return new Point(s,n+o/4);if(c===n+3*o/4)return new Point(s,n+3*o/4)}else if(d>s+l){if(c===n+o/4)return new Point(s+l,n+o/4);if(c===n+3*o/4)return new Point(s+l,n+3*o/4)}else if(d===s){if(c<h)return new Point(s,n+o/4);if(c>h)return new Point(s,n+3*o/4)}else if(d===s+l){if(c<h)return new Point(s+l,n+o/4);if(c>h)return new Point(s+l,n+3*o/4)}if(c===n)return new Point(a,n);if(c===n+o)return new Point(a,n+o);d<a?c>n+o/4&&c<n+3*o/4?(C=new Point(s,n),m=new Point(s,n+o)):c<n+o/4?(C=new Point(s-Math.floor(.5*l),n+Math.floor(.5*o)),m=new Point(s+l,n-Math.floor(.25*o))):c>n+3*o/4&&(C=new Point(s-Math.floor(.5*l),n+Math.floor(.5*o)),m=new Point(s+l,n+Math.floor(1.25*o))):d>a&&(c>n+o/4&&c<n+3*o/4?(C=new Point(s+l,n),m=new Point(s+l,n+o)):c<n+o/4?(C=new Point(s,n-Math.floor(.25*o)),m=new Point(s+Math.floor(1.5*l),n+Math.floor(.5*o))):c>n+3*o/4&&(C=new Point(s+Math.floor(1.5*l),n+Math.floor(.5*o)),m=new Point(s,n+Math.floor(1.25*o))))}else{if(c===h){if(d<=s)return new Point(s,n+o/2);if(d>=s+l)return new Point(s+l,n+o/2)}else if(c<n){if(d===s+l/4)return new Point(s+l/4,n);if(d===s+3*l/4)return new Point(s+3*l/4,n)}else if(c>n+o){if(d===s+l/4)return new Point(s+l/4,n+o);if(d===s+3*l/4)return new Point(s+3*l/4,n+o)}else if(c===n){if(d<a)return new Point(s+l/4,n);if(d>a)return new Point(s+3*l/4,n)}else if(c===n+o){if(d<a)return new Point(s+l/4,n+o);if(c>h)return new Point(s+3*l/4,n+o)}if(d===s)return new Point(s,h);if(d===s+l)return new Point(s+l,h);c<h?d>s+l/4&&d<s+3*l/4?(C=new Point(s,n),m=new Point(s+l,n)):d<s+l/4?(C=new Point(s-Math.floor(.25*l),n+o),m=new Point(s+Math.floor(.5*l),n-Math.floor(.5*o))):d>s+3*l/4&&(C=new Point(s+Math.floor(.5*l),n-Math.floor(.5*o)),m=new Point(s+Math.floor(1.25*l),n+o)):c>h&&(d>s+l/4&&d<s+3*l/4?(C=new Point(s,n+o),m=new Point(s+l,n+o)):d<s+l/4?(C=new Point(s-Math.floor(.25*l),n),m=new Point(s+Math.floor(.5*l),n+Math.floor(1.5*o))):d>s+3*l/4&&(C=new Point(s+Math.floor(.5*l),n+Math.floor(1.5*o)),m=new Point(s+Math.floor(1.25*l),n)))}let b=a,O=h;d>=s&&d<=s+l?(b=d,c<h?O=n+o:O=n):c>=n&&c<=n+o&&(O=c,d<a?b=s+l:b=s),v=intersection(b,O,e.x,e.y,C.x,C.y,m.x,m.y)}else{if(w){const b=Math.atan2(o/4,l/2);if(f===b)return new Point(s+l,n+Math.floor(.25*o));if(f===y)return new Point(s+Math.floor(.5*l),n);if(f===p-b)return new Point(s,n+Math.floor(.25*o));if(f===-b)return new Point(s+l,n+Math.floor(.75*o));if(f===-y)return new Point(s+Math.floor(.5*l),n+o);if(f===-p+b)return new Point(s,n+Math.floor(.75*o));f<b&&f>-b?(C=new Point(s+l,n),m=new Point(s+l,n+o)):f>b&&f<y?(C=new Point(s,n-Math.floor(.25*o)),m=new Point(s+Math.floor(1.5*l),n+Math.floor(.5*o))):f>y&&f<p-b?(C=new Point(s-Math.floor(.5*l),n+Math.floor(.5*o)),m=new Point(s+l,n-Math.floor(.25*o))):f>p-b&&f<=p||f<-p+b&&f>=-p?(C=new Point(s,n),m=new Point(s,n+o)):f<-b&&f>-y?(C=new Point(s+Math.floor(1.5*l),n+Math.floor(.5*o)),m=new Point(s,n+Math.floor(1.25*o))):f<-y&&f>-p+b&&(C=new Point(s-Math.floor(.5*l),n+Math.floor(.5*o)),m=new Point(s+l,n+Math.floor(1.25*o)))}else{const b=Math.atan2(o/2,l/4);if(f===b)return new Point(s+Math.floor(.75*l),n);if(f===p-b)return new Point(s+Math.floor(.25*l),n);if(f===p||f===-p)return new Point(s,n+Math.floor(.5*o));if(f===0)return new Point(s+l,n+Math.floor(.5*o));if(f===-b)return new Point(s+Math.floor(.75*l),n+o);if(f===-p+b)return new Point(s+Math.floor(.25*l),n+o);f>0&&f<b?(C=new Point(s+Math.floor(.5*l),n-Math.floor(.5*o)),m=new Point(s+Math.floor(1.25*l),n+o)):f>b&&f<p-b?(C=new Point(s,n),m=new Point(s+l,n)):f>p-b&&f<p?(C=new Point(s-Math.floor(.25*l),n+o),m=new Point(s+Math.floor(.5*l),n-Math.floor(.5*o))):f<0&&f>-b?(C=new Point(s+Math.floor(.5*l),n+Math.floor(1.5*o)),m=new Point(s+Math.floor(1.25*l),n)):f<-b&&f>-p+b?(C=new Point(s,n+o),m=new Point(s+l,n+o)):f<-p+b&&f>-p&&(C=new Point(s-Math.floor(.25*l),n),m=new Point(s+Math.floor(.5*l),n+Math.floor(1.5*o)))}v=intersection(a,h,e.x,e.y,C.x,C.y,m.x,m.y)}return v??new Point(a,h)},RectanglePerimeter=(r,t,e,i=!1)=>{const s=r.getCenterX(),n=r.getCenterY(),l=e.x-s,o=e.y-n,a=Math.atan2(o,l),h=new Point(0,0),d=Math.PI,u=Math.PI/2-a,g=Math.atan2(r.height,r.width);return a<-d+g||a>d-g?(h.x=r.x,h.y=n-r.width*Math.tan(a)/2):a<-g?(h.y=r.y,h.x=s-r.height*Math.tan(u)/2):a<g?(h.x=r.x+r.width,h.y=n+r.width*Math.tan(a)/2):(h.y=r.y+r.height,h.x=s+r.height*Math.tan(u)/2),i&&(e.x>=r.x&&e.x<=r.x+r.width?h.x=e.x:e.y>=r.y&&e.y<=r.y+r.height&&(h.y=e.y),e.x<r.x?h.x=r.x:e.x>r.x+r.width&&(h.x=r.x+r.width),e.y<r.y?h.y=r.y:e.y>r.y+r.height&&(h.y=r.y+r.height)),h},RhombusPerimeter=(r,t,e,i=!1)=>{const{x:s}=r,{y:n}=r,l=r.width,o=r.height,a=s+l/2,h=n+o/2,d=e.x,c=e.y;if(a===d)return h>c?new Point(a,n):new Point(a,n+o);if(h===c)return a>d?new Point(s,h):new Point(s+l,h);let u=a,g=h;return i&&(d>=s&&d<=s+l?u=d:c>=n&&c<=n+o&&(g=c)),d<a?c<h?intersection(d,c,u,g,a,n,s,h):intersection(d,c,u,g,a,n+o,s,h):c<h?intersection(d,c,u,g,a,n,s+l,h):intersection(d,c,u,g,a,n+o,s+l,h)},TrianglePerimeter=(r,t,e,i=!1)=>{const s=t!=null?t.style.direction:null,n=s==="north"||s==="south",{x:l}=r,{y:o}=r,a=r.width,h=r.height;let d=l+a/2,c=o+h/2,u=new Point(l,o),g=new Point(l+a,c),f=new Point(l,o+h);switch(s){case"north":{u=f,g=new Point(d,o),f=new Point(l+a,o+h);break}case"south":{g=new Point(d,o+h),f=new Point(l+a,o);break}case"west":{u=new Point(l+a,o),g=new Point(l,c),f=new Point(l+a,o+h);break}}let p=e.x-d,y=e.y-c;const v=n?Math.atan2(p,y):Math.atan2(y,p),S=n?Math.atan2(a,h):Math.atan2(h,a);let w=!1;s==="north"||s==="west"?w=v>-S&&v<S:w=v<-Math.PI+S||v>Math.PI-S;let C=null;if(w)if(i&&(n&&e.x>=u.x&&e.x<=f.x||!n&&e.y>=u.y&&e.y<=f.y))n?C=new Point(e.x,u.y):C=new Point(u.x,e.y);else switch(s){case"north":{C=new Point(l+a/2+h*Math.tan(v)/2,o+h);break}case"south":{C=new Point(l+a/2-h*Math.tan(v)/2,o);break}case"west":{C=new Point(l+a,o+h/2+a*Math.tan(v)/2);break}default:C=new Point(l,o+h/2-a*Math.tan(v)/2)}else{if(i){const m=new Point(d,c);e.y>=o&&e.y<=o+h?(m.x=n?d:s==="west"?l+a:l,m.y=e.y):e.x>=l&&e.x<=l+a&&(m.x=e.x,m.y=n?s==="north"?o+h:o:c),p=e.x-m.x,y=e.y-m.y,d=m.x,c=m.y}n&&e.x<=l+a/2||!n&&e.y<=o+h/2?C=intersection(e.x,e.y,d,c,u.x,u.y,g.x,g.y):C=intersection(e.x,e.y,d,c,g.x,g.y,f.x,f.y)}return C==null&&(C=new Point(d,c)),C},isClassicOrClassicThin=r=>r==="classic"||r==="classicThin",isDiamond=r=>r==="diamond",createArrow=r=>(t,e,i,s,n,l,o,a,h,d)=>{const c=n*h*1.118,u=l*h*1.118;n*=o+h,l*=o+h;const g=s.clone();g.x-=c,g.y-=u;const f=isClassicOrClassicThin(i)?3/4:1;return s.x+=-n*f-c,s.y+=-l*f-u,()=>{t.begin(),t.moveTo(g.x,g.y),t.lineTo(g.x-n-l/r,g.y-l+n/r),isClassicOrClassicThin(i)&&t.lineTo(g.x-n*3/4,g.y-l*3/4),t.lineTo(g.x+l/r-n,g.y-l-n/r),t.close(),d?t.fillAndStroke():t.stroke()}},createOpenArrow=r=>(t,e,i,s,n,l,o,a,h,d)=>{const c=n*h*1.118,u=l*h*1.118;n*=o+h,l*=o+h;const g=s.clone();return g.x-=c,g.y-=u,s.x+=-c*2,s.y+=-u*2,()=>{t.begin(),t.moveTo(g.x-n-l/r,g.y-l+n/r),t.lineTo(g.x,g.y),t.lineTo(g.x+l/r-n,g.y-l-n/r),t.stroke()}},oval=(r,t,e,i,s,n,l,o,a,h)=>{const d=l/2,c=i.clone();return i.x-=s*d,i.y-=n*d,()=>{r.ellipse(c.x-d,c.y-d,l,l),h?r.fillAndStroke():r.stroke()}},diamond=(r,t,e,i,s,n,l,o,a,h)=>{const d=isDiamond(e)?.7071:.9862,c=s*a*d,u=n*a*d;s*=l+a,n*=l+a;const g=i.clone();g.x-=c,g.y-=u,i.x+=-s-c,i.y+=-n-u;const f=isDiamond(e)?2:3.4;return()=>{r.begin(),r.moveTo(g.x,g.y),r.lineTo(g.x-s/2-n/f,g.y+s/f-n/2),r.lineTo(g.x-s,g.y-n),r.lineTo(g.x-s/2+n/f,g.y-n/2-s/f),r.close(),h?r.fillAndStroke():r.stroke()}};class BaseRegistry{constructor(){this.values=new Map}add(t,e){this.values.set(t,e)}get(t){return this.values.get(t)??null}getName(t){for(const[e,i]of this.values.entries())if(i===t)return e;return null}clear(){this.values.clear()}}class EdgeStyleRegistryImpl extends BaseRegistry{constructor(){super(...arguments),this.handlerMapping=new Map,this.orthogonalStates=new Map,this.intermediateHandlesStates=new Map}add(t,e,i){super.add(t,e),i!=null&&i.handlerKind&&this.handlerMapping.set(e,i.handlerKind),!isNullish(i==null?void 0:i.isOrthogonal)&&this.orthogonalStates.set(e,i.isOrthogonal),!isNullish(i==null?void 0:i.allowIntermediateHandles)&&this.intermediateHandlesStates.set(e,i.allowIntermediateHandles)}isOrthogonal(t){return this.orthogonalStates.get(t)??!1}getHandlerKind(t){return this.handlerMapping.get(t)??"default"}allowsIntermediateHandles(t){return this.intermediateHandlesStates.get(t)??!0}clear(){super.clear(),this.handlerMapping.clear(),this.orthogonalStates.clear(),this.intermediateHandlesStates.clear()}}const EdgeStyleRegistry=new EdgeStyleRegistryImpl;class CellHighlight{constructor(t,e,i,s){this.strokeWidth=0,this.dashed=!1,this.opacity=100,this.shape=null,this.keepOnTop=!1,this.state=null,this.spacing=2,this.graph=t,this.highlightColor=e??DEFAULT_VALID_COLOR,this.strokeWidth=i??HIGHLIGHT_STROKEWIDTH,this.dashed=s??!1,this.opacity=HIGHLIGHT_OPACITY,this.repaintHandler=()=>{if(this.state){const n=this.graph.view.getState(this.state.cell);n?(this.state=n,this.repaint()):this.hide()}},this.graph.getView().addListener(InternalEvent.SCALE,this.repaintHandler),this.graph.getView().addListener(InternalEvent.TRANSLATE,this.repaintHandler),this.graph.getView().addListener(InternalEvent.SCALE_AND_TRANSLATE,this.repaintHandler),this.graph.getDataModel().addListener(InternalEvent.CHANGE,this.repaintHandler),this.resetHandler=()=>{this.hide()},this.graph.getView().addListener(InternalEvent.DOWN,this.resetHandler),this.graph.getView().addListener(InternalEvent.UP,this.resetHandler)}setHighlightColor(t){this.highlightColor=t,this.shape&&(this.shape.stroke=t)}drawHighlight(){var t;if(this.shape=this.createShape(),this.repaint(),this.shape){const e=this.shape.node;!this.keepOnTop&&((t=e==null?void 0:e.parentNode)==null?void 0:t.firstChild)!==e&&e.parentNode&&e.parentNode.insertBefore(e,e.parentNode.firstChild)}}createShape(){if(!this.state)return null;const t=this.graph.cellRenderer.createShape(this.state);return t.svgStrokeTolerance=this.graph.getEventTolerance(),t.points=this.state.absolutePoints,t.apply(this.state),t.stroke=this.highlightColor,t.opacity=this.opacity,t.isDashed=this.dashed,t.isShadow=!1,t.dialect="svg",t.init(this.graph.getView().getOverlayPane()),InternalEvent.redirectMouseEvents(t.node,this.graph,this.state),this.graph.dialect!=="svg"?t.pointerEvents=!1:t.svgPointerEvents="stroke",t}getStrokeWidth(t=null){return this.strokeWidth}repaint(){this.state&&this.shape&&(this.shape.scale=this.state.view.scale,this.state.cell.isEdge()?(this.shape.strokeWidth=this.getStrokeWidth(),this.shape.points=this.state.absolutePoints,this.shape.outline=!1):(this.shape.bounds=new Rectangle(this.state.x-this.spacing,this.state.y-this.spacing,this.state.width+2*this.spacing,this.state.height+2*this.spacing),this.shape.rotation=this.state.style.rotation??0,this.shape.strokeWidth=this.getStrokeWidth()/this.state.view.scale,this.shape.outline=!0),this.state.shape&&this.shape.setCursor(this.state.shape.getCursor()),this.shape.redraw())}hide(){this.highlight(null)}highlight(t=null){this.state!==t&&(this.shape&&(this.shape.destroy(),this.shape=null),this.state=t,this.state&&this.drawHighlight())}isHighlightAt(t,e){let i=!1;if(this.shape&&document.elementFromPoint){let s=document.elementFromPoint(t,e);for(;s;){if(s===this.shape.node){i=!0;break}s=s.parentNode}}return i}destroy(){const t=this.graph;t.getView().removeListener(this.resetHandler),t.getView().removeListener(this.repaintHandler),t.getDataModel().removeListener(this.repaintHandler),this.shape&&(this.shape.destroy(),this.shape=null)}}class CellMarker extends EventSource{constructor(t,e=DEFAULT_VALID_COLOR,i=DEFAULT_INVALID_COLOR,s=DEFAULT_HOTSPOT){super(),this.enabled=!0,this.hotspot=DEFAULT_HOTSPOT,this.hotspotEnabled=!1,this.currentColor=NONE,this.validState=null,this.markedState=null,this.graph=t,this.validColor=e,this.invalidColor=i,this.hotspot=s,this.highlight=this.createCellHighlight(t)}createCellHighlight(t){return new CellHighlight(t)}setEnabled(t){this.enabled=t}isEnabled(){return this.enabled}setHotspot(t){this.hotspot=t}getHotspot(){return this.hotspot}setHotspotEnabled(t){this.hotspotEnabled=t}isHotspotEnabled(){return this.hotspotEnabled}hasValidState(){return!!this.validState}getValidState(){return this.validState}getMarkedState(){return this.markedState}reset(){this.validState=null,this.markedState&&(this.markedState=null,this.unmark())}process(t){let e=null;return this.isEnabled()&&(e=this.getState(t),this.setCurrentState(e,t)),e}setCurrentState(t,e,i){const s=t?this.isValidState(t):!1;i=i??this.getMarkerColor(e.getEvent(),t,s),s?this.validState=t:this.validState=null,(t!==this.markedState||i!==this.currentColor)&&(this.currentColor=i,t&&this.currentColor!==NONE?(this.markedState=t,this.mark()):this.markedState&&(this.markedState=null,this.unmark()))}markCell(t,e){const i=this.graph.getView().getState(t);i&&(this.currentColor=e??this.validColor,this.markedState=i,this.mark())}mark(){this.highlight.setHighlightColor(this.currentColor),this.highlight.highlight(this.markedState),this.fireEvent(new EventObject(InternalEvent.MARK,"state",this.markedState))}unmark(){this.mark()}isValidState(t){return!0}getMarkerColor(t,e,i){return i?this.validColor:this.invalidColor}getState(t){const e=this.graph.getView(),i=this.getCell(t);if(!i)return null;const s=this.getStateToMark(e.getState(i));return s&&this.intersects(s,t)?s:null}getCell(t){return t.getCell()}getStateToMark(t){return t}intersects(t,e){const i=e.getGraphX(),s=e.getGraphY();return this.hotspotEnabled?intersectsHotspot(t,i,s,this.hotspot,MIN_HOTSPOT_SIZE,MAX_HOTSPOT_SIZE):!0}destroy(){this.highlight.destroy(),super.destroy()}}class UrlConverter{constructor(){this.enabled=!0,this.baseUrl=null,this.baseDomain=null}updateBaseUrl(){this.baseDomain=`${location.protocol}//${location.host}`,this.baseUrl=this.baseDomain+location.pathname;const t=this.baseUrl.lastIndexOf("/");t>0&&(this.baseUrl=this.baseUrl.substring(0,t+1))}isEnabled(){return this.enabled}setEnabled(t){this.enabled=t}getBaseUrl(){return this.baseUrl}setBaseUrl(t){this.baseUrl=t}getBaseDomain(){return this.baseDomain}setBaseDomain(t){this.baseDomain=t}isRelativeUrl(t){return t&&t.substring(0,2)!=="//"&&t.substring(0,7)!=="http://"&&t.substring(0,8)!=="https://"&&t.substring(0,10)!=="data:image"&&t.substring(0,7)!=="file://"}convert(t){return this.isEnabled()&&this.isRelativeUrl(t)&&(this.getBaseUrl()||this.updateBaseUrl(),t.charAt(0)==="/"?t=this.getBaseDomain()+t:t=this.getBaseUrl()+t),t}}class AbstractCanvas2D{constructor(){this.state=this.createState(),this.states=[],this.path=[],this.rotateHtml=!0,this.lastX=0,this.lastY=0,this.moveOp="M",this.lineOp="L",this.quadOp="Q",this.curveOp="C",this.closeOp="Z",this.pointerEvents=!1,this.pointerEventsValue=null,this.addOp=(t,...e)=>{if(this.path.push(t),e.length>1){const i=this.state;for(let s=1;s<e.length;s+=2)this.lastX=e[s-1],this.lastY=e[s],this.path.push(this.format((this.lastX+i.dx)*i.scale)),this.path.push(this.format((this.lastY+i.dy)*i.scale))}},this.converter=this.createUrlConverter(),this.reset()}createUrlConverter(){return new UrlConverter}reset(){this.state=this.createState(),this.states=[]}createState(){return{dx:0,dy:0,scale:1,alpha:1,fillAlpha:1,strokeAlpha:1,fillColor:NONE,gradientFillAlpha:1,gradientColor:NONE,gradientAlpha:1,gradientDirection:"east",strokeColor:NONE,strokeWidth:1,dashed:!1,dashPattern:"3 3",fixDash:!1,lineCap:"flat",lineJoin:"miter",miterLimit:10,fontColor:"#000000",fontBackgroundColor:NONE,fontBorderColor:NONE,fontSize:StyleDefaultsConfig.fontSize,fontFamily:StyleDefaultsConfig.fontFamily,fontStyle:0,shadow:!1,shadowColor:StyleDefaultsConfig.shadowColor,shadowAlpha:StyleDefaultsConfig.shadowOpacity,shadowDx:StyleDefaultsConfig.shadowOffsetX,shadowDy:StyleDefaultsConfig.shadowOffsetY,rotation:0,rotationCx:0,rotationCy:0}}format(t){return Math.round(t)}rotatePoint(t,e,i,s,n){const l=i*(Math.PI/180);return getRotatedPoint(new Point(t,e),Math.cos(l),Math.sin(l),new Point(s,n))}save(){this.states.push(this.state),this.state=clone(this.state)}restore(){const t=this.states.pop();t&&(this.state=t)}setLink(t){}scale(t){this.state.scale*=t,this.state.strokeWidth!==null&&(this.state.strokeWidth*=t)}translate(t,e){this.state.dx+=t,this.state.dy+=e}rotate(t,e,i,s,n){}setAlpha(t){this.state.alpha=t}setFillAlpha(t){this.state.fillAlpha=t}setStrokeAlpha(t){this.state.strokeAlpha=t}setFillColor(t){this.state.fillColor=t??NONE,this.state.gradientColor=NONE}setGradient(t,e,i,s,n,l,o,a=1,h=1){const d=this.state;d.fillColor=t,d.gradientFillAlpha=a,d.gradientColor=e,d.gradientAlpha=h,d.gradientDirection=o}setStrokeColor(t){this.state.strokeColor=t??NONE}setStrokeWidth(t){this.state.strokeWidth=t}setDashed(t,e=!1){this.state.dashed=t,this.state.fixDash=e}setDashPattern(t){this.state.dashPattern=t}setLineCap(t){this.state.lineCap=t}setLineJoin(t){this.state.lineJoin=t}setMiterLimit(t){this.state.miterLimit=t}setFontColor(t){this.state.fontColor=t??NONE}setFontBackgroundColor(t){this.state.fontBackgroundColor=t??NONE}setFontBorderColor(t){this.state.fontBorderColor=t??NONE}setFontSize(t){this.state.fontSize=t}setFontFamily(t){this.state.fontFamily=t}setFontStyle(t){this.state.fontStyle=t}setShadow(t){this.state.shadow=t}setShadowColor(t){this.state.shadowColor=t??NONE}setShadowAlpha(t){this.state.shadowAlpha=t}setShadowOffset(t,e){this.state.shadowDx=t,this.state.shadowDy=e}begin(){this.lastX=0,this.lastY=0,this.path=[]}moveTo(t,e){this.addOp(this.moveOp,t,e)}lineTo(t,e){this.addOp(this.lineOp,t,e)}quadTo(t,e,i,s){this.addOp(this.quadOp,t,e,i,s)}curveTo(t,e,i,s,n,l){this.addOp(this.curveOp,t,e,i,s,n,l)}arcTo(t,e,i,s,n,l,o){const a=arcToCurves(this.lastX,this.lastY,t,e,i,s,n,l,o);if(a!=null)for(let h=0;h<a.length;h+=6)this.curveTo(a[h],a[h+1],a[h+2],a[h+3],a[h+4],a[h+5])}close(t,e,i,s,n,l){this.addOp(this.closeOp)}}const parseXml=r=>new DOMParser().parseFromString(r,"text/xml"),getXml=(r,t="&#xa;")=>{let i=new XMLSerializer().serializeToString(r);return i=i.replace(/\n/g,t),i},useAbsoluteIds=typeof DOMParser=="function"&&!Client.IS_CHROMEAPP&&!Client.IS_EDGE&&document.getElementsByTagName("base").length>0;class SvgCanvas2D extends AbstractCanvas2D{constructor(t,e){super(),this.defs=null,this.styleEnabled=!0,this.node=null,this.matchHtmlAlignment=!0,this.textEnabled=!0,this.foEnabled=!0,this.foAltText="[Object]",this.foOffset=0,this.textOffset=0,this.imageOffset=0,this.strokeTolerance=0,this.minStrokeWidth=1,this.refCount=0,this.lineHeightCorrection=1,this.pointerEventsValue="all",this.fontMetricsPadding=10,this.cacheOffsetSize=!0,this.originalRoot=null,this.root=t,this.gradients={},this.defs=null,this.styleEnabled=e??!1;let i=null;if(t.ownerDocument!==document){let s=t;for(;s&&s.nodeName!=="svg";)s=s.parentElement;i=s}i&&(i.getElementsByTagName("defs").length>0&&(this.defs=i.getElementsByTagName("defs")[0]),this.defs||(this.defs=this.createElement("defs"),i.firstChild!=null?i.insertBefore(this.defs,i.firstChild):i.appendChild(this.defs)),this.styleEnabled&&this.defs.appendChild(this.createStyle()))}format(t){return Number.parseFloat(t.toFixed(2))}getBaseUrl(){let{href:t}=window.location;const e=t.lastIndexOf("#");return e>0&&(t=t.substring(0,e)),t}reset(){super.reset(),this.gradients={}}end(){}createStyle(){const t=this.createElement("style");return t.setAttribute("type","text/css"),write(t,`svg{font-family:${StyleDefaultsConfig.fontFamily};font-size:${StyleDefaultsConfig.fontSize};fill:none;stroke-miterlimit:10}`),t}createElement(t,e){var i;return(i=this.root)==null?void 0:i.ownerDocument.createElementNS(e||NS_SVG,t)}getAlternateText(t,e,i,s,n,l,o,a,h,d,c,u,g){return isNullish(l)?null:this.foAltText}createAlternateContent(t,e,i,s,n,l,o,a,h,d,c,u,g){const f=this.getAlternateText(t,e,i,s,n,l,o,a,h,d,c,u,g),p=this.state;if(!isNullish(f)&&p.fontSize>0){const y=a==="top"?1:a==="bottom"?0:.3,v=o==="right"?"end":o==="left"?"start":"middle",S=this.createElement("text");S.setAttribute("x",String(Math.round(e+p.dx))),S.setAttribute("y",String(Math.round(i+p.dy+y*p.fontSize))),S.setAttribute("fill",p.fontColor||"black"),S.setAttribute("font-family",p.fontFamily),S.setAttribute("font-size",`${Math.round(p.fontSize)}px`),v!=="start"&&S.setAttribute("text-anchor",v);const w=p.fontStyle;matchBinaryMask(w,FONT_STYLE_MASK.BOLD)&&S.setAttribute("font-weight","bold"),matchBinaryMask(w,FONT_STYLE_MASK.ITALIC)&&S.setAttribute("font-style","italic");const C=[];return matchBinaryMask(w,FONT_STYLE_MASK.UNDERLINE)&&C.push("underline"),matchBinaryMask(w,FONT_STYLE_MASK.STRIKETHROUGH)&&C.push("line-through"),C.length>0&&S.setAttribute("text-decoration",C.join(" ")),write(S,f),S}return null}createGradientId(t,e,i,s,n){t.charAt(0)==="#"&&(t=t.substring(1)),e.charAt(0)==="#"&&(e=e.substring(1)),t=`${t.toLowerCase()}-${i}`,e=`${e.toLowerCase()}-${s}`;let l=null;if(n==null||n==="south")l="s";else if(n==="east")l="e";else{const o=t;t=e,e=o,n==="north"?l="s":n==="west"&&(l="e")}return`mx-gradient-${t}-${e}-${l}`}getSvgGradient(t,e,i,s,n){const l=this.createGradientId(t,e,i,s,n);let o=this.gradients[l];if(!o){const a=this.root.ownerSVGElement;let h=0,d=`${l}-${h}`;if(a)for(o=a.ownerDocument.getElementById(d);o&&o.ownerSVGElement!==a;)d=`${l}-${h++}`,o=a.ownerDocument.getElementById(d);else d=`id${++this.refCount}`;o||(o=this.createSvgGradient(t,e,i,s,n),o.setAttribute("id",d),this.defs?this.defs.appendChild(o):a&&a.appendChild(o)),this.gradients[l]=o}return o.getAttribute("id")}createSvgGradient(t,e,i,s,n){const l=this.createElement("linearGradient");if(l.setAttribute("x1","0%"),l.setAttribute("y1","0%"),l.setAttribute("x2","0%"),l.setAttribute("y2","0%"),n==null||n==="south")l.setAttribute("y2","100%");else switch(n){case"east":{l.setAttribute("x2","100%");break}case"north":{l.setAttribute("y1","100%");break}case"west":{l.setAttribute("x1","100%");break}}let o=i<1?`;stop-opacity:${i}`:"",a=this.createElement("stop");return a.setAttribute("offset","0%"),a.setAttribute("style",`stop-color:${t}${o}`),l.appendChild(a),o=s<1?`;stop-opacity:${s}`:"",a=this.createElement("stop"),a.setAttribute("offset","100%"),a.setAttribute("style",`stop-color:${e}${o}`),l.appendChild(a),l}addNode(t,e){const{node:i}=this,s=this.state;if(i){if(i.nodeName==="path")if(this.path&&this.path.length>0)i.setAttribute("d",this.path.join(" "));else return;t&&s.fillColor!==NONE?this.updateFill():this.styleEnabled||(i.nodeName==="ellipse"&&Client.IS_FF?i.setAttribute("fill","transparent"):i.setAttribute("fill",NONE),t=!1),e&&s.strokeColor!==NONE?this.updateStroke():this.styleEnabled||i.setAttribute("stroke",NONE),s.transform&&s.transform.length>0&&i.setAttribute("transform",s.transform),s.shadow&&this.root.appendChild(this.createShadow(i)),this.strokeTolerance>0&&!t&&this.root.appendChild(this.createTolerance(i)),this.pointerEvents?i.setAttribute("pointer-events",this.pointerEventsValue):!this.pointerEvents&&!this.originalRoot&&i.setAttribute("pointer-events",NONE),(i.nodeName!=="rect"&&i.nodeName!=="path"&&i.nodeName!=="ellipse"||i.getAttribute("fill")!==NONE&&i.getAttribute("fill")!=="transparent"||i.getAttribute("stroke")!==NONE||i.getAttribute("pointer-events")!==NONE)&&this.root.appendChild(i),this.node=null}}updateFill(){var e;const t=this.state;if((t.alpha<1||t.fillAlpha<1)&&this.node.setAttribute("fill-opacity",String(t.alpha*t.fillAlpha)),t.fillColor!==NONE)if(t.gradientColor!==NONE){const i=this.getSvgGradient(t.fillColor,t.gradientColor,t.gradientFillAlpha,t.gradientAlpha,t.gradientDirection);if(((e=this.root)==null?void 0:e.ownerDocument)===document&&useAbsoluteIds){const s=this.getBaseUrl().replace(/([()])/g,"\\$1");this.node.setAttribute("fill",`url(${s}#${i})`)}else this.node.setAttribute("fill",`url(#${i})`)}else this.node.setAttribute("fill",t.fillColor.toLowerCase())}getCurrentStrokeWidth(){return Math.max(this.minStrokeWidth,Math.max(.01,this.format(this.state.strokeWidth*this.state.scale)))}updateStroke(){const t=this.state;t.strokeColor&&t.strokeColor!==NONE&&this.node.setAttribute("stroke",t.strokeColor.toLowerCase()),(t.alpha<1||t.strokeAlpha<1)&&this.node.setAttribute("stroke-opacity",String(t.alpha*t.strokeAlpha));const e=this.getCurrentStrokeWidth();e!==1&&this.node.setAttribute("stroke-width",String(e)),this.node.nodeName==="path"&&this.updateStrokeAttributes(),t.dashed&&this.node.setAttribute("stroke-dasharray",this.createDashPattern((t.fixDash?1:t.strokeWidth)*t.scale))}updateStrokeAttributes(){const t=this.state;if(t.lineJoin&&t.lineJoin!=="miter"&&this.node.setAttribute("stroke-linejoin",t.lineJoin),t.lineCap){let e=t.lineCap;e==="flat"&&(e="butt"),e!=="butt"&&this.node.setAttribute("stroke-linecap",e)}t.miterLimit!=null&&(!this.styleEnabled||t.miterLimit!==10)&&this.node.setAttribute("stroke-miterlimit",String(t.miterLimit))}createDashPattern(t){const e=[];if(typeof this.state.dashPattern=="string"){const i=this.state.dashPattern.split(" ");if(i.length>0)for(let s=0;s<i.length;s+=1)e[s]=Number(i[s])*t}return e.join(" ")}createTolerance(t){const e=t.cloneNode(!0),i=Number.parseFloat(e.getAttribute("stroke-width")||"1")+this.strokeTolerance;return e.setAttribute("pointer-events","stroke"),e.setAttribute("visibility","hidden"),e.removeAttribute("stroke-dasharray"),e.setAttribute("stroke-width",String(i)),e.setAttribute("fill","none"),e.setAttribute("stroke","white"),e}createShadow(t){const e=t.cloneNode(!0),i=this.state;return e.getAttribute("fill")!=="none"&&(!Client.IS_FF||e.getAttribute("fill")!=="transparent")&&e.setAttribute("fill",i.shadowColor),e.getAttribute("stroke")!=="none"&&i.shadowColor&&i.shadowColor!==NONE&&e.setAttribute("stroke",i.shadowColor),e.setAttribute("transform",`translate(${this.format(i.shadowDx*i.scale)},${this.format(i.shadowDy*i.scale)})${i.transform||""}`),e.setAttribute("opacity",String(i.shadowAlpha)),e}setLink(t){if(!t)this.root=this.originalRoot;else{this.originalRoot=this.root;const e=this.createElement("a");e.setAttributeNS==null||this.root.ownerDocument!==document?e.setAttribute("xlink:href",t):e.setAttributeNS(NS_XLINK,"xlink:href",t),this.root.appendChild(e),this.root=e}}rotate(t,e,i,s,n){if(t!==0||e||i){const l=this.state;if(s+=l.dx,n+=l.dy,s*=l.scale,n*=l.scale,l.transform=l.transform||"",e&&i)t+=180;else if(e!==i){const o=e?s:0,a=e?-1:1,h=i?n:0,d=i?-1:1;l.transform+=`translate(${this.format(o)},${this.format(h)})scale(${this.format(a)},${this.format(d)})translate(${this.format(-o)},${this.format(-h)})`}(e?!i:i)&&(t*=-1),t!==0&&(l.transform+=`rotate(${this.format(t)},${this.format(s)},${this.format(n)})`),l.rotation+=t,l.rotationCx=s,l.rotationCy=n}}begin(){super.begin(),this.node=this.createElement("path")}rect(t,e,i,s){const n=this.state,l=this.createElement("rect");l.setAttribute("x",String(this.format((t+n.dx)*n.scale))),l.setAttribute("y",String(this.format((e+n.dy)*n.scale))),l.setAttribute("width",String(this.format(i*n.scale))),l.setAttribute("height",String(this.format(s*n.scale))),this.node=l}roundrect(t,e,i,s,n,l){this.rect(t,e,i,s),n>0&&this.node.setAttribute("rx",String(this.format(n*this.state.scale))),l>0&&this.node.setAttribute("ry",String(this.format(l*this.state.scale)))}ellipse(t,e,i,s){const n=this.state,l=this.createElement("ellipse");l.setAttribute("cx",String(this.format((t+i/2+n.dx)*n.scale))),l.setAttribute("cy",String(this.format((e+s/2+n.dy)*n.scale))),l.setAttribute("rx",String(i/2*n.scale)),l.setAttribute("ry",String(s/2*n.scale)),this.node=l}image(t,e,i,s,n,l=!0,o=!1,a=!1){n=this.converter.convert(n);const h=this.state;t+=h.dx,e+=h.dy;const d=this.createElement("image");d.setAttribute("x",String(this.format(t*h.scale)+this.imageOffset)),d.setAttribute("y",String(this.format(e*h.scale)+this.imageOffset)),d.setAttribute("width",String(this.format(i*h.scale))),d.setAttribute("height",String(this.format(s*h.scale))),d.setAttributeNS?d.setAttributeNS(NS_XLINK,"xlink:href",n):d.setAttribute("xlink:href",n),l||d.setAttribute("preserveAspectRatio","none"),(h.alpha<1||h.fillAlpha<1)&&d.setAttribute("opacity",String(h.alpha*h.fillAlpha));let c=this.state.transform||"";if(o||a){let u=1,g=1,f=0,p=0;o&&(u=-1,f=-i-2*t),a&&(g=-1,p=-s-2*e),c+=`scale(${u},${g})translate(${f*h.scale},${p*h.scale})`}c.length>0&&d.setAttribute("transform",c),this.pointerEvents||d.setAttribute("pointer-events","none"),this.root.appendChild(d)}convertHtml(t){const e=new DOMParser().parseFromString(t,"text/html");return e&&(t=new XMLSerializer().serializeToString(e.body),t.substring(0,5)==="<body"&&(t=t.substring(t.indexOf(">",5)+1)),t.substring(t.length-7,t.length)==="</body>"&&(t=t.substring(0,t.length-7))),t}createDiv(t){let e=t;if(isNode(e)||(e=`<div><div>${this.convertHtml(e)}</div></div>`),document.createElementNS){const i=document.createElementNS("http://www.w3.org/1999/xhtml","div");if(isNode(e)){const s=document.createElement("div"),n=s.cloneNode(!1);this.root.ownerDocument!==document?s.appendChild(e.cloneNode(!0)):s.appendChild(e),n.appendChild(s),i.appendChild(n)}else i.innerHTML=e;return i}return isNode(e)&&(e=`<div><div>${getXml(e)}</div></div>`),e=`<div xmlns="http://www.w3.org/1999/xhtml">${e}</div>`,parseXml(e).documentElement}updateText(t,e,i,s,n,l,o,a,h,d,c){c&&c.firstChild&&c.firstChild.firstChild&&this.updateTextNodes(t,e,i,s,n,l,o,a,h,d,c.firstChild)}addForeignObject(t,e,i,s,n,l,o,a,h,d,c,u,g,f,p){var S;const y=this.createElement("g"),v=this.createElement("foreignObject");if(v.setAttribute("style","overflow: visible; text-align: left;"),v.setAttribute("pointer-events","none"),v.appendChild(f),y.appendChild(v),this.updateTextNodes(t,e,i,s,l,o,a,d,c,u,y),((S=this.root)==null?void 0:S.ownerDocument)!==document){const w=this.createAlternateContent(v,t,e,i,s,n,l,o,a,h,d,c,u);if(w!=null){v.setAttribute("requiredFeatures","http://www.w3.org/TR/SVG11/feature#Extensibility");const C=this.createElement("switch");C.appendChild(v),C.appendChild(w),y.appendChild(C)}}p.appendChild(y)}updateTextNodes(t,e,i,s,n,l,o,a,h,d,c){const u=this.state.scale;SvgCanvas2D.createCss(i+2,s,n,l,o,a,h,this.state.fontBackgroundColor!=null?this.state.fontBackgroundColor:null,this.state.fontBorderColor!=null?this.state.fontBorderColor:null,`display: flex; align-items: unsafe ${l==="top"?"flex-start":l==="bottom"?"flex-end":"center"}; justify-content: unsafe ${n==="left"?"flex-start":n==="right"?"flex-end":"center"}; `,this.getTextCss(),u,(g,f,p,y,v)=>{t+=this.state.dx,e+=this.state.dy;const S=c.firstChild,w=S.firstChild,C=w.firstChild,m=C.firstChild,M=(this.rotateHtml?this.state.rotation:0)+(d??0);let b=(this.foOffset!==0?`translate(${this.foOffset} ${this.foOffset})`:"")+(u!==1?`scale(${u})`:"");m.setAttribute("style",v),C.setAttribute("style",y),S.setAttribute("width",`${Math.ceil(1/Math.min(1,u)*100)}%`),S.setAttribute("height",`${Math.ceil(1/Math.min(1,u)*100)}%`);const O=Math.round(e+f);O<0?S.setAttribute("y",String(O)):(S.removeAttribute("y"),p+=`padding-top: ${O}px; `),w.setAttribute("style",`${p}margin-left: ${Math.round(t+g)}px;`),b+=M!==0?`rotate(${M} ${t} ${e})`:"",b!==""?c.setAttribute("transform",b):c.removeAttribute("transform"),this.state.alpha!==1?c.setAttribute("opacity",String(this.state.alpha)):c.removeAttribute("opacity")})}getTextCss(){const t=this.state,e=LINE_HEIGHT*this.lineHeightCorrection;let i=`display: inline-block; font-size: ${t.fontSize}px; font-family: ${t.fontFamily}; color: ${t.fontColor}; line-height: ${e}; pointer-events: ${this.pointerEvents?this.pointerEventsValue:"none"}; `;const s=t.fontStyle;matchBinaryMask(s,FONT_STYLE_MASK.BOLD)&&(i+="font-weight: bold; "),matchBinaryMask(s,FONT_STYLE_MASK.ITALIC)&&(i+="font-style: italic; ");const n=[];return matchBinaryMask(s,FONT_STYLE_MASK.UNDERLINE)&&n.push("underline"),matchBinaryMask(s,FONT_STYLE_MASK.STRIKETHROUGH)&&n.push("line-through"),n.length>0&&(i+=`text-decoration: ${n.join(" ")}; `),i}text(t,e,i,s,n,l,o,a,h,d,c,u=0,g){if(this.textEnabled&&n!=null)if(u=u??0,this.foEnabled&&h==="html"){const f=this.createDiv(n);f!=null&&(g!=null&&f.setAttribute("dir",g),this.addForeignObject(t,e,i,s,n,l,o,a,h,d,c,u,g,f,this.root))}else this.plainText(t+this.state.dx,e+this.state.dy,i,s,n,l,o,a,d,c,u,g)}createClip(t,e,i,s){t=Math.round(t),e=Math.round(e),i=Math.round(i),s=Math.round(s);const n=`mx-clip-${t}-${e}-${i}-${s}`;let l=0,o=`${n}-${l}`;for(;document.getElementById(o)!=null;)o=`${n}-${++l}`;const a=this.createElement("clipPath");a.setAttribute("id",o);const h=this.createElement("rect");return h.setAttribute("x",String(t)),h.setAttribute("y",String(e)),h.setAttribute("width",String(i)),h.setAttribute("height",String(s)),a.appendChild(h),a}plainText(t,e,i,s,n,l,o,a,h,d,c=0,u){const g=this.state,f=g.fontSize,p=this.createElement("g");let y=g.transform||"";if(this.updateFont(p),!this.pointerEvents&&this.originalRoot==null&&p.setAttribute("pointer-events","none"),c!==0&&(y+=`rotate(${c},${this.format(t*g.scale)},${this.format(e*g.scale)})`),u!=null&&p.setAttribute("direction",u),d&&i>0&&s>0){let M=t,b=e;l==="center"?M-=i/2:l==="right"&&(M-=i),h!=="fill"&&(o==="middle"?b-=s/2:o==="bottom"&&(b-=s));const O=this.createClip(M*g.scale-2,b*g.scale-2,i*g.scale+4,s*g.scale+4);if(this.defs!=null?this.defs.appendChild(O):this.root.appendChild(O),!Client.IS_CHROMEAPP&&!Client.IS_EDGE&&this.root.ownerDocument===document){const R=this.getBaseUrl().replace(/([()])/g,"\\$1");p.setAttribute("clip-path",`url(${R}#${O.getAttribute("id")})`)}else p.setAttribute("clip-path",`url(#${O.getAttribute("id")})`)}const v=l==="right"?"end":l==="center"?"middle":"start";v!=="start"&&p.setAttribute("text-anchor",v),(!this.styleEnabled||f!==StyleDefaultsConfig.fontSize)&&p.setAttribute("font-size",`${f*g.scale}px`),y.length>0&&p.setAttribute("transform",y),g.alpha<1&&p.setAttribute("opacity",String(g.alpha));const S=n.split(`
7
- `),w=Math.round(f*LINE_HEIGHT),C=f+(S.length-1)*w;let m=e+f-1;if(o==="middle")if(h==="fill")m-=s/2;else{const M=(this.matchHtmlAlignment&&d&&s>0?Math.min(C,s):C)/2;m-=M}else if(o==="bottom")if(h==="fill")m-=s;else{const M=this.matchHtmlAlignment&&d&&s>0?Math.min(C,s):C;m-=M+1}for(let M=0;M<S.length;M+=1){const b=trim(S[M]);if(b){const O=this.createElement("text");O.setAttribute("x",String(this.format(t*g.scale)+this.textOffset)),O.setAttribute("y",String(this.format(m*g.scale)+this.textOffset)),write(O,b),p.appendChild(O)}m+=w}this.root.appendChild(p),this.addTextBackground(p,n,t,e,i,h==="fill"?s:C,l,o,h)}updateFont(t){const e=this.state;e.fontColor&&e.fontColor!==NONE&&t.setAttribute("fill",e.fontColor),(!this.styleEnabled||e.fontFamily!==StyleDefaultsConfig.fontFamily)&&t.setAttribute("font-family",e.fontFamily);const i=e.fontStyle;matchBinaryMask(i,FONT_STYLE_MASK.BOLD)&&t.setAttribute("font-weight","bold"),matchBinaryMask(i,FONT_STYLE_MASK.ITALIC)&&t.setAttribute("font-style","italic");const s=[];matchBinaryMask(i,FONT_STYLE_MASK.UNDERLINE)&&s.push("underline"),matchBinaryMask(i,FONT_STYLE_MASK.STRIKETHROUGH)&&s.push("line-through"),s.length>0&&t.setAttribute("text-decoration",s.join(" "))}addTextBackground(t,e,i,s,n,l,o,a,h){var c;const d=this.state;if(d.fontBackgroundColor!=null||d.fontBorderColor!=null){let u=null;if(h==="fill"||h==="width")o==="center"?i-=n/2:o==="right"&&(i-=n),a==="middle"?s-=l/2:a==="bottom"&&(s-=l),u=new Rectangle((i+1)*d.scale,s*d.scale,(n-2)*d.scale,(l+2)*d.scale);else if(t.getBBox!=null&&this.root.ownerDocument===document)try{u=t.getBBox(),u=new Rectangle(u.x,u.y+1,u.width,u.height+0)}catch{}if(u==null||u.width===0||u.height===0){const g=document.createElement("div");g.style.lineHeight=String(LINE_HEIGHT),g.style.fontSize=`${d.fontSize}px`,g.style.fontFamily=d.fontFamily,g.style.whiteSpace="nowrap",g.style.position="absolute",g.style.visibility="hidden",g.style.display="inline-block",matchBinaryMask(d.fontStyle,FONT_STYLE_MASK.BOLD)&&(g.style.fontWeight="bold"),matchBinaryMask(d.fontStyle,FONT_STYLE_MASK.ITALIC)&&(g.style.fontStyle="italic"),e=htmlEntities(e,!1),g.innerHTML=e.replace(/\n/g,"<br/>"),document.body.appendChild(g);const f=g.offsetWidth,p=g.offsetHeight;document.body.removeChild(g),o==="center"?i-=f/2:o==="right"&&(i-=f),a==="middle"?s-=p/2:a==="bottom"&&(s-=p),u=new Rectangle((i+1)*d.scale,(s+2)*d.scale,f*d.scale,(p+1)*d.scale)}if(u!=null){const g=this.createElement("rect");g.setAttribute("fill",d.fontBackgroundColor||"none"),g.setAttribute("stroke",d.fontBorderColor||"none"),g.setAttribute("x",String(Math.floor(u.x-1))),g.setAttribute("y",String(Math.floor(u.y-1))),g.setAttribute("width",String(Math.ceil(u.width+2))),g.setAttribute("height",String(Math.ceil(u.height)));const f=d.fontBorderColor?Math.max(1,this.format(d.scale)):0;g.setAttribute("stroke-width",String(f)),((c=this.root)==null?void 0:c.ownerDocument)===document&&mod(f,2)===1&&g.setAttribute("transform","translate(0.5, 0.5)"),t.insertBefore(g,t.firstChild)}}}stroke(){this.addNode(!1,!0)}fill(){this.addNode(!0,!1)}fillAndStroke(){this.addNode(!0,!0)}}SvgCanvas2D.createCss=(r,t,e,i,s,n,l,o,a,h,d,c,u)=>{let g=`box-sizing: border-box; font-size: 0; text-align: ${e==="left"?"left":e==="right"?"right":"center"}; `;const f=getAlignmentAsPoint(e,i);let p="overflow: hidden; ",y="width: 1px; ",v="height: 1px; ",S=f.x*r,w=f.y*t;l?(y=`width: ${Math.round(r)}px; `,g+=`max-height: ${Math.round(t)}px; `,w=0):n==="fill"?(y=`width: ${Math.round(r)}px; `,v=`height: ${Math.round(t)}px; `,d+="width: 100%; height: 100%; ",g+=y+v):n==="width"?(y=`width: ${Math.round(r)}px; `,d+="width: 100%; ",g+=y,w=0,t>0&&(g+=`max-height: ${Math.round(t)}px; `)):(p="",w=0);let C="";o&&(C+=`background-color: ${o}; `),a&&(C+=`border: 1px solid ${a}; `),p==""||l?d+=C:g+=C,s&&r>0?(d+=`white-space: normal; word-wrap: ${WORD_WRAP}; `,y=`width: ${Math.round(r)}px; `,p!==""&&n!=="fill"&&(w=0)):(d+="white-space: nowrap; ",p===""&&(S=0)),u(S,w,h+y+v,g+p,d,p)};class Shape{constructor(t=null){this.preserveImageAspect=!1,this.overlay=null,this.indicator=null,this.indicatorShape=null,this.opacity=100,this.isDashed=!1,this.fill=NONE,this.gradient=NONE,this.gradientDirection="east",this.fillOpacity=100,this.strokeOpacity=100,this.stroke=NONE,this.strokeWidth=1,this.spacing=0,this.startSize=1,this.endSize=1,this.startArrow=NONE,this.endArrow=NONE,this.direction="east",this.flipH=!1,this.flipV=!1,this.isShadow=!1,this.isRounded=!1,this.rotation=0,this.cursor="",this.verticalTextRotation=0,this.oldGradients={},this.glass=!1,this.dialect=null,this.scale=1,this.antiAlias=!0,this.minSvgStrokeWidth=1,this.bounds=null,this.points=[],this.state=null,this.style=null,this.boundingBox=null,this.stencil=null,this.svgStrokeTolerance=8,this.pointerEvents=!0,this.originalPointerEvents=null,this.svgPointerEvents="all",this.shapePointerEvents=!1,this.stencilPointerEvents=!1,this.outline=!1,this.visible=!0,this.useSvgBoundingBox=!0,this.image=null,this.imageSrc=null,this.indicatorColor=NONE,this.indicatorStrokeColor=NONE,this.indicatorGradientColor=NONE,this.indicatorDirection="east",this.indicatorImageSrc=null,t&&(this.stencil=t),this.node=this.create()}init(t){this.node.parentNode||t.appendChild(this.node)}initStyles(){this.strokeWidth=1,this.rotation=0,this.opacity=100,this.fillOpacity=100,this.strokeOpacity=100,this.flipH=!1,this.flipV=!1}isHtmlAllowed(){return!1}getSvgScreenOffset(){const t=this.stencil&&this.stencil.strokeWidthValue!=="inherit"?Number(this.stencil.strokeWidthValue):this.strokeWidth??0;return mod(Math.max(1,Math.round(t*this.scale)),2)===1?.5:0}create(){return document.createElementNS(NS_SVG,"g")}redraw(){this.updateBoundsFromPoints(),this.visible&&this.checkBounds()?(this.node.style.visibility="visible",this.clear(),this.redrawShape(),this.updateBoundingBox()):(this.node.style.visibility="hidden",this.boundingBox=null)}clear(){for(;this.node.lastChild;)this.node.removeChild(this.node.lastChild)}updateBoundsFromPoints(){const t=this.points;if(t.length>0&&t[0]){this.bounds=new Rectangle(Math.round(t[0].x),Math.round(t[0].y),1,1);for(const e of t)e&&this.bounds.add(new Rectangle(Math.round(e.x),Math.round(e.y),1,1))}}getLabelBounds(t){var n,l,o;const e=((n=this.style)==null?void 0:n.direction)??"east";let i=t.clone();e!=="south"&&e!=="north"&&this.state&&this.state.text&&this.state.text.isPaintBoundsInverted()&&(i=i.clone(),[i.width,i.height]=[i.height,i.width]);let s=this.getLabelMargins(i);if(s){s=s.clone();let a=((l=this.style)==null?void 0:l.flipH)??!1,h=((o=this.style)==null?void 0:o.flipV)??!1;if(this.state&&this.state.text&&this.state.text.isPaintBoundsInverted()){const d=s.x;s.x=s.height,s.height=s.width,s.width=s.y,s.y=d,[a,h]=[h,a]}return getDirectedBounds(t,s,this.style,a,h)}return t}getLabelMargins(t){return null}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)&&this.bounds.width>0&&this.bounds.height>0}redrawShape(){const t=this.createCanvas();t&&(t.pointerEvents=this.pointerEvents,this.beforePaint(t),this.paint(t),this.afterPaint(t),this.node!==t.root&&t.root&&this.node.insertAdjacentHTML("beforeend",t.root.outerHTML),this.destroyCanvas(t))}createCanvas(){const t=this.createSvgCanvas();return t&&this.outline&&(t.setStrokeWidth(this.strokeWidth),t.setStrokeColor(this.stroke),this.isDashed&&t.setDashed(this.isDashed),t.setStrokeWidth=()=>{},t.setStrokeColor=()=>{},t.setFillColor=()=>{},t.setGradient=()=>{},t.setDashed=()=>{},t.text=()=>{}),t}createSvgCanvas(){if(!this.node)return null;const t=new SvgCanvas2D(this.node,!1);t.strokeTolerance=this.pointerEvents?this.svgStrokeTolerance:0,t.pointerEventsValue=this.svgPointerEvents;const e=this.getSvgScreenOffset();return e!==0?this.node.setAttribute("transform",`translate(${e},${e})`):this.node.removeAttribute("transform"),t.minStrokeWidth=this.minSvgStrokeWidth,this.antiAlias||(t.format=i=>Math.round(i)),t}destroyCanvas(t){if(t instanceof SvgCanvas2D){for(const e in t.gradients){const i=t.gradients[e];i&&(i.mxRefCount=(i.mxRefCount||0)+1)}this.releaseSvgGradients(this.oldGradients),this.oldGradients=t.gradients}}beforePaint(t){}afterPaint(t){}paint(t){let e=!1;if(t&&this.outline){const{stroke:n}=t;t.stroke=(...o)=>{e=!0,n.apply(t,o)};const{fillAndStroke:l}=t;t.fillAndStroke=(...o)=>{e=!0,l.apply(t,o)}}const i=this.scale,s=this.bounds;if(s){let n=s.x/i,l=s.y/i,o=s.width/i,a=s.height/i;if(this.isPaintBoundsInverted()){const d=(o-a)/2;n+=d,l-=d;const c=o;o=a,a=c}this.updateTransform(t,n,l,o,a),this.configureCanvas(t,n,l,o,a);let h=null;if(!this.stencil&&this.points.length===0&&this.shapePointerEvents||this.stencil&&this.stencilPointerEvents){const d=this.createBoundingBox();d&&this.node&&(h=this.createTransparentSvgRectangle(d.x,d.y,d.width,d.height),this.node.appendChild(h))}if(this.stencil)this.stencil.drawShape(t,this,n,l,o,a);else if(t.setStrokeWidth(this.strokeWidth),this.points.length>0){const d=[];for(let c=0;c<this.points.length;c+=1){const u=this.points[c];u&&d.push(new Point(u.x/i,u.y/i))}this.paintEdgeShape(t,d)}else this.paintVertexShape(t,n,l,o,a);h&&t.state&&!isNullish(t.state.transform)&&h.setAttribute("transform",t.state.transform),t&&this.outline&&!e&&(t.rect(n,l,o,a),t.stroke())}}configureCanvas(t,e,i,s,n){var o;let l=null;if(this.style&&this.style.dashPattern!=null&&(l=this.style.dashPattern),t.setAlpha(this.opacity/100),t.setFillAlpha(this.fillOpacity/100),t.setStrokeAlpha(this.strokeOpacity/100),this.isShadow&&t.setShadow(this.isShadow),this.isDashed&&t.setDashed(this.isDashed,((o=this.style)==null?void 0:o.fixDash)??!1),l&&t.setDashPattern(l),this.fill!==NONE&&this.gradient!==NONE){const a=this.getGradientBounds(t,e,i,s,n);t.setGradient(this.fill,this.gradient,a.x,a.y,a.width,a.height,this.gradientDirection)}else t.setFillColor(this.fill);t.setStrokeColor(this.stroke)}getGradientBounds(t,e,i,s,n){return new Rectangle(e,i,s,n)}updateTransform(t,e,i,s,n){t.scale(this.scale),t.rotate(this.getShapeRotation(),this.flipH,this.flipV,e+s/2,i+n/2)}paintVertexShape(t,e,i,s,n){this.paintBackground(t,e,i,s,n),(!this.outline||!this.style||!(this.style.backgroundOutline??!1))&&(t.setShadow(!1),this.paintForeground(t,e,i,s,n))}paintBackground(t,e,i,s,n){}paintForeground(t,e,i,s,n){}paintEdgeShape(t,e){}getBaseArcSize(){var t;return(((t=this.style)==null?void 0:t.arcSize)??StyleDefaultsConfig.lineArcSize)/2}getArcSize(t,e){var s,n;if((s=this.style)!=null&&s.absoluteArcSize)return Math.min(this.getBaseArcSize(),Math.min(e,t)/2);const i=(((n=this.style)==null?void 0:n.arcSize)??StyleDefaultsConfig.roundingFactor*100)/100;return Math.min(t,e)*i}paintGlassEffect(t,e,i,s,n,l){const o=Math.ceil((this.strokeWidth??0)/2),a=.4;t.setGradient("#ffffff","#ffffff",e,i,s,n*.6,"south",.9,.1),t.begin(),l+=2*o,this.isRounded?(t.moveTo(e-o+l,i-o),t.quadTo(e-o,i-o,e-o,i-o+l),t.lineTo(e-o,i+n*a),t.quadTo(e+s*.5,i+n*.7,e+s+o,i+n*a),t.lineTo(e+s+o,i-o+l),t.quadTo(e+s+o,i-o,e+s+o-l,i-o)):(t.moveTo(e-o,i-o),t.lineTo(e-o,i+n*a),t.quadTo(e+s*.5,i+n*.7,e+s+o,i+n*a),t.lineTo(e+s+o,i-o)),t.close(),t.fill()}addPoints(t,e,i=!1,s,n=!1,l=[],o=!0){if(e.length>0){const a=e[e.length-1];if(n&&i){e=e.slice();const c=e[0],u=new Point(a.x+(c.x-a.x)/2,a.y+(c.y-a.y)/2);e.splice(0,0,u)}let h=e[0],d=1;for(o?t.moveTo(h.x,h.y):t.lineTo(h.x,h.y);d<(n?e.length:e.length-1);){let c=e[mod(d,e.length)],u=h.x-c.x,g=h.y-c.y;if(i&&(u!==0||g!==0)&&!l.includes(d-1)){let f=Math.sqrt(u*u+g*g);const p=u*Math.min(s,f/2)/f,y=g*Math.min(s,f/2)/f,v=c.x+p,S=c.y+y;t.lineTo(v,S);let w=e[mod(d+1,e.length)];for(;d<e.length-2&&Math.round(w.x-c.x)===0&&Math.round(w.y-c.y)===0;)w=e[mod(d+2,e.length)],d++;u=w.x-c.x,g=w.y-c.y,f=Math.max(1,Math.sqrt(u*u+g*g));const C=u*Math.min(s,f/2)/f,m=g*Math.min(s,f/2)/f,M=c.x+C,b=c.y+m;t.quadTo(c.x,c.y,M,b),c=new Point(M,b)}else t.lineTo(c.x,c.y);h=c,d+=1}n?t.close():t.lineTo(a.x,a.y)}}resetStyles(){this.initStyles(),this.spacing=0,this.fill=NONE,this.gradient=NONE,this.gradientDirection="east",this.stroke=NONE,this.startSize=1,this.endSize=1,this.startArrow=NONE,this.endArrow=NONE,this.direction="east",this.isShadow=!1,this.isDashed=!1,this.isRounded=!1,this.glass=!1}apply(t){if(this.state=t,this.style=t.style,this.style){if(this.fill=this.style.fillColor??this.fill,this.gradient=this.style.gradientColor??this.gradient,this.gradientDirection=this.style.gradientDirection??this.gradientDirection,this.opacity=this.style.opacity??this.opacity,this.fillOpacity=this.style.fillOpacity??this.fillOpacity,this.strokeOpacity=this.style.strokeOpacity??this.strokeOpacity,this.stroke=this.style.strokeColor??this.stroke,this.strokeWidth=this.style.strokeWidth??this.strokeWidth,this.spacing=this.style.spacing??this.spacing,this.startSize=this.style.startSize??this.startSize,this.endSize=this.style.endSize??this.endSize,this.startArrow=this.style.startArrow??this.startArrow,this.endArrow=this.style.endArrow??this.endArrow,this.rotation=this.style.rotation??this.rotation,this.direction=this.style.direction??this.direction,this.flipH=!!this.style.flipH,this.flipV=!!this.style.flipV,this.direction==="north"||this.direction==="south"){const e=this.flipH;this.flipH=this.flipV,this.flipV=e}this.isShadow=this.style.shadow??this.isShadow,this.isDashed=this.style.dashed??this.isDashed,this.isRounded=this.style.rounded??this.isRounded,this.glass=this.style.glass??this.glass}}setCursor(t){this.cursor=t,this.node.style.cursor=t}getCursor(){return this.cursor}isRoundable(t,e,i,s,n){return!1}updateBoundingBox(){if(this.useSvgBoundingBox&&this.node.ownerSVGElement)try{const t=this.node.getBBox();if(t.width>0&&t.height>0){this.boundingBox=new Rectangle(t.x,t.y,t.width,t.height),this.boundingBox.grow((this.strokeWidth??0)*this.scale/2);return}}catch{}if(this.bounds){let t=this.createBoundingBox();if(t){this.augmentBoundingBox(t);const e=this.getShapeRotation();e!==0&&(t=getBoundingBox(t,e))}this.boundingBox=t}}createBoundingBox(){if(!this.bounds)return null;const t=this.bounds.clone();return(this.stencil&&(this.direction==="north"||this.direction==="south")||this.isPaintBoundsInverted())&&t.rotate90(),t}augmentBoundingBox(t){this.isShadow&&(t.width+=Math.ceil(StyleDefaultsConfig.shadowOffsetX*this.scale),t.height+=Math.ceil(StyleDefaultsConfig.shadowOffsetX*this.scale)),t.grow((this.strokeWidth??0)*this.scale/2)}isPaintBoundsInverted(){return!this.stencil&&(this.direction==="north"||this.direction==="south")}getRotation(){return this.rotation??0}getTextRotation(){var e;let t=this.getRotation();return(((e=this.style)==null?void 0:e.horizontal)??!0)||(t+=this.verticalTextRotation||-90),t}getShapeRotation(){let t=this.getRotation();switch(this.direction){case"north":{t+=270;break}case"west":{t+=180;break}case"south":{t+=90;break}}return t}createTransparentSvgRectangle(t,e,i,s){const n=document.createElementNS(NS_SVG,"rect");return n.setAttribute("x",String(t)),n.setAttribute("y",String(e)),n.setAttribute("width",String(i)),n.setAttribute("height",String(s)),n.setAttribute("fill",NONE),n.setAttribute("stroke",NONE),n.setAttribute("pointer-events","all"),n}redrawHtmlShape(){}setTransparentBackgroundImage(t){t.style.backgroundImage=`url('${Client.imageBasePath}/transparent.gif')`}releaseSvgGradients(t){for(const e in t){const i=t[e];i&&(i.mxRefCount=(i.mxRefCount||0)-1,i.mxRefCount===0&&i.parentNode&&i.parentNode.removeChild(i))}}destroy(){InternalEvent.release(this.node),this.node.parentNode&&this.node.parentNode.removeChild(this.node),this.node.innerHTML="",this.releaseSvgGradients(this.oldGradients),this.oldGradients={}}}class EllipseShape extends Shape{constructor(t,e,i,s=1){super(),this.bounds=t,this.fill=e,this.stroke=i,this.strokeWidth=s}paintVertexShape(t,e,i,s,n){t.ellipse(e,i,s,n),t.fillAndStroke()}}class RectangleShape extends Shape{constructor(t,e,i,s=1){super(),this.bounds=t,this.fill=e,this.stroke=i,this.strokeWidth=s}isHtmlAllowed(){let t=!0;return this.style&&this.style.pointerEvents!=null&&(t=this.style.pointerEvents),!this.isRounded&&!this.glass&&this.rotation===0&&(t||this.fill!==NONE)}paintBackground(t,e,i,s,n){let l=!0;if(this.style&&this.style.pointerEvents!=null&&(l=this.style.pointerEvents),l||this.fill!==NONE||this.stroke!==NONE){if(!l&&this.fill===NONE&&(t.pointerEvents=!1),this.isRounded){const o=this.getArcSize(s,n);t.roundrect(e,i,s,n,o,o)}else t.rect(e,i,s,n);t.fillAndStroke()}}isRoundable(t,e,i,s,n){return!0}paintForeground(t,e,i,s,n){this.glass&&!this.outline&&this.fill!==NONE&&this.paintGlassEffect(t,e,i,s,n,this.getArcSize(s+this.strokeWidth,n+this.strokeWidth))}}class ImageShape extends RectangleShape{constructor(t,e,i="#FFFFFF",s="#000000",n=1){super(t,i,s,n),this.imageSrc=e,this.shadow=!1,this.preserveImageAspect=!0}getSvgScreenOffset(){return 0}apply(t){super.apply(t),this.fill=NONE,this.stroke=NONE,this.gradient=NONE,this.style&&this.style.imageAspect!=null&&(this.preserveImageAspect=this.style.imageAspect)}isHtmlAllowed(){return!this.preserveImageAspect}isRoundable(t,e,i,s,n){return!1}paintVertexShape(t,e,i,s,n){var l,o;if(this.imageSrc){const a=((l=this.style)==null?void 0:l.imageBackground)??NONE,h=((o=this.style)==null?void 0:o.imageBorder)??NONE;a!==NONE&&(t.setFillColor(a),t.setStrokeColor(h),t.rect(e,i,s,n),t.fillAndStroke()),t.image(e,i,s,n,this.imageSrc,this.preserveImageAspect,!1,!1),h!==NONE&&(t.setShadow(!1),t.setStrokeColor(h),t.rect(e,i,s,n),t.stroke())}else this.paintBackground(t,e,i,s,n)}}class ConnectionConstraint{constructor(t,e=!0,i=null,s=0,n=0){this.perimeter=!0,this.name=null,this.dx=0,this.dy=0,this.point=t,this.perimeter=e,this.name=i,this.dx=s,this.dy=n}}class ConstraintHandler{constructor(t){this.pointImage=new ImageBox(`${Client.imageBasePath}/point.gif`,5,5),this.currentFocus=null,this.currentFocusArea=null,this.focusIcons=[],this.constraints=null,this.currentConstraint=null,this.focusHighlight=null,this.focusPoints=[],this.currentPoint=null,this.enabled=!0,this.highlightColor=DEFAULT_VALID_COLOR,this.mouseleaveHandler=null,this.graph=t,this.resetHandler=()=>{this.currentFocus&&!this.graph.view.getState(this.currentFocus.cell)?this.reset():this.redraw()},this.graph.model.addListener(InternalEvent.CHANGE,this.resetHandler),this.graph.view.addListener(InternalEvent.SCALE_AND_TRANSLATE,this.resetHandler),this.graph.view.addListener(InternalEvent.TRANSLATE,this.resetHandler),this.graph.view.addListener(InternalEvent.SCALE,this.resetHandler),this.graph.addListener(InternalEvent.ROOT,this.resetHandler)}isEnabled(){return this.enabled}setEnabled(t){this.enabled=t}reset(){for(let t=0;t<this.focusIcons.length;t+=1)this.focusIcons[t].destroy();this.focusIcons=[],this.focusHighlight&&(this.focusHighlight.destroy(),this.focusHighlight=null),this.currentConstraint=null,this.currentFocusArea=null,this.currentPoint=null,this.currentFocus=null,this.focusPoints=[]}getTolerance(t){return this.graph.getEventTolerance()}getImageForConstraint(t,e,i){return this.pointImage}isEventIgnored(t,e=!1){return!1}isStateIgnored(t,e=!1){return!1}destroyIcons(){for(let t=0;t<this.focusIcons.length;t+=1)this.focusIcons[t].destroy();this.focusIcons=[],this.focusPoints=[]}destroyFocusHighlight(){this.focusHighlight&&(this.focusHighlight.destroy(),this.focusHighlight=null)}isKeepFocusEvent(t){return isShiftDown(t.getEvent())}getCellForEvent(t,e){let i=t.getCell();if(!i&&e&&(t.getGraphX()!==e.x||t.getGraphY()!==e.y)&&(i=this.graph.getCellAt(e.x,e.y)),i&&!i.isConnectable()){const s=i.getParent();s&&s.isVertex()&&s.isConnectable()&&(i=s)}return i?this.graph.isCellLocked(i)?null:i:null}update(t,e,i,s){if(this.isEnabled()&&!this.isEventIgnored(t)){!this.mouseleaveHandler&&this.graph.container&&(this.mouseleaveHandler=()=>{this.reset()},InternalEvent.addListener(this.graph.container,"mouseleave",this.resetHandler));const n=this.getTolerance(t),l=s?s.x:t.getGraphX(),o=s?s.y:t.getGraphY(),a=new Rectangle(l-n,o-n,2*n,2*n),h=new Rectangle(t.getGraphX()-n,t.getGraphY()-n,2*n,2*n),d=this.graph.view.getState(this.getCellForEvent(t,s));!this.isKeepFocusEvent(t)&&(!this.currentFocusArea||!this.currentFocus||d||!this.currentFocus.cell.isVertex()||!intersects(this.currentFocusArea,h))&&d!==this.currentFocus&&(this.currentFocusArea=null,this.currentFocus=null,this.setFocus(t,d,e)),this.currentConstraint=null,this.currentPoint=null;let c=null,u;if(this.focusIcons.length>0&&this.constraints&&(!d||this.currentFocus===d)){const g=h.getCenterX(),f=h.getCenterY();for(let p=0;p<this.focusIcons.length;p+=1){const y=g-this.focusIcons[p].bounds.getCenterX(),v=f-this.focusIcons[p].bounds.getCenterY();if(u=y*y+v*v,(this.intersects(this.focusIcons[p],h,e,i)||s&&this.intersects(this.focusIcons[p],a,e,i))&&(c===null||u<c)){if(this.currentConstraint=this.constraints[p],this.currentPoint=this.focusPoints[p],c=u,u=this.focusIcons[p].bounds.clone(),u.grow(HIGHLIGHT_SIZE+1),u.width-=1,u.height-=1,!this.focusHighlight){const S=this.createHighlightShape();S.dialect="svg",S.pointerEvents=!1,S.init(this.graph.getView().getOverlayPane()),this.focusHighlight=S;const w=()=>this.currentFocus?this.currentFocus:d;InternalEvent.redirectMouseEvents(S.node,this.graph,w)}this.focusHighlight.bounds=u,this.focusHighlight.redraw()}}}this.currentConstraint||this.destroyFocusHighlight()}else this.currentConstraint=null,this.currentFocus=null,this.currentPoint=null}redraw(){if(this.currentFocus&&this.constraints&&this.focusIcons.length>0){const t=this.graph.view.getState(this.currentFocus.cell);this.currentFocus=t,this.currentFocusArea=new Rectangle(t.x,t.y,t.width,t.height);for(let e=0;e<this.constraints.length;e+=1){const i=this.graph.getConnectionPoint(t,this.constraints[e]),s=this.getImageForConstraint(t,this.constraints[e],i),n=new Rectangle(Math.round(i.x-s.width/2),Math.round(i.y-s.height/2),s.width,s.height);this.focusIcons[e].bounds=n,this.focusIcons[e].redraw(),this.currentFocusArea.add(this.focusIcons[e].bounds),this.focusPoints[e]=i}}}setFocus(t,e,i){var s;if(this.constraints=e&&!this.isStateIgnored(e,i)&&e.cell.isConnectable()?this.isEnabled()?this.graph.getAllConnectionConstraints(e,i)??[]:[]:null,this.constraints&&e){this.currentFocus=e,this.currentFocusArea=new Rectangle(e.x,e.y,e.width,e.height);for(let n=0;n<this.focusIcons.length;n+=1)this.focusIcons[n].destroy();this.focusIcons=[],this.focusPoints=[];for(let n=0;n<this.constraints.length;n+=1){const l=this.graph.getConnectionPoint(e,this.constraints[n]),o=this.getImageForConstraint(e,this.constraints[n],l),{src:a}=o,h=new Rectangle(Math.round(l.x-o.width/2),Math.round(l.y-o.height/2),o.width,o.height),d=new ImageShape(h,a);d.dialect=this.graph.dialect!=="svg"?"mixedHtml":"svg",d.preserveImageAspect=!1,d.init(this.graph.getView().getDecoratorPane()),d.node.previousSibling&&((s=d.node.parentNode)==null||s.insertBefore(d.node,d.node.parentNode.firstChild));const c=()=>this.currentFocus?this.currentFocus:e;d.redraw(),InternalEvent.redirectMouseEvents(d.node,this.graph,c),this.currentFocusArea.add(d.bounds),this.focusIcons.push(d),this.focusPoints.push(l)}this.currentFocusArea.grow(this.getTolerance(t))}else this.destroyIcons(),this.destroyFocusHighlight()}createHighlightShape(){const t=new RectangleShape(new Rectangle,this.highlightColor,this.highlightColor,HIGHLIGHT_STROKEWIDTH);return t.opacity=HIGHLIGHT_OPACITY,t}intersects(t,e,i,s){return intersects(t.bounds,e)}onDestroy(){this.reset(),this.graph.model.removeListener(this.resetHandler),this.graph.view.removeListener(this.resetHandler),this.graph.removeListener(this.resetHandler),this.mouseleaveHandler&&this.graph.container&&(InternalEvent.removeListener(this.graph.container,"mouseleave",this.mouseleaveHandler),this.mouseleaveHandler=null)}}const EdgeHandlerConfig={connectFillColor:CONNECT_HANDLE_FILLCOLOR,cursorBend:"crosshair",cursorMovable:"move",cursorTerminal:"pointer",cursorVirtualBend:"crosshair",selectionColor:EDGE_SELECTION_COLOR,selectionDashed:EDGE_SELECTION_DASHED,selectionStrokeWidth:EDGE_SELECTION_STROKEWIDTH,virtualBendOpacity:20,virtualBendsEnabled:!1},HandleConfig={fillColor:HANDLE_FILLCOLOR,labelCursor:"default",labelFillColor:LABEL_HANDLE_FILLCOLOR,labelSize:LABEL_HANDLE_SIZE,size:HANDLE_SIZE,strokeColor:HANDLE_STROKECOLOR},VertexHandlerConfig={cursorMovable:"move",rotationEnabled:!1,selectionColor:VERTEX_SELECTION_COLOR,selectionStrokeWidth:VERTEX_SELECTION_STROKEWIDTH,selectionDashed:VERTEX_SELECTION_DASHED};class EdgeHandler{constructor(t){if(this.error=null,this.bends=[],this.cloneEnabled=!0,this.dblClickRemoveEnabled=!1,this.mergeRemoveEnabled=!1,this.straightRemoveEnabled=!1,this.parentHighlightEnabled=!1,this.preferHtml=!1,this.allowHandleBoundsCheck=!0,this.snapToTerminals=!1,this.handleImage=null,this.labelHandleImage=null,this.tolerance=0,this.outlineConnect=!1,this.manageLabelHandle=!1,this.currentPoint=null,this.parentHighlight=null,this.index=null,this.isSource=!1,this.isTarget=!1,this.isLabel=!1,this.points=[],this.snapPoint=null,this.abspoints=[],this.startX=0,this.startY=0,this.outline=!0,this.active=!0,this.state=t,this.graph=this.state.view.graph,this.marker=this.createMarker(),this.constraintHandler=this.createConstraintHandler(),this.points=[],this.abspoints=this.getSelectionPoints(this.state),this.shape=this.createSelectionShape(this.abspoints),this.shape.dialect=this.graph.dialect!=="svg"?"mixedHtml":"svg",this.shape.init(this.graph.getView().getOverlayPane()),this.shape.pointerEvents=!1,this.shape.setCursor(EdgeHandlerConfig.cursorMovable),InternalEvent.redirectMouseEvents(this.shape.node,this.graph,this.state),this.preferHtml=this.state.text!=null&&this.state.text.node.parentNode===this.graph.container,!this.preferHtml){const i=this.state.getVisibleTerminalState(!0);if(i!=null&&(this.preferHtml=i.text!=null&&i.text.node.parentNode===this.graph.container),!this.preferHtml){const s=this.state.getVisibleTerminalState(!1);s!=null&&(this.preferHtml=s.text!=null&&s.text.node.parentNode===this.graph.container)}}const e=this.graph.getPlugin("SelectionHandler");e&&(this.graph.getSelectionCount()<e.maxCells||e.maxCells<=0)&&(this.bends=this.createBends(),this.isVirtualBendsEnabled()&&(this.virtualBends=this.createVirtualBends())),this.label=new Point(this.state.absoluteOffset.x,this.state.absoluteOffset.y),this.labelShape=this.createLabelHandleShape(),this.initBend(this.labelShape),this.labelShape.setCursor(HandleConfig.labelCursor),this.customHandles=this.createCustomHandles(),this.updateParentHighlight(),this.redraw(),this.escapeHandler=(i,s)=>{const n=this.index!=null;this.reset(),n&&this.graph.cellRenderer.redraw(this.state,!1,t.view.isRendering())},this.state.view.graph.addListener(InternalEvent.ESCAPE,this.escapeHandler)}createConstraintHandler(){return new ConstraintHandler(this.graph)}isParentHighlightVisible(){const t=this.state.cell.getParent();return t?!this.graph.isCellSelected(t):null}updateParentHighlight(){if(!this.isDestroyed()){const t=this.isParentHighlightVisible(),e=this.state.cell.getParent(),i=e?this.graph.view.getState(e):null;if(this.parentHighlight)if(e&&e.isVertex()&&t){const s=this.parentHighlight.bounds;i&&s&&(s.x!==i.x||s.y!==i.y||s.width!==i.width||s.height!==i.height)&&(this.parentHighlight.bounds=Rectangle.fromRectangle(i),this.parentHighlight.redraw())}else i&&i.parentHighlight===this.parentHighlight&&(i.parentHighlight=null),this.parentHighlight.destroy(),this.parentHighlight=null;else this.parentHighlightEnabled&&t&&e&&e.isVertex()&&i&&!i.parentHighlight&&(this.parentHighlight=this.createParentHighlightShape(i),this.parentHighlight.dialect="svg",this.parentHighlight.pointerEvents=!1,i.style.rotation&&(this.parentHighlight.rotation=i.style.rotation),this.parentHighlight.init(this.graph.getView().getOverlayPane()),this.parentHighlight.redraw(),i.parentHighlight=this.parentHighlight)}}createCustomHandles(){return[]}isVirtualBendsEnabled(t){return EdgeHandlerConfig.virtualBendsEnabled}isCellEnabled(t){return!0}isAddPointEvent(t){return isShiftDown(t)}isRemovePointEvent(t){return isShiftDown(t)}getSelectionPoints(t){return t.absolutePoints}createParentHighlightShape(t){const e=new RectangleShape(Rectangle.fromRectangle(t),NONE,this.getSelectionColor());return e.strokeWidth=this.getSelectionStrokeWidth(),e.isDashed=this.isSelectionDashed(),e}createSelectionShape(t){const e=this.state.shape.constructor,i=new e;return i.outline=!0,i.apply(this.state),i.isDashed=this.isSelectionDashed(),i.stroke=this.getSelectionColor(),i.isShadow=!1,i}getSelectionColor(){return EdgeHandlerConfig.selectionColor}getSelectionStrokeWidth(){return EdgeHandlerConfig.selectionStrokeWidth}isSelectionDashed(){return EdgeHandlerConfig.selectionDashed}isConnectableCell(t){return!0}getCellAt(t,e){return this.outlineConnect?null:this.graph.getCellAt(t,e)}createMarker(){return new EdgeHandlerCellMarker(this.graph,this)}validateConnection(t,e){return this.graph.getEdgeValidationError(this.state.cell,t,e)}createBends(){const{cell:t}=this.state,e=[];for(let i=0;i<this.abspoints.length;i+=1)if(this.isHandleVisible(i)){const s=i===0,n=i===this.abspoints.length-1,l=s||n;(l||this.graph.isCellBendable(t))&&(o=>{const a=this.createHandleShape(o);this.initBend(a,()=>{this.dblClickRemoveEnabled&&this.removePoint(this.state,o)}),this.isHandleEnabled(i)&&a.setCursor(l?EdgeHandlerConfig.cursorTerminal:EdgeHandlerConfig.cursorBend),e.push(a),l||(this.points.push(new Point(0,0)),a.node.style.visibility="hidden")})(i)}return e}createVirtualBends(){const{cell:t}=this.state;this.abspoints[0];const e=[];if(this.graph.isCellBendable(t))for(let i=1;i<this.abspoints.length;i+=1)(s=>{this.initBend(s),s.setCursor(EdgeHandlerConfig.cursorVirtualBend),e.push(s)})(this.createHandleShape());return e}isHandleEnabled(t){return!0}isHandleVisible(t){const e=this.state.getVisibleTerminalState(!0),i=this.state.getVisibleTerminalState(!1),s=this.state.cell.getGeometry(),n=s?this.graph.view.getEdgeStyle(this.state,s.points||void 0,e,i):null;return EdgeStyleRegistry.allowsIntermediateHandles(n)||t===0||t===this.abspoints.length-1}createHandleShape(t){if(this.handleImage){const s=new ImageShape(new Rectangle(0,0,this.handleImage.width,this.handleImage.height),this.handleImage.src);return s.preserveImageAspect=!1,s}let e=HandleConfig.size;this.preferHtml&&(e-=1);const i=RectangleShape;return new i(new Rectangle(0,0,e,e),HandleConfig.fillColor,HandleConfig.strokeColor)}createLabelHandleShape(){if(this.labelHandleImage){const e=new ImageShape(new Rectangle(0,0,this.labelHandleImage.width,this.labelHandleImage.height),this.labelHandleImage.src);return e.preserveImageAspect=!1,e}const t=HandleConfig.labelSize;return new RectangleShape(new Rectangle(0,0,t,t),HandleConfig.labelFillColor,HandleConfig.strokeColor)}initBend(t,e){this.preferHtml?(t.dialect="strictHtml",t.init(this.graph.container)):(t.dialect=this.graph.dialect!=="svg"?"mixedHtml":"svg",t.init(this.graph.getView().getOverlayPane())),InternalEvent.redirectMouseEvents(t.node,this.graph,this.state,null,null,null,e),Client.IS_TOUCH&&t.node.setAttribute("pointer-events","none")}getHandleForEvent(t){let e=null;const i=isMouseEvent(t.getEvent())?1:this.tolerance,s=this.allowHandleBoundsCheck&&i>0?new Rectangle(t.getGraphX()-i,t.getGraphY()-i,2*i,2*i):null;let n=Number.POSITIVE_INFINITY;function l(o){if(o&&o.bounds&&o.node&&o.node.style.display!=="none"&&o.node.style.visibility!=="hidden"&&(t.isSource(o)||s&&intersects(o.bounds,s))){const a=t.getGraphX()-o.bounds.getCenterX(),h=t.getGraphY()-o.bounds.getCenterY(),d=a*a+h*h;if(d<=n)return n=d,!0}return!1}if(this.isCustomHandleEvent(t)&&this.customHandles){for(let o=this.customHandles.length-1;o>=0;o--)if(l(this.customHandles[o].shape))return InternalEvent.CUSTOM_HANDLE-o}(t.isSource(this.state.text)||l(this.labelShape))&&(e=InternalEvent.LABEL_HANDLE);for(let o=0;o<this.bends.length;o+=1)l(this.bends[o])&&(e=o);if(this.virtualBends&&this.isAddVirtualBendEvent(t))for(let o=0;o<this.virtualBends.length;o+=1)l(this.virtualBends[o])&&(e=InternalEvent.VIRTUAL_HANDLE-o);return e}isAddVirtualBendEvent(t){return!0}isCustomHandleEvent(t){return!0}mouseDown(t,e){const i=this.getHandleForEvent(e);if(i!==null&&this.bends[i]){const s=this.bends[i].bounds;s&&(this.snapPoint=new Point(s.getCenterX(),s.getCenterY()))}if(i!==null&&!e.isConsumed()&&this.graph.isEnabled()){const s=e.getCell();(i!==InternalEvent.LABEL_HANDLE||s&&this.graph.isLabelMovable(s))&&(this.virtualBends&&i<=InternalEvent.VIRTUAL_HANDLE&&setOpacity(this.virtualBends[InternalEvent.VIRTUAL_HANDLE-i].node,100),this.start(e.getX(),e.getY(),i)),e.consume()}}start(t,e,i){if(this.startX=t,this.startY=e,this.isSource=this.bends.length===0?!1:i===0,this.isTarget=this.bends.length===0?!1:i===this.bends.length-1,this.isLabel=i===InternalEvent.LABEL_HANDLE,this.isSource||this.isTarget){const{cell:s}=this.state,n=s.getTerminal(this.isSource);(n==null&&this.graph.isTerminalPointMovable(s,this.isSource)||n!=null&&this.graph.isCellDisconnectable(s,n,this.isSource))&&(this.index=i)}else this.index=i;if(this.index!==null&&this.index<=InternalEvent.CUSTOM_HANDLE&&this.index>InternalEvent.VIRTUAL_HANDLE&&this.customHandles!=null)for(let s=0;s<this.customHandles.length;s+=1)s!==InternalEvent.CUSTOM_HANDLE-this.index&&this.customHandles[s].setVisible(!1)}clonePreviewState(t,e){return this.state.clone()}getSnapToTerminalTolerance(){return this.graph.getGridSize()*this.graph.getView().scale/2}updateHint(t,e){}removeHint(){}roundLength(t){return Math.round(t)}isSnapToTerminalsEvent(t){return this.snapToTerminals&&!isAltDown(t.getEvent())}getPointForEvent(t){const e=this.graph.getView(),{scale:i}=e,s=new Point(this.roundLength(t.getGraphX()/i)*i,this.roundLength(t.getGraphY()/i)*i),n=this.getSnapToTerminalTolerance();let l=!1,o=!1;if(n>0&&this.isSnapToTerminalsEvent(t)){const a=d=>{if(d){const{x:c}=d;Math.abs(s.x-c)<n&&(s.x=c,l=!0);const{y:u}=d;Math.abs(s.y-u)<n&&(s.y=u,o=!0)}},h=d=>{d&&a(new Point(e.getRoutingCenterX(d),e.getRoutingCenterY(d)))};h(this.state.getVisibleTerminalState(!0)),h(this.state.getVisibleTerminalState(!1));for(let d=0;d<this.state.absolutePoints.length;d+=1)a(this.state.absolutePoints[d])}if(this.graph.isGridEnabledEvent(t.getEvent())){const a=e.translate;l||(s.x=(this.graph.snap(s.x/i-a.x)+a.x)*i),o||(s.y=(this.graph.snap(s.y/i-a.y)+a.y)*i)}return s}getPreviewTerminalState(t){if(this.constraintHandler.update(t,this.isSource,!0,t.isSource(this.marker.highlight.shape)?null:this.currentPoint),this.constraintHandler.currentFocus&&this.constraintHandler.currentConstraint){this.marker.highlight&&this.marker.highlight.shape&&this.marker.highlight.state&&this.marker.highlight.state.cell===this.constraintHandler.currentFocus.cell?this.marker.highlight.shape.stroke!=="transparent"&&(this.marker.highlight.shape.stroke="transparent",this.marker.highlight.repaint()):this.marker.markCell(this.constraintHandler.currentFocus.cell,"transparent");const e=this.graph.view.getTerminalPort(this.state,this.graph.view.getState(this.state.cell.getTerminal(!this.isSource)),!this.isSource),i=e?e.cell:null,s=this.isSource?this.constraintHandler.currentFocus.cell:i,n=this.isSource?i:this.constraintHandler.currentFocus.cell;this.error=this.validateConnection(s,n);let l=null;return this.error===null&&(l=this.constraintHandler.currentFocus),(this.error!==null||l&&!this.isCellEnabled(l.cell))&&this.constraintHandler.reset(),l}if(!this.graph.isIgnoreTerminalEvent(t.getEvent())){this.marker.process(t);const e=this.marker.getValidState();return e&&!this.isCellEnabled(e.cell)&&(this.constraintHandler.reset(),this.marker.reset()),this.marker.getValidState()}return this.marker.reset(),null}getPreviewPoints(t,e){const i=this.state.cell.getGeometry();if(!i)return null;let s=(i.points||[]).slice();const n=new Point(t.x,t.y);let l=null;if(!this.isSource&&!this.isTarget&&this.index!==null){if(this.convertPoint(n,!1),this.index<=InternalEvent.VIRTUAL_HANDLE&&s.splice(InternalEvent.VIRTUAL_HANDLE-this.index,0,n),!this.isSource&&!this.isTarget){for(let o=0;o<this.bends.length;o+=1)if(o!==this.index){const a=this.bends[o];a&&contains(a.bounds,t.x,t.y)&&(this.index<=InternalEvent.VIRTUAL_HANDLE?s.splice(InternalEvent.VIRTUAL_HANDLE-this.index,1):s.splice(this.index-1,1),l=s)}if(!l&&this.straightRemoveEnabled&&(!e||!isAltDown(e.getEvent()))){const o=this.graph.getEventTolerance()*this.graph.getEventTolerance(),a=this.state.absolutePoints.slice();a[this.index]=t;const h=this.state.getVisibleTerminalState(!0);if(h!=null){const u=this.graph.getConnectionConstraint(this.state,h,!0);(u==null||this.graph.getConnectionPoint(h,u)==null)&&(a[0]=new Point(h.view.getRoutingCenterX(h),h.view.getRoutingCenterY(h)))}const d=this.state.getVisibleTerminalState(!1);if(d!=null){const u=this.graph.getConnectionConstraint(this.state,d,!1);(u==null||this.graph.getConnectionPoint(d,u)==null)&&(a[a.length-1]=new Point(d.view.getRoutingCenterX(d),d.view.getRoutingCenterY(d)))}((u,g)=>{u>0&&u<a.length-1&&ptSegDistSq(a[u-1].x,a[u-1].y,a[u+1].x,a[u+1].y,g.x,g.y)<o&&(s.splice(u-1,1),l=s)})(this.index,t)}}l==null&&this.index>InternalEvent.VIRTUAL_HANDLE&&(s[this.index-1]=n)}else this.graph.isResetEdgesOnConnect()&&(s=[]);return l??s}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))}updatePreviewState(t,e,i,s,n=!1){const l=this.isSource?i:this.state.getVisibleTerminalState(!0),o=this.isTarget?i:this.state.getVisibleTerminalState(!1);let a=this.graph.getConnectionConstraint(t,l,!0),h=this.graph.getConnectionConstraint(t,o,!1),d=this.constraintHandler.currentConstraint;if(d==null&&n&&(i!=null?(s.isSource(this.marker.highlight.shape)&&(e=new Point(s.getGraphX(),s.getGraphY())),d=this.graph.getOutlineConstraint(e,i,s),this.constraintHandler.setFocus(s,i,this.isSource),this.constraintHandler.currentConstraint=d,this.constraintHandler.currentPoint=e):d=new ConnectionConstraint(null)),this.outlineConnect&&this.marker.highlight!=null&&this.marker.highlight.shape!=null){const c=this.graph.view.scale;if(this.constraintHandler.currentConstraint!=null&&this.constraintHandler.currentFocus!=null)this.marker.highlight.shape.stroke=n?OUTLINE_HIGHLIGHT_COLOR:"transparent",this.marker.highlight.shape.strokeWidth=OUTLINE_HIGHLIGHT_STROKEWIDTH/c/c,this.marker.highlight.repaint();else if(this.marker.hasValidState()){const u=s.getCell();this.marker.highlight.shape.stroke=u&&u.isConnectable()&&this.marker.getValidState()!==s.getState()?"transparent":DEFAULT_VALID_COLOR,this.marker.highlight.shape.strokeWidth=HIGHLIGHT_STROKEWIDTH/c/c,this.marker.highlight.repaint()}}this.isSource?a=d:this.isTarget&&(h=d),(this.isSource||this.isTarget)&&(d!=null&&d.point!=null?(t.style[this.isSource?"exitX":"entryX"]=d.point.x,t.style[this.isSource?"exitY":"entryY"]=d.point.y):(delete t.style[this.isSource?"exitX":"entryX"],delete t.style[this.isSource?"exitY":"entryY"])),t.setVisibleTerminalState(l,!0),t.setVisibleTerminalState(o,!1),(!this.isSource||l!=null)&&t.view.updateFixedTerminalPoint(t,l,!0,a),(!this.isTarget||o!=null)&&t.view.updateFixedTerminalPoint(t,o,!1,h),(this.isSource||this.isTarget)&&i==null&&(t.setAbsoluteTerminalPoint(e,this.isSource),this.marker.getMarkedState()==null&&(this.error=this.graph.isAllowDanglingEdges()?null:"")),t.view.updatePoints(t,this.points,l,o),t.view.updateFloatingTerminalPoints(t,l,o)}mouseMove(t,e){var i;if(this.index!=null&&this.marker!=null){if(this.currentPoint=this.getPointForEvent(e),this.error=null,!this.graph.isIgnoreTerminalEvent(e.getEvent())&&isShiftDown(e.getEvent())&&this.snapPoint!=null&&(Math.abs(this.snapPoint.x-this.currentPoint.x)<Math.abs(this.snapPoint.y-this.currentPoint.y)?this.currentPoint.x=this.snapPoint.x:this.currentPoint.y=this.snapPoint.y),this.index<=InternalEvent.CUSTOM_HANDLE&&this.index>InternalEvent.VIRTUAL_HANDLE)this.customHandles!=null&&(this.customHandles[InternalEvent.CUSTOM_HANDLE-this.index].processEvent(e),this.customHandles[InternalEvent.CUSTOM_HANDLE-this.index].positionChanged(),this.shape!=null&&this.shape.node!=null&&(this.shape.node.style.display="none"));else if(this.isLabel&&this.label)this.label.x=this.currentPoint.x,this.label.y=this.currentPoint.y;else{this.points=this.getPreviewPoints(this.currentPoint,e);let s=this.isSource||this.isTarget?this.getPreviewTerminalState(e):null;if(this.constraintHandler.currentConstraint!=null&&this.constraintHandler.currentFocus!=null&&this.constraintHandler.currentPoint!=null?this.currentPoint=this.constraintHandler.currentPoint.clone():this.outlineConnect&&((this.isSource||this.isTarget?this.isOutlineConnectEvent(e):!1)?s=this.marker.highlight.state:s!=null&&s!==e.getState()&&((i=e.getCell())!=null&&i.isConnectable())&&this.marker.highlight.shape!=null&&(this.marker.highlight.shape.stroke="transparent",this.marker.highlight.repaint(),s=null)),s!=null&&!this.isCellEnabled(s.cell)&&(s=null,this.marker.reset()),this.currentPoint){const n=this.clonePreviewState(this.currentPoint,s!=null?s.cell:null);this.updatePreviewState(n,this.currentPoint,s,e,this.outline);const l=this.error==null?this.marker.validColor:this.marker.invalidColor;this.setPreviewColor(l),this.abspoints=n.absolutePoints,this.active=!0,this.updateHint(e,this.currentPoint)}}this.drawPreview(),InternalEvent.consume(e.getEvent()),e.consume()}}mouseUp(t,e){if(this.index!=null&&this.marker!=null){this.shape!=null&&this.shape.node!=null&&(this.shape.node.style.display="");let i=this.state.cell;const{index:s}=this;if(this.index=null,e.getX()!==this.startX||e.getY()!==this.startY){const n=!this.graph.isIgnoreTerminalEvent(e.getEvent())&&this.graph.isCloneEvent(e.getEvent())&&this.cloneEnabled&&this.graph.isCellsCloneable();if(this.error!=null)this.error.length>0&&this.graph.validationAlert(this.error);else if(s<=InternalEvent.CUSTOM_HANDLE&&s>InternalEvent.VIRTUAL_HANDLE){if(this.customHandles!=null){const l=this.graph.getDataModel();l.beginUpdate();try{this.customHandles[InternalEvent.CUSTOM_HANDLE-s].execute(e),this.shape!=null&&this.shape.node!=null&&(this.shape.apply(this.state),this.shape.redraw())}finally{l.endUpdate()}}}else if(this.isLabel&&this.label)this.moveLabel(this.state,this.label.x,this.label.y);else if(this.isSource||this.isTarget){let l=null;if(this.constraintHandler.currentConstraint!=null&&this.constraintHandler.currentFocus!=null&&(l=this.constraintHandler.currentFocus.cell),!l&&this.marker.hasValidState()&&this.marker.highlight!=null&&this.marker.highlight.shape!=null&&this.marker.highlight.shape.stroke!=="transparent"&&this.marker.highlight.shape.stroke!=="white"&&(l=this.marker.validState.cell),l){const o=this.graph.getDataModel(),a=i.getParent();o.beginUpdate();try{if(n){let h=i.getGeometry();const d=this.graph.cloneCell(i);o.add(a,d,a.getChildCount()),h!=null&&(h=h.clone(),o.setGeometry(d,h));const c=i.getTerminal(!this.isSource);this.graph.connectCell(d,c,!this.isSource),i=d}i=this.connect(i,l,this.isSource,n,e)}finally{o.endUpdate()}}else if(this.graph.isAllowDanglingEdges()){const o=this.abspoints[this.isSource?0:this.abspoints.length-1];o.x=this.roundLength(o.x/this.graph.view.scale-this.graph.view.translate.x),o.y=this.roundLength(o.y/this.graph.view.scale-this.graph.view.translate.y);const a=i.getParent(),h=a?this.graph.getView().getState(a):null;h!=null&&(o.x-=h.origin.x,o.y-=h.origin.y),o.x-=this.graph.getPanDx()/this.graph.view.scale,o.y-=this.graph.getPanDy()/this.graph.view.scale,i=this.changeTerminalPoint(i,o,this.isSource,n)}}else this.active?i=this.changePoints(i,this.points,n):(this.graph.getView().invalidate(this.state.cell),this.graph.getView().validate(this.state.cell))}else this.graph.isToggleEvent(e.getEvent())&&this.graph.selectCellForEvent(this.state.cell,e.getEvent());this.marker!=null&&(this.reset(),i!==this.state.cell&&this.graph.setSelectionCell(i)),e.consume()}}reset(){if(this.active&&this.refresh(),this.error=null,this.index=null,this.points=[],this.snapPoint=null,this.isLabel=!1,this.isSource=!1,this.isTarget=!1,this.active=!1,this.marker&&this.marker.reset(),this.constraintHandler.reset(),this.customHandles)for(let t=0;t<this.customHandles.length;t+=1)this.customHandles[t].reset();this.setPreviewColor(EdgeHandlerConfig.selectionColor),this.removeHint(),this.redraw()}setPreviewColor(t){this.shape.stroke=t}convertPoint(t,e){const i=this.graph.getView().getScale(),s=this.graph.getView().getTranslate();e&&(t.x=this.graph.snap(t.x),t.y=this.graph.snap(t.y)),t.x=Math.round(t.x/i-s.x),t.y=Math.round(t.y/i-s.y);const n=this.state.cell.getParent(),l=n&&this.graph.getView().getState(n);return l&&(t.x-=l.origin.x,t.y-=l.origin.y),t}moveLabel(t,e,i){const s=this.graph.getDataModel();let n=t.cell.getGeometry();if(n!=null){const{scale:l}=this.graph.getView();if(n=n.clone(),n.relative){let o=this.graph.getView().getRelativePoint(t,e,i);n.x=Math.round(o.x*1e4)/1e4,n.y=Math.round(o.y),n.offset=new Point(0,0),o=this.graph.view.getPoint(t,n),n.offset=new Point(Math.round((e-o.x)/l),Math.round((i-o.y)/l))}else{const o=t.absolutePoints,a=o[0],h=o[o.length-1];if(a!=null&&h!=null){const d=a.x+(h.x-a.x)/2,c=a.y+(h.y-a.y)/2;n.offset=new Point(Math.round((e-d)/l),Math.round((i-c)/l)),n.x=0,n.y=0}}s.setGeometry(t.cell,n)}}connect(t,e,i,s,n){return t.getParent(),this.graph.batchUpdate(()=>{let l=this.constraintHandler.currentConstraint;l==null&&(l=new ConnectionConstraint(null)),this.graph.connectCell(t,e,i,l)}),t}changeTerminalPoint(t,e,i,s){const n=this.graph.getDataModel();return n.batchUpdate(()=>{if(s){const o=t.getParent(),a=t.getTerminal(!i);t=this.graph.cloneCell(t),n.add(o,t,o.getChildCount()),n.setTerminal(t,a,!i)}let l=t.getGeometry();l!=null&&(l=l.clone(),l.setTerminalPoint(e,i),n.setGeometry(t,l),this.graph.connectCell(t,null,i,new ConnectionConstraint(null)))}),t}changePoints(t,e,i){const s=this.graph.getDataModel();return s.batchUpdate(()=>{if(i){const l=t.getParent(),o=t.getTerminal(!0),a=t.getTerminal(!1);t=this.graph.cloneCell(t),s.add(l,t,l.getChildCount()),s.setTerminal(t,o,!0),s.setTerminal(t,a,!1)}let n=t.getGeometry();n!=null&&(n=n.clone(),n.points=e,s.setGeometry(t,n))}),t}addPoint(t,e){const i=convertPoint(this.graph.container,getClientX(e),getClientY(e)),s=this.graph.isGridEnabledEvent(e);this.convertPoint(i,s),this.addPointAt(t,i.x,i.y),InternalEvent.consume(e)}addPointAt(t,e,i){let s=t.cell.getGeometry();const n=new Point(e,i);if(s!=null){s=s.clone();const l=this.graph.view.translate,o=this.graph.view.scale;let a=new Point(l.x*o,l.y*o);const h=this.state.cell.getParent();if(h&&h.isVertex()){const c=this.graph.view.getState(h);c&&(a=new Point(c.x,c.y))}const d=findNearestSegment(t,n.x*o+a.x,n.y*o+a.y);s.points==null?s.points=[n]:s.points.splice(d,0,n),this.graph.getDataModel().setGeometry(t.cell,s),this.refresh(),this.redraw()}}removePoint(t,e){if(e>0&&e<this.abspoints.length-1){let i=this.state.cell.getGeometry();i!=null&&i.points!=null&&(i=i.clone(),(i.points||[]).splice(e-1,1),this.graph.getDataModel().setGeometry(t.cell,i),this.refresh(),this.redraw())}}getHandleFillColor(t){const e=t===0,{cell:i}=this.state,s=i.getTerminal(e);let n=HandleConfig.fillColor;return s!=null&&!this.graph.isCellDisconnectable(i,s,e)||s==null&&!this.graph.isTerminalPointMovable(i,e)?n=LOCKED_HANDLE_FILLCOLOR:s!=null&&this.graph.isCellDisconnectable(i,s,e)&&(n=EdgeHandlerConfig.connectFillColor),n}redraw(t){this.abspoints=this.state.absolutePoints.slice();const e=this.state.cell.getGeometry();if(e){const i=e.points;if(this.bends!=null&&this.bends.length>0&&i!=null){this.points==null&&(this.points=[]);for(let s=1;s<this.bends.length-1;s+=1)this.bends[s]!=null&&this.abspoints[s]!=null&&(this.points[s-1]=i[s-1])}}this.drawPreview(),t||this.redrawHandles()}redrawHandles(){const{cell:t}=this.state;let e=this.labelShape.bounds;this.label=new Point(this.state.absoluteOffset.x,this.state.absoluteOffset.y),this.labelShape.bounds=new Rectangle(Math.round(this.label.x-e.width/2),Math.round(this.label.y-e.height/2),e.width,e.height);const i=this.graph.getLabel(t);if(this.labelShape.visible=i!=null&&i.length>0&&this.graph.isLabelMovable(t),this.bends!=null&&this.bends.length>0){const s=this.abspoints.length-1,n=this.abspoints[0],l=n.x,o=n.y;e=this.bends[0].bounds,this.bends[0].bounds=new Rectangle(Math.floor(l-e.width/2),Math.floor(o-e.height/2),e.width,e.height),this.bends[0].fill=this.getHandleFillColor(0),this.bends[0].redraw(),this.manageLabelHandle&&this.checkLabelHandle(this.bends[0].bounds);const a=this.abspoints[s],h=a.x,d=a.y,c=this.bends.length-1;e=this.bends[c].bounds,this.bends[c].bounds=new Rectangle(Math.floor(h-e.width/2),Math.floor(d-e.height/2),e.width,e.height),this.bends[c].fill=this.getHandleFillColor(c),this.bends[c].redraw(),this.manageLabelHandle&&this.checkLabelHandle(this.bends[c].bounds),this.redrawInnerBends(n,a)}if(this.virtualBends&&this.virtualBends.length>0){let s=this.abspoints[0];for(let n=0;n<this.virtualBends.length;n+=1)if(this.virtualBends[n]!=null&&this.abspoints[n+1]!=null){const l=this.abspoints[n+1],o=this.virtualBends[n],a=s.x+(l.x-s.x)/2,h=s.y+(l.y-s.y)/2;o.bounds&&(o.bounds=new Rectangle(Math.floor(a-o.bounds.width/2),Math.floor(h-o.bounds.height/2),o.bounds.width,o.bounds.height),o.redraw()),setOpacity(o.node,EdgeHandlerConfig.virtualBendOpacity),s=l,this.manageLabelHandle&&this.checkLabelHandle(o.bounds)}}if(this.labelShape.redraw(),this.customHandles)for(let s=0;s<this.customHandles.length;s+=1){const n=this.customHandles[s].shape;if(n){const l=n.node.style.display;this.customHandles[s].redraw(),n.node.style.display=l,n.node.style.visibility=this.isCustomHandleVisible(this.customHandles[s])?"":"hidden"}}}isCustomHandleVisible(t){return!this.graph.isEditing()&&this.state.view.graph.getSelectionCount()===1}setHandlesVisible(t){for(let e=0;e<this.bends.length;e+=1)this.bends[e].node.style.display=t?"":"none";if(this.virtualBends)for(let e=0;e<this.virtualBends.length;e+=1)this.virtualBends[e].node.style.display=t?"":"none";if(this.labelShape.node.style.display=t?"":"none",this.customHandles)for(let e=0;e<this.customHandles.length;e+=1)this.customHandles[e].setVisible(t)}redrawInnerBends(t,e){for(let i=1;i<this.bends.length-1;i+=1)if(this.bends[i]!=null)if(this.abspoints[i]!=null){const{x:s}=this.abspoints[i],{y:n}=this.abspoints[i],l=this.bends[i].bounds;if(this.bends[i].node.style.visibility="visible",this.bends[i].bounds=new Rectangle(Math.round(s-l.width/2),Math.round(n-l.height/2),l.width,l.height),this.manageLabelHandle)this.checkLabelHandle(this.bends[i].bounds);else if(this.handleImage==null&&this.labelShape.visible&&intersects(this.bends[i].bounds,this.labelShape.bounds)){const o=HandleConfig.size+3,a=o;this.bends[i].bounds=new Rectangle(Math.round(s-o/2),Math.round(n-a/2),o,a)}this.bends[i].redraw()}else this.bends[i].destroy()}checkLabelHandle(t){const e=this.labelShape.bounds;intersects(t,e)&&(t.getCenterY()<e.getCenterY()?e.y=t.y+t.height:e.y=t.y-e.height)}drawPreview(){try{if(this.isLabel){const t=this.labelShape.bounds,e=new Rectangle(Math.round(this.label.x-t.width/2),Math.round(this.label.y-t.height/2),t.width,t.height);t.equals(e)||(this.labelShape.bounds=e,this.labelShape.redraw())}this.shape!=null&&!equalPoints(this.shape.points,this.abspoints)&&(this.shape.apply(this.state),this.shape.points=this.abspoints.slice(),this.shape.scale=this.state.view.scale,this.shape.isDashed=this.isSelectionDashed(),this.shape.stroke=this.getSelectionColor(),this.shape.strokeWidth=this.getSelectionStrokeWidth()/this.shape.scale/this.shape.scale,this.shape.isShadow=!1,this.shape.redraw()),this.updateParentHighlight()}catch{}}refresh(){this.state!=null&&(this.abspoints=this.getSelectionPoints(this.state),this.points=[],this.destroyBends(this.bends),this.bends=this.createBends(),this.virtualBends&&(this.destroyBends(this.virtualBends),this.virtualBends=this.createVirtualBends()),this.customHandles&&(this.destroyBends(this.customHandles),this.customHandles=this.createCustomHandles()),this.labelShape!=null&&this.labelShape.node!=null&&this.labelShape.node.parentNode!=null&&this.labelShape.node.parentNode.appendChild(this.labelShape.node))}isDestroyed(){return this.shape==null}destroyBends(t){if(t!=null)for(let e=0;e<t.length;e+=1)t[e]!=null&&t[e].destroy()}onDestroy(){if(this.state.view.graph.removeListener(this.escapeHandler),this.marker.destroy(),this.marker=null,this.shape.destroy(),this.shape=null,this.parentHighlight){const t=this.state.cell.getParent(),e=t?this.graph.view.getState(t):null;e&&e.parentHighlight===this.parentHighlight&&(e.parentHighlight=null),this.parentHighlight.destroy(),this.parentHighlight=null}this.labelShape.destroy(),this.labelShape=null,this.constraintHandler.onDestroy(),this.constraintHandler=null,this.virtualBends&&(this.destroyBends(this.virtualBends),this.virtualBends=[]),this.customHandles&&(this.destroyBends(this.customHandles),this.customHandles=[]),this.destroyBends(this.bends),this.bends=[],this.removeHint()}}class EdgeHandlerCellMarker extends CellMarker{constructor(t,e,i=DEFAULT_VALID_COLOR,s=DEFAULT_INVALID_COLOR,n=DEFAULT_HOTSPOT){super(t,i,s,n),this.getCell=l=>{let o=super.getCell(l);if((o===this.edgeHandler.state.cell||!o)&&this.edgeHandler.currentPoint&&(o=this.edgeHandler.graph.getCellAt(this.edgeHandler.currentPoint.x,this.edgeHandler.currentPoint.y)),o&&!o.isConnectable()){const a=o.getParent();a&&a.isVertex()&&a.isConnectable()&&(o=a)}return o&&(this.graph.isSwimlane(o)&&this.edgeHandler.currentPoint&&this.graph.hitsSwimlaneContent(o,this.edgeHandler.currentPoint.x,this.edgeHandler.currentPoint.y)||!this.edgeHandler.isConnectableCell(o)||o===this.edgeHandler.state.cell||o&&!this.edgeHandler.graph.connectableEdges&&o.isEdge()||this.edgeHandler.state.cell.isAncestor(o))&&(o=null),o&&!o.isConnectable()&&(o=null),o},this.isValidState=l=>{const o=this.edgeHandler.state.cell.getTerminal(!this.edgeHandler.isSource),a=this.edgeHandler.graph.view.getState(o),h=this.edgeHandler.graph.view.getTerminalPort(l,a,!this.edgeHandler.isSource),d=h?h.cell:null,c=this.edgeHandler.isSource?l.cell:d,u=this.edgeHandler.isSource?d:l.cell;return this.edgeHandler.error=this.edgeHandler.validateConnection(c,u),!this.edgeHandler.error},this.edgeHandler=e}}class VertexHandler{isRotationEnabled(){return VertexHandlerConfig.rotationEnabled}constructor(t){this.sizers=[],this.singleSizer=!1,this.index=null,this.allowHandleBoundsCheck=!0,this.handleImage=null,this.handlesVisible=!0,this.tolerance=0,this.parentHighlightEnabled=!1,this.rotationRaster=!0,this.rotationCursor="crosshair",this.livePreview=!1,this.movePreviewToFront=!1,this.manageSizers=!1,this.constrainGroupByChildren=!1,this.rotationHandleVSpacing=-16,this.horizontalOffset=0,this.verticalOffset=0,this.minBounds=null,this.x0=0,this.y0=0,this.customHandles=[],this.inTolerance=!1,this.startX=0,this.startY=0,this.rotationShape=null,this.currentAlpha=null,this.startAngle=0,this.startDist=0,this.ghostPreview=null,this.livePreviewActive=!1,this.childOffsetX=0,this.childOffsetY=0,this.parentState=null,this.parentHighlight=null,this.unscaledBounds=null,this.preview=null,this.labelShape=null,this.edgeHandlers=[],this.EMPTY_POINT=new Point,this.state=t,this.graph=this.state.view.graph,this.selectionBounds=this.getSelectionBounds(this.state),this.bounds=new Rectangle(this.selectionBounds.x,this.selectionBounds.y,this.selectionBounds.width,this.selectionBounds.height),this.selectionBorder=this.createSelectionShape(this.bounds),this.selectionBorder.dialect="svg",this.selectionBorder.pointerEvents=!1,this.selectionBorder.rotation=this.state.style.rotation??0,this.selectionBorder.init(this.graph.getView().getOverlayPane()),InternalEvent.redirectMouseEvents(this.selectionBorder.node,this.graph,this.state),this.graph.isCellMovable(this.state.cell)&&this.selectionBorder.setCursor(VertexHandlerConfig.cursorMovable);const e=this.getSelectionHandler();if(e&&(e.maxCells<=0||this.graph.getSelectionCount()<e.maxCells)){const i=this.graph.isCellResizable(this.state.cell);if(this.sizers=[],i||this.graph.isLabelMovable(this.state.cell)&&this.state.width>=2&&this.state.height>=2){let s=0;i&&(this.singleSizer||(this.sizers.push(this.createSizer("nw-resize",s++)),this.sizers.push(this.createSizer("n-resize",s++)),this.sizers.push(this.createSizer("ne-resize",s++)),this.sizers.push(this.createSizer("w-resize",s++)),this.sizers.push(this.createSizer("e-resize",s++)),this.sizers.push(this.createSizer("sw-resize",s++)),this.sizers.push(this.createSizer("s-resize",s++))),this.sizers.push(this.createSizer("se-resize",s++)));const n=this.state.cell.getGeometry();n!=null&&!n.relative&&!this.graph.isSwimlane(this.state.cell)&&this.graph.isLabelMovable(this.state.cell)&&(this.labelShape=this.createSizer(HandleConfig.labelCursor,InternalEvent.LABEL_HANDLE,HandleConfig.labelSize,HandleConfig.labelFillColor),this.sizers.push(this.labelShape))}else this.graph.isCellMovable(this.state.cell)&&!this.graph.isCellResizable(this.state.cell)&&this.state.width<2&&this.state.height<2&&(this.labelShape=this.createSizer(VertexHandlerConfig.cursorMovable,InternalEvent.LABEL_HANDLE,void 0,HandleConfig.labelFillColor),this.sizers.push(this.labelShape))}this.isRotationHandleVisible()&&(this.rotationShape=this.createSizer(this.rotationCursor,InternalEvent.ROTATION_HANDLE,HandleConfig.size+3,HandleConfig.fillColor),this.sizers.push(this.rotationShape)),this.customHandles=this.createCustomHandles(),this.redraw(),this.constrainGroupByChildren&&this.updateMinBounds(),this.escapeHandler=(i,s)=>{this.livePreview&&this.index!=null&&(this.state.view.graph.cellRenderer.redraw(this.state,!0),this.state.view.invalidate(this.state.cell),this.state.invalid=!1,this.state.view.validate()),this.reset()},this.state.view.graph.addListener(InternalEvent.ESCAPE,this.escapeHandler)}getSelectionHandler(){return this.graph.getPlugin("SelectionHandler")}isRotationHandleVisible(){const t=this.getSelectionHandler(),e=t?t.maxCells<=0||this.graph.getSelectionCount()<t.maxCells:!0;return this.graph.isEnabled()&&this.isRotationEnabled()&&this.graph.isCellRotatable(this.state.cell)&&e}isConstrainedEvent(t){return isShiftDown(t.getEvent())||this.state.style.aspect==="fixed"}isCenteredEvent(t,e){return!1}createCustomHandles(){return[]}updateMinBounds(){const t=this.graph.getChildCells(this.state.cell);if(t.length>0&&(this.minBounds=this.graph.view.getBounds(t),this.minBounds)){const e=this.state.view.scale,i=this.state.view.translate;this.minBounds.x-=this.state.x,this.minBounds.y-=this.state.y,this.minBounds.x/=e,this.minBounds.y/=e,this.minBounds.width/=e,this.minBounds.height/=e,this.x0=this.state.x/e-i.x,this.y0=this.state.y/e-i.y}}getSelectionBounds(t){return new Rectangle(Math.round(t.x),Math.round(t.y),Math.round(t.width),Math.round(t.height))}createParentHighlightShape(t){return this.createSelectionShape(t)}createSelectionShape(t){const e=new RectangleShape(Rectangle.fromRectangle(t),NONE,this.getSelectionColor());return e.strokeWidth=this.getSelectionStrokeWidth(),e.isDashed=this.isSelectionDashed(),e}getSelectionColor(){return VertexHandlerConfig.selectionColor}getSelectionStrokeWidth(){return VertexHandlerConfig.selectionStrokeWidth}isSelectionDashed(){return VertexHandlerConfig.selectionDashed}createSizer(t,e,i=HandleConfig.size,s=HandleConfig.fillColor){const n=new Rectangle(0,0,i,i),l=this.createSizerShape(n,e,s);return l.bounds&&l.isHtmlAllowed()&&this.state.text&&this.state.text.node.parentNode===this.graph.container?(l.bounds.height-=1,l.bounds.width-=1,l.dialect="strictHtml",l.init(this.graph.container)):(l.dialect=this.graph.dialect!=="svg"?"mixedHtml":"svg",l.init(this.graph.getView().getOverlayPane())),InternalEvent.redirectMouseEvents(l.node,this.graph,this.state),this.graph.isEnabled()&&l.setCursor(t),this.isSizerVisible(e)||(l.visible=!1),l}isSizerVisible(t){return!0}createSizerShape(t,e,i=HandleConfig.fillColor){if(this.handleImage){t=new Rectangle(t.x,t.y,this.handleImage.width,this.handleImage.height);const n=new ImageShape(t,this.handleImage.src);return n.preserveImageAspect=!1,n}const s=HandleConfig.strokeColor;return e===InternalEvent.ROTATION_HANDLE?new EllipseShape(t,i,s):new RectangleShape(t,i,s)}moveSizerTo(t,e,i){t&&t.bounds&&(t.bounds.x=Math.floor(e-t.bounds.width/2),t.bounds.y=Math.floor(i-t.bounds.height/2),t.node&&t.node.style.display!=="none"&&t.redraw())}getHandleForEvent(t){const e=isMouseEvent(t.getEvent())?1:this.tolerance,i=this.allowHandleBoundsCheck&&e>0?new Rectangle(t.getGraphX()-e,t.getGraphY()-e,2*e,2*e):null,s=n=>{const l=n&&n.constructor!==ImageShape&&this.allowHandleBoundsCheck?n.strokeWidth+n.svgStrokeTolerance:null,o=l?new Rectangle(t.getGraphX()-Math.floor(l/2),t.getGraphY()-Math.floor(l/2),l,l):i;return n&&n.bounds&&(t.isSource(n)||o&&intersects(n.bounds,o)&&n.node.style.display!=="none"&&n.node.style.visibility!=="hidden")};if(s(this.rotationShape))return InternalEvent.ROTATION_HANDLE;if(s(this.labelShape))return InternalEvent.LABEL_HANDLE;for(let n=0;n<this.sizers.length;n+=1)if(s(this.sizers[n]))return n;if(this.customHandles!=null&&this.isCustomHandleEvent(t)){for(let n=this.customHandles.length-1;n>=0;n--)if(s(this.customHandles[n].shape))return InternalEvent.CUSTOM_HANDLE-n}return null}isCustomHandleEvent(t){return!0}mouseDown(t,e){if(!e.isConsumed()&&this.graph.isEnabled()){const i=this.getHandleForEvent(e);isNullish(i)||(this.start(e.getGraphX(),e.getGraphY(),i),e.consume())}}isLivePreviewBorder(){return this.state.shape&&this.state.shape.fill===NONE&&this.state.shape.stroke===NONE}start(t,e,i){if(this.livePreviewActive=this.livePreview&&this.state.cell.getChildCount()===0,this.inTolerance=!0,this.childOffsetX=0,this.childOffsetY=0,this.index=i,this.startX=t,this.startY=e,this.index<=InternalEvent.CUSTOM_HANDLE&&this.isGhostPreview())this.ghostPreview=this.createGhostPreview();else{const s=this.state.cell.getParent();if(this.state.view.currentRoot!==s&&s&&(s.isVertex()||s.isEdge())&&(this.parentState=this.state.view.graph.view.getState(s)),this.selectionBorder.node.style.display=i===InternalEvent.ROTATION_HANDLE?"inline":"none",(!this.livePreviewActive||this.isLivePreviewBorder())&&(this.preview=this.createSelectionShape(this.bounds),!(Client.IS_SVG&&(this.state.style.rotation??0)!=0)&&this.state.text!=null&&this.state.text.node.parentNode===this.graph.container?(this.preview.dialect="strictHtml",this.preview.init(this.graph.container)):(this.preview.dialect="svg",this.preview.init(this.graph.view.getOverlayPane()))),i===InternalEvent.ROTATION_HANDLE){const n=this.getRotationHandlePosition(),l=n.x-this.state.getCenterX(),o=n.y-this.state.getCenterY();this.startAngle=l!==0?Math.atan(o/l)*180/Math.PI+90:0,this.startDist=Math.sqrt(l*l+o*o)}if(this.livePreviewActive){this.hideSizers(),i===InternalEvent.ROTATION_HANDLE&&this.rotationShape?this.rotationShape.node.style.display="":i===InternalEvent.LABEL_HANDLE&&this.labelShape?this.labelShape.node.style.display="":this.sizers[i]?this.sizers[i].node.style.display="":i<=InternalEvent.CUSTOM_HANDLE&&this.customHandles[InternalEvent.CUSTOM_HANDLE-i].setVisible(!0);const n=this.state.cell.getEdges();this.edgeHandlers=[];const l=this.graph.getPlugin("SelectionCellsHandler");for(let o=0;o<n.length;o+=1){const a=l==null?void 0:l.getHandler(n[o]);a&&this.edgeHandlers.push(a)}}}}createGhostPreview(){const t=this.graph.cellRenderer.createShape(this.state);return t.init(this.graph.view.getOverlayPane()),t.scale=this.state.view.scale,t.bounds=this.bounds,t.outline=!0,t}setHandlesVisible(t){this.handlesVisible=t;for(let e=0;e<this.sizers.length;e+=1)this.sizers[e].node.style.display=t?"":"none";for(let e=0;e<this.customHandles.length;e+=1)this.customHandles[e].setVisible(t)}hideSizers(){this.setHandlesVisible(!1)}checkTolerance(t){this.inTolerance&&this.startX!==null&&this.startY!==null&&(isMouseEvent(t.getEvent())||Math.abs(t.getGraphX()-this.startX)>this.graph.getEventTolerance()||Math.abs(t.getGraphY()-this.startY)>this.graph.getEventTolerance())&&(this.inTolerance=!1)}updateHint(t){}removeHint(){}roundAngle(t){return Math.round(t*10)/10}roundLength(t){return Math.round(t*100)/100}mouseMove(t,e){!e.isConsumed()&&this.index!=null?(this.checkTolerance(e),this.inTolerance||(this.index<=InternalEvent.CUSTOM_HANDLE?this.customHandles!=null&&(this.customHandles[InternalEvent.CUSTOM_HANDLE-this.index].processEvent(e),this.customHandles[InternalEvent.CUSTOM_HANDLE-this.index].active=!0,this.ghostPreview!=null?(this.ghostPreview.apply(this.state),this.ghostPreview.strokeWidth=this.getSelectionStrokeWidth()/this.ghostPreview.scale/this.ghostPreview.scale,this.ghostPreview.isDashed=this.isSelectionDashed(),this.ghostPreview.stroke=this.getSelectionColor(),this.ghostPreview.redraw(),this.selectionBounds!=null&&(this.selectionBorder.node.style.display="none")):(this.movePreviewToFront&&this.moveToFront(),this.customHandles[InternalEvent.CUSTOM_HANDLE-this.index].positionChanged())):this.index===InternalEvent.LABEL_HANDLE?this.moveLabel(e):(this.index===InternalEvent.ROTATION_HANDLE?this.rotateVertex(e):this.resizeVertex(e),this.updateHint(e))),e.consume()):!this.graph.isMouseDown&&!isNullish(this.getHandleForEvent(e))&&e.consume(!1)}isGhostPreview(){return this.state.cell.getChildCount()>0}moveLabel(t){const e=new Point(t.getGraphX(),t.getGraphY()),i=this.graph.view.translate,{scale:s}=this.graph.view;this.graph.isGridEnabledEvent(t.getEvent())&&(e.x=(this.graph.snap(e.x/s-i.x)+i.x)*s,e.y=(this.graph.snap(e.y/s-i.y)+i.y)*s);const n=this.rotationShape?this.sizers.length-2:this.sizers.length-1;this.moveSizerTo(this.sizers[n],e.x,e.y)}rotateVertex(t){const e=new Point(t.getGraphX(),t.getGraphY());let i=this.state.x+this.state.width/2-e.x,s=this.state.y+this.state.height/2-e.y;if(this.currentAlpha=i!==0?Math.atan(s/i)*180/Math.PI+90:s<0?180:0,i>0&&(this.currentAlpha-=180),this.currentAlpha-=this.startAngle,this.rotationRaster&&this.graph.isGridEnabledEvent(t.getEvent())){let n;i=e.x-this.state.getCenterX(),s=e.y-this.state.getCenterY();const l=Math.sqrt(i*i+s*s);l-this.startDist<2?n=15:l-this.startDist<25?n=5:n=1,this.currentAlpha=Math.round(this.currentAlpha/n)*n}else this.currentAlpha=this.roundAngle(this.currentAlpha);this.selectionBorder.rotation=this.currentAlpha,this.selectionBorder.redraw(),this.livePreviewActive&&this.redrawHandles()}resizeVertex(t){const e=new Point(this.state.getCenterX(),this.state.getCenterY()),i=toRadians(this.state.style.rotation??0),s=new Point(t.getGraphX(),t.getGraphY()),n=this.graph.view.translate,{scale:l}=this.graph.view;let o=Math.cos(-i),a=Math.sin(-i),h=s.x-this.startX,d=s.y-this.startY;const c=o*h-a*d,u=a*h+o*d;h=c,d=u;const g=this.state.cell.getGeometry();if(g&&this.index!==null&&(this.unscaledBounds=this.union(g,h/l,d/l,this.index,this.graph.isGridEnabledEvent(t.getEvent()),1,new Point(0,0),this.isConstrainedEvent(t),this.isCenteredEvent(this.state,t))),g&&!g.relative){let f=this.graph.getMaximumGraphBounds();if(f!=null&&this.parentState!=null&&(f=Rectangle.fromRectangle(f),f.x-=(this.parentState.x-n.x*l)/l,f.y-=(this.parentState.y-n.y*l)/l),this.graph.isConstrainChild(this.state.cell)){let p=this.graph.getCellContainmentArea(this.state.cell);if(p!=null){const y=this.graph.getOverlap(this.state.cell);y>0&&(p=Rectangle.fromRectangle(p),p.x-=p.width*y,p.y-=p.height*y,p.width+=2*p.width*y,p.height+=2*p.height*y),f?(f=Rectangle.fromRectangle(f),f.intersect(p)):f=p}}f&&this.unscaledBounds&&(this.unscaledBounds.x<f.x&&(this.unscaledBounds.width-=f.x-this.unscaledBounds.x,this.unscaledBounds.x=f.x),this.unscaledBounds.y<f.y&&(this.unscaledBounds.height-=f.y-this.unscaledBounds.y,this.unscaledBounds.y=f.y),this.unscaledBounds.x+this.unscaledBounds.width>f.x+f.width&&(this.unscaledBounds.width-=this.unscaledBounds.x+this.unscaledBounds.width-f.x-f.width),this.unscaledBounds.y+this.unscaledBounds.height>f.y+f.height&&(this.unscaledBounds.height-=this.unscaledBounds.y+this.unscaledBounds.height-f.y-f.height))}if(this.unscaledBounds){const f=this.bounds;this.bounds=new Rectangle((this.parentState?this.parentState.x:n.x*l)+this.unscaledBounds.x*l,(this.parentState?this.parentState.y:n.y*l)+this.unscaledBounds.y*l,this.unscaledBounds.width*l,this.unscaledBounds.height*l),g&&g.relative&&this.parentState&&(this.bounds.x+=this.state.x-this.parentState.x,this.bounds.y+=this.state.y-this.parentState.y),o=Math.cos(i),a=Math.sin(i);const p=new Point(this.bounds.getCenterX(),this.bounds.getCenterY());h=p.x-e.x,d=p.y-e.y;const y=o*h-a*d,v=a*h+o*d,S=y-h,w=v-d,C=this.bounds.x-this.state.x,m=this.bounds.y-this.state.y,M=o*C-a*m,b=a*C+o*m;this.bounds.x+=S,this.bounds.y+=w,this.unscaledBounds.x=this.roundLength(this.unscaledBounds.x+S/l),this.unscaledBounds.y=this.roundLength(this.unscaledBounds.y+w/l),this.unscaledBounds.width=this.roundLength(this.unscaledBounds.width),this.unscaledBounds.height=this.roundLength(this.unscaledBounds.height),!this.state.cell.isCollapsed()&&(S!==0||w!==0)?(this.childOffsetX=this.state.x-this.bounds.x+M,this.childOffsetY=this.state.y-this.bounds.y+b):(this.childOffsetX=0,this.childOffsetY=0),f.equals(this.bounds)||(this.livePreviewActive&&this.updateLivePreview(t),this.preview!=null?this.drawPreview():this.updateParentHighlight())}}updateLivePreview(t){const{scale:e}=this.graph.view,i=this.graph.view.translate,s=this.state.clone();this.state.x=this.bounds.x,this.state.y=this.bounds.y,this.state.origin=new Point(this.state.x/e-i.x,this.state.y/e-i.y),this.state.width=this.bounds.width,this.state.height=this.bounds.height;let n=this.state.absoluteOffset;n=new Point(n.x,n.y),this.state.absoluteOffset.x=0,this.state.absoluteOffset.y=0;const l=this.state.cell.getGeometry();if(l!=null){const o=l.offset||this.EMPTY_POINT;o!=null&&!l.relative&&(this.state.absoluteOffset.x=this.state.view.scale*o.x,this.state.absoluteOffset.y=this.state.view.scale*o.y),this.state.view.updateVertexLabelOffset(this.state)}this.state.view.graph.cellRenderer.redraw(this.state,!0),this.state.view.invalidate(this.state.cell),this.state.invalid=!1,this.state.view.validate(),this.redrawHandles(),this.movePreviewToFront&&this.moveToFront(),this.state.control!=null&&this.state.control.node!=null&&(this.state.control.node.style.visibility="hidden"),this.state.setState(s)}moveToFront(){(this.state.text&&this.state.text.node&&this.state.text.node.nextSibling||this.state.shape&&this.state.shape.node&&this.state.shape.node.nextSibling&&(!this.state.text||this.state.shape.node.nextSibling!==this.state.text.node))&&(this.state.shape&&this.state.shape.node&&this.state.shape.node.parentNode&&this.state.shape.node.parentNode.appendChild(this.state.shape.node),this.state.text&&this.state.text.node&&this.state.text.node.parentNode&&this.state.text.node.parentNode.appendChild(this.state.text.node))}mouseUp(t,e){if(this.index!=null&&this.state!=null){const i=new Point(e.getGraphX(),e.getGraphY()),{index:s}=this;this.index=null,this.ghostPreview==null&&(this.state.view.invalidate(this.state.cell,!1,!1),this.state.view.validate()),this.graph.batchUpdate(()=>{if(s<=InternalEvent.CUSTOM_HANDLE){if(this.customHandles!=null){const n=this.state.view.graph.getCellStyle(this.state.cell);this.customHandles[InternalEvent.CUSTOM_HANDLE-s].active=!1,this.customHandles[InternalEvent.CUSTOM_HANDLE-s].execute(e),this.customHandles!=null&&this.customHandles[InternalEvent.CUSTOM_HANDLE-s]!=null&&(this.state.style=n,this.customHandles[InternalEvent.CUSTOM_HANDLE-s].positionChanged())}}else if(s===InternalEvent.ROTATION_HANDLE)if(this.currentAlpha!=null){const n=this.currentAlpha-(this.state.style.rotation??0);n!==0&&this.rotateCell(this.state.cell,n)}else this.rotateClick();else{const n=this.graph.isGridEnabledEvent(e.getEvent()),l=toRadians(this.state.style.rotation??0),o=Math.cos(-l),a=Math.sin(-l);let h=i.x-this.startX,d=i.y-this.startY;const c=o*h-a*d,u=a*h+o*d;h=c,d=u;const g=this.graph.view.scale,f=this.isRecursiveResize(this.state,e);this.resizeCell(this.state.cell,this.roundLength(h/g),this.roundLength(d/g),s,n,this.isConstrainedEvent(e),f)}}),e.consume(),this.reset(),this.redrawHandles()}}isRecursiveResize(t,e){return this.graph.isRecursiveResize(this.state)}rotateClick(){}rotateCell(t,e,i){if(e!==0){const s=this.graph.getDataModel();if(t.isVertex()||t.isEdge()){if(!t.isEdge()){const o=(this.graph.getCurrentCellStyle(t).rotation??0)+e;this.graph.setCellStyles("rotation",o,[t])}let n=t.getGeometry();if(n&&i){const l=i.getGeometry();if(l!=null&&!i.isEdge()&&(n=n.clone(),n.rotate(e,new Point(l.width/2,l.height/2)),s.setGeometry(t,n)),t.isVertex()&&!n.relative||t.isEdge()){const o=t.getChildCount();for(let a=0;a<o;a+=1)this.rotateCell(t.getChildAt(a),e,t)}}}}}reset(){if(this.index!==null&&this.sizers[this.index].node.style.display==="none"&&(this.sizers[this.index].node.style.display=""),this.index=null,this.currentAlpha=null,this.preview&&(this.preview.destroy(),this.preview=null),this.ghostPreview&&(this.ghostPreview.destroy(),this.ghostPreview=null),this.livePreviewActive){for(let t=0;t<this.sizers.length;t+=1)this.sizers[t].node.style.display="";this.state.control&&this.state.control.node&&(this.state.control.node.style.visibility="")}for(let t=0;t<this.customHandles.length;t+=1)this.customHandles[t].active?(this.customHandles[t].active=!1,this.customHandles[t].reset()):this.customHandles[t].setVisible(!0);this.selectionBorder.node.style.display="inline",this.selectionBounds=this.getSelectionBounds(this.state),this.bounds=new Rectangle(this.selectionBounds.x,this.selectionBounds.y,this.selectionBounds.width,this.selectionBounds.height),this.drawPreview(),this.removeHint(),this.redrawHandles(),this.edgeHandlers=[],this.handlesVisible=!0,this.unscaledBounds=null}resizeCell(t,e,i,s,n,l,o){let a=t.getGeometry();if(a){if(s===InternalEvent.LABEL_HANDLE&&this.labelShape&&this.labelShape.bounds){const h=-toRadians(this.state.style.rotation??0),d=Math.cos(h),c=Math.sin(h),{scale:u}=this.graph.view,g=getRotatedPoint(new Point(Math.round((this.labelShape.bounds.getCenterX()-this.startX)/u),Math.round((this.labelShape.bounds.getCenterY()-this.startY)/u)),d,c);a=a.clone(),a.offset==null?a.offset=g:(a.offset.x+=g.x,a.offset.y+=g.y),this.graph.model.setGeometry(t,a)}else if(this.unscaledBounds){const{scale:h}=this.graph.view;(this.childOffsetX!==0||this.childOffsetY!==0)&&this.moveChildren(t,Math.round(this.childOffsetX/h),Math.round(this.childOffsetY/h)),this.graph.resizeCell(t,this.unscaledBounds,o)}}}moveChildren(t,e,i){const s=this.graph.getDataModel(),n=t.getChildCount();for(let l=0;l<n;l+=1){const o=t.getChildAt(l);let a=o.getGeometry();a!=null&&(a=a.clone(),a.translate(e,i),s.setGeometry(o,a))}}union(t,e,i,s,n,l,o,a,h){if(n=n&&this.graph.isGridEnabled(),this.singleSizer){let m=t.x+t.width+e,M=t.y+t.height+i;n&&(m=this.graph.snap(m/l)*l,M=this.graph.snap(M/l)*l);const b=new Rectangle(t.x,t.y,0,0);return b.add(new Rectangle(m,M,0,0)),b}const d=t.width,c=t.height;let u=t.x-o.x*l,g=u+d,f=t.y-o.y*l,p=f+c;const y=u+d/2,v=f+c/2;s>4?(p+=i,n?p=this.graph.snap(p/l)*l:p=Math.round(p/l)*l):s<3&&(f+=i,n?f=this.graph.snap(f/l)*l:f=Math.round(f/l)*l),s===0||s===3||s===5?(u+=e,n?u=this.graph.snap(u/l)*l:u=Math.round(u/l)*l):(s===2||s===4||s===7)&&(g+=e,n?g=this.graph.snap(g/l)*l:g=Math.round(g/l)*l);let S=g-u,w=p-f;if(a){const m=this.state.cell.getGeometry();if(m!=null){const M=m.width/m.height;s===1||s===2||s===7||s===6?S=w*M:w=S/M,s===0&&(u=g-S,f=p-w)}}if(h){S+=S-d,w+=w-c;const m=y-(u+S/2),M=v-(f+w/2);u+=m,f+=M,g+=m,p+=M}S<0&&(u+=S,S=Math.abs(S)),w<0&&(f+=w,w=Math.abs(w));const C=new Rectangle(u+o.x*l,f+o.y*l,S,w);return this.minBounds!=null&&(C.width=Math.max(C.width,this.minBounds.x*l+this.minBounds.width*l+Math.max(0,this.x0*l-C.x)),C.height=Math.max(C.height,this.minBounds.y*l+this.minBounds.height*l+Math.max(0,this.y0*l-C.y))),C}redraw(t){this.selectionBounds=this.getSelectionBounds(this.state),this.bounds=new Rectangle(this.selectionBounds.x,this.selectionBounds.y,this.selectionBounds.width,this.selectionBounds.height),this.drawPreview(),t||this.redrawHandles()}getHandlePadding(){const t=new Point(0,0);let e=this.tolerance;return this.sizers.length>0&&this.sizers[0].bounds&&(this.bounds.width<2*this.sizers[0].bounds.width+2*e||this.bounds.height<2*this.sizers[0].bounds.height+2*e)&&(e/=2,t.x=this.sizers[0].bounds.width+e,t.y=this.sizers[0].bounds.height+e),t}getSizerBounds(){return this.bounds}redrawHandles(){let t=this.getSizerBounds();const e=this.tolerance;this.horizontalOffset=0,this.verticalOffset=0;for(let i=0;i<this.customHandles.length;i+=1){const s=this.customHandles[i].shape;if(s){const n=s.node.style.display;this.customHandles[i].redraw(),s.node.style.display=n,s.node.style.visibility=this.handlesVisible&&this.isCustomHandleVisible(this.customHandles[i])?"":"hidden"}}if(this.sizers.length>0&&this.sizers[0]){if(this.index===null&&this.manageSizers&&this.sizers.length>=8){const n=this.getHandlePadding();this.horizontalOffset=n.x,this.verticalOffset=n.y,(this.horizontalOffset!==0||this.verticalOffset!==0)&&(t=new Rectangle(t.x,t.y,t.width,t.height),t.x-=this.horizontalOffset/2,t.width+=this.horizontalOffset,t.y-=this.verticalOffset/2,t.height+=this.verticalOffset),this.sizers.length>=8&&(this.sizers[0].bounds&&(t.width<2*this.sizers[0].bounds.width+2*e||t.height<2*this.sizers[0].bounds.height+2*e)?(this.sizers[0].node.style.display="none",this.sizers[2].node.style.display="none",this.sizers[5].node.style.display="none",this.sizers[7].node.style.display="none"):this.handlesVisible&&(this.sizers[0].node.style.display="",this.sizers[2].node.style.display="",this.sizers[5].node.style.display="",this.sizers[7].node.style.display=""))}const i=t.x+t.width,s=t.y+t.height;if(this.singleSizer)this.moveSizerTo(this.sizers[0],i,s);else{const n=t.x+t.width/2,l=t.y+t.height/2;if(this.sizers.length>=8){const o=["nw-resize","n-resize","ne-resize","e-resize","se-resize","s-resize","sw-resize","w-resize"],a=toRadians(this.state.style.rotation??0),h=Math.cos(a),d=Math.sin(a),c=Math.round(a*4/Math.PI),u=new Point(t.getCenterX(),t.getCenterY());let g=getRotatedPoint(new Point(t.x,t.y),h,d,u);this.moveSizerTo(this.sizers[0],g.x,g.y),this.sizers[0].setCursor(o[mod(0+c,o.length)]),g.x=n,g.y=t.y,g=getRotatedPoint(g,h,d,u),this.moveSizerTo(this.sizers[1],g.x,g.y),this.sizers[1].setCursor(o[mod(1+c,o.length)]),g.x=i,g.y=t.y,g=getRotatedPoint(g,h,d,u),this.moveSizerTo(this.sizers[2],g.x,g.y),this.sizers[2].setCursor(o[mod(2+c,o.length)]),g.x=t.x,g.y=l,g=getRotatedPoint(g,h,d,u),this.moveSizerTo(this.sizers[3],g.x,g.y),this.sizers[3].setCursor(o[mod(7+c,o.length)]),g.x=i,g.y=l,g=getRotatedPoint(g,h,d,u),this.moveSizerTo(this.sizers[4],g.x,g.y),this.sizers[4].setCursor(o[mod(3+c,o.length)]),g.x=t.x,g.y=s,g=getRotatedPoint(g,h,d,u),this.moveSizerTo(this.sizers[5],g.x,g.y),this.sizers[5].setCursor(o[mod(6+c,o.length)]),g.x=n,g.y=s,g=getRotatedPoint(g,h,d,u),this.moveSizerTo(this.sizers[6],g.x,g.y),this.sizers[6].setCursor(o[mod(5+c,o.length)]),g.x=i,g.y=s,g=getRotatedPoint(g,h,d,u),this.moveSizerTo(this.sizers[7],g.x,g.y),this.sizers[7].setCursor(o[mod(4+c,o.length)]),g.x=n+this.state.absoluteOffset.x,g.y=l+this.state.absoluteOffset.y,g=getRotatedPoint(g,h,d,u),this.moveSizerTo(this.sizers[8],g.x,g.y)}else this.state.width>=2&&this.state.height>=2?this.moveSizerTo(this.sizers[0],n+this.state.absoluteOffset.x,l+this.state.absoluteOffset.y):this.moveSizerTo(this.sizers[0],this.state.x,this.state.y)}}if(this.rotationShape){const i=toRadians(this.currentAlpha??this.state.style.rotation??0),s=Math.cos(i),n=Math.sin(i),l=new Point(this.state.getCenterX(),this.state.getCenterY()),o=getRotatedPoint(this.getRotationHandlePosition(),s,n,l);this.rotationShape.node!=null&&(this.moveSizerTo(this.rotationShape,o.x,o.y),this.rotationShape.node.style.visibility=this.state.view.graph.isEditing()||!this.handlesVisible?"hidden":"")}if(this.selectionBorder!=null&&(this.selectionBorder.rotation=this.state.style.rotation??0),this.edgeHandlers!=null)for(let i=0;i<this.edgeHandlers.length;i+=1)this.edgeHandlers[i].redraw()}isCustomHandleVisible(t){return!this.graph.isEditing()&&this.state.view.graph.getSelectionCount()===1}getRotationHandlePosition(){return new Point(this.bounds.x+this.bounds.width/2,this.bounds.y+this.rotationHandleVSpacing)}isParentHighlightVisible(){const t=this.state.cell.getParent();return t?!this.graph.isCellSelected(t):!1}updateParentHighlight(){if(!this.isDestroyed()){const t=this.isParentHighlightVisible(),e=this.state.cell.getParent(),i=e?this.graph.view.getState(e):null;if(this.parentHighlight)if(e&&e.isVertex()&&t){const s=this.parentHighlight.bounds;i&&s&&(s.x!==i.x||s.y!==i.y||s.width!==i.width||s.height!==i.height)&&(this.parentHighlight.bounds=Rectangle.fromRectangle(i),this.parentHighlight.redraw())}else i!=null&&i.parentHighlight===this.parentHighlight&&(i.parentHighlight=null),this.parentHighlight.destroy(),this.parentHighlight=null;else this.parentHighlightEnabled&&t&&e&&e.isVertex()&&i!=null&&i.parentHighlight==null&&(this.parentHighlight=this.createParentHighlightShape(i),this.parentHighlight.dialect="svg",this.parentHighlight.pointerEvents=!1,this.parentHighlight.rotation=i.style.rotation??0,this.parentHighlight.init(this.graph.getView().getOverlayPane()),this.parentHighlight.redraw(),i.parentHighlight=this.parentHighlight)}}drawPreview(){this.preview!=null&&(this.preview.bounds=this.bounds,this.preview.node.parentNode===this.graph.container&&(this.preview.bounds.width=Math.max(0,this.preview.bounds.width-1),this.preview.bounds.height=Math.max(0,this.preview.bounds.height-1)),this.preview.rotation=this.state.style.rotation??0,this.preview.redraw()),this.selectionBorder.bounds=this.getSelectionBorderBounds(),this.selectionBorder.redraw(),this.updateParentHighlight()}getSelectionBorderBounds(){return this.bounds}isDestroyed(){return this.selectionBorder==null}onDestroy(){if(this.state.view.graph.removeListener(this.escapeHandler),this.escapeHandler=()=>{},this.preview&&(this.preview.destroy(),this.preview=null),this.parentHighlight){const t=this.state.cell.getParent(),e=t?this.graph.view.getState(t):null;e&&e.parentHighlight===this.parentHighlight&&(e.parentHighlight=null),this.parentHighlight.destroy(),this.parentHighlight=null}this.ghostPreview&&(this.ghostPreview.destroy(),this.ghostPreview=null),this.selectionBorder&&this.selectionBorder.destroy(),this.labelShape=null,this.removeHint();for(let t=0;t<this.sizers.length;t+=1)this.sizers[t].destroy();this.sizers=[];for(let t=0;t<this.customHandles.length;t+=1)this.customHandles[t].destroy();this.customHandles=[]}}function isI18nEnabled(){return GlobalConfig.i18n.isEnabled()}function translate(r,t,e){return GlobalConfig.i18n.get(r,t,e)}class ElbowEdgeHandler extends EdgeHandler{constructor(t){super(t),this.flipEnabled=!0,this.doubleClickOrientationResource=isI18nEnabled()?"doubleClickOrientation":""}createBends(){const t=[];let e=this.createHandleShape(0);return this.initBend(e),e.setCursor(EdgeHandlerConfig.cursorTerminal),t.push(e),t.push(this.createVirtualBend(i=>{!isConsumed(i)&&this.flipEnabled&&(this.graph.flipEdge(this.state.cell),InternalEvent.consume(i))})),this.points.push(new Point(0,0)),e=this.createHandleShape(2),this.initBend(e),e.setCursor(EdgeHandlerConfig.cursorTerminal),t.push(e),t}createVirtualBend(t){const e=this.createHandleShape();return this.initBend(e,t),e.setCursor(this.getCursorForBend()),this.graph.isCellBendable(this.state.cell)||(e.node.style.display="none"),e}getCursorForBend(){return this.state.style.edgeStyle==="topToBottomEdgeStyle"||this.state.style.edgeStyle==="elbowEdgeStyle"&&this.state.style.elbow==="vertical"?"row-resize":"col-resize"}getTooltipForNode(t){let e=null;return this.bends!=null&&this.bends[1]!=null&&(t===this.bends[1].node||t.parentNode===this.bends[1].node)&&(e=this.doubleClickOrientationResource,e=translate(e)||e),e}convertPoint(t,e){const i=this.graph.getView().getScale(),s=this.graph.getView().getTranslate(),{origin:n}=this.state;return e&&(t.x=this.graph.snap(t.x),t.y=this.graph.snap(t.y)),t.x=Math.round(t.x/i-s.x-n.x),t.y=Math.round(t.y/i-s.y-n.y),t}redrawInnerBends(t,e){const i=this.state.cell.getGeometry(),s=this.state.absolutePoints;let n=null;s.length>1?(t=s[1],e=s[s.length-2]):i.points!=null&&i.points.length>0&&(n=s[0]),n==null?n=new Point(t.x+(e.x-t.x)/2,t.y+(e.y-t.y)/2):n=new Point(this.graph.getView().scale*(n.x+this.graph.getView().translate.x+this.state.origin.x),this.graph.getView().scale*(n.y+this.graph.getView().translate.y+this.state.origin.y));const l=this.bends[1].bounds;let o=l.width,a=l.height,h=new Rectangle(Math.round(n.x-o/2),Math.round(n.y-a/2),o,a);this.manageLabelHandle?this.checkLabelHandle(h):this.handleImage==null&&this.labelShape.visible&&this.labelShape.bounds&&intersects(h,this.labelShape.bounds)&&(o=HandleConfig.size+3,a=o,h=new Rectangle(Math.floor(n.x-o/2),Math.floor(n.y-a/2),o,a)),this.bends[1].bounds=h,this.bends[1].redraw(),this.manageLabelHandle&&this.checkLabelHandle(this.bends[1].bounds)}}class EdgeSegmentHandler extends ElbowEdgeHandler{constructor(t){super(t),this.points=[]}getCurrentPoints(){let t=this.state.absolutePoints;const e=Math.max(1,this.graph.view.scale);if(t.length===2&&t[0]&&t[1]||t.length===3&&t[0]&&t[1]&&t[2]&&(Math.abs(t[0].x-t[1].x)<e&&Math.abs(t[1].x-t[2].x)<e||Math.abs(t[0].y-t[1].y)<e&&Math.abs(t[1].y-t[2].y)<e)){const i=t[0].x+(t[t.length-1].x-t[0].x)/2,s=t[0].y+(t[t.length-1].y-t[0].y)/2;t=[t[0],new Point(i,s),new Point(i,s),t[t.length-1]]}return t}getPreviewPoints(t){if(this.isSource||this.isTarget)return super.getPreviewPoints(t);const e=this.getCurrentPoints();let i=this.convertPoint(e[0].clone(),!1);t=this.convertPoint(t.clone(),!1);let s=[];for(let n=1;n<e.length;n+=1){const l=this.convertPoint(e[n].clone(),!1);n===this.index&&(Math.round(i.x-l.x)===0&&(i.x=t.x,l.x=t.x),Math.round(i.y-l.y)===0&&(i.y=t.y,l.y=t.y)),n<e.length-1&&s.push(l),i=l}if(s.length===1){const n=this.state.getVisibleTerminalState(!0),l=this.state.getVisibleTerminalState(!1),o=this.state.view.getScale(),a=this.state.view.getTranslate(),h=s[0].x*o+a.x,d=s[0].y*o+a.y;(n!=null&&contains(n,h,d)||l!=null&&contains(l,h,d))&&(s=[t,t])}return s}updatePreviewState(t,e,i,s){if(super.updatePreviewState(t,e,i,s),!this.isSource&&!this.isTarget){e=this.convertPoint(e.clone(),!1);const n=t.absolutePoints;let l=n[0],o=n[1],a=[];for(let g=2;g<n.length;g+=1){const f=n[g];(Math.round(l.x-o.x)!==0||Math.round(o.x-f.x)!==0)&&(Math.round(l.y-o.y)!==0||Math.round(o.y-f.y)!==0)&&a.push(this.convertPoint(o.clone(),!1)),l=o,o=f}const h=this.state.getVisibleTerminalState(!0),d=this.state.getVisibleTerminalState(!1),c=this.state.absolutePoints,u=n[n.length-1];if(a.length===0&&n[0]&&u&&(Math.round(n[0].x-u.x)===0||Math.round(n[0].y-u.y)===0))a=[e,e];else if(n.length===5&&a.length===2&&h!=null&&d!=null&&c!=null&&Math.round(c[0].x-c[c.length-1].x)===0){const g=this.graph.getView(),f=g.getScale(),p=g.getTranslate();let y=g.getRoutingCenterY(h)/f-p.y;const v=this.graph.getConnectionConstraint(t,h,!0);if(v!=null){const C=this.graph.getConnectionPoint(h,v);C!=null&&(this.convertPoint(C,!1),y=C.y)}let S=g.getRoutingCenterY(d)/f-p.y;const w=this.graph.getConnectionConstraint(t,d,!1);if(w){const C=this.graph.getConnectionPoint(d,w);C!=null&&(this.convertPoint(C,!1),S=C.y)}a=[new Point(e.x,y),new Point(e.x,S)]}this.points=a,t.view.updateFixedTerminalPoints(t,h,d),t.view.updatePoints(t,this.points,h,d),t.view.updateFloatingTerminalPoints(t,h,d)}}connect(t,e,i,s,n){const l=this.graph.getDataModel();let o=t.getGeometry(),a=null;if(o!=null&&o.points!=null&&o.points.length>0){const h=this.abspoints;let d=h[0],c=h[1];a=[];for(let u=2;u<h.length;u+=1){const g=h[u];d&&c&&g&&(Math.round(d.x-c.x)!==0||Math.round(c.x-g.x)!==0)&&(Math.round(d.y-c.y)!==0||Math.round(c.y-g.y)!==0)&&a.push(this.convertPoint(c.clone(),!1)),d=c,c=g}}return this.graph.batchUpdate(()=>{a!=null&&(o=t.getGeometry(),o!=null&&(o=o.clone(),o.points=a,l.setGeometry(t,o))),t=super.connect(t,e,i,s,n)}),t}getTooltipForNode(t){return null}start(t,e,i){super.start(t,e,i),this.bends!=null&&this.bends[i]!=null&&!this.isSource&&!this.isTarget&&setOpacity(this.bends[i].node,100)}createBends(){const t=[];let e=this.createHandleShape(0);this.initBend(e),e.setCursor(EdgeHandlerConfig.cursorTerminal),t.push(e);const i=this.getCurrentPoints();if(this.graph.isCellBendable(this.state.cell)){this.points==null&&(this.points=[]);for(let s=0;s<i.length-1;s+=1){e=this.createVirtualBend(),t.push(e);let n=Math.round(i[s].x-i[s+1].x)===0;Math.round(i[s].y-i[s+1].y)===0&&s<i.length-2&&(n=Math.round(i[s].x-i[s+2].x)===0),e.setCursor(n?"col-resize":"row-resize"),this.points.push(new Point(0,0))}}return e=this.createHandleShape(i.length),this.initBend(e),e.setCursor(EdgeHandlerConfig.cursorTerminal),t.push(e),t}redraw(){this.refresh(),super.redraw()}redrawInnerBends(t,e){if(this.graph.isCellBendable(this.state.cell)){const i=this.getCurrentPoints();if(i!=null&&i.length>1){let s=!1;if(i.length===4&&i[0]&&i[1]&&i[2]&&i[3]&&Math.round(i[1].x-i[2].x)===0&&Math.round(i[1].y-i[2].y)===0)if(s=!0,Math.round(i[0].y-i[i.length-1].y)===0){const n=i[0].x+(i[i.length-1].x-i[0].x)/2;i[1]=new Point(n,i[1].y),i[2]=new Point(n,i[2].y)}else{const n=i[0].y+(i[i.length-1].y-i[0].y)/2;i[1]=new Point(i[1].x,n),i[2]=new Point(i[2].x,n)}for(let n=0;n<i.length-1;n+=1)if(this.bends[n+1]!=null){t=i[n],e=i[n+1];const l=new Point(t.x+(e.x-t.x)/2,t.y+(e.y-t.y)/2),o=this.bends[n+1].bounds;this.bends[n+1].bounds=new Rectangle(Math.floor(l.x-o.width/2),Math.floor(l.y-o.height/2),o.width,o.height),this.bends[n+1].redraw(),this.manageLabelHandle&&this.checkLabelHandle(this.bends[n+1].bounds)}s&&(setOpacity(this.bends[1].node,EdgeHandlerConfig.virtualBendOpacity),setOpacity(this.bends[3].node,EdgeHandlerConfig.virtualBendOpacity))}}}}const getTopmostCells=r=>{const t=new Map,e=[];for(let i=0;i<r.length;i+=1)t.set(r[i],!0);for(let i=0;i<r.length;i+=1){const s=r[i];let n=!0,l=s.getParent();for(;l!=null;){if(t.get(l)){n=!1;break}l=l.getParent()}n&&e.push(s)}return e},cloneCells=(r,t=!0,e={})=>{const i=[];for(const s of r)i.push(cloneCellImpl(s,e,t));for(let s=0;s<i.length;s+=1)i[s]!=null&&restoreClone(i[s],r[s],e);return i},cloneCellImpl=(r,t={},e=!1)=>{const i=ObjectIdentity.get(r);let s=t?t[i]:null;if(s==null&&(s=r.clone(),t[i]=s,e)){const n=r.getChildCount();for(let l=0;l<n;l+=1){const o=cloneCellImpl(r.getChildAt(l),t,!0);s.insert(o)}}return s},restoreClone=(r,t,e)=>{const i=t.getTerminal(!0);if(i!=null){const l=e[ObjectIdentity.get(i)];l!=null&&l.insertEdge(r,!0)}const s=t.getTerminal(!1);if(s!=null){const l=e[ObjectIdentity.get(s)];l!=null&&l.insertEdge(r,!1)}const n=r.getChildCount();for(let l=0;l<n;l+=1)restoreClone(r.getChildAt(l),t.getChildAt(l),e)},CellsMixin={cellsResizable:!0,cellsBendable:!0,cellsSelectable:!0,cellsDisconnectable:!0,autoSizeCells:!1,autoSizeCellsOnAdd:!1,cellsLocked:!1,cellsCloneable:!0,cellsDeletable:!0,cellsMovable:!0,extendParents:!0,extendParentsOnAdd:!0,extendParentsOnMove:!1,getBoundingBox(r){let t=null;if(r.length>0){for(const e of r)if(e.isVertex()||e.isEdge()){const i=this.getView().getBoundingBox(this.getView().getState(e),!0);i&&(t?t.add(i):t=Rectangle.fromRectangle(i))}}return t},removeStateForCell(r){for(const t of r.getChildren())this.removeStateForCell(t);this.getView().invalidate(r,!1,!0),this.getView().removeState(r)},getCurrentCellStyle(r,t=!1){const e=t?null:this.getView().getState(r);return e?e.style:this.getCellStyle(r)},getCellStyle(r){const t=r.getStyle(),e=this.getStylesheet(),i=r.isEdge()?e.getDefaultEdgeStyle():e.getDefaultVertexStyle();return this.postProcessCellStyle(e.getCellStyle(t,i??{}))},postProcessCellStyle(r){var i;if(!r.image)return r;const t=r.image;let e=((i=this.getPlugin("image-bundle"))==null?void 0:i.getImageFromBundles(t))??null;if(e?r.image=e:e=t,e&&e.substring(0,11)==="data:image/"){if(e.substring(0,20)==="data:image/svg+xml,<")e=e.substring(0,19)+encodeURIComponent(e.substring(19));else if(e.substring(0,22)!=="data:image/svg+xml,%3C"){const s=e.indexOf(",");s>0&&e.substring(s-7,s+1)!==";base64,"&&(e=`${e.substring(0,s)};base64,${e.substring(s+1)}`)}r.image=e}return r},setCellStyle(r,t){t=t??this.getSelectionCells(),this.batchUpdate(()=>{for(const e of t)this.getDataModel().setStyle(e,r)})},toggleCellStyle(r,t=!1,e){return e=e??this.getSelectionCell(),this.toggleCellStyles(r,t,[e])},toggleCellStyles(r,t=!1,e){let i=!1;return e=e??this.getSelectionCells(),e.length>0&&(i=!(this.getCurrentCellStyle(e[0])[r]??t),this.setCellStyles(r,i,e)),i},setCellStyles(r,t,e){e=e??this.getSelectionCells(),setCellStyles(this.getDataModel(),e,r,t)},toggleCellStyleFlags(r,t,e){e=e??this.getSelectionCells(),this.setCellStyleFlags(r,t,null,e)},setCellStyleFlags(r,t,e=null,i){i=i??this.getSelectionCells(),i.length>0&&(e===null&&(e=((this.getCurrentCellStyle(i[0])[r]||0)&t)!==t),setCellStyleFlags(this.getDataModel(),i,r,t,e))},alignCells(r,t,e=null){if(t=t??this.getSelectionCells(),t.length>1){if(e===null)for(const i of t){const s=this.getView().getState(i);if(s&&!i.isEdge())if(e===null)switch(r){case"center":e=s.x+s.width/2;break;case"right":e=s.x+s.width;break;case"top":e=s.y;break;case"middle":e=s.y+s.height/2;break;case"bottom":e=s.y+s.height;break;default:e=s.x;break}else switch(r){case"right":{e=Math.max(e,s.x+s.width);break}case"top":{e=Math.min(e,s.y);break}case"bottom":{e=Math.max(e,s.y+s.height);break}default:e=Math.min(e,s.x)}}if(e!==null){const i=this.getView().scale;this.batchUpdate(()=>{const s=e;for(const n of t){const l=this.getView().getState(n);if(l!=null){let o=n.getGeometry();if(o!=null&&!n.isEdge()){switch(o=o.clone(),r){case"center":{o.x+=(s-l.x-l.width/2)/i;break}case"right":{o.x+=(s-l.x-l.width)/i;break}case"top":{o.y+=(s-l.y)/i;break}case"middle":{o.y+=(s-l.y-l.height/2)/i;break}case"bottom":{o.y+=(s-l.y-l.height)/i;break}default:o.x+=(s-l.x)/i}this.resizeCell(n,o)}}}this.fireEvent(new EventObject(InternalEvent.ALIGN_CELLS,{align:r,cells:t}))})}}return t},cloneCell(r,t=!1,e={},i=!1){return this.cloneCells([r],t,e,i)[0]},cloneCells(r,t=!0,e={},i=!1){let s;const n=new Map,l=[];for(const o of r)n.set(o,!0),l.push(o);if(l.length>0){const{scale:o}=this.getView(),a=this.getView().translate,h=[];s=cloneCells(r,!0,e);for(let d=0;d<r.length;d+=1){const c=r[d],u=s[d];if(!(!t&&u.isEdge()&&this.getEdgeValidationError(u,u.getTerminal(!0),u.getTerminal(!1))!==null)){h.push(u);const g=u.getGeometry();if(g){const f=this.getView().getState(c),p=c.getParent(),y=p?this.getView().getState(p):null;if(f&&y){const v=i?0:y.origin.x,S=i?0:y.origin.y;if(u.isEdge()){const w=f.absolutePoints;let C=c.getTerminal(!0);for(;C&&!n.get(C);)C=C.getParent();!C&&w[0]&&g.setTerminalPoint(new Point(w[0].x/o-a.x,w[0].y/o-a.y),!0);let m=c.getTerminal(!1);for(;m&&!n.get(m);)m=m.getParent();const M=w.length-1,b=w[M];!m&&b&&g.setTerminalPoint(new Point(b.x/o-a.x,b.y/o-a.y),!1);const{points:O}=g;if(O)for(const R of O)R.x+=v,R.y+=S}else g.translate(v,S)}}}}s=h}else s=[];return s},addCell(r,t=null,e=null,i=null,s=null){return this.addCells([r],t,e,i,s)[0]},addCells(r,t=null,e=null,i=null,s=null,n=!1){const l=t??this.getDefaultParent(),o=e??l.getChildCount();return this.batchUpdate(()=>{this.cellsAdded(r,l,o,i,s,n,!0),this.fireEvent(new EventObject(InternalEvent.ADD_CELLS,{cells:r,p:l,i:o,source:i,target:s}))}),r},cellsAdded(r,t,e,i=null,s=null,n=!1,l=!1,o=!0){this.batchUpdate(()=>{const a=n?this.getView().getState(t):null,h=a?a.origin:null,d=new Point(0,0);r.forEach((c,u)=>{const g=c.getParent();if(h&&c!==t&&t!==g){const f=g?this.getView().getState(g):null,p=f?f.origin:d;let y=c.getGeometry();if(y){const v=p.x-h.x,S=p.y-h.y;y=y.clone(),y.translate(v,S),!y.relative&&c.isVertex()&&!this.isAllowNegativeCoordinates()&&(y.x=Math.max(0,y.x),y.y=Math.max(0,y.y)),this.getDataModel().setGeometry(c,y)}}t===g&&e+u>t.getChildCount()&&e--,this.getDataModel().add(t,c,e+u),this.autoSizeCellsOnAdd&&this.autoSizeCell(c,!0),(!o||o)&&this.isExtendParentsOnAdd(c)&&this.isExtendParent(c)&&this.extendParent(c),(!l||l)&&this.constrainChild(c),i&&this.cellConnected(c,i,!0),s&&this.cellConnected(c,s,!1)}),this.fireEvent(new EventObject(InternalEvent.CELLS_ADDED,{cells:r,parent:t,index:e,source:i,target:s,absolute:n}))})},autoSizeCell(r,t=!0){if(t)for(const e of r.getChildren())this.autoSizeCell(e);r.isVertex()&&this.isAutoSizeCell(r)&&this.updateCellSize(r)},removeCells(r=null,t=!0){if(r||(r=this.getDeletableCells(this.getSelectionCells())),t)r=this.getDeletableCells(this.addAllEdges(r));else{r=r.slice();const e=this.getDeletableCells(this.getAllEdges(r)),i=new Map;for(const s of r)i.set(s,!0);for(const s of e)!this.getView().getState(s)&&!i.get(s)&&(i.set(s,!0),r.push(s))}return this.batchUpdate(()=>{this.cellsRemoved(r),this.fireEvent(new EventObject(InternalEvent.REMOVE_CELLS,{cells:r,includeEdges:t}))}),r??[]},cellsRemoved(r){if(r.length>0){const{scale:t}=this.getView(),e=this.getView().translate;this.batchUpdate(()=>{const i=new Map;for(const s of r)i.set(s,!0);for(const s of r){const n=this.getAllEdges([s]),l=(o,a)=>{let h=o.getGeometry();if(h){const d=o.getTerminal(a);let c=!1,u=d;for(;u;){if(s===u){c=!0;break}u=u.getParent()}if(c){h=h.clone();const g=this.getView().getState(o);if(g){const f=g.absolutePoints,p=a?0:f.length-1,y=f[p];h.setTerminalPoint(new Point(y.x/t-e.x-g.origin.x,y.y/t-e.y-g.origin.y),a)}else if(d){const f=this.getView().getState(d);f&&h.setTerminalPoint(new Point(f.getCenterX()/t-e.x,f.getCenterY()/t-e.y),a)}this.getDataModel().setGeometry(o,h),this.getDataModel().setTerminal(o,null,a)}}};for(const o of n)i.get(o)||(i.set(o,!0),l(o,!0),l(o,!1));this.getDataModel().remove(s)}this.fireEvent(new EventObject(InternalEvent.CELLS_REMOVED,{cells:r}))})}},toggleCells(r=!1,t,e=!0){return t=t??this.getSelectionCells(),e&&(t=this.addAllEdges(t)),this.batchUpdate(()=>{this.cellsToggled(t,r),this.fireEvent(new EventObject(InternalEvent.TOGGLE_CELLS,{show:r,cells:t,includeEdges:e}))}),t},cellsToggled(r,t=!1){r.length>0&&this.batchUpdate(()=>{for(const e of r)this.getDataModel().setVisible(e,t)})},updateCellSize(r,t=!1){return this.batchUpdate(()=>{this.cellSizeUpdated(r,t),this.fireEvent(new EventObject(InternalEvent.UPDATE_CELL_SIZE,{cell:r,ignoreChildren:t}))}),r},cellSizeUpdated(r,t=!1){this.batchUpdate(()=>{const e=this.getPreferredSizeForCell(r);let i=r.getGeometry();if(e&&i){const s=r.isCollapsed();if(i=i.clone(),this.isSwimlane(r)){const n=this.getCellStyle(r),l=r.getStyle();n.horizontal??!0?(l.startSize=e.height+8,s&&(i.height=e.height+8),i.width=e.width):(l.startSize=e.width+8,s&&(i.width=e.width+8),i.height=e.height),this.getDataModel().setStyle(r,l)}else{const n=this.getView().createState(r),l=n.style.align??"center";l==="right"?i.x+=i.width-e.width:l==="center"&&(i.x+=Math.round((i.width-e.width)/2));const o=n.getVerticalAlign();o==="bottom"?i.y+=i.height-e.height:o==="middle"&&(i.y+=Math.round((i.height-e.height)/2)),i.width=e.width,i.height=e.height}if(!t&&!s){const n=this.getView().getBounds(r.getChildren());if(n!=null){const l=this.getView().translate,{scale:o}=this.getView(),a=(n.x+n.width)/o-i.x-l.x,h=(n.y+n.height)/o-i.y-l.y;i.width=Math.max(i.width,a),i.height=Math.max(i.height,h)}}this.cellsResized([r],[i],!1)}})},getPreferredSizeForCell(r,t=null){let e=null;const i=this.getView().createState(r),{style:s}=i;if(!r.isEdge()){const n=s.fontSize||StyleDefaultsConfig.fontSize;let l=0,o=0;(i.getImageSrc()||s.image)&&s.shape==="label"&&(s.verticalAlign==="middle"&&(l+=s.imageWidth||StyleDefaultsConfig.imageSize),s.align!=="center"&&(o+=s.imageHeight||StyleDefaultsConfig.imageSize)),l+=2*(s.spacing||0),l+=s.spacingLeft||0,l+=s.spacingRight||0,o+=2*(s.spacing||0),o+=s.spacingTop||0,o+=s.spacingBottom||0;const a=this.getFoldingImage(i);a&&(l+=a.width+8);let h=this.getCellRenderer().getLabelValue(i);if(h&&h.length>0){this.isHtmlLabel(i.cell)||(h=htmlEntities(h,!1)),h=h.replace(/\n/g,"<br>");const d=getSizeForString(h,n,s.fontFamily,t,s.fontStyle);let c=d.width+l,u=d.height+o;if(!(s.horizontal??!0)){const g=u;u=c,c=g}this.isGridEnabled()&&(c=this.snap(c+this.getGridSize()/2),u=this.snap(u+this.getGridSize()/2)),e=new Rectangle(0,0,c,u)}else{const d=4*this.getGridSize();e=new Rectangle(0,0,d,d)}}return e},resizeCell(r,t,e=!1){return this.resizeCells([r],[t],e)[0]},resizeCells(r,t,e){return e=e??this.isRecursiveResize(),this.batchUpdate(()=>{const i=this.cellsResized(r,t,e);this.fireEvent(new EventObject(InternalEvent.RESIZE_CELLS,{cells:r,bounds:t,prev:i}))}),r},cellsResized(r,t,e=!1){const i=[];return r.length===t.length&&this.batchUpdate(()=>{r.forEach((s,n)=>{i.push(this.cellResized(s,t[n],!1,e)),this.isExtendParent(s)&&this.extendParent(s),this.constrainChild(s)}),this.isResetEdgesOnResize()&&this.resetEdges(r),this.fireEvent(new EventObject(InternalEvent.CELLS_RESIZED,{cells:r,bounds:t,prev:i}))}),i},cellResized(r,t,e=!1,i=!1){const s=r.getGeometry();if(s&&(s.x!==t.x||s.y!==t.y||s.width!==t.width||s.height!==t.height)){const n=s.clone();if(!e&&n.relative){const{offset:l}=n;l&&(l.x+=t.x-n.x,l.y+=t.y-n.y)}else n.x=t.x,n.y=t.y;n.width=t.width,n.height=t.height,!n.relative&&r.isVertex()&&!this.isAllowNegativeCoordinates()&&(n.x=Math.max(0,n.x),n.y=Math.max(0,n.y)),this.batchUpdate(()=>{i&&this.resizeChildCells(r,n),this.getDataModel().setGeometry(r,n),this.constrainChildCells(r)})}return s},resizeChildCells(r,t){const e=r.getGeometry();if(e){const i=e.width!==0?t.width/e.width:1,s=e.height!==0?t.height/e.height:1;for(const n of r.getChildren())this.scaleCell(n,i,s,!0)}},constrainChildCells(r){for(const t of r.getChildren())this.constrainChild(t)},scaleCell(r,t,e,i=!1){let s=r.getGeometry();if(s){const n=this.getCurrentCellStyle(r);s=s.clone();const{x:l}=s,{y:o}=s,a=s.width,h=s.height;s.scale(t,e,n.aspect==="fixed"),n.resizeWidth?s.width=a*t:n.resizeWidth||(s.width=a),n.resizeHeight?s.height=h*e:n.resizeHeight||(s.height=h),this.isCellMovable(r)||(s.x=l,s.y=o),this.isCellResizable(r)||(s.width=a,s.height=h),r.isVertex()?this.cellResized(r,s,!0,i):this.getDataModel().setGeometry(r,s)}},extendParent(r){const t=r.getParent();let e=t?t.getGeometry():null;if(t&&e&&!t.isCollapsed()){const i=r.getGeometry();i&&!i.relative&&(e.width<i.x+i.width||e.height<i.y+i.height)&&(e=e.clone(),e.width=Math.max(e.width,i.x+i.width),e.height=Math.max(e.height,i.y+i.height),this.cellsResized([t],[e],!1))}},importCells(r,t,e,i=null,s=null,n={}){return this.moveCells(r,t,e,!0,i,s,n)},moveCells(r,t=0,e=0,i=!1,s=null,n=null,l={}){if(t!==0||e!==0||i||s){r=getTopmostCells(r);const o=r;this.batchUpdate(()=>{const a=new Map;for(const u of r)a.set(u,!0);const h=u=>{for(;u;){if(a.get(u))return!0;u=u.getParent()}return!1},d=[];for(const u of r){const g=u.getGeometry(),f=u.getParent();(!g||!g.relative||f&&!f.isEdge()||f&&!h(f.getTerminal(!0))&&!h(f.getTerminal(!1)))&&d.push(u)}r=d,i&&(r=this.cloneCells(r,this.isCloneInvalidEdges(),l),s||(s=this.getDefaultParent()));const c=this.isAllowNegativeCoordinates();if(s&&this.setAllowNegativeCoordinates(!0),this.cellsMoved(r,t,e,!i&&this.isDisconnectOnMove()&&this.isAllowDanglingEdges(),!s,this.isExtendParentsOnMove()&&!s),this.setAllowNegativeCoordinates(c),s){const u=s.getChildCount();this.cellsAdded(r,s,u,null,null,!0),i&&r.forEach((g,f)=>{const p=g.getGeometry(),y=o[f].getParent();p&&p.relative&&y&&y.isEdge()&&this.getDataModel().contains(y)&&this.getDataModel().add(y,g)})}this.fireEvent(new EventObject(InternalEvent.MOVE_CELLS,{cells:r,dx:t,dy:e,clone:i,target:s,event:n}))})}return r},cellsMoved(r,t,e,i=!1,s=!1,n=!1){(t!==0||e!==0)&&this.batchUpdate(()=>{i&&this.disconnectGraph(r);for(const l of r)this.translateCell(l,t,e),n&&this.isExtendParent(l)?this.extendParent(l):s&&this.constrainChild(l);this.isResetEdgesOnMove()&&this.resetEdges(r),this.fireEvent(new EventObject(InternalEvent.CELLS_MOVED,{cells:r,dx:t,dy:e,disconnect:i}))})},translateCell(r,t,e){let i=r.getGeometry();if(i){if(i=i.clone(),i.translate(t,e),!i.relative&&r.isVertex()&&!this.isAllowNegativeCoordinates()&&(i.x=Math.max(0,i.x),i.y=Math.max(0,i.y)),i.relative&&!r.isEdge()){const s=r.getParent();let n=0;if(s.isVertex()&&(n=this.getCurrentCellStyle(s).rotation??0),n!==0){const l=toRadians(-n),o=Math.cos(l),a=Math.sin(l),h=getRotatedPoint(new Point(t,e),o,a,new Point(0,0));t=h.x,e=h.y}i.offset?(i.offset.x=i.offset.x+t,i.offset.y=i.offset.y+e):i.offset=new Point(t,e)}this.getDataModel().setGeometry(r,i)}},getCellContainmentArea(r){if(!r.isEdge()){const t=r.getParent();if(t&&t!==this.getDefaultParent()){const e=t.getGeometry();if(e){let i=0,s=0,n=e.width,l=e.height;if(this.isSwimlane(t)){const o=this.getStartSize(t),a=this.getCurrentCellStyle(t),h=a.direction??"east",d=a.flipH??!1,c=a.flipV??!1;if(h==="south"||h==="north"){const u=o.width;o.width=o.height,o.height=u}(h==="east"&&!c||h==="north"&&!d||h==="west"&&c||h==="south"&&d)&&(i=o.width,s=o.height),n-=o.width,l-=o.height}return new Rectangle(i,s,n,l)}}}return null},constrainChild(r,t=!0){let e=r.getGeometry();if(e&&(this.isConstrainRelativeChildren()||!e.relative)){const i=r.getParent();let s=this.getMaximumGraphBounds();if(s&&i){const n=this.getBoundingBoxFromGeometry([i],!1);n&&(s=Rectangle.fromRectangle(s),s.x-=n.x,s.y-=n.y)}if(this.isConstrainChild(r)){let n=this.getCellContainmentArea(r);if(n){const l=this.getOverlap(r);l>0&&(n=Rectangle.fromRectangle(n),n.x-=n.width*l,n.y-=n.height*l,n.width+=2*n.width*l,n.height+=2*n.height*l),s?(s=Rectangle.fromRectangle(s),s.intersect(n)):s=n}}if(s){const n=[r];if(!r.isCollapsed()){const o=r.getDescendants();for(const a of o)a.isVisible()&&n.push(a)}const l=this.getBoundingBoxFromGeometry(n,!1);if(l){e=e.clone();let o=0;e.width>s.width&&(o=e.width-s.width,e.width-=o),l.x+l.width>s.x+s.width&&(o-=l.x+l.width-s.x-s.width-o);let a=0;e.height>s.height&&(a=e.height-s.height,e.height-=a),l.y+l.height>s.y+s.height&&(a-=l.y+l.height-s.y-s.height-a),l.x<s.x&&(o-=l.x-s.x),l.y<s.y&&(a-=l.y-s.y),(o!==0||a!==0)&&(e.relative?(e.offset||(e.offset=new Point),e.offset.x+=o,e.offset.y+=a):(e.x+=o,e.y+=a)),this.getDataModel().setGeometry(r,e)}}}},getChildCells(r,t=!1,e=!1){r=r??this.getDefaultParent();const i=r.getChildCells(t,e),s=[];for(const n of i)n.isVisible()&&s.push(n);return s},getCellAt(r,t,e=null,i=!0,s=!0,n=null){if(e||(e=this.getCurrentRoot(),e||(e=this.getDataModel().getRoot())),e){const l=e.getChildCount();for(let o=l-1;o>=0;o--){const a=e.getChildAt(o),h=this.getCellAt(r,t,a,i,s,n);if(h)return h;if(a.isVisible()&&(s&&a.isEdge()||i&&a.isVertex())){const d=this.getView().getState(a);if(d&&(!n||!n(d,r,t))&&this.intersects(d,r,t))return a}}}return null},getCells(r,t,e,i,s=null,n=[],l=null,o=null,a=!1){if(e>0||i>0||l){const h=this.getDataModel(),d=r+e,c=t+i;if(s||(s=this.getCurrentRoot(),s||(s=h.getRoot())),s)for(const u of s.getChildren()){const g=this.getView().getState(u);if(g&&u.isVisible()&&(!o||!o(g))){const f=g.style.rotation??0;let p=g;f!==0&&(p=getBoundingBox(p,f));const y=l&&u.isVertex()&&intersects(l,p)||!l&&(u.isEdge()||u.isVertex())&&p.x>=r&&p.y+p.height<=c&&p.y>=t&&p.x+p.width<=d;y&&n.push(u),(!y||a)&&this.getCells(r,t,e,i,u,n,l,o,a)}}}return n},getCellsBeyond(r,t,e=null,i=!1,s=!1){const n=[];if((i||s)&&(e||(e=this.getDefaultParent()),e))for(const l of e.getChildren()){const o=this.getView().getState(l);l.isVisible()&&o&&(!i||o.x>=r)&&(!s||o.y>=t)&&n.push(l)}return n},intersects(r,t,e){const i=r.absolutePoints;if(i.length>0){const s=this.getEventTolerance()*this.getEventTolerance();let n=i[0];for(let l=1;l<i.length;l+=1){const o=i[l];if(n&&o&&ptSegDistSq(n.x,n.y,o.x,o.y,t,e)<=s)return!0;n=o}}else{const s=toRadians(r.style.rotation??0);if(s!==0){const n=Math.cos(-s),l=Math.sin(-s),o=new Point(r.getCenterX(),r.getCenterY()),a=getRotatedPoint(new Point(t,e),n,l,o);t=a.x,e=a.y}if(contains(r,t,e))return!0}return!1},isValidAncestor(r,t,e=!1){return e?t.isAncestor(r):(r==null?void 0:r.getParent())===t},isCellLocked(r){const t=r.getGeometry();return this.isCellsLocked()||!!t&&r.isVertex()&&t.relative},isCellsLocked(){return this.cellsLocked},setCellsLocked(r){this.cellsLocked=r},getCloneableCells(r){return this.getDataModel().filterCells(r,t=>this.isCellCloneable(t))},isCellCloneable(r){return this.isCellsCloneable()&&(this.getCurrentCellStyle(r).cloneable??!0)},isCellsCloneable(){return this.cellsCloneable},setCellsCloneable(r){this.cellsCloneable=r},getExportableCells(r){return this.getDataModel().filterCells(r,t=>this.canExportCell(t))},canExportCell(r=null){return this.isExportEnabled()},getImportableCells(r){return this.getDataModel().filterCells(r,t=>this.canImportCell(t))},canImportCell(r=null){return this.isImportEnabled()},isCellSelectable(r){return this.isCellsSelectable()},isCellsSelectable(){return this.cellsSelectable},setCellsSelectable(r){this.cellsSelectable=r},getDeletableCells(r){return this.getDataModel().filterCells(r,t=>this.isCellDeletable(t))},isCellDeletable(r){return this.isCellsDeletable()&&(this.getCurrentCellStyle(r).deletable??!0)},isCellsDeletable(){return this.cellsDeletable},setCellsDeletable(r){this.cellsDeletable=r},isCellRotatable(r){return this.getCurrentCellStyle(r).rotatable??!0},getMovableCells(r){return this.getDataModel().filterCells(r,t=>this.isCellMovable(t))},isCellMovable(r){return this.isCellsMovable()&&!this.isCellLocked(r)&&(this.getCurrentCellStyle(r).movable??!0)},isCellsMovable(){return this.cellsMovable},setCellsMovable(r){this.cellsMovable=r},isCellResizable(r){return this.isCellsResizable()&&!this.isCellLocked(r)&&(this.getCurrentCellStyle(r).resizable??!0)},isCellsResizable(){return this.cellsResizable},setCellsResizable(r){this.cellsResizable=r},isCellBendable(r){return this.isCellsBendable()&&!this.isCellLocked(r)&&(this.getCurrentCellStyle(r).bendable??!0)},isCellsBendable(){return this.cellsBendable},setCellsBendable(r){this.cellsBendable=r},isAutoSizeCell(r){return this.isAutoSizeCells()||(this.getCurrentCellStyle(r).autoSize??!1)},isAutoSizeCells(){return this.autoSizeCells},setAutoSizeCells(r){this.autoSizeCells=r},isExtendParent(r){return!r.isEdge()&&this.isExtendParents()},isExtendParents(){return this.extendParents},setExtendParents(r){this.extendParents=r},isExtendParentsOnAdd(r){return this.extendParentsOnAdd},setExtendParentsOnAdd(r){this.extendParentsOnAdd=r},isExtendParentsOnMove(){return this.extendParentsOnMove},setExtendParentsOnMove(r){this.extendParentsOnMove=r},getCursorForCell(r){return null},getCellBounds(r,t=!1,e=!1){let i=[r];t&&(i=i.concat(r.getEdges()));let s=this.getView().getBounds(i);if(e)for(const n of r.getChildren()){const l=this.getCellBounds(n,t,!0);s&&l?s.add(l):s=l}return s},getBoundingBoxFromGeometry(r,t=!1){let e=null,i=null;for(const s of r)if(t||s.isVertex()){const n=s.getGeometry();if(n){let l=null;if(s.isEdge()){const o=h=>{h&&(i?i.add(new Rectangle(h.x,h.y,0,0)):i=new Rectangle(h.x,h.y,0,0))};s.getTerminal(!0)||o(n.getTerminalPoint(!0)),s.getTerminal(!1)||o(n.getTerminalPoint(!1));const a=n.points;if(a&&a.length>0){i=new Rectangle(a[0].x,a[0].y,0,0);for(let h=1;h<a.length;h++)o(a[h])}l=i}else{const o=s.getParent();n.relative&&o?o.isVertex()&&o!==this.getView().currentRoot&&(i=this.getBoundingBoxFromGeometry([o],!1),i&&(l=new Rectangle(n.x*i.width,n.y*i.height,n.width,n.height),r.includes(o)&&(l.x+=i.x,l.y+=i.y))):(l=Rectangle.fromRectangle(n),o&&o.isVertex()&&r.includes(o)&&(i=this.getBoundingBoxFromGeometry([o],!1),i&&(l.x+=i.x,l.y+=i.y))),l&&n.offset&&(l.x+=n.offset.x,l.y+=n.offset.y);const a=this.getCurrentCellStyle(s);if(l){const h=a.rotation??0;h!==0&&(l=getBoundingBox(l,h))}}l&&(e?e.add(l):e=Rectangle.fromRectangle(l))}}return e}},ConnectionsMixin={constrainChildren:!0,constrainRelativeChildren:!1,disconnectOnMove:!0,cellsDisconnectable:!0,getOutlineConstraint(r,t,e){if(t.shape){const i=this.getView().getPerimeterBounds(t),s=t.style.direction;if(s==="north"||s==="south"){i.x+=i.width/2-i.height/2,i.y+=i.height/2-i.width/2;const u=i.width;i.width=i.height,i.height=u}const n=toRadians(t.shape.getShapeRotation());if(n!==0){const u=Math.cos(-n),g=Math.sin(-n),f=new Point(i.getCenterX(),i.getCenterY());r=getRotatedPoint(r,u,g,f)}let l=1,o=1,a=0,h=0;if(t.cell.isVertex()){let u=t.style.flipH,g=t.style.flipV;if(s==="north"||s==="south"){const f=u;u=g,g=f}u&&(l=-1,a=-i.width),g&&(o=-1,h=-i.height)}r=new Point((r.x-i.x)*l-a+i.x,(r.y-i.y)*o-h+i.y);const d=i.width===0?0:Math.round((r.x-i.x)*1e3/i.width)/1e3,c=i.height===0?0:Math.round((r.y-i.y)*1e3/i.height)/1e3;return new ConnectionConstraint(new Point(d,c),!1)}return null},getAllConnectionConstraints(r,t){var e,i;return((i=(e=r==null?void 0:r.shape)==null?void 0:e.stencil)==null?void 0:i.constraints)??null},getConnectionConstraint(r,t,e=!1){let i=null;const s=r.style[e?"exitX":"entryX"];if(s!==void 0){const a=r.style[e?"exitY":"entryY"];a!==void 0&&(i=new Point(s,a))}let n=!1,l=0,o=0;return i&&(n=r.style[e?"exitPerimeter":"entryPerimeter"]||!1,l=r.style[e?"exitDx":"entryDx"],o=r.style[e?"exitDy":"entryDy"],l=Number.isFinite(l)?l:0,o=Number.isFinite(o)?o:0),new ConnectionConstraint(i,n,null,l,o)},setConnectionConstraint(r,t,e=!1,i=null){i&&this.batchUpdate(()=>{!i||!i.point?(this.setCellStyles(e?"exitX":"entryX",null,[r]),this.setCellStyles(e?"exitY":"entryY",null,[r]),this.setCellStyles(e?"exitDx":"entryDx",null,[r]),this.setCellStyles(e?"exitDy":"entryDy",null,[r]),this.setCellStyles(e?"exitPerimeter":"entryPerimeter",null,[r])):i.point&&(this.setCellStyles(e?"exitX":"entryX",i.point.x,[r]),this.setCellStyles(e?"exitY":"entryY",i.point.y,[r]),this.setCellStyles(e?"exitDx":"entryDx",i.dx,[r]),this.setCellStyles(e?"exitDy":"entryDy",i.dy,[r]),i.perimeter?this.setCellStyles(e?"exitPerimeter":"entryPerimeter",!0,[r]):this.setCellStyles(e?"exitPerimeter":"entryPerimeter",!1,[r]))})},getConnectionPoint(r,t,e=!0){let i=null;if(t.point){const s=this.getView().getPerimeterBounds(r),n=new Point(s.getCenterX(),s.getCenterY()),l=r.style.direction;let o=0;if(r.style.anchorPointDirection){switch(l){case"north":{o+=270;break}case"west":{o+=180;break}case"south":{o+=90;break}}(l==="north"||l==="south")&&s.rotate90()}const{scale:a}=this.getView();i=new Point(s.x+t.point.x*s.width+t.dx*a,s.y+t.point.y*s.height+t.dy*a);let h=r.style.rotation||0;if(t.perimeter){if(o!==0){let d=0,c=0;switch(o){case 90:{c=1;break}case 180:{d=-1;break}case 270:{c=-1;break}}i=getRotatedPoint(i,d,c,n)}i=this.getView().getPerimeterPoint(r,i,!1)}else if(h+=o,r.cell.isVertex()){let d=r.style.flipH,c=r.style.flipV;if(l==="north"||l==="south"){const u=d;d=c,c=u}d&&(i.x=2*s.getCenterX()-i.x),c&&(i.y=2*s.getCenterY()-i.y)}if(h!==0&&i){const d=toRadians(h),c=Math.cos(d),u=Math.sin(d);i=getRotatedPoint(i,c,u,n)}}return e&&i&&(i.x=Math.round(i.x),i.y=Math.round(i.y)),i},connectCell(r,t=null,e=!1,i=null){return this.batchUpdate(()=>{const s=r.getTerminal(e);this.cellConnected(r,t,e,i),this.fireEvent(new EventObject(InternalEvent.CONNECT_CELL,"edge",r,"terminal",t,"source",e,"previous",s))}),r},cellConnected(r,t,e=!1,i=null){this.batchUpdate(()=>{const s=r.getTerminal(e);if(this.setConnectionConstraint(r,t,e,i),this.isPortsEnabled()){let n=null;t&&this.isPort(t)&&(n=t.getId(),t=this.getTerminalForPort(t,e));const l=e?"sourcePort":"targetPort";this.setCellStyles(l,n,[r])}this.getDataModel().setTerminal(r,t,e),this.isResetEdgesOnConnect()&&this.resetEdge(r),this.fireEvent(new EventObject(InternalEvent.CELL_CONNECTED,"edge",r,"terminal",t,"source",e,"previous",s))})},disconnectGraph(r){this.batchUpdate(()=>{const{scale:t,translate:e}=this.getView(),i=new Map;for(let s=0;s<r.length;s+=1)i.set(r[s],!0);for(const s of r)if(s.isEdge()){let n=s.getGeometry();if(n){const l=this.getView().getState(s),o=s.getParent(),a=o?this.getView().getState(o):null;if(l&&a){n=n.clone();const h=-a.origin.x,d=-a.origin.y,c=l.absolutePoints;let u=s.getTerminal(!0);if(u&&this.isCellDisconnectable(s,u,!0)){for(;u&&!i.get(u);)u=u.getParent();!u&&c[0]&&(n.setTerminalPoint(new Point(c[0].x/t-e.x+h,c[0].y/t-e.y+d),!0),this.getDataModel().setTerminal(s,null,!0))}let g=s.getTerminal(!1);if(g&&this.isCellDisconnectable(s,g,!1)){for(;g&&!i.get(g);)g=g.getParent();if(!g){const f=c.length-1,p=c[f];p&&(n.setTerminalPoint(new Point(p.x/t-e.x+h,p.y/t-e.y+d),!1),this.getDataModel().setTerminal(s,null,!1))}}this.getDataModel().setGeometry(s,n)}}}})},getConnections(r,t=null){return this.getEdges(r,t,!0,!0,!1)},isConstrainChild(r){return this.isConstrainChildren()&&!!r.getParent()&&!r.getParent().isEdge()},isConstrainChildren(){return this.constrainChildren},setConstrainChildren(r){this.constrainChildren=r},isConstrainRelativeChildren(){return this.constrainRelativeChildren},setConstrainRelativeChildren(r){this.constrainRelativeChildren=r},isDisconnectOnMove(){return this.disconnectOnMove},setDisconnectOnMove(r){this.disconnectOnMove=r},isCellDisconnectable(r,t=null,e=!1){return this.isCellsDisconnectable()&&!this.isCellLocked(r)},isCellsDisconnectable(){return this.cellsDisconnectable},setCellsDisconnectable(r){this.cellsDisconnectable=r},isValidSource(r){return r==null&&this.isAllowDanglingEdges()||r!=null&&(!r.isEdge()||this.isConnectableEdges())&&r.isConnectable()},isValidTarget(r){return this.isValidSource(r)},isValidConnection(r,t){return this.isValidSource(r)&&this.isValidTarget(t)},setConnectable(r){const t=this.getPlugin("ConnectionHandler");t==null||t.setEnabled(r)},isConnectable(){const r=this.getPlugin("ConnectionHandler");return(r==null?void 0:r.isEnabled())??!1}},DragDropMixin={dropEnabled:!1,splitEnabled:!0,autoScroll:!0,isAutoScroll(){return this.autoScroll},autoExtend:!0,isAutoExtend(){return this.autoExtend},isDropEnabled(){return this.dropEnabled},setDropEnabled(r){this.dropEnabled=r},isSplitEnabled(){return this.splitEnabled},setSplitEnabled(r){this.splitEnabled=r},isSplitTarget(r,t=[],e){if(r.isEdge()&&t.length===1&&t[0].isConnectable()&&!this.getEdgeValidationError(r,r.getTerminal(!0),t[0])){const i=r.getTerminal(!0),s=r.getTerminal(!1);return!t[0].isAncestor(i)&&!t[0].isAncestor(s)}return!1}},EdgeMixin={resetEdgesOnResize:!1,isResetEdgesOnResize(){return this.resetEdgesOnResize},resetEdgesOnMove:!1,isResetEdgesOnMove(){return this.resetEdgesOnMove},resetEdgesOnConnect:!0,isResetEdgesOnConnect(){return this.resetEdgesOnConnect},connectableEdges:!1,allowDanglingEdges:!0,cloneInvalidEdges:!1,edgeLabelsMovable:!0,isEdgeLabelsMovable(){return this.edgeLabelsMovable},setEdgeLabelsMovable(r){this.edgeLabelsMovable=r},setAllowDanglingEdges(r){this.allowDanglingEdges=r},isAllowDanglingEdges(){return this.allowDanglingEdges},setConnectableEdges(r){this.connectableEdges=r},isConnectableEdges(){return this.connectableEdges},setCloneInvalidEdges(r){this.cloneInvalidEdges=r},isCloneInvalidEdges(){return this.cloneInvalidEdges},flipEdge(r){return this.alternateEdgeStyle&&this.batchUpdate(()=>{const t=r.getStyle();Object.keys(t).length?this.getDataModel().setStyle(r,this.alternateEdgeStyle):this.getDataModel().setStyle(r,{}),this.resetEdge(r),this.fireEvent(new EventObject(InternalEvent.FLIP_EDGE,{edge:r}))}),r},splitEdge(r,t,e,i=0,s=0,n,l,o=null){o=o??r.getParent();const a=r.getTerminal(!0);return this.batchUpdate(()=>{if(!e){e=this.cloneCell(r);const h=this.getView().getState(r);let d=e.getGeometry();if(d&&h){const c=this.getView().translate,u=this.getView().scale,g=findNearestSegment(h,(i+c.x)*u,(s+c.y)*u);d.points=d.points.slice(0,g),d=r.getGeometry(),d&&(d=d.clone(),d.points=d.points.slice(g),this.getDataModel().setGeometry(r,d))}}this.cellsMoved(t,i,s,!1,!1),this.cellsAdded(t,o,o?o.getChildCount():0,null,null,!0),this.cellsAdded([e],o,o?o.getChildCount():0,a,t[0],!1),this.cellConnected(r,t[0],!0),this.fireEvent(new EventObject(InternalEvent.SPLIT_EDGE,{edge:r,cells:t,newEdge:e,dx:i,dy:s}))}),e},insertEdge(...r){let t,e,i,s,n,l;if(r.length===1&&typeof r[0]=="object"){const a=r[0];t=a.parent,e=a.id,i=a.value,s=a.source,n=a.target,l=a.style}else[t,e,i,s,n,l]=r;const o=this.createEdge(t,e,i,s,n,l);return this.addEdge(o,t,s,n)},createEdge(r=null,t,e,i=null,s=null,n={}){const l=new Cell(e,new Geometry,n);return l.setId(t),l.setEdge(!0),l.geometry.relative=!0,l},addEdge(r,t=null,e=null,i=null,s=null){return this.addCell(r,t,s,e,i)},addAllEdges(r){const t=r.slice();return removeDuplicates(t.concat(this.getAllEdges(r)))},getAllEdges(r){let t=[];if(r)for(let e=0;e<r.length;e+=1){const i=r[e].getEdgeCount();for(let n=0;n<i;n++)t.push(r[e].getEdgeAt(n));const s=r[e].getChildren();t=t.concat(this.getAllEdges(s))}return t},getIncomingEdges(r,t=null){return this.getEdges(r,t,!0,!1,!1)},getOutgoingEdges(r,t=null){return this.getEdges(r,t,!1,!0,!1)},getEdges(r,t=null,e=!0,i=!0,s=!0,n=!1){let l=[];const o=r.isCollapsed(),a=r.getChildCount();for(let d=0;d<a;d+=1){const c=r.getChildAt(d);(o||!c.isVisible())&&(l=l.concat(c.getEdges(e,i)))}l=l.concat(r.getEdges(e,i));const h=[];for(let d=0;d<l.length;d+=1){const c=this.getView().getState(l[d]),u=c?c.getVisibleTerminal(!0):this.getView().getVisibleTerminal(l[d],!0),g=c?c.getVisibleTerminal(!1):this.getView().getVisibleTerminal(l[d],!1);(s&&u===g||u!==g&&(e&&g===r&&(!t||this.isValidAncestor(u,t,n))||i&&u===r&&(!t||this.isValidAncestor(g,t,n))))&&h.push(l[d])}return h},getChildEdges(r){return this.getChildCells(r,!1,!0)},getEdgesBetween(r,t,e=!1){const i=this.getEdges(r),s=[];for(let n=0;n<i.length;n+=1){const l=this.getView().getState(i[n]),o=l?l.getVisibleTerminal(!0):this.getView().getVisibleTerminal(i[n],!0),a=l?l.getVisibleTerminal(!1):this.getView().getVisibleTerminal(i[n],!1);(o===r&&a===t||!e&&o===t&&a===r)&&s.push(i[n])}return s},resetEdges(r){const t=new Map;for(let e=0;e<r.length;e+=1)t.set(r[e],!0);this.batchUpdate(()=>{for(let e=0;e<r.length;e+=1){const i=r[e].getEdges();for(let s=0;s<i.length;s++){const n=this.getView().getState(i[s]),l=n?n.getVisibleTerminal(!0):this.getView().getVisibleTerminal(i[s],!0),o=n?n.getVisibleTerminal(!1):this.getView().getVisibleTerminal(i[s],!1);(!t.get(l)||!t.get(o))&&this.resetEdge(i[s])}this.resetEdges(r[e].getChildren())}})},resetEdge(r){let t=r.getGeometry();return t&&t.points&&t.points.length>0&&(t=t.clone(),t.points=[],this.getDataModel().setGeometry(r,t)),r}},EditingMixin={cellsEditable:!0,startEditing(r){this.startEditingAtCell(null,r)},startEditingAtCell(r=null,t){if(!t||!isMultiTouchEvent(t))if(!r)r=this.getSelectionCell(),r&&!this.isCellEditable(r)&&(r=null);else{this.fireEvent(new EventObject(InternalEvent.START_EDITING,{cell:r,event:t}));const e=this.getPlugin("CellEditorHandler");e==null||e.startEditing(r,t),this.fireEvent(new EventObject(InternalEvent.EDITING_STARTED,{cell:r,event:t}))}},getEditingValue(r,t){return this.convertValueToString(r)},stopEditing(r=!1){const t=this.getPlugin("CellEditorHandler");t==null||t.stopEditing(r),this.fireEvent(new EventObject(InternalEvent.EDITING_STOPPED,{cancel:r}))},labelChanged(r,t,e){return this.batchUpdate(()=>{const i=r.value;this.cellLabelChanged(r,t,this.isAutoSizeCell(r)),this.fireEvent(new EventObject(InternalEvent.LABEL_CHANGED,{cell:r,value:t,old:i,event:e}))}),r},cellLabelChanged(r,t,e=!1){this.batchUpdate(()=>{this.getDataModel().setValue(r,t),e&&this.cellSizeUpdated(r,!1)})},isEditing(r=null){const t=this.getPlugin("CellEditorHandler"),e=t==null?void 0:t.getEditingCell();return r?r===e:!!e},isCellEditable(r){return this.isCellsEditable()&&!this.isCellLocked(r)&&(this.getCurrentCellStyle(r).editable??!0)},isCellsEditable(){return this.cellsEditable},setCellsEditable(r){this.cellsEditable=r}},EventsMixin={lastTouchEvent:null,doubleClickCounter:0,lastTouchCell:null,fireDoubleClick:null,tapAndHoldThread:null,lastMouseX:null,lastMouseY:null,isMouseTrigger:null,ignoreMouseEvents:null,mouseMoveRedirect:null,mouseUpRedirect:null,lastEvent:null,escapeEnabled:!0,invokesStopCellEditing:!0,enterStopsCellEditing:!1,isMouseDown:!1,nativeDblClickEnabled:!0,doubleTapEnabled:!0,doubleTapTimeout:500,doubleTapTolerance:25,lastTouchX:0,lastTouchY:0,lastTouchTime:0,tapAndHoldEnabled:!0,tapAndHoldDelay:500,tapAndHoldInProgress:!1,tapAndHoldValid:!1,initialTouchX:0,initialTouchY:0,tolerance:4,isNativeDblClickEnabled(){return this.nativeDblClickEnabled},getEventTolerance(){return this.tolerance},setEventTolerance(r){this.tolerance=r},escape(r){this.fireEvent(new EventObject(InternalEvent.ESCAPE,{event:r}))},click(r){const t=r.getEvent();let e=r.getCell();const i=new EventObject(InternalEvent.CLICK,{event:t,cell:e});if(r.isConsumed()&&i.consume(),this.fireEvent(i),this.isEnabled()&&!isConsumed(t)&&!i.isConsumed()){if(e){if(this.isTransparentClickEvent(t)){let s=!1;const n=this.getCellAt(r.graphX,r.graphY,null,!1,!1,l=>{const o=this.isCellSelected(l.cell);return s=s||o,!s||o||l.cell!==e&&l.cell.isAncestor(e)});n&&(e=n)}}else if(this.isSwimlaneSelectionEnabled()&&(e=this.getSwimlaneAt(r.getGraphX(),r.getGraphY()),e!=null&&(!this.isToggleEvent(t)||!isAltDown(t)))){let s=e,n=[];for(;s!=null;){s=s.getParent();const l=this.getView().getState(s);this.isSwimlane(s)&&l!=null&&n.push(s)}if(n.length>0){n=n.reverse(),n.splice(0,0,e),n.push(e);for(let l=0;l<n.length-1;l+=1)this.isCellSelected(n[l])&&(e=n[this.isToggleEvent(t)?l:l+1])}}e?this.selectCellForEvent(e,t):this.isToggleEvent(t)||this.clearSelection()}return!1},dblClick(r,t=null){const e=new EventObject(InternalEvent.DOUBLE_CLICK,{event:r,cell:t});this.fireEvent(e),this.isEnabled()&&!isConsumed(r)&&!e.isConsumed()&&t&&this.isCellEditable(t)&&!this.isEditing(t)&&(this.startEditingAtCell(t,r),InternalEvent.consume(r))},tapAndHold(r){const t=r.getEvent(),e=new EventObject(InternalEvent.TAP_AND_HOLD,{event:t,cell:r.getCell()}),i=this.getPlugin("PanningHandler"),s=this.getPlugin("ConnectionHandler");if(this.fireEvent(e),e.isConsumed()&&i&&(i.panningTrigger=!1),this.isEnabled()&&!isConsumed(t)&&!e.isConsumed()&&s&&s.isEnabled()){const n=s.marker.getCell(r);if(n){const l=this.getView().getState(n);l&&(s.marker.currentColor=s.marker.validColor,s.marker.markedState=l,s.marker.mark(),s.first=new Point(r.getGraphX(),r.getGraphY()),s.edgeState=s.createEdgeState(r),s.previous=l,s.fireEvent(new EventObject(InternalEvent.START,{state:s.previous})))}}},addMouseListener(r){this.mouseListeners.push(r)},removeMouseListener(r){for(let t=0;t<this.mouseListeners.length;t+=1)if(this.mouseListeners[t]===r){this.mouseListeners.splice(t,1);break}},updateMouseEvent(r,t){const e=convertPoint(this.getContainer(),r.getX(),r.getY());if(r.graphX=e.x-this.getPanDx(),r.graphY=e.y-this.getPanDy(),!r.getCell()&&this.isMouseDown&&t===InternalEvent.MOUSE_MOVE){const i=this.getCellAt(e.x,e.y,null,!0,!0,s=>!s.shape||s.shape.paintBackground!==this.paintBackground||s.style.pointerEvents||s.shape.fill!==NONE);r.state=i?this.getView().getState(i):null}return r},getStateForTouchEvent(r){const t=getClientX(r),e=getClientY(r),i=convertPoint(this.getContainer(),t,e),s=this.getCellAt(i.x,i.y);return s?this.getView().getState(s):null},isEventIgnored(r,t,e){const i=isMouseEvent(t.getEvent());let s=!1;t.getEvent()===this.lastEvent?s=!0:this.lastEvent=t.getEvent();const n=this.getEventSource();return n&&r!==InternalEvent.MOUSE_MOVE?(InternalEvent.removeGestureListeners(n,null,this.mouseMoveRedirect,this.mouseUpRedirect),this.mouseMoveRedirect=null,this.mouseUpRedirect=null,this.setEventSource(null)):!Client.IS_GC&&n&&t.getSource()!==n?s=!0:n&&Client.IS_TOUCH&&r===InternalEvent.MOUSE_DOWN&&!i&&!isPenEvent(t.getEvent())&&(this.setEventSource(t.getSource()),this.mouseMoveRedirect=l=>{this.fireMouseEvent(InternalEvent.MOUSE_MOVE,new InternalMouseEvent(l,this.getStateForTouchEvent(l)))},this.mouseUpRedirect=l=>{this.fireMouseEvent(InternalEvent.MOUSE_UP,new InternalMouseEvent(l,this.getStateForTouchEvent(l)))},InternalEvent.addGestureListeners(n,null,this.mouseMoveRedirect,this.mouseUpRedirect)),this.isSyntheticEventIgnored(r,t,e)&&(s=!0),!isPopupTrigger(this.lastEvent)&&r!==InternalEvent.MOUSE_MOVE&&this.lastEvent.detail===2?!0:(r===InternalEvent.MOUSE_UP&&this.isMouseDown?this.isMouseDown=!1:r===InternalEvent.MOUSE_DOWN&&!this.isMouseDown?(this.isMouseDown=!0,this.isMouseTrigger=i):!s&&((!Client.IS_FF||r!==InternalEvent.MOUSE_MOVE)&&this.isMouseDown&&this.isMouseTrigger!==i||r===InternalEvent.MOUSE_DOWN&&this.isMouseDown||r===InternalEvent.MOUSE_UP&&!this.isMouseDown)&&(s=!0),!s&&r===InternalEvent.MOUSE_DOWN&&(this.lastMouseX=t.getX(),this.lastMouseY=t.getY()),s)},isSyntheticEventIgnored(r,t,e){let i=!1;const s=isMouseEvent(t.getEvent());return this.ignoreMouseEvents&&s&&r!==InternalEvent.MOUSE_MOVE?(this.ignoreMouseEvents=r!==InternalEvent.MOUSE_UP,i=!0):Client.IS_FF&&!s&&r===InternalEvent.MOUSE_UP&&(this.ignoreMouseEvents=!0),i},isEventSourceIgnored(r,t){const e=t.getSource();if(!e)return!0;const i=e.nodeName?e.nodeName.toLowerCase():"",s=!isMouseEvent(t.getEvent())||isLeftMouseButton(t.getEvent());return r===InternalEvent.MOUSE_DOWN&&s&&(i==="select"||i==="option"||i==="input"&&e.type!=="checkbox"&&e.type!=="radio"&&e.type!=="button"&&e.type!=="submit"&&e.type!=="file")},getEventState(r){return r},fireMouseEvent(r,t,e){if(e=e??this,this.isEventSourceIgnored(r,t)){const i=this.getPlugin("TooltipHandler");i&&i.hide();return}if(t=this.updateMouseEvent(t,r),!this.nativeDblClickEnabled&&!isPopupTrigger(t.getEvent())||this.doubleTapEnabled&&Client.IS_TOUCH&&(isTouchEvent(t.getEvent())||isPenEvent(t.getEvent()))){const i=new Date().getTime();if(r===InternalEvent.MOUSE_DOWN)if(this.lastTouchEvent&&this.lastTouchEvent!==t.getEvent()&&i-this.lastTouchTime<this.doubleTapTimeout&&Math.abs(this.lastTouchX-t.getX())<this.doubleTapTolerance&&Math.abs(this.lastTouchY-t.getY())<this.doubleTapTolerance&&this.doubleClickCounter<2){this.doubleClickCounter+=1;let s=!1;if(r===InternalEvent.MOUSE_UP){if(t.getCell()===this.lastTouchCell&&this.lastTouchCell){this.lastTouchTime=0;const n=this.lastTouchCell;this.lastTouchCell=null,this.dblClick(t.getEvent(),n),s=!0}}else this.fireDoubleClick=!0,this.lastTouchTime=0;if(s){InternalEvent.consume(t.getEvent());return}}else(!this.lastTouchEvent||this.lastTouchEvent!==t.getEvent())&&(this.lastTouchCell=t.getCell(),this.lastTouchX=t.getX(),this.lastTouchY=t.getY(),this.lastTouchTime=i,this.lastTouchEvent=t.getEvent(),this.doubleClickCounter=0);else if((this.isMouseDown||r===InternalEvent.MOUSE_UP)&&this.fireDoubleClick){this.fireDoubleClick=!1;const s=this.lastTouchCell;this.lastTouchCell=null,this.isMouseDown=!1,(s||(isTouchEvent(t.getEvent())||isPenEvent(t.getEvent()))&&(Client.IS_GC||Client.IS_SF))&&Math.abs(this.lastTouchX-t.getX())<this.doubleTapTolerance&&Math.abs(this.lastTouchY-t.getY())<this.doubleTapTolerance?this.dblClick(t.getEvent(),s):InternalEvent.consume(t.getEvent());return}}if(!this.isEventIgnored(r,t,e)){const i=t.getState();if(t.state=i?this.getEventState(i):null,this.fireEvent(new EventObject(InternalEvent.FIRE_MOUSE_EVENT,{eventName:r,event:t})),Client.IS_SF||Client.IS_GC||t.getEvent().target!==this.getContainer()){const n=this.getContainer();if(r===InternalEvent.MOUSE_MOVE&&this.isMouseDown&&this.isAutoScroll()&&!isMultiTouchEvent(t.getEvent()))this.scrollPointToVisible(t.getGraphX(),t.getGraphY(),this.isAutoExtend());else if(r===InternalEvent.MOUSE_UP&&this.isIgnoreScrollbars()&&this.isTranslateToScrollPosition()&&(n.scrollLeft!==0||n.scrollTop!==0)){const o=this.getView().scale,a=this.getView().translate;this.getView().setTranslate(a.x-n.scrollLeft/o,a.y-n.scrollTop/o),n.scrollLeft=0,n.scrollTop=0}const l=this.mouseListeners;t.getEvent().preventDefault||(t.getEvent().returnValue=!0);for(const o of l)switch(r){case InternalEvent.MOUSE_DOWN:{o.mouseDown(e,t);break}case InternalEvent.MOUSE_MOVE:{o.mouseMove(e,t);break}case InternalEvent.MOUSE_UP:{o.mouseUp(e,t);break}}r===InternalEvent.MOUSE_UP&&this.click(t)}if((isTouchEvent(t.getEvent())||isPenEvent(t.getEvent()))&&r===InternalEvent.MOUSE_DOWN&&this.tapAndHoldEnabled&&!this.tapAndHoldInProgress){this.tapAndHoldInProgress=!0,this.initialTouchX=t.getGraphX(),this.initialTouchY=t.getGraphY();const n=()=>{this.tapAndHoldValid&&this.tapAndHold(t),this.tapAndHoldInProgress=!1,this.tapAndHoldValid=!1};this.tapAndHoldThread&&window.clearTimeout(this.tapAndHoldThread),this.tapAndHoldThread=window.setTimeout(n,this.tapAndHoldDelay),this.tapAndHoldValid=!0}else r===InternalEvent.MOUSE_UP?(this.tapAndHoldInProgress=!1,this.tapAndHoldValid=!1):this.tapAndHoldValid&&(this.tapAndHoldValid=Math.abs(this.initialTouchX-t.getGraphX())<this.tolerance&&Math.abs(this.initialTouchY-t.getGraphY())<this.tolerance);const s=this.getPlugin("CellEditorHandler");r===InternalEvent.MOUSE_DOWN&&this.isEditing()&&!(s!=null&&s.isEventSource(t.getEvent()))&&this.stopEditing(!this.isInvokesStopCellEditing()),this.consumeMouseEvent(r,t,e)}},consumeMouseEvent(r,t,e){r===InternalEvent.MOUSE_DOWN&&isTouchEvent(t.getEvent())&&t.consume(!1)},fireGestureEvent(r,t=null){this.lastTouchTime=0,this.fireEvent(new EventObject(InternalEvent.GESTURE,{event:r,cell:t}))},sizeDidChange(){const r=this.getGraphBounds(),t=this.getBorder();let e=Math.max(0,r.x)+r.width+2*t,i=Math.max(0,r.y)+r.height+2*t;const s=this.getMinimumContainerSize();if(s&&(e=Math.max(e,s.width),i=Math.max(i,s.height)),this.isResizeContainer()&&this.doResizeContainer(e,i),this.isPreferPageSize()||this.isPageVisible()){const o=this.getPreferredPageSize(r,Math.max(1,e),Math.max(1,i));e=o.width*this.getView().scale,i=o.height*this.getView().scale}const n=this.getMinimumGraphSize();n&&(e=Math.max(e,n.width*this.getView().scale),i=Math.max(i,n.height*this.getView().scale)),e=Math.ceil(e),i=Math.ceil(i);const l=this.getView().getDrawPane().ownerSVGElement;l&&(l.style.minWidth=`${Math.max(1,e)}px`,l.style.minHeight=`${Math.max(1,i)}px`,l.style.width="100%",l.style.height="100%"),this.updatePageBreaks(this.isPageBreaksVisible(),e,i),this.fireEvent(new EventObject(InternalEvent.SIZE,{bounds:r}))},isCloneEvent(r){return isControlDown(r)},isTransparentClickEvent(r){return!1},isToggleEvent(r){return Client.IS_MAC?isMetaDown(r):isControlDown(r)},isGridEnabledEvent(r){return!isAltDown(r)},isConstrainedEvent(r){return isShiftDown(r)},isIgnoreTerminalEvent(r){return!1},getPointForEvent(r,t=!0){const e=convertPoint(this.getContainer(),getClientX(r),getClientY(r)),i=this.getView().scale,s=this.getView().translate,n=t?this.getGridSize()/2:0;return e.x=this.snap(e.x/i-s.x-n),e.y=this.snap(e.y/i-s.y-n),e},isEscapeEnabled(){return this.escapeEnabled},setEscapeEnabled(r){this.escapeEnabled=r},isInvokesStopCellEditing(){return this.invokesStopCellEditing},setInvokesStopCellEditing(r){this.invokesStopCellEditing=r},isEnterStopsCellEditing(){return this.enterStopsCellEditing},setEnterStopsCellEditing(r){this.enterStopsCellEditing=r},getCursorForMouseEvent(r){const t=r.getCell();return t?this.getCursorForCell(t):null}},FoldingMixin={collapseExpandResource:isI18nEnabled()?"collapse-expand":"",getCollapseExpandResource(){return this.collapseExpandResource},isFoldingEnabled(){return this.options.foldingEnabled},getFoldableCells(r,t=!1){return this.getDataModel().filterCells(r,e=>this.isCellFoldable(e,t))},isCellFoldable(r,t){return r.getChildCount()>0&&(this.getCurrentCellStyle(r).foldable??!0)},getFoldingImage(r){if(r!=null&&this.isFoldingEnabled()&&!r.cell.isEdge()){const t=r.cell.isCollapsed();if(this.isCellFoldable(r.cell,!t))return t?this.options.collapsedImage:this.options.expandedImage}return null},foldCells(r=!1,t=!1,e=null,i=!1,s=null){return e==null&&(e=this.getFoldableCells(this.getSelectionCells(),r)),this.stopEditing(!1),this.batchUpdate(()=>{this.cellsFolded(e,r,t,i),this.fireEvent(new EventObject(InternalEvent.FOLD_CELLS,"collapse",r,"recurse",t,"cells",e))}),e},cellsFolded(r=null,t=!1,e=!1,i=!1){r!=null&&r.length>0&&this.batchUpdate(()=>{for(let s=0;s<r.length;s+=1)if((!i||this.isCellFoldable(r[s],t))&&t!==r[s].isCollapsed()){if(this.getDataModel().setCollapsed(r[s],t),this.swapBounds(r[s],t),this.isExtendParent(r[s])&&this.extendParent(r[s]),e){const n=r[s].getChildren();this.cellsFolded(n,t,e)}this.constrainChild(r[s])}this.fireEvent(new EventObject(InternalEvent.CELLS_FOLDED,{cells:r,collapse:t,recurse:e}))})},swapBounds(r,t=!1){let e=r.getGeometry();e!=null&&(e=e.clone(),this.updateAlternateBounds(r,e,t),e.swap(),this.getDataModel().setGeometry(r,e))},updateAlternateBounds(r=null,t=null,e=!1){if(r!=null&&t!=null){const i=this.getCurrentCellStyle(r);if(t.alternateBounds==null){let s=t;if(this.options.collapseToPreferredSize){const n=this.getPreferredSizeForCell(r);if(n!=null){s=n;const l=i.startSize??0;l>0&&(s.height=Math.max(s.height,l))}}t.alternateBounds=new Rectangle(0,0,s.width,s.height)}if(t.alternateBounds!=null){t.alternateBounds.x=t.x,t.alternateBounds.y=t.y;const s=toRadians(i.rotation||0);if(s!==0){const n=t.alternateBounds.getCenterX()-t.getCenterX(),l=t.alternateBounds.getCenterY()-t.getCenterY(),o=Math.cos(s),a=Math.sin(s),h=o*n-a*l,d=a*n+o*l;t.alternateBounds.x+=h-n,t.alternateBounds.y+=d-l}}}}},GroupingMixin={groupCells(r,t=0,e){e||(e=sortCells(this.getSelectionCells(),!0)),e||(e=this.getCellsForGroup(e)),r==null&&(r=this.createGroupCell(e));const i=this.getBoundsForGroup(r,e,t);if(e.length>1&&i!=null){let s=r.getParent();s==null&&(s=e[0].getParent()),this.batchUpdate(()=>{r.getGeometry()==null&&this.getDataModel().setGeometry(r,new Geometry);let n=s.getChildCount();this.cellsAdded([r],s,n,null,null,!1,!1,!1),n=r.getChildCount(),this.cellsAdded(e,r,n,null,null,!1,!1,!1),this.cellsMoved(e,-i.x,-i.y,!1,!1,!1),this.cellsResized([r],[i],!1),this.fireEvent(new EventObject(InternalEvent.GROUP_CELLS,{group:r,border:t,cells:e}))})}return r},getCellsForGroup(r){const t=[];if(r!=null&&r.length>0){const e=r[0].getParent();t.push(r[0]);for(let i=1;i<r.length;i+=1)r[i].getParent()===e&&t.push(r[i])}return t},getBoundsForGroup(r,t,e){const i=this.getBoundingBoxFromGeometry(t,!0);if(i!=null){if(this.isSwimlane(r)){const s=this.getStartSize(r);i.x-=s.width,i.y-=s.height,i.width+=s.width,i.height+=s.height}e!=null&&(i.x-=e,i.y-=e,i.width+=2*e,i.height+=2*e)}return i},createGroupCell(r){const t=new Cell("");return t.setVertex(!0),t.setConnectable(!1),t},ungroupCells(r){let t=[];return r==null&&(r=this.getCellsForUngroup()),r!=null&&r.length>0&&this.batchUpdate(()=>{const e=r;for(let i=0;i<e.length;i+=1){let s=e[i].getChildren();if(s!=null&&s.length>0){s=s.slice();const n=e[i].getParent(),l=n.getChildCount();this.cellsAdded(s,n,l,null,null,!0),t=t.concat(s);for(const o of s){const a=this.getView().getState(o);let h=o.getGeometry();a!=null&&h!=null&&h.relative&&(h=h.clone(),h.x=a.origin.x,h.y=a.origin.y,h.relative=!1,this.getDataModel().setGeometry(o,h))}}}this.removeCellsAfterUngroup(e),this.fireEvent(new EventObject(InternalEvent.UNGROUP_CELLS,{cells:r}))}),t},getCellsForUngroup(){const r=this.getSelectionCells(),t=[];for(let e=0;e<r.length;e+=1)r[e].isVertex()&&r[e].getChildCount()>0&&t.push(r[e]);return t},removeCellsAfterUngroup(r){this.cellsRemoved(this.addAllEdges(r))},removeCellsFromParent(r){return r==null&&(r=this.getSelectionCells()),this.batchUpdate(()=>{const t=this.getDefaultParent(),e=t.getChildCount();this.cellsAdded(r,t,e,null,null,!0),this.fireEvent(new EventObject(InternalEvent.REMOVE_CELLS_FROM_PARENT,{cells:r}))}),r},updateGroupBounds(r,t=0,e=!1,i=0,s=0,n=0,l=0){return r==null&&(r=this.getSelectionCells()),t=t??0,e=e??!1,i=i??0,s=s??0,n=n??0,l=l??0,this.batchUpdate(()=>{for(let o=r.length-1;o>=0;o--){let a=r[o].getGeometry();if(a==null)continue;const h=this.getChildCells(r[o]);if(h!=null&&h.length>0){const d=this.getBoundingBoxFromGeometry(h,!0);if(d!=null&&d.width>0&&d.height>0){const c=this.isSwimlane(r[o])?this.getActualStartSize(r[o],!0):new Rectangle;a=a.clone(),e&&(a.x=Math.round(a.x+d.x-t-c.x-l),a.y=Math.round(a.y+d.y-t-c.y-i)),a.width=Math.round(d.width+2*t+c.x+l+s+c.width),a.height=Math.round(d.height+2*t+c.y+i+n+c.height),this.getDataModel().setGeometry(r[o],a),this.moveCells(h,t+c.x-d.x+l,t+c.y-d.y+i)}}}}),r},enterGroup(r){r=r||this.getSelectionCell(),r!=null&&this.isValidRoot(r)&&(this.getView().setCurrentRoot(r),this.clearSelection())},exitGroup(){const r=this.getDataModel().getRoot(),t=this.getCurrentRoot();if(t!=null){let e=t.getParent();for(;e!==r&&!this.isValidRoot(e)&&e.getParent()!==r;)e=e.getParent();e===r||e.getParent()===r?this.getView().setCurrentRoot(null):this.getView().setCurrentRoot(e),this.getView().getState(t)!=null&&this.setSelectionCell(t)}}},LabelMixin={getLabel(r){let t="";return this.isLabelsVisible()&&r&&((this.getCurrentCellStyle(r).noLabel??!1)||(t=this.convertValueToString(r))),t},isHtmlLabel(r){return this.isHtmlLabels()},labelsVisible:!0,isLabelsVisible(){return this.labelsVisible},htmlLabels:!1,isHtmlLabels(){return this.htmlLabels},setHtmlLabels(r){this.htmlLabels=r},isWrapping(r){return this.getCurrentCellStyle(r).whiteSpace==="wrap"},isLabelClipped(r){return this.getCurrentCellStyle(r).overflow==="hidden"},isLabelMovable(r){return!this.isCellLocked(r)&&(r.isEdge()&&this.isEdgeLabelsMovable()||r.isVertex()&&this.isVertexLabelsMovable())}},OrderMixin={orderCells(r=!1,t){return t||(t=this.getSelectionCells()),t||(t=sortCells(this.getSelectionCells(),!0)),this.batchUpdate(()=>{this.cellsOrdered(t,r);const e=new EventObject(InternalEvent.ORDER_CELLS,"back",r,"cells",t);this.fireEvent(e)}),t},cellsOrdered(r,t=!1){this.batchUpdate(()=>{for(let e=0;e<r.length;e+=1){const i=r[e].getParent();t?this.getDataModel().add(i,r[e],e):this.getDataModel().add(i,r[e],i?i.getChildCount()-1:0)}this.fireEvent(new EventObject(InternalEvent.CELLS_ORDERED,{back:t,cells:r}))})}};class CellOverlay extends EventSource{constructor(t,e=null,i="right",s="bottom",n=new Point,l="help"){super(),this.align="right",this.verticalAlign="bottom",this.offset=new Point,this.cursor="help",this.defaultOverlap=.5,this.image=t,this.tooltip=e,this.align=i,this.verticalAlign=s,this.offset=n,this.cursor=l}getBounds(t){const e=t.cell.isEdge(),i=t.view.scale;let s=null;const n=this.image,l=n.width,o=n.height;if(e){const a=t.absolutePoints;if(a.length%2===1)s=a[Math.floor(a.length/2)];else{const h=a.length/2,d=a[h-1],c=a[h];s=new Point(d.x+(c.x-d.x)/2,d.y+(c.y-d.y)/2)}}else{switch(s=new Point,this.align){case"left":{s.x=t.x;break}case"center":{s.x=t.x+t.width/2;break}case"right":{s.x=t.x+t.width;break}default:throw new Error}switch(this.verticalAlign){case"top":{s.y=t.y;break}case"middle":{s.y=t.y+t.height/2;break}case"bottom":{s.y=t.y+t.height;break}default:throw new Error}}return new Rectangle(Math.round(s.x-(l*this.defaultOverlap-this.offset.x)*i),Math.round(s.y-(o*this.defaultOverlap-this.offset.y)*i),l*i,o*i)}toString(){return this.tooltip}}const OverlaysMixin={addCellOverlay(r,t){r.overlays.push(t);const e=this.getView().getState(r);return e&&this.getCellRenderer().redraw(e),this.fireEvent(new EventObject(InternalEvent.ADD_OVERLAY,{cell:r,overlay:t})),t},getCellOverlays(r){return r.overlays},removeCellOverlay(r,t=null){if(!t)this.removeCellOverlays(r);else{const e=r.overlays.indexOf(t);if(e>=0){r.overlays.splice(e,1);const i=this.getView().getState(r);i&&this.getCellRenderer().redraw(i),this.fireEvent(new EventObject(InternalEvent.REMOVE_OVERLAY,{cell:r,overlay:t}))}else t=null}return t},removeCellOverlays(r){const{overlays:t}=r;r.overlays=[];const e=this.getView().getState(r);e&&this.getCellRenderer().redraw(e);for(let i=0;i<t.length;i+=1)this.fireEvent(new EventObject(InternalEvent.REMOVE_OVERLAY,"cell",r,"overlay",t[i]));return t},clearCellOverlays(r=null){if(r=r??this.getDataModel().getRoot(),!r)return;this.removeCellOverlays(r);const t=r.getChildCount();for(let e=0;e<t;e+=1){const i=r.getChildAt(e);this.clearCellOverlays(i)}},setCellWarning(r,t=null,e,i=!1){if(e=e??this.getWarningImage(),t&&t.length>0){const s=new CellOverlay(e,`<font color=red>${t}</font>`);return i&&s.addListener(InternalEvent.CLICK,(n,l)=>{this.isEnabled()&&this.setSelectionCell(r)}),this.addCellOverlay(r,s)}return this.removeCellOverlays(r),null}};class PolylineShape extends Shape{constructor(t,e,i=1){super(),this.points=t,this.stroke=e,this.strokeWidth=i}getRotation(){return 0}getShapeRotation(){return 0}isPaintBoundsInverted(){return!1}paintEdgeShape(t,e){var s;const i=t.pointerEventsValue;t.pointerEventsValue="stroke",(s=this.style)!=null&&s.curved?this.paintCurvedLine(t,e):this.paintLine(t,e,this.isRounded),t.pointerEventsValue=i}paintLine(t,e,i){t.begin(),this.addPoints(t,e,i,this.getBaseArcSize(),!1),t.stroke()}paintCurvedLine(t,e){t.begin();const i=e[0],s=e.length;t.moveTo(i.x,i.y);for(let o=1;o<s-2;o+=1){const a=e[o],h=e[o+1],d=(a.x+h.x)/2,c=(a.y+h.y)/2;t.quadTo(a.x,a.y,d,c)}const n=e[s-2],l=e[s-1];t.quadTo(n.x,n.y,l.x,l.y),t.stroke()}}const PageBreaksMixin={horizontalPageBreaks:null,verticalPageBreaks:null,updatePageBreaks(r,t,e){const{scale:i,translate:s}=this.getView(),n=this.getPageFormat(),l=i*this.getPageScale(),o=new Rectangle(0,0,n.width*l,n.height*l),a=Rectangle.fromRectangle(this.getGraphBounds());a.width=Math.max(1,a.width),a.height=Math.max(1,a.height),o.x=Math.floor((a.x-s.x*i)/o.width)*o.width+s.x*i,o.y=Math.floor((a.y-s.y*i)/o.height)*o.height+s.y*i,a.width=Math.ceil((a.width+(a.x-o.x))/o.width)*o.width,a.height=Math.ceil((a.height+(a.y-o.y))/o.height)*o.height,r=r&&Math.min(o.width,o.height)>this.getMinPageBreakDist();const h=r?Math.ceil(a.height/o.height)+1:0,d=r?Math.ceil(a.width/o.width)+1:0,c=(d-1)*o.width,u=(h-1)*o.height;this.horizontalPageBreaks==null&&h>0&&(this.horizontalPageBreaks=[]),this.verticalPageBreaks==null&&d>0&&(this.verticalPageBreaks=[]);const g=f=>{if(!f)return;const p=f===this.horizontalPageBreaks?h:d;for(let y=0;y<=p;y+=1){const v=f===this.horizontalPageBreaks?[new Point(Math.round(o.x),Math.round(o.y+y*o.height)),new Point(Math.round(o.x+c),Math.round(o.y+y*o.height))]:[new Point(Math.round(o.x+y*o.width),Math.round(o.y)),new Point(Math.round(o.x+y*o.width),Math.round(o.y+u))];if(f[y]!=null)f[y].points=v,f[y].redraw();else{const S=new PolylineShape(v,this.getPageBreakColor());S.dialect=this.getDialect(),S.pointerEvents=!1,S.isDashed=this.isPageBreakDashed(),S.init(this.getView().backgroundPane),S.redraw(),f[y]=S}}for(let y=p;y<f.length;y+=1)f[y].destroy();f.splice(p,f.length-p)};g(this.horizontalPageBreaks),g(this.verticalPageBreaks)}},PanningMixin={shiftPreview1:null,shiftPreview2:null,useScrollbarsForPanning:!0,isUseScrollbarsForPanning(){return this.useScrollbarsForPanning},timerAutoScroll:!1,isTimerAutoScroll(){return this.timerAutoScroll},allowAutoPanning:!1,isAllowAutoPanning(){return this.allowAutoPanning},panDx:0,getPanDx(){return this.panDx},setPanDx(r){this.panDx=r},panDy:0,getPanDy(){return this.panDy},setPanDy(r){this.panDy=r},panGraph(r,t){const e=this.getContainer();if(this.useScrollbarsForPanning&&hasScrollbars(e))e.scrollLeft=-r,e.scrollTop=-t;else{const i=this.getView().getCanvas();if(r===0&&t===0){if(i.removeAttribute("transform"),this.shiftPreview1){let s=this.shiftPreview1.firstChild;for(;s;){const l=s.nextSibling;e.appendChild(s),s=l}this.shiftPreview1.parentNode&&this.shiftPreview1.parentNode.removeChild(this.shiftPreview1),this.shiftPreview1=null,e.appendChild(i.parentNode);const n=this.shiftPreview2;for(s=n.firstChild;s;){const l=s.nextSibling;e.appendChild(s),s=l}n.parentNode&&n.parentNode.removeChild(n),this.shiftPreview2=null}}else{if(i.setAttribute("transform",`translate(${r},${t})`),!this.shiftPreview1){this.shiftPreview1=document.createElement("div"),this.shiftPreview1.style.position="absolute",this.shiftPreview1.style.overflow="visible",this.shiftPreview2=document.createElement("div"),this.shiftPreview2.style.position="absolute",this.shiftPreview2.style.overflow="visible";let s=this.shiftPreview1,n=e.firstChild;for(;n;){const l=n.nextSibling;n!==i.parentNode?s.appendChild(n):s=this.shiftPreview2,n=l}this.shiftPreview1.firstChild&&e.insertBefore(this.shiftPreview1,i.parentNode),this.shiftPreview2.firstChild&&e.appendChild(this.shiftPreview2)}this.shiftPreview1.style.left=`${r}px`,this.shiftPreview1.style.top=`${t}px`,this.shiftPreview2&&(this.shiftPreview2.style.left=`${r}px`,this.shiftPreview2.style.top=`${t}px`)}this.panDx=r,this.panDy=t,this.fireEvent(new EventObject(InternalEvent.PAN))}},scrollCellToVisible(r,t=!1){const e=-this.getView().translate.x,i=-this.getView().translate.y,s=this.getView().getState(r);if(s){const n=new Rectangle(e+s.x,i+s.y,s.width,s.height);if(t&&this.getContainer()){const o=this.getContainer().clientWidth,a=this.getContainer().clientHeight;n.x=n.getCenterX()-o/2,n.width=o,n.y=n.getCenterY()-a/2,n.height=a}const l=new Point(this.getView().translate.x,this.getView().translate.y);if(this.scrollRectToVisible(n)){const o=new Point(this.getView().translate.x,this.getView().translate.y);this.getView().translate.x=l.x,this.getView().translate.y=l.y,this.getView().setTranslate(o.x,o.y)}}},scrollRectToVisible(r){let t=!1;const e=this.getContainer(),i=e.offsetWidth,s=e.offsetHeight,n=Math.min(i,r.width),l=Math.min(s,r.height);if(hasScrollbars(e)){r.x+=this.getView().translate.x,r.y+=this.getView().translate.y;let o=e.scrollLeft-r.x;const a=Math.max(o-e.scrollLeft,0);o>0?e.scrollLeft-=o+2:(o=r.x+n-e.scrollLeft-e.clientWidth,o>0&&(e.scrollLeft+=o+2));let h=e.scrollTop-r.y;const d=Math.max(0,h-e.scrollTop);h>0?e.scrollTop-=h+2:(h=r.y+l-e.scrollTop-e.clientHeight,h>0&&(e.scrollTop+=h+2)),!this.useScrollbarsForPanning&&(a!=0||d!=0)&&this.getView().setTranslate(a,d)}else{const o=-this.getView().translate.x,a=-this.getView().translate.y,h=this.getView().scale;if(r.x+n>o+i&&(this.getView().translate.x-=(r.x+n-i-o)/h,t=!0),r.y+l>a+s&&(this.getView().translate.y-=(r.y+l-s-a)/h,t=!0),r.x<o&&(this.getView().translate.x+=(o-r.x)/h,t=!0),r.y<a&&(this.getView().translate.y+=(a-r.y)/h,t=!0),t){this.getView().refresh();const d=this.getPlugin("SelectionCellsHandler");d&&d.refresh()}}return t},setPanning(r){const t=this.getPlugin("PanningHandler");t&&(t.panningEnabled=r)}},PortsMixin={portsEnabled:!0,isPort(r){return!1},getTerminalForPort(r,t=!1){return r.getParent()},isPortsEnabled(){return this.portsEnabled},setPortsEnabled(r){this.portsEnabled=r}},SelectionMixin={selectionModel:null,getSelectionModel(){return this.selectionModel},setSelectionModel(r){this.selectionModel=r},isCellSelected(r){return this.selectionModel.isSelected(r)},isSelectionEmpty(){return this.selectionModel.isEmpty()},clearSelection(){this.selectionModel.clear()},getSelectionCount(){return this.selectionModel.cells.length},getSelectionCell(){return this.selectionModel.cells[0]},getSelectionCells(){return this.selectionModel.cells.slice()},setSelectionCell(r){this.selectionModel.setCell(r)},setSelectionCells(r){this.selectionModel.setCells(r)},addSelectionCell(r){this.selectionModel.addCell(r)},addSelectionCells(r){this.selectionModel.addCells(r)},removeSelectionCell(r){this.selectionModel.removeCell(r)},removeSelectionCells(r){this.selectionModel.removeCells(r)},selectRegion(r,t){const e=this.getCells(r.x,r.y,r.width,r.height);return this.selectCellsForEvent(e,t),e},selectNextCell(){this.selectCell(!0)},selectPreviousCell(){this.selectCell()},selectParentCell(){this.selectCell(!1,!0)},selectChildCell(){this.selectCell(!1,!1,!0)},selectCell(r=!1,t=!1,e=!1){const i=this.selectionModel.cells.length>0?this.selectionModel.cells[0]:null;this.selectionModel.cells.length>1&&this.selectionModel.clear();const s=i?i.getParent():this.getDefaultParent(),n=s.getChildCount();if(!i&&n>0){const l=s.getChildAt(0);this.setSelectionCell(l)}else if(s&&(!i||t)&&this.getView().getState(s)&&s.getGeometry())this.getCurrentRoot()!==s&&this.setSelectionCell(s);else if(i&&e){if(i.getChildCount()>0){const o=i.getChildAt(0);this.setSelectionCell(o)}}else if(n>0){let l=s.getIndex(i);if(r){l++;const o=s.getChildAt(l%n);this.setSelectionCell(o)}else{l--;const o=l<0?n-1:l,a=s.getChildAt(o);this.setSelectionCell(a)}}},selectAll(r,t=!1){r=r??this.getDefaultParent();const e=t?r.filterDescendants(i=>i!==r&&!!this.getView().getState(i)):r.getChildren();this.setSelectionCells(e)},selectVertices(r,t=!1){this.selectCells(!0,!1,r,t)},selectEdges(r){this.selectCells(!1,!0,r)},selectCells(r=!1,t=!1,e,i=!1){e=e??this.getDefaultParent();const s=l=>{const o=l.getParent();return!!this.getView().getState(l)&&((i||l.getChildCount()===0)&&l.isVertex()&&r&&o&&!o.isEdge()||l.isEdge()&&t)},n=e.filterDescendants(s);this.setSelectionCells(n)},selectCellForEvent(r,t){const e=this.isCellSelected(r);this.isToggleEvent(t)?e?this.removeSelectionCell(r):this.addSelectionCell(r):(!e||this.getSelectionCount()!==1)&&this.setSelectionCell(r)},selectCellsForEvent(r,t){this.isToggleEvent(t)?this.addSelectionCells(r):this.setSelectionCells(r)},isSiblingSelected(r){const t=r.getParent(),e=t.getChildCount();for(let i=0;i<e;i+=1){const s=t.getChildAt(i);if(r!==s&&this.isCellSelected(s))return!0}return!1},getSelectionCellsForChanges(r,t=null){const e=new Map,i=[],s=n=>{if(!e.has(n)&&this.getDataModel().contains(n))if(n.isEdge()||n.isVertex())e.set(n,!0),i.push(n);else{const l=n.getChildCount();for(let o=0;o<l;o+=1)s(n.getChildAt(o))}};for(let n=0;n<r.length;n+=1){const l=r[n];if(l.constructor!==RootChange&&(!t||!t(l))){let o=null;l instanceof ChildChange?o=l.child:l.cell&&l.cell instanceof Cell&&(o=l.cell),o&&s(o)}}return i},updateSelection(){const r=this.getSelectionCells(),t=[];for(const e of r)if(!this.getDataModel().contains(e)||!e.isVisible())t.push(e);else{let i=e.getParent();for(;i&&i!==this.getView().currentRoot;){if(i.isCollapsed()||!i.isVisible()){t.push(e);break}i=i.getParent()}}this.removeSelectionCells(t)}},SnapMixin={snapTolerance:0,getSnapTolerance(){return this.snapTolerance},gridSize:10,gridEnabled:!0,snap(r){return this.gridEnabled&&(r=Math.round(r/this.gridSize)*this.gridSize),r},snapDelta(r,t,e=!1,i=!1,s=!1){const n=this.getView().translate,l=this.getView().scale;if(!e&&this.gridEnabled){const o=this.gridSize*l*.5;if(!i){const a=t.x-(this.snap(t.x/l-n.x)+n.x)*l;Math.abs(r.x-a)<o?r.x=0:r.x=this.snap(r.x/l)*l-a}if(!s){const a=t.y-(this.snap(t.y/l-n.y)+n.y)*l;Math.abs(r.y-a)<o?r.y=0:r.y=this.snap(r.y/l)*l-a}}else{const o=.5*l;if(!i){const a=t.x-(Math.round(t.x/l-n.x)+n.x)*l;Math.abs(r.x-a)<o?r.x=0:r.x=Math.round(r.x/l)*l-a}if(!s){const a=t.y-(Math.round(t.y/l-n.y)+n.y)*l;Math.abs(r.y-a)<o?r.y=0:r.y=Math.round(r.y/l)*l-a}}return r},isGridEnabled(){return this.gridEnabled},setGridEnabled(r){this.gridEnabled=r},getGridSize(){return this.gridSize},setGridSize(r){this.gridSize=r}},SwimlaneMixin={swimlaneSelectionEnabled:!0,swimlaneNesting:!0,swimlaneIndicatorColorAttribute:"fillColor",getSwimlane(r=null){for(;r&&!this.isSwimlane(r);)r=r.getParent();return r},getSwimlaneAt(r,t,e){if(e||(e=this.getCurrentRoot(),e||(e=this.getDataModel().getRoot())),e){const i=e.getChildCount();for(let s=0;s<i;s+=1){const n=e.getChildAt(s);if(n){const l=this.getSwimlaneAt(r,t,n);if(l!=null)return l;if(n.isVisible()&&this.isSwimlane(n)){const o=this.getView().getState(n);if(o&&this.intersects(o,r,t))return n}}}}return null},hitsSwimlaneContent(r,t,e){const i=this.getView().getState(r),s=this.getStartSize(r);if(i){const n=this.getView().getScale();if(t-=i.x,e-=i.y,s.width>0&&t>0&&t>s.width*n||s.height>0&&e>0&&e>s.height*n)return!0}return!1},getStartSize(r,t=!1){const e=new Rectangle,i=this.getCurrentCellStyle(r,t),s=i.startSize??StyleDefaultsConfig.startSize;return i.horizontal??!0?e.height=s:e.width=s,e},getSwimlaneDirection(r){const t=r.direction??"east",e=r.flipH,i=r.flipV;let n=r.horizontal??!0?0:3;switch(t){case"north":{n--;break}case"west":{n+=2;break}case"south":{n+=1;break}}const l=mod(n,2);return e&&l===1&&(n+=2),i&&l===0&&(n+=2),["north","east","south","west"][mod(n,4)]},getActualStartSize(r,t=!1){const e=new Rectangle;if(this.isSwimlane(r,t)){const i=this.getCurrentCellStyle(r,t),s=i.startSize??StyleDefaultsConfig.startSize;switch(this.getSwimlaneDirection(i)){case"north":{e.y=s;break}case"west":{e.x=s;break}case"south":{e.height=s;break}default:e.width=s}}return e},isSwimlane(r,t=!1){return r&&r.getParent()!==this.getDataModel().getRoot()&&!r.isEdge()?this.getCurrentCellStyle(r,t).shape==="swimlane":!1},isValidDropTarget(r,t,e){return r&&(this.isSplitEnabled()&&this.isSplitTarget(r,t,e)||!r.isEdge()&&(this.isSwimlane(r)||r.getChildCount()>0&&!r.isCollapsed()))},getDropTarget(r,t,e=null,i=!1){if(!this.isSwimlaneNesting()){for(let o=0;o<r.length;o+=1)if(this.isSwimlane(r[o]))return null}const s=convertPoint(this.getContainer(),getClientX(t),getClientY(t));s.x-=this.getPanDx(),s.y-=this.getPanDy();const n=this.getSwimlaneAt(s.x,s.y);if(!e)e=n;else if(n){let o=n.getParent();for(;o&&this.isSwimlane(o)&&o!==e;)o=o.getParent();o===e&&(e=n)}for(;e&&!this.isValidDropTarget(e,r,t)&&!this.getDataModel().isLayer(e);)e=e.getParent();let l=e;if(!i)for(;l&&!r.includes(l);)l=l.getParent();return!this.getDataModel().isLayer(e)&&!l?e:null},isSwimlaneNesting(){return this.swimlaneNesting},setSwimlaneNesting(r){this.swimlaneNesting=r},isSwimlaneSelectionEnabled(){return this.swimlaneSelectionEnabled},setSwimlaneSelectionEnabled(r){this.swimlaneSelectionEnabled=r}},TerminalMixin={isTerminalPointMovable(r,t){return!0},getOpposites(r,t=null,e=!0,i=!0){const s=[],n=new Map;for(let l=0;l<r.length;l+=1){const o=this.getView().getState(r[l]),a=o?o.getVisibleTerminal(!0):this.getView().getVisibleTerminal(r[l],!0),h=o?o.getVisibleTerminal(!1):this.getView().getVisibleTerminal(r[l],!1);a===t&&h&&h!==t&&i?n.has(h)||(n.set(h,!0),s.push(h)):h===t&&a&&a!==t&&e&&(n.has(a)||(n.set(a,!0),s.push(a)))}return s}},ValidationMixin={validationAlert(r){alert(r)},isEdgeValid(r,t,e){return!this.getEdgeValidationError(r,t,e)},getEdgeValidationError(r=null,t=null,e=null){if(r&&!this.isAllowDanglingEdges()&&(!t||!e))return"";if(r&&!r.getTerminal(!0)&&!r.getTerminal(!1))return null;if(!this.isAllowLoops()&&t===e&&t||!this.isValidConnection(t,e))return"";if(t&&e){let i="";if(!this.isMultigraph()){const o=this.getDataModel().getEdgesBetween(t,e,!0);(o.length>1||o.length===1&&o[0]!==r)&&(i+=`${translate(this.getAlreadyConnectedResource())||this.getAlreadyConnectedResource()}
6
+ `;)r=r.substring(0,r.length-1),e+=t;return r+e},htmlEntities=(r,t=!0)=>(r=String(r||""),r=r.replace(/&/g,"&amp;"),r=r.replace(/"/g,"&quot;"),r=r.replace(/'/g,"&#39;"),r=r.replace(/</g,"&lt;"),r=r.replace(/>/g,"&gt;"),t&&(r=r.replace(/\n/g,"&#xa;")),r);class ObjectIdentity{static get(t){if(t){if(t[IDENTITY_FIELD_NAME]===null||t[IDENTITY_FIELD_NAME]===void 0)if(typeof t=="object"){const e=getFunctionName(t.constructor);t[IDENTITY_FIELD_NAME]=`${e}#${ObjectIdentity.counter++}`}else typeof t=="function"&&(t[IDENTITY_FIELD_NAME]=`Function#${ObjectIdentity.counter++}`);return t[IDENTITY_FIELD_NAME]}return null}static clear(t){delete t[IDENTITY_FIELD_NAME]}}ObjectIdentity.FIELD_NAME=IDENTITY_FIELD_NAME;ObjectIdentity.counter=0;const clone=function r(t,e=null,i=!1){i=i??!1;let s=null;if(t!=null&&typeof t.constructor=="function"){s=new t.constructor;for(const n in t)n!=ObjectIdentity.FIELD_NAME&&(e==null||!e.includes(n))&&(!i&&typeof t[n]=="object"?s[n]=r(t[n]):s[n]=t[n])}return s};class Cell{constructor(t=null,e=null,i={}){this.invalidating=!1,this.onInit=null,this.overlays=[],this.id=null,this.value=null,this.geometry=null,this.style={},this.vertex=!1,this.edge=!1,this.connectable=!0,this.visible=!0,this.collapsed=!1,this.parent=null,this.source=null,this.target=null,this.children=[],this.edges=[],this.mxTransient=["id","value","parent","source","target","children","edges"],this.value=t,this.setGeometry(e),this.setStyle(i),this.onInit&&this.onInit()}getChildren(){return this.children||[]}getId(){return this.id}setId(t){this.id=t}getValue(){return this.value}setValue(t){this.value=t}valueChanged(t){const e=this.getValue();return this.setValue(t),e}getGeometry(){return this.geometry}setGeometry(t){this.geometry=t}getStyle(){return this.style}getClonedStyle(){return clone(this.getStyle())}setStyle(t){this.style=t}isVertex(){return this.vertex}setVertex(t){this.vertex=t}isEdge(){return this.edge}setEdge(t){this.edge=t}isConnectable(){return this.connectable}setConnectable(t){this.connectable=t}isVisible(){return this.visible}setVisible(t){this.visible=t}isCollapsed(){return this.collapsed}setCollapsed(t){this.collapsed=t}getParent(){return this.parent}setParent(t){this.parent=t}getTerminal(t=!1){return t?this.source:this.target}setTerminal(t,e){return e?this.source=t:this.target=t,t}getChildCount(){return this.children.length}getIndex(t){return t===null?-1:this.children.indexOf(t)}getChildAt(t){return this.children[t]}insert(t,e){return e===void 0&&(e=this.getChildCount(),t.getParent()===this&&e--),t.removeFromParent(),t.setParent(this),this.children.splice(e,0,t),t}remove(t){let e=null;return t>=0&&(e=this.getChildAt(t),e&&(this.children.splice(t,1),e.setParent(null))),e}removeFromParent(){if(this.parent){const t=this.parent.getIndex(this);this.parent.remove(t)}}getEdgeCount(){return this.edges.length}getEdgeIndex(t){return this.edges.indexOf(t)}getEdgeAt(t){return this.edges[t]}insertEdge(t,e=!1){return t.removeFromTerminal(e),t.setTerminal(this,e),(this.edges.length===0||t.getTerminal(!e)!==this||!this.edges.includes(t))&&this.edges.push(t),t}removeEdge(t,e=!1){if(t!=null){if(t.getTerminal(!e)!==this&&this.edges!=null){const i=this.getEdgeIndex(t);i>=0&&this.edges.splice(i,1)}t.setTerminal(null,e)}return t}removeFromTerminal(t){const e=this.getTerminal(t);e&&e.removeEdge(this,t)}hasAttribute(t){var i;const e=this.getValue();return isElement(e)&&e.hasAttribute?e.hasAttribute(t):!isNullish((i=e.getAttribute)==null?void 0:i.call(e,t))}getAttribute(t,e){var n;const i=this.getValue();return(isElement(i)?(n=i.getAttribute)==null?void 0:n.call(i,t):null)??e}setAttribute(t,e){var s;const i=this.getValue();isElement(i)&&((s=i.setAttribute)==null||s.call(i,t,e))}clone(){const t=clone(this,this.mxTransient);return t.setValue(this.cloneValue()),t}cloneValue(){let t=this.getValue();return isNullish(t)||(typeof t.clone=="function"?t=t.clone():!isNullish(t.nodeType)&&t.cloneNode&&(t=t.cloneNode(!0))),t}getNearestCommonAncestor(t){let e=CellPath.create(t);if(e.length>0){let i=this,s=CellPath.create(i);if(e.length<s.length){i=t;const n=s;s=e,e=n}for(;i&&s;){const n=i.getParent();if(e.indexOf(s+CellPath.PATH_SEPARATOR)===0&&n)return i;s=CellPath.getParentPath(s),i=n}}return null}isAncestor(t){for(;t&&t!==this;)t=t.getParent();return t===this}getChildVertices(){return this.getChildCells(!0,!1)}getChildEdges(){return this.getChildCells(!1,!0)}getChildCells(t=!1,e=!1){const i=this.getChildCount(),s=[];for(let n=0;n<i;n+=1){const l=this.getChildAt(n);(!e&&!t||e&&l.isEdge()||t&&l.isVertex())&&s.push(l)}return s}getDirectedEdgeCount(t,e=null){let i=0;const s=this.getEdgeCount();for(let n=0;n<s;n+=1){const l=this.getEdgeAt(n);l!==e&&l&&l.getTerminal(t)===this&&(i+=1)}return i}getConnections(){return this.getEdges(!0,!0,!1)}getIncomingEdges(){return this.getEdges(!0,!1,!1)}getOutgoingEdges(){return this.getEdges(!1,!0,!1)}getEdges(t=!0,e=!0,i=!0){const s=this.getEdgeCount(),n=[];for(let l=0;l<s;l+=1){const o=this.getEdgeAt(l),a=o.getTerminal(!0),h=o.getTerminal(!1);(i&&a===h||a!==h&&(t&&h===this||e&&a===this))&&n.push(o)}return n}getOrigin(){let t=new Point;const e=this.getParent();if(e&&(t=e.getOrigin(),!this.isEdge())){const i=this.getGeometry();i&&(t.x+=i.x,t.y+=i.y)}return t}getDescendants(){return this.filterDescendants(null)}filterDescendants(t){let e=[];(t===null||t(this))&&e.push(this);const i=this.getChildCount();for(let s=0;s<i;s+=1){const n=this.getChildAt(s);e=e.concat(n.filterDescendants(t))}return e}getRoot(){let t=this,e=t;for(;t;)e=t,t=t.getParent();return e}}class ChildChange{constructor(t,e,i,s=0){this.model=t,this.parent=e,this.previous=e,this.child=i,this.index=s,this.previousIndex=s}execute(){let t=this.child.getParent();const e=t?t.getIndex(this.child):0;this.previous||this.connect(this.child,!1),t=this.model.parentForCellChanged(this.child,this.previous,this.previousIndex),this.previous&&this.connect(this.child,!0),this.parent=this.previous,this.previous=t,this.index=this.previousIndex,this.previousIndex=e}connect(t,e=!0){const i=t.getTerminal(!0),s=t.getTerminal(!1);i&&(e?this.model.terminalForCellChanged(t,i,!0):this.model.terminalForCellChanged(t,null,!0)),s&&(e?this.model.terminalForCellChanged(t,s,!1):this.model.terminalForCellChanged(t,null,!1)),t.setTerminal(i,!0),t.setTerminal(s,!1);const n=t.getChildCount();for(let l=0;l<n;l+=1)this.connect(t.getChildAt(l),e)}}class GeometryChange{constructor(t,e,i){this.model=t,this.cell=e,this.geometry=i,this.previous=i}execute(){this.geometry=this.previous,this.previous=this.model.geometryForCellChanged(this.cell,this.previous)}}class RootChange{constructor(t,e){this.model=t,this.root=e,this.previous=e}execute(){this.root=this.previous,this.previous=this.model.rootChanged(this.previous)}}class StyleChange{constructor(t,e,i){this.model=t,this.cell=e,this.style=i,this.previous=i}execute(){this.style=this.previous,this.previous=this.model.styleForCellChanged(this.cell,this.previous)}}class TerminalChange{constructor(t,e,i,s){this.model=t,this.cell=e,this.terminal=i,this.previous=i,this.source=s}execute(){this.terminal=this.previous,this.previous=this.model.terminalForCellChanged(this.cell,this.previous,this.source)}}class ValueChange{constructor(t,e,i){this.model=t,this.cell=e,this.value=i,this.previous=i}execute(){this.value=this.previous,this.previous=this.model.valueForCellChanged(this.cell,this.previous)}}class CellState extends Rectangle{constructor(t=null,e=null,i=null){super(),this.node=null,this.cellBounds=null,this.paintBounds=null,this.boundingBox=null,this.control=null,this.overlays=new Map,this.invalidStyle=!1,this.invalid=!0,this.absolutePoints=[],this.visibleSourceState=null,this.visibleTargetState=null,this.terminalDistance=0,this.length=0,this.segments=[],this.shape=null,this.text=null,this.unscaledWidth=0,this.unscaledHeight=0,this.parentHighlight=null,this.point=null,t&&(this.view=t),e&&(this.cell=e),this.style=i??{},this.origin=new Point,this.absoluteOffset=new Point}getPerimeterBounds(t=0,e=new Rectangle(this.x,this.y,this.width,this.height)){var i,s;if(((s=(i=this.shape)==null?void 0:i.stencil)==null?void 0:s.aspect)==="fixed"){const n=this.shape.stencil.computeAspect(this.shape,e.x,e.y,e.width,e.height);e.x=n.x,e.y=n.y,e.width=this.shape.stencil.w0*n.width,e.height=this.shape.stencil.h0*n.height}return t!==0&&e.grow(t),e}setAbsoluteTerminalPoint(t,e=!1){e?this.absolutePoints.length===0?this.absolutePoints.push(t):this.absolutePoints[0]=t:this.absolutePoints.length===0?(this.absolutePoints.push(null),this.absolutePoints.push(t)):this.absolutePoints.length===1?this.absolutePoints.push(t):this.absolutePoints[this.absolutePoints.length-1]=t}setCursor(t){this.shape&&this.shape.setCursor(t),this.text&&this.text.setCursor(t)}getVisibleTerminal(t=!1){var e;return((e=this.getVisibleTerminalState(t))==null?void 0:e.cell)??null}getVisibleTerminalState(t=!1){return t?this.visibleSourceState:this.visibleTargetState}setVisibleTerminalState(t,e=!1){e?this.visibleSourceState=t:this.visibleTargetState=t}getCellBounds(){return this.cellBounds}getPaintBounds(){return this.paintBounds}updateCachedBounds(){const t=this.view,e=t.translate,i=t.scale;this.cellBounds=new Rectangle(this.x/i-e.x,this.y/i-e.y,this.width/i,this.height/i),this.paintBounds=Rectangle.fromRectangle(this.cellBounds),this.shape&&this.shape.isPaintBoundsInverted()&&this.paintBounds.rotate90()}setState(t){this.view=t.view,this.cell=t.cell,this.style=t.style,this.absolutePoints=t.absolutePoints,this.origin=t.origin,this.absoluteOffset=t.absoluteOffset,this.boundingBox=t.boundingBox,this.terminalDistance=t.terminalDistance,this.segments=t.segments,this.length=t.length,this.x=t.x,this.y=t.y,this.width=t.width,this.height=t.height,this.unscaledWidth=t.unscaledWidth,this.unscaledHeight=t.unscaledHeight}clone(){const t=new CellState(this.view,this.cell,this.style);for(let e=0;e<this.absolutePoints.length;e+=1){const i=this.absolutePoints[e];t.absolutePoints[e]=i?i.clone():null}return this.origin&&(t.origin=this.origin.clone()),this.absoluteOffset&&(t.absoluteOffset=this.absoluteOffset.clone()),this.boundingBox&&(t.boundingBox=this.boundingBox.clone()),t.terminalDistance=this.terminalDistance,t.segments=this.segments,t.length=this.length,t.x=this.x,t.y=this.y,t.width=this.width,t.height=this.height,t.unscaledWidth=this.unscaledWidth,t.unscaledHeight=this.unscaledHeight,t}destroy(){this.view.graph.cellRenderer.destroy(this)}isLoop(t){const e=this.getVisibleTerminalState(!0);return e&&e===this.getVisibleTerminalState(!1)}getVerticalAlign(){return this.style.verticalAlign??"middle"}isTransparentState(){return(this.style.strokeColor??NONE)===NONE&&(this.style.fillColor??NONE)===NONE&&!this.getImageSrc()}getImageSrc(){return this.style.image||null}getIndicatorColor(){return this.style.indicatorColor||null}getIndicatorGradientColor(){return this.style.gradientColor||null}getIndicatorShape(){return this.style.indicatorShape||null}getIndicatorImageSrc(){return this.style.indicatorImage||null}}const toRadians=r=>Math.PI*r/180,arcToCurves=(r,t,e,i,s,n,l,o,a)=>{if(o-=r,a-=t,e===0||i===0)return[];const h=l,d=s;e=Math.abs(e),i=Math.abs(i);const c=-o/2,u=-a/2,g=Math.cos(d*Math.PI/180),f=Math.sin(d*Math.PI/180),p=g*c+f*u,y=-1*f*c+g*u,v=p*p,S=y*y,w=e*e,C=i*i,m=v/w+S/C;let T;if(m>1)e=Math.sqrt(m)*e,i=Math.sqrt(m)*i,T=0;else{let J=1;n===h&&(J=-1),T=J*Math.sqrt((w*C-w*S-C*v)/(w*S+C*v))}const b=T*e*y/i,H=-1*T*i*p/e,R=g*b-f*H+o/2,M=f*b+g*H+a/2;let I=Math.atan2((y-H)/i,(p-b)/e)-Math.atan2(0,1),z=I>=0?I:2*Math.PI+I;I=Math.atan2((-y-H)/i,(-p-b)/e)-Math.atan2((y-H)/i,(p-b)/e);let $=I>=0?I:2*Math.PI+I;!h&&$>0?$-=2*Math.PI:h&&$<0&&($+=2*Math.PI);const et=$*2/Math.PI,x=Math.ceil(et<0?-1*et:et),P=$/x,L=8/3*Math.sin(P/4)*Math.sin(P/4)/Math.sin(P/2),O=g*e,A=g*i,B=f*e,V=f*i;let _=Math.cos(z),Y=Math.sin(z),D=-L*(O*Y+V*_),k=-L*(B*Y-A*_),G=0,W=0;const U=[];for(let J=0;J<x;++J){z+=P,_=Math.cos(z),Y=Math.sin(z),G=O*_-V*Y+R,W=B*_+A*Y+M;const it=-L*(O*Y+V*_),F=-L*(B*Y-A*_),K=J*6;U[K]=Number(D+r),U[K+1]=Number(k+t),U[K+2]=Number(G-it+r),U[K+3]=Number(W-F+t),U[K+4]=Number(G+r),U[K+5]=Number(W+t),D=G+it,k=W+F}return U},getBoundingBox=(r,t,e=null)=>{let i=null;if(r&&t!==0){const s=toRadians(t),n=Math.cos(s),l=Math.sin(s);e=e??new Point(r.x+r.width/2,r.y+r.height/2);let o=new Point(r.x,r.y),a=new Point(r.x+r.width,r.y),h=new Point(a.x,r.y+r.height),d=new Point(r.x,h.y);o=getRotatedPoint(o,n,l,e),a=getRotatedPoint(a,n,l,e),h=getRotatedPoint(h,n,l,e),d=getRotatedPoint(d,n,l,e),i=new Rectangle(o.x,o.y,0,0),i.add(new Rectangle(a.x,a.y,0,0)),i.add(new Rectangle(h.x,h.y,0,0)),i.add(new Rectangle(d.x,d.y,0,0))}return i},getRotatedPoint=(r,t,e,i=new Point)=>{const s=r.x-i.x,n=r.y-i.y,l=s*t-n*e,o=n*t+s*e;return new Point(l+i.x,o+i.y)},getPortConstraints=(r,t,e,i)=>{const s=r.style.portConstraint??(e?t.style.sourcePortConstraint:t.style.targetPortConstraint);if(isNullish(s))return i;const n=s.toString();let l=DIRECTION_MASK.NONE;const a=r.style.portConstraintRotation??!1?r.style.rotation??0:0;let h=0;if(a>45?(h=1,a>=135&&(h=2)):a<-45&&(h=3,a<=-135&&(h=2)),n.includes("north"))switch(h){case 0:l|=DIRECTION_MASK.NORTH;break;case 1:l|=DIRECTION_MASK.EAST;break;case 2:l|=DIRECTION_MASK.SOUTH;break;case 3:l|=DIRECTION_MASK.WEST;break}if(n.includes("west"))switch(h){case 0:l|=DIRECTION_MASK.WEST;break;case 1:l|=DIRECTION_MASK.NORTH;break;case 2:l|=DIRECTION_MASK.EAST;break;case 3:l|=DIRECTION_MASK.SOUTH;break}if(n.includes("south"))switch(h){case 0:l|=DIRECTION_MASK.SOUTH;break;case 1:l|=DIRECTION_MASK.WEST;break;case 2:l|=DIRECTION_MASK.NORTH;break;case 3:l|=DIRECTION_MASK.EAST;break}if(n.includes("east"))switch(h){case 0:l|=DIRECTION_MASK.EAST;break;case 1:l|=DIRECTION_MASK.SOUTH;break;case 2:l|=DIRECTION_MASK.WEST;break;case 3:l|=DIRECTION_MASK.NORTH;break}return l},reversePortConstraints=r=>{let t=0;return t=(r&DIRECTION_MASK.WEST)<<3,t|=(r&DIRECTION_MASK.NORTH)<<1,t|=(r&DIRECTION_MASK.SOUTH)>>1,t|=(r&DIRECTION_MASK.EAST)>>3,t},findNearestSegment=(r,t,e)=>{let i=-1;if(r.absolutePoints.length>0){let s=r.absolutePoints[0],n=null;for(let l=1;l<r.absolutePoints.length;l+=1){const o=r.absolutePoints[l];if(!s||!o)continue;const a=ptSegDistSq(s.x,s.y,o.x,o.y,t,e);(n==null||a<n)&&(n=a,i=l-1),s=o}}return i},getDirectedBounds=(r,t,e,i,s)=>{const n=(e==null?void 0:e.direction)??"east";if(i??(i=(e==null?void 0:e.flipH)??!1),s??(s=(e==null?void 0:e.flipV)??!1),t.x=Math.round(Math.max(0,Math.min(r.width,t.x))),t.y=Math.round(Math.max(0,Math.min(r.height,t.y))),t.width=Math.round(Math.max(0,Math.min(r.width,t.width))),t.height=Math.round(Math.max(0,Math.min(r.height,t.height))),s&&(n==="south"||n==="north")||i&&(n==="east"||n==="west")){const o=t.x;t.x=t.width,t.width=o}if(i&&(n==="south"||n==="north")||s&&(n==="east"||n==="west")){const o=t.y;t.y=t.height,t.height=o}const l=Rectangle.fromRectangle(t);switch(n){case"south":{l.y=t.x,l.x=t.height,l.width=t.y,l.height=t.width;break}case"west":{l.y=t.height,l.x=t.width,l.width=t.x,l.height=t.y;break}case"north":{l.y=t.width,l.x=t.y,l.width=t.height,l.height=t.x;break}}return new Rectangle(r.x+l.x,r.y+l.y,r.width-l.width-l.x,r.height-l.height-l.y)},contains=(r,t,e)=>r.x<=t&&r.x+r.width>=t&&r.y<=e&&r.y+r.height>=e,intersects=(r,t)=>{let e=r.width,i=r.height,s=t.width,n=t.height;if(s<=0||n<=0||e<=0||i<=0)return!1;const l=r.x,o=r.y,a=t.x,h=t.y;return s+=a,n+=h,e+=l,i+=o,(s<a||s>l)&&(n<h||n>o)&&(e<l||e>a)&&(i<o||i>h)},intersectsHotspot=(r,t,e,i,s,n)=>{if(i=i??1,s=s??0,n=n??0,i>0){let l=r.getCenterX(),o=r.getCenterY(),a=r.width,h=r.height;const d=r.style,c=((d==null?void 0:d.startSize)??0)*r.view.scale;c>0&&((d==null?void 0:d.horizontal)??!0?(o=r.y+c/2,h=c):(l=r.x+c/2,a=c)),a=Math.max(s,a*i),h=Math.max(s,h*i),n>0&&(a=Math.min(a,n),h=Math.min(h,n));const u=new Rectangle(l-a/2,o-h/2,a,h),g=toRadians((d==null?void 0:d.rotation)??0);if(g!=0){const f=Math.cos(-g),p=Math.sin(-g),y=new Point(r.getCenterX(),r.getCenterY()),v=getRotatedPoint(new Point(t,e),f,p,y);t=v.x,e=v.y}return contains(u,t,e)}return!0},isNumeric=r=>!Number.isNaN(Number.parseFloat(r))&&Number.isFinite(+r)&&(typeof r!="string"||!r.toLowerCase().includes("0x")),mod=(r,t)=>(r%t+t)%t,intersection=(r,t,e,i,s,n,l,o)=>{const a=(o-n)*(e-r)-(l-s)*(i-t),h=(l-s)*(t-n)-(o-n)*(r-s),d=(e-r)*(t-n)-(i-t)*(r-s),c=h/a,u=d/a;if(c>=0&&c<=1&&u>=0&&u<=1){const g=r+c*(e-r),f=t+c*(i-t);return new Point(g,f)}return null},ptSegDistSq=(r,t,e,i,s,n)=>{e-=r,i-=t,s-=r,n-=t;let l=s*e+n*i,o;l<=0?o=0:(s=e-s,n=i-n,l=s*e+n*i,l<=0?o=0:o=l*l/(e*e+i*i));let a=s*s+n*n-o;return a<0&&(a=0),a},relativeCcw=(r,t,e,i,s,n)=>{e-=r,i-=t,s-=r,n-=t;let l=s*i-n*e;return l==0&&(l=s*e+n*i,l>0&&(s-=e,n-=i,l=s*e+n*i,l<0&&(l=0))),l<0?-1:l>0?1:0},SideToSide=(r,t,e,i,s)=>{const{view:n}=r;let l=i!=null&&i.length>0?i[0]:null;const o=r.absolutePoints,a=o[0],h=o[o.length-1];if(l!=null&&(l=n.transformControlPoint(r,l)),a!=null&&(t=new CellState,t.x=a.x,t.y=a.y),h!=null&&(e=new CellState,e.x=h.x,e.y=h.y),t!=null&&e!=null){const d=Math.max(t.x,e.x),c=Math.min(t.x+t.width,e.x+e.width),u=l!=null?l.x:Math.round(c+(d-c)/2);let g=n.getRoutingCenterY(t),f=n.getRoutingCenterY(e);if(l!=null&&(l.y>=t.y&&l.y<=t.y+t.height&&(g=l.y),l.y>=e.y&&l.y<=e.y+e.height&&(f=l.y)),!contains(e,u,g)&&!contains(t,u,g)&&s.push(new Point(u,g)),!contains(e,u,f)&&!contains(t,u,f)&&s.push(new Point(u,f)),s.length===1)if(l!=null)!contains(e,u,l.y)&&!contains(t,u,l.y)&&s.push(new Point(u,l.y));else{const p=Math.max(t.y,e.y),y=Math.min(t.y+t.height,e.y+e.height);s.push(new Point(u,p+(y-p)/2))}}},TopToBottom=(r,t,e,i,s)=>{const{view:n}=r;let l=i!=null&&i.length>0?i[0]:null;const o=r.absolutePoints,a=o[0],h=o[o.length-1];if(l!=null&&(l=n.transformControlPoint(r,l)),a!=null&&(t=new CellState,t.x=a.x,t.y=a.y),h!=null&&(e=new CellState,e.x=h.x,e.y=h.y),t!=null&&e!=null){const d=Math.max(t.y,e.y),c=Math.min(t.y+t.height,e.y+e.height);let u=n.getRoutingCenterX(t);l!=null&&l.x>=t.x&&l.x<=t.x+t.width&&(u=l.x);const g=l!=null?l.y:Math.round(c+(d-c)/2);if(!contains(e,u,g)&&!contains(t,u,g)&&s.push(new Point(u,g)),l!=null&&l.x>=e.x&&l.x<=e.x+e.width?u=l.x:u=n.getRoutingCenterX(e),!contains(e,u,g)&&!contains(t,u,g)&&s.push(new Point(u,g)),s.length===1)if(l!=null&&s.length===1)!contains(e,l.x,g)&&!contains(t,l.x,g)&&s.push(new Point(l.x,g));else{const f=Math.max(t.x,e.x),p=Math.min(t.x+t.width,e.x+e.width);s.push(new Point(f+(p-f)/2,g))}}},ElbowConnector=(r,t,e,i,s)=>{let n=i!=null&&i.length>0?i[0]:null,l=!1,o=!1;if(t!=null&&e!=null)if(n!=null){const a=Math.min(t.x,e.x),h=Math.max(t.x+t.width,e.x+e.width),d=Math.min(t.y,e.y),c=Math.max(t.y+t.height,e.y+e.height);n=r.view.transformControlPoint(r,n),l=n.y<d||n.y>c,o=n.x<a||n.x>h}else{const a=Math.max(t.x,e.x),h=Math.min(t.x+t.width,e.x+e.width);if(l=a===h,!l){const d=Math.max(t.y,e.y),c=Math.min(t.y+t.height,e.y+e.height);o=d===c}}!o&&(l||r.style.elbow==="vertical")?TopToBottom(r,t,e,i,s):SideToSide(r,t,e,i,s)},EntityRelationConnectorConfig={segment:ENTITY_SEGMENT},OrthogonalConnectorConfig={buffer:10},allDirections=()=>["north","south","east","west"],ManhattanConnectorConfig={maxAllowedDirectionChange:90,maxLoops:2e3,endDirections:allDirections(),startDirections:allDirections(),step:12},originalManhattanConnectorConfig={};shallowCopy(ManhattanConnectorConfig,originalManhattanConnectorConfig);const EntityRelation=(r,t,e,i,s)=>{var u;const{view:n}=r,l=(((u=r.style)==null?void 0:u.segment)??EntityRelationConnectorConfig.segment)*n.scale,o=r.absolutePoints,a=o[0],h=o[o.length-1];let d=!1;if(t!=null){const g=t.cell.getGeometry();g.relative?d=g.x<=.5:e!=null&&(d=(h!=null?h.x:e.x+e.width)<(a!=null?a.x:t.x))}if(a!=null)t=new CellState,t.x=a.x,t.y=a.y;else if(t!=null){const g=getPortConstraints(t,r,!0,DIRECTION_MASK.NONE);g!==DIRECTION_MASK.NONE&&g!==DIRECTION_MASK.WEST+DIRECTION_MASK.EAST&&(d=g===DIRECTION_MASK.WEST)}else return;let c=!0;if(e!=null){const g=e.cell.getGeometry();g.relative?c=g.x<=.5:t!=null&&(c=(a!=null?a.x:t.x+t.width)<(h!=null?h.x:e.x))}if(h!=null)e=new CellState,e.x=h.x,e.y=h.y;else if(e!=null){const g=getPortConstraints(e,r,!1,DIRECTION_MASK.NONE);g!==DIRECTION_MASK.NONE&&g!=DIRECTION_MASK.WEST+DIRECTION_MASK.EAST&&(c=g===DIRECTION_MASK.WEST)}if(t!=null&&e!=null){const g=d?t.x:t.x+t.width,f=n.getRoutingCenterY(t),p=c?e.x:e.x+e.width,y=n.getRoutingCenterY(e),v=l;let S=d?-v:v;const w=new Point(g+S,f);S=c?-v:v;const C=new Point(p+S,y);if(d===c){const m=d?Math.min(g,p)-l:Math.max(g,p)+l;s.push(new Point(m,f)),s.push(new Point(m,y))}else if(w.x<C.x===d){const m=f+(y-f)/2;s.push(w),s.push(new Point(w.x,m)),s.push(new Point(C.x,m)),s.push(C)}else s.push(w),s.push(C)}},Loop=(r,t,e,i,s)=>{var a;const n=r.absolutePoints,l=n[0],o=n[n.length-1];if(l!=null&&o!=null){if(i!=null&&i.length>0)for(let h=0;h<i.length;h+=1){let d=i[h];d=r.view.transformControlPoint(r,d),s.push(new Point(d.x,d.y))}return}if(t!=null){const{view:h}=r,{graph:d}=h;let c=i!=null&&i.length>0?i[0]:null;c!=null&&(c=h.transformControlPoint(r,c),contains(t,c.x,c.y)&&(c=null));let u=0,g=0,f=0,p=0;const y=(r.style.segment??d.gridSize)*h.scale,v=((a=r.style)==null?void 0:a.direction)??"west";if(v==="north"||v==="south"?(u=h.getRoutingCenterX(t),g=y):(f=h.getRoutingCenterY(t),p=y),c==null||c.x<t.x||c.x>t.x+t.width)if(c!=null)u=c.x,p=Math.max(Math.abs(f-c.y),p);else switch(v){case"north":{f=t.y-2*g;break}case"south":{f=t.y+t.height+2*g;break}case"east":{u=t.x-2*p;break}default:u=t.x+t.width+2*p}else c!==null&&(u=h.getRoutingCenterX(t),g=Math.max(Math.abs(u-c.x),p),f=c.y,p=0);s.push(new Point(u-g,f-p)),s.push(new Point(u+g,f+p))}},equalPoints=(r,t)=>{if(!r&&t||r&&!t||r&&t&&r.length!=t.length)return!1;if(r&&t)for(let e=0;e<r.length;e+=1){const i=r[e];if(!i||i&&!i.equals(t[e]))return!1}return!0},equalEntries=(r,t)=>{let e=0;if(!r&&t||r&&!t||r&&t&&r.length!=t.length)return!1;if(r&&t){for(const i in t)e++;for(const i in r)if(e--,(!Number.isNaN(r[i])||!Number.isNaN(t[i]))&&r[i]!==t[i])return!1}return e===0},removeDuplicates=r=>{const t=new Map,e=[];for(let i=0;i<r.length;i+=1)t.get(r[i])||(e.push(r[i]),t.set(r[i],!0));return e};class Geometry extends Rectangle{constructor(t=0,e=0,i=0,s=0){super(t,e,i,s),this.TRANSLATE_CONTROL_POINTS=!0,this.alternateBounds=null,this.sourcePoint=null,this.targetPoint=null,this.points=null,this.offset=null,this.relative=!1}setRelative(t){this.relative=t}swap(){if(this.alternateBounds){const t=new Rectangle(this.x,this.y,this.width,this.height);this.x=this.alternateBounds.x,this.y=this.alternateBounds.y,this.width=this.alternateBounds.width,this.height=this.alternateBounds.height,this.alternateBounds=t}}getTerminalPoint(t){return t?this.sourcePoint:this.targetPoint}setTerminalPoint(t,e){return e?this.sourcePoint=t:this.targetPoint=t,t}rotate(t,e){const i=toRadians(t),s=Math.cos(i),n=Math.sin(i);if(!this.relative){const l=new Point(this.getCenterX(),this.getCenterY()),o=getRotatedPoint(l,s,n,e);this.x=Math.round(o.x-this.width/2),this.y=Math.round(o.y-this.height/2)}if(this.sourcePoint){const l=getRotatedPoint(this.sourcePoint,s,n,e);this.sourcePoint.x=Math.round(l.x),this.sourcePoint.y=Math.round(l.y)}if(this.targetPoint){const l=getRotatedPoint(this.targetPoint,s,n,e);this.targetPoint.x=Math.round(l.x),this.targetPoint.y=Math.round(l.y)}if(this.points){for(let l=0;l<this.points.length;l+=1)if(this.points[l]){const o=getRotatedPoint(this.points[l],s,n,e);this.points[l].x=Math.round(o.x),this.points[l].y=Math.round(o.y)}}}translate(t,e){if(this.relative||(this.x+=t,this.y+=e),this.sourcePoint&&(this.sourcePoint.x=this.sourcePoint.x+t,this.sourcePoint.y=this.sourcePoint.y+e),this.targetPoint&&(this.targetPoint.x=this.targetPoint.x+t,this.targetPoint.y=this.targetPoint.y+e),this.TRANSLATE_CONTROL_POINTS&&this.points)for(let i=0;i<this.points.length;i+=1)this.points[i]&&(this.points[i].x=this.points[i].x+t,this.points[i].y=this.points[i].y+e)}scale(t,e,i){if(this.sourcePoint&&(this.sourcePoint.x=this.sourcePoint.x*t,this.sourcePoint.y=this.sourcePoint.y*e),this.targetPoint&&(this.targetPoint.x=this.targetPoint.x*t,this.targetPoint.y=this.targetPoint.y*e),this.points)for(let s=0;s<this.points.length;s+=1)this.points[s]&&(this.points[s].x=this.points[s].x*t,this.points[s].y=this.points[s].y*e);this.relative||(this.x*=t,this.y*=e,i&&(e=t=Math.min(t,e)),this.width*=t,this.height*=e)}equals(t){var e,i,s,n;return t?super.equals(t)&&this.relative===t.relative&&(this.sourcePoint===null&&t.sourcePoint===null||!!((e=this.sourcePoint)!=null&&e.equals(t.sourcePoint)))&&(this.targetPoint===null&&t.targetPoint===null||!!((i=this.targetPoint)!=null&&i.equals(t.targetPoint)))&&equalPoints(this.points,t.points)&&(this.alternateBounds===null&&t.alternateBounds===null||!!((s=this.alternateBounds)!=null&&s.equals(t.alternateBounds)))&&(this.offset===null&&t.offset===null||!!((n=this.offset)!=null&&n.equals(t.offset))):!1}clone(){return clone(this)}}function scalePointArray(r,t){let e=[];if(r!=null)for(let i=0;i<r.length;i+=1)r[i]!=null?e[i]=new Point(Math.round(r[i].x/t*10)/10,Math.round(r[i].y/t*10)/10):e[i]=null;else e=null;return e}function scaleCellState(r,t){let e=null;return r!=null&&(e=r.clone(),e.setRect(Math.round(r.x/t*10)/10,Math.round(r.y/t*10)/10,Math.round(r.width/t*10)/10,Math.round(r.height/t*10)/10)),e}const SegmentConnector=(r,t,e,i,s)=>{const n=scalePointArray(r.absolutePoints,r.view.scale),l=scaleCellState(t,r.view.scale),o=scaleCellState(e,r.view.scale),a=1;let h=s.length>0?s[0]:null,d=!0,c=null;function u(y){return y.x=Math.round(y.x*r.view.scale*10)/10,y.y=Math.round(y.y*r.view.scale*10)/10,(h==null||Math.abs(h.x-y.x)>=a||Math.abs(h.y-y.y)>=Math.max(1,r.view.scale))&&(s.push(y),h=y),h}let g=n[0];g==null&&l!=null?g=new Point(r.view.getRoutingCenterX(l),r.view.getRoutingCenterY(l)):g!=null&&(g=g.clone());const f=n.length-1;let p=null;if(i!=null&&i.length>0){let y=[];for(let T=0;T<i.length;T+=1){const b=r.view.transformControlPoint(r,i[T],!0);b!=null&&y.push(b)}if(y.length===0)return;g!=null&&y[0]!=null&&(Math.abs(y[0].x-g.x)<a&&(y[0].x=g.x),Math.abs(y[0].y-g.y)<a&&(y[0].y=g.y)),p=n[f],p!=null&&y[y.length-1]!=null&&(Math.abs(y[y.length-1].x-p.x)<a&&(y[y.length-1].x=p.x),Math.abs(y[y.length-1].y-p.y)<a&&(y[y.length-1].y=p.y)),c=y[0];let v=l,S=n[0],w=!1,C=!1,m=c;S!=null&&(v=null);for(let T=0;T<2;T+=1){const b=S!=null&&S.x===m.x,H=S!=null&&S.y===m.y,R=v!=null&&m.y>=v.y&&m.y<=v.y+v.height,M=v!=null&&m.x>=v.x&&m.x<=v.x+v.width;if(w=H||S==null&&R,C=b||S==null&&M,!(T==0&&(w&&C||b&&H))){if(S!=null&&!H&&!b&&(R||M)){d=!R;break}if(C||w){d=w,T===1&&(d=y.length%2===0?w:C);break}}v=o,S=n[f],S!=null&&(v=null),m=y[y.length-1],b&&H&&(y=y.slice(1))}d&&(n[0]!=null&&n[0].y!==c.y||n[0]==null&&l!=null&&(c.y<l.y||c.y>l.y+l.height))?u(new Point(g.x,c.y)):!d&&(n[0]!=null&&n[0].x!==c.x||n[0]==null&&l!=null&&(c.x<l.x||c.x>l.x+l.width))&&u(new Point(c.x,g.y)),d?g.y=c.y:g.x=c.x;for(let T=0;T<y.length;T+=1)d=!d,c=y[T],d?g.y=c.y:g.x=c.x,u(g.clone())}else c=g,d=!0;if(g=n[f],g==null&&o!=null&&(g=new Point(r.view.getRoutingCenterX(o),r.view.getRoutingCenterY(o))),g!=null&&c!=null&&(d&&(n[f]!=null&&n[f].y!==c.y||n[f]==null&&o!=null&&(c.y<o.y||c.y>o.y+o.height))?u(new Point(g.x,c.y)):!d&&(n[f]!=null&&n[f].x!==c.x||n[f]==null&&o!=null&&(c.x<o.x||c.x>o.x+o.width))&&u(new Point(c.x,g.y))),n[0]==null&&l!=null)for(;s.length>1&&s[1]!=null&&contains(l,s[1].x,s[1].y);)s.splice(1,1);if(n[f]==null&&o!=null)for(;s.length>1&&s[s.length-1]!=null&&contains(o,s[s.length-1].x,s[s.length-1].y);)s.splice(s.length-1,1);p!=null&&s[s.length-1]!=null&&Math.abs(p.x-s[s.length-1].x)<=a&&Math.abs(p.y-s[s.length-1].y)<=a&&(s.splice(s.length-1,1),s[s.length-1]!=null&&(Math.abs(s[s.length-1].x-p.x)<a&&(s[s.length-1].x=p.x),Math.abs(s[s.length-1].y-p.y)<a&&(s[s.length-1].y=p.y)))},dirVectors=[[-1,0],[0,-1],[1,0],[0,1],[-1,0],[0,-1],[1,0]],wayPoints1=[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]],routePatterns=[[[513,2308,2081,2562],[513,1090,514,2184,2114,2561],[513,1090,514,2564,2184,2562],[513,2308,2561,1090,514,2568,2308]],[[514,1057,513,2308,2081,2562],[514,2184,2114,2561],[514,2184,2562,1057,513,2564,2184],[514,1057,513,2568,2308,2561]],[[1090,514,1057,513,2308,2081,2562],[2114,2561],[1090,2562,1057,513,2564,2184],[1090,514,1057,513,2308,2561,2568]],[[2081,2562],[1057,513,1090,514,2184,2114,2561],[1057,513,1090,514,2184,2562,2564],[1057,2561,1090,514,2568,2308]]],vertexSeparations=[],limits=[[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0]],SIDE_MASK=480,CENTER_MASK=512,SOURCE_MASK=1024,TARGET_MASK=2048;function getJettySize(r,t){const e=OrthogonalConnectorConfig.buffer;let i=(t?r.style.sourceJettySize:r.style.targetJettySize)??r.style.jettySize??e;if(i==="auto")if(((t?r.style.startArrow:r.style.endArrow)??NONE)!==NONE){const n=(t?r.style.startSize:r.style.endSize)??StyleDefaultsConfig.markerSize;i=Math.max(2,Math.ceil((n+e)/e))*e}else i=2*e;return i}const OrthogonalConnector=(r,t,e,i,s)=>{const n=scalePointArray(r.absolutePoints,r.view.scale),l=scaleCellState(t,r.view.scale),o=scaleCellState(e,r.view.scale),a=l==null?!1:l.cell.isEdge(),h=o==null?!1:o.cell.isEdge(),d=n[0],c=n[n.length-1];let u=l!=null?l.x:d.x,g=l!=null?l.y:d.y,f=l!=null?l.width:0,p=l!=null?l.height:0,y=o!=null?o.x:c.x,v=o!=null?o.y:c.y,S=o!=null?o.width:0,w=o!=null?o.height:0,C=getJettySize(r,!0),m=getJettySize(r,!1);l!=null&&o===l&&(m=Math.max(C,m),C=m);const T=m+C;let b=!1;if(d!=null&&c!=null){const E=c.x-d.x,N=c.y-d.y;b=E*E+N*N<T*T}if(b||i!=null&&i.length>0||a||h){SegmentConnector(r,t,e,i,s);return}const H=[DIRECTION_MASK.ALL,DIRECTION_MASK.ALL];let R=0;if(l!=null&&(H[0]=getPortConstraints(l,r,!0,DIRECTION_MASK.ALL),R=l.style.rotation??0,R!==0)){const E=getBoundingBox(new Rectangle(u,g,f,p),R);u=E.x,g=E.y,f=E.width,p=E.height}if(o!=null&&(H[1]=getPortConstraints(o,r,!1,DIRECTION_MASK.ALL),R=o.style.rotation??0,R!==0)){const E=getBoundingBox(new Rectangle(y,v,S,w),R);y=E.x,v=E.y,S=E.width,w=E.height}const M=[0,0],I=[[u,g,f,p],[y,v,S,w]],z=[C,m];for(let E=0;E<2;E+=1)limits[E][1]=I[E][0]-z[E],limits[E][2]=I[E][1]-z[E],limits[E][4]=I[E][0]+I[E][2]+z[E],limits[E][8]=I[E][1]+I[E][3]+z[E];const $=I[0][0]+I[0][2]/2,et=I[0][1]+I[0][3]/2,x=I[1][0]+I[1][2]/2,P=I[1][1]+I[1][3]/2,L=$-x,O=et-P;let A=0;L<0?O<0?A=2:A=1:O<=0&&(A=3,L===0&&(A=2));let B=null;l!=null&&(B=d);const V=[[.5,.5],[.5,.5]];for(let E=0;E<2;E+=1)B!=null&&(V[E][0]=(B.x-I[E][0])/I[E][2],Math.abs(B.x-I[E][0])<=1?M[E]=DIRECTION_MASK.WEST:Math.abs(B.x-I[E][0]-I[E][2])<=1&&(M[E]=DIRECTION_MASK.EAST),V[E][1]=(B.y-I[E][1])/I[E][3],Math.abs(B.y-I[E][1])<=1?M[E]=DIRECTION_MASK.NORTH:Math.abs(B.y-I[E][1]-I[E][3])<=1&&(M[E]=DIRECTION_MASK.SOUTH)),B=null,o!=null&&(B=c);const _=I[0][1]-(I[1][1]+I[1][3]),Y=I[0][0]-(I[1][0]+I[1][2]),D=I[1][1]-(I[0][1]+I[0][3]),k=I[1][0]-(I[0][0]+I[0][2]);vertexSeparations[1]=Math.max(Y-T,0),vertexSeparations[2]=Math.max(_-T,0),vertexSeparations[4]=Math.max(D-T,0),vertexSeparations[3]=Math.max(k-T,0);const G=[],W=[],U=[];W[0]=Y>=k?DIRECTION_MASK.WEST:DIRECTION_MASK.EAST,U[0]=_>=D?DIRECTION_MASK.NORTH:DIRECTION_MASK.SOUTH,W[1]=reversePortConstraints(W[0]),U[1]=reversePortConstraints(U[0]);const J=Y>=k?Y:k,it=_>=D?_:D,F=[[0,0],[0,0]];let K=!1;for(let E=0;E<2;E+=1)M[E]===0&&((W[E]&H[E])===0&&(W[E]=reversePortConstraints(W[E])),(U[E]&H[E])===0&&(U[E]=reversePortConstraints(U[E])),F[E][0]=U[E],F[E][1]=W[E]);it>0&&J>0&&((W[0]&H[0])>0&&(U[1]&H[1])>0?(F[0][0]=W[0],F[0][1]=U[0],F[1][0]=U[1],F[1][1]=W[1],K=!0):(U[0]&H[0])>0&&(W[1]&H[1])>0&&(F[0][0]=U[0],F[0][1]=W[0],F[1][0]=W[1],F[1][1]=U[1],K=!0)),it>0&&!K&&(F[0][0]=U[0],F[0][1]=W[0],F[1][0]=U[1],F[1][1]=W[1],K=!0),J>0&&!K&&(F[0][0]=W[0],F[0][1]=U[0],F[1][0]=W[1],F[1][1]=U[1],K=!0);for(let E=0;E<2;E+=1)M[E]===0&&((F[E][0]&H[E])===0&&(F[E][0]=F[E][1]),G[E]=F[E][0]&H[E],G[E]|=(F[E][1]&H[E])<<8,G[E]|=(F[1-E][E]&H[E])<<16,G[E]|=(F[1-E][1-E]&H[E])<<24,(G[E]&15)===0&&(G[E]=G[E]<<8),(G[E]&3840)===0&&(G[E]=G[E]&15|G[E]>>8),(G[E]&983040)===0&&(G[E]=G[E]&65535|(G[E]&251658240)>>8),M[E]=G[E]&15,(H[E]===DIRECTION_MASK.WEST||H[E]===DIRECTION_MASK.NORTH||H[E]===DIRECTION_MASK.EAST||H[E]===DIRECTION_MASK.SOUTH)&&(M[E]=H[E]));let rt=M[0]===DIRECTION_MASK.EAST?3:M[0],tt=M[1]===DIRECTION_MASK.EAST?3:M[1];rt-=A,tt-=A,rt<1&&(rt+=4),tt<1&&(tt+=4);const ot=routePatterns[rt-1][tt-1];switch(wayPoints1[0][0]=I[0][0],wayPoints1[0][1]=I[0][1],M[0]){case DIRECTION_MASK.WEST:wayPoints1[0][0]-=C,wayPoints1[0][1]+=V[0][1]*I[0][3];break;case DIRECTION_MASK.SOUTH:wayPoints1[0][0]+=V[0][0]*I[0][2],wayPoints1[0][1]+=I[0][3]+C;break;case DIRECTION_MASK.EAST:wayPoints1[0][0]+=I[0][2]+C,wayPoints1[0][1]+=V[0][1]*I[0][3];break;case DIRECTION_MASK.NORTH:wayPoints1[0][0]+=V[0][0]*I[0][2],wayPoints1[0][1]-=C;break}let Z=0,yt=(M[0]&(DIRECTION_MASK.EAST|DIRECTION_MASK.WEST))>0?0:1;const ut=yt;let q=0;for(let E=0;E<ot.length;E+=1){const N=ot[E]&15;let j=N===DIRECTION_MASK.EAST?3:N;j+=A,j>4&&(j-=4);const Q=dirVectors[j-1];q=j%2>0?0:1,q!==yt&&(Z++,wayPoints1[Z][0]=wayPoints1[Z-1][0],wayPoints1[Z][1]=wayPoints1[Z-1][1]);const st=(ot[E]&TARGET_MASK)>0,ht=(ot[E]&SOURCE_MASK)>0;let nt=(ot[E]&SIDE_MASK)>>5;nt<<=A,nt>15&&(nt>>=4);const vt=(ot[E]&CENTER_MASK)>0;if((ht||st)&&nt<9){let gt=0;const ft=ht?0:1;if(vt&&q===0?gt=I[ft][0]+V[ft][0]*I[ft][2]:vt?gt=I[ft][1]+V[ft][1]*I[ft][3]:gt=limits[ft][nt],q===0){const mt=wayPoints1[Z][0],Et=(gt-mt)*Q[0];Et>0&&(wayPoints1[Z][0]+=Q[0]*Et)}else{const mt=wayPoints1[Z][1],Et=(gt-mt)*Q[1];Et>0&&(wayPoints1[Z][1]+=Q[1]*Et)}}else vt&&(wayPoints1[Z][0]+=Q[0]*Math.abs(vertexSeparations[j]/2),wayPoints1[Z][1]+=Q[1]*Math.abs(vertexSeparations[j]/2));Z>0&&wayPoints1[Z][q]===wayPoints1[Z-1][q]?Z--:yt=q}for(let E=0;E<=Z&&!(E===Z&&(((M[1]&(DIRECTION_MASK.EAST|DIRECTION_MASK.WEST))>0?0:1)===ut?0:1)!==(Z+1)%2);E+=1)s.push(new Point(Math.round(wayPoints1[E][0]*r.view.scale*10)/10,Math.round(wayPoints1[E][1]*r.view.scale*10)/10));let at=1;for(;at<s.length;)s[at-1]==null||s[at]==null||s[at-1].x!==s[at].x||s[at-1].y!==s[at].y?at++:s.splice(at,1)},ManhattanConnector=(r,t,e,i,s)=>{function n(x,P){return x.x+=P.x||0,x.y+=P.y||0,x.width+=P.width||0,x.height+=P.height||0,x}function l(x,P){return P*Math.round(x/P)}function o(x,P,L){return x.x=l(x.x,P),x.y=l(x.y,P),x}function a(x,P){return P.x>=x.x&&P.x<=x.x+x.width&&P.y>=x.y&&P.y<=x.y+x.height}function h(x){return new Point(x.x+x.width/2,x.y+x.height/2)}function d(x,P){return new Point(x.x-P.x,x.y-P.y)}function c(x,P,L){return x.x+=P||0,x.y+=L||0,x}function u(x,P){const L=P.clone(),O=-(L.y-x.y),A=L.x-x.x,B=10;return 180*(O.toFixed(B)=="0"&&A.toFixed(B)=="0"?0:Math.atan2(O,A))/Math.PI}function g(x){return new Point(x.x===0?0:Math.abs(x.x)/x.x,x.y===0?0:Math.abs(x.y)/x.y)}function f(x,P){return Math.abs(P.x-x.x)+Math.abs(P.y-x.y)}function p(x){const P=x.split(x.includes("@")?"@":" ");return new Point(Number.parseInt(P[0],10),Number.parseInt(P[1],10))}function y(x){return`${x.x}@${x.y}`}function v(x){var k;const P=x.view.graph,L=(k=P.getCellBounds(x.cell,!1,!1))==null?void 0:k.clone();if(!L)return;const O=P.view,{scale:A,translate:B}=O,{x:V,y:_}=B,Y=G=>Math.round(G*10)/10;return new Rectangle(Y(L.x/A-V),Y(L.y/A-_),Y(L.width/A),Y(L.height/A))}const S=ManhattanConnectorConfig.step,w={paddingBox:new Geometry(-S,-S,S*2,S*2),directions:[{offsetX:S,offsetY:0,cost:S,angle:H(u(new Point(0,0),new Point(S,0)))},{offsetX:0,offsetY:S,cost:S,angle:H(u(new Point(0,0),new Point(0,S)))},{offsetX:-S,offsetY:0,cost:S,angle:H(u(new Point(0,0),new Point(-S,0)))},{offsetX:0,offsetY:-S,cost:S,angle:H(u(new Point(0,0),new Point(0,-S)))}],directionMap:{east:{x:1,y:0},south:{x:0,y:1},west:{x:-1,y:0},north:{x:0,y:-1}},penaltiesGenerator:x=>x==45||x==90||x==180?S/2:0,draggingRoute:null,previousDirAngle:0};class C{constructor(P){this.options=P,this.mapGridSize=100,this.map=new Map}build(P,L){const O=(P==null?void 0:P.view.graph)||(L==null?void 0:L.view.graph);if(O)return Array.from(O.getView().getCellStates()).filter(A=>A.cell&&A.cell.isVertex()&&!A.cell.isEdge()).map(A=>v(A)).map(A=>A?n(A,this.options.paddingBox):null).forEach(A=>{if(!A)return;const B=o(new Point(A.x,A.y),this.mapGridSize),V=o(new Point(A.x+A.width,A.y+A.height),this.mapGridSize);for(let _=B.x;_<=V.x;_+=this.mapGridSize)for(let Y=B.y;Y<=V.y;Y+=this.mapGridSize){const D=_+"@"+Y,k=this.map.get(D)||[];this.map.has(D)||this.map.set(D,k),k.push(A)}})}isPointAccessible(P){const L=y(o(P.clone(),this.mapGridSize)),O=this.map.get(L);return O?O.every(A=>!a(A,P)):!0}}class m{constructor(){this.items=[],this.hash=new Map}add(P,L){const O=this.hash.get(P);O?(O.value=L,this.items.splice(this.items.indexOf(P),1)):this.hash.set(P,{value:L,open:!0}),this.items.push(P),this.items.sort((A,B)=>{const V=this.hash.get(A),_=this.hash.get(B);return!V||!_?0:V.value-_.value})}remove(P){const L=this.hash.get(P);L&&(L.open=!1)}isOpen(P){const L=this.hash.get(P);return L&&L.open==!0}isClose(P){const L=this.hash.get(P);return L&&L.open==!1}isEmpty(){return this.items.length==0}pop(){const P=this.items.shift();return P&&this.remove(P),P}}function T(x,P,L,O){const A=[];let B=g(d(O,P)),V=P,_;for(;x[y(V)];){if(_=x[y(V)],!_)continue;const D=g(d(V,_));D.equals(B)||(A.unshift(V),B=D),V=_}return g(d(V,L)).equals(B)||A.unshift(V),A}function b(x,P,L){const O=ManhattanConnectorConfig.step,A=h(x),B=[];for(const V of P){const _=L.directionMap[V],Y=_.x*x.width/2,D=_.y*x.height/2,k=c(A.clone(),Y,D);a(x,k)&&c(k,_.x*O,_.y*O),B.push(o(k,O))}return B}function H(x){return x%360+(x<0?360:0)}function R(x,P,L){const O=360/L;return Math.floor(H(u(x,P)+O/2)/O)*O}function M(x,P){const L=Math.abs(x-P);return L>180?360-L:L}function I(x,P){let L=1/0;for(let O=0,A=P.length;O<A;O++){const B=f(x,P[O]);B<L&&(L=B)}return L}function z(x,P,L,O){const A=v(L),B=O?P.style.exitY:P.style.entryY,V=O?ManhattanConnectorConfig.startDirections.every(D=>D!="north"&&D!="south"):ManhattanConnectorConfig.endDirections.every(D=>D!="north"&&D!="south");if(B!=null&&V){const D=(A==null?void 0:A.height)||0;x.y=(A==null?void 0:A.y)!=null?(A==null?void 0:A.y)+D*B:x.y-D/2+D*B}const _=O?P.style.exitX:P.style.entryX,Y=O?ManhattanConnectorConfig.startDirections.every(D=>D!="west"&&D!="east"):ManhattanConnectorConfig.endDirections.every(D=>D!="west"&&D!="east");if(_!=null&&Y){const D=(A==null?void 0:A.width)||0;x.x=(A==null?void 0:A.x)!=null?(A==null?void 0:A.x)+D*_:x.x-D/2+D*(_||0)}}function $(x,P,L,O){const A=ManhattanConnectorConfig.step,B=b(x,ManhattanConnectorConfig.startDirections,O).filter(D=>L.isPointAccessible(D)),V=o(h(x),A),_=b(P,ManhattanConnectorConfig.endDirections,O).filter(D=>L.isPointAccessible(D)),Y=o(h(P),A);if(B.length>0&&_.length>0){const D=new m,k={},G={};B.forEach(F=>{const K=y(F);D.add(K,I(F,_)),G[K]=0});let W=ManhattanConnectorConfig.maxLoops;const U=_.map(F=>y(F));let J,it;for(;!D.isEmpty()&&W>0;){const F=D.pop();if(F==null)continue;const K=p(F),rt=G[F];if(it=J,J=k[F]?R(k[F],K,O.directions.length):O.previousDirAngle!=0?O.previousDirAngle:R(V,K,O.directions.length),U.includes(F)){const tt=M(J,R(K,Y,O.directions.length));if(K.equals(Y)||tt<180)return O.previousDirAngle=J,T(k,K,V,Y)}for(let tt=0;tt<O.directions.length;tt++){const ot=O.directions[tt],Z=M(J,ot.angle);if(it&&Z>ManhattanConnectorConfig.maxAllowedDirectionChange)continue;const yt=c(K.clone(),ot.offsetX,ot.offsetY),ut=y(yt);if(D.isClose(ut)||!L.isPointAccessible(yt))continue;const q=rt+ot.cost+O.penaltiesGenerator(Z);(!D.isOpen(ut)||q<G[ut])&&(k[ut]=K,G[ut]=q,D.add(ut,q+I(yt,_)))}W--}return null}return null}function et(x,P,L,O,A,B){if(O!=null&&O.length>0||P==null||L==null){SegmentConnector(x,P,L,O,A);return}let V=v(P);V=V?n(V,B.paddingBox):void 0;let _=v(L);_=_?n(_,B.paddingBox):void 0;const Y=new C(B);if(Y.build(P,L),!V||!_)return OrthogonalConnector(x,P,L,O,A);const D=$(V,_,Y,B);if(D==null||D.length==0)return OrthogonalConnector(x,P,L,O,A);x.style&&(x.visibleSourceState&&D.length>0&&z(D[0],x,x.visibleSourceState,!0),x.visibleTargetState&&D.length>1&&z(D[D.length-1],x,x.visibleTargetState,!1));const k=x.view.scale;D.forEach(G=>A.push(new Point(Math.round((G.x+x.view.translate.x)*k*10)/10,Math.round((G.y+x.view.translate.y)*k*10)/10)))}et(r,t,e,i,s,w)},EllipsePerimeter=(r,t,e,i=!1)=>{const{x:s}=r,{y:n}=r,l=r.width/2,o=r.height/2,a=s+l,h=n+o,d=e.x,c=e.y,u=Number.parseInt(String(d-a)),g=Number.parseInt(String(c-h));if(u===0&&g!==0)return new Point(a,h+o*g/Math.abs(g));if(u===0&&g===0)return new Point(d,c);if(i){if(c>=n&&c<=n+r.height){const z=c-h;let $=Math.sqrt(l*l*(1-z*z/(o*o)))||0;return d<=s&&($=-$),new Point(a+$,c)}if(d>=s&&d<=s+r.width){const z=d-a;let $=Math.sqrt(o*o*(1-z*z/(l*l)))||0;return c<=n&&($=-$),new Point(d,h+$)}}const f=g/u,p=h-f*a,y=l*l*f*f+o*o,v=-2*a*y,S=l*l*f*f*a*a+o*o*a*a-l*l*o*o,w=Math.sqrt(v*v-4*y*S),C=(-v+w)/(2*y),m=(-v-w)/(2*y),T=f*C+p,b=f*m+p,H=Math.sqrt(Math.pow(C-d,2)+Math.pow(T-c,2)),R=Math.sqrt(Math.pow(m-d,2)+Math.pow(b-c,2));let M=0,I=0;return H<R?(M=C,I=T):(M=m,I=b),new Point(M,I)},HexagonPerimeter=(r,t,e,i=!1)=>{var T;const{x:s}=r,{y:n}=r,l=r.width,o=r.height,a=r.getCenterX(),h=r.getCenterY(),d=e.x,c=e.y,u=d-a,g=c-h,f=-Math.atan2(g,u),p=Math.PI,y=Math.PI/2;let v=new Point(a,h);const S=((T=t==null?void 0:t.style)==null?void 0:T.direction)??"east",w=S==="north"||S==="south";let C=new Point,m=new Point;if((d<s&&c<n||d<s&&c>n+o||d>s+l&&c<n||d>s+l&&c>n+o)&&(i=!1),i){if(w){if(d===a){if(c<=n)return new Point(a,n);if(c>=n+o)return new Point(a,n+o)}else if(d<s){if(c===n+o/4)return new Point(s,n+o/4);if(c===n+3*o/4)return new Point(s,n+3*o/4)}else if(d>s+l){if(c===n+o/4)return new Point(s+l,n+o/4);if(c===n+3*o/4)return new Point(s+l,n+3*o/4)}else if(d===s){if(c<h)return new Point(s,n+o/4);if(c>h)return new Point(s,n+3*o/4)}else if(d===s+l){if(c<h)return new Point(s+l,n+o/4);if(c>h)return new Point(s+l,n+3*o/4)}if(c===n)return new Point(a,n);if(c===n+o)return new Point(a,n+o);d<a?c>n+o/4&&c<n+3*o/4?(C=new Point(s,n),m=new Point(s,n+o)):c<n+o/4?(C=new Point(s-Math.floor(.5*l),n+Math.floor(.5*o)),m=new Point(s+l,n-Math.floor(.25*o))):c>n+3*o/4&&(C=new Point(s-Math.floor(.5*l),n+Math.floor(.5*o)),m=new Point(s+l,n+Math.floor(1.25*o))):d>a&&(c>n+o/4&&c<n+3*o/4?(C=new Point(s+l,n),m=new Point(s+l,n+o)):c<n+o/4?(C=new Point(s,n-Math.floor(.25*o)),m=new Point(s+Math.floor(1.5*l),n+Math.floor(.5*o))):c>n+3*o/4&&(C=new Point(s+Math.floor(1.5*l),n+Math.floor(.5*o)),m=new Point(s,n+Math.floor(1.25*o))))}else{if(c===h){if(d<=s)return new Point(s,n+o/2);if(d>=s+l)return new Point(s+l,n+o/2)}else if(c<n){if(d===s+l/4)return new Point(s+l/4,n);if(d===s+3*l/4)return new Point(s+3*l/4,n)}else if(c>n+o){if(d===s+l/4)return new Point(s+l/4,n+o);if(d===s+3*l/4)return new Point(s+3*l/4,n+o)}else if(c===n){if(d<a)return new Point(s+l/4,n);if(d>a)return new Point(s+3*l/4,n)}else if(c===n+o){if(d<a)return new Point(s+l/4,n+o);if(c>h)return new Point(s+3*l/4,n+o)}if(d===s)return new Point(s,h);if(d===s+l)return new Point(s+l,h);c<h?d>s+l/4&&d<s+3*l/4?(C=new Point(s,n),m=new Point(s+l,n)):d<s+l/4?(C=new Point(s-Math.floor(.25*l),n+o),m=new Point(s+Math.floor(.5*l),n-Math.floor(.5*o))):d>s+3*l/4&&(C=new Point(s+Math.floor(.5*l),n-Math.floor(.5*o)),m=new Point(s+Math.floor(1.25*l),n+o)):c>h&&(d>s+l/4&&d<s+3*l/4?(C=new Point(s,n+o),m=new Point(s+l,n+o)):d<s+l/4?(C=new Point(s-Math.floor(.25*l),n),m=new Point(s+Math.floor(.5*l),n+Math.floor(1.5*o))):d>s+3*l/4&&(C=new Point(s+Math.floor(.5*l),n+Math.floor(1.5*o)),m=new Point(s+Math.floor(1.25*l),n)))}let b=a,H=h;d>=s&&d<=s+l?(b=d,c<h?H=n+o:H=n):c>=n&&c<=n+o&&(H=c,d<a?b=s+l:b=s),v=intersection(b,H,e.x,e.y,C.x,C.y,m.x,m.y)}else{if(w){const b=Math.atan2(o/4,l/2);if(f===b)return new Point(s+l,n+Math.floor(.25*o));if(f===y)return new Point(s+Math.floor(.5*l),n);if(f===p-b)return new Point(s,n+Math.floor(.25*o));if(f===-b)return new Point(s+l,n+Math.floor(.75*o));if(f===-y)return new Point(s+Math.floor(.5*l),n+o);if(f===-p+b)return new Point(s,n+Math.floor(.75*o));f<b&&f>-b?(C=new Point(s+l,n),m=new Point(s+l,n+o)):f>b&&f<y?(C=new Point(s,n-Math.floor(.25*o)),m=new Point(s+Math.floor(1.5*l),n+Math.floor(.5*o))):f>y&&f<p-b?(C=new Point(s-Math.floor(.5*l),n+Math.floor(.5*o)),m=new Point(s+l,n-Math.floor(.25*o))):f>p-b&&f<=p||f<-p+b&&f>=-p?(C=new Point(s,n),m=new Point(s,n+o)):f<-b&&f>-y?(C=new Point(s+Math.floor(1.5*l),n+Math.floor(.5*o)),m=new Point(s,n+Math.floor(1.25*o))):f<-y&&f>-p+b&&(C=new Point(s-Math.floor(.5*l),n+Math.floor(.5*o)),m=new Point(s+l,n+Math.floor(1.25*o)))}else{const b=Math.atan2(o/2,l/4);if(f===b)return new Point(s+Math.floor(.75*l),n);if(f===p-b)return new Point(s+Math.floor(.25*l),n);if(f===p||f===-p)return new Point(s,n+Math.floor(.5*o));if(f===0)return new Point(s+l,n+Math.floor(.5*o));if(f===-b)return new Point(s+Math.floor(.75*l),n+o);if(f===-p+b)return new Point(s+Math.floor(.25*l),n+o);f>0&&f<b?(C=new Point(s+Math.floor(.5*l),n-Math.floor(.5*o)),m=new Point(s+Math.floor(1.25*l),n+o)):f>b&&f<p-b?(C=new Point(s,n),m=new Point(s+l,n)):f>p-b&&f<p?(C=new Point(s-Math.floor(.25*l),n+o),m=new Point(s+Math.floor(.5*l),n-Math.floor(.5*o))):f<0&&f>-b?(C=new Point(s+Math.floor(.5*l),n+Math.floor(1.5*o)),m=new Point(s+Math.floor(1.25*l),n)):f<-b&&f>-p+b?(C=new Point(s,n+o),m=new Point(s+l,n+o)):f<-p+b&&f>-p&&(C=new Point(s-Math.floor(.25*l),n),m=new Point(s+Math.floor(.5*l),n+Math.floor(1.5*o)))}v=intersection(a,h,e.x,e.y,C.x,C.y,m.x,m.y)}return v??new Point(a,h)},RectanglePerimeter=(r,t,e,i=!1)=>{const s=r.getCenterX(),n=r.getCenterY(),l=e.x-s,o=e.y-n,a=Math.atan2(o,l),h=new Point(0,0),d=Math.PI,u=Math.PI/2-a,g=Math.atan2(r.height,r.width);return a<-d+g||a>d-g?(h.x=r.x,h.y=n-r.width*Math.tan(a)/2):a<-g?(h.y=r.y,h.x=s-r.height*Math.tan(u)/2):a<g?(h.x=r.x+r.width,h.y=n+r.width*Math.tan(a)/2):(h.y=r.y+r.height,h.x=s+r.height*Math.tan(u)/2),i&&(e.x>=r.x&&e.x<=r.x+r.width?h.x=e.x:e.y>=r.y&&e.y<=r.y+r.height&&(h.y=e.y),e.x<r.x?h.x=r.x:e.x>r.x+r.width&&(h.x=r.x+r.width),e.y<r.y?h.y=r.y:e.y>r.y+r.height&&(h.y=r.y+r.height)),h},RhombusPerimeter=(r,t,e,i=!1)=>{const{x:s}=r,{y:n}=r,l=r.width,o=r.height,a=s+l/2,h=n+o/2,d=e.x,c=e.y;if(a===d)return h>c?new Point(a,n):new Point(a,n+o);if(h===c)return a>d?new Point(s,h):new Point(s+l,h);let u=a,g=h;return i&&(d>=s&&d<=s+l?u=d:c>=n&&c<=n+o&&(g=c)),d<a?c<h?intersection(d,c,u,g,a,n,s,h):intersection(d,c,u,g,a,n+o,s,h):c<h?intersection(d,c,u,g,a,n,s+l,h):intersection(d,c,u,g,a,n+o,s+l,h)},TrianglePerimeter=(r,t,e,i=!1)=>{const s=t!=null?t.style.direction:null,n=s==="north"||s==="south",{x:l}=r,{y:o}=r,a=r.width,h=r.height;let d=l+a/2,c=o+h/2,u=new Point(l,o),g=new Point(l+a,c),f=new Point(l,o+h);switch(s){case"north":{u=f,g=new Point(d,o),f=new Point(l+a,o+h);break}case"south":{g=new Point(d,o+h),f=new Point(l+a,o);break}case"west":{u=new Point(l+a,o),g=new Point(l,c),f=new Point(l+a,o+h);break}}let p=e.x-d,y=e.y-c;const v=n?Math.atan2(p,y):Math.atan2(y,p),S=n?Math.atan2(a,h):Math.atan2(h,a);let w=!1;s==="north"||s==="west"?w=v>-S&&v<S:w=v<-Math.PI+S||v>Math.PI-S;let C=null;if(w)if(i&&(n&&e.x>=u.x&&e.x<=f.x||!n&&e.y>=u.y&&e.y<=f.y))n?C=new Point(e.x,u.y):C=new Point(u.x,e.y);else switch(s){case"north":{C=new Point(l+a/2+h*Math.tan(v)/2,o+h);break}case"south":{C=new Point(l+a/2-h*Math.tan(v)/2,o);break}case"west":{C=new Point(l+a,o+h/2+a*Math.tan(v)/2);break}default:C=new Point(l,o+h/2-a*Math.tan(v)/2)}else{if(i){const m=new Point(d,c);e.y>=o&&e.y<=o+h?(m.x=n?d:s==="west"?l+a:l,m.y=e.y):e.x>=l&&e.x<=l+a&&(m.x=e.x,m.y=n?s==="north"?o+h:o:c),p=e.x-m.x,y=e.y-m.y,d=m.x,c=m.y}n&&e.x<=l+a/2||!n&&e.y<=o+h/2?C=intersection(e.x,e.y,d,c,u.x,u.y,g.x,g.y):C=intersection(e.x,e.y,d,c,g.x,g.y,f.x,f.y)}return C==null&&(C=new Point(d,c)),C},isClassicOrClassicThin=r=>r==="classic"||r==="classicThin",isDiamond=r=>r==="diamond",createArrow=r=>(t,e,i,s,n,l,o,a,h,d)=>{const c=n*h*1.118,u=l*h*1.118;n*=o+h,l*=o+h;const g=s.clone();g.x-=c,g.y-=u;const f=isClassicOrClassicThin(i)?3/4:1;return s.x+=-n*f-c,s.y+=-l*f-u,()=>{t.begin(),t.moveTo(g.x,g.y),t.lineTo(g.x-n-l/r,g.y-l+n/r),isClassicOrClassicThin(i)&&t.lineTo(g.x-n*3/4,g.y-l*3/4),t.lineTo(g.x+l/r-n,g.y-l-n/r),t.close(),d?t.fillAndStroke():t.stroke()}},createOpenArrow=r=>(t,e,i,s,n,l,o,a,h,d)=>{const c=n*h*1.118,u=l*h*1.118;n*=o+h,l*=o+h;const g=s.clone();return g.x-=c,g.y-=u,s.x+=-c*2,s.y+=-u*2,()=>{t.begin(),t.moveTo(g.x-n-l/r,g.y-l+n/r),t.lineTo(g.x,g.y),t.lineTo(g.x+l/r-n,g.y-l-n/r),t.stroke()}},oval=(r,t,e,i,s,n,l,o,a,h)=>{const d=l/2,c=i.clone();return i.x-=s*d,i.y-=n*d,()=>{r.ellipse(c.x-d,c.y-d,l,l),h?r.fillAndStroke():r.stroke()}},diamond=(r,t,e,i,s,n,l,o,a,h)=>{const d=isDiamond(e)?.7071:.9862,c=s*a*d,u=n*a*d;s*=l+a,n*=l+a;const g=i.clone();g.x-=c,g.y-=u,i.x+=-s-c,i.y+=-n-u;const f=isDiamond(e)?2:3.4;return()=>{r.begin(),r.moveTo(g.x,g.y),r.lineTo(g.x-s/2-n/f,g.y+s/f-n/2),r.lineTo(g.x-s,g.y-n),r.lineTo(g.x-s/2+n/f,g.y-n/2-s/f),r.close(),h?r.fillAndStroke():r.stroke()}};class BaseRegistry{constructor(){this.values=new Map}add(t,e){this.values.set(t,e)}get(t){return this.values.get(t)??null}getName(t){for(const[e,i]of this.values.entries())if(i===t)return e;return null}clear(){this.values.clear()}}class EdgeStyleRegistryImpl extends BaseRegistry{constructor(){super(...arguments),this.handlerMapping=new Map,this.orthogonalStates=new Map,this.intermediateHandlesStates=new Map}add(t,e,i){super.add(t,e),i!=null&&i.handlerKind&&this.handlerMapping.set(e,i.handlerKind),!isNullish(i==null?void 0:i.isOrthogonal)&&this.orthogonalStates.set(e,i.isOrthogonal),!isNullish(i==null?void 0:i.allowIntermediateHandles)&&this.intermediateHandlesStates.set(e,i.allowIntermediateHandles)}isOrthogonal(t){return this.orthogonalStates.get(t)??!1}getHandlerKind(t){return this.handlerMapping.get(t)??"default"}allowsIntermediateHandles(t){return this.intermediateHandlesStates.get(t)??!0}clear(){super.clear(),this.handlerMapping.clear(),this.orthogonalStates.clear(),this.intermediateHandlesStates.clear()}}const EdgeStyleRegistry=new EdgeStyleRegistryImpl;class CellHighlight{constructor(t,e,i,s){this.strokeWidth=0,this.dashed=!1,this.opacity=100,this.shape=null,this.keepOnTop=!1,this.state=null,this.spacing=2,this.graph=t,this.highlightColor=e??DEFAULT_VALID_COLOR,this.strokeWidth=i??HIGHLIGHT_STROKEWIDTH,this.dashed=s??!1,this.opacity=HIGHLIGHT_OPACITY,this.repaintHandler=()=>{if(this.state){const n=this.graph.view.getState(this.state.cell);n?(this.state=n,this.repaint()):this.hide()}},this.graph.getView().addListener(InternalEvent.SCALE,this.repaintHandler),this.graph.getView().addListener(InternalEvent.TRANSLATE,this.repaintHandler),this.graph.getView().addListener(InternalEvent.SCALE_AND_TRANSLATE,this.repaintHandler),this.graph.getDataModel().addListener(InternalEvent.CHANGE,this.repaintHandler),this.resetHandler=()=>{this.hide()},this.graph.getView().addListener(InternalEvent.DOWN,this.resetHandler),this.graph.getView().addListener(InternalEvent.UP,this.resetHandler)}setHighlightColor(t){this.highlightColor=t,this.shape&&(this.shape.stroke=t)}drawHighlight(){var t;if(this.shape=this.createShape(),this.repaint(),this.shape){const e=this.shape.node;!this.keepOnTop&&((t=e==null?void 0:e.parentNode)==null?void 0:t.firstChild)!==e&&e.parentNode&&e.parentNode.insertBefore(e,e.parentNode.firstChild)}}createShape(){if(!this.state)return null;const t=this.graph.cellRenderer.createShape(this.state);return t.svgStrokeTolerance=this.graph.getEventTolerance(),t.points=this.state.absolutePoints,t.apply(this.state),t.stroke=this.highlightColor,t.opacity=this.opacity,t.isDashed=this.dashed,t.isShadow=!1,t.dialect="svg",t.init(this.graph.getView().getOverlayPane()),InternalEvent.redirectMouseEvents(t.node,this.graph,this.state),this.graph.dialect!=="svg"?t.pointerEvents=!1:t.svgPointerEvents="stroke",t}getStrokeWidth(t=null){return this.strokeWidth}repaint(){this.state&&this.shape&&(this.shape.scale=this.state.view.scale,this.state.cell.isEdge()?(this.shape.strokeWidth=this.getStrokeWidth(),this.shape.points=this.state.absolutePoints,this.shape.outline=!1):(this.shape.bounds=new Rectangle(this.state.x-this.spacing,this.state.y-this.spacing,this.state.width+2*this.spacing,this.state.height+2*this.spacing),this.shape.rotation=this.state.style.rotation??0,this.shape.strokeWidth=this.getStrokeWidth()/this.state.view.scale,this.shape.outline=!0),this.state.shape&&this.shape.setCursor(this.state.shape.getCursor()),this.shape.redraw())}hide(){this.highlight(null)}highlight(t=null){this.state!==t&&(this.shape&&(this.shape.destroy(),this.shape=null),this.state=t,this.state&&this.drawHighlight())}isHighlightAt(t,e){let i=!1;if(this.shape&&document.elementFromPoint){let s=document.elementFromPoint(t,e);for(;s;){if(s===this.shape.node){i=!0;break}s=s.parentNode}}return i}destroy(){const t=this.graph;t.getView().removeListener(this.resetHandler),t.getView().removeListener(this.repaintHandler),t.getDataModel().removeListener(this.repaintHandler),this.shape&&(this.shape.destroy(),this.shape=null)}}class CellMarker extends EventSource{constructor(t,e=DEFAULT_VALID_COLOR,i=DEFAULT_INVALID_COLOR,s=DEFAULT_HOTSPOT){super(),this.enabled=!0,this.hotspot=DEFAULT_HOTSPOT,this.hotspotEnabled=!1,this.currentColor=NONE,this.validState=null,this.markedState=null,this.graph=t,this.validColor=e,this.invalidColor=i,this.hotspot=s,this.highlight=this.createCellHighlight(t)}createCellHighlight(t){return new CellHighlight(t)}setEnabled(t){this.enabled=t}isEnabled(){return this.enabled}setHotspot(t){this.hotspot=t}getHotspot(){return this.hotspot}setHotspotEnabled(t){this.hotspotEnabled=t}isHotspotEnabled(){return this.hotspotEnabled}hasValidState(){return!!this.validState}getValidState(){return this.validState}getMarkedState(){return this.markedState}reset(){this.validState=null,this.markedState&&(this.markedState=null,this.unmark())}process(t){let e=null;return this.isEnabled()&&(e=this.getState(t),this.setCurrentState(e,t)),e}setCurrentState(t,e,i){const s=t?this.isValidState(t):!1;i=i??this.getMarkerColor(e.getEvent(),t,s),s?this.validState=t:this.validState=null,(t!==this.markedState||i!==this.currentColor)&&(this.currentColor=i,t&&this.currentColor!==NONE?(this.markedState=t,this.mark()):this.markedState&&(this.markedState=null,this.unmark()))}markCell(t,e){const i=this.graph.getView().getState(t);i&&(this.currentColor=e??this.validColor,this.markedState=i,this.mark())}mark(){this.highlight.setHighlightColor(this.currentColor),this.highlight.highlight(this.markedState),this.fireEvent(new EventObject(InternalEvent.MARK,"state",this.markedState))}unmark(){this.mark()}isValidState(t){return!0}getMarkerColor(t,e,i){return i?this.validColor:this.invalidColor}getState(t){const e=this.graph.getView(),i=this.getCell(t);if(!i)return null;const s=this.getStateToMark(e.getState(i));return s&&this.intersects(s,t)?s:null}getCell(t){return t.getCell()}getStateToMark(t){return t}intersects(t,e){const i=e.getGraphX(),s=e.getGraphY();return this.hotspotEnabled?intersectsHotspot(t,i,s,this.hotspot,MIN_HOTSPOT_SIZE,MAX_HOTSPOT_SIZE):!0}destroy(){this.highlight.destroy(),super.destroy()}}class UrlConverter{constructor(){this.enabled=!0,this.baseUrl=null,this.baseDomain=null}updateBaseUrl(){this.baseDomain=`${location.protocol}//${location.host}`,this.baseUrl=this.baseDomain+location.pathname;const t=this.baseUrl.lastIndexOf("/");t>0&&(this.baseUrl=this.baseUrl.substring(0,t+1))}isEnabled(){return this.enabled}setEnabled(t){this.enabled=t}getBaseUrl(){return this.baseUrl}setBaseUrl(t){this.baseUrl=t}getBaseDomain(){return this.baseDomain}setBaseDomain(t){this.baseDomain=t}isRelativeUrl(t){return t&&t.substring(0,2)!=="//"&&t.substring(0,7)!=="http://"&&t.substring(0,8)!=="https://"&&t.substring(0,10)!=="data:image"&&t.substring(0,7)!=="file://"}convert(t){return this.isEnabled()&&this.isRelativeUrl(t)&&(this.getBaseUrl()||this.updateBaseUrl(),t.charAt(0)==="/"?t=this.getBaseDomain()+t:t=this.getBaseUrl()+t),t}}class AbstractCanvas2D{constructor(){this.state=this.createState(),this.states=[],this.path=[],this.rotateHtml=!0,this.lastX=0,this.lastY=0,this.moveOp="M",this.lineOp="L",this.quadOp="Q",this.curveOp="C",this.closeOp="Z",this.pointerEvents=!1,this.pointerEventsValue=null,this.addOp=(t,...e)=>{if(this.path.push(t),e.length>1){const i=this.state;for(let s=1;s<e.length;s+=2)this.lastX=e[s-1],this.lastY=e[s],this.path.push(this.format((this.lastX+i.dx)*i.scale)),this.path.push(this.format((this.lastY+i.dy)*i.scale))}},this.converter=this.createUrlConverter(),this.reset()}createUrlConverter(){return new UrlConverter}reset(){this.state=this.createState(),this.states=[]}createState(){return{dx:0,dy:0,scale:1,alpha:1,fillAlpha:1,strokeAlpha:1,fillColor:NONE,gradientFillAlpha:1,gradientColor:NONE,gradientAlpha:1,gradientDirection:"east",strokeColor:NONE,strokeWidth:1,dashed:!1,dashPattern:"3 3",fixDash:!1,lineCap:"flat",lineJoin:"miter",miterLimit:10,fontColor:"#000000",fontBackgroundColor:NONE,fontBorderColor:NONE,fontSize:StyleDefaultsConfig.fontSize,fontFamily:StyleDefaultsConfig.fontFamily,fontStyle:0,shadow:!1,shadowColor:StyleDefaultsConfig.shadowColor,shadowAlpha:StyleDefaultsConfig.shadowOpacity,shadowDx:StyleDefaultsConfig.shadowOffsetX,shadowDy:StyleDefaultsConfig.shadowOffsetY,rotation:0,rotationCx:0,rotationCy:0}}format(t){return Math.round(t)}rotatePoint(t,e,i,s,n){const l=i*(Math.PI/180);return getRotatedPoint(new Point(t,e),Math.cos(l),Math.sin(l),new Point(s,n))}save(){this.states.push(this.state),this.state=clone(this.state)}restore(){const t=this.states.pop();t&&(this.state=t)}setLink(t){}scale(t){this.state.scale*=t,this.state.strokeWidth!==null&&(this.state.strokeWidth*=t)}translate(t,e){this.state.dx+=t,this.state.dy+=e}rotate(t,e,i,s,n){}setAlpha(t){this.state.alpha=t}setFillAlpha(t){this.state.fillAlpha=t}setStrokeAlpha(t){this.state.strokeAlpha=t}setFillColor(t){this.state.fillColor=t??NONE,this.state.gradientColor=NONE}setGradient(t,e,i,s,n,l,o,a=1,h=1){const d=this.state;d.fillColor=t,d.gradientFillAlpha=a,d.gradientColor=e,d.gradientAlpha=h,d.gradientDirection=o}setStrokeColor(t){this.state.strokeColor=t??NONE}setStrokeWidth(t){this.state.strokeWidth=t}setDashed(t,e=!1){this.state.dashed=t,this.state.fixDash=e}setDashPattern(t){this.state.dashPattern=t}setLineCap(t){this.state.lineCap=t}setLineJoin(t){this.state.lineJoin=t}setMiterLimit(t){this.state.miterLimit=t}setFontColor(t){this.state.fontColor=t??NONE}setFontBackgroundColor(t){this.state.fontBackgroundColor=t??NONE}setFontBorderColor(t){this.state.fontBorderColor=t??NONE}setFontSize(t){this.state.fontSize=t}setFontFamily(t){this.state.fontFamily=t}setFontStyle(t){this.state.fontStyle=t}setShadow(t){this.state.shadow=t}setShadowColor(t){this.state.shadowColor=t??NONE}setShadowAlpha(t){this.state.shadowAlpha=t}setShadowOffset(t,e){this.state.shadowDx=t,this.state.shadowDy=e}begin(){this.lastX=0,this.lastY=0,this.path=[]}moveTo(t,e){this.addOp(this.moveOp,t,e)}lineTo(t,e){this.addOp(this.lineOp,t,e)}quadTo(t,e,i,s){this.addOp(this.quadOp,t,e,i,s)}curveTo(t,e,i,s,n,l){this.addOp(this.curveOp,t,e,i,s,n,l)}arcTo(t,e,i,s,n,l,o){const a=arcToCurves(this.lastX,this.lastY,t,e,i,s,n,l,o);if(a!=null)for(let h=0;h<a.length;h+=6)this.curveTo(a[h],a[h+1],a[h+2],a[h+3],a[h+4],a[h+5])}close(t,e,i,s,n,l){this.addOp(this.closeOp)}}const parseXml=r=>new DOMParser().parseFromString(r,"text/xml"),getXml=(r,t="&#xa;")=>{let i=new XMLSerializer().serializeToString(r);return i=i.replace(/\n/g,t),i},useAbsoluteIds=typeof DOMParser=="function"&&!Client.IS_CHROMEAPP&&!Client.IS_EDGE&&document.getElementsByTagName("base").length>0;class SvgCanvas2D extends AbstractCanvas2D{constructor(t,e){super(),this.defs=null,this.styleEnabled=!0,this.node=null,this.matchHtmlAlignment=!0,this.textEnabled=!0,this.foEnabled=!0,this.foAltText="[Object]",this.foOffset=0,this.textOffset=0,this.imageOffset=0,this.strokeTolerance=0,this.minStrokeWidth=1,this.refCount=0,this.lineHeightCorrection=1,this.pointerEventsValue="all",this.fontMetricsPadding=10,this.cacheOffsetSize=!0,this.originalRoot=null,this.root=t,this.gradients={},this.defs=null,this.styleEnabled=e??!1;let i=null;if(t.ownerDocument!==document){let s=t;for(;s&&s.nodeName!=="svg";)s=s.parentElement;i=s}i&&(i.getElementsByTagName("defs").length>0&&(this.defs=i.getElementsByTagName("defs")[0]),this.defs||(this.defs=this.createElement("defs"),i.firstChild!=null?i.insertBefore(this.defs,i.firstChild):i.appendChild(this.defs)),this.styleEnabled&&this.defs.appendChild(this.createStyle()))}format(t){return Number.parseFloat(t.toFixed(2))}getBaseUrl(){let{href:t}=window.location;const e=t.lastIndexOf("#");return e>0&&(t=t.substring(0,e)),t}reset(){super.reset(),this.gradients={}}end(){}createStyle(){const t=this.createElement("style");return t.setAttribute("type","text/css"),write(t,`svg{font-family:${StyleDefaultsConfig.fontFamily};font-size:${StyleDefaultsConfig.fontSize};fill:none;stroke-miterlimit:10}`),t}createElement(t,e){var i;return(i=this.root)==null?void 0:i.ownerDocument.createElementNS(e||NS_SVG,t)}getAlternateText(t,e,i,s,n,l,o,a,h,d,c,u,g){return isNullish(l)?null:this.foAltText}createAlternateContent(t,e,i,s,n,l,o,a,h,d,c,u,g){const f=this.getAlternateText(t,e,i,s,n,l,o,a,h,d,c,u,g),p=this.state;if(!isNullish(f)&&p.fontSize>0){const y=a==="top"?1:a==="bottom"?0:.3,v=o==="right"?"end":o==="left"?"start":"middle",S=this.createElement("text");S.setAttribute("x",String(Math.round(e+p.dx))),S.setAttribute("y",String(Math.round(i+p.dy+y*p.fontSize))),S.setAttribute("fill",p.fontColor||"black"),S.setAttribute("font-family",p.fontFamily),S.setAttribute("font-size",`${Math.round(p.fontSize)}px`),v!=="start"&&S.setAttribute("text-anchor",v);const w=p.fontStyle;matchBinaryMask(w,FONT_STYLE_MASK.BOLD)&&S.setAttribute("font-weight","bold"),matchBinaryMask(w,FONT_STYLE_MASK.ITALIC)&&S.setAttribute("font-style","italic");const C=[];return matchBinaryMask(w,FONT_STYLE_MASK.UNDERLINE)&&C.push("underline"),matchBinaryMask(w,FONT_STYLE_MASK.STRIKETHROUGH)&&C.push("line-through"),C.length>0&&S.setAttribute("text-decoration",C.join(" ")),write(S,f),S}return null}createGradientId(t,e,i,s,n){t.charAt(0)==="#"&&(t=t.substring(1)),e.charAt(0)==="#"&&(e=e.substring(1)),t=`${t.toLowerCase()}-${i}`,e=`${e.toLowerCase()}-${s}`;let l=null;if(n==null||n==="south")l="s";else if(n==="east")l="e";else{const o=t;t=e,e=o,n==="north"?l="s":n==="west"&&(l="e")}return`mx-gradient-${t}-${e}-${l}`}getSvgGradient(t,e,i,s,n){const l=this.createGradientId(t,e,i,s,n);let o=this.gradients[l];if(!o){const a=this.root.ownerSVGElement;let h=0,d=`${l}-${h}`;if(a)for(o=a.ownerDocument.getElementById(d);o&&o.ownerSVGElement!==a;)d=`${l}-${h++}`,o=a.ownerDocument.getElementById(d);else d=`id${++this.refCount}`;o||(o=this.createSvgGradient(t,e,i,s,n),o.setAttribute("id",d),this.defs?this.defs.appendChild(o):a&&a.appendChild(o)),this.gradients[l]=o}return o.getAttribute("id")}createSvgGradient(t,e,i,s,n){const l=this.createElement("linearGradient");if(l.setAttribute("x1","0%"),l.setAttribute("y1","0%"),l.setAttribute("x2","0%"),l.setAttribute("y2","0%"),n==null||n==="south")l.setAttribute("y2","100%");else switch(n){case"east":{l.setAttribute("x2","100%");break}case"north":{l.setAttribute("y1","100%");break}case"west":{l.setAttribute("x1","100%");break}}let o=i<1?`;stop-opacity:${i}`:"",a=this.createElement("stop");return a.setAttribute("offset","0%"),a.setAttribute("style",`stop-color:${t}${o}`),l.appendChild(a),o=s<1?`;stop-opacity:${s}`:"",a=this.createElement("stop"),a.setAttribute("offset","100%"),a.setAttribute("style",`stop-color:${e}${o}`),l.appendChild(a),l}addNode(t,e){const{node:i}=this,s=this.state;if(i){if(i.nodeName==="path")if(this.path&&this.path.length>0)i.setAttribute("d",this.path.join(" "));else return;t&&s.fillColor!==NONE?this.updateFill():this.styleEnabled||(i.nodeName==="ellipse"&&Client.IS_FF?i.setAttribute("fill","transparent"):i.setAttribute("fill",NONE),t=!1),e&&s.strokeColor!==NONE?this.updateStroke():this.styleEnabled||i.setAttribute("stroke",NONE),s.transform&&s.transform.length>0&&i.setAttribute("transform",s.transform),s.shadow&&this.root.appendChild(this.createShadow(i)),this.strokeTolerance>0&&!t&&this.root.appendChild(this.createTolerance(i)),this.pointerEvents?i.setAttribute("pointer-events",this.pointerEventsValue):!this.pointerEvents&&!this.originalRoot&&i.setAttribute("pointer-events",NONE),(i.nodeName!=="rect"&&i.nodeName!=="path"&&i.nodeName!=="ellipse"||i.getAttribute("fill")!==NONE&&i.getAttribute("fill")!=="transparent"||i.getAttribute("stroke")!==NONE||i.getAttribute("pointer-events")!==NONE)&&this.root.appendChild(i),this.node=null}}updateFill(){var e;const t=this.state;if((t.alpha<1||t.fillAlpha<1)&&this.node.setAttribute("fill-opacity",String(t.alpha*t.fillAlpha)),t.fillColor!==NONE)if(t.gradientColor!==NONE){const i=this.getSvgGradient(t.fillColor,t.gradientColor,t.gradientFillAlpha,t.gradientAlpha,t.gradientDirection);if(((e=this.root)==null?void 0:e.ownerDocument)===document&&useAbsoluteIds){const s=this.getBaseUrl().replace(/([()])/g,"\\$1");this.node.setAttribute("fill",`url(${s}#${i})`)}else this.node.setAttribute("fill",`url(#${i})`)}else this.node.setAttribute("fill",t.fillColor.toLowerCase())}getCurrentStrokeWidth(){return Math.max(this.minStrokeWidth,Math.max(.01,this.format(this.state.strokeWidth*this.state.scale)))}updateStroke(){const t=this.state;t.strokeColor&&t.strokeColor!==NONE&&this.node.setAttribute("stroke",t.strokeColor.toLowerCase()),(t.alpha<1||t.strokeAlpha<1)&&this.node.setAttribute("stroke-opacity",String(t.alpha*t.strokeAlpha));const e=this.getCurrentStrokeWidth();e!==1&&this.node.setAttribute("stroke-width",String(e)),this.node.nodeName==="path"&&this.updateStrokeAttributes(),t.dashed&&this.node.setAttribute("stroke-dasharray",this.createDashPattern((t.fixDash?1:t.strokeWidth)*t.scale))}updateStrokeAttributes(){const t=this.state;if(t.lineJoin&&t.lineJoin!=="miter"&&this.node.setAttribute("stroke-linejoin",t.lineJoin),t.lineCap){let e=t.lineCap;e==="flat"&&(e="butt"),e!=="butt"&&this.node.setAttribute("stroke-linecap",e)}t.miterLimit!=null&&(!this.styleEnabled||t.miterLimit!==10)&&this.node.setAttribute("stroke-miterlimit",String(t.miterLimit))}createDashPattern(t){const e=[];if(typeof this.state.dashPattern=="string"){const i=this.state.dashPattern.split(" ");if(i.length>0)for(let s=0;s<i.length;s+=1)e[s]=Number(i[s])*t}return e.join(" ")}createTolerance(t){const e=t.cloneNode(!0),i=Number.parseFloat(e.getAttribute("stroke-width")||"1")+this.strokeTolerance;return e.setAttribute("pointer-events","stroke"),e.setAttribute("visibility","hidden"),e.removeAttribute("stroke-dasharray"),e.setAttribute("stroke-width",String(i)),e.setAttribute("fill","none"),e.setAttribute("stroke","white"),e}createShadow(t){const e=t.cloneNode(!0),i=this.state;return e.getAttribute("fill")!=="none"&&(!Client.IS_FF||e.getAttribute("fill")!=="transparent")&&e.setAttribute("fill",i.shadowColor),e.getAttribute("stroke")!=="none"&&i.shadowColor&&i.shadowColor!==NONE&&e.setAttribute("stroke",i.shadowColor),e.setAttribute("transform",`translate(${this.format(i.shadowDx*i.scale)},${this.format(i.shadowDy*i.scale)})${i.transform||""}`),e.setAttribute("opacity",String(i.shadowAlpha)),e}setLink(t){if(!t)this.root=this.originalRoot;else{this.originalRoot=this.root;const e=this.createElement("a");e.setAttributeNS==null||this.root.ownerDocument!==document?e.setAttribute("xlink:href",t):e.setAttributeNS(NS_XLINK,"xlink:href",t),this.root.appendChild(e),this.root=e}}rotate(t,e,i,s,n){if(t!==0||e||i){const l=this.state;if(s+=l.dx,n+=l.dy,s*=l.scale,n*=l.scale,l.transform=l.transform||"",e&&i)t+=180;else if(e!==i){const o=e?s:0,a=e?-1:1,h=i?n:0,d=i?-1:1;l.transform+=`translate(${this.format(o)},${this.format(h)})scale(${this.format(a)},${this.format(d)})translate(${this.format(-o)},${this.format(-h)})`}(e?!i:i)&&(t*=-1),t!==0&&(l.transform+=`rotate(${this.format(t)},${this.format(s)},${this.format(n)})`),l.rotation+=t,l.rotationCx=s,l.rotationCy=n}}begin(){super.begin(),this.node=this.createElement("path")}rect(t,e,i,s){const n=this.state,l=this.createElement("rect");l.setAttribute("x",String(this.format((t+n.dx)*n.scale))),l.setAttribute("y",String(this.format((e+n.dy)*n.scale))),l.setAttribute("width",String(this.format(i*n.scale))),l.setAttribute("height",String(this.format(s*n.scale))),this.node=l}roundrect(t,e,i,s,n,l){this.rect(t,e,i,s),n>0&&this.node.setAttribute("rx",String(this.format(n*this.state.scale))),l>0&&this.node.setAttribute("ry",String(this.format(l*this.state.scale)))}ellipse(t,e,i,s){const n=this.state,l=this.createElement("ellipse");l.setAttribute("cx",String(this.format((t+i/2+n.dx)*n.scale))),l.setAttribute("cy",String(this.format((e+s/2+n.dy)*n.scale))),l.setAttribute("rx",String(i/2*n.scale)),l.setAttribute("ry",String(s/2*n.scale)),this.node=l}image(t,e,i,s,n,l=!0,o=!1,a=!1){n=this.converter.convert(n);const h=this.state;t+=h.dx,e+=h.dy;const d=this.createElement("image");d.setAttribute("x",String(this.format(t*h.scale)+this.imageOffset)),d.setAttribute("y",String(this.format(e*h.scale)+this.imageOffset)),d.setAttribute("width",String(this.format(i*h.scale))),d.setAttribute("height",String(this.format(s*h.scale))),d.setAttributeNS?d.setAttributeNS(NS_XLINK,"xlink:href",n):d.setAttribute("xlink:href",n),l||d.setAttribute("preserveAspectRatio","none"),(h.alpha<1||h.fillAlpha<1)&&d.setAttribute("opacity",String(h.alpha*h.fillAlpha));let c=this.state.transform||"";if(o||a){let u=1,g=1,f=0,p=0;o&&(u=-1,f=-i-2*t),a&&(g=-1,p=-s-2*e),c+=`scale(${u},${g})translate(${f*h.scale},${p*h.scale})`}c.length>0&&d.setAttribute("transform",c),this.pointerEvents||d.setAttribute("pointer-events","none"),this.root.appendChild(d)}convertHtml(t){const e=new DOMParser().parseFromString(t,"text/html");return e&&(t=new XMLSerializer().serializeToString(e.body),t.substring(0,5)==="<body"&&(t=t.substring(t.indexOf(">",5)+1)),t.substring(t.length-7,t.length)==="</body>"&&(t=t.substring(0,t.length-7))),t}createDiv(t){let e=t;if(isNode(e)||(e=`<div><div>${this.convertHtml(e)}</div></div>`),document.createElementNS){const i=document.createElementNS("http://www.w3.org/1999/xhtml","div");if(isNode(e)){const s=document.createElement("div"),n=s.cloneNode(!1);this.root.ownerDocument!==document?s.appendChild(e.cloneNode(!0)):s.appendChild(e),n.appendChild(s),i.appendChild(n)}else i.innerHTML=e;return i}return isNode(e)&&(e=`<div><div>${getXml(e)}</div></div>`),e=`<div xmlns="http://www.w3.org/1999/xhtml">${e}</div>`,parseXml(e).documentElement}updateText(t,e,i,s,n,l,o,a,h,d,c){c&&c.firstChild&&c.firstChild.firstChild&&this.updateTextNodes(t,e,i,s,n,l,o,a,h,d,c.firstChild)}addForeignObject(t,e,i,s,n,l,o,a,h,d,c,u,g,f,p){var S;const y=this.createElement("g"),v=this.createElement("foreignObject");if(v.setAttribute("style","overflow: visible; text-align: left;"),v.setAttribute("pointer-events","none"),v.appendChild(f),y.appendChild(v),this.updateTextNodes(t,e,i,s,l,o,a,d,c,u,y),((S=this.root)==null?void 0:S.ownerDocument)!==document){const w=this.createAlternateContent(v,t,e,i,s,n,l,o,a,h,d,c,u);if(w!=null){v.setAttribute("requiredFeatures","http://www.w3.org/TR/SVG11/feature#Extensibility");const C=this.createElement("switch");C.appendChild(v),C.appendChild(w),y.appendChild(C)}}p.appendChild(y)}updateTextNodes(t,e,i,s,n,l,o,a,h,d,c){const u=this.state.scale;SvgCanvas2D.createCss(i+2,s,n,l,o,a,h,this.state.fontBackgroundColor!=null?this.state.fontBackgroundColor:null,this.state.fontBorderColor!=null?this.state.fontBorderColor:null,`display: flex; align-items: unsafe ${l==="top"?"flex-start":l==="bottom"?"flex-end":"center"}; justify-content: unsafe ${n==="left"?"flex-start":n==="right"?"flex-end":"center"}; `,this.getTextCss(),u,(g,f,p,y,v)=>{t+=this.state.dx,e+=this.state.dy;const S=c.firstChild,w=S.firstChild,C=w.firstChild,m=C.firstChild,T=(this.rotateHtml?this.state.rotation:0)+(d??0);let b=(this.foOffset!==0?`translate(${this.foOffset} ${this.foOffset})`:"")+(u!==1?`scale(${u})`:"");m.setAttribute("style",v),C.setAttribute("style",y),S.setAttribute("width",`${Math.ceil(1/Math.min(1,u)*100)}%`),S.setAttribute("height",`${Math.ceil(1/Math.min(1,u)*100)}%`);const H=Math.round(e+f);H<0?S.setAttribute("y",String(H)):(S.removeAttribute("y"),p+=`padding-top: ${H}px; `),w.setAttribute("style",`${p}margin-left: ${Math.round(t+g)}px;`),b+=T!==0?`rotate(${T} ${t} ${e})`:"",b!==""?c.setAttribute("transform",b):c.removeAttribute("transform"),this.state.alpha!==1?c.setAttribute("opacity",String(this.state.alpha)):c.removeAttribute("opacity")})}getTextCss(){const t=this.state,e=LINE_HEIGHT*this.lineHeightCorrection;let i=`display: inline-block; font-size: ${t.fontSize}px; font-family: ${t.fontFamily}; color: ${t.fontColor}; line-height: ${e}; pointer-events: ${this.pointerEvents?this.pointerEventsValue:"none"}; `;const s=t.fontStyle;matchBinaryMask(s,FONT_STYLE_MASK.BOLD)&&(i+="font-weight: bold; "),matchBinaryMask(s,FONT_STYLE_MASK.ITALIC)&&(i+="font-style: italic; ");const n=[];return matchBinaryMask(s,FONT_STYLE_MASK.UNDERLINE)&&n.push("underline"),matchBinaryMask(s,FONT_STYLE_MASK.STRIKETHROUGH)&&n.push("line-through"),n.length>0&&(i+=`text-decoration: ${n.join(" ")}; `),i}text(t,e,i,s,n,l,o,a,h,d,c,u=0,g){if(this.textEnabled&&n!=null)if(u=u??0,this.foEnabled&&h==="html"){const f=this.createDiv(n);f!=null&&(g!=null&&f.setAttribute("dir",g),this.addForeignObject(t,e,i,s,n,l,o,a,h,d,c,u,g,f,this.root))}else this.plainText(t+this.state.dx,e+this.state.dy,i,s,n,l,o,a,d,c,u,g)}createClip(t,e,i,s){t=Math.round(t),e=Math.round(e),i=Math.round(i),s=Math.round(s);const n=`mx-clip-${t}-${e}-${i}-${s}`;let l=0,o=`${n}-${l}`;for(;document.getElementById(o)!=null;)o=`${n}-${++l}`;const a=this.createElement("clipPath");a.setAttribute("id",o);const h=this.createElement("rect");return h.setAttribute("x",String(t)),h.setAttribute("y",String(e)),h.setAttribute("width",String(i)),h.setAttribute("height",String(s)),a.appendChild(h),a}plainText(t,e,i,s,n,l,o,a,h,d,c=0,u){const g=this.state,f=g.fontSize,p=this.createElement("g");let y=g.transform||"";if(this.updateFont(p),!this.pointerEvents&&this.originalRoot==null&&p.setAttribute("pointer-events","none"),c!==0&&(y+=`rotate(${c},${this.format(t*g.scale)},${this.format(e*g.scale)})`),u!=null&&p.setAttribute("direction",u),d&&i>0&&s>0){let T=t,b=e;l==="center"?T-=i/2:l==="right"&&(T-=i),h!=="fill"&&(o==="middle"?b-=s/2:o==="bottom"&&(b-=s));const H=this.createClip(T*g.scale-2,b*g.scale-2,i*g.scale+4,s*g.scale+4);if(this.defs!=null?this.defs.appendChild(H):this.root.appendChild(H),!Client.IS_CHROMEAPP&&!Client.IS_EDGE&&this.root.ownerDocument===document){const R=this.getBaseUrl().replace(/([()])/g,"\\$1");p.setAttribute("clip-path",`url(${R}#${H.getAttribute("id")})`)}else p.setAttribute("clip-path",`url(#${H.getAttribute("id")})`)}const v=l==="right"?"end":l==="center"?"middle":"start";v!=="start"&&p.setAttribute("text-anchor",v),(!this.styleEnabled||f!==StyleDefaultsConfig.fontSize)&&p.setAttribute("font-size",`${f*g.scale}px`),y.length>0&&p.setAttribute("transform",y),g.alpha<1&&p.setAttribute("opacity",String(g.alpha));const S=n.split(`
7
+ `),w=Math.round(f*LINE_HEIGHT),C=f+(S.length-1)*w;let m=e+f-1;if(o==="middle")if(h==="fill")m-=s/2;else{const T=(this.matchHtmlAlignment&&d&&s>0?Math.min(C,s):C)/2;m-=T}else if(o==="bottom")if(h==="fill")m-=s;else{const T=this.matchHtmlAlignment&&d&&s>0?Math.min(C,s):C;m-=T+1}for(let T=0;T<S.length;T+=1){const b=trim(S[T]);if(b){const H=this.createElement("text");H.setAttribute("x",String(this.format(t*g.scale)+this.textOffset)),H.setAttribute("y",String(this.format(m*g.scale)+this.textOffset)),write(H,b),p.appendChild(H)}m+=w}this.root.appendChild(p),this.addTextBackground(p,n,t,e,i,h==="fill"?s:C,l,o,h)}updateFont(t){const e=this.state;e.fontColor&&e.fontColor!==NONE&&t.setAttribute("fill",e.fontColor),(!this.styleEnabled||e.fontFamily!==StyleDefaultsConfig.fontFamily)&&t.setAttribute("font-family",e.fontFamily);const i=e.fontStyle;matchBinaryMask(i,FONT_STYLE_MASK.BOLD)&&t.setAttribute("font-weight","bold"),matchBinaryMask(i,FONT_STYLE_MASK.ITALIC)&&t.setAttribute("font-style","italic");const s=[];matchBinaryMask(i,FONT_STYLE_MASK.UNDERLINE)&&s.push("underline"),matchBinaryMask(i,FONT_STYLE_MASK.STRIKETHROUGH)&&s.push("line-through"),s.length>0&&t.setAttribute("text-decoration",s.join(" "))}addTextBackground(t,e,i,s,n,l,o,a,h){var c;const d=this.state;if(d.fontBackgroundColor!=null||d.fontBorderColor!=null){let u=null;if(h==="fill"||h==="width")o==="center"?i-=n/2:o==="right"&&(i-=n),a==="middle"?s-=l/2:a==="bottom"&&(s-=l),u=new Rectangle((i+1)*d.scale,s*d.scale,(n-2)*d.scale,(l+2)*d.scale);else if(t.getBBox!=null&&this.root.ownerDocument===document)try{u=t.getBBox(),u=new Rectangle(u.x,u.y+1,u.width,u.height+0)}catch{}if(u==null||u.width===0||u.height===0){const g=document.createElement("div");g.style.lineHeight=String(LINE_HEIGHT),g.style.fontSize=`${d.fontSize}px`,g.style.fontFamily=d.fontFamily,g.style.whiteSpace="nowrap",g.style.position="absolute",g.style.visibility="hidden",g.style.display="inline-block",matchBinaryMask(d.fontStyle,FONT_STYLE_MASK.BOLD)&&(g.style.fontWeight="bold"),matchBinaryMask(d.fontStyle,FONT_STYLE_MASK.ITALIC)&&(g.style.fontStyle="italic"),e=htmlEntities(e,!1),g.innerHTML=e.replace(/\n/g,"<br/>"),document.body.appendChild(g);const f=g.offsetWidth,p=g.offsetHeight;document.body.removeChild(g),o==="center"?i-=f/2:o==="right"&&(i-=f),a==="middle"?s-=p/2:a==="bottom"&&(s-=p),u=new Rectangle((i+1)*d.scale,(s+2)*d.scale,f*d.scale,(p+1)*d.scale)}if(u!=null){const g=this.createElement("rect");g.setAttribute("fill",d.fontBackgroundColor||"none"),g.setAttribute("stroke",d.fontBorderColor||"none"),g.setAttribute("x",String(Math.floor(u.x-1))),g.setAttribute("y",String(Math.floor(u.y-1))),g.setAttribute("width",String(Math.ceil(u.width+2))),g.setAttribute("height",String(Math.ceil(u.height)));const f=d.fontBorderColor?Math.max(1,this.format(d.scale)):0;g.setAttribute("stroke-width",String(f)),((c=this.root)==null?void 0:c.ownerDocument)===document&&mod(f,2)===1&&g.setAttribute("transform","translate(0.5, 0.5)"),t.insertBefore(g,t.firstChild)}}}stroke(){this.addNode(!1,!0)}fill(){this.addNode(!0,!1)}fillAndStroke(){this.addNode(!0,!0)}}SvgCanvas2D.createCss=(r,t,e,i,s,n,l,o,a,h,d,c,u)=>{let g=`box-sizing: border-box; font-size: 0; text-align: ${e==="left"?"left":e==="right"?"right":"center"}; `;const f=getAlignmentAsPoint(e,i);let p="overflow: hidden; ",y="width: 1px; ",v="height: 1px; ",S=f.x*r,w=f.y*t;l?(y=`width: ${Math.round(r)}px; `,g+=`max-height: ${Math.round(t)}px; `,w=0):n==="fill"?(y=`width: ${Math.round(r)}px; `,v=`height: ${Math.round(t)}px; `,d+="width: 100%; height: 100%; ",g+=y+v):n==="width"?(y=`width: ${Math.round(r)}px; `,d+="width: 100%; ",g+=y,w=0,t>0&&(g+=`max-height: ${Math.round(t)}px; `)):(p="",w=0);let C="";o&&(C+=`background-color: ${o}; `),a&&(C+=`border: 1px solid ${a}; `),p==""||l?d+=C:g+=C,s&&r>0?(d+=`white-space: normal; word-wrap: ${WORD_WRAP}; `,y=`width: ${Math.round(r)}px; `,p!==""&&n!=="fill"&&(w=0)):(d+="white-space: nowrap; ",p===""&&(S=0)),u(S,w,h+y+v,g+p,d,p)};class Shape{constructor(t=null){this.preserveImageAspect=!1,this.overlay=null,this.indicator=null,this.indicatorShape=null,this.opacity=100,this.isDashed=!1,this.fill=NONE,this.gradient=NONE,this.gradientDirection="east",this.fillOpacity=100,this.strokeOpacity=100,this.stroke=NONE,this.strokeWidth=1,this.spacing=0,this.startSize=1,this.endSize=1,this.startArrow=NONE,this.endArrow=NONE,this.direction="east",this.flipH=!1,this.flipV=!1,this.isShadow=!1,this.isRounded=!1,this.rotation=0,this.cursor="",this.verticalTextRotation=0,this.oldGradients={},this.glass=!1,this.dialect=null,this.scale=1,this.antiAlias=!0,this.minSvgStrokeWidth=1,this.bounds=null,this.points=[],this.state=null,this.style=null,this.boundingBox=null,this.stencil=null,this.svgStrokeTolerance=8,this.pointerEvents=!0,this.originalPointerEvents=null,this.svgPointerEvents="all",this.shapePointerEvents=!1,this.stencilPointerEvents=!1,this.outline=!1,this.visible=!0,this.useSvgBoundingBox=!0,this.image=null,this.imageSrc=null,this.indicatorColor=NONE,this.indicatorStrokeColor=NONE,this.indicatorGradientColor=NONE,this.indicatorDirection="east",this.indicatorImageSrc=null,t&&(this.stencil=t),this.node=this.create()}init(t){this.node.parentNode||t.appendChild(this.node)}initStyles(){this.strokeWidth=1,this.rotation=0,this.opacity=100,this.fillOpacity=100,this.strokeOpacity=100,this.flipH=!1,this.flipV=!1}isHtmlAllowed(){return!1}getSvgScreenOffset(){const t=this.stencil&&this.stencil.strokeWidthValue!=="inherit"?Number(this.stencil.strokeWidthValue):this.strokeWidth??0;return mod(Math.max(1,Math.round(t*this.scale)),2)===1?.5:0}create(){return document.createElementNS(NS_SVG,"g")}redraw(){this.updateBoundsFromPoints(),this.visible&&this.checkBounds()?(this.node.style.visibility="visible",this.clear(),this.redrawShape(),this.updateBoundingBox()):(this.node.style.visibility="hidden",this.boundingBox=null)}clear(){for(;this.node.lastChild;)this.node.removeChild(this.node.lastChild)}updateBoundsFromPoints(){const t=this.points;if(t.length>0&&t[0]){this.bounds=new Rectangle(Math.round(t[0].x),Math.round(t[0].y),1,1);for(const e of t)e&&this.bounds.add(new Rectangle(Math.round(e.x),Math.round(e.y),1,1))}}getLabelBounds(t){var n,l,o;const e=((n=this.style)==null?void 0:n.direction)??"east";let i=t.clone();e!=="south"&&e!=="north"&&this.state&&this.state.text&&this.state.text.isPaintBoundsInverted()&&(i=i.clone(),[i.width,i.height]=[i.height,i.width]);let s=this.getLabelMargins(i);if(s){s=s.clone();let a=((l=this.style)==null?void 0:l.flipH)??!1,h=((o=this.style)==null?void 0:o.flipV)??!1;if(this.state&&this.state.text&&this.state.text.isPaintBoundsInverted()){const d=s.x;s.x=s.height,s.height=s.width,s.width=s.y,s.y=d,[a,h]=[h,a]}return getDirectedBounds(t,s,this.style,a,h)}return t}getLabelMargins(t){return null}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)&&this.bounds.width>0&&this.bounds.height>0}redrawShape(){const t=this.createCanvas();t&&(t.pointerEvents=this.pointerEvents,this.beforePaint(t),this.paint(t),this.afterPaint(t),this.node!==t.root&&t.root&&this.node.insertAdjacentHTML("beforeend",t.root.outerHTML),this.destroyCanvas(t))}createCanvas(){const t=this.createSvgCanvas();return t&&this.outline&&(t.setStrokeWidth(this.strokeWidth),t.setStrokeColor(this.stroke),this.isDashed&&t.setDashed(this.isDashed),t.setStrokeWidth=()=>{},t.setStrokeColor=()=>{},t.setFillColor=()=>{},t.setGradient=()=>{},t.setDashed=()=>{},t.text=()=>{}),t}createSvgCanvas(){if(!this.node)return null;const t=new SvgCanvas2D(this.node,!1);t.strokeTolerance=this.pointerEvents?this.svgStrokeTolerance:0,t.pointerEventsValue=this.svgPointerEvents;const e=this.getSvgScreenOffset();return e!==0?this.node.setAttribute("transform",`translate(${e},${e})`):this.node.removeAttribute("transform"),t.minStrokeWidth=this.minSvgStrokeWidth,this.antiAlias||(t.format=i=>Math.round(i)),t}destroyCanvas(t){if(t instanceof SvgCanvas2D){for(const e in t.gradients){const i=t.gradients[e];i&&(i.mxRefCount=(i.mxRefCount||0)+1)}this.releaseSvgGradients(this.oldGradients),this.oldGradients=t.gradients}}beforePaint(t){}afterPaint(t){}paint(t){let e=!1;if(t&&this.outline){const{stroke:n}=t;t.stroke=(...o)=>{e=!0,n.apply(t,o)};const{fillAndStroke:l}=t;t.fillAndStroke=(...o)=>{e=!0,l.apply(t,o)}}const i=this.scale,s=this.bounds;if(s){let n=s.x/i,l=s.y/i,o=s.width/i,a=s.height/i;if(this.isPaintBoundsInverted()){const d=(o-a)/2;n+=d,l-=d;const c=o;o=a,a=c}this.updateTransform(t,n,l,o,a),this.configureCanvas(t,n,l,o,a);let h=null;if(!this.stencil&&this.points.length===0&&this.shapePointerEvents||this.stencil&&this.stencilPointerEvents){const d=this.createBoundingBox();d&&this.node&&(h=this.createTransparentSvgRectangle(d.x,d.y,d.width,d.height),this.node.appendChild(h))}if(this.stencil)this.stencil.drawShape(t,this,n,l,o,a);else if(t.setStrokeWidth(this.strokeWidth),this.points.length>0){const d=[];for(let c=0;c<this.points.length;c+=1){const u=this.points[c];u&&d.push(new Point(u.x/i,u.y/i))}this.paintEdgeShape(t,d)}else this.paintVertexShape(t,n,l,o,a);h&&t.state&&!isNullish(t.state.transform)&&h.setAttribute("transform",t.state.transform),t&&this.outline&&!e&&(t.rect(n,l,o,a),t.stroke())}}configureCanvas(t,e,i,s,n){var o;let l=null;if(this.style&&this.style.dashPattern!=null&&(l=this.style.dashPattern),t.setAlpha(this.opacity/100),t.setFillAlpha(this.fillOpacity/100),t.setStrokeAlpha(this.strokeOpacity/100),this.isShadow&&t.setShadow(this.isShadow),this.isDashed&&t.setDashed(this.isDashed,((o=this.style)==null?void 0:o.fixDash)??!1),l&&t.setDashPattern(l),this.fill!==NONE&&this.gradient!==NONE){const a=this.getGradientBounds(t,e,i,s,n);t.setGradient(this.fill,this.gradient,a.x,a.y,a.width,a.height,this.gradientDirection)}else t.setFillColor(this.fill);t.setStrokeColor(this.stroke)}getGradientBounds(t,e,i,s,n){return new Rectangle(e,i,s,n)}updateTransform(t,e,i,s,n){t.scale(this.scale),t.rotate(this.getShapeRotation(),this.flipH,this.flipV,e+s/2,i+n/2)}paintVertexShape(t,e,i,s,n){this.paintBackground(t,e,i,s,n),(!this.outline||!this.style||!(this.style.backgroundOutline??!1))&&(t.setShadow(!1),this.paintForeground(t,e,i,s,n))}paintBackground(t,e,i,s,n){}paintForeground(t,e,i,s,n){}paintEdgeShape(t,e){}getBaseArcSize(){var t;return(((t=this.style)==null?void 0:t.arcSize)??StyleDefaultsConfig.lineArcSize)/2}getArcSize(t,e){var s,n;if((s=this.style)!=null&&s.absoluteArcSize)return Math.min(this.getBaseArcSize(),Math.min(e,t)/2);const i=(((n=this.style)==null?void 0:n.arcSize)??StyleDefaultsConfig.roundingFactor*100)/100;return Math.min(t,e)*i}paintGlassEffect(t,e,i,s,n,l){const o=Math.ceil((this.strokeWidth??0)/2),a=.4;t.setGradient("#ffffff","#ffffff",e,i,s,n*.6,"south",.9,.1),t.begin(),l+=2*o,this.isRounded?(t.moveTo(e-o+l,i-o),t.quadTo(e-o,i-o,e-o,i-o+l),t.lineTo(e-o,i+n*a),t.quadTo(e+s*.5,i+n*.7,e+s+o,i+n*a),t.lineTo(e+s+o,i-o+l),t.quadTo(e+s+o,i-o,e+s+o-l,i-o)):(t.moveTo(e-o,i-o),t.lineTo(e-o,i+n*a),t.quadTo(e+s*.5,i+n*.7,e+s+o,i+n*a),t.lineTo(e+s+o,i-o)),t.close(),t.fill()}addPoints(t,e,i=!1,s,n=!1,l=[],o=!0){if(e.length>0){const a=e[e.length-1];if(n&&i){e=e.slice();const c=e[0],u=new Point(a.x+(c.x-a.x)/2,a.y+(c.y-a.y)/2);e.splice(0,0,u)}let h=e[0],d=1;for(o?t.moveTo(h.x,h.y):t.lineTo(h.x,h.y);d<(n?e.length:e.length-1);){let c=e[mod(d,e.length)],u=h.x-c.x,g=h.y-c.y;if(i&&(u!==0||g!==0)&&!l.includes(d-1)){let f=Math.sqrt(u*u+g*g);const p=u*Math.min(s,f/2)/f,y=g*Math.min(s,f/2)/f,v=c.x+p,S=c.y+y;t.lineTo(v,S);let w=e[mod(d+1,e.length)];for(;d<e.length-2&&Math.round(w.x-c.x)===0&&Math.round(w.y-c.y)===0;)w=e[mod(d+2,e.length)],d++;u=w.x-c.x,g=w.y-c.y,f=Math.max(1,Math.sqrt(u*u+g*g));const C=u*Math.min(s,f/2)/f,m=g*Math.min(s,f/2)/f,T=c.x+C,b=c.y+m;t.quadTo(c.x,c.y,T,b),c=new Point(T,b)}else t.lineTo(c.x,c.y);h=c,d+=1}n?t.close():t.lineTo(a.x,a.y)}}resetStyles(){this.initStyles(),this.spacing=0,this.fill=NONE,this.gradient=NONE,this.gradientDirection="east",this.stroke=NONE,this.startSize=1,this.endSize=1,this.startArrow=NONE,this.endArrow=NONE,this.direction="east",this.isShadow=!1,this.isDashed=!1,this.isRounded=!1,this.glass=!1}apply(t){if(this.state=t,this.style=t.style,this.style){if(this.fill=this.style.fillColor??this.fill,this.gradient=this.style.gradientColor??this.gradient,this.gradientDirection=this.style.gradientDirection??this.gradientDirection,this.opacity=this.style.opacity??this.opacity,this.fillOpacity=this.style.fillOpacity??this.fillOpacity,this.strokeOpacity=this.style.strokeOpacity??this.strokeOpacity,this.stroke=this.style.strokeColor??this.stroke,this.strokeWidth=this.style.strokeWidth??this.strokeWidth,this.spacing=this.style.spacing??this.spacing,this.startSize=this.style.startSize??this.startSize,this.endSize=this.style.endSize??this.endSize,this.startArrow=this.style.startArrow??this.startArrow,this.endArrow=this.style.endArrow??this.endArrow,this.rotation=this.style.rotation??this.rotation,this.direction=this.style.direction??this.direction,this.flipH=!!this.style.flipH,this.flipV=!!this.style.flipV,this.direction==="north"||this.direction==="south"){const e=this.flipH;this.flipH=this.flipV,this.flipV=e}this.isShadow=this.style.shadow??this.isShadow,this.isDashed=this.style.dashed??this.isDashed,this.isRounded=this.style.rounded??this.isRounded,this.glass=this.style.glass??this.glass}}setCursor(t){this.cursor=t,this.node.style.cursor=t}getCursor(){return this.cursor}isRoundable(t,e,i,s,n){return!1}updateBoundingBox(){if(this.useSvgBoundingBox&&this.node.ownerSVGElement)try{const t=this.node.getBBox();if(t.width>0&&t.height>0){this.boundingBox=new Rectangle(t.x,t.y,t.width,t.height),this.boundingBox.grow((this.strokeWidth??0)*this.scale/2);return}}catch{}if(this.bounds){let t=this.createBoundingBox();if(t){this.augmentBoundingBox(t);const e=this.getShapeRotation();e!==0&&(t=getBoundingBox(t,e))}this.boundingBox=t}}createBoundingBox(){if(!this.bounds)return null;const t=this.bounds.clone();return(this.stencil&&(this.direction==="north"||this.direction==="south")||this.isPaintBoundsInverted())&&t.rotate90(),t}augmentBoundingBox(t){this.isShadow&&(t.width+=Math.ceil(StyleDefaultsConfig.shadowOffsetX*this.scale),t.height+=Math.ceil(StyleDefaultsConfig.shadowOffsetX*this.scale)),t.grow((this.strokeWidth??0)*this.scale/2)}isPaintBoundsInverted(){return!this.stencil&&(this.direction==="north"||this.direction==="south")}getRotation(){return this.rotation??0}getTextRotation(){var e;let t=this.getRotation();return(((e=this.style)==null?void 0:e.horizontal)??!0)||(t+=this.verticalTextRotation||-90),t}getShapeRotation(){let t=this.getRotation();switch(this.direction){case"north":{t+=270;break}case"west":{t+=180;break}case"south":{t+=90;break}}return t}createTransparentSvgRectangle(t,e,i,s){const n=document.createElementNS(NS_SVG,"rect");return n.setAttribute("x",String(t)),n.setAttribute("y",String(e)),n.setAttribute("width",String(i)),n.setAttribute("height",String(s)),n.setAttribute("fill",NONE),n.setAttribute("stroke",NONE),n.setAttribute("pointer-events","all"),n}redrawHtmlShape(){}setTransparentBackgroundImage(t){t.style.backgroundImage=`url('${Client.imageBasePath}/transparent.gif')`}releaseSvgGradients(t){for(const e in t){const i=t[e];i&&(i.mxRefCount=(i.mxRefCount||0)-1,i.mxRefCount===0&&i.parentNode&&i.parentNode.removeChild(i))}}destroy(){InternalEvent.release(this.node),this.node.parentNode&&this.node.parentNode.removeChild(this.node),this.node.innerHTML="",this.releaseSvgGradients(this.oldGradients),this.oldGradients={}}}class EllipseShape extends Shape{constructor(t,e,i,s=1){super(),this.bounds=t,this.fill=e,this.stroke=i,this.strokeWidth=s}paintVertexShape(t,e,i,s,n){t.ellipse(e,i,s,n),t.fillAndStroke()}}class RectangleShape extends Shape{constructor(t,e,i,s=1){super(),this.bounds=t,this.fill=e,this.stroke=i,this.strokeWidth=s}isHtmlAllowed(){let t=!0;return this.style&&this.style.pointerEvents!=null&&(t=this.style.pointerEvents),!this.isRounded&&!this.glass&&this.rotation===0&&(t||this.fill!==NONE)}paintBackground(t,e,i,s,n){let l=!0;if(this.style&&this.style.pointerEvents!=null&&(l=this.style.pointerEvents),l||this.fill!==NONE||this.stroke!==NONE){if(!l&&this.fill===NONE&&(t.pointerEvents=!1),this.isRounded){const o=this.getArcSize(s,n);t.roundrect(e,i,s,n,o,o)}else t.rect(e,i,s,n);t.fillAndStroke()}}isRoundable(t,e,i,s,n){return!0}paintForeground(t,e,i,s,n){this.glass&&!this.outline&&this.fill!==NONE&&this.paintGlassEffect(t,e,i,s,n,this.getArcSize(s+this.strokeWidth,n+this.strokeWidth))}}class ImageShape extends RectangleShape{constructor(t,e,i="#FFFFFF",s="#000000",n=1){super(t,i,s,n),this.imageSrc=e,this.shadow=!1,this.preserveImageAspect=!0}getSvgScreenOffset(){return 0}apply(t){super.apply(t),this.fill=NONE,this.stroke=NONE,this.gradient=NONE,this.style&&this.style.imageAspect!=null&&(this.preserveImageAspect=this.style.imageAspect)}isHtmlAllowed(){return!this.preserveImageAspect}isRoundable(t,e,i,s,n){return!1}paintVertexShape(t,e,i,s,n){var l,o;if(this.imageSrc){const a=((l=this.style)==null?void 0:l.imageBackground)??NONE,h=((o=this.style)==null?void 0:o.imageBorder)??NONE;a!==NONE&&(t.setFillColor(a),t.setStrokeColor(h),t.rect(e,i,s,n),t.fillAndStroke()),t.image(e,i,s,n,this.imageSrc,this.preserveImageAspect,!1,!1),h!==NONE&&(t.setShadow(!1),t.setStrokeColor(h),t.rect(e,i,s,n),t.stroke())}else this.paintBackground(t,e,i,s,n)}}class ConnectionConstraint{constructor(t,e=!0,i=null,s=0,n=0){this.perimeter=!0,this.name=null,this.dx=0,this.dy=0,this.point=t,this.perimeter=e,this.name=i,this.dx=s,this.dy=n}}class ConstraintHandler{constructor(t){this.pointImage=new ImageBox(`${Client.imageBasePath}/point.gif`,5,5),this.currentFocus=null,this.currentFocusArea=null,this.focusIcons=[],this.constraints=null,this.currentConstraint=null,this.focusHighlight=null,this.focusPoints=[],this.currentPoint=null,this.enabled=!0,this.highlightColor=DEFAULT_VALID_COLOR,this.mouseleaveHandler=null,this.graph=t,this.resetHandler=()=>{this.currentFocus&&!this.graph.view.getState(this.currentFocus.cell)?this.reset():this.redraw()},this.graph.model.addListener(InternalEvent.CHANGE,this.resetHandler),this.graph.view.addListener(InternalEvent.SCALE_AND_TRANSLATE,this.resetHandler),this.graph.view.addListener(InternalEvent.TRANSLATE,this.resetHandler),this.graph.view.addListener(InternalEvent.SCALE,this.resetHandler),this.graph.addListener(InternalEvent.ROOT,this.resetHandler)}isEnabled(){return this.enabled}setEnabled(t){this.enabled=t}reset(){for(let t=0;t<this.focusIcons.length;t+=1)this.focusIcons[t].destroy();this.focusIcons=[],this.focusHighlight&&(this.focusHighlight.destroy(),this.focusHighlight=null),this.currentConstraint=null,this.currentFocusArea=null,this.currentPoint=null,this.currentFocus=null,this.focusPoints=[]}getTolerance(t){return this.graph.getEventTolerance()}getImageForConstraint(t,e,i){return this.pointImage}isEventIgnored(t,e=!1){return!1}isStateIgnored(t,e=!1){return!1}destroyIcons(){for(let t=0;t<this.focusIcons.length;t+=1)this.focusIcons[t].destroy();this.focusIcons=[],this.focusPoints=[]}destroyFocusHighlight(){this.focusHighlight&&(this.focusHighlight.destroy(),this.focusHighlight=null)}isKeepFocusEvent(t){return isShiftDown(t.getEvent())}getCellForEvent(t,e){let i=t.getCell();if(!i&&e&&(t.getGraphX()!==e.x||t.getGraphY()!==e.y)&&(i=this.graph.getCellAt(e.x,e.y)),i&&!i.isConnectable()){const s=i.getParent();s&&s.isVertex()&&s.isConnectable()&&(i=s)}return i?this.graph.isCellLocked(i)?null:i:null}update(t,e,i,s){if(this.isEnabled()&&!this.isEventIgnored(t)){!this.mouseleaveHandler&&this.graph.container&&(this.mouseleaveHandler=()=>{this.reset()},InternalEvent.addListener(this.graph.container,"mouseleave",this.resetHandler));const n=this.getTolerance(t),l=s?s.x:t.getGraphX(),o=s?s.y:t.getGraphY(),a=new Rectangle(l-n,o-n,2*n,2*n),h=new Rectangle(t.getGraphX()-n,t.getGraphY()-n,2*n,2*n),d=this.graph.view.getState(this.getCellForEvent(t,s));!this.isKeepFocusEvent(t)&&(!this.currentFocusArea||!this.currentFocus||d||!this.currentFocus.cell.isVertex()||!intersects(this.currentFocusArea,h))&&d!==this.currentFocus&&(this.currentFocusArea=null,this.currentFocus=null,this.setFocus(t,d,e)),this.currentConstraint=null,this.currentPoint=null;let c=null,u;if(this.focusIcons.length>0&&this.constraints&&(!d||this.currentFocus===d)){const g=h.getCenterX(),f=h.getCenterY();for(let p=0;p<this.focusIcons.length;p+=1){const y=g-this.focusIcons[p].bounds.getCenterX(),v=f-this.focusIcons[p].bounds.getCenterY();if(u=y*y+v*v,(this.intersects(this.focusIcons[p],h,e,i)||s&&this.intersects(this.focusIcons[p],a,e,i))&&(c===null||u<c)){if(this.currentConstraint=this.constraints[p],this.currentPoint=this.focusPoints[p],c=u,u=this.focusIcons[p].bounds.clone(),u.grow(HIGHLIGHT_SIZE+1),u.width-=1,u.height-=1,!this.focusHighlight){const S=this.createHighlightShape();S.dialect="svg",S.pointerEvents=!1,S.init(this.graph.getView().getOverlayPane()),this.focusHighlight=S;const w=()=>this.currentFocus?this.currentFocus:d;InternalEvent.redirectMouseEvents(S.node,this.graph,w)}this.focusHighlight.bounds=u,this.focusHighlight.redraw()}}}this.currentConstraint||this.destroyFocusHighlight()}else this.currentConstraint=null,this.currentFocus=null,this.currentPoint=null}redraw(){if(this.currentFocus&&this.constraints&&this.focusIcons.length>0){const t=this.graph.view.getState(this.currentFocus.cell);this.currentFocus=t,this.currentFocusArea=new Rectangle(t.x,t.y,t.width,t.height);for(let e=0;e<this.constraints.length;e+=1){const i=this.graph.getConnectionPoint(t,this.constraints[e]),s=this.getImageForConstraint(t,this.constraints[e],i),n=new Rectangle(Math.round(i.x-s.width/2),Math.round(i.y-s.height/2),s.width,s.height);this.focusIcons[e].bounds=n,this.focusIcons[e].redraw(),this.currentFocusArea.add(this.focusIcons[e].bounds),this.focusPoints[e]=i}}}setFocus(t,e,i){var s;if(this.constraints=e&&!this.isStateIgnored(e,i)&&e.cell.isConnectable()?this.isEnabled()?this.graph.getAllConnectionConstraints(e,i)??[]:[]:null,this.constraints&&e){this.currentFocus=e,this.currentFocusArea=new Rectangle(e.x,e.y,e.width,e.height);for(let n=0;n<this.focusIcons.length;n+=1)this.focusIcons[n].destroy();this.focusIcons=[],this.focusPoints=[];for(let n=0;n<this.constraints.length;n+=1){const l=this.graph.getConnectionPoint(e,this.constraints[n]),o=this.getImageForConstraint(e,this.constraints[n],l),{src:a}=o,h=new Rectangle(Math.round(l.x-o.width/2),Math.round(l.y-o.height/2),o.width,o.height),d=new ImageShape(h,a);d.dialect=this.graph.dialect!=="svg"?"mixedHtml":"svg",d.preserveImageAspect=!1,d.init(this.graph.getView().getDecoratorPane()),d.node.previousSibling&&((s=d.node.parentNode)==null||s.insertBefore(d.node,d.node.parentNode.firstChild));const c=()=>this.currentFocus?this.currentFocus:e;d.redraw(),InternalEvent.redirectMouseEvents(d.node,this.graph,c),this.currentFocusArea.add(d.bounds),this.focusIcons.push(d),this.focusPoints.push(l)}this.currentFocusArea.grow(this.getTolerance(t))}else this.destroyIcons(),this.destroyFocusHighlight()}createHighlightShape(){const t=new RectangleShape(new Rectangle,this.highlightColor,this.highlightColor,HIGHLIGHT_STROKEWIDTH);return t.opacity=HIGHLIGHT_OPACITY,t}intersects(t,e,i,s){return intersects(t.bounds,e)}onDestroy(){this.reset(),this.graph.model.removeListener(this.resetHandler),this.graph.view.removeListener(this.resetHandler),this.graph.removeListener(this.resetHandler),this.mouseleaveHandler&&this.graph.container&&(InternalEvent.removeListener(this.graph.container,"mouseleave",this.mouseleaveHandler),this.mouseleaveHandler=null)}}const EdgeHandlerConfig={connectFillColor:CONNECT_HANDLE_FILLCOLOR,cursorBend:"crosshair",cursorMovable:"move",cursorTerminal:"pointer",cursorVirtualBend:"crosshair",selectionColor:EDGE_SELECTION_COLOR,selectionDashed:EDGE_SELECTION_DASHED,selectionStrokeWidth:EDGE_SELECTION_STROKEWIDTH,virtualBendOpacity:20,virtualBendsEnabled:!1},HandleConfig={fillColor:HANDLE_FILLCOLOR,labelCursor:"default",labelFillColor:LABEL_HANDLE_FILLCOLOR,labelSize:LABEL_HANDLE_SIZE,size:HANDLE_SIZE,strokeColor:HANDLE_STROKECOLOR},VertexHandlerConfig={cursorMovable:"move",rotationEnabled:!1,selectionColor:VERTEX_SELECTION_COLOR,selectionStrokeWidth:VERTEX_SELECTION_STROKEWIDTH,selectionDashed:VERTEX_SELECTION_DASHED};class EdgeHandler{constructor(t){if(this.error=null,this.bends=[],this.cloneEnabled=!0,this.dblClickRemoveEnabled=!1,this.mergeRemoveEnabled=!1,this.straightRemoveEnabled=!1,this.parentHighlightEnabled=!1,this.preferHtml=!1,this.allowHandleBoundsCheck=!0,this.snapToTerminals=!1,this.handleImage=null,this.labelHandleImage=null,this.tolerance=0,this.outlineConnect=!1,this.manageLabelHandle=!1,this.currentPoint=null,this.parentHighlight=null,this.index=null,this.isSource=!1,this.isTarget=!1,this.isLabel=!1,this.points=[],this.snapPoint=null,this.abspoints=[],this.startX=0,this.startY=0,this.outline=!0,this.active=!0,this.state=t,this.graph=this.state.view.graph,this.marker=this.createMarker(),this.constraintHandler=this.createConstraintHandler(),this.points=[],this.abspoints=this.getSelectionPoints(this.state),this.shape=this.createSelectionShape(this.abspoints),this.shape.dialect=this.graph.dialect!=="svg"?"mixedHtml":"svg",this.shape.init(this.graph.getView().getOverlayPane()),this.shape.pointerEvents=!1,this.shape.setCursor(EdgeHandlerConfig.cursorMovable),InternalEvent.redirectMouseEvents(this.shape.node,this.graph,this.state),this.preferHtml=this.state.text!=null&&this.state.text.node.parentNode===this.graph.container,!this.preferHtml){const i=this.state.getVisibleTerminalState(!0);if(i!=null&&(this.preferHtml=i.text!=null&&i.text.node.parentNode===this.graph.container),!this.preferHtml){const s=this.state.getVisibleTerminalState(!1);s!=null&&(this.preferHtml=s.text!=null&&s.text.node.parentNode===this.graph.container)}}const e=this.graph.getPlugin("SelectionHandler");e&&(this.graph.getSelectionCount()<e.maxCells||e.maxCells<=0)&&(this.bends=this.createBends(),this.isVirtualBendsEnabled()&&(this.virtualBends=this.createVirtualBends())),this.label=new Point(this.state.absoluteOffset.x,this.state.absoluteOffset.y),this.labelShape=this.createLabelHandleShape(),this.initBend(this.labelShape),this.labelShape.setCursor(HandleConfig.labelCursor),this.customHandles=this.createCustomHandles(),this.updateParentHighlight(),this.redraw(),this.escapeHandler=(i,s)=>{const n=this.index!=null;this.reset(),n&&this.graph.cellRenderer.redraw(this.state,!1,t.view.isRendering())},this.state.view.graph.addListener(InternalEvent.ESCAPE,this.escapeHandler)}createConstraintHandler(){return new ConstraintHandler(this.graph)}isParentHighlightVisible(){const t=this.state.cell.getParent();return t?!this.graph.isCellSelected(t):null}updateParentHighlight(){if(!this.isDestroyed()){const t=this.isParentHighlightVisible(),e=this.state.cell.getParent(),i=e?this.graph.view.getState(e):null;if(this.parentHighlight)if(e&&e.isVertex()&&t){const s=this.parentHighlight.bounds;i&&s&&(s.x!==i.x||s.y!==i.y||s.width!==i.width||s.height!==i.height)&&(this.parentHighlight.bounds=Rectangle.fromRectangle(i),this.parentHighlight.redraw())}else i&&i.parentHighlight===this.parentHighlight&&(i.parentHighlight=null),this.parentHighlight.destroy(),this.parentHighlight=null;else this.parentHighlightEnabled&&t&&e&&e.isVertex()&&i&&!i.parentHighlight&&(this.parentHighlight=this.createParentHighlightShape(i),this.parentHighlight.dialect="svg",this.parentHighlight.pointerEvents=!1,i.style.rotation&&(this.parentHighlight.rotation=i.style.rotation),this.parentHighlight.init(this.graph.getView().getOverlayPane()),this.parentHighlight.redraw(),i.parentHighlight=this.parentHighlight)}}createCustomHandles(){return[]}isVirtualBendsEnabled(t){return EdgeHandlerConfig.virtualBendsEnabled}isCellEnabled(t){return!0}isAddPointEvent(t){return isShiftDown(t)}isRemovePointEvent(t){return isShiftDown(t)}getSelectionPoints(t){return t.absolutePoints}createParentHighlightShape(t){const e=new RectangleShape(Rectangle.fromRectangle(t),NONE,this.getSelectionColor());return e.strokeWidth=this.getSelectionStrokeWidth(),e.isDashed=this.isSelectionDashed(),e}createSelectionShape(t){const e=this.state.shape.constructor,i=new e;return i.outline=!0,i.apply(this.state),i.isDashed=this.isSelectionDashed(),i.stroke=this.getSelectionColor(),i.isShadow=!1,i}getSelectionColor(){return EdgeHandlerConfig.selectionColor}getSelectionStrokeWidth(){return EdgeHandlerConfig.selectionStrokeWidth}isSelectionDashed(){return EdgeHandlerConfig.selectionDashed}isConnectableCell(t){return!0}getCellAt(t,e){return this.outlineConnect?null:this.graph.getCellAt(t,e)}createMarker(){return new EdgeHandlerCellMarker(this.graph,this)}validateConnection(t,e){return this.graph.getEdgeValidationError(this.state.cell,t,e)}createBends(){const{cell:t}=this.state,e=[];for(let i=0;i<this.abspoints.length;i+=1)if(this.isHandleVisible(i)){const s=i===0,n=i===this.abspoints.length-1,l=s||n;(l||this.graph.isCellBendable(t))&&(o=>{const a=this.createHandleShape(o);this.initBend(a,()=>{this.dblClickRemoveEnabled&&this.removePoint(this.state,o)}),this.isHandleEnabled(i)&&a.setCursor(l?EdgeHandlerConfig.cursorTerminal:EdgeHandlerConfig.cursorBend),e.push(a),l||(this.points.push(new Point(0,0)),a.node.style.visibility="hidden")})(i)}return e}createVirtualBends(){const{cell:t}=this.state;this.abspoints[0];const e=[];if(this.graph.isCellBendable(t))for(let i=1;i<this.abspoints.length;i+=1)(s=>{this.initBend(s),s.setCursor(EdgeHandlerConfig.cursorVirtualBend),e.push(s)})(this.createHandleShape());return e}isHandleEnabled(t){return!0}isHandleVisible(t){const e=this.state.getVisibleTerminalState(!0),i=this.state.getVisibleTerminalState(!1),s=this.state.cell.getGeometry(),n=s?this.graph.view.getEdgeStyle(this.state,s.points||void 0,e,i):null;return EdgeStyleRegistry.allowsIntermediateHandles(n)||t===0||t===this.abspoints.length-1}createHandleShape(t){if(this.handleImage){const s=new ImageShape(new Rectangle(0,0,this.handleImage.width,this.handleImage.height),this.handleImage.src);return s.preserveImageAspect=!1,s}let e=HandleConfig.size;this.preferHtml&&(e-=1);const i=RectangleShape;return new i(new Rectangle(0,0,e,e),HandleConfig.fillColor,HandleConfig.strokeColor)}createLabelHandleShape(){if(this.labelHandleImage){const e=new ImageShape(new Rectangle(0,0,this.labelHandleImage.width,this.labelHandleImage.height),this.labelHandleImage.src);return e.preserveImageAspect=!1,e}const t=HandleConfig.labelSize;return new RectangleShape(new Rectangle(0,0,t,t),HandleConfig.labelFillColor,HandleConfig.strokeColor)}initBend(t,e){this.preferHtml?(t.dialect="strictHtml",t.init(this.graph.container)):(t.dialect=this.graph.dialect!=="svg"?"mixedHtml":"svg",t.init(this.graph.getView().getOverlayPane())),InternalEvent.redirectMouseEvents(t.node,this.graph,this.state,null,null,null,e),Client.IS_TOUCH&&t.node.setAttribute("pointer-events","none")}getHandleForEvent(t){let e=null;const i=isMouseEvent(t.getEvent())?1:this.tolerance,s=this.allowHandleBoundsCheck&&i>0?new Rectangle(t.getGraphX()-i,t.getGraphY()-i,2*i,2*i):null;let n=Number.POSITIVE_INFINITY;function l(o){if(o&&o.bounds&&o.node&&o.node.style.display!=="none"&&o.node.style.visibility!=="hidden"&&(t.isSource(o)||s&&intersects(o.bounds,s))){const a=t.getGraphX()-o.bounds.getCenterX(),h=t.getGraphY()-o.bounds.getCenterY(),d=a*a+h*h;if(d<=n)return n=d,!0}return!1}if(this.isCustomHandleEvent(t)&&this.customHandles){for(let o=this.customHandles.length-1;o>=0;o--)if(l(this.customHandles[o].shape))return InternalEvent.CUSTOM_HANDLE-o}(t.isSource(this.state.text)||l(this.labelShape))&&(e=InternalEvent.LABEL_HANDLE);for(let o=0;o<this.bends.length;o+=1)l(this.bends[o])&&(e=o);if(this.virtualBends&&this.isAddVirtualBendEvent(t))for(let o=0;o<this.virtualBends.length;o+=1)l(this.virtualBends[o])&&(e=InternalEvent.VIRTUAL_HANDLE-o);return e}isAddVirtualBendEvent(t){return!0}isCustomHandleEvent(t){return!0}mouseDown(t,e){const i=this.getHandleForEvent(e);if(i!==null&&this.bends[i]){const s=this.bends[i].bounds;s&&(this.snapPoint=new Point(s.getCenterX(),s.getCenterY()))}if(i!==null&&!e.isConsumed()&&this.graph.isEnabled()){const s=e.getCell();(i!==InternalEvent.LABEL_HANDLE||s&&this.graph.isLabelMovable(s))&&(this.virtualBends&&i<=InternalEvent.VIRTUAL_HANDLE&&setOpacity(this.virtualBends[InternalEvent.VIRTUAL_HANDLE-i].node,100),this.start(e.getX(),e.getY(),i)),e.consume()}}start(t,e,i){if(this.startX=t,this.startY=e,this.isSource=this.bends.length===0?!1:i===0,this.isTarget=this.bends.length===0?!1:i===this.bends.length-1,this.isLabel=i===InternalEvent.LABEL_HANDLE,this.isSource||this.isTarget){const{cell:s}=this.state,n=s.getTerminal(this.isSource);(n==null&&this.graph.isTerminalPointMovable(s,this.isSource)||n!=null&&this.graph.isCellDisconnectable(s,n,this.isSource))&&(this.index=i)}else this.index=i;if(this.index!==null&&this.index<=InternalEvent.CUSTOM_HANDLE&&this.index>InternalEvent.VIRTUAL_HANDLE&&this.customHandles!=null)for(let s=0;s<this.customHandles.length;s+=1)s!==InternalEvent.CUSTOM_HANDLE-this.index&&this.customHandles[s].setVisible(!1)}clonePreviewState(t,e){return this.state.clone()}getSnapToTerminalTolerance(){return this.graph.getGridSize()*this.graph.getView().scale/2}updateHint(t,e){}removeHint(){}roundLength(t){return Math.round(t)}isSnapToTerminalsEvent(t){return this.snapToTerminals&&!isAltDown(t.getEvent())}getPointForEvent(t){const e=this.graph.getView(),{scale:i}=e,s=new Point(this.roundLength(t.getGraphX()/i)*i,this.roundLength(t.getGraphY()/i)*i),n=this.getSnapToTerminalTolerance();let l=!1,o=!1;if(n>0&&this.isSnapToTerminalsEvent(t)){const a=d=>{if(d){const{x:c}=d;Math.abs(s.x-c)<n&&(s.x=c,l=!0);const{y:u}=d;Math.abs(s.y-u)<n&&(s.y=u,o=!0)}},h=d=>{d&&a(new Point(e.getRoutingCenterX(d),e.getRoutingCenterY(d)))};h(this.state.getVisibleTerminalState(!0)),h(this.state.getVisibleTerminalState(!1));for(let d=0;d<this.state.absolutePoints.length;d+=1)a(this.state.absolutePoints[d])}if(this.graph.isGridEnabledEvent(t.getEvent())){const a=e.translate;l||(s.x=(this.graph.snap(s.x/i-a.x)+a.x)*i),o||(s.y=(this.graph.snap(s.y/i-a.y)+a.y)*i)}return s}getPreviewTerminalState(t){if(this.constraintHandler.update(t,this.isSource,!0,t.isSource(this.marker.highlight.shape)?null:this.currentPoint),this.constraintHandler.currentFocus&&this.constraintHandler.currentConstraint){this.marker.highlight&&this.marker.highlight.shape&&this.marker.highlight.state&&this.marker.highlight.state.cell===this.constraintHandler.currentFocus.cell?this.marker.highlight.shape.stroke!=="transparent"&&(this.marker.highlight.shape.stroke="transparent",this.marker.highlight.repaint()):this.marker.markCell(this.constraintHandler.currentFocus.cell,"transparent");const e=this.graph.view.getTerminalPort(this.state,this.graph.view.getState(this.state.cell.getTerminal(!this.isSource)),!this.isSource),i=e?e.cell:null,s=this.isSource?this.constraintHandler.currentFocus.cell:i,n=this.isSource?i:this.constraintHandler.currentFocus.cell;this.error=this.validateConnection(s,n);let l=null;return this.error===null&&(l=this.constraintHandler.currentFocus),(this.error!==null||l&&!this.isCellEnabled(l.cell))&&this.constraintHandler.reset(),l}if(!this.graph.isIgnoreTerminalEvent(t.getEvent())){this.marker.process(t);const e=this.marker.getValidState();return e&&!this.isCellEnabled(e.cell)&&(this.constraintHandler.reset(),this.marker.reset()),this.marker.getValidState()}return this.marker.reset(),null}getPreviewPoints(t,e){const i=this.state.cell.getGeometry();if(!i)return null;let s=(i.points||[]).slice();const n=new Point(t.x,t.y);let l=null;if(!this.isSource&&!this.isTarget&&this.index!==null){if(this.convertPoint(n,!1),this.index<=InternalEvent.VIRTUAL_HANDLE&&s.splice(InternalEvent.VIRTUAL_HANDLE-this.index,0,n),!this.isSource&&!this.isTarget){for(let o=0;o<this.bends.length;o+=1)if(o!==this.index){const a=this.bends[o];a&&contains(a.bounds,t.x,t.y)&&(this.index<=InternalEvent.VIRTUAL_HANDLE?s.splice(InternalEvent.VIRTUAL_HANDLE-this.index,1):s.splice(this.index-1,1),l=s)}if(!l&&this.straightRemoveEnabled&&(!e||!isAltDown(e.getEvent()))){const o=this.graph.getEventTolerance()*this.graph.getEventTolerance(),a=this.state.absolutePoints.slice();a[this.index]=t;const h=this.state.getVisibleTerminalState(!0);if(h!=null){const u=this.graph.getConnectionConstraint(this.state,h,!0);(u==null||this.graph.getConnectionPoint(h,u)==null)&&(a[0]=new Point(h.view.getRoutingCenterX(h),h.view.getRoutingCenterY(h)))}const d=this.state.getVisibleTerminalState(!1);if(d!=null){const u=this.graph.getConnectionConstraint(this.state,d,!1);(u==null||this.graph.getConnectionPoint(d,u)==null)&&(a[a.length-1]=new Point(d.view.getRoutingCenterX(d),d.view.getRoutingCenterY(d)))}((u,g)=>{u>0&&u<a.length-1&&ptSegDistSq(a[u-1].x,a[u-1].y,a[u+1].x,a[u+1].y,g.x,g.y)<o&&(s.splice(u-1,1),l=s)})(this.index,t)}}l==null&&this.index>InternalEvent.VIRTUAL_HANDLE&&(s[this.index-1]=n)}else this.graph.isResetEdgesOnConnect()&&(s=[]);return l??s}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))}updatePreviewState(t,e,i,s,n=!1){const l=this.isSource?i:this.state.getVisibleTerminalState(!0),o=this.isTarget?i:this.state.getVisibleTerminalState(!1);let a=this.graph.getConnectionConstraint(t,l,!0),h=this.graph.getConnectionConstraint(t,o,!1),d=this.constraintHandler.currentConstraint;if(d==null&&n&&(i!=null?(s.isSource(this.marker.highlight.shape)&&(e=new Point(s.getGraphX(),s.getGraphY())),d=this.graph.getOutlineConstraint(e,i,s),this.constraintHandler.setFocus(s,i,this.isSource),this.constraintHandler.currentConstraint=d,this.constraintHandler.currentPoint=e):d=new ConnectionConstraint(null)),this.outlineConnect&&this.marker.highlight!=null&&this.marker.highlight.shape!=null){const c=this.graph.view.scale;if(this.constraintHandler.currentConstraint!=null&&this.constraintHandler.currentFocus!=null)this.marker.highlight.shape.stroke=n?OUTLINE_HIGHLIGHT_COLOR:"transparent",this.marker.highlight.shape.strokeWidth=OUTLINE_HIGHLIGHT_STROKEWIDTH/c/c,this.marker.highlight.repaint();else if(this.marker.hasValidState()){const u=s.getCell();this.marker.highlight.shape.stroke=u&&u.isConnectable()&&this.marker.getValidState()!==s.getState()?"transparent":DEFAULT_VALID_COLOR,this.marker.highlight.shape.strokeWidth=HIGHLIGHT_STROKEWIDTH/c/c,this.marker.highlight.repaint()}}this.isSource?a=d:this.isTarget&&(h=d),(this.isSource||this.isTarget)&&(d!=null&&d.point!=null?(t.style[this.isSource?"exitX":"entryX"]=d.point.x,t.style[this.isSource?"exitY":"entryY"]=d.point.y):(delete t.style[this.isSource?"exitX":"entryX"],delete t.style[this.isSource?"exitY":"entryY"])),t.setVisibleTerminalState(l,!0),t.setVisibleTerminalState(o,!1),(!this.isSource||l!=null)&&t.view.updateFixedTerminalPoint(t,l,!0,a),(!this.isTarget||o!=null)&&t.view.updateFixedTerminalPoint(t,o,!1,h),(this.isSource||this.isTarget)&&i==null&&(t.setAbsoluteTerminalPoint(e,this.isSource),this.marker.getMarkedState()==null&&(this.error=this.graph.isAllowDanglingEdges()?null:"")),t.view.updatePoints(t,this.points,l,o),t.view.updateFloatingTerminalPoints(t,l,o)}mouseMove(t,e){var i;if(this.index!=null&&this.marker!=null){if(this.currentPoint=this.getPointForEvent(e),this.error=null,!this.graph.isIgnoreTerminalEvent(e.getEvent())&&isShiftDown(e.getEvent())&&this.snapPoint!=null&&(Math.abs(this.snapPoint.x-this.currentPoint.x)<Math.abs(this.snapPoint.y-this.currentPoint.y)?this.currentPoint.x=this.snapPoint.x:this.currentPoint.y=this.snapPoint.y),this.index<=InternalEvent.CUSTOM_HANDLE&&this.index>InternalEvent.VIRTUAL_HANDLE)this.customHandles!=null&&(this.customHandles[InternalEvent.CUSTOM_HANDLE-this.index].processEvent(e),this.customHandles[InternalEvent.CUSTOM_HANDLE-this.index].positionChanged(),this.shape!=null&&this.shape.node!=null&&(this.shape.node.style.display="none"));else if(this.isLabel&&this.label)this.label.x=this.currentPoint.x,this.label.y=this.currentPoint.y;else{this.points=this.getPreviewPoints(this.currentPoint,e);let s=this.isSource||this.isTarget?this.getPreviewTerminalState(e):null;if(this.constraintHandler.currentConstraint!=null&&this.constraintHandler.currentFocus!=null&&this.constraintHandler.currentPoint!=null?this.currentPoint=this.constraintHandler.currentPoint.clone():this.outlineConnect&&((this.isSource||this.isTarget?this.isOutlineConnectEvent(e):!1)?s=this.marker.highlight.state:s!=null&&s!==e.getState()&&((i=e.getCell())!=null&&i.isConnectable())&&this.marker.highlight.shape!=null&&(this.marker.highlight.shape.stroke="transparent",this.marker.highlight.repaint(),s=null)),s!=null&&!this.isCellEnabled(s.cell)&&(s=null,this.marker.reset()),this.currentPoint){const n=this.clonePreviewState(this.currentPoint,s!=null?s.cell:null);this.updatePreviewState(n,this.currentPoint,s,e,this.outline);const l=this.error==null?this.marker.validColor:this.marker.invalidColor;this.setPreviewColor(l),this.abspoints=n.absolutePoints,this.active=!0,this.updateHint(e,this.currentPoint)}}this.drawPreview(),InternalEvent.consume(e.getEvent()),e.consume()}}mouseUp(t,e){if(this.index!=null&&this.marker!=null){this.shape!=null&&this.shape.node!=null&&(this.shape.node.style.display="");let i=this.state.cell;const{index:s}=this;if(this.index=null,e.getX()!==this.startX||e.getY()!==this.startY){const n=!this.graph.isIgnoreTerminalEvent(e.getEvent())&&this.graph.isCloneEvent(e.getEvent())&&this.cloneEnabled&&this.graph.isCellsCloneable();if(this.error!=null)this.error.length>0&&this.graph.validationAlert(this.error);else if(s<=InternalEvent.CUSTOM_HANDLE&&s>InternalEvent.VIRTUAL_HANDLE){if(this.customHandles!=null){const l=this.graph.getDataModel();l.beginUpdate();try{this.customHandles[InternalEvent.CUSTOM_HANDLE-s].execute(e),this.shape!=null&&this.shape.node!=null&&(this.shape.apply(this.state),this.shape.redraw())}finally{l.endUpdate()}}}else if(this.isLabel&&this.label)this.moveLabel(this.state,this.label.x,this.label.y);else if(this.isSource||this.isTarget){let l=null;if(this.constraintHandler.currentConstraint!=null&&this.constraintHandler.currentFocus!=null&&(l=this.constraintHandler.currentFocus.cell),!l&&this.marker.hasValidState()&&this.marker.highlight!=null&&this.marker.highlight.shape!=null&&this.marker.highlight.shape.stroke!=="transparent"&&this.marker.highlight.shape.stroke!=="white"&&(l=this.marker.validState.cell),l){const o=this.graph.getDataModel(),a=i.getParent();o.beginUpdate();try{if(n){let h=i.getGeometry();const d=this.graph.cloneCell(i);o.add(a,d,a.getChildCount()),h!=null&&(h=h.clone(),o.setGeometry(d,h));const c=i.getTerminal(!this.isSource);this.graph.connectCell(d,c,!this.isSource),i=d}i=this.connect(i,l,this.isSource,n,e)}finally{o.endUpdate()}}else if(this.graph.isAllowDanglingEdges()){const o=this.abspoints[this.isSource?0:this.abspoints.length-1];o.x=this.roundLength(o.x/this.graph.view.scale-this.graph.view.translate.x),o.y=this.roundLength(o.y/this.graph.view.scale-this.graph.view.translate.y);const a=i.getParent(),h=a?this.graph.getView().getState(a):null;h!=null&&(o.x-=h.origin.x,o.y-=h.origin.y),o.x-=this.graph.getPanDx()/this.graph.view.scale,o.y-=this.graph.getPanDy()/this.graph.view.scale,i=this.changeTerminalPoint(i,o,this.isSource,n)}}else this.active?i=this.changePoints(i,this.points,n):(this.graph.getView().invalidate(this.state.cell),this.graph.getView().validate(this.state.cell))}else this.graph.isToggleEvent(e.getEvent())&&this.graph.selectCellForEvent(this.state.cell,e.getEvent());this.marker!=null&&(this.reset(),i!==this.state.cell&&this.graph.setSelectionCell(i)),e.consume()}}reset(){if(this.active&&this.refresh(),this.error=null,this.index=null,this.points=[],this.snapPoint=null,this.isLabel=!1,this.isSource=!1,this.isTarget=!1,this.active=!1,this.marker&&this.marker.reset(),this.constraintHandler.reset(),this.customHandles)for(let t=0;t<this.customHandles.length;t+=1)this.customHandles[t].reset();this.setPreviewColor(EdgeHandlerConfig.selectionColor),this.removeHint(),this.redraw()}setPreviewColor(t){this.shape.stroke=t}convertPoint(t,e){const i=this.graph.getView().getScale(),s=this.graph.getView().getTranslate();e&&(t.x=this.graph.snap(t.x),t.y=this.graph.snap(t.y)),t.x=Math.round(t.x/i-s.x),t.y=Math.round(t.y/i-s.y);const n=this.state.cell.getParent(),l=n&&this.graph.getView().getState(n);return l&&(t.x-=l.origin.x,t.y-=l.origin.y),t}moveLabel(t,e,i){const s=this.graph.getDataModel();let n=t.cell.getGeometry();if(n!=null){const{scale:l}=this.graph.getView();if(n=n.clone(),n.relative){let o=this.graph.getView().getRelativePoint(t,e,i);n.x=Math.round(o.x*1e4)/1e4,n.y=Math.round(o.y),n.offset=new Point(0,0),o=this.graph.view.getPoint(t,n),n.offset=new Point(Math.round((e-o.x)/l),Math.round((i-o.y)/l))}else{const o=t.absolutePoints,a=o[0],h=o[o.length-1];if(a!=null&&h!=null){const d=a.x+(h.x-a.x)/2,c=a.y+(h.y-a.y)/2;n.offset=new Point(Math.round((e-d)/l),Math.round((i-c)/l)),n.x=0,n.y=0}}s.setGeometry(t.cell,n)}}connect(t,e,i,s,n){return t.getParent(),this.graph.batchUpdate(()=>{let l=this.constraintHandler.currentConstraint;l==null&&(l=new ConnectionConstraint(null)),this.graph.connectCell(t,e,i,l)}),t}changeTerminalPoint(t,e,i,s){const n=this.graph.getDataModel();return n.batchUpdate(()=>{if(s){const o=t.getParent(),a=t.getTerminal(!i);t=this.graph.cloneCell(t),n.add(o,t,o.getChildCount()),n.setTerminal(t,a,!i)}let l=t.getGeometry();l!=null&&(l=l.clone(),l.setTerminalPoint(e,i),n.setGeometry(t,l),this.graph.connectCell(t,null,i,new ConnectionConstraint(null)))}),t}changePoints(t,e,i){const s=this.graph.getDataModel();return s.batchUpdate(()=>{if(i){const l=t.getParent(),o=t.getTerminal(!0),a=t.getTerminal(!1);t=this.graph.cloneCell(t),s.add(l,t,l.getChildCount()),s.setTerminal(t,o,!0),s.setTerminal(t,a,!1)}let n=t.getGeometry();n!=null&&(n=n.clone(),n.points=e,s.setGeometry(t,n))}),t}addPoint(t,e){const i=convertPoint(this.graph.container,getClientX(e),getClientY(e)),s=this.graph.isGridEnabledEvent(e);this.convertPoint(i,s),this.addPointAt(t,i.x,i.y),InternalEvent.consume(e)}addPointAt(t,e,i){let s=t.cell.getGeometry();const n=new Point(e,i);if(s!=null){s=s.clone();const l=this.graph.view.translate,o=this.graph.view.scale;let a=new Point(l.x*o,l.y*o);const h=this.state.cell.getParent();if(h&&h.isVertex()){const c=this.graph.view.getState(h);c&&(a=new Point(c.x,c.y))}const d=findNearestSegment(t,n.x*o+a.x,n.y*o+a.y);s.points==null?s.points=[n]:s.points.splice(d,0,n),this.graph.getDataModel().setGeometry(t.cell,s),this.refresh(),this.redraw()}}removePoint(t,e){if(e>0&&e<this.abspoints.length-1){let i=this.state.cell.getGeometry();i!=null&&i.points!=null&&(i=i.clone(),(i.points||[]).splice(e-1,1),this.graph.getDataModel().setGeometry(t.cell,i),this.refresh(),this.redraw())}}getHandleFillColor(t){const e=t===0,{cell:i}=this.state,s=i.getTerminal(e);let n=HandleConfig.fillColor;return s!=null&&!this.graph.isCellDisconnectable(i,s,e)||s==null&&!this.graph.isTerminalPointMovable(i,e)?n=LOCKED_HANDLE_FILLCOLOR:s!=null&&this.graph.isCellDisconnectable(i,s,e)&&(n=EdgeHandlerConfig.connectFillColor),n}redraw(t){this.abspoints=this.state.absolutePoints.slice();const e=this.state.cell.getGeometry();if(e){const i=e.points;if(this.bends!=null&&this.bends.length>0&&i!=null){this.points==null&&(this.points=[]);for(let s=1;s<this.bends.length-1;s+=1)this.bends[s]!=null&&this.abspoints[s]!=null&&(this.points[s-1]=i[s-1])}}this.drawPreview(),t||this.redrawHandles()}redrawHandles(){const{cell:t}=this.state;let e=this.labelShape.bounds;this.label=new Point(this.state.absoluteOffset.x,this.state.absoluteOffset.y),this.labelShape.bounds=new Rectangle(Math.round(this.label.x-e.width/2),Math.round(this.label.y-e.height/2),e.width,e.height);const i=this.graph.getLabel(t);if(this.labelShape.visible=i!=null&&i.length>0&&this.graph.isLabelMovable(t),this.bends!=null&&this.bends.length>0){const s=this.abspoints.length-1,n=this.abspoints[0],l=n.x,o=n.y;e=this.bends[0].bounds,this.bends[0].bounds=new Rectangle(Math.floor(l-e.width/2),Math.floor(o-e.height/2),e.width,e.height),this.bends[0].fill=this.getHandleFillColor(0),this.bends[0].redraw(),this.manageLabelHandle&&this.checkLabelHandle(this.bends[0].bounds);const a=this.abspoints[s],h=a.x,d=a.y,c=this.bends.length-1;e=this.bends[c].bounds,this.bends[c].bounds=new Rectangle(Math.floor(h-e.width/2),Math.floor(d-e.height/2),e.width,e.height),this.bends[c].fill=this.getHandleFillColor(c),this.bends[c].redraw(),this.manageLabelHandle&&this.checkLabelHandle(this.bends[c].bounds),this.redrawInnerBends(n,a)}if(this.virtualBends&&this.virtualBends.length>0){let s=this.abspoints[0];for(let n=0;n<this.virtualBends.length;n+=1)if(this.virtualBends[n]!=null&&this.abspoints[n+1]!=null){const l=this.abspoints[n+1],o=this.virtualBends[n],a=s.x+(l.x-s.x)/2,h=s.y+(l.y-s.y)/2;o.bounds&&(o.bounds=new Rectangle(Math.floor(a-o.bounds.width/2),Math.floor(h-o.bounds.height/2),o.bounds.width,o.bounds.height),o.redraw()),setOpacity(o.node,EdgeHandlerConfig.virtualBendOpacity),s=l,this.manageLabelHandle&&this.checkLabelHandle(o.bounds)}}if(this.labelShape.redraw(),this.customHandles)for(let s=0;s<this.customHandles.length;s+=1){const n=this.customHandles[s].shape;if(n){const l=n.node.style.display;this.customHandles[s].redraw(),n.node.style.display=l,n.node.style.visibility=this.isCustomHandleVisible(this.customHandles[s])?"":"hidden"}}}isCustomHandleVisible(t){return!this.graph.isEditing()&&this.state.view.graph.getSelectionCount()===1}setHandlesVisible(t){for(let e=0;e<this.bends.length;e+=1)this.bends[e].node.style.display=t?"":"none";if(this.virtualBends)for(let e=0;e<this.virtualBends.length;e+=1)this.virtualBends[e].node.style.display=t?"":"none";if(this.labelShape.node.style.display=t?"":"none",this.customHandles)for(let e=0;e<this.customHandles.length;e+=1)this.customHandles[e].setVisible(t)}redrawInnerBends(t,e){for(let i=1;i<this.bends.length-1;i+=1)if(this.bends[i]!=null)if(this.abspoints[i]!=null){const{x:s}=this.abspoints[i],{y:n}=this.abspoints[i],l=this.bends[i].bounds;if(this.bends[i].node.style.visibility="visible",this.bends[i].bounds=new Rectangle(Math.round(s-l.width/2),Math.round(n-l.height/2),l.width,l.height),this.manageLabelHandle)this.checkLabelHandle(this.bends[i].bounds);else if(this.handleImage==null&&this.labelShape.visible&&intersects(this.bends[i].bounds,this.labelShape.bounds)){const o=HandleConfig.size+3,a=o;this.bends[i].bounds=new Rectangle(Math.round(s-o/2),Math.round(n-a/2),o,a)}this.bends[i].redraw()}else this.bends[i].destroy()}checkLabelHandle(t){const e=this.labelShape.bounds;intersects(t,e)&&(t.getCenterY()<e.getCenterY()?e.y=t.y+t.height:e.y=t.y-e.height)}drawPreview(){try{if(this.isLabel){const t=this.labelShape.bounds,e=new Rectangle(Math.round(this.label.x-t.width/2),Math.round(this.label.y-t.height/2),t.width,t.height);t.equals(e)||(this.labelShape.bounds=e,this.labelShape.redraw())}this.shape!=null&&!equalPoints(this.shape.points,this.abspoints)&&(this.shape.apply(this.state),this.shape.points=this.abspoints.slice(),this.shape.scale=this.state.view.scale,this.shape.isDashed=this.isSelectionDashed(),this.shape.stroke=this.getSelectionColor(),this.shape.strokeWidth=this.getSelectionStrokeWidth()/this.shape.scale/this.shape.scale,this.shape.isShadow=!1,this.shape.redraw()),this.updateParentHighlight()}catch{}}refresh(){this.state!=null&&(this.abspoints=this.getSelectionPoints(this.state),this.points=[],this.destroyBends(this.bends),this.bends=this.createBends(),this.virtualBends&&(this.destroyBends(this.virtualBends),this.virtualBends=this.createVirtualBends()),this.customHandles&&(this.destroyBends(this.customHandles),this.customHandles=this.createCustomHandles()),this.labelShape!=null&&this.labelShape.node!=null&&this.labelShape.node.parentNode!=null&&this.labelShape.node.parentNode.appendChild(this.labelShape.node))}isDestroyed(){return this.shape==null}destroyBends(t){if(t!=null)for(let e=0;e<t.length;e+=1)t[e]!=null&&t[e].destroy()}onDestroy(){if(this.state.view.graph.removeListener(this.escapeHandler),this.marker.destroy(),this.marker=null,this.shape.destroy(),this.shape=null,this.parentHighlight){const t=this.state.cell.getParent(),e=t?this.graph.view.getState(t):null;e&&e.parentHighlight===this.parentHighlight&&(e.parentHighlight=null),this.parentHighlight.destroy(),this.parentHighlight=null}this.labelShape.destroy(),this.labelShape=null,this.constraintHandler.onDestroy(),this.constraintHandler=null,this.virtualBends&&(this.destroyBends(this.virtualBends),this.virtualBends=[]),this.customHandles&&(this.destroyBends(this.customHandles),this.customHandles=[]),this.destroyBends(this.bends),this.bends=[],this.removeHint()}}class EdgeHandlerCellMarker extends CellMarker{constructor(t,e,i=DEFAULT_VALID_COLOR,s=DEFAULT_INVALID_COLOR,n=DEFAULT_HOTSPOT){super(t,i,s,n),this.getCell=l=>{let o=super.getCell(l);if((o===this.edgeHandler.state.cell||!o)&&this.edgeHandler.currentPoint&&(o=this.edgeHandler.graph.getCellAt(this.edgeHandler.currentPoint.x,this.edgeHandler.currentPoint.y)),o&&!o.isConnectable()){const a=o.getParent();a&&a.isVertex()&&a.isConnectable()&&(o=a)}return o&&(this.graph.isSwimlane(o)&&this.edgeHandler.currentPoint&&this.graph.hitsSwimlaneContent(o,this.edgeHandler.currentPoint.x,this.edgeHandler.currentPoint.y)||!this.edgeHandler.isConnectableCell(o)||o===this.edgeHandler.state.cell||o&&!this.edgeHandler.graph.connectableEdges&&o.isEdge()||this.edgeHandler.state.cell.isAncestor(o))&&(o=null),o&&!o.isConnectable()&&(o=null),o},this.isValidState=l=>{const o=this.edgeHandler.state.cell.getTerminal(!this.edgeHandler.isSource),a=this.edgeHandler.graph.view.getState(o),h=this.edgeHandler.graph.view.getTerminalPort(l,a,!this.edgeHandler.isSource),d=h?h.cell:null,c=this.edgeHandler.isSource?l.cell:d,u=this.edgeHandler.isSource?d:l.cell;return this.edgeHandler.error=this.edgeHandler.validateConnection(c,u),!this.edgeHandler.error},this.edgeHandler=e}}class VertexHandler{isRotationEnabled(){return VertexHandlerConfig.rotationEnabled}constructor(t){this.sizers=[],this.singleSizer=!1,this.index=null,this.allowHandleBoundsCheck=!0,this.handleImage=null,this.handlesVisible=!0,this.tolerance=0,this.parentHighlightEnabled=!1,this.rotationRaster=!0,this.rotationCursor="crosshair",this.livePreview=!1,this.movePreviewToFront=!1,this.manageSizers=!1,this.constrainGroupByChildren=!1,this.rotationHandleVSpacing=-16,this.horizontalOffset=0,this.verticalOffset=0,this.minBounds=null,this.x0=0,this.y0=0,this.customHandles=[],this.inTolerance=!1,this.startX=0,this.startY=0,this.rotationShape=null,this.currentAlpha=null,this.startAngle=0,this.startDist=0,this.ghostPreview=null,this.livePreviewActive=!1,this.childOffsetX=0,this.childOffsetY=0,this.parentState=null,this.parentHighlight=null,this.unscaledBounds=null,this.preview=null,this.labelShape=null,this.edgeHandlers=[],this.EMPTY_POINT=new Point,this.state=t,this.graph=this.state.view.graph,this.selectionBounds=this.getSelectionBounds(this.state),this.bounds=new Rectangle(this.selectionBounds.x,this.selectionBounds.y,this.selectionBounds.width,this.selectionBounds.height),this.selectionBorder=this.createSelectionShape(this.bounds),this.selectionBorder.dialect="svg",this.selectionBorder.pointerEvents=!1,this.selectionBorder.rotation=this.state.style.rotation??0,this.selectionBorder.init(this.graph.getView().getOverlayPane()),InternalEvent.redirectMouseEvents(this.selectionBorder.node,this.graph,this.state),this.graph.isCellMovable(this.state.cell)&&this.selectionBorder.setCursor(VertexHandlerConfig.cursorMovable);const e=this.getSelectionHandler();if(e&&(e.maxCells<=0||this.graph.getSelectionCount()<e.maxCells)){const i=this.graph.isCellResizable(this.state.cell);if(this.sizers=[],i||this.graph.isLabelMovable(this.state.cell)&&this.state.width>=2&&this.state.height>=2){let s=0;i&&(this.singleSizer||(this.sizers.push(this.createSizer("nw-resize",s++)),this.sizers.push(this.createSizer("n-resize",s++)),this.sizers.push(this.createSizer("ne-resize",s++)),this.sizers.push(this.createSizer("w-resize",s++)),this.sizers.push(this.createSizer("e-resize",s++)),this.sizers.push(this.createSizer("sw-resize",s++)),this.sizers.push(this.createSizer("s-resize",s++))),this.sizers.push(this.createSizer("se-resize",s++)));const n=this.state.cell.getGeometry();n!=null&&!n.relative&&!this.graph.isSwimlane(this.state.cell)&&this.graph.isLabelMovable(this.state.cell)&&(this.labelShape=this.createSizer(HandleConfig.labelCursor,InternalEvent.LABEL_HANDLE,HandleConfig.labelSize,HandleConfig.labelFillColor),this.sizers.push(this.labelShape))}else this.graph.isCellMovable(this.state.cell)&&!this.graph.isCellResizable(this.state.cell)&&this.state.width<2&&this.state.height<2&&(this.labelShape=this.createSizer(VertexHandlerConfig.cursorMovable,InternalEvent.LABEL_HANDLE,void 0,HandleConfig.labelFillColor),this.sizers.push(this.labelShape))}this.isRotationHandleVisible()&&(this.rotationShape=this.createSizer(this.rotationCursor,InternalEvent.ROTATION_HANDLE,HandleConfig.size+3,HandleConfig.fillColor),this.sizers.push(this.rotationShape)),this.customHandles=this.createCustomHandles(),this.redraw(),this.constrainGroupByChildren&&this.updateMinBounds(),this.escapeHandler=(i,s)=>{this.livePreview&&this.index!=null&&(this.state.view.graph.cellRenderer.redraw(this.state,!0),this.state.view.invalidate(this.state.cell),this.state.invalid=!1,this.state.view.validate()),this.reset()},this.state.view.graph.addListener(InternalEvent.ESCAPE,this.escapeHandler)}getSelectionHandler(){return this.graph.getPlugin("SelectionHandler")}isRotationHandleVisible(){const t=this.getSelectionHandler(),e=t?t.maxCells<=0||this.graph.getSelectionCount()<t.maxCells:!0;return this.graph.isEnabled()&&this.isRotationEnabled()&&this.graph.isCellRotatable(this.state.cell)&&e}isConstrainedEvent(t){return isShiftDown(t.getEvent())||this.state.style.aspect==="fixed"}isCenteredEvent(t,e){return!1}createCustomHandles(){return[]}updateMinBounds(){const t=this.graph.getChildCells(this.state.cell);if(t.length>0&&(this.minBounds=this.graph.view.getBounds(t),this.minBounds)){const e=this.state.view.scale,i=this.state.view.translate;this.minBounds.x-=this.state.x,this.minBounds.y-=this.state.y,this.minBounds.x/=e,this.minBounds.y/=e,this.minBounds.width/=e,this.minBounds.height/=e,this.x0=this.state.x/e-i.x,this.y0=this.state.y/e-i.y}}getSelectionBounds(t){return new Rectangle(Math.round(t.x),Math.round(t.y),Math.round(t.width),Math.round(t.height))}createParentHighlightShape(t){return this.createSelectionShape(t)}createSelectionShape(t){const e=new RectangleShape(Rectangle.fromRectangle(t),NONE,this.getSelectionColor());return e.strokeWidth=this.getSelectionStrokeWidth(),e.isDashed=this.isSelectionDashed(),e}getSelectionColor(){return VertexHandlerConfig.selectionColor}getSelectionStrokeWidth(){return VertexHandlerConfig.selectionStrokeWidth}isSelectionDashed(){return VertexHandlerConfig.selectionDashed}createSizer(t,e,i=HandleConfig.size,s=HandleConfig.fillColor){const n=new Rectangle(0,0,i,i),l=this.createSizerShape(n,e,s);return l.bounds&&l.isHtmlAllowed()&&this.state.text&&this.state.text.node.parentNode===this.graph.container?(l.bounds.height-=1,l.bounds.width-=1,l.dialect="strictHtml",l.init(this.graph.container)):(l.dialect=this.graph.dialect!=="svg"?"mixedHtml":"svg",l.init(this.graph.getView().getOverlayPane())),InternalEvent.redirectMouseEvents(l.node,this.graph,this.state),this.graph.isEnabled()&&l.setCursor(t),this.isSizerVisible(e)||(l.visible=!1),l}isSizerVisible(t){return!0}createSizerShape(t,e,i=HandleConfig.fillColor){if(this.handleImage){t=new Rectangle(t.x,t.y,this.handleImage.width,this.handleImage.height);const n=new ImageShape(t,this.handleImage.src);return n.preserveImageAspect=!1,n}const s=HandleConfig.strokeColor;return e===InternalEvent.ROTATION_HANDLE?new EllipseShape(t,i,s):new RectangleShape(t,i,s)}moveSizerTo(t,e,i){t&&t.bounds&&(t.bounds.x=Math.floor(e-t.bounds.width/2),t.bounds.y=Math.floor(i-t.bounds.height/2),t.node&&t.node.style.display!=="none"&&t.redraw())}getHandleForEvent(t){const e=isMouseEvent(t.getEvent())?1:this.tolerance,i=this.allowHandleBoundsCheck&&e>0?new Rectangle(t.getGraphX()-e,t.getGraphY()-e,2*e,2*e):null,s=n=>{const l=n&&n.constructor!==ImageShape&&this.allowHandleBoundsCheck?n.strokeWidth+n.svgStrokeTolerance:null,o=l?new Rectangle(t.getGraphX()-Math.floor(l/2),t.getGraphY()-Math.floor(l/2),l,l):i;return n&&n.bounds&&(t.isSource(n)||o&&intersects(n.bounds,o)&&n.node.style.display!=="none"&&n.node.style.visibility!=="hidden")};if(s(this.rotationShape))return InternalEvent.ROTATION_HANDLE;if(s(this.labelShape))return InternalEvent.LABEL_HANDLE;for(let n=0;n<this.sizers.length;n+=1)if(s(this.sizers[n]))return n;if(this.customHandles!=null&&this.isCustomHandleEvent(t)){for(let n=this.customHandles.length-1;n>=0;n--)if(s(this.customHandles[n].shape))return InternalEvent.CUSTOM_HANDLE-n}return null}isCustomHandleEvent(t){return!0}mouseDown(t,e){if(!e.isConsumed()&&this.graph.isEnabled()){const i=this.getHandleForEvent(e);isNullish(i)||(this.start(e.getGraphX(),e.getGraphY(),i),e.consume())}}isLivePreviewBorder(){return this.state.shape&&this.state.shape.fill===NONE&&this.state.shape.stroke===NONE}start(t,e,i){if(this.livePreviewActive=this.livePreview&&this.state.cell.getChildCount()===0,this.inTolerance=!0,this.childOffsetX=0,this.childOffsetY=0,this.index=i,this.startX=t,this.startY=e,this.index<=InternalEvent.CUSTOM_HANDLE&&this.isGhostPreview())this.ghostPreview=this.createGhostPreview();else{const s=this.state.cell.getParent();if(this.state.view.currentRoot!==s&&s&&(s.isVertex()||s.isEdge())&&(this.parentState=this.state.view.graph.view.getState(s)),this.selectionBorder.node.style.display=i===InternalEvent.ROTATION_HANDLE?"inline":"none",(!this.livePreviewActive||this.isLivePreviewBorder())&&(this.preview=this.createSelectionShape(this.bounds),!(Client.IS_SVG&&(this.state.style.rotation??0)!=0)&&this.state.text!=null&&this.state.text.node.parentNode===this.graph.container?(this.preview.dialect="strictHtml",this.preview.init(this.graph.container)):(this.preview.dialect="svg",this.preview.init(this.graph.view.getOverlayPane()))),i===InternalEvent.ROTATION_HANDLE){const n=this.getRotationHandlePosition(),l=n.x-this.state.getCenterX(),o=n.y-this.state.getCenterY();this.startAngle=l!==0?Math.atan(o/l)*180/Math.PI+90:0,this.startDist=Math.sqrt(l*l+o*o)}if(this.livePreviewActive){this.hideSizers(),i===InternalEvent.ROTATION_HANDLE&&this.rotationShape?this.rotationShape.node.style.display="":i===InternalEvent.LABEL_HANDLE&&this.labelShape?this.labelShape.node.style.display="":this.sizers[i]?this.sizers[i].node.style.display="":i<=InternalEvent.CUSTOM_HANDLE&&this.customHandles[InternalEvent.CUSTOM_HANDLE-i].setVisible(!0);const n=this.state.cell.getEdges();this.edgeHandlers=[];const l=this.graph.getPlugin("SelectionCellsHandler");for(let o=0;o<n.length;o+=1){const a=l==null?void 0:l.getHandler(n[o]);a&&this.edgeHandlers.push(a)}}}}createGhostPreview(){const t=this.graph.cellRenderer.createShape(this.state);return t.init(this.graph.view.getOverlayPane()),t.scale=this.state.view.scale,t.bounds=this.bounds,t.outline=!0,t}setHandlesVisible(t){this.handlesVisible=t;for(let e=0;e<this.sizers.length;e+=1)this.sizers[e].node.style.display=t?"":"none";for(let e=0;e<this.customHandles.length;e+=1)this.customHandles[e].setVisible(t)}hideSizers(){this.setHandlesVisible(!1)}checkTolerance(t){this.inTolerance&&this.startX!==null&&this.startY!==null&&(isMouseEvent(t.getEvent())||Math.abs(t.getGraphX()-this.startX)>this.graph.getEventTolerance()||Math.abs(t.getGraphY()-this.startY)>this.graph.getEventTolerance())&&(this.inTolerance=!1)}updateHint(t){}removeHint(){}roundAngle(t){return Math.round(t*10)/10}roundLength(t){return Math.round(t*100)/100}mouseMove(t,e){!e.isConsumed()&&this.index!=null?(this.checkTolerance(e),this.inTolerance||(this.index<=InternalEvent.CUSTOM_HANDLE?this.customHandles!=null&&(this.customHandles[InternalEvent.CUSTOM_HANDLE-this.index].processEvent(e),this.customHandles[InternalEvent.CUSTOM_HANDLE-this.index].active=!0,this.ghostPreview!=null?(this.ghostPreview.apply(this.state),this.ghostPreview.strokeWidth=this.getSelectionStrokeWidth()/this.ghostPreview.scale/this.ghostPreview.scale,this.ghostPreview.isDashed=this.isSelectionDashed(),this.ghostPreview.stroke=this.getSelectionColor(),this.ghostPreview.redraw(),this.selectionBounds!=null&&(this.selectionBorder.node.style.display="none")):(this.movePreviewToFront&&this.moveToFront(),this.customHandles[InternalEvent.CUSTOM_HANDLE-this.index].positionChanged())):this.index===InternalEvent.LABEL_HANDLE?this.moveLabel(e):(this.index===InternalEvent.ROTATION_HANDLE?this.rotateVertex(e):this.resizeVertex(e),this.updateHint(e))),e.consume()):!this.graph.isMouseDown&&!isNullish(this.getHandleForEvent(e))&&e.consume(!1)}isGhostPreview(){return this.state.cell.getChildCount()>0}moveLabel(t){const e=new Point(t.getGraphX(),t.getGraphY()),i=this.graph.view.translate,{scale:s}=this.graph.view;this.graph.isGridEnabledEvent(t.getEvent())&&(e.x=(this.graph.snap(e.x/s-i.x)+i.x)*s,e.y=(this.graph.snap(e.y/s-i.y)+i.y)*s);const n=this.rotationShape?this.sizers.length-2:this.sizers.length-1;this.moveSizerTo(this.sizers[n],e.x,e.y)}rotateVertex(t){const e=new Point(t.getGraphX(),t.getGraphY());let i=this.state.x+this.state.width/2-e.x,s=this.state.y+this.state.height/2-e.y;if(this.currentAlpha=i!==0?Math.atan(s/i)*180/Math.PI+90:s<0?180:0,i>0&&(this.currentAlpha-=180),this.currentAlpha-=this.startAngle,this.rotationRaster&&this.graph.isGridEnabledEvent(t.getEvent())){let n;i=e.x-this.state.getCenterX(),s=e.y-this.state.getCenterY();const l=Math.sqrt(i*i+s*s);l-this.startDist<2?n=15:l-this.startDist<25?n=5:n=1,this.currentAlpha=Math.round(this.currentAlpha/n)*n}else this.currentAlpha=this.roundAngle(this.currentAlpha);this.selectionBorder.rotation=this.currentAlpha,this.selectionBorder.redraw(),this.livePreviewActive&&this.redrawHandles()}resizeVertex(t){const e=new Point(this.state.getCenterX(),this.state.getCenterY()),i=toRadians(this.state.style.rotation??0),s=new Point(t.getGraphX(),t.getGraphY()),n=this.graph.view.translate,{scale:l}=this.graph.view;let o=Math.cos(-i),a=Math.sin(-i),h=s.x-this.startX,d=s.y-this.startY;const c=o*h-a*d,u=a*h+o*d;h=c,d=u;const g=this.state.cell.getGeometry();if(g&&this.index!==null&&(this.unscaledBounds=this.union(g,h/l,d/l,this.index,this.graph.isGridEnabledEvent(t.getEvent()),1,new Point(0,0),this.isConstrainedEvent(t),this.isCenteredEvent(this.state,t))),g&&!g.relative){let f=this.graph.getMaximumGraphBounds();if(f!=null&&this.parentState!=null&&(f=Rectangle.fromRectangle(f),f.x-=(this.parentState.x-n.x*l)/l,f.y-=(this.parentState.y-n.y*l)/l),this.graph.isConstrainChild(this.state.cell)){let p=this.graph.getCellContainmentArea(this.state.cell);if(p!=null){const y=this.graph.getOverlap(this.state.cell);y>0&&(p=Rectangle.fromRectangle(p),p.x-=p.width*y,p.y-=p.height*y,p.width+=2*p.width*y,p.height+=2*p.height*y),f?(f=Rectangle.fromRectangle(f),f.intersect(p)):f=p}}f&&this.unscaledBounds&&(this.unscaledBounds.x<f.x&&(this.unscaledBounds.width-=f.x-this.unscaledBounds.x,this.unscaledBounds.x=f.x),this.unscaledBounds.y<f.y&&(this.unscaledBounds.height-=f.y-this.unscaledBounds.y,this.unscaledBounds.y=f.y),this.unscaledBounds.x+this.unscaledBounds.width>f.x+f.width&&(this.unscaledBounds.width-=this.unscaledBounds.x+this.unscaledBounds.width-f.x-f.width),this.unscaledBounds.y+this.unscaledBounds.height>f.y+f.height&&(this.unscaledBounds.height-=this.unscaledBounds.y+this.unscaledBounds.height-f.y-f.height))}if(this.unscaledBounds){const f=this.bounds;this.bounds=new Rectangle((this.parentState?this.parentState.x:n.x*l)+this.unscaledBounds.x*l,(this.parentState?this.parentState.y:n.y*l)+this.unscaledBounds.y*l,this.unscaledBounds.width*l,this.unscaledBounds.height*l),g&&g.relative&&this.parentState&&(this.bounds.x+=this.state.x-this.parentState.x,this.bounds.y+=this.state.y-this.parentState.y),o=Math.cos(i),a=Math.sin(i);const p=new Point(this.bounds.getCenterX(),this.bounds.getCenterY());h=p.x-e.x,d=p.y-e.y;const y=o*h-a*d,v=a*h+o*d,S=y-h,w=v-d,C=this.bounds.x-this.state.x,m=this.bounds.y-this.state.y,T=o*C-a*m,b=a*C+o*m;this.bounds.x+=S,this.bounds.y+=w,this.unscaledBounds.x=this.roundLength(this.unscaledBounds.x+S/l),this.unscaledBounds.y=this.roundLength(this.unscaledBounds.y+w/l),this.unscaledBounds.width=this.roundLength(this.unscaledBounds.width),this.unscaledBounds.height=this.roundLength(this.unscaledBounds.height),!this.state.cell.isCollapsed()&&(S!==0||w!==0)?(this.childOffsetX=this.state.x-this.bounds.x+T,this.childOffsetY=this.state.y-this.bounds.y+b):(this.childOffsetX=0,this.childOffsetY=0),f.equals(this.bounds)||(this.livePreviewActive&&this.updateLivePreview(t),this.preview!=null?this.drawPreview():this.updateParentHighlight())}}updateLivePreview(t){const{scale:e}=this.graph.view,i=this.graph.view.translate,s=this.state.clone();this.state.x=this.bounds.x,this.state.y=this.bounds.y,this.state.origin=new Point(this.state.x/e-i.x,this.state.y/e-i.y),this.state.width=this.bounds.width,this.state.height=this.bounds.height;let n=this.state.absoluteOffset;n=new Point(n.x,n.y),this.state.absoluteOffset.x=0,this.state.absoluteOffset.y=0;const l=this.state.cell.getGeometry();if(l!=null){const o=l.offset||this.EMPTY_POINT;o!=null&&!l.relative&&(this.state.absoluteOffset.x=this.state.view.scale*o.x,this.state.absoluteOffset.y=this.state.view.scale*o.y),this.state.view.updateVertexLabelOffset(this.state)}this.state.view.graph.cellRenderer.redraw(this.state,!0),this.state.view.invalidate(this.state.cell),this.state.invalid=!1,this.state.view.validate(),this.redrawHandles(),this.movePreviewToFront&&this.moveToFront(),this.state.control!=null&&this.state.control.node!=null&&(this.state.control.node.style.visibility="hidden"),this.state.setState(s)}moveToFront(){(this.state.text&&this.state.text.node&&this.state.text.node.nextSibling||this.state.shape&&this.state.shape.node&&this.state.shape.node.nextSibling&&(!this.state.text||this.state.shape.node.nextSibling!==this.state.text.node))&&(this.state.shape&&this.state.shape.node&&this.state.shape.node.parentNode&&this.state.shape.node.parentNode.appendChild(this.state.shape.node),this.state.text&&this.state.text.node&&this.state.text.node.parentNode&&this.state.text.node.parentNode.appendChild(this.state.text.node))}mouseUp(t,e){if(this.index!=null&&this.state!=null){const i=new Point(e.getGraphX(),e.getGraphY()),{index:s}=this;this.index=null,this.ghostPreview==null&&(this.state.view.invalidate(this.state.cell,!1,!1),this.state.view.validate()),this.graph.batchUpdate(()=>{if(s<=InternalEvent.CUSTOM_HANDLE){if(this.customHandles!=null){const n=this.state.view.graph.getCellStyle(this.state.cell);this.customHandles[InternalEvent.CUSTOM_HANDLE-s].active=!1,this.customHandles[InternalEvent.CUSTOM_HANDLE-s].execute(e),this.customHandles!=null&&this.customHandles[InternalEvent.CUSTOM_HANDLE-s]!=null&&(this.state.style=n,this.customHandles[InternalEvent.CUSTOM_HANDLE-s].positionChanged())}}else if(s===InternalEvent.ROTATION_HANDLE)if(this.currentAlpha!=null){const n=this.currentAlpha-(this.state.style.rotation??0);n!==0&&this.rotateCell(this.state.cell,n)}else this.rotateClick();else{const n=this.graph.isGridEnabledEvent(e.getEvent()),l=toRadians(this.state.style.rotation??0),o=Math.cos(-l),a=Math.sin(-l);let h=i.x-this.startX,d=i.y-this.startY;const c=o*h-a*d,u=a*h+o*d;h=c,d=u;const g=this.graph.view.scale,f=this.isRecursiveResize(this.state,e);this.resizeCell(this.state.cell,this.roundLength(h/g),this.roundLength(d/g),s,n,this.isConstrainedEvent(e),f)}}),e.consume(),this.reset(),this.redrawHandles()}}isRecursiveResize(t,e){return this.graph.isRecursiveResize(this.state)}rotateClick(){}rotateCell(t,e,i){if(e!==0){const s=this.graph.getDataModel();if(t.isVertex()||t.isEdge()){if(!t.isEdge()){const o=(this.graph.getCurrentCellStyle(t).rotation??0)+e;this.graph.setCellStyles("rotation",o,[t])}let n=t.getGeometry();if(n&&i){const l=i.getGeometry();if(l!=null&&!i.isEdge()&&(n=n.clone(),n.rotate(e,new Point(l.width/2,l.height/2)),s.setGeometry(t,n)),t.isVertex()&&!n.relative||t.isEdge()){const o=t.getChildCount();for(let a=0;a<o;a+=1)this.rotateCell(t.getChildAt(a),e,t)}}}}}reset(){if(this.index!==null&&this.sizers[this.index].node.style.display==="none"&&(this.sizers[this.index].node.style.display=""),this.index=null,this.currentAlpha=null,this.preview&&(this.preview.destroy(),this.preview=null),this.ghostPreview&&(this.ghostPreview.destroy(),this.ghostPreview=null),this.livePreviewActive){for(let t=0;t<this.sizers.length;t+=1)this.sizers[t].node.style.display="";this.state.control&&this.state.control.node&&(this.state.control.node.style.visibility="")}for(let t=0;t<this.customHandles.length;t+=1)this.customHandles[t].active?(this.customHandles[t].active=!1,this.customHandles[t].reset()):this.customHandles[t].setVisible(!0);this.selectionBorder.node.style.display="inline",this.selectionBounds=this.getSelectionBounds(this.state),this.bounds=new Rectangle(this.selectionBounds.x,this.selectionBounds.y,this.selectionBounds.width,this.selectionBounds.height),this.drawPreview(),this.removeHint(),this.redrawHandles(),this.edgeHandlers=[],this.handlesVisible=!0,this.unscaledBounds=null}resizeCell(t,e,i,s,n,l,o){let a=t.getGeometry();if(a){if(s===InternalEvent.LABEL_HANDLE&&this.labelShape&&this.labelShape.bounds){const h=-toRadians(this.state.style.rotation??0),d=Math.cos(h),c=Math.sin(h),{scale:u}=this.graph.view,g=getRotatedPoint(new Point(Math.round((this.labelShape.bounds.getCenterX()-this.startX)/u),Math.round((this.labelShape.bounds.getCenterY()-this.startY)/u)),d,c);a=a.clone(),a.offset==null?a.offset=g:(a.offset.x+=g.x,a.offset.y+=g.y),this.graph.model.setGeometry(t,a)}else if(this.unscaledBounds){const{scale:h}=this.graph.view;(this.childOffsetX!==0||this.childOffsetY!==0)&&this.moveChildren(t,Math.round(this.childOffsetX/h),Math.round(this.childOffsetY/h)),this.graph.resizeCell(t,this.unscaledBounds,o)}}}moveChildren(t,e,i){const s=this.graph.getDataModel(),n=t.getChildCount();for(let l=0;l<n;l+=1){const o=t.getChildAt(l);let a=o.getGeometry();a!=null&&(a=a.clone(),a.translate(e,i),s.setGeometry(o,a))}}union(t,e,i,s,n,l,o,a,h){if(n=n&&this.graph.isGridEnabled(),this.singleSizer){let m=t.x+t.width+e,T=t.y+t.height+i;n&&(m=this.graph.snap(m/l)*l,T=this.graph.snap(T/l)*l);const b=new Rectangle(t.x,t.y,0,0);return b.add(new Rectangle(m,T,0,0)),b}const d=t.width,c=t.height;let u=t.x-o.x*l,g=u+d,f=t.y-o.y*l,p=f+c;const y=u+d/2,v=f+c/2;s>4?(p+=i,n?p=this.graph.snap(p/l)*l:p=Math.round(p/l)*l):s<3&&(f+=i,n?f=this.graph.snap(f/l)*l:f=Math.round(f/l)*l),s===0||s===3||s===5?(u+=e,n?u=this.graph.snap(u/l)*l:u=Math.round(u/l)*l):(s===2||s===4||s===7)&&(g+=e,n?g=this.graph.snap(g/l)*l:g=Math.round(g/l)*l);let S=g-u,w=p-f;if(a){const m=this.state.cell.getGeometry();if(m!=null){const T=m.width/m.height;s===1||s===2||s===7||s===6?S=w*T:w=S/T,s===0&&(u=g-S,f=p-w)}}if(h){S+=S-d,w+=w-c;const m=y-(u+S/2),T=v-(f+w/2);u+=m,f+=T,g+=m,p+=T}S<0&&(u+=S,S=Math.abs(S)),w<0&&(f+=w,w=Math.abs(w));const C=new Rectangle(u+o.x*l,f+o.y*l,S,w);return this.minBounds!=null&&(C.width=Math.max(C.width,this.minBounds.x*l+this.minBounds.width*l+Math.max(0,this.x0*l-C.x)),C.height=Math.max(C.height,this.minBounds.y*l+this.minBounds.height*l+Math.max(0,this.y0*l-C.y))),C}redraw(t){this.selectionBounds=this.getSelectionBounds(this.state),this.bounds=new Rectangle(this.selectionBounds.x,this.selectionBounds.y,this.selectionBounds.width,this.selectionBounds.height),this.drawPreview(),t||this.redrawHandles()}getHandlePadding(){const t=new Point(0,0);let e=this.tolerance;return this.sizers.length>0&&this.sizers[0].bounds&&(this.bounds.width<2*this.sizers[0].bounds.width+2*e||this.bounds.height<2*this.sizers[0].bounds.height+2*e)&&(e/=2,t.x=this.sizers[0].bounds.width+e,t.y=this.sizers[0].bounds.height+e),t}getSizerBounds(){return this.bounds}redrawHandles(){let t=this.getSizerBounds();const e=this.tolerance;this.horizontalOffset=0,this.verticalOffset=0;for(let i=0;i<this.customHandles.length;i+=1){const s=this.customHandles[i].shape;if(s){const n=s.node.style.display;this.customHandles[i].redraw(),s.node.style.display=n,s.node.style.visibility=this.handlesVisible&&this.isCustomHandleVisible(this.customHandles[i])?"":"hidden"}}if(this.sizers.length>0&&this.sizers[0]){if(this.index===null&&this.manageSizers&&this.sizers.length>=8){const n=this.getHandlePadding();this.horizontalOffset=n.x,this.verticalOffset=n.y,(this.horizontalOffset!==0||this.verticalOffset!==0)&&(t=new Rectangle(t.x,t.y,t.width,t.height),t.x-=this.horizontalOffset/2,t.width+=this.horizontalOffset,t.y-=this.verticalOffset/2,t.height+=this.verticalOffset),this.sizers.length>=8&&(this.sizers[0].bounds&&(t.width<2*this.sizers[0].bounds.width+2*e||t.height<2*this.sizers[0].bounds.height+2*e)?(this.sizers[0].node.style.display="none",this.sizers[2].node.style.display="none",this.sizers[5].node.style.display="none",this.sizers[7].node.style.display="none"):this.handlesVisible&&(this.sizers[0].node.style.display="",this.sizers[2].node.style.display="",this.sizers[5].node.style.display="",this.sizers[7].node.style.display=""))}const i=t.x+t.width,s=t.y+t.height;if(this.singleSizer)this.moveSizerTo(this.sizers[0],i,s);else{const n=t.x+t.width/2,l=t.y+t.height/2;if(this.sizers.length>=8){const o=["nw-resize","n-resize","ne-resize","e-resize","se-resize","s-resize","sw-resize","w-resize"],a=toRadians(this.state.style.rotation??0),h=Math.cos(a),d=Math.sin(a),c=Math.round(a*4/Math.PI),u=new Point(t.getCenterX(),t.getCenterY());let g=getRotatedPoint(new Point(t.x,t.y),h,d,u);this.moveSizerTo(this.sizers[0],g.x,g.y),this.sizers[0].setCursor(o[mod(0+c,o.length)]),g.x=n,g.y=t.y,g=getRotatedPoint(g,h,d,u),this.moveSizerTo(this.sizers[1],g.x,g.y),this.sizers[1].setCursor(o[mod(1+c,o.length)]),g.x=i,g.y=t.y,g=getRotatedPoint(g,h,d,u),this.moveSizerTo(this.sizers[2],g.x,g.y),this.sizers[2].setCursor(o[mod(2+c,o.length)]),g.x=t.x,g.y=l,g=getRotatedPoint(g,h,d,u),this.moveSizerTo(this.sizers[3],g.x,g.y),this.sizers[3].setCursor(o[mod(7+c,o.length)]),g.x=i,g.y=l,g=getRotatedPoint(g,h,d,u),this.moveSizerTo(this.sizers[4],g.x,g.y),this.sizers[4].setCursor(o[mod(3+c,o.length)]),g.x=t.x,g.y=s,g=getRotatedPoint(g,h,d,u),this.moveSizerTo(this.sizers[5],g.x,g.y),this.sizers[5].setCursor(o[mod(6+c,o.length)]),g.x=n,g.y=s,g=getRotatedPoint(g,h,d,u),this.moveSizerTo(this.sizers[6],g.x,g.y),this.sizers[6].setCursor(o[mod(5+c,o.length)]),g.x=i,g.y=s,g=getRotatedPoint(g,h,d,u),this.moveSizerTo(this.sizers[7],g.x,g.y),this.sizers[7].setCursor(o[mod(4+c,o.length)]),g.x=n+this.state.absoluteOffset.x,g.y=l+this.state.absoluteOffset.y,g=getRotatedPoint(g,h,d,u),this.moveSizerTo(this.sizers[8],g.x,g.y)}else this.state.width>=2&&this.state.height>=2?this.moveSizerTo(this.sizers[0],n+this.state.absoluteOffset.x,l+this.state.absoluteOffset.y):this.moveSizerTo(this.sizers[0],this.state.x,this.state.y)}}if(this.rotationShape){const i=toRadians(this.currentAlpha??this.state.style.rotation??0),s=Math.cos(i),n=Math.sin(i),l=new Point(this.state.getCenterX(),this.state.getCenterY()),o=getRotatedPoint(this.getRotationHandlePosition(),s,n,l);this.rotationShape.node!=null&&(this.moveSizerTo(this.rotationShape,o.x,o.y),this.rotationShape.node.style.visibility=this.state.view.graph.isEditing()||!this.handlesVisible?"hidden":"")}if(this.selectionBorder!=null&&(this.selectionBorder.rotation=this.state.style.rotation??0),this.edgeHandlers!=null)for(let i=0;i<this.edgeHandlers.length;i+=1)this.edgeHandlers[i].redraw()}isCustomHandleVisible(t){return!this.graph.isEditing()&&this.state.view.graph.getSelectionCount()===1}getRotationHandlePosition(){return new Point(this.bounds.x+this.bounds.width/2,this.bounds.y+this.rotationHandleVSpacing)}isParentHighlightVisible(){const t=this.state.cell.getParent();return t?!this.graph.isCellSelected(t):!1}updateParentHighlight(){if(!this.isDestroyed()){const t=this.isParentHighlightVisible(),e=this.state.cell.getParent(),i=e?this.graph.view.getState(e):null;if(this.parentHighlight)if(e&&e.isVertex()&&t){const s=this.parentHighlight.bounds;i&&s&&(s.x!==i.x||s.y!==i.y||s.width!==i.width||s.height!==i.height)&&(this.parentHighlight.bounds=Rectangle.fromRectangle(i),this.parentHighlight.redraw())}else i!=null&&i.parentHighlight===this.parentHighlight&&(i.parentHighlight=null),this.parentHighlight.destroy(),this.parentHighlight=null;else this.parentHighlightEnabled&&t&&e&&e.isVertex()&&i!=null&&i.parentHighlight==null&&(this.parentHighlight=this.createParentHighlightShape(i),this.parentHighlight.dialect="svg",this.parentHighlight.pointerEvents=!1,this.parentHighlight.rotation=i.style.rotation??0,this.parentHighlight.init(this.graph.getView().getOverlayPane()),this.parentHighlight.redraw(),i.parentHighlight=this.parentHighlight)}}drawPreview(){this.preview!=null&&(this.preview.bounds=this.bounds,this.preview.node.parentNode===this.graph.container&&(this.preview.bounds.width=Math.max(0,this.preview.bounds.width-1),this.preview.bounds.height=Math.max(0,this.preview.bounds.height-1)),this.preview.rotation=this.state.style.rotation??0,this.preview.redraw()),this.selectionBorder.bounds=this.getSelectionBorderBounds(),this.selectionBorder.redraw(),this.updateParentHighlight()}getSelectionBorderBounds(){return this.bounds}isDestroyed(){return this.selectionBorder==null}onDestroy(){if(this.state.view.graph.removeListener(this.escapeHandler),this.escapeHandler=()=>{},this.preview&&(this.preview.destroy(),this.preview=null),this.parentHighlight){const t=this.state.cell.getParent(),e=t?this.graph.view.getState(t):null;e&&e.parentHighlight===this.parentHighlight&&(e.parentHighlight=null),this.parentHighlight.destroy(),this.parentHighlight=null}this.ghostPreview&&(this.ghostPreview.destroy(),this.ghostPreview=null),this.selectionBorder&&this.selectionBorder.destroy(),this.labelShape=null,this.removeHint();for(let t=0;t<this.sizers.length;t+=1)this.sizers[t].destroy();this.sizers=[];for(let t=0;t<this.customHandles.length;t+=1)this.customHandles[t].destroy();this.customHandles=[]}}function isI18nEnabled(){return GlobalConfig.i18n.isEnabled()}function translate(r,t,e){return GlobalConfig.i18n.get(r,t,e)}class ElbowEdgeHandler extends EdgeHandler{constructor(t){super(t),this.flipEnabled=!0,this.doubleClickOrientationResource=isI18nEnabled()?"doubleClickOrientation":""}createBends(){const t=[];let e=this.createHandleShape(0);return this.initBend(e),e.setCursor(EdgeHandlerConfig.cursorTerminal),t.push(e),t.push(this.createVirtualBend(i=>{!isConsumed(i)&&this.flipEnabled&&(this.graph.flipEdge(this.state.cell),InternalEvent.consume(i))})),this.points.push(new Point(0,0)),e=this.createHandleShape(2),this.initBend(e),e.setCursor(EdgeHandlerConfig.cursorTerminal),t.push(e),t}createVirtualBend(t){const e=this.createHandleShape();return this.initBend(e,t),e.setCursor(this.getCursorForBend()),this.graph.isCellBendable(this.state.cell)||(e.node.style.display="none"),e}getCursorForBend(){return this.state.style.edgeStyle==="topToBottomEdgeStyle"||this.state.style.edgeStyle==="elbowEdgeStyle"&&this.state.style.elbow==="vertical"?"row-resize":"col-resize"}getTooltipForNode(t){let e=null;return this.bends!=null&&this.bends[1]!=null&&(t===this.bends[1].node||t.parentNode===this.bends[1].node)&&(e=this.doubleClickOrientationResource,e=translate(e)||e),e}convertPoint(t,e){const i=this.graph.getView().getScale(),s=this.graph.getView().getTranslate(),{origin:n}=this.state;return e&&(t.x=this.graph.snap(t.x),t.y=this.graph.snap(t.y)),t.x=Math.round(t.x/i-s.x-n.x),t.y=Math.round(t.y/i-s.y-n.y),t}redrawInnerBends(t,e){const i=this.state.cell.getGeometry(),s=this.state.absolutePoints;let n=null;s.length>1?(t=s[1],e=s[s.length-2]):i.points!=null&&i.points.length>0&&(n=s[0]),n==null?n=new Point(t.x+(e.x-t.x)/2,t.y+(e.y-t.y)/2):n=new Point(this.graph.getView().scale*(n.x+this.graph.getView().translate.x+this.state.origin.x),this.graph.getView().scale*(n.y+this.graph.getView().translate.y+this.state.origin.y));const l=this.bends[1].bounds;let o=l.width,a=l.height,h=new Rectangle(Math.round(n.x-o/2),Math.round(n.y-a/2),o,a);this.manageLabelHandle?this.checkLabelHandle(h):this.handleImage==null&&this.labelShape.visible&&this.labelShape.bounds&&intersects(h,this.labelShape.bounds)&&(o=HandleConfig.size+3,a=o,h=new Rectangle(Math.floor(n.x-o/2),Math.floor(n.y-a/2),o,a)),this.bends[1].bounds=h,this.bends[1].redraw(),this.manageLabelHandle&&this.checkLabelHandle(this.bends[1].bounds)}}class EdgeSegmentHandler extends ElbowEdgeHandler{constructor(t){super(t),this.points=[]}getCurrentPoints(){let t=this.state.absolutePoints;const e=Math.max(1,this.graph.view.scale);if(t.length===2&&t[0]&&t[1]||t.length===3&&t[0]&&t[1]&&t[2]&&(Math.abs(t[0].x-t[1].x)<e&&Math.abs(t[1].x-t[2].x)<e||Math.abs(t[0].y-t[1].y)<e&&Math.abs(t[1].y-t[2].y)<e)){const i=t[0].x+(t[t.length-1].x-t[0].x)/2,s=t[0].y+(t[t.length-1].y-t[0].y)/2;t=[t[0],new Point(i,s),new Point(i,s),t[t.length-1]]}return t}getPreviewPoints(t){if(this.isSource||this.isTarget)return super.getPreviewPoints(t);const e=this.getCurrentPoints();let i=this.convertPoint(e[0].clone(),!1);t=this.convertPoint(t.clone(),!1);let s=[];for(let n=1;n<e.length;n+=1){const l=this.convertPoint(e[n].clone(),!1);n===this.index&&(Math.round(i.x-l.x)===0&&(i.x=t.x,l.x=t.x),Math.round(i.y-l.y)===0&&(i.y=t.y,l.y=t.y)),n<e.length-1&&s.push(l),i=l}if(s.length===1){const n=this.state.getVisibleTerminalState(!0),l=this.state.getVisibleTerminalState(!1),o=this.state.view.getScale(),a=this.state.view.getTranslate(),h=s[0].x*o+a.x,d=s[0].y*o+a.y;(n!=null&&contains(n,h,d)||l!=null&&contains(l,h,d))&&(s=[t,t])}return s}updatePreviewState(t,e,i,s){if(super.updatePreviewState(t,e,i,s),!this.isSource&&!this.isTarget){e=this.convertPoint(e.clone(),!1);const n=t.absolutePoints;let l=n[0],o=n[1],a=[];for(let g=2;g<n.length;g+=1){const f=n[g];(Math.round(l.x-o.x)!==0||Math.round(o.x-f.x)!==0)&&(Math.round(l.y-o.y)!==0||Math.round(o.y-f.y)!==0)&&a.push(this.convertPoint(o.clone(),!1)),l=o,o=f}const h=this.state.getVisibleTerminalState(!0),d=this.state.getVisibleTerminalState(!1),c=this.state.absolutePoints,u=n[n.length-1];if(a.length===0&&n[0]&&u&&(Math.round(n[0].x-u.x)===0||Math.round(n[0].y-u.y)===0))a=[e,e];else if(n.length===5&&a.length===2&&h!=null&&d!=null&&c!=null&&Math.round(c[0].x-c[c.length-1].x)===0){const g=this.graph.getView(),f=g.getScale(),p=g.getTranslate();let y=g.getRoutingCenterY(h)/f-p.y;const v=this.graph.getConnectionConstraint(t,h,!0);if(v!=null){const C=this.graph.getConnectionPoint(h,v);C!=null&&(this.convertPoint(C,!1),y=C.y)}let S=g.getRoutingCenterY(d)/f-p.y;const w=this.graph.getConnectionConstraint(t,d,!1);if(w){const C=this.graph.getConnectionPoint(d,w);C!=null&&(this.convertPoint(C,!1),S=C.y)}a=[new Point(e.x,y),new Point(e.x,S)]}this.points=a,t.view.updateFixedTerminalPoints(t,h,d),t.view.updatePoints(t,this.points,h,d),t.view.updateFloatingTerminalPoints(t,h,d)}}connect(t,e,i,s,n){const l=this.graph.getDataModel();let o=t.getGeometry(),a=null;if(o!=null&&o.points!=null&&o.points.length>0){const h=this.abspoints;let d=h[0],c=h[1];a=[];for(let u=2;u<h.length;u+=1){const g=h[u];d&&c&&g&&(Math.round(d.x-c.x)!==0||Math.round(c.x-g.x)!==0)&&(Math.round(d.y-c.y)!==0||Math.round(c.y-g.y)!==0)&&a.push(this.convertPoint(c.clone(),!1)),d=c,c=g}}return this.graph.batchUpdate(()=>{a!=null&&(o=t.getGeometry(),o!=null&&(o=o.clone(),o.points=a,l.setGeometry(t,o))),t=super.connect(t,e,i,s,n)}),t}getTooltipForNode(t){return null}start(t,e,i){super.start(t,e,i),this.bends!=null&&this.bends[i]!=null&&!this.isSource&&!this.isTarget&&setOpacity(this.bends[i].node,100)}createBends(){const t=[];let e=this.createHandleShape(0);this.initBend(e),e.setCursor(EdgeHandlerConfig.cursorTerminal),t.push(e);const i=this.getCurrentPoints();if(this.graph.isCellBendable(this.state.cell)){this.points==null&&(this.points=[]);for(let s=0;s<i.length-1;s+=1){e=this.createVirtualBend(),t.push(e);let n=Math.round(i[s].x-i[s+1].x)===0;Math.round(i[s].y-i[s+1].y)===0&&s<i.length-2&&(n=Math.round(i[s].x-i[s+2].x)===0),e.setCursor(n?"col-resize":"row-resize"),this.points.push(new Point(0,0))}}return e=this.createHandleShape(i.length),this.initBend(e),e.setCursor(EdgeHandlerConfig.cursorTerminal),t.push(e),t}redraw(){this.refresh(),super.redraw()}redrawInnerBends(t,e){if(this.graph.isCellBendable(this.state.cell)){const i=this.getCurrentPoints();if(i!=null&&i.length>1){let s=!1;if(i.length===4&&i[0]&&i[1]&&i[2]&&i[3]&&Math.round(i[1].x-i[2].x)===0&&Math.round(i[1].y-i[2].y)===0)if(s=!0,Math.round(i[0].y-i[i.length-1].y)===0){const n=i[0].x+(i[i.length-1].x-i[0].x)/2;i[1]=new Point(n,i[1].y),i[2]=new Point(n,i[2].y)}else{const n=i[0].y+(i[i.length-1].y-i[0].y)/2;i[1]=new Point(i[1].x,n),i[2]=new Point(i[2].x,n)}for(let n=0;n<i.length-1;n+=1)if(this.bends[n+1]!=null){t=i[n],e=i[n+1];const l=new Point(t.x+(e.x-t.x)/2,t.y+(e.y-t.y)/2),o=this.bends[n+1].bounds;this.bends[n+1].bounds=new Rectangle(Math.floor(l.x-o.width/2),Math.floor(l.y-o.height/2),o.width,o.height),this.bends[n+1].redraw(),this.manageLabelHandle&&this.checkLabelHandle(this.bends[n+1].bounds)}s&&(setOpacity(this.bends[1].node,EdgeHandlerConfig.virtualBendOpacity),setOpacity(this.bends[3].node,EdgeHandlerConfig.virtualBendOpacity))}}}}const getTopmostCells=r=>{const t=new Map,e=[];for(let i=0;i<r.length;i+=1)t.set(r[i],!0);for(let i=0;i<r.length;i+=1){const s=r[i];let n=!0,l=s.getParent();for(;l!=null;){if(t.get(l)){n=!1;break}l=l.getParent()}n&&e.push(s)}return e},cloneCells=(r,t=!0,e={})=>{const i=[];for(const s of r)i.push(cloneCellImpl(s,e,t));for(let s=0;s<i.length;s+=1)i[s]!=null&&restoreClone(i[s],r[s],e);return i},cloneCellImpl=(r,t={},e=!1)=>{const i=ObjectIdentity.get(r);let s=t?t[i]:null;if(s==null&&(s=r.clone(),t[i]=s,e)){const n=r.getChildCount();for(let l=0;l<n;l+=1){const o=cloneCellImpl(r.getChildAt(l),t,!0);s.insert(o)}}return s},restoreClone=(r,t,e)=>{const i=t.getTerminal(!0);if(i!=null){const l=e[ObjectIdentity.get(i)];l!=null&&l.insertEdge(r,!0)}const s=t.getTerminal(!1);if(s!=null){const l=e[ObjectIdentity.get(s)];l!=null&&l.insertEdge(r,!1)}const n=r.getChildCount();for(let l=0;l<n;l+=1)restoreClone(r.getChildAt(l),t.getChildAt(l),e)},CellsMixin={cellsResizable:!0,cellsBendable:!0,cellsSelectable:!0,cellsDisconnectable:!0,autoSizeCells:!1,autoSizeCellsOnAdd:!1,cellsLocked:!1,cellsCloneable:!0,cellsDeletable:!0,cellsMovable:!0,extendParents:!0,extendParentsOnAdd:!0,extendParentsOnMove:!1,getBoundingBox(r){let t=null;if(r.length>0){for(const e of r)if(e.isVertex()||e.isEdge()){const i=this.getView().getBoundingBox(this.getView().getState(e),!0);i&&(t?t.add(i):t=Rectangle.fromRectangle(i))}}return t},removeStateForCell(r){for(const t of r.getChildren())this.removeStateForCell(t);this.getView().invalidate(r,!1,!0),this.getView().removeState(r)},getCurrentCellStyle(r,t=!1){const e=t?null:this.getView().getState(r);return e?e.style:this.getCellStyle(r)},getCellStyle(r){const t=r.getStyle(),e=this.getStylesheet(),i=r.isEdge()?e.getDefaultEdgeStyle():e.getDefaultVertexStyle();return this.postProcessCellStyle(e.getCellStyle(t,i??{}))},postProcessCellStyle(r){var i;if(!r.image)return r;const t=r.image;let e=((i=this.getPlugin("image-bundle"))==null?void 0:i.getImageFromBundles(t))??null;if(e?r.image=e:e=t,e&&e.substring(0,11)==="data:image/"){if(e.substring(0,20)==="data:image/svg+xml,<")e=e.substring(0,19)+encodeURIComponent(e.substring(19));else if(e.substring(0,22)!=="data:image/svg+xml,%3C"){const s=e.indexOf(",");s>0&&e.substring(s-7,s+1)!==";base64,"&&(e=`${e.substring(0,s)};base64,${e.substring(s+1)}`)}r.image=e}return r},setCellStyle(r,t){t=t??this.getSelectionCells(),this.batchUpdate(()=>{for(const e of t)this.getDataModel().setStyle(e,r)})},toggleCellStyle(r,t=!1,e){return e=e??this.getSelectionCell(),this.toggleCellStyles(r,t,[e])},toggleCellStyles(r,t=!1,e){let i=!1;return e=e??this.getSelectionCells(),e.length>0&&(i=!(this.getCurrentCellStyle(e[0])[r]??t),this.setCellStyles(r,i,e)),i},setCellStyles(r,t,e){e=e??this.getSelectionCells(),setCellStyles(this.getDataModel(),e,r,t)},toggleCellStyleFlags(r,t,e){e=e??this.getSelectionCells(),this.setCellStyleFlags(r,t,null,e)},setCellStyleFlags(r,t,e=null,i){i=i??this.getSelectionCells(),i.length>0&&(e===null&&(e=((this.getCurrentCellStyle(i[0])[r]||0)&t)!==t),setCellStyleFlags(this.getDataModel(),i,r,t,e))},alignCells(r,t,e=null){if(t=t??this.getSelectionCells(),t.length>1){if(e===null)for(const i of t){const s=this.getView().getState(i);if(s&&!i.isEdge())if(e===null)switch(r){case"center":e=s.x+s.width/2;break;case"right":e=s.x+s.width;break;case"top":e=s.y;break;case"middle":e=s.y+s.height/2;break;case"bottom":e=s.y+s.height;break;default:e=s.x;break}else switch(r){case"right":{e=Math.max(e,s.x+s.width);break}case"top":{e=Math.min(e,s.y);break}case"bottom":{e=Math.max(e,s.y+s.height);break}default:e=Math.min(e,s.x)}}if(e!==null){const i=this.getView().scale;this.batchUpdate(()=>{const s=e;for(const n of t){const l=this.getView().getState(n);if(l!=null){let o=n.getGeometry();if(o!=null&&!n.isEdge()){switch(o=o.clone(),r){case"center":{o.x+=(s-l.x-l.width/2)/i;break}case"right":{o.x+=(s-l.x-l.width)/i;break}case"top":{o.y+=(s-l.y)/i;break}case"middle":{o.y+=(s-l.y-l.height/2)/i;break}case"bottom":{o.y+=(s-l.y-l.height)/i;break}default:o.x+=(s-l.x)/i}this.resizeCell(n,o)}}}this.fireEvent(new EventObject(InternalEvent.ALIGN_CELLS,{align:r,cells:t}))})}}return t},cloneCell(r,t=!1,e={},i=!1){return this.cloneCells([r],t,e,i)[0]},cloneCells(r,t=!0,e={},i=!1){let s;const n=new Map,l=[];for(const o of r)n.set(o,!0),l.push(o);if(l.length>0){const{scale:o}=this.getView(),a=this.getView().translate,h=[];s=cloneCells(r,!0,e);for(let d=0;d<r.length;d+=1){const c=r[d],u=s[d];if(!(!t&&u.isEdge()&&this.getEdgeValidationError(u,u.getTerminal(!0),u.getTerminal(!1))!==null)){h.push(u);const g=u.getGeometry();if(g){const f=this.getView().getState(c),p=c.getParent(),y=p?this.getView().getState(p):null;if(f&&y){const v=i?0:y.origin.x,S=i?0:y.origin.y;if(u.isEdge()){const w=f.absolutePoints;let C=c.getTerminal(!0);for(;C&&!n.get(C);)C=C.getParent();!C&&w[0]&&g.setTerminalPoint(new Point(w[0].x/o-a.x,w[0].y/o-a.y),!0);let m=c.getTerminal(!1);for(;m&&!n.get(m);)m=m.getParent();const T=w.length-1,b=w[T];!m&&b&&g.setTerminalPoint(new Point(b.x/o-a.x,b.y/o-a.y),!1);const{points:H}=g;if(H)for(const R of H)R.x+=v,R.y+=S}else g.translate(v,S)}}}}s=h}else s=[];return s},addCell(r,t=null,e=null,i=null,s=null){return this.addCells([r],t,e,i,s)[0]},addCells(r,t=null,e=null,i=null,s=null,n=!1){const l=t??this.getDefaultParent(),o=e??l.getChildCount();return this.batchUpdate(()=>{this.cellsAdded(r,l,o,i,s,n,!0),this.fireEvent(new EventObject(InternalEvent.ADD_CELLS,{cells:r,p:l,i:o,source:i,target:s}))}),r},cellsAdded(r,t,e,i=null,s=null,n=!1,l=!1,o=!0){this.batchUpdate(()=>{const a=n?this.getView().getState(t):null,h=a?a.origin:null,d=new Point(0,0);r.forEach((c,u)=>{const g=c.getParent();if(h&&c!==t&&t!==g){const f=g?this.getView().getState(g):null,p=f?f.origin:d;let y=c.getGeometry();if(y){const v=p.x-h.x,S=p.y-h.y;y=y.clone(),y.translate(v,S),!y.relative&&c.isVertex()&&!this.isAllowNegativeCoordinates()&&(y.x=Math.max(0,y.x),y.y=Math.max(0,y.y)),this.getDataModel().setGeometry(c,y)}}t===g&&e+u>t.getChildCount()&&e--,this.getDataModel().add(t,c,e+u),this.autoSizeCellsOnAdd&&this.autoSizeCell(c,!0),(!o||o)&&this.isExtendParentsOnAdd(c)&&this.isExtendParent(c)&&this.extendParent(c),(!l||l)&&this.constrainChild(c),i&&this.cellConnected(c,i,!0),s&&this.cellConnected(c,s,!1)}),this.fireEvent(new EventObject(InternalEvent.CELLS_ADDED,{cells:r,parent:t,index:e,source:i,target:s,absolute:n}))})},autoSizeCell(r,t=!0){if(t)for(const e of r.getChildren())this.autoSizeCell(e);r.isVertex()&&this.isAutoSizeCell(r)&&this.updateCellSize(r)},removeCells(r=null,t=!0){if(r||(r=this.getDeletableCells(this.getSelectionCells())),t)r=this.getDeletableCells(this.addAllEdges(r));else{r=r.slice();const e=this.getDeletableCells(this.getAllEdges(r)),i=new Map;for(const s of r)i.set(s,!0);for(const s of e)!this.getView().getState(s)&&!i.get(s)&&(i.set(s,!0),r.push(s))}return this.batchUpdate(()=>{this.cellsRemoved(r),this.fireEvent(new EventObject(InternalEvent.REMOVE_CELLS,{cells:r,includeEdges:t}))}),r??[]},cellsRemoved(r){if(r.length>0){const{scale:t}=this.getView(),e=this.getView().translate;this.batchUpdate(()=>{const i=new Map;for(const s of r)i.set(s,!0);for(const s of r){const n=this.getAllEdges([s]),l=(o,a)=>{let h=o.getGeometry();if(h){const d=o.getTerminal(a);let c=!1,u=d;for(;u;){if(s===u){c=!0;break}u=u.getParent()}if(c){h=h.clone();const g=this.getView().getState(o);if(g){const f=g.absolutePoints,p=a?0:f.length-1,y=f[p];h.setTerminalPoint(new Point(y.x/t-e.x-g.origin.x,y.y/t-e.y-g.origin.y),a)}else if(d){const f=this.getView().getState(d);f&&h.setTerminalPoint(new Point(f.getCenterX()/t-e.x,f.getCenterY()/t-e.y),a)}this.getDataModel().setGeometry(o,h),this.getDataModel().setTerminal(o,null,a)}}};for(const o of n)i.get(o)||(i.set(o,!0),l(o,!0),l(o,!1));this.getDataModel().remove(s)}this.fireEvent(new EventObject(InternalEvent.CELLS_REMOVED,{cells:r}))})}},toggleCells(r=!1,t,e=!0){return t=t??this.getSelectionCells(),e&&(t=this.addAllEdges(t)),this.batchUpdate(()=>{this.cellsToggled(t,r),this.fireEvent(new EventObject(InternalEvent.TOGGLE_CELLS,{show:r,cells:t,includeEdges:e}))}),t},cellsToggled(r,t=!1){r.length>0&&this.batchUpdate(()=>{for(const e of r)this.getDataModel().setVisible(e,t)})},updateCellSize(r,t=!1){return this.batchUpdate(()=>{this.cellSizeUpdated(r,t),this.fireEvent(new EventObject(InternalEvent.UPDATE_CELL_SIZE,{cell:r,ignoreChildren:t}))}),r},cellSizeUpdated(r,t=!1){this.batchUpdate(()=>{const e=this.getPreferredSizeForCell(r);let i=r.getGeometry();if(e&&i){const s=r.isCollapsed();if(i=i.clone(),this.isSwimlane(r)){const n=this.getCellStyle(r),l=r.getStyle();n.horizontal??!0?(l.startSize=e.height+8,s&&(i.height=e.height+8),i.width=e.width):(l.startSize=e.width+8,s&&(i.width=e.width+8),i.height=e.height),this.getDataModel().setStyle(r,l)}else{const n=this.getView().createState(r),l=n.style.align??"center";l==="right"?i.x+=i.width-e.width:l==="center"&&(i.x+=Math.round((i.width-e.width)/2));const o=n.getVerticalAlign();o==="bottom"?i.y+=i.height-e.height:o==="middle"&&(i.y+=Math.round((i.height-e.height)/2)),i.width=e.width,i.height=e.height}if(!t&&!s){const n=this.getView().getBounds(r.getChildren());if(n!=null){const l=this.getView().translate,{scale:o}=this.getView(),a=(n.x+n.width)/o-i.x-l.x,h=(n.y+n.height)/o-i.y-l.y;i.width=Math.max(i.width,a),i.height=Math.max(i.height,h)}}this.cellsResized([r],[i],!1)}})},getPreferredSizeForCell(r,t=null){let e=null;const i=this.getView().createState(r),{style:s}=i;if(!r.isEdge()){const n=s.fontSize||StyleDefaultsConfig.fontSize;let l=0,o=0;(i.getImageSrc()||s.image)&&s.shape==="label"&&(s.verticalAlign==="middle"&&(l+=s.imageWidth||StyleDefaultsConfig.imageSize),s.align!=="center"&&(o+=s.imageHeight||StyleDefaultsConfig.imageSize)),l+=2*(s.spacing||0),l+=s.spacingLeft||0,l+=s.spacingRight||0,o+=2*(s.spacing||0),o+=s.spacingTop||0,o+=s.spacingBottom||0;const a=this.getFoldingImage(i);a&&(l+=a.width+8);let h=this.getCellRenderer().getLabelValue(i);if(h&&h.length>0){this.isHtmlLabel(i.cell)||(h=htmlEntities(h,!1)),h=h.replace(/\n/g,"<br>");const d=getSizeForString(h,n,s.fontFamily,t,s.fontStyle);let c=d.width+l,u=d.height+o;if(!(s.horizontal??!0)){const g=u;u=c,c=g}this.isGridEnabled()&&(c=this.snap(c+this.getGridSize()/2),u=this.snap(u+this.getGridSize()/2)),e=new Rectangle(0,0,c,u)}else{const d=4*this.getGridSize();e=new Rectangle(0,0,d,d)}}return e},resizeCell(r,t,e=!1){return this.resizeCells([r],[t],e)[0]},resizeCells(r,t,e){return e=e??this.isRecursiveResize(),this.batchUpdate(()=>{const i=this.cellsResized(r,t,e);this.fireEvent(new EventObject(InternalEvent.RESIZE_CELLS,{cells:r,bounds:t,prev:i}))}),r},cellsResized(r,t,e=!1){const i=[];return r.length===t.length&&this.batchUpdate(()=>{r.forEach((s,n)=>{i.push(this.cellResized(s,t[n],!1,e)),this.isExtendParent(s)&&this.extendParent(s),this.constrainChild(s)}),this.isResetEdgesOnResize()&&this.resetEdges(r),this.fireEvent(new EventObject(InternalEvent.CELLS_RESIZED,{cells:r,bounds:t,prev:i}))}),i},cellResized(r,t,e=!1,i=!1){const s=r.getGeometry();if(s&&(s.x!==t.x||s.y!==t.y||s.width!==t.width||s.height!==t.height)){const n=s.clone();if(!e&&n.relative){const{offset:l}=n;l&&(l.x+=t.x-n.x,l.y+=t.y-n.y)}else n.x=t.x,n.y=t.y;n.width=t.width,n.height=t.height,!n.relative&&r.isVertex()&&!this.isAllowNegativeCoordinates()&&(n.x=Math.max(0,n.x),n.y=Math.max(0,n.y)),this.batchUpdate(()=>{i&&this.resizeChildCells(r,n),this.getDataModel().setGeometry(r,n),this.constrainChildCells(r)})}return s},resizeChildCells(r,t){const e=r.getGeometry();if(e){const i=e.width!==0?t.width/e.width:1,s=e.height!==0?t.height/e.height:1;for(const n of r.getChildren())this.scaleCell(n,i,s,!0)}},constrainChildCells(r){for(const t of r.getChildren())this.constrainChild(t)},scaleCell(r,t,e,i=!1){let s=r.getGeometry();if(s){const n=this.getCurrentCellStyle(r);s=s.clone();const{x:l}=s,{y:o}=s,a=s.width,h=s.height;s.scale(t,e,n.aspect==="fixed"),n.resizeWidth?s.width=a*t:n.resizeWidth||(s.width=a),n.resizeHeight?s.height=h*e:n.resizeHeight||(s.height=h),this.isCellMovable(r)||(s.x=l,s.y=o),this.isCellResizable(r)||(s.width=a,s.height=h),r.isVertex()?this.cellResized(r,s,!0,i):this.getDataModel().setGeometry(r,s)}},extendParent(r){const t=r.getParent();let e=t?t.getGeometry():null;if(t&&e&&!t.isCollapsed()){const i=r.getGeometry();i&&!i.relative&&(e.width<i.x+i.width||e.height<i.y+i.height)&&(e=e.clone(),e.width=Math.max(e.width,i.x+i.width),e.height=Math.max(e.height,i.y+i.height),this.cellsResized([t],[e],!1))}},importCells(r,t,e,i=null,s=null,n={}){return this.moveCells(r,t,e,!0,i,s,n)},moveCells(r,t=0,e=0,i=!1,s=null,n=null,l={}){if(t!==0||e!==0||i||s){r=getTopmostCells(r);const o=r;this.batchUpdate(()=>{const a=new Map;for(const u of r)a.set(u,!0);const h=u=>{for(;u;){if(a.get(u))return!0;u=u.getParent()}return!1},d=[];for(const u of r){const g=u.getGeometry(),f=u.getParent();(!g||!g.relative||f&&!f.isEdge()||f&&!h(f.getTerminal(!0))&&!h(f.getTerminal(!1)))&&d.push(u)}r=d,i&&(r=this.cloneCells(r,this.isCloneInvalidEdges(),l),s||(s=this.getDefaultParent()));const c=this.isAllowNegativeCoordinates();if(s&&this.setAllowNegativeCoordinates(!0),this.cellsMoved(r,t,e,!i&&this.isDisconnectOnMove()&&this.isAllowDanglingEdges(),!s,this.isExtendParentsOnMove()&&!s),this.setAllowNegativeCoordinates(c),s){const u=s.getChildCount();this.cellsAdded(r,s,u,null,null,!0),i&&r.forEach((g,f)=>{const p=g.getGeometry(),y=o[f].getParent();p&&p.relative&&y&&y.isEdge()&&this.getDataModel().contains(y)&&this.getDataModel().add(y,g)})}this.fireEvent(new EventObject(InternalEvent.MOVE_CELLS,{cells:r,dx:t,dy:e,clone:i,target:s,event:n}))})}return r},cellsMoved(r,t,e,i=!1,s=!1,n=!1){(t!==0||e!==0)&&this.batchUpdate(()=>{i&&this.disconnectGraph(r);for(const l of r)this.translateCell(l,t,e),n&&this.isExtendParent(l)?this.extendParent(l):s&&this.constrainChild(l);this.isResetEdgesOnMove()&&this.resetEdges(r),this.fireEvent(new EventObject(InternalEvent.CELLS_MOVED,{cells:r,dx:t,dy:e,disconnect:i}))})},translateCell(r,t,e){let i=r.getGeometry();if(i){if(i=i.clone(),i.translate(t,e),!i.relative&&r.isVertex()&&!this.isAllowNegativeCoordinates()&&(i.x=Math.max(0,i.x),i.y=Math.max(0,i.y)),i.relative&&!r.isEdge()){const s=r.getParent();let n=0;if(s.isVertex()&&(n=this.getCurrentCellStyle(s).rotation??0),n!==0){const l=toRadians(-n),o=Math.cos(l),a=Math.sin(l),h=getRotatedPoint(new Point(t,e),o,a,new Point(0,0));t=h.x,e=h.y}i.offset?(i.offset.x=i.offset.x+t,i.offset.y=i.offset.y+e):i.offset=new Point(t,e)}this.getDataModel().setGeometry(r,i)}},getCellContainmentArea(r){if(!r.isEdge()){const t=r.getParent();if(t&&t!==this.getDefaultParent()){const e=t.getGeometry();if(e){let i=0,s=0,n=e.width,l=e.height;if(this.isSwimlane(t)){const o=this.getStartSize(t),a=this.getCurrentCellStyle(t),h=a.direction??"east",d=a.flipH??!1,c=a.flipV??!1;if(h==="south"||h==="north"){const u=o.width;o.width=o.height,o.height=u}(h==="east"&&!c||h==="north"&&!d||h==="west"&&c||h==="south"&&d)&&(i=o.width,s=o.height),n-=o.width,l-=o.height}return new Rectangle(i,s,n,l)}}}return null},constrainChild(r,t=!0){let e=r.getGeometry();if(e&&(this.isConstrainRelativeChildren()||!e.relative)){const i=r.getParent();let s=this.getMaximumGraphBounds();if(s&&i){const n=this.getBoundingBoxFromGeometry([i],!1);n&&(s=Rectangle.fromRectangle(s),s.x-=n.x,s.y-=n.y)}if(this.isConstrainChild(r)){let n=this.getCellContainmentArea(r);if(n){const l=this.getOverlap(r);l>0&&(n=Rectangle.fromRectangle(n),n.x-=n.width*l,n.y-=n.height*l,n.width+=2*n.width*l,n.height+=2*n.height*l),s?(s=Rectangle.fromRectangle(s),s.intersect(n)):s=n}}if(s){const n=[r];if(!r.isCollapsed()){const o=r.getDescendants();for(const a of o)a.isVisible()&&n.push(a)}const l=this.getBoundingBoxFromGeometry(n,!1);if(l){e=e.clone();let o=0;e.width>s.width&&(o=e.width-s.width,e.width-=o),l.x+l.width>s.x+s.width&&(o-=l.x+l.width-s.x-s.width-o);let a=0;e.height>s.height&&(a=e.height-s.height,e.height-=a),l.y+l.height>s.y+s.height&&(a-=l.y+l.height-s.y-s.height-a),l.x<s.x&&(o-=l.x-s.x),l.y<s.y&&(a-=l.y-s.y),(o!==0||a!==0)&&(e.relative?(e.offset||(e.offset=new Point),e.offset.x+=o,e.offset.y+=a):(e.x+=o,e.y+=a)),this.getDataModel().setGeometry(r,e)}}}},getChildCells(r,t=!1,e=!1){r=r??this.getDefaultParent();const i=r.getChildCells(t,e),s=[];for(const n of i)n.isVisible()&&s.push(n);return s},getCellAt(r,t,e=null,i=!0,s=!0,n=null){if(e||(e=this.getCurrentRoot(),e||(e=this.getDataModel().getRoot())),e){const l=e.getChildCount();for(let o=l-1;o>=0;o--){const a=e.getChildAt(o),h=this.getCellAt(r,t,a,i,s,n);if(h)return h;if(a.isVisible()&&(s&&a.isEdge()||i&&a.isVertex())){const d=this.getView().getState(a);if(d&&(!n||!n(d,r,t))&&this.intersects(d,r,t))return a}}}return null},getCells(r,t,e,i,s=null,n=[],l=null,o=null,a=!1){if(e>0||i>0||l){const h=this.getDataModel(),d=r+e,c=t+i;if(s||(s=this.getCurrentRoot(),s||(s=h.getRoot())),s)for(const u of s.getChildren()){const g=this.getView().getState(u);if(g&&u.isVisible()&&(!o||!o(g))){const f=g.style.rotation??0;let p=g;f!==0&&(p=getBoundingBox(p,f));const y=l&&u.isVertex()&&intersects(l,p)||!l&&(u.isEdge()||u.isVertex())&&p.x>=r&&p.y+p.height<=c&&p.y>=t&&p.x+p.width<=d;y&&n.push(u),(!y||a)&&this.getCells(r,t,e,i,u,n,l,o,a)}}}return n},getCellsBeyond(r,t,e=null,i=!1,s=!1){const n=[];if((i||s)&&(e||(e=this.getDefaultParent()),e))for(const l of e.getChildren()){const o=this.getView().getState(l);l.isVisible()&&o&&(!i||o.x>=r)&&(!s||o.y>=t)&&n.push(l)}return n},intersects(r,t,e){const i=r.absolutePoints;if(i.length>0){const s=this.getEventTolerance()*this.getEventTolerance();let n=i[0];for(let l=1;l<i.length;l+=1){const o=i[l];if(n&&o&&ptSegDistSq(n.x,n.y,o.x,o.y,t,e)<=s)return!0;n=o}}else{const s=toRadians(r.style.rotation??0);if(s!==0){const n=Math.cos(-s),l=Math.sin(-s),o=new Point(r.getCenterX(),r.getCenterY()),a=getRotatedPoint(new Point(t,e),n,l,o);t=a.x,e=a.y}if(contains(r,t,e))return!0}return!1},isValidAncestor(r,t,e=!1){return e?t.isAncestor(r):(r==null?void 0:r.getParent())===t},isCellLocked(r){const t=r.getGeometry();return this.isCellsLocked()||!!t&&r.isVertex()&&t.relative},isCellsLocked(){return this.cellsLocked},setCellsLocked(r){this.cellsLocked=r},getCloneableCells(r){return this.getDataModel().filterCells(r,t=>this.isCellCloneable(t))},isCellCloneable(r){return this.isCellsCloneable()&&(this.getCurrentCellStyle(r).cloneable??!0)},isCellsCloneable(){return this.cellsCloneable},setCellsCloneable(r){this.cellsCloneable=r},getExportableCells(r){return this.getDataModel().filterCells(r,t=>this.canExportCell(t))},canExportCell(r=null){return this.isExportEnabled()},getImportableCells(r){return this.getDataModel().filterCells(r,t=>this.canImportCell(t))},canImportCell(r=null){return this.isImportEnabled()},isCellSelectable(r){return this.isCellsSelectable()},isCellsSelectable(){return this.cellsSelectable},setCellsSelectable(r){this.cellsSelectable=r},getDeletableCells(r){return this.getDataModel().filterCells(r,t=>this.isCellDeletable(t))},isCellDeletable(r){return this.isCellsDeletable()&&(this.getCurrentCellStyle(r).deletable??!0)},isCellsDeletable(){return this.cellsDeletable},setCellsDeletable(r){this.cellsDeletable=r},isCellRotatable(r){return this.getCurrentCellStyle(r).rotatable??!0},getMovableCells(r){return this.getDataModel().filterCells(r,t=>this.isCellMovable(t))},isCellMovable(r){return this.isCellsMovable()&&!this.isCellLocked(r)&&(this.getCurrentCellStyle(r).movable??!0)},isCellsMovable(){return this.cellsMovable},setCellsMovable(r){this.cellsMovable=r},isCellResizable(r){return this.isCellsResizable()&&!this.isCellLocked(r)&&(this.getCurrentCellStyle(r).resizable??!0)},isCellsResizable(){return this.cellsResizable},setCellsResizable(r){this.cellsResizable=r},isCellBendable(r){return this.isCellsBendable()&&!this.isCellLocked(r)&&(this.getCurrentCellStyle(r).bendable??!0)},isCellsBendable(){return this.cellsBendable},setCellsBendable(r){this.cellsBendable=r},isAutoSizeCell(r){return this.isAutoSizeCells()||(this.getCurrentCellStyle(r).autoSize??!1)},isAutoSizeCells(){return this.autoSizeCells},setAutoSizeCells(r){this.autoSizeCells=r},isExtendParent(r){return!r.isEdge()&&this.isExtendParents()},isExtendParents(){return this.extendParents},setExtendParents(r){this.extendParents=r},isExtendParentsOnAdd(r){return this.extendParentsOnAdd},setExtendParentsOnAdd(r){this.extendParentsOnAdd=r},isExtendParentsOnMove(){return this.extendParentsOnMove},setExtendParentsOnMove(r){this.extendParentsOnMove=r},getCursorForCell(r){return null},getCellBounds(r,t=!1,e=!1){let i=[r];t&&(i=i.concat(r.getEdges()));let s=this.getView().getBounds(i);if(e)for(const n of r.getChildren()){const l=this.getCellBounds(n,t,!0);s&&l?s.add(l):s=l}return s},getBoundingBoxFromGeometry(r,t=!1){let e=null,i=null;for(const s of r)if(t||s.isVertex()){const n=s.getGeometry();if(n){let l=null;if(s.isEdge()){const o=h=>{h&&(i?i.add(new Rectangle(h.x,h.y,0,0)):i=new Rectangle(h.x,h.y,0,0))};s.getTerminal(!0)||o(n.getTerminalPoint(!0)),s.getTerminal(!1)||o(n.getTerminalPoint(!1));const a=n.points;if(a&&a.length>0){i=new Rectangle(a[0].x,a[0].y,0,0);for(let h=1;h<a.length;h++)o(a[h])}l=i}else{const o=s.getParent();n.relative&&o?o.isVertex()&&o!==this.getView().currentRoot&&(i=this.getBoundingBoxFromGeometry([o],!1),i&&(l=new Rectangle(n.x*i.width,n.y*i.height,n.width,n.height),r.includes(o)&&(l.x+=i.x,l.y+=i.y))):(l=Rectangle.fromRectangle(n),o&&o.isVertex()&&r.includes(o)&&(i=this.getBoundingBoxFromGeometry([o],!1),i&&(l.x+=i.x,l.y+=i.y))),l&&n.offset&&(l.x+=n.offset.x,l.y+=n.offset.y);const a=this.getCurrentCellStyle(s);if(l){const h=a.rotation??0;h!==0&&(l=getBoundingBox(l,h))}}l&&(e?e.add(l):e=Rectangle.fromRectangle(l))}}return e}},ConnectionsMixin={constrainChildren:!0,constrainRelativeChildren:!1,disconnectOnMove:!0,cellsDisconnectable:!0,getOutlineConstraint(r,t,e){if(t.shape){const i=this.getView().getPerimeterBounds(t),s=t.style.direction;if(s==="north"||s==="south"){i.x+=i.width/2-i.height/2,i.y+=i.height/2-i.width/2;const u=i.width;i.width=i.height,i.height=u}const n=toRadians(t.shape.getShapeRotation());if(n!==0){const u=Math.cos(-n),g=Math.sin(-n),f=new Point(i.getCenterX(),i.getCenterY());r=getRotatedPoint(r,u,g,f)}let l=1,o=1,a=0,h=0;if(t.cell.isVertex()){let u=t.style.flipH,g=t.style.flipV;if(s==="north"||s==="south"){const f=u;u=g,g=f}u&&(l=-1,a=-i.width),g&&(o=-1,h=-i.height)}r=new Point((r.x-i.x)*l-a+i.x,(r.y-i.y)*o-h+i.y);const d=i.width===0?0:Math.round((r.x-i.x)*1e3/i.width)/1e3,c=i.height===0?0:Math.round((r.y-i.y)*1e3/i.height)/1e3;return new ConnectionConstraint(new Point(d,c),!1)}return null},getAllConnectionConstraints(r,t){var e,i;return((i=(e=r==null?void 0:r.shape)==null?void 0:e.stencil)==null?void 0:i.constraints)??null},getConnectionConstraint(r,t,e=!1){let i=null;const s=r.style[e?"exitX":"entryX"];if(s!==void 0){const a=r.style[e?"exitY":"entryY"];a!==void 0&&(i=new Point(s,a))}let n=!1,l=0,o=0;return i&&(n=r.style[e?"exitPerimeter":"entryPerimeter"]||!1,l=r.style[e?"exitDx":"entryDx"],o=r.style[e?"exitDy":"entryDy"],l=Number.isFinite(l)?l:0,o=Number.isFinite(o)?o:0),new ConnectionConstraint(i,n,null,l,o)},setConnectionConstraint(r,t,e=!1,i=null){i&&this.batchUpdate(()=>{!i||!i.point?(this.setCellStyles(e?"exitX":"entryX",null,[r]),this.setCellStyles(e?"exitY":"entryY",null,[r]),this.setCellStyles(e?"exitDx":"entryDx",null,[r]),this.setCellStyles(e?"exitDy":"entryDy",null,[r]),this.setCellStyles(e?"exitPerimeter":"entryPerimeter",null,[r])):i.point&&(this.setCellStyles(e?"exitX":"entryX",i.point.x,[r]),this.setCellStyles(e?"exitY":"entryY",i.point.y,[r]),this.setCellStyles(e?"exitDx":"entryDx",i.dx,[r]),this.setCellStyles(e?"exitDy":"entryDy",i.dy,[r]),i.perimeter?this.setCellStyles(e?"exitPerimeter":"entryPerimeter",!0,[r]):this.setCellStyles(e?"exitPerimeter":"entryPerimeter",!1,[r]))})},getConnectionPoint(r,t,e=!0){let i=null;if(t.point){const s=this.getView().getPerimeterBounds(r),n=new Point(s.getCenterX(),s.getCenterY()),l=r.style.direction;let o=0;if(r.style.anchorPointDirection){switch(l){case"north":{o+=270;break}case"west":{o+=180;break}case"south":{o+=90;break}}(l==="north"||l==="south")&&s.rotate90()}const{scale:a}=this.getView();i=new Point(s.x+t.point.x*s.width+t.dx*a,s.y+t.point.y*s.height+t.dy*a);let h=r.style.rotation||0;if(t.perimeter){if(o!==0){let d=0,c=0;switch(o){case 90:{c=1;break}case 180:{d=-1;break}case 270:{c=-1;break}}i=getRotatedPoint(i,d,c,n)}i=this.getView().getPerimeterPoint(r,i,!1)}else if(h+=o,r.cell.isVertex()){let d=r.style.flipH,c=r.style.flipV;if(l==="north"||l==="south"){const u=d;d=c,c=u}d&&(i.x=2*s.getCenterX()-i.x),c&&(i.y=2*s.getCenterY()-i.y)}if(h!==0&&i){const d=toRadians(h),c=Math.cos(d),u=Math.sin(d);i=getRotatedPoint(i,c,u,n)}}return e&&i&&(i.x=Math.round(i.x),i.y=Math.round(i.y)),i},connectCell(r,t=null,e=!1,i=null){return this.batchUpdate(()=>{const s=r.getTerminal(e);this.cellConnected(r,t,e,i),this.fireEvent(new EventObject(InternalEvent.CONNECT_CELL,"edge",r,"terminal",t,"source",e,"previous",s))}),r},cellConnected(r,t,e=!1,i=null){this.batchUpdate(()=>{const s=r.getTerminal(e);if(this.setConnectionConstraint(r,t,e,i),this.isPortsEnabled()){let n=null;t&&this.isPort(t)&&(n=t.getId(),t=this.getTerminalForPort(t,e));const l=e?"sourcePort":"targetPort";this.setCellStyles(l,n,[r])}this.getDataModel().setTerminal(r,t,e),this.isResetEdgesOnConnect()&&this.resetEdge(r),this.fireEvent(new EventObject(InternalEvent.CELL_CONNECTED,"edge",r,"terminal",t,"source",e,"previous",s))})},disconnectGraph(r){this.batchUpdate(()=>{const{scale:t,translate:e}=this.getView(),i=new Map;for(let s=0;s<r.length;s+=1)i.set(r[s],!0);for(const s of r)if(s.isEdge()){let n=s.getGeometry();if(n){const l=this.getView().getState(s),o=s.getParent(),a=o?this.getView().getState(o):null;if(l&&a){n=n.clone();const h=-a.origin.x,d=-a.origin.y,c=l.absolutePoints;let u=s.getTerminal(!0);if(u&&this.isCellDisconnectable(s,u,!0)){for(;u&&!i.get(u);)u=u.getParent();!u&&c[0]&&(n.setTerminalPoint(new Point(c[0].x/t-e.x+h,c[0].y/t-e.y+d),!0),this.getDataModel().setTerminal(s,null,!0))}let g=s.getTerminal(!1);if(g&&this.isCellDisconnectable(s,g,!1)){for(;g&&!i.get(g);)g=g.getParent();if(!g){const f=c.length-1,p=c[f];p&&(n.setTerminalPoint(new Point(p.x/t-e.x+h,p.y/t-e.y+d),!1),this.getDataModel().setTerminal(s,null,!1))}}this.getDataModel().setGeometry(s,n)}}}})},getConnections(r,t=null){return this.getEdges(r,t,!0,!0,!1)},isConstrainChild(r){return this.isConstrainChildren()&&!!r.getParent()&&!r.getParent().isEdge()},isConstrainChildren(){return this.constrainChildren},setConstrainChildren(r){this.constrainChildren=r},isConstrainRelativeChildren(){return this.constrainRelativeChildren},setConstrainRelativeChildren(r){this.constrainRelativeChildren=r},isDisconnectOnMove(){return this.disconnectOnMove},setDisconnectOnMove(r){this.disconnectOnMove=r},isCellDisconnectable(r,t=null,e=!1){return this.isCellsDisconnectable()&&!this.isCellLocked(r)},isCellsDisconnectable(){return this.cellsDisconnectable},setCellsDisconnectable(r){this.cellsDisconnectable=r},isValidSource(r){return r==null&&this.isAllowDanglingEdges()||r!=null&&(!r.isEdge()||this.isConnectableEdges())&&r.isConnectable()},isValidTarget(r){return this.isValidSource(r)},isValidConnection(r,t){return this.isValidSource(r)&&this.isValidTarget(t)},setConnectable(r){const t=this.getPlugin("ConnectionHandler");t==null||t.setEnabled(r)},isConnectable(){const r=this.getPlugin("ConnectionHandler");return(r==null?void 0:r.isEnabled())??!1}},DragDropMixin={dropEnabled:!1,splitEnabled:!0,autoScroll:!0,isAutoScroll(){return this.autoScroll},autoExtend:!0,isAutoExtend(){return this.autoExtend},isDropEnabled(){return this.dropEnabled},setDropEnabled(r){this.dropEnabled=r},isSplitEnabled(){return this.splitEnabled},setSplitEnabled(r){this.splitEnabled=r},isSplitTarget(r,t=[],e){if(r.isEdge()&&t.length===1&&t[0].isConnectable()&&!this.getEdgeValidationError(r,r.getTerminal(!0),t[0])){const i=r.getTerminal(!0),s=r.getTerminal(!1);return!t[0].isAncestor(i)&&!t[0].isAncestor(s)}return!1}},EdgeMixin={resetEdgesOnResize:!1,isResetEdgesOnResize(){return this.resetEdgesOnResize},resetEdgesOnMove:!1,isResetEdgesOnMove(){return this.resetEdgesOnMove},resetEdgesOnConnect:!0,isResetEdgesOnConnect(){return this.resetEdgesOnConnect},connectableEdges:!1,allowDanglingEdges:!0,cloneInvalidEdges:!1,edgeLabelsMovable:!0,isEdgeLabelsMovable(){return this.edgeLabelsMovable},setEdgeLabelsMovable(r){this.edgeLabelsMovable=r},setAllowDanglingEdges(r){this.allowDanglingEdges=r},isAllowDanglingEdges(){return this.allowDanglingEdges},setConnectableEdges(r){this.connectableEdges=r},isConnectableEdges(){return this.connectableEdges},setCloneInvalidEdges(r){this.cloneInvalidEdges=r},isCloneInvalidEdges(){return this.cloneInvalidEdges},flipEdge(r){return this.alternateEdgeStyle&&this.batchUpdate(()=>{const t=r.getStyle();Object.keys(t).length?this.getDataModel().setStyle(r,this.alternateEdgeStyle):this.getDataModel().setStyle(r,{}),this.resetEdge(r),this.fireEvent(new EventObject(InternalEvent.FLIP_EDGE,{edge:r}))}),r},splitEdge(r,t,e,i=0,s=0,n,l,o=null){o=o??r.getParent();const a=r.getTerminal(!0);return this.batchUpdate(()=>{if(!e){e=this.cloneCell(r);const h=this.getView().getState(r);let d=e.getGeometry();if(d&&h){const c=this.getView().translate,u=this.getView().scale,g=findNearestSegment(h,(i+c.x)*u,(s+c.y)*u);d.points=d.points.slice(0,g),d=r.getGeometry(),d&&(d=d.clone(),d.points=d.points.slice(g),this.getDataModel().setGeometry(r,d))}}this.cellsMoved(t,i,s,!1,!1),this.cellsAdded(t,o,o?o.getChildCount():0,null,null,!0),this.cellsAdded([e],o,o?o.getChildCount():0,a,t[0],!1),this.cellConnected(r,t[0],!0),this.fireEvent(new EventObject(InternalEvent.SPLIT_EDGE,{edge:r,cells:t,newEdge:e,dx:i,dy:s}))}),e},insertEdge(...r){let t,e,i,s,n,l;if(r.length===1&&typeof r[0]=="object"){const a=r[0];t=a.parent,e=a.id,i=a.value,s=a.source,n=a.target,l=a.style}else[t,e,i,s,n,l]=r;const o=this.createEdge(t,e,i,s,n,l);return this.addEdge(o,t,s,n)},createEdge(r=null,t,e,i=null,s=null,n={}){const l=new Cell(e,new Geometry,n);return l.setId(t),l.setEdge(!0),l.geometry.relative=!0,l},addEdge(r,t=null,e=null,i=null,s=null){return this.addCell(r,t,s,e,i)},addAllEdges(r){const t=r.slice();return removeDuplicates(t.concat(this.getAllEdges(r)))},getAllEdges(r){let t=[];if(r)for(let e=0;e<r.length;e+=1){const i=r[e].getEdgeCount();for(let n=0;n<i;n++)t.push(r[e].getEdgeAt(n));const s=r[e].getChildren();t=t.concat(this.getAllEdges(s))}return t},getIncomingEdges(r,t=null){return this.getEdges(r,t,!0,!1,!1)},getOutgoingEdges(r,t=null){return this.getEdges(r,t,!1,!0,!1)},getEdges(r,t=null,e=!0,i=!0,s=!0,n=!1){let l=[];const o=r.isCollapsed(),a=r.getChildCount();for(let d=0;d<a;d+=1){const c=r.getChildAt(d);(o||!c.isVisible())&&(l=l.concat(c.getEdges(e,i)))}l=l.concat(r.getEdges(e,i));const h=[];for(let d=0;d<l.length;d+=1){const c=this.getView().getState(l[d]),u=c?c.getVisibleTerminal(!0):this.getView().getVisibleTerminal(l[d],!0),g=c?c.getVisibleTerminal(!1):this.getView().getVisibleTerminal(l[d],!1);(s&&u===g||u!==g&&(e&&g===r&&(!t||this.isValidAncestor(u,t,n))||i&&u===r&&(!t||this.isValidAncestor(g,t,n))))&&h.push(l[d])}return h},getChildEdges(r){return this.getChildCells(r,!1,!0)},getEdgesBetween(r,t,e=!1){const i=this.getEdges(r),s=[];for(let n=0;n<i.length;n+=1){const l=this.getView().getState(i[n]),o=l?l.getVisibleTerminal(!0):this.getView().getVisibleTerminal(i[n],!0),a=l?l.getVisibleTerminal(!1):this.getView().getVisibleTerminal(i[n],!1);(o===r&&a===t||!e&&o===t&&a===r)&&s.push(i[n])}return s},resetEdges(r){const t=new Map;for(let e=0;e<r.length;e+=1)t.set(r[e],!0);this.batchUpdate(()=>{for(let e=0;e<r.length;e+=1){const i=r[e].getEdges();for(let s=0;s<i.length;s++){const n=this.getView().getState(i[s]),l=n?n.getVisibleTerminal(!0):this.getView().getVisibleTerminal(i[s],!0),o=n?n.getVisibleTerminal(!1):this.getView().getVisibleTerminal(i[s],!1);(!t.get(l)||!t.get(o))&&this.resetEdge(i[s])}this.resetEdges(r[e].getChildren())}})},resetEdge(r){let t=r.getGeometry();return t&&t.points&&t.points.length>0&&(t=t.clone(),t.points=[],this.getDataModel().setGeometry(r,t)),r}},EditingMixin={cellsEditable:!0,startEditing(r){this.startEditingAtCell(null,r)},startEditingAtCell(r=null,t){if(!t||!isMultiTouchEvent(t))if(!r)r=this.getSelectionCell(),r&&!this.isCellEditable(r)&&(r=null);else{this.fireEvent(new EventObject(InternalEvent.START_EDITING,{cell:r,event:t}));const e=this.getPlugin("CellEditorHandler");e==null||e.startEditing(r,t),this.fireEvent(new EventObject(InternalEvent.EDITING_STARTED,{cell:r,event:t}))}},getEditingValue(r,t){return this.convertValueToString(r)},stopEditing(r=!1){const t=this.getPlugin("CellEditorHandler");t==null||t.stopEditing(r),this.fireEvent(new EventObject(InternalEvent.EDITING_STOPPED,{cancel:r}))},labelChanged(r,t,e){return this.batchUpdate(()=>{const i=r.value;this.cellLabelChanged(r,t,this.isAutoSizeCell(r)),this.fireEvent(new EventObject(InternalEvent.LABEL_CHANGED,{cell:r,value:t,old:i,event:e}))}),r},cellLabelChanged(r,t,e=!1){this.batchUpdate(()=>{this.getDataModel().setValue(r,t),e&&this.cellSizeUpdated(r,!1)})},isEditing(r=null){const t=this.getPlugin("CellEditorHandler"),e=t==null?void 0:t.getEditingCell();return r?r===e:!!e},isCellEditable(r){return this.isCellsEditable()&&!this.isCellLocked(r)&&(this.getCurrentCellStyle(r).editable??!0)},isCellsEditable(){return this.cellsEditable},setCellsEditable(r){this.cellsEditable=r}},EventsMixin={lastTouchEvent:null,doubleClickCounter:0,lastTouchCell:null,fireDoubleClick:null,tapAndHoldThread:null,lastMouseX:null,lastMouseY:null,isMouseTrigger:null,ignoreMouseEvents:null,mouseMoveRedirect:null,mouseUpRedirect:null,lastEvent:null,escapeEnabled:!0,invokesStopCellEditing:!0,enterStopsCellEditing:!1,isMouseDown:!1,nativeDblClickEnabled:!0,doubleTapEnabled:!0,doubleTapTimeout:500,doubleTapTolerance:25,lastTouchX:0,lastTouchY:0,lastTouchTime:0,tapAndHoldEnabled:!0,tapAndHoldDelay:500,tapAndHoldInProgress:!1,tapAndHoldValid:!1,initialTouchX:0,initialTouchY:0,tolerance:4,isNativeDblClickEnabled(){return this.nativeDblClickEnabled},getEventTolerance(){return this.tolerance},setEventTolerance(r){this.tolerance=r},escape(r){this.fireEvent(new EventObject(InternalEvent.ESCAPE,{event:r}))},click(r){const t=r.getEvent();let e=r.getCell();const i=new EventObject(InternalEvent.CLICK,{event:t,cell:e});if(r.isConsumed()&&i.consume(),this.fireEvent(i),this.isEnabled()&&!isConsumed(t)&&!i.isConsumed()){if(e){if(this.isTransparentClickEvent(t)){let s=!1;const n=this.getCellAt(r.graphX,r.graphY,null,!1,!1,l=>{const o=this.isCellSelected(l.cell);return s=s||o,!s||o||l.cell!==e&&l.cell.isAncestor(e)});n&&(e=n)}}else if(this.isSwimlaneSelectionEnabled()&&(e=this.getSwimlaneAt(r.getGraphX(),r.getGraphY()),e!=null&&(!this.isToggleEvent(t)||!isAltDown(t)))){let s=e,n=[];for(;s!=null;){s=s.getParent();const l=this.getView().getState(s);this.isSwimlane(s)&&l!=null&&n.push(s)}if(n.length>0){n=n.reverse(),n.splice(0,0,e),n.push(e);for(let l=0;l<n.length-1;l+=1)this.isCellSelected(n[l])&&(e=n[this.isToggleEvent(t)?l:l+1])}}e?this.selectCellForEvent(e,t):this.isToggleEvent(t)||this.clearSelection()}return!1},dblClick(r,t=null){const e=new EventObject(InternalEvent.DOUBLE_CLICK,{event:r,cell:t});this.fireEvent(e),this.isEnabled()&&!isConsumed(r)&&!e.isConsumed()&&t&&this.isCellEditable(t)&&!this.isEditing(t)&&(this.startEditingAtCell(t,r),InternalEvent.consume(r))},tapAndHold(r){const t=r.getEvent(),e=new EventObject(InternalEvent.TAP_AND_HOLD,{event:t,cell:r.getCell()}),i=this.getPlugin("PanningHandler"),s=this.getPlugin("ConnectionHandler");if(this.fireEvent(e),e.isConsumed()&&i&&(i.panningTrigger=!1),this.isEnabled()&&!isConsumed(t)&&!e.isConsumed()&&s&&s.isEnabled()){const n=s.marker.getCell(r);if(n){const l=this.getView().getState(n);l&&(s.marker.currentColor=s.marker.validColor,s.marker.markedState=l,s.marker.mark(),s.first=new Point(r.getGraphX(),r.getGraphY()),s.edgeState=s.createEdgeState(r),s.previous=l,s.fireEvent(new EventObject(InternalEvent.START,{state:s.previous})))}}},addMouseListener(r){this.mouseListeners.push(r)},removeMouseListener(r){for(let t=0;t<this.mouseListeners.length;t+=1)if(this.mouseListeners[t]===r){this.mouseListeners.splice(t,1);break}},updateMouseEvent(r,t){const e=convertPoint(this.getContainer(),r.getX(),r.getY());if(r.graphX=e.x-this.getPanDx(),r.graphY=e.y-this.getPanDy(),!r.getCell()&&this.isMouseDown&&t===InternalEvent.MOUSE_MOVE){const i=this.getCellAt(e.x,e.y,null,!0,!0,s=>!s.shape||s.shape.paintBackground!==this.paintBackground||s.style.pointerEvents||s.shape.fill!==NONE);r.state=i?this.getView().getState(i):null}return r},getStateForTouchEvent(r){const t=getClientX(r),e=getClientY(r),i=convertPoint(this.getContainer(),t,e),s=this.getCellAt(i.x,i.y);return s?this.getView().getState(s):null},isEventIgnored(r,t,e){const i=isMouseEvent(t.getEvent());let s=!1;t.getEvent()===this.lastEvent?s=!0:this.lastEvent=t.getEvent();const n=this.getEventSource();return n&&r!==InternalEvent.MOUSE_MOVE?(InternalEvent.removeGestureListeners(n,null,this.mouseMoveRedirect,this.mouseUpRedirect),this.mouseMoveRedirect=null,this.mouseUpRedirect=null,this.setEventSource(null)):!Client.IS_GC&&n&&t.getSource()!==n?s=!0:n&&Client.IS_TOUCH&&r===InternalEvent.MOUSE_DOWN&&!i&&!isPenEvent(t.getEvent())&&(this.setEventSource(t.getSource()),this.mouseMoveRedirect=l=>{this.fireMouseEvent(InternalEvent.MOUSE_MOVE,new InternalMouseEvent(l,this.getStateForTouchEvent(l)))},this.mouseUpRedirect=l=>{this.fireMouseEvent(InternalEvent.MOUSE_UP,new InternalMouseEvent(l,this.getStateForTouchEvent(l)))},InternalEvent.addGestureListeners(n,null,this.mouseMoveRedirect,this.mouseUpRedirect)),this.isSyntheticEventIgnored(r,t,e)&&(s=!0),!isPopupTrigger(this.lastEvent)&&r!==InternalEvent.MOUSE_MOVE&&this.lastEvent.detail===2?!0:(r===InternalEvent.MOUSE_UP&&this.isMouseDown?this.isMouseDown=!1:r===InternalEvent.MOUSE_DOWN&&!this.isMouseDown?(this.isMouseDown=!0,this.isMouseTrigger=i):!s&&((!Client.IS_FF||r!==InternalEvent.MOUSE_MOVE)&&this.isMouseDown&&this.isMouseTrigger!==i||r===InternalEvent.MOUSE_DOWN&&this.isMouseDown||r===InternalEvent.MOUSE_UP&&!this.isMouseDown)&&(s=!0),!s&&r===InternalEvent.MOUSE_DOWN&&(this.lastMouseX=t.getX(),this.lastMouseY=t.getY()),s)},isSyntheticEventIgnored(r,t,e){let i=!1;const s=isMouseEvent(t.getEvent());return this.ignoreMouseEvents&&s&&r!==InternalEvent.MOUSE_MOVE?(this.ignoreMouseEvents=r!==InternalEvent.MOUSE_UP,i=!0):Client.IS_FF&&!s&&r===InternalEvent.MOUSE_UP&&(this.ignoreMouseEvents=!0),i},isEventSourceIgnored(r,t){const e=t.getSource();if(!e)return!0;const i=e.nodeName?e.nodeName.toLowerCase():"",s=!isMouseEvent(t.getEvent())||isLeftMouseButton(t.getEvent());return r===InternalEvent.MOUSE_DOWN&&s&&(i==="select"||i==="option"||i==="input"&&e.type!=="checkbox"&&e.type!=="radio"&&e.type!=="button"&&e.type!=="submit"&&e.type!=="file")},getEventState(r){return r},fireMouseEvent(r,t,e){if(e=e??this,this.isEventSourceIgnored(r,t)){const i=this.getPlugin("TooltipHandler");i&&i.hide();return}if(t=this.updateMouseEvent(t,r),!this.nativeDblClickEnabled&&!isPopupTrigger(t.getEvent())||this.doubleTapEnabled&&Client.IS_TOUCH&&(isTouchEvent(t.getEvent())||isPenEvent(t.getEvent()))){const i=new Date().getTime();if(r===InternalEvent.MOUSE_DOWN)if(this.lastTouchEvent&&this.lastTouchEvent!==t.getEvent()&&i-this.lastTouchTime<this.doubleTapTimeout&&Math.abs(this.lastTouchX-t.getX())<this.doubleTapTolerance&&Math.abs(this.lastTouchY-t.getY())<this.doubleTapTolerance&&this.doubleClickCounter<2){this.doubleClickCounter+=1;let s=!1;if(r===InternalEvent.MOUSE_UP){if(t.getCell()===this.lastTouchCell&&this.lastTouchCell){this.lastTouchTime=0;const n=this.lastTouchCell;this.lastTouchCell=null,this.dblClick(t.getEvent(),n),s=!0}}else this.fireDoubleClick=!0,this.lastTouchTime=0;if(s){InternalEvent.consume(t.getEvent());return}}else(!this.lastTouchEvent||this.lastTouchEvent!==t.getEvent())&&(this.lastTouchCell=t.getCell(),this.lastTouchX=t.getX(),this.lastTouchY=t.getY(),this.lastTouchTime=i,this.lastTouchEvent=t.getEvent(),this.doubleClickCounter=0);else if((this.isMouseDown||r===InternalEvent.MOUSE_UP)&&this.fireDoubleClick){this.fireDoubleClick=!1;const s=this.lastTouchCell;this.lastTouchCell=null,this.isMouseDown=!1,(s||(isTouchEvent(t.getEvent())||isPenEvent(t.getEvent()))&&(Client.IS_GC||Client.IS_SF))&&Math.abs(this.lastTouchX-t.getX())<this.doubleTapTolerance&&Math.abs(this.lastTouchY-t.getY())<this.doubleTapTolerance?this.dblClick(t.getEvent(),s):InternalEvent.consume(t.getEvent());return}}if(!this.isEventIgnored(r,t,e)){const i=t.getState();if(t.state=i?this.getEventState(i):null,this.fireEvent(new EventObject(InternalEvent.FIRE_MOUSE_EVENT,{eventName:r,event:t})),Client.IS_SF||Client.IS_GC||t.getEvent().target!==this.getContainer()){const n=this.getContainer();if(r===InternalEvent.MOUSE_MOVE&&this.isMouseDown&&this.isAutoScroll()&&!isMultiTouchEvent(t.getEvent()))this.scrollPointToVisible(t.getGraphX(),t.getGraphY(),this.isAutoExtend());else if(r===InternalEvent.MOUSE_UP&&this.isIgnoreScrollbars()&&this.isTranslateToScrollPosition()&&(n.scrollLeft!==0||n.scrollTop!==0)){const o=this.getView().scale,a=this.getView().translate;this.getView().setTranslate(a.x-n.scrollLeft/o,a.y-n.scrollTop/o),n.scrollLeft=0,n.scrollTop=0}const l=this.mouseListeners;t.getEvent().preventDefault||(t.getEvent().returnValue=!0);for(const o of l)switch(r){case InternalEvent.MOUSE_DOWN:{o.mouseDown(e,t);break}case InternalEvent.MOUSE_MOVE:{o.mouseMove(e,t);break}case InternalEvent.MOUSE_UP:{o.mouseUp(e,t);break}}r===InternalEvent.MOUSE_UP&&this.click(t)}if((isTouchEvent(t.getEvent())||isPenEvent(t.getEvent()))&&r===InternalEvent.MOUSE_DOWN&&this.tapAndHoldEnabled&&!this.tapAndHoldInProgress){this.tapAndHoldInProgress=!0,this.initialTouchX=t.getGraphX(),this.initialTouchY=t.getGraphY();const n=()=>{this.tapAndHoldValid&&this.tapAndHold(t),this.tapAndHoldInProgress=!1,this.tapAndHoldValid=!1};this.tapAndHoldThread&&window.clearTimeout(this.tapAndHoldThread),this.tapAndHoldThread=window.setTimeout(n,this.tapAndHoldDelay),this.tapAndHoldValid=!0}else r===InternalEvent.MOUSE_UP?(this.tapAndHoldInProgress=!1,this.tapAndHoldValid=!1):this.tapAndHoldValid&&(this.tapAndHoldValid=Math.abs(this.initialTouchX-t.getGraphX())<this.tolerance&&Math.abs(this.initialTouchY-t.getGraphY())<this.tolerance);const s=this.getPlugin("CellEditorHandler");r===InternalEvent.MOUSE_DOWN&&this.isEditing()&&!(s!=null&&s.isEventSource(t.getEvent()))&&this.stopEditing(!this.isInvokesStopCellEditing()),this.consumeMouseEvent(r,t,e)}},consumeMouseEvent(r,t,e){r===InternalEvent.MOUSE_DOWN&&isTouchEvent(t.getEvent())&&t.consume(!1)},fireGestureEvent(r,t=null){this.lastTouchTime=0,this.fireEvent(new EventObject(InternalEvent.GESTURE,{event:r,cell:t}))},sizeDidChange(){const r=this.getGraphBounds(),t=this.getBorder();let e=Math.max(0,r.x)+r.width+2*t,i=Math.max(0,r.y)+r.height+2*t;const s=this.getMinimumContainerSize();if(s&&(e=Math.max(e,s.width),i=Math.max(i,s.height)),this.isResizeContainer()&&this.doResizeContainer(e,i),this.isPreferPageSize()||this.isPageVisible()){const o=this.getPreferredPageSize(r,Math.max(1,e),Math.max(1,i));e=o.width*this.getView().scale,i=o.height*this.getView().scale}const n=this.getMinimumGraphSize();n&&(e=Math.max(e,n.width*this.getView().scale),i=Math.max(i,n.height*this.getView().scale)),e=Math.ceil(e),i=Math.ceil(i);const l=this.getView().getDrawPane().ownerSVGElement;l&&(l.style.minWidth=`${Math.max(1,e)}px`,l.style.minHeight=`${Math.max(1,i)}px`,l.style.width="100%",l.style.height="100%"),this.updatePageBreaks(this.isPageBreaksVisible(),e,i),this.fireEvent(new EventObject(InternalEvent.SIZE,{bounds:r}))},isCloneEvent(r){return isControlDown(r)},isTransparentClickEvent(r){return!1},isToggleEvent(r){return Client.IS_MAC?isMetaDown(r):isControlDown(r)},isGridEnabledEvent(r){return!isAltDown(r)},isConstrainedEvent(r){return isShiftDown(r)},isIgnoreTerminalEvent(r){return!1},getPointForEvent(r,t=!0){const e=convertPoint(this.getContainer(),getClientX(r),getClientY(r)),i=this.getView().scale,s=this.getView().translate,n=t?this.getGridSize()/2:0;return e.x=this.snap(e.x/i-s.x-n),e.y=this.snap(e.y/i-s.y-n),e},isEscapeEnabled(){return this.escapeEnabled},setEscapeEnabled(r){this.escapeEnabled=r},isInvokesStopCellEditing(){return this.invokesStopCellEditing},setInvokesStopCellEditing(r){this.invokesStopCellEditing=r},isEnterStopsCellEditing(){return this.enterStopsCellEditing},setEnterStopsCellEditing(r){this.enterStopsCellEditing=r},getCursorForMouseEvent(r){const t=r.getCell();return t?this.getCursorForCell(t):null}},FoldingMixin={collapseExpandResource:isI18nEnabled()?"collapse-expand":"",getCollapseExpandResource(){return this.collapseExpandResource},isFoldingEnabled(){return this.options.foldingEnabled},getFoldableCells(r,t=!1){return this.getDataModel().filterCells(r,e=>this.isCellFoldable(e,t))},isCellFoldable(r,t){return r.getChildCount()>0&&(this.getCurrentCellStyle(r).foldable??!0)},getFoldingImage(r){if(r!=null&&this.isFoldingEnabled()&&!r.cell.isEdge()){const t=r.cell.isCollapsed();if(this.isCellFoldable(r.cell,!t))return t?this.options.collapsedImage:this.options.expandedImage}return null},foldCells(r=!1,t=!1,e=null,i=!1,s=null){return e==null&&(e=this.getFoldableCells(this.getSelectionCells(),r)),this.stopEditing(!1),this.batchUpdate(()=>{this.cellsFolded(e,r,t,i),this.fireEvent(new EventObject(InternalEvent.FOLD_CELLS,"collapse",r,"recurse",t,"cells",e))}),e},cellsFolded(r=null,t=!1,e=!1,i=!1){r!=null&&r.length>0&&this.batchUpdate(()=>{for(let s=0;s<r.length;s+=1)if((!i||this.isCellFoldable(r[s],t))&&t!==r[s].isCollapsed()){if(this.getDataModel().setCollapsed(r[s],t),this.swapBounds(r[s],t),this.isExtendParent(r[s])&&this.extendParent(r[s]),e){const n=r[s].getChildren();this.cellsFolded(n,t,e)}this.constrainChild(r[s])}this.fireEvent(new EventObject(InternalEvent.CELLS_FOLDED,{cells:r,collapse:t,recurse:e}))})},swapBounds(r,t=!1){let e=r.getGeometry();e!=null&&(e=e.clone(),this.updateAlternateBounds(r,e,t),e.swap(),this.getDataModel().setGeometry(r,e))},updateAlternateBounds(r=null,t=null,e=!1){if(r!=null&&t!=null){const i=this.getCurrentCellStyle(r);if(t.alternateBounds==null){let s=t;if(this.options.collapseToPreferredSize){const n=this.getPreferredSizeForCell(r);if(n!=null){s=n;const l=i.startSize??0;l>0&&(s.height=Math.max(s.height,l))}}t.alternateBounds=new Rectangle(0,0,s.width,s.height)}if(t.alternateBounds!=null){t.alternateBounds.x=t.x,t.alternateBounds.y=t.y;const s=toRadians(i.rotation||0);if(s!==0){const n=t.alternateBounds.getCenterX()-t.getCenterX(),l=t.alternateBounds.getCenterY()-t.getCenterY(),o=Math.cos(s),a=Math.sin(s),h=o*n-a*l,d=a*n+o*l;t.alternateBounds.x+=h-n,t.alternateBounds.y+=d-l}}}}},GroupingMixin={groupCells(r,t=0,e){e||(e=sortCells(this.getSelectionCells(),!0)),e||(e=this.getCellsForGroup(e)),r==null&&(r=this.createGroupCell(e));const i=this.getBoundsForGroup(r,e,t);if(e.length>1&&i!=null){let s=r.getParent();s==null&&(s=e[0].getParent()),this.batchUpdate(()=>{r.getGeometry()==null&&this.getDataModel().setGeometry(r,new Geometry);let n=s.getChildCount();this.cellsAdded([r],s,n,null,null,!1,!1,!1),n=r.getChildCount(),this.cellsAdded(e,r,n,null,null,!1,!1,!1),this.cellsMoved(e,-i.x,-i.y,!1,!1,!1),this.cellsResized([r],[i],!1),this.fireEvent(new EventObject(InternalEvent.GROUP_CELLS,{group:r,border:t,cells:e}))})}return r},getCellsForGroup(r){const t=[];if(r!=null&&r.length>0){const e=r[0].getParent();t.push(r[0]);for(let i=1;i<r.length;i+=1)r[i].getParent()===e&&t.push(r[i])}return t},getBoundsForGroup(r,t,e){const i=this.getBoundingBoxFromGeometry(t,!0);if(i!=null){if(this.isSwimlane(r)){const s=this.getStartSize(r);i.x-=s.width,i.y-=s.height,i.width+=s.width,i.height+=s.height}e!=null&&(i.x-=e,i.y-=e,i.width+=2*e,i.height+=2*e)}return i},createGroupCell(r){const t=new Cell("");return t.setVertex(!0),t.setConnectable(!1),t},ungroupCells(r){let t=[];return r==null&&(r=this.getCellsForUngroup()),r!=null&&r.length>0&&this.batchUpdate(()=>{const e=r;for(let i=0;i<e.length;i+=1){let s=e[i].getChildren();if(s!=null&&s.length>0){s=s.slice();const n=e[i].getParent(),l=n.getChildCount();this.cellsAdded(s,n,l,null,null,!0),t=t.concat(s);for(const o of s){const a=this.getView().getState(o);let h=o.getGeometry();a!=null&&h!=null&&h.relative&&(h=h.clone(),h.x=a.origin.x,h.y=a.origin.y,h.relative=!1,this.getDataModel().setGeometry(o,h))}}}this.removeCellsAfterUngroup(e),this.fireEvent(new EventObject(InternalEvent.UNGROUP_CELLS,{cells:r}))}),t},getCellsForUngroup(){const r=this.getSelectionCells(),t=[];for(let e=0;e<r.length;e+=1)r[e].isVertex()&&r[e].getChildCount()>0&&t.push(r[e]);return t},removeCellsAfterUngroup(r){this.cellsRemoved(this.addAllEdges(r))},removeCellsFromParent(r){return r==null&&(r=this.getSelectionCells()),this.batchUpdate(()=>{const t=this.getDefaultParent(),e=t.getChildCount();this.cellsAdded(r,t,e,null,null,!0),this.fireEvent(new EventObject(InternalEvent.REMOVE_CELLS_FROM_PARENT,{cells:r}))}),r},updateGroupBounds(r,t=0,e=!1,i=0,s=0,n=0,l=0){return r==null&&(r=this.getSelectionCells()),t=t??0,e=e??!1,i=i??0,s=s??0,n=n??0,l=l??0,this.batchUpdate(()=>{for(let o=r.length-1;o>=0;o--){let a=r[o].getGeometry();if(a==null)continue;const h=this.getChildCells(r[o]);if(h!=null&&h.length>0){const d=this.getBoundingBoxFromGeometry(h,!0);if(d!=null&&d.width>0&&d.height>0){const c=this.isSwimlane(r[o])?this.getActualStartSize(r[o],!0):new Rectangle;a=a.clone(),e&&(a.x=Math.round(a.x+d.x-t-c.x-l),a.y=Math.round(a.y+d.y-t-c.y-i)),a.width=Math.round(d.width+2*t+c.x+l+s+c.width),a.height=Math.round(d.height+2*t+c.y+i+n+c.height),this.getDataModel().setGeometry(r[o],a),this.moveCells(h,t+c.x-d.x+l,t+c.y-d.y+i)}}}}),r},enterGroup(r){r=r||this.getSelectionCell(),r!=null&&this.isValidRoot(r)&&(this.getView().setCurrentRoot(r),this.clearSelection())},exitGroup(){const r=this.getDataModel().getRoot(),t=this.getCurrentRoot();if(t!=null){let e=t.getParent();for(;e!==r&&!this.isValidRoot(e)&&e.getParent()!==r;)e=e.getParent();e===r||e.getParent()===r?this.getView().setCurrentRoot(null):this.getView().setCurrentRoot(e),this.getView().getState(t)!=null&&this.setSelectionCell(t)}}},LabelMixin={getLabel(r){let t="";return this.isLabelsVisible()&&r&&((this.getCurrentCellStyle(r).noLabel??!1)||(t=this.convertValueToString(r))),t},isHtmlLabel(r){return this.isHtmlLabels()},labelsVisible:!0,isLabelsVisible(){return this.labelsVisible},htmlLabels:!1,isHtmlLabels(){return this.htmlLabels},setHtmlLabels(r){this.htmlLabels=r},isWrapping(r){return this.getCurrentCellStyle(r).whiteSpace==="wrap"},isLabelClipped(r){return this.getCurrentCellStyle(r).overflow==="hidden"},isLabelMovable(r){return!this.isCellLocked(r)&&(r.isEdge()&&this.isEdgeLabelsMovable()||r.isVertex()&&this.isVertexLabelsMovable())}},OrderMixin={orderCells(r=!1,t){return t||(t=this.getSelectionCells()),t||(t=sortCells(this.getSelectionCells(),!0)),this.batchUpdate(()=>{this.cellsOrdered(t,r);const e=new EventObject(InternalEvent.ORDER_CELLS,"back",r,"cells",t);this.fireEvent(e)}),t},cellsOrdered(r,t=!1){this.batchUpdate(()=>{for(let e=0;e<r.length;e+=1){const i=r[e].getParent();t?this.getDataModel().add(i,r[e],e):this.getDataModel().add(i,r[e],i?i.getChildCount()-1:0)}this.fireEvent(new EventObject(InternalEvent.CELLS_ORDERED,{back:t,cells:r}))})}};class CellOverlay extends EventSource{constructor(t,e=null,i="right",s="bottom",n=new Point,l="help"){super(),this.align="right",this.verticalAlign="bottom",this.offset=new Point,this.cursor="help",this.defaultOverlap=.5,this.image=t,this.tooltip=e,this.align=i,this.verticalAlign=s,this.offset=n,this.cursor=l}getBounds(t){const e=t.cell.isEdge(),i=t.view.scale;let s=null;const n=this.image,l=n.width,o=n.height;if(e){const a=t.absolutePoints;if(a.length%2===1)s=a[Math.floor(a.length/2)];else{const h=a.length/2,d=a[h-1],c=a[h];s=new Point(d.x+(c.x-d.x)/2,d.y+(c.y-d.y)/2)}}else{switch(s=new Point,this.align){case"left":{s.x=t.x;break}case"center":{s.x=t.x+t.width/2;break}case"right":{s.x=t.x+t.width;break}default:throw new Error}switch(this.verticalAlign){case"top":{s.y=t.y;break}case"middle":{s.y=t.y+t.height/2;break}case"bottom":{s.y=t.y+t.height;break}default:throw new Error}}return new Rectangle(Math.round(s.x-(l*this.defaultOverlap-this.offset.x)*i),Math.round(s.y-(o*this.defaultOverlap-this.offset.y)*i),l*i,o*i)}toString(){return this.tooltip}}const OverlaysMixin={addCellOverlay(r,t){r.overlays.push(t);const e=this.getView().getState(r);return e&&this.getCellRenderer().redraw(e),this.fireEvent(new EventObject(InternalEvent.ADD_OVERLAY,{cell:r,overlay:t})),t},getCellOverlays(r){return r.overlays},removeCellOverlay(r,t=null){if(!t)this.removeCellOverlays(r);else{const e=r.overlays.indexOf(t);if(e>=0){r.overlays.splice(e,1);const i=this.getView().getState(r);i&&this.getCellRenderer().redraw(i),this.fireEvent(new EventObject(InternalEvent.REMOVE_OVERLAY,{cell:r,overlay:t}))}else t=null}return t},removeCellOverlays(r){const{overlays:t}=r;r.overlays=[];const e=this.getView().getState(r);e&&this.getCellRenderer().redraw(e);for(let i=0;i<t.length;i+=1)this.fireEvent(new EventObject(InternalEvent.REMOVE_OVERLAY,"cell",r,"overlay",t[i]));return t},clearCellOverlays(r=null){if(r=r??this.getDataModel().getRoot(),!r)return;this.removeCellOverlays(r);const t=r.getChildCount();for(let e=0;e<t;e+=1){const i=r.getChildAt(e);this.clearCellOverlays(i)}},setCellWarning(r,t=null,e,i=!1){if(e=e??this.getWarningImage(),t&&t.length>0){const s=new CellOverlay(e,`<font color=red>${t}</font>`);return i&&s.addListener(InternalEvent.CLICK,(n,l)=>{this.isEnabled()&&this.setSelectionCell(r)}),this.addCellOverlay(r,s)}return this.removeCellOverlays(r),null}};class PolylineShape extends Shape{constructor(t,e,i=1){super(),this.points=t,this.stroke=e,this.strokeWidth=i}getRotation(){return 0}getShapeRotation(){return 0}isPaintBoundsInverted(){return!1}paintEdgeShape(t,e){var s;const i=t.pointerEventsValue;t.pointerEventsValue="stroke",(s=this.style)!=null&&s.curved?this.paintCurvedLine(t,e):this.paintLine(t,e,this.isRounded),t.pointerEventsValue=i}paintLine(t,e,i){t.begin(),this.addPoints(t,e,i,this.getBaseArcSize(),!1),t.stroke()}paintCurvedLine(t,e){t.begin();const i=e[0],s=e.length;t.moveTo(i.x,i.y);for(let o=1;o<s-2;o+=1){const a=e[o],h=e[o+1],d=(a.x+h.x)/2,c=(a.y+h.y)/2;t.quadTo(a.x,a.y,d,c)}const n=e[s-2],l=e[s-1];t.quadTo(n.x,n.y,l.x,l.y),t.stroke()}}const PageBreaksMixin={horizontalPageBreaks:null,verticalPageBreaks:null,updatePageBreaks(r,t,e){const{scale:i,translate:s}=this.getView(),n=this.getPageFormat(),l=i*this.getPageScale(),o=new Rectangle(0,0,n.width*l,n.height*l),a=Rectangle.fromRectangle(this.getGraphBounds());a.width=Math.max(1,a.width),a.height=Math.max(1,a.height),o.x=Math.floor((a.x-s.x*i)/o.width)*o.width+s.x*i,o.y=Math.floor((a.y-s.y*i)/o.height)*o.height+s.y*i,a.width=Math.ceil((a.width+(a.x-o.x))/o.width)*o.width,a.height=Math.ceil((a.height+(a.y-o.y))/o.height)*o.height,r=r&&Math.min(o.width,o.height)>this.getMinPageBreakDist();const h=r?Math.ceil(a.height/o.height)+1:0,d=r?Math.ceil(a.width/o.width)+1:0,c=(d-1)*o.width,u=(h-1)*o.height;this.horizontalPageBreaks==null&&h>0&&(this.horizontalPageBreaks=[]),this.verticalPageBreaks==null&&d>0&&(this.verticalPageBreaks=[]);const g=f=>{if(!f)return;const p=f===this.horizontalPageBreaks?h:d;for(let y=0;y<=p;y+=1){const v=f===this.horizontalPageBreaks?[new Point(Math.round(o.x),Math.round(o.y+y*o.height)),new Point(Math.round(o.x+c),Math.round(o.y+y*o.height))]:[new Point(Math.round(o.x+y*o.width),Math.round(o.y)),new Point(Math.round(o.x+y*o.width),Math.round(o.y+u))];if(f[y]!=null)f[y].points=v,f[y].redraw();else{const S=new PolylineShape(v,this.getPageBreakColor());S.dialect=this.getDialect(),S.pointerEvents=!1,S.isDashed=this.isPageBreakDashed(),S.init(this.getView().backgroundPane),S.redraw(),f[y]=S}}for(let y=p;y<f.length;y+=1)f[y].destroy();f.splice(p,f.length-p)};g(this.horizontalPageBreaks),g(this.verticalPageBreaks)}},PanningMixin={shiftPreview1:null,shiftPreview2:null,useScrollbarsForPanning:!0,isUseScrollbarsForPanning(){return this.useScrollbarsForPanning},timerAutoScroll:!1,isTimerAutoScroll(){return this.timerAutoScroll},allowAutoPanning:!1,isAllowAutoPanning(){return this.allowAutoPanning},panDx:0,getPanDx(){return this.panDx},setPanDx(r){this.panDx=r},panDy:0,getPanDy(){return this.panDy},setPanDy(r){this.panDy=r},panGraph(r,t){const e=this.getContainer();if(this.useScrollbarsForPanning&&hasScrollbars(e))e.scrollLeft=-r,e.scrollTop=-t;else{const i=this.getView().getCanvas();if(r===0&&t===0){if(i.removeAttribute("transform"),this.shiftPreview1){let s=this.shiftPreview1.firstChild;for(;s;){const l=s.nextSibling;e.appendChild(s),s=l}this.shiftPreview1.parentNode&&this.shiftPreview1.parentNode.removeChild(this.shiftPreview1),this.shiftPreview1=null,e.appendChild(i.parentNode);const n=this.shiftPreview2;for(s=n.firstChild;s;){const l=s.nextSibling;e.appendChild(s),s=l}n.parentNode&&n.parentNode.removeChild(n),this.shiftPreview2=null}}else{if(i.setAttribute("transform",`translate(${r},${t})`),!this.shiftPreview1){this.shiftPreview1=document.createElement("div"),this.shiftPreview1.style.position="absolute",this.shiftPreview1.style.overflow="visible",this.shiftPreview2=document.createElement("div"),this.shiftPreview2.style.position="absolute",this.shiftPreview2.style.overflow="visible";let s=this.shiftPreview1,n=e.firstChild;for(;n;){const l=n.nextSibling;n!==i.parentNode?s.appendChild(n):s=this.shiftPreview2,n=l}this.shiftPreview1.firstChild&&e.insertBefore(this.shiftPreview1,i.parentNode),this.shiftPreview2.firstChild&&e.appendChild(this.shiftPreview2)}this.shiftPreview1.style.left=`${r}px`,this.shiftPreview1.style.top=`${t}px`,this.shiftPreview2&&(this.shiftPreview2.style.left=`${r}px`,this.shiftPreview2.style.top=`${t}px`)}this.panDx=r,this.panDy=t,this.fireEvent(new EventObject(InternalEvent.PAN))}},scrollCellToVisible(r,t=!1){const e=-this.getView().translate.x,i=-this.getView().translate.y,s=this.getView().getState(r);if(s){const n=new Rectangle(e+s.x,i+s.y,s.width,s.height);if(t&&this.getContainer()){const o=this.getContainer().clientWidth,a=this.getContainer().clientHeight;n.x=n.getCenterX()-o/2,n.width=o,n.y=n.getCenterY()-a/2,n.height=a}const l=new Point(this.getView().translate.x,this.getView().translate.y);if(this.scrollRectToVisible(n)){const o=new Point(this.getView().translate.x,this.getView().translate.y);this.getView().translate.x=l.x,this.getView().translate.y=l.y,this.getView().setTranslate(o.x,o.y)}}},scrollRectToVisible(r){let t=!1;const e=this.getContainer(),i=e.offsetWidth,s=e.offsetHeight,n=Math.min(i,r.width),l=Math.min(s,r.height);if(hasScrollbars(e)){r.x+=this.getView().translate.x,r.y+=this.getView().translate.y;let o=e.scrollLeft-r.x;const a=Math.max(o-e.scrollLeft,0);o>0?e.scrollLeft-=o+2:(o=r.x+n-e.scrollLeft-e.clientWidth,o>0&&(e.scrollLeft+=o+2));let h=e.scrollTop-r.y;const d=Math.max(0,h-e.scrollTop);h>0?e.scrollTop-=h+2:(h=r.y+l-e.scrollTop-e.clientHeight,h>0&&(e.scrollTop+=h+2)),!this.useScrollbarsForPanning&&(a!=0||d!=0)&&this.getView().setTranslate(a,d)}else{const o=-this.getView().translate.x,a=-this.getView().translate.y,h=this.getView().scale;if(r.x+n>o+i&&(this.getView().translate.x-=(r.x+n-i-o)/h,t=!0),r.y+l>a+s&&(this.getView().translate.y-=(r.y+l-s-a)/h,t=!0),r.x<o&&(this.getView().translate.x+=(o-r.x)/h,t=!0),r.y<a&&(this.getView().translate.y+=(a-r.y)/h,t=!0),t){this.getView().refresh();const d=this.getPlugin("SelectionCellsHandler");d&&d.refresh()}}return t},setPanning(r){const t=this.getPlugin("PanningHandler");t&&(t.panningEnabled=r)}},PortsMixin={portsEnabled:!0,isPort(r){return!1},getTerminalForPort(r,t=!1){return r.getParent()},isPortsEnabled(){return this.portsEnabled},setPortsEnabled(r){this.portsEnabled=r}},SelectionMixin={selectionModel:null,getSelectionModel(){return this.selectionModel},setSelectionModel(r){this.selectionModel=r},isCellSelected(r){return this.selectionModel.isSelected(r)},isSelectionEmpty(){return this.selectionModel.isEmpty()},clearSelection(){this.selectionModel.clear()},getSelectionCount(){return this.selectionModel.cells.length},getSelectionCell(){return this.selectionModel.cells[0]},getSelectionCells(){return this.selectionModel.cells.slice()},setSelectionCell(r){this.selectionModel.setCell(r)},setSelectionCells(r){this.selectionModel.setCells(r)},addSelectionCell(r){this.selectionModel.addCell(r)},addSelectionCells(r){this.selectionModel.addCells(r)},removeSelectionCell(r){this.selectionModel.removeCell(r)},removeSelectionCells(r){this.selectionModel.removeCells(r)},selectRegion(r,t){const e=this.getCells(r.x,r.y,r.width,r.height);return this.selectCellsForEvent(e,t),e},selectNextCell(){this.selectCell(!0)},selectPreviousCell(){this.selectCell()},selectParentCell(){this.selectCell(!1,!0)},selectChildCell(){this.selectCell(!1,!1,!0)},selectCell(r=!1,t=!1,e=!1){const i=this.selectionModel.cells.length>0?this.selectionModel.cells[0]:null;this.selectionModel.cells.length>1&&this.selectionModel.clear();const s=i?i.getParent():this.getDefaultParent(),n=s.getChildCount();if(!i&&n>0){const l=s.getChildAt(0);this.setSelectionCell(l)}else if(s&&(!i||t)&&this.getView().getState(s)&&s.getGeometry())this.getCurrentRoot()!==s&&this.setSelectionCell(s);else if(i&&e){if(i.getChildCount()>0){const o=i.getChildAt(0);this.setSelectionCell(o)}}else if(n>0){let l=s.getIndex(i);if(r){l++;const o=s.getChildAt(l%n);this.setSelectionCell(o)}else{l--;const o=l<0?n-1:l,a=s.getChildAt(o);this.setSelectionCell(a)}}},selectAll(r,t=!1){r=r??this.getDefaultParent();const e=t?r.filterDescendants(i=>i!==r&&!!this.getView().getState(i)):r.getChildren();this.setSelectionCells(e)},selectVertices(r,t=!1){this.selectCells(!0,!1,r,t)},selectEdges(r){this.selectCells(!1,!0,r)},selectCells(r=!1,t=!1,e,i=!1){e=e??this.getDefaultParent();const s=l=>{const o=l.getParent();return!!this.getView().getState(l)&&((i||l.getChildCount()===0)&&l.isVertex()&&r&&o&&!o.isEdge()||l.isEdge()&&t)},n=e.filterDescendants(s);this.setSelectionCells(n)},selectCellForEvent(r,t){const e=this.isCellSelected(r);this.isToggleEvent(t)?e?this.removeSelectionCell(r):this.addSelectionCell(r):(!e||this.getSelectionCount()!==1)&&this.setSelectionCell(r)},selectCellsForEvent(r,t){this.isToggleEvent(t)?this.addSelectionCells(r):this.setSelectionCells(r)},isSiblingSelected(r){const t=r.getParent(),e=t.getChildCount();for(let i=0;i<e;i+=1){const s=t.getChildAt(i);if(r!==s&&this.isCellSelected(s))return!0}return!1},getSelectionCellsForChanges(r,t=null){const e=new Map,i=[],s=n=>{if(!e.has(n)&&this.getDataModel().contains(n))if(n.isEdge()||n.isVertex())e.set(n,!0),i.push(n);else{const l=n.getChildCount();for(let o=0;o<l;o+=1)s(n.getChildAt(o))}};for(let n=0;n<r.length;n+=1){const l=r[n];if(l.constructor!==RootChange&&(!t||!t(l))){let o=null;l instanceof ChildChange?o=l.child:l.cell&&l.cell instanceof Cell&&(o=l.cell),o&&s(o)}}return i},updateSelection(){const r=this.getSelectionCells(),t=[];for(const e of r)if(!this.getDataModel().contains(e)||!e.isVisible())t.push(e);else{let i=e.getParent();for(;i&&i!==this.getView().currentRoot;){if(i.isCollapsed()||!i.isVisible()){t.push(e);break}i=i.getParent()}}this.removeSelectionCells(t)}},SnapMixin={snapTolerance:0,getSnapTolerance(){return this.snapTolerance},gridSize:10,gridEnabled:!0,snap(r){return this.gridEnabled&&(r=Math.round(r/this.gridSize)*this.gridSize),r},snapDelta(r,t,e=!1,i=!1,s=!1){const n=this.getView().translate,l=this.getView().scale;if(!e&&this.gridEnabled){const o=this.gridSize*l*.5;if(!i){const a=t.x-(this.snap(t.x/l-n.x)+n.x)*l;Math.abs(r.x-a)<o?r.x=0:r.x=this.snap(r.x/l)*l-a}if(!s){const a=t.y-(this.snap(t.y/l-n.y)+n.y)*l;Math.abs(r.y-a)<o?r.y=0:r.y=this.snap(r.y/l)*l-a}}else{const o=.5*l;if(!i){const a=t.x-(Math.round(t.x/l-n.x)+n.x)*l;Math.abs(r.x-a)<o?r.x=0:r.x=Math.round(r.x/l)*l-a}if(!s){const a=t.y-(Math.round(t.y/l-n.y)+n.y)*l;Math.abs(r.y-a)<o?r.y=0:r.y=Math.round(r.y/l)*l-a}}return r},isGridEnabled(){return this.gridEnabled},setGridEnabled(r){this.gridEnabled=r},getGridSize(){return this.gridSize},setGridSize(r){this.gridSize=r}},SwimlaneMixin={swimlaneSelectionEnabled:!0,swimlaneNesting:!0,swimlaneIndicatorColorAttribute:"fillColor",getSwimlane(r=null){for(;r&&!this.isSwimlane(r);)r=r.getParent();return r},getSwimlaneAt(r,t,e){if(e||(e=this.getCurrentRoot(),e||(e=this.getDataModel().getRoot())),e){const i=e.getChildCount();for(let s=0;s<i;s+=1){const n=e.getChildAt(s);if(n){const l=this.getSwimlaneAt(r,t,n);if(l!=null)return l;if(n.isVisible()&&this.isSwimlane(n)){const o=this.getView().getState(n);if(o&&this.intersects(o,r,t))return n}}}}return null},hitsSwimlaneContent(r,t,e){const i=this.getView().getState(r),s=this.getStartSize(r);if(i){const n=this.getView().getScale();if(t-=i.x,e-=i.y,s.width>0&&t>0&&t>s.width*n||s.height>0&&e>0&&e>s.height*n)return!0}return!1},getStartSize(r,t=!1){const e=new Rectangle,i=this.getCurrentCellStyle(r,t),s=i.startSize??StyleDefaultsConfig.startSize;return i.horizontal??!0?e.height=s:e.width=s,e},getSwimlaneDirection(r){const t=r.direction??"east",e=r.flipH,i=r.flipV;let n=r.horizontal??!0?0:3;switch(t){case"north":{n--;break}case"west":{n+=2;break}case"south":{n+=1;break}}const l=mod(n,2);return e&&l===1&&(n+=2),i&&l===0&&(n+=2),["north","east","south","west"][mod(n,4)]},getActualStartSize(r,t=!1){const e=new Rectangle;if(this.isSwimlane(r,t)){const i=this.getCurrentCellStyle(r,t),s=i.startSize??StyleDefaultsConfig.startSize;switch(this.getSwimlaneDirection(i)){case"north":{e.y=s;break}case"west":{e.x=s;break}case"south":{e.height=s;break}default:e.width=s}}return e},isSwimlane(r,t=!1){return r&&r.getParent()!==this.getDataModel().getRoot()&&!r.isEdge()?this.getCurrentCellStyle(r,t).shape==="swimlane":!1},isValidDropTarget(r,t,e){return r&&(this.isSplitEnabled()&&this.isSplitTarget(r,t,e)||!r.isEdge()&&(this.isSwimlane(r)||r.getChildCount()>0&&!r.isCollapsed()))},getDropTarget(r,t,e=null,i=!1){if(!this.isSwimlaneNesting()){for(let o=0;o<r.length;o+=1)if(this.isSwimlane(r[o]))return null}const s=convertPoint(this.getContainer(),getClientX(t),getClientY(t));s.x-=this.getPanDx(),s.y-=this.getPanDy();const n=this.getSwimlaneAt(s.x,s.y);if(!e)e=n;else if(n){let o=n.getParent();for(;o&&this.isSwimlane(o)&&o!==e;)o=o.getParent();o===e&&(e=n)}for(;e&&!this.isValidDropTarget(e,r,t)&&!this.getDataModel().isLayer(e);)e=e.getParent();let l=e;if(!i)for(;l&&!r.includes(l);)l=l.getParent();return!this.getDataModel().isLayer(e)&&!l?e:null},isSwimlaneNesting(){return this.swimlaneNesting},setSwimlaneNesting(r){this.swimlaneNesting=r},isSwimlaneSelectionEnabled(){return this.swimlaneSelectionEnabled},setSwimlaneSelectionEnabled(r){this.swimlaneSelectionEnabled=r}},TerminalMixin={isTerminalPointMovable(r,t){return!0},getOpposites(r,t=null,e=!0,i=!0){const s=[],n=new Map;for(let l=0;l<r.length;l+=1){const o=this.getView().getState(r[l]),a=o?o.getVisibleTerminal(!0):this.getView().getVisibleTerminal(r[l],!0),h=o?o.getVisibleTerminal(!1):this.getView().getVisibleTerminal(r[l],!1);a===t&&h&&h!==t&&i?n.has(h)||(n.set(h,!0),s.push(h)):h===t&&a&&a!==t&&e&&(n.has(a)||(n.set(a,!0),s.push(a)))}return s}},ValidationMixin={validationAlert(r){alert(r)},isEdgeValid(r,t,e){return!this.getEdgeValidationError(r,t,e)},getEdgeValidationError(r=null,t=null,e=null){if(r&&!this.isAllowDanglingEdges()&&(!t||!e))return"";if(r&&!r.getTerminal(!0)&&!r.getTerminal(!1))return null;if(!this.isAllowLoops()&&t===e&&t||!this.isValidConnection(t,e))return"";if(t&&e){let i="";if(!this.isMultigraph()){const o=this.getDataModel().getEdgesBetween(t,e,!0);(o.length>1||o.length===1&&o[0]!==r)&&(i+=`${translate(this.getAlreadyConnectedResource())||this.getAlreadyConnectedResource()}
8
8
  `)}const s=t.getDirectedEdgeCount(!0,r),n=e.getDirectedEdgeCount(!1,r);for(const o of this.multiplicities){const a=o.check(this,r,t,e,s,n);isNullish(a)||(i+=a)}const l=this.validateEdge(r,t,e);return isNullish(l)||(i+=l),i.length>0?i:null}return this.isAllowDanglingEdges()?null:""},validateEdge(r=null,t=null,e=null){return null},validateGraph(r=null,t){if(r=r??this.getDataModel().getRoot(),!r)return"The root does not exist!";t=t??{};let e=!0;const i=r.getChildCount();for(let l=0;l<i;l+=1){const o=r.getChildAt(l);let a=t;this.isValidRoot(o)&&(a={});const h=this.validateGraph(o,a);h?this.setCellWarning(o,h.replace(/\n/g,"<br>")):this.setCellWarning(o,null),e=e&&h==null}let s="";r&&r.isCollapsed()&&!e&&(s+=`${translate(this.getContainsValidationErrorsResource())||this.getContainsValidationErrorsResource()}
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
- `)}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>&nbsp;</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,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,{viewpointFilter:n,relationshipTypes:e.relationshipTypes});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,e==null?void 0:e.relationshipTypes)),nodeDirections:new Map,callbacks:NO_CALLBACKS,positionCache:h,hierarchyRelationshipTypes:e==null?void 0:e.relationshipTypes,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&&lt.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};
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>&nbsp;</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 $=2;$<l;$+=1){h=d,d=n[$];const et=ptSegDistSq(h.x,h.y,d.x,d.y,e,i);f+=a[$-2],et<=c&&(c=et,g=$-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 T=y-S,b=v-w;C-=S,m-=w;let H=0;C=T-C,m=b-m;const R=C*T+m*b;R<=0?H=0:H=R*R/(T*T+b*b);let M=Math.sqrt(H);M>p&&(M=p);let I=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&&(I=-I),new Point((o/2-u-M)/o*-2,I/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,T=C+f,b=m+p,H=T+y,R=b+v,M=H-3*y,I=R-3*v;t.begin(),t.moveTo(S,w),t.lineTo(C,m),t.lineTo(T,b),t.lineTo(H,R),t.lineTo(o.x-i*u,o.y-i*g),t.lineTo(M,I),t.lineTo(M+y,I+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,T=v/S,b,H=T,R=l*T,M=-l*w;const I=[];g?t.setLineJoin("round"):e.length>2&&t.setMiterLimit(1.42),t.begin();const z=w,$=T;if(a&&!o)this.paintMarker(t,e[0].x,e[0].y,w,T,c,s,l,d,!0);else{const O=e[0].x+R/2+d*w,A=e[0].y+M/2+d*T,B=e[0].x-R/2+d*w,V=e[0].y-M/2+d*T;o?(t.moveTo(O,A),I.push(()=>{t.lineTo(B,V)})):(t.moveTo(B,V),t.lineTo(O,A))}let et=0,x=0,P=0;for(let O=0;O<e.length-2;O+=1){const A=relativeCcw(e[O].x,e[O].y,e[O+1].x,e[O+1].y,e[O+2].x,e[O+2].y);if(et=e[O+2].x-e[O+1].x,x=e[O+2].y-e[O+1].y,P=Math.sqrt(et*et+x*x),P!==0){m=et/P,H=x/P;const B=w*m+T*H,V=Math.max(Math.sqrt((B+1)/2),.04);C=w+m,b=T+H;const _=Math.sqrt(C*C+b*b);if(_!==0){C/=_,b/=_;const Y=Math.max(V,Math.min(this.strokeWidth/200+.04,.35)),D=A!==0&&g?Math.max(.1,Y):Math.max(V,.06),k=e[O+1].x+b*l/2/D,G=e[O+1].y-C*l/2/D,W=e[O+1].x-b*l/2/D,U=e[O+1].y+C*l/2/D;if(A===0||!g)t.lineTo(k,G),((J,it)=>{I.push(()=>{t.lineTo(J,it)})})(W,U);else if(A===-1){const J=W+T*l,it=U-w*l,F=W+H*l,K=U-m*l;t.lineTo(J,it),t.quadTo(k,G,F,K),((rt,tt)=>{I.push(()=>{t.lineTo(rt,tt)})})(W,U)}else t.lineTo(k,G),((J,it)=>{const F=k-T*l,K=G+w*l,rt=k-H*l,tt=G+m*l;I.push(()=>{t.quadTo(J,it,F,K)}),I.push(()=>{t.lineTo(rt,tt)})})(W,U);w=m,T=H}}}if(R=l*H,M=-l*m,h&&!o)this.paintMarker(t,f.x,f.y,-w,-T,u,n,l,d,!1);else{t.lineTo(f.x-d*m+R/2,f.y-d*H+M/2);const O=f.x-d*m-R/2,A=f.y-d*H-M/2;o?(t.moveTo(O,A),I.splice(0,0,()=>{t.moveTo(O,A)})):t.lineTo(O,A)}for(let O=I.length-1;O>=0;O--)I[O]();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,z,$,c,s,l,d,!0),t.stroke(),t.end()),h&&!o&&(t.begin(),this.paintMarker(t,f.x,f.y,-w,-T,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(),T=(R,M,I)=>{let z=!1;I&&Math.abs(R-S)<f?(e.x=R-t.getCenterX(),f=Math.abs(R-S),z=!0):I||(Math.abs(R-y)<f?(e.x=R-t.x,f=Math.abs(R-y),z=!0):Math.abs(R-v)<f&&(e.x=R-t.x-t.width,f=Math.abs(R-v),z=!0)),z&&(h=M,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||z},b=(R,M,I)=>{let z=!1;I&&Math.abs(R-m)<p?(e.y=R-t.getCenterY(),p=Math.abs(R-m),z=!0):I||(Math.abs(R-w)<p?(e.y=R-t.y,p=Math.abs(R-w),z=!0):Math.abs(R-C)<p&&(e.y=R-t.y-t.height,p=Math.abs(R-C),z=!0)),z&&(u=M,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||z};for(let R=0;R<this.states.length;R+=1){const M=this.states[R];M&&!this.isStateIgnored(M)&&(this.horizontal&&(T(M.getCenterX(),M,!0),T(M.x,M,!1),T(M.x+M.width,M,!1),M.cell||T(M.getCenterX(),M,!1)),this.vertical&&(b(M.getCenterY(),M,!0),b(M.y,M,!1),b(M.y+M.height,M,!1),M.cell||b(M.getCenterY(),M,!1)))}this.graph.snapDelta(e,t,!i,a,c),e=this.getDelta(t,h,e.x,u,e.y);const H=this.graph.container;if(!a&&this.guideX)this.guideX.node.style.visibility="hidden";else if(this.guideX){let R=null,M=null;h&&(R=Math.min(t.y+e.y-this.graph.getPanDy(),h.y),M=Math.max(t.y+t.height+e.y-this.graph.getPanDy(),h.y+h.height)),R!==null&&M!==null?this.guideX.points=[new Point(d,R),new Point(d,M)]:this.guideX.points=[new Point(d,-this.graph.getPanDy()),new Point(d,H.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,M=null;u!=null&&t!=null&&(R=Math.min(t.x+e.x-this.graph.getPanDx(),u.x),M=Math.max(t.x+t.width+e.x-this.graph.getPanDx(),u.x+u.width)),R!=null&&M!=null&&g!==null?this.guideY.points=[new Point(R,g),new Point(M,g)]:g!==null&&(this.guideY.points=[new Point(-this.graph.getPanDx(),g),new Point(H.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,T=this.maxFitScale??1/0;if(C=Math.max(Math.min(C,T),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,H=u.y!=null?Math.floor(c.translate.y-u.y/y+e/C+s/2):e;c.scaleAndTranslate(C,b,H)}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})}}function projectIrSemantics(r,t){if(!(t!=null&&t.length))return r;const e=new Map(t.filter(i=>i.kind==="mapped"&&typeof i.memoElementId=="string").map(i=>[i.memoElementId,i]));return r.nodes=r.nodes.map(i=>{var n,l;const s=e.get(i.subjectId);return s?{...i,subjectId:s.identity.id,kind:s.identity.metaclass??i.kind,sourceRange:((l=(n=s.source)==null?void 0:n.start)==null?void 0:l.line)===void 0?i.sourceRange:{start:s.source.start.line,end:s.source.start.line},accessibilityText:`${i.accessibilityText}; SysML subject ${s.identity.id}`}:i}),r}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){var u;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=(u=e==null?void 0:e.elementIds)!=null&&u.length?new Set(e.elementIds):void 0;if(!l&&!o&&!a)return;const h=l?t.viewpoints.find(g=>g.id===n):void 0,d=h?new Set(h.visibleKinds):void 0,c=h?new Set(h.visibleLayers):void 0;return g=>s.has(g.layer)?!1:a?a.has(g.id):((d==null?void 0:d.size)??0)>0||((c==null?void 0:c.size)??0)>0?!!(d!=null&&d.has(g.kind))||!!(c!=null&&c.has(g.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 p,y,v,S,w,C,m,T,b,H,R;const{model:t,diagram:e,layoutProviderId:i}=r,s=resolveViewKind(e);if(nonCanvasKind(s))return null;const n=buildViewpointFilter(r),l=!!((p=e==null?void 0:e.properties)!=null&&p.layoutStyle),o=((y=e==null?void 0:e.properties)==null?void 0:y.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,{viewpointFilter:n,relationshipTypes:e.relationshipTypes});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:((v=r.actionFlow)==null?void 0:v.swimlanes)??!0,laneGrouping:((S=r.actionFlow)==null?void 0:S.laneGrouping)??"allocation",displayLevel:((w=r.actionFlow)==null?void 0:w.displayLevel)??"all",expandedActionIds:((C=r.actionFlow)==null?void 0:C.expandedActionIds)??new Set,onToggleAction:()=>{},focusActionId:((m=r.actionFlow)==null?void 0:m.focusActionId)??void 0,visibleFlowKinds:((T=r.actionFlow)==null?void 0:T.visibleFlowKinds)??new Set(["control","data","energy","material"]),direction:((b=r.actionFlow)==null?void 0:b.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 M=resolveGeneralMode(e==null?void 0:e.properties);a&&M!=="graph"?d=await computeGeneralViewLayout(t,{mode:M,viewpointFilter:n,expandedNodes:expandAll(buildGeneralViewTree(t,n,e==null?void 0:e.relationshipTypes)),nodeDirections:new Map,callbacks:NO_CALLBACKS,positionCache:h,hierarchyRelationshipTypes:e==null?void 0:e.relationshipTypes,layoutProviderId:i}):d=await computeLayout(t,{viewpointFilter:n,relationshipTypes:e==null?void 0:e.relationshipTypes,compartments:a,layoutProviderId:i})}const c=projectIrSemantics(projectLayoutToNotationScene(d.nodes,d.edges),((H=t.sysmlIr)==null?void 0:H.elements)??[]),u=(((R=t.sysmlIr)==null?void 0:R.elements)??[]).filter(M=>M.kind==="generic"),g=new Set(c.nodes.map(M=>M.subjectId)),f=Math.max(24,...c.nodes.map(M=>M.y+M.height+32));return u.forEach((M,I)=>{var $,et,x,P;if(g.has(($=M.identity)==null?void 0:$.id))return;const z=String(((et=M.standardProperties)==null?void 0:et.name)??((x=M.identity)==null?void 0:x.declarationPath)??"Unmapped SysML element");c.nodes.push({id:`generic:${M.identity.id}`,subjectId:M.identity.id,x:24+I%4*170,y:f+Math.floor(I/4)*84,width:150,height:56,label:z,kind:((P=M.identity)==null?void 0:P.metaclass)??"SysML element",glyph:"generic",color:"#D97706",isDefinition:!1,isFrame:!1,accessibilityText:`Unmapped SysML element ${z}`,diagnostic:{domain:"memo-ingest",severity:"warning",message:M.unmappable??`Memo could not lower ${z}`}})}),c}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 at;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,T]=reactExports.useState(!0),[b,H]=reactExports.useState("allocation"),[R,M]=reactExports.useState("all"),[I,z]=reactExports.useState("horizontal"),[$,et]=reactExports.useState(new Set(["control","data","energy","material"])),[x,P]=reactExports.useState(new Set),[L,O]=reactExports.useState(null),[A,B]=reactExports.useState(0),[V,_]=reactExports.useState(null),[Y,D]=reactExports.useState(0),k=getDiagram(r,t),G=resolveViewKind(k),W=nonCanvasKind(G),U=t?o[t]:void 0,J=selectedLayoutProviderId(U),it=reactExports.useMemo(()=>{if(!r||!k)return[];const E=new Set(k.elementIds);return commonDisplayLevels(Object.values(r.elements).filter(N=>E.has(N.id)&&N.allocatedTo).map(N=>N.allocatedTo),r)},[r,k]);reactExports.useEffect(()=>{if(!r||W){y(null);return}const E=c.current;if(u.current!==r&&g.current===t&&E){const st=E.getView();f.current={scale:st.scale,x:st.translate.x,y:st.translate.y}}else f.current=null;u.current=r,g.current=t;let j=!1;S(!0),C(null);const Q=new Promise((st,ht)=>{window.setTimeout(()=>ht(new Error(`Layout exceeded ${SCENE_TIMEOUT_MS/1e3}s`)),SCENE_TIMEOUT_MS)});return Promise.race([computeDiagramScene({model:r,diagram:k??null,selectedViewpointId:e,hiddenLayers:s,layoutProviderId:J,actionFlow:{swimlanes:m,laneGrouping:b,displayLevel:R,expandedActionIds:x,focusActionId:L,visibleFlowKinds:$,direction:I}}),Q]).then(st=>{j||(y(st),S(!1))}).catch(st=>{j||(console.error("maxGraph scene error:",st),C("The diagram could not be laid out. Reduce the visible hierarchy or reset the layout."),S(!1))}),()=>{j=!0}},[r,k,t,e,s,J,W,m,b,R,x,L,$,I]);const F=reactExports.useCallback(E=>{if(!t||E.length===0)return;const N=useModelStore.getState().diagramLayouts[t]??{nodes:{},edges:{}},j={};for(const st of E){const ht=st.getId(),nt=st.getGeometry();!ht||!nt||st.isEdge()||(j[ht]={...N.nodes[ht]??{},x:nt.x,y:nt.y,width:nt.width,height:nt.height})}if(Object.keys(j).length===0)return;const Q={...N,nodes:{...N.nodes,...j},edges:N.edges??{},canvas:{...N.canvas,autoLayout:!1}};a({[t]:Q}),sendDiagramLayoutUpdate(t,Q)},[t,a]),K=reactExports.useRef(F);reactExports.useEffect(()=>{K.current=F},[F]);const rt=reactExports.useRef(r);reactExports.useEffect(()=>{rt.current=r},[r]),reactExports.useEffect(()=>{var bt;const E=d.current;if(!E||!p)return;InternalEvent.disableContextMenu(E);const N=new Graph(E,void 0,[...getDefaultPlugins(),RubberBandHandler]);c.current=N,N.setPanning(!0),N.setCellsEditable(!1),N.setCellsResizable(!1),N.setConnectable(!0),N.setAllowDanglingEdges(!1),N.setCellsDisconnectable(!1),N.options.foldingEnabled=!1,N.setGridEnabled(!0),N.setGridSize(20);const j=N.getPlugin("SelectionHandler");j&&(j.guidesEnabled=!0);const Q=t?useModelStore.getState().diagramLayouts[t]:void 0,st=applySavedLayout(p,Q),ht=N.getDefaultParent(),nt=new Map;N.batchUpdate(()=>{for(const X of st.nodes){const pt=X.parentId?nt.get(X.parentId)??ht:ht,lt=N.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&&lt.setConnectable(!1),nt.set(X.id,lt)}for(const X of st.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=N.insertEdge({parent:ht,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?N.getView().scaleAndTranslate(vt.scale,vt.x,vt.y):((bt=Q==null?void 0:Q.canvas)==null?void 0:bt.zoom)!==void 0&&Q.canvas.pan?(N.getView().setScale(Q.canvas.zoom),N.getView().setTranslate(Q.canvas.pan.x,Q.canvas.pan.y)):gt=fitWhenSized(N,E),N.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)}),N.addListener(InternalEvent.CELLS_MOVED,(X,pt)=>{const lt=pt.getProperty("cells")??[];K.current(lt)});const ft=N.getSelectionModel(),mt=()=>{B(N.getSelectionCells().filter(X=>!X.isEdge()).length)};ft.addListener(InternalEvent.CHANGE,mt);const Et=N.getPlugin("ConnectionHandler");Et==null||Et.addListener(InternalEvent.CONNECT,(X,pt)=>{var Pt,Tt;const lt=pt.getProperty("cell");if(!lt)return;const ct=(Pt=lt.getTerminal(!0))==null?void 0:Pt.getId(),St=(Tt=lt.getTerminal(!1))==null?void 0:Tt.getId();window.setTimeout(()=>{try{N.removeCells([lt],!1)}catch{}},0);const dt=rt.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&&_({sourceElement:Ct,targetElement:wt})});const xt=X=>{X.preventDefault(),X.deltaY<0?N.zoomIn():N.zoomOut()};return E.addEventListener("wheel",xt,{passive:!1}),()=>{gt==null||gt(),E.removeEventListener("wheel",xt),ft.removeListener(mt),B(0),c.current=null,N.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 N=E.getDataModel().getCell(i);N&&E.getSelectionCell()!==N&&E.setSelectionCell(N)},[i,p]);const tt=reactExports.useCallback(E=>{const N=c.current;if(!N)return;const j=N.getSelectionCells().filter(Q=>!Q.isEdge());j.length<2||(N.alignCells(E,j),K.current(j))},[]),ot=reactExports.useCallback(async E=>{const N=V==null?void 0:V.sourceElement.id;if(_(null),!t)return;const j=await h({type:E.type,sourceId:E.sourceId,targetId:E.targetId,direction:E.direction,flowItem:E.flowItem,selectedElementId:N,diagramId:t});j.success||console.warn(`[MEMO] Relationship rejected: ${j.error}`)},[V,t,h]),Z=!!U&&(Object.keys(U.nodes??{}).length>0||((at=U.canvas)==null?void 0:at.autoLayout)===!1),yt=reactExports.useCallback(()=>{if(!t)return;const E={nodes:{},edges:{},canvas:{autoLayout:!0}};a({[t]:E}),sendDiagramLayoutUpdate(t,E),D(N=>N+1)},[t,a]),ut=reactExports.useCallback(()=>{if(!p)return;const E=new Blob([notationSceneToSvg(p)],{type:"image/svg+xml"}),N=URL.createObjectURL(E),j=document.createElement("a");j.href=N,j.download=`${(k==null?void 0:k.name)??"diagram"}.svg`,j.click(),URL.revokeObjectURL(N)},[p,k==null?void 0:k.name]);if(k&&r&&W==="grid")return jsxRuntimeExports.jsx(GridView,{diagram:k,model:r,viewpointFilter:buildViewpointFilter({model:r,diagram:k,selectedViewpointId:e,hiddenLayers:s})});if(k&&r&&W==="browser")return jsxRuntimeExports.jsx(BrowserView,{diagram:k,model:r,viewpointFilter:buildViewpointFilter({model:r,diagram:k,selectedViewpointId:e,hiddenLayers:s})});if(k&&r&&W==="geometry")return jsxRuntimeExports.jsx(ScreenLayoutView,{diagram:k,model:r,viewpointFilter:buildViewpointFilter({model:r,diagram:k,selectedViewpointId:e,hiddenLayers:s})});const q={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"}}),G==="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:{...q,background:m?"#1B3A4B":"#FFFFFF",color:m?"#FFFFFF":"#374151"},onClick:()=>T(E=>!E),title:"Toggle swimlanes",children:"Lanes"}),m&&jsxRuntimeExports.jsx("button",{style:q,onClick:()=>H(E=>E==="allocation"?"stage":"allocation"),title:"Group lanes by allocation or stage",children:b==="allocation"?"Allocation":"Stage"}),m&&b==="allocation"&&it.length>0&&jsxRuntimeExports.jsxs("select",{value:R,onChange:E=>M(E.target.value==="all"?"all":Number(E.target.value)),style:q,title:"Responsibility hierarchy level",children:[jsxRuntimeExports.jsx("option",{value:"all",children:"All levels"}),it.map(E=>jsxRuntimeExports.jsxs("option",{value:E,children:["L",E]},E))]}),jsxRuntimeExports.jsx("button",{style:{...q,background:I==="horizontal"?"#1B3A4B":"#FFFFFF",color:I==="horizontal"?"#FFFFFF":"#374151"},onClick:()=>z("horizontal"),title:"Left-to-right flow",children:"→"}),jsxRuntimeExports.jsx("button",{style:{...q,background:I==="vertical"?"#1B3A4B":"#FFFFFF",color:I==="vertical"?"#FFFFFF":"#374151"},onClick:()=>z("vertical"),title:"Top-to-bottom flow",children:"↓"}),jsxRuntimeExports.jsx("button",{style:q,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:q,onClick:()=>P(new Set),title:"Collapse all sub-actions",children:"Collapse"}),["control","data","energy","material"].map(E=>jsxRuntimeExports.jsx("button",{style:{...q,textTransform:"capitalize",opacity:$.has(E)?1:.45},onClick:()=>et(N=>{const j=new Set(N);return j.has(E)?j.delete(E):j.add(E),j}),title:`Toggle ${E} flows`,children:E},E)),L&&jsxRuntimeExports.jsx("button",{style:q,onClick:()=>O(null),children:"Parent"})]}),jsxRuntimeExports.jsxs("div",{className:"absolute top-3 right-3 z-10 flex items-center gap-1.5",children:[A>=2&&jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment,{children:[jsxRuntimeExports.jsx("button",{style:q,onClick:()=>tt("left"),title:"Align left edges","aria-label":"Align left",children:"⇤"}),jsxRuntimeExports.jsx("button",{style:q,onClick:()=>tt("center"),title:"Align horizontal centres","aria-label":"Align centres",children:"↔"}),jsxRuntimeExports.jsx("button",{style:q,onClick:()=>tt("right"),title:"Align right edges","aria-label":"Align right",children:"⇥"}),jsxRuntimeExports.jsx("button",{style:q,onClick:()=>tt("top"),title:"Align top edges","aria-label":"Align top",children:"⤒"}),jsxRuntimeExports.jsx("button",{style:q,onClick:()=>tt("middle"),title:"Align vertical middles","aria-label":"Align middles",children:"↕"}),jsxRuntimeExports.jsx("button",{style:q,onClick:()=>tt("bottom"),title:"Align bottom edges","aria-label":"Align bottom",children:"⤓"}),jsxRuntimeExports.jsx("span",{style:{color:"#E5E5E0"},children:"|"})]}),jsxRuntimeExports.jsx("button",{style:{...q,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:q,onClick:()=>{var E;return(E=c.current)==null?void 0:E.zoomIn()},title:"Zoom in",children:"+"}),jsxRuntimeExports.jsx("button",{style:q,onClick:()=>{var E;return(E=c.current)==null?void 0:E.zoomOut()},title:"Zoom out",children:"-"}),jsxRuntimeExports.jsx("button",{style:q,onClick:()=>fitGraph(c.current),title:"Fit diagram to the viewport",children:"Fit view"}),jsxRuntimeExports.jsx("button",{style:q,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:k?"No elements in this view.":"Select a view from the explorer."}),V&&jsxRuntimeExports.jsx(RelationshipPicker,{x:window.innerWidth/2-130,y:window.innerHeight/2-160,sourceElement:V.sourceElement,targetElement:V.targetElement,registries:getRegistries(r),allowedTypes:k==null?void 0:k.relationshipTypes,onSelect:ot,onCancel:()=>_(null)})]})}export{MaxGraphCanvas};