import{k as Se,j as S,t as Te,h as W,m as A,n as p,p as i,w as Q,q as xe,i as b,v as V,A as v,e as Ne,x as _,s as Re}from"./web.Os7kOAdY.js";import{c as Ie}from"./clipboard.BNxbz_oK.js";import{g as Y,t as be}from"./i18n-runtime._BAkvU05.js";var me=v(`<div class=tool-card style=padding:20px><div style=display:flex;gap:12px;flex-wrap:wrap;align-items:center;margin-bottom:16px><label style=font-size:13px;font-weight:600></label><select style="padding:6px 10px;border-radius:6px;border:1px solid var(--c-border,#ddd);font-size:13px"><option value=mysql>MySQL</option><option value=postgresql>PostgreSQL</option><option value=sqlite>SQLite</option></select><label style=font-size:13px;font-weight:600;margin-left:12px></label><div style=display:flex;gap:4px></div><button style="margin-left:auto;padding:5px 14px;font-size:12px;border-radius:5px;cursor:pointer;background:var(--c-accent,#4f46e5);color:#fff;border:none"></button></div><div class=mobile-stack-grid style="display:grid;grid-template-columns:1fr 1fr;gap:16px"><div><div style=font-size:12px;font-weight:600;margin-bottom:6px;color:var(--c-muted,#666)></div><textarea style="width:100%;min-height:320px;padding:12px;font-family:'JetBrains Mono',monospace;font-size:13px;line-height:1.6;border:1px solid var(--c-border,#ddd);border-radius:8px;resize:vertical;background:var(--c-surface,#fafafa)"></textarea></div><div><div style=font-size:12px;font-weight:600;margin-bottom:6px;color:var(--c-muted,#666)></div><div style="width:100%;min-height:320px;padding:12px;font-family:'JetBrains Mono',monospace;font-size:13px;line-height:1.6;border:1px solid var(--c-border,#ddd);border-radius:8px;background:#272822;color:#f8f8f2;overflow:auto;white-space:pre-wrap;word-break:break-all"></div></div></div><div style=margin-top:12px;font-size:12px;color:var(--c-muted,#888)><!$><!/><!$><!/> <!$><!/><!$><!/> <!$><!/><!$><!/>`),Oe=v('<button style="padding:5px 12px;font-size:12px;border-radius:5px;cursor:pointer">'),$e=v("<span> <!$><!/><!$><!/>%");const h=["SELECT","FROM","WHERE","JOIN","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","FULL JOIN","CROSS JOIN","ON","AND","OR","NOT","IN","EXISTS","BETWEEN","LIKE","IS","NULL","AS","DISTINCT","ALL","INSERT","INTO","VALUES","UPDATE","SET","DELETE","CREATE","TABLE","ALTER","DROP","INDEX","VIEW","TRIGGER","PROCEDURE","FUNCTION","IF","ELSE","THEN","END","CASE","WHEN","GROUP BY","ORDER BY","HAVING","LIMIT","OFFSET","UNION","UNION ALL","INTERSECT","EXCEPT","ASC","DESC","PRIMARY","KEY","FOREIGN","REFERENCES","CONSTRAINT","DEFAULT","AUTO_INCREMENT","SERIAL","BIGSERIAL","INTEGER","VARCHAR","TEXT","BOOLEAN","DATE","TIMESTAMP","FLOAT","DOUBLE","DECIMAL","WITH","RECURSIVE","RETURNING","CASCADE","RESTRICT","NULLS","FIRST","LAST","OVER","PARTITION BY","ROW_NUMBER","RANK","COUNT","SUM","AVG","MIN","MAX","COALESCE","CAST"],Le=["SELECT","FROM","WHERE","JOIN","LEFT JOIN","RIGHT JOIN","INNER JOIN","OUTER JOIN","FULL JOIN","CROSS JOIN","GROUP BY","ORDER BY","HAVING","LIMIT","OFFSET","UNION","UNION ALL","INTERSECT","EXCEPT","INSERT INTO","VALUES","UPDATE","SET","DELETE FROM","CREATE TABLE","ALTER TABLE","DROP TABLE","ON","AND","OR","WITH","RETURNING"];function Ae(o,t){if(!o.trim())return"";let e=o.replace(/\s+/g," ").trim();for(const l of h){const r=new RegExp(`\\b${l.replace(/ /g,"\\s+")}\\b`,"gi");e=e.replace(r,l)}const c=Le.sort((l,r)=>r.length-l.length).map(l=>l.replace(/ /g,"\\s+"));for(const l of c){const r=new RegExp(`(?<!^)\\s+(?=${l}\\b)`,"gi");e=e.replace(r,`
`)}const m=e.split(`
`),f=[];let E=0;for(const l of m){const r=l.trim();if(!r)continue;const O=(r.match(/\(/g)||[]).length,T=(r.match(/\)/g)||[]).length,g=/^(AND|OR|ON|SET)\b/i.test(r),$=/^(SELECT|FROM|WHERE|JOIN|LEFT JOIN|RIGHT JOIN|INNER JOIN|GROUP BY|ORDER BY|HAVING|LIMIT|OFFSET|UNION|INSERT|UPDATE|DELETE|CREATE|ALTER|DROP|WITH|RETURNING)\b/i.test(r);let x=E;g&&!$&&(x=E+1),f.push("  ".repeat(x)+r),E+=O-T,E<0&&(E=0)}return f.join(`
`)}function _e(o){return o.trim()?o.replace(/--[^\n]*/g,"").replace(/\/\*[\s\S]*?\*\//g,"").replace(/\s+/g," ").trim():""}function ve(o){if(!o.trim())return"";let t=o;for(const e of h){const c=new RegExp(`\\b${e.replace(/ /g,"\\s+")}\\b`,"gi");t=t.replace(c,e)}return t}function he(o){if(!o)return"";let t=o.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");t=t.replace(/('(?:[^'\\]|\\.)*')/g,'<span style="color:#e6db74">$1</span>'),t=t.replace(/\b(\d+(?:\.\d+)?)\b/g,'<span style="color:#ae81ff">$1</span>');for(const e of h){const c=new RegExp(`\\b(${e.replace(/ /g,"\\s+")})\\b`,"g");t=t.replace(c,'<span style="color:#66d9ef;font-weight:600">$1</span>')}return t=t.replace(/(--[^\n]*)/g,'<span style="color:#75715e">$1</span>'),t}const Ce="select u.id, u.name, o.total from users u left join orders o on u.id = o.user_id where u.status = 'active' and o.created_at > '2024-01-01' group by u.id, u.name order by o.total desc limit 20;";function De(){const[o,t]=S(Y(),{equals:!1}),e=a=>be(a,o());Te(()=>{const a=N=>{const u=N.detail?.locale;u&&t(u)};window.addEventListener("taitan:locale-change",a),t(Y()),Re(()=>window.removeEventListener("taitan:locale-change",a))});const[c,m]=S(Ce),[f,E]=S("mysql"),[l,r]=S("format"),[O,T]=S(!1),g=W(()=>{const a=c();switch(l()){case"format":return Ae(a,f());case"minify":return _e(a);case"uppercase":return ve(a);default:return a}}),$=W(()=>he(g())),x=async()=>{await Ie(g()),T(!0),setTimeout(()=>T(!1),1500)};return(()=>{var a=A(me),N=a.firstChild,u=N.firstChild,L=u.nextSibling,C=L.nextSibling,y=C.nextSibling,U=y.nextSibling,w=N.nextSibling,D=w.firstChild,M=D.firstChild,R=M.nextSibling,q=D.nextSibling,F=q.firstChild,X=F.nextSibling,d=w.nextSibling,K=d.firstChild,[J,j]=p(K.nextSibling),Z=J.nextSibling,[P,ee]=p(Z.nextSibling),te=P.nextSibling,ne=te.nextSibling,[B,ie]=p(ne.nextSibling),le=B.nextSibling,[G,re]=p(le.nextSibling),oe=G.nextSibling,ae=oe.nextSibling,[H,se]=p(ae.nextSibling),ce=H.nextSibling,[pe,Ee]=p(ce.nextSibling);return i(u,()=>e("方言：")),L.addEventListener("change",n=>E(n.currentTarget.value)),i(C,()=>e("模式：")),i(y,()=>["format","minify","uppercase"].map(n=>(()=>{var s=A(Oe);return s.$$click=()=>r(n),i(s,n==="format"?"格式化":n==="minify"?"压缩":"大写关键字"),b(()=>Ne(s,l()===n?"btn-primary":"btn-outline")),V(),s})())),U.$$click=x,i(U,()=>O()?"已复制 ✓":"复制结果"),i(M,()=>e("输入 SQL")),R.$$input=n=>m(n.currentTarget.value),Q(R,"spellcheck",!1),i(F,()=>e("输出结果")),i(d,()=>e("输入:"),J,j),i(d,()=>c().length,P,ee),i(d,()=>e("字符 · 输出:"),B,ie),i(d,()=>g().length,G,re),i(d,()=>e("字符"),H,se),i(d,(()=>{var n=xe(()=>l()==="minify"&&c().length>0);return()=>n()&&(()=>{var s=A($e),I=s.firstChild,de=I.nextSibling,[k,ge]=p(de.nextSibling),fe=k.nextSibling,[z,ue]=p(fe.nextSibling);return z.nextSibling,i(s,()=>e("· 压缩率:"),k,ge),i(s,()=>((1-g().length/c().length)*100).toFixed(1),z,ue),s})()})(),pe,Ee),b(n=>{var s=e("粘贴 SQL 语句..."),I=$();return s!==n.e&&Q(R,"placeholder",n.e=s),I!==n.t&&_(X,"innerHTML",n.t=I),n},{e:void 0,t:void 0}),b(()=>_(L,"value",f())),b(()=>_(R,"value",c())),V(),a})()}Se(["click","input"]);export{De as default};
