@tsparticles/shape-text 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/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.8");
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.8");
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.8
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.8");
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.8",
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.8"
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"
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 [23 Jan 2026 at 23:49]</title>
6
+ <title>@tsparticles/shape-text [19 Mar 2026 at 13:59]</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>
@@ -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.8
7
+ * v4.0.0-beta.0
8
8
  */
9
9
  /*
10
10
  * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
@@ -16,25 +16,25 @@
16
16
  */
17
17
  (function webpackUniversalModuleDefinition(root, factory) {
18
18
  if(typeof exports === 'object' && typeof module === 'object')
19
- module.exports = factory(require("@tsparticles/engine"));
19
+ module.exports = factory(require("@tsparticles/engine"), require("@tsparticles/canvas-utils"));
20
20
  else if(typeof define === 'function' && define.amd)
21
- define(["@tsparticles/engine"], factory);
21
+ define(["@tsparticles/engine", "@tsparticles/canvas-utils"], factory);
22
22
  else {
23
- var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]);
23
+ var a = typeof exports === 'object' ? factory(require("@tsparticles/engine"), require("@tsparticles/canvas-utils")) : factory(root["window"], root["window"]);
24
24
  for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
25
25
  }
26
- })(this, (__WEBPACK_EXTERNAL_MODULE__tsparticles_engine__) => {
26
+ })(this, (__WEBPACK_EXTERNAL_MODULE__tsparticles_engine__, __WEBPACK_EXTERNAL_MODULE__tsparticles_canvas_utils__) => {
27
27
  return /******/ (() => { // webpackBootstrap
28
28
  /******/ "use strict";
29
29
  /******/ var __webpack_modules__ = ({
30
30
 
31
- /***/ "./dist/browser/index.js"
32
- /*!*******************************!*\
33
- !*** ./dist/browser/index.js ***!
34
- \*******************************/
35
- (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
31
+ /***/ "@tsparticles/canvas-utils"
32
+ /*!***************************************************************************************************************************************************!*\
33
+ !*** external {"commonjs":"@tsparticles/canvas-utils","commonjs2":"@tsparticles/canvas-utils","amd":"@tsparticles/canvas-utils","root":"window"} ***!
34
+ \***************************************************************************************************************************************************/
35
+ (module) {
36
36
 
37
- eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ loadTextShape: () => (/* binding */ loadTextShape)\n/* harmony export */ });\nasync function loadTextShape(engine) {\n engine.checkVersion(\"4.0.0-alpha.8\");\n await engine.register(async e => {\n const {\n TextDrawer\n } = await __webpack_require__.e(/*! import() */ \"dist_browser_TextDrawer_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./TextDrawer.js */ \"./dist/browser/TextDrawer.js\"));\n e.addShape(new TextDrawer());\n });\n}\n\n//# sourceURL=webpack://@tsparticles/shape-text/./dist/browser/index.js?\n}");
37
+ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_canvas_utils__;
38
38
 
39
39
  /***/ },
40
40
 
@@ -46,6 +46,26 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
46
46
 
47
47
  module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
48
48
 
49
+ /***/ },
50
+
51
+ /***/ "./dist/browser/Utils.js"
52
+ /*!*******************************!*\
53
+ !*** ./dist/browser/Utils.js ***!
54
+ \*******************************/
55
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
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];\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
+
59
+ /***/ },
60
+
61
+ /***/ "./dist/browser/index.js"
62
+ /*!*******************************!*\
63
+ !*** ./dist/browser/index.js ***!
64
+ \*******************************/
65
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
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-beta.0\");\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
+
49
69
  /***/ }
50
70
 
51
71
  /******/ });
@@ -60,12 +80,6 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
60
80
  /******/ if (cachedModule !== undefined) {
61
81
  /******/ return cachedModule.exports;
62
82
  /******/ }
63
- /******/ // Check if module exists (development only)
64
- /******/ if (__webpack_modules__[moduleId] === undefined) {
65
- /******/ var e = new Error("Cannot find module '" + moduleId + "'");
66
- /******/ e.code = 'MODULE_NOT_FOUND';
67
- /******/ throw e;
68
- /******/ }
69
83
  /******/ // Create a new module (and put it into the cache)
70
84
  /******/ var module = __webpack_module_cache__[moduleId] = {
71
85
  /******/ // no module.id needed
@@ -74,6 +88,12 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
74
88
  /******/ };
75
89
  /******/
76
90
  /******/ // Execute the module function
91
+ /******/ if (!(moduleId in __webpack_modules__)) {
92
+ /******/ delete __webpack_module_cache__[moduleId];
93
+ /******/ var e = new Error("Cannot find module '" + moduleId + "'");
94
+ /******/ e.code = 'MODULE_NOT_FOUND';
95
+ /******/ throw e;
96
+ /******/ }
77
97
  /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
78
98
  /******/
79
99
  /******/ // Return the exports of the module
@@ -118,6 +138,18 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
118
138
  /******/ };
119
139
  /******/ })();
120
140
  /******/
141
+ /******/ /* webpack/runtime/global */
142
+ /******/ (() => {
143
+ /******/ __webpack_require__.g = (function() {
144
+ /******/ if (typeof globalThis === 'object') return globalThis;
145
+ /******/ try {
146
+ /******/ return this || new Function('return this')();
147
+ /******/ } catch (e) {
148
+ /******/ if (typeof window === 'object') return window;
149
+ /******/ }
150
+ /******/ })();
151
+ /******/ })();
152
+ /******/
121
153
  /******/ /* webpack/runtime/hasOwnProperty shorthand */
122
154
  /******/ (() => {
123
155
  /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
@@ -182,8 +214,8 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
182
214
  /******/ /* webpack/runtime/publicPath */
183
215
  /******/ (() => {
184
216
  /******/ var scriptUrl;
185
- /******/ if (globalThis.importScripts) scriptUrl = globalThis.location + "";
186
- /******/ var document = globalThis.document;
217
+ /******/ if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + "";
218
+ /******/ var document = __webpack_require__.g.document;
187
219
  /******/ if (!scriptUrl && document) {
188
220
  /******/ if (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT')
189
221
  /******/ scriptUrl = document.currentScript.src;
@@ -1,2 +1,3 @@
1
- /*! For license information please see tsparticles.shape.text.min.js.LICENSE.txt */
2
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],t);else{var r="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var o in r)("object"==typeof exports?exports:e)[o]=r[o]}}(this,(e=>(()=>{var t,r,o={303(t){t.exports=e}},a={};function n(e){var t=a[e];if(void 0!==t)return t.exports;var r=a[e]={exports:{}};return o[e](r,r.exports,n),r.exports}n.m=o,n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.f={},n.e=e=>Promise.all(Object.keys(n.f).reduce(((t,r)=>(n.f[r](e,t),t)),[])),n.u=e=>e+".min.js",n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),t={},r="@tsparticles/shape-text:",n.l=(e,o,a,i)=>{if(t[e])t[e].push(o);else{var s,p;if(void 0!==a)for(var l=document.getElementsByTagName("script"),c=0;c<l.length;c++){var u=l[c];if(u.getAttribute("src")==e||u.getAttribute("data-webpack")==r+a){s=u;break}}s||(p=!0,(s=document.createElement("script")).charset="utf-8",n.nc&&s.setAttribute("nonce",n.nc),s.setAttribute("data-webpack",r+a),s.src=e),t[e]=[o];var d=(r,o)=>{s.onerror=s.onload=null,clearTimeout(f);var a=t[e];if(delete t[e],s.parentNode&&s.parentNode.removeChild(s),a&&a.forEach((e=>e(o))),r)return r(o)},f=setTimeout(d.bind(null,void 0,{type:"timeout",target:s}),12e4);s.onerror=d.bind(null,s.onerror),s.onload=d.bind(null,s.onload),p&&document.head.appendChild(s)}},n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;globalThis.importScripts&&(e=globalThis.location+"");var t=globalThis.document;if(!e&&t&&(t.currentScript&&"SCRIPT"===t.currentScript.tagName.toUpperCase()&&(e=t.currentScript.src),!e)){var r=t.getElementsByTagName("script");if(r.length)for(var o=r.length-1;o>-1&&(!e||!/^http(s?):/.test(e));)e=r[o--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),n.p=e})(),(()=>{var e={973:0};n.f.j=(t,r)=>{var o=n.o(e,t)?e[t]:void 0;if(0!==o)if(o)r.push(o[2]);else{var a=new Promise(((r,a)=>o=e[t]=[r,a]));r.push(o[2]=a);var i=n.p+n.u(t),s=new Error;n.l(i,(r=>{if(n.o(e,t)&&(0!==(o=e[t])&&(e[t]=void 0),o)){var a=r&&("load"===r.type?"missing":r.type),i=r&&r.target&&r.target.src;s.message="Loading chunk "+t+" failed.\n("+a+": "+i+")",s.name="ChunkLoadError",s.type=a,s.request=i,o[1](s)}}),"chunk-"+t,t)}};var t=(t,r)=>{var o,a,[i,s,p]=r,l=0;if(i.some((t=>0!==e[t]))){for(o in s)n.o(s,o)&&(n.m[o]=s[o]);if(p)p(n)}for(t&&t(r);l<i.length;l++)a=i[l],n.o(e,a)&&e[a]&&e[a][0](),e[a]=0},r=this.webpackChunk_tsparticles_shape_text=this.webpackChunk_tsparticles_shape_text||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();var i={};async function s(e){e.checkVersion("4.0.0-alpha.8"),await e.register((async e=>{const{TextDrawer:t}=await n.e(21).then(n.bind(n,21));e.addShape(new t)}))}return n.r(i),n.d(i,{loadTextShape:()=>s}),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},183(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(183);async function g(e){e.checkVersion("4.0.0-beta.0"),await e.register(e=>{e.addShape(f.u,async()=>{let{TextDrawer:e}=await l.e(942).then(l.bind(l,942));return new e})})}return d})());
@@ -1,7 +1,7 @@
1
1
  import type { IShapeValues, SingleOrMultiple } from "@tsparticles/engine";
2
2
  export interface ITextShape extends IShapeValues {
3
- font: string;
4
- style: string;
5
- value: SingleOrMultiple<string>;
6
- weight: string;
3
+ font?: string;
4
+ style?: string;
5
+ value?: SingleOrMultiple<string>;
6
+ weight?: string;
7
7
  }
@@ -1,7 +1,6 @@
1
1
  import { type Container, type IShapeDrawData, type IShapeDrawer } from "@tsparticles/engine";
2
2
  import type { TextParticle } from "./TextParticle.js";
3
3
  export declare class TextDrawer implements IShapeDrawer<TextParticle> {
4
- readonly validTypes: readonly ["text", "character", "char", "multiline-text"];
5
4
  draw(data: IShapeDrawData<TextParticle>): void;
6
5
  init(container: Container): Promise<void>;
7
6
  particleInit(_container: Container, particle: TextParticle): void;
@@ -1,4 +1,5 @@
1
1
  import type { Particle } from "@tsparticles/engine";
2
2
  export interface TextParticle extends Particle {
3
- text?: string;
3
+ maxTextLength?: number;
4
+ textLines?: string[];
4
5
  }
package/types/Utils.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import { type IShapeDrawData } from "@tsparticles/engine";
2
2
  import type { TextParticle } from "./TextParticle.js";
3
+ export declare const validTypes: string[];
3
4
  export declare function drawText(data: IShapeDrawData<TextParticle>): void;
package/umd/TextDrawer.js CHANGED
@@ -4,7 +4,7 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "@tsparticles/engine", "./Utils.js"], factory);
7
+ define(["require", "exports", "@tsparticles/engine", "./Utils.js", "@tsparticles/canvas-utils"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
@@ -12,26 +12,26 @@
12
12
  exports.TextDrawer = void 0;
13
13
  const engine_1 = require("@tsparticles/engine");
14
14
  const Utils_js_1 = require("./Utils.js");
15
- const firstItem = 0;
15
+ const canvas_utils_1 = require("@tsparticles/canvas-utils");
16
+ const firstIndex = 0, minLength = 0;
16
17
  class TextDrawer {
17
- constructor() {
18
- this.validTypes = ["text", "character", "char", "multiline-text"];
19
- }
20
18
  draw(data) {
21
19
  (0, Utils_js_1.drawText)(data);
22
20
  }
23
21
  async init(container) {
24
- const options = container.actualOptions, { validTypes } = this;
25
- if (validTypes.find(t => (0, engine_1.isInArray)(t, options.particles.shape.type))) {
26
- const shapeOptions = validTypes.map(t => options.particles.shape.options[t])[firstItem], promises = [];
22
+ const options = container.actualOptions;
23
+ if (Utils_js_1.validTypes.find(t => (0, engine_1.isInArray)(t, options.particles.shape.type))) {
24
+ const shapeOptions = Utils_js_1.validTypes
25
+ .map(t => options.particles.shape.options[t])
26
+ .find(t => !!t), promises = [];
27
27
  (0, engine_1.executeOnSingleOrMultiple)(shapeOptions, shape => {
28
- promises.push((0, engine_1.loadFont)(shape.font, shape.weight));
28
+ promises.push((0, canvas_utils_1.loadFont)(shape.font, shape.weight));
29
29
  });
30
30
  await Promise.all(promises);
31
31
  }
32
32
  }
33
33
  particleInit(_container, particle) {
34
- if (!particle.shape || !this.validTypes.includes(particle.shape)) {
34
+ if (!particle.shape || !Utils_js_1.validTypes.includes(particle.shape)) {
35
35
  return;
36
36
  }
37
37
  const character = particle.shapeData;
@@ -39,7 +39,13 @@
39
39
  return;
40
40
  }
41
41
  const textData = character.value;
42
- particle.text = (0, engine_1.itemFromSingleOrMultiple)(textData, particle.randomIndexData);
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);
43
49
  }
44
50
  }
45
51
  exports.TextDrawer = TextDrawer;
package/umd/Utils.js CHANGED
@@ -9,38 +9,47 @@
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.validTypes = void 0;
12
13
  exports.drawText = drawText;
13
14
  const engine_1 = require("@tsparticles/engine");
15
+ exports.validTypes = ["text", "character", "char", "multiline-text"];
16
+ const firstIndex = 0, minLength = 0;
14
17
  function drawText(data) {
15
18
  const { context, particle, fill, stroke, radius, opacity } = data, character = particle.shapeData;
16
19
  if (!character) {
17
20
  return;
18
21
  }
19
22
  const textData = character.value;
20
- particle.text ??= (0, engine_1.itemFromSingleOrMultiple)(textData, particle.randomIndexData);
21
- const text = particle.text, style = character.style, weight = character.weight, size = Math.round(radius) * engine_1.double, font = character.font;
22
- const lines = text?.split("\n") ?? [];
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);
23
31
  context.font = `${style} ${weight} ${size.toString()}px "${font}"`;
32
+ const originalGlobalAlpha = context.globalAlpha;
24
33
  context.globalAlpha = opacity;
25
34
  for (let i = 0; i < lines.length; i++) {
26
35
  const currentLine = lines[i];
27
36
  if (!currentLine) {
28
37
  continue;
29
38
  }
30
- drawLine(context, currentLine, radius, opacity, i, fill, stroke);
39
+ drawTextLine(context, currentLine, size, i, fill, stroke);
31
40
  }
32
- context.globalAlpha = 1;
41
+ context.globalAlpha = originalGlobalAlpha;
33
42
  }
34
- function drawLine(context, line, radius, _opacity, index, fill, stroke) {
35
- const offsetX = line.length * radius * engine_1.half, pos = {
36
- x: -offsetX,
37
- y: radius * engine_1.half,
38
- }, diameter = radius * engine_1.double;
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
+ };
39
48
  if (fill) {
40
- context.fillText(line, pos.x, pos.y + diameter * index);
49
+ context.fillText(line, pos.x, pos.y);
41
50
  }
42
51
  if (stroke) {
43
- context.strokeText(line, pos.x, pos.y + diameter * index);
52
+ context.strokeText(line, pos.x, pos.y);
44
53
  }
45
54
  }
46
55
  });
package/umd/index.js CHANGED
@@ -37,18 +37,21 @@ var __importStar = (this && this.__importStar) || (function () {
37
37
  if (v !== undefined) module.exports = v;
38
38
  }
39
39
  else if (typeof define === "function" && define.amd) {
40
- define(["require", "exports"], factory);
40
+ define(["require", "exports", "./Utils.js"], factory);
41
41
  }
42
42
  })(function (require, exports) {
43
43
  "use strict";
44
44
  var __syncRequire = typeof module === "object" && typeof module.exports === "object";
45
45
  Object.defineProperty(exports, "__esModule", { value: true });
46
46
  exports.loadTextShape = loadTextShape;
47
+ const Utils_js_1 = require("./Utils.js");
47
48
  async function loadTextShape(engine) {
48
- engine.checkVersion("4.0.0-alpha.8");
49
- await engine.register(async (e) => {
50
- 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));
51
- e.addShape(new TextDrawer());
49
+ engine.checkVersion("4.0.0-beta.0");
50
+ await engine.register(e => {
51
+ e.addShape(Utils_js_1.validTypes, async () => {
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));
53
+ return new TextDrawer();
54
+ });
52
55
  });
53
56
  }
54
57
  });
package/21.min.js DELETED
@@ -1,2 +0,0 @@
1
- /*! For license information please see 21.min.js.LICENSE.txt */
2
- (this.webpackChunk_tsparticles_shape_text=this.webpackChunk_tsparticles_shape_text||[]).push([[21],{21(t,e,a){a.d(e,{TextDrawer:()=>s});var i=a(303);function l(t,e,a,l,s,n,o){const r={x:-(e.length*a*i.half),y:a*i.half},p=a*i.double;n&&t.fillText(e,r.x,r.y+p*s),o&&t.strokeText(e,r.x,r.y+p*s)}class s{constructor(){this.validTypes=["text","character","char","multiline-text"]}draw(t){!function(t){const{context:e,particle:a,fill:s,stroke:n,radius:o,opacity:r}=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=Math.round(o)*i.double,f=p.font,y=h?.split("\n")??[];e.font=`${u} ${x} ${d.toString()}px "${f}"`,e.globalAlpha=r;for(let t=0;t<y.length;t++){const a=y[t];a&&l(e,a,o,0,t,s,n)}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],l=[];(0,i.executeOnSingleOrMultiple)(t,(t=>{l.push((0,i.loadFont)(t.font,t.weight))})),await Promise.all(l)}}particleInit(t,e){if(!e.shape||!this.validTypes.includes(e.shape))return;const a=e.shapeData;if(void 0===a)return;const l=a.value;e.text=(0,i.itemFromSingleOrMultiple)(l,e.randomIndexData)}}}}]);
@@ -1 +0,0 @@
1
- /*! tsParticles Text Shape v4.0.0-alpha.8 by Matteo Bruni */
@@ -1 +0,0 @@
1
- /*! tsParticles Text Shape v4.0.0-alpha.8 by Matteo Bruni */