@tsparticles/plugin-canvas-mask 3.0.0-alpha.1 → 3.0.0-beta.1
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/README.md +15 -11
- package/browser/CanvasMaskInstance.js +2 -2
- package/browser/Options/Classes/CanvasMask.js +6 -7
- package/browser/Options/Classes/CanvasMaskPixels.js +3 -2
- package/browser/Options/Classes/TextMask.js +2 -2
- package/browser/index.js +8 -10
- package/browser/package.json +1 -0
- package/browser/utils.js +20 -20
- package/cjs/CanvasMaskInstance.js +34 -45
- package/cjs/Options/Classes/CanvasMask.js +10 -11
- package/cjs/Options/Classes/CanvasMaskPixels.js +3 -2
- package/cjs/Options/Classes/TextMask.js +4 -4
- package/cjs/index.js +10 -23
- package/cjs/package.json +1 -0
- package/cjs/utils.js +19 -19
- package/esm/CanvasMaskInstance.js +2 -2
- package/esm/Options/Classes/CanvasMask.js +6 -7
- package/esm/Options/Classes/CanvasMaskPixels.js +3 -2
- package/esm/Options/Classes/TextMask.js +2 -2
- package/esm/index.js +8 -10
- package/esm/package.json +1 -0
- package/esm/utils.js +20 -20
- package/package.json +19 -6
- package/report.html +4 -4
- package/tsparticles.plugin.canvas-mask.js +34 -35
- package/tsparticles.plugin.canvas-mask.min.js +1 -1
- package/tsparticles.plugin.canvas-mask.min.js.LICENSE.txt +1 -8
- package/types/CanvasMaskInstance.d.ts +1 -1
- package/types/Options/Classes/CanvasMask.d.ts +5 -5
- package/types/Options/Classes/CanvasMaskOverride.d.ts +1 -1
- package/types/Options/Classes/CanvasMaskPixels.d.ts +1 -1
- package/types/Options/Classes/FontTextMask.d.ts +1 -1
- package/types/Options/Classes/ImageMask.d.ts +1 -1
- package/types/Options/Classes/TextMask.d.ts +3 -3
- package/types/Options/Classes/TextMaskLine.d.ts +1 -1
- package/types/Options/Interfaces/ICanvasMask.d.ts +4 -4
- package/types/Options/Interfaces/ITextMask.d.ts +2 -2
- package/types/index.d.ts +1 -1
- package/types/types.d.ts +2 -2
- package/types/utils.d.ts +3 -3
- package/umd/CanvasMaskInstance.js +7 -7
- package/umd/Options/Classes/CanvasMask.js +11 -12
- package/umd/Options/Classes/CanvasMaskPixels.js +4 -3
- package/umd/Options/Classes/TextMask.js +5 -5
- package/umd/index.js +11 -13
- package/umd/utils.js +19 -19
|
@@ -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
|
-
* v3.0.0-
|
|
7
|
+
* v3.0.0-beta.1
|
|
8
8
|
*/
|
|
9
9
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
10
10
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
@@ -91,7 +91,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
91
91
|
|
|
92
92
|
// EXPORTS
|
|
93
93
|
__webpack_require__.d(__webpack_exports__, {
|
|
94
|
-
|
|
94
|
+
loadCanvasMaskPlugin: () => (/* binding */ loadCanvasMaskPlugin)
|
|
95
95
|
});
|
|
96
96
|
|
|
97
97
|
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/CanvasMaskOverride.js
|
|
@@ -112,7 +112,10 @@ class CanvasMaskOverride {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
|
+
// EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
|
|
116
|
+
var engine_root_window_ = __webpack_require__(533);
|
|
115
117
|
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/CanvasMaskPixels.js
|
|
118
|
+
|
|
116
119
|
class CanvasMaskPixels {
|
|
117
120
|
constructor() {
|
|
118
121
|
this.filter = pixel => pixel.a > 0;
|
|
@@ -123,10 +126,10 @@ class CanvasMaskPixels {
|
|
|
123
126
|
return;
|
|
124
127
|
}
|
|
125
128
|
if (data.filter !== undefined) {
|
|
126
|
-
if (
|
|
129
|
+
if ((0,engine_root_window_.isString)(data.filter)) {
|
|
127
130
|
if (Object.hasOwn(window, data.filter)) {
|
|
128
131
|
const filter = window[data.filter];
|
|
129
|
-
if (
|
|
132
|
+
if ((0,engine_root_window_.isFunction)(filter)) {
|
|
130
133
|
this.filter = filter;
|
|
131
134
|
}
|
|
132
135
|
}
|
|
@@ -239,7 +242,6 @@ class CanvasMask {
|
|
|
239
242
|
this.scale = 1;
|
|
240
243
|
}
|
|
241
244
|
load(data) {
|
|
242
|
-
var _a, _b;
|
|
243
245
|
if (!data) {
|
|
244
246
|
return;
|
|
245
247
|
}
|
|
@@ -258,8 +260,8 @@ class CanvasMask {
|
|
|
258
260
|
this.pixels.load(data.pixels);
|
|
259
261
|
if (data.position) {
|
|
260
262
|
this.position = {
|
|
261
|
-
x:
|
|
262
|
-
y:
|
|
263
|
+
x: data.position.x ?? this.position.x,
|
|
264
|
+
y: data.position.y ?? this.position.y
|
|
263
265
|
};
|
|
264
266
|
}
|
|
265
267
|
this.override.load(data.override);
|
|
@@ -277,8 +279,6 @@ class CanvasMask {
|
|
|
277
279
|
}
|
|
278
280
|
}
|
|
279
281
|
}
|
|
280
|
-
// EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
|
|
281
|
-
var engine_root_window_ = __webpack_require__(533);
|
|
282
282
|
;// CONCATENATED MODULE: ./dist/browser/utils.js
|
|
283
283
|
|
|
284
284
|
function shuffle(array) {
|
|
@@ -310,25 +310,26 @@ function addParticlesFromCanvasPixels(container, data, position, scale, override
|
|
|
310
310
|
},
|
|
311
311
|
pixel = data.pixels[pixelPos.y][pixelPos.x],
|
|
312
312
|
shouldCreateParticle = filter(pixel);
|
|
313
|
-
if (shouldCreateParticle) {
|
|
314
|
-
|
|
313
|
+
if (!shouldCreateParticle) {
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
const pos = {
|
|
315
317
|
x: pixelPos.x * scale + positionOffset.x,
|
|
316
318
|
y: pixelPos.y * scale + positionOffset.y
|
|
319
|
+
},
|
|
320
|
+
pOptions = {};
|
|
321
|
+
if (override.color) {
|
|
322
|
+
pOptions.color = {
|
|
323
|
+
value: pixel
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
if (override.opacity) {
|
|
327
|
+
pOptions.opacity = {
|
|
328
|
+
value: pixel.a
|
|
317
329
|
};
|
|
318
|
-
const pOptions = {};
|
|
319
|
-
if (override.color) {
|
|
320
|
-
pOptions.color = {
|
|
321
|
-
value: pixel
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
if (override.opacity) {
|
|
325
|
-
pOptions.opacity = {
|
|
326
|
-
value: pixel.a
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
container.particles.addParticle(pos, pOptions);
|
|
330
|
-
selectedPixels++;
|
|
331
330
|
}
|
|
331
|
+
container.particles.addParticle(pos, pOptions);
|
|
332
|
+
selectedPixels++;
|
|
332
333
|
}
|
|
333
334
|
}
|
|
334
335
|
function getCanvasImageData(ctx, size, offset, clear = true) {
|
|
@@ -370,7 +371,7 @@ function getImageData(src, offset) {
|
|
|
370
371
|
canvas.height = image.height;
|
|
371
372
|
const context = canvas.getContext("2d");
|
|
372
373
|
if (!context) {
|
|
373
|
-
return reject(new Error(
|
|
374
|
+
return reject(new Error(`${engine_root_window_.errorPrefix} Could not get canvas context`));
|
|
374
375
|
}
|
|
375
376
|
context.drawImage(image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height);
|
|
376
377
|
resolve(getCanvasImageData(context, canvas, offset));
|
|
@@ -392,7 +393,7 @@ function getTextData(textOptions, offset) {
|
|
|
392
393
|
return;
|
|
393
394
|
}
|
|
394
395
|
const lines = text.split(linesOptions.separator),
|
|
395
|
-
fontSize =
|
|
396
|
+
fontSize = (0,engine_root_window_.isNumber)(font.size) ? `${font.size}px` : font.size,
|
|
396
397
|
linesData = [];
|
|
397
398
|
let maxWidth = 0,
|
|
398
399
|
totalHeight = 0;
|
|
@@ -431,7 +432,7 @@ class CanvasMaskInstance {
|
|
|
431
432
|
async init() {
|
|
432
433
|
const container = this._container,
|
|
433
434
|
options = container.actualOptions.canvasMask;
|
|
434
|
-
if (!
|
|
435
|
+
if (!options?.enable) {
|
|
435
436
|
return;
|
|
436
437
|
}
|
|
437
438
|
let pixelData = {
|
|
@@ -479,23 +480,21 @@ class CanvasMaskPlugin {
|
|
|
479
480
|
return new CanvasMaskInstance(container, this._engine);
|
|
480
481
|
}
|
|
481
482
|
loadOptions(options, source) {
|
|
482
|
-
if (!this.needsPlugin(source)) {
|
|
483
|
+
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
483
484
|
return;
|
|
484
485
|
}
|
|
485
486
|
let canvasMaskOptions = options.canvasMask;
|
|
486
|
-
if (
|
|
487
|
+
if (canvasMaskOptions?.load === undefined) {
|
|
487
488
|
options.canvasMask = canvasMaskOptions = new CanvasMask();
|
|
488
489
|
}
|
|
489
|
-
canvasMaskOptions.load(source
|
|
490
|
+
canvasMaskOptions.load(source?.canvasMask);
|
|
490
491
|
}
|
|
491
492
|
needsPlugin(options) {
|
|
492
|
-
|
|
493
|
-
return (_b = (_a = options === null || options === void 0 ? void 0 : options.canvasMask) === null || _a === void 0 ? void 0 : _a.enable) !== null && _b !== void 0 ? _b : false;
|
|
493
|
+
return options?.canvasMask?.enable ?? false;
|
|
494
494
|
}
|
|
495
495
|
}
|
|
496
|
-
async function loadCanvasMaskPlugin(engine) {
|
|
497
|
-
|
|
498
|
-
await engine.addPlugin(plugin);
|
|
496
|
+
async function loadCanvasMaskPlugin(engine, refresh = true) {
|
|
497
|
+
await engine.addPlugin(new CanvasMaskPlugin(engine), refresh);
|
|
499
498
|
}
|
|
500
499
|
})();
|
|
501
500
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! For license information please see tsparticles.plugin.canvas-mask.min.js.LICENSE.txt */
|
|
2
|
-
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],e);else{var i="object"==typeof exports?e(require("@tsparticles/engine")):e(t.window);for(var
|
|
2
|
+
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],e);else{var i="object"==typeof exports?e(require("@tsparticles/engine")):e(t.window);for(var s in i)("object"==typeof exports?exports:t)[s]=i[s]}}(this,(t=>(()=>{"use strict";var e={533:e=>{e.exports=t}},i={};function s(t){var o=i[t];if(void 0!==o)return o.exports;var n=i[t]={exports:{}};return e[t](n,n.exports,s),n.exports}s.d=(t,e)=>{for(var i in e)s.o(e,i)&&!s.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},s.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),s.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};return(()=>{s.r(o),s.d(o,{loadCanvasMaskPlugin:()=>p});class t{constructor(){this.color=!0,this.opacity=!1}load(t){t&&(void 0!==t.color&&(this.color=t.color),void 0!==t.opacity&&(this.opacity=t.opacity))}}var e=s(533);class i{constructor(){this.filter=t=>t.a>0,this.offset=4}load(t){if(t){if(void 0!==t.filter)if((0,e.isString)(t.filter)){if(Object.hasOwn(window,t.filter)){const i=window[t.filter];(0,e.isFunction)(i)&&(this.filter=i)}}else this.filter=t.filter;void 0!==t.offset&&(this.offset=t.offset)}}}class n{constructor(){this.src=""}load(t){t&&void 0!==t.src&&(this.src=t.src)}}class r{constructor(){this.family="sans-serif",this.size=100}load(t){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 a{constructor(){this.separator="\n",this.spacing=10}load(t){t&&(void 0!==t.separator&&(this.separator=t.separator),void 0!==t.spacing&&(this.spacing=t.spacing))}}class l{constructor(){this.color="#000000",this.font=new r,this.lines=new a,this.text=""}load(t){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 c{constructor(){this.enable=!1,this.override=new t,this.pixels=new i,this.position={x:50,y:50},this.scale=1}load(t){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||(this.image=new n),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||(this.text=new l),this.text.load(t.text)))}}function h(t,i,s,o,n,r){const{height:a,width:l}=i,c=a*l,h=function(t){for(let i=t.length-1;i>=0;i--){const s=Math.floor((0,e.getRandom)()*i);[t[i],t[s]]=[t[s],t[i]]}return t}(f(c)),d=Math.min(c,t.actualOptions.particles.number.value),u=t.canvas.size;let g=0;const p=u.width*s.x/100-l*o/2,x=u.height*s.y/100-a*o/2;for(;g<d&&h.length;){const e=h.pop()||0,s={x:e%l,y:Math.floor(e/l)},a=i.pixels[s.y][s.x];if(!r(a))continue;const c={x:s.x*o+p,y:s.y*o+x},d={};n.color&&(d.color={value:a}),n.opacity&&(d.opacity={value:a.a}),t.particles.addParticle(c,d),g++}}function d(t,e,i,s=!0){const o=t.getImageData(0,0,e.width,e.height).data;s&&t.clearRect(0,0,e.width,e.height);const n=[];for(let t=0;t<o.length;t+=i){const s=t/i,r={x:s%e.width,y:Math.floor(s/e.width)};n[r.y]||(n[r.y]=[]),n[r.y][r.x]={r:o[t],g:o[t+1],b:o[t+2],a:o[t+3]/255}}return{pixels:n,width:Math.min(...n.map((t=>t.length))),height:n.length}}const f=t=>[...Array(t).keys()];class u{constructor(t,e){this._container=t,this._engine=e}async init(){const t=this._container,i=t.actualOptions.canvasMask;if(!i?.enable)return;let s={pixels:[],height:0,width:0};const o=i.pixels.offset;if(i.image){const t=i.image.src;if(!t)return;s=await function(t,i){const s=new Image;s.crossOrigin="Anonymous";const o=new Promise(((t,o)=>{s.onerror=o,s.onload=()=>{const n=document.createElement("canvas");n.width=s.width,n.height=s.height;const r=n.getContext("2d");if(!r)return o(new Error(`${e.errorPrefix} Could not get canvas context`));r.drawImage(s,0,0,s.width,s.height,0,0,n.width,n.height),t(d(r,n,i))}}));return s.src=t,o}(t,o)}else if(i.text){const t=function(t,i){const s=document.createElement("canvas"),o=s.getContext("2d"),{font:n,text:r,lines:a,color:l}=t;if(!r||!o)return;const c=r.split(a.separator),h=(0,e.isNumber)(n.size)?`${n.size}px`:n.size,f=[];let u=0,g=0;for(const t of c){o.font=`${n.style||""} ${n.variant||""} ${n.weight||""} ${h} ${n.family}`;const e=o.measureText(t),i={measure:e,text:t,height:e.actualBoundingBoxAscent+e.actualBoundingBoxDescent,width:e.width};u=Math.max(u||0,i.width),g+=i.height+a.spacing,f.push(i)}s.width=u,s.height=g;let p=0;for(const t of f)o.font=`${n.style||""} ${n.variant||""} ${n.weight||""} ${h} ${n.family}`,o.fillStyle=l,o.fillText(t.text,0,p+t.measure.actualBoundingBoxAscent),p+=t.height+a.spacing;return d(o,s,i)}(i.text,o);if(!t)return;s=t}else if(i.element||i.selector){const t=i.element||i.selector&&document.querySelector(i.selector);if(!t)return;const e=t.getContext("2d");if(!e)return;s=d(e,t,o)}h(t,s,i.position,i.scale,i.override,i.pixels.filter)}}class g{constructor(t){this.id="canvasMask",this._engine=t}getPlugin(t){return new u(t,this._engine)}loadOptions(t,e){if(!this.needsPlugin(t)&&!this.needsPlugin(e))return;let i=t.canvasMask;void 0===i?.load&&(t.canvasMask=i=new c),i.load(e?.canvasMask)}needsPlugin(t){return t?.canvasMask?.enable??!1}}async function p(t,e=!0){await t.addPlugin(new g(t),e)}})(),o})()));
|
|
@@ -1,8 +1 @@
|
|
|
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-alpha.1
|
|
8
|
-
*/
|
|
1
|
+
/*! tsParticles Canvas Mask Plugin v3.0.0-beta.1 by Matteo Bruni */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Engine, IContainerPlugin } from "@tsparticles/engine";
|
|
2
|
-
import type { CanvasMaskContainer } from "./types";
|
|
2
|
+
import type { CanvasMaskContainer } from "./types.js";
|
|
3
3
|
export declare class CanvasMaskInstance implements IContainerPlugin {
|
|
4
4
|
private readonly _container;
|
|
5
5
|
private readonly _engine;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ICoordinates, IOptionLoader, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
-
import { CanvasMaskOverride } from "./CanvasMaskOverride";
|
|
3
|
-
import { CanvasMaskPixels } from "./CanvasMaskPixels";
|
|
4
|
-
import type { ICanvasMask } from "../Interfaces/ICanvasMask";
|
|
5
|
-
import { ImageMask } from "./ImageMask";
|
|
6
|
-
import { TextMask } from "./TextMask";
|
|
2
|
+
import { CanvasMaskOverride } from "./CanvasMaskOverride.js";
|
|
3
|
+
import { CanvasMaskPixels } from "./CanvasMaskPixels.js";
|
|
4
|
+
import type { ICanvasMask } from "../Interfaces/ICanvasMask.js";
|
|
5
|
+
import { ImageMask } from "./ImageMask.js";
|
|
6
|
+
import { TextMask } from "./TextMask.js";
|
|
7
7
|
export declare class CanvasMask implements ICanvasMask, IOptionLoader<ICanvasMask> {
|
|
8
8
|
element?: HTMLCanvasElement;
|
|
9
9
|
enable: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
-
import type { ICanvasMaskOverride } from "../Interfaces/ICanvasMaskOverride";
|
|
2
|
+
import type { ICanvasMaskOverride } from "../Interfaces/ICanvasMaskOverride.js";
|
|
3
3
|
export declare class CanvasMaskOverride implements ICanvasMaskOverride, IOptionLoader<ICanvasMaskOverride> {
|
|
4
4
|
color: boolean;
|
|
5
5
|
opacity: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IOptionLoader, IRgba, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
-
import type { ICanvasMaskPixels } from "../Interfaces/ICanvasMaskPixels";
|
|
2
|
+
import type { ICanvasMaskPixels } from "../Interfaces/ICanvasMaskPixels.js";
|
|
3
3
|
export declare class CanvasMaskPixels implements ICanvasMaskPixels, IOptionLoader<ICanvasMaskPixels> {
|
|
4
4
|
filter: (pixel: IRgba) => boolean;
|
|
5
5
|
offset: number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
-
import type { IFontTextMask } from "../Interfaces/IFontTextMask";
|
|
2
|
+
import type { IFontTextMask } from "../Interfaces/IFontTextMask.js";
|
|
3
3
|
export declare class FontTextMask implements IFontTextMask, IOptionLoader<IFontTextMask> {
|
|
4
4
|
family: string;
|
|
5
5
|
size: string | number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
-
import type { IImageMask } from "../Interfaces/IImageMask";
|
|
2
|
+
import type { IImageMask } from "../Interfaces/IImageMask.js";
|
|
3
3
|
export declare class ImageMask implements IImageMask, IOptionLoader<IImageMask> {
|
|
4
4
|
src: string;
|
|
5
5
|
constructor();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
-
import { FontTextMask } from "./FontTextMask";
|
|
3
|
-
import type { ITextMask } from "../Interfaces/ITextMask";
|
|
4
|
-
import { TextMaskLine } from "./TextMaskLine";
|
|
2
|
+
import { FontTextMask } from "./FontTextMask.js";
|
|
3
|
+
import type { ITextMask } from "../Interfaces/ITextMask.js";
|
|
4
|
+
import { TextMaskLine } from "./TextMaskLine.js";
|
|
5
5
|
export declare class TextMask implements ITextMask, IOptionLoader<ITextMask> {
|
|
6
6
|
color: string;
|
|
7
7
|
font: FontTextMask;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
-
import type { ITextMaskLine } from "../Interfaces/ITextMaskLine";
|
|
2
|
+
import type { ITextMaskLine } from "../Interfaces/ITextMaskLine.js";
|
|
3
3
|
export declare class TextMaskLine implements ITextMaskLine, IOptionLoader<ITextMaskLine> {
|
|
4
4
|
separator: string;
|
|
5
5
|
spacing: number;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { ICanvasMaskOverride } from "./ICanvasMaskOverride";
|
|
2
|
-
import type { ICanvasMaskPixels } from "./ICanvasMaskPixels";
|
|
1
|
+
import type { ICanvasMaskOverride } from "./ICanvasMaskOverride.js";
|
|
2
|
+
import type { ICanvasMaskPixels } from "./ICanvasMaskPixels.js";
|
|
3
3
|
import type { ICoordinates } from "@tsparticles/engine";
|
|
4
|
-
import type { IImageMask } from "./IImageMask";
|
|
5
|
-
import type { ITextMask } from "./ITextMask";
|
|
4
|
+
import type { IImageMask } from "./IImageMask.js";
|
|
5
|
+
import type { ITextMask } from "./ITextMask.js";
|
|
6
6
|
export interface ICanvasMask {
|
|
7
7
|
element?: HTMLCanvasElement;
|
|
8
8
|
enable: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { IFontTextMask } from "./IFontTextMask";
|
|
2
|
-
import type { ITextMaskLine } from "./ITextMaskLine";
|
|
1
|
+
import type { IFontTextMask } from "./IFontTextMask.js";
|
|
2
|
+
import type { ITextMaskLine } from "./ITextMaskLine.js";
|
|
3
3
|
export interface ITextMask {
|
|
4
4
|
color: string;
|
|
5
5
|
font: IFontTextMask;
|
package/types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Engine } from "@tsparticles/engine";
|
|
2
|
-
export declare function loadCanvasMaskPlugin(engine: Engine): Promise<void>;
|
|
2
|
+
export declare function loadCanvasMaskPlugin(engine: Engine, refresh?: boolean): Promise<void>;
|
package/types/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Container, IOptions, Options } from "@tsparticles/engine";
|
|
2
|
-
import type { CanvasMask } from "./Options/Classes/CanvasMask";
|
|
3
|
-
import type { ICanvasMask } from "./Options/Interfaces/ICanvasMask";
|
|
2
|
+
import type { CanvasMask } from "./Options/Classes/CanvasMask.js";
|
|
3
|
+
import type { ICanvasMask } from "./Options/Interfaces/ICanvasMask.js";
|
|
4
4
|
export type ICanvasMaskOptions = IOptions & {
|
|
5
5
|
canvasMask?: ICanvasMask;
|
|
6
6
|
};
|
package/types/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { ICanvasMaskOverride } from "./Options/Interfaces/ICanvasMaskOverride";
|
|
3
|
-
import type { TextMask } from "./Options/Classes/TextMask";
|
|
1
|
+
import { type Container, type ICoordinates, type IDimension, type IRgba } from "@tsparticles/engine";
|
|
2
|
+
import type { ICanvasMaskOverride } from "./Options/Interfaces/ICanvasMaskOverride.js";
|
|
3
|
+
import type { TextMask } from "./Options/Classes/TextMask.js";
|
|
4
4
|
export type CanvasPixelData = {
|
|
5
5
|
height: number;
|
|
6
6
|
pixels: IRgba[][];
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "./utils"], factory);
|
|
7
|
+
define(["require", "exports", "./utils.js"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.CanvasMaskInstance = void 0;
|
|
13
|
-
const
|
|
13
|
+
const utils_js_1 = require("./utils.js");
|
|
14
14
|
class CanvasMaskInstance {
|
|
15
15
|
constructor(container, engine) {
|
|
16
16
|
this._container = container;
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
}
|
|
19
19
|
async init() {
|
|
20
20
|
const container = this._container, options = container.actualOptions.canvasMask;
|
|
21
|
-
if (!
|
|
21
|
+
if (!options?.enable) {
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
let pixelData = {
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
if (!url) {
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
|
-
pixelData = await (0,
|
|
35
|
+
pixelData = await (0, utils_js_1.getImageData)(url, offset);
|
|
36
36
|
}
|
|
37
37
|
else if (options.text) {
|
|
38
38
|
const textOptions = options.text;
|
|
39
|
-
const data = (0,
|
|
39
|
+
const data = (0, utils_js_1.getTextData)(textOptions, offset);
|
|
40
40
|
if (!data) {
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
@@ -51,9 +51,9 @@
|
|
|
51
51
|
if (!context) {
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
|
-
pixelData = (0,
|
|
54
|
+
pixelData = (0, utils_js_1.getCanvasImageData)(context, canvas, offset);
|
|
55
55
|
}
|
|
56
|
-
(0,
|
|
56
|
+
(0, utils_js_1.addParticlesFromCanvasPixels)(container, pixelData, options.position, options.scale, options.override, options.pixels.filter);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
exports.CanvasMaskInstance = CanvasMaskInstance;
|
|
@@ -4,21 +4,21 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "./CanvasMaskOverride", "./CanvasMaskPixels", "./ImageMask", "./TextMask"], factory);
|
|
7
|
+
define(["require", "exports", "./CanvasMaskOverride.js", "./CanvasMaskPixels.js", "./ImageMask.js", "./TextMask.js"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.CanvasMask = void 0;
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
13
|
+
const CanvasMaskOverride_js_1 = require("./CanvasMaskOverride.js");
|
|
14
|
+
const CanvasMaskPixels_js_1 = require("./CanvasMaskPixels.js");
|
|
15
|
+
const ImageMask_js_1 = require("./ImageMask.js");
|
|
16
|
+
const TextMask_js_1 = require("./TextMask.js");
|
|
17
17
|
class CanvasMask {
|
|
18
18
|
constructor() {
|
|
19
19
|
this.enable = false;
|
|
20
|
-
this.override = new
|
|
21
|
-
this.pixels = new
|
|
20
|
+
this.override = new CanvasMaskOverride_js_1.CanvasMaskOverride();
|
|
21
|
+
this.pixels = new CanvasMaskPixels_js_1.CanvasMaskPixels();
|
|
22
22
|
this.position = {
|
|
23
23
|
x: 50,
|
|
24
24
|
y: 50,
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
this.scale = 1;
|
|
27
27
|
}
|
|
28
28
|
load(data) {
|
|
29
|
-
var _a, _b;
|
|
30
29
|
if (!data) {
|
|
31
30
|
return;
|
|
32
31
|
}
|
|
@@ -38,15 +37,15 @@
|
|
|
38
37
|
}
|
|
39
38
|
if (data.image) {
|
|
40
39
|
if (!this.image) {
|
|
41
|
-
this.image = new
|
|
40
|
+
this.image = new ImageMask_js_1.ImageMask();
|
|
42
41
|
}
|
|
43
42
|
this.image.load(data.image);
|
|
44
43
|
}
|
|
45
44
|
this.pixels.load(data.pixels);
|
|
46
45
|
if (data.position) {
|
|
47
46
|
this.position = {
|
|
48
|
-
x:
|
|
49
|
-
y:
|
|
47
|
+
x: data.position.x ?? this.position.x,
|
|
48
|
+
y: data.position.y ?? this.position.y,
|
|
50
49
|
};
|
|
51
50
|
}
|
|
52
51
|
this.override.load(data.override);
|
|
@@ -58,7 +57,7 @@
|
|
|
58
57
|
}
|
|
59
58
|
if (data.text) {
|
|
60
59
|
if (!this.text) {
|
|
61
|
-
this.text = new
|
|
60
|
+
this.text = new TextMask_js_1.TextMask();
|
|
62
61
|
}
|
|
63
62
|
this.text.load(data.text);
|
|
64
63
|
}
|
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports"], factory);
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.CanvasMaskPixels = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
13
14
|
class CanvasMaskPixels {
|
|
14
15
|
constructor() {
|
|
15
16
|
this.filter = (pixel) => pixel.a > 0;
|
|
@@ -20,10 +21,10 @@
|
|
|
20
21
|
return;
|
|
21
22
|
}
|
|
22
23
|
if (data.filter !== undefined) {
|
|
23
|
-
if (
|
|
24
|
+
if ((0, engine_1.isString)(data.filter)) {
|
|
24
25
|
if (Object.hasOwn(window, data.filter)) {
|
|
25
26
|
const filter = window[data.filter];
|
|
26
|
-
if (
|
|
27
|
+
if ((0, engine_1.isFunction)(filter)) {
|
|
27
28
|
this.filter = filter;
|
|
28
29
|
}
|
|
29
30
|
}
|
|
@@ -4,19 +4,19 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "./FontTextMask", "./TextMaskLine"], factory);
|
|
7
|
+
define(["require", "exports", "./FontTextMask.js", "./TextMaskLine.js"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.TextMask = void 0;
|
|
13
|
-
const
|
|
14
|
-
const
|
|
13
|
+
const FontTextMask_js_1 = require("./FontTextMask.js");
|
|
14
|
+
const TextMaskLine_js_1 = require("./TextMaskLine.js");
|
|
15
15
|
class TextMask {
|
|
16
16
|
constructor() {
|
|
17
17
|
this.color = "#000000";
|
|
18
|
-
this.font = new
|
|
19
|
-
this.lines = new
|
|
18
|
+
this.font = new FontTextMask_js_1.FontTextMask();
|
|
19
|
+
this.lines = new TextMaskLine_js_1.TextMaskLine();
|
|
20
20
|
this.text = "";
|
|
21
21
|
}
|
|
22
22
|
load(data) {
|
package/umd/index.js
CHANGED
|
@@ -4,40 +4,38 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "./Options/Classes/CanvasMask", "./CanvasMaskInstance"], factory);
|
|
7
|
+
define(["require", "exports", "./Options/Classes/CanvasMask.js", "./CanvasMaskInstance.js"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.loadCanvasMaskPlugin = void 0;
|
|
13
|
-
const
|
|
14
|
-
const
|
|
13
|
+
const CanvasMask_js_1 = require("./Options/Classes/CanvasMask.js");
|
|
14
|
+
const CanvasMaskInstance_js_1 = require("./CanvasMaskInstance.js");
|
|
15
15
|
class CanvasMaskPlugin {
|
|
16
16
|
constructor(engine) {
|
|
17
17
|
this.id = "canvasMask";
|
|
18
18
|
this._engine = engine;
|
|
19
19
|
}
|
|
20
20
|
getPlugin(container) {
|
|
21
|
-
return new
|
|
21
|
+
return new CanvasMaskInstance_js_1.CanvasMaskInstance(container, this._engine);
|
|
22
22
|
}
|
|
23
23
|
loadOptions(options, source) {
|
|
24
|
-
if (!this.needsPlugin(source)) {
|
|
24
|
+
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
27
|
let canvasMaskOptions = options.canvasMask;
|
|
28
|
-
if (
|
|
29
|
-
options.canvasMask = canvasMaskOptions = new
|
|
28
|
+
if (canvasMaskOptions?.load === undefined) {
|
|
29
|
+
options.canvasMask = canvasMaskOptions = new CanvasMask_js_1.CanvasMask();
|
|
30
30
|
}
|
|
31
|
-
canvasMaskOptions.load(source
|
|
31
|
+
canvasMaskOptions.load(source?.canvasMask);
|
|
32
32
|
}
|
|
33
33
|
needsPlugin(options) {
|
|
34
|
-
|
|
35
|
-
return (_b = (_a = options === null || options === void 0 ? void 0 : options.canvasMask) === null || _a === void 0 ? void 0 : _a.enable) !== null && _b !== void 0 ? _b : false;
|
|
34
|
+
return options?.canvasMask?.enable ?? false;
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
|
-
async function loadCanvasMaskPlugin(engine) {
|
|
39
|
-
|
|
40
|
-
await engine.addPlugin(plugin);
|
|
37
|
+
async function loadCanvasMaskPlugin(engine, refresh = true) {
|
|
38
|
+
await engine.addPlugin(new CanvasMaskPlugin(engine), refresh);
|
|
41
39
|
}
|
|
42
40
|
exports.loadCanvasMaskPlugin = loadCanvasMaskPlugin;
|
|
43
41
|
});
|
package/umd/utils.js
CHANGED
|
@@ -31,25 +31,25 @@
|
|
|
31
31
|
x: nextIndex % width,
|
|
32
32
|
y: Math.floor(nextIndex / width),
|
|
33
33
|
}, pixel = data.pixels[pixelPos.y][pixelPos.x], shouldCreateParticle = filter(pixel);
|
|
34
|
-
if (shouldCreateParticle) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
if (!shouldCreateParticle) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const pos = {
|
|
38
|
+
x: pixelPos.x * scale + positionOffset.x,
|
|
39
|
+
y: pixelPos.y * scale + positionOffset.y,
|
|
40
|
+
}, pOptions = {};
|
|
41
|
+
if (override.color) {
|
|
42
|
+
pOptions.color = {
|
|
43
|
+
value: pixel,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (override.opacity) {
|
|
47
|
+
pOptions.opacity = {
|
|
48
|
+
value: pixel.a,
|
|
38
49
|
};
|
|
39
|
-
const pOptions = {};
|
|
40
|
-
if (override.color) {
|
|
41
|
-
pOptions.color = {
|
|
42
|
-
value: pixel,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
if (override.opacity) {
|
|
46
|
-
pOptions.opacity = {
|
|
47
|
-
value: pixel.a,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
container.particles.addParticle(pos, pOptions);
|
|
51
|
-
selectedPixels++;
|
|
52
50
|
}
|
|
51
|
+
container.particles.addParticle(pos, pOptions);
|
|
52
|
+
selectedPixels++;
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
exports.addParticlesFromCanvasPixels = addParticlesFromCanvasPixels;
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
canvas.height = image.height;
|
|
93
93
|
const context = canvas.getContext("2d");
|
|
94
94
|
if (!context) {
|
|
95
|
-
return reject(new Error(
|
|
95
|
+
return reject(new Error(`${engine_1.errorPrefix} Could not get canvas context`));
|
|
96
96
|
}
|
|
97
97
|
context.drawImage(image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height);
|
|
98
98
|
resolve(getCanvasImageData(context, canvas, offset));
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
if (!text || !context) {
|
|
108
108
|
return;
|
|
109
109
|
}
|
|
110
|
-
const lines = text.split(linesOptions.separator), fontSize =
|
|
110
|
+
const lines = text.split(linesOptions.separator), fontSize = (0, engine_1.isNumber)(font.size) ? `${font.size}px` : font.size, linesData = [];
|
|
111
111
|
let maxWidth = 0, totalHeight = 0;
|
|
112
112
|
for (const line of lines) {
|
|
113
113
|
context.font = `${font.style || ""} ${font.variant || ""} ${font.weight || ""} ${fontSize} ${font.family}`;
|