@tsparticles/plugin-export-video 3.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,149 @@
1
+ /*!
2
+ * Author : Matteo Bruni
3
+ * MIT license: https://opensource.org/licenses/MIT
4
+ * Demo / Generator : https://particles.js.org/
5
+ * GitHub : https://www.github.com/matteobruni/tsparticles
6
+ * How to use? : Check the GitHub README
7
+ * v3.0.0-beta.0
8
+ */
9
+ (function webpackUniversalModuleDefinition(root, factory) {
10
+ if(typeof exports === 'object' && typeof module === 'object')
11
+ module.exports = factory();
12
+ else if(typeof define === 'function' && define.amd)
13
+ define([], factory);
14
+ else {
15
+ var a = factory();
16
+ for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
17
+ }
18
+ })(this, () => {
19
+ return /******/ (() => { // webpackBootstrap
20
+ /******/ "use strict";
21
+ /******/ // The require scope
22
+ /******/ var __webpack_require__ = {};
23
+ /******/
24
+ /************************************************************************/
25
+ /******/ /* webpack/runtime/define property getters */
26
+ /******/ (() => {
27
+ /******/ // define getter functions for harmony exports
28
+ /******/ __webpack_require__.d = (exports, definition) => {
29
+ /******/ for(var key in definition) {
30
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
31
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
32
+ /******/ }
33
+ /******/ }
34
+ /******/ };
35
+ /******/ })();
36
+ /******/
37
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
38
+ /******/ (() => {
39
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
40
+ /******/ })();
41
+ /******/
42
+ /******/ /* webpack/runtime/make namespace object */
43
+ /******/ (() => {
44
+ /******/ // define __esModule on exports
45
+ /******/ __webpack_require__.r = (exports) => {
46
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
47
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
48
+ /******/ }
49
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
50
+ /******/ };
51
+ /******/ })();
52
+ /******/
53
+ /************************************************************************/
54
+ var __webpack_exports__ = {};
55
+ // ESM COMPAT FLAG
56
+ __webpack_require__.r(__webpack_exports__);
57
+
58
+ // EXPORTS
59
+ __webpack_require__.d(__webpack_exports__, {
60
+ loadExportVideoPlugin: () => (/* binding */ loadExportVideoPlugin)
61
+ });
62
+
63
+ ;// CONCATENATED MODULE: ./dist/browser/ExportVideoInstance.js
64
+ const videoTypes = ["webm", "ogg", "mp4", "x-matroska"],
65
+ codecs = ["vp9", "vp9.0", "vp8", "vp8.0", "avc1", "av1", "h265", "h.265", "h264", "h.264", "opus", "pcm", "aac", "mpeg", "mp4a"];
66
+ function getVideoSupportedMimeTypes() {
67
+ const isSupported = MediaRecorder.isTypeSupported,
68
+ supported = [];
69
+ videoTypes.forEach(type => {
70
+ const mimeType = `video/${type}`;
71
+ codecs.forEach(codec => [`${mimeType};codecs=${codec}`, `${mimeType};codecs=${codec.toUpperCase()}`].forEach(variation => {
72
+ if (isSupported(variation)) {
73
+ supported.push(variation);
74
+ }
75
+ }));
76
+ if (isSupported(mimeType)) {
77
+ supported.push(mimeType);
78
+ }
79
+ });
80
+ return supported;
81
+ }
82
+ class ExportVideoInstance {
83
+ constructor(container, engine) {
84
+ this._supportedTypes = [];
85
+ this._exportVideo = async data => {
86
+ const element = this._container.canvas.element;
87
+ if (!element) {
88
+ return;
89
+ }
90
+ return new Promise(resolve => {
91
+ const stream = element.captureStream(data.fps ?? this._container.actualOptions.fpsLimit),
92
+ mimeType = data.mimeType ?? this._supportedTypes[0],
93
+ recorder = new MediaRecorder(stream, {
94
+ mimeType
95
+ }),
96
+ chunks = [];
97
+ recorder.addEventListener("dataavailable", event => {
98
+ chunks.push(event.data);
99
+ });
100
+ recorder.addEventListener("stop", () => {
101
+ resolve(new Blob(chunks, {
102
+ type: mimeType
103
+ }));
104
+ });
105
+ recorder.start();
106
+ setTimeout(() => {
107
+ recorder.stop();
108
+ }, data.duration ?? 5000);
109
+ });
110
+ };
111
+ this._container = container;
112
+ this._engine = engine;
113
+ this._supportedTypes = getVideoSupportedMimeTypes();
114
+ }
115
+ async export(type, data) {
116
+ const res = {
117
+ supported: false
118
+ };
119
+ switch (type) {
120
+ case "video":
121
+ res.supported = true;
122
+ res.blob = await this._exportVideo(data);
123
+ break;
124
+ }
125
+ return res;
126
+ }
127
+ }
128
+ ;// CONCATENATED MODULE: ./dist/browser/index.js
129
+
130
+ class ExportVideoPlugin {
131
+ constructor(engine) {
132
+ this.id = "export-video";
133
+ this._engine = engine;
134
+ }
135
+ getPlugin(container) {
136
+ return new ExportVideoInstance(container, this._engine);
137
+ }
138
+ loadOptions() {}
139
+ needsPlugin() {
140
+ return true;
141
+ }
142
+ }
143
+ async function loadExportVideoPlugin(engine, refresh = true) {
144
+ await engine.addPlugin(new ExportVideoPlugin(engine), refresh);
145
+ }
146
+ /******/ return __webpack_exports__;
147
+ /******/ })()
148
+ ;
149
+ });
@@ -0,0 +1,2 @@
1
+ /*! For license information please see tsparticles.plugin.export.video.min.js.LICENSE.txt */
2
+ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var o=t();for(var r in o)("object"==typeof exports?exports:e)[r]=o[r]}}(this,(()=>(()=>{"use strict";var e={d:(t,o)=>{for(var r in o)e.o(o,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:o[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{loadExportVideoPlugin:()=>i});const o=["webm","ogg","mp4","x-matroska"],r=["vp9","vp9.0","vp8","vp8.0","avc1","av1","h265","h.265","h264","h.264","opus","pcm","aac","mpeg","mp4a"];class n{constructor(e,t){this._supportedTypes=[],this._exportVideo=async e=>{const t=this._container.canvas.element;if(t)return new Promise((o=>{const r=t.captureStream(e.fps??this._container.actualOptions.fpsLimit),n=e.mimeType??this._supportedTypes[0],s=new MediaRecorder(r,{mimeType:n}),i=[];s.addEventListener("dataavailable",(e=>{i.push(e.data)})),s.addEventListener("stop",(()=>{o(new Blob(i,{type:n}))})),s.start(),setTimeout((()=>{s.stop()}),e.duration??5e3)}))},this._container=e,this._engine=t,this._supportedTypes=function(){const e=MediaRecorder.isTypeSupported,t=[];return o.forEach((o=>{const n=`video/${o}`;r.forEach((o=>[`${n};codecs=${o}`,`${n};codecs=${o.toUpperCase()}`].forEach((o=>{e(o)&&t.push(o)})))),e(n)&&t.push(n)})),t}()}async export(e,t){const o={supported:!1};if("video"===e)o.supported=!0,o.blob=await this._exportVideo(t);return o}}class s{constructor(e){this.id="export-video",this._engine=e}getPlugin(e){return new n(e,this._engine)}loadOptions(){}needsPlugin(){return!0}}async function i(e,t=!0){await e.addPlugin(new s(e),t)}return t})()));
@@ -0,0 +1 @@
1
+ /*! tsParticles Export Video Plugin v3.0.0-beta.0 by Matteo Bruni */
@@ -0,0 +1,9 @@
1
+ import type { Container, Engine, ExportResult, IContainerPlugin } from "@tsparticles/engine";
2
+ export declare class ExportVideoInstance implements IContainerPlugin {
3
+ private readonly _container;
4
+ private readonly _engine;
5
+ private readonly _supportedTypes;
6
+ constructor(container: Container, engine: Engine);
7
+ export(type: string, data: Record<string, unknown>): Promise<ExportResult>;
8
+ private readonly _exportVideo;
9
+ }
@@ -0,0 +1,5 @@
1
+ export interface IExportVideoData {
2
+ duration?: number;
3
+ fps?: number;
4
+ mimeType?: string;
5
+ }
@@ -0,0 +1,2 @@
1
+ import type { Engine } from "@tsparticles/engine";
2
+ export declare function loadExportVideoPlugin(engine: Engine, refresh?: boolean): Promise<void>;
@@ -0,0 +1,90 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ExportVideoInstance = void 0;
13
+ const videoTypes = ["webm", "ogg", "mp4", "x-matroska"], codecs = [
14
+ "vp9",
15
+ "vp9.0",
16
+ "vp8",
17
+ "vp8.0",
18
+ "avc1",
19
+ "av1",
20
+ "h265",
21
+ "h.265",
22
+ "h264",
23
+ "h.264",
24
+ "opus",
25
+ "pcm",
26
+ "aac",
27
+ "mpeg",
28
+ "mp4a",
29
+ ];
30
+ function getVideoSupportedMimeTypes() {
31
+ const isSupported = MediaRecorder.isTypeSupported, supported = [];
32
+ videoTypes.forEach((type) => {
33
+ const mimeType = `video/${type}`;
34
+ codecs.forEach((codec) => [
35
+ `${mimeType};codecs=${codec}`,
36
+ `${mimeType};codecs=${codec.toUpperCase()}`,
37
+ ].forEach((variation) => {
38
+ if (isSupported(variation)) {
39
+ supported.push(variation);
40
+ }
41
+ }));
42
+ if (isSupported(mimeType)) {
43
+ supported.push(mimeType);
44
+ }
45
+ });
46
+ return supported;
47
+ }
48
+ class ExportVideoInstance {
49
+ constructor(container, engine) {
50
+ this._supportedTypes = [];
51
+ this._exportVideo = async (data) => {
52
+ const element = this._container.canvas.element;
53
+ if (!element) {
54
+ return;
55
+ }
56
+ return new Promise((resolve) => {
57
+ const stream = element.captureStream(data.fps ?? this._container.actualOptions.fpsLimit), mimeType = data.mimeType ?? this._supportedTypes[0], recorder = new MediaRecorder(stream, {
58
+ mimeType,
59
+ }), chunks = [];
60
+ recorder.addEventListener("dataavailable", (event) => {
61
+ chunks.push(event.data);
62
+ });
63
+ recorder.addEventListener("stop", () => {
64
+ resolve(new Blob(chunks, { type: mimeType }));
65
+ });
66
+ recorder.start();
67
+ setTimeout(() => {
68
+ recorder.stop();
69
+ }, data.duration ?? 5000);
70
+ });
71
+ };
72
+ this._container = container;
73
+ this._engine = engine;
74
+ this._supportedTypes = getVideoSupportedMimeTypes();
75
+ }
76
+ async export(type, data) {
77
+ const res = {
78
+ supported: false,
79
+ };
80
+ switch (type) {
81
+ case "video":
82
+ res.supported = true;
83
+ res.blob = await this._exportVideo(data);
84
+ break;
85
+ }
86
+ return res;
87
+ }
88
+ }
89
+ exports.ExportVideoInstance = ExportVideoInstance;
90
+ });
@@ -0,0 +1,12 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ });
package/umd/index.js ADDED
@@ -0,0 +1,32 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "./ExportVideoInstance"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.loadExportVideoPlugin = void 0;
13
+ const ExportVideoInstance_1 = require("./ExportVideoInstance");
14
+ class ExportVideoPlugin {
15
+ constructor(engine) {
16
+ this.id = "export-video";
17
+ this._engine = engine;
18
+ }
19
+ getPlugin(container) {
20
+ return new ExportVideoInstance_1.ExportVideoInstance(container, this._engine);
21
+ }
22
+ loadOptions() {
23
+ }
24
+ needsPlugin() {
25
+ return true;
26
+ }
27
+ }
28
+ async function loadExportVideoPlugin(engine, refresh = true) {
29
+ await engine.addPlugin(new ExportVideoPlugin(engine), refresh);
30
+ }
31
+ exports.loadExportVideoPlugin = loadExportVideoPlugin;
32
+ });