@tsparticles/shape-text 3.0.0-alpha.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/LICENSE +21 -0
- package/README.md +71 -0
- package/browser/ICharacterShape.js +1 -0
- package/browser/TextDrawer.js +48 -0
- package/browser/TextParticle.js +1 -0
- package/browser/index.js +4 -0
- package/cjs/ICharacterShape.js +2 -0
- package/cjs/TextDrawer.js +63 -0
- package/cjs/TextParticle.js +2 -0
- package/cjs/index.js +19 -0
- package/esm/ICharacterShape.js +1 -0
- package/esm/TextDrawer.js +48 -0
- package/esm/TextParticle.js +1 -0
- package/esm/index.js +4 -0
- package/package.json +54 -0
- package/report.html +39 -0
- package/tsparticles.shape.text.js +162 -0
- package/tsparticles.shape.text.min.js +2 -0
- package/tsparticles.shape.text.min.js.LICENSE.txt +8 -0
- package/types/ICharacterShape.d.ts +7 -0
- package/types/TextDrawer.d.ts +7 -0
- package/types/TextParticle.d.ts +4 -0
- package/types/index.d.ts +2 -0
- package/umd/ICharacterShape.js +12 -0
- package/umd/TextDrawer.js +62 -0
- package/umd/TextParticle.js +12 -0
- package/umd/index.js +18 -0
|
@@ -0,0 +1,162 @@
|
|
|
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.0
|
|
8
|
+
*/
|
|
9
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
10
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
|
11
|
+
module.exports = factory(require("@tsparticles/engine"));
|
|
12
|
+
else if(typeof define === 'function' && define.amd)
|
|
13
|
+
define(["@tsparticles/engine"], factory);
|
|
14
|
+
else {
|
|
15
|
+
var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]);
|
|
16
|
+
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
|
|
17
|
+
}
|
|
18
|
+
})(this, (__WEBPACK_EXTERNAL_MODULE__533__) => {
|
|
19
|
+
return /******/ (() => { // webpackBootstrap
|
|
20
|
+
/******/ "use strict";
|
|
21
|
+
/******/ var __webpack_modules__ = ({
|
|
22
|
+
|
|
23
|
+
/***/ 533:
|
|
24
|
+
/***/ ((module) => {
|
|
25
|
+
|
|
26
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE__533__;
|
|
27
|
+
|
|
28
|
+
/***/ })
|
|
29
|
+
|
|
30
|
+
/******/ });
|
|
31
|
+
/************************************************************************/
|
|
32
|
+
/******/ // The module cache
|
|
33
|
+
/******/ var __webpack_module_cache__ = {};
|
|
34
|
+
/******/
|
|
35
|
+
/******/ // The require function
|
|
36
|
+
/******/ function __webpack_require__(moduleId) {
|
|
37
|
+
/******/ // Check if module is in cache
|
|
38
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
39
|
+
/******/ if (cachedModule !== undefined) {
|
|
40
|
+
/******/ return cachedModule.exports;
|
|
41
|
+
/******/ }
|
|
42
|
+
/******/ // Create a new module (and put it into the cache)
|
|
43
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
44
|
+
/******/ // no module.id needed
|
|
45
|
+
/******/ // no module.loaded needed
|
|
46
|
+
/******/ exports: {}
|
|
47
|
+
/******/ };
|
|
48
|
+
/******/
|
|
49
|
+
/******/ // Execute the module function
|
|
50
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
51
|
+
/******/
|
|
52
|
+
/******/ // Return the exports of the module
|
|
53
|
+
/******/ return module.exports;
|
|
54
|
+
/******/ }
|
|
55
|
+
/******/
|
|
56
|
+
/************************************************************************/
|
|
57
|
+
/******/ /* webpack/runtime/define property getters */
|
|
58
|
+
/******/ (() => {
|
|
59
|
+
/******/ // define getter functions for harmony exports
|
|
60
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
61
|
+
/******/ for(var key in definition) {
|
|
62
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
63
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
64
|
+
/******/ }
|
|
65
|
+
/******/ }
|
|
66
|
+
/******/ };
|
|
67
|
+
/******/ })();
|
|
68
|
+
/******/
|
|
69
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
70
|
+
/******/ (() => {
|
|
71
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
72
|
+
/******/ })();
|
|
73
|
+
/******/
|
|
74
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
75
|
+
/******/ (() => {
|
|
76
|
+
/******/ // define __esModule on exports
|
|
77
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
78
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
79
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
80
|
+
/******/ }
|
|
81
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
82
|
+
/******/ };
|
|
83
|
+
/******/ })();
|
|
84
|
+
/******/
|
|
85
|
+
/************************************************************************/
|
|
86
|
+
var __webpack_exports__ = {};
|
|
87
|
+
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
|
88
|
+
(() => {
|
|
89
|
+
// ESM COMPAT FLAG
|
|
90
|
+
__webpack_require__.r(__webpack_exports__);
|
|
91
|
+
|
|
92
|
+
// EXPORTS
|
|
93
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
94
|
+
"loadTextShape": () => (/* binding */ loadTextShape)
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
|
|
98
|
+
var engine_root_window_ = __webpack_require__(533);
|
|
99
|
+
;// CONCATENATED MODULE: ./dist/browser/TextDrawer.js
|
|
100
|
+
|
|
101
|
+
const validTypes = ["text", "character", "char"];
|
|
102
|
+
class TextDrawer {
|
|
103
|
+
draw(context, particle, radius, opacity) {
|
|
104
|
+
var _a, _b, _c;
|
|
105
|
+
const character = particle.shapeData;
|
|
106
|
+
if (character === undefined) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const textData = character.value;
|
|
110
|
+
if (textData === undefined) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const textParticle = particle;
|
|
114
|
+
if (textParticle.text === undefined) {
|
|
115
|
+
textParticle.text = (0,engine_root_window_.itemFromSingleOrMultiple)(textData, particle.randomIndexData);
|
|
116
|
+
}
|
|
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",
|
|
120
|
+
size = Math.round(radius) * 2,
|
|
121
|
+
font = (_c = character.font) !== null && _c !== void 0 ? _c : "Verdana",
|
|
122
|
+
fill = particle.fill,
|
|
123
|
+
offsetX = text.length * radius / 2;
|
|
124
|
+
context.font = `${style} ${weight} ${size}px "${font}"`;
|
|
125
|
+
const pos = {
|
|
126
|
+
x: -offsetX,
|
|
127
|
+
y: radius / 2
|
|
128
|
+
};
|
|
129
|
+
context.globalAlpha = opacity;
|
|
130
|
+
if (fill) {
|
|
131
|
+
context.fillText(text, pos.x, pos.y);
|
|
132
|
+
} else {
|
|
133
|
+
context.strokeText(text, pos.x, pos.y);
|
|
134
|
+
}
|
|
135
|
+
context.globalAlpha = 1;
|
|
136
|
+
}
|
|
137
|
+
getSidesCount() {
|
|
138
|
+
return 12;
|
|
139
|
+
}
|
|
140
|
+
async init(container) {
|
|
141
|
+
const options = container.actualOptions;
|
|
142
|
+
if (validTypes.find(t => (0,engine_root_window_.isInArray)(t, options.particles.shape.type))) {
|
|
143
|
+
const shapeOptions = validTypes.map(t => options.particles.shape.options[t]).find(t => !!t),
|
|
144
|
+
promises = [];
|
|
145
|
+
(0,engine_root_window_.executeOnSingleOrMultiple)(shapeOptions, shape => {
|
|
146
|
+
promises.push((0,engine_root_window_.loadFont)(shape.font, shape.weight));
|
|
147
|
+
});
|
|
148
|
+
await Promise.all(promises);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
;// CONCATENATED MODULE: ./dist/browser/index.js
|
|
153
|
+
|
|
154
|
+
async function loadTextShape(engine) {
|
|
155
|
+
await engine.addShape(validTypes, new TextDrawer());
|
|
156
|
+
}
|
|
157
|
+
})();
|
|
158
|
+
|
|
159
|
+
/******/ return __webpack_exports__;
|
|
160
|
+
/******/ })()
|
|
161
|
+
;
|
|
162
|
+
});
|
|
@@ -0,0 +1,2 @@
|
|
|
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})()));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Container, IParticle, IShapeDrawer } from "@tsparticles/engine";
|
|
2
|
+
export declare const validTypes: string[];
|
|
3
|
+
export declare class TextDrawer implements IShapeDrawer {
|
|
4
|
+
draw(context: CanvasRenderingContext2D, particle: IParticle, radius: number, opacity: number): void;
|
|
5
|
+
getSidesCount(): number;
|
|
6
|
+
init(container: Container): Promise<void>;
|
|
7
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.TextDrawer = exports.validTypes = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
exports.validTypes = ["text", "character", "char"];
|
|
15
|
+
class TextDrawer {
|
|
16
|
+
draw(context, particle, radius, opacity) {
|
|
17
|
+
var _a, _b, _c;
|
|
18
|
+
const character = particle.shapeData;
|
|
19
|
+
if (character === undefined) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const textData = character.value;
|
|
23
|
+
if (textData === undefined) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const textParticle = particle;
|
|
27
|
+
if (textParticle.text === undefined) {
|
|
28
|
+
textParticle.text = (0, engine_1.itemFromSingleOrMultiple)(textData, particle.randomIndexData);
|
|
29
|
+
}
|
|
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;
|
|
31
|
+
context.font = `${style} ${weight} ${size}px "${font}"`;
|
|
32
|
+
const pos = {
|
|
33
|
+
x: -offsetX,
|
|
34
|
+
y: radius / 2,
|
|
35
|
+
};
|
|
36
|
+
context.globalAlpha = opacity;
|
|
37
|
+
if (fill) {
|
|
38
|
+
context.fillText(text, pos.x, pos.y);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
context.strokeText(text, pos.x, pos.y);
|
|
42
|
+
}
|
|
43
|
+
context.globalAlpha = 1;
|
|
44
|
+
}
|
|
45
|
+
getSidesCount() {
|
|
46
|
+
return 12;
|
|
47
|
+
}
|
|
48
|
+
async init(container) {
|
|
49
|
+
const options = container.actualOptions;
|
|
50
|
+
if (exports.validTypes.find((t) => (0, engine_1.isInArray)(t, options.particles.shape.type))) {
|
|
51
|
+
const shapeOptions = exports.validTypes
|
|
52
|
+
.map((t) => options.particles.shape.options[t])
|
|
53
|
+
.find((t) => !!t), promises = [];
|
|
54
|
+
(0, engine_1.executeOnSingleOrMultiple)(shapeOptions, (shape) => {
|
|
55
|
+
promises.push((0, engine_1.loadFont)(shape.font, shape.weight));
|
|
56
|
+
});
|
|
57
|
+
await Promise.all(promises);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.TextDrawer = TextDrawer;
|
|
62
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
package/umd/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "./TextDrawer"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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());
|
|
16
|
+
}
|
|
17
|
+
exports.loadTextShape = loadTextShape;
|
|
18
|
+
});
|