@tsparticles/plugin-emitters
Advanced tools
Comparing version 3.1.0 to 3.2.0
import { Vector, calcPositionOrRandomFromSizeRanged, deepExtend, getRangeValue, getSize, isPointInside, itemFromSingleOrMultiple, millisecondsToSeconds, randomInRange, rangeColorToHsl, } from "@tsparticles/engine"; | ||
import { Emitter } from "./Options/Classes/Emitter.js"; | ||
import { EmitterSize } from "./Options/Classes/EmitterSize.js"; | ||
const half = 0.5, defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1; | ||
const half = 0.5, defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1, defaultColorAnimationFactor = 1; | ||
function setParticlesOptionsColor(particlesOptions, color) { | ||
@@ -44,3 +44,3 @@ if (particlesOptions.color) { | ||
}; | ||
this._setColorAnimation = (animation, initValue, maxValue) => { | ||
this._setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => { | ||
const container = this.container; | ||
@@ -50,4 +50,4 @@ if (!animation.enable) { | ||
} | ||
const colorOffset = randomInRange(animation.offset), delay = getRangeValue(this.options.rate.delay), emitFactor = (delay * millisecondsToSeconds) / container.retina.reduceFactor, defaultColorSpeed = 0, colorFactor = 3.6, colorSpeed = getRangeValue(animation.speed ?? defaultColorSpeed); | ||
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * colorFactor) % maxValue; | ||
const colorOffset = randomInRange(animation.offset), delay = getRangeValue(this.options.rate.delay), emitFactor = (delay * millisecondsToSeconds) / container.retina.reduceFactor, defaultColorSpeed = 0, colorSpeed = getRangeValue(animation.speed ?? defaultColorSpeed); | ||
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * factor) % maxValue; | ||
}; | ||
@@ -217,5 +217,5 @@ this._engine = engine; | ||
if (this.options.domId) { | ||
const container = this.container, element = document.getElementById(this.options.domId); | ||
const element = document.getElementById(this.options.domId); | ||
if (element) { | ||
const elRect = element.getBoundingClientRect(), pxRatio = container.retina.pixelRatio; | ||
const elRect = element.getBoundingClientRect(), pxRatio = this.container.retina.pixelRatio; | ||
return { | ||
@@ -274,4 +274,4 @@ x: (elRect.x + elRect.width * half) * pxRatio, | ||
l: 100, | ||
}; | ||
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h); | ||
}, colorFactor = 3.6; | ||
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h, colorFactor); | ||
this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, maxValues.s); | ||
@@ -308,3 +308,3 @@ this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, maxValues.l); | ||
if (position) { | ||
this.container.particles.addParticle(position, particlesOptions); | ||
await this.container.particles.addParticle(position, particlesOptions); | ||
} | ||
@@ -311,0 +311,0 @@ } |
import { arrayRandomIndex, executeOnSingleOrMultiple, isArray, isNumber, itemFromArray, } from "@tsparticles/engine"; | ||
import { Emitter } from "./Options/Classes/Emitter.js"; | ||
import { EmitterInstance } from "./EmitterInstance.js"; | ||
export class Emitters { | ||
@@ -42,3 +40,3 @@ constructor(engine, container) { | ||
async addEmitter(options, position) { | ||
const emitterOptions = new Emitter(); | ||
const { Emitter } = await import("./Options/Classes/Emitter.js"), { EmitterInstance } = await import("./EmitterInstance.js"), emitterOptions = new Emitter(); | ||
emitterOptions.load(options); | ||
@@ -45,0 +43,0 @@ const emitter = new EmitterInstance(this._engine, this, this.container, emitterOptions, position); |
@@ -1,94 +0,4 @@ | ||
import { executeOnSingleOrMultiple, isArray, isInArray, } from "@tsparticles/engine"; | ||
import { Emitter } from "./Options/Classes/Emitter.js"; | ||
import { Emitters } from "./Emitters.js"; | ||
import { ShapeManager } from "./ShapeManager.js"; | ||
class EmittersPlugin { | ||
constructor(engine) { | ||
this._engine = engine; | ||
this.id = "emitters"; | ||
} | ||
getPlugin(container) { | ||
return new Emitters(this._engine, container); | ||
} | ||
loadOptions(options, source) { | ||
if (!this.needsPlugin(options) && !this.needsPlugin(source)) { | ||
return; | ||
} | ||
if (source?.emitters) { | ||
options.emitters = executeOnSingleOrMultiple(source.emitters, (emitter) => { | ||
const tmp = new Emitter(); | ||
tmp.load(emitter); | ||
return tmp; | ||
}); | ||
} | ||
const interactivityEmitters = source?.interactivity?.modes?.emitters; | ||
if (interactivityEmitters) { | ||
if (isArray(interactivityEmitters)) { | ||
options.interactivity.modes.emitters = { | ||
random: { | ||
count: 1, | ||
enable: true, | ||
}, | ||
value: interactivityEmitters.map((s) => { | ||
const tmp = new Emitter(); | ||
tmp.load(s); | ||
return tmp; | ||
}), | ||
}; | ||
} | ||
else { | ||
const emitterMode = interactivityEmitters; | ||
if (emitterMode.value !== undefined) { | ||
const defaultCount = 1; | ||
if (isArray(emitterMode.value)) { | ||
options.interactivity.modes.emitters = { | ||
random: { | ||
count: emitterMode.random.count ?? defaultCount, | ||
enable: emitterMode.random.enable ?? false, | ||
}, | ||
value: emitterMode.value.map((s) => { | ||
const tmp = new Emitter(); | ||
tmp.load(s); | ||
return tmp; | ||
}), | ||
}; | ||
} | ||
else { | ||
const tmp = new Emitter(); | ||
tmp.load(emitterMode.value); | ||
options.interactivity.modes.emitters = { | ||
random: { | ||
count: emitterMode.random.count ?? defaultCount, | ||
enable: emitterMode.random.enable ?? false, | ||
}, | ||
value: tmp, | ||
}; | ||
} | ||
} | ||
else { | ||
const emitterOptions = (options.interactivity.modes.emitters = { | ||
random: { | ||
count: 1, | ||
enable: false, | ||
}, | ||
value: new Emitter(), | ||
}); | ||
emitterOptions.value.load(interactivityEmitters); | ||
} | ||
} | ||
} | ||
} | ||
needsPlugin(options) { | ||
if (!options) { | ||
return false; | ||
} | ||
const emitters = options.emitters; | ||
return ((isArray(emitters) && !!emitters.length) || | ||
emitters !== undefined || | ||
(!!options.interactivity?.events?.onClick?.mode && | ||
isInArray("emitter", options.interactivity.events.onClick.mode))); | ||
} | ||
} | ||
export async function loadEmittersPlugin(engine, refresh = true) { | ||
if (!engine.emitterShapeManager) { | ||
const { ShapeManager } = await import("./ShapeManager.js"); | ||
engine.emitterShapeManager = new ShapeManager(engine); | ||
@@ -101,3 +11,3 @@ } | ||
} | ||
const plugin = new EmittersPlugin(engine); | ||
const { EmittersPlugin } = await import("./EmittersPlugin.js"), plugin = new EmittersPlugin(engine); | ||
await engine.addPlugin(plugin, refresh); | ||
@@ -104,0 +14,0 @@ } |
@@ -7,3 +7,3 @@ "use strict"; | ||
const EmitterSize_js_1 = require("./Options/Classes/EmitterSize.js"); | ||
const half = 0.5, defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1; | ||
const half = 0.5, defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1, defaultColorAnimationFactor = 1; | ||
function setParticlesOptionsColor(particlesOptions, color) { | ||
@@ -48,3 +48,3 @@ if (particlesOptions.color) { | ||
}; | ||
this._setColorAnimation = (animation, initValue, maxValue) => { | ||
this._setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => { | ||
const container = this.container; | ||
@@ -54,4 +54,4 @@ if (!animation.enable) { | ||
} | ||
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, colorFactor = 3.6, colorSpeed = (0, engine_1.getRangeValue)(animation.speed ?? defaultColorSpeed); | ||
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * colorFactor) % maxValue; | ||
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); | ||
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * factor) % maxValue; | ||
}; | ||
@@ -221,5 +221,5 @@ this._engine = engine; | ||
if (this.options.domId) { | ||
const container = this.container, element = document.getElementById(this.options.domId); | ||
const element = document.getElementById(this.options.domId); | ||
if (element) { | ||
const elRect = element.getBoundingClientRect(), pxRatio = container.retina.pixelRatio; | ||
const elRect = element.getBoundingClientRect(), pxRatio = this.container.retina.pixelRatio; | ||
return { | ||
@@ -278,4 +278,4 @@ x: (elRect.x + elRect.width * half) * pxRatio, | ||
l: 100, | ||
}; | ||
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h); | ||
}, colorFactor = 3.6; | ||
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h, colorFactor); | ||
this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, maxValues.s); | ||
@@ -312,3 +312,3 @@ this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, maxValues.l); | ||
if (position) { | ||
this.container.particles.addParticle(position, particlesOptions); | ||
await this.container.particles.addParticle(position, particlesOptions); | ||
} | ||
@@ -315,0 +315,0 @@ } |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Emitters = void 0; | ||
const engine_1 = require("@tsparticles/engine"); | ||
const Emitter_js_1 = require("./Options/Classes/Emitter.js"); | ||
const EmitterInstance_js_1 = require("./EmitterInstance.js"); | ||
class Emitters { | ||
@@ -45,5 +66,5 @@ constructor(engine, container) { | ||
async addEmitter(options, position) { | ||
const emitterOptions = new Emitter_js_1.Emitter(); | ||
const { Emitter } = await Promise.resolve().then(() => __importStar(require("./Options/Classes/Emitter.js"))), { EmitterInstance } = await Promise.resolve().then(() => __importStar(require("./EmitterInstance.js"))), emitterOptions = new Emitter(); | ||
emitterOptions.load(options); | ||
const emitter = new EmitterInstance_js_1.EmitterInstance(this._engine, this, this.container, emitterOptions, position); | ||
const emitter = new EmitterInstance(this._engine, this, this.container, emitterOptions, position); | ||
await emitter.init(); | ||
@@ -50,0 +71,0 @@ this.array.push(emitter); |
108
cjs/index.js
@@ -13,2 +13,14 @@ "use strict"; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
@@ -19,96 +31,6 @@ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
exports.loadEmittersPlugin = void 0; | ||
const engine_1 = require("@tsparticles/engine"); | ||
const Emitter_js_1 = require("./Options/Classes/Emitter.js"); | ||
const Emitters_js_1 = require("./Emitters.js"); | ||
const ShapeManager_js_1 = require("./ShapeManager.js"); | ||
class EmittersPlugin { | ||
constructor(engine) { | ||
this._engine = engine; | ||
this.id = "emitters"; | ||
} | ||
getPlugin(container) { | ||
return new Emitters_js_1.Emitters(this._engine, container); | ||
} | ||
loadOptions(options, source) { | ||
if (!this.needsPlugin(options) && !this.needsPlugin(source)) { | ||
return; | ||
} | ||
if (source?.emitters) { | ||
options.emitters = (0, engine_1.executeOnSingleOrMultiple)(source.emitters, (emitter) => { | ||
const tmp = new Emitter_js_1.Emitter(); | ||
tmp.load(emitter); | ||
return tmp; | ||
}); | ||
} | ||
const interactivityEmitters = source?.interactivity?.modes?.emitters; | ||
if (interactivityEmitters) { | ||
if ((0, engine_1.isArray)(interactivityEmitters)) { | ||
options.interactivity.modes.emitters = { | ||
random: { | ||
count: 1, | ||
enable: true, | ||
}, | ||
value: interactivityEmitters.map((s) => { | ||
const tmp = new Emitter_js_1.Emitter(); | ||
tmp.load(s); | ||
return tmp; | ||
}), | ||
}; | ||
} | ||
else { | ||
const emitterMode = interactivityEmitters; | ||
if (emitterMode.value !== undefined) { | ||
const defaultCount = 1; | ||
if ((0, engine_1.isArray)(emitterMode.value)) { | ||
options.interactivity.modes.emitters = { | ||
random: { | ||
count: emitterMode.random.count ?? defaultCount, | ||
enable: emitterMode.random.enable ?? false, | ||
}, | ||
value: emitterMode.value.map((s) => { | ||
const tmp = new Emitter_js_1.Emitter(); | ||
tmp.load(s); | ||
return tmp; | ||
}), | ||
}; | ||
} | ||
else { | ||
const tmp = new Emitter_js_1.Emitter(); | ||
tmp.load(emitterMode.value); | ||
options.interactivity.modes.emitters = { | ||
random: { | ||
count: emitterMode.random.count ?? defaultCount, | ||
enable: emitterMode.random.enable ?? false, | ||
}, | ||
value: tmp, | ||
}; | ||
} | ||
} | ||
else { | ||
const emitterOptions = (options.interactivity.modes.emitters = { | ||
random: { | ||
count: 1, | ||
enable: false, | ||
}, | ||
value: new Emitter_js_1.Emitter(), | ||
}); | ||
emitterOptions.value.load(interactivityEmitters); | ||
} | ||
} | ||
} | ||
} | ||
needsPlugin(options) { | ||
if (!options) { | ||
return false; | ||
} | ||
const emitters = options.emitters; | ||
return (((0, engine_1.isArray)(emitters) && !!emitters.length) || | ||
emitters !== undefined || | ||
(!!options.interactivity?.events?.onClick?.mode && | ||
(0, engine_1.isInArray)("emitter", options.interactivity.events.onClick.mode))); | ||
} | ||
} | ||
async function loadEmittersPlugin(engine, refresh = true) { | ||
if (!engine.emitterShapeManager) { | ||
engine.emitterShapeManager = new ShapeManager_js_1.ShapeManager(engine); | ||
const { ShapeManager } = await Promise.resolve().then(() => __importStar(require("./ShapeManager.js"))); | ||
engine.emitterShapeManager = new ShapeManager(engine); | ||
} | ||
@@ -120,3 +42,3 @@ if (!engine.addEmitterShapeGenerator) { | ||
} | ||
const plugin = new EmittersPlugin(engine); | ||
const { EmittersPlugin } = await Promise.resolve().then(() => __importStar(require("./EmittersPlugin.js"))), plugin = new EmittersPlugin(engine); | ||
await engine.addPlugin(plugin, refresh); | ||
@@ -123,0 +45,0 @@ } |
import { Vector, calcPositionOrRandomFromSizeRanged, deepExtend, getRangeValue, getSize, isPointInside, itemFromSingleOrMultiple, millisecondsToSeconds, randomInRange, rangeColorToHsl, } from "@tsparticles/engine"; | ||
import { Emitter } from "./Options/Classes/Emitter.js"; | ||
import { EmitterSize } from "./Options/Classes/EmitterSize.js"; | ||
const half = 0.5, defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1; | ||
const half = 0.5, defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1, defaultColorAnimationFactor = 1; | ||
function setParticlesOptionsColor(particlesOptions, color) { | ||
@@ -44,3 +44,3 @@ if (particlesOptions.color) { | ||
}; | ||
this._setColorAnimation = (animation, initValue, maxValue) => { | ||
this._setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => { | ||
const container = this.container; | ||
@@ -50,4 +50,4 @@ if (!animation.enable) { | ||
} | ||
const colorOffset = randomInRange(animation.offset), delay = getRangeValue(this.options.rate.delay), emitFactor = (delay * millisecondsToSeconds) / container.retina.reduceFactor, defaultColorSpeed = 0, colorFactor = 3.6, colorSpeed = getRangeValue(animation.speed ?? defaultColorSpeed); | ||
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * colorFactor) % maxValue; | ||
const colorOffset = randomInRange(animation.offset), delay = getRangeValue(this.options.rate.delay), emitFactor = (delay * millisecondsToSeconds) / container.retina.reduceFactor, defaultColorSpeed = 0, colorSpeed = getRangeValue(animation.speed ?? defaultColorSpeed); | ||
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * factor) % maxValue; | ||
}; | ||
@@ -217,5 +217,5 @@ this._engine = engine; | ||
if (this.options.domId) { | ||
const container = this.container, element = document.getElementById(this.options.domId); | ||
const element = document.getElementById(this.options.domId); | ||
if (element) { | ||
const elRect = element.getBoundingClientRect(), pxRatio = container.retina.pixelRatio; | ||
const elRect = element.getBoundingClientRect(), pxRatio = this.container.retina.pixelRatio; | ||
return { | ||
@@ -274,4 +274,4 @@ x: (elRect.x + elRect.width * half) * pxRatio, | ||
l: 100, | ||
}; | ||
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h); | ||
}, colorFactor = 3.6; | ||
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h, colorFactor); | ||
this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, maxValues.s); | ||
@@ -308,3 +308,3 @@ this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, maxValues.l); | ||
if (position) { | ||
this.container.particles.addParticle(position, particlesOptions); | ||
await this.container.particles.addParticle(position, particlesOptions); | ||
} | ||
@@ -311,0 +311,0 @@ } |
import { arrayRandomIndex, executeOnSingleOrMultiple, isArray, isNumber, itemFromArray, } from "@tsparticles/engine"; | ||
import { Emitter } from "./Options/Classes/Emitter.js"; | ||
import { EmitterInstance } from "./EmitterInstance.js"; | ||
export class Emitters { | ||
@@ -42,3 +40,3 @@ constructor(engine, container) { | ||
async addEmitter(options, position) { | ||
const emitterOptions = new Emitter(); | ||
const { Emitter } = await import("./Options/Classes/Emitter.js"), { EmitterInstance } = await import("./EmitterInstance.js"), emitterOptions = new Emitter(); | ||
emitterOptions.load(options); | ||
@@ -45,0 +43,0 @@ const emitter = new EmitterInstance(this._engine, this, this.container, emitterOptions, position); |
@@ -1,94 +0,4 @@ | ||
import { executeOnSingleOrMultiple, isArray, isInArray, } from "@tsparticles/engine"; | ||
import { Emitter } from "./Options/Classes/Emitter.js"; | ||
import { Emitters } from "./Emitters.js"; | ||
import { ShapeManager } from "./ShapeManager.js"; | ||
class EmittersPlugin { | ||
constructor(engine) { | ||
this._engine = engine; | ||
this.id = "emitters"; | ||
} | ||
getPlugin(container) { | ||
return new Emitters(this._engine, container); | ||
} | ||
loadOptions(options, source) { | ||
if (!this.needsPlugin(options) && !this.needsPlugin(source)) { | ||
return; | ||
} | ||
if (source?.emitters) { | ||
options.emitters = executeOnSingleOrMultiple(source.emitters, (emitter) => { | ||
const tmp = new Emitter(); | ||
tmp.load(emitter); | ||
return tmp; | ||
}); | ||
} | ||
const interactivityEmitters = source?.interactivity?.modes?.emitters; | ||
if (interactivityEmitters) { | ||
if (isArray(interactivityEmitters)) { | ||
options.interactivity.modes.emitters = { | ||
random: { | ||
count: 1, | ||
enable: true, | ||
}, | ||
value: interactivityEmitters.map((s) => { | ||
const tmp = new Emitter(); | ||
tmp.load(s); | ||
return tmp; | ||
}), | ||
}; | ||
} | ||
else { | ||
const emitterMode = interactivityEmitters; | ||
if (emitterMode.value !== undefined) { | ||
const defaultCount = 1; | ||
if (isArray(emitterMode.value)) { | ||
options.interactivity.modes.emitters = { | ||
random: { | ||
count: emitterMode.random.count ?? defaultCount, | ||
enable: emitterMode.random.enable ?? false, | ||
}, | ||
value: emitterMode.value.map((s) => { | ||
const tmp = new Emitter(); | ||
tmp.load(s); | ||
return tmp; | ||
}), | ||
}; | ||
} | ||
else { | ||
const tmp = new Emitter(); | ||
tmp.load(emitterMode.value); | ||
options.interactivity.modes.emitters = { | ||
random: { | ||
count: emitterMode.random.count ?? defaultCount, | ||
enable: emitterMode.random.enable ?? false, | ||
}, | ||
value: tmp, | ||
}; | ||
} | ||
} | ||
else { | ||
const emitterOptions = (options.interactivity.modes.emitters = { | ||
random: { | ||
count: 1, | ||
enable: false, | ||
}, | ||
value: new Emitter(), | ||
}); | ||
emitterOptions.value.load(interactivityEmitters); | ||
} | ||
} | ||
} | ||
} | ||
needsPlugin(options) { | ||
if (!options) { | ||
return false; | ||
} | ||
const emitters = options.emitters; | ||
return ((isArray(emitters) && !!emitters.length) || | ||
emitters !== undefined || | ||
(!!options.interactivity?.events?.onClick?.mode && | ||
isInArray("emitter", options.interactivity.events.onClick.mode))); | ||
} | ||
} | ||
export async function loadEmittersPlugin(engine, refresh = true) { | ||
if (!engine.emitterShapeManager) { | ||
const { ShapeManager } = await import("./ShapeManager.js"); | ||
engine.emitterShapeManager = new ShapeManager(engine); | ||
@@ -101,3 +11,3 @@ } | ||
} | ||
const plugin = new EmittersPlugin(engine); | ||
const { EmittersPlugin } = await import("./EmittersPlugin.js"), plugin = new EmittersPlugin(engine); | ||
await engine.addPlugin(plugin, refresh); | ||
@@ -104,0 +14,0 @@ } |
{ | ||
"name": "@tsparticles/plugin-emitters", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "tsParticles emitters plugin", | ||
@@ -89,3 +89,3 @@ "homepage": "https://particles.js.org", | ||
"dependencies": { | ||
"@tsparticles/engine": "^3.1.0" | ||
"@tsparticles/engine": "^3.2.0" | ||
}, | ||
@@ -92,0 +92,0 @@ "publishConfig": { |
@@ -7,4 +7,12 @@ /*! | ||
* How to use? : Check the GitHub README | ||
* v3.1.0 | ||
* v3.2.0 | ||
*/ | ||
/* | ||
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development"). | ||
* This devtool is neither made for production nor for readable output files. | ||
* It uses "eval()" calls to create a separate source file in the browser devtools. | ||
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/) | ||
* or disable the default devtool with "devtool: false". | ||
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/). | ||
*/ | ||
(function webpackUniversalModuleDefinition(root, factory) { | ||
@@ -19,3 +27,3 @@ if(typeof exports === 'object' && typeof module === 'object') | ||
} | ||
})(this, (__WEBPACK_EXTERNAL_MODULE__533__) => { | ||
})(this, (__WEBPACK_EXTERNAL_MODULE__tsparticles_engine__) => { | ||
return /******/ (() => { // webpackBootstrap | ||
@@ -25,6 +33,29 @@ /******/ "use strict"; | ||
/***/ 533: | ||
/***/ "./dist/browser/EmitterShapeBase.js": | ||
/*!******************************************!*\ | ||
!*** ./dist/browser/EmitterShapeBase.js ***! | ||
\******************************************/ | ||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { | ||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ EmitterShapeBase: () => (/* binding */ EmitterShapeBase)\n/* harmony export */ });\nclass EmitterShapeBase {\n constructor(position, size, fill, options) {\n this.position = position;\n this.size = size;\n this.fill = fill;\n this.options = options;\n }\n resize(position, size) {\n this.position = position;\n this.size = size;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters/./dist/browser/EmitterShapeBase.js?"); | ||
/***/ }), | ||
/***/ "./dist/browser/index.js": | ||
/*!*******************************!*\ | ||
!*** ./dist/browser/index.js ***! | ||
\*******************************/ | ||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { | ||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ EmitterShapeBase: () => (/* reexport safe */ _EmitterShapeBase_js__WEBPACK_IMPORTED_MODULE_0__.EmitterShapeBase),\n/* harmony export */ loadEmittersPlugin: () => (/* binding */ loadEmittersPlugin)\n/* harmony export */ });\n/* harmony import */ var _EmitterShapeBase_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./EmitterShapeBase.js */ \"./dist/browser/EmitterShapeBase.js\");\nasync function loadEmittersPlugin(engine, refresh = true) {\n if (!engine.emitterShapeManager) {\n const {\n ShapeManager\n } = await __webpack_require__.e(/*! import() */ \"dist_browser_ShapeManager_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./ShapeManager.js */ \"./dist/browser/ShapeManager.js\"));\n engine.emitterShapeManager = new ShapeManager(engine);\n }\n if (!engine.addEmitterShapeGenerator) {\n engine.addEmitterShapeGenerator = (name, generator) => {\n engine.emitterShapeManager?.addShapeGenerator(name, generator);\n };\n }\n const {\n EmittersPlugin\n } = await __webpack_require__.e(/*! import() */ \"dist_browser_EmittersPlugin_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./EmittersPlugin.js */ \"./dist/browser/EmittersPlugin.js\")),\n plugin = new EmittersPlugin(engine);\n await engine.addPlugin(plugin, refresh);\n}\n\n\n\n\n\n\n\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters/./dist/browser/index.js?"); | ||
/***/ }), | ||
/***/ "@tsparticles/engine": | ||
/*!*********************************************************************************************************************************!*\ | ||
!*** external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"} ***! | ||
\*********************************************************************************************************************************/ | ||
/***/ ((module) => { | ||
module.exports = __WEBPACK_EXTERNAL_MODULE__533__; | ||
module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__; | ||
@@ -59,3 +90,18 @@ /***/ }) | ||
/******/ | ||
/******/ // expose the modules object (__webpack_modules__) | ||
/******/ __webpack_require__.m = __webpack_modules__; | ||
/******/ | ||
/************************************************************************/ | ||
/******/ /* webpack/runtime/compat get default export */ | ||
/******/ (() => { | ||
/******/ // getDefaultExport function for compatibility with non-harmony modules | ||
/******/ __webpack_require__.n = (module) => { | ||
/******/ var getter = module && module.__esModule ? | ||
/******/ () => (module['default']) : | ||
/******/ () => (module); | ||
/******/ __webpack_require__.d(getter, { a: getter }); | ||
/******/ return getter; | ||
/******/ }; | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/define property getters */ | ||
@@ -73,2 +119,36 @@ /******/ (() => { | ||
/******/ | ||
/******/ /* webpack/runtime/ensure chunk */ | ||
/******/ (() => { | ||
/******/ __webpack_require__.f = {}; | ||
/******/ // This file contains only the entry chunk. | ||
/******/ // The chunk loading function for additional chunks | ||
/******/ __webpack_require__.e = (chunkId) => { | ||
/******/ return Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key) => { | ||
/******/ __webpack_require__.f[key](chunkId, promises); | ||
/******/ return promises; | ||
/******/ }, [])); | ||
/******/ }; | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/get javascript chunk filename */ | ||
/******/ (() => { | ||
/******/ // This function allow to reference async chunks | ||
/******/ __webpack_require__.u = (chunkId) => { | ||
/******/ // return url for filenames based on template | ||
/******/ return "" + chunkId + ".js"; | ||
/******/ }; | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/global */ | ||
/******/ (() => { | ||
/******/ __webpack_require__.g = (function() { | ||
/******/ if (typeof globalThis === 'object') return globalThis; | ||
/******/ try { | ||
/******/ return this || new Function('return this')(); | ||
/******/ } catch (e) { | ||
/******/ if (typeof window === 'object') return window; | ||
/******/ } | ||
/******/ })(); | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/hasOwnProperty shorthand */ | ||
@@ -79,2 +159,48 @@ /******/ (() => { | ||
/******/ | ||
/******/ /* webpack/runtime/load script */ | ||
/******/ (() => { | ||
/******/ var inProgress = {}; | ||
/******/ var dataWebpackPrefix = "@tsparticles/plugin-emitters:"; | ||
/******/ // loadScript function to load a script via script tag | ||
/******/ __webpack_require__.l = (url, done, key, chunkId) => { | ||
/******/ if(inProgress[url]) { inProgress[url].push(done); return; } | ||
/******/ var script, needAttach; | ||
/******/ if(key !== undefined) { | ||
/******/ var scripts = document.getElementsByTagName("script"); | ||
/******/ for(var i = 0; i < scripts.length; i++) { | ||
/******/ var s = scripts[i]; | ||
/******/ if(s.getAttribute("src") == url || s.getAttribute("data-webpack") == dataWebpackPrefix + key) { script = s; break; } | ||
/******/ } | ||
/******/ } | ||
/******/ if(!script) { | ||
/******/ needAttach = true; | ||
/******/ script = document.createElement('script'); | ||
/******/ | ||
/******/ script.charset = 'utf-8'; | ||
/******/ script.timeout = 120; | ||
/******/ if (__webpack_require__.nc) { | ||
/******/ script.setAttribute("nonce", __webpack_require__.nc); | ||
/******/ } | ||
/******/ script.setAttribute("data-webpack", dataWebpackPrefix + key); | ||
/******/ | ||
/******/ script.src = url; | ||
/******/ } | ||
/******/ inProgress[url] = [done]; | ||
/******/ var onScriptComplete = (prev, event) => { | ||
/******/ // avoid mem leaks in IE. | ||
/******/ script.onerror = script.onload = null; | ||
/******/ clearTimeout(timeout); | ||
/******/ var doneFns = inProgress[url]; | ||
/******/ delete inProgress[url]; | ||
/******/ script.parentNode && script.parentNode.removeChild(script); | ||
/******/ doneFns && doneFns.forEach((fn) => (fn(event))); | ||
/******/ if(prev) return prev(event); | ||
/******/ } | ||
/******/ var timeout = setTimeout(onScriptComplete.bind(null, undefined, { type: 'timeout', target: script }), 120000); | ||
/******/ script.onerror = onScriptComplete.bind(null, script.onerror); | ||
/******/ script.onload = onScriptComplete.bind(null, script.onload); | ||
/******/ needAttach && document.head.appendChild(script); | ||
/******/ }; | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/make namespace object */ | ||
@@ -91,754 +217,124 @@ /******/ (() => { | ||
/******/ | ||
/******/ /* webpack/runtime/publicPath */ | ||
/******/ (() => { | ||
/******/ var scriptUrl; | ||
/******/ if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + ""; | ||
/******/ var document = __webpack_require__.g.document; | ||
/******/ if (!scriptUrl && document) { | ||
/******/ if (document.currentScript) | ||
/******/ scriptUrl = document.currentScript.src; | ||
/******/ if (!scriptUrl) { | ||
/******/ var scripts = document.getElementsByTagName("script"); | ||
/******/ if(scripts.length) { | ||
/******/ var i = scripts.length - 1; | ||
/******/ while (i > -1 && !scriptUrl) scriptUrl = scripts[i--].src; | ||
/******/ } | ||
/******/ } | ||
/******/ } | ||
/******/ // When supporting browsers where an automatic publicPath is not supported you must specify an output.publicPath manually via configuration | ||
/******/ // or pass an empty string ("") and set the __webpack_public_path__ variable from your code to use your own logic. | ||
/******/ if (!scriptUrl) throw new Error("Automatic publicPath is not supported in this browser"); | ||
/******/ scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/"); | ||
/******/ __webpack_require__.p = scriptUrl; | ||
/******/ })(); | ||
/******/ | ||
/******/ /* webpack/runtime/jsonp chunk loading */ | ||
/******/ (() => { | ||
/******/ // no baseURI | ||
/******/ | ||
/******/ // object to store loaded and loading chunks | ||
/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched | ||
/******/ // [resolve, reject, Promise] = chunk loading, 0 = chunk loaded | ||
/******/ var installedChunks = { | ||
/******/ "tsparticles.plugin.emitters": 0 | ||
/******/ }; | ||
/******/ | ||
/******/ __webpack_require__.f.j = (chunkId, promises) => { | ||
/******/ // JSONP chunk loading for javascript | ||
/******/ var installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : undefined; | ||
/******/ if(installedChunkData !== 0) { // 0 means "already installed". | ||
/******/ | ||
/******/ // a Promise means "currently loading". | ||
/******/ if(installedChunkData) { | ||
/******/ promises.push(installedChunkData[2]); | ||
/******/ } else { | ||
/******/ if(true) { // all chunks have JS | ||
/******/ // setup Promise in chunk cache | ||
/******/ var promise = new Promise((resolve, reject) => (installedChunkData = installedChunks[chunkId] = [resolve, reject])); | ||
/******/ promises.push(installedChunkData[2] = promise); | ||
/******/ | ||
/******/ // start chunk loading | ||
/******/ var url = __webpack_require__.p + __webpack_require__.u(chunkId); | ||
/******/ // create error before stack unwound to get useful stacktrace later | ||
/******/ var error = new Error(); | ||
/******/ var loadingEnded = (event) => { | ||
/******/ if(__webpack_require__.o(installedChunks, chunkId)) { | ||
/******/ installedChunkData = installedChunks[chunkId]; | ||
/******/ if(installedChunkData !== 0) installedChunks[chunkId] = undefined; | ||
/******/ if(installedChunkData) { | ||
/******/ var errorType = event && (event.type === 'load' ? 'missing' : event.type); | ||
/******/ var realSrc = event && event.target && event.target.src; | ||
/******/ error.message = 'Loading chunk ' + chunkId + ' failed.\n(' + errorType + ': ' + realSrc + ')'; | ||
/******/ error.name = 'ChunkLoadError'; | ||
/******/ error.type = errorType; | ||
/******/ error.request = realSrc; | ||
/******/ installedChunkData[1](error); | ||
/******/ } | ||
/******/ } | ||
/******/ }; | ||
/******/ __webpack_require__.l(url, loadingEnded, "chunk-" + chunkId, chunkId); | ||
/******/ } | ||
/******/ } | ||
/******/ } | ||
/******/ }; | ||
/******/ | ||
/******/ // no prefetching | ||
/******/ | ||
/******/ // no preloaded | ||
/******/ | ||
/******/ // no HMR | ||
/******/ | ||
/******/ // no HMR manifest | ||
/******/ | ||
/******/ // no on chunks loaded | ||
/******/ | ||
/******/ // install a JSONP callback for chunk loading | ||
/******/ var webpackJsonpCallback = (parentChunkLoadingFunction, data) => { | ||
/******/ var chunkIds = data[0]; | ||
/******/ var moreModules = data[1]; | ||
/******/ var runtime = data[2]; | ||
/******/ // add "moreModules" to the modules object, | ||
/******/ // then flag all "chunkIds" as loaded and fire callback | ||
/******/ var moduleId, chunkId, i = 0; | ||
/******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) { | ||
/******/ for(moduleId in moreModules) { | ||
/******/ if(__webpack_require__.o(moreModules, moduleId)) { | ||
/******/ __webpack_require__.m[moduleId] = moreModules[moduleId]; | ||
/******/ } | ||
/******/ } | ||
/******/ if(runtime) var result = runtime(__webpack_require__); | ||
/******/ } | ||
/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data); | ||
/******/ for(;i < chunkIds.length; i++) { | ||
/******/ chunkId = chunkIds[i]; | ||
/******/ if(__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) { | ||
/******/ installedChunks[chunkId][0](); | ||
/******/ } | ||
/******/ installedChunks[chunkId] = 0; | ||
/******/ } | ||
/******/ | ||
/******/ } | ||
/******/ | ||
/******/ var chunkLoadingGlobal = this["webpackChunk_tsparticles_plugin_emitters"] = this["webpackChunk_tsparticles_plugin_emitters"] || []; | ||
/******/ chunkLoadingGlobal.forEach(webpackJsonpCallback.bind(null, 0)); | ||
/******/ chunkLoadingGlobal.push = webpackJsonpCallback.bind(null, chunkLoadingGlobal.push.bind(chunkLoadingGlobal)); | ||
/******/ })(); | ||
/******/ | ||
/************************************************************************/ | ||
var __webpack_exports__ = {}; | ||
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. | ||
(() => { | ||
// ESM COMPAT FLAG | ||
__webpack_require__.r(__webpack_exports__); | ||
// EXPORTS | ||
__webpack_require__.d(__webpack_exports__, { | ||
EmitterShapeBase: () => (/* reexport */ EmitterShapeBase), | ||
loadEmittersPlugin: () => (/* binding */ loadEmittersPlugin) | ||
}); | ||
// EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"} | ||
var engine_root_window_ = __webpack_require__(533); | ||
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/EmitterLife.js | ||
class EmitterLife { | ||
constructor() { | ||
this.wait = false; | ||
} | ||
load(data) { | ||
if (!data) { | ||
return; | ||
} | ||
if (data.count !== undefined) { | ||
this.count = data.count; | ||
} | ||
if (data.delay !== undefined) { | ||
this.delay = (0,engine_root_window_.setRangeValue)(data.delay); | ||
} | ||
if (data.duration !== undefined) { | ||
this.duration = (0,engine_root_window_.setRangeValue)(data.duration); | ||
} | ||
if (data.wait !== undefined) { | ||
this.wait = data.wait; | ||
} | ||
} | ||
} | ||
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/EmitterRate.js | ||
class EmitterRate { | ||
constructor() { | ||
this.quantity = 1; | ||
this.delay = 0.1; | ||
} | ||
load(data) { | ||
if (data === undefined) { | ||
return; | ||
} | ||
if (data.quantity !== undefined) { | ||
this.quantity = (0,engine_root_window_.setRangeValue)(data.quantity); | ||
} | ||
if (data.delay !== undefined) { | ||
this.delay = (0,engine_root_window_.setRangeValue)(data.delay); | ||
} | ||
} | ||
} | ||
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/EmitterShapeReplace.js | ||
class EmitterShapeReplace { | ||
constructor() { | ||
this.color = false; | ||
this.opacity = false; | ||
} | ||
load(data) { | ||
if (!data) { | ||
return; | ||
} | ||
if (data.color !== undefined) { | ||
this.color = data.color; | ||
} | ||
if (data.opacity !== undefined) { | ||
this.opacity = data.opacity; | ||
} | ||
} | ||
} | ||
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/EmitterShape.js | ||
class EmitterShape { | ||
constructor() { | ||
this.options = {}; | ||
this.replace = new EmitterShapeReplace(); | ||
this.type = "square"; | ||
} | ||
load(data) { | ||
if (!data) { | ||
return; | ||
} | ||
if (data.options !== undefined) { | ||
this.options = (0,engine_root_window_.deepExtend)({}, data.options ?? {}); | ||
} | ||
this.replace.load(data.replace); | ||
if (data.type !== undefined) { | ||
this.type = data.type; | ||
} | ||
} | ||
} | ||
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/EmitterSize.js | ||
class EmitterSize { | ||
constructor() { | ||
this.mode = "percent"; | ||
this.height = 0; | ||
this.width = 0; | ||
} | ||
load(data) { | ||
if (data === undefined) { | ||
return; | ||
} | ||
if (data.mode !== undefined) { | ||
this.mode = data.mode; | ||
} | ||
if (data.height !== undefined) { | ||
this.height = data.height; | ||
} | ||
if (data.width !== undefined) { | ||
this.width = data.width; | ||
} | ||
} | ||
} | ||
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/Emitter.js | ||
class Emitter { | ||
constructor() { | ||
this.autoPlay = true; | ||
this.fill = true; | ||
this.life = new EmitterLife(); | ||
this.rate = new EmitterRate(); | ||
this.shape = new EmitterShape(); | ||
this.startCount = 0; | ||
} | ||
load(data) { | ||
if (!data) { | ||
return; | ||
} | ||
if (data.autoPlay !== undefined) { | ||
this.autoPlay = data.autoPlay; | ||
} | ||
if (data.size !== undefined) { | ||
if (!this.size) { | ||
this.size = new EmitterSize(); | ||
} | ||
this.size.load(data.size); | ||
} | ||
if (data.direction !== undefined) { | ||
this.direction = data.direction; | ||
} | ||
this.domId = data.domId; | ||
if (data.fill !== undefined) { | ||
this.fill = data.fill; | ||
} | ||
this.life.load(data.life); | ||
this.name = data.name; | ||
this.particles = (0,engine_root_window_.executeOnSingleOrMultiple)(data.particles, particles => { | ||
return (0,engine_root_window_.deepExtend)({}, particles); | ||
}); | ||
this.rate.load(data.rate); | ||
this.shape.load(data.shape); | ||
if (data.position !== undefined) { | ||
this.position = {}; | ||
if (data.position.x !== undefined) { | ||
this.position.x = (0,engine_root_window_.setRangeValue)(data.position.x); | ||
} | ||
if (data.position.y !== undefined) { | ||
this.position.y = (0,engine_root_window_.setRangeValue)(data.position.y); | ||
} | ||
} | ||
if (data.spawnColor !== undefined) { | ||
if (this.spawnColor === undefined) { | ||
this.spawnColor = new engine_root_window_.AnimatableColor(); | ||
} | ||
this.spawnColor.load(data.spawnColor); | ||
} | ||
if (data.startCount !== undefined) { | ||
this.startCount = data.startCount; | ||
} | ||
} | ||
} | ||
;// CONCATENATED MODULE: ./dist/browser/EmitterInstance.js | ||
const half = 0.5, | ||
defaultLifeDelay = 0, | ||
minLifeCount = 0, | ||
defaultSpawnDelay = 0, | ||
defaultEmitDelay = 0, | ||
defaultLifeCount = -1; | ||
function setParticlesOptionsColor(particlesOptions, color) { | ||
if (particlesOptions.color) { | ||
particlesOptions.color.value = color; | ||
} else { | ||
particlesOptions.color = { | ||
value: color | ||
}; | ||
} | ||
} | ||
class EmitterInstance { | ||
constructor(engine, emitters, container, options, position) { | ||
this.emitters = emitters; | ||
this.container = container; | ||
this._destroy = () => { | ||
this._mutationObserver?.disconnect(); | ||
this._mutationObserver = undefined; | ||
this._resizeObserver?.disconnect(); | ||
this._resizeObserver = undefined; | ||
this.emitters.removeEmitter(this); | ||
this._engine.dispatchEvent("emitterDestroyed", { | ||
container: this.container, | ||
data: { | ||
emitter: this | ||
} | ||
}); | ||
}; | ||
this._prepareToDie = () => { | ||
if (this._paused) { | ||
return; | ||
} | ||
const duration = this.options.life?.duration !== undefined ? (0,engine_root_window_.getRangeValue)(this.options.life.duration) : undefined, | ||
minDuration = 0, | ||
minLifeCount = 0; | ||
if (this.container.retina.reduceFactor && (this._lifeCount > minLifeCount || this._immortal) && duration !== undefined && duration > minDuration) { | ||
this._duration = duration * engine_root_window_.millisecondsToSeconds; | ||
} | ||
}; | ||
this._setColorAnimation = (animation, initValue, maxValue) => { | ||
const container = this.container; | ||
if (!animation.enable) { | ||
return initValue; | ||
} | ||
const colorOffset = (0,engine_root_window_.randomInRange)(animation.offset), | ||
delay = (0,engine_root_window_.getRangeValue)(this.options.rate.delay), | ||
emitFactor = delay * engine_root_window_.millisecondsToSeconds / container.retina.reduceFactor, | ||
defaultColorSpeed = 0, | ||
colorFactor = 3.6, | ||
colorSpeed = (0,engine_root_window_.getRangeValue)(animation.speed ?? defaultColorSpeed); | ||
return (initValue + colorSpeed * container.fpsLimit / emitFactor + colorOffset * colorFactor) % maxValue; | ||
}; | ||
this._engine = engine; | ||
this._currentDuration = 0; | ||
this._currentEmitDelay = 0; | ||
this._currentSpawnDelay = 0; | ||
this._initialPosition = position; | ||
if (options instanceof Emitter) { | ||
this.options = options; | ||
} else { | ||
this.options = new Emitter(); | ||
this.options.load(options); | ||
} | ||
this._spawnDelay = (0,engine_root_window_.getRangeValue)(this.options.life.delay ?? defaultLifeDelay) * engine_root_window_.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 = false; | ||
let particlesOptions = (0,engine_root_window_.deepExtend)({}, this.options.particles); | ||
particlesOptions ??= {}; | ||
particlesOptions.move ??= {}; | ||
particlesOptions.move.direction ??= this.options.direction; | ||
if (this.options.spawnColor) { | ||
this.spawnColor = (0,engine_root_window_.rangeColorToHsl)(this.options.spawnColor); | ||
} | ||
this._paused = !this.options.autoPlay; | ||
this._particlesOptions = particlesOptions; | ||
this._size = this._calcSize(); | ||
this.size = (0,engine_root_window_.getSize)(this._size, this.container.canvas.size); | ||
this._lifeCount = this.options.life.count ?? defaultLifeCount; | ||
this._immortal = this._lifeCount <= minLifeCount; | ||
if (this.options.domId) { | ||
const element = document.getElementById(this.options.domId); | ||
if (element) { | ||
this._mutationObserver = new MutationObserver(() => { | ||
this.resize(); | ||
}); | ||
this._resizeObserver = new ResizeObserver(() => { | ||
this.resize(); | ||
}); | ||
this._mutationObserver.observe(element, { | ||
attributes: true, | ||
attributeFilter: ["style", "width", "height"] | ||
}); | ||
this._resizeObserver.observe(element); | ||
} | ||
} | ||
const shapeOptions = this.options.shape, | ||
shapeGenerator = this._engine.emitterShapeManager?.getShapeGenerator(shapeOptions.type); | ||
if (shapeGenerator) { | ||
this._shape = shapeGenerator.generate(this.position, this.size, this.fill, shapeOptions.options); | ||
} | ||
this._engine.dispatchEvent("emitterCreated", { | ||
container, | ||
data: { | ||
emitter: this | ||
} | ||
}); | ||
this.play(); | ||
} | ||
externalPause() { | ||
this._paused = true; | ||
this.pause(); | ||
} | ||
externalPlay() { | ||
this._paused = false; | ||
this.play(); | ||
} | ||
async init() { | ||
await this._shape?.init(); | ||
} | ||
pause() { | ||
if (this._paused) { | ||
return; | ||
} | ||
delete this._emitDelay; | ||
} | ||
play() { | ||
if (this._paused) { | ||
return; | ||
} | ||
if (!(this.container.retina.reduceFactor && (this._lifeCount > minLifeCount || this._immortal || !this.options.life.count) && (this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? defaultSpawnDelay)))) { | ||
return; | ||
} | ||
if (this._emitDelay === undefined) { | ||
const delay = (0,engine_root_window_.getRangeValue)(this.options.rate.delay); | ||
this._emitDelay = delay * engine_root_window_.millisecondsToSeconds / this.container.retina.reduceFactor; | ||
} | ||
if (this._lifeCount > minLifeCount || this._immortal) { | ||
this._prepareToDie(); | ||
} | ||
} | ||
resize() { | ||
const initialPosition = this._initialPosition; | ||
this.position = initialPosition && (0,engine_root_window_.isPointInside)(initialPosition, this.container.canvas.size, engine_root_window_.Vector.origin) ? initialPosition : this._calcPosition(); | ||
this._size = this._calcSize(); | ||
this.size = (0,engine_root_window_.getSize)(this._size, this.container.canvas.size); | ||
this._shape?.resize(this.position, this.size); | ||
} | ||
async update(delta) { | ||
if (this._paused) { | ||
return; | ||
} | ||
if (this._firstSpawn) { | ||
this._firstSpawn = false; | ||
this._currentSpawnDelay = this._spawnDelay ?? defaultSpawnDelay; | ||
this._currentEmitDelay = this._emitDelay ?? defaultEmitDelay; | ||
} | ||
if (!this._startParticlesAdded) { | ||
this._startParticlesAdded = true; | ||
await this._emitParticles(this.options.startCount); | ||
} | ||
if (this._duration !== undefined) { | ||
this._currentDuration += delta.value; | ||
if (this._currentDuration >= this._duration) { | ||
this.pause(); | ||
if (this._spawnDelay !== undefined) { | ||
delete this._spawnDelay; | ||
} | ||
if (!this._immortal) { | ||
this._lifeCount--; | ||
} | ||
if (this._lifeCount > minLifeCount || this._immortal) { | ||
this.position = this._calcPosition(); | ||
this._shape?.resize(this.position, this.size); | ||
this._spawnDelay = (0,engine_root_window_.getRangeValue)(this.options.life.delay ?? defaultLifeDelay) * engine_root_window_.millisecondsToSeconds / this.container.retina.reduceFactor; | ||
} else { | ||
this._destroy(); | ||
} | ||
this._currentDuration -= this._duration; | ||
delete this._duration; | ||
} | ||
} | ||
if (this._spawnDelay !== undefined) { | ||
this._currentSpawnDelay += delta.value; | ||
if (this._currentSpawnDelay >= this._spawnDelay) { | ||
this._engine.dispatchEvent("emitterPlay", { | ||
container: this.container | ||
}); | ||
this.play(); | ||
this._currentSpawnDelay -= this._currentSpawnDelay; | ||
delete this._spawnDelay; | ||
} | ||
} | ||
if (this._emitDelay !== undefined) { | ||
this._currentEmitDelay += delta.value; | ||
if (this._currentEmitDelay >= this._emitDelay) { | ||
await this._emit(); | ||
this._currentEmitDelay -= this._emitDelay; | ||
} | ||
} | ||
} | ||
_calcPosition() { | ||
if (this.options.domId) { | ||
const container = this.container, | ||
element = document.getElementById(this.options.domId); | ||
if (element) { | ||
const elRect = element.getBoundingClientRect(), | ||
pxRatio = container.retina.pixelRatio; | ||
return { | ||
x: (elRect.x + elRect.width * half) * pxRatio, | ||
y: (elRect.y + elRect.height * half) * pxRatio | ||
}; | ||
} | ||
} | ||
return (0,engine_root_window_.calcPositionOrRandomFromSizeRanged)({ | ||
size: this.container.canvas.size, | ||
position: this.options.position | ||
}); | ||
} | ||
_calcSize() { | ||
const container = this.container; | ||
if (this.options.domId) { | ||
const element = document.getElementById(this.options.domId); | ||
if (element) { | ||
const elRect = element.getBoundingClientRect(); | ||
return { | ||
width: elRect.width * container.retina.pixelRatio, | ||
height: elRect.height * container.retina.pixelRatio, | ||
mode: "precise" | ||
}; | ||
} | ||
} | ||
return this.options.size ?? (() => { | ||
const size = new EmitterSize(); | ||
size.load({ | ||
height: 0, | ||
mode: "percent", | ||
width: 0 | ||
}); | ||
return size; | ||
})(); | ||
} | ||
async _emit() { | ||
if (this._paused) { | ||
return; | ||
} | ||
const quantity = (0,engine_root_window_.getRangeValue)(this.options.rate.quantity); | ||
await this._emitParticles(quantity); | ||
} | ||
async _emitParticles(quantity) { | ||
const singleParticlesOptions = (0,engine_root_window_.itemFromSingleOrMultiple)(this._particlesOptions); | ||
for (let i = 0; i < quantity; i++) { | ||
const particlesOptions = (0,engine_root_window_.deepExtend)({}, singleParticlesOptions); | ||
if (this.spawnColor) { | ||
const hslAnimation = this.options.spawnColor?.animation; | ||
if (hslAnimation) { | ||
const maxValues = { | ||
h: 360, | ||
s: 100, | ||
l: 100 | ||
}; | ||
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h); | ||
this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, maxValues.s); | ||
this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, maxValues.l); | ||
} | ||
setParticlesOptionsColor(particlesOptions, this.spawnColor); | ||
} | ||
const shapeOptions = this.options.shape; | ||
let position = this.position; | ||
if (this._shape) { | ||
const shapePosData = await this._shape.randomPosition(); | ||
if (shapePosData) { | ||
position = shapePosData.position; | ||
const replaceData = shapeOptions.replace; | ||
if (replaceData.color && shapePosData.color) { | ||
setParticlesOptionsColor(particlesOptions, shapePosData.color); | ||
} | ||
if (replaceData.opacity) { | ||
if (particlesOptions.opacity) { | ||
particlesOptions.opacity.value = shapePosData.opacity; | ||
} else { | ||
particlesOptions.opacity = { | ||
value: shapePosData.opacity | ||
}; | ||
} | ||
} | ||
} else { | ||
position = null; | ||
} | ||
} | ||
if (position) { | ||
this.container.particles.addParticle(position, particlesOptions); | ||
} | ||
} | ||
} | ||
} | ||
;// CONCATENATED MODULE: ./dist/browser/Emitters.js | ||
class Emitters { | ||
constructor(engine, container) { | ||
this.container = container; | ||
this._engine = engine; | ||
this.array = []; | ||
this.emitters = []; | ||
this.interactivityEmitters = { | ||
random: { | ||
count: 1, | ||
enable: false | ||
}, | ||
value: [] | ||
}; | ||
const defaultIndex = 0; | ||
container.getEmitter = idxOrName => idxOrName === undefined || (0,engine_root_window_.isNumber)(idxOrName) ? this.array[idxOrName ?? defaultIndex] : this.array.find(t => t.name === idxOrName); | ||
container.addEmitter = async (options, position) => this.addEmitter(options, position); | ||
container.removeEmitter = idxOrName => { | ||
const emitter = container.getEmitter(idxOrName); | ||
if (emitter) { | ||
this.removeEmitter(emitter); | ||
} | ||
}; | ||
container.playEmitter = idxOrName => { | ||
const emitter = container.getEmitter(idxOrName); | ||
if (emitter) { | ||
emitter.externalPlay(); | ||
} | ||
}; | ||
container.pauseEmitter = idxOrName => { | ||
const emitter = container.getEmitter(idxOrName); | ||
if (emitter) { | ||
emitter.externalPause(); | ||
} | ||
}; | ||
} | ||
async addEmitter(options, position) { | ||
const emitterOptions = new Emitter(); | ||
emitterOptions.load(options); | ||
const emitter = new EmitterInstance(this._engine, this, this.container, emitterOptions, position); | ||
await emitter.init(); | ||
this.array.push(emitter); | ||
return emitter; | ||
} | ||
handleClickMode(mode) { | ||
const emitterOptions = this.emitters, | ||
modeEmitters = this.interactivityEmitters; | ||
if (mode !== "emitter") { | ||
return; | ||
} | ||
let emittersModeOptions; | ||
if (modeEmitters && (0,engine_root_window_.isArray)(modeEmitters.value)) { | ||
const minLength = 0; | ||
if (modeEmitters.value.length > minLength && modeEmitters.random.enable) { | ||
emittersModeOptions = []; | ||
const usedIndexes = []; | ||
for (let i = 0; i < modeEmitters.random.count; i++) { | ||
const idx = (0,engine_root_window_.arrayRandomIndex)(modeEmitters.value); | ||
if (usedIndexes.includes(idx) && usedIndexes.length < modeEmitters.value.length) { | ||
i--; | ||
continue; | ||
} | ||
usedIndexes.push(idx); | ||
emittersModeOptions.push((0,engine_root_window_.itemFromArray)(modeEmitters.value, idx)); | ||
} | ||
} else { | ||
emittersModeOptions = modeEmitters.value; | ||
} | ||
} else { | ||
emittersModeOptions = modeEmitters?.value; | ||
} | ||
const emittersOptions = emittersModeOptions ?? emitterOptions, | ||
ePosition = this.container.interactivity.mouse.clickPosition; | ||
void (0,engine_root_window_.executeOnSingleOrMultiple)(emittersOptions, async emitter => { | ||
await this.addEmitter(emitter, ePosition); | ||
}); | ||
} | ||
async init() { | ||
this.emitters = this.container.actualOptions.emitters; | ||
this.interactivityEmitters = this.container.actualOptions.interactivity.modes.emitters; | ||
if (!this.emitters) { | ||
return; | ||
} | ||
if ((0,engine_root_window_.isArray)(this.emitters)) { | ||
for (const emitterOptions of this.emitters) { | ||
await this.addEmitter(emitterOptions); | ||
} | ||
} else { | ||
await this.addEmitter(this.emitters); | ||
} | ||
} | ||
pause() { | ||
for (const emitter of this.array) { | ||
emitter.pause(); | ||
} | ||
} | ||
play() { | ||
for (const emitter of this.array) { | ||
emitter.play(); | ||
} | ||
} | ||
removeEmitter(emitter) { | ||
const index = this.array.indexOf(emitter), | ||
minIndex = 0, | ||
deleteCount = 1; | ||
if (index >= minIndex) { | ||
this.array.splice(index, deleteCount); | ||
} | ||
} | ||
resize() { | ||
for (const emitter of this.array) { | ||
emitter.resize(); | ||
} | ||
} | ||
stop() { | ||
this.array = []; | ||
} | ||
async update(delta) { | ||
for (const emitter of this.array) { | ||
await emitter.update(delta); | ||
} | ||
} | ||
} | ||
;// CONCATENATED MODULE: ./dist/browser/ShapeManager.js | ||
const shapeGeneratorss = new Map(); | ||
class ShapeManager { | ||
constructor(engine) { | ||
this._engine = engine; | ||
} | ||
addShapeGenerator(name, generator) { | ||
if (!this.getShapeGenerator(name)) { | ||
shapeGeneratorss.set(name, generator); | ||
} | ||
} | ||
getShapeGenerator(name) { | ||
return shapeGeneratorss.get(name); | ||
} | ||
getSupportedShapeGenerators() { | ||
return shapeGeneratorss.keys(); | ||
} | ||
} | ||
;// CONCATENATED MODULE: ./dist/browser/EmitterShapeBase.js | ||
class EmitterShapeBase { | ||
constructor(position, size, fill, options) { | ||
this.position = position; | ||
this.size = size; | ||
this.fill = fill; | ||
this.options = options; | ||
} | ||
resize(position, size) { | ||
this.position = position; | ||
this.size = size; | ||
} | ||
} | ||
;// CONCATENATED MODULE: ./dist/browser/index.js | ||
class EmittersPlugin { | ||
constructor(engine) { | ||
this._engine = engine; | ||
this.id = "emitters"; | ||
} | ||
getPlugin(container) { | ||
return new Emitters(this._engine, container); | ||
} | ||
loadOptions(options, source) { | ||
if (!this.needsPlugin(options) && !this.needsPlugin(source)) { | ||
return; | ||
} | ||
if (source?.emitters) { | ||
options.emitters = (0,engine_root_window_.executeOnSingleOrMultiple)(source.emitters, emitter => { | ||
const tmp = new Emitter(); | ||
tmp.load(emitter); | ||
return tmp; | ||
}); | ||
} | ||
const interactivityEmitters = source?.interactivity?.modes?.emitters; | ||
if (interactivityEmitters) { | ||
if ((0,engine_root_window_.isArray)(interactivityEmitters)) { | ||
options.interactivity.modes.emitters = { | ||
random: { | ||
count: 1, | ||
enable: true | ||
}, | ||
value: interactivityEmitters.map(s => { | ||
const tmp = new Emitter(); | ||
tmp.load(s); | ||
return tmp; | ||
}) | ||
}; | ||
} else { | ||
const emitterMode = interactivityEmitters; | ||
if (emitterMode.value !== undefined) { | ||
const defaultCount = 1; | ||
if ((0,engine_root_window_.isArray)(emitterMode.value)) { | ||
options.interactivity.modes.emitters = { | ||
random: { | ||
count: emitterMode.random.count ?? defaultCount, | ||
enable: emitterMode.random.enable ?? false | ||
}, | ||
value: emitterMode.value.map(s => { | ||
const tmp = new Emitter(); | ||
tmp.load(s); | ||
return tmp; | ||
}) | ||
}; | ||
} else { | ||
const tmp = new Emitter(); | ||
tmp.load(emitterMode.value); | ||
options.interactivity.modes.emitters = { | ||
random: { | ||
count: emitterMode.random.count ?? defaultCount, | ||
enable: emitterMode.random.enable ?? false | ||
}, | ||
value: tmp | ||
}; | ||
} | ||
} else { | ||
const emitterOptions = options.interactivity.modes.emitters = { | ||
random: { | ||
count: 1, | ||
enable: false | ||
}, | ||
value: new Emitter() | ||
}; | ||
emitterOptions.value.load(interactivityEmitters); | ||
} | ||
} | ||
} | ||
} | ||
needsPlugin(options) { | ||
if (!options) { | ||
return false; | ||
} | ||
const emitters = options.emitters; | ||
return (0,engine_root_window_.isArray)(emitters) && !!emitters.length || emitters !== undefined || !!options.interactivity?.events?.onClick?.mode && (0,engine_root_window_.isInArray)("emitter", options.interactivity.events.onClick.mode); | ||
} | ||
} | ||
async function loadEmittersPlugin(engine, refresh = true) { | ||
if (!engine.emitterShapeManager) { | ||
engine.emitterShapeManager = new ShapeManager(engine); | ||
} | ||
if (!engine.addEmitterShapeGenerator) { | ||
engine.addEmitterShapeGenerator = (name, generator) => { | ||
engine.emitterShapeManager?.addShapeGenerator(name, generator); | ||
}; | ||
} | ||
const plugin = new EmittersPlugin(engine); | ||
await engine.addPlugin(plugin, refresh); | ||
} | ||
})(); | ||
/******/ | ||
/******/ // startup | ||
/******/ // Load entry module and return exports | ||
/******/ // This entry module can't be inlined because the eval devtool is used. | ||
/******/ var __webpack_exports__ = __webpack_require__("./dist/browser/index.js"); | ||
/******/ | ||
/******/ return __webpack_exports__; | ||
@@ -845,0 +341,0 @@ /******/ })() |
/*! For license information please see tsparticles.plugin.emitters.min.js.LICENSE.txt */ | ||
!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 o=e[t];if(void 0!==o)return o.exports;var n=e[t]={exports:{}};return i[t](n,n.exports,s),n.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 o={};return(()=>{s.r(o),s.d(o,{EmitterShapeBase:()=>m,loadEmittersPlugin:()=>_});var t=s(533);class i{constructor(){this.wait=!1}load(i){i&&(void 0!==i.count&&(this.count=i.count),void 0!==i.delay&&(this.delay=(0,t.setRangeValue)(i.delay)),void 0!==i.duration&&(this.duration=(0,t.setRangeValue)(i.duration)),void 0!==i.wait&&(this.wait=i.wait))}}class e{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 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 a{constructor(){this.options={},this.replace=new n,this.type="square"}load(i){i&&(void 0!==i.options&&(this.options=(0,t.deepExtend)({},i.options??{})),this.replace.load(i.replace),void 0!==i.type&&(this.type=i.type))}}class r{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 h{constructor(){this.autoPlay=!0,this.fill=!0,this.life=new i,this.rate=new e,this.shape=new a,this.startCount=0}load(i){i&&(void 0!==i.autoPlay&&(this.autoPlay=i.autoPlay),void 0!==i.size&&(this.size||(this.size=new r),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),this.shape.load(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))}}function l(t,i){t.color?t.color.value=i:t.color={value:i}}class c{constructor(i,e,s,o,n){this.emitters=e,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 i=void 0!==this.options.life?.duration?(0,t.getRangeValue)(this.options.life.duration):void 0;this.container.retina.reduceFactor&&(this._lifeCount>0||this._immortal)&&void 0!==i&&i>0&&(this._duration=i*t.millisecondsToSeconds)},this._setColorAnimation=(i,e,s)=>{const o=this.container;if(!i.enable)return e;const n=(0,t.randomInRange)(i.offset),a=(0,t.getRangeValue)(this.options.rate.delay)*t.millisecondsToSeconds/o.retina.reduceFactor;return(e+(0,t.getRangeValue)(i.speed??0)*o.fpsLimit/a+3.6*n)%s},this._engine=i,this._currentDuration=0,this._currentEmitDelay=0,this._currentSpawnDelay=0,this._initialPosition=n,o instanceof h?this.options=o:(this.options=new h,this.options.load(o)),this._spawnDelay=(0,t.getRangeValue)(this.options.life.delay??0)*t.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 a=(0,t.deepExtend)({},this.options.particles);if(a??={},a.move??={},a.move.direction??=this.options.direction,this.options.spawnColor&&(this.spawnColor=(0,t.rangeColorToHsl)(this.options.spawnColor)),this._paused=!this.options.autoPlay,this._particlesOptions=a,this._size=this._calcSize(),this.size=(0,t.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 r=this.options.shape,l=this._engine.emitterShapeManager?.getShapeGenerator(r.type);l&&(this._shape=l.generate(this.position,this.size,this.fill,r.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 i=(0,t.getRangeValue)(this.options.rate.delay);this._emitDelay=i*t.millisecondsToSeconds/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(),this._size=this._calcSize(),this.size=(0,t.getSize)(this._size,this.container.canvas.size),this._shape?.resize(this.position,this.size)}async update(i){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+=i.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,t.getRangeValue)(this.options.life.delay??0)*t.millisecondsToSeconds/this.container.retina.reduceFactor):this._destroy(),this._currentDuration-=this._duration,delete this._duration)),void 0!==this._spawnDelay&&(this._currentSpawnDelay+=i.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+=i.value,this._currentEmitDelay>=this._emitDelay&&(await this._emit(),this._currentEmitDelay-=this._emitDelay)))}_calcPosition(){if(this.options.domId){const t=this.container,i=document.getElementById(this.options.domId);if(i){const e=i.getBoundingClientRect(),s=t.retina.pixelRatio;return{x:(e.x+.5*e.width)*s,y:(e.y+.5*e.height)*s}}}return(0,t.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 e=i.getBoundingClientRect();return{width:e.width*t.retina.pixelRatio,height:e.height*t.retina.pixelRatio,mode:"precise"}}}return this.options.size??(()=>{const t=new r;return t.load({height:0,mode:"percent",width:0}),t})()}async _emit(){if(this._paused)return;const i=(0,t.getRangeValue)(this.options.rate.quantity);await this._emitParticles(i)}async _emitParticles(i){const e=(0,t.itemFromSingleOrMultiple)(this._particlesOptions);for(let s=0;s<i;s++){const i=(0,t.deepExtend)({},e);if(this.spawnColor){const t=this.options.spawnColor?.animation;if(t){const i={h:360,s:100,l:100};this.spawnColor.h=this._setColorAnimation(t.h,this.spawnColor.h,i.h),this.spawnColor.s=this._setColorAnimation(t.s,this.spawnColor.s,i.s),this.spawnColor.l=this._setColorAnimation(t.l,this.spawnColor.l,i.l)}l(i,this.spawnColor)}const s=this.options.shape;let o=this.position;if(this._shape){const t=await this._shape.randomPosition();if(t){o=t.position;const e=s.replace;e.color&&t.color&&l(i,t.color),e.opacity&&(i.opacity?i.opacity.value=t.opacity:i.opacity={value:t.opacity})}else o=null}o&&this.container.particles.addParticle(o,i)}}}class d{constructor(i,e){this.container=e,this._engine=i,this.array=[],this.emitters=[],this.interactivityEmitters={random:{count:1,enable:!1},value:[]};e.getEmitter=i=>void 0===i||(0,t.isNumber)(i)?this.array[i??0]:this.array.find((t=>t.name===i)),e.addEmitter=async(t,i)=>this.addEmitter(t,i),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,i){const e=new h;e.load(t);const s=new c(this._engine,this,this.container,e,i);return await s.init(),this.array.push(s),s}handleClickMode(i){const e=this.emitters,s=this.interactivityEmitters;if("emitter"!==i)return;let o;if(s&&(0,t.isArray)(s.value)){const i=0;if(s.value.length>i&&s.random.enable){o=[];const i=[];for(let e=0;e<s.random.count;e++){const n=(0,t.arrayRandomIndex)(s.value);i.includes(n)&&i.length<s.value.length?e--:(i.push(n),o.push((0,t.itemFromArray)(s.value,n)))}}else o=s.value}else o=s?.value;const n=o??e,a=this.container.interactivity.mouse.clickPosition;(0,t.executeOnSingleOrMultiple)(n,(async t=>{await this.addEmitter(t,a)}))}async init(){if(this.emitters=this.container.actualOptions.emitters,this.interactivityEmitters=this.container.actualOptions.interactivity.modes.emitters,this.emitters)if((0,t.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 i=this.array.indexOf(t);i>=0&&this.array.splice(i,1)}resize(){for(const t of this.array)t.resize()}stop(){this.array=[]}async update(t){for(const i of this.array)await i.update(t)}}const p=new Map;class u{constructor(t){this._engine=t}addShapeGenerator(t,i){this.getShapeGenerator(t)||p.set(t,i)}getShapeGenerator(t){return p.get(t)}getSupportedShapeGenerators(){return p.keys()}}class m{constructor(t,i,e,s){this.position=t,this.size=i,this.fill=e,this.options=s}resize(t,i){this.position=t,this.size=i}}class y{constructor(t){this._engine=t,this.id="emitters"}getPlugin(t){return new d(this._engine,t)}loadOptions(i,e){if(!this.needsPlugin(i)&&!this.needsPlugin(e))return;e?.emitters&&(i.emitters=(0,t.executeOnSingleOrMultiple)(e.emitters,(t=>{const i=new h;return i.load(t),i})));const s=e?.interactivity?.modes?.emitters;if(s)if((0,t.isArray)(s))i.interactivity.modes.emitters={random:{count:1,enable:!0},value:s.map((t=>{const i=new h;return i.load(t),i}))};else{const e=s;if(void 0!==e.value){const s=1;if((0,t.isArray)(e.value))i.interactivity.modes.emitters={random:{count:e.random.count??s,enable:e.random.enable??!1},value:e.value.map((t=>{const i=new h;return i.load(t),i}))};else{const t=new h;t.load(e.value),i.interactivity.modes.emitters={random:{count:e.random.count??s,enable:e.random.enable??!1},value:t}}}else{(i.interactivity.modes.emitters={random:{count:1,enable:!1},value:new h}).value.load(s)}}}needsPlugin(i){if(!i)return!1;const e=i.emitters;return(0,t.isArray)(e)&&!!e.length||void 0!==e||!!i.interactivity?.events?.onClick?.mode&&(0,t.isInArray)("emitter",i.interactivity.events.onClick.mode)}}async function _(t,i=!0){t.emitterShapeManager||(t.emitterShapeManager=new u(t)),t.addEmitterShapeGenerator||(t.addEmitterShapeGenerator=(i,e)=>{t.emitterShapeManager?.addShapeGenerator(i,e)});const e=new y(t);await t.addPlugin(e,i)}})(),o})())); | ||
!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 r="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var i in r)("object"==typeof exports?exports:e)[i]=r[i]}}(this,(e=>(()=>{var t,r,i={533:t=>{t.exports=e}},n={};function o(e){var t=n[e];if(void 0!==t)return t.exports;var r=n[e]={exports:{}};return i[e](r,r.exports,o),r.exports}o.m=i,o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},o.d=(e,t)=>{for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.f={},o.e=e=>Promise.all(Object.keys(o.f).reduce(((t,r)=>(o.f[r](e,t),t)),[])),o.u=e=>e+".min.js",o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),t={},r="@tsparticles/plugin-emitters:",o.l=(e,i,n,a)=>{if(t[e])t[e].push(i);else{var s,p;if(void 0!==n)for(var l=document.getElementsByTagName("script"),u=0;u<l.length;u++){var c=l[u];if(c.getAttribute("src")==e||c.getAttribute("data-webpack")==r+n){s=c;break}}s||(p=!0,(s=document.createElement("script")).charset="utf-8",s.timeout=120,o.nc&&s.setAttribute("nonce",o.nc),s.setAttribute("data-webpack",r+n),s.src=e),t[e]=[i];var d=(r,i)=>{s.onerror=s.onload=null,clearTimeout(f);var n=t[e];if(delete t[e],s.parentNode&&s.parentNode.removeChild(s),n&&n.forEach((e=>e(i))),r)return r(i)},f=setTimeout(d.bind(null,void 0,{type:"timeout",target:s}),12e4);s.onerror=d.bind(null,s.onerror),s.onload=d.bind(null,s.onload),p&&document.head.appendChild(s)}},o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;o.g.importScripts&&(e=o.g.location+"");var t=o.g.document;if(!e&&t&&(t.currentScript&&(e=t.currentScript.src),!e)){var r=t.getElementsByTagName("script");if(r.length)for(var i=r.length-1;i>-1&&!e;)e=r[i--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),o.p=e})(),(()=>{var e={606:0};o.f.j=(t,r)=>{var i=o.o(e,t)?e[t]:void 0;if(0!==i)if(i)r.push(i[2]);else{var n=new Promise(((r,n)=>i=e[t]=[r,n]));r.push(i[2]=n);var a=o.p+o.u(t),s=new Error;o.l(a,(r=>{if(o.o(e,t)&&(0!==(i=e[t])&&(e[t]=void 0),i)){var n=r&&("load"===r.type?"missing":r.type),a=r&&r.target&&r.target.src;s.message="Loading chunk "+t+" failed.\n("+n+": "+a+")",s.name="ChunkLoadError",s.type=n,s.request=a,i[1](s)}}),"chunk-"+t,t)}};var t=(t,r)=>{var i,n,a=r[0],s=r[1],p=r[2],l=0;if(a.some((t=>0!==e[t]))){for(i in s)o.o(s,i)&&(o.m[i]=s[i]);if(p)p(o)}for(t&&t(r);l<a.length;l++)n=a[l],o.o(e,n)&&e[n]&&e[n][0](),e[n]=0},r=this.webpackChunk_tsparticles_plugin_emitters=this.webpackChunk_tsparticles_plugin_emitters||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();var a={};return(()=>{o.r(a),o.d(a,{EmitterShapeBase:()=>e,loadEmittersPlugin:()=>t});class e{constructor(e,t,r,i){this.position=e,this.size=t,this.fill=r,this.options=i}resize(e,t){this.position=e,this.size=t}}async function t(e,t=!0){if(!e.emitterShapeManager){const{ShapeManager:t}=await o.e(113).then(o.bind(o,113));e.emitterShapeManager=new t(e)}e.addEmitterShapeGenerator||(e.addEmitterShapeGenerator=(t,r)=>{e.emitterShapeManager?.addShapeGenerator(t,r)});const{EmittersPlugin:r}=await o.e(964).then(o.bind(o,964)),i=new r(e);await e.addPlugin(i,t)}})(),a})())); |
@@ -1,1 +0,1 @@ | ||
/*! tsParticles Emitters Plugin v3.1.0 by Matteo Bruni */ | ||
/*! tsParticles Emitters Plugin v3.2.0 by Matteo Bruni */ |
@@ -33,3 +33,3 @@ import { type Container, type ICoordinates, type IDelta, type IDimension, type IHsl, type RecursivePartial } from "@tsparticles/engine"; | ||
private _startParticlesAdded; | ||
constructor(engine: EmittersEngine, emitters: Emitters, container: Container, options: RecursivePartial<IEmitter>, position?: ICoordinates); | ||
constructor(engine: EmittersEngine, emitters: Emitters, container: Container, options: Emitter | RecursivePartial<IEmitter>, position?: ICoordinates); | ||
externalPause(): void; | ||
@@ -36,0 +36,0 @@ externalPlay(): void; |
import { type IContainerPlugin, type ICoordinates, type IDelta, type RecursivePartial, type SingleOrMultiple } from "@tsparticles/engine"; | ||
import { Emitter } from "./Options/Classes/Emitter.js"; | ||
import type { Emitter } from "./Options/Classes/Emitter.js"; | ||
import type { EmitterContainer } from "./EmitterContainer.js"; | ||
import { EmitterInstance } from "./EmitterInstance.js"; | ||
import type { EmitterInstance } from "./EmitterInstance.js"; | ||
import type { EmitterModeOptions } from "./types.js"; | ||
@@ -6,0 +6,0 @@ import type { EmittersEngine } from "./EmittersEngine.js"; |
@@ -16,3 +16,3 @@ (function (factory) { | ||
const EmitterSize_js_1 = require("./Options/Classes/EmitterSize.js"); | ||
const half = 0.5, defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1; | ||
const half = 0.5, defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultEmitDelay = 0, defaultLifeCount = -1, defaultColorAnimationFactor = 1; | ||
function setParticlesOptionsColor(particlesOptions, color) { | ||
@@ -57,3 +57,3 @@ if (particlesOptions.color) { | ||
}; | ||
this._setColorAnimation = (animation, initValue, maxValue) => { | ||
this._setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => { | ||
const container = this.container; | ||
@@ -63,4 +63,4 @@ if (!animation.enable) { | ||
} | ||
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, colorFactor = 3.6, colorSpeed = (0, engine_1.getRangeValue)(animation.speed ?? defaultColorSpeed); | ||
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * colorFactor) % maxValue; | ||
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); | ||
return (initValue + (colorSpeed * container.fpsLimit) / emitFactor + colorOffset * factor) % maxValue; | ||
}; | ||
@@ -230,5 +230,5 @@ this._engine = engine; | ||
if (this.options.domId) { | ||
const container = this.container, element = document.getElementById(this.options.domId); | ||
const element = document.getElementById(this.options.domId); | ||
if (element) { | ||
const elRect = element.getBoundingClientRect(), pxRatio = container.retina.pixelRatio; | ||
const elRect = element.getBoundingClientRect(), pxRatio = this.container.retina.pixelRatio; | ||
return { | ||
@@ -287,4 +287,4 @@ x: (elRect.x + elRect.width * half) * pxRatio, | ||
l: 100, | ||
}; | ||
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h); | ||
}, colorFactor = 3.6; | ||
this.spawnColor.h = this._setColorAnimation(hslAnimation.h, this.spawnColor.h, maxValues.h, colorFactor); | ||
this.spawnColor.s = this._setColorAnimation(hslAnimation.s, this.spawnColor.s, maxValues.s); | ||
@@ -321,3 +321,3 @@ this.spawnColor.l = this._setColorAnimation(hslAnimation.l, this.spawnColor.l, maxValues.l); | ||
if (position) { | ||
this.container.particles.addParticle(position, particlesOptions); | ||
await this.container.particles.addParticle(position, particlesOptions); | ||
} | ||
@@ -324,0 +324,0 @@ } |
@@ -0,1 +1,24 @@ | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
(function (factory) { | ||
@@ -7,11 +30,10 @@ if (typeof module === "object" && typeof module.exports === "object") { | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "@tsparticles/engine", "./Options/Classes/Emitter.js", "./EmitterInstance.js"], factory); | ||
define(["require", "exports", "@tsparticles/engine"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
var __syncRequire = typeof module === "object" && typeof module.exports === "object"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Emitters = void 0; | ||
const engine_1 = require("@tsparticles/engine"); | ||
const Emitter_js_1 = require("./Options/Classes/Emitter.js"); | ||
const EmitterInstance_js_1 = require("./EmitterInstance.js"); | ||
class Emitters { | ||
@@ -55,5 +77,5 @@ constructor(engine, container) { | ||
async addEmitter(options, position) { | ||
const emitterOptions = new Emitter_js_1.Emitter(); | ||
const { Emitter } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./Options/Classes/Emitter.js"))) : new Promise((resolve_1, reject_1) => { require(["./Options/Classes/Emitter.js"], resolve_1, reject_1); }).then(__importStar)), { EmitterInstance } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./EmitterInstance.js"))) : new Promise((resolve_2, reject_2) => { require(["./EmitterInstance.js"], resolve_2, reject_2); }).then(__importStar)), emitterOptions = new Emitter(); | ||
emitterOptions.load(options); | ||
const emitter = new EmitterInstance_js_1.EmitterInstance(this._engine, this, this.container, emitterOptions, position); | ||
const emitter = new EmitterInstance(this._engine, this, this.container, emitterOptions, position); | ||
await emitter.init(); | ||
@@ -60,0 +82,0 @@ this.array.push(emitter); |
111
umd/index.js
@@ -12,2 +12,14 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
@@ -22,102 +34,13 @@ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "@tsparticles/engine", "./Options/Classes/Emitter.js", "./Emitters.js", "./ShapeManager.js", "./EmitterContainer.js", "./EmitterShapeBase.js", "./EmittersEngine.js", "./IEmitterShape.js", "./IEmitterShapeGenerator.js", "./Enums/EmitterClickMode.js", "./IRandomPositionData.js"], factory); | ||
define(["require", "exports", "./EmitterContainer.js", "./EmitterShapeBase.js", "./EmittersEngine.js", "./IEmitterShape.js", "./IEmitterShapeGenerator.js", "./Enums/EmitterClickMode.js", "./IRandomPositionData.js"], factory); | ||
} | ||
})(function (require, exports) { | ||
"use strict"; | ||
var __syncRequire = typeof module === "object" && typeof module.exports === "object"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.loadEmittersPlugin = void 0; | ||
const engine_1 = require("@tsparticles/engine"); | ||
const Emitter_js_1 = require("./Options/Classes/Emitter.js"); | ||
const Emitters_js_1 = require("./Emitters.js"); | ||
const ShapeManager_js_1 = require("./ShapeManager.js"); | ||
class EmittersPlugin { | ||
constructor(engine) { | ||
this._engine = engine; | ||
this.id = "emitters"; | ||
} | ||
getPlugin(container) { | ||
return new Emitters_js_1.Emitters(this._engine, container); | ||
} | ||
loadOptions(options, source) { | ||
if (!this.needsPlugin(options) && !this.needsPlugin(source)) { | ||
return; | ||
} | ||
if (source?.emitters) { | ||
options.emitters = (0, engine_1.executeOnSingleOrMultiple)(source.emitters, (emitter) => { | ||
const tmp = new Emitter_js_1.Emitter(); | ||
tmp.load(emitter); | ||
return tmp; | ||
}); | ||
} | ||
const interactivityEmitters = source?.interactivity?.modes?.emitters; | ||
if (interactivityEmitters) { | ||
if ((0, engine_1.isArray)(interactivityEmitters)) { | ||
options.interactivity.modes.emitters = { | ||
random: { | ||
count: 1, | ||
enable: true, | ||
}, | ||
value: interactivityEmitters.map((s) => { | ||
const tmp = new Emitter_js_1.Emitter(); | ||
tmp.load(s); | ||
return tmp; | ||
}), | ||
}; | ||
} | ||
else { | ||
const emitterMode = interactivityEmitters; | ||
if (emitterMode.value !== undefined) { | ||
const defaultCount = 1; | ||
if ((0, engine_1.isArray)(emitterMode.value)) { | ||
options.interactivity.modes.emitters = { | ||
random: { | ||
count: emitterMode.random.count ?? defaultCount, | ||
enable: emitterMode.random.enable ?? false, | ||
}, | ||
value: emitterMode.value.map((s) => { | ||
const tmp = new Emitter_js_1.Emitter(); | ||
tmp.load(s); | ||
return tmp; | ||
}), | ||
}; | ||
} | ||
else { | ||
const tmp = new Emitter_js_1.Emitter(); | ||
tmp.load(emitterMode.value); | ||
options.interactivity.modes.emitters = { | ||
random: { | ||
count: emitterMode.random.count ?? defaultCount, | ||
enable: emitterMode.random.enable ?? false, | ||
}, | ||
value: tmp, | ||
}; | ||
} | ||
} | ||
else { | ||
const emitterOptions = (options.interactivity.modes.emitters = { | ||
random: { | ||
count: 1, | ||
enable: false, | ||
}, | ||
value: new Emitter_js_1.Emitter(), | ||
}); | ||
emitterOptions.value.load(interactivityEmitters); | ||
} | ||
} | ||
} | ||
} | ||
needsPlugin(options) { | ||
if (!options) { | ||
return false; | ||
} | ||
const emitters = options.emitters; | ||
return (((0, engine_1.isArray)(emitters) && !!emitters.length) || | ||
emitters !== undefined || | ||
(!!options.interactivity?.events?.onClick?.mode && | ||
(0, engine_1.isInArray)("emitter", options.interactivity.events.onClick.mode))); | ||
} | ||
} | ||
async function loadEmittersPlugin(engine, refresh = true) { | ||
if (!engine.emitterShapeManager) { | ||
engine.emitterShapeManager = new ShapeManager_js_1.ShapeManager(engine); | ||
const { ShapeManager } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./ShapeManager.js"))) : new Promise((resolve_1, reject_1) => { require(["./ShapeManager.js"], resolve_1, reject_1); }).then(__importStar)); | ||
engine.emitterShapeManager = new ShapeManager(engine); | ||
} | ||
@@ -129,3 +52,3 @@ if (!engine.addEmitterShapeGenerator) { | ||
} | ||
const plugin = new EmittersPlugin(engine); | ||
const { EmittersPlugin } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./EmittersPlugin.js"))) : new Promise((resolve_2, reject_2) => { require(["./EmittersPlugin.js"], resolve_2, reject_2); }).then(__importStar)), plugin = new EmittersPlugin(engine); | ||
await engine.addPlugin(plugin, refresh); | ||
@@ -132,0 +55,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 2 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
499638
147
4380
1
6
4
Updated@tsparticles/engine@^3.2.0