@tsparticles/engine
Version:
Easily create highly customizable particle, confetti and fireworks animations and use them as animated backgrounds for your website. Ready to use components available also for React, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Riot.js, Inferno.
66 lines (65 loc) • 2.37 kB
JavaScript
import { MoveDirection } from "../../../../Enums/Directions/MoveDirection.js";
import { isNumber, isObject } from "../../../../Utils/TypeUtils.js";
import { loadProperty, loadRangeProperty } from "../../../../Utils/OptionsUtils.js";
import { MoveAngle } from "./MoveAngle.js";
import { MoveCenter } from "./MoveCenter.js";
import { MoveGravity } from "./MoveGravity.js";
import { MovePath } from "./Path/MovePath.js";
import { OptionLoader } from "../../../../Utils/OptionLoader.js";
import { OutModes } from "./OutModes.js";
import { Spin } from "./Spin.js";
export class Move extends OptionLoader {
angle = new MoveAngle();
center = new MoveCenter();
decay = 0;
direction = MoveDirection.none;
distance = {};
drift = 0;
enable = false;
gravity = new MoveGravity();
outModes = new OutModes();
path = new MovePath();
random = false;
size = false;
speed = 2;
spin = new Spin();
straight = false;
vibrate = false;
warp = false;
doLoad(data) {
this.angle.load(isNumber(data.angle) ? { value: data.angle } : data.angle);
this.center.load(data.center);
loadRangeProperty(this, "decay", data.decay);
loadProperty(this, "direction", data.direction);
if (data.distance !== undefined) {
this.distance = isNumber(data.distance)
? {
horizontal: data.distance,
vertical: data.distance,
}
: { ...data.distance };
}
loadRangeProperty(this, "drift", data.drift);
loadProperty(this, "enable", data.enable);
this.gravity.load(data.gravity);
const outModes = data.outModes;
if (outModes !== undefined) {
if (isObject(outModes)) {
this.outModes.load(outModes);
}
else {
this.outModes.load({
default: outModes,
});
}
}
this.path.load(data.path);
loadProperty(this, "random", data.random);
loadProperty(this, "size", data.size);
loadRangeProperty(this, "speed", data.speed);
this.spin.load(data.spin);
loadProperty(this, "straight", data.straight);
loadProperty(this, "vibrate", data.vibrate);
loadProperty(this, "warp", data.warp);
}
}