hz-particles 1.0.15 → 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,368 +1,111 @@
1
- import { jsxs as Ut, Fragment as qt, jsx as Je } from "react/jsx-runtime";
2
- import { useState as Bt, useEffect as _e, useRef as j, useMemo as T } from "react";
3
- import { useThree as wt, useFrame as bt } from "@react-three/fiber";
4
- import * as a from "three";
5
- import { fetchPreset as Ht, ParticleSystemManager as Lt } from "hz-particles";
6
- import { fetchPreset as tn } from "hz-particles";
7
- function At(l) {
8
- return Math.abs(Math.sin(l * 12.9898) * 43758.5453) % 1;
9
- }
10
- function Ot(l) {
11
- const r = Math.sin(l * 54321.67) * 43758.5453 % 1;
12
- return r < 0 ? r + 1 : r;
13
- }
14
- function Wt(l, r, U, e) {
15
- if (U <= 0) return 0;
16
- const g = r / U;
17
- let N = l.particleSize ?? 0.5;
18
- if (l.randomSize) {
19
- const X = l.minSize ?? 0.1, Q = l.maxSize ?? 0.5;
20
- N = X + (Q - X) * Ot(U);
21
- }
22
- const K = Math.max(0.01, Math.min(10, l.sizeLifetimeSpeed ?? 1));
23
- if (l.fadeSizeEnabled && (N *= 1 - Math.pow(g, 1 / K)), l.increaseSizeEnabled && (N *= 1 + Math.pow(g, 1 / K)), l.pulseEnabled) {
24
- const X = l.pulseAmplitude ?? 0.5, Q = l.pulseFrequency ?? 1, ce = (l.pulsePhaseRandom ?? 0) * At(e) * Math.PI * 2;
25
- N *= 1 + X * Math.sin(r * Q * Math.PI * 2 + ce);
26
- }
27
- return Math.max(0, N);
28
- }
29
- function _t(l, r, U, e) {
30
- if (U <= 0) return 0;
31
- let g = l.opacity ?? 1;
32
- const N = r / U;
33
- if (l.fadeEnabled && (g *= Math.max(0, 1 - N)), l.pulseEnabled && l.pulseOpacity) {
34
- const K = l.pulseAmplitude ?? 0.5, X = l.pulseFrequency ?? 1, re = (l.pulsePhaseRandom ?? 0) * At(e) * Math.PI * 2;
35
- g *= Math.max(0, 1 + K * Math.sin(r * X * Math.PI * 2 + re));
36
- }
37
- return Math.max(0, Math.min(1, g));
38
- }
39
- function Gt(l, r) {
40
- if (r === 1) return l;
41
- const U = (e, g) => e != null ? e * r : g * r;
1
+ import { useRef as I, useMemo as b, useEffect as X } from "react";
2
+ import { useFrame as J, useThree as N } from "@react-three/fiber";
3
+ import { initHzFxOverlay as Q, makeThreeSceneDepth as Y } from "hz-particles";
4
+ import { fetchPreset as he } from "hz-particles";
5
+ import { jsx as $ } from "react/jsx-runtime";
6
+ import * as s from "three";
7
+ function ee(r, t) {
8
+ if (t === 1) return r;
9
+ const v = (e, a) => e != null ? e * t : a * t;
42
10
  return {
43
- ...l,
44
- systems: l.systems.map((e) => ({
11
+ ...r,
12
+ systems: r.systems.map((e) => ({
45
13
  ...e,
46
14
  // Particle visual size
47
- particleSize: U(e.particleSize, 0.5),
48
- minSize: e.minSize != null ? e.minSize * r : void 0,
49
- maxSize: e.maxSize != null ? e.maxSize * r : void 0,
15
+ particleSize: v(e.particleSize, 0.5),
16
+ minSize: e.minSize != null ? e.minSize * t : void 0,
17
+ maxSize: e.maxSize != null ? e.maxSize * t : void 0,
50
18
  // Speed
51
- particleSpeed: (e.particleSpeed ?? 1) * r,
52
- minSpeed: e.minSpeed != null ? e.minSpeed * r : void 0,
53
- maxSpeed: e.maxSpeed != null ? e.maxSpeed * r : void 0,
19
+ particleSpeed: (e.particleSpeed ?? 1) * t,
20
+ minSpeed: e.minSpeed != null ? e.minSpeed * t : void 0,
21
+ maxSpeed: e.maxSpeed != null ? e.maxSpeed * t : void 0,
54
22
  // Emission shape dimensions
55
- cubeLength: e.cubeLength != null ? e.cubeLength * r : void 0,
56
- outerLength: e.outerLength != null ? e.outerLength * r : void 0,
57
- innerLength: e.innerLength != null ? e.innerLength * r : void 0,
58
- outerRadius: e.outerRadius != null ? e.outerRadius * r : void 0,
59
- innerRadius: e.innerRadius != null ? e.innerRadius * r : void 0,
60
- squareSize: e.squareSize != null ? e.squareSize * r : void 0,
61
- squareInnerSize: e.squareInnerSize != null ? e.squareInnerSize * r : void 0,
62
- circleInnerRadius: e.circleInnerRadius != null ? e.circleInnerRadius * r : void 0,
63
- circleOuterRadius: e.circleOuterRadius != null ? e.circleOuterRadius * r : void 0,
64
- cylinderInnerRadius: e.cylinderInnerRadius != null ? e.cylinderInnerRadius * r : void 0,
65
- cylinderOuterRadius: e.cylinderOuterRadius != null ? e.cylinderOuterRadius * r : void 0,
66
- cylinderHeight: e.cylinderHeight != null ? e.cylinderHeight * r : void 0,
23
+ cubeLength: e.cubeLength != null ? e.cubeLength * t : void 0,
24
+ outerLength: e.outerLength != null ? e.outerLength * t : void 0,
25
+ innerLength: e.innerLength != null ? e.innerLength * t : void 0,
26
+ outerRadius: e.outerRadius != null ? e.outerRadius * t : void 0,
27
+ innerRadius: e.innerRadius != null ? e.innerRadius * t : void 0,
28
+ squareSize: e.squareSize != null ? e.squareSize * t : void 0,
29
+ squareInnerSize: e.squareInnerSize != null ? e.squareInnerSize * t : void 0,
30
+ circleInnerRadius: e.circleInnerRadius != null ? e.circleInnerRadius * t : void 0,
31
+ circleOuterRadius: e.circleOuterRadius != null ? e.circleOuterRadius * t : void 0,
32
+ cylinderInnerRadius: e.cylinderInnerRadius != null ? e.cylinderInnerRadius * t : void 0,
33
+ cylinderOuterRadius: e.cylinderOuterRadius != null ? e.cylinderOuterRadius * t : void 0,
34
+ cylinderHeight: e.cylinderHeight != null ? e.cylinderHeight * t : void 0,
67
35
  // Trail
68
- emissionTrailWidth: (e.emissionTrailWidth ?? 0.3) * r,
69
- emissionTrailDuration: (e.emissionTrailDuration ?? 1) * r,
70
- emissionTrailMinDistance: e.emissionTrailMinDistance != null ? e.emissionTrailMinDistance * r : void 0,
71
- emissionTrailShapeAmplitude: e.emissionTrailShapeAmplitude != null ? e.emissionTrailShapeAmplitude * r : void 0
36
+ emissionTrailWidth: (e.emissionTrailWidth ?? 0.3) * t,
37
+ emissionTrailDuration: (e.emissionTrailDuration ?? 1) * t,
38
+ emissionTrailMinDistance: e.emissionTrailMinDistance != null ? e.emissionTrailMinDistance * t : void 0,
39
+ emissionTrailShapeAmplitude: e.emissionTrailShapeAmplitude != null ? e.emissionTrailShapeAmplitude * t : void 0
72
40
  }))
73
41
  };
74
42
  }
75
- function Xt(l) {
76
- let r = 0;
77
- for (const U of l.systems)
78
- r += U.maxParticles ?? 1e4;
79
- return r;
80
- }
81
- function Jt({
82
- preset: l,
83
- position: r,
84
- positionRef: U,
85
- autoPlay: e = !0,
86
- visible: g = !0,
87
- scale: N = 1,
88
- resetKey: K = 0,
89
- onComplete: X
43
+ function de({
44
+ preset: r,
45
+ positionRef: t,
46
+ position: v = [0, 0, 0],
47
+ scale: e = 1,
48
+ active: a = !0,
49
+ renderPriority: x = 1,
50
+ noOcclusion: T = !1,
51
+ respectReducedMotion: z = !0
90
52
  }) {
91
- var Le;
92
- const [Q, re] = Bt(
93
- typeof l == "string" ? null : l
94
- );
95
- _e(() => {
96
- typeof l == "string" ? (re(null), Ht(l).then(re).catch((u) => {
97
- console.error("[HZParticlesFX] Failed to fetch preset:", u);
98
- })) : re(l);
99
- }, [l]);
100
- const { camera: ce, gl: Ye } = wt(), pe = j(null);
101
- if (!pe.current) {
102
- const u = (Le = Ye.backend) == null ? void 0 : Le.device;
103
- u && (pe.current = u);
104
- }
105
- const De = pe.current, Pe = j(null), ge = j(null), Ve = j(!1), H = j(!1), f = T(
106
- () => Q ? Gt(Q, N) : null,
107
- [Q, N]
108
- ), Be = T(
109
- () => (f == null ? void 0 : f.systems.every((u) => u.emissionTrailEnabled)) ?? !1,
110
- [f]
111
- ), je = T(
112
- () => f ? f.systems.every((u) => u.emissionTrailEnabled) ? 1 : Xt(f) : 0,
113
- [f]
114
- ), Ge = T(() => r ? r instanceof a.Vector3 ? r.clone() : new a.Vector3(...r) : new a.Vector3(0, 0, 0), [r]), ye = T(
115
- () => (f == null ? void 0 : f.systems.some((u) => u.emissionTrailEnabled)) ?? !1,
116
- [f]
117
- ), He = T(() => new a.PlaneGeometry(1, 1), []), n = T(() => {
118
- const u = document.createElement("canvas");
119
- u.width = 64, u.height = 64;
120
- const R = u.getContext("2d");
121
- R.clearRect(0, 0, 64, 64);
122
- const w = R.createRadialGradient(32, 32, 0, 32, 32, 32);
123
- w.addColorStop(0, "rgba(255,255,255,1)"), w.addColorStop(0.7, "rgba(255,255,255,1)"), w.addColorStop(1, "rgba(255,255,255,0)"), R.fillStyle = w, R.beginPath(), R.arc(32, 32, 32, 0, Math.PI * 2), R.fill();
124
- const b = new a.CanvasTexture(u);
125
- b.flipY = !1;
126
- const _ = new a.MeshBasicMaterial({
127
- color: 16777215,
128
- transparent: !0,
129
- depthWrite: !1,
130
- alphaTest: 0.01,
131
- map: b,
132
- vertexColors: !0,
133
- side: a.DoubleSide,
134
- blending: a.NormalBlending
135
- });
136
- return _.needsUpdate = !0, _;
137
- }, []), D = j(null);
138
- _e(() => {
139
- if (!f) return;
140
- const u = f.systems.find(
141
- (w) => !w.emissionTrailEnabled && w.textureEnabled && w.textureImageData
142
- );
143
- if (!u) {
144
- D.current && n.map !== D.current && (n.map = D.current, n.needsUpdate = !0);
145
- return;
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(
58
+ () => e && e !== 1 ? ee(r, e) : r,
59
+ [r, e]
60
+ ), U = (i) => t ? i.addMovingEmitter(B, {
61
+ getPosition: () => {
62
+ const o = t.current;
63
+ return C.current && o ? [o.x, o.y, o.z] : null;
146
64
  }
147
- D.current || (D.current = n.map);
148
- const R = new Image();
149
- return R.onload = () => {
150
- const w = new a.Texture(R);
151
- w.needsUpdate = !0, n.map = w, n.needsUpdate = !0;
152
- }, R.src = u.textureImageData, () => {
153
- n.map && n.map !== D.current && n.map.dispose();
154
- };
155
- }, [f, n]);
156
- const Se = 64, Z = j(null), k = j(0), y = 512, se = j({
157
- buf: new Float32Array(y * 6),
158
- // x, y, z, time, d1, d2
159
- head: 0,
160
- count: 0,
161
- elapsed: 0
162
- }), { trailGeo: ie, trailPosAttr: z, trailColAttr: L } = T(() => {
163
- const R = 8 * Se * 6, w = new Float32Array(R * 3), b = new Float32Array(R * 3), _ = new a.BufferGeometry(), he = new a.BufferAttribute(w, 3);
164
- he.setUsage(a.DynamicDrawUsage), _.setAttribute("position", he);
165
- const ve = new a.BufferAttribute(b, 3);
166
- return ve.setUsage(a.DynamicDrawUsage), _.setAttribute("color", ve), _.setDrawRange(0, 0), { trailGeo: _, trailPosAttr: he, trailColAttr: ve };
167
- }, []), Fe = T(() => new a.MeshBasicMaterial({
168
- color: 16777215,
169
- vertexColors: !0,
170
- transparent: !0,
171
- depthWrite: !1,
172
- side: a.DoubleSide,
173
- blending: a.NormalBlending
174
- }), []);
175
- _e(() => {
176
- if (!De || !f)
177
- return;
178
- const u = new Lt(De);
179
- return ge.current = u, H.current = !1, u.replaceSystems(f).then(() => {
180
- e && g && (u.respawnAllSystems(), H.current = !0);
181
- }).catch((R) => {
182
- console.error("[HZParticlesFX] replaceSystems FAILED:", R);
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;
183
74
  }), () => {
184
- typeof u.destroy == "function" && u.destroy(), ge.current = null;
75
+ o = !0;
185
76
  };
186
- }, [De, f]), _e(() => {
187
- const u = ge.current;
188
- u && e && g && !H.current && (u.respawnAllSystems(), H.current = !0, Ve.current = !1);
189
- }, [e, g]);
190
- const me = j(null), xe = j(K);
191
- _e(() => {
192
- if (K === xe.current) return;
193
- xe.current = K;
194
- const u = se.current;
195
- u.head = 0, u.count = 0, u.elapsed = 0, ie.setDrawRange(0, 0), me.current = null;
196
- const R = ge.current;
197
- R && (R.respawnAllSystems(), H.current = !0, Ve.current = !1);
198
- }, [K]);
199
- const Ne = T(() => new a.Matrix4(), []), fe = T(() => new a.Vector3(), []), ee = T(() => new a.Vector3(), []), oe = T(() => new a.Quaternion(), []), Me = T(() => new a.Vector3(), []), V = T(() => new a.Vector3(0, 0, 1), []), Ee = T(() => new a.Color(), []);
200
- return bt((u, R) => {
201
- var Ke;
202
- if (!g || !Pe.current || !ge.current) return;
203
- const w = ge.current, b = (U == null ? void 0 : U.current) ?? Ge, _ = R > 1 ? R / 1e3 : R, he = me.current, ve = he && _ > 0, Tt = ve ? (b.x - he.x) / _ : 0, Rt = ve ? (b.y - he.y) / _ : 0, It = ve ? (b.z - he.z) / _ : 0;
204
- me.current = { x: b.x, y: b.y, z: b.z };
205
- for (const { system: s, config: c } of w.particleSystems)
206
- c.emissionTrailEnabled ? (s.setSimulationTransform({
207
- position: [b.x, b.y, b.z],
208
- velocity: [Tt, Rt, It]
209
- }), c.emissionTranslationX = 0, c.emissionTranslationY = 0, c.emissionTranslationZ = 0) : (c.emissionTranslationX = b.x, c.emissionTranslationY = b.y, c.emissionTranslationZ = b.z);
210
- w.updateAllSystems(_);
211
- for (const { system: s } of w.particleSystems)
212
- s.readbackAndProcessParticles();
213
- if (ye) {
214
- const s = se.current;
215
- s.elapsed += _;
216
- let c = 0, P = 0;
217
- const q = (Ke = w.particleSystems.find(({ config: O }) => O.emissionTrailEnabled)) == null ? void 0 : Ke.config;
218
- if (q) {
219
- const O = q.emissionTrailShape ?? "straight";
220
- if (O !== "straight") {
221
- const B = q.emissionTrailShapeAmplitude ?? 0.1, le = q.emissionTrailShapeFrequency ?? 4, ne = 2 * Math.PI * le * s.elapsed;
222
- O === "zigzag" ? c = B * Math.sign(Math.sin(ne)) : O === "sine" ? c = B * Math.sin(ne) : O === "spiral" && (c = B * Math.sin(ne), P = B * Math.cos(ne));
223
- }
224
- }
225
- const te = s.head * 6;
226
- s.buf[te] = b.x, s.buf[te + 1] = b.y, s.buf[te + 2] = b.z, s.buf[te + 3] = s.elapsed, s.buf[te + 4] = c, s.buf[te + 5] = P, s.head = (s.head + 1) % y, s.count < y && s.count++;
227
- }
228
- const ze = Pe.current;
229
- let we = 0;
230
- for (let s = 0; s < w.particleSystems.length; s++) {
231
- const { system: c, config: P } = w.particleSystems[s];
232
- if (P.emissionTrailEnabled) continue;
233
- const q = c.particleData, te = c.activeParticles;
234
- if (!(!q || te <= 0))
235
- for (let O = 0; O < te; O++) {
236
- const B = O * 8, le = q[B + 0], ne = q[B + 1], C = q[B + 2];
237
- let be = q[B + 3], Ae = q[B + 4], J = q[B + 5];
238
- const Te = q[B + 6], ae = q[B + 7];
239
- if (Te >= ae || ae <= 0) continue;
240
- const x = Te / ae;
241
- if (P.colorTransitionEnabled) {
242
- const F = P.startColor ?? [1, 0, 0], ue = P.endColor ?? [0, 0, 1];
243
- be = F[0] + (ue[0] - F[0]) * x, Ae = F[1] + (ue[1] - F[1]) * x, J = F[2] + (ue[2] - F[2]) * x;
244
- }
245
- const Re = P.bloomIntensity ?? 1;
246
- be = Math.min(1, be * Re), Ae = Math.min(1, Ae * Re), J = Math.min(1, J * Re);
247
- const Ie = _t(P, Te, ae, O);
248
- be *= Ie, Ae *= Ie, J *= Ie;
249
- const $ = Wt(P, Te, ae, O);
250
- if (!($ <= 0)) {
251
- if (fe.set(le, ne, C), ee.subVectors(ce.position, fe).normalize(), oe.setFromUnitVectors(V, ee), P.velocityStretchEnabled && c.particleVelocities) {
252
- const F = O * 4, ue = c.particleVelocities[F], Ue = c.particleVelocities[F + 1], E = c.particleVelocities[F + 2], de = Math.sqrt(ue * ue + Ue * Ue + E * E);
253
- if (de > 1e-3) {
254
- const Qe = P.velocityStretchFactor ?? 1, G = $ * (1 + de * Qe);
255
- Me.set($, G, 1), ee.set(ue, Ue, E).normalize(), oe.setFromUnitVectors(V, ee);
256
- const i = (G - $) * 0.5;
257
- fe.addScaledVector(ee, i);
258
- } else
259
- Me.set($, $, 1);
260
- } else
261
- Me.set($, $, 1);
262
- Ne.compose(fe, oe, Me), ze.setMatrixAt(we, Ne), Ee.setRGB(be, Ae, J), ze.setColorAt(we, Ee), we++;
263
- }
264
- }
265
- }
266
- ze.count = we, ze.visible = we > 0, we > 0 && (ze.instanceMatrix.needsUpdate = !0, ze.instanceColor && (ze.instanceColor.needsUpdate = !0));
267
- const $e = we > 0 || w.particleSystems.some(({ system: s }) => s.emitting || s.activeParticles > 0);
268
- if (Ve.current && !$e && (H.current = !1, X == null || X()), Ve.current = $e, ye && Z.current) {
269
- const s = z.array, c = L.array;
270
- let P = 0;
271
- const q = ce.position.x, te = ce.position.y, O = ce.position.z;
272
- for (let le = 0; le < w.particleSystems.length; le++) {
273
- const { system: ne, config: C } = w.particleSystems[le];
274
- if (!C.emissionTrailEnabled || !ne.emitting && ne.activeParticles <= 0) continue;
275
- const be = C.emissionTrailDuration ?? 1, Ae = C.emissionTrailWidth ?? 0.3, J = C.bloomIntensity ?? 1, Te = Ae * 0.5, ae = se.current, x = ae.buf, Re = ae.count, Ie = ae.head, $ = ae.elapsed;
276
- if (Re < 2) continue;
277
- const F = ((Ie - Re) % y + y) % y, ue = $ - x[F * 6 + 3], Ue = Math.min(be, ue);
278
- if (Ue < 1e-3) continue;
279
- const E = C.colorTransitionEnabled ? C.startColor ?? [1, 1, 1] : C.particleColor ?? [1, 1, 1], de = C.colorTransitionEnabled ? C.endColor ?? [1, 1, 1] : E, Qe = (t, o) => {
280
- const h = $ - t;
281
- for (let d = 0; d < Re - 1; d++) {
282
- const M = ((Ie - 1 - d) % y + y) % y, I = ((Ie - 2 - d) % y + y) % y, W = x[M * 6 + 3], A = x[I * 6 + 3];
283
- if (h >= A && h <= W) {
284
- const m = W !== A ? (h - A) / (W - A) : 0;
285
- o[0] = x[I * 6] + (x[M * 6] - x[I * 6]) * m, o[1] = x[I * 6 + 1] + (x[M * 6 + 1] - x[I * 6 + 1]) * m, o[2] = x[I * 6 + 2] + (x[M * 6 + 2] - x[I * 6 + 2]) * m, o[3] = x[I * 6 + 4] + (x[M * 6 + 4] - x[I * 6 + 4]) * m, o[4] = x[I * 6 + 5] + (x[M * 6 + 5] - x[I * 6 + 5]) * m;
286
- return;
287
- }
288
- }
289
- o[0] = x[F * 6], o[1] = x[F * 6 + 1], o[2] = x[F * 6 + 2], o[3] = x[F * 6 + 4], o[4] = x[F * 6 + 5];
290
- }, G = Math.max(1, Math.min(Se, C.emissionTrailSegments ?? 8)), i = [b.x, b.y, b.z], Oe = C.emissionTrailShape ?? "straight", Xe = [];
291
- {
292
- const t = C.emissionTrailShapeAmplitude ?? 0.1, o = C.emissionTrailShapeFrequency ?? 4, h = 2 * Math.PI * o * $;
293
- let d = 0, M = 0;
294
- Oe === "zigzag" ? d = t * Math.sign(Math.sin(h)) : Oe === "sine" ? d = t * Math.sin(h) : Oe === "spiral" && (d = t * Math.sin(h), M = t * Math.cos(h)), Xe.push(d, M);
295
- }
296
- const qe = [0, 0, 0, 0, 0];
297
- for (let t = 1; t <= G; t++) {
298
- const o = t / G * Ue;
299
- Qe(o, qe), i.push(qe[0], qe[1], qe[2]), Xe.push(qe[3], qe[4]);
300
- }
301
- const et = i[0] - i[G * 3], tt = i[1] - i[G * 3 + 1], nt = i[2] - i[G * 3 + 2];
302
- if (et * et + tt * tt + nt * nt < 1e-6) continue;
303
- let rt = 0, st = 0, it = 0;
304
- const Ce = [], Ze = [];
305
- for (let t = 0; t <= G; t++) {
306
- let o, h, d;
307
- t === 0 ? (o = i[3] - i[0], h = i[4] - i[1], d = i[5] - i[2]) : t === G ? (o = i[t * 3] - i[(t - 1) * 3], h = i[t * 3 + 1] - i[(t - 1) * 3 + 1], d = i[t * 3 + 2] - i[(t - 1) * 3 + 2]) : (o = i[(t + 1) * 3] - i[(t - 1) * 3], h = i[(t + 1) * 3 + 1] - i[(t - 1) * 3 + 1], d = i[(t + 1) * 3 + 2] - i[(t - 1) * 3 + 2]);
308
- let M = Math.sqrt(o * o + h * h + d * d);
309
- M < 1e-8 && (o = 0, h = 0, d = 1, M = 1), o /= M, h /= M, d /= M, Ze.push(o, h, d);
310
- const I = q - i[t * 3], W = te - i[t * 3 + 1], A = O - i[t * 3 + 2];
311
- let m = h * A - d * W, S = d * I - o * A, v = o * W - h * I, Y = Math.sqrt(m * m + S * S + v * v);
312
- Y < 1e-8 && (m = -d, S = 0, v = o, Y = Math.sqrt(m * m + S * S + v * v)), Y < 1e-8 && (m = 0, S = 1, v = 0, Y = 1), m /= Y, S /= Y, v /= Y, t > 0 && m * rt + S * st + v * it < 0 && (m = -m, S = -S, v = -v), rt = m, st = S, it = v, Ce.push(m, S, v);
313
- }
314
- if (Oe !== "straight")
315
- for (let t = 1; t <= G; t++) {
316
- const o = Xe[t * 2], h = Xe[t * 2 + 1];
317
- if (Math.abs(o) < 1e-8 && Math.abs(h) < 1e-8) continue;
318
- const d = t * 3, M = Ze[d], I = Ze[d + 1], W = Ze[d + 2];
319
- let A = -W, m = 0, S = M, v = Math.sqrt(A * A + S * S);
320
- if (v < 1e-6 && (A = 0, m = W, S = -I, v = Math.sqrt(A * A + m * m + S * S), v < 1e-6 && (A = 1, m = 0, S = 0, v = 1)), A /= v, m /= v, S /= v, Oe === "spiral") {
321
- const Y = I * S - W * m, We = W * A - M * S, ke = M * m - I * A;
322
- i[d] += A * o + Y * h, i[d + 1] += m * o + We * h, i[d + 2] += S * o + ke * h;
323
- } else
324
- i[d] += A * o, i[d + 1] += m * o, i[d + 2] += S * o;
325
- }
326
- for (let t = 0; t < G; t++) {
327
- const o = t / G, h = (t + 1) / G, d = Te * (1 - o), M = Te * (1 - h), I = (1 - o) * (1 - o), W = (1 - h) * (1 - h), A = Math.min(1, (E[0] + (de[0] - E[0]) * o) * J) * I, m = Math.min(1, (E[1] + (de[1] - E[1]) * o) * J) * I, S = Math.min(1, (E[2] + (de[2] - E[2]) * o) * J) * I, v = Math.min(1, (E[0] + (de[0] - E[0]) * h) * J) * W, Y = Math.min(1, (E[1] + (de[1] - E[1]) * h) * J) * W, We = Math.min(1, (E[2] + (de[2] - E[2]) * h) * J) * W, ke = i[t * 3], ot = i[t * 3 + 1], at = i[t * 3 + 2], ct = i[(t + 1) * 3], lt = i[(t + 1) * 3 + 1], ut = i[(t + 1) * 3 + 2], dt = Ce[t * 3], pt = Ce[t * 3 + 1], mt = Ce[t * 3 + 2], ft = Ce[(t + 1) * 3], ht = Ce[(t + 1) * 3 + 1], gt = Ce[(t + 1) * 3 + 2], Ct = ke + dt * d, Dt = ot + pt * d, Pt = at + mt * d, yt = ke - dt * d, St = ot - pt * d, xt = at - mt * d, Mt = ct + ft * M, vt = lt + ht * M, zt = ut + gt * M, Vt = ct - ft * M, Ft = lt - ht * M, Et = ut - gt * M, p = P * 3;
328
- s[p] = Ct, s[p + 1] = Dt, s[p + 2] = Pt, c[p] = A, c[p + 1] = m, c[p + 2] = S, s[p + 3] = yt, s[p + 4] = St, s[p + 5] = xt, c[p + 3] = A, c[p + 4] = m, c[p + 5] = S, s[p + 6] = Mt, s[p + 7] = vt, s[p + 8] = zt, c[p + 6] = v, c[p + 7] = Y, c[p + 8] = We, s[p + 9] = yt, s[p + 10] = St, s[p + 11] = xt, c[p + 9] = A, c[p + 10] = m, c[p + 11] = S, s[p + 12] = Vt, s[p + 13] = Ft, s[p + 14] = Et, c[p + 12] = v, c[p + 13] = Y, c[p + 14] = We, s[p + 15] = Mt, s[p + 16] = vt, s[p + 17] = zt, c[p + 15] = v, c[p + 16] = Y, c[p + 17] = We, P += 6;
329
- }
330
- }
331
- const B = k.current;
332
- if (P < B) {
333
- const le = P * 3, ne = B * 3;
334
- for (let C = le; C < ne; C++)
335
- s[C] = 0, c[C] = 0;
336
- }
337
- k.current = P, ie.setDrawRange(0, P), z.needsUpdate = !0, L.needsUpdate = !0;
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);
338
105
  }
339
- }), Q ? /* @__PURE__ */ Ut(qt, { children: [
340
- /* @__PURE__ */ Je(
341
- "instancedMesh",
342
- {
343
- ref: (u) => {
344
- Pe.current = u, u && (u.count = 0, u.visible = !Be);
345
- },
346
- args: [He, n, je],
347
- frustumCulled: !1,
348
- renderOrder: 100,
349
- visible: g && !Be
350
- }
351
- ),
352
- ye && /* @__PURE__ */ Je(
353
- "mesh",
354
- {
355
- ref: Z,
356
- geometry: ie,
357
- material: Fe,
358
- frustumCulled: !1,
359
- renderOrder: 99,
360
- visible: g
361
- }
362
- )
363
- ] }) : null;
106
+ }, x), null;
364
107
  }
365
- const Zt = (
108
+ const te = (
366
109
  /* glsl */
367
110
  `
368
111
  attribute vec4 aColor;
@@ -372,7 +115,7 @@ void main() {
372
115
  gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
373
116
  }
374
117
  `
375
- ), kt = (
118
+ ), ne = (
376
119
  /* glsl */
377
120
  `
378
121
  varying vec4 vColor;
@@ -381,113 +124,145 @@ void main() {
381
124
  }
382
125
  `
383
126
  );
384
- function $t({
385
- positionRef: l,
386
- duration: r = 1,
387
- width: U = 0.3,
127
+ function se({
128
+ positionRef: r,
129
+ duration: t = 1,
130
+ width: v = 0.3,
388
131
  color: e = [1, 1, 1],
389
- maxPoints: g = 256,
390
- minDistance: N = 0.05,
391
- opacity: K = 1,
392
- blending: X = a.AdditiveBlending,
393
- visible: Q = !0
132
+ maxPoints: a = 256,
133
+ minDistance: x = 0.05,
134
+ opacity: T = 1,
135
+ blending: z = s.AdditiveBlending,
136
+ visible: p = !0
394
137
  }) {
395
- const { camera: re } = wt(), ce = j(null), Ye = j({
396
- positions: new Float32Array(g * 3),
397
- times: new Float32Array(g),
138
+ const { camera: S } = N(), D = I(null), L = I({
139
+ positions: new Float32Array(a * 3),
140
+ times: new Float32Array(a),
398
141
  head: 0,
399
142
  count: 0,
400
- lastPos: new a.Vector3(1 / 0, 1 / 0, 1 / 0),
143
+ lastPos: new s.Vector3(1 / 0, 1 / 0, 1 / 0),
401
144
  elapsed: 0
402
- }), { geometry: pe, posAttr: De, colorAttr: Pe, indexBuf: ge } = T(() => {
403
- const ye = g * 2, He = new Float32Array(ye * 3), n = new Float32Array(ye * 4), D = new a.BufferGeometry(), Se = new a.BufferAttribute(He, 3);
404
- Se.setUsage(a.DynamicDrawUsage), D.setAttribute("position", Se);
405
- const Z = new a.BufferAttribute(n, 4);
406
- Z.setUsage(a.DynamicDrawUsage), D.setAttribute("aColor", Z);
407
- const k = (g - 1) * 6, y = new Uint32Array(k);
408
- for (let ie = 0; ie < g - 1; ie++) {
409
- const z = ie * 2, L = ie * 6;
410
- y[L] = z, y[L + 1] = z + 1, y[L + 2] = z + 2, y[L + 3] = z + 1, y[L + 4] = z + 3, y[L + 5] = z + 2;
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);
148
+ const g = new s.BufferAttribute(n, 4);
149
+ g.setUsage(s.DynamicDrawUsage), R.setAttribute("aColor", g);
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;
411
154
  }
412
- const se = new a.BufferAttribute(y, 1);
413
- return D.setIndex(se), D.setDrawRange(0, 0), { geometry: D, posAttr: Se, colorAttr: Z, indexBuf: se };
414
- }, [g]), Ve = T(() => new a.ShaderMaterial({
415
- vertexShader: Zt,
416
- fragmentShader: kt,
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({
158
+ vertexShader: te,
159
+ fragmentShader: ne,
417
160
  transparent: !0,
418
161
  depthWrite: !1,
419
- side: a.DoubleSide,
420
- blending: X
421
- }), [X]), H = T(() => new a.Vector3(), []), f = T(() => new a.Vector3(), []), Be = T(() => new a.Vector3(), []), je = T(() => new a.Vector3(0, 1, 0), []), Ge = T(() => new a.Vector3(), []);
422
- return bt((ye, He) => {
423
- if (!ce.current) return;
424
- const n = Ye.current;
425
- if (n.elapsed += He, !Q) {
426
- n.count = 0, n.head = 0, n.lastPos.set(1 / 0, 1 / 0, 1 / 0), pe.setDrawRange(0, 0);
162
+ side: s.DoubleSide,
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) {
169
+ n.count = 0, n.head = 0, n.lastPos.set(1 / 0, 1 / 0, 1 / 0), C.setDrawRange(0, 0);
427
170
  return;
428
171
  }
429
- const D = l.current;
430
- if (!D) return;
431
- if (n.lastPos.distanceTo(D) >= N) {
432
- const z = (n.head + n.count) % g;
433
- n.positions[z * 3] = D.x, n.positions[z * 3 + 1] = D.y, n.positions[z * 3 + 2] = D.z, n.times[z] = n.elapsed, n.count < g ? n.count++ : n.head = (n.head + 1) % g, n.lastPos.copy(D);
172
+ const R = r.current;
173
+ if (!R) return;
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);
434
177
  }
435
178
  for (; n.count > 0; ) {
436
- const z = n.head;
437
- if (n.elapsed - n.times[z] > r)
438
- n.head = (n.head + 1) % g, n.count--;
179
+ const u = n.head;
180
+ if (n.elapsed - n.times[u] > t)
181
+ n.head = (n.head + 1) % a, n.count--;
439
182
  else
440
183
  break;
441
184
  }
442
185
  if (n.count < 2) {
443
- pe.setDrawRange(0, 0);
186
+ C.setDrawRange(0, 0);
444
187
  return;
445
188
  }
446
- const Z = De.array, k = Pe.array;
447
- let y = null;
448
- const se = n.count;
449
- for (let z = 0; z < se; z++) {
450
- const L = (n.head + z) % g, Fe = n.positions[L * 3], me = n.positions[L * 3 + 1], xe = n.positions[L * 3 + 2], fe = 1 - (n.elapsed - n.times[L]) / r;
451
- if (z < se - 1) {
452
- const Ee = (n.head + z + 1) % g;
453
- H.set(
454
- n.positions[Ee * 3] - Fe,
455
- n.positions[Ee * 3 + 1] - me,
456
- n.positions[Ee * 3 + 2] - xe
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
457
200
  );
458
- const Le = H.length();
459
- Le > 1e-6 ? H.divideScalar(Le) : y && H.copy(y);
460
- } else y && H.copy(y);
461
- Be.set(
462
- re.position.x - Fe,
463
- re.position.y - me,
464
- re.position.z - xe
465
- ), f.crossVectors(H, Be);
466
- let ee = f.length();
467
- ee < 1e-6 && (Ge.crossVectors(H, je), f.copy(Ge), ee = f.length(), ee < 1e-6 && (f.set(1, 0, 0), ee = 1)), f.divideScalar(ee);
468
- const oe = U * fe, Me = K * fe * fe, V = z * 2;
469
- Z[V * 3] = Fe + f.x * oe, Z[V * 3 + 1] = me + f.y * oe, Z[V * 3 + 2] = xe + f.z * oe, Z[(V + 1) * 3] = Fe - f.x * oe, Z[(V + 1) * 3 + 1] = me - f.y * oe, Z[(V + 1) * 3 + 2] = xe - f.z * oe, k[V * 4] = e[0], k[V * 4 + 1] = e[1], k[V * 4 + 2] = e[2], k[V * 4 + 3] = Me, k[(V + 1) * 4] = e[0], k[(V + 1) * 4 + 1] = e[1], k[(V + 1) * 4 + 2] = e[2], k[(V + 1) * 4 + 3] = Me, y = y || new a.Vector3(), y.copy(H);
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);
470
213
  }
471
- const ie = (se - 1) * 6;
472
- pe.setDrawRange(0, ie), De.needsUpdate = !0, Pe.needsUpdate = !0;
473
- }), /* @__PURE__ */ Je(
214
+ const F = (E - 1) * 6;
215
+ C.setDrawRange(0, F), V.needsUpdate = !0, H.needsUpdate = !0;
216
+ }), /* @__PURE__ */ $(
474
217
  "mesh",
475
218
  {
476
- ref: ce,
477
- geometry: pe,
478
- material: Ve,
219
+ ref: D,
220
+ geometry: C,
221
+ material: U,
479
222
  frustumCulled: !1,
480
223
  renderOrder: 101,
481
- visible: Q
224
+ visible: p
482
225
  }
483
226
  );
484
227
  }
228
+ function K(r) {
229
+ return Math.abs(Math.sin(r * 12.9898) * 43758.5453) % 1;
230
+ }
231
+ function re(r) {
232
+ const t = Math.sin(r * 54321.67) * 43758.5453 % 1;
233
+ return t < 0 ? t + 1 : t;
234
+ }
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;
239
+ if (r.randomSize) {
240
+ const z = r.minSize ?? 0.1, p = r.maxSize ?? 0.5;
241
+ x = z + (p - z) * re(v);
242
+ }
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);
247
+ }
248
+ return Math.max(0, x);
249
+ }
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));
257
+ }
258
+ return Math.max(0, Math.min(1, a));
259
+ }
485
260
  export {
486
- Jt as HZParticlesFX,
487
- $t as HZTrailRibbon,
488
- _t as computeParticleOpacity,
489
- Wt as computeParticleSize,
490
- tn as fetchPreset,
491
- At as particleHash,
492
- Gt as scalePreset
261
+ de as HZFaithfulFX,
262
+ se as HZTrailRibbon,
263
+ pe as computeParticleOpacity,
264
+ le as computeParticleSize,
265
+ he as fetchPreset,
266
+ K as particleHash,
267
+ ee as scalePreset
493
268
  };