@tsparticles/shape-text 3.0.0-beta.3 → 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.
- package/browser/TextDrawer.js +23 -15
- package/cjs/TextDrawer.js +23 -15
- package/esm/TextDrawer.js +23 -15
- package/package.json +3 -3
- package/report.html +4 -22
- package/tsparticles.shape.text.js +24 -16
- package/tsparticles.shape.text.min.js +1 -1
- package/tsparticles.shape.text.min.js.LICENSE.txt +1 -1
- package/types/{ICharacterShape.d.ts → ITextShape.d.ts} +1 -1
- package/types/TextDrawer.d.ts +1 -1
- package/umd/TextDrawer.js +23 -15
- /package/browser/{ICharacterShape.js → ITextShape.js} +0 -0
- /package/cjs/{ICharacterShape.js → ITextShape.js} +0 -0
- /package/esm/{ICharacterShape.js → ITextShape.js} +0 -0
- /package/umd/{ICharacterShape.js → ITextShape.js} +0 -0
|
@@ -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.
|
|
7
|
+
* v3.0.0-beta.4
|
|
8
8
|
*/
|
|
9
9
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
10
10
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
@@ -98,8 +98,22 @@ __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
|
+
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
|
+
}
|
|
103
117
|
draw(data) {
|
|
104
118
|
const {
|
|
105
119
|
context,
|
|
@@ -108,7 +122,7 @@ class TextDrawer {
|
|
|
108
122
|
opacity
|
|
109
123
|
} = data,
|
|
110
124
|
character = particle.shapeData;
|
|
111
|
-
if (character
|
|
125
|
+
if (!character) {
|
|
112
126
|
return;
|
|
113
127
|
}
|
|
114
128
|
const textData = character.value;
|
|
@@ -123,24 +137,18 @@ class TextDrawer {
|
|
|
123
137
|
weight = character.weight ?? "400",
|
|
124
138
|
size = Math.round(radius) * 2,
|
|
125
139
|
font = character.font ?? "Verdana",
|
|
126
|
-
fill = particle.
|
|
127
|
-
|
|
140
|
+
fill = particle.shapeFill;
|
|
141
|
+
const lines = text?.split("\n");
|
|
142
|
+
if (!lines) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
128
145
|
context.font = `${style} ${weight} ${size}px "${font}"`;
|
|
129
|
-
const pos = {
|
|
130
|
-
x: -offsetX,
|
|
131
|
-
y: radius / 2
|
|
132
|
-
};
|
|
133
146
|
context.globalAlpha = opacity;
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
} else {
|
|
137
|
-
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);
|
|
138
149
|
}
|
|
139
150
|
context.globalAlpha = 1;
|
|
140
151
|
}
|
|
141
|
-
getSidesCount() {
|
|
142
|
-
return 12;
|
|
143
|
-
}
|
|
144
152
|
async init(container) {
|
|
145
153
|
const options = container.actualOptions;
|
|
146
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
|
|
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.
|
|
1
|
+
/*! tsParticles Text Shape v3.0.0-beta.4 by Matteo Bruni */
|
package/types/TextDrawer.d.ts
CHANGED
|
@@ -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
|
+
};
|
|
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
|
+
}
|
|
16
30
|
draw(data) {
|
|
17
31
|
const { context, particle, radius, opacity } = data, character = particle.shapeData;
|
|
18
|
-
if (character
|
|
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.
|
|
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
|
-
|
|
36
|
-
|
|
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
|