UNPKG

@tsparticles/fireworks

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.

537 lines (486 loc) 17.2 kB
/*! * Author : Matteo Bruni * MIT license: https://opensource.org/licenses/MIT * Demo / Generator : https://particles.js.org/ * GitHub : https://www.github.com/matteobruni/tsparticles * How to use? : Check the GitHub README * v3.0.3 */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("@tsparticles/engine"), require("@tsparticles/basic"), require("@tsparticles/updater-destroy"), require("@tsparticles/plugin-emitters"), require("@tsparticles/plugin-emitters-shape-square"), require("@tsparticles/updater-life"), require("@tsparticles/shape-line"), require("@tsparticles/updater-rotate"), require("@tsparticles/plugin-sounds"), require("@tsparticles/updater-stroke-color"), require("@tsparticles/effect-trail")); else if(typeof define === 'function' && define.amd) define(["@tsparticles/engine", "@tsparticles/basic", "@tsparticles/updater-destroy", "@tsparticles/plugin-emitters", "@tsparticles/plugin-emitters-shape-square", "@tsparticles/updater-life", "@tsparticles/shape-line", "@tsparticles/updater-rotate", "@tsparticles/plugin-sounds", "@tsparticles/updater-stroke-color", "@tsparticles/effect-trail"], factory); else { var a = typeof exports === 'object' ? factory(require("@tsparticles/engine"), require("@tsparticles/basic"), require("@tsparticles/updater-destroy"), require("@tsparticles/plugin-emitters"), require("@tsparticles/plugin-emitters-shape-square"), require("@tsparticles/updater-life"), require("@tsparticles/shape-line"), require("@tsparticles/updater-rotate"), require("@tsparticles/plugin-sounds"), require("@tsparticles/updater-stroke-color"), require("@tsparticles/effect-trail")) : factory(root["window"], root["window"], root["window"], root["window"], root["window"], root["window"], root["window"], root["window"], root["window"], root["window"], root["window"]); for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; } })(this, (__WEBPACK_EXTERNAL_MODULE__533__, __WEBPACK_EXTERNAL_MODULE__574__, __WEBPACK_EXTERNAL_MODULE__344__, __WEBPACK_EXTERNAL_MODULE__68__, __WEBPACK_EXTERNAL_MODULE__787__, __WEBPACK_EXTERNAL_MODULE__84__, __WEBPACK_EXTERNAL_MODULE__137__, __WEBPACK_EXTERNAL_MODULE__59__, __WEBPACK_EXTERNAL_MODULE__490__, __WEBPACK_EXTERNAL_MODULE__204__, __WEBPACK_EXTERNAL_MODULE__20__) => { return /******/ (() => { // webpackBootstrap /******/ "use strict"; /******/ var __webpack_modules__ = ({ /***/ 574: /***/ ((module) => { module.exports = __WEBPACK_EXTERNAL_MODULE__574__; /***/ }), /***/ 20: /***/ ((module) => { module.exports = __WEBPACK_EXTERNAL_MODULE__20__; /***/ }), /***/ 533: /***/ ((module) => { module.exports = __WEBPACK_EXTERNAL_MODULE__533__; /***/ }), /***/ 68: /***/ ((module) => { module.exports = __WEBPACK_EXTERNAL_MODULE__68__; /***/ }), /***/ 787: /***/ ((module) => { module.exports = __WEBPACK_EXTERNAL_MODULE__787__; /***/ }), /***/ 490: /***/ ((module) => { module.exports = __WEBPACK_EXTERNAL_MODULE__490__; /***/ }), /***/ 137: /***/ ((module) => { module.exports = __WEBPACK_EXTERNAL_MODULE__137__; /***/ }), /***/ 344: /***/ ((module) => { module.exports = __WEBPACK_EXTERNAL_MODULE__344__; /***/ }), /***/ 84: /***/ ((module) => { module.exports = __WEBPACK_EXTERNAL_MODULE__84__; /***/ }), /***/ 59: /***/ ((module) => { module.exports = __WEBPACK_EXTERNAL_MODULE__59__; /***/ }), /***/ 204: /***/ ((module) => { module.exports = __WEBPACK_EXTERNAL_MODULE__204__; /***/ }) /******/ }); /************************************************************************/ /******/ // The module cache /******/ var __webpack_module_cache__ = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ var cachedModule = __webpack_module_cache__[moduleId]; /******/ if (cachedModule !== undefined) { /******/ return cachedModule.exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { /******/ // no module.id needed /******/ // no module.loaded needed /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /************************************************************************/ /******/ /* webpack/runtime/define property getters */ /******/ (() => { /******/ // define getter functions for harmony exports /******/ __webpack_require__.d = (exports, definition) => { /******/ for(var key in definition) { /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); /******/ } /******/ } /******/ }; /******/ })(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ (() => { /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) /******/ })(); /******/ /******/ /* webpack/runtime/make namespace object */ /******/ (() => { /******/ // define __esModule on exports /******/ __webpack_require__.r = (exports) => { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ })(); /******/ /************************************************************************/ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. (() => { // ESM COMPAT FLAG __webpack_require__.r(__webpack_exports__); // EXPORTS __webpack_require__.d(__webpack_exports__, { fireworks: () => (/* reexport */ fireworks) }); // EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"} var engine_root_window_ = __webpack_require__(533); ;// CONCATENATED MODULE: ./dist/browser/FireworkOptions.js class FireworkOptions { constructor() { this.background = "none"; this.brightness = { min: -30, max: 30 }; this.colors = ["#ff595e", "#ffca3a", "#8ac926", "#1982c4", "#6a4c93"]; this.gravity = 5; this.minHeight = { min: 10, max: 30 }; this.rate = 10; this.saturation = { min: -30, max: 30 }; this.sounds = true; this.speed = { min: 5, max: 15 }; this.splitCount = { min: 75, max: 150 }; } load(data) { if (!data) { return; } if (data.background !== undefined) { this.background = data.background; } if (data.colors !== undefined) { if ((0,engine_root_window_.isArray)(data.colors)) { this.colors = [...data.colors]; } else { this.colors = data.colors; } } if (data.brightness !== undefined) { this.brightness = (0,engine_root_window_.setRangeValue)(data.brightness); } if (data.gravity !== undefined) { this.gravity = (0,engine_root_window_.setRangeValue)(data.gravity); } if (data.minHeight !== undefined) { this.minHeight = (0,engine_root_window_.setRangeValue)(data.minHeight); } if (data.rate !== undefined) { this.rate = (0,engine_root_window_.setRangeValue)(data.rate); } if (data.saturation !== undefined) { this.saturation = (0,engine_root_window_.setRangeValue)(data.saturation); } if (data.sounds !== undefined) { this.sounds = data.sounds; } if (data.speed !== undefined) { this.speed = (0,engine_root_window_.setRangeValue)(data.speed); } if (data.splitCount !== undefined) { this.splitCount = (0,engine_root_window_.setRangeValue)(data.splitCount); } } } // EXTERNAL MODULE: external {"commonjs":"@tsparticles/basic","commonjs2":"@tsparticles/basic","amd":"@tsparticles/basic","root":"window"} var basic_root_window_ = __webpack_require__(574); // EXTERNAL MODULE: external {"commonjs":"@tsparticles/updater-destroy","commonjs2":"@tsparticles/updater-destroy","amd":"@tsparticles/updater-destroy","root":"window"} var updater_destroy_root_window_ = __webpack_require__(344); // EXTERNAL MODULE: external {"commonjs":"@tsparticles/plugin-emitters","commonjs2":"@tsparticles/plugin-emitters","amd":"@tsparticles/plugin-emitters","root":"window"} var plugin_emitters_root_window_ = __webpack_require__(68); // EXTERNAL MODULE: external {"commonjs":"@tsparticles/plugin-emitters-shape-square","commonjs2":"@tsparticles/plugin-emitters-shape-square","amd":"@tsparticles/plugin-emitters-shape-square","root":"window"} var plugin_emitters_shape_square_root_window_ = __webpack_require__(787); // EXTERNAL MODULE: external {"commonjs":"@tsparticles/updater-life","commonjs2":"@tsparticles/updater-life","amd":"@tsparticles/updater-life","root":"window"} var updater_life_root_window_ = __webpack_require__(84); // EXTERNAL MODULE: external {"commonjs":"@tsparticles/shape-line","commonjs2":"@tsparticles/shape-line","amd":"@tsparticles/shape-line","root":"window"} var shape_line_root_window_ = __webpack_require__(137); // EXTERNAL MODULE: external {"commonjs":"@tsparticles/updater-rotate","commonjs2":"@tsparticles/updater-rotate","amd":"@tsparticles/updater-rotate","root":"window"} var updater_rotate_root_window_ = __webpack_require__(59); // EXTERNAL MODULE: external {"commonjs":"@tsparticles/plugin-sounds","commonjs2":"@tsparticles/plugin-sounds","amd":"@tsparticles/plugin-sounds","root":"window"} var plugin_sounds_root_window_ = __webpack_require__(490); // EXTERNAL MODULE: external {"commonjs":"@tsparticles/updater-stroke-color","commonjs2":"@tsparticles/updater-stroke-color","amd":"@tsparticles/updater-stroke-color","root":"window"} var updater_stroke_color_root_window_ = __webpack_require__(204); // EXTERNAL MODULE: external {"commonjs":"@tsparticles/effect-trail","commonjs2":"@tsparticles/effect-trail","amd":"@tsparticles/effect-trail","root":"window"} var effect_trail_root_window_ = __webpack_require__(20); ;// CONCATENATED MODULE: ./dist/browser/fireworks.js let initialized = false; let initializing = false; const explodeSoundCheck = args => { const data = args.data; return data.particle.shape === "circle" && !!data.particle.splitCount && data.particle.splitCount < 2; }; class FireworksInstance { constructor(container) { this._container = container; } pause() { this._container.pause(); } play() { this._container.play(); } stop() { this._container.stop(); } } async function initPlugins() { if (initialized) { return; } if (initializing) { return new Promise(resolve => { const interval = setInterval(() => { if (!initialized) { return; } clearInterval(interval); resolve(); }, 100); }); } initializing = true; await (0,plugin_emitters_root_window_.loadEmittersPlugin)(engine_root_window_.tsParticles, false); await (0,plugin_emitters_shape_square_root_window_.loadEmittersShapeSquare)(engine_root_window_.tsParticles, false); await (0,plugin_sounds_root_window_.loadSoundsPlugin)(engine_root_window_.tsParticles, false); await (0,shape_line_root_window_.loadLineShape)(engine_root_window_.tsParticles, false); await (0,updater_rotate_root_window_.loadRotateUpdater)(engine_root_window_.tsParticles, false); await (0,updater_destroy_root_window_.loadDestroyUpdater)(engine_root_window_.tsParticles, false); await (0,updater_life_root_window_.loadLifeUpdater)(engine_root_window_.tsParticles, false); await (0,updater_stroke_color_root_window_.loadStrokeColorUpdater)(engine_root_window_.tsParticles, false); await (0,effect_trail_root_window_.loadTrailEffect)(engine_root_window_.tsParticles, false); await (0,basic_root_window_.loadBasic)(engine_root_window_.tsParticles, false); initializing = false; initialized = true; } async function fireworks(idOrOptions, sourceOptions) { await initPlugins(); let id; const options = new FireworkOptions(); if ((0,engine_root_window_.isString)(idOrOptions)) { id = idOrOptions; options.load(sourceOptions); } else { id = "fireworks"; options.load(idOrOptions); } const particlesOptions = { detectRetina: true, background: { color: options.background }, fpsLimit: 60, emitters: { direction: "top", life: { count: 0, duration: 0.1, delay: 0.1 }, rate: { delay: (0,engine_root_window_.isNumber)(options.rate) ? 1 / options.rate : { min: 1 / (0,engine_root_window_.getRangeMin)(options.rate), max: 1 / (0,engine_root_window_.getRangeMax)(options.rate) }, quantity: 1 }, size: { width: 100, height: 0 }, position: { y: 100, x: 50 } }, particles: { number: { value: 0 }, color: { value: "#fff" }, destroy: { mode: "split", bounds: { top: (0,engine_root_window_.setRangeValue)(options.minHeight) }, split: { sizeOffset: false, count: 1, factor: { value: 0.333333 }, rate: { value: options.splitCount }, colorOffset: { s: options.saturation, l: options.brightness }, particles: { color: { value: options.colors }, number: { value: 0 }, opacity: { value: { min: 0.1, max: 1 }, animation: { enable: true, speed: 1, sync: false, startValue: "max", destroy: "min" } }, effect: { type: "trail", options: { trail: { length: { min: 5, max: 10 } } } }, shape: { type: "circle" }, size: { value: { min: 1, max: 2 }, animation: { enable: true, speed: 5, count: 1, sync: false, startValue: "min", destroy: "none" } }, life: { count: 1, duration: { value: { min: 0.25, max: 0.5 } } }, move: { decay: { min: 0.05, max: 0.1 }, enable: true, gravity: { enable: true, inverse: false, acceleration: (0,engine_root_window_.setRangeValue)(options.gravity) }, speed: (0,engine_root_window_.setRangeValue)(options.speed), direction: "none", outModes: "destroy" } } } }, life: { count: 1 }, effect: { type: "trail", options: { trail: { length: { min: 10, max: 30 }, minWidth: 1, maxWidth: 1 } } }, shape: { type: "circle" }, size: { value: 1 }, opacity: { value: 0.5 }, rotate: { path: true }, move: { enable: true, gravity: { acceleration: 15, enable: true, inverse: true, maxSpeed: 100 }, speed: { min: 10, max: 20 }, outModes: { default: "destroy", top: "none" } } }, sounds: { enable: options.sounds, events: [{ event: "particleDestroyed", filter: explodeSoundCheck, audio: ["https://particles.js.org/audio/explosion0.mp3", "https://particles.js.org/audio/explosion1.mp3", "https://particles.js.org/audio/explosion2.mp3"] }], volume: 50 } }; const container = await engine_root_window_.tsParticles.load({ id, options: particlesOptions }); if (!container) { return; } return new FireworksInstance(container); } fireworks.version = engine_root_window_.tsParticles.version; if (!(0,engine_root_window_.isSsr)()) { window.fireworks = fireworks; } ;// CONCATENATED MODULE: ./dist/browser/index.js })(); /******/ return __webpack_exports__; /******/ })() ; });