@tsparticles/shape-text 4.0.0-alpha.2 → 4.0.0-alpha.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/13.min.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";(this.webpackChunk_tsparticles_shape_text=this.webpackChunk_tsparticles_shape_text||[]).push([[13],{13(e,t,a){a.d(t,{TextDrawer:()=>p});var i=a(303),s=a(962),l=a(425);class p{draw(e){(0,s.m)(e)}async init(e){let t=e.actualOptions;if(s.u.find(e=>(0,i.isInArray)(e,t.particles.shape.type))){let e=s.u.map(e=>t.particles.shape.options[e])[0],a=[];(0,i.executeOnSingleOrMultiple)(e,e=>{a.push((0,l.loadFont)(e.font,e.weight))}),await Promise.all(a)}}particleInit(e,t){if(!t.shape||!s.u.includes(t.shape))return;let a=t.shapeData;if(void 0===a)return;let l=a.value;t.text=(0,i.itemFromSingleOrMultiple)(l,t.randomIndexData)}}}}]);
@@ -1,15 +1,13 @@
1
- import { executeOnSingleOrMultiple, isInArray, itemFromSingleOrMultiple, loadFont, } from "@tsparticles/engine";
2
- import { drawText } from "./Utils.js";
1
+ import { executeOnSingleOrMultiple, isInArray, itemFromSingleOrMultiple, } from "@tsparticles/engine";
2
+ import { drawText, validTypes } from "./Utils.js";
3
+ import { loadFont } from "@tsparticles/canvas-utils";
3
4
  const firstItem = 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
12
  const shapeOptions = validTypes.map(t => options.particles.shape.options[t])[firstItem], promises = [];
15
13
  executeOnSingleOrMultiple(shapeOptions, shape => {
@@ -19,7 +17,7 @@ export class TextDrawer {
19
17
  }
20
18
  }
21
19
  particleInit(_container, particle) {
22
- if (!particle.shape || !this.validTypes.includes(particle.shape)) {
20
+ if (!particle.shape || !validTypes.includes(particle.shape)) {
23
21
  return;
24
22
  }
25
23
  const character = particle.shapeData;
package/browser/Utils.js CHANGED
@@ -1,5 +1,5 @@
1
- import { itemFromSingleOrMultiple } from "@tsparticles/engine";
2
- const double = 2, half = 0.5;
1
+ import { double, half, itemFromSingleOrMultiple } from "@tsparticles/engine";
2
+ export const validTypes = ["text", "character", "char", "multiline-text"];
3
3
  export function drawText(data) {
4
4
  const { context, particle, fill, stroke, radius, opacity } = data, character = particle.shapeData;
5
5
  if (!character) {
@@ -7,20 +7,20 @@ export function drawText(data) {
7
7
  }
8
8
  const textData = character.value;
9
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") ?? [];
10
+ const text = particle.text, style = character.style, weight = character.weight, size = Math.round(radius) * double, font = character.font, lines = text?.split("\n") ?? [];
12
11
  context.font = `${style} ${weight} ${size.toString()}px "${font}"`;
12
+ const originalGlobalAlpha = context.globalAlpha;
13
13
  context.globalAlpha = opacity;
14
14
  for (let i = 0; i < lines.length; i++) {
15
15
  const currentLine = lines[i];
16
16
  if (!currentLine) {
17
17
  continue;
18
18
  }
19
- drawLine(context, currentLine, radius, opacity, i, fill, stroke);
19
+ drawTextLine(context, currentLine, radius, i, fill, stroke);
20
20
  }
21
- context.globalAlpha = 1;
21
+ context.globalAlpha = originalGlobalAlpha;
22
22
  }
23
- function drawLine(context, line, radius, _opacity, index, fill, stroke) {
23
+ function drawTextLine(context, line, radius, index, fill, stroke) {
24
24
  const offsetX = line.length * radius * half, pos = {
25
25
  x: -offsetX,
26
26
  y: radius * half,
package/browser/index.js CHANGED
@@ -1,7 +1,10 @@
1
- export function loadTextShape(engine) {
2
- engine.checkVersion("4.0.0-alpha.2");
3
- engine.register(async (e) => {
4
- const { TextDrawer } = await import("./TextDrawer.js");
5
- e.addShape(new TextDrawer());
1
+ import { validTypes } from "./Utils.js";
2
+ export async function loadTextShape(engine) {
3
+ engine.checkVersion("4.0.0-alpha.20");
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,15 +1,13 @@
1
- import { executeOnSingleOrMultiple, isInArray, itemFromSingleOrMultiple, loadFont, } from "@tsparticles/engine";
2
- import { drawText } from "./Utils.js";
1
+ import { executeOnSingleOrMultiple, isInArray, itemFromSingleOrMultiple, } from "@tsparticles/engine";
2
+ import { drawText, validTypes } from "./Utils.js";
3
+ import { loadFont } from "@tsparticles/canvas-utils";
3
4
  const firstItem = 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
12
  const shapeOptions = validTypes.map(t => options.particles.shape.options[t])[firstItem], promises = [];
15
13
  executeOnSingleOrMultiple(shapeOptions, shape => {
@@ -19,7 +17,7 @@ export class TextDrawer {
19
17
  }
20
18
  }
21
19
  particleInit(_container, particle) {
22
- if (!particle.shape || !this.validTypes.includes(particle.shape)) {
20
+ if (!particle.shape || !validTypes.includes(particle.shape)) {
23
21
  return;
24
22
  }
25
23
  const character = particle.shapeData;
package/cjs/Utils.js CHANGED
@@ -1,5 +1,5 @@
1
- import { itemFromSingleOrMultiple } from "@tsparticles/engine";
2
- const double = 2, half = 0.5;
1
+ import { double, half, itemFromSingleOrMultiple } from "@tsparticles/engine";
2
+ export const validTypes = ["text", "character", "char", "multiline-text"];
3
3
  export function drawText(data) {
4
4
  const { context, particle, fill, stroke, radius, opacity } = data, character = particle.shapeData;
5
5
  if (!character) {
@@ -7,20 +7,20 @@ export function drawText(data) {
7
7
  }
8
8
  const textData = character.value;
9
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") ?? [];
10
+ const text = particle.text, style = character.style, weight = character.weight, size = Math.round(radius) * double, font = character.font, lines = text?.split("\n") ?? [];
12
11
  context.font = `${style} ${weight} ${size.toString()}px "${font}"`;
12
+ const originalGlobalAlpha = context.globalAlpha;
13
13
  context.globalAlpha = opacity;
14
14
  for (let i = 0; i < lines.length; i++) {
15
15
  const currentLine = lines[i];
16
16
  if (!currentLine) {
17
17
  continue;
18
18
  }
19
- drawLine(context, currentLine, radius, opacity, i, fill, stroke);
19
+ drawTextLine(context, currentLine, radius, i, fill, stroke);
20
20
  }
21
- context.globalAlpha = 1;
21
+ context.globalAlpha = originalGlobalAlpha;
22
22
  }
23
- function drawLine(context, line, radius, _opacity, index, fill, stroke) {
23
+ function drawTextLine(context, line, radius, index, fill, stroke) {
24
24
  const offsetX = line.length * radius * half, pos = {
25
25
  x: -offsetX,
26
26
  y: radius * half,
package/cjs/index.js CHANGED
@@ -1,7 +1,10 @@
1
- export function loadTextShape(engine) {
2
- engine.checkVersion("4.0.0-alpha.2");
3
- engine.register(async (e) => {
4
- const { TextDrawer } = await import("./TextDrawer.js");
5
- e.addShape(new TextDrawer());
1
+ import { validTypes } from "./Utils.js";
2
+ export async function loadTextShape(engine) {
3
+ engine.checkVersion("4.0.0-alpha.20");
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.2
7
+ * v4.0.0-alpha.20
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\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}");
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 firstItem = 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])[firstItem], 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 particle.text = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.itemFromSingleOrMultiple)(textData, particle.randomIndexData);\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,15 +1,13 @@
1
- import { executeOnSingleOrMultiple, isInArray, itemFromSingleOrMultiple, loadFont, } from "@tsparticles/engine";
2
- import { drawText } from "./Utils.js";
1
+ import { executeOnSingleOrMultiple, isInArray, itemFromSingleOrMultiple, } from "@tsparticles/engine";
2
+ import { drawText, validTypes } from "./Utils.js";
3
+ import { loadFont } from "@tsparticles/canvas-utils";
3
4
  const firstItem = 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
12
  const shapeOptions = validTypes.map(t => options.particles.shape.options[t])[firstItem], promises = [];
15
13
  executeOnSingleOrMultiple(shapeOptions, shape => {
@@ -19,7 +17,7 @@ export class TextDrawer {
19
17
  }
20
18
  }
21
19
  particleInit(_container, particle) {
22
- if (!particle.shape || !this.validTypes.includes(particle.shape)) {
20
+ if (!particle.shape || !validTypes.includes(particle.shape)) {
23
21
  return;
24
22
  }
25
23
  const character = particle.shapeData;
package/esm/Utils.js CHANGED
@@ -1,5 +1,5 @@
1
- import { itemFromSingleOrMultiple } from "@tsparticles/engine";
2
- const double = 2, half = 0.5;
1
+ import { double, half, itemFromSingleOrMultiple } from "@tsparticles/engine";
2
+ export const validTypes = ["text", "character", "char", "multiline-text"];
3
3
  export function drawText(data) {
4
4
  const { context, particle, fill, stroke, radius, opacity } = data, character = particle.shapeData;
5
5
  if (!character) {
@@ -7,20 +7,20 @@ export function drawText(data) {
7
7
  }
8
8
  const textData = character.value;
9
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") ?? [];
10
+ const text = particle.text, style = character.style, weight = character.weight, size = Math.round(radius) * double, font = character.font, lines = text?.split("\n") ?? [];
12
11
  context.font = `${style} ${weight} ${size.toString()}px "${font}"`;
12
+ const originalGlobalAlpha = context.globalAlpha;
13
13
  context.globalAlpha = opacity;
14
14
  for (let i = 0; i < lines.length; i++) {
15
15
  const currentLine = lines[i];
16
16
  if (!currentLine) {
17
17
  continue;
18
18
  }
19
- drawLine(context, currentLine, radius, opacity, i, fill, stroke);
19
+ drawTextLine(context, currentLine, radius, i, fill, stroke);
20
20
  }
21
- context.globalAlpha = 1;
21
+ context.globalAlpha = originalGlobalAlpha;
22
22
  }
23
- function drawLine(context, line, radius, _opacity, index, fill, stroke) {
23
+ function drawTextLine(context, line, radius, index, fill, stroke) {
24
24
  const offsetX = line.length * radius * half, pos = {
25
25
  x: -offsetX,
26
26
  y: radius * half,
package/esm/index.js CHANGED
@@ -1,7 +1,10 @@
1
- export function loadTextShape(engine) {
2
- engine.checkVersion("4.0.0-alpha.2");
3
- engine.register(async (e) => {
4
- const { TextDrawer } = await import("./TextDrawer.js");
5
- e.addShape(new TextDrawer());
1
+ import { validTypes } from "./Utils.js";
2
+ export async function loadTextShape(engine) {
3
+ engine.checkVersion("4.0.0-alpha.20");
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.2",
3
+ "version": "4.0.0-alpha.20",
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.2"
62
+ "@tsparticles/canvas-utils": "4.0.0-alpha.20",
63
+ "@tsparticles/engine": "4.0.0-alpha.20"
63
64
  },
64
65
  "publishConfig": {
65
66
  "access": "public"