@tsparticles/plugin-emitters 4.0.0-beta.1 → 4.0.0-beta.11

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 (81) hide show
  1. package/{815.min.js → 100.min.js} +1 -1
  2. package/106.min.js +1 -0
  3. package/443.min.js +1 -0
  4. package/475.min.js +1 -0
  5. package/{392.min.js → 515.min.js} +1 -1
  6. package/746.min.js +1 -0
  7. package/{414.min.js → 812.min.js} +1 -1
  8. package/903.min.js +1 -0
  9. package/README.md +27 -0
  10. package/browser/EmitterInstance.js +13 -9
  11. package/browser/addEmittersShapesManager.js +7 -0
  12. package/browser/ensureEmittersPluginLoaded.js +5 -0
  13. package/browser/getEmittersInstancesManager.js +15 -0
  14. package/browser/index.js +5 -24
  15. package/browser/interaction.js +18 -0
  16. package/browser/plugin.js +14 -0
  17. package/cjs/EmitterInstance.js +13 -9
  18. package/cjs/addEmittersShapesManager.js +7 -0
  19. package/cjs/ensureEmittersPluginLoaded.js +5 -0
  20. package/cjs/getEmittersInstancesManager.js +15 -0
  21. package/cjs/index.js +5 -24
  22. package/cjs/interaction.js +18 -0
  23. package/cjs/plugin.js +14 -0
  24. package/dist_browser_EmitterInstance_js.js +2 -2
  25. package/dist_browser_EmittersInstancesManager_js.js +1 -1
  26. package/dist_browser_EmittersInteractor_js.js +1 -1
  27. package/dist_browser_EmittersPluginInstance_js.js +1 -1
  28. package/dist_browser_EmittersPlugin_js.js +1 -1
  29. package/dist_browser_ShapeManager_js.js +1 -1
  30. package/dist_browser_addEmittersShapesManager_js.js +30 -0
  31. package/dist_browser_getEmittersInstancesManager_js.js +30 -0
  32. package/esm/EmitterInstance.js +13 -9
  33. package/esm/addEmittersShapesManager.js +7 -0
  34. package/esm/ensureEmittersPluginLoaded.js +5 -0
  35. package/esm/getEmittersInstancesManager.js +15 -0
  36. package/esm/index.js +5 -24
  37. package/esm/interaction.js +18 -0
  38. package/esm/plugin.js +14 -0
  39. package/package.json +24 -6
  40. package/report.html +1 -1
  41. package/tsparticles.plugin.emitters.js +32 -2
  42. package/tsparticles.plugin.emitters.min.js +2 -2
  43. package/types/addEmittersShapesManager.d.ts +2 -0
  44. package/types/ensureEmittersPluginLoaded.d.ts +2 -0
  45. package/types/getEmittersInstancesManager.d.ts +3 -0
  46. package/types/index.d.ts +1 -1
  47. package/types/interaction.d.ts +9 -0
  48. package/types/plugin.d.ts +9 -0
  49. package/399.min.js +0 -1
  50. package/592.min.js +0 -1
  51. package/764.min.js +0 -1
  52. package/umd/EmitterContainer.js +0 -12
  53. package/umd/EmitterInstance.js +0 -358
  54. package/umd/EmitterShapeBase.js +0 -30
  55. package/umd/EmittersEngine.js +0 -12
  56. package/umd/EmittersInstancesManager.js +0 -119
  57. package/umd/EmittersInteractor.js +0 -130
  58. package/umd/EmittersPlugin.js +0 -80
  59. package/umd/EmittersPluginInstance.js +0 -58
  60. package/umd/Enums/EmitterClickMode.js +0 -17
  61. package/umd/IEmitterShape.js +0 -12
  62. package/umd/IEmitterShapeGenerator.js +0 -12
  63. package/umd/IRandomPositionData.js +0 -12
  64. package/umd/Options/Classes/Emitter.js +0 -93
  65. package/umd/Options/Classes/EmitterLife.js +0 -41
  66. package/umd/Options/Classes/EmitterRate.js +0 -34
  67. package/umd/Options/Classes/EmitterShape.js +0 -38
  68. package/umd/Options/Classes/EmitterShapeReplace.js +0 -34
  69. package/umd/Options/Classes/EmitterSize.js +0 -39
  70. package/umd/Options/Classes/EmitterSpawn.js +0 -32
  71. package/umd/Options/Interfaces/IEmitter.js +0 -12
  72. package/umd/Options/Interfaces/IEmitterLife.js +0 -12
  73. package/umd/Options/Interfaces/IEmitterRate.js +0 -12
  74. package/umd/Options/Interfaces/IEmitterShape.js +0 -12
  75. package/umd/Options/Interfaces/IEmitterShapeReplace.js +0 -12
  76. package/umd/Options/Interfaces/IEmitterSize.js +0 -12
  77. package/umd/Options/Interfaces/IEmitterSpawn.js +0 -12
  78. package/umd/ShapeManager.js +0 -28
  79. package/umd/constants.js +0 -17
  80. package/umd/index.js +0 -79
  81. package/umd/types.js +0 -12
@@ -1,358 +0,0 @@
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", "./Options/Classes/Emitter.js", "./Options/Classes/EmitterSize.js"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.EmitterInstance = void 0;
13
- const engine_1 = require("@tsparticles/engine");
14
- const Emitter_js_1 = require("./Options/Classes/Emitter.js");
15
- const EmitterSize_js_1 = require("./Options/Classes/EmitterSize.js");
16
- const defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1, defaultColorAnimationFactor = 1, colorFactor = 3.6, defaultStrokeWidth = 1;
17
- function setParticlesOptionsFillColor(particlesOptions, color, opacity, enable) {
18
- particlesOptions.fill = new engine_1.Fill();
19
- particlesOptions.fill.color = engine_1.AnimatableColor.create(undefined, { value: color });
20
- particlesOptions.fill.enable = enable;
21
- particlesOptions.fill.opacity = opacity;
22
- }
23
- function setParticlesOptionsStrokeColor(particlesOptions, color, opacity, width) {
24
- particlesOptions.stroke = new engine_1.Stroke();
25
- particlesOptions.stroke.color = engine_1.AnimatableColor.create(undefined, { value: color });
26
- particlesOptions.stroke.opacity = opacity;
27
- particlesOptions.stroke.width = width;
28
- }
29
- class EmitterInstance {
30
- fill;
31
- name;
32
- options;
33
- position;
34
- size;
35
- spawnFillColor;
36
- spawnFillEnabled;
37
- spawnFillOpacity;
38
- spawnStrokeColor;
39
- spawnStrokeOpacity;
40
- spawnStrokeWidth;
41
- _container;
42
- _currentDuration;
43
- _currentEmitDelay;
44
- _currentSpawnDelay;
45
- _duration;
46
- _emitDelay;
47
- _firstSpawn;
48
- _immortal;
49
- _initialPosition;
50
- _lifeCount;
51
- _mutationObserver;
52
- _particlesOptions;
53
- _paused;
54
- _pluginManager;
55
- _removeCallback;
56
- _resizeObserver;
57
- _shape;
58
- _size;
59
- _spawnDelay;
60
- _startParticlesAdded;
61
- constructor(pluginManager, container, removeCallback, options, position) {
62
- this._pluginManager = pluginManager;
63
- this._container = container;
64
- this._removeCallback = removeCallback;
65
- this._currentDuration = 0;
66
- this._currentEmitDelay = 0;
67
- this._currentSpawnDelay = 0;
68
- this._initialPosition = position;
69
- if (options instanceof Emitter_js_1.Emitter) {
70
- this.options = options;
71
- }
72
- else {
73
- this.options = new Emitter_js_1.Emitter();
74
- this.options.load(options);
75
- }
76
- this._spawnDelay = container.retina.reduceFactor
77
- ? ((0, engine_1.getRangeValue)(this.options.life.delay ?? defaultLifeDelay) * engine_1.millisecondsToSeconds) /
78
- container.retina.reduceFactor
79
- : Infinity;
80
- this.position = this._initialPosition ?? this._calcPosition();
81
- this.name = this.options.name;
82
- this.fill = this.options.fill;
83
- this._firstSpawn = !this.options.life.wait;
84
- this._startParticlesAdded = false;
85
- const particlesOptions = (0, engine_1.deepExtend)({}, this.options.particles);
86
- particlesOptions.move ??= {};
87
- particlesOptions.move.direction ??= this.options.direction;
88
- if (this.options.spawn.fill?.color) {
89
- this.spawnFillColor = (0, engine_1.rangeColorToHsl)(this._pluginManager, this.options.spawn.fill.color);
90
- }
91
- if (this.options.spawn.stroke?.color) {
92
- this.spawnStrokeColor = (0, engine_1.rangeColorToHsl)(this._pluginManager, this.options.spawn.stroke.color);
93
- }
94
- this._paused = !this.options.autoPlay;
95
- this._particlesOptions = particlesOptions;
96
- this._size = this._calcSize();
97
- this.size = (0, engine_1.getSize)(this._size, this._container.canvas.size);
98
- this._lifeCount = this.options.life.count ?? defaultLifeCount;
99
- this._immortal = this._lifeCount <= minLifeCount;
100
- if (this.options.domId) {
101
- const element = (0, engine_1.safeDocument)().getElementById(this.options.domId);
102
- if (element) {
103
- this._mutationObserver = new MutationObserver(() => {
104
- this.resize();
105
- });
106
- this._resizeObserver = new ResizeObserver(() => {
107
- this.resize();
108
- });
109
- this._mutationObserver.observe(element, {
110
- attributes: true,
111
- attributeFilter: ["style", "width", "height"],
112
- });
113
- this._resizeObserver.observe(element);
114
- }
115
- }
116
- const shapeOptions = this.options.shape, shapeGenerator = this._pluginManager.emitterShapeManager?.getShapeGenerator(shapeOptions.type);
117
- if (shapeGenerator) {
118
- this._shape = shapeGenerator.generate(this._container, this.position, this.size, this.fill, shapeOptions.options);
119
- }
120
- this._container.dispatchEvent("emitterCreated", {
121
- emitter: this,
122
- });
123
- this.play();
124
- }
125
- externalPause() {
126
- this._paused = true;
127
- this.pause();
128
- }
129
- externalPlay() {
130
- this._paused = false;
131
- this.play();
132
- }
133
- async init() {
134
- await this._shape?.init();
135
- }
136
- pause() {
137
- if (this._paused) {
138
- return;
139
- }
140
- delete this._emitDelay;
141
- }
142
- play() {
143
- if (this._paused) {
144
- return;
145
- }
146
- if (!((this._lifeCount > minLifeCount || this._immortal || !this.options.life.count) &&
147
- (this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? defaultSpawnDelay)))) {
148
- return;
149
- }
150
- const container = this._container;
151
- if (this._emitDelay === undefined) {
152
- const delay = (0, engine_1.getRangeValue)(this.options.rate.delay);
153
- this._emitDelay = container.retina.reduceFactor
154
- ? (delay * engine_1.millisecondsToSeconds) / container.retina.reduceFactor
155
- : Infinity;
156
- }
157
- if (this._lifeCount > minLifeCount || this._immortal) {
158
- this._prepareToDie();
159
- }
160
- }
161
- resize() {
162
- const initialPosition = this._initialPosition, container = this._container;
163
- this.position =
164
- initialPosition && (0, engine_1.isPointInside)(initialPosition, container.canvas.size, engine_1.Vector.origin)
165
- ? initialPosition
166
- : this._calcPosition();
167
- this._size = this._calcSize();
168
- this.size = (0, engine_1.getSize)(this._size, container.canvas.size);
169
- this._shape?.resize(this.position, this.size);
170
- }
171
- update(delta) {
172
- if (this._paused) {
173
- return;
174
- }
175
- const container = this._container;
176
- if (this._firstSpawn) {
177
- this._firstSpawn = false;
178
- this._currentSpawnDelay = this._spawnDelay ?? defaultSpawnDelay;
179
- this._currentEmitDelay = this._emitDelay ?? defaultEmitDelay;
180
- }
181
- if (!this._startParticlesAdded) {
182
- this._startParticlesAdded = true;
183
- this._emitParticles(this.options.startCount);
184
- }
185
- if (this._duration !== undefined) {
186
- this._currentDuration += delta.value;
187
- if (this._currentDuration >= this._duration) {
188
- this.pause();
189
- if (this._spawnDelay !== undefined) {
190
- delete this._spawnDelay;
191
- }
192
- if (!this._immortal) {
193
- this._lifeCount--;
194
- }
195
- if (this._lifeCount > minLifeCount || this._immortal) {
196
- this.position = this._calcPosition();
197
- this._shape?.resize(this.position, this.size);
198
- this._spawnDelay = container.retina.reduceFactor
199
- ? ((0, engine_1.getRangeValue)(this.options.life.delay ?? defaultLifeDelay) * engine_1.millisecondsToSeconds) /
200
- container.retina.reduceFactor
201
- : Infinity;
202
- }
203
- else {
204
- this._destroy();
205
- }
206
- this._currentDuration -= this._duration;
207
- delete this._duration;
208
- }
209
- }
210
- if (this._spawnDelay !== undefined) {
211
- this._currentSpawnDelay += delta.value;
212
- if (this._currentSpawnDelay >= this._spawnDelay) {
213
- this._container.dispatchEvent("emitterPlay");
214
- this.play();
215
- this._currentSpawnDelay -= this._spawnDelay;
216
- delete this._spawnDelay;
217
- }
218
- }
219
- if (this._emitDelay !== undefined) {
220
- this._currentEmitDelay += delta.value;
221
- if (this._currentEmitDelay >= this._emitDelay) {
222
- this._emit();
223
- this._currentEmitDelay -= this._emitDelay;
224
- }
225
- }
226
- }
227
- _calcPosition() {
228
- const container = this._container;
229
- if (this.options.domId) {
230
- const element = (0, engine_1.safeDocument)().getElementById(this.options.domId);
231
- if (element) {
232
- const elRect = element.getBoundingClientRect(), pxRatio = container.retina.pixelRatio;
233
- return {
234
- x: (elRect.x + elRect.width * engine_1.half) * pxRatio,
235
- y: (elRect.y + elRect.height * engine_1.half) * pxRatio,
236
- };
237
- }
238
- }
239
- return (0, engine_1.calcPositionOrRandomFromSizeRanged)({
240
- size: container.canvas.size,
241
- position: this.options.position,
242
- });
243
- }
244
- _calcSize() {
245
- const container = this._container;
246
- if (this.options.domId) {
247
- const element = (0, engine_1.safeDocument)().getElementById(this.options.domId);
248
- if (element) {
249
- const elRect = element.getBoundingClientRect();
250
- return {
251
- width: elRect.width * container.retina.pixelRatio,
252
- height: elRect.height * container.retina.pixelRatio,
253
- mode: engine_1.PixelMode.precise,
254
- };
255
- }
256
- }
257
- return (this.options.size ??
258
- (() => {
259
- const size = new EmitterSize_js_1.EmitterSize();
260
- size.load({
261
- height: 0,
262
- mode: engine_1.PixelMode.percent,
263
- width: 0,
264
- });
265
- return size;
266
- })());
267
- }
268
- _destroy = () => {
269
- this._mutationObserver?.disconnect();
270
- this._mutationObserver = undefined;
271
- this._resizeObserver?.disconnect();
272
- this._resizeObserver = undefined;
273
- this._removeCallback(this);
274
- this._container.dispatchEvent("emitterDestroyed", {
275
- emitter: this,
276
- });
277
- };
278
- _emit() {
279
- if (this._paused) {
280
- return;
281
- }
282
- const quantity = (0, engine_1.getRangeValue)(this.options.rate.quantity);
283
- this._emitParticles(quantity);
284
- }
285
- _emitParticles(quantity) {
286
- const singleParticlesOptions = ((0, engine_1.itemFromSingleOrMultiple)(this._particlesOptions) ??
287
- {}), 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
288
- ? engine_1.defaultOpacity
289
- : (0, engine_1.getRangeValue)(this.options.spawn.fill.opacity), strokeHslAnimation = this.options.spawn.stroke?.color?.animation, strokeOpacity = this.options.spawn.stroke?.opacity === undefined
290
- ? engine_1.defaultOpacity
291
- : (0, engine_1.getRangeValue)(this.options.spawn.stroke.opacity), strokeWidth = this.options.spawn.stroke?.width === undefined
292
- ? defaultStrokeWidth
293
- : (0, engine_1.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: engine_1.hMax, s: engine_1.sMax, l: engine_1.lMax } : null, shapeOptions = this.options.shape;
294
- for (let i = 0; i < quantity * reduceFactor; i++) {
295
- const particlesOptions = needsCopy
296
- ? (0, engine_1.deepExtend)({}, singleParticlesOptions)
297
- : singleParticlesOptions;
298
- this.spawnFillOpacity = fillOpacity;
299
- this.spawnFillEnabled = fillEnabled;
300
- this.spawnStrokeOpacity = strokeOpacity;
301
- this.spawnStrokeWidth = strokeWidth;
302
- if (this.spawnFillColor) {
303
- if (fillHslAnimation && maxValues) {
304
- this.spawnFillColor.h = this._setColorAnimation(fillHslAnimation.h, this.spawnFillColor.h, maxValues.h, colorFactor);
305
- this.spawnFillColor.s = this._setColorAnimation(fillHslAnimation.s, this.spawnFillColor.s, maxValues.s);
306
- this.spawnFillColor.l = this._setColorAnimation(fillHslAnimation.l, this.spawnFillColor.l, maxValues.l);
307
- }
308
- setParticlesOptionsFillColor(particlesOptions, this.spawnFillColor, this.spawnFillOpacity, this.spawnFillEnabled);
309
- }
310
- if (this.spawnStrokeColor) {
311
- if (strokeHslAnimation && maxValues) {
312
- this.spawnStrokeColor.h = this._setColorAnimation(strokeHslAnimation.h, this.spawnStrokeColor.h, maxValues.h, colorFactor);
313
- this.spawnStrokeColor.s = this._setColorAnimation(strokeHslAnimation.s, this.spawnStrokeColor.s, maxValues.s);
314
- this.spawnStrokeColor.l = this._setColorAnimation(strokeHslAnimation.l, this.spawnStrokeColor.l, maxValues.l);
315
- }
316
- setParticlesOptionsStrokeColor(particlesOptions, this.spawnStrokeColor, this.spawnStrokeOpacity, this.spawnStrokeWidth);
317
- }
318
- let position = this.position;
319
- if (this._shape) {
320
- const shapePosData = this._shape.randomPosition();
321
- if (shapePosData) {
322
- position = shapePosData.position;
323
- const replaceData = shapeOptions.replace;
324
- if (replaceData.color && shapePosData.color) {
325
- setParticlesOptionsFillColor(particlesOptions, shapePosData.color, replaceData.opacity ? (shapePosData.opacity ?? engine_1.defaultOpacity) : engine_1.defaultOpacity, true);
326
- }
327
- }
328
- else {
329
- position = null;
330
- }
331
- }
332
- if (position) {
333
- this._container.particles.addParticle(position, particlesOptions);
334
- }
335
- }
336
- }
337
- _prepareToDie = () => {
338
- if (this._paused) {
339
- return;
340
- }
341
- const duration = this.options.life.duration !== undefined ? (0, engine_1.getRangeValue)(this.options.life.duration) : undefined, minDuration = 0, minLifeCount = 0;
342
- if ((this._lifeCount > minLifeCount || this._immortal) && duration !== undefined && duration > minDuration) {
343
- this._duration = duration * engine_1.millisecondsToSeconds;
344
- }
345
- };
346
- _setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => {
347
- const container = this._container;
348
- if (!animation.enable) {
349
- return initValue;
350
- }
351
- const colorOffset = (0, engine_1.randomInRangeValue)(animation.offset), delay = (0, engine_1.getRangeValue)(this.options.rate.delay), emitFactor = container.retina.reduceFactor
352
- ? (delay * engine_1.millisecondsToSeconds) / container.retina.reduceFactor
353
- : Infinity, colorSpeed = (0, engine_1.getRangeValue)(animation.speed);
354
- return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * factor) % maxValue;
355
- };
356
- }
357
- exports.EmitterInstance = EmitterInstance;
358
- });
@@ -1,30 +0,0 @@
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
- fill;
15
- options;
16
- position;
17
- size;
18
- constructor(position, size, fill, options) {
19
- this.position = position;
20
- this.size = size;
21
- this.fill = fill;
22
- this.options = options;
23
- }
24
- resize(position, size) {
25
- this.position = position;
26
- this.size = size;
27
- }
28
- }
29
- exports.EmitterShapeBase = EmitterShapeBase;
30
- });
@@ -1,12 +0,0 @@
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
- });
@@ -1,119 +0,0 @@
1
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
2
- if (k2 === undefined) k2 = k;
3
- var desc = Object.getOwnPropertyDescriptor(m, k);
4
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
5
- desc = { enumerable: true, get: function() { return m[k]; } };
6
- }
7
- Object.defineProperty(o, k2, desc);
8
- }) : (function(o, m, k, k2) {
9
- if (k2 === undefined) k2 = k;
10
- o[k2] = m[k];
11
- }));
12
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
13
- Object.defineProperty(o, "default", { enumerable: true, value: v });
14
- }) : function(o, v) {
15
- o["default"] = v;
16
- });
17
- var __importStar = (this && this.__importStar) || (function () {
18
- var ownKeys = function(o) {
19
- ownKeys = Object.getOwnPropertyNames || function (o) {
20
- var ar = [];
21
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
22
- return ar;
23
- };
24
- return ownKeys(o);
25
- };
26
- return function (mod) {
27
- if (mod && mod.__esModule) return mod;
28
- var result = {};
29
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
30
- __setModuleDefault(result, mod);
31
- return result;
32
- };
33
- })();
34
- (function (factory) {
35
- if (typeof module === "object" && typeof module.exports === "object") {
36
- var v = factory(require, exports);
37
- if (v !== undefined) module.exports = v;
38
- }
39
- else if (typeof define === "function" && define.amd) {
40
- define(["require", "exports", "@tsparticles/engine", "./Options/Classes/Emitter.js"], factory);
41
- }
42
- })(function (require, exports) {
43
- "use strict";
44
- var __syncRequire = typeof module === "object" && typeof module.exports === "object";
45
- Object.defineProperty(exports, "__esModule", { value: true });
46
- exports.EmittersInstancesManager = void 0;
47
- const engine_1 = require("@tsparticles/engine");
48
- const Emitter_js_1 = require("./Options/Classes/Emitter.js");
49
- const defaultIndex = 0;
50
- class EmittersInstancesManager {
51
- _containerArrays;
52
- _pluginManager;
53
- constructor(pluginManager) {
54
- this._containerArrays = new Map();
55
- this._pluginManager = pluginManager;
56
- }
57
- async addEmitter(container, options, position) {
58
- const emitterOptions = new Emitter_js_1.Emitter();
59
- emitterOptions.load(options);
60
- const { EmitterInstance } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./EmitterInstance.js"))) : new Promise((resolve_1, reject_1) => { require(["./EmitterInstance.js"], resolve_1, reject_1); }).then(__importStar)), emitter = new EmitterInstance(this._pluginManager, container, (emitter) => {
61
- this.removeEmitter(container, emitter);
62
- }, emitterOptions, position);
63
- await emitter.init();
64
- this.getArray(container).push(emitter);
65
- return emitter;
66
- }
67
- clear(container) {
68
- this.initContainer(container);
69
- this._containerArrays.set(container, []);
70
- }
71
- getArray(container) {
72
- this.initContainer(container);
73
- let array = this._containerArrays.get(container);
74
- if (!array) {
75
- array = [];
76
- this._containerArrays.set(container, array);
77
- }
78
- return array;
79
- }
80
- initContainer(container) {
81
- if (this._containerArrays.has(container)) {
82
- return;
83
- }
84
- this._containerArrays.set(container, []);
85
- container.getEmitter = (idxOrName) => {
86
- const array = this.getArray(container);
87
- return idxOrName === undefined || (0, engine_1.isNumber)(idxOrName)
88
- ? array[idxOrName ?? defaultIndex]
89
- : array.find(t => t.name === idxOrName);
90
- };
91
- container.addEmitter = async (options, position) => this.addEmitter(container, options, position);
92
- container.removeEmitter = (idxOrName) => {
93
- const emitter = container.getEmitter?.(idxOrName);
94
- if (emitter) {
95
- this.removeEmitter(container, emitter);
96
- }
97
- };
98
- container.playEmitter = (idxOrName) => {
99
- const emitter = container.getEmitter?.(idxOrName);
100
- if (emitter) {
101
- emitter.externalPlay();
102
- }
103
- };
104
- container.pauseEmitter = (idxOrName) => {
105
- const emitter = container.getEmitter?.(idxOrName);
106
- if (emitter) {
107
- emitter.externalPause();
108
- }
109
- };
110
- }
111
- removeEmitter(container, emitter) {
112
- const index = this.getArray(container).indexOf(emitter), minIndex = 0, deleteCount = 1;
113
- if (index >= minIndex) {
114
- this.getArray(container).splice(index, deleteCount);
115
- }
116
- }
117
- }
118
- exports.EmittersInstancesManager = EmittersInstancesManager;
119
- });
@@ -1,130 +0,0 @@
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/plugin-interactivity", "@tsparticles/engine", "./Options/Classes/Emitter.js", "./constants.js"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.EmittersInteractor = void 0;
13
- const plugin_interactivity_1 = require("@tsparticles/plugin-interactivity");
14
- const engine_1 = require("@tsparticles/engine");
15
- const Emitter_js_1 = require("./Options/Classes/Emitter.js");
16
- const constants_js_1 = require("./constants.js");
17
- const emittersMode = "emitters";
18
- class EmittersInteractor extends plugin_interactivity_1.ExternalInteractorBase {
19
- handleClickMode;
20
- maxDistance;
21
- _instancesManager;
22
- constructor(instancesManager, container) {
23
- super(container);
24
- this._instancesManager = instancesManager;
25
- this.maxDistance = 0;
26
- this.handleClickMode = (mode, interactivityData) => {
27
- const container = this.container, options = container.actualOptions, modeEmitters = options.interactivity.modes.emitters;
28
- if (!modeEmitters || mode !== emittersMode) {
29
- return;
30
- }
31
- let emittersModeOptions;
32
- if ((0, engine_1.isArray)(modeEmitters.value)) {
33
- const minLength = 0, modeEmittersCount = modeEmitters.value.length;
34
- if (modeEmittersCount > minLength && modeEmitters.random.enable) {
35
- emittersModeOptions = [];
36
- const usedIndexes = new Set();
37
- for (let i = 0; i < modeEmitters.random.count; i++) {
38
- const idx = (0, engine_1.arrayRandomIndex)(modeEmitters.value);
39
- if (usedIndexes.has(idx) && usedIndexes.size < modeEmittersCount) {
40
- i--;
41
- continue;
42
- }
43
- usedIndexes.add(idx);
44
- const selectedOptions = (0, engine_1.itemFromArray)(modeEmitters.value, idx);
45
- if (!selectedOptions) {
46
- continue;
47
- }
48
- emittersModeOptions.push(selectedOptions);
49
- }
50
- }
51
- else {
52
- emittersModeOptions = modeEmitters.value;
53
- }
54
- }
55
- else {
56
- emittersModeOptions = modeEmitters.value;
57
- }
58
- const emittersOptions = emittersModeOptions, ePosition = interactivityData.mouse.clickPosition;
59
- void (0, engine_1.executeOnSingleOrMultiple)(emittersOptions, async (emitter) => {
60
- await this._instancesManager.addEmitter(this.container, emitter, ePosition);
61
- });
62
- };
63
- }
64
- clear() {
65
- }
66
- init() {
67
- }
68
- interact(_interactivityData, delta) {
69
- for (const emitter of this._instancesManager.getArray(this.container)) {
70
- emitter.update(delta);
71
- }
72
- }
73
- isEnabled(interactivityData, particle) {
74
- const container = this.container, options = container.actualOptions, mouse = interactivityData.mouse, events = (particle?.interactivity ?? options.interactivity).events;
75
- if (!mouse.clickPosition || !events.onClick.enable) {
76
- return false;
77
- }
78
- return (0, engine_1.isInArray)(emittersMode, events.onClick.mode);
79
- }
80
- loadModeOptions(options, ...sources) {
81
- options.emitters = {
82
- random: constants_js_1.defaultRandomOptions,
83
- value: [],
84
- };
85
- for (const source of sources) {
86
- if (!source?.emitters) {
87
- continue;
88
- }
89
- if ((0, engine_1.isArray)(source.emitters)) {
90
- for (const emitter of source.emitters) {
91
- const tmp = new Emitter_js_1.Emitter();
92
- tmp.load(emitter);
93
- options.emitters.value.push(tmp);
94
- }
95
- }
96
- else if ("value" in source.emitters) {
97
- const emitterModeOptions = source.emitters;
98
- options.emitters.random.enable = emitterModeOptions.random?.enable ?? options.emitters.random.enable;
99
- options.emitters.random.count = emitterModeOptions.random?.count ?? options.emitters.random.count;
100
- if ((0, engine_1.isArray)(emitterModeOptions.value)) {
101
- for (const emitter of emitterModeOptions.value) {
102
- const tmp = new Emitter_js_1.Emitter();
103
- tmp.load(emitter);
104
- options.emitters.value.push(tmp);
105
- }
106
- }
107
- else {
108
- const tmp = new Emitter_js_1.Emitter();
109
- tmp.load(emitterModeOptions.value);
110
- options.emitters.value.push(tmp);
111
- }
112
- }
113
- else {
114
- const tmp = new Emitter_js_1.Emitter();
115
- tmp.load(source.emitters);
116
- options.emitters.value.push(tmp);
117
- }
118
- }
119
- }
120
- removeEmitter(emitter) {
121
- const index = this._instancesManager.getArray(this.container).indexOf(emitter), minIndex = 0, deleteCount = 1;
122
- if (index >= minIndex) {
123
- this._instancesManager.getArray(this.container).splice(index, deleteCount);
124
- }
125
- }
126
- reset() {
127
- }
128
- }
129
- exports.EmittersInteractor = EmittersInteractor;
130
- });