import{k as se,j as x,t as ce,g as fe,m as S,n as h,p as s,f as E,i as $,v as C,B as de,A as L,x as y,s as pe,F as ge,w as W,q,S as I}from"./web.Os7kOAdY.js";import{g as B,t as ue}from"./i18n-runtime._BAkvU05.js";var D=L("<input class=tool-input>"),me=L("<button class=tool-btn>"),$e=L('<div class=tool-container><div style=display:flex;flex-wrap:wrap;gap:12px;margin-bottom:16px><label class=tool-btn style=cursor:pointer><!$><!/><input type=file accept=image/* style=display:none></label><select class=tool-select></select><label style=font-size:13px;display:flex;align-items:center;gap:4px><!$><!/><input type=range min=16 max=80><!$><!/></label></div><div class=mobile-stack-grid style="display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-bottom:16px"><!$><!/><!$><!/></div><div style=text-align:center;margin-bottom:16px;background:#222;padding:16px;border-radius:8px><canvas style=max-width:100%;height:auto></canvas></div><!$><!/>'),be=L("<option>");const xe=[{id:"top-bottom",label:"上下文字"},{id:"top-only",label:"仅顶部文字"},{id:"bottom-only",label:"仅底部文字"},{id:"caption",label:"图下加字"},{id:"speech",label:"对话气泡"}];function ve(){const[N,F]=x(B(),{equals:!1}),_=t=>ue(t,N());ce(()=>{const t=a=>{const l=a.detail?.locale;l&&F(l)};window.addEventListener("taitan:locale-change",t),F(B()),pe(()=>window.removeEventListener("taitan:locale-change",t))});const[w,U]=x(null),[f,j]=x(""),[b,G]=x(""),[d,J]=x("top-bottom"),[T,K]=x(36);let c;function O(t){const a=t.target.files?.[0];if(!a)return;const l=new FileReader;l.onload=()=>U(l.result),l.readAsDataURL(a)}function Q(){if(!c||!w())return;const t=new Image;t.onload=()=>{const a=d(),l=t.naturalWidth,A=a==="caption"?80:0,v=t.naturalHeight+A;c.width=l,c.height=v;const e=c.getContext("2d");a==="caption"&&(e.fillStyle="#ffffff",e.fillRect(0,0,l,v)),e.drawImage(t,0,0);const o=T();e.font=`bold ${o}px Impact, Arial, sans-serif`,e.textAlign="center",e.lineWidth=o/10,e.strokeStyle="#000",e.fillStyle="#fff";const p=(r,i,g)=>{e.strokeText(r,i,g),e.fillText(r,i,g)};if((a==="top-bottom"||a==="top-only")&&f()&&p(f(),l/2,o+10),(a==="top-bottom"||a==="bottom-only")&&b()&&p(b(),l/2,t.naturalHeight-15),a==="caption"&&(e.fillStyle="#000",e.strokeStyle="transparent",e.font=`bold ${o*.7}px Arial, sans-serif`,b()&&e.fillText(b(),l/2,t.naturalHeight+50)),a==="speech"&&f()){const r=e.measureText(f()).width+40,i=o+20,g=l/2-r/2,u=20;e.fillStyle="#fff",e.beginPath(),e.roundRect(g,u,r,i,12),e.fill(),e.strokeStyle="#000",e.lineWidth=2,e.stroke(),e.fillStyle="#fff",e.beginPath(),e.moveTo(l/2-10,u+i),e.lineTo(l/2,u+i+15),e.lineTo(l/2+10,u+i),e.closePath(),e.fill(),e.stroke(),e.fillStyle="#000",e.font=`bold ${o*.7}px Arial, sans-serif`,e.fillText(f(),l/2,u+i/2+o*.25)}},t.src=w()}fe(()=>{w(),f(),b(),d(),T(),Q()});function V(){if(!c)return;const t=document.createElement("a");t.download="meme.png",t.href=c.toDataURL("image/png"),t.click()}return(()=>{var t=S($e),a=t.firstChild,l=a.firstChild,A=l.firstChild,[v,e]=h(A.nextSibling),o=v.nextSibling,p=l.nextSibling,r=p.nextSibling,i=r.firstChild,[g,u]=h(i.nextSibling),R=g.nextSibling,X=R.nextSibling,[Y,Z]=h(X.nextSibling),k=a.nextSibling,ee=k.firstChild,[P,te]=h(ee.nextSibling),le=P.nextSibling,[ne,ae]=h(le.nextSibling),H=k.nextSibling,M=H.firstChild,ie=H.nextSibling,[oe,re]=h(ie.nextSibling);s(l,()=>_("上传底图"),v,e),o.addEventListener("change",O),p.addEventListener("change",n=>J(n.currentTarget.value)),s(p,E(ge,{each:xe,children:n=>(()=>{var m=S(be);return s(m,()=>n.label),$(()=>y(m,"value",n.id)),m})()})),s(r,()=>_("字号:"),g,u),R.$$input=n=>K(parseInt(n.currentTarget.value)),s(r,T,Y,Z),s(k,E(I,{get when(){return q(()=>d()!=="bottom-only")()&&d()!=="caption"},get children(){var n=S(D);return n.$$input=m=>j(m.currentTarget.value),$(()=>W(n,"placeholder",_("顶部文字"))),$(()=>y(n,"value",f())),C(),n}}),P,te),s(k,E(I,{get when(){return q(()=>d()!=="top-only")()&&d()!=="speech"},get children(){var n=S(D);return n.$$input=m=>G(m.currentTarget.value),$(()=>W(n,"placeholder",_("底部文字"))),$(()=>y(n,"value",b())),C(),n}}),ne,ae);var z=c;return typeof z=="function"?de(z,M):c=M,s(t,E(I,{get when(){return w()},get children(){var n=S(me);return n.$$click=V,s(n,()=>_("下载表情包")),C(),n}}),oe,re),$(()=>y(p,"value",d())),$(()=>y(R,"value",T())),C(),t})()}se(["input","click"]);export{ve as default};
