@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.
@@ -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/esm/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./confetti";
package/package.json ADDED
@@ -0,0 +1,110 @@
1
+ {
2
+ "name": "@tsparticles/confetti",
3
+ "version": "3.0.0-beta.0",
4
+ "description": "Easily create highly customizable particle animations and use them as animated backgrounds for your website. Ready to use components available also for React, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Riot.js, Inferno.",
5
+ "homepage": "https://particles.js.org",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/matteobruni/tsparticles.git",
9
+ "directory": "bundles/confetti"
10
+ },
11
+ "keywords": [
12
+ "front-end",
13
+ "frontend",
14
+ "tsparticles",
15
+ "particles.js",
16
+ "particlesjs",
17
+ "particles",
18
+ "particle",
19
+ "canvas",
20
+ "jsparticles",
21
+ "xparticles",
22
+ "particles-js",
23
+ "particles-bg",
24
+ "particles-bg-vue",
25
+ "particles-ts",
26
+ "particles.ts",
27
+ "react-particles-js",
28
+ "react-particles.js",
29
+ "react-particles",
30
+ "react",
31
+ "reactjs",
32
+ "vue-particles",
33
+ "ngx-particles",
34
+ "angular-particles",
35
+ "particleground",
36
+ "vue",
37
+ "vuejs",
38
+ "preact",
39
+ "preactjs",
40
+ "jquery",
41
+ "angularjs",
42
+ "angular",
43
+ "typescript",
44
+ "javascript",
45
+ "animation",
46
+ "web",
47
+ "html5",
48
+ "web-design",
49
+ "webdesign",
50
+ "css",
51
+ "html",
52
+ "css3",
53
+ "animated",
54
+ "background",
55
+ "confetti",
56
+ "canvas",
57
+ "fireworks",
58
+ "fireworks-js",
59
+ "confetti-js",
60
+ "confettijs",
61
+ "fireworksjs",
62
+ "canvas-confetti"
63
+ ],
64
+ "author": "Matteo Bruni <matteo.bruni@me.com>",
65
+ "license": "MIT",
66
+ "bugs": {
67
+ "url": "https://github.com/matteobruni/tsparticles/issues"
68
+ },
69
+ "funding": [
70
+ {
71
+ "type": "github",
72
+ "url": "https://github.com/sponsors/matteobruni"
73
+ },
74
+ {
75
+ "type": "github",
76
+ "url": "https://github.com/sponsors/tsparticles"
77
+ },
78
+ {
79
+ "type": "buymeacoffee",
80
+ "url": "https://www.buymeacoffee.com/matteobruni"
81
+ }
82
+ ],
83
+ "main": "cjs/index.js",
84
+ "module": "esm/index.js",
85
+ "jsdelivr": "tsparticles.confetti.bundle.min.js",
86
+ "unpkg": "tsparticles.confetti.bundle.min.js",
87
+ "sideEffects": false,
88
+ "types": "types/index.d.ts",
89
+ "dependencies": {
90
+ "@tsparticles/basic": "^3.0.0-beta.0",
91
+ "@tsparticles/engine": "^3.0.0-beta.0",
92
+ "@tsparticles/plugin-emitters": "^3.0.0-beta.0",
93
+ "@tsparticles/plugin-motion": "^3.0.0-beta.0",
94
+ "@tsparticles/shape-cards": "^3.0.0-beta.0",
95
+ "@tsparticles/shape-heart": "^3.0.0-beta.0",
96
+ "@tsparticles/shape-image": "^3.0.0-beta.0",
97
+ "@tsparticles/shape-polygon": "^3.0.0-beta.0",
98
+ "@tsparticles/shape-square": "^3.0.0-beta.0",
99
+ "@tsparticles/shape-star": "^3.0.0-beta.0",
100
+ "@tsparticles/shape-text": "^3.0.0-beta.0",
101
+ "@tsparticles/updater-life": "^3.0.0-beta.0",
102
+ "@tsparticles/updater-roll": "^3.0.0-beta.0",
103
+ "@tsparticles/updater-rotate": "^3.0.0-beta.0",
104
+ "@tsparticles/updater-tilt": "^3.0.0-beta.0",
105
+ "@tsparticles/updater-wobble": "^3.0.0-beta.0"
106
+ },
107
+ "publishConfig": {
108
+ "access": "public"
109
+ }
110
+ }