@tsparticles/plugin-emitters 3.0.0-beta.2 → 3.0.0-beta.4
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/browser/EmitterInstance.js +133 -80
- package/browser/EmitterShapeBase.js +12 -0
- package/browser/Emitters.js +7 -6
- package/browser/Options/Classes/Emitter.js +3 -4
- package/browser/Options/Classes/EmitterShape.js +21 -0
- package/browser/Options/Classes/EmitterShapeReplace.js +17 -0
- package/browser/Options/Interfaces/IEmitterShape.js +1 -0
- package/browser/Options/Interfaces/IEmitterShapeReplace.js +1 -0
- package/browser/ShapeManager.js +8 -8
- package/browser/index.js +7 -8
- package/cjs/EmitterInstance.js +133 -80
- package/cjs/EmitterShapeBase.js +16 -0
- package/cjs/Emitters.js +7 -6
- package/cjs/IRandomPositionData.js +2 -0
- package/cjs/Options/Classes/Emitter.js +3 -4
- package/cjs/Options/Classes/EmitterShape.js +25 -0
- package/cjs/Options/Classes/EmitterShapeReplace.js +21 -0
- package/cjs/Options/Interfaces/IEmitterShape.js +2 -0
- package/cjs/Options/Interfaces/IEmitterShapeReplace.js +2 -0
- package/cjs/ShapeManager.js +8 -8
- package/cjs/index.js +7 -8
- package/esm/EmitterInstance.js +133 -80
- package/esm/EmitterShapeBase.js +12 -0
- package/esm/Emitters.js +7 -6
- package/esm/IEmitterShapeGenerator.js +1 -0
- package/esm/IRandomPositionData.js +1 -0
- package/esm/Options/Classes/Emitter.js +3 -4
- package/esm/Options/Classes/EmitterShape.js +21 -0
- package/esm/Options/Classes/EmitterShapeReplace.js +17 -0
- package/esm/Options/Interfaces/IEmitterShape.js +1 -0
- package/esm/Options/Interfaces/IEmitterShapeReplace.js +1 -0
- package/esm/ShapeManager.js +8 -8
- package/esm/index.js +7 -8
- package/package.json +3 -3
- package/report.html +4 -22
- package/tsparticles.plugin.emitters.js +208 -176
- package/tsparticles.plugin.emitters.min.js +1 -1
- package/tsparticles.plugin.emitters.min.js.LICENSE.txt +1 -1
- package/types/EmitterContainer.d.ts +1 -1
- package/types/EmitterInstance.d.ts +11 -9
- package/types/EmitterShapeBase.d.ts +13 -0
- package/types/Emitters.d.ts +2 -2
- package/types/EmittersEngine.d.ts +2 -2
- package/types/IEmitterShape.d.ts +4 -1
- package/types/IEmitterShapeGenerator.d.ts +5 -0
- package/types/IRandomPositionData.d.ts +6 -0
- package/types/Options/Classes/Emitter.d.ts +2 -2
- package/types/Options/Classes/EmitterShape.d.ts +10 -0
- package/types/Options/Classes/EmitterShapeReplace.d.ts +8 -0
- package/types/Options/Interfaces/IEmitter.d.ts +2 -2
- package/types/Options/Interfaces/IEmitterShape.d.ts +6 -0
- package/types/Options/Interfaces/IEmitterShapeReplace.d.ts +4 -0
- package/types/ShapeManager.d.ts +4 -4
- package/types/index.d.ts +4 -1
- package/umd/EmitterInstance.js +133 -80
- package/umd/EmitterShapeBase.js +26 -0
- package/umd/Emitters.js +7 -6
- package/umd/IRandomPositionData.js +12 -0
- package/umd/Options/Classes/Emitter.js +4 -5
- package/umd/Options/Classes/EmitterShape.js +35 -0
- package/umd/Options/Classes/EmitterShapeReplace.js +31 -0
- package/umd/Options/Interfaces/IEmitterShape.js +12 -0
- package/umd/Options/Interfaces/IEmitterShapeReplace.js +12 -0
- package/umd/ShapeManager.js +8 -8
- package/umd/index.js +8 -9
- package/browser/Shapes/Circle/CircleShape.js +0 -24
- package/browser/Shapes/Square/SquareShape.js +0 -40
- package/cjs/Shapes/Circle/CircleShape.js +0 -28
- package/cjs/Shapes/Square/SquareShape.js +0 -44
- package/esm/Shapes/Circle/CircleShape.js +0 -24
- package/esm/Shapes/Square/SquareShape.js +0 -40
- package/types/Enums/EmitterShapeType.d.ts +0 -6
- package/types/Shapes/Circle/CircleShape.d.ts +0 -5
- package/types/Shapes/Square/SquareShape.d.ts +0 -5
- package/umd/Shapes/Circle/CircleShape.js +0 -38
- package/umd/Shapes/Square/SquareShape.js +0 -54
- /package/browser/{Enums/EmitterShapeType.js → IEmitterShapeGenerator.js} +0 -0
- /package/{esm/Enums/EmitterShapeType.js → browser/IRandomPositionData.js} +0 -0
- /package/cjs/{Enums/EmitterShapeType.js → IEmitterShapeGenerator.js} +0 -0
- /package/umd/{Enums/EmitterShapeType.js → IEmitterShapeGenerator.js} +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ICoordinates, IDimension } from "@tsparticles/engine";
|
|
2
|
+
import type { IEmitterShape } from "./IEmitterShape.js";
|
|
3
|
+
import type { IRandomPositionData } from "./IRandomPositionData.js";
|
|
4
|
+
export declare abstract class EmitterShapeBase<TOptions = unknown> implements IEmitterShape {
|
|
5
|
+
fill: boolean;
|
|
6
|
+
options: TOptions;
|
|
7
|
+
position: ICoordinates;
|
|
8
|
+
size: IDimension;
|
|
9
|
+
protected constructor(position: ICoordinates, size: IDimension, fill: boolean, options: TOptions);
|
|
10
|
+
resize(position: ICoordinates, size: IDimension): void;
|
|
11
|
+
abstract init(): Promise<void>;
|
|
12
|
+
abstract randomPosition(): Promise<IRandomPositionData | null>;
|
|
13
|
+
}
|
package/types/Emitters.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare class Emitters implements IContainerPlugin {
|
|
|
12
12
|
interactivityEmitters: EmitterModeOptions;
|
|
13
13
|
private readonly _engine;
|
|
14
14
|
constructor(engine: EmittersEngine, container: EmitterContainer);
|
|
15
|
-
addEmitter(options: RecursivePartial<IEmitter>, position?: ICoordinates): EmitterInstance
|
|
15
|
+
addEmitter(options: RecursivePartial<IEmitter>, position?: ICoordinates): Promise<EmitterInstance>;
|
|
16
16
|
handleClickMode(mode: string): void;
|
|
17
17
|
init(): Promise<void>;
|
|
18
18
|
pause(): void;
|
|
@@ -20,5 +20,5 @@ export declare class Emitters implements IContainerPlugin {
|
|
|
20
20
|
removeEmitter(emitter: EmitterInstance): void;
|
|
21
21
|
resize(): void;
|
|
22
22
|
stop(): void;
|
|
23
|
-
update(delta: IDelta): void
|
|
23
|
+
update(delta: IDelta): Promise<void>;
|
|
24
24
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Engine } from "@tsparticles/engine";
|
|
2
|
-
import type {
|
|
2
|
+
import type { IEmitterShapeGenerator } from "./IEmitterShapeGenerator.js";
|
|
3
3
|
import type { ShapeManager } from "./ShapeManager.js";
|
|
4
4
|
export type EmittersEngine = Engine & {
|
|
5
|
-
|
|
5
|
+
addEmitterShapeGenerator?: (name: string, shape: IEmitterShapeGenerator) => void;
|
|
6
6
|
emitterShapeManager?: ShapeManager;
|
|
7
7
|
};
|
package/types/IEmitterShape.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { ICoordinates, IDimension } from "@tsparticles/engine";
|
|
2
|
+
import type { IRandomPositionData } from "./IRandomPositionData.js";
|
|
2
3
|
export interface IEmitterShape {
|
|
3
|
-
|
|
4
|
+
init(): Promise<void>;
|
|
5
|
+
randomPosition(): Promise<IRandomPositionData | null>;
|
|
6
|
+
resize(position: ICoordinates, size: IDimension): void;
|
|
4
7
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ICoordinates, IDimension } from "@tsparticles/engine";
|
|
2
|
+
import type { IEmitterShape } from "./IEmitterShape.js";
|
|
3
|
+
export interface IEmitterShapeGenerator<TOptions = unknown> {
|
|
4
|
+
generate(position: ICoordinates, size: IDimension, fill: boolean, options: TOptions): IEmitterShape;
|
|
5
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AnimatableColor, type IOptionLoader, type IParticlesOptions, type IRangedCoordinates, type MoveDirection, type MoveDirectionAlt, type RecursivePartial, type SingleOrMultiple } from "@tsparticles/engine";
|
|
2
2
|
import { EmitterLife } from "./EmitterLife.js";
|
|
3
3
|
import { EmitterRate } from "./EmitterRate.js";
|
|
4
|
-
import {
|
|
4
|
+
import { EmitterShape } from "./EmitterShape.js";
|
|
5
5
|
import { EmitterSize } from "./EmitterSize.js";
|
|
6
6
|
import type { IEmitter } from "../Interfaces/IEmitter.js";
|
|
7
7
|
export declare class Emitter implements IEmitter, IOptionLoader<IEmitter> {
|
|
@@ -14,7 +14,7 @@ export declare class Emitter implements IEmitter, IOptionLoader<IEmitter> {
|
|
|
14
14
|
particles?: SingleOrMultiple<RecursivePartial<IParticlesOptions>>;
|
|
15
15
|
position?: RecursivePartial<IRangedCoordinates>;
|
|
16
16
|
rate: EmitterRate;
|
|
17
|
-
shape:
|
|
17
|
+
shape: EmitterShape;
|
|
18
18
|
size?: EmitterSize;
|
|
19
19
|
spawnColor?: AnimatableColor;
|
|
20
20
|
startCount: number;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type IOptionLoader, type RecursivePartial } from "@tsparticles/engine";
|
|
2
|
+
import { EmitterShapeReplace } from "./EmitterShapeReplace.js";
|
|
3
|
+
import type { IEmitterShape } from "../Interfaces/IEmitterShape.js";
|
|
4
|
+
export declare class EmitterShape implements IEmitterShape, IOptionLoader<IEmitterShape> {
|
|
5
|
+
options: Record<string, unknown>;
|
|
6
|
+
replace: EmitterShapeReplace;
|
|
7
|
+
type: string;
|
|
8
|
+
constructor();
|
|
9
|
+
load(data?: RecursivePartial<IEmitterShape> | undefined): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
+
import type { IEmitterShapeReplace } from "../Interfaces/IEmitterShapeReplace.js";
|
|
3
|
+
export declare class EmitterShapeReplace implements IEmitterShapeReplace, IOptionLoader<IEmitterShapeReplace> {
|
|
4
|
+
color: boolean;
|
|
5
|
+
opacity: boolean;
|
|
6
|
+
constructor();
|
|
7
|
+
load(data?: RecursivePartial<IEmitterShapeReplace> | undefined): void;
|
|
8
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IAnimatableColor, IParticlesOptions, IRangedCoordinates, MoveDirection, MoveDirectionAlt, RecursivePartial, SingleOrMultiple } from "@tsparticles/engine";
|
|
2
|
-
import type { EmitterShapeType } from "../../Enums/EmitterShapeType.js";
|
|
3
2
|
import type { IEmitterLife } from "./IEmitterLife.js";
|
|
4
3
|
import type { IEmitterRate } from "./IEmitterRate.js";
|
|
4
|
+
import type { IEmitterShape } from "./IEmitterShape.js";
|
|
5
5
|
import type { IEmitterSize } from "./IEmitterSize.js";
|
|
6
6
|
export interface IEmitter {
|
|
7
7
|
autoPlay: boolean;
|
|
@@ -13,7 +13,7 @@ export interface IEmitter {
|
|
|
13
13
|
particles?: SingleOrMultiple<RecursivePartial<IParticlesOptions>>;
|
|
14
14
|
position?: RecursivePartial<IRangedCoordinates>;
|
|
15
15
|
rate: IEmitterRate;
|
|
16
|
-
shape:
|
|
16
|
+
shape: IEmitterShape;
|
|
17
17
|
size?: IEmitterSize;
|
|
18
18
|
spawnColor?: IAnimatableColor;
|
|
19
19
|
startCount: number;
|
package/types/ShapeManager.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Engine } from "@tsparticles/engine";
|
|
2
|
-
import type {
|
|
2
|
+
import type { IEmitterShapeGenerator } from "./IEmitterShapeGenerator.js";
|
|
3
3
|
export declare class ShapeManager {
|
|
4
4
|
private readonly _engine;
|
|
5
5
|
constructor(engine: Engine);
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
addShapeGenerator(name: string, generator: IEmitterShapeGenerator): void;
|
|
7
|
+
getShapeGenerator(name: string): IEmitterShapeGenerator | undefined;
|
|
8
|
+
getSupportedShapeGenerators(): IterableIterator<string>;
|
|
9
9
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { EmittersEngine } from "./EmittersEngine.js";
|
|
2
2
|
export declare function loadEmittersPlugin(engine: EmittersEngine, refresh?: boolean): Promise<void>;
|
|
3
3
|
export * from "./EmitterContainer.js";
|
|
4
|
+
export * from "./EmitterShapeBase.js";
|
|
4
5
|
export * from "./EmittersEngine.js";
|
|
6
|
+
export * from "./IEmitterShape.js";
|
|
7
|
+
export * from "./IEmitterShapeGenerator.js";
|
|
5
8
|
export * from "./Enums/EmitterClickMode.js";
|
|
6
|
-
export * from "./
|
|
9
|
+
export * from "./IRandomPositionData.js";
|
package/umd/EmitterInstance.js
CHANGED
|
@@ -13,17 +13,25 @@
|
|
|
13
13
|
const engine_1 = require("@tsparticles/engine");
|
|
14
14
|
const Emitter_js_1 = require("./Options/Classes/Emitter.js");
|
|
15
15
|
const EmitterSize_js_1 = require("./Options/Classes/EmitterSize.js");
|
|
16
|
+
function setParticlesOptionsColor(particlesOptions, color) {
|
|
17
|
+
if (particlesOptions.color) {
|
|
18
|
+
particlesOptions.color.value = color;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
particlesOptions.color = {
|
|
22
|
+
value: color,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
16
26
|
class EmitterInstance {
|
|
17
27
|
constructor(engine, emitters, container, options, position) {
|
|
18
28
|
this.emitters = emitters;
|
|
19
29
|
this.container = container;
|
|
20
|
-
this._calcPosition = () => {
|
|
21
|
-
return (0, engine_1.calcPositionOrRandomFromSizeRanged)({
|
|
22
|
-
size: this.container.canvas.size,
|
|
23
|
-
position: this.options.position,
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
30
|
this._destroy = () => {
|
|
31
|
+
this._mutationObserver?.disconnect();
|
|
32
|
+
this._mutationObserver = undefined;
|
|
33
|
+
this._resizeObserver?.disconnect();
|
|
34
|
+
this._resizeObserver = undefined;
|
|
27
35
|
this.emitters.removeEmitter(this);
|
|
28
36
|
this._engine.dispatchEvent("emitterDestroyed", {
|
|
29
37
|
container: this.container,
|
|
@@ -32,40 +40,6 @@
|
|
|
32
40
|
},
|
|
33
41
|
});
|
|
34
42
|
};
|
|
35
|
-
this._emit = () => {
|
|
36
|
-
if (this._paused) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
const quantity = (0, engine_1.getRangeValue)(this.options.rate.quantity);
|
|
40
|
-
this._emitParticles(quantity);
|
|
41
|
-
};
|
|
42
|
-
this._emitParticles = (quantity) => {
|
|
43
|
-
const position = this.getPosition(), size = this.getSize(), singleParticlesOptions = (0, engine_1.itemFromSingleOrMultiple)(this._particlesOptions);
|
|
44
|
-
for (let i = 0; i < quantity; i++) {
|
|
45
|
-
const particlesOptions = (0, engine_1.deepExtend)({}, singleParticlesOptions);
|
|
46
|
-
if (this.spawnColor) {
|
|
47
|
-
const hslAnimation = this.options.spawnColor?.animation;
|
|
48
|
-
if (hslAnimation) {
|
|
49
|
-
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
|
|
50
|
-
this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
|
|
51
|
-
this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
|
|
52
|
-
}
|
|
53
|
-
if (!particlesOptions.color) {
|
|
54
|
-
particlesOptions.color = {
|
|
55
|
-
value: this.spawnColor,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
particlesOptions.color.value = this.spawnColor;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (!position) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const pPosition = this._shape?.randomPosition(position, size, this.fill) ?? position;
|
|
66
|
-
this.container.particles.addParticle(pPosition, particlesOptions);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
43
|
this._prepareToDie = () => {
|
|
70
44
|
if (this._paused) {
|
|
71
45
|
return;
|
|
@@ -101,7 +75,6 @@
|
|
|
101
75
|
this._spawnDelay = ((0, engine_1.getRangeValue)(this.options.life.delay ?? 0) * 1000) / this.container.retina.reduceFactor;
|
|
102
76
|
this.position = this._initialPosition ?? this._calcPosition();
|
|
103
77
|
this.name = this.options.name;
|
|
104
|
-
this._shape = this._engine.emitterShapeManager?.getShape(this.options.shape);
|
|
105
78
|
this.fill = this.options.fill;
|
|
106
79
|
this._firstSpawn = !this.options.life.wait;
|
|
107
80
|
this._startParticlesAdded = false;
|
|
@@ -114,19 +87,30 @@
|
|
|
114
87
|
}
|
|
115
88
|
this._paused = !this.options.autoPlay;
|
|
116
89
|
this._particlesOptions = particlesOptions;
|
|
117
|
-
this.
|
|
118
|
-
|
|
119
|
-
(() => {
|
|
120
|
-
const size = new EmitterSize_js_1.EmitterSize();
|
|
121
|
-
size.load({
|
|
122
|
-
height: 0,
|
|
123
|
-
mode: "percent",
|
|
124
|
-
width: 0,
|
|
125
|
-
});
|
|
126
|
-
return size;
|
|
127
|
-
})();
|
|
90
|
+
this._size = this._calcSize();
|
|
91
|
+
this.size = (0, engine_1.getSize)(this._size, this.container.canvas.size);
|
|
128
92
|
this._lifeCount = this.options.life.count ?? -1;
|
|
129
93
|
this._immortal = this._lifeCount <= 0;
|
|
94
|
+
if (this.options.domId) {
|
|
95
|
+
const element = document.getElementById(this.options.domId);
|
|
96
|
+
if (element) {
|
|
97
|
+
this._mutationObserver = new MutationObserver(() => {
|
|
98
|
+
this.resize();
|
|
99
|
+
});
|
|
100
|
+
this._resizeObserver = new ResizeObserver(() => {
|
|
101
|
+
this.resize();
|
|
102
|
+
});
|
|
103
|
+
this._mutationObserver.observe(element, {
|
|
104
|
+
attributes: true,
|
|
105
|
+
attributeFilter: ["style", "width", "height"],
|
|
106
|
+
});
|
|
107
|
+
this._resizeObserver.observe(element);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const shapeOptions = this.options.shape, shapeGenerator = this._engine.emitterShapeManager?.getShapeGenerator(shapeOptions.type);
|
|
111
|
+
if (shapeGenerator) {
|
|
112
|
+
this._shape = shapeGenerator.generate(this.position, this.size, this.fill, shapeOptions.options);
|
|
113
|
+
}
|
|
130
114
|
this._engine.dispatchEvent("emitterCreated", {
|
|
131
115
|
container,
|
|
132
116
|
data: {
|
|
@@ -143,32 +127,8 @@
|
|
|
143
127
|
this._paused = false;
|
|
144
128
|
this.play();
|
|
145
129
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const container = this.container, element = document.getElementById(this.options.domId);
|
|
149
|
-
if (element) {
|
|
150
|
-
const elRect = element.getBoundingClientRect();
|
|
151
|
-
return {
|
|
152
|
-
x: (elRect.x + elRect.width / 2) * container.retina.pixelRatio,
|
|
153
|
-
y: (elRect.y + elRect.height / 2) * container.retina.pixelRatio,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return this.position;
|
|
158
|
-
}
|
|
159
|
-
getSize() {
|
|
160
|
-
const container = this.container;
|
|
161
|
-
if (this.options.domId) {
|
|
162
|
-
const element = document.getElementById(this.options.domId);
|
|
163
|
-
if (element) {
|
|
164
|
-
const elRect = element.getBoundingClientRect();
|
|
165
|
-
return {
|
|
166
|
-
width: elRect.width * container.retina.pixelRatio,
|
|
167
|
-
height: elRect.height * container.retina.pixelRatio,
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
return (0, engine_1.getSize)(this.size, container.canvas.size);
|
|
130
|
+
async init() {
|
|
131
|
+
await this._shape?.init();
|
|
172
132
|
}
|
|
173
133
|
pause() {
|
|
174
134
|
if (this._paused) {
|
|
@@ -199,8 +159,11 @@
|
|
|
199
159
|
initialPosition && (0, engine_1.isPointInside)(initialPosition, this.container.canvas.size, engine_1.Vector.origin)
|
|
200
160
|
? initialPosition
|
|
201
161
|
: this._calcPosition();
|
|
162
|
+
this._size = this._calcSize();
|
|
163
|
+
this.size = (0, engine_1.getSize)(this._size, this.container.canvas.size);
|
|
164
|
+
this._shape?.resize(this.position, this.size);
|
|
202
165
|
}
|
|
203
|
-
update(delta) {
|
|
166
|
+
async update(delta) {
|
|
204
167
|
if (this._paused) {
|
|
205
168
|
return;
|
|
206
169
|
}
|
|
@@ -211,7 +174,7 @@
|
|
|
211
174
|
}
|
|
212
175
|
if (!this._startParticlesAdded) {
|
|
213
176
|
this._startParticlesAdded = true;
|
|
214
|
-
this._emitParticles(this.options.startCount);
|
|
177
|
+
await this._emitParticles(this.options.startCount);
|
|
215
178
|
}
|
|
216
179
|
if (this._duration !== undefined) {
|
|
217
180
|
this._currentDuration += delta.value;
|
|
@@ -254,6 +217,96 @@
|
|
|
254
217
|
}
|
|
255
218
|
}
|
|
256
219
|
}
|
|
220
|
+
_calcPosition() {
|
|
221
|
+
if (this.options.domId) {
|
|
222
|
+
const container = this.container, element = document.getElementById(this.options.domId);
|
|
223
|
+
if (element) {
|
|
224
|
+
const elRect = element.getBoundingClientRect();
|
|
225
|
+
return {
|
|
226
|
+
x: (elRect.x + elRect.width / 2) * container.retina.pixelRatio,
|
|
227
|
+
y: (elRect.y + elRect.height / 2) * container.retina.pixelRatio,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return (0, engine_1.calcPositionOrRandomFromSizeRanged)({
|
|
232
|
+
size: this.container.canvas.size,
|
|
233
|
+
position: this.options.position,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
_calcSize() {
|
|
237
|
+
const container = this.container;
|
|
238
|
+
if (this.options.domId) {
|
|
239
|
+
const element = document.getElementById(this.options.domId);
|
|
240
|
+
if (element) {
|
|
241
|
+
const elRect = element.getBoundingClientRect();
|
|
242
|
+
return {
|
|
243
|
+
width: elRect.width * container.retina.pixelRatio,
|
|
244
|
+
height: elRect.height * container.retina.pixelRatio,
|
|
245
|
+
mode: "precise",
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return (this.options.size ??
|
|
250
|
+
(() => {
|
|
251
|
+
const size = new EmitterSize_js_1.EmitterSize();
|
|
252
|
+
size.load({
|
|
253
|
+
height: 0,
|
|
254
|
+
mode: "percent",
|
|
255
|
+
width: 0,
|
|
256
|
+
});
|
|
257
|
+
return size;
|
|
258
|
+
})());
|
|
259
|
+
}
|
|
260
|
+
async _emit() {
|
|
261
|
+
if (this._paused) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const quantity = (0, engine_1.getRangeValue)(this.options.rate.quantity);
|
|
265
|
+
await this._emitParticles(quantity);
|
|
266
|
+
}
|
|
267
|
+
async _emitParticles(quantity) {
|
|
268
|
+
const singleParticlesOptions = (0, engine_1.itemFromSingleOrMultiple)(this._particlesOptions);
|
|
269
|
+
for (let i = 0; i < quantity; i++) {
|
|
270
|
+
const particlesOptions = (0, engine_1.deepExtend)({}, singleParticlesOptions);
|
|
271
|
+
if (this.spawnColor) {
|
|
272
|
+
const hslAnimation = this.options.spawnColor?.animation;
|
|
273
|
+
if (hslAnimation) {
|
|
274
|
+
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
|
|
275
|
+
this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
|
|
276
|
+
this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
|
|
277
|
+
}
|
|
278
|
+
setParticlesOptionsColor(particlesOptions, this.spawnColor);
|
|
279
|
+
}
|
|
280
|
+
const shapeOptions = this.options.shape;
|
|
281
|
+
let position = this.position;
|
|
282
|
+
if (this._shape) {
|
|
283
|
+
const shapePosData = await this._shape.randomPosition();
|
|
284
|
+
if (shapePosData) {
|
|
285
|
+
position = shapePosData.position;
|
|
286
|
+
const replaceData = shapeOptions.replace;
|
|
287
|
+
if (replaceData.color && shapePosData.color) {
|
|
288
|
+
setParticlesOptionsColor(particlesOptions, shapePosData.color);
|
|
289
|
+
}
|
|
290
|
+
if (replaceData.opacity) {
|
|
291
|
+
if (particlesOptions.opacity) {
|
|
292
|
+
particlesOptions.opacity.value = shapePosData.opacity;
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
particlesOptions.opacity = {
|
|
296
|
+
value: shapePosData.opacity,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
position = null;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
if (position) {
|
|
306
|
+
this.container.particles.addParticle(position, particlesOptions);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
257
310
|
}
|
|
258
311
|
exports.EmitterInstance = EmitterInstance;
|
|
259
312
|
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.EmitterShapeBase = void 0;
|
|
13
|
+
class EmitterShapeBase {
|
|
14
|
+
constructor(position, size, fill, options) {
|
|
15
|
+
this.position = position;
|
|
16
|
+
this.size = size;
|
|
17
|
+
this.fill = fill;
|
|
18
|
+
this.options = options;
|
|
19
|
+
}
|
|
20
|
+
resize(position, size) {
|
|
21
|
+
this.position = position;
|
|
22
|
+
this.size = size;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.EmitterShapeBase = EmitterShapeBase;
|
|
26
|
+
});
|
package/umd/Emitters.js
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
container.getEmitter = (idxOrName) => idxOrName === undefined || (0, engine_1.isNumber)(idxOrName)
|
|
30
30
|
? this.array[idxOrName || 0]
|
|
31
31
|
: this.array.find((t) => t.name === idxOrName);
|
|
32
|
-
container.addEmitter = (options, position) => this.addEmitter(options, position);
|
|
32
|
+
container.addEmitter = async (options, position) => this.addEmitter(options, position);
|
|
33
33
|
container.removeEmitter = (idxOrName) => {
|
|
34
34
|
const emitter = container.getEmitter(idxOrName);
|
|
35
35
|
if (emitter) {
|
|
@@ -49,10 +49,11 @@
|
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
-
addEmitter(options, position) {
|
|
52
|
+
async addEmitter(options, position) {
|
|
53
53
|
const emitterOptions = new Emitter_js_1.Emitter();
|
|
54
54
|
emitterOptions.load(options);
|
|
55
55
|
const emitter = new EmitterInstance_js_1.EmitterInstance(this._engine, this, this.container, emitterOptions, position);
|
|
56
|
+
await emitter.init();
|
|
56
57
|
this.array.push(emitter);
|
|
57
58
|
return emitter;
|
|
58
59
|
}
|
|
@@ -96,11 +97,11 @@
|
|
|
96
97
|
}
|
|
97
98
|
if ((0, engine_1.isArray)(this.emitters)) {
|
|
98
99
|
for (const emitterOptions of this.emitters) {
|
|
99
|
-
this.addEmitter(emitterOptions);
|
|
100
|
+
await this.addEmitter(emitterOptions);
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
else {
|
|
103
|
-
this.addEmitter(this.emitters);
|
|
104
|
+
await this.addEmitter(this.emitters);
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
pause() {
|
|
@@ -127,9 +128,9 @@
|
|
|
127
128
|
stop() {
|
|
128
129
|
this.array = [];
|
|
129
130
|
}
|
|
130
|
-
update(delta) {
|
|
131
|
+
async update(delta) {
|
|
131
132
|
for (const emitter of this.array) {
|
|
132
|
-
emitter.update(delta);
|
|
133
|
+
await emitter.update(delta);
|
|
133
134
|
}
|
|
134
135
|
}
|
|
135
136
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "@tsparticles/engine", "./EmitterLife.js", "./EmitterRate.js", "./EmitterSize.js"], factory);
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine", "./EmitterLife.js", "./EmitterRate.js", "./EmitterShape.js", "./EmitterSize.js"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
const engine_1 = require("@tsparticles/engine");
|
|
14
14
|
const EmitterLife_js_1 = require("./EmitterLife.js");
|
|
15
15
|
const EmitterRate_js_1 = require("./EmitterRate.js");
|
|
16
|
+
const EmitterShape_js_1 = require("./EmitterShape.js");
|
|
16
17
|
const EmitterSize_js_1 = require("./EmitterSize.js");
|
|
17
18
|
class Emitter {
|
|
18
19
|
constructor() {
|
|
@@ -20,7 +21,7 @@
|
|
|
20
21
|
this.fill = true;
|
|
21
22
|
this.life = new EmitterLife_js_1.EmitterLife();
|
|
22
23
|
this.rate = new EmitterRate_js_1.EmitterRate();
|
|
23
|
-
this.shape =
|
|
24
|
+
this.shape = new EmitterShape_js_1.EmitterShape();
|
|
24
25
|
this.startCount = 0;
|
|
25
26
|
}
|
|
26
27
|
load(data) {
|
|
@@ -49,9 +50,7 @@
|
|
|
49
50
|
return (0, engine_1.deepExtend)({}, particles);
|
|
50
51
|
});
|
|
51
52
|
this.rate.load(data.rate);
|
|
52
|
-
|
|
53
|
-
this.shape = data.shape;
|
|
54
|
-
}
|
|
53
|
+
this.shape.load(data.shape);
|
|
55
54
|
if (data.position !== undefined) {
|
|
56
55
|
this.position = {};
|
|
57
56
|
if (data.position.x !== undefined) {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine", "./EmitterShapeReplace.js"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.EmitterShape = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
const EmitterShapeReplace_js_1 = require("./EmitterShapeReplace.js");
|
|
15
|
+
class EmitterShape {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.options = {};
|
|
18
|
+
this.replace = new EmitterShapeReplace_js_1.EmitterShapeReplace();
|
|
19
|
+
this.type = "square";
|
|
20
|
+
}
|
|
21
|
+
load(data) {
|
|
22
|
+
if (!data) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (data.options !== undefined) {
|
|
26
|
+
this.options = (0, engine_1.deepExtend)({}, data.options ?? {});
|
|
27
|
+
}
|
|
28
|
+
this.replace.load(data.replace);
|
|
29
|
+
if (data.type !== undefined) {
|
|
30
|
+
this.type = data.type;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.EmitterShape = EmitterShape;
|
|
35
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.EmitterShapeReplace = void 0;
|
|
13
|
+
class EmitterShapeReplace {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.color = false;
|
|
16
|
+
this.opacity = false;
|
|
17
|
+
}
|
|
18
|
+
load(data) {
|
|
19
|
+
if (!data) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (data.color !== undefined) {
|
|
23
|
+
this.color = data.color;
|
|
24
|
+
}
|
|
25
|
+
if (data.opacity !== undefined) {
|
|
26
|
+
this.opacity = data.opacity;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.EmitterShapeReplace = EmitterShapeReplace;
|
|
31
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|