@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,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EmitterSize = void 0;
4
+ class EmitterSize {
5
+ constructor() {
6
+ this.mode = "percent";
7
+ this.height = 0;
8
+ this.width = 0;
9
+ }
10
+ load(data) {
11
+ if (data === undefined) {
12
+ return;
13
+ }
14
+ if (data.mode !== undefined) {
15
+ this.mode = data.mode;
16
+ }
17
+ if (data.height !== undefined) {
18
+ this.height = data.height;
19
+ }
20
+ if (data.width !== undefined) {
21
+ this.width = data.width;
22
+ }
23
+ }
24
+ }
25
+ exports.EmitterSize = EmitterSize;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ShapeManager = void 0;
4
+ const shapes = new Map();
5
+ class ShapeManager {
6
+ constructor(engine) {
7
+ this._engine = engine;
8
+ }
9
+ addShape(name, drawer) {
10
+ if (!this.getShape(name)) {
11
+ shapes.set(name, drawer);
12
+ }
13
+ }
14
+ getShape(name) {
15
+ return shapes.get(name);
16
+ }
17
+ getSupportedShapes() {
18
+ return shapes.keys();
19
+ }
20
+ }
21
+ exports.ShapeManager = ShapeManager;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CircleShape = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ class CircleShape {
6
+ randomPosition(position, size, fill) {
7
+ const generateTheta = (x, y) => {
8
+ const u = (0, engine_1.getRandom)() / 4.0, theta = Math.atan((y / x) * Math.tan(2 * Math.PI * u)), v = (0, engine_1.getRandom)();
9
+ if (v < 0.25) {
10
+ return theta;
11
+ }
12
+ else if (v < 0.5) {
13
+ return Math.PI - theta;
14
+ }
15
+ else if (v < 0.75) {
16
+ return Math.PI + theta;
17
+ }
18
+ else {
19
+ return -theta;
20
+ }
21
+ }, radius = (x, y, theta) => (x * y) / Math.sqrt(Math.pow((y * Math.cos(theta)), 2) + Math.pow((x * Math.sin(theta)), 2)), [a, b] = [size.width / 2, size.height / 2], randomTheta = generateTheta(a, b), maxRadius = radius(a, b, randomTheta), randomRadius = fill ? maxRadius * Math.sqrt((0, engine_1.getRandom)()) : maxRadius;
22
+ return {
23
+ x: position.x + randomRadius * Math.cos(randomTheta),
24
+ y: position.y + randomRadius * Math.sin(randomTheta),
25
+ };
26
+ }
27
+ }
28
+ exports.CircleShape = CircleShape;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SquareShape = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ function randomSquareCoordinate(position, offset) {
6
+ return position + offset * ((0, engine_1.getRandom)() - 0.5);
7
+ }
8
+ class SquareShape {
9
+ randomPosition(position, size, fill) {
10
+ if (fill) {
11
+ return {
12
+ x: randomSquareCoordinate(position.x, size.width),
13
+ y: randomSquareCoordinate(position.y, size.height),
14
+ };
15
+ }
16
+ else {
17
+ const halfW = size.width / 2, halfH = size.height / 2, side = Math.floor((0, engine_1.getRandom)() * 4), v = ((0, engine_1.getRandom)() - 0.5) * 2;
18
+ switch (side) {
19
+ case 0:
20
+ return {
21
+ x: position.x + v * halfW,
22
+ y: position.y - halfH,
23
+ };
24
+ case 1:
25
+ return {
26
+ x: position.x - halfW,
27
+ y: position.y + v * halfH,
28
+ };
29
+ case 2:
30
+ return {
31
+ x: position.x + v * halfW,
32
+ y: position.y + halfH,
33
+ };
34
+ case 3:
35
+ default:
36
+ return {
37
+ x: position.x + halfW,
38
+ y: position.y + v * halfH,
39
+ };
40
+ }
41
+ }
42
+ }
43
+ }
44
+ exports.SquareShape = SquareShape;
package/cjs/index.js ADDED
@@ -0,0 +1,142 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.loadEmittersPlugin = void 0;
27
+ const engine_1 = require("@tsparticles/engine");
28
+ const CircleShape_1 = require("./Shapes/Circle/CircleShape");
29
+ const Emitter_1 = require("./Options/Classes/Emitter");
30
+ const Emitters_1 = require("./Emitters");
31
+ const ShapeManager_1 = require("./ShapeManager");
32
+ const SquareShape_1 = require("./Shapes/Square/SquareShape");
33
+ class EmittersPlugin {
34
+ constructor(engine) {
35
+ this._engine = engine;
36
+ this.id = "emitters";
37
+ }
38
+ getPlugin(container) {
39
+ return new Emitters_1.Emitters(this._engine, container);
40
+ }
41
+ loadOptions(options, source) {
42
+ var _a, _b, _c, _d, _e, _f;
43
+ if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
44
+ return;
45
+ }
46
+ if (source === null || source === void 0 ? void 0 : source.emitters) {
47
+ options.emitters = (0, engine_1.executeOnSingleOrMultiple)(source.emitters, (emitter) => {
48
+ const tmp = new Emitter_1.Emitter();
49
+ tmp.load(emitter);
50
+ return tmp;
51
+ });
52
+ }
53
+ 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;
54
+ if (interactivityEmitters) {
55
+ if (interactivityEmitters instanceof Array) {
56
+ options.interactivity.modes.emitters = {
57
+ random: {
58
+ count: 1,
59
+ enable: true,
60
+ },
61
+ value: interactivityEmitters.map((s) => {
62
+ const tmp = new Emitter_1.Emitter();
63
+ tmp.load(s);
64
+ return tmp;
65
+ }),
66
+ };
67
+ }
68
+ else {
69
+ const emitterMode = interactivityEmitters;
70
+ if (emitterMode.value !== undefined) {
71
+ if (emitterMode.value instanceof Array) {
72
+ options.interactivity.modes.emitters = {
73
+ random: {
74
+ count: (_c = emitterMode.random.count) !== null && _c !== void 0 ? _c : 1,
75
+ enable: (_d = emitterMode.random.enable) !== null && _d !== void 0 ? _d : false,
76
+ },
77
+ value: emitterMode.value.map((s) => {
78
+ const tmp = new Emitter_1.Emitter();
79
+ tmp.load(s);
80
+ return tmp;
81
+ }),
82
+ };
83
+ }
84
+ else {
85
+ const tmp = new Emitter_1.Emitter();
86
+ tmp.load(emitterMode.value);
87
+ options.interactivity.modes.emitters = {
88
+ random: {
89
+ count: (_e = emitterMode.random.count) !== null && _e !== void 0 ? _e : 1,
90
+ enable: (_f = emitterMode.random.enable) !== null && _f !== void 0 ? _f : false,
91
+ },
92
+ value: tmp,
93
+ };
94
+ }
95
+ }
96
+ else {
97
+ const emitterOptions = (options.interactivity.modes.emitters = {
98
+ random: {
99
+ count: 1,
100
+ enable: false,
101
+ },
102
+ value: new Emitter_1.Emitter(),
103
+ });
104
+ emitterOptions.value.load(interactivityEmitters);
105
+ }
106
+ }
107
+ }
108
+ }
109
+ needsPlugin(options) {
110
+ var _a, _b, _c;
111
+ if (!options) {
112
+ return false;
113
+ }
114
+ const emitters = options.emitters;
115
+ return ((emitters instanceof Array && !!emitters.length) ||
116
+ emitters !== undefined ||
117
+ (!!((_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) &&
118
+ (0, engine_1.isInArray)("emitter", options.interactivity.events.onClick.mode)));
119
+ }
120
+ }
121
+ function loadEmittersPlugin(engine) {
122
+ return __awaiter(this, void 0, void 0, function* () {
123
+ if (!engine.emitterShapeManager) {
124
+ engine.emitterShapeManager = new ShapeManager_1.ShapeManager(engine);
125
+ }
126
+ if (!engine.addEmitterShape) {
127
+ engine.addEmitterShape = (name, shape) => {
128
+ var _a;
129
+ (_a = engine.emitterShapeManager) === null || _a === void 0 ? void 0 : _a.addShape(name, shape);
130
+ };
131
+ }
132
+ const plugin = new EmittersPlugin(engine);
133
+ yield engine.addPlugin(plugin);
134
+ engine.addEmitterShape("circle", new CircleShape_1.CircleShape());
135
+ engine.addEmitterShape("square", new SquareShape_1.SquareShape());
136
+ });
137
+ }
138
+ exports.loadEmittersPlugin = loadEmittersPlugin;
139
+ __exportStar(require("./EmitterContainer"), exports);
140
+ __exportStar(require("./EmittersEngine"), exports);
141
+ __exportStar(require("./Enums/EmitterClickMode"), exports);
142
+ __exportStar(require("./Enums/EmitterShapeType"), exports);
package/cjs/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,257 @@
1
+ import { Vector, calcPositionOrRandomFromSizeRanged, deepExtend, getRangeValue, isPointInside, itemFromSingleOrMultiple, randomInRange, rangeColorToHsl, } from "@tsparticles/engine";
2
+ import { Emitter } from "./Options/Classes/Emitter";
3
+ import { EmitterSize } from "./Options/Classes/EmitterSize";
4
+ export class EmitterInstance {
5
+ constructor(engine, emitters, container, options, position) {
6
+ var _a, _b, _c, _d, _e, _f, _g;
7
+ var _h;
8
+ this.emitters = emitters;
9
+ this.container = container;
10
+ this._engine = engine;
11
+ this._currentDuration = 0;
12
+ this._currentEmitDelay = 0;
13
+ this._currentSpawnDelay = 0;
14
+ this._initialPosition = position;
15
+ if (options instanceof Emitter) {
16
+ this.options = options;
17
+ }
18
+ else {
19
+ this.options = new Emitter();
20
+ this.options.load(options);
21
+ }
22
+ this._spawnDelay = (((_a = this.options.life.delay) !== null && _a !== void 0 ? _a : 0) * 1000) / this.container.retina.reduceFactor;
23
+ this.position = (_b = this._initialPosition) !== null && _b !== void 0 ? _b : this.calcPosition();
24
+ this.name = this.options.name;
25
+ this._shape = (_c = this._engine.emitterShapeManager) === null || _c === void 0 ? void 0 : _c.getShape(this.options.shape);
26
+ this.fill = this.options.fill;
27
+ this._firstSpawn = !this.options.life.wait;
28
+ this._startParticlesAdded = false;
29
+ let particlesOptions = deepExtend({}, this.options.particles);
30
+ particlesOptions !== null && particlesOptions !== void 0 ? particlesOptions : (particlesOptions = {});
31
+ (_d = particlesOptions.move) !== null && _d !== void 0 ? _d : (particlesOptions.move = {});
32
+ (_e = (_h = particlesOptions.move).direction) !== null && _e !== void 0 ? _e : (_h.direction = this.options.direction);
33
+ if (this.options.spawnColor) {
34
+ this.spawnColor = rangeColorToHsl(this.options.spawnColor);
35
+ }
36
+ this._paused = !this.options.autoPlay;
37
+ this._particlesOptions = particlesOptions;
38
+ this.size =
39
+ (_f = this.options.size) !== null && _f !== void 0 ? _f : (() => {
40
+ const size = new EmitterSize();
41
+ size.load({
42
+ height: 0,
43
+ mode: "percent",
44
+ width: 0,
45
+ });
46
+ return size;
47
+ })();
48
+ this._lifeCount = (_g = this.options.life.count) !== null && _g !== void 0 ? _g : -1;
49
+ this._immortal = this._lifeCount <= 0;
50
+ this._engine.dispatchEvent("emitterCreated", {
51
+ container,
52
+ data: {
53
+ emitter: this,
54
+ },
55
+ });
56
+ this.play();
57
+ }
58
+ externalPause() {
59
+ this._paused = true;
60
+ this.pause();
61
+ }
62
+ externalPlay() {
63
+ this._paused = false;
64
+ this.play();
65
+ }
66
+ getPosition() {
67
+ if (this.options.domId) {
68
+ const container = this.container, element = document.getElementById(this.options.domId);
69
+ if (element) {
70
+ const elRect = element.getBoundingClientRect();
71
+ return {
72
+ x: (elRect.x + elRect.width / 2) * container.retina.pixelRatio,
73
+ y: (elRect.y + elRect.height / 2) * container.retina.pixelRatio,
74
+ };
75
+ }
76
+ }
77
+ return this.position;
78
+ }
79
+ getSize() {
80
+ const container = this.container;
81
+ if (this.options.domId) {
82
+ const element = document.getElementById(this.options.domId);
83
+ if (element) {
84
+ const elRect = element.getBoundingClientRect();
85
+ return {
86
+ width: elRect.width * container.retina.pixelRatio,
87
+ height: elRect.height * container.retina.pixelRatio,
88
+ };
89
+ }
90
+ }
91
+ return {
92
+ width: this.size.mode === "percent"
93
+ ? (container.canvas.size.width * this.size.width) / 100
94
+ : this.size.width,
95
+ height: this.size.mode === "percent"
96
+ ? (container.canvas.size.height * this.size.height) / 100
97
+ : this.size.height,
98
+ };
99
+ }
100
+ pause() {
101
+ if (this._paused) {
102
+ return;
103
+ }
104
+ delete this._emitDelay;
105
+ }
106
+ play() {
107
+ var _a;
108
+ if (this._paused) {
109
+ return;
110
+ }
111
+ if (!(this.container.retina.reduceFactor &&
112
+ (this._lifeCount > 0 || this._immortal || !this.options.life.count) &&
113
+ (this._firstSpawn || this._currentSpawnDelay >= ((_a = this._spawnDelay) !== null && _a !== void 0 ? _a : 0)))) {
114
+ return;
115
+ }
116
+ if (this._emitDelay === undefined) {
117
+ const delay = getRangeValue(this.options.rate.delay);
118
+ this._emitDelay = (1000 * delay) / this.container.retina.reduceFactor;
119
+ }
120
+ if (this._lifeCount > 0 || this._immortal) {
121
+ this.prepareToDie();
122
+ }
123
+ }
124
+ resize() {
125
+ const initialPosition = this._initialPosition;
126
+ this.position =
127
+ initialPosition && isPointInside(initialPosition, this.container.canvas.size, Vector.origin)
128
+ ? initialPosition
129
+ : this.calcPosition();
130
+ }
131
+ update(delta) {
132
+ var _a, _b, _c;
133
+ if (this._paused) {
134
+ return;
135
+ }
136
+ if (this._firstSpawn) {
137
+ this._firstSpawn = false;
138
+ this._currentSpawnDelay = (_a = this._spawnDelay) !== null && _a !== void 0 ? _a : 0;
139
+ this._currentEmitDelay = (_b = this._emitDelay) !== null && _b !== void 0 ? _b : 0;
140
+ }
141
+ if (!this._startParticlesAdded) {
142
+ this._startParticlesAdded = true;
143
+ this.emitParticles(this.options.startCount);
144
+ }
145
+ if (this._duration !== undefined) {
146
+ this._currentDuration += delta.value;
147
+ if (this._currentDuration >= this._duration) {
148
+ this.pause();
149
+ if (this._spawnDelay !== undefined) {
150
+ delete this._spawnDelay;
151
+ }
152
+ if (!this._immortal) {
153
+ this._lifeCount--;
154
+ }
155
+ if (this._lifeCount > 0 || this._immortal) {
156
+ this.position = this.calcPosition();
157
+ this._spawnDelay = (((_c = this.options.life.delay) !== null && _c !== void 0 ? _c : 0) * 1000) / this.container.retina.reduceFactor;
158
+ }
159
+ else {
160
+ this.destroy();
161
+ }
162
+ this._currentDuration -= this._duration;
163
+ delete this._duration;
164
+ }
165
+ }
166
+ if (this._spawnDelay !== undefined) {
167
+ this._currentSpawnDelay += delta.value;
168
+ if (this._currentSpawnDelay >= this._spawnDelay) {
169
+ this._engine.dispatchEvent("emitterPlay", {
170
+ container: this.container,
171
+ });
172
+ this.play();
173
+ this._currentSpawnDelay -= this._currentSpawnDelay;
174
+ delete this._spawnDelay;
175
+ }
176
+ }
177
+ if (this._emitDelay !== undefined) {
178
+ this._currentEmitDelay += delta.value;
179
+ if (this._currentEmitDelay >= this._emitDelay) {
180
+ this.emit();
181
+ this._currentEmitDelay -= this._emitDelay;
182
+ }
183
+ }
184
+ }
185
+ calcPosition() {
186
+ return calcPositionOrRandomFromSizeRanged({
187
+ size: this.container.canvas.size,
188
+ position: this.options.position,
189
+ });
190
+ }
191
+ destroy() {
192
+ this.emitters.removeEmitter(this);
193
+ this._engine.dispatchEvent("emitterDestroyed", {
194
+ container: this.container,
195
+ data: {
196
+ emitter: this,
197
+ },
198
+ });
199
+ }
200
+ emit() {
201
+ if (this._paused) {
202
+ return;
203
+ }
204
+ const quantity = getRangeValue(this.options.rate.quantity);
205
+ this.emitParticles(quantity);
206
+ }
207
+ emitParticles(quantity) {
208
+ var _a, _b, _c;
209
+ const position = this.getPosition(), size = this.getSize(), singleParticlesOptions = itemFromSingleOrMultiple(this._particlesOptions);
210
+ for (let i = 0; i < quantity; i++) {
211
+ const particlesOptions = deepExtend({}, singleParticlesOptions);
212
+ if (this.spawnColor) {
213
+ const hslAnimation = (_a = this.options.spawnColor) === null || _a === void 0 ? void 0 : _a.animation;
214
+ if (hslAnimation) {
215
+ this.spawnColor.h = this.setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
216
+ this.spawnColor.s = this.setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
217
+ this.spawnColor.l = this.setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
218
+ }
219
+ if (!particlesOptions.color) {
220
+ particlesOptions.color = {
221
+ value: this.spawnColor,
222
+ };
223
+ }
224
+ else {
225
+ particlesOptions.color.value = this.spawnColor;
226
+ }
227
+ }
228
+ if (!position) {
229
+ return;
230
+ }
231
+ const pPosition = (_c = (_b = this._shape) === null || _b === void 0 ? void 0 : _b.randomPosition(position, size, this.fill)) !== null && _c !== void 0 ? _c : position;
232
+ this.container.particles.addParticle(pPosition, particlesOptions);
233
+ }
234
+ }
235
+ prepareToDie() {
236
+ var _a;
237
+ if (this._paused) {
238
+ return;
239
+ }
240
+ const duration = (_a = this.options.life) === null || _a === void 0 ? void 0 : _a.duration;
241
+ if (this.container.retina.reduceFactor &&
242
+ (this._lifeCount > 0 || this._immortal) &&
243
+ duration !== undefined &&
244
+ duration > 0) {
245
+ this._duration = duration * 1000;
246
+ }
247
+ }
248
+ setColorAnimation(animation, initValue, maxValue) {
249
+ var _a;
250
+ const container = this.container;
251
+ if (!animation.enable) {
252
+ return initValue;
253
+ }
254
+ const colorOffset = randomInRange(animation.offset), delay = getRangeValue(this.options.rate.delay), emitFactor = (1000 * delay) / container.retina.reduceFactor, colorSpeed = getRangeValue((_a = animation.speed) !== null && _a !== void 0 ? _a : 0);
255
+ return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * 3.6) % maxValue;
256
+ }
257
+ }
@@ -0,0 +1,119 @@
1
+ import { arrayRandomIndex, executeOnSingleOrMultiple, itemFromArray } from "@tsparticles/engine";
2
+ import { Emitter } from "./Options/Classes/Emitter";
3
+ import { EmitterInstance } from "./EmitterInstance";
4
+ export class Emitters {
5
+ constructor(engine, container) {
6
+ this.container = container;
7
+ this._engine = engine;
8
+ this.array = [];
9
+ this.emitters = [];
10
+ this.interactivityEmitters = {
11
+ random: {
12
+ count: 1,
13
+ enable: false,
14
+ },
15
+ value: [],
16
+ };
17
+ container.getEmitter = (idxOrName) => idxOrName === undefined || typeof idxOrName === "number"
18
+ ? this.array[idxOrName || 0]
19
+ : this.array.find((t) => t.name === idxOrName);
20
+ container.addEmitter = (options, position) => this.addEmitter(options, position);
21
+ container.removeEmitter = (idxOrName) => {
22
+ const emitter = container.getEmitter(idxOrName);
23
+ if (emitter) {
24
+ this.removeEmitter(emitter);
25
+ }
26
+ };
27
+ container.playEmitter = (idxOrName) => {
28
+ const emitter = container.getEmitter(idxOrName);
29
+ if (emitter) {
30
+ emitter.externalPlay();
31
+ }
32
+ };
33
+ container.pauseEmitter = (idxOrName) => {
34
+ const emitter = container.getEmitter(idxOrName);
35
+ if (emitter) {
36
+ emitter.externalPause();
37
+ }
38
+ };
39
+ }
40
+ addEmitter(options, position) {
41
+ const emitterOptions = new Emitter();
42
+ emitterOptions.load(options);
43
+ const emitter = new EmitterInstance(this._engine, this, this.container, emitterOptions, position);
44
+ this.array.push(emitter);
45
+ return emitter;
46
+ }
47
+ handleClickMode(mode) {
48
+ const emitterOptions = this.emitters, modeEmitters = this.interactivityEmitters;
49
+ if (mode === "emitter") {
50
+ let emittersModeOptions;
51
+ if (modeEmitters && modeEmitters.value instanceof Array) {
52
+ if (modeEmitters.value.length > 0 && modeEmitters.random.enable) {
53
+ emittersModeOptions = [];
54
+ const usedIndexes = [];
55
+ for (let i = 0; i < modeEmitters.random.count; i++) {
56
+ const idx = arrayRandomIndex(modeEmitters.value);
57
+ if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
58
+ i--;
59
+ continue;
60
+ }
61
+ usedIndexes.push(idx);
62
+ emittersModeOptions.push(itemFromArray(modeEmitters.value, idx));
63
+ }
64
+ }
65
+ else {
66
+ emittersModeOptions = modeEmitters.value;
67
+ }
68
+ }
69
+ else {
70
+ emittersModeOptions = modeEmitters === null || modeEmitters === void 0 ? void 0 : modeEmitters.value;
71
+ }
72
+ const emittersOptions = emittersModeOptions !== null && emittersModeOptions !== void 0 ? emittersModeOptions : emitterOptions, ePosition = this.container.interactivity.mouse.clickPosition;
73
+ executeOnSingleOrMultiple(emittersOptions, (emitter) => {
74
+ this.addEmitter(emitter, ePosition);
75
+ });
76
+ }
77
+ }
78
+ async init() {
79
+ this.emitters = this.container.actualOptions.emitters;
80
+ this.interactivityEmitters = this.container.actualOptions.interactivity.modes.emitters;
81
+ if (this.emitters instanceof Array) {
82
+ for (const emitterOptions of this.emitters) {
83
+ this.addEmitter(emitterOptions);
84
+ }
85
+ }
86
+ else {
87
+ this.addEmitter(this.emitters);
88
+ }
89
+ }
90
+ pause() {
91
+ for (const emitter of this.array) {
92
+ emitter.pause();
93
+ }
94
+ }
95
+ play() {
96
+ for (const emitter of this.array) {
97
+ emitter.play();
98
+ }
99
+ }
100
+ removeEmitter(emitter) {
101
+ const index = this.array.indexOf(emitter);
102
+ if (index >= 0) {
103
+ this.array.splice(index, 1);
104
+ }
105
+ }
106
+ resize() {
107
+ for (const emitter of this.array) {
108
+ emitter.resize();
109
+ }
110
+ }
111
+ stop() {
112
+ this.array = [];
113
+ }
114
+ update(delta) {
115
+ for (const emitter of this.array) {
116
+ emitter.update(delta);
117
+ }
118
+ }
119
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};