flow-mindmap 0.1.0-beta.1 → 0.1.1-beta.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.
@@ -1 +1,5 @@
1
- (function(D,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(D=typeof globalThis<"u"?globalThis:D||self,e(D.FlowMind={},D.Vue))})(this,function(D,e){"use strict";const It=["width","height","stroke-width"],Wt={key:4,points:"6 9 12 15 18 9"},$t={key:5,points:"9 6 15 12 9 18"},z=e.defineComponent({__name:"Icon",props:{name:{},size:{},stroke:{}},setup(o){return(u,l)=>(e.openBlock(),e.createElementBlock("svg",{width:o.size??16,height:o.size??16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":o.stroke??1.8,"stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[o.name==="add"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[l[0]||(l[0]=e.createElementVNode("circle",{cx:"12",cy:"12",r:"9"},null,-1)),l[1]||(l[1]=e.createElementVNode("line",{x1:"12",y1:"8",x2:"12",y2:"16"},null,-1)),l[2]||(l[2]=e.createElementVNode("line",{x1:"8",y1:"12",x2:"16",y2:"12"},null,-1))],64)):o.name==="minus"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[l[3]||(l[3]=e.createElementVNode("circle",{cx:"12",cy:"12",r:"9"},null,-1)),l[4]||(l[4]=e.createElementVNode("line",{x1:"8",y1:"12",x2:"16",y2:"12"},null,-1))],64)):o.name==="delete"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[l[5]||(l[5]=e.createStaticVNode('<polyline points="4 7 20 7"></polyline><path d="M9 7 V5 a1 1 0 0 1 1 -1 h4 a1 1 0 0 1 1 1 V7"></path><path d="M6 7 l1 12 a1 1 0 0 0 1 1 h8 a1 1 0 0 0 1 -1 l1 -12"></path><line x1="10" y1="11" x2="10" y2="18"></line><line x1="14" y1="11" x2="14" y2="18"></line>',5))],64)):o.name==="edit"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:3},[l[6]||(l[6]=e.createElementVNode("path",{d:"M4 20 l4 -1 11 -11 -3 -3 -11 11 z"},null,-1)),l[7]||(l[7]=e.createElementVNode("line",{x1:"14",y1:"6",x2:"18",y2:"10"},null,-1))],64)):o.name==="collapse"?(e.openBlock(),e.createElementBlock("polyline",Wt)):o.name==="expand"?(e.openBlock(),e.createElementBlock("polyline",$t)):o.name==="zoom-in"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:6},[l[8]||(l[8]=e.createElementVNode("circle",{cx:"11",cy:"11",r:"7"},null,-1)),l[9]||(l[9]=e.createElementVNode("line",{x1:"11",y1:"8",x2:"11",y2:"14"},null,-1)),l[10]||(l[10]=e.createElementVNode("line",{x1:"8",y1:"11",x2:"14",y2:"11"},null,-1)),l[11]||(l[11]=e.createElementVNode("line",{x1:"16",y1:"16",x2:"21",y2:"21"},null,-1))],64)):o.name==="zoom-out"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:7},[l[12]||(l[12]=e.createElementVNode("circle",{cx:"11",cy:"11",r:"7"},null,-1)),l[13]||(l[13]=e.createElementVNode("line",{x1:"8",y1:"11",x2:"14",y2:"11"},null,-1)),l[14]||(l[14]=e.createElementVNode("line",{x1:"16",y1:"16",x2:"21",y2:"21"},null,-1))],64)):o.name==="reset"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:8},[l[15]||(l[15]=e.createElementVNode("circle",{cx:"12",cy:"12",r:"9"},null,-1)),l[16]||(l[16]=e.createElementVNode("circle",{cx:"12",cy:"12",r:"4"},null,-1)),l[17]||(l[17]=e.createElementVNode("circle",{cx:"12",cy:"12",r:"0.8",fill:"currentColor"},null,-1))],64)):o.name==="logo"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:9},[l[18]||(l[18]=e.createStaticVNode('<circle cx="12" cy="12" r="2.2"></circle><circle cx="4" cy="5" r="1.6"></circle><circle cx="20" cy="5" r="1.6"></circle><circle cx="4" cy="19" r="1.6"></circle><circle cx="20" cy="19" r="1.6"></circle><line x1="10.5" y1="10.8" x2="5.2" y2="6.4"></line><line x1="13.5" y1="10.8" x2="18.8" y2="6.4"></line><line x1="10.5" y1="13.2" x2="5.2" y2="17.6"></line><line x1="13.5" y1="13.2" x2="18.8" y2="17.6"></line>',9))],64)):o.name==="import"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:10},[l[19]||(l[19]=e.createElementVNode("path",{d:"M12 4 V15"},null,-1)),l[20]||(l[20]=e.createElementVNode("polyline",{points:"7 10 12 15 17 10"},null,-1)),l[21]||(l[21]=e.createElementVNode("path",{d:"M4 19 H20"},null,-1))],64)):o.name==="export"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:11},[l[22]||(l[22]=e.createElementVNode("path",{d:"M12 15 V4"},null,-1)),l[23]||(l[23]=e.createElementVNode("polyline",{points:"7 9 12 4 17 9"},null,-1)),l[24]||(l[24]=e.createElementVNode("path",{d:"M4 19 H20"},null,-1))],64)):o.name==="balance"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:12},[l[25]||(l[25]=e.createStaticVNode('<line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="18" x2="21" y2="18"></line><polyline points="9 4 5 6 9 8"></polyline><polyline points="15 4 19 6 15 8"></polyline><polyline points="9 10 5 12 9 14"></polyline><polyline points="15 10 19 12 15 14"></polyline><polyline points="9 16 5 18 9 20"></polyline><polyline points="15 16 19 18 15 20"></polyline>',9))],64)):o.name==="mindmap"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:13},[l[26]||(l[26]=e.createStaticVNode('<circle cx="12" cy="12" r="2.2" fill="currentColor" stroke="none"></circle><line x1="13" y1="11" x2="19" y2="6"></line><line x1="13" y1="13" x2="19" y2="18"></line><line x1="11" y1="11" x2="5" y2="6"></line><line x1="11" y1="13" x2="5" y2="18"></line>',5))],64)):o.name==="tree"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:14},[l[27]||(l[27]=e.createStaticVNode('<circle cx="6" cy="12" r="2" fill="currentColor" stroke="none"></circle><circle cx="18" cy="6" r="2" fill="currentColor" stroke="none"></circle><circle cx="18" cy="12" r="2" fill="currentColor" stroke="none"></circle><circle cx="18" cy="18" r="2" fill="currentColor" stroke="none"></circle><line x1="8" y1="12" x2="16" y2="6"></line><line x1="8" y1="12" x2="16" y2="12"></line><line x1="8" y1="12" x2="16" y2="18"></line>',7))],64)):o.name==="org"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:15},[l[28]||(l[28]=e.createStaticVNode('<circle cx="12" cy="5" r="2" fill="currentColor" stroke="none"></circle><circle cx="6" cy="19" r="2" fill="currentColor" stroke="none"></circle><circle cx="12" cy="19" r="2" fill="currentColor" stroke="none"></circle><circle cx="18" cy="19" r="2" fill="currentColor" stroke="none"></circle><line x1="12" y1="7" x2="12" y2="13"></line><line x1="6" y1="13" x2="18" y2="13"></line><line x1="6" y1="13" x2="6" y2="17"></line><line x1="12" y1="13" x2="12" y2="17"></line><line x1="18" y1="13" x2="18" y2="17"></line>',9))],64)):o.name==="image"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:16},[l[29]||(l[29]=e.createElementVNode("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2"},null,-1)),l[30]||(l[30]=e.createElementVNode("circle",{cx:"9",cy:"11",r:"1.6"},null,-1)),l[31]||(l[31]=e.createElementVNode("polyline",{points:"3 17 9 12 13 15 16 13 21 17"},null,-1))],64)):o.name==="x"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:17},[l[32]||(l[32]=e.createElementVNode("line",{x1:"6",y1:"6",x2:"18",y2:"18"},null,-1)),l[33]||(l[33]=e.createElementVNode("line",{x1:"18",y1:"6",x2:"6",y2:"18"},null,-1))],64)):o.name==="link"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:18},[l[34]||(l[34]=e.createElementVNode("path",{d:"M10 13 a4 4 0 0 0 5.66 0 l3 -3 a4 4 0 1 0 -5.66 -5.66 l-1 1"},null,-1)),l[35]||(l[35]=e.createElementVNode("path",{d:"M14 11 a4 4 0 0 0 -5.66 0 l-3 3 a4 4 0 1 0 5.66 5.66 l1 -1"},null,-1))],64)):o.name==="note"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:19},[l[36]||(l[36]=e.createElementVNode("path",{d:"M6 4 h9 l3 3 v13 a1 1 0 0 1 -1 1 h-11 a1 1 0 0 1 -1 -1 v-15 a1 1 0 0 1 1 -1 z"},null,-1)),l[37]||(l[37]=e.createElementVNode("line",{x1:"8",y1:"10",x2:"16",y2:"10"},null,-1)),l[38]||(l[38]=e.createElementVNode("line",{x1:"8",y1:"13",x2:"16",y2:"13"},null,-1)),l[39]||(l[39]=e.createElementVNode("line",{x1:"8",y1:"16",x2:"13",y2:"16"},null,-1))],64)):e.createCommentVNode("",!0)],8,It))}}),Rt="data:image/svg+xml,%3csvg%20t='1780822312364'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='7459'%20width='200'%20height='200'%3e%3cpath%20d='M329.16%20292.571h658.286V512H329.16zM329.16%200h658.286v219.429H329.16z'%20fill='%239AA1A2'%20p-id='7460'%3e%3c/path%3e%3cpath%20d='M44.927%20146.286a46.519%2046.519%200%200%201%2038.107-73.143h319.269v73.143H109.73V791.99l-48.713%205.705-24.43-651.41h8.339z'%20fill='%239AA1A2'%20p-id='7461'%3e%3c/path%3e%3cpath%20d='M363.83%20877.714H179.51c-78.775%200-142.921-66.12-142.921-147.31V112.787c0-21.943%2017.188-39.643%2038.473-39.643%2021.211%200%2033.5%2017.774%2033.5%2039.643v617.619c0%2037.522%2028.013%2076.58%2064.438%2076.58h190.903c21.211%200%2038.766%2013.97%2038.766%2035.84%200%2021.943-17.555%2034.89-38.766%2034.89z'%20fill='%239AA1A2'%20p-id='7462'%3e%3c/path%3e%3cpath%20d='M432.95%20438.857H179.51c-78.775%200-81.043-18.578-81.043-62.903l10.094-90.624c0%2020.48%2013.458%2080.677%2049.884%2080.677h210.139c21.211%200%20120.613%204.023%20120.613%2016.018%200%2011.922-35.036%2056.832-56.32%2056.832zM640.017%20749.714V640a54.857%2054.857%200%200%201%20109.714%200v109.714h109.715a54.857%2054.857%200%200%201%200%20109.715H749.73v109.714a54.857%2054.857%200%200%201-109.714%200V859.429H530.303a54.857%2054.857%200%200%201%200-109.715h109.714z'%20fill='%239AA1A2'%20p-id='7463'%3e%3c/path%3e%3c/svg%3e",Dt="data:image/svg+xml,%3csvg%20t='1780822464335'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='8457'%20width='200'%20height='200'%3e%3cpath%20d='M512%20804.571h512V1024H512V804.571zM0%200h658.286v219.429H0V0z'%20fill='%239AA1A2'%20p-id='8458'%3e%3c/path%3e%3cpath%20d='M619.813%20950.857h-184.32c-78.775%200-142.922-66.121-142.922-147.31V185.93c0-21.943%2017.189-39.643%2038.474-39.643%2021.211%200%2033.353%2017.773%2033.353%2039.643v617.618c0%2037.523%2034.743%2073.728%2071.095%2073.728h184.32c21.211%200%2038.473%2012.069%2038.473%2033.939%200%2021.943-17.189%2039.643-38.473%2039.643z'%20fill='%239AA1A2'%20p-id='8459'%3e%3c/path%3e%3cpath%20d='M676.571%20457.143V347.429a54.857%2054.857%200%200%201%20109.715%200v109.714H896a54.857%2054.857%200%200%201%200%20109.714H786.286v109.714a54.857%2054.857%200%200%201-109.715%200V566.857H566.857a54.857%2054.857%200%200%201%200-109.714h109.714z'%20fill='%239AA1A2'%20p-id='8460'%3e%3c/path%3e%3c/svg%3e",Me=[18,15,13,12],Lt=[700,600,500,400],At=[52,40,32,28],je=[120,80,60,44],Ht=[.8,.8,.8,.8],Pt=Me.length-1;function Tt(o){return Math.round(Me[Be(o)]*Ht[Be(o)])}function Be(o){return Math.min(Pt,Math.max(0,o))}function Ft(o){return Me[Be(o)]}const Ce=60,le=14,F=24;let Ae=null;function Ot(){if(Ae)return Ae;const o=typeof document<"u"?document.createElement("canvas").getContext("2d"):null;return o?(Ae=o,o):{font:"",measureText:()=>({width:0})}}const Ge=new Map;function qt(o,u,l){const i=`${l}|${u}|${o}`,c=Ge.get(i);if(c!==void 0)return c;const d=Ot();d.font=`${l} ${u}px "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif`;const m=d.measureText(o).width;return Ge.set(i,m),m}const Xt=24,Kt=400,Ut=8,Je=16,Yt=4;function jt(o,u,l){return Math.min(l,Math.max(u,o))}function Gt(o,u){const l=Be(u),i=qt(o.text||"",Me[l],Lt[l]),c=Tt(u),d=Math.ceil(i+c*2),m=At[l];let p=0;if(o.link&&(p+=Je),o.note&&(p+=Je),p>0){const v=(o.link?1:0)+(o.note?1:0);p+=Yt*v}const g=d+p;if(!o.image)return{w:Math.max(je[l],g),h:m};const x=jt(o.image.width,Xt,Kt),s=Math.max(je[l],g,Math.ceil(x+c*2)),w=Math.ceil(o.image.height+Ut+m);return{w:s,h:w}}function Jt(o,u={}){const l=u.mode??"mindmap",i=u.preservePositions===!0,c=Qe(o,0,null,1,"right");return Qt(c),Zt(c,l,i),c.x=0,c.y=0,_t(c,i)}function Zt(o,u,l=!1){if(u==="mindmap"){const i=o.children;if(i.length!==0)if(i.length===1)i[0]._dir="right",i[0].side=1,i[0]._dirRight=1;else{const p=i.reduce((w,v)=>w+v._subtreeH,0);let g=1,x=Math.abs(i[0]._subtreeH-(p-i[0]._subtreeH)),s=0;for(let w=0;w<i.length-1;w++){s+=i[w]._subtreeH;const v=Math.abs(s-(p-s));v<x&&(x=v,g=w+1)}for(let w=0;w<g;w++)i[w]._dir="right",i[w].side=1,i[w]._dirRight=1;for(let w=g;w<i.length;w++)i[w]._dir="left",i[w].side=-1,i[w]._dirRight=-1}const c=o.children.filter(p=>p.side===1),d=o.children.filter(p=>p.side===-1),m=(p,g)=>{const x=g==="right"?1:-1;p._dir=g,p.side=x,p._dirRight=x;for(const s of p.children)m(s,g)};for(const p of c)m(p,"right");for(const p of d)m(p,"left");if(c.length>0){const p={...o,children:c};ve(p,"right",Ce,!0,l)}if(d.length>0){const p={...o,children:d};ve(p,"left",Ce,!0,l)}}else if(u==="tree"){const i=c=>{c.side=1,c._dir="right";for(const d of c.children)i(d)};for(const c of o.children)c._dir="right";ve(o,"right",Ce,!0,l),i(o)}else{for(const i of o.children)i._dir="down";Ze(o,Ce,l)}}function ve(o,u,l,i,c=!1){if(o.children.length===0)return;const d=o.children.reduce((x,s,w)=>x+s._subtreeH+(w>0?le:0),0),m=u==="right"?1:-1,p=i?m:1;let g=o.y-p*d/2;o.children.forEach(x=>{c||(x.x=o.x+m*(o.width/2+l+x.width/2),x.y=g+p*x._subtreeH/2),x._dir=u,g+=p*(x._subtreeH+le),ve(x,u,l,!1,c)})}function Ze(o,u,l=!1){if(o.children.length===0)return;const i=o.children.reduce((d,m,p)=>d+m._subtreeW+(p>0?le*2:0),0);let c=o.x-i/2;o.children.forEach(d=>{l||(d.x=c+d._subtreeW/2,d.y=o.y+o.height/2+u+d.height/2),d._dir="down",c+=d._subtreeW+le*2,Ze(d,u,l)})}function Qe(o,u,l,i,c){const d=Gt(o,u),m={id:o.id,text:o.text,depth:u,x:o._x??0,y:o._y??0,width:d.w,height:d.h,fontSize:Ft(u),isRoot:u===0,collapsed:o.collapsed,side:i,_dir:c,_dirRight:i,_subtreeH:d.h,_subtreeW:d.w,image:o.image?{...o.image}:void 0,link:o.link?{url:o.link.url}:void 0,note:o.note?{text:o.note.text}:void 0,children:[],parent:l};if(o.collapsed)return m;const p=o.children.length,g=Math.ceil(p/2);return m.children=o.children.map((x,s)=>{const w=u===0?s<g?1:-1:i;return Qe(x,u+1,m,w,c)}),m}function Qt(o){const u=[o];for(let l=0;l<u.length;l++){const i=u[l];for(const c of i.children)u.push(c)}for(let l=u.length-1;l>=0;l--){const i=u[l];if(i.collapsed||i.children.length===0){i._subtreeH=i.height,i._subtreeW=i.width;continue}let c=0,d=0;for(const m of i.children)c+=m._subtreeH,d+=m._subtreeW;i.children.length>1&&(c+=le*(i.children.length-1),d+=le*2*(i.children.length-1)),i._subtreeH=Math.max(i.height,c),i._subtreeW=Math.max(i.width,d)}}function _t(o,u=!1){const l=[o];let i=1/0,c=-1/0,d=1/0,m=-1/0;for(;l.length;){const x=l.pop(),s=x.width/2,w=x.height/2;x.x-s<i&&(i=x.x-s),x.x+s>c&&(c=x.x+s),x.y-w<d&&(d=x.y-w),x.y+w>m&&(m=x.y+w),l.push(...x.children)}if(u)return{root:o,width:c-i+F*2,height:m-d+F*2,vbX:i-F,vbY:d-F,vbW:c-i+F*2,vbH:m-d+F*2};const p=F-d,g=[o];for(;g.length;){const x=g.pop();x.y+=p,g.push(...x.children)}return d+=p,m+=p,{root:o,width:c-i+F*2,height:m+F,vbX:i-F,vbY:0,vbW:c-i+F*2,vbH:m+F}}const ue=[{id:"default",name:"默认",colors:["#f87171","#fb923c","#fbbf24","#a3e635","#34d399","#22d3ee","#818cf8","#c084fc"]},{id:"classic",name:"经典",colors:["#ef4444","#f59e0b","#10b981","#3b82f6","#6366f1","#8b5cf6","#ec4899","#14b8a6"]},{id:"vivid",name:"活力",colors:["#dc2626","#ea580c","#ca8a04","#16a34a","#0891b2","#2563eb","#7c3aed","#db2777"]},{id:"dev",name:"代码",colors:["#f472b6","#a78bfa","#60a5fa","#38bdf8","#22d3ee","#34d399","#facc15","#fb923c"]},{id:"mint",name:"薄荷",colors:["#5eead4","#67e8f9","#93c5fd","#c4b5fd","#fbcfe8","#fde68a","#a7f3d0","#bae6fd"]}];function en(o,u=[]){return[...ue,...u].find(i=>i.id===o)??ue[0]}function fe(){return"n_"+Math.random().toString(36).slice(2,10)+Date.now().toString(36).slice(-4)}function J(o){return JSON.parse(JSON.stringify(o))}function B(o,u){if(o.id===u)return o;for(const l of o.children){const i=B(l,u);if(i)return i}return null}function O(o,u,l=null){if(o.id===u)return l;for(const i of o.children){const c=O(i,u,o);if(c!==null)return c}return null}function He(o,u){const l=o.children.findIndex(i=>i.id===u);if(l>=0)return o.children.splice(l,1),!0;for(const i of o.children)if(He(i,u))return!0;return!1}function tn(o,u,l){const i=B(o,u);return!i||i.text===l?!1:(i.text=l,!0)}function nn(o,u,l,i){if(!O(o,u)||u===l||B(B(o,u),l))return!1;const c=O(o,u),d=c.children.findIndex(x=>x.id===u);if(d<0)return!1;const[m]=c.children.splice(d,1);if(i==="child"){const x=B(o,l);return x?(x.children.push(m),!0):(c.children.splice(d,0,m),!1)}const p=O(o,l);if(!p)return c.children.splice(d,0,m),!1;let g=p.children.findIndex(x=>x.id===l);return g<0?(c.children.splice(d,0,m),!1):(i==="after"&&(g+=1),p.children.splice(g,0,m),!0)}function _e(o){const u=/^新节点(?:\s+(\d+))?$/;let l=0,i=!1;for(const c of o.children){const d=c.text.match(u);if(d)if(d[1]){const m=parseInt(d[1],10);m>l&&(l=m)}else i=!0}return l===0&&!i?Se:l>0?`新节点 ${l+1}`:"新节点 2"}function et(o,u,l){const i=B(o,u);if(!i)return null;const c={id:fe(),text:l??_e(i),children:[]};return i.children.push(c),c}function tt(o,u,l){const i=O(o,u);if(!i)return null;const c=i.children.findIndex(m=>m.id===u);if(c<0)return null;const d={id:fe(),text:l??_e(i),children:[]};return i.children.splice(c+1,0,d),d}function on(o,u,l){const i=O(o,u);if(!i)return null;const c=i.children.findIndex(m=>m.id===u);if(c<0)return null;const d={id:fe(),text:l,children:[]};return i.children.splice(c,0,d),d}function ln(o,u){const l=O(o,u);if(!l)return null;const i=l.children.findIndex(m=>m.id===u);if(i<0)return null;const c=l.children[i],d=J(c);return nt(d),l.children.splice(i+1,0,d),d}function nt(o){o.id=fe();for(const u of o.children)nt(u)}const Se="新节点";function rn(o){const u=o.minScale??.2,l=o.maxScale??3,i=o.step??1.2,c=e.ref(1),d=e.ref(0),m=e.ref(0),p=e.ref(!1),g=e.reactive({x:0,y:0,ox:0,oy:0}),x=e.ref(!1),s=e.reactive({x:0,y:0}),w=e.reactive({x:0,y:0,width:0,height:0}),v=e.ref(0);let E=null;function I(M){E=M}function K(M){M.preventDefault();const R=o.getContainer();if(!R)return;const L=-M.deltaY*.001,H=Math.min(l,Math.max(u,c.value*(1+L))),q=R.getBoundingClientRect(),X=M.clientX-q.left,re=M.clientY-q.top,ke=(X-d.value)/c.value,Q=(re-m.value)/c.value;c.value=H,d.value=X-ke*H,m.value=re-Q*H}function j(){c.value=Math.min(l,c.value*i)}function Ve(){c.value=Math.max(u,c.value/i)}function G(M){var L;M.target.closest(".zm-node, .zm-toolbar, button, input, textarea")||(p.value=!0,g.x=M.clientX,g.y=M.clientY,g.ox=d.value,g.oy=m.value,window.addEventListener("mousemove",he),window.addEventListener("mouseup",ze),(L=M.preventDefault)==null||L.call(M))}function he(M){p.value&&(d.value=g.ox+(M.clientX-g.x),m.value=g.oy+(M.clientY-g.y))}function ze(){p.value=!1,window.removeEventListener("mousemove",he),window.removeEventListener("mouseup",ze)}function ye(M,R){x.value=!0,s.x=M,s.y=R,w.x=M,w.y=R,w.width=0,w.height=0,v.value++,window.addEventListener("mousemove",pe),window.addEventListener("mouseup",xe)}function ge(M,R){if(!x.value)return;const L=Math.min(s.x,M),H=Math.min(s.y,R),q=Math.max(s.x,M),X=Math.max(s.y,R);w.x=L,w.y=H,w.width=q-L,w.height=X-H,v.value++}function xe(){x.value=!1,window.removeEventListener("mousemove",pe),window.removeEventListener("mouseup",xe),E&&E()}function pe(M){if(!x.value)return;const R=o.getContainer();if(!R)return;const L=R.getBoundingClientRect(),H=(M.clientX-L.left-d.value)/c.value,q=(M.clientY-L.top-m.value)/c.value;ge(H,q)}function $(M,R,L,H=60){const q=o.getContainer();if(!q)return;const X=q.getBoundingClientRect(),re=(X.width-H*2)/M,ke=(X.height-H*2)/R,Q=Math.min(1,Math.max(.3,Math.min(re,ke)));c.value=Q,d.value=X.width/2,m.value=X.height/2-L*Q}return{scale:c,offsetX:d,offsetY:m,isPanning:p,onWheel:K,zoomIn:j,zoomOut:Ve,startPan:G,startMarquee:ye,updateMarquee:ge,isMarquee:x,marquee:w,marqueeVersion:v,setOnMarqueeEnd:I,resetView:$}}const an=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform);function ot(o){return an?o.metaKey:o.ctrlKey}function cn(o){function u(){const i=o.getSelectedId();return i||(o.defaultTargetId?o.defaultTargetId():o.getRootId())}function l(i){const c=i.target;if(c&&(c.tagName==="INPUT"||c.tagName==="TEXTAREA"||c.isContentEditable)||o.isReadonly()||o.isEditing())return;const d=o.getSelectedId(),m=u();if(m){if(ot(i)&&!i.shiftKey){if(i.key==="d"||i.key==="D"){d&&d!==o.getRootId()&&(i.preventDefault(),o.onDuplicate(d));return}if(i.key==="z"||i.key==="Z"){i.preventDefault(),o.onUndo();return}if(i.key==="y"||i.key==="Y"){i.preventDefault(),o.onRedo();return}if(i.key==="Home"){i.preventDefault(),o.onSelectRoot();return}}if(ot(i)&&i.shiftKey&&(i.key==="Z"||i.key==="z")){i.preventDefault(),o.onRedo();return}i.key==="Tab"?(i.preventDefault(),o.onAddChild(m)):i.key==="Enter"?(i.preventDefault(),i.shiftKey?d&&d!==o.getRootId()&&o.onAddSiblingBefore(d):o.onAddSibling(m)):(i.key==="Delete"||i.key==="Backspace")&&d&&d!==o.getRootId()?(i.preventDefault(),o.onRemove(d)):i.key==="F2"&&d?(i.preventDefault(),o.onStartEdit(d)):i.key==="Escape"?(i.preventDefault(),o.onClearSelection()):i.key==="ArrowDown"?(i.preventDefault(),o.onNavigate(0,1)):i.key==="ArrowUp"?(i.preventDefault(),o.onNavigate(0,-1)):i.key==="ArrowRight"?(i.preventDefault(),o.onNavigate(1,0)):i.key==="ArrowLeft"&&(i.preventDefault(),o.onNavigate(-1,0))}}e.onMounted(()=>{window.addEventListener("keydown",l)}),e.onBeforeUnmount(()=>{window.removeEventListener("keydown",l)})}function sn(o=100){const u=e.ref([]);let l=-1;function i(){return l>0}function c(){return l<u.value.length-1}function d(x){const s=JSON.stringify(x);for(l<u.value.length-1&&(u.value=u.value.slice(0,l+1)),u.value.push(s),l=u.value.length-1;u.value.length>o;)u.value.shift(),l--}function m(){return i()?(l--,JSON.parse(u.value[l])):null}function p(){return c()?(l++,JSON.parse(u.value[l])):null}function g(){u.value=[],l=-1}return{canUndo:i,canRedo:c,record:d,undo:m,redo:p,reset:g}}const dn=["disabled"],un=["disabled"],fn=["disabled"],mn=["disabled"],hn=["disabled"],yn=["disabled"],gn=e.defineComponent({__name:"NodeContextMenu",props:{x:{},y:{},container:{},hasImage:{type:Boolean,default:!1},hasLink:{type:Boolean,default:!1},hasNote:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1}},emits:["pickImage","setLink","removeLink","editNote","removeNote","removeImage","close"],setup(o,{emit:u}){const l=o,i=u,c=e.computed(()=>{let v=l.x+2,E=l.y+2;if(l.container){const I=l.container.getBoundingClientRect(),K=180,j=d.value?m.value?184:160:136;v+K>I.right&&(v=Math.max(I.left+4,l.x-K-2)),E+j>I.bottom&&(E=Math.max(I.top+4,l.y-j-2)),v<I.left+2&&(v=I.left+2),E<I.top+2&&(E=I.top+2)}return{left:v,top:E}}),d=e.computed(()=>l.hasImage),m=e.computed(()=>l.hasLink),p=e.computed(()=>l.hasNote);function g(v){const E=v.target;E&&E.closest(".zm-node-menu")||i("close")}function x(v){v.key==="Escape"&&i("close")}function s(){i("close")}window.addEventListener("mousedown",g,!0),window.addEventListener("keydown",x,!0),window.addEventListener("wheel",s,!0),window.addEventListener("scroll",s,!0),e.onBeforeUnmount(()=>{window.removeEventListener("mousedown",g,!0),window.removeEventListener("keydown",x,!0),window.removeEventListener("wheel",s,!0),window.removeEventListener("scroll",s,!0)});function w(v){l.readonly||(v(),i("close"))}return(v,E)=>(e.openBlock(),e.createElementBlock("div",{class:"zm-node-menu",style:e.normalizeStyle({left:c.value.left+"px",top:c.value.top+"px"}),onContextmenu:E[6]||(E[6]=e.withModifiers(()=>{},["prevent"]))},[e.createElementVNode("button",{class:"zm-node-menu-item",disabled:o.readonly,onClick:E[0]||(E[0]=e.withModifiers(I=>w(()=>i("pickImage")),["stop"]))},[e.createVNode(z,{name:"image",size:13}),e.createElementVNode("span",null,e.toDisplayString(d.value?"替换图片":"添加图片"),1)],8,dn),d.value?(e.openBlock(),e.createElementBlock("button",{key:0,class:"zm-node-menu-item",disabled:o.readonly,onClick:E[1]||(E[1]=e.withModifiers(I=>w(()=>i("removeImage")),["stop"]))},[e.createVNode(z,{name:"x",size:13}),E[7]||(E[7]=e.createElementVNode("span",null,"移除图片",-1))],8,un)):e.createCommentVNode("",!0),e.createElementVNode("button",{class:"zm-node-menu-item",disabled:o.readonly,onClick:E[2]||(E[2]=e.withModifiers(I=>w(()=>i("setLink")),["stop"]))},[e.createVNode(z,{name:"link",size:13}),e.createElementVNode("span",null,e.toDisplayString(m.value?"编辑链接":"添加链接"),1)],8,fn),m.value?(e.openBlock(),e.createElementBlock("button",{key:1,class:"zm-node-menu-item",disabled:o.readonly,onClick:E[3]||(E[3]=e.withModifiers(I=>w(()=>i("removeLink")),["stop"]))},[e.createVNode(z,{name:"x",size:13}),E[8]||(E[8]=e.createElementVNode("span",null,"移除链接",-1))],8,mn)):e.createCommentVNode("",!0),e.createElementVNode("button",{class:"zm-node-menu-item",disabled:o.readonly,onClick:E[4]||(E[4]=e.withModifiers(I=>w(()=>i("editNote")),["stop"]))},[e.createVNode(z,{name:"note",size:13}),e.createElementVNode("span",null,e.toDisplayString(p.value?"编辑笔记":"添加笔记"),1)],8,hn),p.value?(e.openBlock(),e.createElementBlock("button",{key:2,class:"zm-node-menu-item",disabled:o.readonly,onClick:E[5]||(E[5]=e.withModifiers(I=>w(()=>i("removeNote")),["stop"]))},[e.createVNode(z,{name:"x",size:13}),E[9]||(E[9]=e.createElementVNode("span",null,"移除笔记",-1))],8,yn)):e.createCommentVNode("",!0)],36))}}),xn=["viewBox","width","height"],pn={class:"zm-edges"},kn=["d","fill"],wn=["data-node-id","onClick","onDblclick","onContextmenu","onMouseenter","onMouseleave"],bn=["src","width","height","alt"],En={key:1,class:"zm-text"},Nn={class:"zm-text-label"},Mn=["href","title"],Bn=["title","onClick"],Cn=["title"],vn=["title","onClick"],Sn=["onClick"],Vn=["onMousedown"],zn=["onClick"],In={key:0,class:"zm-toolbar"},Wn=["src"],$n=["src"],Rn={class:"zm-tb-tip"},ie=24,me=400,Z=160,lt=e.defineComponent({__name:"MindMap",props:{data:{},readonly:{type:Boolean,default:!1},theme:{},previewMode:{type:Boolean,default:!1}},emits:["change","select","edit-note"],setup(o,{expose:u,emit:l}){const i=o,c=l,d=e.ref(null),m=e.ref(null),p=e.ref(""),g=e.ref(null),x=e.ref(new Set),s=e.ref(J(i.data)),w=e.computed(()=>k.showOrderBadge===!0),v=e.ref(new Map),E=v.value;function I(t,n){const a={};n.bg&&(a.bg=n.bg),n.textColor&&(a.textColor=n.textColor),n.borderColor&&(a.borderColor=n.borderColor),n.fontWeight&&(a.fontWeight=n.fontWeight),Object.keys(a).length===0?E.delete(t):E.set(t,a),v.value=new Map(E)}function K(t){return E.get(t)??{}}function j(t,n){const a=B(s.value,t);a&&(a.image={src:n.src,naturalW:n.naturalW,naturalH:n.naturalH,width:G(n.width,ie,me),height:G(n.height,ie,me)},P(),V(),c("change",s.value))}function Ve(t){const n=B(s.value,t);!n||!n.image||(delete n.image,P(),V(),c("change",s.value))}function G(t,n,a){return Math.min(a,Math.max(n,t))}function he(t,n){const a=new FileReader;a.onload=()=>{if(typeof a.result!="string")return;const f=a.result,h=new window.Image;h.onload=()=>{const r=h.naturalWidth||Z,y=h.naturalHeight||Z,C=G(r,ie,Z),W=G(Math.round(y*C/r),ie,me);n({src:f,naturalW:r,naturalH:y,width:C,height:W})},h.onerror=()=>{n({src:f,naturalW:Z,naturalH:Z,width:Z,height:Z})},h.src=f},a.readAsDataURL(t)}function ze(t){const n=document.createElement("input");n.type="file",n.accept="image/*",n.style.display="none",n.onchange=()=>{var f;const a=(f=n.files)==null?void 0:f[0];a&&(he(a,h=>j(t,h)),document.body.removeChild(n))},document.body.appendChild(n),n.click()}function ye(t,n){const a=n.trim(),f=B(s.value,t);f&&(a?f.link={url:a}:delete f.link,P(),V(),c("change",s.value))}function ge(t){ye(t,"")}function xe(t,n){const a=B(s.value,t);a&&(n?a.note={text:n}:delete a.note,P(),V(),c("change",s.value))}function pe(t){xe(t,"")}const $=e.ref(null);function M(t,n){i.readonly||(t.preventDefault(),t.stopPropagation(),g.value=n.id,c("select",B(s.value,n.id)),$.value={nodeId:n.id,x:t.clientX,y:t.clientY})}function R(){$.value=null}function L(){var n;const t=(n=$.value)==null?void 0:n.nodeId;t&&ze(t)}function H(){var f,h,r;const t=(f=$.value)==null?void 0:f.nodeId;if(!t)return;const n=((r=(h=B(s.value,t))==null?void 0:h.link)==null?void 0:r.url)??"",a=window.prompt("输入链接 URL(留空取消)",n);a!==null&&ye(t,a)}function q(){var n;const t=(n=$.value)==null?void 0:n.nodeId;t&&ge(t)}function X(){var n;const t=(n=$.value)==null?void 0:n.nodeId;t&&Q(t)}function re(){var n;const t=(n=$.value)==null?void 0:n.nodeId;t&&pe(t)}function ke(){var n;const t=(n=$.value)==null?void 0:n.nodeId;t&&Ve(t)}function Q(t){i.readonly||c("edit-note",t)}function Ln(t,n=60){const a=t.replace(/\s+/g," ").trim();return a.length<=n?a||"点击编辑笔记":a.slice(0,n)+"…"}function it(t){var h;if(i.readonly||m.value)return;const n=t.target;if(n&&(n.tagName==="INPUT"||n.tagName==="TEXTAREA"||n.isContentEditable))return;const a=g.value;if(!a)return;const f=(h=t.clipboardData)==null?void 0:h.items;if(f)for(let r=0;r<f.length;r++){const y=f[r];if(y.kind==="file"&&y.type.startsWith("image/")){const C=y.getAsFile();if(!C)continue;t.preventDefault();const W=B(s.value,a);if(W!=null&&W.image&&!window.confirm("该节点已有图片,要用剪贴板里的图片替换吗?"))return;he(C,A=>j(a,A));return}}}e.onMounted(()=>{window.addEventListener("paste",it)}),e.onBeforeUnmount(()=>{window.removeEventListener("paste",it)});const we=e.ref(null),An=e.computed(()=>{var t;return((t=we.value)==null?void 0:t.nodeId)??null});function Hn(t,n){if(!n.image)return;t.preventDefault(),t.stopPropagation();const a=n.image.naturalW||n.image.width,f=n.image.naturalH||n.image.height,h=f>0?f/a:1;we.value={nodeId:n.id,startX:t.clientX,startY:t.clientY,startW:n.image.width,startH:n.image.height,naturalW:a,naturalH:f,ratio:h,pendingW:n.image.width,pendingH:n.image.height},window.addEventListener("mousemove",rt),window.addEventListener("mouseup",at)}function rt(t){var W,A;const n=we.value;if(!n)return;const a=b.scale.value||1,f=t.clientX-n.startX,h=G(n.startW+f/a,ie,me),r=G(h*n.ratio,ie,me);n.pendingW=h,n.pendingH=r;const y=(W=d.value)==null?void 0:W.querySelector(`[data-node-id="${n.nodeId}"] .zm-node-img`);y&&(y.style.width=`${h}px`,y.style.height=`${r}px`);const C=(A=d.value)==null?void 0:A.querySelector(`[data-node-id="${n.nodeId}"]`);C&&(C.style.minWidth=`${Math.max(80,Math.ceil(h+28))}px`,C.style.height=`${Math.ceil(r+8+30)}px`)}function at(){const t=we.value;if(window.removeEventListener("mousemove",rt),window.removeEventListener("mouseup",at),we.value=null,!t)return;const n=B(s.value,t.nodeId);!n||!n.image||(j(t.nodeId,{src:n.image.src,naturalW:n.image.naturalW,naturalH:n.image.naturalH,width:t.pendingW,height:t.pendingH}),g.value=t.nodeId,c("select",n),Te=!0)}const Pe=e.ref(null);let Te=!1;function Pn(t){Pe.value=t}function Tn(t){Pe.value===t&&(Pe.value=null)}const ct=e.ref(0),Fe=e.ref(!1),_=sn(100);function P(){_.record({data:s.value})}function V(){x.value=new Set(x.value),ct.value++}const U=e.computed(()=>{var t,n,a,f,h,r,y,C,W,A;return{rootBg:((t=i.theme)==null?void 0:t.rootBg)??"#1f2937",rootText:((n=i.theme)==null?void 0:n.rootText)??"#ffffff",branchBg:((a=i.theme)==null?void 0:a.branchBg)??"#ffffff",branchText:((f=i.theme)==null?void 0:f.branchText)??"#1f2937",lineColor:((h=i.theme)==null?void 0:h.lineColor)??"#94a3b8",bgColor:((r=i.theme)==null?void 0:r.bgColor)??"#f8fafc",fontSize:((y=i.theme)==null?void 0:y.fontSize)??14,lineWidthStart:((C=i.theme)==null?void 0:C.lineWidthStart)??2.2,lineWidthEnd:((W=i.theme)==null?void 0:W.lineWidthEnd)??.8,rainbowBranch:((A=i.theme)==null?void 0:A.rainbowBranch)??!1}}),k=e.reactive({autoBalanceOnChange:!0,lineWidthStart:12,lineWidthEnd:3.6,rainbowBranch:!0,branchPaletteId:"default",customPalettes:[],lineStyle:"curve",layoutMode:"mindmap",taperedEdge:!0,showOrderBadge:!1});function st(t){return k.taperedEdge?Fn(t):ut(t)}function dt(t){return k.taperedEdge?k.lineWidthEnd:ut(t)}function Fn(t){return t<=0?k.lineWidthStart:t===1?Math.max(1.5,k.lineWidthStart*.67):t===2?Math.max(.8,k.lineWidthStart*.42):k.lineWidthEnd}function ut(t){if(t<=0)return k.lineWidthStart;if(t>=3)return k.lineWidthEnd;const n=t/3;return k.lineWidthStart+(k.lineWidthEnd-k.lineWidthStart)*n}function On(t,n,a,f){const h=1-t,r=h*h*h*n.x+3*h*h*t*a.x1+3*h*t*t*a.x2+t*t*t*f.x,y=h*h*h*n.y+3*h*h*t*a.y1+3*h*t*t*a.y2+t*t*t*f.y;return{x:r,y}}function qn(t,n,a,f,h=32,r="curve",y="right"){if(r==="curve"){let oe;if(y==="right"||y==="left"){const S=Math.abs(n.x-t.x)*.45,Y=y==="right"?1:-1;oe={x1:t.x+Y*S,y1:t.y,x2:n.x-Y*S,y2:n.y}}else{const S=Math.abs(n.y-t.y)*.45;oe={x1:t.x,y1:t.y+S,x2:n.x,y2:n.y-S}}const mo=N=>{const S=1-N,Y=-3*S*S*t.x+3*(S*S-2*S*N)*oe.x1+3*(2*S*N-N*N)*oe.x2+3*N*N*n.x,de=-3*S*S*t.y+3*(S*S-2*S*N)*oe.y1+3*(2*S*N-N*N)*oe.y2+3*N*N*n.y;return{dx:Y,dy:de}},Ne=[],Ye=[];for(let N=0;N<=h;N++){const S=N/h,Y=N===0?t:N===h?n:On(S,t,oe,n),de=mo(S);let De=Math.hypot(de.dx,de.dy);De<1e-6&&(De=1);const Vt=-de.dy/De,zt=de.dx/De,Le=(a+(f-a)*S)/2;Ne.push({x:Y.x+Vt*Le,y:Y.y+zt*Le}),Ye.push({x:Y.x-Vt*Le,y:Y.y-zt*Le})}let Re=`M ${Ne[0].x.toFixed(2)} ${Ne[0].y.toFixed(2)}`;for(let N=1;N<=h;N++)Re+=` L ${Ne[N].x.toFixed(2)} ${Ne[N].y.toFixed(2)}`;for(let N=h;N>=0;N--)Re+=` L ${Ye[N].x.toFixed(2)} ${Ye[N].y.toFixed(2)}`;return Re+=" Z",Re}const C=n.x-t.x,W=n.y-t.y;let A=Math.hypot(C,W);A<1e-6&&(A=1);const ne=-W/A,ce=C/A,se=a/2,Ee=f/2,Bt={x:t.x+ne*se,y:t.y+ce*se},Ct={x:t.x-ne*se,y:t.y-ce*se},vt={x:n.x-ne*Ee,y:n.y-ce*Ee},St={x:n.x+ne*Ee,y:n.y+ce*Ee};return`M ${Bt.x.toFixed(2)} ${Bt.y.toFixed(2)} L ${St.x.toFixed(2)} ${St.y.toFixed(2)} L ${vt.x.toFixed(2)} ${vt.y.toFixed(2)} L ${Ct.x.toFixed(2)} ${Ct.y.toFixed(2)} Z`}const Ie=e.computed(()=>T.value.root.children),Xn=ue[0].colors,ft=e.computed(()=>en(k.branchPaletteId,k.customPalettes)),ee=e.computed(()=>{const t=new Map;if(!k.rainbowBranch)return t;const n=ft.value.colors.length>0?ft.value.colors:Xn;for(let f=0;f<Ie.value.length;f++){const h=Ie.value[f];t.set(h.id,n[f%n.length])}const a=(f,h)=>{t.set(f.id,h);for(const r of f.children)a(r,h)};for(let f=0;f<Ie.value.length;f++){const h=Ie.value[f];a(h,n[f%n.length])}return t});function Kn(t,n){return k.rainbowBranch?ee.value.get(n.id)??U.value.lineColor:U.value.lineColor}function Un(t){const n=K(t.id);if(n.bg)return n.bg;if(t.isRoot)return U.value.rootBg;if(k.rainbowBranch){const a=ee.value.get(t.id);if(a)return Jn(a,.18)}return U.value.branchBg}function Yn(t){const n=K(t.id);if(n.textColor)return n.textColor;if(t.isRoot)return U.value.rootText;if(k.rainbowBranch){const a=ee.value.get(t.id);if(a)return mt(a,.55)}return U.value.branchText}function jn(t){const n=K(t.id);if(n.borderColor)return n.borderColor;if(t.isRoot)return U.value.rootBg;if(k.rainbowBranch){const a=ee.value.get(t.id);if(a)return mt(a,.3)}return U.value.lineColor}function Gn(t){return K(t.id).fontWeight??(t.isRoot?600:400)}function Jn(t,n){const a=t.replace("#",""),f=a.length===6?a:a.split("").map(C=>C+C).join(""),h=parseInt(f.slice(0,2),16),r=parseInt(f.slice(2,4),16),y=parseInt(f.slice(4,6),16);return`rgba(${h}, ${r}, ${y}, ${n})`}function mt(t,n){const a=t.replace("#",""),f=a.length===6?a:a.split("").map(C=>C+C).join(""),h=Math.round(parseInt(f.slice(0,2),16)*(1-n)),r=Math.round(parseInt(f.slice(2,4),16)*(1-n)),y=Math.round(parseInt(f.slice(4,6),16)*(1-n));return`rgb(${h}, ${r}, ${y})`}const b=rn({getContainer:()=>d.value});b.setOnMarqueeEnd(ao),cn({isEditing:()=>m.value!==null,isReadonly:()=>i.readonly,getSelectedId:()=>g.value,getRootId:()=>s.value.id,defaultTargetId:()=>s.value.id,onAddChild:ae,onAddSibling:$e,onAddSiblingBefore:gt,onRemove:pt,onStartEdit:be,onClearSelection:()=>{g.value=null,c("select",null)},onDuplicate:xt,onUndo:qe,onRedo:Xe,onNavigate:to,onSelectRoot:()=>{g.value=s.value.id;const t=B(s.value,s.value.id);t&&c("select",t)}});const T=e.computed(()=>{const t=J(s.value);return yt(t),Jt(t,{mode:k.layoutMode})}),ht=e.ref([]),Oe=e.computed(()=>(ct.value,ht.value));e.watch(T,t=>{const n=[],a=f=>{n.push(f);for(const h of f.children)a(h)};a(t.root),ht.value=n},{immediate:!0});const Zn=e.computed(()=>{const t=[];for(const n of Oe.value)for(const a of n.children)t.push({from:n,to:a,key:`${n.id}->${a.id}`});return t}),Qn=e.computed(()=>`${T.value.vbX} ${T.value.vbY} ${T.value.vbW} ${T.value.vbH}`);function yt(t){if(x.value.has(t.id)){t.children=[],t.collapsed=!0;return}t.collapsed=!1;for(const n of t.children)yt(n)}function be(t){const n=B(s.value,t);n&&(m.value=t,p.value=n.text,e.nextTick(()=>{const a=document.querySelector(".zm-input");a==null||a.focus(),a==null||a.select()}))}function We(t={}){if(!m.value)return;const n=B(s.value,m.value);n&&n.text!==(p.value.trim()||" ")&&(n.text=p.value.trim()||" ",P(),c("change",s.value));const a=m.value;m.value=null,t.addChild?e.nextTick(()=>ae(a)):t.addSibling==="after"?e.nextTick(()=>$e(a)):t.addSibling==="before"&&e.nextTick(()=>gt(a))}function _n(){m.value=null}function eo(t){const n=t.metaKey||t.ctrlKey;n&&(t.key==="z"||t.key==="Z")&&!t.shiftKey?(t.preventDefault(),qe()):(n&&t.shiftKey&&(t.key==="z"||t.key==="Z")||n&&(t.key==="y"||t.key==="Y")&&!t.shiftKey)&&(t.preventDefault(),Xe())}function ae(t){const n=et(s.value,t,Se);n&&(P(),V(),c("change",s.value),e.nextTick(()=>be(n.id)))}function $e(t){if(t===s.value.id){ae(t);return}const n=tt(s.value,t,Se);n&&(P(),V(),c("change",s.value),e.nextTick(()=>be(n.id)))}function gt(t){if(t===s.value.id){ae(t);return}const n=on(s.value,t,Se);n&&(P(),V(),c("change",s.value),e.nextTick(()=>be(n.id)))}function xt(t){if(t===s.value.id)return;const n=ln(s.value,t);n&&(P(),g.value=n.id,c("change",s.value),V())}function qe(){const t=_.undo();t&&(s.value=t.data,g.value=null,c("select",null),V(),c("change",s.value))}function Xe(){const t=_.redo();t&&(s.value=t.data,g.value=null,c("select",null),V(),c("change",s.value))}function to(t,n){const a=g.value??s.value.id,f=B(s.value,a);if(!f)return;let h=null;if(n===1){const r=O(s.value,f.id);if(r){const y=r.children.findIndex(C=>C.id===f.id);y>=0&&y<r.children.length-1&&(h=r.children[y+1].id)}}else if(n===-1){const r=O(s.value,f.id);if(r){const y=r.children.findIndex(C=>C.id===f.id);y>0&&(h=r.children[y-1].id)}}else if(t===1){const r=O(s.value,f.id);r&&(h=r.id)}else t===-1&&f.children.length>0&&(h=f.children[0].id);if(h){g.value=h;const r=B(s.value,h);r&&c("select",r)}}function pt(t){t!==s.value.id&&He(s.value,t)&&(P(),g.value===t&&(g.value=null),V(),c("change",s.value))}function kt(t){x.value.has(t)?x.value.delete(t):x.value.add(t),V()}function no(t,n){tn(s.value,t,n)&&(P(),V(),c("change",s.value))}function oo(t,n,a){return nn(s.value,t,n,a)?(P(),V(),c("change",s.value),!0):!1}function lo(t,n){t.stopPropagation(),g.value=n.id;const a=B(s.value,n.id);c("select",a)}function io(t){const n=t.target;if(!n||n.closest(".zm-node, .zm-toolbar, button, input, textarea"))return;if(t.button===2){b.startPan(t);return}if(t.button!==0)return;const a=d.value.getBoundingClientRect(),f=(t.clientX-a.left-b.offsetX.value)/b.scale.value,h=(t.clientY-a.top-b.offsetY.value)/b.scale.value;b.startMarquee(f,h)}function ro(t){if(Te){Te=!1;return}const n=t.target;if(!n||n.closest(".zm-node"))return;const a=b.marquee;a.width>=4||a.height>=4||g.value!==null&&(g.value=null,c("select",null))}function ao(){const t=b.marquee;if(t.width<4&&t.height<4)return;const n=t.x,a=t.y,f=t.x+t.width,h=t.y+t.height,r=[];for(const y of Oe.value){const C=y.width/2,W=y.height/2,A=y.x-C,ne=y.x+C,ce=y.y-W,se=y.y+W;A<=f&&ne>=n&&ce<=h&&se>=a&&r.push(y.id)}if(r.length>0){g.value=r[0];const y=B(s.value,r[0]);y&&c("select",y)}}function wt(t){return x.value.has(t)}function co(t){const n=B(s.value,t.id);return!!n&&n.children.length>0}function Ke(t){const n=B(s.value,t);return n?n.children.length:0}function bt(t){if(!B(s.value,t))return 0;const f=[s.value];for(;f.length;){const h=f.pop(),r=h.children.findIndex(y=>y.id===t);if(r>=0)return r;for(const y of h.children)f.push(y)}return 0}function Et(t,n,a,f){if(((f==null?void 0:f._dir)??t._dir)==="down")return n==="out"?{x:t.x,y:t.y+t.height/2}:{x:t.x,y:t.y-t.height/2};let r;return n==="in"?r=-t.side:a!==void 0?r=a:r=t.side,{x:t.x+r*(t.width/2),y:t.y}}function te(){const t=T.value;b.resetView(t.width,t.height,t.root.y)}function so(){Fe.value=!0,P(),V(),e.nextTick(()=>te())}function Ue(t){k.layoutMode!==t&&(k.layoutMode=t,V(),e.nextTick(()=>te()))}function Nt(){return JSON.stringify(s.value,null,2)}function Mt(t){try{const n=JSON.parse(t);return!n.id||!Array.isArray(n.children)?!1:(_.reset(),s.value=J(n),g.value=null,x.value=new Set,V(),e.nextTick(()=>te()),c("change",s.value),!0)}catch{return!1}}function uo(){const t=document.createElement("input");t.type="file",t.accept="application/json",t.onchange=()=>{var f;const n=(f=t.files)==null?void 0:f[0];if(!n)return;const a=new FileReader;a.onload=()=>{typeof a.result=="string"&&(Mt(a.result)||alert("导入失败:JSON 格式无效"))},a.readAsText(n)},t.click()}function fo(){const t=new Blob([Nt()],{type:"application/json"}),n=URL.createObjectURL(t),a=document.createElement("a");a.href=n,a.download=`${s.value.text||"mindmap"}.json`,a.click(),URL.revokeObjectURL(n)}return u({addChild:t=>ae(t),addSibling:t=>$e(t),removeNode:t=>pt(t),duplicateNode:t=>xt(t),setNodeText:(t,n)=>no(t,n),moveNode:(t,n,a)=>oo(t,n,a),lineWidthForDepth:st,endWidthForDepth:dt,getData:()=>s.value,setData:t=>{_.reset(),s.value=J(t),g.value=null,x.value=new Set,V(),e.nextTick(()=>te())},resetView:()=>te(),exportData:Nt,importData:Mt,setBalanced:t=>{Fe.value=t},isBalanced:()=>Fe.value,balance:()=>so(),applyNodeStyle:(t,n)=>I(t,n),getNodeStyle:t=>K(t),applyNodeLink:(t,n)=>ye(t,n),removeNodeLink:t=>ge(t),applyNodeNote:(t,n)=>xe(t,n),removeNodeNote:t=>pe(t),undo:()=>qe(),redo:()=>Xe(),canUndo:()=>_.canUndo(),canRedo:()=>_.canRedo(),applySettings:t=>{t.autoBalanceOnChange!==void 0&&(k.autoBalanceOnChange=t.autoBalanceOnChange),t.lineWidthStart!==void 0&&(k.lineWidthStart=Math.max(.5,Math.min(20,t.lineWidthStart))),t.lineWidthEnd!==void 0&&(k.lineWidthEnd=Math.max(.3,Math.min(10,t.lineWidthEnd))),t.rainbowBranch!==void 0&&(k.rainbowBranch=t.rainbowBranch),t.branchPaletteId!==void 0&&(k.branchPaletteId=t.branchPaletteId),t.customPalettes!==void 0&&(k.customPalettes=t.customPalettes),t.lineStyle!==void 0&&(k.lineStyle=t.lineStyle),t.taperedEdge!==void 0&&(k.taperedEdge=t.taperedEdge),t.showOrderBadge!==void 0&&(k.showOrderBadge=t.showOrderBadge)},getSettings:()=>({autoBalanceOnChange:k.autoBalanceOnChange,lineWidthStart:k.lineWidthStart,lineWidthEnd:k.lineWidthEnd,rainbowBranch:k.rainbowBranch,branchPaletteId:k.branchPaletteId,customPalettes:k.customPalettes,lineStyle:k.lineStyle,layoutMode:k.layoutMode,taperedEdge:k.taperedEdge,showOrderBadge:k.showOrderBadge}),setBranchPalette:t=>{if(!t)return;[...ue,...k.customPalettes].find(a=>a.id===t)&&(k.branchPaletteId=t)},getBranchPalette:()=>k.branchPaletteId,getBranchPalettes:()=>[...ue,...k.customPalettes]}),e.watch(()=>i.data,t=>{s.value=J(t),V()},{deep:!1}),e.onMounted(()=>{e.nextTick(()=>te())}),(t,n)=>{var a,f,h;return e.openBlock(),e.createElementBlock("div",{class:"zm-mindmap",style:e.normalizeStyle({background:U.value.bgColor,fontSize:U.value.fontSize+"px"})},[e.createElementVNode("div",{ref_key:"wrapperRef",ref:d,class:"zm-canvas",onMousedown:io,onContextmenu:n[13]||(n[13]=e.withModifiers(()=>{},["prevent"])),onWheel:n[14]||(n[14]=(...r)=>e.unref(b).onWheel&&e.unref(b).onWheel(...r)),onClick:ro},[e.createElementVNode("div",{class:"zm-svg-layer",style:e.normalizeStyle({left:T.value.vbX*e.unref(b).scale.value+e.unref(b).offsetX.value+"px",top:T.value.vbY*e.unref(b).scale.value+e.unref(b).offsetY.value+"px",width:T.value.vbW*e.unref(b).scale.value+"px",height:T.value.vbH*e.unref(b).scale.value+"px"})},[(e.openBlock(),e.createElementBlock("svg",{class:"zm-svg",viewBox:Qn.value,preserveAspectRatio:"xMinYMin meet",width:T.value.vbW*e.unref(b).scale.value,height:T.value.vbH*e.unref(b).scale.value},[e.createElementVNode("g",pn,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(Zn.value,r=>(e.openBlock(),e.createElementBlock("path",{key:r.key,d:qn(Et(r.from,"out",r.to.side,r.to),Et(r.to,"in"),st(r.from.depth),dt(r.to.depth),32,k.lineStyle,r.to._dir),fill:Kn(r.from,r.to),stroke:"none"},null,8,kn))),128))])],8,xn))],4),e.unref(b).isMarquee.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"zm-marquee",style:e.normalizeStyle({left:e.unref(b).marquee.x*e.unref(b).scale.value+e.unref(b).offsetX.value+"px",top:e.unref(b).marquee.y*e.unref(b).scale.value+e.unref(b).offsetY.value+"px",width:e.unref(b).marquee.width*e.unref(b).scale.value+"px",height:e.unref(b).marquee.height*e.unref(b).scale.value+"px"})},null,4)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"zm-world",style:e.normalizeStyle({transform:`translate(${e.unref(b).offsetX.value}px, ${e.unref(b).offsetY.value}px) scale(${e.unref(b).scale.value})`})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(Oe.value,r=>(e.openBlock(),e.createElementBlock("div",{key:r.id,class:e.normalizeClass(["zm-node",{"is-root":r.isRoot,"is-selected":g.value===r.id,"is-editing":m.value===r.id,"has-image":!!r.image,"is-resizing":An.value===r.id}]),"data-node-id":r.id,style:e.normalizeStyle({left:r.x+"px",top:r.y+"px",minWidth:r.width+"px",height:r.height+"px",fontSize:r.fontSize+"px",background:Un(r),color:Yn(r),borderColor:jn(r),fontWeight:Gn(r),transform:"translate(-50%, -50%)"}),onClick:y=>lo(y,r),onDblclick:y=>{y.stopPropagation(),o.readonly||be(r.id)},onContextmenu:y=>M(y,r),onMouseenter:y=>Pn(r.id),onMouseleave:y=>Tn(r.id)},[r.image?(e.openBlock(),e.createElementBlock("img",{key:0,class:"zm-node-img",src:r.image.src,width:r.image.width,height:r.image.height,alt:r.text,draggable:"false"},null,8,bn)):e.createCommentVNode("",!0),m.value!==r.id?(e.openBlock(),e.createElementBlock("span",En,[e.createElementVNode("span",Nn,e.toDisplayString(r.text),1),r.link&&!m.value?(e.openBlock(),e.createElementBlock("a",{key:0,class:"zm-node-link",href:r.link.url,target:"_blank",rel:"noopener noreferrer",title:`打开链接:${r.link.url}`,onClick:n[0]||(n[0]=e.withModifiers(()=>{},["stop"])),onMousedown:n[1]||(n[1]=e.withModifiers(()=>{},["stop"]))},[e.createVNode(z,{name:"link",size:11,stroke:2})],40,Mn)):e.createCommentVNode("",!0),r.note&&!m.value?(e.openBlock(),e.createElementBlock("button",{key:1,class:"zm-node-note-btn",type:"button",title:Ln(r.note.text),onClick:e.withModifiers(y=>Q(r.id),["stop"]),onMousedown:n[2]||(n[2]=e.withModifiers(()=>{},["stop"]))},[e.createVNode(z,{name:"note",size:11,stroke:2})],40,Bn)):e.createCommentVNode("",!0)])):e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:2,class:"zm-input","onUpdate:modelValue":n[3]||(n[3]=y=>p.value=y),autofocus:"",onBlur:n[4]||(n[4]=y=>We()),onKeydown:[n[5]||(n[5]=e.withKeys(e.withModifiers(y=>We({addSibling:"after"}),["exact"]),["enter"])),n[6]||(n[6]=e.withKeys(e.withModifiers(y=>We({addSibling:"before"}),["shift","prevent","exact"]),["enter"])),n[7]||(n[7]=e.withKeys(e.withModifiers(y=>We({addChild:!0}),["prevent"]),["tab"])),e.withKeys(_n,["esc"]),eo],onMousedown:n[8]||(n[8]=e.withModifiers(()=>{},["stop"])),onClick:n[9]||(n[9]=e.withModifiers(()=>{},["stop"]))},null,544)),[[e.vModelText,p.value]]),w.value?(e.openBlock(),e.createElementBlock("span",{key:3,class:"zm-order-badge",title:`数据顺序:第 ${bt(r.id)+1} 个`},e.toDisplayString(bt(r.id)+1),9,Cn)):e.createCommentVNode("",!0),wt(r.id)&&!r.isRoot&&Ke(r.id)>0?(e.openBlock(),e.createElementBlock("span",{key:4,class:e.normalizeClass(["zm-collapse-badge",{"is-on-left":r.side===-1}]),style:e.normalizeStyle({background:ee.value.get(r.id)??"#64748b"}),title:`展开 ${Ke(r.id)} 个子节点`,onMousedown:n[10]||(n[10]=e.withModifiers(()=>{},["stop"])),onClick:e.withModifiers(y=>kt(r.id),["stop"])},e.toDisplayString(Ke(r.id)),47,vn)):e.createCommentVNode("",!0),!o.readonly&&!r.isRoot&&co(r)&&!wt(r.id)?(e.openBlock(),e.createElementBlock("button",{key:5,class:e.normalizeClass(["zm-btn zm-collapse",{"is-on-left":r.side===-1}]),style:e.normalizeStyle({color:ee.value.get(r.id)??"#64748b",borderColor:ee.value.get(r.id)??"#64748b"}),title:"折叠",onMousedown:n[11]||(n[11]=e.withModifiers(()=>{},["stop"])),onClick:e.withModifiers(y=>kt(r.id),["stop"])},[e.createVNode(z,{name:"minus",size:10,stroke:2.4})],46,Sn)):e.createCommentVNode("",!0),r.image&&g.value===r.id&&m.value!==r.id?(e.openBlock(),e.createElementBlock("span",{key:6,class:"zm-img-resize-handle",title:"拖动调整图片大小",onMousedown:e.withModifiers(y=>Hn(y,r),["stop"])},null,40,Vn)):e.createCommentVNode("",!0),r.image&&g.value===r.id&&m.value!==r.id?(e.openBlock(),e.createElementBlock("button",{key:7,class:"zm-img-remove-btn",title:"移除图片",onMousedown:n[12]||(n[12]=e.withModifiers(()=>{},["stop"])),onClick:e.withModifiers(y=>Ve(r.id),["stop"])},[e.createVNode(z,{name:"x",size:9,stroke:2.2})],40,zn)):e.createCommentVNode("",!0)],46,wn))),128))],4),$.value?(e.openBlock(),e.createBlock(gn,{key:1,x:$.value.x,y:$.value.y,container:d.value,"has-image":!!((a=e.unref(B)(s.value,$.value.nodeId))!=null&&a.image),"has-link":!!((f=e.unref(B)(s.value,$.value.nodeId))!=null&&f.link),"has-note":!!((h=e.unref(B)(s.value,$.value.nodeId))!=null&&h.note),readonly:i.readonly,onPickImage:L,onRemoveImage:ke,onSetLink:H,onRemoveLink:q,onEditNote:X,onRemoveNote:re,onClose:R},null,8,["x","y","container","has-image","has-link","has-note","readonly"])):e.createCommentVNode("",!0)],544),i.previewMode?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",In,[e.createElementVNode("button",{class:"zm-tb-btn",title:"放大",onClick:n[15]||(n[15]=(...r)=>e.unref(b).zoomIn&&e.unref(b).zoomIn(...r))},[e.createVNode(z,{name:"zoom-in"})]),e.createElementVNode("button",{class:"zm-tb-btn",title:"缩小",onClick:n[16]||(n[16]=(...r)=>e.unref(b).zoomOut&&e.unref(b).zoomOut(...r))},[e.createVNode(z,{name:"zoom-out"})]),e.createElementVNode("button",{class:"zm-tb-btn",title:"重置视图",onClick:te},[e.createVNode(z,{name:"reset"})]),n[22]||(n[22]=e.createElementVNode("span",{class:"zm-tb-divider"},null,-1)),o.readonly?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("button",{key:0,class:"zm-tb-btn",title:"添加子节点 (Tab)",onClick:n[17]||(n[17]=r=>g.value&&ae(g.value))},[e.createElementVNode("img",{src:e.unref(Dt),width:"14",height:"14",alt:"添加子节点",draggable:"false"},null,8,Wn)])),o.readonly?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("button",{key:1,class:"zm-tb-btn",title:"添加同级 (Enter)",onClick:n[18]||(n[18]=r=>g.value&&$e(g.value))},[e.createElementVNode("img",{src:e.unref(Rt),width:"14",height:"14",alt:"添加同级",draggable:"false"},null,8,$n)])),n[23]||(n[23]=e.createElementVNode("span",{class:"zm-tb-divider"},null,-1)),e.createElementVNode("button",{class:e.normalizeClass(["zm-tb-btn",{active:k.layoutMode==="mindmap"}]),title:"思维导图布局 (中心辐射)",onClick:n[19]||(n[19]=r=>Ue("mindmap"))},[e.createVNode(z,{name:"mindmap"})],2),e.createElementVNode("button",{class:e.normalizeClass(["zm-tb-btn",{active:k.layoutMode==="tree"}]),title:"树形布局 (向右展开)",onClick:n[20]||(n[20]=r=>Ue("tree"))},[e.createVNode(z,{name:"tree"})],2),e.createElementVNode("button",{class:e.normalizeClass(["zm-tb-btn",{active:k.layoutMode==="org"}]),title:"组织结构布局 (向下展开)",onClick:n[21]||(n[21]=r=>Ue("org"))},[e.createVNode(z,{name:"org"})],2),n[24]||(n[24]=e.createElementVNode("span",{class:"zm-tb-divider"},null,-1)),o.readonly?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("button",{key:2,class:"zm-tb-btn",title:"导入 JSON",onClick:uo},[e.createVNode(z,{name:"import"})])),e.createElementVNode("button",{class:"zm-tb-btn",title:"导出 JSON",onClick:fo},[e.createVNode(z,{name:"export"})]),e.createElementVNode("span",Rn,e.toDisplayString(Math.round(e.unref(b).scale.value*100))+"%",1)]))],4)}}}),Dn={install(o){o.component("FlowMindMap",lt)}};D.MindMap=lt,D.addChild=et,D.addSibling=tt,D.clone=J,D.default=Dn,D.findNode=B,D.findParent=O,D.removeNode=He,D.uid=fe,Object.defineProperties(D,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function(L,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(L=typeof globalThis<"u"?globalThis:L||self,e(L.FlowMind={},L.Vue))})(this,function(L,e){"use strict";const Rt=["width","height","stroke-width"],Lt={key:4,points:"6 9 12 15 18 9"},At={key:5,points:"9 6 15 12 9 18"},R=e.defineComponent({__name:"Icon",props:{name:{},size:{},stroke:{}},setup(o){return(d,l)=>(e.openBlock(),e.createElementBlock("svg",{width:o.size??16,height:o.size??16,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":o.stroke??1.8,"stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true"},[o.name==="add"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[l[0]||(l[0]=e.createElementVNode("circle",{cx:"12",cy:"12",r:"9"},null,-1)),l[1]||(l[1]=e.createElementVNode("line",{x1:"12",y1:"8",x2:"12",y2:"16"},null,-1)),l[2]||(l[2]=e.createElementVNode("line",{x1:"8",y1:"12",x2:"16",y2:"12"},null,-1))],64)):o.name==="minus"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[l[3]||(l[3]=e.createElementVNode("circle",{cx:"12",cy:"12",r:"9"},null,-1)),l[4]||(l[4]=e.createElementVNode("line",{x1:"8",y1:"12",x2:"16",y2:"12"},null,-1))],64)):o.name==="delete"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[l[5]||(l[5]=e.createStaticVNode('<polyline points="4 7 20 7"></polyline><path d="M9 7 V5 a1 1 0 0 1 1 -1 h4 a1 1 0 0 1 1 1 V7"></path><path d="M6 7 l1 12 a1 1 0 0 0 1 1 h8 a1 1 0 0 0 1 -1 l1 -12"></path><line x1="10" y1="11" x2="10" y2="18"></line><line x1="14" y1="11" x2="14" y2="18"></line>',5))],64)):o.name==="edit"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:3},[l[6]||(l[6]=e.createElementVNode("path",{d:"M4 20 l4 -1 11 -11 -3 -3 -11 11 z"},null,-1)),l[7]||(l[7]=e.createElementVNode("line",{x1:"14",y1:"6",x2:"18",y2:"10"},null,-1))],64)):o.name==="collapse"?(e.openBlock(),e.createElementBlock("polyline",Lt)):o.name==="expand"?(e.openBlock(),e.createElementBlock("polyline",At)):o.name==="zoom-in"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:6},[l[8]||(l[8]=e.createElementVNode("circle",{cx:"11",cy:"11",r:"7"},null,-1)),l[9]||(l[9]=e.createElementVNode("line",{x1:"11",y1:"8",x2:"11",y2:"14"},null,-1)),l[10]||(l[10]=e.createElementVNode("line",{x1:"8",y1:"11",x2:"14",y2:"11"},null,-1)),l[11]||(l[11]=e.createElementVNode("line",{x1:"16",y1:"16",x2:"21",y2:"21"},null,-1))],64)):o.name==="zoom-out"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:7},[l[12]||(l[12]=e.createElementVNode("circle",{cx:"11",cy:"11",r:"7"},null,-1)),l[13]||(l[13]=e.createElementVNode("line",{x1:"8",y1:"11",x2:"14",y2:"11"},null,-1)),l[14]||(l[14]=e.createElementVNode("line",{x1:"16",y1:"16",x2:"21",y2:"21"},null,-1))],64)):o.name==="reset"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:8},[l[15]||(l[15]=e.createElementVNode("circle",{cx:"12",cy:"12",r:"9"},null,-1)),l[16]||(l[16]=e.createElementVNode("circle",{cx:"12",cy:"12",r:"4"},null,-1)),l[17]||(l[17]=e.createElementVNode("circle",{cx:"12",cy:"12",r:"0.8",fill:"currentColor"},null,-1))],64)):o.name==="logo"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:9},[l[18]||(l[18]=e.createStaticVNode('<circle cx="12" cy="12" r="2.2"></circle><circle cx="4" cy="5" r="1.6"></circle><circle cx="20" cy="5" r="1.6"></circle><circle cx="4" cy="19" r="1.6"></circle><circle cx="20" cy="19" r="1.6"></circle><line x1="10.5" y1="10.8" x2="5.2" y2="6.4"></line><line x1="13.5" y1="10.8" x2="18.8" y2="6.4"></line><line x1="10.5" y1="13.2" x2="5.2" y2="17.6"></line><line x1="13.5" y1="13.2" x2="18.8" y2="17.6"></line>',9))],64)):o.name==="import"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:10},[l[19]||(l[19]=e.createElementVNode("path",{d:"M12 4 V15"},null,-1)),l[20]||(l[20]=e.createElementVNode("polyline",{points:"7 10 12 15 17 10"},null,-1)),l[21]||(l[21]=e.createElementVNode("path",{d:"M4 19 H20"},null,-1))],64)):o.name==="export"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:11},[l[22]||(l[22]=e.createElementVNode("path",{d:"M12 15 V4"},null,-1)),l[23]||(l[23]=e.createElementVNode("polyline",{points:"7 9 12 4 17 9"},null,-1)),l[24]||(l[24]=e.createElementVNode("path",{d:"M4 19 H20"},null,-1))],64)):o.name==="balance"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:12},[l[25]||(l[25]=e.createStaticVNode('<line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="18" x2="21" y2="18"></line><polyline points="9 4 5 6 9 8"></polyline><polyline points="15 4 19 6 15 8"></polyline><polyline points="9 10 5 12 9 14"></polyline><polyline points="15 10 19 12 15 14"></polyline><polyline points="9 16 5 18 9 20"></polyline><polyline points="15 16 19 18 15 20"></polyline>',9))],64)):o.name==="mindmap"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:13},[l[26]||(l[26]=e.createStaticVNode('<circle cx="12" cy="12" r="2.2" fill="currentColor" stroke="none"></circle><line x1="13" y1="11" x2="19" y2="6"></line><line x1="13" y1="13" x2="19" y2="18"></line><line x1="11" y1="11" x2="5" y2="6"></line><line x1="11" y1="13" x2="5" y2="18"></line>',5))],64)):o.name==="tree"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:14},[l[27]||(l[27]=e.createStaticVNode('<circle cx="6" cy="12" r="2" fill="currentColor" stroke="none"></circle><circle cx="18" cy="6" r="2" fill="currentColor" stroke="none"></circle><circle cx="18" cy="12" r="2" fill="currentColor" stroke="none"></circle><circle cx="18" cy="18" r="2" fill="currentColor" stroke="none"></circle><line x1="8" y1="12" x2="16" y2="6"></line><line x1="8" y1="12" x2="16" y2="12"></line><line x1="8" y1="12" x2="16" y2="18"></line>',7))],64)):o.name==="org"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:15},[l[28]||(l[28]=e.createStaticVNode('<circle cx="12" cy="5" r="2" fill="currentColor" stroke="none"></circle><circle cx="6" cy="19" r="2" fill="currentColor" stroke="none"></circle><circle cx="12" cy="19" r="2" fill="currentColor" stroke="none"></circle><circle cx="18" cy="19" r="2" fill="currentColor" stroke="none"></circle><line x1="12" y1="7" x2="12" y2="13"></line><line x1="6" y1="13" x2="18" y2="13"></line><line x1="6" y1="13" x2="6" y2="17"></line><line x1="12" y1="13" x2="12" y2="17"></line><line x1="18" y1="13" x2="18" y2="17"></line>',9))],64)):o.name==="image"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:16},[l[29]||(l[29]=e.createElementVNode("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2"},null,-1)),l[30]||(l[30]=e.createElementVNode("circle",{cx:"9",cy:"11",r:"1.6"},null,-1)),l[31]||(l[31]=e.createElementVNode("polyline",{points:"3 17 9 12 13 15 16 13 21 17"},null,-1))],64)):o.name==="x"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:17},[l[32]||(l[32]=e.createElementVNode("line",{x1:"6",y1:"6",x2:"18",y2:"18"},null,-1)),l[33]||(l[33]=e.createElementVNode("line",{x1:"18",y1:"6",x2:"6",y2:"18"},null,-1))],64)):o.name==="link"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:18},[l[34]||(l[34]=e.createElementVNode("path",{d:"M10 13 a4 4 0 0 0 5.66 0 l3 -3 a4 4 0 1 0 -5.66 -5.66 l-1 1"},null,-1)),l[35]||(l[35]=e.createElementVNode("path",{d:"M14 11 a4 4 0 0 0 -5.66 0 l-3 3 a4 4 0 1 0 5.66 5.66 l1 -1"},null,-1))],64)):o.name==="note"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:19},[l[36]||(l[36]=e.createElementVNode("path",{d:"M6 4 h9 l3 3 v13 a1 1 0 0 1 -1 1 h-11 a1 1 0 0 1 -1 -1 v-15 a1 1 0 0 1 1 -1 z"},null,-1)),l[37]||(l[37]=e.createElementVNode("line",{x1:"8",y1:"10",x2:"16",y2:"10"},null,-1)),l[38]||(l[38]=e.createElementVNode("line",{x1:"8",y1:"13",x2:"16",y2:"13"},null,-1)),l[39]||(l[39]=e.createElementVNode("line",{x1:"8",y1:"16",x2:"13",y2:"16"},null,-1))],64)):e.createCommentVNode("",!0)],8,Rt))}}),Tt="data:image/svg+xml,%3csvg%20t='1780822312364'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='7459'%20width='200'%20height='200'%3e%3cpath%20d='M329.16%20292.571h658.286V512H329.16zM329.16%200h658.286v219.429H329.16z'%20fill='%239AA1A2'%20p-id='7460'%3e%3c/path%3e%3cpath%20d='M44.927%20146.286a46.519%2046.519%200%200%201%2038.107-73.143h319.269v73.143H109.73V791.99l-48.713%205.705-24.43-651.41h8.339z'%20fill='%239AA1A2'%20p-id='7461'%3e%3c/path%3e%3cpath%20d='M363.83%20877.714H179.51c-78.775%200-142.921-66.12-142.921-147.31V112.787c0-21.943%2017.188-39.643%2038.473-39.643%2021.211%200%2033.5%2017.774%2033.5%2039.643v617.619c0%2037.522%2028.013%2076.58%2064.438%2076.58h190.903c21.211%200%2038.766%2013.97%2038.766%2035.84%200%2021.943-17.555%2034.89-38.766%2034.89z'%20fill='%239AA1A2'%20p-id='7462'%3e%3c/path%3e%3cpath%20d='M432.95%20438.857H179.51c-78.775%200-81.043-18.578-81.043-62.903l10.094-90.624c0%2020.48%2013.458%2080.677%2049.884%2080.677h210.139c21.211%200%20120.613%204.023%20120.613%2016.018%200%2011.922-35.036%2056.832-56.32%2056.832zM640.017%20749.714V640a54.857%2054.857%200%200%201%20109.714%200v109.714h109.715a54.857%2054.857%200%200%201%200%20109.715H749.73v109.714a54.857%2054.857%200%200%201-109.714%200V859.429H530.303a54.857%2054.857%200%200%201%200-109.715h109.714z'%20fill='%239AA1A2'%20p-id='7463'%3e%3c/path%3e%3c/svg%3e",Dt="data:image/svg+xml,%3csvg%20t='1780822464335'%20class='icon'%20viewBox='0%200%201024%201024'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20p-id='8457'%20width='200'%20height='200'%3e%3cpath%20d='M512%20804.571h512V1024H512V804.571zM0%200h658.286v219.429H0V0z'%20fill='%239AA1A2'%20p-id='8458'%3e%3c/path%3e%3cpath%20d='M619.813%20950.857h-184.32c-78.775%200-142.922-66.121-142.922-147.31V185.93c0-21.943%2017.189-39.643%2038.474-39.643%2021.211%200%2033.353%2017.773%2033.353%2039.643v617.618c0%2037.523%2034.743%2073.728%2071.095%2073.728h184.32c21.211%200%2038.473%2012.069%2038.473%2033.939%200%2021.943-17.189%2039.643-38.473%2039.643z'%20fill='%239AA1A2'%20p-id='8459'%3e%3c/path%3e%3cpath%20d='M676.571%20457.143V347.429a54.857%2054.857%200%200%201%20109.715%200v109.714H896a54.857%2054.857%200%200%201%200%20109.714H786.286v109.714a54.857%2054.857%200%200%201-109.715%200V566.857H566.857a54.857%2054.857%200%200%201%200-109.714h109.714z'%20fill='%239AA1A2'%20p-id='8460'%3e%3c/path%3e%3c/svg%3e",Je=[18,15,13,12],Ht=[700,600,500,400],Pt=[52,40,32,28],Ft=[120,80,60,44],Ot=[.8,.8,.8,.8],qt=Je.length-1;function Xt(o,d){return Math.round(Te(o,d)*Ot[ve(o)])}function ve(o){return Math.min(qt,Math.max(0,o))}function Te(o,d=14){return Math.round(Je[ve(o)]*d/14*10)/10}function Kt(o,d=14){return Math.round(Pt[ve(o)]*d/14)}const Ce=60,ue=14,U=24;let De=null;function Ut(){if(De)return De;const o=typeof document<"u"?document.createElement("canvas").getContext("2d"):null;return o?(De=o,o):{font:"",measureText:()=>({width:0})}}const Ze=new Map;function Yt(o,d,l){const i=`${l}|${d}|${o}`,c=Ze.get(i);if(c!==void 0)return c;const u=Ut();u.font=`${l} ${d}px "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif`;const f=u.measureText(o).width;return Ze.set(i,f),f}const jt=24,Gt=400,Jt=8,Qe=16,Zt=4;function Qt(o,d,l){return Math.min(l,Math.max(d,o))}function _t(o,d,l){const i=ve(d),c=Te(d,l),u=Yt(o.text||"",c,Ht[i]),f=Xt(d,l),p=Math.ceil(u+f*2),y=Kt(d,l);let g=0;if(o.link&&(g+=Qe),o.note&&(g+=Qe),g>0){const P=(o.link?1:0)+(o.note?1:0);g+=Zt*P}const s=p+g,k=Math.round(Ft[i]*l/14);if(!o.image)return{w:Math.max(k,s),h:y};const N=Qt(o.image.width,jt,Gt),w=Math.max(k,s,Math.ceil(N+f*2)),z=Math.ceil(o.image.height+Jt+y);return{w,h:z}}function en(o,d={}){const l=d.mode??"mindmap",i=d.preservePositions===!0,c=d.baseFontSize??14,u=et(o,0,null,1,"right",c);return nn(u),tn(u,l,i),u.x=0,u.y=0,on(u,i)}function tn(o,d,l=!1){if(d==="mindmap"){const i=o.children;if(i.length!==0)if(i.length===1)i[0]._dir="right",i[0].side=1,i[0]._dirRight=1;else{const p=i.reduce((k,N)=>k+N._subtreeH,0);let y=1,g=Math.abs(i[0]._subtreeH-(p-i[0]._subtreeH)),s=0;for(let k=0;k<i.length-1;k++){s+=i[k]._subtreeH;const N=Math.abs(s-(p-s));N<g&&(g=N,y=k+1)}for(let k=0;k<y;k++)i[k]._dir="right",i[k].side=1,i[k]._dirRight=1;for(let k=y;k<i.length;k++)i[k]._dir="left",i[k].side=-1,i[k]._dirRight=-1}const c=o.children.filter(p=>p.side===1),u=o.children.filter(p=>p.side===-1),f=(p,y)=>{const g=y==="right"?1:-1;p._dir=y,p.side=g,p._dirRight=g;for(const s of p.children)f(s,y)};for(const p of c)f(p,"right");for(const p of u)f(p,"left");if(c.length>0){const p={...o,children:c};Se(p,"right",Ce,!0,l)}if(u.length>0){const p={...o,children:u};Se(p,"left",Ce,!0,l)}}else if(d==="tree"){const i=c=>{c.side=1,c._dir="right";for(const u of c.children)i(u)};for(const c of o.children)c._dir="right";Se(o,"right",Ce,!0,l),i(o)}else{for(const i of o.children)i._dir="down";_e(o,Ce,l)}}function Se(o,d,l,i,c=!1){if(o.children.length===0)return;const u=o.children.reduce((g,s,k)=>g+s._subtreeH+(k>0?ue:0),0),f=d==="right"?1:-1,p=i?f:1;let y=o.y-p*u/2;o.children.forEach(g=>{c||(g.x=o.x+f*(o.width/2+l+g.width/2),g.y=y+p*g._subtreeH/2),g._dir=d,y+=p*(g._subtreeH+ue),Se(g,d,l,!1,c)})}function _e(o,d,l=!1){if(o.children.length===0)return;const i=o.children.reduce((u,f,p)=>u+f._subtreeW+(p>0?ue*2:0),0);let c=o.x-i/2;o.children.forEach(u=>{l||(u.x=c+u._subtreeW/2,u.y=o.y+o.height/2+d+u.height/2),u._dir="down",c+=u._subtreeW+ue*2,_e(u,d,l)})}function et(o,d,l,i,c,u){const f=_t(o,d,u),p={id:o.id,text:o.text,depth:d,x:o._x??0,y:o._y??0,width:f.w,height:f.h,fontSize:Te(d,u),isRoot:d===0,collapsed:o.collapsed,side:i,_dir:c,_dirRight:i,_subtreeH:f.h,_subtreeW:f.w,image:o.image?{...o.image}:void 0,link:o.link?{url:o.link.url}:void 0,note:o.note?{text:o.note.text}:void 0,children:[],parent:l};if(o.collapsed)return p;const y=o.children.length,g=Math.ceil(y/2);return p.children=o.children.map((s,k)=>{const N=d===0?k<g?1:-1:i;return et(s,d+1,p,N,c,u)}),p}function nn(o){const d=[o];for(let l=0;l<d.length;l++){const i=d[l];for(const c of i.children)d.push(c)}for(let l=d.length-1;l>=0;l--){const i=d[l];if(i.collapsed||i.children.length===0){i._subtreeH=i.height,i._subtreeW=i.width;continue}let c=0,u=0;for(const f of i.children)c+=f._subtreeH,u+=f._subtreeW;i.children.length>1&&(c+=ue*(i.children.length-1),u+=ue*2*(i.children.length-1)),i._subtreeH=Math.max(i.height,c),i._subtreeW=Math.max(i.width,u)}}function on(o,d=!1){const l=[o];let i=1/0,c=-1/0,u=1/0,f=-1/0;for(;l.length;){const g=l.pop(),s=g.width/2,k=g.height/2;g.x-s<i&&(i=g.x-s),g.x+s>c&&(c=g.x+s),g.y-k<u&&(u=g.y-k),g.y+k>f&&(f=g.y+k),l.push(...g.children)}if(d)return{root:o,width:c-i+U*2,height:f-u+U*2,vbX:i-U,vbY:u-U,vbW:c-i+U*2,vbH:f-u+U*2};const p=U-u,y=[o];for(;y.length;){const g=y.pop();g.y+=p,y.push(...g.children)}return u+=p,f+=p,{root:o,width:c-i+U*2,height:f+U,vbX:i-U,vbY:0,vbW:c-i+U*2,vbH:f+U}}const ke=[{id:"default",name:"默认",colors:["#f87171","#fb923c","#fbbf24","#a3e635","#34d399","#22d3ee","#818cf8","#c084fc"]},{id:"classic",name:"经典",colors:["#ef4444","#f59e0b","#10b981","#3b82f6","#6366f1","#8b5cf6","#ec4899","#14b8a6"]},{id:"vivid",name:"活力",colors:["#dc2626","#ea580c","#ca8a04","#16a34a","#0891b2","#2563eb","#7c3aed","#db2777"]},{id:"dev",name:"代码",colors:["#f472b6","#a78bfa","#60a5fa","#38bdf8","#22d3ee","#34d399","#facc15","#fb923c"]},{id:"mint",name:"薄荷",colors:["#5eead4","#67e8f9","#93c5fd","#c4b5fd","#fbcfe8","#fde68a","#a7f3d0","#bae6fd"]}];function ln(o,d=[]){return[...ke,...d].find(i=>i.id===o)??ke[0]}function oe(){return"n_"+Math.random().toString(36).slice(2,10)+Date.now().toString(36).slice(-4)}function _(o){return JSON.parse(JSON.stringify(o))}function S(o,d){if(o.id===d)return o;for(const l of o.children){const i=S(l,d);if(i)return i}return null}function Y(o,d,l=null){if(o.id===d)return l;for(const i of o.children){const c=Y(i,d,o);if(c!==null)return c}return null}function He(o,d){const l=o.children.findIndex(i=>i.id===d);if(l>=0)return o.children.splice(l,1),!0;for(const i of o.children)if(He(i,d))return!0;return!1}function rn(o,d,l){const i=S(o,d);return!i||i.text===l?!1:(i.text=l,!0)}function an(o,d,l,i){if(!Y(o,d)||d===l||S(S(o,d),l))return!1;const c=Y(o,d),u=c.children.findIndex(g=>g.id===d);if(u<0)return!1;const[f]=c.children.splice(u,1);if(i==="child"){const g=S(o,l);return g?(g.children.push(f),!0):(c.children.splice(u,0,f),!1)}const p=Y(o,l);if(!p)return c.children.splice(u,0,f),!1;let y=p.children.findIndex(g=>g.id===l);return y<0?(c.children.splice(u,0,f),!1):(i==="after"&&(y+=1),p.children.splice(y,0,f),!0)}function tt(o){const d=/^新节点(?:\s+(\d+))?$/;let l=0,i=!1;for(const c of o.children){const u=c.text.match(d);if(u)if(u[1]){const f=parseInt(u[1],10);f>l&&(l=f)}else i=!0}return l===0&&!i?Ve:l>0?`新节点 ${l+1}`:"新节点 2"}function nt(o,d,l){const i=S(o,d);if(!i)return null;const c={id:oe(),text:l??tt(i),children:[]};return i.children.push(c),c}function ot(o,d,l){const i=Y(o,d);if(!i)return null;const c=i.children.findIndex(f=>f.id===d);if(c<0)return null;const u={id:oe(),text:l??tt(i),children:[]};return i.children.splice(c+1,0,u),u}function cn(o,d,l){const i=Y(o,d);if(!i)return null;const c=i.children.findIndex(f=>f.id===d);if(c<0)return null;const u={id:oe(),text:l,children:[]};return i.children.splice(c,0,u),u}function sn(o,d){const l=Y(o,d);if(!l)return null;const i=l.children.findIndex(f=>f.id===d);if(i<0)return null;const c=l.children[i],u=_(c);return it(u),l.children.splice(i+1,0,u),u}function it(o){o.id=oe();for(const d of o.children)it(d)}const Ve="新节点";function Pe(o,d="导入的导图"){const l=o.split(/\r?\n/),i={id:oe(),text:d,children:[]},c=[i],u=[-1/0],f=[],p=/^(#{1,6})\s+(.+?)\s*#*\s*$/,y=/^!\[([^\]]*)\]\((\S+?)(?:\s+"[^"]*")?\)\s*$/,g=/^\[([^\]]+)\]\((\S+?)(?:\s+"[^"]*")?\)\s*$/,s=/^(`{3,}|~{3,})\s*(\S+)?\s*$/;let k=!1,N=[],w=null;function z(b){N.push(b)}function P(){if(w&&N.length>0){for(;N.length>0&&N[0].trim()==="";)N.shift();for(;N.length>0&&N[N.length-1].trim()==="";)N.pop();const b=N.join(`
2
+ `);b&&(w.note={text:b})}k=!1,N=[]}for(const b of l){if(k){const D=b.match(s);if(D&&D[1][0]==="`"){P();continue}z(b);continue}const F=b.match(p);if(F){const D=F[1].length,Q=F[2].trim();f.push({level:D,text:Q,body:""}),w=f[f.length-1];continue}const T=b.match(s);if(T&&T[2]==="note"){k=!0,N=[];continue}const $=b.match(y);if($&&w){const D=$[2],Q=160,ae=120;w.image={src:D,naturalW:Q,naturalH:ae,width:Q,height:ae};continue}const Z=b.match(g);if(Z&&w){w.link={url:Z[2]},w.text=Z[1];continue}b.trim().length>0&&w&&(w.body=w.body?w.body+" "+b.trim():b.trim())}k&&P();function ie(b){for(;c.length>1;){const Z=c.length-1,D=u[Z];if(D!==void 0&&D<b.level)break;c.pop(),u.pop()}const F=c[c.length-1],T=b.text,$={id:oe(),text:T,children:[]};b.image&&($.image={...b.image}),b.link&&($.link={url:b.link.url}),b.note&&($.note={text:b.note.text}),b.body&&ee(b,f,f.indexOf(b))&&$.children.push({id:oe(),text:b.body,children:[]}),F.children.push($),c.push($),u.push(b.level)}function ee(b,F,T){for(let $=T+1;$<F.length;$++){if(F[$].level<=b.level)return!0;if(F[$].level>b.level)return!1}return!0}for(const b of f)ie(b);if(f.length>0&&f[0].level===1){const b=i.children[0];b&&(i.text=b.text,i.id=b.id,b.image&&(i.image={...b.image}),b.link&&(i.link={url:b.link.url}),b.note&&(i.note={text:b.note.text}),i.children=b.children)}return i}function ze(o,d=1){let l="#".repeat(d)+" "+(o.text||"")+`
3
+ `;o.link&&(l+=`[${o.text||"link"}](${o.link.url})
4
+ `),o.image&&(l+=`![image](${o.image.src})
5
+ `),o.note&&(l+="```note\n"+o.note.text+"\n```\n");for(const i of o.children)l+=ze(i,d+1);return l}function dn(o){const d=o.minScale??.2,l=o.maxScale??3,i=o.step??1.2,c=e.ref(1),u=e.ref(0),f=e.ref(0),p=e.ref(!1),y=e.reactive({x:0,y:0,ox:0,oy:0}),g=e.ref(!1),s=e.reactive({x:0,y:0}),k=e.reactive({x:0,y:0,width:0,height:0}),N=e.ref(0);let w=null;function z(v){w=v}function P(v){v.preventDefault();const C=o.getContainer();if(!C)return;const O=-v.deltaY*.001,X=Math.min(l,Math.max(d,c.value*(1+O))),j=C.getBoundingClientRect(),G=v.clientX-j.left,me=v.clientY-j.top,be=(G-u.value)/c.value,he=(me-f.value)/c.value;c.value=X,u.value=G-be*X,f.value=me-he*X}function ie(){c.value=Math.min(l,c.value*i)}function ee(){c.value=Math.max(d,c.value/i)}function b(v){var O;v.target.closest(".zm-node, .zm-toolbar, button, input, textarea")||(p.value=!0,y.x=v.clientX,y.y=v.clientY,y.ox=u.value,y.oy=f.value,window.addEventListener("mousemove",F),window.addEventListener("mouseup",T),(O=v.preventDefault)==null||O.call(v))}function F(v){p.value&&(u.value=y.ox+(v.clientX-y.x),f.value=y.oy+(v.clientY-y.y))}function T(){p.value=!1,window.removeEventListener("mousemove",F),window.removeEventListener("mouseup",T)}function $(v,C){g.value=!0,s.x=v,s.y=C,k.x=v,k.y=C,k.width=0,k.height=0,N.value++,window.addEventListener("mousemove",Q),window.addEventListener("mouseup",D)}function Z(v,C){if(!g.value)return;const O=Math.min(s.x,v),X=Math.min(s.y,C),j=Math.max(s.x,v),G=Math.max(s.y,C);k.x=O,k.y=X,k.width=j-O,k.height=G-X,N.value++}function D(){g.value=!1,window.removeEventListener("mousemove",Q),window.removeEventListener("mouseup",D),w&&w()}function Q(v){if(!g.value)return;const C=o.getContainer();if(!C)return;const O=C.getBoundingClientRect(),X=(v.clientX-O.left-u.value)/c.value,j=(v.clientY-O.top-f.value)/c.value;Z(X,j)}function ae(v,C,O,X=60){const j=o.getContainer();if(!j)return;const G=j.getBoundingClientRect(),me=(G.width-X*2)/v,be=(G.height-X*2)/C,he=Math.min(1,Math.max(.3,Math.min(me,be)));c.value=he,u.value=G.width/2,f.value=G.height/2-O*he}return{scale:c,offsetX:u,offsetY:f,isPanning:p,onWheel:P,zoomIn:ie,zoomOut:ee,startPan:b,startMarquee:$,updateMarquee:Z,isMarquee:g,marquee:k,marqueeVersion:N,setOnMarqueeEnd:z,resetView:ae}}const un=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform);function lt(o){return un?o.metaKey:o.ctrlKey}function fn(o){function d(){const i=o.getSelectedId();return i||(o.defaultTargetId?o.defaultTargetId():o.getRootId())}function l(i){const c=i.target;if(c&&(c.tagName==="INPUT"||c.tagName==="TEXTAREA"||c.isContentEditable)||o.isReadonly()||o.isEditing())return;const u=o.getSelectedId(),f=d();if(f){if(lt(i)&&!i.shiftKey){if(i.key==="d"||i.key==="D"){u&&u!==o.getRootId()&&(i.preventDefault(),o.onDuplicate(u));return}if(i.key==="z"||i.key==="Z"){i.preventDefault(),o.onUndo();return}if(i.key==="y"||i.key==="Y"){i.preventDefault(),o.onRedo();return}if(i.key==="Home"){i.preventDefault(),o.onSelectRoot();return}}if(lt(i)&&i.shiftKey&&(i.key==="Z"||i.key==="z")){i.preventDefault(),o.onRedo();return}i.key==="Tab"?(i.preventDefault(),o.onAddChild(f)):i.key==="Enter"?(i.preventDefault(),i.shiftKey?u&&u!==o.getRootId()&&o.onAddSiblingBefore(u):o.onAddSibling(f)):(i.key==="Delete"||i.key==="Backspace")&&u&&u!==o.getRootId()?(i.preventDefault(),o.onRemove(u)):i.key==="F2"&&u?(i.preventDefault(),o.onStartEdit(u)):i.key==="Escape"?(i.preventDefault(),o.onClearSelection()):i.key==="ArrowDown"?(i.preventDefault(),o.onNavigate(0,1)):i.key==="ArrowUp"?(i.preventDefault(),o.onNavigate(0,-1)):i.key==="ArrowRight"?(i.preventDefault(),o.onNavigate(1,0)):i.key==="ArrowLeft"&&(i.preventDefault(),o.onNavigate(-1,0))}}e.onMounted(()=>{window.addEventListener("keydown",l)}),e.onBeforeUnmount(()=>{window.removeEventListener("keydown",l)})}function mn(o=100){const d=e.ref([]);let l=-1;function i(){return l>0}function c(){return l<d.value.length-1}function u(g){const s=JSON.stringify(g);for(l<d.value.length-1&&(d.value=d.value.slice(0,l+1)),d.value.push(s),l=d.value.length-1;d.value.length>o;)d.value.shift(),l--}function f(){return i()?(l--,JSON.parse(d.value[l])):null}function p(){return c()?(l++,JSON.parse(d.value[l])):null}function y(){d.value=[],l=-1}return{canUndo:i,canRedo:c,record:u,undo:f,redo:p,reset:y}}const hn=["disabled"],gn=["disabled"],yn=["disabled"],xn=["disabled"],pn=["disabled"],kn=["disabled"],wn=e.defineComponent({__name:"NodeContextMenu",props:{x:{},y:{},container:{},hasImage:{type:Boolean,default:!1},hasLink:{type:Boolean,default:!1},hasNote:{type:Boolean,default:!1},readonly:{type:Boolean,default:!1}},emits:["pickImage","setLink","removeLink","editNote","removeNote","removeImage","close"],setup(o,{emit:d}){const l=o,i=d,c=e.computed(()=>{let N=l.x+2,w=l.y+2;if(l.container){const z=l.container.getBoundingClientRect(),P=180,ie=u.value?f.value?184:160:136;N+P>z.right&&(N=Math.max(z.left+4,l.x-P-2)),w+ie>z.bottom&&(w=Math.max(z.top+4,l.y-ie-2)),N<z.left+2&&(N=z.left+2),w<z.top+2&&(w=z.top+2)}return{left:N,top:w}}),u=e.computed(()=>l.hasImage),f=e.computed(()=>l.hasLink),p=e.computed(()=>l.hasNote);function y(N){const w=N.target;w&&w.closest(".zm-node-menu")||i("close")}function g(N){N.key==="Escape"&&i("close")}function s(){i("close")}window.addEventListener("mousedown",y,!0),window.addEventListener("keydown",g,!0),window.addEventListener("wheel",s,!0),window.addEventListener("scroll",s,!0),e.onBeforeUnmount(()=>{window.removeEventListener("mousedown",y,!0),window.removeEventListener("keydown",g,!0),window.removeEventListener("wheel",s,!0),window.removeEventListener("scroll",s,!0)});function k(N){l.readonly||(N(),i("close"))}return(N,w)=>(e.openBlock(),e.createElementBlock("div",{class:"zm-node-menu",style:e.normalizeStyle({left:c.value.left+"px",top:c.value.top+"px"}),onContextmenu:w[6]||(w[6]=e.withModifiers(()=>{},["prevent"]))},[e.createElementVNode("button",{class:"zm-node-menu-item",disabled:o.readonly,onClick:w[0]||(w[0]=e.withModifiers(z=>k(()=>i("pickImage")),["stop"]))},[e.createVNode(R,{name:"image",size:13}),e.createElementVNode("span",null,e.toDisplayString(u.value?"替换图片":"添加图片"),1)],8,hn),u.value?(e.openBlock(),e.createElementBlock("button",{key:0,class:"zm-node-menu-item",disabled:o.readonly,onClick:w[1]||(w[1]=e.withModifiers(z=>k(()=>i("removeImage")),["stop"]))},[e.createVNode(R,{name:"x",size:13}),w[7]||(w[7]=e.createElementVNode("span",null,"移除图片",-1))],8,gn)):e.createCommentVNode("",!0),e.createElementVNode("button",{class:"zm-node-menu-item",disabled:o.readonly,onClick:w[2]||(w[2]=e.withModifiers(z=>k(()=>i("setLink")),["stop"]))},[e.createVNode(R,{name:"link",size:13}),e.createElementVNode("span",null,e.toDisplayString(f.value?"编辑链接":"添加链接"),1)],8,yn),f.value?(e.openBlock(),e.createElementBlock("button",{key:1,class:"zm-node-menu-item",disabled:o.readonly,onClick:w[3]||(w[3]=e.withModifiers(z=>k(()=>i("removeLink")),["stop"]))},[e.createVNode(R,{name:"x",size:13}),w[8]||(w[8]=e.createElementVNode("span",null,"移除链接",-1))],8,xn)):e.createCommentVNode("",!0),e.createElementVNode("button",{class:"zm-node-menu-item",disabled:o.readonly,onClick:w[4]||(w[4]=e.withModifiers(z=>k(()=>i("editNote")),["stop"]))},[e.createVNode(R,{name:"note",size:13}),e.createElementVNode("span",null,e.toDisplayString(p.value?"编辑笔记":"添加笔记"),1)],8,pn),p.value?(e.openBlock(),e.createElementBlock("button",{key:2,class:"zm-node-menu-item",disabled:o.readonly,onClick:w[5]||(w[5]=e.withModifiers(z=>k(()=>i("removeNote")),["stop"]))},[e.createVNode(R,{name:"x",size:13}),w[9]||(w[9]=e.createElementVNode("span",null,"移除笔记",-1))],8,kn)):e.createCommentVNode("",!0)],36))}}),bn=["viewBox","width","height"],En={class:"zm-edges"},Nn=["d","fill"],Mn=["data-node-id","onClick","onDblclick","onContextmenu","onMouseenter","onMouseleave"],Bn=["src","width","height","alt"],vn={key:1,class:"zm-text"},Cn={class:"zm-text-label"},Sn=["href","title"],Vn=["title","onClick"],zn=["title"],In=["title","onClick"],Wn=["onClick"],$n=["onMousedown"],Rn=["onClick"],Ln={key:0,class:"zm-toolbar"},An=["src"],Tn=["src"],Dn={class:"zm-tb-tip"},fe=24,we=400,re=160,rt=e.defineComponent({__name:"MindMap",props:{data:{},readonly:{type:Boolean,default:!1},theme:{},previewMode:{type:Boolean,default:!1},markdown:{},lineColors:{}},emits:["change","select","edit-note","markdownChange"],setup(o,{expose:d,emit:l}){const i=o,c=l,u=e.ref(null),f=e.ref(null),p=e.ref(""),y=e.ref(null),g=e.ref(new Set),s=e.ref(_(i.data)),k=e.ref(i.markdown!==void 0);let N=!1;e.watch(()=>i.markdown,t=>{if(t===void 0){k.value=!1;return}k.value=!0;const n=Pe(t||"");N=!0,s.value=_(n),y.value=null,g.value=new Set,W(),e.nextTick(()=>{N=!1,te()})}),e.watch(s,()=>{k.value&&!N&&c("markdownChange",ze(s.value))},{deep:!0});const w=e.computed(()=>E.showOrderBadge===!0),z=e.ref(new Map),P=z.value;function ie(t,n){const a={};n.bg&&(a.bg=n.bg),n.textColor&&(a.textColor=n.textColor),n.borderColor&&(a.borderColor=n.borderColor),n.fontWeight&&(a.fontWeight=n.fontWeight),Object.keys(a).length===0?P.delete(t):P.set(t,a),z.value=new Map(P)}function ee(t){return P.get(t)??{}}function b(t,n){const a=S(s.value,t);a&&(a.image={src:n.src,naturalW:n.naturalW,naturalH:n.naturalH,width:T(n.width,fe,we),height:T(n.height,fe,we)},H(),W(),c("change",s.value))}function F(t){const n=S(s.value,t);!n||!n.image||(delete n.image,H(),W(),c("change",s.value))}function T(t,n,a){return Math.min(a,Math.max(n,t))}function $(t,n){const a=new FileReader;a.onload=()=>{if(typeof a.result!="string")return;const h=a.result,m=new window.Image;m.onload=()=>{const r=m.naturalWidth||re,x=m.naturalHeight||re,V=T(r,fe,re),A=T(Math.round(x*V/r),fe,we);n({src:h,naturalW:r,naturalH:x,width:V,height:A})},m.onerror=()=>{n({src:h,naturalW:re,naturalH:re,width:re,height:re})},m.src=h},a.readAsDataURL(t)}function Z(t){const n=document.createElement("input");n.type="file",n.accept="image/*",n.style.display="none",n.onchange=()=>{var h;const a=(h=n.files)==null?void 0:h[0];a&&($(a,m=>b(t,m)),document.body.removeChild(n))},document.body.appendChild(n),n.click()}function D(t,n){const a=n.trim(),h=S(s.value,t);h&&(a?h.link={url:a}:delete h.link,H(),W(),c("change",s.value))}function Q(t){D(t,"")}function ae(t,n){const a=S(s.value,t);a&&(n?a.note={text:n}:delete a.note,H(),W(),c("change",s.value))}function v(t){ae(t,"")}const C=e.ref(null);function O(t,n){i.readonly||(t.preventDefault(),t.stopPropagation(),y.value=n.id,c("select",S(s.value,n.id)),C.value={nodeId:n.id,x:t.clientX,y:t.clientY})}function X(){C.value=null}function j(){var n;const t=(n=C.value)==null?void 0:n.nodeId;t&&Z(t)}function G(){var h,m,r;const t=(h=C.value)==null?void 0:h.nodeId;if(!t)return;const n=((r=(m=S(s.value,t))==null?void 0:m.link)==null?void 0:r.url)??"",a=window.prompt("输入链接 URL(留空取消)",n);a!==null&&D(t,a)}function me(){var n;const t=(n=C.value)==null?void 0:n.nodeId;t&&Q(t)}function be(){var n;const t=(n=C.value)==null?void 0:n.nodeId;t&&at(t)}function he(){var n;const t=(n=C.value)==null?void 0:n.nodeId;t&&v(t)}function Pn(){var n;const t=(n=C.value)==null?void 0:n.nodeId;t&&F(t)}function at(t){i.readonly||c("edit-note",t)}function Fn(t,n=60){const a=t.replace(/\s+/g," ").trim();return a.length<=n?a||"点击编辑笔记":a.slice(0,n)+"…"}function ct(t){var m;if(i.readonly||f.value)return;const n=t.target;if(n&&(n.tagName==="INPUT"||n.tagName==="TEXTAREA"||n.isContentEditable))return;const a=y.value;if(!a)return;const h=(m=t.clipboardData)==null?void 0:m.items;if(h)for(let r=0;r<h.length;r++){const x=h[r];if(x.kind==="file"&&x.type.startsWith("image/")){const V=x.getAsFile();if(!V)continue;t.preventDefault();const A=S(s.value,a);if(A!=null&&A.image&&!window.confirm("该节点已有图片,要用剪贴板里的图片替换吗?"))return;$(V,q=>b(a,q));return}}}e.onMounted(()=>{window.addEventListener("paste",ct)}),e.onBeforeUnmount(()=>{window.removeEventListener("paste",ct)});const Ee=e.ref(null),On=e.computed(()=>{var t;return((t=Ee.value)==null?void 0:t.nodeId)??null});function qn(t,n){if(!n.image)return;t.preventDefault(),t.stopPropagation();const a=n.image.naturalW||n.image.width,h=n.image.naturalH||n.image.height,m=h>0?h/a:1;Ee.value={nodeId:n.id,startX:t.clientX,startY:t.clientY,startW:n.image.width,startH:n.image.height,naturalW:a,naturalH:h,ratio:m,pendingW:n.image.width,pendingH:n.image.height},window.addEventListener("mousemove",st),window.addEventListener("mouseup",dt)}function st(t){var A,q;const n=Ee.value;if(!n)return;const a=M.scale.value||1,h=t.clientX-n.startX,m=T(n.startW+h/a,fe,we),r=T(m*n.ratio,fe,we);n.pendingW=m,n.pendingH=r;const x=(A=u.value)==null?void 0:A.querySelector(`[data-node-id="${n.nodeId}"] .zm-node-img`);x&&(x.style.width=`${m}px`,x.style.height=`${r}px`);const V=(q=u.value)==null?void 0:q.querySelector(`[data-node-id="${n.nodeId}"]`);V&&(V.style.minWidth=`${Math.max(80,Math.ceil(m+28))}px`,V.style.height=`${Math.ceil(r+8+30)}px`)}function dt(){const t=Ee.value;if(window.removeEventListener("mousemove",st),window.removeEventListener("mouseup",dt),Ee.value=null,!t)return;const n=S(s.value,t.nodeId);!n||!n.image||(b(t.nodeId,{src:n.image.src,naturalW:n.image.naturalW,naturalH:n.image.naturalH,width:t.pendingW,height:t.pendingH}),y.value=t.nodeId,c("select",n),Oe=!0)}const Fe=e.ref(null);let Oe=!1;function Xn(t){Fe.value=t}function Kn(t){Fe.value===t&&(Fe.value=null)}const ut=e.ref(0),qe=e.ref(!1),le=mn(100);function H(){le.record({data:s.value})}function W(){g.value=new Set(g.value),ut.value++}const J=e.computed(()=>{var t,n,a,h,m,r,x,V,A,q;return{rootBg:((t=i.theme)==null?void 0:t.rootBg)??"#1f2937",rootText:((n=i.theme)==null?void 0:n.rootText)??"#ffffff",branchBg:((a=i.theme)==null?void 0:a.branchBg)??"#ffffff",branchText:((h=i.theme)==null?void 0:h.branchText)??"#1f2937",lineColor:((m=i.theme)==null?void 0:m.lineColor)??"#94a3b8",bgColor:((r=i.theme)==null?void 0:r.bgColor)??"#f8fafc",fontSize:((x=i.theme)==null?void 0:x.fontSize)??14,lineWidthStart:((V=i.theme)==null?void 0:V.lineWidthStart)??2.2,lineWidthEnd:((A=i.theme)==null?void 0:A.lineWidthEnd)??.8,rainbowBranch:((q=i.theme)==null?void 0:q.rainbowBranch)??!1}}),E=e.reactive({autoBalanceOnChange:!0,lineWidthStart:12,lineWidthEnd:3.6,rainbowBranch:!0,branchPaletteId:"default",customPalettes:[],lineStyle:"curve",layoutMode:"mindmap",taperedEdge:!0,showOrderBadge:!1});function ft(t){return E.taperedEdge?Un(t):ht(t)}function mt(t){return E.taperedEdge?E.lineWidthEnd:ht(t)}function Un(t){return t<=0?E.lineWidthStart:t===1?Math.max(1.5,E.lineWidthStart*.67):t===2?Math.max(.8,E.lineWidthStart*.42):E.lineWidthEnd}function ht(t){if(t<=0)return E.lineWidthStart;if(t>=3)return E.lineWidthEnd;const n=t/3;return E.lineWidthStart+(E.lineWidthEnd-E.lineWidthStart)*n}function Yn(t,n,a,h){const m=1-t,r=m*m*m*n.x+3*m*m*t*a.x1+3*m*t*t*a.x2+t*t*t*h.x,x=m*m*m*n.y+3*m*m*t*a.y1+3*m*t*t*a.y2+t*t*t*h.y;return{x:r,y:x}}function jn(t,n,a,h,m=32,r="curve",x="right"){if(r==="curve"){let de;if(x==="right"||x==="left"){const I=Math.abs(n.x-t.x)*.45,ne=x==="right"?1:-1;de={x1:t.x+ne*I,y1:t.y,x2:n.x-ne*I,y2:n.y}}else{const I=Math.abs(n.y-t.y)*.45;de={x1:t.x,y1:t.y+I,x2:n.x,y2:n.y-I}}const po=B=>{const I=1-B,ne=-3*I*I*t.x+3*(I*I-2*I*B)*de.x1+3*(2*I*B-B*B)*de.x2+3*B*B*n.x,pe=-3*I*I*t.y+3*(I*I-2*I*B)*de.y1+3*(2*I*B-B*B)*de.y2+3*B*B*n.y;return{dx:ne,dy:pe}},Be=[],Ge=[];for(let B=0;B<=m;B++){const I=B/m,ne=B===0?t:B===m?n:Yn(I,t,de,n),pe=po(I);let Le=Math.hypot(pe.dx,pe.dy);Le<1e-6&&(Le=1);const Wt=-pe.dy/Le,$t=pe.dx/Le,Ae=(a+(h-a)*I)/2;Be.push({x:ne.x+Wt*Ae,y:ne.y+$t*Ae}),Ge.push({x:ne.x-Wt*Ae,y:ne.y-$t*Ae})}let Re=`M ${Be[0].x.toFixed(2)} ${Be[0].y.toFixed(2)}`;for(let B=1;B<=m;B++)Re+=` L ${Be[B].x.toFixed(2)} ${Be[B].y.toFixed(2)}`;for(let B=m;B>=0;B--)Re+=` L ${Ge[B].x.toFixed(2)} ${Ge[B].y.toFixed(2)}`;return Re+=" Z",Re}const V=n.x-t.x,A=n.y-t.y;let q=Math.hypot(V,A);q<1e-6&&(q=1);const se=-A/q,ye=V/q,xe=a/2,Me=h/2,St={x:t.x+se*xe,y:t.y+ye*xe},Vt={x:t.x-se*xe,y:t.y-ye*xe},zt={x:n.x-se*Me,y:n.y-ye*Me},It={x:n.x+se*Me,y:n.y+ye*Me};return`M ${St.x.toFixed(2)} ${St.y.toFixed(2)} L ${It.x.toFixed(2)} ${It.y.toFixed(2)} L ${zt.x.toFixed(2)} ${zt.y.toFixed(2)} L ${Vt.x.toFixed(2)} ${Vt.y.toFixed(2)} Z`}const Ie=e.computed(()=>K.value.root.children),Gn=ke[0].colors,gt=e.computed(()=>ln(E.branchPaletteId,E.customPalettes)),ce=e.computed(()=>{const t=new Map;if(!E.rainbowBranch)return t;const n=i.lineColors,a=n&&n.length>0?n:gt.value.colors.length>0?gt.value.colors:Gn;for(let m=0;m<Ie.value.length;m++){const r=Ie.value[m];t.set(r.id,a[m%a.length])}const h=(m,r)=>{t.set(m.id,r);for(const x of m.children)h(x,r)};for(let m=0;m<Ie.value.length;m++){const r=Ie.value[m];h(r,a[m%a.length])}return t});function Jn(t,n){return E.rainbowBranch?ce.value.get(n.id)??J.value.lineColor:J.value.lineColor}function Zn(t){const n=ee(t.id);if(n.bg)return n.bg;if(t.isRoot)return J.value.rootBg;if(E.rainbowBranch){const a=ce.value.get(t.id);if(a)return to(a,.18)}return J.value.branchBg}function Qn(t){const n=ee(t.id);if(n.textColor)return n.textColor;if(t.isRoot)return J.value.rootText;if(E.rainbowBranch){const a=ce.value.get(t.id);if(a)return yt(a,.55)}return J.value.branchText}function _n(t){const n=ee(t.id);if(n.borderColor)return n.borderColor;if(t.isRoot)return J.value.rootBg;if(E.rainbowBranch){const a=ce.value.get(t.id);if(a)return yt(a,.3)}return J.value.lineColor}function eo(t){return ee(t.id).fontWeight??(t.isRoot?600:400)}function to(t,n){const a=t.replace("#",""),h=a.length===6?a:a.split("").map(V=>V+V).join(""),m=parseInt(h.slice(0,2),16),r=parseInt(h.slice(2,4),16),x=parseInt(h.slice(4,6),16);return`rgba(${m}, ${r}, ${x}, ${n})`}function yt(t,n){const a=t.replace("#",""),h=a.length===6?a:a.split("").map(V=>V+V).join(""),m=Math.round(parseInt(h.slice(0,2),16)*(1-n)),r=Math.round(parseInt(h.slice(2,4),16)*(1-n)),x=Math.round(parseInt(h.slice(4,6),16)*(1-n));return`rgb(${m}, ${r}, ${x})`}const M=dn({getContainer:()=>u.value});M.setOnMarqueeEnd(mo),fn({isEditing:()=>f.value!==null,isReadonly:()=>i.readonly,getSelectedId:()=>y.value,getRootId:()=>s.value.id,defaultTargetId:()=>s.value.id,onAddChild:ge,onAddSibling:$e,onAddSiblingBefore:kt,onRemove:bt,onStartEdit:Ne,onClearSelection:()=>{y.value=null,c("select",null)},onDuplicate:wt,onUndo:Ke,onRedo:Ue,onNavigate:ro,onSelectRoot:()=>{y.value=s.value.id;const t=S(s.value,s.value.id);t&&c("select",t)}});const K=e.computed(()=>{const t=_(s.value);return pt(t),en(t,{mode:E.layoutMode,baseFontSize:J.value.fontSize})}),xt=e.ref([]),Xe=e.computed(()=>(ut.value,xt.value));e.watch(K,t=>{const n=[],a=h=>{n.push(h);for(const m of h.children)a(m)};a(t.root),xt.value=n},{immediate:!0});const no=e.computed(()=>{const t=[];for(const n of Xe.value)for(const a of n.children)t.push({from:n,to:a,key:`${n.id}->${a.id}`});return t}),oo=e.computed(()=>`${K.value.vbX} ${K.value.vbY} ${K.value.vbW} ${K.value.vbH}`);function pt(t){if(g.value.has(t.id)){t.children=[],t.collapsed=!0;return}t.collapsed=!1;for(const n of t.children)pt(n)}function Ne(t){const n=S(s.value,t);n&&(f.value=t,p.value=n.text,e.nextTick(()=>{const a=document.querySelector(".zm-input");a==null||a.focus(),a==null||a.select()}))}function We(t={}){if(!f.value)return;const n=S(s.value,f.value);n&&n.text!==(p.value.trim()||" ")&&(n.text=p.value.trim()||" ",H(),c("change",s.value));const a=f.value;f.value=null,t.addChild?e.nextTick(()=>ge(a)):t.addSibling==="after"?e.nextTick(()=>$e(a)):t.addSibling==="before"&&e.nextTick(()=>kt(a))}function io(){f.value=null}function lo(t){const n=t.metaKey||t.ctrlKey;n&&(t.key==="z"||t.key==="Z")&&!t.shiftKey?(t.preventDefault(),Ke()):(n&&t.shiftKey&&(t.key==="z"||t.key==="Z")||n&&(t.key==="y"||t.key==="Y")&&!t.shiftKey)&&(t.preventDefault(),Ue())}function ge(t){const n=nt(s.value,t,Ve);n&&(H(),W(),c("change",s.value),e.nextTick(()=>Ne(n.id)))}function $e(t){if(t===s.value.id){ge(t);return}const n=ot(s.value,t,Ve);n&&(H(),W(),c("change",s.value),e.nextTick(()=>Ne(n.id)))}function kt(t){if(t===s.value.id){ge(t);return}const n=cn(s.value,t,Ve);n&&(H(),W(),c("change",s.value),e.nextTick(()=>Ne(n.id)))}function wt(t){if(t===s.value.id)return;const n=sn(s.value,t);n&&(H(),y.value=n.id,c("change",s.value),W())}function Ke(){const t=le.undo();t&&(s.value=t.data,y.value=null,c("select",null),W(),c("change",s.value))}function Ue(){const t=le.redo();t&&(s.value=t.data,y.value=null,c("select",null),W(),c("change",s.value))}function ro(t,n){const a=y.value??s.value.id,h=S(s.value,a);if(!h)return;let m=null;if(n===1){const r=Y(s.value,h.id);if(r){const x=r.children.findIndex(V=>V.id===h.id);x>=0&&x<r.children.length-1&&(m=r.children[x+1].id)}}else if(n===-1){const r=Y(s.value,h.id);if(r){const x=r.children.findIndex(V=>V.id===h.id);x>0&&(m=r.children[x-1].id)}}else if(t===1){const r=Y(s.value,h.id);r&&(m=r.id)}else t===-1&&h.children.length>0&&(m=h.children[0].id);if(m){y.value=m;const r=S(s.value,m);r&&c("select",r)}}function bt(t){t!==s.value.id&&He(s.value,t)&&(H(),y.value===t&&(y.value=null),W(),c("change",s.value))}function Et(t){g.value.has(t)?g.value.delete(t):g.value.add(t),W()}function ao(t,n){rn(s.value,t,n)&&(H(),W(),c("change",s.value))}function co(t,n,a){return an(s.value,t,n,a)?(H(),W(),c("change",s.value),!0):!1}function so(t,n){t.stopPropagation(),y.value=n.id;const a=S(s.value,n.id);c("select",a)}function uo(t){const n=t.target;if(!n||n.closest(".zm-node, .zm-toolbar, button, input, textarea"))return;if(t.button===2){M.startPan(t);return}if(t.button!==0)return;const a=u.value.getBoundingClientRect(),h=(t.clientX-a.left-M.offsetX.value)/M.scale.value,m=(t.clientY-a.top-M.offsetY.value)/M.scale.value;M.startMarquee(h,m)}function fo(t){if(Oe){Oe=!1;return}const n=t.target;if(!n||n.closest(".zm-node"))return;const a=M.marquee;a.width>=4||a.height>=4||y.value!==null&&(y.value=null,c("select",null))}function mo(){const t=M.marquee;if(t.width<4&&t.height<4)return;const n=t.x,a=t.y,h=t.x+t.width,m=t.y+t.height,r=[];for(const x of Xe.value){const V=x.width/2,A=x.height/2,q=x.x-V,se=x.x+V,ye=x.y-A,xe=x.y+A;q<=h&&se>=n&&ye<=m&&xe>=a&&r.push(x.id)}if(r.length>0){y.value=r[0];const x=S(s.value,r[0]);x&&c("select",x)}}function Nt(t){return g.value.has(t)}function ho(t){const n=S(s.value,t.id);return!!n&&n.children.length>0}function Ye(t){const n=S(s.value,t);return n?n.children.length:0}function Mt(t){if(!S(s.value,t))return 0;const h=[s.value];for(;h.length;){const m=h.pop(),r=m.children.findIndex(x=>x.id===t);if(r>=0)return r;for(const x of m.children)h.push(x)}return 0}function Bt(t,n,a,h){if(((h==null?void 0:h._dir)??t._dir)==="down")return n==="out"?{x:t.x,y:t.y+t.height/2}:{x:t.x,y:t.y-t.height/2};let r;return n==="in"?r=-t.side:a!==void 0?r=a:r=t.side,{x:t.x+r*(t.width/2),y:t.y}}function te(){const t=K.value;M.resetView(t.width,t.height,t.root.y)}function go(){qe.value=!0,H(),W(),e.nextTick(()=>te())}function je(t){E.layoutMode!==t&&(E.layoutMode=t,W(),e.nextTick(()=>te()))}function vt(){return JSON.stringify(s.value,null,2)}function Ct(t){try{const n=JSON.parse(t);return!n.id||!Array.isArray(n.children)?!1:(le.reset(),s.value=_(n),y.value=null,g.value=new Set,W(),e.nextTick(()=>te()),c("change",s.value),!0)}catch{return!1}}function yo(){const t=document.createElement("input");t.type="file",t.accept="application/json",t.onchange=()=>{var h;const n=(h=t.files)==null?void 0:h[0];if(!n)return;const a=new FileReader;a.onload=()=>{typeof a.result=="string"&&(Ct(a.result)||alert("导入失败:JSON 格式无效"))},a.readAsText(n)},t.click()}function xo(){const t=new Blob([vt()],{type:"application/json"}),n=URL.createObjectURL(t),a=document.createElement("a");a.href=n,a.download=`${s.value.text||"mindmap"}.json`,a.click(),URL.revokeObjectURL(n)}return d({addChild:t=>ge(t),addSibling:t=>$e(t),removeNode:t=>bt(t),duplicateNode:t=>wt(t),setNodeText:(t,n)=>ao(t,n),moveNode:(t,n,a)=>co(t,n,a),lineWidthForDepth:ft,endWidthForDepth:mt,getData:()=>s.value,setData:t=>{le.reset(),s.value=_(t),y.value=null,g.value=new Set,W(),H(),e.nextTick(()=>te())},resetView:()=>te(),exportData:vt,importData:Ct,getMarkdown:()=>ze(s.value),setMarkdown:(t,n=!0)=>{const a=Pe(t||"");n&&(k.value=!0),N=!n,le.reset(),s.value=_(a),y.value=null,g.value=new Set,W(),H(),e.nextTick(()=>{N=!1,te()}),c("change",s.value)},setBalanced:t=>{qe.value=t},isBalanced:()=>qe.value,balance:()=>go(),applyNodeStyle:(t,n)=>ie(t,n),getNodeStyle:t=>ee(t),applyNodeLink:(t,n)=>D(t,n),removeNodeLink:t=>Q(t),applyNodeNote:(t,n)=>ae(t,n),removeNodeNote:t=>v(t),undo:()=>Ke(),redo:()=>Ue(),canUndo:()=>le.canUndo(),canRedo:()=>le.canRedo(),applySettings:t=>{t.autoBalanceOnChange!==void 0&&(E.autoBalanceOnChange=t.autoBalanceOnChange),t.lineWidthStart!==void 0&&(E.lineWidthStart=Math.max(.5,Math.min(20,t.lineWidthStart))),t.lineWidthEnd!==void 0&&(E.lineWidthEnd=Math.max(.3,Math.min(10,t.lineWidthEnd))),t.rainbowBranch!==void 0&&(E.rainbowBranch=t.rainbowBranch),t.branchPaletteId!==void 0&&(E.branchPaletteId=t.branchPaletteId),t.customPalettes!==void 0&&(E.customPalettes=t.customPalettes),t.lineStyle!==void 0&&(E.lineStyle=t.lineStyle),t.taperedEdge!==void 0&&(E.taperedEdge=t.taperedEdge),t.showOrderBadge!==void 0&&(E.showOrderBadge=t.showOrderBadge)},getSettings:()=>({autoBalanceOnChange:E.autoBalanceOnChange,lineWidthStart:E.lineWidthStart,lineWidthEnd:E.lineWidthEnd,rainbowBranch:E.rainbowBranch,branchPaletteId:E.branchPaletteId,customPalettes:E.customPalettes,lineStyle:E.lineStyle,layoutMode:E.layoutMode,taperedEdge:E.taperedEdge,showOrderBadge:E.showOrderBadge}),setBranchPalette:t=>{if(!t)return;[...ke,...E.customPalettes].find(a=>a.id===t)&&(E.branchPaletteId=t)},getBranchPalette:()=>E.branchPaletteId,getBranchPalettes:()=>[...ke,...E.customPalettes]}),e.watch(()=>i.data,t=>{s.value=_(t),W()},{deep:!1}),e.onMounted(()=>{H(),e.nextTick(()=>te())}),(t,n)=>{var a,h,m;return e.openBlock(),e.createElementBlock("div",{class:"zm-mindmap",style:e.normalizeStyle({background:J.value.bgColor,fontSize:J.value.fontSize+"px"})},[e.createElementVNode("div",{ref_key:"wrapperRef",ref:u,class:"zm-canvas",onMousedown:uo,onContextmenu:n[13]||(n[13]=e.withModifiers(()=>{},["prevent"])),onWheel:n[14]||(n[14]=(...r)=>e.unref(M).onWheel&&e.unref(M).onWheel(...r)),onClick:fo},[e.createElementVNode("div",{class:"zm-svg-layer",style:e.normalizeStyle({left:K.value.vbX*e.unref(M).scale.value+e.unref(M).offsetX.value+"px",top:K.value.vbY*e.unref(M).scale.value+e.unref(M).offsetY.value+"px",width:K.value.vbW*e.unref(M).scale.value+"px",height:K.value.vbH*e.unref(M).scale.value+"px"})},[(e.openBlock(),e.createElementBlock("svg",{class:"zm-svg",viewBox:oo.value,preserveAspectRatio:"xMinYMin meet",width:K.value.vbW*e.unref(M).scale.value,height:K.value.vbH*e.unref(M).scale.value},[e.createElementVNode("g",En,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(no.value,r=>(e.openBlock(),e.createElementBlock("path",{key:r.key,d:jn(Bt(r.from,"out",r.to.side,r.to),Bt(r.to,"in"),ft(r.from.depth),mt(r.to.depth),32,E.lineStyle,r.to._dir),fill:Jn(r.from,r.to),stroke:"none"},null,8,Nn))),128))])],8,bn))],4),e.unref(M).isMarquee.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"zm-marquee",style:e.normalizeStyle({left:e.unref(M).marquee.x*e.unref(M).scale.value+e.unref(M).offsetX.value+"px",top:e.unref(M).marquee.y*e.unref(M).scale.value+e.unref(M).offsetY.value+"px",width:e.unref(M).marquee.width*e.unref(M).scale.value+"px",height:e.unref(M).marquee.height*e.unref(M).scale.value+"px"})},null,4)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:"zm-world",style:e.normalizeStyle({transform:`translate(${e.unref(M).offsetX.value}px, ${e.unref(M).offsetY.value}px) scale(${e.unref(M).scale.value})`})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(Xe.value,r=>(e.openBlock(),e.createElementBlock("div",{key:r.id,class:e.normalizeClass(["zm-node",{"is-root":r.isRoot,"is-selected":y.value===r.id,"is-editing":f.value===r.id,"has-image":!!r.image,"is-resizing":On.value===r.id}]),"data-node-id":r.id,style:e.normalizeStyle({left:r.x+"px",top:r.y+"px",minWidth:r.width+"px",height:r.height+"px",fontSize:r.fontSize+"px",background:Zn(r),color:Qn(r),borderColor:_n(r),fontWeight:eo(r),transform:"translate(-50%, -50%)"}),onClick:x=>so(x,r),onDblclick:x=>{x.stopPropagation(),o.readonly||Ne(r.id)},onContextmenu:x=>O(x,r),onMouseenter:x=>Xn(r.id),onMouseleave:x=>Kn(r.id)},[r.image?(e.openBlock(),e.createElementBlock("img",{key:0,class:"zm-node-img",src:r.image.src,width:r.image.width,height:r.image.height,alt:r.text,draggable:"false"},null,8,Bn)):e.createCommentVNode("",!0),f.value!==r.id?(e.openBlock(),e.createElementBlock("span",vn,[e.createElementVNode("span",Cn,e.toDisplayString(r.text),1),r.link&&!f.value?(e.openBlock(),e.createElementBlock("a",{key:0,class:"zm-node-link",href:r.link.url,target:"_blank",rel:"noopener noreferrer",title:`打开链接:${r.link.url}`,onClick:n[0]||(n[0]=e.withModifiers(()=>{},["stop"])),onMousedown:n[1]||(n[1]=e.withModifiers(()=>{},["stop"]))},[e.createVNode(R,{name:"link",size:11,stroke:2})],40,Sn)):e.createCommentVNode("",!0),r.note&&!f.value?(e.openBlock(),e.createElementBlock("button",{key:1,class:"zm-node-note-btn",type:"button",title:Fn(r.note.text),onClick:e.withModifiers(x=>at(r.id),["stop"]),onMousedown:n[2]||(n[2]=e.withModifiers(()=>{},["stop"]))},[e.createVNode(R,{name:"note",size:11,stroke:2})],40,Vn)):e.createCommentVNode("",!0)])):e.withDirectives((e.openBlock(),e.createElementBlock("input",{key:2,class:"zm-input","onUpdate:modelValue":n[3]||(n[3]=x=>p.value=x),autofocus:"",onBlur:n[4]||(n[4]=x=>We()),onKeydown:[n[5]||(n[5]=e.withKeys(e.withModifiers(x=>We({addSibling:"after"}),["exact"]),["enter"])),n[6]||(n[6]=e.withKeys(e.withModifiers(x=>We({addSibling:"before"}),["shift","prevent","exact"]),["enter"])),n[7]||(n[7]=e.withKeys(e.withModifiers(x=>We({addChild:!0}),["prevent"]),["tab"])),e.withKeys(io,["esc"]),lo],onMousedown:n[8]||(n[8]=e.withModifiers(()=>{},["stop"])),onClick:n[9]||(n[9]=e.withModifiers(()=>{},["stop"]))},null,544)),[[e.vModelText,p.value]]),w.value?(e.openBlock(),e.createElementBlock("span",{key:3,class:"zm-order-badge",title:`数据顺序:第 ${Mt(r.id)+1} 个`},e.toDisplayString(Mt(r.id)+1),9,zn)):e.createCommentVNode("",!0),Nt(r.id)&&!r.isRoot&&Ye(r.id)>0?(e.openBlock(),e.createElementBlock("span",{key:4,class:e.normalizeClass(["zm-collapse-badge",{"is-on-left":r.side===-1}]),style:e.normalizeStyle({background:ce.value.get(r.id)??"#64748b"}),title:`展开 ${Ye(r.id)} 个子节点`,onMousedown:n[10]||(n[10]=e.withModifiers(()=>{},["stop"])),onClick:e.withModifiers(x=>Et(r.id),["stop"])},e.toDisplayString(Ye(r.id)),47,In)):e.createCommentVNode("",!0),!o.readonly&&!r.isRoot&&ho(r)&&!Nt(r.id)?(e.openBlock(),e.createElementBlock("button",{key:5,class:e.normalizeClass(["zm-btn zm-collapse",{"is-on-left":r.side===-1}]),style:e.normalizeStyle({color:ce.value.get(r.id)??"#64748b",borderColor:ce.value.get(r.id)??"#64748b"}),title:"折叠",onMousedown:n[11]||(n[11]=e.withModifiers(()=>{},["stop"])),onClick:e.withModifiers(x=>Et(r.id),["stop"])},[e.createVNode(R,{name:"minus",size:10,stroke:2.4})],46,Wn)):e.createCommentVNode("",!0),r.image&&y.value===r.id&&f.value!==r.id?(e.openBlock(),e.createElementBlock("span",{key:6,class:"zm-img-resize-handle",title:"拖动调整图片大小",onMousedown:e.withModifiers(x=>qn(x,r),["stop"])},null,40,$n)):e.createCommentVNode("",!0),r.image&&y.value===r.id&&f.value!==r.id?(e.openBlock(),e.createElementBlock("button",{key:7,class:"zm-img-remove-btn",title:"移除图片",onMousedown:n[12]||(n[12]=e.withModifiers(()=>{},["stop"])),onClick:e.withModifiers(x=>F(r.id),["stop"])},[e.createVNode(R,{name:"x",size:9,stroke:2.2})],40,Rn)):e.createCommentVNode("",!0)],46,Mn))),128))],4),C.value?(e.openBlock(),e.createBlock(wn,{key:1,x:C.value.x,y:C.value.y,container:u.value,"has-image":!!((a=e.unref(S)(s.value,C.value.nodeId))!=null&&a.image),"has-link":!!((h=e.unref(S)(s.value,C.value.nodeId))!=null&&h.link),"has-note":!!((m=e.unref(S)(s.value,C.value.nodeId))!=null&&m.note),readonly:i.readonly,onPickImage:j,onRemoveImage:Pn,onSetLink:G,onRemoveLink:me,onEditNote:be,onRemoveNote:he,onClose:X},null,8,["x","y","container","has-image","has-link","has-note","readonly"])):e.createCommentVNode("",!0)],544),i.previewMode?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",Ln,[e.createElementVNode("button",{class:"zm-tb-btn",title:"放大",onClick:n[15]||(n[15]=(...r)=>e.unref(M).zoomIn&&e.unref(M).zoomIn(...r))},[e.createVNode(R,{name:"zoom-in"})]),e.createElementVNode("button",{class:"zm-tb-btn",title:"缩小",onClick:n[16]||(n[16]=(...r)=>e.unref(M).zoomOut&&e.unref(M).zoomOut(...r))},[e.createVNode(R,{name:"zoom-out"})]),e.createElementVNode("button",{class:"zm-tb-btn",title:"重置视图",onClick:te},[e.createVNode(R,{name:"reset"})]),n[22]||(n[22]=e.createElementVNode("span",{class:"zm-tb-divider"},null,-1)),o.readonly?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("button",{key:0,class:"zm-tb-btn",title:"添加子节点 (Tab)",onClick:n[17]||(n[17]=r=>y.value&&ge(y.value))},[e.createElementVNode("img",{src:e.unref(Dt),width:"14",height:"14",alt:"添加子节点",draggable:"false"},null,8,An)])),o.readonly?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("button",{key:1,class:"zm-tb-btn",title:"添加同级 (Enter)",onClick:n[18]||(n[18]=r=>y.value&&$e(y.value))},[e.createElementVNode("img",{src:e.unref(Tt),width:"14",height:"14",alt:"添加同级",draggable:"false"},null,8,Tn)])),n[23]||(n[23]=e.createElementVNode("span",{class:"zm-tb-divider"},null,-1)),e.createElementVNode("button",{class:e.normalizeClass(["zm-tb-btn",{active:E.layoutMode==="mindmap"}]),title:"思维导图布局 (中心辐射)",onClick:n[19]||(n[19]=r=>je("mindmap"))},[e.createVNode(R,{name:"mindmap"})],2),e.createElementVNode("button",{class:e.normalizeClass(["zm-tb-btn",{active:E.layoutMode==="tree"}]),title:"树形布局 (向右展开)",onClick:n[20]||(n[20]=r=>je("tree"))},[e.createVNode(R,{name:"tree"})],2),e.createElementVNode("button",{class:e.normalizeClass(["zm-tb-btn",{active:E.layoutMode==="org"}]),title:"组织结构布局 (向下展开)",onClick:n[21]||(n[21]=r=>je("org"))},[e.createVNode(R,{name:"org"})],2),n[24]||(n[24]=e.createElementVNode("span",{class:"zm-tb-divider"},null,-1)),o.readonly?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("button",{key:2,class:"zm-tb-btn",title:"导入 JSON",onClick:yo},[e.createVNode(R,{name:"import"})])),e.createElementVNode("button",{class:"zm-tb-btn",title:"导出 JSON",onClick:xo},[e.createVNode(R,{name:"export"})]),e.createElementVNode("span",Dn,e.toDisplayString(Math.round(e.unref(M).scale.value*100))+"%",1)]))],4)}}}),Hn={install(o){o.component("FlowMindMap",rt)}};L.MindMap=rt,L.addChild=nt,L.addSibling=ot,L.clone=_,L.default=Hn,L.findNode=S,L.findParent=Y,L.markdownToMindMap=Pe,L.mindMapToMarkdown=ze,L.removeNode=He,L.uid=oe,Object.defineProperties(L,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/dist/types.d.ts CHANGED
@@ -171,6 +171,14 @@ export interface MindMapExpose {
171
171
  resetView: () => void;
172
172
  exportData: () => string;
173
173
  importData: (json: string) => boolean;
174
+ /** Serialize the current data tree as markdown. */
175
+ getMarkdown: () => string;
176
+ /** Replace the data tree with the result of parsing `md`. The
177
+ * `emitMarkdownChange` flag (default true) controls whether the
178
+ * change is also echoed via `markdownChange` — set false to
179
+ * avoid feedback loops when the host just wrote back the
180
+ * value the component emitted. */
181
+ setMarkdown: (md: string, emitMarkdownChange?: boolean) => void;
174
182
  setBalanced: (value: boolean) => void;
175
183
  isBalanced: () => boolean;
176
184
  balance: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flow-mindmap",
3
- "version": "0.1.0-beta.1",
3
+ "version": "0.1.1-beta.1",
4
4
  "description": "A modern, minimalist mind mapping tool — xmind-style, embeddable as a Vue component.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",