@tsparticles/plugin-background-mask 4.0.0-alpha.2 → 4.0.0-alpha.21
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/603.min.js +1 -0
- package/607.min.js +1 -0
- package/browser/BackgroundMaskPlugin.js +9 -8
- package/browser/BackgroundMaskPluginInstance.js +79 -0
- package/browser/Options/Classes/BackgroundMask.js +3 -0
- package/browser/Options/Classes/BackgroundMaskCover.js +3 -0
- package/browser/index.js +3 -3
- package/cjs/BackgroundMaskPlugin.js +9 -8
- package/cjs/BackgroundMaskPluginInstance.js +79 -0
- package/cjs/Options/Classes/BackgroundMask.js +3 -0
- package/cjs/Options/Classes/BackgroundMaskCover.js +3 -0
- package/cjs/index.js +3 -3
- package/dist_browser_BackgroundMaskPluginInstance_js.js +30 -0
- package/dist_browser_BackgroundMaskPlugin_js.js +4 -14
- package/esm/BackgroundMaskPlugin.js +9 -8
- package/esm/BackgroundMaskPluginInstance.js +79 -0
- package/esm/Options/Classes/BackgroundMask.js +3 -0
- package/esm/Options/Classes/BackgroundMaskCover.js +3 -0
- package/esm/index.js +3 -3
- package/package.json +2 -2
- package/report.html +3 -3
- package/tsparticles.plugin.background-mask.js +11 -11
- package/tsparticles.plugin.background-mask.min.js +2 -2
- package/types/BackgroundMaskPlugin.d.ts +5 -6
- package/types/{BackgroundMaskInstance.d.ts → BackgroundMaskPluginInstance.d.ts} +3 -3
- package/types/index.d.ts +1 -1
- package/umd/BackgroundMaskPlugin.js +44 -9
- package/umd/{BackgroundMaskInstance.js → BackgroundMaskPluginInstance.js} +42 -38
- package/umd/Options/Classes/BackgroundMask.js +3 -0
- package/umd/Options/Classes/BackgroundMaskCover.js +3 -0
- package/umd/index.js +3 -3
- package/224.min.js +0 -2
- package/224.min.js.LICENSE.txt +0 -1
- package/browser/BackgroundMaskInstance.js +0 -75
- package/cjs/BackgroundMaskInstance.js +0 -75
- package/esm/BackgroundMaskInstance.js +0 -75
- package/tsparticles.plugin.background-mask.min.js.LICENSE.txt +0 -1
package/603.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(this.webpackChunk_tsparticles_plugin_background_mask=this.webpackChunk_tsparticles_plugin_background_mask||[]).push([[603],{603(o,i,e){e.d(i,{BackgroundMaskPlugin:()=>c});var s=e(303);class t{color;image;opacity;constructor(){this.opacity=1}load(o){(0,s.isNull)(o)||(void 0!==o.color&&(this.color=s.OptionsColor.create(this.color,o.color)),void 0!==o.image&&(this.image=o.image),void 0!==o.opacity&&(this.opacity=o.opacity))}}class a{composite;cover;enable;constructor(){this.composite="destination-out",this.cover=new t,this.enable=!1}load(o){if(!(0,s.isNull)(o)){if(void 0!==o.composite&&(this.composite=o.composite),void 0!==o.cover){let i=o.cover,e=(0,s.isString)(o.cover)?{color:o.cover}:o.cover;this.cover.load(void 0!==i.color||void 0!==i.image?i:{color:e})}void 0!==o.enable&&(this.enable=o.enable)}}}class c{id="background-mask";_engine;constructor(o){this._engine=o}async getPlugin(o){let{BackgroundMaskPluginInstance:i}=await e.e(607).then(e.bind(e,607));return new i(o,this._engine)}loadOptions(o,i,e){if(!this.needsPlugin(i)&&!this.needsPlugin(e))return;let s=i.backgroundMask;s?.load||(i.backgroundMask=s=new a),s.load(e?.backgroundMask)}needsPlugin(o){return!!o?.backgroundMask?.enable}}}}]);
|
package/607.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(this.webpackChunk_tsparticles_plugin_background_mask=this.webpackChunk_tsparticles_plugin_background_mask||[]).push([[607],{607(e,a,t){t.d(a,{BackgroundMaskPluginInstance:()=>n});var i=t(303);class n{_container;_coverColorStyle;_coverImage;_defaultCompositeValue;_engine;constructor(e,a){this._container=e,this._engine=a}canvasClear(){let e=this._container.actualOptions.backgroundMask;return!!e?.enable&&this.canvasPaint()}canvasPaint(){if(!this._container.actualOptions.backgroundMask?.enable)return!1;let e=this._container.canvas;return e.canvasClear(),this._coverImage?e.paintImage(this._coverImage.image,this._coverImage.opacity):e.paintBase(this._coverColorStyle),!0}drawSettingsCleanup(e){this._defaultCompositeValue&&(e.globalCompositeOperation=this._defaultCompositeValue)}drawSettingsSetup(e){let a=e.globalCompositeOperation,t=this._container.actualOptions.backgroundMask;this._defaultCompositeValue=a,e.globalCompositeOperation=t?.enable?t.composite:a}async init(){await this._initCover()}_initCover=async()=>{let e=this._container.actualOptions,a=e.backgroundMask?.cover,t=a?.color;if(t){let e=(0,i.rangeColorToRgb)(this._engine,t);if(e){let t={...e,a:a.opacity};this._coverColorStyle=(0,i.getStyleFromRgb)(t,this._container.hdr,t.a)}}else await new Promise((e,t)=>{if(!a?.image)return;let n=(0,i.safeDocument)().createElement("img");n.addEventListener("load",()=>{this._coverImage={image:n,opacity:a.opacity},e()}),n.addEventListener("error",()=>{t(Error("Error loading image"))}),n.src=a.image})}}}}]);
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { BackgroundMask } from "./Options/Classes/BackgroundMask.js";
|
|
2
|
-
import { BackgroundMaskInstance } from "./BackgroundMaskInstance.js";
|
|
3
2
|
export class BackgroundMaskPlugin {
|
|
3
|
+
id = "background-mask";
|
|
4
|
+
_engine;
|
|
4
5
|
constructor(engine) {
|
|
5
|
-
this.id = "background-mask";
|
|
6
6
|
this._engine = engine;
|
|
7
7
|
}
|
|
8
|
-
getPlugin(container) {
|
|
9
|
-
|
|
8
|
+
async getPlugin(container) {
|
|
9
|
+
const { BackgroundMaskPluginInstance } = await import("./BackgroundMaskPluginInstance.js");
|
|
10
|
+
return new BackgroundMaskPluginInstance(container, this._engine);
|
|
10
11
|
}
|
|
11
|
-
loadOptions(options, source) {
|
|
12
|
-
if (!this.needsPlugin()) {
|
|
12
|
+
loadOptions(_container, options, source) {
|
|
13
|
+
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
13
14
|
return;
|
|
14
15
|
}
|
|
15
16
|
let backgroundMaskOptions = options.backgroundMask;
|
|
@@ -18,7 +19,7 @@ export class BackgroundMaskPlugin {
|
|
|
18
19
|
}
|
|
19
20
|
backgroundMaskOptions.load(source?.backgroundMask);
|
|
20
21
|
}
|
|
21
|
-
needsPlugin() {
|
|
22
|
-
return
|
|
22
|
+
needsPlugin(options) {
|
|
23
|
+
return !!options?.backgroundMask?.enable;
|
|
23
24
|
}
|
|
24
25
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { getStyleFromRgb, rangeColorToRgb, safeDocument, } from "@tsparticles/engine";
|
|
2
|
+
export class BackgroundMaskPluginInstance {
|
|
3
|
+
_container;
|
|
4
|
+
_coverColorStyle;
|
|
5
|
+
_coverImage;
|
|
6
|
+
_defaultCompositeValue;
|
|
7
|
+
_engine;
|
|
8
|
+
constructor(container, engine) {
|
|
9
|
+
this._container = container;
|
|
10
|
+
this._engine = engine;
|
|
11
|
+
}
|
|
12
|
+
canvasClear() {
|
|
13
|
+
const backgroundMask = this._container.actualOptions.backgroundMask;
|
|
14
|
+
if (!backgroundMask?.enable) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return this.canvasPaint();
|
|
18
|
+
}
|
|
19
|
+
canvasPaint() {
|
|
20
|
+
if (!this._container.actualOptions.backgroundMask?.enable) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
const canvas = this._container.canvas;
|
|
24
|
+
canvas.canvasClear();
|
|
25
|
+
if (this._coverImage) {
|
|
26
|
+
canvas.paintImage(this._coverImage.image, this._coverImage.opacity);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
canvas.paintBase(this._coverColorStyle);
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
drawSettingsCleanup(context) {
|
|
34
|
+
if (!this._defaultCompositeValue) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
context.globalCompositeOperation = this._defaultCompositeValue;
|
|
38
|
+
}
|
|
39
|
+
drawSettingsSetup(context) {
|
|
40
|
+
const previousComposite = context.globalCompositeOperation, backgroundMask = this._container.actualOptions.backgroundMask;
|
|
41
|
+
this._defaultCompositeValue = previousComposite;
|
|
42
|
+
context.globalCompositeOperation = backgroundMask?.enable ? backgroundMask.composite : previousComposite;
|
|
43
|
+
}
|
|
44
|
+
async init() {
|
|
45
|
+
await this._initCover();
|
|
46
|
+
}
|
|
47
|
+
_initCover = async () => {
|
|
48
|
+
const options = this._container.actualOptions, cover = options.backgroundMask?.cover, color = cover?.color;
|
|
49
|
+
if (color) {
|
|
50
|
+
const coverRgb = rangeColorToRgb(this._engine, color);
|
|
51
|
+
if (coverRgb) {
|
|
52
|
+
const coverColor = {
|
|
53
|
+
...coverRgb,
|
|
54
|
+
a: cover.opacity,
|
|
55
|
+
};
|
|
56
|
+
this._coverColorStyle = getStyleFromRgb(coverColor, this._container.hdr, coverColor.a);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
await new Promise((resolve, reject) => {
|
|
61
|
+
if (!cover?.image) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const img = safeDocument().createElement("img");
|
|
65
|
+
img.addEventListener("load", () => {
|
|
66
|
+
this._coverImage = {
|
|
67
|
+
image: img,
|
|
68
|
+
opacity: cover.opacity,
|
|
69
|
+
};
|
|
70
|
+
resolve();
|
|
71
|
+
});
|
|
72
|
+
img.addEventListener("error", () => {
|
|
73
|
+
reject(new Error("Error loading image"));
|
|
74
|
+
});
|
|
75
|
+
img.src = cover.image;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { isNull, isString } from "@tsparticles/engine";
|
|
2
2
|
import { BackgroundMaskCover } from "./BackgroundMaskCover.js";
|
|
3
3
|
export class BackgroundMask {
|
|
4
|
+
composite;
|
|
5
|
+
cover;
|
|
6
|
+
enable;
|
|
4
7
|
constructor() {
|
|
5
8
|
this.composite = "destination-out";
|
|
6
9
|
this.cover = new BackgroundMaskCover();
|
package/browser/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export function loadBackgroundMaskPlugin(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-alpha.
|
|
3
|
-
engine.register(async (e) => {
|
|
1
|
+
export async function loadBackgroundMaskPlugin(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.21");
|
|
3
|
+
await engine.register(async (e) => {
|
|
4
4
|
const { BackgroundMaskPlugin } = await import("./BackgroundMaskPlugin.js");
|
|
5
5
|
e.addPlugin(new BackgroundMaskPlugin(e));
|
|
6
6
|
});
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { BackgroundMask } from "./Options/Classes/BackgroundMask.js";
|
|
2
|
-
import { BackgroundMaskInstance } from "./BackgroundMaskInstance.js";
|
|
3
2
|
export class BackgroundMaskPlugin {
|
|
3
|
+
id = "background-mask";
|
|
4
|
+
_engine;
|
|
4
5
|
constructor(engine) {
|
|
5
|
-
this.id = "background-mask";
|
|
6
6
|
this._engine = engine;
|
|
7
7
|
}
|
|
8
|
-
getPlugin(container) {
|
|
9
|
-
|
|
8
|
+
async getPlugin(container) {
|
|
9
|
+
const { BackgroundMaskPluginInstance } = await import("./BackgroundMaskPluginInstance.js");
|
|
10
|
+
return new BackgroundMaskPluginInstance(container, this._engine);
|
|
10
11
|
}
|
|
11
|
-
loadOptions(options, source) {
|
|
12
|
-
if (!this.needsPlugin()) {
|
|
12
|
+
loadOptions(_container, options, source) {
|
|
13
|
+
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
13
14
|
return;
|
|
14
15
|
}
|
|
15
16
|
let backgroundMaskOptions = options.backgroundMask;
|
|
@@ -18,7 +19,7 @@ export class BackgroundMaskPlugin {
|
|
|
18
19
|
}
|
|
19
20
|
backgroundMaskOptions.load(source?.backgroundMask);
|
|
20
21
|
}
|
|
21
|
-
needsPlugin() {
|
|
22
|
-
return
|
|
22
|
+
needsPlugin(options) {
|
|
23
|
+
return !!options?.backgroundMask?.enable;
|
|
23
24
|
}
|
|
24
25
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { getStyleFromRgb, rangeColorToRgb, safeDocument, } from "@tsparticles/engine";
|
|
2
|
+
export class BackgroundMaskPluginInstance {
|
|
3
|
+
_container;
|
|
4
|
+
_coverColorStyle;
|
|
5
|
+
_coverImage;
|
|
6
|
+
_defaultCompositeValue;
|
|
7
|
+
_engine;
|
|
8
|
+
constructor(container, engine) {
|
|
9
|
+
this._container = container;
|
|
10
|
+
this._engine = engine;
|
|
11
|
+
}
|
|
12
|
+
canvasClear() {
|
|
13
|
+
const backgroundMask = this._container.actualOptions.backgroundMask;
|
|
14
|
+
if (!backgroundMask?.enable) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return this.canvasPaint();
|
|
18
|
+
}
|
|
19
|
+
canvasPaint() {
|
|
20
|
+
if (!this._container.actualOptions.backgroundMask?.enable) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
const canvas = this._container.canvas;
|
|
24
|
+
canvas.canvasClear();
|
|
25
|
+
if (this._coverImage) {
|
|
26
|
+
canvas.paintImage(this._coverImage.image, this._coverImage.opacity);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
canvas.paintBase(this._coverColorStyle);
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
drawSettingsCleanup(context) {
|
|
34
|
+
if (!this._defaultCompositeValue) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
context.globalCompositeOperation = this._defaultCompositeValue;
|
|
38
|
+
}
|
|
39
|
+
drawSettingsSetup(context) {
|
|
40
|
+
const previousComposite = context.globalCompositeOperation, backgroundMask = this._container.actualOptions.backgroundMask;
|
|
41
|
+
this._defaultCompositeValue = previousComposite;
|
|
42
|
+
context.globalCompositeOperation = backgroundMask?.enable ? backgroundMask.composite : previousComposite;
|
|
43
|
+
}
|
|
44
|
+
async init() {
|
|
45
|
+
await this._initCover();
|
|
46
|
+
}
|
|
47
|
+
_initCover = async () => {
|
|
48
|
+
const options = this._container.actualOptions, cover = options.backgroundMask?.cover, color = cover?.color;
|
|
49
|
+
if (color) {
|
|
50
|
+
const coverRgb = rangeColorToRgb(this._engine, color);
|
|
51
|
+
if (coverRgb) {
|
|
52
|
+
const coverColor = {
|
|
53
|
+
...coverRgb,
|
|
54
|
+
a: cover.opacity,
|
|
55
|
+
};
|
|
56
|
+
this._coverColorStyle = getStyleFromRgb(coverColor, this._container.hdr, coverColor.a);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
await new Promise((resolve, reject) => {
|
|
61
|
+
if (!cover?.image) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const img = safeDocument().createElement("img");
|
|
65
|
+
img.addEventListener("load", () => {
|
|
66
|
+
this._coverImage = {
|
|
67
|
+
image: img,
|
|
68
|
+
opacity: cover.opacity,
|
|
69
|
+
};
|
|
70
|
+
resolve();
|
|
71
|
+
});
|
|
72
|
+
img.addEventListener("error", () => {
|
|
73
|
+
reject(new Error("Error loading image"));
|
|
74
|
+
});
|
|
75
|
+
img.src = cover.image;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { isNull, isString } from "@tsparticles/engine";
|
|
2
2
|
import { BackgroundMaskCover } from "./BackgroundMaskCover.js";
|
|
3
3
|
export class BackgroundMask {
|
|
4
|
+
composite;
|
|
5
|
+
cover;
|
|
6
|
+
enable;
|
|
4
7
|
constructor() {
|
|
5
8
|
this.composite = "destination-out";
|
|
6
9
|
this.cover = new BackgroundMaskCover();
|
package/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export function loadBackgroundMaskPlugin(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-alpha.
|
|
3
|
-
engine.register(async (e) => {
|
|
1
|
+
export async function loadBackgroundMaskPlugin(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.21");
|
|
3
|
+
await engine.register(async (e) => {
|
|
4
4
|
const { BackgroundMaskPlugin } = await import("./BackgroundMaskPlugin.js");
|
|
5
5
|
e.addPlugin(new BackgroundMaskPlugin(e));
|
|
6
6
|
});
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
* v4.0.0-alpha.21
|
|
8
|
+
*/
|
|
9
|
+
"use strict";
|
|
10
|
+
/*
|
|
11
|
+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
12
|
+
* This devtool is neither made for production nor for readable output files.
|
|
13
|
+
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
|
14
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
15
|
+
* or disable the default devtool with "devtool: false".
|
|
16
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
17
|
+
*/
|
|
18
|
+
(this["webpackChunk_tsparticles_plugin_background_mask"] = this["webpackChunk_tsparticles_plugin_background_mask"] || []).push([["dist_browser_BackgroundMaskPluginInstance_js"],{
|
|
19
|
+
|
|
20
|
+
/***/ "./dist/browser/BackgroundMaskPluginInstance.js"
|
|
21
|
+
/*!******************************************************!*\
|
|
22
|
+
!*** ./dist/browser/BackgroundMaskPluginInstance.js ***!
|
|
23
|
+
\******************************************************/
|
|
24
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
25
|
+
|
|
26
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ BackgroundMaskPluginInstance: () => (/* binding */ BackgroundMaskPluginInstance)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nclass BackgroundMaskPluginInstance {\n _container;\n _coverColorStyle;\n _coverImage;\n _defaultCompositeValue;\n _engine;\n constructor(container, engine){\n this._container = container;\n this._engine = engine;\n }\n canvasClear() {\n const backgroundMask = this._container.actualOptions.backgroundMask;\n if (!backgroundMask?.enable) {\n return false;\n }\n return this.canvasPaint();\n }\n canvasPaint() {\n if (!this._container.actualOptions.backgroundMask?.enable) {\n return false;\n }\n const canvas = this._container.canvas;\n canvas.canvasClear();\n if (this._coverImage) {\n canvas.paintImage(this._coverImage.image, this._coverImage.opacity);\n } else {\n canvas.paintBase(this._coverColorStyle);\n }\n return true;\n }\n drawSettingsCleanup(context) {\n if (!this._defaultCompositeValue) {\n return;\n }\n context.globalCompositeOperation = this._defaultCompositeValue;\n }\n drawSettingsSetup(context) {\n const previousComposite = context.globalCompositeOperation, backgroundMask = this._container.actualOptions.backgroundMask;\n this._defaultCompositeValue = previousComposite;\n context.globalCompositeOperation = backgroundMask?.enable ? backgroundMask.composite : previousComposite;\n }\n async init() {\n await this._initCover();\n }\n _initCover = async ()=>{\n const options = this._container.actualOptions, cover = options.backgroundMask?.cover, color = cover?.color;\n if (color) {\n const coverRgb = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.rangeColorToRgb)(this._engine, color);\n if (coverRgb) {\n const coverColor = {\n ...coverRgb,\n a: cover.opacity\n };\n this._coverColorStyle = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getStyleFromRgb)(coverColor, this._container.hdr, coverColor.a);\n }\n } else {\n await new Promise((resolve, reject)=>{\n if (!cover?.image) {\n return;\n }\n const img = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeDocument)().createElement(\"img\");\n img.addEventListener(\"load\", ()=>{\n this._coverImage = {\n image: img,\n opacity: cover.opacity\n };\n resolve();\n });\n img.addEventListener(\"error\", ()=>{\n reject(new Error(\"Error loading image\"));\n });\n img.src = cover.image;\n });\n }\n };\n}\n\n\n//# sourceURL=webpack://@tsparticles/plugin-background-mask/./dist/browser/BackgroundMaskPluginInstance.js?\n}");
|
|
27
|
+
|
|
28
|
+
/***/ }
|
|
29
|
+
|
|
30
|
+
}]);
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Demo / Generator : https://particles.js.org/
|
|
5
5
|
* GitHub : https://www.github.com/matteobruni/tsparticles
|
|
6
6
|
* How to use? : Check the GitHub README
|
|
7
|
-
* v4.0.0-alpha.
|
|
7
|
+
* v4.0.0-alpha.21
|
|
8
8
|
*/
|
|
9
9
|
"use strict";
|
|
10
10
|
/*
|
|
@@ -17,23 +17,13 @@
|
|
|
17
17
|
*/
|
|
18
18
|
(this["webpackChunk_tsparticles_plugin_background_mask"] = this["webpackChunk_tsparticles_plugin_background_mask"] || []).push([["dist_browser_BackgroundMaskPlugin_js"],{
|
|
19
19
|
|
|
20
|
-
/***/ "./dist/browser/BackgroundMaskInstance.js"
|
|
21
|
-
/*!************************************************!*\
|
|
22
|
-
!*** ./dist/browser/BackgroundMaskInstance.js ***!
|
|
23
|
-
\************************************************/
|
|
24
|
-
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
25
|
-
|
|
26
|
-
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ BackgroundMaskInstance: () => (/* binding */ BackgroundMaskInstance)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nclass BackgroundMaskInstance {\n constructor(container, engine) {\n this._initCover = async () => {\n const options = this._container.actualOptions,\n cover = options.backgroundMask?.cover,\n color = cover?.color;\n if (color) {\n const coverRgb = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.rangeColorToRgb)(this._engine, color);\n if (coverRgb) {\n const coverColor = {\n ...coverRgb,\n a: cover.opacity\n };\n this._coverColorStyle = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getStyleFromRgb)(coverColor, this._container.hdr, coverColor.a);\n }\n } else {\n await new Promise((resolve, reject) => {\n if (!cover?.image) {\n return;\n }\n const img = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeDocument)().createElement(\"img\");\n img.addEventListener(\"load\", () => {\n this._coverImage = {\n image: img,\n opacity: cover.opacity\n };\n resolve();\n });\n img.addEventListener(\"error\", evt => {\n (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getLogger)().error(evt);\n reject(new Error(\"Error loading image\"));\n });\n img.src = cover.image;\n });\n }\n };\n this._container = container;\n this._engine = engine;\n }\n canvasClear() {\n const backgroundMask = this._container.actualOptions.backgroundMask;\n if (!backgroundMask?.enable) {\n return false;\n }\n return this.canvasPaint();\n }\n canvasPaint() {\n if (!this._container.actualOptions.backgroundMask?.enable) {\n return false;\n }\n const canvas = this._container.canvas;\n canvas.canvasClear();\n if (this._coverImage) {\n canvas.paintImage(this._coverImage.image, this._coverImage.opacity);\n } else {\n canvas.paintBase(this._coverColorStyle);\n }\n return true;\n }\n clearDraw(context) {\n if (!this._defaultCompositeValue) {\n return;\n }\n context.globalCompositeOperation = this._defaultCompositeValue;\n }\n draw(context) {\n const previousComposite = context.globalCompositeOperation,\n backgroundMask = this._container.actualOptions.backgroundMask;\n this._defaultCompositeValue = previousComposite;\n context.globalCompositeOperation = backgroundMask?.enable ? backgroundMask.composite : previousComposite;\n }\n async init() {\n await this._initCover();\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-background-mask/./dist/browser/BackgroundMaskInstance.js?\n}");
|
|
27
|
-
|
|
28
|
-
/***/ },
|
|
29
|
-
|
|
30
20
|
/***/ "./dist/browser/BackgroundMaskPlugin.js"
|
|
31
21
|
/*!**********************************************!*\
|
|
32
22
|
!*** ./dist/browser/BackgroundMaskPlugin.js ***!
|
|
33
23
|
\**********************************************/
|
|
34
24
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
35
25
|
|
|
36
|
-
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ BackgroundMaskPlugin: () => (/* binding */ BackgroundMaskPlugin)\n/* harmony export */ });\n/* harmony import */ var _Options_Classes_BackgroundMask_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Options/Classes/BackgroundMask.js */ \"./dist/browser/Options/Classes/BackgroundMask.js\");\n
|
|
26
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ BackgroundMaskPlugin: () => (/* binding */ BackgroundMaskPlugin)\n/* harmony export */ });\n/* harmony import */ var _Options_Classes_BackgroundMask_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Options/Classes/BackgroundMask.js */ \"./dist/browser/Options/Classes/BackgroundMask.js\");\n\nclass BackgroundMaskPlugin {\n id = \"background-mask\";\n _engine;\n constructor(engine){\n this._engine = engine;\n }\n async getPlugin(container) {\n const { BackgroundMaskPluginInstance } = await __webpack_require__.e(/*! import() */ \"dist_browser_BackgroundMaskPluginInstance_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./BackgroundMaskPluginInstance.js */ \"./dist/browser/BackgroundMaskPluginInstance.js\"));\n return new BackgroundMaskPluginInstance(container, this._engine);\n }\n loadOptions(_container, options, source) {\n if (!this.needsPlugin(options) && !this.needsPlugin(source)) {\n return;\n }\n let backgroundMaskOptions = options.backgroundMask;\n if (!backgroundMaskOptions?.load) {\n options.backgroundMask = backgroundMaskOptions = new _Options_Classes_BackgroundMask_js__WEBPACK_IMPORTED_MODULE_0__.BackgroundMask();\n }\n backgroundMaskOptions.load(source?.backgroundMask);\n }\n needsPlugin(options) {\n return !!options?.backgroundMask?.enable;\n }\n}\n\n\n//# sourceURL=webpack://@tsparticles/plugin-background-mask/./dist/browser/BackgroundMaskPlugin.js?\n}");
|
|
37
27
|
|
|
38
28
|
/***/ },
|
|
39
29
|
|
|
@@ -43,7 +33,7 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
|
|
|
43
33
|
\********************************************************/
|
|
44
34
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
45
35
|
|
|
46
|
-
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ BackgroundMask: () => (/* binding */ BackgroundMask)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _BackgroundMaskCover_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./BackgroundMaskCover.js */ \"./dist/browser/Options/Classes/BackgroundMaskCover.js\");\n\n\nclass BackgroundMask {\n
|
|
36
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ BackgroundMask: () => (/* binding */ BackgroundMask)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _BackgroundMaskCover_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./BackgroundMaskCover.js */ \"./dist/browser/Options/Classes/BackgroundMaskCover.js\");\n\n\nclass BackgroundMask {\n composite;\n cover;\n enable;\n constructor(){\n this.composite = \"destination-out\";\n this.cover = new _BackgroundMaskCover_js__WEBPACK_IMPORTED_MODULE_1__.BackgroundMaskCover();\n this.enable = false;\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n if (data.composite !== undefined) {\n this.composite = data.composite;\n }\n if (data.cover !== undefined) {\n const cover = data.cover, color = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isString)(data.cover) ? {\n color: data.cover\n } : data.cover;\n this.cover.load(cover.color !== undefined || cover.image !== undefined ? cover : {\n color: color\n });\n }\n if (data.enable !== undefined) {\n this.enable = data.enable;\n }\n }\n}\n\n\n//# sourceURL=webpack://@tsparticles/plugin-background-mask/./dist/browser/Options/Classes/BackgroundMask.js?\n}");
|
|
47
37
|
|
|
48
38
|
/***/ },
|
|
49
39
|
|
|
@@ -53,7 +43,7 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
|
|
|
53
43
|
\*************************************************************/
|
|
54
44
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
55
45
|
|
|
56
|
-
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ BackgroundMaskCover: () => (/* binding */ BackgroundMaskCover)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nclass BackgroundMaskCover {\n
|
|
46
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ BackgroundMaskCover: () => (/* binding */ BackgroundMaskCover)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nclass BackgroundMaskCover {\n color;\n image;\n opacity;\n constructor(){\n this.opacity = 1;\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n if (data.color !== undefined) {\n this.color = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.OptionsColor.create(this.color, data.color);\n }\n if (data.image !== undefined) {\n this.image = data.image;\n }\n if (data.opacity !== undefined) {\n this.opacity = data.opacity;\n }\n }\n}\n\n\n//# sourceURL=webpack://@tsparticles/plugin-background-mask/./dist/browser/Options/Classes/BackgroundMaskCover.js?\n}");
|
|
57
47
|
|
|
58
48
|
/***/ }
|
|
59
49
|
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { BackgroundMask } from "./Options/Classes/BackgroundMask.js";
|
|
2
|
-
import { BackgroundMaskInstance } from "./BackgroundMaskInstance.js";
|
|
3
2
|
export class BackgroundMaskPlugin {
|
|
3
|
+
id = "background-mask";
|
|
4
|
+
_engine;
|
|
4
5
|
constructor(engine) {
|
|
5
|
-
this.id = "background-mask";
|
|
6
6
|
this._engine = engine;
|
|
7
7
|
}
|
|
8
|
-
getPlugin(container) {
|
|
9
|
-
|
|
8
|
+
async getPlugin(container) {
|
|
9
|
+
const { BackgroundMaskPluginInstance } = await import("./BackgroundMaskPluginInstance.js");
|
|
10
|
+
return new BackgroundMaskPluginInstance(container, this._engine);
|
|
10
11
|
}
|
|
11
|
-
loadOptions(options, source) {
|
|
12
|
-
if (!this.needsPlugin()) {
|
|
12
|
+
loadOptions(_container, options, source) {
|
|
13
|
+
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
13
14
|
return;
|
|
14
15
|
}
|
|
15
16
|
let backgroundMaskOptions = options.backgroundMask;
|
|
@@ -18,7 +19,7 @@ export class BackgroundMaskPlugin {
|
|
|
18
19
|
}
|
|
19
20
|
backgroundMaskOptions.load(source?.backgroundMask);
|
|
20
21
|
}
|
|
21
|
-
needsPlugin() {
|
|
22
|
-
return
|
|
22
|
+
needsPlugin(options) {
|
|
23
|
+
return !!options?.backgroundMask?.enable;
|
|
23
24
|
}
|
|
24
25
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { getStyleFromRgb, rangeColorToRgb, safeDocument, } from "@tsparticles/engine";
|
|
2
|
+
export class BackgroundMaskPluginInstance {
|
|
3
|
+
_container;
|
|
4
|
+
_coverColorStyle;
|
|
5
|
+
_coverImage;
|
|
6
|
+
_defaultCompositeValue;
|
|
7
|
+
_engine;
|
|
8
|
+
constructor(container, engine) {
|
|
9
|
+
this._container = container;
|
|
10
|
+
this._engine = engine;
|
|
11
|
+
}
|
|
12
|
+
canvasClear() {
|
|
13
|
+
const backgroundMask = this._container.actualOptions.backgroundMask;
|
|
14
|
+
if (!backgroundMask?.enable) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return this.canvasPaint();
|
|
18
|
+
}
|
|
19
|
+
canvasPaint() {
|
|
20
|
+
if (!this._container.actualOptions.backgroundMask?.enable) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
const canvas = this._container.canvas;
|
|
24
|
+
canvas.canvasClear();
|
|
25
|
+
if (this._coverImage) {
|
|
26
|
+
canvas.paintImage(this._coverImage.image, this._coverImage.opacity);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
canvas.paintBase(this._coverColorStyle);
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
drawSettingsCleanup(context) {
|
|
34
|
+
if (!this._defaultCompositeValue) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
context.globalCompositeOperation = this._defaultCompositeValue;
|
|
38
|
+
}
|
|
39
|
+
drawSettingsSetup(context) {
|
|
40
|
+
const previousComposite = context.globalCompositeOperation, backgroundMask = this._container.actualOptions.backgroundMask;
|
|
41
|
+
this._defaultCompositeValue = previousComposite;
|
|
42
|
+
context.globalCompositeOperation = backgroundMask?.enable ? backgroundMask.composite : previousComposite;
|
|
43
|
+
}
|
|
44
|
+
async init() {
|
|
45
|
+
await this._initCover();
|
|
46
|
+
}
|
|
47
|
+
_initCover = async () => {
|
|
48
|
+
const options = this._container.actualOptions, cover = options.backgroundMask?.cover, color = cover?.color;
|
|
49
|
+
if (color) {
|
|
50
|
+
const coverRgb = rangeColorToRgb(this._engine, color);
|
|
51
|
+
if (coverRgb) {
|
|
52
|
+
const coverColor = {
|
|
53
|
+
...coverRgb,
|
|
54
|
+
a: cover.opacity,
|
|
55
|
+
};
|
|
56
|
+
this._coverColorStyle = getStyleFromRgb(coverColor, this._container.hdr, coverColor.a);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
await new Promise((resolve, reject) => {
|
|
61
|
+
if (!cover?.image) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const img = safeDocument().createElement("img");
|
|
65
|
+
img.addEventListener("load", () => {
|
|
66
|
+
this._coverImage = {
|
|
67
|
+
image: img,
|
|
68
|
+
opacity: cover.opacity,
|
|
69
|
+
};
|
|
70
|
+
resolve();
|
|
71
|
+
});
|
|
72
|
+
img.addEventListener("error", () => {
|
|
73
|
+
reject(new Error("Error loading image"));
|
|
74
|
+
});
|
|
75
|
+
img.src = cover.image;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { isNull, isString } from "@tsparticles/engine";
|
|
2
2
|
import { BackgroundMaskCover } from "./BackgroundMaskCover.js";
|
|
3
3
|
export class BackgroundMask {
|
|
4
|
+
composite;
|
|
5
|
+
cover;
|
|
6
|
+
enable;
|
|
4
7
|
constructor() {
|
|
5
8
|
this.composite = "destination-out";
|
|
6
9
|
this.cover = new BackgroundMaskCover();
|
package/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export function loadBackgroundMaskPlugin(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-alpha.
|
|
3
|
-
engine.register(async (e) => {
|
|
1
|
+
export async function loadBackgroundMaskPlugin(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.21");
|
|
3
|
+
await engine.register(async (e) => {
|
|
4
4
|
const { BackgroundMaskPlugin } = await import("./BackgroundMaskPlugin.js");
|
|
5
5
|
e.addPlugin(new BackgroundMaskPlugin(e));
|
|
6
6
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/plugin-background-mask",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.21",
|
|
4
4
|
"description": "tsParticles background mask plugin",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"./package.json": "./package.json"
|
|
87
87
|
},
|
|
88
88
|
"dependencies": {
|
|
89
|
-
"@tsparticles/engine": "4.0.0-alpha.
|
|
89
|
+
"@tsparticles/engine": "4.0.0-alpha.21"
|
|
90
90
|
},
|
|
91
91
|
"publishConfig": {
|
|
92
92
|
"access": "public"
|