@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 +21 -0
- package/README.md +74 -0
- package/browser/ExportImageInstance.js +33 -0
- package/browser/IExportImageData.js +1 -0
- package/browser/index.js +18 -0
- package/cjs/ExportImageInstance.js +37 -0
- package/cjs/IExportImageData.js +2 -0
- package/cjs/index.js +22 -0
- package/esm/ExportImageInstance.js +33 -0
- package/esm/IExportImageData.js +1 -0
- package/esm/index.js +18 -0
- package/package.json +96 -0
- package/report.html +39 -0
- package/tsparticles.plugin.export.image.js +118 -0
- package/tsparticles.plugin.export.image.min.js +2 -0
- package/tsparticles.plugin.export.image.min.js.LICENSE.txt +1 -0
- package/types/ExportImageInstance.d.ts +8 -0
- package/types/IExportImageData.d.ts +4 -0
- package/types/index.d.ts +2 -0
- package/umd/ExportImageInstance.js +47 -0
- package/umd/IExportImageData.js +12 -0
- package/umd/index.js +32 -0
|
@@ -0,0 +1,118 @@
|
|
|
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
|
+
loadExportImagePlugin: () => (/* binding */ loadExportImagePlugin)
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
;// CONCATENATED MODULE: ./dist/browser/ExportImageInstance.js
|
|
64
|
+
class ExportImageInstance {
|
|
65
|
+
constructor(container, engine) {
|
|
66
|
+
this._exportImage = async data => {
|
|
67
|
+
const element = this._container.canvas.element;
|
|
68
|
+
if (!element) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
return new Promise(resolve => {
|
|
72
|
+
element.toBlob(blob => {
|
|
73
|
+
if (!blob) {
|
|
74
|
+
resolve(undefined);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
resolve(blob);
|
|
78
|
+
}, data.type ?? "image/png", data.quality);
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
this._container = container;
|
|
82
|
+
this._engine = engine;
|
|
83
|
+
}
|
|
84
|
+
async export(type, data) {
|
|
85
|
+
const res = {
|
|
86
|
+
supported: false
|
|
87
|
+
};
|
|
88
|
+
switch (type) {
|
|
89
|
+
case "image":
|
|
90
|
+
res.supported = true;
|
|
91
|
+
res.blob = await this._exportImage(data);
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
return res;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
;// CONCATENATED MODULE: ./dist/browser/index.js
|
|
98
|
+
|
|
99
|
+
class ExportImagePlugin {
|
|
100
|
+
constructor(engine) {
|
|
101
|
+
this.id = "export-image";
|
|
102
|
+
this._engine = engine;
|
|
103
|
+
}
|
|
104
|
+
getPlugin(container) {
|
|
105
|
+
return new ExportImageInstance(container, this._engine);
|
|
106
|
+
}
|
|
107
|
+
loadOptions() {}
|
|
108
|
+
needsPlugin() {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async function loadExportImagePlugin(engine, refresh = true) {
|
|
113
|
+
await engine.addPlugin(new ExportImagePlugin(engine), refresh);
|
|
114
|
+
}
|
|
115
|
+
/******/ return __webpack_exports__;
|
|
116
|
+
/******/ })()
|
|
117
|
+
;
|
|
118
|
+
});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see tsparticles.plugin.export.image.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 n in o)("object"==typeof exports?exports:e)[n]=o[n]}}(this,(()=>(()=>{"use strict";var e={d:(t,o)=>{for(var n in o)e.o(o,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:o[n]})},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,{loadExportImagePlugin:()=>r});class o{constructor(e,t){this._exportImage=async e=>{const t=this._container.canvas.element;if(t)return new Promise((o=>{t.toBlob((e=>{o(e||void 0)}),e.type??"image/png",e.quality)}))},this._container=e,this._engine=t}async export(e,t){const o={supported:!1};if("image"===e)o.supported=!0,o.blob=await this._exportImage(t);return o}}class n{constructor(e){this.id="export-image",this._engine=e}getPlugin(e){return new o(e,this._engine)}loadOptions(){}needsPlugin(){return!0}}async function r(e,t=!0){await e.addPlugin(new n(e),t)}return t})()));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles Export Image Plugin v3.0.0-beta.0 by Matteo Bruni */
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Container, Engine, ExportResult, IContainerPlugin } from "@tsparticles/engine";
|
|
2
|
+
export declare class ExportImageInstance implements IContainerPlugin {
|
|
3
|
+
private readonly _container;
|
|
4
|
+
private readonly _engine;
|
|
5
|
+
constructor(container: Container, engine: Engine);
|
|
6
|
+
export(type: string, data: Record<string, unknown>): Promise<ExportResult>;
|
|
7
|
+
private readonly _exportImage;
|
|
8
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
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.ExportImageInstance = void 0;
|
|
13
|
+
class ExportImageInstance {
|
|
14
|
+
constructor(container, engine) {
|
|
15
|
+
this._exportImage = async (data) => {
|
|
16
|
+
const element = this._container.canvas.element;
|
|
17
|
+
if (!element) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
return new Promise((resolve) => {
|
|
21
|
+
element.toBlob((blob) => {
|
|
22
|
+
if (!blob) {
|
|
23
|
+
resolve(undefined);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
resolve(blob);
|
|
27
|
+
}, data.type ?? "image/png", data.quality);
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
this._container = container;
|
|
31
|
+
this._engine = engine;
|
|
32
|
+
}
|
|
33
|
+
async export(type, data) {
|
|
34
|
+
const res = {
|
|
35
|
+
supported: false,
|
|
36
|
+
};
|
|
37
|
+
switch (type) {
|
|
38
|
+
case "image":
|
|
39
|
+
res.supported = true;
|
|
40
|
+
res.blob = await this._exportImage(data);
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
return res;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.ExportImageInstance = ExportImageInstance;
|
|
47
|
+
});
|
|
@@ -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", "./ExportImageInstance"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.loadExportImagePlugin = void 0;
|
|
13
|
+
const ExportImageInstance_1 = require("./ExportImageInstance");
|
|
14
|
+
class ExportImagePlugin {
|
|
15
|
+
constructor(engine) {
|
|
16
|
+
this.id = "export-image";
|
|
17
|
+
this._engine = engine;
|
|
18
|
+
}
|
|
19
|
+
getPlugin(container) {
|
|
20
|
+
return new ExportImageInstance_1.ExportImageInstance(container, this._engine);
|
|
21
|
+
}
|
|
22
|
+
loadOptions() {
|
|
23
|
+
}
|
|
24
|
+
needsPlugin() {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async function loadExportImagePlugin(engine, refresh = true) {
|
|
29
|
+
await engine.addPlugin(new ExportImagePlugin(engine), refresh);
|
|
30
|
+
}
|
|
31
|
+
exports.loadExportImagePlugin = loadExportImagePlugin;
|
|
32
|
+
});
|