UNPKG

@tsparticles/updater-size

Version:

tsParticles particles size updater

105 lines (97 loc) 7.33 kB
(function(g){g.__tsParticlesInternals=g.__tsParticlesInternals||{};g.__tsParticlesInternals.bundles=g.__tsParticlesInternals.bundles||{};g.__tsParticlesInternals.effects=g.__tsParticlesInternals.effects||{};g.__tsParticlesInternals.engine=g.__tsParticlesInternals.engine||{};g.__tsParticlesInternals.interactions=g.__tsParticlesInternals.interactions||{};g.__tsParticlesInternals.palettes=g.__tsParticlesInternals.palettes||{};g.__tsParticlesInternals.paths=g.__tsParticlesInternals.paths||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins.emittersShapes=g.__tsParticlesInternals.plugins.emittersShapes||{};g.__tsParticlesInternals.presets=g.__tsParticlesInternals.presets||{};g.__tsParticlesInternals.shapes=g.__tsParticlesInternals.shapes||{};g.__tsParticlesInternals.updaters=g.__tsParticlesInternals.updaters||{};g.__tsParticlesInternals.utils=g.__tsParticlesInternals.utils||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas.utils=g.__tsParticlesInternals.canvas.utils||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path.utils=g.__tsParticlesInternals.path.utils||{};var __tsProxyFactory=typeof Proxy!=="undefined"?function(obj){return new Proxy(obj,{get:function(target,key){if(!(key in target)){target[key]={};}return target[key];}});}:function(obj){return obj;};g.__tsParticlesInternals.bundles=__tsProxyFactory(g.__tsParticlesInternals.bundles);g.__tsParticlesInternals.effects=__tsProxyFactory(g.__tsParticlesInternals.effects);g.__tsParticlesInternals.interactions=__tsProxyFactory(g.__tsParticlesInternals.interactions);g.__tsParticlesInternals.palettes=__tsProxyFactory(g.__tsParticlesInternals.palettes);g.__tsParticlesInternals.paths=__tsProxyFactory(g.__tsParticlesInternals.paths);g.__tsParticlesInternals.plugins=__tsProxyFactory(g.__tsParticlesInternals.plugins);g.__tsParticlesInternals.plugins.emittersShapes=__tsProxyFactory(g.__tsParticlesInternals.plugins.emittersShapes);g.__tsParticlesInternals.presets=__tsProxyFactory(g.__tsParticlesInternals.presets);g.__tsParticlesInternals.shapes=__tsProxyFactory(g.__tsParticlesInternals.shapes);g.__tsParticlesInternals.updaters=__tsProxyFactory(g.__tsParticlesInternals.updaters);g.__tsParticlesInternals.utils=__tsProxyFactory(g.__tsParticlesInternals.utils);g.__tsParticlesInternals.canvas=__tsProxyFactory(g.__tsParticlesInternals.canvas);g.__tsParticlesInternals.path=__tsProxyFactory(g.__tsParticlesInternals.path);g.tsparticlesInternalExports=g.tsparticlesInternalExports||{};})(typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:this); /* Updater v4.3.2 */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tsparticles/engine'), require('@tsparticles/animation-utils')) : typeof define === 'function' && define.amd ? define(['exports', '@tsparticles/engine', '@tsparticles/animation-utils'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.__tsParticlesInternals = global.__tsParticlesInternals || {}, global.__tsParticlesInternals.updaters = global.__tsParticlesInternals.updaters || {}, global.__tsParticlesInternals.updaters.size = global.__tsParticlesInternals.updaters.size || {}), global.__tsParticlesInternals.engine, global.__tsParticlesInternals.animation.utils)); })(this, (function (exports, engine, animationUtils) { 'use strict'; class SizeAnimation extends engine.RangedAnimationOptions { destroy = engine.DestroyType.none; load(data) { super.load(data); if (engine.isNull(data)) { return; } engine.loadProperty(this, "destroy", data.destroy); } } class Size extends engine.RangedAnimationValueWithRandom { animation = new SizeAnimation(); value = 3; load(data) { super.load(data); if (engine.isNull(data)) { return; } const animation = data.animation; if (animation !== undefined) { this.animation.load(animation); } } } const minLoops = 0; class SizeUpdater { #container; constructor(container) { this.#container = container; } init(particle) { const container = this.#container, sizeOptions = particle.options.size; if (!sizeOptions) { return; } const sizeAnimation = sizeOptions.animation; if (!sizeAnimation.enable) { return; } particle.size.velocity = (particle.retina.sizeAnimationSpeed / engine.percentDenominator) * container.retina.reduceFactor; if (sizeAnimation.sync) { return; } particle.size.velocity *= engine.getRandom(); } isEnabled(particle) { return (!particle.destroyed && !particle.spawning && particle.size.enable && ((particle.size.maxLoops ?? minLoops) <= minLoops || ((particle.size.maxLoops ?? minLoops) > minLoops && (particle.size.loops ?? minLoops) < (particle.size.maxLoops ?? minLoops)))); } loadOptions(options, ...sources) { engine.loadOptionProperty(options, "size", Size, ...sources); } preInit(particle) { const pxRatio = this.#container.retina.pixelRatio, options = particle.options, sizeOptions = options.size; if (!sizeOptions) { return; } particle.size = animationUtils.initParticleNumericAnimationValue(sizeOptions, pxRatio); particle.retina.sizeAnimationSpeed = engine.getRangeValue(sizeOptions.animation.speed) * pxRatio; } reset(particle) { particle.size.time = 0; particle.size.loops = 0; } update(particle, delta) { if (!this.isEnabled(particle) || !particle.options.size) { return; } animationUtils.updateAnimation(particle, particle.size, true, particle.options.size.animation.destroy, delta); } } async function loadSizeUpdater(engine) { engine.checkVersion("4.3.2"); await engine.pluginManager.register(e => { e.pluginManager.addParticleUpdater("size", container => { return Promise.resolve(new SizeUpdater(container)); }); }); } const globalObject = globalThis; globalObject.__tsParticlesInternals = globalObject.__tsParticlesInternals ?? {}; globalObject.loadSizeUpdater = loadSizeUpdater; exports.loadSizeUpdater = loadSizeUpdater; })); Object.assign(globalThis.window || globalThis, { loadSizeUpdater: (globalThis.__tsParticlesInternals.updaters.size || {}).loadSizeUpdater }); delete (globalThis.window || globalThis).tsparticlesInternalExports;