@tsparticles/shape-text 3.9.0 → 4.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/90.min.js +2 -0
- package/90.min.js.LICENSE.txt +1 -0
- package/browser/TextDrawer.js +3 -7
- package/browser/Utils.js +12 -16
- package/browser/index.js +6 -4
- package/cjs/ITextShape.js +1 -2
- package/cjs/TextDrawer.js +11 -19
- package/cjs/TextParticle.js +1 -2
- package/cjs/Utils.js +14 -21
- package/cjs/index.js +6 -7
- package/dist_browser_TextDrawer_js.js +40 -0
- package/esm/TextDrawer.js +3 -7
- package/esm/Utils.js +12 -16
- package/esm/index.js +6 -4
- package/package.json +4 -3
- package/report.html +5 -4
- package/tsparticles.shape.text.js +209 -40
- package/tsparticles.shape.text.min.js +1 -1
- package/tsparticles.shape.text.min.js.LICENSE.txt +1 -1
- package/types/TextDrawer.d.ts +1 -1
- package/types/index.d.ts +1 -1
- package/umd/TextDrawer.js +3 -7
- package/umd/Utils.js +12 -16
- package/umd/index.js +41 -5
package/90.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see 90.min.js.LICENSE.txt */
|
|
2
|
+
(this.webpackChunk_tsparticles_shape_text=this.webpackChunk_tsparticles_shape_text||[]).push([[90],{90(t,e,a){a.d(e,{TextDrawer:()=>n});var i=a(303);function s(t,e,a,i,s,n,l){const r={x:-(e.length*a*.5),y:.5*a},o=2*a;n&&t.fillText(e,r.x,r.y+o*s),l&&t.strokeText(e,r.x,r.y+o*s)}class n{constructor(){this.validTypes=["text","character","char","multiline-text"]}draw(t){!function(t){const{context:e,particle:a,fill:n,stroke:l,radius:r,opacity:o}=t,p=a.shapeData;if(!p)return;const c=p.value;a.text??=(0,i.itemFromSingleOrMultiple)(c,a.randomIndexData);const h=a.text,u=p.style,x=p.weight,d=2*Math.round(r),f=p.font,y=h?.split("\n")??[];e.font=`${u} ${x} ${d.toString()}px "${f}"`,e.globalAlpha=o;for(let t=0;t<y.length;t++){const a=y[t];a&&s(e,a,r,0,t,n,l)}e.globalAlpha=1}(t)}async init(t){const e=t.actualOptions,{validTypes:a}=this;if(a.find((t=>(0,i.isInArray)(t,e.particles.shape.type)))){const t=a.map((t=>e.particles.shape.options[t]))[0],s=[];(0,i.executeOnSingleOrMultiple)(t,(t=>{s.push((0,i.loadFont)(t.font,t.weight))})),await Promise.all(s)}}particleInit(t,e){if(!e.shape||!this.validTypes.includes(e.shape))return;const a=e.shapeData;if(void 0===a)return;const s=a.value;e.text=(0,i.itemFromSingleOrMultiple)(s,e.randomIndexData)}}}}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles Text Shape v4.0.0-alpha.0 by Matteo Bruni */
|
package/browser/TextDrawer.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { executeOnSingleOrMultiple, isInArray, itemFromSingleOrMultiple, loadFont, } from "@tsparticles/engine";
|
|
2
2
|
import { drawText } from "./Utils.js";
|
|
3
|
+
const firstItem = 0;
|
|
3
4
|
export class TextDrawer {
|
|
4
5
|
constructor() {
|
|
5
6
|
this.validTypes = ["text", "character", "char", "multiline-text"];
|
|
@@ -10,16 +11,14 @@ export class TextDrawer {
|
|
|
10
11
|
async init(container) {
|
|
11
12
|
const options = container.actualOptions, { validTypes } = this;
|
|
12
13
|
if (validTypes.find(t => isInArray(t, options.particles.shape.type))) {
|
|
13
|
-
const shapeOptions = validTypes
|
|
14
|
-
.map(t => options.particles.shape.options[t])
|
|
15
|
-
.find(t => !!t), promises = [];
|
|
14
|
+
const shapeOptions = validTypes.map(t => options.particles.shape.options[t])[firstItem], promises = [];
|
|
16
15
|
executeOnSingleOrMultiple(shapeOptions, shape => {
|
|
17
16
|
promises.push(loadFont(shape.font, shape.weight));
|
|
18
17
|
});
|
|
19
18
|
await Promise.all(promises);
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
|
-
particleInit(
|
|
21
|
+
particleInit(_container, particle) {
|
|
23
22
|
if (!particle.shape || !this.validTypes.includes(particle.shape)) {
|
|
24
23
|
return;
|
|
25
24
|
}
|
|
@@ -28,9 +27,6 @@ export class TextDrawer {
|
|
|
28
27
|
return;
|
|
29
28
|
}
|
|
30
29
|
const textData = character.value;
|
|
31
|
-
if (textData === undefined) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
30
|
particle.text = itemFromSingleOrMultiple(textData, particle.randomIndexData);
|
|
35
31
|
}
|
|
36
32
|
}
|
package/browser/Utils.js
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
import { itemFromSingleOrMultiple } from "@tsparticles/engine";
|
|
2
2
|
const double = 2, half = 0.5;
|
|
3
3
|
export function drawText(data) {
|
|
4
|
-
const { context, particle, radius, opacity } = data, character = particle.shapeData;
|
|
4
|
+
const { context, particle, fill, stroke, radius, opacity } = data, character = particle.shapeData;
|
|
5
5
|
if (!character) {
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
8
8
|
const textData = character.value;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
particle.text = itemFromSingleOrMultiple(textData, particle.randomIndexData);
|
|
14
|
-
}
|
|
15
|
-
const text = particle.text, style = character.style ?? "", weight = character.weight ?? "400", size = Math.round(radius) * double, font = character.font ?? "Verdana", fill = particle.shapeFill;
|
|
16
|
-
const lines = text?.split("\n");
|
|
17
|
-
if (!lines) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
context.font = `${style} ${weight} ${size}px "${font}"`;
|
|
9
|
+
particle.text ??= itemFromSingleOrMultiple(textData, particle.randomIndexData);
|
|
10
|
+
const text = particle.text, style = character.style, weight = character.weight, size = Math.round(radius) * double, font = character.font;
|
|
11
|
+
const lines = text?.split("\n") ?? [];
|
|
12
|
+
context.font = `${style} ${weight} ${size.toString()}px "${font}"`;
|
|
21
13
|
context.globalAlpha = opacity;
|
|
22
14
|
for (let i = 0; i < lines.length; i++) {
|
|
23
|
-
|
|
15
|
+
const currentLine = lines[i];
|
|
16
|
+
if (!currentLine) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
drawLine(context, currentLine, radius, opacity, i, fill, stroke);
|
|
24
20
|
}
|
|
25
21
|
context.globalAlpha = 1;
|
|
26
22
|
}
|
|
27
|
-
function drawLine(context, line, radius,
|
|
23
|
+
function drawLine(context, line, radius, _opacity, index, fill, stroke) {
|
|
28
24
|
const offsetX = line.length * radius * half, pos = {
|
|
29
25
|
x: -offsetX,
|
|
30
26
|
y: radius * half,
|
|
@@ -32,7 +28,7 @@ function drawLine(context, line, radius, opacity, index, fill) {
|
|
|
32
28
|
if (fill) {
|
|
33
29
|
context.fillText(line, pos.x, pos.y + diameter * index);
|
|
34
30
|
}
|
|
35
|
-
|
|
31
|
+
if (stroke) {
|
|
36
32
|
context.strokeText(line, pos.x, pos.y + diameter * index);
|
|
37
33
|
}
|
|
38
34
|
}
|
package/browser/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
engine.
|
|
4
|
-
|
|
1
|
+
export function loadTextShape(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.0");
|
|
3
|
+
engine.register(async (e) => {
|
|
4
|
+
const { TextDrawer } = await import("./TextDrawer.js");
|
|
5
|
+
e.addShape(new TextDrawer());
|
|
6
|
+
});
|
|
5
7
|
}
|
package/cjs/ITextShape.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/cjs/TextDrawer.js
CHANGED
|
@@ -1,28 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const Utils_js_1 = require("./Utils.js");
|
|
6
|
-
class TextDrawer {
|
|
1
|
+
import { executeOnSingleOrMultiple, isInArray, itemFromSingleOrMultiple, loadFont, } from "@tsparticles/engine";
|
|
2
|
+
import { drawText } from "./Utils.js";
|
|
3
|
+
const firstItem = 0;
|
|
4
|
+
export class TextDrawer {
|
|
7
5
|
constructor() {
|
|
8
6
|
this.validTypes = ["text", "character", "char", "multiline-text"];
|
|
9
7
|
}
|
|
10
8
|
draw(data) {
|
|
11
|
-
|
|
9
|
+
drawText(data);
|
|
12
10
|
}
|
|
13
11
|
async init(container) {
|
|
14
12
|
const options = container.actualOptions, { validTypes } = this;
|
|
15
|
-
if (validTypes.find(t =>
|
|
16
|
-
const shapeOptions = validTypes
|
|
17
|
-
|
|
18
|
-
.
|
|
19
|
-
(0, engine_1.executeOnSingleOrMultiple)(shapeOptions, shape => {
|
|
20
|
-
promises.push((0, engine_1.loadFont)(shape.font, shape.weight));
|
|
13
|
+
if (validTypes.find(t => isInArray(t, options.particles.shape.type))) {
|
|
14
|
+
const shapeOptions = validTypes.map(t => options.particles.shape.options[t])[firstItem], promises = [];
|
|
15
|
+
executeOnSingleOrMultiple(shapeOptions, shape => {
|
|
16
|
+
promises.push(loadFont(shape.font, shape.weight));
|
|
21
17
|
});
|
|
22
18
|
await Promise.all(promises);
|
|
23
19
|
}
|
|
24
20
|
}
|
|
25
|
-
particleInit(
|
|
21
|
+
particleInit(_container, particle) {
|
|
26
22
|
if (!particle.shape || !this.validTypes.includes(particle.shape)) {
|
|
27
23
|
return;
|
|
28
24
|
}
|
|
@@ -31,10 +27,6 @@ class TextDrawer {
|
|
|
31
27
|
return;
|
|
32
28
|
}
|
|
33
29
|
const textData = character.value;
|
|
34
|
-
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
particle.text = (0, engine_1.itemFromSingleOrMultiple)(textData, particle.randomIndexData);
|
|
30
|
+
particle.text = itemFromSingleOrMultiple(textData, particle.randomIndexData);
|
|
38
31
|
}
|
|
39
32
|
}
|
|
40
|
-
exports.TextDrawer = TextDrawer;
|
package/cjs/TextParticle.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/cjs/Utils.js
CHANGED
|
@@ -1,33 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.drawText = drawText;
|
|
4
|
-
const engine_1 = require("@tsparticles/engine");
|
|
1
|
+
import { itemFromSingleOrMultiple } from "@tsparticles/engine";
|
|
5
2
|
const double = 2, half = 0.5;
|
|
6
|
-
function drawText(data) {
|
|
7
|
-
const { context, particle, radius, opacity } = data, character = particle.shapeData;
|
|
3
|
+
export function drawText(data) {
|
|
4
|
+
const { context, particle, fill, stroke, radius, opacity } = data, character = particle.shapeData;
|
|
8
5
|
if (!character) {
|
|
9
6
|
return;
|
|
10
7
|
}
|
|
11
8
|
const textData = character.value;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
particle.text = (0, engine_1.itemFromSingleOrMultiple)(textData, particle.randomIndexData);
|
|
17
|
-
}
|
|
18
|
-
const text = particle.text, style = character.style ?? "", weight = character.weight ?? "400", size = Math.round(radius) * double, font = character.font ?? "Verdana", fill = particle.shapeFill;
|
|
19
|
-
const lines = text?.split("\n");
|
|
20
|
-
if (!lines) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
context.font = `${style} ${weight} ${size}px "${font}"`;
|
|
9
|
+
particle.text ??= itemFromSingleOrMultiple(textData, particle.randomIndexData);
|
|
10
|
+
const text = particle.text, style = character.style, weight = character.weight, size = Math.round(radius) * double, font = character.font;
|
|
11
|
+
const lines = text?.split("\n") ?? [];
|
|
12
|
+
context.font = `${style} ${weight} ${size.toString()}px "${font}"`;
|
|
24
13
|
context.globalAlpha = opacity;
|
|
25
14
|
for (let i = 0; i < lines.length; i++) {
|
|
26
|
-
|
|
15
|
+
const currentLine = lines[i];
|
|
16
|
+
if (!currentLine) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
drawLine(context, currentLine, radius, opacity, i, fill, stroke);
|
|
27
20
|
}
|
|
28
21
|
context.globalAlpha = 1;
|
|
29
22
|
}
|
|
30
|
-
function drawLine(context, line, radius,
|
|
23
|
+
function drawLine(context, line, radius, _opacity, index, fill, stroke) {
|
|
31
24
|
const offsetX = line.length * radius * half, pos = {
|
|
32
25
|
x: -offsetX,
|
|
33
26
|
y: radius * half,
|
|
@@ -35,7 +28,7 @@ function drawLine(context, line, radius, opacity, index, fill) {
|
|
|
35
28
|
if (fill) {
|
|
36
29
|
context.fillText(line, pos.x, pos.y + diameter * index);
|
|
37
30
|
}
|
|
38
|
-
|
|
31
|
+
if (stroke) {
|
|
39
32
|
context.strokeText(line, pos.x, pos.y + diameter * index);
|
|
40
33
|
}
|
|
41
34
|
}
|
package/cjs/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
await engine.addShape(new TextDrawer_js_1.TextDrawer(), refresh);
|
|
1
|
+
export function loadTextShape(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.0");
|
|
3
|
+
engine.register(async (e) => {
|
|
4
|
+
const { TextDrawer } = await import("./TextDrawer.js");
|
|
5
|
+
e.addShape(new TextDrawer());
|
|
6
|
+
});
|
|
8
7
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Author : Matteo Bruni
|
|
3
|
+
* MIT license: https://opensource.org/licenses/MIT
|
|
4
|
+
* Demo / Generator : https://particles.js.org/
|
|
5
|
+
* GitHub : https://www.github.com/matteobruni/tsparticles
|
|
6
|
+
* How to use? : Check the GitHub README
|
|
7
|
+
* v4.0.0-alpha.0
|
|
8
|
+
*/
|
|
9
|
+
"use strict";
|
|
10
|
+
/*
|
|
11
|
+
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
12
|
+
* This devtool is neither made for production nor for readable output files.
|
|
13
|
+
* It uses "eval()" calls to create a separate source file in the browser devtools.
|
|
14
|
+
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
|
|
15
|
+
* or disable the default devtool with "devtool: false".
|
|
16
|
+
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
|
|
17
|
+
*/
|
|
18
|
+
(this["webpackChunk_tsparticles_shape_text"] = this["webpackChunk_tsparticles_shape_text"] || []).push([["dist_browser_TextDrawer_js"],{
|
|
19
|
+
|
|
20
|
+
/***/ "./dist/browser/TextDrawer.js"
|
|
21
|
+
/*!************************************!*\
|
|
22
|
+
!*** ./dist/browser/TextDrawer.js ***!
|
|
23
|
+
\************************************/
|
|
24
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
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\n\nconst firstItem = 0;\nclass TextDrawer {\n constructor() {\n this.validTypes = [\"text\", \"character\", \"char\", \"multiline-text\"];\n }\n draw(data) {\n (0,_Utils_js__WEBPACK_IMPORTED_MODULE_1__.drawText)(data);\n }\n async init(container) {\n const options = container.actualOptions,\n {\n validTypes\n } = this;\n if (validTypes.find(t => (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(t, options.particles.shape.type))) {\n const shapeOptions = validTypes.map(t => options.particles.shape.options[t])[firstItem],\n promises = [];\n (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.executeOnSingleOrMultiple)(shapeOptions, shape => {\n promises.push((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.loadFont)(shape.font, shape.weight));\n });\n await Promise.all(promises);\n }\n }\n particleInit(_container, particle) {\n if (!particle.shape || !this.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 particle.text = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.itemFromSingleOrMultiple)(textData, particle.randomIndexData);\n }\n}\n\n//# sourceURL=webpack://@tsparticles/shape-text/./dist/browser/TextDrawer.js?\n}");
|
|
27
|
+
|
|
28
|
+
/***/ },
|
|
29
|
+
|
|
30
|
+
/***/ "./dist/browser/Utils.js"
|
|
31
|
+
/*!*******************************!*\
|
|
32
|
+
!*** ./dist/browser/Utils.js ***!
|
|
33
|
+
\*******************************/
|
|
34
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
35
|
+
|
|
36
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ drawText: () => (/* binding */ drawText)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nconst double = 2,\n half = 0.5;\nfunction drawText(data) {\n const {\n context,\n particle,\n fill,\n stroke,\n radius,\n opacity\n } = data,\n character = particle.shapeData;\n if (!character) {\n return;\n }\n const textData = character.value;\n particle.text ??= (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.itemFromSingleOrMultiple)(textData, particle.randomIndexData);\n const text = particle.text,\n style = character.style,\n weight = character.weight,\n size = Math.round(radius) * double,\n font = character.font;\n const lines = text?.split(\"\\n\") ?? [];\n context.font = `${style} ${weight} ${size.toString()}px \"${font}\"`;\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 drawLine(context, currentLine, radius, opacity, i, fill, stroke);\n }\n context.globalAlpha = 1;\n}\nfunction drawLine(context, line, radius, _opacity, index, fill, stroke) {\n const offsetX = line.length * radius * half,\n pos = {\n x: -offsetX,\n y: radius * half\n },\n diameter = radius * double;\n if (fill) {\n context.fillText(line, pos.x, pos.y + diameter * index);\n }\n if (stroke) {\n context.strokeText(line, pos.x, pos.y + diameter * index);\n }\n}\n\n//# sourceURL=webpack://@tsparticles/shape-text/./dist/browser/Utils.js?\n}");
|
|
37
|
+
|
|
38
|
+
/***/ }
|
|
39
|
+
|
|
40
|
+
}]);
|
package/esm/TextDrawer.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { executeOnSingleOrMultiple, isInArray, itemFromSingleOrMultiple, loadFont, } from "@tsparticles/engine";
|
|
2
2
|
import { drawText } from "./Utils.js";
|
|
3
|
+
const firstItem = 0;
|
|
3
4
|
export class TextDrawer {
|
|
4
5
|
constructor() {
|
|
5
6
|
this.validTypes = ["text", "character", "char", "multiline-text"];
|
|
@@ -10,16 +11,14 @@ export class TextDrawer {
|
|
|
10
11
|
async init(container) {
|
|
11
12
|
const options = container.actualOptions, { validTypes } = this;
|
|
12
13
|
if (validTypes.find(t => isInArray(t, options.particles.shape.type))) {
|
|
13
|
-
const shapeOptions = validTypes
|
|
14
|
-
.map(t => options.particles.shape.options[t])
|
|
15
|
-
.find(t => !!t), promises = [];
|
|
14
|
+
const shapeOptions = validTypes.map(t => options.particles.shape.options[t])[firstItem], promises = [];
|
|
16
15
|
executeOnSingleOrMultiple(shapeOptions, shape => {
|
|
17
16
|
promises.push(loadFont(shape.font, shape.weight));
|
|
18
17
|
});
|
|
19
18
|
await Promise.all(promises);
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
|
-
particleInit(
|
|
21
|
+
particleInit(_container, particle) {
|
|
23
22
|
if (!particle.shape || !this.validTypes.includes(particle.shape)) {
|
|
24
23
|
return;
|
|
25
24
|
}
|
|
@@ -28,9 +27,6 @@ export class TextDrawer {
|
|
|
28
27
|
return;
|
|
29
28
|
}
|
|
30
29
|
const textData = character.value;
|
|
31
|
-
if (textData === undefined) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
30
|
particle.text = itemFromSingleOrMultiple(textData, particle.randomIndexData);
|
|
35
31
|
}
|
|
36
32
|
}
|
package/esm/Utils.js
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
import { itemFromSingleOrMultiple } from "@tsparticles/engine";
|
|
2
2
|
const double = 2, half = 0.5;
|
|
3
3
|
export function drawText(data) {
|
|
4
|
-
const { context, particle, radius, opacity } = data, character = particle.shapeData;
|
|
4
|
+
const { context, particle, fill, stroke, radius, opacity } = data, character = particle.shapeData;
|
|
5
5
|
if (!character) {
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
8
8
|
const textData = character.value;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
particle.text = itemFromSingleOrMultiple(textData, particle.randomIndexData);
|
|
14
|
-
}
|
|
15
|
-
const text = particle.text, style = character.style ?? "", weight = character.weight ?? "400", size = Math.round(radius) * double, font = character.font ?? "Verdana", fill = particle.shapeFill;
|
|
16
|
-
const lines = text?.split("\n");
|
|
17
|
-
if (!lines) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
context.font = `${style} ${weight} ${size}px "${font}"`;
|
|
9
|
+
particle.text ??= itemFromSingleOrMultiple(textData, particle.randomIndexData);
|
|
10
|
+
const text = particle.text, style = character.style, weight = character.weight, size = Math.round(radius) * double, font = character.font;
|
|
11
|
+
const lines = text?.split("\n") ?? [];
|
|
12
|
+
context.font = `${style} ${weight} ${size.toString()}px "${font}"`;
|
|
21
13
|
context.globalAlpha = opacity;
|
|
22
14
|
for (let i = 0; i < lines.length; i++) {
|
|
23
|
-
|
|
15
|
+
const currentLine = lines[i];
|
|
16
|
+
if (!currentLine) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
drawLine(context, currentLine, radius, opacity, i, fill, stroke);
|
|
24
20
|
}
|
|
25
21
|
context.globalAlpha = 1;
|
|
26
22
|
}
|
|
27
|
-
function drawLine(context, line, radius,
|
|
23
|
+
function drawLine(context, line, radius, _opacity, index, fill, stroke) {
|
|
28
24
|
const offsetX = line.length * radius * half, pos = {
|
|
29
25
|
x: -offsetX,
|
|
30
26
|
y: radius * half,
|
|
@@ -32,7 +28,7 @@ function drawLine(context, line, radius, opacity, index, fill) {
|
|
|
32
28
|
if (fill) {
|
|
33
29
|
context.fillText(line, pos.x, pos.y + diameter * index);
|
|
34
30
|
}
|
|
35
|
-
|
|
31
|
+
if (stroke) {
|
|
36
32
|
context.strokeText(line, pos.x, pos.y + diameter * index);
|
|
37
33
|
}
|
|
38
34
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
engine.
|
|
4
|
-
|
|
1
|
+
export function loadTextShape(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.0");
|
|
3
|
+
engine.register(async (e) => {
|
|
4
|
+
const { TextDrawer } = await import("./TextDrawer.js");
|
|
5
|
+
e.addShape(new TextDrawer());
|
|
6
|
+
});
|
|
5
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/shape-text",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.0",
|
|
4
4
|
"description": "tsParticles text shape",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -59,9 +59,10 @@
|
|
|
59
59
|
"./package.json": "./package.json"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@tsparticles/engine": "
|
|
62
|
+
"@tsparticles/engine": "4.0.0-alpha.0"
|
|
63
63
|
},
|
|
64
64
|
"publishConfig": {
|
|
65
65
|
"access": "public"
|
|
66
|
-
}
|
|
66
|
+
},
|
|
67
|
+
"type": "module"
|
|
67
68
|
}
|