hz-particles 1.0.13 → 1.0.15

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