@tsparticles/plugin-emitters 3.0.0-alpha.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 (107) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +70 -0
  3. package/browser/EmitterContainer.js +1 -0
  4. package/browser/EmitterInstance.js +257 -0
  5. package/browser/Emitters.js +119 -0
  6. package/browser/EmittersEngine.js +1 -0
  7. package/browser/Enums/EmitterClickMode.js +1 -0
  8. package/browser/Enums/EmitterShapeType.js +1 -0
  9. package/browser/IEmitterShape.js +1 -0
  10. package/browser/Options/Classes/Emitter.js +62 -0
  11. package/browser/Options/Classes/EmitterLife.js +22 -0
  12. package/browser/Options/Classes/EmitterRate.js +18 -0
  13. package/browser/Options/Classes/EmitterSize.js +21 -0
  14. package/browser/Options/Interfaces/IEmitter.js +1 -0
  15. package/browser/Options/Interfaces/IEmitterLife.js +1 -0
  16. package/browser/Options/Interfaces/IEmitterRate.js +1 -0
  17. package/browser/Options/Interfaces/IEmitterSize.js +1 -0
  18. package/browser/ShapeManager.js +17 -0
  19. package/browser/Shapes/Circle/CircleShape.js +24 -0
  20. package/browser/Shapes/Square/SquareShape.js +40 -0
  21. package/browser/index.js +113 -0
  22. package/browser/types.js +1 -0
  23. package/cjs/EmitterContainer.js +2 -0
  24. package/cjs/EmitterInstance.js +261 -0
  25. package/cjs/Emitters.js +134 -0
  26. package/cjs/EmittersEngine.js +2 -0
  27. package/cjs/Enums/EmitterClickMode.js +2 -0
  28. package/cjs/Enums/EmitterShapeType.js +2 -0
  29. package/cjs/IEmitterShape.js +2 -0
  30. package/cjs/Options/Classes/Emitter.js +66 -0
  31. package/cjs/Options/Classes/EmitterLife.js +26 -0
  32. package/cjs/Options/Classes/EmitterRate.js +22 -0
  33. package/cjs/Options/Classes/EmitterSize.js +25 -0
  34. package/cjs/Options/Interfaces/IEmitter.js +2 -0
  35. package/cjs/Options/Interfaces/IEmitterLife.js +2 -0
  36. package/cjs/Options/Interfaces/IEmitterRate.js +2 -0
  37. package/cjs/Options/Interfaces/IEmitterSize.js +2 -0
  38. package/cjs/ShapeManager.js +21 -0
  39. package/cjs/Shapes/Circle/CircleShape.js +28 -0
  40. package/cjs/Shapes/Square/SquareShape.js +44 -0
  41. package/cjs/index.js +142 -0
  42. package/cjs/types.js +2 -0
  43. package/esm/EmitterContainer.js +1 -0
  44. package/esm/EmitterInstance.js +257 -0
  45. package/esm/Emitters.js +119 -0
  46. package/esm/EmittersEngine.js +1 -0
  47. package/esm/Enums/EmitterClickMode.js +1 -0
  48. package/esm/Enums/EmitterShapeType.js +1 -0
  49. package/esm/IEmitterShape.js +1 -0
  50. package/esm/Options/Classes/Emitter.js +62 -0
  51. package/esm/Options/Classes/EmitterLife.js +22 -0
  52. package/esm/Options/Classes/EmitterRate.js +18 -0
  53. package/esm/Options/Classes/EmitterSize.js +21 -0
  54. package/esm/Options/Interfaces/IEmitter.js +1 -0
  55. package/esm/Options/Interfaces/IEmitterLife.js +1 -0
  56. package/esm/Options/Interfaces/IEmitterRate.js +1 -0
  57. package/esm/Options/Interfaces/IEmitterSize.js +1 -0
  58. package/esm/ShapeManager.js +17 -0
  59. package/esm/Shapes/Circle/CircleShape.js +24 -0
  60. package/esm/Shapes/Square/SquareShape.js +40 -0
  61. package/esm/index.js +113 -0
  62. package/esm/types.js +1 -0
  63. package/package.json +81 -0
  64. package/report.html +39 -0
  65. package/tsparticles.plugin.emitters.js +794 -0
  66. package/tsparticles.plugin.emitters.min.js +2 -0
  67. package/tsparticles.plugin.emitters.min.js.LICENSE.txt +8 -0
  68. package/types/EmitterContainer.d.ts +12 -0
  69. package/types/EmitterInstance.d.ts +46 -0
  70. package/types/Emitters.d.ts +24 -0
  71. package/types/EmittersEngine.d.ts +7 -0
  72. package/types/Enums/EmitterClickMode.d.ts +3 -0
  73. package/types/Enums/EmitterShapeType.d.ts +4 -0
  74. package/types/IEmitterShape.d.ts +4 -0
  75. package/types/Options/Classes/Emitter.d.ts +24 -0
  76. package/types/Options/Classes/EmitterLife.d.ts +10 -0
  77. package/types/Options/Classes/EmitterRate.d.ts +8 -0
  78. package/types/Options/Classes/EmitterSize.d.ts +10 -0
  79. package/types/Options/Interfaces/IEmitter.d.ts +20 -0
  80. package/types/Options/Interfaces/IEmitterLife.d.ts +6 -0
  81. package/types/Options/Interfaces/IEmitterRate.d.ts +5 -0
  82. package/types/Options/Interfaces/IEmitterSize.d.ts +4 -0
  83. package/types/ShapeManager.d.ts +9 -0
  84. package/types/Shapes/Circle/CircleShape.d.ts +5 -0
  85. package/types/Shapes/Square/SquareShape.d.ts +5 -0
  86. package/types/index.d.ts +6 -0
  87. package/types/types.d.ts +31 -0
  88. package/umd/EmitterContainer.js +12 -0
  89. package/umd/EmitterInstance.js +271 -0
  90. package/umd/Emitters.js +133 -0
  91. package/umd/EmittersEngine.js +12 -0
  92. package/umd/Enums/EmitterClickMode.js +12 -0
  93. package/umd/Enums/EmitterShapeType.js +12 -0
  94. package/umd/IEmitterShape.js +12 -0
  95. package/umd/Options/Classes/Emitter.js +76 -0
  96. package/umd/Options/Classes/EmitterLife.js +36 -0
  97. package/umd/Options/Classes/EmitterRate.js +32 -0
  98. package/umd/Options/Classes/EmitterSize.js +35 -0
  99. package/umd/Options/Interfaces/IEmitter.js +12 -0
  100. package/umd/Options/Interfaces/IEmitterLife.js +12 -0
  101. package/umd/Options/Interfaces/IEmitterRate.js +12 -0
  102. package/umd/Options/Interfaces/IEmitterSize.js +12 -0
  103. package/umd/ShapeManager.js +31 -0
  104. package/umd/Shapes/Circle/CircleShape.js +38 -0
  105. package/umd/Shapes/Square/SquareShape.js +54 -0
  106. package/umd/index.js +141 -0
  107. package/umd/types.js +12 -0
@@ -0,0 +1,2 @@
1
+ /*! For license information please see tsparticles.plugin.emitters.min.js.LICENSE.txt */
2
+ !function(t,i){if("object"==typeof exports&&"object"==typeof module)module.exports=i(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],i);else{var e="object"==typeof exports?i(require("@tsparticles/engine")):i(t.window);for(var s in e)("object"==typeof exports?exports:t)[s]=e[s]}}(this,(t=>(()=>{"use strict";var i={533:i=>{i.exports=t}},e={};function s(t){var n=e[t];if(void 0!==n)return n.exports;var o=e[t]={exports:{}};return i[t](o,o.exports,s),o.exports}s.d=(t,i)=>{for(var e in i)s.o(i,e)&&!s.o(t,e)&&Object.defineProperty(t,e,{enumerable:!0,get:i[e]})},s.o=(t,i)=>Object.prototype.hasOwnProperty.call(t,i),s.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{s.r(n),s.d(n,{loadEmittersPlugin:()=>v});var t=s(533);class i{randomPosition(i,e,s){const[n,o]=[e.width/2,e.height/2],a=((i,e)=>{const s=(0,t.getRandom)()/4,n=Math.atan(e/i*Math.tan(2*Math.PI*s)),o=(0,t.getRandom)();return o<.25?n:o<.5?Math.PI-n:o<.75?Math.PI+n:-n})(n,o),r=(c=a,(h=n)*(d=o)/Math.sqrt((d*Math.cos(c))**2+(h*Math.sin(c))**2)),l=s?r*Math.sqrt((0,t.getRandom)()):r;var h,d,c;return{x:i.x+l*Math.cos(a),y:i.y+l*Math.sin(a)}}}class e{constructor(){this.wait=!1}load(t){void 0!==t&&(void 0!==t.count&&(this.count=t.count),void 0!==t.delay&&(this.delay=t.delay),void 0!==t.duration&&(this.duration=t.duration),void 0!==t.wait&&(this.wait=t.wait))}}class o{constructor(){this.quantity=1,this.delay=.1}load(i){void 0!==i&&(void 0!==i.quantity&&(this.quantity=(0,t.setRangeValue)(i.quantity)),void 0!==i.delay&&(this.delay=(0,t.setRangeValue)(i.delay)))}}class a{constructor(){this.mode="percent",this.height=0,this.width=0}load(t){void 0!==t&&(void 0!==t.mode&&(this.mode=t.mode),void 0!==t.height&&(this.height=t.height),void 0!==t.width&&(this.width=t.width))}}class r{constructor(){this.autoPlay=!0,this.fill=!0,this.life=new e,this.rate=new o,this.shape="square",this.startCount=0}load(i){void 0!==i&&(void 0!==i.autoPlay&&(this.autoPlay=i.autoPlay),void 0!==i.size&&(void 0===this.size&&(this.size=new a),this.size.load(i.size)),void 0!==i.direction&&(this.direction=i.direction),this.domId=i.domId,void 0!==i.fill&&(this.fill=i.fill),this.life.load(i.life),this.name=i.name,this.particles=(0,t.executeOnSingleOrMultiple)(i.particles,(i=>(0,t.deepExtend)({},i))),this.rate.load(i.rate),void 0!==i.shape&&(this.shape=i.shape),void 0!==i.position&&(this.position={},void 0!==i.position.x&&(this.position.x=(0,t.setRangeValue)(i.position.x)),void 0!==i.position.y&&(this.position.y=(0,t.setRangeValue)(i.position.y))),void 0!==i.spawnColor&&(void 0===this.spawnColor&&(this.spawnColor=new t.AnimatableColor),this.spawnColor.load(i.spawnColor)),void 0!==i.startCount&&(this.startCount=i.startCount))}}class l{constructor(i,e,s,n,o){var l,h,d,c,u,p,m,v;this.emitters=e,this.container=s,this._engine=i,this._currentDuration=0,this._currentEmitDelay=0,this._currentSpawnDelay=0,this._initialPosition=o,n instanceof r?this.options=n:(this.options=new r,this.options.load(n)),this._spawnDelay=1e3*(null!==(l=this.options.life.delay)&&void 0!==l?l:0)/this.container.retina.reduceFactor,this.position=null!==(h=this._initialPosition)&&void 0!==h?h:this.calcPosition(),this.name=this.options.name,this._shape=null===(d=this._engine.emitterShapeManager)||void 0===d?void 0:d.getShape(this.options.shape),this.fill=this.options.fill,this._firstSpawn=!this.options.life.wait,this._startParticlesAdded=!1;let y=(0,t.deepExtend)({},this.options.particles);null!=y||(y={}),null!==(c=y.move)&&void 0!==c||(y.move={}),null!==(u=(v=y.move).direction)&&void 0!==u||(v.direction=this.options.direction),this.options.spawnColor&&(this.spawnColor=(0,t.rangeColorToHsl)(this.options.spawnColor)),this._paused=!this.options.autoPlay,this._particlesOptions=y,this.size=null!==(p=this.options.size)&&void 0!==p?p:(()=>{const t=new a;return t.load({height:0,mode:"percent",width:0}),t})(),this._lifeCount=null!==(m=this.options.life.count)&&void 0!==m?m:-1,this._immortal=this._lifeCount<=0,this._engine.dispatchEvent("emitterCreated",{container:s,data:{emitter:this}}),this.play()}externalPause(){this._paused=!0,this.pause()}externalPlay(){this._paused=!1,this.play()}getPosition(){if(this.options.domId){const t=this.container,i=document.getElementById(this.options.domId);if(i){const e=i.getBoundingClientRect();return{x:(e.x+e.width/2)*t.retina.pixelRatio,y:(e.y+e.height/2)*t.retina.pixelRatio}}}return this.position}getSize(){const t=this.container;if(this.options.domId){const i=document.getElementById(this.options.domId);if(i){const e=i.getBoundingClientRect();return{width:e.width*t.retina.pixelRatio,height:e.height*t.retina.pixelRatio}}}return{width:"percent"===this.size.mode?t.canvas.size.width*this.size.width/100:this.size.width,height:"percent"===this.size.mode?t.canvas.size.height*this.size.height/100:this.size.height}}pause(){this._paused||delete this._emitDelay}play(){var i;if(!this._paused&&this.container.retina.reduceFactor&&(this._lifeCount>0||this._immortal||!this.options.life.count)&&(this._firstSpawn||this._currentSpawnDelay>=(null!==(i=this._spawnDelay)&&void 0!==i?i:0))){if(void 0===this._emitDelay){const i=(0,t.getRangeValue)(this.options.rate.delay);this._emitDelay=1e3*i/this.container.retina.reduceFactor}(this._lifeCount>0||this._immortal)&&this.prepareToDie()}}resize(){const i=this._initialPosition;this.position=i&&(0,t.isPointInside)(i,this.container.canvas.size,t.Vector.origin)?i:this.calcPosition()}update(t){var i,e,s;this._paused||(this._firstSpawn&&(this._firstSpawn=!1,this._currentSpawnDelay=null!==(i=this._spawnDelay)&&void 0!==i?i:0,this._currentEmitDelay=null!==(e=this._emitDelay)&&void 0!==e?e: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._spawnDelay=1e3*(null!==(s=this.options.life.delay)&&void 0!==s?s:0)/this.container.retina.reduceFactor):this.destroy(),this._currentDuration-=this._duration,delete this._duration)),void 0!==this._spawnDelay&&(this._currentSpawnDelay+=t.value,this._currentSpawnDelay>=this._spawnDelay&&(this._engine.dispatchEvent("emitterPlay",{container:this.container}),this.play(),this._currentSpawnDelay-=this._currentSpawnDelay,delete this._spawnDelay)),void 0!==this._emitDelay&&(this._currentEmitDelay+=t.value,this._currentEmitDelay>=this._emitDelay&&(this.emit(),this._currentEmitDelay-=this._emitDelay)))}calcPosition(){return(0,t.calcPositionOrRandomFromSizeRanged)({size:this.container.canvas.size,position:this.options.position})}destroy(){this.emitters.removeEmitter(this),this._engine.dispatchEvent("emitterDestroyed",{container:this.container,data:{emitter:this}})}emit(){if(this._paused)return;const i=(0,t.getRangeValue)(this.options.rate.quantity);this.emitParticles(i)}emitParticles(i){var e,s,n;const o=this.getPosition(),a=this.getSize(),r=(0,t.itemFromSingleOrMultiple)(this._particlesOptions);for(let l=0;l<i;l++){const i=(0,t.deepExtend)({},r);if(this.spawnColor){const t=null===(e=this.options.spawnColor)||void 0===e?void 0:e.animation;t&&(this.spawnColor.h=this.setColorAnimation(t.h,this.spawnColor.h,360),this.spawnColor.s=this.setColorAnimation(t.s,this.spawnColor.s,100),this.spawnColor.l=this.setColorAnimation(t.l,this.spawnColor.l,100)),i.color?i.color.value=this.spawnColor:i.color={value:this.spawnColor}}if(!o)return;const l=null!==(n=null===(s=this._shape)||void 0===s?void 0:s.randomPosition(o,a,this.fill))&&void 0!==n?n:o;this.container.particles.addParticle(l,i)}}prepareToDie(){var t;if(this._paused)return;const i=null===(t=this.options.life)||void 0===t?void 0:t.duration;this.container.retina.reduceFactor&&(this._lifeCount>0||this._immortal)&&void 0!==i&&i>0&&(this._duration=1e3*i)}setColorAnimation(i,e,s){var n;const o=this.container;if(!i.enable)return e;const a=(0,t.randomInRange)(i.offset),r=1e3*(0,t.getRangeValue)(this.options.rate.delay)/o.retina.reduceFactor;return(e+(0,t.getRangeValue)(null!==(n=i.speed)&&void 0!==n?n:0)*o.fpsLimit/r+3.6*a)%s}}class h{constructor(t,i){this.container=i,this._engine=t,this.array=[],this.emitters=[],this.interactivityEmitters={random:{count:1,enable:!1},value:[]},i.getEmitter=t=>void 0===t||"number"==typeof t?this.array[t||0]:this.array.find((i=>i.name===t)),i.addEmitter=(t,i)=>this.addEmitter(t,i),i.removeEmitter=t=>{const e=i.getEmitter(t);e&&this.removeEmitter(e)},i.playEmitter=t=>{const e=i.getEmitter(t);e&&e.externalPlay()},i.pauseEmitter=t=>{const e=i.getEmitter(t);e&&e.externalPause()}}addEmitter(t,i){const e=new r;e.load(t);const s=new l(this._engine,this,this.container,e,i);return this.array.push(s),s}handleClickMode(i){const e=this.emitters,s=this.interactivityEmitters;if("emitter"===i){let i;if(s&&s.value instanceof Array)if(s.value.length>0&&s.random.enable){i=[];const e=[];for(let n=0;n<s.random.count;n++){const o=(0,t.arrayRandomIndex)(s.value);e.includes(o)&&e.length<s.value.length?n--:(e.push(o),i.push((0,t.itemFromArray)(s.value,o)))}}else i=s.value;else i=null==s?void 0:s.value;const n=null!=i?i:e,o=this.container.interactivity.mouse.clickPosition;(0,t.executeOnSingleOrMultiple)(n,(t=>{this.addEmitter(t,o)}))}}async init(){if(this.emitters=this.container.actualOptions.emitters,this.interactivityEmitters=this.container.actualOptions.interactivity.modes.emitters,this.emitters instanceof Array)for(const t of this.emitters)this.addEmitter(t);else this.addEmitter(this.emitters)}pause(){for(const t of this.array)t.pause()}play(){for(const t of this.array)t.play()}removeEmitter(t){const i=this.array.indexOf(t);i>=0&&this.array.splice(i,1)}resize(){for(const t of this.array)t.resize()}stop(){this.array=[]}update(t){for(const i of this.array)i.update(t)}}const d=new Map;class c{constructor(t){this._engine=t}addShape(t,i){this.getShape(t)||d.set(t,i)}getShape(t){return d.get(t)}getSupportedShapes(){return d.keys()}}function u(i,e){return i+e*((0,t.getRandom)()-.5)}class p{randomPosition(i,e,s){if(s)return{x:u(i.x,e.width),y:u(i.y,e.height)};{const s=e.width/2,n=e.height/2,o=Math.floor(4*(0,t.getRandom)()),a=2*((0,t.getRandom)()-.5);switch(o){case 0:return{x:i.x+a*s,y:i.y-n};case 1:return{x:i.x-s,y:i.y+a*n};case 2:return{x:i.x+a*s,y:i.y+n};default:return{x:i.x+s,y:i.y+a*n}}}}}class m{constructor(t){this._engine=t,this.id="emitters"}getPlugin(t){return new h(this._engine,t)}loadOptions(i,e){var s,n,o,a,l,h;if(!this.needsPlugin(i)&&!this.needsPlugin(e))return;(null==e?void 0:e.emitters)&&(i.emitters=(0,t.executeOnSingleOrMultiple)(e.emitters,(t=>{const i=new r;return i.load(t),i})));const d=null===(n=null===(s=null==e?void 0:e.interactivity)||void 0===s?void 0:s.modes)||void 0===n?void 0:n.emitters;if(d)if(d instanceof Array)i.interactivity.modes.emitters={random:{count:1,enable:!0},value:d.map((t=>{const i=new r;return i.load(t),i}))};else{const t=d;if(void 0!==t.value)if(t.value instanceof Array)i.interactivity.modes.emitters={random:{count:null!==(o=t.random.count)&&void 0!==o?o:1,enable:null!==(a=t.random.enable)&&void 0!==a&&a},value:t.value.map((t=>{const i=new r;return i.load(t),i}))};else{const e=new r;e.load(t.value),i.interactivity.modes.emitters={random:{count:null!==(l=t.random.count)&&void 0!==l?l:1,enable:null!==(h=t.random.enable)&&void 0!==h&&h},value:e}}else{(i.interactivity.modes.emitters={random:{count:1,enable:!1},value:new r}).value.load(d)}}}needsPlugin(i){var e,s,n;if(!i)return!1;const o=i.emitters;return o instanceof Array&&!!o.length||void 0!==o||!!(null===(n=null===(s=null===(e=i.interactivity)||void 0===e?void 0:e.events)||void 0===s?void 0:s.onClick)||void 0===n?void 0:n.mode)&&(0,t.isInArray)("emitter",i.interactivity.events.onClick.mode)}}async function v(t){t.emitterShapeManager||(t.emitterShapeManager=new c(t)),t.addEmitterShape||(t.addEmitterShape=(i,e)=>{var s;null===(s=t.emitterShapeManager)||void 0===s||s.addShape(i,e)});const e=new m(t);await t.addPlugin(e),t.addEmitterShape("circle",new i),t.addEmitterShape("square",new p)}})(),n})()));
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * Author : Matteo Bruni
3
+ * MIT license: https://opensource.org/licenses/MIT
4
+ * Demo / Generator : https://particles.js.org/
5
+ * GitHub : https://www.github.com/matteobruni/tsparticles
6
+ * How to use? : Check the GitHub README
7
+ * v3.0.0-alpha.0
8
+ */
@@ -0,0 +1,12 @@
1
+ import type { Container, ICoordinates, RecursivePartial } from "@tsparticles/engine";
2
+ import type { EmitterInstance } from "./EmitterInstance";
3
+ import type { EmitterOptions } from "./types";
4
+ import type { IEmitter } from "./Options/Interfaces/IEmitter";
5
+ export type EmitterContainer = Container & {
6
+ actualOptions: EmitterOptions;
7
+ addEmitter: (options: RecursivePartial<IEmitter>, position?: ICoordinates) => EmitterInstance;
8
+ getEmitter: (idxOrName?: number | string) => EmitterInstance | undefined;
9
+ pauseEmitter: (idxOrName?: number | string) => void;
10
+ playEmitter: (idxOrName?: number | string) => void;
11
+ removeEmitter: (idxOrName?: number | string) => void;
12
+ };
@@ -0,0 +1,46 @@
1
+ import type { Container, ICoordinates, IDelta, IDimension, IHsl, RecursivePartial } from "@tsparticles/engine";
2
+ import { Emitter } from "./Options/Classes/Emitter";
3
+ import type { Emitters } from "./Emitters";
4
+ import type { EmittersEngine } from "./EmittersEngine";
5
+ import type { IEmitter } from "./Options/Interfaces/IEmitter";
6
+ import type { IEmitterSize } from "./Options/Interfaces/IEmitterSize";
7
+ export declare class EmitterInstance {
8
+ private readonly emitters;
9
+ private readonly container;
10
+ fill: boolean;
11
+ readonly name?: string;
12
+ options: Emitter;
13
+ position?: ICoordinates;
14
+ size: IEmitterSize;
15
+ spawnColor?: IHsl;
16
+ private _currentDuration;
17
+ private _currentEmitDelay;
18
+ private _currentSpawnDelay;
19
+ private _duration?;
20
+ private _emitDelay?;
21
+ private readonly _engine;
22
+ private _firstSpawn;
23
+ private readonly _immortal;
24
+ private readonly _initialPosition?;
25
+ private _lifeCount;
26
+ private readonly _particlesOptions;
27
+ private _paused;
28
+ private readonly _shape?;
29
+ private _spawnDelay?;
30
+ private _startParticlesAdded;
31
+ constructor(engine: EmittersEngine, emitters: Emitters, container: Container, options: RecursivePartial<IEmitter>, position?: ICoordinates);
32
+ externalPause(): void;
33
+ externalPlay(): void;
34
+ getPosition(): ICoordinates | undefined;
35
+ getSize(): IDimension;
36
+ pause(): void;
37
+ play(): void;
38
+ resize(): void;
39
+ update(delta: IDelta): void;
40
+ private calcPosition;
41
+ private destroy;
42
+ private emit;
43
+ private emitParticles;
44
+ private prepareToDie;
45
+ private setColorAnimation;
46
+ }
@@ -0,0 +1,24 @@
1
+ import type { IContainerPlugin, ICoordinates, IDelta, RecursivePartial, SingleOrMultiple } from "@tsparticles/engine";
2
+ import { Emitter } from "./Options/Classes/Emitter";
3
+ import type { EmitterContainer } from "./EmitterContainer";
4
+ import { EmitterInstance } from "./EmitterInstance";
5
+ import type { EmitterModeOptions } from "./types";
6
+ import type { EmittersEngine } from "./EmittersEngine";
7
+ import type { IEmitter } from "./Options/Interfaces/IEmitter";
8
+ export declare class Emitters implements IContainerPlugin {
9
+ private readonly container;
10
+ array: EmitterInstance[];
11
+ emitters: SingleOrMultiple<Emitter>;
12
+ interactivityEmitters: EmitterModeOptions;
13
+ private readonly _engine;
14
+ constructor(engine: EmittersEngine, container: EmitterContainer);
15
+ addEmitter(options: RecursivePartial<IEmitter>, position?: ICoordinates): EmitterInstance;
16
+ handleClickMode(mode: string): void;
17
+ init(): Promise<void>;
18
+ pause(): void;
19
+ play(): void;
20
+ removeEmitter(emitter: EmitterInstance): void;
21
+ resize(): void;
22
+ stop(): void;
23
+ update(delta: IDelta): void;
24
+ }
@@ -0,0 +1,7 @@
1
+ import type { Engine } from "@tsparticles/engine";
2
+ import type { IEmitterShape } from "./IEmitterShape";
3
+ import type { ShapeManager } from "./ShapeManager";
4
+ export type EmittersEngine = Engine & {
5
+ addEmitterShape?: (name: string, shape: IEmitterShape) => void;
6
+ emitterShapeManager?: ShapeManager;
7
+ };
@@ -0,0 +1,3 @@
1
+ export declare const enum EmitterClickMode {
2
+ emitter = "emitter"
3
+ }
@@ -0,0 +1,4 @@
1
+ export declare const enum EmitterShapeType {
2
+ circle = "circle",
3
+ square = "square"
4
+ }
@@ -0,0 +1,4 @@
1
+ import type { ICoordinates, IDimension } from "@tsparticles/engine";
2
+ export interface IEmitterShape {
3
+ randomPosition(position: ICoordinates, size: IDimension, fill: boolean): ICoordinates;
4
+ }
@@ -0,0 +1,24 @@
1
+ import { AnimatableColor } from "@tsparticles/engine";
2
+ import type { IOptionLoader, IParticlesOptions, IRangedCoordinates, MoveDirection, MoveDirectionAlt, RecursivePartial, SingleOrMultiple } from "@tsparticles/engine";
3
+ import { EmitterLife } from "./EmitterLife";
4
+ import { EmitterRate } from "./EmitterRate";
5
+ import { EmitterShapeType } from "../../Enums/EmitterShapeType";
6
+ import { EmitterSize } from "./EmitterSize";
7
+ import type { IEmitter } from "../Interfaces/IEmitter";
8
+ export declare class Emitter implements IEmitter, IOptionLoader<IEmitter> {
9
+ autoPlay: boolean;
10
+ direction?: MoveDirection | keyof typeof MoveDirection | MoveDirectionAlt | number;
11
+ domId?: string;
12
+ fill: boolean;
13
+ life: EmitterLife;
14
+ name?: string;
15
+ particles?: SingleOrMultiple<RecursivePartial<IParticlesOptions>>;
16
+ position?: RecursivePartial<IRangedCoordinates>;
17
+ rate: EmitterRate;
18
+ shape: EmitterShapeType | keyof typeof EmitterShapeType;
19
+ size?: EmitterSize;
20
+ spawnColor?: AnimatableColor;
21
+ startCount: number;
22
+ constructor();
23
+ load(data?: RecursivePartial<IEmitter>): void;
24
+ }
@@ -0,0 +1,10 @@
1
+ import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
2
+ import type { IEmitterLife } from "../Interfaces/IEmitterLife";
3
+ export declare class EmitterLife implements IEmitterLife, IOptionLoader<IEmitterLife> {
4
+ count?: number;
5
+ delay?: number;
6
+ duration?: number;
7
+ wait: boolean;
8
+ constructor();
9
+ load(data?: RecursivePartial<IEmitterLife>): void;
10
+ }
@@ -0,0 +1,8 @@
1
+ import type { IOptionLoader, RangeValue, RecursivePartial } from "@tsparticles/engine";
2
+ import type { IEmitterRate } from "../Interfaces/IEmitterRate";
3
+ export declare class EmitterRate implements IEmitterRate, IOptionLoader<IEmitterRate> {
4
+ delay: RangeValue;
5
+ quantity: RangeValue;
6
+ constructor();
7
+ load(data?: RecursivePartial<IEmitterRate>): void;
8
+ }
@@ -0,0 +1,10 @@
1
+ import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
2
+ import type { IEmitterSize } from "../Interfaces/IEmitterSize";
3
+ import { SizeMode } from "@tsparticles/engine";
4
+ export declare class EmitterSize implements IEmitterSize, IOptionLoader<IEmitterSize> {
5
+ height: number;
6
+ mode: SizeMode | keyof typeof SizeMode;
7
+ width: number;
8
+ constructor();
9
+ load(data?: RecursivePartial<IEmitterSize>): void;
10
+ }
@@ -0,0 +1,20 @@
1
+ import type { IAnimatableColor, IParticlesOptions, IRangedCoordinates, MoveDirection, MoveDirectionAlt, RecursivePartial, SingleOrMultiple } from "@tsparticles/engine";
2
+ import type { EmitterShapeType } from "../../Enums/EmitterShapeType";
3
+ import type { IEmitterLife } from "./IEmitterLife";
4
+ import type { IEmitterRate } from "./IEmitterRate";
5
+ import type { IEmitterSize } from "./IEmitterSize";
6
+ export interface IEmitter {
7
+ autoPlay: boolean;
8
+ direction?: MoveDirection | keyof typeof MoveDirection | MoveDirectionAlt | number;
9
+ domId?: string;
10
+ fill: boolean;
11
+ life: IEmitterLife;
12
+ name?: string;
13
+ particles?: SingleOrMultiple<RecursivePartial<IParticlesOptions>>;
14
+ position?: RecursivePartial<IRangedCoordinates>;
15
+ rate: IEmitterRate;
16
+ shape: EmitterShapeType | keyof typeof EmitterShapeType;
17
+ size?: IEmitterSize;
18
+ spawnColor?: IAnimatableColor;
19
+ startCount: number;
20
+ }
@@ -0,0 +1,6 @@
1
+ export interface IEmitterLife {
2
+ count?: number;
3
+ delay?: number;
4
+ duration?: number;
5
+ wait: boolean;
6
+ }
@@ -0,0 +1,5 @@
1
+ import type { RangeValue } from "@tsparticles/engine";
2
+ export interface IEmitterRate {
3
+ delay: RangeValue;
4
+ quantity: RangeValue;
5
+ }
@@ -0,0 +1,4 @@
1
+ import type { IDimension, SizeMode } from "@tsparticles/engine";
2
+ export interface IEmitterSize extends IDimension {
3
+ mode: SizeMode | keyof typeof SizeMode;
4
+ }
@@ -0,0 +1,9 @@
1
+ import type { Engine } from "@tsparticles/engine";
2
+ import type { IEmitterShape } from "./IEmitterShape";
3
+ export declare class ShapeManager {
4
+ private readonly _engine;
5
+ constructor(engine: Engine);
6
+ addShape(name: string, drawer: IEmitterShape): void;
7
+ getShape(name: string): IEmitterShape | undefined;
8
+ getSupportedShapes(): IterableIterator<string>;
9
+ }
@@ -0,0 +1,5 @@
1
+ import type { ICoordinates, IDimension } from "@tsparticles/engine";
2
+ import type { IEmitterShape } from "../../IEmitterShape";
3
+ export declare class CircleShape implements IEmitterShape {
4
+ randomPosition(position: ICoordinates, size: IDimension, fill: boolean): ICoordinates;
5
+ }
@@ -0,0 +1,5 @@
1
+ import type { ICoordinates, IDimension } from "@tsparticles/engine";
2
+ import type { IEmitterShape } from "../../IEmitterShape";
3
+ export declare class SquareShape implements IEmitterShape {
4
+ randomPosition(position: ICoordinates, size: IDimension, fill: boolean): ICoordinates;
5
+ }
@@ -0,0 +1,6 @@
1
+ import type { EmittersEngine } from "./EmittersEngine";
2
+ export declare function loadEmittersPlugin(engine: EmittersEngine): Promise<void>;
3
+ export * from "./EmitterContainer";
4
+ export * from "./EmittersEngine";
5
+ export * from "./Enums/EmitterClickMode";
6
+ export * from "./Enums/EmitterShapeType";
@@ -0,0 +1,31 @@
1
+ import type { IOptions, Options, SingleOrMultiple } from "@tsparticles/engine";
2
+ import type { Emitter } from "./Options/Classes/Emitter";
3
+ import type { IEmitter } from "./Options/Interfaces/IEmitter";
4
+ export interface IEmitterModeOptions {
5
+ random: IEmitterModeRandomOptions;
6
+ value: SingleOrMultiple<IEmitter>;
7
+ }
8
+ export interface IEmitterModeRandomOptions {
9
+ count: number;
10
+ enable: boolean;
11
+ }
12
+ export interface EmitterModeOptions {
13
+ random: IEmitterModeRandomOptions;
14
+ value: SingleOrMultiple<Emitter>;
15
+ }
16
+ export type IEmitterOptions = IOptions & {
17
+ emitters: SingleOrMultiple<IEmitter>;
18
+ interactivity: {
19
+ modes: {
20
+ emitters: IEmitterModeOptions | SingleOrMultiple<IEmitter>;
21
+ };
22
+ };
23
+ };
24
+ export type EmitterOptions = Options & {
25
+ emitters: SingleOrMultiple<Emitter>;
26
+ interactivity: {
27
+ modes: {
28
+ emitters: EmitterModeOptions;
29
+ };
30
+ };
31
+ };
@@ -0,0 +1,12 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ });
@@ -0,0 +1,271 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "@tsparticles/engine", "./Options/Classes/Emitter", "./Options/Classes/EmitterSize"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.EmitterInstance = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ const Emitter_1 = require("./Options/Classes/Emitter");
15
+ const EmitterSize_1 = require("./Options/Classes/EmitterSize");
16
+ class EmitterInstance {
17
+ constructor(engine, emitters, container, options, position) {
18
+ var _a, _b, _c, _d, _e, _f, _g;
19
+ var _h;
20
+ this.emitters = emitters;
21
+ this.container = container;
22
+ this._engine = engine;
23
+ this._currentDuration = 0;
24
+ this._currentEmitDelay = 0;
25
+ this._currentSpawnDelay = 0;
26
+ this._initialPosition = position;
27
+ if (options instanceof Emitter_1.Emitter) {
28
+ this.options = options;
29
+ }
30
+ else {
31
+ this.options = new Emitter_1.Emitter();
32
+ this.options.load(options);
33
+ }
34
+ this._spawnDelay = (((_a = this.options.life.delay) !== null && _a !== void 0 ? _a : 0) * 1000) / this.container.retina.reduceFactor;
35
+ this.position = (_b = this._initialPosition) !== null && _b !== void 0 ? _b : this.calcPosition();
36
+ this.name = this.options.name;
37
+ this._shape = (_c = this._engine.emitterShapeManager) === null || _c === void 0 ? void 0 : _c.getShape(this.options.shape);
38
+ this.fill = this.options.fill;
39
+ this._firstSpawn = !this.options.life.wait;
40
+ this._startParticlesAdded = false;
41
+ let particlesOptions = (0, engine_1.deepExtend)({}, this.options.particles);
42
+ particlesOptions !== null && particlesOptions !== void 0 ? particlesOptions : (particlesOptions = {});
43
+ (_d = particlesOptions.move) !== null && _d !== void 0 ? _d : (particlesOptions.move = {});
44
+ (_e = (_h = particlesOptions.move).direction) !== null && _e !== void 0 ? _e : (_h.direction = this.options.direction);
45
+ if (this.options.spawnColor) {
46
+ this.spawnColor = (0, engine_1.rangeColorToHsl)(this.options.spawnColor);
47
+ }
48
+ this._paused = !this.options.autoPlay;
49
+ this._particlesOptions = particlesOptions;
50
+ this.size =
51
+ (_f = this.options.size) !== null && _f !== void 0 ? _f : (() => {
52
+ const size = new EmitterSize_1.EmitterSize();
53
+ size.load({
54
+ height: 0,
55
+ mode: "percent",
56
+ width: 0,
57
+ });
58
+ return size;
59
+ })();
60
+ this._lifeCount = (_g = this.options.life.count) !== null && _g !== void 0 ? _g : -1;
61
+ this._immortal = this._lifeCount <= 0;
62
+ this._engine.dispatchEvent("emitterCreated", {
63
+ container,
64
+ data: {
65
+ emitter: this,
66
+ },
67
+ });
68
+ this.play();
69
+ }
70
+ externalPause() {
71
+ this._paused = true;
72
+ this.pause();
73
+ }
74
+ externalPlay() {
75
+ this._paused = false;
76
+ this.play();
77
+ }
78
+ getPosition() {
79
+ if (this.options.domId) {
80
+ const container = this.container, element = document.getElementById(this.options.domId);
81
+ if (element) {
82
+ const elRect = element.getBoundingClientRect();
83
+ return {
84
+ x: (elRect.x + elRect.width / 2) * container.retina.pixelRatio,
85
+ y: (elRect.y + elRect.height / 2) * container.retina.pixelRatio,
86
+ };
87
+ }
88
+ }
89
+ return this.position;
90
+ }
91
+ getSize() {
92
+ const container = this.container;
93
+ if (this.options.domId) {
94
+ const element = document.getElementById(this.options.domId);
95
+ if (element) {
96
+ const elRect = element.getBoundingClientRect();
97
+ return {
98
+ width: elRect.width * container.retina.pixelRatio,
99
+ height: elRect.height * container.retina.pixelRatio,
100
+ };
101
+ }
102
+ }
103
+ return {
104
+ width: this.size.mode === "percent"
105
+ ? (container.canvas.size.width * this.size.width) / 100
106
+ : this.size.width,
107
+ height: this.size.mode === "percent"
108
+ ? (container.canvas.size.height * this.size.height) / 100
109
+ : this.size.height,
110
+ };
111
+ }
112
+ pause() {
113
+ if (this._paused) {
114
+ return;
115
+ }
116
+ delete this._emitDelay;
117
+ }
118
+ play() {
119
+ var _a;
120
+ if (this._paused) {
121
+ return;
122
+ }
123
+ if (!(this.container.retina.reduceFactor &&
124
+ (this._lifeCount > 0 || this._immortal || !this.options.life.count) &&
125
+ (this._firstSpawn || this._currentSpawnDelay >= ((_a = this._spawnDelay) !== null && _a !== void 0 ? _a : 0)))) {
126
+ return;
127
+ }
128
+ if (this._emitDelay === undefined) {
129
+ const delay = (0, engine_1.getRangeValue)(this.options.rate.delay);
130
+ this._emitDelay = (1000 * delay) / this.container.retina.reduceFactor;
131
+ }
132
+ if (this._lifeCount > 0 || this._immortal) {
133
+ this.prepareToDie();
134
+ }
135
+ }
136
+ resize() {
137
+ const initialPosition = this._initialPosition;
138
+ this.position =
139
+ initialPosition && (0, engine_1.isPointInside)(initialPosition, this.container.canvas.size, engine_1.Vector.origin)
140
+ ? initialPosition
141
+ : this.calcPosition();
142
+ }
143
+ update(delta) {
144
+ var _a, _b, _c;
145
+ if (this._paused) {
146
+ return;
147
+ }
148
+ if (this._firstSpawn) {
149
+ this._firstSpawn = false;
150
+ this._currentSpawnDelay = (_a = this._spawnDelay) !== null && _a !== void 0 ? _a : 0;
151
+ this._currentEmitDelay = (_b = this._emitDelay) !== null && _b !== void 0 ? _b : 0;
152
+ }
153
+ if (!this._startParticlesAdded) {
154
+ this._startParticlesAdded = true;
155
+ this.emitParticles(this.options.startCount);
156
+ }
157
+ if (this._duration !== undefined) {
158
+ this._currentDuration += delta.value;
159
+ if (this._currentDuration >= this._duration) {
160
+ this.pause();
161
+ if (this._spawnDelay !== undefined) {
162
+ delete this._spawnDelay;
163
+ }
164
+ if (!this._immortal) {
165
+ this._lifeCount--;
166
+ }
167
+ if (this._lifeCount > 0 || this._immortal) {
168
+ this.position = this.calcPosition();
169
+ this._spawnDelay = (((_c = this.options.life.delay) !== null && _c !== void 0 ? _c : 0) * 1000) / this.container.retina.reduceFactor;
170
+ }
171
+ else {
172
+ this.destroy();
173
+ }
174
+ this._currentDuration -= this._duration;
175
+ delete this._duration;
176
+ }
177
+ }
178
+ if (this._spawnDelay !== undefined) {
179
+ this._currentSpawnDelay += delta.value;
180
+ if (this._currentSpawnDelay >= this._spawnDelay) {
181
+ this._engine.dispatchEvent("emitterPlay", {
182
+ container: this.container,
183
+ });
184
+ this.play();
185
+ this._currentSpawnDelay -= this._currentSpawnDelay;
186
+ delete this._spawnDelay;
187
+ }
188
+ }
189
+ if (this._emitDelay !== undefined) {
190
+ this._currentEmitDelay += delta.value;
191
+ if (this._currentEmitDelay >= this._emitDelay) {
192
+ this.emit();
193
+ this._currentEmitDelay -= this._emitDelay;
194
+ }
195
+ }
196
+ }
197
+ calcPosition() {
198
+ return (0, engine_1.calcPositionOrRandomFromSizeRanged)({
199
+ size: this.container.canvas.size,
200
+ position: this.options.position,
201
+ });
202
+ }
203
+ destroy() {
204
+ this.emitters.removeEmitter(this);
205
+ this._engine.dispatchEvent("emitterDestroyed", {
206
+ container: this.container,
207
+ data: {
208
+ emitter: this,
209
+ },
210
+ });
211
+ }
212
+ emit() {
213
+ if (this._paused) {
214
+ return;
215
+ }
216
+ const quantity = (0, engine_1.getRangeValue)(this.options.rate.quantity);
217
+ this.emitParticles(quantity);
218
+ }
219
+ emitParticles(quantity) {
220
+ var _a, _b, _c;
221
+ const position = this.getPosition(), size = this.getSize(), singleParticlesOptions = (0, engine_1.itemFromSingleOrMultiple)(this._particlesOptions);
222
+ for (let i = 0; i < quantity; i++) {
223
+ const particlesOptions = (0, engine_1.deepExtend)({}, singleParticlesOptions);
224
+ if (this.spawnColor) {
225
+ const hslAnimation = (_a = this.options.spawnColor) === null || _a === void 0 ? void 0 : _a.animation;
226
+ if (hslAnimation) {
227
+ this.spawnColor.h = this.setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
228
+ this.spawnColor.s = this.setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
229
+ this.spawnColor.l = this.setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
230
+ }
231
+ if (!particlesOptions.color) {
232
+ particlesOptions.color = {
233
+ value: this.spawnColor,
234
+ };
235
+ }
236
+ else {
237
+ particlesOptions.color.value = this.spawnColor;
238
+ }
239
+ }
240
+ if (!position) {
241
+ return;
242
+ }
243
+ const pPosition = (_c = (_b = this._shape) === null || _b === void 0 ? void 0 : _b.randomPosition(position, size, this.fill)) !== null && _c !== void 0 ? _c : position;
244
+ this.container.particles.addParticle(pPosition, particlesOptions);
245
+ }
246
+ }
247
+ prepareToDie() {
248
+ var _a;
249
+ if (this._paused) {
250
+ return;
251
+ }
252
+ const duration = (_a = this.options.life) === null || _a === void 0 ? void 0 : _a.duration;
253
+ if (this.container.retina.reduceFactor &&
254
+ (this._lifeCount > 0 || this._immortal) &&
255
+ duration !== undefined &&
256
+ duration > 0) {
257
+ this._duration = duration * 1000;
258
+ }
259
+ }
260
+ setColorAnimation(animation, initValue, maxValue) {
261
+ var _a;
262
+ const container = this.container;
263
+ if (!animation.enable) {
264
+ return initValue;
265
+ }
266
+ const colorOffset = (0, engine_1.randomInRange)(animation.offset), delay = (0, engine_1.getRangeValue)(this.options.rate.delay), emitFactor = (1000 * delay) / container.retina.reduceFactor, colorSpeed = (0, engine_1.getRangeValue)((_a = animation.speed) !== null && _a !== void 0 ? _a : 0);
267
+ return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * 3.6) % maxValue;
268
+ }
269
+ }
270
+ exports.EmitterInstance = EmitterInstance;
271
+ });