@tsparticles/plugin-emitters-shape-canvas 4.0.0-alpha.8 → 4.0.0-beta.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/373.min.js +2 -0
- package/browser/EmittersCanvasShape.js +12 -7
- package/browser/EmittersCanvasShapeGenerator.js +2 -2
- package/browser/Options/Classes/EmittersCanvasShapeOptions.js +7 -0
- package/browser/Options/Classes/PixelsOptions.js +1 -0
- package/browser/Options/Classes/TextFontOptions.js +5 -0
- package/browser/Options/Classes/TextLinesOptions.js +2 -0
- package/browser/Options/Classes/TextOptions.js +4 -0
- package/browser/index.js +4 -5
- package/cjs/EmittersCanvasShape.js +12 -7
- package/cjs/EmittersCanvasShapeGenerator.js +2 -2
- package/cjs/Options/Classes/EmittersCanvasShapeOptions.js +7 -0
- package/cjs/Options/Classes/PixelsOptions.js +1 -0
- package/cjs/Options/Classes/TextFontOptions.js +5 -0
- package/cjs/Options/Classes/TextLinesOptions.js +2 -0
- package/cjs/Options/Classes/TextOptions.js +4 -0
- package/cjs/index.js +4 -5
- package/dist_browser_EmittersCanvasShapeGenerator_js.js +8 -18
- package/esm/EmittersCanvasShape.js +12 -7
- package/esm/EmittersCanvasShapeGenerator.js +2 -2
- package/esm/Options/Classes/EmittersCanvasShapeOptions.js +7 -0
- package/esm/Options/Classes/PixelsOptions.js +1 -0
- package/esm/Options/Classes/TextFontOptions.js +5 -0
- package/esm/Options/Classes/TextLinesOptions.js +2 -0
- package/esm/Options/Classes/TextOptions.js +4 -0
- package/esm/index.js +4 -5
- package/package.json +4 -3
- package/report.html +1 -1
- package/tsparticles.plugin.emitters.shape.canvas.js +71 -19
- package/tsparticles.plugin.emitters.shape.canvas.min.js +2 -2
- package/types/EmittersCanvasShape.d.ts +3 -2
- package/types/EmittersCanvasShapeGenerator.d.ts +2 -2
- package/types/Options/Interfaces/ITextFontOptions.d.ts +2 -7
- package/types/Options/Interfaces/ITextLinesOptions.d.ts +2 -4
- package/types/Options/Interfaces/ITextOptions.d.ts +2 -3
- package/umd/EmittersCanvasShape.js +14 -9
- package/umd/EmittersCanvasShapeGenerator.js +2 -2
- package/umd/Options/Classes/EmittersCanvasShapeOptions.js +7 -0
- package/umd/Options/Classes/PixelsOptions.js +1 -0
- package/umd/Options/Classes/TextFontOptions.js +5 -0
- package/umd/Options/Classes/TextLinesOptions.js +2 -0
- package/umd/Options/Classes/TextOptions.js +4 -0
- package/umd/index.js +5 -6
- package/103.min.js +0 -2
- package/103.min.js.LICENSE.txt +0 -1
- package/browser/utils.js +0 -96
- package/cjs/utils.js +0 -96
- package/esm/utils.js +0 -96
- package/tsparticles.plugin.emitters.shape.canvas.min.js.LICENSE.txt +0 -1
- package/types/utils.d.ts +0 -6
- package/umd/utils.js +0 -111
package/esm/utils.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { isNumber, safeDocument } from "@tsparticles/engine";
|
|
2
|
-
const origin = {
|
|
3
|
-
x: 0,
|
|
4
|
-
y: 0,
|
|
5
|
-
}, minWidth = 0, defaultRgbValue = 0, defaultAlphaValue = 1;
|
|
6
|
-
export function getCanvasImageData(ctx, size, offset, clear = true) {
|
|
7
|
-
const imageData = ctx.getImageData(origin.x, origin.y, size.width, size.height).data;
|
|
8
|
-
if (clear) {
|
|
9
|
-
ctx.clearRect(origin.x, origin.y, size.width, size.height);
|
|
10
|
-
}
|
|
11
|
-
const pixels = [];
|
|
12
|
-
for (let i = 0; i < imageData.length; i += offset) {
|
|
13
|
-
const idx = i / offset, pos = {
|
|
14
|
-
x: idx % size.width,
|
|
15
|
-
y: Math.floor(idx / size.width),
|
|
16
|
-
};
|
|
17
|
-
pixels[pos.y] ??= [];
|
|
18
|
-
const indexesOffset = {
|
|
19
|
-
r: 0,
|
|
20
|
-
g: 1,
|
|
21
|
-
b: 2,
|
|
22
|
-
a: 3,
|
|
23
|
-
}, alphaFactor = 255, row = pixels[pos.y];
|
|
24
|
-
if (!row) {
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
row[pos.x] = {
|
|
28
|
-
r: imageData[i + indexesOffset.r] ?? defaultRgbValue,
|
|
29
|
-
g: imageData[i + indexesOffset.g] ?? defaultRgbValue,
|
|
30
|
-
b: imageData[i + indexesOffset.b] ?? defaultRgbValue,
|
|
31
|
-
a: (imageData[i + indexesOffset.a] ?? defaultAlphaValue) / alphaFactor,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
pixels,
|
|
36
|
-
width: Math.min(...pixels.map(row => row.length)),
|
|
37
|
-
height: pixels.length,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
export function getImageData(src, offset) {
|
|
41
|
-
const image = new Image();
|
|
42
|
-
image.crossOrigin = "Anonymous";
|
|
43
|
-
const p = new Promise((resolve, reject) => {
|
|
44
|
-
image.onerror = reject;
|
|
45
|
-
image.onload = () => {
|
|
46
|
-
const canvas = safeDocument().createElement("canvas");
|
|
47
|
-
canvas.width = image.width;
|
|
48
|
-
canvas.height = image.height;
|
|
49
|
-
const context = canvas.getContext("2d");
|
|
50
|
-
if (!context) {
|
|
51
|
-
reject(new Error("Could not get canvas context"));
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
context.drawImage(image, origin.x, origin.y, image.width, image.height, origin.x, origin.y, canvas.width, canvas.height);
|
|
55
|
-
resolve(getCanvasImageData(context, canvas, offset));
|
|
56
|
-
};
|
|
57
|
-
});
|
|
58
|
-
image.src = src;
|
|
59
|
-
return p;
|
|
60
|
-
}
|
|
61
|
-
export function getTextData(textOptions, offset, fill) {
|
|
62
|
-
const canvas = safeDocument().createElement("canvas"), context = canvas.getContext("2d"), { font, text, lines: linesOptions, color } = textOptions;
|
|
63
|
-
if (!text || !context) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const lines = text.split(linesOptions.separator), fontSize = isNumber(font.size) ? `${font.size.toString()}px` : font.size, linesData = [];
|
|
67
|
-
let maxWidth = 0, totalHeight = 0;
|
|
68
|
-
for (const line of lines) {
|
|
69
|
-
context.font = `${font.style || ""} ${font.variant || ""} ${font.weight || ""} ${fontSize} ${font.family}`;
|
|
70
|
-
const measure = context.measureText(line), lineData = {
|
|
71
|
-
measure,
|
|
72
|
-
text: line,
|
|
73
|
-
height: measure.actualBoundingBoxAscent + measure.actualBoundingBoxDescent,
|
|
74
|
-
width: measure.width,
|
|
75
|
-
};
|
|
76
|
-
maxWidth = Math.max(maxWidth || minWidth, lineData.width);
|
|
77
|
-
totalHeight += lineData.height + linesOptions.spacing;
|
|
78
|
-
linesData.push(lineData);
|
|
79
|
-
}
|
|
80
|
-
canvas.width = maxWidth;
|
|
81
|
-
canvas.height = totalHeight;
|
|
82
|
-
let currentHeight = 0;
|
|
83
|
-
for (const line of linesData) {
|
|
84
|
-
context.font = `${font.style || ""} ${font.variant || ""} ${font.weight || ""} ${fontSize} ${font.family}`;
|
|
85
|
-
if (fill) {
|
|
86
|
-
context.fillStyle = color;
|
|
87
|
-
context.fillText(line.text, origin.x, currentHeight + line.measure.actualBoundingBoxAscent);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
context.strokeStyle = color;
|
|
91
|
-
context.strokeText(line.text, origin.x, currentHeight + line.measure.actualBoundingBoxAscent);
|
|
92
|
-
}
|
|
93
|
-
currentHeight += line.height + linesOptions.spacing;
|
|
94
|
-
}
|
|
95
|
-
return getCanvasImageData(context, canvas, offset);
|
|
96
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/*! tsParticles Emitters Shape Canvas Plugin v4.0.0-alpha.8 by Matteo Bruni */
|
package/types/utils.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { CanvasPixelData } from "./types.js";
|
|
2
|
-
import { type IDimension } from "@tsparticles/engine";
|
|
3
|
-
import type { TextOptions } from "./Options/Classes/TextOptions.js";
|
|
4
|
-
export declare function getCanvasImageData(ctx: CanvasRenderingContext2D, size: IDimension, offset: number, clear?: boolean): CanvasPixelData;
|
|
5
|
-
export declare function getImageData(src: string, offset: number): Promise<CanvasPixelData>;
|
|
6
|
-
export declare function getTextData(textOptions: TextOptions, offset: number, fill: boolean): CanvasPixelData | undefined;
|
package/umd/utils.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
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.getCanvasImageData = getCanvasImageData;
|
|
13
|
-
exports.getImageData = getImageData;
|
|
14
|
-
exports.getTextData = getTextData;
|
|
15
|
-
const engine_1 = require("@tsparticles/engine");
|
|
16
|
-
const origin = {
|
|
17
|
-
x: 0,
|
|
18
|
-
y: 0,
|
|
19
|
-
}, minWidth = 0, defaultRgbValue = 0, defaultAlphaValue = 1;
|
|
20
|
-
function getCanvasImageData(ctx, size, offset, clear = true) {
|
|
21
|
-
const imageData = ctx.getImageData(origin.x, origin.y, size.width, size.height).data;
|
|
22
|
-
if (clear) {
|
|
23
|
-
ctx.clearRect(origin.x, origin.y, size.width, size.height);
|
|
24
|
-
}
|
|
25
|
-
const pixels = [];
|
|
26
|
-
for (let i = 0; i < imageData.length; i += offset) {
|
|
27
|
-
const idx = i / offset, pos = {
|
|
28
|
-
x: idx % size.width,
|
|
29
|
-
y: Math.floor(idx / size.width),
|
|
30
|
-
};
|
|
31
|
-
pixels[pos.y] ??= [];
|
|
32
|
-
const indexesOffset = {
|
|
33
|
-
r: 0,
|
|
34
|
-
g: 1,
|
|
35
|
-
b: 2,
|
|
36
|
-
a: 3,
|
|
37
|
-
}, alphaFactor = 255, row = pixels[pos.y];
|
|
38
|
-
if (!row) {
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
row[pos.x] = {
|
|
42
|
-
r: imageData[i + indexesOffset.r] ?? defaultRgbValue,
|
|
43
|
-
g: imageData[i + indexesOffset.g] ?? defaultRgbValue,
|
|
44
|
-
b: imageData[i + indexesOffset.b] ?? defaultRgbValue,
|
|
45
|
-
a: (imageData[i + indexesOffset.a] ?? defaultAlphaValue) / alphaFactor,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
pixels,
|
|
50
|
-
width: Math.min(...pixels.map(row => row.length)),
|
|
51
|
-
height: pixels.length,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
function getImageData(src, offset) {
|
|
55
|
-
const image = new Image();
|
|
56
|
-
image.crossOrigin = "Anonymous";
|
|
57
|
-
const p = new Promise((resolve, reject) => {
|
|
58
|
-
image.onerror = reject;
|
|
59
|
-
image.onload = () => {
|
|
60
|
-
const canvas = (0, engine_1.safeDocument)().createElement("canvas");
|
|
61
|
-
canvas.width = image.width;
|
|
62
|
-
canvas.height = image.height;
|
|
63
|
-
const context = canvas.getContext("2d");
|
|
64
|
-
if (!context) {
|
|
65
|
-
reject(new Error("Could not get canvas context"));
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
context.drawImage(image, origin.x, origin.y, image.width, image.height, origin.x, origin.y, canvas.width, canvas.height);
|
|
69
|
-
resolve(getCanvasImageData(context, canvas, offset));
|
|
70
|
-
};
|
|
71
|
-
});
|
|
72
|
-
image.src = src;
|
|
73
|
-
return p;
|
|
74
|
-
}
|
|
75
|
-
function getTextData(textOptions, offset, fill) {
|
|
76
|
-
const canvas = (0, engine_1.safeDocument)().createElement("canvas"), context = canvas.getContext("2d"), { font, text, lines: linesOptions, color } = textOptions;
|
|
77
|
-
if (!text || !context) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
const lines = text.split(linesOptions.separator), fontSize = (0, engine_1.isNumber)(font.size) ? `${font.size.toString()}px` : font.size, linesData = [];
|
|
81
|
-
let maxWidth = 0, totalHeight = 0;
|
|
82
|
-
for (const line of lines) {
|
|
83
|
-
context.font = `${font.style || ""} ${font.variant || ""} ${font.weight || ""} ${fontSize} ${font.family}`;
|
|
84
|
-
const measure = context.measureText(line), lineData = {
|
|
85
|
-
measure,
|
|
86
|
-
text: line,
|
|
87
|
-
height: measure.actualBoundingBoxAscent + measure.actualBoundingBoxDescent,
|
|
88
|
-
width: measure.width,
|
|
89
|
-
};
|
|
90
|
-
maxWidth = Math.max(maxWidth || minWidth, lineData.width);
|
|
91
|
-
totalHeight += lineData.height + linesOptions.spacing;
|
|
92
|
-
linesData.push(lineData);
|
|
93
|
-
}
|
|
94
|
-
canvas.width = maxWidth;
|
|
95
|
-
canvas.height = totalHeight;
|
|
96
|
-
let currentHeight = 0;
|
|
97
|
-
for (const line of linesData) {
|
|
98
|
-
context.font = `${font.style || ""} ${font.variant || ""} ${font.weight || ""} ${fontSize} ${font.family}`;
|
|
99
|
-
if (fill) {
|
|
100
|
-
context.fillStyle = color;
|
|
101
|
-
context.fillText(line.text, origin.x, currentHeight + line.measure.actualBoundingBoxAscent);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
context.strokeStyle = color;
|
|
105
|
-
context.strokeText(line.text, origin.x, currentHeight + line.measure.actualBoundingBoxAscent);
|
|
106
|
-
}
|
|
107
|
-
currentHeight += line.height + linesOptions.spacing;
|
|
108
|
-
}
|
|
109
|
-
return getCanvasImageData(context, canvas, offset);
|
|
110
|
-
}
|
|
111
|
-
});
|