mind-elixir 4.0.0 → 4.0.1
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/dist/MindElixir.iife.js
CHANGED
|
@@ -8,5 +8,5 @@ var MindElixir=function(){"use strict";const jn="";(function(e){var t,n,o,s,i,r,
|
|
|
8
8
|
`;function n(o,s){for(let i=0;i<o.length;i++)s<=6?t+="".padStart(s,"#")+" "+o[i].topic+`
|
|
9
9
|
|
|
10
10
|
`:t+="".padStart(s-7," ")+"- "+o[i].topic+`
|
|
11
|
-
`,o[i].children&&n(o[i].children||[],s+1)}return n(e.children||[],2),t},getDataString:function(){const e=He(this);return JSON.stringify(e,(t,n)=>{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.arrows=e.arrows||[],this.summaries=e.summaries||[]),D(this.nodeData),this.layout(),this.linkDiv()},scale:function(e){this.scaleVal=e,this.map.style.transform="scale("+e+")"},selectNode:function(e,t,n){if(e){if(console.time("selectNode"),this.clearSelection(),typeof e=="string"){const o=C(e);return o?this.selectNode(o):void 0}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){console.time("selectNodes"),this.clearSelection();for(const t of e)t.className="selected";this.currentNodes=e,this.bus.fire("selectNodes",e.map(t=>t.nodeObj)),console.timeEnd("selectNodes")},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"})),W=e=>{var o;const t=(o=e.parent)==null?void 0:o.children,n=t.indexOf(e);return{siblings:t,index:n}};function Rt(e){const{siblings:t,index:n}=W(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 qt(e){const{siblings:t,index:n}=W(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 me(e){const{siblings:t,index:n}=W(e);return t.splice(n,1),t.length}function Ft(e,t,n){const{siblings:o,index:s}=W(n);t==="before"?o.splice(s,0,e):o.splice(s+1,0,e)}function It(e,t){const{siblings:n,index:o}=W(e);n[o]=t,t.children=[e]}function Be(e,t,n){if(me(t),e==="in")n.children?n.children.push(t):n.children=[t];else{t.direction!==void 0&&(t.direction=n.direction);const{siblings:o,index:s}=W(n);e==="before"?o.splice(s,0,t):o.splice(s+1,0,t)}}const Vt=function(e,t){var n,o;if(e===L)return L;if(e===P)return P;if(e===J){const s=((n=document.querySelector(".lhs"))==null?void 0:n.childElementCount)||0,i=((o=document.querySelector(".rhs"))==null?void 0:o.childElementCount)||0;return s<=i?(t.direction=L,L):(t.direction=P,P)}},ze=function(e,t,n){var i,r;const o=n.children[0].children[0],s=t.parentElement;if(s.tagName==="ME-PARENT"){if(oe(o),s.children[1])s.nextSibling.appendChild(n);else{const l=e.createChildren([n]);s.appendChild(ue(!0)),s.insertAdjacentElement("afterend",l)}e.linkDiv(n.offsetParent)}else s.tagName==="ME-ROOT"&&(Vt(e.direction,o.nodeObj)===L?(i=document.querySelector(".lhs"))==null||i.appendChild(n):(r=document.querySelector(".rhs"))==null||r.appendChild(n),e.linkDiv())},ge=function(e,t,n){if(!t)return null;const o=t.nodeObj;o.expanded===!1&&(e.expandNode(t,!0),t=C(o.id));const s=n||e.generateNewObj();o.children?o.children.push(s):o.children=[s],D(e.nodeData);const{grp:i,top:r}=e.createWrapper(s);return ze(e,t,i),{newTop:r,newNodeObj:s}},Re=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()},qe={before:"beforebegin",after:"afterend"},oe=function(e){const n=e.parentElement.parentElement.lastElementChild;(n==null?void 0:n.tagName)==="svg"&&(n==null||n.remove())},Wt=function(e,t){const n=e.nodeObj,o=ae(n);o.style&&t.style&&(t.style=Object.assign(o.style,t.style));const s=Object.assign(n,t);he(e,s),this.linkDiv(),this.bus.fire("operation",{name:"reshapeNode",obj:s,origin:o})},Kt=function(e,t,n){var h,a,u;const o=t||this.currentNode;if(!o)return;const s=o.nodeObj;if(s.root===!0){this.addChild();return}else if(((h=s.parent)==null?void 0:h.root)===!0&&((u=(a=s.parent)==null?void 0:a.children)==null?void 0:u.length)===1){this.addChild(C(s.parent.id));return}const i=n||this.generateNewObj();Ft(i,e,s),D(this.nodeData);const r=o.parentElement;console.time("insertSibling_DOM");const{grp:l,top:c}=this.createWrapper(i);r.parentElement.insertAdjacentElement(qe[e],l),this.linkDiv(l.offsetParent),n||this.editTopic(c.firstChild),this.selectNode(c.firstChild,!0),console.timeEnd("insertSibling_DOM"),this.bus.fire("operation",{name:"insertSibling",type:e,obj:i})},Ut=function(e,t){const n=e||this.currentNode;if(!n)return;oe(n);const o=n.nodeObj;if(o.root===!0)return;const s=t||this.generateNewObj();It(o,s),D(this.nodeData);const i=n.parentElement.parentElement;console.time("insertParent_DOM");const{grp:r,top:l}=this.createWrapper(s,!0);l.appendChild(ue(!0)),i.insertAdjacentElement("afterend",r);const c=this.createChildren([i]);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:s})},Yt=function(e,t){console.time("addChild");const n=e||this.currentNode;if(!n)return;const o=ge(this,n,t);if(!o)return;const{newTop:s,newNodeObj:i}=o;this.bus.fire("operation",{name:"addChild",obj:i}),console.timeEnd("addChild"),t||this.editTopic(s.firstChild),this.selectNode(s.firstChild,!0)},Xt=function(e,t){console.time("copyNode");const n=ae(e.nodeObj);ce(n);const o=ge(this,t,n);if(!o)return;const{newNodeObj:s}=o;console.timeEnd("copyNode"),this.selectNode(C(s.id)),this.bus.fire("operation",{name:"copyNode",obj:s})},Gt=function(e,t){e=ee(e);const n=[];for(let o=0;o<e.length;o++){const s=e[o],i=ae(s.nodeObj);ce(i);const r=ge(this,t,i);if(!r)return;const{newNodeObj:l}=r;n.push(l)}this.selectNodes(n.map(o=>C(o.id))),this.bus.fire("operation",{name:"copyNodes",objs:n})},Jt=function(e){const t=e||this.currentNode;if(!t)return;const n=t.nodeObj;Rt(n);const o=t.parentNode.parentNode;o.parentNode.insertBefore(o,o.previousSibling),this.linkDiv(),this.bus.fire("operation",{name:"moveUpNode",obj:n})},Qt=function(e){const t=e||this.currentNode;if(!t)return;const n=t.nodeObj;qt(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})},Zt=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,s=o.findIndex(l=>l===n),i=me(n);if(Re(t,i),o.length!==0){const l=o[s]||o[s-1];this.selectNode(C(l.id))}else this.selectNode(C(n.parent.id));this.linkDiv(),this.bus.fire("operation",{name:"removeNode",obj:n,originIndex:s,originParentId:(r=n==null?void 0:n.parent)==null?void 0:r.id})},en=function(e){e=ee(e);for(const t of e){const n=t.nodeObj;if(n.root===!0)continue;const o=me(n);Re(t,o)}this.linkDiv(),this.bus.fire("operation",{name:"removeNodes",objs:e.map(t=>t.nodeObj)})},tn=function(e,t){e=ee(e);const n=t.nodeObj;n.expanded===!1&&(this.expandNode(t,!0),t=C(n.id)),console.time("moveNodeIn");for(const o of e){const s=o.nodeObj;Be("in",s,n),D(this.nodeData);const i=o.parentElement;ze(this,t,i.parentElement)}this.linkDiv(),this.bus.fire("operation",{name:"moveNodeIn",objs:e.map(o=>o.nodeObj),toObj:n}),console.timeEnd("moveNodeIn")},Fe=(e,t,n,o)=>{e=ee(e),t==="after"&&(e=e.reverse());const s=n.nodeObj;for(const i of e){const r=i.nodeObj;Be(t,r,s),D(o.nodeData),oe(i);const l=i.parentElement.parentNode;n.parentElement.parentNode.insertAdjacentElement(qe[t],l)}o.linkDiv(),o.bus.fire("operation",{name:t==="before"?"moveNodeBefore":"moveNodeAfter",objs:e.map(i=>i.nodeObj),toObj:s})},Ie=Object.freeze(Object.defineProperty({__proto__:null,addChild:Yt,beginEdit:function(e){const t=e||this.currentNode;t&&(t.nodeObj.dangerouslySetInnerHTML||this.editTopic(t))},copyNode:Xt,copyNodes:Gt,insertParent:Ut,insertSibling:Kt,mainToSub:oe,moveDownNode:Qt,moveNodeAfter:function(e,t){Fe(e,"after",t,this)},moveNodeBefore:function(e,t){Fe(e,"before",t,this)},moveNodeIn:tn,moveUpNode:Jt,removeNode:Zt,removeNodes:en,reshapeNode:Wt,setNodeTopic:function(e,t){e.text.textContent=t,e.nodeObj.topic=t,this.linkDiv()}},Symbol.toStringTag,{value:"Module"})),Ve={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:s}=j(e.nodes,t),i=t.offsetWidth,r=t.offsetHeight,l=o+i/2,c=s+r/2,h=l+n.x,a=c+n.y;return{w:i,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 nn=function(e,t,n,o){const s=document.createElementNS("http://www.w3.org/2000/svg","text");return E(s,{"text-anchor":"middle",x:t+"",y:n+"",fill:o||"#666"}),s.dataset.type="custom-link",s.innerHTML=e,s},We=function(e,t,n,o,s){if(!t||!n)return;const i=performance.now(),r=se(e,t,o.delta1),l=se(e,n,o.delta2),{x:c,y:h}=K(r),{ctrlX:a,ctrlY:u}=r,{ctrlX:d,ctrlY:m}=l,{x:g,y:p}=K(l),f=ye(d,m,g,p),v=ft(`M ${c} ${h} C ${a} ${u} ${d} ${m} ${g} ${p}`,`M ${f.x1} ${f.y1} L ${g} ${p} L ${f.x2} ${f.y2}`),b=c/8+a*3/8+d*3/8+g/8,y=h/8+u*3/8+m*3/8+p/8,x=nn(o.label,b,y,e.theme.cssVar["--color"]);v.appendChild(x),v.arrowObj=o,v.dataset.linkid=o.id,e.linkSvgGroup.appendChild(v),s||(e.arrows.push(o),e.currentArrow=v,Ue(e,o,r,l));const w=performance.now();console.log(`DrawArrow Execution time: ${w-i} ms`)},on=function(e,t){const n={id:U(),label:"Custom Link",from:e.nodeObj.id,to:t.nodeObj.id,delta1:{x:0,y:-200},delta2:{x:0,y:-200}};We(this,e,t,n),this.bus.fire("operation",{name:"createArrow",obj:n})},sn=function(e){let t;if(e?t=e:t=this.currentArrow,!t)return;Ke(this);const n=t.arrowObj.id;this.arrows=this.arrows.filter(o=>o.id!==n),t.remove(),this.bus.fire("operation",{name:"removeArrow",obj:{id:n}})},rn=function(e){this.currentArrow=e;const t=e.arrowObj,n=C(t.from),o=C(t.to),s=se(this,n,t.delta1),i=se(this,o,t.delta2);Ue(this,t,s,i)},ln=function(){this.currentArrow=null,Ke(this)},Ke=function(e){e.linkController.style.display="none",e.P2.style.display="none",e.P3.style.display="none"},Ue=function(e,t,n,o){var d;e.linkController.style.display="initial",e.P2.style.display="initial",e.P3.style.display="initial",e.nodes.appendChild(e.linkController),e.nodes.appendChild(e.P2),e.nodes.appendChild(e.P3);let{x:s,y:i}=K(n),{ctrlX:r,ctrlY:l}=n,{ctrlX:c,ctrlY:h}=o,{x:a,y:u}=K(o);e.P2.style.cssText=`top:${l}px;left:${r}px;`,e.P3.style.cssText=`top:${h}px;left:${c}px;`,E(e.line1,{x1:s+"",y1:i+"",x2:r+"",y2:l+""}),E(e.line2,{x1:c+"",y1:h+"",x2:a+"",y2:u+""}),e.helper1&&(e.helper1.destory(e.map),(d=e.helper2)==null||d.destory(e.map)),e.helper1=Ve.create(e.P2),e.helper2=Ve.create(e.P3),e.helper1.init(e.map,(m,g)=>{var b;r=r+m/e.scaleVal,l=l+g/e.scaleVal;const p=K({...n,ctrlX:r,ctrlY:l});s=p.x,i=p.y;const f=s/8+r*3/8+c*3/8+a/8,v=i/8+l*3/8+h*3/8+u/8;e.P2.style.top=l+"px",e.P2.style.left=r+"px",(b=e.currentArrow)==null||b.children[0].setAttribute("d",`M ${s} ${i} C ${r} ${l} ${c} ${h} ${a} ${u}`),E(e.currentArrow.children[2],{x:f+"",y:v+""}),E(e.line1,{x1:s+"",y1:i+"",x2:r+"",y2:l+""}),t.delta1.x=r-n.cx,t.delta1.y=l-n.cy}),e.helper2.init(e.map,(m,g)=>{var y,x;c=c+m/e.scaleVal,h=h+g/e.scaleVal;const p=K({...o,ctrlX:c,ctrlY:h});a=p.x,u=p.y;const f=s/8+r*3/8+c*3/8+a/8,v=i/8+l*3/8+h*3/8+u/8,b=ye(c,h,a,u);e.P3.style.top=h+"px",e.P3.style.left=c+"px",(y=e.currentArrow)==null||y.children[0].setAttribute("d",`M ${s} ${i} C ${r} ${l} ${c} ${h} ${a} ${u}`),(x=e.currentArrow)==null||x.children[1].setAttribute("d",`M ${b.x1} ${b.y1} L ${a} ${u} L ${b.x2} ${b.y2}`),E(e.currentArrow.children[2],{x:f+"",y:v+""}),E(e.line2,{x1:c+"",y1:h+"",x2:a+"",y2:u+""}),t.delta2.x=c-o.cx,t.delta2.y=h-o.cy})};function cn(){this.linkSvgGroup.innerHTML="";for(let e=0;e<this.arrows.length;e++){const t=this.arrows[e];try{We(this,C(t.from),C(t.to),t,!0)}catch{console.warn("Node may not be expanded")}}this.nodes.appendChild(this.linkSvgGroup)}function an(e){if(console.time("editSummary"),!e)return;const t=e.children[2];console.log(t,e),Ne(this,t,n=>{var i;const o=e.arrowObj,s=((i=n.textContent)==null?void 0:i.trim())||"";s===""?o.label=origin:o.label=s,n.remove(),s!==origin&&(t.innerHTML=o.label,this.linkDiv(),this.bus.fire("operation",{name:"finishEditArrowLabel",obj:o}))}),console.timeEnd("editSummary")}function dn(){this.arrows=this.arrows.filter(e=>Z(e.from,this.nodeData)&&Z(e.to,this.nodeData))}const hn=Object.freeze(Object.defineProperty({__proto__:null,createArrow:on,editArrowLabel:an,removeArrow:sn,renderArrow:cn,selectArrow:rn,tidyArrow:dn,unselectArrow:ln},Symbol.toStringTag,{value:"Module"})),un=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(m=>a===m);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 m=u.parent,g=m.children,p=g==null?void 0:g.indexOf(u);u=m,d.unshift({node:u,index:p})}return d.length>t&&(t=d.length),d});let o=0;e:for(;o<t;o++){const a=(c=n[0][o])==null?void 0:c.node;for(let u=1;u<n.length;u++)if(((h=n[u][o])==null?void 0:h.node)!==a)break e}if(!o)throw new Error("Can not select root node.");const s=n.map(a=>a[o-1].index).sort(),i=s[0]||0,r=s[s.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:i,end:r}},fn=function(e){const t=document.createElementNS("http://www.w3.org/2000/svg","g");return t.setAttribute("id",e),t},Ye=function(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","path");return E(n,{d:e,stroke:t||"#666",fill:"none","stroke-linecap":"round","stroke-width":"2"}),n},Xe=function(e,t,n,o,s){const i=document.createElementNS("http://www.w3.org/2000/svg","text");return E(i,{"text-anchor":o,x:t+"",y:n+"",fill:s||"#666"}),i.innerHTML=e,i},pn=e=>C(e).parentElement.parentElement,mn=function({parent:e,start:t}){var i,r;const n=C(e),o=n.nodeObj;let s;return o.root===!0?s=(i=C(o.children[t].id).closest("me-main"))==null?void 0:i.className:s=(r=n.closest("me-main"))==null?void 0:r.className,s},Ge=function(e,t){var S;const{id:n,text:o,parent:s,start:i,end:r}=t,l=e.nodes,h=C(s).nodeObj,a=mn(t);let u=1/0,d=0,m=0,g=0;for(let z=i;z<=r;z++){const G=(S=h.children)==null?void 0:S[z];if(!G)return console.warn("Child not found"),e.removeSummary(n),null;const R=pn(G.id),{offsetLeft:le,offsetTop:Ze}=j(l,R);z===i&&(m=Ze),z===r&&(g=Ze+R.offsetHeight),le<u&&(u=le),R.offsetWidth+le>d&&(d=R.offsetWidth+le)}let p,f;const v=m+10,b=g+10,y=(v+b)/2,x=e.theme.cssVar["--color"];a==="lhs"?(p=Ye(`M ${u+10} ${v} c -5 0 -10 5 -10 10 L ${u} ${b-10} c 0 5 5 10 10 10 M ${u} ${y} h -10`,x),f=Xe(o,u-20,y+6,"end",x)):(p=Ye(`M ${d-10} ${v} c 5 0 10 5 10 10 L ${d} ${b-10} c 0 5 -5 10 -10 10 M ${d} ${y} h 10`,x),f=Xe(o,d+20,y+6,"start",x));const w=fn("s-"+n);return w.appendChild(p),w.appendChild(f),w.summaryObj=t,e.summarySvg.appendChild(w),w},gn=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}=un(e),s={id:U(),parent:t,start:n,end:o,text:"summary"},i=Ge(this,s);this.summaries.push(s),this.editSummary(i),this.bus.fire("operation",{name:"createSummary",obj:s})},editSummary:function(e){if(console.time("editSummary"),!e)return;const t=e.childNodes[1];Ne(this,t,n=>{var i;const o=e.summaryObj,s=((i=n.textContent)==null?void 0:i.trim())||"";s===""?o.text=origin:o.text=s,n.remove(),s!==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{Ge(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,s=document.createElementNS("http://www.w3.org/2000/svg","rect");E(s,{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"}),s.classList.add("selected"),e.appendChild(s),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"})),M="http://www.w3.org/2000/svg";function vn(e,t){const n=document.createElementNS(M,"svg");return E(n,{version:"1.1",xmlns:M,height:e,width:t}),n}function bn(e,t){return(parseInt(e)-parseInt(t))/2}function yn(e,t,n,o){const s=document.createElementNS(M,"g");let i="";return e.text?i=e.text.textContent:i=e.childNodes[0].textContent,i.split(`
|
|
12
|
-
`).forEach((l,c)=>{const h=document.createElementNS(M,"text");E(h,{x:n+parseInt(t.paddingLeft)+"",y:o+parseInt(t.paddingTop)+bn(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,s.appendChild(h)}),s}function xn(e,t,n,o){var l;let s="";(l=e.nodeObj)!=null&&l.dangerouslySetInnerHTML?s=e.nodeObj.dangerouslySetInnerHTML:e.text?s=e.text.textContent:s=e.childNodes[0].textContent;const i=document.createElementNS(M,"foreignObject");E(i,{x:n+parseInt(t.paddingLeft)+"",y:o+parseInt(t.paddingTop)+"",width:t.width,height:t.height});const r=document.createElement("div");return E(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=s,i.appendChild(r),i}function wn(e,t){const n=getComputedStyle(t),{offsetLeft:o,offsetTop:s}=j(e.nodes,t),i=document.createElementNS(M,"rect");return E(i,{x:o+"",y:s+"",rx:n.borderRadius,ry:n.borderRadius,width:n.width,height:n.height,fill:n.backgroundColor,stroke:n.borderColor,"stroke-width":n.borderWidth}),i}function ie(e,t,n=!1){const o=getComputedStyle(t),{offsetLeft:s,offsetTop:i}=j(e.nodes,t),r=document.createElementNS(M,"rect");E(r,{x:s+"",y:i+"",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(M,"g");l.appendChild(r);let c;return n?c=xn(t,o,s,i):c=yn(t,o,s,i),l.appendChild(c),l}function En(e,t){const n=getComputedStyle(t),{offsetLeft:o,offsetTop:s}=j(e.nodes,t),i=document.createElementNS(M,"a"),r=document.createElementNS(M,"text");return E(r,{x:o+"",y:s+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,i.appendChild(r),i.setAttribute("href",t.href),i}function Nn(e,t){const n=getComputedStyle(t),{offsetLeft:o,offsetTop:s}=j(e.nodes,t),i=document.createElementNS(M,"image");return E(i,{x:o+"",y:s+"",width:n.width+"",height:n.height+"",href:t.src}),i}const re=100,Cn='<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">',Sn=(e,t=!1)=>{var u,d,m;const n=e.nodes,o=n.offsetHeight+re*2,s=n.offsetWidth+re*2,i=vn(o+"px",s+"px"),r=document.createElementNS(M,"svg"),l=document.createElementNS(M,"rect");E(l,{x:"0",y:"0",width:`${s}`,height:`${o}`,fill:e.theme.cssVar["--bgcolor"]}),i.appendChild(l),n.querySelectorAll(".subLines").forEach(g=>{const p=g.cloneNode(!0),{offsetLeft:f,offsetTop:v}=j(n,g.parentElement);p.setAttribute("x",`${f}`),p.setAttribute("y",`${v}`),r.appendChild(p)});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=(m=n.querySelector(".summary"))==null?void 0:m.cloneNode(!0);return a&&r.appendChild(a),n.querySelectorAll("me-tpc").forEach(g=>{g.nodeObj.dangerouslySetInnerHTML?r.appendChild(ie(e,g,!t)):(r.appendChild(wn(e,g)),r.appendChild(ie(e,g.text,!t)))}),n.querySelectorAll(".tags > span").forEach(g=>{r.appendChild(ie(e,g))}),n.querySelectorAll(".icons > span").forEach(g=>{r.appendChild(ie(e,g))}),n.querySelectorAll(".hyper-link").forEach(g=>{r.appendChild(En(e,g))}),n.querySelectorAll("img").forEach(g=>{r.appendChild(Nn(e,g))}),E(r,{x:re+"",y:re+"",overflow:"visible"}),i.appendChild(r),i},_n=(e,t)=>(t&&e.insertAdjacentHTML("afterbegin","<style>"+t+"</style>"),Cn+e.outerHTML);function Mn(e){return new Promise((t,n)=>{const o=new FileReader;o.onload=s=>{t(s.target.result)},o.onerror=s=>{n(s)},o.readAsDataURL(e)})}const Ln=Object.freeze(Object.defineProperty({__proto__:null,exportPng:async function(e=!1,t){const n=this.exportSvg(e,t),o=await Mn(n);return new Promise((s,i)=>{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(s,"image/png",1)},r.src=o,r.onerror=i})},exportSvg:function(e=!1,t){const n=Sn(this,e),o=_n(n,t);return new Blob([o],{type:"image/svg+xml"})}},Symbol.toStringTag,{value:"Module"}));function Tn(e,t){return async function(...n){const o=this.before[t];o&&!await o.apply(this,n)||e.apply(this,n)}}const Je=Object.keys(Ie),Qe={};for(let e=0;e<Je.length;e++){const t=Je[e];Qe[t]=Tn(Ie[t],t)}const kn={getObjById:Z,generateNewObj:nt,layout:it,linkDiv:pt,editTopic:ut,createWrapper:ct,createParent:at,createChildren:dt,createTopic:ht,findEle:C,changeTheme:Bt,...zt,...Qe,...hn,...gn,...Ln,init(e){if(!e||!e.nodeData)return new Error("MindElixir: `data` is required");e.direction!==void 0&&(this.direction=e.direction),this.changeTheme(e.theme||this.theme,!1),this.nodeData=e.nodeData,D(this.nodeData),this.arrows=e.arrows||[],this.summaries=e.summaries||[],this.tidyArrow(),this.toolBar&&kt(this),this.keypress&&wt(this),this.editable&&Ht(this),et()&&this.mobileMenu?Et(this):this.contextMenu&&mt(this,this.contextMenuOption),this.draggable&&St(this),this.allowUndo&&Mt(this),this.toCenter(),this.layout(),this.linkDiv()}};function An({pT:e,pL:t,pW:n,pH:o,cT:s,cL:i,cW:r,cH:l,direction:c,containerHeight:h}){let a=t+n/2;const u=e+o/2;let d;c==="lhs"?d=i+r:d=i;const m=s+l/2,p=(1-Math.abs(m-u)/h)*.25*(n/2);return c==="lhs"?a=a-n/10-p:a=a+n/10+p,`M ${a} ${u} Q ${a} ${m} ${d} ${m}`}function Dn({pT:e,pL:t,pW:n,pH:o,cT:s,cL:i,cW:r,cH:l,direction:c,isFirst:h}){let a=0,u=0;h?a=e+o/2:a=e+o;const d=s+l;let m=0,g=0,p=0;const f=Math.abs(a-d)/300*A;return c==="lhs"?(p=t,m=p+A,g=p-A,u=i+A,`M ${m} ${a} C ${p} ${a} ${p+f} ${d} ${g} ${d} H ${u}`):(p=t+n,m=p-A,g=p+A,u=i+r-A,`M ${m} ${a} C ${p} ${a} ${p-f} ${d} ${g} ${d} H ${u}`)}const X=document;function k({el:e,direction:t,locale:n,draggable:o,editable:s,contextMenu:i,contextMenuOption:r,toolBar:l,keypress:c,mouseSelectionButton:h,before:a,newTopicName:u,allowUndo:d,generateMainBranch:m,generateSubBranch:g,overflowHidden:p,mobileMenu:f,theme:v}){console.log("ME_version "+k.version,this);let b=null;const y=Object.prototype.toString.call(e);if(y==="[object HTMLDivElement]"?b=e:y==="[object String]"&&(b=document.querySelector(e)),!b)throw new Error("MindElixir: el is not a valid element");b.className+=" mind-elixir",b.innerHTML="",b.style.setProperty("--gap",A+"px"),this.mindElixirBox=b,this.before=a||{},this.locale=n||"en",this.contextMenuOption=r,this.contextMenu=i===void 0?!0:i,this.toolBar=l===void 0?!0:l,this.keypress=c===void 0?!0:c,this.mouseSelectionButton=h||0,this.mobileMenu=f||!1,this.direction=typeof t=="number"?t:1,this.draggable=o===void 0?!0:o,this.newTopicName=u||"new node",this.editable=s===void 0?!0:s,this.allowUndo=d===void 0?!1:d,this.currentNode=null,this.currentArrow=null,this.scaleVal=1,this.tempDirection=null,this.generateMainBranch=m||An,this.generateSubBranch=g||Dn,this.overflowHidden=p||!1,this.bus=st.create(),this.container=X.createElement("div"),this.container.className="map-container";const x=window.matchMedia("(prefers-color-scheme: dark)");this.theme=v||(x.matches?be:ve);const w=X.createElement("div");w.className="map-canvas",this.map=w,this.map.setAttribute("tabindex","0"),this.container.appendChild(this.map),this.mindElixirBox.appendChild(this.container),this.nodes=X.createElement("me-nodes"),this.nodes.className="main-node-container",this.lines=Y("lines"),this.summarySvg=Y("summary"),this.linkController=Y("linkcontroller"),this.P2=X.createElement("div"),this.P3=X.createElement("div"),this.P2.className=this.P3.className="circle",this.P2.style.display=this.P3.style.display="none",this.line1=Ee(),this.line2=Ee(),this.linkController.appendChild(this.line1),this.linkController.appendChild(this.line2),this.linkSvgGroup=Y("topiclinks"),this.map.appendChild(this.nodes),this.overflowHidden?this.container.style.overflow="hidden":ot(this)}return k.prototype=kn,k.LEFT=L,k.RIGHT=P,k.SIDE=J,k.THEME=ve,k.DARK_THEME=be,k.version="4.0.
|
|
11
|
+
`,o[i].children&&n(o[i].children||[],s+1)}return n(e.children||[],2),t},getDataString:function(){const e=He(this);return JSON.stringify(e,(t,n)=>{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.arrows=e.arrows||[],this.summaries=e.summaries||[]),D(this.nodeData),this.layout(),this.linkDiv()},scale:function(e){this.scaleVal=e,this.map.style.transform="scale("+e+")"},selectNode:function(e,t,n){if(e){if(console.time("selectNode"),this.clearSelection(),typeof e=="string"){const o=C(e);return o?this.selectNode(o):void 0}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){console.time("selectNodes"),this.clearSelection();for(const t of e)t.className="selected";this.currentNodes=e,this.bus.fire("selectNodes",e.map(t=>t.nodeObj)),console.timeEnd("selectNodes")},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"})),W=e=>{var o;const t=(o=e.parent)==null?void 0:o.children,n=t.indexOf(e);return{siblings:t,index:n}};function Rt(e){const{siblings:t,index:n}=W(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 qt(e){const{siblings:t,index:n}=W(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 me(e){const{siblings:t,index:n}=W(e);return t.splice(n,1),t.length}function Ft(e,t,n){const{siblings:o,index:s}=W(n);t==="before"?o.splice(s,0,e):o.splice(s+1,0,e)}function It(e,t){const{siblings:n,index:o}=W(e);n[o]=t,t.children=[e]}function Be(e,t,n){if(me(t),e==="in")n.children?n.children.push(t):n.children=[t];else{t.direction!==void 0&&(t.direction=n.direction);const{siblings:o,index:s}=W(n);e==="before"?o.splice(s,0,t):o.splice(s+1,0,t)}}const Vt=function(e,t){var n,o;if(e===L)return L;if(e===P)return P;if(e===J){const s=((n=document.querySelector(".lhs"))==null?void 0:n.childElementCount)||0,i=((o=document.querySelector(".rhs"))==null?void 0:o.childElementCount)||0;return s<=i?(t.direction=L,L):(t.direction=P,P)}},ze=function(e,t,n){var i,r;const o=n.children[0].children[0],s=t.parentElement;if(s.tagName==="ME-PARENT"){if(oe(o),s.children[1])s.nextSibling.appendChild(n);else{const l=e.createChildren([n]);s.appendChild(ue(!0)),s.insertAdjacentElement("afterend",l)}e.linkDiv(n.offsetParent)}else s.tagName==="ME-ROOT"&&(Vt(e.direction,o.nodeObj)===L?(i=e.container.querySelector(".lhs"))==null||i.appendChild(n):(r=e.container.querySelector(".rhs"))==null||r.appendChild(n),e.linkDiv())},ge=function(e,t,n){if(!t)return null;const o=t.nodeObj;o.expanded===!1&&(e.expandNode(t,!0),t=C(o.id));const s=n||e.generateNewObj();o.children?o.children.push(s):o.children=[s],D(e.nodeData);const{grp:i,top:r}=e.createWrapper(s);return ze(e,t,i),{newTop:r,newNodeObj:s}},Re=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()},qe={before:"beforebegin",after:"afterend"},oe=function(e){const n=e.parentElement.parentElement.lastElementChild;(n==null?void 0:n.tagName)==="svg"&&(n==null||n.remove())},Wt=function(e,t){const n=e.nodeObj,o=ae(n);o.style&&t.style&&(t.style=Object.assign(o.style,t.style));const s=Object.assign(n,t);he(e,s),this.linkDiv(),this.bus.fire("operation",{name:"reshapeNode",obj:s,origin:o})},Kt=function(e,t,n){var h,a,u;const o=t||this.currentNode;if(!o)return;const s=o.nodeObj;if(s.root===!0){this.addChild();return}else if(((h=s.parent)==null?void 0:h.root)===!0&&((u=(a=s.parent)==null?void 0:a.children)==null?void 0:u.length)===1){this.addChild(C(s.parent.id));return}const i=n||this.generateNewObj();Ft(i,e,s),D(this.nodeData);const r=o.parentElement;console.time("insertSibling_DOM");const{grp:l,top:c}=this.createWrapper(i);r.parentElement.insertAdjacentElement(qe[e],l),this.linkDiv(l.offsetParent),n||this.editTopic(c.firstChild),this.selectNode(c.firstChild,!0),console.timeEnd("insertSibling_DOM"),this.bus.fire("operation",{name:"insertSibling",type:e,obj:i})},Ut=function(e,t){const n=e||this.currentNode;if(!n)return;oe(n);const o=n.nodeObj;if(o.root===!0)return;const s=t||this.generateNewObj();It(o,s),D(this.nodeData);const i=n.parentElement.parentElement;console.time("insertParent_DOM");const{grp:r,top:l}=this.createWrapper(s,!0);l.appendChild(ue(!0)),i.insertAdjacentElement("afterend",r);const c=this.createChildren([i]);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:s})},Yt=function(e,t){console.time("addChild");const n=e||this.currentNode;if(!n)return;const o=ge(this,n,t);if(!o)return;const{newTop:s,newNodeObj:i}=o;this.bus.fire("operation",{name:"addChild",obj:i}),console.timeEnd("addChild"),t||this.editTopic(s.firstChild),this.selectNode(s.firstChild,!0)},Xt=function(e,t){console.time("copyNode");const n=ae(e.nodeObj);ce(n);const o=ge(this,t,n);if(!o)return;const{newNodeObj:s}=o;console.timeEnd("copyNode"),this.selectNode(C(s.id)),this.bus.fire("operation",{name:"copyNode",obj:s})},Gt=function(e,t){e=ee(e);const n=[];for(let o=0;o<e.length;o++){const s=e[o],i=ae(s.nodeObj);ce(i);const r=ge(this,t,i);if(!r)return;const{newNodeObj:l}=r;n.push(l)}this.selectNodes(n.map(o=>C(o.id))),this.bus.fire("operation",{name:"copyNodes",objs:n})},Jt=function(e){const t=e||this.currentNode;if(!t)return;const n=t.nodeObj;Rt(n);const o=t.parentNode.parentNode;o.parentNode.insertBefore(o,o.previousSibling),this.linkDiv(),this.bus.fire("operation",{name:"moveUpNode",obj:n})},Qt=function(e){const t=e||this.currentNode;if(!t)return;const n=t.nodeObj;qt(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})},Zt=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,s=o.findIndex(l=>l===n),i=me(n);if(Re(t,i),o.length!==0){const l=o[s]||o[s-1];this.selectNode(C(l.id))}else this.selectNode(C(n.parent.id));this.linkDiv(),this.bus.fire("operation",{name:"removeNode",obj:n,originIndex:s,originParentId:(r=n==null?void 0:n.parent)==null?void 0:r.id})},en=function(e){e=ee(e);for(const t of e){const n=t.nodeObj;if(n.root===!0)continue;const o=me(n);Re(t,o)}this.linkDiv(),this.bus.fire("operation",{name:"removeNodes",objs:e.map(t=>t.nodeObj)})},tn=function(e,t){e=ee(e);const n=t.nodeObj;n.expanded===!1&&(this.expandNode(t,!0),t=C(n.id)),console.time("moveNodeIn");for(const o of e){const s=o.nodeObj;Be("in",s,n),D(this.nodeData);const i=o.parentElement;ze(this,t,i.parentElement)}this.linkDiv(),this.bus.fire("operation",{name:"moveNodeIn",objs:e.map(o=>o.nodeObj),toObj:n}),console.timeEnd("moveNodeIn")},Fe=(e,t,n,o)=>{e=ee(e),t==="after"&&(e=e.reverse());const s=n.nodeObj;for(const i of e){const r=i.nodeObj;Be(t,r,s),D(o.nodeData),oe(i);const l=i.parentElement.parentNode;n.parentElement.parentNode.insertAdjacentElement(qe[t],l)}o.linkDiv(),o.bus.fire("operation",{name:t==="before"?"moveNodeBefore":"moveNodeAfter",objs:e.map(i=>i.nodeObj),toObj:s})},Ie=Object.freeze(Object.defineProperty({__proto__:null,addChild:Yt,beginEdit:function(e){const t=e||this.currentNode;t&&(t.nodeObj.dangerouslySetInnerHTML||this.editTopic(t))},copyNode:Xt,copyNodes:Gt,insertParent:Ut,insertSibling:Kt,mainToSub:oe,moveDownNode:Qt,moveNodeAfter:function(e,t){Fe(e,"after",t,this)},moveNodeBefore:function(e,t){Fe(e,"before",t,this)},moveNodeIn:tn,moveUpNode:Jt,removeNode:Zt,removeNodes:en,reshapeNode:Wt,setNodeTopic:function(e,t){e.text.textContent=t,e.nodeObj.topic=t,this.linkDiv()}},Symbol.toStringTag,{value:"Module"})),Ve={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:s}=j(e.nodes,t),i=t.offsetWidth,r=t.offsetHeight,l=o+i/2,c=s+r/2,h=l+n.x,a=c+n.y;return{w:i,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 nn=function(e,t,n,o){const s=document.createElementNS("http://www.w3.org/2000/svg","text");return E(s,{"text-anchor":"middle",x:t+"",y:n+"",fill:o||"#666"}),s.dataset.type="custom-link",s.innerHTML=e,s},We=function(e,t,n,o,s){if(!t||!n)return;const i=performance.now(),r=se(e,t,o.delta1),l=se(e,n,o.delta2),{x:c,y:h}=K(r),{ctrlX:a,ctrlY:u}=r,{ctrlX:d,ctrlY:m}=l,{x:g,y:p}=K(l),f=ye(d,m,g,p),v=ft(`M ${c} ${h} C ${a} ${u} ${d} ${m} ${g} ${p}`,`M ${f.x1} ${f.y1} L ${g} ${p} L ${f.x2} ${f.y2}`),b=c/8+a*3/8+d*3/8+g/8,y=h/8+u*3/8+m*3/8+p/8,x=nn(o.label,b,y,e.theme.cssVar["--color"]);v.appendChild(x),v.arrowObj=o,v.dataset.linkid=o.id,e.linkSvgGroup.appendChild(v),s||(e.arrows.push(o),e.currentArrow=v,Ue(e,o,r,l));const w=performance.now();console.log(`DrawArrow Execution time: ${w-i} ms`)},on=function(e,t){const n={id:U(),label:"Custom Link",from:e.nodeObj.id,to:t.nodeObj.id,delta1:{x:0,y:-200},delta2:{x:0,y:-200}};We(this,e,t,n),this.bus.fire("operation",{name:"createArrow",obj:n})},sn=function(e){let t;if(e?t=e:t=this.currentArrow,!t)return;Ke(this);const n=t.arrowObj.id;this.arrows=this.arrows.filter(o=>o.id!==n),t.remove(),this.bus.fire("operation",{name:"removeArrow",obj:{id:n}})},rn=function(e){this.currentArrow=e;const t=e.arrowObj,n=C(t.from),o=C(t.to),s=se(this,n,t.delta1),i=se(this,o,t.delta2);Ue(this,t,s,i)},ln=function(){this.currentArrow=null,Ke(this)},Ke=function(e){e.linkController.style.display="none",e.P2.style.display="none",e.P3.style.display="none"},Ue=function(e,t,n,o){var d;e.linkController.style.display="initial",e.P2.style.display="initial",e.P3.style.display="initial",e.nodes.appendChild(e.linkController),e.nodes.appendChild(e.P2),e.nodes.appendChild(e.P3);let{x:s,y:i}=K(n),{ctrlX:r,ctrlY:l}=n,{ctrlX:c,ctrlY:h}=o,{x:a,y:u}=K(o);e.P2.style.cssText=`top:${l}px;left:${r}px;`,e.P3.style.cssText=`top:${h}px;left:${c}px;`,E(e.line1,{x1:s+"",y1:i+"",x2:r+"",y2:l+""}),E(e.line2,{x1:c+"",y1:h+"",x2:a+"",y2:u+""}),e.helper1&&(e.helper1.destory(e.map),(d=e.helper2)==null||d.destory(e.map)),e.helper1=Ve.create(e.P2),e.helper2=Ve.create(e.P3),e.helper1.init(e.map,(m,g)=>{var b;r=r+m/e.scaleVal,l=l+g/e.scaleVal;const p=K({...n,ctrlX:r,ctrlY:l});s=p.x,i=p.y;const f=s/8+r*3/8+c*3/8+a/8,v=i/8+l*3/8+h*3/8+u/8;e.P2.style.top=l+"px",e.P2.style.left=r+"px",(b=e.currentArrow)==null||b.children[0].setAttribute("d",`M ${s} ${i} C ${r} ${l} ${c} ${h} ${a} ${u}`),E(e.currentArrow.children[2],{x:f+"",y:v+""}),E(e.line1,{x1:s+"",y1:i+"",x2:r+"",y2:l+""}),t.delta1.x=r-n.cx,t.delta1.y=l-n.cy}),e.helper2.init(e.map,(m,g)=>{var y,x;c=c+m/e.scaleVal,h=h+g/e.scaleVal;const p=K({...o,ctrlX:c,ctrlY:h});a=p.x,u=p.y;const f=s/8+r*3/8+c*3/8+a/8,v=i/8+l*3/8+h*3/8+u/8,b=ye(c,h,a,u);e.P3.style.top=h+"px",e.P3.style.left=c+"px",(y=e.currentArrow)==null||y.children[0].setAttribute("d",`M ${s} ${i} C ${r} ${l} ${c} ${h} ${a} ${u}`),(x=e.currentArrow)==null||x.children[1].setAttribute("d",`M ${b.x1} ${b.y1} L ${a} ${u} L ${b.x2} ${b.y2}`),E(e.currentArrow.children[2],{x:f+"",y:v+""}),E(e.line2,{x1:c+"",y1:h+"",x2:a+"",y2:u+""}),t.delta2.x=c-o.cx,t.delta2.y=h-o.cy})};function cn(){this.linkSvgGroup.innerHTML="";for(let e=0;e<this.arrows.length;e++){const t=this.arrows[e];try{We(this,C(t.from),C(t.to),t,!0)}catch{console.warn("Node may not be expanded")}}this.nodes.appendChild(this.linkSvgGroup)}function an(e){if(console.time("editSummary"),!e)return;const t=e.children[2];console.log(t,e),Ne(this,t,n=>{var i;const o=e.arrowObj,s=((i=n.textContent)==null?void 0:i.trim())||"";s===""?o.label=origin:o.label=s,n.remove(),s!==origin&&(t.innerHTML=o.label,this.linkDiv(),this.bus.fire("operation",{name:"finishEditArrowLabel",obj:o}))}),console.timeEnd("editSummary")}function dn(){this.arrows=this.arrows.filter(e=>Z(e.from,this.nodeData)&&Z(e.to,this.nodeData))}const hn=Object.freeze(Object.defineProperty({__proto__:null,createArrow:on,editArrowLabel:an,removeArrow:sn,renderArrow:cn,selectArrow:rn,tidyArrow:dn,unselectArrow:ln},Symbol.toStringTag,{value:"Module"})),un=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(m=>a===m);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 m=u.parent,g=m.children,p=g==null?void 0:g.indexOf(u);u=m,d.unshift({node:u,index:p})}return d.length>t&&(t=d.length),d});let o=0;e:for(;o<t;o++){const a=(c=n[0][o])==null?void 0:c.node;for(let u=1;u<n.length;u++)if(((h=n[u][o])==null?void 0:h.node)!==a)break e}if(!o)throw new Error("Can not select root node.");const s=n.map(a=>a[o-1].index).sort(),i=s[0]||0,r=s[s.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:i,end:r}},fn=function(e){const t=document.createElementNS("http://www.w3.org/2000/svg","g");return t.setAttribute("id",e),t},Ye=function(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","path");return E(n,{d:e,stroke:t||"#666",fill:"none","stroke-linecap":"round","stroke-width":"2"}),n},Xe=function(e,t,n,o,s){const i=document.createElementNS("http://www.w3.org/2000/svg","text");return E(i,{"text-anchor":o,x:t+"",y:n+"",fill:s||"#666"}),i.innerHTML=e,i},pn=e=>C(e).parentElement.parentElement,mn=function({parent:e,start:t}){var i,r;const n=C(e),o=n.nodeObj;let s;return o.root===!0?s=(i=C(o.children[t].id).closest("me-main"))==null?void 0:i.className:s=(r=n.closest("me-main"))==null?void 0:r.className,s},Ge=function(e,t){var S;const{id:n,text:o,parent:s,start:i,end:r}=t,l=e.nodes,h=C(s).nodeObj,a=mn(t);let u=1/0,d=0,m=0,g=0;for(let z=i;z<=r;z++){const G=(S=h.children)==null?void 0:S[z];if(!G)return console.warn("Child not found"),e.removeSummary(n),null;const R=pn(G.id),{offsetLeft:le,offsetTop:Ze}=j(l,R);z===i&&(m=Ze),z===r&&(g=Ze+R.offsetHeight),le<u&&(u=le),R.offsetWidth+le>d&&(d=R.offsetWidth+le)}let p,f;const v=m+10,b=g+10,y=(v+b)/2,x=e.theme.cssVar["--color"];a==="lhs"?(p=Ye(`M ${u+10} ${v} c -5 0 -10 5 -10 10 L ${u} ${b-10} c 0 5 5 10 10 10 M ${u} ${y} h -10`,x),f=Xe(o,u-20,y+6,"end",x)):(p=Ye(`M ${d-10} ${v} c 5 0 10 5 10 10 L ${d} ${b-10} c 0 5 -5 10 -10 10 M ${d} ${y} h 10`,x),f=Xe(o,d+20,y+6,"start",x));const w=fn("s-"+n);return w.appendChild(p),w.appendChild(f),w.summaryObj=t,e.summarySvg.appendChild(w),w},gn=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}=un(e),s={id:U(),parent:t,start:n,end:o,text:"summary"},i=Ge(this,s);this.summaries.push(s),this.editSummary(i),this.bus.fire("operation",{name:"createSummary",obj:s})},editSummary:function(e){if(console.time("editSummary"),!e)return;const t=e.childNodes[1];Ne(this,t,n=>{var i;const o=e.summaryObj,s=((i=n.textContent)==null?void 0:i.trim())||"";s===""?o.text=origin:o.text=s,n.remove(),s!==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{Ge(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,s=document.createElementNS("http://www.w3.org/2000/svg","rect");E(s,{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"}),s.classList.add("selected"),e.appendChild(s),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"})),M="http://www.w3.org/2000/svg";function vn(e,t){const n=document.createElementNS(M,"svg");return E(n,{version:"1.1",xmlns:M,height:e,width:t}),n}function bn(e,t){return(parseInt(e)-parseInt(t))/2}function yn(e,t,n,o){const s=document.createElementNS(M,"g");let i="";return e.text?i=e.text.textContent:i=e.childNodes[0].textContent,i.split(`
|
|
12
|
+
`).forEach((l,c)=>{const h=document.createElementNS(M,"text");E(h,{x:n+parseInt(t.paddingLeft)+"",y:o+parseInt(t.paddingTop)+bn(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,s.appendChild(h)}),s}function xn(e,t,n,o){var l;let s="";(l=e.nodeObj)!=null&&l.dangerouslySetInnerHTML?s=e.nodeObj.dangerouslySetInnerHTML:e.text?s=e.text.textContent:s=e.childNodes[0].textContent;const i=document.createElementNS(M,"foreignObject");E(i,{x:n+parseInt(t.paddingLeft)+"",y:o+parseInt(t.paddingTop)+"",width:t.width,height:t.height});const r=document.createElement("div");return E(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=s,i.appendChild(r),i}function wn(e,t){const n=getComputedStyle(t),{offsetLeft:o,offsetTop:s}=j(e.nodes,t),i=document.createElementNS(M,"rect");return E(i,{x:o+"",y:s+"",rx:n.borderRadius,ry:n.borderRadius,width:n.width,height:n.height,fill:n.backgroundColor,stroke:n.borderColor,"stroke-width":n.borderWidth}),i}function ie(e,t,n=!1){const o=getComputedStyle(t),{offsetLeft:s,offsetTop:i}=j(e.nodes,t),r=document.createElementNS(M,"rect");E(r,{x:s+"",y:i+"",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(M,"g");l.appendChild(r);let c;return n?c=xn(t,o,s,i):c=yn(t,o,s,i),l.appendChild(c),l}function En(e,t){const n=getComputedStyle(t),{offsetLeft:o,offsetTop:s}=j(e.nodes,t),i=document.createElementNS(M,"a"),r=document.createElementNS(M,"text");return E(r,{x:o+"",y:s+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,i.appendChild(r),i.setAttribute("href",t.href),i}function Nn(e,t){const n=getComputedStyle(t),{offsetLeft:o,offsetTop:s}=j(e.nodes,t),i=document.createElementNS(M,"image");return E(i,{x:o+"",y:s+"",width:n.width+"",height:n.height+"",href:t.src}),i}const re=100,Cn='<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">',Sn=(e,t=!1)=>{var u,d,m;const n=e.nodes,o=n.offsetHeight+re*2,s=n.offsetWidth+re*2,i=vn(o+"px",s+"px"),r=document.createElementNS(M,"svg"),l=document.createElementNS(M,"rect");E(l,{x:"0",y:"0",width:`${s}`,height:`${o}`,fill:e.theme.cssVar["--bgcolor"]}),i.appendChild(l),n.querySelectorAll(".subLines").forEach(g=>{const p=g.cloneNode(!0),{offsetLeft:f,offsetTop:v}=j(n,g.parentElement);p.setAttribute("x",`${f}`),p.setAttribute("y",`${v}`),r.appendChild(p)});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=(m=n.querySelector(".summary"))==null?void 0:m.cloneNode(!0);return a&&r.appendChild(a),n.querySelectorAll("me-tpc").forEach(g=>{g.nodeObj.dangerouslySetInnerHTML?r.appendChild(ie(e,g,!t)):(r.appendChild(wn(e,g)),r.appendChild(ie(e,g.text,!t)))}),n.querySelectorAll(".tags > span").forEach(g=>{r.appendChild(ie(e,g))}),n.querySelectorAll(".icons > span").forEach(g=>{r.appendChild(ie(e,g))}),n.querySelectorAll(".hyper-link").forEach(g=>{r.appendChild(En(e,g))}),n.querySelectorAll("img").forEach(g=>{r.appendChild(Nn(e,g))}),E(r,{x:re+"",y:re+"",overflow:"visible"}),i.appendChild(r),i},_n=(e,t)=>(t&&e.insertAdjacentHTML("afterbegin","<style>"+t+"</style>"),Cn+e.outerHTML);function Mn(e){return new Promise((t,n)=>{const o=new FileReader;o.onload=s=>{t(s.target.result)},o.onerror=s=>{n(s)},o.readAsDataURL(e)})}const Ln=Object.freeze(Object.defineProperty({__proto__:null,exportPng:async function(e=!1,t){const n=this.exportSvg(e,t),o=await Mn(n);return new Promise((s,i)=>{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(s,"image/png",1)},r.src=o,r.onerror=i})},exportSvg:function(e=!1,t){const n=Sn(this,e),o=_n(n,t);return new Blob([o],{type:"image/svg+xml"})}},Symbol.toStringTag,{value:"Module"}));function Tn(e,t){return async function(...n){const o=this.before[t];o&&!await o.apply(this,n)||e.apply(this,n)}}const Je=Object.keys(Ie),Qe={};for(let e=0;e<Je.length;e++){const t=Je[e];Qe[t]=Tn(Ie[t],t)}const kn={getObjById:Z,generateNewObj:nt,layout:it,linkDiv:pt,editTopic:ut,createWrapper:ct,createParent:at,createChildren:dt,createTopic:ht,findEle:C,changeTheme:Bt,...zt,...Qe,...hn,...gn,...Ln,init(e){if(!e||!e.nodeData)return new Error("MindElixir: `data` is required");e.direction!==void 0&&(this.direction=e.direction),this.changeTheme(e.theme||this.theme,!1),this.nodeData=e.nodeData,D(this.nodeData),this.arrows=e.arrows||[],this.summaries=e.summaries||[],this.tidyArrow(),this.toolBar&&kt(this),this.keypress&&wt(this),this.editable&&Ht(this),et()&&this.mobileMenu?Et(this):this.contextMenu&&mt(this,this.contextMenuOption),this.draggable&&St(this),this.allowUndo&&Mt(this),this.toCenter(),this.layout(),this.linkDiv()}};function An({pT:e,pL:t,pW:n,pH:o,cT:s,cL:i,cW:r,cH:l,direction:c,containerHeight:h}){let a=t+n/2;const u=e+o/2;let d;c==="lhs"?d=i+r:d=i;const m=s+l/2,p=(1-Math.abs(m-u)/h)*.25*(n/2);return c==="lhs"?a=a-n/10-p:a=a+n/10+p,`M ${a} ${u} Q ${a} ${m} ${d} ${m}`}function Dn({pT:e,pL:t,pW:n,pH:o,cT:s,cL:i,cW:r,cH:l,direction:c,isFirst:h}){let a=0,u=0;h?a=e+o/2:a=e+o;const d=s+l;let m=0,g=0,p=0;const f=Math.abs(a-d)/300*A;return c==="lhs"?(p=t,m=p+A,g=p-A,u=i+A,`M ${m} ${a} C ${p} ${a} ${p+f} ${d} ${g} ${d} H ${u}`):(p=t+n,m=p-A,g=p+A,u=i+r-A,`M ${m} ${a} C ${p} ${a} ${p-f} ${d} ${g} ${d} H ${u}`)}const X=document;function k({el:e,direction:t,locale:n,draggable:o,editable:s,contextMenu:i,contextMenuOption:r,toolBar:l,keypress:c,mouseSelectionButton:h,before:a,newTopicName:u,allowUndo:d,generateMainBranch:m,generateSubBranch:g,overflowHidden:p,mobileMenu:f,theme:v}){console.log("ME_version "+k.version,this);let b=null;const y=Object.prototype.toString.call(e);if(y==="[object HTMLDivElement]"?b=e:y==="[object String]"&&(b=document.querySelector(e)),!b)throw new Error("MindElixir: el is not a valid element");b.className+=" mind-elixir",b.innerHTML="",b.style.setProperty("--gap",A+"px"),this.mindElixirBox=b,this.before=a||{},this.locale=n||"en",this.contextMenuOption=r,this.contextMenu=i===void 0?!0:i,this.toolBar=l===void 0?!0:l,this.keypress=c===void 0?!0:c,this.mouseSelectionButton=h||0,this.mobileMenu=f||!1,this.direction=typeof t=="number"?t:1,this.draggable=o===void 0?!0:o,this.newTopicName=u||"new node",this.editable=s===void 0?!0:s,this.allowUndo=d===void 0?!1:d,this.currentNode=null,this.currentArrow=null,this.scaleVal=1,this.tempDirection=null,this.generateMainBranch=m||An,this.generateSubBranch=g||Dn,this.overflowHidden=p||!1,this.bus=st.create(),this.container=X.createElement("div"),this.container.className="map-container";const x=window.matchMedia("(prefers-color-scheme: dark)");this.theme=v||(x.matches?be:ve);const w=X.createElement("div");w.className="map-canvas",this.map=w,this.map.setAttribute("tabindex","0"),this.container.appendChild(this.map),this.mindElixirBox.appendChild(this.container),this.nodes=X.createElement("me-nodes"),this.nodes.className="main-node-container",this.lines=Y("lines"),this.summarySvg=Y("summary"),this.linkController=Y("linkcontroller"),this.P2=X.createElement("div"),this.P3=X.createElement("div"),this.P2.className=this.P3.className="circle",this.P2.style.display=this.P3.style.display="none",this.line1=Ee(),this.line2=Ee(),this.linkController.appendChild(this.line1),this.linkController.appendChild(this.line2),this.linkSvgGroup=Y("topiclinks"),this.map.appendChild(this.nodes),this.overflowHidden?this.container.style.overflow="hidden":ot(this)}return k.prototype=kn,k.LEFT=L,k.RIGHT=P,k.SIDE=J,k.THEME=ve,k.DARK_THEME=be,k.version="4.0.1",k.E=C,k.new=e=>({nodeData:{id:U(),topic:e||"new topic",root:!0,children:[]}}),k}();
|
package/dist/MindElixir.js
CHANGED
|
@@ -1493,7 +1493,7 @@ const un = function(e, t) {
|
|
|
1493
1493
|
}
|
|
1494
1494
|
e.linkDiv(n.offsetParent);
|
|
1495
1495
|
} else
|
|
1496
|
-
s.tagName === "ME-ROOT" && (un(e.direction, o.nodeObj) === T ? (i =
|
|
1496
|
+
s.tagName === "ME-ROOT" && (un(e.direction, o.nodeObj) === T ? (i = e.container.querySelector(".lhs")) == null || i.appendChild(n) : (r = e.container.querySelector(".rhs")) == null || r.appendChild(n), e.linkDiv());
|
|
1497
1497
|
}, ge = function(e, t, n) {
|
|
1498
1498
|
if (!t)
|
|
1499
1499
|
return null;
|
|
@@ -2299,7 +2299,7 @@ k.RIGHT = z;
|
|
|
2299
2299
|
k.SIDE = ie;
|
|
2300
2300
|
k.THEME = De;
|
|
2301
2301
|
k.DARK_THEME = Oe;
|
|
2302
|
-
k.version = "4.0.
|
|
2302
|
+
k.version = "4.0.1";
|
|
2303
2303
|
k.E = C;
|
|
2304
2304
|
k.new = (e) => ({
|
|
2305
2305
|
nodeData: {
|
|
@@ -7,4 +7,4 @@ var MindElixirLite=function(){"use strict";const $t="";(function(e){var t,n,o,s,
|
|
|
7
7
|
|
|
8
8
|
`:t+="".padStart(s-7," ")+"- "+o[i].topic+`
|
|
9
9
|
`,o[i].children&&n(o[i].children||[],s+1)}return n(e.children||[],2),t},getDataString:function(){const e=xe(this);return JSON.stringify(e,(t,n)=>{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.arrows=e.arrows||[],this.summaries=e.summaries||[]),ee(this.nodeData),this.layout(),this.linkDiv()},scale:function(e){this.scaleVal=e,this.map.style.transform="scale("+e+")"},selectNode:function(e,t,n){if(e){if(console.time("selectNode"),this.clearSelection(),typeof e=="string"){const o=L(e);return o?this.selectNode(o):void 0}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){console.time("selectNodes"),this.clearSelection();for(const t of e)t.className="selected";this.currentNodes=e,this.bus.fire("selectNodes",e.map(t=>t.nodeObj)),console.timeEnd("selectNodes")},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"})),we={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 X(e,t,n){const{offsetLeft:o,offsetTop:s}=N(e.nodes,t),i=t.offsetWidth,r=t.offsetHeight,l=o+i/2,c=s+r/2,d=l+n.x,h=c+n.y;return{w:i,h:r,cx:l,cy:c,ctrlX:d,ctrlY:h}}function q(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 nt=function(e,t,n,o){const s=document.createElementNS("http://www.w3.org/2000/svg","text");return b(s,{"text-anchor":"middle",x:t+"",y:n+"",fill:o||"#666"}),s.dataset.type="custom-link",s.innerHTML=e,s},_e=function(e,t,n,o,s){if(!t||!n)return;const i=performance.now(),r=X(e,t,o.delta1),l=X(e,n,o.delta2),{x:c,y:d}=q(r),{ctrlX:h,ctrlY:u}=r,{ctrlX:a,ctrlY:p}=l,{x:m,y:f}=q(l),g=re(a,p,m,f),y=Ve(`M ${c} ${d} C ${h} ${u} ${a} ${p} ${m} ${f}`,`M ${g.x1} ${g.y1} L ${m} ${f} L ${g.x2} ${g.y2}`),v=c/8+h*3/8+a*3/8+m/8,w=d/8+u*3/8+p*3/8+f/8,E=nt(o.label,v,w,e.theme.cssVar["--color"]);y.appendChild(E),y.arrowObj=o,y.dataset.linkid=o.id,e.linkSvgGroup.appendChild(y),s||(e.arrows.push(o),e.currentArrow=y,Se(e,o,r,l));const _=performance.now();console.log(`DrawArrow Execution time: ${_-i} ms`)},ot=function(e,t){const n={id:te(),label:"Custom Link",from:e.nodeObj.id,to:t.nodeObj.id,delta1:{x:0,y:-200},delta2:{x:0,y:-200}};_e(this,e,t,n),this.bus.fire("operation",{name:"createArrow",obj:n})},st=function(e){let t;if(e?t=e:t=this.currentArrow,!t)return;Ee(this);const n=t.arrowObj.id;this.arrows=this.arrows.filter(o=>o.id!==n),t.remove(),this.bus.fire("operation",{name:"removeArrow",obj:{id:n}})},it=function(e){this.currentArrow=e;const t=e.arrowObj,n=L(t.from),o=L(t.to),s=X(this,n,t.delta1),i=X(this,o,t.delta2);Se(this,t,s,i)},rt=function(){this.currentArrow=null,Ee(this)},Ee=function(e){e.linkController.style.display="none",e.P2.style.display="none",e.P3.style.display="none"},Se=function(e,t,n,o){var a;e.linkController.style.display="initial",e.P2.style.display="initial",e.P3.style.display="initial",e.nodes.appendChild(e.linkController),e.nodes.appendChild(e.P2),e.nodes.appendChild(e.P3);let{x:s,y:i}=q(n),{ctrlX:r,ctrlY:l}=n,{ctrlX:c,ctrlY:d}=o,{x:h,y:u}=q(o);e.P2.style.cssText=`top:${l}px;left:${r}px;`,e.P3.style.cssText=`top:${d}px;left:${c}px;`,b(e.line1,{x1:s+"",y1:i+"",x2:r+"",y2:l+""}),b(e.line2,{x1:c+"",y1:d+"",x2:h+"",y2:u+""}),e.helper1&&(e.helper1.destory(e.map),(a=e.helper2)==null||a.destory(e.map)),e.helper1=we.create(e.P2),e.helper2=we.create(e.P3),e.helper1.init(e.map,(p,m)=>{var v;r=r+p/e.scaleVal,l=l+m/e.scaleVal;const f=q({...n,ctrlX:r,ctrlY:l});s=f.x,i=f.y;const g=s/8+r*3/8+c*3/8+h/8,y=i/8+l*3/8+d*3/8+u/8;e.P2.style.top=l+"px",e.P2.style.left=r+"px",(v=e.currentArrow)==null||v.children[0].setAttribute("d",`M ${s} ${i} C ${r} ${l} ${c} ${d} ${h} ${u}`),b(e.currentArrow.children[2],{x:g+"",y:y+""}),b(e.line1,{x1:s+"",y1:i+"",x2:r+"",y2:l+""}),t.delta1.x=r-n.cx,t.delta1.y=l-n.cy}),e.helper2.init(e.map,(p,m)=>{var w,E;c=c+p/e.scaleVal,d=d+m/e.scaleVal;const f=q({...o,ctrlX:c,ctrlY:d});h=f.x,u=f.y;const g=s/8+r*3/8+c*3/8+h/8,y=i/8+l*3/8+d*3/8+u/8,v=re(c,d,h,u);e.P3.style.top=d+"px",e.P3.style.left=c+"px",(w=e.currentArrow)==null||w.children[0].setAttribute("d",`M ${s} ${i} C ${r} ${l} ${c} ${d} ${h} ${u}`),(E=e.currentArrow)==null||E.children[1].setAttribute("d",`M ${v.x1} ${v.y1} L ${h} ${u} L ${v.x2} ${v.y2}`),b(e.currentArrow.children[2],{x:g+"",y:y+""}),b(e.line2,{x1:c+"",y1:d+"",x2:h+"",y2:u+""}),t.delta2.x=c-o.cx,t.delta2.y=d-o.cy})};function lt(){this.linkSvgGroup.innerHTML="";for(let e=0;e<this.arrows.length;e++){const t=this.arrows[e];try{_e(this,L(t.from),L(t.to),t,!0)}catch{console.warn("Node may not be expanded")}}this.nodes.appendChild(this.linkSvgGroup)}function ct(e){if(console.time("editSummary"),!e)return;const t=e.children[2];console.log(t,e),ue(this,t,n=>{var i;const o=e.arrowObj,s=((i=n.textContent)==null?void 0:i.trim())||"";s===""?o.label=origin:o.label=s,n.remove(),s!==origin&&(t.innerHTML=o.label,this.linkDiv(),this.bus.fire("operation",{name:"finishEditArrowLabel",obj:o}))}),console.timeEnd("editSummary")}function at(){this.arrows=this.arrows.filter(e=>F(e.from,this.nodeData)&&F(e.to,this.nodeData))}const ht=Object.freeze(Object.defineProperty({__proto__:null,createArrow:ot,editArrowLabel:ct,removeArrow:st,renderArrow:lt,selectArrow:it,tidyArrow:at,unselectArrow:rt},Symbol.toStringTag,{value:"Module"})),dt=function(e){var c,d;if(e.length===0)throw new Error("No selected node.");if(e.length===1){const h=e[0].nodeObj,u=e[0].nodeObj.parent;if(!u)throw new Error("Can not select root node.");const a=u.children.findIndex(p=>h===p);return{parent:u.id,start:a,end:a}}let t=0;const n=e.map(h=>{let u=h.nodeObj;const a=[];for(;u.parent;){const p=u.parent,m=p.children,f=m==null?void 0:m.indexOf(u);u=p,a.unshift({node:u,index:f})}return a.length>t&&(t=a.length),a});let o=0;e:for(;o<t;o++){const h=(c=n[0][o])==null?void 0:c.node;for(let u=1;u<n.length;u++)if(((d=n[u][o])==null?void 0:d.node)!==h)break e}if(!o)throw new Error("Can not select root node.");const s=n.map(h=>h[o-1].index).sort(),i=s[0]||0,r=s[s.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:i,end:r}},ut=function(e){const t=document.createElementNS("http://www.w3.org/2000/svg","g");return t.setAttribute("id",e),t},Ce=function(e,t){const n=document.createElementNS("http://www.w3.org/2000/svg","path");return b(n,{d:e,stroke:t||"#666",fill:"none","stroke-linecap":"round","stroke-width":"2"}),n},Le=function(e,t,n,o,s){const i=document.createElementNS("http://www.w3.org/2000/svg","text");return b(i,{"text-anchor":o,x:t+"",y:n+"",fill:s||"#666"}),i.innerHTML=e,i},ft=e=>L(e).parentElement.parentElement,pt=function({parent:e,start:t}){var i,r;const n=L(e),o=n.nodeObj;let s;return o.root===!0?s=(i=L(o.children[t].id).closest("me-main"))==null?void 0:i.className:s=(r=n.closest("me-main"))==null?void 0:r.className,s},Me=function(e,t){var ne;const{id:n,text:o,parent:s,start:i,end:r}=t,l=e.nodes,d=L(s).nodeObj,h=pt(t);let u=1/0,a=0,p=0,m=0;for(let I=i;I<=r;I++){const Te=(ne=d.children)==null?void 0:ne[I];if(!Te)return console.warn("Child not found"),e.removeSummary(n),null;const U=ft(Te.id),{offsetLeft:J,offsetTop:Ne}=N(l,U);I===i&&(p=Ne),I===r&&(m=Ne+U.offsetHeight),J<u&&(u=J),U.offsetWidth+J>a&&(a=U.offsetWidth+J)}let f,g;const y=p+10,v=m+10,w=(y+v)/2,E=e.theme.cssVar["--color"];h==="lhs"?(f=Ce(`M ${u+10} ${y} c -5 0 -10 5 -10 10 L ${u} ${v-10} c 0 5 5 10 10 10 M ${u} ${w} h -10`,E),g=Le(o,u-20,w+6,"end",E)):(f=Ce(`M ${a-10} ${y} c 5 0 10 5 10 10 L ${a} ${v-10} c 0 5 -5 10 -10 10 M ${a} ${w} h 10`,E),g=Le(o,a+20,w+6,"start",E));const _=ut("s-"+n);return _.appendChild(f),_.appendChild(g),_.summaryObj=t,e.summarySvg.appendChild(_),_},mt=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}=dt(e),s={id:te(),parent:t,start:n,end:o,text:"summary"},i=Me(this,s);this.summaries.push(s),this.editSummary(i),this.bus.fire("operation",{name:"createSummary",obj:s})},editSummary:function(e){if(console.time("editSummary"),!e)return;const t=e.childNodes[1];ue(this,t,n=>{var i;const o=e.summaryObj,s=((i=n.textContent)==null?void 0:i.trim())||"";s===""?o.text=origin:o.text=s,n.remove(),s!==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{Me(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,s=document.createElementNS("http://www.w3.org/2000/svg","rect");b(s,{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"}),s.classList.add("selected"),e.appendChild(s),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"})),C="http://www.w3.org/2000/svg";function gt(e,t){const n=document.createElementNS(C,"svg");return b(n,{version:"1.1",xmlns:C,height:e,width:t}),n}function vt(e,t){return(parseInt(e)-parseInt(t))/2}function yt(e,t,n,o){const s=document.createElementNS(C,"g");let i="";return e.text?i=e.text.textContent:i=e.childNodes[0].textContent,i.split(`
|
|
10
|
-
`).forEach((l,c)=>{const d=document.createElementNS(C,"text");b(d,{x:n+parseInt(t.paddingLeft)+"",y:o+parseInt(t.paddingTop)+vt(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}`}),d.innerHTML=l,s.appendChild(d)}),s}function bt(e,t,n,o){var l;let s="";(l=e.nodeObj)!=null&&l.dangerouslySetInnerHTML?s=e.nodeObj.dangerouslySetInnerHTML:e.text?s=e.text.textContent:s=e.childNodes[0].textContent;const i=document.createElementNS(C,"foreignObject");b(i,{x:n+parseInt(t.paddingLeft)+"",y:o+parseInt(t.paddingTop)+"",width:t.width,height:t.height});const r=document.createElement("div");return b(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=s,i.appendChild(r),i}function xt(e,t){const n=getComputedStyle(t),{offsetLeft:o,offsetTop:s}=N(e.nodes,t),i=document.createElementNS(C,"rect");return b(i,{x:o+"",y:s+"",rx:n.borderRadius,ry:n.borderRadius,width:n.width,height:n.height,fill:n.backgroundColor,stroke:n.borderColor,"stroke-width":n.borderWidth}),i}function G(e,t,n=!1){const o=getComputedStyle(t),{offsetLeft:s,offsetTop:i}=N(e.nodes,t),r=document.createElementNS(C,"rect");b(r,{x:s+"",y:i+"",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(C,"g");l.appendChild(r);let c;return n?c=bt(t,o,s,i):c=yt(t,o,s,i),l.appendChild(c),l}function wt(e,t){const n=getComputedStyle(t),{offsetLeft:o,offsetTop:s}=N(e.nodes,t),i=document.createElementNS(C,"a"),r=document.createElementNS(C,"text");return b(r,{x:o+"",y:s+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,i.appendChild(r),i.setAttribute("href",t.href),i}function _t(e,t){const n=getComputedStyle(t),{offsetLeft:o,offsetTop:s}=N(e.nodes,t),i=document.createElementNS(C,"image");return b(i,{x:o+"",y:s+"",width:n.width+"",height:n.height+"",href:t.src}),i}const K=100,Et='<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">',St=(e,t=!1)=>{var u,a,p;const n=e.nodes,o=n.offsetHeight+K*2,s=n.offsetWidth+K*2,i=gt(o+"px",s+"px"),r=document.createElementNS(C,"svg"),l=document.createElementNS(C,"rect");b(l,{x:"0",y:"0",width:`${s}`,height:`${o}`,fill:e.theme.cssVar["--bgcolor"]}),i.appendChild(l),n.querySelectorAll(".subLines").forEach(m=>{const f=m.cloneNode(!0),{offsetLeft:g,offsetTop:y}=N(n,m.parentElement);f.setAttribute("x",`${g}`),f.setAttribute("y",`${y}`),r.appendChild(f)});const c=(u=n.querySelector(".lines"))==null?void 0:u.cloneNode(!0);c&&r.appendChild(c);const d=(a=n.querySelector(".topiclinks"))==null?void 0:a.cloneNode(!0);d&&r.appendChild(d);const h=(p=n.querySelector(".summary"))==null?void 0:p.cloneNode(!0);return h&&r.appendChild(h),n.querySelectorAll("me-tpc").forEach(m=>{m.nodeObj.dangerouslySetInnerHTML?r.appendChild(G(e,m,!t)):(r.appendChild(xt(e,m)),r.appendChild(G(e,m.text,!t)))}),n.querySelectorAll(".tags > span").forEach(m=>{r.appendChild(G(e,m))}),n.querySelectorAll(".icons > span").forEach(m=>{r.appendChild(G(e,m))}),n.querySelectorAll(".hyper-link").forEach(m=>{r.appendChild(wt(e,m))}),n.querySelectorAll("img").forEach(m=>{r.appendChild(_t(e,m))}),b(r,{x:K+"",y:K+"",overflow:"visible"}),i.appendChild(r),i},Ct=(e,t)=>(t&&e.insertAdjacentHTML("afterbegin","<style>"+t+"</style>"),Et+e.outerHTML);function Lt(e){return new Promise((t,n)=>{const o=new FileReader;o.onload=s=>{t(s.target.result)},o.onerror=s=>{n(s)},o.readAsDataURL(e)})}const Mt={getObjById:F,generateNewObj:$e,layout:De,linkDiv:Ie,editTopic:qe,createWrapper:Pe,createParent:ze,createChildren:je,createTopic:Oe,findEle:L,changeTheme:et,...tt,...{},...ht,...mt,...Object.freeze(Object.defineProperty({__proto__:null,exportPng:async function(e=!1,t){const n=this.exportSvg(e,t),o=await Lt(n);return new Promise((s,i)=>{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(s,"image/png",1)},r.src=o,r.onerror=i})},exportSvg:function(e=!1,t){const n=St(this,e),o=Ct(n,t);return new Blob([o],{type:"image/svg+xml"})}},Symbol.toStringTag,{value:"Module"})),init(e){if(!e||!e.nodeData)return new Error("MindElixir: `data` is required");e.direction!==void 0&&(this.direction=e.direction),this.changeTheme(e.theme||this.theme,!1),this.nodeData=e.nodeData,ee(this.nodeData),this.arrows=e.arrows||[],this.summaries=e.summaries||[],this.tidyArrow(),this.toolBar&&Ye(this),this.toCenter(),this.layout(),this.linkDiv()}};function Tt({pT:e,pL:t,pW:n,pH:o,cT:s,cL:i,cW:r,cH:l,direction:c,containerHeight:d}){let h=t+n/2;const u=e+o/2;let a;c==="lhs"?a=i+r:a=i;const p=s+l/2,f=(1-Math.abs(p-u)/d)*.25*(n/2);return c==="lhs"?h=h-n/10-f:h=h+n/10+f,`M ${h} ${u} Q ${h} ${p} ${a} ${p}`}function Nt({pT:e,pL:t,pW:n,pH:o,cT:s,cL:i,cW:r,cH:l,direction:c,isFirst:d}){let h=0,u=0;d?h=e+o/2:h=e+o;const a=s+l;let p=0,m=0,f=0;const g=Math.abs(h-a)/300*T;return c==="lhs"?(f=t,p=f+T,m=f-T,u=i+T,`M ${p} ${h} C ${f} ${h} ${f+g} ${a} ${m} ${a} H ${u}`):(f=t+n,p=f-T,m=f+T,u=i+r-T,`M ${p} ${h} C ${f} ${h} ${f-g} ${a} ${m} ${a} H ${u}`)}const V=document;function M({el:e,direction:t,locale:n,draggable:o,editable:s,contextMenu:i,contextMenuOption:r,toolBar:l,keypress:c,mouseSelectionButton:d,before:h,newTopicName:u,allowUndo:a,generateMainBranch:p,generateSubBranch:m,overflowHidden:f,mobileMenu:g,theme:y}){console.log("ME_version "+M.version,this);let v=null;const w=Object.prototype.toString.call(e);if(w==="[object HTMLDivElement]"?v=e:w==="[object String]"&&(v=document.querySelector(e)),!v)throw new Error("MindElixir: el is not a valid element");v.className+=" mind-elixir",v.innerHTML="",v.style.setProperty("--gap",T+"px"),this.mindElixirBox=v,this.before=h||{},this.locale=n||"en",this.contextMenuOption=r,this.contextMenu=i===void 0?!0:i,this.toolBar=l===void 0?!0:l,this.keypress=c===void 0?!0:c,this.mouseSelectionButton=d||0,this.mobileMenu=g||!1,this.direction=typeof t=="number"?t:1,this.draggable=o===void 0?!0:o,this.newTopicName=u||"new node",this.editable=s===void 0?!0:s,this.allowUndo=a===void 0?!1:a,this.currentNode=null,this.currentArrow=null,this.scaleVal=1,this.tempDirection=null,this.generateMainBranch=p||Tt,this.generateSubBranch=m||Nt,this.overflowHidden=f||!1,this.bus=ke.create(),this.container=V.createElement("div"),this.container.className="map-container";const E=window.matchMedia("(prefers-color-scheme: dark)");this.theme=y||(E.matches?se:oe);const _=V.createElement("div");_.className="map-canvas",this.map=_,this.map.setAttribute("tabindex","0"),this.container.appendChild(this.map),this.mindElixirBox.appendChild(this.container),this.nodes=V.createElement("me-nodes"),this.nodes.className="main-node-container",this.lines=R("lines"),this.summarySvg=R("summary"),this.linkController=R("linkcontroller"),this.P2=V.createElement("div"),this.P3=V.createElement("div"),this.P2.className=this.P3.className="circle",this.P2.style.display=this.P3.style.display="none",this.line1=de(),this.line2=de(),this.linkController.appendChild(this.line1),this.linkController.appendChild(this.line2),this.linkSvgGroup=R("topiclinks"),this.map.appendChild(this.nodes),this.overflowHidden?this.container.style.overflow="hidden":Ae(this)}return M.prototype=Mt,M.LEFT=B,M.RIGHT=Q,M.SIDE=Z,M.THEME=oe,M.DARK_THEME=se,M.version="4.0.
|
|
10
|
+
`).forEach((l,c)=>{const d=document.createElementNS(C,"text");b(d,{x:n+parseInt(t.paddingLeft)+"",y:o+parseInt(t.paddingTop)+vt(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}`}),d.innerHTML=l,s.appendChild(d)}),s}function bt(e,t,n,o){var l;let s="";(l=e.nodeObj)!=null&&l.dangerouslySetInnerHTML?s=e.nodeObj.dangerouslySetInnerHTML:e.text?s=e.text.textContent:s=e.childNodes[0].textContent;const i=document.createElementNS(C,"foreignObject");b(i,{x:n+parseInt(t.paddingLeft)+"",y:o+parseInt(t.paddingTop)+"",width:t.width,height:t.height});const r=document.createElement("div");return b(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=s,i.appendChild(r),i}function xt(e,t){const n=getComputedStyle(t),{offsetLeft:o,offsetTop:s}=N(e.nodes,t),i=document.createElementNS(C,"rect");return b(i,{x:o+"",y:s+"",rx:n.borderRadius,ry:n.borderRadius,width:n.width,height:n.height,fill:n.backgroundColor,stroke:n.borderColor,"stroke-width":n.borderWidth}),i}function G(e,t,n=!1){const o=getComputedStyle(t),{offsetLeft:s,offsetTop:i}=N(e.nodes,t),r=document.createElementNS(C,"rect");b(r,{x:s+"",y:i+"",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(C,"g");l.appendChild(r);let c;return n?c=bt(t,o,s,i):c=yt(t,o,s,i),l.appendChild(c),l}function wt(e,t){const n=getComputedStyle(t),{offsetLeft:o,offsetTop:s}=N(e.nodes,t),i=document.createElementNS(C,"a"),r=document.createElementNS(C,"text");return b(r,{x:o+"",y:s+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,i.appendChild(r),i.setAttribute("href",t.href),i}function _t(e,t){const n=getComputedStyle(t),{offsetLeft:o,offsetTop:s}=N(e.nodes,t),i=document.createElementNS(C,"image");return b(i,{x:o+"",y:s+"",width:n.width+"",height:n.height+"",href:t.src}),i}const K=100,Et='<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">',St=(e,t=!1)=>{var u,a,p;const n=e.nodes,o=n.offsetHeight+K*2,s=n.offsetWidth+K*2,i=gt(o+"px",s+"px"),r=document.createElementNS(C,"svg"),l=document.createElementNS(C,"rect");b(l,{x:"0",y:"0",width:`${s}`,height:`${o}`,fill:e.theme.cssVar["--bgcolor"]}),i.appendChild(l),n.querySelectorAll(".subLines").forEach(m=>{const f=m.cloneNode(!0),{offsetLeft:g,offsetTop:y}=N(n,m.parentElement);f.setAttribute("x",`${g}`),f.setAttribute("y",`${y}`),r.appendChild(f)});const c=(u=n.querySelector(".lines"))==null?void 0:u.cloneNode(!0);c&&r.appendChild(c);const d=(a=n.querySelector(".topiclinks"))==null?void 0:a.cloneNode(!0);d&&r.appendChild(d);const h=(p=n.querySelector(".summary"))==null?void 0:p.cloneNode(!0);return h&&r.appendChild(h),n.querySelectorAll("me-tpc").forEach(m=>{m.nodeObj.dangerouslySetInnerHTML?r.appendChild(G(e,m,!t)):(r.appendChild(xt(e,m)),r.appendChild(G(e,m.text,!t)))}),n.querySelectorAll(".tags > span").forEach(m=>{r.appendChild(G(e,m))}),n.querySelectorAll(".icons > span").forEach(m=>{r.appendChild(G(e,m))}),n.querySelectorAll(".hyper-link").forEach(m=>{r.appendChild(wt(e,m))}),n.querySelectorAll("img").forEach(m=>{r.appendChild(_t(e,m))}),b(r,{x:K+"",y:K+"",overflow:"visible"}),i.appendChild(r),i},Ct=(e,t)=>(t&&e.insertAdjacentHTML("afterbegin","<style>"+t+"</style>"),Et+e.outerHTML);function Lt(e){return new Promise((t,n)=>{const o=new FileReader;o.onload=s=>{t(s.target.result)},o.onerror=s=>{n(s)},o.readAsDataURL(e)})}const Mt={getObjById:F,generateNewObj:$e,layout:De,linkDiv:Ie,editTopic:qe,createWrapper:Pe,createParent:ze,createChildren:je,createTopic:Oe,findEle:L,changeTheme:et,...tt,...{},...ht,...mt,...Object.freeze(Object.defineProperty({__proto__:null,exportPng:async function(e=!1,t){const n=this.exportSvg(e,t),o=await Lt(n);return new Promise((s,i)=>{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(s,"image/png",1)},r.src=o,r.onerror=i})},exportSvg:function(e=!1,t){const n=St(this,e),o=Ct(n,t);return new Blob([o],{type:"image/svg+xml"})}},Symbol.toStringTag,{value:"Module"})),init(e){if(!e||!e.nodeData)return new Error("MindElixir: `data` is required");e.direction!==void 0&&(this.direction=e.direction),this.changeTheme(e.theme||this.theme,!1),this.nodeData=e.nodeData,ee(this.nodeData),this.arrows=e.arrows||[],this.summaries=e.summaries||[],this.tidyArrow(),this.toolBar&&Ye(this),this.toCenter(),this.layout(),this.linkDiv()}};function Tt({pT:e,pL:t,pW:n,pH:o,cT:s,cL:i,cW:r,cH:l,direction:c,containerHeight:d}){let h=t+n/2;const u=e+o/2;let a;c==="lhs"?a=i+r:a=i;const p=s+l/2,f=(1-Math.abs(p-u)/d)*.25*(n/2);return c==="lhs"?h=h-n/10-f:h=h+n/10+f,`M ${h} ${u} Q ${h} ${p} ${a} ${p}`}function Nt({pT:e,pL:t,pW:n,pH:o,cT:s,cL:i,cW:r,cH:l,direction:c,isFirst:d}){let h=0,u=0;d?h=e+o/2:h=e+o;const a=s+l;let p=0,m=0,f=0;const g=Math.abs(h-a)/300*T;return c==="lhs"?(f=t,p=f+T,m=f-T,u=i+T,`M ${p} ${h} C ${f} ${h} ${f+g} ${a} ${m} ${a} H ${u}`):(f=t+n,p=f-T,m=f+T,u=i+r-T,`M ${p} ${h} C ${f} ${h} ${f-g} ${a} ${m} ${a} H ${u}`)}const V=document;function M({el:e,direction:t,locale:n,draggable:o,editable:s,contextMenu:i,contextMenuOption:r,toolBar:l,keypress:c,mouseSelectionButton:d,before:h,newTopicName:u,allowUndo:a,generateMainBranch:p,generateSubBranch:m,overflowHidden:f,mobileMenu:g,theme:y}){console.log("ME_version "+M.version,this);let v=null;const w=Object.prototype.toString.call(e);if(w==="[object HTMLDivElement]"?v=e:w==="[object String]"&&(v=document.querySelector(e)),!v)throw new Error("MindElixir: el is not a valid element");v.className+=" mind-elixir",v.innerHTML="",v.style.setProperty("--gap",T+"px"),this.mindElixirBox=v,this.before=h||{},this.locale=n||"en",this.contextMenuOption=r,this.contextMenu=i===void 0?!0:i,this.toolBar=l===void 0?!0:l,this.keypress=c===void 0?!0:c,this.mouseSelectionButton=d||0,this.mobileMenu=g||!1,this.direction=typeof t=="number"?t:1,this.draggable=o===void 0?!0:o,this.newTopicName=u||"new node",this.editable=s===void 0?!0:s,this.allowUndo=a===void 0?!1:a,this.currentNode=null,this.currentArrow=null,this.scaleVal=1,this.tempDirection=null,this.generateMainBranch=p||Tt,this.generateSubBranch=m||Nt,this.overflowHidden=f||!1,this.bus=ke.create(),this.container=V.createElement("div"),this.container.className="map-container";const E=window.matchMedia("(prefers-color-scheme: dark)");this.theme=y||(E.matches?se:oe);const _=V.createElement("div");_.className="map-canvas",this.map=_,this.map.setAttribute("tabindex","0"),this.container.appendChild(this.map),this.mindElixirBox.appendChild(this.container),this.nodes=V.createElement("me-nodes"),this.nodes.className="main-node-container",this.lines=R("lines"),this.summarySvg=R("summary"),this.linkController=R("linkcontroller"),this.P2=V.createElement("div"),this.P3=V.createElement("div"),this.P2.className=this.P3.className="circle",this.P2.style.display=this.P3.style.display="none",this.line1=de(),this.line2=de(),this.linkController.appendChild(this.line1),this.linkController.appendChild(this.line2),this.linkSvgGroup=R("topiclinks"),this.map.appendChild(this.nodes),this.overflowHidden?this.container.style.overflow="hidden":Ae(this)}return M.prototype=Mt,M.LEFT=B,M.RIGHT=Q,M.SIDE=Z,M.THEME=oe,M.DARK_THEME=se,M.version="4.0.1",M.E=L,M}();
|
package/dist/MindElixirLite.js
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ declare function MindElixir(this: MindElixirInstance, { el, direction, locale, d
|
|
|
9
9
|
declare namespace MindElixir {
|
|
10
10
|
export var prototype: {
|
|
11
11
|
init(this: MindElixirInstance, data: MindElixirData): Error | undefined;
|
|
12
|
-
exportSvg: (this: MindElixirInstance,
|
|
13
|
-
exportPng: (this: MindElixirInstance,
|
|
12
|
+
exportSvg: (this: MindElixirInstance, noForeignObject?: boolean, injectCss?: string | undefined) => Blob;
|
|
13
|
+
exportPng: (this: MindElixirInstance, noForeignObject?: boolean, injectCss?: string | undefined) => Promise<Blob | null>;
|
|
14
14
|
createSummary: (this: MindElixirInstance) => void;
|
|
15
15
|
removeSummary: (this: MindElixirInstance, id: string) => void;
|
|
16
16
|
selectSummary: (this: MindElixirInstance, el: import("./summary").SummarySvgGroup) => void;
|
package/dist/types/methods.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ export type MindElixirMethods = typeof methods;
|
|
|
11
11
|
*/
|
|
12
12
|
declare const methods: {
|
|
13
13
|
init(this: MindElixirInstance, data: MindElixirData): Error | undefined;
|
|
14
|
-
exportSvg: (this: MindElixirInstance,
|
|
15
|
-
exportPng: (this: MindElixirInstance,
|
|
14
|
+
exportSvg: (this: MindElixirInstance, noForeignObject?: boolean, injectCss?: string | undefined) => Blob;
|
|
15
|
+
exportPng: (this: MindElixirInstance, noForeignObject?: boolean, injectCss?: string | undefined) => Promise<Blob | null>;
|
|
16
16
|
createSummary: (this: MindElixirInstance) => void;
|
|
17
17
|
removeSummary: (this: MindElixirInstance, id: string) => void;
|
|
18
18
|
selectSummary: (this: MindElixirInstance, el: summary.SummarySvgGroup) => void;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { MindElixirInstance } from '../types';
|
|
2
|
-
export declare const exportSvg: (this: MindElixirInstance,
|
|
3
|
-
export declare const exportPng: (this: MindElixirInstance,
|
|
2
|
+
export declare const exportSvg: (this: MindElixirInstance, noForeignObject?: boolean, injectCss?: string) => Blob;
|
|
3
|
+
export declare const exportPng: (this: MindElixirInstance, noForeignObject?: boolean, injectCss?: string) => Promise<Blob | null>;
|