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

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.
@@ -1 +1 @@
1
- "use strict";(this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[588],{588(t,i,s){s.r(i),s.d(i,{EmittersPlugin:()=>l});var o=s(303),e=s(982);class l{id="emitters";_instancesManager;constructor(t){this._instancesManager=t}async getPlugin(t){let{EmittersPluginInstance:i}=await s.e(803).then(s.bind(s,803));return new i(this._instancesManager,t)}loadOptions(t,i,s){(this.needsPlugin(i)||this.needsPlugin(s))&&s?.emitters&&(i.emitters=(0,o.executeOnSingleOrMultiple)(s.emitters,t=>{let i=new e.v;return i.load(t),i}))}needsPlugin(t){if(!t)return!1;let i=t.emitters;return(0,o.isArray)(i)&&!!i.length||void 0!==i}}},982(t,i,s){s.d(i,{v:()=>h});var o=s(303);class e{count;delay;duration;wait;constructor(){this.wait=!1}load(t){(0,o.isNull)(t)||(void 0!==t.count&&(this.count=t.count),void 0!==t.delay&&(this.delay=(0,o.setRangeValue)(t.delay)),void 0!==t.duration&&(this.duration=(0,o.setRangeValue)(t.duration)),void 0!==t.wait&&(this.wait=t.wait))}}class l{delay;quantity;constructor(){this.quantity=1,this.delay=.1}load(t){(0,o.isNull)(t)||(void 0!==t.quantity&&(this.quantity=(0,o.setRangeValue)(t.quantity)),void 0!==t.delay&&(this.delay=(0,o.setRangeValue)(t.delay)))}}class a{color;opacity;constructor(){this.color=!1,this.opacity=!1}load(t){(0,o.isNull)(t)||(void 0!==t.color&&(this.color=t.color),void 0!==t.opacity&&(this.opacity=t.opacity))}}class n{options;replace;type;constructor(){this.options={},this.replace=new a,this.type="square"}load(t){(0,o.isNull)(t)||(void 0!==t.options&&(this.options=(0,o.deepExtend)({},t.options??{})),this.replace.load(t.replace),void 0!==t.type&&(this.type=t.type))}}var r=s(747);class d{fill;stroke;load(t){!(0,o.isNull)(t)&&(t.fill&&(this.fill??=new o.Fill,this.fill.load(t.fill)),t.stroke&&(this.stroke??=new o.Stroke,this.stroke.load(t.stroke)))}}class h{autoPlay;direction;domId;fill;life;name;particles;position;rate;shape;size;spawn;spawnFillColor;spawnStrokeColor;startCount;constructor(){this.autoPlay=!0,this.fill=!0,this.life=new e,this.rate=new l,this.shape=new n,this.spawn=new d,this.startCount=0}load(t){(0,o.isNull)(t)||(void 0!==t.autoPlay&&(this.autoPlay=t.autoPlay),void 0!==t.size&&(this.size??=new r.G,this.size.load(t.size)),void 0!==t.direction&&(this.direction=t.direction),this.domId=t.domId,void 0!==t.fill&&(this.fill=t.fill),this.life.load(t.life),this.name=t.name,this.particles=(0,o.executeOnSingleOrMultiple)(t.particles,t=>(0,o.deepExtend)({},t)),this.rate.load(t.rate),this.shape.load(t.shape),this.spawn.load(t.spawn),void 0!==t.position&&(this.position={},void 0!==t.position.x&&(this.position.x=(0,o.setRangeValue)(t.position.x)),void 0!==t.position.y&&(this.position.y=(0,o.setRangeValue)(t.position.y))),void 0!==t.spawnFillColor&&(this.spawnFillColor??=new o.AnimatableColor,this.spawnFillColor.load(t.spawnFillColor)),void 0!==t.spawnStrokeColor&&(this.spawnStrokeColor??=new o.AnimatableColor,this.spawnStrokeColor.load(t.spawnStrokeColor)),void 0!==t.startCount&&(this.startCount=t.startCount))}}},747(t,i,s){s.d(i,{G:()=>e});var o=s(303);class e{height;mode;width;constructor(){this.mode=o.PixelMode.percent,this.height=0,this.width=0}load(t){(0,o.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))}}}}]);
1
+ "use strict";(this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[392],{392(t,i,s){s.r(i),s.d(i,{EmittersPlugin:()=>l});var o=s(303),e=s(565);class l{id="emitters";_instancesManager;constructor(t){this._instancesManager=t}async getPlugin(t){let{EmittersPluginInstance:i}=await s.e(815).then(s.bind(s,815));return new i(this._instancesManager,t)}loadOptions(t,i,s){(this.needsPlugin(i)||this.needsPlugin(s))&&s?.emitters&&(i.emitters=(0,o.executeOnSingleOrMultiple)(s.emitters,t=>{let i=new e.v;return i.load(t),i}))}needsPlugin(t){if(!t)return!1;let i=t.emitters;return(0,o.isArray)(i)&&!!i.length||void 0!==i}}},565(t,i,s){s.d(i,{v:()=>h});var o=s(303);class e{count;delay;duration;wait;constructor(){this.wait=!1}load(t){(0,o.isNull)(t)||(void 0!==t.count&&(this.count=t.count),void 0!==t.delay&&(this.delay=(0,o.setRangeValue)(t.delay)),void 0!==t.duration&&(this.duration=(0,o.setRangeValue)(t.duration)),void 0!==t.wait&&(this.wait=t.wait))}}class l{delay;quantity;constructor(){this.quantity=1,this.delay=.1}load(t){(0,o.isNull)(t)||(void 0!==t.quantity&&(this.quantity=(0,o.setRangeValue)(t.quantity)),void 0!==t.delay&&(this.delay=(0,o.setRangeValue)(t.delay)))}}class a{color;opacity;constructor(){this.color=!1,this.opacity=!1}load(t){(0,o.isNull)(t)||(void 0!==t.color&&(this.color=t.color),void 0!==t.opacity&&(this.opacity=t.opacity))}}class n{options;replace;type;constructor(){this.options={},this.replace=new a,this.type="square"}load(t){(0,o.isNull)(t)||(void 0!==t.options&&(this.options=(0,o.deepExtend)({},t.options??{})),this.replace.load(t.replace),void 0!==t.type&&(this.type=t.type))}}var r=s(143);class d{fill;stroke;load(t){!(0,o.isNull)(t)&&(t.fill&&(this.fill??=new o.Fill,this.fill.load(t.fill)),t.stroke&&(this.stroke??=new o.Stroke,this.stroke.load(t.stroke)))}}class h{autoPlay;direction;domId;fill;life;name;particles;position;rate;shape;size;spawn;spawnFillColor;spawnStrokeColor;startCount;constructor(){this.autoPlay=!0,this.fill=!0,this.life=new e,this.rate=new l,this.shape=new n,this.spawn=new d,this.startCount=0}load(t){(0,o.isNull)(t)||(void 0!==t.autoPlay&&(this.autoPlay=t.autoPlay),void 0!==t.size&&(this.size??=new r.G,this.size.load(t.size)),void 0!==t.direction&&(this.direction=t.direction),this.domId=t.domId,void 0!==t.fill&&(this.fill=t.fill),this.life.load(t.life),this.name=t.name,this.particles=(0,o.executeOnSingleOrMultiple)(t.particles,t=>(0,o.deepExtend)({},t)),this.rate.load(t.rate),this.shape.load(t.shape),this.spawn.load(t.spawn),void 0!==t.position&&(this.position={},void 0!==t.position.x&&(this.position.x=(0,o.setRangeValue)(t.position.x)),void 0!==t.position.y&&(this.position.y=(0,o.setRangeValue)(t.position.y))),void 0!==t.spawnFillColor&&(this.spawnFillColor??=new o.AnimatableColor,this.spawnFillColor.load(t.spawnFillColor)),void 0!==t.spawnStrokeColor&&(this.spawnStrokeColor??=new o.AnimatableColor,this.spawnStrokeColor.load(t.spawnStrokeColor)),void 0!==t.startCount&&(this.startCount=t.startCount))}}},143(t,i,s){s.d(i,{G:()=>e});var o=s(303);class e{height;mode;width;constructor(){this.mode=o.PixelMode.percent,this.height=0,this.width=0}load(t){(0,o.isNull)(t)||(void 0!==t.mode&&(this.mode=t.mode),void 0!==t.height&&(this.height=t.height),void 0!==t.width&&(this.width=t.width))}}}}]);
package/399.min.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";(this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[399],{399(t,i,e){e.d(i,{EmitterInstance:()=>r});var s=e(303),o=e(565),a=e(143);let n=1;function l(t,i,e,o){t.fill=new s.Fill,t.fill.color=s.AnimatableColor.create(void 0,{value:i}),t.fill.enable=o,t.fill.opacity=e}class r{fill;name;options;position;size;spawnFillColor;spawnFillEnabled;spawnFillOpacity;spawnStrokeColor;spawnStrokeOpacity;spawnStrokeWidth;_container;_currentDuration;_currentEmitDelay;_currentSpawnDelay;_duration;_emitDelay;_firstSpawn;_immortal;_initialPosition;_lifeCount;_mutationObserver;_particlesOptions;_paused;_pluginManager;_removeCallback;_resizeObserver;_shape;_size;_spawnDelay;_startParticlesAdded;constructor(t,i,e,a,n){this._pluginManager=t,this._container=i,this._removeCallback=e,this._currentDuration=0,this._currentEmitDelay=0,this._currentSpawnDelay=0,this._initialPosition=n,a instanceof o.v?this.options=a:(this.options=new o.v,this.options.load(a)),this._spawnDelay=i.retina.reduceFactor?(0,s.getRangeValue)(this.options.life.delay??0)*s.millisecondsToSeconds/i.retina.reduceFactor:1/0,this.position=this._initialPosition??this._calcPosition(),this.name=this.options.name,this.fill=this.options.fill,this._firstSpawn=!this.options.life.wait,this._startParticlesAdded=!1;const l=(0,s.deepExtend)({},this.options.particles);if(l.move??={},l.move.direction??=this.options.direction,this.options.spawn.fill?.color&&(this.spawnFillColor=(0,s.rangeColorToHsl)(this._pluginManager,this.options.spawn.fill.color)),this.options.spawn.stroke?.color&&(this.spawnStrokeColor=(0,s.rangeColorToHsl)(this._pluginManager,this.options.spawn.stroke.color)),this._paused=!this.options.autoPlay,this._particlesOptions=l,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._pluginManager.emitterShapeManager?.getShapeGenerator(r.type);h&&(this._shape=h.generate(this._container,this.position,this.size,this.fill,r.options)),this._container.dispatchEvent("emitterCreated",{emitter:this}),this.play()}externalPause(){this._paused=!0,this.pause()}externalPlay(){this._paused=!1,this.play()}async init(){await this._shape?.init()}pause(){this._paused||delete this._emitDelay}play(){if(this._paused||!((this._lifeCount>0||this._immortal||!this.options.life.count)&&(this._firstSpawn||this._currentSpawnDelay>=(this._spawnDelay??0))))return;let t=this._container;if(void 0===this._emitDelay){let i=(0,s.getRangeValue)(this.options.rate.delay);this._emitDelay=t.retina.reduceFactor?i*s.millisecondsToSeconds/t.retina.reduceFactor:1/0}(this._lifeCount>0||this._immortal)&&this._prepareToDie()}resize(){let t=this._initialPosition,i=this._container;this.position=t&&(0,s.isPointInside)(t,i.canvas.size,s.Vector.origin)?t:this._calcPosition(),this._size=this._calcSize(),this.size=(0,s.getSize)(this._size,i.canvas.size),this._shape?.resize(this.position,this.size)}update(t){if(this._paused)return;let i=this._container;this._firstSpawn&&(this._firstSpawn=!1,this._currentSpawnDelay=this._spawnDelay??0,this._currentEmitDelay=this._emitDelay??0),this._startParticlesAdded||(this._startParticlesAdded=!0,this._emitParticles(this.options.startCount)),void 0!==this._duration&&(this._currentDuration+=t.value,this._currentDuration>=this._duration&&(this.pause(),void 0!==this._spawnDelay&&delete this._spawnDelay,!this._immortal&&this._lifeCount--,this._lifeCount>0||this._immortal?(this.position=this._calcPosition(),this._shape?.resize(this.position,this.size),this._spawnDelay=i.retina.reduceFactor?(0,s.getRangeValue)(this.options.life.delay??0)*s.millisecondsToSeconds/i.retina.reduceFactor:1/0):this._destroy(),this._currentDuration-=this._duration,delete this._duration)),void 0!==this._spawnDelay&&(this._currentSpawnDelay+=t.value,this._currentSpawnDelay>=this._spawnDelay&&(this._container.dispatchEvent("emitterPlay"),this.play(),this._currentSpawnDelay-=this._spawnDelay,delete this._spawnDelay)),void 0!==this._emitDelay&&(this._currentEmitDelay+=t.value,this._currentEmitDelay>=this._emitDelay&&(this._emit(),this._currentEmitDelay-=this._emitDelay))}_calcPosition(){let t=this._container;if(this.options.domId){let i=(0,s.safeDocument)().getElementById(this.options.domId);if(i){let e=i.getBoundingClientRect(),o=t.retina.pixelRatio;return{x:(e.x+e.width*s.half)*o,y:(e.y+e.height*s.half)*o}}}return(0,s.calcPositionOrRandomFromSizeRanged)({size:t.canvas.size,position:this.options.position})}_calcSize(){let t,i=this._container;if(this.options.domId){let t=(0,s.safeDocument)().getElementById(this.options.domId);if(t){let e=t.getBoundingClientRect();return{width:e.width*i.retina.pixelRatio,height:e.height*i.retina.pixelRatio,mode:s.PixelMode.precise}}}return this.options.size??((t=new a.G).load({height:0,mode:s.PixelMode.percent,width:0}),t)}_destroy=()=>{this._mutationObserver?.disconnect(),this._mutationObserver=void 0,this._resizeObserver?.disconnect(),this._resizeObserver=void 0,this._removeCallback(this),this._container.dispatchEvent("emitterDestroyed",{emitter:this})};_emit(){if(this._paused)return;let t=(0,s.getRangeValue)(this.options.rate.quantity);this._emitParticles(t)}_emitParticles(t){let i=(0,s.itemFromSingleOrMultiple)(this._particlesOptions)??{},e=this.options.spawn.fill?.color.animation,o=this.options.spawn.fill?.enable??!!this.options.spawn.fill?.color,a=this.options.spawn.fill?.opacity===void 0?s.defaultOpacity:(0,s.getRangeValue)(this.options.spawn.fill.opacity),n=this.options.spawn.stroke?.color?.animation,r=this.options.spawn.stroke?.opacity===void 0?s.defaultOpacity:(0,s.getRangeValue)(this.options.spawn.stroke.opacity),h=this.options.spawn.stroke?.width===void 0?1:(0,s.getRangeValue)(this.options.spawn.stroke.width),p=this._container.retina.reduceFactor,c=!!e,_=!!n,d=!!this._shape,u=c||_,m=u||d,w=u?{h:s.hMax,s:s.sMax,l:s.lMax}:null,y=this.options.shape;for(let c=0;c<t*p;c++){let t=m?(0,s.deepExtend)({},i):i;if(this.spawnFillOpacity=a,this.spawnFillEnabled=o,this.spawnStrokeOpacity=r,this.spawnStrokeWidth=h,this.spawnFillColor&&(e&&w&&(this.spawnFillColor.h=this._setColorAnimation(e.h,this.spawnFillColor.h,w.h,3.6),this.spawnFillColor.s=this._setColorAnimation(e.s,this.spawnFillColor.s,w.s),this.spawnFillColor.l=this._setColorAnimation(e.l,this.spawnFillColor.l,w.l)),l(t,this.spawnFillColor,this.spawnFillOpacity,this.spawnFillEnabled)),this.spawnStrokeColor){var f,g,v;n&&w&&(this.spawnStrokeColor.h=this._setColorAnimation(n.h,this.spawnStrokeColor.h,w.h,3.6),this.spawnStrokeColor.s=this._setColorAnimation(n.s,this.spawnStrokeColor.s,w.s),this.spawnStrokeColor.l=this._setColorAnimation(n.l,this.spawnStrokeColor.l,w.l)),f=this.spawnStrokeColor,g=this.spawnStrokeOpacity,v=this.spawnStrokeWidth,t.stroke=new s.Stroke,t.stroke.color=s.AnimatableColor.create(void 0,{value:f}),t.stroke.opacity=g,t.stroke.width=v}let p=this.position;if(this._shape){let i=this._shape.randomPosition();if(i){p=i.position;let e=y.replace;e.color&&i.color&&l(t,i.color,e.opacity?i.opacity??s.defaultOpacity:s.defaultOpacity,!0)}else p=null}p&&this._container.particles.addParticle(p,t)}}_prepareToDie=()=>{if(this._paused)return;let t=void 0!==this.options.life.duration?(0,s.getRangeValue)(this.options.life.duration):void 0;(this._lifeCount>0||this._immortal)&&void 0!==t&&t>0&&(this._duration=t*s.millisecondsToSeconds)};_setColorAnimation=(t,i,e,o=n)=>{let a=this._container;if(!t.enable)return i;let l=(0,s.randomInRangeValue)(t.offset),r=(0,s.getRangeValue)(this.options.rate.delay),h=a.retina.reduceFactor?r*s.millisecondsToSeconds/a.retina.reduceFactor:1/0;return(i+(0,s.getRangeValue)(t.speed)*a.fpsLimit/h+l*o)%e}}}}]);
@@ -1 +1 @@
1
- "use strict";(this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[526],{526(t,e,i){i.d(e,{EmittersInteractor:()=>r});var s=i(702),a=i(303),o=i(982);let l={count:1,enable:!0},n="emitters";class r extends s.ExternalInteractorBase{handleClickMode;maxDistance;_instancesManager;constructor(t,e){super(e),this._instancesManager=t,this.maxDistance=0,this.handleClickMode=(t,e)=>{let i,s=this.container.actualOptions.interactivity.modes.emitters;if(!s||t!==n)return;if((0,a.isArray)(s.value)){let t=s.value.length;if(t>0&&s.random.enable){i=[];let e=new Set;for(let o=0;o<s.random.count;o++){let l=(0,a.arrayRandomIndex)(s.value);if(e.has(l)&&e.size<t){o--;continue}e.add(l);let n=(0,a.itemFromArray)(s.value,l);n&&i.push(n)}}else i=s.value}else i=s.value;let o=i,l=e.mouse.clickPosition;(0,a.executeOnSingleOrMultiple)(o,async t=>{await this._instancesManager.addEmitter(this.container,t,l)})}}clear(){}init(){}interact(t,e){for(let t of this._instancesManager.getArray(this.container))t.update(e)}isEnabled(t,e){let i=this.container.actualOptions,s=t.mouse,o=(e?.interactivity??i.interactivity).events;return!!s.clickPosition&&!!o.onClick.enable&&(0,a.isInArray)(n,o.onClick.mode)}loadModeOptions(t,...e){for(let i of(t.emitters={random:l,value:[]},e))if(i?.emitters)if((0,a.isArray)(i.emitters))for(let e of i.emitters){let i=new o.v;i.load(e),t.emitters.value.push(i)}else if("value"in i.emitters){let e=i.emitters;if(t.emitters.random.enable=e.random?.enable??t.emitters.random.enable,t.emitters.random.count=e.random?.count??t.emitters.random.count,(0,a.isArray)(e.value))for(let i of e.value){let e=new o.v;e.load(i),t.emitters.value.push(e)}else{let i=new o.v;i.load(e.value),t.emitters.value.push(i)}}else{let e=new o.v;e.load(i.emitters),t.emitters.value.push(e)}}removeEmitter(t){let e=this._instancesManager.getArray(this.container).indexOf(t);e>=0&&this._instancesManager.getArray(this.container).splice(e,1)}reset(){}}},982(t,e,i){i.d(e,{v:()=>h});var s=i(303);class a{count;delay;duration;wait;constructor(){this.wait=!1}load(t){(0,s.isNull)(t)||(void 0!==t.count&&(this.count=t.count),void 0!==t.delay&&(this.delay=(0,s.setRangeValue)(t.delay)),void 0!==t.duration&&(this.duration=(0,s.setRangeValue)(t.duration)),void 0!==t.wait&&(this.wait=t.wait))}}class o{delay;quantity;constructor(){this.quantity=1,this.delay=.1}load(t){(0,s.isNull)(t)||(void 0!==t.quantity&&(this.quantity=(0,s.setRangeValue)(t.quantity)),void 0!==t.delay&&(this.delay=(0,s.setRangeValue)(t.delay)))}}class l{color;opacity;constructor(){this.color=!1,this.opacity=!1}load(t){(0,s.isNull)(t)||(void 0!==t.color&&(this.color=t.color),void 0!==t.opacity&&(this.opacity=t.opacity))}}class n{options;replace;type;constructor(){this.options={},this.replace=new l,this.type="square"}load(t){(0,s.isNull)(t)||(void 0!==t.options&&(this.options=(0,s.deepExtend)({},t.options??{})),this.replace.load(t.replace),void 0!==t.type&&(this.type=t.type))}}var r=i(747);class d{fill;stroke;load(t){!(0,s.isNull)(t)&&(t.fill&&(this.fill??=new s.Fill,this.fill.load(t.fill)),t.stroke&&(this.stroke??=new s.Stroke,this.stroke.load(t.stroke)))}}class h{autoPlay;direction;domId;fill;life;name;particles;position;rate;shape;size;spawn;spawnFillColor;spawnStrokeColor;startCount;constructor(){this.autoPlay=!0,this.fill=!0,this.life=new a,this.rate=new o,this.shape=new n,this.spawn=new d,this.startCount=0}load(t){(0,s.isNull)(t)||(void 0!==t.autoPlay&&(this.autoPlay=t.autoPlay),void 0!==t.size&&(this.size??=new r.G,this.size.load(t.size)),void 0!==t.direction&&(this.direction=t.direction),this.domId=t.domId,void 0!==t.fill&&(this.fill=t.fill),this.life.load(t.life),this.name=t.name,this.particles=(0,s.executeOnSingleOrMultiple)(t.particles,t=>(0,s.deepExtend)({},t)),this.rate.load(t.rate),this.shape.load(t.shape),this.spawn.load(t.spawn),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.spawnFillColor&&(this.spawnFillColor??=new s.AnimatableColor,this.spawnFillColor.load(t.spawnFillColor)),void 0!==t.spawnStrokeColor&&(this.spawnStrokeColor??=new s.AnimatableColor,this.spawnStrokeColor.load(t.spawnStrokeColor)),void 0!==t.startCount&&(this.startCount=t.startCount))}}},747(t,e,i){i.d(e,{G:()=>a});var s=i(303);class a{height;mode;width;constructor(){this.mode=s.PixelMode.percent,this.height=0,this.width=0}load(t){(0,s.isNull)(t)||(void 0!==t.mode&&(this.mode=t.mode),void 0!==t.height&&(this.height=t.height),void 0!==t.width&&(this.width=t.width))}}}}]);
1
+ "use strict";(this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[414],{414(t,e,i){i.d(e,{EmittersInteractor:()=>r});var s=i(702),a=i(303),o=i(565);let l={count:1,enable:!0},n="emitters";class r extends s.ExternalInteractorBase{handleClickMode;maxDistance;_instancesManager;constructor(t,e){super(e),this._instancesManager=t,this.maxDistance=0,this.handleClickMode=(t,e)=>{let i,s=this.container.actualOptions.interactivity.modes.emitters;if(!s||t!==n)return;if((0,a.isArray)(s.value)){let t=s.value.length;if(t>0&&s.random.enable){i=[];let e=new Set;for(let o=0;o<s.random.count;o++){let l=(0,a.arrayRandomIndex)(s.value);if(e.has(l)&&e.size<t){o--;continue}e.add(l);let n=(0,a.itemFromArray)(s.value,l);n&&i.push(n)}}else i=s.value}else i=s.value;let o=i,l=e.mouse.clickPosition;(0,a.executeOnSingleOrMultiple)(o,async t=>{await this._instancesManager.addEmitter(this.container,t,l)})}}clear(){}init(){}interact(t,e){for(let t of this._instancesManager.getArray(this.container))t.update(e)}isEnabled(t,e){let i=this.container.actualOptions,s=t.mouse,o=(e?.interactivity??i.interactivity).events;return!!s.clickPosition&&!!o.onClick.enable&&(0,a.isInArray)(n,o.onClick.mode)}loadModeOptions(t,...e){for(let i of(t.emitters={random:l,value:[]},e))if(i?.emitters)if((0,a.isArray)(i.emitters))for(let e of i.emitters){let i=new o.v;i.load(e),t.emitters.value.push(i)}else if("value"in i.emitters){let e=i.emitters;if(t.emitters.random.enable=e.random?.enable??t.emitters.random.enable,t.emitters.random.count=e.random?.count??t.emitters.random.count,(0,a.isArray)(e.value))for(let i of e.value){let e=new o.v;e.load(i),t.emitters.value.push(e)}else{let i=new o.v;i.load(e.value),t.emitters.value.push(i)}}else{let e=new o.v;e.load(i.emitters),t.emitters.value.push(e)}}removeEmitter(t){let e=this._instancesManager.getArray(this.container).indexOf(t);e>=0&&this._instancesManager.getArray(this.container).splice(e,1)}reset(){}}},565(t,e,i){i.d(e,{v:()=>h});var s=i(303);class a{count;delay;duration;wait;constructor(){this.wait=!1}load(t){(0,s.isNull)(t)||(void 0!==t.count&&(this.count=t.count),void 0!==t.delay&&(this.delay=(0,s.setRangeValue)(t.delay)),void 0!==t.duration&&(this.duration=(0,s.setRangeValue)(t.duration)),void 0!==t.wait&&(this.wait=t.wait))}}class o{delay;quantity;constructor(){this.quantity=1,this.delay=.1}load(t){(0,s.isNull)(t)||(void 0!==t.quantity&&(this.quantity=(0,s.setRangeValue)(t.quantity)),void 0!==t.delay&&(this.delay=(0,s.setRangeValue)(t.delay)))}}class l{color;opacity;constructor(){this.color=!1,this.opacity=!1}load(t){(0,s.isNull)(t)||(void 0!==t.color&&(this.color=t.color),void 0!==t.opacity&&(this.opacity=t.opacity))}}class n{options;replace;type;constructor(){this.options={},this.replace=new l,this.type="square"}load(t){(0,s.isNull)(t)||(void 0!==t.options&&(this.options=(0,s.deepExtend)({},t.options??{})),this.replace.load(t.replace),void 0!==t.type&&(this.type=t.type))}}var r=i(143);class d{fill;stroke;load(t){!(0,s.isNull)(t)&&(t.fill&&(this.fill??=new s.Fill,this.fill.load(t.fill)),t.stroke&&(this.stroke??=new s.Stroke,this.stroke.load(t.stroke)))}}class h{autoPlay;direction;domId;fill;life;name;particles;position;rate;shape;size;spawn;spawnFillColor;spawnStrokeColor;startCount;constructor(){this.autoPlay=!0,this.fill=!0,this.life=new a,this.rate=new o,this.shape=new n,this.spawn=new d,this.startCount=0}load(t){(0,s.isNull)(t)||(void 0!==t.autoPlay&&(this.autoPlay=t.autoPlay),void 0!==t.size&&(this.size??=new r.G,this.size.load(t.size)),void 0!==t.direction&&(this.direction=t.direction),this.domId=t.domId,void 0!==t.fill&&(this.fill=t.fill),this.life.load(t.life),this.name=t.name,this.particles=(0,s.executeOnSingleOrMultiple)(t.particles,t=>(0,s.deepExtend)({},t)),this.rate.load(t.rate),this.shape.load(t.shape),this.spawn.load(t.spawn),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.spawnFillColor&&(this.spawnFillColor??=new s.AnimatableColor,this.spawnFillColor.load(t.spawnFillColor)),void 0!==t.spawnStrokeColor&&(this.spawnStrokeColor??=new s.AnimatableColor,this.spawnStrokeColor.load(t.spawnStrokeColor)),void 0!==t.startCount&&(this.startCount=t.startCount))}}},143(t,e,i){i.d(e,{G:()=>a});var s=i(303);class a{height;mode;width;constructor(){this.mode=s.PixelMode.percent,this.height=0,this.width=0}load(t){(0,s.isNull)(t)||(void 0!==t.mode&&(this.mode=t.mode),void 0!==t.height&&(this.height=t.height),void 0!==t.width&&(this.width=t.width))}}}}]);
@@ -1 +1 @@
1
- "use strict";(this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[772],{772(e,t,r){r.r(t),r.d(t,{ShapeManager:()=>s});let a=new Map;class s{addShapeGenerator(e,t){this.getShapeGenerator(e)||a.set(e,t)}getShapeGenerator(e){return a.get(e)}getSupportedShapeGenerators(){return a.keys()}}}}]);
1
+ "use strict";(this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[592],{592(e,t,r){r.r(t),r.d(t,{ShapeManager:()=>s});let a=new Map;class s{addShapeGenerator(e,t){this.getShapeGenerator(e)||a.set(e,t)}getShapeGenerator(e){return a.get(e)}getSupportedShapeGenerators(){return a.keys()}}}}]);
package/764.min.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";(this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[764],{764(t,i,e){e.r(i),e.d(i,{EmittersInstancesManager:()=>a});var s=e(303),o=e(565);class a{_containerArrays;_pluginManager;constructor(t){this._containerArrays=new Map,this._pluginManager=t}async addEmitter(t,i,s){let a=new o.v;a.load(i);let{EmitterInstance:l}=await e.e(399).then(e.bind(e,399)),r=new l(this._pluginManager,t,i=>{this.removeEmitter(t,i)},a,s);return await r.init(),this.getArray(t).push(r),r}clear(t){this.initContainer(t),this._containerArrays.set(t,[])}getArray(t){this.initContainer(t);let i=this._containerArrays.get(t);return i||(i=[],this._containerArrays.set(t,i)),i}initContainer(t){this._containerArrays.has(t)||(this._containerArrays.set(t,[]),t.getEmitter=i=>{let e=this.getArray(t);return void 0===i||(0,s.isNumber)(i)?e[i??0]:e.find(t=>t.name===i)},t.addEmitter=async(i,e)=>this.addEmitter(t,i,e),t.removeEmitter=i=>{let e=t.getEmitter?.(i);e&&this.removeEmitter(t,e)},t.playEmitter=i=>{let e=t.getEmitter?.(i);e&&e.externalPlay()},t.pauseEmitter=i=>{let e=t.getEmitter?.(i);e&&e.externalPause()})}removeEmitter(t,i){let e=this.getArray(t).indexOf(i);e>=0&&this.getArray(t).splice(e,1)}}},565(t,i,e){e.d(i,{v:()=>d});var s=e(303);class o{count;delay;duration;wait;constructor(){this.wait=!1}load(t){(0,s.isNull)(t)||(void 0!==t.count&&(this.count=t.count),void 0!==t.delay&&(this.delay=(0,s.setRangeValue)(t.delay)),void 0!==t.duration&&(this.duration=(0,s.setRangeValue)(t.duration)),void 0!==t.wait&&(this.wait=t.wait))}}class a{delay;quantity;constructor(){this.quantity=1,this.delay=.1}load(t){(0,s.isNull)(t)||(void 0!==t.quantity&&(this.quantity=(0,s.setRangeValue)(t.quantity)),void 0!==t.delay&&(this.delay=(0,s.setRangeValue)(t.delay)))}}class l{color;opacity;constructor(){this.color=!1,this.opacity=!1}load(t){(0,s.isNull)(t)||(void 0!==t.color&&(this.color=t.color),void 0!==t.opacity&&(this.opacity=t.opacity))}}class r{options;replace;type;constructor(){this.options={},this.replace=new l,this.type="square"}load(t){(0,s.isNull)(t)||(void 0!==t.options&&(this.options=(0,s.deepExtend)({},t.options??{})),this.replace.load(t.replace),void 0!==t.type&&(this.type=t.type))}}var n=e(143);class h{fill;stroke;load(t){!(0,s.isNull)(t)&&(t.fill&&(this.fill??=new s.Fill,this.fill.load(t.fill)),t.stroke&&(this.stroke??=new s.Stroke,this.stroke.load(t.stroke)))}}class d{autoPlay;direction;domId;fill;life;name;particles;position;rate;shape;size;spawn;spawnFillColor;spawnStrokeColor;startCount;constructor(){this.autoPlay=!0,this.fill=!0,this.life=new o,this.rate=new a,this.shape=new r,this.spawn=new h,this.startCount=0}load(t){(0,s.isNull)(t)||(void 0!==t.autoPlay&&(this.autoPlay=t.autoPlay),void 0!==t.size&&(this.size??=new n.G,this.size.load(t.size)),void 0!==t.direction&&(this.direction=t.direction),this.domId=t.domId,void 0!==t.fill&&(this.fill=t.fill),this.life.load(t.life),this.name=t.name,this.particles=(0,s.executeOnSingleOrMultiple)(t.particles,t=>(0,s.deepExtend)({},t)),this.rate.load(t.rate),this.shape.load(t.shape),this.spawn.load(t.spawn),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.spawnFillColor&&(this.spawnFillColor??=new s.AnimatableColor,this.spawnFillColor.load(t.spawnFillColor)),void 0!==t.spawnStrokeColor&&(this.spawnStrokeColor??=new s.AnimatableColor,this.spawnStrokeColor.load(t.spawnStrokeColor)),void 0!==t.startCount&&(this.startCount=t.startCount))}}},143(t,i,e){e.d(i,{G:()=>o});var s=e(303);class o{height;mode;width;constructor(){this.mode=s.PixelMode.percent,this.height=0,this.width=0}load(t){(0,s.isNull)(t)||(void 0!==t.mode&&(this.mode=t.mode),void 0!==t.height&&(this.height=t.height),void 0!==t.width&&(this.width=t.width))}}}}]);
@@ -1 +1 @@
1
- "use strict";(this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[803],{803(t,a,e){e.d(a,{EmittersPluginInstance:()=>n});var i=e(303);class n{container;_instancesManager;constructor(t,a){this.container=a,this._instancesManager=t,this._instancesManager.initContainer(a)}async init(){let t=this.container.actualOptions.emitters;if((0,i.isArray)(t))for(let a of t)await this._instancesManager.addEmitter(this.container,a);else await this._instancesManager.addEmitter(this.container,t)}pause(){for(let t of this._instancesManager.getArray(this.container))t.pause()}play(){for(let t of this._instancesManager.getArray(this.container))t.play()}resize(){for(let t of this._instancesManager.getArray(this.container))t.resize()}stop(){this._instancesManager.clear(this.container)}update(t){this._instancesManager.getArray(this.container).forEach(a=>{a.update(t)})}}}}]);
1
+ "use strict";(this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[815],{815(t,a,e){e.d(a,{EmittersPluginInstance:()=>n});var i=e(303);class n{container;_instancesManager;constructor(t,a){this.container=a,this._instancesManager=t,this._instancesManager.initContainer(a)}async init(){let t=this.container.actualOptions.emitters;if((0,i.isArray)(t))for(let a of t)await this._instancesManager.addEmitter(this.container,a);else await this._instancesManager.addEmitter(this.container,t)}pause(){for(let t of this._instancesManager.getArray(this.container))t.pause()}play(){for(let t of this._instancesManager.getArray(this.container))t.play()}resize(){for(let t of this._instancesManager.getArray(this.container))t.resize()}stop(){this._instancesManager.clear(this.container)}update(t){this._instancesManager.getArray(this.container).forEach(a=>{a.update(t)})}}}}]);
@@ -15,8 +15,6 @@ function setParticlesOptionsStrokeColor(particlesOptions, color, opacity, width)
15
15
  particlesOptions.stroke.width = width;
16
16
  }
17
17
  export class EmitterInstance {
18
- container;
19
- removeCallback;
20
18
  fill;
21
19
  name;
22
20
  options;
@@ -28,12 +26,12 @@ export class EmitterInstance {
28
26
  spawnStrokeColor;
29
27
  spawnStrokeOpacity;
30
28
  spawnStrokeWidth;
29
+ _container;
31
30
  _currentDuration;
32
31
  _currentEmitDelay;
33
32
  _currentSpawnDelay;
34
33
  _duration;
35
34
  _emitDelay;
36
- _engine;
37
35
  _firstSpawn;
38
36
  _immortal;
39
37
  _initialPosition;
@@ -41,15 +39,17 @@ export class EmitterInstance {
41
39
  _mutationObserver;
42
40
  _particlesOptions;
43
41
  _paused;
42
+ _pluginManager;
43
+ _removeCallback;
44
44
  _resizeObserver;
45
45
  _shape;
46
46
  _size;
47
47
  _spawnDelay;
48
48
  _startParticlesAdded;
49
- constructor(engine, container, removeCallback, options, position) {
50
- this.container = container;
51
- this.removeCallback = removeCallback;
52
- this._engine = engine;
49
+ constructor(pluginManager, container, removeCallback, options, position) {
50
+ this._pluginManager = pluginManager;
51
+ this._container = container;
52
+ this._removeCallback = removeCallback;
53
53
  this._currentDuration = 0;
54
54
  this._currentEmitDelay = 0;
55
55
  this._currentSpawnDelay = 0;
@@ -74,15 +74,15 @@ export class EmitterInstance {
74
74
  particlesOptions.move ??= {};
75
75
  particlesOptions.move.direction ??= this.options.direction;
76
76
  if (this.options.spawn.fill?.color) {
77
- this.spawnFillColor = rangeColorToHsl(this._engine, this.options.spawn.fill.color);
77
+ this.spawnFillColor = rangeColorToHsl(this._pluginManager, this.options.spawn.fill.color);
78
78
  }
79
79
  if (this.options.spawn.stroke?.color) {
80
- this.spawnStrokeColor = rangeColorToHsl(this._engine, this.options.spawn.stroke.color);
80
+ this.spawnStrokeColor = rangeColorToHsl(this._pluginManager, this.options.spawn.stroke.color);
81
81
  }
82
82
  this._paused = !this.options.autoPlay;
83
83
  this._particlesOptions = particlesOptions;
84
84
  this._size = this._calcSize();
85
- this.size = getSize(this._size, this.container.canvas.size);
85
+ this.size = getSize(this._size, this._container.canvas.size);
86
86
  this._lifeCount = this.options.life.count ?? defaultLifeCount;
87
87
  this._immortal = this._lifeCount <= minLifeCount;
88
88
  if (this.options.domId) {
@@ -101,15 +101,12 @@ export class EmitterInstance {
101
101
  this._resizeObserver.observe(element);
102
102
  }
103
103
  }
104
- const shapeOptions = this.options.shape, shapeGenerator = this._engine.emitterShapeManager?.getShapeGenerator(shapeOptions.type);
104
+ const shapeOptions = this.options.shape, shapeGenerator = this._pluginManager.emitterShapeManager?.getShapeGenerator(shapeOptions.type);
105
105
  if (shapeGenerator) {
106
- this._shape = shapeGenerator.generate(this.container, this.position, this.size, this.fill, shapeOptions.options);
106
+ this._shape = shapeGenerator.generate(this._container, this.position, this.size, this.fill, shapeOptions.options);
107
107
  }
108
- this._engine.dispatchEvent("emitterCreated", {
109
- container,
110
- data: {
111
- emitter: this,
112
- },
108
+ this._container.dispatchEvent("emitterCreated", {
109
+ emitter: this,
113
110
  });
114
111
  this.play();
115
112
  }
@@ -138,7 +135,7 @@ export class EmitterInstance {
138
135
  (this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? defaultSpawnDelay)))) {
139
136
  return;
140
137
  }
141
- const container = this.container;
138
+ const container = this._container;
142
139
  if (this._emitDelay === undefined) {
143
140
  const delay = getRangeValue(this.options.rate.delay);
144
141
  this._emitDelay = container.retina.reduceFactor
@@ -150,7 +147,7 @@ export class EmitterInstance {
150
147
  }
151
148
  }
152
149
  resize() {
153
- const initialPosition = this._initialPosition, container = this.container;
150
+ const initialPosition = this._initialPosition, container = this._container;
154
151
  this.position =
155
152
  initialPosition && isPointInside(initialPosition, container.canvas.size, Vector.origin)
156
153
  ? initialPosition
@@ -163,7 +160,7 @@ export class EmitterInstance {
163
160
  if (this._paused) {
164
161
  return;
165
162
  }
166
- const container = this.container;
163
+ const container = this._container;
167
164
  if (this._firstSpawn) {
168
165
  this._firstSpawn = false;
169
166
  this._currentSpawnDelay = this._spawnDelay ?? defaultSpawnDelay;
@@ -201,9 +198,7 @@ export class EmitterInstance {
201
198
  if (this._spawnDelay !== undefined) {
202
199
  this._currentSpawnDelay += delta.value;
203
200
  if (this._currentSpawnDelay >= this._spawnDelay) {
204
- this._engine.dispatchEvent("emitterPlay", {
205
- container: this.container,
206
- });
201
+ this._container.dispatchEvent("emitterPlay");
207
202
  this.play();
208
203
  this._currentSpawnDelay -= this._spawnDelay;
209
204
  delete this._spawnDelay;
@@ -218,7 +213,7 @@ export class EmitterInstance {
218
213
  }
219
214
  }
220
215
  _calcPosition() {
221
- const container = this.container;
216
+ const container = this._container;
222
217
  if (this.options.domId) {
223
218
  const element = safeDocument().getElementById(this.options.domId);
224
219
  if (element) {
@@ -235,7 +230,7 @@ export class EmitterInstance {
235
230
  });
236
231
  }
237
232
  _calcSize() {
238
- const container = this.container;
233
+ const container = this._container;
239
234
  if (this.options.domId) {
240
235
  const element = safeDocument().getElementById(this.options.domId);
241
236
  if (element) {
@@ -263,12 +258,9 @@ export class EmitterInstance {
263
258
  this._mutationObserver = undefined;
264
259
  this._resizeObserver?.disconnect();
265
260
  this._resizeObserver = undefined;
266
- this.removeCallback(this);
267
- this._engine.dispatchEvent("emitterDestroyed", {
268
- container: this.container,
269
- data: {
270
- emitter: this,
271
- },
261
+ this._removeCallback(this);
262
+ this._container.dispatchEvent("emitterDestroyed", {
263
+ emitter: this,
272
264
  });
273
265
  };
274
266
  _emit() {
@@ -286,7 +278,7 @@ export class EmitterInstance {
286
278
  ? defaultOpacity
287
279
  : getRangeValue(this.options.spawn.stroke.opacity), strokeWidth = this.options.spawn.stroke?.width === undefined
288
280
  ? defaultStrokeWidth
289
- : getRangeValue(this.options.spawn.stroke.width), reduceFactor = this.container.retina.reduceFactor, needsFillColorAnimation = !!fillHslAnimation, needsStrokeColorAnimation = !!strokeHslAnimation, needsShapeData = !!this._shape, needsColorAnimation = needsFillColorAnimation || needsStrokeColorAnimation, needsCopy = needsColorAnimation || needsShapeData, maxValues = needsColorAnimation ? { h: hMax, s: sMax, l: lMax } : null, shapeOptions = this.options.shape;
281
+ : getRangeValue(this.options.spawn.stroke.width), reduceFactor = this._container.retina.reduceFactor, needsFillColorAnimation = !!fillHslAnimation, needsStrokeColorAnimation = !!strokeHslAnimation, needsShapeData = !!this._shape, needsColorAnimation = needsFillColorAnimation || needsStrokeColorAnimation, needsCopy = needsColorAnimation || needsShapeData, maxValues = needsColorAnimation ? { h: hMax, s: sMax, l: lMax } : null, shapeOptions = this.options.shape;
290
282
  for (let i = 0; i < quantity * reduceFactor; i++) {
291
283
  const particlesOptions = needsCopy
292
284
  ? deepExtend({}, singleParticlesOptions)
@@ -326,7 +318,7 @@ export class EmitterInstance {
326
318
  }
327
319
  }
328
320
  if (position) {
329
- this.container.particles.addParticle(position, particlesOptions);
321
+ this._container.particles.addParticle(position, particlesOptions);
330
322
  }
331
323
  }
332
324
  }
@@ -340,7 +332,7 @@ export class EmitterInstance {
340
332
  }
341
333
  };
342
334
  _setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => {
343
- const container = this.container;
335
+ const container = this._container;
344
336
  if (!animation.enable) {
345
337
  return initValue;
346
338
  }
@@ -3,15 +3,15 @@ import { Emitter } from "./Options/Classes/Emitter.js";
3
3
  const defaultIndex = 0;
4
4
  export class EmittersInstancesManager {
5
5
  _containerArrays;
6
- _engine;
7
- constructor(engine) {
6
+ _pluginManager;
7
+ constructor(pluginManager) {
8
8
  this._containerArrays = new Map();
9
- this._engine = engine;
9
+ this._pluginManager = pluginManager;
10
10
  }
11
11
  async addEmitter(container, options, position) {
12
12
  const emitterOptions = new Emitter();
13
13
  emitterOptions.load(options);
14
- const { EmitterInstance } = await import("./EmitterInstance.js"), emitter = new EmitterInstance(this._engine, container, (emitter) => {
14
+ const { EmitterInstance } = await import("./EmitterInstance.js"), emitter = new EmitterInstance(this._pluginManager, container, (emitter) => {
15
15
  this.removeEmitter(container, emitter);
16
16
  }, emitterOptions, position);
17
17
  await emitter.init();
package/browser/index.js CHANGED
@@ -1,26 +1,26 @@
1
1
  export async function loadEmittersPlugin(engine) {
2
- engine.checkVersion("4.0.0-beta.0");
3
- await engine.register(async (e) => {
2
+ engine.checkVersion("4.0.0-beta.1");
3
+ await engine.pluginManager.register(async (e) => {
4
4
  const [{ ensureInteractivityPluginLoaded }, { ShapeManager }, { EmittersInstancesManager }, { EmittersPlugin },] = await Promise.all([
5
5
  import("@tsparticles/plugin-interactivity"),
6
6
  import("./ShapeManager.js"),
7
7
  import("./EmittersInstancesManager.js"),
8
8
  import("./EmittersPlugin.js"),
9
- ]), instancesManager = new EmittersInstancesManager(e);
9
+ ]), pluginManager = e.pluginManager, instancesManager = new EmittersInstancesManager(pluginManager);
10
10
  ensureInteractivityPluginLoaded(e);
11
- e.emitterShapeManager ??= new ShapeManager();
12
- e.addEmitterShapeGenerator ??= (name, generator) => {
13
- e.emitterShapeManager?.addShapeGenerator(name, generator);
11
+ pluginManager.emitterShapeManager ??= new ShapeManager();
12
+ pluginManager.addEmitterShapeGenerator ??= (name, generator) => {
13
+ pluginManager.emitterShapeManager?.addShapeGenerator(name, generator);
14
14
  };
15
- e.addPlugin(new EmittersPlugin(instancesManager));
16
- e.addInteractor?.("externalEmitters", async (container) => {
15
+ pluginManager.addPlugin(new EmittersPlugin(instancesManager));
16
+ pluginManager.addInteractor?.("externalEmitters", async (container) => {
17
17
  const { EmittersInteractor } = await import("./EmittersInteractor.js");
18
18
  return new EmittersInteractor(instancesManager, container);
19
19
  });
20
20
  });
21
21
  }
22
22
  export function ensureEmittersPluginLoaded(e) {
23
- if (!e.addEmitterShapeGenerator) {
23
+ if (!e.pluginManager.addEmitterShapeGenerator) {
24
24
  throw new Error("tsParticles Emitters Plugin is not loaded");
25
25
  }
26
26
  }
@@ -15,8 +15,6 @@ function setParticlesOptionsStrokeColor(particlesOptions, color, opacity, width)
15
15
  particlesOptions.stroke.width = width;
16
16
  }
17
17
  export class EmitterInstance {
18
- container;
19
- removeCallback;
20
18
  fill;
21
19
  name;
22
20
  options;
@@ -28,12 +26,12 @@ export class EmitterInstance {
28
26
  spawnStrokeColor;
29
27
  spawnStrokeOpacity;
30
28
  spawnStrokeWidth;
29
+ _container;
31
30
  _currentDuration;
32
31
  _currentEmitDelay;
33
32
  _currentSpawnDelay;
34
33
  _duration;
35
34
  _emitDelay;
36
- _engine;
37
35
  _firstSpawn;
38
36
  _immortal;
39
37
  _initialPosition;
@@ -41,15 +39,17 @@ export class EmitterInstance {
41
39
  _mutationObserver;
42
40
  _particlesOptions;
43
41
  _paused;
42
+ _pluginManager;
43
+ _removeCallback;
44
44
  _resizeObserver;
45
45
  _shape;
46
46
  _size;
47
47
  _spawnDelay;
48
48
  _startParticlesAdded;
49
- constructor(engine, container, removeCallback, options, position) {
50
- this.container = container;
51
- this.removeCallback = removeCallback;
52
- this._engine = engine;
49
+ constructor(pluginManager, container, removeCallback, options, position) {
50
+ this._pluginManager = pluginManager;
51
+ this._container = container;
52
+ this._removeCallback = removeCallback;
53
53
  this._currentDuration = 0;
54
54
  this._currentEmitDelay = 0;
55
55
  this._currentSpawnDelay = 0;
@@ -74,15 +74,15 @@ export class EmitterInstance {
74
74
  particlesOptions.move ??= {};
75
75
  particlesOptions.move.direction ??= this.options.direction;
76
76
  if (this.options.spawn.fill?.color) {
77
- this.spawnFillColor = rangeColorToHsl(this._engine, this.options.spawn.fill.color);
77
+ this.spawnFillColor = rangeColorToHsl(this._pluginManager, this.options.spawn.fill.color);
78
78
  }
79
79
  if (this.options.spawn.stroke?.color) {
80
- this.spawnStrokeColor = rangeColorToHsl(this._engine, this.options.spawn.stroke.color);
80
+ this.spawnStrokeColor = rangeColorToHsl(this._pluginManager, this.options.spawn.stroke.color);
81
81
  }
82
82
  this._paused = !this.options.autoPlay;
83
83
  this._particlesOptions = particlesOptions;
84
84
  this._size = this._calcSize();
85
- this.size = getSize(this._size, this.container.canvas.size);
85
+ this.size = getSize(this._size, this._container.canvas.size);
86
86
  this._lifeCount = this.options.life.count ?? defaultLifeCount;
87
87
  this._immortal = this._lifeCount <= minLifeCount;
88
88
  if (this.options.domId) {
@@ -101,15 +101,12 @@ export class EmitterInstance {
101
101
  this._resizeObserver.observe(element);
102
102
  }
103
103
  }
104
- const shapeOptions = this.options.shape, shapeGenerator = this._engine.emitterShapeManager?.getShapeGenerator(shapeOptions.type);
104
+ const shapeOptions = this.options.shape, shapeGenerator = this._pluginManager.emitterShapeManager?.getShapeGenerator(shapeOptions.type);
105
105
  if (shapeGenerator) {
106
- this._shape = shapeGenerator.generate(this.container, this.position, this.size, this.fill, shapeOptions.options);
106
+ this._shape = shapeGenerator.generate(this._container, this.position, this.size, this.fill, shapeOptions.options);
107
107
  }
108
- this._engine.dispatchEvent("emitterCreated", {
109
- container,
110
- data: {
111
- emitter: this,
112
- },
108
+ this._container.dispatchEvent("emitterCreated", {
109
+ emitter: this,
113
110
  });
114
111
  this.play();
115
112
  }
@@ -138,7 +135,7 @@ export class EmitterInstance {
138
135
  (this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? defaultSpawnDelay)))) {
139
136
  return;
140
137
  }
141
- const container = this.container;
138
+ const container = this._container;
142
139
  if (this._emitDelay === undefined) {
143
140
  const delay = getRangeValue(this.options.rate.delay);
144
141
  this._emitDelay = container.retina.reduceFactor
@@ -150,7 +147,7 @@ export class EmitterInstance {
150
147
  }
151
148
  }
152
149
  resize() {
153
- const initialPosition = this._initialPosition, container = this.container;
150
+ const initialPosition = this._initialPosition, container = this._container;
154
151
  this.position =
155
152
  initialPosition && isPointInside(initialPosition, container.canvas.size, Vector.origin)
156
153
  ? initialPosition
@@ -163,7 +160,7 @@ export class EmitterInstance {
163
160
  if (this._paused) {
164
161
  return;
165
162
  }
166
- const container = this.container;
163
+ const container = this._container;
167
164
  if (this._firstSpawn) {
168
165
  this._firstSpawn = false;
169
166
  this._currentSpawnDelay = this._spawnDelay ?? defaultSpawnDelay;
@@ -201,9 +198,7 @@ export class EmitterInstance {
201
198
  if (this._spawnDelay !== undefined) {
202
199
  this._currentSpawnDelay += delta.value;
203
200
  if (this._currentSpawnDelay >= this._spawnDelay) {
204
- this._engine.dispatchEvent("emitterPlay", {
205
- container: this.container,
206
- });
201
+ this._container.dispatchEvent("emitterPlay");
207
202
  this.play();
208
203
  this._currentSpawnDelay -= this._spawnDelay;
209
204
  delete this._spawnDelay;
@@ -218,7 +213,7 @@ export class EmitterInstance {
218
213
  }
219
214
  }
220
215
  _calcPosition() {
221
- const container = this.container;
216
+ const container = this._container;
222
217
  if (this.options.domId) {
223
218
  const element = safeDocument().getElementById(this.options.domId);
224
219
  if (element) {
@@ -235,7 +230,7 @@ export class EmitterInstance {
235
230
  });
236
231
  }
237
232
  _calcSize() {
238
- const container = this.container;
233
+ const container = this._container;
239
234
  if (this.options.domId) {
240
235
  const element = safeDocument().getElementById(this.options.domId);
241
236
  if (element) {
@@ -263,12 +258,9 @@ export class EmitterInstance {
263
258
  this._mutationObserver = undefined;
264
259
  this._resizeObserver?.disconnect();
265
260
  this._resizeObserver = undefined;
266
- this.removeCallback(this);
267
- this._engine.dispatchEvent("emitterDestroyed", {
268
- container: this.container,
269
- data: {
270
- emitter: this,
271
- },
261
+ this._removeCallback(this);
262
+ this._container.dispatchEvent("emitterDestroyed", {
263
+ emitter: this,
272
264
  });
273
265
  };
274
266
  _emit() {
@@ -286,7 +278,7 @@ export class EmitterInstance {
286
278
  ? defaultOpacity
287
279
  : getRangeValue(this.options.spawn.stroke.opacity), strokeWidth = this.options.spawn.stroke?.width === undefined
288
280
  ? defaultStrokeWidth
289
- : getRangeValue(this.options.spawn.stroke.width), reduceFactor = this.container.retina.reduceFactor, needsFillColorAnimation = !!fillHslAnimation, needsStrokeColorAnimation = !!strokeHslAnimation, needsShapeData = !!this._shape, needsColorAnimation = needsFillColorAnimation || needsStrokeColorAnimation, needsCopy = needsColorAnimation || needsShapeData, maxValues = needsColorAnimation ? { h: hMax, s: sMax, l: lMax } : null, shapeOptions = this.options.shape;
281
+ : getRangeValue(this.options.spawn.stroke.width), reduceFactor = this._container.retina.reduceFactor, needsFillColorAnimation = !!fillHslAnimation, needsStrokeColorAnimation = !!strokeHslAnimation, needsShapeData = !!this._shape, needsColorAnimation = needsFillColorAnimation || needsStrokeColorAnimation, needsCopy = needsColorAnimation || needsShapeData, maxValues = needsColorAnimation ? { h: hMax, s: sMax, l: lMax } : null, shapeOptions = this.options.shape;
290
282
  for (let i = 0; i < quantity * reduceFactor; i++) {
291
283
  const particlesOptions = needsCopy
292
284
  ? deepExtend({}, singleParticlesOptions)
@@ -326,7 +318,7 @@ export class EmitterInstance {
326
318
  }
327
319
  }
328
320
  if (position) {
329
- this.container.particles.addParticle(position, particlesOptions);
321
+ this._container.particles.addParticle(position, particlesOptions);
330
322
  }
331
323
  }
332
324
  }
@@ -340,7 +332,7 @@ export class EmitterInstance {
340
332
  }
341
333
  };
342
334
  _setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => {
343
- const container = this.container;
335
+ const container = this._container;
344
336
  if (!animation.enable) {
345
337
  return initValue;
346
338
  }
@@ -3,15 +3,15 @@ import { Emitter } from "./Options/Classes/Emitter.js";
3
3
  const defaultIndex = 0;
4
4
  export class EmittersInstancesManager {
5
5
  _containerArrays;
6
- _engine;
7
- constructor(engine) {
6
+ _pluginManager;
7
+ constructor(pluginManager) {
8
8
  this._containerArrays = new Map();
9
- this._engine = engine;
9
+ this._pluginManager = pluginManager;
10
10
  }
11
11
  async addEmitter(container, options, position) {
12
12
  const emitterOptions = new Emitter();
13
13
  emitterOptions.load(options);
14
- const { EmitterInstance } = await import("./EmitterInstance.js"), emitter = new EmitterInstance(this._engine, container, (emitter) => {
14
+ const { EmitterInstance } = await import("./EmitterInstance.js"), emitter = new EmitterInstance(this._pluginManager, container, (emitter) => {
15
15
  this.removeEmitter(container, emitter);
16
16
  }, emitterOptions, position);
17
17
  await emitter.init();
package/cjs/index.js CHANGED
@@ -1,26 +1,26 @@
1
1
  export async function loadEmittersPlugin(engine) {
2
- engine.checkVersion("4.0.0-beta.0");
3
- await engine.register(async (e) => {
2
+ engine.checkVersion("4.0.0-beta.1");
3
+ await engine.pluginManager.register(async (e) => {
4
4
  const [{ ensureInteractivityPluginLoaded }, { ShapeManager }, { EmittersInstancesManager }, { EmittersPlugin },] = await Promise.all([
5
5
  import("@tsparticles/plugin-interactivity"),
6
6
  import("./ShapeManager.js"),
7
7
  import("./EmittersInstancesManager.js"),
8
8
  import("./EmittersPlugin.js"),
9
- ]), instancesManager = new EmittersInstancesManager(e);
9
+ ]), pluginManager = e.pluginManager, instancesManager = new EmittersInstancesManager(pluginManager);
10
10
  ensureInteractivityPluginLoaded(e);
11
- e.emitterShapeManager ??= new ShapeManager();
12
- e.addEmitterShapeGenerator ??= (name, generator) => {
13
- e.emitterShapeManager?.addShapeGenerator(name, generator);
11
+ pluginManager.emitterShapeManager ??= new ShapeManager();
12
+ pluginManager.addEmitterShapeGenerator ??= (name, generator) => {
13
+ pluginManager.emitterShapeManager?.addShapeGenerator(name, generator);
14
14
  };
15
- e.addPlugin(new EmittersPlugin(instancesManager));
16
- e.addInteractor?.("externalEmitters", async (container) => {
15
+ pluginManager.addPlugin(new EmittersPlugin(instancesManager));
16
+ pluginManager.addInteractor?.("externalEmitters", async (container) => {
17
17
  const { EmittersInteractor } = await import("./EmittersInteractor.js");
18
18
  return new EmittersInteractor(instancesManager, container);
19
19
  });
20
20
  });
21
21
  }
22
22
  export function ensureEmittersPluginLoaded(e) {
23
- if (!e.addEmitterShapeGenerator) {
23
+ if (!e.pluginManager.addEmitterShapeGenerator) {
24
24
  throw new Error("tsParticles Emitters Plugin is not loaded");
25
25
  }
26
26
  }