UNPKG

@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.

118 lines (117 loc) • 4.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Options = void 0; const Utils_js_1 = require("../../Utils/Utils.js"); const OptionsUtils_js_1 = require("../../Utils/OptionsUtils.js"); const Background_js_1 = require("./Background/Background.js"); const FullScreen_js_1 = require("./FullScreen/FullScreen.js"); const HDROptions_js_1 = require("./HDROptions.js"); const HdrMode_js_1 = require("../../Enums/Modes/HdrMode.js"); const OptionLoader_js_1 = require("../../Utils/OptionLoader.js"); const ResizeEvent_js_1 = require("./ResizeEvent.js"); const TypeUtils_js_1 = require("../../Utils/TypeUtils.js"); const ParticlesOptionsLoader_js_1 = require("../../Utils/ParticlesOptionsLoader.js"); class Options extends OptionLoader_js_1.OptionLoader { autoPlay = true; background; clear = true; defaultThemes = {}; delay = 0; detectRetina = true; duration = 0; fpsLimit = 120; fullScreen; hdr; key; name; palette; particles; pauseOnBlur = true; pauseOnOutsideViewport = true; preset; resize; smooth = false; style = {}; zLayers = 100; #container; #pluginManager; constructor(pluginManager, container) { super(); this.#pluginManager = pluginManager; this.#container = container; this.background = new Background_js_1.Background(); this.fullScreen = new FullScreen_js_1.FullScreen(); this.hdr = new HDROptions_js_1.HDROptions(); this.particles = (0, ParticlesOptionsLoader_js_1.loadParticlesOptions)(this.#pluginManager, this.#container); this.resize = new ResizeEvent_js_1.ResizeEvent(); } doLoad(data) { if (data.preset !== undefined) { this.preset = data.preset; (0, Utils_js_1.executeOnSingleOrMultiple)(this.preset, preset => { this.#importPreset(preset); }); } if (data.palette !== undefined) { this.palette = data.palette; this.#importPalette(this.palette); } (0, OptionsUtils_js_1.loadProperty)(this, "autoPlay", data.autoPlay); (0, OptionsUtils_js_1.loadProperty)(this, "clear", data.clear); (0, OptionsUtils_js_1.loadProperty)(this, "key", data.key); (0, OptionsUtils_js_1.loadProperty)(this, "name", data.name); (0, OptionsUtils_js_1.loadRangeProperty)(this, "delay", data.delay); (0, OptionsUtils_js_1.loadProperty)(this, "detectRetina", data.detectRetina); (0, OptionsUtils_js_1.loadRangeProperty)(this, "duration", data.duration); (0, OptionsUtils_js_1.loadProperty)(this, "fpsLimit", data.fpsLimit); const hdrData = data.hdr; if ((0, TypeUtils_js_1.isBoolean)(hdrData)) { this.hdr.enable = hdrData; this.hdr.mode = HdrMode_js_1.HdrMode.standard; this.hdr.peakNits = 400; } else { this.hdr.load(hdrData); } (0, OptionsUtils_js_1.loadProperty)(this, "pauseOnBlur", data.pauseOnBlur); (0, OptionsUtils_js_1.loadProperty)(this, "pauseOnOutsideViewport", data.pauseOnOutsideViewport); (0, OptionsUtils_js_1.loadProperty)(this, "zLayers", data.zLayers); this.background.load(data.background); const fullScreen = data.fullScreen; if ((0, TypeUtils_js_1.isBoolean)(fullScreen)) { this.fullScreen.enable = fullScreen; } else { this.fullScreen.load(fullScreen); } this.particles.load(data.particles); this.resize.load(data.resize); this.style = (0, Utils_js_1.deepExtend)(this.style, data.style); (0, OptionsUtils_js_1.loadProperty)(this, "smooth", data.smooth); this.#pluginManager.plugins.forEach(plugin => { plugin.loadOptions(this.#container, this, data); }); } #importPalette(palette) { const paletteData = this.#pluginManager.getPalette(palette); if (!paletteData) { return; } this.load({ background: { color: paletteData.background, }, blend: { enable: true, mode: paletteData.blendMode, }, particles: { palette, }, }); } #importPreset(preset) { this.load(this.#pluginManager.getPreset(preset)); } } exports.Options = Options;