partycles
Version:
🎉 Delightful particle animations for React
48 lines • 32.4 kB
JavaScript
import b,{useState,useRef,useCallback,useMemo,useEffect}from'react';import {createRoot}from'react-dom/client';/* Partycles - Delightful particle animations for React */
var ue=Object.defineProperty,he=Object.defineProperties;var pe=Object.getOwnPropertyDescriptors;var dt=Object.getOwnPropertySymbols;var ye=Object.prototype.hasOwnProperty,ge=Object.prototype.propertyIsEnumerable;var ft=(t,e,r)=>e in t?ue(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r,A=(t,e)=>{for(var r in e||(e={}))ye.call(e,r)&&ft(t,r,e[r]);if(dt)for(var r of dt(e))ge.call(e,r)&&ft(t,r,e[r]);return t},R=(t,e)=>he(t,pe(e));var o=(t,e)=>Math.random()*(e-t)+t,p=t=>t*Math.PI/180,f=()=>Math.random().toString(36).substring(2,9),x=t=>t[Math.floor(Math.random()*t.length)]||t[0]||"#ffffff",mt=(t,e)=>({position:"absolute",left:`${t.x}px`,top:`${t.y}px`,width:`${t.size}px`,height:`${t.size}px`,transform:`rotate(${t.rotation}deg) translateX(-50%) translateY(-50%)`,opacity:t.opacity,pointerEvents:"none",transition:"none",willChange:"transform, opacity"});var X=class{constructor(e=1e3){this.pool=[];this.created=0;this.maxSize=e;}acquire(){let e=this.pool.pop();return e?(e._pooled=false,e):(this.created++,{id:`p${this.created}`,x:0,y:0,vx:0,vy:0,life:0,opacity:0,size:0,rotation:0,color:"",_pooled:false})}release(e){e._pooled||this.pool.length>=this.maxSize||(e._pooled=true,e.element=void 0,e.config=void 0,this.pool.push(e));}releaseAll(e){e.forEach(r=>this.release(r));}clear(){this.pool=[];}getStats(){return {poolSize:this.pool.length,totalCreated:this.created,maxSize:this.maxSize}}},N=new X;function xe(t){let e=N.acquire();return Object.assign(e,t),t.id||(e.id=`p${Date.now()}-${Math.random().toString(36).substr(2,9)}`),e}function m(t,e){let r=[];for(let n=0;n<t;n++)r.push(xe(e(n)));return r}var be=["#f44336","#e91e63","#9c27b0","#673ab7","#3f51b5","#2196f3","#03a9f4","#00bcd4","#009688","#4caf50","#8bc34a","#cddc39","#ffeb3b","#ffc107","#ff9800","#ff5722"],ut=(t,e)=>{let{particleCount:r=50,startVelocity:n=20,colors:a=be,elementSize:i=20}=e;return m(r,()=>{let s=o(0,360),l=o(n*.5,n),c=x(a);return {id:f(),x:t.x,y:t.y,vx:Math.cos(p(s))*l,vy:Math.sin(p(s))*l-30,life:e.lifetime||150,opacity:1,size:o(i*.7,i*1.5),rotation:o(0,360),color:c}})},ht=t=>{var a,i;let n=((i=(a=t.config)==null?void 0:a.effects)==null?void 0:i.flutter)&&t.life>0?`rotateY(${Math.sin(t.life*.1)*360}deg)`:"";return b.createElement("div",{key:t.id,style:{width:`${t.size}px`,height:`${t.size*.6}px`,backgroundColor:t.color,borderRadius:"3px",boxShadow:"0 2px 4px rgba(0,0,0,0.2)",transform:n}})};var yt=(t,e)=>{let{particleCount:r=35,spread:n=120,startVelocity:a=15,elementSize:i=25,colors:s=["#FFD700","#FFFFFF"]}=e;return m(r,()=>{let l=a/45;return {id:f(),x:t.x+o(-n,n),y:t.y+o(-n,n),vx:o(-3,3)*l,vy:o(-3,3)*l,life:e.lifetime||120,opacity:0,size:o(i*.4,i*1.2),rotation:o(0,360),color:s[Math.floor(Math.random()*s.length)]||s[0]||"#ffffff"}})},gt=t=>{let e=t.opacity;return b.createElement("svg",{key:t.id,width:t.size,height:t.size,viewBox:"0 0 24 24",style:{transform:`scale(${e}) rotate(${t.rotation}deg)`,filter:"drop-shadow(0 0 6px rgba(255, 215, 0, 0.8))"}},b.createElement("path",{d:"M12 0L14.59 8.41L23 11L14.59 13.59L12 22L9.41 13.59L1 11L9.41 8.41L12 0Z",fill:t.color}))};var ve=["#ff1744","#e91e63","#ff4569","#ff6b6b","#ee5a70"],Pt=(t,e)=>{let{particleCount:r=25,startVelocity:n=12,colors:a=ve,elementSize:i=30}=e;return m(r,()=>{let s=o(-45,-135),l=o(n*.7,n*1.3),c=o(-2,2);return {id:f(),x:t.x+o(-10,10),y:t.y,vx:Math.cos(s*Math.PI/180)*l+c,vy:Math.sin(s*Math.PI/180)*l,life:e.lifetime||180,opacity:1,size:o(i*.6,i*1.2),rotation:o(-20,20),color:x(a)}})},bt=t=>{var r,n;let e=(n=(r=t.config)==null?void 0:r.effects)!=null&&n.pulse?1+Math.sin(t.life*.2)*.1:1;return b.createElement("svg",{key:t.id,width:t.size*e,height:t.size*e,viewBox:"0 0 24 24",fill:t.color,style:{filter:`drop-shadow(0 0 ${t.size*.15}px ${t.color})`,transition:"width 0.1s ease-out, height 0.1s ease-out"}},b.createElement("path",{d:"M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"}))};var $e=["#ff0000","#00ff00","#0000ff","#ffff00","#ff00ff","#00ffff","#ffffff"],vt=(t,e)=>{let{particleCount:r=60,startVelocity:n=25,colors:a=$e,elementSize:i=8}=e;return createPooledParticles(r,s=>{let l=360/r*s+o(-5,5),c=o(n*.5,n*1.2),d=x(a);return {id:f(),x:t.x,y:t.y,vx:Math.cos(p(l))*c,vy:Math.sin(p(l))*c-10,life:e.lifetime||140,opacity:1,size:o(i*.6,i*1.4),rotation:0,color:d}})},Ct=t=>b.createElement("div",{key:t.id,style:{width:`${t.size}px`,height:`${t.size}px`,backgroundColor:"#ffffff",borderRadius:"50%",boxShadow:`
0 0 ${t.size}px ${t.color},
0 0 ${t.size*2}px ${t.color},
0 0 ${t.size*3}px ${t.color},
0 0 ${t.size*4}px ${t.color}
`,background:`radial-gradient(circle, #ffffff 0%, ${t.color} 40%, transparent 70%)`}});var ze=["rgba(66, 165, 245, 0.4)","rgba(41, 182, 246, 0.4)","rgba(38, 198, 218, 0.4)","rgba(129, 212, 250, 0.4)"],$t=(t,e)=>{let{particleCount:r=30,spread:n=80,startVelocity:a=8,colors:i=ze,elementSize:s=40}=e;return m(r,()=>({id:f(),x:t.x+o(-n,n),y:t.y,vx:o(-3,3),vy:-o(a*.7,a*1.2),life:e.lifetime||160,opacity:.7,size:o(s*.4,s*1.2),rotation:0,color:i[Math.floor(Math.random()*i.length)]||i[0]||"#ffffff"}))},Ft=t=>b.createElement("div",{key:t.id,style:{width:`${t.size}px`,height:`${t.size}px`,backgroundColor:t.color,borderRadius:"50%",border:"2px solid rgba(255, 255, 255, 0.6)",backgroundImage:"radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.8), transparent)",boxShadow:`
inset 0 0 ${t.size*.3}px rgba(255, 255, 255, 0.4),
0 0 ${t.size*.5}px ${t.color}
`}});var Me=["#FFD700","#FFA500","#FF6347","#FFE4B5"],Mt=(t,e)=>{let{particleCount:r=40,startVelocity:n=18,colors:a=Me,elementSize:i=30}=e;return m(r,()=>{let s=o(0,360),l=o(n*.5,n);return {id:f(),x:t.x,y:t.y,vx:Math.cos(s*Math.PI/180)*l,vy:Math.sin(s*Math.PI/180)*l-15,life:e.lifetime||150,opacity:1,size:o(i*.5,i*1.3),rotation:o(0,360),color:a[Math.floor(Math.random()*a.length)]||a[0]||"#ffffff"}})},wt=t=>b.createElement("svg",{key:t.id,width:t.size,height:t.size,viewBox:"0 0 24 24",fill:t.color,style:{filter:`drop-shadow(0 0 ${t.size*.2}px ${t.color})`}},b.createElement("path",{d:"M12,17.27L18.18,21L16.54,13.97L22,9.24L14.81,8.62L12,2L9.19,8.62L2,9.24L7.45,13.97L5.82,21L12,17.27Z"}));var Ae=["#FFFFFF","#F0F8FF","#F5F5F5","#FAFAFA"],At=(t,e)=>{let{particleCount:r=50,spread:n=200,startVelocity:a=3,colors:i=Ae,elementSize:s=15}=e;return m(r,()=>{let l=t.x+o(-n*2,n*2),c=t.y-o(100,300);return {id:f(),x:l,y:c,vx:o(-0.5,.5),vy:o(a*.5,a*1.2),life:e.lifetime||300,opacity:o(.4,.9),size:o(s*.3,s),rotation:o(0,360),color:i[Math.floor(Math.random()*i.length)]||i[0]||"#ffffff"}})},Rt=t=>b.createElement("div",{key:t.id,style:{width:`${t.size}px`,height:`${t.size}px`,backgroundColor:t.color,borderRadius:"50%",boxShadow:`
0 0 ${t.size*.5}px rgba(255, 255, 255, 0.8),
inset 0 0 ${t.size*.3}px rgba(255, 255, 255, 0.5)
`,filter:"blur(0.5px)"}});var kt=["\u{1F389}","\u{1F38A}","\u{1F388}","\u{1F381}","\u2728","\u{1F31F}","\u{1F4AB}","\u{1F3AF}"],ke=["\u{1F389}","\u{1F38A}","\u{1F973}","\u{1F388}","\u{1F381}","\u{1F37E}","\u{1F942}","\u{1F386}"],Ie=["\u2764\uFE0F","\u{1F495}","\u{1F496}","\u{1F49D}","\u{1F497}","\u{1F493}","\u{1F49E}","\u{1F498}"],Se=["\u{1F60A}","\u{1F604}","\u{1F970}","\u{1F60D}","\u{1F917}","\u{1F618}","\u{1F601}","\u{1F929}"],Ee=["\u{1F338}","\u{1F33A}","\u{1F33B}","\u{1F339}","\u{1F337}","\u{1F33C}","\u{1F340}","\u{1F33F}"],Be=["\u{1F355}","\u{1F354}","\u{1F35F}","\u{1F32E}","\u{1F37F}","\u{1F369}","\u{1F36A}","\u{1F9C1}"],It=(t,e)=>{let{particleCount:r=30,spread:n=100,startVelocity:a=15,elementSize:i=35,emojis:s=kt}=e;return m(r,()=>{let l=o(-45,-135),c=o(a*.5,a*1.2);return {id:f(),x:t.x+o(-n,n),y:t.y,vx:Math.cos(l*Math.PI/180)*c,vy:Math.sin(l*Math.PI/180)*c,life:e.lifetime||180,opacity:1,size:o(i*.7,i*1.3),rotation:o(-45,45),color:"",element:s[Math.floor(Math.random()*s.length)]}})},St=t=>b.createElement("div",{key:t.id,style:{fontSize:`${t.size}px`,lineHeight:1,userSelect:"none",filter:t.opacity<.5?"blur(1px)":void 0}},t.element),De={celebration:ke,love:Ie,happy:Se,nature:Ee,food:Be,default:kt};var Le=["#FFD700","#FFA500","#FFB300","#FFC700"],Bt=(t,e)=>{let{particleCount:r=30,spread:n=70,startVelocity:a=25,colors:i=Le,elementSize:s=25}=e;return m(r,()=>{let l=o(-n/2,n/2)*(Math.PI/180),c=o(a*.5,a);return {id:f(),x:t.x,y:t.y,vx:Math.sin(l)*c,vy:-Math.cos(l)*c,life:e.lifetime||120,opacity:1,size:o(s*.8,s*1.2),rotation:o(0,360),color:i[Math.floor(Math.random()*i.length)]||i[0]||"#ffffff"}})},Dt=t=>{var a,i,s,l,c,d,u,h;let e=(i=(a=t.config)==null?void 0:a.effects)!=null&&i.spin3D?8:2,r=t.rotation+(120-t.life)*e,n=(l=(s=t.config)==null?void 0:s.effects)!=null&&l.spin3D?Math.abs(Math.cos(r*Math.PI/180)):1;return b.createElement("div",{key:t.id,style:{width:`${t.size}px`,height:`${t.size}px`,background:`radial-gradient(ellipse at 30% 30%, ${t.color}, #B8860B)`,borderRadius:"50%",transform:(d=(c=t.config)==null?void 0:c.effects)!=null&&d.spin3D?`rotateY(${r}deg) scaleX(${n})`:`rotate(${r}deg)`,transformStyle:"preserve-3d",boxShadow:`
inset -2px -2px 4px rgba(0, 0, 0, 0.3),
inset 2px 2px 4px rgba(255, 255, 255, 0.5),
0 2px 4px rgba(0, 0, 0, 0.3)
`,border:`1px solid ${t.color}`,position:"relative",overflow:"hidden",backfaceVisibility:"hidden"}},b.createElement("div",{style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:`${t.size*.5}px`,fontWeight:"bold",color:"#B8860B",textShadow:"1px 1px 1px rgba(0, 0, 0, 0.3)",fontFamily:"Arial, sans-serif",opacity:(h=(u=t.config)==null?void 0:u.effects)!=null&&h.spin3D&&n<.3?0:1,transition:"opacity 0.1s"}},"$"))};var Te=["#FFB6C1","#FFC0CB","#FF69B4","#FF1493","#FFF0F5"],Lt=(t,e)=>{let{particleCount:r=40,spread:n=100,startVelocity:a=8,colors:i=Te,elementSize:s=20}=e;return m(r,()=>{let l=o(-n/2,n/2)*(Math.PI/180),c=o(a*.3,a);return {id:f(),x:t.x+o(-20,20),y:t.y-o(0,30),vx:Math.sin(l)*c,vy:o(2,5),life:e.lifetime||200,opacity:o(.7,1),size:o(s*.7,s*1.3),rotation:o(0,360),color:i[Math.floor(Math.random()*i.length)]||i[0]||"#ffffff"}})},Tt=t=>{let e=(200-t.life)*.1,r=Math.sin(e)*15,n=Math.sin(t.life*.1)*10;return b.createElement("div",{key:t.id,style:{width:`${t.size}px`,height:`${t.size*1.2}px`,position:"relative",transform:`translateX(${r}px) rotate(${t.rotation+n}deg)`,transformStyle:"preserve-3d"}},b.createElement("div",{style:{width:"100%",height:"100%",background:`radial-gradient(ellipse at 50% 30%, ${t.color}, ${t.color}DD)`,borderRadius:"0% 100% 0% 100%",position:"absolute",boxShadow:`
inset 1px 1px 3px rgba(255, 255, 255, 0.5),
0 2px 4px rgba(0, 0, 0, 0.1)
`,border:`1px solid ${t.color}CC`,transform:"rotateY(45deg)"}}),b.createElement("div",{style:{width:"100%",height:"100%",background:`radial-gradient(ellipse at 50% 30%, ${t.color}EE, ${t.color}BB)`,borderRadius:"0% 100% 0% 100%",position:"absolute",transform:"rotate(45deg) scale(0.9)",opacity:.8}}))};var je=["#00ff88","#00ffaa","#00ddff","#0099ff","#0066ff","#9933ff","#ff00ff"],jt=(t,e)=>{let{particleCount:r=15,spread:n=200,startVelocity:a=3,colors:i=je,elementSize:s=100}=e;return m(r,l=>{let c=l/r*n-n/2,d=o(-30,30);return {id:f(),x:t.x+c+d,y:t.y,vx:o(-1,1),vy:-a,life:e.lifetime||250,opacity:0,size:o(s*.8,s*1.2),rotation:o(-15,15),color:i[Math.floor(Math.random()*i.length)]||i[0]||"#ffffff"}})},Nt=t=>{let e=Math.sin(t.life*.05)*20,r=Math.min(1,(250-t.life)/50),n=t.life/250,a=Math.min(r,n)*.4;return b.createElement("div",{key:t.id,style:{width:`${t.size}px`,height:`${t.size*.3}px`,position:"relative",transform:`translateX(${e}px) rotate(${t.rotation}deg)`,filter:"blur(2px)"}},b.createElement("div",{style:{width:"100%",height:"100%",background:`linear-gradient(90deg, transparent, ${t.color}, transparent)`,borderRadius:"50%",opacity:a,boxShadow:`0 0 ${t.size*.5}px ${t.color}`,animation:"shimmer 2s infinite"}}),b.createElement("div",{style:{position:"absolute",top:"20%",left:"10%",width:"80%",height:"60%",background:`radial-gradient(ellipse at center, ${t.color}44, transparent)`,borderRadius:"50%",opacity:a*.5,filter:"blur(4px)"}}))};var Ne=["#FFFF99","#FFFFCC","#FFFF66","#FFFFAA"],Vt=(t,e)=>{let{particleCount:r=20,spread:n=150,startVelocity:a=2,colors:i=Ne,elementSize:s=8}=e;return m(r,()=>{let l=o(0,360)*(Math.PI/180),c=o(a*.3,a);return {id:f(),x:t.x+o(-n/2,n/2),y:t.y+o(-20,20),vx:Math.cos(l)*c,vy:Math.sin(l)*c*.5,life:e.lifetime||300,opacity:0,size:o(s*.6,s),rotation:o(0,360),color:i[Math.floor(Math.random()*i.length)]||i[0]||"#ffffff"}})},Ht=t=>{let e=Math.sin(t.life*.02+t.rotation)*15,r=Math.cos(t.life*.03+t.rotation)*10,i=Math.sin(t.life*.1+t.rotation*.1)>.3?1:.1,s=Math.min(1,(300-t.life)/30),l=t.life/300,c=Math.min(s,l);return b.createElement("div",{key:t.id,style:{width:`${t.size}px`,height:`${t.size}px`,position:"relative",transform:`translate(${e}px, ${r}px)`}},b.createElement("div",{style:{width:"100%",height:"100%",background:t.color,borderRadius:"50%",opacity:c*i,boxShadow:`
0 0 ${t.size}px ${t.color},
0 0 ${t.size*2}px ${t.color},
0 0 ${t.size*3}px ${t.color}88
`,transition:"opacity 0.3s ease"}}),b.createElement("div",{style:{position:"absolute",top:"50%",left:"50%",width:`${t.size*4}px`,height:`${t.size*4}px`,background:`radial-gradient(circle, ${t.color}44 0%, transparent 70%)`,borderRadius:"50%",transform:"translate(-50%, -50%)",opacity:c*i*.5,transition:"opacity 0.3s ease"}}))};var Ve=["#FF006E","#FB5607","#FFBE0B","#8338EC","#3A86FF","#06FFB4"],Xt=(t,e)=>{let{particleCount:r=25,spread:n=120,startVelocity:a=35,colors:i=Ve,elementSize:s=30}=e;return m(r,l=>{let c=o(-n/2,n/2)*(Math.PI/180),d=o(a*.5,a),u=l<5;return {id:f(),x:t.x,y:t.y,vx:Math.sin(c)*d*(u?.3:1),vy:-Math.cos(c)*d*.7+(u?5:0),life:e.lifetime||150,opacity:1,size:u?o(s*1.5,s*2.5):o(s*.3,s),rotation:o(0,360),color:i[Math.floor(Math.random()*i.length)]||i[0]||"#ffffff"}})},Ot=t=>{let e=1+(Math.abs(t.vx)+Math.abs(t.vy))*.01,r=1/e,n=t.size>15&&t.rotation>180,a=n?t.size*.5:0;return b.createElement("div",{key:t.id,style:{width:`${t.size}px`,height:`${t.size}px`,position:"relative",transform:`
scaleX(${e})
scaleY(${r})
rotate(${Math.atan2(t.vy,t.vx)*180/Math.PI}deg)
`}},b.createElement("div",{style:{width:"100%",height:"100%",background:t.color,borderRadius:"50%",position:"relative",boxShadow:"inset -2px -2px 4px rgba(0,0,0,0.2)"}},b.createElement("div",{style:{position:"absolute",top:"20%",left:"20%",width:"30%",height:"30%",background:t.color,borderRadius:"50%",opacity:.8,transform:`translate(${o(-5,5)}px, ${o(-5,5)}px)`}}),b.createElement("div",{style:{position:"absolute",bottom:"15%",right:"15%",width:"25%",height:"25%",background:t.color,borderRadius:"50%",opacity:.7}})),n&&b.createElement("div",{style:{position:"absolute",bottom:`-${a}px`,left:"40%",width:"20%",height:`${a}px`,background:t.color,borderRadius:"0 0 50% 50%",opacity:.9}}))};var He=["#FF006E","#FB5607","#FFBE0B","#8338EC","#3A86FF","#06FFB4","#FF4081"],Ut=(t,e)=>{let{particleCount:r=15,spread:n=80,startVelocity:a=10,colors:i=He,elementSize:s=35}=e;return m(r,()=>{let l=o(-n/2,n/2)*(Math.PI/180),c=o(a*.7,a);return {id:f(),x:t.x+o(-n*.8,n*.8),y:t.y+o(-10,30),vx:Math.sin(l)*c*.3+o(-1,1),vy:-c*.4,life:e.lifetime||250,opacity:.9,size:o(s*.8,s*1.2),rotation:o(-10,10),color:i[Math.floor(Math.random()*i.length)]||i[0]||"#ffffff"}})},Wt=t=>{let e=Math.sin(t.life*.03)*15,r=Math.sin(t.life*.05)*5,n=t.life>50?1:t.life/50;return b.createElement("div",{key:t.id,style:{width:`${t.size}px`,height:`${t.size*1.2}px`,position:"relative",transform:`
translateX(${e}px)
translateY(${r}px)
rotate(${t.rotation+e*.2}deg)
`,opacity:t.opacity*n}},b.createElement("div",{style:{width:"100%",height:"100%",background:`radial-gradient(circle at 30% 30%, ${t.color}ee, ${t.color})`,borderRadius:"50% 50% 50% 50% / 60% 60% 40% 40%",position:"relative",boxShadow:`
inset -5px -5px 10px rgba(0,0,0,0.2),
0 4px 8px rgba(0,0,0,0.2)
`}},b.createElement("div",{style:{position:"absolute",top:"15%",left:"20%",width:"25%",height:"30%",background:"radial-gradient(circle, rgba(255,255,255,0.8) 0%, transparent 70%)",borderRadius:"50%",transform:"rotate(-20deg)"}}),b.createElement("div",{style:{position:"absolute",bottom:"-5px",left:"50%",transform:"translateX(-50%)",width:"0",height:"0",borderLeft:"4px solid transparent",borderRight:"4px solid transparent",borderTop:`8px solid ${t.color}`}})),b.createElement("svg",{style:{position:"absolute",top:"100%",left:"50%",transform:"translateX(-50%)",width:"2px",height:`${t.size*2}px`,opacity:.6}},b.createElement("path",{d:`M1 0 Q ${1+Math.sin(t.life*.1)*3} ${t.size} 1 ${t.size*2}`,stroke:t.color,strokeWidth:"1.5",fill:"none",opacity:"0.4"})))};var Xe=["#FFFFFF","#FFF9C4","#BBDEFB","#C5CAE9","#D1C4E9","#FFE082","#FFCCBC"],Gt=(t,e)=>{let{particleCount:r=60,spread:n=200,startVelocity:a=15,colors:i=Xe,elementSize:s=8}=e;return m(r,l=>{let c=l/r,d=c*Math.PI*4,u=c*n,h=o(-0.3,.3),F=o(-10,10),P=d+h,M=u+F,D=Math.cos(P)*M,L=Math.sin(P)*M,C=P+Math.PI/2,$=a*(1-c*.5);return {id:f(),x:t.x,y:t.y,vx:Math.cos(C)*$*.3+D*.02,vy:Math.sin(C)*$*.3+L*.02,life:e.lifetime||250,opacity:0,size:o(s*.3,s)*(1-c*.5),rotation:o(0,360),color:i[Math.floor(Math.random()*i.length)]||i[0]||"#ffffff"}})},Yt=t=>{let r=1+(250-t.life)/250*.5,n=Math.min(1,(250-t.life)/30),a=t.life/250,i=Math.min(n,a),s=Math.sin(t.life*.2+t.rotation)*.3+.7;return b.createElement("div",{key:t.id,style:{width:`${t.size}px`,height:`${t.size}px`,position:"relative",transform:`scale(${r})`,opacity:i*s}},b.createElement("div",{style:{width:"100%",height:"100%",background:t.color,borderRadius:"50%",boxShadow:`
0 0 ${t.size}px ${t.color},
0 0 ${t.size*2}px ${t.color}88,
0 0 ${t.size*3}px ${t.color}44
`,position:"relative"}},b.createElement("div",{style:{position:"absolute",top:"50%",left:"50%",width:`${t.size*3}px`,height:"1px",background:`linear-gradient(90deg, transparent, ${t.color}, transparent)`,transform:`translate(-50%, -50%) rotate(${t.rotation}deg)`,opacity:s}}),b.createElement("div",{style:{position:"absolute",top:"50%",left:"50%",width:"1px",height:`${t.size*3}px`,background:`linear-gradient(180deg, transparent, ${t.color}, transparent)`,transform:`translate(-50%, -50%) rotate(${t.rotation}deg)`,opacity:s}})),t.size>5&&b.createElement("div",{style:{position:"absolute",top:"50%",left:"50%",width:`${t.size*6}px`,height:`${t.size*6}px`,background:`radial-gradient(circle, ${t.color}22 0%, transparent 70%)`,borderRadius:"50%",transform:"translate(-50%, -50%)",opacity:i*.3,filter:"blur(3px)"}}))};var qt=(t,e)=>{let{particleCount:r=20,elementSize:n=200}=e,a=[],i=["r","g","b"];for(let s=0;s<r;s++){let l=Math.random()>.3,c=s%3,d=i[c],u=l?o(50,200):o(2,8),h=l?o(2,8):o(50,200),F=o(-20,20),P=c+(l?4:0)+(Math.floor(u)<<3)+(Math.floor(h)<<11)+(F+32<<19);a.push({id:f(),x:t.x+o(-n/2,n/2),y:t.y+o(-n/2,n/2),vx:o(-50,50),vy:o(-30,30),life:e.lifetime||150,opacity:o(.3,1),size:o(5,20),rotation:P,color:d==="r"?"#ff0000":d==="g"?"#00ff00":"#0000ff"});}return a},_t=t=>{let e=t.rotation&3,r=t.rotation>>3&255,n=t.rotation>>11&255,a=(t.rotation>>19&63)-32,i=["r","g","b"][e],s=t.size,l={r:i==="r"?255:0,g:i==="g"?255:0,b:i==="b"?255:0},c=i==="r"?"screen":i==="g"?"multiply":"difference";return b.createElement("div",{key:t.id,style:{width:`${r}px`,height:`${n}px`,backgroundColor:`rgba(${l.r}, ${l.g}, ${l.b}, ${t.opacity})`,mixBlendMode:c,filter:`blur(${o(0,2)}px)`,boxShadow:`${a}px 0 ${s}px rgba(${l.r}, ${l.g}, ${l.b}, ${t.opacity*.5})`}})};var Ue=["#9C27B0","#E91E63","#FF00FF","#00FFFF","#FFD700","#FF69B4","#DA70D6","#9370DB"],Zt=(t,e)=>{let{particleCount:r=40,startVelocity:n=8,colors:a=Ue,elementSize:i=12}=e;return createPooledParticles(r,s=>{let l=s/r*360+o(-30,30),c=o(n*.3,n),d=x(a),u=o(0,360),h=o(0,30);return {id:f(),x:t.x+Math.cos(p(u))*h,y:t.y+Math.sin(p(u))*h,vx:Math.cos(p(l))*c+o(-2,2),vy:Math.sin(p(l))*c+o(-2,2),life:e.lifetime||120,opacity:o(.4,1),size:o(i*.3,i),rotation:o(0,360),color:d}})},Qt=t=>{let e=t.size*.7;return b.createElement("div",{key:t.id,style:{width:`${t.size}px`,height:`${t.size}px`,position:"relative"}},b.createElement("div",{style:{position:"absolute",width:"100%",height:"100%",backgroundColor:t.color,borderRadius:"50%",boxShadow:`0 0 ${t.size}px ${t.color}, 0 0 ${t.size*2}px ${t.color}`,filter:"blur(1px)"}}),b.createElement("div",{style:{position:"absolute",top:"50%",left:"50%",width:`${e}px`,height:`${e}px`,transform:`translate(-50%, -50%) rotate(${t.rotation}deg)`}},b.createElement("div",{style:{position:"absolute",width:"100%",height:"2px",backgroundColor:"white",top:"50%",left:"0",transform:"translateY(-50%)",boxShadow:"0 0 4px white"}}),b.createElement("div",{style:{position:"absolute",width:"2px",height:"100%",backgroundColor:"white",left:"50%",top:"0",transform:"translateX(-50%)",boxShadow:"0 0 4px white"}})))};var We=["#FF1493","#00CED1","#FFD700","#FF69B4","#7B68EE","#00FA9A","#FF6347","#4169E1"],Jt=(t,e)=>{let{particleCount:r=15,startVelocity:n=15,colors:a=We,elementSize:i=25}=e;return createPooledParticles(r,()=>{let s=o(0,360),l=o(n*.5,n),c=x(a);return {id:f(),x:t.x,y:t.y,vx:Math.cos(p(s))*l,vy:Math.sin(p(s))*l-10,life:e.lifetime||150,opacity:o(.7,1),size:o(i*.6,i),rotation:o(0,360),color:c}})},Kt=t=>{let e=(Date.now()*.5+t.x+t.y)%360;return b.createElement("div",{key:t.id,style:{width:`${t.size}px`,height:`${t.size*1.5}px`,position:"relative",transform:`rotate(${t.rotation}deg)`}},b.createElement("div",{style:{position:"absolute",width:"100%",height:"100%",background:`linear-gradient(135deg, ${t.color}, ${t.color}88, transparent)`,clipPath:"polygon(50% 0%, 100% 40%, 75% 100%, 25% 100%, 0% 40%)",boxShadow:`0 0 ${t.size}px ${t.color}44`}}),b.createElement("div",{style:{position:"absolute",width:"80%",height:"80%",top:"10%",left:"10%",background:"linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.4), transparent)",clipPath:"polygon(50% 10%, 90% 45%, 65% 90%, 35% 90%, 10% 45%)"}}),b.createElement("div",{style:{position:"absolute",width:"100%",height:"100%",background:`linear-gradient(${e}deg,
hsla(${e}, 100%, 50%, 0.3),
hsla(${(e+60)%360}, 100%, 50%, 0.3),
hsla(${(e+120)%360}, 100%, 50%, 0.3)
)`,clipPath:"polygon(50% 0%, 100% 40%, 75% 100%, 25% 100%, 0% 40%)",mixBlendMode:"screen"}}),b.createElement("div",{style:{position:"absolute",width:"30%",height:"30%",top:"20%",left:"35%",background:"radial-gradient(circle, rgba(255, 255, 255, 0.8), transparent)",borderRadius:"50%",filter:"blur(2px)"}}))};var Ge=["#D2691E","#CD853F","#8B4513","#A0522D","#FF8C00","#FF6347"],te=(t,e)=>{let{particleCount:r=10,colors:n=Ge,elementSize:a=25}=e;return m(r,()=>({id:f(),x:t.x+o(-100,100),y:t.y+o(-50,0),vx:o(-1,1),vy:o(.5,2),life:e.lifetime||300,opacity:1,size:o(a*.6,a),rotation:Math.floor(o(0,360))+Math.floor(o(0,360))*1e3+Math.floor(o(20,40))*1e6+(Math.floor(o(-3,3))+3)*1e8,color:x(n)}))},ee=t=>{let e=t.rotation%1e3,r=Math.floor(t.rotation%1e6/1e3),n=Math.floor(t.rotation%1e8/1e6),a=Math.floor(t.rotation/1e8)-3,i=Math.sin((Date.now()*.002+e)*Math.PI/180)*30,s=Math.sin((Date.now()*.001+r)*Math.PI/180)*n,l=(Date.now()*a*.01+i)%360;return b.createElement("div",{key:t.id,style:{width:`${t.size}px`,height:`${t.size}px`,position:"relative",transform:`translateX(${s}px) rotate(${l}deg)`}},b.createElement("svg",{width:t.size,height:t.size,viewBox:`-${t.size/2} -${t.size/2} ${t.size} ${t.size}`,style:{position:"absolute",top:0,left:0}},b.createElement("path",{d:`
M 0,-${t.size/2}
C -${t.size/3},-${t.size/3} -${t.size/3},${t.size/3} 0,${t.size/2}
C ${t.size/3},${t.size/3} ${t.size/3},-${t.size/3} 0,-${t.size/2}
`,fill:t.color,opacity:"0.9"}),b.createElement("line",{x1:"0",y1:-t.size/2,x2:"0",y2:t.size/2,stroke:"#8B4513",strokeWidth:"1",opacity:"0.5"}),b.createElement("line",{x1:"0",y1:-t.size/4,x2:-t.size/4,y2:-t.size/8,stroke:"#8B4513",strokeWidth:"0.5",opacity:"0.5"}),b.createElement("line",{x1:"0",y1:-t.size/4,x2:t.size/4,y2:-t.size/8,stroke:"#8B4513",strokeWidth:"0.5",opacity:"0.5"}),b.createElement("line",{x1:"0",y1:t.size/4,x2:-t.size/4,y2:t.size/8,stroke:"#8B4513",strokeWidth:"0.5",opacity:"0.5"}),b.createElement("line",{x1:"0",y1:t.size/4,x2:t.size/4,y2:t.size/8,stroke:"#8B4513",strokeWidth:"0.5",opacity:"0.5"})))};var oe={confetti:{createParticles:ut,renderParticle:ht},sparkles:{createParticles:yt,renderParticle:gt},hearts:{createParticles:Pt,renderParticle:bt},fireworks:{createParticles:vt,renderParticle:Ct},bubbles:{createParticles:$t,renderParticle:Ft},stars:{createParticles:Mt,renderParticle:wt},snow:{createParticles:At,renderParticle:Rt},emoji:{createParticles:It,renderParticle:St},coins:{createParticles:Bt,renderParticle:Dt},petals:{createParticles:Lt,renderParticle:Tt},aurora:{createParticles:jt,renderParticle:Nt},fireflies:{createParticles:Vt,renderParticle:Ht},paint:{createParticles:Xt,renderParticle:Ot},balloons:{createParticles:Ut,renderParticle:Wt},galaxy:{createParticles:Gt,renderParticle:Yt},glitch:{createParticles:qt,renderParticle:_t},magicdust:{createParticles:Zt,renderParticle:Qt},crystals:{createParticles:Jt,renderParticle:Kt},leaves:{createParticles:te,renderParticle:ee}};var G=()=>{if(typeof window=="undefined")return false;let t=navigator.userAgent||navigator.vendor||window.opera||"",e=/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(t),r=window.innerWidth<=768,n="ontouchstart"in window||navigator.maxTouchPoints>0;return e||r&&n},Y=t=>{var e,r,n;return G()?R(A({},t),{particleCount:Math.floor((t.particleCount||50)*.6),elementSize:Math.floor((t.elementSize||20)*.8),lifetime:Math.floor((t.lifetime||150)*.8),physics:R(A({},t.physics),{gravity:Math.round((((e=t.physics)==null?void 0:e.gravity)||0)*100)/100,wind:Math.round((((r=t.physics)==null?void 0:r.wind)||0)*100)/100,friction:Math.round((((n=t.physics)==null?void 0:n.friction)||.98)*100)/100})}):t},re=t=>G()?t%3===0:false;var q=class{constructor(){this.animations=new Map;this.rafId=null;this.isRunning=false;this.lastFrameTime=0;this.frameInterval=1e3/60;this.frameCount=0;this.fpsUpdateInterval=1e3;this.lastFpsUpdate=0;this.currentFps=0;this.update=this.update.bind(this);}addAnimation(e){this.animations.set(e.id,e),!this.isRunning&&this.animations.size>0&&this.start();}removeAnimation(e){let r=this.animations.get(e);r&&(N.releaseAll(r.particles),r.containerElement&&document.body.contains(r.containerElement)&&document.body.removeChild(r.containerElement),this.animations.delete(e)),this.animations.size===0&&this.stop();}start(){this.isRunning||(this.isRunning=true,this.lastFrameTime=performance.now(),this.lastFpsUpdate=this.lastFrameTime,this.frameCount=0,this.rafId=requestAnimationFrame(this.update));}stop(){this.isRunning&&(this.isRunning=false,this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null));}update(e){let r=e-this.lastFrameTime;if(r<this.frameInterval){this.rafId=requestAnimationFrame(this.update);return}if(this.lastFrameTime=e-r%this.frameInterval,this.frameCount++,e-this.lastFpsUpdate>=this.fpsUpdateInterval&&(this.currentFps=this.frameCount,this.frameCount=0,this.lastFpsUpdate=e),!!document.hidden){this.rafId=requestAnimationFrame(this.update);return}let a=[];this.animations.forEach((i,s)=>{if(i.isPaused)return;i.frameCount++;let l=re(i.frameCount),c=0;i.particles=i.particles.map(d=>(d.life<=0||(c++,d.x+=d.vx,d.y+=d.vy,d.vy+=i.physics.gravity,d.vx+=i.physics.wind,d.vx*=i.physics.friction,d.vy*=i.physics.friction,d.rotation+=d.vx*2,d.life-=1.2,this.applyEffects(d,i),this.updateOpacity(d,i)),d)),i.updateCallback&&!l&&i.updateCallback(i.particles),c===0&&(a.push(s),i.onComplete&&i.onComplete());}),a.forEach(i=>this.removeAnimation(i)),this.isRunning&&(this.rafId=requestAnimationFrame(this.update));}applyEffects(e,r){var i;let n=(i=r.config)==null?void 0:i.effects;if(!n)return;let{animationType:a}=r;n.flutter&&a==="confetti"&&(e.x+=Math.sin(e.life*.1)*.5,e.rotation+=Math.sin(e.life*.05)*2),n.windDrift&&(a==="snow"||a==="leaves")&&(e.x+=Math.sin(e.life*.05+e.id.charCodeAt(0))*.8),n.wobble&&a==="bubbles"&&(e.x+=Math.sin(e.life*.08)*.3,e.y+=Math.cos(e.life*.08)*.2);}updateOpacity(e,r){let{animationType:n,config:a}=r,i=a==null?void 0:a.effects;n==="sparkles"?(e.life>70?e.opacity=(100-e.life)/30:e.life<30&&(e.opacity=e.life/30),i!=null&&i.twinkle&&(e.opacity*=.5+Math.sin(e.life*.3)*.5)):n==="stars"&&(i!=null&&i.twinkle)?e.opacity=e.life/100*(.5+Math.sin(e.life*.3)*.5):e.opacity=e.life/100;}getStats(){return {activeAnimations:this.animations.size,currentFps:this.currentFps,isRunning:this.isRunning,totalParticles:Array.from(this.animations.values()).reduce((e,r)=>e+r.particles.filter(n=>n.life>0).length,0)}}setTargetFPS(e){this.frameInterval=1e3/e;}pauseAnimation(e){let r=this.animations.get(e);r&&!r.isPaused&&(r.isPaused=true,r.pausedAt=performance.now());}resumeAnimation(e){let r=this.animations.get(e);r&&r.isPaused&&(r.isPaused=false,this.animations.size>0&&!this.isRunning&&this.start());}isAnimationPaused(e){let r=this.animations.get(e);return r?!!r.isPaused:false}getAnimation(e){return this.animations.get(e)}},v=new q;function Qe(t,e,r){let[n,a]=useState(false),i=useRef(null),s=useRef(null),l=useRef(null),c=useRef(null),d=typeof t=="string",u=d?c:t,h=useCallback(()=>new Promise(C=>{var Q,J,K,tt,et,ot,rt,it,nt,at,st,lt,ct;let $=null;if(d){if(typeof document=="undefined")return;$=document.getElementById(t);}else $=u.current;if(!$){(Q=console.warn)==null||Q.call(console,`[Partycles] Element ${d?`with ID "${t}"`:"from ref"} not found. Make sure the element exists when reward() is called.`),C();return}let T=$.getBoundingClientRect(),ie={x:T.left+T.width/2,y:T.top+T.height/2},j=oe[e];if(!j){console.error(`Animation type "${e}" not found`),C();return}let y=r?Y(r):void 0,ne=j.createParticles(ie,y||{}).map(H=>R(A({},H),{config:y||r}));if(typeof document=="undefined"){C();return}let g=document.createElement("div");g.style.position="fixed",g.style.top="0",g.style.left="0",g.style.width="100%",g.style.height="100%",g.style.pointerEvents="none",g.style.zIndex="9999",document.body.appendChild(g),s.current=g;let ae=createRoot(g);l.current=ae;g.getBoundingClientRect();let le=e==="bubbles"?-0.1:e==="snow"?.05:.35,ce=(et=(tt=(J=y==null?void 0:y.physics)==null?void 0:J.gravity)!=null?tt:(K=r==null?void 0:r.physics)==null?void 0:K.gravity)!=null?et:le,de=(nt=(it=(ot=y==null?void 0:y.physics)==null?void 0:ot.friction)!=null?it:(rt=r==null?void 0:r.physics)==null?void 0:rt.friction)!=null?nt:.98,fe=(ct=(lt=(at=y==null?void 0:y.physics)==null?void 0:at.wind)!=null?lt:(st=r==null?void 0:r.physics)==null?void 0:st.wind)!=null?ct:0,Z=`${Date.now()}-${Math.random().toString(36).substr(2,9)}`;i.current=Z;let me=H=>{l.current&&l.current.render(b.createElement(b.Fragment,null,H.filter(w=>w.life>0).map(w=>b.createElement("div",{key:w.id,style:mt(w)},j.renderParticle(w)))));};v.addAnimation({id:Z,particles:ne,containerElement:g,renderFunction:j.renderParticle,updateCallback:me,onComplete:()=>{l.current&&(l.current.unmount(),l.current=null),s.current=null,i.current=null,a(false),C();},physics:{gravity:ce,friction:de,wind:fe},animationType:e,config:y||r,frameCount:0}),a(true);}),[t,e,r,d,u]),F=useCallback(()=>n?Promise.resolve():h(),[h,n]),P=useCallback(()=>{i.current&&v.pauseAnimation(i.current);},[]),M=useCallback(()=>{i.current&&v.resumeAnimation(i.current);},[]),D=useCallback(()=>(i.current&&(v.removeAnimation(i.current),i.current=null),a(false),h()),[h]),L=useMemo(()=>i.current?v.isAnimationPaused(i.current):false,[n]);return useEffect(()=>()=>{i.current&&v.removeAnimation(i.current),l.current&&(l.current.unmount(),l.current=null),s.current&&document.body.contains(s.current)&&(document.body.removeChild(s.current),s.current=null);},[]),d?{reward:F,isAnimating:n,pause:P,resume:M,replay:D,isPaused:L}:{reward:F,isAnimating:n,targetRef:u,pause:P,resume:M,replay:D,isPaused:L}}export{v as animationManager,De as emojiPresets,G as isMobileDevice,Y as optimizeConfigForMobile,N as particlePool,Qe as useReward};//# sourceMappingURL=index.mjs.map
//# sourceMappingURL=index.mjs.map