@tsparticles/shape-text 4.0.0-alpha.22 → 4.0.0-alpha.24
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/13.min.js +2 -1
- package/browser/TextDrawer.js +11 -3
- package/browser/Utils.js +17 -10
- package/browser/index.js +1 -1
- package/cjs/TextDrawer.js +11 -3
- package/cjs/Utils.js +17 -10
- package/cjs/index.js +1 -1
- package/dist_browser_TextDrawer_js.js +2 -2
- package/esm/TextDrawer.js +11 -3
- package/esm/Utils.js +17 -10
- package/esm/index.js +1 -1
- package/package.json +3 -3
- package/report.html +3 -3
- package/tsparticles.shape.text.js +3 -3
- package/tsparticles.shape.text.min.js +3 -3
- package/types/ITextShape.d.ts +4 -4
- package/types/TextParticle.d.ts +2 -1
- package/umd/TextDrawer.js +11 -3
- package/umd/Utils.js +17 -10
- package/umd/index.js +1 -1
package/13.min.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";(this.webpackChunk_tsparticles_shape_text=this.webpackChunk_tsparticles_shape_text||[]).push([[13],{13(e,
|
|
1
|
+
"use strict";(this.webpackChunk_tsparticles_shape_text=this.webpackChunk_tsparticles_shape_text||[]).push([[13],{13(t,e,a){a.d(e,{TextDrawer:()=>l});var i=a(303),s=a(962),n=a(425);class l{draw(t){(0,s.m)(t)}async init(t){let e=t.actualOptions;if(s.u.find(t=>(0,i.isInArray)(t,e.particles.shape.type))){let t=s.u.map(t=>e.particles.shape.options[t]).find(t=>!!t),a=[];(0,i.executeOnSingleOrMultiple)(t,t=>{a.push((0,n.loadFont)(t.font,t.weight))}),await Promise.all(a)}}particleInit(t,e){if(!e.shape||!s.u.includes(e.shape))return;let a=e.shapeData;if(void 0===a)return;let n=a.value;n&&(e.textLines=(0,i.itemFromSingleOrMultiple)(n,e.randomIndexData)?.split(`
|
|
2
|
+
`)??[],e.maxTextLength=e.textLines.length?Math.max(...e.textLines.map(t=>t.length)):e.textLines[0]?.length??0)}}}}]);
|
package/browser/TextDrawer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { executeOnSingleOrMultiple, isInArray, itemFromSingleOrMultiple, } from "@tsparticles/engine";
|
|
2
2
|
import { drawText, validTypes } from "./Utils.js";
|
|
3
3
|
import { loadFont } from "@tsparticles/canvas-utils";
|
|
4
|
-
const
|
|
4
|
+
const firstIndex = 0, minLength = 0;
|
|
5
5
|
export class TextDrawer {
|
|
6
6
|
draw(data) {
|
|
7
7
|
drawText(data);
|
|
@@ -9,7 +9,9 @@ export class TextDrawer {
|
|
|
9
9
|
async init(container) {
|
|
10
10
|
const options = container.actualOptions;
|
|
11
11
|
if (validTypes.find(t => isInArray(t, options.particles.shape.type))) {
|
|
12
|
-
const shapeOptions = validTypes
|
|
12
|
+
const shapeOptions = validTypes
|
|
13
|
+
.map(t => options.particles.shape.options[t])
|
|
14
|
+
.find(t => !!t), promises = [];
|
|
13
15
|
executeOnSingleOrMultiple(shapeOptions, shape => {
|
|
14
16
|
promises.push(loadFont(shape.font, shape.weight));
|
|
15
17
|
});
|
|
@@ -25,6 +27,12 @@ export class TextDrawer {
|
|
|
25
27
|
return;
|
|
26
28
|
}
|
|
27
29
|
const textData = character.value;
|
|
28
|
-
|
|
30
|
+
if (!textData) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
particle.textLines = itemFromSingleOrMultiple(textData, particle.randomIndexData)?.split("\n") ?? [];
|
|
34
|
+
particle.maxTextLength = particle.textLines.length
|
|
35
|
+
? Math.max(...particle.textLines.map(t => t.length))
|
|
36
|
+
: (particle.textLines[firstIndex]?.length ?? minLength);
|
|
29
37
|
}
|
|
30
38
|
}
|
package/browser/Utils.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { double, half, itemFromSingleOrMultiple } from "@tsparticles/engine";
|
|
2
2
|
export const validTypes = ["text", "character", "char", "multiline-text"];
|
|
3
|
+
const firstIndex = 0, minLength = 0;
|
|
3
4
|
export function drawText(data) {
|
|
4
5
|
const { context, particle, fill, stroke, radius, opacity } = data, character = particle.shapeData;
|
|
5
6
|
if (!character) {
|
|
6
7
|
return;
|
|
7
8
|
}
|
|
8
9
|
const textData = character.value;
|
|
9
|
-
particle.
|
|
10
|
-
|
|
10
|
+
particle.textLines ??= itemFromSingleOrMultiple(textData, particle.randomIndexData)?.split("\n") ?? [];
|
|
11
|
+
particle.maxTextLength ??= particle.textLines.length
|
|
12
|
+
? Math.max(...particle.textLines.map(t => t.length))
|
|
13
|
+
: (particle.textLines[firstIndex]?.length ?? minLength);
|
|
14
|
+
if (!particle.textLines.length || !particle.maxTextLength) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const lines = particle.textLines, style = character.style ?? "", weight = character.weight ?? "400", font = character.font ?? "Verdana", size = (Math.round(radius) * double) / (lines.length * particle.maxTextLength);
|
|
11
18
|
context.font = `${style} ${weight} ${size.toString()}px "${font}"`;
|
|
12
19
|
const originalGlobalAlpha = context.globalAlpha;
|
|
13
20
|
context.globalAlpha = opacity;
|
|
@@ -16,19 +23,19 @@ export function drawText(data) {
|
|
|
16
23
|
if (!currentLine) {
|
|
17
24
|
continue;
|
|
18
25
|
}
|
|
19
|
-
drawTextLine(context, currentLine,
|
|
26
|
+
drawTextLine(context, currentLine, size, i, fill, stroke);
|
|
20
27
|
}
|
|
21
28
|
context.globalAlpha = originalGlobalAlpha;
|
|
22
29
|
}
|
|
23
|
-
function drawTextLine(context, line,
|
|
24
|
-
const
|
|
25
|
-
x: -
|
|
26
|
-
y:
|
|
27
|
-
}
|
|
30
|
+
function drawTextLine(context, line, size, index, fill, stroke) {
|
|
31
|
+
const pos = {
|
|
32
|
+
x: -(line.length * size * half),
|
|
33
|
+
y: size * half + index * size,
|
|
34
|
+
};
|
|
28
35
|
if (fill) {
|
|
29
|
-
context.fillText(line, pos.x, pos.y
|
|
36
|
+
context.fillText(line, pos.x, pos.y);
|
|
30
37
|
}
|
|
31
38
|
if (stroke) {
|
|
32
|
-
context.strokeText(line, pos.x, pos.y
|
|
39
|
+
context.strokeText(line, pos.x, pos.y);
|
|
33
40
|
}
|
|
34
41
|
}
|
package/browser/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { validTypes } from "./Utils.js";
|
|
2
2
|
export async function loadTextShape(engine) {
|
|
3
|
-
engine.checkVersion("4.0.0-alpha.
|
|
3
|
+
engine.checkVersion("4.0.0-alpha.24");
|
|
4
4
|
await engine.register(e => {
|
|
5
5
|
e.addShape(validTypes, async () => {
|
|
6
6
|
const { TextDrawer } = await import("./TextDrawer.js");
|
package/cjs/TextDrawer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { executeOnSingleOrMultiple, isInArray, itemFromSingleOrMultiple, } from "@tsparticles/engine";
|
|
2
2
|
import { drawText, validTypes } from "./Utils.js";
|
|
3
3
|
import { loadFont } from "@tsparticles/canvas-utils";
|
|
4
|
-
const
|
|
4
|
+
const firstIndex = 0, minLength = 0;
|
|
5
5
|
export class TextDrawer {
|
|
6
6
|
draw(data) {
|
|
7
7
|
drawText(data);
|
|
@@ -9,7 +9,9 @@ export class TextDrawer {
|
|
|
9
9
|
async init(container) {
|
|
10
10
|
const options = container.actualOptions;
|
|
11
11
|
if (validTypes.find(t => isInArray(t, options.particles.shape.type))) {
|
|
12
|
-
const shapeOptions = validTypes
|
|
12
|
+
const shapeOptions = validTypes
|
|
13
|
+
.map(t => options.particles.shape.options[t])
|
|
14
|
+
.find(t => !!t), promises = [];
|
|
13
15
|
executeOnSingleOrMultiple(shapeOptions, shape => {
|
|
14
16
|
promises.push(loadFont(shape.font, shape.weight));
|
|
15
17
|
});
|
|
@@ -25,6 +27,12 @@ export class TextDrawer {
|
|
|
25
27
|
return;
|
|
26
28
|
}
|
|
27
29
|
const textData = character.value;
|
|
28
|
-
|
|
30
|
+
if (!textData) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
particle.textLines = itemFromSingleOrMultiple(textData, particle.randomIndexData)?.split("\n") ?? [];
|
|
34
|
+
particle.maxTextLength = particle.textLines.length
|
|
35
|
+
? Math.max(...particle.textLines.map(t => t.length))
|
|
36
|
+
: (particle.textLines[firstIndex]?.length ?? minLength);
|
|
29
37
|
}
|
|
30
38
|
}
|
package/cjs/Utils.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { double, half, itemFromSingleOrMultiple } from "@tsparticles/engine";
|
|
2
2
|
export const validTypes = ["text", "character", "char", "multiline-text"];
|
|
3
|
+
const firstIndex = 0, minLength = 0;
|
|
3
4
|
export function drawText(data) {
|
|
4
5
|
const { context, particle, fill, stroke, radius, opacity } = data, character = particle.shapeData;
|
|
5
6
|
if (!character) {
|
|
6
7
|
return;
|
|
7
8
|
}
|
|
8
9
|
const textData = character.value;
|
|
9
|
-
particle.
|
|
10
|
-
|
|
10
|
+
particle.textLines ??= itemFromSingleOrMultiple(textData, particle.randomIndexData)?.split("\n") ?? [];
|
|
11
|
+
particle.maxTextLength ??= particle.textLines.length
|
|
12
|
+
? Math.max(...particle.textLines.map(t => t.length))
|
|
13
|
+
: (particle.textLines[firstIndex]?.length ?? minLength);
|
|
14
|
+
if (!particle.textLines.length || !particle.maxTextLength) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const lines = particle.textLines, style = character.style ?? "", weight = character.weight ?? "400", font = character.font ?? "Verdana", size = (Math.round(radius) * double) / (lines.length * particle.maxTextLength);
|
|
11
18
|
context.font = `${style} ${weight} ${size.toString()}px "${font}"`;
|
|
12
19
|
const originalGlobalAlpha = context.globalAlpha;
|
|
13
20
|
context.globalAlpha = opacity;
|
|
@@ -16,19 +23,19 @@ export function drawText(data) {
|
|
|
16
23
|
if (!currentLine) {
|
|
17
24
|
continue;
|
|
18
25
|
}
|
|
19
|
-
drawTextLine(context, currentLine,
|
|
26
|
+
drawTextLine(context, currentLine, size, i, fill, stroke);
|
|
20
27
|
}
|
|
21
28
|
context.globalAlpha = originalGlobalAlpha;
|
|
22
29
|
}
|
|
23
|
-
function drawTextLine(context, line,
|
|
24
|
-
const
|
|
25
|
-
x: -
|
|
26
|
-
y:
|
|
27
|
-
}
|
|
30
|
+
function drawTextLine(context, line, size, index, fill, stroke) {
|
|
31
|
+
const pos = {
|
|
32
|
+
x: -(line.length * size * half),
|
|
33
|
+
y: size * half + index * size,
|
|
34
|
+
};
|
|
28
35
|
if (fill) {
|
|
29
|
-
context.fillText(line, pos.x, pos.y
|
|
36
|
+
context.fillText(line, pos.x, pos.y);
|
|
30
37
|
}
|
|
31
38
|
if (stroke) {
|
|
32
|
-
context.strokeText(line, pos.x, pos.y
|
|
39
|
+
context.strokeText(line, pos.x, pos.y);
|
|
33
40
|
}
|
|
34
41
|
}
|
package/cjs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { validTypes } from "./Utils.js";
|
|
2
2
|
export async function loadTextShape(engine) {
|
|
3
|
-
engine.checkVersion("4.0.0-alpha.
|
|
3
|
+
engine.checkVersion("4.0.0-alpha.24");
|
|
4
4
|
await engine.register(e => {
|
|
5
5
|
e.addShape(validTypes, async () => {
|
|
6
6
|
const { TextDrawer } = await import("./TextDrawer.js");
|
|
@@ -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
|
-
* v4.0.0-alpha.
|
|
7
|
+
* v4.0.0-alpha.24
|
|
8
8
|
*/
|
|
9
9
|
"use strict";
|
|
10
10
|
/*
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
\************************************/
|
|
24
24
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
25
25
|
|
|
26
|
-
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ TextDrawer: () => (/* binding */ TextDrawer)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Utils.js */ \"./dist/browser/Utils.js\");\n/* harmony import */ var _tsparticles_canvas_utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @tsparticles/canvas-utils */ \"@tsparticles/canvas-utils\");\n\n\n\nconst
|
|
26
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ TextDrawer: () => (/* binding */ TextDrawer)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Utils.js */ \"./dist/browser/Utils.js\");\n/* harmony import */ var _tsparticles_canvas_utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @tsparticles/canvas-utils */ \"@tsparticles/canvas-utils\");\n\n\n\nconst firstIndex = 0, minLength = 0;\nclass TextDrawer {\n draw(data) {\n (0,_Utils_js__WEBPACK_IMPORTED_MODULE_1__.drawText)(data);\n }\n async init(container) {\n const options = container.actualOptions;\n if (_Utils_js__WEBPACK_IMPORTED_MODULE_1__.validTypes.find((t)=>(0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(t, options.particles.shape.type))) {\n const shapeOptions = _Utils_js__WEBPACK_IMPORTED_MODULE_1__.validTypes.map((t)=>options.particles.shape.options[t]).find((t)=>!!t), promises = [];\n (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.executeOnSingleOrMultiple)(shapeOptions, (shape)=>{\n promises.push((0,_tsparticles_canvas_utils__WEBPACK_IMPORTED_MODULE_2__.loadFont)(shape.font, shape.weight));\n });\n await Promise.all(promises);\n }\n }\n particleInit(_container, particle) {\n if (!particle.shape || !_Utils_js__WEBPACK_IMPORTED_MODULE_1__.validTypes.includes(particle.shape)) {\n return;\n }\n const character = particle.shapeData;\n if (character === undefined) {\n return;\n }\n const textData = character.value;\n if (!textData) {\n return;\n }\n particle.textLines = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.itemFromSingleOrMultiple)(textData, particle.randomIndexData)?.split(\"\\n\") ?? [];\n particle.maxTextLength = particle.textLines.length ? Math.max(...particle.textLines.map((t)=>t.length)) : particle.textLines[firstIndex]?.length ?? minLength;\n }\n}\n\n\n//# sourceURL=webpack://@tsparticles/shape-text/./dist/browser/TextDrawer.js?\n}");
|
|
27
27
|
|
|
28
28
|
/***/ }
|
|
29
29
|
|
package/esm/TextDrawer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { executeOnSingleOrMultiple, isInArray, itemFromSingleOrMultiple, } from "@tsparticles/engine";
|
|
2
2
|
import { drawText, validTypes } from "./Utils.js";
|
|
3
3
|
import { loadFont } from "@tsparticles/canvas-utils";
|
|
4
|
-
const
|
|
4
|
+
const firstIndex = 0, minLength = 0;
|
|
5
5
|
export class TextDrawer {
|
|
6
6
|
draw(data) {
|
|
7
7
|
drawText(data);
|
|
@@ -9,7 +9,9 @@ export class TextDrawer {
|
|
|
9
9
|
async init(container) {
|
|
10
10
|
const options = container.actualOptions;
|
|
11
11
|
if (validTypes.find(t => isInArray(t, options.particles.shape.type))) {
|
|
12
|
-
const shapeOptions = validTypes
|
|
12
|
+
const shapeOptions = validTypes
|
|
13
|
+
.map(t => options.particles.shape.options[t])
|
|
14
|
+
.find(t => !!t), promises = [];
|
|
13
15
|
executeOnSingleOrMultiple(shapeOptions, shape => {
|
|
14
16
|
promises.push(loadFont(shape.font, shape.weight));
|
|
15
17
|
});
|
|
@@ -25,6 +27,12 @@ export class TextDrawer {
|
|
|
25
27
|
return;
|
|
26
28
|
}
|
|
27
29
|
const textData = character.value;
|
|
28
|
-
|
|
30
|
+
if (!textData) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
particle.textLines = itemFromSingleOrMultiple(textData, particle.randomIndexData)?.split("\n") ?? [];
|
|
34
|
+
particle.maxTextLength = particle.textLines.length
|
|
35
|
+
? Math.max(...particle.textLines.map(t => t.length))
|
|
36
|
+
: (particle.textLines[firstIndex]?.length ?? minLength);
|
|
29
37
|
}
|
|
30
38
|
}
|
package/esm/Utils.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { double, half, itemFromSingleOrMultiple } from "@tsparticles/engine";
|
|
2
2
|
export const validTypes = ["text", "character", "char", "multiline-text"];
|
|
3
|
+
const firstIndex = 0, minLength = 0;
|
|
3
4
|
export function drawText(data) {
|
|
4
5
|
const { context, particle, fill, stroke, radius, opacity } = data, character = particle.shapeData;
|
|
5
6
|
if (!character) {
|
|
6
7
|
return;
|
|
7
8
|
}
|
|
8
9
|
const textData = character.value;
|
|
9
|
-
particle.
|
|
10
|
-
|
|
10
|
+
particle.textLines ??= itemFromSingleOrMultiple(textData, particle.randomIndexData)?.split("\n") ?? [];
|
|
11
|
+
particle.maxTextLength ??= particle.textLines.length
|
|
12
|
+
? Math.max(...particle.textLines.map(t => t.length))
|
|
13
|
+
: (particle.textLines[firstIndex]?.length ?? minLength);
|
|
14
|
+
if (!particle.textLines.length || !particle.maxTextLength) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const lines = particle.textLines, style = character.style ?? "", weight = character.weight ?? "400", font = character.font ?? "Verdana", size = (Math.round(radius) * double) / (lines.length * particle.maxTextLength);
|
|
11
18
|
context.font = `${style} ${weight} ${size.toString()}px "${font}"`;
|
|
12
19
|
const originalGlobalAlpha = context.globalAlpha;
|
|
13
20
|
context.globalAlpha = opacity;
|
|
@@ -16,19 +23,19 @@ export function drawText(data) {
|
|
|
16
23
|
if (!currentLine) {
|
|
17
24
|
continue;
|
|
18
25
|
}
|
|
19
|
-
drawTextLine(context, currentLine,
|
|
26
|
+
drawTextLine(context, currentLine, size, i, fill, stroke);
|
|
20
27
|
}
|
|
21
28
|
context.globalAlpha = originalGlobalAlpha;
|
|
22
29
|
}
|
|
23
|
-
function drawTextLine(context, line,
|
|
24
|
-
const
|
|
25
|
-
x: -
|
|
26
|
-
y:
|
|
27
|
-
}
|
|
30
|
+
function drawTextLine(context, line, size, index, fill, stroke) {
|
|
31
|
+
const pos = {
|
|
32
|
+
x: -(line.length * size * half),
|
|
33
|
+
y: size * half + index * size,
|
|
34
|
+
};
|
|
28
35
|
if (fill) {
|
|
29
|
-
context.fillText(line, pos.x, pos.y
|
|
36
|
+
context.fillText(line, pos.x, pos.y);
|
|
30
37
|
}
|
|
31
38
|
if (stroke) {
|
|
32
|
-
context.strokeText(line, pos.x, pos.y
|
|
39
|
+
context.strokeText(line, pos.x, pos.y);
|
|
33
40
|
}
|
|
34
41
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { validTypes } from "./Utils.js";
|
|
2
2
|
export async function loadTextShape(engine) {
|
|
3
|
-
engine.checkVersion("4.0.0-alpha.
|
|
3
|
+
engine.checkVersion("4.0.0-alpha.24");
|
|
4
4
|
await engine.register(e => {
|
|
5
5
|
e.addShape(validTypes, async () => {
|
|
6
6
|
const { TextDrawer } = await import("./TextDrawer.js");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/shape-text",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.24",
|
|
4
4
|
"description": "tsParticles text shape",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -59,8 +59,8 @@
|
|
|
59
59
|
"./package.json": "./package.json"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@tsparticles/canvas-utils": "4.0.0-alpha.
|
|
63
|
-
"@tsparticles/engine": "4.0.0-alpha.
|
|
62
|
+
"@tsparticles/canvas-utils": "4.0.0-alpha.24",
|
|
63
|
+
"@tsparticles/engine": "4.0.0-alpha.24"
|
|
64
64
|
},
|
|
65
65
|
"publishConfig": {
|
|
66
66
|
"access": "public"
|
package/report.html
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8"/>
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
6
|
-
<title>@tsparticles/shape-text [
|
|
6
|
+
<title>@tsparticles/shape-text [12 Feb 2026 at 18:50]</title>
|
|
7
7
|
<link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAABrVBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+O1foceMD///+J0/qK1Pr7/v8Xdr/9///W8P4UdL7L7P0Scr2r4Pyj3vwad8D5/f/2/f+55f3E6f34+/2H0/ojfMKpzOd0rNgQcb3F3O/j9f7c8v6g3Pz0/P/w+v/q+P7n9v6T1/uQ1vuE0vqLut/y+v+Z2fvt+f+15Pzv9fuc2/vR7v2V2Pvd6/bg9P7I6/285/2y4/yp3/zp8vk8i8kqgMT7/P31+fyv4vxGkcz6/P6/6P3j7vfS5PNnpNUxhcbO7f7F6v3O4vHK3/DA2u631Ouy0eqXweKJud5wqthfoNMMbLvY8f73+v2dxeR8sNtTmdDx9/zX6PSjyeaCtd1YnNGX2PuQveCGt95Nls42h8dLlM3F4vBtAAAAM3RSTlMAAyOx0/sKBvik8opWGBMOAe3l1snDm2E9LSb06eHcu5JpHbarfHZCN9CBb08zzkdNS0kYaptYAAAFV0lEQVRYw92X51/aYBDHHS2O2qqttVbrqNq9m+TJIAYIShBkWwqIiCgoWvfeq7Z2/s29hyQNyUcR7LveGwVyXy6XH8/9rqxglLfUPLxVduUor3h0rfp2TYvpivk37929TkG037hffoX0+peVtZQc1589rigVUdXS/ABSAyEmGIO/1XfvldSK8vs3OqB6u3m0nxmIrvgB0dj7rr7Y9IbuF68hnfFaiHA/sxqm0wciIG43P60qKv9WXWc1RXGh/mFESFABTSBi0sNAKzqet17eCtOb3kZIDwxEEU0oAIJGYxNBDhBND29e0rtXXbcpuPmED9IhEAAQ/AXEaF8EPmnrrKsv0LvWR3fg5sWDNAFZOgAgaKvZDogHNU9MFwnnYROkc56RD5CjAbQX9Ow4g7upCsvYu55aSI/Nj0H1akgKQEUM94dwK65hYRmFU9MIcH/fqJYOZYcnuJSU/waKDgTOEVaVKhwrTRP5XzgSpAITYzom7UvkhFX5VutmxeNnWDjjswTKTyfgluNDGbUpWissXhF3s7mlSml+czWkg3D0l1nNjGNjz3myOQOa1KM/jOS6ebdbAVTCi4gljHSFrviza7tOgRWcS0MOUX9zdNgag5w7rRqA44Lzw0hr1WqES36dFliSJFlh2rXIae3FFcDDgKdxrUIDePr8jGcSClV1u7A9xeN0ModY/pHMxmR1EzRh8TJiwqsHmKW0l4FCEZI+jHio+JdPPE9qwQtTRxku2D8sIeRL2LnxWSllANCQGOIiqVHAz2ye2JR0DcH+HoxDkaADLjgxjKQ+AwCX/g0+DNgdG0ukYCONAe+dbc2IAc6fwt1ARoDSezNHxV2Cmzwv3O6lDMV55edBGwGK9n1+x2F8EDfAGCxug8MhpsMEcTEAWf3rx2vZhe/LAmtIn/6apE6PN0ULKgywD9mmdxbmFl3OvD5AS5fW5zLbv/YHmcsBTjf/afDz3MaZTVCfAP9z6/Bw6ycv8EUBWJIn9zYcoAWWlW9+OzO3vkTy8H+RANLmdrpOuYWdZYEXpo+TlCJrW5EARb7fF+bWdqf3hhyZI1nWJQHgznErZhbjoEsWqi8dQNoE294aldzFurwSABL2XXMf9+H1VQGke9exw5P/AnA5Pv5ngMul7LOvO922iwACu8WkCwLCafvM4CeWPxfA8lNHcWZSoi8EwMAIciKX2Z4SWCMAa3snCZ/G4EA8D6CMLNFsGQhkkz/gQNEBbPCbWsxGUpYVu3z8IyNAknwJkfPMEhLyrdi5RTyUVACkw4GSFRNWJNEW+fgPGwHD8/JxnRuLabN4CGNRkAE23na2+VmEAUmrYymSGjMAYqH84YUIyzgzs3XC7gNgH36Vcc4zKY9o9fgPBXUAiHHwVboBHGLiX6Zcjp1f2wu4tvzZKo0ecPnDtQYDQvJXaBeNzce45Fp28ZQLrEZVuFqgBwOalArKXnW1UzlnSusQKJqKYNuz4tOnI6sZG4zanpemv+7ySU2jbA9h6uhcgpfy6G2PahirDZ6zvq6zDduMVFTKvzw8wgyEdelwY9in3XkEPs3osJuwRQ4qTkfzifndg9Gfc4pdsu82+tTnHZTBa2EAMrqr2t43pguc8tNm7JQVQ2S0ukj2d22dhXYP0/veWtwKrCkNoNimAN5+Xr/oLrxswKbVJjteWrX7eR63o4j9q0GxnaBdWgGA5VStpanIjQmEhV0/nVt5VOFUvix6awJhPcAaTEShgrG+iGyvb5a0Ndb1YGHFPEwoqAinoaykaID1o1pdPNu7XsnCKQ3R+hwWIIhGvORcJUBYXe3Xa3vq/mF/N9V13ugufMkfXn+KHsRD0B8AAAAASUVORK5CYII=" type="image/x-icon" />
|
|
8
8
|
|
|
9
9
|
<script>
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
<body>
|
|
32
32
|
<div id="app"></div>
|
|
33
33
|
<script>
|
|
34
|
-
window.chartData = [];
|
|
35
|
-
window.entrypoints = ["tsparticles.shape.text
|
|
34
|
+
window.chartData = [{"label":"tsparticles.shape.text.js","isAsset":true,"statSize":2152,"parsedSize":18310,"gzipSize":4870,"groups":[{"label":"dist/browser","path":"./dist/browser","statSize":2068,"groups":[{"id":"./dist/browser/Utils.js","label":"Utils.js","path":"./dist/browser/Utils.js","statSize":1740},{"id":"./dist/browser/index.js","label":"index.js","path":"./dist/browser/index.js","statSize":328,"parsedSize":18310,"gzipSize":4870}],"parsedSize":18310,"gzipSize":4870},{"label":"canvas-utils\",\"commonjs2\":\"@tsparticles/canvas-utils\",\"amd\":\"@tsparticles","path":"./canvas-utils\",\"commonjs2\":\"@tsparticles/canvas-utils\",\"amd\":\"@tsparticles","statSize":42,"groups":[{"id":"@tsparticles/canvas-utils","label":"canvas-utils\",\"root\":\"window\"}","path":"./canvas-utils\",\"commonjs2\":\"@tsparticles/canvas-utils\",\"amd\":\"@tsparticles/canvas-utils\",\"root\":\"window\"}","statSize":42}],"parsedSize":0,"gzipSize":0},{"label":"engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles","path":"./engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles","statSize":42,"groups":[{"id":"@tsparticles/engine","label":"engine\",\"root\":\"window\"}","path":"./engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles/engine\",\"root\":\"window\"}","statSize":42}],"parsedSize":0,"gzipSize":0}],"isInitialByEntrypoint":{"tsparticles.shape.text":true}},{"label":"dist_browser_TextDrawer_js.js","isAsset":true,"statSize":1436,"parsedSize":3621,"gzipSize":1314,"groups":[{"label":"dist/browser","path":"./dist/browser","statSize":1436,"groups":[{"id":"./dist/browser/TextDrawer.js","label":"TextDrawer.js","path":"./dist/browser/TextDrawer.js","statSize":1436,"parsedSize":2486,"gzipSize":823}],"parsedSize":2486,"gzipSize":823}],"isInitialByEntrypoint":{}}];
|
|
35
|
+
window.entrypoints = ["tsparticles.shape.text"];
|
|
36
36
|
window.defaultSizes = "parsed";
|
|
37
37
|
window.compressionAlgorithm = "gzip";
|
|
38
38
|
</script>
|
|
@@ -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
|
-
* v4.0.0-alpha.
|
|
7
|
+
* v4.0.0-alpha.24
|
|
8
8
|
*/
|
|
9
9
|
/*
|
|
10
10
|
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
@@ -54,7 +54,7 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
|
|
|
54
54
|
\*******************************/
|
|
55
55
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
56
56
|
|
|
57
|
-
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ drawText: () => (/* binding */ drawText),\n/* harmony export */ validTypes: () => (/* binding */ validTypes)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nconst validTypes = [\n \"text\",\n \"character\",\n \"char\",\n \"multiline-text\"\n];\nfunction drawText(data) {\n const { context, particle, fill, stroke, radius, opacity } = data, character = particle.shapeData;\n if (!character) {\n return;\n }\n const textData = character.value;\n particle.
|
|
57
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ drawText: () => (/* binding */ drawText),\n/* harmony export */ validTypes: () => (/* binding */ validTypes)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nconst validTypes = [\n \"text\",\n \"character\",\n \"char\",\n \"multiline-text\"\n];\nconst firstIndex = 0, minLength = 0;\nfunction drawText(data) {\n const { context, particle, fill, stroke, radius, opacity } = data, character = particle.shapeData;\n if (!character) {\n return;\n }\n const textData = character.value;\n particle.textLines ??= (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.itemFromSingleOrMultiple)(textData, particle.randomIndexData)?.split(\"\\n\") ?? [];\n particle.maxTextLength ??= particle.textLines.length ? Math.max(...particle.textLines.map((t)=>t.length)) : particle.textLines[firstIndex]?.length ?? minLength;\n if (!particle.textLines.length || !particle.maxTextLength) {\n return;\n }\n const lines = particle.textLines, style = character.style ?? \"\", weight = character.weight ?? \"400\", font = character.font ?? \"Verdana\", size = Math.round(radius) * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.double / (lines.length * particle.maxTextLength);\n context.font = `${style} ${weight} ${size.toString()}px \"${font}\"`;\n const originalGlobalAlpha = context.globalAlpha;\n context.globalAlpha = opacity;\n for(let i = 0; i < lines.length; i++){\n const currentLine = lines[i];\n if (!currentLine) {\n continue;\n }\n drawTextLine(context, currentLine, size, i, fill, stroke);\n }\n context.globalAlpha = originalGlobalAlpha;\n}\nfunction drawTextLine(context, line, size, index, fill, stroke) {\n const pos = {\n x: -(line.length * size * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half),\n y: size * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half + index * size\n };\n if (fill) {\n context.fillText(line, pos.x, pos.y);\n }\n if (stroke) {\n context.strokeText(line, pos.x, pos.y);\n }\n}\n\n\n//# sourceURL=webpack://@tsparticles/shape-text/./dist/browser/Utils.js?\n}");
|
|
58
58
|
|
|
59
59
|
/***/ },
|
|
60
60
|
|
|
@@ -64,7 +64,7 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
|
|
|
64
64
|
\*******************************/
|
|
65
65
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
66
66
|
|
|
67
|
-
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ loadTextShape: () => (/* binding */ loadTextShape)\n/* harmony export */ });\n/* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Utils.js */ \"./dist/browser/Utils.js\");\n\nasync function loadTextShape(engine) {\n engine.checkVersion(\"4.0.0-alpha.
|
|
67
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ loadTextShape: () => (/* binding */ loadTextShape)\n/* harmony export */ });\n/* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Utils.js */ \"./dist/browser/Utils.js\");\n\nasync function loadTextShape(engine) {\n engine.checkVersion(\"4.0.0-alpha.24\");\n await engine.register((e)=>{\n e.addShape(_Utils_js__WEBPACK_IMPORTED_MODULE_0__.validTypes, async ()=>{\n const { TextDrawer } = await __webpack_require__.e(/*! import() */ \"dist_browser_TextDrawer_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./TextDrawer.js */ \"./dist/browser/TextDrawer.js\"));\n return new TextDrawer();\n });\n });\n}\n\n\n//# sourceURL=webpack://@tsparticles/shape-text/./dist/browser/index.js?\n}");
|
|
68
68
|
|
|
69
69
|
/***/ }
|
|
70
70
|
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"),require("@tsparticles/canvas-utils"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine","@tsparticles/canvas-utils"],t);else{var r="object"==typeof exports?t(require("@tsparticles/engine"),require("@tsparticles/canvas-utils")):t(e.window,e.window);for(var
|
|
2
|
-
`)??[];t.font=`${u} ${
|
|
3
|
-
(`+a+": "+i+")",
|
|
1
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"),require("@tsparticles/canvas-utils"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine","@tsparticles/canvas-utils"],t);else{var r="object"==typeof exports?t(require("@tsparticles/engine"),require("@tsparticles/canvas-utils")):t(e.window,e.window);for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(this,(e,t)=>(()=>{"use strict";var r,n,a,i={425(e){e.exports=t},303(t){t.exports=e},962(e,t,r){r.d(t,{m:()=>i,u:()=>a});var n=r(303);let a=["text","character","char","multiline-text"];function i(e){let{context:t,particle:r,fill:a,stroke:i,radius:o,opacity:l}=e,s=r.shapeData;if(!s)return;let p=s.value;if(r.textLines??=(0,n.itemFromSingleOrMultiple)(p,r.randomIndexData)?.split(`
|
|
2
|
+
`)??[],r.maxTextLength??=r.textLines.length?Math.max(...r.textLines.map(e=>e.length)):r.textLines[0]?.length??0,!r.textLines.length||!r.maxTextLength)return;let c=r.textLines,u=s.style??"",h=s.weight??"400",d=s.font??"Verdana",f=Math.round(o)*n.double/(c.length*r.maxTextLength);t.font=`${u} ${h} ${f.toString()}px "${d}"`;let g=t.globalAlpha;t.globalAlpha=l;for(let e=0;e<c.length;e++){let r=c[e];r&&function(e,t,r,a,i,o){let l={x:-(t.length*r*n.half),y:r*n.half+a*r};i&&e.fillText(t,l.x,l.y),o&&e.strokeText(t,l.x,l.y)}(t,r,f,e,a,i)}t.globalAlpha=g}}},o={};function l(e){var t=o[e];if(void 0!==t)return t.exports;var r=o[e]={exports:{}};return i[e](r,r.exports,l),r.exports}l.m=i,l.d=(e,t)=>{for(var r in t)l.o(t,r)&&!l.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},l.f={},l.e=e=>Promise.all(Object.keys(l.f).reduce((t,r)=>(l.f[r](e,t),t),[])),l.u=e=>""+e+".min.js",l.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),l.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),s={},l.l=(e,t,r,n)=>{if(s[e])return void s[e].push(t);if(void 0!==r)for(var a,i,o=document.getElementsByTagName("script"),p=0;p<o.length;p++){var c=o[p];if(c.getAttribute("src")==e||c.getAttribute("data-webpack")=="@tsparticles/shape-text:"+r){a=c;break}}a||(i=!0,(a=document.createElement("script")).charset="utf-8",l.nc&&a.setAttribute("nonce",l.nc),a.setAttribute("data-webpack","@tsparticles/shape-text:"+r),a.src=e),s[e]=[t];var u=(t,r)=>{a.onerror=a.onload=null,clearTimeout(h);var n=s[e];if(delete s[e],a.parentNode&&a.parentNode.removeChild(a),n&&n.forEach(e=>e(r)),t)return t(r)},h=setTimeout(u.bind(null,void 0,{type:"timeout",target:a}),12e4);a.onerror=u.bind(null,a.onerror),a.onload=u.bind(null,a.onload),i&&document.head.appendChild(a)},l.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},l.g.importScripts&&(p=l.g.location+"");var s,p,c=l.g.document;if(!p&&c&&(c.currentScript&&"SCRIPT"===c.currentScript.tagName.toUpperCase()&&(p=c.currentScript.src),!p)){var u=c.getElementsByTagName("script");if(u.length)for(var h=u.length-1;h>-1&&(!p||!/^http(s?):/.test(p));)p=u[h--].src}if(!p)throw Error("Automatic publicPath is not supported in this browser");l.p=p=p.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),r={973:0},l.f.j=(e,t)=>{var n=l.o(r,e)?r[e]:void 0;if(0!==n)if(n)t.push(n[2]);else{var a=new Promise((t,a)=>n=r[e]=[t,a]);t.push(n[2]=a);var i=l.p+l.u(e),o=Error();l.l(i,t=>{if(l.o(r,e)&&(0!==(n=r[e])&&(r[e]=void 0),n)){var a=t&&("load"===t.type?"missing":t.type),i=t&&t.target&&t.target.src;o.message="Loading chunk "+e+` failed.
|
|
3
|
+
(`+a+": "+i+")",o.name="ChunkLoadError",o.type=a,o.request=i,n[1](o)}},"chunk-"+e,e)}},n=(e,t)=>{var n,a,[i,o,s]=t,p=0;if(i.some(e=>0!==r[e])){for(n in o)l.o(o,n)&&(l.m[n]=o[n]);s&&s(l)}for(e&&e(t);p<i.length;p++)a=i[p],l.o(r,a)&&r[a]&&r[a][0](),r[a]=0},(a=this.webpackChunk_tsparticles_shape_text=this.webpackChunk_tsparticles_shape_text||[]).forEach(n.bind(null,0)),a.push=n.bind(null,a.push.bind(a));var d={};l.r(d),l.d(d,{loadTextShape:()=>g});var f=l(962);async function g(e){e.checkVersion("4.0.0-alpha.24"),await e.register(e=>{e.addShape(f.u,async()=>{let{TextDrawer:e}=await l.e(13).then(l.bind(l,13));return new e})})}return d})());
|
package/types/ITextShape.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IShapeValues, SingleOrMultiple } from "@tsparticles/engine";
|
|
2
2
|
export interface ITextShape extends IShapeValues {
|
|
3
|
-
font
|
|
4
|
-
style
|
|
5
|
-
value
|
|
6
|
-
weight
|
|
3
|
+
font?: string;
|
|
4
|
+
style?: string;
|
|
5
|
+
value?: SingleOrMultiple<string>;
|
|
6
|
+
weight?: string;
|
|
7
7
|
}
|
package/types/TextParticle.d.ts
CHANGED
package/umd/TextDrawer.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
const engine_1 = require("@tsparticles/engine");
|
|
14
14
|
const Utils_js_1 = require("./Utils.js");
|
|
15
15
|
const canvas_utils_1 = require("@tsparticles/canvas-utils");
|
|
16
|
-
const
|
|
16
|
+
const firstIndex = 0, minLength = 0;
|
|
17
17
|
class TextDrawer {
|
|
18
18
|
draw(data) {
|
|
19
19
|
(0, Utils_js_1.drawText)(data);
|
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
async init(container) {
|
|
22
22
|
const options = container.actualOptions;
|
|
23
23
|
if (Utils_js_1.validTypes.find(t => (0, engine_1.isInArray)(t, options.particles.shape.type))) {
|
|
24
|
-
const shapeOptions = Utils_js_1.validTypes
|
|
24
|
+
const shapeOptions = Utils_js_1.validTypes
|
|
25
|
+
.map(t => options.particles.shape.options[t])
|
|
26
|
+
.find(t => !!t), promises = [];
|
|
25
27
|
(0, engine_1.executeOnSingleOrMultiple)(shapeOptions, shape => {
|
|
26
28
|
promises.push((0, canvas_utils_1.loadFont)(shape.font, shape.weight));
|
|
27
29
|
});
|
|
@@ -37,7 +39,13 @@
|
|
|
37
39
|
return;
|
|
38
40
|
}
|
|
39
41
|
const textData = character.value;
|
|
40
|
-
|
|
42
|
+
if (!textData) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
particle.textLines = (0, engine_1.itemFromSingleOrMultiple)(textData, particle.randomIndexData)?.split("\n") ?? [];
|
|
46
|
+
particle.maxTextLength = particle.textLines.length
|
|
47
|
+
? Math.max(...particle.textLines.map(t => t.length))
|
|
48
|
+
: (particle.textLines[firstIndex]?.length ?? minLength);
|
|
41
49
|
}
|
|
42
50
|
}
|
|
43
51
|
exports.TextDrawer = TextDrawer;
|
package/umd/Utils.js
CHANGED
|
@@ -13,14 +13,21 @@
|
|
|
13
13
|
exports.drawText = drawText;
|
|
14
14
|
const engine_1 = require("@tsparticles/engine");
|
|
15
15
|
exports.validTypes = ["text", "character", "char", "multiline-text"];
|
|
16
|
+
const firstIndex = 0, minLength = 0;
|
|
16
17
|
function drawText(data) {
|
|
17
18
|
const { context, particle, fill, stroke, radius, opacity } = data, character = particle.shapeData;
|
|
18
19
|
if (!character) {
|
|
19
20
|
return;
|
|
20
21
|
}
|
|
21
22
|
const textData = character.value;
|
|
22
|
-
particle.
|
|
23
|
-
|
|
23
|
+
particle.textLines ??= (0, engine_1.itemFromSingleOrMultiple)(textData, particle.randomIndexData)?.split("\n") ?? [];
|
|
24
|
+
particle.maxTextLength ??= particle.textLines.length
|
|
25
|
+
? Math.max(...particle.textLines.map(t => t.length))
|
|
26
|
+
: (particle.textLines[firstIndex]?.length ?? minLength);
|
|
27
|
+
if (!particle.textLines.length || !particle.maxTextLength) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const lines = particle.textLines, style = character.style ?? "", weight = character.weight ?? "400", font = character.font ?? "Verdana", size = (Math.round(radius) * engine_1.double) / (lines.length * particle.maxTextLength);
|
|
24
31
|
context.font = `${style} ${weight} ${size.toString()}px "${font}"`;
|
|
25
32
|
const originalGlobalAlpha = context.globalAlpha;
|
|
26
33
|
context.globalAlpha = opacity;
|
|
@@ -29,20 +36,20 @@
|
|
|
29
36
|
if (!currentLine) {
|
|
30
37
|
continue;
|
|
31
38
|
}
|
|
32
|
-
drawTextLine(context, currentLine,
|
|
39
|
+
drawTextLine(context, currentLine, size, i, fill, stroke);
|
|
33
40
|
}
|
|
34
41
|
context.globalAlpha = originalGlobalAlpha;
|
|
35
42
|
}
|
|
36
|
-
function drawTextLine(context, line,
|
|
37
|
-
const
|
|
38
|
-
x: -
|
|
39
|
-
y:
|
|
40
|
-
}
|
|
43
|
+
function drawTextLine(context, line, size, index, fill, stroke) {
|
|
44
|
+
const pos = {
|
|
45
|
+
x: -(line.length * size * engine_1.half),
|
|
46
|
+
y: size * engine_1.half + index * size,
|
|
47
|
+
};
|
|
41
48
|
if (fill) {
|
|
42
|
-
context.fillText(line, pos.x, pos.y
|
|
49
|
+
context.fillText(line, pos.x, pos.y);
|
|
43
50
|
}
|
|
44
51
|
if (stroke) {
|
|
45
|
-
context.strokeText(line, pos.x, pos.y
|
|
52
|
+
context.strokeText(line, pos.x, pos.y);
|
|
46
53
|
}
|
|
47
54
|
}
|
|
48
55
|
});
|
package/umd/index.js
CHANGED
|
@@ -46,7 +46,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
46
46
|
exports.loadTextShape = loadTextShape;
|
|
47
47
|
const Utils_js_1 = require("./Utils.js");
|
|
48
48
|
async function loadTextShape(engine) {
|
|
49
|
-
engine.checkVersion("4.0.0-alpha.
|
|
49
|
+
engine.checkVersion("4.0.0-alpha.24");
|
|
50
50
|
await engine.register(e => {
|
|
51
51
|
e.addShape(Utils_js_1.validTypes, async () => {
|
|
52
52
|
const { TextDrawer } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./TextDrawer.js"))) : new Promise((resolve_1, reject_1) => { require(["./TextDrawer.js"], resolve_1, reject_1); }).then(__importStar));
|