@tsparticles/preset-confetti 3.0.0-alpha.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/LICENSE +21 -0
- package/README.md +453 -0
- package/browser/ConfettiOptions.js +100 -0
- package/browser/IConfettiOptions.js +1 -0
- package/browser/bundle.js +6 -0
- package/browser/index.js +55 -0
- package/browser/options.js +131 -0
- package/cjs/ConfettiOptions.js +104 -0
- package/cjs/IConfettiOptions.js +2 -0
- package/cjs/bundle.js +20 -0
- package/cjs/index.js +75 -0
- package/cjs/options.js +135 -0
- package/esm/ConfettiOptions.js +100 -0
- package/esm/IConfettiOptions.js +1 -0
- package/esm/bundle.js +6 -0
- package/esm/index.js +55 -0
- package/esm/options.js +131 -0
- package/package.json +105 -0
- package/report.html +39 -0
- package/tsparticles.preset.confetti.bundle.js +8088 -0
- package/tsparticles.preset.confetti.bundle.min.js +2 -0
- package/tsparticles.preset.confetti.bundle.min.js.LICENSE.txt +8 -0
- package/tsparticles.preset.confetti.js +520 -0
- package/tsparticles.preset.confetti.min.js +2 -0
- package/tsparticles.preset.confetti.min.js.LICENSE.txt +8 -0
- package/types/ConfettiOptions.d.ts +24 -0
- package/types/IConfettiOptions.d.ts +19 -0
- package/types/bundle.d.ts +5 -0
- package/types/index.d.ts +6 -0
- package/types/options.d.ts +3 -0
- package/umd/ConfettiOptions.js +114 -0
- package/umd/IConfettiOptions.js +12 -0
- package/umd/bundle.js +21 -0
- package/umd/index.js +70 -0
- package/umd/options.js +145 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Matteo Bruni
|
|
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,453 @@
|
|
|
1
|
+
[](https://particles.js.org)
|
|
2
|
+
|
|
3
|
+
# tsParticles Confetti Preset
|
|
4
|
+
|
|
5
|
+
[](https://www.jsdelivr.com/package/npm/@tsparticles/preset-confetti) [](https://www.npmjs.com/package/@tsparticles/preset-confetti) [](https://www.npmjs.com/package/@tsparticles/preset-confetti) [](https://github.com/sponsors/matteobruni)
|
|
6
|
+
|
|
7
|
+
[tsParticles](https://github.com/matteobruni/tsparticles) preset for white and red confetti launched from the screen
|
|
8
|
+
center on a transparent background.
|
|
9
|
+
|
|
10
|
+
[](https://join.slack.com/t/tsparticles/shared_invite/enQtOTcxNTQxNjQ4NzkxLWE2MTZhZWExMWRmOWI5MTMxNjczOGE1Yjk0MjViYjdkYTUzODM3OTc5MGQ5MjFlODc4MzE0N2Q1OWQxZDc1YzI) [](https://discord.gg/hACwv45Hme) [](https://t.me/tsparticles)
|
|
11
|
+
|
|
12
|
+
[](https://www.producthunt.com/posts/tsparticles?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-tsparticles") <a href="https://www.buymeacoffee.com/matteobruni"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a beer&emoji=🍺&slug=matteobruni&button_colour=5F7FFF&font_colour=ffffff&font_family=Arial&outline_colour=000000&coffee_colour=FFDD00"></a>
|
|
13
|
+
|
|
14
|
+
## Sample
|
|
15
|
+
|
|
16
|
+
[](https://particles.js.org/samples/presets/confetti)
|
|
17
|
+
|
|
18
|
+
## How to use it
|
|
19
|
+
|
|
20
|
+
### CDN / Vanilla JS / jQuery
|
|
21
|
+
|
|
22
|
+
The first step is installing [tsParticles](https://github.com/matteobruni/tsparticles) following the instructions for
|
|
23
|
+
vanilla javascript in the main project [here](https://github.com/matteobruni/tsparticles)
|
|
24
|
+
|
|
25
|
+
Once added the script you need one more script to be included in your page (or you can download that
|
|
26
|
+
from [jsDelivr](https://www.jsdelivr.com/package/npm/@tsparticles/preset-confetti):
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
<script src="https://cdn.jsdelivr.net/npm/tsparticles-engine@2/tsparticles.engine.min.js"></script>
|
|
30
|
+
<script src="https://cdn.jsdelivr.net/npm/tsparticles-move-base@2/tsparticles.move.base.min.js"></script>
|
|
31
|
+
<script src="https://cdn.jsdelivr.net/npm/tsparticles-plugin-emitters@2/tsparticles.plugin.emitters.min.js"></script>
|
|
32
|
+
<script src="https://cdn.jsdelivr.net/npm/tsparticles-shape-circle@2/tsparticles.shape.circle.min.js"></script>
|
|
33
|
+
<script src="https://cdn.jsdelivr.net/npm/tsparticles-shape-square@2/tsparticles.shape.square.min.js"></script>
|
|
34
|
+
<script src="https://cdn.jsdelivr.net/npm/tsparticles-updater-angle@2/tsparticles.updater.angle.min.js"></script>
|
|
35
|
+
<script src="https://cdn.jsdelivr.net/npm/tsparticles-updater-color@2/tsparticles.updater.color.min.js"></script>
|
|
36
|
+
<script src="https://cdn.jsdelivr.net/npm/tsparticles-updater-life@2/tsparticles.updater.life.min.js"></script>
|
|
37
|
+
<script src="https://cdn.jsdelivr.net/npm/tsparticles-updater-opacity@2/tsparticles.updater.opacity.min.js"></script>
|
|
38
|
+
<script src="https://cdn.jsdelivr.net/npm/tsparticles-updater-out-modes@2/tsparticles.updater.out-modes.min.js"></script>
|
|
39
|
+
<script src="https://cdn.jsdelivr.net/npm/tsparticles-updater-roll@2/tsparticles.updater.roll.min.js"></script>
|
|
40
|
+
<script src="https://cdn.jsdelivr.net/npm/tsparticles-updater-size@2/tsparticles.updater.size.min.js"></script>
|
|
41
|
+
<script src="https://cdn.jsdelivr.net/npm/tsparticles-updater-tilt@2/tsparticles.updater.tilt.min.js"></script>
|
|
42
|
+
<script src="https://cdn.jsdelivr.net/npm/tsparticles-updater-wobble@2/tsparticles.updater.wobble.min.js"></script>
|
|
43
|
+
<script src="https://cdn.jsdelivr.net/npm/@tsparticles/preset-confetti@2/tsparticles.preset.confetti.min.js"></script>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
#### Bundle
|
|
47
|
+
|
|
48
|
+
A bundled script can also be used, this will include every needed plugin needed by the preset.
|
|
49
|
+
|
|
50
|
+
```html
|
|
51
|
+
<script src="https://cdn.jsdelivr.net/npm/@tsparticles/preset-confetti@2/tsparticles.preset.confetti.bundle.min.js"></script>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Usage
|
|
55
|
+
|
|
56
|
+
Once the scripts are loaded you can set up `tsParticles` like this:
|
|
57
|
+
|
|
58
|
+
```javascript
|
|
59
|
+
(async () => {
|
|
60
|
+
await loadConfettiPreset(tsParticles); // this is required only if you are not using the bundle script
|
|
61
|
+
|
|
62
|
+
await tsParticles.load("tsparticles", {
|
|
63
|
+
preset: "confetti",
|
|
64
|
+
});
|
|
65
|
+
})();
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Customization
|
|
69
|
+
|
|
70
|
+
```javascript
|
|
71
|
+
tsParticles.load("tsparticles", {
|
|
72
|
+
particles: {
|
|
73
|
+
color: {
|
|
74
|
+
value: ["#0000ff", "#00ff00"],
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
preset: "confetti",
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Like in the sample above, the white and red colors will be replaced by blue and lime.
|
|
82
|
+
|
|
83
|
+
#### Cannons
|
|
84
|
+
|
|
85
|
+
The preset has a single life cannon, with a short duration. The effect is immediate and ends few seconds after, but this
|
|
86
|
+
can be customized too.
|
|
87
|
+
|
|
88
|
+
The confetti cannons are made using the _Emitter_ plugin, which is already
|
|
89
|
+
documented [here](https://particles.js.org/docs/classes/Plugins_Emitters_Options_Classes_Emitter.Emitter.html).
|
|
90
|
+
|
|
91
|
+
These are the default cannon (emitter) options:
|
|
92
|
+
|
|
93
|
+
The default emitter options are these:
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"startCount": 50,
|
|
98
|
+
"position": {
|
|
99
|
+
"x": 50,
|
|
100
|
+
"y": 50
|
|
101
|
+
},
|
|
102
|
+
"size": {
|
|
103
|
+
"width": 0,
|
|
104
|
+
"height": 0
|
|
105
|
+
},
|
|
106
|
+
"rate": {
|
|
107
|
+
"delay": 0,
|
|
108
|
+
"quantity": 0
|
|
109
|
+
},
|
|
110
|
+
"life": {
|
|
111
|
+
"duration": 0.1,
|
|
112
|
+
"count": 1
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Let's see how to create the most common types of cannon animations:
|
|
118
|
+
|
|
119
|
+
##### Long lasting Cannon
|
|
120
|
+
|
|
121
|
+
To create a long-lasting cannon, the emitter life options need some changes.
|
|
122
|
+
|
|
123
|
+
The `life.duration` needs to be increased, the value is in `seconds`, so actually it lasts one tenth of a second.
|
|
124
|
+
|
|
125
|
+
If `life.duration` is set to `0`, the cannon will last forever.
|
|
126
|
+
|
|
127
|
+
The `life.count` parameter instead can be changed as well, but the animation will last for the specified
|
|
128
|
+
duration, `life.count` times, if the `life.duration` is set to `0`, the `life.count` is ignored since its first life
|
|
129
|
+
will last forever.
|
|
130
|
+
|
|
131
|
+
###### Sample
|
|
132
|
+
|
|
133
|
+
```javascript
|
|
134
|
+
tsParticles.load("tsparticles", {
|
|
135
|
+
emitters: {
|
|
136
|
+
life: {
|
|
137
|
+
duration: 0,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
preset: "confetti",
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
This will create an infinite cannon shooting confetti from the center of the canvas.
|
|
145
|
+
|
|
146
|
+
##### Immortal Cannon - Fireworks
|
|
147
|
+
|
|
148
|
+
To create a fireworks effect, or an immortal cannon, the emitter life options, again, need some changes.
|
|
149
|
+
|
|
150
|
+
The `life.duration` can be kept to the default short value, but the `life.count` is what we need to change.
|
|
151
|
+
|
|
152
|
+
For an immortal cannon we can change `life.count` to `0` and the emitter will continue respawning every `life.delay`
|
|
153
|
+
seconds. Actually is not specified, if you want some delay between "explosions", set this value to something greater
|
|
154
|
+
than `0`.
|
|
155
|
+
|
|
156
|
+
For an improved effect, the `position` as well can be customized. For randomizing it, it can be set to `{}`, and it'll
|
|
157
|
+
have a random position every "explosion". If a coordinate is set, that will be used everytime, as a percentage of the
|
|
158
|
+
canvas size.
|
|
159
|
+
|
|
160
|
+
```javascript
|
|
161
|
+
tsParticles.load("tsparticles", {
|
|
162
|
+
emitters: {
|
|
163
|
+
life: {
|
|
164
|
+
count: 0,
|
|
165
|
+
},
|
|
166
|
+
position: {
|
|
167
|
+
// uncomment only one of these lines,
|
|
168
|
+
// to have explosions on the x or y axis
|
|
169
|
+
// centered on the other one
|
|
170
|
+
// if everything is kept commented,
|
|
171
|
+
// random positions will be used everytime the cannon fires
|
|
172
|
+
// x: 50,
|
|
173
|
+
// y: 50
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
preset: "confetti",
|
|
177
|
+
});
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
###### Multiple Cannons
|
|
181
|
+
|
|
182
|
+
Now that we have played with a single cannon, what about multiple ones?
|
|
183
|
+
|
|
184
|
+
This needs more customization since the cannons array will overwrite the existing options.
|
|
185
|
+
|
|
186
|
+
First let's start overriding the emitters (cannons) options placing an array instead of an object.
|
|
187
|
+
|
|
188
|
+
Like this:
|
|
189
|
+
|
|
190
|
+
```javascript
|
|
191
|
+
tsParticles.load("tsparticles", {
|
|
192
|
+
emitters: [],
|
|
193
|
+
preset: "confetti",
|
|
194
|
+
});
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
If you test this, you won't see anything, because the emitters are set to an empty array, so there's nothing to show.
|
|
198
|
+
|
|
199
|
+
Now you can add emitters to the array, using the standard tsParticles emitters options.
|
|
200
|
+
|
|
201
|
+
###### Sample
|
|
202
|
+
|
|
203
|
+
```javascript
|
|
204
|
+
tsParticles.load("tsparticles", {
|
|
205
|
+
emitters: [
|
|
206
|
+
{
|
|
207
|
+
life: {
|
|
208
|
+
duration: 5,
|
|
209
|
+
count: 1,
|
|
210
|
+
},
|
|
211
|
+
position: {
|
|
212
|
+
x: 0,
|
|
213
|
+
y: 30,
|
|
214
|
+
},
|
|
215
|
+
particles: {
|
|
216
|
+
move: {
|
|
217
|
+
direction: "top-right",
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
life: {
|
|
223
|
+
duration: 5,
|
|
224
|
+
count: 1,
|
|
225
|
+
},
|
|
226
|
+
position: {
|
|
227
|
+
x: 100,
|
|
228
|
+
y: 30,
|
|
229
|
+
},
|
|
230
|
+
particles: {
|
|
231
|
+
move: {
|
|
232
|
+
direction: "top-left",
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
preset: "confetti",
|
|
238
|
+
});
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
This samples creates two cannons, one on the left and one on the right of the canvas, at 30% of canvas height, shooting
|
|
242
|
+
in opposite directions.
|
|
243
|
+
|
|
244
|
+
### React.js / Preact / Inferno
|
|
245
|
+
|
|
246
|
+
_The syntax for `React.js`, `Preact` and `Inferno` is the same_.
|
|
247
|
+
|
|
248
|
+
This sample uses the class component syntax, but you can use hooks as well (if the library supports it).
|
|
249
|
+
|
|
250
|
+
```typescript jsx
|
|
251
|
+
import Particles from "react-particles";
|
|
252
|
+
import type { Engine } from "tsparticles-engine";
|
|
253
|
+
import { loadConfettiPreset } from "@tsparticles/preset-confetti";
|
|
254
|
+
|
|
255
|
+
export class ParticlesContainer extends React.PureComponent<IProps> {
|
|
256
|
+
// this customizes the component tsParticles installation
|
|
257
|
+
async customInit(engine: Engine): Promise<void> {
|
|
258
|
+
// this adds the preset to tsParticles, you can safely use the
|
|
259
|
+
await loadConfettiPreset(engine);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
render() {
|
|
263
|
+
const options = {
|
|
264
|
+
preset: "confetti",
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
return <Particles options={options} init={this.customInit} />;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Vue (2.x and 3.x)
|
|
273
|
+
|
|
274
|
+
_The syntax for `Vue.js 2.x` and `3.x` is the same_
|
|
275
|
+
|
|
276
|
+
```vue
|
|
277
|
+
<Particles id="tsparticles" :particlesInit="particlesInit" :options="particlesOptions" />
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
```ts
|
|
281
|
+
const particlesOptions = {
|
|
282
|
+
preset: "confetti",
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
async function particlesInit(engine: Engine): Promise<void> {
|
|
286
|
+
await loadConfettiPreset(engine);
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### Angular
|
|
291
|
+
|
|
292
|
+
```html
|
|
293
|
+
<angular-particles [id]="id" [options]="particlesOptions" [particlesInit]="particlesInit"></angular-particles>
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
```ts
|
|
297
|
+
const particlesOptions = {
|
|
298
|
+
preset: "confetti",
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
async function particlesInit(engine: Engine): Promise<void> {
|
|
302
|
+
await loadConfettiPreset(engine);
|
|
303
|
+
}
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### Svelte
|
|
307
|
+
|
|
308
|
+
```sveltehtml
|
|
309
|
+
|
|
310
|
+
<Particles
|
|
311
|
+
id="tsparticles"
|
|
312
|
+
options={options}
|
|
313
|
+
particlesInit={particlesInit}
|
|
314
|
+
/>
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
```js
|
|
318
|
+
let particlesOptions = {
|
|
319
|
+
preset: "confetti",
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
let particlesInit = async (engine) => {
|
|
323
|
+
await loadConfettiPreset(engine);
|
|
324
|
+
};
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### Alternative Usage
|
|
328
|
+
|
|
329
|
+
This module exports another method for using the confetti preset
|
|
330
|
+
|
|
331
|
+
```javascript
|
|
332
|
+
confetti("tsparticles", {
|
|
333
|
+
/**
|
|
334
|
+
* @deprecated use count property instead
|
|
335
|
+
*/
|
|
336
|
+
particleCount: 50,
|
|
337
|
+
/**
|
|
338
|
+
* @deprecated use position property instead
|
|
339
|
+
*/
|
|
340
|
+
origin: {
|
|
341
|
+
x: 50,
|
|
342
|
+
y: 50,
|
|
343
|
+
},
|
|
344
|
+
//------------------------------------------
|
|
345
|
+
angle: 90,
|
|
346
|
+
count: 50,
|
|
347
|
+
position: {
|
|
348
|
+
x: 50,
|
|
349
|
+
y: 50,
|
|
350
|
+
},
|
|
351
|
+
spread: 45,
|
|
352
|
+
startVelocity: 45,
|
|
353
|
+
decay: 0.9,
|
|
354
|
+
gravity: 1,
|
|
355
|
+
drift: 0,
|
|
356
|
+
ticks: 200,
|
|
357
|
+
colors: ["#ffffff", "#ff0000"],
|
|
358
|
+
shapes: ["square", "circle"],
|
|
359
|
+
scalar: 1,
|
|
360
|
+
zIndex: 100,
|
|
361
|
+
disableForReducedMotion: true,
|
|
362
|
+
});
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
This method doesn't need to call the `loadConfettiPreset` method since it's called automatically.
|
|
366
|
+
|
|
367
|
+
#### Customization
|
|
368
|
+
|
|
369
|
+
**Important ⚠️**
|
|
370
|
+
You can override all the options defining the properties like in any standard `tsParticles` installation. This works
|
|
371
|
+
only with the classic `loadConfettiPreset` method, the `confetti` function has its own parameters.
|
|
372
|
+
|
|
373
|
+
#### Options
|
|
374
|
+
|
|
375
|
+
The `confetti` first parameter is the `tsParticles` container id and the second parameter is a single `options` object,
|
|
376
|
+
which has the following properties:
|
|
377
|
+
|
|
378
|
+
- `count` _Integer (default: 50)_: The number of confetti to launch. More is always fun... but be cool, there's a lot of
|
|
379
|
+
math involved. (`particleCount` can be used too, but it's deprecated)
|
|
380
|
+
- `angle` _Number (default: 90)_: The angle in which to launch the confetti, in degrees: 90 is straight up.
|
|
381
|
+
- `spread` _Number (default: 45)_: How far off center the confetti can go, in degrees. 45 means the confetti will launch
|
|
382
|
+
at the defined `angle` plus or minus 22.5 degrees.
|
|
383
|
+
- `startVelocity` _Number (default: 45)_: How fast the confetti will start going, in pixels.
|
|
384
|
+
- `decay` _Number (default: 0.9)_: How quickly the confetti will lose speed. Keep this number between 0 and 1, otherwise
|
|
385
|
+
the confetti will gain speed. Better yet, just never change it.
|
|
386
|
+
- `gravity` _Number (default: 1)_: How quickly the particles are pulled down: 1 is full gravity, 0.5 is half gravity,
|
|
387
|
+
etc., but there are no limits. You can even make particles go up if you'd like.
|
|
388
|
+
- `drift` _Number (default: 0)_: How much to the side the confetti will drift. The default is 0, meaning that they will
|
|
389
|
+
fall straight down. Use a negative number for left and positive number for right.
|
|
390
|
+
- `ticks` _Number (default: 200)_: How many times the confetti will move. This is abstract... but play with it if the
|
|
391
|
+
confetti disappear too quickly for you.
|
|
392
|
+
- `position` _Object_: Where to start firing confetti from. Feel free to launch off-screen if you'd like. (`origin` can
|
|
393
|
+
be used too, but it's deprecated)
|
|
394
|
+
- `position.x` _Number (default: 0.5)_: The `x` position on the page, with `0` being the left edge and `1` being the
|
|
395
|
+
right edge.
|
|
396
|
+
- `position.y` _Number (default: 0.5)_: The `y` position on the page, with `0` being the top edge and `1` being the
|
|
397
|
+
bottom edge.
|
|
398
|
+
- `colors` _Array<String>_: An array of color strings, in the HEX format... you know, like `#bada55`.
|
|
399
|
+
- `shapes` _Array<String>_: An array of shapes for the confetti. The possible values are `square` and `circle`.
|
|
400
|
+
The default is to use both shapes in an even mix. You can even change the mix by providing a value such
|
|
401
|
+
as `['circle', 'circle', 'square']` to use two third circles and one third squares.
|
|
402
|
+
- `scalar` _Number (default: 1)_: Scale factor for each confetti particle. Use decimals to make the confetti smaller. Go
|
|
403
|
+
on, try teeny tiny confetti, they are adorable!
|
|
404
|
+
- `zIndex` _Integer (default: 100)_: The confetti should be on top, after all. But if you have a crazy high page, you
|
|
405
|
+
can set it even higher.
|
|
406
|
+
- `disableForReducedMotion` _Boolean (default: true)_: Disables confetti entirely for users
|
|
407
|
+
that [prefer reduced motion](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion).
|
|
408
|
+
|
|
409
|
+
---
|
|
410
|
+
|
|
411
|
+
```mermaid
|
|
412
|
+
flowchart TD
|
|
413
|
+
|
|
414
|
+
subgraph m [Movers]
|
|
415
|
+
mb[Base]
|
|
416
|
+
end
|
|
417
|
+
|
|
418
|
+
e[tsParticles Engine] --> m
|
|
419
|
+
|
|
420
|
+
subgraph pl [Plugins]
|
|
421
|
+
ple[Emitters]
|
|
422
|
+
plm[Motion]
|
|
423
|
+
end
|
|
424
|
+
|
|
425
|
+
e --> pl
|
|
426
|
+
|
|
427
|
+
subgraph s [Shapes]
|
|
428
|
+
sc[Circle]
|
|
429
|
+
ssq[Square]
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
e --> s
|
|
433
|
+
|
|
434
|
+
subgraph u [Updaters]
|
|
435
|
+
ua[Angle]
|
|
436
|
+
uc[Color]
|
|
437
|
+
ul[Life]
|
|
438
|
+
uop[Opacity]
|
|
439
|
+
uou[Out Modes]
|
|
440
|
+
ur[Roll]
|
|
441
|
+
usi[Size]
|
|
442
|
+
uti[Tilt]
|
|
443
|
+
uw[Wobble]
|
|
444
|
+
end
|
|
445
|
+
|
|
446
|
+
e --> u
|
|
447
|
+
|
|
448
|
+
subgraph pr [Presets]
|
|
449
|
+
prc[Confetti]
|
|
450
|
+
end
|
|
451
|
+
|
|
452
|
+
mb & ple & plm & sc & ssq & ua & uc & ul & uop & uou & ur & usi & uti & uw --> prc
|
|
453
|
+
```
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
export class ConfettiOptions {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.angle = 90;
|
|
4
|
+
this.count = 50;
|
|
5
|
+
this.spread = 45;
|
|
6
|
+
this.startVelocity = 45;
|
|
7
|
+
this.decay = 0.9;
|
|
8
|
+
this.gravity = 1;
|
|
9
|
+
this.drift = 0;
|
|
10
|
+
this.ticks = 200;
|
|
11
|
+
this.position = {
|
|
12
|
+
x: 50,
|
|
13
|
+
y: 50,
|
|
14
|
+
};
|
|
15
|
+
this.colors = ["#ffffff", "#ff0000"];
|
|
16
|
+
this.shapes = ["square", "circle"];
|
|
17
|
+
this.scalar = 1;
|
|
18
|
+
this.zIndex = 100;
|
|
19
|
+
this.disableForReducedMotion = true;
|
|
20
|
+
}
|
|
21
|
+
get origin() {
|
|
22
|
+
return {
|
|
23
|
+
x: this.position.x / 100,
|
|
24
|
+
y: this.position.y / 100,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
set origin(value) {
|
|
28
|
+
this.position.x = value.x * 100;
|
|
29
|
+
this.position.y = value.y * 100;
|
|
30
|
+
}
|
|
31
|
+
get particleCount() {
|
|
32
|
+
return this.count;
|
|
33
|
+
}
|
|
34
|
+
set particleCount(value) {
|
|
35
|
+
this.count = value;
|
|
36
|
+
}
|
|
37
|
+
load(data) {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
if (!data) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (data.angle !== undefined) {
|
|
43
|
+
this.angle = data.angle;
|
|
44
|
+
}
|
|
45
|
+
const count = (_a = data.count) !== null && _a !== void 0 ? _a : data.particleCount;
|
|
46
|
+
if (count !== undefined) {
|
|
47
|
+
this.count = count;
|
|
48
|
+
}
|
|
49
|
+
if (data.spread !== undefined) {
|
|
50
|
+
this.spread = data.spread;
|
|
51
|
+
}
|
|
52
|
+
if (data.startVelocity !== undefined) {
|
|
53
|
+
this.startVelocity = data.startVelocity;
|
|
54
|
+
}
|
|
55
|
+
if (data.decay !== undefined) {
|
|
56
|
+
this.decay = data.decay;
|
|
57
|
+
}
|
|
58
|
+
if (data.gravity !== undefined) {
|
|
59
|
+
this.gravity = data.gravity;
|
|
60
|
+
}
|
|
61
|
+
if (data.drift !== undefined) {
|
|
62
|
+
this.drift = data.drift;
|
|
63
|
+
}
|
|
64
|
+
if (data.ticks !== undefined) {
|
|
65
|
+
this.ticks = data.ticks;
|
|
66
|
+
}
|
|
67
|
+
const position = (_b = data.position) !== null && _b !== void 0 ? _b : this.position;
|
|
68
|
+
if ((position === null || position === void 0 ? void 0 : position.x) !== undefined) {
|
|
69
|
+
this.position.x = position.x;
|
|
70
|
+
}
|
|
71
|
+
if ((position === null || position === void 0 ? void 0 : position.y) !== undefined) {
|
|
72
|
+
this.position.y = position.y;
|
|
73
|
+
}
|
|
74
|
+
if (data.colors !== undefined) {
|
|
75
|
+
if (data.colors instanceof Array) {
|
|
76
|
+
this.colors = [...data.colors];
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
this.colors = data.colors;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (data.shapes !== undefined) {
|
|
83
|
+
if (data.shapes instanceof Array) {
|
|
84
|
+
this.shapes = [...data.shapes];
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
this.shapes = data.shapes;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (data.scalar !== undefined) {
|
|
91
|
+
this.scalar = data.scalar;
|
|
92
|
+
}
|
|
93
|
+
if (data.zIndex !== undefined) {
|
|
94
|
+
this.zIndex = data.zIndex;
|
|
95
|
+
}
|
|
96
|
+
if (data.disableForReducedMotion !== undefined) {
|
|
97
|
+
this.disableForReducedMotion = data.disableForReducedMotion;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/browser/index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { getRandom, tsParticles } from "@tsparticles/engine";
|
|
2
|
+
import { loadAngleUpdater } from "@tsparticles/updater-angle";
|
|
3
|
+
import { loadBaseMover } from "@tsparticles/move-base";
|
|
4
|
+
import { loadCircleShape } from "@tsparticles/shape-circle";
|
|
5
|
+
import { loadColorUpdater } from "@tsparticles/updater-color";
|
|
6
|
+
import { loadEmittersPlugin } from "@tsparticles/plugin-emitters";
|
|
7
|
+
import { loadLifeUpdater } from "@tsparticles/updater-life";
|
|
8
|
+
import { loadMotionPlugin } from "@tsparticles/plugin-motion";
|
|
9
|
+
import { loadOpacityUpdater } from "@tsparticles/updater-opacity";
|
|
10
|
+
import { loadOptions } from "./options";
|
|
11
|
+
import { loadOutModesUpdater } from "@tsparticles/updater-out-modes";
|
|
12
|
+
import { loadRollUpdater } from "@tsparticles/updater-roll";
|
|
13
|
+
import { loadSizeUpdater } from "@tsparticles/updater-size";
|
|
14
|
+
import { loadSquareShape } from "@tsparticles/shape-square";
|
|
15
|
+
import { loadTiltUpdater } from "@tsparticles/updater-tilt";
|
|
16
|
+
import { loadWobbleUpdater } from "@tsparticles/updater-wobble";
|
|
17
|
+
async function loadPreset(engine, confettiOptions, override = false) {
|
|
18
|
+
await loadBaseMover(engine);
|
|
19
|
+
await loadCircleShape(engine);
|
|
20
|
+
await loadSquareShape(engine);
|
|
21
|
+
await loadColorUpdater(engine);
|
|
22
|
+
await loadSizeUpdater(engine);
|
|
23
|
+
await loadOpacityUpdater(engine);
|
|
24
|
+
await loadOutModesUpdater(engine);
|
|
25
|
+
await loadEmittersPlugin(engine);
|
|
26
|
+
await loadMotionPlugin(engine);
|
|
27
|
+
await loadWobbleUpdater(engine);
|
|
28
|
+
await loadRollUpdater(engine);
|
|
29
|
+
await loadAngleUpdater(engine);
|
|
30
|
+
await loadTiltUpdater(engine);
|
|
31
|
+
await loadLifeUpdater(engine);
|
|
32
|
+
await engine.addPreset("confetti", loadOptions(confettiOptions), override);
|
|
33
|
+
}
|
|
34
|
+
export async function loadConfettiPreset(main) {
|
|
35
|
+
await loadPreset(main, {}, true);
|
|
36
|
+
}
|
|
37
|
+
export async function confetti(idOrOptions, confettiOptions) {
|
|
38
|
+
let options;
|
|
39
|
+
let id;
|
|
40
|
+
if (typeof idOrOptions === "string") {
|
|
41
|
+
id = idOrOptions;
|
|
42
|
+
options = confettiOptions !== null && confettiOptions !== void 0 ? confettiOptions : {};
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
id = `tsparticles_${Math.floor(getRandom() * 1000)}`;
|
|
46
|
+
options = idOrOptions;
|
|
47
|
+
}
|
|
48
|
+
await loadPreset(tsParticles, options, true);
|
|
49
|
+
await tsParticles.load({
|
|
50
|
+
id,
|
|
51
|
+
options: {
|
|
52
|
+
preset: "confetti",
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|