@tsparticles/shape-text 3.0.0-alpha.1 → 3.0.0-beta.1

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-alpha.1
7
+ * v3.0.0-beta.1
8
8
  */
9
9
  (function webpackUniversalModuleDefinition(root, factory) {
10
10
  if(typeof exports === 'object' && typeof module === 'object')
@@ -91,7 +91,7 @@ __webpack_require__.r(__webpack_exports__);
91
91
 
92
92
  // EXPORTS
93
93
  __webpack_require__.d(__webpack_exports__, {
94
- "loadTextShape": () => (/* binding */ loadTextShape)
94
+ loadTextShape: () => (/* binding */ loadTextShape)
95
95
  });
96
96
 
97
97
  // EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
@@ -101,7 +101,6 @@ var engine_root_window_ = __webpack_require__(533);
101
101
  const validTypes = ["text", "character", "char"];
102
102
  class TextDrawer {
103
103
  draw(context, particle, radius, opacity) {
104
- var _a, _b, _c;
105
104
  const character = particle.shapeData;
106
105
  if (character === undefined) {
107
106
  return;
@@ -110,15 +109,14 @@ class TextDrawer {
110
109
  if (textData === undefined) {
111
110
  return;
112
111
  }
113
- const textParticle = particle;
114
- if (textParticle.text === undefined) {
115
- textParticle.text = (0,engine_root_window_.itemFromSingleOrMultiple)(textData, particle.randomIndexData);
112
+ if (particle.text === undefined) {
113
+ particle.text = (0,engine_root_window_.itemFromSingleOrMultiple)(textData, particle.randomIndexData);
116
114
  }
117
- const text = textParticle.text,
118
- style = (_a = character.style) !== null && _a !== void 0 ? _a : "",
119
- weight = (_b = character.weight) !== null && _b !== void 0 ? _b : "400",
115
+ const text = particle.text,
116
+ style = character.style ?? "",
117
+ weight = character.weight ?? "400",
120
118
  size = Math.round(radius) * 2,
121
- font = (_c = character.font) !== null && _c !== void 0 ? _c : "Verdana",
119
+ font = character.font ?? "Verdana",
122
120
  fill = particle.fill,
123
121
  offsetX = text.length * radius / 2;
124
122
  context.font = `${style} ${weight} ${size}px "${font}"`;
@@ -148,11 +146,25 @@ class TextDrawer {
148
146
  await Promise.all(promises);
149
147
  }
150
148
  }
149
+ particleInit(container, particle) {
150
+ if (!particle.shape || !validTypes.includes(particle.shape)) {
151
+ return;
152
+ }
153
+ const character = particle.shapeData;
154
+ if (character === undefined) {
155
+ return;
156
+ }
157
+ const textData = character.value;
158
+ if (textData === undefined) {
159
+ return;
160
+ }
161
+ particle.text = (0,engine_root_window_.itemFromSingleOrMultiple)(textData, particle.randomIndexData);
162
+ }
151
163
  }
152
164
  ;// CONCATENATED MODULE: ./dist/browser/index.js
153
165
 
154
- async function loadTextShape(engine) {
155
- await engine.addShape(validTypes, new TextDrawer());
166
+ async function loadTextShape(engine, refresh = true) {
167
+ await engine.addShape(validTypes, new TextDrawer(), refresh);
156
168
  }
157
169
  })();
158
170
 
@@ -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 i=o[e]={exports:{}};return t[e](i,i.exports,r),i.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:()=>i});var e=r(533);const t=["text","character","char"];class o{draw(t,o,r,n){var i,a,l;const s=o.shapeData;if(void 0===s)return;const p=s.value;if(void 0===p)return;const c=o;void 0===c.text&&(c.text=(0,e.itemFromSingleOrMultiple)(p,o.randomIndexData));const d=c.text,f=null!==(i=s.style)&&void 0!==i?i:"",u=null!==(a=s.weight)&&void 0!==a?a:"400",x=2*Math.round(r),y=null!==(l=s.font)&&void 0!==l?l:"Verdana",v=o.fill,g=d.length*r/2;t.font=`${f} ${u} ${x}px "${y}"`;const h={x:-g,y:r/2};t.globalAlpha=n,v?t.fillText(d,h.x,h.y):t.strokeText(d,h.x,h.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)}}}async function i(e){await e.addShape(t,new o)}})(),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 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})()));
@@ -1,8 +1 @@
1
- /*!
2
- * Author : Matteo Bruni
3
- * MIT license: https://opensource.org/licenses/MIT
4
- * Demo / Generator : https://particles.js.org/
5
- * GitHub : https://www.github.com/matteobruni/tsparticles
6
- * How to use? : Check the GitHub README
7
- * v3.0.0-alpha.1
8
- */
1
+ /*! tsParticles Text Shape v3.0.0-beta.1 by Matteo Bruni */
@@ -1,7 +1,9 @@
1
- import type { Container, IParticle, IShapeDrawer } from "@tsparticles/engine";
1
+ import { type Container, type IShapeDrawer } from "@tsparticles/engine";
2
+ import type { TextParticle } from "./TextParticle.js";
2
3
  export declare const validTypes: string[];
3
4
  export declare class TextDrawer implements IShapeDrawer {
4
- draw(context: CanvasRenderingContext2D, particle: IParticle, radius: number, opacity: number): void;
5
+ draw(context: CanvasRenderingContext2D, particle: TextParticle, radius: number, opacity: number): void;
5
6
  getSidesCount(): number;
6
7
  init(container: Container): Promise<void>;
8
+ particleInit(container: Container, particle: TextParticle): void;
7
9
  }
package/types/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import type { Engine } from "@tsparticles/engine";
2
- export declare function loadTextShape(engine: Engine): Promise<void>;
2
+ export declare function loadTextShape(engine: Engine, refresh?: boolean): Promise<void>;
package/umd/TextDrawer.js CHANGED
@@ -14,7 +14,6 @@
14
14
  exports.validTypes = ["text", "character", "char"];
15
15
  class TextDrawer {
16
16
  draw(context, particle, radius, opacity) {
17
- var _a, _b, _c;
18
17
  const character = particle.shapeData;
19
18
  if (character === undefined) {
20
19
  return;
@@ -23,11 +22,10 @@
23
22
  if (textData === undefined) {
24
23
  return;
25
24
  }
26
- const textParticle = particle;
27
- if (textParticle.text === undefined) {
28
- textParticle.text = (0, engine_1.itemFromSingleOrMultiple)(textData, particle.randomIndexData);
25
+ if (particle.text === undefined) {
26
+ particle.text = (0, engine_1.itemFromSingleOrMultiple)(textData, particle.randomIndexData);
29
27
  }
30
- const text = textParticle.text, style = (_a = character.style) !== null && _a !== void 0 ? _a : "", weight = (_b = character.weight) !== null && _b !== void 0 ? _b : "400", size = Math.round(radius) * 2, font = (_c = character.font) !== null && _c !== void 0 ? _c : "Verdana", fill = particle.fill, offsetX = (text.length * radius) / 2;
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;
31
29
  context.font = `${style} ${weight} ${size}px "${font}"`;
32
30
  const pos = {
33
31
  x: -offsetX,
@@ -57,6 +55,20 @@
57
55
  await Promise.all(promises);
58
56
  }
59
57
  }
58
+ particleInit(container, particle) {
59
+ if (!particle.shape || !exports.validTypes.includes(particle.shape)) {
60
+ return;
61
+ }
62
+ const character = particle.shapeData;
63
+ if (character === undefined) {
64
+ return;
65
+ }
66
+ const textData = character.value;
67
+ if (textData === undefined) {
68
+ return;
69
+ }
70
+ particle.text = (0, engine_1.itemFromSingleOrMultiple)(textData, particle.randomIndexData);
71
+ }
60
72
  }
61
73
  exports.TextDrawer = TextDrawer;
62
74
  });
package/umd/index.js CHANGED
@@ -4,15 +4,15 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "./TextDrawer"], factory);
7
+ define(["require", "exports", "./TextDrawer.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.loadTextShape = void 0;
13
- const TextDrawer_1 = require("./TextDrawer");
14
- async function loadTextShape(engine) {
15
- await engine.addShape(TextDrawer_1.validTypes, new TextDrawer_1.TextDrawer());
13
+ const TextDrawer_js_1 = require("./TextDrawer.js");
14
+ async function loadTextShape(engine, refresh = true) {
15
+ await engine.addShape(TextDrawer_js_1.validTypes, new TextDrawer_js_1.TextDrawer(), refresh);
16
16
  }
17
17
  exports.loadTextShape = loadTextShape;
18
18
  });