import{k as He,j as H,t as Ne,h as te,m as I,n as v,p as l,q as De,f as le,i as k,v as Fe,A as Q,w as ie,x as N,s as Ie,e as ne,F as oe}from"./web.Os7kOAdY.js";import{c as Pe}from"./clipboard.BNxbz_oK.js";import{g as se,t as We}from"./i18n-runtime._BAkvU05.js";var ze=Q('<div class=panel style=display:flex;flex-direction:column;gap:14px><div class=tool-grid-2><div class=tool-field><span class=tool-label></span><textarea class=tool-textarea rows=10></textarea></div><div class=tool-field><span class=tool-label></span><textarea class=tool-textarea rows=10></textarea></div></div><div class=tool-actions><label class=tool-chip><input type=checkbox> <!$><!/></label><label class=tool-chip><input type=checkbox> <!$><!/></label><button class=tool-btn></button><button class=tool-btn></button><button class="tool-btn is-ghost"></button><button class="tool-btn is-ghost"></button></div><div class=tool-hint><!$><!/><strong style=color:var(--subtle)></strong> <!$><!/><strong style=color:var(--chart-good)>+<!$><!/></strong> <!$><!/><strong style=color:var(--chart-bad)>−<!$><!/></strong></div><!$><!/>'),Be=Q('<div style="border:1px solid var(--border);border-radius:10px;overflow:hidden;background:var(--surface)"><div class=mobile-stack-split style="display:grid;grid-template-columns:1fr 1fr;gap:0"><div style="border-right:1px solid var(--border)"></div><div>'),ae=Q("<div><span class=diff-ln></span><span style=white-space:pre-wrap;word-break:break-all>");function Ge(L,y){const n=L.length,S=y.length,a=[];for(let r=0;r<=n;r++)a.push(new Array(S+1).fill(0));for(let r=1;r<=n;r++)for(let h=1;h<=S;h++)L[r-1]===y[h-1]?a[r][h]=a[r-1][h-1]+1:a[r][h]=Math.max(a[r-1][h],a[r][h-1]);const f=[];let o=n,s=S;for(;o>0&&s>0;)L[o-1]===y[s-1]?(f.push({op:"eq",ai:o-1,bi:s-1}),o--,s--):a[o-1][s]>=a[o][s-1]?(f.push({op:"del",ai:o-1}),o--):(f.push({op:"add",bi:s-1}),s--);for(;o>0;)f.push({op:"del",ai:o-1}),o--;for(;s>0;)f.push({op:"add",bi:s-1}),s--;return f.reverse()}function Qe(){const[L,y]=H(se(),{equals:!1}),n=t=>We(t,L());Ne(()=>{const t=e=>{const c=e.detail?.locale;c&&y(c)};window.addEventListener("taitan:locale-change",t),y(se()),Ie(()=>window.removeEventListener("taitan:locale-change",t))});const[S,a]=H(""),[f,o]=H(""),[s,r]=H(!1),[h,re]=H(!1),q=te(()=>{const t=$=>{let g=$;return h()&&(g=g.toLowerCase()),s()&&(g=g.replace(/\s+/g," ").trim()),g},e=S().split(`
`),c=f().split(`
`),p=e.map(t),j=c.map(t),u=Ge(p,j),x=[];let d=0;for(;d<u.length;){const $=u[d];if($.op==="eq"){x.push({op:"eq",left:{ln:$.ai+1,text:e[$.ai]},right:{ln:$.bi+1,text:c[$.bi]}}),d++;continue}const g=[],m=[];for(;d<u.length&&u[d].op!=="eq";)u[d].op==="del"?g.push(u[d].ai):m.push(u[d].bi),d++;const W=Math.max(g.length,m.length);for(let E=0;E<W;E++){const _=g[E],w=m[E];_!==void 0&&w!==void 0?x.push({op:"add",left:{ln:_+1,text:e[_]},right:{ln:w+1,text:c[w]}}):_!==void 0?x.push({op:"del",left:{ln:_+1,text:e[_]}}):x.push({op:"add",right:{ln:w+1,text:c[w]}})}}return x}),P=te(()=>{let t=0,e=0,c=0;for(const p of q())p.op==="eq"?c++:p.op==="add"&&p.left&&p.right?(t++,e++):p.op==="add"?t++:p.op==="del"&&e++;return{add:t,del:e,eq:c}}),ce=()=>{a(["function hello(name) {",'  console.log("Hello, " + name);',"  return name;","}"].join(`
`)),o(['function hello(name, greet = "Hi") {',"  console.log(`${greet}, ${name}`);","  return { name };","}"].join(`
`))},de=()=>{const t=["--- a","+++ b"];for(const e of q())e.op==="eq"?t.push(" "+(e.left?.text??"")):e.op==="del"?t.push("-"+(e.left?.text??"")):(e.left&&t.push("-"+e.left.text),e.right&&t.push("+"+e.right.text));Pe(t.join(`
`))};return(()=>{var t=I(ze),e=t.firstChild,c=e.firstChild,p=c.firstChild,j=p.nextSibling,u=c.nextSibling,x=u.firstChild,d=x.nextSibling,$=e.nextSibling,g=$.firstChild,m=g.firstChild,W=m.nextSibling,E=W.nextSibling,[_,w]=v(E.nextSibling),z=g.nextSibling,B=z.firstChild,ge=B.nextSibling,he=ge.nextSibling,[pe,fe]=v(he.nextSibling),G=z.nextSibling,D=G.nextSibling,J=D.nextSibling,U=J.nextSibling,T=$.nextSibling,$e=T.firstChild,[V,be]=v($e.nextSibling),X=V.nextSibling,ue=X.nextSibling,xe=ue.nextSibling,[Y,_e]=v(xe.nextSibling),K=Y.nextSibling,ve=K.firstChild,Se=ve.nextSibling,[me,we]=v(Se.nextSibling),Ce=K.nextSibling,ke=Ce.nextSibling,[Z,ye]=v(ke.nextSibling),ee=Z.nextSibling,qe=ee.firstChild,Ee=qe.nextSibling,[Le,je]=v(Ee.nextSibling),Te=T.nextSibling,[Me,Re]=v(Te.nextSibling);return l(p,()=>n("原文（左）")),j.$$input=i=>a(i.currentTarget.value),l(x,()=>n("新文（右）")),d.$$input=i=>o(i.currentTarget.value),m.addEventListener("change",i=>r(i.currentTarget.checked)),l(g,()=>n("忽略空白"),_,w),B.addEventListener("change",i=>re(i.currentTarget.checked)),l(z,()=>n("忽略大小写"),pe,fe),G.$$click=()=>{const i=S();a(f()),o(i)},l(G,()=>n("↔ 交换")),D.$$click=de,l(D,()=>n("复制 patch")),J.$$click=ce,l(J,()=>n("示例")),U.$$click=()=>{a(""),o("")},l(U,()=>n("清空")),l(T,()=>n("相同"),V,be),l(X,()=>P().eq),l(T,()=>n("行 · 新增"),Y,_e),l(K,()=>P().add,me,we),l(T,()=>n("· 删除"),Z,ye),l(ee,()=>P().del,Le,je),l(t,(()=>{var i=De(()=>q().length>0);return()=>i()&&(()=>{var M=I(Be),F=M.firstChild,R=F.firstChild,Ae=R.nextSibling;return l(R,le(oe,{get each(){return q()},children:b=>(()=>{var C=I(ae),A=C.firstChild,O=A.nextSibling;return l(A,()=>b.left?.ln??""),l(O,()=>b.left?.text??""),k(()=>ne(C,`diff-row ${b.op==="del"||b.op==="add"&&b.left&&b.right?"is-del":""}`)),C})()})),l(Ae,le(oe,{get each(){return q()},children:b=>(()=>{var C=I(ae),A=C.firstChild,O=A.nextSibling;return l(A,()=>b.right?.ln??""),l(O,()=>b.right?.text??""),k(()=>ne(C,`diff-row ${b.op==="add"?"is-add":""}`)),C})()})),M})()})(),Me,Re),k(i=>{var M=n("原始文本…"),F=n("对比文本…"),R=!q().length;return M!==i.e&&ie(j,"placeholder",i.e=M),F!==i.t&&ie(d,"placeholder",i.t=F),R!==i.a&&N(D,"disabled",i.a=R),i},{e:void 0,t:void 0,a:void 0}),k(()=>N(j,"value",S())),k(()=>N(d,"value",f())),k(()=>N(m,"checked",s())),k(()=>N(B,"checked",h())),Fe(),t})()}He(["input","click"]);export{Qe as default};
