UNPKG

@tsparticles/updater-life

Version:

tsParticles particles life updater

2 lines 3.06 kB
/*! For license information please see tsparticles.updater.life.min.js.LICENSE.txt */ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],t);else{var n="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(this,(e=>(()=>{var t={303:t=>{t.exports=e}},n={};function i(e){var o=n[e];if(void 0!==o)return o.exports;var a=n[e]={exports:{}};return t[e](a,a.exports,i),a.exports}i.d=(e,t)=>{for(var n in t)i.o(t,n)&&!i.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};i.r(o),i.d(o,{loadLifeUpdater:()=>c});var a=i(303);class r extends a.ValueWithRandom{constructor(){super(),this.sync=!1}load(e){(0,a.isNull)(e)||(super.load(e),void 0!==e.sync&&(this.sync=e.sync))}}class s extends a.ValueWithRandom{constructor(){super(),this.sync=!1}load(e){(0,a.isNull)(e)||(super.load(e),void 0!==e.sync&&(this.sync=e.sync))}}class l{constructor(){this.count=0,this.delay=new r,this.duration=new s}load(e){(0,a.isNull)(e)||(void 0!==e.count&&(this.count=e.count),this.delay.load(e.delay),this.duration.load(e.duration))}}class d{constructor(e){this.container=e}init(e){const t=this.container,n=e.options.life;n&&(e.life={delay:t.retina.reduceFactor?(0,a.getRangeValue)(n.delay.value)*(n.delay.sync?1:(0,a.getRandom)())/t.retina.reduceFactor*a.millisecondsToSeconds:0,delayTime:0,duration:t.retina.reduceFactor?(0,a.getRangeValue)(n.duration.value)*(n.duration.sync?1:(0,a.getRandom)())/t.retina.reduceFactor*a.millisecondsToSeconds:0,time:0,count:n.count},e.life.duration<=0&&(e.life.duration=-1),e.life.count<=0&&(e.life.count=-1),e.life&&(e.spawning=e.life.delay>0))}isEnabled(e){return!e.destroyed}loadOptions(e,...t){e.life||(e.life=new l);for(const n of t)e.life.load(n?.life)}update(e,t){this.isEnabled(e)&&e.life&&function(e,t,n){if(!e.life)return;const i=e.life;let o=!1;if(e.spawning){if(i.delayTime+=t.value,!(i.delayTime>=e.life.delay))return;o=!0,e.spawning=!1,i.delayTime=0,i.time=0}if(-1===i.duration)return;if(e.spawning)return;if(o?i.time=0:i.time+=t.value,i.time<i.duration)return;if(i.time=0,e.life.count>0&&e.life.count--,0===e.life.count)return void e.destroy();const r=(0,a.setRangeValue)(0,n.width),s=(0,a.setRangeValue)(0,n.width);e.position.x=(0,a.randomInRange)(r),e.position.y=(0,a.randomInRange)(s),e.spawning=!0,i.delayTime=0,i.time=0,e.reset();const l=e.options.life;l&&(i.delay=(0,a.getRangeValue)(l.delay.value)*a.millisecondsToSeconds,i.duration=(0,a.getRangeValue)(l.duration.value)*a.millisecondsToSeconds)}(e,t,this.container.canvas.size)}}async function c(e,t=!0){e.checkVersion("3.9.0"),await e.addParticleUpdater("life",(async e=>Promise.resolve(new d(e))),t)}return o})()));