@tsparticles/plugin-emitters 3.0.0-alpha.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.
Files changed (107) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +70 -0
  3. package/browser/EmitterContainer.js +1 -0
  4. package/browser/EmitterInstance.js +257 -0
  5. package/browser/Emitters.js +119 -0
  6. package/browser/EmittersEngine.js +1 -0
  7. package/browser/Enums/EmitterClickMode.js +1 -0
  8. package/browser/Enums/EmitterShapeType.js +1 -0
  9. package/browser/IEmitterShape.js +1 -0
  10. package/browser/Options/Classes/Emitter.js +62 -0
  11. package/browser/Options/Classes/EmitterLife.js +22 -0
  12. package/browser/Options/Classes/EmitterRate.js +18 -0
  13. package/browser/Options/Classes/EmitterSize.js +21 -0
  14. package/browser/Options/Interfaces/IEmitter.js +1 -0
  15. package/browser/Options/Interfaces/IEmitterLife.js +1 -0
  16. package/browser/Options/Interfaces/IEmitterRate.js +1 -0
  17. package/browser/Options/Interfaces/IEmitterSize.js +1 -0
  18. package/browser/ShapeManager.js +17 -0
  19. package/browser/Shapes/Circle/CircleShape.js +24 -0
  20. package/browser/Shapes/Square/SquareShape.js +40 -0
  21. package/browser/index.js +113 -0
  22. package/browser/types.js +1 -0
  23. package/cjs/EmitterContainer.js +2 -0
  24. package/cjs/EmitterInstance.js +261 -0
  25. package/cjs/Emitters.js +134 -0
  26. package/cjs/EmittersEngine.js +2 -0
  27. package/cjs/Enums/EmitterClickMode.js +2 -0
  28. package/cjs/Enums/EmitterShapeType.js +2 -0
  29. package/cjs/IEmitterShape.js +2 -0
  30. package/cjs/Options/Classes/Emitter.js +66 -0
  31. package/cjs/Options/Classes/EmitterLife.js +26 -0
  32. package/cjs/Options/Classes/EmitterRate.js +22 -0
  33. package/cjs/Options/Classes/EmitterSize.js +25 -0
  34. package/cjs/Options/Interfaces/IEmitter.js +2 -0
  35. package/cjs/Options/Interfaces/IEmitterLife.js +2 -0
  36. package/cjs/Options/Interfaces/IEmitterRate.js +2 -0
  37. package/cjs/Options/Interfaces/IEmitterSize.js +2 -0
  38. package/cjs/ShapeManager.js +21 -0
  39. package/cjs/Shapes/Circle/CircleShape.js +28 -0
  40. package/cjs/Shapes/Square/SquareShape.js +44 -0
  41. package/cjs/index.js +142 -0
  42. package/cjs/types.js +2 -0
  43. package/esm/EmitterContainer.js +1 -0
  44. package/esm/EmitterInstance.js +257 -0
  45. package/esm/Emitters.js +119 -0
  46. package/esm/EmittersEngine.js +1 -0
  47. package/esm/Enums/EmitterClickMode.js +1 -0
  48. package/esm/Enums/EmitterShapeType.js +1 -0
  49. package/esm/IEmitterShape.js +1 -0
  50. package/esm/Options/Classes/Emitter.js +62 -0
  51. package/esm/Options/Classes/EmitterLife.js +22 -0
  52. package/esm/Options/Classes/EmitterRate.js +18 -0
  53. package/esm/Options/Classes/EmitterSize.js +21 -0
  54. package/esm/Options/Interfaces/IEmitter.js +1 -0
  55. package/esm/Options/Interfaces/IEmitterLife.js +1 -0
  56. package/esm/Options/Interfaces/IEmitterRate.js +1 -0
  57. package/esm/Options/Interfaces/IEmitterSize.js +1 -0
  58. package/esm/ShapeManager.js +17 -0
  59. package/esm/Shapes/Circle/CircleShape.js +24 -0
  60. package/esm/Shapes/Square/SquareShape.js +40 -0
  61. package/esm/index.js +113 -0
  62. package/esm/types.js +1 -0
  63. package/package.json +81 -0
  64. package/report.html +39 -0
  65. package/tsparticles.plugin.emitters.js +794 -0
  66. package/tsparticles.plugin.emitters.min.js +2 -0
  67. package/tsparticles.plugin.emitters.min.js.LICENSE.txt +8 -0
  68. package/types/EmitterContainer.d.ts +12 -0
  69. package/types/EmitterInstance.d.ts +46 -0
  70. package/types/Emitters.d.ts +24 -0
  71. package/types/EmittersEngine.d.ts +7 -0
  72. package/types/Enums/EmitterClickMode.d.ts +3 -0
  73. package/types/Enums/EmitterShapeType.d.ts +4 -0
  74. package/types/IEmitterShape.d.ts +4 -0
  75. package/types/Options/Classes/Emitter.d.ts +24 -0
  76. package/types/Options/Classes/EmitterLife.d.ts +10 -0
  77. package/types/Options/Classes/EmitterRate.d.ts +8 -0
  78. package/types/Options/Classes/EmitterSize.d.ts +10 -0
  79. package/types/Options/Interfaces/IEmitter.d.ts +20 -0
  80. package/types/Options/Interfaces/IEmitterLife.d.ts +6 -0
  81. package/types/Options/Interfaces/IEmitterRate.d.ts +5 -0
  82. package/types/Options/Interfaces/IEmitterSize.d.ts +4 -0
  83. package/types/ShapeManager.d.ts +9 -0
  84. package/types/Shapes/Circle/CircleShape.d.ts +5 -0
  85. package/types/Shapes/Square/SquareShape.d.ts +5 -0
  86. package/types/index.d.ts +6 -0
  87. package/types/types.d.ts +31 -0
  88. package/umd/EmitterContainer.js +12 -0
  89. package/umd/EmitterInstance.js +271 -0
  90. package/umd/Emitters.js +133 -0
  91. package/umd/EmittersEngine.js +12 -0
  92. package/umd/Enums/EmitterClickMode.js +12 -0
  93. package/umd/Enums/EmitterShapeType.js +12 -0
  94. package/umd/IEmitterShape.js +12 -0
  95. package/umd/Options/Classes/Emitter.js +76 -0
  96. package/umd/Options/Classes/EmitterLife.js +36 -0
  97. package/umd/Options/Classes/EmitterRate.js +32 -0
  98. package/umd/Options/Classes/EmitterSize.js +35 -0
  99. package/umd/Options/Interfaces/IEmitter.js +12 -0
  100. package/umd/Options/Interfaces/IEmitterLife.js +12 -0
  101. package/umd/Options/Interfaces/IEmitterRate.js +12 -0
  102. package/umd/Options/Interfaces/IEmitterSize.js +12 -0
  103. package/umd/ShapeManager.js +31 -0
  104. package/umd/Shapes/Circle/CircleShape.js +38 -0
  105. package/umd/Shapes/Square/SquareShape.js +54 -0
  106. package/umd/index.js +141 -0
  107. package/umd/types.js +12 -0
@@ -0,0 +1,794 @@
1
+ /*!
2
+ * Author : Matteo Bruni
3
+ * MIT license: https://opensource.org/licenses/MIT
4
+ * Demo / Generator : https://particles.js.org/
5
+ * GitHub : https://www.github.com/matteobruni/tsparticles
6
+ * How to use? : Check the GitHub README
7
+ * v3.0.0-alpha.0
8
+ */
9
+ (function webpackUniversalModuleDefinition(root, factory) {
10
+ if(typeof exports === 'object' && typeof module === 'object')
11
+ module.exports = factory(require("@tsparticles/engine"));
12
+ else if(typeof define === 'function' && define.amd)
13
+ define(["@tsparticles/engine"], factory);
14
+ else {
15
+ var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]);
16
+ for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
17
+ }
18
+ })(this, (__WEBPACK_EXTERNAL_MODULE__533__) => {
19
+ return /******/ (() => { // webpackBootstrap
20
+ /******/ "use strict";
21
+ /******/ var __webpack_modules__ = ({
22
+
23
+ /***/ 533:
24
+ /***/ ((module) => {
25
+
26
+ module.exports = __WEBPACK_EXTERNAL_MODULE__533__;
27
+
28
+ /***/ })
29
+
30
+ /******/ });
31
+ /************************************************************************/
32
+ /******/ // The module cache
33
+ /******/ var __webpack_module_cache__ = {};
34
+ /******/
35
+ /******/ // The require function
36
+ /******/ function __webpack_require__(moduleId) {
37
+ /******/ // Check if module is in cache
38
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
39
+ /******/ if (cachedModule !== undefined) {
40
+ /******/ return cachedModule.exports;
41
+ /******/ }
42
+ /******/ // Create a new module (and put it into the cache)
43
+ /******/ var module = __webpack_module_cache__[moduleId] = {
44
+ /******/ // no module.id needed
45
+ /******/ // no module.loaded needed
46
+ /******/ exports: {}
47
+ /******/ };
48
+ /******/
49
+ /******/ // Execute the module function
50
+ /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
51
+ /******/
52
+ /******/ // Return the exports of the module
53
+ /******/ return module.exports;
54
+ /******/ }
55
+ /******/
56
+ /************************************************************************/
57
+ /******/ /* webpack/runtime/define property getters */
58
+ /******/ (() => {
59
+ /******/ // define getter functions for harmony exports
60
+ /******/ __webpack_require__.d = (exports, definition) => {
61
+ /******/ for(var key in definition) {
62
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
63
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
64
+ /******/ }
65
+ /******/ }
66
+ /******/ };
67
+ /******/ })();
68
+ /******/
69
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
70
+ /******/ (() => {
71
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
72
+ /******/ })();
73
+ /******/
74
+ /******/ /* webpack/runtime/make namespace object */
75
+ /******/ (() => {
76
+ /******/ // define __esModule on exports
77
+ /******/ __webpack_require__.r = (exports) => {
78
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
79
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
80
+ /******/ }
81
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
82
+ /******/ };
83
+ /******/ })();
84
+ /******/
85
+ /************************************************************************/
86
+ var __webpack_exports__ = {};
87
+ // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
88
+ (() => {
89
+ // ESM COMPAT FLAG
90
+ __webpack_require__.r(__webpack_exports__);
91
+
92
+ // EXPORTS
93
+ __webpack_require__.d(__webpack_exports__, {
94
+ "loadEmittersPlugin": () => (/* binding */ loadEmittersPlugin)
95
+ });
96
+
97
+ // EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
98
+ var engine_root_window_ = __webpack_require__(533);
99
+ ;// CONCATENATED MODULE: ./dist/browser/Shapes/Circle/CircleShape.js
100
+
101
+ class CircleShape {
102
+ randomPosition(position, size, fill) {
103
+ const generateTheta = (x, y) => {
104
+ const u = (0,engine_root_window_.getRandom)() / 4.0,
105
+ theta = Math.atan(y / x * Math.tan(2 * Math.PI * u)),
106
+ v = (0,engine_root_window_.getRandom)();
107
+ if (v < 0.25) {
108
+ return theta;
109
+ } else if (v < 0.5) {
110
+ return Math.PI - theta;
111
+ } else if (v < 0.75) {
112
+ return Math.PI + theta;
113
+ } else {
114
+ return -theta;
115
+ }
116
+ },
117
+ radius = (x, y, theta) => x * y / Math.sqrt((y * Math.cos(theta)) ** 2 + (x * Math.sin(theta)) ** 2),
118
+ [a, b] = [size.width / 2, size.height / 2],
119
+ randomTheta = generateTheta(a, b),
120
+ maxRadius = radius(a, b, randomTheta),
121
+ randomRadius = fill ? maxRadius * Math.sqrt((0,engine_root_window_.getRandom)()) : maxRadius;
122
+ return {
123
+ x: position.x + randomRadius * Math.cos(randomTheta),
124
+ y: position.y + randomRadius * Math.sin(randomTheta)
125
+ };
126
+ }
127
+ }
128
+ ;// CONCATENATED MODULE: ./dist/browser/Options/Classes/EmitterLife.js
129
+ class EmitterLife {
130
+ constructor() {
131
+ this.wait = false;
132
+ }
133
+ load(data) {
134
+ if (data === undefined) {
135
+ return;
136
+ }
137
+ if (data.count !== undefined) {
138
+ this.count = data.count;
139
+ }
140
+ if (data.delay !== undefined) {
141
+ this.delay = data.delay;
142
+ }
143
+ if (data.duration !== undefined) {
144
+ this.duration = data.duration;
145
+ }
146
+ if (data.wait !== undefined) {
147
+ this.wait = data.wait;
148
+ }
149
+ }
150
+ }
151
+ ;// CONCATENATED MODULE: ./dist/browser/Options/Classes/EmitterRate.js
152
+
153
+ class EmitterRate {
154
+ constructor() {
155
+ this.quantity = 1;
156
+ this.delay = 0.1;
157
+ }
158
+ load(data) {
159
+ if (data === undefined) {
160
+ return;
161
+ }
162
+ if (data.quantity !== undefined) {
163
+ this.quantity = (0,engine_root_window_.setRangeValue)(data.quantity);
164
+ }
165
+ if (data.delay !== undefined) {
166
+ this.delay = (0,engine_root_window_.setRangeValue)(data.delay);
167
+ }
168
+ }
169
+ }
170
+ ;// CONCATENATED MODULE: ./dist/browser/Options/Classes/EmitterSize.js
171
+ class EmitterSize {
172
+ constructor() {
173
+ this.mode = "percent";
174
+ this.height = 0;
175
+ this.width = 0;
176
+ }
177
+ load(data) {
178
+ if (data === undefined) {
179
+ return;
180
+ }
181
+ if (data.mode !== undefined) {
182
+ this.mode = data.mode;
183
+ }
184
+ if (data.height !== undefined) {
185
+ this.height = data.height;
186
+ }
187
+ if (data.width !== undefined) {
188
+ this.width = data.width;
189
+ }
190
+ }
191
+ }
192
+ ;// CONCATENATED MODULE: ./dist/browser/Options/Classes/Emitter.js
193
+
194
+
195
+
196
+
197
+ class Emitter {
198
+ constructor() {
199
+ this.autoPlay = true;
200
+ this.fill = true;
201
+ this.life = new EmitterLife();
202
+ this.rate = new EmitterRate();
203
+ this.shape = "square";
204
+ this.startCount = 0;
205
+ }
206
+ load(data) {
207
+ if (data === undefined) {
208
+ return;
209
+ }
210
+ if (data.autoPlay !== undefined) {
211
+ this.autoPlay = data.autoPlay;
212
+ }
213
+ if (data.size !== undefined) {
214
+ if (this.size === undefined) {
215
+ this.size = new EmitterSize();
216
+ }
217
+ this.size.load(data.size);
218
+ }
219
+ if (data.direction !== undefined) {
220
+ this.direction = data.direction;
221
+ }
222
+ this.domId = data.domId;
223
+ if (data.fill !== undefined) {
224
+ this.fill = data.fill;
225
+ }
226
+ this.life.load(data.life);
227
+ this.name = data.name;
228
+ this.particles = (0,engine_root_window_.executeOnSingleOrMultiple)(data.particles, particles => {
229
+ return (0,engine_root_window_.deepExtend)({}, particles);
230
+ });
231
+ this.rate.load(data.rate);
232
+ if (data.shape !== undefined) {
233
+ this.shape = data.shape;
234
+ }
235
+ if (data.position !== undefined) {
236
+ this.position = {};
237
+ if (data.position.x !== undefined) {
238
+ this.position.x = (0,engine_root_window_.setRangeValue)(data.position.x);
239
+ }
240
+ if (data.position.y !== undefined) {
241
+ this.position.y = (0,engine_root_window_.setRangeValue)(data.position.y);
242
+ }
243
+ }
244
+ if (data.spawnColor !== undefined) {
245
+ if (this.spawnColor === undefined) {
246
+ this.spawnColor = new engine_root_window_.AnimatableColor();
247
+ }
248
+ this.spawnColor.load(data.spawnColor);
249
+ }
250
+ if (data.startCount !== undefined) {
251
+ this.startCount = data.startCount;
252
+ }
253
+ }
254
+ }
255
+ ;// CONCATENATED MODULE: ./dist/browser/EmitterInstance.js
256
+
257
+
258
+
259
+ class EmitterInstance {
260
+ constructor(engine, emitters, container, options, position) {
261
+ var _a, _b, _c, _d, _e, _f, _g;
262
+ var _h;
263
+ this.emitters = emitters;
264
+ this.container = container;
265
+ this._engine = engine;
266
+ this._currentDuration = 0;
267
+ this._currentEmitDelay = 0;
268
+ this._currentSpawnDelay = 0;
269
+ this._initialPosition = position;
270
+ if (options instanceof Emitter) {
271
+ this.options = options;
272
+ } else {
273
+ this.options = new Emitter();
274
+ this.options.load(options);
275
+ }
276
+ this._spawnDelay = ((_a = this.options.life.delay) !== null && _a !== void 0 ? _a : 0) * 1000 / this.container.retina.reduceFactor;
277
+ this.position = (_b = this._initialPosition) !== null && _b !== void 0 ? _b : this.calcPosition();
278
+ this.name = this.options.name;
279
+ this._shape = (_c = this._engine.emitterShapeManager) === null || _c === void 0 ? void 0 : _c.getShape(this.options.shape);
280
+ this.fill = this.options.fill;
281
+ this._firstSpawn = !this.options.life.wait;
282
+ this._startParticlesAdded = false;
283
+ let particlesOptions = (0,engine_root_window_.deepExtend)({}, this.options.particles);
284
+ particlesOptions !== null && particlesOptions !== void 0 ? particlesOptions : particlesOptions = {};
285
+ (_d = particlesOptions.move) !== null && _d !== void 0 ? _d : particlesOptions.move = {};
286
+ (_e = (_h = particlesOptions.move).direction) !== null && _e !== void 0 ? _e : _h.direction = this.options.direction;
287
+ if (this.options.spawnColor) {
288
+ this.spawnColor = (0,engine_root_window_.rangeColorToHsl)(this.options.spawnColor);
289
+ }
290
+ this._paused = !this.options.autoPlay;
291
+ this._particlesOptions = particlesOptions;
292
+ this.size = (_f = this.options.size) !== null && _f !== void 0 ? _f : (() => {
293
+ const size = new EmitterSize();
294
+ size.load({
295
+ height: 0,
296
+ mode: "percent",
297
+ width: 0
298
+ });
299
+ return size;
300
+ })();
301
+ this._lifeCount = (_g = this.options.life.count) !== null && _g !== void 0 ? _g : -1;
302
+ this._immortal = this._lifeCount <= 0;
303
+ this._engine.dispatchEvent("emitterCreated", {
304
+ container,
305
+ data: {
306
+ emitter: this
307
+ }
308
+ });
309
+ this.play();
310
+ }
311
+ externalPause() {
312
+ this._paused = true;
313
+ this.pause();
314
+ }
315
+ externalPlay() {
316
+ this._paused = false;
317
+ this.play();
318
+ }
319
+ getPosition() {
320
+ if (this.options.domId) {
321
+ const container = this.container,
322
+ element = document.getElementById(this.options.domId);
323
+ if (element) {
324
+ const elRect = element.getBoundingClientRect();
325
+ return {
326
+ x: (elRect.x + elRect.width / 2) * container.retina.pixelRatio,
327
+ y: (elRect.y + elRect.height / 2) * container.retina.pixelRatio
328
+ };
329
+ }
330
+ }
331
+ return this.position;
332
+ }
333
+ getSize() {
334
+ const container = this.container;
335
+ if (this.options.domId) {
336
+ const element = document.getElementById(this.options.domId);
337
+ if (element) {
338
+ const elRect = element.getBoundingClientRect();
339
+ return {
340
+ width: elRect.width * container.retina.pixelRatio,
341
+ height: elRect.height * container.retina.pixelRatio
342
+ };
343
+ }
344
+ }
345
+ return {
346
+ width: this.size.mode === "percent" ? container.canvas.size.width * this.size.width / 100 : this.size.width,
347
+ height: this.size.mode === "percent" ? container.canvas.size.height * this.size.height / 100 : this.size.height
348
+ };
349
+ }
350
+ pause() {
351
+ if (this._paused) {
352
+ return;
353
+ }
354
+ delete this._emitDelay;
355
+ }
356
+ play() {
357
+ var _a;
358
+ if (this._paused) {
359
+ return;
360
+ }
361
+ if (!(this.container.retina.reduceFactor && (this._lifeCount > 0 || this._immortal || !this.options.life.count) && (this._firstSpawn || this._currentSpawnDelay >= ((_a = this._spawnDelay) !== null && _a !== void 0 ? _a : 0)))) {
362
+ return;
363
+ }
364
+ if (this._emitDelay === undefined) {
365
+ const delay = (0,engine_root_window_.getRangeValue)(this.options.rate.delay);
366
+ this._emitDelay = 1000 * delay / this.container.retina.reduceFactor;
367
+ }
368
+ if (this._lifeCount > 0 || this._immortal) {
369
+ this.prepareToDie();
370
+ }
371
+ }
372
+ resize() {
373
+ const initialPosition = this._initialPosition;
374
+ this.position = initialPosition && (0,engine_root_window_.isPointInside)(initialPosition, this.container.canvas.size, engine_root_window_.Vector.origin) ? initialPosition : this.calcPosition();
375
+ }
376
+ update(delta) {
377
+ var _a, _b, _c;
378
+ if (this._paused) {
379
+ return;
380
+ }
381
+ if (this._firstSpawn) {
382
+ this._firstSpawn = false;
383
+ this._currentSpawnDelay = (_a = this._spawnDelay) !== null && _a !== void 0 ? _a : 0;
384
+ this._currentEmitDelay = (_b = this._emitDelay) !== null && _b !== void 0 ? _b : 0;
385
+ }
386
+ if (!this._startParticlesAdded) {
387
+ this._startParticlesAdded = true;
388
+ this.emitParticles(this.options.startCount);
389
+ }
390
+ if (this._duration !== undefined) {
391
+ this._currentDuration += delta.value;
392
+ if (this._currentDuration >= this._duration) {
393
+ this.pause();
394
+ if (this._spawnDelay !== undefined) {
395
+ delete this._spawnDelay;
396
+ }
397
+ if (!this._immortal) {
398
+ this._lifeCount--;
399
+ }
400
+ if (this._lifeCount > 0 || this._immortal) {
401
+ this.position = this.calcPosition();
402
+ this._spawnDelay = ((_c = this.options.life.delay) !== null && _c !== void 0 ? _c : 0) * 1000 / this.container.retina.reduceFactor;
403
+ } else {
404
+ this.destroy();
405
+ }
406
+ this._currentDuration -= this._duration;
407
+ delete this._duration;
408
+ }
409
+ }
410
+ if (this._spawnDelay !== undefined) {
411
+ this._currentSpawnDelay += delta.value;
412
+ if (this._currentSpawnDelay >= this._spawnDelay) {
413
+ this._engine.dispatchEvent("emitterPlay", {
414
+ container: this.container
415
+ });
416
+ this.play();
417
+ this._currentSpawnDelay -= this._currentSpawnDelay;
418
+ delete this._spawnDelay;
419
+ }
420
+ }
421
+ if (this._emitDelay !== undefined) {
422
+ this._currentEmitDelay += delta.value;
423
+ if (this._currentEmitDelay >= this._emitDelay) {
424
+ this.emit();
425
+ this._currentEmitDelay -= this._emitDelay;
426
+ }
427
+ }
428
+ }
429
+ calcPosition() {
430
+ return (0,engine_root_window_.calcPositionOrRandomFromSizeRanged)({
431
+ size: this.container.canvas.size,
432
+ position: this.options.position
433
+ });
434
+ }
435
+ destroy() {
436
+ this.emitters.removeEmitter(this);
437
+ this._engine.dispatchEvent("emitterDestroyed", {
438
+ container: this.container,
439
+ data: {
440
+ emitter: this
441
+ }
442
+ });
443
+ }
444
+ emit() {
445
+ if (this._paused) {
446
+ return;
447
+ }
448
+ const quantity = (0,engine_root_window_.getRangeValue)(this.options.rate.quantity);
449
+ this.emitParticles(quantity);
450
+ }
451
+ emitParticles(quantity) {
452
+ var _a, _b, _c;
453
+ const position = this.getPosition(),
454
+ size = this.getSize(),
455
+ singleParticlesOptions = (0,engine_root_window_.itemFromSingleOrMultiple)(this._particlesOptions);
456
+ for (let i = 0; i < quantity; i++) {
457
+ const particlesOptions = (0,engine_root_window_.deepExtend)({}, singleParticlesOptions);
458
+ if (this.spawnColor) {
459
+ const hslAnimation = (_a = this.options.spawnColor) === null || _a === void 0 ? void 0 : _a.animation;
460
+ if (hslAnimation) {
461
+ this.spawnColor.h = this.setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
462
+ this.spawnColor.s = this.setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
463
+ this.spawnColor.l = this.setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
464
+ }
465
+ if (!particlesOptions.color) {
466
+ particlesOptions.color = {
467
+ value: this.spawnColor
468
+ };
469
+ } else {
470
+ particlesOptions.color.value = this.spawnColor;
471
+ }
472
+ }
473
+ if (!position) {
474
+ return;
475
+ }
476
+ const pPosition = (_c = (_b = this._shape) === null || _b === void 0 ? void 0 : _b.randomPosition(position, size, this.fill)) !== null && _c !== void 0 ? _c : position;
477
+ this.container.particles.addParticle(pPosition, particlesOptions);
478
+ }
479
+ }
480
+ prepareToDie() {
481
+ var _a;
482
+ if (this._paused) {
483
+ return;
484
+ }
485
+ const duration = (_a = this.options.life) === null || _a === void 0 ? void 0 : _a.duration;
486
+ if (this.container.retina.reduceFactor && (this._lifeCount > 0 || this._immortal) && duration !== undefined && duration > 0) {
487
+ this._duration = duration * 1000;
488
+ }
489
+ }
490
+ setColorAnimation(animation, initValue, maxValue) {
491
+ var _a;
492
+ const container = this.container;
493
+ if (!animation.enable) {
494
+ return initValue;
495
+ }
496
+ const colorOffset = (0,engine_root_window_.randomInRange)(animation.offset),
497
+ delay = (0,engine_root_window_.getRangeValue)(this.options.rate.delay),
498
+ emitFactor = 1000 * delay / container.retina.reduceFactor,
499
+ colorSpeed = (0,engine_root_window_.getRangeValue)((_a = animation.speed) !== null && _a !== void 0 ? _a : 0);
500
+ return (initValue + colorSpeed * container.fpsLimit / emitFactor + colorOffset * 3.6) % maxValue;
501
+ }
502
+ }
503
+ ;// CONCATENATED MODULE: ./dist/browser/Emitters.js
504
+
505
+
506
+
507
+ class Emitters {
508
+ constructor(engine, container) {
509
+ this.container = container;
510
+ this._engine = engine;
511
+ this.array = [];
512
+ this.emitters = [];
513
+ this.interactivityEmitters = {
514
+ random: {
515
+ count: 1,
516
+ enable: false
517
+ },
518
+ value: []
519
+ };
520
+ container.getEmitter = idxOrName => idxOrName === undefined || typeof idxOrName === "number" ? this.array[idxOrName || 0] : this.array.find(t => t.name === idxOrName);
521
+ container.addEmitter = (options, position) => this.addEmitter(options, position);
522
+ container.removeEmitter = idxOrName => {
523
+ const emitter = container.getEmitter(idxOrName);
524
+ if (emitter) {
525
+ this.removeEmitter(emitter);
526
+ }
527
+ };
528
+ container.playEmitter = idxOrName => {
529
+ const emitter = container.getEmitter(idxOrName);
530
+ if (emitter) {
531
+ emitter.externalPlay();
532
+ }
533
+ };
534
+ container.pauseEmitter = idxOrName => {
535
+ const emitter = container.getEmitter(idxOrName);
536
+ if (emitter) {
537
+ emitter.externalPause();
538
+ }
539
+ };
540
+ }
541
+ addEmitter(options, position) {
542
+ const emitterOptions = new Emitter();
543
+ emitterOptions.load(options);
544
+ const emitter = new EmitterInstance(this._engine, this, this.container, emitterOptions, position);
545
+ this.array.push(emitter);
546
+ return emitter;
547
+ }
548
+ handleClickMode(mode) {
549
+ const emitterOptions = this.emitters,
550
+ modeEmitters = this.interactivityEmitters;
551
+ if (mode === "emitter") {
552
+ let emittersModeOptions;
553
+ if (modeEmitters && modeEmitters.value instanceof Array) {
554
+ if (modeEmitters.value.length > 0 && modeEmitters.random.enable) {
555
+ emittersModeOptions = [];
556
+ const usedIndexes = [];
557
+ for (let i = 0; i < modeEmitters.random.count; i++) {
558
+ const idx = (0,engine_root_window_.arrayRandomIndex)(modeEmitters.value);
559
+ if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
560
+ i--;
561
+ continue;
562
+ }
563
+ usedIndexes.push(idx);
564
+ emittersModeOptions.push((0,engine_root_window_.itemFromArray)(modeEmitters.value, idx));
565
+ }
566
+ } else {
567
+ emittersModeOptions = modeEmitters.value;
568
+ }
569
+ } else {
570
+ emittersModeOptions = modeEmitters === null || modeEmitters === void 0 ? void 0 : modeEmitters.value;
571
+ }
572
+ const emittersOptions = emittersModeOptions !== null && emittersModeOptions !== void 0 ? emittersModeOptions : emitterOptions,
573
+ ePosition = this.container.interactivity.mouse.clickPosition;
574
+ (0,engine_root_window_.executeOnSingleOrMultiple)(emittersOptions, emitter => {
575
+ this.addEmitter(emitter, ePosition);
576
+ });
577
+ }
578
+ }
579
+ async init() {
580
+ this.emitters = this.container.actualOptions.emitters;
581
+ this.interactivityEmitters = this.container.actualOptions.interactivity.modes.emitters;
582
+ if (this.emitters instanceof Array) {
583
+ for (const emitterOptions of this.emitters) {
584
+ this.addEmitter(emitterOptions);
585
+ }
586
+ } else {
587
+ this.addEmitter(this.emitters);
588
+ }
589
+ }
590
+ pause() {
591
+ for (const emitter of this.array) {
592
+ emitter.pause();
593
+ }
594
+ }
595
+ play() {
596
+ for (const emitter of this.array) {
597
+ emitter.play();
598
+ }
599
+ }
600
+ removeEmitter(emitter) {
601
+ const index = this.array.indexOf(emitter);
602
+ if (index >= 0) {
603
+ this.array.splice(index, 1);
604
+ }
605
+ }
606
+ resize() {
607
+ for (const emitter of this.array) {
608
+ emitter.resize();
609
+ }
610
+ }
611
+ stop() {
612
+ this.array = [];
613
+ }
614
+ update(delta) {
615
+ for (const emitter of this.array) {
616
+ emitter.update(delta);
617
+ }
618
+ }
619
+ }
620
+ ;// CONCATENATED MODULE: ./dist/browser/ShapeManager.js
621
+ const shapes = new Map();
622
+ class ShapeManager {
623
+ constructor(engine) {
624
+ this._engine = engine;
625
+ }
626
+ addShape(name, drawer) {
627
+ if (!this.getShape(name)) {
628
+ shapes.set(name, drawer);
629
+ }
630
+ }
631
+ getShape(name) {
632
+ return shapes.get(name);
633
+ }
634
+ getSupportedShapes() {
635
+ return shapes.keys();
636
+ }
637
+ }
638
+ ;// CONCATENATED MODULE: ./dist/browser/Shapes/Square/SquareShape.js
639
+
640
+ function randomSquareCoordinate(position, offset) {
641
+ return position + offset * ((0,engine_root_window_.getRandom)() - 0.5);
642
+ }
643
+ class SquareShape {
644
+ randomPosition(position, size, fill) {
645
+ if (fill) {
646
+ return {
647
+ x: randomSquareCoordinate(position.x, size.width),
648
+ y: randomSquareCoordinate(position.y, size.height)
649
+ };
650
+ } else {
651
+ const halfW = size.width / 2,
652
+ halfH = size.height / 2,
653
+ side = Math.floor((0,engine_root_window_.getRandom)() * 4),
654
+ v = ((0,engine_root_window_.getRandom)() - 0.5) * 2;
655
+ switch (side) {
656
+ case 0:
657
+ return {
658
+ x: position.x + v * halfW,
659
+ y: position.y - halfH
660
+ };
661
+ case 1:
662
+ return {
663
+ x: position.x - halfW,
664
+ y: position.y + v * halfH
665
+ };
666
+ case 2:
667
+ return {
668
+ x: position.x + v * halfW,
669
+ y: position.y + halfH
670
+ };
671
+ case 3:
672
+ default:
673
+ return {
674
+ x: position.x + halfW,
675
+ y: position.y + v * halfH
676
+ };
677
+ }
678
+ }
679
+ }
680
+ }
681
+ ;// CONCATENATED MODULE: ./dist/browser/index.js
682
+
683
+
684
+
685
+
686
+
687
+
688
+ class EmittersPlugin {
689
+ constructor(engine) {
690
+ this._engine = engine;
691
+ this.id = "emitters";
692
+ }
693
+ getPlugin(container) {
694
+ return new Emitters(this._engine, container);
695
+ }
696
+ loadOptions(options, source) {
697
+ var _a, _b, _c, _d, _e, _f;
698
+ if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
699
+ return;
700
+ }
701
+ if (source === null || source === void 0 ? void 0 : source.emitters) {
702
+ options.emitters = (0,engine_root_window_.executeOnSingleOrMultiple)(source.emitters, emitter => {
703
+ const tmp = new Emitter();
704
+ tmp.load(emitter);
705
+ return tmp;
706
+ });
707
+ }
708
+ const interactivityEmitters = (_b = (_a = source === null || source === void 0 ? void 0 : source.interactivity) === null || _a === void 0 ? void 0 : _a.modes) === null || _b === void 0 ? void 0 : _b.emitters;
709
+ if (interactivityEmitters) {
710
+ if (interactivityEmitters instanceof Array) {
711
+ options.interactivity.modes.emitters = {
712
+ random: {
713
+ count: 1,
714
+ enable: true
715
+ },
716
+ value: interactivityEmitters.map(s => {
717
+ const tmp = new Emitter();
718
+ tmp.load(s);
719
+ return tmp;
720
+ })
721
+ };
722
+ } else {
723
+ const emitterMode = interactivityEmitters;
724
+ if (emitterMode.value !== undefined) {
725
+ if (emitterMode.value instanceof Array) {
726
+ options.interactivity.modes.emitters = {
727
+ random: {
728
+ count: (_c = emitterMode.random.count) !== null && _c !== void 0 ? _c : 1,
729
+ enable: (_d = emitterMode.random.enable) !== null && _d !== void 0 ? _d : false
730
+ },
731
+ value: emitterMode.value.map(s => {
732
+ const tmp = new Emitter();
733
+ tmp.load(s);
734
+ return tmp;
735
+ })
736
+ };
737
+ } else {
738
+ const tmp = new Emitter();
739
+ tmp.load(emitterMode.value);
740
+ options.interactivity.modes.emitters = {
741
+ random: {
742
+ count: (_e = emitterMode.random.count) !== null && _e !== void 0 ? _e : 1,
743
+ enable: (_f = emitterMode.random.enable) !== null && _f !== void 0 ? _f : false
744
+ },
745
+ value: tmp
746
+ };
747
+ }
748
+ } else {
749
+ const emitterOptions = options.interactivity.modes.emitters = {
750
+ random: {
751
+ count: 1,
752
+ enable: false
753
+ },
754
+ value: new Emitter()
755
+ };
756
+ emitterOptions.value.load(interactivityEmitters);
757
+ }
758
+ }
759
+ }
760
+ }
761
+ needsPlugin(options) {
762
+ var _a, _b, _c;
763
+ if (!options) {
764
+ return false;
765
+ }
766
+ const emitters = options.emitters;
767
+ return emitters instanceof Array && !!emitters.length || emitters !== undefined || !!((_c = (_b = (_a = options.interactivity) === null || _a === void 0 ? void 0 : _a.events) === null || _b === void 0 ? void 0 : _b.onClick) === null || _c === void 0 ? void 0 : _c.mode) && (0,engine_root_window_.isInArray)("emitter", options.interactivity.events.onClick.mode);
768
+ }
769
+ }
770
+ async function loadEmittersPlugin(engine) {
771
+ if (!engine.emitterShapeManager) {
772
+ engine.emitterShapeManager = new ShapeManager(engine);
773
+ }
774
+ if (!engine.addEmitterShape) {
775
+ engine.addEmitterShape = (name, shape) => {
776
+ var _a;
777
+ (_a = engine.emitterShapeManager) === null || _a === void 0 ? void 0 : _a.addShape(name, shape);
778
+ };
779
+ }
780
+ const plugin = new EmittersPlugin(engine);
781
+ await engine.addPlugin(plugin);
782
+ engine.addEmitterShape("circle", new CircleShape());
783
+ engine.addEmitterShape("square", new SquareShape());
784
+ }
785
+
786
+
787
+
788
+
789
+ })();
790
+
791
+ /******/ return __webpack_exports__;
792
+ /******/ })()
793
+ ;
794
+ });