tsparticles
Version:
Easily create highly customizable particle 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.
95 lines (94 loc) • 3.46 kB
JavaScript
import { Links } from "./Links/Links";
import { Move } from "./Move/Move";
import { ParticlesNumber } from "./Number/ParticlesNumber";
import { Opacity } from "./Opacity/Opacity";
import { Shape } from "./Shape/Shape";
import { Size } from "./Size/Size";
import { Rotate } from "./Rotate/Rotate";
import { Shadow } from "./Shadow";
import { Stroke } from "./Stroke";
import { Collisions } from "./Collisions/Collisions";
import { Twinkle } from "./Twinkle/Twinkle";
import { AnimatableColor } from "./AnimatableColor";
import { Life } from "./Life/Life";
import { Bounce } from "./Bounce/Bounce";
import { Destroy } from "./Destroy/Destroy";
export class ParticlesOptions {
constructor() {
this.bounce = new Bounce();
this.collisions = new Collisions();
this.color = new AnimatableColor();
this.destroy = new Destroy();
this.life = new Life();
this.links = new Links();
this.move = new Move();
this.number = new ParticlesNumber();
this.opacity = new Opacity();
this.reduceDuplicates = false;
this.rotate = new Rotate();
this.shadow = new Shadow();
this.shape = new Shape();
this.size = new Size();
this.stroke = new Stroke();
this.twinkle = new Twinkle();
}
get line_linked() {
return this.links;
}
set line_linked(value) {
this.links = value;
}
get lineLinked() {
return this.links;
}
set lineLinked(value) {
this.links = value;
}
load(data) {
var _a, _b, _c, _d, _e, _f, _g;
if (data === undefined) {
return;
}
this.bounce.load(data.bounce);
this.color = AnimatableColor.create(this.color, data.color);
this.destroy.load(data.destroy);
this.life.load(data.life);
const links = (_b = (_a = data.links) !== null && _a !== void 0 ? _a : data.lineLinked) !== null && _b !== void 0 ? _b : data.line_linked;
if (links !== undefined) {
this.links.load(links);
}
this.move.load(data.move);
this.number.load(data.number);
this.opacity.load(data.opacity);
if (data.reduceDuplicates !== undefined) {
this.reduceDuplicates = data.reduceDuplicates;
}
this.rotate.load(data.rotate);
this.shape.load(data.shape);
this.size.load(data.size);
this.shadow.load(data.shadow);
this.twinkle.load(data.twinkle);
const collisions = (_d = (_c = data.move) === null || _c === void 0 ? void 0 : _c.collisions) !== null && _d !== void 0 ? _d : (_e = data.move) === null || _e === void 0 ? void 0 : _e.bounce;
if (collisions !== undefined) {
this.collisions.enable = collisions;
}
this.collisions.load(data.collisions);
const strokeToLoad = (_f = data.stroke) !== null && _f !== void 0 ? _f : (_g = data.shape) === null || _g === void 0 ? void 0 : _g.stroke;
if (strokeToLoad === undefined) {
return;
}
if (strokeToLoad instanceof Array) {
this.stroke = strokeToLoad.map((s) => {
const tmp = new Stroke();
tmp.load(s);
return tmp;
});
}
else {
if (this.stroke instanceof Array) {
this.stroke = new Stroke();
}
this.stroke.load(strokeToLoad);
}
}
}