@tsparticles/plugin-emitters 4.0.0-alpha.5 → 4.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/526.min.js +1 -0
- package/588.min.js +1 -0
- package/772.min.js +1 -0
- package/784.min.js +1 -0
- package/795.min.js +1 -0
- package/803.min.js +1 -0
- package/README.md +5 -0
- package/browser/EmitterInstance.js +109 -65
- package/browser/EmitterShapeBase.js +4 -0
- package/browser/EmittersInstancesManager.js +2 -0
- package/browser/EmittersInteractor.js +5 -1
- package/browser/EmittersPlugin.js +2 -1
- package/browser/EmittersPluginInstance.js +2 -0
- package/browser/Options/Classes/Emitter.js +25 -3
- package/browser/Options/Classes/EmitterLife.js +4 -0
- package/browser/Options/Classes/EmitterRate.js +2 -0
- package/browser/Options/Classes/EmitterShape.js +3 -0
- package/browser/Options/Classes/EmitterShapeReplace.js +2 -0
- package/browser/Options/Classes/EmitterSize.js +3 -0
- package/browser/Options/Classes/EmitterSpawn.js +18 -0
- package/browser/Options/Interfaces/IEmitterSpawn.js +1 -0
- package/browser/index.js +13 -3
- package/cjs/EmitterInstance.js +109 -65
- package/cjs/EmitterShapeBase.js +4 -0
- package/cjs/EmittersInstancesManager.js +2 -0
- package/cjs/EmittersInteractor.js +5 -1
- package/cjs/EmittersPlugin.js +2 -1
- package/cjs/EmittersPluginInstance.js +2 -0
- package/cjs/Options/Classes/Emitter.js +25 -3
- package/cjs/Options/Classes/EmitterLife.js +4 -0
- package/cjs/Options/Classes/EmitterRate.js +2 -0
- package/cjs/Options/Classes/EmitterShape.js +3 -0
- package/cjs/Options/Classes/EmitterShapeReplace.js +2 -0
- package/cjs/Options/Classes/EmitterSize.js +3 -0
- package/cjs/Options/Classes/EmitterSpawn.js +18 -0
- package/cjs/Options/Interfaces/IEmitterSpawn.js +1 -0
- package/cjs/index.js +13 -3
- package/dist_browser_EmitterInstance_js.js +2 -2
- package/dist_browser_EmittersInstancesManager_js.js +18 -8
- package/dist_browser_EmittersInteractor_js.js +19 -9
- package/dist_browser_EmittersPluginInstance_js.js +2 -2
- package/dist_browser_EmittersPlugin_js.js +18 -8
- package/dist_browser_ShapeManager_js.js +2 -2
- package/esm/EmitterInstance.js +109 -65
- package/esm/EmitterShapeBase.js +4 -0
- package/esm/EmittersInstancesManager.js +2 -0
- package/esm/EmittersInteractor.js +5 -1
- package/esm/EmittersPlugin.js +2 -1
- package/esm/EmittersPluginInstance.js +2 -0
- package/esm/Options/Classes/Emitter.js +25 -3
- package/esm/Options/Classes/EmitterLife.js +4 -0
- package/esm/Options/Classes/EmitterRate.js +2 -0
- package/esm/Options/Classes/EmitterShape.js +3 -0
- package/esm/Options/Classes/EmitterShapeReplace.js +2 -0
- package/esm/Options/Classes/EmitterSize.js +3 -0
- package/esm/Options/Classes/EmitterSpawn.js +18 -0
- package/esm/Options/Interfaces/IEmitterSpawn.js +1 -0
- package/esm/index.js +13 -3
- package/package.json +3 -3
- package/report.html +3 -3
- package/tsparticles.plugin.emitters.js +44 -32
- package/tsparticles.plugin.emitters.min.js +2 -2
- package/types/EmitterInstance.d.ts +6 -1
- package/types/EmittersInteractor.d.ts +1 -0
- package/types/EmittersPlugin.d.ts +1 -1
- package/types/IEmitterShapeGenerator.d.ts +2 -2
- package/types/Options/Classes/Emitter.d.ts +4 -1
- package/types/Options/Classes/EmitterSpawn.d.ts +7 -0
- package/types/Options/Interfaces/IEmitter.d.ts +4 -1
- package/types/Options/Interfaces/IEmitterSpawn.d.ts +5 -0
- package/types/index.d.ts +1 -0
- package/umd/EmitterInstance.js +108 -64
- package/umd/EmitterShapeBase.js +4 -0
- package/umd/EmittersInstancesManager.js +2 -0
- package/umd/EmittersInteractor.js +5 -1
- package/umd/EmittersPlugin.js +2 -1
- package/umd/EmittersPluginInstance.js +2 -0
- package/umd/Options/Classes/Emitter.js +26 -4
- package/umd/Options/Classes/EmitterLife.js +4 -0
- package/umd/Options/Classes/EmitterRate.js +2 -0
- package/umd/Options/Classes/EmitterShape.js +3 -0
- package/umd/Options/Classes/EmitterShapeReplace.js +2 -0
- package/umd/Options/Classes/EmitterSize.js +3 -0
- package/umd/Options/Classes/EmitterSpawn.js +32 -0
- package/umd/Options/Interfaces/IEmitterSpawn.js +12 -0
- package/umd/index.js +14 -3
- package/129.min.js +0 -2
- package/129.min.js.LICENSE.txt +0 -1
- package/246.min.js +0 -2
- package/246.min.js.LICENSE.txt +0 -1
- package/330.min.js +0 -2
- package/330.min.js.LICENSE.txt +0 -1
- package/490.min.js +0 -2
- package/490.min.js.LICENSE.txt +0 -1
- package/849.min.js +0 -2
- package/849.min.js.LICENSE.txt +0 -1
- package/940.min.js +0 -2
- package/940.min.js.LICENSE.txt +0 -1
- package/tsparticles.plugin.emitters.min.js.LICENSE.txt +0 -1
package/esm/EmitterInstance.js
CHANGED
|
@@ -1,53 +1,54 @@
|
|
|
1
|
-
import { PixelMode, Vector, calcPositionOrRandomFromSizeRanged, deepExtend, getRangeValue, getSize, hMax, half, isPointInside, itemFromSingleOrMultiple, lMax, millisecondsToSeconds, randomInRangeValue, rangeColorToHsl, sMax, safeDocument, } from "@tsparticles/engine";
|
|
1
|
+
import { AnimatableColor, Fill, PixelMode, Stroke, Vector, calcPositionOrRandomFromSizeRanged, deepExtend, defaultOpacity, getRangeValue, getSize, hMax, half, isPointInside, itemFromSingleOrMultiple, lMax, millisecondsToSeconds, randomInRangeValue, rangeColorToHsl, sMax, safeDocument, } from "@tsparticles/engine";
|
|
2
2
|
import { Emitter } from "./Options/Classes/Emitter.js";
|
|
3
3
|
import { EmitterSize } from "./Options/Classes/EmitterSize.js";
|
|
4
|
-
const defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1, defaultColorAnimationFactor = 1, colorFactor = 3.6;
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
4
|
+
const defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1, defaultColorAnimationFactor = 1, colorFactor = 3.6, defaultStrokeWidth = 1;
|
|
5
|
+
function setParticlesOptionsFillColor(particlesOptions, color, opacity, enable) {
|
|
6
|
+
particlesOptions.fill = new Fill();
|
|
7
|
+
particlesOptions.fill.color = AnimatableColor.create(undefined, { value: color });
|
|
8
|
+
particlesOptions.fill.enable = enable;
|
|
9
|
+
particlesOptions.fill.opacity = opacity;
|
|
10
|
+
}
|
|
11
|
+
function setParticlesOptionsStrokeColor(particlesOptions, color, opacity, width) {
|
|
12
|
+
particlesOptions.stroke = new Stroke();
|
|
13
|
+
particlesOptions.stroke.color = AnimatableColor.create(undefined, { value: color });
|
|
14
|
+
particlesOptions.stroke.opacity = opacity;
|
|
15
|
+
particlesOptions.stroke.width = width;
|
|
14
16
|
}
|
|
15
17
|
export class EmitterInstance {
|
|
18
|
+
container;
|
|
19
|
+
removeCallback;
|
|
20
|
+
fill;
|
|
21
|
+
name;
|
|
22
|
+
options;
|
|
23
|
+
position;
|
|
24
|
+
size;
|
|
25
|
+
spawnFillColor;
|
|
26
|
+
spawnFillEnabled;
|
|
27
|
+
spawnFillOpacity;
|
|
28
|
+
spawnStrokeColor;
|
|
29
|
+
spawnStrokeOpacity;
|
|
30
|
+
spawnStrokeWidth;
|
|
31
|
+
_currentDuration;
|
|
32
|
+
_currentEmitDelay;
|
|
33
|
+
_currentSpawnDelay;
|
|
34
|
+
_duration;
|
|
35
|
+
_emitDelay;
|
|
36
|
+
_engine;
|
|
37
|
+
_firstSpawn;
|
|
38
|
+
_immortal;
|
|
39
|
+
_initialPosition;
|
|
40
|
+
_lifeCount;
|
|
41
|
+
_mutationObserver;
|
|
42
|
+
_particlesOptions;
|
|
43
|
+
_paused;
|
|
44
|
+
_resizeObserver;
|
|
45
|
+
_shape;
|
|
46
|
+
_size;
|
|
47
|
+
_spawnDelay;
|
|
48
|
+
_startParticlesAdded;
|
|
16
49
|
constructor(engine, container, removeCallback, options, position) {
|
|
17
50
|
this.container = container;
|
|
18
51
|
this.removeCallback = removeCallback;
|
|
19
|
-
this._destroy = () => {
|
|
20
|
-
this._mutationObserver?.disconnect();
|
|
21
|
-
this._mutationObserver = undefined;
|
|
22
|
-
this._resizeObserver?.disconnect();
|
|
23
|
-
this._resizeObserver = undefined;
|
|
24
|
-
this.removeCallback(this);
|
|
25
|
-
this._engine.dispatchEvent("emitterDestroyed", {
|
|
26
|
-
container: this.container,
|
|
27
|
-
data: {
|
|
28
|
-
emitter: this,
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
this._prepareToDie = () => {
|
|
33
|
-
if (this._paused) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const duration = this.options.life.duration !== undefined ? getRangeValue(this.options.life.duration) : undefined, minDuration = 0, minLifeCount = 0;
|
|
37
|
-
if ((this._lifeCount > minLifeCount || this._immortal) && duration !== undefined && duration > minDuration) {
|
|
38
|
-
this._duration = duration * millisecondsToSeconds;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
this._setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => {
|
|
42
|
-
const container = this.container;
|
|
43
|
-
if (!animation.enable) {
|
|
44
|
-
return initValue;
|
|
45
|
-
}
|
|
46
|
-
const colorOffset = randomInRangeValue(animation.offset), delay = getRangeValue(this.options.rate.delay), emitFactor = container.retina.reduceFactor
|
|
47
|
-
? (delay * millisecondsToSeconds) / container.retina.reduceFactor
|
|
48
|
-
: Infinity, colorSpeed = getRangeValue(animation.speed);
|
|
49
|
-
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * factor) % maxValue;
|
|
50
|
-
};
|
|
51
52
|
this._engine = engine;
|
|
52
53
|
this._currentDuration = 0;
|
|
53
54
|
this._currentEmitDelay = 0;
|
|
@@ -72,8 +73,11 @@ export class EmitterInstance {
|
|
|
72
73
|
const particlesOptions = deepExtend({}, this.options.particles);
|
|
73
74
|
particlesOptions.move ??= {};
|
|
74
75
|
particlesOptions.move.direction ??= this.options.direction;
|
|
75
|
-
if (this.options.
|
|
76
|
-
this.
|
|
76
|
+
if (this.options.spawn.fill?.color) {
|
|
77
|
+
this.spawnFillColor = rangeColorToHsl(this._engine, this.options.spawn.fill.color);
|
|
78
|
+
}
|
|
79
|
+
if (this.options.spawn.stroke?.color) {
|
|
80
|
+
this.spawnStrokeColor = rangeColorToHsl(this._engine, this.options.spawn.stroke.color);
|
|
77
81
|
}
|
|
78
82
|
this._paused = !this.options.autoPlay;
|
|
79
83
|
this._particlesOptions = particlesOptions;
|
|
@@ -99,7 +103,7 @@ export class EmitterInstance {
|
|
|
99
103
|
}
|
|
100
104
|
const shapeOptions = this.options.shape, shapeGenerator = this._engine.emitterShapeManager?.getShapeGenerator(shapeOptions.type);
|
|
101
105
|
if (shapeGenerator) {
|
|
102
|
-
this._shape = shapeGenerator.generate(this.position, this.size, this.fill, shapeOptions.options);
|
|
106
|
+
this._shape = shapeGenerator.generate(this.container, this.position, this.size, this.fill, shapeOptions.options);
|
|
103
107
|
}
|
|
104
108
|
this._engine.dispatchEvent("emitterCreated", {
|
|
105
109
|
container,
|
|
@@ -201,7 +205,7 @@ export class EmitterInstance {
|
|
|
201
205
|
container: this.container,
|
|
202
206
|
});
|
|
203
207
|
this.play();
|
|
204
|
-
this._currentSpawnDelay -= this.
|
|
208
|
+
this._currentSpawnDelay -= this._spawnDelay;
|
|
205
209
|
delete this._spawnDelay;
|
|
206
210
|
}
|
|
207
211
|
}
|
|
@@ -254,6 +258,19 @@ export class EmitterInstance {
|
|
|
254
258
|
return size;
|
|
255
259
|
})());
|
|
256
260
|
}
|
|
261
|
+
_destroy = () => {
|
|
262
|
+
this._mutationObserver?.disconnect();
|
|
263
|
+
this._mutationObserver = undefined;
|
|
264
|
+
this._resizeObserver?.disconnect();
|
|
265
|
+
this._resizeObserver = undefined;
|
|
266
|
+
this.removeCallback(this);
|
|
267
|
+
this._engine.dispatchEvent("emitterDestroyed", {
|
|
268
|
+
container: this.container,
|
|
269
|
+
data: {
|
|
270
|
+
emitter: this,
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
};
|
|
257
274
|
_emit() {
|
|
258
275
|
if (this._paused) {
|
|
259
276
|
return;
|
|
@@ -263,18 +280,36 @@ export class EmitterInstance {
|
|
|
263
280
|
}
|
|
264
281
|
_emitParticles(quantity) {
|
|
265
282
|
const singleParticlesOptions = (itemFromSingleOrMultiple(this._particlesOptions) ??
|
|
266
|
-
{}),
|
|
283
|
+
{}), fillHslAnimation = this.options.spawn.fill?.color.animation, fillEnabled = this.options.spawn.fill?.enable ?? !!this.options.spawn.fill?.color, fillOpacity = this.options.spawn.fill?.opacity === undefined
|
|
284
|
+
? defaultOpacity
|
|
285
|
+
: getRangeValue(this.options.spawn.fill.opacity), strokeHslAnimation = this.options.spawn.stroke?.color?.animation, strokeOpacity = this.options.spawn.stroke?.opacity === undefined
|
|
286
|
+
? defaultOpacity
|
|
287
|
+
: getRangeValue(this.options.spawn.stroke.opacity), strokeWidth = this.options.spawn.stroke?.width === undefined
|
|
288
|
+
? defaultStrokeWidth
|
|
289
|
+
: getRangeValue(this.options.spawn.stroke.width), reduceFactor = this.container.retina.reduceFactor, needsFillColorAnimation = !!fillHslAnimation, needsStrokeColorAnimation = !!strokeHslAnimation, needsShapeData = !!this._shape, needsColorAnimation = needsFillColorAnimation || needsStrokeColorAnimation, needsCopy = needsColorAnimation || needsShapeData, maxValues = needsColorAnimation ? { h: hMax, s: sMax, l: lMax } : null, shapeOptions = this.options.shape;
|
|
267
290
|
for (let i = 0; i < quantity * reduceFactor; i++) {
|
|
268
291
|
const particlesOptions = needsCopy
|
|
269
292
|
? deepExtend({}, singleParticlesOptions)
|
|
270
293
|
: singleParticlesOptions;
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
294
|
+
this.spawnFillOpacity = fillOpacity;
|
|
295
|
+
this.spawnFillEnabled = fillEnabled;
|
|
296
|
+
this.spawnStrokeOpacity = strokeOpacity;
|
|
297
|
+
this.spawnStrokeWidth = strokeWidth;
|
|
298
|
+
if (this.spawnFillColor) {
|
|
299
|
+
if (fillHslAnimation && maxValues) {
|
|
300
|
+
this.spawnFillColor.h = this._setColorAnimation(fillHslAnimation.h, this.spawnFillColor.h, maxValues.h, colorFactor);
|
|
301
|
+
this.spawnFillColor.s = this._setColorAnimation(fillHslAnimation.s, this.spawnFillColor.s, maxValues.s);
|
|
302
|
+
this.spawnFillColor.l = this._setColorAnimation(fillHslAnimation.l, this.spawnFillColor.l, maxValues.l);
|
|
303
|
+
}
|
|
304
|
+
setParticlesOptionsFillColor(particlesOptions, this.spawnFillColor, this.spawnFillOpacity, this.spawnFillEnabled);
|
|
305
|
+
}
|
|
306
|
+
if (this.spawnStrokeColor) {
|
|
307
|
+
if (strokeHslAnimation && maxValues) {
|
|
308
|
+
this.spawnStrokeColor.h = this._setColorAnimation(strokeHslAnimation.h, this.spawnStrokeColor.h, maxValues.h, colorFactor);
|
|
309
|
+
this.spawnStrokeColor.s = this._setColorAnimation(strokeHslAnimation.s, this.spawnStrokeColor.s, maxValues.s);
|
|
310
|
+
this.spawnStrokeColor.l = this._setColorAnimation(strokeHslAnimation.l, this.spawnStrokeColor.l, maxValues.l);
|
|
276
311
|
}
|
|
277
|
-
|
|
312
|
+
setParticlesOptionsStrokeColor(particlesOptions, this.spawnStrokeColor, this.spawnStrokeOpacity, this.spawnStrokeWidth);
|
|
278
313
|
}
|
|
279
314
|
let position = this.position;
|
|
280
315
|
if (this._shape) {
|
|
@@ -283,17 +318,7 @@ export class EmitterInstance {
|
|
|
283
318
|
position = shapePosData.position;
|
|
284
319
|
const replaceData = shapeOptions.replace;
|
|
285
320
|
if (replaceData.color && shapePosData.color) {
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
if (replaceData.opacity) {
|
|
289
|
-
if (particlesOptions.opacity) {
|
|
290
|
-
particlesOptions.opacity.value = shapePosData.opacity;
|
|
291
|
-
}
|
|
292
|
-
else {
|
|
293
|
-
particlesOptions.opacity = {
|
|
294
|
-
value: shapePosData.opacity,
|
|
295
|
-
};
|
|
296
|
-
}
|
|
321
|
+
setParticlesOptionsFillColor(particlesOptions, shapePosData.color, replaceData.opacity ? (shapePosData.opacity ?? defaultOpacity) : defaultOpacity, true);
|
|
297
322
|
}
|
|
298
323
|
}
|
|
299
324
|
else {
|
|
@@ -305,4 +330,23 @@ export class EmitterInstance {
|
|
|
305
330
|
}
|
|
306
331
|
}
|
|
307
332
|
}
|
|
333
|
+
_prepareToDie = () => {
|
|
334
|
+
if (this._paused) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
const duration = this.options.life.duration !== undefined ? getRangeValue(this.options.life.duration) : undefined, minDuration = 0, minLifeCount = 0;
|
|
338
|
+
if ((this._lifeCount > minLifeCount || this._immortal) && duration !== undefined && duration > minDuration) {
|
|
339
|
+
this._duration = duration * millisecondsToSeconds;
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
_setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => {
|
|
343
|
+
const container = this.container;
|
|
344
|
+
if (!animation.enable) {
|
|
345
|
+
return initValue;
|
|
346
|
+
}
|
|
347
|
+
const colorOffset = randomInRangeValue(animation.offset), delay = getRangeValue(this.options.rate.delay), emitFactor = container.retina.reduceFactor
|
|
348
|
+
? (delay * millisecondsToSeconds) / container.retina.reduceFactor
|
|
349
|
+
: Infinity, colorSpeed = getRangeValue(animation.speed);
|
|
350
|
+
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * factor) % maxValue;
|
|
351
|
+
};
|
|
308
352
|
}
|
package/esm/EmitterShapeBase.js
CHANGED
|
@@ -2,6 +2,8 @@ import { isNumber } from "@tsparticles/engine";
|
|
|
2
2
|
import { Emitter } from "./Options/Classes/Emitter.js";
|
|
3
3
|
const defaultIndex = 0;
|
|
4
4
|
export class EmittersInstancesManager {
|
|
5
|
+
_containerArrays;
|
|
6
|
+
_engine;
|
|
5
7
|
constructor(engine) {
|
|
6
8
|
this._containerArrays = new Map();
|
|
7
9
|
this._engine = engine;
|
|
@@ -4,9 +4,13 @@ import { Emitter } from "./Options/Classes/Emitter.js";
|
|
|
4
4
|
import { defaultRandomOptions } from "./constants.js";
|
|
5
5
|
const emittersMode = "emitters";
|
|
6
6
|
export class EmittersInteractor extends ExternalInteractorBase {
|
|
7
|
+
handleClickMode;
|
|
8
|
+
maxDistance;
|
|
9
|
+
_instancesManager;
|
|
7
10
|
constructor(instancesManager, container) {
|
|
8
11
|
super(container);
|
|
9
12
|
this._instancesManager = instancesManager;
|
|
13
|
+
this.maxDistance = 0;
|
|
10
14
|
this.handleClickMode = (mode, interactivityData) => {
|
|
11
15
|
const container = this.container, options = container.actualOptions, modeEmitters = options.interactivity.modes.emitters;
|
|
12
16
|
if (!modeEmitters || mode !== emittersMode) {
|
|
@@ -77,7 +81,7 @@ export class EmittersInteractor extends ExternalInteractorBase {
|
|
|
77
81
|
options.emitters.value.push(tmp);
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
|
-
else if (
|
|
84
|
+
else if ("value" in source.emitters) {
|
|
81
85
|
const emitterModeOptions = source.emitters;
|
|
82
86
|
options.emitters.random.enable = emitterModeOptions.random?.enable ?? options.emitters.random.enable;
|
|
83
87
|
options.emitters.random.count = emitterModeOptions.random?.count ?? options.emitters.random.count;
|
package/esm/EmittersPlugin.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { executeOnSingleOrMultiple, isArray, } from "@tsparticles/engine";
|
|
2
2
|
import { Emitter } from "./Options/Classes/Emitter.js";
|
|
3
3
|
export class EmittersPlugin {
|
|
4
|
+
id = "emitters";
|
|
5
|
+
_instancesManager;
|
|
4
6
|
constructor(instancesManager) {
|
|
5
7
|
this._instancesManager = instancesManager;
|
|
6
|
-
this.id = "emitters";
|
|
7
8
|
}
|
|
8
9
|
async getPlugin(container) {
|
|
9
10
|
const { EmittersPluginInstance } = await import("./EmittersPluginInstance.js");
|
|
@@ -3,13 +3,30 @@ import { EmitterLife } from "./EmitterLife.js";
|
|
|
3
3
|
import { EmitterRate } from "./EmitterRate.js";
|
|
4
4
|
import { EmitterShape } from "./EmitterShape.js";
|
|
5
5
|
import { EmitterSize } from "./EmitterSize.js";
|
|
6
|
+
import { EmitterSpawn } from "./EmitterSpawn.js";
|
|
6
7
|
export class Emitter {
|
|
8
|
+
autoPlay;
|
|
9
|
+
direction;
|
|
10
|
+
domId;
|
|
11
|
+
fill;
|
|
12
|
+
life;
|
|
13
|
+
name;
|
|
14
|
+
particles;
|
|
15
|
+
position;
|
|
16
|
+
rate;
|
|
17
|
+
shape;
|
|
18
|
+
size;
|
|
19
|
+
spawn;
|
|
20
|
+
spawnFillColor;
|
|
21
|
+
spawnStrokeColor;
|
|
22
|
+
startCount;
|
|
7
23
|
constructor() {
|
|
8
24
|
this.autoPlay = true;
|
|
9
25
|
this.fill = true;
|
|
10
26
|
this.life = new EmitterLife();
|
|
11
27
|
this.rate = new EmitterRate();
|
|
12
28
|
this.shape = new EmitterShape();
|
|
29
|
+
this.spawn = new EmitterSpawn();
|
|
13
30
|
this.startCount = 0;
|
|
14
31
|
}
|
|
15
32
|
load(data) {
|
|
@@ -37,6 +54,7 @@ export class Emitter {
|
|
|
37
54
|
});
|
|
38
55
|
this.rate.load(data.rate);
|
|
39
56
|
this.shape.load(data.shape);
|
|
57
|
+
this.spawn.load(data.spawn);
|
|
40
58
|
if (data.position !== undefined) {
|
|
41
59
|
this.position = {};
|
|
42
60
|
if (data.position.x !== undefined) {
|
|
@@ -46,9 +64,13 @@ export class Emitter {
|
|
|
46
64
|
this.position.y = setRangeValue(data.position.y);
|
|
47
65
|
}
|
|
48
66
|
}
|
|
49
|
-
if (data.
|
|
50
|
-
this.
|
|
51
|
-
this.
|
|
67
|
+
if (data.spawnFillColor !== undefined) {
|
|
68
|
+
this.spawnFillColor ??= new AnimatableColor();
|
|
69
|
+
this.spawnFillColor.load(data.spawnFillColor);
|
|
70
|
+
}
|
|
71
|
+
if (data.spawnStrokeColor !== undefined) {
|
|
72
|
+
this.spawnStrokeColor ??= new AnimatableColor();
|
|
73
|
+
this.spawnStrokeColor.load(data.spawnStrokeColor);
|
|
52
74
|
}
|
|
53
75
|
if (data.startCount !== undefined) {
|
|
54
76
|
this.startCount = data.startCount;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { deepExtend, isNull } from "@tsparticles/engine";
|
|
2
2
|
import { EmitterShapeReplace } from "./EmitterShapeReplace.js";
|
|
3
3
|
export class EmitterShape {
|
|
4
|
+
options;
|
|
5
|
+
replace;
|
|
6
|
+
type;
|
|
4
7
|
constructor() {
|
|
5
8
|
this.options = {};
|
|
6
9
|
this.replace = new EmitterShapeReplace();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Fill, Stroke, isNull } from "@tsparticles/engine";
|
|
2
|
+
export class EmitterSpawn {
|
|
3
|
+
fill;
|
|
4
|
+
stroke;
|
|
5
|
+
load(data) {
|
|
6
|
+
if (isNull(data)) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (data.fill) {
|
|
10
|
+
this.fill ??= new Fill();
|
|
11
|
+
this.fill.load(data.fill);
|
|
12
|
+
}
|
|
13
|
+
if (data.stroke) {
|
|
14
|
+
this.stroke ??= new Stroke();
|
|
15
|
+
this.stroke.load(data.stroke);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/index.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
export async function loadEmittersPlugin(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-
|
|
2
|
+
engine.checkVersion("4.0.0-beta.0");
|
|
3
3
|
await engine.register(async (e) => {
|
|
4
|
-
const {
|
|
5
|
-
|
|
4
|
+
const [{ ensureInteractivityPluginLoaded }, { ShapeManager }, { EmittersInstancesManager }, { EmittersPlugin },] = await Promise.all([
|
|
5
|
+
import("@tsparticles/plugin-interactivity"),
|
|
6
|
+
import("./ShapeManager.js"),
|
|
7
|
+
import("./EmittersInstancesManager.js"),
|
|
8
|
+
import("./EmittersPlugin.js"),
|
|
9
|
+
]), instancesManager = new EmittersInstancesManager(e);
|
|
10
|
+
ensureInteractivityPluginLoaded(e);
|
|
6
11
|
e.emitterShapeManager ??= new ShapeManager();
|
|
7
12
|
e.addEmitterShapeGenerator ??= (name, generator) => {
|
|
8
13
|
e.emitterShapeManager?.addShapeGenerator(name, generator);
|
|
@@ -14,5 +19,10 @@ export async function loadEmittersPlugin(engine) {
|
|
|
14
19
|
});
|
|
15
20
|
});
|
|
16
21
|
}
|
|
22
|
+
export function ensureEmittersPluginLoaded(e) {
|
|
23
|
+
if (!e.addEmitterShapeGenerator) {
|
|
24
|
+
throw new Error("tsParticles Emitters Plugin is not loaded");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
17
27
|
export * from "./EmitterShapeBase.js";
|
|
18
28
|
export * from "./Enums/EmitterClickMode.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/plugin-emitters",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-beta.0",
|
|
4
4
|
"description": "tsParticles emitters plugin",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -86,8 +86,8 @@
|
|
|
86
86
|
"./package.json": "./package.json"
|
|
87
87
|
},
|
|
88
88
|
"dependencies": {
|
|
89
|
-
"@tsparticles/engine": "4.0.0-
|
|
90
|
-
"@tsparticles/plugin-interactivity": "4.0.0-
|
|
89
|
+
"@tsparticles/engine": "4.0.0-beta.0",
|
|
90
|
+
"@tsparticles/plugin-interactivity": "4.0.0-beta.0"
|
|
91
91
|
},
|
|
92
92
|
"publishConfig": {
|
|
93
93
|
"access": "public"
|