falling-animation 0.1.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.
- package/LICENSE +21 -0
- package/README.md +251 -0
- package/dist/falling-animation.cjs.js +670 -0
- package/dist/falling-animation.cjs.js.map +1 -0
- package/dist/falling-animation.esm.js +663 -0
- package/dist/falling-animation.esm.js.map +1 -0
- package/dist/falling-animation.umd.js +676 -0
- package/dist/falling-animation.umd.js.map +1 -0
- package/dist/falling-animation.umd.min.js +9 -0
- package/dist/falling-animation.umd.min.js.map +1 -0
- package/dist/types/FallingAnimation.d.ts +77 -0
- package/dist/types/Particle.d.ts +52 -0
- package/dist/types/animations/index.d.ts +45 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/types.d.ts +100 -0
- package/dist/types/utils.d.ts +51 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 phongdh
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
# ð Falling Animation
|
|
2
|
+
|
|
3
|
+
A lightweight, customizable falling objects animation library for the web. Create beautiful falling effects like snow, leaves, confetti, and more!
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/falling-animation)
|
|
6
|
+
[](https://bundlephobia.com/package/falling-animation)
|
|
7
|
+
[](https://github.com/phongdh/falling-animation/blob/main/LICENSE)
|
|
8
|
+
|
|
9
|
+
## âĻ Features
|
|
10
|
+
|
|
11
|
+
- ðŠķ **Lightweight** - No dependencies, < 10KB gzipped
|
|
12
|
+
- ðĻ **Customizable** - Full control over speed, size, animation, and more
|
|
13
|
+
- ð **8 Animation Types** - fall, swing, rotate, flutter, spiral, tumble, zigzag, float
|
|
14
|
+
- ðą **Responsive** - Automatically adapts to container size
|
|
15
|
+
- ðžïļ **Multiple Object Types** - Emojis, images, or custom HTML
|
|
16
|
+
- ⥠**Performant** - Uses requestAnimationFrame and CSS transforms
|
|
17
|
+
- ðĶ **TypeScript** - Full type definitions included
|
|
18
|
+
- ð **Universal** - Works with ESM, CJS, and UMD
|
|
19
|
+
|
|
20
|
+
## ðĶ Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install falling-animation
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or use via CDN:
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
<script src="https://unpkg.com/falling-animation/dist/falling-animation.umd.min.js"></script>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## ð Quick Start
|
|
33
|
+
|
|
34
|
+
### ES Modules
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
import { FallingAnimation } from 'falling-animation';
|
|
38
|
+
|
|
39
|
+
const falling = new FallingAnimation({
|
|
40
|
+
objects: [
|
|
41
|
+
{ type: 'emoji', content: 'âïļ' },
|
|
42
|
+
{ type: 'emoji', content: 'ðļ' }
|
|
43
|
+
]
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### CDN / UMD
|
|
48
|
+
|
|
49
|
+
```html
|
|
50
|
+
<script src="https://unpkg.com/falling-animation/dist/falling-animation.umd.min.js"></script>
|
|
51
|
+
<script>
|
|
52
|
+
const falling = new FallingAnimation.FallingAnimation({
|
|
53
|
+
objects: [{ type: 'emoji', content: 'ð' }]
|
|
54
|
+
});
|
|
55
|
+
</script>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## ð API Reference
|
|
59
|
+
|
|
60
|
+
### Constructor Options
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
interface FallingAnimationOptions {
|
|
64
|
+
// Required: Objects to fall
|
|
65
|
+
objects: FallingObject[];
|
|
66
|
+
|
|
67
|
+
// Container element or selector (default: document.body)
|
|
68
|
+
container?: HTMLElement | string;
|
|
69
|
+
|
|
70
|
+
// Falling speed in px/frame (default: { min: 2, max: 5 })
|
|
71
|
+
speed?: { min: number; max: number };
|
|
72
|
+
|
|
73
|
+
// Objects spawned per second (default: 3)
|
|
74
|
+
spawnRate?: number;
|
|
75
|
+
|
|
76
|
+
// Maximum concurrent particles (default: 50)
|
|
77
|
+
maxParticles?: number;
|
|
78
|
+
|
|
79
|
+
// Animation type(s) (default: 'fall')
|
|
80
|
+
animation?: AnimationType | AnimationType[];
|
|
81
|
+
|
|
82
|
+
// Object size in px (default: { min: 20, max: 40 })
|
|
83
|
+
size?: { min: number; max: number };
|
|
84
|
+
|
|
85
|
+
// Object opacity (default: { min: 0.6, max: 1 })
|
|
86
|
+
opacity?: { min: number; max: number };
|
|
87
|
+
|
|
88
|
+
// Wind effect from -1 to 1 (default: 0)
|
|
89
|
+
wind?: number;
|
|
90
|
+
|
|
91
|
+
// Auto start animation (default: true)
|
|
92
|
+
autoStart?: boolean;
|
|
93
|
+
|
|
94
|
+
// Z-index for container (default: 9999)
|
|
95
|
+
zIndex?: number;
|
|
96
|
+
|
|
97
|
+
// Enable responsive behavior (default: true)
|
|
98
|
+
responsive?: boolean;
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Object Types
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
// Emoji
|
|
106
|
+
{ type: 'emoji', content: 'ð' }
|
|
107
|
+
|
|
108
|
+
// Image
|
|
109
|
+
{ type: 'image', src: '/path/to/image.png' }
|
|
110
|
+
|
|
111
|
+
// Custom HTML
|
|
112
|
+
{ type: 'html', content: '<div class="custom">â
</div>' }
|
|
113
|
+
|
|
114
|
+
// With weight for random selection
|
|
115
|
+
{ type: 'emoji', content: 'âïļ', weight: 3 }
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Animation Types
|
|
119
|
+
|
|
120
|
+
| Type | Description |
|
|
121
|
+
|------|-------------|
|
|
122
|
+
| `fall` | Simple vertical fall |
|
|
123
|
+
| `swing` | Pendulum-like swinging |
|
|
124
|
+
| `rotate` | Continuous 360° rotation |
|
|
125
|
+
| `flutter` | Butterfly-like fluttering |
|
|
126
|
+
| `spiral` | Spiraling down pattern |
|
|
127
|
+
| `tumble` | Chaotic tumbling motion |
|
|
128
|
+
| `zigzag` | Zigzag falling pattern |
|
|
129
|
+
| `float` | Slow floating descent |
|
|
130
|
+
|
|
131
|
+
### Methods
|
|
132
|
+
|
|
133
|
+
```javascript
|
|
134
|
+
// Control methods
|
|
135
|
+
falling.start(); // Start the animation
|
|
136
|
+
falling.stop(); // Stop and clear all particles
|
|
137
|
+
falling.pause(); // Pause animation (keeps particles)
|
|
138
|
+
falling.resume(); // Resume paused animation
|
|
139
|
+
falling.destroy(); // Clean up and remove from DOM
|
|
140
|
+
|
|
141
|
+
// Update options dynamically
|
|
142
|
+
falling.setOptions({
|
|
143
|
+
speed: { min: 5, max: 10 },
|
|
144
|
+
spawnRate: 5,
|
|
145
|
+
animation: 'tumble'
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Get state
|
|
149
|
+
falling.getParticleCount(); // Current particle count
|
|
150
|
+
falling.getIsRunning(); // Is animation running?
|
|
151
|
+
falling.getIsPaused(); // Is animation paused?
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## ðĻ Examples
|
|
155
|
+
|
|
156
|
+
### Snow Effect
|
|
157
|
+
|
|
158
|
+
```javascript
|
|
159
|
+
new FallingAnimation({
|
|
160
|
+
objects: [
|
|
161
|
+
{ type: 'emoji', content: 'âïļ' },
|
|
162
|
+
{ type: 'emoji', content: 'â
' },
|
|
163
|
+
{ type: 'emoji', content: 'â' }
|
|
164
|
+
],
|
|
165
|
+
animation: 'float',
|
|
166
|
+
speed: { min: 1, max: 3 },
|
|
167
|
+
size: { min: 15, max: 35 }
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Autumn Leaves
|
|
172
|
+
|
|
173
|
+
```javascript
|
|
174
|
+
new FallingAnimation({
|
|
175
|
+
objects: [
|
|
176
|
+
{ type: 'emoji', content: 'ð', weight: 3 },
|
|
177
|
+
{ type: 'emoji', content: 'ð', weight: 2 },
|
|
178
|
+
{ type: 'emoji', content: 'ð', weight: 1 }
|
|
179
|
+
],
|
|
180
|
+
animation: 'swing',
|
|
181
|
+
speed: { min: 2, max: 4 },
|
|
182
|
+
wind: 0.3
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Confetti Party
|
|
187
|
+
|
|
188
|
+
```javascript
|
|
189
|
+
new FallingAnimation({
|
|
190
|
+
objects: [
|
|
191
|
+
{ type: 'emoji', content: 'ð' },
|
|
192
|
+
{ type: 'emoji', content: 'ð' },
|
|
193
|
+
{ type: 'emoji', content: 'âĻ' }
|
|
194
|
+
],
|
|
195
|
+
animation: ['tumble', 'rotate', 'zigzag'],
|
|
196
|
+
speed: { min: 3, max: 6 },
|
|
197
|
+
spawnRate: 10,
|
|
198
|
+
maxParticles: 100
|
|
199
|
+
});
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Bounded Container
|
|
203
|
+
|
|
204
|
+
```javascript
|
|
205
|
+
new FallingAnimation({
|
|
206
|
+
container: '#my-container', // or document.getElementById('my-container')
|
|
207
|
+
objects: [{ type: 'emoji', content: 'â' }],
|
|
208
|
+
animation: 'spiral',
|
|
209
|
+
zIndex: 100
|
|
210
|
+
});
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Using Images
|
|
214
|
+
|
|
215
|
+
```javascript
|
|
216
|
+
new FallingAnimation({
|
|
217
|
+
objects: [
|
|
218
|
+
{ type: 'image', src: '/images/snowflake.png' },
|
|
219
|
+
{ type: 'image', src: '/images/star.png' }
|
|
220
|
+
],
|
|
221
|
+
size: { min: 30, max: 50 }
|
|
222
|
+
});
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## ð§ TypeScript
|
|
226
|
+
|
|
227
|
+
Full TypeScript support with exported types:
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
import {
|
|
231
|
+
FallingAnimation,
|
|
232
|
+
FallingAnimationOptions,
|
|
233
|
+
FallingObject,
|
|
234
|
+
AnimationType
|
|
235
|
+
} from 'falling-animation';
|
|
236
|
+
|
|
237
|
+
const options: FallingAnimationOptions = {
|
|
238
|
+
objects: [{ type: 'emoji', content: 'ð' }],
|
|
239
|
+
animation: 'rotate' as AnimationType
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const falling = new FallingAnimation(options);
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## ð License
|
|
246
|
+
|
|
247
|
+
MIT ÂĐ [phongdh](https://github.com/phongdh)
|
|
248
|
+
|
|
249
|
+
## ð Contributing
|
|
250
|
+
|
|
251
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|