hz-particles 1.2.0 → 1.3.0

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,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),Z=require("@react-three/fiber"),X=require("hz-particles"),K=require("react/jsx-runtime"),Q=require("three");function Y(n){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const a in n)if(a!=="default"){const e=Object.getOwnPropertyDescriptor(n,a);Object.defineProperty(t,a,e.get?e:{enumerable:!0,get:()=>n[a]})}}return t.default=n,Object.freeze(t)}const p=Y(Q);function J(n,t){if(t===1)return n;const a=(e,i)=>e!=null?e*t:i*t;return{...n,systems:n.systems.map(e=>({...e,particleSize:a(e.particleSize,.5),minSize:e.minSize!=null?e.minSize*t:void 0,maxSize:e.maxSize!=null?e.maxSize*t:void 0,particleSpeed:(e.particleSpeed??1)*t,minSpeed:e.minSpeed!=null?e.minSpeed*t:void 0,maxSpeed:e.maxSpeed!=null?e.maxSpeed*t:void 0,cubeLength:e.cubeLength!=null?e.cubeLength*t:void 0,outerLength:e.outerLength!=null?e.outerLength*t:void 0,innerLength:e.innerLength!=null?e.innerLength*t:void 0,outerRadius:e.outerRadius!=null?e.outerRadius*t:void 0,innerRadius:e.innerRadius!=null?e.innerRadius*t:void 0,squareSize:e.squareSize!=null?e.squareSize*t:void 0,squareInnerSize:e.squareInnerSize!=null?e.squareInnerSize*t:void 0,circleInnerRadius:e.circleInnerRadius!=null?e.circleInnerRadius*t:void 0,circleOuterRadius:e.circleOuterRadius!=null?e.circleOuterRadius*t:void 0,cylinderInnerRadius:e.cylinderInnerRadius!=null?e.cylinderInnerRadius*t:void 0,cylinderOuterRadius:e.cylinderOuterRadius!=null?e.cylinderOuterRadius*t:void 0,cylinderHeight:e.cylinderHeight!=null?e.cylinderHeight*t:void 0,emissionTrailWidth:(e.emissionTrailWidth??.3)*t,emissionTrailDuration:(e.emissionTrailDuration??1)*t,emissionTrailMinDistance:e.emissionTrailMinDistance!=null?e.emissionTrailMinDistance*t:void 0,emissionTrailShapeAmplitude:e.emissionTrailShapeAmplitude!=null?e.emissionTrailShapeAmplitude*t:void 0}))}}function $({preset:n,positionRef:t,position:a=[0,0,0],scale:e=1,active:i=!0,renderPriority:z=1,noOcclusion:A=!1}){const d=s.useRef(null),v=s.useRef(null),x=s.useRef(!1),I=s.useRef(0),C=s.useRef(i);C.current=i;const y=s.useRef(a);y.current=a;const D=s.useMemo(()=>e&&e!==1?J(n,e):n,[n,e]),E=l=>t?l.addMovingEmitter(D,{getPosition:()=>{const m=t.current;return C.current&&m?[m.x,m.y,m.z]:null}}):l.addEmitter(D,y.current);return s.useEffect(()=>{var f,u;const l=d.current;if(!l)return;let m=!1;return(u=(f=v.current)==null?void 0:f.remove)==null||u.call(f),v.current=null,E(l).then(c=>{var T;m?(T=c==null?void 0:c.remove)==null||T.call(c):v.current=c}),()=>{m=!0}},[D]),s.useEffect(()=>()=>{var l,m;(m=(l=d.current)==null?void 0:l.destroy)==null||m.call(l),d.current=null,v.current=null,x.current=!1},[]),Z.useFrame(l=>{l.gl.render(l.scene,l.camera);const m=performance.now(),f=I.current?Math.min(.05,(m-I.current)/1e3):.016;I.current=m;const u=l.gl,c=u.backend;!d.current&&!x.current&&(c!=null&&c.device)&&(c!=null&&c.context)&&(x.current=!0,X.initHzFxOverlay({device:c.device,context:c.context,canvas:u.domElement},{getSceneDepth:A?()=>null:X.makeThreeSceneDepth(u)}).then(R=>(d.current=R,E(R))).then(R=>{v.current=R}).catch(R=>console.error("[HZFaithfulFX] init failed:",R)));const T=d.current;if(T){const R=l.camera;T.setCamera(R.projectionMatrix.elements,R.matrixWorldInverse.elements,R.position),T.render(f)}},z),null}const ee=`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react"),Z=require("@react-three/fiber"),X=require("hz-particles"),K=require("react/jsx-runtime"),Q=require("three");function Y(n){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const s in n)if(s!=="default"){const e=Object.getOwnPropertyDescriptor(n,s);Object.defineProperty(t,s,e.get?e:{enumerable:!0,get:()=>n[s]})}}return t.default=n,Object.freeze(t)}const p=Y(Q);function J(n,t){if(t===1)return n;const s=(e,u)=>e!=null?e*t:u*t;return{...n,systems:n.systems.map(e=>({...e,particleSize:s(e.particleSize,.5),minSize:e.minSize!=null?e.minSize*t:void 0,maxSize:e.maxSize!=null?e.maxSize*t:void 0,particleSpeed:(e.particleSpeed??1)*t,minSpeed:e.minSpeed!=null?e.minSpeed*t:void 0,maxSpeed:e.maxSpeed!=null?e.maxSpeed*t:void 0,cubeLength:e.cubeLength!=null?e.cubeLength*t:void 0,outerLength:e.outerLength!=null?e.outerLength*t:void 0,innerLength:e.innerLength!=null?e.innerLength*t:void 0,outerRadius:e.outerRadius!=null?e.outerRadius*t:void 0,innerRadius:e.innerRadius!=null?e.innerRadius*t:void 0,squareSize:e.squareSize!=null?e.squareSize*t:void 0,squareInnerSize:e.squareInnerSize!=null?e.squareInnerSize*t:void 0,circleInnerRadius:e.circleInnerRadius!=null?e.circleInnerRadius*t:void 0,circleOuterRadius:e.circleOuterRadius!=null?e.circleOuterRadius*t:void 0,cylinderInnerRadius:e.cylinderInnerRadius!=null?e.cylinderInnerRadius*t:void 0,cylinderOuterRadius:e.cylinderOuterRadius!=null?e.cylinderOuterRadius*t:void 0,cylinderHeight:e.cylinderHeight!=null?e.cylinderHeight*t:void 0,emissionTrailWidth:(e.emissionTrailWidth??.3)*t,emissionTrailDuration:(e.emissionTrailDuration??1)*t,emissionTrailMinDistance:e.emissionTrailMinDistance!=null?e.emissionTrailMinDistance*t:void 0,emissionTrailShapeAmplitude:e.emissionTrailShapeAmplitude!=null?e.emissionTrailShapeAmplitude*t:void 0}))}}function $({preset:n,positionRef:t,position:s=[0,0,0],scale:e=1,active:u=!0,renderPriority:w=1,noOcclusion:I=!1,respectReducedMotion:z=!0}){const f=c.useRef(null),S=c.useRef(null),T=c.useRef(!1),F=c.useRef(0),y=c.useRef(u);y.current=u;const P=c.useRef(s);P.current=s;const C=c.useRef(!1),L=c.useMemo(()=>e&&e!==1?J(n,e):n,[n,e]),q=i=>t?i.addMovingEmitter(L,{getPosition:()=>{const o=t.current;return y.current&&o?[o.x,o.y,o.z]:null}}):i.addEmitter(L,P.current);return c.useEffect(()=>{var d,h;const i=f.current;if(!i)return;let o=!1;return(h=(d=S.current)==null?void 0:d.remove)==null||h.call(d),S.current=null,q(i).then(l=>{var x;o?(x=l==null?void 0:l.remove)==null||x.call(l):S.current=l}),()=>{o=!0}},[L]),c.useEffect(()=>{var d;if(typeof window>"u"||!window.matchMedia)return;const i=window.matchMedia("(prefers-reduced-motion: reduce)"),o=()=>{C.current=i.matches};return o(),(d=i.addEventListener)==null||d.call(i,"change",o),()=>{var h;return(h=i.removeEventListener)==null?void 0:h.call(i,"change",o)}},[]),c.useEffect(()=>()=>{var i,o,d,h;(o=(i=S.current)==null?void 0:i.remove)==null||o.call(i),(h=(d=f.current)==null?void 0:d.destroy)==null||h.call(d),f.current=null,S.current=null,T.current=!1},[]),Z.useFrame(i=>{i.gl.render(i.scene,i.camera);const o=performance.now(),d=F.current?Math.min(.05,(o-F.current)/1e3):.016;F.current=o;const h=i.gl,l=h.backend;!f.current&&!T.current&&(l!=null&&l.device)&&(l!=null&&l.context)&&(T.current=!0,X.initHzFxOverlay({device:l.device,context:l.context,canvas:h.domElement},{getSceneDepth:I?()=>null:X.makeThreeSceneDepth(h)}).then(v=>(f.current=v,q(v))).then(v=>{S.current=v}).catch(v=>console.error("[HZFaithfulFX] init failed:",v)));const x=f.current;if(x){const v=i.camera;x.setCamera(v.projectionMatrix.elements,v.matrixWorldInverse.elements,v.position),z&&C.current||x.render(d)}},w),null}const ee=`
2
2
  attribute vec4 aColor;
3
3
  varying vec4 vColor;
4
4
  void main() {
@@ -10,4 +10,4 @@ varying vec4 vColor;
10
10
  void main() {
11
11
  gl_FragColor = vColor;
12
12
  }
13
- `;function ne({positionRef:n,duration:t=1,width:a=.3,color:e=[1,1,1],maxPoints:i=256,minDistance:z=.05,opacity:A=1,blending:d=p.AdditiveBlending,visible:v=!0}){const{camera:x}=Z.useThree(),I=s.useRef(null),C=s.useRef({positions:new Float32Array(i*3),times:new Float32Array(i),head:0,count:0,lastPos:new p.Vector3(1/0,1/0,1/0),elapsed:0}),{geometry:y,posAttr:D,colorAttr:E,indexBuf:l}=s.useMemo(()=>{const B=i*2,U=new Float32Array(B*3),r=new Float32Array(B*4),M=new p.BufferGeometry,H=new p.BufferAttribute(U,3);H.setUsage(p.DynamicDrawUsage),M.setAttribute("position",H);const w=new p.BufferAttribute(r,4);w.setUsage(p.DynamicDrawUsage),M.setAttribute("aColor",w);const b=(i-1)*6,h=new Uint32Array(b);for(let F=0;F<i-1;F++){const o=F*2,g=F*6;h[g]=o,h[g+1]=o+1,h[g+2]=o+2,h[g+3]=o+1,h[g+4]=o+3,h[g+5]=o+2}const O=new p.BufferAttribute(h,1);return M.setIndex(O),M.setDrawRange(0,0),{geometry:M,posAttr:H,colorAttr:w,indexBuf:O}},[i]),m=s.useMemo(()=>new p.ShaderMaterial({vertexShader:ee,fragmentShader:te,transparent:!0,depthWrite:!1,side:p.DoubleSide,blending:d}),[d]),f=s.useMemo(()=>new p.Vector3,[]),u=s.useMemo(()=>new p.Vector3,[]),c=s.useMemo(()=>new p.Vector3,[]),T=s.useMemo(()=>new p.Vector3(0,1,0),[]),R=s.useMemo(()=>new p.Vector3,[]);return Z.useFrame((B,U)=>{if(!I.current)return;const r=C.current;if(r.elapsed+=U,!v){r.count=0,r.head=0,r.lastPos.set(1/0,1/0,1/0),y.setDrawRange(0,0);return}const M=n.current;if(!M)return;if(r.lastPos.distanceTo(M)>=z){const o=(r.head+r.count)%i;r.positions[o*3]=M.x,r.positions[o*3+1]=M.y,r.positions[o*3+2]=M.z,r.times[o]=r.elapsed,r.count<i?r.count++:r.head=(r.head+1)%i,r.lastPos.copy(M)}for(;r.count>0;){const o=r.head;if(r.elapsed-r.times[o]>t)r.head=(r.head+1)%i,r.count--;else break}if(r.count<2){y.setDrawRange(0,0);return}const w=D.array,b=E.array;let h=null;const O=r.count;for(let o=0;o<O;o++){const g=(r.head+o)%i,L=r.positions[g*3],V=r.positions[g*3+1],j=r.positions[g*3+2],_=1-(r.elapsed-r.times[g])/t;if(o<O-1){const W=(r.head+o+1)%i;f.set(r.positions[W*3]-L,r.positions[W*3+1]-V,r.positions[W*3+2]-j);const N=f.length();N>1e-6?f.divideScalar(N):h&&f.copy(h)}else h&&f.copy(h);c.set(x.position.x-L,x.position.y-V,x.position.z-j),u.crossVectors(f,c);let P=u.length();P<1e-6&&(R.crossVectors(f,T),u.copy(R),P=u.length(),P<1e-6&&(u.set(1,0,0),P=1)),u.divideScalar(P);const q=a*_,G=A*_*_,S=o*2;w[S*3]=L+u.x*q,w[S*3+1]=V+u.y*q,w[S*3+2]=j+u.z*q,w[(S+1)*3]=L-u.x*q,w[(S+1)*3+1]=V-u.y*q,w[(S+1)*3+2]=j-u.z*q,b[S*4]=e[0],b[S*4+1]=e[1],b[S*4+2]=e[2],b[S*4+3]=G,b[(S+1)*4]=e[0],b[(S+1)*4+1]=e[1],b[(S+1)*4+2]=e[2],b[(S+1)*4+3]=G,h=h||new p.Vector3,h.copy(f)}const F=(O-1)*6;y.setDrawRange(0,F),D.needsUpdate=!0,E.needsUpdate=!0}),K.jsx("mesh",{ref:I,geometry:y,material:m,frustumCulled:!1,renderOrder:101,visible:v})}function k(n){return Math.abs(Math.sin(n*12.9898)*43758.5453)%1}function re(n){const t=Math.sin(n*54321.67)*43758.5453%1;return t<0?t+1:t}function ie(n,t,a,e){if(a<=0)return 0;const i=t/a;let z=n.particleSize??.5;if(n.randomSize){const d=n.minSize??.1,v=n.maxSize??.5;z=d+(v-d)*re(a)}const A=Math.max(.01,Math.min(10,n.sizeLifetimeSpeed??1));if(n.fadeSizeEnabled&&(z*=1-Math.pow(i,1/A)),n.increaseSizeEnabled&&(z*=1+Math.pow(i,1/A)),n.pulseEnabled){const d=n.pulseAmplitude??.5,v=n.pulseFrequency??1,I=(n.pulsePhaseRandom??0)*k(e)*Math.PI*2;z*=1+d*Math.sin(t*v*Math.PI*2+I)}return Math.max(0,z)}function oe(n,t,a,e){if(a<=0)return 0;let i=n.opacity??1;const z=t/a;if(n.fadeEnabled&&(i*=Math.max(0,1-z)),n.pulseEnabled&&n.pulseOpacity){const A=n.pulseAmplitude??.5,d=n.pulseFrequency??1,x=(n.pulsePhaseRandom??0)*k(e)*Math.PI*2;i*=Math.max(0,1+A*Math.sin(t*d*Math.PI*2+x))}return Math.max(0,Math.min(1,i))}Object.defineProperty(exports,"fetchPreset",{enumerable:!0,get:()=>X.fetchPreset});exports.HZFaithfulFX=$;exports.HZTrailRibbon=ne;exports.computeParticleOpacity=oe;exports.computeParticleSize=ie;exports.particleHash=k;exports.scalePreset=J;
13
+ `;function ne({positionRef:n,duration:t=1,width:s=.3,color:e=[1,1,1],maxPoints:u=256,minDistance:w=.05,opacity:I=1,blending:z=p.AdditiveBlending,visible:f=!0}){const{camera:S}=Z.useThree(),T=c.useRef(null),F=c.useRef({positions:new Float32Array(u*3),times:new Float32Array(u),head:0,count:0,lastPos:new p.Vector3(1/0,1/0,1/0),elapsed:0}),{geometry:y,posAttr:P,colorAttr:C,indexBuf:L}=c.useMemo(()=>{const x=u*2,v=new Float32Array(x*3),r=new Float32Array(x*4),M=new p.BufferGeometry,V=new p.BufferAttribute(v,3);V.setUsage(p.DynamicDrawUsage),M.setAttribute("position",V);const b=new p.BufferAttribute(r,4);b.setUsage(p.DynamicDrawUsage),M.setAttribute("aColor",b);const A=(u-1)*6,m=new Uint32Array(A);for(let E=0;E<u-1;E++){const a=E*2,g=E*6;m[g]=a,m[g+1]=a+1,m[g+2]=a+2,m[g+3]=a+1,m[g+4]=a+3,m[g+5]=a+2}const D=new p.BufferAttribute(m,1);return M.setIndex(D),M.setDrawRange(0,0),{geometry:M,posAttr:V,colorAttr:b,indexBuf:D}},[u]),q=c.useMemo(()=>new p.ShaderMaterial({vertexShader:ee,fragmentShader:te,transparent:!0,depthWrite:!1,side:p.DoubleSide,blending:z}),[z]),i=c.useMemo(()=>new p.Vector3,[]),o=c.useMemo(()=>new p.Vector3,[]),d=c.useMemo(()=>new p.Vector3,[]),h=c.useMemo(()=>new p.Vector3(0,1,0),[]),l=c.useMemo(()=>new p.Vector3,[]);return Z.useFrame((x,v)=>{if(!T.current)return;const r=F.current;if(r.elapsed+=v,!f){r.count=0,r.head=0,r.lastPos.set(1/0,1/0,1/0),y.setDrawRange(0,0);return}const M=n.current;if(!M)return;if(r.lastPos.distanceTo(M)>=w){const a=(r.head+r.count)%u;r.positions[a*3]=M.x,r.positions[a*3+1]=M.y,r.positions[a*3+2]=M.z,r.times[a]=r.elapsed,r.count<u?r.count++:r.head=(r.head+1)%u,r.lastPos.copy(M)}for(;r.count>0;){const a=r.head;if(r.elapsed-r.times[a]>t)r.head=(r.head+1)%u,r.count--;else break}if(r.count<2){y.setDrawRange(0,0);return}const b=P.array,A=C.array;let m=null;const D=r.count;for(let a=0;a<D;a++){const g=(r.head+a)%u,j=r.positions[g*3],B=r.positions[g*3+1],U=r.positions[g*3+2],_=1-(r.elapsed-r.times[g])/t;if(a<D-1){const W=(r.head+a+1)%u;i.set(r.positions[W*3]-j,r.positions[W*3+1]-B,r.positions[W*3+2]-U);const N=i.length();N>1e-6?i.divideScalar(N):m&&i.copy(m)}else m&&i.copy(m);d.set(S.position.x-j,S.position.y-B,S.position.z-U),o.crossVectors(i,d);let H=o.length();H<1e-6&&(l.crossVectors(i,h),o.copy(l),H=o.length(),H<1e-6&&(o.set(1,0,0),H=1)),o.divideScalar(H);const O=s*_,G=I*_*_,R=a*2;b[R*3]=j+o.x*O,b[R*3+1]=B+o.y*O,b[R*3+2]=U+o.z*O,b[(R+1)*3]=j-o.x*O,b[(R+1)*3+1]=B-o.y*O,b[(R+1)*3+2]=U-o.z*O,A[R*4]=e[0],A[R*4+1]=e[1],A[R*4+2]=e[2],A[R*4+3]=G,A[(R+1)*4]=e[0],A[(R+1)*4+1]=e[1],A[(R+1)*4+2]=e[2],A[(R+1)*4+3]=G,m=m||new p.Vector3,m.copy(i)}const E=(D-1)*6;y.setDrawRange(0,E),P.needsUpdate=!0,C.needsUpdate=!0}),K.jsx("mesh",{ref:T,geometry:y,material:q,frustumCulled:!1,renderOrder:101,visible:f})}function k(n){return Math.abs(Math.sin(n*12.9898)*43758.5453)%1}function re(n){const t=Math.sin(n*54321.67)*43758.5453%1;return t<0?t+1:t}function ie(n,t,s,e){if(s<=0)return 0;const u=t/s;let w=n.particleSize??.5;if(n.randomSize){const z=n.minSize??.1,f=n.maxSize??.5;w=z+(f-z)*re(s)}const I=Math.max(.01,Math.min(10,n.sizeLifetimeSpeed??1));if(n.fadeSizeEnabled&&(w*=1-Math.pow(u,1/I)),n.increaseSizeEnabled&&(w*=1+Math.pow(u,1/I)),n.pulseEnabled){const z=n.pulseAmplitude??.5,f=n.pulseFrequency??1,T=(n.pulsePhaseRandom??0)*k(e)*Math.PI*2;w*=1+z*Math.sin(t*f*Math.PI*2+T)}return Math.max(0,w)}function oe(n,t,s,e){if(s<=0)return 0;let u=n.opacity??1;const w=t/s;if(n.fadeEnabled&&(u*=Math.max(0,1-w)),n.pulseEnabled&&n.pulseOpacity){const I=n.pulseAmplitude??.5,z=n.pulseFrequency??1,S=(n.pulsePhaseRandom??0)*k(e)*Math.PI*2;u*=Math.max(0,1+I*Math.sin(t*z*Math.PI*2+S))}return Math.max(0,Math.min(1,u))}Object.defineProperty(exports,"fetchPreset",{enumerable:!0,get:()=>X.fetchPreset});exports.HZFaithfulFX=$;exports.HZTrailRibbon=ne;exports.computeParticleOpacity=oe;exports.computeParticleSize=ie;exports.particleHash=k;exports.scalePreset=J;
@@ -17,6 +17,8 @@ export interface HZFaithfulFXProps {
17
17
  renderPriority?: number;
18
18
  /** Skip scene-depth occlusion (particles never hidden behind geometry). */
19
19
  noOcclusion?: boolean;
20
+ /** Respect the user's `prefers-reduced-motion` setting by freezing the FX. Default true. */
21
+ respectReducedMotion?: boolean;
20
22
  }
21
23
 
22
24
  /**
@@ -1,4 +1,4 @@
1
- import { useRef as b, useMemo as D, useEffect as k } from "react";
1
+ import { useRef as I, useMemo as b, useEffect as X } from "react";
2
2
  import { useFrame as J, useThree as N } from "@react-three/fiber";
3
3
  import { initHzFxOverlay as Q, makeThreeSceneDepth as Y } from "hz-particles";
4
4
  import { fetchPreset as he } from "hz-particles";
@@ -6,13 +6,13 @@ import { jsx as $ } from "react/jsx-runtime";
6
6
  import * as s from "three";
7
7
  function ee(r, t) {
8
8
  if (t === 1) return r;
9
- const h = (e, i) => e != null ? e * t : i * t;
9
+ const v = (e, a) => e != null ? e * t : a * t;
10
10
  return {
11
11
  ...r,
12
12
  systems: r.systems.map((e) => ({
13
13
  ...e,
14
14
  // Particle visual size
15
- particleSize: h(e.particleSize, 0.5),
15
+ particleSize: v(e.particleSize, 0.5),
16
16
  minSize: e.minSize != null ? e.minSize * t : void 0,
17
17
  maxSize: e.maxSize != null ? e.maxSize * t : void 0,
18
18
  // Speed
@@ -40,59 +40,70 @@ function ee(r, t) {
40
40
  }))
41
41
  };
42
42
  }
43
- function le({
43
+ function de({
44
44
  preset: r,
45
45
  positionRef: t,
46
- position: h = [0, 0, 0],
46
+ position: v = [0, 0, 0],
47
47
  scale: e = 1,
48
- active: i = !0,
49
- renderPriority: z = 1,
50
- noOcclusion: A = !1
48
+ active: a = !0,
49
+ renderPriority: x = 1,
50
+ noOcclusion: T = !1,
51
+ respectReducedMotion: z = !0
51
52
  }) {
52
- const l = b(null), v = b(null), w = b(!1), I = b(0), H = b(i);
53
- H.current = i;
54
- const C = b(h);
55
- C.current = h;
56
- const F = D(
53
+ const p = I(null), S = I(null), D = I(!1), L = I(0), C = I(a);
54
+ C.current = a;
55
+ const V = I(v);
56
+ V.current = v;
57
+ const H = I(!1), B = b(
57
58
  () => e && e !== 1 ? ee(r, e) : r,
58
59
  [r, e]
59
- ), V = (c) => t ? c.addMovingEmitter(F, {
60
+ ), U = (i) => t ? i.addMovingEmitter(B, {
60
61
  getPosition: () => {
61
- const d = t.current;
62
- return H.current && d ? [d.x, d.y, d.z] : null;
62
+ const o = t.current;
63
+ return C.current && o ? [o.x, o.y, o.z] : null;
63
64
  }
64
- }) : c.addEmitter(F, C.current);
65
- return k(() => {
66
- var p, a;
67
- const c = l.current;
68
- if (!c) return;
69
- let d = !1;
70
- return (a = (p = v.current) == null ? void 0 : p.remove) == null || a.call(p), v.current = null, V(c).then((u) => {
71
- var T;
72
- d ? (T = u == null ? void 0 : u.remove) == null || T.call(u) : v.current = u;
65
+ }) : i.addEmitter(B, V.current);
66
+ return X(() => {
67
+ var d, m;
68
+ const i = p.current;
69
+ if (!i) return;
70
+ let o = !1;
71
+ return (m = (d = S.current) == null ? void 0 : d.remove) == null || m.call(d), S.current = null, U(i).then((c) => {
72
+ var M;
73
+ o ? (M = c == null ? void 0 : c.remove) == null || M.call(c) : S.current = c;
73
74
  }), () => {
74
- d = !0;
75
+ o = !0;
75
76
  };
76
- }, [F]), k(() => () => {
77
- var c, d;
78
- (d = (c = l.current) == null ? void 0 : c.destroy) == null || d.call(c), l.current = null, v.current = null, w.current = !1;
79
- }, []), J((c) => {
80
- c.gl.render(c.scene, c.camera);
81
- const d = performance.now(), p = I.current ? Math.min(0.05, (d - I.current) / 1e3) : 0.016;
82
- I.current = d;
83
- const a = c.gl, u = a.backend;
84
- !l.current && !w.current && (u != null && u.device) && (u != null && u.context) && (w.current = !0, Q(
85
- { device: u.device, context: u.context, canvas: a.domElement },
86
- { getSceneDepth: A ? () => null : Y(a) }
87
- ).then((S) => (l.current = S, V(S))).then((S) => {
88
- v.current = S;
89
- }).catch((S) => console.error("[HZFaithfulFX] init failed:", S)));
90
- const T = l.current;
91
- if (T) {
92
- const S = c.camera;
93
- T.setCamera(S.projectionMatrix.elements, S.matrixWorldInverse.elements, S.position), T.render(p);
77
+ }, [B]), X(() => {
78
+ var d;
79
+ if (typeof window > "u" || !window.matchMedia) return;
80
+ const i = window.matchMedia("(prefers-reduced-motion: reduce)"), o = () => {
81
+ H.current = i.matches;
82
+ };
83
+ return o(), (d = i.addEventListener) == null || d.call(i, "change", o), () => {
84
+ var m;
85
+ return (m = i.removeEventListener) == null ? void 0 : m.call(i, "change", o);
86
+ };
87
+ }, []), X(() => () => {
88
+ var i, o, d, m;
89
+ (o = (i = S.current) == null ? void 0 : i.remove) == null || o.call(i), (m = (d = p.current) == null ? void 0 : d.destroy) == null || m.call(d), p.current = null, S.current = null, D.current = !1;
90
+ }, []), J((i) => {
91
+ i.gl.render(i.scene, i.camera);
92
+ const o = performance.now(), d = L.current ? Math.min(0.05, (o - L.current) / 1e3) : 0.016;
93
+ L.current = o;
94
+ const m = i.gl, c = m.backend;
95
+ !p.current && !D.current && (c != null && c.device) && (c != null && c.context) && (D.current = !0, Q(
96
+ { device: c.device, context: c.context, canvas: m.domElement },
97
+ { getSceneDepth: T ? () => null : Y(m) }
98
+ ).then((f) => (p.current = f, U(f))).then((f) => {
99
+ S.current = f;
100
+ }).catch((f) => console.error("[HZFaithfulFX] init failed:", f)));
101
+ const M = p.current;
102
+ if (M) {
103
+ const f = i.camera;
104
+ M.setCamera(f.projectionMatrix.elements, f.matrixWorldInverse.elements, f.position), z && H.current || M.render(d);
94
105
  }
95
- }, z), null;
106
+ }, x), null;
96
107
  }
97
108
  const te = (
98
109
  /* glsl */
@@ -116,58 +127,58 @@ void main() {
116
127
  function se({
117
128
  positionRef: r,
118
129
  duration: t = 1,
119
- width: h = 0.3,
130
+ width: v = 0.3,
120
131
  color: e = [1, 1, 1],
121
- maxPoints: i = 256,
122
- minDistance: z = 0.05,
123
- opacity: A = 1,
124
- blending: l = s.AdditiveBlending,
125
- visible: v = !0
132
+ maxPoints: a = 256,
133
+ minDistance: x = 0.05,
134
+ opacity: T = 1,
135
+ blending: z = s.AdditiveBlending,
136
+ visible: p = !0
126
137
  }) {
127
- const { camera: w } = N(), I = b(null), H = b({
128
- positions: new Float32Array(i * 3),
129
- times: new Float32Array(i),
138
+ const { camera: S } = N(), D = I(null), L = I({
139
+ positions: new Float32Array(a * 3),
140
+ times: new Float32Array(a),
130
141
  head: 0,
131
142
  count: 0,
132
143
  lastPos: new s.Vector3(1 / 0, 1 / 0, 1 / 0),
133
144
  elapsed: 0
134
- }), { geometry: C, posAttr: F, colorAttr: V, indexBuf: c } = D(() => {
135
- const W = i * 2, j = new Float32Array(W * 3), n = new Float32Array(W * 4), R = new s.BufferGeometry(), O = new s.BufferAttribute(j, 3);
136
- O.setUsage(s.DynamicDrawUsage), R.setAttribute("position", O);
145
+ }), { geometry: C, posAttr: V, colorAttr: H, indexBuf: B } = b(() => {
146
+ const M = a * 2, f = new Float32Array(M * 3), n = new Float32Array(M * 4), R = new s.BufferGeometry(), q = new s.BufferAttribute(f, 3);
147
+ q.setUsage(s.DynamicDrawUsage), R.setAttribute("position", q);
137
148
  const g = new s.BufferAttribute(n, 4);
138
149
  g.setUsage(s.DynamicDrawUsage), R.setAttribute("aColor", g);
139
- const M = (i - 1) * 6, m = new Uint32Array(M);
140
- for (let E = 0; E < i - 1; E++) {
141
- const o = E * 2, x = E * 6;
142
- m[x] = o, m[x + 1] = o + 1, m[x + 2] = o + 2, m[x + 3] = o + 1, m[x + 4] = o + 3, m[x + 5] = o + 2;
150
+ const A = (a - 1) * 6, l = new Uint32Array(A);
151
+ for (let F = 0; F < a - 1; F++) {
152
+ const u = F * 2, w = F * 6;
153
+ l[w] = u, l[w + 1] = u + 1, l[w + 2] = u + 2, l[w + 3] = u + 1, l[w + 4] = u + 3, l[w + 5] = u + 2;
143
154
  }
144
- const y = new s.BufferAttribute(m, 1);
145
- return R.setIndex(y), R.setDrawRange(0, 0), { geometry: R, posAttr: O, colorAttr: g, indexBuf: y };
146
- }, [i]), d = D(() => new s.ShaderMaterial({
155
+ const E = new s.BufferAttribute(l, 1);
156
+ return R.setIndex(E), R.setDrawRange(0, 0), { geometry: R, posAttr: q, colorAttr: g, indexBuf: E };
157
+ }, [a]), U = b(() => new s.ShaderMaterial({
147
158
  vertexShader: te,
148
159
  fragmentShader: ne,
149
160
  transparent: !0,
150
161
  depthWrite: !1,
151
162
  side: s.DoubleSide,
152
- blending: l
153
- }), [l]), p = D(() => new s.Vector3(), []), a = D(() => new s.Vector3(), []), u = D(() => new s.Vector3(), []), T = D(() => new s.Vector3(0, 1, 0), []), S = D(() => new s.Vector3(), []);
154
- return J((W, j) => {
155
- if (!I.current) return;
156
- const n = H.current;
157
- if (n.elapsed += j, !v) {
163
+ blending: z
164
+ }), [z]), i = b(() => new s.Vector3(), []), o = b(() => new s.Vector3(), []), d = b(() => new s.Vector3(), []), m = b(() => new s.Vector3(0, 1, 0), []), c = b(() => new s.Vector3(), []);
165
+ return J((M, f) => {
166
+ if (!D.current) return;
167
+ const n = L.current;
168
+ if (n.elapsed += f, !p) {
158
169
  n.count = 0, n.head = 0, n.lastPos.set(1 / 0, 1 / 0, 1 / 0), C.setDrawRange(0, 0);
159
170
  return;
160
171
  }
161
172
  const R = r.current;
162
173
  if (!R) return;
163
- if (n.lastPos.distanceTo(R) >= z) {
164
- const o = (n.head + n.count) % i;
165
- n.positions[o * 3] = R.x, n.positions[o * 3 + 1] = R.y, n.positions[o * 3 + 2] = R.z, n.times[o] = n.elapsed, n.count < i ? n.count++ : n.head = (n.head + 1) % i, n.lastPos.copy(R);
174
+ if (n.lastPos.distanceTo(R) >= x) {
175
+ const u = (n.head + n.count) % a;
176
+ n.positions[u * 3] = R.x, n.positions[u * 3 + 1] = R.y, n.positions[u * 3 + 2] = R.z, n.times[u] = n.elapsed, n.count < a ? n.count++ : n.head = (n.head + 1) % a, n.lastPos.copy(R);
166
177
  }
167
178
  for (; n.count > 0; ) {
168
- const o = n.head;
169
- if (n.elapsed - n.times[o] > t)
170
- n.head = (n.head + 1) % i, n.count--;
179
+ const u = n.head;
180
+ if (n.elapsed - n.times[u] > t)
181
+ n.head = (n.head + 1) % a, n.count--;
171
182
  else
172
183
  break;
173
184
  }
@@ -175,42 +186,42 @@ function se({
175
186
  C.setDrawRange(0, 0);
176
187
  return;
177
188
  }
178
- const g = F.array, M = V.array;
179
- let m = null;
180
- const y = n.count;
181
- for (let o = 0; o < y; o++) {
182
- const x = (n.head + o) % i, B = n.positions[x * 3], U = n.positions[x * 3 + 1], P = n.positions[x * 3 + 2], Z = 1 - (n.elapsed - n.times[x]) / t;
183
- if (o < y - 1) {
184
- const _ = (n.head + o + 1) % i;
185
- p.set(
186
- n.positions[_ * 3] - B,
187
- n.positions[_ * 3 + 1] - U,
188
- n.positions[_ * 3 + 2] - P
189
+ const g = V.array, A = H.array;
190
+ let l = null;
191
+ const E = n.count;
192
+ for (let u = 0; u < E; u++) {
193
+ const w = (n.head + u) % a, P = n.positions[w * 3], W = n.positions[w * 3 + 1], j = n.positions[w * 3 + 2], Z = 1 - (n.elapsed - n.times[w]) / t;
194
+ if (u < E - 1) {
195
+ const _ = (n.head + u + 1) % a;
196
+ i.set(
197
+ n.positions[_ * 3] - P,
198
+ n.positions[_ * 3 + 1] - W,
199
+ n.positions[_ * 3 + 2] - j
189
200
  );
190
- const G = p.length();
191
- G > 1e-6 ? p.divideScalar(G) : m && p.copy(m);
192
- } else m && p.copy(m);
193
- u.set(
194
- w.position.x - B,
195
- w.position.y - U,
196
- w.position.z - P
197
- ), a.crossVectors(p, u);
198
- let q = a.length();
199
- q < 1e-6 && (S.crossVectors(p, T), a.copy(S), q = a.length(), q < 1e-6 && (a.set(1, 0, 0), q = 1)), a.divideScalar(q);
200
- const L = h * Z, X = A * Z * Z, f = o * 2;
201
- g[f * 3] = B + a.x * L, g[f * 3 + 1] = U + a.y * L, g[f * 3 + 2] = P + a.z * L, g[(f + 1) * 3] = B - a.x * L, g[(f + 1) * 3 + 1] = U - a.y * L, g[(f + 1) * 3 + 2] = P - a.z * L, M[f * 4] = e[0], M[f * 4 + 1] = e[1], M[f * 4 + 2] = e[2], M[f * 4 + 3] = X, M[(f + 1) * 4] = e[0], M[(f + 1) * 4 + 1] = e[1], M[(f + 1) * 4 + 2] = e[2], M[(f + 1) * 4 + 3] = X, m = m || new s.Vector3(), m.copy(p);
201
+ const k = i.length();
202
+ k > 1e-6 ? i.divideScalar(k) : l && i.copy(l);
203
+ } else l && i.copy(l);
204
+ d.set(
205
+ S.position.x - P,
206
+ S.position.y - W,
207
+ S.position.z - j
208
+ ), o.crossVectors(i, d);
209
+ let O = o.length();
210
+ O < 1e-6 && (c.crossVectors(i, m), o.copy(c), O = o.length(), O < 1e-6 && (o.set(1, 0, 0), O = 1)), o.divideScalar(O);
211
+ const y = v * Z, G = T * Z * Z, h = u * 2;
212
+ g[h * 3] = P + o.x * y, g[h * 3 + 1] = W + o.y * y, g[h * 3 + 2] = j + o.z * y, g[(h + 1) * 3] = P - o.x * y, g[(h + 1) * 3 + 1] = W - o.y * y, g[(h + 1) * 3 + 2] = j - o.z * y, A[h * 4] = e[0], A[h * 4 + 1] = e[1], A[h * 4 + 2] = e[2], A[h * 4 + 3] = G, A[(h + 1) * 4] = e[0], A[(h + 1) * 4 + 1] = e[1], A[(h + 1) * 4 + 2] = e[2], A[(h + 1) * 4 + 3] = G, l = l || new s.Vector3(), l.copy(i);
202
213
  }
203
- const E = (y - 1) * 6;
204
- C.setDrawRange(0, E), F.needsUpdate = !0, V.needsUpdate = !0;
214
+ const F = (E - 1) * 6;
215
+ C.setDrawRange(0, F), V.needsUpdate = !0, H.needsUpdate = !0;
205
216
  }), /* @__PURE__ */ $(
206
217
  "mesh",
207
218
  {
208
- ref: I,
219
+ ref: D,
209
220
  geometry: C,
210
- material: d,
221
+ material: U,
211
222
  frustumCulled: !1,
212
223
  renderOrder: 101,
213
- visible: v
224
+ visible: p
214
225
  }
215
226
  );
216
227
  }
@@ -221,36 +232,36 @@ function re(r) {
221
232
  const t = Math.sin(r * 54321.67) * 43758.5453 % 1;
222
233
  return t < 0 ? t + 1 : t;
223
234
  }
224
- function de(r, t, h, e) {
225
- if (h <= 0) return 0;
226
- const i = t / h;
227
- let z = r.particleSize ?? 0.5;
235
+ function le(r, t, v, e) {
236
+ if (v <= 0) return 0;
237
+ const a = t / v;
238
+ let x = r.particleSize ?? 0.5;
228
239
  if (r.randomSize) {
229
- const l = r.minSize ?? 0.1, v = r.maxSize ?? 0.5;
230
- z = l + (v - l) * re(h);
240
+ const z = r.minSize ?? 0.1, p = r.maxSize ?? 0.5;
241
+ x = z + (p - z) * re(v);
231
242
  }
232
- const A = Math.max(0.01, Math.min(10, r.sizeLifetimeSpeed ?? 1));
233
- if (r.fadeSizeEnabled && (z *= 1 - Math.pow(i, 1 / A)), r.increaseSizeEnabled && (z *= 1 + Math.pow(i, 1 / A)), r.pulseEnabled) {
234
- const l = r.pulseAmplitude ?? 0.5, v = r.pulseFrequency ?? 1, I = (r.pulsePhaseRandom ?? 0) * K(e) * Math.PI * 2;
235
- z *= 1 + l * Math.sin(t * v * Math.PI * 2 + I);
243
+ const T = Math.max(0.01, Math.min(10, r.sizeLifetimeSpeed ?? 1));
244
+ if (r.fadeSizeEnabled && (x *= 1 - Math.pow(a, 1 / T)), r.increaseSizeEnabled && (x *= 1 + Math.pow(a, 1 / T)), r.pulseEnabled) {
245
+ const z = r.pulseAmplitude ?? 0.5, p = r.pulseFrequency ?? 1, D = (r.pulsePhaseRandom ?? 0) * K(e) * Math.PI * 2;
246
+ x *= 1 + z * Math.sin(t * p * Math.PI * 2 + D);
236
247
  }
237
- return Math.max(0, z);
248
+ return Math.max(0, x);
238
249
  }
239
- function pe(r, t, h, e) {
240
- if (h <= 0) return 0;
241
- let i = r.opacity ?? 1;
242
- const z = t / h;
243
- if (r.fadeEnabled && (i *= Math.max(0, 1 - z)), r.pulseEnabled && r.pulseOpacity) {
244
- const A = r.pulseAmplitude ?? 0.5, l = r.pulseFrequency ?? 1, w = (r.pulsePhaseRandom ?? 0) * K(e) * Math.PI * 2;
245
- i *= Math.max(0, 1 + A * Math.sin(t * l * Math.PI * 2 + w));
250
+ function pe(r, t, v, e) {
251
+ if (v <= 0) return 0;
252
+ let a = r.opacity ?? 1;
253
+ const x = t / v;
254
+ if (r.fadeEnabled && (a *= Math.max(0, 1 - x)), r.pulseEnabled && r.pulseOpacity) {
255
+ const T = r.pulseAmplitude ?? 0.5, z = r.pulseFrequency ?? 1, S = (r.pulsePhaseRandom ?? 0) * K(e) * Math.PI * 2;
256
+ a *= Math.max(0, 1 + T * Math.sin(t * z * Math.PI * 2 + S));
246
257
  }
247
- return Math.max(0, Math.min(1, i));
258
+ return Math.max(0, Math.min(1, a));
248
259
  }
249
260
  export {
250
- le as HZFaithfulFX,
261
+ de as HZFaithfulFX,
251
262
  se as HZTrailRibbon,
252
263
  pe as computeParticleOpacity,
253
- de as computeParticleSize,
264
+ le as computeParticleSize,
254
265
  he as fetchPreset,
255
266
  K as particleHash,
256
267
  ee as scalePreset