import{k as O,j as x,t as Q,m as v,n as z,p as i,f as y,i as $,v as M,A as m,x as w,s as V,w as T,S as C}from"./web.Os7kOAdY.js";import{g as I,t as W}from"./i18n-runtime._BAkvU05.js";var X=m("<input class=tool-input maxlength=1 style=width:60px>"),Y=m('<img style="width:200px;height:200px;border-radius:12px;border:1px solid var(--border)">'),Z=m("<div style=display:flex;gap:12px;justify-content:center><button class=tool-btn></button><button class=tool-btn>"),tt=m("<div class=tool-container><div style=display:flex;flex-wrap:wrap;gap:12px;margin-bottom:16px;align-items:center><select class=tool-select><option value=pixel></option><option value=gradient></option><option value=letter></option></select><!$><!/><select class=tool-select><option value=128>128px</option><option value=256>256px</option><option value=512>512px</option></select><button class=tool-btn></button></div><div style=text-align:center;margin-bottom:16px></div><!$><!/>"),et=m("<p style=color:var(--text-2)>");function at(){const[U,E]=x(I(),{equals:!1}),f=e=>W(e,U());Q(()=>{const e=t=>{const n=t.detail?.locale;n&&E(n)};window.addEventListener("taitan:locale-change",e),E(I()),V(()=>window.removeEventListener("taitan:locale-change",e))});const[b,D]=x("pixel"),[L,j]=x("A"),[_,G]=x(256),[p,S]=x(null);function u(){const e=Math.floor(Math.random()*360),t=50+Math.floor(Math.random()*40),n=40+Math.floor(Math.random()*30);return`hsl(${e},${t}%,${n}%)`}function N(){const e=document.createElement("canvas"),t=_();e.width=t,e.height=t;const n=e.getContext("2d"),r=8,s=t/r,c=[u(),u(),"#ffffff","transparent"],g=Math.ceil(r/2),d=[];for(let o=0;o<r;o++){d[o]=[];for(let l=0;l<g;l++)d[o][l]=c[Math.floor(Math.random()*c.length)];for(let l=g;l<r;l++)d[o][l]=d[o][r-1-l]}n.fillStyle="#f0f0f0",n.fillRect(0,0,t,t);for(let o=0;o<r;o++)for(let l=0;l<r;l++)d[o][l]!=="transparent"&&(n.fillStyle=d[o][l],n.fillRect(l*s,o*s,s,s));S(e.toDataURL("image/png"))}function q(){const e=document.createElement("canvas"),t=_();e.width=t,e.height=t;const n=e.getContext("2d"),r=u(),s=u(),c=Math.random()*Math.PI*2,g=n.createLinearGradient(t/2+Math.cos(c)*t/2,t/2+Math.sin(c)*t/2,t/2-Math.cos(c)*t/2,t/2-Math.sin(c)*t/2);g.addColorStop(0,r),g.addColorStop(1,s),n.beginPath(),n.arc(t/2,t/2,t/2,0,Math.PI*2),n.fillStyle=g,n.fill(),S(e.toDataURL("image/png"))}function B(){const e=document.createElement("canvas"),t=_();e.width=t,e.height=t;const n=e.getContext("2d");n.fillStyle=u(),n.beginPath(),n.arc(t/2,t/2,t/2,0,Math.PI*2),n.fill(),n.fillStyle="#ffffff",n.font=`bold ${t*.5}px Arial, sans-serif`,n.textAlign="center",n.textBaseline="middle",n.fillText((L()||"A").charAt(0).toUpperCase(),t/2,t/2+t*.03),S(e.toDataURL("image/png"))}function k(){const e=b();e==="pixel"?N():e==="gradient"?q():B()}function H(){if(!p())return;const e=document.createElement("a");e.download=`avatar-${b()}.png`,e.href=p(),e.click()}return(()=>{var e=v(tt),t=e.firstChild,n=t.firstChild,r=n.firstChild,s=r.nextSibling,c=s.nextSibling,g=n.nextSibling,[d,o]=z(g.nextSibling),l=d.nextSibling,A=l.nextSibling,P=t.nextSibling,F=P.nextSibling,[J,K]=z(F.nextSibling);return n.addEventListener("change",a=>D(a.currentTarget.value)),i(r,()=>f("像素风格")),i(s,()=>f("渐变圆形")),i(c,()=>f("字母头像")),i(t,y(C,{get when(){return b()==="letter"},get children(){var a=v(X);return a.$$input=h=>j(h.currentTarget.value),$(()=>T(a,"placeholder",f("字母"))),$(()=>w(a,"value",L())),M(),a}}),d,o),l.addEventListener("change",a=>G(parseInt(a.currentTarget.value))),A.$$click=k,i(A,()=>f("随机生成")),i(P,y(C,{get when(){return p()},get fallback(){return(()=>{var a=v(et);return i(a,()=>f('点击"随机生成"创建头像')),a})()},get children(){var a=v(Y);return $(()=>T(a,"src",p())),a}})),i(e,y(C,{get when(){return p()},get children(){var a=v(Z),h=a.firstChild,R=h.nextSibling;return h.$$click=k,i(h,()=>f("再来一个")),R.$$click=H,i(R,()=>f("下载")),M(),a}}),J,K),$(()=>w(n,"value",b())),$(()=>w(l,"value",_())),M(),e})()}O(["input","click"]);export{at as default};
