@tsparticles/fireworks 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 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,92 @@
1
+ [![banner](https://particles.js.org/images/banner2.png)](https://particles.js.org)
2
+
3
+ # tsParticles Fireworks Bundle
4
+
5
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/@tsparticles/fireworks/badge)](https://www.jsdelivr.com/package/npm/@tsparticles/fireworks) [![npmjs](https://badge.fury.io/js/@tsparticles/fireworks.svg)](https://www.npmjs.com/package/@tsparticles/fireworks) [![npmjs](https://img.shields.io/npm/dt/@tsparticles/fireworks)](https://www.npmjs.com/package/@tsparticles/fireworks) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
6
+
7
+ [tsParticles](https://github.com/matteobruni/tsparticles) fireworks bundle loads all the features necessary to create
8
+ beautiful fireworks effects with ease.
9
+
10
+ **Included Packages**
11
+
12
+ - [@tsparticles/engine](https://github.com/matteobruni/tsparticles/tree/main/engine)
13
+ - [@tsparticles/move-base](https://github.com/matteobruni/tsparticles/tree/main/move/base)
14
+ - [@tsparticles/plugin-emitters](https://github.com/matteobruni/tsparticles/tree/main/plugins/emitters)
15
+ - [@tsparticles/plugin-sounds](https://github.com/matteobruni/tsparticles/tree/main/plugins/sounds)
16
+ - [@tsparticles/shape-circle](https://github.com/matteobruni/tsparticles/tree/main/shapes/circle)
17
+ - [@tsparticles/shape-line](https://github.com/matteobruni/tsparticles/tree/main/shapes/line)
18
+ - [@tsparticles/updater-color](https://github.com/matteobruni/tsparticles/tree/main/updaters/color)
19
+ - [@tsparticles/updater-destroy](https://github.com/matteobruni/tsparticles/tree/main/updaters/destroy)
20
+ - [@tsparticles/updater-life](https://github.com/matteobruni/tsparticles/tree/main/updaters/life)
21
+ - [@tsparticles/updater-opacity](https://github.com/matteobruni/tsparticles/tree/main/updaters/opacity)
22
+ - [@tsparticles/updater-out-modes](https://github.com/matteobruni/tsparticles/tree/main/updaters/outModes)
23
+ - [@tsparticles/updater-rotate](https://github.com/matteobruni/tsparticles/tree/main/updaters/rotate)
24
+ - [@tsparticles/updater-size](https://github.com/matteobruni/tsparticles/tree/main/updaters/size)
25
+ - [@tsparticles/updater-stroke-color](https://github.com/matteobruni/tsparticles/tree/main/updaters/strokeColor)
26
+
27
+ ## How to use it
28
+
29
+ ### CDN / Vanilla JS / jQuery
30
+
31
+ The CDN/Vanilla version JS has two different files:
32
+
33
+ - One is a bundle file with all the scripts included in a single file
34
+ - One is a file including just the `fireworks` function to load the tsParticles fireworks bunddle, all dependencies must
35
+ be
36
+ included manually
37
+
38
+ #### Bundle
39
+
40
+ Including the `tsparticles.fireworks.bundle.min.js` file will out of the box.
41
+
42
+ This is the easiest usage, since it's a single file with all the features loaded.
43
+
44
+ You can still add additional packages, loading them like all the other packages.
45
+
46
+ #### Not Bundle
47
+
48
+ This installation requires more work since all dependencies must be included in the page. Some lines above are all
49
+ specified in the **Included Packages** section.
50
+
51
+ ### Usage
52
+
53
+ Once the scripts are loaded you can set up `tsParticles` like the following examples:
54
+
55
+ ** Easiest Way **
56
+
57
+ ```javascript
58
+ fireworks();
59
+ ```
60
+
61
+ ** Async Way, best practice **
62
+
63
+ ```javascript
64
+ (async () => {
65
+ await fireworks();
66
+ })();
67
+ ```
68
+
69
+ ** Fireworks Options **
70
+
71
+ ```javascript
72
+ fireworks({
73
+ colors: ["#ffffff", "#ff0000"],
74
+ });
75
+ ```
76
+
77
+ #### Options
78
+
79
+ The `fireworks` has only a single `options` object parameter, with the following properties:
80
+
81
+ - `brightness` Number or { min: number; max: number; }: The brightness offset applied to the particles color, from -100
82
+ to 100.
83
+ - `colors` String or _Array<String>_: An array of color strings, in the HEX format... you know, like `#bada55`.
84
+ - `gravity` Number or { min: number; max: number; }: The gravity applied to the fireworks particles.
85
+ - `minHeight` Number or { min: number; max: number; }: The minimum height for fireworks explosions (the lesser, the
86
+ higher).
87
+ - `rate` Number or { min: number; max: number; }: The rate of the fireworks explosions.
88
+ - `saturation` Number or { min: number; max: number; }: The saturation offset applied to the particles color, from -100
89
+ to 100.
90
+ - `sounds` Boolean: Whether to play sounds or not.
91
+ - `speed` Number or { min: number; max: number; }: The speed of the fireworks particles.
92
+ - `splitCount` Number or { min: number; max: number; }: The number of particles to split the emitter in.
@@ -0,0 +1,63 @@
1
+ import { isArray, setRangeValue, } from "@tsparticles/engine";
2
+ export class FireworkOptions {
3
+ constructor() {
4
+ this.brightness = {
5
+ min: -30,
6
+ max: 30,
7
+ };
8
+ this.colors = ["#ff595e", "#ffca3a", "#8ac926", "#1982c4", "#6a4c93"];
9
+ this.gravity = 5;
10
+ this.minHeight = {
11
+ min: 10,
12
+ max: 30,
13
+ };
14
+ this.rate = 20;
15
+ this.saturation = {
16
+ min: -30,
17
+ max: 30,
18
+ };
19
+ this.sounds = true;
20
+ this.speed = { min: 5, max: 15 };
21
+ this.splitCount = {
22
+ min: 75,
23
+ max: 150,
24
+ };
25
+ }
26
+ load(data) {
27
+ if (!data) {
28
+ return;
29
+ }
30
+ if (data.colors !== undefined) {
31
+ if (isArray(data.colors)) {
32
+ this.colors = [...data.colors];
33
+ }
34
+ else {
35
+ this.colors = data.colors;
36
+ }
37
+ }
38
+ if (data.brightness !== undefined) {
39
+ this.brightness = setRangeValue(data.brightness);
40
+ }
41
+ if (data.gravity !== undefined) {
42
+ this.gravity = setRangeValue(data.gravity);
43
+ }
44
+ if (data.minHeight !== undefined) {
45
+ this.minHeight = setRangeValue(data.minHeight);
46
+ }
47
+ if (data.rate !== undefined) {
48
+ this.rate = setRangeValue(data.rate);
49
+ }
50
+ if (data.saturation !== undefined) {
51
+ this.saturation = setRangeValue(data.saturation);
52
+ }
53
+ if (data.sounds !== undefined) {
54
+ this.sounds = data.sounds;
55
+ }
56
+ if (data.speed !== undefined) {
57
+ this.speed = setRangeValue(data.speed);
58
+ }
59
+ if (data.splitCount !== undefined) {
60
+ this.splitCount = setRangeValue(data.splitCount);
61
+ }
62
+ }
63
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from ".";
2
+ export * from "@tsparticles/engine";
@@ -0,0 +1,264 @@
1
+ import { getRangeMax, getRangeMin, isNumber, isSsr, isString, setRangeValue, tsParticles, } from "@tsparticles/engine";
2
+ import { FireworkOptions } from "./FireworkOptions";
3
+ import { loadBasic } from "@tsparticles/basic";
4
+ import { loadDestroyUpdater } from "@tsparticles/updater-destroy";
5
+ import { loadEmittersPlugin } from "@tsparticles/plugin-emitters";
6
+ import { loadLifeUpdater } from "@tsparticles/updater-life";
7
+ import { loadLineShape } from "@tsparticles/shape-line";
8
+ import { loadRotateUpdater } from "@tsparticles/updater-rotate";
9
+ import { loadSoundsPlugin } from "@tsparticles/plugin-sounds";
10
+ import { loadStrokeColorUpdater } from "@tsparticles/updater-stroke-color";
11
+ let initialized = false;
12
+ let initializing = false;
13
+ const explodeSoundCheck = (args) => {
14
+ const data = args.data;
15
+ return data.particle.shape === "line";
16
+ };
17
+ class FireworksInstance {
18
+ constructor(container) {
19
+ this._container = container;
20
+ }
21
+ pause() {
22
+ this._container.pause();
23
+ }
24
+ play() {
25
+ this._container.play();
26
+ }
27
+ stop() {
28
+ this._container.stop();
29
+ }
30
+ }
31
+ async function initPlugins() {
32
+ if (initialized) {
33
+ return;
34
+ }
35
+ if (initializing) {
36
+ return new Promise((resolve) => {
37
+ const interval = setInterval(() => {
38
+ if (!initialized) {
39
+ return;
40
+ }
41
+ clearInterval(interval);
42
+ resolve();
43
+ }, 100);
44
+ });
45
+ }
46
+ initializing = true;
47
+ await loadEmittersPlugin(tsParticles, false);
48
+ await loadSoundsPlugin(tsParticles, false);
49
+ await loadLineShape(tsParticles, false);
50
+ await loadRotateUpdater(tsParticles, false);
51
+ await loadDestroyUpdater(tsParticles, false);
52
+ await loadLifeUpdater(tsParticles, false);
53
+ await loadStrokeColorUpdater(tsParticles, false);
54
+ await loadBasic(tsParticles, false);
55
+ initializing = false;
56
+ initialized = true;
57
+ }
58
+ export async function fireworks(idOrOptions, sourceOptions) {
59
+ await initPlugins();
60
+ let id;
61
+ const options = new FireworkOptions();
62
+ if (isString(idOrOptions)) {
63
+ id = idOrOptions;
64
+ options.load(sourceOptions);
65
+ }
66
+ else {
67
+ id = "fireworks";
68
+ options.load(idOrOptions);
69
+ }
70
+ const particlesOptions = {
71
+ detectRetina: true,
72
+ background: {
73
+ color: "#000",
74
+ },
75
+ fpsLimit: 120,
76
+ emitters: {
77
+ direction: "top",
78
+ life: {
79
+ count: 0,
80
+ duration: 0.1,
81
+ delay: 0.1,
82
+ },
83
+ rate: {
84
+ delay: isNumber(options.rate)
85
+ ? 1 / options.rate
86
+ : { min: 1 / getRangeMin(options.rate), max: 1 / getRangeMax(options.rate) },
87
+ quantity: 1,
88
+ },
89
+ size: {
90
+ width: 100,
91
+ height: 0,
92
+ },
93
+ position: {
94
+ y: 100,
95
+ x: 50,
96
+ },
97
+ },
98
+ particles: {
99
+ number: {
100
+ value: 0,
101
+ },
102
+ color: {
103
+ value: options.colors,
104
+ },
105
+ destroy: {
106
+ mode: "split",
107
+ bounds: {
108
+ top: setRangeValue(options.minHeight),
109
+ },
110
+ split: {
111
+ sizeOffset: false,
112
+ count: 1,
113
+ factor: {
114
+ value: 0.333333,
115
+ },
116
+ rate: {
117
+ value: options.splitCount,
118
+ },
119
+ colorOffset: {
120
+ s: options.saturation,
121
+ l: options.brightness,
122
+ },
123
+ particles: {
124
+ stroke: {
125
+ width: 0,
126
+ },
127
+ number: {
128
+ value: 0,
129
+ },
130
+ opacity: {
131
+ value: {
132
+ min: 0.1,
133
+ max: 1,
134
+ },
135
+ animation: {
136
+ enable: true,
137
+ speed: 0.7,
138
+ sync: false,
139
+ startValue: "max",
140
+ destroy: "min",
141
+ },
142
+ },
143
+ shape: {
144
+ type: "circle",
145
+ },
146
+ size: {
147
+ value: { min: 1, max: 2 },
148
+ animation: {
149
+ enable: true,
150
+ speed: 5,
151
+ count: 1,
152
+ sync: false,
153
+ startValue: "min",
154
+ destroy: "none",
155
+ },
156
+ },
157
+ life: {
158
+ count: 1,
159
+ duration: {
160
+ value: {
161
+ min: 0.25,
162
+ max: 0.5,
163
+ },
164
+ },
165
+ },
166
+ move: {
167
+ decay: { min: 0.05, max: 0.1 },
168
+ enable: true,
169
+ gravity: {
170
+ enable: true,
171
+ inverse: false,
172
+ acceleration: setRangeValue(options.gravity),
173
+ },
174
+ speed: setRangeValue(options.speed),
175
+ direction: "none",
176
+ outModes: "destroy",
177
+ },
178
+ },
179
+ },
180
+ },
181
+ life: {
182
+ count: 1,
183
+ },
184
+ shape: {
185
+ type: "line",
186
+ options: {
187
+ line: {
188
+ cap: "round",
189
+ },
190
+ },
191
+ },
192
+ size: {
193
+ value: {
194
+ min: 0.1,
195
+ max: 50,
196
+ },
197
+ animation: {
198
+ enable: true,
199
+ sync: true,
200
+ speed: 90,
201
+ startValue: "max",
202
+ destroy: "min",
203
+ },
204
+ },
205
+ stroke: {
206
+ color: {
207
+ value: "#ffffff",
208
+ },
209
+ width: 0.5,
210
+ },
211
+ rotate: {
212
+ path: true,
213
+ },
214
+ move: {
215
+ enable: true,
216
+ gravity: {
217
+ acceleration: 15,
218
+ enable: true,
219
+ inverse: true,
220
+ maxSpeed: 100,
221
+ },
222
+ speed: {
223
+ min: 10,
224
+ max: 20,
225
+ },
226
+ outModes: {
227
+ default: "destroy",
228
+ top: "none",
229
+ },
230
+ trail: {
231
+ fill: {
232
+ color: "#000",
233
+ },
234
+ enable: true,
235
+ length: 10,
236
+ },
237
+ },
238
+ },
239
+ sounds: {
240
+ enable: options.sounds,
241
+ events: [
242
+ {
243
+ event: "particleRemoved",
244
+ filter: explodeSoundCheck,
245
+ audio: [
246
+ "https://particles.js.org/audio/explosion0.mp3",
247
+ "https://particles.js.org/audio/explosion1.mp3",
248
+ "https://particles.js.org/audio/explosion2.mp3",
249
+ ],
250
+ },
251
+ ],
252
+ volume: 50,
253
+ },
254
+ };
255
+ const container = await tsParticles.load({ id, options: particlesOptions });
256
+ if (!container) {
257
+ return;
258
+ }
259
+ return new FireworksInstance(container);
260
+ }
261
+ fireworks.version = tsParticles.version;
262
+ if (!isSsr()) {
263
+ window.fireworks = fireworks;
264
+ }
@@ -0,0 +1 @@
1
+ export * from "./fireworks";
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FireworkOptions = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ class FireworkOptions {
6
+ constructor() {
7
+ this.brightness = {
8
+ min: -30,
9
+ max: 30,
10
+ };
11
+ this.colors = ["#ff595e", "#ffca3a", "#8ac926", "#1982c4", "#6a4c93"];
12
+ this.gravity = 5;
13
+ this.minHeight = {
14
+ min: 10,
15
+ max: 30,
16
+ };
17
+ this.rate = 20;
18
+ this.saturation = {
19
+ min: -30,
20
+ max: 30,
21
+ };
22
+ this.sounds = true;
23
+ this.speed = { min: 5, max: 15 };
24
+ this.splitCount = {
25
+ min: 75,
26
+ max: 150,
27
+ };
28
+ }
29
+ load(data) {
30
+ if (!data) {
31
+ return;
32
+ }
33
+ if (data.colors !== undefined) {
34
+ if ((0, engine_1.isArray)(data.colors)) {
35
+ this.colors = [...data.colors];
36
+ }
37
+ else {
38
+ this.colors = data.colors;
39
+ }
40
+ }
41
+ if (data.brightness !== undefined) {
42
+ this.brightness = (0, engine_1.setRangeValue)(data.brightness);
43
+ }
44
+ if (data.gravity !== undefined) {
45
+ this.gravity = (0, engine_1.setRangeValue)(data.gravity);
46
+ }
47
+ if (data.minHeight !== undefined) {
48
+ this.minHeight = (0, engine_1.setRangeValue)(data.minHeight);
49
+ }
50
+ if (data.rate !== undefined) {
51
+ this.rate = (0, engine_1.setRangeValue)(data.rate);
52
+ }
53
+ if (data.saturation !== undefined) {
54
+ this.saturation = (0, engine_1.setRangeValue)(data.saturation);
55
+ }
56
+ if (data.sounds !== undefined) {
57
+ this.sounds = data.sounds;
58
+ }
59
+ if (data.speed !== undefined) {
60
+ this.speed = (0, engine_1.setRangeValue)(data.speed);
61
+ }
62
+ if (data.splitCount !== undefined) {
63
+ this.splitCount = (0, engine_1.setRangeValue)(data.splitCount);
64
+ }
65
+ }
66
+ }
67
+ exports.FireworkOptions = FireworkOptions;
@@ -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);