partycles 1.1.5 → 1.2.1
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.
- package/README.md +107 -10
- package/dist/index.d.mts +149 -0
- package/dist/index.d.ts +149 -5
- package/dist/index.js +48 -1487
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +20 -9
- package/dist/animations/animations/aurora.d.ts +0 -8
- package/dist/animations/animations/aurora.d.ts.map +0 -1
- package/dist/animations/animations/balloons.d.ts +0 -8
- package/dist/animations/animations/balloons.d.ts.map +0 -1
- package/dist/animations/animations/bubbles.d.ts +0 -8
- package/dist/animations/animations/bubbles.d.ts.map +0 -1
- package/dist/animations/animations/coins.d.ts +0 -10
- package/dist/animations/animations/coins.d.ts.map +0 -1
- package/dist/animations/animations/confetti.d.ts +0 -8
- package/dist/animations/animations/confetti.d.ts.map +0 -1
- package/dist/animations/animations/crystals.d.ts +0 -8
- package/dist/animations/animations/crystals.d.ts.map +0 -1
- package/dist/animations/animations/emoji.d.ts +0 -19
- package/dist/animations/animations/emoji.d.ts.map +0 -1
- package/dist/animations/animations/fireflies.d.ts +0 -8
- package/dist/animations/animations/fireflies.d.ts.map +0 -1
- package/dist/animations/animations/fireworks.d.ts +0 -8
- package/dist/animations/animations/fireworks.d.ts.map +0 -1
- package/dist/animations/animations/galaxy.d.ts +0 -8
- package/dist/animations/animations/galaxy.d.ts.map +0 -1
- package/dist/animations/animations/glitch.d.ts +0 -8
- package/dist/animations/animations/glitch.d.ts.map +0 -1
- package/dist/animations/animations/hearts.d.ts +0 -10
- package/dist/animations/animations/hearts.d.ts.map +0 -1
- package/dist/animations/animations/index.d.ts +0 -13
- package/dist/animations/animations/index.d.ts.map +0 -1
- package/dist/animations/animations/leaves.d.ts +0 -8
- package/dist/animations/animations/leaves.d.ts.map +0 -1
- package/dist/animations/animations/magicdust.d.ts +0 -8
- package/dist/animations/animations/magicdust.d.ts.map +0 -1
- package/dist/animations/animations/paint.d.ts +0 -8
- package/dist/animations/animations/paint.d.ts.map +0 -1
- package/dist/animations/animations/petals.d.ts +0 -8
- package/dist/animations/animations/petals.d.ts.map +0 -1
- package/dist/animations/animations/snow.d.ts +0 -8
- package/dist/animations/animations/snow.d.ts.map +0 -1
- package/dist/animations/animations/sparkles.d.ts +0 -8
- package/dist/animations/animations/sparkles.d.ts.map +0 -1
- package/dist/animations/animations/stars.d.ts +0 -8
- package/dist/animations/animations/stars.d.ts.map +0 -1
- package/dist/animations/aurora.d.ts +0 -8
- package/dist/animations/aurora.d.ts.map +0 -1
- package/dist/animations/balloons.d.ts +0 -8
- package/dist/animations/balloons.d.ts.map +0 -1
- package/dist/animations/bubbles.d.ts +0 -8
- package/dist/animations/bubbles.d.ts.map +0 -1
- package/dist/animations/bubbles.esm.js +0 -53
- package/dist/animations/bubbles.esm.js.map +0 -1
- package/dist/animations/bubbles.js +0 -56
- package/dist/animations/bubbles.js.map +0 -1
- package/dist/animations/coins.d.ts +0 -10
- package/dist/animations/coins.d.ts.map +0 -1
- package/dist/animations/confetti.d.ts +0 -8
- package/dist/animations/confetti.d.ts.map +0 -1
- package/dist/animations/confetti.esm.js +0 -67
- package/dist/animations/confetti.esm.js.map +0 -1
- package/dist/animations/confetti.js +0 -70
- package/dist/animations/confetti.js.map +0 -1
- package/dist/animations/crystals.d.ts +0 -8
- package/dist/animations/crystals.d.ts.map +0 -1
- package/dist/animations/emoji.d.ts +0 -19
- package/dist/animations/emoji.d.ts.map +0 -1
- package/dist/animations/emoji.esm.js +0 -58
- package/dist/animations/emoji.esm.js.map +0 -1
- package/dist/animations/emoji.js +0 -62
- package/dist/animations/emoji.js.map +0 -1
- package/dist/animations/fireflies.d.ts +0 -8
- package/dist/animations/fireflies.d.ts.map +0 -1
- package/dist/animations/fireworks.d.ts +0 -8
- package/dist/animations/fireworks.d.ts.map +0 -1
- package/dist/animations/fireworks.esm.js +0 -64
- package/dist/animations/fireworks.esm.js.map +0 -1
- package/dist/animations/fireworks.js +0 -67
- package/dist/animations/fireworks.js.map +0 -1
- package/dist/animations/galaxy.d.ts +0 -8
- package/dist/animations/galaxy.d.ts.map +0 -1
- package/dist/animations/glitch.d.ts +0 -8
- package/dist/animations/glitch.d.ts.map +0 -1
- package/dist/animations/hearts.d.ts +0 -10
- package/dist/animations/hearts.d.ts.map +0 -1
- package/dist/animations/hearts.esm.js +0 -50
- package/dist/animations/hearts.esm.js.map +0 -1
- package/dist/animations/hearts.js +0 -53
- package/dist/animations/hearts.js.map +0 -1
- package/dist/animations/index.d.ts +0 -5
- package/dist/animations/index.d.ts.map +0 -1
- package/dist/animations/leaves.d.ts +0 -8
- package/dist/animations/leaves.d.ts.map +0 -1
- package/dist/animations/magicdust.d.ts +0 -8
- package/dist/animations/magicdust.d.ts.map +0 -1
- package/dist/animations/mobileOptimizations.d.ts +0 -6
- package/dist/animations/mobileOptimizations.d.ts.map +0 -1
- package/dist/animations/paint.d.ts +0 -8
- package/dist/animations/paint.d.ts.map +0 -1
- package/dist/animations/petals.d.ts +0 -8
- package/dist/animations/petals.d.ts.map +0 -1
- package/dist/animations/snow.d.ts +0 -8
- package/dist/animations/snow.d.ts.map +0 -1
- package/dist/animations/snow.esm.js +0 -50
- package/dist/animations/snow.esm.js.map +0 -1
- package/dist/animations/snow.js +0 -53
- package/dist/animations/snow.js.map +0 -1
- package/dist/animations/sparkles.d.ts +0 -8
- package/dist/animations/sparkles.d.ts.map +0 -1
- package/dist/animations/sparkles.esm.js +0 -42
- package/dist/animations/sparkles.esm.js.map +0 -1
- package/dist/animations/sparkles.js +0 -45
- package/dist/animations/sparkles.js.map +0 -1
- package/dist/animations/stars.d.ts +0 -8
- package/dist/animations/stars.d.ts.map +0 -1
- package/dist/animations/stars.esm.js +0 -42
- package/dist/animations/stars.esm.js.map +0 -1
- package/dist/animations/stars.js +0 -45
- package/dist/animations/stars.js.map +0 -1
- package/dist/animations/types.d.ts +0 -42
- package/dist/animations/types.d.ts.map +0 -1
- package/dist/animations/useReward.d.ts +0 -8
- package/dist/animations/useReward.d.ts.map +0 -1
- package/dist/animations/utils.d.ts +0 -7
- package/dist/animations/utils.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.esm.js +0 -1489
- package/dist/index.esm.js.map +0 -1
- package/dist/mobileOptimizations.d.ts +0 -6
- package/dist/mobileOptimizations.d.ts.map +0 -1
- package/dist/types.d.ts +0 -42
- package/dist/types.d.ts.map +0 -1
- package/dist/useReward.d.ts +0 -8
- package/dist/useReward.d.ts.map +0 -1
- package/dist/utils.d.ts +0 -7
- package/dist/utils.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ A lightweight, performant React library for adding delightful animation effects
|
|
|
12
12
|
## ✨ Features
|
|
13
13
|
|
|
14
14
|
- 🎯 **Simple API** - Just one hook to rule them all
|
|
15
|
-
- 🎨 **
|
|
15
|
+
- 🎨 **20 Beautiful Animations** - Confetti, sparkles, hearts, stars, fireworks, bubbles, snow, emoji, coins, petals, aurora, fireflies, paint, balloons, galaxy, glitch, magicdust, crystals, leaves, and mortar
|
|
16
16
|
- 📦 **Tiny Bundle** - Zero dependencies, optimized for performance
|
|
17
17
|
- 🚀 **Performant** - Optimized animations using requestAnimationFrame
|
|
18
18
|
- 🎮 **Full Control** - Customize colors, particle count, physics, and more
|
|
@@ -33,13 +33,15 @@ pnpm add partycles
|
|
|
33
33
|
## 🚀 Quick Start
|
|
34
34
|
|
|
35
35
|
```tsx
|
|
36
|
+
import { useRef } from 'react';
|
|
36
37
|
import { useReward } from 'partycles';
|
|
37
38
|
|
|
38
39
|
function App() {
|
|
39
|
-
const
|
|
40
|
+
const buttonRef = useRef<HTMLButtonElement>(null);
|
|
41
|
+
const { reward, isAnimating } = useReward(buttonRef, 'confetti');
|
|
40
42
|
|
|
41
43
|
return (
|
|
42
|
-
<button
|
|
44
|
+
<button ref={buttonRef} onClick={reward} disabled={isAnimating}>
|
|
43
45
|
Click me for a surprise! 🎉
|
|
44
46
|
</button>
|
|
45
47
|
);
|
|
@@ -48,31 +50,50 @@ function App() {
|
|
|
48
50
|
|
|
49
51
|
That's it! No configuration needed - it just works. 🎊
|
|
50
52
|
|
|
53
|
+
### Using String IDs (Legacy)
|
|
54
|
+
|
|
55
|
+
For backward compatibility, you can still use element IDs:
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
const { reward, isAnimating } = useReward('my-button', 'confetti');
|
|
59
|
+
|
|
60
|
+
<button id="my-button" onClick={reward}>
|
|
61
|
+
Click me! 🎉
|
|
62
|
+
</button>
|
|
63
|
+
```
|
|
64
|
+
|
|
51
65
|
## 🤔 Why Partycles?
|
|
52
66
|
|
|
53
67
|
- **Zero Dependencies** - No bloat, just pure React code
|
|
54
68
|
- **One Hook** - Simple `useReward` hook handles everything
|
|
55
|
-
- **
|
|
69
|
+
- **20 Animations** - From confetti to explosive effects, we've got you covered
|
|
56
70
|
- **Fully Typed** - Great TypeScript support out of the box
|
|
57
71
|
- **Customizable** - Tweak colors, physics, particle count, and more
|
|
58
72
|
- **Performant** - Optimized animations that won't slow down your app
|
|
59
73
|
|
|
60
74
|
## 📖 API Reference
|
|
61
75
|
|
|
62
|
-
### `useReward(
|
|
76
|
+
### `useReward(targetRef, animationType, config?)` (Recommended)
|
|
77
|
+
### `useReward(elementId, animationType, config?)` (Legacy)
|
|
63
78
|
|
|
64
79
|
The main hook for creating reward animations.
|
|
65
80
|
|
|
66
81
|
#### Parameters
|
|
67
82
|
|
|
68
|
-
- `
|
|
69
|
-
- `
|
|
83
|
+
- `targetRef` (RefObject<HTMLElement>): A React ref to the element to animate from (recommended)
|
|
84
|
+
- `elementId` (string): The ID of the element to animate from (legacy, for backward compatibility)
|
|
85
|
+
- `animationType` (string): One of: `'confetti'`, `'sparkles'`, `'hearts'`, `'stars'`, `'fireworks'`, `'bubbles'`, `'snow'`, `'emoji'`, `'coins'`, `'petals'`, `'aurora'`, `'fireflies'`, `'paint'`, `'balloons'`, `'galaxy'`, `'glitch'`, `'magicdust'`, `'crystals'`, `'leaves'`, `'mortar'`
|
|
70
86
|
- `config` (optional): Animation configuration object
|
|
71
87
|
|
|
72
88
|
#### Returns
|
|
73
89
|
|
|
74
|
-
- `reward` (function): Triggers the animation
|
|
90
|
+
- `reward` (function): Triggers the animation, returns a Promise that resolves when complete
|
|
75
91
|
- `isAnimating` (boolean): Whether the animation is currently running
|
|
92
|
+
- `pause` (function): Pauses the current animation
|
|
93
|
+
- `resume` (function): Resumes a paused animation
|
|
94
|
+
- `replay` (function): Stops current animation and starts a new one
|
|
95
|
+
- `isPaused` (boolean): Whether the animation is currently paused
|
|
96
|
+
- `targetRef` (RefObject<HTMLElement>): The ref object (only returned when using ref-based API)
|
|
76
97
|
|
|
77
98
|
### Configuration Options
|
|
78
99
|
|
|
@@ -109,7 +130,8 @@ interface AnimationConfig {
|
|
|
109
130
|
Classic celebration effect with colorful paper pieces.
|
|
110
131
|
|
|
111
132
|
```tsx
|
|
112
|
-
const
|
|
133
|
+
const buttonRef = useRef<HTMLButtonElement>(null);
|
|
134
|
+
const { reward } = useReward(buttonRef, 'confetti', {
|
|
113
135
|
particleCount: 30,
|
|
114
136
|
spread: 60,
|
|
115
137
|
colors: ['#ff0000', '#00ff00', '#0000ff'],
|
|
@@ -313,8 +335,72 @@ const { reward } = useReward('buttonId', 'leaves', {
|
|
|
313
335
|
});
|
|
314
336
|
```
|
|
315
337
|
|
|
338
|
+
### Mortar 💥
|
|
339
|
+
Explosive mortar-style bursts with galaxy-like explosions.
|
|
340
|
+
|
|
341
|
+
```tsx
|
|
342
|
+
const { reward } = useReward('buttonId', 'mortar', {
|
|
343
|
+
particleCount: 2,
|
|
344
|
+
spread: 45,
|
|
345
|
+
physics: { gravity: 0.35 }
|
|
346
|
+
});
|
|
347
|
+
```
|
|
348
|
+
|
|
316
349
|
## 💡 Examples
|
|
317
350
|
|
|
351
|
+
### Animation Controls
|
|
352
|
+
|
|
353
|
+
Control your animations with pause, resume, and replay:
|
|
354
|
+
|
|
355
|
+
```tsx
|
|
356
|
+
import { useRef } from 'react';
|
|
357
|
+
import { useReward } from 'partycles';
|
|
358
|
+
|
|
359
|
+
function ControlledAnimation() {
|
|
360
|
+
const buttonRef = useRef<HTMLButtonElement>(null);
|
|
361
|
+
const { reward, isAnimating, pause, resume, replay, isPaused } = useReward(
|
|
362
|
+
buttonRef,
|
|
363
|
+
'confetti',
|
|
364
|
+
{ particleCount: 50 }
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
return (
|
|
368
|
+
<div>
|
|
369
|
+
<button ref={buttonRef} onClick={reward}>
|
|
370
|
+
Start Animation
|
|
371
|
+
</button>
|
|
372
|
+
|
|
373
|
+
<button onClick={pause} disabled={!isAnimating || isPaused}>
|
|
374
|
+
Pause
|
|
375
|
+
</button>
|
|
376
|
+
|
|
377
|
+
<button onClick={resume} disabled={!isAnimating || !isPaused}>
|
|
378
|
+
Resume
|
|
379
|
+
</button>
|
|
380
|
+
|
|
381
|
+
<button onClick={replay}>
|
|
382
|
+
Replay
|
|
383
|
+
</button>
|
|
384
|
+
|
|
385
|
+
<p>Status: {isAnimating ? (isPaused ? 'Paused' : 'Playing') : 'Idle'}</p>
|
|
386
|
+
</div>
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
### Promise-based Completion
|
|
392
|
+
|
|
393
|
+
Chain actions after animations complete:
|
|
394
|
+
|
|
395
|
+
```tsx
|
|
396
|
+
const { reward } = useReward(buttonRef, 'confetti');
|
|
397
|
+
|
|
398
|
+
const handleSuccess = async () => {
|
|
399
|
+
await reward(); // Wait for animation to complete
|
|
400
|
+
console.log('Animation finished!');
|
|
401
|
+
// Navigate, show message, etc.
|
|
402
|
+
};
|
|
403
|
+
|
|
318
404
|
### Form Submission Success
|
|
319
405
|
```tsx
|
|
320
406
|
function ContactForm() {
|
|
@@ -529,7 +615,18 @@ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) f
|
|
|
529
615
|
|
|
530
616
|
## 📈 Changelog
|
|
531
617
|
|
|
532
|
-
### v1.1
|
|
618
|
+
### v1.2.1 (Latest)
|
|
619
|
+
- 🎆 Added new `mortar` animation with galaxy-style explosions
|
|
620
|
+
- 🐛 Fixed particle rendering issues with dynamic particle creation
|
|
621
|
+
- 🎨 Updated emoji assignments for better consistency (fireflies: 🌟, coins: 💰)
|
|
622
|
+
- ⚡ Optimized mortar explosion performance for mobile devices
|
|
623
|
+
- 🔧 Improved animation manager to handle particles created during updates
|
|
624
|
+
|
|
625
|
+
### v1.1.5
|
|
626
|
+
- ✨ Added optional enhanced effects (flutter, twinkle, pulse, spin3D, wobble, windDrift)
|
|
627
|
+
- 📱 Improved mobile performance with automatic optimizations
|
|
628
|
+
|
|
629
|
+
### v1.1.3
|
|
533
630
|
- 🚀 Added automatic mobile performance optimizations
|
|
534
631
|
- 🐛 Fixed Safari compatibility issues
|
|
535
632
|
- 📦 Streamlined bundle size by removing 7 animations
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
|
|
3
|
+
interface Particle {
|
|
4
|
+
id: string;
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
vx: number;
|
|
8
|
+
vy: number;
|
|
9
|
+
life: number;
|
|
10
|
+
opacity: number;
|
|
11
|
+
size: number;
|
|
12
|
+
rotation: number;
|
|
13
|
+
color: string;
|
|
14
|
+
element?: React.ReactNode | string;
|
|
15
|
+
config?: AnimationConfig;
|
|
16
|
+
}
|
|
17
|
+
interface AnimationConfig {
|
|
18
|
+
particleCount?: number;
|
|
19
|
+
spread?: number;
|
|
20
|
+
startVelocity?: number;
|
|
21
|
+
decay?: number;
|
|
22
|
+
lifetime?: number;
|
|
23
|
+
colors?: string[];
|
|
24
|
+
elementSize?: number;
|
|
25
|
+
duration?: number;
|
|
26
|
+
physics?: {
|
|
27
|
+
gravity?: number;
|
|
28
|
+
wind?: number;
|
|
29
|
+
friction?: number;
|
|
30
|
+
};
|
|
31
|
+
effects?: {
|
|
32
|
+
flutter?: boolean;
|
|
33
|
+
twinkle?: boolean;
|
|
34
|
+
pulse?: boolean;
|
|
35
|
+
spin3D?: boolean;
|
|
36
|
+
wobble?: boolean;
|
|
37
|
+
windDrift?: boolean;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
type AnimationType = 'confetti' | 'sparkles' | 'fireworks' | 'hearts' | 'stars' | 'bubbles' | 'snow' | 'emoji' | 'coins' | 'petals' | 'aurora' | 'fireflies' | 'paint' | 'balloons' | 'galaxy' | 'leaves' | 'glitch' | 'magicdust' | 'crystals' | 'mortar';
|
|
41
|
+
interface UseRewardConfig extends AnimationConfig {
|
|
42
|
+
animationType: AnimationType;
|
|
43
|
+
}
|
|
44
|
+
interface AnimationControls {
|
|
45
|
+
pause: () => void;
|
|
46
|
+
resume: () => void;
|
|
47
|
+
replay: () => Promise<void>;
|
|
48
|
+
isPaused: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface UseRewardReturn extends AnimationControls {
|
|
52
|
+
reward: () => Promise<void>;
|
|
53
|
+
isAnimating: boolean;
|
|
54
|
+
targetRef?: RefObject<HTMLElement>;
|
|
55
|
+
}
|
|
56
|
+
declare function useReward(elementId: string, animationType: AnimationType, config?: AnimationConfig): UseRewardReturn;
|
|
57
|
+
declare function useReward(targetRef: RefObject<HTMLElement>, animationType: AnimationType, config?: AnimationConfig): UseRewardReturn;
|
|
58
|
+
|
|
59
|
+
declare const emojiPresets: {
|
|
60
|
+
celebration: string[];
|
|
61
|
+
love: string[];
|
|
62
|
+
happy: string[];
|
|
63
|
+
nature: string[];
|
|
64
|
+
food: string[];
|
|
65
|
+
default: string[];
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
declare const isMobileDevice: () => boolean;
|
|
69
|
+
declare const optimizeConfigForMobile: (config: AnimationConfig) => AnimationConfig;
|
|
70
|
+
|
|
71
|
+
interface PooledParticle extends Particle {
|
|
72
|
+
_pooled?: boolean;
|
|
73
|
+
}
|
|
74
|
+
declare class ParticlePool {
|
|
75
|
+
private pool;
|
|
76
|
+
private maxSize;
|
|
77
|
+
private created;
|
|
78
|
+
constructor(maxSize?: number);
|
|
79
|
+
acquire(): PooledParticle;
|
|
80
|
+
release(particle: PooledParticle): void;
|
|
81
|
+
releaseAll(particles: PooledParticle[]): void;
|
|
82
|
+
clear(): void;
|
|
83
|
+
getStats(): {
|
|
84
|
+
poolSize: number;
|
|
85
|
+
totalCreated: number;
|
|
86
|
+
maxSize: number;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
declare const particlePool: ParticlePool;
|
|
90
|
+
|
|
91
|
+
interface AnimationInstance {
|
|
92
|
+
id: string;
|
|
93
|
+
particles: Particle[];
|
|
94
|
+
containerElement: HTMLDivElement;
|
|
95
|
+
renderFunction: (particle: Particle) => React.ReactNode;
|
|
96
|
+
updateCallback?: (particles: Particle[]) => void;
|
|
97
|
+
onComplete?: () => void;
|
|
98
|
+
physics: {
|
|
99
|
+
gravity: number;
|
|
100
|
+
friction: number;
|
|
101
|
+
wind: number;
|
|
102
|
+
};
|
|
103
|
+
animationType: string;
|
|
104
|
+
config?: {
|
|
105
|
+
effects?: {
|
|
106
|
+
flutter?: boolean;
|
|
107
|
+
windDrift?: boolean;
|
|
108
|
+
wobble?: boolean;
|
|
109
|
+
twinkle?: boolean;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
frameCount: number;
|
|
113
|
+
isPaused?: boolean;
|
|
114
|
+
pausedAt?: number;
|
|
115
|
+
}
|
|
116
|
+
declare class AnimationManager {
|
|
117
|
+
private animations;
|
|
118
|
+
private rafId;
|
|
119
|
+
private isRunning;
|
|
120
|
+
private lastFrameTime;
|
|
121
|
+
private frameInterval;
|
|
122
|
+
private frameCount;
|
|
123
|
+
private fpsUpdateInterval;
|
|
124
|
+
private lastFpsUpdate;
|
|
125
|
+
private currentFps;
|
|
126
|
+
constructor();
|
|
127
|
+
addAnimation(animation: AnimationInstance): void;
|
|
128
|
+
removeAnimation(id: string): void;
|
|
129
|
+
private start;
|
|
130
|
+
private stop;
|
|
131
|
+
private update;
|
|
132
|
+
private applyEffects;
|
|
133
|
+
private handleMortarExplosion;
|
|
134
|
+
private updateOpacity;
|
|
135
|
+
getStats(): {
|
|
136
|
+
activeAnimations: number;
|
|
137
|
+
currentFps: number;
|
|
138
|
+
isRunning: boolean;
|
|
139
|
+
totalParticles: number;
|
|
140
|
+
};
|
|
141
|
+
setTargetFPS(fps: number): void;
|
|
142
|
+
pauseAnimation(id: string): void;
|
|
143
|
+
resumeAnimation(id: string): void;
|
|
144
|
+
isAnimationPaused(id: string): boolean;
|
|
145
|
+
getAnimation(id: string): AnimationInstance | undefined;
|
|
146
|
+
}
|
|
147
|
+
declare const animationManager: AnimationManager;
|
|
148
|
+
|
|
149
|
+
export { type AnimationConfig, type AnimationType, type UseRewardConfig, animationManager, emojiPresets, isMobileDevice, optimizeConfigForMobile, particlePool, useReward };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,149 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
|
|
3
|
+
interface Particle {
|
|
4
|
+
id: string;
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
vx: number;
|
|
8
|
+
vy: number;
|
|
9
|
+
life: number;
|
|
10
|
+
opacity: number;
|
|
11
|
+
size: number;
|
|
12
|
+
rotation: number;
|
|
13
|
+
color: string;
|
|
14
|
+
element?: React.ReactNode | string;
|
|
15
|
+
config?: AnimationConfig;
|
|
16
|
+
}
|
|
17
|
+
interface AnimationConfig {
|
|
18
|
+
particleCount?: number;
|
|
19
|
+
spread?: number;
|
|
20
|
+
startVelocity?: number;
|
|
21
|
+
decay?: number;
|
|
22
|
+
lifetime?: number;
|
|
23
|
+
colors?: string[];
|
|
24
|
+
elementSize?: number;
|
|
25
|
+
duration?: number;
|
|
26
|
+
physics?: {
|
|
27
|
+
gravity?: number;
|
|
28
|
+
wind?: number;
|
|
29
|
+
friction?: number;
|
|
30
|
+
};
|
|
31
|
+
effects?: {
|
|
32
|
+
flutter?: boolean;
|
|
33
|
+
twinkle?: boolean;
|
|
34
|
+
pulse?: boolean;
|
|
35
|
+
spin3D?: boolean;
|
|
36
|
+
wobble?: boolean;
|
|
37
|
+
windDrift?: boolean;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
type AnimationType = 'confetti' | 'sparkles' | 'fireworks' | 'hearts' | 'stars' | 'bubbles' | 'snow' | 'emoji' | 'coins' | 'petals' | 'aurora' | 'fireflies' | 'paint' | 'balloons' | 'galaxy' | 'leaves' | 'glitch' | 'magicdust' | 'crystals' | 'mortar';
|
|
41
|
+
interface UseRewardConfig extends AnimationConfig {
|
|
42
|
+
animationType: AnimationType;
|
|
43
|
+
}
|
|
44
|
+
interface AnimationControls {
|
|
45
|
+
pause: () => void;
|
|
46
|
+
resume: () => void;
|
|
47
|
+
replay: () => Promise<void>;
|
|
48
|
+
isPaused: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface UseRewardReturn extends AnimationControls {
|
|
52
|
+
reward: () => Promise<void>;
|
|
53
|
+
isAnimating: boolean;
|
|
54
|
+
targetRef?: RefObject<HTMLElement>;
|
|
55
|
+
}
|
|
56
|
+
declare function useReward(elementId: string, animationType: AnimationType, config?: AnimationConfig): UseRewardReturn;
|
|
57
|
+
declare function useReward(targetRef: RefObject<HTMLElement>, animationType: AnimationType, config?: AnimationConfig): UseRewardReturn;
|
|
58
|
+
|
|
59
|
+
declare const emojiPresets: {
|
|
60
|
+
celebration: string[];
|
|
61
|
+
love: string[];
|
|
62
|
+
happy: string[];
|
|
63
|
+
nature: string[];
|
|
64
|
+
food: string[];
|
|
65
|
+
default: string[];
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
declare const isMobileDevice: () => boolean;
|
|
69
|
+
declare const optimizeConfigForMobile: (config: AnimationConfig) => AnimationConfig;
|
|
70
|
+
|
|
71
|
+
interface PooledParticle extends Particle {
|
|
72
|
+
_pooled?: boolean;
|
|
73
|
+
}
|
|
74
|
+
declare class ParticlePool {
|
|
75
|
+
private pool;
|
|
76
|
+
private maxSize;
|
|
77
|
+
private created;
|
|
78
|
+
constructor(maxSize?: number);
|
|
79
|
+
acquire(): PooledParticle;
|
|
80
|
+
release(particle: PooledParticle): void;
|
|
81
|
+
releaseAll(particles: PooledParticle[]): void;
|
|
82
|
+
clear(): void;
|
|
83
|
+
getStats(): {
|
|
84
|
+
poolSize: number;
|
|
85
|
+
totalCreated: number;
|
|
86
|
+
maxSize: number;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
declare const particlePool: ParticlePool;
|
|
90
|
+
|
|
91
|
+
interface AnimationInstance {
|
|
92
|
+
id: string;
|
|
93
|
+
particles: Particle[];
|
|
94
|
+
containerElement: HTMLDivElement;
|
|
95
|
+
renderFunction: (particle: Particle) => React.ReactNode;
|
|
96
|
+
updateCallback?: (particles: Particle[]) => void;
|
|
97
|
+
onComplete?: () => void;
|
|
98
|
+
physics: {
|
|
99
|
+
gravity: number;
|
|
100
|
+
friction: number;
|
|
101
|
+
wind: number;
|
|
102
|
+
};
|
|
103
|
+
animationType: string;
|
|
104
|
+
config?: {
|
|
105
|
+
effects?: {
|
|
106
|
+
flutter?: boolean;
|
|
107
|
+
windDrift?: boolean;
|
|
108
|
+
wobble?: boolean;
|
|
109
|
+
twinkle?: boolean;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
frameCount: number;
|
|
113
|
+
isPaused?: boolean;
|
|
114
|
+
pausedAt?: number;
|
|
115
|
+
}
|
|
116
|
+
declare class AnimationManager {
|
|
117
|
+
private animations;
|
|
118
|
+
private rafId;
|
|
119
|
+
private isRunning;
|
|
120
|
+
private lastFrameTime;
|
|
121
|
+
private frameInterval;
|
|
122
|
+
private frameCount;
|
|
123
|
+
private fpsUpdateInterval;
|
|
124
|
+
private lastFpsUpdate;
|
|
125
|
+
private currentFps;
|
|
126
|
+
constructor();
|
|
127
|
+
addAnimation(animation: AnimationInstance): void;
|
|
128
|
+
removeAnimation(id: string): void;
|
|
129
|
+
private start;
|
|
130
|
+
private stop;
|
|
131
|
+
private update;
|
|
132
|
+
private applyEffects;
|
|
133
|
+
private handleMortarExplosion;
|
|
134
|
+
private updateOpacity;
|
|
135
|
+
getStats(): {
|
|
136
|
+
activeAnimations: number;
|
|
137
|
+
currentFps: number;
|
|
138
|
+
isRunning: boolean;
|
|
139
|
+
totalParticles: number;
|
|
140
|
+
};
|
|
141
|
+
setTargetFPS(fps: number): void;
|
|
142
|
+
pauseAnimation(id: string): void;
|
|
143
|
+
resumeAnimation(id: string): void;
|
|
144
|
+
isAnimationPaused(id: string): boolean;
|
|
145
|
+
getAnimation(id: string): AnimationInstance | undefined;
|
|
146
|
+
}
|
|
147
|
+
declare const animationManager: AnimationManager;
|
|
148
|
+
|
|
149
|
+
export { type AnimationConfig, type AnimationType, type UseRewardConfig, animationManager, emojiPresets, isMobileDevice, optimizeConfigForMobile, particlePool, useReward };
|