@tsparticles/plugin-canvas-mask 3.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/LICENSE +21 -0
- package/README.md +70 -0
- package/browser/CanvasMaskInstance.js +46 -0
- package/browser/Options/Classes/CanvasMask.js +54 -0
- package/browser/Options/Classes/CanvasMaskOverride.js +17 -0
- package/browser/Options/Classes/CanvasMaskPixels.js +27 -0
- package/browser/Options/Classes/FontTextMask.js +26 -0
- package/browser/Options/Classes/ImageMask.js +13 -0
- package/browser/Options/Classes/TextMask.js +23 -0
- package/browser/Options/Classes/TextMaskLine.js +17 -0
- package/browser/Options/Interfaces/ICanvasMask.js +1 -0
- package/browser/Options/Interfaces/ICanvasMaskOverride.js +1 -0
- package/browser/Options/Interfaces/ICanvasMaskPixels.js +1 -0
- package/browser/Options/Interfaces/IFontTextMask.js +1 -0
- package/browser/Options/Interfaces/IImageMask.js +1 -0
- package/browser/Options/Interfaces/ITextMask.js +1 -0
- package/browser/Options/Interfaces/ITextMaskLine.js +1 -0
- package/browser/index.js +29 -0
- package/browser/types.js +1 -0
- package/browser/utils.js +119 -0
- package/cjs/CanvasMaskInstance.js +61 -0
- package/cjs/Options/Classes/CanvasMask.js +58 -0
- package/cjs/Options/Classes/CanvasMaskOverride.js +21 -0
- package/cjs/Options/Classes/CanvasMaskPixels.js +31 -0
- package/cjs/Options/Classes/FontTextMask.js +30 -0
- package/cjs/Options/Classes/ImageMask.js +17 -0
- package/cjs/Options/Classes/TextMask.js +27 -0
- package/cjs/Options/Classes/TextMaskLine.js +21 -0
- package/cjs/Options/Interfaces/ICanvasMask.js +2 -0
- package/cjs/Options/Interfaces/ICanvasMaskOverride.js +2 -0
- package/cjs/Options/Interfaces/ICanvasMaskPixels.js +2 -0
- package/cjs/Options/Interfaces/IFontTextMask.js +2 -0
- package/cjs/Options/Interfaces/IImageMask.js +2 -0
- package/cjs/Options/Interfaces/ITextMask.js +2 -0
- package/cjs/Options/Interfaces/ITextMaskLine.js +2 -0
- package/cjs/index.js +44 -0
- package/cjs/types.js +2 -0
- package/cjs/utils.js +128 -0
- package/esm/CanvasMaskInstance.js +46 -0
- package/esm/Options/Classes/CanvasMask.js +54 -0
- package/esm/Options/Classes/CanvasMaskOverride.js +17 -0
- package/esm/Options/Classes/CanvasMaskPixels.js +27 -0
- package/esm/Options/Classes/FontTextMask.js +26 -0
- package/esm/Options/Classes/ImageMask.js +13 -0
- package/esm/Options/Classes/TextMask.js +23 -0
- package/esm/Options/Classes/TextMaskLine.js +17 -0
- package/esm/Options/Interfaces/ICanvasMask.js +1 -0
- package/esm/Options/Interfaces/ICanvasMaskOverride.js +1 -0
- package/esm/Options/Interfaces/ICanvasMaskPixels.js +1 -0
- package/esm/Options/Interfaces/IFontTextMask.js +1 -0
- package/esm/Options/Interfaces/IImageMask.js +1 -0
- package/esm/Options/Interfaces/ITextMask.js +1 -0
- package/esm/Options/Interfaces/ITextMaskLine.js +1 -0
- package/esm/index.js +29 -0
- package/esm/types.js +1 -0
- package/esm/utils.js +119 -0
- package/package.json +81 -0
- package/report.html +39 -0
- package/tsparticles.plugin.canvas-mask.js +505 -0
- package/tsparticles.plugin.canvas-mask.min.js +2 -0
- package/tsparticles.plugin.canvas-mask.min.js.LICENSE.txt +8 -0
- package/types/CanvasMaskInstance.d.ts +8 -0
- package/types/Options/Classes/CanvasMask.d.ts +19 -0
- package/types/Options/Classes/CanvasMaskOverride.d.ts +8 -0
- package/types/Options/Classes/CanvasMaskPixels.d.ts +8 -0
- package/types/Options/Classes/FontTextMask.d.ts +11 -0
- package/types/Options/Classes/ImageMask.d.ts +7 -0
- package/types/Options/Classes/TextMask.d.ts +12 -0
- package/types/Options/Classes/TextMaskLine.d.ts +8 -0
- package/types/Options/Interfaces/ICanvasMask.d.ts +16 -0
- package/types/Options/Interfaces/ICanvasMaskOverride.d.ts +4 -0
- package/types/Options/Interfaces/ICanvasMaskPixels.d.ts +5 -0
- package/types/Options/Interfaces/IFontTextMask.d.ts +7 -0
- package/types/Options/Interfaces/IImageMask.d.ts +3 -0
- package/types/Options/Interfaces/ITextMask.d.ts +8 -0
- package/types/Options/Interfaces/ITextMaskLine.d.ts +4 -0
- package/types/index.d.ts +2 -0
- package/types/types.d.ts +12 -0
- package/types/utils.d.ts +14 -0
- package/umd/CanvasMaskInstance.js +60 -0
- package/umd/Options/Classes/CanvasMask.js +68 -0
- package/umd/Options/Classes/CanvasMaskOverride.js +31 -0
- package/umd/Options/Classes/CanvasMaskPixels.js +41 -0
- package/umd/Options/Classes/FontTextMask.js +40 -0
- package/umd/Options/Classes/ImageMask.js +27 -0
- package/umd/Options/Classes/TextMask.js +37 -0
- package/umd/Options/Classes/TextMaskLine.js +31 -0
- package/umd/Options/Interfaces/ICanvasMask.js +12 -0
- package/umd/Options/Interfaces/ICanvasMaskOverride.js +12 -0
- package/umd/Options/Interfaces/ICanvasMaskPixels.js +12 -0
- package/umd/Options/Interfaces/IFontTextMask.js +12 -0
- package/umd/Options/Interfaces/IImageMask.js +12 -0
- package/umd/Options/Interfaces/ITextMask.js +12 -0
- package/umd/Options/Interfaces/ITextMaskLine.js +12 -0
- package/umd/index.js +43 -0
- package/umd/types.js +12 -0
- package/umd/utils.js +138 -0
package/types/types.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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";
|
|
4
|
+
export type ICanvasMaskOptions = IOptions & {
|
|
5
|
+
canvasMask?: ICanvasMask;
|
|
6
|
+
};
|
|
7
|
+
export type CanvasMaskOptions = Options & {
|
|
8
|
+
canvasMask?: CanvasMask;
|
|
9
|
+
};
|
|
10
|
+
export type CanvasMaskContainer = Container & {
|
|
11
|
+
actualOptions: CanvasMaskOptions;
|
|
12
|
+
};
|
package/types/utils.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Container, ICoordinates, IDimension, IRgba } from "@tsparticles/engine";
|
|
2
|
+
import type { ICanvasMaskOverride } from "./Options/Interfaces/ICanvasMaskOverride";
|
|
3
|
+
import type { TextMask } from "./Options/Classes/TextMask";
|
|
4
|
+
export type CanvasPixelData = {
|
|
5
|
+
height: number;
|
|
6
|
+
pixels: IRgba[][];
|
|
7
|
+
width: number;
|
|
8
|
+
};
|
|
9
|
+
export declare function shuffle<T>(array: T[]): T[];
|
|
10
|
+
export declare function addParticlesFromCanvasPixels(container: Container, data: CanvasPixelData, position: ICoordinates, scale: number, override: ICanvasMaskOverride, filter: (pixel: IRgba) => boolean): void;
|
|
11
|
+
export declare function getCanvasImageData(ctx: CanvasRenderingContext2D, size: IDimension, offset: number, clear?: boolean): CanvasPixelData;
|
|
12
|
+
export declare function getImageData(src: string, offset: number): Promise<CanvasPixelData>;
|
|
13
|
+
export declare function getTextData(textOptions: TextMask, offset: number): CanvasPixelData | undefined;
|
|
14
|
+
export declare const range: (n: number) => Array<number>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "./utils"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CanvasMaskInstance = void 0;
|
|
13
|
+
const utils_1 = require("./utils");
|
|
14
|
+
class CanvasMaskInstance {
|
|
15
|
+
constructor(container, engine) {
|
|
16
|
+
this._container = container;
|
|
17
|
+
this._engine = engine;
|
|
18
|
+
}
|
|
19
|
+
async init() {
|
|
20
|
+
const container = this._container, options = container.actualOptions.canvasMask;
|
|
21
|
+
if (!(options === null || options === void 0 ? void 0 : options.enable)) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
let pixelData = {
|
|
25
|
+
pixels: [],
|
|
26
|
+
height: 0,
|
|
27
|
+
width: 0,
|
|
28
|
+
};
|
|
29
|
+
const offset = options.pixels.offset;
|
|
30
|
+
if (options.image) {
|
|
31
|
+
const url = options.image.src;
|
|
32
|
+
if (!url) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
pixelData = await (0, utils_1.getImageData)(url, offset);
|
|
36
|
+
}
|
|
37
|
+
else if (options.text) {
|
|
38
|
+
const textOptions = options.text;
|
|
39
|
+
const data = (0, utils_1.getTextData)(textOptions, offset);
|
|
40
|
+
if (!data) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
pixelData = data;
|
|
44
|
+
}
|
|
45
|
+
else if (options.element || options.selector) {
|
|
46
|
+
const canvas = options.element || (options.selector && document.querySelector(options.selector));
|
|
47
|
+
if (!canvas) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const context = canvas.getContext("2d");
|
|
51
|
+
if (!context) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
pixelData = (0, utils_1.getCanvasImageData)(context, canvas, offset);
|
|
55
|
+
}
|
|
56
|
+
(0, utils_1.addParticlesFromCanvasPixels)(container, pixelData, options.position, options.scale, options.override, options.pixels.filter);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.CanvasMaskInstance = CanvasMaskInstance;
|
|
60
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "./CanvasMaskOverride", "./CanvasMaskPixels", "./ImageMask", "./TextMask"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CanvasMask = void 0;
|
|
13
|
+
const CanvasMaskOverride_1 = require("./CanvasMaskOverride");
|
|
14
|
+
const CanvasMaskPixels_1 = require("./CanvasMaskPixels");
|
|
15
|
+
const ImageMask_1 = require("./ImageMask");
|
|
16
|
+
const TextMask_1 = require("./TextMask");
|
|
17
|
+
class CanvasMask {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.enable = false;
|
|
20
|
+
this.override = new CanvasMaskOverride_1.CanvasMaskOverride();
|
|
21
|
+
this.pixels = new CanvasMaskPixels_1.CanvasMaskPixels();
|
|
22
|
+
this.position = {
|
|
23
|
+
x: 50,
|
|
24
|
+
y: 50,
|
|
25
|
+
};
|
|
26
|
+
this.scale = 1;
|
|
27
|
+
}
|
|
28
|
+
load(data) {
|
|
29
|
+
var _a, _b;
|
|
30
|
+
if (!data) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (data.element !== undefined && data.element instanceof HTMLCanvasElement) {
|
|
34
|
+
this.element = data.element;
|
|
35
|
+
}
|
|
36
|
+
if (data.enable !== undefined) {
|
|
37
|
+
this.enable = data.enable;
|
|
38
|
+
}
|
|
39
|
+
if (data.image) {
|
|
40
|
+
if (!this.image) {
|
|
41
|
+
this.image = new ImageMask_1.ImageMask();
|
|
42
|
+
}
|
|
43
|
+
this.image.load(data.image);
|
|
44
|
+
}
|
|
45
|
+
this.pixels.load(data.pixels);
|
|
46
|
+
if (data.position) {
|
|
47
|
+
this.position = {
|
|
48
|
+
x: (_a = data.position.x) !== null && _a !== void 0 ? _a : this.position.x,
|
|
49
|
+
y: (_b = data.position.y) !== null && _b !== void 0 ? _b : this.position.y,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
this.override.load(data.override);
|
|
53
|
+
if (data.scale !== undefined) {
|
|
54
|
+
this.scale = data.scale;
|
|
55
|
+
}
|
|
56
|
+
if (data.selector !== undefined) {
|
|
57
|
+
this.selector = data.selector;
|
|
58
|
+
}
|
|
59
|
+
if (data.text) {
|
|
60
|
+
if (!this.text) {
|
|
61
|
+
this.text = new TextMask_1.TextMask();
|
|
62
|
+
}
|
|
63
|
+
this.text.load(data.text);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.CanvasMask = CanvasMask;
|
|
68
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CanvasMaskOverride = void 0;
|
|
13
|
+
class CanvasMaskOverride {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.color = true;
|
|
16
|
+
this.opacity = false;
|
|
17
|
+
}
|
|
18
|
+
load(data) {
|
|
19
|
+
if (!data) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (data.color !== undefined) {
|
|
23
|
+
this.color = data.color;
|
|
24
|
+
}
|
|
25
|
+
if (data.opacity !== undefined) {
|
|
26
|
+
this.opacity = data.opacity;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.CanvasMaskOverride = CanvasMaskOverride;
|
|
31
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CanvasMaskPixels = void 0;
|
|
13
|
+
class CanvasMaskPixels {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.filter = (pixel) => pixel.a > 0;
|
|
16
|
+
this.offset = 4;
|
|
17
|
+
}
|
|
18
|
+
load(data) {
|
|
19
|
+
if (!data) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (data.filter !== undefined) {
|
|
23
|
+
if (typeof data.filter === "string") {
|
|
24
|
+
if (Object.hasOwn(window, data.filter)) {
|
|
25
|
+
const filter = window[data.filter];
|
|
26
|
+
if (typeof filter === "function") {
|
|
27
|
+
this.filter = filter;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
this.filter = data.filter;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (data.offset !== undefined) {
|
|
36
|
+
this.offset = data.offset;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.CanvasMaskPixels = CanvasMaskPixels;
|
|
41
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.FontTextMask = void 0;
|
|
13
|
+
class FontTextMask {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.family = "sans-serif";
|
|
16
|
+
this.size = 100;
|
|
17
|
+
}
|
|
18
|
+
load(data) {
|
|
19
|
+
if (!data) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (data.family !== undefined) {
|
|
23
|
+
this.family = data.family;
|
|
24
|
+
}
|
|
25
|
+
if (data.size !== undefined) {
|
|
26
|
+
this.size = data.size;
|
|
27
|
+
}
|
|
28
|
+
if (data.style !== undefined) {
|
|
29
|
+
this.style = data.style;
|
|
30
|
+
}
|
|
31
|
+
if (data.variant !== undefined) {
|
|
32
|
+
this.variant = data.variant;
|
|
33
|
+
}
|
|
34
|
+
if (data.weight !== undefined) {
|
|
35
|
+
this.weight = data.weight;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.FontTextMask = FontTextMask;
|
|
40
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ImageMask = void 0;
|
|
13
|
+
class ImageMask {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.src = "";
|
|
16
|
+
}
|
|
17
|
+
load(data) {
|
|
18
|
+
if (!data) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (data.src !== undefined) {
|
|
22
|
+
this.src = data.src;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.ImageMask = ImageMask;
|
|
27
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "./FontTextMask", "./TextMaskLine"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TextMask = void 0;
|
|
13
|
+
const FontTextMask_1 = require("./FontTextMask");
|
|
14
|
+
const TextMaskLine_1 = require("./TextMaskLine");
|
|
15
|
+
class TextMask {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.color = "#000000";
|
|
18
|
+
this.font = new FontTextMask_1.FontTextMask();
|
|
19
|
+
this.lines = new TextMaskLine_1.TextMaskLine();
|
|
20
|
+
this.text = "";
|
|
21
|
+
}
|
|
22
|
+
load(data) {
|
|
23
|
+
if (!data) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (data.color !== undefined) {
|
|
27
|
+
this.color = data.color;
|
|
28
|
+
}
|
|
29
|
+
this.font.load(data.font);
|
|
30
|
+
this.lines.load(data.lines);
|
|
31
|
+
if (data.text !== undefined) {
|
|
32
|
+
this.text = data.text;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.TextMask = TextMask;
|
|
37
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TextMaskLine = void 0;
|
|
13
|
+
class TextMaskLine {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.separator = "\n";
|
|
16
|
+
this.spacing = 10;
|
|
17
|
+
}
|
|
18
|
+
load(data) {
|
|
19
|
+
if (!data) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (data.separator !== undefined) {
|
|
23
|
+
this.separator = data.separator;
|
|
24
|
+
}
|
|
25
|
+
if (data.spacing !== undefined) {
|
|
26
|
+
this.spacing = data.spacing;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.TextMaskLine = TextMaskLine;
|
|
31
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
package/umd/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "./Options/Classes/CanvasMask", "./CanvasMaskInstance"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.loadCanvasMaskPlugin = void 0;
|
|
13
|
+
const CanvasMask_1 = require("./Options/Classes/CanvasMask");
|
|
14
|
+
const CanvasMaskInstance_1 = require("./CanvasMaskInstance");
|
|
15
|
+
class CanvasMaskPlugin {
|
|
16
|
+
constructor(engine) {
|
|
17
|
+
this.id = "canvasMask";
|
|
18
|
+
this._engine = engine;
|
|
19
|
+
}
|
|
20
|
+
getPlugin(container) {
|
|
21
|
+
return new CanvasMaskInstance_1.CanvasMaskInstance(container, this._engine);
|
|
22
|
+
}
|
|
23
|
+
loadOptions(options, source) {
|
|
24
|
+
if (!this.needsPlugin(source)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
let canvasMaskOptions = options.canvasMask;
|
|
28
|
+
if ((canvasMaskOptions === null || canvasMaskOptions === void 0 ? void 0 : canvasMaskOptions.load) === undefined) {
|
|
29
|
+
options.canvasMask = canvasMaskOptions = new CanvasMask_1.CanvasMask();
|
|
30
|
+
}
|
|
31
|
+
canvasMaskOptions.load(source === null || source === void 0 ? void 0 : source.canvasMask);
|
|
32
|
+
}
|
|
33
|
+
needsPlugin(options) {
|
|
34
|
+
var _a, _b;
|
|
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;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function loadCanvasMaskPlugin(engine) {
|
|
39
|
+
const plugin = new CanvasMaskPlugin(engine);
|
|
40
|
+
await engine.addPlugin(plugin);
|
|
41
|
+
}
|
|
42
|
+
exports.loadCanvasMaskPlugin = loadCanvasMaskPlugin;
|
|
43
|
+
});
|
package/umd/types.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
package/umd/utils.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.range = exports.getTextData = exports.getImageData = exports.getCanvasImageData = exports.addParticlesFromCanvasPixels = exports.shuffle = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
function shuffle(array) {
|
|
15
|
+
for (let currentIndex = array.length - 1; currentIndex >= 0; currentIndex--) {
|
|
16
|
+
const randomIndex = Math.floor((0, engine_1.getRandom)() * currentIndex);
|
|
17
|
+
[array[currentIndex], array[randomIndex]] = [array[randomIndex], array[currentIndex]];
|
|
18
|
+
}
|
|
19
|
+
return array;
|
|
20
|
+
}
|
|
21
|
+
exports.shuffle = shuffle;
|
|
22
|
+
function addParticlesFromCanvasPixels(container, data, position, scale, override, filter) {
|
|
23
|
+
const { height, width } = data, numPixels = height * width, indexArray = shuffle((0, exports.range)(numPixels)), maxParticles = Math.min(numPixels, container.actualOptions.particles.number.value), canvasSize = container.canvas.size;
|
|
24
|
+
let selectedPixels = 0;
|
|
25
|
+
const positionOffset = {
|
|
26
|
+
x: (canvasSize.width * position.x) / 100 - (width * scale) / 2,
|
|
27
|
+
y: (canvasSize.height * position.y) / 100 - (height * scale) / 2,
|
|
28
|
+
};
|
|
29
|
+
while (selectedPixels < maxParticles && indexArray.length) {
|
|
30
|
+
const nextIndex = indexArray.pop() || 0, pixelPos = {
|
|
31
|
+
x: nextIndex % width,
|
|
32
|
+
y: Math.floor(nextIndex / width),
|
|
33
|
+
}, pixel = data.pixels[pixelPos.y][pixelPos.x], shouldCreateParticle = filter(pixel);
|
|
34
|
+
if (shouldCreateParticle) {
|
|
35
|
+
const pos = {
|
|
36
|
+
x: pixelPos.x * scale + positionOffset.x,
|
|
37
|
+
y: pixelPos.y * scale + positionOffset.y,
|
|
38
|
+
};
|
|
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
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.addParticlesFromCanvasPixels = addParticlesFromCanvasPixels;
|
|
56
|
+
function getCanvasImageData(ctx, size, offset, clear = true) {
|
|
57
|
+
const imageData = ctx.getImageData(0, 0, size.width, size.height).data;
|
|
58
|
+
if (clear) {
|
|
59
|
+
ctx.clearRect(0, 0, size.width, size.height);
|
|
60
|
+
}
|
|
61
|
+
const pixels = [];
|
|
62
|
+
for (let i = 0; i < imageData.length; i += offset) {
|
|
63
|
+
const idx = i / offset, pos = {
|
|
64
|
+
x: idx % size.width,
|
|
65
|
+
y: Math.floor(idx / size.width),
|
|
66
|
+
};
|
|
67
|
+
if (!pixels[pos.y]) {
|
|
68
|
+
pixels[pos.y] = [];
|
|
69
|
+
}
|
|
70
|
+
pixels[pos.y][pos.x] = {
|
|
71
|
+
r: imageData[i],
|
|
72
|
+
g: imageData[i + 1],
|
|
73
|
+
b: imageData[i + 2],
|
|
74
|
+
a: imageData[i + 3] / 255,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
pixels,
|
|
79
|
+
width: Math.min(...pixels.map((row) => row.length)),
|
|
80
|
+
height: pixels.length,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
exports.getCanvasImageData = getCanvasImageData;
|
|
84
|
+
function getImageData(src, offset) {
|
|
85
|
+
const image = new Image();
|
|
86
|
+
image.crossOrigin = "Anonymous";
|
|
87
|
+
const p = new Promise((resolve, reject) => {
|
|
88
|
+
image.onerror = reject;
|
|
89
|
+
image.onload = () => {
|
|
90
|
+
const canvas = document.createElement("canvas");
|
|
91
|
+
canvas.width = image.width;
|
|
92
|
+
canvas.height = image.height;
|
|
93
|
+
const context = canvas.getContext("2d");
|
|
94
|
+
if (!context) {
|
|
95
|
+
return reject(new Error("Could not get canvas context"));
|
|
96
|
+
}
|
|
97
|
+
context.drawImage(image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height);
|
|
98
|
+
resolve(getCanvasImageData(context, canvas, offset));
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
image.src = src;
|
|
102
|
+
return p;
|
|
103
|
+
}
|
|
104
|
+
exports.getImageData = getImageData;
|
|
105
|
+
function getTextData(textOptions, offset) {
|
|
106
|
+
const canvas = document.createElement("canvas"), context = canvas.getContext("2d"), { font, text, lines: linesOptions, color } = textOptions;
|
|
107
|
+
if (!text || !context) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const lines = text.split(linesOptions.separator), fontSize = typeof font.size === "number" ? `${font.size}px` : font.size, linesData = [];
|
|
111
|
+
let maxWidth = 0, totalHeight = 0;
|
|
112
|
+
for (const line of lines) {
|
|
113
|
+
context.font = `${font.style || ""} ${font.variant || ""} ${font.weight || ""} ${fontSize} ${font.family}`;
|
|
114
|
+
const measure = context.measureText(line), lineData = {
|
|
115
|
+
measure,
|
|
116
|
+
text: line,
|
|
117
|
+
height: measure.actualBoundingBoxAscent + measure.actualBoundingBoxDescent,
|
|
118
|
+
width: measure.width,
|
|
119
|
+
};
|
|
120
|
+
maxWidth = Math.max(maxWidth || 0, lineData.width);
|
|
121
|
+
totalHeight += lineData.height + linesOptions.spacing;
|
|
122
|
+
linesData.push(lineData);
|
|
123
|
+
}
|
|
124
|
+
canvas.width = maxWidth;
|
|
125
|
+
canvas.height = totalHeight;
|
|
126
|
+
let currentHeight = 0;
|
|
127
|
+
for (const line of linesData) {
|
|
128
|
+
context.font = `${font.style || ""} ${font.variant || ""} ${font.weight || ""} ${fontSize} ${font.family}`;
|
|
129
|
+
context.fillStyle = color;
|
|
130
|
+
context.fillText(line.text, 0, currentHeight + line.measure.actualBoundingBoxAscent);
|
|
131
|
+
currentHeight += line.height + linesOptions.spacing;
|
|
132
|
+
}
|
|
133
|
+
return getCanvasImageData(context, canvas, offset);
|
|
134
|
+
}
|
|
135
|
+
exports.getTextData = getTextData;
|
|
136
|
+
const range = (n) => [...Array(n).keys()];
|
|
137
|
+
exports.range = range;
|
|
138
|
+
});
|