@tsparticles/plugin-export-image 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/images/banner3.png)](https://particles.js.org)
2
+
3
+ # tsParticles Export Image Plugin
4
+
5
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/@tsparticles/plugin-export-image/badge)](https://www.jsdelivr.com/package/npm/@tsparticles/plugin-export-image)
6
+ [![npmjs](https://badge.fury.io/js/@tsparticles/plugin-export-image.svg)](https://www.npmjs.com/package/@tsparticles/plugin-export-image)
7
+ [![npmjs](https://img.shields.io/npm/dt/@tsparticles/plugin-export-image)](https://www.npmjs.com/package/@tsparticles/plugin-export-image) [![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 image 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.image.min.js` file will export the function to load the plugin:
18
+
19
+ ```text
20
+ loadExportImagePlugin
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 loadExportImagePlugin();
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-image
46
+ ```
47
+
48
+ or
49
+
50
+ ```shell
51
+ $ yarn add @tsparticles/plugin-export-image
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 { loadExportImagePlugin } = require("@tsparticles/plugin-export-image");
59
+
60
+ (async () => {
61
+ await loadExportImagePlugin();
62
+ })();
63
+ ```
64
+
65
+ or
66
+
67
+ ```javascript
68
+ import { tsParticles } from "@tsparticles/engine";
69
+ import { loadExportImagePlugin } from "@tsparticles/plugin-export-image";
70
+
71
+ (async () => {
72
+ await loadExportImagePlugin();
73
+ })();
74
+ ```
@@ -0,0 +1,33 @@
1
+ export class ExportImageInstance {
2
+ constructor(container, engine) {
3
+ this._exportImage = async (data) => {
4
+ const element = this._container.canvas.element;
5
+ if (!element) {
6
+ return;
7
+ }
8
+ return new Promise((resolve) => {
9
+ element.toBlob((blob) => {
10
+ if (!blob) {
11
+ resolve(undefined);
12
+ return;
13
+ }
14
+ resolve(blob);
15
+ }, data.type ?? "image/png", data.quality);
16
+ });
17
+ };
18
+ this._container = container;
19
+ this._engine = engine;
20
+ }
21
+ async export(type, data) {
22
+ const res = {
23
+ supported: false,
24
+ };
25
+ switch (type) {
26
+ case "image":
27
+ res.supported = true;
28
+ res.blob = await this._exportImage(data);
29
+ break;
30
+ }
31
+ return res;
32
+ }
33
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ import { ExportImageInstance } from "./ExportImageInstance";
2
+ class ExportImagePlugin {
3
+ constructor(engine) {
4
+ this.id = "export-image";
5
+ this._engine = engine;
6
+ }
7
+ getPlugin(container) {
8
+ return new ExportImageInstance(container, this._engine);
9
+ }
10
+ loadOptions() {
11
+ }
12
+ needsPlugin() {
13
+ return true;
14
+ }
15
+ }
16
+ export async function loadExportImagePlugin(engine, refresh = true) {
17
+ await engine.addPlugin(new ExportImagePlugin(engine), refresh);
18
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExportImageInstance = void 0;
4
+ class ExportImageInstance {
5
+ constructor(container, engine) {
6
+ this._exportImage = async (data) => {
7
+ const element = this._container.canvas.element;
8
+ if (!element) {
9
+ return;
10
+ }
11
+ return new Promise((resolve) => {
12
+ element.toBlob((blob) => {
13
+ if (!blob) {
14
+ resolve(undefined);
15
+ return;
16
+ }
17
+ resolve(blob);
18
+ }, data.type ?? "image/png", data.quality);
19
+ });
20
+ };
21
+ this._container = container;
22
+ this._engine = engine;
23
+ }
24
+ async export(type, data) {
25
+ const res = {
26
+ supported: false,
27
+ };
28
+ switch (type) {
29
+ case "image":
30
+ res.supported = true;
31
+ res.blob = await this._exportImage(data);
32
+ break;
33
+ }
34
+ return res;
35
+ }
36
+ }
37
+ exports.ExportImageInstance = ExportImageInstance;
@@ -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.loadExportImagePlugin = void 0;
4
+ const ExportImageInstance_1 = require("./ExportImageInstance");
5
+ class ExportImagePlugin {
6
+ constructor(engine) {
7
+ this.id = "export-image";
8
+ this._engine = engine;
9
+ }
10
+ getPlugin(container) {
11
+ return new ExportImageInstance_1.ExportImageInstance(container, this._engine);
12
+ }
13
+ loadOptions() {
14
+ }
15
+ needsPlugin() {
16
+ return true;
17
+ }
18
+ }
19
+ async function loadExportImagePlugin(engine, refresh = true) {
20
+ await engine.addPlugin(new ExportImagePlugin(engine), refresh);
21
+ }
22
+ exports.loadExportImagePlugin = loadExportImagePlugin;
@@ -0,0 +1,33 @@
1
+ export class ExportImageInstance {
2
+ constructor(container, engine) {
3
+ this._exportImage = async (data) => {
4
+ const element = this._container.canvas.element;
5
+ if (!element) {
6
+ return;
7
+ }
8
+ return new Promise((resolve) => {
9
+ element.toBlob((blob) => {
10
+ if (!blob) {
11
+ resolve(undefined);
12
+ return;
13
+ }
14
+ resolve(blob);
15
+ }, data.type ?? "image/png", data.quality);
16
+ });
17
+ };
18
+ this._container = container;
19
+ this._engine = engine;
20
+ }
21
+ async export(type, data) {
22
+ const res = {
23
+ supported: false,
24
+ };
25
+ switch (type) {
26
+ case "image":
27
+ res.supported = true;
28
+ res.blob = await this._exportImage(data);
29
+ break;
30
+ }
31
+ return res;
32
+ }
33
+ }
@@ -0,0 +1 @@
1
+ export {};
package/esm/index.js ADDED
@@ -0,0 +1,18 @@
1
+ import { ExportImageInstance } from "./ExportImageInstance";
2
+ class ExportImagePlugin {
3
+ constructor(engine) {
4
+ this.id = "export-image";
5
+ this._engine = engine;
6
+ }
7
+ getPlugin(container) {
8
+ return new ExportImageInstance(container, this._engine);
9
+ }
10
+ loadOptions() {
11
+ }
12
+ needsPlugin() {
13
+ return true;
14
+ }
15
+ }
16
+ export async function loadExportImagePlugin(engine, refresh = true) {
17
+ await engine.addPlugin(new ExportImagePlugin(engine), refresh);
18
+ }
package/package.json ADDED
@@ -0,0 +1,96 @@
1
+ {
2
+ "name": "@tsparticles/plugin-export-image",
3
+ "version": "3.0.0-beta.0",
4
+ "description": "tsParticles export image 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/image"
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.image.min.js",
86
+ "unpkg": "tsparticles.plugin.export.image.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
+ }