@tsparticles/plugin-emitters 3.1.0 → 3.2.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.
- package/113.min.js +2 -0
- package/113.min.js.LICENSE.txt +1 -0
- package/927.min.js +2 -0
- package/927.min.js.LICENSE.txt +1 -0
- package/964.min.js +2 -0
- package/964.min.js.LICENSE.txt +1 -0
- package/973.min.js +2 -0
- package/973.min.js.LICENSE.txt +1 -0
- package/browser/EmitterInstance.js +9 -9
- package/browser/Emitters.js +1 -3
- package/browser/EmittersPlugin.js +90 -0
- package/browser/index.js +2 -92
- package/cjs/EmitterInstance.js +9 -9
- package/cjs/Emitters.js +25 -4
- package/cjs/EmittersPlugin.js +117 -0
- package/cjs/index.js +15 -93
- package/dist_browser_EmitterInstance_js.js +30 -0
- package/dist_browser_EmittersPlugin_js.js +90 -0
- package/dist_browser_Emitters_js.js +30 -0
- package/dist_browser_ShapeManager_js.js +30 -0
- package/esm/EmitterInstance.js +9 -9
- package/esm/Emitters.js +1 -3
- package/esm/EmittersPlugin.js +90 -0
- package/esm/index.js +2 -92
- package/package.json +2 -2
- package/report.html +3 -3
- package/tsparticles.plugin.emitters.js +251 -755
- package/tsparticles.plugin.emitters.min.js +1 -1
- package/tsparticles.plugin.emitters.min.js.LICENSE.txt +1 -1
- package/types/EmitterInstance.d.ts +1 -1
- package/types/Emitters.d.ts +2 -2
- package/types/EmittersPlugin.d.ts +13 -0
- package/umd/EmitterInstance.js +9 -9
- package/umd/Emitters.js +27 -5
- package/umd/EmittersPlugin.js +128 -0
- package/umd/index.js +17 -94
package/113.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see 113.min.js.LICENSE.txt */
|
|
2
|
+
(this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[113],{113:(e,t,r)=>{r.d(t,{ShapeManager:()=>s});const a=new Map;class s{constructor(e){this._engine=e}addShapeGenerator(e,t){this.getShapeGenerator(e)||a.set(e,t)}getShapeGenerator(e){return a.get(e)}getSupportedShapeGenerators(){return a.keys()}}}}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles Emitters Plugin v3.2.1 by Matteo Bruni */
|
package/927.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see 927.min.js.LICENSE.txt */
|
|
2
|
+
(this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[927],{927:(t,i,s)=>{s.d(i,{EmitterInstance:()=>r});var e=s(533),n=s(177),o=s(518);function a(t,i){t.color?t.color.value=i:t.color={value:i}}class r{constructor(t,i,s,o,a){this.emitters=i,this.container=s,this._destroy=()=>{this._mutationObserver?.disconnect(),this._mutationObserver=void 0,this._resizeObserver?.disconnect(),this._resizeObserver=void 0,this.emitters.removeEmitter(this),this._engine.dispatchEvent("emitterDestroyed",{container:this.container,data:{emitter:this}})},this._prepareToDie=()=>{if(this._paused)return;const t=void 0!==this.options.life?.duration?(0,e.getRangeValue)(this.options.life.duration):void 0;this.container.retina.reduceFactor&&(this._lifeCount>0||this._immortal)&&void 0!==t&&t>0&&(this._duration=t*e.millisecondsToSeconds)},this._setColorAnimation=(t,i,s,n=1)=>{const o=this.container;if(!t.enable)return i;const a=(0,e.randomInRange)(t.offset),r=(0,e.getRangeValue)(this.options.rate.delay)*e.millisecondsToSeconds/o.retina.reduceFactor;return(i+(0,e.getRangeValue)(t.speed??0)*o.fpsLimit/r+a*n)%s},this._engine=t,this._currentDuration=0,this._currentEmitDelay=0,this._currentSpawnDelay=0,this._initialPosition=a,o instanceof n.Emitter?this.options=o:(this.options=new n.Emitter,this.options.load(o)),this._spawnDelay=(0,e.getRangeValue)(this.options.life.delay??0)*e.millisecondsToSeconds/this.container.retina.reduceFactor,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;let r=(0,e.deepExtend)({},this.options.particles);if(r??={},r.move??={},r.move.direction??=this.options.direction,this.options.spawnColor&&(this.spawnColor=(0,e.rangeColorToHsl)(this.options.spawnColor)),this._paused=!this.options.autoPlay,this._particlesOptions=r,this._size=this._calcSize(),this.size=(0,e.getSize)(this._size,this.container.canvas.size),this._lifeCount=this.options.life.count??-1,this._immortal=this._lifeCount<=0,this.options.domId){const t=document.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 h=this.options.shape,l=this._engine.emitterShapeManager?.getShapeGenerator(h.type);l&&(this._shape=l.generate(this.position,this.size,this.fill,h.options)),this._engine.dispatchEvent("emitterCreated",{container:s,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.container.retina.reduceFactor&&(this._lifeCount>0||this._immortal||!this.options.life.count)&&(this._firstSpawn||this._currentSpawnDelay>=(this._spawnDelay??0))){if(void 0===this._emitDelay){const t=(0,e.getRangeValue)(this.options.rate.delay);this._emitDelay=t*e.millisecondsToSeconds/this.container.retina.reduceFactor}(this._lifeCount>0||this._immortal)&&this._prepareToDie()}}resize(){const t=this._initialPosition;this.position=t&&(0,e.isPointInside)(t,this.container.canvas.size,e.Vector.origin)?t:this._calcPosition(),this._size=this._calcSize(),this.size=(0,e.getSize)(this._size,this.container.canvas.size),this._shape?.resize(this.position,this.size)}async update(t){this._paused||(this._firstSpawn&&(this._firstSpawn=!1,this._currentSpawnDelay=this._spawnDelay??0,this._currentEmitDelay=this._emitDelay??0),this._startParticlesAdded||(this._startParticlesAdded=!0,await 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=(0,e.getRangeValue)(this.options.life.delay??0)*e.millisecondsToSeconds/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&&(await this._emit(),this._currentEmitDelay-=this._emitDelay)))}_calcPosition(){if(this.options.domId){const t=document.getElementById(this.options.domId);if(t){const i=t.getBoundingClientRect(),s=this.container.retina.pixelRatio;return{x:(i.x+.5*i.width)*s,y:(i.y+.5*i.height)*s}}}return(0,e.calcPositionOrRandomFromSizeRanged)({size:this.container.canvas.size,position:this.options.position})}_calcSize(){const t=this.container;if(this.options.domId){const i=document.getElementById(this.options.domId);if(i){const s=i.getBoundingClientRect();return{width:s.width*t.retina.pixelRatio,height:s.height*t.retina.pixelRatio,mode:"precise"}}}return this.options.size??(()=>{const t=new o.r;return t.load({height:0,mode:"percent",width:0}),t})()}async _emit(){if(this._paused)return;const t=(0,e.getRangeValue)(this.options.rate.quantity);await this._emitParticles(t)}async _emitParticles(t){const i=(0,e.itemFromSingleOrMultiple)(this._particlesOptions);for(let s=0;s<t;s++){const t=(0,e.deepExtend)({},i);if(this.spawnColor){const i=this.options.spawnColor?.animation;if(i){const t={h:360,s:100,l:100},s=3.6;this.spawnColor.h=this._setColorAnimation(i.h,this.spawnColor.h,t.h,s),this.spawnColor.s=this._setColorAnimation(i.s,this.spawnColor.s,t.s),this.spawnColor.l=this._setColorAnimation(i.l,this.spawnColor.l,t.l)}a(t,this.spawnColor)}const s=this.options.shape;let n=this.position;if(this._shape){const i=await this._shape.randomPosition();if(i){n=i.position;const e=s.replace;e.color&&i.color&&a(t,i.color),e.opacity&&(t.opacity?t.opacity.value=i.opacity:t.opacity={value:i.opacity})}else n=null}n&&await this.container.particles.addParticle(n,t)}}}}}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles Emitters Plugin v3.2.1 by Matteo Bruni */
|
package/964.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see 964.min.js.LICENSE.txt */
|
|
2
|
+
(this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[964],{964:(t,i,e)=>{e.d(i,{EmittersPlugin:()=>a});var o=e(533),s=e(177);class a{constructor(t){this._engine=t,this.id="emitters"}async getPlugin(t){const{Emitters:i}=await e.e(973).then(e.bind(e,973));return new i(this._engine,t)}loadOptions(t,i){if(!this.needsPlugin(t)&&!this.needsPlugin(i))return;i?.emitters&&(t.emitters=(0,o.executeOnSingleOrMultiple)(i.emitters,(t=>{const i=new s.Emitter;return i.load(t),i})));const e=i?.interactivity?.modes?.emitters;if(e)if((0,o.isArray)(e))t.interactivity.modes.emitters={random:{count:1,enable:!0},value:e.map((t=>{const i=new s.Emitter;return i.load(t),i}))};else{const i=e;if(void 0!==i.value){const e=1;if((0,o.isArray)(i.value))t.interactivity.modes.emitters={random:{count:i.random.count??e,enable:i.random.enable??!1},value:i.value.map((t=>{const i=new s.Emitter;return i.load(t),i}))};else{const o=new s.Emitter;o.load(i.value),t.interactivity.modes.emitters={random:{count:i.random.count??e,enable:i.random.enable??!1},value:o}}}else{(t.interactivity.modes.emitters={random:{count:1,enable:!1},value:new s.Emitter}).value.load(e)}}}needsPlugin(t){if(!t)return!1;const i=t.emitters;return(0,o.isArray)(i)&&!!i.length||void 0!==i||!!t.interactivity?.events?.onClick?.mode&&(0,o.isInArray)("emitter",t.interactivity.events.onClick.mode)}}},177:(t,i,e)=>{e.d(i,{Emitter:()=>d});var o=e(533);class s{constructor(){this.wait=!1}load(t){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 a{constructor(){this.quantity=1,this.delay=.1}load(t){void 0!==t&&(void 0!==t.quantity&&(this.quantity=(0,o.setRangeValue)(t.quantity)),void 0!==t.delay&&(this.delay=(0,o.setRangeValue)(t.delay)))}}class n{constructor(){this.color=!1,this.opacity=!1}load(t){t&&(void 0!==t.color&&(this.color=t.color),void 0!==t.opacity&&(this.opacity=t.opacity))}}class r{constructor(){this.options={},this.replace=new n,this.type="square"}load(t){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 l=e(518);class d{constructor(){this.autoPlay=!0,this.fill=!0,this.life=new s,this.rate=new a,this.shape=new r,this.startCount=0}load(t){t&&(void 0!==t.autoPlay&&(this.autoPlay=t.autoPlay),void 0!==t.size&&(this.size||(this.size=new l.r),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),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.spawnColor&&(void 0===this.spawnColor&&(this.spawnColor=new o.AnimatableColor),this.spawnColor.load(t.spawnColor)),void 0!==t.startCount&&(this.startCount=t.startCount))}}},518:(t,i,e)=>{e.d(i,{r:()=>o});class o{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))}}}}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles Emitters Plugin v3.2.1 by Matteo Bruni */
|
package/973.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see 973.min.js.LICENSE.txt */
|
|
2
|
+
(this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[]).push([[973],{973:(t,e,i)=>{i.d(e,{Emitters:()=>r});var s=i(533);class r{constructor(t,e){this.container=e,this._engine=t,this.array=[],this.emitters=[],this.interactivityEmitters={random:{count:1,enable:!1},value:[]};e.getEmitter=t=>void 0===t||(0,s.isNumber)(t)?this.array[t??0]:this.array.find((e=>e.name===t)),e.addEmitter=async(t,e)=>this.addEmitter(t,e),e.removeEmitter=t=>{const i=e.getEmitter(t);i&&this.removeEmitter(i)},e.playEmitter=t=>{const i=e.getEmitter(t);i&&i.externalPlay()},e.pauseEmitter=t=>{const i=e.getEmitter(t);i&&i.externalPause()}}async addEmitter(t,e){const{Emitter:s}=await Promise.resolve().then(i.bind(i,177)),{EmitterInstance:r}=await i.e(927).then(i.bind(i,927)),a=new s;a.load(t);const n=new r(this._engine,this,this.container,a,e);return await n.init(),this.array.push(n),n}handleClickMode(t){const e=this.emitters,i=this.interactivityEmitters;if("emitter"!==t)return;let r;if(i&&(0,s.isArray)(i.value)){const t=0;if(i.value.length>t&&i.random.enable){r=[];const t=[];for(let e=0;e<i.random.count;e++){const a=(0,s.arrayRandomIndex)(i.value);t.includes(a)&&t.length<i.value.length?e--:(t.push(a),r.push((0,s.itemFromArray)(i.value,a)))}}else r=i.value}else r=i?.value;const a=r??e,n=this.container.interactivity.mouse.clickPosition;(0,s.executeOnSingleOrMultiple)(a,(async t=>{await this.addEmitter(t,n)}))}async init(){if(this.emitters=this.container.actualOptions.emitters,this.interactivityEmitters=this.container.actualOptions.interactivity.modes.emitters,this.emitters)if((0,s.isArray)(this.emitters))for(const t of this.emitters)await this.addEmitter(t);else await this.addEmitter(this.emitters)}pause(){for(const t of this.array)t.pause()}play(){for(const t of this.array)t.play()}removeEmitter(t){const e=this.array.indexOf(t);e>=0&&this.array.splice(e,1)}resize(){for(const t of this.array)t.resize()}stop(){this.array=[]}async update(t){for(const e of this.array)await e.update(t)}}}}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles Emitters Plugin v3.2.1 by Matteo Bruni */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Vector, calcPositionOrRandomFromSizeRanged, deepExtend, getRangeValue, getSize, isPointInside, itemFromSingleOrMultiple, millisecondsToSeconds, randomInRange, rangeColorToHsl, } from "@tsparticles/engine";
|
|
2
2
|
import { Emitter } from "./Options/Classes/Emitter.js";
|
|
3
3
|
import { EmitterSize } from "./Options/Classes/EmitterSize.js";
|
|
4
|
-
const half = 0.5, defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1;
|
|
4
|
+
const half = 0.5, defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1, defaultColorAnimationFactor = 1;
|
|
5
5
|
function setParticlesOptionsColor(particlesOptions, color) {
|
|
6
6
|
if (particlesOptions.color) {
|
|
7
7
|
particlesOptions.color.value = color;
|
|
@@ -41,13 +41,13 @@ export class EmitterInstance {
|
|
|
41
41
|
this._duration = duration * millisecondsToSeconds;
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
|
-
this._setColorAnimation = (animation, initValue, maxValue) => {
|
|
44
|
+
this._setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => {
|
|
45
45
|
const container = this.container;
|
|
46
46
|
if (!animation.enable) {
|
|
47
47
|
return initValue;
|
|
48
48
|
}
|
|
49
|
-
const colorOffset = randomInRange(animation.offset), delay = getRangeValue(this.options.rate.delay), emitFactor = (delay * millisecondsToSeconds) / container.retina.reduceFactor, defaultColorSpeed = 0,
|
|
50
|
-
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset *
|
|
49
|
+
const colorOffset = randomInRange(animation.offset), delay = getRangeValue(this.options.rate.delay), emitFactor = (delay * millisecondsToSeconds) / container.retina.reduceFactor, defaultColorSpeed = 0, colorSpeed = getRangeValue(animation.speed ?? defaultColorSpeed);
|
|
50
|
+
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * factor) % maxValue;
|
|
51
51
|
};
|
|
52
52
|
this._engine = engine;
|
|
53
53
|
this._currentDuration = 0;
|
|
@@ -212,9 +212,9 @@ export class EmitterInstance {
|
|
|
212
212
|
}
|
|
213
213
|
_calcPosition() {
|
|
214
214
|
if (this.options.domId) {
|
|
215
|
-
const
|
|
215
|
+
const element = document.getElementById(this.options.domId);
|
|
216
216
|
if (element) {
|
|
217
|
-
const elRect = element.getBoundingClientRect(), pxRatio = container.retina.pixelRatio;
|
|
217
|
+
const elRect = element.getBoundingClientRect(), pxRatio = this.container.retina.pixelRatio;
|
|
218
218
|
return {
|
|
219
219
|
x: (elRect.x + elRect.width * half) * pxRatio,
|
|
220
220
|
y: (elRect.y + elRect.height * half) * pxRatio,
|
|
@@ -268,8 +268,8 @@ export class EmitterInstance {
|
|
|
268
268
|
h: 360,
|
|
269
269
|
s: 100,
|
|
270
270
|
l: 100,
|
|
271
|
-
};
|
|
272
|
-
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h);
|
|
271
|
+
}, colorFactor = 3.6;
|
|
272
|
+
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h, colorFactor);
|
|
273
273
|
this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, maxValues.s);
|
|
274
274
|
this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, maxValues.l);
|
|
275
275
|
}
|
|
@@ -301,7 +301,7 @@ export class EmitterInstance {
|
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
303
|
if (position) {
|
|
304
|
-
this.container.particles.addParticle(position, particlesOptions);
|
|
304
|
+
await this.container.particles.addParticle(position, particlesOptions);
|
|
305
305
|
}
|
|
306
306
|
}
|
|
307
307
|
}
|
package/browser/Emitters.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { arrayRandomIndex, executeOnSingleOrMultiple, isArray, isNumber, itemFromArray, } from "@tsparticles/engine";
|
|
2
|
-
import { Emitter } from "./Options/Classes/Emitter.js";
|
|
3
|
-
import { EmitterInstance } from "./EmitterInstance.js";
|
|
4
2
|
export class Emitters {
|
|
5
3
|
constructor(engine, container) {
|
|
6
4
|
this.container = container;
|
|
@@ -39,7 +37,7 @@ export class Emitters {
|
|
|
39
37
|
};
|
|
40
38
|
}
|
|
41
39
|
async addEmitter(options, position) {
|
|
42
|
-
const emitterOptions = new Emitter();
|
|
40
|
+
const { Emitter } = await import("./Options/Classes/Emitter.js"), { EmitterInstance } = await import("./EmitterInstance.js"), emitterOptions = new Emitter();
|
|
43
41
|
emitterOptions.load(options);
|
|
44
42
|
const emitter = new EmitterInstance(this._engine, this, this.container, emitterOptions, position);
|
|
45
43
|
await emitter.init();
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { executeOnSingleOrMultiple, isArray, isInArray, } from "@tsparticles/engine";
|
|
2
|
+
import { Emitter } from "./Options/Classes/Emitter.js";
|
|
3
|
+
export class EmittersPlugin {
|
|
4
|
+
constructor(engine) {
|
|
5
|
+
this._engine = engine;
|
|
6
|
+
this.id = "emitters";
|
|
7
|
+
}
|
|
8
|
+
async getPlugin(container) {
|
|
9
|
+
const { Emitters } = await import("./Emitters.js");
|
|
10
|
+
return new Emitters(this._engine, container);
|
|
11
|
+
}
|
|
12
|
+
loadOptions(options, source) {
|
|
13
|
+
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (source?.emitters) {
|
|
17
|
+
options.emitters = executeOnSingleOrMultiple(source.emitters, (emitter) => {
|
|
18
|
+
const tmp = new Emitter();
|
|
19
|
+
tmp.load(emitter);
|
|
20
|
+
return tmp;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const interactivityEmitters = source?.interactivity?.modes?.emitters;
|
|
24
|
+
if (interactivityEmitters) {
|
|
25
|
+
if (isArray(interactivityEmitters)) {
|
|
26
|
+
options.interactivity.modes.emitters = {
|
|
27
|
+
random: {
|
|
28
|
+
count: 1,
|
|
29
|
+
enable: true,
|
|
30
|
+
},
|
|
31
|
+
value: interactivityEmitters.map((s) => {
|
|
32
|
+
const tmp = new Emitter();
|
|
33
|
+
tmp.load(s);
|
|
34
|
+
return tmp;
|
|
35
|
+
}),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const emitterMode = interactivityEmitters;
|
|
40
|
+
if (emitterMode.value !== undefined) {
|
|
41
|
+
const defaultCount = 1;
|
|
42
|
+
if (isArray(emitterMode.value)) {
|
|
43
|
+
options.interactivity.modes.emitters = {
|
|
44
|
+
random: {
|
|
45
|
+
count: emitterMode.random.count ?? defaultCount,
|
|
46
|
+
enable: emitterMode.random.enable ?? false,
|
|
47
|
+
},
|
|
48
|
+
value: emitterMode.value.map((s) => {
|
|
49
|
+
const tmp = new Emitter();
|
|
50
|
+
tmp.load(s);
|
|
51
|
+
return tmp;
|
|
52
|
+
}),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const tmp = new Emitter();
|
|
57
|
+
tmp.load(emitterMode.value);
|
|
58
|
+
options.interactivity.modes.emitters = {
|
|
59
|
+
random: {
|
|
60
|
+
count: emitterMode.random.count ?? defaultCount,
|
|
61
|
+
enable: emitterMode.random.enable ?? false,
|
|
62
|
+
},
|
|
63
|
+
value: tmp,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const emitterOptions = (options.interactivity.modes.emitters = {
|
|
69
|
+
random: {
|
|
70
|
+
count: 1,
|
|
71
|
+
enable: false,
|
|
72
|
+
},
|
|
73
|
+
value: new Emitter(),
|
|
74
|
+
});
|
|
75
|
+
emitterOptions.value.load(interactivityEmitters);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
needsPlugin(options) {
|
|
81
|
+
if (!options) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
const emitters = options.emitters;
|
|
85
|
+
return ((isArray(emitters) && !!emitters.length) ||
|
|
86
|
+
emitters !== undefined ||
|
|
87
|
+
(!!options.interactivity?.events?.onClick?.mode &&
|
|
88
|
+
isInArray("emitter", options.interactivity.events.onClick.mode)));
|
|
89
|
+
}
|
|
90
|
+
}
|
package/browser/index.js
CHANGED
|
@@ -1,96 +1,6 @@
|
|
|
1
|
-
import { executeOnSingleOrMultiple, isArray, isInArray, } from "@tsparticles/engine";
|
|
2
|
-
import { Emitter } from "./Options/Classes/Emitter.js";
|
|
3
|
-
import { Emitters } from "./Emitters.js";
|
|
4
|
-
import { ShapeManager } from "./ShapeManager.js";
|
|
5
|
-
class EmittersPlugin {
|
|
6
|
-
constructor(engine) {
|
|
7
|
-
this._engine = engine;
|
|
8
|
-
this.id = "emitters";
|
|
9
|
-
}
|
|
10
|
-
getPlugin(container) {
|
|
11
|
-
return new Emitters(this._engine, container);
|
|
12
|
-
}
|
|
13
|
-
loadOptions(options, source) {
|
|
14
|
-
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
if (source?.emitters) {
|
|
18
|
-
options.emitters = executeOnSingleOrMultiple(source.emitters, (emitter) => {
|
|
19
|
-
const tmp = new Emitter();
|
|
20
|
-
tmp.load(emitter);
|
|
21
|
-
return tmp;
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
const interactivityEmitters = source?.interactivity?.modes?.emitters;
|
|
25
|
-
if (interactivityEmitters) {
|
|
26
|
-
if (isArray(interactivityEmitters)) {
|
|
27
|
-
options.interactivity.modes.emitters = {
|
|
28
|
-
random: {
|
|
29
|
-
count: 1,
|
|
30
|
-
enable: true,
|
|
31
|
-
},
|
|
32
|
-
value: interactivityEmitters.map((s) => {
|
|
33
|
-
const tmp = new Emitter();
|
|
34
|
-
tmp.load(s);
|
|
35
|
-
return tmp;
|
|
36
|
-
}),
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
const emitterMode = interactivityEmitters;
|
|
41
|
-
if (emitterMode.value !== undefined) {
|
|
42
|
-
const defaultCount = 1;
|
|
43
|
-
if (isArray(emitterMode.value)) {
|
|
44
|
-
options.interactivity.modes.emitters = {
|
|
45
|
-
random: {
|
|
46
|
-
count: emitterMode.random.count ?? defaultCount,
|
|
47
|
-
enable: emitterMode.random.enable ?? false,
|
|
48
|
-
},
|
|
49
|
-
value: emitterMode.value.map((s) => {
|
|
50
|
-
const tmp = new Emitter();
|
|
51
|
-
tmp.load(s);
|
|
52
|
-
return tmp;
|
|
53
|
-
}),
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
const tmp = new Emitter();
|
|
58
|
-
tmp.load(emitterMode.value);
|
|
59
|
-
options.interactivity.modes.emitters = {
|
|
60
|
-
random: {
|
|
61
|
-
count: emitterMode.random.count ?? defaultCount,
|
|
62
|
-
enable: emitterMode.random.enable ?? false,
|
|
63
|
-
},
|
|
64
|
-
value: tmp,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
const emitterOptions = (options.interactivity.modes.emitters = {
|
|
70
|
-
random: {
|
|
71
|
-
count: 1,
|
|
72
|
-
enable: false,
|
|
73
|
-
},
|
|
74
|
-
value: new Emitter(),
|
|
75
|
-
});
|
|
76
|
-
emitterOptions.value.load(interactivityEmitters);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
needsPlugin(options) {
|
|
82
|
-
if (!options) {
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
const emitters = options.emitters;
|
|
86
|
-
return ((isArray(emitters) && !!emitters.length) ||
|
|
87
|
-
emitters !== undefined ||
|
|
88
|
-
(!!options.interactivity?.events?.onClick?.mode &&
|
|
89
|
-
isInArray("emitter", options.interactivity.events.onClick.mode)));
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
1
|
export async function loadEmittersPlugin(engine, refresh = true) {
|
|
93
2
|
if (!engine.emitterShapeManager) {
|
|
3
|
+
const { ShapeManager } = await import("./ShapeManager.js");
|
|
94
4
|
engine.emitterShapeManager = new ShapeManager(engine);
|
|
95
5
|
}
|
|
96
6
|
if (!engine.addEmitterShapeGenerator) {
|
|
@@ -98,7 +8,7 @@ export async function loadEmittersPlugin(engine, refresh = true) {
|
|
|
98
8
|
engine.emitterShapeManager?.addShapeGenerator(name, generator);
|
|
99
9
|
};
|
|
100
10
|
}
|
|
101
|
-
const plugin = new EmittersPlugin(engine);
|
|
11
|
+
const { EmittersPlugin } = await import("./EmittersPlugin.js"), plugin = new EmittersPlugin(engine);
|
|
102
12
|
await engine.addPlugin(plugin, refresh);
|
|
103
13
|
}
|
|
104
14
|
export * from "./EmitterContainer.js";
|
package/cjs/EmitterInstance.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.EmitterInstance = void 0;
|
|
|
4
4
|
const engine_1 = require("@tsparticles/engine");
|
|
5
5
|
const Emitter_js_1 = require("./Options/Classes/Emitter.js");
|
|
6
6
|
const EmitterSize_js_1 = require("./Options/Classes/EmitterSize.js");
|
|
7
|
-
const half = 0.5, defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1;
|
|
7
|
+
const half = 0.5, defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1, defaultColorAnimationFactor = 1;
|
|
8
8
|
function setParticlesOptionsColor(particlesOptions, color) {
|
|
9
9
|
if (particlesOptions.color) {
|
|
10
10
|
particlesOptions.color.value = color;
|
|
@@ -44,13 +44,13 @@ class EmitterInstance {
|
|
|
44
44
|
this._duration = duration * engine_1.millisecondsToSeconds;
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
|
-
this._setColorAnimation = (animation, initValue, maxValue) => {
|
|
47
|
+
this._setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => {
|
|
48
48
|
const container = this.container;
|
|
49
49
|
if (!animation.enable) {
|
|
50
50
|
return initValue;
|
|
51
51
|
}
|
|
52
|
-
const colorOffset = (0, engine_1.randomInRange)(animation.offset), delay = (0, engine_1.getRangeValue)(this.options.rate.delay), emitFactor = (delay * engine_1.millisecondsToSeconds) / container.retina.reduceFactor, defaultColorSpeed = 0,
|
|
53
|
-
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset *
|
|
52
|
+
const colorOffset = (0, engine_1.randomInRange)(animation.offset), delay = (0, engine_1.getRangeValue)(this.options.rate.delay), emitFactor = (delay * engine_1.millisecondsToSeconds) / container.retina.reduceFactor, defaultColorSpeed = 0, colorSpeed = (0, engine_1.getRangeValue)(animation.speed ?? defaultColorSpeed);
|
|
53
|
+
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * factor) % maxValue;
|
|
54
54
|
};
|
|
55
55
|
this._engine = engine;
|
|
56
56
|
this._currentDuration = 0;
|
|
@@ -215,9 +215,9 @@ class EmitterInstance {
|
|
|
215
215
|
}
|
|
216
216
|
_calcPosition() {
|
|
217
217
|
if (this.options.domId) {
|
|
218
|
-
const
|
|
218
|
+
const element = document.getElementById(this.options.domId);
|
|
219
219
|
if (element) {
|
|
220
|
-
const elRect = element.getBoundingClientRect(), pxRatio = container.retina.pixelRatio;
|
|
220
|
+
const elRect = element.getBoundingClientRect(), pxRatio = this.container.retina.pixelRatio;
|
|
221
221
|
return {
|
|
222
222
|
x: (elRect.x + elRect.width * half) * pxRatio,
|
|
223
223
|
y: (elRect.y + elRect.height * half) * pxRatio,
|
|
@@ -271,8 +271,8 @@ class EmitterInstance {
|
|
|
271
271
|
h: 360,
|
|
272
272
|
s: 100,
|
|
273
273
|
l: 100,
|
|
274
|
-
};
|
|
275
|
-
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h);
|
|
274
|
+
}, colorFactor = 3.6;
|
|
275
|
+
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h, colorFactor);
|
|
276
276
|
this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, maxValues.s);
|
|
277
277
|
this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, maxValues.l);
|
|
278
278
|
}
|
|
@@ -304,7 +304,7 @@ class EmitterInstance {
|
|
|
304
304
|
}
|
|
305
305
|
}
|
|
306
306
|
if (position) {
|
|
307
|
-
this.container.particles.addParticle(position, particlesOptions);
|
|
307
|
+
await this.container.particles.addParticle(position, particlesOptions);
|
|
308
308
|
}
|
|
309
309
|
}
|
|
310
310
|
}
|
package/cjs/Emitters.js
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.Emitters = void 0;
|
|
4
27
|
const engine_1 = require("@tsparticles/engine");
|
|
5
|
-
const Emitter_js_1 = require("./Options/Classes/Emitter.js");
|
|
6
|
-
const EmitterInstance_js_1 = require("./EmitterInstance.js");
|
|
7
28
|
class Emitters {
|
|
8
29
|
constructor(engine, container) {
|
|
9
30
|
this.container = container;
|
|
@@ -42,9 +63,9 @@ class Emitters {
|
|
|
42
63
|
};
|
|
43
64
|
}
|
|
44
65
|
async addEmitter(options, position) {
|
|
45
|
-
const emitterOptions = new
|
|
66
|
+
const { Emitter } = await Promise.resolve().then(() => __importStar(require("./Options/Classes/Emitter.js"))), { EmitterInstance } = await Promise.resolve().then(() => __importStar(require("./EmitterInstance.js"))), emitterOptions = new Emitter();
|
|
46
67
|
emitterOptions.load(options);
|
|
47
|
-
const emitter = new
|
|
68
|
+
const emitter = new EmitterInstance(this._engine, this, this.container, emitterOptions, position);
|
|
48
69
|
await emitter.init();
|
|
49
70
|
this.array.push(emitter);
|
|
50
71
|
return emitter;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.EmittersPlugin = void 0;
|
|
27
|
+
const engine_1 = require("@tsparticles/engine");
|
|
28
|
+
const Emitter_js_1 = require("./Options/Classes/Emitter.js");
|
|
29
|
+
class EmittersPlugin {
|
|
30
|
+
constructor(engine) {
|
|
31
|
+
this._engine = engine;
|
|
32
|
+
this.id = "emitters";
|
|
33
|
+
}
|
|
34
|
+
async getPlugin(container) {
|
|
35
|
+
const { Emitters } = await Promise.resolve().then(() => __importStar(require("./Emitters.js")));
|
|
36
|
+
return new Emitters(this._engine, container);
|
|
37
|
+
}
|
|
38
|
+
loadOptions(options, source) {
|
|
39
|
+
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (source?.emitters) {
|
|
43
|
+
options.emitters = (0, engine_1.executeOnSingleOrMultiple)(source.emitters, (emitter) => {
|
|
44
|
+
const tmp = new Emitter_js_1.Emitter();
|
|
45
|
+
tmp.load(emitter);
|
|
46
|
+
return tmp;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const interactivityEmitters = source?.interactivity?.modes?.emitters;
|
|
50
|
+
if (interactivityEmitters) {
|
|
51
|
+
if ((0, engine_1.isArray)(interactivityEmitters)) {
|
|
52
|
+
options.interactivity.modes.emitters = {
|
|
53
|
+
random: {
|
|
54
|
+
count: 1,
|
|
55
|
+
enable: true,
|
|
56
|
+
},
|
|
57
|
+
value: interactivityEmitters.map((s) => {
|
|
58
|
+
const tmp = new Emitter_js_1.Emitter();
|
|
59
|
+
tmp.load(s);
|
|
60
|
+
return tmp;
|
|
61
|
+
}),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const emitterMode = interactivityEmitters;
|
|
66
|
+
if (emitterMode.value !== undefined) {
|
|
67
|
+
const defaultCount = 1;
|
|
68
|
+
if ((0, engine_1.isArray)(emitterMode.value)) {
|
|
69
|
+
options.interactivity.modes.emitters = {
|
|
70
|
+
random: {
|
|
71
|
+
count: emitterMode.random.count ?? defaultCount,
|
|
72
|
+
enable: emitterMode.random.enable ?? false,
|
|
73
|
+
},
|
|
74
|
+
value: emitterMode.value.map((s) => {
|
|
75
|
+
const tmp = new Emitter_js_1.Emitter();
|
|
76
|
+
tmp.load(s);
|
|
77
|
+
return tmp;
|
|
78
|
+
}),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
const tmp = new Emitter_js_1.Emitter();
|
|
83
|
+
tmp.load(emitterMode.value);
|
|
84
|
+
options.interactivity.modes.emitters = {
|
|
85
|
+
random: {
|
|
86
|
+
count: emitterMode.random.count ?? defaultCount,
|
|
87
|
+
enable: emitterMode.random.enable ?? false,
|
|
88
|
+
},
|
|
89
|
+
value: tmp,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
const emitterOptions = (options.interactivity.modes.emitters = {
|
|
95
|
+
random: {
|
|
96
|
+
count: 1,
|
|
97
|
+
enable: false,
|
|
98
|
+
},
|
|
99
|
+
value: new Emitter_js_1.Emitter(),
|
|
100
|
+
});
|
|
101
|
+
emitterOptions.value.load(interactivityEmitters);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
needsPlugin(options) {
|
|
107
|
+
if (!options) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
const emitters = options.emitters;
|
|
111
|
+
return (((0, engine_1.isArray)(emitters) && !!emitters.length) ||
|
|
112
|
+
emitters !== undefined ||
|
|
113
|
+
(!!options.interactivity?.events?.onClick?.mode &&
|
|
114
|
+
(0, engine_1.isInArray)("emitter", options.interactivity.events.onClick.mode)));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.EmittersPlugin = EmittersPlugin;
|