@tsparticles/shape-text 3.0.0-beta.3 → 3.0.0-beta.5

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.
@@ -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
- * v3.0.0-beta.3
7
+ * v3.0.0-beta.5
8
8
  */
9
9
  (function webpackUniversalModuleDefinition(root, factory) {
10
10
  if(typeof exports === 'object' && typeof module === 'object')
@@ -98,8 +98,23 @@ __webpack_require__.d(__webpack_exports__, {
98
98
  var engine_root_window_ = __webpack_require__(533);
99
99
  ;// CONCATENATED MODULE: ./dist/browser/TextDrawer.js
100
100
 
101
- const validTypes = ["text", "character", "char"];
101
+ const validTypes = ["text", "character", "char", "multiline-text"];
102
102
  class TextDrawer {
103
+ constructor() {
104
+ this._drawLine = (context, line, radius, opacity, index, fill) => {
105
+ const offsetX = line.length * radius / 2,
106
+ pos = {
107
+ x: -offsetX,
108
+ y: radius / 2
109
+ },
110
+ diameter = radius * 2;
111
+ if (fill) {
112
+ context.fillText(line, pos.x, pos.y + diameter * index);
113
+ } else {
114
+ context.strokeText(line, pos.x, pos.y + diameter * index);
115
+ }
116
+ };
117
+ }
103
118
  draw(data) {
104
119
  const {
105
120
  context,
@@ -108,7 +123,7 @@ class TextDrawer {
108
123
  opacity
109
124
  } = data,
110
125
  character = particle.shapeData;
111
- if (character === undefined) {
126
+ if (!character) {
112
127
  return;
113
128
  }
114
129
  const textData = character.value;
@@ -123,24 +138,18 @@ class TextDrawer {
123
138
  weight = character.weight ?? "400",
124
139
  size = Math.round(radius) * 2,
125
140
  font = character.font ?? "Verdana",
126
- fill = particle.fill,
127
- offsetX = text.length * radius / 2;
141
+ fill = particle.shapeFill;
142
+ const lines = text?.split("\n");
143
+ if (!lines) {
144
+ return;
145
+ }
128
146
  context.font = `${style} ${weight} ${size}px "${font}"`;
129
- const pos = {
130
- x: -offsetX,
131
- y: radius / 2
132
- };
133
147
  context.globalAlpha = opacity;
134
- if (fill) {
135
- context.fillText(text, pos.x, pos.y);
136
- } else {
137
- context.strokeText(text, pos.x, pos.y);
148
+ for (let i = 0; i < lines.length; i++) {
149
+ this._drawLine(context, lines[i], radius, opacity, i, fill);
138
150
  }
139
151
  context.globalAlpha = 1;
140
152
  }
141
- getSidesCount() {
142
- return 12;
143
- }
144
153
  async init(container) {
145
154
  const options = container.actualOptions;
146
155
  if (validTypes.find(t => (0,engine_root_window_.isInArray)(t, options.particles.shape.type))) {
@@ -1,2 +1,2 @@
1
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 o="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var r in o)("object"==typeof exports?exports:e)[r]=o[r]}}(this,(e=>(()=>{"use strict";var t={533:t=>{t.exports=e}},o={};function r(e){var n=o[e];if(void 0!==n)return n.exports;var a=o[e]={exports:{}};return t[e](a,a.exports,r),a.exports}r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{r.r(n),r.d(n,{loadTextShape:()=>a});var e=r(533);const t=["text","character","char"];class o{draw(t){const{context:o,particle:r,radius:n,opacity:a}=t,i=r.shapeData;if(void 0===i)return;const s=i.value;if(void 0===s)return;void 0===r.text&&(r.text=(0,e.itemFromSingleOrMultiple)(s,r.randomIndexData));const l=r.text,p=i.style??"",c=i.weight??"400",d=2*Math.round(n),u=i.font??"Verdana",f=r.fill,x=l.length*n/2;o.font=`${p} ${c} ${d}px "${u}"`;const y={x:-x,y:n/2};o.globalAlpha=a,f?o.fillText(l,y.x,y.y):o.strokeText(l,y.x,y.y),o.globalAlpha=1}getSidesCount(){return 12}async init(o){const r=o.actualOptions;if(t.find((t=>(0,e.isInArray)(t,r.particles.shape.type)))){const o=t.map((e=>r.particles.shape.options[e])).find((e=>!!e)),n=[];(0,e.executeOnSingleOrMultiple)(o,(t=>{n.push((0,e.loadFont)(t.font,t.weight))})),await Promise.all(n)}}particleInit(o,r){if(!r.shape||!t.includes(r.shape))return;const n=r.shapeData;if(void 0===n)return;const a=n.value;void 0!==a&&(r.text=(0,e.itemFromSingleOrMultiple)(a,r.randomIndexData))}}async function a(e,r=!0){await e.addShape(t,new o,r)}})(),n})()));
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=>(()=>{"use strict";var t={533:t=>{t.exports=e}},r={};function o(e){var n=r[e];if(void 0!==n)return n.exports;var i=r[e]={exports:{}};return t[e](i,i.exports,o),i.exports}o.d=(e,t)=>{for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{o.r(n),o.d(n,{loadTextShape:()=>i});var e=o(533);const t=["text","character","char","multiline-text"];class r{constructor(){this._drawLine=(e,t,r,o,n,i)=>{const a={x:-(t.length*r/2),y:r/2},s=2*r;i?e.fillText(t,a.x,a.y+s*n):e.strokeText(t,a.x,a.y+s*n)}}draw(t){const{context:r,particle:o,radius:n,opacity:i}=t,a=o.shapeData;if(!a)return;const s=a.value;if(void 0===s)return;void 0===o.text&&(o.text=(0,e.itemFromSingleOrMultiple)(s,o.randomIndexData));const l=o.text,p=a.style??"",c=a.weight??"400",d=2*Math.round(n),f=a.font??"Verdana",u=o.shapeFill,x=l?.split("\n");if(x){r.font=`${p} ${c} ${d}px "${f}"`,r.globalAlpha=i;for(let e=0;e<x.length;e++)this._drawLine(r,x[e],n,i,e,u);r.globalAlpha=1}}async init(r){const o=r.actualOptions;if(t.find((t=>(0,e.isInArray)(t,o.particles.shape.type)))){const r=t.map((e=>o.particles.shape.options[e])).find((e=>!!e)),n=[];(0,e.executeOnSingleOrMultiple)(r,(t=>{n.push((0,e.loadFont)(t.font,t.weight))})),await Promise.all(n)}}particleInit(r,o){if(!o.shape||!t.includes(o.shape))return;const n=o.shapeData;if(void 0===n)return;const i=n.value;void 0!==i&&(o.text=(0,e.itemFromSingleOrMultiple)(i,o.randomIndexData))}}async function i(e,o=!0){await e.addShape(t,new r,o)}})(),n})()));
@@ -1 +1 @@
1
- /*! tsParticles Text Shape v3.0.0-beta.3 by Matteo Bruni */
1
+ /*! tsParticles Text Shape v3.0.0-beta.5 by Matteo Bruni */
@@ -1,5 +1,5 @@
1
1
  import type { IShapeValues, SingleOrMultiple } from "@tsparticles/engine";
2
- export interface ICharacterShape extends IShapeValues {
2
+ export interface ITextShape extends IShapeValues {
3
3
  font: string;
4
4
  style: string;
5
5
  value: SingleOrMultiple<string>;
@@ -3,7 +3,7 @@ import type { TextParticle } from "./TextParticle.js";
3
3
  export declare const validTypes: string[];
4
4
  export declare class TextDrawer implements IShapeDrawer<TextParticle> {
5
5
  draw(data: IShapeDrawData<TextParticle>): void;
6
- getSidesCount(): number;
7
6
  init(container: Container): Promise<void>;
8
7
  particleInit(container: Container, particle: TextParticle): void;
8
+ private readonly _drawLine;
9
9
  }
package/umd/TextDrawer.js CHANGED
@@ -11,11 +11,25 @@
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.TextDrawer = exports.validTypes = void 0;
13
13
  const engine_1 = require("@tsparticles/engine");
14
- exports.validTypes = ["text", "character", "char"];
14
+ exports.validTypes = ["text", "character", "char", "multiline-text"];
15
15
  class TextDrawer {
16
+ constructor() {
17
+ this._drawLine = (context, line, radius, opacity, index, fill) => {
18
+ const offsetX = (line.length * radius) / 2, pos = {
19
+ x: -offsetX,
20
+ y: radius / 2,
21
+ }, diameter = radius * 2;
22
+ if (fill) {
23
+ context.fillText(line, pos.x, pos.y + diameter * index);
24
+ }
25
+ else {
26
+ context.strokeText(line, pos.x, pos.y + diameter * index);
27
+ }
28
+ };
29
+ }
16
30
  draw(data) {
17
31
  const { context, particle, radius, opacity } = data, character = particle.shapeData;
18
- if (character === undefined) {
32
+ if (!character) {
19
33
  return;
20
34
  }
21
35
  const textData = character.value;
@@ -25,24 +39,18 @@
25
39
  if (particle.text === undefined) {
26
40
  particle.text = (0, engine_1.itemFromSingleOrMultiple)(textData, particle.randomIndexData);
27
41
  }
28
- const text = particle.text, style = character.style ?? "", weight = character.weight ?? "400", size = Math.round(radius) * 2, font = character.font ?? "Verdana", fill = particle.fill, offsetX = (text.length * radius) / 2;
42
+ const text = particle.text, style = character.style ?? "", weight = character.weight ?? "400", size = Math.round(radius) * 2, font = character.font ?? "Verdana", fill = particle.shapeFill;
43
+ const lines = text?.split("\n");
44
+ if (!lines) {
45
+ return;
46
+ }
29
47
  context.font = `${style} ${weight} ${size}px "${font}"`;
30
- const pos = {
31
- x: -offsetX,
32
- y: radius / 2,
33
- };
34
48
  context.globalAlpha = opacity;
35
- if (fill) {
36
- context.fillText(text, pos.x, pos.y);
37
- }
38
- else {
39
- context.strokeText(text, pos.x, pos.y);
49
+ for (let i = 0; i < lines.length; i++) {
50
+ this._drawLine(context, lines[i], radius, opacity, i, fill);
40
51
  }
41
52
  context.globalAlpha = 1;
42
53
  }
43
- getSidesCount() {
44
- return 12;
45
- }
46
54
  async init(container) {
47
55
  const options = container.actualOptions;
48
56
  if (exports.validTypes.find((t) => (0, engine_1.isInArray)(t, options.particles.shape.type))) {
File without changes
File without changes
File without changes
File without changes