import{k as ot,j as I,t as st,h as O,m as y,p as v,q as at,n as U,w as d,i as E,v as ct,A as b,x as ht,s as dt}from"./web.Os7kOAdY.js";import{g as W,t as Y}from"./i18n-runtime._BAkvU05.js";var ut=b(`<div class=panel style=display:flex;flex-direction:column;gap:16px><div style=display:flex;flex-direction:column;gap:6px><label style=font-size:13px;font-weight:600;color:var(--text)></label><textarea rows=10 style="width:100%;padding:12px;border:1px solid var(--border);border-radius:8px;font-size:13px;font-family:'JetBrains Mono',ui-monospace,monospace;line-height:1.6;background:var(--surface);color:var(--text);resize:vertical;outline:none;tab-size:2"></textarea><span style=font-size:11px;color:var(--muted)></span></div><div style="border:1px solid var(--border);border-radius:12px;overflow:auto;background:var(--surface-soft);max-height:500px"></div><div class=tool-hint style=font-size:12px;color:var(--muted)>`),ft=b("<svg style=display:block;min-width:100%><!$><!/><!$><!/>"),vt=b("<svg><path fill=none stroke=#94a3b8 stroke-width=1.5 opacity=0.6></svg>",!1,!0,!1),gt=b('<svg><g><rect rx=6 ry=6 opacity=0.9></rect><text text-anchor=middle dominant-baseline=middle fill=#fff font-size=12 font-family="system-ui, sans-serif"></svg>',!1,!0,!1),xt=b("<div style=padding:40px;text-align:center;color:var(--muted);font-size:14px>");const D=`思维导图
	工作
		项目A
			任务1
			任务2
		项目B
	学习
		编程
			Rust
			TypeScript
		数学
	生活
		运动
		阅读`;function yt(){const[F,H]=I(W(),{equals:!1}),$=t=>Y(t,F()),[T,S]=I(D);let M=D;st(()=>{const t=e=>{const n=e.detail?.locale;if(n){H(n);const r=D.split(`
`).map(l=>(l.match(/^\s*/)?.[0]??"")+Y(l.trim(),n)).join(`
`);T()===M&&S(r),M=r}};window.addEventListener("taitan:locale-change",t),H(W()),dt(()=>window.removeEventListener("taitan:locale-change",t))});const J=t=>{const e=t.split(`
`).filter(l=>l.trim());if(e.length===0)return null;const n={text:e[0].trim(),children:[],x:0,y:0,width:0,height:0},r=[{node:n,level:-1}];for(let l=1;l<e.length;l++){const o=e[l],h=o.match(/^(\t*)/),s=h?h[1].length:0,i=o.trim();if(!i)continue;const u={text:i,children:[],x:0,y:0,width:0,height:0};for(;r.length>1&&r[r.length-1].level>=s;)r.pop();r[r.length-1].node.children.push(u),r.push({node:u,level:s})}return n},g=30,V=12,z=8,K=40,Q=8,Z=t=>{let e=0;for(const n of t)e+=n.charCodeAt(0)>127?14:Q;return e+V*2},A=(t,e,n)=>{if(t.width=Z(t.text),t.height=g,t.x=e,t.children.length===0)return t.y=n,{totalHeight:g};const r=e+t.width+K;let l=n,o=0;for(let i=0;i<t.children.length;i++){const u=A(t.children[i],r,l);l+=u.totalHeight+z,o+=u.totalHeight+(i>0?z:0)}const h=t.children[0],s=t.children[t.children.length-1];return t.y=(h.y+s.y+s.height)/2-g/2,{totalHeight:Math.max(g,o)}},N=(t,e=[])=>{e.push(t);for(const n of t.children)N(n,e);return e},f=O(()=>{const t=J(T());if(!t)return{nodes:[],root:null,width:0,height:0};const{totalHeight:e}=A(t,20,20),n=N(t),r=Math.max(...n.map(o=>o.x+o.width))+40,l=Math.max(...n.map(o=>o.y+o.height))+40;return{nodes:n,root:t,width:r,height:Math.max(l,e+40)}}),L=t=>{const e=[];for(const n of t.children){const r=t.x+t.width,l=t.y+g/2,o=n.x,h=n.y+g/2,s=(r+o)/2;e.push(`M ${r} ${l} C ${s} ${l}, ${s} ${h}, ${o} ${h}`),e.push(...L(n))}return e},tt=O(()=>{const{root:t}=f();return t?L(t):[]}),P=["#6366f1","#ec4899","#f59e0b","#10b981","#3b82f6","#8b5cf6","#ef4444","#06b6d4"],et=t=>P[t%P.length],nt=(t,e)=>{const n=(r,l,o)=>{if(r===l)return o;for(const h of r.children){const s=n(h,l,o+1);if(s>=0)return s}return-1};return n(e,t,0)};return(()=>{var t=y(ut),e=t.firstChild,n=e.firstChild,r=n.nextSibling,l=r.nextSibling,o=e.nextSibling,h=o.nextSibling;return v(n,()=>$("输入文本（用 Tab 缩进表示层级）")),r.$$keydown=s=>{if(s.key==="Tab"){s.preventDefault();const i=s.currentTarget,u=i.selectionStart,w=i.selectionEnd,_=i.value;i.value=_.substring(0,u)+"	"+_.substring(w),i.selectionStart=i.selectionEnd=u+1,S(i.value)}},r.$$input=s=>S(s.currentTarget.value),v(l,()=>$("提示：按 Tab 键插入缩进，每多一级 Tab 表示子节点")),v(o,(()=>{var s=at(()=>!!f().root);return()=>s()?(()=>{var i=y(ft),u=i.firstChild,[w,_]=U(u.nextSibling),it=w.nextSibling,[rt,lt]=U(it.nextSibling);return v(i,()=>tt().map(a=>(()=>{var x=y(vt);return d(x,"d",a),x})()),w,_),v(i,()=>f().nodes.map(a=>{const x=nt(a,f().root),C=et(x);return(()=>{var p=y(gt),m=p.firstChild,k=m.nextSibling;return d(m,"fill",C),v(k,()=>a.text),E(c=>{var X=a.x,B=a.y,R=a.width,j=a.height,q=a.x+a.width/2,G=a.y+g/2+1;return X!==c.e&&d(m,"x",c.e=X),B!==c.t&&d(m,"y",c.t=B),R!==c.a&&d(m,"width",c.a=R),j!==c.o&&d(m,"height",c.o=j),q!==c.i&&d(k,"x",c.i=q),G!==c.n&&d(k,"y",c.n=G),c},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),p})()}),rt,lt),E(a=>{var x=f().width,C=f().height,p=`0 0 ${f().width} ${f().height}`;return x!==a.e&&d(i,"width",a.e=x),C!==a.t&&d(i,"height",a.t=C),p!==a.a&&d(i,"viewBox",a.a=p),a},{e:void 0,t:void 0,a:void 0}),i})():(()=>{var i=y(xt);return v(i,()=>$("请在上方输入文本以生成思维导图")),i})()})()),v(h,()=>$("使用 Tab 缩进定义层级关系，自动生成水平树形思维导图。支持多级嵌套。")),E(()=>ht(r,"value",T())),ct(),t})()}ot(["input","keydown"]);export{yt as default};
