@tsparticles/confetti 3.0.0-beta.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 +158 -0
- package/browser/ConfettiOptions.js +119 -0
- package/browser/IConfettiOptions.js +1 -0
- package/browser/bundle.js +2 -0
- package/browser/confetti.js +300 -0
- package/browser/index.js +1 -0
- package/cjs/ConfettiOptions.js +123 -0
- package/cjs/IConfettiOptions.js +2 -0
- package/cjs/bundle.js +18 -0
- package/cjs/confetti.js +304 -0
- package/cjs/index.js +17 -0
- package/esm/ConfettiOptions.js +119 -0
- package/esm/IConfettiOptions.js +1 -0
- package/esm/bundle.js +2 -0
- package/esm/confetti.js +300 -0
- package/esm/index.js +1 -0
- package/package.json +110 -0
- package/report.html +39 -0
- package/tsparticles.confetti.bundle.js +9605 -0
- package/tsparticles.confetti.bundle.min.js +2 -0
- package/tsparticles.confetti.bundle.min.js.LICENSE.txt +1 -0
- package/tsparticles.confetti.js +874 -0
- package/tsparticles.confetti.min.js +2 -0
- package/tsparticles.confetti.min.js.LICENSE.txt +1 -0
- package/types/ConfettiOptions.d.ts +25 -0
- package/types/IConfettiOptions.d.ts +20 -0
- package/types/bundle.d.ts +2 -0
- package/types/confetti.d.ts +18 -0
- package/types/index.d.ts +4 -0
- package/umd/ConfettiOptions.js +133 -0
- package/umd/IConfettiOptions.js +12 -0
- package/umd/bundle.js +28 -0
- package/umd/confetti.js +314 -0
- package/umd/index.js +27 -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,158 @@
|
|
|
1
|
+
[](https://particles.js.org)
|
|
2
|
+
|
|
3
|
+
# tsParticles Confetti Bundle
|
|
4
|
+
|
|
5
|
+
[](https://www.jsdelivr.com/package/npm/@tsparticles/confetti) [](https://www.npmjs.com/package/@tsparticles/confetti) [](https://www.npmjs.com/package/@tsparticles/confetti) [](https://github.com/sponsors/matteobruni)
|
|
6
|
+
|
|
7
|
+
[tsParticles](https://github.com/matteobruni/tsparticles) confetti bundle loads all the features necessary to create beautiful confetti effects with ease.
|
|
8
|
+
|
|
9
|
+
**Included Packages**
|
|
10
|
+
|
|
11
|
+
- [@tsparticles/engine](https://github.com/matteobruni/tsparticles/tree/main/engine)
|
|
12
|
+
- [@tsparticles/move-base](https://github.com/matteobruni/tsparticles/tree/main/move/base)
|
|
13
|
+
- [@tsparticles/plugin-emitters](https://github.com/matteobruni/tsparticles/tree/main/plugins/emitters)
|
|
14
|
+
- [@tsparticles/plugin-motion](https://github.com/matteobruni/tsparticles/tree/main/plugins/motion)
|
|
15
|
+
- [@tsparticles/shape-cards](https://github.com/matteobruni/tsparticles/tree/main/shapes/cards)
|
|
16
|
+
- [@tsparticles/shape-circle](https://github.com/matteobruni/tsparticles/tree/main/shapes/circle)
|
|
17
|
+
- [@tsparticles/shape-heart](https://github.com/matteobruni/tsparticles/tree/main/shapes/heart)
|
|
18
|
+
- [@tsparticles/shape-image](https://github.com/matteobruni/tsparticles/tree/main/shapes/image)
|
|
19
|
+
- [@tsparticles/shape-polygon](https://github.com/matteobruni/tsparticles/tree/main/shapes/polygon)
|
|
20
|
+
- [@tsparticles/shape-square](https://github.com/matteobruni/tsparticles/tree/main/shapes/square)
|
|
21
|
+
- [@tsparticles/shape-star](https://github.com/matteobruni/tsparticles/tree/main/shapes/star)
|
|
22
|
+
- [@tsparticles/shape-text](https://github.com/matteobruni/tsparticles/tree/main/shapes/text)
|
|
23
|
+
- [@tsparticles/updater-color](https://github.com/matteobruni/tsparticles/tree/main/updaters/color)
|
|
24
|
+
- [@tsparticles/updater-life](https://github.com/matteobruni/tsparticles/tree/main/updaters/life)
|
|
25
|
+
- [@tsparticles/updater-opacity](https://github.com/matteobruni/tsparticles/tree/main/updaters/opacity)
|
|
26
|
+
- [@tsparticles/updater-out-modes](https://github.com/matteobruni/tsparticles/tree/main/updaters/outModes)
|
|
27
|
+
- [@tsparticles/updater-roll](https://github.com/matteobruni/tsparticles/tree/main/updaters/roll)
|
|
28
|
+
- [@tsparticles/updater-rotate](https://github.com/matteobruni/tsparticles/tree/main/updaters/rotate)
|
|
29
|
+
- [@tsparticles/updater-size](https://github.com/matteobruni/tsparticles/tree/main/updaters/size)
|
|
30
|
+
- [@tsparticles/updater-tilt](https://github.com/matteobruni/tsparticles/tree/main/updaters/tilt)
|
|
31
|
+
- [@tsparticles/updater-wobble](https://github.com/matteobruni/tsparticles/tree/main/updaters/wobble)
|
|
32
|
+
|
|
33
|
+
## How to use it
|
|
34
|
+
|
|
35
|
+
### CDN / Vanilla JS / jQuery
|
|
36
|
+
|
|
37
|
+
The CDN/Vanilla version JS has two different files:
|
|
38
|
+
|
|
39
|
+
- One is a bundle file with all the scripts included in a single file
|
|
40
|
+
- One is a file including just the `confetti` function to load the tsParticles confetti bunddle, all dependencies must be
|
|
41
|
+
included manually
|
|
42
|
+
|
|
43
|
+
#### Bundle
|
|
44
|
+
|
|
45
|
+
Including the `tsparticles.confetti.bundle.min.js` file will out of the box.
|
|
46
|
+
|
|
47
|
+
This is the easiest usage, since it's a single file with all the features loaded.
|
|
48
|
+
|
|
49
|
+
You can still add additional packages, loading them like all the other packages.
|
|
50
|
+
|
|
51
|
+
#### Not Bundle
|
|
52
|
+
|
|
53
|
+
This installation requires more work since all dependencies must be included in the page. Some lines above are all
|
|
54
|
+
specified in the **Included Packages** section.
|
|
55
|
+
|
|
56
|
+
### Usage
|
|
57
|
+
|
|
58
|
+
Once the scripts are loaded you can set up `tsParticles` like the following examples:
|
|
59
|
+
|
|
60
|
+
````javascript
|
|
61
|
+
|
|
62
|
+
** Easiest Way **
|
|
63
|
+
|
|
64
|
+
```javascript
|
|
65
|
+
confetti()
|
|
66
|
+
````
|
|
67
|
+
|
|
68
|
+
** Async Way, best practice **
|
|
69
|
+
|
|
70
|
+
```javascript
|
|
71
|
+
(async () => {
|
|
72
|
+
await confetti();
|
|
73
|
+
})();
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
** Confetti Options **
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
confetti("tsparticles", {
|
|
80
|
+
/**
|
|
81
|
+
* @deprecated use count property instead
|
|
82
|
+
*/
|
|
83
|
+
particleCount: 50,
|
|
84
|
+
/**
|
|
85
|
+
* @deprecated use position property instead
|
|
86
|
+
*/
|
|
87
|
+
origin: {
|
|
88
|
+
x: 0.5,
|
|
89
|
+
y: 0.5,
|
|
90
|
+
},
|
|
91
|
+
//------------------------------------------
|
|
92
|
+
angle: 90,
|
|
93
|
+
count: 50,
|
|
94
|
+
position: {
|
|
95
|
+
x: 50,
|
|
96
|
+
y: 50,
|
|
97
|
+
},
|
|
98
|
+
spread: 45,
|
|
99
|
+
startVelocity: 45,
|
|
100
|
+
decay: 0.9,
|
|
101
|
+
gravity: 1,
|
|
102
|
+
drift: 0,
|
|
103
|
+
ticks: 200,
|
|
104
|
+
colors: ["#ffffff", "#ff0000"],
|
|
105
|
+
shapes: ["square", "circle"],
|
|
106
|
+
scalar: 1,
|
|
107
|
+
zIndex: 100,
|
|
108
|
+
disableForReducedMotion: true,
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
#### Options
|
|
113
|
+
|
|
114
|
+
The `confetti` first parameter can be an id and the second parameter a single `options` object, or just the single options object without the id, which will be `confetti` by default. The `options` object has the following properties:
|
|
115
|
+
|
|
116
|
+
- `count` _Integer (default: 50)_: The number of confetti to launch. More is always fun... but be cool, there's a lot of
|
|
117
|
+
math involved. (`particleCount` can be used too, but it's deprecated)
|
|
118
|
+
- `angle` _Number (default: 90)_: The angle in which to launch the confetti, in degrees: 90 is straight up.
|
|
119
|
+
- `spread` _Number (default: 45)_: How far off center the confetti can go, in degrees. 45 means the confetti will launch
|
|
120
|
+
at the defined `angle` plus or minus 22.5 degrees.
|
|
121
|
+
- `startVelocity` _Number (default: 45)_: How fast the confetti will start going, in pixels.
|
|
122
|
+
- `decay` _Number (default: 0.9)_: How quickly the confetti will lose speed. Keep this number between 0 and 1, otherwise
|
|
123
|
+
the confetti will gain speed. Better yet, just never change it.
|
|
124
|
+
- `gravity` _Number (default: 1)_: How quickly the particles are pulled down: 1 is full gravity, 0.5 is half gravity,
|
|
125
|
+
etc., but there are no limits. You can even make particles go up if you'd like.
|
|
126
|
+
- `drift` _Number (default: 0)_: How much to the side the confetti will drift. The default is 0, meaning that they will
|
|
127
|
+
fall straight down. Use a negative number for left and positive number for right.
|
|
128
|
+
- `ticks` _Number (default: 200)_: How many times the confetti will move. This is abstract... but play with it if the
|
|
129
|
+
confetti disappear too quickly for you.
|
|
130
|
+
- `position` _Object_: Where to start firing confetti from. Feel free to launch off-screen if you'd like. (`origin` can
|
|
131
|
+
be used too, but it's deprecated)
|
|
132
|
+
- `position.x` _Number (default: 50)_: The `x` position on the page, with `0` being the left edge and `100` being the
|
|
133
|
+
right edge.
|
|
134
|
+
- `position.y` _Number (default: 50)_: The `y` position on the page, with `0` being the top edge and `100` being the
|
|
135
|
+
bottom edge.
|
|
136
|
+
- `colors` _Array<String>_: An array of color strings, in the HEX format... you know, like `#bada55`.
|
|
137
|
+
- `shapes` _Array<String>_: An array of shapes for the confetti. The possible values are:
|
|
138
|
+
- `circle`
|
|
139
|
+
- `square`
|
|
140
|
+
- `star`
|
|
141
|
+
- `polygon`
|
|
142
|
+
- `image`
|
|
143
|
+
- `heart`
|
|
144
|
+
- `hearts`
|
|
145
|
+
- `spades`
|
|
146
|
+
- `clubs`
|
|
147
|
+
- `diamonds`
|
|
148
|
+
- `text`
|
|
149
|
+
The default is to use both shapes in an even mix. You can even change the mix by providing a value such
|
|
150
|
+
as `['circle', 'circle', 'square']` to use two third circles and one third squares.
|
|
151
|
+
- `scalar` _Number (default: 1)_: Scale factor for each confetti particle. Use decimals to make the confetti smaller. Go
|
|
152
|
+
on, try teeny tiny confetti, they are adorable!
|
|
153
|
+
- `zIndex` _Integer (default: 100)_: The confetti should be on top, after all. But if you have a crazy high page, you
|
|
154
|
+
can set it even higher.
|
|
155
|
+
- `disableForReducedMotion` _Boolean (default: true)_: Disables confetti entirely for users
|
|
156
|
+
that [prefer reduced motion](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion).
|
|
157
|
+
|
|
158
|
+
And for those asking, yes you can paste your canvas-confetti code and migrate to tsParticles Confetti without changing a thing
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { deepExtend, isArray, } from "@tsparticles/engine";
|
|
2
|
+
export class ConfettiOptions {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.angle = 90;
|
|
5
|
+
this.count = 50;
|
|
6
|
+
this.spread = 45;
|
|
7
|
+
this.startVelocity = 45;
|
|
8
|
+
this.decay = 0.9;
|
|
9
|
+
this.gravity = 1;
|
|
10
|
+
this.drift = 0;
|
|
11
|
+
this.ticks = 200;
|
|
12
|
+
this.position = {
|
|
13
|
+
x: 50,
|
|
14
|
+
y: 50,
|
|
15
|
+
};
|
|
16
|
+
this.colors = ["#26ccff", "#a25afd", "#ff5e7e", "#88ff5a", "#fcff42", "#ffa62d", "#ff36ff"];
|
|
17
|
+
this.shapes = ["square", "circle"];
|
|
18
|
+
this.scalar = 1;
|
|
19
|
+
this.zIndex = 100;
|
|
20
|
+
this.disableForReducedMotion = true;
|
|
21
|
+
this.shapeOptions = {};
|
|
22
|
+
}
|
|
23
|
+
get origin() {
|
|
24
|
+
return {
|
|
25
|
+
x: this.position.x / 100,
|
|
26
|
+
y: this.position.y / 100,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
set origin(value) {
|
|
30
|
+
this.position.x = value.x * 100;
|
|
31
|
+
this.position.y = value.y * 100;
|
|
32
|
+
}
|
|
33
|
+
get particleCount() {
|
|
34
|
+
return this.count;
|
|
35
|
+
}
|
|
36
|
+
set particleCount(value) {
|
|
37
|
+
this.count = value;
|
|
38
|
+
}
|
|
39
|
+
load(data) {
|
|
40
|
+
if (!data) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (data.angle !== undefined) {
|
|
44
|
+
this.angle = data.angle;
|
|
45
|
+
}
|
|
46
|
+
const count = data.count ?? data.particleCount;
|
|
47
|
+
if (count !== undefined) {
|
|
48
|
+
this.count = count;
|
|
49
|
+
}
|
|
50
|
+
if (data.spread !== undefined) {
|
|
51
|
+
this.spread = data.spread;
|
|
52
|
+
}
|
|
53
|
+
if (data.startVelocity !== undefined) {
|
|
54
|
+
this.startVelocity = data.startVelocity;
|
|
55
|
+
}
|
|
56
|
+
if (data.decay !== undefined) {
|
|
57
|
+
this.decay = data.decay;
|
|
58
|
+
}
|
|
59
|
+
if (data.gravity !== undefined) {
|
|
60
|
+
this.gravity = data.gravity;
|
|
61
|
+
}
|
|
62
|
+
if (data.drift !== undefined) {
|
|
63
|
+
this.drift = data.drift;
|
|
64
|
+
}
|
|
65
|
+
if (data.ticks !== undefined) {
|
|
66
|
+
this.ticks = data.ticks;
|
|
67
|
+
}
|
|
68
|
+
const origin = data.origin;
|
|
69
|
+
if (origin && !data.position) {
|
|
70
|
+
data.position = {
|
|
71
|
+
x: origin.x !== undefined ? origin.x * 100 : undefined,
|
|
72
|
+
y: origin.y !== undefined ? origin.y * 100 : undefined,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const position = data.position;
|
|
76
|
+
if (position) {
|
|
77
|
+
if (position.x !== undefined) {
|
|
78
|
+
this.position.x = position.x;
|
|
79
|
+
}
|
|
80
|
+
if (position.y !== undefined) {
|
|
81
|
+
this.position.y = position.y;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (data.colors !== undefined) {
|
|
85
|
+
if (isArray(data.colors)) {
|
|
86
|
+
this.colors = [...data.colors];
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
this.colors = data.colors;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const options = data.shapeOptions;
|
|
93
|
+
if (options !== undefined) {
|
|
94
|
+
for (const shape in options) {
|
|
95
|
+
const item = options[shape];
|
|
96
|
+
if (item) {
|
|
97
|
+
this.shapeOptions[shape] = deepExtend(this.shapeOptions[shape] ?? {}, item);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (data.shapes !== undefined) {
|
|
102
|
+
if (isArray(data.shapes)) {
|
|
103
|
+
this.shapes = [...data.shapes];
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
this.shapes = data.shapes;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (data.scalar !== undefined) {
|
|
110
|
+
this.scalar = data.scalar;
|
|
111
|
+
}
|
|
112
|
+
if (data.zIndex !== undefined) {
|
|
113
|
+
this.zIndex = data.zIndex;
|
|
114
|
+
}
|
|
115
|
+
if (data.disableForReducedMotion !== undefined) {
|
|
116
|
+
this.disableForReducedMotion = data.disableForReducedMotion;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { isSsr, isString, tsParticles, } from "@tsparticles/engine";
|
|
2
|
+
import { ConfettiOptions } from "./ConfettiOptions";
|
|
3
|
+
import { loadBasic } from "@tsparticles/basic";
|
|
4
|
+
import { loadCardsShape } from "@tsparticles/shape-cards";
|
|
5
|
+
import { loadEmittersPlugin } from "@tsparticles/plugin-emitters";
|
|
6
|
+
import { loadHeartShape } from "@tsparticles/shape-heart";
|
|
7
|
+
import { loadImageShape } from "@tsparticles/shape-image";
|
|
8
|
+
import { loadLifeUpdater } from "@tsparticles/updater-life";
|
|
9
|
+
import { loadMotionPlugin } from "@tsparticles/plugin-motion";
|
|
10
|
+
import { loadPolygonShape } from "@tsparticles/shape-polygon";
|
|
11
|
+
import { loadRollUpdater } from "@tsparticles/updater-roll";
|
|
12
|
+
import { loadRotateUpdater } from "@tsparticles/updater-rotate";
|
|
13
|
+
import { loadSquareShape } from "@tsparticles/shape-square";
|
|
14
|
+
import { loadStarShape } from "@tsparticles/shape-star";
|
|
15
|
+
import { loadTextShape } from "@tsparticles/shape-text";
|
|
16
|
+
import { loadTiltUpdater } from "@tsparticles/updater-tilt";
|
|
17
|
+
import { loadWobbleUpdater } from "@tsparticles/updater-wobble";
|
|
18
|
+
let initialized = false;
|
|
19
|
+
let initializing = false;
|
|
20
|
+
const ids = new Map();
|
|
21
|
+
async function initPlugins(engine) {
|
|
22
|
+
if (initialized) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (initializing) {
|
|
26
|
+
return new Promise((resolve) => {
|
|
27
|
+
const interval = setInterval(() => {
|
|
28
|
+
if (!initialized) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
clearInterval(interval);
|
|
32
|
+
resolve();
|
|
33
|
+
}, 100);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
initializing = true;
|
|
37
|
+
await loadEmittersPlugin(engine, false);
|
|
38
|
+
await loadMotionPlugin(engine, false);
|
|
39
|
+
await loadCardsShape(engine, false);
|
|
40
|
+
await loadHeartShape(engine, false);
|
|
41
|
+
await loadImageShape(engine, false);
|
|
42
|
+
await loadPolygonShape(engine, false);
|
|
43
|
+
await loadSquareShape(engine, false);
|
|
44
|
+
await loadStarShape(engine, false);
|
|
45
|
+
await loadTextShape(engine, false);
|
|
46
|
+
await loadRotateUpdater(engine, false);
|
|
47
|
+
await loadLifeUpdater(engine, false);
|
|
48
|
+
await loadRollUpdater(engine, false);
|
|
49
|
+
await loadTiltUpdater(engine, false);
|
|
50
|
+
await loadWobbleUpdater(engine, false);
|
|
51
|
+
await loadBasic(engine);
|
|
52
|
+
initializing = false;
|
|
53
|
+
initialized = true;
|
|
54
|
+
}
|
|
55
|
+
async function setConfetti(params) {
|
|
56
|
+
const actualOptions = new ConfettiOptions();
|
|
57
|
+
actualOptions.load(params.options);
|
|
58
|
+
let container;
|
|
59
|
+
const fpsLimit = 120, opacitySpeed = (actualOptions.ticks * 1000) / (3600 * fpsLimit);
|
|
60
|
+
if (ids.has(params.id)) {
|
|
61
|
+
container = ids.get(params.id);
|
|
62
|
+
if (container && !container.destroyed) {
|
|
63
|
+
const alias = container;
|
|
64
|
+
if (alias.addEmitter) {
|
|
65
|
+
alias.addEmitter({
|
|
66
|
+
startCount: actualOptions.count,
|
|
67
|
+
position: actualOptions.position,
|
|
68
|
+
size: {
|
|
69
|
+
width: 0,
|
|
70
|
+
height: 0,
|
|
71
|
+
},
|
|
72
|
+
rate: {
|
|
73
|
+
delay: 0,
|
|
74
|
+
quantity: 0,
|
|
75
|
+
},
|
|
76
|
+
life: {
|
|
77
|
+
duration: 0.1,
|
|
78
|
+
count: 1,
|
|
79
|
+
},
|
|
80
|
+
particles: {
|
|
81
|
+
color: {
|
|
82
|
+
value: actualOptions.colors,
|
|
83
|
+
},
|
|
84
|
+
shape: {
|
|
85
|
+
type: actualOptions.shapes,
|
|
86
|
+
options: actualOptions.shapeOptions,
|
|
87
|
+
},
|
|
88
|
+
life: {
|
|
89
|
+
count: 1,
|
|
90
|
+
},
|
|
91
|
+
opacity: {
|
|
92
|
+
value: { min: 0, max: 1 },
|
|
93
|
+
animation: {
|
|
94
|
+
enable: true,
|
|
95
|
+
sync: true,
|
|
96
|
+
speed: opacitySpeed,
|
|
97
|
+
startValue: "max",
|
|
98
|
+
destroy: "min",
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
size: {
|
|
102
|
+
value: 5 * actualOptions.scalar,
|
|
103
|
+
},
|
|
104
|
+
move: {
|
|
105
|
+
angle: {
|
|
106
|
+
value: actualOptions.spread,
|
|
107
|
+
offset: 0,
|
|
108
|
+
},
|
|
109
|
+
drift: {
|
|
110
|
+
min: -actualOptions.drift,
|
|
111
|
+
max: actualOptions.drift,
|
|
112
|
+
},
|
|
113
|
+
gravity: {
|
|
114
|
+
acceleration: actualOptions.gravity * 9.81,
|
|
115
|
+
},
|
|
116
|
+
speed: actualOptions.startVelocity * 3,
|
|
117
|
+
decay: 1 - actualOptions.decay,
|
|
118
|
+
direction: -actualOptions.angle,
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const particlesOptions = {
|
|
127
|
+
fullScreen: {
|
|
128
|
+
enable: !params.canvas,
|
|
129
|
+
zIndex: actualOptions.zIndex,
|
|
130
|
+
},
|
|
131
|
+
fpsLimit: 120,
|
|
132
|
+
particles: {
|
|
133
|
+
number: {
|
|
134
|
+
value: 0,
|
|
135
|
+
},
|
|
136
|
+
color: {
|
|
137
|
+
value: actualOptions.colors,
|
|
138
|
+
},
|
|
139
|
+
shape: {
|
|
140
|
+
type: actualOptions.shapes,
|
|
141
|
+
options: actualOptions.shapeOptions,
|
|
142
|
+
},
|
|
143
|
+
opacity: {
|
|
144
|
+
value: { min: 0, max: 1 },
|
|
145
|
+
animation: {
|
|
146
|
+
enable: true,
|
|
147
|
+
sync: true,
|
|
148
|
+
speed: opacitySpeed,
|
|
149
|
+
startValue: "max",
|
|
150
|
+
destroy: "min",
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
size: {
|
|
154
|
+
value: 5 * actualOptions.scalar,
|
|
155
|
+
},
|
|
156
|
+
links: {
|
|
157
|
+
enable: false,
|
|
158
|
+
},
|
|
159
|
+
life: {
|
|
160
|
+
count: 1,
|
|
161
|
+
},
|
|
162
|
+
move: {
|
|
163
|
+
angle: {
|
|
164
|
+
value: actualOptions.spread,
|
|
165
|
+
offset: 0,
|
|
166
|
+
},
|
|
167
|
+
drift: {
|
|
168
|
+
min: -actualOptions.drift,
|
|
169
|
+
max: actualOptions.drift,
|
|
170
|
+
},
|
|
171
|
+
enable: true,
|
|
172
|
+
gravity: {
|
|
173
|
+
enable: true,
|
|
174
|
+
acceleration: actualOptions.gravity * 9.81,
|
|
175
|
+
},
|
|
176
|
+
speed: actualOptions.startVelocity * 3,
|
|
177
|
+
decay: 1 - actualOptions.decay,
|
|
178
|
+
direction: -actualOptions.angle,
|
|
179
|
+
random: true,
|
|
180
|
+
straight: false,
|
|
181
|
+
outModes: {
|
|
182
|
+
default: "none",
|
|
183
|
+
bottom: "destroy",
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
rotate: {
|
|
187
|
+
value: {
|
|
188
|
+
min: 0,
|
|
189
|
+
max: 360,
|
|
190
|
+
},
|
|
191
|
+
direction: "random",
|
|
192
|
+
animation: {
|
|
193
|
+
enable: true,
|
|
194
|
+
speed: 60,
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
tilt: {
|
|
198
|
+
direction: "random",
|
|
199
|
+
enable: true,
|
|
200
|
+
value: {
|
|
201
|
+
min: 0,
|
|
202
|
+
max: 360,
|
|
203
|
+
},
|
|
204
|
+
animation: {
|
|
205
|
+
enable: true,
|
|
206
|
+
speed: 60,
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
roll: {
|
|
210
|
+
darken: {
|
|
211
|
+
enable: true,
|
|
212
|
+
value: 25,
|
|
213
|
+
},
|
|
214
|
+
enable: true,
|
|
215
|
+
speed: {
|
|
216
|
+
min: 15,
|
|
217
|
+
max: 25,
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
wobble: {
|
|
221
|
+
distance: 30,
|
|
222
|
+
enable: true,
|
|
223
|
+
speed: {
|
|
224
|
+
min: -15,
|
|
225
|
+
max: 15,
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
detectRetina: true,
|
|
230
|
+
motion: {
|
|
231
|
+
disable: actualOptions.disableForReducedMotion,
|
|
232
|
+
},
|
|
233
|
+
emitters: {
|
|
234
|
+
name: "confetti",
|
|
235
|
+
startCount: actualOptions.count,
|
|
236
|
+
position: actualOptions.position,
|
|
237
|
+
size: {
|
|
238
|
+
width: 0,
|
|
239
|
+
height: 0,
|
|
240
|
+
},
|
|
241
|
+
rate: {
|
|
242
|
+
delay: 0,
|
|
243
|
+
quantity: 0,
|
|
244
|
+
},
|
|
245
|
+
life: {
|
|
246
|
+
duration: 0.1,
|
|
247
|
+
count: 1,
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
container = await tsParticles.load({ id: params.id, element: params.canvas, options: particlesOptions });
|
|
252
|
+
ids.set(params.id, container);
|
|
253
|
+
return container;
|
|
254
|
+
}
|
|
255
|
+
export async function confetti(idOrOptions, confettiOptions) {
|
|
256
|
+
await initPlugins(tsParticles);
|
|
257
|
+
let options;
|
|
258
|
+
let id;
|
|
259
|
+
if (isString(idOrOptions)) {
|
|
260
|
+
id = idOrOptions;
|
|
261
|
+
options = confettiOptions ?? {};
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
id = "confetti";
|
|
265
|
+
options = idOrOptions;
|
|
266
|
+
}
|
|
267
|
+
return setConfetti({
|
|
268
|
+
id,
|
|
269
|
+
options,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
confetti.create = async (canvas, options) => {
|
|
273
|
+
if (!canvas) {
|
|
274
|
+
return confetti;
|
|
275
|
+
}
|
|
276
|
+
await initPlugins(tsParticles);
|
|
277
|
+
const id = canvas.getAttribute("id") || "confetti";
|
|
278
|
+
canvas.setAttribute("id", id);
|
|
279
|
+
return async (idOrOptions, confettiOptions) => {
|
|
280
|
+
let subOptions;
|
|
281
|
+
let subId;
|
|
282
|
+
if (isString(idOrOptions)) {
|
|
283
|
+
subId = idOrOptions;
|
|
284
|
+
subOptions = confettiOptions ?? options;
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
subId = id;
|
|
288
|
+
subOptions = idOrOptions;
|
|
289
|
+
}
|
|
290
|
+
return setConfetti({
|
|
291
|
+
id: subId,
|
|
292
|
+
canvas,
|
|
293
|
+
options: subOptions,
|
|
294
|
+
});
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
confetti.version = tsParticles.version;
|
|
298
|
+
if (!isSsr()) {
|
|
299
|
+
window.confetti = confetti;
|
|
300
|
+
}
|
package/browser/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./confetti";
|