@tsparticles/preset-fireworks 3.0.2 → 3.2.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/cjs/options.js CHANGED
@@ -1,214 +1,221 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.options = void 0;
3
+ exports.initOptions = void 0;
4
4
  const engine_1 = require("@tsparticles/engine");
5
- const explodeSoundCheck = (args) => {
6
- const data = args.data;
7
- return data.particle.shape === "line";
8
- };
9
- const fixRange = (value, min, max) => {
10
- const minValue = 0, diffSMax = value.max > max ? value.max - max : minValue;
11
- let res = (0, engine_1.setRangeValue)(value);
12
- if (diffSMax) {
13
- res = (0, engine_1.setRangeValue)(value.min - diffSMax, max);
14
- }
15
- const diffSMin = value.min < min ? value.min : minValue;
16
- if (diffSMin) {
17
- res = (0, engine_1.setRangeValue)(minValue, value.max + diffSMin);
18
- }
19
- return res;
20
- };
21
- const fireworksOptions = ["#ff595e", "#ffca3a", "#8ac926", "#1982c4", "#6a4c93"]
22
- .map((color) => {
23
- const rgb = (0, engine_1.stringToRgb)(color);
24
- if (!rgb) {
25
- return undefined;
26
- }
27
- const hsl = (0, engine_1.rgbToHsl)(rgb), sOffset = 30, lOffset = 30, sBounds = {
28
- min: 0,
29
- max: 100,
30
- }, lBounds = {
31
- min: 0,
32
- max: 100,
33
- }, sRange = fixRange({ min: hsl.s - sOffset, max: hsl.s + sOffset }, sBounds.min, sBounds.max), lRange = fixRange({ min: hsl.l - lOffset, max: hsl.l + lOffset }, lBounds.min, lBounds.max);
34
- return {
35
- color: {
36
- value: {
37
- h: hsl.h,
38
- s: sRange,
39
- l: lRange,
40
- },
41
- },
42
- stroke: {
43
- width: 0,
44
- },
45
- number: {
46
- value: 0,
47
- },
48
- opacity: {
49
- value: {
50
- min: 0.1,
51
- max: 1,
5
+ function initOptions(engine) {
6
+ const explodeSoundCheck = (args) => {
7
+ const data = args.data;
8
+ return data.particle.shape === "line";
9
+ }, fixRange = (value, min, max) => {
10
+ const minValue = 0, diffSMax = value.max > max ? value.max - max : minValue;
11
+ let res = (0, engine_1.setRangeValue)(value);
12
+ if (diffSMax) {
13
+ res = (0, engine_1.setRangeValue)(value.min - diffSMax, max);
14
+ }
15
+ const diffSMin = value.min < min ? value.min : minValue;
16
+ if (diffSMin) {
17
+ res = (0, engine_1.setRangeValue)(minValue, value.max + diffSMin);
18
+ }
19
+ return res;
20
+ }, fireworksOptions = [
21
+ "#ff595e",
22
+ "#ffca3a",
23
+ "#8ac926",
24
+ "#1982c4",
25
+ "#6a4c93",
26
+ ]
27
+ .map(color => {
28
+ const rgb = (0, engine_1.stringToRgb)(engine, color);
29
+ if (!rgb) {
30
+ return undefined;
31
+ }
32
+ const hsl = (0, engine_1.rgbToHsl)(rgb), sOffset = 30, lOffset = 30, sBounds = {
33
+ min: 0,
34
+ max: 100,
35
+ }, lBounds = {
36
+ min: 0,
37
+ max: 100,
38
+ }, sRange = fixRange({ min: hsl.s - sOffset, max: hsl.s + sOffset }, sBounds.min, sBounds.max), lRange = fixRange({ min: hsl.l - lOffset, max: hsl.l + lOffset }, lBounds.min, lBounds.max);
39
+ return {
40
+ color: {
41
+ value: {
42
+ h: hsl.h,
43
+ s: sRange,
44
+ l: lRange,
45
+ },
52
46
  },
53
- animation: {
54
- enable: true,
55
- speed: 0.7,
56
- sync: false,
57
- startValue: "max",
58
- destroy: "min",
47
+ stroke: {
48
+ width: 0,
59
49
  },
60
- },
61
- shape: {
62
- type: "circle",
63
- },
64
- size: {
65
- value: { min: 1, max: 2 },
66
- animation: {
67
- enable: true,
68
- speed: 5,
69
- count: 1,
70
- sync: false,
71
- startValue: "min",
72
- destroy: "none",
50
+ number: {
51
+ value: 0,
73
52
  },
74
- },
75
- life: {
76
- count: 1,
77
- duration: {
53
+ opacity: {
78
54
  value: {
79
- min: 1,
80
- max: 2,
55
+ min: 0.1,
56
+ max: 1,
57
+ },
58
+ animation: {
59
+ enable: true,
60
+ speed: 0.7,
61
+ sync: false,
62
+ startValue: engine_1.StartValueType.max,
63
+ destroy: engine_1.DestroyType.min,
81
64
  },
82
65
  },
83
- },
84
- move: {
85
- decay: { min: 0.075, max: 0.1 },
86
- enable: true,
87
- gravity: {
88
- enable: true,
89
- inverse: false,
90
- acceleration: 5,
91
- },
92
- speed: { min: 5, max: 15 },
93
- direction: "none",
94
- outModes: "destroy",
95
- },
96
- };
97
- })
98
- .filter((t) => t !== undefined);
99
- exports.options = {
100
- detectRetina: true,
101
- background: {
102
- color: "#000",
103
- },
104
- fpsLimit: 120,
105
- emitters: {
106
- direction: "top",
107
- life: {
108
- count: 0,
109
- duration: 0.1,
110
- delay: 0.1,
111
- },
112
- rate: {
113
- delay: 0.05,
114
- quantity: 1,
115
- },
116
- size: {
117
- width: 100,
118
- height: 0,
119
- },
120
- position: {
121
- y: 100,
122
- x: 50,
123
- },
124
- },
125
- particles: {
126
- number: {
127
- value: 0,
128
- },
129
- destroy: {
130
- mode: "split",
131
- bounds: {
132
- top: { min: 10, max: 30 },
66
+ shape: {
67
+ type: "circle",
68
+ },
69
+ size: {
70
+ value: { min: 1, max: 2 },
71
+ animation: {
72
+ enable: true,
73
+ speed: 5,
74
+ count: 1,
75
+ sync: false,
76
+ startValue: engine_1.StartValueType.min,
77
+ destroy: engine_1.DestroyType.none,
78
+ },
133
79
  },
134
- split: {
135
- sizeOffset: false,
80
+ life: {
136
81
  count: 1,
137
- factor: {
138
- value: 0.333333,
139
- },
140
- rate: {
141
- value: { min: 75, max: 150 },
82
+ duration: {
83
+ value: {
84
+ min: 1,
85
+ max: 2,
86
+ },
142
87
  },
143
- particles: fireworksOptions,
144
88
  },
145
- },
146
- life: {
147
- count: 1,
148
- },
149
- shape: {
150
- type: "line",
151
- },
152
- size: {
153
- value: {
154
- min: 0.1,
155
- max: 50,
156
- },
157
- animation: {
89
+ move: {
90
+ decay: { min: 0.075, max: 0.1 },
158
91
  enable: true,
159
- sync: true,
160
- speed: 90,
161
- startValue: "max",
162
- destroy: "min",
92
+ gravity: {
93
+ enable: true,
94
+ inverse: false,
95
+ acceleration: 5,
96
+ },
97
+ speed: { min: 5, max: 15 },
98
+ direction: "none",
99
+ outModes: engine_1.OutMode.destroy,
163
100
  },
164
- },
165
- stroke: {
166
- color: {
167
- value: "#ffffff",
101
+ };
102
+ })
103
+ .filter(t => t !== undefined);
104
+ return {
105
+ detectRetina: true,
106
+ background: {
107
+ color: "#000",
108
+ },
109
+ fpsLimit: 120,
110
+ emitters: {
111
+ direction: engine_1.MoveDirection.top,
112
+ life: {
113
+ count: 0,
114
+ duration: 0.1,
115
+ delay: 0.1,
116
+ },
117
+ rate: {
118
+ delay: 0.05,
119
+ quantity: 1,
120
+ },
121
+ size: {
122
+ width: 100,
123
+ height: 0,
124
+ },
125
+ position: {
126
+ y: 100,
127
+ x: 50,
128
+ },
129
+ },
130
+ particles: {
131
+ number: {
132
+ value: 0,
133
+ },
134
+ destroy: {
135
+ mode: "split",
136
+ bounds: {
137
+ top: { min: 10, max: 30 },
138
+ },
139
+ split: {
140
+ sizeOffset: false,
141
+ count: 1,
142
+ factor: {
143
+ value: 0.333333,
144
+ },
145
+ rate: {
146
+ value: { min: 75, max: 150 },
147
+ },
148
+ particles: fireworksOptions,
149
+ },
168
150
  },
169
- width: 1,
170
- },
171
- rotate: {
172
- path: true,
173
- },
174
- move: {
175
- enable: true,
176
- gravity: {
177
- acceleration: 15,
178
- enable: true,
179
- inverse: true,
180
- maxSpeed: 100,
151
+ life: {
152
+ count: 1,
181
153
  },
182
- speed: {
183
- min: 10,
184
- max: 20,
154
+ shape: {
155
+ type: "line",
185
156
  },
186
- outModes: {
187
- default: "destroy",
188
- top: "none",
157
+ size: {
158
+ value: {
159
+ min: 0.1,
160
+ max: 50,
161
+ },
162
+ animation: {
163
+ enable: true,
164
+ sync: true,
165
+ speed: 90,
166
+ startValue: engine_1.StartValueType.max,
167
+ destroy: engine_1.DestroyType.min,
168
+ },
189
169
  },
190
- trail: {
191
- fill: {
192
- color: "#000",
170
+ stroke: {
171
+ color: {
172
+ value: "#ffffff",
193
173
  },
174
+ width: 1,
175
+ },
176
+ rotate: {
177
+ path: true,
178
+ },
179
+ move: {
194
180
  enable: true,
195
- length: 10,
181
+ gravity: {
182
+ acceleration: 15,
183
+ enable: true,
184
+ inverse: true,
185
+ maxSpeed: 100,
186
+ },
187
+ speed: {
188
+ min: 10,
189
+ max: 20,
190
+ },
191
+ outModes: {
192
+ default: engine_1.OutMode.destroy,
193
+ top: engine_1.OutMode.none,
194
+ },
195
+ trail: {
196
+ fill: {
197
+ color: "#000",
198
+ },
199
+ enable: true,
200
+ length: 10,
201
+ },
196
202
  },
197
203
  },
198
- },
199
- sounds: {
200
- enable: true,
201
- events: [
202
- {
203
- event: "particleRemoved",
204
- filter: explodeSoundCheck,
205
- audio: [
206
- "https://particles.js.org/audio/explosion0.mp3",
207
- "https://particles.js.org/audio/explosion1.mp3",
208
- "https://particles.js.org/audio/explosion2.mp3",
209
- ],
210
- },
211
- ],
212
- volume: 50,
213
- },
214
- };
204
+ sounds: {
205
+ enable: true,
206
+ events: [
207
+ {
208
+ event: engine_1.EventType.particleRemoved,
209
+ filter: explodeSoundCheck,
210
+ audio: [
211
+ "https://particles.js.org/audio/explosion0.mp3",
212
+ "https://particles.js.org/audio/explosion1.mp3",
213
+ "https://particles.js.org/audio/explosion2.mp3",
214
+ ],
215
+ },
216
+ ],
217
+ volume: 50,
218
+ },
219
+ };
220
+ }
221
+ exports.initOptions = initOptions;
package/esm/bundle.js CHANGED
@@ -1,4 +1,3 @@
1
1
  import { loadFireworksPreset } from "./index.js";
2
2
  import { tsParticles } from "@tsparticles/engine";
3
- void loadFireworksPreset(tsParticles);
4
3
  export { loadFireworksPreset, tsParticles };
package/esm/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { initOptions } from "./options.js";
1
2
  import { loadBasic } from "@tsparticles/basic";
2
3
  import { loadDestroyUpdater } from "@tsparticles/updater-destroy";
3
4
  import { loadEmittersPlugin } from "@tsparticles/plugin-emitters";
@@ -7,7 +8,6 @@ import { loadLineShape } from "@tsparticles/shape-line";
7
8
  import { loadRotateUpdater } from "@tsparticles/updater-rotate";
8
9
  import { loadSoundsPlugin } from "@tsparticles/plugin-sounds";
9
10
  import { loadStrokeColorUpdater } from "@tsparticles/updater-stroke-color";
10
- import { options } from "./options.js";
11
11
  export async function loadFireworksPreset(engine, refresh = true) {
12
12
  await loadBasic(engine, false);
13
13
  await loadEmittersPlugin(engine, false);
@@ -18,5 +18,6 @@ export async function loadFireworksPreset(engine, refresh = true) {
18
18
  await loadDestroyUpdater(engine, false);
19
19
  await loadLifeUpdater(engine, false);
20
20
  await loadStrokeColorUpdater(engine, false);
21
- await engine.addPreset("fireworks", options, refresh);
21
+ await engine.addPreset("fireworks", initOptions(engine), false);
22
+ await engine.refresh(refresh);
22
23
  }