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

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/214.min.js CHANGED
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see 214.min.js.LICENSE.txt */
2
- (this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[214],{214(t,i,e){e.d(i,{EmittersPlugin:()=>m});var s=e(303);class o{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 n{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 a{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 r{constructor(){this.options={},this.replace=new a,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))}}class h{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))}}class l{constructor(){this.autoPlay=!0,this.fill=!0,this.life=new o,this.rate=new n,this.shape=new r,this.startCount=0}load(t){(0,s.isNull)(t)||(void 0!==t.autoPlay&&(this.autoPlay=t.autoPlay),void 0!==t.size&&(this.size??=new h,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))}}var c=e(271);function d(t,i){t.color?t.color.value=i:t.color={value:i}}class u{constructor(t,i,e,o,n){this.emitters=i,this.container=e,this._destroy=()=>{this._mutationObserver?.disconnect(),this._mutationObserver=void 0,this._resizeObserver?.disconnect(),this._resizeObserver=void 0,this.emitters.removeEmitter(this),this._engine.dispatchEvent("emitterDestroyed",{container:this.container,data:{emitter:this}})},this._prepareToDie=()=>{if(this._paused)return;const 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)},this._setColorAnimation=(t,i,e,o=1)=>{const n=this.container;if(!t.enable)return i;const a=(0,s.randomInRangeValue)(t.offset),r=(0,s.getRangeValue)(this.options.rate.delay),h=n.retina.reduceFactor?r*s.millisecondsToSeconds/n.retina.reduceFactor:1/0;return(i+(0,s.getRangeValue)(t.speed)*n.fpsLimit/h+a*o)%e},this._engine=t,this._currentDuration=0,this._currentEmitDelay=0,this._currentSpawnDelay=0,this._initialPosition=n,o instanceof l?this.options=o:(this.options=new l,this.options.load(o)),this._spawnDelay=e.retina.reduceFactor?(0,s.getRangeValue)(this.options.life.delay??0)*s.millisecondsToSeconds/e.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 a=(0,s.deepExtend)({},this.options.particles);if(a.move??={},a.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=a,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 r=this.options.shape,h=this._engine.emitterShapeManager?.getShapeGenerator(r.type);h&&(this._shape=h.generate(this.position,this.size,this.fill,r.options)),this._engine.dispatchEvent("emitterCreated",{container:e,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)return;if(!(this._lifeCount>0||this._immortal)&&this.options.life.count||!(this._firstSpawn||this._currentSpawnDelay>=(this._spawnDelay??0)))return;const t=this.container;if(void 0===this._emitDelay){const 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(){const 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;const 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._currentSpawnDelay,delete this._spawnDelay)),void 0!==this._emitDelay&&(this._currentEmitDelay+=t.value,this._currentEmitDelay>=this._emitDelay&&(this._emit(),this._currentEmitDelay-=this._emitDelay))}_calcPosition(){const t=this.container;if(this.options.domId){const i=(0,s.safeDocument)().getElementById(this.options.domId);if(i){const 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(){const t=this.container;if(this.options.domId){const i=(0,s.safeDocument)().getElementById(this.options.domId);if(i){const e=i.getBoundingClientRect();return{width:e.width*t.retina.pixelRatio,height:e.height*t.retina.pixelRatio,mode:s.PixelMode.precise}}}return this.options.size??(()=>{const t=new h;return t.load({height:0,mode:s.PixelMode.percent,width:0}),t})()}_emit(){if(this._paused)return;const t=(0,s.getRangeValue)(this.options.rate.quantity);this._emitParticles(t)}_emitParticles(t){const i=(0,s.itemFromSingleOrMultiple)(this._particlesOptions),e=this.container.retina.reduceFactor;for(let o=0;o<t*e;o++){const t=(0,s.deepExtend)({},i);if(this.spawnColor){const i=this.options.spawnColor?.animation;if(i){const t={h:s.hMax,s:s.sMax,l:s.lMax},e=3.6;this.spawnColor.h=this._setColorAnimation(i.h,this.spawnColor.h,t.h,e),this.spawnColor.s=this._setColorAnimation(i.s,this.spawnColor.s,t.s),this.spawnColor.l=this._setColorAnimation(i.l,this.spawnColor.l,t.l)}d(t,this.spawnColor)}const e=this.options.shape;let o=this.position;if(this._shape){const i=this._shape.randomPosition();if(i){o=i.position;const s=e.replace;s.color&&i.color&&d(t,i.color),s.opacity&&(t.opacity?t.opacity.value=i.opacity:t.opacity={value:i.opacity})}else o=null}o&&this.container.particles.addParticle(o,t)}}}class p{constructor(t,i){this.container=i,this._engine=t,this.array=[],this.emitters=[],this.interactivityEmitters={random:{count:1,enable:!1},value:[]};i.getEmitter=t=>void 0===t||(0,s.isNumber)(t)?this.array[t??0]:this.array.find((i=>i.name===t)),i.addEmitter=async(t,i)=>this.addEmitter(t,i),i.removeEmitter=t=>{const e=i.getEmitter(t);e&&this.removeEmitter(e)},i.playEmitter=t=>{const e=i.getEmitter(t);e&&e.externalPlay()},i.pauseEmitter=t=>{const e=i.getEmitter(t);e&&e.externalPause()}}async addEmitter(t,i){const e=new l;e.load(t);const s=new u(this._engine,this,this.container,e,i);return await s.init(),this.array.push(s),s}handleClickMode(t){const i=this.interactivityEmitters;if(t!==c.c.emitter)return;let e;if((0,s.isArray)(i.value)){const t=0;if(i.value.length>t&&i.random.enable){e=[];const t=[];for(let o=0;o<i.random.count;o++){const n=(0,s.arrayRandomIndex)(i.value);if(t.includes(n)&&t.length<i.value.length){o--;continue}t.push(n);const a=(0,s.itemFromArray)(i.value,n);a&&e.push(a)}}else e=i.value}else e=i.value;const o=e,n=this.container.interactivity.mouse.clickPosition;(0,s.executeOnSingleOrMultiple)(o,(async t=>{await this.addEmitter(t,n)}))}async init(){if(this.emitters=this.container.actualOptions.emitters,this.interactivityEmitters=this.container.actualOptions.interactivity.modes.emitters,(0,s.isArray)(this.emitters))for(const t of this.emitters)await this.addEmitter(t);else await this.addEmitter(this.emitters)}pause(){for(const t of this.array)t.pause()}play(){for(const t of this.array)t.play()}removeEmitter(t){const i=this.array.indexOf(t);i>=0&&this.array.splice(i,1)}resize(){for(const t of this.array)t.resize()}stop(){this.array=[]}update(t){for(const i of this.array)i.update(t)}}class m{constructor(t){this._engine=t,this.id="emitters"}getPlugin(t){return Promise.resolve(new p(this._engine,t))}loadOptions(t,i){if(!this.needsPlugin(t)&&!this.needsPlugin(i))return;i?.emitters&&(t.emitters=(0,s.executeOnSingleOrMultiple)(i.emitters,(t=>{const i=new l;return i.load(t),i})));const e=i?.interactivity?.modes?.emitters;if(e)if((0,s.isArray)(e))t.interactivity.modes.emitters={random:{count:1,enable:!0},value:e.map((t=>{const i=new l;return i.load(t),i}))};else{const i=e;if((0,s.isArray)(i.value))t.interactivity.modes.emitters={random:{count:i.random.count,enable:i.random.enable},value:i.value.map((t=>{const i=new l;return i.load(t),i}))};else{const e=new l;e.load(i.value),t.interactivity.modes.emitters={random:{count:i.random.count,enable:i.random.enable},value:e}}}}needsPlugin(t){if(!t)return!1;const i=t.emitters;return(0,s.isArray)(i)&&!!i.length||void 0!==i||!!t.interactivity?.events?.onClick?.mode&&(0,s.isInArray)(c.c.emitter,t.interactivity.events.onClick.mode)}}}}]);
2
+ (this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[214],{214(t,i,e){e.d(i,{EmittersPlugin:()=>m});var s=e(303);class o{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 n{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 a{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 r{constructor(){this.options={},this.replace=new a,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))}}class h{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))}}class l{constructor(){this.autoPlay=!0,this.fill=!0,this.life=new o,this.rate=new n,this.shape=new r,this.startCount=0}load(t){(0,s.isNull)(t)||(void 0!==t.autoPlay&&(this.autoPlay=t.autoPlay),void 0!==t.size&&(this.size??=new h,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))}}var c=e(271);function d(t,i){t.color?t.color.value=i:t.color={value:i}}class u{constructor(t,i,e,o,n){this.emitters=i,this.container=e,this._destroy=()=>{this._mutationObserver?.disconnect(),this._mutationObserver=void 0,this._resizeObserver?.disconnect(),this._resizeObserver=void 0,this.emitters.removeEmitter(this),this._engine.dispatchEvent("emitterDestroyed",{container:this.container,data:{emitter:this}})},this._prepareToDie=()=>{if(this._paused)return;const 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)},this._setColorAnimation=(t,i,e,o=1)=>{const n=this.container;if(!t.enable)return i;const a=(0,s.randomInRangeValue)(t.offset),r=(0,s.getRangeValue)(this.options.rate.delay),h=n.retina.reduceFactor?r*s.millisecondsToSeconds/n.retina.reduceFactor:1/0;return(i+(0,s.getRangeValue)(t.speed)*n.fpsLimit/h+a*o)%e},this._engine=t,this._currentDuration=0,this._currentEmitDelay=0,this._currentSpawnDelay=0,this._initialPosition=n,o instanceof l?this.options=o:(this.options=new l,this.options.load(o)),this._spawnDelay=e.retina.reduceFactor?(0,s.getRangeValue)(this.options.life.delay??0)*s.millisecondsToSeconds/e.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 a=(0,s.deepExtend)({},this.options.particles);if(a.move??={},a.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=a,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 r=this.options.shape,h=this._engine.emitterShapeManager?.getShapeGenerator(r.type);h&&(this._shape=h.generate(this.position,this.size,this.fill,r.options)),this._engine.dispatchEvent("emitterCreated",{container:e,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)return;if(!(this._lifeCount>0||this._immortal)&&this.options.life.count||!(this._firstSpawn||this._currentSpawnDelay>=(this._spawnDelay??0)))return;const t=this.container;if(void 0===this._emitDelay){const 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(){const 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;const 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._currentSpawnDelay,delete this._spawnDelay)),void 0!==this._emitDelay&&(this._currentEmitDelay+=t.value,this._currentEmitDelay>=this._emitDelay&&(this._emit(),this._currentEmitDelay-=this._emitDelay))}_calcPosition(){const t=this.container;if(this.options.domId){const i=(0,s.safeDocument)().getElementById(this.options.domId);if(i){const 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(){const t=this.container;if(this.options.domId){const i=(0,s.safeDocument)().getElementById(this.options.domId);if(i){const e=i.getBoundingClientRect();return{width:e.width*t.retina.pixelRatio,height:e.height*t.retina.pixelRatio,mode:s.PixelMode.precise}}}return this.options.size??(()=>{const t=new h;return t.load({height:0,mode:s.PixelMode.percent,width:0}),t})()}_emit(){if(this._paused)return;const t=(0,s.getRangeValue)(this.options.rate.quantity);this._emitParticles(t)}_emitParticles(t){const i=(0,s.itemFromSingleOrMultiple)(this._particlesOptions),e=this.options.spawnColor?.animation,o=this.container.retina.reduceFactor,n=!!e,a=!!this._shape,r=n||a,h=n?{h:s.hMax,s:s.sMax,l:s.lMax}:null,l=this.options.shape;for(let n=0;n<t*o;n++){const t=r?(0,s.deepExtend)({},i):i;this.spawnColor&&(e&&h&&(this.spawnColor.h=this._setColorAnimation(e.h,this.spawnColor.h,h.h,3.6),this.spawnColor.s=this._setColorAnimation(e.s,this.spawnColor.s,h.s),this.spawnColor.l=this._setColorAnimation(e.l,this.spawnColor.l,h.l)),d(t,this.spawnColor));let o=this.position;if(this._shape){const i=this._shape.randomPosition();if(i){o=i.position;const e=l.replace;e.color&&i.color&&d(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)}}}class p{constructor(t,i){this.container=i,this._engine=t,this.array=[],this.emitters=[],this.interactivityEmitters={random:{count:1,enable:!1},value:[]};i.getEmitter=t=>void 0===t||(0,s.isNumber)(t)?this.array[t??0]:this.array.find((i=>i.name===t)),i.addEmitter=async(t,i)=>this.addEmitter(t,i),i.removeEmitter=t=>{const e=i.getEmitter(t);e&&this.removeEmitter(e)},i.playEmitter=t=>{const e=i.getEmitter(t);e&&e.externalPlay()},i.pauseEmitter=t=>{const e=i.getEmitter(t);e&&e.externalPause()}}async addEmitter(t,i){const e=new l;e.load(t);const s=new u(this._engine,this,this.container,e,i);return await s.init(),this.array.push(s),s}handleClickMode(t){const i=this.interactivityEmitters;if(t!==c.c.emitter)return;let e;if((0,s.isArray)(i.value)){const t=0,o=i.value.length;if(o>t&&i.random.enable){e=[];const t=new Set;for(let n=0;n<i.random.count;n++){const a=(0,s.arrayRandomIndex)(i.value);if(t.has(a)&&t.size<o){n--;continue}t.add(a);const r=(0,s.itemFromArray)(i.value,a);r&&e.push(r)}}else e=i.value}else e=i.value;const o=e,n=this.container.interactivity.mouse.clickPosition;(0,s.executeOnSingleOrMultiple)(o,(async t=>{await this.addEmitter(t,n)}))}async init(){if(this.emitters=this.container.actualOptions.emitters,this.interactivityEmitters=this.container.actualOptions.interactivity.modes.emitters,(0,s.isArray)(this.emitters))for(const t of this.emitters)await this.addEmitter(t);else await this.addEmitter(this.emitters)}pause(){for(const t of this.array)t.pause()}play(){for(const t of this.array)t.play()}removeEmitter(t){const i=this.array.indexOf(t);i>=0&&this.array.splice(i,1)}resize(){for(const t of this.array)t.resize()}stop(){this.array=[]}update(t){const i=[];for(const e of this.array)i.push((()=>{e.update(t)}));i.forEach((t=>{t()}))}}class m{constructor(t){this._engine=t,this.id="emitters"}getPlugin(t){return Promise.resolve(new p(this._engine,t))}loadOptions(t,i){if(!this.needsPlugin(t)&&!this.needsPlugin(i))return;i?.emitters&&(t.emitters=(0,s.executeOnSingleOrMultiple)(i.emitters,(t=>{const i=new l;return i.load(t),i})));const e=i?.interactivity?.modes?.emitters;if(!e)return;const o={count:1,enable:!0};if((0,s.isArray)(e))t.interactivity.modes.emitters={random:o,value:e.map((t=>{const i=new l;return i.load(t),i}))};else{const i=e;if(Object.hasOwn(i,"value")){const e=i;if((0,s.isArray)(e.value))t.interactivity.modes.emitters={random:{count:e.random?.count??o.count,enable:e.random?.enable??o.enable},value:e.value.map((t=>{const i=new l;return i.load(t),i}))};else{const i=new l;i.load(e.value),t.interactivity.modes.emitters={random:{count:e.random?.count??o.count,enable:e.random?.enable??o.enable},value:i}}}else{const e=new l;e.load(i),t.interactivity.modes.emitters={random:o,value:e}}}}needsPlugin(t){if(!t)return!1;const i=t.emitters;return(0,s.isArray)(i)&&!!i.length||void 0!==i||!!t.interactivity?.events?.onClick?.mode&&(0,s.isInArray)(c.c.emitter,t.interactivity.events.onClick.mode)}}}}]);
@@ -1 +1 @@
1
- /*! tsParticles Emitters Plugin v4.0.0-alpha.2 by Matteo Bruni */
1
+ /*! tsParticles Emitters Plugin v4.0.0-alpha.3 by Matteo Bruni */
@@ -1 +1 @@
1
- /*! tsParticles Emitters Plugin v4.0.0-alpha.2 by Matteo Bruni */
1
+ /*! tsParticles Emitters Plugin v4.0.0-alpha.3 by Matteo Bruni */
@@ -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;
@@ -262,24 +262,19 @@ export class EmitterInstance {
262
262
  this._emitParticles(quantity);
263
263
  }
264
264
  _emitParticles(quantity) {
265
- const singleParticlesOptions = itemFromSingleOrMultiple(this._particlesOptions), reduceFactor = this.container.retina.reduceFactor;
265
+ const singleParticlesOptions = itemFromSingleOrMultiple(this._particlesOptions), 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
266
  for (let i = 0; i < quantity * reduceFactor; i++) {
267
- const particlesOptions = deepExtend({}, singleParticlesOptions);
267
+ const particlesOptions = needsCopy
268
+ ? deepExtend({}, singleParticlesOptions)
269
+ : singleParticlesOptions;
268
270
  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;
271
+ if (hslAnimation && maxValues) {
276
272
  this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h, colorFactor);
277
273
  this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, maxValues.s);
278
274
  this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, maxValues.l);
279
275
  }
280
276
  setParticlesOptionsColor(particlesOptions, this.spawnColor);
281
277
  }
282
- const shapeOptions = this.options.shape;
283
278
  let position = this.position;
284
279
  if (this._shape) {
285
280
  const shapePosData = this._shape.randomPosition();
@@ -54,17 +54,17 @@ export class Emitters {
54
54
  }
55
55
  let emittersModeOptions;
56
56
  if (isArray(modeEmitters.value)) {
57
- const minLength = 0;
58
- if (modeEmitters.value.length > minLength && modeEmitters.random.enable) {
57
+ const minLength = 0, modeEmittersCount = modeEmitters.value.length;
58
+ if (modeEmittersCount > minLength && modeEmitters.random.enable) {
59
59
  emittersModeOptions = [];
60
- const usedIndexes = [];
60
+ const usedIndexes = new Set();
61
61
  for (let i = 0; i < modeEmitters.random.count; i++) {
62
62
  const idx = arrayRandomIndex(modeEmitters.value);
63
- if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
63
+ if (usedIndexes.has(idx) && usedIndexes.size < modeEmittersCount) {
64
64
  i--;
65
65
  continue;
66
66
  }
67
- usedIndexes.push(idx);
67
+ usedIndexes.add(idx);
68
68
  const selectedOptions = itemFromArray(modeEmitters.value, idx);
69
69
  if (!selectedOptions) {
70
70
  continue;
@@ -121,8 +121,14 @@ export class Emitters {
121
121
  this.array = [];
122
122
  }
123
123
  update(delta) {
124
+ const updates = [];
124
125
  for (const emitter of this.array) {
125
- emitter.update(delta);
126
+ updates.push(() => {
127
+ emitter.update(delta);
128
+ });
126
129
  }
130
+ updates.forEach(update => {
131
+ update();
132
+ });
127
133
  }
128
134
  }
@@ -22,29 +22,34 @@ export class EmittersPlugin {
22
22
  });
23
23
  }
24
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)) {
25
+ if (!interactivityEmitters) {
26
+ return;
27
+ }
28
+ const defaultRandomOptions = {
29
+ count: 1,
30
+ enable: true,
31
+ };
32
+ if (isArray(interactivityEmitters)) {
33
+ options.interactivity.modes.emitters = {
34
+ random: defaultRandomOptions,
35
+ value: interactivityEmitters.map(s => {
36
+ const tmp = new Emitter();
37
+ tmp.load(s);
38
+ return tmp;
39
+ }),
40
+ };
41
+ }
42
+ else {
43
+ const emitterMode = interactivityEmitters;
44
+ if (Object.hasOwn(emitterMode, "value")) {
45
+ const emitterModeOptions = emitterMode;
46
+ if (isArray(emitterModeOptions.value)) {
42
47
  options.interactivity.modes.emitters = {
43
48
  random: {
44
- count: emitterMode.random.count,
45
- enable: emitterMode.random.enable,
49
+ count: emitterModeOptions.random?.count ?? defaultRandomOptions.count,
50
+ enable: emitterModeOptions.random?.enable ?? defaultRandomOptions.enable,
46
51
  },
47
- value: emitterMode.value.map(s => {
52
+ value: emitterModeOptions.value.map(s => {
48
53
  const tmp = new Emitter();
49
54
  tmp.load(s);
50
55
  return tmp;
@@ -53,16 +58,24 @@ export class EmittersPlugin {
53
58
  }
54
59
  else {
55
60
  const tmp = new Emitter();
56
- tmp.load(emitterMode.value);
61
+ tmp.load(emitterModeOptions.value);
57
62
  options.interactivity.modes.emitters = {
58
63
  random: {
59
- count: emitterMode.random.count,
60
- enable: emitterMode.random.enable,
64
+ count: emitterModeOptions.random?.count ?? defaultRandomOptions.count,
65
+ enable: emitterModeOptions.random?.enable ?? defaultRandomOptions.enable,
61
66
  },
62
67
  value: tmp,
63
68
  };
64
69
  }
65
70
  }
71
+ else {
72
+ const tmp = new Emitter();
73
+ tmp.load(emitterMode);
74
+ options.interactivity.modes.emitters = {
75
+ random: defaultRandomOptions,
76
+ value: tmp,
77
+ };
78
+ }
66
79
  }
67
80
  }
68
81
  needsPlugin(options) {
@@ -1,14 +1,14 @@
1
- const shapeGeneratorss = new Map();
1
+ const shapeGenerators = new Map();
2
2
  export class ShapeManager {
3
3
  addShapeGenerator(name, generator) {
4
4
  if (!this.getShapeGenerator(name)) {
5
- shapeGeneratorss.set(name, generator);
5
+ shapeGenerators.set(name, generator);
6
6
  }
7
7
  }
8
8
  getShapeGenerator(name) {
9
- return shapeGeneratorss.get(name);
9
+ return shapeGenerators.get(name);
10
10
  }
11
11
  getSupportedShapeGenerators() {
12
- return shapeGeneratorss.keys();
12
+ return shapeGenerators.keys();
13
13
  }
14
14
  }
package/browser/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export function loadEmittersPlugin(engine) {
2
- engine.checkVersion("4.0.0-alpha.2");
2
+ engine.checkVersion("4.0.0-alpha.3");
3
3
  engine.register(async (e) => {
4
4
  const { ShapeManager } = await import("./ShapeManager.js"), { EmittersPlugin } = await import("./EmittersPlugin.js");
5
5
  e.emitterShapeManager ??= new ShapeManager();
@@ -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;
@@ -262,24 +262,19 @@ export class EmitterInstance {
262
262
  this._emitParticles(quantity);
263
263
  }
264
264
  _emitParticles(quantity) {
265
- const singleParticlesOptions = itemFromSingleOrMultiple(this._particlesOptions), reduceFactor = this.container.retina.reduceFactor;
265
+ const singleParticlesOptions = itemFromSingleOrMultiple(this._particlesOptions), 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
266
  for (let i = 0; i < quantity * reduceFactor; i++) {
267
- const particlesOptions = deepExtend({}, singleParticlesOptions);
267
+ const particlesOptions = needsCopy
268
+ ? deepExtend({}, singleParticlesOptions)
269
+ : singleParticlesOptions;
268
270
  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;
271
+ if (hslAnimation && maxValues) {
276
272
  this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h, colorFactor);
277
273
  this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, maxValues.s);
278
274
  this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, maxValues.l);
279
275
  }
280
276
  setParticlesOptionsColor(particlesOptions, this.spawnColor);
281
277
  }
282
- const shapeOptions = this.options.shape;
283
278
  let position = this.position;
284
279
  if (this._shape) {
285
280
  const shapePosData = this._shape.randomPosition();
package/cjs/Emitters.js CHANGED
@@ -54,17 +54,17 @@ export class Emitters {
54
54
  }
55
55
  let emittersModeOptions;
56
56
  if (isArray(modeEmitters.value)) {
57
- const minLength = 0;
58
- if (modeEmitters.value.length > minLength && modeEmitters.random.enable) {
57
+ const minLength = 0, modeEmittersCount = modeEmitters.value.length;
58
+ if (modeEmittersCount > minLength && modeEmitters.random.enable) {
59
59
  emittersModeOptions = [];
60
- const usedIndexes = [];
60
+ const usedIndexes = new Set();
61
61
  for (let i = 0; i < modeEmitters.random.count; i++) {
62
62
  const idx = arrayRandomIndex(modeEmitters.value);
63
- if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
63
+ if (usedIndexes.has(idx) && usedIndexes.size < modeEmittersCount) {
64
64
  i--;
65
65
  continue;
66
66
  }
67
- usedIndexes.push(idx);
67
+ usedIndexes.add(idx);
68
68
  const selectedOptions = itemFromArray(modeEmitters.value, idx);
69
69
  if (!selectedOptions) {
70
70
  continue;
@@ -121,8 +121,14 @@ export class Emitters {
121
121
  this.array = [];
122
122
  }
123
123
  update(delta) {
124
+ const updates = [];
124
125
  for (const emitter of this.array) {
125
- emitter.update(delta);
126
+ updates.push(() => {
127
+ emitter.update(delta);
128
+ });
126
129
  }
130
+ updates.forEach(update => {
131
+ update();
132
+ });
127
133
  }
128
134
  }
@@ -22,29 +22,34 @@ export class EmittersPlugin {
22
22
  });
23
23
  }
24
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)) {
25
+ if (!interactivityEmitters) {
26
+ return;
27
+ }
28
+ const defaultRandomOptions = {
29
+ count: 1,
30
+ enable: true,
31
+ };
32
+ if (isArray(interactivityEmitters)) {
33
+ options.interactivity.modes.emitters = {
34
+ random: defaultRandomOptions,
35
+ value: interactivityEmitters.map(s => {
36
+ const tmp = new Emitter();
37
+ tmp.load(s);
38
+ return tmp;
39
+ }),
40
+ };
41
+ }
42
+ else {
43
+ const emitterMode = interactivityEmitters;
44
+ if (Object.hasOwn(emitterMode, "value")) {
45
+ const emitterModeOptions = emitterMode;
46
+ if (isArray(emitterModeOptions.value)) {
42
47
  options.interactivity.modes.emitters = {
43
48
  random: {
44
- count: emitterMode.random.count,
45
- enable: emitterMode.random.enable,
49
+ count: emitterModeOptions.random?.count ?? defaultRandomOptions.count,
50
+ enable: emitterModeOptions.random?.enable ?? defaultRandomOptions.enable,
46
51
  },
47
- value: emitterMode.value.map(s => {
52
+ value: emitterModeOptions.value.map(s => {
48
53
  const tmp = new Emitter();
49
54
  tmp.load(s);
50
55
  return tmp;
@@ -53,16 +58,24 @@ export class EmittersPlugin {
53
58
  }
54
59
  else {
55
60
  const tmp = new Emitter();
56
- tmp.load(emitterMode.value);
61
+ tmp.load(emitterModeOptions.value);
57
62
  options.interactivity.modes.emitters = {
58
63
  random: {
59
- count: emitterMode.random.count,
60
- enable: emitterMode.random.enable,
64
+ count: emitterModeOptions.random?.count ?? defaultRandomOptions.count,
65
+ enable: emitterModeOptions.random?.enable ?? defaultRandomOptions.enable,
61
66
  },
62
67
  value: tmp,
63
68
  };
64
69
  }
65
70
  }
71
+ else {
72
+ const tmp = new Emitter();
73
+ tmp.load(emitterMode);
74
+ options.interactivity.modes.emitters = {
75
+ random: defaultRandomOptions,
76
+ value: tmp,
77
+ };
78
+ }
66
79
  }
67
80
  }
68
81
  needsPlugin(options) {
@@ -1,14 +1,14 @@
1
- const shapeGeneratorss = new Map();
1
+ const shapeGenerators = new Map();
2
2
  export class ShapeManager {
3
3
  addShapeGenerator(name, generator) {
4
4
  if (!this.getShapeGenerator(name)) {
5
- shapeGeneratorss.set(name, generator);
5
+ shapeGenerators.set(name, generator);
6
6
  }
7
7
  }
8
8
  getShapeGenerator(name) {
9
- return shapeGeneratorss.get(name);
9
+ return shapeGenerators.get(name);
10
10
  }
11
11
  getSupportedShapeGenerators() {
12
- return shapeGeneratorss.keys();
12
+ return shapeGenerators.keys();
13
13
  }
14
14
  }
package/cjs/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export function loadEmittersPlugin(engine) {
2
- engine.checkVersion("4.0.0-alpha.2");
2
+ engine.checkVersion("4.0.0-alpha.3");
3
3
  engine.register(async (e) => {
4
4
  const { ShapeManager } = await import("./ShapeManager.js"), { EmittersPlugin } = await import("./EmittersPlugin.js");
5
5
  e.emitterShapeManager ??= new ShapeManager();
@@ -4,7 +4,7 @@
4
4
  * Demo / Generator : https://particles.js.org/
5
5
  * GitHub : https://www.github.com/matteobruni/tsparticles
6
6
  * How to use? : Check the GitHub README
7
- * v4.0.0-alpha.2
7
+ * v4.0.0-alpha.3
8
8
  */
9
9
  "use strict";
10
10
  /*
@@ -23,7 +23,7 @@
23
23
  \*****************************************/
24
24
  (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
25
25
 
26
- eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ EmitterInstance: () => (/* binding */ EmitterInstance)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Options/Classes/Emitter.js */ \"./dist/browser/Options/Classes/Emitter.js\");\n/* harmony import */ var _Options_Classes_EmitterSize_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Options/Classes/EmitterSize.js */ \"./dist/browser/Options/Classes/EmitterSize.js\");\n\n\n\nconst defaultLifeDelay = 0,\n minLifeCount = 0,\n defaultSpawnDelay = 0,\n defaultEmitDelay = 0,\n defaultLifeCount = -1,\n defaultColorAnimationFactor = 1;\nfunction setParticlesOptionsColor(particlesOptions, color) {\n if (particlesOptions.color) {\n particlesOptions.color.value = color;\n } else {\n particlesOptions.color = {\n value: color\n };\n }\n}\nclass EmitterInstance {\n constructor(engine, emitters, container, options, position) {\n this.emitters = emitters;\n this.container = container;\n this._destroy = () => {\n this._mutationObserver?.disconnect();\n this._mutationObserver = undefined;\n this._resizeObserver?.disconnect();\n this._resizeObserver = undefined;\n this.emitters.removeEmitter(this);\n this._engine.dispatchEvent(\"emitterDestroyed\", {\n container: this.container,\n data: {\n emitter: this\n }\n });\n };\n this._prepareToDie = () => {\n if (this._paused) {\n return;\n }\n const duration = this.options.life.duration !== undefined ? (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(this.options.life.duration) : undefined,\n minDuration = 0,\n minLifeCount = 0;\n if ((this._lifeCount > minLifeCount || this._immortal) && duration !== undefined && duration > minDuration) {\n this._duration = duration * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds;\n }\n };\n this._setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => {\n const container = this.container;\n if (!animation.enable) {\n return initValue;\n }\n const colorOffset = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.randomInRangeValue)(animation.offset),\n delay = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(this.options.rate.delay),\n emitFactor = container.retina.reduceFactor ? delay * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds / container.retina.reduceFactor : Infinity,\n colorSpeed = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(animation.speed);\n return (initValue + colorSpeed * container.fpsLimit / emitFactor + colorOffset * factor) % maxValue;\n };\n this._engine = engine;\n this._currentDuration = 0;\n this._currentEmitDelay = 0;\n this._currentSpawnDelay = 0;\n this._initialPosition = position;\n if (options instanceof _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__.Emitter) {\n this.options = options;\n } else {\n this.options = new _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__.Emitter();\n this.options.load(options);\n }\n this._spawnDelay = container.retina.reduceFactor ? (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(this.options.life.delay ?? defaultLifeDelay) * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds / container.retina.reduceFactor : Infinity;\n this.position = this._initialPosition ?? this._calcPosition();\n this.name = this.options.name;\n this.fill = this.options.fill;\n this._firstSpawn = !this.options.life.wait;\n this._startParticlesAdded = false;\n const particlesOptions = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.deepExtend)({}, this.options.particles);\n particlesOptions.move ??= {};\n particlesOptions.move.direction ??= this.options.direction;\n if (this.options.spawnColor) {\n this.spawnColor = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.rangeColorToHsl)(this._engine, this.options.spawnColor);\n }\n this._paused = !this.options.autoPlay;\n this._particlesOptions = particlesOptions;\n this._size = this._calcSize();\n this.size = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getSize)(this._size, this.container.canvas.size);\n this._lifeCount = this.options.life.count ?? defaultLifeCount;\n this._immortal = this._lifeCount <= minLifeCount;\n if (this.options.domId) {\n const element = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeDocument)().getElementById(this.options.domId);\n if (element) {\n this._mutationObserver = new MutationObserver(() => {\n this.resize();\n });\n this._resizeObserver = new ResizeObserver(() => {\n this.resize();\n });\n this._mutationObserver.observe(element, {\n attributes: true,\n attributeFilter: [\"style\", \"width\", \"height\"]\n });\n this._resizeObserver.observe(element);\n }\n }\n const shapeOptions = this.options.shape,\n shapeGenerator = this._engine.emitterShapeManager?.getShapeGenerator(shapeOptions.type);\n if (shapeGenerator) {\n this._shape = shapeGenerator.generate(this.position, this.size, this.fill, shapeOptions.options);\n }\n this._engine.dispatchEvent(\"emitterCreated\", {\n container,\n data: {\n emitter: this\n }\n });\n this.play();\n }\n externalPause() {\n this._paused = true;\n this.pause();\n }\n externalPlay() {\n this._paused = false;\n this.play();\n }\n async init() {\n await this._shape?.init();\n }\n pause() {\n if (this._paused) {\n return;\n }\n delete this._emitDelay;\n }\n play() {\n if (this._paused) {\n return;\n }\n if (!((this._lifeCount > minLifeCount || this._immortal || !this.options.life.count) && (this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? defaultSpawnDelay)))) {\n return;\n }\n const container = this.container;\n if (this._emitDelay === undefined) {\n const delay = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(this.options.rate.delay);\n this._emitDelay = container.retina.reduceFactor ? delay * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds / container.retina.reduceFactor : Infinity;\n }\n if (this._lifeCount > minLifeCount || this._immortal) {\n this._prepareToDie();\n }\n }\n resize() {\n const initialPosition = this._initialPosition,\n container = this.container;\n this.position = initialPosition && (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isPointInside)(initialPosition, container.canvas.size, _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Vector.origin) ? initialPosition : this._calcPosition();\n this._size = this._calcSize();\n this.size = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getSize)(this._size, container.canvas.size);\n this._shape?.resize(this.position, this.size);\n }\n update(delta) {\n if (this._paused) {\n return;\n }\n const container = this.container;\n if (this._firstSpawn) {\n this._firstSpawn = false;\n this._currentSpawnDelay = this._spawnDelay ?? defaultSpawnDelay;\n this._currentEmitDelay = this._emitDelay ?? defaultEmitDelay;\n }\n if (!this._startParticlesAdded) {\n this._startParticlesAdded = true;\n this._emitParticles(this.options.startCount);\n }\n if (this._duration !== undefined) {\n this._currentDuration += delta.value;\n if (this._currentDuration >= this._duration) {\n this.pause();\n if (this._spawnDelay !== undefined) {\n delete this._spawnDelay;\n }\n if (!this._immortal) {\n this._lifeCount--;\n }\n if (this._lifeCount > minLifeCount || this._immortal) {\n this.position = this._calcPosition();\n this._shape?.resize(this.position, this.size);\n this._spawnDelay = container.retina.reduceFactor ? (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(this.options.life.delay ?? defaultLifeDelay) * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds / container.retina.reduceFactor : Infinity;\n } else {\n this._destroy();\n }\n this._currentDuration -= this._duration;\n delete this._duration;\n }\n }\n if (this._spawnDelay !== undefined) {\n this._currentSpawnDelay += delta.value;\n if (this._currentSpawnDelay >= this._spawnDelay) {\n this._engine.dispatchEvent(\"emitterPlay\", {\n container: this.container\n });\n this.play();\n this._currentSpawnDelay -= this._currentSpawnDelay;\n delete this._spawnDelay;\n }\n }\n if (this._emitDelay !== undefined) {\n this._currentEmitDelay += delta.value;\n if (this._currentEmitDelay >= this._emitDelay) {\n this._emit();\n this._currentEmitDelay -= this._emitDelay;\n }\n }\n }\n _calcPosition() {\n const container = this.container;\n if (this.options.domId) {\n const element = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeDocument)().getElementById(this.options.domId);\n if (element) {\n const elRect = element.getBoundingClientRect(),\n pxRatio = container.retina.pixelRatio;\n return {\n x: (elRect.x + elRect.width * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half) * pxRatio,\n y: (elRect.y + elRect.height * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half) * pxRatio\n };\n }\n }\n return (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.calcPositionOrRandomFromSizeRanged)({\n size: container.canvas.size,\n position: this.options.position\n });\n }\n _calcSize() {\n const container = this.container;\n if (this.options.domId) {\n const element = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeDocument)().getElementById(this.options.domId);\n if (element) {\n const elRect = element.getBoundingClientRect();\n return {\n width: elRect.width * container.retina.pixelRatio,\n height: elRect.height * container.retina.pixelRatio,\n mode: _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.PixelMode.precise\n };\n }\n }\n return this.options.size ?? (() => {\n const size = new _Options_Classes_EmitterSize_js__WEBPACK_IMPORTED_MODULE_2__.EmitterSize();\n size.load({\n height: 0,\n mode: _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.PixelMode.percent,\n width: 0\n });\n return size;\n })();\n }\n _emit() {\n if (this._paused) {\n return;\n }\n const quantity = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(this.options.rate.quantity);\n this._emitParticles(quantity);\n }\n _emitParticles(quantity) {\n const singleParticlesOptions = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.itemFromSingleOrMultiple)(this._particlesOptions),\n reduceFactor = this.container.retina.reduceFactor;\n for (let i = 0; i < quantity * reduceFactor; i++) {\n const particlesOptions = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.deepExtend)({}, singleParticlesOptions);\n if (this.spawnColor) {\n const hslAnimation = this.options.spawnColor?.animation;\n if (hslAnimation) {\n const maxValues = {\n h: _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.hMax,\n s: _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.sMax,\n l: _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.lMax\n },\n colorFactor = 3.6;\n this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h, colorFactor);\n this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, maxValues.s);\n this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, maxValues.l);\n }\n setParticlesOptionsColor(particlesOptions, this.spawnColor);\n }\n const shapeOptions = this.options.shape;\n let position = this.position;\n if (this._shape) {\n const shapePosData = this._shape.randomPosition();\n if (shapePosData) {\n position = shapePosData.position;\n const replaceData = shapeOptions.replace;\n if (replaceData.color && shapePosData.color) {\n setParticlesOptionsColor(particlesOptions, shapePosData.color);\n }\n if (replaceData.opacity) {\n if (particlesOptions.opacity) {\n particlesOptions.opacity.value = shapePosData.opacity;\n } else {\n particlesOptions.opacity = {\n value: shapePosData.opacity\n };\n }\n }\n } else {\n position = null;\n }\n }\n if (position) {\n this.container.particles.addParticle(position, particlesOptions);\n }\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters/./dist/browser/EmitterInstance.js?\n}");
26
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ EmitterInstance: () => (/* binding */ EmitterInstance)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Options/Classes/Emitter.js */ \"./dist/browser/Options/Classes/Emitter.js\");\n/* harmony import */ var _Options_Classes_EmitterSize_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Options/Classes/EmitterSize.js */ \"./dist/browser/Options/Classes/EmitterSize.js\");\n\n\n\nconst defaultLifeDelay = 0,\n minLifeCount = 0,\n defaultSpawnDelay = 0,\n defaultEmitDelay = 0,\n defaultLifeCount = -1,\n defaultColorAnimationFactor = 1,\n colorFactor = 3.6;\nfunction setParticlesOptionsColor(particlesOptions, color) {\n if (particlesOptions.color) {\n particlesOptions.color.value = color;\n } else {\n particlesOptions.color = {\n value: color\n };\n }\n}\nclass EmitterInstance {\n constructor(engine, emitters, container, options, position) {\n this.emitters = emitters;\n this.container = container;\n this._destroy = () => {\n this._mutationObserver?.disconnect();\n this._mutationObserver = undefined;\n this._resizeObserver?.disconnect();\n this._resizeObserver = undefined;\n this.emitters.removeEmitter(this);\n this._engine.dispatchEvent(\"emitterDestroyed\", {\n container: this.container,\n data: {\n emitter: this\n }\n });\n };\n this._prepareToDie = () => {\n if (this._paused) {\n return;\n }\n const duration = this.options.life.duration !== undefined ? (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(this.options.life.duration) : undefined,\n minDuration = 0,\n minLifeCount = 0;\n if ((this._lifeCount > minLifeCount || this._immortal) && duration !== undefined && duration > minDuration) {\n this._duration = duration * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds;\n }\n };\n this._setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => {\n const container = this.container;\n if (!animation.enable) {\n return initValue;\n }\n const colorOffset = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.randomInRangeValue)(animation.offset),\n delay = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(this.options.rate.delay),\n emitFactor = container.retina.reduceFactor ? delay * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds / container.retina.reduceFactor : Infinity,\n colorSpeed = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(animation.speed);\n return (initValue + colorSpeed * container.fpsLimit / emitFactor + colorOffset * factor) % maxValue;\n };\n this._engine = engine;\n this._currentDuration = 0;\n this._currentEmitDelay = 0;\n this._currentSpawnDelay = 0;\n this._initialPosition = position;\n if (options instanceof _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__.Emitter) {\n this.options = options;\n } else {\n this.options = new _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__.Emitter();\n this.options.load(options);\n }\n this._spawnDelay = container.retina.reduceFactor ? (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(this.options.life.delay ?? defaultLifeDelay) * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds / container.retina.reduceFactor : Infinity;\n this.position = this._initialPosition ?? this._calcPosition();\n this.name = this.options.name;\n this.fill = this.options.fill;\n this._firstSpawn = !this.options.life.wait;\n this._startParticlesAdded = false;\n const particlesOptions = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.deepExtend)({}, this.options.particles);\n particlesOptions.move ??= {};\n particlesOptions.move.direction ??= this.options.direction;\n if (this.options.spawnColor) {\n this.spawnColor = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.rangeColorToHsl)(this._engine, this.options.spawnColor);\n }\n this._paused = !this.options.autoPlay;\n this._particlesOptions = particlesOptions;\n this._size = this._calcSize();\n this.size = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getSize)(this._size, this.container.canvas.size);\n this._lifeCount = this.options.life.count ?? defaultLifeCount;\n this._immortal = this._lifeCount <= minLifeCount;\n if (this.options.domId) {\n const element = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeDocument)().getElementById(this.options.domId);\n if (element) {\n this._mutationObserver = new MutationObserver(() => {\n this.resize();\n });\n this._resizeObserver = new ResizeObserver(() => {\n this.resize();\n });\n this._mutationObserver.observe(element, {\n attributes: true,\n attributeFilter: [\"style\", \"width\", \"height\"]\n });\n this._resizeObserver.observe(element);\n }\n }\n const shapeOptions = this.options.shape,\n shapeGenerator = this._engine.emitterShapeManager?.getShapeGenerator(shapeOptions.type);\n if (shapeGenerator) {\n this._shape = shapeGenerator.generate(this.position, this.size, this.fill, shapeOptions.options);\n }\n this._engine.dispatchEvent(\"emitterCreated\", {\n container,\n data: {\n emitter: this\n }\n });\n this.play();\n }\n externalPause() {\n this._paused = true;\n this.pause();\n }\n externalPlay() {\n this._paused = false;\n this.play();\n }\n async init() {\n await this._shape?.init();\n }\n pause() {\n if (this._paused) {\n return;\n }\n delete this._emitDelay;\n }\n play() {\n if (this._paused) {\n return;\n }\n if (!((this._lifeCount > minLifeCount || this._immortal || !this.options.life.count) && (this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? defaultSpawnDelay)))) {\n return;\n }\n const container = this.container;\n if (this._emitDelay === undefined) {\n const delay = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(this.options.rate.delay);\n this._emitDelay = container.retina.reduceFactor ? delay * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds / container.retina.reduceFactor : Infinity;\n }\n if (this._lifeCount > minLifeCount || this._immortal) {\n this._prepareToDie();\n }\n }\n resize() {\n const initialPosition = this._initialPosition,\n container = this.container;\n this.position = initialPosition && (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isPointInside)(initialPosition, container.canvas.size, _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Vector.origin) ? initialPosition : this._calcPosition();\n this._size = this._calcSize();\n this.size = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getSize)(this._size, container.canvas.size);\n this._shape?.resize(this.position, this.size);\n }\n update(delta) {\n if (this._paused) {\n return;\n }\n const container = this.container;\n if (this._firstSpawn) {\n this._firstSpawn = false;\n this._currentSpawnDelay = this._spawnDelay ?? defaultSpawnDelay;\n this._currentEmitDelay = this._emitDelay ?? defaultEmitDelay;\n }\n if (!this._startParticlesAdded) {\n this._startParticlesAdded = true;\n this._emitParticles(this.options.startCount);\n }\n if (this._duration !== undefined) {\n this._currentDuration += delta.value;\n if (this._currentDuration >= this._duration) {\n this.pause();\n if (this._spawnDelay !== undefined) {\n delete this._spawnDelay;\n }\n if (!this._immortal) {\n this._lifeCount--;\n }\n if (this._lifeCount > minLifeCount || this._immortal) {\n this.position = this._calcPosition();\n this._shape?.resize(this.position, this.size);\n this._spawnDelay = container.retina.reduceFactor ? (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(this.options.life.delay ?? defaultLifeDelay) * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds / container.retina.reduceFactor : Infinity;\n } else {\n this._destroy();\n }\n this._currentDuration -= this._duration;\n delete this._duration;\n }\n }\n if (this._spawnDelay !== undefined) {\n this._currentSpawnDelay += delta.value;\n if (this._currentSpawnDelay >= this._spawnDelay) {\n this._engine.dispatchEvent(\"emitterPlay\", {\n container: this.container\n });\n this.play();\n this._currentSpawnDelay -= this._currentSpawnDelay;\n delete this._spawnDelay;\n }\n }\n if (this._emitDelay !== undefined) {\n this._currentEmitDelay += delta.value;\n if (this._currentEmitDelay >= this._emitDelay) {\n this._emit();\n this._currentEmitDelay -= this._emitDelay;\n }\n }\n }\n _calcPosition() {\n const container = this.container;\n if (this.options.domId) {\n const element = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeDocument)().getElementById(this.options.domId);\n if (element) {\n const elRect = element.getBoundingClientRect(),\n pxRatio = container.retina.pixelRatio;\n return {\n x: (elRect.x + elRect.width * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half) * pxRatio,\n y: (elRect.y + elRect.height * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half) * pxRatio\n };\n }\n }\n return (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.calcPositionOrRandomFromSizeRanged)({\n size: container.canvas.size,\n position: this.options.position\n });\n }\n _calcSize() {\n const container = this.container;\n if (this.options.domId) {\n const element = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeDocument)().getElementById(this.options.domId);\n if (element) {\n const elRect = element.getBoundingClientRect();\n return {\n width: elRect.width * container.retina.pixelRatio,\n height: elRect.height * container.retina.pixelRatio,\n mode: _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.PixelMode.precise\n };\n }\n }\n return this.options.size ?? (() => {\n const size = new _Options_Classes_EmitterSize_js__WEBPACK_IMPORTED_MODULE_2__.EmitterSize();\n size.load({\n height: 0,\n mode: _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.PixelMode.percent,\n width: 0\n });\n return size;\n })();\n }\n _emit() {\n if (this._paused) {\n return;\n }\n const quantity = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeValue)(this.options.rate.quantity);\n this._emitParticles(quantity);\n }\n _emitParticles(quantity) {\n const singleParticlesOptions = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.itemFromSingleOrMultiple)(this._particlesOptions),\n hslAnimation = this.options.spawnColor?.animation,\n reduceFactor = this.container.retina.reduceFactor,\n needsColorAnimation = !!hslAnimation,\n needsShapeData = !!this._shape,\n needsCopy = needsColorAnimation || needsShapeData,\n maxValues = needsColorAnimation ? {\n h: _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.hMax,\n s: _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.sMax,\n l: _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.lMax\n } : null,\n shapeOptions = this.options.shape;\n for (let i = 0; i < quantity * reduceFactor; i++) {\n const particlesOptions = needsCopy ? (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.deepExtend)({}, singleParticlesOptions) : singleParticlesOptions;\n if (this.spawnColor) {\n if (hslAnimation && maxValues) {\n this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h, colorFactor);\n this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, maxValues.s);\n this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, maxValues.l);\n }\n setParticlesOptionsColor(particlesOptions, this.spawnColor);\n }\n let position = this.position;\n if (this._shape) {\n const shapePosData = this._shape.randomPosition();\n if (shapePosData) {\n position = shapePosData.position;\n const replaceData = shapeOptions.replace;\n if (replaceData.color && shapePosData.color) {\n setParticlesOptionsColor(particlesOptions, shapePosData.color);\n }\n if (replaceData.opacity) {\n if (particlesOptions.opacity) {\n particlesOptions.opacity.value = shapePosData.opacity;\n } else {\n particlesOptions.opacity = {\n value: shapePosData.opacity\n };\n }\n }\n } else {\n position = null;\n }\n }\n if (position) {\n this.container.particles.addParticle(position, particlesOptions);\n }\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters/./dist/browser/EmitterInstance.js?\n}");
27
27
 
28
28
  /***/ },
29
29
 
@@ -33,7 +33,7 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
33
33
  \**********************************/
34
34
  (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
35
35
 
36
- eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Emitters: () => (/* binding */ Emitters)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Options/Classes/Emitter.js */ \"./dist/browser/Options/Classes/Emitter.js\");\n/* harmony import */ var _Enums_EmitterClickMode_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Enums/EmitterClickMode.js */ \"./dist/browser/Enums/EmitterClickMode.js\");\n/* harmony import */ var _EmitterInstance_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./EmitterInstance.js */ \"./dist/browser/EmitterInstance.js\");\n\n\n\n\nclass Emitters {\n constructor(engine, container) {\n this.container = container;\n this._engine = engine;\n this.array = [];\n this.emitters = [];\n this.interactivityEmitters = {\n random: {\n count: 1,\n enable: false\n },\n value: []\n };\n const defaultIndex = 0;\n container.getEmitter = idxOrName => idxOrName === undefined || (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNumber)(idxOrName) ? this.array[idxOrName ?? defaultIndex] : this.array.find(t => t.name === idxOrName);\n container.addEmitter = async (options, position) => this.addEmitter(options, position);\n container.removeEmitter = idxOrName => {\n const emitter = container.getEmitter(idxOrName);\n if (emitter) {\n this.removeEmitter(emitter);\n }\n };\n container.playEmitter = idxOrName => {\n const emitter = container.getEmitter(idxOrName);\n if (emitter) {\n emitter.externalPlay();\n }\n };\n container.pauseEmitter = idxOrName => {\n const emitter = container.getEmitter(idxOrName);\n if (emitter) {\n emitter.externalPause();\n }\n };\n }\n async addEmitter(options, position) {\n const emitterOptions = new _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__.Emitter();\n emitterOptions.load(options);\n const emitter = new _EmitterInstance_js__WEBPACK_IMPORTED_MODULE_3__.EmitterInstance(this._engine, this, this.container, emitterOptions, position);\n await emitter.init();\n this.array.push(emitter);\n return emitter;\n }\n handleClickMode(mode) {\n const modeEmitters = this.interactivityEmitters;\n if (mode !== _Enums_EmitterClickMode_js__WEBPACK_IMPORTED_MODULE_2__.EmitterClickMode.emitter) {\n return;\n }\n let emittersModeOptions;\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isArray)(modeEmitters.value)) {\n const minLength = 0;\n if (modeEmitters.value.length > minLength && modeEmitters.random.enable) {\n emittersModeOptions = [];\n const usedIndexes = [];\n for (let i = 0; i < modeEmitters.random.count; i++) {\n const idx = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.arrayRandomIndex)(modeEmitters.value);\n if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {\n i--;\n continue;\n }\n usedIndexes.push(idx);\n const selectedOptions = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.itemFromArray)(modeEmitters.value, idx);\n if (!selectedOptions) {\n continue;\n }\n emittersModeOptions.push(selectedOptions);\n }\n } else {\n emittersModeOptions = modeEmitters.value;\n }\n } else {\n emittersModeOptions = modeEmitters.value;\n }\n const emittersOptions = emittersModeOptions,\n ePosition = this.container.interactivity.mouse.clickPosition;\n void (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.executeOnSingleOrMultiple)(emittersOptions, async emitter => {\n await this.addEmitter(emitter, ePosition);\n });\n }\n async init() {\n this.emitters = this.container.actualOptions.emitters;\n this.interactivityEmitters = this.container.actualOptions.interactivity.modes.emitters;\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isArray)(this.emitters)) {\n for (const emitterOptions of this.emitters) {\n await this.addEmitter(emitterOptions);\n }\n } else {\n await this.addEmitter(this.emitters);\n }\n }\n pause() {\n for (const emitter of this.array) {\n emitter.pause();\n }\n }\n play() {\n for (const emitter of this.array) {\n emitter.play();\n }\n }\n removeEmitter(emitter) {\n const index = this.array.indexOf(emitter),\n minIndex = 0,\n deleteCount = 1;\n if (index >= minIndex) {\n this.array.splice(index, deleteCount);\n }\n }\n resize() {\n for (const emitter of this.array) {\n emitter.resize();\n }\n }\n stop() {\n this.array = [];\n }\n update(delta) {\n for (const emitter of this.array) {\n emitter.update(delta);\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters/./dist/browser/Emitters.js?\n}");
36
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ Emitters: () => (/* binding */ Emitters)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Options/Classes/Emitter.js */ \"./dist/browser/Options/Classes/Emitter.js\");\n/* harmony import */ var _Enums_EmitterClickMode_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Enums/EmitterClickMode.js */ \"./dist/browser/Enums/EmitterClickMode.js\");\n/* harmony import */ var _EmitterInstance_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./EmitterInstance.js */ \"./dist/browser/EmitterInstance.js\");\n\n\n\n\nclass Emitters {\n constructor(engine, container) {\n this.container = container;\n this._engine = engine;\n this.array = [];\n this.emitters = [];\n this.interactivityEmitters = {\n random: {\n count: 1,\n enable: false\n },\n value: []\n };\n const defaultIndex = 0;\n container.getEmitter = idxOrName => idxOrName === undefined || (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNumber)(idxOrName) ? this.array[idxOrName ?? defaultIndex] : this.array.find(t => t.name === idxOrName);\n container.addEmitter = async (options, position) => this.addEmitter(options, position);\n container.removeEmitter = idxOrName => {\n const emitter = container.getEmitter(idxOrName);\n if (emitter) {\n this.removeEmitter(emitter);\n }\n };\n container.playEmitter = idxOrName => {\n const emitter = container.getEmitter(idxOrName);\n if (emitter) {\n emitter.externalPlay();\n }\n };\n container.pauseEmitter = idxOrName => {\n const emitter = container.getEmitter(idxOrName);\n if (emitter) {\n emitter.externalPause();\n }\n };\n }\n async addEmitter(options, position) {\n const emitterOptions = new _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__.Emitter();\n emitterOptions.load(options);\n const emitter = new _EmitterInstance_js__WEBPACK_IMPORTED_MODULE_3__.EmitterInstance(this._engine, this, this.container, emitterOptions, position);\n await emitter.init();\n this.array.push(emitter);\n return emitter;\n }\n handleClickMode(mode) {\n const modeEmitters = this.interactivityEmitters;\n if (mode !== _Enums_EmitterClickMode_js__WEBPACK_IMPORTED_MODULE_2__.EmitterClickMode.emitter) {\n return;\n }\n let emittersModeOptions;\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isArray)(modeEmitters.value)) {\n const minLength = 0,\n modeEmittersCount = modeEmitters.value.length;\n if (modeEmittersCount > minLength && modeEmitters.random.enable) {\n emittersModeOptions = [];\n const usedIndexes = new Set();\n for (let i = 0; i < modeEmitters.random.count; i++) {\n const idx = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.arrayRandomIndex)(modeEmitters.value);\n if (usedIndexes.has(idx) && usedIndexes.size < modeEmittersCount) {\n i--;\n continue;\n }\n usedIndexes.add(idx);\n const selectedOptions = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.itemFromArray)(modeEmitters.value, idx);\n if (!selectedOptions) {\n continue;\n }\n emittersModeOptions.push(selectedOptions);\n }\n } else {\n emittersModeOptions = modeEmitters.value;\n }\n } else {\n emittersModeOptions = modeEmitters.value;\n }\n const emittersOptions = emittersModeOptions,\n ePosition = this.container.interactivity.mouse.clickPosition;\n void (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.executeOnSingleOrMultiple)(emittersOptions, async emitter => {\n await this.addEmitter(emitter, ePosition);\n });\n }\n async init() {\n this.emitters = this.container.actualOptions.emitters;\n this.interactivityEmitters = this.container.actualOptions.interactivity.modes.emitters;\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isArray)(this.emitters)) {\n for (const emitterOptions of this.emitters) {\n await this.addEmitter(emitterOptions);\n }\n } else {\n await this.addEmitter(this.emitters);\n }\n }\n pause() {\n for (const emitter of this.array) {\n emitter.pause();\n }\n }\n play() {\n for (const emitter of this.array) {\n emitter.play();\n }\n }\n removeEmitter(emitter) {\n const index = this.array.indexOf(emitter),\n minIndex = 0,\n deleteCount = 1;\n if (index >= minIndex) {\n this.array.splice(index, deleteCount);\n }\n }\n resize() {\n for (const emitter of this.array) {\n emitter.resize();\n }\n }\n stop() {\n this.array = [];\n }\n update(delta) {\n const updates = [];\n for (const emitter of this.array) {\n updates.push(() => {\n emitter.update(delta);\n });\n }\n updates.forEach(update => {\n update();\n });\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters/./dist/browser/Emitters.js?\n}");
37
37
 
38
38
  /***/ },
39
39
 
@@ -43,7 +43,7 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
43
43
  \****************************************/
44
44
  (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
45
45
 
46
- eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ EmittersPlugin: () => (/* binding */ EmittersPlugin)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Options/Classes/Emitter.js */ \"./dist/browser/Options/Classes/Emitter.js\");\n/* harmony import */ var _Enums_EmitterClickMode_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Enums/EmitterClickMode.js */ \"./dist/browser/Enums/EmitterClickMode.js\");\n/* harmony import */ var _Emitters_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Emitters.js */ \"./dist/browser/Emitters.js\");\n\n\n\n\nclass EmittersPlugin {\n constructor(engine) {\n this._engine = engine;\n this.id = \"emitters\";\n }\n getPlugin(container) {\n return Promise.resolve(new _Emitters_js__WEBPACK_IMPORTED_MODULE_3__.Emitters(this._engine, container));\n }\n loadOptions(options, source) {\n if (!this.needsPlugin(options) && !this.needsPlugin(source)) {\n return;\n }\n if (source?.emitters) {\n options.emitters = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.executeOnSingleOrMultiple)(source.emitters, emitter => {\n const tmp = new _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__.Emitter();\n tmp.load(emitter);\n return tmp;\n });\n }\n const interactivityEmitters = source?.interactivity?.modes?.emitters;\n if (interactivityEmitters) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isArray)(interactivityEmitters)) {\n options.interactivity.modes.emitters = {\n random: {\n count: 1,\n enable: true\n },\n value: interactivityEmitters.map(s => {\n const tmp = new _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__.Emitter();\n tmp.load(s);\n return tmp;\n })\n };\n } else {\n const emitterMode = interactivityEmitters;\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isArray)(emitterMode.value)) {\n options.interactivity.modes.emitters = {\n random: {\n count: emitterMode.random.count,\n enable: emitterMode.random.enable\n },\n value: emitterMode.value.map(s => {\n const tmp = new _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__.Emitter();\n tmp.load(s);\n return tmp;\n })\n };\n } else {\n const tmp = new _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__.Emitter();\n tmp.load(emitterMode.value);\n options.interactivity.modes.emitters = {\n random: {\n count: emitterMode.random.count,\n enable: emitterMode.random.enable\n },\n value: tmp\n };\n }\n }\n }\n }\n needsPlugin(options) {\n if (!options) {\n return false;\n }\n const emitters = options.emitters;\n return (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isArray)(emitters) && !!emitters.length || emitters !== undefined || !!options.interactivity?.events?.onClick?.mode && (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(_Enums_EmitterClickMode_js__WEBPACK_IMPORTED_MODULE_2__.EmitterClickMode.emitter, options.interactivity.events.onClick.mode);\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters/./dist/browser/EmittersPlugin.js?\n}");
46
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ EmittersPlugin: () => (/* binding */ EmittersPlugin)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Options/Classes/Emitter.js */ \"./dist/browser/Options/Classes/Emitter.js\");\n/* harmony import */ var _Enums_EmitterClickMode_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Enums/EmitterClickMode.js */ \"./dist/browser/Enums/EmitterClickMode.js\");\n/* harmony import */ var _Emitters_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Emitters.js */ \"./dist/browser/Emitters.js\");\n\n\n\n\nclass EmittersPlugin {\n constructor(engine) {\n this._engine = engine;\n this.id = \"emitters\";\n }\n getPlugin(container) {\n return Promise.resolve(new _Emitters_js__WEBPACK_IMPORTED_MODULE_3__.Emitters(this._engine, container));\n }\n loadOptions(options, source) {\n if (!this.needsPlugin(options) && !this.needsPlugin(source)) {\n return;\n }\n if (source?.emitters) {\n options.emitters = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.executeOnSingleOrMultiple)(source.emitters, emitter => {\n const tmp = new _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__.Emitter();\n tmp.load(emitter);\n return tmp;\n });\n }\n const interactivityEmitters = source?.interactivity?.modes?.emitters;\n if (!interactivityEmitters) {\n return;\n }\n const defaultRandomOptions = {\n count: 1,\n enable: true\n };\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isArray)(interactivityEmitters)) {\n options.interactivity.modes.emitters = {\n random: defaultRandomOptions,\n value: interactivityEmitters.map(s => {\n const tmp = new _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__.Emitter();\n tmp.load(s);\n return tmp;\n })\n };\n } else {\n const emitterMode = interactivityEmitters;\n if (Object.hasOwn(emitterMode, \"value\")) {\n const emitterModeOptions = emitterMode;\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isArray)(emitterModeOptions.value)) {\n options.interactivity.modes.emitters = {\n random: {\n count: emitterModeOptions.random?.count ?? defaultRandomOptions.count,\n enable: emitterModeOptions.random?.enable ?? defaultRandomOptions.enable\n },\n value: emitterModeOptions.value.map(s => {\n const tmp = new _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__.Emitter();\n tmp.load(s);\n return tmp;\n })\n };\n } else {\n const tmp = new _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__.Emitter();\n tmp.load(emitterModeOptions.value);\n options.interactivity.modes.emitters = {\n random: {\n count: emitterModeOptions.random?.count ?? defaultRandomOptions.count,\n enable: emitterModeOptions.random?.enable ?? defaultRandomOptions.enable\n },\n value: tmp\n };\n }\n } else {\n const tmp = new _Options_Classes_Emitter_js__WEBPACK_IMPORTED_MODULE_1__.Emitter();\n tmp.load(emitterMode);\n options.interactivity.modes.emitters = {\n random: defaultRandomOptions,\n value: tmp\n };\n }\n }\n }\n needsPlugin(options) {\n if (!options) {\n return false;\n }\n const emitters = options.emitters;\n return (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isArray)(emitters) && !!emitters.length || emitters !== undefined || !!options.interactivity?.events?.onClick?.mode && (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(_Enums_EmitterClickMode_js__WEBPACK_IMPORTED_MODULE_2__.EmitterClickMode.emitter, options.interactivity.events.onClick.mode);\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters/./dist/browser/EmittersPlugin.js?\n}");
47
47
 
48
48
  /***/ },
49
49
 
@@ -4,7 +4,7 @@
4
4
  * Demo / Generator : https://particles.js.org/
5
5
  * GitHub : https://www.github.com/matteobruni/tsparticles
6
6
  * How to use? : Check the GitHub README
7
- * v4.0.0-alpha.2
7
+ * v4.0.0-alpha.3
8
8
  */
9
9
  "use strict";
10
10
  /*
@@ -23,7 +23,7 @@
23
23
  \**************************************/
24
24
  (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
25
25
 
26
- eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ ShapeManager: () => (/* binding */ ShapeManager)\n/* harmony export */ });\nconst shapeGeneratorss = new Map();\nclass ShapeManager {\n addShapeGenerator(name, generator) {\n if (!this.getShapeGenerator(name)) {\n shapeGeneratorss.set(name, generator);\n }\n }\n getShapeGenerator(name) {\n return shapeGeneratorss.get(name);\n }\n getSupportedShapeGenerators() {\n return shapeGeneratorss.keys();\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters/./dist/browser/ShapeManager.js?\n}");
26
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ ShapeManager: () => (/* binding */ ShapeManager)\n/* harmony export */ });\nconst shapeGenerators = new Map();\nclass ShapeManager {\n addShapeGenerator(name, generator) {\n if (!this.getShapeGenerator(name)) {\n shapeGenerators.set(name, generator);\n }\n }\n getShapeGenerator(name) {\n return shapeGenerators.get(name);\n }\n getSupportedShapeGenerators() {\n return shapeGenerators.keys();\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters/./dist/browser/ShapeManager.js?\n}");
27
27
 
28
28
  /***/ }
29
29
 
@@ -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;
@@ -262,24 +262,19 @@ export class EmitterInstance {
262
262
  this._emitParticles(quantity);
263
263
  }
264
264
  _emitParticles(quantity) {
265
- const singleParticlesOptions = itemFromSingleOrMultiple(this._particlesOptions), reduceFactor = this.container.retina.reduceFactor;
265
+ const singleParticlesOptions = itemFromSingleOrMultiple(this._particlesOptions), 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
266
  for (let i = 0; i < quantity * reduceFactor; i++) {
267
- const particlesOptions = deepExtend({}, singleParticlesOptions);
267
+ const particlesOptions = needsCopy
268
+ ? deepExtend({}, singleParticlesOptions)
269
+ : singleParticlesOptions;
268
270
  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;
271
+ if (hslAnimation && maxValues) {
276
272
  this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h, colorFactor);
277
273
  this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, maxValues.s);
278
274
  this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, maxValues.l);
279
275
  }
280
276
  setParticlesOptionsColor(particlesOptions, this.spawnColor);
281
277
  }
282
- const shapeOptions = this.options.shape;
283
278
  let position = this.position;
284
279
  if (this._shape) {
285
280
  const shapePosData = this._shape.randomPosition();
package/esm/Emitters.js CHANGED
@@ -54,17 +54,17 @@ export class Emitters {
54
54
  }
55
55
  let emittersModeOptions;
56
56
  if (isArray(modeEmitters.value)) {
57
- const minLength = 0;
58
- if (modeEmitters.value.length > minLength && modeEmitters.random.enable) {
57
+ const minLength = 0, modeEmittersCount = modeEmitters.value.length;
58
+ if (modeEmittersCount > minLength && modeEmitters.random.enable) {
59
59
  emittersModeOptions = [];
60
- const usedIndexes = [];
60
+ const usedIndexes = new Set();
61
61
  for (let i = 0; i < modeEmitters.random.count; i++) {
62
62
  const idx = arrayRandomIndex(modeEmitters.value);
63
- if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
63
+ if (usedIndexes.has(idx) && usedIndexes.size < modeEmittersCount) {
64
64
  i--;
65
65
  continue;
66
66
  }
67
- usedIndexes.push(idx);
67
+ usedIndexes.add(idx);
68
68
  const selectedOptions = itemFromArray(modeEmitters.value, idx);
69
69
  if (!selectedOptions) {
70
70
  continue;
@@ -121,8 +121,14 @@ export class Emitters {
121
121
  this.array = [];
122
122
  }
123
123
  update(delta) {
124
+ const updates = [];
124
125
  for (const emitter of this.array) {
125
- emitter.update(delta);
126
+ updates.push(() => {
127
+ emitter.update(delta);
128
+ });
126
129
  }
130
+ updates.forEach(update => {
131
+ update();
132
+ });
127
133
  }
128
134
  }
@@ -22,29 +22,34 @@ export class EmittersPlugin {
22
22
  });
23
23
  }
24
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)) {
25
+ if (!interactivityEmitters) {
26
+ return;
27
+ }
28
+ const defaultRandomOptions = {
29
+ count: 1,
30
+ enable: true,
31
+ };
32
+ if (isArray(interactivityEmitters)) {
33
+ options.interactivity.modes.emitters = {
34
+ random: defaultRandomOptions,
35
+ value: interactivityEmitters.map(s => {
36
+ const tmp = new Emitter();
37
+ tmp.load(s);
38
+ return tmp;
39
+ }),
40
+ };
41
+ }
42
+ else {
43
+ const emitterMode = interactivityEmitters;
44
+ if (Object.hasOwn(emitterMode, "value")) {
45
+ const emitterModeOptions = emitterMode;
46
+ if (isArray(emitterModeOptions.value)) {
42
47
  options.interactivity.modes.emitters = {
43
48
  random: {
44
- count: emitterMode.random.count,
45
- enable: emitterMode.random.enable,
49
+ count: emitterModeOptions.random?.count ?? defaultRandomOptions.count,
50
+ enable: emitterModeOptions.random?.enable ?? defaultRandomOptions.enable,
46
51
  },
47
- value: emitterMode.value.map(s => {
52
+ value: emitterModeOptions.value.map(s => {
48
53
  const tmp = new Emitter();
49
54
  tmp.load(s);
50
55
  return tmp;
@@ -53,16 +58,24 @@ export class EmittersPlugin {
53
58
  }
54
59
  else {
55
60
  const tmp = new Emitter();
56
- tmp.load(emitterMode.value);
61
+ tmp.load(emitterModeOptions.value);
57
62
  options.interactivity.modes.emitters = {
58
63
  random: {
59
- count: emitterMode.random.count,
60
- enable: emitterMode.random.enable,
64
+ count: emitterModeOptions.random?.count ?? defaultRandomOptions.count,
65
+ enable: emitterModeOptions.random?.enable ?? defaultRandomOptions.enable,
61
66
  },
62
67
  value: tmp,
63
68
  };
64
69
  }
65
70
  }
71
+ else {
72
+ const tmp = new Emitter();
73
+ tmp.load(emitterMode);
74
+ options.interactivity.modes.emitters = {
75
+ random: defaultRandomOptions,
76
+ value: tmp,
77
+ };
78
+ }
66
79
  }
67
80
  }
68
81
  needsPlugin(options) {
@@ -1,14 +1,14 @@
1
- const shapeGeneratorss = new Map();
1
+ const shapeGenerators = new Map();
2
2
  export class ShapeManager {
3
3
  addShapeGenerator(name, generator) {
4
4
  if (!this.getShapeGenerator(name)) {
5
- shapeGeneratorss.set(name, generator);
5
+ shapeGenerators.set(name, generator);
6
6
  }
7
7
  }
8
8
  getShapeGenerator(name) {
9
- return shapeGeneratorss.get(name);
9
+ return shapeGenerators.get(name);
10
10
  }
11
11
  getSupportedShapeGenerators() {
12
- return shapeGeneratorss.keys();
12
+ return shapeGenerators.keys();
13
13
  }
14
14
  }
package/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export function loadEmittersPlugin(engine) {
2
- engine.checkVersion("4.0.0-alpha.2");
2
+ engine.checkVersion("4.0.0-alpha.3");
3
3
  engine.register(async (e) => {
4
4
  const { ShapeManager } = await import("./ShapeManager.js"), { EmittersPlugin } = await import("./EmittersPlugin.js");
5
5
  e.emitterShapeManager ??= new ShapeManager();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/plugin-emitters",
3
- "version": "4.0.0-alpha.2",
3
+ "version": "4.0.0-alpha.3",
4
4
  "description": "tsParticles emitters plugin",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -86,7 +86,7 @@
86
86
  "./package.json": "./package.json"
87
87
  },
88
88
  "dependencies": {
89
- "@tsparticles/engine": "4.0.0-alpha.2"
89
+ "@tsparticles/engine": "4.0.0-alpha.3"
90
90
  },
91
91
  "publishConfig": {
92
92
  "access": "public"
package/report.html CHANGED
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <meta charset="UTF-8"/>
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
6
- <title>@tsparticles/plugin-emitters [8 Jan 2026 at 10:13]</title>
6
+ <title>@tsparticles/plugin-emitters [10 Jan 2026 at 19:20]</title>
7
7
  <link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAABrVBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+O1foceMD///+J0/qK1Pr7/v8Xdr/9///W8P4UdL7L7P0Scr2r4Pyj3vwad8D5/f/2/f+55f3E6f34+/2H0/ojfMKpzOd0rNgQcb3F3O/j9f7c8v6g3Pz0/P/w+v/q+P7n9v6T1/uQ1vuE0vqLut/y+v+Z2fvt+f+15Pzv9fuc2/vR7v2V2Pvd6/bg9P7I6/285/2y4/yp3/zp8vk8i8kqgMT7/P31+fyv4vxGkcz6/P6/6P3j7vfS5PNnpNUxhcbO7f7F6v3O4vHK3/DA2u631Ouy0eqXweKJud5wqthfoNMMbLvY8f73+v2dxeR8sNtTmdDx9/zX6PSjyeaCtd1YnNGX2PuQveCGt95Nls42h8dLlM3F4vBtAAAAM3RSTlMAAyOx0/sKBvik8opWGBMOAe3l1snDm2E9LSb06eHcu5JpHbarfHZCN9CBb08zzkdNS0kYaptYAAAFV0lEQVRYw92X51/aYBDHHS2O2qqttVbrqNq9m+TJIAYIShBkWwqIiCgoWvfeq7Z2/s29hyQNyUcR7LveGwVyXy6XH8/9rqxglLfUPLxVduUor3h0rfp2TYvpivk37929TkG037hffoX0+peVtZQc1589rigVUdXS/ABSAyEmGIO/1XfvldSK8vs3OqB6u3m0nxmIrvgB0dj7rr7Y9IbuF68hnfFaiHA/sxqm0wciIG43P60qKv9WXWc1RXGh/mFESFABTSBi0sNAKzqet17eCtOb3kZIDwxEEU0oAIJGYxNBDhBND29e0rtXXbcpuPmED9IhEAAQ/AXEaF8EPmnrrKsv0LvWR3fg5sWDNAFZOgAgaKvZDogHNU9MFwnnYROkc56RD5CjAbQX9Ow4g7upCsvYu55aSI/Nj0H1akgKQEUM94dwK65hYRmFU9MIcH/fqJYOZYcnuJSU/waKDgTOEVaVKhwrTRP5XzgSpAITYzom7UvkhFX5VutmxeNnWDjjswTKTyfgluNDGbUpWissXhF3s7mlSml+czWkg3D0l1nNjGNjz3myOQOa1KM/jOS6ebdbAVTCi4gljHSFrviza7tOgRWcS0MOUX9zdNgag5w7rRqA44Lzw0hr1WqES36dFliSJFlh2rXIae3FFcDDgKdxrUIDePr8jGcSClV1u7A9xeN0ModY/pHMxmR1EzRh8TJiwqsHmKW0l4FCEZI+jHio+JdPPE9qwQtTRxku2D8sIeRL2LnxWSllANCQGOIiqVHAz2ye2JR0DcH+HoxDkaADLjgxjKQ+AwCX/g0+DNgdG0ukYCONAe+dbc2IAc6fwt1ARoDSezNHxV2Cmzwv3O6lDMV55edBGwGK9n1+x2F8EDfAGCxug8MhpsMEcTEAWf3rx2vZhe/LAmtIn/6apE6PN0ULKgywD9mmdxbmFl3OvD5AS5fW5zLbv/YHmcsBTjf/afDz3MaZTVCfAP9z6/Bw6ycv8EUBWJIn9zYcoAWWlW9+OzO3vkTy8H+RANLmdrpOuYWdZYEXpo+TlCJrW5EARb7fF+bWdqf3hhyZI1nWJQHgznErZhbjoEsWqi8dQNoE294aldzFurwSABL2XXMf9+H1VQGke9exw5P/AnA5Pv5ngMul7LOvO922iwACu8WkCwLCafvM4CeWPxfA8lNHcWZSoi8EwMAIciKX2Z4SWCMAa3snCZ/G4EA8D6CMLNFsGQhkkz/gQNEBbPCbWsxGUpYVu3z8IyNAknwJkfPMEhLyrdi5RTyUVACkw4GSFRNWJNEW+fgPGwHD8/JxnRuLabN4CGNRkAE23na2+VmEAUmrYymSGjMAYqH84YUIyzgzs3XC7gNgH36Vcc4zKY9o9fgPBXUAiHHwVboBHGLiX6Zcjp1f2wu4tvzZKo0ecPnDtQYDQvJXaBeNzce45Fp28ZQLrEZVuFqgBwOalArKXnW1UzlnSusQKJqKYNuz4tOnI6sZG4zanpemv+7ySU2jbA9h6uhcgpfy6G2PahirDZ6zvq6zDduMVFTKvzw8wgyEdelwY9in3XkEPs3osJuwRQ4qTkfzifndg9Gfc4pdsu82+tTnHZTBa2EAMrqr2t43pguc8tNm7JQVQ2S0ukj2d22dhXYP0/veWtwKrCkNoNimAN5+Xr/oLrxswKbVJjteWrX7eR63o4j9q0GxnaBdWgGA5VStpanIjQmEhV0/nVt5VOFUvix6awJhPcAaTEShgrG+iGyvb5a0Ndb1YGHFPEwoqAinoaykaID1o1pdPNu7XsnCKQ3R+hwWIIhGvORcJUBYXe3Xa3vq/mF/N9V13ugufMkfXn+KHsRD0B8AAAAASUVORK5CYII=" type="image/x-icon" />
8
8
 
9
9
  <script>
@@ -4,7 +4,7 @@
4
4
  * Demo / Generator : https://particles.js.org/
5
5
  * GitHub : https://www.github.com/matteobruni/tsparticles
6
6
  * How to use? : Check the GitHub README
7
- * v4.0.0-alpha.2
7
+ * v4.0.0-alpha.3
8
8
  */
9
9
  /*
10
10
  * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
@@ -54,7 +54,7 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
54
54
  \*******************************/
55
55
  (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
56
56
 
57
- eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ EmitterClickMode: () => (/* reexport safe */ _Enums_EmitterClickMode_js__WEBPACK_IMPORTED_MODULE_1__.EmitterClickMode),\n/* harmony export */ EmitterShapeBase: () => (/* reexport safe */ _EmitterShapeBase_js__WEBPACK_IMPORTED_MODULE_0__.EmitterShapeBase),\n/* harmony export */ loadEmittersPlugin: () => (/* binding */ loadEmittersPlugin)\n/* harmony export */ });\n/* harmony import */ var _EmitterShapeBase_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./EmitterShapeBase.js */ \"./dist/browser/EmitterShapeBase.js\");\n/* harmony import */ var _Enums_EmitterClickMode_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Enums/EmitterClickMode.js */ \"./dist/browser/Enums/EmitterClickMode.js\");\nfunction loadEmittersPlugin(engine) {\n engine.checkVersion(\"4.0.0-alpha.2\");\n engine.register(async e => {\n const {\n ShapeManager\n } = await __webpack_require__.e(/*! import() */ \"dist_browser_ShapeManager_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./ShapeManager.js */ \"./dist/browser/ShapeManager.js\")),\n {\n EmittersPlugin\n } = await __webpack_require__.e(/*! import() */ \"dist_browser_EmittersPlugin_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./EmittersPlugin.js */ \"./dist/browser/EmittersPlugin.js\"));\n e.emitterShapeManager ??= new ShapeManager();\n e.addEmitterShapeGenerator ??= (name, generator) => {\n e.emitterShapeManager?.addShapeGenerator(name, generator);\n };\n const plugin = new EmittersPlugin(e);\n e.addPlugin(plugin);\n });\n}\n\n\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters/./dist/browser/index.js?\n}");
57
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ EmitterClickMode: () => (/* reexport safe */ _Enums_EmitterClickMode_js__WEBPACK_IMPORTED_MODULE_1__.EmitterClickMode),\n/* harmony export */ EmitterShapeBase: () => (/* reexport safe */ _EmitterShapeBase_js__WEBPACK_IMPORTED_MODULE_0__.EmitterShapeBase),\n/* harmony export */ loadEmittersPlugin: () => (/* binding */ loadEmittersPlugin)\n/* harmony export */ });\n/* harmony import */ var _EmitterShapeBase_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./EmitterShapeBase.js */ \"./dist/browser/EmitterShapeBase.js\");\n/* harmony import */ var _Enums_EmitterClickMode_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Enums/EmitterClickMode.js */ \"./dist/browser/Enums/EmitterClickMode.js\");\nfunction loadEmittersPlugin(engine) {\n engine.checkVersion(\"4.0.0-alpha.3\");\n engine.register(async e => {\n const {\n ShapeManager\n } = await __webpack_require__.e(/*! import() */ \"dist_browser_ShapeManager_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./ShapeManager.js */ \"./dist/browser/ShapeManager.js\")),\n {\n EmittersPlugin\n } = await __webpack_require__.e(/*! import() */ \"dist_browser_EmittersPlugin_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./EmittersPlugin.js */ \"./dist/browser/EmittersPlugin.js\"));\n e.emitterShapeManager ??= new ShapeManager();\n e.addEmitterShapeGenerator ??= (name, generator) => {\n e.emitterShapeManager?.addShapeGenerator(name, generator);\n };\n const plugin = new EmittersPlugin(e);\n e.addPlugin(plugin);\n });\n}\n\n\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters/./dist/browser/index.js?\n}");
58
58
 
59
59
  /***/ },
60
60
 
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see tsparticles.plugin.emitters.min.js.LICENSE.txt */
2
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],t);else{var r="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var i in r)("object"==typeof exports?exports:e)[i]=r[i]}}(this,(e=>(()=>{var t,r,i={271(e,t,r){var i;r.d(t,{c:()=>i}),function(e){e.emitter="emitter"}(i||(i={}))},303(t){t.exports=e}},o={};function n(e){var t=o[e];if(void 0!==t)return t.exports;var r=o[e]={exports:{}};return i[e](r,r.exports,n),r.exports}n.m=i,n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.f={},n.e=e=>Promise.all(Object.keys(n.f).reduce(((t,r)=>(n.f[r](e,t),t)),[])),n.u=e=>e+".min.js",n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),t={},r="@tsparticles/plugin-emitters:",n.l=(e,i,o,a)=>{if(t[e])t[e].push(i);else{var s,p;if(void 0!==o)for(var c=document.getElementsByTagName("script"),l=0;l<c.length;l++){var u=c[l];if(u.getAttribute("src")==e||u.getAttribute("data-webpack")==r+o){s=u;break}}s||(p=!0,(s=document.createElement("script")).charset="utf-8",n.nc&&s.setAttribute("nonce",n.nc),s.setAttribute("data-webpack",r+o),s.src=e),t[e]=[i];var d=(r,i)=>{s.onerror=s.onload=null,clearTimeout(f);var o=t[e];if(delete t[e],s.parentNode&&s.parentNode.removeChild(s),o&&o.forEach((e=>e(i))),r)return r(i)},f=setTimeout(d.bind(null,void 0,{type:"timeout",target:s}),12e4);s.onerror=d.bind(null,s.onerror),s.onload=d.bind(null,s.onload),p&&document.head.appendChild(s)}},n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;n.g.importScripts&&(e=n.g.location+"");var t=n.g.document;if(!e&&t&&(t.currentScript&&"SCRIPT"===t.currentScript.tagName.toUpperCase()&&(e=t.currentScript.src),!e)){var r=t.getElementsByTagName("script");if(r.length)for(var i=r.length-1;i>-1&&(!e||!/^http(s?):/.test(e));)e=r[i--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),n.p=e})(),(()=>{var e={833:0};n.f.j=(t,r)=>{var i=n.o(e,t)?e[t]:void 0;if(0!==i)if(i)r.push(i[2]);else{var o=new Promise(((r,o)=>i=e[t]=[r,o]));r.push(i[2]=o);var a=n.p+n.u(t),s=new Error;n.l(a,(r=>{if(n.o(e,t)&&(0!==(i=e[t])&&(e[t]=void 0),i)){var o=r&&("load"===r.type?"missing":r.type),a=r&&r.target&&r.target.src;s.message="Loading chunk "+t+" failed.\n("+o+": "+a+")",s.name="ChunkLoadError",s.type=o,s.request=a,i[1](s)}}),"chunk-"+t,t)}};var t=(t,r)=>{var i,o,[a,s,p]=r,c=0;if(a.some((t=>0!==e[t]))){for(i in s)n.o(s,i)&&(n.m[i]=s[i]);if(p)p(n)}for(t&&t(r);c<a.length;c++)o=a[c],n.o(e,o)&&e[o]&&e[o][0](),e[o]=0},r=this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();var a={};n.r(a),n.d(a,{EmitterClickMode:()=>p.c,EmitterShapeBase:()=>s,loadEmittersPlugin:()=>c});class s{constructor(e,t,r,i){this.position=e,this.size=t,this.fill=r,this.options=i}resize(e,t){this.position=e,this.size=t}}var p=n(271);function c(e){e.checkVersion("4.0.0-alpha.2"),e.register((async e=>{const{ShapeManager:t}=await n.e(921).then(n.bind(n,921)),{EmittersPlugin:r}=await n.e(214).then(n.bind(n,214));e.emitterShapeManager??=new t,e.addEmitterShapeGenerator??=(t,r)=>{e.emitterShapeManager?.addShapeGenerator(t,r)};const i=new r(e);e.addPlugin(i)}))}return a})()));
2
+ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],t);else{var r="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var i in r)("object"==typeof exports?exports:e)[i]=r[i]}}(this,(e=>(()=>{var t,r,i={271(e,t,r){var i;r.d(t,{c:()=>i}),function(e){e.emitter="emitter"}(i||(i={}))},303(t){t.exports=e}},o={};function n(e){var t=o[e];if(void 0!==t)return t.exports;var r=o[e]={exports:{}};return i[e](r,r.exports,n),r.exports}n.m=i,n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.f={},n.e=e=>Promise.all(Object.keys(n.f).reduce(((t,r)=>(n.f[r](e,t),t)),[])),n.u=e=>e+".min.js",n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),t={},r="@tsparticles/plugin-emitters:",n.l=(e,i,o,a)=>{if(t[e])t[e].push(i);else{var s,p;if(void 0!==o)for(var c=document.getElementsByTagName("script"),l=0;l<c.length;l++){var u=c[l];if(u.getAttribute("src")==e||u.getAttribute("data-webpack")==r+o){s=u;break}}s||(p=!0,(s=document.createElement("script")).charset="utf-8",n.nc&&s.setAttribute("nonce",n.nc),s.setAttribute("data-webpack",r+o),s.src=e),t[e]=[i];var d=(r,i)=>{s.onerror=s.onload=null,clearTimeout(f);var o=t[e];if(delete t[e],s.parentNode&&s.parentNode.removeChild(s),o&&o.forEach((e=>e(i))),r)return r(i)},f=setTimeout(d.bind(null,void 0,{type:"timeout",target:s}),12e4);s.onerror=d.bind(null,s.onerror),s.onload=d.bind(null,s.onload),p&&document.head.appendChild(s)}},n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;n.g.importScripts&&(e=n.g.location+"");var t=n.g.document;if(!e&&t&&(t.currentScript&&"SCRIPT"===t.currentScript.tagName.toUpperCase()&&(e=t.currentScript.src),!e)){var r=t.getElementsByTagName("script");if(r.length)for(var i=r.length-1;i>-1&&(!e||!/^http(s?):/.test(e));)e=r[i--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),n.p=e})(),(()=>{var e={833:0};n.f.j=(t,r)=>{var i=n.o(e,t)?e[t]:void 0;if(0!==i)if(i)r.push(i[2]);else{var o=new Promise(((r,o)=>i=e[t]=[r,o]));r.push(i[2]=o);var a=n.p+n.u(t),s=new Error;n.l(a,(r=>{if(n.o(e,t)&&(0!==(i=e[t])&&(e[t]=void 0),i)){var o=r&&("load"===r.type?"missing":r.type),a=r&&r.target&&r.target.src;s.message="Loading chunk "+t+" failed.\n("+o+": "+a+")",s.name="ChunkLoadError",s.type=o,s.request=a,i[1](s)}}),"chunk-"+t,t)}};var t=(t,r)=>{var i,o,[a,s,p]=r,c=0;if(a.some((t=>0!==e[t]))){for(i in s)n.o(s,i)&&(n.m[i]=s[i]);if(p)p(n)}for(t&&t(r);c<a.length;c++)o=a[c],n.o(e,o)&&e[o]&&e[o][0](),e[o]=0},r=this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();var a={};n.r(a),n.d(a,{EmitterClickMode:()=>p.c,EmitterShapeBase:()=>s,loadEmittersPlugin:()=>c});class s{constructor(e,t,r,i){this.position=e,this.size=t,this.fill=r,this.options=i}resize(e,t){this.position=e,this.size=t}}var p=n(271);function c(e){e.checkVersion("4.0.0-alpha.3"),e.register((async e=>{const{ShapeManager:t}=await n.e(921).then(n.bind(n,921)),{EmittersPlugin:r}=await n.e(214).then(n.bind(n,214));e.emitterShapeManager??=new t,e.addEmitterShapeGenerator??=(t,r)=>{e.emitterShapeManager?.addShapeGenerator(t,r)};const i=new r(e);e.addPlugin(i)}))}return a})()));
@@ -1 +1 @@
1
- /*! tsParticles Emitters Plugin v4.0.0-alpha.2 by Matteo Bruni */
1
+ /*! tsParticles Emitters Plugin v4.0.0-alpha.3 by Matteo Bruni */
package/types/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { Engine } from "@tsparticles/engine";
2
- export declare function loadEmittersPlugin(engine: Engine): void;
1
+ import type { EmittersEngine } from "./EmittersEngine.js";
2
+ export declare function loadEmittersPlugin(engine: EmittersEngine): void;
3
3
  export type * from "./EmitterContainer.js";
4
4
  export * from "./EmitterShapeBase.js";
5
5
  export type * from "./EmittersEngine.js";
@@ -13,7 +13,7 @@
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
- const defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1, defaultColorAnimationFactor = 1;
16
+ const defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1, defaultColorAnimationFactor = 1, colorFactor = 3.6;
17
17
  function setParticlesOptionsColor(particlesOptions, color) {
18
18
  if (particlesOptions.color) {
19
19
  particlesOptions.color.value = color;
@@ -274,24 +274,19 @@
274
274
  this._emitParticles(quantity);
275
275
  }
276
276
  _emitParticles(quantity) {
277
- const singleParticlesOptions = (0, engine_1.itemFromSingleOrMultiple)(this._particlesOptions), reduceFactor = this.container.retina.reduceFactor;
277
+ const singleParticlesOptions = (0, engine_1.itemFromSingleOrMultiple)(this._particlesOptions), hslAnimation = this.options.spawnColor?.animation, reduceFactor = this.container.retina.reduceFactor, needsColorAnimation = !!hslAnimation, needsShapeData = !!this._shape, needsCopy = needsColorAnimation || needsShapeData, maxValues = needsColorAnimation ? { h: engine_1.hMax, s: engine_1.sMax, l: engine_1.lMax } : null, shapeOptions = this.options.shape;
278
278
  for (let i = 0; i < quantity * reduceFactor; i++) {
279
- const particlesOptions = (0, engine_1.deepExtend)({}, singleParticlesOptions);
279
+ const particlesOptions = needsCopy
280
+ ? (0, engine_1.deepExtend)({}, singleParticlesOptions)
281
+ : singleParticlesOptions;
280
282
  if (this.spawnColor) {
281
- const hslAnimation = this.options.spawnColor?.animation;
282
- if (hslAnimation) {
283
- const maxValues = {
284
- h: engine_1.hMax,
285
- s: engine_1.sMax,
286
- l: engine_1.lMax,
287
- }, colorFactor = 3.6;
283
+ if (hslAnimation && maxValues) {
288
284
  this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h, colorFactor);
289
285
  this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, maxValues.s);
290
286
  this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, maxValues.l);
291
287
  }
292
288
  setParticlesOptionsColor(particlesOptions, this.spawnColor);
293
289
  }
294
- const shapeOptions = this.options.shape;
295
290
  let position = this.position;
296
291
  if (this._shape) {
297
292
  const shapePosData = this._shape.randomPosition();
package/umd/Emitters.js CHANGED
@@ -66,17 +66,17 @@
66
66
  }
67
67
  let emittersModeOptions;
68
68
  if ((0, engine_1.isArray)(modeEmitters.value)) {
69
- const minLength = 0;
70
- if (modeEmitters.value.length > minLength && modeEmitters.random.enable) {
69
+ const minLength = 0, modeEmittersCount = modeEmitters.value.length;
70
+ if (modeEmittersCount > minLength && modeEmitters.random.enable) {
71
71
  emittersModeOptions = [];
72
- const usedIndexes = [];
72
+ const usedIndexes = new Set();
73
73
  for (let i = 0; i < modeEmitters.random.count; i++) {
74
74
  const idx = (0, engine_1.arrayRandomIndex)(modeEmitters.value);
75
- if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) {
75
+ if (usedIndexes.has(idx) && usedIndexes.size < modeEmittersCount) {
76
76
  i--;
77
77
  continue;
78
78
  }
79
- usedIndexes.push(idx);
79
+ usedIndexes.add(idx);
80
80
  const selectedOptions = (0, engine_1.itemFromArray)(modeEmitters.value, idx);
81
81
  if (!selectedOptions) {
82
82
  continue;
@@ -133,9 +133,15 @@
133
133
  this.array = [];
134
134
  }
135
135
  update(delta) {
136
+ const updates = [];
136
137
  for (const emitter of this.array) {
137
- emitter.update(delta);
138
+ updates.push(() => {
139
+ emitter.update(delta);
140
+ });
138
141
  }
142
+ updates.forEach(update => {
143
+ update();
144
+ });
139
145
  }
140
146
  }
141
147
  exports.Emitters = Emitters;
@@ -34,29 +34,34 @@
34
34
  });
35
35
  }
36
36
  const interactivityEmitters = source?.interactivity?.modes?.emitters;
37
- if (interactivityEmitters) {
38
- if ((0, engine_1.isArray)(interactivityEmitters)) {
39
- options.interactivity.modes.emitters = {
40
- random: {
41
- count: 1,
42
- enable: true,
43
- },
44
- value: interactivityEmitters.map(s => {
45
- const tmp = new Emitter_js_1.Emitter();
46
- tmp.load(s);
47
- return tmp;
48
- }),
49
- };
50
- }
51
- else {
52
- const emitterMode = interactivityEmitters;
53
- if ((0, engine_1.isArray)(emitterMode.value)) {
37
+ if (!interactivityEmitters) {
38
+ return;
39
+ }
40
+ const defaultRandomOptions = {
41
+ count: 1,
42
+ enable: true,
43
+ };
44
+ if ((0, engine_1.isArray)(interactivityEmitters)) {
45
+ options.interactivity.modes.emitters = {
46
+ random: defaultRandomOptions,
47
+ value: interactivityEmitters.map(s => {
48
+ const tmp = new Emitter_js_1.Emitter();
49
+ tmp.load(s);
50
+ return tmp;
51
+ }),
52
+ };
53
+ }
54
+ else {
55
+ const emitterMode = interactivityEmitters;
56
+ if (Object.hasOwn(emitterMode, "value")) {
57
+ const emitterModeOptions = emitterMode;
58
+ if ((0, engine_1.isArray)(emitterModeOptions.value)) {
54
59
  options.interactivity.modes.emitters = {
55
60
  random: {
56
- count: emitterMode.random.count,
57
- enable: emitterMode.random.enable,
61
+ count: emitterModeOptions.random?.count ?? defaultRandomOptions.count,
62
+ enable: emitterModeOptions.random?.enable ?? defaultRandomOptions.enable,
58
63
  },
59
- value: emitterMode.value.map(s => {
64
+ value: emitterModeOptions.value.map(s => {
60
65
  const tmp = new Emitter_js_1.Emitter();
61
66
  tmp.load(s);
62
67
  return tmp;
@@ -65,16 +70,24 @@
65
70
  }
66
71
  else {
67
72
  const tmp = new Emitter_js_1.Emitter();
68
- tmp.load(emitterMode.value);
73
+ tmp.load(emitterModeOptions.value);
69
74
  options.interactivity.modes.emitters = {
70
75
  random: {
71
- count: emitterMode.random.count,
72
- enable: emitterMode.random.enable,
76
+ count: emitterModeOptions.random?.count ?? defaultRandomOptions.count,
77
+ enable: emitterModeOptions.random?.enable ?? defaultRandomOptions.enable,
73
78
  },
74
79
  value: tmp,
75
80
  };
76
81
  }
77
82
  }
83
+ else {
84
+ const tmp = new Emitter_js_1.Emitter();
85
+ tmp.load(emitterMode);
86
+ options.interactivity.modes.emitters = {
87
+ random: defaultRandomOptions,
88
+ value: tmp,
89
+ };
90
+ }
78
91
  }
79
92
  }
80
93
  needsPlugin(options) {
@@ -10,18 +10,18 @@
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ShapeManager = void 0;
13
- const shapeGeneratorss = new Map();
13
+ const shapeGenerators = new Map();
14
14
  class ShapeManager {
15
15
  addShapeGenerator(name, generator) {
16
16
  if (!this.getShapeGenerator(name)) {
17
- shapeGeneratorss.set(name, generator);
17
+ shapeGenerators.set(name, generator);
18
18
  }
19
19
  }
20
20
  getShapeGenerator(name) {
21
- return shapeGeneratorss.get(name);
21
+ return shapeGenerators.get(name);
22
22
  }
23
23
  getSupportedShapeGenerators() {
24
- return shapeGeneratorss.keys();
24
+ return shapeGenerators.keys();
25
25
  }
26
26
  }
27
27
  exports.ShapeManager = ShapeManager;
package/umd/index.js CHANGED
@@ -48,7 +48,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
48
48
  Object.defineProperty(exports, "__esModule", { value: true });
49
49
  exports.loadEmittersPlugin = loadEmittersPlugin;
50
50
  function loadEmittersPlugin(engine) {
51
- engine.checkVersion("4.0.0-alpha.2");
51
+ engine.checkVersion("4.0.0-alpha.3");
52
52
  engine.register(async (e) => {
53
53
  const { ShapeManager } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./ShapeManager.js"))) : new Promise((resolve_1, reject_1) => { require(["./ShapeManager.js"], resolve_1, reject_1); }).then(__importStar)), { EmittersPlugin } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./EmittersPlugin.js"))) : new Promise((resolve_2, reject_2) => { require(["./EmittersPlugin.js"], resolve_2, reject_2); }).then(__importStar));
54
54
  e.emitterShapeManager ??= new ShapeManager();