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.
90 lines (89 loc) • 4.03 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AbsorbersPlugin = void 0;
const Absorbers_1 = require("./Absorbers");
const Utils_1 = require("../../Utils");
const Enums_1 = require("./Enums");
const Absorber_1 = require("./Options/Classes/Absorber");
class AbsorbersPlugin {
constructor() {
this.id = "absorbers";
}
getPlugin(container) {
return new Absorbers_1.Absorbers(container);
}
needsPlugin(options) {
var _a, _b, _c;
if (options === undefined) {
return false;
}
const absorbers = options.absorbers;
let loadAbsorbers = false;
if (absorbers instanceof Array) {
if (absorbers.length) {
loadAbsorbers = true;
}
}
else if (absorbers !== undefined) {
loadAbsorbers = true;
}
else if (((_c = (_b = (_a = options.interactivity) === null || _a === void 0 ? void 0 : _a.events) === null || _b === void 0 ? void 0 : _b.onClick) === null || _c === void 0 ? void 0 : _c.mode) &&
Utils_1.Utils.isInArray(Enums_1.AbsorberClickMode.absorber, options.interactivity.events.onClick.mode)) {
loadAbsorbers = true;
}
return loadAbsorbers;
}
loadOptions(options, source) {
var _a, _b;
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
return;
}
const optionsCast = options;
if (source === null || source === void 0 ? void 0 : source.absorbers) {
if ((source === null || source === void 0 ? void 0 : source.absorbers) instanceof Array) {
optionsCast.absorbers = source === null || source === void 0 ? void 0 : source.absorbers.map((s) => {
const tmp = new Absorber_1.Absorber();
tmp.load(s);
return tmp;
});
}
else {
let absorberOptions = optionsCast.absorbers;
if ((absorberOptions === null || absorberOptions === void 0 ? void 0 : absorberOptions.load) === undefined) {
optionsCast.absorbers = absorberOptions = new Absorber_1.Absorber();
}
absorberOptions.load(source === null || source === void 0 ? void 0 : source.absorbers);
}
}
const interactivityAbsorbers = (_b = (_a = source === null || source === void 0 ? void 0 : source.interactivity) === null || _a === void 0 ? void 0 : _a.modes) === null || _b === void 0 ? void 0 : _b.absorbers;
if (interactivityAbsorbers) {
if (interactivityAbsorbers instanceof Array) {
optionsCast.interactivity.modes.absorbers = interactivityAbsorbers.map((s) => {
const tmp = new Absorber_1.Absorber();
tmp.load(s);
return tmp;
});
}
else {
let absorberOptions = optionsCast.interactivity.modes.absorbers;
if ((absorberOptions === null || absorberOptions === void 0 ? void 0 : absorberOptions.load) === undefined) {
optionsCast.interactivity.modes.absorbers = absorberOptions = new Absorber_1.Absorber();
}
absorberOptions.load(interactivityAbsorbers);
}
}
}
}
const plugin = new AbsorbersPlugin();
exports.AbsorbersPlugin = plugin;
__exportStar(require("./Enums"), exports);