@tsparticles/shape-text 3.0.0-beta.2 → 3.0.0-beta.4

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.2
7
+ * v3.0.0-beta.4
8
8
  */
9
9
  (function webpackUniversalModuleDefinition(root, factory) {
10
10
  if(typeof exports === 'object' && typeof module === 'object')
@@ -98,11 +98,31 @@ __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
- draw(context, particle, radius, opacity) {
104
- const character = particle.shapeData;
105
- if (character === undefined) {
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
+ if (fill) {
111
+ context.fillText(line, pos.x, pos.y + radius * 2 * index);
112
+ } else {
113
+ context.strokeText(line, pos.x, pos.y + radius * 2 * index);
114
+ }
115
+ };
116
+ }
117
+ draw(data) {
118
+ const {
119
+ context,
120
+ particle,
121
+ radius,
122
+ opacity
123
+ } = data,
124
+ character = particle.shapeData;
125
+ if (!character) {
106
126
  return;
107
127
  }
108
128
  const textData = character.value;
@@ -117,24 +137,18 @@ class TextDrawer {
117
137
  weight = character.weight ?? "400",
118
138
  size = Math.round(radius) * 2,
119
139
  font = character.font ?? "Verdana",
120
- fill = particle.fill,
121
- offsetX = text.length * radius / 2;
140
+ fill = particle.shapeFill;
141
+ const lines = text?.split("\n");
142
+ if (!lines) {
143
+ return;
144
+ }
122
145
  context.font = `${style} ${weight} ${size}px "${font}"`;
123
- const pos = {
124
- x: -offsetX,
125
- y: radius / 2
126
- };
127
146
  context.globalAlpha = opacity;
128
- if (fill) {
129
- context.fillText(text, pos.x, pos.y);
130
- } else {
131
- context.strokeText(text, pos.x, pos.y);
147
+ for (let i = 0; i < lines.length; i++) {
148
+ this._drawLine(context, lines[i], radius, opacity, i, fill);
132
149
  }
133
150
  context.globalAlpha = 1;
134
151
  }
135
- getSidesCount() {
136
- return 12;
137
- }
138
152
  async init(container) {
139
153
  const options = container.actualOptions;
140
154
  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,o,r,n){const a=o.shapeData;if(void 0===a)return;const i=a.value;if(void 0===i)return;void 0===o.text&&(o.text=(0,e.itemFromSingleOrMultiple)(i,o.randomIndexData));const s=o.text,l=a.style??"",p=a.weight??"400",c=2*Math.round(r),d=a.font??"Verdana",f=o.fill,u=s.length*r/2;t.font=`${l} ${p} ${c}px "${d}"`;const x={x:-u,y:r/2};t.globalAlpha=n,f?t.fillText(s,x.x,x.y):t.strokeText(s,x.x,x.y),t.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};i?e.fillText(t,a.x,a.y+2*r*n):e.strokeText(t,a.x,a.y+2*r*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.2 by Matteo Bruni */
1
+ /*! tsParticles Text Shape v3.0.0-beta.4 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>;
@@ -1,9 +1,9 @@
1
- import { type Container, type IShapeDrawer } from "@tsparticles/engine";
1
+ import { type Container, type IShapeDrawData, type IShapeDrawer } from "@tsparticles/engine";
2
2
  import type { TextParticle } from "./TextParticle.js";
3
3
  export declare const validTypes: string[];
4
- export declare class TextDrawer implements IShapeDrawer {
5
- draw(context: CanvasRenderingContext2D, particle: TextParticle, radius: number, opacity: number): void;
6
- getSidesCount(): number;
4
+ export declare class TextDrawer implements IShapeDrawer<TextParticle> {
5
+ draw(data: IShapeDrawData<TextParticle>): void;
7
6
  init(container: Container): Promise<void>;
8
7
  particleInit(container: Container, particle: TextParticle): void;
8
+ private readonly _drawLine;
9
9
  }
@@ -1,4 +1,4 @@
1
- import type { IParticle } from "@tsparticles/engine";
2
- export interface TextParticle extends IParticle {
1
+ import type { Particle } from "@tsparticles/engine";
2
+ export interface TextParticle extends Particle {
3
3
  text?: string;
4
4
  }
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
- draw(context, particle, radius, opacity) {
17
- const character = particle.shapeData;
18
- if (character === undefined) {
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
+ };
22
+ if (fill) {
23
+ context.fillText(line, pos.x, pos.y + radius * 2 * index);
24
+ }
25
+ else {
26
+ context.strokeText(line, pos.x, pos.y + radius * 2 * index);
27
+ }
28
+ };
29
+ }
30
+ draw(data) {
31
+ const { context, particle, radius, opacity } = data, character = particle.shapeData;
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