@tsparticles/plugin-emitters 4.0.0-alpha.5 → 4.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/526.min.js +1 -0
  2. package/588.min.js +1 -0
  3. package/772.min.js +1 -0
  4. package/784.min.js +1 -0
  5. package/795.min.js +1 -0
  6. package/803.min.js +1 -0
  7. package/README.md +5 -0
  8. package/browser/EmitterInstance.js +109 -65
  9. package/browser/EmitterShapeBase.js +4 -0
  10. package/browser/EmittersInstancesManager.js +2 -0
  11. package/browser/EmittersInteractor.js +5 -1
  12. package/browser/EmittersPlugin.js +2 -1
  13. package/browser/EmittersPluginInstance.js +2 -0
  14. package/browser/Options/Classes/Emitter.js +25 -3
  15. package/browser/Options/Classes/EmitterLife.js +4 -0
  16. package/browser/Options/Classes/EmitterRate.js +2 -0
  17. package/browser/Options/Classes/EmitterShape.js +3 -0
  18. package/browser/Options/Classes/EmitterShapeReplace.js +2 -0
  19. package/browser/Options/Classes/EmitterSize.js +3 -0
  20. package/browser/Options/Classes/EmitterSpawn.js +18 -0
  21. package/browser/Options/Interfaces/IEmitterSpawn.js +1 -0
  22. package/browser/index.js +13 -3
  23. package/cjs/EmitterInstance.js +109 -65
  24. package/cjs/EmitterShapeBase.js +4 -0
  25. package/cjs/EmittersInstancesManager.js +2 -0
  26. package/cjs/EmittersInteractor.js +5 -1
  27. package/cjs/EmittersPlugin.js +2 -1
  28. package/cjs/EmittersPluginInstance.js +2 -0
  29. package/cjs/Options/Classes/Emitter.js +25 -3
  30. package/cjs/Options/Classes/EmitterLife.js +4 -0
  31. package/cjs/Options/Classes/EmitterRate.js +2 -0
  32. package/cjs/Options/Classes/EmitterShape.js +3 -0
  33. package/cjs/Options/Classes/EmitterShapeReplace.js +2 -0
  34. package/cjs/Options/Classes/EmitterSize.js +3 -0
  35. package/cjs/Options/Classes/EmitterSpawn.js +18 -0
  36. package/cjs/Options/Interfaces/IEmitterSpawn.js +1 -0
  37. package/cjs/index.js +13 -3
  38. package/dist_browser_EmitterInstance_js.js +2 -2
  39. package/dist_browser_EmittersInstancesManager_js.js +18 -8
  40. package/dist_browser_EmittersInteractor_js.js +19 -9
  41. package/dist_browser_EmittersPluginInstance_js.js +2 -2
  42. package/dist_browser_EmittersPlugin_js.js +18 -8
  43. package/dist_browser_ShapeManager_js.js +2 -2
  44. package/esm/EmitterInstance.js +109 -65
  45. package/esm/EmitterShapeBase.js +4 -0
  46. package/esm/EmittersInstancesManager.js +2 -0
  47. package/esm/EmittersInteractor.js +5 -1
  48. package/esm/EmittersPlugin.js +2 -1
  49. package/esm/EmittersPluginInstance.js +2 -0
  50. package/esm/Options/Classes/Emitter.js +25 -3
  51. package/esm/Options/Classes/EmitterLife.js +4 -0
  52. package/esm/Options/Classes/EmitterRate.js +2 -0
  53. package/esm/Options/Classes/EmitterShape.js +3 -0
  54. package/esm/Options/Classes/EmitterShapeReplace.js +2 -0
  55. package/esm/Options/Classes/EmitterSize.js +3 -0
  56. package/esm/Options/Classes/EmitterSpawn.js +18 -0
  57. package/esm/Options/Interfaces/IEmitterSpawn.js +1 -0
  58. package/esm/index.js +13 -3
  59. package/package.json +3 -3
  60. package/report.html +3 -3
  61. package/tsparticles.plugin.emitters.js +44 -32
  62. package/tsparticles.plugin.emitters.min.js +2 -2
  63. package/types/EmitterInstance.d.ts +6 -1
  64. package/types/EmittersInteractor.d.ts +1 -0
  65. package/types/EmittersPlugin.d.ts +1 -1
  66. package/types/IEmitterShapeGenerator.d.ts +2 -2
  67. package/types/Options/Classes/Emitter.d.ts +4 -1
  68. package/types/Options/Classes/EmitterSpawn.d.ts +7 -0
  69. package/types/Options/Interfaces/IEmitter.d.ts +4 -1
  70. package/types/Options/Interfaces/IEmitterSpawn.d.ts +5 -0
  71. package/types/index.d.ts +1 -0
  72. package/umd/EmitterInstance.js +108 -64
  73. package/umd/EmitterShapeBase.js +4 -0
  74. package/umd/EmittersInstancesManager.js +2 -0
  75. package/umd/EmittersInteractor.js +5 -1
  76. package/umd/EmittersPlugin.js +2 -1
  77. package/umd/EmittersPluginInstance.js +2 -0
  78. package/umd/Options/Classes/Emitter.js +26 -4
  79. package/umd/Options/Classes/EmitterLife.js +4 -0
  80. package/umd/Options/Classes/EmitterRate.js +2 -0
  81. package/umd/Options/Classes/EmitterShape.js +3 -0
  82. package/umd/Options/Classes/EmitterShapeReplace.js +2 -0
  83. package/umd/Options/Classes/EmitterSize.js +3 -0
  84. package/umd/Options/Classes/EmitterSpawn.js +32 -0
  85. package/umd/Options/Interfaces/IEmitterSpawn.js +12 -0
  86. package/umd/index.js +14 -3
  87. package/129.min.js +0 -2
  88. package/129.min.js.LICENSE.txt +0 -1
  89. package/246.min.js +0 -2
  90. package/246.min.js.LICENSE.txt +0 -1
  91. package/330.min.js +0 -2
  92. package/330.min.js.LICENSE.txt +0 -1
  93. package/490.min.js +0 -2
  94. package/490.min.js.LICENSE.txt +0 -1
  95. package/849.min.js +0 -2
  96. package/849.min.js.LICENSE.txt +0 -1
  97. package/940.min.js +0 -2
  98. package/940.min.js.LICENSE.txt +0 -1
  99. package/tsparticles.plugin.emitters.min.js.LICENSE.txt +0 -1
package/526.min.js ADDED
@@ -0,0 +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))}}}}]);
package/588.min.js ADDED
@@ -0,0 +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))}}}}]);
package/772.min.js ADDED
@@ -0,0 +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()}}}}]);
package/784.min.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";(this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[784],{784(t,i,e){e.r(i),e.d(i,{EmittersInstancesManager:()=>a});var s=e(303),o=e(982);class a{_containerArrays;_engine;constructor(t){this._containerArrays=new Map,this._engine=t}async addEmitter(t,i,s){let a=new o.v;a.load(i);let{EmitterInstance:l}=await e.e(795).then(e.bind(e,795)),r=new l(this._engine,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)}}},982(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(747);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))}}},747(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))}}}}]);
package/795.min.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";(this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[795],{795(t,i,e){e.d(i,{EmitterInstance:()=>r});var s=e(303),o=e(982),n=e(747);let a=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{container;removeCallback;fill;name;options;position;size;spawnFillColor;spawnFillEnabled;spawnFillOpacity;spawnStrokeColor;spawnStrokeOpacity;spawnStrokeWidth;_currentDuration;_currentEmitDelay;_currentSpawnDelay;_duration;_emitDelay;_engine;_firstSpawn;_immortal;_initialPosition;_lifeCount;_mutationObserver;_particlesOptions;_paused;_resizeObserver;_shape;_size;_spawnDelay;_startParticlesAdded;constructor(t,i,e,n,a){this.container=i,this.removeCallback=e,this._engine=t,this._currentDuration=0,this._currentEmitDelay=0,this._currentSpawnDelay=0,this._initialPosition=a,n instanceof o.v?this.options=n:(this.options=new o.v,this.options.load(n)),this._spawnDelay=i.retina.reduceFactor?(0,s.getRangeValue)(this.options.life.delay??0)*s.millisecondsToSeconds/i.retina.reduceFactor:1/0,this.position=this._initialPosition??this._calcPosition(),this.name=this.options.name,this.fill=this.options.fill,this._firstSpawn=!this.options.life.wait,this._startParticlesAdded=!1;const 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._engine,this.options.spawn.fill.color)),this.options.spawn.stroke?.color&&(this.spawnStrokeColor=(0,s.rangeColorToHsl)(this._engine,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._engine.emitterShapeManager?.getShapeGenerator(r.type);h&&(this._shape=h.generate(this.container,this.position,this.size,this.fill,r.options)),this._engine.dispatchEvent("emitterCreated",{container:i,data:{emitter:this}}),this.play()}externalPause(){this._paused=!0,this.pause()}externalPlay(){this._paused=!1,this.play()}async init(){await this._shape?.init()}pause(){this._paused||delete this._emitDelay}play(){if(this._paused||!((this._lifeCount>0||this._immortal||!this.options.life.count)&&(this._firstSpawn||this._currentSpawnDelay>=(this._spawnDelay??0))))return;let t=this.container;if(void 0===this._emitDelay){let i=(0,s.getRangeValue)(this.options.rate.delay);this._emitDelay=t.retina.reduceFactor?i*s.millisecondsToSeconds/t.retina.reduceFactor:1/0}(this._lifeCount>0||this._immortal)&&this._prepareToDie()}resize(){let t=this._initialPosition,i=this.container;this.position=t&&(0,s.isPointInside)(t,i.canvas.size,s.Vector.origin)?t:this._calcPosition(),this._size=this._calcSize(),this.size=(0,s.getSize)(this._size,i.canvas.size),this._shape?.resize(this.position,this.size)}update(t){if(this._paused)return;let i=this.container;this._firstSpawn&&(this._firstSpawn=!1,this._currentSpawnDelay=this._spawnDelay??0,this._currentEmitDelay=this._emitDelay??0),this._startParticlesAdded||(this._startParticlesAdded=!0,this._emitParticles(this.options.startCount)),void 0!==this._duration&&(this._currentDuration+=t.value,this._currentDuration>=this._duration&&(this.pause(),void 0!==this._spawnDelay&&delete this._spawnDelay,!this._immortal&&this._lifeCount--,this._lifeCount>0||this._immortal?(this.position=this._calcPosition(),this._shape?.resize(this.position,this.size),this._spawnDelay=i.retina.reduceFactor?(0,s.getRangeValue)(this.options.life.delay??0)*s.millisecondsToSeconds/i.retina.reduceFactor:1/0):this._destroy(),this._currentDuration-=this._duration,delete this._duration)),void 0!==this._spawnDelay&&(this._currentSpawnDelay+=t.value,this._currentSpawnDelay>=this._spawnDelay&&(this._engine.dispatchEvent("emitterPlay",{container:this.container}),this.play(),this._currentSpawnDelay-=this._spawnDelay,delete this._spawnDelay)),void 0!==this._emitDelay&&(this._currentEmitDelay+=t.value,this._currentEmitDelay>=this._emitDelay&&(this._emit(),this._currentEmitDelay-=this._emitDelay))}_calcPosition(){let t=this.container;if(this.options.domId){let i=(0,s.safeDocument)().getElementById(this.options.domId);if(i){let e=i.getBoundingClientRect(),o=t.retina.pixelRatio;return{x:(e.x+e.width*s.half)*o,y:(e.y+e.height*s.half)*o}}}return(0,s.calcPositionOrRandomFromSizeRanged)({size:t.canvas.size,position:this.options.position})}_calcSize(){let t,i=this.container;if(this.options.domId){let t=(0,s.safeDocument)().getElementById(this.options.domId);if(t){let e=t.getBoundingClientRect();return{width:e.width*i.retina.pixelRatio,height:e.height*i.retina.pixelRatio,mode:s.PixelMode.precise}}}return this.options.size??((t=new n.G).load({height:0,mode:s.PixelMode.percent,width:0}),t)}_destroy=()=>{this._mutationObserver?.disconnect(),this._mutationObserver=void 0,this._resizeObserver?.disconnect(),this._resizeObserver=void 0,this.removeCallback(this),this._engine.dispatchEvent("emitterDestroyed",{container:this.container,data:{emitter:this}})};_emit(){if(this._paused)return;let t=(0,s.getRangeValue)(this.options.rate.quantity);this._emitParticles(t)}_emitParticles(t){let i=(0,s.itemFromSingleOrMultiple)(this._particlesOptions)??{},e=this.options.spawn.fill?.color.animation,o=this.options.spawn.fill?.enable??!!this.options.spawn.fill?.color,n=this.options.spawn.fill?.opacity===void 0?s.defaultOpacity:(0,s.getRangeValue)(this.options.spawn.fill.opacity),a=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,_=!!a,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=n,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;a&&w&&(this.spawnStrokeColor.h=this._setColorAnimation(a.h,this.spawnStrokeColor.h,w.h,3.6),this.spawnStrokeColor.s=this._setColorAnimation(a.s,this.spawnStrokeColor.s,w.s),this.spawnStrokeColor.l=this._setColorAnimation(a.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=a)=>{let n=this.container;if(!t.enable)return i;let l=(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+l*o)%e}}}}]);
package/803.min.js ADDED
@@ -0,0 +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)})}}}}]);
package/README.md CHANGED
@@ -26,6 +26,7 @@ Once the scripts are loaded you can set up `tsParticles` and the plugin like thi
26
26
 
27
27
  ```javascript
28
28
  (async () => {
29
+ await loadInteractivityPlugin(tsParticles);
29
30
  await loadEmittersPlugin(tsParticles);
30
31
 
31
32
  await tsParticles.load({
@@ -55,9 +56,11 @@ Then you need to import it in the app, like this:
55
56
 
56
57
  ```javascript
57
58
  const { tsParticles } = require("@tsparticles/engine");
59
+ const { loadInteractivityPlugin } = require("@tsparticles/plugin-interactivity");
58
60
  const { loadEmittersPlugin } = require("@tsparticles/plugin-emitters");
59
61
 
60
62
  (async () => {
63
+ await loadInteractivityPlugin(tsParticles);
61
64
  await loadEmittersPlugin(tsParticles);
62
65
  })();
63
66
  ```
@@ -66,9 +69,11 @@ or
66
69
 
67
70
  ```javascript
68
71
  import { tsParticles } from "@tsparticles/engine";
72
+ import { loadInteractivityPlugin } from "@tsparticles/plugin-interactivity";
69
73
  import { loadEmittersPlugin } from "@tsparticles/plugin-emitters";
70
74
 
71
75
  (async () => {
76
+ await loadInteractivityPlugin(tsParticles);
72
77
  await loadEmittersPlugin(tsParticles);
73
78
  })();
74
79
  ```
@@ -1,53 +1,54 @@
1
- import { PixelMode, Vector, calcPositionOrRandomFromSizeRanged, deepExtend, getRangeValue, getSize, hMax, half, isPointInside, itemFromSingleOrMultiple, lMax, millisecondsToSeconds, randomInRangeValue, rangeColorToHsl, sMax, safeDocument, } from "@tsparticles/engine";
1
+ import { AnimatableColor, Fill, PixelMode, Stroke, Vector, calcPositionOrRandomFromSizeRanged, deepExtend, defaultOpacity, 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, colorFactor = 3.6;
5
- function setParticlesOptionsColor(particlesOptions, color) {
6
- if (particlesOptions.color) {
7
- particlesOptions.color.value = color;
8
- }
9
- else {
10
- particlesOptions.color = {
11
- value: color,
12
- };
13
- }
4
+ const defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1, defaultColorAnimationFactor = 1, colorFactor = 3.6, defaultStrokeWidth = 1;
5
+ function setParticlesOptionsFillColor(particlesOptions, color, opacity, enable) {
6
+ particlesOptions.fill = new Fill();
7
+ particlesOptions.fill.color = AnimatableColor.create(undefined, { value: color });
8
+ particlesOptions.fill.enable = enable;
9
+ particlesOptions.fill.opacity = opacity;
10
+ }
11
+ function setParticlesOptionsStrokeColor(particlesOptions, color, opacity, width) {
12
+ particlesOptions.stroke = new Stroke();
13
+ particlesOptions.stroke.color = AnimatableColor.create(undefined, { value: color });
14
+ particlesOptions.stroke.opacity = opacity;
15
+ particlesOptions.stroke.width = width;
14
16
  }
15
17
  export class EmitterInstance {
18
+ container;
19
+ removeCallback;
20
+ fill;
21
+ name;
22
+ options;
23
+ position;
24
+ size;
25
+ spawnFillColor;
26
+ spawnFillEnabled;
27
+ spawnFillOpacity;
28
+ spawnStrokeColor;
29
+ spawnStrokeOpacity;
30
+ spawnStrokeWidth;
31
+ _currentDuration;
32
+ _currentEmitDelay;
33
+ _currentSpawnDelay;
34
+ _duration;
35
+ _emitDelay;
36
+ _engine;
37
+ _firstSpawn;
38
+ _immortal;
39
+ _initialPosition;
40
+ _lifeCount;
41
+ _mutationObserver;
42
+ _particlesOptions;
43
+ _paused;
44
+ _resizeObserver;
45
+ _shape;
46
+ _size;
47
+ _spawnDelay;
48
+ _startParticlesAdded;
16
49
  constructor(engine, container, removeCallback, options, position) {
17
50
  this.container = container;
18
51
  this.removeCallback = removeCallback;
19
- this._destroy = () => {
20
- this._mutationObserver?.disconnect();
21
- this._mutationObserver = undefined;
22
- this._resizeObserver?.disconnect();
23
- this._resizeObserver = undefined;
24
- this.removeCallback(this);
25
- this._engine.dispatchEvent("emitterDestroyed", {
26
- container: this.container,
27
- data: {
28
- emitter: this,
29
- },
30
- });
31
- };
32
- this._prepareToDie = () => {
33
- if (this._paused) {
34
- return;
35
- }
36
- const duration = this.options.life.duration !== undefined ? getRangeValue(this.options.life.duration) : undefined, minDuration = 0, minLifeCount = 0;
37
- if ((this._lifeCount > minLifeCount || this._immortal) && duration !== undefined && duration > minDuration) {
38
- this._duration = duration * millisecondsToSeconds;
39
- }
40
- };
41
- this._setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => {
42
- const container = this.container;
43
- if (!animation.enable) {
44
- return initValue;
45
- }
46
- const colorOffset = randomInRangeValue(animation.offset), delay = getRangeValue(this.options.rate.delay), emitFactor = container.retina.reduceFactor
47
- ? (delay * millisecondsToSeconds) / container.retina.reduceFactor
48
- : Infinity, colorSpeed = getRangeValue(animation.speed);
49
- return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * factor) % maxValue;
50
- };
51
52
  this._engine = engine;
52
53
  this._currentDuration = 0;
53
54
  this._currentEmitDelay = 0;
@@ -72,8 +73,11 @@ export class EmitterInstance {
72
73
  const particlesOptions = deepExtend({}, this.options.particles);
73
74
  particlesOptions.move ??= {};
74
75
  particlesOptions.move.direction ??= this.options.direction;
75
- if (this.options.spawnColor) {
76
- this.spawnColor = rangeColorToHsl(this._engine, this.options.spawnColor);
76
+ if (this.options.spawn.fill?.color) {
77
+ this.spawnFillColor = rangeColorToHsl(this._engine, this.options.spawn.fill.color);
78
+ }
79
+ if (this.options.spawn.stroke?.color) {
80
+ this.spawnStrokeColor = rangeColorToHsl(this._engine, this.options.spawn.stroke.color);
77
81
  }
78
82
  this._paused = !this.options.autoPlay;
79
83
  this._particlesOptions = particlesOptions;
@@ -99,7 +103,7 @@ export class EmitterInstance {
99
103
  }
100
104
  const shapeOptions = this.options.shape, shapeGenerator = this._engine.emitterShapeManager?.getShapeGenerator(shapeOptions.type);
101
105
  if (shapeGenerator) {
102
- this._shape = shapeGenerator.generate(this.position, this.size, this.fill, shapeOptions.options);
106
+ this._shape = shapeGenerator.generate(this.container, this.position, this.size, this.fill, shapeOptions.options);
103
107
  }
104
108
  this._engine.dispatchEvent("emitterCreated", {
105
109
  container,
@@ -201,7 +205,7 @@ export class EmitterInstance {
201
205
  container: this.container,
202
206
  });
203
207
  this.play();
204
- this._currentSpawnDelay -= this._currentSpawnDelay;
208
+ this._currentSpawnDelay -= this._spawnDelay;
205
209
  delete this._spawnDelay;
206
210
  }
207
211
  }
@@ -254,6 +258,19 @@ export class EmitterInstance {
254
258
  return size;
255
259
  })());
256
260
  }
261
+ _destroy = () => {
262
+ this._mutationObserver?.disconnect();
263
+ this._mutationObserver = undefined;
264
+ this._resizeObserver?.disconnect();
265
+ this._resizeObserver = undefined;
266
+ this.removeCallback(this);
267
+ this._engine.dispatchEvent("emitterDestroyed", {
268
+ container: this.container,
269
+ data: {
270
+ emitter: this,
271
+ },
272
+ });
273
+ };
257
274
  _emit() {
258
275
  if (this._paused) {
259
276
  return;
@@ -263,18 +280,36 @@ export class EmitterInstance {
263
280
  }
264
281
  _emitParticles(quantity) {
265
282
  const singleParticlesOptions = (itemFromSingleOrMultiple(this._particlesOptions) ??
266
- {}), 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;
283
+ {}), fillHslAnimation = this.options.spawn.fill?.color.animation, fillEnabled = this.options.spawn.fill?.enable ?? !!this.options.spawn.fill?.color, fillOpacity = this.options.spawn.fill?.opacity === undefined
284
+ ? defaultOpacity
285
+ : getRangeValue(this.options.spawn.fill.opacity), strokeHslAnimation = this.options.spawn.stroke?.color?.animation, strokeOpacity = this.options.spawn.stroke?.opacity === undefined
286
+ ? defaultOpacity
287
+ : getRangeValue(this.options.spawn.stroke.opacity), strokeWidth = this.options.spawn.stroke?.width === undefined
288
+ ? 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;
267
290
  for (let i = 0; i < quantity * reduceFactor; i++) {
268
291
  const particlesOptions = needsCopy
269
292
  ? deepExtend({}, singleParticlesOptions)
270
293
  : singleParticlesOptions;
271
- if (this.spawnColor) {
272
- if (hslAnimation && maxValues) {
273
- this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h, colorFactor);
274
- this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, maxValues.s);
275
- this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, maxValues.l);
294
+ this.spawnFillOpacity = fillOpacity;
295
+ this.spawnFillEnabled = fillEnabled;
296
+ this.spawnStrokeOpacity = strokeOpacity;
297
+ this.spawnStrokeWidth = strokeWidth;
298
+ if (this.spawnFillColor) {
299
+ if (fillHslAnimation && maxValues) {
300
+ this.spawnFillColor.h = this._setColorAnimation(fillHslAnimation.h, this.spawnFillColor.h, maxValues.h, colorFactor);
301
+ this.spawnFillColor.s = this._setColorAnimation(fillHslAnimation.s, this.spawnFillColor.s, maxValues.s);
302
+ this.spawnFillColor.l = this._setColorAnimation(fillHslAnimation.l, this.spawnFillColor.l, maxValues.l);
303
+ }
304
+ setParticlesOptionsFillColor(particlesOptions, this.spawnFillColor, this.spawnFillOpacity, this.spawnFillEnabled);
305
+ }
306
+ if (this.spawnStrokeColor) {
307
+ if (strokeHslAnimation && maxValues) {
308
+ this.spawnStrokeColor.h = this._setColorAnimation(strokeHslAnimation.h, this.spawnStrokeColor.h, maxValues.h, colorFactor);
309
+ this.spawnStrokeColor.s = this._setColorAnimation(strokeHslAnimation.s, this.spawnStrokeColor.s, maxValues.s);
310
+ this.spawnStrokeColor.l = this._setColorAnimation(strokeHslAnimation.l, this.spawnStrokeColor.l, maxValues.l);
276
311
  }
277
- setParticlesOptionsColor(particlesOptions, this.spawnColor);
312
+ setParticlesOptionsStrokeColor(particlesOptions, this.spawnStrokeColor, this.spawnStrokeOpacity, this.spawnStrokeWidth);
278
313
  }
279
314
  let position = this.position;
280
315
  if (this._shape) {
@@ -283,17 +318,7 @@ export class EmitterInstance {
283
318
  position = shapePosData.position;
284
319
  const replaceData = shapeOptions.replace;
285
320
  if (replaceData.color && shapePosData.color) {
286
- setParticlesOptionsColor(particlesOptions, shapePosData.color);
287
- }
288
- if (replaceData.opacity) {
289
- if (particlesOptions.opacity) {
290
- particlesOptions.opacity.value = shapePosData.opacity;
291
- }
292
- else {
293
- particlesOptions.opacity = {
294
- value: shapePosData.opacity,
295
- };
296
- }
321
+ setParticlesOptionsFillColor(particlesOptions, shapePosData.color, replaceData.opacity ? (shapePosData.opacity ?? defaultOpacity) : defaultOpacity, true);
297
322
  }
298
323
  }
299
324
  else {
@@ -305,4 +330,23 @@ export class EmitterInstance {
305
330
  }
306
331
  }
307
332
  }
333
+ _prepareToDie = () => {
334
+ if (this._paused) {
335
+ return;
336
+ }
337
+ const duration = this.options.life.duration !== undefined ? getRangeValue(this.options.life.duration) : undefined, minDuration = 0, minLifeCount = 0;
338
+ if ((this._lifeCount > minLifeCount || this._immortal) && duration !== undefined && duration > minDuration) {
339
+ this._duration = duration * millisecondsToSeconds;
340
+ }
341
+ };
342
+ _setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => {
343
+ const container = this.container;
344
+ if (!animation.enable) {
345
+ return initValue;
346
+ }
347
+ const colorOffset = randomInRangeValue(animation.offset), delay = getRangeValue(this.options.rate.delay), emitFactor = container.retina.reduceFactor
348
+ ? (delay * millisecondsToSeconds) / container.retina.reduceFactor
349
+ : Infinity, colorSpeed = getRangeValue(animation.speed);
350
+ return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * factor) % maxValue;
351
+ };
308
352
  }
@@ -1,4 +1,8 @@
1
1
  export class EmitterShapeBase {
2
+ fill;
3
+ options;
4
+ position;
5
+ size;
2
6
  constructor(position, size, fill, options) {
3
7
  this.position = position;
4
8
  this.size = size;
@@ -2,6 +2,8 @@ import { isNumber } from "@tsparticles/engine";
2
2
  import { Emitter } from "./Options/Classes/Emitter.js";
3
3
  const defaultIndex = 0;
4
4
  export class EmittersInstancesManager {
5
+ _containerArrays;
6
+ _engine;
5
7
  constructor(engine) {
6
8
  this._containerArrays = new Map();
7
9
  this._engine = engine;
@@ -4,9 +4,13 @@ import { Emitter } from "./Options/Classes/Emitter.js";
4
4
  import { defaultRandomOptions } from "./constants.js";
5
5
  const emittersMode = "emitters";
6
6
  export class EmittersInteractor extends ExternalInteractorBase {
7
+ handleClickMode;
8
+ maxDistance;
9
+ _instancesManager;
7
10
  constructor(instancesManager, container) {
8
11
  super(container);
9
12
  this._instancesManager = instancesManager;
13
+ this.maxDistance = 0;
10
14
  this.handleClickMode = (mode, interactivityData) => {
11
15
  const container = this.container, options = container.actualOptions, modeEmitters = options.interactivity.modes.emitters;
12
16
  if (!modeEmitters || mode !== emittersMode) {
@@ -77,7 +81,7 @@ export class EmittersInteractor extends ExternalInteractorBase {
77
81
  options.emitters.value.push(tmp);
78
82
  }
79
83
  }
80
- else if (Object.hasOwn(source.emitters, "value")) {
84
+ else if ("value" in source.emitters) {
81
85
  const emitterModeOptions = source.emitters;
82
86
  options.emitters.random.enable = emitterModeOptions.random?.enable ?? options.emitters.random.enable;
83
87
  options.emitters.random.count = emitterModeOptions.random?.count ?? options.emitters.random.count;
@@ -1,9 +1,10 @@
1
1
  import { executeOnSingleOrMultiple, isArray, } from "@tsparticles/engine";
2
2
  import { Emitter } from "./Options/Classes/Emitter.js";
3
3
  export class EmittersPlugin {
4
+ id = "emitters";
5
+ _instancesManager;
4
6
  constructor(instancesManager) {
5
7
  this._instancesManager = instancesManager;
6
- this.id = "emitters";
7
8
  }
8
9
  async getPlugin(container) {
9
10
  const { EmittersPluginInstance } = await import("./EmittersPluginInstance.js");
@@ -1,5 +1,7 @@
1
1
  import { isArray } from "@tsparticles/engine";
2
2
  export class EmittersPluginInstance {
3
+ container;
4
+ _instancesManager;
3
5
  constructor(instancesManager, container) {
4
6
  this.container = container;
5
7
  this._instancesManager = instancesManager;
@@ -3,13 +3,30 @@ import { EmitterLife } from "./EmitterLife.js";
3
3
  import { EmitterRate } from "./EmitterRate.js";
4
4
  import { EmitterShape } from "./EmitterShape.js";
5
5
  import { EmitterSize } from "./EmitterSize.js";
6
+ import { EmitterSpawn } from "./EmitterSpawn.js";
6
7
  export class Emitter {
8
+ autoPlay;
9
+ direction;
10
+ domId;
11
+ fill;
12
+ life;
13
+ name;
14
+ particles;
15
+ position;
16
+ rate;
17
+ shape;
18
+ size;
19
+ spawn;
20
+ spawnFillColor;
21
+ spawnStrokeColor;
22
+ startCount;
7
23
  constructor() {
8
24
  this.autoPlay = true;
9
25
  this.fill = true;
10
26
  this.life = new EmitterLife();
11
27
  this.rate = new EmitterRate();
12
28
  this.shape = new EmitterShape();
29
+ this.spawn = new EmitterSpawn();
13
30
  this.startCount = 0;
14
31
  }
15
32
  load(data) {
@@ -37,6 +54,7 @@ export class Emitter {
37
54
  });
38
55
  this.rate.load(data.rate);
39
56
  this.shape.load(data.shape);
57
+ this.spawn.load(data.spawn);
40
58
  if (data.position !== undefined) {
41
59
  this.position = {};
42
60
  if (data.position.x !== undefined) {
@@ -46,9 +64,13 @@ export class Emitter {
46
64
  this.position.y = setRangeValue(data.position.y);
47
65
  }
48
66
  }
49
- if (data.spawnColor !== undefined) {
50
- this.spawnColor ??= new AnimatableColor();
51
- this.spawnColor.load(data.spawnColor);
67
+ if (data.spawnFillColor !== undefined) {
68
+ this.spawnFillColor ??= new AnimatableColor();
69
+ this.spawnFillColor.load(data.spawnFillColor);
70
+ }
71
+ if (data.spawnStrokeColor !== undefined) {
72
+ this.spawnStrokeColor ??= new AnimatableColor();
73
+ this.spawnStrokeColor.load(data.spawnStrokeColor);
52
74
  }
53
75
  if (data.startCount !== undefined) {
54
76
  this.startCount = data.startCount;
@@ -1,5 +1,9 @@
1
1
  import { isNull, setRangeValue } from "@tsparticles/engine";
2
2
  export class EmitterLife {
3
+ count;
4
+ delay;
5
+ duration;
6
+ wait;
3
7
  constructor() {
4
8
  this.wait = false;
5
9
  }
@@ -1,5 +1,7 @@
1
1
  import { isNull, setRangeValue } from "@tsparticles/engine";
2
2
  export class EmitterRate {
3
+ delay;
4
+ quantity;
3
5
  constructor() {
4
6
  this.quantity = 1;
5
7
  this.delay = 0.1;
@@ -1,6 +1,9 @@
1
1
  import { deepExtend, isNull } from "@tsparticles/engine";
2
2
  import { EmitterShapeReplace } from "./EmitterShapeReplace.js";
3
3
  export class EmitterShape {
4
+ options;
5
+ replace;
6
+ type;
4
7
  constructor() {
5
8
  this.options = {};
6
9
  this.replace = new EmitterShapeReplace();
@@ -1,5 +1,7 @@
1
1
  import { isNull } from "@tsparticles/engine";
2
2
  export class EmitterShapeReplace {
3
+ color;
4
+ opacity;
3
5
  constructor() {
4
6
  this.color = false;
5
7
  this.opacity = false;
@@ -1,5 +1,8 @@
1
1
  import { PixelMode, isNull } from "@tsparticles/engine";
2
2
  export class EmitterSize {
3
+ height;
4
+ mode;
5
+ width;
3
6
  constructor() {
4
7
  this.mode = PixelMode.percent;
5
8
  this.height = 0;
@@ -0,0 +1,18 @@
1
+ import { Fill, Stroke, isNull } from "@tsparticles/engine";
2
+ export class EmitterSpawn {
3
+ fill;
4
+ stroke;
5
+ load(data) {
6
+ if (isNull(data)) {
7
+ return;
8
+ }
9
+ if (data.fill) {
10
+ this.fill ??= new Fill();
11
+ this.fill.load(data.fill);
12
+ }
13
+ if (data.stroke) {
14
+ this.stroke ??= new Stroke();
15
+ this.stroke.load(data.stroke);
16
+ }
17
+ }
18
+ }
@@ -0,0 +1 @@
1
+ export {};
package/browser/index.js CHANGED
@@ -1,8 +1,13 @@
1
1
  export async function loadEmittersPlugin(engine) {
2
- engine.checkVersion("4.0.0-alpha.5");
2
+ engine.checkVersion("4.0.0-beta.0");
3
3
  await engine.register(async (e) => {
4
- const { loadInteractivityPlugin } = await import("@tsparticles/plugin-interactivity"), { ShapeManager } = await import("./ShapeManager.js"), { EmittersInstancesManager } = await import("./EmittersInstancesManager.js"), { EmittersPlugin } = await import("./EmittersPlugin.js"), instancesManager = new EmittersInstancesManager(e);
5
- await loadInteractivityPlugin(e);
4
+ const [{ ensureInteractivityPluginLoaded }, { ShapeManager }, { EmittersInstancesManager }, { EmittersPlugin },] = await Promise.all([
5
+ import("@tsparticles/plugin-interactivity"),
6
+ import("./ShapeManager.js"),
7
+ import("./EmittersInstancesManager.js"),
8
+ import("./EmittersPlugin.js"),
9
+ ]), instancesManager = new EmittersInstancesManager(e);
10
+ ensureInteractivityPluginLoaded(e);
6
11
  e.emitterShapeManager ??= new ShapeManager();
7
12
  e.addEmitterShapeGenerator ??= (name, generator) => {
8
13
  e.emitterShapeManager?.addShapeGenerator(name, generator);
@@ -14,5 +19,10 @@ export async function loadEmittersPlugin(engine) {
14
19
  });
15
20
  });
16
21
  }
22
+ export function ensureEmittersPluginLoaded(e) {
23
+ if (!e.addEmitterShapeGenerator) {
24
+ throw new Error("tsParticles Emitters Plugin is not loaded");
25
+ }
26
+ }
17
27
  export * from "./EmitterShapeBase.js";
18
28
  export * from "./Enums/EmitterClickMode.js";