@tsparticles/plugin-emitters 4.0.0-alpha.2 → 4.0.0-alpha.20

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 (98) hide show
  1. package/278.min.js +1 -0
  2. package/615.min.js +1 -0
  3. package/751.min.js +1 -0
  4. package/816.min.js +1 -0
  5. package/88.min.js +1 -0
  6. package/975.min.js +1 -0
  7. package/README.md +5 -0
  8. package/browser/EmitterInstance.js +69 -47
  9. package/browser/EmitterShapeBase.js +4 -0
  10. package/browser/EmittersInstancesManager.js +71 -0
  11. package/browser/EmittersInteractor.js +114 -0
  12. package/browser/EmittersPlugin.js +10 -56
  13. package/browser/EmittersPluginInstance.js +44 -0
  14. package/browser/Options/Classes/Emitter.js +13 -0
  15. package/browser/Options/Classes/EmitterLife.js +4 -0
  16. package/browser/Options/Classes/EmitterRate.js +2 -0
  17. package/browser/Options/Classes/EmitterShape.js +3 -0
  18. package/browser/Options/Classes/EmitterShapeReplace.js +2 -0
  19. package/browser/Options/Classes/EmitterSize.js +3 -0
  20. package/browser/ShapeManager.js +4 -4
  21. package/browser/constants.js +4 -0
  22. package/browser/index.js +20 -6
  23. package/cjs/EmitterInstance.js +69 -47
  24. package/cjs/EmitterShapeBase.js +4 -0
  25. package/cjs/EmittersInstancesManager.js +71 -0
  26. package/cjs/EmittersInteractor.js +114 -0
  27. package/cjs/EmittersPlugin.js +10 -56
  28. package/cjs/EmittersPluginInstance.js +44 -0
  29. package/cjs/Options/Classes/Emitter.js +13 -0
  30. package/cjs/Options/Classes/EmitterLife.js +4 -0
  31. package/cjs/Options/Classes/EmitterRate.js +2 -0
  32. package/cjs/Options/Classes/EmitterShape.js +3 -0
  33. package/cjs/Options/Classes/EmitterShapeReplace.js +2 -0
  34. package/cjs/Options/Classes/EmitterSize.js +3 -0
  35. package/cjs/ShapeManager.js +4 -4
  36. package/cjs/constants.js +4 -0
  37. package/cjs/index.js +20 -6
  38. package/dist_browser_EmitterInstance_js.js +30 -0
  39. package/dist_browser_EmittersInstancesManager_js.js +90 -0
  40. package/dist_browser_EmittersInteractor_js.js +100 -0
  41. package/dist_browser_EmittersPluginInstance_js.js +30 -0
  42. package/dist_browser_EmittersPlugin_js.js +8 -28
  43. package/dist_browser_ShapeManager_js.js +2 -2
  44. package/esm/EmitterInstance.js +69 -47
  45. package/esm/EmitterShapeBase.js +4 -0
  46. package/esm/EmittersInstancesManager.js +71 -0
  47. package/esm/EmittersInteractor.js +114 -0
  48. package/esm/EmittersPlugin.js +10 -56
  49. package/esm/EmittersPluginInstance.js +44 -0
  50. package/esm/Options/Classes/Emitter.js +13 -0
  51. package/esm/Options/Classes/EmitterLife.js +4 -0
  52. package/esm/Options/Classes/EmitterRate.js +2 -0
  53. package/esm/Options/Classes/EmitterShape.js +3 -0
  54. package/esm/Options/Classes/EmitterShapeReplace.js +2 -0
  55. package/esm/Options/Classes/EmitterSize.js +3 -0
  56. package/esm/ShapeManager.js +4 -4
  57. package/esm/constants.js +4 -0
  58. package/esm/index.js +20 -6
  59. package/package.json +3 -2
  60. package/report.html +3 -3
  61. package/tsparticles.plugin.emitters.js +58 -18
  62. package/tsparticles.plugin.emitters.min.js +2 -2
  63. package/types/EmitterContainer.d.ts +8 -7
  64. package/types/EmitterInstance.d.ts +2 -3
  65. package/types/EmittersEngine.d.ts +2 -2
  66. package/types/EmittersInstancesManager.d.ts +15 -0
  67. package/types/EmittersInteractor.d.ts +18 -0
  68. package/types/EmittersPlugin.d.ts +7 -8
  69. package/types/EmittersPluginInstance.d.ts +14 -0
  70. package/types/IEmitterShapeGenerator.d.ts +2 -2
  71. package/types/constants.d.ts +2 -0
  72. package/types/index.d.ts +3 -2
  73. package/types/types.d.ts +15 -9
  74. package/umd/EmitterInstance.js +69 -47
  75. package/umd/EmitterShapeBase.js +4 -0
  76. package/umd/EmittersInstancesManager.js +119 -0
  77. package/umd/EmittersInteractor.js +128 -0
  78. package/umd/EmittersPlugin.js +44 -56
  79. package/umd/EmittersPluginInstance.js +58 -0
  80. package/umd/Options/Classes/Emitter.js +13 -0
  81. package/umd/Options/Classes/EmitterLife.js +4 -0
  82. package/umd/Options/Classes/EmitterRate.js +2 -0
  83. package/umd/Options/Classes/EmitterShape.js +3 -0
  84. package/umd/Options/Classes/EmitterShapeReplace.js +2 -0
  85. package/umd/Options/Classes/EmitterSize.js +3 -0
  86. package/umd/ShapeManager.js +4 -4
  87. package/umd/constants.js +17 -0
  88. package/umd/index.js +21 -6
  89. package/214.min.js +0 -2
  90. package/214.min.js.LICENSE.txt +0 -1
  91. package/921.min.js +0 -2
  92. package/921.min.js.LICENSE.txt +0 -1
  93. package/browser/Emitters.js +0 -128
  94. package/cjs/Emitters.js +0 -128
  95. package/esm/Emitters.js +0 -128
  96. package/tsparticles.plugin.emitters.min.js.LICENSE.txt +0 -1
  97. package/types/Emitters.d.ts +0 -24
  98. package/umd/Emitters.js +0 -142
package/278.min.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";(this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[278],{278(t,i,e){e.d(i,{EmitterInstance:()=>h});var s=e(303),o=e(880),n=e(806);let a=1;function r(t,i){t.color?t.color.value=i:t.color={value:i}}class h{container;removeCallback;fill;name;options;position;size;spawnColor;_currentDuration;_currentEmitDelay;_currentSpawnDelay;_duration;_emitDelay;_engine;_firstSpawn;_immortal;_initialPosition;_lifeCount;_mutationObserver;_particlesOptions;_paused;_resizeObserver;_shape;_size;_spawnDelay;_startParticlesAdded;constructor(t,i,e,n,a){this.container=i,this.removeCallback=e,this._engine=t,this._currentDuration=0,this._currentEmitDelay=0,this._currentSpawnDelay=0,this._initialPosition=a,n instanceof o.v?this.options=n:(this.options=new o.v,this.options.load(n)),this._spawnDelay=i.retina.reduceFactor?(0,s.getRangeValue)(this.options.life.delay??0)*s.millisecondsToSeconds/i.retina.reduceFactor:1/0,this.position=this._initialPosition??this._calcPosition(),this.name=this.options.name,this.fill=this.options.fill,this._firstSpawn=!this.options.life.wait,this._startParticlesAdded=!1;const r=(0,s.deepExtend)({},this.options.particles);if(r.move??={},r.move.direction??=this.options.direction,this.options.spawnColor&&(this.spawnColor=(0,s.rangeColorToHsl)(this._engine,this.options.spawnColor)),this._paused=!this.options.autoPlay,this._particlesOptions=r,this._size=this._calcSize(),this.size=(0,s.getSize)(this._size,this.container.canvas.size),this._lifeCount=this.options.life.count??-1,this._immortal=this._lifeCount<=0,this.options.domId){const t=(0,s.safeDocument)().getElementById(this.options.domId);t&&(this._mutationObserver=new MutationObserver(()=>{this.resize()}),this._resizeObserver=new ResizeObserver(()=>{this.resize()}),this._mutationObserver.observe(t,{attributes:!0,attributeFilter:["style","width","height"]}),this._resizeObserver.observe(t))}const h=this.options.shape,l=this._engine.emitterShapeManager?.getShapeGenerator(h.type);l&&(this._shape=l.generate(this.container,this.position,this.size,this.fill,h.options)),this._engine.dispatchEvent("emitterCreated",{container:i,data:{emitter:this}}),this.play()}externalPause(){this._paused=!0,this.pause()}externalPlay(){this._paused=!1,this.play()}async init(){await this._shape?.init()}pause(){this._paused||delete this._emitDelay}play(){if(this._paused||!((this._lifeCount>0||this._immortal||!this.options.life.count)&&(this._firstSpawn||this._currentSpawnDelay>=(this._spawnDelay??0))))return;let t=this.container;if(void 0===this._emitDelay){let i=(0,s.getRangeValue)(this.options.rate.delay);this._emitDelay=t.retina.reduceFactor?i*s.millisecondsToSeconds/t.retina.reduceFactor:1/0}(this._lifeCount>0||this._immortal)&&this._prepareToDie()}resize(){let t=this._initialPosition,i=this.container;this.position=t&&(0,s.isPointInside)(t,i.canvas.size,s.Vector.origin)?t:this._calcPosition(),this._size=this._calcSize(),this.size=(0,s.getSize)(this._size,i.canvas.size),this._shape?.resize(this.position,this.size)}update(t){if(this._paused)return;let i=this.container;this._firstSpawn&&(this._firstSpawn=!1,this._currentSpawnDelay=this._spawnDelay??0,this._currentEmitDelay=this._emitDelay??0),this._startParticlesAdded||(this._startParticlesAdded=!0,this._emitParticles(this.options.startCount)),void 0!==this._duration&&(this._currentDuration+=t.value,this._currentDuration>=this._duration&&(this.pause(),void 0!==this._spawnDelay&&delete this._spawnDelay,!this._immortal&&this._lifeCount--,this._lifeCount>0||this._immortal?(this.position=this._calcPosition(),this._shape?.resize(this.position,this.size),this._spawnDelay=i.retina.reduceFactor?(0,s.getRangeValue)(this.options.life.delay??0)*s.millisecondsToSeconds/i.retina.reduceFactor:1/0):this._destroy(),this._currentDuration-=this._duration,delete this._duration)),void 0!==this._spawnDelay&&(this._currentSpawnDelay+=t.value,this._currentSpawnDelay>=this._spawnDelay&&(this._engine.dispatchEvent("emitterPlay",{container:this.container}),this.play(),this._currentSpawnDelay-=this._spawnDelay,delete this._spawnDelay)),void 0!==this._emitDelay&&(this._currentEmitDelay+=t.value,this._currentEmitDelay>=this._emitDelay&&(this._emit(),this._currentEmitDelay-=this._emitDelay))}_calcPosition(){let t=this.container;if(this.options.domId){let i=(0,s.safeDocument)().getElementById(this.options.domId);if(i){let e=i.getBoundingClientRect(),o=t.retina.pixelRatio;return{x:(e.x+e.width*s.half)*o,y:(e.y+e.height*s.half)*o}}}return(0,s.calcPositionOrRandomFromSizeRanged)({size:t.canvas.size,position:this.options.position})}_calcSize(){let t,i=this.container;if(this.options.domId){let t=(0,s.safeDocument)().getElementById(this.options.domId);if(t){let e=t.getBoundingClientRect();return{width:e.width*i.retina.pixelRatio,height:e.height*i.retina.pixelRatio,mode:s.PixelMode.precise}}}return this.options.size??((t=new n.G).load({height:0,mode:s.PixelMode.percent,width:0}),t)}_destroy=()=>{this._mutationObserver?.disconnect(),this._mutationObserver=void 0,this._resizeObserver?.disconnect(),this._resizeObserver=void 0,this.removeCallback(this),this._engine.dispatchEvent("emitterDestroyed",{container:this.container,data:{emitter:this}})};_emit(){if(this._paused)return;let t=(0,s.getRangeValue)(this.options.rate.quantity);this._emitParticles(t)}_emitParticles(t){let i=(0,s.itemFromSingleOrMultiple)(this._particlesOptions)??{},e=this.options.spawnColor?.animation,o=this.container.retina.reduceFactor,n=!!e,a=!!this._shape,h=n||a,l=n?{h:s.hMax,s:s.sMax,l:s.lMax}:null,p=this.options.shape;for(let n=0;n<t*o;n++){let t=h?(0,s.deepExtend)({},i):i;this.spawnColor&&(e&&l&&(this.spawnColor.h=this._setColorAnimation(e.h,this.spawnColor.h,l.h,3.6),this.spawnColor.s=this._setColorAnimation(e.s,this.spawnColor.s,l.s),this.spawnColor.l=this._setColorAnimation(e.l,this.spawnColor.l,l.l)),r(t,this.spawnColor));let o=this.position;if(this._shape){let i=this._shape.randomPosition();if(i){o=i.position;let e=p.replace;e.color&&i.color&&r(t,i.color),e.opacity&&(t.opacity?t.opacity.value=i.opacity:t.opacity={value:i.opacity})}else o=null}o&&this.container.particles.addParticle(o,t)}}_prepareToDie=()=>{if(this._paused)return;let t=void 0!==this.options.life.duration?(0,s.getRangeValue)(this.options.life.duration):void 0;(this._lifeCount>0||this._immortal)&&void 0!==t&&t>0&&(this._duration=t*s.millisecondsToSeconds)};_setColorAnimation=(t,i,e,o=a)=>{let n=this.container;if(!t.enable)return i;let r=(0,s.randomInRangeValue)(t.offset),h=(0,s.getRangeValue)(this.options.rate.delay),l=n.retina.reduceFactor?h*s.millisecondsToSeconds/n.retina.reduceFactor:1/0;return(i+(0,s.getRangeValue)(t.speed)*n.fpsLimit/l+r*o)%e}}}}]);
package/615.min.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";(this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[615],{615(t,i,e){e.r(i),e.d(i,{EmittersInstancesManager:()=>o});var s=e(303),a=e(880);class o{_containerArrays;_engine;constructor(t){this._containerArrays=new Map,this._engine=t}async addEmitter(t,i,s){let o=new a.v;o.load(i);let{EmitterInstance:r}=await e.e(278).then(e.bind(e,278)),n=new r(this._engine,t,i=>{this.removeEmitter(t,i)},o,s);return await n.init(),this.getArray(t).push(n),n}clear(t){this.initContainer(t),this._containerArrays.set(t,[])}getArray(t){this.initContainer(t);let i=this._containerArrays.get(t);return i||(i=[],this._containerArrays.set(t,i)),i}initContainer(t){this._containerArrays.has(t)||(this._containerArrays.set(t,[]),t.getEmitter=i=>{let e=this.getArray(t);return void 0===i||(0,s.isNumber)(i)?e[i??0]:e.find(t=>t.name===i)},t.addEmitter=async(i,e)=>this.addEmitter(t,i,e),t.removeEmitter=i=>{let e=t.getEmitter?.(i);e&&this.removeEmitter(t,e)},t.playEmitter=i=>{let e=t.getEmitter?.(i);e&&e.externalPlay()},t.pauseEmitter=i=>{let e=t.getEmitter?.(i);e&&e.externalPause()})}removeEmitter(t,i){let e=this.getArray(t).indexOf(i);e>=0&&this.getArray(t).splice(e,1)}}},880(t,i,e){e.d(i,{v:()=>h});var s=e(303);class a{count;delay;duration;wait;constructor(){this.wait=!1}load(t){(0,s.isNull)(t)||(void 0!==t.count&&(this.count=t.count),void 0!==t.delay&&(this.delay=(0,s.setRangeValue)(t.delay)),void 0!==t.duration&&(this.duration=(0,s.setRangeValue)(t.duration)),void 0!==t.wait&&(this.wait=t.wait))}}class o{delay;quantity;constructor(){this.quantity=1,this.delay=.1}load(t){(0,s.isNull)(t)||(void 0!==t.quantity&&(this.quantity=(0,s.setRangeValue)(t.quantity)),void 0!==t.delay&&(this.delay=(0,s.setRangeValue)(t.delay)))}}class r{color;opacity;constructor(){this.color=!1,this.opacity=!1}load(t){(0,s.isNull)(t)||(void 0!==t.color&&(this.color=t.color),void 0!==t.opacity&&(this.opacity=t.opacity))}}class n{options;replace;type;constructor(){this.options={},this.replace=new r,this.type="square"}load(t){(0,s.isNull)(t)||(void 0!==t.options&&(this.options=(0,s.deepExtend)({},t.options??{})),this.replace.load(t.replace),void 0!==t.type&&(this.type=t.type))}}var l=e(806);class h{autoPlay;direction;domId;fill;life;name;particles;position;rate;shape;size;spawnColor;startCount;constructor(){this.autoPlay=!0,this.fill=!0,this.life=new a,this.rate=new o,this.shape=new n,this.startCount=0}load(t){(0,s.isNull)(t)||(void 0!==t.autoPlay&&(this.autoPlay=t.autoPlay),void 0!==t.size&&(this.size??=new l.G,this.size.load(t.size)),void 0!==t.direction&&(this.direction=t.direction),this.domId=t.domId,void 0!==t.fill&&(this.fill=t.fill),this.life.load(t.life),this.name=t.name,this.particles=(0,s.executeOnSingleOrMultiple)(t.particles,t=>(0,s.deepExtend)({},t)),this.rate.load(t.rate),this.shape.load(t.shape),void 0!==t.position&&(this.position={},void 0!==t.position.x&&(this.position.x=(0,s.setRangeValue)(t.position.x)),void 0!==t.position.y&&(this.position.y=(0,s.setRangeValue)(t.position.y))),void 0!==t.spawnColor&&(this.spawnColor??=new s.AnimatableColor,this.spawnColor.load(t.spawnColor)),void 0!==t.startCount&&(this.startCount=t.startCount))}}},806(t,i,e){e.d(i,{G:()=>a});var s=e(303);class a{height;mode;width;constructor(){this.mode=s.PixelMode.percent,this.height=0,this.width=0}load(t){(0,s.isNull)(t)||(void 0!==t.mode&&(this.mode=t.mode),void 0!==t.height&&(this.height=t.height),void 0!==t.width&&(this.width=t.width))}}}}]);
package/751.min.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";(this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[751],{751(t,i,s){s.r(i),s.d(i,{EmittersPlugin:()=>a});var e=s(303),o=s(880);class a{id="emitters";_instancesManager;constructor(t){this._instancesManager=t}async getPlugin(t){let{EmittersPluginInstance:i}=await s.e(88).then(s.bind(s,88));return new i(this._instancesManager,t)}loadOptions(t,i,s){(this.needsPlugin(i)||this.needsPlugin(s))&&s?.emitters&&(i.emitters=(0,e.executeOnSingleOrMultiple)(s.emitters,t=>{let i=new o.v;return i.load(t),i}))}needsPlugin(t){if(!t)return!1;let i=t.emitters;return(0,e.isArray)(i)&&!!i.length||void 0!==i}}},880(t,i,s){s.d(i,{v:()=>r});var e=s(303);class o{count;delay;duration;wait;constructor(){this.wait=!1}load(t){(0,e.isNull)(t)||(void 0!==t.count&&(this.count=t.count),void 0!==t.delay&&(this.delay=(0,e.setRangeValue)(t.delay)),void 0!==t.duration&&(this.duration=(0,e.setRangeValue)(t.duration)),void 0!==t.wait&&(this.wait=t.wait))}}class a{delay;quantity;constructor(){this.quantity=1,this.delay=.1}load(t){(0,e.isNull)(t)||(void 0!==t.quantity&&(this.quantity=(0,e.setRangeValue)(t.quantity)),void 0!==t.delay&&(this.delay=(0,e.setRangeValue)(t.delay)))}}class l{color;opacity;constructor(){this.color=!1,this.opacity=!1}load(t){(0,e.isNull)(t)||(void 0!==t.color&&(this.color=t.color),void 0!==t.opacity&&(this.opacity=t.opacity))}}class n{options;replace;type;constructor(){this.options={},this.replace=new l,this.type="square"}load(t){(0,e.isNull)(t)||(void 0!==t.options&&(this.options=(0,e.deepExtend)({},t.options??{})),this.replace.load(t.replace),void 0!==t.type&&(this.type=t.type))}}var d=s(806);class r{autoPlay;direction;domId;fill;life;name;particles;position;rate;shape;size;spawnColor;startCount;constructor(){this.autoPlay=!0,this.fill=!0,this.life=new o,this.rate=new a,this.shape=new n,this.startCount=0}load(t){(0,e.isNull)(t)||(void 0!==t.autoPlay&&(this.autoPlay=t.autoPlay),void 0!==t.size&&(this.size??=new d.G,this.size.load(t.size)),void 0!==t.direction&&(this.direction=t.direction),this.domId=t.domId,void 0!==t.fill&&(this.fill=t.fill),this.life.load(t.life),this.name=t.name,this.particles=(0,e.executeOnSingleOrMultiple)(t.particles,t=>(0,e.deepExtend)({},t)),this.rate.load(t.rate),this.shape.load(t.shape),void 0!==t.position&&(this.position={},void 0!==t.position.x&&(this.position.x=(0,e.setRangeValue)(t.position.x)),void 0!==t.position.y&&(this.position.y=(0,e.setRangeValue)(t.position.y))),void 0!==t.spawnColor&&(this.spawnColor??=new e.AnimatableColor,this.spawnColor.load(t.spawnColor)),void 0!==t.startCount&&(this.startCount=t.startCount))}}},806(t,i,s){s.d(i,{G:()=>o});var e=s(303);class o{height;mode;width;constructor(){this.mode=e.PixelMode.percent,this.height=0,this.width=0}load(t){(0,e.isNull)(t)||(void 0!==t.mode&&(this.mode=t.mode),void 0!==t.height&&(this.height=t.height),void 0!==t.width&&(this.width=t.width))}}}}]);
package/816.min.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";(this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[816],{816(t,e,i){i.d(e,{EmittersInteractor:()=>r});var s=i(702),a=i(303),o=i(880);let n={count:1,enable:!0},l="emitters";class r extends s.ExternalInteractorBase{handleClickMode;_instancesManager;constructor(t,e){super(e),this._instancesManager=t,this.handleClickMode=(t,e)=>{let i,s=this.container.actualOptions.interactivity.modes.emitters;if(!s||t!==l)return;if((0,a.isArray)(s.value)){let t=s.value.length;if(t>0&&s.random.enable){i=[];let e=new Set;for(let o=0;o<s.random.count;o++){let n=(0,a.arrayRandomIndex)(s.value);if(e.has(n)&&e.size<t){o--;continue}e.add(n);let l=(0,a.itemFromArray)(s.value,n);l&&i.push(l)}}else i=s.value}else i=s.value;let o=i,n=e.mouse.clickPosition;(0,a.executeOnSingleOrMultiple)(o,async t=>{await this._instancesManager.addEmitter(this.container,t,n)})}}clear(){}init(){}interact(t,e){for(let t of this._instancesManager.getArray(this.container))t.update(e)}isEnabled(t,e){let i=this.container.actualOptions,s=t.mouse,o=(e?.interactivity??i.interactivity).events;return!!s.clickPosition&&!!o.onClick.enable&&(0,a.isInArray)(l,o.onClick.mode)}loadModeOptions(t,...e){for(let i of(t.emitters={random:n,value:[]},e))if(i?.emitters)if((0,a.isArray)(i.emitters))for(let e of i.emitters){let i=new o.v;i.load(e),t.emitters.value.push(i)}else if(Object.hasOwn(i.emitters,"value")){let e=i.emitters;if(t.emitters.random.enable=e.random?.enable??t.emitters.random.enable,t.emitters.random.count=e.random?.count??t.emitters.random.count,(0,a.isArray)(e.value))for(let i of e.value){let e=new o.v;e.load(i),t.emitters.value.push(e)}else{let i=new o.v;i.load(e.value),t.emitters.value.push(i)}}else{let e=new o.v;e.load(i.emitters),t.emitters.value.push(e)}}removeEmitter(t){let e=this._instancesManager.getArray(this.container).indexOf(t);e>=0&&this._instancesManager.getArray(this.container).splice(e,1)}reset(){}}},880(t,e,i){i.d(e,{v:()=>d});var s=i(303);class a{count;delay;duration;wait;constructor(){this.wait=!1}load(t){(0,s.isNull)(t)||(void 0!==t.count&&(this.count=t.count),void 0!==t.delay&&(this.delay=(0,s.setRangeValue)(t.delay)),void 0!==t.duration&&(this.duration=(0,s.setRangeValue)(t.duration)),void 0!==t.wait&&(this.wait=t.wait))}}class o{delay;quantity;constructor(){this.quantity=1,this.delay=.1}load(t){(0,s.isNull)(t)||(void 0!==t.quantity&&(this.quantity=(0,s.setRangeValue)(t.quantity)),void 0!==t.delay&&(this.delay=(0,s.setRangeValue)(t.delay)))}}class n{color;opacity;constructor(){this.color=!1,this.opacity=!1}load(t){(0,s.isNull)(t)||(void 0!==t.color&&(this.color=t.color),void 0!==t.opacity&&(this.opacity=t.opacity))}}class l{options;replace;type;constructor(){this.options={},this.replace=new n,this.type="square"}load(t){(0,s.isNull)(t)||(void 0!==t.options&&(this.options=(0,s.deepExtend)({},t.options??{})),this.replace.load(t.replace),void 0!==t.type&&(this.type=t.type))}}var r=i(806);class d{autoPlay;direction;domId;fill;life;name;particles;position;rate;shape;size;spawnColor;startCount;constructor(){this.autoPlay=!0,this.fill=!0,this.life=new a,this.rate=new o,this.shape=new l,this.startCount=0}load(t){(0,s.isNull)(t)||(void 0!==t.autoPlay&&(this.autoPlay=t.autoPlay),void 0!==t.size&&(this.size??=new r.G,this.size.load(t.size)),void 0!==t.direction&&(this.direction=t.direction),this.domId=t.domId,void 0!==t.fill&&(this.fill=t.fill),this.life.load(t.life),this.name=t.name,this.particles=(0,s.executeOnSingleOrMultiple)(t.particles,t=>(0,s.deepExtend)({},t)),this.rate.load(t.rate),this.shape.load(t.shape),void 0!==t.position&&(this.position={},void 0!==t.position.x&&(this.position.x=(0,s.setRangeValue)(t.position.x)),void 0!==t.position.y&&(this.position.y=(0,s.setRangeValue)(t.position.y))),void 0!==t.spawnColor&&(this.spawnColor??=new s.AnimatableColor,this.spawnColor.load(t.spawnColor)),void 0!==t.startCount&&(this.startCount=t.startCount))}}},806(t,e,i){i.d(e,{G:()=>a});var s=i(303);class a{height;mode;width;constructor(){this.mode=s.PixelMode.percent,this.height=0,this.width=0}load(t){(0,s.isNull)(t)||(void 0!==t.mode&&(this.mode=t.mode),void 0!==t.height&&(this.height=t.height),void 0!==t.width&&(this.width=t.width))}}}}]);
package/88.min.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";(this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[88],{88(t,a,e){e.d(a,{EmittersPluginInstance:()=>n});var i=e(303);class n{container;_instancesManager;constructor(t,a){this.container=a,this._instancesManager=t,this._instancesManager.initContainer(a)}async init(){let t=this.container.actualOptions.emitters;if((0,i.isArray)(t))for(let a of t)await this._instancesManager.addEmitter(this.container,a);else await this._instancesManager.addEmitter(this.container,t)}pause(){for(let t of this._instancesManager.getArray(this.container))t.pause()}play(){for(let t of this._instancesManager.getArray(this.container))t.play()}resize(){for(let t of this._instancesManager.getArray(this.container))t.resize()}stop(){this._instancesManager.clear(this.container)}update(t){this._instancesManager.getArray(this.container).forEach(a=>{a.update(t)})}}}}]);
package/975.min.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";(this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[975],{975(e,t,r){r.r(t),r.d(t,{ShapeManager:()=>s});let a=new Map;class s{addShapeGenerator(e,t){this.getShapeGenerator(e)||a.set(e,t)}getShapeGenerator(e){return a.get(e)}getSupportedShapeGenerators(){return a.keys()}}}}]);
package/README.md CHANGED
@@ -26,6 +26,7 @@ Once the scripts are loaded you can set up `tsParticles` and the plugin like thi
26
26
 
27
27
  ```javascript
28
28
  (async () => {
29
+ await loadInteractivityPlugin(tsParticles);
29
30
  await loadEmittersPlugin(tsParticles);
30
31
 
31
32
  await tsParticles.load({
@@ -55,9 +56,11 @@ Then you need to import it in the app, like this:
55
56
 
56
57
  ```javascript
57
58
  const { tsParticles } = require("@tsparticles/engine");
59
+ const { loadInteractivityPlugin } = require("@tsparticles/plugin-interactivity");
58
60
  const { loadEmittersPlugin } = require("@tsparticles/plugin-emitters");
59
61
 
60
62
  (async () => {
63
+ await loadInteractivityPlugin(tsParticles);
61
64
  await loadEmittersPlugin(tsParticles);
62
65
  })();
63
66
  ```
@@ -66,9 +69,11 @@ or
66
69
 
67
70
  ```javascript
68
71
  import { tsParticles } from "@tsparticles/engine";
72
+ import { loadInteractivityPlugin } from "@tsparticles/plugin-interactivity";
69
73
  import { loadEmittersPlugin } from "@tsparticles/plugin-emitters";
70
74
 
71
75
  (async () => {
76
+ await loadInteractivityPlugin(tsParticles);
72
77
  await loadEmittersPlugin(tsParticles);
73
78
  })();
74
79
  ```
@@ -1,7 +1,7 @@
1
1
  import { PixelMode, Vector, calcPositionOrRandomFromSizeRanged, deepExtend, 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;
4
+ const defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1, defaultColorAnimationFactor = 1, colorFactor = 3.6;
5
5
  function setParticlesOptionsColor(particlesOptions, color) {
6
6
  if (particlesOptions.color) {
7
7
  particlesOptions.color.value = color;
@@ -13,41 +13,35 @@ function setParticlesOptionsColor(particlesOptions, color) {
13
13
  }
14
14
  }
15
15
  export class EmitterInstance {
16
- constructor(engine, emitters, container, options, position) {
17
- this.emitters = emitters;
16
+ container;
17
+ removeCallback;
18
+ fill;
19
+ name;
20
+ options;
21
+ position;
22
+ size;
23
+ spawnColor;
24
+ _currentDuration;
25
+ _currentEmitDelay;
26
+ _currentSpawnDelay;
27
+ _duration;
28
+ _emitDelay;
29
+ _engine;
30
+ _firstSpawn;
31
+ _immortal;
32
+ _initialPosition;
33
+ _lifeCount;
34
+ _mutationObserver;
35
+ _particlesOptions;
36
+ _paused;
37
+ _resizeObserver;
38
+ _shape;
39
+ _size;
40
+ _spawnDelay;
41
+ _startParticlesAdded;
42
+ constructor(engine, container, removeCallback, options, position) {
18
43
  this.container = container;
19
- this._destroy = () => {
20
- this._mutationObserver?.disconnect();
21
- this._mutationObserver = undefined;
22
- this._resizeObserver?.disconnect();
23
- this._resizeObserver = undefined;
24
- this.emitters.removeEmitter(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
- };
44
+ this.removeCallback = removeCallback;
51
45
  this._engine = engine;
52
46
  this._currentDuration = 0;
53
47
  this._currentEmitDelay = 0;
@@ -99,7 +93,7 @@ export class EmitterInstance {
99
93
  }
100
94
  const shapeOptions = this.options.shape, shapeGenerator = this._engine.emitterShapeManager?.getShapeGenerator(shapeOptions.type);
101
95
  if (shapeGenerator) {
102
- this._shape = shapeGenerator.generate(this.position, this.size, this.fill, shapeOptions.options);
96
+ this._shape = shapeGenerator.generate(this.container, this.position, this.size, this.fill, shapeOptions.options);
103
97
  }
104
98
  this._engine.dispatchEvent("emitterCreated", {
105
99
  container,
@@ -201,7 +195,7 @@ export class EmitterInstance {
201
195
  container: this.container,
202
196
  });
203
197
  this.play();
204
- this._currentSpawnDelay -= this._currentSpawnDelay;
198
+ this._currentSpawnDelay -= this._spawnDelay;
205
199
  delete this._spawnDelay;
206
200
  }
207
201
  }
@@ -254,6 +248,19 @@ export class EmitterInstance {
254
248
  return size;
255
249
  })());
256
250
  }
251
+ _destroy = () => {
252
+ this._mutationObserver?.disconnect();
253
+ this._mutationObserver = undefined;
254
+ this._resizeObserver?.disconnect();
255
+ this._resizeObserver = undefined;
256
+ this.removeCallback(this);
257
+ this._engine.dispatchEvent("emitterDestroyed", {
258
+ container: this.container,
259
+ data: {
260
+ emitter: this,
261
+ },
262
+ });
263
+ };
257
264
  _emit() {
258
265
  if (this._paused) {
259
266
  return;
@@ -262,24 +269,20 @@ export class EmitterInstance {
262
269
  this._emitParticles(quantity);
263
270
  }
264
271
  _emitParticles(quantity) {
265
- const singleParticlesOptions = itemFromSingleOrMultiple(this._particlesOptions), reduceFactor = this.container.retina.reduceFactor;
272
+ const singleParticlesOptions = (itemFromSingleOrMultiple(this._particlesOptions) ??
273
+ {}), hslAnimation = this.options.spawnColor?.animation, reduceFactor = this.container.retina.reduceFactor, needsColorAnimation = !!hslAnimation, needsShapeData = !!this._shape, needsCopy = needsColorAnimation || needsShapeData, maxValues = needsColorAnimation ? { h: hMax, s: sMax, l: lMax } : null, shapeOptions = this.options.shape;
266
274
  for (let i = 0; i < quantity * reduceFactor; i++) {
267
- const particlesOptions = deepExtend({}, singleParticlesOptions);
275
+ const particlesOptions = needsCopy
276
+ ? deepExtend({}, singleParticlesOptions)
277
+ : singleParticlesOptions;
268
278
  if (this.spawnColor) {
269
- const hslAnimation = this.options.spawnColor?.animation;
270
- if (hslAnimation) {
271
- const maxValues = {
272
- h: hMax,
273
- s: sMax,
274
- l: lMax,
275
- }, colorFactor = 3.6;
279
+ if (hslAnimation && maxValues) {
276
280
  this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h, colorFactor);
277
281
  this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, maxValues.s);
278
282
  this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, maxValues.l);
279
283
  }
280
284
  setParticlesOptionsColor(particlesOptions, this.spawnColor);
281
285
  }
282
- const shapeOptions = this.options.shape;
283
286
  let position = this.position;
284
287
  if (this._shape) {
285
288
  const shapePosData = this._shape.randomPosition();
@@ -309,4 +312,23 @@ export class EmitterInstance {
309
312
  }
310
313
  }
311
314
  }
315
+ _prepareToDie = () => {
316
+ if (this._paused) {
317
+ return;
318
+ }
319
+ const duration = this.options.life.duration !== undefined ? getRangeValue(this.options.life.duration) : undefined, minDuration = 0, minLifeCount = 0;
320
+ if ((this._lifeCount > minLifeCount || this._immortal) && duration !== undefined && duration > minDuration) {
321
+ this._duration = duration * millisecondsToSeconds;
322
+ }
323
+ };
324
+ _setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => {
325
+ const container = this.container;
326
+ if (!animation.enable) {
327
+ return initValue;
328
+ }
329
+ const colorOffset = randomInRangeValue(animation.offset), delay = getRangeValue(this.options.rate.delay), emitFactor = container.retina.reduceFactor
330
+ ? (delay * millisecondsToSeconds) / container.retina.reduceFactor
331
+ : Infinity, colorSpeed = getRangeValue(animation.speed);
332
+ return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * factor) % maxValue;
333
+ };
312
334
  }
@@ -1,4 +1,8 @@
1
1
  export class EmitterShapeBase {
2
+ fill;
3
+ options;
4
+ position;
5
+ size;
2
6
  constructor(position, size, fill, options) {
3
7
  this.position = position;
4
8
  this.size = size;
@@ -0,0 +1,71 @@
1
+ import { isNumber } from "@tsparticles/engine";
2
+ import { Emitter } from "./Options/Classes/Emitter.js";
3
+ const defaultIndex = 0;
4
+ export class EmittersInstancesManager {
5
+ _containerArrays;
6
+ _engine;
7
+ constructor(engine) {
8
+ this._containerArrays = new Map();
9
+ this._engine = engine;
10
+ }
11
+ async addEmitter(container, options, position) {
12
+ const emitterOptions = new Emitter();
13
+ emitterOptions.load(options);
14
+ const { EmitterInstance } = await import("./EmitterInstance.js"), emitter = new EmitterInstance(this._engine, container, (emitter) => {
15
+ this.removeEmitter(container, emitter);
16
+ }, emitterOptions, position);
17
+ await emitter.init();
18
+ this.getArray(container).push(emitter);
19
+ return emitter;
20
+ }
21
+ clear(container) {
22
+ this.initContainer(container);
23
+ this._containerArrays.set(container, []);
24
+ }
25
+ getArray(container) {
26
+ this.initContainer(container);
27
+ let array = this._containerArrays.get(container);
28
+ if (!array) {
29
+ array = [];
30
+ this._containerArrays.set(container, array);
31
+ }
32
+ return array;
33
+ }
34
+ initContainer(container) {
35
+ if (this._containerArrays.has(container)) {
36
+ return;
37
+ }
38
+ this._containerArrays.set(container, []);
39
+ container.getEmitter = (idxOrName) => {
40
+ const array = this.getArray(container);
41
+ return idxOrName === undefined || isNumber(idxOrName)
42
+ ? array[idxOrName ?? defaultIndex]
43
+ : array.find(t => t.name === idxOrName);
44
+ };
45
+ container.addEmitter = async (options, position) => this.addEmitter(container, options, position);
46
+ container.removeEmitter = (idxOrName) => {
47
+ const emitter = container.getEmitter?.(idxOrName);
48
+ if (emitter) {
49
+ this.removeEmitter(container, emitter);
50
+ }
51
+ };
52
+ container.playEmitter = (idxOrName) => {
53
+ const emitter = container.getEmitter?.(idxOrName);
54
+ if (emitter) {
55
+ emitter.externalPlay();
56
+ }
57
+ };
58
+ container.pauseEmitter = (idxOrName) => {
59
+ const emitter = container.getEmitter?.(idxOrName);
60
+ if (emitter) {
61
+ emitter.externalPause();
62
+ }
63
+ };
64
+ }
65
+ removeEmitter(container, emitter) {
66
+ const index = this.getArray(container).indexOf(emitter), minIndex = 0, deleteCount = 1;
67
+ if (index >= minIndex) {
68
+ this.getArray(container).splice(index, deleteCount);
69
+ }
70
+ }
71
+ }
@@ -0,0 +1,114 @@
1
+ import { ExternalInteractorBase, } from "@tsparticles/plugin-interactivity";
2
+ import { arrayRandomIndex, executeOnSingleOrMultiple, isArray, isInArray, itemFromArray, } from "@tsparticles/engine";
3
+ import { Emitter } from "./Options/Classes/Emitter.js";
4
+ import { defaultRandomOptions } from "./constants.js";
5
+ const emittersMode = "emitters";
6
+ export class EmittersInteractor extends ExternalInteractorBase {
7
+ handleClickMode;
8
+ _instancesManager;
9
+ constructor(instancesManager, container) {
10
+ super(container);
11
+ this._instancesManager = instancesManager;
12
+ this.handleClickMode = (mode, interactivityData) => {
13
+ const container = this.container, options = container.actualOptions, modeEmitters = options.interactivity.modes.emitters;
14
+ if (!modeEmitters || mode !== emittersMode) {
15
+ return;
16
+ }
17
+ let emittersModeOptions;
18
+ if (isArray(modeEmitters.value)) {
19
+ const minLength = 0, modeEmittersCount = modeEmitters.value.length;
20
+ if (modeEmittersCount > minLength && modeEmitters.random.enable) {
21
+ emittersModeOptions = [];
22
+ const usedIndexes = new Set();
23
+ for (let i = 0; i < modeEmitters.random.count; i++) {
24
+ const idx = arrayRandomIndex(modeEmitters.value);
25
+ if (usedIndexes.has(idx) && usedIndexes.size < modeEmittersCount) {
26
+ i--;
27
+ continue;
28
+ }
29
+ usedIndexes.add(idx);
30
+ const selectedOptions = itemFromArray(modeEmitters.value, idx);
31
+ if (!selectedOptions) {
32
+ continue;
33
+ }
34
+ emittersModeOptions.push(selectedOptions);
35
+ }
36
+ }
37
+ else {
38
+ emittersModeOptions = modeEmitters.value;
39
+ }
40
+ }
41
+ else {
42
+ emittersModeOptions = modeEmitters.value;
43
+ }
44
+ const emittersOptions = emittersModeOptions, ePosition = interactivityData.mouse.clickPosition;
45
+ void executeOnSingleOrMultiple(emittersOptions, async (emitter) => {
46
+ await this._instancesManager.addEmitter(this.container, emitter, ePosition);
47
+ });
48
+ };
49
+ }
50
+ clear() {
51
+ }
52
+ init() {
53
+ }
54
+ interact(_interactivityData, delta) {
55
+ for (const emitter of this._instancesManager.getArray(this.container)) {
56
+ emitter.update(delta);
57
+ }
58
+ }
59
+ isEnabled(interactivityData, particle) {
60
+ const container = this.container, options = container.actualOptions, mouse = interactivityData.mouse, events = (particle?.interactivity ?? options.interactivity).events;
61
+ if (!mouse.clickPosition || !events.onClick.enable) {
62
+ return false;
63
+ }
64
+ return isInArray(emittersMode, events.onClick.mode);
65
+ }
66
+ loadModeOptions(options, ...sources) {
67
+ options.emitters = {
68
+ random: defaultRandomOptions,
69
+ value: [],
70
+ };
71
+ for (const source of sources) {
72
+ if (!source?.emitters) {
73
+ continue;
74
+ }
75
+ if (isArray(source.emitters)) {
76
+ for (const emitter of source.emitters) {
77
+ const tmp = new Emitter();
78
+ tmp.load(emitter);
79
+ options.emitters.value.push(tmp);
80
+ }
81
+ }
82
+ else if (Object.hasOwn(source.emitters, "value")) {
83
+ const emitterModeOptions = source.emitters;
84
+ options.emitters.random.enable = emitterModeOptions.random?.enable ?? options.emitters.random.enable;
85
+ options.emitters.random.count = emitterModeOptions.random?.count ?? options.emitters.random.count;
86
+ if (isArray(emitterModeOptions.value)) {
87
+ for (const emitter of emitterModeOptions.value) {
88
+ const tmp = new Emitter();
89
+ tmp.load(emitter);
90
+ options.emitters.value.push(tmp);
91
+ }
92
+ }
93
+ else {
94
+ const tmp = new Emitter();
95
+ tmp.load(emitterModeOptions.value);
96
+ options.emitters.value.push(tmp);
97
+ }
98
+ }
99
+ else {
100
+ const tmp = new Emitter();
101
+ tmp.load(source.emitters);
102
+ options.emitters.value.push(tmp);
103
+ }
104
+ }
105
+ }
106
+ removeEmitter(emitter) {
107
+ const index = this._instancesManager.getArray(this.container).indexOf(emitter), minIndex = 0, deleteCount = 1;
108
+ if (index >= minIndex) {
109
+ this._instancesManager.getArray(this.container).splice(index, deleteCount);
110
+ }
111
+ }
112
+ reset() {
113
+ }
114
+ }
@@ -1,16 +1,16 @@
1
- import { executeOnSingleOrMultiple, isArray, isInArray, } from "@tsparticles/engine";
1
+ import { executeOnSingleOrMultiple, isArray, } from "@tsparticles/engine";
2
2
  import { Emitter } from "./Options/Classes/Emitter.js";
3
- import { EmitterClickMode } from "./Enums/EmitterClickMode.js";
4
- import { Emitters } from "./Emitters.js";
5
3
  export class EmittersPlugin {
6
- constructor(engine) {
7
- this._engine = engine;
8
- this.id = "emitters";
4
+ id = "emitters";
5
+ _instancesManager;
6
+ constructor(instancesManager) {
7
+ this._instancesManager = instancesManager;
9
8
  }
10
- getPlugin(container) {
11
- return Promise.resolve(new Emitters(this._engine, container));
9
+ async getPlugin(container) {
10
+ const { EmittersPluginInstance } = await import("./EmittersPluginInstance.js");
11
+ return new EmittersPluginInstance(this._instancesManager, container);
12
12
  }
13
- loadOptions(options, source) {
13
+ loadOptions(_container, options, source) {
14
14
  if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
15
15
  return;
16
16
  }
@@ -21,58 +21,12 @@ export class EmittersPlugin {
21
21
  return tmp;
22
22
  });
23
23
  }
24
- const interactivityEmitters = source?.interactivity?.modes?.emitters;
25
- if (interactivityEmitters) {
26
- if (isArray(interactivityEmitters)) {
27
- options.interactivity.modes.emitters = {
28
- random: {
29
- count: 1,
30
- enable: true,
31
- },
32
- value: interactivityEmitters.map(s => {
33
- const tmp = new Emitter();
34
- tmp.load(s);
35
- return tmp;
36
- }),
37
- };
38
- }
39
- else {
40
- const emitterMode = interactivityEmitters;
41
- if (isArray(emitterMode.value)) {
42
- options.interactivity.modes.emitters = {
43
- random: {
44
- count: emitterMode.random.count,
45
- enable: emitterMode.random.enable,
46
- },
47
- value: emitterMode.value.map(s => {
48
- const tmp = new Emitter();
49
- tmp.load(s);
50
- return tmp;
51
- }),
52
- };
53
- }
54
- else {
55
- const tmp = new Emitter();
56
- tmp.load(emitterMode.value);
57
- options.interactivity.modes.emitters = {
58
- random: {
59
- count: emitterMode.random.count,
60
- enable: emitterMode.random.enable,
61
- },
62
- value: tmp,
63
- };
64
- }
65
- }
66
- }
67
24
  }
68
25
  needsPlugin(options) {
69
26
  if (!options) {
70
27
  return false;
71
28
  }
72
29
  const emitters = options.emitters;
73
- return ((isArray(emitters) && !!emitters.length) ||
74
- emitters !== undefined ||
75
- (!!options.interactivity?.events?.onClick?.mode &&
76
- isInArray(EmitterClickMode.emitter, options.interactivity.events.onClick.mode)));
30
+ return (isArray(emitters) && !!emitters.length) || emitters !== undefined;
77
31
  }
78
32
  }
@@ -0,0 +1,44 @@
1
+ import { isArray } from "@tsparticles/engine";
2
+ export class EmittersPluginInstance {
3
+ container;
4
+ _instancesManager;
5
+ constructor(instancesManager, container) {
6
+ this.container = container;
7
+ this._instancesManager = instancesManager;
8
+ this._instancesManager.initContainer(container);
9
+ }
10
+ async init() {
11
+ const emittersOptions = this.container.actualOptions.emitters;
12
+ if (isArray(emittersOptions)) {
13
+ for (const emitterOptions of emittersOptions) {
14
+ await this._instancesManager.addEmitter(this.container, emitterOptions);
15
+ }
16
+ }
17
+ else {
18
+ await this._instancesManager.addEmitter(this.container, emittersOptions);
19
+ }
20
+ }
21
+ pause() {
22
+ for (const emitter of this._instancesManager.getArray(this.container)) {
23
+ emitter.pause();
24
+ }
25
+ }
26
+ play() {
27
+ for (const emitter of this._instancesManager.getArray(this.container)) {
28
+ emitter.play();
29
+ }
30
+ }
31
+ resize() {
32
+ for (const emitter of this._instancesManager.getArray(this.container)) {
33
+ emitter.resize();
34
+ }
35
+ }
36
+ stop() {
37
+ this._instancesManager.clear(this.container);
38
+ }
39
+ update(delta) {
40
+ this._instancesManager.getArray(this.container).forEach(emitter => {
41
+ emitter.update(delta);
42
+ });
43
+ }
44
+ }
@@ -4,6 +4,19 @@ import { EmitterRate } from "./EmitterRate.js";
4
4
  import { EmitterShape } from "./EmitterShape.js";
5
5
  import { EmitterSize } from "./EmitterSize.js";
6
6
  export class Emitter {
7
+ autoPlay;
8
+ direction;
9
+ domId;
10
+ fill;
11
+ life;
12
+ name;
13
+ particles;
14
+ position;
15
+ rate;
16
+ shape;
17
+ size;
18
+ spawnColor;
19
+ startCount;
7
20
  constructor() {
8
21
  this.autoPlay = true;
9
22
  this.fill = true;
@@ -1,5 +1,9 @@
1
1
  import { isNull, setRangeValue } from "@tsparticles/engine";
2
2
  export class EmitterLife {
3
+ count;
4
+ delay;
5
+ duration;
6
+ wait;
3
7
  constructor() {
4
8
  this.wait = false;
5
9
  }
@@ -1,5 +1,7 @@
1
1
  import { isNull, setRangeValue } from "@tsparticles/engine";
2
2
  export class EmitterRate {
3
+ delay;
4
+ quantity;
3
5
  constructor() {
4
6
  this.quantity = 1;
5
7
  this.delay = 0.1;
@@ -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();
@@ -1,5 +1,7 @@
1
1
  import { isNull } from "@tsparticles/engine";
2
2
  export class EmitterShapeReplace {
3
+ color;
4
+ opacity;
3
5
  constructor() {
4
6
  this.color = false;
5
7
  this.opacity = false;
@@ -1,5 +1,8 @@
1
1
  import { PixelMode, isNull } from "@tsparticles/engine";
2
2
  export class EmitterSize {
3
+ height;
4
+ mode;
5
+ width;
3
6
  constructor() {
4
7
  this.mode = PixelMode.percent;
5
8
  this.height = 0;