@relation-graph/vue3 3.0.10 → 3.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/relation-graph.js +3 -3
- package/relation-graph.mjs +6 -6
- package/relation-graph.ssr.mjs +6 -6
- package/relation-graph.umd.js +3 -3
package/relation-graph.umd.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
(function(B,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],r):(B=typeof globalThis<"u"?globalThis:B||self,r(B.RelationGraph={},B.Vue))})(this,function(B,r){"use strict";var ms=Object.defineProperty;var ys=(B,r,ue)=>r in B?ms(B,r,{enumerable:!0,configurable:!0,writable:!0,value:ue}):B[r]=ue;var _=(B,r,ue)=>(ys(B,typeof r!="symbol"?r+"":r,ue),ue);/*!
|
|
2
|
-
* relation-graph v3.0.
|
|
2
|
+
* relation-graph v3.0.11
|
|
3
3
|
* (c) 2026 WanLian <seeksdream@qq.com>
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
* Repository: https://github.com/seeksdream/relation-graph
|
|
6
|
-
*/const ue="",vs="",We="3.0.
|
|
6
|
+
*/const ue="",vs="",We="3.0.11",Tt=Symbol("INSTALLED_KEY"),ye="RelationGraphProvideKey",de=l=>{try{if("touches"in l&&l.touches||"targetTouches"in l&&l.targetTouches)return!0}catch{}return!1},ce=l=>{if(de(l)){const i=("touches"in l&&l.touches.length>0?l.touches:void 0)||("targetTouches"in l&&l.targetTouches.length>0?l.targetTouches:void 0)||("changedTouches"in l&&l.changedTouches.length>0?l.changedTouches:void 0);if(!i||i.length===0)throw new Error("error touches");return{clientX:i[0].clientX,clientY:i[0].clientY}}if("clientX"in l&&"clientY"in l)return{clientX:l.clientX,clientY:l.clientY};throw new Error("error client coordinate")},L=(...l)=>{typeof window<"u"&&window.relationGraphDebug&&console.log("[relation-graph:debug]",...l)},ve=(l,i,e)=>{if(!l)return null;if(l.classList){if(l.classList.contains(i))return l;if(l.classList.contains(e))return null}let t=null;if(l.assignedSlot?t=l.assignedSlot:t=l.parentElement,!t){const n=l.parentNode;n instanceof ShadowRoot&&(t=n.host)}return ve(t,i,e)},Ee=l=>new Promise(i=>setTimeout(i,l)),St=()=>{const l="l",i="o",e="g",t=new Date().getFullYear(),n=[];return t>1&&n.push(l),t>201&&n.push(i),t>1113&&n.push(e),n.join("")},Rt=()=>{const l="c",i="o",e="n",t="s",n="o",o="l",s="e",a=new Date().getFullYear(),d=[];return a>1&&d.push(l),a>21&&d.push(i),a>35&&d.push(e),a>55&&d.push(t),a>189&&d.push(n),a>231&&d.push(o),a>1234&&d.push(s),d.join("")},Ue=l=>l.replace(/-/g,"").replace(/\*/g,"-"),Je=l=>{const i=Rt(),e=St(),t="r-e-l-a-t-i-o-n*g-r-a-p-h",n="h-t-t-p-s-:-/-/-g-i-t-h-u-b-.-c-o-m-/-s-e-e-k-s-d-r-e-a-m-/-r-e-l-a-t-i-o-n-*-g-r-a-p-h";typeof window<"u"&&window&&window[i]&&window[i][e](`%c ${Ue(t)} %c Version v${We}(${l}) %c More info: ${Ue(n)} %c`,"background:#35495e ; padding: 1px; border-radius: 3px 0 0 3px; color: #fff","background:#41b883 ; padding: 1px; border-radius: 0 3px 3px 0; color: #fff","background:#fff ; padding: 1px; border-radius: 0 3px 3px 0; color: #41b883","background:transparent")},Mt=(l,i)=>{typeof i=="string"&&(i=[i]);for(const t of i)if(l.classList.contains(t))return!0;let e=l.parentElement;for(;e;){for(const t of i)if(e.classList.contains(t))return!0;e=e.parentElement}return!1},ge=l=>{const i=l.target;return Mt(i,"rel-text-editing")?!0:["input","textarea"].includes(document.activeElement.tagName.toLowerCase())},Ie=(l=5)=>{const i="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";let e="";const t=l>30?30:l;for(let n=0;n<t;n++)e+=i[Math.floor(Math.random()*i.length)];return e},Et={"icon-quanping":{data:`
|
|
7
7
|
<path d="M921.6 358.4h-76.8V179.2h-179.2V102.4h256v256zM102.4 358.4h76.8V179.2h179.2V102.4H102.4v256z m0 307.2h76.8v179.2h179.2v76.8H102.4V665.6z m819.2 0h-76.8v179.2h-179.2v76.8h256V665.6z"></path>`},"icon-fangda":{data:`
|
|
8
8
|
<path d="M853.333333 480H544V170.666667c0-17.066667-14.933333-32-32-32s-32 14.933333-32 32v309.333333H170.666667c-17.066667 0-32 14.933333-32 32s14.933333 32 32 32h309.333333V853.333333c0 17.066667 14.933333 32 32 32s32-14.933333 32-32V544H853.333333c17.066667 0 32-14.933333 32-32s-14.933333-32-32-32z"></path>
|
|
9
9
|
`},"icon-suoxiao":{data:`
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
`},"icon-lianjiezhong":{data:`
|
|
40
40
|
<path d="M512 907c-24.852 0-45-20.148-45-45s20.148-45 45-45c168.446 0 305-136.554 305-305S680.446 207 512 207 207 343.554 207 512c0 24.852-20.148 45-45 45S117 536.852 117 512c0-218.152 176.848-395 395-395S907 293.848 907 512 730.152 907 512 907z"></path>
|
|
41
41
|
|
|
42
|
-
`}},It=["innerHTML"],K=r.defineComponent({__name:"RGIcons",props:{iconName:{},className:{}},setup(l){const i=l,e=r.computed(()=>Et[i.iconName]);return(t,n)=>(r.openBlock(),r.createElementBlock("svg",{class:r.normalizeClass(["rg-icon",t.className]),viewBox:"0 0 1024 1024",version:"1.1",xmlns:"http://www.w3.org/2000/svg",innerHTML:e.value.data},null,10,It))}}),je=r.defineComponent({__name:"RGNodeExpandHolder",props:{node:{},expandOrCollapseNode:{type:Function},expandHolderPosition:{}},setup(l){const i=l,e=r.computed(()=>i.node.expanded===!1?"c-expanded":"c-collapsed");return(t,n)=>(r.openBlock(),r.createElementBlock("div",{class:r.normalizeClass(["rg-node-expand-holder","c-expand-positon-"+t.expandHolderPosition])},[r.createElementVNode("div",{class:r.normalizeClass(["rg-node-expand-button",e.value]),onClick:n[0]||(n[0]=r.withModifiers((...o)=>t.expandOrCollapseNode&&t.expandOrCollapseNode(...o),["stop"])),onTouchend:n[1]||(n[1]=r.withModifiers((...o)=>t.expandOrCollapseNode&&t.expandOrCollapseNode(...o),["stop"]))},[t.node.expanded===!1?(r.openBlock(),r.createBlock(K,{key:0,iconName:"icon-fangda"})):(r.openBlock(),r.createBlock(K,{key:1,iconName:"icon-suoxiao"}))],34)],2))}});function H(){const l=r.inject(ye,null);if(!l)throw new Error("RGHooks.useGraphInstance must be used inside RGProvider or RelationGraph tag.");return l==null?void 0:l.graphInstance}const Dt=["data-id"],Vt={class:"rg-node-text"},qe=r.defineComponent({__name:"RGNodePeel",props:{nodeProps:{},defaultExpandHolderPosition:{},dragging:{type:Boolean},checked:{type:Boolean}},setup(l){const i=H(),e=l,t=r.ref(),n=r.computed(()=>e.nodeProps.borderColor),o=r.computed(()=>e.nodeProps.borderWidth===void 0?void 0:e.nodeProps.borderWidth+"px"),s=r.computed(()=>e.nodeProps.width?e.nodeProps.width+"px":void 0),a=r.computed(()=>e.nodeProps.height?e.nodeProps.height+"px":void 0),d=r.computed(()=>e.nodeProps.expandHolderPosition?e.nodeProps.expandHolderPosition!=="hide":e.defaultExpandHolderPosition&&e.defaultExpandHolderPosition!=="hide"&&e.nodeProps.rgChildrenSize>0),h=r.computed(()=>e.nodeProps.rgCalcedVisibility),c=p=>{i.expandOrCollapseNode(e.nodeProps,p)},f=p=>{i.onNodeDragStart(e.nodeProps,p)};return r.onMounted(()=>{i.addNodeResizeListener(t.value,e.nodeProps)}),r.onBeforeUnmount(()=>{i.removeNodeResizeListener(t.value)}),(p,m)=>r.withDirectives((r.openBlock(),r.createElementBlock("div",{ref_key:"nodePeelRef",ref:t,style:r.normalizeStyle({transform:`translate(${p.nodeProps.x}px, ${p.nodeProps.y}px)`,"--rg-node-z-index":p.nodeProps.zIndex?p.nodeProps.zIndex:void 0,"--rg-node-color":p.nodeProps.color,"--rg-node-font-color":p.nodeProps.fontColor,"--rg-node-font-size":p.nodeProps.fontSize?p.nodeProps.fontSize+"px":void 0,"--rg-node-border-width":o.value,"--rg-node-border-radius":p.nodeProps.borderRadius&&p.nodeProps.borderRadius+"px","--rg-node-border-color":n.value,"--rg-node-width":s.value,"--rg-node-height":a.value,"--rg-node-opacity":p.nodeProps.opacity===void 0?void 0:p.nodeProps.opacity}),class:r.normalizeClass(["rg-node-peel",p.nodeProps.selected&&"rg-node-selected",p.dragging&&"rg-node-dragging",p.checked&&"rg-node-checked",(p.nodeProps.disablePointEvent||p.nodeProps.opacity===0)&&"rg-node-disable-events","rg-node-shape-"+(p.nodeProps.nodeShape===void 0?1:p.nodeProps.nodeShape),"rg-node-type-"+p.nodeProps.type,p.nodeProps.className]),"data-id":p.nodeProps.id},[d.value?r.renderSlot(p.$slots,"node-expand-button",{key:0,node:p.nodeProps,expandOrCollapseNode:c,expandHolderPosition:p.nodeProps.expandHolderPosition||p.defaultExpandHolderPosition},()=>[r.createVNode(je,{node:p.nodeProps,checked:p.checked,expandOrCollapseNode:c,expandHolderPosition:p.nodeProps.expandHolderPosition||p.defaultExpandHolderPosition},null,8,["node","checked","expandHolderPosition"])]):r.createCommentVNode("",!0),r.createElementVNode("div",{class:"rg-node",onMousedown:r.withModifiers(f,["left","stop"]),onTouchstart:r.withModifiers(f,["stop"])},[r.renderSlot(p.$slots,"node",{node:p.nodeProps,checked:p.checked,dragging:p.dragging},()=>[r.createElementVNode("div",Vt,[r.createElementVNode("span",null,r.toDisplayString(p.nodeProps.text),1)])])],32)],14,Dt)),[[r.vShow,h.value]])}}),Bt={class:"rg-nodes-container"},At=r.defineComponent({__name:"RGCanvasContent4Nodes",props:{defaultExpandHolderPosition:{},draggingNodeId:{},checkedNodeId:{}},setup(l){const i=H(),e=r.computed(()=>i.getShouldRenderNodes(i.dataStores.shouldRenderNodesRef.value));return r.onMounted(()=>{L("[RGCanvas mounted]")}),(t,n)=>(r.openBlock(),r.createElementBlock("div",Bt,[(r.openBlock(!0),r.createElementBlock(r.Fragment,null,r.renderList(e.value,o=>(r.openBlock(),r.createBlock(qe,{key:o.id,"node-props":o,"default-expand-holder-position":t.defaultExpandHolderPosition,dragging:o.id===t.draggingNodeId,checked:o.id===t.checkedNodeId},{node:r.withCtx(s=>[r.renderSlot(t.$slots,"node",r.mergeProps({ref_for:!0},s))]),"node-expand-button":r.withCtx(s=>[r.renderSlot(t.$slots,"node-expand-button",r.mergeProps({ref_for:!0},s))]),_:2},1032,["node-props","default-expand-holder-position","dragging","checked"]))),128))]))}}),zt=["id","markerWidth","markerHeight","refX","refY","viewBox"],Xt=["d"],Gt=["id","markerWidth","markerHeight","refX","refY","viewBox"],Ft=["d"],Ze=r.defineComponent({__name:"RGGraphDefs",props:{forElementLines:{type:Boolean}},setup(l){const i=H(),e=r.computed(()=>i.dataStores.optionsRef.value);return(t,n)=>(r.openBlock(),r.createElementBlock("defs",null,[r.createElementVNode("marker",{id:e.value.instanceId+"-arrow-default",markerWidth:e.value.defaultLineMarker.markerWidth,markerHeight:e.value.defaultLineMarker.markerHeight,refX:e.value.defaultLineMarker.refX,refY:e.value.defaultLineMarker.refY,markerUnits:"userSpaceOnUse",orient:"auto",viewBox:e.value.defaultLineMarker.viewBox},[r.createElementVNode("path",{style:{fill:"context-stroke"},d:e.value.defaultLineMarker.data},null,8,Xt)],8,zt),r.createElementVNode("marker",{id:e.value.instanceId+"-start-arrow-default",markerWidth:e.value.defaultLineMarker.markerWidth,markerHeight:e.value.defaultLineMarker.markerHeight,refX:e.value.defaultLineMarker.refX,refY:e.value.defaultLineMarker.refY,markerUnits:"userSpaceOnUse",orient:"auto-start-reverse",viewBox:e.value.defaultLineMarker.viewBox},[r.createElementVNode("path",{style:{fill:"context-stroke"},d:e.value.defaultLineMarker.data},null,8,Ft)],8,Gt),r.renderSlot(t.$slots,"default")]))}});var D=(l=>(l.Node="node",l.NodePoint="NodePoint",l.HTMLElementId="HTMLElementId",l.CanvasPoint="CanvasPoint",l.ViewPoint="ViewPoint",l))(D||{}),W=(l=>(l.border="border",l.ltrb="ltrb",l.tb="tb",l.lr="lr",l.left="left",l.right="right",l.top="top",l.bottom="bottom",l))(W||{}),xe=(l=>(l[l.circle=0]="circle",l[l.rect=1]="rect",l))(xe||{}),Y=(l=>(l[l.StandardStraight=1]="StandardStraight",l[l.StandardCurve=6]="StandardCurve",l[l.Curve2=2]="Curve2",l[l.Curve3=3]="Curve3",l[l.Curve5=5]="Curve5",l[l.Curve7=7]="Curve7",l[l.Curve8=8]="Curve8",l[l.SimpleOrthogonal=4]="SimpleOrthogonal",l[l.StandardOrthogonal=44]="StandardOrthogonal",l[l.HardOrthogonal=49]="HardOrthogonal",l))(Y||{}),Ke=(l=>(l.Left="left",l.Top="top",l.Right="right",l.Bottom="bottom",l))(Ke||{}),I=(l=>(l.onReady="onReady",l.onNodeClick="onNodeClick",l.onNodeExpand="onNodeExpand",l.onNodeCollapse="onNodeCollapse",l.onLineClick="onLineClick",l.onNodeDragStart="onNodeDragStart",l.onNodeDragEnd="onNodeDragEnd",l.onNodeDragging="onNodeDragging",l.onCanvasDragEnd="onCanvasDragEnd",l.onCanvasDragging="onCanvasDragging",l.onContextmenu="onContextmenu",l.onFullscreen="onFullscreen",l.onCanvasClick="onCanvasClick",l.onCanvasSelectionEnd="onCanvasSelectionEnd",l.beforeZoomStart="beforeZoomStart",l.onZoomEnd="onZoomEnd",l.onViewResize="onViewResize",l.onResizeStart="onResizeStart",l.beforeNodeResize="beforeNodeResize",l.onResizeEnd="onResizeEnd",l.onLineVertexDropped="onLineVertexDropped",l.beforeCreateLine="beforeCreateLine",l.onLineBeCreated="onLineBeCreated",l.beforeAddNodes="beforeAddNodes",l.beforeAddLines="beforeAddLines",l.onKeyboardDown="onKeyboardDown",l.onKeyboardUp="onKeyboardUp",l.onCanvasDragStart="onCanvasDragStart",l.onForceLayoutFinish="onForceLayoutFinish",l.beforeScrollStart="beforeScrollStart",l))(I||{});const Ht={key:0},$t=["data-id"],Yt={key:1},Qe=r.defineComponent({__name:"RGLineText",props:{lineConfig:{},linePathInfo:{},checked:{type:Boolean}},setup(l){const i=H(),e=r.computed(()=>{var n;return(n=l.lineConfig)==null?void 0:n.line}),t=r.computed(()=>e.value.isFakeLine?i.dataStores.textContainer4FakeLineRef.value:i.dataStores.textContainer4NormalRef.value);return(n,o)=>e.value&&t.value?(r.openBlock(),r.createElementBlock("foreignObject",Ht,[(r.openBlock(),r.createBlock(r.Teleport,{to:t.value},[r.createElementVNode("div",{class:r.normalizeClass(["rg-line-peel",e.value.className,n.checked&&"rg-line-checked",(e.value.disablePointEvent||e.value.opacity===0)&&"rg-line-disable-events",e.value.selected&&"rg-line-selected"]),"data-id":e.value.id,style:r.normalizeStyle({"--rg-line-color":e.value.color,"--rg-line-fontsize":e.value.fontSize?`${e.value.fontSize}px`:void 0,"--rg-line-opacity":e.value.opacity,"--rg-line-fontcolor":e.value.fontColor,...e.value.cssVars||{}})},[r.renderSlot(n.$slots,"default")],14,$t)],8,["to"]))])):(r.openBlock(),r.createElementBlock("g",Yt,[r.createElementVNode("text",null,"Null-text-"+r.toDisplayString(!!e.value)+"-"+r.toDisplayString(!!t.value),1)]))}}),Wt=["data-id"],Ut=["d"],Jt=["id","d"],jt={key:0},qt=["dx","dy"],Zt=["xlink:href","startOffset","text-anchor"],et=r.defineComponent({__name:"RGLinePath",props:{lineConfig:{},linePathInfo:{},useTextOnPath:{type:Boolean},checked:{type:Boolean},graphInstanceId:{}},emits:["onLineClick"],setup(l,{emit:i}){const e=H(),t=i,n=r.computed(()=>l.lineConfig.line),o=r.computed(()=>e.getArrowMarkerId(l.lineConfig.line,!0)),s=r.computed(()=>e.getArrowMarkerId(l.lineConfig.line,!1)),a=r.computed(()=>e.generateLineTextStyle4TextOnPath(l.lineConfig)),d=r.computed(()=>l.lineConfig.line.lineWidth?l.lineConfig.line.lineWidth+"px":void 0),h=r.computed(()=>l.graphInstanceId+"-"+l.lineConfig.line.id),c=f=>{t("onLineClick",f)};return(f,p)=>(r.openBlock(),r.createElementBlock("g",{class:r.normalizeClass(["rg-line-peel",n.value.className,n.value.selected&&"rg-line-selected",(n.value.disablePointEvent||n.value.opacity===0)&&"rg-line-disable-events",f.checked&&"rg-line-checked"]),"data-id":n.value.id,style:r.normalizeStyle({"--rg-line-width":d.value,"--rg-line-color":n.value.color,"--rg-line-opacity":n.value.opacity,"--rg-line-fontcolor":n.value.fontColor,"--rg-line-marker-end":s.value,"--rg-line-marker-start":o.value,...n.value.cssVars||{}})},[r.createElementVNode("path",{d:f.linePathInfo.pathData,class:"rg-line-bg",onTouchstart:c,onClick:c},null,40,Ut),r.createElementVNode("path",{id:h.value,d:f.linePathInfo.pathData,class:r.normalizeClass(["rg-line",[n.value.dashType?"rg-line-dashtype-"+n.value.dashType:void 0,n.value.animation?"rg-line-anm-"+n.value.animation:void 0]])},null,10,Jt),f.useTextOnPath&&a.value?(r.openBlock(),r.createElementBlock("g",jt,[r.createElementVNode("text",{class:"rg-line-text rg-line-text-on-path",dx:a.value.textOffset.x+"px",dy:a.value.textOffset.y+"px",onTouchstart:c,onClick:c},[r.createElementVNode("textPath",{"xlink:href":"#"+h.value,startOffset:a.value.onPathStartOffset,"text-anchor":a.value.textAnchor,method:"align",spacing:"auto"},r.toDisplayString(a.value.text),9,Zt)],40,qt)])):r.createCommentVNode("",!0),r.renderSlot(f.$slots,"default")],14,Wt))}}),tt=r.defineComponent({__name:"RGLineContent",props:{lineConfig:{},checked:{type:Boolean},defaultLineTextOnPath:{type:Boolean},graphInstanceId:{}},setup(l){const i=H(),e=r.computed(()=>i.generateLinePath(l.lineConfig)),t=r.computed(()=>i.generateLineTextStyle(l.lineConfig,e.value)),n=r.computed(()=>l.lineConfig.line.useTextOnPath||l.defaultLineTextOnPath),o=r.computed(()=>n.value&&l.lineConfig.line.lineShape!==Y.StandardStraight),s=a=>{i.onLineClick(l.lineConfig.line,a)};return(a,d)=>(r.openBlock(),r.createElementBlock(r.Fragment,null,[r.createVNode(et,{lineConfig:a.lineConfig,linePathInfo:e.value,useTextOnPath:o.value,"graph-instance-id":a.graphInstanceId,checked:a.checked,onOnLineClick:s},null,8,["lineConfig","linePathInfo","useTextOnPath","graph-instance-id","checked"]),a.lineConfig.line.text&&!o.value?(r.openBlock(),r.createBlock(Qe,{key:0,lineConfig:a.lineConfig,linePathInfo:e.value,checked:a.checked},{default:r.withCtx(()=>[r.createElementVNode("div",{class:r.normalizeClass(`rg-line-label ${n.value?"rg-line-label-on-path":""}`),style:r.normalizeStyle({...t.value.cssStyles}),onTouchstart:s,onClick:s},r.toDisplayString(t.value.text),39)]),_:1},8,["lineConfig","linePathInfo","checked"])):r.createCommentVNode("",!0)],64))}}),Kt={key:0},nt=r.defineComponent({__name:"RGLinePeel",props:{line:{},checked:{type:Boolean},defaultLineTextOnPath:{type:Boolean},graphInstanceId:{}},setup(l){const i=H(),e=r.computed(()=>l.line.isFakeLine?i.generateFakeLineConfig(l.line):i.generateLineConfig(l.line));return(t,n)=>e.value?(r.openBlock(),r.createElementBlock("g",Kt,[r.renderSlot(t.$slots,"line",{lineConfig:e.value,defaultLineTextOnPath:t.defaultLineTextOnPath,graphInstanceId:t.graphInstanceId,checked:t.checked},()=>[r.createVNode(tt,{"line-config":e.value,defaultLineTextOnPath:t.defaultLineTextOnPath,"graph-instance-id":t.graphInstanceId,checked:t.checked},null,8,["line-config","defaultLineTextOnPath","graph-instance-id","checked"])])])):r.createCommentVNode("",!0)}}),Qt={class:"rg-lines-container rg-lines-container-el-lines"},en={class:"rg-lines-svg rg-lines-svg-el-lines",xmlns:"http://www.w3.org/2000/svg"},tn=r.defineComponent({__name:"RGCanvasContent4FakeLines",props:{showEasyView:{type:Boolean},defaultLineTextOnPath:{type:Boolean},checkedLineId:{},graphInstanceId:{}},setup(l){const i=H(),e=r.computed(()=>i.getShouldRenderFakeLines(i.dataStores.shouldRenderFakeLinesRef.value));return r.onMounted(()=>{L("[RGCanvas mounted]")}),(t,n)=>(r.openBlock(),r.createElementBlock("div",Qt,[n[0]||(n[0]=r.createElementVNode("div",{class:"rg-linetext-container"},null,-1)),(r.openBlock(),r.createElementBlock("svg",en,[r.createVNode(Ze,{"for-element-lines":!0}),t.showEasyView?r.createCommentVNode("",!0):(r.openBlock(!0),r.createElementBlock(r.Fragment,{key:0},r.renderList(e.value,o=>(r.openBlock(),r.createElementBlock(r.Fragment,{key:o.id},[o.hidden!==!0?(r.openBlock(),r.createBlock(nt,{key:0,line:o,defaultLineTextOnPath:t.defaultLineTextOnPath,checked:o.id===t.checkedLineId,"graph-instance-id":t.graphInstanceId},{line:r.withCtx(s=>[r.renderSlot(t.$slots,"line",r.mergeProps({ref_for:!0},s))]),_:2},1032,["line","defaultLineTextOnPath","checked","graph-instance-id"])):r.createCommentVNode("",!0)],64))),128))]))]))}}),nn={class:"rg-lines-container rg-lines-container-el-lines"},on={class:"rg-lines-svg rg-lines-svg-el-lines",xmlns:"http://www.w3.org/2000/svg"},sn=r.defineComponent({__name:"RGCanvasContent4CreatingLine",props:{defaultLineTextOnPath:{type:Boolean},checkedLineId:{},graphInstanceId:{}},setup(l){const i=H(),e=r.computed(()=>i.generateCreatingLineConfig(i.dataStores.optionsRef.value));return r.onMounted(()=>{L("[RGCanvas mounted]")}),(t,n)=>(r.openBlock(),r.createElementBlock("div",nn,[n[0]||(n[0]=r.createElementVNode("div",{class:"rg-linetext-container"},null,-1)),(r.openBlock(),r.createElementBlock("svg",on,[r.renderSlot(t.$slots,"line",{lineConfig:e.value},()=>[r.createVNode(tt,{"line-config":e.value,defaultLineTextOnPath:t.defaultLineTextOnPath,"graph-instance-id":t.graphInstanceId},null,8,["line-config","defaultLineTextOnPath","graph-instance-id"])])]))]))}}),an={class:"rg-lines-container rg-lines-container-normal-lines"},rn={class:"rg-lines-svg",xmlns:"http://www.w3.org/2000/svg"},ln=r.defineComponent({__name:"RGCanvasContent4Lines",props:{showEasyView:{type:Boolean},defaultLineTextOnPath:{type:Boolean},checkedLineId:{},graphInstanceId:{}},setup(l){const i=H(),e=r.computed(()=>i.getShouldRenderLines(i.dataStores.shouldRenderLinesRef.value));return r.onMounted(()=>{L("[RGCanvas mounted]")}),(t,n)=>(r.openBlock(),r.createElementBlock("div",an,[n[0]||(n[0]=r.createElementVNode("div",{class:"rg-linetext-container"},null,-1)),(r.openBlock(),r.createElementBlock("svg",rn,[r.createVNode(Ze),t.showEasyView?r.createCommentVNode("",!0):(r.openBlock(!0),r.createElementBlock(r.Fragment,{key:0},r.renderList(e.value,o=>(r.openBlock(),r.createElementBlock(r.Fragment,{key:o.id},[o.hidden!==!0?(r.openBlock(),r.createBlock(nt,{key:"l-"+o.id,line:o,defaultLineTextOnPath:t.defaultLineTextOnPath,checked:o.id===t.checkedLineId,"graph-instance-id":t.graphInstanceId},{line:r.withCtx(s=>[r.renderSlot(t.$slots,"line",r.mergeProps({ref_for:!0},s))]),_:2},1032,["line","defaultLineTextOnPath","checked","graph-instance-id"])):r.createCommentVNode("",!0)],64))),128))]))]))}}),dn={class:"rg-single-graph"},cn={class:"rg-nodes-container-wrapper"},ot=r.defineComponent({__name:"RGCanvasContent",props:{showEasyView:{type:Boolean},creatingLine:{type:Boolean},defaultExpandHolderPosition:{},draggingNodeId:{},checkedNodeId:{},checkedLineId:{},graphInstanceId:{},defaultLineTextOnPath:{type:Boolean}},setup(l){return(i,e)=>(r.openBlock(),r.createElementBlock("div",dn,[r.withMemo([i.defaultLineTextOnPath,i.checkedLineId],()=>r.createVNode(ln,{showEasyView:i.showEasyView,defaultLineTextOnPath:i.defaultLineTextOnPath,"checked-line-id":i.checkedLineId,"graph-instance-id":i.graphInstanceId},{line:r.withCtx(t=>[r.renderSlot(i.$slots,"line",r.normalizeProps(r.guardReactiveProps(t)))]),_:3},8,["showEasyView","defaultLineTextOnPath","checked-line-id","graph-instance-id"]),e,0),r.createElementVNode("div",cn,[i.showEasyView?r.createCommentVNode("",!0):r.withMemo([i.draggingNodeId,i.checkedNodeId,i.defaultExpandHolderPosition],()=>(r.openBlock(),r.createBlock(At,{key:0,"default-expand-holder-position":i.defaultExpandHolderPosition,draggingNodeId:i.draggingNodeId,checkedNodeId:i.checkedNodeId},{node:r.withCtx(t=>[r.renderSlot(i.$slots,"node",r.normalizeProps(r.guardReactiveProps(t)))]),"node-expand-button":r.withCtx(t=>[r.renderSlot(i.$slots,"node-expand-button",r.normalizeProps(r.guardReactiveProps(t)))]),_:3},8,["default-expand-holder-position","draggingNodeId","checkedNodeId"])),e,1)]),r.createVNode(tn,{showEasyView:i.showEasyView,defaultLineTextOnPath:i.defaultLineTextOnPath,"checked-line-id":i.checkedLineId,"graph-instance-id":i.graphInstanceId},{line:r.withCtx(t=>[r.renderSlot(i.$slots,"line",r.normalizeProps(r.guardReactiveProps(t)))]),_:3},8,["showEasyView","defaultLineTextOnPath","checked-line-id","graph-instance-id"]),i.creatingLine?(r.openBlock(),r.createBlock(sn,{key:0,defaultLineTextOnPath:i.defaultLineTextOnPath,"checked-line-id":i.checkedLineId},{line:r.withCtx(t=>[r.renderSlot(i.$slots,"line",r.normalizeProps(r.guardReactiveProps(t)))]),_:3},8,["defaultLineTextOnPath","checked-line-id"])):r.createCommentVNode("",!0)]))}}),hn=r.defineComponent({__name:"RGEasyView",setup(l){const i=H(),e=r.ref(),t=r.computed(()=>i.dataStores.optionsRef.value);return r.onMounted(()=>{L("[RGEasyView mounted]"),i.setEasyViewCanvas&&i.setEasyViewCanvas(e.value)}),(n,o)=>(r.openBlock(),r.createElementBlock("div",{class:r.normalizeClass(["rg-easy-view",{"rg-easy-view-active":t.value.showEasyView}])},[r.createElementVNode("canvas",{ref_key:"$rgEasyCanvas",ref:e,style:{width:"100%",height:"100%"}},null,512)],2))}}),fn={class:"rg-map-background"},pn={class:"rg-canvas-slot rg-canvas-slot-behind"},un={class:"rg-canvas-slot rg-canvas-slot-above"},gn=r.defineComponent({__name:"RGCanvas",setup(l){const i=r.ref(),e=H(),t=r.computed(()=>e.dataStores.optionsRef.value),n=a=>{e.onCanvasDragStart(a)},o=a=>{e.onContextmenu(a)},s=r.computed(()=>{const a=e.dataStores.optionsRef.value;return{width:`${a.canvasSize.width}px`,height:`${a.canvasSize.height}px`,"background-color":"transparent",transform:`translate(${a.canvasOffset.x}px, ${a.canvasOffset.y}px) scale(${a.canvasZoom/100},${t.value.canvasZoom/100})`}});return r.onMounted(()=>{L("[RGCanvas mounted]"),e.setCanvasDom(i.value)}),(a,d)=>(r.openBlock(),r.createElementBlock("div",{class:r.normalizeClass(["rg-map",[t.value.canvasOpacity===1&&"rg-map-ready"]]),onContextmenu:d[0]||(d[0]=r.withModifiers(h=>o(h),["prevent"])),onMousedown:d[1]||(d[1]=r.withModifiers(h=>n(h),["left"])),onTouchstart:d[2]||(d[2]=h=>n(h))},[r.createElementVNode("div",fn,[r.renderSlot(a.$slots,"background")]),r.createElementVNode("div",{style:r.normalizeStyle(s.value),class:"rg-map-canvas rg-canvas-behind"},[r.createElementVNode("div",pn,[r.renderSlot(a.$slots,"canvas-plug-behind")])],4),r.createVNode(hn),r.createElementVNode("div",{ref_key:"rgCanvasRef",ref:i,style:r.normalizeStyle(s.value),class:"rg-map-canvas"},[r.createVNode(ot,{"show-easy-view":t.value.showEasyView,"creating-line":!!(t.value.creatingLinePlot&&t.value.newLinkTemplate.fromNode),"default-expand-holder-position":t.value.defaultExpandHolderPosition,draggingNodeId:t.value.draggingNodeId,checkedNodeId:t.value.checkedNodeId,defaultLineTextOnPath:t.value.defaultLineTextOnPath,"checked-line-id":t.value.checkedLineId,"graph-instance-id":t.value.instanceId},{line:r.withCtx(h=>[r.renderSlot(a.$slots,"line",r.normalizeProps(r.guardReactiveProps(h)))]),node:r.withCtx(h=>[r.renderSlot(a.$slots,"node",r.normalizeProps(r.guardReactiveProps(h)))]),"node-expand-button":r.withCtx(h=>[r.renderSlot(a.$slots,"node-expand-button",r.normalizeProps(r.guardReactiveProps(h)))]),_:3},8,["show-easy-view","creating-line","default-expand-holder-position","draggingNodeId","checkedNodeId","defaultLineTextOnPath","checked-line-id","graph-instance-id"])],4),r.createElementVNode("div",{style:r.normalizeStyle(s.value),class:"rg-map-canvas rg-canvas-above"},[r.createElementVNode("div",un,[r.renderSlot(a.$slots,"canvas-plug-above")])],4)],34))}}),mn=r.defineComponent({__name:"GraphMoveOperator",setup(l){const i=H(),e=r.computed(()=>i.dataStores.optionsRef.value),t=r.computed(()=>e.value.canvasMoveMode),n=o=>{i.startMoveCanvas(o,!0)};return(o,s)=>(r.openBlock(),r.createElementBlock("div",{class:r.normalizeClass(["rg-move-operator",{"rg-move-operator-active":t.value}])},[r.createElementVNode("div",{class:"rg-move-touchpad",onMousedown:n,onTouchstart:n},null,32)],2))}}),yn={class:"rg-graph-loading-message"},vn=r.defineComponent({__name:"GraphLoading",setup(l){const i=H(),e=r.computed(()=>i.dataStores.optionsRef.value),t=n=>{i.clearLoading()};return(n,o)=>(r.openBlock(),r.createElementBlock("div",{class:r.normalizeClass(["rg-graph-loading",{"rg-graph-loading-hide":!e.value.graphLoading}]),onClick:t},[r.createElementVNode("div",yn,[r.createVNode(K,{"icon-name":"icon-lianjiezhong","class-name":"rg-graph-loading-icon"}),r.createTextVNode(" "+r.toDisplayString(e.value.graphLoadingText||"Loading..."),1)])],2))}}),xn={key:0,class:"rg-operate"},Cn={class:"rg-creating-container"},it=r.defineComponent({__name:"GraphOperateStuff",setup(l){const i=H(),e=r.computed(()=>i.dataStores.optionsRef.value);return(t,n)=>e.value?(r.openBlock(),r.createElementBlock("div",xn,[r.createElementVNode("div",Cn,[e.value.creatingNodePlot&&e.value.showTemplateNode?(r.openBlock(),r.createBlock(qe,{key:0,"node-props":e.value.newNodeTemplate},{node:r.withCtx(()=>[r.renderSlot(t.$slots,"node",{node:e.value.newNodeTemplate})]),_:3},8,["node-props"])):r.createCommentVNode("",!0),e.value.creatingSelection?(r.openBlock(),r.createElementBlock("div",{key:1,class:"rg-selection",style:r.normalizeStyle({transform:`translate(${e.value.selectionView.x}px, ${e.value.selectionView.y}px)`,width:e.value.selectionView.width+"px",height:e.value.selectionView.height+"px"})},null,4)):r.createCommentVNode("",!0)]),r.createVNode(mn),r.createVNode(vn)])):r.createCommentVNode("",!0)}}),Ln=["title"],st=r.defineComponent({__name:"GraphXsToolBar",props:{direction:{},positionH:{},positionV:{}},setup(l){const i=H(),e=r.computed(()=>i.dataStores.optionsRef.value),t=()=>{i.toggleAutoLayout()},n=async()=>{i.enableCanvasAnimation(),i.setZoom(100),i.moveToCenter(),i.zoomToFit(),setTimeout(()=>{i.disableCanvasAnimation()},300)},o=async a=>{i.zoom(a)},s=async()=>{i.fullscreen()};return(a,d)=>(r.openBlock(),r.createElementBlock("div",{class:r.normalizeClass(["rg-toolbar rg-xs-toolbar",["rg-toolbar-h-"+(a.positionH||e.value.toolBarPositionH||"left"),"rg-toolbar-v-"+(a.positionV||e.value.toolBarPositionV||"bottom"),"rg-toolbar-"+(a.direction||e.value.toolBarDirection||"h")]])},[r.createElementVNode("div",{title:"Full Screen",class:"rg-mb-button",style:{"margin-top":"0px"},onClick:s},[r.createVNode(K,{"icon-name":"icon-quanping"})]),r.createElementVNode("div",{class:"rg-mb-button",onClick:d[0]||(d[0]=h=>o(20))},[r.createVNode(K,{"icon-name":"icon-fangda"})]),r.createElementVNode("div",{class:"rg-current-zoom",onClick:n},r.toDisplayString(Math.round(e.value.canvasZoom))+"%",1),r.createElementVNode("div",{class:"rg-mb-button",style:{"margin-top":"0px"},onClick:d[1]||(d[1]=h=>o(-20))},[r.createVNode(K,{"icon-name":"icon-suoxiao"})]),e.value.layout.supportAutoLayout?(r.openBlock(),r.createElementBlock("div",{key:0,title:e.value.layout.autoLayouting?"Stop Force Layout":"Start Force Layout",class:r.normalizeClass([{"rg-mb-button-on":e.value.layout.autoLayouting},"rg-mb-button"]),onClick:t},[e.value.layout.autoLayouting?(r.openBlock(),r.createBlock(K,{key:1,"icon-name":"icon-lianjiezhong","class-name":"rg-loading-icon"})):(r.openBlock(),r.createBlock(K,{key:0,"icon-name":"icon-zidong"}))],10,Ln)):r.createCommentVNode("",!0),r.renderSlot(a.$slots,"default"),d[2]||(d[2]=r.createElementVNode("div",{style:{clear:"both"}},null,-1))],2))}}),wn=["id"],_n={class:"rg-graph-plugs"},Nn={class:"rg-view-slot"},bn=r.defineComponent({__name:"RelationGraphUI",setup(l){const i=H(),e=r.ref(),t=r.computed(()=>i.dataStores.optionsRef.value),n=r.ref(!1);r.onMounted(()=>{i.setDom(e.value),n.value=!0}),r.onBeforeUnmount(()=>{i.beforeUnmount()});const o=s=>{i.onMouseWheel(s)};return r.onMounted(()=>{}),(s,a)=>{var d,h,c,f,p,m,u,g,y,v,x;return r.openBlock(),r.createElementBlock("div",{ref_key:"relationGraphRef$",ref:e,id:"relation-graph-ins-"+((d=t.value)==null?void 0:d.instanceId),tabindex:"1",class:r.normalizeClass(["relation-graph",t.value&&t.value.creatingLinePlot?"rg-creating-line":"",t.value&&t.value.dragEventAction==="move"?"rg-move-mode":"",t.value&&t.value.enableNodeXYAnimation?"rg-enable-node-xy-animation":"",t.value&&t.value.enableCanvasTransformAnimation?"rg-enable-canvas-animation":""]),style:r.normalizeStyle({width:"100%",height:(h=t.value)!=null&&h.viewHeight?(c=t.value)==null?void 0:c.viewHeight:"100%",opacity:n.value?1:0,"--rg-checked-item-bg-color":(f=t.value)==null?void 0:f.checkedItemBackgroundColor,"--rg-background-color":(p=t.value)==null?void 0:p.backgroundColor,"--rg-node-color":(m=t.value)==null?void 0:m.defaultNodeColor,"--rg-node-border-color":(u=t.value)==null?void 0:u.defaultNodeBorderColor,"--rg-node-border-width":((g=t.value)==null?void 0:g.defaultNodeBorderWidth)+"px","--rg-node-border-radius":((y=t.value)==null?void 0:y.defaultNodeBorderRadius)+"px","--rg-line-color":(v=t.value)==null?void 0:v.defaultLineColor,"--rg-line-width":((x=t.value)==null?void 0:x.defaultLineWidth)+"px"}),onWheel:o},[t.value&&n.value?(r.openBlock(),r.createElementBlock(r.Fragment,{key:0},[t.value.showToolBar?(r.openBlock(),r.createBlock(st,{key:0})):r.createCommentVNode("",!0),r.createVNode(gn,null,{node:r.withCtx(w=>[r.renderSlot(s.$slots,"node",r.normalizeProps(r.guardReactiveProps(w)))]),line:r.withCtx(w=>[r.renderSlot(s.$slots,"line",r.normalizeProps(r.guardReactiveProps(w)))]),"canvas-plug-behind":r.withCtx(()=>[r.renderSlot(s.$slots,"canvas"),r.renderSlot(s.$slots,"default")]),"canvas-plug-above":r.withCtx(()=>[r.renderSlot(s.$slots,"canvas-above")]),"node-expand-button":r.withCtx(w=>[r.renderSlot(s.$slots,"node-expand-button",r.normalizeProps(r.guardReactiveProps(w)))]),background:r.withCtx(()=>[r.renderSlot(s.$slots,"background")]),_:3}),r.createVNode(it,null,{node:r.withCtx(w=>[r.renderSlot(s.$slots,"node",r.normalizeProps(r.guardReactiveProps(w)))]),_:3}),r.createElementVNode("div",_n,[r.createElementVNode("div",Nn,[r.renderSlot(s.$slots,"view")])])],64)):r.createCommentVNode("",!0)],46,wn)}}});class kn{constructor(i){_(this,"$evCanvasCtx");_(this,"viewScale",1);_(this,"offset",{x:0,y:0});const e=i.getContext("2d");if(!e)throw new Error("\u65E0\u6CD5\u83B7\u53D6 Canvas 2D \u4E0A\u4E0B\u6587");this.$evCanvasCtx=e}setSize(i,e){const t=this.$evCanvasCtx.canvas;t.width=i*window.devicePixelRatio,t.height=e*window.devicePixelRatio,t.style.width=`${i}px`,t.style.height=`${e}px`,this.$evCanvasCtx.setTransform(window.devicePixelRatio,0,0,window.devicePixelRatio,0,0),this.applyCurrentViewTransform()}setScale(i){this.viewScale=i,this.applyCurrentViewTransform()}applyCurrentViewTransform(){this.$evCanvasCtx.setTransform(window.devicePixelRatio,0,0,window.devicePixelRatio,0,0),this.$evCanvasCtx.scale(this.viewScale,this.viewScale)}setViewOffset(i,e){this.offset.x=i/this.viewScale,this.offset.y=e/this.viewScale}beforeDraw(){}evDrawNode4Rect(i,e,t,n,o,s,a=5,d){const h=this.$evCanvasCtx,c=this.offset.x+i,f=this.offset.y+e;let p=Math.max(0,a);t<2*p&&(p=t/2),n<2*p&&(p=n/2),h.beginPath(),h.globalAlpha=s,p===0?h.rect(c,f,t,n):(h.moveTo(c+p,f),h.arcTo(c+t,f,c+t,f+p,p),h.arcTo(c+t,f+n,c+t-p,f+n,p),h.arcTo(c,f+n,c,f+n-p,p),h.arcTo(c,f,c+p,f,p),h.closePath()),h.fillStyle=o,h.fill(),h.globalAlpha=1,h.strokeStyle=d,h.lineWidth=1,h.stroke()}evDrawNode4Circle(i,e,t,n,o,s,a){const d=this.$evCanvasCtx,h=this.offset.x+i+t/2,c=this.offset.y+e+n/2;d.beginPath(),d.globalAlpha=s,d.ellipse(h,c,t/2,n/2,0,0,2*Math.PI),d.fillStyle=o,d.fill(),d.strokeStyle=a,d.lineWidth=1,d.stroke(),d.globalAlpha=1}evDrawLine(i,e,t,n){const o=this.$evCanvasCtx;o.beginPath(),o.globalAlpha=n,this.evDrawSvgPathOnCanvas(o,i),o.strokeStyle=t,o.lineWidth=e*this.viewScale<.5?.5:e,o.stroke(),o.globalAlpha=1}getPointValue(i,e,t){return t?i+parseFloat(e):parseFloat(e)}evDrawSvgPathOnCanvas(i,e){const t=e.match(/[a-zA-Z][^a-zA-Z]*/g);if(!t)return;let n=0,o=0,s=0,a=0,d=0,h=0,c=0,f=0,p="";i.beginPath(),t.forEach(m=>{const u=m.trim(),g=u.charAt(0),v=u.substring(1).trim().split(/[ ,]+/).filter(C=>C!=="").map(parseFloat);let x=0,w=0,k=0,T=0,O=0,b=0,N=0,P=0,R=0,S=0,M=0;switch(g){case"M":n=v[0],o=v[1],s=n,a=o,i.moveTo(n+this.offset.x,o+this.offset.y);for(let C=2;C<v.length;C+=2)n=v[C],o=v[C+1],i.lineTo(n+this.offset.x,o+this.offset.y);break;case"L":for(let C=0;C<v.length;C+=2)n=v[C],o=v[C+1],i.lineTo(n+this.offset.x,o+this.offset.y);break;case"l":for(let C=0;C<v.length;C+=2)n+=v[C],o+=v[C+1],i.lineTo(n+this.offset.x,o+this.offset.y);break;case"H":for(let C=0;C<v.length;C++)n=v[C],i.lineTo(n+this.offset.x,o+this.offset.y);break;case"h":for(let C=0;C<v.length;C++)n+=v[C],i.lineTo(n+this.offset.x,o+this.offset.y);break;case"V":for(let C=0;C<v.length;C++)o=v[C],i.lineTo(n+this.offset.x,o+this.offset.y);break;case"v":for(let C=0;C<v.length;C++)o+=v[C],i.lineTo(n+this.offset.x,o+this.offset.y);break;case"C":for(let C=0;C<v.length;C+=6)k=v[C],T=v[C+1],O=v[C+2],b=v[C+3],x=v[C+4],w=v[C+5],i.bezierCurveTo(k+this.offset.x,T+this.offset.y,O+this.offset.x,b+this.offset.y,x+this.offset.x,w+this.offset.y),n=x,o=w,d=O,h=b;break;case"c":for(let C=0;C<v.length;C+=6)k=n+v[C],T=o+v[C+1],O=n+v[C+2],b=o+v[C+3],x=n+v[C+4],w=o+v[C+5],i.bezierCurveTo(k+this.offset.x,T+this.offset.y,O+this.offset.x,b+this.offset.y,x+this.offset.x,w+this.offset.y),d=O,h=b,n=x,o=w;break;case"S":for(let C=0;C<v.length;C+=4)p.match(/[CS]/i)?(k=2*n-d,T=2*o-h):(k=n,T=o),O=v[C],b=v[C+1],x=v[C+2],w=v[C+3],i.bezierCurveTo(k+this.offset.x,T+this.offset.y,O+this.offset.x,b+this.offset.y,x+this.offset.x,w+this.offset.y),n=x,o=w,d=O,h=b;break;case"s":for(let C=0;C<v.length;C+=4)p.match(/[CS]/i)?(k=2*n-d,T=2*o-h):(k=n,T=o),O=n+v[C],b=o+v[C+1],x=n+v[C+2],w=o+v[C+3],i.bezierCurveTo(k+this.offset.x,T+this.offset.y,O+this.offset.x,b+this.offset.y,x+this.offset.x,w+this.offset.y),d=O,h=b,n=x,o=w;break;case"Q":for(let C=0;C<v.length;C+=4)k=v[C],T=v[C+1],x=v[C+2],w=v[C+3],i.quadraticCurveTo(k+this.offset.x,T+this.offset.y,x+this.offset.x,w+this.offset.y),n=x,o=w,c=k,f=T;break;case"q":for(let C=0;C<v.length;C+=4)k=n+v[C],T=o+v[C+1],x=n+v[C+2],w=o+v[C+3],i.quadraticCurveTo(k+this.offset.x,T+this.offset.y,x+this.offset.x,w+this.offset.y),c=k,f=T,n=x,o=w;break;case"T":for(let C=0;C<v.length;C+=2)p.match(/[QT]/i)?(k=2*n-c,T=2*o-f):(k=n,T=o),x=v[C],w=v[C+1],i.quadraticCurveTo(k+this.offset.x,T+this.offset.y,x+this.offset.x,w+this.offset.y),n=x,o=w,c=k,f=T;break;case"t":for(let C=0;C<v.length;C+=2)p.match(/[QT]/i)?(k=2*n-c,T=2*o-f):(k=n,T=o),x=n+v[C],w=o+v[C+1],i.quadraticCurveTo(k+this.offset.x,T+this.offset.y,x+this.offset.x,w+this.offset.y),c=k,f=T,n=x,o=w;break;case"A":for(let C=0;C<v.length;C+=7)N=v[C],P=v[C+1],R=v[C+2],S=v[C+3],M=v[C+4],x=v[C+5],w=v[C+6],this.drawArc(i,n,o,N,P,R,S,M,x,w),n=x,o=w;break;case"a":for(let C=0;C<v.length;C+=7)N=v[C],P=v[C+1],R=v[C+2],S=v[C+3],M=v[C+4],x=n+v[C+5],w=o+v[C+6],this.drawArc(i,n,o,N,P,R,S,M,x,w),n=x,o=w;break;case"Z":case"z":i.closePath(),n=s,o=a;break;default:console.warn(`\u672A\u652F\u6301\u7684SVG\u547D\u4EE4\u5B57\u7B26: ${g}`)}g.match(/[CSQT]/i)?p=g:p=""})}drawArc(i,e,t,n,o,s,a,d,h,c){if(n=Math.abs(n),o=Math.abs(o),n===0||o===0){i.lineTo(h+this.offset.x,c+this.offset.y);return}const f=s%360*Math.PI/180,p=Math.sin(f),m=Math.cos(f),u=m*(e-h)/2+p*(t-c)/2,g=-p*(e-h)/2+m*(t-c)/2,y=u*u/(n*n)+g*g/(o*o);y>1&&(n*=Math.sqrt(y),o*=Math.sqrt(y));let v=(a===d?-1:1)*Math.sqrt(Math.max(0,(n*n*o*o-n*n*g*g-o*o*u*u)/(n*n*g*g+o*o*u*u)));isNaN(v)&&(v=0);const x=v*n*g/o,w=v*-o*u/n,k=m*x-p*w+(e+h)/2,T=p*x+m*w+(t+c)/2,O=(u-x)/n,b=(g-w)/o,N=(-u-x)/n,P=(-g-w)/o;let R=Math.atan2(b,O),S=Math.atan2(b*N-O*P,O*N+b*P);d===0&&S>0?S-=2*Math.PI:d===1&&S<0&&(S+=2*Math.PI);const M=R+S;i.ellipse?i.ellipse(k+this.offset.x,T+this.offset.y,n,o,f,R,M,d===0):(console.warn("ctx.ellipse is not supported. Arc will be drawn as a line."),i.lineTo(h+this.offset.x,c+this.offset.y))}}const z={getDescendantNodes(l,i=[]){return l.lot&&l.lot.childs&&l.lot.childs.forEach(e=>{i.push(e),z.getDescendantNodes(e,i)}),i},isVisibleNode(l,i=0){return typeof i!="number"&&(i=0),i>18?!0:l.hidden?!1:l.lot&&l.lot.parent?l.lot.parent.expanded===!1?!1:z.isVisibleNode(l.lot.parent,i+1):!0},isAllowShowNode(l,i=0){return z.isVisibleNode(l,i=0)},getNodeWidth(l){return l.el_W||l.width||50},getNodeHeight(l){return l.el_H||l.height||50},getNodeXByLotX(l,i){const e=i.lot.x||0;return l.alignItemsX==="end"?e-z.getNodeWidth(i):l.alignItemsX==="start"?e:e-z.getNodeWidth(i)/2},getNodeYByLotY(l,i){const e=i.lot.y||0;return l.alignItemsY==="end"?e-z.getNodeHeight(i):l.alignItemsY==="start"?e:e-z.getNodeHeight(i)/2},getNodeLotXY(l,i){let e=i.x||0,t=i.y||0;return l.alignItemsX==="end"?e=e+z.getNodeWidth(i):l.alignItemsX==="start"||(e=e+z.getNodeWidth(i)/2),l.alignItemsY==="end"?t=t+z.getNodeHeight(i):l.alignItemsY==="start"||(t=t+z.getNodeHeight(i)/2),{x:e,y:t}},isRectangleOverlap(l,i){const e=l.x,t=i.x,n=l.el_W,o=i.el_W,s=l.y,a=i.y,d=l.el_H,h=i.el_H;return!(t>=e+n||t+o<=e||a>=s+d||a+h<=s)},isXOverlap(l,i,e,t){return!(i>=l+e||i+t<=l)},isYOverlap(l,i,e,t){return!(i>=l+e||i+t<=l)},shapesOverlap(l,i,e=1,t=1){return this.isRectangleOverlap(l,i)},getNoOverlapLimitedPosition(l,i,e,t){const n=l.x,o=l.y,s=i,a=t.x,d=l.el_W,h=t.el_W,c=e,f=t.y,p=l.el_H,m=t.el_H;let u=l.x,g=l.y;const y=this.isXOverlap(n,a,d,h),v=this.isYOverlap(o,f,p,m);return y?c<f?(u=i,g=f-p):c>f&&(u=i,g=f+m):v&&(s<a?(u=a-d,g=e):s>a&&(u=a+h,g=e)),{x:u,y:g}},flatNodeData(l,i,e,t){l.forEach(n=>{e.push(n),i&&t.push({from:i.id,to:n.id});const o=n.children||n.childs;o&&o.length>0&&this.flatNodeData(o,n,e,t)})}},Ce=(l,i)=>l||l===0?l:i,Le=z,De={id:"rg-newNodeTemplate",x:0,y:0,text:""},we=(l,i,e)=>{if(l.id===void 0)throw console.log("node must has id:",l),new Error("node must has option[id]:");l.isShow!==void 0&&(l.hidden=!l.isShow,console.warn("[relation-graph Warning] line option[isShow] is deprecated, please use [hidden] instead.")),l.isHide!==void 0&&(l.hidden=l.isHide,console.warn("[relation-graph Warning] line option[isHide] is deprecated, please use [hidden] instead."));const t=l.width||l.width===0?l.width:i==null?void 0:i.defaultNodeWidth,n=l.height||l.height===0?l.height:i==null?void 0:i.defaultNodeHeight,o={id:l.id,text:l.text!==void 0?l.text:"",type:l.type!==void 0?l.type:"",targetType:l.targetType!==void 0?l.targetType:D.Node,expanded:l.expanded!==void 0?l.expanded:!0,selected:l.selected!==void 0?l.selected:!1,className:l.className!==void 0?l.className:"",nodeShape:Ce(l.nodeShape,i==null?void 0:i.defaultNodeShape),borderWidth:l.borderWidth!==void 0?l.borderWidth:void 0,borderRadius:l.borderRadius!==void 0?l.borderRadius:void 0,borderColor:l.borderColor!==void 0?l.borderColor:void 0,fontColor:l.fontColor!==void 0?l.fontColor:void 0,fontSize:l.fontSize!==void 0?l.fontSize:void 0,color:l.color!==void 0?l.color:void 0,opacity:l.opacity!==void 0?l.opacity:void 0,fixed:l.fixed!==void 0?l.fixed:!1,width:t,height:n,force_weight:l.force_weight,x:l.x!==void 0?l.x:0,y:l.y!==void 0?l.y:0,expandHolderPosition:l.expandHolderPosition!==void 0?l.expandHolderPosition:void 0,disablePointEvent:l.disablePointEvent!==void 0?l.disablePointEvent:void 0,disableDrag:l.disableDrag!==void 0?l.disableDrag:!1,hidden:l.hidden!==void 0?l.hidden:!1,rgCalcedVisibility:!0,rgShouldRender:!0,rgChildrenSize:0,zIndex:l.zIndex||0,el_W:l.el_W||t||0,el_H:l.el_H||n||0,data:l.data!==void 0?l.data:{}};if(e&&e.has&&e.has(o.id)){const s=e.get(o.id);o.el_W||s&&(o.el_W=s[0]),o.el_H||s&&(o.el_H=s[1])}return o.lot={childs:[],parent:void 0,eached:!1,strength:0},o.width&&(o.el_W=o.width),o.height&&(o.el_H=o.height),o},On=["Fx","Fy","appended","dragging","el","el_W","el_H","targetFrom","targetNodes","targetTo","lot","seeks_id","shouldRender","rgCalcedVisibility","rgShouldRender","rgChildrenSize","origin_x","origin_y","selected"],Te=l=>{if(!l)return;const i={};return Object.keys(l).forEach(e=>{if(!On.includes(e)){const t=l[e];t!==void 0&&(e==="offset_x"&&t===0||e==="nodeShape"&&t===1||e==="offset_y"&&t===0||e==="zIndex"&&t===0||e==="width"&&!t||e==="height"&&!t||e==="fixed"&&t===!1||e==="className"&&t===""||e==="hidden"&&t===!1||e==="disableDrag"&&t===!1||e==="expanded"&&t===!0||e==="opacity"&&t===1||e==="type"&&t==="node"||e==="targetType"&&t===D.Node||e==="data"&&(!t||Object.keys(t).length===0)||(i[e]=t))}}),i},Pn=Object.freeze(Object.defineProperty({__proto__:null,newNodeTemplate:De,json2Node:we,transNodeToJson:Te,default:{json2Node:we,transNodeToJson:Te}},Symbol.toStringTag,{value:"Module"}));let _e={x:0,y:0};const Ne={x:0,y:0},se={x:0,y:0},at={passive:!1};let Ve,Be;const Ae=l=>ce(l),ee={startDrag(l,i,e,t){t?Ve=(n,o,s)=>{const a=n-se.x,d=o-se.y;t(a,d,Ne,se,s)}:Ve=(n,o)=>{_e.x=Ne.x+(n-se.x),_e.y=Ne.y+(o-se.y)},Be=e,_e=i,Ne.x=_e.x,Ne.y=_e.y;try{const n=Ae(l);se.x=n.clientX,se.y=n.clientY,de(l)?(document.body.addEventListener("touchmove",ee.onNodeMove,at),document.body.addEventListener("touchend",ee.onNodeDragend),document.body.addEventListener("mousemove",ee.onNodeMove),document.body.addEventListener("mouseup",ee.onNodeDragend),l.preventDefault()):(document.body.addEventListener("mousemove",ee.onNodeMove),document.body.addEventListener("mouseup",ee.onNodeDragend))}catch(n){console.error(n.message)}},onNodeMove(l){const i=Ae(l);Ve(i.clientX,i.clientY,l)},onNodeDragend(l){if(de(l)?(document.body.removeEventListener("touchmove",ee.onNodeMove,at),document.body.removeEventListener("touchend",ee.onNodeDragend),document.body.removeEventListener("mousemove",ee.onNodeMove),document.body.removeEventListener("mouseup",ee.onNodeDragend)):(document.body.removeEventListener("mousemove",ee.onNodeMove),document.body.removeEventListener("mouseup",ee.onNodeDragend)),Be){const i=Ae(l),e=i.clientX,t=i.clientY,n=e-se.x,o=t-se.y;Be(n,o,l)}}},le=ee,he=(l,i)=>{if(l.from===void 0)throw console.log("error,line must has option[from](nodeId):",l),new Error("error,line must has option[from]:");if(l.to===void 0)throw console.log("error,line must has option[to](nodeId):",l),new Error("error,line must has option[to]:");if(typeof l.from!="string")throw console.log("error line from, must be string(nodeId):",l),new TypeError("error line from, must be string:");if(typeof l.to!="string")throw console.log("error line to, must be string(nodeId):",l),new TypeError("error line to, must be string:");return l.hidden===void 0&&l.isShow!==void 0&&(l.hidden=!l.isShow,console.warn("[relation-graph Warning] line option[isShow] is deprecated, please use [hidden] instead.")),l.hidden===void 0&&l.isHide!==void 0&&(l.hidden=l.isHide,console.warn("[relation-graph Warning] line option[isHide] is deprecated, please use [hidden] instead.")),{id:l.id,from:l.from,to:l.to,type:l.type!==void 0?l.type:"",isFakeLine:l.isFakeLine!==void 0?l.isFakeLine:!1,fromType:l.fromType!==void 0?l.fromType:l.isFakeLine?D.CanvasPoint:D.Node,toType:l.toType!==void 0?l.toType:l.isFakeLine?D.CanvasPoint:D.Node,selected:!1,text:l.text!==void 0?l.text:"",textOffsetX:l.textOffsetX!==void 0?l.textOffsetX:void 0,textOffsetY:l.textOffsetY!==void 0?l.textOffsetY:void 0,color:l.color!==void 0?l.color:void 0,opacity:l.opacity!==void 0?l.opacity:void 0,fontSize:l.fontSize!==void 0?l.fontSize:void 0,fontColor:l.fontColor!==void 0?l.fontColor:void 0,lineWidth:l.lineWidth!==void 0?l.lineWidth:void 0,lineShape:l.lineShape||i.defaultLineShape||1,className:l.className!==void 0?l.className:void 0,animation:l.animation!==void 0?l.animation:0,dashType:l.dashType!==void 0?l.dashType:0,disablePointEvent:l.disablePointEvent!==void 0?l.disablePointEvent:!1,showStartArrow:l.showStartArrow!==void 0?l.showStartArrow:!1,showEndArrow:l.showEndArrow!==void 0?l.showEndArrow:!0,useTextOnPath:l.useTextOnPath!==void 0?l.useTextOnPath:void 0,placeText:l.placeText!==void 0?l.placeText:void 0,startMarkerId:l.startMarkerId||"",endMarkerId:l.endMarkerId||"",textAnchor:l.textAnchor!==void 0?l.textAnchor:void 0,junctionOffset:l.junctionOffset,fromJunctionPoint:l.fromJunctionPoint,toJunctionPoint:l.toJunctionPoint,fromJunctionPointOffsetX:l.fromJunctionPointOffsetX||0,fromJunctionPointOffsetY:l.fromJunctionPointOffsetY||0,toJunctionPointOffsetX:l.toJunctionPointOffsetX||0,toJunctionPointOffsetY:l.toJunctionPointOffsetY||0,lineRadius:l.lineRadius,force_elastic:l.force_elastic,polyLineStartDistance:l.polyLineStartDistance,ctrlPointsFor49:l.ctrlPointsFor49,ctrlPointsFor44:l.ctrlPointsFor44,ctrlPoints:l.ctrlPoints,lineDirection:l.lineDirection!==void 0?l.lineDirection:void 0,forDisplayOnly:l.forDisplayOnly||l.from===l.to,hidden:l.hidden!==void 0?l.hidden:!1,cssVars:l.cssVars!==void 0?l.cssVars:void 0,data:l.data!==void 0?l.data:{}}},Tn=["arrow","isReverse","selected","shouldRender","rgCalcedVisibility"],be=l=>{if(!l)return;const i={};return Object.keys(l).forEach(e=>{if(!Tn.includes(e)){const t=l[e];t!==void 0&&(e==="isFakeLine"&&t===!1||e==="fromType"&&t===D.Node||e==="toType"&&t===D.Node||e==="animation"&&t===0||e==="text"&&t===""||e==="dashType"&&t===0||e==="disablePointEvent"&&t===!1||e==="showStartArrow"&&t===!1||e==="showEndArrow"&&t===!0||e==="startMarkerId"&&t===""||e==="endMarkerId"&&t===""||e==="forDisplayOnly"&&t===!1||e==="fromJunctionPointOffsetX"&&t===0||e==="fromJunctionPointOffsetY"&&t===0||e==="toJunctionPointOffsetX"&&t===0||e==="toJunctionPointOffsetY"&&t===0||e==="opacity"&&t===1||e==="hidden"&&t===!1||e==="data"&&(!t||Object.keys(t).length===0)||(i[e]=l[e]))}}),i},ze=l=>{if(!!l)return be(l.line)},Sn=Object.freeze(Object.defineProperty({__proto__:null,json2Line:he,transLineToJson:be,transLinkToJson:ze,default:{json2Line:he,transLinkToJson:ze}},Symbol.toStringTag,{value:"Module"}));function Rn(l,i,e,t,n,o,s,a,d){const h=n-l,c=o-i,f=Math.sqrt(h*h+c*c);if(f===0)return{x:l,y:i};const p=d*c/f,m=-(d*h)/f,u=l+p,g=i+m,y=l-e/2,v=l+e/2,x=i-t/2,w=i+t/2;let k=[];if(h!==0){let b=(y-u)/h,N=g+b*c;N>=x&&N<=w&&k.push({x:y,y:N});let P=(v-u)/h,R=g+P*c;R>=x&&R<=w&&k.push({x:v,y:R})}if(c!==0){let b=(x-g)/c,N=u+b*h;N>=y&&N<=v&&k.push({x:N,y:x});let P=(w-g)/c,R=u+P*h;R>=y&&R<=v&&k.push({x:R,y:w})}if(k.length===0&&h===0&&c===0)return{x:u,y:g};let T=null,O=1/0;return k.forEach(b=>{const N=Math.sqrt((b.x-n)**2+(b.y-o)**2);N<O&&(O=N,T=b)}),T}const Mn={getRectPoint(l,i,e,t,n,o,s,a,d=!1,h=1,c=0,f=14,p=!1){const m=l+n/2,u=i+o/2,g=e+s/2,y=t+a/2;if(h>1){const P=Math.min(f,n,o),R=-P/2,S=P/(h-1),M=d&&p||!d&&!p?R*-1-c*S:R+c*S,C=Rn(m,u,n,o,g,y,s,a,M);if(C)return C}const v=m<g?1:-1,x=u<y?1:-1;if(y===u)return{x:m+v*n/2,y:u};const w=Math.abs((g-m)/(y-u)),k=n/o;let T=0,O=0;w<k?(T=v*o/2*w,O=x*o/2):(T=v*n/2,O=x*n/2/w);const b=m+T,N=u+O;return{x:b,y:N}},getRectPointBasic(l,i,e,t,n,o,s,a){const d=l+n/2,h=i+o/2,c=e+s/2,f=t+a/2;let p=f===h?0:(c-d)/(f-h);p===0&&f===h&&c===d?p=1:p===0&&(p=(c-d)/(f-h+(f>h?-1:1)*1e-4));const m=n/o;let u=0,g=0,y="1";return Math.abs(p)<m?(y="2",h<=f?(g=o/2,u=g*p):(g=-o/2,u=g*p)):(y="3",d<=c?(u=n/2,g=p===0&&c===d?0:u/p):(u=-n/2,g=p===0&&c===d?0:u/p)),{x:d+u,y:h+g,_case:y}},getRectJoinPoint(l){const{from_x:i,from_y:e,to_x:t,to_y:n,f_W:o,f_H:s,t_W:a,t_H:d}=l,h=i+o/2,c=e+s/2,f=t+a/2,p=n+d/2,m=f-h,u=p-c,g=m/(o/2),y=u/(s/2);return Math.abs(g)>Math.abs(y)?g>0?{x:i+o,y:c}:{x:i,y:c}:y>0?{x:h,y:e+s}:{x:h,y:e}},getRectHJoinPoint(l){const{from_x:i,from_y:e,to_x:t,f_W:n,f_H:o,t_W:s}=l,a=o/2;return i+n<t?{x:i+n,y:e+a}:{x:i,y:e+a}},getRectLeftJoinPoint(l){const{from_x:i,from_y:e,f_H:t}=l;return{x:i,y:e+t/2}},getRectRightJoinPoint(l){const{from_x:i,from_y:e,f_W:t,f_H:n}=l;return{x:i+t,y:e+n/2}},getRectTopJoinPoint(l){const{from_x:i,from_y:e,f_W:t}=l;return{x:i+t/2,y:e}},getRectBottomJoinPoint(l){const{from_x:i,from_y:e,f_W:t,f_H:n}=l;return{x:i+t/2,y:e+n}},getRectHorizontalLineJoinPoint(l){return this.getRectVJoinPoint(l)},getRectVerticalLineLineJoinPoint(l){return this.getRectHJoinPoint(l)},getRectVJoinPoint(l){const{from_x:i,from_y:e,to_y:t,f_W:n,f_H:o,t_H:s}=l,a=n/2;return e+o<t?{y:e+o,x:i+a}:{y:e,x:i+a}},getBorderPoint(l,i,e,t,n,o,s,a,d){return d===0?this.getCirclePoint(l,i,e,t,n,o,s,a):this.getRectPoint(l,i,e,t,n,o,s,a)},getBorderPoint4MultiLine(l){const{from_x:i,from_y:e,to_x:t,to_y:n,f_W:o,f_H:s,t_W:a,t_H:d,nodeShape:h,isReverse:c=!1,isEndPoint:f,totalLinesBetweenNodes:p=1,currentLineIndex:m=0,lineDistance:u=50}=l;return h===0?this.getCirclePoint4MultiLine(i,e,t,n,o,s,a,d,c,p,m,u,f):this.getRectPoint(i,e,t,n,o,s,a,d,c,p,m,u,f)},getCirclePoint(l,i,e,t,n,o,s,a){const d=e+s/2,h=t+a/2,c=l+n/2,f=i+o/2,p=d-c;if(p===0)return{x:c,y:f-o/2*(h<f?1:-1)};const u=(h-f)/p,g=Math.sqrt(1/(1/(n/2)**2+u**2/(o/2)**2))*(d<c?1:-1),y=u*g;return{x:c-g,y:f-y}},getCirclePoint4MultiLine(l,i,e,t,n,o,s,a,d,h,c,f,p){let m=e+s/2;const u=t+a/2;let g=l+n/2;const y=i+o/2;let v=m-g;v>-1&&v<1&&(m=m-.5,g=g+.5,v=-1);let w=0;if(h>1){const M=Math.min(f,n,o),C=-M/2,E=M/(h-1);w=d&&p||!d&&!p?C*-1-c*E:C+c*E}const k=u-y,T=Math.sqrt(v**2+k**2)*w/v,O=k/v,b=n/2,N=o/2,P=g<m?-1:1,R=(-1*b**2*O*T+b*N*Math.sqrt(Math.abs(N**2+O**2*b**2-T**2))/P)/(N**2+b**2*O**2),S=O*R+T;return{x:g-R,y:y-S}},getCirclePointBasic(l,i,e,t,n,o,s,a,d){const h=l+n/2,c=i+o/2,f=e+s/2,p=t+a/2,m=f-h,u=p-c,g=Math.sqrt(m*m+u*u),y=g-d,v=y*m/g*-1,x=y*u/g*-1;return{x:f+v,y:p+x}},getCirclePointPlus(l,i,e,t,n,o,s,a){const d=l+n/2,h=i+o/2,c=e+s/2,f=t+a/2,p=c-d,m=f-h,u=Math.sqrt(p*p+m*m),g=(u-n/2)*p/u*-1,y=(u-o/2)*m/u*-1;return{x:c+g,y:f+y}},getOvalPoint(l,i,e,t,n,o=180){const s=t*(360/n),a=(180-o+s)*Math.PI/180;return{x:l+e*Math.sin(a),y:i+e*Math.cos(a)*-1}},getRotatedPoint(l,i,e,t,n){const o=n*Math.PI/180,s=Math.cos(o),a=Math.sin(o),d=(l-e)*s-(i-t)*a+e,h=(l-e)*a+(i-t)*s+t;return{x:d,y:h}},getFlippedX(l,i){return i-(l-i)},getFlippedY(l,i){return i-(l-i)},getAngleType(l,i){if(l>=0&&i>=0)return 1;if(l<0&&i>=0)return 2;if(l<0&&i<0)return 3;if(l>=0&&i<0)return 4},getTextAngle(l,i,e,t){let n=Math.atan2(t-i,e-l)*180/Math.PI;return n<0&&(n+=360),n>90&&n<=270&&(n+=180),n>=360&&(n-=360),Math.round(n)}},me=(l,i,e,t)=>{const n=l-e,o=i-t;return Math.sqrt(n**2+o**2)};function rt(l,i,e,t,n=0,o=0){let s=1,a=n,d=o,h=0;for(let c of e){const f=c.width,p=c.height;p>h&&(h=p),t(c,a,d),a+=f+i,s>l?(d+=h+i,s=1,a=0,h=0):s++}}const j=Mn;class En{constructor(i){_(this,"graphInstance");_(this,"initialized",!1);_(this,"isFolderLayout",!1);this.graphInstance=i}analyzeNetwork(i,e,t=!1,n=!1){this.initialized||(this.initialized=!0),i.forEach(u=>{u.lot||(u.lot={}),u.lot.eached=!1,u.lot.index_of_level=0,u.lot.index_of_p_childs=0,u.lot.index_of_parent=0,u.lot.strength=0,u.lot.strengthWithChilds_from=0,u.lot.strengthWithChilds=0,u.lot.childrenSizeVisible=0,u.lot.childrenSize=0,u.lot.childs=[],u.lot.subling=void 0,u.lot.parent=void 0}),e.lot.parent=void 0;const o=this.markNodeParent(e);L("groupNodes:marked-tree-node:",o.networkNodes.length);const s=[],a={direct:1,min_deep:0,max_deep:0,max_length:1,max_strength:1,levels:new Map},d={direct:-1,min_deep:0,max_deep:0,max_length:1,max_strength:1,levels:new Map},h=[e];this.expandLevelNodesWithDirection(s,h,0,t,n,a,d),this.calcStrengthWithChildsValue(s),this.calcStrengthFromValue(e,1),t&&this.calcStrengthFromValue(e,-1);const c=s.filter(u=>u.lot.level===1),f=c.length===0?1:c.map(u=>u.lot.strengthWithChilds).reduce((u,g)=>u+g,0);a.max_strength=f;const p=s.filter(u=>u.lot.level>=0);L("groupNodes:tree-nodes:",p.length,a);const m={tree:{networkNodes:p,analyticResult:a},reverseTree:{networkNodes:[],analyticResult:d}};if(t){const u=s.filter(v=>v.lot.level===-1),g=u.length===0?1:u.map(v=>v.lot.strengthWithChilds).reduce((v,x)=>v+x,0);d.max_strength=g;const y=s.filter(v=>v.lot.level<=0);L("groupNodes:reverse-tree-nodes:",y.length,d),m.reverseTree.networkNodes=y}for(const u of i)this.graphInstance.updateNode(u,{rgChildrenSize:u.lot.childrenSize});return m}markNodeParent(i){let e=[];return this._markNodeParent(e,[i],0),{networkNodes:e}}_markNodeParent(i,e,t){t===0&&e.forEach(o=>{o.lot.parent=void 0});const n=[];for(const o of e){i.includes(o)||i.push(o);for(const s of this.graphInstance.getNodeRelatedNodes(o))i.includes(s)||(i.push(s),s.lot.parent=o,n.push(s))}n.length>0&&this._markNodeParent(i,n,t+1)}expandLevelNodesWithDirection(i,e,t,n,o,s,a){const d=n&&t<0?a:s;L(`bothWay:${n}(deep:${o}) level ${t} size: ${e.length}`,d.direct),e.length>d.max_length&&(d.max_length=e.length),t>d.max_deep&&(d.max_deep=t),t<d.min_deep&&(d.min_deep=t),d.levels.has(t)||d.levels.set(t,{level:t,all_size:e.length,all_strength:0});const h=d.levels.get(t);e.forEach(u=>{u.lot.eached=!0,u.lot.subling=h,u.lot.level=t,i.push(u)});const c=[],f=[];let p=1,m=0;e.forEach(u=>{let g=[],y=[];n?o||t===0?(g=this.graphInstance.getNodeIncomingNodes(u),y=this.graphInstance.getNodeOutgoingNodes(u)):(t<0&&(p=-1),y=this.graphInstance.getNodeRelatedNodes(u)):y=this.graphInstance.getNodeRelatedNodes(u),this._appendNodeChildrenToNextLevelNodes(u,y,f,h,n,1),this._appendNodeChildrenToNextLevelNodes(u,g,c,h,n,-1),u.lot.index_of_level=m,m++}),h.all_strength>d.max_strength&&(d.max_strength=h.all_strength),f.length>0&&this.expandLevelNodesWithDirection(i,f,t+p,n,o,s,a),c.length>0&&this.expandLevelNodesWithDirection(i,c,t-1,n,o,s,a)}_appendNodeChildrenToNextLevelNodes(i,e,t,n,o,s){let a=0,d=0,h=0;if(e.forEach(c=>{c.lot||(c.lot={eached:!1,childs:[]}),c.lot.eached||(d++,c.lot.parent=i,z.isVisibleNode(c)&&(c.lot.eached=!0,c.lot.index_of_parent=h++,t.push(c),a++),i.lot.childs.push(c))}),s===1){const c=a>0?a:1;i.lot.strength=c,n.all_strength+=c,i.lot.strength_of_level=n.all_strength,i.lot.childrenSizeVisible=a,i.lot.childrenSize=d}}calcStrengthWithChildsValue(i){this.isFolderLayout?i.forEach(e=>{e.lot.strengthWithChilds=1,this.conductStrengthToParents(e)}):(i.forEach(e=>{e.lot.childrenSizeVisible>0&&(e.lot.strengthWithChilds=0)}),i.forEach(e=>{e.lot.childrenSizeVisible===0&&(e.lot.strengthWithChilds=1,this.conductStrengthToParents(e))}))}calcStrengthFromValue(i,e=1){this._calcStrengthFromValue([i],0,e===-1?-1:1)}_calcStrengthFromValue(i,e,t=1){const n=[];let o=0;i.forEach(s=>{if(s.lot.level===0||t===(s.lot.level<0?-1:1)){s.lot.childs.forEach(d=>{n.push(d)}),s.lot.parent&&o<s.lot.parent.lot.strengthWithChilds_from&&(o=s.lot.parent.lot.strengthWithChilds_from);const a=this.isFolderLayout?1:0;s.lot.strengthWithChilds_from=o+a,o+=s.lot.strengthWithChilds}}),n.length>0&&this._calcStrengthFromValue(n,e+(t<0?-1:1),t)}conductStrengthToParents(i){if(i.lot.parent){const e=Math.abs(i.lot.level)-1===Math.abs(i.lot.parent.lot.level);(this.isFolderLayout||e)&&(i.lot.parent.lot.strengthWithChilds+=1,this.conductStrengthToParents(i.lot.parent))}}}class In{constructor(i,e,t){_(this,"graphOptions");_(this,"layoutOptions");_(this,"graphInstance");_(this,"networkAnalyzer");_(this,"allNodes",[]);_(this,"isMainLayouer",!0);_(this,"requireLinks",!1);_(this,"allLinks",[]);_(this,"rootNode");this.layoutOptions=i,this.graphOptions=e,this.graphInstance=t,this.networkAnalyzer=new En(t)}setLinks(i){L("setLinks:",i.length),this.allLinks=i}generateCalcNodes(i){const e=[],t=new Map;for(const n of i){const o={rgNode:n,x:n.x,y:n.y,width:n.width||n.el_W||50,height:n.height||n.el_H||50};e.push(o),t.set(n.id,o)}return{calcNodes:e,calcNodeMap:t}}generateLevels(i){const e=[],t=new Map;for(const n of i){if(!n.lot||typeof n.lot.level!="number")continue;const o=n.lot.level;e.includes(o)||(e.push(o),t.set(o,[])),t.get(o).push(n)}return e.sort((n,o)=>n-o),{levels:e,levelNodesMap:t}}adjustNodePositions(i,e,t){if(!i||i.length===0)return[];for(let n=1;n<i.length;n++){const o=i[n],s=i[n-1];switch(e){case"right":o.x<s.x+s.width+t&&(o.x=s.x+s.width+t);break;case"left":o.x+o.width>s.x-t&&(o.x=s.x-o.width-t);break;case"bottom":o.y<s.y+s.height+t&&(o.y=s.y+s.height+t);break;case"top":o.y+o.height>s.y-t&&(o.y=s.y-o.height-t);break}}return i}getReverseAlignItems(i){return Dn[i]}updateNodePosition(i,e,t){this.graphInstance.updateNode(typeof i=="string"?i:i.id,{x:e,y:t})}layoutEnd(){this.graphInstance&&(this.graphInstance.dataProvider.updateShouldRenderGraphData(),this.graphInstance._dataUpdated())}}const Dn={start:"end",end:"start",center:"center"},fe=In;class Vn extends fe{constructor(e,t,n){super(e,t,n);_(this,"layoutOptions");_(this,"fastStart",!1);_(this,"skipInitLayout",!1);_(this,"maxLayoutTimes",300);_(this,"byNode",!0);_(this,"byLine",!0);_(this,"lockX",!1);_(this,"lockY",!1);_(this,"force_node_repulsion",1);_(this,"force_line_elastic",1);_(this,"disableLiveChanges",!1);_(this,"force_x_coefficient",1);_(this,"force_y_coefficient",1);_(this,"instanceId","");_(this,"calcNodes",[]);_(this,"_graphEventHandler");_(this,"layoutTimes",0);_(this,"prev10",[]);_(this,"visibleNodes",[]);_(this,"_onFinishCallback");_(this,"_onTickCallback");_(this,"calcNodeMap",new WeakMap);_(this,"forCalcNodes",[]);_(this,"recentGraphVelocity",[]);_(this,"graphVelocityBalancedValue",.1);_(this,"prevLogTime",0);_(this,"animationFrameTimer",0);_(this,"prevNodeLevel1Index",0);_(this,"prevNodeLevel2Index",0);_(this,"stoped",!1);_(this,"maxTractionLength",400);_(this,"zeroForceLength",40);_(this,"maxRepulsionDistance",600);_(this,"nodeCollisionRadius",40);_(this,"maxMoveSpeed",100);_(this,"n2nMaxForce",50);this.layoutOptions=e,this.updateOptions(e),this.requireLinks=!0,this.instanceId=n?n.generateNewUUID(5):"error-id"}updateOptions(e){e.fastStart!==void 0&&(this.fastStart=e.fastStart),e.maxLayoutTimes!==void 0&&(this.maxLayoutTimes=e.maxLayoutTimes),e.byNode!==void 0&&(this.byNode=e.byNode),e.byLine!==void 0&&(this.byLine=e.byLine),e.force_node_repulsion!==void 0&&(this.force_node_repulsion=e.force_node_repulsion),e.force_line_elastic!==void 0&&(this.force_line_elastic=e.force_line_elastic),e.force_x_coefficient!==void 0&&(this.force_x_coefficient=e.force_x_coefficient),e.force_y_coefficient!==void 0&&(this.force_y_coefficient=e.force_y_coefficient),e.disableLiveChanges!==void 0&&(this.disableLiveChanges=e.disableLiveChanges),e.skipInitLayout!==void 0&&(this.skipInitLayout=e.skipInitLayout),e.maxTractionLength!==void 0&&(this.maxTractionLength=e.maxTractionLength),e.zeroForceLength!==void 0&&(this.zeroForceLength=e.zeroForceLength),e.maxRepulsionDistance!==void 0&&(this.maxRepulsionDistance=e.maxRepulsionDistance),e.nodeCollisionRadius!==void 0&&(this.nodeCollisionRadius=e.nodeCollisionRadius)}placeNodes(e,t){if(L("RGForceLayout["+this.instanceId+"].placeNodes"),this.calcNodes=e,this.allNodes.length===0&&(this.allNodes=e),this.rootNode=t,this.fastStart)L("RGForceLayout["+this.instanceId+"] fastStart"),this.calcNodes.forEach(n=>{if(n.fixed===!0)return;let o=n.x,s=n.y,a=!1;(Number.isNaN(o)||o===void 0)&&(o=Math.floor(Math.random()*200)-100,a=!0),(Number.isNaN(s)||s===void 0)&&(s=Math.floor(Math.random()*200)-100,a=!0),o===0&&s===0&&(o=Math.floor(Math.random()*200)-100,s=Math.floor(Math.random()*200)-100,a=!0),a&&this.updateNodePosition(n,o,s)});else if(!this.skipInitLayout){if(L("!!!initNodesPosition....."),t){L("layout by root:",t),(Number.isNaN(t.x)||t.x===void 0)&&this.updateNodePosition(t,0,0);const{tree:n}=this.networkAnalyzer.analyzeNetwork(e,t),{networkNodes:o,analyticResult:s}=n;t.fixed||this.layoutOptions.fixedRootNode||this.updateNodePosition(t,0,0);const a=z.getNodeLotXY({alignItemsX:"center",alignItemsY:"center"},t);t.lot.x=a.x,t.lot.y=a.y,this.placeRelativePosition(t,o,s,1,[]),L("!!!initNodesPosition fixedRootNode:2:",t.x,t.y),o.forEach(d=>{if(d.fixed===!0||!d.rgCalcedVisibility||d===t)return;const h=d.lot.x-z.getNodeWidth(d)/2,c=d.lot.y-z.getNodeHeight(d)/2;this.updateNodePosition(d,h,c)})}}this.allNodes.forEach(n=>{let o=n.x,s=n.y,a=!1;(Number.isNaN(o)||o===void 0)&&(o=0,a=!0),(Number.isNaN(s)||s===void 0)&&(s=0,a=!0),a&&this.updateNodePosition(n,o,s)}),L("["+this.instanceId+"]Start Auto Layout....."),this.start()}getLevelR(e,t){if(e.length===0)return;let n=0;for(let o=0;o<t;o++)n+=e[o]||e[e.length-1];return n}placeRelativePosition(e,t,n,o,s){L("analyticResult:",this.layoutOptions,n,o,s);const a={x:e.lot.x,y:e.lot.y},d=t.filter(h=>h.lot.level===1);this.placeNodesInFanRegion(d,0,360,a,1,n.max_strength,s,1,o,0)}calculateMinimumRadius(e,t=0){if(e.length===0||e.length===1)return 0;const n=e.map(c=>{const f=c.width||c.el_W,p=c.height||c.el_H;return Math.sqrt(f*f+p*p)/2+t/2}),o=[];for(let c=0;c<n.length;c++){const f=(c+1)%n.length;o.push(n[c]+n[f])}let s=Math.max(...o)/2,a=o.reduce((c,f)=>c+f,0);const d=100;let h=a;for(let c=0;c<d;c++){const f=(s+a)/2;let p=0;for(const m of o){const u=m/(2*f);if(u>1){p=10;break}p+=2*Math.asin(u)}p>2*Math.PI?s=f:(a=f,h=f)}return h}placeNodesInFanRegion(e,t,n,o,s,a,d,h,c,f){var y,v;let p=t;const m=n-t,u=200;let g=this.getLevelR(d,s)||f+u*c;s===1&&c===1&&(!this.layoutOptions.levelGaps||this.layoutOptions.levelGaps.length===0)&&(g=this.calculateMinimumRadius(e,10),g=Math.min(Math.max(g,200),500));for(const x of e){const w=((y=x.lot)==null?void 0:y.strengthWithChilds)/a,k=o.x+g,T=o.y,O=w*m,b=p+O/2,N=j.getRotatedPoint(k,T,o.x,o.y,b);x.lot.x=N.x,x.lot.y=N.y,x.lot.childs&&x.lot.childs.length>0&&this.placeNodesInFanRegion(x.lot.childs,p,p+O,o,s+1,(v=x.lot)==null?void 0:v.strengthWithChilds,d,h+1,c,g),p+=O}}graphEventHandle(e,...t){if(e===I.onNodeDragStart){const n=t[0],o=this.calcNodeMap.get(n);o&&(o.dragging=!0)}else if(e===I.onNodeDragging){const n=t[0],o=t[1],s=t[2],a=this.calcNodeMap.get(n);a&&(a.x=o,a.y=s)}else if(e===I.onNodeDragEnd){const n=t[0],o=this.calcNodeMap.get(n);o&&(o.dragging=!1)}}connectToGraphInstance(){this._graphEventHandler=this.graphEventHandle.bind(this),this.graphInstance&&this.graphInstance.addEventHandler(this._graphEventHandler)}disConnectToGraphInstance(){this.graphInstance&&this.graphInstance.removeEventHandler(this._graphEventHandler)}updateVisibleNodes(e){this.visibleNodes=[],e&&(this.allNodes=e),this.allNodes.forEach(t=>{t.lot||(L("node miss lot:",t.text),t.lot={x:t.x,y:t.y,childs:[]}),this.visibleNodes.push(t)}),this.resetCalcNodes(),L("visibleNodes:",this.visibleNodes.length)}viewUpdate(){this._onTickCallback&&this._onTickCallback(),this.graphInstance&&this.graphInstance.forceLayoutTickCallback()}autoLayout(e=!1){if(this.updateVisibleNodes(),this.isMainLayouer){const t=this.graphInstance.dataProvider.getOptions();this.graphInstance.dataProvider.updateOptions({layout:{...t.layout,autoLayouting:!0}})}this.doForceLayout(0)}onFinish(e){this._onFinishCallback=e}onTick(e){this._onTickCallback=e}applyFBuffToNodes(){for(const e of this.forCalcNodes)this.applyToNodePosition(e)}applyPositionToNodes(){this.visibleNodes.forEach(e=>{if(e.fixed)return;const t=this.calcNodeMap.get(e);t&&(e.x=t.x,e.y=t.y)}),this.viewUpdate()}layoutFinished(){if(cancelAnimationFrame(this.animationFrameTimer),this.isMainLayouer){const e=this.graphInstance.dataProvider.getOptions();this.graphInstance.dataProvider.updateOptions({layout:{...e.layout,autoLayouting:!1}})}L("Force Layout["+this.instanceId+"] finished"),this.applyFBuffToNodes(),this.applyPositionToNodes(),this.disConnectToGraphInstance();try{this._onFinishCallback&&this._onFinishCallback()}catch(e){console.error(e)}}resetCalcNodes(){this.forCalcNodes=[],this.calcNodeMap=new WeakMap,this.visibleNodes.forEach(e=>{const t={rgNode:e,Fx:0,Fy:0,x:e.x,y:e.y,dragging:!1,force_weight:e.force_weight||1,forceCenterOffset_X:(e.width||e.el_W||60)/2,forceCenterOffset_Y:(e.height||e.el_H||60)/2,fixed:e.fixed||!1};this.forCalcNodes.push(t),this.calcNodeMap.set(e,t)}),this.allLinks=this.graphInstance.getLinksBetweenNodes(this.visibleNodes)}start(){this.stoped&&this.layoutTimes===0||(this.stoped=!1,this.layoutTimes=0,this.updateVisibleNodes(),this.connectToGraphInstance(),this.autoLayout(!0))}doForceLayout(e){if(this.graphInstance.viewComponentUnmounted){L("["+this.instanceId+"]stop layout:viewComponentUnmounted"),this.layoutFinished();return}let t="0";e>0?(this.prev10.length>=10&&(this.prev10.splice(0,1),t=(1e3/((this.prev10[this.prev10.length-1]-this.prev10[0])/10)).toFixed(1)),this.prev10.push(e)):this.visibleNodes.length===0&&this.updateVisibleNodes(),this.layoutTimes++,this.calcNodesPosition(),this.applyFBuffToNodes(),this.disableLiveChanges||this.layoutTimes%2===0&&this.applyPositionToNodes(),this.layoutTimes<=this.maxLayoutTimes?(Date.now()-this.prevLogTime>3e3&&(L("Force Layout["+this.instanceId+"] Is Working...layoutTimes:",this.layoutTimes,"of",this.maxLayoutTimes,t,"Hz",this.visibleNodes.length),this.prevLogTime=Date.now()),this.animationFrameTimer=requestAnimationFrame(this.doForceLayout.bind(this))):this.layoutFinished()}syncNodePosition(e,t,n){const o=this.allNodes.find(a=>a.id===e),s=this.calcNodeMap.get(o);s&&(s.x=t,s.y=n)}calcNodesPosition(){if(this.byNode)for(let e=this.prevNodeLevel1Index;e<this.forCalcNodes.length;e++){const t=this.forCalcNodes[e];if(!t.dragging&&!t.fixed){for(let n=this.prevNodeLevel2Index;n<this.forCalcNodes.length;n++)if(e!==n){const o=this.forCalcNodes[n];if(o.dragging)continue;this.addGravityByNode(t,o)}}}if(this.byLine){if(this.allLinks&&this.allLinks.length>0){for(const e of this.allLinks)if(!e.line.forDisplayOnly){let t=e.line.force_elastic===void 0?1:e.line.force_elastic;if(this.visibleNodes.includes(e.fromNode)&&this.visibleNodes.includes(e.toNode)){const n=this.calcNodeMap.get(e.fromNode),o=this.calcNodeMap.get(e.toNode);this.addElasticByLine(n,o,t)}}}else for(const e of this.visibleNodes)if(e.lot&&e.lot.parent){const t=this.calcNodeMap.get(e.lot.parent),n=this.calcNodeMap.get(e);this.addElasticByLine(t,n,1)}}return!0}stop(){if(this.stoped=!0,this.layoutTimes===0)return;const e=this.graphInstance.dataProvider.getOptions();cancelAnimationFrame(this.animationFrameTimer),L("[RGForceLayout]["+this.instanceId+"]stop:",e.layout.autoLayouting,this.layoutTimes),this.layoutTimes=Number.MAX_VALUE,this.layoutFinished()}addElasticByLine(e,t,n=1){const o=e.x,s=e.y,a=t.x,d=t.y;let h=Math.sqrt((s-d)**2+(o-a)**2);if(h<this.zeroForceLength)return;h>this.maxTractionLength&&(h=this.maxTractionLength);const c=(h-this.zeroForceLength)*.02*this.force_line_elastic*n,f=c,p=c,m=(o-a)/h,u=(s-d)/h;this.addFtoNode(e,m*f*-1,u*f*-1),this.addFtoNode(t,m*p,u*p)}addGravityByNode(e,t,n=1){const o=e.x,s=e.y,a=t.x,d=t.y;if(n===1&&(Math.abs(o-a)>this.maxRepulsionDistance||Math.abs(s-d)>this.maxRepulsionDistance))return;const h=Math.sqrt((s-d)**2+(o-a)**2);if(n===1&&h>this.maxRepulsionDistance)return;let c=(this.maxRepulsionDistance-h)*.02*this.force_node_repulsion*n;h<this.nodeCollisionRadius&&(c=c*2);const f=(o-a)/h,p=(s-d)/h;this.addFtoNode(e,f*c,p*c)}addFtoNode(e,t,n){if(e.fixed||e.dragging||Number.isNaN(t)||Number.isNaN(n))return;t>this.n2nMaxForce&&(t=this.n2nMaxForce),n>this.n2nMaxForce&&(n=this.n2nMaxForce),t<-this.n2nMaxForce&&(t=-this.n2nMaxForce),n<-this.n2nMaxForce&&(n=-this.n2nMaxForce);const o=e.force_weight||1;this.lockX||(e.Fx+=t*(1/o)),this.lockY||(e.Fy+=n*(1/o))}applyToNodePosition(e){if(e.fixed)return 0;if(e.dragging){const o=e.rgNode;return this.updateNodePosition(o,e.x,e.y),0}if(this.calcNodes!==this.allNodes&&!this.calcNodes.includes(e.rgNode))return 0;let t=e.Fx,n=e.Fy;if(t>this.maxMoveSpeed&&(t=this.maxMoveSpeed),n>this.maxMoveSpeed&&(n=this.maxMoveSpeed),t<-this.maxMoveSpeed&&(t=-this.maxMoveSpeed),n<-this.maxMoveSpeed&&(n=-this.maxMoveSpeed),e.x=e.x+t*this.force_x_coefficient,e.y=e.y+n*this.force_y_coefficient,!this.disableLiveChanges){const o=e.rgNode;this.updateNodePosition(o,e.x,e.y)}e.Fx=0,e.Fy=0}}const ke=Vn;class Bn extends fe{constructor(e,t,n){super(e,t,n);_(this,"enableGatherNodes",!1);_(this,"layoutOptions");this.layoutOptions=e,L("new RGTreeLayout:",this.layoutOptions),this.layoutOptions.from||(this.layoutOptions.from="left"),this.layoutOptions.levelGaps||(this.layoutOptions.levelGaps=[]);const o=this.layoutOptions.from;o==="top"||o==="bottom"?(this.layoutOptions.treeNodeGapH||(this.layoutOptions.treeNodeGapH=10),this.layoutOptions.treeNodeGapV||(this.layoutOptions.treeNodeGapV=50)):(this.layoutOptions.treeNodeGapH||(this.layoutOptions.treeNodeGapH=50),this.layoutOptions.treeNodeGapV||(this.layoutOptions.treeNodeGapV=10)),o==="top"?(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="center"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="start"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.layoutOptions.alignItemsX),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.getReverseAlignItems(this.layoutOptions.alignItemsY))):o==="bottom"?(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="center"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="end"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.layoutOptions.alignItemsX),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.getReverseAlignItems(this.layoutOptions.alignItemsY))):o==="right"?(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="end"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="center"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.getReverseAlignItems(this.layoutOptions.alignItemsX)),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.layoutOptions.alignItemsY)):(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="start"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="center"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.getReverseAlignItems(this.layoutOptions.alignItemsX)),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.layoutOptions.alignItemsY)),this.layoutOptions.ignoreNodeSize===void 0&&(this.layoutOptions.ignoreNodeSize=!1);const s=this.layoutOptions.layoutExpansionDirection,a=s==="start"||s==="left"||s==="top"?"start":s==="end"||s==="right"||s==="bottom"?"end":"center";this.layoutOptions.layoutExpansionDirection=a,this.layoutOptions.levelDistance&&console.error("Error: levelDistance is not support\uFF0C Please use levelGaps or treeNodeGapH,treeNodeGapV option in layoutOptions"),this.enableGatherNodes=this.layoutOptions.enableGatherNodes,this.layoutOptions.rotate||(this.layoutOptions.rotate=0)}placeNodes(e,t){if(L("RGTreeLayout:placeNodes"),t)L("layout by root:",t);else{console.error("root is null");return}L("allNodes:",e.length);const n={alignItemsX:this.layoutOptions.alignItemsX,alignItemsY:this.layoutOptions.alignItemsY},o={alignItemsX:this.layoutOptions.alignParentItemsX,alignItemsY:this.layoutOptions.alignParentItemsY};this.rootNode=t,this.allNodes=e,t.fixed||this.layoutOptions.fixedRootNode||this.updateNodePosition(t,0,0);const s=z.getNodeLotXY(n,t);t.lot.x=s.x,t.lot.y=s.y;const a=e;if(L("groupNodes:2:",a.length,a.map(c=>c.text).join(",")),this.layoutOptions.simpleTree===!0){const{tree:c}=this.networkAnalyzer.analyzeNetwork(a,this.rootNode,!1);this.placeNodesPosition(this.rootNode,c.networkNodes,c.analyticResult)}else{const{tree:c,reverseTree:f}=this.networkAnalyzer.analyzeNetwork(a,this.rootNode,!0);this.placeNodesPosition(this.rootNode,c.networkNodes,c.analyticResult),this.placeNodesPosition(this.rootNode,f.networkNodes,f.analyticResult)}const d=this.layoutOptions.rotate||0,h={x:t.x,y:t.y};this.allNodes.forEach(c=>{if(c.fixed!==!0&&!!z.isVisibleNode(c)&&(Number.isNaN(c.lot.x)&&(L("bad lot x:",c.text,c.lot.x),c.lot.x=0),Number.isNaN(c.lot.y)&&(L("bad lot y:",c.text,c.lot.y),c.lot.y=0),c!==t)){if(d){const u=j.getRotatedPoint(c.lot.x,c.lot.y,h.x,h.y,d);c.lot.x=u.x,c.lot.y=u.y}const f=c.lot.level<0?o:n,p=z.getNodeXByLotX(f,c),m=z.getNodeYByLotY(f,c);this.updateNodePosition(c,p,m)}}),L("create rootNode coordinates:1",t.x,t.y),this.layoutEnd()}placeNodesPosition(e,t,n){this.placeRelativePosition(e,t,n)}placeRelativePosition(e,t,n){const o=this.layoutOptions.layoutExpansionDirection,{levels:s,levelNodesMap:a}=this.generateLevels(t),d=n.max_strength;if(this.layoutOptions.from==="top"||this.layoutOptions.from==="bottom"){const h=this.layoutOptions.treeNodeGapH||20,c=this.layoutOptions.treeNodeGapV||20,f=new Map;for(const y of s){const v=a.get(y);f.set(y,Math.max(...v.map(x=>x.el_H)))}let p=0,m=0;for(const y of t){const v=y.el_W;p+=v,m++}const g=p/m+h;t.forEach(y=>{y.fixed!==!0&&y!==e&&(this.layoutOptions.from==="bottom"?y.lot.y=e.lot.y-this.getLevelDistance(y.lot.level,f,c+10):y.lot.y=e.lot.y+this.getLevelDistance(y.lot.level,f,c+10))}),t.forEach(y=>{y.fixed!==!0&&y.lot.level!==0&&(o==="start"?y.lot.x=e.lot.x-g*y.lot.strengthWithChilds_from:o==="end"?y.lot.x=e.lot.x+g*y.lot.strengthWithChilds_from:y.lot.x=e.lot.x+g*(d/-2+y.lot.strengthWithChilds_from+y.lot.strengthWithChilds/2))}),this.applyNodesGap(t,"v"),this.gatherNodes(t,"v",g)}else{const h=this.layoutOptions.treeNodeGapH||20,c=this.layoutOptions.treeNodeGapV||20,f=new Map;for(const y of s){const v=a.get(y);f.set(y,Math.max(...v.map(x=>x.el_W||x.width||50)))}let p=0,m=0;for(const y of t){const v=y.el_H;p+=v,m++}if(m===0)return;const g=p/m+c;t.forEach(y=>{y.fixed!==!0&&y!==e&&(this.layoutOptions.from==="right"?y.lot.x=e.lot.x-this.getLevelDistance(y.lot.level,f,h+50):y.lot.x=e.lot.x+this.getLevelDistance(y.lot.level,f,h+50))}),t.forEach(y=>{y.fixed!==!0&&y.lot.level!==0&&(o==="start"?y.lot.y=e.lot.y-g*y.lot.strengthWithChilds_from:o==="end"?y.lot.y=e.lot.y+g*y.lot.strengthWithChilds_from:y.lot.y=e.lot.y+g*(d/-2+y.lot.strengthWithChilds_from+y.lot.strengthWithChilds/2))}),this.applyNodesGap(t,"h"),this.gatherNodes(t,"h",g)}}getLevelDistance(e,t,n){if(e===0)return 0;if(e>0){let o=0;for(let s=0;s<e;s++){const a=t.get(s);o+=a+this.getLevelGap(s,n,a,e)}return o}else{let o=0;for(let s=0;s>e;s--){const a=t.get(s);o+=a+this.getLevelGap(s,n,a,e)}return-o}}getLevelGap(e,t,n,o){let s=t+(o===-1&&e===0?n/2:0);if(this.layoutOptions.levelGaps.length>0){const a=this.layoutOptions.levelGaps[Math.abs(e)];a&&(s=a)}return s}applyNodesGap(e,t){if(this.layoutOptions.ignoreNodeSize)return;const n={alignItemsX:this.layoutOptions.alignItemsX,alignItemsY:this.layoutOptions.alignItemsY},o={alignItemsX:this.layoutOptions.alignParentItemsX,alignItemsY:this.layoutOptions.alignParentItemsY},s=this.layoutOptions.layoutExpansionDirection,{levels:a,levelNodesMap:d}=this.generateLevels(e),h=new Map;for(const p of a){const m=d.get(p);h.set(p,Math.max(...m.map(u=>u.el_W)))}const{calcNodes:c,calcNodeMap:f}=this.generateCalcNodes(e);c.forEach(p=>{const m=p.rgNode.lot.level<0?o:n;p.x=z.getNodeXByLotX(m,p.rgNode),p.y=z.getNodeYByLotY(m,p.rgNode),p.width=p.rgNode.el_W,p.height=p.rgNode.el_H,p.buffY=0});for(const p of a){const m=d.get(p)||[];if(t==="h")if(s==="end"){m.sort((g,y)=>g.lot.y-y.lot.y);const u=m.map(g=>f.get(g.id));this.adjustNodePositions(u,"bottom",this.layoutOptions.treeNodeGapV);for(const g of u){const y=g.rgNode.lot.level<0?o:n;g.rgNode.lot.y=z.getNodeLotXY(y,g).y}}else{m.sort((g,y)=>y.lot.y-g.lot.y);const u=m.map(g=>f.get(g.id));this.adjustNodePositions(u,"top",this.layoutOptions.treeNodeGapV);for(const g of u){const y=g.rgNode.lot.level<0?o:n;g.rgNode.lot.y=z.getNodeLotXY(y,g).y}}else if(s==="end"){m.sort((g,y)=>g.lot.x-y.lot.x);const u=m.map(g=>f.get(g.id));this.adjustNodePositions(u,"right",this.layoutOptions.treeNodeGapH);for(const g of u){const y=g.rgNode.lot.level<0?o:n,v=z.getNodeLotXY(y,g);g.rgNode.lot.x=v.x}}else{m.sort((g,y)=>y.lot.x-g.lot.x);const u=m.map(g=>f.get(g.id));this.adjustNodePositions(u,"left",this.layoutOptions.treeNodeGapH);for(const g of u){const y=g.rgNode.lot.level<0?o:n;g.rgNode.lot.x=z.getNodeLotXY(y,g).x}}}if(t==="h"){const p=new Map,m=new Map;for(const w of a){const T=d.get(w).map(O=>f.get(O.id));p.set(w,Math.max(...T.map(O=>O.width))),m.set(w,Math.min(...T.map(O=>O.x)))}const u=this.layoutOptions.treeNodeGapH;let g=a.filter(w=>w>0).sort((w,k)=>w-k),y=a.filter(w=>w<0).sort((w,k)=>k-w),v=1;this.layoutOptions.from==="right"&&([y,g]=[g,y],v=-1);let x=0;for(const w of g){const k=w-v,T=m.get(k),O=p.get(k),b=m.get(w)+x;p.get(w);const N=T+O+u;if(N>b){const P=N-b;x=P;const R=d.get(w);for(const S of R)S.lot.x+=x;m.set(w,b+P)}else m.set(w,b)}x=0;for(const w of y){const k=w+v,T=m.get(k);p.get(k);const O=m.get(w)+x,b=p.get(w),N=T-u;if(O+b>N){const P=N-(O+b);x=P;const R=d.get(w);for(const S of R)S.lot.x+=x;m.set(w,O+P)}else m.set(w,O)}}else{const p=new Map,m=new Map;for(const w of a){const T=d.get(w).map(O=>f.get(O.id));p.set(w,Math.max(...T.map(O=>O.height))),m.set(w,Math.min(...T.map(O=>O.y)))}const u=this.layoutOptions.treeNodeGapV;let g=a.filter(w=>w>0).sort((w,k)=>w-k),y=a.filter(w=>w<0).sort((w,k)=>k-w),v=1;this.layoutOptions.from==="bottom"&&([y,g]=[g,y],v=-1);let x=0;for(const w of g){const k=w-v,T=m.get(k),O=p.get(k),b=m.get(w)+x;p.get(w);const N=T+O+u;if(N>b){const P=N-b;x=P;const R=d.get(w);for(const S of R)S.lot.y+=x;m.set(w,b+P)}else m.set(w,b)}x=0;for(const w of y){const k=w+v,T=m.get(k);p.get(k);const O=m.get(w)+x,b=p.get(w),N=T-u;if(O+b>N){const P=N-(O+b);x=P;const R=d.get(w);for(const S of R)S.lot.y+=x;m.set(w,O+P)}else m.set(w,O)}}}gatherNodes(e,t,n){if(!this.enableGatherNodes)return;const{calcNodes:o,calcNodeMap:s}=this.generateCalcNodes(e);o.forEach(d=>{d.movedNodeSizeBefore=1,d.movedNodeSizeAfter=1});const{levelNodesMap:a}=this.generateLevels(e);e.forEach(d=>{if(d.fixed!==!0&&d.lot.level!==0){const h=a.get(d.lot.level)||[];if(d.lot.strengthWithChilds===1&&d.lot.childrenSizeVisible<=1){const c=this.getBloomingNearByParent(d,d.lot.parent,h,t);if(c){const f=s.get(d.id);t==="h"?d.lot.y-c.lot.y>0?(d.lot.y=c.lot.y+n*f.movedNodeSizeAfter,f.movedNodeSizeAfter++):(d.lot.y=c.lot.y-n*f.movedNodeSizeBefore,f.movedNodeSizeBefore++):d.lot.x-c.lot.x>0?(d.lot.x=c.lot.x+n*f.movedNodeSizeAfter,f.movedNodeSizeAfter++):(d.lot.x=c.lot.x-n*f.movedNodeSizeBefore,f.movedNodeSizeBefore++)}}}})}getBloomingNearByParent(e,t,n,o){let s=9999,a;for(const d of n)if(d.lot.childrenSizeVisible>1&&d.lot.parent===t){const h=o==="h"?d.lot.y-t.lot.y:d.lot.x-t.lot.x;Math.abs(h)<s&&(s=Math.abs(h),a=d)}if(a&&a!==e)return a}}const lt=Bn;class An extends ke{constructor(e,t,n){super(e,t,n);_(this,"layoutOptions");this.layoutOptions=e,this.layoutOptions.distanceCoefficient||(this.layoutOptions.distanceCoefficient=1),this.layoutOptions.levelGaps||(this.layoutOptions.levelGaps=[]),this.layoutOptions.levelDistance&&console.error("Error: levelDistance is not support\uFF0C Please use levelGaps option in layoutOptions")}placeNodes(e,t){if(L("RGCenterLayout:placeNodes"),!t){L("root is null:",t);return}L("layout by root:",t),this.allNodes=e,this.calcNodes=e,this.rootNode=t;const{tree:n}=this.networkAnalyzer.analyzeNetwork(e,this.rootNode),{networkNodes:o,analyticResult:s}=n;if(this.layoutOptions.genLotInfoOnly){L("only gen lot info, return");return}t.fixed||this.layoutOptions.fixedRootNode||this.updateNodePosition(t,0,0);const a={alignItemsX:this.layoutOptions.alignItemsX||"center",alignItemsY:this.layoutOptions.alignItemsY||"center"},d=z.getNodeLotXY(a,t);t.lot.x=d.x,t.lot.y=d.y;const h=this.layoutOptions.rotate||0;L("root position:",t.lot.x,t.lot.y);const c=this.layoutOptions.distanceCoefficient||1,f=this.getLevelDistanceArr();this.placeRelativePosition(this.rootNode,o,s,c,f);const p={x:t.x,y:t.y};o.forEach(m=>{if(m.fixed!==!0&&!!m.rgCalcedVisibility&&m!==t){if(h){const v=j.getRotatedPoint(m.lot.x,m.lot.y,p.x,p.y,h);m.lot.x=v.x,m.lot.y=v.y}const u=a,g=z.getNodeXByLotX(u,m),y=z.getNodeYByLotY(u,m);this.updateNodePosition(m,g,y)}}),this.layoutEnd()}getLevelDistanceArr(){let e=[];if(this.layoutOptions.levelGaps){if(Array.isArray(this.layoutOptions.levelGaps))e=this.layoutOptions.levelGaps;else return console.error("Error levelDistance, levelDistance must is Array"),new Array(10).fill(200);if(e.length>0&&e.length<10)for(let t=e.length;t<10;t++)e.push(e[e.length-1])}return e}}const dt=An;class zn extends ke{constructor(i,e,t){super(i,e,t)}placeNodes(i,e){if(e)L("layout by root:",e);else{L("root is null:",e);return}this.allNodes=i,this.rootNode=e,e.fixed||this.layoutOptions.fixedRootNode||this.updateNodePosition(e,0,0);const t={alignItemsX:this.layoutOptions.alignItemsX||"center",alignItemsY:this.layoutOptions.alignItemsY||"center"},n=this.layoutOptions.rotate||0,o=z.getNodeLotXY(t,e);e.lot.x=o.x,e.lot.y=o.y;const s=this.allNodes.filter(h=>h.rgCalcedVisibility),a=s.length;let d=a*90/Math.PI/2;d<200&&(d=200),d>800&&(d=800),s.forEach((h,c)=>{const f=j.getOvalPoint(o.x,o.y,d,c,a);h.lot.x=f.x,h.lot.y=f.y}),s.forEach(h=>{if(h.fixed===!0||!h.rgCalcedVisibility)return;if(n){const m=j.getRotatedPoint(h.lot.x,h.lot.y,e.lot.x,e.lot.y,n);h.lot.x=m.x,h.lot.y=m.y}const c=t,f=z.getNodeXByLotX(c,h),p=z.getNodeYByLotY(c,h);this.updateNodePosition(h,f,p)}),this.layoutEnd()}}const ct=zn;class Xn extends fe{constructor(e,t,n){super(e,t,n);_(this,"graphOptions");_(this,"layoutOptions");_(this,"allNodes",[]);this.layoutOptions=e,this.graphOptions=t}placeNodes(e,t){if(t)L("layout by root:",t);else{L("root is null:",t);return}L("allNodes:",e.length),this.networkAnalyzer.analyzeNetwork(e,t,!1,!1),L("[Fixed layout canvasOffset]",this.graphOptions.viewSize,this.graphOptions.canvasSize),this.layoutEnd()}}const ht=Xn;class Gn extends fe{constructor(e,t,n){super(e,t,n);_(this,"graphInstance");_(this,"layoutOptions");_(this,"levelGaps",[]);this.layoutOptions=e,L("new RGSmartTreeLayout:",this.layoutOptions),this.layoutOptions.from||(this.layoutOptions.from="left"),this.layoutOptions.levelGaps&&(Array.isArray(this.layoutOptions.levelGaps)?this.levelGaps=this.layoutOptions.levelGaps:console.error("Error levelDistance, levelDistance must is Array"));const o=this.layoutOptions.from;o==="top"||o==="bottom"?(this.layoutOptions.treeNodeGapH||(this.layoutOptions.treeNodeGapH=10),this.layoutOptions.treeNodeGapV||(this.layoutOptions.treeNodeGapV=30),this.layoutOptions.treeNodeGapV<30&&(this.layoutOptions.treeNodeGapV=30)):(this.layoutOptions.treeNodeGapH||(this.layoutOptions.treeNodeGapH=30),this.layoutOptions.treeNodeGapV||(this.layoutOptions.treeNodeGapV=10),this.layoutOptions.treeNodeGapH<30&&(this.layoutOptions.treeNodeGapH=30)),o==="top"?(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="center"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="start"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.layoutOptions.alignItemsX),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.getReverseAlignItems(this.layoutOptions.alignItemsY))):o==="bottom"?(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="center"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="end"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.layoutOptions.alignItemsX),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.getReverseAlignItems(this.layoutOptions.alignItemsY))):o==="right"?(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="end"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="center"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.getReverseAlignItems(this.layoutOptions.alignItemsX)),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.layoutOptions.alignItemsY)):(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="end"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="center"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.getReverseAlignItems(this.layoutOptions.alignItemsX)),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.layoutOptions.alignItemsY)),this.requireLinks=!0,this.graphInstance=n}placeNodes(e,t){if(L("RGSmartTreeLayout:placeNodes"),t)L("layout by root:",t);else{console.error("root is null");return}this.rootNode=t,this.allNodes=e,L("allNodes:",e.length);const n={alignItemsX:this.layoutOptions.alignItemsX,alignItemsY:this.layoutOptions.alignItemsY},o={alignItemsX:this.layoutOptions.alignParentItemsX,alignItemsY:this.layoutOptions.alignParentItemsY},{tree:s,reverseTree:a}=this.networkAnalyzer.analyzeNetwork(e,this.rootNode,!0,!0);t.fixed||this.layoutOptions.fixedRootNode||this.updateNodePosition(t,0,0);const d=z.getNodeLotXY(n,t);t.lot.x=d.x,t.lot.y=d.y,this.placeRelativePosition(t,[...s.networkNodes].concat(a.networkNodes),Math.max(s.analyticResult.max_strength,a.analyticResult.max_strength)),L("allNodes:",e.length);const h={left:0,top:90,right:180,bottom:270}[this.layoutOptions.from],c={x:t.x,y:t.y};this.allNodes.forEach(m=>{if(m.fixed===!0||!m.rgCalcedVisibility)return;if(Number.isNaN(m.lot.x)&&(L("bad lot x:",m.text,m.lot.x),m.lot.x=0),Number.isNaN(m.lot.y)&&(L("bad lot y:",m.text,m.lot.y),m.lot.y=0),h){const v=j.getRotatedPoint(m.lot.x,m.lot.y,c.x,c.y,h);m.lot.x=v.x,m.lot.y=v.y}const u=m.lot.level<0?o:n,g=z.getNodeXByLotX(u,m),y=z.getNodeYByLotY(u,m);this.updateNodePosition(m,g,y)}),L("create rootNode coordinates:1",t.x,t.y);const f=new ke({layoutName:"force",maxLayoutTimes:30,force_node_repulsion:.1,force_line_elastic:1,fixedRootNode:!0,disableLiveChanges:!0},this.graphOptions,this.graphInstance);f.isMainLayouer=!1,f.requireLinks=!0,this.layoutOptions.from==="top"||this.layoutOptions.from==="bottom"?f.lockY=!0:f.lockX=!0;const p=t.fixed;t.fixed=!0,f.skipInitLayout=!0,f.resetCalcNodes(),setTimeout(()=>{t.fixed=p},800),f.onFinish(()=>{t.fixed=p,this.graphInstance&&(this.graphInstance.enableNodeXYAnimation(),this.graphInstance._dataUpdated()),this.applyNodesGap(this.allNodes),this.graphInstance&&(this.graphInstance._dataUpdated(),this.allNodes.forEach(m=>{this.graphInstance.updateNode(m,{x:m.x,y:m.y})}),setTimeout(()=>{this.graphInstance.disableNodeXYAnimation(),this.graphInstance._dataUpdated()},300))}),f.placeNodes(this.allNodes,t),this.layoutEnd()}placeRelativePosition(e,t,n){const o=this.layoutOptions.from==="top"||this.layoutOptions.from==="bottom"?"v":"h";let s=this.layoutOptions.treeNodeGapH||300,a=this.layoutOptions.treeNodeGapV||10;o==="v"&&([s,a]=[a,s]);const{levels:d,levelNodesMap:h}=this.generateLevels(t),c=new Map;for(const g of d){const y=h.get(g);c.set(g,Math.max(...y.map(v=>v.el_W)))}let f=0,p=0;for(const g of t){const y=g.el_H;f+=y,p++}if(p===0)return;const u=f/p+a;t.forEach(g=>{g.fixed!==!0&&g!==e&&(g.lot.x=e.lot.x+this.getLevelDistance(g.lot.level,c,s))}),t.forEach(g=>{g.fixed!==!0&&g!==e&&(g.lot.level===0?g.lot.y=e.lot.y+u*g.lot.index_of_level:g.lot.y=e.lot.y+u*(n/-2+g.lot.strengthWithChilds_from+g.lot.strengthWithChilds/2))})}applyNodesGap(e){const t=this.layoutOptions.from==="top"||this.layoutOptions.from==="bottom"?"v":"h",{levels:n,levelNodesMap:o}=this.generateLevels(e),s=new Map;for(const h of n){const c=o.get(h);s.set(h,Math.max(...c.map(f=>f.el_W)))}const{calcNodes:a,calcNodeMap:d}=this.generateCalcNodes(e);a.forEach(h=>{h.x=h.rgNode.x,h.y=h.rgNode.y,h.width=h.rgNode.el_W,h.height=h.rgNode.el_H,h.buffY=0});for(const h of n){const c=o.get(h)||[];if(t==="h"){const f=c.map(u=>d.get(u.id)),p=f.filter(u=>u.y<this.rootNode.y).sort((u,g)=>g.y-u.y),m=f.filter(u=>u.y>=this.rootNode.y).sort((u,g)=>u.y-g.y);this.adjustNodePositions(p,"top",5),this.adjustNodePositions(m,"bottom",5);for(const u of f)u.rgNode.y=u.y}else{const f=c.map(u=>d.get(u.id)),p=f.filter(u=>u.x<this.rootNode.x).sort((u,g)=>g.x-u.x),m=f.filter(u=>u.x>=this.rootNode.x).sort((u,g)=>u.x-g.x);this.adjustNodePositions(p,"left",5),this.adjustNodePositions(m,"right",5);for(const u of f)u.rgNode.x=u.x}}}getLevelDistance(e,t,n){if(e===0)return 0;if(e>0){let o=0;for(let s=1;s<=e;s++){const a=t.get(s);o+=a+this.getLevelGap(s,n,a)}return o}else{let o=0;for(let s=-1;s>=e;s--){const a=t.get(s);o+=a+this.getLevelGap(s,n,a)}return-o}}getLevelGap(e,t,n){var s;let o=t+(e===-1?n/2:0);if(((s=this.layoutOptions.levelGaps)==null?void 0:s.length)>0){const a=this.layoutOptions.levelGaps[Math.abs(e)];a&&(o=a)}return o}}const Fn=Gn;class Hn extends fe{constructor(e,t,n){super(e,t,n);_(this,"enableGatherNodes",!1);_(this,"layoutOptions");this.layoutOptions=e,L("new RGFolderLayout:",this.layoutOptions),this.layoutOptions.from||(this.layoutOptions.from="left"),this.layoutOptions.treeNodeGapH||(this.layoutOptions.treeNodeGapH=10),this.layoutOptions.treeNodeGapV||(this.layoutOptions.treeNodeGapV=10),this.layoutOptions.levelGaps||(this.layoutOptions.levelGaps=[]),this.layoutOptions.bottomJunctionPointOffsetX===void 0&&(this.layoutOptions.bottomJunctionPointOffsetX=-50);const o=this.layoutOptions.from;o==="top"?(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="center"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="start"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.layoutOptions.alignItemsX),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.getReverseAlignItems(this.layoutOptions.alignItemsY))):o==="bottom"?(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="center"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="end"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.layoutOptions.alignItemsX),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.getReverseAlignItems(this.layoutOptions.alignItemsY))):o==="right"?(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="end"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="center"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.getReverseAlignItems(this.layoutOptions.alignItemsX)),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.layoutOptions.alignItemsY)):(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="end"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="center"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.getReverseAlignItems(this.layoutOptions.alignItemsX)),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.layoutOptions.alignItemsY)),this.layoutOptions.levelDistance&&console.error("Error: levelDistance is not support\uFF0C Please use levelGaps, treeNodeGapH, treeNodeGapV option in layoutOptions"),this.enableGatherNodes=this.layoutOptions.enableGatherNodes}placeNodes(e,t){if(L("RGFolderLayout:placeNodes"),t)L("layout by root:",t);else{console.error("root is null");return}this.rootNode=t,this.allNodes=e;const n={alignItemsX:this.layoutOptions.alignItemsX,alignItemsY:this.layoutOptions.alignItemsY},o={alignItemsX:this.layoutOptions.alignParentItemsX,alignItemsY:this.layoutOptions.alignParentItemsY};t.fixed||this.layoutOptions.fixedRootNode||this.updateNodePosition(t,0,0);const s=z.getNodeLotXY(n,t);t.lot.x=s.x,t.lot.y=s.y,L("allNodes:",e.length),this.networkAnalyzer.isFolderLayout=!0;const{tree:a}=this.networkAnalyzer.analyzeNetwork(e,t,!1,!1);this.placeRelativePosition(t,a.networkNodes,a.analyticResult),L("networkNodes:",a.networkNodes.length),this.allNodes.forEach(d=>{if(d.fixed!==!0&&(Number.isNaN(d.lot.x)&&(L("bad lot x:",d.text,d.lot.x),d.lot.x=0),Number.isNaN(d.lot.y)&&(L("bad lot y:",d.text,d.lot.y),d.lot.y=0),d!==t)){const h=d.lot.level<0?o:n,c=z.getNodeXByLotX(h,d),f=z.getNodeYByLotY(h,d);this.updateNodePosition(d,c,f)}}),L("create rootNode coordinates:1",t.x,t.y),this.layoutEnd()}placeRelativePosition(e,t,n){const o=this.layoutOptions.treeNodeGapH||20,s=this.layoutOptions.treeNodeGapV||20,a=new Map;let d=0,h=0;for(const p of t){const m=p.lot.level,u=p.width||p.el_W||50,g=p.height||p.el_H||50;d+=g,h++;const y=a.get(m);y===void 0?a.set(m,u):u>y&&a.set(m,y)}if(h===0)return;const f=d/h+s;t.forEach(p=>{p.fixed!==!0&&p!==e&&(this.layoutOptions.from==="right"?p.lot.x=e.lot.x-this.getLevelDistance(p.lot.level,a,o+50):p.lot.x=e.lot.x+this.getLevelDistance(p.lot.level,a,o+50))}),t.forEach(p=>{p.fixed!==!0&&p!==e&&p.lot.level!==0&&(p.lot.y=e.lot.y+f*p.lot.strengthWithChilds_from)}),this.gatherNodes(t,"h",f)}gatherNodes(e,t,n){if(!this.enableGatherNodes)return;const o={};e.forEach(s=>{if(s.lot.level!==0)return;const a=s.lot.level+"";o[a]||(o[a]=[]),o[a].push(s),s.lot.movedNodeSizeBefore=1,s.lot.movedNodeSizeAfter=1}),e.forEach(s=>{if(s.fixed!==!0&&s.lot.level!==0){const a=s.lot.level+"",d=o[a];if(s.lot.strengthWithChilds===1&&s.lot.childrenSizeVisible<=1){const h=this.getBloomingNearByParent(s,s.lot.parent,d,t);h&&(t==="h"?s.lot.y-h.lot.y>0?(s.lot.y=h.lot.y+n*h.lot.movedNodeSizeAfter,h.lot.movedNodeSizeAfter++):(s.lot.y=h.lot.y-n*h.lot.movedNodeSizeBefore,h.lot.movedNodeSizeBefore++):s.lot.x-h.lot.x>0?(s.lot.x=h.lot.x+n*h.lot.movedNodeSizeAfter,h.lot.movedNodeSizeAfter++):(s.lot.x=h.lot.x-n*h.lot.movedNodeSizeBefore,h.lot.movedNodeSizeBefore++))}}})}getBloomingNearByParent(e,t,n,o){let s=9999,a;for(const d of n)if(d.lot.childrenSizeVisible>1&&d.lot.parent===t){const h=o==="h"?d.lot.y-t.lot.y:d.lot.x-t.lot.x;Math.abs(h)<s&&(s=Math.abs(h),a=d)}if(a&&a!==e)return a}getLevelDistance(e,t,n){if(e===0)return 0;if(e>0){let o=0;for(let s=0;s<e;s++)o+=t.get(s)+this.getLevelGap(s,n);return o}else{let o=e<-1?0:-t.get(e)/2;for(let s=e;s<0;s++)o+=t.get(s)+this.getLevelGap(s,n)+50;return-o}}getLevelGap(e,t){var o;let n=t;if(((o=this.layoutOptions.levelGaps)==null?void 0:o.length)>0){const s=this.layoutOptions.levelGaps[Math.abs(e)];s&&(n=s)}return n}}const ft=Hn,ae=l=>!l||l.length===0?"":l.map(i=>{switch(i.type){case"M":return`${i.type} ${i.x} ${i.y}`;case"l":return`${i.type} ${i.dx} ${i.dy}`;case"L":return`${i.type} ${i.x} ${i.y}`;case"h":return`${i.type} ${i.dx}`;case"v":return`${i.type} ${i.dy}`;case"c":return`${i.type} ${i.dx1} ${i.dy1} ${i.dx2} ${i.dy2} ${i.dx} ${i.dy}`;case"s":return`${i.type} ${i.dx2} ${i.dy2} ${i.dx} ${i.dy}`;case"q":return`${i.type} ${i.dx1} ${i.dy1} ${i.dx} ${i.dy}`;case"Q":return`${i.type} ${i.x1} ${i.y1} ${i.x} ${i.y}`;case"t":return`${i.type} ${i.dx} ${i.dy}`;case"a":return`${i.type} ${i.rx} ${i.ry} ${i.xAxisRotation} ${i.largeArcFlag} ${i.sweepFlag} ${i.dx} ${i.dy}`;case"Z":return i.type;default:return console.warn("\u672A\u77E5\u7684\u8DEF\u5F84\u547D\u4EE4\u7C7B\u578B:",i),""}}).join(" ").trim(),pt=l=>{const i=l.match(/[a-zA-Z][^a-zA-Z]*/g);let e=0,t=0,n=0,o=0,s=0,a=0,d=0,h=0;const c={x:0,y:0},f={x:0,y:0},p=[];for(const m of i){const u=m.trim().split(/[ ,]+/),g=u[0].toUpperCase(),y=u[0]===u[0].toLowerCase();switch(g){case"M":e=U(n,u[1],y),t=U(o,u[2],y),n=e,o=t;break;case"L":e=U(n,u[1],y),t=U(o,u[2],y),p.push({x:e,y:t});break;case"C":s=U(n,u[1],y),a=U(o,u[2],y),d=U(n,u[3],y),h=U(o,u[4],y),e=U(n,u[5],y),t=U(o,u[6],y),n=e,o=t;break;case"Q":s=U(n,u[1],y),a=U(o,u[2],y),e=U(n,u[3],y),t=U(o,u[4],y),n=e,o=t;break;case"V":t=U(o,u[1],y),o=t;break;case"H":e=U(n,u[1],y),n=e;break;case"Z":break;default:console.log(`Unsupported command: ${g}`)}m===i[0]&&(c.x=e,c.y=t),m===i[i.length-1]&&(f.x=e,f.y=t)}return{startPoint:c,ctrl1:{x:s,y:a},ctrl2:{x:d,y:h},endPoint:f,lines:p}},U=(l,i,e)=>e?l+parseFloat(i):parseFloat(i),$n=(l,i,e,t,n,o,s)=>{const a=JSON.parse(JSON.stringify(l));let d=!1;if(e<0||e>=l.length-1)return{newPoints:a,pointsChanged:d};a[e-1];const h=a[e],c=a[e+1];i[e-1];const f=i[e];i[e+1];let p=o,m=s;if(t.direction==="v"){const u=i[e-2],g=i[e+2],y=f.x+p;let v=3e3;if(u){const x=Math.abs(u.x-y);x<10&&x<v&&(v=x,p=u.x-f.x)}if(g){const x=Math.abs(g.x-y);x<10&&x<v&&(v=x,p=g.x-f.x)}}else{const u=i[e-2],g=i[e+2],y=f.y+m;let v=3e3;if(u){const x=Math.abs(u.y-y);x<10&&x<v&&(v=x,m=u.y-f.y)}if(g){const x=Math.abs(g.y-y);x<10&&x<v&&(v=x,m=g.y-f.y)}}if(t.direction==="v")if(e===0){const u=h.y<c.y?1:-1,g={x:h.x,y:h.y},y={x:h.x,y:h.y+20*u};h.x=y.x+p,h.y=y.y,a.splice(e,0,g,y),n.indexOffset+=2,d=!0}else if(e===l.length-2){const u=h.y<c.y?1:-1,g={x:f.x+p,y:c.y-20*u},y={x:c.x,y:c.y-20*u};a.splice(e+1,0,g,y),d=!0}else h.x=f.x+p,c.x=f.x+p;else if(e===0){const u=h.x<c.x?1:-1,g={x:h.x,y:h.y},y={x:h.x+20*u,y:h.y};h.x=y.x,h.y=f.y+m,a.splice(e,0,g,y),n.indexOffset+=2,d=!0}else if(e===l.length-2){const u=h.x<c.x?1:-1,g={x:c.x-20*u,y:f.y+m},y={x:c.x-20*u,y:c.y};a.splice(e+1,0,g,y),d=!0}else h.y=f.y+m,c.y=f.y+m;return{newPoints:a,pointsChanged:d}},Yn=(l,i={x:0,y:0,rotate:0})=>{const{fx:e,fy:t,tx:n,ty:o}=l;i.rotate=j.getTextAngle(e,t,n,o),i.x=e+(n-e)/2,i.y=t+(o-t)/2,Number.isNaN(i.rotate)&&(i.rotate=0);const s=n-e,a=o-t,d=[{type:"M",x:e,y:t},{type:"l",dx:s,dy:a}],h=ae(d);return{pathCommands:d,pathData:h,textPosition:i,points:[]}},Wn=(l,i={x:0,y:0,rotate:0},e={})=>{const{line:t,fx:n,fy:o,fcx:s,fcy:a,f_W:d,f_H:h,tx:c,ty:f,tcx:p,tcy:m,t_W:u,t_H:g}=l,y=c-n,v=f-o,x=n-s,w=o-a,k=c-p,T=f-m,O=t.lineRadius!==void 0?t.lineRadius:e.lineRadius||0;let b=Math.min(O,Math.abs(y))*(n<c?1:-1),N=Math.min(O,Math.abs(v))*(o<f?1:-1);const P=t.fromJunctionPoint||e.defaultJunctionPoint||W.border,R=t.toJunctionPoint||e.defaultJunctionPoint||W.border,S=t.lineDirection||(P===W.tb||P===W.top||P===W.bottom?"v":"h")||(Math.abs(x)>=d/2?"h":"v"),M=t.lineDirection||(R===W.tb||R===W.top||R===W.bottom?"v":"h")||(Math.abs(k)>=u/2?"h":"v"),C=[];let E=0,V=0;if(S==="v"){const A=t.polyLineStartDistance||Math.max(Math.min(30,Math.abs(f-o)/2),15),G=w>0?A:-A;if(t.placeText==="start"?(E=n,V=o+(w>0?20:-5)):t.placeText==="center"||t.placeText==="middle"?(E=n+(c-n)/2,V=o+G):(E=c,V=f-(w>0?20:-5)),C.push({type:"M",x:Math.round(n),y:Math.round(o)},{type:"v",dy:Math.round(G-N)},{type:"c",dx1:0,dy1:Math.round(N),dx2:Math.round(b),dy2:Math.round(N),dx:Math.round(b),dy:Math.round(N)}),M==="v")C.push({type:"h",dx:Math.round(c-n-b*2)},{type:"c",dx1:Math.round(b),dy1:0,dx2:Math.round(b),dy2:Math.round(N),dx:Math.round(b),dy:Math.round(N)},{type:"v",dy:Math.round(f-o-G-N)});else{const $=Math.min(30,Math.abs(c-n)/2),J=k>0?-$:$;C.push({type:"h",dx:Math.round(c-n+J-b)},{type:"c",dx1:Math.round(b),dy1:0,dx2:Math.round(b),dy2:Math.round(N),dx:Math.round(b),dy:Math.round(N)},{type:"v",dy:Math.round(f-o-G-N)},{type:"h",dx:Math.round(J-b)})}}else{const A=t.polyLineStartDistance||Math.max(Math.min(30,Math.abs(c-n)/2),15),G=x>0?A:-A;if(t.placeText==="start"?(E=n+(x>0?10:-50),V=o):t.placeText==="center"||t.placeText==="middle"?(E=n+G,V=o+(f-o)/2):(E=c-(x>0?10:-50),V=f),b=Math.min(O,Math.abs(y))*(n>s?1:-1),N=Math.min(O,Math.abs(v))*(o<f?1:-1),C.push({type:"M",x:Math.round(n),y:Math.round(o)},{type:"h",dx:Math.round(G-b)},{type:"c",dx1:Math.round(b),dy1:0,dx2:Math.round(b),dy2:Math.round(N),dx:Math.round(b),dy:Math.round(N)}),M==="v"){b=Math.min(O,Math.abs(y))*(f<m?1:-1),N=Math.min(O,Math.abs(v))*(f<m?1:-1);const $=Math.min(30,Math.abs(f-o)/2),J=T>0?-$:$;C.push({type:"v",dy:Math.round(f-o+J-N)},{type:"h",dx:Math.round(c-n-G-b)},{type:"c",dx1:0,dy1:Math.round(N),dx2:Math.round(b),dy2:Math.round(N),dx:Math.round(b),dy:Math.round(N)},{type:"v",dy:Math.round(J-N)})}else b=Math.min(O,Math.abs(y))*(n+G<c?1:-1),N=Math.min(O,Math.abs(v))*(f>o?1:-1),C.push({type:"v",dy:Math.round(f-o-N*2)},{type:"c",dx1:0,dy1:Math.round(N),dx2:Math.round(b),dy2:Math.round(N),dx:Math.round(b),dy:Math.round(N)},{type:"h",dx:Math.round(c-n-G-b)})}i.x=E,i.y=V;const X=ae(C);return{pathCommands:C,pathData:X,textPosition:i,points:[]}},Se={left:{x:-1,y:0},right:{x:1,y:0},top:{x:0,y:-1},bottom:{x:0,y:1}},Un=({source:l,sourcePosition:i="bottom",target:e})=>i==="left"||i==="right"?l.x<e.x?{x:1,y:0}:{x:-1,y:0}:l.y<e.y?{x:0,y:1}:{x:0,y:-1},ut=(l,i)=>Math.sqrt(Math.pow(i.x-l.x,2)+Math.pow(i.y-l.y,2));function Xe({source:l,sourcePosition:i="bottom",target:e,targetPosition:t="top",center:n,sourceOffset:o,targetOffset:s}){const a=Se[i],d=Se[t],h={x:l.x+a.x*o,y:l.y+a.y*o},c={x:e.x+d.x*s,y:e.y+d.y*s},f=Un({source:h,sourcePosition:i,target:c}),p=f.x!==0?"x":"y",m=f[p];let u=[],g,y;const v={x:0,y:0},x={x:0,y:0};let w=0;if(a[p]*d[p]===-1){g=n.x,y=n.y;const T=[{x:g,y:h.y},{x:g,y:c.y}],O=[{x:h.x,y},{x:c.x,y}];a[p]===m?(w=1.1,u=p==="x"?T:O):(w=1.2,u=p==="x"?O:T)}else{const T=[{x:h.x,y:c.y}],O=[{x:c.x,y:h.y}];if(p==="x"?u=a.x===m?O:T:u=a.y===m?T:O,i===t){w=2.1;const S=Math.abs(l[p]-e[p]),M=a[p]===m?o:s;if(S<=M){const C=Math.min(M-1,M-S);a[p]===m?v[p]=(h[p]>l[p]?-1:1)*C:x[p]=(c[p]>e[p]?-1:1)*C}}if(i!==t){w=2.2;const S=p==="x"?"y":"x",M=a[p]===d[S],C=h[S]>c[S],E=h[S]<c[S];(a[p]===1&&(!M&&C||M&&E)||a[p]!==1&&(!M&&E||M&&C))&&(u=p==="x"?T:O)}const b={x:h.x+v.x,y:h.y+v.y},N={x:c.x+x.x,y:c.y+x.y},P=Math.max(Math.abs(b.x-u[0].x),Math.abs(N.x-u[0].x)),R=Math.max(Math.abs(b.y-u[0].y),Math.abs(N.y-u[0].y));P>=R?(g=(b.x+N.x)/2,y=u[0].y):(g=u[0].x,y=(b.y+N.y)/2)}return[[l,{x:h.x+v.x,y:h.y+v.y},...u,{x:c.x+x.x,y:c.y+x.y},e],g,y,0,0,w]}const Re=l=>{const i=[];for(let e=0;e<l.length;e++){const t=l[e];if(t.x=Math.round(t.x),t.y=Math.round(t.y),e===0||e===l.length-1)i.push(t);else{const n=i[i.length-1];t.x===n.x&&t.y===n.y||i.push(t)}}for(let e=2;e<i.length;e++){const t=i[e-2],n=i[e-1],o=i[e],s=t.x===n.x?"v":"h",a=n.x===o.x?"v":"h";s===a&&(n.merged=!0)}return i.filter(e=>e.merged!==!0)};function Jn(l,i,e,t){const n=Math.min(ut(l,i)/2,ut(i,e)/2,t),{x:o,y:s}=i;if(l.x===o&&o===e.x||l.y===s&&s===e.y)return[{type:"L",x:o,y:s}];if(l.y===s){const h=l.x<e.x?-1:1,c=l.y<e.y?1:-1;return[{type:"L",x:o+n*h,y:s},{type:"Q",x1:o,y1:s,x:o,y:s+n*c}]}const a=l.x<e.x?1:-1,d=l.y<e.y?-1:1;return[{type:"L",x:o,y:s+n*d},{type:"Q",x1:o,y1:s,x:o+n*a,y:s}]}const gt=(l,i)=>{const e=[];return l.forEach((t,n)=>{if(n===0)e.push({type:"M",x:Math.round(t.x),y:Math.round(t.y)});else if(n===l.length-1){const o=l[n-1];let s=o.x===t.x?0:o.x<t.x?-1:1,a=o.y===t.y?0:o.y<t.y?-1:1;l.length===2&&(s=0,a=0),e.push({type:"l",dx:Math.round(t.x-o.x+i*s),dy:Math.round(t.y-o.y+i*a)})}else{const o=Jn(l[n-1],t,l[n+1],i);e.push(...o)}}),e};var re=(l=>(l.border="border",l.ltrb="ltrb",l.tb="tb",l.lr="lr",l.left="left",l.right="right",l.top="top",l.bottom="bottom",l))(re||{});const Me=(l,i,e,t,n,o,s,a)=>l==="left"?"left":l==="right"?"right":l==="top"?"top":l==="bottom"?"bottom":l==="horizontalLine"?t?o>a?"bottom":"top":o<a?"bottom":"top":l==="verticalLine"?t?n>s?"right":"left":n<s?"right":"left":i===1?"right":i===-1?"left":e===1?"bottom":e===-1?"top":"left",mt=l=>l==="left"?"right":l==="right"?"left":l==="top"?"bottom":l==="bottom"?"top":"left",yt=l=>{if(l.length<2)throw new Error("At least two points are required to form a polyline.");let i=0;const e=[];for(let o=1;o<l.length;o++){const s=l[o].x-l[o-1].x,a=l[o].y-l[o-1].y,d=Math.sqrt(s*s+a*a);e.push(d),i+=d}const t=i/2;let n=0;for(let o=0;o<e.length;o++)if(n+=e[o],n>=t){const s=l[o],a=l[o+1],d=e[o],c=(t-(n-d))/d,f=s.x+(a.x-s.x)*c,p=s.y+(a.y-s.y)*c;return{x:f,y:p}}return{x:0,y:0}},jn=(l,i={x:0,y:0,rotate:0},e={})=>{const{line:t,fromJunctionPoint:n,toJunctionPoint:o,lineDirection:s,lineShape:a,fx:d,fy:h,fcx:c,fcy:f,f_W:p,f_H:m,tx:u,ty:g,tcx:y,tcy:v,t_W:x,t_H:w}=l,k=d-c,T=h-f;let O=k>1?1:k<-1?-1:0,b=T>1?1:T<-1?-1:0;Math.abs(O)===1&&Math.abs(b)===1&&(Math.abs(k)>Math.abs(T)?b=0:O=0),O===0&&b===0&&(O=1);const N=u-y,P=g-v;let R=N>1?1:N<-1?-1:0,S=P>1?1:P<-1?-1:0;Math.abs(R)===1&&Math.abs(S)===1&&(Math.abs(N)>Math.abs(P)?S=0:R=0),R===0&&S===0&&(O=-1);const M=Me(n,O,b,!1,d,h,u,g),C=Me(o,R,S,!0,d,h,u,g),E=M,V=C,X=d+(u-d)/2,A=h+(g-h)/2;let G={x:0,y:0},$=20,J=20;t.ctrlOptionsFor44&&(G={x:t.ctrlOptionsFor44.cx,y:t.ctrlOptionsFor44.cy},$+=t.ctrlOptionsFor44.fd,J+=t.ctrlOptionsFor44.td);const ie=t.lineRadius!==void 0?t.lineRadius:e.lineRadius||0,[te]=Xe({source:{x:d,y:h},sourcePosition:E,target:{x:u,y:g},targetPosition:V,center:{x:X+G.x,y:A+G.y},sourceOffset:$,targetOffset:J}),ne=Re(te),Q=gt(ne,ie),Z=ae(Q),oe=yt(te);if(i.x=oe.x,i.y=oe.y,s==="v"){const q=T>1?1:T<-1?-1:0,F=P>1?1:P<-1?-1:0;t.placeText==="start"?(i.x=d,i.y=h+q*10):t.placeText==="end"&&(i.x=u,i.y=g+F*10)}else{const q=k>1?1:k<-1?-1:0,F=N>1?1:N<-1?-1:0;t.placeText==="start"?(i.x=d+q*10,i.y=h):t.placeText==="end"&&(i.x=u+F*10,i.y=g)}return{pathCommands:Q,pathData:Z,textPosition:i,points:ne,startDirection:E,endDirection:V}},qn=(l,i={x:0,y:0,rotate:0},e={})=>{const{line:t,fromJunctionPoint:n,toJunctionPoint:o,lineDirection:s,lineShape:a,fx:d,fy:h,fcx:c,fcy:f,f_W:p,f_H:m,tx:u,ty:g,tcx:y,tcy:v,t_W:x,t_H:w}=l,k=d-c,T=h-f;let O=k>3?1:k<-3?-1:0,b=T>3?1:T<-3?-1:0;Math.abs(O)===1&&Math.abs(b)===1&&(Math.abs(k)>Math.abs(T)?b=0:O=0),O===0&&b===0&&(O=1);const N=u-y,P=g-v;let R=N>3?1:N<-3?-1:0,S=P>3?1:P<-3?-1:0;Math.abs(R)===1&&Math.abs(S)===1&&(Math.abs(N)>Math.abs(P)?S=0:R=0),R===0&&S===0&&(O=-1);let M=Me(n,O,b,!1,d,h,u,g),C=Me(o,R,S,!0,d,h,u,g);const E=t.lineRadius!==void 0?t.lineRadius:e.lineRadius||0,V=t.ctrlPointsFor49;let X={x:Math.round(d),y:Math.round(h)},A={x:Math.round(u),y:Math.round(g)},G={x:Math.round(V[0].x),y:Math.round(V[0].y)},$={x:Math.round(V[V.length-1].x),y:Math.round(V[V.length-1].y)},J=[...V];if(t.isReverse&&([M,C]=[C,M]),Math.abs(X.x-G.x)>3||Math.abs(X.y-G.y)>3){const Z=X.x+(G.x-X.x)/2,oe=X.y+(G.y-X.y)/2,q=mt(M),[F]=Xe({source:X,sourcePosition:M,target:G,targetPosition:q,center:{x:Z,y:oe},sourceOffset:20,targetOffset:5});J=Re([...F,...J])}if(Math.abs(A.x-$.x)>3||Math.abs(A.y-$.y)>3){const Z=$.x+(A.x-$.x)/2,oe=$.y+(A.y-$.y)/2,q=mt(C),[F]=Xe({source:$,sourcePosition:q,target:A,targetPosition:C,center:{x:Z,y:oe},sourceOffset:5,targetOffset:20});J=Re([...J,...F])}const ie=J,te=gt(ie,E),ne=ae(te),Q=yt(V);return i.x=Q.x,i.y=Q.y,{pathCommands:[],pathData:ne,textPosition:i,points:ie,startDirection:M,endDirection:C}},Zn=(l,i={x:0,y:0,rotate:0})=>{const{line:e,lineShape:t,fx:n,fy:o,fcx:s,fcy:a,tx:d,ty:h,tcx:c,tcy:f}=l,p=d-n,m=h-o;let u=n-s,g=o-a,y=d-c,v=h-f,{fromJunctionPoint:x,toJunctionPoint:w}=e;e.isReverse&&([x,w]=[w,x]),(x===W.left||x===W.right)&&(g=0),(x===W.top||x===W.bottom)&&(u=0),(w===W.left||w===W.right)&&(v=0),(w===W.top||w===W.bottom)&&(y=0);const k=Math.min(200,Math.max(100,Math.abs(p/2))),T=Math.min(200,Math.max(100,Math.abs(m/2))),O=u/(Math.abs(u)+Math.abs(g))*k,b=g/(Math.abs(u)+Math.abs(g))*T;let N={x:O,y:b};const P=y/(Math.abs(y)+Math.abs(v))*k+p,R=v/(Math.abs(y)+Math.abs(v))*T+m;let S={x:P,y:R};e.ctrlPoints&&e.ctrlPoints.length>0&&(e.isReverse?(N.x+=e.ctrlPoints[1].x,N.y+=e.ctrlPoints[1].y,S.x+=e.ctrlPoints[0].x,S.y+=e.ctrlPoints[0].y):(N.x+=e.ctrlPoints[0].x,N.y+=e.ctrlPoints[0].y,S.x+=e.ctrlPoints[1].x,S.y+=e.ctrlPoints[1].y));const M={x:n+N.x,y:o+N.y},C={x:n+S.x,y:o+S.y},E={x:n+p,y:o+m},V=[{type:"M",x:n,y:o},{type:"c",dx1:N.x,dy1:N.y,dx2:S.x,dy2:S.y,dx:p,dy:m}];t===8&&V.push({type:"Z"});const X=vt({x:n,y:o},M,C,E,t<6?.8:.5);i.x=X.x,i.y=X.y;const A=ae(V);return{pathCommands:V,pathData:A,textPosition:i,points:[]}},vt=(l,i,e,t,n=.5)=>{const o={x:(1-n)*l.x+n*i.x,y:(1-n)*l.y+n*i.y},s={x:(1-n)*i.x+n*e.x,y:(1-n)*i.y+n*e.y},a={x:(1-n)*e.x+n*t.x,y:(1-n)*e.y+n*t.y},d={x:(1-n)*o.x+n*s.x,y:(1-n)*o.y+n*s.y},h={x:(1-n)*s.x+n*a.x,y:(1-n)*s.y+n*a.y};return{x:(1-n)*d.x+n*h.x,y:(1-n)*d.y+n*h.y}},Kn=(l,i={x:0,y:0,rotate:0})=>{const{line:e,totalLinesBetweenNodes:t,currentLineIndex:n,lineDirection:o,lineShape:s,fx:a,fy:d,fcx:h,fcy:c,f_W:f,f_H:p,tx:m,ty:u,tcx:g,tcy:y,t_W:v,t_H:x}=l,w=m-a,k=u-d,T=m>a?1:-1,O=u>d?1:-1,b=o==="v"?O:T,N=a-h,P=d-c,R=m-g,S=u-y,M=1/(t+1)*(n+1);let C={x:0,y:0},E={x:0,y:0};if(s===Y.Curve2)C=o==="v"?{x:0,y:b*30}:{x:b*30,y:0},E=o==="v"?{x:w*M,y:b*-10}:{x:b*-10,y:k*M};else if(s===Y.Curve3)C=o==="v"?{x:0,y:k*M}:{x:b*30,y:0},E=o==="v"?{x:0,y:0}:{x:b*-10,y:k*M};else if(s===Y.Curve5)C={x:0,y:0},E=o==="v"?{x:0,y:k*M}:{x:w*M,y:0};else if(s===Y.Curve7||s===Y.Curve8){const ne=N/(Math.abs(N)+Math.abs(P))*30,Q=P/(Math.abs(N)+Math.abs(P))*30;C={x:ne,y:Q};const Z=R/(Math.abs(R)+Math.abs(S))*30+w,oe=S/(Math.abs(R)+Math.abs(S))*30+k;E={x:Z,y:oe}}const V={x:a+C.x,y:d+C.y},X={x:a+E.x,y:d+E.y},A={x:a+w,y:d+k},G=[{type:"M",x:a,y:d},{type:"c",dx1:C.x,dy1:C.y,dx2:E.x,dy2:E.y,dx:w,dy:k}];s===8&&G.push({type:"Z"});const $=vt({x:a,y:d},V,X,A,s<6?.8:.5);i.x=$.x,i.y=$.y;const J=ae(G);return{pathCommands:G,pathData:J,textPosition:i,points:[]}};class Qn{constructor(){_(this,"graphData",{rootNode:void 0,nodes:[],normalLines:[],fakeLines:[]});_(this,"options",{});_(this,"runtimeDATA4NodeMap",new Map);_(this,"runtimeDATA4Links",[]);_(this,"runtimeDATA4LinkMap",new Map);_(this,"runtimeDATA4ConnectTargets",[]);_(this,"runtimeDATA4ElLineTargets",[]);_(this,"runtimeDATA4ShouldRenderItems",{nodes:[],lines:[],fakeLines:[]})}}class eo extends Qn{constructor(){super()}getOptions(){return this.options}getNodeById(i){return this.runtimeDATA4NodeMap.get(i)}getLineById(i){var e;return(e=this.runtimeDATA4LinkMap.get(i))==null?void 0:e.line}getLinkByLineId(i){return this.runtimeDATA4LinkMap.get(i)}getFakeLineById(i){return this.graphData.fakeLines.find(e=>e.id===i)}getNodes(){return this.graphData.nodes}getLinks(){return this.runtimeDATA4Links}getFakeLines(){return this.graphData.fakeLines}getLines(){return this.runtimeDATA4Links.map(i=>i.line)}getRootNode(){return this.graphData.rootNode}getShouldRenderNodes(){return this.isPerformanceMode()?this.runtimeDATA4ShouldRenderItems.nodes:this.graphData.nodes}getShouldRenderLines(){return this.isPerformanceMode()?this.runtimeDATA4ShouldRenderItems.lines:this.graphData.normalLines}getShouldRenderFakeLines(){return this.isPerformanceMode()?this.runtimeDATA4ShouldRenderItems.fakeLines:this.graphData.fakeLines}isPerformanceMode(){return this.options.performanceMode}getCanvasScale(){return this.options.canvasZoom/100}getConnectTargets(){return this.runtimeDATA4ConnectTargets}getConnectTargetById(i){if(!i)throw new Error("[getConnectTargetById]targetId is empty");for(let e=0;e<this.runtimeDATA4ConnectTargets.length;e++){const t=this.runtimeDATA4ConnectTargets[e];if(t.targetId===i)return t}}getElLineTargets(){return this.runtimeDATA4ElLineTargets}getElLineTargetById(i){return this.runtimeDATA4ElLineTargets.find(e=>e.id===i)}calcShouldRenderNodes(){const i=[];return this.graphData.nodes.forEach(e=>{e.rgShouldRender!==!1&&e.rgCalcedVisibility!==!1&&i.push(e)}),i}calcShouldRenderLines(){const i=[];return this.runtimeDATA4Links.forEach(e=>{e.rgShouldRender!==!1&&e.line.hidden!==!0&&e.rgCalcedVisibility!==!1&&i.push(e.line)}),i}calcShouldRenderFakeLines(){return this.graphData.fakeLines}findNodeByXy(i){const e=this.graphData.nodes;for(let t=e.length-1;t>=0;t--){const n=e[t],o=n.x,s=n.y,a=n.el_W||n.width||50,d=n.el_H||n.height||50;if(i.x>o&&i.x<o+a&&i.y>s&&i.y<s+d)return n}return null}}class to{constructor(){_(this,"map");this.map=new Map}_key(i,e){return i<=e?`${i}${e}`:`${e}${i}`}addEdge(i,e){const t=this._key(i,e),n=this.map.get(t)||0;return this.map.set(t,n+1),n}getCount(i,e){const t=this._key(i,e);return this.map.get(t)||0}clear(){this.map.clear()}}const Ge=(l={})=>{const i={definitelyNoDataProviderNeeded:!1,instanceId:"",debug:!0,graphLoading:!1,graphLoadingText:"",showToolBar:!0,backgroundColor:"transparent",checkedItemBackgroundColor:void 0,selectionMode:!1,disableWheelEvent:!1,wheelEventAction:"zoom",dragEventAction:"move",fullscreenElementXPath:"",disableDragNode:!1,disableDragLine:!0,canvasMoveMode:!1,disableNodePointEvent:!1,disableLinePointEvent:!1,enableNodeXYAnimation:!1,enableCanvasTransformAnimation:!1,reLayoutWhenExpandedOrCollapsed:!1,defaultExpandHolderPosition:"hide",toolBarDirection:"h",toolBarPositionH:"left",toolBarPositionV:"bottom",defaultNodeColor:"#ffffff",defaultNodeBorderColor:"#666666",defaultNodeBorderWidth:1,defaultNodeBorderRadius:4,defaultNodeShape:xe.rect,defaultNodeWidth:void 0,defaultNodeHeight:void 0,defaultLineColor:"#cccccc",defaultLineWidth:2,defaultLineShape:Y.StandardStraight,defaultLineTextOffsetX:void 0,defaultLineTextOffsetY:void 0,defaultJunctionPoint:W.border,defaultLineJunctionOffset:3,defaultPolyLineRadius:5,placeOtherGroup:!0,defaultLineTextOnPath:!1,lineTextMaxLength:66,multiLineDistance:30,defaultLineMarker:{viewBox:"0 0 12 12",markerWidth:20,markerHeight:20,refX:3,refY:3,data:"M 0 0, V 6, L 4 3, Z"},viewSize:{width:300,height:300},canvasSize:{width:300,height:300},canvasOffset:{x:25,y:27},fullscreen:!1,checkedNodeId:"",checkedLineId:"",draggingNodeId:"",layout:{layoutName:"center"},canvasZoom:100,mouseWheelSpeed:10,minCanvasZoom:5,maxCanvasZoom:500,showEasyView:!1,performanceMode:!1,viewHeight:"100%",canvasOpacity:1,creatingSelection:!1,selectionView:{x:25,y:27,width:0,height:0},creatingNodePlot:!1,showTemplateNode:!0,newNodeTemplate:we(JSON.parse(JSON.stringify(De)),{}),creatingLinePlot:!1,newLineTemplate:{from:"newRelationTemplate-from",to:"newRelationTemplate-to",color:"",text:""},newLinkTemplate:{fromNode:null,toNodeObject:null,toNode:{nothing:!0,x:400,y:400,el_W:30,el_H:30},totalLinesBetweenNodes:1,currentLineIndex:0,line:{}},data:{},editingLineController:{show:!1,line:null,startPoint:{x:0,y:0},endPoint:{x:0,y:0},text:{show:!0,x:0,y:0,width:10,height:10},ctrlPoints:[],selectedLines:[],line44Splits:[],line49Points:[],ctrlPoint1:{x:0,y:0},ctrlPoint2:{x:0,y:0},toolbar:{x:0,y:0}},editingController:{show:!1,nodes:[],x:0,y:0,width:100,height:100},nodeConnectController:{show:!1,node:void 0,x:0,y:0,width:100,height:100},showReferenceLine:!1,referenceLineAdsorption:!1,editingReferenceLine:{show:!1,directionV:!1,directionH:!1,v_x:0,v_y:0,v_height:0,h_x:0,h_y:0,h_width:0},showMiniView:!1,miniViewVisibleHandle:{x:0,y:0,width:100,height:100,emptyContent:!1},snapshotting:!1};i.newLineTemplate=he(i.newLineTemplate,i);const e=Object.keys(i);return l&&Object.keys(l).forEach(t=>{const n=l[t];if(!e.includes(t)){L("RGOptions: unknow option key:",t);return}if(typeof n=="object"){L("RGOptions:user setting object:",t,n);const o=i[t];if(t==="layout")i[t]=JSON.parse(JSON.stringify(n));else if(o&&!Array.isArray(o)&&n)Object.keys(o).forEach(s=>{o[s]=n[s]});else if(Array.isArray(o)){const s=[];n.forEach(a=>{a&&typeof a=="object"?s.push(JSON.parse(JSON.stringify(a))):s.push(a)}),i[t]=s}else i[t]=n}else i[t]=n}),i},xt=l=>{const i=l.layoutName||"";if(i==="center"){const e=l;e.layoutDirection=void 0}else if(i.includes("tree")){const e=l;e.from===void 0&&(e.from="left"),e.levelGaps===void 0&&(e.levelGaps=[]),(e.from==="top"||e.from==="bottom")&&(e.layoutDirection===void 0&&(e.layoutDirection="v"),L("set layoutDirection=v"),L("set defaultJunctionPoint=tb")),(e.from==="left"||e.from==="right")&&(e.layoutDirection===void 0&&(e.layoutDirection="h"),L("set defaultJunctionPoint=lr"))}else(i==="fixed"||i==="force")&&(l.layoutDirection=void 0)},no=Object.freeze(Object.defineProperty({__proto__:null,createDefaultConfig:Ge,appendDefaultOptions4Layout:xt,default:{createDefaultConfig:Ge}},Symbol.toStringTag,{value:"Module"}));class Oe extends eo{constructor(){super();_(this,"commits");_(this,"updateViewHook",e=>{});this.options=Ge({}),this.commits=this.resetCommints()}clearReactiveData(){this.graphData.nodes=[],this.graphData.normalLines=[],this.graphData.fakeLines=[],this.runtimeDATA4Links.splice(0,this.runtimeDATA4Links.length),this.runtimeDATA4ElLineTargets.splice(0,this.runtimeDATA4ElLineTargets.length),this.runtimeDATA4NodeMap.clear(),this.runtimeDATA4LinkMap.clear(),this.graphData.rootNode=void 0,this.updateShouldRenderGraphData(),this.commits.optionsChanged=!0,this.commits.nodesListChanged=!0,this.commits.linesListChanged=!0,this.commits.fakeLinesListChanged=!0}resetCommints(){return{optionsChanged:!1,changedNodes:[],nodesListChanged:!1,changedLines:[],linesListChanged:!1,changedFakeLines:[],fakeLinesListChanged:!1,changedConnectTargets:[],connectTargetsListChanged:!1}}commitLine(e){this.commits.linesListChanged=!0}commitNode(e){this.commits.changedNodes.includes(e)||this.commits.changedNodes.push(e),this.commits.linesListChanged=!0,this.commits.fakeLinesListChanged=!0}commitFakeLine(e){this.commits.fakeLinesListChanged=!0}commitConnectTarget(e){this.commits.changedConnectTargets.includes(e)||this.commits.changedConnectTargets.push(e),this.commits.fakeLinesListChanged=!0}dataUpdated(){const e=this.commits;this.commits=this.resetCommints(),this.updateViewHook(e)}updateOptions(e){if(e.layout,Object.assign(this.options,e),this.isPerformanceMode()&&!this.options.showEasyView){const t=Object.keys(e);t.includes("canvasZoom")&&(this.commits.nodesListChanged=!0,this.commits.linesListChanged=!0),t.includes("viewSize")&&(this.commits.nodesListChanged=!0,this.commits.linesListChanged=!0),t.includes("canvasOffset")&&(this.commits.nodesListChanged=!0,this.commits.linesListChanged=!0)}this.commits.optionsChanged=!0}clearChecked(){this.updateOptions({checkedNodeId:"",checkedLineId:""})}setCanvasOffset(e,t){this.updateOptions({canvasOffset:{x:e,y:t}}),this.commits.optionsChanged=!0}setCanvasZoom(e){this.updateOptions({canvasZoom:e})}setEditingLine(e){if(e){const t=this.getLineById(e.id)||this.getFakeLineById(e.id);t&&this.updateOptions({editingLineController:{...this.options.editingLineController,line:t,show:!0},checkedLineId:e.id})}else this.updateOptions({editingLineController:{...this.options.editingLineController,line:null,show:!1},checkedLineId:""})}setEditingNodes(e){for(const n of e)if(!n||!this.getNodeById(n.id)){console.error("setEditingNodes Error: node not found:",n);return}this.getNodes().filter(n=>n.selected).forEach(n=>this.updateNode(n.id,{selected:!1})),this.updateOptions({editingController:{...this.options.editingController,nodes:e,show:e.length>0}}),e.length>1&&this.options.editingController.nodes.forEach(n=>this.updateNode(n.id,{selected:!0}))}setCanvasCenter(e,t){const n=this.options.viewSize.width/2,o=this.options.viewSize.height/2,s=this.options.canvasZoom/100;this.setCanvasOffset(n-e*s,o-t*s)}removeNodeById(e){this.beforeNodeBeRemove(e);let t=0;for(let n=0;n<this.graphData.nodes.length;n++)e.includes(this.graphData.nodes[n].id)&&(this.graphData.nodes.splice(n,1),n--,t++);for(const n of e)this.runtimeDATA4NodeMap.delete(n);L("Removed node\uFF1A",e,t),this.commits.nodesListChanged=!0}removeLineByIds(e){L("_removeLineByIds:",e.length,e),this.removeFakeLineByIds(e);let t=0;for(let n=0;n<this.graphData.normalLines.length;n++){const o=this.graphData.normalLines[n];e.includes(o.id)&&(this.graphData.normalLines.splice(n,1),n--,t++)}L("_removeLineByIds:",t),this.removeLinkByLineIds(e),this.updateLinks(),this.commits.linesListChanged=!0}removeFakeLineByIds(e){L("_removeFakeLineByIds:",e.length,e);let t=0;for(let n=0;n<this.graphData.fakeLines.length;n++){const o=this.graphData.fakeLines[n];e.includes(o.id)&&(this.graphData.fakeLines.splice(n,1),n--,t++)}this.commits.fakeLinesListChanged=!0,L("_removeFakeLineByIds:",t)}removeLinkByLineIds(e){L("_removeLinkByLineIds:",e.length,e);let t=0;for(let n=0;n<this.runtimeDATA4Links.length;n++){const o=this.runtimeDATA4Links[n];e.includes(o.lineId)&&(this.runtimeDATA4Links.splice(n,1),this.runtimeDATA4LinkMap.delete(o.lineId),n--,t++)}this.commits.fakeLinesListChanged=!0,L("_removeLinkByLineIds:",t)}removeConnectTarget(e){const t=this.runtimeDATA4ConnectTargets.findIndex(n=>n.targetId===e);if(t!==-1){const n=this.runtimeDATA4ConnectTargets[t];(n.targetType===D.NodePoint||n.targetType===D.CanvasPoint)&&this.runtimeDATA4ConnectTargets.splice(t,1)}this.commits.connectTargetsListChanged=!0}updateLinks(e=[]){const t=new to;for(const n of this.runtimeDATA4Links){const{from:o,to:s}=n.line,a=t.addEdge(o,s);a!==n.currentLineIndex&&(n.currentLineIndex=a,this.commitLine(n.lineId))}for(const n of this.runtimeDATA4Links){const{from:o,to:s}=n.line,a=t.getCount(o,s);a!==n.totalLinesBetweenNodes&&(n.totalLinesBetweenNodes=a,this.commitLine(n.lineId))}t.clear()}beforeNodeBeRemove(e){for(let t=0;t<this.runtimeDATA4Links.length;t++){const n=this.runtimeDATA4Links[t];(e.includes(n.fromNode.id)||e.includes(n.toNode.id))&&(L("Removed Node-line\uFF1A",n.lineId),this.removeLineByIds([n.lineId]),t--)}for(let t=0;t<this.graphData.fakeLines.length;t++){const n=this.graphData.fakeLines[t];let o=!1;if(n.fromType===D.Node&&e.includes(n.from))o=!0;else if(n.fromType===D.CanvasPoint||n.fromType===D.NodePoint){const s=this.getConnectTargetById(n.from);s&&s.nodeId&&e.includes(s.nodeId)&&(o=!0)}else if(n.toType===D.CanvasPoint||n.toType===D.NodePoint){const s=this.getConnectTargetById(n.to);s&&s.nodeId&&e.includes(s.nodeId)&&(o=!0)}o&&(this.graphData.fakeLines.splice(t,1),L("Removed Node-fakeLine\uFF1A",n.id),t--,this.commits.fakeLinesListChanged=!0)}L("Removed Node connect-target\uFF1A");for(let t=0;t<this.runtimeDATA4ConnectTargets.length;t++){const n=this.runtimeDATA4ConnectTargets[t];n.nodeId&&e.includes(n.nodeId)&&(this.runtimeDATA4ConnectTargets.splice(t,1),L("Removed Node-connect-target\uFF1A",n.targetId),this.commitConnectTarget(n.targetId),t--)}}addFakeLines(e){for(const t of e)if(t.id||console.warn("[relation-graph]Must have id for fake line:",t),this.graphData.fakeLines.some(n=>n.id===t.id))console.log("[relation-graph]Ignore duplicate fake line id:",t.id);else{t.isFakeLine=!0;const n=he(t,this.options);n.id||(n.id=Ie(6)),this.graphData.fakeLines.push(n)}this.commits.fakeLinesListChanged=!0}clearFakeLines(){this.graphData.fakeLines.splice(0,this.graphData.fakeLines.length),this.commits.fakeLinesListChanged=!0}addNodes(e){for(const t of e)this.runtimeDATA4NodeMap.set(t.id,t);this.graphData.nodes.push(...e.map(t=>this.runtimeDATA4NodeMap.get(t.id))),this.commits.nodesListChanged=!0}addLines(e){this.graphData.normalLines.push(...e);const t=[];for(const n of e){const o=this.getNodeById(n.from),s=this.getNodeById(n.to),a={lineId:n.id,line:n,fromNode:o,toNode:s,currentLineIndex:0,totalLinesBetweenNodes:1,rgShouldRender:!0,rgCalcedVisibility:!0};this.runtimeDATA4LinkMap.set(a.lineId,a),t.push(a)}this.runtimeDATA4Links.push(...t.map(n=>this.runtimeDATA4LinkMap.get(n.lineId))),this.updateLinks(),this.commits.linesListChanged=!0}updateNode(e,t){const n=this.getNodeById(e);if(!n){console.error("Cannot find node to update:",e,t);return}const o=t.hidden!==void 0&&n.hidden!==t.hidden;if(Object.assign(n,t,{id:e}),o){const s=Le.getDescendantNodes(n);this.updateNodesVisibleProperty([n].concat(s))}this.commitNode(e)}updateNodeData(e,t){const n=this.getNodeById(e);if(!n){console.error("Cannot find node to update:",e);return}this.updateNode(e,{data:Object.assign(n.data||{},t)})}updateLine(e,t){const n=this.getLineById(e);if(!n){this.updateFakeLine(e,t);return}Object.assign(n,t,{id:e}),this.commitLine(e)}updateLineData(e,t){const n=this.getLineById(e);if(!n){console.error("Cannot find line to update:",e);return}this.updateLine(e,{data:Object.assign(n.data||{},t)})}updateFakeLine(e,t){const n=this.getFakeLineById(e);if(!n){console.error("Cannot find fakeLine to update:",e,t);return}Object.assign(n,t,{id:e}),this.commitFakeLine(e)}updateConnectTarget(e,t){const n=this.getConnectTargetById(e);!n||(Object.assign(n,t,{targetId:e}),this.commitConnectTarget(e))}updateElLineTarget(e,t){const n=this.getElLineTargetById(e);!n||Object.assign(n,t,{id:e})}updateNodesVisibleProperty(e){let t=!1;e||(e=this.getNodes(),t=!0);for(const n of e){const o=Le.isVisibleNode(n);n.rgCalcedVisibility!==o&&(n.rgCalcedVisibility=o,this.commitNode(n.id))}for(const n of this.runtimeDATA4Links)if(t||e.includes(n.fromNode)||e.includes(n.toNode)){const s=this.calcLinkVisibility(n);n.rgCalcedVisibility=s,this.commitLine(n.lineId)}}calcLinkVisibility(e){return e.fromNode.rgCalcedVisibility&&e.toNode.rgCalcedVisibility}updateShouldRenderGraphData(){const e=this.options,t=e.canvasZoom/100,n={x:-e.canvasOffset.x/t,y:-e.canvasOffset.y/t},o={x:n.x+e.viewSize.width/t,y:n.y+e.viewSize.height/t},s=e.snapshotting;for(const a of this.getNodes()){let d=!0;s||a.alwaysRender?d=!0:((a.x>o.x||a.y>o.y)&&(d=!1),(a.x+a.el_W<n.x||a.y+a.el_H<n.y)&&(d=!1)),a.rgShouldRender=d}for(const a of this.runtimeDATA4Links){if(s){a.rgShouldRender=!0;continue}a.rgShouldRender=a.fromNode.rgShouldRender||a.toNode.rgShouldRender}this.options.showEasyView?(this.runtimeDATA4ShouldRenderItems.nodes=[],this.runtimeDATA4ShouldRenderItems.lines=[],this.runtimeDATA4ShouldRenderItems.fakeLines=[]):(this.runtimeDATA4ShouldRenderItems.nodes=this.calcShouldRenderNodes(),this.runtimeDATA4ShouldRenderItems.lines=this.calcShouldRenderLines(),this.runtimeDATA4ShouldRenderItems.fakeLines=this.calcShouldRenderFakeLines())}addConnectTarget(e){return this.runtimeDATA4ConnectTargets.push(e),this.commits.connectTargetsListChanged=!0,this.commits.fakeLinesListChanged=!0,this.getConnectTargetById(e.targetId)}addElLineTarget(e){this.runtimeDATA4ElLineTargets.push(e),this.commits.fakeLinesListChanged=!0}setRootNodeId(e){if(this.graphData.rootNode=this.graphData.nodes.find(t=>t.id===e),!this.graphData.rootNode)throw new Error("The root node [rootId] is not set! Or cannot get the root node:"+e+", If you don't have any nodes to display, you can simply set an invisible node: {id:'root', opacity:0}")}}class oo{constructor(){_(this,"listeners");_(this,"useReactiveDataToAutoUpdateView",!1);_(this,"instanceId");_(this,"dataProvider");_(this,"options");_(this,"_dataUpdatedRequested",!1);_(this,"eventHandlers",[]);_(this,"_emitHook");this.dataProvider=new Oe,this.options=this.dataProvider.getOptions(),this.listeners={},this.instanceId="RG-"+this.generateNewUUID(5)}generateNewUUID(i=5){return Ie(i)}enableDebugLog(i){this.dataProvider.updateOptions({debug:i}),window&&(window.relationGraphDebug=i)}_dataUpdated(){this._requestDataUpdate()}_requestDataUpdate(){!window||!window.requestAnimationFrame||this._dataUpdatedRequested||(this._dataUpdatedRequested=!0,requestAnimationFrame(this._doSomethingAfterDataUpdated.bind(this)))}_doSomethingAfterDataUpdated(){try{!this.useReactiveDataToAutoUpdateView||this.dataProvider.isPerformanceMode()?(this._previousUpdateTime=Date.now(),this.updateShouldRenderGraphData(),this.updateEasyView(),this.dataProvider&&this.dataProvider.dataUpdated()):this.updateMiniView()}catch(i){console.error("[relation-graph]Error:",i)}finally{this._dataUpdatedRequested=!1}}addEventHandler(i){this.eventHandlers.includes(i)||this.eventHandlers.push(i)}removeEventHandler(i){const e=this.eventHandlers.indexOf(i);e!==-1&&this.eventHandlers.splice(e,1)}setEventEmitHook(i){this._emitHook=i}emitEvent(i,...e){let{result:t,handled:n}=this.defaultEventHandler(i,...e);for(const o of this.eventHandlers){const s=o(i,...e);s!==void 0&&(t=s,n=!0)}if(n||this._emitHook&&this._emitHook(i,...e,o=>{o!==void 0&&(t=o)}),t!==void 0)return L("[custom event hook]Event:",i," => returnValue:",t),t}defaultEventHandler(i,...e){let t,n=!1;if(i===I.onReady)this.listeners.onReady&&(n=!0,this.listeners.onReady(this));else if(i===I.onNodeDragStart)this.listeners.onNodeDragStart&&(n=!0,this.listeners.onNodeDragStart(e[0],e[1]));else if(i===I.onNodeDragging){if(this.listeners.onNodeDragging){n=!0;const o=e[0],s=e[1],a=e[2],d=e[3],h=e[4],c=e[5];t=this.listeners.onNodeDragging(o,s,a,d,h,c)}}else if(i===I.onCanvasDragging){if(this.listeners.onCanvasDragging){n=!0;const o=e[0],s=e[1],a=e[2],d=e[3];t=this.listeners.onCanvasDragging(o,s,a,d)}}else if(i===I.onNodeDragEnd){const o=e[0],s=e[1],a=e[2],d=e[3];this.listeners.onNodeDragEnd&&(n=!0,this.listeners.onNodeDragEnd(o,s,a,d))}else if(i===I.onZoomEnd)this.listeners.onZoomEnd&&(n=!0,this.listeners.onZoomEnd());else if(i===I.onNodeClick){if(this.listeners.onNodeClick){n=!0;const o=e[0],s=e[1];this.listeners.onNodeClick(o,s)}}else if(i===I.onLineClick){if(this.listeners.onLineClick){n=!0;const o=e[0],s=e[1],a=e[2];this.listeners.onLineClick(o,s,a)}}else if(i===I.onNodeExpand){if(this.listeners.onNodeExpand){n=!0;const o=e[0],s=e[1];this.listeners.onNodeExpand(o,s)}}else if(i===I.onNodeCollapse){if(this.listeners.onNodeCollapse){n=!0;const o=e[0],s=e[1];this.listeners.onNodeCollapse(o,s)}}else if(i===I.onCanvasDragEnd){if(this.listeners.onCanvasDragEnd){n=!0;const o=e[0];this.listeners.onCanvasDragEnd(o)}}else if(i===I.onCanvasClick){if(this.listeners.onCanvasClick){n=!0;const o=e[0];this.listeners.onCanvasClick(o)}}else if(i===I.onCanvasSelectionEnd){if(this.listeners.onCanvasSelectionEnd){n=!0;const o=e[0],s=e[1];this.listeners.onCanvasSelectionEnd(o,s)}}else if(i===I.onContextmenu){if(this.listeners.onContextmenu){n=!0;const o=e[0],s=e[1],a=e[2],d=e[3],h=e[4];this.listeners.onContextmenu(o,s,a,d,h)}}else if(i===I.onFullscreen){if(this.listeners.onFullscreen){n=!0;const o=e[0],s=e[1];t=this.listeners.onFullscreen(o,s)}}else if(i===I.beforeAddNodes){if(this.listeners.beforeAddNodes){n=!0;const o=e[0];t=this.listeners.beforeAddNodes(o)}}else if(i===I.beforeAddLines){if(this.listeners.beforeAddLines){n=!0;const o=e[0];t=this.listeners.beforeAddLines(o)}}else if(i===I.onKeyboardDown){if(this.listeners.onKeyboardDown){n=!0;const o=e[0];t=this.listeners.onKeyboardDown(o)}}else if(i===I.onKeyboardUp){if(this.listeners.onKeyboardUp){n=!0;const o=e[0];t=this.listeners.onKeyboardUp(o)}}else if(i===I.onLineBeCreated){if(this.listeners.onLineBeCreated){n=!0;const o=e[0];t=this.listeners.onLineBeCreated(o)}}else if(i===I.onCanvasDragStart){if(this.listeners.onCanvasDragStart){n=!0;const o=e[0],s=e[1],a=e[2];t=this.listeners.onCanvasDragStart(o,s,a)}}else if(i===I.onResizeEnd){if(this.listeners.onResizeEnd){n=!0;const o=e[0],s=e[1],a=e[2],d=e[3];t=this.listeners.onResizeEnd(o,s,a,d)}}else if(i===I.onResizeStart){if(this.listeners.onResizeStart){n=!0;const o=e[0],s=e[1];t=this.listeners.onResizeStart(o,s)}}else if(i===I.beforeNodeResize){if(this.listeners.beforeNodeResize){n=!0;const o=e[0],s=e[1],a=e[2],d=e[3],h=e[4];t=this.listeners.beforeNodeResize(o,s,a,d,h)}}else if(i===I.onViewResize&&this.listeners.onViewResize){n=!0;const o=e[0];t=this.listeners.onViewResize(o)}return{result:t,handled:n}}setEventListener(i){Object.assign(this.listeners,i)}}class io extends oo{constructor(){super(...arguments);_(this,"$dom");_(this,"$canvasDom");_(this,"_rgAsConnectArea",!1);_(this,"$lineTextContainer4NormalLine");_(this,"$lineTextContainer4FakeLine");_(this,"viewBoundingClientRect",null)}getLineTextContainer(e){if(!(!e||!this.$canvasDom))return e.isFakeLine?(this.$lineTextContainer4NormalLine||(this.$lineTextContainer4NormalLine=this.$canvasDom.querySelector(".rg-lines-container-el-lines .rg-linetext-container"),this.dataStores.textContainer4NormalRef&&(this.dataStores.textContainer4NormalRef.value=this.$lineTextContainer4NormalLine)),this.$lineTextContainer4NormalLine):(this.$lineTextContainer4FakeLine||(this.$lineTextContainer4FakeLine=this.$canvasDom.querySelector(".rg-lines-container-normal-lines .rg-linetext-container"),this.dataStores.textContainer4FakeLineRef&&(this.dataStores.textContainer4FakeLineRef.value=this.$lineTextContainer4FakeLine)),this.$lineTextContainer4FakeLine)}getViewBoundingClientRect(){var t;if(!this.$dom)return this.viewBoundingClientRect||console.error("[getViewBoundingClientRect] RelationGraph DOM is not set yet!"),this.viewBoundingClientRect;const e=(t=this.$dom)==null?void 0:t.getBoundingClientRect();return this.viewBoundingClientRect=e,e}getBoundingClientRect(){return console.warn("Please use getViewBoundingClientRect instead of getBoundingClientRect, this method is compatible with older api versions."),this.getViewBoundingClientRect()}_getEventPoint(e){return this.getViewXyByEvent(e)}getViewXyByEvent(e){const t=ce(e),n={x:t.clientX,y:t.clientY};return this.getViewXyByClientXy(n)}getViewXyByClientXy(e){const t=this.getViewBoundingClientRect();return{x:e.x-t.x,y:e.y-t.y}}getCanvasXyByClientXy(e){const t=this.getViewBoundingClientRect(),n={x:e.x-t.left,y:e.y-t.top};return this.getCanvasXyByViewXy(n)}getCanvasXyByViewXy(e){if(this._rgAsConnectArea)return e;const t=this.dataProvider.getOptions(),n=t.canvasZoom/100,o={x:e.x-t.canvasOffset.x,y:e.y-t.canvasOffset.y};return{x:o.x/n,y:o.y/n}}getViewXyByCanvasXy(e){const t=this.dataProvider.getOptions(),n=t.canvasZoom/100;return{x:e.x*n+t.canvasOffset.x,y:e.y*n+t.canvasOffset.y}}getCanvasCoordinateByClientCoordinate(e){return console.warn("Please use getCanvasXyByClientXy instead of getCanvasCoordinateByClientCoordinate, this method is compatible with older api versions."),this.getCanvasXyByClientXy(e)}isNode(e){const t=ve(e,"rg-node-peel","rg-map");if(!!t)return this.dataProvider.getNodeById(t.dataset.id)}isLine(e){const t=ve(e,"rg-line-peel","relation-graph");if(!!t)return this.dataProvider.getLineById(t.dataset.id)}isLink(e){throw new Error("Please use isLine")}}class so extends Oe{constructor(e,t,n,o){super();_(this,"dataStores");this.dataStores=e;const s=Object.assign({},this.options,n);this.options=n,Object.assign(this.options,s),this.graphData=t,this.runtimeDATA4Links=o.runtimeDATA4Links,this.runtimeDATA4ShouldRenderItems=o.runtimeDATA4ShouldRenderItems,this.runtimeDATA4ConnectTargets=o.runtimeDATA4ConnectTargets,this.runtimeDATA4NodeMap=o.runtimeDATA4NodeMap,this.runtimeDATA4LinkMap=o.runtimeDATA4LinkMap,this.runtimeDATA4ElLineTargets=o.runtimeDATA4ElLineTargets,this.updateViewHook=a=>{if(a.optionsChanged&&this.dataStores.store4Options.set(this.getOptions()),a.nodesListChanged&&this.dataStores.store4ShouldRenderNodes.set(this.getShouldRenderNodes()),a.linesListChanged){const d=this.getShouldRenderLines();this.dataStores.store4ShouldRenderLines.set(d)}if(a.fakeLinesListChanged){const d=this.getShouldRenderFakeLines();this.dataStores.store4ShouldRenderFakeLines.set(d)}}}}class ao extends Oe{constructor(i,e,t){super(),this.graphData=i,this.runtimeDATA4Links=t.runtimeDATA4Links,this.runtimeDATA4ShouldRenderItems=t.runtimeDATA4ShouldRenderItems,this.runtimeDATA4ConnectTargets=t.runtimeDATA4ConnectTargets,this.runtimeDATA4NodeMap=t.runtimeDATA4NodeMap,this.runtimeDATA4LinkMap=t.runtimeDATA4LinkMap,this.runtimeDATA4ElLineTargets=t.runtimeDATA4ElLineTargets;const n=Object.assign({},this.options,e);this.options=e,Object.assign(this.options,n)}}class ro extends Oe{constructor(e,t){super();_(this,"dataStores");this.dataStores=e,this.updateViewHook=n=>{n.optionsChanged&&this.dataStores.store4Options.set(this.getOptions()),(n.nodesListChanged||n.changedNodes.length>0)&&this.dataStores.store4ShouldRenderNodes.set(this.getShouldRenderNodes()),(n.nodesListChanged||n.linesListChanged||n.changedLines.length>0)&&this.dataStores.store4ShouldRenderLines.set(this.getShouldRenderLines()),(n.fakeLinesListChanged||n.changedFakeLines.length>0)&&this.dataStores.store4ShouldRenderFakeLines.set([...this.getShouldRenderFakeLines()])}}}class lo extends Oe{constructor(i,e){super(),e(),this.updateViewHook=t=>{if(t.optionsChanged&&i.store4Options.set(this.getOptions()),t.linesListChanged||t.changedLines.length>0||t.nodesListChanged||t.changedNodes.length>0){const n=this.getShouldRenderNodes();i.store4ShouldRenderNodes.set([...n])}if(t.linesListChanged||t.changedLines.length>0){const n=this.getShouldRenderLines();i.store4ShouldRenderLines.set(n)}t.fakeLinesListChanged?i.store4ShouldRenderFakeLines.set([...this.getShouldRenderFakeLines()]):t.changedFakeLines.length>0&&i.store4ShouldRenderFakeLines.set(this.getShouldRenderFakeLines())}}}class co extends io{constructor(){super();_(this,"_initRawPropertyFn",(e,t,n)=>{});_(this,"dataStores")}setReactiveData4Vue2(e,t,n,o){this.useReactiveDataToAutoUpdateView=!0,this.dataProvider=new ao(e,t,n),this._initRawPropertyFn=o,this.options=this.dataProvider.options,this.dataStores={shouldRenderNodesStore:n.runtimeDATA4ShouldRenderItems.nodes,shouldRenderLinesStore:n.runtimeDATA4ShouldRenderItems.lines,shouldRenderFakeLinesStore:n.runtimeDATA4ShouldRenderItems.fakeLines}}setReactiveData4Vue3(e,t,n,o,s){this.useReactiveDataToAutoUpdateView=!0,this.dataProvider=new so(e,t,n,o),this._initRawPropertyFn=s,this.options=this.dataProvider.getOptions(),this.dataStores={optionsStore:e.store4Options,shouldRenderNodesStore:e.store4ShouldRenderNodes,shouldRenderLinesStore:e.store4ShouldRenderLines,shouldRenderFakeLinesStore:e.store4ShouldRenderFakeLines,optionsRef:e.optionsRef,shouldRenderNodesRef:e.shouldRenderNodesRef,shouldRenderLinesRef:e.shouldRenderLinesRef,shouldRenderFakeLinesRef:e.shouldRenderFakeLinesRef,textContainer4NormalRef:e.textContainer4NormalRef,textContainer4FakeLineRef:e.textContainer4FakeLineRef}}setReactiveData4React(e,t){this.dataProvider=new lo(e,t),this.options=this.dataProvider.getOptions(),this.dataStores={optionsStore:e.store4Options,shouldRenderNodesStore:e.store4ShouldRenderNodes,shouldRenderLinesStore:e.store4ShouldRenderLines,shouldRenderFakeLinesStore:e.store4ShouldRenderFakeLines}}setReactiveData4Svelte(e,t){this.dataProvider=new ro(e,t),this.options=this.dataProvider.getOptions(),this.dataStores={optionsStore:e.store4Options,shouldRenderNodesStore:e.store4ShouldRenderNodes,shouldRenderLinesStore:e.store4ShouldRenderLines,shouldRenderFakeLinesStore:e.store4ShouldRenderFakeLines}}generateNewNodeId(e=5){const t=Ie(e);return this.dataProvider.getNodeById(t)?this.generateNewNodeId(e+1):t}}class ho extends co{constructor(){super()}getOptions(){return this.dataProvider.getOptions()}getNodeById(i){return this.dataProvider.getNodeById(i)}getLineById(i){return this.dataProvider.getLineById(i)}getLinkByLineId(i){return this.dataProvider.getLinkByLineId(i)}getLinkByLine(i){return this.getLinkByLineId(i.id)}getLines(){return this.dataProvider.getLines()}getElementLineById(i){return this.getFakeLineById(i)}getElementLines(){return this.getFakeLines()}getFakeLines(){return this.dataProvider.getFakeLines()}getFakeLineById(i){return this.dataProvider.getFakeLineById(i)}getNodes(){return this.dataProvider.getNodes()}getLinks(){return this.dataProvider.getLinks()}_getAllLinks(){const i=this.getLinks();return this._getFakeLineLinks().concat(i)}getNodeByTargetId(i){const e=this.dataProvider.getConnectTargetById(i);if(e&&e.nodeId)return this.getNodeById(e.nodeId)}_getFakeLineLinks(){const i=[];for(const e of this.getFakeLines())if(!e.forDisplayOnly&&(e.fromType===D.Node||e.fromType===D.NodePoint||e.fromType===D.CanvasPoint)&&(e.toType===D.Node||e.toType===D.NodePoint||e.toType===D.CanvasPoint)){let t=null,n=null;e.fromType===D.Node?t=this.getNodeById(e.from):(e.fromType===D.NodePoint||e.fromType===D.CanvasPoint)&&(t=this.getNodeByTargetId(e.from)),e.toType===D.Node?n=this.getNodeById(e.to):(e.toType===D.NodePoint||e.toType===D.CanvasPoint)&&(n=this.getNodeByTargetId(e.to)),t&&n&&i.push({lineId:e.id,line:e,fromNode:t,toNode:n,totalLinesBetweenNodes:1,currentLineIndex:0,rgShouldRender:!0,rgCalcedVisibility:!0})}return i}getConnectTargets(){return this.dataProvider.getConnectTargets()}getConnectTargetById(i){return this.dataProvider.getConnectTargetById(i)}}class fo extends ho{constructor(){super()}getRelatedLinesByNode(i){const e=[];for(const t of this._getAllLinks())(i===t.fromNode||i===t.toNode)&&e.push(t.line);return e}getLinksBetweenNodes(i){const e=[],t=this._getAllLinks();for(const n of t)i.includes(n.fromNode)&&i.includes(n.toNode)&&e.push(n);return e}getLinesBetweenNodes(i){return this.getLinksBetweenNodes(i).map(e=>e.line)}getNodeRelatedNodes(i,e={incoming:!0,outgoing:!0}){const t=[];for(const n of this.getLinks()){if(n.line.forDisplayOnly)continue;const{fromNode:o,toNode:s}=n;e.outgoing&&o===i&&(t.includes(s)||t.push(s)),e.incoming&&s===i&&(t.includes(o)||t.push(o))}for(const n of this._getFakeLineLinks()){if(n.line.forDisplayOnly)continue;const{fromNode:o,toNode:s}=n;e.outgoing&&o===i&&(t.includes(s)||t.push(s)),e.incoming&&s===i&&(t.includes(o)||t.push(o))}return t}getNodeIncomingNodes(i){return this.getNodeRelatedNodes(i,{incoming:!0,outgoing:!1})}getNodeOutgoingNodes(i){return this.getNodeRelatedNodes(i,{incoming:!1,outgoing:!0})}findGroupNodes(i,e=[]){return this._getNetworkNodesByNode(i,e)}getGroupNodesByNode(i,e=[]){return this._getNetworkNodesByNode(i,e)}getNetworkNodesByNode(i){return this._getNetworkNodesByNode(i)}_getNetworkNodesByNode(i,e=[]){if(!i)throw new Error("Call graphInstance.getNetworkNodesByNode:error: node is undefined");e.includes(i)||e.push(i);for(const t of this.getNodeRelatedNodes(i))e.includes(t)||this._getNetworkNodesByNode(t,e);return e}getStuffSize(i){return console.warn("Please use getNodesRectBox instead of getStuffSize, this method is compatible with older api versions."),this.getNodesRectBox(i)}getNodesViewInfo(i){return console.warn("Please use getNodesRectBox instead of getNodesViewInfo, this method is compatible with older api versions."),this.getNodesRectBox(i)}getNodesRectBox(i){const t=(i||this.getNodes()).filter(c=>c.rgCalcedVisibility!==!1);if(t.length===0)return{width:10,height:10,minX:0,minY:0,maxX:0,maxY:0};let n=9999999,o=9999999,s=-9999999,a=-9999999;t.forEach(c=>{c.x<n&&(n=c.x),c.x+(c.width||c.el_W)>s&&(s=c.x+(c.width||c.el_W)),c.y<o&&(o=c.y);const p=c.y+(c.height||c.el_H);p>a&&(a=p)});const d=s-n,h=a-o;return{width:d<0?0:d,height:h<0?0:h,minX:n===9999999?0:n,minY:o===9999999?0:o,maxX:s===-9999999?0:s,maxY:a===-9999999?0:a}}getNodesCenter(i){const e=this.getNodesRectBox(i);L("getNodesCenter:",e);const t=e.minX+(e.maxX-e.minX)/2,n=e.minY+(e.maxY-e.minY)/2;return{x:t,y:n}}getDescendantNodes(i){return Le.getDescendantNodes(i)}getNodesInSelectionView(i){const e=this.getCanvasXyByViewXy({x:i.x,y:i.y}),t=this.getCanvasXyByViewXy({x:i.x+i.width,y:i.y+i.height}),n=[];return this.getNodes().forEach(o=>{const s=o.x+o.el_W/2,a=o.y+o.el_H/2;s>e.x&&a>e.y&&s<t.x&&a<t.y&&n.push(o)}),n}getShouldRenderNodes(i){return this.dataProvider.isPerformanceMode()&&i?i:this.dataProvider.getShouldRenderNodes()}getShouldRenderLines(i){return this.dataProvider.isPerformanceMode()&&i?i:this.dataProvider.getShouldRenderLines()}getShouldRenderFakeLines(i){return this.dataProvider.isPerformanceMode()&&i?i:this.dataProvider.getShouldRenderFakeLines()}}class po extends fo{constructor(){super();_(this,"_elLineUpdateTimer");_(this,"_canvasCurrentInfo",{x:0,y:0,scale:1});_(this,"_nodeResizeEffectTimer");_(this,"prevAddNodeTimestamp",0);_(this,"_nodesElSizeMap",new Map)}removeLine(e){this.removeLines([e])}removeLines(e){this.removeLineByIds(e.map(t=>t.id))}removeLineById(e){this.removeLineByIds([e])}removeLineByIds(e){this.dataProvider.removeLineByIds(e),this._dataUpdated()}removeFakeLine(e){this.removeFakeLineById(e.id)}removeFakeLineById(e){L("removeLineById:",e),this.dataProvider.removeFakeLineByIds([e]),this._dataUpdated()}removeLink(e){L("removeLink:",e),this.removeLinkByLineId(e.lineId)}removeLinkByLineId(e){this.dataProvider.removeLineByIds([e]),this._dataUpdated()}removeNodeById(e){this.dataProvider.removeNodeById([e]),this._dataUpdated()}removeNodesByIds(e){e.forEach(t=>this.dataProvider.removeNodeById(e)),this._dataUpdated()}removeNodes(e){this.removeNodesByIds(e.map(t=>t.id))}removeNode(e){this.removeNodes([e])}removeELementLineById(e){L("removeELementLineById:",e),this.removeFakeLineById(e)}addNode(e){if(L("addNode:",e),e&&Array.isArray(e)){console.error("addNode: node is array:",e);return}this._addNodes([e]),this._dataUpdated()}addNodes(e){if(L("addNodes:",e),e&&!Array.isArray(e)){console.error("addNodes: nodes is not array:",e);return}this._addNodes(e),this._dataUpdated()}addLine(e){if(L("addLine:",e),e&&Array.isArray(e)){console.error("addLine: line is array:",e);return}this.addLines([e])}addLines(e){if(L("addLines:",e),e&&!Array.isArray(e)){console.error("addLines: lines is not array:",e);return}if(e.length===0)return;const t=e.filter(o=>!o.isFakeLine);this._addLines(t);const n=e.filter(o=>o.isFakeLine);this.addFakeLines(n),this._dataUpdated()}_addFakeLines(e){this.dataProvider.addFakeLines(e)}addFakeLines(e){L("addFakeLines:",e),this._addFakeLines(e),this._dataUpdated()}updateElementLines(){this.dataProvider.getElLineTargets().length!==0&&(L("updateElementLines:runtimeDATA4ElLineTargets:",this.dataProvider.getElLineTargets().length),this._elLineUpdateTimer&&clearTimeout(this._elLineUpdateTimer),this._elLineUpdateTimer=setTimeout(()=>{this._updateElementLines(),this._dataUpdated()},100))}_updateElementLines(){this._updateCanvasBoxInfo();for(const e of this.dataProvider.getElLineTargets())this.updateElementTarget(e)}_updateCanvasBoxInfo(){const e=this.$canvasDom.getBoundingClientRect();this._canvasCurrentInfo.x=e.x,this._canvasCurrentInfo.y=e.y,this._canvasCurrentInfo.scale=this.dataProvider.getOptions().canvasZoom/100}updateElementTarget(e){const t=this._getElementTargetPosition(document.getElementById(e.id),e);t?this.dataProvider.updateElLineTarget(e.id,{hidden:!1,...t}):this.dataProvider.updateElLineTarget(e.id,{hidden:!0})}_getElementTargetPosition(e){if(!e)return null;const t=e.getBoundingClientRect(),n=(t.x-this._canvasCurrentInfo.x)/this._canvasCurrentInfo.scale,o=(t.y-this._canvasCurrentInfo.y)/this._canvasCurrentInfo.scale,s=t.width/this._canvasCurrentInfo.scale,a=t.height/this._canvasCurrentInfo.scale;return{x:n,y:o,el_W:s,el_H:a}}addElementLines(e){L("addElementLines:",e),e.forEach(t=>{t.fromType=D.HTMLElementId,t.toType=D.HTMLElementId,t.isFakeLine=!0,t.id||(t.id=this.generateNewUUID(6)),t.forDisplayOnly=!0}),this.addFakeLines(e),this.updateElementLines()}updateNodeOffsetSize(e,t,n){const o=this.getNodeById(e);if(!o)return;const s=o.el_W,a=o.el_H;(s!==t||a!==n)&&(this.dataProvider.updateNode(e,{el_W:t,el_H:n}),this._nodeResizeEffectTimer&&clearTimeout(this._nodeResizeEffectTimer),this._nodeResizeEffectTimer=setTimeout(()=>{this._dataUpdated()},100))}clearFakeLines(){this.dataProvider.clearFakeLines(),this._dataUpdated()}clearElementLines(){const e=[];for(const t of this.getFakeLines())(t.fromType===D.HTMLElementId||t.toType===D.HTMLElementId)&&e.push(t.id);this.dataProvider.removeFakeLineByIds(e),this._dataUpdated()}_addNodes(e){this.emitEvent(I.beforeAddNodes,e);const t={};this.getNodes().forEach(s=>{t[s.id]=s});const n=[],o=this.getOptions();e.forEach(s=>{let a=t[s.id];if(!a){let{text:d,id:h}=s;!d&&s.label&&(d=s.label,console.warn('Use "label" as "text":',s.label)),d===void 0&&h&&(d=h,console.warn('Use "id" as "text":',h)),a=we(Object.assign({},s,{text:d}),o,this._nodesElSizeMap),this._initRawPropertyFn&&this._initRawPropertyFn(a,"lot",a.lot),a&&(t[a.id]=a,n.push(a))}}),this.dataProvider.addNodes(n),n.length>0&&(this.prevAddNodeTimestamp=Date.now())}_addLines(e){this.emitEvent(I.beforeAddLines,e);const t=[];e.forEach(n=>{let{from:o,to:s,text:a}=n;if(!o)if(n.source)o=n.source,console.warn('Use "source" as "from":',n.source);else{console.error('JsonLine Must have field:"from"',n);return}if(!s)if(n.target)s=n.target,console.warn('Use "target" as "to":',n.target);else{console.error('JsonLine Must have field:"to"',n);return}if(a||n.label&&(a=n.label,console.warn('Use "label" as "text":',n.label)),!this.getNodeById(o)){console.error("Can not found from node:",n);return}if(!this.getNodeById(s)){console.error("Can not found to node:",n);return}if(n.id){if(this.getLineById(n.id)){console.warn("_addLines:skip duplicate line id:",n.id);return}else if(t.some(p=>p.id===n.id)){console.warn("Duplicate line id in new lines:",n.id);return}}else n.id="L-"+this.generateNewUUID(6);const c=he(Object.assign({},n,{from:o,to:s,text:a}),this.getOptions());t.push(c)}),this.dataProvider.addLines(t)}updateNode(e,t){this.dataProvider.updateNode(typeof e=="string"?e:e.id,t),this._dataUpdated()}updateNodePosition(e,t,n){var s;const o=typeof e=="string"?e:e.id;this.dataProvider.updateNode(o,{x:t,y:n}),this.getOptions().layout.autoLayouting&&((s=this.layoutor)==null||s.syncNodePosition(o,t,n)),this._dataUpdated()}updateNodeData(e,t){this.dataProvider.updateNodeData(typeof e=="string"?e:e.id,t),this._dataUpdated()}updateLine(e,t){this.dataProvider.updateLine(typeof e=="string"?e:e.id,t),this._dataUpdated()}updateLineData(e,t){this.dataProvider.updateLineData(typeof e=="string"?e:e.id,t),this._dataUpdated()}updateFakeLine(e,t){this.dataProvider.updateFakeLine(typeof e=="string"?e:e.id,t),this._dataUpdated()}flatNodeData(e,t,n,o){Le.flatNodeData(e,t,n,o)}backupNodesElSize(){for(const e of this.getNodes())this._nodesElSizeMap.set(e.id,[e.el_W,e.el_H])}loadGraphJsonData(e){e.lines||(e.lines=e.relations,e.lines&&console.warn("[relation-graph] For compatibility with older version, Use jsonData.relations as jsonData.lines, It is recommended that you define your data using")),e.lines||(e.lines=e.links||e.edges,e.lines&&console.warn("[relation-graph] For compatibility with older version, Use jsonData.links/jsonData.edges as jsonData.lines, It is recommended that you define your data using"));const t=e.nodes||[],n=e.lines||[],o=[],s=[];this.flatNodeData(t,null,o,s),n.forEach(a=>{s.push(a)}),this._addNodes(o),L("Nodes is initialized"),this._addLines(s),this._dataUpdated(),e.fakeLines&&this.addFakeLines(e.fakeLines),setTimeout(()=>{e.elementLines&&(console.warn("elementLines is deprecated, please use fakeLines with isFakeLine and fromType/toType = RGInnerConnectTargetType.HTMLElementId instead:",e.elementLines),this.addElementLines(e.elementLines)),this._dataUpdated()},500)}updateShouldRenderGraphData(e=!1){!e&&!this.dataProvider.isPerformanceMode()||this.dataProvider.updateShouldRenderGraphData()}updateNodesVisibleProperty(e){this.dataProvider.updateNodesVisibleProperty(e)}updateVisibleNodesSize(){for(const e of this.getShouldRenderNodes()){const t=this.getNodeElByNodeId(e.id);t&&this._onNodeDomResize(t,t.clientWidth,t.clientHeight)}}_clearGraph(){this.backupNodesElSize(),this.dataProvider.clearReactiveData(),this.dataProvider.clearChecked(),this.dataProvider.setEditingLine(null),this.dataProvider.setEditingNodes([])}_setJsonData(e,t=!1){this._clearGraph(),this.loadGraphJsonData(e)}}class uo extends po{constructor(){super();_(this,"canvasConnectTargetsMap",new Map);_(this,"nodeConnectTargetsMap",new Map);_(this,"connectTargetElementMap",new Map);_(this,"_connectTargetUpdateRequestedSet",new Map);_(this,"_updateTimer");_(this,"_removedConnectTargetMap",new Map)}updateConnectTargetsOnCanvas(e,t){if(!t)return;const n=t.classList.contains("rg-canvas-slot-above")?"above":"behind",o=this.canvasConnectTargetsMap.get(n);o&&o.length>0&&this.updateConnectTargetList(e,t,o)}updateConnectTargetsByNodeId(e){const t=this.getNodeElByNodeId(e);this.updateConnectTargetsOnNode("API",e,t)}getNodeElByNodeId(e){return this.$dom.querySelector(`[data-id="${e}"]`)}updateConnectTargetsOnNode(e,t,n){const o=this.nodeConnectTargetsMap.get(t)||[];o.length!==0&&this.updateConnectTargetList(e,n,o)}updateConnectTargetList(e,t,n){const o=this.dataProvider.getCanvasScale();for(const s of n){const a=this.connectTargetElementMap.get(s.targetId);if(!a){console.error("Can not find el for connectTarget:",s.targetId,s);continue}this._requestUpdateConnectTargetOffset(e,s,a,t,o)}}_requestUpdateConnectTargetOffset(e,t,n,o,s){this._connectTargetUpdateRequestedSet.set(t.targetId,{stableTimes:0,connectTarget:t,by:e,connectTargetEl:n,relativeEl:o}),clearTimeout(this._updateTimer),this._updateTimer=setTimeout(()=>{this._updateAllRequestedConnectTargetOffsets()},Math.min(this._connectTargetUpdateRequestedSet.size+10,50))}_updateAllRequestedConnectTargetOffsets(){let e=0;for(const t of this._connectTargetUpdateRequestedSet.values()){const{by:n,connectTargetEl:o,relativeEl:s,connectTarget:a}=t;if(this.dataProvider.isPerformanceMode()&&a.nodeId){const f=this.getNodeById(a.nodeId);if(!f||!f.rgShouldRender||!f.rgCalcedVisibility)continue}if(!this.dataProvider.getConnectTargetById(a.targetId))continue;const h=this.dataProvider.getCanvasScale();this._updateConnectTargetOffset(n,a,o,s,h)?e++:t.stableTimes++,t.stableTimes>2&&this._connectTargetUpdateRequestedSet.delete(a.targetId)}e>0?(clearTimeout(this._updateTimer),this._updateTimer=setTimeout(()=>{this._updateAllRequestedConnectTargetOffsets()},Math.min(e/2+10,100)),this._dataUpdated()):(this._connectTargetUpdateRequestedSet.clear(),this._dataUpdated())}_updateConnectTargetOffset(e,t,n,o,s){const a=o.getBoundingClientRect(),d=n.getBoundingClientRect(),h=Math.round(d.x-a.x),c=Math.round(d.y-a.y),f=this.dataProvider.getCanvasScale(),p=Math.round(h/f),m=Math.round(c/f),u=Math.round(d.width/f),g=Math.round(d.height/f),y=t.offsetX!==p,v=t.offsetY!==m,x=u!==0&&t.width!==u,w=g!==0&&t.height!==g;return y||v||x||w?(this.dataProvider.updateConnectTarget(t.targetId,{offsetX:p,offsetY:m,width:u,height:g}),!0):!1}_onConnectTargetMounted(e,t,n,o){const s=this.dataProvider.getCanvasScale();this._requestUpdateConnectTargetOffset(e,t,n,o,s)}getNodeElByChildrenTarget(e){return ve(e,"rg-node-peel","rg-map")}registerConnectTarget(e,t,n,o,s={}){if(n!==D.NodePoint&&n!==D.CanvasPoint)return;if(!e){console.error(`[registerConnectTarget]Can not find CanvasPoint target DOM: ${t}`);return}const a=this.getNodeElByChildrenTarget(e),d=a==null?void 0:a.dataset.id;if(d==="rg-newNodeTemplate")return;let h=this.dataProvider.getConnectTargetById(t);if(!h){const f={targetId:t,targetType:n,junctionPoint:o,nodeId:"",width:20,height:20,offsetX:0,offsetY:0,offsetPercentX:0,offsetPercentY:0,targetData:s||{}};this.reuseConnectTarget(f),h=this.dataProvider.addConnectTarget(f)}return this.connectTargetElementMap.set(h.targetId,e),(d?this.getNodeById(d):null)?this._addConnectTargetToNodeMap(d,h,e,a):this._addConnectTargetToCanvasMap(h,e),h}_addConnectTargetToNodeMap(e,t,n,o){this.dataProvider.updateConnectTarget(t.targetId,{junctionPoint:t.junctionPoint,targetType:D.NodePoint,nodeId:e,targetData:Object.assign({},t.targetData||{},{nodeId:e})});let s=this.nodeConnectTargetsMap.get(e);s?s.some(a=>a.targetId===t.targetId)||s.push(t):this.nodeConnectTargetsMap.set(e,[t]),this._onConnectTargetMounted("NT-Mounted",t,n,o)}_addConnectTargetToCanvasMap(e,t){let n=ve(t,"rg-canvas-slot","rg-map");if(!!n&&n){const o=n.classList.contains("rg-canvas-slot-above")?"above":"behind";this.dataProvider.updateConnectTarget(e.targetId,{junctionPoint:e.junctionPoint,targetType:D.CanvasPoint,targetData:Object.assign({},e.targetData||{})});const s=this.canvasConnectTargetsMap.get(o);s?s.some(a=>a.targetId===e.targetId)||s.push(e):this.canvasConnectTargetsMap.set(o,[e]),this._onConnectTargetMounted("CT-Mounted",e,t,n)}}unregisterConnectTarget(e){const t=this.dataProvider.getConnectTargetById(e);if(!t)return;let n;if(t.nodeId&&this.nodeConnectTargetsMap.has(t.nodeId))n=this.nodeConnectTargetsMap.get(t.nodeId);else{const o=this.canvasConnectTargetsMap.get("behind");if(o){let s=o.findIndex(a=>a.targetId===e);s!==-1?n=this.canvasConnectTargetsMap.get("behind"):(s=this.canvasConnectTargetsMap.get("above").findIndex(a=>a.targetId===e),s!==-1&&(n=this.canvasConnectTargetsMap.get("above")))}}if(n){const o=n.findIndex(s=>s.targetId===e);o!==-1&&n.splice(o,1)}this.dataProvider.removeConnectTarget(e),this.connectTargetElementMap.delete(e),this._removedConnectTargetMap.set(t.targetId,t)}reuseConnectTarget(e){if(this._removedConnectTargetMap.has(e.targetId)){const t=this._removedConnectTargetMap.get(e.targetId);e.offsetX=t.offsetX,e.offsetY=t.offsetY,e.width=t.width,e.height=t.height,e.offsetPercentX=t.offsetPercentX,e.offsetPercentY=t.offsetPercentY,this._removedConnectTargetMap.delete(e.targetId)}}}class go extends uo{constructor(){super();_(this,"fakeLineTargetRender")}generateCreatingLineConfig(e){e||(e=this.dataProvider.getOptions());const{newLinkTemplate:t,newLineTemplate:n}=e,o=t.fromNode;if(!o)return{line:n,from:null,to:null,totalLinesBetweenNodes:1,currentLineIndex:0};const s=t.toNode,a=s.targetType===D.Node?t.toNode:this.getFakeLineTarget(s.targetType,s.id,n);return{line:Object.assign({},n,{isFakeLine:!1}),from:this.getFakeLineTarget(o.targetType,o.id,n),to:a,totalLinesBetweenNodes:1,currentLineIndex:0}}generateLineConfig(e){const t=this.getLinkByLine(e);return!t||!t.rgCalcedVisibility?!1:{line:t.line,from:t.fromNode,to:t.toNode,totalLinesBetweenNodes:t.totalLinesBetweenNodes,currentLineIndex:t.currentLineIndex}}generateFakeLineConfig(e){let t=1,n=0;if(e.fromType===D.HTMLElementId&&e.toType===D.HTMLElementId){const a=this.dataProvider.getFakeLines().filter(d=>d.from===e.from&&d.to===e.to);a.length>1&&(console.warn("sameTargetLines element-line:",e),t=a.length,n=a.indexOf(e))}let o=this.getFakeLineTarget(e.fromType,e.from,e),s=this.getFakeLineTarget(e.toType,e.to,e);return!o&&e.fromType===D.Node?(console.error("[generateFakeLineConfig]error fakeLine from:",e.fromType,e.from,e),!1):!s&&e.fromType===D.Node?(console.error("[generateFakeLineConfig]error fakeLine to:",e.toType,e.to,e),!1):{line:e,from:o,to:s,totalLinesBetweenNodes:t,currentLineIndex:n}}setFakeLineTargetRender(e){this.fakeLineTargetRender=e}getFakeLineTarget(e,t,n){if(e===D.HTMLElementId){let o=this.dataProvider.getElLineTargets().find(s=>s.id===t);return o||(o={x:300,y:300,targetType:D.HTMLElementId,nodeShape:1,id:t,el_W:40,el_H:40,hidden:!0},this.dataProvider.addElLineTarget(o),this.updateElementLines()),o.hidden?null:o}else{if(e===D.Node)return this.getNodeById(t);if(e===D.NodePoint||e===D.CanvasPoint){const o=this.dataProvider.getConnectTargetById(t);if(!o)return;if(o.nodeId){const s=this.getNodeById(o.nodeId);if(!s){console.error("[getFakeLineTarget]Can not find NodePoint-s Node:",`${o.targetId}@${o.nodeId}`);return}return{x:s.x+o.offsetPercentX*s.el_W+o.offsetX,y:s.y+o.offsetPercentY*s.el_H+o.offsetY,targetType:D.NodePoint,targetData:o.targetData,nodeShape:0,id:t,el_W:o.width,el_H:o.height,hidden:!1}}else return{x:o.offsetX,y:o.offsetY,targetType:D.CanvasPoint,targetData:o.targetData,nodeShape:0,id:t,el_W:o.width,el_H:o.height,hidden:!1}}}if(this.fakeLineTargetRender)return this.fakeLineTargetRender(e,t,n)}}class mo extends go{constructor(){super()}_updateOptions(i){!i.instanceId&&this.getOptions().instanceId!==i.instanceId&&(i.instanceId=this.instanceId);const e=Object.assign({},i);if(e.layouts)throw new Error('Graph options do not support setting layouts properties, Please use "layout"!');if(e.lineUseTextPath)throw new Error('Graph options do not support setting layouts properties, Please use "defaultLineTextOnPath"!');if(e.debug!==void 0){const t=e.debug===!0;t&&L("RGOptions:user instance options:",e),window&&(window.relationGraphDebug=t)}e.layout?(this.dataProvider.updateOptions({...e,layout:{...this.getOptions().layout,...e.layout}}),this.layoutor&&this.layoutor.updateOptions&&this.layoutor.updateOptions(e.layout)):this.dataProvider.updateOptions(e)}resetViewSize(i=!1){const e=this.getViewBoundingClientRect(),t={};t.viewSize={width:e.width,height:e.height},this._rgAsConnectArea?(t.canvasZoom=100,t.canvasOffset={x:0,y:0}):i&&(t.canvasZoom=100,t.canvasOffset={x:t.viewSize.width/2,y:t.viewSize.height/2}),this.dataProvider.updateOptions(t),L("resetViewSize:1:",t),this._dataUpdated()}loading(i=""){this.dataProvider.updateOptions({graphLoading:!0,graphLoadingText:i}),this._dataUpdated()}clearLoading(){this.dataProvider.updateOptions({graphLoading:!1,graphLoadingText:""}),this._dataUpdated()}setCheckedNode(i){this.dataProvider.updateOptions({checkedNodeId:i?typeof i=="string"?i:i.id:""}),this._dataUpdated()}setCheckedLine(i){this.dataProvider.updateOptions({checkedLineId:i?typeof i=="string"?i:i.id:""})}clearChecked(){this.dataProvider.clearChecked(),this._dataUpdated()}clearSelected(){const i=this.getNodes().filter(n=>n.selected),e=this.getLines().filter(n=>n.selected),t=this.getFakeLines().filter(n=>n.selected);i.forEach(n=>this.dataProvider.updateNode(n.id,{selected:!1})),e.forEach(n=>this.dataProvider.updateLine(n.id,{selected:!1})),t.forEach(n=>this.dataProvider.updateFakeLine(n.id,{selected:!1})),this._dataUpdated()}setCanvasOffset(i,e){this.dataProvider.setCanvasOffset(i,e),this._updateEditingControllerView(),this.updateShouldRenderGraphData(),this._dataUpdated()}setCanvasMoveMode(i){this.dataProvider.updateOptions({canvasMoveMode:i}),this._dataUpdated()}onMiniViewMounted(){this.dataProvider.updateOptions({showMiniView:!0}),this._dataUpdated()}onMiniViewUnMounted(){this.dataProvider.updateOptions({showMiniView:!1})}onReferenceLineMounted(i){this.dataProvider.updateOptions({referenceLineAdsorption:i||!1,showReferenceLine:!0})}onReferenceLineUnMounted(){this.dataProvider.updateOptions({referenceLineAdsorption:!1,showReferenceLine:!1})}}class yo extends mo{constructor(){super()}getCreatingLine(i){if(i||(i=this.getOptions()),!i.creatingLinePlot)return{creating:!1};const{line:e,from:t,to:n}=this.generateCreatingLineConfig();return{creating:!0,fromTarget:t,toTarget:n,lineJson:e}}getCreatingNode(i){return i||(i=this.getOptions()),i.creatingNodePlot?{creating:i.creatingNodePlot,nodeJson:i.newNodeTemplate}:{creating:!1}}}const vo=l=>{const i=Math.sin(l)*1e4;return i-Math.floor(i)},Ct=(l,i,e,t,n,o)=>{const a=e-l,d=t-i,h=Math.sqrt(a*a+d*d),c=Math.max(2,Math.floor(h/12)),f=-d/h,p=a/h,m=[{type:"M",x:l,y:i}];let u=l,g=i;for(let y=1;y<=c;y++){let v=l+a*y/c,x=i+d*y/c;if(y<c){const w=vo(n+y)-.5;v+=f*w*o,x+=p*w*o}m.push({type:"l",dx:v-u,dy:x-g}),u=v,g=x}return m},xo=(l,i={x:0,y:0,rotate:0})=>{const{fx:e,fy:t,tx:n,ty:o}=l;i.rotate=j.getTextAngle(e,t,n,o),i.x=e+(n-e)/2,i.y=t+(o-t)/2,Number.isNaN(i.rotate)&&(i.rotate=0);const s=e+t+n+o,a=Ct(e,t,n,o,s,2.5),d=Ct(e,t,n,o,s+99,1.5),h=`${ae(a)} ${ae(d)}`;return{pathCommands:[...a,...d],pathData:h,textPosition:i,points:[]}};class Co extends yo{constructor(){super()}_getJunctionPoint(i,e){return i===W.border?j.getBorderPoint4MultiLine(e):i===W.ltrb?j.getRectJoinPoint(e):i===W.tb?j.getRectVJoinPoint(e):i===W.lr?j.getRectHJoinPoint(e):i===W.left?j.getRectLeftJoinPoint(e):i===W.right?j.getRectRightJoinPoint(e):i===W.top?j.getRectTopJoinPoint(e):i===W.bottom?j.getRectBottomJoinPoint(e):i==="horizontalLine"?j.getRectHorizontalLineJoinPoint(e):i==="verticalLine"?j.getRectVerticalLineLineJoinPoint(e):j.getBorderPoint4MultiLine(e)}createLinePath(i,e,t){throw new Error("createLinePath() is deprecated, please use createLineDrawInfo() instead.")}createLineDrawInfo(i,e){let t,n,o=1,s=0;if(i&&(s=i.currentLineIndex,o=i.totalLinesBetweenNodes),i)t=i.fromNode,n=i.toNode;else{const a=e;if(t=this.getFakeLineTarget(a.fromType,a.from,a),n=this.getFakeLineTarget(a.toType,a.to,a),!t){console.error("Invalid line configuration:error from:",e);return}if(!n){console.error("Invalid line configuration:error to:",e);return}}return this.generateLinePath({line:e,from:t,to:n,totalLinesBetweenNodes:o,currentLineIndex:s})}_getLineDefaultOptions(){const i=this.getOptions();return{layoutDirection:i.layout.layoutDirection,multiLineDistance:i.multiLineDistance,defaultJunctionPoint:i.defaultJunctionPoint,lineRadius:i.defaultPolyLineRadius,defaultLineJunctionOffset:i.defaultLineJunctionOffset,defaultNodeShape:i.defaultNodeShape}}generateLinePath(i){i.totalLinesBetweenNodes===void 0&&(i.totalLinesBetweenNodes=1),i.currentLineIndex===void 0&&(i.currentLineIndex=0),i.defaultOptions===void 0&&(i.defaultOptions=this._getLineDefaultOptions());try{const e=this.withLineJunctionPoints(i);return this.createLinePathData(e)}catch(e){if(e.rgError)return this.createErrorLineValue(e.errorCode,e.x,e.y);throw e}}throwLineError(i,e,t){return{rgError:!0,errorCode:i,x:e,y:t}}createErrorLineValue(i,e,t){const n={x:0,y:0,rotate:0},o=[{type:"M",x:0,y:0},{type:"l",dx:e,dy:t}];return{pathCommands:o,pathData:ae(o),textPosition:n,points:[]}}withLineJunctionPoints({line:i,from:e,to:t,totalLinesBetweenNodes:n,currentLineIndex:o,defaultOptions:s}){if(!e||!t)throw L("error from-to:",e,t),this.throwLineError("F",-10,0);let a=i.lineShape||1;const d=i.lineDirection||s.layoutDirection||"h";let h=e.x||0,c=e.y||0,f=t.x||0,p=t.y||0;if(Number.isNaN(h)||Number.isNaN(c))throw L("error start node:",e.text,e.x,e.y),this.throwLineError("A",-10,-10);if(Number.isNaN(f)||Number.isNaN(p))throw L("error end point:",t.text,t.x,t.y),this.throwLineError("B",10,-10);let m=e.el_W||60,u=e.el_H||60;if(Number.isNaN(m)||Number.isNaN(u))throw this.throwLineError("C",-10,10);let g=t.el_W||60,y=t.el_H||60;if(Number.isNaN(g)||Number.isNaN(y))throw this.throwLineError("D",10,10);if(h===0&&f===0&&c===0&&p===0)throw this.throwLineError("D",10,10);const v=f-h+(p-c)>0,x=i.isReverse?t:e,w=i.isReverse?e:t,k=Ce(x.nodeShape,s.defaultNodeShape),T=i.junctionOffset||s.defaultLineJunctionOffset||0;h-=T,c-=T,f-=T,p-=T,m+=T*2,u+=T*2,g+=T*2,y+=T*2;const O={from_x:h,from_y:c,to_x:f,to_y:p,f_W:m,f_H:u,t_W:g,t_H:y,nodeShape:k,isReverse:v,isEndPoint:!1,totalLinesBetweenNodes:n,currentLineIndex:o,lineDistance:s.multiLineDistance||30},b=Ce(w.nodeShape,s.defaultNodeShape),N={from_x:f,from_y:p,to_x:h,to_y:c,f_W:g,f_H:y,t_W:m,t_H:u,nodeShape:b,isReverse:v,isEndPoint:!0,totalLinesBetweenNodes:n,currentLineIndex:o,lineDistance:s.multiLineDistance||50},P=s.defaultJunctionPoint||W.border;let R=i.fromJunctionPoint||P,S=i.toJunctionPoint||P,M=i.fromJunctionPointOffsetX||0,C=i.fromJunctionPointOffsetY||0,E=i.toJunctionPointOffsetX||0,V=i.toJunctionPointOffsetY||0;i.isReverse&&([R,S]=[S,R],[M,C,E,V]=[E,V,M,C]),(e===t||h===0&&f===0&&c===0&&p===0)&&M===0&&C===0&&E===0&&V===0&&((a===Y.StandardStraight||a===Y.Curve2||a===Y.Curve3||a===Y.SimpleOrthogonal||a===Y.Curve5)&&(a=Y.StandardCurve),V=20);const X=this._getJunctionPoint(R,O);X.x+=M,X.y+=C;const A=this._getJunctionPoint(S,N);if(A.x+=E,A.y+=V,!X||!A)throw this.throwLineError("E",-20,-20);const G=h+m/2,$=c+u/2,J=f+g/2,ie=p+y/2;R==="horizontalLine"?(X.x=A.x,(a===44||a===49)&&(X.x+=(A.x>J?1:-1)*30)):R==="verticalLine"&&(X.y=A.y,(a===44||a===49)&&(X.y+=(A.y>ie?1:-1)*30)),S==="horizontalLine"?(A.x=X.x,(a===44||a===49)&&(A.x+=(X.x>G?1:-1)*30)):S==="verticalLine"&&(A.y=X.y,(a===44||a===49)&&(A.y+=(X.y>$?1:-1)*30));const te=X.x,ne=X.y,Q=A.x,Z=A.y;if(Number.isNaN(te)||Number.isNaN(ne))throw L("error start point:",e.text),this.throwLineError("F",-10,0);if(Number.isNaN(Q)||Number.isNaN(Z))throw L("error end point:",t.text),this.throwLineError("G",10,0);return{line:i,totalLinesBetweenNodes:n,currentLineIndex:o,lineDirection:d==="v"?"v":"h",lineShape:a,lineRadius:s.lineRadius||0,fromJunctionPoint:R,toJunctionPoint:S,fx:te,fy:ne,fcx:G,fcy:$,f_W:m,f_H:u,tx:Q,ty:Z,tcx:J,tcy:ie,t_W:g,t_H:y}}createLinePathData(i){const{lineShape:e}=i;let t;return e===Y.SimpleOrthogonal?t=Wn(i,void 0,this._getLineDefaultOptions()):e===Y.StandardOrthogonal?t=jn(i,void 0,this._getLineDefaultOptions()):e===Y.HardOrthogonal?t=qn(i,void 0,this._getLineDefaultOptions()):e===Y.StandardCurve?t=Zn(i):e===Y.Curve2||e===Y.Curve3||e===Y.Curve5||e===Y.Curve7?t=Kn(i):e===Y.Curve8?t=xo(i):t=Yn(i),t}getArrowMarkerId(i,e=!1){let t=i.showStartArrow===!0,n=i.showEndArrow!==!1;if(i.isReverse&&([t,n]=[n,t]),e){if(!t)return;if(i.startMarkerId)return`url('#${i.startMarkerId}')`}else{if(!n)return;if(i.endMarkerId)return`url('#${i.endMarkerId}')`}return`url('#${this.getLineArrow(i.color,e,!1)}')`}getLineArrow(i,e=!1,t=!1){const n=e?"start-":"";return`${this.getOptions().instanceId}-${n}arrow-default`}getTextTransform(i,e){if(!i||!e)return"translate(0,0)";const{x:t,y:n,rotate:o}=e;if(Number.isNaN(t)||Number.isNaN(n))return"translate(0,0)";const s=this.getOptions(),a=i.textOffsetX||s.defaultLineTextOffsetX||0,d=i.textOffsetY||s.defaultLineTextOffsetY||0,h=i.lineShape||1;return h===Y.StandardStraight||h===Y.SimpleOrthogonal?`translate(-50%, -50%) translate(${t+a}px,${n+d}px) rotate(${o||0}deg)`:`translate(-50%, -50%) translate(${t+a}px,${n+d}px)`}generateLineTextStyle(i,e){const t=this.getOptions(),n={transform:"",transformOrigin:"0 0"};if(!i||!e)return{cssStyles:n};const{line:o}=i,{textPosition:s}=e;if(!o||!s)return{cssStyles:n};let a=o.text||"";a.length>t.lineTextMaxLength&&(a=a.substring(0,t.lineTextMaxLength||15)+"...");const{x:d,y:h,rotate:c}=s;if(Number.isNaN(d)||Number.isNaN(h))return{text:a,cssStyles:n};const f=[],p=o.textAnchor||"center";p==="start"?f.push("translate(0%, -50%)"):p==="end"?f.push("translate(-100%, -50%)"):f.push("translate(-50%, -50%)"),f.push(`translate(${d}px,${h}px)`);const m=o.textOffsetX||t.defaultLineTextOffsetX||0,u=o.textOffsetY||t.defaultLineTextOffsetY||0,g=o.lineShape||1;return(o.useTextOnPath||t.defaultLineTextOnPath)&&g===1&&c&&f.push(`rotate(${c||0}deg)`),g===Y.StandardStraight?(n.transformOrigin="50% 50%",f.push(`translate(${m}px,${u}px)`)):f.push(`translate(${m}px,${u}px)`),n.transform=f.join(" "),{text:a,cssStyles:n}}generateLineTextStyle4TextOnPath(i){const{line:e,from:t,to:n}=i;let o=e.text;if(!o||!n||!t)return null;let s=0;const a=this.getOptions();o.length>a.lineTextMaxLength&&(o=o.substring(0,a.lineTextMaxLength||15)+"...");const d=e.textOffsetX||a.defaultLineTextOffsetX||0,h=e.textOffsetY||a.defaultLineTextOffsetY||0,c={x:d,y:h-6};let f="50%";e.placeText==="start"?(f="0%",c.x+=20):e.placeText==="end"?(f="100%",c.x-=20):e.placeText==="center"?f="50%":e.placeText&&(f=e.placeText);let p="middle";return e.textAnchor&&(p=e.textAnchor),{text:o,textOffset:c,textAnchor:p,onPathStartOffset:f,textRotate:s}}}class Lo extends Co{constructor(){super()}getClampedZoom(i){const e=this.getOptions();return Math.max(e.minCanvasZoom,Math.min(e.maxCanvasZoom,i))}applyZoom(i,e,t){if(this._rgAsConnectArea)return;const n=this.getOptions(),o=this.getClampedZoom(i),s=o-n.canvasZoom,a=e.x!==n.canvasOffset.x||e.y!==n.canvasOffset.y;if(!(s===0&&!a))try{const d=this.emitEvent(I.beforeZoomStart,n.canvasZoom,s,t);if(L("[zoom]","abortZoom:",d),d===!0)return;const h=n.canvasZoom;this._performanceModeLogicHook(h,o),this.dataProvider.updateOptions({canvasOffset:{x:e.x,y:e.y},canvasZoom:o}),this.emitEvent(I.onZoomEnd,o,h)}finally{this._updateEditingControllerView(),this._dataUpdated()}}zoom(i,e,t){if(this._rgAsConnectArea)return;const n=this.getOptions(),o=this.getViewBoundingClientRect(),s=this.getClampedZoom(n.canvasZoom+i);e||(e={x:o.x+o.width/2,y:o.y+o.height/2});const a=e.x-o.left,d=e.y-o.top,h=n.canvasZoom/100,c=s/100,f=a-(a-n.canvasOffset.x)*(c/h),p=d-(d-n.canvasOffset.y)*(c/h);this.applyZoom(s,{x:f,y:p},t)}setZoomAndOffset(i,e,t){this.applyZoom(i,e,t)}_performanceModeLogicHook(i,e){const t=this.getOptions();i<=40?e>40&&(t.performanceMode&&this.updateShouldRenderGraphData(!0),this.dataProvider.updateOptions({showEasyView:!1}),L("zoom:hide:showEasyView",i,e),this.updateElementLines()):i>40&&e<=40&&(L("zoom:show:showEasyView",i,e),t.performanceMode&&this.dataProvider.updateOptions({showEasyView:!0}))}setZoom(i,e){const t=this.getOptions(),n=i-t.canvasZoom;this.zoom(n,e)}}class wo extends Lo{constructor(){super()}fitContentHeight(i=20){this.dataProvider.updateOptions({canvasOpacity:.01}),this._dataUpdated();const e=this.getOptions(),t=this.getNodesRectBox(),n=t.height,o=t.width,s=e.viewSize.width-i*2,a=t.minX+t.width/2,d=t.minY+t.height/2;this.dataProvider.setCanvasCenter(a,d);const h=Math.min(1,s/o),c=n*h+i*2;this.dataProvider.updateOptions({viewSize:{...e.viewSize,height:c},viewHeight:c+"px"}),setTimeout(()=>{this.setZoom(h*100),this._moveToCenter(),this.dataProvider.updateOptions({canvasOpacity:1}),this._dataUpdated()},200)}_moveToCenter(i){const e=this.getNodesCenter(i);this.dataProvider.setCanvasCenter(e.x,e.y),this._dataUpdated()}setCanvasCenter(i,e){this.dataProvider.setCanvasCenter(i,e),this._dataUpdated()}zoomToFit(i){const e=this.getOptions(),t=this.getCanvasSlotRectItems(),n=t.length>0?[...t,...i||this.getNodes()]:i,o=this.getNodesRectBox(n),s=50,a=e.viewSize.width/(o.width+s*2),d=e.viewSize.height/(o.height+s*2),h=Math.min(a,d,1);L("zoomToFit:",{stuffSize:o,zoomPercent:h,zoomPercentX:a,zoomPercentY:d,viewSize:e.viewSize}),this._moveToCenter(n),this.setZoom(h*100),this._dataUpdated()}async zoomToFitWithAnimation(i){this.enableCanvasAnimation(),this.zoomToFit(i),await this.sleep(330),this.disableCanvasAnimation()}async moveToCenterWithAnimation(i){this.enableCanvasAnimation(),this.moveToCenter(i),await this.sleep(330),this.disableCanvasAnimation()}enableNodeXYAnimation(){this.dataProvider.updateOptions({enableNodeXYAnimation:!0}),this._dataUpdated()}disableNodeXYAnimation(){this.dataProvider.updateOptions({enableNodeXYAnimation:!1}),this._dataUpdated()}enableCanvasAnimation(){this.dataProvider.updateOptions({enableCanvasTransformAnimation:!0}),this._dataUpdated()}disableCanvasAnimation(){this.dataProvider.updateOptions({enableCanvasTransformAnimation:!1}),this._dataUpdated()}focusNodeById(i){const e=this.getNodeById(i);e&&this.focusNode(e)}focusRootNode(){throw new Error("focusRootNode is deprecated, please use focusNodeById instead.")}focusNode(i){L("checked:",i);const e=this.getOptions();this.setZoom(100);const t=i.width||50,n=i.height||50,o=i.x*-1+e.viewSize.width/2-t/2,s=i.y*-1+e.viewSize.height/2-n/2;this.dataProvider.setCanvasOffset(o,s),this.dataProvider.updateOptions({checkedNodeId:i.id})}}class _o extends fe{constructor(e,t,n){super(e,t,n);_(this,"rotate",0);_(this,"enableGatherNodes",!1);_(this,"layoutOptions");this.layoutOptions=e,L("new RGTreeLayout:",this.layoutOptions),this.layoutOptions.from||(this.layoutOptions.from="left"),this.layoutOptions.levelGaps||(this.layoutOptions.levelGaps=[]);const o=this.layoutOptions.from;o==="top"||o==="bottom"?(this.layoutOptions.treeNodeGapH||(this.layoutOptions.treeNodeGapH=10),this.layoutOptions.treeNodeGapV||(this.layoutOptions.treeNodeGapV=50)):(this.layoutOptions.treeNodeGapH||(this.layoutOptions.treeNodeGapH=50),this.layoutOptions.treeNodeGapV||(this.layoutOptions.treeNodeGapV=10)),o==="top"?(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="center"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="start"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.layoutOptions.alignItemsX),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.getReverseAlignItems(this.layoutOptions.alignItemsY))):(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="start"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="start"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.getReverseAlignItems(this.layoutOptions.alignItemsX)),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.layoutOptions.alignItemsY)),this.layoutOptions.ignoreNodeSize===void 0&&(this.layoutOptions.ignoreNodeSize=!1);const s=this.layoutOptions.layoutExpansionDirection,a=s==="start"||s==="left"||s==="top"?"start":s==="end"||s==="right"||s==="bottom"?"end":"center";this.layoutOptions.layoutExpansionDirection=a,this.layoutOptions.treeNodeGapH<100&&(this.layoutOptions.treeNodeGapH=100),this.layoutOptions.treeNodeGapV<10&&(this.layoutOptions.treeNodeGapV=10),(this.layoutOptions.from==="bottom"||this.layoutOptions.from==="right")&&(this.rotate=180),this.layoutOptions.changeNodeSizeDuringLayout===void 0&&(this.layoutOptions.changeNodeSizeDuringLayout=!1)}placeNodes(e,t){if(L("RGTreeLayout:placeNodes"),t)L("layout by root:",t);else{console.error("root is null");return}L("allNodes:",e.length),this.layoutOptions.alignItemsX,this.layoutOptions.alignItemsY,this.layoutOptions.alignParentItemsX,this.layoutOptions.alignParentItemsY,this.rootNode=t,this.allNodes=e,t.fixed||this.layoutOptions.fixedRootNode||this.updateNodePosition(t,0,0),t.lot.x=t.x,t.lot.y=t.y;const n=e;L("groupNodes:2:",n.length,n.map(s=>s.text).join(",")),this.rotate,this.networkAnalyzer.analyzeNetwork(n,this.rootNode,!1),this.placeNodesPosition(t,n);const o={x:t.x,y:t.y};this.allNodes.forEach(s=>{if(s.fixed!==!0&&!!z.isVisibleNode(s)&&(Number.isNaN(s.lot.x)&&(L("bad lot x:",s.text,s.lot.x),s.lot.x=0),Number.isNaN(s.lot.y)&&(L("bad lot y:",s.text,s.lot.y),s.lot.y=0),s!==t)){this.layoutOptions.from==="right"&&(s.lot.x=j.getFlippedX(s.lot.x,o.x)),this.layoutOptions.from==="bottom"&&(s.lot.y=j.getFlippedY(s.lot.y,o.y));const a=this.layoutOptions.from==="right"?z.getNodeXByLotX({alignItemsX:"end"},s):s.lot.x,d=this.layoutOptions.from==="bottom"?z.getNodeYByLotY({alignItemsY:"end"},s):s.lot.y;this.updateNodePosition(s,a,d)}});for(const s of this.allNodes)this.graphInstance.updateNode(s,{rgChildrenSize:s.lot.childs.length});L("create rootNode coordinates:1",t.x,t.y),this.layoutEnd()}placeNodesPosition(e,t){this.placeRelativePosition(e,t)}placeRelativePosition(e,t){e.lot.parent=void 0,e.lot.level=0;const n=[];this.buildNetwork([e],n,0);const o=Math.max(...n.map(h=>h.lot.level)),s=this.layoutOptions.from==="left"||this.layoutOptions.from==="right";this.reduceNodeRect(n,o,s),s?this.placeNodeChildrenH(n,0):this.placeNodeChildrenV(n,0);let a=e.lot.x-e.x,d=e.lot.y-e.y;this.layoutOptions.from==="right"&&(a+=e.lot.width),this.layoutOptions.from==="bottom"&&(d+=e.lot.height),n.forEach(h=>{h.fixed!==!0&&(h.lot.x-=a,h.lot.y-=d)})}buildNetwork(e,t,n){n===0&&t.push(...e);const o=[];e.forEach(s=>{if(!z.isVisibleNode(s))return;const a=this.graphInstance.getNodeIncomingNodes(s).filter(z.isVisibleNode),h=this.graphInstance.getNodeOutgoingNodes(s).filter(z.isVisibleNode).filter(f=>!t.includes(f));t.push(...h);const c=a.filter(f=>!t.includes(f));t.push(...c),s.lot.level=n,s.lot.toNodes=h,s.lot.fromNodes=c;for(const f of c.concat(h))f.lot.parent=s,o.includes(f)||o.push(f)}),o.length>0&&this.buildNetwork(o,t,n+1)}reduceNodeRect(e,t,n=!1){let o=this.layoutOptions.treeNodeGapH,s=this.layoutOptions.treeNodeGapV;const a=o,d=s,h=e.filter(c=>c.lot.level===t);for(const c of h){if(!z.isVisibleNode(c))continue;let f=c.width||c.el_W||50,p=c.height||c.el_H||50;if(c.lot.width=f,c.lot.height=p,c.lot.toNodes.length===0&&c.lot.fromNodes.length===0)c.lot.width_with_childs=f,c.lot.height_with_childs=p;else if(n){let m=0,u=0;for(const v of c.lot.fromNodes)v.lot.height_with_childs>u&&(u=v.lot.height_with_childs),m+=v.lot.width_with_childs+d;let g=0,y=0;for(const v of c.lot.toNodes)v.lot.height_with_childs>y&&(y=v.lot.height_with_childs),g+=v.lot.width_with_childs+d;this.layoutOptions.changeNodeSizeDuringLayout&&(p=0),p=Math.max(u+a/2,p/2)+Math.max(y+a/2,p/2),c.lot.width_with_childs=f+Math.max(m,g)+d,c.lot.height_with_childs=p}else{let m=0,u=0;for(const v of c.lot.fromNodes)v.lot.width_with_childs>m&&(m=v.lot.width_with_childs),u+=v.lot.height_with_childs+d;let g=0,y=0;for(const v of c.lot.toNodes)v.lot.width_with_childs>g&&(g=v.lot.width_with_childs),y+=v.lot.height_with_childs+d;this.layoutOptions.changeNodeSizeDuringLayout&&(f=0),f=Math.max(m+a/2,f/2)+Math.max(g+a/2,f/2),c.lot.width_with_childs=f,c.lot.height_with_childs=p+Math.max(u,y)+d}}t>=0&&this.reduceNodeRect(e,t-1,n)}placeNodeChildrenV(e,t){const n=this.layoutOptions.treeNodeGapH,o=this.layoutOptions.treeNodeGapV,s=n,a=o;let d=0;const h=e.filter(c=>c.lot.level===t);for(const c of h){d++;let f=c.lot.width;this.layoutOptions.changeNodeSizeDuringLayout&&(f=0),t===0&&(c.lot.groupStartX=c.lot.x+f/2-c.lot.width_with_childs/2);const p=c.lot.groupStartX,m=c.lot.y;let u=0,g=0;for(const v of c.lot.fromNodes)v.lot.width_with_childs>u&&(u=v.lot.width_with_childs);for(const v of c.lot.toNodes)v.lot.width_with_childs>g&&(g=v.lot.width_with_childs);const y=p+Math.max(u+s/2,f/2);if(c.lot.fromNodes.length>0){let v=c.lot.height+a;for(const x of c.lot.fromNodes)x.lot.groupStartX=y-x.lot.width_with_childs-s/2,x.lot.y=m+v+a,v+=x.lot.height_with_childs+a}if(c.lot.toNodes.length>0){let v=c.lot.height+a;for(const x of c.lot.toNodes)x.lot.groupStartX=y+s/2,x.lot.y=m+v+a,v+=x.lot.height_with_childs+a}u>0||g>0?this.layoutOptions.changeNodeSizeDuringLayout?(c.lot.x=p,c.width=c.lot.width_with_childs):c.lot.x=y-c.lot.width/2:c.lot.x=p}d>0&&this.placeNodeChildrenV(e,t+1)}placeNodeChildrenH(e,t){const n=this.layoutOptions.treeNodeGapH,o=this.layoutOptions.treeNodeGapV,s=n,a=o;let d=0;const h=e.filter(c=>c.lot.level===t);for(const c of h){d++;let f=c.lot.height;this.layoutOptions.changeNodeSizeDuringLayout&&(f=0),t===0&&(c.lot.groupStartY=c.lot.y+f/2-c.lot.height_with_childs/2);const p=c.lot.groupStartY,m=c.lot.x;let u=0,g=0;for(const v of c.lot.fromNodes)v.lot.height_with_childs>u&&(u=v.lot.height_with_childs);for(const v of c.lot.toNodes)v.lot.height_with_childs>g&&(g=v.lot.height_with_childs);const y=p+Math.max(u+s/2,f/2);if(c.lot.fromNodes.length>0){let v=c.lot.width+a;for(const x of c.lot.fromNodes)x.lot.groupStartY=y-x.lot.height_with_childs-s/2,x.lot.x=m+v+a,v+=x.lot.width_with_childs+a}if(c.lot.toNodes.length>0){let v=c.lot.width+a;for(const x of c.lot.toNodes)x.lot.groupStartY=y+s/2,x.lot.x=m+v+a,v+=x.lot.width_with_childs+a}u>0||g>0?this.layoutOptions.changeNodeSizeDuringLayout?(c.lot.y=p,c.height=c.lot.height_with_childs):c.lot.y=y-c.lot.height/2:c.lot.y=p}d>0&&this.placeNodeChildrenH(e,t+1)}getLevelDistance(e,t,n){if(e===0)return 0;if(e>0){let o=0;for(let s=0;s<e;s++){const a=t.get(s);o+=a+this.getLevelGap(s,n,a,e)}return o}else{let o=0;for(let s=0;s>e;s--){const a=t.get(s);o+=a+this.getLevelGap(s,n,a,e)}return-o}}getLevelGap(e,t,n,o){let s=t+(o===-1&&e===0?n/2:0);if(this.layoutOptions.levelGaps.length>0){const a=this.layoutOptions.levelGaps[Math.abs(e)];a&&(s=a)}return s}}const No=_o;class bo extends wo{constructor(){super();_(this,"_layoutTimer",null);_(this,"_layoutPromise",null);_(this,"_layoutResolve",null);_(this,"layoutor")}async doLayout(e){const t=Date.now()-this.prevAddNodeTimestamp;return t<300&&(this.dataProvider.updateOptions({canvasOpacity:.01}),this._dataUpdated(),await Ee(300-t)),this._layoutPromise||(this._layoutPromise=new Promise(n=>{this._layoutResolve=n})),clearTimeout(this._layoutTimer),this._layoutTimer=setTimeout(async()=>{var n;try{await this._doLayout(e),this.dataProvider.updateOptions({canvasOpacity:1}),this._dataUpdated()}finally{(n=this._layoutResolve)==null||n.call(this),this._layoutResolve=null,this._layoutPromise=null}},50),this._layoutPromise}async _doLayout(e){this.updateNodesVisibleProperty();const t=this.getNodes();L("node size\uFF1A",t.length);let n=this.dataProvider.getRootNode();if(e&&(n=typeof e=="string"?this.getNodeById(e):e),n||(n=t[0],this._rgAsConnectArea||(L("[relation-graph]No root node, use first node as root:",n),L("[relation-graph]You can set rootNode call doLayout(rootNode | nodeId) with a node id"))),!n)throw new Error("custom rootNode not found, id:"+e);const o=this.getOptions();this.dataProvider.setRootNodeId(n?n.id:""),this.stopAutoLayout();const s=this.createLayout(o.layout,!0);if(s.layoutOptions.layoutName==="force")s.isMainLayouer=!0,s.onFinish(()=>{this.emitEvent(I.onForceLayoutFinish)}),await Ee(100),L("doLayout:start force:",t.length),s.placeNodes(t,n);else{this.enableNodeXYAnimation();let a=[];n&&(a=this.getNetworkNodesByNode(n),s.placeNodes(a,n)),L("doLayout:placeOtherNodes:all:",t.length,"mainGroupNodes:",a.length),this.placeOtherNodes(a),setTimeout(()=>{this.disableNodeXYAnimation()},300),L("doLayout:placeOtherNodes ok!")}t.forEach(a=>this.dataProvider.updateNode(a.id,{x:a.x||0,y:a.y||0,rgChildrenSize:a.rgChildrenSize||0})),this.updateElementLines()}async refresh(e=!0){this.resetViewSize(!0),this._dataUpdated(),e&&await this.doLayout(),this.updateElementLines(),this._dataUpdated()}placeOtherNodes(e=[]){const t=this.getOptions();if(t.layout.layoutName==="fixed"||!t.placeOtherGroup)return;const o=[],s=[],a=this.getNodes();a.forEach(h=>{if(h.fixed===!0||e.includes(h))return;this.getNodeRelatedNodes(h).length===0?s.push(h):o.push(h)}),L("doLayout:allNodes:",a.length),L("doLayout:mainGroupNodes:",e.length),L("doLayout:notInMainGroupNodes:",o.length),L("doLayout:singleNodes:",s.length);const d=[{nodes:e}];this.placeNextNetwork(o,[...e],d),this.placeSingleNodes(s),d.push({nodes:s}),this.sortGroups(d),this._dataUpdated()}placeSingleNodes(e){if(e.length>0){const t=Math.ceil(Math.sqrt(e.length));rt(t,30,e.map(o=>({width:o.el_W,height:o.el_H,node:o})),(o,s,a)=>{const d=o.node;d.x=s,d.y=a,d.lot||(d.lot={childs:[]})}),L("[placeSingleNodes]Single nodes:",e.length)}}sortGroups(e){L("[placeSingleNodes]sortGroups groupList:",e.length,e.map(s=>s.nodes.length));const t=e.map(s=>{const a=this.getNodesRectBox(s.nodes);return{width:a.width,height:a.height,nodes:s.nodes,orignX:a.minX,orignY:a.minY}});if(t.length===0)return;const n=Math.floor(Math.sqrt(t.length))||1;rt(n,100,t,(s,a,d)=>{const h=a-s.orignX,c=d-s.orignY;L(`[placeNextNetwork]Move ${s.nodes.length} Nodes :`,h,c,s," > ");for(const f of s.nodes)this.updateNodePosition(f,f.x+h,f.y+c)},t[0].orignX,t[0].orignY)}placeNextNetwork(e,t,n){if(e.length>0){const o=this.getOptions();L("[placeNextNetwork]notPlacedNodes nodes:",e.length);const s=JSON.parse(JSON.stringify(o.layout)),a=e[0],d=this.createLayout(s);if(d.isMainLayouer=!1,L("[placeNextNetwork]layoutName:",d.layoutOptions.layoutName,"root:",a.text),d.layoutOptions.layoutName==="force"){const f=d;f.maxLayoutTimes=0}a.fixed?L("[placeNextNetwork]fixed root x,y:",a.x,a.y,a.text):(this.updateNodePosition(a,0,0),L("[placeNextNetwork]set root x,y:",a.x,a.y,a.text)),d.layoutOptions.fixedRootNode=!0;const h=this.getNetworkNodesByNode(a);L("[placeNextNetwork]thisNetworkNodes:",e.length),d.placeNodes(h,a),t.push(...h),n.push({nodes:h});const c=[];e.forEach(f=>{t.includes(f)||c.push(f)}),o.placeOtherGroup&&this.placeNextNetwork(c,t,n),this._dataUpdated()}else L("[placeOtherGroup]thisGroupNodes:all is OK!")}toggleAutoLayout(){const e=this.getOptions();L("toggleAutoLayout:to:",e.layout.autoLayouting),e.layout.autoLayouting?this.stopAutoLayout():this.startAutoLayout()}startAutoLayout(){var e;(e=this.layoutor)!=null&&e.start&&(L("Start force layout:"+this.layoutor.instanceId),this.layoutor.start())}stopAutoLayout(){var e;(e=this.layoutor)!=null&&e.stop&&(L("Stop force layout:"+this.layoutor.instanceId),this.layoutor.stop())}createLayout(e,t=!1){L("########createLayout:",e);const n=this.getOptions();xt(e);let o=null;if(e.layoutName==="tree"?o=new lt(e,n,this):e.layoutName==="center"?o=new dt(e,n,this):e.layoutName==="circle"?o=new ct(e,n,this):e.layoutName==="force"?o=new ke(e,n,this):e.layoutName==="fixed"?o=new ht(e,n,this):e.layoutName==="smart-tree"?o=new Fn(e,n,this):e.layoutName==="io-tree"?o=new No(e,n,this):e.layoutName==="folder"&&(o=new ft(e,n,this)),!o)throw new Error("unknown layout: "+e.layoutName);return L("########supportAutoLayout:",o.autoLayout!==void 0,e.disableAsForceLayout),this.setLayoutor(o,t,o.autoLayout!==void 0&&e.disableAsForceLayout!==!0),o}setLayoutor(e,t,n=!1){e.isMainLayouer=t,e.layoutOptions.fixedRootNode=!0,t&&(this.layoutor=e,this._updateOptions({layout:{supportAutoLayout:n}}))}}const ko=async(l,i)=>{const e=l||document.documentElement;i?await Oo(e):await Po()},Oo=async l=>{l.requestFullscreen?await l.requestFullscreen():l.mozRequestFullScreen?await l.mozRequestFullScreen():l.webkitRequestFullscreen?await l.webkitRequestFullscreen():l.msRequestFullscreen&&await l.msRequestFullscreen()},Po=async()=>{document.exitFullscreen?await document.exitFullscreen():document.mozCancelFullScreen?await document.mozCancelFullScreen():document.webkitExitFullscreen?await document.webkitExitFullscreen():document.msExitFullscreen&&await document.msExitFullscreen()};class To extends bo{constructor(){super();_(this,"_prevClickNodeTime",0);_(this,"_nodeXYMappingBeforeDrag",{});_(this,"canvasAutoMoving",e=>{const t=this.getOptions(),n=t.viewSize,o=40;let s=0,a=0;e.x<o?s=o-e.x:n.width-o<e.x&&(s=n.width-o-e.x),e.y<o?a=o-e.y:n.height-o<e.y&&(a=n.height-o-e.y);const d=s!==0||a!==0;d&&(s=Math.max(Math.min(s/5,30),-30),a=Math.max(Math.min(a/5,30),-30));const h=t.canvasOffset.x+s,c=t.canvasOffset.y+a;return this.onCanvasDragging(h,c,s,a),d});_(this,"_canvasMovingTimer");_(this,"_relayoutTaskTimer");_(this,"_onMovingWhenCreatingLine");_(this,"_step1EventTime",0);_(this,"_onCreateLineCallback");_(this,"_mouseWheelTimer");_(this,"_mouseWheelEventPrevApplyTime",0);_(this,"_mouseWheelForce",{x:0,y:0});_(this,"_fullscreenchangeHandler")}onNodeClick(e,t){if("button"in t&&t.button===2)return;if(Date.now()-this._prevClickNodeTime<200){L("[node]click abort : time < 200");return}this._prevClickNodeTime=Date.now();const n=this.getOptions();if(n.creatingLinePlot){this.onNodeClickWhenCreatingLinePlot(e);return}const o=e.disablePointEvent===void 0?n.disableNodePointEvent:e.disablePointEvent;L("[node]node click",e.text,n.creatingLinePlot,o),!t.shiftKey&&!o&&(n.checkedLineId="",this.dataProvider.updateOptions({checkedLineId:"",checkedNodeId:e.id})),this.emitEvent(I.onNodeClick,e,t),this._prevClickNodeTime=Date.now()}onNodeDragStart(e,t){if(!e||ge(t))return;const n=this.getOptions();if((e.disableDrag||n.disableDragNode)&&!(t.target&&t.target.closest(".rg-node-drag-handler"))){const g=y=>{this.onNodeClick(e,y),document.body.removeEventListener("mouseup",g)};document.body.addEventListener("mouseup",g);return}isNaN(e.x)&&(e.x=0),isNaN(e.y)&&(e.y=0),this.dataProvider.setEditingLine(null),this.dataProvider.updateOptions({checkedLineId:""});let s=!1;const a=(u,g,y)=>{y.stopPropagation(),s=!0,this._canvasMovingTimer&&cancelAnimationFrame(this._canvasMovingTimer),this.dataProvider.updateOptions({draggingNodeId:"",editingReferenceLine:{...n.editingReferenceLine,show:!1}}),this._onNodeDragEnd(e,u,g,y),c?this.emitEvent(I.onNodeDragEnd,e,y,u,g):this.onNodeClick(e,t),this._dataUpdated()};this._nodeXYMappingBeforeDrag={},this._nodeXYMappingBeforeDrag[e.id]={x:e.x,y:e.y};for(const u of n.editingController.nodes)this._nodeXYMappingBeforeDrag[u.id]={x:u.x,y:u.y};const d=this.getCanvasXyByViewXy(this.getViewXyByEvent(t)),h={x:e.x,y:e.y};let c=!1;this._canvasMovingTimer&&cancelAnimationFrame(this._canvasMovingTimer);let f;const p=()=>{if(!f||s)return;const u=this.getViewXyByEvent(f),g=this.getCanvasXyByViewXy(u),y=g.x-d.x,v=g.y-d.y;let x=y+h.x,w=v+h.y,k=x-h.x,T=w-h.y;const O=this.emitEvent(I.onNodeDragging,e,x,w,k,T,f);O&&(typeof O.x=="number"&&(x=O.x,k=x-h.x),typeof O.y=="number"&&(w=O.y,T=w-h.y)),this.canvasAutoMoving(u),this.draggingSelectedNodes(e,x,w,k,T),this._dataUpdated()},m=()=>{p(),this._canvasMovingTimer=requestAnimationFrame(m)};le.startDrag(t,h,a,(u,g,y,v,x)=>{c?f=x:Math.abs(u)+Math.abs(g)>4&&(L("[node]onNodeDragStart...",de(x),x),this.emitEvent(I.onNodeDragStart,e,x),c=!0,this.dataProvider.updateOptions({draggingNodeId:e.id}),this._canvasMovingTimer=requestAnimationFrame(m)),this.updateElementLines(),this._dataUpdated()})}_onNodeDragEnd(e,t,n,o){this.updateElementLines()}onLineClick(e,t){if("button"in t&&t.button===2)return;const n=this.getLinkByLineId(e.id);L("onLineClick:","line:",e,"link:",n);const o=this.getOptions();(e.disablePointEvent===void 0?o.disableLinePointEvent:e.disablePointEvent)||(this.setCheckedNode(""),this.setCheckedLine(e)),this.emitEvent(I.onLineClick,e,n,t),this._dataUpdated()}expandOrCollapseNode(e,t){t.stopPropagation(),e.expanded===!1?this.expandNode(e,t):this.collapseNode(e,t)}expandNode(e,t){L("onNodeExpand:",e),this.dataProvider.updateNode(e.id,{expanded:!0}),this._effectWhenExpandedOrCollapsed(e),this.emitEvent(I.onNodeExpand,e,t)}collapseNode(e,t){L("onNodeCollapse:",e),this.dataProvider.updateNode(e.id,{expanded:!1}),this._effectWhenExpandedOrCollapsed(e),this.emitEvent(I.onNodeCollapse,e,t)}_effectWhenExpandedOrCollapsed(e){const t=this.getDescendantNodes(e);this.updateNodesVisibleProperty([e].concat(t)),this._relayoutTaskTimer&&clearTimeout(this._relayoutTaskTimer),this._relayoutTaskTimer=setTimeout(()=>{this.updateElementLines(),this._dataUpdated();const n=this.getOptions();n.reLayoutWhenExpandedOrCollapsed&&(n.layout.layoutName==="force"?this.startAutoLayout():this.doLayout())},100)}onCanvasDragEnd(e){this._updateEditingControllerView(),this.updateShouldRenderGraphData(),this._dataUpdated(),this.emitEvent(I.onCanvasDragEnd,e)}onCanvasClick(e){if("button"in e&&e.button===2)return;if(this.getOptions().creatingLinePlot)this.onCanvasClickWhenCreatingLinePlot(e);else{if(this.dataProvider.isPerformanceMode()){const n=this.getNodeAtEvent(e);if(n){this.emitEvent(I.onNodeClick,n,e);return}}this.emitEvent(I.onCanvasClick,e)}}getNodeAtEvent(e){const t=this.getCanvasXyByClientXy(e);return this.dataProvider.findNodeByXy(t)}onCanvasSelectionEnd(e,t){this.emitEvent(I.onCanvasSelectionEnd,e,t),L("[canvas]onCanvasSelectionEnd:",e),this._dataUpdated()}startCreatingNodePlot(e,t){if(!t)throw new Error("startCreatingNodePlot need setting param");if(!t.onCreateNode)throw new Error("startCreatingNodePlot need setting.onCreateNode param as callback");const n=we(JSON.parse(JSON.stringify(De)),this.getOptions()),o=de(e);this.dataProvider.updateOptions({newNodeTemplate:Object.assign({},n,t.templateNode),creatingNodePlot:!0,showTemplateNode:!o});let s=(u,g)=>{const y=this.getOptions().newNodeTemplate,v={width:y.width||50,height:y.height||50};this.dataProvider.updateOptions({newNodeTemplate:{...y,x:u-v.width/2,y:g-v.height/2}}),this._dataUpdated()};const a=this.getViewBoundingClientRect();L("[CreatingNodePlot]startCreatingNodePlot:");const d=ce(e),h=d.clientX-a.x+10,c=d.clientY-a.y+10;o||s(h,c);const f=u=>{L("[CreatingNodePlot]objectTemplateMove");const g=this.getViewXyByEvent(u);t.templateMove&&t.templateMove(g.x,g.y),s(g.x,g.y)},p=u=>{L("[CreatingNodePlot]user abort!"),this.$dom.removeEventListener("mousemove",f),this.$dom.removeEventListener("click",m),this.$dom.removeEventListener("contextmenu",p),this.dataProvider.updateOptions({creatingNodePlot:!1})},m=u=>{let g=!1;if(this.getOptions().creatingNodePlot||(g=!0),this.$dom.removeEventListener("mousemove",f),this.$dom.removeEventListener("click",m),this.$dom.removeEventListener("contextmenu",p),this.dataProvider.updateOptions({creatingNodePlot:!1}),g){L("[CreatingNodePlot]action be abort!");return}const y=ce(u),v=y.clientX-a.x+10,x=y.clientY-a.y+10;if(Math.abs(h-v)<30&&Math.abs(c-x)<30){L("[CreatingNodePlot]create node be abort!");return}const w=this.getCanvasXyByClientXy({x:y.clientX,y:y.clientY});L("[CreatingNodePlot]objectBePlaced:",w),t.onCreateNode(w.x,w.y,this.getOptions().newNodeTemplate),this._dataUpdated()};setTimeout(()=>{this.$dom.addEventListener("click",m),this.$dom.addEventListener("contextmenu",p)},300),o||this.$dom.addEventListener("mousemove",f)}startCreatingLinePlot(e,t){const n=de(e);t&&t.onCreateLine&&(this._onCreateLineCallback=t.onCreateLine);const o=he({from:"newRelationTemplate-from",to:"newRelationTemplate-to",color:"",text:""},this.getOptions());t&&t.template&&Object.assign(o,t.template),this.dataProvider.updateOptions({newLineTemplate:Object.assign(o,{isReverse:t.isReverse||!1})}),this.dataProvider.updateOptions({newLineTemplate:Object.assign(o,{isReverse:t.isReverse||!1,disablePointEvent:!0}),creatingLinePlot:!0});const s=Object.assign({},this.getOptions().newLinkTemplate,{fromNode:null,toNode:{id:"",targetType:D.Node,x:0,y:0,el_W:2,el_H:2},toNodeObject:null});t&&t.fromNode&&(s.toNode.x=t.fromNode.x+50,s.toNode.y=t.fromNode.y+50,s.fromNode=t.fromNode,this._step1EventTime=Date.now()),this.dataProvider.updateOptions({newLinkTemplate:s}),L("[CreatingLinePlot]startCreatingLinePlot:isTouchEvent:",n),n||(L("[CreatingLinePlot]Listener move"),this._onMovingWhenCreatingLine&&this.$dom.removeEventListener("mousemove",this._onMovingWhenCreatingLine),this._onMovingWhenCreatingLine=this.onMovingWhenCreatingLinePlot.bind(this),this.$dom.addEventListener("mousemove",this._onMovingWhenCreatingLine)),this._dataUpdated()}stopCreatingLinePlot(){L("[CreatingLinePlot]stop CreatingLinePlot!"),this.dataProvider.updateOptions({creatingLinePlot:!1,newLinkTemplate:{...this.getOptions().newLinkTemplate,fromNode:null,toNodeObject:null},nodeConnectController:{...this.getOptions().nodeConnectController,show:!1}}),this._onCreateLineCallback=void 0,this.$dom.removeEventListener("mousemove",this._onMovingWhenCreatingLine),this._onMovingWhenCreatingLine=void 0,this._dataUpdated()}onMovingWhenCreatingLinePlot(e){L("[CreatingLinePlot]mousemove");const t=this.getCanvasXyByClientXy({x:e.clientX,y:e.clientY}),n=this.getOptions(),o=e.target;let s="",a=D.Node;const d=this.isNode(o);let h=!1,c={x:0,y:0,el_W:5,el_H:5,nodeShape:0};d&&(s=d.id,d===this.getOptions().newLinkTemplate.fromNode?this.dataProvider.updateOptions({nodeConnectController:{...this.getOptions().nodeConnectController,show:!1}}):(this.dataProvider.updateOptions({nodeConnectController:{...this.getOptions().nodeConnectController,node:d,show:!0}}),this._updateEditingConnectControllerView()));const f=o.closest(".rg-connect-ctl-handler");if(f){let p=this.getOptions().nodeConnectController.node;L("[CreatingLinePlot]content point:",f.dataset.point);let m=f.dataset.point||"border";if(f.classList.contains("rg-connect-target")){const{width:u,height:g,x:y,y:v}=f.getBoundingClientRect(),x=this.getCanvasXyByClientXy({x:y,y:v}),w=this.dataProvider.getCanvasScale(),k={x:x.x,y:x.y,el_W:u/w,el_H:g/w,nodeShape:1,id:f.dataset.targetId,targetData:JSON.parse(f.dataset.targetData||"{}"),targetType:f.dataset.targetType};h=!0,c.x=k.x,c.y=k.y,c.el_W=k.el_W,c.el_H=k.el_H,c.nodeShape=k.nodeShape,this.dataProvider.updateOptions({nodeConnectController:{...this.getOptions().nodeConnectController,node:k,show:!1}}),m=f.dataset.point,n.newLinkTemplate.toNode&&(s=k.id,a=k.targetType,this.dataProvider.updateOptions({newLinkTemplate:{...this.getOptions().newLinkTemplate,toNode:{...this.getOptions().newLinkTemplate.toNode,nodeShape:k.nodeShape}}})),this._updateEditingConnectControllerView()}else p&&(a=D.Node,h=!0,c.x=p.x,c.y=p.y,c.el_W=p.el_W,c.el_H=p.el_H,c.nodeShape=p.nodeShape,o.dataset.innode==="true"&&(c.x=t.x,c.y=t.y,c.el_W=2,c.el_H=2,c.nodeShape=1));n.newLineTemplate.isReverse?this.dataProvider.updateOptions({newLineTemplate:{...this.getOptions().newLineTemplate,fromJunctionPoint:m}}):this.dataProvider.updateOptions({newLineTemplate:{...this.getOptions().newLineTemplate,toJunctionPoint:m}})}else L("[CreatingLinePlot]point:",o.dataset.point),n.newLineTemplate.isReverse?this.dataProvider.updateOptions({newLineTemplate:{...this.getOptions().newLineTemplate,fromJunctionPoint:W.border}}):this.dataProvider.updateOptions({newLineTemplate:{...this.getOptions().newLineTemplate,toJunctionPoint:W.border}}),n.newLinkTemplate.toNode&&(a=D.Node);n.newLinkTemplate.toNode&&(s&&this.dataProvider.updateOptions({newLinkTemplate:{...this.getOptions().newLinkTemplate,toNode:{...this.getOptions().newLinkTemplate.toNode,id:s}}}),this.dataProvider.updateOptions({newLinkTemplate:{...this.getOptions().newLinkTemplate,toNode:{...this.getOptions().newLinkTemplate.toNode,targetType:a}}})),n.newLinkTemplate.fromNode&&this.dataProvider.updateOptions({newLinkTemplate:{...this.getOptions().newLinkTemplate,toNode:{...this.getOptions().newLinkTemplate.toNode,x:h?c.x:t.x,y:h?c.y:t.y,el_W:c.el_W,el_H:c.el_H,nodeShape:c.nodeShape}}}),this._dataUpdated()}onCanvasClickWhenCreatingLinePlot(e){if(Date.now()-this._step1EventTime<500){L("[CreatingLinePlot]step1EventTime:",this._step1EventTime);return}const t=this.getOptions();if(!t.newLinkTemplate.fromNode){L("[CreatingLinePlot]CreatingLinePlot:fromNode not set!");return}let n=!1;if(!t.newLinkTemplate.toNodeObject){L("[CreatingLinePlot]CreatingLinePlot:toNodeObject not set!");const o=ce(e),s=this.getCanvasXyByClientXy({x:o.clientX,y:o.clientY});n=this.onReadyToCreateLine(t.newLinkTemplate.fromNode,s)}n!==!0&&this.stopCreatingLinePlot()}onNodeClickWhenCreatingLinePlot(e){const t=this.getOptions();t.newLinkTemplate.fromNode?(L("[CreatingLinePlot]step 2: set toNodeObjecct:",t.newLinkTemplate.fromNode,e),this.dataProvider.updateOptions({newLinkTemplate:{...t.newLinkTemplate,toNodeObject:e}}),this.onReadyToCreateLine(t.newLinkTemplate.fromNode,e)!==!0&&this.stopCreatingLinePlot()):(L("[CreatingLinePlot]step 1: set fromNode:",e),this.dataProvider.updateOptions({newLinkTemplate:{...t.newLinkTemplate,fromNode:e,toNode:{...t.newLinkTemplate.toNode,x:e.x+50,y:e.y+50}}}),this._step1EventTime=Date.now())}onReadyToCreateLine(e,t){L("[CreatingLinePlot][fire-event]onCreateLine:",e,t);const n=this.getOptions(),o=he(n.newLineTemplate,this.getOptions());n.newLineTemplate.isReverse?(o.from=t?t.id:"",o.to=e?e.id:"",o.isReverse=void 0,[e,t]=[t,e]):(o.from=e?e.id:"",o.to=t?t.id:""),o.disablePointEvent=!1;const s=this.emitEvent(I.beforeCreateLine,{lineJson:o,fromNode:e,toNode:t});if(L("[CreatingLinePlot]onCreateLine:abort-flag:",s),s===!0){L("[CreatingLinePlot]onCreateLine:abort!");return}if(this._onCreateLineCallback){L("[CreatingLinePlot]onCreateLine:callback");try{this._onCreateLineCallback(e,t,o)}catch(d){return console.warn("[Custom Reject Connect By Throw Error:",d),!1}}return L("[CreatingLinePlot]onCreateLine:emitEvent"),this.emitEvent(I.onLineBeCreated,{lineJson:o,fromNode:e,toNode:t})}onContextmenu(e){e.stopPropagation(),e.preventDefault(),this.stopCreatingLinePlot();let t="canvas",n=this.isNode(e.target);n?t="node":(n=this.isLine(e.target),n&&(t="line")),L("contextmenu:objectType",t,n);const o=ce(e),s=this.getCanvasXyByClientXy({x:o.clientX,y:o.clientY}),a=this.getViewXyByCanvasXy(s);this.emitEvent(I.onContextmenu,e,t,n,s,a)}async fullscreen(e){const t=this.getOptions();if(e!==void 0&&e===t.fullscreen)return;L("fullscreen:newValue:",e),e===void 0&&(e=!t.fullscreen);let n=this.$dom;t.fullscreenElementXPath&&(n=document.querySelector(t.fullscreenElementXPath)||this.$dom),await ko(n,e),this.dataProvider.updateOptions({fullscreen:e}),this.emitEvent(I.onFullscreen,e),this._dataUpdated()}onMouseWheel(e){const t=this.getOptions();if(!e.ctrlKey&&!e.metaKey&&(t.disableWheelEvent||t.wheelEventAction==="none"))return!0;try{e.preventDefault(),e.stopPropagation()}catch{}let{deltaX:n,deltaY:o,deltaMode:s}=e;s===1?(n*=40,o*=40):s===2&&(n*=800,o*=800),this._mouseWheelForce.x+=n,this._mouseWheelForce.y+=o,this._applyWheelEvent(e)}_applyWheelEvent(e){clearTimeout(this._mouseWheelTimer),this._mouseWheelTimer=setTimeout(()=>{const t=this._mouseWheelForce.x,n=this._mouseWheelForce.y;this._onMouseWheel(e,t,n),this._mouseWheelForce.x-=t,this._mouseWheelForce.y-=n,this._mouseWheelEventPrevApplyTime=Date.now(),(Math.abs(this._mouseWheelForce.x)>1||Math.abs(this._mouseWheelForce.y)>1)&&this._applyWheelEvent(e)},Date.now()-this._mouseWheelEventPrevApplyTime>50?0:50)}_onMouseWheel(e,t,n){const o=e.ctrlKey||e.metaKey,s=this.getOptions();if(!o&&s.wheelEventAction==="scroll"){let a=Math.max(Math.abs(t),Math.abs(n));const d=t/a,h=n/a;a>200&&(a=200);const c=s.mouseWheelSpeed/10*-d*a,f=s.mouseWheelSpeed/10*-h*a,p=this.emitEvent(I.beforeScrollStart,c,f,e);if(L("[scroll]","abortScroll:",p),p===!0)return;this.scrollView(c,f)}else if(!(!o&&s.wheelEventAction==="none")){const a={x:e.clientX,y:e.clientY};let d=s.mouseWheelSpeed/20*-n;d=Math.max(Math.min(d,20),-20),this.zoom(d,a,e)}}scrollView(e,t){const n=this.getOptions();this.dataProvider.setCanvasOffset(n.canvasOffset.x+e,n.canvasOffset.y+t),this._updateEditingControllerView(),this.updateShouldRenderGraphData(),this._dataUpdated()}onLineDragStart(e,t){L("onLineDragStart...");const n=this.getLinkByLine(e),o={x:n.fromNode.x,y:n.fromNode.y},s={x:n.toNode.x,y:n.toNode.y},a=(d,h,c,f,p)=>{const m=this.dataProvider.getCanvasScale();n.fromNode.x=o.x+d/m,n.fromNode.y=o.y+h/m,n.toNode.x=s.x+d/m,n.toNode.y=s.y+h/m,this._updateEditingControllerView(),this._dataUpdated()};le.startDrag(t,{x:0,y:0},(...d)=>{this.onLineDragEnd(...d)},a)}onLineDragEnd(e,t,n){L("onLineDragEnd"),this.updateElementLines()}onCanvasDragStart(e){if(ge(e)||e.target&&e.target.closest(".rg-line-peel"))return;const t=this.getOptions();if(this.dataProvider.isPerformanceMode()&&t.editingController.nodes.length>0){const n=this.getNodeAtEvent(e);if(n){this.onNodeDragStart(n,e);return}}if(t.dragEventAction==="none"){this.onCanvasClick(e);return}if(t.dragEventAction==="selection"||e.shiftKey){this.startCreateSelection(e);return}if(!t.disableDragLine){const n=this.isLine(e.target);if(n){this.onLineDragStart(n,e);return}}this.startMoveCanvas(e)}startMoveCanvas(e,t=!1){let n;if(de(e)){let f,p,m,u,g,y=0,v=100;const x=N=>{if("touches"in N&&N.touches.length>0)return N.touches;if("targetTouches"in N&&N.targetTouches.length>0)return N.targetTouches},w=N=>({x:N.clientX,y:N.clientY}),k=(N,P)=>Math.hypot(P.x-N.x,P.y-N.y),T=(N,P)=>({x:(N.x+P.x)/2,y:(N.y+P.y)/2}),O=(N,P)=>{if(f="pan",P)p={x:P.touch.x,y:P.touch.y},m={x:P.offset.x,y:P.offset.y};else{p=w(N);const R=this.getOptions();m={x:R.canvasOffset.x,y:R.canvasOffset.y}}},b=(N,P)=>{f="pinch";const R=w(N),S=w(P),M=this.getOptions();y=k(R,S),v=M.canvasZoom,g={x:M.canvasOffset.x,y:M.canvasOffset.y},u=this.getViewXyByClientXy(T(R,S))};n=(N,P,R,S,M)=>{const C=x(M);if(!(!C||C.length===0))if(M.cancelable&&M.preventDefault(),C.length>1){const E=C[0],V=C[1];f!=="pinch"&&b(E,V);const X=w(E),A=w(V),G=k(X,A);if(!u||!g||y<=0||G<=0){b(E,V);return}const $=this.getViewXyByClientXy(T(X,A)),J=G-y,ie=$.x-u.x,te=$.y-u.y;if(Math.abs(J)<6&&Math.abs(ie)<2&&Math.abs(te)<2)return;const ne=G/y,Q=Math.pow(ne,.85),Z=v*Q,oe=v/100,q=this.getClampedZoom(Z)/100,F=$.x-(u.x-g.x)*(q/oe),gs=$.y-(u.y-g.y)*(q/oe);this.setZoomAndOffset(Z,{x:F,y:gs})}else{const E=C[0];if(f!=="pan"&&O(E,f===void 0?{touch:S,offset:R}:void 0),!p||!m){O(E);return}const V=w(E),X=V.x-p.x,A=V.y-p.y,G=m.x+X,$=m.y+A;this.onCanvasDragging(G,$,X,A),this._updateEditingControllerView(),this._dataUpdated()}}}else n=(d,h,c,f,p)=>{const m=c.x+d,u=c.y+h;this.onCanvasDragging(m,u,d,h),this._updateEditingControllerView(),this._dataUpdated()};const o=this.getOptions(),s={x:o.canvasOffset.x,y:o.canvasOffset.y};let a=t;le.startDrag(e,s,(d,h,c)=>{this.onCanvasDragStop(d,h,c)},(d,h,c,f,p)=>{const m="touches"in p&&p.touches?p.touches.length:0;a||(m>1||Math.abs(d)+Math.abs(h)>4)&&(this.emitEvent(I.onCanvasDragStart,c,f,p),a=!0),a&&n(d,h,c,f,p)})}onCanvasDragging(e,t,n,o){const s=this.emitEvent(I.onCanvasDragging,e,t,n,o);s!==!1&&(s&&(typeof s.x=="number"&&(e=s.x),typeof s.y=="number"&&(t=s.y)),this.dataProvider.setCanvasOffset(e,t))}onCanvasDragStop(e,t,n){const o=this.getOptions();if(o.creatingSelection){this.dataProvider.updateOptions({creatingSelection:!1}),this.onCanvasSelectionEnd(o.selectionView,n);return}if(Math.abs(e)+Math.abs(t)<4){L("[canvas]onDragEnd as click2"),this._dataUpdated(),this.onCanvasClick(n);return}else L("[canvas]onDragEnd"),this.onCanvasDragEnd(n)}startCreateSelection(e){const t=()=>{if(!n||s)return;const c=this.getViewXyByEvent(n);this.canvasAutoMoving(c)&&this._updateEditingControllerView();const p=this.getViewXyByCanvasXy(a),m=c.x-p.x,u=c.y-p.y;m<0?this.dataProvider.updateOptions({selectionView:{...this.getOptions().selectionView,x:p.x+m,width:Math.abs(m)}}):this.dataProvider.updateOptions({selectionView:{...this.getOptions().selectionView,x:p.x,width:Math.abs(m)}}),u<0?this.dataProvider.updateOptions({selectionView:{...this.getOptions().selectionView,y:p.y+u,height:Math.abs(u)}}):this.dataProvider.updateOptions({selectionView:{...this.getOptions().selectionView,y:p.y,height:u}}),this._dataUpdated()};let n,o=!1,s=!0;const a=this.getCanvasXyByViewXy(this.getViewXyByEvent(e)),d=()=>{t(),this._canvasMovingTimer=requestAnimationFrame(d)},h=(c,f,p,m,u)=>{if(n=u,o)n=u;else if(Math.abs(c)+Math.abs(f)>6){o=!0,s=!1;const g=this.getOptions();g.selectionView.width=5,g.selectionView.height=5,this.dataProvider.updateOptions({creatingSelection:!0}),this._canvasMovingTimer&&cancelAnimationFrame(this._canvasMovingTimer),this._canvasMovingTimer=requestAnimationFrame(d)}this._dataUpdated()};le.startDrag(e,{x:0,y:0},(...c)=>{s=!0,this._canvasMovingTimer&&cancelAnimationFrame(this._canvasMovingTimer),this.onCanvasDragStop(...c)},h)}addFullscreenListener(){this._fullscreenchangeHandler=()=>{let e=!1;document.fullscreenElement?(L("div entered fullscreen mode",document.fullscreenElement),this.$dom===document.fullscreenElement&&(L("relation-graph is fullscreen!"),e=!0)):L("div exited fullscreen mode"),e!==this.getOptions().fullscreen&&(this.dataProvider.updateOptions({fullscreen:e}),this._dataUpdated(),setTimeout(async()=>{this.resetViewSize(),this._moveToCenter(),this.zoomToFit(),L("relation-graph reset complete!")},500))},document.addEventListener("fullscreenchange",this._fullscreenchangeHandler)}removeFullscreenListener(){document.addEventListener("fullscreenchange",this._fullscreenchangeHandler)}defaultLineConnectEndHandler(e,t,n){L("defaultLineConnectEndHandler:",e,t,n)}defaultLineVertexBeChangedHandler(e,t,n){L("defaultLineVertexBeChangedHandler:",n&&n.isReverse)}async sleep(e){await Ee(e)}forceLayoutTickCallback(){this._updateEditingControllerView(),this.dataProvider.updateShouldRenderGraphData(),this._dataUpdated()}}class So extends To{constructor(){super();_(this,"$easyViewCanvas");_(this,"$rgWebglPainter");_(this,"_updateEasyViewRequested",!1);_(this,"_easyViewOffset",{x:0,y:0})}setEasyViewCanvas(e){this.$easyViewCanvas=e,this.$rgWebglPainter=new kn(e)}updateEasyView(){this.updateMiniView(),this.dataProvider.isPerformanceMode()&&(!this.getOptions().showEasyView||this._updateEasyViewRequested||(this._updateEasyViewRequested=!0,requestAnimationFrame(this._updateEasyView.bind(this))))}_updateEasyView(e){try{const t=Date.now();if(!this.$easyViewCanvas)return;this.updateShouldRenderGraphData(),this.evDosomethingBeforeDraw(),this.evDrawAllLines(),this.evDrawAllNodes()}catch(t){console.error(t)}finally{this._updateEasyViewRequested=!1}}evDosomethingBeforeDraw(){const e=this.getOptions(),t=e.viewSize.width,n=e.viewSize.height;this.$easyViewCanvas.width=t,this.$easyViewCanvas.height=n,this.$rgWebglPainter.setSize(t,n);const o=this.dataProvider.getCanvasScale();this.$rgWebglPainter.setScale(o),this._easyViewOffset.x=e.canvasOffset.x,this._easyViewOffset.y=e.canvasOffset.y,this.$rgWebglPainter.setViewOffset(this._easyViewOffset.x,this._easyViewOffset.y),this.$rgWebglPainter.beforeDraw()}evDrawAllNodes(){const e=this.getOptions().defaultNodeShape;for(const t of this.getNodes()){if(!(t.rgShouldRender!==!1&&t.rgCalcedVisibility&&t.opacity!==0))continue;const o=Ce(t.nodeShape,e);this.evDrawNode(t,o)}}evDrawNode(e,t){t===xe.circle?this.evDrawNode4Circle(e):this.evDrawNode4Rect(e)}getNodeColor(e){const t=e.color||this.getOptions().defaultNodeColor||"#dddddd";return t==="transparent"?"rgba(204,204,204,0.2)":t}evDrawNode4Rect(e){const t=e.el_W,n=e.el_H,o=e.opacity||.8,s=this.getNodeColor(e),a=e.borderRadius===void 0?3:e.borderRadius,d=e.borderColor||"#666666";this.$rgWebglPainter.evDrawNode4Rect(e.x,e.y,t,n,s,o,a,d)}evDrawNode4Circle(e){const t=e.el_W,n=e.el_H,o=e.opacity||.8,s=this.getNodeColor(e),a=e.borderColor||"#666666";this.$rgWebglPainter.evDrawNode4Circle(e.x,e.y,t,n,s,o,a)}evDrawAllLines(){for(const e of this.getLinks()){const t=e.fromNode.rgShouldRender!==!1&&e.fromNode.opacity!==0&&e.fromNode.rgCalcedVisibility,n=e.toNode.rgShouldRender!==!1&&e.toNode.opacity!==0&&e.toNode.rgCalcedVisibility;!t&&!n||this.evDrawLine(e,e.line)}}evDrawLine(e,t){const n=this.createLineDrawInfo(e,t),o=t.opacity||1,s=this.getOptions(),a=t.color||s.defaultLineColor||"#888888",d=t.lineWidth||s.defaultLineWidth||1;this.$rgWebglPainter.evDrawLine(n.pathData,d,a,o)}}class Ro extends So{constructor(){super();_(this,"_onResizing");_(this,"_onResizeEnd");_(this,"_startPoint",{x:0,y:0});_(this,"_startEventCanvasXy",{x:0,y:0});_(this,"_startSizeCanvasXy",{x:0,y:0});_(this,"_startSize",{x:0,y:0,width:0,height:0,widthOnCanvas:0,heightOnCanvas:0});_(this,"_resizeType","l");_(this,"_nodeStartSizeMap",new WeakMap);_(this,"resizeMinLimit",{width:10,height:10});_(this,"_resizeDraggingTimer");_(this,"_resizeDraggingEvent");_(this,"_resizeDraggingStoped",!0);_(this,"_startCreateLineFromNodeTime",0)}setEditingNodes(e){if(e===null||e.length===0)this.dataProvider.setEditingNodes([]);else{const t=e.map(o=>o.id),n=this.getNodes().filter(o=>t.includes(o.id));this.dataProvider.setEditingNodes(n)}this._updateEditingControllerView(),this._dataUpdated()}addEditingNode(e){if(!this.getNodeById(e.id))throw new Error("Node not found: "+e.id);this.dataProvider.setEditingNodes(this.getOptions().editingController.nodes.concat(e)),this._updateEditingControllerView(),this._dataUpdated()}removeEditingNode(e){this.dataProvider.setEditingNodes(this.getOptions().editingController.nodes.filter(t=>t.id!==e.id)),this._updateEditingControllerView(),this._dataUpdated()}toggleEditingNode(e){this.getOptions().editingController.nodes.findIndex(n=>n.id===e.id)===-1?this.addEditingNode(e):this.removeEditingNode(e)}updateEditingControllerView(){this._updateEditingControllerView(),this._dataUpdated()}_updateEditingControllerView(){this._updateEditingLineView(),this._updateEditingConnectControllerView();const e=this.getOptions();if(!e.editingController.show)return;const{minX:t,minY:n,maxX:o,maxY:s}=this.getNodesRectBox(e.editingController.nodes),a=e.editingController.nodes.length>1?5:0,d=this.dataProvider.getCanvasScale();let h=o-t,c=s-n;if(h<0&&(h=0),c<0&&(c=0),h>0&&c>0){const f=this.getViewXyByCanvasXy({x:t,y:n}),p=f.x-a*d,m=f.y-a*d,u=h*d+a*2*d,g=c*d+a*2*d;this.dataProvider.updateOptions({editingController:{...e.editingController,x:p,y:m,width:u,height:g}})}else this.dataProvider.updateOptions({editingController:{...e.editingController,show:!1}})}onResizeStart(e,t){this._resizeType=e,this._startPoint=this.getViewXyByEvent(t),this._startEventCanvasXy=this.getCanvasXyByViewXy(this._startPoint);const n=this.getOptions();this._startSize.x=n.editingController.x,this._startSize.y=n.editingController.y,this._startSizeCanvasXy=this.getCanvasXyByViewXy(this._startSize),this._startSize.width=n.editingController.width,this._startSize.height=n.editingController.height;const o=this.dataProvider.getCanvasScale();this._startSize.widthOnCanvas=n.editingController.width/o,this._startSize.heightOnCanvas=n.editingController.height/o;for(const d of n.editingController.nodes)this._nodeStartSizeMap.set(d,{x:d.x,y:d.y,width:d.el_W,height:d.el_H});this._onResizing&&this.$dom.removeEventListener("mousemove",this._onResizing),this._onResizeEnd&&this.$dom.removeEventListener("mouseup",this._onResizeEnd),this._resizeDraggingEvent=null,this._resizeDraggingStoped=!1,this._onResizing=this.onResizing.bind(this),this._onResizeEnd=this.onResizeEnd.bind(this),this.$dom.addEventListener("mousemove",this._onResizing),this.$dom.addEventListener("mouseup",this._onResizeEnd);const s=this.onResizingRequest.bind(this),a=()=>{s(),this._resizeDraggingTimer=requestAnimationFrame(a)};this._resizeDraggingTimer=requestAnimationFrame(a),this.emitEvent(I.onResizeStart,n.editingController.nodes,t)}onResizing(e){this._resizeDraggingEvent=e}onResizingRequest(){if(!this._resizeDraggingEvent||this._resizeDraggingStoped)return;const e=this.getViewXyByEvent(this._resizeDraggingEvent);this.canvasAutoMoving(e);const t=this.getViewXyByCanvasXy(this._startEventCanvasXy),n=this.getViewXyByCanvasXy(this._startSizeCanvasXy),o=e.x-t.x,s=e.y-t.y,a=this.getOptions();let d=a.editingController.width,h=a.editingController.height,c=a.editingController.x,f=a.editingController.y;const p=this.dataProvider.getCanvasScale();this._resizeType==="tl"?(c=t.x+o,f=t.y+s,d=this._startSize.widthOnCanvas*p-o,h=this._startSize.heightOnCanvas*p-s):this._resizeType==="tr"?(f=t.y+s,c=n.x,d=this._startSize.widthOnCanvas*p+o,h=this._startSize.heightOnCanvas*p-s):this._resizeType==="bl"?(c=t.x+o,f=n.y,d=this._startSize.widthOnCanvas*p-o,h=this._startSize.heightOnCanvas*p+s):this._resizeType==="br"?(c=n.x,f=n.y,d=this._startSize.widthOnCanvas*p+o,h=this._startSize.heightOnCanvas*p+s):this._resizeType==="t"?(f=t.y+s,h=this._startSize.heightOnCanvas*p-s):this._resizeType==="r"?(c=n.x,d=this._startSize.widthOnCanvas*p+o):this._resizeType==="b"?(h=this._startSize.heightOnCanvas*p+s,f=n.y):this._resizeType==="l"&&(c=t.x+o,d=this._startSize.widthOnCanvas*p-o),d<this.resizeMinLimit.width&&(d=this.resizeMinLimit.width),h<this.resizeMinLimit.width&&(h=this.resizeMinLimit.height),this.dataProvider.updateOptions({editingController:{...a.editingController,x:c,y:f,width:d,height:h}}),this._applyResizeScale(this._resizeDraggingEvent),this._updateEditingControllerView(),this._dataUpdated()}_applyResizeScale(e){const t=this.getOptions(),n=this.dataProvider.getCanvasScale(),o=t.editingController.width/n/this._startSize.widthOnCanvas,s=t.editingController.height/n/this._startSize.heightOnCanvas,a=this._startSizeCanvasXy,d=this.getCanvasXyByViewXy({x:t.editingController.x,y:t.editingController.y});let h=!0,c=!0;this._resizeType==="t"||this._resizeType==="b"?h=!1:(this._resizeType==="r"||this._resizeType==="l")&&(c=!1);for(const f of t.editingController.nodes){const p=this._nodeStartSizeMap.get(f),m=p.width*o,u=p.height*s,g=d.x+o*(p.x-a.x),y=d.y+s*(p.y-a.y),v=m,x=u;this.emitEvent(I.beforeNodeResize,f,g,y,v,x)===!1||(h&&this.dataProvider.updateNode(f.id,{x:g,width:v,el_W:v}),c&&this.dataProvider.updateNode(f.id,{y,height:x,el_H:x}))}}onResizeEnd(e){cancelAnimationFrame(this._resizeDraggingTimer),this._resizeDraggingStoped=!0;const t=this.getViewXyByEvent(e),n=t.x-this._startPoint.x,o=t.y-this._startPoint.y;this._applyResizeScale(e),this.$dom.removeEventListener("mousemove",this._onResizing),this.$dom.removeEventListener("mouseup",this._onResizeEnd),this._onResizing=null,this._onResizeEnd=null,L("onResizeEnd:",this.getOptions().editingController.nodes,n,o),this.emitEvent(I.onResizeEnd,this.getOptions().editingController.nodes,n,o,e)}draggingSelectedNodes(e,t,n,o,s){const a=this.updateReferenceLineView(e,t,n,o,s);if(a){const{showV:h,fixedX:c,showH:f,fixedY:p}=a;h&&(o+=c-t,t=c),f&&(s+=p-n,n=p)}const d=this.getOptions();if(!d.editingController.nodes.includes(e))this.dataProvider.updateNode(e.id,{x:t,y:n}),this._updateEditingLineView();else{for(const h of d.editingController.nodes){const c=this._nodeXYMappingBeforeDrag[h.id];c&&this.dataProvider.updateNode(h.id,{x:c.x+o,y:c.y+s})}this._updateEditingControllerView()}}_updateEditingConnectControllerView(){const e=this.getOptions();if(!e.nodeConnectController.show)return;const t=e.nodeConnectController.node,n=t.x,o=t.y,s=t.x+t.el_W,a=t.y+t.el_H,d=0,h=this.dataProvider.getCanvasScale(),c=n,f=o,p=s-n,m=a-o,u=this.getViewXyByCanvasXy({x:c,y:f});this.dataProvider.updateOptions({nodeConnectController:{...e.nodeConnectController,x:u.x-d*h,y:u.y-d*h,width:p*h+d*2*h,height:m*h+d*2*h}})}setEditingLine(e){this.dataProvider.setEditingLine(e),this._updateEditingLineView(),this._dataUpdated()}updateReferenceLineView(e,t,n,o,s){const a=this.getOptions();if(!a.showReferenceLine)return;if(!a.editingReferenceLine.show){const M=Math.abs(o),C=Math.abs(s);M+C>2&&this.dataProvider.updateOptions({editingReferenceLine:{...a.editingReferenceLine,show:!0}})}if(!a.editingReferenceLine.show)return;const d=t,h=e.el_W,c=e.el_H,f=t+h/2,p=t+h,m=n,u=n+c/2,g=n+c,y=this.getViewXyByCanvasXy({x:f,y:u});let v=!1,x=!1,w=0,k=0;const T=this.getNodes().filter(M=>this._nodeXYMappingBeforeDrag[M.id]?!1:Math.abs(M.x-f)<600&&Math.abs(M.y-u)<600);T.sort((M,C)=>{const E=me(f,u,M.x+M.el_W/2,M.y+M.el_H/2),V=me(f,u,C.x+C.el_W/2,C.y+C.el_H/2);return E<V?-1:1});let{v_x:O,v_y:b,v_height:N,h_x:P,h_y:R,h_width:S}=a.editingReferenceLine;for(const M of T){const C=M.x,E=M.el_W,V=M.el_H,X=M.x+E/2,A=M.x+E,G=M.y,$=M.y+V/2,J=M.y+V,ie=Math.abs(d-C),te=Math.abs(f-X),ne=Math.abs(p-A),Q=Math.abs(m-G),Z=Math.abs(u-$),oe=Math.abs(g-J),q=5;if(te<800&&Z<800){if(!x&&te<q){const F=this.getViewXyByCanvasXy({x:X,y:$});O=F.x,b=y.y>F.y?F.y:y.y,N=Math.round(Math.abs(y.y-F.y)),x=!0,w=X-h/2}if(!x&&ie<q){const F=this.getViewXyByCanvasXy({x:C,y:$});O=F.x,b=y.y>F.y?F.y:y.y,N=Math.round(Math.abs(y.y-F.y)),x=!0,w=C}if(!x&&ne<q){const F=this.getViewXyByCanvasXy({x:A,y:$});O=F.x,b=y.y>F.y?F.y:y.y,N=Math.round(Math.abs(y.y-F.y)),x=!0,w=A-h}if(!v&&Z<q){const F=this.getViewXyByCanvasXy({x:X,y:$});R=F.y,P=y.x>F.x?F.x:y.x,S=Math.round(Math.abs(y.x-F.x)),v=!0,k=$-c/2}if(!v&&Q<q){const F=this.getViewXyByCanvasXy({x:X,y:G});R=F.y,P=y.x>F.x?F.x:y.x,S=Math.round(Math.abs(y.x-F.x)),v=!0,k=G}if(!v&&oe<q){const F=this.getViewXyByCanvasXy({x:X,y:J});R=F.y,P=y.x>F.x?F.x:y.x,S=Math.abs(y.x-F.x),v=!0,k=J-c}if(v&&x)break}}if(this.dataProvider.updateOptions({editingReferenceLine:{...a.editingReferenceLine,v_x:O,v_y:b,v_height:N,h_x:P,h_y:R,h_width:S,directionH:v,directionV:x}}),a.referenceLineAdsorption)return{showV:x,fixedX:w,showH:v,fixedY:k}}hideEditingLineView(){this.dataProvider.updateOptions({editingLineController:{...this.getOptions().editingLineController,show:!1}})}updateEditingLineView(){this._updateEditingLineView(),this._dataUpdated()}_updateEditingLineView(){this.updateElementLines();const e=this.getOptions();if(!e.editingLineController.show)return;const t=e.editingLineController.line,n=this.getLinkByLine(t);if(!t||t.to==="newRelationTemplate-to"){this.dataProvider.updateOptions({editingLineController:{...this.getOptions().editingLineController,show:!1}});return}let o,s,a;const d=this.createLineDrawInfo(n,t);if(!d){this.dataProvider.updateOptions({editingLineController:{...this.getOptions().editingLineController,show:!1}});return}if(t.lineShape===Y.StandardOrthogonal){let{textPosition:k,pathData:T,points:O,startDirection:b,endDirection:N}=d;a=k,o=O[0],s=O[O.length-1];const P=[];for(let R=0;R<O.length-1;R++){const S=O[R],M=O[R+1],C={pIndex:R,optionName:"cp-"+R,x:0,y:0,direction:"v",startDirection:b,endDirection:N};S.x!==M.x&&(C.direction="h");const E=this.getViewXyByCanvasXy({x:(S.x+M.x)/2,y:(S.y+M.y)/2});C.x=E.x,C.y=E.y,P.push(C)}if(P.length!==1){if(P.length!==2)if(P.length===3){const R=O[0],S=O[1],M=O[3];if(P[1].direction==="v"){const C=R.x,E=S.x,V=M.x;if(Math.max(C,E,V)!==E&&Math.min(C,E,V)!==E)P[1].optionName="cx";else{const A=Math.abs(E-C),G=Math.abs(E-V);A>=G?P[1].optionName="td":A<G&&(P[1].optionName="fd")}}else{const C=R.y,E=S.y,V=M.y;if(Math.max(C,E,V)!==E&&Math.min(C,E,V)!==E)P[1].optionName="cy";else{const A=Math.abs(E-C),G=Math.abs(E-V);A>=G?P[1].optionName="td":A<G&&(P[1].optionName="fd")}}}else P.length===4?(P[1].optionName="fd",P[2].optionName="td"):P.length===5&&(P[1].optionName="fd",P[2].direction==="v"?P[2].optionName="cx":P[2].optionName="cy",P[3].optionName="td")}this.dataProvider.updateOptions({editingLineController:{...this.getOptions().editingLineController,line44Splits:P,line49Points:O}})}else if(t.lineShape===Y.HardOrthogonal){let{textPosition:k,pathData:T,points:O,startDirection:b,endDirection:N}=d;a=k;const P=[];O=t.ctrlPointsFor49,o=O[0],s=O[O.length-1];const R=O;for(let S=0;S<R.length-1;S++){const M=R[S],C=R[S+1],E={pIndex:S,optionName:"cp-"+S,x:0,y:0,direction:"v",startDirection:b,endDirection:N};M.x!==C.x?(E.direction="h",Math.abs(M.x-C.x)<15&&(E.hide=!0)):Math.abs(M.y-C.y)<15&&(E.hide=!0);const V=this.getViewXyByCanvasXy({x:(M.x+C.x)/2,y:(M.y+C.y)/2});E.x=V.x,E.y=V.y,P.push(E)}for(let S=0;S<P.length;S++){const M=P[S-1],C=P[S],E=P[S+1];S===0&&C.direction===E.direction&&(C.hide=!0),S===P.length-1&&C.direction===M.direction&&(C.hide=!0)}this.dataProvider.updateOptions({editingLineController:{...this.getOptions().editingLineController,line44Splits:P,line49Points:R}})}else if(t.lineShape!==1){a=d.textPosition;const k=pt(d.pathData);let T,O;t.isReverse?(o=k.endPoint,s=k.startPoint,T=this.getViewXyByCanvasXy(k.ctrl1),O=this.getViewXyByCanvasXy(k.ctrl2)):(o=k.startPoint,s=k.endPoint,T=this.getViewXyByCanvasXy(k.ctrl1),O=this.getViewXyByCanvasXy(k.ctrl2)),this.dataProvider.updateOptions({editingLineController:{...this.getOptions().editingLineController,ctrlPoint1:T,ctrlPoint2:O}})}else{a=d.textPosition;const k=d.pathData,T=pt(k);o=T.startPoint,s=T.endPoint}const h=this.getViewXyByCanvasXy(t.isReverse?s:o),c=this.getViewXyByCanvasXy(t.isReverse?o:s);this.dataProvider.updateOptions({editingLineController:{...this.getOptions().editingLineController,startPoint:h,endPoint:c}});const f=this.getViewXyByCanvasXy(a),p=this.$canvasDom.querySelector(`g[data-id='${t.id}']`);let m=0,u=0,g=t.textOffsetX||0,y=t.textOffsetY||0;const v=this.dataProvider.getCanvasScale();let x=20,w=20;if(p){const k=p.querySelector("text.rg-line-text");if(k){g=Math.floor(parseFloat(k.getAttribute("x")||"0")),y=Math.floor(parseFloat(k.getAttribute("y")||"0"));const T=k.clientWidth,O=k.clientHeight;x=T,w=O}}x+=40,w+=10,x>120&&(x=120),w>20&&(w=20),this.dataProvider.updateOptions({editingLineController:{...this.getOptions().editingLineController,text:{...this.getOptions().editingLineController.text,width:x,height:w,x:f.x+m+g*v,y:f.y+u+y*v}}})}startMoveLineVertex(e,t,n){t.stopPropagation();const o=this.getOptions().editingLineController.line,s=this.getLinkByLine(o);let a,d;if(s)a=s.fromNode,d=s.toNode;else{const{from:f,to:p}=this.generateFakeLineConfig(o);a=f,d=p}let h=a;this.dataProvider.setEditingLine(null),s?this.removeLine(o):this.removeFakeLine(o);let c=!1;o.lineShape===Y.HardOrthogonal&&(o.lineShape=Y.StandardOrthogonal),e==="start"?(o.fromJunctionPointOffsetX=0,o.fromJunctionPointOffsetY=0,h=d,c=!0):(o.toJunctionPointOffsetX=0,o.toJunctionPointOffsetY=0),this.startCreatingLinePlot(t,{template:o,fromNode:h,isReverse:c,onCreateLine:n})}startCreateLineFromNode(e,t,n,o){n.stopPropagation();const s=JSON.parse(JSON.stringify(t));if(this._startCreateLineFromNodeTime=Date.now(),!s.from){if(!e){const d=this.getOptions().editingController.nodes;d.length===1&&(e=d[0])}e&&(s.from=e.id,s.fromType=e.targetType)}if(!s.from)throw console.error("Error:lineTemplate:",s),Error("Error:startCreateLineByTemplate: lineTemplate must has [fromType, from]");const a=this.getFakeLineTarget(s.fromType,s.from,s);if(!a)throw console.error("Error:fakeTarget[fromType, from]:",s.fromType,s.from,s),Error(`Error:startCreateLineByTemplate: error from fakeTarget[fromType, from]:${s.fromType}, ${s.from}`);s.lineShape||(s.lineShape=6),this.startCreatingLinePlot(n,{template:s,fromNode:a,isReverse:!1,onCreateLine:o})}onLineVertexBeDropped(e,t,n={x:0,y:0},o){t.stopPropagation();const s=this.getOptions();if(!s.creatingLinePlot||Date.now()-this._startCreateLineFromNodeTime<500)return;const a=s.nodeConnectController.node;let{toJunctionPoint:d,toJunctionPointOffsetX:h,toJunctionPointOffsetY:c,fromJunctionPoint:f,fromJunctionPointOffsetX:p,fromJunctionPointOffsetY:m}=s.newLineTemplate;if(!s.newLinkTemplate.fromNode)s.newLineTemplate.isReverse?(d=e,h=n.x,c=n.y):(f=e,p=n.x,m=n.y),this.dataProvider.updateOptions({newLineTemplate:{...this.getOptions().newLineTemplate,fromJunctionPoint:f,fromJunctionPointOffsetX:p,fromJunctionPointOffsetY:m,toJunctionPoint:d,toJunctionPointOffsetX:h,toJunctionPointOffsetY:c},newLinkTemplate:{...this.getOptions().newLinkTemplate,fromNode:a}});else{s.newLineTemplate.isReverse?(f=e,p=n.x,m=n.y):(d=e,h=n.x,c=n.y);const u=this.getOptions().newLinkTemplate.fromNode;this.dataProvider.updateOptions({newLineTemplate:{...this.getOptions().newLineTemplate,fromJunctionPoint:f,fromJunctionPointOffsetX:p,fromJunctionPointOffsetY:m,toJunctionPoint:d,toJunctionPointOffsetX:h,toJunctionPointOffsetY:c},newLinkTemplate:{...this.getOptions().newLinkTemplate,toNodeObject:a}});const g=a;try{const y={newLineTemplate:this.getOptions().newLineTemplate,fromNode:u,toNode:g};this.emitEvent(I.onLineVertexDropped,y),o&&o(y.fromNode,y.toNode,y.newLineTemplate),this.onReadyToCreateLine(this.getOptions().newLinkTemplate.fromNode,this.getOptions().nodeConnectController.node)!==!0&&this.stopCreatingLinePlot()}catch(y){this.stopCreatingLinePlot(),console.warn("[Custom Reject onCreateLine By Throw Error:",y)}}}startMoveLineText(e,t){if(ge(e))return;const n=this.getViewXyByEvent(e),s=this.getOptions().editingLineController.line,a=s.textOffsetX||0,d=s.textOffsetY||0;let h=!1;const c=p=>{const m=this.dataProvider.getCanvasScale(),u=this.getViewXyByEvent(p),g=u.x-n.x,y=u.y-n.y;(g>0||y>0)&&(h=!0);const v=Math.round(a+g/m),x=Math.round(d+y/m);this.dataProvider.updateLine(s.id,{textOffsetX:v,textOffsetY:x}),this._updateEditingLineView(),this._dataUpdated()},f=p=>{this.$dom.removeEventListener("mousemove",c),this.$dom.removeEventListener("mouseup",f),h&&t&&t(),this._dataUpdated()};this.$dom.addEventListener("mousemove",c),this.$dom.addEventListener("mouseup",f)}startMoveLine6CtrlPoint(e,t,n){t.stopPropagation(),t.preventDefault();const a=this.getOptions().editingLineController.line;let d=a.ctrlPoints||[];d.length===0&&(d.push({x:0,y:0}),d.push({x:0,y:0})),this.dataProvider.updateLine(a.id,{ctrlPoints:d}),d=a.ctrlPoints,a.isReverse&&(e=d.length-1-e);const h=this.dataProvider.getCanvasScale(),c=d[e],{x:f,y:p}=c,m=()=>{n(a),this._dataUpdated()};le.startDrag(t,{x:0,y:0},m,(u,g)=>{c.x=f+u/h,c.y=p+g/h,this.dataProvider.updateLine(a.id,{ctrlPoints:d}),this._updateEditingLineView(),this._dataUpdated()})}startMoveLine44CtrlPoint(e,t,n){t.stopPropagation(),t.preventDefault();const s=this.getOptions().editingLineController,a=s.line;let d=a.ctrlOptionsFor44;d||(d={cx:0,cy:0,fd:0,td:0},this.dataProvider.updateLine(a.id,{ctrlOptionsFor44:d}),d=a.ctrlOptionsFor44);const h=d[e.optionName],c={indexOffset:0};let f=a.ctrlPointsFor49?JSON.parse(JSON.stringify(a.ctrlPointsFor49)):null;const p=(u,g)=>{const y=this.dataProvider.getCanvasScale();if(a.lineShape===Y.StandardOrthogonal){if(e.optionName==="cx"){const x=h+u/y*1;d.cx=x,this.dataProvider.updateLine(a.id,{ctrlOptionsFor44:d})}else if(e.optionName==="cy"){const x=h+g/y*1;d.cy=x,this.dataProvider.updateLine(a.id,{ctrlOptionsFor44:d})}else if(e.optionName==="fd"){const v=Se[e.startDirection],x=e.direction==="v"?u*v.x:g*v.y;d.fd=h+x/y,this.dataProvider.updateLine(a.id,{ctrlOptionsFor44:d})}else if(e.optionName==="td"){const v=Se[e.endDirection],x=e.direction==="v"?u*v.x:g*v.y;d.td=h+x/y,this.dataProvider.updateLine(a.id,{ctrlOptionsFor44:d})}else if(e.direction==="v"&&Math.abs(u)>5||e.direction==="h"&&Math.abs(g)>5){const v=s.line49Points;f=JSON.parse(JSON.stringify(v)),this.dataProvider.updateLine(a.id,{ctrlPointsFor49:f}),this.dataProvider.updateLine(a.id,{lineShape:Y.HardOrthogonal})}}else if(a.lineShape===Y.HardOrthogonal){const{newPoints:v,pointsChanged:x}=$n(a.ctrlPointsFor49,f,e.pIndex+c.indexOffset,e,c,u/y,g/y);x&&(f=JSON.parse(JSON.stringify(v))),this.dataProvider.updateLine(a.id,{ctrlPointsFor49:v})}},m=()=>{if(a.lineShape===Y.HardOrthogonal){const u=Re(a.ctrlPointsFor49);this.dataProvider.updateLine(a.id,{ctrlPointsFor49:u})}this._updateEditingLineView(),n&&n(a),this._dataUpdated()};le.startDrag(t,{x:0,y:0},m,(u,g)=>{p(u,g),this._updateEditingLineView(),this._dataUpdated()})}onLineVertexBeDroppedOnConnectController(e,t,n,o){if(L("onLineVertexBeDroppedOnConnectController",e,t,n),t.stopPropagation(),!n){this.onLineVertexBeDropped(e,t,void 0,o);return}const s=ce(t),a=n.getBoundingClientRect(),d={x:a.left,y:a.top+a.height/2},h={x:a.left+a.width/2,y:a.top},c={x:a.left+a.width,y:a.top+a.height/2},f={x:a.left+a.width/2,y:a.top+a.height};let p=re.left;const m={x:0,y:0};if(e)p=e,p===re.top||p===re.bottom?m.x=s.clientX-f.x:p===re.right?m.y=s.clientY-c.y:m.y=s.clientY-d.y;else{const g=me(s.clientX,s.clientY,d.x,d.y),y=me(s.clientX,s.clientY,h.x,h.y),v=me(s.clientX,s.clientY,c.x,c.y),x=me(s.clientX,s.clientY,f.x,f.y),w=Math.min(g,y,v,x);w===g?(p=re.left,m.x=s.clientX-d.x,m.y=s.clientY-d.y):w===y?(p=re.top,m.x=s.clientX-h.x,m.y=s.clientY-h.y):w===v?(p=re.right,m.x=s.clientX-c.x,m.y=s.clientY-c.y):w===x&&(p=re.bottom,m.x=s.clientX-f.x,m.y=s.clientY-f.y)}const u=this.dataProvider.getCanvasScale();m.x=m.x/u,m.y=m.y/u,L("onMouseUpWithOffset:",e,m),this.onLineVertexBeDropped(p,t,m,o)}}class Mo extends Ro{constructor(){super();_(this,"$miniViewCanvas");_(this,"$mvCanvasCtx");_(this,"_canvasDomScale",1);_(this,"miniViewBox",{visibleAreaStart:{x:0,y:0},visibleAreaEnd:{x:0,y:0},canvas_start_x:0,canvas_start_y:0,canvas_end_x:0,canvas_end_y:0,canvas_width:0,canvas_height:0,miniview_width:0,miniview_height:0});_(this,"visibleArea",{x:0,y:0});_(this,"_canvasItemMiniSizeLimit",1)}setMiniViewCanvas(e){this.$miniViewCanvas=e,this.$mvCanvasCtx=this.$miniViewCanvas.getContext("2d")}updateMiniView(){!this.getOptions().showMiniView||(this.updateMiniViewVisibleArea(),this._updateMiniView())}_updateMiniView(){try{const e=Date.now();this.mvDosomethingBeforeDraw(),this.mvDrawAllNodes()}catch(e){console.error(e)}}mvDosomethingBeforeDraw(){let e=9999999,t=9999999,n=-9999999,o=-9999999,s=0;for(const x of this.getNodes())if(x.rgCalcedVisibility&&x.opacity!==0){x.x<e&&(e=x.x),x.y<t&&(t=x.y);const w=x.x+x.el_W,k=x.y+x.el_H;w>n&&(n=w),k>o&&(o=k),s++}const a=1,d=50,h=50;s===0?(this.miniViewBox.canvas_start_x=-100-d,this.miniViewBox.canvas_start_y=-100-h,this.miniViewBox.canvas_end_x=100+d,this.miniViewBox.canvas_end_y=100+h,this.miniViewBox.canvas_width=this.miniViewBox.canvas_end_x-this.miniViewBox.canvas_start_x,this.miniViewBox.canvas_height=this.miniViewBox.canvas_end_y-this.miniViewBox.canvas_start_y):(this.miniViewBox.canvas_start_x=e-d,this.miniViewBox.canvas_start_y=t-h,this.miniViewBox.canvas_end_x=n+d,this.miniViewBox.canvas_end_y=o+h,this.miniViewBox.canvas_width=this.miniViewBox.canvas_end_x-this.miniViewBox.canvas_start_x,this.miniViewBox.canvas_height=this.miniViewBox.canvas_end_y-this.miniViewBox.canvas_start_y);const c=this.$miniViewCanvas.parentElement.getBoundingClientRect(),f=c.width,p=c.height;let m=0,u=0,g=1;f/this.miniViewBox.canvas_width<p/this.miniViewBox.canvas_height?(g=f/this.miniViewBox.canvas_width*a,m=f,u=f/this.miniViewBox.canvas_width*this.miniViewBox.canvas_height):(g=p/this.miniViewBox.canvas_height*a,m=p/this.miniViewBox.canvas_height*this.miniViewBox.canvas_width,u=p),this.miniViewBox.miniview_width=f,this.miniViewBox.miniview_height=p,this.$miniViewCanvas.width=f,this.$miniViewCanvas.height=p,this.$mvCanvasCtx.canvas.width=f*window.devicePixelRatio,this.$mvCanvasCtx.canvas.height=p*window.devicePixelRatio,this.$mvCanvasCtx.canvas.style.width=`${f}px`,this.$mvCanvasCtx.canvas.style.height=`${p}px`;const y=(p-u)/2,v=(f-m)/2;this.miniViewBox.canvas_start_x-=v/g,this.miniViewBox.canvas_start_y-=y/g,this.$mvCanvasCtx.setTransform(window.devicePixelRatio,0,0,window.devicePixelRatio,0,0),this.$mvCanvasCtx.scale(g,g),this._canvasDomScale=g,this.$mvCanvasCtx.clearRect(0,0,this.$mvCanvasCtx.canvas.width,this.$mvCanvasCtx.canvas.height)}updateMiniViewVisibleArea(){const e=this.getCanvasXyByViewXy({x:0,y:0}),t=this.getOptions().viewSize,n=this.getCanvasXyByViewXy({x:t.width,y:t.height}),o=this._canvasDomScale,s=n.x-e.x,a=n.y-e.y;this.miniViewBox.visibleAreaStart=e,this.miniViewBox.visibleAreaEnd=n;const d=o*s,h=o*a,c=e.x-this.miniViewBox.canvas_start_x,f=e.y-this.miniViewBox.canvas_start_y,p=o*c,m=o*f;let u=!1;(p+d<0||m+h<0||m>this.miniViewBox.miniview_height||p>this.miniViewBox.miniview_width)&&(u=!0);const g=this.getOptions().miniViewVisibleHandle;(g.emptyContent!==u||g.width!==d||g.height!==h||g.x!==d||g.y!==h)&&this.dataProvider.updateOptions({miniViewVisibleHandle:{emptyContent:u,width:d,height:h,x:p,y:m}})}mvDrawAllNodes(){const e=this._canvasDomScale,t=this.getOptions().defaultNodeShape;for(const n of this.getNodes())if(n.rgCalcedVisibility&&n.opacity!==0){let o=n.el_W,s=n.el_H;e*o<this._canvasItemMiniSizeLimit&&(o=this._canvasItemMiniSizeLimit/this._canvasDomScale),e*s<this._canvasItemMiniSizeLimit&&(s=this._canvasItemMiniSizeLimit/this._canvasDomScale);const a=Ce(n.nodeShape,t);this.mvDrawNode(n,a,o,s)}}mvDrawNode(e,t,n,o){t===xe.circle?this.mvDrawNode4Circle(e,n,o):this.mvDrawNode4Rect(e,n,o)}mvDrawNode4Rect(e,t,n){const o=this.$mvCanvasCtx,s=e.x-this.miniViewBox.canvas_start_x,a=e.y-this.miniViewBox.canvas_start_y;o.beginPath(),o.globalAlpha=e.opacity||1,o.rect(s,a,t,n),o.fillStyle=this.getNodeColor(e),o.fill(),o.strokeStyle="#666666",o.lineWidth=2,o.stroke(),o.globalAlpha=1}mvDrawNode4Circle(e,t,n){const o=this.$mvCanvasCtx,s=e.x+t/2-this.miniViewBox.canvas_start_x,a=e.y+n/2-this.miniViewBox.canvas_start_y;o.beginPath(),o.globalAlpha=e.opacity||1,o.ellipse(s,a,t/2,n/2,0,0,2*Math.PI),o.fillStyle=this.getNodeColor(e),o.fill(),o.strokeStyle="#666666",o.lineWidth=2,o.stroke(),o.globalAlpha=1}mvDrawAllLines(){for(const e of this.getLinks())e.fromNode.rgCalcedVisibility&&e.toNode.rgCalcedVisibility&&this.mvDrawLine(e,e.line)}mvDrawLine(e,t){const n=this.$mvCanvasCtx,o=this.createLineDrawInfo(e,t);n.beginPath(),n.globalAlpha=t.opacity||1,this.mvDrawSvgPathOnCanvas(n,o.pathData);const s=this.getOptions();n.strokeStyle=t.color||s.defaultLineColor||"#888888",n.lineWidth=t.lineWidth||s.defaultLineWidth||1,n.stroke(),n.globalAlpha=1}mvDrawSvgPathOnCanvas(e,t){const n=t.match(/[a-zA-Z][^a-zA-Z]*/g);let o=0,s=0,a=0,d=0,h=0,c=0,f=0,p=0,m=!1;n.forEach(u=>{const g=u.trim().split(/[ ,]+/),y=g[0].toUpperCase(),v=g[0]===g[0].toLowerCase();switch(y){case"M":o=U(a,g[1],v)-this.miniViewBox.canvas_start_x,s=U(d,g[2],v)-this.miniViewBox.canvas_start_y,a=o,d=s,m&&(e.closePath(),m=!1),e.moveTo(o,s);break;case"L":o=U(a,g[1],v)-this.miniViewBox.canvas_start_x,s=U(d,g[2],v)-this.miniViewBox.canvas_start_y,e.lineTo(o,s);break;case"C":h=U(a,g[1],v),c=U(d,g[2],v),f=U(a,g[3],v),p=U(d,g[4],v),o=U(a,g[5],v),s=U(d,g[6],v),a=o,d=s,e.bezierCurveTo(h,c,f,p,o,s);break;case"Q":h=U(a,g[1],v),c=U(d,g[2],v),o=U(a,g[3],v),s=U(d,g[4],v),a=o,d=s;break;case"V":s=U(d,g[1],v),d=s,e.lineTo(o,s);break;case"H":o=U(a,g[1],v),a=o,e.lineTo(o,s);break;case"Z":e.closePath(),m=!1;break;default:L(`Unsupported command: ${y}`)}})}onVisibleViewHandleDragStart(e){e.preventDefault(),e.stopPropagation();const t=this.getOptions(),n=t.canvasOffset.x,o=t.canvasOffset.y,s=this.miniViewBox.canvas_width,a=this.miniViewBox.canvas_height,d=()=>{const u=p/this.miniViewBox.miniview_width,g=m/this.miniViewBox.miniview_height,y=this.dataProvider.getCanvasScale(),v=s*u*y,x=a*g*y;this.dataProvider.setCanvasOffset(n-v,o-x),this._updateEditingControllerView(),this.updateMiniViewVisibleArea(),this.updateShouldRenderGraphData(),this.dataProvider.dataUpdated()};let h;const c=(u,g,y)=>{h&&clearInterval(h),this.onCanvasDragEnd(y)};let f=!1,p=0,m=0;le.startDrag(e,{x:0,y:0},c,(u,g)=>{p=u,m=g,!f&&Math.abs(u)+Math.abs(g)>3&&(f=!0,h=setInterval(()=>{d()},50))})}resetByVisiableView(e){!this.getOptions().miniViewVisibleHandle.emptyContent||(this.setZoom(100),this._moveToCenter(),this.zoomToFit())}}class Eo extends Mo{constructor(){super();_(this,"$watermarkDom",null);_(this,"$watermarkPosition","br");_(this,"$backgroundDom",null);_(this,"_originBackgroundColor","");_(this,"graphStatusBeforeImageGeneration",{orignCanvasOffsetX:0,orignCanvasOffsetY:0,orignZoom:0,forceLayouting:!1})}setWatermarkDom(e,t=!0,n=!1,o="br"){t&&(this.$watermarkDom=e),this.$watermarkPosition=o}setBackgroundDom(e,t=!0,n=!0){e===null?(this._originBackgroundColor=this.options.backgroundColor,this.dataProvider.updateOptions({backgroundColor:"transparent"}),t?this.$backgroundDom=e:this.$backgroundDom=null):(this.dataProvider.updateOptions({backgroundColor:this._originBackgroundColor}),this.$backgroundDom=null)}async prepareForImageGeneration(){return this.updateShouldRenderGraphData(),this.updateElementLines(),await this.moveItemsAndFitContent(),this._dataUpdated(),this.$canvasDom.parentElement}async restoreAfterImageGeneration(){const{orignCanvasOffsetX:e,orignCanvasOffsetY:t,orignZoom:n,forceLayouting:o}=this.graphStatusBeforeImageGeneration;this.$canvasDom.parentElement.style.width="100%",this.$canvasDom.parentElement.style.height="100%",this.setZoom(n),this.dataProvider.updateOptions({canvasOffset:{x:e,y:t}}),this._dataUpdated(),o&&this.startAutoLayout(),this.clearLoading()}async moveItemsAndFitContent(){const e=this.getOptions(),t=e.canvasZoom,n=e.canvasOffset.x,o=e.canvasOffset.y,s=e.layout.autoLayouting===!0;s&&(this.stopAutoLayout(),await this.sleep(200)),this.loading("Generating..."),this.dataProvider.updateOptions({snapshotting:!0}),this.dataProvider.clearChecked(),this.setZoom(100),this.updateShouldRenderGraphData(!0),this._dataUpdated(),await this.sleep(200);const a=this.getNodesRectBox(),d=this.getCanvasSlotRectItems(),h=this.getNodesRectBox(d),c=100,f=Math.min(a.minX,h.minX)-c,p=Math.min(a.minY,h.minY)-c,m=Math.max(a.maxX,h.maxX)+c,u=Math.max(a.maxY,h.maxY)+c,g=f,y=p,v=m-f,x=u-p;this.graphStatusBeforeImageGeneration={orignCanvasOffsetX:n,orignCanvasOffsetY:o,orignZoom:t,forceLayouting:s},this.dataProvider.updateOptions({canvasOffset:{x:-g,y:-y}}),this._dataUpdated(),this.setZoom(100),this.$canvasDom.parentElement.style.width=v+"px",this.$canvasDom.parentElement.style.height=x+"px",L("export image:",{imageWidth:v,imageHeight:x,minX:f,minY:p,maxX:m,maxY:u,devicePixelRatio:window.devicePixelRatio}),await this.sleep(200)}}class Io extends Eo{constructor(){super();_(this,"resizeObserver");_(this,"resizeListenerMap",new WeakMap);_(this,"domToNodeIdMap",new WeakMap);_(this,"_trackpadGestureActive",!1);_(this,"_trackpadGestureStartZoom",100);_(this,"_trackpadGestureAnchorView");_(this,"_trackpadGestureStartOffset");_(this,"_mouseMoveHandler");_(this,"_gestureStartHandler");_(this,"_gestureChangeHandler");_(this,"_gestureEndHandler");_(this,"_lastMouseClientXy");_(this,"mutationObserver4Nodes");_(this,"mutationObserver4CanvasSlotBehind");_(this,"mutationObserver4CanvasSlotAbove");_(this,"_updateCanvasConnectTargetsTask");_(this,"onKeyDownHanlder");_(this,"onKeyUpHanlder")}setDom(e){L("relation-graph mounted on:",this.instanceId,e),this.$dom=e}setCanvasDom(e){L("relation-graph canvas dom mounted!"),this.$canvasDom=e,this.$lineTextContainer4NormalLine=null,this.$lineTextContainer4FakeLine=null,this.reinitMutationObservers(),this.getLineTextContainer({isFakeLine:!0}),this.getLineTextContainer({isFakeLine:!1})}getResizeObserver(){return this.resizeObserver||(this.resizeObserver=new ResizeObserver((e,t)=>{for(const n of e){const o=this.resizeListenerMap.get(n.target);o?n.borderBoxSize?o(n.borderBoxSize[0].inlineSize,n.borderBoxSize[0].blockSize):o(n.target.clientWidth,n.target.clientHeight):n.borderBoxSize?this._onNodeDomResize(n.target,n.borderBoxSize[0].inlineSize,n.borderBoxSize[0].blockSize):this._onNodeDomResize(n.target,n.target.clientWidth,n.target.clientHeight)}})),this.resizeObserver}initDom(){this.addResizeListener(this.$dom,(e,t)=>{L("resizeListener:this.$dom"),this.resetViewSize(),this.updateEasyView(),this._rgAsConnectArea&&this.updateCanvasConnectTargetsPosition("View Resize"),this._updateEditingLineView(),this._updateEditingControllerView(),this._dataUpdated(),setTimeout(()=>{L("resizeListener:updateShouldRenderGraphData"),this.emitEvent(I.onViewResize,{width:e,height:t}),this._dataUpdated()},500)}),this._rgAsConnectArea||(this.removeKeyboardListener(),this.addKeyboardListener(),this.removeTrackpadGestureListeners(),this.addTrackpadGestureListeners())}updateCanvasConnectTargetsPosition(e="api"){this.updateConnectTargetsOnCanvas(e,this.$dom.querySelector(".rg-canvas-slot-behind")),this.updateConnectTargetsOnCanvas(e,this.$dom.querySelector(".rg-canvas-slot-above"))}reinitMutationObservers(){this.destroyMutationObserver();const e=this.$canvasDom.querySelector(".rg-nodes-container-wrapper");if(e)this.mutationObserver4Nodes=new MutationObserver(o=>{if(this.dataProvider.getConnectTargets().length>0)for(const s of o){const a=this.getNodeElByChildrenTarget(s.target),d=this.domToNodeIdMap.get(a);d&&this.updateConnectTargetsOnNode("Mutation",d,a)}}),this.mutationObserver4Nodes.observe(e,{childList:!0,subtree:!0,characterData:!0});else throw new Error("MutationObserver:error:Can not find: .rg-nodes-container-wrapper");const t=this.$canvasDom.parentElement.querySelector(".rg-canvas-slot-behind");if(t)this.mutationObserver4CanvasSlotBehind=new MutationObserver(o=>{this.updateConnectTargetsOnCanvas("CanvasBehind-Mutation",t)}),this.mutationObserver4CanvasSlotBehind.observe(t,{childList:!0,subtree:!0,characterData:!0});else throw new Error("MutationObserver:error:Can not find: .rg-canvas-slot-behind");const n=this.$canvasDom.parentElement.querySelector(".rg-canvas-slot-above");n&&(this.mutationObserver4CanvasSlotAbove=new MutationObserver(o=>{this.updateConnectTargetsOnCanvas("CanvasAbove-Mutation",n)}),this.mutationObserver4CanvasSlotAbove.observe(n,{childList:!0,subtree:!0,characterData:!0}))}destroyMutationObserver(){this.mutationObserver4Nodes&&(this.mutationObserver4Nodes.disconnect(),this.mutationObserver4Nodes=void 0),this.mutationObserver4CanvasSlotBehind&&(this.mutationObserver4CanvasSlotBehind.disconnect(),this.mutationObserver4CanvasSlotBehind=void 0),this.mutationObserver4CanvasSlotAbove&&(this.mutationObserver4CanvasSlotAbove.disconnect(),this.mutationObserver4CanvasSlotAbove=void 0)}getTrackpadGestureAnchorView(){const e=this.getViewBoundingClientRect();return e?this._lastMouseClientXy?this.getViewXyByClientXy({x:this._lastMouseClientXy.x,y:this._lastMouseClientXy.y}):{x:e.width/2,y:e.height/2}:{x:0,y:0}}addTrackpadGestureListeners(){this._mouseMoveHandler=e=>{this._lastMouseClientXy={x:e.clientX,y:e.clientY}},this._gestureStartHandler=e=>{const t=e;ge(t)||(t.cancelable&&t.preventDefault(),t.stopPropagation(),this._trackpadGestureActive=!0,this._trackpadGestureStartZoom=this.getOptions().canvasZoom,this._trackpadGestureStartOffset={x:this.getOptions().canvasOffset.x,y:this.getOptions().canvasOffset.y},this._trackpadGestureAnchorView=this.getTrackpadGestureAnchorView())},this._gestureChangeHandler=e=>{const t=e;if(!this._trackpadGestureActive||!this._trackpadGestureAnchorView||!this._trackpadGestureStartOffset)return;t.cancelable&&t.preventDefault(),t.stopPropagation();const n=t.scale;if(!n||!Number.isFinite(n)||n<=0)return;const o=.01;if(Math.abs(n-1)<o)return;const s=this._trackpadGestureStartZoom*n,a=this._trackpadGestureStartZoom/100,d=this.getClampedZoom(s)/100,h=this._trackpadGestureAnchorView.x-(this._trackpadGestureAnchorView.x-this._trackpadGestureStartOffset.x)*(d/a),c=this._trackpadGestureAnchorView.y-(this._trackpadGestureAnchorView.y-this._trackpadGestureStartOffset.y)*(d/a);this.setZoomAndOffset(s,{x:h,y:c})},this._gestureEndHandler=e=>{const t=e;t.cancelable&&t.preventDefault(),t.stopPropagation(),this._trackpadGestureActive=!1,this._trackpadGestureAnchorView=void 0,this._trackpadGestureStartOffset=void 0},this.$dom.addEventListener("mousemove",this._mouseMoveHandler),this.$dom.addEventListener("gesturestart",this._gestureStartHandler),this.$dom.addEventListener("gesturechange",this._gestureChangeHandler),this.$dom.addEventListener("gestureend",this._gestureEndHandler)}removeTrackpadGestureListeners(){this._mouseMoveHandler&&this.$dom.removeEventListener("mousemove",this._mouseMoveHandler),this._gestureStartHandler&&this.$dom.removeEventListener("gesturestart",this._gestureStartHandler),this._gestureChangeHandler&&this.$dom.removeEventListener("gesturechange",this._gestureChangeHandler),this._gestureEndHandler&&this.$dom.removeEventListener("gestureend",this._gestureEndHandler),this._trackpadGestureActive=!1,this._trackpadGestureAnchorView=void 0,this._trackpadGestureStartOffset=void 0,this._mouseMoveHandler=void 0,this._gestureStartHandler=void 0,this._gestureChangeHandler=void 0,this._gestureEndHandler=void 0}addKeyboardListener(){this.onKeyDownHanlder=e=>{ge(e)||(e.code==="Space"&&(e.preventDefault(),this.getOptions().canvasMoveMode===!1&&this.setCanvasMoveMode(!0)),this.emitEvent(I.onKeyboardDown,e))},this.onKeyUpHanlder=e=>{ge(e)||(e.code==="Space"&&(e.preventDefault(),this.getOptions().canvasMoveMode===!0&&this.setCanvasMoveMode(!1)),this.emitEvent(I.onKeyboardUp,e))},this.$dom.addEventListener("keydown",this.onKeyDownHanlder),this.$dom.addEventListener("keyup",this.onKeyUpHanlder)}removeKeyboardListener(){this.onKeyDownHanlder&&this.$dom.removeEventListener("keydown",this.onKeyDownHanlder),this.onKeyUpHanlder&&this.$dom.removeEventListener("keyup",this.onKeyUpHanlder)}addResizeListener(e,t){this.resizeListenerMap.set(e,t),this.getResizeObserver().observe(e)}_onNodeDomResize(e,t,n){if(t===0||n===0)return;const o=this.domToNodeIdMap.get(e);this._onNodeResize(e,o,t,n)}_onNodeResize(e,t,n,o){n===0||o===0||(this.updateConnectTargetsOnNode("Node-Created",t,e),this.updateNodeOffsetSize(t,n,o))}addNodeResizeListener(e,t){this.domToNodeIdMap.set(e,t.id),this._onNodeResize(e,t.id,e.offsetWidth,e.offsetHeight),this.getResizeObserver().observe(e)}removeNodeResizeListener(e){this.domToNodeIdMap.delete(e),e?this.getResizeObserver().unobserve(e):L("removeNodeResizeListener: dom is null or undefined!")}removeResizeListener(e){this.resizeListenerMap.delete(e),this.resizeObserver&&this.resizeObserver.unobserve(e)}destroyResizeObserver(){this.resizeObserver&&this.resizeObserver.disconnect()}getCanvasSlotList(){return this.$dom.querySelectorAll(".rg-map > .rg-map-canvas > .rg-canvas-slot")}getCanvasSlotRectItems(){if(!this.$dom)return[];const e=this.getCanvasSlotList(),t=[];for(const n of e)for(const o of n.children){const s=o,a={x:s.offsetLeft||0,y:s.offsetTop||0,nodeShape:1,el_W:s.scrollWidth,el_H:s.scrollHeight};t.push(a)}return t}}class Do extends Io{constructor(){super()}dataUpdated(){this._requestDataUpdate()}setOptions(i){L("setOptions:",i),this._updateOptions(i),this._dataUpdated()}updateOptions(i){L("updateOptions:",i),this._updateOptions(i),this._dataUpdated()}moveToCenter(i){this._moveToCenter(i),this._dataUpdated()}transToLinker(i=!0){this._rgAsConnectArea=i,this.resetViewSize(),this.updateCanvasConnectTargetsPosition("Linker"),this.removeKeyboardListener(),this._rgAsConnectArea||this.addKeyboardListener(),this._dataUpdated()}setRootNodeId(i){L("setRootNodeId:",i),this.dataProvider.setRootNodeId(i)}getRootNode(){return this.dataProvider.getRootNode()}getCheckedNode(){return this.getNodeById(this.getOptions().checkedNodeId)}getCheckedLine(){const i=this.getLineById(this.getOptions().checkedLineId);return i||this.getFakeLineById(this.getOptions().checkedLineId)}getSelectedNodes(){return this.getNodes().filter(i=>i.selected)}getEditingNodes(){return[...this.getOptions().editingController.nodes]}async setJsonData(i){this._setJsonData(i),await this.doLayout(i.rootId)}async appendJsonData(i,e=!0){L("appendData:",i),this.loadGraphJsonData(i),e&&await this.doLayout()}async applyInitialData(i){L("applyInitialData:",i),await this.setJsonData(i),this.moveToCenter(),this.zoomToFit()}getGraphJsonData(){var o;const i=[],e=[],t=[];this.getNodes().forEach(s=>{const a=Te(s);a&&i.push(a)}),this.getLines().forEach(s=>{const a=be(s);a&&e.push(a)}),this.getFakeLines().forEach(s=>{const a=be(s);a&&t.push(a)});const n={rootId:((o=this.dataProvider.getRootNode())==null?void 0:o.id)||"",nodes:i,lines:e};return t.length>0&&(n.fakeLines=t),n}transRGNodeToJsonObject(i){return Te(i)}transRGLinkToJsonObject(i){return ze(i)}transRGLineToJsonObject(i){return be(i)}getGraphJsonOptions(){const i={},e=["layouter","layoutor","autoLayouting","canvasNVInfo","canvasOffset","canvasZoom","fullscreen","instanceId","layoutClassName","layoutDirection","layoutLabel","layoutName","resetViewSize","viewELSize","viewNVInfo","viewSize","canvasSize","newLinkTemplate","newLineTemplate","newNodeTemplate"],t=this.getOptions();return Object.keys(t).forEach(n=>{e.includes(n)||(i[n]=t[n])}),i}clearGraph(){this._clearGraph(),this._dataUpdated()}printOptions(){this.getGraphJsonOptions()}printData(){this.getGraphJsonData()}printGraphJsonData(){this.printOptions(),this.printData()}}class Lt extends Do{constructor(){super();_(this,"viewComponentUnmounted",!1)}setListeners(e){this.listeners=e}ready(){this.initDom(),this.resetViewSize(),this.addFullscreenListener(),this.emitEvent(I.onReady,this),this.viewComponentUnmounted=!1}beforeUnmount(){this.viewComponentUnmounted=!0,this.removeFullscreenListener(),this.removeKeyboardListener(),this.removeTrackpadGestureListeners(),this.destroyMutationObserver(),this.destroyResizeObserver()}}function wt(l,i=!1){const e=r.markRaw(l?Reflect.construct(l,[]):new Lt);return e._rgAsConnectArea=i,e}function _t(l,i=!1){const e=r.inject(ye,null);return e?e.graphInstance:wt(l,i)}const Fe=l=>({get value(){return l()}});function He(l){return r.defineComponent({name:"RGDataProvider",props:{options:{required:!1,type:Object}},setup(i,{slots:e}){if(!r.inject(ye,null)){const n=r.ref({rootNode:void 0,nodes:[],normalLines:[],fakeLines:[]}),o=r.ref({}),s=r.ref({nodes:[],lines:[],fakeLines:[]}),a=r.ref(null),d=r.ref(null),h=r.ref([]),c=r.ref([]),f=r.ref([]),p=r.ref(new Map),m=r.ref(new Map),u=Fe(()=>s.value.nodes),g=Fe(()=>s.value.lines),y=Fe(()=>s.value.fakeLines),T={store4Options:{set:O=>{}},store4ShouldRenderNodes:{set:O=>{}},store4ShouldRenderLines:{set:O=>{}},store4ShouldRenderFakeLines:{set:O=>{}},optionsRef:o,shouldRenderNodesRef:u,shouldRenderLinesRef:g,shouldRenderFakeLinesRef:y,textContainer4FakeLineRef:a,textContainer4NormalRef:d};l.setReactiveData4Vue3(T,n.value,o.value,{runtimeDATA4Links:f.value,runtimeDATA4ElLineTargets:h.value,runtimeDATA4ConnectTargets:c.value,runtimeDATA4NodeMap:p.value,runtimeDATA4LinkMap:m.value,runtimeDATA4ShouldRenderItems:s.value},(O,b,N)=>{O[b]=r.markRaw(N)}),l.setOptions(i.options||{}),r.provide(ye,{graphInstance:l})}return r.onMounted(()=>{}),()=>e.default?e.default():null}})}const $e={onReady:l=>!0,onNodeClick:(l,i)=>!0,onNodeExpand:(l,i)=>!0,onNodeCollapse:(l,i)=>!0,onLineClick:(l,i,e)=>!0,onNodeDragStart:(l,i)=>!0,onNodeDragEnd:(l,i,e,t)=>!0,onNodeDragging:(l,i,e,t,n,o)=>!0,onCanvasDragEnd:l=>!0,onCanvasDragging:(l,i,e,t)=>!0,onContextmenu:(l,i,e,t,n)=>!0,onFullscreen:(l,i)=>!0,onCanvasClick:l=>!0,onCanvasSelectionEnd:(l,i)=>!0,beforeZoomStart:()=>!0,onZoomEnd:()=>!0,onViewResize:()=>!0,onResizeStart:(l,i)=>!0,beforeNodeResize:(l,i,e,t,n)=>!0,onResizeEnd:(l,i,e,t)=>!0,onLineVertexDropped:l=>!0,beforeCreateLine:l=>!0,onLineBeCreated:l=>!0,beforeAddNodes:l=>!0,beforeAddLines:l=>!0,onKeyboardDown:l=>!0,onKeyboardUp:l=>!0,onCanvasDragStart:(l,i,e)=>!0,onForceLayoutFinish:()=>!0,beforeScrollStart:(l,i,e)=>!0};function Nt({relationGraphCore:l}={}){const i=_t(l),e=He(i);return{RelationGraph:r.defineComponent({name:"RelationGraph",props:{options:{required:!1,type:Object},initialData:{required:!1,type:Object},emitProxy:{required:!1,type:Function}},emits:$e,setup(t,{slots:n,emit:o}){return r.onMounted(()=>{const s=t.emitProxy||o;i.setEventEmitHook((a,...d)=>{s(a,...d)}),Je("Vue3"),t.options&&i.setOptions(t.options||{}),i.ready(),t.initialData&&i.applyInitialData(t.initialData)}),r.onBeforeUnmount(()=>{i.beforeUnmount()}),()=>r.h(e,{options:t.options},{default:()=>r.h(bn,t,n)})}}),graphInstance:i}}const Pe=l=>l,Vo=`graphRef.value.getInstance() will be deprecated
|
|
42
|
+
`}},It=["innerHTML"],K=r.defineComponent({__name:"RGIcons",props:{iconName:{},className:{}},setup(l){const i=l,e=r.computed(()=>Et[i.iconName]);return(t,n)=>(r.openBlock(),r.createElementBlock("svg",{class:r.normalizeClass(["rg-icon",t.className]),viewBox:"0 0 1024 1024",version:"1.1",xmlns:"http://www.w3.org/2000/svg",innerHTML:e.value.data},null,10,It))}}),je=r.defineComponent({__name:"RGNodeExpandHolder",props:{node:{},expandOrCollapseNode:{type:Function},expandHolderPosition:{}},setup(l){const i=l,e=r.computed(()=>i.node.expanded===!1?"c-expanded":"c-collapsed");return(t,n)=>(r.openBlock(),r.createElementBlock("div",{class:r.normalizeClass(["rg-node-expand-holder","c-expand-positon-"+t.expandHolderPosition])},[r.createElementVNode("div",{class:r.normalizeClass(["rg-node-expand-button",e.value]),onClick:n[0]||(n[0]=r.withModifiers((...o)=>t.expandOrCollapseNode&&t.expandOrCollapseNode(...o),["stop"])),onTouchend:n[1]||(n[1]=r.withModifiers((...o)=>t.expandOrCollapseNode&&t.expandOrCollapseNode(...o),["stop"]))},[t.node.expanded===!1?(r.openBlock(),r.createBlock(K,{key:0,iconName:"icon-fangda"})):(r.openBlock(),r.createBlock(K,{key:1,iconName:"icon-suoxiao"}))],34)],2))}});function H(){const l=r.inject(ye,null);if(!l)throw new Error("RGHooks.useGraphInstance must be used inside RGProvider or RelationGraph tag.");return l==null?void 0:l.graphInstance}const Dt=["data-id"],Vt={class:"rg-node-text"},qe=r.defineComponent({__name:"RGNodePeel",props:{nodeProps:{},defaultExpandHolderPosition:{},dragging:{type:Boolean},checked:{type:Boolean}},setup(l){const i=H(),e=l,t=r.ref(),n=r.computed(()=>e.nodeProps.borderColor),o=r.computed(()=>e.nodeProps.borderWidth===void 0?void 0:e.nodeProps.borderWidth+"px"),s=r.computed(()=>e.nodeProps.width?e.nodeProps.width+"px":void 0),a=r.computed(()=>e.nodeProps.height?e.nodeProps.height+"px":void 0),d=r.computed(()=>e.nodeProps.expandHolderPosition?e.nodeProps.expandHolderPosition!=="hide":e.defaultExpandHolderPosition&&e.defaultExpandHolderPosition!=="hide"&&e.nodeProps.rgChildrenSize>0),h=r.computed(()=>e.nodeProps.rgCalcedVisibility),c=p=>{i.expandOrCollapseNode(e.nodeProps,p)},f=p=>{i.onNodeDragStart(e.nodeProps,p)};return r.onMounted(()=>{i.addNodeResizeListener(t.value,e.nodeProps)}),r.onBeforeUnmount(()=>{i.removeNodeResizeListener(t.value)}),(p,m)=>r.withDirectives((r.openBlock(),r.createElementBlock("div",{ref_key:"nodePeelRef",ref:t,style:r.normalizeStyle({transform:`translate(${p.nodeProps.x}px, ${p.nodeProps.y}px)`,"--rg-node-z-index":p.nodeProps.zIndex?p.nodeProps.zIndex:void 0,"--rg-node-color":p.nodeProps.color,"--rg-node-font-color":p.nodeProps.fontColor,"--rg-node-font-size":p.nodeProps.fontSize?p.nodeProps.fontSize+"px":void 0,"--rg-node-border-width":o.value,"--rg-node-border-radius":p.nodeProps.borderRadius&&p.nodeProps.borderRadius+"px","--rg-node-border-color":n.value,"--rg-node-width":s.value,"--rg-node-height":a.value,"--rg-node-opacity":p.nodeProps.opacity===void 0?void 0:p.nodeProps.opacity}),class:r.normalizeClass(["rg-node-peel",p.nodeProps.selected&&"rg-node-selected",p.dragging&&"rg-node-dragging",p.checked&&"rg-node-checked",(p.nodeProps.disablePointEvent||p.nodeProps.opacity===0)&&"rg-node-disable-events","rg-node-shape-"+(p.nodeProps.nodeShape===void 0?1:p.nodeProps.nodeShape),"rg-node-type-"+p.nodeProps.type,p.nodeProps.className]),"data-id":p.nodeProps.id},[d.value?r.renderSlot(p.$slots,"node-expand-button",{key:0,node:p.nodeProps,expandOrCollapseNode:c,expandHolderPosition:p.nodeProps.expandHolderPosition||p.defaultExpandHolderPosition},()=>[r.createVNode(je,{node:p.nodeProps,checked:p.checked,expandOrCollapseNode:c,expandHolderPosition:p.nodeProps.expandHolderPosition||p.defaultExpandHolderPosition},null,8,["node","checked","expandHolderPosition"])]):r.createCommentVNode("",!0),r.createElementVNode("div",{class:"rg-node",onMousedown:r.withModifiers(f,["left","stop"]),onTouchstart:r.withModifiers(f,["stop"])},[r.renderSlot(p.$slots,"node",{node:p.nodeProps,checked:p.checked,dragging:p.dragging},()=>[r.createElementVNode("div",Vt,[r.createElementVNode("span",null,r.toDisplayString(p.nodeProps.text),1)])])],32)],14,Dt)),[[r.vShow,h.value]])}}),Bt={class:"rg-nodes-container"},At=r.defineComponent({__name:"RGCanvasContent4Nodes",props:{defaultExpandHolderPosition:{},draggingNodeId:{},checkedNodeId:{}},setup(l){const i=H(),e=r.computed(()=>i.getShouldRenderNodes(i.dataStores.shouldRenderNodesRef.value));return r.onMounted(()=>{L("[RGCanvas mounted]")}),(t,n)=>(r.openBlock(),r.createElementBlock("div",Bt,[(r.openBlock(!0),r.createElementBlock(r.Fragment,null,r.renderList(e.value,o=>(r.openBlock(),r.createBlock(qe,{key:o.id,"node-props":o,"default-expand-holder-position":t.defaultExpandHolderPosition,dragging:o.id===t.draggingNodeId,checked:o.id===t.checkedNodeId},{node:r.withCtx(s=>[r.renderSlot(t.$slots,"node",r.mergeProps({ref_for:!0},s))]),"node-expand-button":r.withCtx(s=>[r.renderSlot(t.$slots,"node-expand-button",r.mergeProps({ref_for:!0},s))]),_:2},1032,["node-props","default-expand-holder-position","dragging","checked"]))),128))]))}}),zt=["id","markerWidth","markerHeight","refX","refY","viewBox"],Xt=["d"],Gt=["id","markerWidth","markerHeight","refX","refY","viewBox"],Ft=["d"],Ze=r.defineComponent({__name:"RGGraphDefs",props:{forElementLines:{type:Boolean}},setup(l){const i=H(),e=r.computed(()=>i.dataStores.optionsRef.value);return(t,n)=>(r.openBlock(),r.createElementBlock("defs",null,[r.createElementVNode("marker",{id:e.value.instanceId+"-arrow-default",markerWidth:e.value.defaultLineMarker.markerWidth,markerHeight:e.value.defaultLineMarker.markerHeight,refX:e.value.defaultLineMarker.refX,refY:e.value.defaultLineMarker.refY,markerUnits:"userSpaceOnUse",orient:"auto",viewBox:e.value.defaultLineMarker.viewBox},[r.createElementVNode("path",{style:{fill:"context-stroke"},d:e.value.defaultLineMarker.data},null,8,Xt)],8,zt),r.createElementVNode("marker",{id:e.value.instanceId+"-start-arrow-default",markerWidth:e.value.defaultLineMarker.markerWidth,markerHeight:e.value.defaultLineMarker.markerHeight,refX:e.value.defaultLineMarker.refX,refY:e.value.defaultLineMarker.refY,markerUnits:"userSpaceOnUse",orient:"auto-start-reverse",viewBox:e.value.defaultLineMarker.viewBox},[r.createElementVNode("path",{style:{fill:"context-stroke"},d:e.value.defaultLineMarker.data},null,8,Ft)],8,Gt),r.renderSlot(t.$slots,"default")]))}});var D=(l=>(l.Node="node",l.NodePoint="NodePoint",l.HTMLElementId="HTMLElementId",l.CanvasPoint="CanvasPoint",l.ViewPoint="ViewPoint",l))(D||{}),W=(l=>(l.border="border",l.ltrb="ltrb",l.tb="tb",l.lr="lr",l.left="left",l.right="right",l.top="top",l.bottom="bottom",l))(W||{}),xe=(l=>(l[l.circle=0]="circle",l[l.rect=1]="rect",l))(xe||{}),Y=(l=>(l[l.StandardStraight=1]="StandardStraight",l[l.StandardCurve=6]="StandardCurve",l[l.Curve2=2]="Curve2",l[l.Curve3=3]="Curve3",l[l.Curve5=5]="Curve5",l[l.Curve7=7]="Curve7",l[l.Curve8=8]="Curve8",l[l.SimpleOrthogonal=4]="SimpleOrthogonal",l[l.StandardOrthogonal=44]="StandardOrthogonal",l[l.HardOrthogonal=49]="HardOrthogonal",l))(Y||{}),Ke=(l=>(l.Left="left",l.Top="top",l.Right="right",l.Bottom="bottom",l))(Ke||{}),I=(l=>(l.onReady="onReady",l.onNodeClick="onNodeClick",l.onNodeExpand="onNodeExpand",l.onNodeCollapse="onNodeCollapse",l.onLineClick="onLineClick",l.onNodeDragStart="onNodeDragStart",l.onNodeDragEnd="onNodeDragEnd",l.onNodeDragging="onNodeDragging",l.onCanvasDragEnd="onCanvasDragEnd",l.onCanvasDragging="onCanvasDragging",l.onContextmenu="onContextmenu",l.onFullscreen="onFullscreen",l.onCanvasClick="onCanvasClick",l.onCanvasSelectionEnd="onCanvasSelectionEnd",l.beforeZoomStart="beforeZoomStart",l.onZoomEnd="onZoomEnd",l.onViewResize="onViewResize",l.onResizeStart="onResizeStart",l.beforeNodeResize="beforeNodeResize",l.onResizeEnd="onResizeEnd",l.onLineVertexDropped="onLineVertexDropped",l.beforeCreateLine="beforeCreateLine",l.onLineBeCreated="onLineBeCreated",l.beforeAddNodes="beforeAddNodes",l.beforeAddLines="beforeAddLines",l.onKeyboardDown="onKeyboardDown",l.onKeyboardUp="onKeyboardUp",l.onCanvasDragStart="onCanvasDragStart",l.onForceLayoutFinish="onForceLayoutFinish",l.beforeScrollStart="beforeScrollStart",l))(I||{});const Ht={key:0},$t=["data-id"],Yt={key:1},Qe=r.defineComponent({__name:"RGLineText",props:{lineConfig:{},linePathInfo:{},checked:{type:Boolean}},setup(l){const i=H(),e=r.computed(()=>{var n;return(n=l.lineConfig)==null?void 0:n.line}),t=r.computed(()=>e.value.isFakeLine?i.dataStores.textContainer4FakeLineRef.value:i.dataStores.textContainer4NormalRef.value);return(n,o)=>e.value&&t.value?(r.openBlock(),r.createElementBlock("foreignObject",Ht,[(r.openBlock(),r.createBlock(r.Teleport,{to:t.value},[r.createElementVNode("div",{class:r.normalizeClass(["rg-line-peel",e.value.className,n.checked&&"rg-line-checked",(e.value.disablePointEvent||e.value.opacity===0)&&"rg-line-disable-events",e.value.selected&&"rg-line-selected"]),"data-id":e.value.id,style:r.normalizeStyle({"--rg-line-color":e.value.color,"--rg-line-fontsize":e.value.fontSize?`${e.value.fontSize}px`:void 0,"--rg-line-opacity":e.value.opacity,"--rg-line-fontcolor":e.value.fontColor,...e.value.cssVars||{}})},[r.renderSlot(n.$slots,"default")],14,$t)],8,["to"]))])):(r.openBlock(),r.createElementBlock("g",Yt,[r.createElementVNode("text",null,"Null-text-"+r.toDisplayString(!!e.value)+"-"+r.toDisplayString(!!t.value),1)]))}}),Wt=["data-id"],Ut=["d"],Jt=["id","d"],jt={key:0},qt=["dx","dy"],Zt=["xlink:href","startOffset","text-anchor"],et=r.defineComponent({__name:"RGLinePath",props:{lineConfig:{},linePathInfo:{},useTextOnPath:{type:Boolean},checked:{type:Boolean},graphInstanceId:{}},emits:["onLineClick"],setup(l,{emit:i}){const e=H(),t=i,n=r.computed(()=>l.lineConfig.line),o=r.computed(()=>e.getArrowMarkerId(l.lineConfig.line,!0)),s=r.computed(()=>e.getArrowMarkerId(l.lineConfig.line,!1)),a=r.computed(()=>e.generateLineTextStyle4TextOnPath(l.lineConfig)),d=r.computed(()=>l.lineConfig.line.lineWidth?l.lineConfig.line.lineWidth+"px":void 0),h=r.computed(()=>l.graphInstanceId+"-"+l.lineConfig.line.id),c=f=>{t("onLineClick",f)};return(f,p)=>(r.openBlock(),r.createElementBlock("g",{class:r.normalizeClass(["rg-line-peel",n.value.className,n.value.selected&&"rg-line-selected",(n.value.disablePointEvent||n.value.opacity===0)&&"rg-line-disable-events",f.checked&&"rg-line-checked"]),"data-id":n.value.id,style:r.normalizeStyle({"--rg-line-width":d.value,"--rg-line-color":n.value.color,"--rg-line-opacity":n.value.opacity,"--rg-line-fontcolor":n.value.fontColor,"--rg-line-marker-end":s.value,"--rg-line-marker-start":o.value,...n.value.cssVars||{}})},[r.createElementVNode("path",{d:f.linePathInfo.pathData,class:"rg-line-bg",onTouchstart:c,onClick:c},null,40,Ut),r.createElementVNode("path",{id:h.value,d:f.linePathInfo.pathData,class:r.normalizeClass(["rg-line",[n.value.dashType?"rg-line-dashtype-"+n.value.dashType:void 0,n.value.animation?"rg-line-anm-"+n.value.animation:void 0]])},null,10,Jt),f.useTextOnPath&&a.value?(r.openBlock(),r.createElementBlock("g",jt,[r.createElementVNode("text",{class:"rg-line-text rg-line-text-on-path",dx:a.value.textOffset.x+"px",dy:a.value.textOffset.y+"px",onTouchstart:c,onClick:c},[r.createElementVNode("textPath",{"xlink:href":"#"+h.value,startOffset:a.value.onPathStartOffset,"text-anchor":a.value.textAnchor,method:"align",spacing:"auto"},r.toDisplayString(a.value.text),9,Zt)],40,qt)])):r.createCommentVNode("",!0),r.renderSlot(f.$slots,"default")],14,Wt))}}),tt=r.defineComponent({__name:"RGLineContent",props:{lineConfig:{},checked:{type:Boolean},defaultLineTextOnPath:{type:Boolean},graphInstanceId:{}},setup(l){const i=H(),e=r.computed(()=>i.generateLinePath(l.lineConfig)),t=r.computed(()=>i.generateLineTextStyle(l.lineConfig,e.value)),n=r.computed(()=>l.lineConfig.line.useTextOnPath||l.defaultLineTextOnPath),o=r.computed(()=>n.value&&l.lineConfig.line.lineShape!==Y.StandardStraight),s=a=>{i.onLineClick(l.lineConfig.line,a)};return(a,d)=>(r.openBlock(),r.createElementBlock(r.Fragment,null,[r.createVNode(et,{lineConfig:a.lineConfig,linePathInfo:e.value,useTextOnPath:o.value,"graph-instance-id":a.graphInstanceId,checked:a.checked,onOnLineClick:s},null,8,["lineConfig","linePathInfo","useTextOnPath","graph-instance-id","checked"]),a.lineConfig.line.text&&!o.value?(r.openBlock(),r.createBlock(Qe,{key:0,lineConfig:a.lineConfig,linePathInfo:e.value,checked:a.checked},{default:r.withCtx(()=>[r.createElementVNode("div",{class:r.normalizeClass(`rg-line-label ${n.value?"rg-line-label-on-path":""}`),style:r.normalizeStyle({...t.value.cssStyles}),onTouchstart:s,onClick:s},r.toDisplayString(t.value.text),39)]),_:1},8,["lineConfig","linePathInfo","checked"])):r.createCommentVNode("",!0)],64))}}),Kt={key:0},nt=r.defineComponent({__name:"RGLinePeel",props:{line:{},checked:{type:Boolean},defaultLineTextOnPath:{type:Boolean},graphInstanceId:{}},setup(l){const i=H(),e=r.computed(()=>l.line.isFakeLine?i.generateFakeLineConfig(l.line):i.generateLineConfig(l.line));return(t,n)=>e.value?(r.openBlock(),r.createElementBlock("g",Kt,[r.renderSlot(t.$slots,"line",{lineConfig:e.value,defaultLineTextOnPath:t.defaultLineTextOnPath,graphInstanceId:t.graphInstanceId,checked:t.checked},()=>[r.createVNode(tt,{"line-config":e.value,defaultLineTextOnPath:t.defaultLineTextOnPath,"graph-instance-id":t.graphInstanceId,checked:t.checked},null,8,["line-config","defaultLineTextOnPath","graph-instance-id","checked"])])])):r.createCommentVNode("",!0)}}),Qt={class:"rg-lines-container rg-lines-container-el-lines"},en={class:"rg-lines-svg rg-lines-svg-el-lines",xmlns:"http://www.w3.org/2000/svg"},tn=r.defineComponent({__name:"RGCanvasContent4FakeLines",props:{showEasyView:{type:Boolean},defaultLineTextOnPath:{type:Boolean},checkedLineId:{},graphInstanceId:{}},setup(l){const i=H(),e=r.computed(()=>i.getShouldRenderFakeLines(i.dataStores.shouldRenderFakeLinesRef.value));return r.onMounted(()=>{L("[RGCanvas mounted]")}),(t,n)=>(r.openBlock(),r.createElementBlock("div",Qt,[n[0]||(n[0]=r.createElementVNode("div",{class:"rg-linetext-container"},null,-1)),(r.openBlock(),r.createElementBlock("svg",en,[r.createVNode(Ze,{"for-element-lines":!0}),t.showEasyView?r.createCommentVNode("",!0):(r.openBlock(!0),r.createElementBlock(r.Fragment,{key:0},r.renderList(e.value,o=>(r.openBlock(),r.createElementBlock(r.Fragment,{key:o.id},[o.hidden!==!0?(r.openBlock(),r.createBlock(nt,{key:0,line:o,defaultLineTextOnPath:t.defaultLineTextOnPath,checked:o.id===t.checkedLineId,"graph-instance-id":t.graphInstanceId},{line:r.withCtx(s=>[r.renderSlot(t.$slots,"line",r.mergeProps({ref_for:!0},s))]),_:2},1032,["line","defaultLineTextOnPath","checked","graph-instance-id"])):r.createCommentVNode("",!0)],64))),128))]))]))}}),nn={class:"rg-lines-container rg-lines-container-el-lines"},on={class:"rg-lines-svg rg-lines-svg-el-lines",xmlns:"http://www.w3.org/2000/svg"},sn=r.defineComponent({__name:"RGCanvasContent4CreatingLine",props:{defaultLineTextOnPath:{type:Boolean},checkedLineId:{},graphInstanceId:{}},setup(l){const i=H(),e=r.computed(()=>i.generateCreatingLineConfig(i.dataStores.optionsRef.value));return r.onMounted(()=>{L("[RGCanvas mounted]")}),(t,n)=>(r.openBlock(),r.createElementBlock("div",nn,[n[0]||(n[0]=r.createElementVNode("div",{class:"rg-linetext-container"},null,-1)),(r.openBlock(),r.createElementBlock("svg",on,[r.renderSlot(t.$slots,"line",{lineConfig:e.value},()=>[r.createVNode(tt,{"line-config":e.value,defaultLineTextOnPath:t.defaultLineTextOnPath,"graph-instance-id":t.graphInstanceId},null,8,["line-config","defaultLineTextOnPath","graph-instance-id"])])]))]))}}),an={class:"rg-lines-container rg-lines-container-normal-lines"},rn={class:"rg-lines-svg",xmlns:"http://www.w3.org/2000/svg"},ln=r.defineComponent({__name:"RGCanvasContent4Lines",props:{showEasyView:{type:Boolean},defaultLineTextOnPath:{type:Boolean},checkedLineId:{},graphInstanceId:{}},setup(l){const i=H(),e=r.computed(()=>i.getShouldRenderLines(i.dataStores.shouldRenderLinesRef.value));return r.onMounted(()=>{L("[RGCanvas mounted]")}),(t,n)=>(r.openBlock(),r.createElementBlock("div",an,[n[0]||(n[0]=r.createElementVNode("div",{class:"rg-linetext-container"},null,-1)),(r.openBlock(),r.createElementBlock("svg",rn,[r.createVNode(Ze),t.showEasyView?r.createCommentVNode("",!0):(r.openBlock(!0),r.createElementBlock(r.Fragment,{key:0},r.renderList(e.value,o=>(r.openBlock(),r.createElementBlock(r.Fragment,{key:o.id},[o.hidden!==!0?(r.openBlock(),r.createBlock(nt,{key:"l-"+o.id,line:o,defaultLineTextOnPath:t.defaultLineTextOnPath,checked:o.id===t.checkedLineId,"graph-instance-id":t.graphInstanceId},{line:r.withCtx(s=>[r.renderSlot(t.$slots,"line",r.mergeProps({ref_for:!0},s))]),_:2},1032,["line","defaultLineTextOnPath","checked","graph-instance-id"])):r.createCommentVNode("",!0)],64))),128))]))]))}}),dn={class:"rg-single-graph"},cn={class:"rg-nodes-container-wrapper"},ot=r.defineComponent({__name:"RGCanvasContent",props:{showEasyView:{type:Boolean},creatingLine:{type:Boolean},defaultExpandHolderPosition:{},draggingNodeId:{},checkedNodeId:{},checkedLineId:{},graphInstanceId:{},defaultLineTextOnPath:{type:Boolean}},setup(l){return(i,e)=>(r.openBlock(),r.createElementBlock("div",dn,[r.withMemo([i.defaultLineTextOnPath,i.checkedLineId],()=>r.createVNode(ln,{showEasyView:i.showEasyView,defaultLineTextOnPath:i.defaultLineTextOnPath,"checked-line-id":i.checkedLineId,"graph-instance-id":i.graphInstanceId},{line:r.withCtx(t=>[r.renderSlot(i.$slots,"line",r.normalizeProps(r.guardReactiveProps(t)))]),_:3},8,["showEasyView","defaultLineTextOnPath","checked-line-id","graph-instance-id"]),e,0),r.createElementVNode("div",cn,[i.showEasyView?r.createCommentVNode("",!0):r.withMemo([i.draggingNodeId,i.checkedNodeId,i.defaultExpandHolderPosition],()=>(r.openBlock(),r.createBlock(At,{key:0,"default-expand-holder-position":i.defaultExpandHolderPosition,draggingNodeId:i.draggingNodeId,checkedNodeId:i.checkedNodeId},{node:r.withCtx(t=>[r.renderSlot(i.$slots,"node",r.normalizeProps(r.guardReactiveProps(t)))]),"node-expand-button":r.withCtx(t=>[r.renderSlot(i.$slots,"node-expand-button",r.normalizeProps(r.guardReactiveProps(t)))]),_:3},8,["default-expand-holder-position","draggingNodeId","checkedNodeId"])),e,1)]),r.createVNode(tn,{showEasyView:i.showEasyView,defaultLineTextOnPath:i.defaultLineTextOnPath,"checked-line-id":i.checkedLineId,"graph-instance-id":i.graphInstanceId},{line:r.withCtx(t=>[r.renderSlot(i.$slots,"line",r.normalizeProps(r.guardReactiveProps(t)))]),_:3},8,["showEasyView","defaultLineTextOnPath","checked-line-id","graph-instance-id"]),i.creatingLine?(r.openBlock(),r.createBlock(sn,{key:0,defaultLineTextOnPath:i.defaultLineTextOnPath,"checked-line-id":i.checkedLineId},{line:r.withCtx(t=>[r.renderSlot(i.$slots,"line",r.normalizeProps(r.guardReactiveProps(t)))]),_:3},8,["defaultLineTextOnPath","checked-line-id"])):r.createCommentVNode("",!0)]))}}),hn=r.defineComponent({__name:"RGEasyView",setup(l){const i=H(),e=r.ref(),t=r.computed(()=>i.dataStores.optionsRef.value);return r.onMounted(()=>{L("[RGEasyView mounted]"),i.setEasyViewCanvas&&i.setEasyViewCanvas(e.value)}),(n,o)=>(r.openBlock(),r.createElementBlock("div",{class:r.normalizeClass(["rg-easy-view",{"rg-easy-view-active":t.value.showEasyView}])},[r.createElementVNode("canvas",{ref_key:"$rgEasyCanvas",ref:e,style:{width:"100%",height:"100%"}},null,512)],2))}}),fn={class:"rg-map-background"},pn={class:"rg-canvas-slot rg-canvas-slot-behind"},un={class:"rg-canvas-slot rg-canvas-slot-above"},gn=r.defineComponent({__name:"RGCanvas",setup(l){const i=r.ref(),e=H(),t=r.computed(()=>e.dataStores.optionsRef.value),n=a=>{e.onCanvasDragStart(a)},o=a=>{e.onContextmenu(a)},s=r.computed(()=>{const a=e.dataStores.optionsRef.value;return{width:`${a.canvasSize.width}px`,height:`${a.canvasSize.height}px`,"background-color":"transparent",transform:`translate(${a.canvasOffset.x}px, ${a.canvasOffset.y}px) scale(${a.canvasZoom/100},${t.value.canvasZoom/100})`}});return r.onMounted(()=>{L("[RGCanvas mounted]"),e.setCanvasDom(i.value)}),(a,d)=>(r.openBlock(),r.createElementBlock("div",{class:r.normalizeClass(["rg-map",[t.value.canvasOpacity===1&&"rg-map-ready"]]),onContextmenu:d[0]||(d[0]=r.withModifiers(h=>o(h),["prevent"])),onMousedown:d[1]||(d[1]=r.withModifiers(h=>n(h),["left"])),onTouchstart:d[2]||(d[2]=h=>n(h))},[r.createElementVNode("div",fn,[r.renderSlot(a.$slots,"background")]),r.createElementVNode("div",{style:r.normalizeStyle(s.value),class:"rg-map-canvas rg-canvas-behind"},[r.createElementVNode("div",pn,[r.renderSlot(a.$slots,"canvas-plug-behind")])],4),r.createVNode(hn),r.createElementVNode("div",{ref_key:"rgCanvasRef",ref:i,style:r.normalizeStyle(s.value),class:"rg-map-canvas"},[r.createVNode(ot,{"show-easy-view":t.value.showEasyView,"creating-line":!!(t.value.creatingLinePlot&&t.value.newLinkTemplate.fromNode),"default-expand-holder-position":t.value.defaultExpandHolderPosition,draggingNodeId:t.value.draggingNodeId,checkedNodeId:t.value.checkedNodeId,defaultLineTextOnPath:t.value.defaultLineTextOnPath,"checked-line-id":t.value.checkedLineId,"graph-instance-id":t.value.instanceId},{line:r.withCtx(h=>[r.renderSlot(a.$slots,"line",r.normalizeProps(r.guardReactiveProps(h)))]),node:r.withCtx(h=>[r.renderSlot(a.$slots,"node",r.normalizeProps(r.guardReactiveProps(h)))]),"node-expand-button":r.withCtx(h=>[r.renderSlot(a.$slots,"node-expand-button",r.normalizeProps(r.guardReactiveProps(h)))]),_:3},8,["show-easy-view","creating-line","default-expand-holder-position","draggingNodeId","checkedNodeId","defaultLineTextOnPath","checked-line-id","graph-instance-id"])],4),r.createElementVNode("div",{style:r.normalizeStyle(s.value),class:"rg-map-canvas rg-canvas-above"},[r.createElementVNode("div",un,[r.renderSlot(a.$slots,"canvas-plug-above")])],4)],34))}}),mn=r.defineComponent({__name:"GraphMoveOperator",setup(l){const i=H(),e=r.computed(()=>i.dataStores.optionsRef.value),t=r.computed(()=>e.value.canvasMoveMode),n=o=>{i.startMoveCanvas(o,!0)};return(o,s)=>(r.openBlock(),r.createElementBlock("div",{class:r.normalizeClass(["rg-move-operator",{"rg-move-operator-active":t.value}])},[r.createElementVNode("div",{class:"rg-move-touchpad",onMousedown:n,onTouchstart:n},null,32)],2))}}),yn={class:"rg-graph-loading-message"},vn=r.defineComponent({__name:"GraphLoading",setup(l){const i=H(),e=r.computed(()=>i.dataStores.optionsRef.value),t=n=>{i.clearLoading()};return(n,o)=>(r.openBlock(),r.createElementBlock("div",{class:r.normalizeClass(["rg-graph-loading",{"rg-graph-loading-hide":!e.value.graphLoading}]),onClick:t},[r.createElementVNode("div",yn,[r.createVNode(K,{"icon-name":"icon-lianjiezhong","class-name":"rg-graph-loading-icon"}),r.createTextVNode(" "+r.toDisplayString(e.value.graphLoadingText||"Loading..."),1)])],2))}}),xn={key:0,class:"rg-operate"},Cn={class:"rg-creating-container"},it=r.defineComponent({__name:"GraphOperateStuff",setup(l){const i=H(),e=r.computed(()=>i.dataStores.optionsRef.value);return(t,n)=>e.value?(r.openBlock(),r.createElementBlock("div",xn,[r.createElementVNode("div",Cn,[e.value.creatingNodePlot&&e.value.showTemplateNode?(r.openBlock(),r.createBlock(qe,{key:0,"node-props":e.value.newNodeTemplate},{node:r.withCtx(()=>[r.renderSlot(t.$slots,"node",{node:e.value.newNodeTemplate})]),_:3},8,["node-props"])):r.createCommentVNode("",!0),e.value.creatingSelection?(r.openBlock(),r.createElementBlock("div",{key:1,class:"rg-selection",style:r.normalizeStyle({transform:`translate(${e.value.selectionView.x}px, ${e.value.selectionView.y}px)`,width:e.value.selectionView.width+"px",height:e.value.selectionView.height+"px"})},null,4)):r.createCommentVNode("",!0)]),r.createVNode(mn),r.createVNode(vn)])):r.createCommentVNode("",!0)}}),Ln=["title"],st=r.defineComponent({__name:"GraphXsToolBar",props:{direction:{},positionH:{},positionV:{}},setup(l){const i=H(),e=r.computed(()=>i.dataStores.optionsRef.value),t=()=>{i.toggleAutoLayout()},n=async()=>{i.enableCanvasAnimation(),i.setZoom(100),i.moveToCenter(),i.zoomToFit(),setTimeout(()=>{i.disableCanvasAnimation()},300)},o=async a=>{i.zoom(a)},s=async()=>{i.fullscreen()};return(a,d)=>(r.openBlock(),r.createElementBlock("div",{class:r.normalizeClass(["rg-toolbar rg-xs-toolbar",["rg-toolbar-h-"+(a.positionH||e.value.toolBarPositionH||"left"),"rg-toolbar-v-"+(a.positionV||e.value.toolBarPositionV||"bottom"),"rg-toolbar-"+(a.direction||e.value.toolBarDirection||"h")]])},[r.createElementVNode("div",{title:"Full Screen",class:"rg-mb-button",style:{"margin-top":"0px"},onClick:s},[r.createVNode(K,{"icon-name":"icon-quanping"})]),r.createElementVNode("div",{class:"rg-mb-button",onClick:d[0]||(d[0]=h=>o(20))},[r.createVNode(K,{"icon-name":"icon-fangda"})]),r.createElementVNode("div",{class:"rg-current-zoom",onClick:n},r.toDisplayString(Math.round(e.value.canvasZoom))+"%",1),r.createElementVNode("div",{class:"rg-mb-button",style:{"margin-top":"0px"},onClick:d[1]||(d[1]=h=>o(-20))},[r.createVNode(K,{"icon-name":"icon-suoxiao"})]),e.value.layout.supportAutoLayout?(r.openBlock(),r.createElementBlock("div",{key:0,title:e.value.layout.autoLayouting?"Stop Force Layout":"Start Force Layout",class:r.normalizeClass([{"rg-mb-button-on":e.value.layout.autoLayouting},"rg-mb-button"]),onClick:t},[e.value.layout.autoLayouting?(r.openBlock(),r.createBlock(K,{key:1,"icon-name":"icon-lianjiezhong","class-name":"rg-loading-icon"})):(r.openBlock(),r.createBlock(K,{key:0,"icon-name":"icon-zidong"}))],10,Ln)):r.createCommentVNode("",!0),r.renderSlot(a.$slots,"default"),d[2]||(d[2]=r.createElementVNode("div",{style:{clear:"both"}},null,-1))],2))}}),wn=["id"],_n={class:"rg-graph-plugs"},Nn={class:"rg-view-slot"},bn=r.defineComponent({__name:"RelationGraphUI",setup(l){const i=H(),e=r.ref(),t=r.computed(()=>i.dataStores.optionsRef.value),n=r.ref(!1);r.onMounted(()=>{i.setDom(e.value),n.value=!0}),r.onBeforeUnmount(()=>{i.beforeUnmount()});const o=s=>{i.onMouseWheel(s)};return r.onMounted(()=>{}),(s,a)=>{var d,h,c,f,p,m,u,g,y,v,x;return r.openBlock(),r.createElementBlock("div",{ref_key:"relationGraphRef$",ref:e,id:"relation-graph-ins-"+((d=t.value)==null?void 0:d.instanceId),tabindex:"1",class:r.normalizeClass(["relation-graph",t.value&&t.value.creatingLinePlot?"rg-creating-line":"",t.value&&t.value.dragEventAction==="move"?"rg-move-mode":"",t.value&&t.value.enableNodeXYAnimation?"rg-enable-node-xy-animation":"",t.value&&t.value.enableCanvasTransformAnimation?"rg-enable-canvas-animation":""]),style:r.normalizeStyle({width:"100%",height:(h=t.value)!=null&&h.viewHeight?(c=t.value)==null?void 0:c.viewHeight:"100%",opacity:n.value?1:0,"--rg-checked-item-bg-color":(f=t.value)==null?void 0:f.checkedItemBackgroundColor,"--rg-background-color":(p=t.value)==null?void 0:p.backgroundColor,"--rg-node-color":(m=t.value)==null?void 0:m.defaultNodeColor,"--rg-node-border-color":(u=t.value)==null?void 0:u.defaultNodeBorderColor,"--rg-node-border-width":((g=t.value)==null?void 0:g.defaultNodeBorderWidth)+"px","--rg-node-border-radius":((y=t.value)==null?void 0:y.defaultNodeBorderRadius)+"px","--rg-line-color":(v=t.value)==null?void 0:v.defaultLineColor,"--rg-line-width":((x=t.value)==null?void 0:x.defaultLineWidth)+"px"}),onWheel:o},[t.value&&n.value?(r.openBlock(),r.createElementBlock(r.Fragment,{key:0},[t.value.showToolBar?(r.openBlock(),r.createBlock(st,{key:0})):r.createCommentVNode("",!0),r.createVNode(gn,null,{node:r.withCtx(w=>[r.renderSlot(s.$slots,"node",r.normalizeProps(r.guardReactiveProps(w)))]),line:r.withCtx(w=>[r.renderSlot(s.$slots,"line",r.normalizeProps(r.guardReactiveProps(w)))]),"canvas-plug-behind":r.withCtx(()=>[r.renderSlot(s.$slots,"canvas"),r.renderSlot(s.$slots,"default")]),"canvas-plug-above":r.withCtx(()=>[r.renderSlot(s.$slots,"canvas-above")]),"node-expand-button":r.withCtx(w=>[r.renderSlot(s.$slots,"node-expand-button",r.normalizeProps(r.guardReactiveProps(w)))]),background:r.withCtx(()=>[r.renderSlot(s.$slots,"background")]),_:3}),r.createVNode(it,null,{node:r.withCtx(w=>[r.renderSlot(s.$slots,"node",r.normalizeProps(r.guardReactiveProps(w)))]),_:3}),r.createElementVNode("div",_n,[r.createElementVNode("div",Nn,[r.renderSlot(s.$slots,"view")])])],64)):r.createCommentVNode("",!0)],46,wn)}}});class kn{constructor(i){_(this,"$evCanvasCtx");_(this,"viewScale",1);_(this,"offset",{x:0,y:0});const e=i.getContext("2d");if(!e)throw new Error("\u65E0\u6CD5\u83B7\u53D6 Canvas 2D \u4E0A\u4E0B\u6587");this.$evCanvasCtx=e}setSize(i,e){const t=this.$evCanvasCtx.canvas;t.width=i*window.devicePixelRatio,t.height=e*window.devicePixelRatio,t.style.width=`${i}px`,t.style.height=`${e}px`,this.$evCanvasCtx.setTransform(window.devicePixelRatio,0,0,window.devicePixelRatio,0,0),this.applyCurrentViewTransform()}setScale(i){this.viewScale=i,this.applyCurrentViewTransform()}applyCurrentViewTransform(){this.$evCanvasCtx.setTransform(window.devicePixelRatio,0,0,window.devicePixelRatio,0,0),this.$evCanvasCtx.scale(this.viewScale,this.viewScale)}setViewOffset(i,e){this.offset.x=i/this.viewScale,this.offset.y=e/this.viewScale}beforeDraw(){}evDrawNode4Rect(i,e,t,n,o,s,a=5,d){const h=this.$evCanvasCtx,c=this.offset.x+i,f=this.offset.y+e;let p=Math.max(0,a);t<2*p&&(p=t/2),n<2*p&&(p=n/2),h.beginPath(),h.globalAlpha=s,p===0?h.rect(c,f,t,n):(h.moveTo(c+p,f),h.arcTo(c+t,f,c+t,f+p,p),h.arcTo(c+t,f+n,c+t-p,f+n,p),h.arcTo(c,f+n,c,f+n-p,p),h.arcTo(c,f,c+p,f,p),h.closePath()),h.fillStyle=o,h.fill(),h.globalAlpha=1,h.strokeStyle=d,h.lineWidth=1,h.stroke()}evDrawNode4Circle(i,e,t,n,o,s,a){const d=this.$evCanvasCtx,h=this.offset.x+i+t/2,c=this.offset.y+e+n/2;d.beginPath(),d.globalAlpha=s,d.ellipse(h,c,t/2,n/2,0,0,2*Math.PI),d.fillStyle=o,d.fill(),d.strokeStyle=a,d.lineWidth=1,d.stroke(),d.globalAlpha=1}evDrawLine(i,e,t,n){const o=this.$evCanvasCtx;o.beginPath(),o.globalAlpha=n,this.evDrawSvgPathOnCanvas(o,i),o.strokeStyle=t,o.lineWidth=e*this.viewScale<.5?.5:e,o.stroke(),o.globalAlpha=1}getPointValue(i,e,t){return t?i+parseFloat(e):parseFloat(e)}evDrawSvgPathOnCanvas(i,e){const t=e.match(/[a-zA-Z][^a-zA-Z]*/g);if(!t)return;let n=0,o=0,s=0,a=0,d=0,h=0,c=0,f=0,p="";i.beginPath(),t.forEach(m=>{const u=m.trim(),g=u.charAt(0),v=u.substring(1).trim().split(/[ ,]+/).filter(C=>C!=="").map(parseFloat);let x=0,w=0,k=0,T=0,O=0,b=0,N=0,P=0,R=0,S=0,M=0;switch(g){case"M":n=v[0],o=v[1],s=n,a=o,i.moveTo(n+this.offset.x,o+this.offset.y);for(let C=2;C<v.length;C+=2)n=v[C],o=v[C+1],i.lineTo(n+this.offset.x,o+this.offset.y);break;case"L":for(let C=0;C<v.length;C+=2)n=v[C],o=v[C+1],i.lineTo(n+this.offset.x,o+this.offset.y);break;case"l":for(let C=0;C<v.length;C+=2)n+=v[C],o+=v[C+1],i.lineTo(n+this.offset.x,o+this.offset.y);break;case"H":for(let C=0;C<v.length;C++)n=v[C],i.lineTo(n+this.offset.x,o+this.offset.y);break;case"h":for(let C=0;C<v.length;C++)n+=v[C],i.lineTo(n+this.offset.x,o+this.offset.y);break;case"V":for(let C=0;C<v.length;C++)o=v[C],i.lineTo(n+this.offset.x,o+this.offset.y);break;case"v":for(let C=0;C<v.length;C++)o+=v[C],i.lineTo(n+this.offset.x,o+this.offset.y);break;case"C":for(let C=0;C<v.length;C+=6)k=v[C],T=v[C+1],O=v[C+2],b=v[C+3],x=v[C+4],w=v[C+5],i.bezierCurveTo(k+this.offset.x,T+this.offset.y,O+this.offset.x,b+this.offset.y,x+this.offset.x,w+this.offset.y),n=x,o=w,d=O,h=b;break;case"c":for(let C=0;C<v.length;C+=6)k=n+v[C],T=o+v[C+1],O=n+v[C+2],b=o+v[C+3],x=n+v[C+4],w=o+v[C+5],i.bezierCurveTo(k+this.offset.x,T+this.offset.y,O+this.offset.x,b+this.offset.y,x+this.offset.x,w+this.offset.y),d=O,h=b,n=x,o=w;break;case"S":for(let C=0;C<v.length;C+=4)p.match(/[CS]/i)?(k=2*n-d,T=2*o-h):(k=n,T=o),O=v[C],b=v[C+1],x=v[C+2],w=v[C+3],i.bezierCurveTo(k+this.offset.x,T+this.offset.y,O+this.offset.x,b+this.offset.y,x+this.offset.x,w+this.offset.y),n=x,o=w,d=O,h=b;break;case"s":for(let C=0;C<v.length;C+=4)p.match(/[CS]/i)?(k=2*n-d,T=2*o-h):(k=n,T=o),O=n+v[C],b=o+v[C+1],x=n+v[C+2],w=o+v[C+3],i.bezierCurveTo(k+this.offset.x,T+this.offset.y,O+this.offset.x,b+this.offset.y,x+this.offset.x,w+this.offset.y),d=O,h=b,n=x,o=w;break;case"Q":for(let C=0;C<v.length;C+=4)k=v[C],T=v[C+1],x=v[C+2],w=v[C+3],i.quadraticCurveTo(k+this.offset.x,T+this.offset.y,x+this.offset.x,w+this.offset.y),n=x,o=w,c=k,f=T;break;case"q":for(let C=0;C<v.length;C+=4)k=n+v[C],T=o+v[C+1],x=n+v[C+2],w=o+v[C+3],i.quadraticCurveTo(k+this.offset.x,T+this.offset.y,x+this.offset.x,w+this.offset.y),c=k,f=T,n=x,o=w;break;case"T":for(let C=0;C<v.length;C+=2)p.match(/[QT]/i)?(k=2*n-c,T=2*o-f):(k=n,T=o),x=v[C],w=v[C+1],i.quadraticCurveTo(k+this.offset.x,T+this.offset.y,x+this.offset.x,w+this.offset.y),n=x,o=w,c=k,f=T;break;case"t":for(let C=0;C<v.length;C+=2)p.match(/[QT]/i)?(k=2*n-c,T=2*o-f):(k=n,T=o),x=n+v[C],w=o+v[C+1],i.quadraticCurveTo(k+this.offset.x,T+this.offset.y,x+this.offset.x,w+this.offset.y),c=k,f=T,n=x,o=w;break;case"A":for(let C=0;C<v.length;C+=7)N=v[C],P=v[C+1],R=v[C+2],S=v[C+3],M=v[C+4],x=v[C+5],w=v[C+6],this.drawArc(i,n,o,N,P,R,S,M,x,w),n=x,o=w;break;case"a":for(let C=0;C<v.length;C+=7)N=v[C],P=v[C+1],R=v[C+2],S=v[C+3],M=v[C+4],x=n+v[C+5],w=o+v[C+6],this.drawArc(i,n,o,N,P,R,S,M,x,w),n=x,o=w;break;case"Z":case"z":i.closePath(),n=s,o=a;break;default:console.warn(`\u672A\u652F\u6301\u7684SVG\u547D\u4EE4\u5B57\u7B26: ${g}`)}g.match(/[CSQT]/i)?p=g:p=""})}drawArc(i,e,t,n,o,s,a,d,h,c){if(n=Math.abs(n),o=Math.abs(o),n===0||o===0){i.lineTo(h+this.offset.x,c+this.offset.y);return}const f=s%360*Math.PI/180,p=Math.sin(f),m=Math.cos(f),u=m*(e-h)/2+p*(t-c)/2,g=-p*(e-h)/2+m*(t-c)/2,y=u*u/(n*n)+g*g/(o*o);y>1&&(n*=Math.sqrt(y),o*=Math.sqrt(y));let v=(a===d?-1:1)*Math.sqrt(Math.max(0,(n*n*o*o-n*n*g*g-o*o*u*u)/(n*n*g*g+o*o*u*u)));isNaN(v)&&(v=0);const x=v*n*g/o,w=v*-o*u/n,k=m*x-p*w+(e+h)/2,T=p*x+m*w+(t+c)/2,O=(u-x)/n,b=(g-w)/o,N=(-u-x)/n,P=(-g-w)/o;let R=Math.atan2(b,O),S=Math.atan2(b*N-O*P,O*N+b*P);d===0&&S>0?S-=2*Math.PI:d===1&&S<0&&(S+=2*Math.PI);const M=R+S;i.ellipse?i.ellipse(k+this.offset.x,T+this.offset.y,n,o,f,R,M,d===0):(console.warn("ctx.ellipse is not supported. Arc will be drawn as a line."),i.lineTo(h+this.offset.x,c+this.offset.y))}}const z={getDescendantNodes(l,i=[]){return l.lot&&l.lot.childs&&l.lot.childs.forEach(e=>{i.push(e),z.getDescendantNodes(e,i)}),i},isVisibleNode(l,i=0){return typeof i!="number"&&(i=0),i>18?!0:l.hidden?!1:l.lot&&l.lot.parent?l.lot.parent.expanded===!1?!1:z.isVisibleNode(l.lot.parent,i+1):!0},isAllowShowNode(l,i=0){return z.isVisibleNode(l,i=0)},getNodeWidth(l){return l.el_W||l.width||50},getNodeHeight(l){return l.el_H||l.height||50},getNodeXByLotX(l,i){const e=i.lot.x||0;return l.alignItemsX==="end"?e-z.getNodeWidth(i):l.alignItemsX==="start"?e:e-z.getNodeWidth(i)/2},getNodeYByLotY(l,i){const e=i.lot.y||0;return l.alignItemsY==="end"?e-z.getNodeHeight(i):l.alignItemsY==="start"?e:e-z.getNodeHeight(i)/2},getNodeLotXY(l,i){let e=i.x||0,t=i.y||0;return l.alignItemsX==="end"?e=e+z.getNodeWidth(i):l.alignItemsX==="start"||(e=e+z.getNodeWidth(i)/2),l.alignItemsY==="end"?t=t+z.getNodeHeight(i):l.alignItemsY==="start"||(t=t+z.getNodeHeight(i)/2),{x:e,y:t}},isRectangleOverlap(l,i){const e=l.x,t=i.x,n=l.el_W,o=i.el_W,s=l.y,a=i.y,d=l.el_H,h=i.el_H;return!(t>=e+n||t+o<=e||a>=s+d||a+h<=s)},isXOverlap(l,i,e,t){return!(i>=l+e||i+t<=l)},isYOverlap(l,i,e,t){return!(i>=l+e||i+t<=l)},shapesOverlap(l,i,e=1,t=1){return this.isRectangleOverlap(l,i)},getNoOverlapLimitedPosition(l,i,e,t){const n=l.x,o=l.y,s=i,a=t.x,d=l.el_W,h=t.el_W,c=e,f=t.y,p=l.el_H,m=t.el_H;let u=l.x,g=l.y;const y=this.isXOverlap(n,a,d,h),v=this.isYOverlap(o,f,p,m);return y?c<f?(u=i,g=f-p):c>f&&(u=i,g=f+m):v&&(s<a?(u=a-d,g=e):s>a&&(u=a+h,g=e)),{x:u,y:g}},flatNodeData(l,i,e,t){l.forEach(n=>{e.push(n),i&&t.push({from:i.id,to:n.id});const o=n.children||n.childs;o&&o.length>0&&this.flatNodeData(o,n,e,t)})}},Ce=(l,i)=>l||l===0?l:i,Le=z,De={id:"rg-newNodeTemplate",x:0,y:0,text:""},we=(l,i,e)=>{if(l.id===void 0)throw console.log("node must has id:",l),new Error("node must has option[id]:");l.isShow!==void 0&&(l.hidden=!l.isShow,console.warn("[relation-graph Warning] line option[isShow] is deprecated, please use [hidden] instead.")),l.isHide!==void 0&&(l.hidden=l.isHide,console.warn("[relation-graph Warning] line option[isHide] is deprecated, please use [hidden] instead."));const t=l.width||l.width===0?l.width:i==null?void 0:i.defaultNodeWidth,n=l.height||l.height===0?l.height:i==null?void 0:i.defaultNodeHeight,o={id:l.id,text:l.text!==void 0?l.text:"",type:l.type!==void 0?l.type:"",targetType:l.targetType!==void 0?l.targetType:D.Node,expanded:l.expanded!==void 0?l.expanded:!0,selected:l.selected!==void 0?l.selected:!1,className:l.className!==void 0?l.className:"",nodeShape:Ce(l.nodeShape,i==null?void 0:i.defaultNodeShape),borderWidth:l.borderWidth!==void 0?l.borderWidth:void 0,borderRadius:l.borderRadius!==void 0?l.borderRadius:void 0,borderColor:l.borderColor!==void 0?l.borderColor:void 0,fontColor:l.fontColor!==void 0?l.fontColor:void 0,fontSize:l.fontSize!==void 0?l.fontSize:void 0,color:l.color!==void 0?l.color:void 0,opacity:l.opacity!==void 0?l.opacity:void 0,fixed:l.fixed!==void 0?l.fixed:!1,width:t,height:n,force_weight:l.force_weight,x:l.x!==void 0?l.x:0,y:l.y!==void 0?l.y:0,expandHolderPosition:l.expandHolderPosition!==void 0?l.expandHolderPosition:void 0,disablePointEvent:l.disablePointEvent!==void 0?l.disablePointEvent:void 0,disableDrag:l.disableDrag!==void 0?l.disableDrag:!1,hidden:l.hidden!==void 0?l.hidden:!1,rgCalcedVisibility:!0,rgShouldRender:!0,rgChildrenSize:0,zIndex:l.zIndex||0,el_W:l.el_W||t||0,el_H:l.el_H||n||0,data:l.data!==void 0?l.data:{}};if(e&&e.has&&e.has(o.id)){const s=e.get(o.id);o.el_W||s&&(o.el_W=s[0]),o.el_H||s&&(o.el_H=s[1])}return o.lot={childs:[],parent:void 0,eached:!1,strength:0},o.width&&(o.el_W=o.width),o.height&&(o.el_H=o.height),o},On=["Fx","Fy","appended","dragging","el","el_W","el_H","targetFrom","targetNodes","targetTo","lot","seeks_id","shouldRender","rgCalcedVisibility","rgShouldRender","rgChildrenSize","origin_x","origin_y","selected"],Te=l=>{if(!l)return;const i={};return Object.keys(l).forEach(e=>{if(!On.includes(e)){const t=l[e];t!==void 0&&(e==="offset_x"&&t===0||e==="nodeShape"&&t===1||e==="offset_y"&&t===0||e==="zIndex"&&t===0||e==="width"&&!t||e==="height"&&!t||e==="fixed"&&t===!1||e==="className"&&t===""||e==="hidden"&&t===!1||e==="disableDrag"&&t===!1||e==="expanded"&&t===!0||e==="opacity"&&t===1||e==="type"&&t==="node"||e==="targetType"&&t===D.Node||e==="data"&&(!t||Object.keys(t).length===0)||(i[e]=t))}}),i},Pn=Object.freeze(Object.defineProperty({__proto__:null,newNodeTemplate:De,json2Node:we,transNodeToJson:Te,default:{json2Node:we,transNodeToJson:Te}},Symbol.toStringTag,{value:"Module"}));let _e={x:0,y:0};const Ne={x:0,y:0},se={x:0,y:0},at={passive:!1};let Ve,Be;const Ae=l=>ce(l),ee={startDrag(l,i,e,t){t?Ve=(n,o,s)=>{const a=n-se.x,d=o-se.y;t(a,d,Ne,se,s)}:Ve=(n,o)=>{_e.x=Ne.x+(n-se.x),_e.y=Ne.y+(o-se.y)},Be=e,_e=i,Ne.x=_e.x,Ne.y=_e.y;try{const n=Ae(l);se.x=n.clientX,se.y=n.clientY,de(l)?(document.body.addEventListener("touchmove",ee.onNodeMove,at),document.body.addEventListener("touchend",ee.onNodeDragend),document.body.addEventListener("mousemove",ee.onNodeMove),document.body.addEventListener("mouseup",ee.onNodeDragend),l.preventDefault()):(document.body.addEventListener("mousemove",ee.onNodeMove),document.body.addEventListener("mouseup",ee.onNodeDragend))}catch(n){console.error(n.message)}},onNodeMove(l){const i=Ae(l);Ve(i.clientX,i.clientY,l)},onNodeDragend(l){if(de(l)?(document.body.removeEventListener("touchmove",ee.onNodeMove,at),document.body.removeEventListener("touchend",ee.onNodeDragend),document.body.removeEventListener("mousemove",ee.onNodeMove),document.body.removeEventListener("mouseup",ee.onNodeDragend)):(document.body.removeEventListener("mousemove",ee.onNodeMove),document.body.removeEventListener("mouseup",ee.onNodeDragend)),Be){const i=Ae(l),e=i.clientX,t=i.clientY,n=e-se.x,o=t-se.y;Be(n,o,l)}}},le=ee,he=(l,i)=>{if(l.from===void 0)throw console.log("error,line must has option[from](nodeId):",l),new Error("error,line must has option[from]:");if(l.to===void 0)throw console.log("error,line must has option[to](nodeId):",l),new Error("error,line must has option[to]:");if(typeof l.from!="string")throw console.log("error line from, must be string(nodeId):",l),new TypeError("error line from, must be string:");if(typeof l.to!="string")throw console.log("error line to, must be string(nodeId):",l),new TypeError("error line to, must be string:");return l.hidden===void 0&&l.isShow!==void 0&&(l.hidden=!l.isShow,console.warn("[relation-graph Warning] line option[isShow] is deprecated, please use [hidden] instead.")),l.hidden===void 0&&l.isHide!==void 0&&(l.hidden=l.isHide,console.warn("[relation-graph Warning] line option[isHide] is deprecated, please use [hidden] instead.")),{id:l.id,from:l.from,to:l.to,type:l.type!==void 0?l.type:"",isFakeLine:l.isFakeLine!==void 0?l.isFakeLine:!1,fromType:l.fromType!==void 0?l.fromType:l.isFakeLine?D.CanvasPoint:D.Node,toType:l.toType!==void 0?l.toType:l.isFakeLine?D.CanvasPoint:D.Node,selected:!1,text:l.text!==void 0?l.text:"",textOffsetX:l.textOffsetX!==void 0?l.textOffsetX:void 0,textOffsetY:l.textOffsetY!==void 0?l.textOffsetY:void 0,color:l.color!==void 0?l.color:void 0,opacity:l.opacity!==void 0?l.opacity:void 0,fontSize:l.fontSize!==void 0?l.fontSize:void 0,fontColor:l.fontColor!==void 0?l.fontColor:void 0,lineWidth:l.lineWidth!==void 0?l.lineWidth:void 0,lineShape:l.lineShape||i.defaultLineShape||1,className:l.className!==void 0?l.className:void 0,animation:l.animation!==void 0?l.animation:0,dashType:l.dashType!==void 0?l.dashType:0,disablePointEvent:l.disablePointEvent!==void 0?l.disablePointEvent:!1,showStartArrow:l.showStartArrow!==void 0?l.showStartArrow:!1,showEndArrow:l.showEndArrow!==void 0?l.showEndArrow:!0,useTextOnPath:l.useTextOnPath!==void 0?l.useTextOnPath:void 0,placeText:l.placeText!==void 0?l.placeText:void 0,startMarkerId:l.startMarkerId||"",endMarkerId:l.endMarkerId||"",textAnchor:l.textAnchor!==void 0?l.textAnchor:void 0,junctionOffset:l.junctionOffset,fromJunctionPoint:l.fromJunctionPoint,toJunctionPoint:l.toJunctionPoint,fromJunctionPointOffsetX:l.fromJunctionPointOffsetX||0,fromJunctionPointOffsetY:l.fromJunctionPointOffsetY||0,toJunctionPointOffsetX:l.toJunctionPointOffsetX||0,toJunctionPointOffsetY:l.toJunctionPointOffsetY||0,lineRadius:l.lineRadius,force_elastic:l.force_elastic,polyLineStartDistance:l.polyLineStartDistance,ctrlPointsFor49:l.ctrlPointsFor49,ctrlPointsFor44:l.ctrlPointsFor44,ctrlPoints:l.ctrlPoints,lineDirection:l.lineDirection!==void 0?l.lineDirection:void 0,forDisplayOnly:l.forDisplayOnly||l.from===l.to,hidden:l.hidden!==void 0?l.hidden:!1,cssVars:l.cssVars!==void 0?l.cssVars:void 0,data:l.data!==void 0?l.data:{}}},Tn=["arrow","isReverse","selected","shouldRender","rgCalcedVisibility"],be=l=>{if(!l)return;const i={};return Object.keys(l).forEach(e=>{if(!Tn.includes(e)){const t=l[e];t!==void 0&&(e==="isFakeLine"&&t===!1||e==="fromType"&&t===D.Node||e==="toType"&&t===D.Node||e==="animation"&&t===0||e==="text"&&t===""||e==="dashType"&&t===0||e==="disablePointEvent"&&t===!1||e==="showStartArrow"&&t===!1||e==="showEndArrow"&&t===!0||e==="startMarkerId"&&t===""||e==="endMarkerId"&&t===""||e==="forDisplayOnly"&&t===!1||e==="fromJunctionPointOffsetX"&&t===0||e==="fromJunctionPointOffsetY"&&t===0||e==="toJunctionPointOffsetX"&&t===0||e==="toJunctionPointOffsetY"&&t===0||e==="opacity"&&t===1||e==="hidden"&&t===!1||e==="data"&&(!t||Object.keys(t).length===0)||(i[e]=l[e]))}}),i},ze=l=>{if(!!l)return be(l.line)},Sn=Object.freeze(Object.defineProperty({__proto__:null,json2Line:he,transLineToJson:be,transLinkToJson:ze,default:{json2Line:he,transLinkToJson:ze}},Symbol.toStringTag,{value:"Module"}));function Rn(l,i,e,t,n,o,s,a,d){const h=n-l,c=o-i,f=Math.sqrt(h*h+c*c);if(f===0)return{x:l,y:i};const p=d*c/f,m=-(d*h)/f,u=l+p,g=i+m,y=l-e/2,v=l+e/2,x=i-t/2,w=i+t/2;let k=[];if(h!==0){let b=(y-u)/h,N=g+b*c;N>=x&&N<=w&&k.push({x:y,y:N});let P=(v-u)/h,R=g+P*c;R>=x&&R<=w&&k.push({x:v,y:R})}if(c!==0){let b=(x-g)/c,N=u+b*h;N>=y&&N<=v&&k.push({x:N,y:x});let P=(w-g)/c,R=u+P*h;R>=y&&R<=v&&k.push({x:R,y:w})}if(k.length===0&&h===0&&c===0)return{x:u,y:g};let T=null,O=1/0;return k.forEach(b=>{const N=Math.sqrt((b.x-n)**2+(b.y-o)**2);N<O&&(O=N,T=b)}),T}const Mn={getRectPoint(l,i,e,t,n,o,s,a,d=!1,h=1,c=0,f=14,p=!1){const m=l+n/2,u=i+o/2,g=e+s/2,y=t+a/2;if(h>1){const P=Math.min(f,n,o),R=-P/2,S=P/(h-1),M=d&&p||!d&&!p?R*-1-c*S:R+c*S,C=Rn(m,u,n,o,g,y,s,a,M);if(C)return C}const v=m<g?1:-1,x=u<y?1:-1;if(y===u)return{x:m+v*n/2,y:u};const w=Math.abs((g-m)/(y-u)),k=n/o;let T=0,O=0;w<k?(T=v*o/2*w,O=x*o/2):(T=v*n/2,O=x*n/2/w);const b=m+T,N=u+O;return{x:b,y:N}},getRectPointBasic(l,i,e,t,n,o,s,a){const d=l+n/2,h=i+o/2,c=e+s/2,f=t+a/2;let p=f===h?0:(c-d)/(f-h);p===0&&f===h&&c===d?p=1:p===0&&(p=(c-d)/(f-h+(f>h?-1:1)*1e-4));const m=n/o;let u=0,g=0,y="1";return Math.abs(p)<m?(y="2",h<=f?(g=o/2,u=g*p):(g=-o/2,u=g*p)):(y="3",d<=c?(u=n/2,g=p===0&&c===d?0:u/p):(u=-n/2,g=p===0&&c===d?0:u/p)),{x:d+u,y:h+g,_case:y}},getRectJoinPoint(l){const{from_x:i,from_y:e,to_x:t,to_y:n,f_W:o,f_H:s,t_W:a,t_H:d}=l,h=i+o/2,c=e+s/2,f=t+a/2,p=n+d/2,m=f-h,u=p-c,g=m/(o/2),y=u/(s/2);return Math.abs(g)>Math.abs(y)?g>0?{x:i+o,y:c}:{x:i,y:c}:y>0?{x:h,y:e+s}:{x:h,y:e}},getRectHJoinPoint(l){const{from_x:i,from_y:e,to_x:t,f_W:n,f_H:o,t_W:s}=l,a=o/2;return i+n<t?{x:i+n,y:e+a}:{x:i,y:e+a}},getRectLeftJoinPoint(l){const{from_x:i,from_y:e,f_H:t}=l;return{x:i,y:e+t/2}},getRectRightJoinPoint(l){const{from_x:i,from_y:e,f_W:t,f_H:n}=l;return{x:i+t,y:e+n/2}},getRectTopJoinPoint(l){const{from_x:i,from_y:e,f_W:t}=l;return{x:i+t/2,y:e}},getRectBottomJoinPoint(l){const{from_x:i,from_y:e,f_W:t,f_H:n}=l;return{x:i+t/2,y:e+n}},getRectHorizontalLineJoinPoint(l){return this.getRectVJoinPoint(l)},getRectVerticalLineLineJoinPoint(l){return this.getRectHJoinPoint(l)},getRectVJoinPoint(l){const{from_x:i,from_y:e,to_y:t,f_W:n,f_H:o,t_H:s}=l,a=n/2;return e+o<t?{y:e+o,x:i+a}:{y:e,x:i+a}},getBorderPoint(l,i,e,t,n,o,s,a,d){return d===0?this.getCirclePoint(l,i,e,t,n,o,s,a):this.getRectPoint(l,i,e,t,n,o,s,a)},getBorderPoint4MultiLine(l){const{from_x:i,from_y:e,to_x:t,to_y:n,f_W:o,f_H:s,t_W:a,t_H:d,nodeShape:h,isReverse:c=!1,isEndPoint:f,totalLinesBetweenNodes:p=1,currentLineIndex:m=0,lineDistance:u=50}=l;return h===0?this.getCirclePoint4MultiLine(i,e,t,n,o,s,a,d,c,p,m,u,f):this.getRectPoint(i,e,t,n,o,s,a,d,c,p,m,u,f)},getCirclePoint(l,i,e,t,n,o,s,a){const d=e+s/2,h=t+a/2,c=l+n/2,f=i+o/2,p=d-c;if(p===0)return{x:c,y:f-o/2*(h<f?1:-1)};const u=(h-f)/p,g=Math.sqrt(1/(1/(n/2)**2+u**2/(o/2)**2))*(d<c?1:-1),y=u*g;return{x:c-g,y:f-y}},getCirclePoint4MultiLine(l,i,e,t,n,o,s,a,d,h,c,f,p){let m=e+s/2;const u=t+a/2;let g=l+n/2;const y=i+o/2;let v=m-g;v>-1&&v<1&&(m=m-.5,g=g+.5,v=-1);let w=0;if(h>1){const M=Math.min(f,n,o),C=-M/2,E=M/(h-1);w=d&&p||!d&&!p?C*-1-c*E:C+c*E}const k=u-y,T=Math.sqrt(v**2+k**2)*w/v,O=k/v,b=n/2,N=o/2,P=g<m?-1:1,R=(-1*b**2*O*T+b*N*Math.sqrt(Math.abs(N**2+O**2*b**2-T**2))/P)/(N**2+b**2*O**2),S=O*R+T;return{x:g-R,y:y-S}},getCirclePointBasic(l,i,e,t,n,o,s,a,d){const h=l+n/2,c=i+o/2,f=e+s/2,p=t+a/2,m=f-h,u=p-c,g=Math.sqrt(m*m+u*u),y=g-d,v=y*m/g*-1,x=y*u/g*-1;return{x:f+v,y:p+x}},getCirclePointPlus(l,i,e,t,n,o,s,a){const d=l+n/2,h=i+o/2,c=e+s/2,f=t+a/2,p=c-d,m=f-h,u=Math.sqrt(p*p+m*m),g=(u-n/2)*p/u*-1,y=(u-o/2)*m/u*-1;return{x:c+g,y:f+y}},getOvalPoint(l,i,e,t,n,o=180){const s=t*(360/n),a=(180-o+s)*Math.PI/180;return{x:l+e*Math.sin(a),y:i+e*Math.cos(a)*-1}},getRotatedPoint(l,i,e,t,n){const o=n*Math.PI/180,s=Math.cos(o),a=Math.sin(o),d=(l-e)*s-(i-t)*a+e,h=(l-e)*a+(i-t)*s+t;return{x:d,y:h}},getFlippedX(l,i){return i-(l-i)},getFlippedY(l,i){return i-(l-i)},getAngleType(l,i){if(l>=0&&i>=0)return 1;if(l<0&&i>=0)return 2;if(l<0&&i<0)return 3;if(l>=0&&i<0)return 4},getTextAngle(l,i,e,t){let n=Math.atan2(t-i,e-l)*180/Math.PI;return n<0&&(n+=360),n>90&&n<=270&&(n+=180),n>=360&&(n-=360),Math.round(n)}},me=(l,i,e,t)=>{const n=l-e,o=i-t;return Math.sqrt(n**2+o**2)};function rt(l,i,e,t,n=0,o=0){let s=1,a=n,d=o,h=0;for(let c of e){const f=c.width,p=c.height;p>h&&(h=p),t(c,a,d),a+=f+i,s>l?(d+=h+i,s=1,a=0,h=0):s++}}const j=Mn;class En{constructor(i){_(this,"graphInstance");_(this,"initialized",!1);_(this,"isFolderLayout",!1);this.graphInstance=i}analyzeNetwork(i,e,t=!1,n=!1){this.initialized||(this.initialized=!0),i.forEach(u=>{u.lot||(u.lot={}),u.lot.eached=!1,u.lot.index_of_level=0,u.lot.index_of_p_childs=0,u.lot.index_of_parent=0,u.lot.strength=0,u.lot.strengthWithChilds_from=0,u.lot.strengthWithChilds=0,u.lot.childrenSizeVisible=0,u.lot.childrenSize=0,u.lot.childs=[],u.lot.subling=void 0,u.lot.parent=void 0}),e.lot.parent=void 0;const o=this.markNodeParent(e);L("groupNodes:marked-tree-node:",o.networkNodes.length);const s=[],a={direct:1,min_deep:0,max_deep:0,max_length:1,max_strength:1,levels:new Map},d={direct:-1,min_deep:0,max_deep:0,max_length:1,max_strength:1,levels:new Map},h=[e];this.expandLevelNodesWithDirection(s,h,0,t,n,a,d),this.calcStrengthWithChildsValue(s),this.calcStrengthFromValue(e,1),t&&this.calcStrengthFromValue(e,-1);const c=s.filter(u=>u.lot.level===1),f=c.length===0?1:c.map(u=>u.lot.strengthWithChilds).reduce((u,g)=>u+g,0);a.max_strength=f;const p=s.filter(u=>u.lot.level>=0);L("groupNodes:tree-nodes:",p.length,a);const m={tree:{networkNodes:p,analyticResult:a},reverseTree:{networkNodes:[],analyticResult:d}};if(t){const u=s.filter(v=>v.lot.level===-1),g=u.length===0?1:u.map(v=>v.lot.strengthWithChilds).reduce((v,x)=>v+x,0);d.max_strength=g;const y=s.filter(v=>v.lot.level<=0);L("groupNodes:reverse-tree-nodes:",y.length,d),m.reverseTree.networkNodes=y}for(const u of i)this.graphInstance.updateNode(u,{rgChildrenSize:u.lot.childrenSize});return m}markNodeParent(i){let e=[];return this._markNodeParent(e,[i],0),{networkNodes:e}}_markNodeParent(i,e,t){t===0&&e.forEach(o=>{o.lot.parent=void 0});const n=[];for(const o of e){i.includes(o)||i.push(o);for(const s of this.graphInstance.getNodeRelatedNodes(o))i.includes(s)||(i.push(s),s.lot.parent=o,n.push(s))}n.length>0&&this._markNodeParent(i,n,t+1)}expandLevelNodesWithDirection(i,e,t,n,o,s,a){const d=n&&t<0?a:s;L(`bothWay:${n}(deep:${o}) level ${t} size: ${e.length}`,d.direct),e.length>d.max_length&&(d.max_length=e.length),t>d.max_deep&&(d.max_deep=t),t<d.min_deep&&(d.min_deep=t),d.levels.has(t)||d.levels.set(t,{level:t,all_size:e.length,all_strength:0});const h=d.levels.get(t);e.forEach(u=>{u.lot.eached=!0,u.lot.subling=h,u.lot.level=t,i.push(u)});const c=[],f=[];let p=1,m=0;e.forEach(u=>{let g=[],y=[];n?o||t===0?(g=this.graphInstance.getNodeIncomingNodes(u),y=this.graphInstance.getNodeOutgoingNodes(u)):(t<0&&(p=-1),y=this.graphInstance.getNodeRelatedNodes(u)):y=this.graphInstance.getNodeRelatedNodes(u),this._appendNodeChildrenToNextLevelNodes(u,y,f,h,n,1),this._appendNodeChildrenToNextLevelNodes(u,g,c,h,n,-1),u.lot.index_of_level=m,m++}),h.all_strength>d.max_strength&&(d.max_strength=h.all_strength),f.length>0&&this.expandLevelNodesWithDirection(i,f,t+p,n,o,s,a),c.length>0&&this.expandLevelNodesWithDirection(i,c,t-1,n,o,s,a)}_appendNodeChildrenToNextLevelNodes(i,e,t,n,o,s){let a=0,d=0,h=0;if(e.forEach(c=>{c.lot||(c.lot={eached:!1,childs:[]}),c.lot.eached||(d++,c.lot.parent=i,z.isVisibleNode(c)&&(c.lot.eached=!0,c.lot.index_of_parent=h++,t.push(c),a++),i.lot.childs.push(c))}),s===1){const c=a>0?a:1;i.lot.strength=c,n.all_strength+=c,i.lot.strength_of_level=n.all_strength,i.lot.childrenSizeVisible=a,i.lot.childrenSize=d}}calcStrengthWithChildsValue(i){this.isFolderLayout?i.forEach(e=>{e.lot.strengthWithChilds=1,this.conductStrengthToParents(e)}):(i.forEach(e=>{e.lot.childrenSizeVisible>0&&(e.lot.strengthWithChilds=0)}),i.forEach(e=>{e.lot.childrenSizeVisible===0&&(e.lot.strengthWithChilds=1,this.conductStrengthToParents(e))}))}calcStrengthFromValue(i,e=1){this._calcStrengthFromValue([i],0,e===-1?-1:1)}_calcStrengthFromValue(i,e,t=1){const n=[];let o=0;i.forEach(s=>{if(s.lot.level===0||t===(s.lot.level<0?-1:1)){s.lot.childs.forEach(d=>{n.push(d)}),s.lot.parent&&o<s.lot.parent.lot.strengthWithChilds_from&&(o=s.lot.parent.lot.strengthWithChilds_from);const a=this.isFolderLayout?1:0;s.lot.strengthWithChilds_from=o+a,o+=s.lot.strengthWithChilds}}),n.length>0&&this._calcStrengthFromValue(n,e+(t<0?-1:1),t)}conductStrengthToParents(i){if(i.lot.parent){const e=Math.abs(i.lot.level)-1===Math.abs(i.lot.parent.lot.level);(this.isFolderLayout||e)&&(i.lot.parent.lot.strengthWithChilds+=1,this.conductStrengthToParents(i.lot.parent))}}}class In{constructor(i,e,t){_(this,"graphOptions");_(this,"layoutOptions");_(this,"graphInstance");_(this,"networkAnalyzer");_(this,"allNodes",[]);_(this,"isMainLayouer",!0);_(this,"requireLinks",!1);_(this,"allLinks",[]);_(this,"rootNode");this.layoutOptions=i,this.graphOptions=e,this.graphInstance=t,this.networkAnalyzer=new En(t)}setLinks(i){L("setLinks:",i.length),this.allLinks=i}generateCalcNodes(i){const e=[],t=new Map;for(const n of i){const o={rgNode:n,x:n.x,y:n.y,width:n.width||n.el_W||50,height:n.height||n.el_H||50};e.push(o),t.set(n.id,o)}return{calcNodes:e,calcNodeMap:t}}generateLevels(i){const e=[],t=new Map;for(const n of i){if(!n.lot||typeof n.lot.level!="number")continue;const o=n.lot.level;e.includes(o)||(e.push(o),t.set(o,[])),t.get(o).push(n)}return e.sort((n,o)=>n-o),{levels:e,levelNodesMap:t}}adjustNodePositions(i,e,t){if(!i||i.length===0)return[];for(let n=1;n<i.length;n++){const o=i[n],s=i[n-1];switch(e){case"right":o.x<s.x+s.width+t&&(o.x=s.x+s.width+t);break;case"left":o.x+o.width>s.x-t&&(o.x=s.x-o.width-t);break;case"bottom":o.y<s.y+s.height+t&&(o.y=s.y+s.height+t);break;case"top":o.y+o.height>s.y-t&&(o.y=s.y-o.height-t);break}}return i}getReverseAlignItems(i){return Dn[i]}updateNodePosition(i,e,t){this.graphInstance.updateNode(typeof i=="string"?i:i.id,{x:e,y:t})}layoutEnd(){this.graphInstance&&(this.graphInstance.dataProvider.updateShouldRenderGraphData(),this.graphInstance._dataUpdated())}}const Dn={start:"end",end:"start",center:"center"},fe=In;class Vn extends fe{constructor(e,t,n){super(e,t,n);_(this,"layoutOptions");_(this,"fastStart",!1);_(this,"skipInitLayout",!1);_(this,"maxLayoutTimes",300);_(this,"byNode",!0);_(this,"byLine",!0);_(this,"lockX",!1);_(this,"lockY",!1);_(this,"force_node_repulsion",1);_(this,"force_line_elastic",1);_(this,"disableLiveChanges",!1);_(this,"force_x_coefficient",1);_(this,"force_y_coefficient",1);_(this,"instanceId","");_(this,"calcNodes",[]);_(this,"_graphEventHandler");_(this,"layoutTimes",0);_(this,"prev10",[]);_(this,"visibleNodes",[]);_(this,"_onFinishCallback");_(this,"_onTickCallback");_(this,"calcNodeMap",new WeakMap);_(this,"forCalcNodes",[]);_(this,"recentGraphVelocity",[]);_(this,"graphVelocityBalancedValue",.1);_(this,"prevLogTime",0);_(this,"animationFrameTimer",0);_(this,"prevNodeLevel1Index",0);_(this,"prevNodeLevel2Index",0);_(this,"stoped",!1);_(this,"maxTractionLength",400);_(this,"zeroForceLength",40);_(this,"maxRepulsionDistance",600);_(this,"nodeCollisionRadius",40);_(this,"maxMoveSpeed",100);_(this,"n2nMaxForce",50);this.layoutOptions=e,this.updateOptions(e),this.requireLinks=!0,this.instanceId=n?n.generateNewUUID(5):"error-id"}updateOptions(e){e.fastStart!==void 0&&(this.fastStart=e.fastStart),e.maxLayoutTimes!==void 0&&(this.maxLayoutTimes=e.maxLayoutTimes),e.byNode!==void 0&&(this.byNode=e.byNode),e.byLine!==void 0&&(this.byLine=e.byLine),e.force_node_repulsion!==void 0&&(this.force_node_repulsion=e.force_node_repulsion),e.force_line_elastic!==void 0&&(this.force_line_elastic=e.force_line_elastic),e.force_x_coefficient!==void 0&&(this.force_x_coefficient=e.force_x_coefficient),e.force_y_coefficient!==void 0&&(this.force_y_coefficient=e.force_y_coefficient),e.disableLiveChanges!==void 0&&(this.disableLiveChanges=e.disableLiveChanges),e.skipInitLayout!==void 0&&(this.skipInitLayout=e.skipInitLayout),e.maxTractionLength!==void 0&&(this.maxTractionLength=e.maxTractionLength),e.zeroForceLength!==void 0&&(this.zeroForceLength=e.zeroForceLength),e.maxRepulsionDistance!==void 0&&(this.maxRepulsionDistance=e.maxRepulsionDistance),e.nodeCollisionRadius!==void 0&&(this.nodeCollisionRadius=e.nodeCollisionRadius)}placeNodes(e,t){if(L("RGForceLayout["+this.instanceId+"].placeNodes"),this.calcNodes=e,this.allNodes.length===0&&(this.allNodes=e),this.rootNode=t,this.fastStart)L("RGForceLayout["+this.instanceId+"] fastStart"),this.calcNodes.forEach(n=>{if(n.fixed===!0)return;let o=n.x,s=n.y,a=!1;(Number.isNaN(o)||o===void 0)&&(o=Math.floor(Math.random()*200)-100,a=!0),(Number.isNaN(s)||s===void 0)&&(s=Math.floor(Math.random()*200)-100,a=!0),o===0&&s===0&&(o=Math.floor(Math.random()*200)-100,s=Math.floor(Math.random()*200)-100,a=!0),a&&this.updateNodePosition(n,o,s)});else if(!this.skipInitLayout){if(L("!!!initNodesPosition....."),t){L("layout by root:",t),(Number.isNaN(t.x)||t.x===void 0)&&this.updateNodePosition(t,0,0);const{tree:n}=this.networkAnalyzer.analyzeNetwork(e,t),{networkNodes:o,analyticResult:s}=n;t.fixed||this.layoutOptions.fixedRootNode||this.updateNodePosition(t,0,0);const a=z.getNodeLotXY({alignItemsX:"center",alignItemsY:"center"},t);t.lot.x=a.x,t.lot.y=a.y,this.placeRelativePosition(t,o,s,1,[]),L("!!!initNodesPosition fixedRootNode:2:",t.x,t.y),o.forEach(d=>{if(d.fixed===!0||!d.rgCalcedVisibility||d===t)return;const h=d.lot.x-z.getNodeWidth(d)/2,c=d.lot.y-z.getNodeHeight(d)/2;this.updateNodePosition(d,h,c)})}}this.allNodes.forEach(n=>{let o=n.x,s=n.y,a=!1;(Number.isNaN(o)||o===void 0)&&(o=0,a=!0),(Number.isNaN(s)||s===void 0)&&(s=0,a=!0),a&&this.updateNodePosition(n,o,s)}),L("["+this.instanceId+"]Start Auto Layout....."),this.start()}getLevelR(e,t){if(e.length===0)return;let n=0;for(let o=0;o<t;o++)n+=e[o]||e[e.length-1];return n}placeRelativePosition(e,t,n,o,s){L("analyticResult:",this.layoutOptions,n,o,s);const a={x:e.lot.x,y:e.lot.y},d=t.filter(h=>h.lot.level===1);this.placeNodesInFanRegion(d,0,360,a,1,n.max_strength,s,1,o,0)}calculateMinimumRadius(e,t=0){if(e.length===0||e.length===1)return 0;const n=e.map(c=>{const f=c.width||c.el_W,p=c.height||c.el_H;return Math.sqrt(f*f+p*p)/2+t/2}),o=[];for(let c=0;c<n.length;c++){const f=(c+1)%n.length;o.push(n[c]+n[f])}let s=Math.max(...o)/2,a=o.reduce((c,f)=>c+f,0);const d=100;let h=a;for(let c=0;c<d;c++){const f=(s+a)/2;let p=0;for(const m of o){const u=m/(2*f);if(u>1){p=10;break}p+=2*Math.asin(u)}p>2*Math.PI?s=f:(a=f,h=f)}return h}placeNodesInFanRegion(e,t,n,o,s,a,d,h,c,f){var y,v;let p=t;const m=n-t,u=200;let g=this.getLevelR(d,s)||f+u*c;s===1&&c===1&&(!this.layoutOptions.levelGaps||this.layoutOptions.levelGaps.length===0)&&(g=this.calculateMinimumRadius(e,10),g=Math.min(Math.max(g,200),500));for(const x of e){const w=((y=x.lot)==null?void 0:y.strengthWithChilds)/a,k=o.x+g,T=o.y,O=w*m,b=p+O/2,N=j.getRotatedPoint(k,T,o.x,o.y,b);x.lot.x=N.x,x.lot.y=N.y,x.lot.childs&&x.lot.childs.length>0&&this.placeNodesInFanRegion(x.lot.childs,p,p+O,o,s+1,(v=x.lot)==null?void 0:v.strengthWithChilds,d,h+1,c,g),p+=O}}graphEventHandle(e,...t){if(e===I.onNodeDragStart){const n=t[0],o=this.calcNodeMap.get(n);o&&(o.dragging=!0)}else if(e===I.onNodeDragging){const n=t[0],o=t[1],s=t[2],a=this.calcNodeMap.get(n);a&&(a.x=o,a.y=s)}else if(e===I.onNodeDragEnd){const n=t[0],o=this.calcNodeMap.get(n);o&&(o.dragging=!1)}}connectToGraphInstance(){this._graphEventHandler=this.graphEventHandle.bind(this),this.graphInstance&&this.graphInstance.addEventHandler(this._graphEventHandler)}disConnectToGraphInstance(){this.graphInstance&&this.graphInstance.removeEventHandler(this._graphEventHandler)}updateVisibleNodes(e){this.visibleNodes=[],e&&(this.allNodes=e),this.allNodes.forEach(t=>{t.lot||(L("node miss lot:",t.text),t.lot={x:t.x,y:t.y,childs:[]}),this.visibleNodes.push(t)}),this.resetCalcNodes(),L("visibleNodes:",this.visibleNodes.length)}viewUpdate(){this._onTickCallback&&this._onTickCallback(),this.graphInstance&&this.graphInstance.forceLayoutTickCallback()}autoLayout(e=!1){if(this.updateVisibleNodes(),this.isMainLayouer){const t=this.graphInstance.dataProvider.getOptions();this.graphInstance.dataProvider.updateOptions({layout:{...t.layout,autoLayouting:!0}})}this.doForceLayout(0)}onFinish(e){this._onFinishCallback=e}onTick(e){this._onTickCallback=e}applyFBuffToNodes(){for(const e of this.forCalcNodes)this.applyToNodePosition(e)}applyPositionToNodes(){this.visibleNodes.forEach(e=>{if(e.fixed)return;const t=this.calcNodeMap.get(e);t&&(e.x=t.x,e.y=t.y)}),this.viewUpdate()}layoutFinished(){if(cancelAnimationFrame(this.animationFrameTimer),this.isMainLayouer){const e=this.graphInstance.dataProvider.getOptions();this.graphInstance.dataProvider.updateOptions({layout:{...e.layout,autoLayouting:!1}})}L("Force Layout["+this.instanceId+"] finished"),this.applyFBuffToNodes(),this.applyPositionToNodes(),this.disConnectToGraphInstance();try{this._onFinishCallback&&this._onFinishCallback()}catch(e){console.error(e)}}resetCalcNodes(){this.forCalcNodes=[],this.calcNodeMap=new WeakMap,this.visibleNodes.forEach(e=>{const t={rgNode:e,Fx:0,Fy:0,x:e.x,y:e.y,dragging:!1,force_weight:e.force_weight||1,forceCenterOffset_X:(e.width||e.el_W||60)/2,forceCenterOffset_Y:(e.height||e.el_H||60)/2,fixed:e.fixed||!1};this.forCalcNodes.push(t),this.calcNodeMap.set(e,t)}),this.allLinks=this.graphInstance.getLinksBetweenNodes(this.visibleNodes)}start(){this.stoped&&this.layoutTimes===0||(this.stoped=!1,this.layoutTimes=0,this.updateVisibleNodes(),this.connectToGraphInstance(),this.autoLayout(!0))}doForceLayout(e){if(this.graphInstance.viewComponentUnmounted){L("["+this.instanceId+"]stop layout:viewComponentUnmounted"),this.layoutFinished();return}let t="0";e>0?(this.prev10.length>=10&&(this.prev10.splice(0,1),t=(1e3/((this.prev10[this.prev10.length-1]-this.prev10[0])/10)).toFixed(1)),this.prev10.push(e)):this.visibleNodes.length===0&&this.updateVisibleNodes(),this.layoutTimes++,this.calcNodesPosition(),this.applyFBuffToNodes(),this.disableLiveChanges||this.layoutTimes%2===0&&this.applyPositionToNodes(),this.layoutTimes<=this.maxLayoutTimes?(Date.now()-this.prevLogTime>3e3&&(L("Force Layout["+this.instanceId+"] Is Working...layoutTimes:",this.layoutTimes,"of",this.maxLayoutTimes,t,"Hz",this.visibleNodes.length),this.prevLogTime=Date.now()),this.animationFrameTimer=requestAnimationFrame(this.doForceLayout.bind(this))):this.layoutFinished()}syncNodePosition(e,t,n){const o=this.allNodes.find(a=>a.id===e),s=this.calcNodeMap.get(o);s&&(s.x=t,s.y=n)}calcNodesPosition(){if(this.byNode)for(let e=this.prevNodeLevel1Index;e<this.forCalcNodes.length;e++){const t=this.forCalcNodes[e];if(!t.dragging&&!t.fixed){for(let n=this.prevNodeLevel2Index;n<this.forCalcNodes.length;n++)if(e!==n){const o=this.forCalcNodes[n];if(o.dragging)continue;this.addGravityByNode(t,o)}}}if(this.byLine){if(this.allLinks&&this.allLinks.length>0){for(const e of this.allLinks)if(!e.line.forDisplayOnly){let t=e.line.force_elastic===void 0?1:e.line.force_elastic;if(this.visibleNodes.includes(e.fromNode)&&this.visibleNodes.includes(e.toNode)){const n=this.calcNodeMap.get(e.fromNode),o=this.calcNodeMap.get(e.toNode);this.addElasticByLine(n,o,t)}}}else for(const e of this.visibleNodes)if(e.lot&&e.lot.parent){const t=this.calcNodeMap.get(e.lot.parent),n=this.calcNodeMap.get(e);this.addElasticByLine(t,n,1)}}return!0}stop(){if(this.stoped=!0,this.layoutTimes===0)return;const e=this.graphInstance.dataProvider.getOptions();cancelAnimationFrame(this.animationFrameTimer),L("[RGForceLayout]["+this.instanceId+"]stop:",e.layout.autoLayouting,this.layoutTimes),this.layoutTimes=Number.MAX_VALUE,this.layoutFinished()}addElasticByLine(e,t,n=1){const o=e.x,s=e.y,a=t.x,d=t.y;let h=Math.sqrt((s-d)**2+(o-a)**2);if(h<this.zeroForceLength)return;h>this.maxTractionLength&&(h=this.maxTractionLength);const c=(h-this.zeroForceLength)*.02*this.force_line_elastic*n,f=c,p=c,m=(o-a)/h,u=(s-d)/h;this.addFtoNode(e,m*f*-1,u*f*-1),this.addFtoNode(t,m*p,u*p)}addGravityByNode(e,t,n=1){const o=e.x,s=e.y,a=t.x,d=t.y;if(n===1&&(Math.abs(o-a)>this.maxRepulsionDistance||Math.abs(s-d)>this.maxRepulsionDistance))return;const h=Math.sqrt((s-d)**2+(o-a)**2);if(n===1&&h>this.maxRepulsionDistance)return;let c=(this.maxRepulsionDistance-h)*.02*this.force_node_repulsion*n;h<this.nodeCollisionRadius&&(c=c*2);const f=(o-a)/h,p=(s-d)/h;this.addFtoNode(e,f*c,p*c)}addFtoNode(e,t,n){if(e.fixed||e.dragging||Number.isNaN(t)||Number.isNaN(n))return;t>this.n2nMaxForce&&(t=this.n2nMaxForce),n>this.n2nMaxForce&&(n=this.n2nMaxForce),t<-this.n2nMaxForce&&(t=-this.n2nMaxForce),n<-this.n2nMaxForce&&(n=-this.n2nMaxForce);const o=e.force_weight||1;this.lockX||(e.Fx+=t*(1/o)),this.lockY||(e.Fy+=n*(1/o))}applyToNodePosition(e){if(e.fixed)return 0;if(e.dragging){const o=e.rgNode;return this.updateNodePosition(o,e.x,e.y),0}if(this.calcNodes!==this.allNodes&&!this.calcNodes.includes(e.rgNode))return 0;let t=e.Fx,n=e.Fy;if(t>this.maxMoveSpeed&&(t=this.maxMoveSpeed),n>this.maxMoveSpeed&&(n=this.maxMoveSpeed),t<-this.maxMoveSpeed&&(t=-this.maxMoveSpeed),n<-this.maxMoveSpeed&&(n=-this.maxMoveSpeed),e.x=e.x+t*this.force_x_coefficient,e.y=e.y+n*this.force_y_coefficient,!this.disableLiveChanges){const o=e.rgNode;this.updateNodePosition(o,e.x,e.y)}e.Fx=0,e.Fy=0}}const ke=Vn;class Bn extends fe{constructor(e,t,n){super(e,t,n);_(this,"enableGatherNodes",!1);_(this,"layoutOptions");this.layoutOptions=e,L("new RGTreeLayout:",this.layoutOptions),this.layoutOptions.from||(this.layoutOptions.from="left"),this.layoutOptions.levelGaps||(this.layoutOptions.levelGaps=[]);const o=this.layoutOptions.from;o==="top"||o==="bottom"?(this.layoutOptions.treeNodeGapH||(this.layoutOptions.treeNodeGapH=10),this.layoutOptions.treeNodeGapV||(this.layoutOptions.treeNodeGapV=50)):(this.layoutOptions.treeNodeGapH||(this.layoutOptions.treeNodeGapH=50),this.layoutOptions.treeNodeGapV||(this.layoutOptions.treeNodeGapV=10)),o==="top"?(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="center"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="start"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.layoutOptions.alignItemsX),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.getReverseAlignItems(this.layoutOptions.alignItemsY))):o==="bottom"?(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="center"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="end"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.layoutOptions.alignItemsX),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.getReverseAlignItems(this.layoutOptions.alignItemsY))):o==="right"?(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="end"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="center"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.getReverseAlignItems(this.layoutOptions.alignItemsX)),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.layoutOptions.alignItemsY)):(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="start"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="center"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.getReverseAlignItems(this.layoutOptions.alignItemsX)),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.layoutOptions.alignItemsY)),this.layoutOptions.ignoreNodeSize===void 0&&(this.layoutOptions.ignoreNodeSize=!1);const s=this.layoutOptions.layoutExpansionDirection,a=s==="start"||s==="left"||s==="top"?"start":s==="end"||s==="right"||s==="bottom"?"end":"center";this.layoutOptions.layoutExpansionDirection=a,this.layoutOptions.levelDistance&&console.error("Error: levelDistance is not support\uFF0C Please use levelGaps or treeNodeGapH,treeNodeGapV option in layoutOptions"),this.enableGatherNodes=this.layoutOptions.enableGatherNodes,this.layoutOptions.rotate||(this.layoutOptions.rotate=0)}placeNodes(e,t){if(L("RGTreeLayout:placeNodes"),t)L("layout by root:",t);else{console.error("root is null");return}L("allNodes:",e.length);const n={alignItemsX:this.layoutOptions.alignItemsX,alignItemsY:this.layoutOptions.alignItemsY},o={alignItemsX:this.layoutOptions.alignParentItemsX,alignItemsY:this.layoutOptions.alignParentItemsY};this.rootNode=t,this.allNodes=e,t.fixed||this.layoutOptions.fixedRootNode||this.updateNodePosition(t,0,0);const s=z.getNodeLotXY(n,t);t.lot.x=s.x,t.lot.y=s.y;const a=e;if(L("groupNodes:2:",a.length,a.map(c=>c.text).join(",")),this.layoutOptions.simpleTree===!0){const{tree:c}=this.networkAnalyzer.analyzeNetwork(a,this.rootNode,!1);this.placeNodesPosition(this.rootNode,c.networkNodes,c.analyticResult)}else{const{tree:c,reverseTree:f}=this.networkAnalyzer.analyzeNetwork(a,this.rootNode,!0);this.placeNodesPosition(this.rootNode,c.networkNodes,c.analyticResult),this.placeNodesPosition(this.rootNode,f.networkNodes,f.analyticResult)}const d=this.layoutOptions.rotate||0,h={x:t.x,y:t.y};this.allNodes.forEach(c=>{if(c.fixed!==!0&&!!z.isVisibleNode(c)&&(Number.isNaN(c.lot.x)&&(L("bad lot x:",c.text,c.lot.x),c.lot.x=0),Number.isNaN(c.lot.y)&&(L("bad lot y:",c.text,c.lot.y),c.lot.y=0),c!==t)){if(d){const u=j.getRotatedPoint(c.lot.x,c.lot.y,h.x,h.y,d);c.lot.x=u.x,c.lot.y=u.y}const f=c.lot.level<0?o:n,p=z.getNodeXByLotX(f,c),m=z.getNodeYByLotY(f,c);this.updateNodePosition(c,p,m)}}),L("create rootNode coordinates:1",t.x,t.y),this.layoutEnd()}placeNodesPosition(e,t,n){this.placeRelativePosition(e,t,n)}placeRelativePosition(e,t,n){const o=this.layoutOptions.layoutExpansionDirection,{levels:s,levelNodesMap:a}=this.generateLevels(t),d=n.max_strength;if(this.layoutOptions.from==="top"||this.layoutOptions.from==="bottom"){const h=this.layoutOptions.treeNodeGapH||20,c=this.layoutOptions.treeNodeGapV||20,f=new Map;for(const y of s){const v=a.get(y);f.set(y,Math.max(...v.map(x=>x.el_H)))}let p=0,m=0;for(const y of t){const v=y.el_W;p+=v,m++}const g=p/m+h;t.forEach(y=>{y.fixed!==!0&&y!==e&&(this.layoutOptions.from==="bottom"?y.lot.y=e.lot.y-this.getLevelDistance(y.lot.level,f,c+10):y.lot.y=e.lot.y+this.getLevelDistance(y.lot.level,f,c+10))}),t.forEach(y=>{y.fixed!==!0&&y.lot.level!==0&&(o==="start"?y.lot.x=e.lot.x-g*y.lot.strengthWithChilds_from:o==="end"?y.lot.x=e.lot.x+g*y.lot.strengthWithChilds_from:y.lot.x=e.lot.x+g*(d/-2+y.lot.strengthWithChilds_from+y.lot.strengthWithChilds/2))}),this.applyNodesGap(t,"v"),this.gatherNodes(t,"v",g)}else{const h=this.layoutOptions.treeNodeGapH||20,c=this.layoutOptions.treeNodeGapV||20,f=new Map;for(const y of s){const v=a.get(y);f.set(y,Math.max(...v.map(x=>x.el_W||x.width||50)))}let p=0,m=0;for(const y of t){const v=y.el_H;p+=v,m++}if(m===0)return;const g=p/m+c;t.forEach(y=>{y.fixed!==!0&&y!==e&&(this.layoutOptions.from==="right"?y.lot.x=e.lot.x-this.getLevelDistance(y.lot.level,f,h+50):y.lot.x=e.lot.x+this.getLevelDistance(y.lot.level,f,h+50))}),t.forEach(y=>{y.fixed!==!0&&y.lot.level!==0&&(o==="start"?y.lot.y=e.lot.y-g*y.lot.strengthWithChilds_from:o==="end"?y.lot.y=e.lot.y+g*y.lot.strengthWithChilds_from:y.lot.y=e.lot.y+g*(d/-2+y.lot.strengthWithChilds_from+y.lot.strengthWithChilds/2))}),this.applyNodesGap(t,"h"),this.gatherNodes(t,"h",g)}}getLevelDistance(e,t,n){if(e===0)return 0;if(e>0){let o=0;for(let s=0;s<e;s++){const a=t.get(s);o+=a+this.getLevelGap(s,n,a,e)}return o}else{let o=0;for(let s=0;s>e;s--){const a=t.get(s);o+=a+this.getLevelGap(s,n,a,e)}return-o}}getLevelGap(e,t,n,o){let s=t+(o===-1&&e===0?n/2:0);if(this.layoutOptions.levelGaps.length>0){const a=this.layoutOptions.levelGaps[Math.abs(e)];a&&(s=a)}return s}applyNodesGap(e,t){if(this.layoutOptions.ignoreNodeSize)return;const n={alignItemsX:this.layoutOptions.alignItemsX,alignItemsY:this.layoutOptions.alignItemsY},o={alignItemsX:this.layoutOptions.alignParentItemsX,alignItemsY:this.layoutOptions.alignParentItemsY},s=this.layoutOptions.layoutExpansionDirection,{levels:a,levelNodesMap:d}=this.generateLevels(e),h=new Map;for(const p of a){const m=d.get(p);h.set(p,Math.max(...m.map(u=>u.el_W)))}const{calcNodes:c,calcNodeMap:f}=this.generateCalcNodes(e);c.forEach(p=>{const m=p.rgNode.lot.level<0?o:n;p.x=z.getNodeXByLotX(m,p.rgNode),p.y=z.getNodeYByLotY(m,p.rgNode),p.width=p.rgNode.el_W,p.height=p.rgNode.el_H,p.buffY=0});for(const p of a){const m=d.get(p)||[];if(t==="h")if(s==="end"){m.sort((g,y)=>g.lot.y-y.lot.y);const u=m.map(g=>f.get(g.id));this.adjustNodePositions(u,"bottom",this.layoutOptions.treeNodeGapV);for(const g of u){const y=g.rgNode.lot.level<0?o:n;g.rgNode.lot.y=z.getNodeLotXY(y,g).y}}else{m.sort((g,y)=>y.lot.y-g.lot.y);const u=m.map(g=>f.get(g.id));this.adjustNodePositions(u,"top",this.layoutOptions.treeNodeGapV);for(const g of u){const y=g.rgNode.lot.level<0?o:n;g.rgNode.lot.y=z.getNodeLotXY(y,g).y}}else if(s==="end"){m.sort((g,y)=>g.lot.x-y.lot.x);const u=m.map(g=>f.get(g.id));this.adjustNodePositions(u,"right",this.layoutOptions.treeNodeGapH);for(const g of u){const y=g.rgNode.lot.level<0?o:n,v=z.getNodeLotXY(y,g);g.rgNode.lot.x=v.x}}else{m.sort((g,y)=>y.lot.x-g.lot.x);const u=m.map(g=>f.get(g.id));this.adjustNodePositions(u,"left",this.layoutOptions.treeNodeGapH);for(const g of u){const y=g.rgNode.lot.level<0?o:n;g.rgNode.lot.x=z.getNodeLotXY(y,g).x}}}if(t==="h"){const p=new Map,m=new Map;for(const w of a){const T=d.get(w).map(O=>f.get(O.id));p.set(w,Math.max(...T.map(O=>O.width))),m.set(w,Math.min(...T.map(O=>O.x)))}const u=this.layoutOptions.treeNodeGapH;let g=a.filter(w=>w>0).sort((w,k)=>w-k),y=a.filter(w=>w<0).sort((w,k)=>k-w),v=1;this.layoutOptions.from==="right"&&([y,g]=[g,y],v=-1);let x=0;for(const w of g){const k=w-v,T=m.get(k),O=p.get(k),b=m.get(w)+x;p.get(w);const N=T+O+u;if(N>b){const P=N-b;x=P;const R=d.get(w);for(const S of R)S.lot.x+=x;m.set(w,b+P)}else m.set(w,b)}x=0;for(const w of y){const k=w+v,T=m.get(k);p.get(k);const O=m.get(w)+x,b=p.get(w),N=T-u;if(O+b>N){const P=N-(O+b);x=P;const R=d.get(w);for(const S of R)S.lot.x+=x;m.set(w,O+P)}else m.set(w,O)}}else{const p=new Map,m=new Map;for(const w of a){const T=d.get(w).map(O=>f.get(O.id));p.set(w,Math.max(...T.map(O=>O.height))),m.set(w,Math.min(...T.map(O=>O.y)))}const u=this.layoutOptions.treeNodeGapV;let g=a.filter(w=>w>0).sort((w,k)=>w-k),y=a.filter(w=>w<0).sort((w,k)=>k-w),v=1;this.layoutOptions.from==="bottom"&&([y,g]=[g,y],v=-1);let x=0;for(const w of g){const k=w-v,T=m.get(k),O=p.get(k),b=m.get(w)+x;p.get(w);const N=T+O+u;if(N>b){const P=N-b;x=P;const R=d.get(w);for(const S of R)S.lot.y+=x;m.set(w,b+P)}else m.set(w,b)}x=0;for(const w of y){const k=w+v,T=m.get(k);p.get(k);const O=m.get(w)+x,b=p.get(w),N=T-u;if(O+b>N){const P=N-(O+b);x=P;const R=d.get(w);for(const S of R)S.lot.y+=x;m.set(w,O+P)}else m.set(w,O)}}}gatherNodes(e,t,n){if(!this.enableGatherNodes)return;const{calcNodes:o,calcNodeMap:s}=this.generateCalcNodes(e);o.forEach(d=>{d.movedNodeSizeBefore=1,d.movedNodeSizeAfter=1});const{levelNodesMap:a}=this.generateLevels(e);e.forEach(d=>{if(d.fixed!==!0&&d.lot.level!==0){const h=a.get(d.lot.level)||[];if(d.lot.strengthWithChilds===1&&d.lot.childrenSizeVisible<=1){const c=this.getBloomingNearByParent(d,d.lot.parent,h,t);if(c){const f=s.get(d.id);t==="h"?d.lot.y-c.lot.y>0?(d.lot.y=c.lot.y+n*f.movedNodeSizeAfter,f.movedNodeSizeAfter++):(d.lot.y=c.lot.y-n*f.movedNodeSizeBefore,f.movedNodeSizeBefore++):d.lot.x-c.lot.x>0?(d.lot.x=c.lot.x+n*f.movedNodeSizeAfter,f.movedNodeSizeAfter++):(d.lot.x=c.lot.x-n*f.movedNodeSizeBefore,f.movedNodeSizeBefore++)}}}})}getBloomingNearByParent(e,t,n,o){let s=9999,a;for(const d of n)if(d.lot.childrenSizeVisible>1&&d.lot.parent===t){const h=o==="h"?d.lot.y-t.lot.y:d.lot.x-t.lot.x;Math.abs(h)<s&&(s=Math.abs(h),a=d)}if(a&&a!==e)return a}}const lt=Bn;class An extends ke{constructor(e,t,n){super(e,t,n);_(this,"layoutOptions");this.layoutOptions=e,this.layoutOptions.distanceCoefficient||(this.layoutOptions.distanceCoefficient=1),this.layoutOptions.levelGaps||(this.layoutOptions.levelGaps=[]),this.layoutOptions.levelDistance&&console.error("Error: levelDistance is not support\uFF0C Please use levelGaps option in layoutOptions")}placeNodes(e,t){if(L("RGCenterLayout:placeNodes"),!t){L("root is null:",t);return}L("layout by root:",t),this.allNodes=e,this.calcNodes=e,this.rootNode=t;const{tree:n}=this.networkAnalyzer.analyzeNetwork(e,this.rootNode),{networkNodes:o,analyticResult:s}=n;if(this.layoutOptions.genLotInfoOnly){L("only gen lot info, return");return}t.fixed||this.layoutOptions.fixedRootNode||this.updateNodePosition(t,0,0);const a={alignItemsX:this.layoutOptions.alignItemsX||"center",alignItemsY:this.layoutOptions.alignItemsY||"center"},d=z.getNodeLotXY(a,t);t.lot.x=d.x,t.lot.y=d.y;const h=this.layoutOptions.rotate||0;L("root position:",t.lot.x,t.lot.y);const c=this.layoutOptions.distanceCoefficient||1,f=this.getLevelDistanceArr();this.placeRelativePosition(this.rootNode,o,s,c,f);const p={x:t.x,y:t.y};o.forEach(m=>{if(m.fixed!==!0&&!!m.rgCalcedVisibility&&m!==t){if(h){const v=j.getRotatedPoint(m.lot.x,m.lot.y,p.x,p.y,h);m.lot.x=v.x,m.lot.y=v.y}const u=a,g=z.getNodeXByLotX(u,m),y=z.getNodeYByLotY(u,m);this.updateNodePosition(m,g,y)}}),this.layoutEnd()}getLevelDistanceArr(){let e=[];if(this.layoutOptions.levelGaps){if(Array.isArray(this.layoutOptions.levelGaps))e=this.layoutOptions.levelGaps;else return console.error("Error levelDistance, levelDistance must is Array"),new Array(10).fill(200);if(e.length>0&&e.length<10)for(let t=e.length;t<10;t++)e.push(e[e.length-1])}return e}}const dt=An;class zn extends ke{constructor(i,e,t){super(i,e,t)}placeNodes(i,e){if(e)L("layout by root:",e);else{L("root is null:",e);return}this.allNodes=i,this.rootNode=e,e.fixed||this.layoutOptions.fixedRootNode||this.updateNodePosition(e,0,0);const t={alignItemsX:this.layoutOptions.alignItemsX||"center",alignItemsY:this.layoutOptions.alignItemsY||"center"},n=this.layoutOptions.rotate||0,o=z.getNodeLotXY(t,e);e.lot.x=o.x,e.lot.y=o.y;const s=this.allNodes.filter(h=>h.rgCalcedVisibility),a=s.length;let d=a*90/Math.PI/2;d<200&&(d=200),d>800&&(d=800),s.forEach((h,c)=>{const f=j.getOvalPoint(o.x,o.y,d,c,a);h.lot.x=f.x,h.lot.y=f.y}),s.forEach(h=>{if(h.fixed===!0||!h.rgCalcedVisibility)return;if(n){const m=j.getRotatedPoint(h.lot.x,h.lot.y,e.lot.x,e.lot.y,n);h.lot.x=m.x,h.lot.y=m.y}const c=t,f=z.getNodeXByLotX(c,h),p=z.getNodeYByLotY(c,h);this.updateNodePosition(h,f,p)}),this.layoutEnd()}}const ct=zn;class Xn extends fe{constructor(e,t,n){super(e,t,n);_(this,"graphOptions");_(this,"layoutOptions");_(this,"allNodes",[]);this.layoutOptions=e,this.graphOptions=t}placeNodes(e,t){if(t)L("layout by root:",t);else{L("root is null:",t);return}L("allNodes:",e.length),this.networkAnalyzer.analyzeNetwork(e,t,!1,!1),L("[Fixed layout canvasOffset]",this.graphOptions.viewSize,this.graphOptions.canvasSize),this.layoutEnd()}}const ht=Xn;class Gn extends fe{constructor(e,t,n){super(e,t,n);_(this,"graphInstance");_(this,"layoutOptions");_(this,"levelGaps",[]);this.layoutOptions=e,L("new RGSmartTreeLayout:",this.layoutOptions),this.layoutOptions.from||(this.layoutOptions.from="left"),this.layoutOptions.levelGaps&&(Array.isArray(this.layoutOptions.levelGaps)?this.levelGaps=this.layoutOptions.levelGaps:console.error("Error levelDistance, levelDistance must is Array"));const o=this.layoutOptions.from;o==="top"||o==="bottom"?(this.layoutOptions.treeNodeGapH||(this.layoutOptions.treeNodeGapH=10),this.layoutOptions.treeNodeGapV||(this.layoutOptions.treeNodeGapV=30),this.layoutOptions.treeNodeGapV<30&&(this.layoutOptions.treeNodeGapV=30)):(this.layoutOptions.treeNodeGapH||(this.layoutOptions.treeNodeGapH=30),this.layoutOptions.treeNodeGapV||(this.layoutOptions.treeNodeGapV=10),this.layoutOptions.treeNodeGapH<30&&(this.layoutOptions.treeNodeGapH=30)),o==="top"?(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="center"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="start"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.layoutOptions.alignItemsX),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.getReverseAlignItems(this.layoutOptions.alignItemsY))):o==="bottom"?(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="center"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="end"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.layoutOptions.alignItemsX),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.getReverseAlignItems(this.layoutOptions.alignItemsY))):o==="right"?(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="end"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="center"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.getReverseAlignItems(this.layoutOptions.alignItemsX)),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.layoutOptions.alignItemsY)):(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="end"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="center"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.getReverseAlignItems(this.layoutOptions.alignItemsX)),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.layoutOptions.alignItemsY)),this.requireLinks=!0,this.graphInstance=n}placeNodes(e,t){if(L("RGSmartTreeLayout:placeNodes"),t)L("layout by root:",t);else{console.error("root is null");return}this.rootNode=t,this.allNodes=e,L("allNodes:",e.length);const n={alignItemsX:this.layoutOptions.alignItemsX,alignItemsY:this.layoutOptions.alignItemsY},o={alignItemsX:this.layoutOptions.alignParentItemsX,alignItemsY:this.layoutOptions.alignParentItemsY},{tree:s,reverseTree:a}=this.networkAnalyzer.analyzeNetwork(e,this.rootNode,!0,!0);t.fixed||this.layoutOptions.fixedRootNode||this.updateNodePosition(t,0,0);const d=z.getNodeLotXY(n,t);t.lot.x=d.x,t.lot.y=d.y,this.placeRelativePosition(t,[...s.networkNodes].concat(a.networkNodes),Math.max(s.analyticResult.max_strength,a.analyticResult.max_strength)),L("allNodes:",e.length);const h={left:0,top:90,right:180,bottom:270}[this.layoutOptions.from],c={x:t.x,y:t.y};this.allNodes.forEach(m=>{if(m.fixed===!0||!m.rgCalcedVisibility)return;if(Number.isNaN(m.lot.x)&&(L("bad lot x:",m.text,m.lot.x),m.lot.x=0),Number.isNaN(m.lot.y)&&(L("bad lot y:",m.text,m.lot.y),m.lot.y=0),h){const v=j.getRotatedPoint(m.lot.x,m.lot.y,c.x,c.y,h);m.lot.x=v.x,m.lot.y=v.y}const u=m.lot.level<0?o:n,g=z.getNodeXByLotX(u,m),y=z.getNodeYByLotY(u,m);this.updateNodePosition(m,g,y)}),L("create rootNode coordinates:1",t.x,t.y);const f=new ke({layoutName:"force",maxLayoutTimes:30,force_node_repulsion:.1,force_line_elastic:1,fixedRootNode:!0,disableLiveChanges:!0},this.graphOptions,this.graphInstance);f.isMainLayouer=!1,f.requireLinks=!0,this.layoutOptions.from==="top"||this.layoutOptions.from==="bottom"?f.lockY=!0:f.lockX=!0;const p=t.fixed;t.fixed=!0,f.skipInitLayout=!0,f.resetCalcNodes(),setTimeout(()=>{t.fixed=p},800),f.onFinish(()=>{t.fixed=p,this.graphInstance&&(this.graphInstance.enableNodeXYAnimation(),this.graphInstance._dataUpdated()),this.applyNodesGap(this.allNodes),this.graphInstance&&(this.graphInstance._dataUpdated(),this.allNodes.forEach(m=>{this.graphInstance.updateNode(m,{x:m.x,y:m.y})}),setTimeout(()=>{this.graphInstance.disableNodeXYAnimation(),this.graphInstance._dataUpdated()},300))}),f.placeNodes(this.allNodes,t),this.layoutEnd()}placeRelativePosition(e,t,n){const o=this.layoutOptions.from==="top"||this.layoutOptions.from==="bottom"?"v":"h";let s=this.layoutOptions.treeNodeGapH||300,a=this.layoutOptions.treeNodeGapV||10;o==="v"&&([s,a]=[a,s]);const{levels:d,levelNodesMap:h}=this.generateLevels(t),c=new Map;for(const g of d){const y=h.get(g);c.set(g,Math.max(...y.map(v=>v.el_W)))}let f=0,p=0;for(const g of t){const y=g.el_H;f+=y,p++}if(p===0)return;const u=f/p+a;t.forEach(g=>{g.fixed!==!0&&g!==e&&(g.lot.x=e.lot.x+this.getLevelDistance(g.lot.level,c,s))}),t.forEach(g=>{g.fixed!==!0&&g!==e&&(g.lot.level===0?g.lot.y=e.lot.y+u*g.lot.index_of_level:g.lot.y=e.lot.y+u*(n/-2+g.lot.strengthWithChilds_from+g.lot.strengthWithChilds/2))})}applyNodesGap(e){const t=this.layoutOptions.from==="top"||this.layoutOptions.from==="bottom"?"v":"h",{levels:n,levelNodesMap:o}=this.generateLevels(e),s=new Map;for(const h of n){const c=o.get(h);s.set(h,Math.max(...c.map(f=>f.el_W)))}const{calcNodes:a,calcNodeMap:d}=this.generateCalcNodes(e);a.forEach(h=>{h.x=h.rgNode.x,h.y=h.rgNode.y,h.width=h.rgNode.el_W,h.height=h.rgNode.el_H,h.buffY=0});for(const h of n){const c=o.get(h)||[];if(t==="h"){const f=c.map(u=>d.get(u.id)),p=f.filter(u=>u.y<this.rootNode.y).sort((u,g)=>g.y-u.y),m=f.filter(u=>u.y>=this.rootNode.y).sort((u,g)=>u.y-g.y);this.adjustNodePositions(p,"top",5),this.adjustNodePositions(m,"bottom",5);for(const u of f)u.rgNode.y=u.y}else{const f=c.map(u=>d.get(u.id)),p=f.filter(u=>u.x<this.rootNode.x).sort((u,g)=>g.x-u.x),m=f.filter(u=>u.x>=this.rootNode.x).sort((u,g)=>u.x-g.x);this.adjustNodePositions(p,"left",5),this.adjustNodePositions(m,"right",5);for(const u of f)u.rgNode.x=u.x}}}getLevelDistance(e,t,n){if(e===0)return 0;if(e>0){let o=0;for(let s=1;s<=e;s++){const a=t.get(s);o+=a+this.getLevelGap(s,n,a)}return o}else{let o=0;for(let s=-1;s>=e;s--){const a=t.get(s);o+=a+this.getLevelGap(s,n,a)}return-o}}getLevelGap(e,t,n){var s;let o=t+(e===-1?n/2:0);if(((s=this.layoutOptions.levelGaps)==null?void 0:s.length)>0){const a=this.layoutOptions.levelGaps[Math.abs(e)];a&&(o=a)}return o}}const Fn=Gn;class Hn extends fe{constructor(e,t,n){super(e,t,n);_(this,"enableGatherNodes",!1);_(this,"layoutOptions");this.layoutOptions=e,L("new RGFolderLayout:",this.layoutOptions),this.layoutOptions.from||(this.layoutOptions.from="left"),this.layoutOptions.treeNodeGapH||(this.layoutOptions.treeNodeGapH=10),this.layoutOptions.treeNodeGapV||(this.layoutOptions.treeNodeGapV=10),this.layoutOptions.levelGaps||(this.layoutOptions.levelGaps=[]),this.layoutOptions.bottomJunctionPointOffsetX===void 0&&(this.layoutOptions.bottomJunctionPointOffsetX=-50);const o=this.layoutOptions.from;o==="top"?(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="center"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="start"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.layoutOptions.alignItemsX),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.getReverseAlignItems(this.layoutOptions.alignItemsY))):o==="bottom"?(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="center"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="end"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.layoutOptions.alignItemsX),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.getReverseAlignItems(this.layoutOptions.alignItemsY))):o==="right"?(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="end"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="center"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.getReverseAlignItems(this.layoutOptions.alignItemsX)),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.layoutOptions.alignItemsY)):(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="end"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="center"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.getReverseAlignItems(this.layoutOptions.alignItemsX)),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.layoutOptions.alignItemsY)),this.layoutOptions.levelDistance&&console.error("Error: levelDistance is not support\uFF0C Please use levelGaps, treeNodeGapH, treeNodeGapV option in layoutOptions"),this.enableGatherNodes=this.layoutOptions.enableGatherNodes}placeNodes(e,t){if(L("RGFolderLayout:placeNodes"),t)L("layout by root:",t);else{console.error("root is null");return}this.rootNode=t,this.allNodes=e;const n={alignItemsX:this.layoutOptions.alignItemsX,alignItemsY:this.layoutOptions.alignItemsY},o={alignItemsX:this.layoutOptions.alignParentItemsX,alignItemsY:this.layoutOptions.alignParentItemsY};t.fixed||this.layoutOptions.fixedRootNode||this.updateNodePosition(t,0,0);const s=z.getNodeLotXY(n,t);t.lot.x=s.x,t.lot.y=s.y,L("allNodes:",e.length),this.networkAnalyzer.isFolderLayout=!0;const{tree:a}=this.networkAnalyzer.analyzeNetwork(e,t,!1,!1);this.placeRelativePosition(t,a.networkNodes,a.analyticResult),L("networkNodes:",a.networkNodes.length),this.allNodes.forEach(d=>{if(d.fixed!==!0&&(Number.isNaN(d.lot.x)&&(L("bad lot x:",d.text,d.lot.x),d.lot.x=0),Number.isNaN(d.lot.y)&&(L("bad lot y:",d.text,d.lot.y),d.lot.y=0),d!==t)){const h=d.lot.level<0?o:n,c=z.getNodeXByLotX(h,d),f=z.getNodeYByLotY(h,d);this.updateNodePosition(d,c,f)}}),L("create rootNode coordinates:1",t.x,t.y),this.layoutEnd()}placeRelativePosition(e,t,n){const o=this.layoutOptions.treeNodeGapH||20,s=this.layoutOptions.treeNodeGapV||20,a=new Map;let d=0,h=0;for(const p of t){const m=p.lot.level,u=p.width||p.el_W||50,g=p.height||p.el_H||50;d+=g,h++;const y=a.get(m);y===void 0?a.set(m,u):u>y&&a.set(m,y)}if(h===0)return;const f=d/h+s;t.forEach(p=>{p.fixed!==!0&&p!==e&&(this.layoutOptions.from==="right"?p.lot.x=e.lot.x-this.getLevelDistance(p.lot.level,a,o+50):p.lot.x=e.lot.x+this.getLevelDistance(p.lot.level,a,o+50))}),t.forEach(p=>{p.fixed!==!0&&p!==e&&p.lot.level!==0&&(p.lot.y=e.lot.y+f*p.lot.strengthWithChilds_from)}),this.gatherNodes(t,"h",f)}gatherNodes(e,t,n){if(!this.enableGatherNodes)return;const o={};e.forEach(s=>{if(s.lot.level!==0)return;const a=s.lot.level+"";o[a]||(o[a]=[]),o[a].push(s),s.lot.movedNodeSizeBefore=1,s.lot.movedNodeSizeAfter=1}),e.forEach(s=>{if(s.fixed!==!0&&s.lot.level!==0){const a=s.lot.level+"",d=o[a];if(s.lot.strengthWithChilds===1&&s.lot.childrenSizeVisible<=1){const h=this.getBloomingNearByParent(s,s.lot.parent,d,t);h&&(t==="h"?s.lot.y-h.lot.y>0?(s.lot.y=h.lot.y+n*h.lot.movedNodeSizeAfter,h.lot.movedNodeSizeAfter++):(s.lot.y=h.lot.y-n*h.lot.movedNodeSizeBefore,h.lot.movedNodeSizeBefore++):s.lot.x-h.lot.x>0?(s.lot.x=h.lot.x+n*h.lot.movedNodeSizeAfter,h.lot.movedNodeSizeAfter++):(s.lot.x=h.lot.x-n*h.lot.movedNodeSizeBefore,h.lot.movedNodeSizeBefore++))}}})}getBloomingNearByParent(e,t,n,o){let s=9999,a;for(const d of n)if(d.lot.childrenSizeVisible>1&&d.lot.parent===t){const h=o==="h"?d.lot.y-t.lot.y:d.lot.x-t.lot.x;Math.abs(h)<s&&(s=Math.abs(h),a=d)}if(a&&a!==e)return a}getLevelDistance(e,t,n){if(e===0)return 0;if(e>0){let o=0;for(let s=0;s<e;s++)o+=t.get(s)+this.getLevelGap(s,n);return o}else{let o=e<-1?0:-t.get(e)/2;for(let s=e;s<0;s++)o+=t.get(s)+this.getLevelGap(s,n)+50;return-o}}getLevelGap(e,t){var o;let n=t;if(((o=this.layoutOptions.levelGaps)==null?void 0:o.length)>0){const s=this.layoutOptions.levelGaps[Math.abs(e)];s&&(n=s)}return n}}const ft=Hn,ae=l=>!l||l.length===0?"":l.map(i=>{switch(i.type){case"M":return`${i.type} ${i.x} ${i.y}`;case"l":return`${i.type} ${i.dx} ${i.dy}`;case"L":return`${i.type} ${i.x} ${i.y}`;case"h":return`${i.type} ${i.dx}`;case"v":return`${i.type} ${i.dy}`;case"c":return`${i.type} ${i.dx1} ${i.dy1} ${i.dx2} ${i.dy2} ${i.dx} ${i.dy}`;case"s":return`${i.type} ${i.dx2} ${i.dy2} ${i.dx} ${i.dy}`;case"q":return`${i.type} ${i.dx1} ${i.dy1} ${i.dx} ${i.dy}`;case"Q":return`${i.type} ${i.x1} ${i.y1} ${i.x} ${i.y}`;case"t":return`${i.type} ${i.dx} ${i.dy}`;case"a":return`${i.type} ${i.rx} ${i.ry} ${i.xAxisRotation} ${i.largeArcFlag} ${i.sweepFlag} ${i.dx} ${i.dy}`;case"Z":return i.type;default:return console.warn("\u672A\u77E5\u7684\u8DEF\u5F84\u547D\u4EE4\u7C7B\u578B:",i),""}}).join(" ").trim(),pt=l=>{const i=l.match(/[a-zA-Z][^a-zA-Z]*/g);let e=0,t=0,n=0,o=0,s=0,a=0,d=0,h=0;const c={x:0,y:0},f={x:0,y:0},p=[];for(const m of i){const u=m.trim().split(/[ ,]+/),g=u[0].toUpperCase(),y=u[0]===u[0].toLowerCase();switch(g){case"M":e=U(n,u[1],y),t=U(o,u[2],y),n=e,o=t;break;case"L":e=U(n,u[1],y),t=U(o,u[2],y),p.push({x:e,y:t});break;case"C":s=U(n,u[1],y),a=U(o,u[2],y),d=U(n,u[3],y),h=U(o,u[4],y),e=U(n,u[5],y),t=U(o,u[6],y),n=e,o=t;break;case"Q":s=U(n,u[1],y),a=U(o,u[2],y),e=U(n,u[3],y),t=U(o,u[4],y),n=e,o=t;break;case"V":t=U(o,u[1],y),o=t;break;case"H":e=U(n,u[1],y),n=e;break;case"Z":break;default:console.log(`Unsupported command: ${g}`)}m===i[0]&&(c.x=e,c.y=t),m===i[i.length-1]&&(f.x=e,f.y=t)}return{startPoint:c,ctrl1:{x:s,y:a},ctrl2:{x:d,y:h},endPoint:f,lines:p}},U=(l,i,e)=>e?l+parseFloat(i):parseFloat(i),$n=(l,i,e,t,n,o,s)=>{const a=JSON.parse(JSON.stringify(l));let d=!1;if(e<0||e>=l.length-1)return{newPoints:a,pointsChanged:d};a[e-1];const h=a[e],c=a[e+1];i[e-1];const f=i[e];i[e+1];let p=o,m=s;if(t.direction==="v"){const u=i[e-2],g=i[e+2],y=f.x+p;let v=3e3;if(u){const x=Math.abs(u.x-y);x<10&&x<v&&(v=x,p=u.x-f.x)}if(g){const x=Math.abs(g.x-y);x<10&&x<v&&(v=x,p=g.x-f.x)}}else{const u=i[e-2],g=i[e+2],y=f.y+m;let v=3e3;if(u){const x=Math.abs(u.y-y);x<10&&x<v&&(v=x,m=u.y-f.y)}if(g){const x=Math.abs(g.y-y);x<10&&x<v&&(v=x,m=g.y-f.y)}}if(t.direction==="v")if(e===0){const u=h.y<c.y?1:-1,g={x:h.x,y:h.y},y={x:h.x,y:h.y+20*u};h.x=y.x+p,h.y=y.y,a.splice(e,0,g,y),n.indexOffset+=2,d=!0}else if(e===l.length-2){const u=h.y<c.y?1:-1,g={x:f.x+p,y:c.y-20*u},y={x:c.x,y:c.y-20*u};a.splice(e+1,0,g,y),d=!0}else h.x=f.x+p,c.x=f.x+p;else if(e===0){const u=h.x<c.x?1:-1,g={x:h.x,y:h.y},y={x:h.x+20*u,y:h.y};h.x=y.x,h.y=f.y+m,a.splice(e,0,g,y),n.indexOffset+=2,d=!0}else if(e===l.length-2){const u=h.x<c.x?1:-1,g={x:c.x-20*u,y:f.y+m},y={x:c.x-20*u,y:c.y};a.splice(e+1,0,g,y),d=!0}else h.y=f.y+m,c.y=f.y+m;return{newPoints:a,pointsChanged:d}},Yn=(l,i={x:0,y:0,rotate:0})=>{const{fx:e,fy:t,tx:n,ty:o}=l;i.rotate=j.getTextAngle(e,t,n,o),i.x=e+(n-e)/2,i.y=t+(o-t)/2,Number.isNaN(i.rotate)&&(i.rotate=0);const s=n-e,a=o-t,d=[{type:"M",x:e,y:t},{type:"l",dx:s,dy:a}],h=ae(d);return{pathCommands:d,pathData:h,textPosition:i,points:[]}},Wn=(l,i={x:0,y:0,rotate:0},e={})=>{const{line:t,fx:n,fy:o,fcx:s,fcy:a,f_W:d,f_H:h,tx:c,ty:f,tcx:p,tcy:m,t_W:u,t_H:g}=l,y=c-n,v=f-o,x=n-s,w=o-a,k=c-p,T=f-m,O=t.lineRadius!==void 0?t.lineRadius:e.lineRadius||0;let b=Math.min(O,Math.abs(y))*(n<c?1:-1),N=Math.min(O,Math.abs(v))*(o<f?1:-1);const P=t.fromJunctionPoint||e.defaultJunctionPoint||W.border,R=t.toJunctionPoint||e.defaultJunctionPoint||W.border,S=t.lineDirection||(P===W.tb||P===W.top||P===W.bottom?"v":"h")||(Math.abs(x)>=d/2?"h":"v"),M=t.lineDirection||(R===W.tb||R===W.top||R===W.bottom?"v":"h")||(Math.abs(k)>=u/2?"h":"v"),C=[];let E=0,V=0;if(S==="v"){const A=t.polyLineStartDistance||Math.max(Math.min(30,Math.abs(f-o)/2),15),G=w>0?A:-A;if(t.placeText==="start"?(E=n,V=o+(w>0?20:-5)):t.placeText==="center"||t.placeText==="middle"?(E=n+(c-n)/2,V=o+G):(E=c,V=f-(w>0?20:-5)),C.push({type:"M",x:Math.round(n),y:Math.round(o)},{type:"v",dy:Math.round(G-N)},{type:"c",dx1:0,dy1:Math.round(N),dx2:Math.round(b),dy2:Math.round(N),dx:Math.round(b),dy:Math.round(N)}),M==="v")C.push({type:"h",dx:Math.round(c-n-b*2)},{type:"c",dx1:Math.round(b),dy1:0,dx2:Math.round(b),dy2:Math.round(N),dx:Math.round(b),dy:Math.round(N)},{type:"v",dy:Math.round(f-o-G-N)});else{const $=Math.min(30,Math.abs(c-n)/2),J=k>0?-$:$;C.push({type:"h",dx:Math.round(c-n+J-b)},{type:"c",dx1:Math.round(b),dy1:0,dx2:Math.round(b),dy2:Math.round(N),dx:Math.round(b),dy:Math.round(N)},{type:"v",dy:Math.round(f-o-G-N)},{type:"h",dx:Math.round(J-b)})}}else{const A=t.polyLineStartDistance||Math.max(Math.min(30,Math.abs(c-n)/2),15),G=x>0?A:-A;if(t.placeText==="start"?(E=n+(x>0?10:-50),V=o):t.placeText==="center"||t.placeText==="middle"?(E=n+G,V=o+(f-o)/2):(E=c-(x>0?10:-50),V=f),b=Math.min(O,Math.abs(y))*(n>s?1:-1),N=Math.min(O,Math.abs(v))*(o<f?1:-1),C.push({type:"M",x:Math.round(n),y:Math.round(o)},{type:"h",dx:Math.round(G-b)},{type:"c",dx1:Math.round(b),dy1:0,dx2:Math.round(b),dy2:Math.round(N),dx:Math.round(b),dy:Math.round(N)}),M==="v"){b=Math.min(O,Math.abs(y))*(f<m?1:-1),N=Math.min(O,Math.abs(v))*(f<m?1:-1);const $=Math.min(30,Math.abs(f-o)/2),J=T>0?-$:$;C.push({type:"v",dy:Math.round(f-o+J-N)},{type:"h",dx:Math.round(c-n-G-b)},{type:"c",dx1:0,dy1:Math.round(N),dx2:Math.round(b),dy2:Math.round(N),dx:Math.round(b),dy:Math.round(N)},{type:"v",dy:Math.round(J-N)})}else b=Math.min(O,Math.abs(y))*(n+G<c?1:-1),N=Math.min(O,Math.abs(v))*(f>o?1:-1),C.push({type:"v",dy:Math.round(f-o-N*2)},{type:"c",dx1:0,dy1:Math.round(N),dx2:Math.round(b),dy2:Math.round(N),dx:Math.round(b),dy:Math.round(N)},{type:"h",dx:Math.round(c-n-G-b)})}i.x=E,i.y=V;const X=ae(C);return{pathCommands:C,pathData:X,textPosition:i,points:[]}},Se={left:{x:-1,y:0},right:{x:1,y:0},top:{x:0,y:-1},bottom:{x:0,y:1}},Un=({source:l,sourcePosition:i="bottom",target:e})=>i==="left"||i==="right"?l.x<e.x?{x:1,y:0}:{x:-1,y:0}:l.y<e.y?{x:0,y:1}:{x:0,y:-1},ut=(l,i)=>Math.sqrt(Math.pow(i.x-l.x,2)+Math.pow(i.y-l.y,2));function Xe({source:l,sourcePosition:i="bottom",target:e,targetPosition:t="top",center:n,sourceOffset:o,targetOffset:s}){const a=Se[i],d=Se[t],h={x:l.x+a.x*o,y:l.y+a.y*o},c={x:e.x+d.x*s,y:e.y+d.y*s},f=Un({source:h,sourcePosition:i,target:c}),p=f.x!==0?"x":"y",m=f[p];let u=[],g,y;const v={x:0,y:0},x={x:0,y:0};let w=0;if(a[p]*d[p]===-1){g=n.x,y=n.y;const T=[{x:g,y:h.y},{x:g,y:c.y}],O=[{x:h.x,y},{x:c.x,y}];a[p]===m?(w=1.1,u=p==="x"?T:O):(w=1.2,u=p==="x"?O:T)}else{const T=[{x:h.x,y:c.y}],O=[{x:c.x,y:h.y}];if(p==="x"?u=a.x===m?O:T:u=a.y===m?T:O,i===t){w=2.1;const S=Math.abs(l[p]-e[p]),M=a[p]===m?o:s;if(S<=M){const C=Math.min(M-1,M-S);a[p]===m?v[p]=(h[p]>l[p]?-1:1)*C:x[p]=(c[p]>e[p]?-1:1)*C}}if(i!==t){w=2.2;const S=p==="x"?"y":"x",M=a[p]===d[S],C=h[S]>c[S],E=h[S]<c[S];(a[p]===1&&(!M&&C||M&&E)||a[p]!==1&&(!M&&E||M&&C))&&(u=p==="x"?T:O)}const b={x:h.x+v.x,y:h.y+v.y},N={x:c.x+x.x,y:c.y+x.y},P=Math.max(Math.abs(b.x-u[0].x),Math.abs(N.x-u[0].x)),R=Math.max(Math.abs(b.y-u[0].y),Math.abs(N.y-u[0].y));P>=R?(g=(b.x+N.x)/2,y=u[0].y):(g=u[0].x,y=(b.y+N.y)/2)}return[[l,{x:h.x+v.x,y:h.y+v.y},...u,{x:c.x+x.x,y:c.y+x.y},e],g,y,0,0,w]}const Re=l=>{const i=[];for(let e=0;e<l.length;e++){const t=l[e];if(t.x=Math.round(t.x),t.y=Math.round(t.y),e===0||e===l.length-1)i.push(t);else{const n=i[i.length-1];t.x===n.x&&t.y===n.y||i.push(t)}}for(let e=2;e<i.length;e++){const t=i[e-2],n=i[e-1],o=i[e],s=t.x===n.x?"v":"h",a=n.x===o.x?"v":"h";s===a&&(n.merged=!0)}return i.filter(e=>e.merged!==!0)};function Jn(l,i,e,t){const n=Math.min(ut(l,i)/2,ut(i,e)/2,t),{x:o,y:s}=i;if(l.x===o&&o===e.x||l.y===s&&s===e.y)return[{type:"L",x:o,y:s}];if(l.y===s){const h=l.x<e.x?-1:1,c=l.y<e.y?1:-1;return[{type:"L",x:o+n*h,y:s},{type:"Q",x1:o,y1:s,x:o,y:s+n*c}]}const a=l.x<e.x?1:-1,d=l.y<e.y?-1:1;return[{type:"L",x:o,y:s+n*d},{type:"Q",x1:o,y1:s,x:o+n*a,y:s}]}const gt=(l,i)=>{const e=[];return l.forEach((t,n)=>{if(n===0)e.push({type:"M",x:Math.round(t.x),y:Math.round(t.y)});else if(n===l.length-1){const o=l[n-1];let s=o.x===t.x?0:o.x<t.x?-1:1,a=o.y===t.y?0:o.y<t.y?-1:1;l.length===2&&(s=0,a=0),e.push({type:"l",dx:Math.round(t.x-o.x+i*s),dy:Math.round(t.y-o.y+i*a)})}else{const o=Jn(l[n-1],t,l[n+1],i);e.push(...o)}}),e};var re=(l=>(l.border="border",l.ltrb="ltrb",l.tb="tb",l.lr="lr",l.left="left",l.right="right",l.top="top",l.bottom="bottom",l))(re||{});const Me=(l,i,e,t,n,o,s,a)=>l==="left"?"left":l==="right"?"right":l==="top"?"top":l==="bottom"?"bottom":l==="horizontalLine"?t?o>a?"bottom":"top":o<a?"bottom":"top":l==="verticalLine"?t?n>s?"right":"left":n<s?"right":"left":i===1?"right":i===-1?"left":e===1?"bottom":e===-1?"top":"left",mt=l=>l==="left"?"right":l==="right"?"left":l==="top"?"bottom":l==="bottom"?"top":"left",yt=l=>{if(l.length<2)throw new Error("At least two points are required to form a polyline.");let i=0;const e=[];for(let o=1;o<l.length;o++){const s=l[o].x-l[o-1].x,a=l[o].y-l[o-1].y,d=Math.sqrt(s*s+a*a);e.push(d),i+=d}const t=i/2;let n=0;for(let o=0;o<e.length;o++)if(n+=e[o],n>=t){const s=l[o],a=l[o+1],d=e[o],c=(t-(n-d))/d,f=s.x+(a.x-s.x)*c,p=s.y+(a.y-s.y)*c;return{x:f,y:p}}return{x:0,y:0}},jn=(l,i={x:0,y:0,rotate:0},e={})=>{const{line:t,fromJunctionPoint:n,toJunctionPoint:o,lineDirection:s,lineShape:a,fx:d,fy:h,fcx:c,fcy:f,f_W:p,f_H:m,tx:u,ty:g,tcx:y,tcy:v,t_W:x,t_H:w}=l,k=d-c,T=h-f;let O=k>1?1:k<-1?-1:0,b=T>1?1:T<-1?-1:0;Math.abs(O)===1&&Math.abs(b)===1&&(Math.abs(k)>Math.abs(T)?b=0:O=0),O===0&&b===0&&(O=1);const N=u-y,P=g-v;let R=N>1?1:N<-1?-1:0,S=P>1?1:P<-1?-1:0;Math.abs(R)===1&&Math.abs(S)===1&&(Math.abs(N)>Math.abs(P)?S=0:R=0),R===0&&S===0&&(O=-1);const M=Me(n,O,b,!1,d,h,u,g),C=Me(o,R,S,!0,d,h,u,g),E=M,V=C,X=d+(u-d)/2,A=h+(g-h)/2;let G={x:0,y:0},$=20,J=20;t.ctrlOptionsFor44&&(G={x:t.ctrlOptionsFor44.cx,y:t.ctrlOptionsFor44.cy},$+=t.ctrlOptionsFor44.fd,J+=t.ctrlOptionsFor44.td);const ie=t.lineRadius!==void 0?t.lineRadius:e.lineRadius||0,[te]=Xe({source:{x:d,y:h},sourcePosition:E,target:{x:u,y:g},targetPosition:V,center:{x:X+G.x,y:A+G.y},sourceOffset:$,targetOffset:J}),ne=Re(te),Q=gt(ne,ie),Z=ae(Q),oe=yt(te);if(i.x=oe.x,i.y=oe.y,s==="v"){const q=T>1?1:T<-1?-1:0,F=P>1?1:P<-1?-1:0;t.placeText==="start"?(i.x=d,i.y=h+q*10):t.placeText==="end"&&(i.x=u,i.y=g+F*10)}else{const q=k>1?1:k<-1?-1:0,F=N>1?1:N<-1?-1:0;t.placeText==="start"?(i.x=d+q*10,i.y=h):t.placeText==="end"&&(i.x=u+F*10,i.y=g)}return{pathCommands:Q,pathData:Z,textPosition:i,points:ne,startDirection:E,endDirection:V}},qn=(l,i={x:0,y:0,rotate:0},e={})=>{const{line:t,fromJunctionPoint:n,toJunctionPoint:o,lineDirection:s,lineShape:a,fx:d,fy:h,fcx:c,fcy:f,f_W:p,f_H:m,tx:u,ty:g,tcx:y,tcy:v,t_W:x,t_H:w}=l,k=d-c,T=h-f;let O=k>3?1:k<-3?-1:0,b=T>3?1:T<-3?-1:0;Math.abs(O)===1&&Math.abs(b)===1&&(Math.abs(k)>Math.abs(T)?b=0:O=0),O===0&&b===0&&(O=1);const N=u-y,P=g-v;let R=N>3?1:N<-3?-1:0,S=P>3?1:P<-3?-1:0;Math.abs(R)===1&&Math.abs(S)===1&&(Math.abs(N)>Math.abs(P)?S=0:R=0),R===0&&S===0&&(O=-1);let M=Me(n,O,b,!1,d,h,u,g),C=Me(o,R,S,!0,d,h,u,g);const E=t.lineRadius!==void 0?t.lineRadius:e.lineRadius||0,V=t.ctrlPointsFor49;let X={x:Math.round(d),y:Math.round(h)},A={x:Math.round(u),y:Math.round(g)},G={x:Math.round(V[0].x),y:Math.round(V[0].y)},$={x:Math.round(V[V.length-1].x),y:Math.round(V[V.length-1].y)},J=[...V];if(t.isReverse&&([M,C]=[C,M]),Math.abs(X.x-G.x)>3||Math.abs(X.y-G.y)>3){const Z=X.x+(G.x-X.x)/2,oe=X.y+(G.y-X.y)/2,q=mt(M),[F]=Xe({source:X,sourcePosition:M,target:G,targetPosition:q,center:{x:Z,y:oe},sourceOffset:20,targetOffset:5});J=Re([...F,...J])}if(Math.abs(A.x-$.x)>3||Math.abs(A.y-$.y)>3){const Z=$.x+(A.x-$.x)/2,oe=$.y+(A.y-$.y)/2,q=mt(C),[F]=Xe({source:$,sourcePosition:q,target:A,targetPosition:C,center:{x:Z,y:oe},sourceOffset:5,targetOffset:20});J=Re([...J,...F])}const ie=J,te=gt(ie,E),ne=ae(te),Q=yt(V);return i.x=Q.x,i.y=Q.y,{pathCommands:[],pathData:ne,textPosition:i,points:ie,startDirection:M,endDirection:C}},Zn=(l,i={x:0,y:0,rotate:0})=>{const{line:e,lineShape:t,fx:n,fy:o,fcx:s,fcy:a,tx:d,ty:h,tcx:c,tcy:f}=l,p=d-n,m=h-o;let u=n-s,g=o-a,y=d-c,v=h-f,{fromJunctionPoint:x,toJunctionPoint:w}=e;e.isReverse&&([x,w]=[w,x]),(x===W.left||x===W.right)&&(g=0),(x===W.top||x===W.bottom)&&(u=0),(w===W.left||w===W.right)&&(v=0),(w===W.top||w===W.bottom)&&(y=0);const k=Math.min(200,Math.max(100,Math.abs(p/2))),T=Math.min(200,Math.max(100,Math.abs(m/2))),O=u/(Math.abs(u)+Math.abs(g))*k,b=g/(Math.abs(u)+Math.abs(g))*T;let N={x:O,y:b};const P=y/(Math.abs(y)+Math.abs(v))*k+p,R=v/(Math.abs(y)+Math.abs(v))*T+m;let S={x:P,y:R};e.ctrlPoints&&e.ctrlPoints.length>0&&(e.isReverse?(N.x+=e.ctrlPoints[1].x,N.y+=e.ctrlPoints[1].y,S.x+=e.ctrlPoints[0].x,S.y+=e.ctrlPoints[0].y):(N.x+=e.ctrlPoints[0].x,N.y+=e.ctrlPoints[0].y,S.x+=e.ctrlPoints[1].x,S.y+=e.ctrlPoints[1].y));const M={x:n+N.x,y:o+N.y},C={x:n+S.x,y:o+S.y},E={x:n+p,y:o+m},V=[{type:"M",x:n,y:o},{type:"c",dx1:N.x,dy1:N.y,dx2:S.x,dy2:S.y,dx:p,dy:m}];t===8&&V.push({type:"Z"});const X=vt({x:n,y:o},M,C,E,t<6?.8:.5);i.x=X.x,i.y=X.y;const A=ae(V);return{pathCommands:V,pathData:A,textPosition:i,points:[]}},vt=(l,i,e,t,n=.5)=>{const o={x:(1-n)*l.x+n*i.x,y:(1-n)*l.y+n*i.y},s={x:(1-n)*i.x+n*e.x,y:(1-n)*i.y+n*e.y},a={x:(1-n)*e.x+n*t.x,y:(1-n)*e.y+n*t.y},d={x:(1-n)*o.x+n*s.x,y:(1-n)*o.y+n*s.y},h={x:(1-n)*s.x+n*a.x,y:(1-n)*s.y+n*a.y};return{x:(1-n)*d.x+n*h.x,y:(1-n)*d.y+n*h.y}},Kn=(l,i={x:0,y:0,rotate:0})=>{const{line:e,totalLinesBetweenNodes:t,currentLineIndex:n,lineDirection:o,lineShape:s,fx:a,fy:d,fcx:h,fcy:c,f_W:f,f_H:p,tx:m,ty:u,tcx:g,tcy:y,t_W:v,t_H:x}=l,w=m-a,k=u-d,T=m>a?1:-1,O=u>d?1:-1,b=o==="v"?O:T,N=a-h,P=d-c,R=m-g,S=u-y,M=1/(t+1)*(n+1);let C={x:0,y:0},E={x:0,y:0};if(s===Y.Curve2)C=o==="v"?{x:0,y:b*30}:{x:b*30,y:0},E=o==="v"?{x:w*M,y:b*-10}:{x:b*-10,y:k*M};else if(s===Y.Curve3)C=o==="v"?{x:0,y:k*M}:{x:b*30,y:0},E=o==="v"?{x:0,y:0}:{x:b*-10,y:k*M};else if(s===Y.Curve5)C={x:0,y:0},E=o==="v"?{x:0,y:k*M}:{x:w*M,y:0};else if(s===Y.Curve7||s===Y.Curve8){const ne=N/(Math.abs(N)+Math.abs(P))*30,Q=P/(Math.abs(N)+Math.abs(P))*30;C={x:ne,y:Q};const Z=R/(Math.abs(R)+Math.abs(S))*30+w,oe=S/(Math.abs(R)+Math.abs(S))*30+k;E={x:Z,y:oe}}const V={x:a+C.x,y:d+C.y},X={x:a+E.x,y:d+E.y},A={x:a+w,y:d+k},G=[{type:"M",x:a,y:d},{type:"c",dx1:C.x,dy1:C.y,dx2:E.x,dy2:E.y,dx:w,dy:k}];s===8&&G.push({type:"Z"});const $=vt({x:a,y:d},V,X,A,s<6?.8:.5);i.x=$.x,i.y=$.y;const J=ae(G);return{pathCommands:G,pathData:J,textPosition:i,points:[]}};class Qn{constructor(){_(this,"graphData",{rootNode:void 0,nodes:[],normalLines:[],fakeLines:[]});_(this,"options",{});_(this,"runtimeDATA4NodeMap",new Map);_(this,"runtimeDATA4Links",[]);_(this,"runtimeDATA4LinkMap",new Map);_(this,"runtimeDATA4ConnectTargets",[]);_(this,"runtimeDATA4ElLineTargets",[]);_(this,"runtimeDATA4ShouldRenderItems",{nodes:[],lines:[],fakeLines:[]})}}class eo extends Qn{constructor(){super()}getOptions(){return this.options}getNodeById(i){return this.runtimeDATA4NodeMap.get(i)}getLineById(i){var e;return(e=this.runtimeDATA4LinkMap.get(i))==null?void 0:e.line}getLinkByLineId(i){return this.runtimeDATA4LinkMap.get(i)}getFakeLineById(i){return this.graphData.fakeLines.find(e=>e.id===i)}getNodes(){return this.graphData.nodes}getLinks(){return this.runtimeDATA4Links}getFakeLines(){return this.graphData.fakeLines}getLines(){return this.runtimeDATA4Links.map(i=>i.line)}getRootNode(){return this.graphData.rootNode}getShouldRenderNodes(){return this.isPerformanceMode()?this.runtimeDATA4ShouldRenderItems.nodes:this.graphData.nodes}getShouldRenderLines(){return this.isPerformanceMode()?this.runtimeDATA4ShouldRenderItems.lines:this.graphData.normalLines}getShouldRenderFakeLines(){return this.isPerformanceMode()?this.runtimeDATA4ShouldRenderItems.fakeLines:this.graphData.fakeLines}isPerformanceMode(){return this.options.performanceMode}getCanvasScale(){return this.options.canvasZoom/100}getConnectTargets(){return this.runtimeDATA4ConnectTargets}getConnectTargetById(i){if(!i)throw new Error("[getConnectTargetById]targetId is empty");for(let e=0;e<this.runtimeDATA4ConnectTargets.length;e++){const t=this.runtimeDATA4ConnectTargets[e];if(t.targetId===i)return t}}getElLineTargets(){return this.runtimeDATA4ElLineTargets}getElLineTargetById(i){return this.runtimeDATA4ElLineTargets.find(e=>e.id===i)}calcShouldRenderNodes(){const i=[];return this.graphData.nodes.forEach(e=>{e.rgShouldRender!==!1&&e.rgCalcedVisibility!==!1&&i.push(e)}),i}calcShouldRenderLines(){const i=[];return this.runtimeDATA4Links.forEach(e=>{e.rgShouldRender!==!1&&e.line.hidden!==!0&&e.rgCalcedVisibility!==!1&&i.push(e.line)}),i}calcShouldRenderFakeLines(){return this.graphData.fakeLines}findNodeByXy(i){const e=this.graphData.nodes;for(let t=e.length-1;t>=0;t--){const n=e[t],o=n.x,s=n.y,a=n.el_W||n.width||50,d=n.el_H||n.height||50;if(i.x>o&&i.x<o+a&&i.y>s&&i.y<s+d)return n}return null}}class to{constructor(){_(this,"map");this.map=new Map}_key(i,e){return i<=e?`${i}${e}`:`${e}${i}`}addEdge(i,e){const t=this._key(i,e),n=this.map.get(t)||0;return this.map.set(t,n+1),n}getCount(i,e){const t=this._key(i,e);return this.map.get(t)||0}clear(){this.map.clear()}}const Ge=(l={})=>{const i={definitelyNoDataProviderNeeded:!1,instanceId:"",debug:!0,graphLoading:!1,graphLoadingText:"",showToolBar:!0,backgroundColor:"transparent",checkedItemBackgroundColor:void 0,selectionMode:!1,disableWheelEvent:!1,wheelEventAction:"zoom",dragEventAction:"move",fullscreenElementXPath:"",disableDragNode:!1,disableDragLine:!0,canvasMoveMode:!1,disableNodePointEvent:!1,disableLinePointEvent:!1,enableNodeXYAnimation:!1,enableCanvasTransformAnimation:!1,reLayoutWhenExpandedOrCollapsed:!1,defaultExpandHolderPosition:"hide",toolBarDirection:"h",toolBarPositionH:"left",toolBarPositionV:"bottom",defaultNodeColor:"#ffffff",defaultNodeBorderColor:"#666666",defaultNodeBorderWidth:1,defaultNodeBorderRadius:4,defaultNodeShape:xe.rect,defaultNodeWidth:void 0,defaultNodeHeight:void 0,defaultLineColor:"#cccccc",defaultLineWidth:2,defaultLineShape:Y.StandardStraight,defaultLineTextOffsetX:void 0,defaultLineTextOffsetY:void 0,defaultJunctionPoint:W.border,defaultLineJunctionOffset:3,defaultPolyLineRadius:5,placeOtherGroup:!0,defaultLineTextOnPath:!1,lineTextMaxLength:66,multiLineDistance:30,defaultLineMarker:{viewBox:"0 0 12 12",markerWidth:20,markerHeight:20,refX:3,refY:3,data:"M 0 0, V 6, L 4 3, Z"},viewSize:{width:300,height:300},canvasSize:{width:300,height:300},canvasOffset:{x:25,y:27},fullscreen:!1,checkedNodeId:"",checkedLineId:"",draggingNodeId:"",layout:{layoutName:"center"},canvasZoom:100,mouseWheelSpeed:10,minCanvasZoom:5,maxCanvasZoom:500,showEasyView:!1,performanceMode:!1,viewHeight:"100%",canvasOpacity:1,creatingSelection:!1,selectionView:{x:25,y:27,width:0,height:0},creatingNodePlot:!1,showTemplateNode:!0,newNodeTemplate:we(JSON.parse(JSON.stringify(De)),{}),creatingLinePlot:!1,newLineTemplate:{from:"newRelationTemplate-from",to:"newRelationTemplate-to",color:"",text:""},newLinkTemplate:{fromNode:null,toNodeObject:null,toNode:{nothing:!0,x:400,y:400,el_W:30,el_H:30},totalLinesBetweenNodes:1,currentLineIndex:0,line:{}},data:{},editingLineController:{show:!1,line:null,startPoint:{x:0,y:0},endPoint:{x:0,y:0},text:{show:!0,x:0,y:0,width:10,height:10},ctrlPoints:[],selectedLines:[],line44Splits:[],line49Points:[],ctrlPoint1:{x:0,y:0},ctrlPoint2:{x:0,y:0},toolbar:{x:0,y:0}},editingController:{show:!1,nodes:[],x:0,y:0,width:100,height:100},nodeConnectController:{show:!1,node:void 0,x:0,y:0,width:100,height:100},showReferenceLine:!1,referenceLineAdsorption:!1,editingReferenceLine:{show:!1,directionV:!1,directionH:!1,v_x:0,v_y:0,v_height:0,h_x:0,h_y:0,h_width:0},showMiniView:!1,miniViewVisibleHandle:{x:0,y:0,width:100,height:100,emptyContent:!1},snapshotting:!1};i.newLineTemplate=he(i.newLineTemplate,i);const e=Object.keys(i);return l&&Object.keys(l).forEach(t=>{const n=l[t];if(!e.includes(t)){L("RGOptions: unknow option key:",t);return}if(typeof n=="object"){L("RGOptions:user setting object:",t,n);const o=i[t];if(t==="layout")i[t]=JSON.parse(JSON.stringify(n));else if(o&&!Array.isArray(o)&&n)Object.keys(o).forEach(s=>{o[s]=n[s]});else if(Array.isArray(o)){const s=[];n.forEach(a=>{a&&typeof a=="object"?s.push(JSON.parse(JSON.stringify(a))):s.push(a)}),i[t]=s}else i[t]=n}else i[t]=n}),i},xt=l=>{const i=l.layoutName||"";if(i==="center"){const e=l;e.layoutDirection=void 0}else if(i.includes("tree")){const e=l;e.from===void 0&&(e.from="left"),e.levelGaps===void 0&&(e.levelGaps=[]),(e.from==="top"||e.from==="bottom")&&(e.layoutDirection===void 0&&(e.layoutDirection="v"),L("set layoutDirection=v"),L("set defaultJunctionPoint=tb")),(e.from==="left"||e.from==="right")&&(e.layoutDirection===void 0&&(e.layoutDirection="h"),L("set defaultJunctionPoint=lr"))}else(i==="fixed"||i==="force")&&(l.layoutDirection=void 0)},no=Object.freeze(Object.defineProperty({__proto__:null,createDefaultConfig:Ge,appendDefaultOptions4Layout:xt,default:{createDefaultConfig:Ge}},Symbol.toStringTag,{value:"Module"}));class Oe extends eo{constructor(){super();_(this,"commits");_(this,"updateViewHook",e=>{});this.options=Ge({}),this.commits=this.resetCommints()}clearReactiveData(){this.graphData.nodes=[],this.graphData.normalLines=[],this.graphData.fakeLines=[],this.runtimeDATA4Links.splice(0,this.runtimeDATA4Links.length),this.runtimeDATA4ElLineTargets.splice(0,this.runtimeDATA4ElLineTargets.length),this.runtimeDATA4NodeMap.clear(),this.runtimeDATA4LinkMap.clear(),this.graphData.rootNode=void 0,this.updateShouldRenderGraphData(),this.commits.optionsChanged=!0,this.commits.nodesListChanged=!0,this.commits.linesListChanged=!0,this.commits.fakeLinesListChanged=!0}resetCommints(){return{optionsChanged:!1,changedNodes:[],nodesListChanged:!1,changedLines:[],linesListChanged:!1,changedFakeLines:[],fakeLinesListChanged:!1,changedConnectTargets:[],connectTargetsListChanged:!1}}commitLine(e){this.commits.linesListChanged=!0}commitNode(e){this.commits.changedNodes.includes(e)||this.commits.changedNodes.push(e),this.commits.linesListChanged=!0,this.commits.fakeLinesListChanged=!0}commitFakeLine(e){this.commits.fakeLinesListChanged=!0}commitConnectTarget(e){this.commits.changedConnectTargets.includes(e)||this.commits.changedConnectTargets.push(e),this.commits.fakeLinesListChanged=!0}dataUpdated(){const e=this.commits;this.commits=this.resetCommints(),this.updateViewHook(e)}updateOptions(e){if(e.layout,Object.assign(this.options,e),this.isPerformanceMode()&&!this.options.showEasyView){const t=Object.keys(e);t.includes("canvasZoom")&&(this.commits.nodesListChanged=!0,this.commits.linesListChanged=!0),t.includes("viewSize")&&(this.commits.nodesListChanged=!0,this.commits.linesListChanged=!0),t.includes("canvasOffset")&&(this.commits.nodesListChanged=!0,this.commits.linesListChanged=!0)}this.commits.optionsChanged=!0}clearChecked(){this.updateOptions({checkedNodeId:"",checkedLineId:""})}setCanvasOffset(e,t){this.updateOptions({canvasOffset:{x:e,y:t}}),this.commits.optionsChanged=!0}setCanvasZoom(e){this.updateOptions({canvasZoom:e})}setEditingLine(e){if(e){const t=this.getLineById(e.id)||this.getFakeLineById(e.id);t&&this.updateOptions({editingLineController:{...this.options.editingLineController,line:t,show:!0},checkedLineId:e.id})}else this.updateOptions({editingLineController:{...this.options.editingLineController,line:null,show:!1},checkedLineId:""})}setEditingNodes(e){for(const n of e)if(!n||!this.getNodeById(n.id)){console.error("setEditingNodes Error: node not found:",n);return}this.getNodes().filter(n=>n.selected).forEach(n=>this.updateNode(n.id,{selected:!1})),this.updateOptions({editingController:{...this.options.editingController,nodes:e,show:e.length>0}}),e.length>1&&this.options.editingController.nodes.forEach(n=>this.updateNode(n.id,{selected:!0}))}setCanvasCenter(e,t){const n=this.options.viewSize.width/2,o=this.options.viewSize.height/2,s=this.options.canvasZoom/100;this.setCanvasOffset(n-e*s,o-t*s)}removeNodeById(e){this.beforeNodeBeRemove(e);let t=0;for(let n=0;n<this.graphData.nodes.length;n++)e.includes(this.graphData.nodes[n].id)&&(this.graphData.nodes.splice(n,1),n--,t++);for(const n of e)this.runtimeDATA4NodeMap.delete(n);L("Removed node\uFF1A",e,t),this.commits.nodesListChanged=!0}removeLineByIds(e){L("_removeLineByIds:",e.length,e),this.removeFakeLineByIds(e);let t=0;for(let n=0;n<this.graphData.normalLines.length;n++){const o=this.graphData.normalLines[n];e.includes(o.id)&&(this.graphData.normalLines.splice(n,1),n--,t++)}L("_removeLineByIds:",t),this.removeLinkByLineIds(e),this.updateLinks(),this.commits.linesListChanged=!0}removeFakeLineByIds(e){L("_removeFakeLineByIds:",e.length,e);let t=0;for(let n=0;n<this.graphData.fakeLines.length;n++){const o=this.graphData.fakeLines[n];e.includes(o.id)&&(this.graphData.fakeLines.splice(n,1),n--,t++)}this.commits.fakeLinesListChanged=!0,L("_removeFakeLineByIds:",t)}removeLinkByLineIds(e){L("_removeLinkByLineIds:",e.length,e);let t=0;for(let n=0;n<this.runtimeDATA4Links.length;n++){const o=this.runtimeDATA4Links[n];e.includes(o.lineId)&&(this.runtimeDATA4Links.splice(n,1),this.runtimeDATA4LinkMap.delete(o.lineId),n--,t++)}this.commits.fakeLinesListChanged=!0,L("_removeLinkByLineIds:",t)}removeConnectTarget(e){const t=this.runtimeDATA4ConnectTargets.findIndex(n=>n.targetId===e);if(t!==-1){const n=this.runtimeDATA4ConnectTargets[t];(n.targetType===D.NodePoint||n.targetType===D.CanvasPoint)&&this.runtimeDATA4ConnectTargets.splice(t,1)}this.commits.connectTargetsListChanged=!0}updateLinks(e=[]){const t=new to;for(const n of this.runtimeDATA4Links){const{from:o,to:s}=n.line,a=t.addEdge(o,s);a!==n.currentLineIndex&&(n.currentLineIndex=a,this.commitLine(n.lineId))}for(const n of this.runtimeDATA4Links){const{from:o,to:s}=n.line,a=t.getCount(o,s);a!==n.totalLinesBetweenNodes&&(n.totalLinesBetweenNodes=a,this.commitLine(n.lineId))}t.clear()}beforeNodeBeRemove(e){for(let t=0;t<this.runtimeDATA4Links.length;t++){const n=this.runtimeDATA4Links[t];(e.includes(n.fromNode.id)||e.includes(n.toNode.id))&&(L("Removed Node-line\uFF1A",n.lineId),this.removeLineByIds([n.lineId]),t--)}for(let t=0;t<this.graphData.fakeLines.length;t++){const n=this.graphData.fakeLines[t];let o=!1;if(n.fromType===D.Node&&e.includes(n.from))o=!0;else if(n.fromType===D.CanvasPoint||n.fromType===D.NodePoint){const s=this.getConnectTargetById(n.from);s&&s.nodeId&&e.includes(s.nodeId)&&(o=!0)}else if(n.toType===D.CanvasPoint||n.toType===D.NodePoint){const s=this.getConnectTargetById(n.to);s&&s.nodeId&&e.includes(s.nodeId)&&(o=!0)}o&&(this.graphData.fakeLines.splice(t,1),L("Removed Node-fakeLine\uFF1A",n.id),t--,this.commits.fakeLinesListChanged=!0)}L("Removed Node connect-target\uFF1A");for(let t=0;t<this.runtimeDATA4ConnectTargets.length;t++){const n=this.runtimeDATA4ConnectTargets[t];n.nodeId&&e.includes(n.nodeId)&&(this.runtimeDATA4ConnectTargets.splice(t,1),L("Removed Node-connect-target\uFF1A",n.targetId),this.commitConnectTarget(n.targetId),t--)}}addFakeLines(e){for(const t of e)if(t.id||console.warn("[relation-graph]Must have id for fake line:",t),this.graphData.fakeLines.some(n=>n.id===t.id))console.log("[relation-graph]Ignore duplicate fake line id:",t.id);else{t.isFakeLine=!0;const n=he(t,this.options);n.id||(n.id=Ie(6)),this.graphData.fakeLines.push(n)}this.commits.fakeLinesListChanged=!0}clearFakeLines(){this.graphData.fakeLines.splice(0,this.graphData.fakeLines.length),this.commits.fakeLinesListChanged=!0}addNodes(e){for(const t of e)this.runtimeDATA4NodeMap.set(t.id,t);this.graphData.nodes.push(...e.map(t=>this.runtimeDATA4NodeMap.get(t.id))),this.commits.nodesListChanged=!0}addLines(e){this.graphData.normalLines.push(...e);const t=[];for(const n of e){const o=this.getNodeById(n.from),s=this.getNodeById(n.to),a={lineId:n.id,line:n,fromNode:o,toNode:s,currentLineIndex:0,totalLinesBetweenNodes:1,rgShouldRender:!0,rgCalcedVisibility:!0};this.runtimeDATA4LinkMap.set(a.lineId,a),t.push(a)}this.runtimeDATA4Links.push(...t.map(n=>this.runtimeDATA4LinkMap.get(n.lineId))),this.updateLinks(),this.commits.linesListChanged=!0}updateNode(e,t){const n=this.getNodeById(e);if(!n){console.error("Cannot find node to update:",e,t);return}const o=t.hidden!==void 0&&n.hidden!==t.hidden;if(Object.assign(n,t,{id:e}),o){const s=Le.getDescendantNodes(n);this.updateNodesVisibleProperty([n].concat(s))}this.commitNode(e)}updateNodeData(e,t){const n=this.getNodeById(e);if(!n){console.error("Cannot find node to update:",e);return}this.updateNode(e,{data:Object.assign(n.data||{},t)})}updateLine(e,t){const n=this.getLineById(e);if(!n){this.updateFakeLine(e,t);return}Object.assign(n,t,{id:e}),this.commitLine(e)}updateLineData(e,t){const n=this.getLineById(e);if(!n){console.error("Cannot find line to update:",e);return}this.updateLine(e,{data:Object.assign(n.data||{},t)})}updateFakeLine(e,t){const n=this.getFakeLineById(e);if(!n){console.error("Cannot find fakeLine to update:",e,t);return}Object.assign(n,t,{id:e}),this.commitFakeLine(e)}updateConnectTarget(e,t){const n=this.getConnectTargetById(e);!n||(Object.assign(n,t,{targetId:e}),this.commitConnectTarget(e))}updateElLineTarget(e,t){const n=this.getElLineTargetById(e);!n||Object.assign(n,t,{id:e})}updateNodesVisibleProperty(e){let t=!1;e||(e=this.getNodes(),t=!0);for(const n of e){const o=Le.isVisibleNode(n);n.rgCalcedVisibility!==o&&(n.rgCalcedVisibility=o,this.commitNode(n.id))}for(const n of this.runtimeDATA4Links)if(t||e.includes(n.fromNode)||e.includes(n.toNode)){const s=this.calcLinkVisibility(n);n.rgCalcedVisibility=s,this.commitLine(n.lineId)}}calcLinkVisibility(e){return e.fromNode.rgCalcedVisibility&&e.toNode.rgCalcedVisibility}updateShouldRenderGraphData(){const e=this.options,t=e.canvasZoom/100,n={x:-e.canvasOffset.x/t,y:-e.canvasOffset.y/t},o={x:n.x+e.viewSize.width/t,y:n.y+e.viewSize.height/t},s=e.snapshotting;for(const a of this.getNodes()){let d=!0;s||a.alwaysRender?d=!0:((a.x>o.x||a.y>o.y)&&(d=!1),(a.x+a.el_W<n.x||a.y+a.el_H<n.y)&&(d=!1)),a.rgShouldRender=d}for(const a of this.runtimeDATA4Links){if(s){a.rgShouldRender=!0;continue}a.rgShouldRender=a.fromNode.rgShouldRender||a.toNode.rgShouldRender}this.options.showEasyView?(this.runtimeDATA4ShouldRenderItems.nodes=[],this.runtimeDATA4ShouldRenderItems.lines=[],this.runtimeDATA4ShouldRenderItems.fakeLines=[]):(this.runtimeDATA4ShouldRenderItems.nodes=this.calcShouldRenderNodes(),this.runtimeDATA4ShouldRenderItems.lines=this.calcShouldRenderLines(),this.runtimeDATA4ShouldRenderItems.fakeLines=this.calcShouldRenderFakeLines())}addConnectTarget(e){return this.runtimeDATA4ConnectTargets.push(e),this.commits.connectTargetsListChanged=!0,this.commits.fakeLinesListChanged=!0,this.getConnectTargetById(e.targetId)}addElLineTarget(e){this.runtimeDATA4ElLineTargets.push(e),this.commits.fakeLinesListChanged=!0}setRootNodeId(e){if(this.graphData.rootNode=this.graphData.nodes.find(t=>t.id===e),!this.graphData.rootNode)throw new Error("The root node [rootId] is not set! Or cannot get the root node:"+e+", If you don't have any nodes to display, you can simply set an invisible node: {id:'root', opacity:0}")}}class oo{constructor(){_(this,"listeners");_(this,"useReactiveDataToAutoUpdateView",!1);_(this,"instanceId");_(this,"dataProvider");_(this,"options");_(this,"_dataUpdatedRequested",!1);_(this,"eventHandlers",[]);_(this,"_emitHook");this.dataProvider=new Oe,this.options=this.dataProvider.getOptions(),this.listeners={},this.instanceId="RG-"+this.generateNewUUID(5)}generateNewUUID(i=5){return Ie(i)}enableDebugLog(i){this.dataProvider.updateOptions({debug:i}),typeof window<"u"&&window&&(window.relationGraphDebug=i)}_dataUpdated(){this._requestDataUpdate()}_requestDataUpdate(){typeof window>"u"||!window.requestAnimationFrame||this._dataUpdatedRequested||(this._dataUpdatedRequested=!0,requestAnimationFrame(this._doSomethingAfterDataUpdated.bind(this)))}_doSomethingAfterDataUpdated(){try{!this.useReactiveDataToAutoUpdateView||this.dataProvider.isPerformanceMode()?(this._previousUpdateTime=Date.now(),this.updateShouldRenderGraphData(),this.updateEasyView(),this.dataProvider&&this.dataProvider.dataUpdated()):this.updateMiniView()}catch(i){console.error("[relation-graph]Error:",i)}finally{this._dataUpdatedRequested=!1}}addEventHandler(i){this.eventHandlers.includes(i)||this.eventHandlers.push(i)}removeEventHandler(i){const e=this.eventHandlers.indexOf(i);e!==-1&&this.eventHandlers.splice(e,1)}setEventEmitHook(i){this._emitHook=i}emitEvent(i,...e){let{result:t,handled:n}=this.defaultEventHandler(i,...e);for(const o of this.eventHandlers){const s=o(i,...e);s!==void 0&&(t=s,n=!0)}if(n||this._emitHook&&this._emitHook(i,...e,o=>{o!==void 0&&(t=o)}),t!==void 0)return L("[custom event hook]Event:",i," => returnValue:",t),t}defaultEventHandler(i,...e){let t,n=!1;if(i===I.onReady)this.listeners.onReady&&(n=!0,this.listeners.onReady(this));else if(i===I.onNodeDragStart)this.listeners.onNodeDragStart&&(n=!0,this.listeners.onNodeDragStart(e[0],e[1]));else if(i===I.onNodeDragging){if(this.listeners.onNodeDragging){n=!0;const o=e[0],s=e[1],a=e[2],d=e[3],h=e[4],c=e[5];t=this.listeners.onNodeDragging(o,s,a,d,h,c)}}else if(i===I.onCanvasDragging){if(this.listeners.onCanvasDragging){n=!0;const o=e[0],s=e[1],a=e[2],d=e[3];t=this.listeners.onCanvasDragging(o,s,a,d)}}else if(i===I.onNodeDragEnd){const o=e[0],s=e[1],a=e[2],d=e[3];this.listeners.onNodeDragEnd&&(n=!0,this.listeners.onNodeDragEnd(o,s,a,d))}else if(i===I.onZoomEnd)this.listeners.onZoomEnd&&(n=!0,this.listeners.onZoomEnd());else if(i===I.onNodeClick){if(this.listeners.onNodeClick){n=!0;const o=e[0],s=e[1];this.listeners.onNodeClick(o,s)}}else if(i===I.onLineClick){if(this.listeners.onLineClick){n=!0;const o=e[0],s=e[1],a=e[2];this.listeners.onLineClick(o,s,a)}}else if(i===I.onNodeExpand){if(this.listeners.onNodeExpand){n=!0;const o=e[0],s=e[1];this.listeners.onNodeExpand(o,s)}}else if(i===I.onNodeCollapse){if(this.listeners.onNodeCollapse){n=!0;const o=e[0],s=e[1];this.listeners.onNodeCollapse(o,s)}}else if(i===I.onCanvasDragEnd){if(this.listeners.onCanvasDragEnd){n=!0;const o=e[0];this.listeners.onCanvasDragEnd(o)}}else if(i===I.onCanvasClick){if(this.listeners.onCanvasClick){n=!0;const o=e[0];this.listeners.onCanvasClick(o)}}else if(i===I.onCanvasSelectionEnd){if(this.listeners.onCanvasSelectionEnd){n=!0;const o=e[0],s=e[1];this.listeners.onCanvasSelectionEnd(o,s)}}else if(i===I.onContextmenu){if(this.listeners.onContextmenu){n=!0;const o=e[0],s=e[1],a=e[2],d=e[3],h=e[4];this.listeners.onContextmenu(o,s,a,d,h)}}else if(i===I.onFullscreen){if(this.listeners.onFullscreen){n=!0;const o=e[0],s=e[1];t=this.listeners.onFullscreen(o,s)}}else if(i===I.beforeAddNodes){if(this.listeners.beforeAddNodes){n=!0;const o=e[0];t=this.listeners.beforeAddNodes(o)}}else if(i===I.beforeAddLines){if(this.listeners.beforeAddLines){n=!0;const o=e[0];t=this.listeners.beforeAddLines(o)}}else if(i===I.onKeyboardDown){if(this.listeners.onKeyboardDown){n=!0;const o=e[0];t=this.listeners.onKeyboardDown(o)}}else if(i===I.onKeyboardUp){if(this.listeners.onKeyboardUp){n=!0;const o=e[0];t=this.listeners.onKeyboardUp(o)}}else if(i===I.onLineBeCreated){if(this.listeners.onLineBeCreated){n=!0;const o=e[0];t=this.listeners.onLineBeCreated(o)}}else if(i===I.onCanvasDragStart){if(this.listeners.onCanvasDragStart){n=!0;const o=e[0],s=e[1],a=e[2];t=this.listeners.onCanvasDragStart(o,s,a)}}else if(i===I.onResizeEnd){if(this.listeners.onResizeEnd){n=!0;const o=e[0],s=e[1],a=e[2],d=e[3];t=this.listeners.onResizeEnd(o,s,a,d)}}else if(i===I.onResizeStart){if(this.listeners.onResizeStart){n=!0;const o=e[0],s=e[1];t=this.listeners.onResizeStart(o,s)}}else if(i===I.beforeNodeResize){if(this.listeners.beforeNodeResize){n=!0;const o=e[0],s=e[1],a=e[2],d=e[3],h=e[4];t=this.listeners.beforeNodeResize(o,s,a,d,h)}}else if(i===I.onViewResize&&this.listeners.onViewResize){n=!0;const o=e[0];t=this.listeners.onViewResize(o)}return{result:t,handled:n}}setEventListener(i){Object.assign(this.listeners,i)}}class io extends oo{constructor(){super(...arguments);_(this,"$dom");_(this,"$canvasDom");_(this,"_rgAsConnectArea",!1);_(this,"$lineTextContainer4NormalLine");_(this,"$lineTextContainer4FakeLine");_(this,"viewBoundingClientRect",null)}getLineTextContainer(e){if(!(!e||!this.$canvasDom))return e.isFakeLine?(this.$lineTextContainer4NormalLine||(this.$lineTextContainer4NormalLine=this.$canvasDom.querySelector(".rg-lines-container-el-lines .rg-linetext-container"),this.dataStores.textContainer4NormalRef&&(this.dataStores.textContainer4NormalRef.value=this.$lineTextContainer4NormalLine)),this.$lineTextContainer4NormalLine):(this.$lineTextContainer4FakeLine||(this.$lineTextContainer4FakeLine=this.$canvasDom.querySelector(".rg-lines-container-normal-lines .rg-linetext-container"),this.dataStores.textContainer4FakeLineRef&&(this.dataStores.textContainer4FakeLineRef.value=this.$lineTextContainer4FakeLine)),this.$lineTextContainer4FakeLine)}getViewBoundingClientRect(){var t;if(!this.$dom)return this.viewBoundingClientRect||console.error("[getViewBoundingClientRect] RelationGraph DOM is not set yet!"),this.viewBoundingClientRect;const e=(t=this.$dom)==null?void 0:t.getBoundingClientRect();return this.viewBoundingClientRect=e,e}getBoundingClientRect(){return console.warn("Please use getViewBoundingClientRect instead of getBoundingClientRect, this method is compatible with older api versions."),this.getViewBoundingClientRect()}_getEventPoint(e){return this.getViewXyByEvent(e)}getViewXyByEvent(e){const t=ce(e),n={x:t.clientX,y:t.clientY};return this.getViewXyByClientXy(n)}getViewXyByClientXy(e){const t=this.getViewBoundingClientRect();return{x:e.x-t.x,y:e.y-t.y}}getCanvasXyByClientXy(e){const t=this.getViewBoundingClientRect(),n={x:e.x-t.left,y:e.y-t.top};return this.getCanvasXyByViewXy(n)}getCanvasXyByViewXy(e){if(this._rgAsConnectArea)return e;const t=this.dataProvider.getOptions(),n=t.canvasZoom/100,o={x:e.x-t.canvasOffset.x,y:e.y-t.canvasOffset.y};return{x:o.x/n,y:o.y/n}}getViewXyByCanvasXy(e){const t=this.dataProvider.getOptions(),n=t.canvasZoom/100;return{x:e.x*n+t.canvasOffset.x,y:e.y*n+t.canvasOffset.y}}getCanvasCoordinateByClientCoordinate(e){return console.warn("Please use getCanvasXyByClientXy instead of getCanvasCoordinateByClientCoordinate, this method is compatible with older api versions."),this.getCanvasXyByClientXy(e)}isNode(e){const t=ve(e,"rg-node-peel","rg-map");if(!!t)return this.dataProvider.getNodeById(t.dataset.id)}isLine(e){const t=ve(e,"rg-line-peel","relation-graph");if(!!t)return this.dataProvider.getLineById(t.dataset.id)}isLink(e){throw new Error("Please use isLine")}}class so extends Oe{constructor(e,t,n,o){super();_(this,"dataStores");this.dataStores=e;const s=Object.assign({},this.options,n);this.options=n,Object.assign(this.options,s),this.graphData=t,this.runtimeDATA4Links=o.runtimeDATA4Links,this.runtimeDATA4ShouldRenderItems=o.runtimeDATA4ShouldRenderItems,this.runtimeDATA4ConnectTargets=o.runtimeDATA4ConnectTargets,this.runtimeDATA4NodeMap=o.runtimeDATA4NodeMap,this.runtimeDATA4LinkMap=o.runtimeDATA4LinkMap,this.runtimeDATA4ElLineTargets=o.runtimeDATA4ElLineTargets,this.updateViewHook=a=>{if(a.optionsChanged&&this.dataStores.store4Options.set(this.getOptions()),a.nodesListChanged&&this.dataStores.store4ShouldRenderNodes.set(this.getShouldRenderNodes()),a.linesListChanged){const d=this.getShouldRenderLines();this.dataStores.store4ShouldRenderLines.set(d)}if(a.fakeLinesListChanged){const d=this.getShouldRenderFakeLines();this.dataStores.store4ShouldRenderFakeLines.set(d)}}}}class ao extends Oe{constructor(i,e,t){super(),this.graphData=i,this.runtimeDATA4Links=t.runtimeDATA4Links,this.runtimeDATA4ShouldRenderItems=t.runtimeDATA4ShouldRenderItems,this.runtimeDATA4ConnectTargets=t.runtimeDATA4ConnectTargets,this.runtimeDATA4NodeMap=t.runtimeDATA4NodeMap,this.runtimeDATA4LinkMap=t.runtimeDATA4LinkMap,this.runtimeDATA4ElLineTargets=t.runtimeDATA4ElLineTargets;const n=Object.assign({},this.options,e);this.options=e,Object.assign(this.options,n)}}class ro extends Oe{constructor(e,t){super();_(this,"dataStores");this.dataStores=e,this.updateViewHook=n=>{n.optionsChanged&&this.dataStores.store4Options.set(this.getOptions()),(n.nodesListChanged||n.changedNodes.length>0)&&this.dataStores.store4ShouldRenderNodes.set(this.getShouldRenderNodes()),(n.nodesListChanged||n.linesListChanged||n.changedLines.length>0)&&this.dataStores.store4ShouldRenderLines.set(this.getShouldRenderLines()),(n.fakeLinesListChanged||n.changedFakeLines.length>0)&&this.dataStores.store4ShouldRenderFakeLines.set([...this.getShouldRenderFakeLines()])}}}class lo extends Oe{constructor(i,e){super(),e(),this.updateViewHook=t=>{if(t.optionsChanged&&i.store4Options.set(this.getOptions()),t.linesListChanged||t.changedLines.length>0||t.nodesListChanged||t.changedNodes.length>0){const n=this.getShouldRenderNodes();i.store4ShouldRenderNodes.set([...n])}if(t.linesListChanged||t.changedLines.length>0){const n=this.getShouldRenderLines();i.store4ShouldRenderLines.set(n)}t.fakeLinesListChanged?i.store4ShouldRenderFakeLines.set([...this.getShouldRenderFakeLines()]):t.changedFakeLines.length>0&&i.store4ShouldRenderFakeLines.set(this.getShouldRenderFakeLines())}}}class co extends io{constructor(){super();_(this,"_initRawPropertyFn",(e,t,n)=>{});_(this,"dataStores")}setReactiveData4Vue2(e,t,n,o){this.useReactiveDataToAutoUpdateView=!0,this.dataProvider=new ao(e,t,n),this._initRawPropertyFn=o,this.options=this.dataProvider.options,this.dataStores={shouldRenderNodesStore:n.runtimeDATA4ShouldRenderItems.nodes,shouldRenderLinesStore:n.runtimeDATA4ShouldRenderItems.lines,shouldRenderFakeLinesStore:n.runtimeDATA4ShouldRenderItems.fakeLines}}setReactiveData4Vue3(e,t,n,o,s){this.useReactiveDataToAutoUpdateView=!0,this.dataProvider=new so(e,t,n,o),this._initRawPropertyFn=s,this.options=this.dataProvider.getOptions(),this.dataStores={optionsStore:e.store4Options,shouldRenderNodesStore:e.store4ShouldRenderNodes,shouldRenderLinesStore:e.store4ShouldRenderLines,shouldRenderFakeLinesStore:e.store4ShouldRenderFakeLines,optionsRef:e.optionsRef,shouldRenderNodesRef:e.shouldRenderNodesRef,shouldRenderLinesRef:e.shouldRenderLinesRef,shouldRenderFakeLinesRef:e.shouldRenderFakeLinesRef,textContainer4NormalRef:e.textContainer4NormalRef,textContainer4FakeLineRef:e.textContainer4FakeLineRef}}setReactiveData4React(e,t){this.dataProvider=new lo(e,t),this.options=this.dataProvider.getOptions(),this.dataStores={optionsStore:e.store4Options,shouldRenderNodesStore:e.store4ShouldRenderNodes,shouldRenderLinesStore:e.store4ShouldRenderLines,shouldRenderFakeLinesStore:e.store4ShouldRenderFakeLines}}setReactiveData4Svelte(e,t){this.dataProvider=new ro(e,t),this.options=this.dataProvider.getOptions(),this.dataStores={optionsStore:e.store4Options,shouldRenderNodesStore:e.store4ShouldRenderNodes,shouldRenderLinesStore:e.store4ShouldRenderLines,shouldRenderFakeLinesStore:e.store4ShouldRenderFakeLines}}generateNewNodeId(e=5){const t=Ie(e);return this.dataProvider.getNodeById(t)?this.generateNewNodeId(e+1):t}}class ho extends co{constructor(){super()}getOptions(){return this.dataProvider.getOptions()}getNodeById(i){return this.dataProvider.getNodeById(i)}getLineById(i){return this.dataProvider.getLineById(i)}getLinkByLineId(i){return this.dataProvider.getLinkByLineId(i)}getLinkByLine(i){return this.getLinkByLineId(i.id)}getLines(){return this.dataProvider.getLines()}getElementLineById(i){return this.getFakeLineById(i)}getElementLines(){return this.getFakeLines()}getFakeLines(){return this.dataProvider.getFakeLines()}getFakeLineById(i){return this.dataProvider.getFakeLineById(i)}getNodes(){return this.dataProvider.getNodes()}getLinks(){return this.dataProvider.getLinks()}_getAllLinks(){const i=this.getLinks();return this._getFakeLineLinks().concat(i)}getNodeByTargetId(i){const e=this.dataProvider.getConnectTargetById(i);if(e&&e.nodeId)return this.getNodeById(e.nodeId)}_getFakeLineLinks(){const i=[];for(const e of this.getFakeLines())if(!e.forDisplayOnly&&(e.fromType===D.Node||e.fromType===D.NodePoint||e.fromType===D.CanvasPoint)&&(e.toType===D.Node||e.toType===D.NodePoint||e.toType===D.CanvasPoint)){let t=null,n=null;e.fromType===D.Node?t=this.getNodeById(e.from):(e.fromType===D.NodePoint||e.fromType===D.CanvasPoint)&&(t=this.getNodeByTargetId(e.from)),e.toType===D.Node?n=this.getNodeById(e.to):(e.toType===D.NodePoint||e.toType===D.CanvasPoint)&&(n=this.getNodeByTargetId(e.to)),t&&n&&i.push({lineId:e.id,line:e,fromNode:t,toNode:n,totalLinesBetweenNodes:1,currentLineIndex:0,rgShouldRender:!0,rgCalcedVisibility:!0})}return i}getConnectTargets(){return this.dataProvider.getConnectTargets()}getConnectTargetById(i){return this.dataProvider.getConnectTargetById(i)}}class fo extends ho{constructor(){super()}getRelatedLinesByNode(i){const e=[];for(const t of this._getAllLinks())(i===t.fromNode||i===t.toNode)&&e.push(t.line);return e}getLinksBetweenNodes(i){const e=[],t=this._getAllLinks();for(const n of t)i.includes(n.fromNode)&&i.includes(n.toNode)&&e.push(n);return e}getLinesBetweenNodes(i){return this.getLinksBetweenNodes(i).map(e=>e.line)}getNodeRelatedNodes(i,e={incoming:!0,outgoing:!0}){const t=[];for(const n of this.getLinks()){if(n.line.forDisplayOnly)continue;const{fromNode:o,toNode:s}=n;e.outgoing&&o===i&&(t.includes(s)||t.push(s)),e.incoming&&s===i&&(t.includes(o)||t.push(o))}for(const n of this._getFakeLineLinks()){if(n.line.forDisplayOnly)continue;const{fromNode:o,toNode:s}=n;e.outgoing&&o===i&&(t.includes(s)||t.push(s)),e.incoming&&s===i&&(t.includes(o)||t.push(o))}return t}getNodeIncomingNodes(i){return this.getNodeRelatedNodes(i,{incoming:!0,outgoing:!1})}getNodeOutgoingNodes(i){return this.getNodeRelatedNodes(i,{incoming:!1,outgoing:!0})}findGroupNodes(i,e=[]){return this._getNetworkNodesByNode(i,e)}getGroupNodesByNode(i,e=[]){return this._getNetworkNodesByNode(i,e)}getNetworkNodesByNode(i){return this._getNetworkNodesByNode(i)}_getNetworkNodesByNode(i,e=[]){if(!i)throw new Error("Call graphInstance.getNetworkNodesByNode:error: node is undefined");e.includes(i)||e.push(i);for(const t of this.getNodeRelatedNodes(i))e.includes(t)||this._getNetworkNodesByNode(t,e);return e}getStuffSize(i){return console.warn("Please use getNodesRectBox instead of getStuffSize, this method is compatible with older api versions."),this.getNodesRectBox(i)}getNodesViewInfo(i){return console.warn("Please use getNodesRectBox instead of getNodesViewInfo, this method is compatible with older api versions."),this.getNodesRectBox(i)}getNodesRectBox(i){const t=(i||this.getNodes()).filter(c=>c.rgCalcedVisibility!==!1);if(t.length===0)return{width:10,height:10,minX:0,minY:0,maxX:0,maxY:0};let n=9999999,o=9999999,s=-9999999,a=-9999999;t.forEach(c=>{c.x<n&&(n=c.x),c.x+(c.width||c.el_W)>s&&(s=c.x+(c.width||c.el_W)),c.y<o&&(o=c.y);const p=c.y+(c.height||c.el_H);p>a&&(a=p)});const d=s-n,h=a-o;return{width:d<0?0:d,height:h<0?0:h,minX:n===9999999?0:n,minY:o===9999999?0:o,maxX:s===-9999999?0:s,maxY:a===-9999999?0:a}}getNodesCenter(i){const e=this.getNodesRectBox(i);L("getNodesCenter:",e);const t=e.minX+(e.maxX-e.minX)/2,n=e.minY+(e.maxY-e.minY)/2;return{x:t,y:n}}getDescendantNodes(i){return Le.getDescendantNodes(i)}getNodesInSelectionView(i){const e=this.getCanvasXyByViewXy({x:i.x,y:i.y}),t=this.getCanvasXyByViewXy({x:i.x+i.width,y:i.y+i.height}),n=[];return this.getNodes().forEach(o=>{const s=o.x+o.el_W/2,a=o.y+o.el_H/2;s>e.x&&a>e.y&&s<t.x&&a<t.y&&n.push(o)}),n}getShouldRenderNodes(i){return this.dataProvider.isPerformanceMode()&&i?i:this.dataProvider.getShouldRenderNodes()}getShouldRenderLines(i){return this.dataProvider.isPerformanceMode()&&i?i:this.dataProvider.getShouldRenderLines()}getShouldRenderFakeLines(i){return this.dataProvider.isPerformanceMode()&&i?i:this.dataProvider.getShouldRenderFakeLines()}}class po extends fo{constructor(){super();_(this,"_elLineUpdateTimer");_(this,"_canvasCurrentInfo",{x:0,y:0,scale:1});_(this,"_nodeResizeEffectTimer");_(this,"prevAddNodeTimestamp",0);_(this,"_nodesElSizeMap",new Map)}removeLine(e){this.removeLines([e])}removeLines(e){this.removeLineByIds(e.map(t=>t.id))}removeLineById(e){this.removeLineByIds([e])}removeLineByIds(e){this.dataProvider.removeLineByIds(e),this._dataUpdated()}removeFakeLine(e){this.removeFakeLineById(e.id)}removeFakeLineById(e){L("removeLineById:",e),this.dataProvider.removeFakeLineByIds([e]),this._dataUpdated()}removeLink(e){L("removeLink:",e),this.removeLinkByLineId(e.lineId)}removeLinkByLineId(e){this.dataProvider.removeLineByIds([e]),this._dataUpdated()}removeNodeById(e){this.dataProvider.removeNodeById([e]),this._dataUpdated()}removeNodesByIds(e){e.forEach(t=>this.dataProvider.removeNodeById(e)),this._dataUpdated()}removeNodes(e){this.removeNodesByIds(e.map(t=>t.id))}removeNode(e){this.removeNodes([e])}removeELementLineById(e){L("removeELementLineById:",e),this.removeFakeLineById(e)}addNode(e){if(L("addNode:",e),e&&Array.isArray(e)){console.error("addNode: node is array:",e);return}this._addNodes([e]),this._dataUpdated()}addNodes(e){if(L("addNodes:",e),e&&!Array.isArray(e)){console.error("addNodes: nodes is not array:",e);return}this._addNodes(e),this._dataUpdated()}addLine(e){if(L("addLine:",e),e&&Array.isArray(e)){console.error("addLine: line is array:",e);return}this.addLines([e])}addLines(e){if(L("addLines:",e),e&&!Array.isArray(e)){console.error("addLines: lines is not array:",e);return}if(e.length===0)return;const t=e.filter(o=>!o.isFakeLine);this._addLines(t);const n=e.filter(o=>o.isFakeLine);this.addFakeLines(n),this._dataUpdated()}_addFakeLines(e){this.dataProvider.addFakeLines(e)}addFakeLines(e){L("addFakeLines:",e),this._addFakeLines(e),this._dataUpdated()}updateElementLines(){this.dataProvider.getElLineTargets().length!==0&&(L("updateElementLines:runtimeDATA4ElLineTargets:",this.dataProvider.getElLineTargets().length),this._elLineUpdateTimer&&clearTimeout(this._elLineUpdateTimer),this._elLineUpdateTimer=setTimeout(()=>{this._updateElementLines(),this._dataUpdated()},100))}_updateElementLines(){this._updateCanvasBoxInfo();for(const e of this.dataProvider.getElLineTargets())this.updateElementTarget(e)}_updateCanvasBoxInfo(){const e=this.$canvasDom.getBoundingClientRect();this._canvasCurrentInfo.x=e.x,this._canvasCurrentInfo.y=e.y,this._canvasCurrentInfo.scale=this.dataProvider.getOptions().canvasZoom/100}updateElementTarget(e){const t=this._getElementTargetPosition(document.getElementById(e.id),e);t?this.dataProvider.updateElLineTarget(e.id,{hidden:!1,...t}):this.dataProvider.updateElLineTarget(e.id,{hidden:!0})}_getElementTargetPosition(e){if(!e)return null;const t=e.getBoundingClientRect(),n=(t.x-this._canvasCurrentInfo.x)/this._canvasCurrentInfo.scale,o=(t.y-this._canvasCurrentInfo.y)/this._canvasCurrentInfo.scale,s=t.width/this._canvasCurrentInfo.scale,a=t.height/this._canvasCurrentInfo.scale;return{x:n,y:o,el_W:s,el_H:a}}addElementLines(e){L("addElementLines:",e),e.forEach(t=>{t.fromType=D.HTMLElementId,t.toType=D.HTMLElementId,t.isFakeLine=!0,t.id||(t.id=this.generateNewUUID(6)),t.forDisplayOnly=!0}),this.addFakeLines(e),this.updateElementLines()}updateNodeOffsetSize(e,t,n){const o=this.getNodeById(e);if(!o)return;const s=o.el_W,a=o.el_H;(s!==t||a!==n)&&(this.dataProvider.updateNode(e,{el_W:t,el_H:n}),this._nodeResizeEffectTimer&&clearTimeout(this._nodeResizeEffectTimer),this._nodeResizeEffectTimer=setTimeout(()=>{this._dataUpdated()},100))}clearFakeLines(){this.dataProvider.clearFakeLines(),this._dataUpdated()}clearElementLines(){const e=[];for(const t of this.getFakeLines())(t.fromType===D.HTMLElementId||t.toType===D.HTMLElementId)&&e.push(t.id);this.dataProvider.removeFakeLineByIds(e),this._dataUpdated()}_addNodes(e){this.emitEvent(I.beforeAddNodes,e);const t={};this.getNodes().forEach(s=>{t[s.id]=s});const n=[],o=this.getOptions();e.forEach(s=>{let a=t[s.id];if(!a){let{text:d,id:h}=s;!d&&s.label&&(d=s.label,console.warn('Use "label" as "text":',s.label)),d===void 0&&h&&(d=h,console.warn('Use "id" as "text":',h)),a=we(Object.assign({},s,{text:d}),o,this._nodesElSizeMap),this._initRawPropertyFn&&this._initRawPropertyFn(a,"lot",a.lot),a&&(t[a.id]=a,n.push(a))}}),this.dataProvider.addNodes(n),n.length>0&&(this.prevAddNodeTimestamp=Date.now())}_addLines(e){this.emitEvent(I.beforeAddLines,e);const t=[];e.forEach(n=>{let{from:o,to:s,text:a}=n;if(!o)if(n.source)o=n.source,console.warn('Use "source" as "from":',n.source);else{console.error('JsonLine Must have field:"from"',n);return}if(!s)if(n.target)s=n.target,console.warn('Use "target" as "to":',n.target);else{console.error('JsonLine Must have field:"to"',n);return}if(a||n.label&&(a=n.label,console.warn('Use "label" as "text":',n.label)),!this.getNodeById(o)){console.error("Can not found from node:",n);return}if(!this.getNodeById(s)){console.error("Can not found to node:",n);return}if(n.id){if(this.getLineById(n.id)){console.warn("_addLines:skip duplicate line id:",n.id);return}else if(t.some(p=>p.id===n.id)){console.warn("Duplicate line id in new lines:",n.id);return}}else n.id="L-"+this.generateNewUUID(6);const c=he(Object.assign({},n,{from:o,to:s,text:a}),this.getOptions());t.push(c)}),this.dataProvider.addLines(t)}updateNode(e,t){this.dataProvider.updateNode(typeof e=="string"?e:e.id,t),this._dataUpdated()}updateNodePosition(e,t,n){var s;const o=typeof e=="string"?e:e.id;this.dataProvider.updateNode(o,{x:t,y:n}),this.getOptions().layout.autoLayouting&&((s=this.layoutor)==null||s.syncNodePosition(o,t,n)),this._dataUpdated()}updateNodeData(e,t){this.dataProvider.updateNodeData(typeof e=="string"?e:e.id,t),this._dataUpdated()}updateLine(e,t){this.dataProvider.updateLine(typeof e=="string"?e:e.id,t),this._dataUpdated()}updateLineData(e,t){this.dataProvider.updateLineData(typeof e=="string"?e:e.id,t),this._dataUpdated()}updateFakeLine(e,t){this.dataProvider.updateFakeLine(typeof e=="string"?e:e.id,t),this._dataUpdated()}flatNodeData(e,t,n,o){Le.flatNodeData(e,t,n,o)}backupNodesElSize(){for(const e of this.getNodes())this._nodesElSizeMap.set(e.id,[e.el_W,e.el_H])}loadGraphJsonData(e){e.lines||(e.lines=e.relations,e.lines&&console.warn("[relation-graph] For compatibility with older version, Use jsonData.relations as jsonData.lines, It is recommended that you define your data using")),e.lines||(e.lines=e.links||e.edges,e.lines&&console.warn("[relation-graph] For compatibility with older version, Use jsonData.links/jsonData.edges as jsonData.lines, It is recommended that you define your data using"));const t=e.nodes||[],n=e.lines||[],o=[],s=[];this.flatNodeData(t,null,o,s),n.forEach(a=>{s.push(a)}),this._addNodes(o),L("Nodes is initialized"),this._addLines(s),this._dataUpdated(),e.fakeLines&&this.addFakeLines(e.fakeLines),setTimeout(()=>{e.elementLines&&(console.warn("elementLines is deprecated, please use fakeLines with isFakeLine and fromType/toType = RGInnerConnectTargetType.HTMLElementId instead:",e.elementLines),this.addElementLines(e.elementLines)),this._dataUpdated()},500)}updateShouldRenderGraphData(e=!1){!e&&!this.dataProvider.isPerformanceMode()||this.dataProvider.updateShouldRenderGraphData()}updateNodesVisibleProperty(e){this.dataProvider.updateNodesVisibleProperty(e)}updateVisibleNodesSize(){for(const e of this.getShouldRenderNodes()){const t=this.getNodeElByNodeId(e.id);t&&this._onNodeDomResize(t,t.clientWidth,t.clientHeight)}}_clearGraph(){this.backupNodesElSize(),this.dataProvider.clearReactiveData(),this.dataProvider.clearChecked(),this.dataProvider.setEditingLine(null),this.dataProvider.setEditingNodes([])}_setJsonData(e,t=!1){this._clearGraph(),this.loadGraphJsonData(e)}}class uo extends po{constructor(){super();_(this,"canvasConnectTargetsMap",new Map);_(this,"nodeConnectTargetsMap",new Map);_(this,"connectTargetElementMap",new Map);_(this,"_connectTargetUpdateRequestedSet",new Map);_(this,"_updateTimer");_(this,"_removedConnectTargetMap",new Map)}updateConnectTargetsOnCanvas(e,t){if(!t)return;const n=t.classList.contains("rg-canvas-slot-above")?"above":"behind",o=this.canvasConnectTargetsMap.get(n);o&&o.length>0&&this.updateConnectTargetList(e,t,o)}updateConnectTargetsByNodeId(e){const t=this.getNodeElByNodeId(e);this.updateConnectTargetsOnNode("API",e,t)}getNodeElByNodeId(e){return this.$dom.querySelector(`[data-id="${e}"]`)}updateConnectTargetsOnNode(e,t,n){const o=this.nodeConnectTargetsMap.get(t)||[];o.length!==0&&this.updateConnectTargetList(e,n,o)}updateConnectTargetList(e,t,n){const o=this.dataProvider.getCanvasScale();for(const s of n){const a=this.connectTargetElementMap.get(s.targetId);if(!a){console.error("Can not find el for connectTarget:",s.targetId,s);continue}this._requestUpdateConnectTargetOffset(e,s,a,t,o)}}_requestUpdateConnectTargetOffset(e,t,n,o,s){this._connectTargetUpdateRequestedSet.set(t.targetId,{stableTimes:0,connectTarget:t,by:e,connectTargetEl:n,relativeEl:o}),clearTimeout(this._updateTimer),this._updateTimer=setTimeout(()=>{this._updateAllRequestedConnectTargetOffsets()},Math.min(this._connectTargetUpdateRequestedSet.size+10,50))}_updateAllRequestedConnectTargetOffsets(){let e=0;for(const t of this._connectTargetUpdateRequestedSet.values()){const{by:n,connectTargetEl:o,relativeEl:s,connectTarget:a}=t;if(this.dataProvider.isPerformanceMode()&&a.nodeId){const f=this.getNodeById(a.nodeId);if(!f||!f.rgShouldRender||!f.rgCalcedVisibility)continue}if(!this.dataProvider.getConnectTargetById(a.targetId))continue;const h=this.dataProvider.getCanvasScale();this._updateConnectTargetOffset(n,a,o,s,h)?e++:t.stableTimes++,t.stableTimes>2&&this._connectTargetUpdateRequestedSet.delete(a.targetId)}e>0?(clearTimeout(this._updateTimer),this._updateTimer=setTimeout(()=>{this._updateAllRequestedConnectTargetOffsets()},Math.min(e/2+10,100)),this._dataUpdated()):(this._connectTargetUpdateRequestedSet.clear(),this._dataUpdated())}_updateConnectTargetOffset(e,t,n,o,s){const a=o.getBoundingClientRect(),d=n.getBoundingClientRect(),h=Math.round(d.x-a.x),c=Math.round(d.y-a.y),f=this.dataProvider.getCanvasScale(),p=Math.round(h/f),m=Math.round(c/f),u=Math.round(d.width/f),g=Math.round(d.height/f),y=t.offsetX!==p,v=t.offsetY!==m,x=u!==0&&t.width!==u,w=g!==0&&t.height!==g;return y||v||x||w?(this.dataProvider.updateConnectTarget(t.targetId,{offsetX:p,offsetY:m,width:u,height:g}),!0):!1}_onConnectTargetMounted(e,t,n,o){const s=this.dataProvider.getCanvasScale();this._requestUpdateConnectTargetOffset(e,t,n,o,s)}getNodeElByChildrenTarget(e){return ve(e,"rg-node-peel","rg-map")}registerConnectTarget(e,t,n,o,s={}){if(n!==D.NodePoint&&n!==D.CanvasPoint)return;if(!e){console.error(`[registerConnectTarget]Can not find CanvasPoint target DOM: ${t}`);return}const a=this.getNodeElByChildrenTarget(e),d=a==null?void 0:a.dataset.id;if(d==="rg-newNodeTemplate")return;let h=this.dataProvider.getConnectTargetById(t);if(!h){const f={targetId:t,targetType:n,junctionPoint:o,nodeId:"",width:20,height:20,offsetX:0,offsetY:0,offsetPercentX:0,offsetPercentY:0,targetData:s||{}};this.reuseConnectTarget(f),h=this.dataProvider.addConnectTarget(f)}return this.connectTargetElementMap.set(h.targetId,e),(d?this.getNodeById(d):null)?this._addConnectTargetToNodeMap(d,h,e,a):this._addConnectTargetToCanvasMap(h,e),h}_addConnectTargetToNodeMap(e,t,n,o){this.dataProvider.updateConnectTarget(t.targetId,{junctionPoint:t.junctionPoint,targetType:D.NodePoint,nodeId:e,targetData:Object.assign({},t.targetData||{},{nodeId:e})});let s=this.nodeConnectTargetsMap.get(e);s?s.some(a=>a.targetId===t.targetId)||s.push(t):this.nodeConnectTargetsMap.set(e,[t]),this._onConnectTargetMounted("NT-Mounted",t,n,o)}_addConnectTargetToCanvasMap(e,t){let n=ve(t,"rg-canvas-slot","rg-map");if(!!n&&n){const o=n.classList.contains("rg-canvas-slot-above")?"above":"behind";this.dataProvider.updateConnectTarget(e.targetId,{junctionPoint:e.junctionPoint,targetType:D.CanvasPoint,targetData:Object.assign({},e.targetData||{})});const s=this.canvasConnectTargetsMap.get(o);s?s.some(a=>a.targetId===e.targetId)||s.push(e):this.canvasConnectTargetsMap.set(o,[e]),this._onConnectTargetMounted("CT-Mounted",e,t,n)}}unregisterConnectTarget(e){const t=this.dataProvider.getConnectTargetById(e);if(!t)return;let n;if(t.nodeId&&this.nodeConnectTargetsMap.has(t.nodeId))n=this.nodeConnectTargetsMap.get(t.nodeId);else{const o=this.canvasConnectTargetsMap.get("behind");if(o){let s=o.findIndex(a=>a.targetId===e);s!==-1?n=this.canvasConnectTargetsMap.get("behind"):(s=this.canvasConnectTargetsMap.get("above").findIndex(a=>a.targetId===e),s!==-1&&(n=this.canvasConnectTargetsMap.get("above")))}}if(n){const o=n.findIndex(s=>s.targetId===e);o!==-1&&n.splice(o,1)}this.dataProvider.removeConnectTarget(e),this.connectTargetElementMap.delete(e),this._removedConnectTargetMap.set(t.targetId,t)}reuseConnectTarget(e){if(this._removedConnectTargetMap.has(e.targetId)){const t=this._removedConnectTargetMap.get(e.targetId);e.offsetX=t.offsetX,e.offsetY=t.offsetY,e.width=t.width,e.height=t.height,e.offsetPercentX=t.offsetPercentX,e.offsetPercentY=t.offsetPercentY,this._removedConnectTargetMap.delete(e.targetId)}}}class go extends uo{constructor(){super();_(this,"fakeLineTargetRender")}generateCreatingLineConfig(e){e||(e=this.dataProvider.getOptions());const{newLinkTemplate:t,newLineTemplate:n}=e,o=t.fromNode;if(!o)return{line:n,from:null,to:null,totalLinesBetweenNodes:1,currentLineIndex:0};const s=t.toNode,a=s.targetType===D.Node?t.toNode:this.getFakeLineTarget(s.targetType,s.id,n);return{line:Object.assign({},n,{isFakeLine:!1}),from:this.getFakeLineTarget(o.targetType,o.id,n),to:a,totalLinesBetweenNodes:1,currentLineIndex:0}}generateLineConfig(e){const t=this.getLinkByLine(e);return!t||!t.rgCalcedVisibility?!1:{line:t.line,from:t.fromNode,to:t.toNode,totalLinesBetweenNodes:t.totalLinesBetweenNodes,currentLineIndex:t.currentLineIndex}}generateFakeLineConfig(e){let t=1,n=0;if(e.fromType===D.HTMLElementId&&e.toType===D.HTMLElementId){const a=this.dataProvider.getFakeLines().filter(d=>d.from===e.from&&d.to===e.to);a.length>1&&(console.warn("sameTargetLines element-line:",e),t=a.length,n=a.indexOf(e))}let o=this.getFakeLineTarget(e.fromType,e.from,e),s=this.getFakeLineTarget(e.toType,e.to,e);return!o&&e.fromType===D.Node?(console.error("[generateFakeLineConfig]error fakeLine from:",e.fromType,e.from,e),!1):!s&&e.fromType===D.Node?(console.error("[generateFakeLineConfig]error fakeLine to:",e.toType,e.to,e),!1):{line:e,from:o,to:s,totalLinesBetweenNodes:t,currentLineIndex:n}}setFakeLineTargetRender(e){this.fakeLineTargetRender=e}getFakeLineTarget(e,t,n){if(e===D.HTMLElementId){let o=this.dataProvider.getElLineTargets().find(s=>s.id===t);return o||(o={x:300,y:300,targetType:D.HTMLElementId,nodeShape:1,id:t,el_W:40,el_H:40,hidden:!0},this.dataProvider.addElLineTarget(o),this.updateElementLines()),o.hidden?null:o}else{if(e===D.Node)return this.getNodeById(t);if(e===D.NodePoint||e===D.CanvasPoint){const o=this.dataProvider.getConnectTargetById(t);if(!o)return;if(o.nodeId){const s=this.getNodeById(o.nodeId);if(!s){console.error("[getFakeLineTarget]Can not find NodePoint-s Node:",`${o.targetId}@${o.nodeId}`);return}return{x:s.x+o.offsetPercentX*s.el_W+o.offsetX,y:s.y+o.offsetPercentY*s.el_H+o.offsetY,targetType:D.NodePoint,targetData:o.targetData,nodeShape:0,id:t,el_W:o.width,el_H:o.height,hidden:!1}}else return{x:o.offsetX,y:o.offsetY,targetType:D.CanvasPoint,targetData:o.targetData,nodeShape:0,id:t,el_W:o.width,el_H:o.height,hidden:!1}}}if(this.fakeLineTargetRender)return this.fakeLineTargetRender(e,t,n)}}class mo extends go{constructor(){super()}_updateOptions(i){!i.instanceId&&this.getOptions().instanceId!==i.instanceId&&(i.instanceId=this.instanceId);const e=Object.assign({},i);if(e.layouts)throw new Error('Graph options do not support setting layouts properties, Please use "layout"!');if(e.lineUseTextPath)throw new Error('Graph options do not support setting layouts properties, Please use "defaultLineTextOnPath"!');if(e.debug!==void 0){const t=e.debug===!0;t&&L("RGOptions:user instance options:",e),typeof window<"u"&&window&&(window.relationGraphDebug=t)}e.layout?(this.dataProvider.updateOptions({...e,layout:{...this.getOptions().layout,...e.layout}}),this.layoutor&&this.layoutor.updateOptions&&this.layoutor.updateOptions(e.layout)):this.dataProvider.updateOptions(e)}resetViewSize(i=!1){const e=this.getViewBoundingClientRect(),t={};t.viewSize={width:e.width,height:e.height},this._rgAsConnectArea?(t.canvasZoom=100,t.canvasOffset={x:0,y:0}):i&&(t.canvasZoom=100,t.canvasOffset={x:t.viewSize.width/2,y:t.viewSize.height/2}),this.dataProvider.updateOptions(t),L("resetViewSize:1:",t),this._dataUpdated()}loading(i=""){this.dataProvider.updateOptions({graphLoading:!0,graphLoadingText:i}),this._dataUpdated()}clearLoading(){this.dataProvider.updateOptions({graphLoading:!1,graphLoadingText:""}),this._dataUpdated()}setCheckedNode(i){this.dataProvider.updateOptions({checkedNodeId:i?typeof i=="string"?i:i.id:""}),this._dataUpdated()}setCheckedLine(i){this.dataProvider.updateOptions({checkedLineId:i?typeof i=="string"?i:i.id:""})}clearChecked(){this.dataProvider.clearChecked(),this._dataUpdated()}clearSelected(){const i=this.getNodes().filter(n=>n.selected),e=this.getLines().filter(n=>n.selected),t=this.getFakeLines().filter(n=>n.selected);i.forEach(n=>this.dataProvider.updateNode(n.id,{selected:!1})),e.forEach(n=>this.dataProvider.updateLine(n.id,{selected:!1})),t.forEach(n=>this.dataProvider.updateFakeLine(n.id,{selected:!1})),this._dataUpdated()}setCanvasOffset(i,e){this.dataProvider.setCanvasOffset(i,e),this._updateEditingControllerView(),this.updateShouldRenderGraphData(),this._dataUpdated()}setCanvasMoveMode(i){this.dataProvider.updateOptions({canvasMoveMode:i}),this._dataUpdated()}onMiniViewMounted(){this.dataProvider.updateOptions({showMiniView:!0}),this._dataUpdated()}onMiniViewUnMounted(){this.dataProvider.updateOptions({showMiniView:!1})}onReferenceLineMounted(i){this.dataProvider.updateOptions({referenceLineAdsorption:i||!1,showReferenceLine:!0})}onReferenceLineUnMounted(){this.dataProvider.updateOptions({referenceLineAdsorption:!1,showReferenceLine:!1})}}class yo extends mo{constructor(){super()}getCreatingLine(i){if(i||(i=this.getOptions()),!i.creatingLinePlot)return{creating:!1};const{line:e,from:t,to:n}=this.generateCreatingLineConfig();return{creating:!0,fromTarget:t,toTarget:n,lineJson:e}}getCreatingNode(i){return i||(i=this.getOptions()),i.creatingNodePlot?{creating:i.creatingNodePlot,nodeJson:i.newNodeTemplate}:{creating:!1}}}const vo=l=>{const i=Math.sin(l)*1e4;return i-Math.floor(i)},Ct=(l,i,e,t,n,o)=>{const a=e-l,d=t-i,h=Math.sqrt(a*a+d*d),c=Math.max(2,Math.floor(h/12)),f=-d/h,p=a/h,m=[{type:"M",x:l,y:i}];let u=l,g=i;for(let y=1;y<=c;y++){let v=l+a*y/c,x=i+d*y/c;if(y<c){const w=vo(n+y)-.5;v+=f*w*o,x+=p*w*o}m.push({type:"l",dx:v-u,dy:x-g}),u=v,g=x}return m},xo=(l,i={x:0,y:0,rotate:0})=>{const{fx:e,fy:t,tx:n,ty:o}=l;i.rotate=j.getTextAngle(e,t,n,o),i.x=e+(n-e)/2,i.y=t+(o-t)/2,Number.isNaN(i.rotate)&&(i.rotate=0);const s=e+t+n+o,a=Ct(e,t,n,o,s,2.5),d=Ct(e,t,n,o,s+99,1.5),h=`${ae(a)} ${ae(d)}`;return{pathCommands:[...a,...d],pathData:h,textPosition:i,points:[]}};class Co extends yo{constructor(){super()}_getJunctionPoint(i,e){return i===W.border?j.getBorderPoint4MultiLine(e):i===W.ltrb?j.getRectJoinPoint(e):i===W.tb?j.getRectVJoinPoint(e):i===W.lr?j.getRectHJoinPoint(e):i===W.left?j.getRectLeftJoinPoint(e):i===W.right?j.getRectRightJoinPoint(e):i===W.top?j.getRectTopJoinPoint(e):i===W.bottom?j.getRectBottomJoinPoint(e):i==="horizontalLine"?j.getRectHorizontalLineJoinPoint(e):i==="verticalLine"?j.getRectVerticalLineLineJoinPoint(e):j.getBorderPoint4MultiLine(e)}createLinePath(i,e,t){throw new Error("createLinePath() is deprecated, please use createLineDrawInfo() instead.")}createLineDrawInfo(i,e){let t,n,o=1,s=0;if(i&&(s=i.currentLineIndex,o=i.totalLinesBetweenNodes),i)t=i.fromNode,n=i.toNode;else{const a=e;if(t=this.getFakeLineTarget(a.fromType,a.from,a),n=this.getFakeLineTarget(a.toType,a.to,a),!t){console.error("Invalid line configuration:error from:",e);return}if(!n){console.error("Invalid line configuration:error to:",e);return}}return this.generateLinePath({line:e,from:t,to:n,totalLinesBetweenNodes:o,currentLineIndex:s})}_getLineDefaultOptions(){const i=this.getOptions();return{layoutDirection:i.layout.layoutDirection,multiLineDistance:i.multiLineDistance,defaultJunctionPoint:i.defaultJunctionPoint,lineRadius:i.defaultPolyLineRadius,defaultLineJunctionOffset:i.defaultLineJunctionOffset,defaultNodeShape:i.defaultNodeShape}}generateLinePath(i){i.totalLinesBetweenNodes===void 0&&(i.totalLinesBetweenNodes=1),i.currentLineIndex===void 0&&(i.currentLineIndex=0),i.defaultOptions===void 0&&(i.defaultOptions=this._getLineDefaultOptions());try{const e=this.withLineJunctionPoints(i);return this.createLinePathData(e)}catch(e){if(e.rgError)return this.createErrorLineValue(e.errorCode,e.x,e.y);throw e}}throwLineError(i,e,t){return{rgError:!0,errorCode:i,x:e,y:t}}createErrorLineValue(i,e,t){const n={x:0,y:0,rotate:0},o=[{type:"M",x:0,y:0},{type:"l",dx:e,dy:t}];return{pathCommands:o,pathData:ae(o),textPosition:n,points:[]}}withLineJunctionPoints({line:i,from:e,to:t,totalLinesBetweenNodes:n,currentLineIndex:o,defaultOptions:s}){if(!e||!t)throw L("error from-to:",e,t),this.throwLineError("F",-10,0);let a=i.lineShape||1;const d=i.lineDirection||s.layoutDirection||"h";let h=e.x||0,c=e.y||0,f=t.x||0,p=t.y||0;if(Number.isNaN(h)||Number.isNaN(c))throw L("error start node:",e.text,e.x,e.y),this.throwLineError("A",-10,-10);if(Number.isNaN(f)||Number.isNaN(p))throw L("error end point:",t.text,t.x,t.y),this.throwLineError("B",10,-10);let m=e.el_W||60,u=e.el_H||60;if(Number.isNaN(m)||Number.isNaN(u))throw this.throwLineError("C",-10,10);let g=t.el_W||60,y=t.el_H||60;if(Number.isNaN(g)||Number.isNaN(y))throw this.throwLineError("D",10,10);if(h===0&&f===0&&c===0&&p===0)throw this.throwLineError("D",10,10);const v=f-h+(p-c)>0,x=i.isReverse?t:e,w=i.isReverse?e:t,k=Ce(x.nodeShape,s.defaultNodeShape),T=i.junctionOffset||s.defaultLineJunctionOffset||0;h-=T,c-=T,f-=T,p-=T,m+=T*2,u+=T*2,g+=T*2,y+=T*2;const O={from_x:h,from_y:c,to_x:f,to_y:p,f_W:m,f_H:u,t_W:g,t_H:y,nodeShape:k,isReverse:v,isEndPoint:!1,totalLinesBetweenNodes:n,currentLineIndex:o,lineDistance:s.multiLineDistance||30},b=Ce(w.nodeShape,s.defaultNodeShape),N={from_x:f,from_y:p,to_x:h,to_y:c,f_W:g,f_H:y,t_W:m,t_H:u,nodeShape:b,isReverse:v,isEndPoint:!0,totalLinesBetweenNodes:n,currentLineIndex:o,lineDistance:s.multiLineDistance||50},P=s.defaultJunctionPoint||W.border;let R=i.fromJunctionPoint||P,S=i.toJunctionPoint||P,M=i.fromJunctionPointOffsetX||0,C=i.fromJunctionPointOffsetY||0,E=i.toJunctionPointOffsetX||0,V=i.toJunctionPointOffsetY||0;i.isReverse&&([R,S]=[S,R],[M,C,E,V]=[E,V,M,C]),(e===t||h===0&&f===0&&c===0&&p===0)&&M===0&&C===0&&E===0&&V===0&&((a===Y.StandardStraight||a===Y.Curve2||a===Y.Curve3||a===Y.SimpleOrthogonal||a===Y.Curve5)&&(a=Y.StandardCurve),V=20);const X=this._getJunctionPoint(R,O);X.x+=M,X.y+=C;const A=this._getJunctionPoint(S,N);if(A.x+=E,A.y+=V,!X||!A)throw this.throwLineError("E",-20,-20);const G=h+m/2,$=c+u/2,J=f+g/2,ie=p+y/2;R==="horizontalLine"?(X.x=A.x,(a===44||a===49)&&(X.x+=(A.x>J?1:-1)*30)):R==="verticalLine"&&(X.y=A.y,(a===44||a===49)&&(X.y+=(A.y>ie?1:-1)*30)),S==="horizontalLine"?(A.x=X.x,(a===44||a===49)&&(A.x+=(X.x>G?1:-1)*30)):S==="verticalLine"&&(A.y=X.y,(a===44||a===49)&&(A.y+=(X.y>$?1:-1)*30));const te=X.x,ne=X.y,Q=A.x,Z=A.y;if(Number.isNaN(te)||Number.isNaN(ne))throw L("error start point:",e.text),this.throwLineError("F",-10,0);if(Number.isNaN(Q)||Number.isNaN(Z))throw L("error end point:",t.text),this.throwLineError("G",10,0);return{line:i,totalLinesBetweenNodes:n,currentLineIndex:o,lineDirection:d==="v"?"v":"h",lineShape:a,lineRadius:s.lineRadius||0,fromJunctionPoint:R,toJunctionPoint:S,fx:te,fy:ne,fcx:G,fcy:$,f_W:m,f_H:u,tx:Q,ty:Z,tcx:J,tcy:ie,t_W:g,t_H:y}}createLinePathData(i){const{lineShape:e}=i;let t;return e===Y.SimpleOrthogonal?t=Wn(i,void 0,this._getLineDefaultOptions()):e===Y.StandardOrthogonal?t=jn(i,void 0,this._getLineDefaultOptions()):e===Y.HardOrthogonal?t=qn(i,void 0,this._getLineDefaultOptions()):e===Y.StandardCurve?t=Zn(i):e===Y.Curve2||e===Y.Curve3||e===Y.Curve5||e===Y.Curve7?t=Kn(i):e===Y.Curve8?t=xo(i):t=Yn(i),t}getArrowMarkerId(i,e=!1){let t=i.showStartArrow===!0,n=i.showEndArrow!==!1;if(i.isReverse&&([t,n]=[n,t]),e){if(!t)return;if(i.startMarkerId)return`url('#${i.startMarkerId}')`}else{if(!n)return;if(i.endMarkerId)return`url('#${i.endMarkerId}')`}return`url('#${this.getLineArrow(i.color,e,!1)}')`}getLineArrow(i,e=!1,t=!1){const n=e?"start-":"";return`${this.getOptions().instanceId}-${n}arrow-default`}getTextTransform(i,e){if(!i||!e)return"translate(0,0)";const{x:t,y:n,rotate:o}=e;if(Number.isNaN(t)||Number.isNaN(n))return"translate(0,0)";const s=this.getOptions(),a=i.textOffsetX||s.defaultLineTextOffsetX||0,d=i.textOffsetY||s.defaultLineTextOffsetY||0,h=i.lineShape||1;return h===Y.StandardStraight||h===Y.SimpleOrthogonal?`translate(-50%, -50%) translate(${t+a}px,${n+d}px) rotate(${o||0}deg)`:`translate(-50%, -50%) translate(${t+a}px,${n+d}px)`}generateLineTextStyle(i,e){const t=this.getOptions(),n={transform:"",transformOrigin:"0 0"};if(!i||!e)return{cssStyles:n};const{line:o}=i,{textPosition:s}=e;if(!o||!s)return{cssStyles:n};let a=o.text||"";a.length>t.lineTextMaxLength&&(a=a.substring(0,t.lineTextMaxLength||15)+"...");const{x:d,y:h,rotate:c}=s;if(Number.isNaN(d)||Number.isNaN(h))return{text:a,cssStyles:n};const f=[],p=o.textAnchor||"center";p==="start"?f.push("translate(0%, -50%)"):p==="end"?f.push("translate(-100%, -50%)"):f.push("translate(-50%, -50%)"),f.push(`translate(${d}px,${h}px)`);const m=o.textOffsetX||t.defaultLineTextOffsetX||0,u=o.textOffsetY||t.defaultLineTextOffsetY||0,g=o.lineShape||1;return(o.useTextOnPath||t.defaultLineTextOnPath)&&g===1&&c&&f.push(`rotate(${c||0}deg)`),g===Y.StandardStraight?(n.transformOrigin="50% 50%",f.push(`translate(${m}px,${u}px)`)):f.push(`translate(${m}px,${u}px)`),n.transform=f.join(" "),{text:a,cssStyles:n}}generateLineTextStyle4TextOnPath(i){const{line:e,from:t,to:n}=i;let o=e.text;if(!o||!n||!t)return null;let s=0;const a=this.getOptions();o.length>a.lineTextMaxLength&&(o=o.substring(0,a.lineTextMaxLength||15)+"...");const d=e.textOffsetX||a.defaultLineTextOffsetX||0,h=e.textOffsetY||a.defaultLineTextOffsetY||0,c={x:d,y:h-6};let f="50%";e.placeText==="start"?(f="0%",c.x+=20):e.placeText==="end"?(f="100%",c.x-=20):e.placeText==="center"?f="50%":e.placeText&&(f=e.placeText);let p="middle";return e.textAnchor&&(p=e.textAnchor),{text:o,textOffset:c,textAnchor:p,onPathStartOffset:f,textRotate:s}}}class Lo extends Co{constructor(){super()}getClampedZoom(i){const e=this.getOptions();return Math.max(e.minCanvasZoom,Math.min(e.maxCanvasZoom,i))}applyZoom(i,e,t){if(this._rgAsConnectArea)return;const n=this.getOptions(),o=this.getClampedZoom(i),s=o-n.canvasZoom,a=e.x!==n.canvasOffset.x||e.y!==n.canvasOffset.y;if(!(s===0&&!a))try{const d=this.emitEvent(I.beforeZoomStart,n.canvasZoom,s,t);if(L("[zoom]","abortZoom:",d),d===!0)return;const h=n.canvasZoom;this._performanceModeLogicHook(h,o),this.dataProvider.updateOptions({canvasOffset:{x:e.x,y:e.y},canvasZoom:o}),this.emitEvent(I.onZoomEnd,o,h)}finally{this._updateEditingControllerView(),this._dataUpdated()}}zoom(i,e,t){if(this._rgAsConnectArea)return;const n=this.getOptions(),o=this.getViewBoundingClientRect(),s=this.getClampedZoom(n.canvasZoom+i);e||(e={x:o.x+o.width/2,y:o.y+o.height/2});const a=e.x-o.left,d=e.y-o.top,h=n.canvasZoom/100,c=s/100,f=a-(a-n.canvasOffset.x)*(c/h),p=d-(d-n.canvasOffset.y)*(c/h);this.applyZoom(s,{x:f,y:p},t)}setZoomAndOffset(i,e,t){this.applyZoom(i,e,t)}_performanceModeLogicHook(i,e){const t=this.getOptions();i<=40?e>40&&(t.performanceMode&&this.updateShouldRenderGraphData(!0),this.dataProvider.updateOptions({showEasyView:!1}),L("zoom:hide:showEasyView",i,e),this.updateElementLines()):i>40&&e<=40&&(L("zoom:show:showEasyView",i,e),t.performanceMode&&this.dataProvider.updateOptions({showEasyView:!0}))}setZoom(i,e){const t=this.getOptions(),n=i-t.canvasZoom;this.zoom(n,e)}}class wo extends Lo{constructor(){super()}fitContentHeight(i=20){this.dataProvider.updateOptions({canvasOpacity:.01}),this._dataUpdated();const e=this.getOptions(),t=this.getNodesRectBox(),n=t.height,o=t.width,s=e.viewSize.width-i*2,a=t.minX+t.width/2,d=t.minY+t.height/2;this.dataProvider.setCanvasCenter(a,d);const h=Math.min(1,s/o),c=n*h+i*2;this.dataProvider.updateOptions({viewSize:{...e.viewSize,height:c},viewHeight:c+"px"}),setTimeout(()=>{this.setZoom(h*100),this._moveToCenter(),this.dataProvider.updateOptions({canvasOpacity:1}),this._dataUpdated()},200)}_moveToCenter(i){const e=this.getNodesCenter(i);this.dataProvider.setCanvasCenter(e.x,e.y),this._dataUpdated()}setCanvasCenter(i,e){this.dataProvider.setCanvasCenter(i,e),this._dataUpdated()}zoomToFit(i){const e=this.getOptions(),t=this.getCanvasSlotRectItems(),n=t.length>0?[...t,...i||this.getNodes()]:i,o=this.getNodesRectBox(n),s=50,a=e.viewSize.width/(o.width+s*2),d=e.viewSize.height/(o.height+s*2),h=Math.min(a,d,1);L("zoomToFit:",{stuffSize:o,zoomPercent:h,zoomPercentX:a,zoomPercentY:d,viewSize:e.viewSize}),this._moveToCenter(n),this.setZoom(h*100),this._dataUpdated()}async zoomToFitWithAnimation(i){this.enableCanvasAnimation(),this.zoomToFit(i),await this.sleep(330),this.disableCanvasAnimation()}async moveToCenterWithAnimation(i){this.enableCanvasAnimation(),this.moveToCenter(i),await this.sleep(330),this.disableCanvasAnimation()}enableNodeXYAnimation(){this.dataProvider.updateOptions({enableNodeXYAnimation:!0}),this._dataUpdated()}disableNodeXYAnimation(){this.dataProvider.updateOptions({enableNodeXYAnimation:!1}),this._dataUpdated()}enableCanvasAnimation(){this.dataProvider.updateOptions({enableCanvasTransformAnimation:!0}),this._dataUpdated()}disableCanvasAnimation(){this.dataProvider.updateOptions({enableCanvasTransformAnimation:!1}),this._dataUpdated()}focusNodeById(i){const e=this.getNodeById(i);e&&this.focusNode(e)}focusRootNode(){throw new Error("focusRootNode is deprecated, please use focusNodeById instead.")}focusNode(i){L("checked:",i);const e=this.getOptions();this.setZoom(100);const t=i.width||50,n=i.height||50,o=i.x*-1+e.viewSize.width/2-t/2,s=i.y*-1+e.viewSize.height/2-n/2;this.dataProvider.setCanvasOffset(o,s),this.dataProvider.updateOptions({checkedNodeId:i.id})}}class _o extends fe{constructor(e,t,n){super(e,t,n);_(this,"rotate",0);_(this,"enableGatherNodes",!1);_(this,"layoutOptions");this.layoutOptions=e,L("new RGTreeLayout:",this.layoutOptions),this.layoutOptions.from||(this.layoutOptions.from="left"),this.layoutOptions.levelGaps||(this.layoutOptions.levelGaps=[]);const o=this.layoutOptions.from;o==="top"||o==="bottom"?(this.layoutOptions.treeNodeGapH||(this.layoutOptions.treeNodeGapH=10),this.layoutOptions.treeNodeGapV||(this.layoutOptions.treeNodeGapV=50)):(this.layoutOptions.treeNodeGapH||(this.layoutOptions.treeNodeGapH=50),this.layoutOptions.treeNodeGapV||(this.layoutOptions.treeNodeGapV=10)),o==="top"?(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="center"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="start"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.layoutOptions.alignItemsX),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.getReverseAlignItems(this.layoutOptions.alignItemsY))):(this.layoutOptions.alignItemsX||(this.layoutOptions.alignItemsX="start"),this.layoutOptions.alignItemsY||(this.layoutOptions.alignItemsY="start"),this.layoutOptions.alignParentItemsX||(this.layoutOptions.alignParentItemsX=this.getReverseAlignItems(this.layoutOptions.alignItemsX)),this.layoutOptions.alignParentItemsY||(this.layoutOptions.alignParentItemsY=this.layoutOptions.alignItemsY)),this.layoutOptions.ignoreNodeSize===void 0&&(this.layoutOptions.ignoreNodeSize=!1);const s=this.layoutOptions.layoutExpansionDirection,a=s==="start"||s==="left"||s==="top"?"start":s==="end"||s==="right"||s==="bottom"?"end":"center";this.layoutOptions.layoutExpansionDirection=a,this.layoutOptions.treeNodeGapH<100&&(this.layoutOptions.treeNodeGapH=100),this.layoutOptions.treeNodeGapV<10&&(this.layoutOptions.treeNodeGapV=10),(this.layoutOptions.from==="bottom"||this.layoutOptions.from==="right")&&(this.rotate=180),this.layoutOptions.changeNodeSizeDuringLayout===void 0&&(this.layoutOptions.changeNodeSizeDuringLayout=!1)}placeNodes(e,t){if(L("RGTreeLayout:placeNodes"),t)L("layout by root:",t);else{console.error("root is null");return}L("allNodes:",e.length),this.layoutOptions.alignItemsX,this.layoutOptions.alignItemsY,this.layoutOptions.alignParentItemsX,this.layoutOptions.alignParentItemsY,this.rootNode=t,this.allNodes=e,t.fixed||this.layoutOptions.fixedRootNode||this.updateNodePosition(t,0,0),t.lot.x=t.x,t.lot.y=t.y;const n=e;L("groupNodes:2:",n.length,n.map(s=>s.text).join(",")),this.rotate,this.networkAnalyzer.analyzeNetwork(n,this.rootNode,!1),this.placeNodesPosition(t,n);const o={x:t.x,y:t.y};this.allNodes.forEach(s=>{if(s.fixed!==!0&&!!z.isVisibleNode(s)&&(Number.isNaN(s.lot.x)&&(L("bad lot x:",s.text,s.lot.x),s.lot.x=0),Number.isNaN(s.lot.y)&&(L("bad lot y:",s.text,s.lot.y),s.lot.y=0),s!==t)){this.layoutOptions.from==="right"&&(s.lot.x=j.getFlippedX(s.lot.x,o.x)),this.layoutOptions.from==="bottom"&&(s.lot.y=j.getFlippedY(s.lot.y,o.y));const a=this.layoutOptions.from==="right"?z.getNodeXByLotX({alignItemsX:"end"},s):s.lot.x,d=this.layoutOptions.from==="bottom"?z.getNodeYByLotY({alignItemsY:"end"},s):s.lot.y;this.updateNodePosition(s,a,d)}});for(const s of this.allNodes)this.graphInstance.updateNode(s,{rgChildrenSize:s.lot.childs.length});L("create rootNode coordinates:1",t.x,t.y),this.layoutEnd()}placeNodesPosition(e,t){this.placeRelativePosition(e,t)}placeRelativePosition(e,t){e.lot.parent=void 0,e.lot.level=0;const n=[];this.buildNetwork([e],n,0);const o=Math.max(...n.map(h=>h.lot.level)),s=this.layoutOptions.from==="left"||this.layoutOptions.from==="right";this.reduceNodeRect(n,o,s),s?this.placeNodeChildrenH(n,0):this.placeNodeChildrenV(n,0);let a=e.lot.x-e.x,d=e.lot.y-e.y;this.layoutOptions.from==="right"&&(a+=e.lot.width),this.layoutOptions.from==="bottom"&&(d+=e.lot.height),n.forEach(h=>{h.fixed!==!0&&(h.lot.x-=a,h.lot.y-=d)})}buildNetwork(e,t,n){n===0&&t.push(...e);const o=[];e.forEach(s=>{if(!z.isVisibleNode(s))return;const a=this.graphInstance.getNodeIncomingNodes(s).filter(z.isVisibleNode),h=this.graphInstance.getNodeOutgoingNodes(s).filter(z.isVisibleNode).filter(f=>!t.includes(f));t.push(...h);const c=a.filter(f=>!t.includes(f));t.push(...c),s.lot.level=n,s.lot.toNodes=h,s.lot.fromNodes=c;for(const f of c.concat(h))f.lot.parent=s,o.includes(f)||o.push(f)}),o.length>0&&this.buildNetwork(o,t,n+1)}reduceNodeRect(e,t,n=!1){let o=this.layoutOptions.treeNodeGapH,s=this.layoutOptions.treeNodeGapV;const a=o,d=s,h=e.filter(c=>c.lot.level===t);for(const c of h){if(!z.isVisibleNode(c))continue;let f=c.width||c.el_W||50,p=c.height||c.el_H||50;if(c.lot.width=f,c.lot.height=p,c.lot.toNodes.length===0&&c.lot.fromNodes.length===0)c.lot.width_with_childs=f,c.lot.height_with_childs=p;else if(n){let m=0,u=0;for(const v of c.lot.fromNodes)v.lot.height_with_childs>u&&(u=v.lot.height_with_childs),m+=v.lot.width_with_childs+d;let g=0,y=0;for(const v of c.lot.toNodes)v.lot.height_with_childs>y&&(y=v.lot.height_with_childs),g+=v.lot.width_with_childs+d;this.layoutOptions.changeNodeSizeDuringLayout&&(p=0),p=Math.max(u+a/2,p/2)+Math.max(y+a/2,p/2),c.lot.width_with_childs=f+Math.max(m,g)+d,c.lot.height_with_childs=p}else{let m=0,u=0;for(const v of c.lot.fromNodes)v.lot.width_with_childs>m&&(m=v.lot.width_with_childs),u+=v.lot.height_with_childs+d;let g=0,y=0;for(const v of c.lot.toNodes)v.lot.width_with_childs>g&&(g=v.lot.width_with_childs),y+=v.lot.height_with_childs+d;this.layoutOptions.changeNodeSizeDuringLayout&&(f=0),f=Math.max(m+a/2,f/2)+Math.max(g+a/2,f/2),c.lot.width_with_childs=f,c.lot.height_with_childs=p+Math.max(u,y)+d}}t>=0&&this.reduceNodeRect(e,t-1,n)}placeNodeChildrenV(e,t){const n=this.layoutOptions.treeNodeGapH,o=this.layoutOptions.treeNodeGapV,s=n,a=o;let d=0;const h=e.filter(c=>c.lot.level===t);for(const c of h){d++;let f=c.lot.width;this.layoutOptions.changeNodeSizeDuringLayout&&(f=0),t===0&&(c.lot.groupStartX=c.lot.x+f/2-c.lot.width_with_childs/2);const p=c.lot.groupStartX,m=c.lot.y;let u=0,g=0;for(const v of c.lot.fromNodes)v.lot.width_with_childs>u&&(u=v.lot.width_with_childs);for(const v of c.lot.toNodes)v.lot.width_with_childs>g&&(g=v.lot.width_with_childs);const y=p+Math.max(u+s/2,f/2);if(c.lot.fromNodes.length>0){let v=c.lot.height+a;for(const x of c.lot.fromNodes)x.lot.groupStartX=y-x.lot.width_with_childs-s/2,x.lot.y=m+v+a,v+=x.lot.height_with_childs+a}if(c.lot.toNodes.length>0){let v=c.lot.height+a;for(const x of c.lot.toNodes)x.lot.groupStartX=y+s/2,x.lot.y=m+v+a,v+=x.lot.height_with_childs+a}u>0||g>0?this.layoutOptions.changeNodeSizeDuringLayout?(c.lot.x=p,c.width=c.lot.width_with_childs):c.lot.x=y-c.lot.width/2:c.lot.x=p}d>0&&this.placeNodeChildrenV(e,t+1)}placeNodeChildrenH(e,t){const n=this.layoutOptions.treeNodeGapH,o=this.layoutOptions.treeNodeGapV,s=n,a=o;let d=0;const h=e.filter(c=>c.lot.level===t);for(const c of h){d++;let f=c.lot.height;this.layoutOptions.changeNodeSizeDuringLayout&&(f=0),t===0&&(c.lot.groupStartY=c.lot.y+f/2-c.lot.height_with_childs/2);const p=c.lot.groupStartY,m=c.lot.x;let u=0,g=0;for(const v of c.lot.fromNodes)v.lot.height_with_childs>u&&(u=v.lot.height_with_childs);for(const v of c.lot.toNodes)v.lot.height_with_childs>g&&(g=v.lot.height_with_childs);const y=p+Math.max(u+s/2,f/2);if(c.lot.fromNodes.length>0){let v=c.lot.width+a;for(const x of c.lot.fromNodes)x.lot.groupStartY=y-x.lot.height_with_childs-s/2,x.lot.x=m+v+a,v+=x.lot.width_with_childs+a}if(c.lot.toNodes.length>0){let v=c.lot.width+a;for(const x of c.lot.toNodes)x.lot.groupStartY=y+s/2,x.lot.x=m+v+a,v+=x.lot.width_with_childs+a}u>0||g>0?this.layoutOptions.changeNodeSizeDuringLayout?(c.lot.y=p,c.height=c.lot.height_with_childs):c.lot.y=y-c.lot.height/2:c.lot.y=p}d>0&&this.placeNodeChildrenH(e,t+1)}getLevelDistance(e,t,n){if(e===0)return 0;if(e>0){let o=0;for(let s=0;s<e;s++){const a=t.get(s);o+=a+this.getLevelGap(s,n,a,e)}return o}else{let o=0;for(let s=0;s>e;s--){const a=t.get(s);o+=a+this.getLevelGap(s,n,a,e)}return-o}}getLevelGap(e,t,n,o){let s=t+(o===-1&&e===0?n/2:0);if(this.layoutOptions.levelGaps.length>0){const a=this.layoutOptions.levelGaps[Math.abs(e)];a&&(s=a)}return s}}const No=_o;class bo extends wo{constructor(){super();_(this,"_layoutTimer",null);_(this,"_layoutPromise",null);_(this,"_layoutResolve",null);_(this,"layoutor")}async doLayout(e){const t=Date.now()-this.prevAddNodeTimestamp;return t<300&&(this.dataProvider.updateOptions({canvasOpacity:.01}),this._dataUpdated(),await Ee(300-t)),this._layoutPromise||(this._layoutPromise=new Promise(n=>{this._layoutResolve=n})),clearTimeout(this._layoutTimer),this._layoutTimer=setTimeout(async()=>{var n;try{await this._doLayout(e),this.dataProvider.updateOptions({canvasOpacity:1}),this._dataUpdated()}finally{(n=this._layoutResolve)==null||n.call(this),this._layoutResolve=null,this._layoutPromise=null}},50),this._layoutPromise}async _doLayout(e){this.updateNodesVisibleProperty();const t=this.getNodes();L("node size\uFF1A",t.length);let n=this.dataProvider.getRootNode();if(e&&(n=typeof e=="string"?this.getNodeById(e):e),n||(n=t[0],this._rgAsConnectArea||(L("[relation-graph]No root node, use first node as root:",n),L("[relation-graph]You can set rootNode call doLayout(rootNode | nodeId) with a node id"))),!n)throw new Error("custom rootNode not found, id:"+e);const o=this.getOptions();this.dataProvider.setRootNodeId(n?n.id:""),this.stopAutoLayout();const s=this.createLayout(o.layout,!0);if(s.layoutOptions.layoutName==="force")s.isMainLayouer=!0,s.onFinish(()=>{this.emitEvent(I.onForceLayoutFinish)}),await Ee(100),L("doLayout:start force:",t.length),s.placeNodes(t,n);else{this.enableNodeXYAnimation();let a=[];n&&(a=this.getNetworkNodesByNode(n),s.placeNodes(a,n)),L("doLayout:placeOtherNodes:all:",t.length,"mainGroupNodes:",a.length),this.placeOtherNodes(a),setTimeout(()=>{this.disableNodeXYAnimation()},300),L("doLayout:placeOtherNodes ok!")}t.forEach(a=>this.dataProvider.updateNode(a.id,{x:a.x||0,y:a.y||0,rgChildrenSize:a.rgChildrenSize||0})),this.updateElementLines()}async refresh(e=!0){this.resetViewSize(!0),this._dataUpdated(),e&&await this.doLayout(),this.updateElementLines(),this._dataUpdated()}placeOtherNodes(e=[]){const t=this.getOptions();if(t.layout.layoutName==="fixed"||!t.placeOtherGroup)return;const o=[],s=[],a=this.getNodes();a.forEach(h=>{if(h.fixed===!0||e.includes(h))return;this.getNodeRelatedNodes(h).length===0?s.push(h):o.push(h)}),L("doLayout:allNodes:",a.length),L("doLayout:mainGroupNodes:",e.length),L("doLayout:notInMainGroupNodes:",o.length),L("doLayout:singleNodes:",s.length);const d=[{nodes:e}];this.placeNextNetwork(o,[...e],d),this.placeSingleNodes(s),d.push({nodes:s}),this.sortGroups(d),this._dataUpdated()}placeSingleNodes(e){if(e.length>0){const t=Math.ceil(Math.sqrt(e.length));rt(t,30,e.map(o=>({width:o.el_W,height:o.el_H,node:o})),(o,s,a)=>{const d=o.node;d.x=s,d.y=a,d.lot||(d.lot={childs:[]})}),L("[placeSingleNodes]Single nodes:",e.length)}}sortGroups(e){L("[placeSingleNodes]sortGroups groupList:",e.length,e.map(s=>s.nodes.length));const t=e.map(s=>{const a=this.getNodesRectBox(s.nodes);return{width:a.width,height:a.height,nodes:s.nodes,orignX:a.minX,orignY:a.minY}});if(t.length===0)return;const n=Math.floor(Math.sqrt(t.length))||1;rt(n,100,t,(s,a,d)=>{const h=a-s.orignX,c=d-s.orignY;L(`[placeNextNetwork]Move ${s.nodes.length} Nodes :`,h,c,s," > ");for(const f of s.nodes)this.updateNodePosition(f,f.x+h,f.y+c)},t[0].orignX,t[0].orignY)}placeNextNetwork(e,t,n){if(e.length>0){const o=this.getOptions();L("[placeNextNetwork]notPlacedNodes nodes:",e.length);const s=JSON.parse(JSON.stringify(o.layout)),a=e[0],d=this.createLayout(s);if(d.isMainLayouer=!1,L("[placeNextNetwork]layoutName:",d.layoutOptions.layoutName,"root:",a.text),d.layoutOptions.layoutName==="force"){const f=d;f.maxLayoutTimes=0}a.fixed?L("[placeNextNetwork]fixed root x,y:",a.x,a.y,a.text):(this.updateNodePosition(a,0,0),L("[placeNextNetwork]set root x,y:",a.x,a.y,a.text)),d.layoutOptions.fixedRootNode=!0;const h=this.getNetworkNodesByNode(a);L("[placeNextNetwork]thisNetworkNodes:",e.length),d.placeNodes(h,a),t.push(...h),n.push({nodes:h});const c=[];e.forEach(f=>{t.includes(f)||c.push(f)}),o.placeOtherGroup&&this.placeNextNetwork(c,t,n),this._dataUpdated()}else L("[placeOtherGroup]thisGroupNodes:all is OK!")}toggleAutoLayout(){const e=this.getOptions();L("toggleAutoLayout:to:",e.layout.autoLayouting),e.layout.autoLayouting?this.stopAutoLayout():this.startAutoLayout()}startAutoLayout(){var e;(e=this.layoutor)!=null&&e.start&&(L("Start force layout:"+this.layoutor.instanceId),this.layoutor.start())}stopAutoLayout(){var e;(e=this.layoutor)!=null&&e.stop&&(L("Stop force layout:"+this.layoutor.instanceId),this.layoutor.stop())}createLayout(e,t=!1){L("########createLayout:",e);const n=this.getOptions();xt(e);let o=null;if(e.layoutName==="tree"?o=new lt(e,n,this):e.layoutName==="center"?o=new dt(e,n,this):e.layoutName==="circle"?o=new ct(e,n,this):e.layoutName==="force"?o=new ke(e,n,this):e.layoutName==="fixed"?o=new ht(e,n,this):e.layoutName==="smart-tree"?o=new Fn(e,n,this):e.layoutName==="io-tree"?o=new No(e,n,this):e.layoutName==="folder"&&(o=new ft(e,n,this)),!o)throw new Error("unknown layout: "+e.layoutName);return L("########supportAutoLayout:",o.autoLayout!==void 0,e.disableAsForceLayout),this.setLayoutor(o,t,o.autoLayout!==void 0&&e.disableAsForceLayout!==!0),o}setLayoutor(e,t,n=!1){e.isMainLayouer=t,e.layoutOptions.fixedRootNode=!0,t&&(this.layoutor=e,this._updateOptions({layout:{supportAutoLayout:n}}))}}const ko=async(l,i)=>{const e=l||document.documentElement;i?await Oo(e):await Po()},Oo=async l=>{l.requestFullscreen?await l.requestFullscreen():l.mozRequestFullScreen?await l.mozRequestFullScreen():l.webkitRequestFullscreen?await l.webkitRequestFullscreen():l.msRequestFullscreen&&await l.msRequestFullscreen()},Po=async()=>{document.exitFullscreen?await document.exitFullscreen():document.mozCancelFullScreen?await document.mozCancelFullScreen():document.webkitExitFullscreen?await document.webkitExitFullscreen():document.msExitFullscreen&&await document.msExitFullscreen()};class To extends bo{constructor(){super();_(this,"_prevClickNodeTime",0);_(this,"_nodeXYMappingBeforeDrag",{});_(this,"canvasAutoMoving",e=>{const t=this.getOptions(),n=t.viewSize,o=40;let s=0,a=0;e.x<o?s=o-e.x:n.width-o<e.x&&(s=n.width-o-e.x),e.y<o?a=o-e.y:n.height-o<e.y&&(a=n.height-o-e.y);const d=s!==0||a!==0;d&&(s=Math.max(Math.min(s/5,30),-30),a=Math.max(Math.min(a/5,30),-30));const h=t.canvasOffset.x+s,c=t.canvasOffset.y+a;return this.onCanvasDragging(h,c,s,a),d});_(this,"_canvasMovingTimer");_(this,"_relayoutTaskTimer");_(this,"_onMovingWhenCreatingLine");_(this,"_step1EventTime",0);_(this,"_onCreateLineCallback");_(this,"_mouseWheelTimer");_(this,"_mouseWheelEventPrevApplyTime",0);_(this,"_mouseWheelForce",{x:0,y:0});_(this,"_fullscreenchangeHandler")}onNodeClick(e,t){if("button"in t&&t.button===2)return;if(Date.now()-this._prevClickNodeTime<200){L("[node]click abort : time < 200");return}this._prevClickNodeTime=Date.now();const n=this.getOptions();if(n.creatingLinePlot){this.onNodeClickWhenCreatingLinePlot(e);return}const o=e.disablePointEvent===void 0?n.disableNodePointEvent:e.disablePointEvent;L("[node]node click",e.text,n.creatingLinePlot,o),!t.shiftKey&&!o&&(n.checkedLineId="",this.dataProvider.updateOptions({checkedLineId:"",checkedNodeId:e.id})),this.emitEvent(I.onNodeClick,e,t),this._prevClickNodeTime=Date.now()}onNodeDragStart(e,t){if(!e||ge(t))return;const n=this.getOptions();if((e.disableDrag||n.disableDragNode)&&!(t.target&&t.target.closest(".rg-node-drag-handler"))){const g=y=>{this.onNodeClick(e,y),document.body.removeEventListener("mouseup",g)};document.body.addEventListener("mouseup",g);return}isNaN(e.x)&&(e.x=0),isNaN(e.y)&&(e.y=0),this.dataProvider.setEditingLine(null),this.dataProvider.updateOptions({checkedLineId:""});let s=!1;const a=(u,g,y)=>{y.stopPropagation(),s=!0,this._canvasMovingTimer&&cancelAnimationFrame(this._canvasMovingTimer),this.dataProvider.updateOptions({draggingNodeId:"",editingReferenceLine:{...n.editingReferenceLine,show:!1}}),this._onNodeDragEnd(e,u,g,y),c?this.emitEvent(I.onNodeDragEnd,e,y,u,g):this.onNodeClick(e,t),this._dataUpdated()};this._nodeXYMappingBeforeDrag={},this._nodeXYMappingBeforeDrag[e.id]={x:e.x,y:e.y};for(const u of n.editingController.nodes)this._nodeXYMappingBeforeDrag[u.id]={x:u.x,y:u.y};const d=this.getCanvasXyByViewXy(this.getViewXyByEvent(t)),h={x:e.x,y:e.y};let c=!1;this._canvasMovingTimer&&cancelAnimationFrame(this._canvasMovingTimer);let f;const p=()=>{if(!f||s)return;const u=this.getViewXyByEvent(f),g=this.getCanvasXyByViewXy(u),y=g.x-d.x,v=g.y-d.y;let x=y+h.x,w=v+h.y,k=x-h.x,T=w-h.y;const O=this.emitEvent(I.onNodeDragging,e,x,w,k,T,f);O&&(typeof O.x=="number"&&(x=O.x,k=x-h.x),typeof O.y=="number"&&(w=O.y,T=w-h.y)),this.canvasAutoMoving(u),this.draggingSelectedNodes(e,x,w,k,T),this._dataUpdated()},m=()=>{p(),this._canvasMovingTimer=requestAnimationFrame(m)};le.startDrag(t,h,a,(u,g,y,v,x)=>{c?f=x:Math.abs(u)+Math.abs(g)>4&&(L("[node]onNodeDragStart...",de(x),x),this.emitEvent(I.onNodeDragStart,e,x),c=!0,this.dataProvider.updateOptions({draggingNodeId:e.id}),this._canvasMovingTimer=requestAnimationFrame(m)),this.updateElementLines(),this._dataUpdated()})}_onNodeDragEnd(e,t,n,o){this.updateElementLines()}onLineClick(e,t){if("button"in t&&t.button===2)return;const n=this.getLinkByLineId(e.id);L("onLineClick:","line:",e,"link:",n);const o=this.getOptions();(e.disablePointEvent===void 0?o.disableLinePointEvent:e.disablePointEvent)||(this.setCheckedNode(""),this.setCheckedLine(e)),this.emitEvent(I.onLineClick,e,n,t),this._dataUpdated()}expandOrCollapseNode(e,t){t.stopPropagation(),e.expanded===!1?this.expandNode(e,t):this.collapseNode(e,t)}expandNode(e,t){L("onNodeExpand:",e),this.dataProvider.updateNode(e.id,{expanded:!0}),this._effectWhenExpandedOrCollapsed(e),this.emitEvent(I.onNodeExpand,e,t)}collapseNode(e,t){L("onNodeCollapse:",e),this.dataProvider.updateNode(e.id,{expanded:!1}),this._effectWhenExpandedOrCollapsed(e),this.emitEvent(I.onNodeCollapse,e,t)}_effectWhenExpandedOrCollapsed(e){const t=this.getDescendantNodes(e);this.updateNodesVisibleProperty([e].concat(t)),this._relayoutTaskTimer&&clearTimeout(this._relayoutTaskTimer),this._relayoutTaskTimer=setTimeout(()=>{this.updateElementLines(),this._dataUpdated();const n=this.getOptions();n.reLayoutWhenExpandedOrCollapsed&&(n.layout.layoutName==="force"?this.startAutoLayout():this.doLayout())},100)}onCanvasDragEnd(e){this._updateEditingControllerView(),this.updateShouldRenderGraphData(),this._dataUpdated(),this.emitEvent(I.onCanvasDragEnd,e)}onCanvasClick(e){if("button"in e&&e.button===2)return;if(this.getOptions().creatingLinePlot)this.onCanvasClickWhenCreatingLinePlot(e);else{if(this.dataProvider.isPerformanceMode()){const n=this.getNodeAtEvent(e);if(n){this.emitEvent(I.onNodeClick,n,e);return}}this.emitEvent(I.onCanvasClick,e)}}getNodeAtEvent(e){const t=this.getCanvasXyByClientXy(e);return this.dataProvider.findNodeByXy(t)}onCanvasSelectionEnd(e,t){this.emitEvent(I.onCanvasSelectionEnd,e,t),L("[canvas]onCanvasSelectionEnd:",e),this._dataUpdated()}startCreatingNodePlot(e,t){if(!t)throw new Error("startCreatingNodePlot need setting param");if(!t.onCreateNode)throw new Error("startCreatingNodePlot need setting.onCreateNode param as callback");const n=we(JSON.parse(JSON.stringify(De)),this.getOptions()),o=de(e);this.dataProvider.updateOptions({newNodeTemplate:Object.assign({},n,t.templateNode),creatingNodePlot:!0,showTemplateNode:!o});let s=(u,g)=>{const y=this.getOptions().newNodeTemplate,v={width:y.width||50,height:y.height||50};this.dataProvider.updateOptions({newNodeTemplate:{...y,x:u-v.width/2,y:g-v.height/2}}),this._dataUpdated()};const a=this.getViewBoundingClientRect();L("[CreatingNodePlot]startCreatingNodePlot:");const d=ce(e),h=d.clientX-a.x+10,c=d.clientY-a.y+10;o||s(h,c);const f=u=>{L("[CreatingNodePlot]objectTemplateMove");const g=this.getViewXyByEvent(u);t.templateMove&&t.templateMove(g.x,g.y),s(g.x,g.y)},p=u=>{L("[CreatingNodePlot]user abort!"),this.$dom.removeEventListener("mousemove",f),this.$dom.removeEventListener("click",m),this.$dom.removeEventListener("contextmenu",p),this.dataProvider.updateOptions({creatingNodePlot:!1})},m=u=>{let g=!1;if(this.getOptions().creatingNodePlot||(g=!0),this.$dom.removeEventListener("mousemove",f),this.$dom.removeEventListener("click",m),this.$dom.removeEventListener("contextmenu",p),this.dataProvider.updateOptions({creatingNodePlot:!1}),g){L("[CreatingNodePlot]action be abort!");return}const y=ce(u),v=y.clientX-a.x+10,x=y.clientY-a.y+10;if(Math.abs(h-v)<30&&Math.abs(c-x)<30){L("[CreatingNodePlot]create node be abort!");return}const w=this.getCanvasXyByClientXy({x:y.clientX,y:y.clientY});L("[CreatingNodePlot]objectBePlaced:",w),t.onCreateNode(w.x,w.y,this.getOptions().newNodeTemplate),this._dataUpdated()};setTimeout(()=>{this.$dom.addEventListener("click",m),this.$dom.addEventListener("contextmenu",p)},300),o||this.$dom.addEventListener("mousemove",f)}startCreatingLinePlot(e,t){const n=de(e);t&&t.onCreateLine&&(this._onCreateLineCallback=t.onCreateLine);const o=he({from:"newRelationTemplate-from",to:"newRelationTemplate-to",color:"",text:""},this.getOptions());t&&t.template&&Object.assign(o,t.template),this.dataProvider.updateOptions({newLineTemplate:Object.assign(o,{isReverse:t.isReverse||!1})}),this.dataProvider.updateOptions({newLineTemplate:Object.assign(o,{isReverse:t.isReverse||!1,disablePointEvent:!0}),creatingLinePlot:!0});const s=Object.assign({},this.getOptions().newLinkTemplate,{fromNode:null,toNode:{id:"",targetType:D.Node,x:0,y:0,el_W:2,el_H:2},toNodeObject:null});t&&t.fromNode&&(s.toNode.x=t.fromNode.x+50,s.toNode.y=t.fromNode.y+50,s.fromNode=t.fromNode,this._step1EventTime=Date.now()),this.dataProvider.updateOptions({newLinkTemplate:s}),L("[CreatingLinePlot]startCreatingLinePlot:isTouchEvent:",n),n||(L("[CreatingLinePlot]Listener move"),this._onMovingWhenCreatingLine&&this.$dom.removeEventListener("mousemove",this._onMovingWhenCreatingLine),this._onMovingWhenCreatingLine=this.onMovingWhenCreatingLinePlot.bind(this),this.$dom.addEventListener("mousemove",this._onMovingWhenCreatingLine)),this._dataUpdated()}stopCreatingLinePlot(){L("[CreatingLinePlot]stop CreatingLinePlot!"),this.dataProvider.updateOptions({creatingLinePlot:!1,newLinkTemplate:{...this.getOptions().newLinkTemplate,fromNode:null,toNodeObject:null},nodeConnectController:{...this.getOptions().nodeConnectController,show:!1}}),this._onCreateLineCallback=void 0,this.$dom.removeEventListener("mousemove",this._onMovingWhenCreatingLine),this._onMovingWhenCreatingLine=void 0,this._dataUpdated()}onMovingWhenCreatingLinePlot(e){L("[CreatingLinePlot]mousemove");const t=this.getCanvasXyByClientXy({x:e.clientX,y:e.clientY}),n=this.getOptions(),o=e.target;let s="",a=D.Node;const d=this.isNode(o);let h=!1,c={x:0,y:0,el_W:5,el_H:5,nodeShape:0};d&&(s=d.id,d===this.getOptions().newLinkTemplate.fromNode?this.dataProvider.updateOptions({nodeConnectController:{...this.getOptions().nodeConnectController,show:!1}}):(this.dataProvider.updateOptions({nodeConnectController:{...this.getOptions().nodeConnectController,node:d,show:!0}}),this._updateEditingConnectControllerView()));const f=o.closest(".rg-connect-ctl-handler");if(f){let p=this.getOptions().nodeConnectController.node;L("[CreatingLinePlot]content point:",f.dataset.point);let m=f.dataset.point||"border";if(f.classList.contains("rg-connect-target")){const{width:u,height:g,x:y,y:v}=f.getBoundingClientRect(),x=this.getCanvasXyByClientXy({x:y,y:v}),w=this.dataProvider.getCanvasScale(),k={x:x.x,y:x.y,el_W:u/w,el_H:g/w,nodeShape:1,id:f.dataset.targetId,targetData:JSON.parse(f.dataset.targetData||"{}"),targetType:f.dataset.targetType};h=!0,c.x=k.x,c.y=k.y,c.el_W=k.el_W,c.el_H=k.el_H,c.nodeShape=k.nodeShape,this.dataProvider.updateOptions({nodeConnectController:{...this.getOptions().nodeConnectController,node:k,show:!1}}),m=f.dataset.point,n.newLinkTemplate.toNode&&(s=k.id,a=k.targetType,this.dataProvider.updateOptions({newLinkTemplate:{...this.getOptions().newLinkTemplate,toNode:{...this.getOptions().newLinkTemplate.toNode,nodeShape:k.nodeShape}}})),this._updateEditingConnectControllerView()}else p&&(a=D.Node,h=!0,c.x=p.x,c.y=p.y,c.el_W=p.el_W,c.el_H=p.el_H,c.nodeShape=p.nodeShape,o.dataset.innode==="true"&&(c.x=t.x,c.y=t.y,c.el_W=2,c.el_H=2,c.nodeShape=1));n.newLineTemplate.isReverse?this.dataProvider.updateOptions({newLineTemplate:{...this.getOptions().newLineTemplate,fromJunctionPoint:m}}):this.dataProvider.updateOptions({newLineTemplate:{...this.getOptions().newLineTemplate,toJunctionPoint:m}})}else L("[CreatingLinePlot]point:",o.dataset.point),n.newLineTemplate.isReverse?this.dataProvider.updateOptions({newLineTemplate:{...this.getOptions().newLineTemplate,fromJunctionPoint:W.border}}):this.dataProvider.updateOptions({newLineTemplate:{...this.getOptions().newLineTemplate,toJunctionPoint:W.border}}),n.newLinkTemplate.toNode&&(a=D.Node);n.newLinkTemplate.toNode&&(s&&this.dataProvider.updateOptions({newLinkTemplate:{...this.getOptions().newLinkTemplate,toNode:{...this.getOptions().newLinkTemplate.toNode,id:s}}}),this.dataProvider.updateOptions({newLinkTemplate:{...this.getOptions().newLinkTemplate,toNode:{...this.getOptions().newLinkTemplate.toNode,targetType:a}}})),n.newLinkTemplate.fromNode&&this.dataProvider.updateOptions({newLinkTemplate:{...this.getOptions().newLinkTemplate,toNode:{...this.getOptions().newLinkTemplate.toNode,x:h?c.x:t.x,y:h?c.y:t.y,el_W:c.el_W,el_H:c.el_H,nodeShape:c.nodeShape}}}),this._dataUpdated()}onCanvasClickWhenCreatingLinePlot(e){if(Date.now()-this._step1EventTime<500){L("[CreatingLinePlot]step1EventTime:",this._step1EventTime);return}const t=this.getOptions();if(!t.newLinkTemplate.fromNode){L("[CreatingLinePlot]CreatingLinePlot:fromNode not set!");return}let n=!1;if(!t.newLinkTemplate.toNodeObject){L("[CreatingLinePlot]CreatingLinePlot:toNodeObject not set!");const o=ce(e),s=this.getCanvasXyByClientXy({x:o.clientX,y:o.clientY});n=this.onReadyToCreateLine(t.newLinkTemplate.fromNode,s)}n!==!0&&this.stopCreatingLinePlot()}onNodeClickWhenCreatingLinePlot(e){const t=this.getOptions();t.newLinkTemplate.fromNode?(L("[CreatingLinePlot]step 2: set toNodeObjecct:",t.newLinkTemplate.fromNode,e),this.dataProvider.updateOptions({newLinkTemplate:{...t.newLinkTemplate,toNodeObject:e}}),this.onReadyToCreateLine(t.newLinkTemplate.fromNode,e)!==!0&&this.stopCreatingLinePlot()):(L("[CreatingLinePlot]step 1: set fromNode:",e),this.dataProvider.updateOptions({newLinkTemplate:{...t.newLinkTemplate,fromNode:e,toNode:{...t.newLinkTemplate.toNode,x:e.x+50,y:e.y+50}}}),this._step1EventTime=Date.now())}onReadyToCreateLine(e,t){L("[CreatingLinePlot][fire-event]onCreateLine:",e,t);const n=this.getOptions(),o=he(n.newLineTemplate,this.getOptions());n.newLineTemplate.isReverse?(o.from=t?t.id:"",o.to=e?e.id:"",o.isReverse=void 0,[e,t]=[t,e]):(o.from=e?e.id:"",o.to=t?t.id:""),o.disablePointEvent=!1;const s=this.emitEvent(I.beforeCreateLine,{lineJson:o,fromNode:e,toNode:t});if(L("[CreatingLinePlot]onCreateLine:abort-flag:",s),s===!0){L("[CreatingLinePlot]onCreateLine:abort!");return}if(this._onCreateLineCallback){L("[CreatingLinePlot]onCreateLine:callback");try{this._onCreateLineCallback(e,t,o)}catch(d){return console.warn("[Custom Reject Connect By Throw Error:",d),!1}}return L("[CreatingLinePlot]onCreateLine:emitEvent"),this.emitEvent(I.onLineBeCreated,{lineJson:o,fromNode:e,toNode:t})}onContextmenu(e){e.stopPropagation(),e.preventDefault(),this.stopCreatingLinePlot();let t="canvas",n=this.isNode(e.target);n?t="node":(n=this.isLine(e.target),n&&(t="line")),L("contextmenu:objectType",t,n);const o=ce(e),s=this.getCanvasXyByClientXy({x:o.clientX,y:o.clientY}),a=this.getViewXyByCanvasXy(s);this.emitEvent(I.onContextmenu,e,t,n,s,a)}async fullscreen(e){const t=this.getOptions();if(e!==void 0&&e===t.fullscreen)return;L("fullscreen:newValue:",e),e===void 0&&(e=!t.fullscreen);let n=this.$dom;t.fullscreenElementXPath&&(n=document.querySelector(t.fullscreenElementXPath)||this.$dom),await ko(n,e),this.dataProvider.updateOptions({fullscreen:e}),this.emitEvent(I.onFullscreen,e),this._dataUpdated()}onMouseWheel(e){const t=this.getOptions();if(!e.ctrlKey&&!e.metaKey&&(t.disableWheelEvent||t.wheelEventAction==="none"))return!0;try{e.preventDefault(),e.stopPropagation()}catch{}let{deltaX:n,deltaY:o,deltaMode:s}=e;s===1?(n*=40,o*=40):s===2&&(n*=800,o*=800),this._mouseWheelForce.x+=n,this._mouseWheelForce.y+=o,this._applyWheelEvent(e)}_applyWheelEvent(e){clearTimeout(this._mouseWheelTimer),this._mouseWheelTimer=setTimeout(()=>{const t=this._mouseWheelForce.x,n=this._mouseWheelForce.y;this._onMouseWheel(e,t,n),this._mouseWheelForce.x-=t,this._mouseWheelForce.y-=n,this._mouseWheelEventPrevApplyTime=Date.now(),(Math.abs(this._mouseWheelForce.x)>1||Math.abs(this._mouseWheelForce.y)>1)&&this._applyWheelEvent(e)},Date.now()-this._mouseWheelEventPrevApplyTime>50?0:50)}_onMouseWheel(e,t,n){const o=e.ctrlKey||e.metaKey,s=this.getOptions();if(!o&&s.wheelEventAction==="scroll"){let a=Math.max(Math.abs(t),Math.abs(n));const d=t/a,h=n/a;a>200&&(a=200);const c=s.mouseWheelSpeed/10*-d*a,f=s.mouseWheelSpeed/10*-h*a,p=this.emitEvent(I.beforeScrollStart,c,f,e);if(L("[scroll]","abortScroll:",p),p===!0)return;this.scrollView(c,f)}else if(!(!o&&s.wheelEventAction==="none")){const a={x:e.clientX,y:e.clientY};let d=s.mouseWheelSpeed/20*-n;d=Math.max(Math.min(d,20),-20),this.zoom(d,a,e)}}scrollView(e,t){const n=this.getOptions();this.dataProvider.setCanvasOffset(n.canvasOffset.x+e,n.canvasOffset.y+t),this._updateEditingControllerView(),this.updateShouldRenderGraphData(),this._dataUpdated()}onLineDragStart(e,t){L("onLineDragStart...");const n=this.getLinkByLine(e),o={x:n.fromNode.x,y:n.fromNode.y},s={x:n.toNode.x,y:n.toNode.y},a=(d,h,c,f,p)=>{const m=this.dataProvider.getCanvasScale();n.fromNode.x=o.x+d/m,n.fromNode.y=o.y+h/m,n.toNode.x=s.x+d/m,n.toNode.y=s.y+h/m,this._updateEditingControllerView(),this._dataUpdated()};le.startDrag(t,{x:0,y:0},(...d)=>{this.onLineDragEnd(...d)},a)}onLineDragEnd(e,t,n){L("onLineDragEnd"),this.updateElementLines()}onCanvasDragStart(e){if(ge(e)||e.target&&e.target.closest(".rg-line-peel"))return;const t=this.getOptions();if(this.dataProvider.isPerformanceMode()&&t.editingController.nodes.length>0){const n=this.getNodeAtEvent(e);if(n){this.onNodeDragStart(n,e);return}}if(t.dragEventAction==="none"){this.onCanvasClick(e);return}if(t.dragEventAction==="selection"||e.shiftKey){this.startCreateSelection(e);return}if(!t.disableDragLine){const n=this.isLine(e.target);if(n){this.onLineDragStart(n,e);return}}this.startMoveCanvas(e)}startMoveCanvas(e,t=!1){let n;if(de(e)){let f,p,m,u,g,y=0,v=100;const x=N=>{if("touches"in N&&N.touches.length>0)return N.touches;if("targetTouches"in N&&N.targetTouches.length>0)return N.targetTouches},w=N=>({x:N.clientX,y:N.clientY}),k=(N,P)=>Math.hypot(P.x-N.x,P.y-N.y),T=(N,P)=>({x:(N.x+P.x)/2,y:(N.y+P.y)/2}),O=(N,P)=>{if(f="pan",P)p={x:P.touch.x,y:P.touch.y},m={x:P.offset.x,y:P.offset.y};else{p=w(N);const R=this.getOptions();m={x:R.canvasOffset.x,y:R.canvasOffset.y}}},b=(N,P)=>{f="pinch";const R=w(N),S=w(P),M=this.getOptions();y=k(R,S),v=M.canvasZoom,g={x:M.canvasOffset.x,y:M.canvasOffset.y},u=this.getViewXyByClientXy(T(R,S))};n=(N,P,R,S,M)=>{const C=x(M);if(!(!C||C.length===0))if(M.cancelable&&M.preventDefault(),C.length>1){const E=C[0],V=C[1];f!=="pinch"&&b(E,V);const X=w(E),A=w(V),G=k(X,A);if(!u||!g||y<=0||G<=0){b(E,V);return}const $=this.getViewXyByClientXy(T(X,A)),J=G-y,ie=$.x-u.x,te=$.y-u.y;if(Math.abs(J)<6&&Math.abs(ie)<2&&Math.abs(te)<2)return;const ne=G/y,Q=Math.pow(ne,.85),Z=v*Q,oe=v/100,q=this.getClampedZoom(Z)/100,F=$.x-(u.x-g.x)*(q/oe),gs=$.y-(u.y-g.y)*(q/oe);this.setZoomAndOffset(Z,{x:F,y:gs})}else{const E=C[0];if(f!=="pan"&&O(E,f===void 0?{touch:S,offset:R}:void 0),!p||!m){O(E);return}const V=w(E),X=V.x-p.x,A=V.y-p.y,G=m.x+X,$=m.y+A;this.onCanvasDragging(G,$,X,A),this._updateEditingControllerView(),this._dataUpdated()}}}else n=(d,h,c,f,p)=>{const m=c.x+d,u=c.y+h;this.onCanvasDragging(m,u,d,h),this._updateEditingControllerView(),this._dataUpdated()};const o=this.getOptions(),s={x:o.canvasOffset.x,y:o.canvasOffset.y};let a=t;le.startDrag(e,s,(d,h,c)=>{this.onCanvasDragStop(d,h,c)},(d,h,c,f,p)=>{const m="touches"in p&&p.touches?p.touches.length:0;a||(m>1||Math.abs(d)+Math.abs(h)>4)&&(this.emitEvent(I.onCanvasDragStart,c,f,p),a=!0),a&&n(d,h,c,f,p)})}onCanvasDragging(e,t,n,o){const s=this.emitEvent(I.onCanvasDragging,e,t,n,o);s!==!1&&(s&&(typeof s.x=="number"&&(e=s.x),typeof s.y=="number"&&(t=s.y)),this.dataProvider.setCanvasOffset(e,t))}onCanvasDragStop(e,t,n){const o=this.getOptions();if(o.creatingSelection){this.dataProvider.updateOptions({creatingSelection:!1}),this.onCanvasSelectionEnd(o.selectionView,n);return}if(Math.abs(e)+Math.abs(t)<4){L("[canvas]onDragEnd as click2"),this._dataUpdated(),this.onCanvasClick(n);return}else L("[canvas]onDragEnd"),this.onCanvasDragEnd(n)}startCreateSelection(e){const t=()=>{if(!n||s)return;const c=this.getViewXyByEvent(n);this.canvasAutoMoving(c)&&this._updateEditingControllerView();const p=this.getViewXyByCanvasXy(a),m=c.x-p.x,u=c.y-p.y;m<0?this.dataProvider.updateOptions({selectionView:{...this.getOptions().selectionView,x:p.x+m,width:Math.abs(m)}}):this.dataProvider.updateOptions({selectionView:{...this.getOptions().selectionView,x:p.x,width:Math.abs(m)}}),u<0?this.dataProvider.updateOptions({selectionView:{...this.getOptions().selectionView,y:p.y+u,height:Math.abs(u)}}):this.dataProvider.updateOptions({selectionView:{...this.getOptions().selectionView,y:p.y,height:u}}),this._dataUpdated()};let n,o=!1,s=!0;const a=this.getCanvasXyByViewXy(this.getViewXyByEvent(e)),d=()=>{t(),this._canvasMovingTimer=requestAnimationFrame(d)},h=(c,f,p,m,u)=>{if(n=u,o)n=u;else if(Math.abs(c)+Math.abs(f)>6){o=!0,s=!1;const g=this.getOptions();g.selectionView.width=5,g.selectionView.height=5,this.dataProvider.updateOptions({creatingSelection:!0}),this._canvasMovingTimer&&cancelAnimationFrame(this._canvasMovingTimer),this._canvasMovingTimer=requestAnimationFrame(d)}this._dataUpdated()};le.startDrag(e,{x:0,y:0},(...c)=>{s=!0,this._canvasMovingTimer&&cancelAnimationFrame(this._canvasMovingTimer),this.onCanvasDragStop(...c)},h)}addFullscreenListener(){this._fullscreenchangeHandler=()=>{let e=!1;document.fullscreenElement?(L("div entered fullscreen mode",document.fullscreenElement),this.$dom===document.fullscreenElement&&(L("relation-graph is fullscreen!"),e=!0)):L("div exited fullscreen mode"),e!==this.getOptions().fullscreen&&(this.dataProvider.updateOptions({fullscreen:e}),this._dataUpdated(),setTimeout(async()=>{this.resetViewSize(),this._moveToCenter(),this.zoomToFit(),L("relation-graph reset complete!")},500))},document.addEventListener("fullscreenchange",this._fullscreenchangeHandler)}removeFullscreenListener(){document.addEventListener("fullscreenchange",this._fullscreenchangeHandler)}defaultLineConnectEndHandler(e,t,n){L("defaultLineConnectEndHandler:",e,t,n)}defaultLineVertexBeChangedHandler(e,t,n){L("defaultLineVertexBeChangedHandler:",n&&n.isReverse)}async sleep(e){await Ee(e)}forceLayoutTickCallback(){this._updateEditingControllerView(),this.dataProvider.updateShouldRenderGraphData(),this._dataUpdated()}}class So extends To{constructor(){super();_(this,"$easyViewCanvas");_(this,"$rgWebglPainter");_(this,"_updateEasyViewRequested",!1);_(this,"_easyViewOffset",{x:0,y:0})}setEasyViewCanvas(e){this.$easyViewCanvas=e,this.$rgWebglPainter=new kn(e)}updateEasyView(){this.updateMiniView(),this.dataProvider.isPerformanceMode()&&(!this.getOptions().showEasyView||this._updateEasyViewRequested||(this._updateEasyViewRequested=!0,requestAnimationFrame(this._updateEasyView.bind(this))))}_updateEasyView(e){try{const t=Date.now();if(!this.$easyViewCanvas)return;this.updateShouldRenderGraphData(),this.evDosomethingBeforeDraw(),this.evDrawAllLines(),this.evDrawAllNodes()}catch(t){console.error(t)}finally{this._updateEasyViewRequested=!1}}evDosomethingBeforeDraw(){const e=this.getOptions(),t=e.viewSize.width,n=e.viewSize.height;this.$easyViewCanvas.width=t,this.$easyViewCanvas.height=n,this.$rgWebglPainter.setSize(t,n);const o=this.dataProvider.getCanvasScale();this.$rgWebglPainter.setScale(o),this._easyViewOffset.x=e.canvasOffset.x,this._easyViewOffset.y=e.canvasOffset.y,this.$rgWebglPainter.setViewOffset(this._easyViewOffset.x,this._easyViewOffset.y),this.$rgWebglPainter.beforeDraw()}evDrawAllNodes(){const e=this.getOptions().defaultNodeShape;for(const t of this.getNodes()){if(!(t.rgShouldRender!==!1&&t.rgCalcedVisibility&&t.opacity!==0))continue;const o=Ce(t.nodeShape,e);this.evDrawNode(t,o)}}evDrawNode(e,t){t===xe.circle?this.evDrawNode4Circle(e):this.evDrawNode4Rect(e)}getNodeColor(e){const t=e.color||this.getOptions().defaultNodeColor||"#dddddd";return t==="transparent"?"rgba(204,204,204,0.2)":t}evDrawNode4Rect(e){const t=e.el_W,n=e.el_H,o=e.opacity||.8,s=this.getNodeColor(e),a=e.borderRadius===void 0?3:e.borderRadius,d=e.borderColor||"#666666";this.$rgWebglPainter.evDrawNode4Rect(e.x,e.y,t,n,s,o,a,d)}evDrawNode4Circle(e){const t=e.el_W,n=e.el_H,o=e.opacity||.8,s=this.getNodeColor(e),a=e.borderColor||"#666666";this.$rgWebglPainter.evDrawNode4Circle(e.x,e.y,t,n,s,o,a)}evDrawAllLines(){for(const e of this.getLinks()){const t=e.fromNode.rgShouldRender!==!1&&e.fromNode.opacity!==0&&e.fromNode.rgCalcedVisibility,n=e.toNode.rgShouldRender!==!1&&e.toNode.opacity!==0&&e.toNode.rgCalcedVisibility;!t&&!n||this.evDrawLine(e,e.line)}}evDrawLine(e,t){const n=this.createLineDrawInfo(e,t),o=t.opacity||1,s=this.getOptions(),a=t.color||s.defaultLineColor||"#888888",d=t.lineWidth||s.defaultLineWidth||1;this.$rgWebglPainter.evDrawLine(n.pathData,d,a,o)}}class Ro extends So{constructor(){super();_(this,"_onResizing");_(this,"_onResizeEnd");_(this,"_startPoint",{x:0,y:0});_(this,"_startEventCanvasXy",{x:0,y:0});_(this,"_startSizeCanvasXy",{x:0,y:0});_(this,"_startSize",{x:0,y:0,width:0,height:0,widthOnCanvas:0,heightOnCanvas:0});_(this,"_resizeType","l");_(this,"_nodeStartSizeMap",new WeakMap);_(this,"resizeMinLimit",{width:10,height:10});_(this,"_resizeDraggingTimer");_(this,"_resizeDraggingEvent");_(this,"_resizeDraggingStoped",!0);_(this,"_startCreateLineFromNodeTime",0)}setEditingNodes(e){if(e===null||e.length===0)this.dataProvider.setEditingNodes([]);else{const t=e.map(o=>o.id),n=this.getNodes().filter(o=>t.includes(o.id));this.dataProvider.setEditingNodes(n)}this._updateEditingControllerView(),this._dataUpdated()}addEditingNode(e){if(!this.getNodeById(e.id))throw new Error("Node not found: "+e.id);this.dataProvider.setEditingNodes(this.getOptions().editingController.nodes.concat(e)),this._updateEditingControllerView(),this._dataUpdated()}removeEditingNode(e){this.dataProvider.setEditingNodes(this.getOptions().editingController.nodes.filter(t=>t.id!==e.id)),this._updateEditingControllerView(),this._dataUpdated()}toggleEditingNode(e){this.getOptions().editingController.nodes.findIndex(n=>n.id===e.id)===-1?this.addEditingNode(e):this.removeEditingNode(e)}updateEditingControllerView(){this._updateEditingControllerView(),this._dataUpdated()}_updateEditingControllerView(){this._updateEditingLineView(),this._updateEditingConnectControllerView();const e=this.getOptions();if(!e.editingController.show)return;const{minX:t,minY:n,maxX:o,maxY:s}=this.getNodesRectBox(e.editingController.nodes),a=e.editingController.nodes.length>1?5:0,d=this.dataProvider.getCanvasScale();let h=o-t,c=s-n;if(h<0&&(h=0),c<0&&(c=0),h>0&&c>0){const f=this.getViewXyByCanvasXy({x:t,y:n}),p=f.x-a*d,m=f.y-a*d,u=h*d+a*2*d,g=c*d+a*2*d;this.dataProvider.updateOptions({editingController:{...e.editingController,x:p,y:m,width:u,height:g}})}else this.dataProvider.updateOptions({editingController:{...e.editingController,show:!1}})}onResizeStart(e,t){this._resizeType=e,this._startPoint=this.getViewXyByEvent(t),this._startEventCanvasXy=this.getCanvasXyByViewXy(this._startPoint);const n=this.getOptions();this._startSize.x=n.editingController.x,this._startSize.y=n.editingController.y,this._startSizeCanvasXy=this.getCanvasXyByViewXy(this._startSize),this._startSize.width=n.editingController.width,this._startSize.height=n.editingController.height;const o=this.dataProvider.getCanvasScale();this._startSize.widthOnCanvas=n.editingController.width/o,this._startSize.heightOnCanvas=n.editingController.height/o;for(const d of n.editingController.nodes)this._nodeStartSizeMap.set(d,{x:d.x,y:d.y,width:d.el_W,height:d.el_H});this._onResizing&&this.$dom.removeEventListener("mousemove",this._onResizing),this._onResizeEnd&&this.$dom.removeEventListener("mouseup",this._onResizeEnd),this._resizeDraggingEvent=null,this._resizeDraggingStoped=!1,this._onResizing=this.onResizing.bind(this),this._onResizeEnd=this.onResizeEnd.bind(this),this.$dom.addEventListener("mousemove",this._onResizing),this.$dom.addEventListener("mouseup",this._onResizeEnd);const s=this.onResizingRequest.bind(this),a=()=>{s(),this._resizeDraggingTimer=requestAnimationFrame(a)};this._resizeDraggingTimer=requestAnimationFrame(a),this.emitEvent(I.onResizeStart,n.editingController.nodes,t)}onResizing(e){this._resizeDraggingEvent=e}onResizingRequest(){if(!this._resizeDraggingEvent||this._resizeDraggingStoped)return;const e=this.getViewXyByEvent(this._resizeDraggingEvent);this.canvasAutoMoving(e);const t=this.getViewXyByCanvasXy(this._startEventCanvasXy),n=this.getViewXyByCanvasXy(this._startSizeCanvasXy),o=e.x-t.x,s=e.y-t.y,a=this.getOptions();let d=a.editingController.width,h=a.editingController.height,c=a.editingController.x,f=a.editingController.y;const p=this.dataProvider.getCanvasScale();this._resizeType==="tl"?(c=t.x+o,f=t.y+s,d=this._startSize.widthOnCanvas*p-o,h=this._startSize.heightOnCanvas*p-s):this._resizeType==="tr"?(f=t.y+s,c=n.x,d=this._startSize.widthOnCanvas*p+o,h=this._startSize.heightOnCanvas*p-s):this._resizeType==="bl"?(c=t.x+o,f=n.y,d=this._startSize.widthOnCanvas*p-o,h=this._startSize.heightOnCanvas*p+s):this._resizeType==="br"?(c=n.x,f=n.y,d=this._startSize.widthOnCanvas*p+o,h=this._startSize.heightOnCanvas*p+s):this._resizeType==="t"?(f=t.y+s,h=this._startSize.heightOnCanvas*p-s):this._resizeType==="r"?(c=n.x,d=this._startSize.widthOnCanvas*p+o):this._resizeType==="b"?(h=this._startSize.heightOnCanvas*p+s,f=n.y):this._resizeType==="l"&&(c=t.x+o,d=this._startSize.widthOnCanvas*p-o),d<this.resizeMinLimit.width&&(d=this.resizeMinLimit.width),h<this.resizeMinLimit.width&&(h=this.resizeMinLimit.height),this.dataProvider.updateOptions({editingController:{...a.editingController,x:c,y:f,width:d,height:h}}),this._applyResizeScale(this._resizeDraggingEvent),this._updateEditingControllerView(),this._dataUpdated()}_applyResizeScale(e){const t=this.getOptions(),n=this.dataProvider.getCanvasScale(),o=t.editingController.width/n/this._startSize.widthOnCanvas,s=t.editingController.height/n/this._startSize.heightOnCanvas,a=this._startSizeCanvasXy,d=this.getCanvasXyByViewXy({x:t.editingController.x,y:t.editingController.y});let h=!0,c=!0;this._resizeType==="t"||this._resizeType==="b"?h=!1:(this._resizeType==="r"||this._resizeType==="l")&&(c=!1);for(const f of t.editingController.nodes){const p=this._nodeStartSizeMap.get(f),m=p.width*o,u=p.height*s,g=d.x+o*(p.x-a.x),y=d.y+s*(p.y-a.y),v=m,x=u;this.emitEvent(I.beforeNodeResize,f,g,y,v,x)===!1||(h&&this.dataProvider.updateNode(f.id,{x:g,width:v,el_W:v}),c&&this.dataProvider.updateNode(f.id,{y,height:x,el_H:x}))}}onResizeEnd(e){cancelAnimationFrame(this._resizeDraggingTimer),this._resizeDraggingStoped=!0;const t=this.getViewXyByEvent(e),n=t.x-this._startPoint.x,o=t.y-this._startPoint.y;this._applyResizeScale(e),this.$dom.removeEventListener("mousemove",this._onResizing),this.$dom.removeEventListener("mouseup",this._onResizeEnd),this._onResizing=null,this._onResizeEnd=null,L("onResizeEnd:",this.getOptions().editingController.nodes,n,o),this.emitEvent(I.onResizeEnd,this.getOptions().editingController.nodes,n,o,e)}draggingSelectedNodes(e,t,n,o,s){const a=this.updateReferenceLineView(e,t,n,o,s);if(a){const{showV:h,fixedX:c,showH:f,fixedY:p}=a;h&&(o+=c-t,t=c),f&&(s+=p-n,n=p)}const d=this.getOptions();if(!d.editingController.nodes.includes(e))this.dataProvider.updateNode(e.id,{x:t,y:n}),this._updateEditingLineView();else{for(const h of d.editingController.nodes){const c=this._nodeXYMappingBeforeDrag[h.id];c&&this.dataProvider.updateNode(h.id,{x:c.x+o,y:c.y+s})}this._updateEditingControllerView()}}_updateEditingConnectControllerView(){const e=this.getOptions();if(!e.nodeConnectController.show)return;const t=e.nodeConnectController.node,n=t.x,o=t.y,s=t.x+t.el_W,a=t.y+t.el_H,d=0,h=this.dataProvider.getCanvasScale(),c=n,f=o,p=s-n,m=a-o,u=this.getViewXyByCanvasXy({x:c,y:f});this.dataProvider.updateOptions({nodeConnectController:{...e.nodeConnectController,x:u.x-d*h,y:u.y-d*h,width:p*h+d*2*h,height:m*h+d*2*h}})}setEditingLine(e){this.dataProvider.setEditingLine(e),this._updateEditingLineView(),this._dataUpdated()}updateReferenceLineView(e,t,n,o,s){const a=this.getOptions();if(!a.showReferenceLine)return;if(!a.editingReferenceLine.show){const M=Math.abs(o),C=Math.abs(s);M+C>2&&this.dataProvider.updateOptions({editingReferenceLine:{...a.editingReferenceLine,show:!0}})}if(!a.editingReferenceLine.show)return;const d=t,h=e.el_W,c=e.el_H,f=t+h/2,p=t+h,m=n,u=n+c/2,g=n+c,y=this.getViewXyByCanvasXy({x:f,y:u});let v=!1,x=!1,w=0,k=0;const T=this.getNodes().filter(M=>this._nodeXYMappingBeforeDrag[M.id]?!1:Math.abs(M.x-f)<600&&Math.abs(M.y-u)<600);T.sort((M,C)=>{const E=me(f,u,M.x+M.el_W/2,M.y+M.el_H/2),V=me(f,u,C.x+C.el_W/2,C.y+C.el_H/2);return E<V?-1:1});let{v_x:O,v_y:b,v_height:N,h_x:P,h_y:R,h_width:S}=a.editingReferenceLine;for(const M of T){const C=M.x,E=M.el_W,V=M.el_H,X=M.x+E/2,A=M.x+E,G=M.y,$=M.y+V/2,J=M.y+V,ie=Math.abs(d-C),te=Math.abs(f-X),ne=Math.abs(p-A),Q=Math.abs(m-G),Z=Math.abs(u-$),oe=Math.abs(g-J),q=5;if(te<800&&Z<800){if(!x&&te<q){const F=this.getViewXyByCanvasXy({x:X,y:$});O=F.x,b=y.y>F.y?F.y:y.y,N=Math.round(Math.abs(y.y-F.y)),x=!0,w=X-h/2}if(!x&&ie<q){const F=this.getViewXyByCanvasXy({x:C,y:$});O=F.x,b=y.y>F.y?F.y:y.y,N=Math.round(Math.abs(y.y-F.y)),x=!0,w=C}if(!x&&ne<q){const F=this.getViewXyByCanvasXy({x:A,y:$});O=F.x,b=y.y>F.y?F.y:y.y,N=Math.round(Math.abs(y.y-F.y)),x=!0,w=A-h}if(!v&&Z<q){const F=this.getViewXyByCanvasXy({x:X,y:$});R=F.y,P=y.x>F.x?F.x:y.x,S=Math.round(Math.abs(y.x-F.x)),v=!0,k=$-c/2}if(!v&&Q<q){const F=this.getViewXyByCanvasXy({x:X,y:G});R=F.y,P=y.x>F.x?F.x:y.x,S=Math.round(Math.abs(y.x-F.x)),v=!0,k=G}if(!v&&oe<q){const F=this.getViewXyByCanvasXy({x:X,y:J});R=F.y,P=y.x>F.x?F.x:y.x,S=Math.abs(y.x-F.x),v=!0,k=J-c}if(v&&x)break}}if(this.dataProvider.updateOptions({editingReferenceLine:{...a.editingReferenceLine,v_x:O,v_y:b,v_height:N,h_x:P,h_y:R,h_width:S,directionH:v,directionV:x}}),a.referenceLineAdsorption)return{showV:x,fixedX:w,showH:v,fixedY:k}}hideEditingLineView(){this.dataProvider.updateOptions({editingLineController:{...this.getOptions().editingLineController,show:!1}})}updateEditingLineView(){this._updateEditingLineView(),this._dataUpdated()}_updateEditingLineView(){this.updateElementLines();const e=this.getOptions();if(!e.editingLineController.show)return;const t=e.editingLineController.line,n=this.getLinkByLine(t);if(!t||t.to==="newRelationTemplate-to"){this.dataProvider.updateOptions({editingLineController:{...this.getOptions().editingLineController,show:!1}});return}let o,s,a;const d=this.createLineDrawInfo(n,t);if(!d){this.dataProvider.updateOptions({editingLineController:{...this.getOptions().editingLineController,show:!1}});return}if(t.lineShape===Y.StandardOrthogonal){let{textPosition:k,pathData:T,points:O,startDirection:b,endDirection:N}=d;a=k,o=O[0],s=O[O.length-1];const P=[];for(let R=0;R<O.length-1;R++){const S=O[R],M=O[R+1],C={pIndex:R,optionName:"cp-"+R,x:0,y:0,direction:"v",startDirection:b,endDirection:N};S.x!==M.x&&(C.direction="h");const E=this.getViewXyByCanvasXy({x:(S.x+M.x)/2,y:(S.y+M.y)/2});C.x=E.x,C.y=E.y,P.push(C)}if(P.length!==1){if(P.length!==2)if(P.length===3){const R=O[0],S=O[1],M=O[3];if(P[1].direction==="v"){const C=R.x,E=S.x,V=M.x;if(Math.max(C,E,V)!==E&&Math.min(C,E,V)!==E)P[1].optionName="cx";else{const A=Math.abs(E-C),G=Math.abs(E-V);A>=G?P[1].optionName="td":A<G&&(P[1].optionName="fd")}}else{const C=R.y,E=S.y,V=M.y;if(Math.max(C,E,V)!==E&&Math.min(C,E,V)!==E)P[1].optionName="cy";else{const A=Math.abs(E-C),G=Math.abs(E-V);A>=G?P[1].optionName="td":A<G&&(P[1].optionName="fd")}}}else P.length===4?(P[1].optionName="fd",P[2].optionName="td"):P.length===5&&(P[1].optionName="fd",P[2].direction==="v"?P[2].optionName="cx":P[2].optionName="cy",P[3].optionName="td")}this.dataProvider.updateOptions({editingLineController:{...this.getOptions().editingLineController,line44Splits:P,line49Points:O}})}else if(t.lineShape===Y.HardOrthogonal){let{textPosition:k,pathData:T,points:O,startDirection:b,endDirection:N}=d;a=k;const P=[];O=t.ctrlPointsFor49,o=O[0],s=O[O.length-1];const R=O;for(let S=0;S<R.length-1;S++){const M=R[S],C=R[S+1],E={pIndex:S,optionName:"cp-"+S,x:0,y:0,direction:"v",startDirection:b,endDirection:N};M.x!==C.x?(E.direction="h",Math.abs(M.x-C.x)<15&&(E.hide=!0)):Math.abs(M.y-C.y)<15&&(E.hide=!0);const V=this.getViewXyByCanvasXy({x:(M.x+C.x)/2,y:(M.y+C.y)/2});E.x=V.x,E.y=V.y,P.push(E)}for(let S=0;S<P.length;S++){const M=P[S-1],C=P[S],E=P[S+1];S===0&&C.direction===E.direction&&(C.hide=!0),S===P.length-1&&C.direction===M.direction&&(C.hide=!0)}this.dataProvider.updateOptions({editingLineController:{...this.getOptions().editingLineController,line44Splits:P,line49Points:R}})}else if(t.lineShape!==1){a=d.textPosition;const k=pt(d.pathData);let T,O;t.isReverse?(o=k.endPoint,s=k.startPoint,T=this.getViewXyByCanvasXy(k.ctrl1),O=this.getViewXyByCanvasXy(k.ctrl2)):(o=k.startPoint,s=k.endPoint,T=this.getViewXyByCanvasXy(k.ctrl1),O=this.getViewXyByCanvasXy(k.ctrl2)),this.dataProvider.updateOptions({editingLineController:{...this.getOptions().editingLineController,ctrlPoint1:T,ctrlPoint2:O}})}else{a=d.textPosition;const k=d.pathData,T=pt(k);o=T.startPoint,s=T.endPoint}const h=this.getViewXyByCanvasXy(t.isReverse?s:o),c=this.getViewXyByCanvasXy(t.isReverse?o:s);this.dataProvider.updateOptions({editingLineController:{...this.getOptions().editingLineController,startPoint:h,endPoint:c}});const f=this.getViewXyByCanvasXy(a),p=this.$canvasDom.querySelector(`g[data-id='${t.id}']`);let m=0,u=0,g=t.textOffsetX||0,y=t.textOffsetY||0;const v=this.dataProvider.getCanvasScale();let x=20,w=20;if(p){const k=p.querySelector("text.rg-line-text");if(k){g=Math.floor(parseFloat(k.getAttribute("x")||"0")),y=Math.floor(parseFloat(k.getAttribute("y")||"0"));const T=k.clientWidth,O=k.clientHeight;x=T,w=O}}x+=40,w+=10,x>120&&(x=120),w>20&&(w=20),this.dataProvider.updateOptions({editingLineController:{...this.getOptions().editingLineController,text:{...this.getOptions().editingLineController.text,width:x,height:w,x:f.x+m+g*v,y:f.y+u+y*v}}})}startMoveLineVertex(e,t,n){t.stopPropagation();const o=this.getOptions().editingLineController.line,s=this.getLinkByLine(o);let a,d;if(s)a=s.fromNode,d=s.toNode;else{const{from:f,to:p}=this.generateFakeLineConfig(o);a=f,d=p}let h=a;this.dataProvider.setEditingLine(null),s?this.removeLine(o):this.removeFakeLine(o);let c=!1;o.lineShape===Y.HardOrthogonal&&(o.lineShape=Y.StandardOrthogonal),e==="start"?(o.fromJunctionPointOffsetX=0,o.fromJunctionPointOffsetY=0,h=d,c=!0):(o.toJunctionPointOffsetX=0,o.toJunctionPointOffsetY=0),this.startCreatingLinePlot(t,{template:o,fromNode:h,isReverse:c,onCreateLine:n})}startCreateLineFromNode(e,t,n,o){n.stopPropagation();const s=JSON.parse(JSON.stringify(t));if(this._startCreateLineFromNodeTime=Date.now(),!s.from){if(!e){const d=this.getOptions().editingController.nodes;d.length===1&&(e=d[0])}e&&(s.from=e.id,s.fromType=e.targetType)}if(!s.from)throw console.error("Error:lineTemplate:",s),Error("Error:startCreateLineByTemplate: lineTemplate must has [fromType, from]");const a=this.getFakeLineTarget(s.fromType,s.from,s);if(!a)throw console.error("Error:fakeTarget[fromType, from]:",s.fromType,s.from,s),Error(`Error:startCreateLineByTemplate: error from fakeTarget[fromType, from]:${s.fromType}, ${s.from}`);s.lineShape||(s.lineShape=6),this.startCreatingLinePlot(n,{template:s,fromNode:a,isReverse:!1,onCreateLine:o})}onLineVertexBeDropped(e,t,n={x:0,y:0},o){t.stopPropagation();const s=this.getOptions();if(!s.creatingLinePlot||Date.now()-this._startCreateLineFromNodeTime<500)return;const a=s.nodeConnectController.node;let{toJunctionPoint:d,toJunctionPointOffsetX:h,toJunctionPointOffsetY:c,fromJunctionPoint:f,fromJunctionPointOffsetX:p,fromJunctionPointOffsetY:m}=s.newLineTemplate;if(!s.newLinkTemplate.fromNode)s.newLineTemplate.isReverse?(d=e,h=n.x,c=n.y):(f=e,p=n.x,m=n.y),this.dataProvider.updateOptions({newLineTemplate:{...this.getOptions().newLineTemplate,fromJunctionPoint:f,fromJunctionPointOffsetX:p,fromJunctionPointOffsetY:m,toJunctionPoint:d,toJunctionPointOffsetX:h,toJunctionPointOffsetY:c},newLinkTemplate:{...this.getOptions().newLinkTemplate,fromNode:a}});else{s.newLineTemplate.isReverse?(f=e,p=n.x,m=n.y):(d=e,h=n.x,c=n.y);const u=this.getOptions().newLinkTemplate.fromNode;this.dataProvider.updateOptions({newLineTemplate:{...this.getOptions().newLineTemplate,fromJunctionPoint:f,fromJunctionPointOffsetX:p,fromJunctionPointOffsetY:m,toJunctionPoint:d,toJunctionPointOffsetX:h,toJunctionPointOffsetY:c},newLinkTemplate:{...this.getOptions().newLinkTemplate,toNodeObject:a}});const g=a;try{const y={newLineTemplate:this.getOptions().newLineTemplate,fromNode:u,toNode:g};this.emitEvent(I.onLineVertexDropped,y),o&&o(y.fromNode,y.toNode,y.newLineTemplate),this.onReadyToCreateLine(this.getOptions().newLinkTemplate.fromNode,this.getOptions().nodeConnectController.node)!==!0&&this.stopCreatingLinePlot()}catch(y){this.stopCreatingLinePlot(),console.warn("[Custom Reject onCreateLine By Throw Error:",y)}}}startMoveLineText(e,t){if(ge(e))return;const n=this.getViewXyByEvent(e),s=this.getOptions().editingLineController.line,a=s.textOffsetX||0,d=s.textOffsetY||0;let h=!1;const c=p=>{const m=this.dataProvider.getCanvasScale(),u=this.getViewXyByEvent(p),g=u.x-n.x,y=u.y-n.y;(g>0||y>0)&&(h=!0);const v=Math.round(a+g/m),x=Math.round(d+y/m);this.dataProvider.updateLine(s.id,{textOffsetX:v,textOffsetY:x}),this._updateEditingLineView(),this._dataUpdated()},f=p=>{this.$dom.removeEventListener("mousemove",c),this.$dom.removeEventListener("mouseup",f),h&&t&&t(),this._dataUpdated()};this.$dom.addEventListener("mousemove",c),this.$dom.addEventListener("mouseup",f)}startMoveLine6CtrlPoint(e,t,n){t.stopPropagation(),t.preventDefault();const a=this.getOptions().editingLineController.line;let d=a.ctrlPoints||[];d.length===0&&(d.push({x:0,y:0}),d.push({x:0,y:0})),this.dataProvider.updateLine(a.id,{ctrlPoints:d}),d=a.ctrlPoints,a.isReverse&&(e=d.length-1-e);const h=this.dataProvider.getCanvasScale(),c=d[e],{x:f,y:p}=c,m=()=>{n(a),this._dataUpdated()};le.startDrag(t,{x:0,y:0},m,(u,g)=>{c.x=f+u/h,c.y=p+g/h,this.dataProvider.updateLine(a.id,{ctrlPoints:d}),this._updateEditingLineView(),this._dataUpdated()})}startMoveLine44CtrlPoint(e,t,n){t.stopPropagation(),t.preventDefault();const s=this.getOptions().editingLineController,a=s.line;let d=a.ctrlOptionsFor44;d||(d={cx:0,cy:0,fd:0,td:0},this.dataProvider.updateLine(a.id,{ctrlOptionsFor44:d}),d=a.ctrlOptionsFor44);const h=d[e.optionName],c={indexOffset:0};let f=a.ctrlPointsFor49?JSON.parse(JSON.stringify(a.ctrlPointsFor49)):null;const p=(u,g)=>{const y=this.dataProvider.getCanvasScale();if(a.lineShape===Y.StandardOrthogonal){if(e.optionName==="cx"){const x=h+u/y*1;d.cx=x,this.dataProvider.updateLine(a.id,{ctrlOptionsFor44:d})}else if(e.optionName==="cy"){const x=h+g/y*1;d.cy=x,this.dataProvider.updateLine(a.id,{ctrlOptionsFor44:d})}else if(e.optionName==="fd"){const v=Se[e.startDirection],x=e.direction==="v"?u*v.x:g*v.y;d.fd=h+x/y,this.dataProvider.updateLine(a.id,{ctrlOptionsFor44:d})}else if(e.optionName==="td"){const v=Se[e.endDirection],x=e.direction==="v"?u*v.x:g*v.y;d.td=h+x/y,this.dataProvider.updateLine(a.id,{ctrlOptionsFor44:d})}else if(e.direction==="v"&&Math.abs(u)>5||e.direction==="h"&&Math.abs(g)>5){const v=s.line49Points;f=JSON.parse(JSON.stringify(v)),this.dataProvider.updateLine(a.id,{ctrlPointsFor49:f}),this.dataProvider.updateLine(a.id,{lineShape:Y.HardOrthogonal})}}else if(a.lineShape===Y.HardOrthogonal){const{newPoints:v,pointsChanged:x}=$n(a.ctrlPointsFor49,f,e.pIndex+c.indexOffset,e,c,u/y,g/y);x&&(f=JSON.parse(JSON.stringify(v))),this.dataProvider.updateLine(a.id,{ctrlPointsFor49:v})}},m=()=>{if(a.lineShape===Y.HardOrthogonal){const u=Re(a.ctrlPointsFor49);this.dataProvider.updateLine(a.id,{ctrlPointsFor49:u})}this._updateEditingLineView(),n&&n(a),this._dataUpdated()};le.startDrag(t,{x:0,y:0},m,(u,g)=>{p(u,g),this._updateEditingLineView(),this._dataUpdated()})}onLineVertexBeDroppedOnConnectController(e,t,n,o){if(L("onLineVertexBeDroppedOnConnectController",e,t,n),t.stopPropagation(),!n){this.onLineVertexBeDropped(e,t,void 0,o);return}const s=ce(t),a=n.getBoundingClientRect(),d={x:a.left,y:a.top+a.height/2},h={x:a.left+a.width/2,y:a.top},c={x:a.left+a.width,y:a.top+a.height/2},f={x:a.left+a.width/2,y:a.top+a.height};let p=re.left;const m={x:0,y:0};if(e)p=e,p===re.top||p===re.bottom?m.x=s.clientX-f.x:p===re.right?m.y=s.clientY-c.y:m.y=s.clientY-d.y;else{const g=me(s.clientX,s.clientY,d.x,d.y),y=me(s.clientX,s.clientY,h.x,h.y),v=me(s.clientX,s.clientY,c.x,c.y),x=me(s.clientX,s.clientY,f.x,f.y),w=Math.min(g,y,v,x);w===g?(p=re.left,m.x=s.clientX-d.x,m.y=s.clientY-d.y):w===y?(p=re.top,m.x=s.clientX-h.x,m.y=s.clientY-h.y):w===v?(p=re.right,m.x=s.clientX-c.x,m.y=s.clientY-c.y):w===x&&(p=re.bottom,m.x=s.clientX-f.x,m.y=s.clientY-f.y)}const u=this.dataProvider.getCanvasScale();m.x=m.x/u,m.y=m.y/u,L("onMouseUpWithOffset:",e,m),this.onLineVertexBeDropped(p,t,m,o)}}class Mo extends Ro{constructor(){super();_(this,"$miniViewCanvas");_(this,"$mvCanvasCtx");_(this,"_canvasDomScale",1);_(this,"miniViewBox",{visibleAreaStart:{x:0,y:0},visibleAreaEnd:{x:0,y:0},canvas_start_x:0,canvas_start_y:0,canvas_end_x:0,canvas_end_y:0,canvas_width:0,canvas_height:0,miniview_width:0,miniview_height:0});_(this,"visibleArea",{x:0,y:0});_(this,"_canvasItemMiniSizeLimit",1)}setMiniViewCanvas(e){this.$miniViewCanvas=e,this.$mvCanvasCtx=this.$miniViewCanvas.getContext("2d")}updateMiniView(){!this.getOptions().showMiniView||(this.updateMiniViewVisibleArea(),this._updateMiniView())}_updateMiniView(){try{const e=Date.now();this.mvDosomethingBeforeDraw(),this.mvDrawAllNodes()}catch(e){console.error(e)}}mvDosomethingBeforeDraw(){let e=9999999,t=9999999,n=-9999999,o=-9999999,s=0;for(const x of this.getNodes())if(x.rgCalcedVisibility&&x.opacity!==0){x.x<e&&(e=x.x),x.y<t&&(t=x.y);const w=x.x+x.el_W,k=x.y+x.el_H;w>n&&(n=w),k>o&&(o=k),s++}const a=1,d=50,h=50;s===0?(this.miniViewBox.canvas_start_x=-100-d,this.miniViewBox.canvas_start_y=-100-h,this.miniViewBox.canvas_end_x=100+d,this.miniViewBox.canvas_end_y=100+h,this.miniViewBox.canvas_width=this.miniViewBox.canvas_end_x-this.miniViewBox.canvas_start_x,this.miniViewBox.canvas_height=this.miniViewBox.canvas_end_y-this.miniViewBox.canvas_start_y):(this.miniViewBox.canvas_start_x=e-d,this.miniViewBox.canvas_start_y=t-h,this.miniViewBox.canvas_end_x=n+d,this.miniViewBox.canvas_end_y=o+h,this.miniViewBox.canvas_width=this.miniViewBox.canvas_end_x-this.miniViewBox.canvas_start_x,this.miniViewBox.canvas_height=this.miniViewBox.canvas_end_y-this.miniViewBox.canvas_start_y);const c=this.$miniViewCanvas.parentElement.getBoundingClientRect(),f=c.width,p=c.height;let m=0,u=0,g=1;f/this.miniViewBox.canvas_width<p/this.miniViewBox.canvas_height?(g=f/this.miniViewBox.canvas_width*a,m=f,u=f/this.miniViewBox.canvas_width*this.miniViewBox.canvas_height):(g=p/this.miniViewBox.canvas_height*a,m=p/this.miniViewBox.canvas_height*this.miniViewBox.canvas_width,u=p),this.miniViewBox.miniview_width=f,this.miniViewBox.miniview_height=p,this.$miniViewCanvas.width=f,this.$miniViewCanvas.height=p,this.$mvCanvasCtx.canvas.width=f*window.devicePixelRatio,this.$mvCanvasCtx.canvas.height=p*window.devicePixelRatio,this.$mvCanvasCtx.canvas.style.width=`${f}px`,this.$mvCanvasCtx.canvas.style.height=`${p}px`;const y=(p-u)/2,v=(f-m)/2;this.miniViewBox.canvas_start_x-=v/g,this.miniViewBox.canvas_start_y-=y/g,this.$mvCanvasCtx.setTransform(window.devicePixelRatio,0,0,window.devicePixelRatio,0,0),this.$mvCanvasCtx.scale(g,g),this._canvasDomScale=g,this.$mvCanvasCtx.clearRect(0,0,this.$mvCanvasCtx.canvas.width,this.$mvCanvasCtx.canvas.height)}updateMiniViewVisibleArea(){const e=this.getCanvasXyByViewXy({x:0,y:0}),t=this.getOptions().viewSize,n=this.getCanvasXyByViewXy({x:t.width,y:t.height}),o=this._canvasDomScale,s=n.x-e.x,a=n.y-e.y;this.miniViewBox.visibleAreaStart=e,this.miniViewBox.visibleAreaEnd=n;const d=o*s,h=o*a,c=e.x-this.miniViewBox.canvas_start_x,f=e.y-this.miniViewBox.canvas_start_y,p=o*c,m=o*f;let u=!1;(p+d<0||m+h<0||m>this.miniViewBox.miniview_height||p>this.miniViewBox.miniview_width)&&(u=!0);const g=this.getOptions().miniViewVisibleHandle;(g.emptyContent!==u||g.width!==d||g.height!==h||g.x!==d||g.y!==h)&&this.dataProvider.updateOptions({miniViewVisibleHandle:{emptyContent:u,width:d,height:h,x:p,y:m}})}mvDrawAllNodes(){const e=this._canvasDomScale,t=this.getOptions().defaultNodeShape;for(const n of this.getNodes())if(n.rgCalcedVisibility&&n.opacity!==0){let o=n.el_W,s=n.el_H;e*o<this._canvasItemMiniSizeLimit&&(o=this._canvasItemMiniSizeLimit/this._canvasDomScale),e*s<this._canvasItemMiniSizeLimit&&(s=this._canvasItemMiniSizeLimit/this._canvasDomScale);const a=Ce(n.nodeShape,t);this.mvDrawNode(n,a,o,s)}}mvDrawNode(e,t,n,o){t===xe.circle?this.mvDrawNode4Circle(e,n,o):this.mvDrawNode4Rect(e,n,o)}mvDrawNode4Rect(e,t,n){const o=this.$mvCanvasCtx,s=e.x-this.miniViewBox.canvas_start_x,a=e.y-this.miniViewBox.canvas_start_y;o.beginPath(),o.globalAlpha=e.opacity||1,o.rect(s,a,t,n),o.fillStyle=this.getNodeColor(e),o.fill(),o.strokeStyle="#666666",o.lineWidth=2,o.stroke(),o.globalAlpha=1}mvDrawNode4Circle(e,t,n){const o=this.$mvCanvasCtx,s=e.x+t/2-this.miniViewBox.canvas_start_x,a=e.y+n/2-this.miniViewBox.canvas_start_y;o.beginPath(),o.globalAlpha=e.opacity||1,o.ellipse(s,a,t/2,n/2,0,0,2*Math.PI),o.fillStyle=this.getNodeColor(e),o.fill(),o.strokeStyle="#666666",o.lineWidth=2,o.stroke(),o.globalAlpha=1}mvDrawAllLines(){for(const e of this.getLinks())e.fromNode.rgCalcedVisibility&&e.toNode.rgCalcedVisibility&&this.mvDrawLine(e,e.line)}mvDrawLine(e,t){const n=this.$mvCanvasCtx,o=this.createLineDrawInfo(e,t);n.beginPath(),n.globalAlpha=t.opacity||1,this.mvDrawSvgPathOnCanvas(n,o.pathData);const s=this.getOptions();n.strokeStyle=t.color||s.defaultLineColor||"#888888",n.lineWidth=t.lineWidth||s.defaultLineWidth||1,n.stroke(),n.globalAlpha=1}mvDrawSvgPathOnCanvas(e,t){const n=t.match(/[a-zA-Z][^a-zA-Z]*/g);let o=0,s=0,a=0,d=0,h=0,c=0,f=0,p=0,m=!1;n.forEach(u=>{const g=u.trim().split(/[ ,]+/),y=g[0].toUpperCase(),v=g[0]===g[0].toLowerCase();switch(y){case"M":o=U(a,g[1],v)-this.miniViewBox.canvas_start_x,s=U(d,g[2],v)-this.miniViewBox.canvas_start_y,a=o,d=s,m&&(e.closePath(),m=!1),e.moveTo(o,s);break;case"L":o=U(a,g[1],v)-this.miniViewBox.canvas_start_x,s=U(d,g[2],v)-this.miniViewBox.canvas_start_y,e.lineTo(o,s);break;case"C":h=U(a,g[1],v),c=U(d,g[2],v),f=U(a,g[3],v),p=U(d,g[4],v),o=U(a,g[5],v),s=U(d,g[6],v),a=o,d=s,e.bezierCurveTo(h,c,f,p,o,s);break;case"Q":h=U(a,g[1],v),c=U(d,g[2],v),o=U(a,g[3],v),s=U(d,g[4],v),a=o,d=s;break;case"V":s=U(d,g[1],v),d=s,e.lineTo(o,s);break;case"H":o=U(a,g[1],v),a=o,e.lineTo(o,s);break;case"Z":e.closePath(),m=!1;break;default:L(`Unsupported command: ${y}`)}})}onVisibleViewHandleDragStart(e){e.preventDefault(),e.stopPropagation();const t=this.getOptions(),n=t.canvasOffset.x,o=t.canvasOffset.y,s=this.miniViewBox.canvas_width,a=this.miniViewBox.canvas_height,d=()=>{const u=p/this.miniViewBox.miniview_width,g=m/this.miniViewBox.miniview_height,y=this.dataProvider.getCanvasScale(),v=s*u*y,x=a*g*y;this.dataProvider.setCanvasOffset(n-v,o-x),this._updateEditingControllerView(),this.updateMiniViewVisibleArea(),this.updateShouldRenderGraphData(),this.dataProvider.dataUpdated()};let h;const c=(u,g,y)=>{h&&clearInterval(h),this.onCanvasDragEnd(y)};let f=!1,p=0,m=0;le.startDrag(e,{x:0,y:0},c,(u,g)=>{p=u,m=g,!f&&Math.abs(u)+Math.abs(g)>3&&(f=!0,h=setInterval(()=>{d()},50))})}resetByVisiableView(e){!this.getOptions().miniViewVisibleHandle.emptyContent||(this.setZoom(100),this._moveToCenter(),this.zoomToFit())}}class Eo extends Mo{constructor(){super();_(this,"$watermarkDom",null);_(this,"$watermarkPosition","br");_(this,"$backgroundDom",null);_(this,"_originBackgroundColor","");_(this,"graphStatusBeforeImageGeneration",{orignCanvasOffsetX:0,orignCanvasOffsetY:0,orignZoom:0,forceLayouting:!1})}setWatermarkDom(e,t=!0,n=!1,o="br"){t&&(this.$watermarkDom=e),this.$watermarkPosition=o}setBackgroundDom(e,t=!0,n=!0){e===null?(this._originBackgroundColor=this.options.backgroundColor,this.dataProvider.updateOptions({backgroundColor:"transparent"}),t?this.$backgroundDom=e:this.$backgroundDom=null):(this.dataProvider.updateOptions({backgroundColor:this._originBackgroundColor}),this.$backgroundDom=null)}async prepareForImageGeneration(){return this.updateShouldRenderGraphData(),this.updateElementLines(),await this.moveItemsAndFitContent(),this._dataUpdated(),this.$canvasDom.parentElement}async restoreAfterImageGeneration(){const{orignCanvasOffsetX:e,orignCanvasOffsetY:t,orignZoom:n,forceLayouting:o}=this.graphStatusBeforeImageGeneration;this.$canvasDom.parentElement.style.width="100%",this.$canvasDom.parentElement.style.height="100%",this.setZoom(n),this.dataProvider.updateOptions({canvasOffset:{x:e,y:t}}),this._dataUpdated(),o&&this.startAutoLayout(),this.clearLoading()}async moveItemsAndFitContent(){const e=this.getOptions(),t=e.canvasZoom,n=e.canvasOffset.x,o=e.canvasOffset.y,s=e.layout.autoLayouting===!0;s&&(this.stopAutoLayout(),await this.sleep(200)),this.loading("Generating..."),this.dataProvider.updateOptions({snapshotting:!0}),this.dataProvider.clearChecked(),this.setZoom(100),this.updateShouldRenderGraphData(!0),this._dataUpdated(),await this.sleep(200);const a=this.getNodesRectBox(),d=this.getCanvasSlotRectItems(),h=this.getNodesRectBox(d),c=100,f=Math.min(a.minX,h.minX)-c,p=Math.min(a.minY,h.minY)-c,m=Math.max(a.maxX,h.maxX)+c,u=Math.max(a.maxY,h.maxY)+c,g=f,y=p,v=m-f,x=u-p;this.graphStatusBeforeImageGeneration={orignCanvasOffsetX:n,orignCanvasOffsetY:o,orignZoom:t,forceLayouting:s},this.dataProvider.updateOptions({canvasOffset:{x:-g,y:-y}}),this._dataUpdated(),this.setZoom(100),this.$canvasDom.parentElement.style.width=v+"px",this.$canvasDom.parentElement.style.height=x+"px",L("export image:",{imageWidth:v,imageHeight:x,minX:f,minY:p,maxX:m,maxY:u,devicePixelRatio:window.devicePixelRatio}),await this.sleep(200)}}class Io extends Eo{constructor(){super();_(this,"resizeObserver");_(this,"resizeListenerMap",new WeakMap);_(this,"domToNodeIdMap",new WeakMap);_(this,"_trackpadGestureActive",!1);_(this,"_trackpadGestureStartZoom",100);_(this,"_trackpadGestureAnchorView");_(this,"_trackpadGestureStartOffset");_(this,"_mouseMoveHandler");_(this,"_gestureStartHandler");_(this,"_gestureChangeHandler");_(this,"_gestureEndHandler");_(this,"_lastMouseClientXy");_(this,"mutationObserver4Nodes");_(this,"mutationObserver4CanvasSlotBehind");_(this,"mutationObserver4CanvasSlotAbove");_(this,"_updateCanvasConnectTargetsTask");_(this,"onKeyDownHanlder");_(this,"onKeyUpHanlder")}setDom(e){L("relation-graph mounted on:",this.instanceId,e),this.$dom=e}setCanvasDom(e){L("relation-graph canvas dom mounted!"),this.$canvasDom=e,this.$lineTextContainer4NormalLine=null,this.$lineTextContainer4FakeLine=null,this.reinitMutationObservers(),this.getLineTextContainer({isFakeLine:!0}),this.getLineTextContainer({isFakeLine:!1})}getResizeObserver(){return this.resizeObserver||(this.resizeObserver=new ResizeObserver((e,t)=>{for(const n of e){const o=this.resizeListenerMap.get(n.target);o?n.borderBoxSize?o(n.borderBoxSize[0].inlineSize,n.borderBoxSize[0].blockSize):o(n.target.clientWidth,n.target.clientHeight):n.borderBoxSize?this._onNodeDomResize(n.target,n.borderBoxSize[0].inlineSize,n.borderBoxSize[0].blockSize):this._onNodeDomResize(n.target,n.target.clientWidth,n.target.clientHeight)}})),this.resizeObserver}initDom(){this.addResizeListener(this.$dom,(e,t)=>{L("resizeListener:this.$dom"),this.resetViewSize(),this.updateEasyView(),this._rgAsConnectArea&&this.updateCanvasConnectTargetsPosition("View Resize"),this._updateEditingLineView(),this._updateEditingControllerView(),this._dataUpdated(),setTimeout(()=>{L("resizeListener:updateShouldRenderGraphData"),this.emitEvent(I.onViewResize,{width:e,height:t}),this._dataUpdated()},500)}),this._rgAsConnectArea||(this.removeKeyboardListener(),this.addKeyboardListener(),this.removeTrackpadGestureListeners(),this.addTrackpadGestureListeners())}updateCanvasConnectTargetsPosition(e="api"){this.updateConnectTargetsOnCanvas(e,this.$dom.querySelector(".rg-canvas-slot-behind")),this.updateConnectTargetsOnCanvas(e,this.$dom.querySelector(".rg-canvas-slot-above"))}reinitMutationObservers(){this.destroyMutationObserver();const e=this.$canvasDom.querySelector(".rg-nodes-container-wrapper");if(e)this.mutationObserver4Nodes=new MutationObserver(o=>{if(this.dataProvider.getConnectTargets().length>0)for(const s of o){const a=this.getNodeElByChildrenTarget(s.target),d=this.domToNodeIdMap.get(a);d&&this.updateConnectTargetsOnNode("Mutation",d,a)}}),this.mutationObserver4Nodes.observe(e,{childList:!0,subtree:!0,characterData:!0});else throw new Error("MutationObserver:error:Can not find: .rg-nodes-container-wrapper");const t=this.$canvasDom.parentElement.querySelector(".rg-canvas-slot-behind");if(t)this.mutationObserver4CanvasSlotBehind=new MutationObserver(o=>{this.updateConnectTargetsOnCanvas("CanvasBehind-Mutation",t)}),this.mutationObserver4CanvasSlotBehind.observe(t,{childList:!0,subtree:!0,characterData:!0});else throw new Error("MutationObserver:error:Can not find: .rg-canvas-slot-behind");const n=this.$canvasDom.parentElement.querySelector(".rg-canvas-slot-above");n&&(this.mutationObserver4CanvasSlotAbove=new MutationObserver(o=>{this.updateConnectTargetsOnCanvas("CanvasAbove-Mutation",n)}),this.mutationObserver4CanvasSlotAbove.observe(n,{childList:!0,subtree:!0,characterData:!0}))}destroyMutationObserver(){this.mutationObserver4Nodes&&(this.mutationObserver4Nodes.disconnect(),this.mutationObserver4Nodes=void 0),this.mutationObserver4CanvasSlotBehind&&(this.mutationObserver4CanvasSlotBehind.disconnect(),this.mutationObserver4CanvasSlotBehind=void 0),this.mutationObserver4CanvasSlotAbove&&(this.mutationObserver4CanvasSlotAbove.disconnect(),this.mutationObserver4CanvasSlotAbove=void 0)}getTrackpadGestureAnchorView(){const e=this.getViewBoundingClientRect();return e?this._lastMouseClientXy?this.getViewXyByClientXy({x:this._lastMouseClientXy.x,y:this._lastMouseClientXy.y}):{x:e.width/2,y:e.height/2}:{x:0,y:0}}addTrackpadGestureListeners(){this._mouseMoveHandler=e=>{this._lastMouseClientXy={x:e.clientX,y:e.clientY}},this._gestureStartHandler=e=>{const t=e;ge(t)||(t.cancelable&&t.preventDefault(),t.stopPropagation(),this._trackpadGestureActive=!0,this._trackpadGestureStartZoom=this.getOptions().canvasZoom,this._trackpadGestureStartOffset={x:this.getOptions().canvasOffset.x,y:this.getOptions().canvasOffset.y},this._trackpadGestureAnchorView=this.getTrackpadGestureAnchorView())},this._gestureChangeHandler=e=>{const t=e;if(!this._trackpadGestureActive||!this._trackpadGestureAnchorView||!this._trackpadGestureStartOffset)return;t.cancelable&&t.preventDefault(),t.stopPropagation();const n=t.scale;if(!n||!Number.isFinite(n)||n<=0)return;const o=.01;if(Math.abs(n-1)<o)return;const s=this._trackpadGestureStartZoom*n,a=this._trackpadGestureStartZoom/100,d=this.getClampedZoom(s)/100,h=this._trackpadGestureAnchorView.x-(this._trackpadGestureAnchorView.x-this._trackpadGestureStartOffset.x)*(d/a),c=this._trackpadGestureAnchorView.y-(this._trackpadGestureAnchorView.y-this._trackpadGestureStartOffset.y)*(d/a);this.setZoomAndOffset(s,{x:h,y:c})},this._gestureEndHandler=e=>{const t=e;t.cancelable&&t.preventDefault(),t.stopPropagation(),this._trackpadGestureActive=!1,this._trackpadGestureAnchorView=void 0,this._trackpadGestureStartOffset=void 0},this.$dom.addEventListener("mousemove",this._mouseMoveHandler),this.$dom.addEventListener("gesturestart",this._gestureStartHandler),this.$dom.addEventListener("gesturechange",this._gestureChangeHandler),this.$dom.addEventListener("gestureend",this._gestureEndHandler)}removeTrackpadGestureListeners(){this._mouseMoveHandler&&this.$dom.removeEventListener("mousemove",this._mouseMoveHandler),this._gestureStartHandler&&this.$dom.removeEventListener("gesturestart",this._gestureStartHandler),this._gestureChangeHandler&&this.$dom.removeEventListener("gesturechange",this._gestureChangeHandler),this._gestureEndHandler&&this.$dom.removeEventListener("gestureend",this._gestureEndHandler),this._trackpadGestureActive=!1,this._trackpadGestureAnchorView=void 0,this._trackpadGestureStartOffset=void 0,this._mouseMoveHandler=void 0,this._gestureStartHandler=void 0,this._gestureChangeHandler=void 0,this._gestureEndHandler=void 0}addKeyboardListener(){this.onKeyDownHanlder=e=>{ge(e)||(e.code==="Space"&&(e.preventDefault(),this.getOptions().canvasMoveMode===!1&&this.setCanvasMoveMode(!0)),this.emitEvent(I.onKeyboardDown,e))},this.onKeyUpHanlder=e=>{ge(e)||(e.code==="Space"&&(e.preventDefault(),this.getOptions().canvasMoveMode===!0&&this.setCanvasMoveMode(!1)),this.emitEvent(I.onKeyboardUp,e))},this.$dom.addEventListener("keydown",this.onKeyDownHanlder),this.$dom.addEventListener("keyup",this.onKeyUpHanlder)}removeKeyboardListener(){this.onKeyDownHanlder&&this.$dom.removeEventListener("keydown",this.onKeyDownHanlder),this.onKeyUpHanlder&&this.$dom.removeEventListener("keyup",this.onKeyUpHanlder)}addResizeListener(e,t){this.resizeListenerMap.set(e,t),this.getResizeObserver().observe(e)}_onNodeDomResize(e,t,n){if(t===0||n===0)return;const o=this.domToNodeIdMap.get(e);this._onNodeResize(e,o,t,n)}_onNodeResize(e,t,n,o){n===0||o===0||(this.updateConnectTargetsOnNode("Node-Created",t,e),this.updateNodeOffsetSize(t,n,o))}addNodeResizeListener(e,t){this.domToNodeIdMap.set(e,t.id),this._onNodeResize(e,t.id,e.offsetWidth,e.offsetHeight),this.getResizeObserver().observe(e)}removeNodeResizeListener(e){this.domToNodeIdMap.delete(e),e?this.getResizeObserver().unobserve(e):L("removeNodeResizeListener: dom is null or undefined!")}removeResizeListener(e){this.resizeListenerMap.delete(e),this.resizeObserver&&this.resizeObserver.unobserve(e)}destroyResizeObserver(){this.resizeObserver&&this.resizeObserver.disconnect()}getCanvasSlotList(){return this.$dom.querySelectorAll(".rg-map > .rg-map-canvas > .rg-canvas-slot")}getCanvasSlotRectItems(){if(!this.$dom)return[];const e=this.getCanvasSlotList(),t=[];for(const n of e)for(const o of n.children){const s=o,a={x:s.offsetLeft||0,y:s.offsetTop||0,nodeShape:1,el_W:s.scrollWidth,el_H:s.scrollHeight};t.push(a)}return t}}class Do extends Io{constructor(){super()}dataUpdated(){this._requestDataUpdate()}setOptions(i){L("setOptions:",i),this._updateOptions(i),this._dataUpdated()}updateOptions(i){L("updateOptions:",i),this._updateOptions(i),this._dataUpdated()}moveToCenter(i){this._moveToCenter(i),this._dataUpdated()}transToLinker(i=!0){this._rgAsConnectArea=i,this.resetViewSize(),this.updateCanvasConnectTargetsPosition("Linker"),this.removeKeyboardListener(),this._rgAsConnectArea||this.addKeyboardListener(),this._dataUpdated()}setRootNodeId(i){L("setRootNodeId:",i),this.dataProvider.setRootNodeId(i)}getRootNode(){return this.dataProvider.getRootNode()}getCheckedNode(){return this.getNodeById(this.getOptions().checkedNodeId)}getCheckedLine(){const i=this.getLineById(this.getOptions().checkedLineId);return i||this.getFakeLineById(this.getOptions().checkedLineId)}getSelectedNodes(){return this.getNodes().filter(i=>i.selected)}getEditingNodes(){return[...this.getOptions().editingController.nodes]}async setJsonData(i){this._setJsonData(i),await this.doLayout(i.rootId)}async appendJsonData(i,e=!0){L("appendData:",i),this.loadGraphJsonData(i),e&&await this.doLayout()}async applyInitialData(i){L("applyInitialData:",i),await this.setJsonData(i),this.moveToCenter(),this.zoomToFit()}getGraphJsonData(){var o;const i=[],e=[],t=[];this.getNodes().forEach(s=>{const a=Te(s);a&&i.push(a)}),this.getLines().forEach(s=>{const a=be(s);a&&e.push(a)}),this.getFakeLines().forEach(s=>{const a=be(s);a&&t.push(a)});const n={rootId:((o=this.dataProvider.getRootNode())==null?void 0:o.id)||"",nodes:i,lines:e};return t.length>0&&(n.fakeLines=t),n}transRGNodeToJsonObject(i){return Te(i)}transRGLinkToJsonObject(i){return ze(i)}transRGLineToJsonObject(i){return be(i)}getGraphJsonOptions(){const i={},e=["layouter","layoutor","autoLayouting","canvasNVInfo","canvasOffset","canvasZoom","fullscreen","instanceId","layoutClassName","layoutDirection","layoutLabel","layoutName","resetViewSize","viewELSize","viewNVInfo","viewSize","canvasSize","newLinkTemplate","newLineTemplate","newNodeTemplate"],t=this.getOptions();return Object.keys(t).forEach(n=>{e.includes(n)||(i[n]=t[n])}),i}clearGraph(){this._clearGraph(),this._dataUpdated()}printOptions(){this.getGraphJsonOptions()}printData(){this.getGraphJsonData()}printGraphJsonData(){this.printOptions(),this.printData()}}class Lt extends Do{constructor(){super();_(this,"viewComponentUnmounted",!1)}setListeners(e){this.listeners=e}ready(){this.initDom(),this.resetViewSize(),this.addFullscreenListener(),this.emitEvent(I.onReady,this),this.viewComponentUnmounted=!1}beforeUnmount(){this.viewComponentUnmounted=!0,this.removeFullscreenListener(),this.removeKeyboardListener(),this.removeTrackpadGestureListeners(),this.destroyMutationObserver(),this.destroyResizeObserver()}}function wt(l,i=!1){const e=r.markRaw(l?Reflect.construct(l,[]):new Lt);return e._rgAsConnectArea=i,e}function _t(l,i=!1){const e=r.inject(ye,null);return e?e.graphInstance:wt(l,i)}const Fe=l=>({get value(){return l()}});function He(l){return r.defineComponent({name:"RGDataProvider",props:{options:{required:!1,type:Object}},setup(i,{slots:e}){if(!r.inject(ye,null)){const n=r.ref({rootNode:void 0,nodes:[],normalLines:[],fakeLines:[]}),o=r.ref({}),s=r.ref({nodes:[],lines:[],fakeLines:[]}),a=r.ref(null),d=r.ref(null),h=r.ref([]),c=r.ref([]),f=r.ref([]),p=r.ref(new Map),m=r.ref(new Map),u=Fe(()=>s.value.nodes),g=Fe(()=>s.value.lines),y=Fe(()=>s.value.fakeLines),T={store4Options:{set:O=>{}},store4ShouldRenderNodes:{set:O=>{}},store4ShouldRenderLines:{set:O=>{}},store4ShouldRenderFakeLines:{set:O=>{}},optionsRef:o,shouldRenderNodesRef:u,shouldRenderLinesRef:g,shouldRenderFakeLinesRef:y,textContainer4FakeLineRef:a,textContainer4NormalRef:d};l.setReactiveData4Vue3(T,n.value,o.value,{runtimeDATA4Links:f.value,runtimeDATA4ElLineTargets:h.value,runtimeDATA4ConnectTargets:c.value,runtimeDATA4NodeMap:p.value,runtimeDATA4LinkMap:m.value,runtimeDATA4ShouldRenderItems:s.value},(O,b,N)=>{O[b]=r.markRaw(N)}),l.setOptions(i.options||{}),r.provide(ye,{graphInstance:l})}return r.onMounted(()=>{}),()=>e.default?e.default():null}})}const $e={onReady:l=>!0,onNodeClick:(l,i)=>!0,onNodeExpand:(l,i)=>!0,onNodeCollapse:(l,i)=>!0,onLineClick:(l,i,e)=>!0,onNodeDragStart:(l,i)=>!0,onNodeDragEnd:(l,i,e,t)=>!0,onNodeDragging:(l,i,e,t,n,o)=>!0,onCanvasDragEnd:l=>!0,onCanvasDragging:(l,i,e,t)=>!0,onContextmenu:(l,i,e,t,n)=>!0,onFullscreen:(l,i)=>!0,onCanvasClick:l=>!0,onCanvasSelectionEnd:(l,i)=>!0,beforeZoomStart:()=>!0,onZoomEnd:()=>!0,onViewResize:()=>!0,onResizeStart:(l,i)=>!0,beforeNodeResize:(l,i,e,t,n)=>!0,onResizeEnd:(l,i,e,t)=>!0,onLineVertexDropped:l=>!0,beforeCreateLine:l=>!0,onLineBeCreated:l=>!0,beforeAddNodes:l=>!0,beforeAddLines:l=>!0,onKeyboardDown:l=>!0,onKeyboardUp:l=>!0,onCanvasDragStart:(l,i,e)=>!0,onForceLayoutFinish:()=>!0,beforeScrollStart:(l,i,e)=>!0};function Nt({relationGraphCore:l}={}){const i=_t(l),e=He(i);return{RelationGraph:r.defineComponent({name:"RelationGraph",props:{options:{required:!1,type:Object},initialData:{required:!1,type:Object},emitProxy:{required:!1,type:Function}},emits:$e,setup(t,{slots:n,emit:o}){return r.onMounted(()=>{const s=t.emitProxy||o;i.setEventEmitHook((a,...d)=>{s(a,...d)}),Je("Vue3"),t.options&&i.setOptions(t.options||{}),i.ready(),t.initialData&&i.applyInitialData(t.initialData)}),r.onBeforeUnmount(()=>{i.beforeUnmount()}),()=>r.h(e,{options:t.options},{default:()=>r.h(bn,t,n)})}}),graphInstance:i}}const Pe=l=>l,Vo=`graphRef.value.getInstance() will be deprecated
|
|
43
43
|
|
|
44
44
|
It is recommended to use the graphInstance:
|
|
45
45
|
###### Method 1: ######
|