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