@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.
@@ -0,0 +1,131 @@
1
+ import { ConfettiOptions } from "./ConfettiOptions";
2
+ export const loadOptions = (confettiOptions) => {
3
+ const actualOptions = new ConfettiOptions();
4
+ actualOptions.load(confettiOptions);
5
+ return {
6
+ fullScreen: {
7
+ enable: true,
8
+ zIndex: actualOptions.zIndex,
9
+ },
10
+ fpsLimit: 120,
11
+ particles: {
12
+ number: {
13
+ value: 0,
14
+ },
15
+ color: {
16
+ value: actualOptions.colors,
17
+ },
18
+ shape: {
19
+ type: actualOptions.shapes,
20
+ },
21
+ opacity: {
22
+ value: { min: 0, max: 1 },
23
+ animation: {
24
+ enable: true,
25
+ speed: 0.5,
26
+ startValue: "max",
27
+ destroy: "min",
28
+ },
29
+ },
30
+ size: {
31
+ value: 5 * actualOptions.scalar,
32
+ },
33
+ links: {
34
+ enable: false,
35
+ },
36
+ life: {
37
+ duration: {
38
+ sync: true,
39
+ value: actualOptions.ticks / 60,
40
+ },
41
+ count: 1,
42
+ },
43
+ move: {
44
+ angle: {
45
+ value: actualOptions.spread,
46
+ offset: 0,
47
+ },
48
+ drift: {
49
+ min: -actualOptions.drift,
50
+ max: actualOptions.drift,
51
+ },
52
+ enable: true,
53
+ gravity: {
54
+ enable: true,
55
+ acceleration: actualOptions.gravity * 9.81,
56
+ },
57
+ speed: actualOptions.startVelocity,
58
+ decay: 1 - actualOptions.decay,
59
+ direction: -actualOptions.angle,
60
+ random: true,
61
+ straight: false,
62
+ outModes: {
63
+ default: "none",
64
+ bottom: "destroy",
65
+ },
66
+ },
67
+ rotate: {
68
+ value: {
69
+ min: 0,
70
+ max: 360,
71
+ },
72
+ direction: "random",
73
+ animation: {
74
+ enable: true,
75
+ speed: 60,
76
+ },
77
+ },
78
+ tilt: {
79
+ direction: "random",
80
+ enable: true,
81
+ value: {
82
+ min: 0,
83
+ max: 360,
84
+ },
85
+ animation: {
86
+ enable: true,
87
+ speed: 60,
88
+ },
89
+ },
90
+ roll: {
91
+ darken: {
92
+ enable: true,
93
+ value: 25,
94
+ },
95
+ enable: true,
96
+ speed: {
97
+ min: 15,
98
+ max: 25,
99
+ },
100
+ },
101
+ wobble: {
102
+ distance: 30,
103
+ enable: true,
104
+ speed: {
105
+ min: -15,
106
+ max: 15,
107
+ },
108
+ },
109
+ },
110
+ detectRetina: true,
111
+ motion: {
112
+ disable: actualOptions.disableForReducedMotion,
113
+ },
114
+ emitters: {
115
+ startCount: actualOptions.count,
116
+ position: actualOptions.position,
117
+ size: {
118
+ width: 0,
119
+ height: 0,
120
+ },
121
+ rate: {
122
+ delay: 0,
123
+ quantity: 0,
124
+ },
125
+ life: {
126
+ duration: 0.1,
127
+ count: 1,
128
+ },
129
+ },
130
+ };
131
+ };
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfettiOptions = void 0;
4
+ class ConfettiOptions {
5
+ constructor() {
6
+ this.angle = 90;
7
+ this.count = 50;
8
+ this.spread = 45;
9
+ this.startVelocity = 45;
10
+ this.decay = 0.9;
11
+ this.gravity = 1;
12
+ this.drift = 0;
13
+ this.ticks = 200;
14
+ this.position = {
15
+ x: 50,
16
+ y: 50,
17
+ };
18
+ this.colors = ["#ffffff", "#ff0000"];
19
+ this.shapes = ["square", "circle"];
20
+ this.scalar = 1;
21
+ this.zIndex = 100;
22
+ this.disableForReducedMotion = true;
23
+ }
24
+ get origin() {
25
+ return {
26
+ x: this.position.x / 100,
27
+ y: this.position.y / 100,
28
+ };
29
+ }
30
+ set origin(value) {
31
+ this.position.x = value.x * 100;
32
+ this.position.y = value.y * 100;
33
+ }
34
+ get particleCount() {
35
+ return this.count;
36
+ }
37
+ set particleCount(value) {
38
+ this.count = value;
39
+ }
40
+ load(data) {
41
+ var _a, _b;
42
+ if (!data) {
43
+ return;
44
+ }
45
+ if (data.angle !== undefined) {
46
+ this.angle = data.angle;
47
+ }
48
+ const count = (_a = data.count) !== null && _a !== void 0 ? _a : data.particleCount;
49
+ if (count !== undefined) {
50
+ this.count = count;
51
+ }
52
+ if (data.spread !== undefined) {
53
+ this.spread = data.spread;
54
+ }
55
+ if (data.startVelocity !== undefined) {
56
+ this.startVelocity = data.startVelocity;
57
+ }
58
+ if (data.decay !== undefined) {
59
+ this.decay = data.decay;
60
+ }
61
+ if (data.gravity !== undefined) {
62
+ this.gravity = data.gravity;
63
+ }
64
+ if (data.drift !== undefined) {
65
+ this.drift = data.drift;
66
+ }
67
+ if (data.ticks !== undefined) {
68
+ this.ticks = data.ticks;
69
+ }
70
+ const position = (_b = data.position) !== null && _b !== void 0 ? _b : this.position;
71
+ if ((position === null || position === void 0 ? void 0 : position.x) !== undefined) {
72
+ this.position.x = position.x;
73
+ }
74
+ if ((position === null || position === void 0 ? void 0 : position.y) !== undefined) {
75
+ this.position.y = position.y;
76
+ }
77
+ if (data.colors !== undefined) {
78
+ if (data.colors instanceof Array) {
79
+ this.colors = [...data.colors];
80
+ }
81
+ else {
82
+ this.colors = data.colors;
83
+ }
84
+ }
85
+ if (data.shapes !== undefined) {
86
+ if (data.shapes instanceof Array) {
87
+ this.shapes = [...data.shapes];
88
+ }
89
+ else {
90
+ this.shapes = data.shapes;
91
+ }
92
+ }
93
+ if (data.scalar !== undefined) {
94
+ this.scalar = data.scalar;
95
+ }
96
+ if (data.zIndex !== undefined) {
97
+ this.zIndex = data.zIndex;
98
+ }
99
+ if (data.disableForReducedMotion !== undefined) {
100
+ this.disableForReducedMotion = data.disableForReducedMotion;
101
+ }
102
+ }
103
+ }
104
+ 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,20 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.tsParticles = exports.loadConfettiPreset = exports.confetti = void 0;
13
+ const index_1 = require("./index");
14
+ Object.defineProperty(exports, "confetti", { enumerable: true, get: function () { return index_1.confetti; } });
15
+ Object.defineProperty(exports, "loadConfettiPreset", { enumerable: true, get: function () { return index_1.loadConfettiPreset; } });
16
+ const engine_1 = require("@tsparticles/engine");
17
+ Object.defineProperty(exports, "tsParticles", { enumerable: true, get: function () { return engine_1.tsParticles; } });
18
+ (() => __awaiter(void 0, void 0, void 0, function* () {
19
+ yield (0, index_1.loadConfettiPreset)(engine_1.tsParticles);
20
+ }))();
package/cjs/index.js ADDED
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.confetti = exports.loadConfettiPreset = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ const updater_angle_1 = require("@tsparticles/updater-angle");
15
+ const move_base_1 = require("@tsparticles/move-base");
16
+ const shape_circle_1 = require("@tsparticles/shape-circle");
17
+ const updater_color_1 = require("@tsparticles/updater-color");
18
+ const plugin_emitters_1 = require("@tsparticles/plugin-emitters");
19
+ const updater_life_1 = require("@tsparticles/updater-life");
20
+ const plugin_motion_1 = require("@tsparticles/plugin-motion");
21
+ const updater_opacity_1 = require("@tsparticles/updater-opacity");
22
+ const options_1 = require("./options");
23
+ const updater_out_modes_1 = require("@tsparticles/updater-out-modes");
24
+ const updater_roll_1 = require("@tsparticles/updater-roll");
25
+ const updater_size_1 = require("@tsparticles/updater-size");
26
+ const shape_square_1 = require("@tsparticles/shape-square");
27
+ const updater_tilt_1 = require("@tsparticles/updater-tilt");
28
+ const updater_wobble_1 = require("@tsparticles/updater-wobble");
29
+ function loadPreset(engine, confettiOptions, override = false) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ yield (0, move_base_1.loadBaseMover)(engine);
32
+ yield (0, shape_circle_1.loadCircleShape)(engine);
33
+ yield (0, shape_square_1.loadSquareShape)(engine);
34
+ yield (0, updater_color_1.loadColorUpdater)(engine);
35
+ yield (0, updater_size_1.loadSizeUpdater)(engine);
36
+ yield (0, updater_opacity_1.loadOpacityUpdater)(engine);
37
+ yield (0, updater_out_modes_1.loadOutModesUpdater)(engine);
38
+ yield (0, plugin_emitters_1.loadEmittersPlugin)(engine);
39
+ yield (0, plugin_motion_1.loadMotionPlugin)(engine);
40
+ yield (0, updater_wobble_1.loadWobbleUpdater)(engine);
41
+ yield (0, updater_roll_1.loadRollUpdater)(engine);
42
+ yield (0, updater_angle_1.loadAngleUpdater)(engine);
43
+ yield (0, updater_tilt_1.loadTiltUpdater)(engine);
44
+ yield (0, updater_life_1.loadLifeUpdater)(engine);
45
+ yield engine.addPreset("confetti", (0, options_1.loadOptions)(confettiOptions), override);
46
+ });
47
+ }
48
+ function loadConfettiPreset(main) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ yield loadPreset(main, {}, true);
51
+ });
52
+ }
53
+ exports.loadConfettiPreset = loadConfettiPreset;
54
+ function confetti(idOrOptions, confettiOptions) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ let options;
57
+ let id;
58
+ if (typeof idOrOptions === "string") {
59
+ id = idOrOptions;
60
+ options = confettiOptions !== null && confettiOptions !== void 0 ? confettiOptions : {};
61
+ }
62
+ else {
63
+ id = `tsparticles_${Math.floor((0, engine_1.getRandom)() * 1000)}`;
64
+ options = idOrOptions;
65
+ }
66
+ yield loadPreset(engine_1.tsParticles, options, true);
67
+ yield engine_1.tsParticles.load({
68
+ id,
69
+ options: {
70
+ preset: "confetti",
71
+ },
72
+ });
73
+ });
74
+ }
75
+ exports.confetti = confetti;
package/cjs/options.js ADDED
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadOptions = void 0;
4
+ const ConfettiOptions_1 = require("./ConfettiOptions");
5
+ const loadOptions = (confettiOptions) => {
6
+ const actualOptions = new ConfettiOptions_1.ConfettiOptions();
7
+ actualOptions.load(confettiOptions);
8
+ return {
9
+ fullScreen: {
10
+ enable: true,
11
+ zIndex: actualOptions.zIndex,
12
+ },
13
+ fpsLimit: 120,
14
+ particles: {
15
+ number: {
16
+ value: 0,
17
+ },
18
+ color: {
19
+ value: actualOptions.colors,
20
+ },
21
+ shape: {
22
+ type: actualOptions.shapes,
23
+ },
24
+ opacity: {
25
+ value: { min: 0, max: 1 },
26
+ animation: {
27
+ enable: true,
28
+ speed: 0.5,
29
+ startValue: "max",
30
+ destroy: "min",
31
+ },
32
+ },
33
+ size: {
34
+ value: 5 * actualOptions.scalar,
35
+ },
36
+ links: {
37
+ enable: false,
38
+ },
39
+ life: {
40
+ duration: {
41
+ sync: true,
42
+ value: actualOptions.ticks / 60,
43
+ },
44
+ count: 1,
45
+ },
46
+ move: {
47
+ angle: {
48
+ value: actualOptions.spread,
49
+ offset: 0,
50
+ },
51
+ drift: {
52
+ min: -actualOptions.drift,
53
+ max: actualOptions.drift,
54
+ },
55
+ enable: true,
56
+ gravity: {
57
+ enable: true,
58
+ acceleration: actualOptions.gravity * 9.81,
59
+ },
60
+ speed: actualOptions.startVelocity,
61
+ decay: 1 - actualOptions.decay,
62
+ direction: -actualOptions.angle,
63
+ random: true,
64
+ straight: false,
65
+ outModes: {
66
+ default: "none",
67
+ bottom: "destroy",
68
+ },
69
+ },
70
+ rotate: {
71
+ value: {
72
+ min: 0,
73
+ max: 360,
74
+ },
75
+ direction: "random",
76
+ animation: {
77
+ enable: true,
78
+ speed: 60,
79
+ },
80
+ },
81
+ tilt: {
82
+ direction: "random",
83
+ enable: true,
84
+ value: {
85
+ min: 0,
86
+ max: 360,
87
+ },
88
+ animation: {
89
+ enable: true,
90
+ speed: 60,
91
+ },
92
+ },
93
+ roll: {
94
+ darken: {
95
+ enable: true,
96
+ value: 25,
97
+ },
98
+ enable: true,
99
+ speed: {
100
+ min: 15,
101
+ max: 25,
102
+ },
103
+ },
104
+ wobble: {
105
+ distance: 30,
106
+ enable: true,
107
+ speed: {
108
+ min: -15,
109
+ max: 15,
110
+ },
111
+ },
112
+ },
113
+ detectRetina: true,
114
+ motion: {
115
+ disable: actualOptions.disableForReducedMotion,
116
+ },
117
+ emitters: {
118
+ startCount: actualOptions.count,
119
+ position: actualOptions.position,
120
+ size: {
121
+ width: 0,
122
+ height: 0,
123
+ },
124
+ rate: {
125
+ delay: 0,
126
+ quantity: 0,
127
+ },
128
+ life: {
129
+ duration: 0.1,
130
+ count: 1,
131
+ },
132
+ },
133
+ };
134
+ };
135
+ exports.loadOptions = loadOptions;
@@ -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/esm/bundle.js ADDED
@@ -0,0 +1,6 @@
1
+ import { confetti, loadConfettiPreset } from "./index";
2
+ import { tsParticles } from "@tsparticles/engine";
3
+ (async () => {
4
+ await loadConfettiPreset(tsParticles);
5
+ })();
6
+ export { confetti, loadConfettiPreset, tsParticles };
package/esm/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
+ }