hz-particles 1.0.13 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,13 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Oe=require("react/jsx-runtime"),r=require("react"),je=require("@react-three/fiber"),Vt=require("three"),Xe=require("hz-particles");function Dt(e){const u=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const f in e)if(f!=="default"){const A=Object.getOwnPropertyDescriptor(e,f);Object.defineProperty(u,f,A.get?A:{enumerable:!0,get:()=>e[f]})}}return u.default=e,Object.freeze(u)}const c=Dt(Vt);function ke(e){return Math.abs(Math.sin(e*12.9898)*43758.5453)%1}function Et(e){const u=Math.sin(e*54321.67)*43758.5453%1;return u<0?u+1:u}function xt(e,u,f,A){if(f<=0)return 0;const p=u/f;let _=e.particleSize??.5;if(e.randomSize){const q=e.minSize??.1,W=e.maxSize??.5;_=q+(W-q)*Et(f)}const Z=Math.max(.01,Math.min(10,e.sizeLifetimeSpeed??1));if(e.fadeSizeEnabled&&(_*=1-Math.pow(p,1/Z)),e.increaseSizeEnabled&&(_*=1+Math.pow(p,1/Z)),e.pulseEnabled){const q=e.pulseAmplitude??.5,W=e.pulseFrequency??1,te=(e.pulsePhaseRandom??0)*ke(A)*Math.PI*2;_*=1+q*Math.sin(u*W*Math.PI*2+te)}return Math.max(0,_)}function St(e,u,f,A){if(f<=0)return 0;let p=e.opacity??1;const _=u/f;if(e.fadeEnabled&&(p*=Math.max(0,1-_)),e.pulseEnabled&&e.pulseOpacity){const Z=e.pulseAmplitude??.5,q=e.pulseFrequency??1,J=(e.pulsePhaseRandom??0)*ke(A)*Math.PI*2;p*=Math.max(0,1+Z*Math.sin(u*q*Math.PI*2+J))}return Math.max(0,Math.min(1,p))}function gt(e,u){return u===1?e:{...e,systems:e.systems.map(f=>({...f,particleSize:(f.particleSize??.5)*u,minSize:f.minSize!=null?f.minSize*u:void 0,maxSize:f.maxSize!=null?f.maxSize*u:void 0,particleSpeed:(f.particleSpeed??1)*u,minSpeed:f.minSpeed!=null?f.minSpeed*u:void 0,maxSpeed:f.maxSpeed!=null?f.maxSpeed*u:void 0,emissionTrailWidth:(f.emissionTrailWidth??.3)*u}))}}function Ft(e){let u=0;for(const f of e.systems)u+=f.maxParticles??1e4;return u}function It({preset:e,position:u,positionRef:f,autoPlay:A=!0,visible:p=!0,scale:_=1,resetKey:Z=0,onComplete:q}){var Ce;const[W,J]=r.useState(typeof e=="string"?null:e);r.useEffect(()=>{typeof e=="string"?(J(null),Xe.fetchPreset(e).then(J).catch(a=>{console.error("[HZParticlesFX] Failed to fetch preset:",a)})):J(e)},[e]);const{camera:te,gl:_e}=je.useThree(),ae=r.useRef(null);if(!ae.current){const a=(Ce=_e.backend)==null?void 0:Ce.device;a&&(ae.current=a)}const Re=ae.current,Pe=r.useRef(null),fe=r.useRef(null),Te=r.useRef(!1),E=r.useRef(!1),d=r.useMemo(()=>W?gt(W,_):null,[W,_]),Fe=r.useMemo(()=>(d==null?void 0:d.systems.every(a=>a.emissionTrailEnabled))??!1,[d]),We=r.useMemo(()=>d?d.systems.every(a=>a.emissionTrailEnabled)?1:Ft(d):0,[d]),He=r.useMemo(()=>u?u instanceof c.Vector3?u.clone():new c.Vector3(...u):new c.Vector3(0,0,0),[u]),de=r.useMemo(()=>(d==null?void 0:d.systems.some(a=>a.emissionTrailEnabled))??!1,[d]),Ie=r.useMemo(()=>new c.PlaneGeometry(1,1),[]),s=r.useMemo(()=>{const a=document.createElement("canvas");a.width=64,a.height=64;const z=a.getContext("2d");z.clearRect(0,0,64,64);const F=z.createRadialGradient(32,32,0,32,32,32);F.addColorStop(0,"rgba(255,255,255,1)"),F.addColorStop(.7,"rgba(255,255,255,1)"),F.addColorStop(1,"rgba(255,255,255,0)"),z.fillStyle=F,z.beginPath(),z.arc(32,32,32,0,Math.PI*2),z.fill();const x=new c.CanvasTexture(a);x.flipY=!1;const B=new c.MeshBasicMaterial({color:16777215,transparent:!0,depthWrite:!1,alphaTest:.01,map:x,vertexColors:!0,side:c.DoubleSide,blending:c.AdditiveBlending});return B.needsUpdate=!0,B},[]),h=8,pe=r.useRef(null),j=r.useRef(0),y=512,b=r.useRef({buf:new Float32Array(y*4),head:0,count:0,elapsed:0}),{trailGeo:$,trailPosAttr:ne,trailColAttr:M}=r.useMemo(()=>{const z=8*h*6,F=new Float32Array(z*3),x=new Float32Array(z*3),B=new c.BufferGeometry,le=new c.BufferAttribute(F,3);le.setUsage(c.DynamicDrawUsage),B.setAttribute("position",le);const ye=new c.BufferAttribute(x,3);return ye.setUsage(c.DynamicDrawUsage),B.setAttribute("color",ye),B.setDrawRange(0,0),{trailGeo:B,trailPosAttr:le,trailColAttr:ye}},[]),U=r.useMemo(()=>new c.MeshBasicMaterial({color:16777215,vertexColors:!0,transparent:!0,depthWrite:!1,side:c.DoubleSide,blending:c.AdditiveBlending}),[]);r.useEffect(()=>{if(!Re||!d)return;const a=new Xe.ParticleSystemManager(Re);return fe.current=a,E.current=!1,a.replaceSystems(d).then(()=>{A&&p&&(a.respawnAllSystems(),E.current=!0)}).catch(z=>{console.error("[HZParticlesFX] replaceSystems FAILED:",z)}),()=>{typeof a.destroy=="function"&&a.destroy(),fe.current=null}},[Re,d]),r.useEffect(()=>{const a=fe.current;a&&A&&p&&!E.current&&(a.respawnAllSystems(),E.current=!0,Te.current=!1)},[A,p]);const ie=r.useRef(null),me=r.useRef(Z);r.useEffect(()=>{if(Z===me.current)return;me.current=Z;const a=b.current;a.head=0,a.count=0,a.elapsed=0,$.setDrawRange(0,0),ie.current=null;const z=fe.current;z&&(z.respawnAllSystems(),E.current=!0,Te.current=!1)},[Z]);const he=r.useMemo(()=>new c.Matrix4,[]),Ue=r.useMemo(()=>new c.Vector3,[]),se=r.useMemo(()=>new c.Vector3,[]),re=r.useMemo(()=>new c.Quaternion,[]),X=r.useMemo(()=>new c.Vector3,[]),Be=r.useMemo(()=>new c.Vector3(0,0,1),[]),R=r.useMemo(()=>new c.Color,[]);return je.useFrame((a,z)=>{if(!p||!Pe.current||!fe.current)return;const F=fe.current,x=(f==null?void 0:f.current)??He,B=z>1?z/1e3:z,le=ie.current,ye=le&&B>0,vt=ye?(x.x-le.x)/B:0,bt=ye?(x.y-le.y)/B:0,wt=ye?(x.z-le.z)/B:0;ie.current={x:x.x,y:x.y,z:x.z};for(const{system:n,config:o}of F.particleSystems)o.emissionTrailEnabled?(n.setSimulationTransform({position:[x.x,x.y,x.z],velocity:[vt,bt,wt]}),o.shapeTranslationX=0,o.shapeTranslationY=0,o.shapeTranslationZ=0):(o.shapeTranslationX=x.x,o.shapeTranslationY=x.y,o.shapeTranslationZ=x.z);F.updateAllSystems(B);for(const{system:n}of F.particleSystems)n.readbackAndProcessParticles();if(de){const n=b.current;n.elapsed+=B;const o=n.head*4;n.buf[o]=x.x,n.buf[o+1]=x.y,n.buf[o+2]=x.z,n.buf[o+3]=n.elapsed,n.head=(n.head+1)%y,n.count<y&&n.count++}const Me=Pe.current;let xe=0;for(let n=0;n<F.particleSystems.length;n++){const{system:o,config:C}=F.particleSystems[n];if(C.emissionTrailEnabled)continue;const k=o.particleData,qe=o.activeParticles;if(!(!k||qe<=0))for(let ue=0;ue<qe;ue++){const L=ue*8,Se=k[L+0],Ve=k[L+1],O=k[L+2];let ge=k[L+3],ve=k[L+4],G=k[L+5];const be=k[L+6],K=k[L+7];if(be>=K||K<=0)continue;const w=be/K;if(C.colorTransitionEnabled){const I=C.startColor??[1,0,0],oe=C.endColor??[0,0,1];ge=I[0]+(oe[0]-I[0])*w,ve=I[1]+(oe[1]-I[1])*w,G=I[2]+(oe[2]-I[2])*w}const we=C.bloomIntensity??1;ge=Math.min(1,ge*we),ve=Math.min(1,ve*we),G=Math.min(1,G*we);const ze=St(C,be,K,ue);ge*=ze,ve*=ze,G*=ze;const Y=xt(C,be,K,ue);if(!(Y<=0)){if(Ue.set(Se,Ve,O),se.subVectors(te.position,Ue).normalize(),re.setFromUnitVectors(Be,se),C.velocityStretchEnabled&&o.particleVelocities){const I=ue*4,oe=o.particleVelocities[I],De=o.particleVelocities[I+1],P=o.particleVelocities[I+2],ce=Math.sqrt(oe*oe+De*De+P*P);if(ce>.001){const Ge=C.velocityStretchFactor??1,i=Y*(1+ce*Ge);X.set(Y,i,1),se.set(oe,De,P).normalize(),re.setFromUnitVectors(Be,se);const Ee=(i-Y)*.5;Ue.addScaledVector(se,Ee)}else X.set(Y,Y,1)}else X.set(Y,Y,1);he.compose(Ue,re,X),Me.setMatrixAt(xe,he),R.setRGB(ge,ve,G),Me.setColorAt(xe,R),xe++}}}Me.count=xe,Me.visible=xe>0,xe>0&&(Me.instanceMatrix.needsUpdate=!0,Me.instanceColor&&(Me.instanceColor.needsUpdate=!0));const Le=xe>0||F.particleSystems.some(({system:n})=>n.emitting||n.activeParticles>0);if(Te.current&&!Le&&(E.current=!1,q==null||q()),Te.current=Le,de&&pe.current){const n=ne.array,o=M.array;let C=0;const k=te.position.x,qe=te.position.y,ue=te.position.z;for(let Se=0;Se<F.particleSystems.length;Se++){const{system:Ve,config:O}=F.particleSystems[Se];if(!O.emissionTrailEnabled||!Ve.emitting&&Ve.activeParticles<=0)continue;const ge=O.emissionTrailDuration??1,ve=O.emissionTrailWidth??.3,G=O.bloomIntensity??1,be=ve*.5,K=b.current,w=K.buf,we=K.count,ze=K.head,Y=K.elapsed;if(we<2)continue;const I=((ze-we)%y+y)%y,oe=Y-w[I*4+3],De=Math.min(ge,oe);if(De<.001)continue;const P=O.startColor??[1,1,1],ce=O.colorTransitionEnabled?O.endColor??[1,1,1]:P,Ge=(t,m)=>{const g=Y-t;for(let S=0;S<we-1;S++){const T=((ze-1-S)%y+y)%y,H=((ze-2-S)%y+y)%y,ee=w[T*4+3],N=w[H*4+3];if(g>=N&&g<=ee){const v=ee!==N?(g-N)/(ee-N):0;m[0]=w[H*4]+(w[T*4]-w[H*4])*v,m[1]=w[H*4+1]+(w[T*4+1]-w[H*4+1])*v,m[2]=w[H*4+2]+(w[T*4+2]-w[H*4+2])*v;return}}m[0]=w[I*4],m[1]=w[I*4+1],m[2]=w[I*4+2]},i=[x.x,x.y,x.z],Ee=[0,0,0];for(let t=1;t<=h;t++){const m=t/h*De;Ge(m,Ee),i.push(Ee[0],Ee[1],Ee[2])}const Ye=i[0]-i[h*3],Ne=i[1]-i[h*3+1],Qe=i[2]-i[h*3+2];if(Ye*Ye+Ne*Ne+Qe*Qe<1e-6)continue;let Je=0,$e=0,Ke=0;const Ae=[];for(let t=0;t<=h;t++){let m,g,S;t===0?(m=i[3]-i[0],g=i[4]-i[1],S=i[5]-i[2]):t===h?(m=i[t*3]-i[(t-1)*3],g=i[t*3+1]-i[(t-1)*3+1],S=i[t*3+2]-i[(t-1)*3+2]):(m=i[(t+1)*3]-i[(t-1)*3],g=i[(t+1)*3+1]-i[(t-1)*3+1],S=i[(t+1)*3+2]-i[(t-1)*3+2]);let T=Math.sqrt(m*m+g*g+S*S);T<1e-8&&(m=0,g=0,S=1,T=1),m/=T,g/=T,S/=T;const H=k-i[t*3],ee=qe-i[t*3+1],N=ue-i[t*3+2];let v=g*N-S*ee,V=S*H-m*N,D=m*ee-g*H,Q=Math.sqrt(v*v+V*V+D*D);Q<1e-8&&(v=-S,V=0,D=m,Q=Math.sqrt(v*v+V*V+D*D)),Q<1e-8&&(v=0,V=1,D=0,Q=1),v/=Q,V/=Q,D/=Q,t>0&&v*Je+V*$e+D*Ke<0&&(v=-v,V=-V,D=-D),Je=v,$e=V,Ke=D,Ae.push(v,V,D)}for(let t=0;t<h;t++){const m=t/h,g=(t+1)/h,S=be*(1-m),T=be*(1-g),H=(1-m)*(1-m),ee=(1-g)*(1-g),N=Math.min(1,(P[0]+(ce[0]-P[0])*m)*G)*H,v=Math.min(1,(P[1]+(ce[1]-P[1])*m)*G)*H,V=Math.min(1,(P[2]+(ce[2]-P[2])*m)*G)*H,D=Math.min(1,(P[0]+(ce[0]-P[0])*g)*G)*ee,Q=Math.min(1,(P[1]+(ce[1]-P[1])*g)*G)*ee,Ze=Math.min(1,(P[2]+(ce[2]-P[2])*g)*G)*ee,et=i[t*3],tt=i[t*3+1],nt=i[t*3+2],st=i[(t+1)*3],rt=i[(t+1)*3+1],ot=i[(t+1)*3+2],ct=Ae[t*3],at=Ae[t*3+1],it=Ae[t*3+2],lt=Ae[(t+1)*3],ut=Ae[(t+1)*3+1],ft=Ae[(t+1)*3+2],zt=et+ct*S,At=tt+at*S,Rt=nt+it*S,dt=et-ct*S,pt=tt-at*S,mt=nt-it*S,ht=st+lt*T,yt=rt+ut*T,Mt=ot+ft*T,Pt=st-lt*T,Tt=rt-ut*T,Ct=ot-ft*T,l=C*3;n[l]=zt,n[l+1]=At,n[l+2]=Rt,o[l]=N,o[l+1]=v,o[l+2]=V,n[l+3]=dt,n[l+4]=pt,n[l+5]=mt,o[l+3]=N,o[l+4]=v,o[l+5]=V,n[l+6]=ht,n[l+7]=yt,n[l+8]=Mt,o[l+6]=D,o[l+7]=Q,o[l+8]=Ze,n[l+9]=dt,n[l+10]=pt,n[l+11]=mt,o[l+9]=N,o[l+10]=v,o[l+11]=V,n[l+12]=Pt,n[l+13]=Tt,n[l+14]=Ct,o[l+12]=D,o[l+13]=Q,o[l+14]=Ze,n[l+15]=ht,n[l+16]=yt,n[l+17]=Mt,o[l+15]=D,o[l+16]=Q,o[l+17]=Ze,C+=6}}const L=j.current;if(C<L){const Se=C*3,Ve=L*3;for(let O=Se;O<Ve;O++)n[O]=0,o[O]=0}j.current=C,$.setDrawRange(0,C),ne.needsUpdate=!0,M.needsUpdate=!0}}),W?Oe.jsxs(Oe.Fragment,{children:[Oe.jsx("instancedMesh",{ref:a=>{Pe.current=a,a&&(a.count=0,a.visible=!Fe)},args:[Ie,s,We],frustumCulled:!1,renderOrder:100,visible:p&&!Fe}),de&&Oe.jsx("mesh",{ref:pe,geometry:$,material:U,frustumCulled:!1,renderOrder:99,visible:p})]}):null}const Ut=`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _e=require("react/jsx-runtime"),i=require("react"),ke=require("@react-three/fiber"),qt=require("three"),Qe=require("hz-particles");function Ut(s){const p=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const d in s)if(d!=="default"){const V=Object.getOwnPropertyDescriptor(s,d);Object.defineProperty(p,d,V.get?V:{enumerable:!0,get:()=>s[d]})}}return p.default=s,Object.freeze(p)}const c=Ut(qt);function Je(s){return Math.abs(Math.sin(s*12.9898)*43758.5453)%1}function Bt(s){const p=Math.sin(s*54321.67)*43758.5453%1;return p<0?p+1:p}function wt(s,p,d,V){if(d<=0)return 0;const S=p/d;let Y=s.particleSize??.5;if(s.randomSize){const Z=s.minSize??.1,N=s.maxSize??.5;Y=Z+(N-Z)*Bt(d)}const $=Math.max(.01,Math.min(10,s.sizeLifetimeSpeed??1));if(s.fadeSizeEnabled&&(Y*=1-Math.pow(S,1/$)),s.increaseSizeEnabled&&(Y*=1+Math.pow(S,1/$)),s.pulseEnabled){const Z=s.pulseAmplitude??.5,N=s.pulseFrequency??1,oe=(s.pulsePhaseRandom??0)*Je(V)*Math.PI*2;Y*=1+Z*Math.sin(p*N*Math.PI*2+oe)}return Math.max(0,Y)}function zt(s,p,d,V){if(d<=0)return 0;let S=s.opacity??1;const Y=p/d;if(s.fadeEnabled&&(S*=Math.max(0,1-Y)),s.pulseEnabled&&s.pulseOpacity){const $=s.pulseAmplitude??.5,Z=s.pulseFrequency??1,se=(s.pulsePhaseRandom??0)*Je(V)*Math.PI*2;S*=Math.max(0,1+$*Math.sin(p*Z*Math.PI*2+se))}return Math.max(0,Math.min(1,S))}function At(s,p){return p===1?s:{...s,systems:s.systems.map(d=>({...d,particleSize:(d.particleSize??.5)*p,minSize:d.minSize!=null?d.minSize*p:void 0,maxSize:d.maxSize!=null?d.maxSize*p:void 0,particleSpeed:(d.particleSpeed??1)*p,minSpeed:d.minSpeed!=null?d.minSpeed*p:void 0,maxSpeed:d.maxSpeed!=null?d.maxSpeed*p:void 0,emissionTrailWidth:(d.emissionTrailWidth??.3)*p,emissionTrailShapeAmplitude:d.emissionTrailShapeAmplitude!=null?d.emissionTrailShapeAmplitude*p:void 0}))}}function Ot(s){let p=0;for(const d of s.systems)p+=d.maxParticles??1e4;return p}function Ht({preset:s,position:p,positionRef:d,autoPlay:V=!0,visible:S=!0,scale:Y=1,resetKey:$=0,onComplete:Z}){var Fe;const[N,se]=i.useState(typeof s=="string"?null:s);i.useEffect(()=>{typeof s=="string"?(se(null),Qe.fetchPreset(s).then(se).catch(l=>{console.error("[HZParticlesFX] Failed to fetch preset:",l)})):se(s)},[s]);const{camera:oe,gl:Le}=ke.useThree(),pe=i.useRef(null);if(!pe.current){const l=(Fe=Le.backend)==null?void 0:Fe.device;l&&(pe.current=l)}const Ce=pe.current,De=i.useRef(null),he=i.useRef(null),Ve=i.useRef(!1),O=i.useRef(!1),y=i.useMemo(()=>N?At(N,Y):null,[N,Y]),qe=i.useMemo(()=>(y==null?void 0:y.systems.every(l=>l.emissionTrailEnabled))??!1,[y]),Ye=i.useMemo(()=>y?y.systems.every(l=>l.emissionTrailEnabled)?1:Ot(y):0,[y]),We=i.useMemo(()=>p?p instanceof c.Vector3?p.clone():new c.Vector3(...p):new c.Vector3(0,0,0),[p]),ye=i.useMemo(()=>(y==null?void 0:y.systems.some(l=>l.emissionTrailEnabled))??!1,[y]),Ue=i.useMemo(()=>new c.PlaneGeometry(1,1),[]),o=i.useMemo(()=>{const l=document.createElement("canvas");l.width=64,l.height=64;const C=l.getContext("2d");C.clearRect(0,0,64,64);const q=C.createRadialGradient(32,32,0,32,32,32);q.addColorStop(0,"rgba(255,255,255,1)"),q.addColorStop(.7,"rgba(255,255,255,1)"),q.addColorStop(1,"rgba(255,255,255,0)"),C.fillStyle=q,C.beginPath(),C.arc(32,32,32,0,Math.PI*2),C.fill();const z=new c.CanvasTexture(l);z.flipY=!1;const G=new c.MeshBasicMaterial({color:16777215,transparent:!0,depthWrite:!1,alphaTest:.01,map:z,vertexColors:!0,side:c.DoubleSide,blending:c.AdditiveBlending});return G.needsUpdate=!0,G},[]),H=64,Me=i.useRef(null),k=i.useRef(0),v=512,R=i.useRef({buf:new Float32Array(v*6),head:0,count:0,elapsed:0}),{trailGeo:ne,trailPosAttr:ie,trailColAttr:w}=i.useMemo(()=>{const C=8*H*6,q=new Float32Array(C*3),z=new Float32Array(C*3),G=new c.BufferGeometry,me=new c.BufferAttribute(q,3);me.setUsage(c.DynamicDrawUsage),G.setAttribute("position",me);const xe=new c.BufferAttribute(z,3);return xe.setUsage(c.DynamicDrawUsage),G.setAttribute("color",xe),G.setDrawRange(0,0),{trailGeo:G,trailPosAttr:me,trailColAttr:xe}},[]),W=i.useMemo(()=>new c.MeshBasicMaterial({color:16777215,vertexColors:!0,transparent:!0,depthWrite:!1,side:c.DoubleSide,blending:c.AdditiveBlending}),[]);i.useEffect(()=>{if(!Ce||!y)return;const l=new Qe.ParticleSystemManager(Ce);return he.current=l,O.current=!1,l.replaceSystems(y).then(()=>{V&&S&&(l.respawnAllSystems(),O.current=!0)}).catch(C=>{console.error("[HZParticlesFX] replaceSystems FAILED:",C)}),()=>{typeof l.destroy=="function"&&l.destroy(),he.current=null}},[Ce,y]),i.useEffect(()=>{const l=he.current;l&&V&&S&&!O.current&&(l.respawnAllSystems(),O.current=!0,Ve.current=!1)},[V,S]);const de=i.useRef(null),ge=i.useRef($);i.useEffect(()=>{if($===ge.current)return;ge.current=$;const l=R.current;l.head=0,l.count=0,l.elapsed=0,ne.setDrawRange(0,0),de.current=null;const C=he.current;C&&(C.respawnAllSystems(),O.current=!0,Ve.current=!1)},[$]);const Se=i.useMemo(()=>new c.Matrix4,[]),Be=i.useMemo(()=>new c.Vector3,[]),ae=i.useMemo(()=>new c.Vector3,[]),ce=i.useMemo(()=>new c.Quaternion,[]),K=i.useMemo(()=>new c.Vector3,[]),Oe=i.useMemo(()=>new c.Vector3(0,0,1),[]),F=i.useMemo(()=>new c.Color,[]);return ke.useFrame((l,C)=>{var Ke;if(!S||!De.current||!he.current)return;const q=he.current,z=(d==null?void 0:d.current)??We,G=C>1?C/1e3:C,me=de.current,xe=me&&G>0,Tt=xe?(z.x-me.x)/G:0,Rt=xe?(z.y-me.y)/G:0,Pt=xe?(z.z-me.z)/G:0;de.current={x:z.x,y:z.y,z:z.z};for(const{system:t,config:a}of q.particleSystems)a.emissionTrailEnabled?(t.setSimulationTransform({position:[z.x,z.y,z.z],velocity:[Tt,Rt,Pt]}),a.shapeTranslationX=0,a.shapeTranslationY=0,a.shapeTranslationZ=0):(a.shapeTranslationX=z.x,a.shapeTranslationY=z.y,a.shapeTranslationZ=z.z);q.updateAllSystems(G);for(const{system:t}of q.particleSystems)t.readbackAndProcessParticles();if(ye){const t=R.current;t.elapsed+=G;let a=0,P=0;const U=(Ke=q.particleSystems.find(({config:j})=>j.emissionTrailEnabled))==null?void 0:Ke.config;if(U){const j=U.emissionTrailShape??"straight";if(j!=="straight"){const B=U.emissionTrailShapeAmplitude??.1,le=U.emissionTrailShapeFrequency??4,te=2*Math.PI*le*t.elapsed;j==="zigzag"?a=B*Math.sign(Math.sin(te)):j==="sine"?a=B*Math.sin(te):j==="spiral"&&(a=B*Math.sin(te),P=B*Math.cos(te))}}const ee=t.head*6;t.buf[ee]=z.x,t.buf[ee+1]=z.y,t.buf[ee+2]=z.z,t.buf[ee+3]=t.elapsed,t.buf[ee+4]=a,t.buf[ee+5]=P,t.head=(t.head+1)%v,t.count<v&&t.count++}const be=De.current;let ve=0;for(let t=0;t<q.particleSystems.length;t++){const{system:a,config:P}=q.particleSystems[t];if(P.emissionTrailEnabled)continue;const U=a.particleData,ee=a.activeParticles;if(!(!U||ee<=0))for(let j=0;j<ee;j++){const B=j*8,le=U[B+0],te=U[B+1],D=U[B+2];let we=U[B+3],ze=U[B+4],Q=U[B+5];const Ae=U[B+6],re=U[B+7];if(Ae>=re||re<=0)continue;const g=Ae/re;if(P.colorTransitionEnabled){const I=P.startColor??[1,0,0],ue=P.endColor??[0,0,1];we=I[0]+(ue[0]-I[0])*g,ze=I[1]+(ue[1]-I[1])*g,Q=I[2]+(ue[2]-I[2])*g}const Te=P.bloomIntensity??1;we=Math.min(1,we*Te),ze=Math.min(1,ze*Te),Q=Math.min(1,Q*Te);const Re=zt(P,Ae,re,j);we*=Re,ze*=Re,Q*=Re;const J=wt(P,Ae,re,j);if(!(J<=0)){if(Be.set(le,te,D),ae.subVectors(oe.position,Be).normalize(),ce.setFromUnitVectors(Oe,ae),P.velocityStretchEnabled&&a.particleVelocities){const I=j*4,ue=a.particleVelocities[I],Ie=a.particleVelocities[I+1],E=a.particleVelocities[I+2],fe=Math.sqrt(ue*ue+Ie*Ie+E*E);if(fe>.001){const Ne=P.velocityStretchFactor??1,X=J*(1+fe*Ne);K.set(J,X,1),ae.set(ue,Ie,E).normalize(),ce.setFromUnitVectors(Oe,ae);const n=(X-J)*.5;Be.addScaledVector(ae,n)}else K.set(J,J,1)}else K.set(J,J,1);Se.compose(Be,ce,K),be.setMatrixAt(ve,Se),F.setRGB(we,ze,Q),be.setColorAt(ve,F),ve++}}}be.count=ve,be.visible=ve>0,ve>0&&(be.instanceMatrix.needsUpdate=!0,be.instanceColor&&(be.instanceColor.needsUpdate=!0));const $e=ve>0||q.particleSystems.some(({system:t})=>t.emitting||t.activeParticles>0);if(Ve.current&&!$e&&(O.current=!1,Z==null||Z()),Ve.current=$e,ye&&Me.current){const t=ie.array,a=w.array;let P=0;const U=oe.position.x,ee=oe.position.y,j=oe.position.z;for(let le=0;le<q.particleSystems.length;le++){const{system:te,config:D}=q.particleSystems[le];if(!D.emissionTrailEnabled||!te.emitting&&te.activeParticles<=0)continue;const we=D.emissionTrailDuration??1,ze=D.emissionTrailWidth??.3,Q=D.bloomIntensity??1,Ae=ze*.5,re=R.current,g=re.buf,Te=re.count,Re=re.head,J=re.elapsed;if(Te<2)continue;const I=((Re-Te)%v+v)%v,ue=J-g[I*6+3],Ie=Math.min(we,ue);if(Ie<.001)continue;const E=D.startColor??[1,1,1],fe=D.colorTransitionEnabled?D.endColor??[1,1,1]:E,Ne=(e,r)=>{const h=J-e;for(let u=0;u<Te-1;u++){const x=((Re-1-u)%v+v)%v,T=((Re-2-u)%v+v)%v,_=g[x*6+3],A=g[T*6+3];if(h>=A&&h<=_){const m=_!==A?(h-A)/(_-A):0;r[0]=g[T*6]+(g[x*6]-g[T*6])*m,r[1]=g[T*6+1]+(g[x*6+1]-g[T*6+1])*m,r[2]=g[T*6+2]+(g[x*6+2]-g[T*6+2])*m,r[3]=g[T*6+4]+(g[x*6+4]-g[T*6+4])*m,r[4]=g[T*6+5]+(g[x*6+5]-g[T*6+5])*m;return}}r[0]=g[I*6],r[1]=g[I*6+1],r[2]=g[I*6+2],r[3]=g[I*6+4],r[4]=g[I*6+5]},X=Math.max(1,Math.min(H,D.emissionTrailSegments??8)),n=[z.x,z.y,z.z],He=D.emissionTrailShape??"straight",Ge=[];{const e=D.emissionTrailShapeAmplitude??.1,r=D.emissionTrailShapeFrequency??4,h=2*Math.PI*r*J;let u=0,x=0;He==="zigzag"?u=e*Math.sign(Math.sin(h)):He==="sine"?u=e*Math.sin(h):He==="spiral"&&(u=e*Math.sin(h),x=e*Math.cos(h)),Ge.push(u,x)}const Ee=[0,0,0,0,0];for(let e=1;e<=X;e++){const r=e/X*Ie;Ne(r,Ee),n.push(Ee[0],Ee[1],Ee[2]),Ge.push(Ee[3],Ee[4])}const et=n[0]-n[X*3],tt=n[1]-n[X*3+1],st=n[2]-n[X*3+2];if(et*et+tt*tt+st*st<1e-6)continue;let nt=0,rt=0,ot=0;const Pe=[],Xe=[];for(let e=0;e<=X;e++){let r,h,u;e===0?(r=n[3]-n[0],h=n[4]-n[1],u=n[5]-n[2]):e===X?(r=n[e*3]-n[(e-1)*3],h=n[e*3+1]-n[(e-1)*3+1],u=n[e*3+2]-n[(e-1)*3+2]):(r=n[(e+1)*3]-n[(e-1)*3],h=n[(e+1)*3+1]-n[(e-1)*3+1],u=n[(e+1)*3+2]-n[(e-1)*3+2]);let x=Math.sqrt(r*r+h*h+u*u);x<1e-8&&(r=0,h=0,u=1,x=1),r/=x,h/=x,u/=x,Xe.push(r,h,u);const T=U-n[e*3],_=ee-n[e*3+1],A=j-n[e*3+2];let m=h*A-u*_,M=u*T-r*A,b=r*_-h*T,L=Math.sqrt(m*m+M*M+b*b);L<1e-8&&(m=-u,M=0,b=r,L=Math.sqrt(m*m+M*M+b*b)),L<1e-8&&(m=0,M=1,b=0,L=1),m/=L,M/=L,b/=L,e>0&&m*nt+M*rt+b*ot<0&&(m=-m,M=-M,b=-b),nt=m,rt=M,ot=b,Pe.push(m,M,b)}if(He!=="straight")for(let e=1;e<=X;e++){const r=Ge[e*2],h=Ge[e*2+1];if(Math.abs(r)<1e-8&&Math.abs(h)<1e-8)continue;const u=e*3,x=Xe[u],T=Xe[u+1],_=Xe[u+2];let A=-_,m=0,M=x,b=Math.sqrt(A*A+M*M);if(b<1e-6&&(A=0,m=_,M=-T,b=Math.sqrt(A*A+m*m+M*M),b<1e-6&&(A=1,m=0,M=0,b=1)),A/=b,m/=b,M/=b,He==="spiral"){const L=T*M-_*m,je=_*A-x*M,Ze=x*m-T*A;n[u]+=A*r+L*h,n[u+1]+=m*r+je*h,n[u+2]+=M*r+Ze*h}else n[u]+=A*r,n[u+1]+=m*r,n[u+2]+=M*r}for(let e=0;e<X;e++){const r=e/X,h=(e+1)/X,u=Ae*(1-r),x=Ae*(1-h),T=(1-r)*(1-r),_=(1-h)*(1-h),A=Math.min(1,(E[0]+(fe[0]-E[0])*r)*Q)*T,m=Math.min(1,(E[1]+(fe[1]-E[1])*r)*Q)*T,M=Math.min(1,(E[2]+(fe[2]-E[2])*r)*Q)*T,b=Math.min(1,(E[0]+(fe[0]-E[0])*h)*Q)*_,L=Math.min(1,(E[1]+(fe[1]-E[1])*h)*Q)*_,je=Math.min(1,(E[2]+(fe[2]-E[2])*h)*Q)*_,Ze=n[e*3],it=n[e*3+1],at=n[e*3+2],ct=n[(e+1)*3],lt=n[(e+1)*3+1],ut=n[(e+1)*3+2],ft=Pe[e*3],pt=Pe[e*3+1],dt=Pe[e*3+2],mt=Pe[(e+1)*3],ht=Pe[(e+1)*3+1],yt=Pe[(e+1)*3+2],Ct=Ze+ft*u,Dt=it+pt*u,Vt=at+dt*u,Mt=Ze-ft*u,gt=it-pt*u,St=at-dt*u,xt=ct+mt*x,bt=lt+ht*x,vt=ut+yt*x,Ft=ct-mt*x,It=lt-ht*x,Et=ut-yt*x,f=P*3;t[f]=Ct,t[f+1]=Dt,t[f+2]=Vt,a[f]=A,a[f+1]=m,a[f+2]=M,t[f+3]=Mt,t[f+4]=gt,t[f+5]=St,a[f+3]=A,a[f+4]=m,a[f+5]=M,t[f+6]=xt,t[f+7]=bt,t[f+8]=vt,a[f+6]=b,a[f+7]=L,a[f+8]=je,t[f+9]=Mt,t[f+10]=gt,t[f+11]=St,a[f+9]=A,a[f+10]=m,a[f+11]=M,t[f+12]=Ft,t[f+13]=It,t[f+14]=Et,a[f+12]=b,a[f+13]=L,a[f+14]=je,t[f+15]=xt,t[f+16]=bt,t[f+17]=vt,a[f+15]=b,a[f+16]=L,a[f+17]=je,P+=6}}const B=k.current;if(P<B){const le=P*3,te=B*3;for(let D=le;D<te;D++)t[D]=0,a[D]=0}k.current=P,ne.setDrawRange(0,P),ie.needsUpdate=!0,w.needsUpdate=!0}}),N?_e.jsxs(_e.Fragment,{children:[_e.jsx("instancedMesh",{ref:l=>{De.current=l,l&&(l.count=0,l.visible=!qe)},args:[Ue,o,Ye],frustumCulled:!1,renderOrder:100,visible:S&&!qe}),ye&&_e.jsx("mesh",{ref:Me,geometry:ne,material:W,frustumCulled:!1,renderOrder:99,visible:S})]}):null}const jt=`
2
2
  attribute vec4 aColor;
3
3
  varying vec4 vColor;
4
4
  void main() {
5
5
  vColor = aColor;
6
6
  gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
7
7
  }
8
- `,Bt=`
8
+ `,_t=`
9
9
  varying vec4 vColor;
10
10
  void main() {
11
11
  gl_FragColor = vColor;
12
12
  }
13
- `;function Ot({positionRef:e,duration:u=1,width:f=.3,color:A=[1,1,1],maxPoints:p=256,minDistance:_=.05,opacity:Z=1,blending:q=c.AdditiveBlending,visible:W=!0}){const{camera:J}=je.useThree(),te=r.useRef(null),_e=r.useRef({positions:new Float32Array(p*3),times:new Float32Array(p),head:0,count:0,lastPos:new c.Vector3(1/0,1/0,1/0),elapsed:0}),{geometry:ae,posAttr:Re,colorAttr:Pe,indexBuf:fe}=r.useMemo(()=>{const de=p*2,Ie=new Float32Array(de*3),s=new Float32Array(de*4),h=new c.BufferGeometry,pe=new c.BufferAttribute(Ie,3);pe.setUsage(c.DynamicDrawUsage),h.setAttribute("position",pe);const j=new c.BufferAttribute(s,4);j.setUsage(c.DynamicDrawUsage),h.setAttribute("aColor",j);const y=(p-1)*6,b=new Uint32Array(y);for(let ne=0;ne<p-1;ne++){const M=ne*2,U=ne*6;b[U]=M,b[U+1]=M+1,b[U+2]=M+2,b[U+3]=M+1,b[U+4]=M+3,b[U+5]=M+2}const $=new c.BufferAttribute(b,1);return h.setIndex($),h.setDrawRange(0,0),{geometry:h,posAttr:pe,colorAttr:j,indexBuf:$}},[p]),Te=r.useMemo(()=>new c.ShaderMaterial({vertexShader:Ut,fragmentShader:Bt,transparent:!0,depthWrite:!1,side:c.DoubleSide,blending:q}),[q]),E=r.useMemo(()=>new c.Vector3,[]),d=r.useMemo(()=>new c.Vector3,[]),Fe=r.useMemo(()=>new c.Vector3,[]),We=r.useMemo(()=>new c.Vector3(0,1,0),[]),He=r.useMemo(()=>new c.Vector3,[]);return je.useFrame((de,Ie)=>{if(!te.current)return;const s=_e.current;if(s.elapsed+=Ie,!W){s.count=0,s.head=0,s.lastPos.set(1/0,1/0,1/0),ae.setDrawRange(0,0);return}const h=e.current;if(!h)return;if(s.lastPos.distanceTo(h)>=_){const M=(s.head+s.count)%p;s.positions[M*3]=h.x,s.positions[M*3+1]=h.y,s.positions[M*3+2]=h.z,s.times[M]=s.elapsed,s.count<p?s.count++:s.head=(s.head+1)%p,s.lastPos.copy(h)}for(;s.count>0;){const M=s.head;if(s.elapsed-s.times[M]>u)s.head=(s.head+1)%p,s.count--;else break}if(s.count<2){ae.setDrawRange(0,0);return}const j=Re.array,y=Pe.array;let b=null;const $=s.count;for(let M=0;M<$;M++){const U=(s.head+M)%p,ie=s.positions[U*3],me=s.positions[U*3+1],he=s.positions[U*3+2],se=1-(s.elapsed-s.times[U])/u;if(M<$-1){const Ce=(s.head+M+1)%p;E.set(s.positions[Ce*3]-ie,s.positions[Ce*3+1]-me,s.positions[Ce*3+2]-he);const a=E.length();a>1e-6?E.divideScalar(a):b&&E.copy(b)}else b&&E.copy(b);Fe.set(J.position.x-ie,J.position.y-me,J.position.z-he),d.crossVectors(E,Fe);let re=d.length();re<1e-6&&(He.crossVectors(E,We),d.copy(He),re=d.length(),re<1e-6&&(d.set(1,0,0),re=1)),d.divideScalar(re);const X=f*se,Be=Z*se*se,R=M*2;j[R*3]=ie+d.x*X,j[R*3+1]=me+d.y*X,j[R*3+2]=he+d.z*X,j[(R+1)*3]=ie-d.x*X,j[(R+1)*3+1]=me-d.y*X,j[(R+1)*3+2]=he-d.z*X,y[R*4]=A[0],y[R*4+1]=A[1],y[R*4+2]=A[2],y[R*4+3]=Be,y[(R+1)*4]=A[0],y[(R+1)*4+1]=A[1],y[(R+1)*4+2]=A[2],y[(R+1)*4+3]=Be,b=b||new c.Vector3,b.copy(E)}const ne=($-1)*6;ae.setDrawRange(0,ne),Re.needsUpdate=!0,Pe.needsUpdate=!0}),Oe.jsx("mesh",{ref:te,geometry:ae,material:Te,frustumCulled:!1,renderOrder:101,visible:W})}Object.defineProperty(exports,"fetchPreset",{enumerable:!0,get:()=>Xe.fetchPreset});exports.HZParticlesFX=It;exports.HZTrailRibbon=Ot;exports.computeParticleOpacity=St;exports.computeParticleSize=xt;exports.particleHash=ke;exports.scalePreset=gt;
13
+ `;function Wt({positionRef:s,duration:p=1,width:d=.3,color:V=[1,1,1],maxPoints:S=256,minDistance:Y=.05,opacity:$=1,blending:Z=c.AdditiveBlending,visible:N=!0}){const{camera:se}=ke.useThree(),oe=i.useRef(null),Le=i.useRef({positions:new Float32Array(S*3),times:new Float32Array(S),head:0,count:0,lastPos:new c.Vector3(1/0,1/0,1/0),elapsed:0}),{geometry:pe,posAttr:Ce,colorAttr:De,indexBuf:he}=i.useMemo(()=>{const ye=S*2,Ue=new Float32Array(ye*3),o=new Float32Array(ye*4),H=new c.BufferGeometry,Me=new c.BufferAttribute(Ue,3);Me.setUsage(c.DynamicDrawUsage),H.setAttribute("position",Me);const k=new c.BufferAttribute(o,4);k.setUsage(c.DynamicDrawUsage),H.setAttribute("aColor",k);const v=(S-1)*6,R=new Uint32Array(v);for(let ie=0;ie<S-1;ie++){const w=ie*2,W=ie*6;R[W]=w,R[W+1]=w+1,R[W+2]=w+2,R[W+3]=w+1,R[W+4]=w+3,R[W+5]=w+2}const ne=new c.BufferAttribute(R,1);return H.setIndex(ne),H.setDrawRange(0,0),{geometry:H,posAttr:Me,colorAttr:k,indexBuf:ne}},[S]),Ve=i.useMemo(()=>new c.ShaderMaterial({vertexShader:jt,fragmentShader:_t,transparent:!0,depthWrite:!1,side:c.DoubleSide,blending:Z}),[Z]),O=i.useMemo(()=>new c.Vector3,[]),y=i.useMemo(()=>new c.Vector3,[]),qe=i.useMemo(()=>new c.Vector3,[]),Ye=i.useMemo(()=>new c.Vector3(0,1,0),[]),We=i.useMemo(()=>new c.Vector3,[]);return ke.useFrame((ye,Ue)=>{if(!oe.current)return;const o=Le.current;if(o.elapsed+=Ue,!N){o.count=0,o.head=0,o.lastPos.set(1/0,1/0,1/0),pe.setDrawRange(0,0);return}const H=s.current;if(!H)return;if(o.lastPos.distanceTo(H)>=Y){const w=(o.head+o.count)%S;o.positions[w*3]=H.x,o.positions[w*3+1]=H.y,o.positions[w*3+2]=H.z,o.times[w]=o.elapsed,o.count<S?o.count++:o.head=(o.head+1)%S,o.lastPos.copy(H)}for(;o.count>0;){const w=o.head;if(o.elapsed-o.times[w]>p)o.head=(o.head+1)%S,o.count--;else break}if(o.count<2){pe.setDrawRange(0,0);return}const k=Ce.array,v=De.array;let R=null;const ne=o.count;for(let w=0;w<ne;w++){const W=(o.head+w)%S,de=o.positions[W*3],ge=o.positions[W*3+1],Se=o.positions[W*3+2],ae=1-(o.elapsed-o.times[W])/p;if(w<ne-1){const Fe=(o.head+w+1)%S;O.set(o.positions[Fe*3]-de,o.positions[Fe*3+1]-ge,o.positions[Fe*3+2]-Se);const l=O.length();l>1e-6?O.divideScalar(l):R&&O.copy(R)}else R&&O.copy(R);qe.set(se.position.x-de,se.position.y-ge,se.position.z-Se),y.crossVectors(O,qe);let ce=y.length();ce<1e-6&&(We.crossVectors(O,Ye),y.copy(We),ce=y.length(),ce<1e-6&&(y.set(1,0,0),ce=1)),y.divideScalar(ce);const K=d*ae,Oe=$*ae*ae,F=w*2;k[F*3]=de+y.x*K,k[F*3+1]=ge+y.y*K,k[F*3+2]=Se+y.z*K,k[(F+1)*3]=de-y.x*K,k[(F+1)*3+1]=ge-y.y*K,k[(F+1)*3+2]=Se-y.z*K,v[F*4]=V[0],v[F*4+1]=V[1],v[F*4+2]=V[2],v[F*4+3]=Oe,v[(F+1)*4]=V[0],v[(F+1)*4+1]=V[1],v[(F+1)*4+2]=V[2],v[(F+1)*4+3]=Oe,R=R||new c.Vector3,R.copy(O)}const ie=(ne-1)*6;pe.setDrawRange(0,ie),Ce.needsUpdate=!0,De.needsUpdate=!0}),_e.jsx("mesh",{ref:oe,geometry:pe,material:Ve,frustumCulled:!1,renderOrder:101,visible:N})}Object.defineProperty(exports,"fetchPreset",{enumerable:!0,get:()=>Qe.fetchPreset});exports.HZParticlesFX=Ht;exports.HZTrailRibbon=Wt;exports.computeParticleOpacity=zt;exports.computeParticleSize=wt;exports.particleHash=Je;exports.scalePreset=At;