UNPKG

@tsparticles/plugin-export-video

Version:

tsParticles export video plugin

148 lines (135 loc) 10.3 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.9.1 */ /* * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development"). * This devtool is neither made for production nor for readable output files. * It uses "eval()" calls to create a separate source file in the browser devtools. * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/) * or disable the default devtool with "devtool: false". * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/). */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("@tsparticles/engine")); else if(typeof define === 'function' && define.amd) define(["@tsparticles/engine"], factory); else { var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]); for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; } })(this, (__WEBPACK_EXTERNAL_MODULE__tsparticles_engine__) => { return /******/ (() => { // webpackBootstrap /******/ "use strict"; /******/ var __webpack_modules__ = ({ /***/ "./dist/browser/ExportVideoInstance.js": /*!*********************************************!*\ !*** ./dist/browser/ExportVideoInstance.js ***! \*********************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ ExportVideoInstance: () => (/* binding */ ExportVideoInstance)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n\nconst videoTypes = [\"webm\", \"ogg\", \"mp4\", \"x-matroska\"],\n codecs = [\"vp9\", \"vp9.0\", \"vp8\", \"vp8.0\", \"avc1\", \"av1\", \"h265\", \"h.265\", \"h264\", \"h.264\", \"opus\", \"pcm\", \"aac\", \"mpeg\", \"mp4a\"];\nfunction getVideoSupportedMimeTypes() {\n const isSupported = type => MediaRecorder.isTypeSupported(type),\n supported = [];\n videoTypes.forEach(type => {\n const mimeType = `video/${type}`;\n codecs.forEach(codec => [`${mimeType};codecs=${codec}`, `${mimeType};codecs=${codec.toUpperCase()}`].forEach(variation => {\n if (isSupported(variation)) {\n supported.push(variation);\n }\n }));\n if (isSupported(mimeType)) {\n supported.push(mimeType);\n }\n });\n return supported;\n}\nclass ExportVideoInstance {\n constructor(container, engine) {\n this._supportedTypes = [];\n this._exportVideo = async data => {\n const element = this._container.canvas.element;\n if (!element) {\n return;\n }\n return new Promise(resolve => {\n const stream = element.captureStream(data.fps ?? this._container.actualOptions.fpsLimit),\n firstIndex = 0,\n mimeType = data.mimeType ?? this._supportedTypes[firstIndex],\n recorder = new MediaRecorder(stream, {\n mimeType\n }),\n chunks = [],\n defaultDuration = 5;\n recorder.addEventListener(\"dataavailable\", event => {\n chunks.push(event.data);\n });\n recorder.addEventListener(\"stop\", () => {\n resolve(new Blob(chunks, {\n type: mimeType\n }));\n });\n recorder.start();\n setTimeout(() => {\n recorder.stop();\n }, data.duration ?? defaultDuration * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds);\n });\n };\n this._container = container;\n this._engine = engine;\n this._supportedTypes = getVideoSupportedMimeTypes();\n }\n async export(type, data) {\n const res = {\n supported: false\n };\n switch (type) {\n case \"video\":\n res.supported = true;\n res.blob = await this._exportVideo(data);\n break;\n }\n return res;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-export-video/./dist/browser/ExportVideoInstance.js?\n}"); /***/ }), /***/ "./dist/browser/ExportVideoPlugin.js": /*!*******************************************!*\ !*** ./dist/browser/ExportVideoPlugin.js ***! \*******************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ ExportVideoPlugin: () => (/* binding */ ExportVideoPlugin)\n/* harmony export */ });\n/* harmony import */ var _ExportVideoInstance_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ExportVideoInstance.js */ \"./dist/browser/ExportVideoInstance.js\");\n\nclass ExportVideoPlugin {\n constructor(engine) {\n this.id = \"export-video\";\n this._engine = engine;\n }\n getPlugin(container) {\n return Promise.resolve(new _ExportVideoInstance_js__WEBPACK_IMPORTED_MODULE_0__.ExportVideoInstance(container, this._engine));\n }\n loadOptions() {}\n needsPlugin() {\n return true;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-export-video/./dist/browser/ExportVideoPlugin.js?\n}"); /***/ }), /***/ "./dist/browser/index.js": /*!*******************************!*\ !*** ./dist/browser/index.js ***! \*******************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ loadExportVideoPlugin: () => (/* binding */ loadExportVideoPlugin)\n/* harmony export */ });\n/* harmony import */ var _ExportVideoPlugin_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ExportVideoPlugin.js */ \"./dist/browser/ExportVideoPlugin.js\");\n\nasync function loadExportVideoPlugin(engine, refresh = true) {\n engine.checkVersion(\"3.9.1\");\n await engine.addPlugin(new _ExportVideoPlugin_js__WEBPACK_IMPORTED_MODULE_0__.ExportVideoPlugin(engine), refresh);\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-export-video/./dist/browser/index.js?\n}"); /***/ }), /***/ "@tsparticles/engine": /*!*********************************************************************************************************************************!*\ !*** external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"} ***! \*********************************************************************************************************************************/ /***/ ((module) => { module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__; /***/ }) /******/ }); /************************************************************************/ /******/ // 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/compat get default export */ /******/ (() => { /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = (module) => { /******/ var getter = module && module.__esModule ? /******/ () => (module['default']) : /******/ () => (module); /******/ __webpack_require__.d(getter, { a: getter }); /******/ return getter; /******/ }; /******/ })(); /******/ /******/ /* 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 }); /******/ }; /******/ })(); /******/ /************************************************************************/ /******/ /******/ // startup /******/ // Load entry module and return exports /******/ // This entry module can't be inlined because the eval devtool is used. /******/ var __webpack_exports__ = __webpack_require__("./dist/browser/index.js"); /******/ /******/ return __webpack_exports__; /******/ })() ; });