@tsparticles/plugin-canvas-mask 3.9.0 → 4.0.0-alpha.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/76.min.js +2 -0
- package/76.min.js.LICENSE.txt +1 -0
- package/browser/CanvasMaskInstance.js +3 -2
- package/browser/Options/Classes/CanvasMask.js +2 -6
- package/browser/Options/Classes/CanvasMaskPixels.js +2 -2
- package/browser/index.js +6 -4
- package/browser/utils.js +37 -20
- package/cjs/CanvasMaskInstance.js +10 -13
- package/cjs/CanvasMaskPlugin.js +5 -9
- package/cjs/Options/Classes/CanvasMask.js +11 -19
- package/cjs/Options/Classes/CanvasMaskOverride.js +3 -7
- package/cjs/Options/Classes/CanvasMaskPixels.js +7 -11
- package/cjs/Options/Classes/FontTextMask.js +3 -7
- package/cjs/Options/Classes/ImageMask.js +3 -7
- package/cjs/Options/Classes/TextMask.js +7 -11
- package/cjs/Options/Classes/TextMaskLine.js +3 -7
- package/cjs/Options/Interfaces/ICanvasMask.js +1 -2
- package/cjs/Options/Interfaces/ICanvasMaskOverride.js +1 -2
- package/cjs/Options/Interfaces/ICanvasMaskPixels.js +1 -2
- package/cjs/Options/Interfaces/IFontTextMask.js +1 -2
- package/cjs/Options/Interfaces/IImageMask.js +1 -2
- package/cjs/Options/Interfaces/ITextMask.js +1 -2
- package/cjs/Options/Interfaces/ITextMaskLine.js +1 -2
- package/cjs/index.js +6 -7
- package/cjs/types.js +1 -2
- package/cjs/utils.js +43 -32
- package/dist_browser_CanvasMaskPlugin_js.js +120 -0
- package/esm/CanvasMaskInstance.js +3 -2
- package/esm/Options/Classes/CanvasMask.js +2 -6
- package/esm/Options/Classes/CanvasMaskPixels.js +2 -2
- package/esm/index.js +6 -4
- package/esm/utils.js +37 -20
- package/package.json +4 -3
- package/report.html +5 -4
- package/tsparticles.plugin.canvas-mask.js +209 -120
- package/tsparticles.plugin.canvas-mask.min.js +1 -1
- package/tsparticles.plugin.canvas-mask.min.js.LICENSE.txt +1 -1
- package/types/Options/Classes/CanvasMaskPixels.d.ts +1 -1
- package/types/Options/Classes/FontTextMask.d.ts +1 -1
- package/types/Options/Classes/TextMaskLine.d.ts +1 -1
- package/types/index.d.ts +1 -1
- package/umd/CanvasMaskInstance.js +2 -1
- package/umd/Options/Classes/CanvasMask.js +2 -6
- package/umd/Options/Classes/CanvasMaskPixels.js +2 -2
- package/umd/index.js +41 -5
- package/umd/utils.js +36 -19
package/76.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see 76.min.js.LICENSE.txt */
|
|
2
|
+
(this.webpackChunk_tsparticles_plugin_canvas_mask=this.webpackChunk_tsparticles_plugin_canvas_mask||[]).push([[76],{76(t,i,e){e.d(i,{CanvasMaskPlugin:()=>m});var s=e(303);class o{constructor(){this.color=!0,this.opacity=!1}load(t){(0,s.isNull)(t)||(void 0!==t.color&&(this.color=t.color),void 0!==t.opacity&&(this.opacity=t.opacity))}}class n{constructor(){this.filter=t=>t.a>0,this.offset=4}load(t){if(!(0,s.isNull)(t)){if(void 0!==t.filter)if((0,s.isString)(t.filter)){if(Object.hasOwn(globalThis,t.filter)){const i=globalThis[t.filter];(0,s.isFunction)(i)&&(this.filter=i)}}else this.filter=t.filter;void 0!==t.offset&&(this.offset=t.offset)}}}class a{constructor(){this.src=""}load(t){(0,s.isNull)(t)||void 0!==t.src&&(this.src=t.src)}}class l{constructor(){this.family="sans-serif",this.size=100}load(t){(0,s.isNull)(t)||(void 0!==t.family&&(this.family=t.family),void 0!==t.size&&(this.size=t.size),void 0!==t.style&&(this.style=t.style),void 0!==t.variant&&(this.variant=t.variant),void 0!==t.weight&&(this.weight=t.weight))}}class r{constructor(){this.separator="\n",this.spacing=10}load(t){(0,s.isNull)(t)||(void 0!==t.separator&&(this.separator=t.separator),void 0!==t.spacing&&(this.spacing=t.spacing))}}class c{constructor(){this.color="#000000",this.font=new l,this.lines=new r,this.text=""}load(t){(0,s.isNull)(t)||(void 0!==t.color&&(this.color=t.color),this.font.load(t.font),this.lines.load(t.lines),void 0!==t.text&&(this.text=t.text))}}class h{constructor(){this.enable=!1,this.override=new o,this.pixels=new n,this.position={x:50,y:50},this.scale=1}load(t){(0,s.isNull)(t)||(void 0!==t.element&&t.element instanceof HTMLCanvasElement&&(this.element=t.element),void 0!==t.enable&&(this.enable=t.enable),t.image&&(this.image??=new a,this.image.load(t.image)),this.pixels.load(t.pixels),t.position&&(this.position={x:t.position.x??this.position.x,y:t.position.y??this.position.y}),this.override.load(t.override),void 0!==t.scale&&(this.scale=t.scale),void 0!==t.selector&&(this.selector=t.selector),t.text&&(this.text??=new c,this.text.load(t.text)))}}const d=0,u=0;function f(t,i,e,o,n,a){const{height:l,width:r}=i,c=l*r,h=function(t){const i=1,e=0;for(let o=t.length-i;o>=e;o--){const i=Math.floor((0,s.getRandom)()*o),e=t[o],n=t[i];n!==e&&(void 0!==n&&void 0!==e&&(t[o]=n,t[i]=e))}return t}(p(c)),d=Math.min(c,t.actualOptions.particles.number.value),u=t.canvas.size;let f=0;const g=u.width*e.x/s.percentDenominator-r*o*.5,v=u.height*e.y/s.percentDenominator-l*o*.5;for(;f<d&&h.length;){const e=0,s=h.pop()??e,l={x:s%r,y:Math.floor(s/r)},c=i.pixels[l.y];if(!c)continue;const d=c[l.x];if(!d)continue;if(!a(d))continue;const u={x:l.x*o+g,y:l.y*o+v},p={};n.color&&(p.color={value:d}),n.opacity&&(p.opacity={value:d.a}),t.particles.addParticle(u,p),f++}}function g(t,i,e,s=!0){const o=t.getImageData(d,u,i.width,i.height).data;s&&t.clearRect(d,u,i.width,i.height);const n=[];for(let t=0;t<o.length;t+=e){const s=t/e,a={x:s%i.width,y:Math.floor(s/i.width)};n[a.y]??=[];const l={r:0,g:1,b:2,a:3},r=255,c=n[a.y];c&&(c[a.x]={r:o[t+l.r]??0,g:o[t+l.g]??0,b:o[t+l.b]??0,a:(o[t+l.a]??1)/r})}return{pixels:n,width:Math.min(...n.map((t=>t.length))),height:n.length}}const p=t=>[...Array(t).keys()];class v{constructor(t){this._container=t}async init(){const t=this._container,i=t.actualOptions.canvasMask;if(!i?.enable)return;let e={pixels:[],height:0,width:0};const o=i.pixels.offset;if(i.image){const t=i.image.src;if(!t)return;e=await function(t,i){const e=new Image;e.crossOrigin="Anonymous";const o=new Promise(((t,o)=>{e.onerror=o,e.onload=()=>{const n=(0,s.safeDocument)().createElement("canvas");n.width=e.width,n.height=e.height;const a=n.getContext("2d");a?(a.drawImage(e,d,u,e.width,e.height,d,u,n.width,n.height),t(g(a,n,i))):o(new Error("Could not get canvas context"))}}));return e.src=t,o}(t,o)}else if(i.text){const t=function(t,i){const e=(0,s.safeDocument)().createElement("canvas"),o=e.getContext("2d"),{font:n,text:a,lines:l,color:r}=t;if(!a||!o)return;const c=a.split(l.separator),h=(0,s.isNumber)(n.size)?`${n.size.toString()}px`:n.size,u=[];let f=0,p=0;for(const t of c){o.font=`${n.style??""} ${n.variant??""} ${n.weight?.toString()??""} ${h} ${n.family}`;const i=o.measureText(t),e={measure:i,text:t,height:i.actualBoundingBoxAscent+i.actualBoundingBoxDescent,width:i.width};f=Math.max(f||0,e.width),p+=e.height+l.spacing,u.push(e)}e.width=f,e.height=p;let v=0;for(const t of u)o.font=`${n.style??""} ${n.variant??""} ${n.weight?.toString()??""} ${h} ${n.family}`,o.fillStyle=r,o.fillText(t.text,d,v+t.measure.actualBoundingBoxAscent),v+=t.height+l.spacing;return g(o,e,i)}(i.text,o);if((0,s.isNull)(t))return;e=t}else if(i.element??i.selector){const t=i.element??(i.selector&&(0,s.safeDocument)().querySelector(i.selector));if(!t)return;const n=t.getContext("2d");if(!n)return;e=g(n,t,o)}f(t,e,i.position,i.scale,i.override,i.pixels.filter)}}class m{constructor(){this.id="canvasMask"}getPlugin(t){return Promise.resolve(new v(t))}loadOptions(t,i){if(!this.needsPlugin(t)&&!this.needsPlugin(i))return;let e=t.canvasMask;void 0===e?.load&&(t.canvasMask=e=new h),e.load(i?.canvasMask)}needsPlugin(t){return t?.canvasMask?.enable??!1}}}}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles Canvas Mask Plugin v4.0.0-alpha.0 by Matteo Bruni */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { addParticlesFromCanvasPixels, getCanvasImageData, getImageData, getTextData, } from "./utils.js";
|
|
2
|
-
import { isNull } from "@tsparticles/engine";
|
|
2
|
+
import { isNull, safeDocument } from "@tsparticles/engine";
|
|
3
3
|
export class CanvasMaskInstance {
|
|
4
4
|
constructor(container) {
|
|
5
5
|
this._container = container;
|
|
@@ -31,7 +31,8 @@ export class CanvasMaskInstance {
|
|
|
31
31
|
pixelData = data;
|
|
32
32
|
}
|
|
33
33
|
else if (options.element ?? options.selector) {
|
|
34
|
-
const canvas = options.element ??
|
|
34
|
+
const canvas = options.element ??
|
|
35
|
+
(options.selector && safeDocument().querySelector(options.selector));
|
|
35
36
|
if (!canvas) {
|
|
36
37
|
return;
|
|
37
38
|
}
|
|
@@ -25,9 +25,7 @@ export class CanvasMask {
|
|
|
25
25
|
this.enable = data.enable;
|
|
26
26
|
}
|
|
27
27
|
if (data.image) {
|
|
28
|
-
|
|
29
|
-
this.image = new ImageMask();
|
|
30
|
-
}
|
|
28
|
+
this.image ??= new ImageMask();
|
|
31
29
|
this.image.load(data.image);
|
|
32
30
|
}
|
|
33
31
|
this.pixels.load(data.pixels);
|
|
@@ -45,9 +43,7 @@ export class CanvasMask {
|
|
|
45
43
|
this.selector = data.selector;
|
|
46
44
|
}
|
|
47
45
|
if (data.text) {
|
|
48
|
-
|
|
49
|
-
this.text = new TextMask();
|
|
50
|
-
}
|
|
46
|
+
this.text ??= new TextMask();
|
|
51
47
|
this.text.load(data.text);
|
|
52
48
|
}
|
|
53
49
|
}
|
|
@@ -11,8 +11,8 @@ export class CanvasMaskPixels {
|
|
|
11
11
|
}
|
|
12
12
|
if (data.filter !== undefined) {
|
|
13
13
|
if (isString(data.filter)) {
|
|
14
|
-
if (Object.hasOwn(
|
|
15
|
-
const filter =
|
|
14
|
+
if (Object.hasOwn(globalThis, data.filter)) {
|
|
15
|
+
const filter = globalThis[data.filter];
|
|
16
16
|
if (isFunction(filter)) {
|
|
17
17
|
this.filter = filter;
|
|
18
18
|
}
|
package/browser/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
engine.
|
|
4
|
-
|
|
1
|
+
export function loadCanvasMaskPlugin(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.0");
|
|
3
|
+
engine.register(async (e) => {
|
|
4
|
+
const { CanvasMaskPlugin } = await import("./CanvasMaskPlugin.js");
|
|
5
|
+
e.addPlugin(new CanvasMaskPlugin());
|
|
6
|
+
});
|
|
5
7
|
}
|
package/browser/utils.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getRandom, isNumber, percentDenominator, safeDocument, } from "@tsparticles/engine";
|
|
2
2
|
const half = 0.5, origin = {
|
|
3
3
|
x: 0,
|
|
4
4
|
y: 0,
|
|
5
|
-
}, defaultWidth = 0;
|
|
5
|
+
}, defaultWidth = 0, defaultRgb = 0, defaultAlpha = 1;
|
|
6
6
|
export function addParticlesFromCanvasPixels(container, data, position, scale, override, filter) {
|
|
7
7
|
const { height, width } = data, numPixels = height * width, indexArray = shuffle(range(numPixels)), maxParticles = Math.min(numPixels, container.actualOptions.particles.number.value), canvasSize = container.canvas.size;
|
|
8
8
|
let selectedPixels = 0;
|
|
@@ -14,7 +14,15 @@ export function addParticlesFromCanvasPixels(container, data, position, scale, o
|
|
|
14
14
|
const defaultIndex = 0, nextIndex = indexArray.pop() ?? defaultIndex, pixelPos = {
|
|
15
15
|
x: nextIndex % width,
|
|
16
16
|
y: Math.floor(nextIndex / width),
|
|
17
|
-
},
|
|
17
|
+
}, row = data.pixels[pixelPos.y];
|
|
18
|
+
if (!row) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const pixel = row[pixelPos.x];
|
|
22
|
+
if (!pixel) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
const shouldCreateParticle = filter(pixel);
|
|
18
26
|
if (!shouldCreateParticle) {
|
|
19
27
|
continue;
|
|
20
28
|
}
|
|
@@ -47,20 +55,21 @@ export function getCanvasImageData(ctx, size, offset, clear = true) {
|
|
|
47
55
|
x: idx % size.width,
|
|
48
56
|
y: Math.floor(idx / size.width),
|
|
49
57
|
};
|
|
50
|
-
|
|
51
|
-
pixels[pos.y] = [];
|
|
52
|
-
}
|
|
58
|
+
pixels[pos.y] ??= [];
|
|
53
59
|
const indexesOffset = {
|
|
54
60
|
r: 0,
|
|
55
61
|
g: 1,
|
|
56
62
|
b: 2,
|
|
57
63
|
a: 3,
|
|
58
|
-
}, alphaFactor = 255;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
}, alphaFactor = 255, row = pixels[pos.y];
|
|
65
|
+
if (!row) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
row[pos.x] = {
|
|
69
|
+
r: imageData[i + indexesOffset.r] ?? defaultRgb,
|
|
70
|
+
g: imageData[i + indexesOffset.g] ?? defaultRgb,
|
|
71
|
+
b: imageData[i + indexesOffset.b] ?? defaultRgb,
|
|
72
|
+
a: (imageData[i + indexesOffset.a] ?? defaultAlpha) / alphaFactor,
|
|
64
73
|
};
|
|
65
74
|
}
|
|
66
75
|
return {
|
|
@@ -75,12 +84,13 @@ export function getImageData(src, offset) {
|
|
|
75
84
|
const p = new Promise((resolve, reject) => {
|
|
76
85
|
image.onerror = reject;
|
|
77
86
|
image.onload = () => {
|
|
78
|
-
const canvas =
|
|
87
|
+
const canvas = safeDocument().createElement("canvas");
|
|
79
88
|
canvas.width = image.width;
|
|
80
89
|
canvas.height = image.height;
|
|
81
90
|
const context = canvas.getContext("2d");
|
|
82
91
|
if (!context) {
|
|
83
|
-
|
|
92
|
+
reject(new Error("Could not get canvas context"));
|
|
93
|
+
return;
|
|
84
94
|
}
|
|
85
95
|
context.drawImage(image, origin.x, origin.y, image.width, image.height, origin.x, origin.y, canvas.width, canvas.height);
|
|
86
96
|
resolve(getCanvasImageData(context, canvas, offset));
|
|
@@ -90,14 +100,14 @@ export function getImageData(src, offset) {
|
|
|
90
100
|
return p;
|
|
91
101
|
}
|
|
92
102
|
export function getTextData(textOptions, offset) {
|
|
93
|
-
const canvas =
|
|
103
|
+
const canvas = safeDocument().createElement("canvas"), context = canvas.getContext("2d"), { font, text, lines: linesOptions, color } = textOptions;
|
|
94
104
|
if (!text || !context) {
|
|
95
105
|
return;
|
|
96
106
|
}
|
|
97
|
-
const lines = text.split(linesOptions.separator), fontSize = isNumber(font.size) ? `${font.size}px` : font.size, linesData = [];
|
|
107
|
+
const lines = text.split(linesOptions.separator), fontSize = isNumber(font.size) ? `${font.size.toString()}px` : font.size, linesData = [];
|
|
98
108
|
let maxWidth = 0, totalHeight = 0;
|
|
99
109
|
for (const line of lines) {
|
|
100
|
-
context.font = `${font.style ?? ""} ${font.variant ?? ""} ${font.weight ?? ""} ${fontSize} ${font.family}`;
|
|
110
|
+
context.font = `${font.style ?? ""} ${font.variant ?? ""} ${font.weight?.toString() ?? ""} ${fontSize} ${font.family}`;
|
|
101
111
|
const measure = context.measureText(line), lineData = {
|
|
102
112
|
measure,
|
|
103
113
|
text: line,
|
|
@@ -112,7 +122,7 @@ export function getTextData(textOptions, offset) {
|
|
|
112
122
|
canvas.height = totalHeight;
|
|
113
123
|
let currentHeight = 0;
|
|
114
124
|
for (const line of linesData) {
|
|
115
|
-
context.font = `${font.style ?? ""} ${font.variant ?? ""} ${font.weight ?? ""} ${fontSize} ${font.family}`;
|
|
125
|
+
context.font = `${font.style ?? ""} ${font.variant ?? ""} ${font.weight?.toString() ?? ""} ${fontSize} ${font.family}`;
|
|
116
126
|
context.fillStyle = color;
|
|
117
127
|
context.fillText(line.text, origin.x, currentHeight + line.measure.actualBoundingBoxAscent);
|
|
118
128
|
currentHeight += line.height + linesOptions.spacing;
|
|
@@ -122,8 +132,15 @@ export function getTextData(textOptions, offset) {
|
|
|
122
132
|
function shuffle(array) {
|
|
123
133
|
const lengthOffset = 1, minIndex = 0;
|
|
124
134
|
for (let currentIndex = array.length - lengthOffset; currentIndex >= minIndex; currentIndex--) {
|
|
125
|
-
const randomIndex = Math.floor(getRandom() * currentIndex);
|
|
126
|
-
|
|
135
|
+
const randomIndex = Math.floor(getRandom() * currentIndex), currentItem = array[currentIndex], randomItem = array[randomIndex];
|
|
136
|
+
if (randomItem === currentItem) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (randomItem === undefined || currentItem === undefined) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
array[currentIndex] = randomItem;
|
|
143
|
+
array[randomIndex] = currentItem;
|
|
127
144
|
}
|
|
128
145
|
return array;
|
|
129
146
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const utils_js_1 = require("./utils.js");
|
|
5
|
-
const engine_1 = require("@tsparticles/engine");
|
|
6
|
-
class CanvasMaskInstance {
|
|
1
|
+
import { addParticlesFromCanvasPixels, getCanvasImageData, getImageData, getTextData, } from "./utils.js";
|
|
2
|
+
import { isNull, safeDocument } from "@tsparticles/engine";
|
|
3
|
+
export class CanvasMaskInstance {
|
|
7
4
|
constructor(container) {
|
|
8
5
|
this._container = container;
|
|
9
6
|
}
|
|
@@ -23,18 +20,19 @@ class CanvasMaskInstance {
|
|
|
23
20
|
if (!url) {
|
|
24
21
|
return;
|
|
25
22
|
}
|
|
26
|
-
pixelData = await
|
|
23
|
+
pixelData = await getImageData(url, offset);
|
|
27
24
|
}
|
|
28
25
|
else if (options.text) {
|
|
29
26
|
const textOptions = options.text;
|
|
30
|
-
const data =
|
|
31
|
-
if (
|
|
27
|
+
const data = getTextData(textOptions, offset);
|
|
28
|
+
if (isNull(data)) {
|
|
32
29
|
return;
|
|
33
30
|
}
|
|
34
31
|
pixelData = data;
|
|
35
32
|
}
|
|
36
33
|
else if (options.element ?? options.selector) {
|
|
37
|
-
const canvas = options.element ??
|
|
34
|
+
const canvas = options.element ??
|
|
35
|
+
(options.selector && safeDocument().querySelector(options.selector));
|
|
38
36
|
if (!canvas) {
|
|
39
37
|
return;
|
|
40
38
|
}
|
|
@@ -42,9 +40,8 @@ class CanvasMaskInstance {
|
|
|
42
40
|
if (!context) {
|
|
43
41
|
return;
|
|
44
42
|
}
|
|
45
|
-
pixelData =
|
|
43
|
+
pixelData = getCanvasImageData(context, canvas, offset);
|
|
46
44
|
}
|
|
47
|
-
|
|
45
|
+
addParticlesFromCanvasPixels(container, pixelData, options.position, options.scale, options.override, options.pixels.filter);
|
|
48
46
|
}
|
|
49
47
|
}
|
|
50
|
-
exports.CanvasMaskInstance = CanvasMaskInstance;
|
package/cjs/CanvasMaskPlugin.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const CanvasMask_js_1 = require("./Options/Classes/CanvasMask.js");
|
|
5
|
-
const CanvasMaskInstance_js_1 = require("./CanvasMaskInstance.js");
|
|
6
|
-
class CanvasMaskPlugin {
|
|
1
|
+
import { CanvasMask } from "./Options/Classes/CanvasMask.js";
|
|
2
|
+
import { CanvasMaskInstance } from "./CanvasMaskInstance.js";
|
|
3
|
+
export class CanvasMaskPlugin {
|
|
7
4
|
constructor() {
|
|
8
5
|
this.id = "canvasMask";
|
|
9
6
|
}
|
|
10
7
|
getPlugin(container) {
|
|
11
|
-
return Promise.resolve(new
|
|
8
|
+
return Promise.resolve(new CanvasMaskInstance(container));
|
|
12
9
|
}
|
|
13
10
|
loadOptions(options, source) {
|
|
14
11
|
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
@@ -16,7 +13,7 @@ class CanvasMaskPlugin {
|
|
|
16
13
|
}
|
|
17
14
|
let canvasMaskOptions = options.canvasMask;
|
|
18
15
|
if (canvasMaskOptions?.load === undefined) {
|
|
19
|
-
options.canvasMask = canvasMaskOptions = new
|
|
16
|
+
options.canvasMask = canvasMaskOptions = new CanvasMask();
|
|
20
17
|
}
|
|
21
18
|
canvasMaskOptions.load(source?.canvasMask);
|
|
22
19
|
}
|
|
@@ -24,4 +21,3 @@ class CanvasMaskPlugin {
|
|
|
24
21
|
return options?.canvasMask?.enable ?? false;
|
|
25
22
|
}
|
|
26
23
|
}
|
|
27
|
-
exports.CanvasMaskPlugin = CanvasMaskPlugin;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const ImageMask_js_1 = require("./ImageMask.js");
|
|
8
|
-
const TextMask_js_1 = require("./TextMask.js");
|
|
9
|
-
class CanvasMask {
|
|
1
|
+
import { isNull } from "@tsparticles/engine";
|
|
2
|
+
import { CanvasMaskOverride } from "./CanvasMaskOverride.js";
|
|
3
|
+
import { CanvasMaskPixels } from "./CanvasMaskPixels.js";
|
|
4
|
+
import { ImageMask } from "./ImageMask.js";
|
|
5
|
+
import { TextMask } from "./TextMask.js";
|
|
6
|
+
export class CanvasMask {
|
|
10
7
|
constructor() {
|
|
11
8
|
this.enable = false;
|
|
12
|
-
this.override = new
|
|
13
|
-
this.pixels = new
|
|
9
|
+
this.override = new CanvasMaskOverride();
|
|
10
|
+
this.pixels = new CanvasMaskPixels();
|
|
14
11
|
this.position = {
|
|
15
12
|
x: 50,
|
|
16
13
|
y: 50,
|
|
@@ -18,7 +15,7 @@ class CanvasMask {
|
|
|
18
15
|
this.scale = 1;
|
|
19
16
|
}
|
|
20
17
|
load(data) {
|
|
21
|
-
if (
|
|
18
|
+
if (isNull(data)) {
|
|
22
19
|
return;
|
|
23
20
|
}
|
|
24
21
|
if (data.element !== undefined && data.element instanceof HTMLCanvasElement) {
|
|
@@ -28,9 +25,7 @@ class CanvasMask {
|
|
|
28
25
|
this.enable = data.enable;
|
|
29
26
|
}
|
|
30
27
|
if (data.image) {
|
|
31
|
-
|
|
32
|
-
this.image = new ImageMask_js_1.ImageMask();
|
|
33
|
-
}
|
|
28
|
+
this.image ??= new ImageMask();
|
|
34
29
|
this.image.load(data.image);
|
|
35
30
|
}
|
|
36
31
|
this.pixels.load(data.pixels);
|
|
@@ -48,11 +43,8 @@ class CanvasMask {
|
|
|
48
43
|
this.selector = data.selector;
|
|
49
44
|
}
|
|
50
45
|
if (data.text) {
|
|
51
|
-
|
|
52
|
-
this.text = new TextMask_js_1.TextMask();
|
|
53
|
-
}
|
|
46
|
+
this.text ??= new TextMask();
|
|
54
47
|
this.text.load(data.text);
|
|
55
48
|
}
|
|
56
49
|
}
|
|
57
50
|
}
|
|
58
|
-
exports.CanvasMask = CanvasMask;
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.CanvasMaskOverride = void 0;
|
|
4
|
-
const engine_1 = require("@tsparticles/engine");
|
|
5
|
-
class CanvasMaskOverride {
|
|
1
|
+
import { isNull } from "@tsparticles/engine";
|
|
2
|
+
export class CanvasMaskOverride {
|
|
6
3
|
constructor() {
|
|
7
4
|
this.color = true;
|
|
8
5
|
this.opacity = false;
|
|
9
6
|
}
|
|
10
7
|
load(data) {
|
|
11
|
-
if (
|
|
8
|
+
if (isNull(data)) {
|
|
12
9
|
return;
|
|
13
10
|
}
|
|
14
11
|
if (data.color !== undefined) {
|
|
@@ -19,4 +16,3 @@ class CanvasMaskOverride {
|
|
|
19
16
|
}
|
|
20
17
|
}
|
|
21
18
|
}
|
|
22
|
-
exports.CanvasMaskOverride = CanvasMaskOverride;
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CanvasMaskPixels = void 0;
|
|
4
|
-
const engine_1 = require("@tsparticles/engine");
|
|
1
|
+
import { isFunction, isNull, isString, } from "@tsparticles/engine";
|
|
5
2
|
const minAlpha = 0;
|
|
6
|
-
class CanvasMaskPixels {
|
|
3
|
+
export class CanvasMaskPixels {
|
|
7
4
|
constructor() {
|
|
8
5
|
this.filter = (pixel) => pixel.a > minAlpha;
|
|
9
6
|
this.offset = 4;
|
|
10
7
|
}
|
|
11
8
|
load(data) {
|
|
12
|
-
if (
|
|
9
|
+
if (isNull(data)) {
|
|
13
10
|
return;
|
|
14
11
|
}
|
|
15
12
|
if (data.filter !== undefined) {
|
|
16
|
-
if (
|
|
17
|
-
if (Object.hasOwn(
|
|
18
|
-
const filter =
|
|
19
|
-
if (
|
|
13
|
+
if (isString(data.filter)) {
|
|
14
|
+
if (Object.hasOwn(globalThis, data.filter)) {
|
|
15
|
+
const filter = globalThis[data.filter];
|
|
16
|
+
if (isFunction(filter)) {
|
|
20
17
|
this.filter = filter;
|
|
21
18
|
}
|
|
22
19
|
}
|
|
@@ -30,4 +27,3 @@ class CanvasMaskPixels {
|
|
|
30
27
|
}
|
|
31
28
|
}
|
|
32
29
|
}
|
|
33
|
-
exports.CanvasMaskPixels = CanvasMaskPixels;
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.FontTextMask = void 0;
|
|
4
|
-
const engine_1 = require("@tsparticles/engine");
|
|
5
|
-
class FontTextMask {
|
|
1
|
+
import { isNull } from "@tsparticles/engine";
|
|
2
|
+
export class FontTextMask {
|
|
6
3
|
constructor() {
|
|
7
4
|
this.family = "sans-serif";
|
|
8
5
|
this.size = 100;
|
|
9
6
|
}
|
|
10
7
|
load(data) {
|
|
11
|
-
if (
|
|
8
|
+
if (isNull(data)) {
|
|
12
9
|
return;
|
|
13
10
|
}
|
|
14
11
|
if (data.family !== undefined) {
|
|
@@ -28,4 +25,3 @@ class FontTextMask {
|
|
|
28
25
|
}
|
|
29
26
|
}
|
|
30
27
|
}
|
|
31
|
-
exports.FontTextMask = FontTextMask;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ImageMask = void 0;
|
|
4
|
-
const engine_1 = require("@tsparticles/engine");
|
|
5
|
-
class ImageMask {
|
|
1
|
+
import { isNull } from "@tsparticles/engine";
|
|
2
|
+
export class ImageMask {
|
|
6
3
|
constructor() {
|
|
7
4
|
this.src = "";
|
|
8
5
|
}
|
|
9
6
|
load(data) {
|
|
10
|
-
if (
|
|
7
|
+
if (isNull(data)) {
|
|
11
8
|
return;
|
|
12
9
|
}
|
|
13
10
|
if (data.src !== undefined) {
|
|
@@ -15,4 +12,3 @@ class ImageMask {
|
|
|
15
12
|
}
|
|
16
13
|
}
|
|
17
14
|
}
|
|
18
|
-
exports.ImageMask = ImageMask;
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const FontTextMask_js_1 = require("./FontTextMask.js");
|
|
6
|
-
const TextMaskLine_js_1 = require("./TextMaskLine.js");
|
|
7
|
-
class TextMask {
|
|
1
|
+
import { isNull } from "@tsparticles/engine";
|
|
2
|
+
import { FontTextMask } from "./FontTextMask.js";
|
|
3
|
+
import { TextMaskLine } from "./TextMaskLine.js";
|
|
4
|
+
export class TextMask {
|
|
8
5
|
constructor() {
|
|
9
6
|
this.color = "#000000";
|
|
10
|
-
this.font = new
|
|
11
|
-
this.lines = new
|
|
7
|
+
this.font = new FontTextMask();
|
|
8
|
+
this.lines = new TextMaskLine();
|
|
12
9
|
this.text = "";
|
|
13
10
|
}
|
|
14
11
|
load(data) {
|
|
15
|
-
if (
|
|
12
|
+
if (isNull(data)) {
|
|
16
13
|
return;
|
|
17
14
|
}
|
|
18
15
|
if (data.color !== undefined) {
|
|
@@ -25,4 +22,3 @@ class TextMask {
|
|
|
25
22
|
}
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
|
-
exports.TextMask = TextMask;
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.TextMaskLine = void 0;
|
|
4
|
-
const engine_1 = require("@tsparticles/engine");
|
|
5
|
-
class TextMaskLine {
|
|
1
|
+
import { isNull } from "@tsparticles/engine";
|
|
2
|
+
export class TextMaskLine {
|
|
6
3
|
constructor() {
|
|
7
4
|
this.separator = "\n";
|
|
8
5
|
this.spacing = 10;
|
|
9
6
|
}
|
|
10
7
|
load(data) {
|
|
11
|
-
if (
|
|
8
|
+
if (isNull(data)) {
|
|
12
9
|
return;
|
|
13
10
|
}
|
|
14
11
|
if (data.separator !== undefined) {
|
|
@@ -19,4 +16,3 @@ class TextMaskLine {
|
|
|
19
16
|
}
|
|
20
17
|
}
|
|
21
18
|
}
|
|
22
|
-
exports.TextMaskLine = TextMaskLine;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/cjs/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
await engine.addPlugin(new CanvasMaskPlugin_js_1.CanvasMaskPlugin(), refresh);
|
|
1
|
+
export function loadCanvasMaskPlugin(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.0");
|
|
3
|
+
engine.register(async (e) => {
|
|
4
|
+
const { CanvasMaskPlugin } = await import("./CanvasMaskPlugin.js");
|
|
5
|
+
e.addPlugin(new CanvasMaskPlugin());
|
|
6
|
+
});
|
|
8
7
|
}
|
package/cjs/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|