@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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Matteo Bruni
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,74 @@
1
+ [![banner](https://particles.js.org/videos/banner3.png)](https://particles.js.org)
2
+
3
+ # tsParticles Export Video Plugin
4
+
5
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/@tsparticles/plugin-export-video/badge)](https://www.jsdelivr.com/package/npm/@tsparticles/plugin-export-video)
6
+ [![npmjs](https://badge.fury.io/js/@tsparticles/plugin-export-video.svg)](https://www.npmjs.com/package/@tsparticles/plugin-export-video)
7
+ [![npmjs](https://img.shields.io/npm/dt/@tsparticles/plugin-export-video)](https://www.npmjs.com/package/@tsparticles/plugin-export-video) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
8
+
9
+ [tsParticles](https://github.com/matteobruni/tsparticles) plugin for adding the export video support.
10
+
11
+ ## How to use it
12
+
13
+ ### CDN / Vanilla JS / jQuery
14
+
15
+ The CDN/Vanilla version JS has one required file in vanilla configuration:
16
+
17
+ Including the `tsparticles.plugin.export.video.min.js` file will export the function to load the plugin:
18
+
19
+ ```text
20
+ loadExportVideoPlugin
21
+ ```
22
+
23
+ ### Usage
24
+
25
+ Once the scripts are loaded you can set up `tsParticles` and the plugin like this:
26
+
27
+ ```javascript
28
+ (async () => {
29
+ await loadExportVideoPlugin();
30
+
31
+ await tsParticles.load({
32
+ id: "tsparticles",
33
+ options: {
34
+ /* options */
35
+ },
36
+ });
37
+ })();
38
+ ```
39
+
40
+ ### ESM / CommonJS
41
+
42
+ This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
43
+
44
+ ```shell
45
+ $ npm install @tsparticles/plugin-export-video
46
+ ```
47
+
48
+ or
49
+
50
+ ```shell
51
+ $ yarn add @tsparticles/plugin-export-video
52
+ ```
53
+
54
+ Then you need to import it in the app, like this:
55
+
56
+ ```javascript
57
+ const { tsParticles } = require("@tsparticles/engine");
58
+ const { loadExportVideoPlugin } = require("@tsparticles/plugin-export-video");
59
+
60
+ (async () => {
61
+ await loadExportVideoPlugin();
62
+ })();
63
+ ```
64
+
65
+ or
66
+
67
+ ```javascript
68
+ import { tsParticles } from "@tsparticles/engine";
69
+ import { loadExportVideoPlugin } from "@tsparticles/plugin-export-video";
70
+
71
+ (async () => {
72
+ await loadExportVideoPlugin();
73
+ })();
74
+ ```
@@ -0,0 +1,76 @@
1
+ const videoTypes = ["webm", "ogg", "mp4", "x-matroska"], codecs = [
2
+ "vp9",
3
+ "vp9.0",
4
+ "vp8",
5
+ "vp8.0",
6
+ "avc1",
7
+ "av1",
8
+ "h265",
9
+ "h.265",
10
+ "h264",
11
+ "h.264",
12
+ "opus",
13
+ "pcm",
14
+ "aac",
15
+ "mpeg",
16
+ "mp4a",
17
+ ];
18
+ function getVideoSupportedMimeTypes() {
19
+ const isSupported = MediaRecorder.isTypeSupported, supported = [];
20
+ videoTypes.forEach((type) => {
21
+ const mimeType = `video/${type}`;
22
+ codecs.forEach((codec) => [
23
+ `${mimeType};codecs=${codec}`,
24
+ `${mimeType};codecs=${codec.toUpperCase()}`,
25
+ ].forEach((variation) => {
26
+ if (isSupported(variation)) {
27
+ supported.push(variation);
28
+ }
29
+ }));
30
+ if (isSupported(mimeType)) {
31
+ supported.push(mimeType);
32
+ }
33
+ });
34
+ return supported;
35
+ }
36
+ export class ExportVideoInstance {
37
+ constructor(container, engine) {
38
+ this._supportedTypes = [];
39
+ this._exportVideo = async (data) => {
40
+ const element = this._container.canvas.element;
41
+ if (!element) {
42
+ return;
43
+ }
44
+ return new Promise((resolve) => {
45
+ const stream = element.captureStream(data.fps ?? this._container.actualOptions.fpsLimit), mimeType = data.mimeType ?? this._supportedTypes[0], recorder = new MediaRecorder(stream, {
46
+ mimeType,
47
+ }), chunks = [];
48
+ recorder.addEventListener("dataavailable", (event) => {
49
+ chunks.push(event.data);
50
+ });
51
+ recorder.addEventListener("stop", () => {
52
+ resolve(new Blob(chunks, { type: mimeType }));
53
+ });
54
+ recorder.start();
55
+ setTimeout(() => {
56
+ recorder.stop();
57
+ }, data.duration ?? 5000);
58
+ });
59
+ };
60
+ this._container = container;
61
+ this._engine = engine;
62
+ this._supportedTypes = getVideoSupportedMimeTypes();
63
+ }
64
+ async export(type, data) {
65
+ const res = {
66
+ supported: false,
67
+ };
68
+ switch (type) {
69
+ case "video":
70
+ res.supported = true;
71
+ res.blob = await this._exportVideo(data);
72
+ break;
73
+ }
74
+ return res;
75
+ }
76
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ import { ExportVideoInstance } from "./ExportVideoInstance";
2
+ class ExportVideoPlugin {
3
+ constructor(engine) {
4
+ this.id = "export-video";
5
+ this._engine = engine;
6
+ }
7
+ getPlugin(container) {
8
+ return new ExportVideoInstance(container, this._engine);
9
+ }
10
+ loadOptions() {
11
+ }
12
+ needsPlugin() {
13
+ return true;
14
+ }
15
+ }
16
+ export async function loadExportVideoPlugin(engine, refresh = true) {
17
+ await engine.addPlugin(new ExportVideoPlugin(engine), refresh);
18
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExportVideoInstance = void 0;
4
+ const videoTypes = ["webm", "ogg", "mp4", "x-matroska"], codecs = [
5
+ "vp9",
6
+ "vp9.0",
7
+ "vp8",
8
+ "vp8.0",
9
+ "avc1",
10
+ "av1",
11
+ "h265",
12
+ "h.265",
13
+ "h264",
14
+ "h.264",
15
+ "opus",
16
+ "pcm",
17
+ "aac",
18
+ "mpeg",
19
+ "mp4a",
20
+ ];
21
+ function getVideoSupportedMimeTypes() {
22
+ const isSupported = MediaRecorder.isTypeSupported, supported = [];
23
+ videoTypes.forEach((type) => {
24
+ const mimeType = `video/${type}`;
25
+ codecs.forEach((codec) => [
26
+ `${mimeType};codecs=${codec}`,
27
+ `${mimeType};codecs=${codec.toUpperCase()}`,
28
+ ].forEach((variation) => {
29
+ if (isSupported(variation)) {
30
+ supported.push(variation);
31
+ }
32
+ }));
33
+ if (isSupported(mimeType)) {
34
+ supported.push(mimeType);
35
+ }
36
+ });
37
+ return supported;
38
+ }
39
+ class ExportVideoInstance {
40
+ constructor(container, engine) {
41
+ this._supportedTypes = [];
42
+ this._exportVideo = async (data) => {
43
+ const element = this._container.canvas.element;
44
+ if (!element) {
45
+ return;
46
+ }
47
+ return new Promise((resolve) => {
48
+ const stream = element.captureStream(data.fps ?? this._container.actualOptions.fpsLimit), mimeType = data.mimeType ?? this._supportedTypes[0], recorder = new MediaRecorder(stream, {
49
+ mimeType,
50
+ }), chunks = [];
51
+ recorder.addEventListener("dataavailable", (event) => {
52
+ chunks.push(event.data);
53
+ });
54
+ recorder.addEventListener("stop", () => {
55
+ resolve(new Blob(chunks, { type: mimeType }));
56
+ });
57
+ recorder.start();
58
+ setTimeout(() => {
59
+ recorder.stop();
60
+ }, data.duration ?? 5000);
61
+ });
62
+ };
63
+ this._container = container;
64
+ this._engine = engine;
65
+ this._supportedTypes = getVideoSupportedMimeTypes();
66
+ }
67
+ async export(type, data) {
68
+ const res = {
69
+ supported: false,
70
+ };
71
+ switch (type) {
72
+ case "video":
73
+ res.supported = true;
74
+ res.blob = await this._exportVideo(data);
75
+ break;
76
+ }
77
+ return res;
78
+ }
79
+ }
80
+ exports.ExportVideoInstance = ExportVideoInstance;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/index.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadExportVideoPlugin = void 0;
4
+ const ExportVideoInstance_1 = require("./ExportVideoInstance");
5
+ class ExportVideoPlugin {
6
+ constructor(engine) {
7
+ this.id = "export-video";
8
+ this._engine = engine;
9
+ }
10
+ getPlugin(container) {
11
+ return new ExportVideoInstance_1.ExportVideoInstance(container, this._engine);
12
+ }
13
+ loadOptions() {
14
+ }
15
+ needsPlugin() {
16
+ return true;
17
+ }
18
+ }
19
+ async function loadExportVideoPlugin(engine, refresh = true) {
20
+ await engine.addPlugin(new ExportVideoPlugin(engine), refresh);
21
+ }
22
+ exports.loadExportVideoPlugin = loadExportVideoPlugin;
@@ -0,0 +1,76 @@
1
+ const videoTypes = ["webm", "ogg", "mp4", "x-matroska"], codecs = [
2
+ "vp9",
3
+ "vp9.0",
4
+ "vp8",
5
+ "vp8.0",
6
+ "avc1",
7
+ "av1",
8
+ "h265",
9
+ "h.265",
10
+ "h264",
11
+ "h.264",
12
+ "opus",
13
+ "pcm",
14
+ "aac",
15
+ "mpeg",
16
+ "mp4a",
17
+ ];
18
+ function getVideoSupportedMimeTypes() {
19
+ const isSupported = MediaRecorder.isTypeSupported, supported = [];
20
+ videoTypes.forEach((type) => {
21
+ const mimeType = `video/${type}`;
22
+ codecs.forEach((codec) => [
23
+ `${mimeType};codecs=${codec}`,
24
+ `${mimeType};codecs=${codec.toUpperCase()}`,
25
+ ].forEach((variation) => {
26
+ if (isSupported(variation)) {
27
+ supported.push(variation);
28
+ }
29
+ }));
30
+ if (isSupported(mimeType)) {
31
+ supported.push(mimeType);
32
+ }
33
+ });
34
+ return supported;
35
+ }
36
+ export class ExportVideoInstance {
37
+ constructor(container, engine) {
38
+ this._supportedTypes = [];
39
+ this._exportVideo = async (data) => {
40
+ const element = this._container.canvas.element;
41
+ if (!element) {
42
+ return;
43
+ }
44
+ return new Promise((resolve) => {
45
+ const stream = element.captureStream(data.fps ?? this._container.actualOptions.fpsLimit), mimeType = data.mimeType ?? this._supportedTypes[0], recorder = new MediaRecorder(stream, {
46
+ mimeType,
47
+ }), chunks = [];
48
+ recorder.addEventListener("dataavailable", (event) => {
49
+ chunks.push(event.data);
50
+ });
51
+ recorder.addEventListener("stop", () => {
52
+ resolve(new Blob(chunks, { type: mimeType }));
53
+ });
54
+ recorder.start();
55
+ setTimeout(() => {
56
+ recorder.stop();
57
+ }, data.duration ?? 5000);
58
+ });
59
+ };
60
+ this._container = container;
61
+ this._engine = engine;
62
+ this._supportedTypes = getVideoSupportedMimeTypes();
63
+ }
64
+ async export(type, data) {
65
+ const res = {
66
+ supported: false,
67
+ };
68
+ switch (type) {
69
+ case "video":
70
+ res.supported = true;
71
+ res.blob = await this._exportVideo(data);
72
+ break;
73
+ }
74
+ return res;
75
+ }
76
+ }
@@ -0,0 +1 @@
1
+ export {};
package/esm/index.js ADDED
@@ -0,0 +1,18 @@
1
+ import { ExportVideoInstance } from "./ExportVideoInstance";
2
+ class ExportVideoPlugin {
3
+ constructor(engine) {
4
+ this.id = "export-video";
5
+ this._engine = engine;
6
+ }
7
+ getPlugin(container) {
8
+ return new ExportVideoInstance(container, this._engine);
9
+ }
10
+ loadOptions() {
11
+ }
12
+ needsPlugin() {
13
+ return true;
14
+ }
15
+ }
16
+ export async function loadExportVideoPlugin(engine, refresh = true) {
17
+ await engine.addPlugin(new ExportVideoPlugin(engine), refresh);
18
+ }
package/package.json ADDED
@@ -0,0 +1,96 @@
1
+ {
2
+ "name": "@tsparticles/plugin-export-video",
3
+ "version": "3.0.0-beta.0",
4
+ "description": "tsParticles export video plugin",
5
+ "homepage": "https://particles.js.org",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/matteobruni/tsparticles.git",
9
+ "directory": "plugins/exports/video"
10
+ },
11
+ "keywords": [
12
+ "front-end",
13
+ "frontend",
14
+ "tsparticles",
15
+ "particles.js",
16
+ "particlesjs",
17
+ "particles",
18
+ "particle",
19
+ "canvas",
20
+ "jsparticles",
21
+ "xparticles",
22
+ "particles-js",
23
+ "particles-bg",
24
+ "particles-bg-vue",
25
+ "particles-ts",
26
+ "particles.ts",
27
+ "react-particles-js",
28
+ "react-particles.js",
29
+ "react-particles",
30
+ "react",
31
+ "reactjs",
32
+ "vue-particles",
33
+ "ngx-particles",
34
+ "angular-particles",
35
+ "particleground",
36
+ "vue",
37
+ "vuejs",
38
+ "preact",
39
+ "preactjs",
40
+ "jquery",
41
+ "angularjs",
42
+ "angular",
43
+ "typescript",
44
+ "javascript",
45
+ "animation",
46
+ "web",
47
+ "html5",
48
+ "web-design",
49
+ "webdesign",
50
+ "css",
51
+ "html",
52
+ "css3",
53
+ "animated",
54
+ "background",
55
+ "confetti",
56
+ "canvas",
57
+ "fireworks",
58
+ "fireworks-js",
59
+ "confetti-js",
60
+ "confettijs",
61
+ "fireworksjs",
62
+ "canvas-confetti",
63
+ "@tsparticles/plugin"
64
+ ],
65
+ "author": "Matteo Bruni <matteo.bruni@me.com>",
66
+ "license": "MIT",
67
+ "bugs": {
68
+ "url": "https://github.com/matteobruni/tsparticles/issues"
69
+ },
70
+ "funding": [
71
+ {
72
+ "type": "github",
73
+ "url": "https://github.com/sponsors/matteobruni"
74
+ },
75
+ {
76
+ "type": "github",
77
+ "url": "https://github.com/sponsors/tsparticles"
78
+ },
79
+ {
80
+ "type": "buymeacoffee",
81
+ "url": "https://www.buymeacoffee.com/matteobruni"
82
+ }
83
+ ],
84
+ "main": "cjs/index.js",
85
+ "jsdelivr": "tsparticles.plugin.export.video.min.js",
86
+ "unpkg": "tsparticles.plugin.export.video.min.js",
87
+ "module": "esm/index.js",
88
+ "types": "types/index.d.ts",
89
+ "sideEffects": false,
90
+ "dependencies": {
91
+ "@tsparticles/engine": "^3.0.0-beta.0"
92
+ },
93
+ "publishConfig": {
94
+ "access": "public"
95
+ }
96
+ }