u&&cd})}if(!s)return;for(this.resolveSelectables();!this._selectables.includes(s);){if(!s.parentElement)return;s=s.parentElement}const{stored:r}=this._selection;if(this._emitEvent("start",t),t.shiftKey&&o&&this._latestElement){const l=this._latestElement,[c,h]=l.compareDocumentPosition(s)&4?[s,l]:[l,s],a=[...this._selectables.filter(u=>u.compareDocumentPosition(c)&4&&u.compareDocumentPosition(h)&2),c,h];this.select(a),this._latestElement=l}else r.includes(s)&&(r.length===1||t.ctrlKey||r.every(l=>this._selection.stored.includes(l)))?this.deselect(s):(this.select(s),this._latestElement=s);this._emitEvent("stop",t)}_delayedTapMove(t){const{container:n,document:o,behaviour:{startThreshold:i}}=this._options,{x1:s,y1:r}=this._areaLocation,{x:l,y:c}=oe(t);if(typeof i=="number"&&R(l+c-(s+r))>=i||typeof i=="object"&&R(l-s)>=i.x||R(c-r)>=i.y){if(O(o,["mousemove","touchmove"],this._delayedTapMove,{passive:!1}),this._emitEvent("beforedrag",t)===!1){O(o,["mouseup","touchcancel","touchend"],this._onTapStop);return}W(o,["mousemove","touchmove"],this._onTapMove,{passive:!1}),j(this._area,"display","block"),I(n,o)[0].appendChild(this._clippingElement),this.resolveSelectables(),this._singleClick=!1,this._targetRect=this._targetElement.getBoundingClientRect(),this._scrollAvailable=this._targetElement.scrollHeight!==this._targetElement.clientHeight||this._targetElement.scrollWidth!==this._targetElement.clientWidth,this._scrollAvailable&&(W(o,"wheel",this._manualScroll,{passive:!1}),this._selectables=this._selectables.filter(h=>this._targetElement.contains(h))),this._setupSelectionArea(),this._emitEvent("start",t),this._onTapMove(t)}this._handleMoveEvent(t)}_setupSelectionArea(){const{_clippingElement:t,_targetElement:n,_area:o}=this,i=this._targetRect=n.getBoundingClientRect();this._scrollAvailable?(j(t,{top:i.top,left:i.left,width:i.width,height:i.height}),j(o,{marginTop:-i.top,marginLeft:-i.left})):(j(t,{top:0,left:0,width:"100%",height:"100%"}),j(o,{marginTop:0,marginLeft:0}))}_onTapMove(t){const{x:n,y:o}=oe(t),{_scrollSpeed:i,_areaLocation:s,_options:r,_frame:l}=this,{speedDivider:c}=r.behaviour.scrolling,h=this._targetElement;if(s.x2=n,s.y2=o,this._scrollAvailable&&!this._scrollingActive&&(i.y||i.x)){this._scrollingActive=!0;const a=()=>{if(!i.x&&!i.y){this._scrollingActive=!1;return}const{scrollTop:u,scrollLeft:d}=h;i.y&&(h.scrollTop+=je(i.y/c),s.y1-=h.scrollTop-u),i.x&&(h.scrollLeft+=je(i.x/c),s.x1-=h.scrollLeft-d),l.next(t),requestAnimationFrame(a)};requestAnimationFrame(a)}else l.next(t);this._handleMoveEvent(t)}_handleMoveEvent(t){const{features:n}=this._options;(n.touch&&$t()||this._scrollAvailable&&Dt())&&t.preventDefault()}_onScroll(){const{_scrollDelta:t,_options:{document:n}}=this,{scrollTop:o,scrollLeft:i}=n.scrollingElement??n.body;this._areaLocation.x1+=t.x-i,this._areaLocation.y1+=t.y-o,t.x=i,t.y=o,this._setupSelectionArea(),this._frame.next(null)}_manualScroll(t){const{manualSpeed:n}=this._options.behaviour.scrolling,o=t.deltaY?t.deltaY>0?1:-1:0,i=t.deltaX?t.deltaX>0?1:-1:0;this._scrollSpeed.y+=o*n,this._scrollSpeed.x+=i*n,this._onTapMove(t),t.preventDefault()}_recalculateSelectionAreaRect(){const{_scrollSpeed:t,_areaLocation:n,_areaRect:o,_targetElement:i,_options:s}=this,{scrollTop:r,scrollHeight:l,clientHeight:c,scrollLeft:h,scrollWidth:a,clientWidth:u}=i,d=this._targetRect,{x1:p,y1:g}=n;let{x2:m,y2:f}=n;const{behaviour:{scrolling:{startScrollMargins:v}}}=s;md.right-v.x?(t.x=a-h-u?R(d.left+d.width-m-v.x):0,m=m>d.right?d.right:m):t.x=0,fd.bottom-v.y?(t.y=l-r-c?R(d.top+d.height-f-v.y):0,f=f>d.bottom?d.bottom:f):t.y=0;const y=De(p,m),b=De(g,f),x=$e(p,m),E=$e(g,f);o.x=y,o.y=b,o.width=x-y,o.height=E-b}_redrawSelectionArea(){const{x:t,y:n,width:o,height:i}=this._areaRect,{style:s}=this._area;s.left=`${t}px`,s.top=`${n}px`,s.width=`${o}px`,s.height=`${i}px`}_onTapStop(t,n){var o;const{document:i,features:s}=this._options,{_singleClick:r}=this;O(i,["mousemove","touchmove"],this._delayedTapMove),O(i,["touchmove","mousemove"],this._onTapMove),O(i,["mouseup","touchcancel","touchend"],this._onTapStop),O(i,"scroll",this._onScroll),this._keepSelection(),t&&r&&s.singleTap.allow?this._onSingleTap(t):!r&&!n&&(this._updateElementSelection(),this._emitEvent("stop",t)),this._scrollSpeed.x=0,this._scrollSpeed.y=0,this._scrollAvailable&&O(i,"wheel",this._manualScroll,{passive:!0}),this._clippingElement.remove(),(o=this._frame)==null||o.cancel(),j(this._area,"display","none")}_updateElementSelection(){const{_selectables:t,_options:n,_selection:o,_areaRect:i}=this,{stored:s,selected:r,touched:l}=o,{intersect:c,overlap:h}=n.behaviour,a=h==="invert",u=[],d=[],p=[];for(let m=0;m!r.includes(m)));const g=h==="keep";for(let m=0;m!r.includes(c));switch(t.behaviour.overlap){case"drop":{n.stored=[...l,...r.filter(c=>!s.includes(c))];break}case"invert":{n.stored=[...l,...r.filter(c=>!i.removed.includes(c))];break}case"keep":{n.stored=[...r,...o.filter(c=>!r.includes(c))];break}}}trigger(t,n=!0){this._onTapStart(t,n)}resolveSelectables(){this._selectables=I(this._options.selectables,this._options.document)}clearSelection(t=!0,n=!1){const{selected:o,stored:i,changed:s}=this._selection;s.added=[],s.removed.push(...o,...t?i:[]),n||(this._emitEvent("move",null),this._emitEvent("stop",null)),this._selection={stored:t?[]:i,selected:[],touched:[],changed:{added:[],removed:[]}}}getSelection(){return this._selection.stored}getSelectionArea(){return this._area}cancel(t=!1){this._onTapStop(null,!t)}destroy(){this.cancel(),this.disable(),this._clippingElement.remove(),super.unbindAllListeners()}select(t,n=!1){const{changed:o,selected:i,stored:s}=this._selection,r=I(t,this._options.document).filter(l=>!i.includes(l)&&!s.includes(l));return s.push(...r),i.push(...r),o.added.push(...r),o.removed=[],this._latestElement=void 0,n||(this._emitEvent("move",null),this._emitEvent("stop",null)),r}deselect(t,n=!1){const{selected:o,stored:i,changed:s}=this._selection,r=I(t,this._options.document).filter(l=>o.includes(l)||i.includes(l));r.length&&(this._selection.stored=i.filter(l=>!r.includes(l)),this._selection.selected=o.filter(l=>!r.includes(l)),this._selection.changed.added=[],this._selection.changed.removed.push(...r.filter(l=>!s.removed.includes(l))),this._latestElement=void 0,n||(this._emitEvent("move",null),this._emitEvent("stop",null)))}}N(Oe,"version","3.3.1");function Ot(e){const t=new Oe({selectables:[".map-container me-tpc"],boundaries:[e.container],container:"body",behaviour:{scrolling:{speedDivider:10,manualSpeed:750,startScrollMargins:{x:10,y:10}}}}).on("beforestart",({event:n})=>{if(n.button!==e.mouseSelectionButton||n.target.tagName==="ME-TPC"||n.target.id==="input-box"||n.target.className==="circle")return!1;const o=t.getSelectionArea();return o.style.background="#4f90f22d",o.style.border="1px solid #4f90f2",o.parentElement&&(o.parentElement.style.zIndex="9999"),!0}).on("start",({event:n})=>{!n.ctrlKey&&!n.metaKey&&(e.unselectNode(),e.unselectNodes(),e.unselectSummary(),e.unselectLink(),t.clearSelection(!0,!0))}).on("move",({store:{changed:{added:n,removed:o}}})=>{L.moved=!0;for(const i of n)i.classList.add("selected");for(const i of o)i.classList.remove("selected")}).on("stop",({store:{stored:n}})=>{e.selectNodes(n)});e.selection=t}const At=function(e,t=!0){this.theme=e;const n=this.theme.cssVar,o=Object.keys(n);for(let i=0;i{if(!(t==="parent"&&typeof n!="string"))return n})},initLeft:function(){this.direction=0,this.refresh()},initRight:function(){this.direction=1,this.refresh()},initSide:function(){this.direction=2,this.refresh()},install:function(e){e(this)},refresh:function(e){e&&(e=JSON.parse(JSON.stringify(e)),this.nodeData=e.nodeData,this.linkData=e.linkData||{},this.summaries=e.summaries||[]),D(this.nodeData),this.layout(),this.linkDiv()},scale:function(e){this.scaleVal=e,this.map.style.transform="scale("+e+")"},selectFirstChild:function(){if(!this.currentNode)return;const e=this.currentNode.parentElement.nextSibling;if(e&&e.firstChild){const t=e.firstChild.firstChild.firstChild;this.selectNode(t)}},selectNextSibling:function(){if(!this.currentNode||this.currentNode.dataset.nodeid==="meroot")return!1;const e=this.currentNode.parentElement.parentElement.nextSibling;let t;if(e)t=e.firstChild.firstChild;else return!1;return this.selectNode(t),!0},selectNode:function(e,t,n){if(e){if(console.time("selectNode"),typeof e=="string"){const o=w(e);return o?this.selectNode(o):void 0}this.currentNode&&(this.currentNode.className=""),e.className="selected",e.scrollIntoView({block:"nearest",inline:"nearest"}),this.currentNode=e,t?this.bus.fire("selectNewNode",e.nodeObj):this.bus.fire("selectNode",e.nodeObj,n),console.timeEnd("selectNode")}},selectNodes:function(e){if(e){console.time("selectNodes");for(const t of e)t.className="selected";this.currentNodes=e,this.bus.fire("selectNodes",e.map(t=>t.nodeObj)),console.timeEnd("selectNodes")}},selectParent:function(){if(!this.currentNode||this.currentNode.dataset.nodeid==="meroot")return;const e=this.currentNode.parentElement.parentElement.parentElement.previousSibling;if(e){const t=e.firstChild;this.selectNode(t)}},selectPrevSibling:function(){if(!this.currentNode||this.currentNode.dataset.nodeid==="meroot")return!1;const e=this.currentNode.parentElement.parentElement.previousSibling;let t;if(e)t=e.firstChild.firstChild;else return!1;return this.selectNode(t),!0},setLocale:function(e){this.locale=e,this.refresh()},toCenter:function(){this.container.scrollTo(1e4-this.container.offsetWidth/2,1e4-this.container.offsetHeight/2)},unselectNode:function(){this.currentNode&&(this.currentNode.className=""),this.currentNode=null,this.bus.fire("unselectNode")},unselectNodes:function(){if(this.currentNodes)for(const e of this.currentNodes)e.classList.remove("selected");this.currentNodes=null,this.bus.fire("unselectNodes")}},Symbol.toStringTag,{value:"Module"})),A=e=>{var o;const t=(o=e.parent)==null?void 0:o.children,n=t.indexOf(e);return{siblings:t,index:n}};function Ht(e){const{siblings:t,index:n}=A(e),o=t[n];n===0?(t[n]=t[t.length-1],t[t.length-1]=o):(t[n]=t[n-1],t[n-1]=o)}function Bt(e){const{siblings:t,index:n}=A(e),o=t[n];n===t.length-1?(t[n]=t[0],t[0]=o):(t[n]=t[n+1],t[n+1]=o)}function X(e){const{siblings:t,index:n}=A(e);return t.splice(n,1),t.length}function zt(e,t){const{siblings:n,index:o}=A(e);n.splice(o+1,0,t)}function Rt(e,t){const{siblings:n,index:o}=A(e);n.splice(o,0,t)}function qt(e,t){const{siblings:n,index:o}=A(e);n[o]=t,t.children=[e]}function Ft(e,t){X(e),t.children?t.children.push(e):t.children=[e]}function Vt(e,t){e.direction!==void 0&&(e.direction=t.direction),X(e);const{siblings:n,index:o}=A(t);n.splice(o,0,e)}function Wt(e,t){e.direction!==void 0&&(e.direction=t.direction),X(e);const{siblings:n,index:o}=A(t);n.splice(o+1,0,e)}const Pe=function(e,t){var n,o;if(e===k)return k;if(e===P)return P;if(e===U){const i=((n=document.querySelector(".lhs"))==null?void 0:n.childElementCount)||0,s=((o=document.querySelector(".rhs"))==null?void 0:o.childElementCount)||0;return i<=s?(t.direction=k,k):(t.direction=P,P)}},He=function(e,t){var l,c;if(!e)return null;const n=e.nodeObj;n.expanded===!1&&(this.expandNode(e,!0),e=w(n.id));const o=t||this.generateNewObj();n.children?n.children.push(o):n.children=[o],D(this.nodeData);const i=e.parentElement,{grp:s,top:r}=this.createWrapper(o);if(i.tagName==="ME-PARENT"){if(i.children[1])i.nextSibling.appendChild(s);else{const h=this.createChildren([s]);i.appendChild(ne(!0)),i.insertAdjacentElement("afterend",h)}this.linkDiv(s.offsetParent)}else i.tagName==="ME-ROOT"&&(Pe(this.direction,o)===k?(l=document.querySelector(".lhs"))==null||l.appendChild(s):(c=document.querySelector(".rhs"))==null||c.appendChild(s),this.linkDiv());return{newTop:r,newNodeObj:o}},Be=function(e,t){const n=e.parentNode;if(t===0){const o=n.parentNode.parentNode;o.tagName!=="ME-MAIN"&&o.previousSibling.children[1].remove()}n.parentNode.remove()},ie=function(e){const n=e.parentElement.parentElement.lastElementChild;(n==null?void 0:n.tagName)==="svg"&&(n==null||n.remove())},ze=Object.freeze(Object.defineProperty({__proto__:null,addChild:function(e,t){console.time("addChild");const n=e||this.currentNode;if(!n)return;const o=He.call(this,n,t);if(!o)return;const{newTop:i,newNodeObj:s}=o;this.bus.fire("operation",{name:"addChild",obj:s}),console.timeEnd("addChild"),t||this.editTopic(i.firstChild),this.selectNode(i.firstChild,!0)},beginEdit:function(e){const t=e||this.currentNode;t&&this.editTopic(t)},copyNode:function(e,t){console.time("copyNode");const n=ve(e.nodeObj);me(n);const o=He.call(this,t,n);if(!o)return;const{newNodeObj:i}=o;console.timeEnd("copyNode"),this.bus.fire("operation",{name:"copyNode",obj:i})},insertBefore:function(e,t){const n=e||this.currentNode;if(!n)return;const o=n.nodeObj;if(o.root===!0){this.addChild();return}const i=t||this.generateNewObj();Rt(o,i),D(this.nodeData);const s=n.parentElement;console.time("insertSibling_DOM");const{grp:r,top:l}=this.createWrapper(i);s.parentNode.parentNode.insertBefore(r,s.parentNode),this.linkDiv(r.offsetParent),t||this.editTopic(l.firstChild),this.selectNode(l.firstChild,!0),console.timeEnd("insertSibling_DOM"),this.bus.fire("operation",{name:"insertBefore",obj:i})},insertParent:function(e,t){const n=e||this.currentNode;if(!n)return;ie(n);const o=n.nodeObj;if(o.root===!0)return;const i=t||this.generateNewObj();qt(o,i),D(this.nodeData);const s=n.parentElement.parentElement;console.time("insertParent_DOM");const{grp:r,top:l}=this.createWrapper(i,!0);l.appendChild(ne(!0)),s.insertAdjacentElement("afterend",r);const c=this.createChildren([s]);l.insertAdjacentElement("afterend",c),this.linkDiv(),t||this.editTopic(l.firstChild),this.selectNode(l.firstChild,!0),console.timeEnd("insertParent_DOM"),this.bus.fire("operation",{name:"insertParent",obj:i})},insertSibling:function(e,t){var h,a,u;const n=e||this.currentNode;if(!n)return;const o=n.nodeObj;if(o.root===!0){this.addChild();return}else if(((h=o.parent)==null?void 0:h.root)===!0&&((u=(a=o.parent)==null?void 0:a.children)==null?void 0:u.length)===1){this.addChild(w(o.parent.id));return}const i=t||this.generateNewObj();zt(o,i),D(this.nodeData);const s=n.parentElement;console.time("insertSibling_DOM");const{grp:r,top:l}=this.createWrapper(i);s.parentNode.parentNode.insertBefore(r,s.parentNode.nextSibling),this.linkDiv(r.offsetParent),t||this.editTopic(l.firstChild),this.selectNode(l.firstChild,!0),console.timeEnd("insertSibling_DOM"),this.bus.fire("operation",{name:"insertSibling",obj:i})},moveDownNode:function(e){const t=e||this.currentNode;if(!t)return;const n=t.nodeObj;Bt(n);const o=t.parentNode.parentNode;o.nextSibling?o.nextSibling.insertAdjacentElement("afterend",o):o.parentNode.prepend(o),this.linkDiv(),this.bus.fire("operation",{name:"moveDownNode",obj:n})},moveNode:function(e,t){var l;const n=e.nodeObj,o=t.nodeObj,i=(l=n==null?void 0:n.parent)==null?void 0:l.id;if(o.expanded===!1&&(this.expandNode(t,!0),e=w(n.id),t=w(o.id)),!Je(n,o)){console.warn("Invalid move");return}console.time("moveNode"),Ft(n,o),D(this.nodeData);const s=e.parentElement,r=t.parentElement;if(r.tagName==="ME-PARENT")if(ie(e),r.children[1])r.nextSibling.appendChild(s.parentElement);else{const c=this.createChildren([s.parentElement]);r.appendChild(ne(!0)),r.parentElement.insertBefore(c,r.nextSibling)}else r.tagName==="ME-ROOT"&&(Pe(this.direction,n),r.nextSibling.appendChild(s.parentElement));this.linkDiv(),this.bus.fire("operation",{name:"moveNode",obj:n,toObj:o,originParentId:i}),console.timeEnd("moveNode")},moveNodeAfter:function(e,t){var l;const n=e.nodeObj,o=t.nodeObj,i=(l=n.parent)==null?void 0:l.id;Wt(n,o),D(this.nodeData),ie(e);const s=e.parentElement.parentNode;t.parentElement.parentNode.insertAdjacentElement("afterend",s),this.linkDiv(),this.bus.fire("operation",{name:"moveNodeAfter",obj:n,toObj:o,originParentId:i})},moveNodeBefore:function(e,t){var l;const n=e.nodeObj,o=t.nodeObj,i=(l=n.parent)==null?void 0:l.id;Vt(n,o),D(this.nodeData),ie(e);const s=e.parentElement.parentNode;t.parentElement.parentNode.insertAdjacentElement("beforebegin",s),this.linkDiv(),this.bus.fire("operation",{name:"moveNodeBefore",obj:n,toObj:o,originParentId:i})},moveUpNode:function(e){const t=e||this.currentNode;if(!t)return;const n=t.nodeObj;Ht(n);const o=t.parentNode.parentNode;o.parentNode.insertBefore(o,o.previousSibling),this.linkDiv(),this.bus.fire("operation",{name:"moveUpNode",obj:n})},removeNode:function(e){var r;const t=e||this.currentNode;if(!t)return;const n=t.nodeObj;if(n.root===!0)throw new Error("Can not remove root node");const o=n.parent.children,i=o.findIndex(l=>l===n),s=X(n);if(Be(t,s),o.length!==0){const l=o[i]||o[i-1];this.selectNode(w(l.id))}else this.selectNode(w(n.parent.id));this.linkDiv(),this.bus.fire("operation",{name:"removeNode",obj:n,originIndex:i,originParentId:(r=n==null?void 0:n.parent)==null?void 0:r.id})},removeNodes:function(e){for(const t of e){const n=t.nodeObj;if(n.root===!0)continue;const o=X(n);Be(t,o)}this.linkDiv(),this.bus.fire("operation",{name:"removeNodes",objs:e.map(t=>t.nodeObj)})},reshapeNode:function(e,t){console.log(t);const n=e.nodeObj,o=ve(n);o.style&&t.style&&(t.style=Object.assign(o.style,t.style));const i=Object.assign(n,t);ae(e,i),this.linkDiv(),this.bus.fire("operation",{name:"reshapeNode",obj:i,origin:o})},setNodeTopic:function(e,t){e.text.textContent=t,e.nodeObj.topic=t,this.linkDiv()}},Symbol.toStringTag,{value:"Module"})),Re={create:function(e){return{dom:e,moved:!1,mousedown:!1,handleMouseMove(t){this.mousedown&&(this.moved=!0,this.cb&&this.cb(t.movementX,t.movementY))},handleMouseDown(t){t.button===0&&(this.mousedown=!0)},handleClear(t){this.mousedown=!1},cb:null,init(t,n){this.cb=n,this.handleClear=this.handleClear.bind(this),this.handleMouseMove=this.handleMouseMove.bind(this),this.handleMouseDown=this.handleMouseDown.bind(this),t.addEventListener("mousemove",this.handleMouseMove),t.addEventListener("mouseleave",this.handleClear),t.addEventListener("mouseup",this.handleClear),this.dom.addEventListener("mousedown",this.handleMouseDown)},destory(t){t.removeEventListener("mousemove",this.handleMouseMove),t.removeEventListener("mouseleave",this.handleClear),t.removeEventListener("mouseup",this.handleClear),this.dom.removeEventListener("mousedown",this.handleMouseDown)},clear(){this.moved=!1,this.mousedown=!1}}}};function se(e,t,n){const{offsetLeft:o,offsetTop:i}=V(e.nodes,t),s=t.offsetWidth,r=t.offsetHeight,l=o+s/2,c=i+r/2,h=l+n.x,a=c+n.y;return{w:s,h:r,cx:l,cy:c,ctrlX:h,ctrlY:a}}function K(e){let t,n;const o=(e.cy-e.ctrlY)/(e.ctrlX-e.cx);return o>e.h/e.w||o<-e.h/e.w?e.cy-e.ctrlY<0?(t=e.cx-e.h/2/o,n=e.cy+e.h/2):(t=e.cx+e.h/2/o,n=e.cy-e.h/2):e.cx-e.ctrlX<0?(t=e.cx+e.w/2,n=e.cy-e.w*o/2):(t=e.cx-e.w/2,n=e.cy+e.w*o/2),{x:t,y:n}}const It=function(e,t,n,o){const i=document.createElementNS("http://www.w3.org/2000/svg","text");return C(i,{"text-anchor":"middle",x:t+"",y:n+"",fill:o||"#666"}),i.dataset.type="custom-link",i.innerHTML=e,i},Kt=function(e,t,n,o){if(!e||!t)return;const i=performance.now(),s=se(this,e,n.delta1),r=se(this,t,n.delta2),{x:l,y:c}=K(s),{ctrlX:h,ctrlY:a}=s,{ctrlX:u,ctrlY:d}=r,{x:p,y:g}=K(r),m=ge(u,d,p,g),f=dt(`M ${l} ${c} C ${h} ${a} ${u} ${d} ${p} ${g}`,`M ${m.x1} ${m.y1} L ${p} ${g} L ${m.x2} ${m.y2}`),v=l/8+h*3/8+u*3/8+p/8,y=c/8+a*3/8+d*3/8+g/8,b=It(n.label,v,y,this.theme.cssVar["--color"]);f.appendChild(b),f.linkObj=n,f.dataset.linkid=n.id,this.linkSvgGroup.appendChild(f),o||(this.linkData[n.id]=n,this.currentLink=f,this.showLinkController(n,s,r));const x=performance.now();console.log(`DrawCustomLink Execution time: ${x-i} ms`)},Ut=function(e,t){const n={id:Y(),label:"Custom Link",from:e.nodeObj.id,to:t.nodeObj.id,delta1:{x:0,y:-200},delta2:{x:0,y:-200}};this.drawCustomLink(e,t,n),this.bus.fire("operation",{name:"createCustomLink",obj:n})},Yt=function(e){let t;if(e?t=e:t=this.currentLink,!t)return;this.hideLinkController();const n=t.linkObj.id;delete this.linkData[n],t.remove(),this.bus.fire("operation",{name:"removeCustomLink",obj:{id:n}})},Gt=function(e){this.currentLink=e;const t=e.linkObj,n=w(t.from),o=w(t.to),i=se(this,n,t.delta1),s=se(this,o,t.delta2);this.showLinkController(t,i,s)},Xt=function(){this.currentLink=null,this.hideLinkController()},Jt=function(){this.linkController.style.display="none",this.P2.style.display="none",this.P3.style.display="none"},Qt=function(e,t,n){var u;this.linkController.style.display="initial",this.P2.style.display="initial",this.P3.style.display="initial",this.nodes.appendChild(this.linkController),this.nodes.appendChild(this.P2),this.nodes.appendChild(this.P3);let{x:o,y:i}=K(t),{ctrlX:s,ctrlY:r}=t,{ctrlX:l,ctrlY:c}=n,{x:h,y:a}=K(n);this.P2.style.cssText=`top:${r}px;left:${s}px;`,this.P3.style.cssText=`top:${c}px;left:${l}px;`,C(this.line1,{x1:o+"",y1:i+"",x2:s+"",y2:r+""}),C(this.line2,{x1:l+"",y1:c+"",x2:h+"",y2:a+""}),this.helper1&&(this.helper1.destory(this.map),(u=this.helper2)==null||u.destory(this.map)),this.helper1=Re.create(this.P2),this.helper2=Re.create(this.P3),this.helper1.init(this.map,(d,p)=>{var v;s=s+d/this.scaleVal,r=r+p/this.scaleVal;const g=K({...t,ctrlX:s,ctrlY:r});o=g.x,i=g.y;const m=o/8+s*3/8+l*3/8+h/8,f=i/8+r*3/8+c*3/8+a/8;this.P2.style.top=r+"px",this.P2.style.left=s+"px",(v=this.currentLink)==null||v.children[0].setAttribute("d",`M ${o} ${i} C ${s} ${r} ${l} ${c} ${h} ${a}`),C(this.currentLink.children[2],{x:m+"",y:f+""}),C(this.line1,{x1:o+"",y1:i+"",x2:s+"",y2:r+""}),e.delta1.x=s-t.cx,e.delta1.y=r-t.cy}),this.helper2.init(this.map,(d,p)=>{var y,b;l=l+d/this.scaleVal,c=c+p/this.scaleVal;const g=K({...n,ctrlX:l,ctrlY:c});h=g.x,a=g.y;const m=o/8+s*3/8+l*3/8+h/8,f=i/8+r*3/8+c*3/8+a/8,v=ge(l,c,h,a);this.P3.style.top=c+"px",this.P3.style.left=l+"px",(y=this.currentLink)==null||y.children[0].setAttribute("d",`M ${o} ${i} C ${s} ${r} ${l} ${c} ${h} ${a}`),(b=this.currentLink)==null||b.children[1].setAttribute("d",`M ${v.x1} ${v.y1} L ${h} ${a} L ${v.x2} ${v.y2}`),C(this.currentLink.children[2],{x:m+"",y:f+""}),C(this.line2,{x1:l+"",y1:c+"",x2:h+"",y2:a+""}),e.delta2.x=l-n.cx,e.delta2.y=c-n.cy})};function Zt(){this.linkSvgGroup.innerHTML="";for(const e in this.linkData){const t=this.linkData[e];try{this.drawCustomLink(w(t.from),w(t.to),t,!0)}catch{console.warn("Node may not be expanded")}}this.nodes.appendChild(this.linkSvgGroup)}function en(e){if(console.time("editSummary"),!e)return;const t=e.children[2];console.log(t,e),xe(this,t,n=>{var s;const o=e.linkObj,i=((s=n.textContent)==null?void 0:s.trim())||"";i===""?o.label=origin:o.label=i,n.remove(),i!==origin&&(t.innerHTML=o.label,this.linkDiv(),this.bus.fire("operation",{name:"finishEditCustomLinkLabel",obj:o}))}),console.timeEnd("editSummary")}function tn(){for(const e in this.linkData){const t=this.linkData[e];(!ee(t.from,this.nodeData)||!ee(t.to,this.nodeData))&&delete this.linkData[t.id]}}const nn=Object.freeze(Object.defineProperty({__proto__:null,createLink:Ut,drawCustomLink:Kt,editCutsomLinkLabel:en,hideLinkController:Jt,removeLink:Yt,renderCustomLink:Zt,selectLink:Gt,showLinkController:Qt,tidyCustomLink:tn,unselectLink:Xt},Symbol.toStringTag,{value:"Module"})),on=function(e){var c,h;if(e.length===0)throw new Error("No selected node.");if(e.length===1){const a=e[0].nodeObj,u=e[0].nodeObj.parent;if(!u)throw new Error("Can not select root node.");const d=u.children.findIndex(p=>a===p);return{parent:u.id,start:d,end:d}}let t=0;const n=e.map(a=>{let u=a.nodeObj;const d=[];for(;u.parent;){const p=u.parent,g=p.children,m=g==null?void 0:g.indexOf(u);u=p,d.unshift({node:u,index:m})}return d.length>t&&(t=d.length),d});let o=0;e:for(;oa[o-1].index).sort(),s=i[0]||0,r=i[i.length-1]||0,l=n[0][o-1].node;if(l.root)throw new Error("Please select nodes in the same main topic.");return{parent:l.id,start:s,end:r}},sn=function(e){const t=document.createElementNS("http://www.w3.org/2000/svg","g");return t.setAttribute("id",e),t},qe=function(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","path");return C(n,{d:e,stroke:t||"#666",fill:"none","stroke-linecap":"round","stroke-width":"2"}),n},Fe=function(e,t,n,o,i){const s=document.createElementNS("http://www.w3.org/2000/svg","text");return C(s,{"text-anchor":o,x:t+"",y:n+"",fill:i||"#666"}),s.innerHTML=e,s},rn=e=>w(e).parentElement.parentElement,ln=function({parent:e,start:t}){var s,r;const n=w(e),o=n.nodeObj;let i;return o.root===!0?i=(s=w(o.children[t].id).closest("me-main"))==null?void 0:s.className:i=(r=n.closest("me-main"))==null?void 0:r.className,i},Ve=function(e,t){var _;const{id:n,text:o,parent:i,start:s,end:r}=t,l=e.nodes,h=w(i).nodeObj,a=ln(t);let u=1/0,d=0,p=0,g=0;for(let q=s;q<=r;q++){const Q=(_=h.children)==null?void 0:_[q];if(!Q)return console.warn("Child not found"),e.removeSummary(n),null;const F=rn(Q.id),{offsetLeft:le,offsetTop:Ue}=V(l,F);q===s&&(p=Ue),q===r&&(g=Ue+F.offsetHeight),led&&(d=F.offsetWidth+le)}let m,f;const v=p+10,y=g+10,b=(v+y)/2,x=e.theme.cssVar["--color"];a==="lhs"?(m=qe(`M ${u+10} ${v} c -5 0 -10 5 -10 10 L ${u} ${y-10} c 0 5 5 10 10 10 M ${u} ${b} h -10`,x),f=Fe(o,u-20,b+6,"end",x)):(m=qe(`M ${d-10} ${v} c 5 0 10 5 10 10 L ${d} ${y-10} c 0 5 -5 10 -10 10 M ${d} ${b} h 10`,x),f=Fe(o,d+20,b+6,"start",x));const E=sn("s-"+n);return E.appendChild(m),E.appendChild(f),E.summaryObj=t,e.summarySvg.appendChild(E),E},cn=Object.freeze(Object.defineProperty({__proto__:null,createSummary:function(){let e=[];this.currentNode?e=[this.currentNode]:this.currentNodes&&(e=this.currentNodes);const{parent:t,start:n,end:o}=on(e),i={id:Y(),parent:t,start:n,end:o,text:"summary"},s=Ve(this,i);this.summaries.push(i),this.editSummary(s),this.bus.fire("operation",{name:"createSummary",obj:i})},editSummary:function(e){if(console.time("editSummary"),!e)return;const t=e.childNodes[1];xe(this,t,n=>{var s;const o=e.summaryObj,i=((s=n.textContent)==null?void 0:s.trim())||"";i===""?o.text=origin:o.text=i,n.remove(),i!==origin&&(t.innerHTML=o.text,this.linkDiv(),this.bus.fire("operation",{name:"finishEditSummary",obj:o}))}),console.timeEnd("editSummary")},removeSummary:function(e){var n;const t=this.summaries.findIndex(o=>o.id===e);t>-1&&(this.summaries.splice(t,1),(n=document.querySelector("#s-"+e))==null||n.remove()),this.bus.fire("operation",{name:"removeSummary",obj:{id:e}})},renderSummary:function(){this.summarySvg.innerHTML="",this.summaries.forEach(e=>{try{Ve(this,e)}catch{console.warn("Node may not be expanded")}}),this.nodes.insertAdjacentElement("beforeend",this.summarySvg)},selectSummary:function(e){const t=e.children[1].getBBox(),n=6,o=3,i=document.createElementNS("http://www.w3.org/2000/svg","rect");C(i,{x:t.x-n+"",y:t.y-n+"",width:t.width+n*2+"",height:t.height+n*2+"",rx:o+"",stroke:this.theme.cssVar["--selected"]||"#4dc4ff","stroke-width":"2",fill:"none"}),i.classList.add("selected"),e.appendChild(i),this.currentSummary=e},unselectSummary:function(){var e,t;(t=(e=this.currentSummary)==null?void 0:e.querySelector("rect"))==null||t.remove(),this.currentSummary=null}},Symbol.toStringTag,{value:"Module"}));function an(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","svg");return C(n,{version:"1.1",xmlns:"http://www.w3.org/2000/svg",height:e,width:t}),n}function dn(e,t){return(parseInt(e)-parseInt(t))/2}function hn(e,t,n,o){const i=document.createElementNS("http://www.w3.org/2000/svg","g");let s="";return e.text?s=e.text.textContent:s=e.childNodes[0].textContent,s.split(`
`).forEach((l,c)=>{const h=document.createElementNS("http://www.w3.org/2000/svg","text");C(h,{x:n+parseInt(t.paddingLeft)+"",y:o+parseInt(t.paddingTop)+dn(t.lineHeight,t.fontSize)*(c+1)+parseFloat(t.fontSize)*(c+1)+"","text-anchor":"start","font-family":t.fontFamily,"font-size":`${t.fontSize}`,"font-weight":`${t.fontWeight}`,fill:`${t.color}`}),h.innerHTML=l,i.appendChild(h)}),i}function un(e,t,n,o){let i="";e.text?i=e.text.textContent:i=e.childNodes[0].textContent;const s=document.createElementNS("http://www.w3.org/2000/svg","foreignObject");C(s,{x:n+parseInt(t.paddingLeft)+"",y:o+parseInt(t.paddingTop)+"",width:t.width,height:t.height});const r=document.createElement("div");return C(r,{xmlns:"http://www.w3.org/1999/xhtml",style:`font-family: ${t.fontFamily}; font-size: ${t.fontSize}; font-weight: ${t.fontWeight}; color: ${t.color}; white-space: pre-wrap;`}),r.innerHTML=i,s.appendChild(r),s}function ue(e,t,n=!1){const o=getComputedStyle(t),{offsetLeft:i,offsetTop:s}=V(e.nodes,t),r=document.createElementNS("http://www.w3.org/2000/svg","rect");C(r,{x:i+"",y:s+"",rx:o.borderRadius,ry:o.borderRadius,width:o.width,height:o.height,fill:o.backgroundColor,stroke:o.borderColor,"stroke-width":o.borderWidth});const l=document.createElementNS("http://www.w3.org/2000/svg","g");l.appendChild(r);let c;return n?c=un(t,o,i,s):c=hn(t,o,i,s),l.appendChild(c),l}function fn(e,t){const n=getComputedStyle(t),{offsetLeft:o,offsetTop:i}=V(e.nodes,t),s=document.createElementNS("http://www.w3.org/2000/svg","a"),r=document.createElementNS("http://www.w3.org/2000/svg","text");return C(r,{x:o+"",y:i+parseInt(n.fontSize)+"","text-anchor":"start","font-family":n.fontFamily,"font-size":`${n.fontSize}`,"font-weight":`${n.fontWeight}`,fill:`${n.color}`}),r.innerHTML=t.textContent,s.appendChild(r),s.setAttribute("href",t.href),s}const re=100,pn='',We=(e,t=!1)=>{var u,d,p;const n=e.nodes,o=n.offsetHeight+re*2,i=n.offsetWidth+re*2,s=an(o+"px",i+"px"),r=document.createElementNS("http://www.w3.org/2000/svg","svg"),l=document.createElementNS("http://www.w3.org/2000/svg","rect");C(l,{x:"0",y:"0",width:`${i}`,height:`${o}`,fill:e.theme.cssVar["--bgcolor"]}),s.appendChild(l),n.querySelectorAll(".subLines").forEach(g=>{const m=g.cloneNode(!0),{offsetLeft:f,offsetTop:v}=V(n,g.parentElement);m.setAttribute("x",`${f}`),m.setAttribute("y",`${v}`),r.appendChild(m)});const c=(u=n.querySelector(".lines"))==null?void 0:u.cloneNode(!0);c&&r.appendChild(c);const h=(d=n.querySelector(".topiclinks"))==null?void 0:d.cloneNode(!0);h&&r.appendChild(h);const a=(p=n.querySelector(".summary"))==null?void 0:p.cloneNode(!0);return a&&r.appendChild(a),n.querySelectorAll("me-tpc").forEach(g=>{r.appendChild(ue(e,g,!t))}),n.querySelectorAll(".tags > span").forEach(g=>{r.appendChild(ue(e,g))}),n.querySelectorAll(".icons > span").forEach(g=>{r.appendChild(ue(e,g))}),n.querySelectorAll(".hyper-link").forEach(g=>{r.appendChild(fn(e,g))}),C(r,{x:re+"",y:re+"",overflow:"visible"}),s.appendChild(r),pn+s.outerHTML};function mn(e){return new Promise((t,n)=>{const o=new FileReader;o.onload=i=>{t(i.target.result)},o.onerror=i=>{n(i)},o.readAsDataURL(e)})}const gn=Object.freeze(Object.defineProperty({__proto__:null,exportPng:async function(e=!1){const t=We(this,e),n=new Blob([t],{type:"image/svg+xml"}),o=await mn(n);return new Promise((i,s)=>{const r=new Image;r.setAttribute("crossOrigin","anonymous"),r.onload=()=>{const l=document.createElement("canvas");l.width=r.width,l.height=r.height,l.getContext("2d").drawImage(r,0,0),l.toBlob(i,"image/png",1)},r.src=o,r.onerror=s})},exportSvg:function(e=!1){const t=We(this,e);return new Blob([t],{type:"image/svg+xml"})}},Symbol.toStringTag,{value:"Module"}));function vn(e,t){return async function(...n){const o=this.before[t];o&&!await o.apply(this,n)||e.apply(this,n)}}const Ie=Object.keys(ze),Ke={};for(let e=0;e({nodeData:{id:Y(),topic:e||"new topic",root:!0,children:[]},linkData:{}}),M}();