@tsparticles/shape-text 4.0.0-alpha.5 → 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/942.min.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";(this.webpackChunk_tsparticles_shape_text=this.webpackChunk_tsparticles_shape_text||[]).push([[942],{942(t,e,a){a.d(e,{TextDrawer:()=>l});var i=a(303),s=a(183),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)}}}}]);
@@ -1,17 +1,17 @@
1
- import { executeOnSingleOrMultiple, isInArray, itemFromSingleOrMultiple, loadFont, } from "@tsparticles/engine";
2
- import { drawText } from "./Utils.js";
3
- const firstItem = 0;
1
+ import { executeOnSingleOrMultiple, isInArray, itemFromSingleOrMultiple, } from "@tsparticles/engine";
2
+ import { drawText, validTypes } from "./Utils.js";
3
+ import { loadFont } from "@tsparticles/canvas-utils";
4
+ const firstIndex = 0, minLength = 0;
4
5
  export class TextDrawer {
5
- constructor() {
6
- this.validTypes = ["text", "character", "char", "multiline-text"];
7
- }
8
6
  draw(data) {
9
7
  drawText(data);
10
8
  }
11
9
  async init(container) {
12
- const options = container.actualOptions, { validTypes } = this;
10
+ const options = container.actualOptions;
13
11
  if (validTypes.find(t => isInArray(t, options.particles.shape.type))) {
14
- const shapeOptions = validTypes.map(t => options.particles.shape.options[t])[firstItem], promises = [];
12
+ const shapeOptions = validTypes
13
+ .map(t => options.particles.shape.options[t])
14
+ .find(t => !!t), promises = [];
15
15
  executeOnSingleOrMultiple(shapeOptions, shape => {
16
16
  promises.push(loadFont(shape.font, shape.weight));
17
17
  });
@@ -19,7 +19,7 @@ export class TextDrawer {
19
19
  }
20
20
  }
21
21
  particleInit(_container, particle) {
22
- if (!particle.shape || !this.validTypes.includes(particle.shape)) {
22
+ if (!particle.shape || !validTypes.includes(particle.shape)) {
23
23
  return;
24
24
  }
25
25
  const character = particle.shapeData;
@@ -27,6 +27,12 @@ export class TextDrawer {
27
27
  return;
28
28
  }
29
29
  const textData = character.value;
30
- particle.text = itemFromSingleOrMultiple(textData, particle.randomIndexData);
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);
31
37
  }
32
38
  }
package/browser/Utils.js CHANGED
@@ -1,33 +1,41 @@
1
1
  import { double, half, itemFromSingleOrMultiple } from "@tsparticles/engine";
2
+ export const validTypes = ["text", "character", "char", "multiline-text"];
3
+ const firstIndex = 0, minLength = 0;
2
4
  export function drawText(data) {
3
5
  const { context, particle, fill, stroke, radius, opacity } = data, character = particle.shapeData;
4
6
  if (!character) {
5
7
  return;
6
8
  }
7
9
  const textData = character.value;
8
- particle.text ??= itemFromSingleOrMultiple(textData, particle.randomIndexData);
9
- const text = particle.text, style = character.style, weight = character.weight, size = Math.round(radius) * double, font = character.font;
10
- const lines = text?.split("\n") ?? [];
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}"`;
19
+ const originalGlobalAlpha = context.globalAlpha;
12
20
  context.globalAlpha = opacity;
13
21
  for (let i = 0; i < lines.length; i++) {
14
22
  const currentLine = lines[i];
15
23
  if (!currentLine) {
16
24
  continue;
17
25
  }
18
- drawLine(context, currentLine, radius, opacity, i, fill, stroke);
26
+ drawTextLine(context, currentLine, size, i, fill, stroke);
19
27
  }
20
- context.globalAlpha = 1;
28
+ context.globalAlpha = originalGlobalAlpha;
21
29
  }
22
- function drawLine(context, line, radius, _opacity, index, fill, stroke) {
23
- const offsetX = line.length * radius * half, pos = {
24
- x: -offsetX,
25
- y: radius * half,
26
- }, diameter = radius * double;
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
+ };
27
35
  if (fill) {
28
- context.fillText(line, pos.x, pos.y + diameter * index);
36
+ context.fillText(line, pos.x, pos.y);
29
37
  }
30
38
  if (stroke) {
31
- context.strokeText(line, pos.x, pos.y + diameter * index);
39
+ context.strokeText(line, pos.x, pos.y);
32
40
  }
33
41
  }
package/browser/index.js CHANGED
@@ -1,7 +1,10 @@
1
+ import { validTypes } from "./Utils.js";
1
2
  export async function loadTextShape(engine) {
2
- engine.checkVersion("4.0.0-alpha.5");
3
- await engine.register(async (e) => {
4
- const { TextDrawer } = await import("./TextDrawer.js");
5
- e.addShape(new TextDrawer());
3
+ engine.checkVersion("4.0.0-beta.0");
4
+ await engine.register(e => {
5
+ e.addShape(validTypes, async () => {
6
+ const { TextDrawer } = await import("./TextDrawer.js");
7
+ return new TextDrawer();
8
+ });
6
9
  });
7
10
  }
package/cjs/TextDrawer.js CHANGED
@@ -1,17 +1,17 @@
1
- import { executeOnSingleOrMultiple, isInArray, itemFromSingleOrMultiple, loadFont, } from "@tsparticles/engine";
2
- import { drawText } from "./Utils.js";
3
- const firstItem = 0;
1
+ import { executeOnSingleOrMultiple, isInArray, itemFromSingleOrMultiple, } from "@tsparticles/engine";
2
+ import { drawText, validTypes } from "./Utils.js";
3
+ import { loadFont } from "@tsparticles/canvas-utils";
4
+ const firstIndex = 0, minLength = 0;
4
5
  export class TextDrawer {
5
- constructor() {
6
- this.validTypes = ["text", "character", "char", "multiline-text"];
7
- }
8
6
  draw(data) {
9
7
  drawText(data);
10
8
  }
11
9
  async init(container) {
12
- const options = container.actualOptions, { validTypes } = this;
10
+ const options = container.actualOptions;
13
11
  if (validTypes.find(t => isInArray(t, options.particles.shape.type))) {
14
- const shapeOptions = validTypes.map(t => options.particles.shape.options[t])[firstItem], promises = [];
12
+ const shapeOptions = validTypes
13
+ .map(t => options.particles.shape.options[t])
14
+ .find(t => !!t), promises = [];
15
15
  executeOnSingleOrMultiple(shapeOptions, shape => {
16
16
  promises.push(loadFont(shape.font, shape.weight));
17
17
  });
@@ -19,7 +19,7 @@ export class TextDrawer {
19
19
  }
20
20
  }
21
21
  particleInit(_container, particle) {
22
- if (!particle.shape || !this.validTypes.includes(particle.shape)) {
22
+ if (!particle.shape || !validTypes.includes(particle.shape)) {
23
23
  return;
24
24
  }
25
25
  const character = particle.shapeData;
@@ -27,6 +27,12 @@ export class TextDrawer {
27
27
  return;
28
28
  }
29
29
  const textData = character.value;
30
- particle.text = itemFromSingleOrMultiple(textData, particle.randomIndexData);
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);
31
37
  }
32
38
  }
package/cjs/Utils.js CHANGED
@@ -1,33 +1,41 @@
1
1
  import { double, half, itemFromSingleOrMultiple } from "@tsparticles/engine";
2
+ export const validTypes = ["text", "character", "char", "multiline-text"];
3
+ const firstIndex = 0, minLength = 0;
2
4
  export function drawText(data) {
3
5
  const { context, particle, fill, stroke, radius, opacity } = data, character = particle.shapeData;
4
6
  if (!character) {
5
7
  return;
6
8
  }
7
9
  const textData = character.value;
8
- particle.text ??= itemFromSingleOrMultiple(textData, particle.randomIndexData);
9
- const text = particle.text, style = character.style, weight = character.weight, size = Math.round(radius) * double, font = character.font;
10
- const lines = text?.split("\n") ?? [];
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}"`;
19
+ const originalGlobalAlpha = context.globalAlpha;
12
20
  context.globalAlpha = opacity;
13
21
  for (let i = 0; i < lines.length; i++) {
14
22
  const currentLine = lines[i];
15
23
  if (!currentLine) {
16
24
  continue;
17
25
  }
18
- drawLine(context, currentLine, radius, opacity, i, fill, stroke);
26
+ drawTextLine(context, currentLine, size, i, fill, stroke);
19
27
  }
20
- context.globalAlpha = 1;
28
+ context.globalAlpha = originalGlobalAlpha;
21
29
  }
22
- function drawLine(context, line, radius, _opacity, index, fill, stroke) {
23
- const offsetX = line.length * radius * half, pos = {
24
- x: -offsetX,
25
- y: radius * half,
26
- }, diameter = radius * double;
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
+ };
27
35
  if (fill) {
28
- context.fillText(line, pos.x, pos.y + diameter * index);
36
+ context.fillText(line, pos.x, pos.y);
29
37
  }
30
38
  if (stroke) {
31
- context.strokeText(line, pos.x, pos.y + diameter * index);
39
+ context.strokeText(line, pos.x, pos.y);
32
40
  }
33
41
  }
package/cjs/index.js CHANGED
@@ -1,7 +1,10 @@
1
+ import { validTypes } from "./Utils.js";
1
2
  export async function loadTextShape(engine) {
2
- engine.checkVersion("4.0.0-alpha.5");
3
- await engine.register(async (e) => {
4
- const { TextDrawer } = await import("./TextDrawer.js");
5
- e.addShape(new TextDrawer());
3
+ engine.checkVersion("4.0.0-beta.0");
4
+ await engine.register(e => {
5
+ e.addShape(validTypes, async () => {
6
+ const { TextDrawer } = await import("./TextDrawer.js");
7
+ return new TextDrawer();
8
+ });
6
9
  });
7
10
  }
@@ -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.5
7
+ * v4.0.0-beta.0
8
8
  */
9
9
  "use strict";
10
10
  /*
@@ -23,17 +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\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\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) * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.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 * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half,\n pos = {\n x: -offsetX,\n y: radius * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half\n },\n diameter = radius * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.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}");
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}");
37
27
 
38
28
  /***/ }
39
29
 
package/esm/TextDrawer.js CHANGED
@@ -1,17 +1,17 @@
1
- import { executeOnSingleOrMultiple, isInArray, itemFromSingleOrMultiple, loadFont, } from "@tsparticles/engine";
2
- import { drawText } from "./Utils.js";
3
- const firstItem = 0;
1
+ import { executeOnSingleOrMultiple, isInArray, itemFromSingleOrMultiple, } from "@tsparticles/engine";
2
+ import { drawText, validTypes } from "./Utils.js";
3
+ import { loadFont } from "@tsparticles/canvas-utils";
4
+ const firstIndex = 0, minLength = 0;
4
5
  export class TextDrawer {
5
- constructor() {
6
- this.validTypes = ["text", "character", "char", "multiline-text"];
7
- }
8
6
  draw(data) {
9
7
  drawText(data);
10
8
  }
11
9
  async init(container) {
12
- const options = container.actualOptions, { validTypes } = this;
10
+ const options = container.actualOptions;
13
11
  if (validTypes.find(t => isInArray(t, options.particles.shape.type))) {
14
- const shapeOptions = validTypes.map(t => options.particles.shape.options[t])[firstItem], promises = [];
12
+ const shapeOptions = validTypes
13
+ .map(t => options.particles.shape.options[t])
14
+ .find(t => !!t), promises = [];
15
15
  executeOnSingleOrMultiple(shapeOptions, shape => {
16
16
  promises.push(loadFont(shape.font, shape.weight));
17
17
  });
@@ -19,7 +19,7 @@ export class TextDrawer {
19
19
  }
20
20
  }
21
21
  particleInit(_container, particle) {
22
- if (!particle.shape || !this.validTypes.includes(particle.shape)) {
22
+ if (!particle.shape || !validTypes.includes(particle.shape)) {
23
23
  return;
24
24
  }
25
25
  const character = particle.shapeData;
@@ -27,6 +27,12 @@ export class TextDrawer {
27
27
  return;
28
28
  }
29
29
  const textData = character.value;
30
- particle.text = itemFromSingleOrMultiple(textData, particle.randomIndexData);
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);
31
37
  }
32
38
  }
package/esm/Utils.js CHANGED
@@ -1,33 +1,41 @@
1
1
  import { double, half, itemFromSingleOrMultiple } from "@tsparticles/engine";
2
+ export const validTypes = ["text", "character", "char", "multiline-text"];
3
+ const firstIndex = 0, minLength = 0;
2
4
  export function drawText(data) {
3
5
  const { context, particle, fill, stroke, radius, opacity } = data, character = particle.shapeData;
4
6
  if (!character) {
5
7
  return;
6
8
  }
7
9
  const textData = character.value;
8
- particle.text ??= itemFromSingleOrMultiple(textData, particle.randomIndexData);
9
- const text = particle.text, style = character.style, weight = character.weight, size = Math.round(radius) * double, font = character.font;
10
- const lines = text?.split("\n") ?? [];
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}"`;
19
+ const originalGlobalAlpha = context.globalAlpha;
12
20
  context.globalAlpha = opacity;
13
21
  for (let i = 0; i < lines.length; i++) {
14
22
  const currentLine = lines[i];
15
23
  if (!currentLine) {
16
24
  continue;
17
25
  }
18
- drawLine(context, currentLine, radius, opacity, i, fill, stroke);
26
+ drawTextLine(context, currentLine, size, i, fill, stroke);
19
27
  }
20
- context.globalAlpha = 1;
28
+ context.globalAlpha = originalGlobalAlpha;
21
29
  }
22
- function drawLine(context, line, radius, _opacity, index, fill, stroke) {
23
- const offsetX = line.length * radius * half, pos = {
24
- x: -offsetX,
25
- y: radius * half,
26
- }, diameter = radius * double;
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
+ };
27
35
  if (fill) {
28
- context.fillText(line, pos.x, pos.y + diameter * index);
36
+ context.fillText(line, pos.x, pos.y);
29
37
  }
30
38
  if (stroke) {
31
- context.strokeText(line, pos.x, pos.y + diameter * index);
39
+ context.strokeText(line, pos.x, pos.y);
32
40
  }
33
41
  }
package/esm/index.js CHANGED
@@ -1,7 +1,10 @@
1
+ import { validTypes } from "./Utils.js";
1
2
  export async function loadTextShape(engine) {
2
- engine.checkVersion("4.0.0-alpha.5");
3
- await engine.register(async (e) => {
4
- const { TextDrawer } = await import("./TextDrawer.js");
5
- e.addShape(new TextDrawer());
3
+ engine.checkVersion("4.0.0-beta.0");
4
+ await engine.register(e => {
5
+ e.addShape(validTypes, async () => {
6
+ const { TextDrawer } = await import("./TextDrawer.js");
7
+ return new TextDrawer();
8
+ });
6
9
  });
7
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/shape-text",
3
- "version": "4.0.0-alpha.5",
3
+ "version": "4.0.0-beta.0",
4
4
  "description": "tsParticles text shape",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -59,7 +59,8 @@
59
59
  "./package.json": "./package.json"
60
60
  },
61
61
  "dependencies": {
62
- "@tsparticles/engine": "4.0.0-alpha.5"
62
+ "@tsparticles/canvas-utils": "4.0.0-beta.0",
63
+ "@tsparticles/engine": "4.0.0-beta.0"
63
64
  },
64
65
  "publishConfig": {
65
66
  "access": "public"