@tsparticles/plugin-emitters 3.0.0-alpha.1 → 3.0.0-beta.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.
- package/README.md +15 -11
- package/browser/EmitterInstance.js +101 -113
- package/browser/Emitters.js +31 -27
- package/browser/Options/Classes/Emitter.js +6 -6
- package/browser/Options/Classes/EmitterLife.js +4 -3
- package/browser/index.js +23 -26
- package/browser/package.json +1 -0
- package/cjs/EmitterInstance.js +102 -114
- package/cjs/Emitters.js +41 -48
- package/cjs/Options/Classes/Emitter.js +8 -8
- package/cjs/Options/Classes/EmitterLife.js +4 -3
- package/cjs/Shapes/Circle/CircleShape.js +1 -1
- package/cjs/index.js +38 -52
- package/cjs/package.json +1 -0
- package/esm/EmitterInstance.js +101 -113
- package/esm/Emitters.js +31 -27
- package/esm/Options/Classes/Emitter.js +6 -6
- package/esm/Options/Classes/EmitterLife.js +4 -3
- package/esm/index.js +23 -26
- package/esm/package.json +1 -0
- package/package.json +19 -6
- package/report.html +4 -4
- package/tsparticles.plugin.emitters.js +137 -145
- package/tsparticles.plugin.emitters.min.js +1 -1
- package/tsparticles.plugin.emitters.min.js.LICENSE.txt +1 -8
- package/types/EmitterContainer.d.ts +3 -3
- package/types/EmitterInstance.d.ts +12 -12
- package/types/Emitters.d.ts +7 -7
- package/types/EmittersEngine.d.ts +2 -2
- package/types/Enums/EmitterShapeType.d.ts +3 -1
- package/types/Options/Classes/Emitter.d.ts +6 -7
- package/types/Options/Classes/EmitterLife.d.ts +4 -4
- package/types/Options/Classes/EmitterRate.d.ts +2 -2
- package/types/Options/Classes/EmitterSize.d.ts +3 -4
- package/types/Options/Interfaces/IEmitter.d.ts +4 -4
- package/types/Options/Interfaces/IEmitterLife.d.ts +3 -2
- package/types/Options/Interfaces/IEmitterSize.d.ts +2 -2
- package/types/ShapeManager.d.ts +1 -1
- package/types/Shapes/Circle/CircleShape.d.ts +2 -2
- package/types/Shapes/Square/SquareShape.d.ts +2 -2
- package/types/index.d.ts +6 -6
- package/types/types.d.ts +2 -2
- package/umd/EmitterInstance.js +103 -115
- package/umd/Emitters.js +33 -29
- package/umd/Options/Classes/Emitter.js +9 -9
- package/umd/Options/Classes/EmitterLife.js +5 -4
- package/umd/index.js +32 -35
package/cjs/index.js
CHANGED
|
@@ -13,53 +13,43 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
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
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
17
|
exports.loadEmittersPlugin = void 0;
|
|
27
18
|
const engine_1 = require("@tsparticles/engine");
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const
|
|
19
|
+
const CircleShape_js_1 = require("./Shapes/Circle/CircleShape.js");
|
|
20
|
+
const Emitter_js_1 = require("./Options/Classes/Emitter.js");
|
|
21
|
+
const Emitters_js_1 = require("./Emitters.js");
|
|
22
|
+
const ShapeManager_js_1 = require("./ShapeManager.js");
|
|
23
|
+
const SquareShape_js_1 = require("./Shapes/Square/SquareShape.js");
|
|
33
24
|
class EmittersPlugin {
|
|
34
25
|
constructor(engine) {
|
|
35
26
|
this._engine = engine;
|
|
36
27
|
this.id = "emitters";
|
|
37
28
|
}
|
|
38
29
|
getPlugin(container) {
|
|
39
|
-
return new
|
|
30
|
+
return new Emitters_js_1.Emitters(this._engine, container);
|
|
40
31
|
}
|
|
41
32
|
loadOptions(options, source) {
|
|
42
|
-
var _a, _b, _c, _d, _e, _f;
|
|
43
33
|
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
44
34
|
return;
|
|
45
35
|
}
|
|
46
|
-
if (source
|
|
36
|
+
if (source?.emitters) {
|
|
47
37
|
options.emitters = (0, engine_1.executeOnSingleOrMultiple)(source.emitters, (emitter) => {
|
|
48
|
-
const tmp = new
|
|
38
|
+
const tmp = new Emitter_js_1.Emitter();
|
|
49
39
|
tmp.load(emitter);
|
|
50
40
|
return tmp;
|
|
51
41
|
});
|
|
52
42
|
}
|
|
53
|
-
const interactivityEmitters =
|
|
43
|
+
const interactivityEmitters = source?.interactivity?.modes?.emitters;
|
|
54
44
|
if (interactivityEmitters) {
|
|
55
|
-
if (
|
|
45
|
+
if ((0, engine_1.isArray)(interactivityEmitters)) {
|
|
56
46
|
options.interactivity.modes.emitters = {
|
|
57
47
|
random: {
|
|
58
48
|
count: 1,
|
|
59
49
|
enable: true,
|
|
60
50
|
},
|
|
61
51
|
value: interactivityEmitters.map((s) => {
|
|
62
|
-
const tmp = new
|
|
52
|
+
const tmp = new Emitter_js_1.Emitter();
|
|
63
53
|
tmp.load(s);
|
|
64
54
|
return tmp;
|
|
65
55
|
}),
|
|
@@ -68,26 +58,26 @@ class EmittersPlugin {
|
|
|
68
58
|
else {
|
|
69
59
|
const emitterMode = interactivityEmitters;
|
|
70
60
|
if (emitterMode.value !== undefined) {
|
|
71
|
-
if (emitterMode.value
|
|
61
|
+
if ((0, engine_1.isArray)(emitterMode.value)) {
|
|
72
62
|
options.interactivity.modes.emitters = {
|
|
73
63
|
random: {
|
|
74
|
-
count:
|
|
75
|
-
enable:
|
|
64
|
+
count: emitterMode.random.count ?? 1,
|
|
65
|
+
enable: emitterMode.random.enable ?? false,
|
|
76
66
|
},
|
|
77
67
|
value: emitterMode.value.map((s) => {
|
|
78
|
-
const tmp = new
|
|
68
|
+
const tmp = new Emitter_js_1.Emitter();
|
|
79
69
|
tmp.load(s);
|
|
80
70
|
return tmp;
|
|
81
71
|
}),
|
|
82
72
|
};
|
|
83
73
|
}
|
|
84
74
|
else {
|
|
85
|
-
const tmp = new
|
|
75
|
+
const tmp = new Emitter_js_1.Emitter();
|
|
86
76
|
tmp.load(emitterMode.value);
|
|
87
77
|
options.interactivity.modes.emitters = {
|
|
88
78
|
random: {
|
|
89
|
-
count:
|
|
90
|
-
enable:
|
|
79
|
+
count: emitterMode.random.count ?? 1,
|
|
80
|
+
enable: emitterMode.random.enable ?? false,
|
|
91
81
|
},
|
|
92
82
|
value: tmp,
|
|
93
83
|
};
|
|
@@ -99,7 +89,7 @@ class EmittersPlugin {
|
|
|
99
89
|
count: 1,
|
|
100
90
|
enable: false,
|
|
101
91
|
},
|
|
102
|
-
value: new
|
|
92
|
+
value: new Emitter_js_1.Emitter(),
|
|
103
93
|
});
|
|
104
94
|
emitterOptions.value.load(interactivityEmitters);
|
|
105
95
|
}
|
|
@@ -107,36 +97,32 @@ class EmittersPlugin {
|
|
|
107
97
|
}
|
|
108
98
|
}
|
|
109
99
|
needsPlugin(options) {
|
|
110
|
-
var _a, _b, _c;
|
|
111
100
|
if (!options) {
|
|
112
101
|
return false;
|
|
113
102
|
}
|
|
114
103
|
const emitters = options.emitters;
|
|
115
|
-
return ((emitters
|
|
104
|
+
return (((0, engine_1.isArray)(emitters) && !!emitters.length) ||
|
|
116
105
|
emitters !== undefined ||
|
|
117
|
-
(!!
|
|
106
|
+
(!!options.interactivity?.events?.onClick?.mode &&
|
|
118
107
|
(0, engine_1.isInArray)("emitter", options.interactivity.events.onClick.mode)));
|
|
119
108
|
}
|
|
120
109
|
}
|
|
121
|
-
function loadEmittersPlugin(engine) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
engine.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
engine.addEmitterShape("circle", new CircleShape_1.CircleShape());
|
|
135
|
-
engine.addEmitterShape("square", new SquareShape_1.SquareShape());
|
|
136
|
-
});
|
|
110
|
+
async function loadEmittersPlugin(engine, refresh = true) {
|
|
111
|
+
if (!engine.emitterShapeManager) {
|
|
112
|
+
engine.emitterShapeManager = new ShapeManager_js_1.ShapeManager(engine);
|
|
113
|
+
}
|
|
114
|
+
if (!engine.addEmitterShape) {
|
|
115
|
+
engine.addEmitterShape = (name, shape) => {
|
|
116
|
+
engine.emitterShapeManager?.addShape(name, shape);
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const plugin = new EmittersPlugin(engine);
|
|
120
|
+
await engine.addPlugin(plugin, refresh);
|
|
121
|
+
engine.addEmitterShape("circle", new CircleShape_js_1.CircleShape());
|
|
122
|
+
engine.addEmitterShape("square", new SquareShape_js_1.SquareShape());
|
|
137
123
|
}
|
|
138
124
|
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);
|
|
125
|
+
__exportStar(require("./EmitterContainer.js"), exports);
|
|
126
|
+
__exportStar(require("./EmittersEngine.js"), exports);
|
|
127
|
+
__exportStar(require("./Enums/EmitterClickMode.js"), exports);
|
|
128
|
+
__exportStar(require("./Enums/EmitterShapeType.js"), exports);
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "commonjs" }
|
package/esm/EmitterInstance.js
CHANGED
|
@@ -1,12 +1,79 @@
|
|
|
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";
|
|
1
|
+
import { Vector, calcPositionOrRandomFromSizeRanged, deepExtend, getRangeValue, getSize, isPointInside, itemFromSingleOrMultiple, randomInRange, rangeColorToHsl, } from "@tsparticles/engine";
|
|
2
|
+
import { Emitter } from "./Options/Classes/Emitter.js";
|
|
3
|
+
import { EmitterSize } from "./Options/Classes/EmitterSize.js";
|
|
4
4
|
export class EmitterInstance {
|
|
5
5
|
constructor(engine, emitters, container, options, position) {
|
|
6
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
7
|
-
var _h;
|
|
8
6
|
this.emitters = emitters;
|
|
9
7
|
this.container = container;
|
|
8
|
+
this._calcPosition = () => {
|
|
9
|
+
return calcPositionOrRandomFromSizeRanged({
|
|
10
|
+
size: this.container.canvas.size,
|
|
11
|
+
position: this.options.position,
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
this._destroy = () => {
|
|
15
|
+
this.emitters.removeEmitter(this);
|
|
16
|
+
this._engine.dispatchEvent("emitterDestroyed", {
|
|
17
|
+
container: this.container,
|
|
18
|
+
data: {
|
|
19
|
+
emitter: this,
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
this._emit = () => {
|
|
24
|
+
if (this._paused) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const quantity = getRangeValue(this.options.rate.quantity);
|
|
28
|
+
this._emitParticles(quantity);
|
|
29
|
+
};
|
|
30
|
+
this._emitParticles = (quantity) => {
|
|
31
|
+
const position = this.getPosition(), size = this.getSize(), singleParticlesOptions = itemFromSingleOrMultiple(this._particlesOptions);
|
|
32
|
+
for (let i = 0; i < quantity; i++) {
|
|
33
|
+
const particlesOptions = deepExtend({}, singleParticlesOptions);
|
|
34
|
+
if (this.spawnColor) {
|
|
35
|
+
const hslAnimation = this.options.spawnColor?.animation;
|
|
36
|
+
if (hslAnimation) {
|
|
37
|
+
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
|
|
38
|
+
this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
|
|
39
|
+
this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
|
|
40
|
+
}
|
|
41
|
+
if (!particlesOptions.color) {
|
|
42
|
+
particlesOptions.color = {
|
|
43
|
+
value: this.spawnColor,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
particlesOptions.color.value = this.spawnColor;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (!position) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const pPosition = this._shape?.randomPosition(position, size, this.fill) ?? position;
|
|
54
|
+
this.container.particles.addParticle(pPosition, particlesOptions);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
this._prepareToDie = () => {
|
|
58
|
+
if (this._paused) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const duration = this.options.life?.duration !== undefined ? getRangeValue(this.options.life.duration) : undefined;
|
|
62
|
+
if (this.container.retina.reduceFactor &&
|
|
63
|
+
(this._lifeCount > 0 || this._immortal) &&
|
|
64
|
+
duration !== undefined &&
|
|
65
|
+
duration > 0) {
|
|
66
|
+
this._duration = duration * 1000;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
this._setColorAnimation = (animation, initValue, maxValue) => {
|
|
70
|
+
const container = this.container;
|
|
71
|
+
if (!animation.enable) {
|
|
72
|
+
return initValue;
|
|
73
|
+
}
|
|
74
|
+
const colorOffset = randomInRange(animation.offset), delay = getRangeValue(this.options.rate.delay), emitFactor = (1000 * delay) / container.retina.reduceFactor, colorSpeed = getRangeValue(animation.speed ?? 0);
|
|
75
|
+
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * 3.6) % maxValue;
|
|
76
|
+
};
|
|
10
77
|
this._engine = engine;
|
|
11
78
|
this._currentDuration = 0;
|
|
12
79
|
this._currentEmitDelay = 0;
|
|
@@ -19,33 +86,34 @@ export class EmitterInstance {
|
|
|
19
86
|
this.options = new Emitter();
|
|
20
87
|
this.options.load(options);
|
|
21
88
|
}
|
|
22
|
-
this._spawnDelay = ((
|
|
23
|
-
this.position =
|
|
89
|
+
this._spawnDelay = (getRangeValue(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor;
|
|
90
|
+
this.position = this._initialPosition ?? this._calcPosition();
|
|
24
91
|
this.name = this.options.name;
|
|
25
|
-
this._shape =
|
|
92
|
+
this._shape = this._engine.emitterShapeManager?.getShape(this.options.shape);
|
|
26
93
|
this.fill = this.options.fill;
|
|
27
94
|
this._firstSpawn = !this.options.life.wait;
|
|
28
95
|
this._startParticlesAdded = false;
|
|
29
96
|
let particlesOptions = deepExtend({}, this.options.particles);
|
|
30
|
-
particlesOptions
|
|
31
|
-
|
|
32
|
-
|
|
97
|
+
particlesOptions ??= {};
|
|
98
|
+
particlesOptions.move ??= {};
|
|
99
|
+
particlesOptions.move.direction ??= this.options.direction;
|
|
33
100
|
if (this.options.spawnColor) {
|
|
34
101
|
this.spawnColor = rangeColorToHsl(this.options.spawnColor);
|
|
35
102
|
}
|
|
36
103
|
this._paused = !this.options.autoPlay;
|
|
37
104
|
this._particlesOptions = particlesOptions;
|
|
38
105
|
this.size =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
106
|
+
this.options.size ??
|
|
107
|
+
(() => {
|
|
108
|
+
const size = new EmitterSize();
|
|
109
|
+
size.load({
|
|
110
|
+
height: 0,
|
|
111
|
+
mode: "percent",
|
|
112
|
+
width: 0,
|
|
113
|
+
});
|
|
114
|
+
return size;
|
|
115
|
+
})();
|
|
116
|
+
this._lifeCount = this.options.life.count ?? -1;
|
|
49
117
|
this._immortal = this._lifeCount <= 0;
|
|
50
118
|
this._engine.dispatchEvent("emitterCreated", {
|
|
51
119
|
container,
|
|
@@ -88,14 +156,7 @@ export class EmitterInstance {
|
|
|
88
156
|
};
|
|
89
157
|
}
|
|
90
158
|
}
|
|
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
|
-
};
|
|
159
|
+
return getSize(this.size, container.canvas.size);
|
|
99
160
|
}
|
|
100
161
|
pause() {
|
|
101
162
|
if (this._paused) {
|
|
@@ -104,13 +165,12 @@ export class EmitterInstance {
|
|
|
104
165
|
delete this._emitDelay;
|
|
105
166
|
}
|
|
106
167
|
play() {
|
|
107
|
-
var _a;
|
|
108
168
|
if (this._paused) {
|
|
109
169
|
return;
|
|
110
170
|
}
|
|
111
171
|
if (!(this.container.retina.reduceFactor &&
|
|
112
172
|
(this._lifeCount > 0 || this._immortal || !this.options.life.count) &&
|
|
113
|
-
(this._firstSpawn || this._currentSpawnDelay >= (
|
|
173
|
+
(this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? 0)))) {
|
|
114
174
|
return;
|
|
115
175
|
}
|
|
116
176
|
if (this._emitDelay === undefined) {
|
|
@@ -118,7 +178,7 @@ export class EmitterInstance {
|
|
|
118
178
|
this._emitDelay = (1000 * delay) / this.container.retina.reduceFactor;
|
|
119
179
|
}
|
|
120
180
|
if (this._lifeCount > 0 || this._immortal) {
|
|
121
|
-
this.
|
|
181
|
+
this._prepareToDie();
|
|
122
182
|
}
|
|
123
183
|
}
|
|
124
184
|
resize() {
|
|
@@ -126,21 +186,20 @@ export class EmitterInstance {
|
|
|
126
186
|
this.position =
|
|
127
187
|
initialPosition && isPointInside(initialPosition, this.container.canvas.size, Vector.origin)
|
|
128
188
|
? initialPosition
|
|
129
|
-
: this.
|
|
189
|
+
: this._calcPosition();
|
|
130
190
|
}
|
|
131
191
|
update(delta) {
|
|
132
|
-
var _a, _b, _c;
|
|
133
192
|
if (this._paused) {
|
|
134
193
|
return;
|
|
135
194
|
}
|
|
136
195
|
if (this._firstSpawn) {
|
|
137
196
|
this._firstSpawn = false;
|
|
138
|
-
this._currentSpawnDelay =
|
|
139
|
-
this._currentEmitDelay =
|
|
197
|
+
this._currentSpawnDelay = this._spawnDelay ?? 0;
|
|
198
|
+
this._currentEmitDelay = this._emitDelay ?? 0;
|
|
140
199
|
}
|
|
141
200
|
if (!this._startParticlesAdded) {
|
|
142
201
|
this._startParticlesAdded = true;
|
|
143
|
-
this.
|
|
202
|
+
this._emitParticles(this.options.startCount);
|
|
144
203
|
}
|
|
145
204
|
if (this._duration !== undefined) {
|
|
146
205
|
this._currentDuration += delta.value;
|
|
@@ -153,11 +212,12 @@ export class EmitterInstance {
|
|
|
153
212
|
this._lifeCount--;
|
|
154
213
|
}
|
|
155
214
|
if (this._lifeCount > 0 || this._immortal) {
|
|
156
|
-
this.position = this.
|
|
157
|
-
this._spawnDelay =
|
|
215
|
+
this.position = this._calcPosition();
|
|
216
|
+
this._spawnDelay =
|
|
217
|
+
(getRangeValue(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor;
|
|
158
218
|
}
|
|
159
219
|
else {
|
|
160
|
-
this.
|
|
220
|
+
this._destroy();
|
|
161
221
|
}
|
|
162
222
|
this._currentDuration -= this._duration;
|
|
163
223
|
delete this._duration;
|
|
@@ -177,81 +237,9 @@ export class EmitterInstance {
|
|
|
177
237
|
if (this._emitDelay !== undefined) {
|
|
178
238
|
this._currentEmitDelay += delta.value;
|
|
179
239
|
if (this._currentEmitDelay >= this._emitDelay) {
|
|
180
|
-
this.
|
|
240
|
+
this._emit();
|
|
181
241
|
this._currentEmitDelay -= this._emitDelay;
|
|
182
242
|
}
|
|
183
243
|
}
|
|
184
244
|
}
|
|
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
245
|
}
|
package/esm/Emitters.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { arrayRandomIndex, executeOnSingleOrMultiple, itemFromArray } from "@tsparticles/engine";
|
|
2
|
-
import { Emitter } from "./Options/Classes/Emitter";
|
|
3
|
-
import { EmitterInstance } from "./EmitterInstance";
|
|
1
|
+
import { arrayRandomIndex, executeOnSingleOrMultiple, isArray, isNumber, itemFromArray, } from "@tsparticles/engine";
|
|
2
|
+
import { Emitter } from "./Options/Classes/Emitter.js";
|
|
3
|
+
import { EmitterInstance } from "./EmitterInstance.js";
|
|
4
4
|
export class Emitters {
|
|
5
5
|
constructor(engine, container) {
|
|
6
6
|
this.container = container;
|
|
@@ -14,7 +14,7 @@ export class Emitters {
|
|
|
14
14
|
},
|
|
15
15
|
value: [],
|
|
16
16
|
};
|
|
17
|
-
container.getEmitter = (idxOrName) => idxOrName === undefined ||
|
|
17
|
+
container.getEmitter = (idxOrName) => idxOrName === undefined || isNumber(idxOrName)
|
|
18
18
|
? this.array[idxOrName || 0]
|
|
19
19
|
: this.array.find((t) => t.name === idxOrName);
|
|
20
20
|
container.addEmitter = (options, position) => this.addEmitter(options, position);
|
|
@@ -46,39 +46,43 @@ export class Emitters {
|
|
|
46
46
|
}
|
|
47
47
|
handleClickMode(mode) {
|
|
48
48
|
const emitterOptions = this.emitters, modeEmitters = this.interactivityEmitters;
|
|
49
|
-
if (mode
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
emittersModeOptions.push(itemFromArray(modeEmitters.value, idx));
|
|
49
|
+
if (mode !== "emitter") {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
let emittersModeOptions;
|
|
53
|
+
if (modeEmitters && isArray(modeEmitters.value)) {
|
|
54
|
+
if (modeEmitters.value.length > 0 && modeEmitters.random.enable) {
|
|
55
|
+
emittersModeOptions = [];
|
|
56
|
+
const usedIndexes = [];
|
|
57
|
+
for (let i = 0; i < modeEmitters.random.count; i++) {
|
|
58
|
+
const idx = arrayRandomIndex(modeEmitters.value);
|
|
59
|
+
if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
|
|
60
|
+
i--;
|
|
61
|
+
continue;
|
|
63
62
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
emittersModeOptions = modeEmitters.value;
|
|
63
|
+
usedIndexes.push(idx);
|
|
64
|
+
emittersModeOptions.push(itemFromArray(modeEmitters.value, idx));
|
|
67
65
|
}
|
|
68
66
|
}
|
|
69
67
|
else {
|
|
70
|
-
emittersModeOptions = modeEmitters
|
|
68
|
+
emittersModeOptions = modeEmitters.value;
|
|
71
69
|
}
|
|
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
70
|
}
|
|
71
|
+
else {
|
|
72
|
+
emittersModeOptions = modeEmitters?.value;
|
|
73
|
+
}
|
|
74
|
+
const emittersOptions = emittersModeOptions ?? emitterOptions, ePosition = this.container.interactivity.mouse.clickPosition;
|
|
75
|
+
executeOnSingleOrMultiple(emittersOptions, (emitter) => {
|
|
76
|
+
this.addEmitter(emitter, ePosition);
|
|
77
|
+
});
|
|
77
78
|
}
|
|
78
79
|
async init() {
|
|
79
80
|
this.emitters = this.container.actualOptions.emitters;
|
|
80
81
|
this.interactivityEmitters = this.container.actualOptions.interactivity.modes.emitters;
|
|
81
|
-
if (this.emitters
|
|
82
|
+
if (!this.emitters) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (isArray(this.emitters)) {
|
|
82
86
|
for (const emitterOptions of this.emitters) {
|
|
83
87
|
this.addEmitter(emitterOptions);
|
|
84
88
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AnimatableColor, deepExtend, executeOnSingleOrMultiple, setRangeValue } from "@tsparticles/engine";
|
|
2
|
-
import { EmitterLife } from "./EmitterLife";
|
|
3
|
-
import { EmitterRate } from "./EmitterRate";
|
|
4
|
-
import { EmitterSize } from "./EmitterSize";
|
|
1
|
+
import { AnimatableColor, deepExtend, executeOnSingleOrMultiple, setRangeValue, } from "@tsparticles/engine";
|
|
2
|
+
import { EmitterLife } from "./EmitterLife.js";
|
|
3
|
+
import { EmitterRate } from "./EmitterRate.js";
|
|
4
|
+
import { EmitterSize } from "./EmitterSize.js";
|
|
5
5
|
export class Emitter {
|
|
6
6
|
constructor() {
|
|
7
7
|
this.autoPlay = true;
|
|
@@ -12,14 +12,14 @@ export class Emitter {
|
|
|
12
12
|
this.startCount = 0;
|
|
13
13
|
}
|
|
14
14
|
load(data) {
|
|
15
|
-
if (data
|
|
15
|
+
if (!data) {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
18
|
if (data.autoPlay !== undefined) {
|
|
19
19
|
this.autoPlay = data.autoPlay;
|
|
20
20
|
}
|
|
21
21
|
if (data.size !== undefined) {
|
|
22
|
-
if (this.size
|
|
22
|
+
if (!this.size) {
|
|
23
23
|
this.size = new EmitterSize();
|
|
24
24
|
}
|
|
25
25
|
this.size.load(data.size);
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
+
import { setRangeValue } from "@tsparticles/engine";
|
|
1
2
|
export class EmitterLife {
|
|
2
3
|
constructor() {
|
|
3
4
|
this.wait = false;
|
|
4
5
|
}
|
|
5
6
|
load(data) {
|
|
6
|
-
if (data
|
|
7
|
+
if (!data) {
|
|
7
8
|
return;
|
|
8
9
|
}
|
|
9
10
|
if (data.count !== undefined) {
|
|
10
11
|
this.count = data.count;
|
|
11
12
|
}
|
|
12
13
|
if (data.delay !== undefined) {
|
|
13
|
-
this.delay = data.delay;
|
|
14
|
+
this.delay = setRangeValue(data.delay);
|
|
14
15
|
}
|
|
15
16
|
if (data.duration !== undefined) {
|
|
16
|
-
this.duration = data.duration;
|
|
17
|
+
this.duration = setRangeValue(data.duration);
|
|
17
18
|
}
|
|
18
19
|
if (data.wait !== undefined) {
|
|
19
20
|
this.wait = data.wait;
|