2023-02-17 11:06:01 +01:00

93 lines
3.7 KiB
JavaScript

import { deepExtend, executeOnSingleOrMultiple } from "../../../Utils/Utils";
import { AnimatableColor } from "../AnimatableColor";
import { Collisions } from "./Collisions/Collisions";
import { Move } from "./Move/Move";
import { Opacity } from "./Opacity/Opacity";
import { ParticlesBounce } from "./Bounce/ParticlesBounce";
import { ParticlesNumber } from "./Number/ParticlesNumber";
import { Shadow } from "./Shadow";
import { Shape } from "./Shape/Shape";
import { Size } from "./Size/Size";
import { Stroke } from "./Stroke";
import { ZIndex } from "./ZIndex/ZIndex";
export class ParticlesOptions {
constructor(engine, container) {
this._engine = engine;
this._container = container;
this.bounce = new ParticlesBounce();
this.collisions = new Collisions();
this.color = new AnimatableColor();
this.color.value = "#fff";
this.groups = {};
this.move = new Move();
this.number = new ParticlesNumber();
this.opacity = new Opacity();
this.reduceDuplicates = false;
this.shadow = new Shadow();
this.shape = new Shape();
this.size = new Size();
this.stroke = new Stroke();
this.zIndex = new ZIndex();
}
load(data) {
var _a, _b, _c, _d, _e, _f;
if (!data) {
return;
}
this.bounce.load(data.bounce);
this.color.load(AnimatableColor.create(this.color, data.color));
if (data.groups !== undefined) {
for (const group in data.groups) {
const item = data.groups[group];
if (item !== undefined) {
this.groups[group] = deepExtend((_a = this.groups[group]) !== null && _a !== void 0 ? _a : {}, item);
}
}
}
this.move.load(data.move);
this.number.load(data.number);
this.opacity.load(data.opacity);
if (data.reduceDuplicates !== undefined) {
this.reduceDuplicates = data.reduceDuplicates;
}
this.shape.load(data.shape);
this.size.load(data.size);
this.shadow.load(data.shadow);
this.zIndex.load(data.zIndex);
const collisions = (_c = (_b = data.move) === null || _b === void 0 ? void 0 : _b.collisions) !== null && _c !== void 0 ? _c : (_d = data.move) === null || _d === void 0 ? void 0 : _d.bounce;
if (collisions !== undefined) {
this.collisions.enable = collisions;
}
this.collisions.load(data.collisions);
if (data.interactivity !== undefined) {
this.interactivity = deepExtend({}, data.interactivity);
}
const strokeToLoad = (_e = data.stroke) !== null && _e !== void 0 ? _e : (_f = data.shape) === null || _f === void 0 ? void 0 : _f.stroke;
if (strokeToLoad) {
this.stroke = executeOnSingleOrMultiple(strokeToLoad, (t) => {
const tmp = new Stroke();
tmp.load(t);
return tmp;
});
}
if (this._container) {
const updaters = this._engine.plugins.updaters.get(this._container);
if (updaters) {
for (const updater of updaters) {
if (updater.loadOptions) {
updater.loadOptions(this, data);
}
}
}
const interactors = this._engine.plugins.interactors.get(this._container);
if (interactors) {
for (const interactor of interactors) {
if (interactor.loadParticlesOptions) {
interactor.loadParticlesOptions(this, data);
}
}
}
}
}
}