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.
112 lines (111 loc) • 4.53 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to set private field on non-instance");
}
privateMap.set(receiver, value);
return value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to get private field on non-instance");
}
return privateMap.get(receiver);
};
var _initialized;
import { SquareDrawer } from "./ShapeDrawers/SquareDrawer";
import { TextDrawer } from "./ShapeDrawers/TextDrawer";
import { ImageDrawer } from "./ShapeDrawers/ImageDrawer";
import { Plugins } from "./Utils";
import { ShapeType } from "./Enums/Types";
import { LineDrawer } from "./ShapeDrawers/LineDrawer";
import { CircleDrawer } from "./ShapeDrawers/CircleDrawer";
import { TriangleDrawer } from "./ShapeDrawers/TriangleDrawer";
import { StarDrawer } from "./ShapeDrawers/StarDrawer";
import { PolygonDrawer } from "./ShapeDrawers/PolygonDrawer";
import { Loader } from "./Core/Loader";
export class MainSlim {
constructor() {
_initialized.set(this, void 0);
__classPrivateFieldSet(this, _initialized, false);
const squareDrawer = new SquareDrawer();
const textDrawer = new TextDrawer();
const imageDrawer = new ImageDrawer();
Plugins.addShapeDrawer(ShapeType.line, new LineDrawer());
Plugins.addShapeDrawer(ShapeType.circle, new CircleDrawer());
Plugins.addShapeDrawer(ShapeType.edge, squareDrawer);
Plugins.addShapeDrawer(ShapeType.square, squareDrawer);
Plugins.addShapeDrawer(ShapeType.triangle, new TriangleDrawer());
Plugins.addShapeDrawer(ShapeType.star, new StarDrawer());
Plugins.addShapeDrawer(ShapeType.polygon, new PolygonDrawer());
Plugins.addShapeDrawer(ShapeType.char, textDrawer);
Plugins.addShapeDrawer(ShapeType.character, textDrawer);
Plugins.addShapeDrawer(ShapeType.image, imageDrawer);
Plugins.addShapeDrawer(ShapeType.images, imageDrawer);
}
init() {
if (!__classPrivateFieldGet(this, _initialized)) {
__classPrivateFieldSet(this, _initialized, true);
}
}
loadFromArray(tagId, options, index) {
return __awaiter(this, void 0, void 0, function* () {
return Loader.load(tagId, options, index);
});
}
load(tagId, options) {
return __awaiter(this, void 0, void 0, function* () {
return Loader.load(tagId, options);
});
}
set(id, element, options) {
return __awaiter(this, void 0, void 0, function* () {
return Loader.set(id, element, options);
});
}
loadJSON(tagId, pathConfigJson, index) {
return Loader.loadJSON(tagId, pathConfigJson, index);
}
setOnClickHandler(callback) {
Loader.setOnClickHandler(callback);
}
dom() {
return Loader.dom();
}
domItem(index) {
return Loader.domItem(index);
}
addShape(shape, drawer, init, afterEffect, destroy) {
let customDrawer;
if (typeof drawer === "function") {
customDrawer = {
afterEffect: afterEffect,
destroy: destroy,
draw: drawer,
init: init,
};
}
else {
customDrawer = drawer;
}
Plugins.addShapeDrawer(shape, customDrawer);
}
addPreset(preset, options) {
Plugins.addPreset(preset, options);
}
addPlugin(plugin) {
Plugins.addPlugin(plugin);
}
addPathGenerator(name, generator) {
Plugins.addPathGenerator(name, generator);
}
}
_initialized = new WeakMap();