@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,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfettiOptions = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ class ConfettiOptions {
6
+ constructor() {
7
+ this.angle = 90;
8
+ this.count = 50;
9
+ this.spread = 45;
10
+ this.startVelocity = 45;
11
+ this.decay = 0.9;
12
+ this.gravity = 1;
13
+ this.drift = 0;
14
+ this.ticks = 200;
15
+ this.position = {
16
+ x: 50,
17
+ y: 50,
18
+ };
19
+ this.colors = ["#26ccff", "#a25afd", "#ff5e7e", "#88ff5a", "#fcff42", "#ffa62d", "#ff36ff"];
20
+ this.shapes = ["square", "circle"];
21
+ this.scalar = 1;
22
+ this.zIndex = 100;
23
+ this.disableForReducedMotion = true;
24
+ this.shapeOptions = {};
25
+ }
26
+ get origin() {
27
+ return {
28
+ x: this.position.x / 100,
29
+ y: this.position.y / 100,
30
+ };
31
+ }
32
+ set origin(value) {
33
+ this.position.x = value.x * 100;
34
+ this.position.y = value.y * 100;
35
+ }
36
+ get particleCount() {
37
+ return this.count;
38
+ }
39
+ set particleCount(value) {
40
+ this.count = value;
41
+ }
42
+ load(data) {
43
+ if (!data) {
44
+ return;
45
+ }
46
+ if (data.angle !== undefined) {
47
+ this.angle = data.angle;
48
+ }
49
+ const count = data.count ?? data.particleCount;
50
+ if (count !== undefined) {
51
+ this.count = count;
52
+ }
53
+ if (data.spread !== undefined) {
54
+ this.spread = data.spread;
55
+ }
56
+ if (data.startVelocity !== undefined) {
57
+ this.startVelocity = data.startVelocity;
58
+ }
59
+ if (data.decay !== undefined) {
60
+ this.decay = data.decay;
61
+ }
62
+ if (data.gravity !== undefined) {
63
+ this.gravity = data.gravity;
64
+ }
65
+ if (data.drift !== undefined) {
66
+ this.drift = data.drift;
67
+ }
68
+ if (data.ticks !== undefined) {
69
+ this.ticks = data.ticks;
70
+ }
71
+ const origin = data.origin;
72
+ if (origin && !data.position) {
73
+ data.position = {
74
+ x: origin.x !== undefined ? origin.x * 100 : undefined,
75
+ y: origin.y !== undefined ? origin.y * 100 : undefined,
76
+ };
77
+ }
78
+ const position = data.position;
79
+ if (position) {
80
+ if (position.x !== undefined) {
81
+ this.position.x = position.x;
82
+ }
83
+ if (position.y !== undefined) {
84
+ this.position.y = position.y;
85
+ }
86
+ }
87
+ if (data.colors !== undefined) {
88
+ if ((0, engine_1.isArray)(data.colors)) {
89
+ this.colors = [...data.colors];
90
+ }
91
+ else {
92
+ this.colors = data.colors;
93
+ }
94
+ }
95
+ const options = data.shapeOptions;
96
+ if (options !== undefined) {
97
+ for (const shape in options) {
98
+ const item = options[shape];
99
+ if (item) {
100
+ this.shapeOptions[shape] = (0, engine_1.deepExtend)(this.shapeOptions[shape] ?? {}, item);
101
+ }
102
+ }
103
+ }
104
+ if (data.shapes !== undefined) {
105
+ if ((0, engine_1.isArray)(data.shapes)) {
106
+ this.shapes = [...data.shapes];
107
+ }
108
+ else {
109
+ this.shapes = data.shapes;
110
+ }
111
+ }
112
+ if (data.scalar !== undefined) {
113
+ this.scalar = data.scalar;
114
+ }
115
+ if (data.zIndex !== undefined) {
116
+ this.zIndex = data.zIndex;
117
+ }
118
+ if (data.disableForReducedMotion !== undefined) {
119
+ this.disableForReducedMotion = data.disableForReducedMotion;
120
+ }
121
+ }
122
+ }
123
+ exports.ConfettiOptions = ConfettiOptions;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/bundle.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("."), exports);
18
+ __exportStar(require("@tsparticles/engine"), exports);
@@ -0,0 +1,304 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.confetti = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ const ConfettiOptions_1 = require("./ConfettiOptions");
6
+ const basic_1 = require("@tsparticles/basic");
7
+ const shape_cards_1 = require("@tsparticles/shape-cards");
8
+ const plugin_emitters_1 = require("@tsparticles/plugin-emitters");
9
+ const shape_heart_1 = require("@tsparticles/shape-heart");
10
+ const shape_image_1 = require("@tsparticles/shape-image");
11
+ const updater_life_1 = require("@tsparticles/updater-life");
12
+ const plugin_motion_1 = require("@tsparticles/plugin-motion");
13
+ const shape_polygon_1 = require("@tsparticles/shape-polygon");
14
+ const updater_roll_1 = require("@tsparticles/updater-roll");
15
+ const updater_rotate_1 = require("@tsparticles/updater-rotate");
16
+ const shape_square_1 = require("@tsparticles/shape-square");
17
+ const shape_star_1 = require("@tsparticles/shape-star");
18
+ const shape_text_1 = require("@tsparticles/shape-text");
19
+ const updater_tilt_1 = require("@tsparticles/updater-tilt");
20
+ const updater_wobble_1 = require("@tsparticles/updater-wobble");
21
+ let initialized = false;
22
+ let initializing = false;
23
+ const ids = new Map();
24
+ async function initPlugins(engine) {
25
+ if (initialized) {
26
+ return;
27
+ }
28
+ if (initializing) {
29
+ return new Promise((resolve) => {
30
+ const interval = setInterval(() => {
31
+ if (!initialized) {
32
+ return;
33
+ }
34
+ clearInterval(interval);
35
+ resolve();
36
+ }, 100);
37
+ });
38
+ }
39
+ initializing = true;
40
+ await (0, plugin_emitters_1.loadEmittersPlugin)(engine, false);
41
+ await (0, plugin_motion_1.loadMotionPlugin)(engine, false);
42
+ await (0, shape_cards_1.loadCardsShape)(engine, false);
43
+ await (0, shape_heart_1.loadHeartShape)(engine, false);
44
+ await (0, shape_image_1.loadImageShape)(engine, false);
45
+ await (0, shape_polygon_1.loadPolygonShape)(engine, false);
46
+ await (0, shape_square_1.loadSquareShape)(engine, false);
47
+ await (0, shape_star_1.loadStarShape)(engine, false);
48
+ await (0, shape_text_1.loadTextShape)(engine, false);
49
+ await (0, updater_rotate_1.loadRotateUpdater)(engine, false);
50
+ await (0, updater_life_1.loadLifeUpdater)(engine, false);
51
+ await (0, updater_roll_1.loadRollUpdater)(engine, false);
52
+ await (0, updater_tilt_1.loadTiltUpdater)(engine, false);
53
+ await (0, updater_wobble_1.loadWobbleUpdater)(engine, false);
54
+ await (0, basic_1.loadBasic)(engine);
55
+ initializing = false;
56
+ initialized = true;
57
+ }
58
+ async function setConfetti(params) {
59
+ const actualOptions = new ConfettiOptions_1.ConfettiOptions();
60
+ actualOptions.load(params.options);
61
+ let container;
62
+ const fpsLimit = 120, opacitySpeed = (actualOptions.ticks * 1000) / (3600 * fpsLimit);
63
+ if (ids.has(params.id)) {
64
+ container = ids.get(params.id);
65
+ if (container && !container.destroyed) {
66
+ const alias = container;
67
+ if (alias.addEmitter) {
68
+ alias.addEmitter({
69
+ startCount: actualOptions.count,
70
+ position: actualOptions.position,
71
+ size: {
72
+ width: 0,
73
+ height: 0,
74
+ },
75
+ rate: {
76
+ delay: 0,
77
+ quantity: 0,
78
+ },
79
+ life: {
80
+ duration: 0.1,
81
+ count: 1,
82
+ },
83
+ particles: {
84
+ color: {
85
+ value: actualOptions.colors,
86
+ },
87
+ shape: {
88
+ type: actualOptions.shapes,
89
+ options: actualOptions.shapeOptions,
90
+ },
91
+ life: {
92
+ count: 1,
93
+ },
94
+ opacity: {
95
+ value: { min: 0, max: 1 },
96
+ animation: {
97
+ enable: true,
98
+ sync: true,
99
+ speed: opacitySpeed,
100
+ startValue: "max",
101
+ destroy: "min",
102
+ },
103
+ },
104
+ size: {
105
+ value: 5 * actualOptions.scalar,
106
+ },
107
+ move: {
108
+ angle: {
109
+ value: actualOptions.spread,
110
+ offset: 0,
111
+ },
112
+ drift: {
113
+ min: -actualOptions.drift,
114
+ max: actualOptions.drift,
115
+ },
116
+ gravity: {
117
+ acceleration: actualOptions.gravity * 9.81,
118
+ },
119
+ speed: actualOptions.startVelocity * 3,
120
+ decay: 1 - actualOptions.decay,
121
+ direction: -actualOptions.angle,
122
+ },
123
+ },
124
+ });
125
+ return;
126
+ }
127
+ }
128
+ }
129
+ const particlesOptions = {
130
+ fullScreen: {
131
+ enable: !params.canvas,
132
+ zIndex: actualOptions.zIndex,
133
+ },
134
+ fpsLimit: 120,
135
+ particles: {
136
+ number: {
137
+ value: 0,
138
+ },
139
+ color: {
140
+ value: actualOptions.colors,
141
+ },
142
+ shape: {
143
+ type: actualOptions.shapes,
144
+ options: actualOptions.shapeOptions,
145
+ },
146
+ opacity: {
147
+ value: { min: 0, max: 1 },
148
+ animation: {
149
+ enable: true,
150
+ sync: true,
151
+ speed: opacitySpeed,
152
+ startValue: "max",
153
+ destroy: "min",
154
+ },
155
+ },
156
+ size: {
157
+ value: 5 * actualOptions.scalar,
158
+ },
159
+ links: {
160
+ enable: false,
161
+ },
162
+ life: {
163
+ count: 1,
164
+ },
165
+ move: {
166
+ angle: {
167
+ value: actualOptions.spread,
168
+ offset: 0,
169
+ },
170
+ drift: {
171
+ min: -actualOptions.drift,
172
+ max: actualOptions.drift,
173
+ },
174
+ enable: true,
175
+ gravity: {
176
+ enable: true,
177
+ acceleration: actualOptions.gravity * 9.81,
178
+ },
179
+ speed: actualOptions.startVelocity * 3,
180
+ decay: 1 - actualOptions.decay,
181
+ direction: -actualOptions.angle,
182
+ random: true,
183
+ straight: false,
184
+ outModes: {
185
+ default: "none",
186
+ bottom: "destroy",
187
+ },
188
+ },
189
+ rotate: {
190
+ value: {
191
+ min: 0,
192
+ max: 360,
193
+ },
194
+ direction: "random",
195
+ animation: {
196
+ enable: true,
197
+ speed: 60,
198
+ },
199
+ },
200
+ tilt: {
201
+ direction: "random",
202
+ enable: true,
203
+ value: {
204
+ min: 0,
205
+ max: 360,
206
+ },
207
+ animation: {
208
+ enable: true,
209
+ speed: 60,
210
+ },
211
+ },
212
+ roll: {
213
+ darken: {
214
+ enable: true,
215
+ value: 25,
216
+ },
217
+ enable: true,
218
+ speed: {
219
+ min: 15,
220
+ max: 25,
221
+ },
222
+ },
223
+ wobble: {
224
+ distance: 30,
225
+ enable: true,
226
+ speed: {
227
+ min: -15,
228
+ max: 15,
229
+ },
230
+ },
231
+ },
232
+ detectRetina: true,
233
+ motion: {
234
+ disable: actualOptions.disableForReducedMotion,
235
+ },
236
+ emitters: {
237
+ name: "confetti",
238
+ startCount: actualOptions.count,
239
+ position: actualOptions.position,
240
+ size: {
241
+ width: 0,
242
+ height: 0,
243
+ },
244
+ rate: {
245
+ delay: 0,
246
+ quantity: 0,
247
+ },
248
+ life: {
249
+ duration: 0.1,
250
+ count: 1,
251
+ },
252
+ },
253
+ };
254
+ container = await engine_1.tsParticles.load({ id: params.id, element: params.canvas, options: particlesOptions });
255
+ ids.set(params.id, container);
256
+ return container;
257
+ }
258
+ async function confetti(idOrOptions, confettiOptions) {
259
+ await initPlugins(engine_1.tsParticles);
260
+ let options;
261
+ let id;
262
+ if ((0, engine_1.isString)(idOrOptions)) {
263
+ id = idOrOptions;
264
+ options = confettiOptions ?? {};
265
+ }
266
+ else {
267
+ id = "confetti";
268
+ options = idOrOptions;
269
+ }
270
+ return setConfetti({
271
+ id,
272
+ options,
273
+ });
274
+ }
275
+ exports.confetti = confetti;
276
+ confetti.create = async (canvas, options) => {
277
+ if (!canvas) {
278
+ return confetti;
279
+ }
280
+ await initPlugins(engine_1.tsParticles);
281
+ const id = canvas.getAttribute("id") || "confetti";
282
+ canvas.setAttribute("id", id);
283
+ return async (idOrOptions, confettiOptions) => {
284
+ let subOptions;
285
+ let subId;
286
+ if ((0, engine_1.isString)(idOrOptions)) {
287
+ subId = idOrOptions;
288
+ subOptions = confettiOptions ?? options;
289
+ }
290
+ else {
291
+ subId = id;
292
+ subOptions = idOrOptions;
293
+ }
294
+ return setConfetti({
295
+ id: subId,
296
+ canvas,
297
+ options: subOptions,
298
+ });
299
+ };
300
+ };
301
+ confetti.version = engine_1.tsParticles.version;
302
+ if (!(0, engine_1.isSsr)()) {
303
+ window.confetti = confetti;
304
+ }
package/cjs/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./confetti"), exports);
@@ -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 {};
package/esm/bundle.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from ".";
2
+ export * from "@tsparticles/engine";