@tsparticles/updater-rotate
Version:
tsParticles particles rotate updater
124 lines (116 loc) • 8.3 kB
JavaScript
(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.rotate = global.__tsParticlesInternals.updaters.rotate || {}), global.__tsParticlesInternals.engine, global.__tsParticlesInternals.animation.utils));
})(this, (function (exports, engine, animationUtils) { 'use strict';
class RotateAnimation {
decay = 0;
enable = false;
speed = 0;
sync = false;
load(data) {
if (engine.isNull(data)) {
return;
}
engine.loadProperty(this, "enable", data.enable);
engine.loadRangeProperty(this, "speed", data.speed);
engine.loadRangeProperty(this, "decay", data.decay);
engine.loadProperty(this, "sync", data.sync);
}
}
class Rotate extends engine.ValueWithRandom {
animation = new RotateAnimation();
direction = engine.RotateDirection.clockwise;
path = false;
load(data) {
if (engine.isNull(data)) {
return;
}
super.load(data);
engine.loadProperty(this, "direction", data.direction);
this.animation.load(data.animation);
engine.loadProperty(this, "path", data.path);
}
}
const doublePIDeg = 360;
class RotateUpdater {
#container;
constructor(container) {
this.#container = container;
}
init(particle) {
const rotateOptions = particle.options.rotate;
if (!rotateOptions) {
return;
}
particle.rotate = {
enable: rotateOptions.animation.enable,
value: engine.degToRad(engine.getRangeValue(rotateOptions.value)),
min: 0,
max: engine.doublePI,
};
particle.pathRotation = rotateOptions.path;
let rotateDirection = rotateOptions.direction;
if (rotateDirection === engine.RotateDirection.random) {
const index = Math.floor(engine.getRandom() * engine.double), minIndex = 0;
rotateDirection = index > minIndex ? engine.RotateDirection.counterClockwise : engine.RotateDirection.clockwise;
}
switch (rotateDirection) {
case engine.RotateDirection.counterClockwise:
case "counterClockwise":
particle.rotate.status = engine.AnimationStatus.decreasing;
break;
case engine.RotateDirection.clockwise:
particle.rotate.status = engine.AnimationStatus.increasing;
break;
}
const rotateAnimation = rotateOptions.animation;
if (rotateAnimation.enable) {
particle.rotate.decay = engine.identity - engine.getRangeValue(rotateAnimation.decay);
particle.rotate.velocity =
(engine.getRangeValue(rotateAnimation.speed) / doublePIDeg) * this.#container.retina.reduceFactor;
if (!rotateAnimation.sync) {
particle.rotate.velocity *= engine.getRandom();
}
}
particle.rotation = particle.rotate.value;
}
isEnabled(particle) {
const rotate = particle.options.rotate;
if (!rotate) {
return false;
}
return !particle.destroyed && !particle.spawning && (!!rotate.value || rotate.animation.enable || rotate.path);
}
loadOptions(options, ...sources) {
engine.loadOptionProperty(options, "rotate", Rotate, ...sources);
}
update(particle, delta) {
if (!this.isEnabled(particle)) {
return;
}
particle.isRotating = !!particle.rotate;
if (!particle.rotate) {
return;
}
animationUtils.updateAnimation(particle, particle.rotate, false, engine.DestroyType.none, delta);
particle.rotation = particle.rotate.value;
}
}
async function loadRotateUpdater(engine) {
engine.checkVersion("4.3.2");
await engine.pluginManager.register(e => {
e.pluginManager.addParticleUpdater("rotate", container => {
return Promise.resolve(new RotateUpdater(container));
});
});
}
const globalObject = globalThis;
globalObject.__tsParticlesInternals = globalObject.__tsParticlesInternals ?? {};
globalObject.loadRotateUpdater = loadRotateUpdater;
exports.loadRotateUpdater = loadRotateUpdater;
}));
Object.assign(globalThis.window || globalThis, { loadRotateUpdater: (globalThis.__tsParticlesInternals.updaters.rotate || {}).loadRotateUpdater });
delete (globalThis.window || globalThis).tsparticlesInternalExports;