@tsparticles/shape-text 4.0.0-alpha.5 → 4.0.0-beta.0
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/942.min.js +2 -0
- package/browser/TextDrawer.js +16 -10
- package/browser/Utils.js +20 -12
- package/browser/index.js +7 -4
- package/cjs/TextDrawer.js +16 -10
- package/cjs/Utils.js +20 -12
- package/cjs/index.js +7 -4
- package/dist_browser_TextDrawer_js.js +2 -12
- package/esm/TextDrawer.js +16 -10
- package/esm/Utils.js +20 -12
- package/esm/index.js +7 -4
- package/package.json +3 -2
- package/report.html +3 -3
- package/tsparticles.shape.text.js +51 -19
- package/tsparticles.shape.text.min.js +3 -2
- package/types/ITextShape.d.ts +4 -4
- package/types/TextDrawer.d.ts +0 -1
- package/types/TextParticle.d.ts +2 -1
- package/types/Utils.d.ts +1 -0
- package/umd/TextDrawer.js +17 -11
- package/umd/Utils.js +21 -12
- package/umd/index.js +8 -5
- package/21.min.js +0 -2
- package/21.min.js.LICENSE.txt +0 -1
- package/tsparticles.shape.text.min.js.LICENSE.txt +0 -1
|
@@ -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-
|
|
7
|
+
* v4.0.0-beta.0
|
|
8
8
|
*/
|
|
9
9
|
/*
|
|
10
10
|
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
|
|
@@ -16,25 +16,25 @@
|
|
|
16
16
|
*/
|
|
17
17
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
18
18
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
19
|
-
module.exports = factory(require("@tsparticles/engine"));
|
|
19
|
+
module.exports = factory(require("@tsparticles/engine"), require("@tsparticles/canvas-utils"));
|
|
20
20
|
else if(typeof define === 'function' && define.amd)
|
|
21
|
-
define(["@tsparticles/engine"], factory);
|
|
21
|
+
define(["@tsparticles/engine", "@tsparticles/canvas-utils"], factory);
|
|
22
22
|
else {
|
|
23
|
-
var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]);
|
|
23
|
+
var a = typeof exports === 'object' ? factory(require("@tsparticles/engine"), require("@tsparticles/canvas-utils")) : factory(root["window"], root["window"]);
|
|
24
24
|
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
|
|
25
25
|
}
|
|
26
|
-
})(this, (__WEBPACK_EXTERNAL_MODULE__tsparticles_engine__) => {
|
|
26
|
+
})(this, (__WEBPACK_EXTERNAL_MODULE__tsparticles_engine__, __WEBPACK_EXTERNAL_MODULE__tsparticles_canvas_utils__) => {
|
|
27
27
|
return /******/ (() => { // webpackBootstrap
|
|
28
28
|
/******/ "use strict";
|
|
29
29
|
/******/ var __webpack_modules__ = ({
|
|
30
30
|
|
|
31
|
-
/***/ "
|
|
32
|
-
|
|
33
|
-
!***
|
|
34
|
-
|
|
35
|
-
(
|
|
31
|
+
/***/ "@tsparticles/canvas-utils"
|
|
32
|
+
/*!***************************************************************************************************************************************************!*\
|
|
33
|
+
!*** external {"commonjs":"@tsparticles/canvas-utils","commonjs2":"@tsparticles/canvas-utils","amd":"@tsparticles/canvas-utils","root":"window"} ***!
|
|
34
|
+
\***************************************************************************************************************************************************/
|
|
35
|
+
(module) {
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_canvas_utils__;
|
|
38
38
|
|
|
39
39
|
/***/ },
|
|
40
40
|
|
|
@@ -46,6 +46,26 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
|
|
|
46
46
|
|
|
47
47
|
module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
|
|
48
48
|
|
|
49
|
+
/***/ },
|
|
50
|
+
|
|
51
|
+
/***/ "./dist/browser/Utils.js"
|
|
52
|
+
/*!*******************************!*\
|
|
53
|
+
!*** ./dist/browser/Utils.js ***!
|
|
54
|
+
\*******************************/
|
|
55
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
56
|
+
|
|
57
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ drawText: () => (/* binding */ drawText),\n/* harmony export */ validTypes: () => (/* binding */ validTypes)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nconst validTypes = [\n \"text\",\n \"character\",\n \"char\",\n \"multiline-text\"\n];\nconst firstIndex = 0, minLength = 0;\nfunction drawText(data) {\n const { context, particle, fill, stroke, radius, opacity } = data, character = particle.shapeData;\n if (!character) {\n return;\n }\n const textData = character.value;\n particle.textLines ??= (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.itemFromSingleOrMultiple)(textData, particle.randomIndexData)?.split(\"\\n\") ?? [];\n particle.maxTextLength ??= particle.textLines.length ? Math.max(...particle.textLines.map((t)=>t.length)) : particle.textLines[firstIndex]?.length ?? minLength;\n if (!particle.textLines.length || !particle.maxTextLength) {\n return;\n }\n const lines = particle.textLines, style = character.style ?? \"\", weight = character.weight ?? \"400\", font = character.font ?? \"Verdana\", size = Math.round(radius) * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.double / (lines.length * particle.maxTextLength);\n context.font = `${style} ${weight} ${size.toString()}px \"${font}\"`;\n const originalGlobalAlpha = context.globalAlpha;\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 drawTextLine(context, currentLine, size, i, fill, stroke);\n }\n context.globalAlpha = originalGlobalAlpha;\n}\nfunction drawTextLine(context, line, size, index, fill, stroke) {\n const pos = {\n x: -(line.length * size * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half),\n y: size * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half + index * size\n };\n if (fill) {\n context.fillText(line, pos.x, pos.y);\n }\n if (stroke) {\n context.strokeText(line, pos.x, pos.y);\n }\n}\n\n\n//# sourceURL=webpack://@tsparticles/shape-text/./dist/browser/Utils.js?\n}");
|
|
58
|
+
|
|
59
|
+
/***/ },
|
|
60
|
+
|
|
61
|
+
/***/ "./dist/browser/index.js"
|
|
62
|
+
/*!*******************************!*\
|
|
63
|
+
!*** ./dist/browser/index.js ***!
|
|
64
|
+
\*******************************/
|
|
65
|
+
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
66
|
+
|
|
67
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ loadTextShape: () => (/* binding */ loadTextShape)\n/* harmony export */ });\n/* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Utils.js */ \"./dist/browser/Utils.js\");\n\nasync function loadTextShape(engine) {\n engine.checkVersion(\"4.0.0-beta.0\");\n await engine.register((e)=>{\n e.addShape(_Utils_js__WEBPACK_IMPORTED_MODULE_0__.validTypes, async ()=>{\n const { TextDrawer } = await __webpack_require__.e(/*! import() */ \"dist_browser_TextDrawer_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./TextDrawer.js */ \"./dist/browser/TextDrawer.js\"));\n return new TextDrawer();\n });\n });\n}\n\n\n//# sourceURL=webpack://@tsparticles/shape-text/./dist/browser/index.js?\n}");
|
|
68
|
+
|
|
49
69
|
/***/ }
|
|
50
70
|
|
|
51
71
|
/******/ });
|
|
@@ -60,12 +80,6 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
|
|
|
60
80
|
/******/ if (cachedModule !== undefined) {
|
|
61
81
|
/******/ return cachedModule.exports;
|
|
62
82
|
/******/ }
|
|
63
|
-
/******/ // Check if module exists (development only)
|
|
64
|
-
/******/ if (__webpack_modules__[moduleId] === undefined) {
|
|
65
|
-
/******/ var e = new Error("Cannot find module '" + moduleId + "'");
|
|
66
|
-
/******/ e.code = 'MODULE_NOT_FOUND';
|
|
67
|
-
/******/ throw e;
|
|
68
|
-
/******/ }
|
|
69
83
|
/******/ // Create a new module (and put it into the cache)
|
|
70
84
|
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
71
85
|
/******/ // no module.id needed
|
|
@@ -74,6 +88,12 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
|
|
|
74
88
|
/******/ };
|
|
75
89
|
/******/
|
|
76
90
|
/******/ // Execute the module function
|
|
91
|
+
/******/ if (!(moduleId in __webpack_modules__)) {
|
|
92
|
+
/******/ delete __webpack_module_cache__[moduleId];
|
|
93
|
+
/******/ var e = new Error("Cannot find module '" + moduleId + "'");
|
|
94
|
+
/******/ e.code = 'MODULE_NOT_FOUND';
|
|
95
|
+
/******/ throw e;
|
|
96
|
+
/******/ }
|
|
77
97
|
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
78
98
|
/******/
|
|
79
99
|
/******/ // Return the exports of the module
|
|
@@ -118,6 +138,18 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
|
|
|
118
138
|
/******/ };
|
|
119
139
|
/******/ })();
|
|
120
140
|
/******/
|
|
141
|
+
/******/ /* webpack/runtime/global */
|
|
142
|
+
/******/ (() => {
|
|
143
|
+
/******/ __webpack_require__.g = (function() {
|
|
144
|
+
/******/ if (typeof globalThis === 'object') return globalThis;
|
|
145
|
+
/******/ try {
|
|
146
|
+
/******/ return this || new Function('return this')();
|
|
147
|
+
/******/ } catch (e) {
|
|
148
|
+
/******/ if (typeof window === 'object') return window;
|
|
149
|
+
/******/ }
|
|
150
|
+
/******/ })();
|
|
151
|
+
/******/ })();
|
|
152
|
+
/******/
|
|
121
153
|
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
122
154
|
/******/ (() => {
|
|
123
155
|
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
@@ -182,8 +214,8 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
|
|
|
182
214
|
/******/ /* webpack/runtime/publicPath */
|
|
183
215
|
/******/ (() => {
|
|
184
216
|
/******/ var scriptUrl;
|
|
185
|
-
/******/ if (
|
|
186
|
-
/******/ var document =
|
|
217
|
+
/******/ if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + "";
|
|
218
|
+
/******/ var document = __webpack_require__.g.document;
|
|
187
219
|
/******/ if (!scriptUrl && document) {
|
|
188
220
|
/******/ if (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT')
|
|
189
221
|
/******/ scriptUrl = document.currentScript.src;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"),require("@tsparticles/canvas-utils"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine","@tsparticles/canvas-utils"],t);else{var r="object"==typeof exports?t(require("@tsparticles/engine"),require("@tsparticles/canvas-utils")):t(e.window,e.window);for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(this,(e,t)=>(()=>{"use strict";var r,n,a,i={425(e){e.exports=t},303(t){t.exports=e},183(e,t,r){r.d(t,{m:()=>i,u:()=>a});var n=r(303);let a=["text","character","char","multiline-text"];function i(e){let{context:t,particle:r,fill:a,stroke:i,radius:o,opacity:l}=e,s=r.shapeData;if(!s)return;let p=s.value;if(r.textLines??=(0,n.itemFromSingleOrMultiple)(p,r.randomIndexData)?.split(`
|
|
2
|
+
`)??[],r.maxTextLength??=r.textLines.length?Math.max(...r.textLines.map(e=>e.length)):r.textLines[0]?.length??0,!r.textLines.length||!r.maxTextLength)return;let c=r.textLines,u=s.style??"",h=s.weight??"400",d=s.font??"Verdana",f=Math.round(o)*n.double/(c.length*r.maxTextLength);t.font=`${u} ${h} ${f.toString()}px "${d}"`;let g=t.globalAlpha;t.globalAlpha=l;for(let e=0;e<c.length;e++){let r=c[e];r&&function(e,t,r,a,i,o){let l={x:-(t.length*r*n.half),y:r*n.half+a*r};i&&e.fillText(t,l.x,l.y),o&&e.strokeText(t,l.x,l.y)}(t,r,f,e,a,i)}t.globalAlpha=g}}},o={};function l(e){var t=o[e];if(void 0!==t)return t.exports;var r=o[e]={exports:{}};return i[e](r,r.exports,l),r.exports}l.m=i,l.d=(e,t)=>{for(var r in t)l.o(t,r)&&!l.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},l.f={},l.e=e=>Promise.all(Object.keys(l.f).reduce((t,r)=>(l.f[r](e,t),t),[])),l.u=e=>""+e+".min.js",l.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),l.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),s={},l.l=(e,t,r,n)=>{if(s[e])return void s[e].push(t);if(void 0!==r)for(var a,i,o=document.getElementsByTagName("script"),p=0;p<o.length;p++){var c=o[p];if(c.getAttribute("src")==e||c.getAttribute("data-webpack")=="@tsparticles/shape-text:"+r){a=c;break}}a||(i=!0,(a=document.createElement("script")).charset="utf-8",l.nc&&a.setAttribute("nonce",l.nc),a.setAttribute("data-webpack","@tsparticles/shape-text:"+r),a.src=e),s[e]=[t];var u=(t,r)=>{a.onerror=a.onload=null,clearTimeout(h);var n=s[e];if(delete s[e],a.parentNode&&a.parentNode.removeChild(a),n&&n.forEach(e=>e(r)),t)return t(r)},h=setTimeout(u.bind(null,void 0,{type:"timeout",target:a}),12e4);a.onerror=u.bind(null,a.onerror),a.onload=u.bind(null,a.onload),i&&document.head.appendChild(a)},l.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},l.g.importScripts&&(p=l.g.location+"");var s,p,c=l.g.document;if(!p&&c&&(c.currentScript&&"SCRIPT"===c.currentScript.tagName.toUpperCase()&&(p=c.currentScript.src),!p)){var u=c.getElementsByTagName("script");if(u.length)for(var h=u.length-1;h>-1&&(!p||!/^http(s?):/.test(p));)p=u[h--].src}if(!p)throw Error("Automatic publicPath is not supported in this browser");l.p=p=p.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),r={973:0},l.f.j=(e,t)=>{var n=l.o(r,e)?r[e]:void 0;if(0!==n)if(n)t.push(n[2]);else{var a=new Promise((t,a)=>n=r[e]=[t,a]);t.push(n[2]=a);var i=l.p+l.u(e),o=Error();l.l(i,t=>{if(l.o(r,e)&&(0!==(n=r[e])&&(r[e]=void 0),n)){var a=t&&("load"===t.type?"missing":t.type),i=t&&t.target&&t.target.src;o.message="Loading chunk "+e+` failed.
|
|
3
|
+
(`+a+": "+i+")",o.name="ChunkLoadError",o.type=a,o.request=i,n[1](o)}},"chunk-"+e,e)}},n=(e,t)=>{var n,a,[i,o,s]=t,p=0;if(i.some(e=>0!==r[e])){for(n in o)l.o(o,n)&&(l.m[n]=o[n]);s&&s(l)}for(e&&e(t);p<i.length;p++)a=i[p],l.o(r,a)&&r[a]&&r[a][0](),r[a]=0},(a=this.webpackChunk_tsparticles_shape_text=this.webpackChunk_tsparticles_shape_text||[]).forEach(n.bind(null,0)),a.push=n.bind(null,a.push.bind(a));var d={};l.r(d),l.d(d,{loadTextShape:()=>g});var f=l(183);async function g(e){e.checkVersion("4.0.0-beta.0"),await e.register(e=>{e.addShape(f.u,async()=>{let{TextDrawer:e}=await l.e(942).then(l.bind(l,942));return new e})})}return d})());
|
package/types/ITextShape.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IShapeValues, SingleOrMultiple } from "@tsparticles/engine";
|
|
2
2
|
export interface ITextShape extends IShapeValues {
|
|
3
|
-
font
|
|
4
|
-
style
|
|
5
|
-
value
|
|
6
|
-
weight
|
|
3
|
+
font?: string;
|
|
4
|
+
style?: string;
|
|
5
|
+
value?: SingleOrMultiple<string>;
|
|
6
|
+
weight?: string;
|
|
7
7
|
}
|
package/types/TextDrawer.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type Container, type IShapeDrawData, type IShapeDrawer } from "@tsparticles/engine";
|
|
2
2
|
import type { TextParticle } from "./TextParticle.js";
|
|
3
3
|
export declare class TextDrawer implements IShapeDrawer<TextParticle> {
|
|
4
|
-
readonly validTypes: readonly ["text", "character", "char", "multiline-text"];
|
|
5
4
|
draw(data: IShapeDrawData<TextParticle>): void;
|
|
6
5
|
init(container: Container): Promise<void>;
|
|
7
6
|
particleInit(_container: Container, particle: TextParticle): void;
|
package/types/TextParticle.d.ts
CHANGED
package/types/Utils.d.ts
CHANGED
package/umd/TextDrawer.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
if (v !== undefined) module.exports = v;
|
|
5
5
|
}
|
|
6
6
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "@tsparticles/engine", "./Utils.js"], factory);
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine", "./Utils.js", "@tsparticles/canvas-utils"], factory);
|
|
8
8
|
}
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
@@ -12,26 +12,26 @@
|
|
|
12
12
|
exports.TextDrawer = void 0;
|
|
13
13
|
const engine_1 = require("@tsparticles/engine");
|
|
14
14
|
const Utils_js_1 = require("./Utils.js");
|
|
15
|
-
const
|
|
15
|
+
const canvas_utils_1 = require("@tsparticles/canvas-utils");
|
|
16
|
+
const firstIndex = 0, minLength = 0;
|
|
16
17
|
class TextDrawer {
|
|
17
|
-
constructor() {
|
|
18
|
-
this.validTypes = ["text", "character", "char", "multiline-text"];
|
|
19
|
-
}
|
|
20
18
|
draw(data) {
|
|
21
19
|
(0, Utils_js_1.drawText)(data);
|
|
22
20
|
}
|
|
23
21
|
async init(container) {
|
|
24
|
-
const options = container.actualOptions
|
|
25
|
-
if (validTypes.find(t => (0, engine_1.isInArray)(t, options.particles.shape.type))) {
|
|
26
|
-
const shapeOptions = validTypes
|
|
22
|
+
const options = container.actualOptions;
|
|
23
|
+
if (Utils_js_1.validTypes.find(t => (0, engine_1.isInArray)(t, options.particles.shape.type))) {
|
|
24
|
+
const shapeOptions = Utils_js_1.validTypes
|
|
25
|
+
.map(t => options.particles.shape.options[t])
|
|
26
|
+
.find(t => !!t), promises = [];
|
|
27
27
|
(0, engine_1.executeOnSingleOrMultiple)(shapeOptions, shape => {
|
|
28
|
-
promises.push((0,
|
|
28
|
+
promises.push((0, canvas_utils_1.loadFont)(shape.font, shape.weight));
|
|
29
29
|
});
|
|
30
30
|
await Promise.all(promises);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
particleInit(_container, particle) {
|
|
34
|
-
if (!particle.shape || !
|
|
34
|
+
if (!particle.shape || !Utils_js_1.validTypes.includes(particle.shape)) {
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
37
|
const character = particle.shapeData;
|
|
@@ -39,7 +39,13 @@
|
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
41
|
const textData = character.value;
|
|
42
|
-
|
|
42
|
+
if (!textData) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
particle.textLines = (0, engine_1.itemFromSingleOrMultiple)(textData, particle.randomIndexData)?.split("\n") ?? [];
|
|
46
|
+
particle.maxTextLength = particle.textLines.length
|
|
47
|
+
? Math.max(...particle.textLines.map(t => t.length))
|
|
48
|
+
: (particle.textLines[firstIndex]?.length ?? minLength);
|
|
43
49
|
}
|
|
44
50
|
}
|
|
45
51
|
exports.TextDrawer = TextDrawer;
|
package/umd/Utils.js
CHANGED
|
@@ -9,38 +9,47 @@
|
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.validTypes = void 0;
|
|
12
13
|
exports.drawText = drawText;
|
|
13
14
|
const engine_1 = require("@tsparticles/engine");
|
|
15
|
+
exports.validTypes = ["text", "character", "char", "multiline-text"];
|
|
16
|
+
const firstIndex = 0, minLength = 0;
|
|
14
17
|
function drawText(data) {
|
|
15
18
|
const { context, particle, fill, stroke, radius, opacity } = data, character = particle.shapeData;
|
|
16
19
|
if (!character) {
|
|
17
20
|
return;
|
|
18
21
|
}
|
|
19
22
|
const textData = character.value;
|
|
20
|
-
particle.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
particle.textLines ??= (0, engine_1.itemFromSingleOrMultiple)(textData, particle.randomIndexData)?.split("\n") ?? [];
|
|
24
|
+
particle.maxTextLength ??= particle.textLines.length
|
|
25
|
+
? Math.max(...particle.textLines.map(t => t.length))
|
|
26
|
+
: (particle.textLines[firstIndex]?.length ?? minLength);
|
|
27
|
+
if (!particle.textLines.length || !particle.maxTextLength) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const lines = particle.textLines, style = character.style ?? "", weight = character.weight ?? "400", font = character.font ?? "Verdana", size = (Math.round(radius) * engine_1.double) / (lines.length * particle.maxTextLength);
|
|
23
31
|
context.font = `${style} ${weight} ${size.toString()}px "${font}"`;
|
|
32
|
+
const originalGlobalAlpha = context.globalAlpha;
|
|
24
33
|
context.globalAlpha = opacity;
|
|
25
34
|
for (let i = 0; i < lines.length; i++) {
|
|
26
35
|
const currentLine = lines[i];
|
|
27
36
|
if (!currentLine) {
|
|
28
37
|
continue;
|
|
29
38
|
}
|
|
30
|
-
|
|
39
|
+
drawTextLine(context, currentLine, size, i, fill, stroke);
|
|
31
40
|
}
|
|
32
|
-
context.globalAlpha =
|
|
41
|
+
context.globalAlpha = originalGlobalAlpha;
|
|
33
42
|
}
|
|
34
|
-
function
|
|
35
|
-
const
|
|
36
|
-
x: -
|
|
37
|
-
y:
|
|
38
|
-
}
|
|
43
|
+
function drawTextLine(context, line, size, index, fill, stroke) {
|
|
44
|
+
const pos = {
|
|
45
|
+
x: -(line.length * size * engine_1.half),
|
|
46
|
+
y: size * engine_1.half + index * size,
|
|
47
|
+
};
|
|
39
48
|
if (fill) {
|
|
40
|
-
context.fillText(line, pos.x, pos.y
|
|
49
|
+
context.fillText(line, pos.x, pos.y);
|
|
41
50
|
}
|
|
42
51
|
if (stroke) {
|
|
43
|
-
context.strokeText(line, pos.x, pos.y
|
|
52
|
+
context.strokeText(line, pos.x, pos.y);
|
|
44
53
|
}
|
|
45
54
|
}
|
|
46
55
|
});
|
package/umd/index.js
CHANGED
|
@@ -37,18 +37,21 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
37
37
|
if (v !== undefined) module.exports = v;
|
|
38
38
|
}
|
|
39
39
|
else if (typeof define === "function" && define.amd) {
|
|
40
|
-
define(["require", "exports"], factory);
|
|
40
|
+
define(["require", "exports", "./Utils.js"], factory);
|
|
41
41
|
}
|
|
42
42
|
})(function (require, exports) {
|
|
43
43
|
"use strict";
|
|
44
44
|
var __syncRequire = typeof module === "object" && typeof module.exports === "object";
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
46
|
exports.loadTextShape = loadTextShape;
|
|
47
|
+
const Utils_js_1 = require("./Utils.js");
|
|
47
48
|
async function loadTextShape(engine) {
|
|
48
|
-
engine.checkVersion("4.0.0-
|
|
49
|
-
await engine.register(
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
engine.checkVersion("4.0.0-beta.0");
|
|
50
|
+
await engine.register(e => {
|
|
51
|
+
e.addShape(Utils_js_1.validTypes, async () => {
|
|
52
|
+
const { TextDrawer } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./TextDrawer.js"))) : new Promise((resolve_1, reject_1) => { require(["./TextDrawer.js"], resolve_1, reject_1); }).then(__importStar));
|
|
53
|
+
return new TextDrawer();
|
|
54
|
+
});
|
|
52
55
|
});
|
|
53
56
|
}
|
|
54
57
|
});
|
package/21.min.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
/*! For license information please see 21.min.js.LICENSE.txt */
|
|
2
|
-
(this.webpackChunk_tsparticles_shape_text=this.webpackChunk_tsparticles_shape_text||[]).push([[21],{21(t,e,a){a.d(e,{TextDrawer:()=>s});var i=a(303);function l(t,e,a,l,s,n,o){const r={x:-(e.length*a*i.half),y:a*i.half},p=a*i.double;n&&t.fillText(e,r.x,r.y+p*s),o&&t.strokeText(e,r.x,r.y+p*s)}class s{constructor(){this.validTypes=["text","character","char","multiline-text"]}draw(t){!function(t){const{context:e,particle:a,fill:s,stroke:n,radius:o,opacity:r}=t,p=a.shapeData;if(!p)return;const c=p.value;a.text??=(0,i.itemFromSingleOrMultiple)(c,a.randomIndexData);const h=a.text,u=p.style,x=p.weight,d=Math.round(o)*i.double,f=p.font,y=h?.split("\n")??[];e.font=`${u} ${x} ${d.toString()}px "${f}"`,e.globalAlpha=r;for(let t=0;t<y.length;t++){const a=y[t];a&&l(e,a,o,0,t,s,n)}e.globalAlpha=1}(t)}async init(t){const e=t.actualOptions,{validTypes:a}=this;if(a.find((t=>(0,i.isInArray)(t,e.particles.shape.type)))){const t=a.map((t=>e.particles.shape.options[t]))[0],l=[];(0,i.executeOnSingleOrMultiple)(t,(t=>{l.push((0,i.loadFont)(t.font,t.weight))})),await Promise.all(l)}}particleInit(t,e){if(!e.shape||!this.validTypes.includes(e.shape))return;const a=e.shapeData;if(void 0===a)return;const l=a.value;e.text=(0,i.itemFromSingleOrMultiple)(l,e.randomIndexData)}}}}]);
|
package/21.min.js.LICENSE.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/*! tsParticles Text Shape v4.0.0-alpha.5 by Matteo Bruni */
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/*! tsParticles Text Shape v4.0.0-alpha.5 by Matteo Bruni */
|