Skip to content

serejaris/telegram-skills / skills/tg-widgets

tg-widgets

Verified

Use when building or sending a Telegram message widget (HTML bubble, HTMLBubbles, `sendWidget`, `messageMediaWidget`, Bot API 10.4): an interactive HTML, CSS and JS program inside a chat bubble, such as a game, poll, calculator or live ticker. Teaches everything needed to write one: size, bubble, input, sandbox rules, state and requests, sending, and which chats accept a widget in production. Not for Mini Apps or Rich Messages.

examples/night-deploy-textmode.html

View on GitHub
<style>body{margin:0}canvas{display:block;width:100%;touch-action:none}</style><canvas></canvas><script>const e=document.querySelector("canvas"),f=e.getContext("2d"),t=window.TelegramWidget,{sin:l,cos:i,sqrt:r,random:o,min:n,max:c,floor:a,round:s}=Math,y=6.283,x=48,h=[[7,40,7,"ж","#f22","#fff"],[5,88,4,"x","#f0f","#fff"],[11,30,28,"Ж","#7f3","#000"],[13,26,80,"Ф","#000","#f22"],[32,36,300,"#","#f22","#fff"]],p=[...h.map(e=>[e[4],e[5]]),["#fff","#f22"],["#fff","#000"],["#f22","#fff"],["#fff","#00f"],["","#fff"],["#0ff","#000"],["","#fff"],["","#0ff"],["","#0ff"]],m=p.map(()=>[]),u=["#########","П Р О Д !","#########"],g=["Регресс","Гонка","Утечка"],d=[["Промпт","Больше снарядов"],["Коммит","Кружат и бьют"],["Откат","Волна отбрасывает орду"],["Ревью","Молния по багам"],["Кофе","Ходишь быстрее"],["Контекст","Притягивает опыт"],["Поспать","+30 здоровья и лечение"]],S=[],z=new Int32Array(624);for(let e=0;16>e;e++){let f="";for(let e=0;64>e;e++)f+=.05>o()?".:"[2*o()|0]:" ";S[e]=f+f.slice(0,x)}let v,w,R,k,b,T,q,A,I,O,j,C,E,F,W,B,J,M,N,P,_,H,L,X,Y,D,G,K,Q,U,V,Z,$,ee,fe,te,le,ie,re,oe,ne,ce=0,ae=-1,se=0,ye=1,xe=0,he=0,pe=[],me=[0,0],ue=0;try{me=JSON.parse(localStorage.getItem("b"))||me}catch{}const ge=e=>t?.HapticFeedback?.impactOccurred(e),de=(e,f=o()*y,t=320,r=E,n=F)=>{let c=h[e],a={x:r+i(f)*t,y:n+l(f)*t,k:e,r:c[0],s:c[1],z:c[2]*(e>3?P:1+T/45),j:o()-.5,a:0,c:0,f:0};return(60>le.length||e>3)&&le.push(a),a},Se=()=>{W=E+12*(ee/k-24-.5),B=F+25*(fe/b-7-.5)},ze=e=>{Y=e,X=2},ve=(e,f)=>{e.z>0&&(e.f=.09,0>=(e.z-=f))&&(C++,re.push({x:e.x,y:e.y,w:e.r/4|0,z:1}),re.length>30&&re.shift())},we=()=>{le=[],ie=[],re=[],pe=[],T=O=C=E=F=W=B=J=_=G=U=V=X=L=P=$=H=0,q=A=100,I=1,j=4,M=16,N=60,K=Q=2,D=[1,0,0,0,0,0,0];for(let e=0;8>e;e++)de(0,.8*e,240)},Re=e=>s(e*k),ke=e=>s(e*b),be=(e,t,l,i,r)=>{f.fillStyle=r,f.fillRect(Re(e),ke(t),Re(e+l)-Re(e),ke(t+i)-ke(t))},Te=(e,t,l,i)=>{be(e,t,l,i,"#000"),f.fillStyle="#fff",f.fillRect(Re(e)+1,ke(t)+1,Re(e+l)-Re(e)-2,ke(t+i)-ke(t)-2)},qe=(e,t,l,i="#000")=>{f.fillStyle=i;for(let i=0;e.length>i;i++)" "!=e[i]&&f.fillText(e[i],(t+i+.5)*k,(l+.5)*b)},Ae=e=>(e/60|0)+":"+("0"+(e%60|0)).slice(-2),Ie=(e,f,t,l)=>{let i=f*x+e;e>=0&&x>e&&f>0&&13>f&&z[i]!=ue&&(z[i]=ue,m[l].push(e,f,t))},Oe=(e,f,t,l)=>Ie(a(e/12+.5)-oe+24,a(f/25+.5)-ne+7,t,l),je=(e,t,l,i)=>{be(e,.2,t,.6,"#000"),f.fillStyle=i,f.fillRect(Re(e)+1,ke(.2)+1,(Re(e+t)-Re(e)-2)*n(c(l,0),1),ke(.8)-ke(.2)-2)},Ce=()=>{ue++,oe=a(E/12+.5),ne=a(F/25+.5),f.fillStyle="#00f",f.fillRect(0,0,v,w),f.fillStyle="#fff";for(let e=1;13>e;e++)f.fillText(S[ne+e&15].substr(63&oe,x),v/2,(e+.5)*b);let e=J>0&&8*xe&1?7:6;Ie(24,7,">",e),Ie(25,7,"_",e);for(let e of le)if(e.k>3){let f=a(e.x/12+.5)-oe+24,t=a(e.y/25+.5)-ne+7;for(let l=0;3>l;l++)for(let i=0;9>i;i++)Ie(f+i-4,t+l-1,u[l][i],e.f>0?5:4)}for(let e=0;D[1]>e;e++){let f=V+e*y/D[1];Oe(E+56*i(f),F+56*l(f),"@",8)}for(let e of ie)Oe(e.x,e.y,"*",9);for(let e of le)4>e.k&&Oe(e.x,e.y,h[e.k][3],e.f>0?5:e.k);if(U>0)for(let e=0;14>e;e++){let f=e*y/14,t=(95+16*D[2])*(1-U/.35);Oe(E+i(f)*t,F+l(f)*t,"o",11)}for(let e of pe)for(let f=1;7>f;f++)Oe(E+(e.x-E)*f/7,F+(e.y-F)*f/7,"~",12);for(let e of re)Oe(e.x,e.y,"+",10);var t;1==ce&&Oe(W,B,"o",13),m.forEach((e,t)=>{if(e.length){if(p[t][0]){f.fillStyle=p[t][0];for(let t=0;e.length>t;t+=3)f.fillRect(Re(e[t]),ke(e[t+1]),Re(e[t]+1)-Re(e[t]),ke(e[t+1]+1)-ke(e[t+1]))}f.fillStyle=p[t][1];for(let t=0;e.length>t;t+=3)f.fillText(e[t+2],(e[t]+.5)*k,(e[t+1]+.5)*b);e.length=0}}),Te(0,0,x,1),2==ce?(qe("Уровень "+I+": выбери улучшение",1,0),Z.forEach((e,f)=>{let t=d[e],l=1+4*f,i=4>e;Te(1,l,46,3),be(1,l,5,3,i?"#f0f":"#7f3"),qe(t[0][0],3,l+1,i?"#fff":"#000"),qe(t[0]+" "+(D[e]+1),7,l+.5),qe(t[1],7,l+1.5)})):(qe("ур."+I,1,0),je(7,11,q/A,"#f22"),qe(Ae(T),20,0),je(26,9,O/j,"#0ff"),qe("баг "+C,37,0),H&&(f.fillStyle="#f22",f.fillRect(0,ke(1),v*H.z/(300*P),3)),X>0&&(Te(24-Y.length/2-1,1,Y.length+2,1),qe(Y,24-Y.length/2,1))),0!=ce&&3!=ce||(Te(4,1,40,11),be(5,2,38,1,ce?"#f22":"#000"),ce?(qe("Орда победила",17.5,2,"#fff"),qe("Время "+Ae(T)+", багов "+C,7,4)):(qe("Ночной деплой >_",16,2,"#fff"),qe("Вайбкодер против багов",7,4),qe("Тап: идёт туда. Палец: идёт за ним",7,5)),me[0]&&qe("Рекорд "+Ae(me[0])+", багов "+me[1],7,7),t=ce?"Ещё раз":"В бой",be(6,9,36,2,"#f0f"),qe(t,24-t.length/2,9.5,"#fff"))},Ee=e=>{requestAnimationFrame(Ee);let f=e-he;if(f>=60){if(he=e,xe+=f/1e3,1==ce)(e=>{let f,t,a,s,x,h=300,p=D[2]&&0>(K-=e);if(T+=e,J-=e,X-=e,U-=e,V+=3.2*e,_-=e,$&&Se(),f=W-E,t=B-F,a=r(f*f+t*t),a&&(s=n(a,(100+14*D[4])*e)/a,E+=f*s,F+=t*s),0>_&&(_=c(.09,.4/(1+T/20))*(H?1.6:1),de(o()*o()*n(T/14,4)|0)),T>M){M+=15,f=L++%3,s=(10+T/4)/(f+1);for(let e=0;s>e;e++)de(f,e*y/s);ze(g[f])}T>N&&(N+=60,P++,H=de(4),ze("Прод упал!")),p&&(K=6-.6*D[2],U=.35);for(let o of le){f=E-o.x,t=F-o.y;let s=r(f*f+t*t)||1,m=o.u=f/s,u=o.v=t/s;if(o.f-=e,o.c-=e,o.a+=10*e,s>400)o.x+=1.6*f,o.y+=1.6*t;else{if(o.x+=(m-u*o.j)*o.s*e,o.y+=(u+m*o.j)*o.s*e,h>s&&(h=s,x=o),o.r+9>s&&0>=J&&(q-=6+o.r/2|0,J=.6,ge("medium"),0>=q)){ce=3,ae=xe,ye=1,$=0,me=[c(T,me[0]),c(C,me[1])];try{localStorage.setItem("b",JSON.stringify(me))}catch{}}if(p&&95+16*D[2]>s&&(ve(o,6+5*D[2]),o.x-=46*m,o.y-=46*u),0>o.c)for(let e=0;D[1]>e;e++)a=V+e*y/D[1],f=E+56*i(a)-o.x,t=F+56*l(a)-o.y,(o.r+12)**2>f*f+t*t&&(ve(o,5+3*D[1]),o.c=.3);if(o.k>3&&(o.x=c(E-170,n(E+170,o.x)),o.y=c(F-100,n(F+85,o.y)),o.a>25)){o.a=0;for(let e=0;6+2*P>e;e++)de(1,e,40,o.x,o.y)}}}if(0>(G-=e)&&x){G=.62-.05*D[0],H&&.5>o()&&(x=H),s=1+(D[0]>>1);for(let e=0;s>e;e++)t=.2*(e-(s-1)/2),ie.push({x:E,y:F,u:220*(x.v*t-x.u),v:220*(-x.u*t-x.v),z:1.2,p:D[0]>>2})}if(pe=[],D[3]&&0>(Q-=e)){Q=2-.15*D[3];for(let e=0;D[3]>=e;e++){let e=le[o()*le.length|0];e&&(ve(e,12+7*D[3]),pe.push(e))}}for(let l of ie){l.x+=l.u*e,l.y+=l.v*e,l.z-=e;for(let e of le)f=l.x-e.x,t=l.y-e.y,l.z>0&&(e.r+10)**2>f*f+t*t&&(ve(e,5+3*D[0]),0>--l.p&&(l.z=0))}a=(50+32*D[5])**2;for(let l of re)f=E-l.x,t=F-l.y,s=f*f+t*t,a>s&&(l.m=1),l.m&&(s=r(s)||1,l.x+=f/s*280*e,l.y+=t/s*280*e,14>s&&(l.z=0,O+=l.w));H&&0>=H.z&&(H=0,q=n(A,q+25),O+=20,ze("Хотфикс!")),[le,ie,re]=[le,ie,re].map(e=>e.filter(e=>e.z>0)),1!=ce||j>O||(O-=j,I++,j=I*I/8+2*I+3|0,Z=[0,1,2,3,4,5,6].filter(e=>4>e||I>2).sort(()=>o()-.5).slice(0,3),ce=2,ae=xe,ye=1,$=0)})(n(f,100)/1e3);else if(!ye)return;ye=0,Ce()}},Fe=e=>{ee=e.clientX-te.left,fe=e.clientY-te.top},We=(f,t)=>e.addEventListener(f,t),Be=()=>{v=e.clientWidth||390,w=s(9*v/16),R=n(devicePixelRatio||1,2),e.style.height=w+"px",e.width=v*R,e.height=w*R,f.setTransform(R,0,0,R,0,0),k=v/x,b=w/13,f.font="700 14px ui-monospace,monospace",f.font="700 "+n(14*k/f.measureText("M").width,.92*b)+"px ui-monospace,monospace",f.textBaseline="middle",f.textAlign="center",ye=1};We("pointerdown",f=>{se=xe,te=e.getBoundingClientRect(),1==ce&&(Fe(f),Se(),$=1,e.setPointerCapture(f.pointerId))}),We("pointermove",e=>{$&&Fe(e)}),We("pointerup",()=>{$=0}),We("pointercancel",()=>{$=0,W=E,B=F}),We("click",e=>{if(1==ce||.3>se-ae)return;Fe(e);let f=fe/b;if(2==ce){let e=Z[a((f-1)/4)];e+1&&(D[e]++,6==e&&(q=A+=30),ce=1,ge("light"))}else f>8&&(we(),ce=1)}),new ResizeObserver(()=>{e.clientWidth!=v&&Be()}).observe(e),Be(),we(),Ce(),t?.ready(),requestAnimationFrame(Ee);
</script>
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 322kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 198kUpdated Claude CodeCodexVerifiedInstall