mind-elixir 4.1.1 → 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/MindElixir.iife.js +5 -5
- package/dist/MindElixir.js +427 -415
- package/dist/MindElixirLite.iife.js +1 -1
- package/dist/MindElixirLite.js +1 -1
- package/package.json +1 -1
|
@@ -7,4 +7,4 @@ var MindElixirLite=function(){"use strict";const kt="";(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=be(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(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)}},selectNodes:function(e){this.clearSelection();for(const t of e)t.className="selected";this.currentNodes=e,this.bus.fire("selectNodes",e.map(t=>t.nodeObj))},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"})),xe={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 Y(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 st=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},we=function(e,t,n,o,s){if(!t||!n)return;performance.now();const i=Y(e,t,o.delta1),r=Y(e,n,o.delta2),{x:l,y:c}=q(i),{ctrlX:d,ctrlY:h}=i,{ctrlX:u,ctrlY:a}=r,{x:p,y:m}=q(r),f=ie(u,a,p,m),g=Ve(`M ${l} ${c} C ${d} ${h} ${u} ${a} ${p} ${m}`,`M ${f.x1} ${f.y1} L ${p} ${m} L ${f.x2} ${f.y2}`),y=l/8+d*3/8+u*3/8+p/8,v=c/8+h*3/8+a*3/8+m/8,w=st(o.label,y,v,e.theme.cssVar["--color"]);g.appendChild(w),g.arrowObj=o,g.dataset.linkid=o.id,e.linkSvgGroup.appendChild(g),s||(e.arrows.push(o),e.currentArrow=g,Ee(e,o,i,r)),performance.now()},it=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}};we(this,e,t,n),this.bus.fire("operation",{name:"createArrow",obj:n})},rt=function(e){let t;if(e?t=e:t=this.currentArrow,!t)return;_e(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}})},lt=function(e){this.currentArrow=e;const t=e.arrowObj,n=L(t.from),o=L(t.to),s=Y(this,n,t.delta1),i=Y(this,o,t.delta2);Ee(this,t,s,i)},ct=function(){this.currentArrow=null,_e(this)},_e=function(e){e.linkController.style.display="none",e.P2.style.display="none",e.P3.style.display="none"},Ee=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=xe.create(e.P2),e.helper2=xe.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=ie(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 at(){this.linkSvgGroup.innerHTML="";for(let e=0;e<this.arrows.length;e++){const t=this.arrows[e];try{we(this,L(t.from),L(t.to),t,!0)}catch{}}this.nodes.appendChild(this.linkSvgGroup)}function ht(e){if(!e)return;const t=e.children[2];de(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}))})}function dt(){this.arrows=this.arrows.filter(e=>F(e.from,this.nodeData)&&F(e.to,this.nodeData))}const ut=Object.freeze(Object.defineProperty({__proto__:null,createArrow:it,editArrowLabel:ht,removeArrow:rt,renderArrow:at,selectArrow:lt,tidyArrow:dt,unselectArrow:ct},Symbol.toStringTag,{value:"Module"})),ft=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.parent)throw new Error("Please select nodes in the same main topic.");return{parent:l.id,start:i,end:r}},pt=function(e){const t=document.createElementNS("http://www.w3.org/2000/svg","g");return t.setAttribute("id",e),t},Se=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},Ce=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},mt=e=>L(e).parentElement.parentElement,gt=function({parent:e,start:t}){var i,r;const n=L(e),o=n.nodeObj;let s;return o.parent?s=(i=n.closest("me-main"))==null?void 0:i.className:s=(r=L(o.children[t].id).closest("me-main"))==null?void 0:r.className,s},Le=function(e,t){var Me;const{id:n,text:o,parent:s,start:i,end:r}=t,l=e.nodes,d=L(s).nodeObj,h=gt(t);let u=1/0,a=0,p=0,m=0;for(let I=i;I<=r;I++){const Te=(Me=d.children)==null?void 0:Me[I];if(!Te)return e.removeSummary(n),null;const U=mt(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=Se(`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=Ce(o,u-20,w+6,"end",E)):(f=Se(`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=Ce(o,a+20,w+6,"start",E));const _=pt("s-"+n);return _.appendChild(f),_.appendChild(g),_.summaryObj=t,e.summarySvg.appendChild(_),_},vt=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}=ft(e),s={id:te(),parent:t,start:n,end:o,text:"summary"},i=Le(this,s);this.summaries.push(s),this.editSummary(i),this.bus.fire("operation",{name:"createSummary",obj:s})},editSummary:function(e){if(!e)return;const t=e.childNodes[1];de(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}))})},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{Le(this,e)}catch{}}),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 yt(e,t){const n=document.createElementNS(C,"svg");return b(n,{version:"1.1",xmlns:C,height:e,width:t}),n}function bt(e,t){return(parseInt(e)-parseInt(t))/2}function xt(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)+bt(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 wt(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 _t(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=wt(t,o,s,i):c=xt(t,o,s,i),l.appendChild(c),l}function Et(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 St(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,Ct='<?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">',Lt=(e,t=!1)=>{var u,a,p;const n=e.nodes,o=n.offsetHeight+K*2,s=n.offsetWidth+K*2,i=yt(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(_t(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(Et(e,m))}),n.querySelectorAll("img").forEach(m=>{r.appendChild(St(e,m))}),b(r,{x:K+"",y:K+"",overflow:"visible"}),i.appendChild(r),i},Mt=(e,t)=>(t&&e.insertAdjacentHTML("afterbegin","<style>"+t+"</style>"),Ct+e.outerHTML);function Tt(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 Nt={getObjById:F,generateNewObj:$e,layout:De,linkDiv:Ie,editTopic:qe,createWrapper:Pe,createParent:ze,createChildren:je,createTopic:Oe,findEle:L,changeTheme:tt,...ot,...{},...ut,...vt,...Object.freeze(Object.defineProperty({__proto__:null,exportPng:async function(e=!1,t){const n=this.exportSvg(e,t),o=await Tt(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=Lt(this,e),o=Mt(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&&Xe(this),this.toCenter(),this.layout(),this.linkDiv()},destroy(){var e,t;this.disposable.forEach(n=>n()),(e=this.mindElixirBox)==null||e.remove(),this.mindElixirBox=void 0,this.nodeData=void 0,this.arrows=void 0,this.summaries=void 0,this.currentArrow=void 0,this.currentNode=void 0,this.currentNodes=void 0,this.currentSummary=void 0,this.waitCopy=void 0,this.theme=void 0,this.direction=void 0,this.bus=void 0,this.container=void 0,this.map=void 0,this.lines=void 0,this.linkController=void 0,this.linkSvgGroup=void 0,this.P2=void 0,this.P3=void 0,this.line1=void 0,this.line2=void 0,this.nodes=void 0,(t=this.selection)==null||t.destroy(),this.selection=void 0}};function $t({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 At({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}){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.disposable=[],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||$t,this.generateSubBranch=m||At,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?oe:ne);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=he(),this.line2=he(),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=Nt,M.LEFT=B,M.RIGHT=Q,M.SIDE=Z,M.THEME=ne,M.DARK_THEME=oe,M.version="4.1.
|
|
10
|
+
`).forEach((l,c)=>{const d=document.createElementNS(C,"text");b(d,{x:n+parseInt(t.paddingLeft)+"",y:o+parseInt(t.paddingTop)+bt(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 wt(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 _t(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=wt(t,o,s,i):c=xt(t,o,s,i),l.appendChild(c),l}function Et(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 St(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,Ct='<?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">',Lt=(e,t=!1)=>{var u,a,p;const n=e.nodes,o=n.offsetHeight+K*2,s=n.offsetWidth+K*2,i=yt(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(_t(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(Et(e,m))}),n.querySelectorAll("img").forEach(m=>{r.appendChild(St(e,m))}),b(r,{x:K+"",y:K+"",overflow:"visible"}),i.appendChild(r),i},Mt=(e,t)=>(t&&e.insertAdjacentHTML("afterbegin","<style>"+t+"</style>"),Ct+e.outerHTML);function Tt(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 Nt={getObjById:F,generateNewObj:$e,layout:De,linkDiv:Ie,editTopic:qe,createWrapper:Pe,createParent:ze,createChildren:je,createTopic:Oe,findEle:L,changeTheme:tt,...ot,...{},...ut,...vt,...Object.freeze(Object.defineProperty({__proto__:null,exportPng:async function(e=!1,t){const n=this.exportSvg(e,t),o=await Tt(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=Lt(this,e),o=Mt(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&&Xe(this),this.toCenter(),this.layout(),this.linkDiv()},destroy(){var e,t;this.disposable.forEach(n=>n()),(e=this.mindElixirBox)==null||e.remove(),this.mindElixirBox=void 0,this.nodeData=void 0,this.arrows=void 0,this.summaries=void 0,this.currentArrow=void 0,this.currentNode=void 0,this.currentNodes=void 0,this.currentSummary=void 0,this.waitCopy=void 0,this.theme=void 0,this.direction=void 0,this.bus=void 0,this.container=void 0,this.map=void 0,this.lines=void 0,this.linkController=void 0,this.linkSvgGroup=void 0,this.P2=void 0,this.P3=void 0,this.line1=void 0,this.line2=void 0,this.nodes=void 0,(t=this.selection)==null||t.destroy(),this.selection=void 0}};function $t({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 At({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}){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.disposable=[],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||$t,this.generateSubBranch=m||At,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?oe:ne);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=he(),this.line2=he(),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=Nt,M.LEFT=B,M.RIGHT=Q,M.SIDE=Z,M.THEME=ne,M.DARK_THEME=oe,M.version="4.1.2",M.E=L,M}();
|
package/dist/MindElixirLite.js
CHANGED