@tsparticles/shape-emoji 3.0.0-beta.5
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 +75 -0
- package/browser/EmojiDrawer.js +68 -0
- package/browser/EmojiParticle.js +1 -0
- package/browser/IEmojiShape.js +1 -0
- package/browser/index.js +4 -0
- package/browser/package.json +1 -0
- package/cjs/EmojiDrawer.js +72 -0
- package/cjs/EmojiParticle.js +2 -0
- package/cjs/IEmojiShape.js +2 -0
- package/cjs/index.js +8 -0
- package/cjs/package.json +1 -0
- package/esm/EmojiDrawer.js +68 -0
- package/esm/EmojiParticle.js +1 -0
- package/esm/IEmojiShape.js +1 -0
- package/esm/index.js +4 -0
- package/esm/package.json +1 -0
- package/package.json +67 -0
- package/report.html +39 -0
- package/tsparticles.shape.emoji.js +186 -0
- package/tsparticles.shape.emoji.min.js +2 -0
- package/tsparticles.shape.emoji.min.js.LICENSE.txt +1 -0
- package/types/EmojiDrawer.d.ts +11 -0
- package/types/EmojiParticle.d.ts +4 -0
- package/types/IEmojiShape.d.ts +5 -0
- package/types/index.d.ts +2 -0
- package/umd/EmojiDrawer.js +82 -0
- package/umd/EmojiParticle.js +12 -0
- package/umd/IEmojiShape.js +12 -0
- package/umd/index.js +18 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Matteo Bruni
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
[](https://particles.js.org)
|
|
2
|
+
|
|
3
|
+
# tsParticles Emoji Shape
|
|
4
|
+
|
|
5
|
+
[](https://www.jsdelivr.com/package/npm/@tsparticles/shape-emoji)
|
|
6
|
+
[](https://www.npmjs.com/package/@tsparticles/shape-emoji)
|
|
7
|
+
[](https://www.npmjs.com/package/@tsparticles/shape-emoji) [](https://github.com/sponsors/matteobruni)
|
|
8
|
+
|
|
9
|
+
[tsParticles](https://github.com/tsparticles/tsparticles) additional emoji shape.
|
|
10
|
+
|
|
11
|
+
## How to use it
|
|
12
|
+
|
|
13
|
+
### CDN / Vanilla JS / jQuery
|
|
14
|
+
|
|
15
|
+
The CDN/Vanilla version JS has one required file in vanilla configuration:
|
|
16
|
+
|
|
17
|
+
Including the `tsparticles.shape.emoji.min.js` file will export the function to load the shape:
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
loadEmojiShape;
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Usage
|
|
24
|
+
|
|
25
|
+
Once the scripts are loaded you can set up `tsParticles` and the shape like this:
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
(async () => {
|
|
29
|
+
await loadEmojiShape(tsParticles);
|
|
30
|
+
|
|
31
|
+
await tsParticles.load({
|
|
32
|
+
id: "tsparticles",
|
|
33
|
+
options: {
|
|
34
|
+
/* options */
|
|
35
|
+
/* here you can use particles.shape.type: "emoji" */
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
})();
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### ESM / CommonJS
|
|
42
|
+
|
|
43
|
+
This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
|
|
44
|
+
|
|
45
|
+
```shell
|
|
46
|
+
$ npm install @tsparticles/shape-emoji
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
or
|
|
50
|
+
|
|
51
|
+
```shell
|
|
52
|
+
$ yarn add @tsparticles/shape-emoji
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Then you need to import it in the app, like this:
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
const { tsParticles } = require("@tsparticles/engine");
|
|
59
|
+
const { loadEmojiShape } = require("@tsparticles/shape-emoji");
|
|
60
|
+
|
|
61
|
+
(async () => {
|
|
62
|
+
await loadEmojiShape(tsParticles);
|
|
63
|
+
})();
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
or
|
|
67
|
+
|
|
68
|
+
```javascript
|
|
69
|
+
import { tsParticles } from "@tsparticles/engine";
|
|
70
|
+
import { loadEmojiShape } from "@tsparticles/shape-emoji";
|
|
71
|
+
|
|
72
|
+
(async () => {
|
|
73
|
+
await loadEmojiShape(tsParticles);
|
|
74
|
+
})();
|
|
75
|
+
```
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { executeOnSingleOrMultiple, getRangeMax, isInArray, itemFromSingleOrMultiple, loadFont, } from "@tsparticles/engine";
|
|
2
|
+
export const validTypes = ["emoji"];
|
|
3
|
+
const defaultFont = '"Twemoji Mozilla", Apple Color Emoji, "Segoe UI Emoji", "Noto Color Emoji", "EmojiOne Color"';
|
|
4
|
+
export class EmojiDrawer {
|
|
5
|
+
constructor() {
|
|
6
|
+
this._emojiShapeDict = new Map();
|
|
7
|
+
}
|
|
8
|
+
destroy() {
|
|
9
|
+
for (const [, emojiData] of this._emojiShapeDict) {
|
|
10
|
+
emojiData?.close();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
draw(data) {
|
|
14
|
+
const { context, particle, radius, opacity } = data, emojiData = particle.emojiData;
|
|
15
|
+
if (!emojiData) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
context.globalAlpha = opacity;
|
|
19
|
+
context.drawImage(emojiData, -radius, -radius, radius * 2, radius * 2);
|
|
20
|
+
context.globalAlpha = 1;
|
|
21
|
+
}
|
|
22
|
+
async init(container) {
|
|
23
|
+
const options = container.actualOptions;
|
|
24
|
+
if (validTypes.find((t) => isInArray(t, options.particles.shape.type))) {
|
|
25
|
+
const promises = [loadFont(defaultFont)], shapeOptions = validTypes
|
|
26
|
+
.map((t) => options.particles.shape.options[t])
|
|
27
|
+
.find((t) => !!t);
|
|
28
|
+
if (shapeOptions) {
|
|
29
|
+
executeOnSingleOrMultiple(shapeOptions, (shape) => {
|
|
30
|
+
shape.font && promises.push(loadFont(shape.font));
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
await Promise.all(promises);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
particleDestroy(particle) {
|
|
37
|
+
delete particle.emojiData;
|
|
38
|
+
}
|
|
39
|
+
particleInit(container, particle) {
|
|
40
|
+
if (!particle.emojiData) {
|
|
41
|
+
const shapeData = particle.shapeData;
|
|
42
|
+
if (!shapeData?.value) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const emoji = itemFromSingleOrMultiple(shapeData.value, particle.randomIndexData), font = shapeData.font ?? defaultFont;
|
|
46
|
+
if (!emoji) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const key = `${emoji}_${font}`, existingData = this._emojiShapeDict.get(key);
|
|
50
|
+
if (existingData) {
|
|
51
|
+
particle.emojiData = existingData;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const canvasSize = getRangeMax(particle.size.value) * 2, canvas = new OffscreenCanvas(canvasSize, canvasSize);
|
|
55
|
+
const context = canvas.getContext("2d");
|
|
56
|
+
if (!context) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
context.font = `400 ${getRangeMax(particle.size.value) * 2}px ${font}`;
|
|
60
|
+
context.textBaseline = "middle";
|
|
61
|
+
context.textAlign = "center";
|
|
62
|
+
context.fillText(emoji, getRangeMax(particle.size.value), getRangeMax(particle.size.value));
|
|
63
|
+
const emojiData = canvas.transferToImageBitmap();
|
|
64
|
+
this._emojiShapeDict.set(key, emojiData);
|
|
65
|
+
particle.emojiData = emojiData;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/browser/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "module" }
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmojiDrawer = exports.validTypes = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
exports.validTypes = ["emoji"];
|
|
6
|
+
const defaultFont = '"Twemoji Mozilla", Apple Color Emoji, "Segoe UI Emoji", "Noto Color Emoji", "EmojiOne Color"';
|
|
7
|
+
class EmojiDrawer {
|
|
8
|
+
constructor() {
|
|
9
|
+
this._emojiShapeDict = new Map();
|
|
10
|
+
}
|
|
11
|
+
destroy() {
|
|
12
|
+
for (const [, emojiData] of this._emojiShapeDict) {
|
|
13
|
+
emojiData?.close();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
draw(data) {
|
|
17
|
+
const { context, particle, radius, opacity } = data, emojiData = particle.emojiData;
|
|
18
|
+
if (!emojiData) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
context.globalAlpha = opacity;
|
|
22
|
+
context.drawImage(emojiData, -radius, -radius, radius * 2, radius * 2);
|
|
23
|
+
context.globalAlpha = 1;
|
|
24
|
+
}
|
|
25
|
+
async init(container) {
|
|
26
|
+
const options = container.actualOptions;
|
|
27
|
+
if (exports.validTypes.find((t) => (0, engine_1.isInArray)(t, options.particles.shape.type))) {
|
|
28
|
+
const promises = [(0, engine_1.loadFont)(defaultFont)], shapeOptions = exports.validTypes
|
|
29
|
+
.map((t) => options.particles.shape.options[t])
|
|
30
|
+
.find((t) => !!t);
|
|
31
|
+
if (shapeOptions) {
|
|
32
|
+
(0, engine_1.executeOnSingleOrMultiple)(shapeOptions, (shape) => {
|
|
33
|
+
shape.font && promises.push((0, engine_1.loadFont)(shape.font));
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
await Promise.all(promises);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
particleDestroy(particle) {
|
|
40
|
+
delete particle.emojiData;
|
|
41
|
+
}
|
|
42
|
+
particleInit(container, particle) {
|
|
43
|
+
if (!particle.emojiData) {
|
|
44
|
+
const shapeData = particle.shapeData;
|
|
45
|
+
if (!shapeData?.value) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const emoji = (0, engine_1.itemFromSingleOrMultiple)(shapeData.value, particle.randomIndexData), font = shapeData.font ?? defaultFont;
|
|
49
|
+
if (!emoji) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const key = `${emoji}_${font}`, existingData = this._emojiShapeDict.get(key);
|
|
53
|
+
if (existingData) {
|
|
54
|
+
particle.emojiData = existingData;
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const canvasSize = (0, engine_1.getRangeMax)(particle.size.value) * 2, canvas = new OffscreenCanvas(canvasSize, canvasSize);
|
|
58
|
+
const context = canvas.getContext("2d");
|
|
59
|
+
if (!context) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
context.font = `400 ${(0, engine_1.getRangeMax)(particle.size.value) * 2}px ${font}`;
|
|
63
|
+
context.textBaseline = "middle";
|
|
64
|
+
context.textAlign = "center";
|
|
65
|
+
context.fillText(emoji, (0, engine_1.getRangeMax)(particle.size.value), (0, engine_1.getRangeMax)(particle.size.value));
|
|
66
|
+
const emojiData = canvas.transferToImageBitmap();
|
|
67
|
+
this._emojiShapeDict.set(key, emojiData);
|
|
68
|
+
particle.emojiData = emojiData;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.EmojiDrawer = EmojiDrawer;
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadEmojiShape = void 0;
|
|
4
|
+
const EmojiDrawer_js_1 = require("./EmojiDrawer.js");
|
|
5
|
+
async function loadEmojiShape(engine, refresh = true) {
|
|
6
|
+
await engine.addShape(EmojiDrawer_js_1.validTypes, new EmojiDrawer_js_1.EmojiDrawer(), refresh);
|
|
7
|
+
}
|
|
8
|
+
exports.loadEmojiShape = loadEmojiShape;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "commonjs" }
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { executeOnSingleOrMultiple, getRangeMax, isInArray, itemFromSingleOrMultiple, loadFont, } from "@tsparticles/engine";
|
|
2
|
+
export const validTypes = ["emoji"];
|
|
3
|
+
const defaultFont = '"Twemoji Mozilla", Apple Color Emoji, "Segoe UI Emoji", "Noto Color Emoji", "EmojiOne Color"';
|
|
4
|
+
export class EmojiDrawer {
|
|
5
|
+
constructor() {
|
|
6
|
+
this._emojiShapeDict = new Map();
|
|
7
|
+
}
|
|
8
|
+
destroy() {
|
|
9
|
+
for (const [, emojiData] of this._emojiShapeDict) {
|
|
10
|
+
emojiData?.close();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
draw(data) {
|
|
14
|
+
const { context, particle, radius, opacity } = data, emojiData = particle.emojiData;
|
|
15
|
+
if (!emojiData) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
context.globalAlpha = opacity;
|
|
19
|
+
context.drawImage(emojiData, -radius, -radius, radius * 2, radius * 2);
|
|
20
|
+
context.globalAlpha = 1;
|
|
21
|
+
}
|
|
22
|
+
async init(container) {
|
|
23
|
+
const options = container.actualOptions;
|
|
24
|
+
if (validTypes.find((t) => isInArray(t, options.particles.shape.type))) {
|
|
25
|
+
const promises = [loadFont(defaultFont)], shapeOptions = validTypes
|
|
26
|
+
.map((t) => options.particles.shape.options[t])
|
|
27
|
+
.find((t) => !!t);
|
|
28
|
+
if (shapeOptions) {
|
|
29
|
+
executeOnSingleOrMultiple(shapeOptions, (shape) => {
|
|
30
|
+
shape.font && promises.push(loadFont(shape.font));
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
await Promise.all(promises);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
particleDestroy(particle) {
|
|
37
|
+
delete particle.emojiData;
|
|
38
|
+
}
|
|
39
|
+
particleInit(container, particle) {
|
|
40
|
+
if (!particle.emojiData) {
|
|
41
|
+
const shapeData = particle.shapeData;
|
|
42
|
+
if (!shapeData?.value) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const emoji = itemFromSingleOrMultiple(shapeData.value, particle.randomIndexData), font = shapeData.font ?? defaultFont;
|
|
46
|
+
if (!emoji) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const key = `${emoji}_${font}`, existingData = this._emojiShapeDict.get(key);
|
|
50
|
+
if (existingData) {
|
|
51
|
+
particle.emojiData = existingData;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const canvasSize = getRangeMax(particle.size.value) * 2, canvas = new OffscreenCanvas(canvasSize, canvasSize);
|
|
55
|
+
const context = canvas.getContext("2d");
|
|
56
|
+
if (!context) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
context.font = `400 ${getRangeMax(particle.size.value) * 2}px ${font}`;
|
|
60
|
+
context.textBaseline = "middle";
|
|
61
|
+
context.textAlign = "center";
|
|
62
|
+
context.fillText(emoji, getRangeMax(particle.size.value), getRangeMax(particle.size.value));
|
|
63
|
+
const emojiData = canvas.transferToImageBitmap();
|
|
64
|
+
this._emojiShapeDict.set(key, emojiData);
|
|
65
|
+
particle.emojiData = emojiData;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/index.js
ADDED
package/esm/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "module" }
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tsparticles/shape-emoji",
|
|
3
|
+
"version": "3.0.0-beta.5",
|
|
4
|
+
"description": "tsParticles emoji shape",
|
|
5
|
+
"homepage": "https://particles.js.org",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/tsparticles/tsparticles.git",
|
|
9
|
+
"directory": "shapes/emoji"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"front-end",
|
|
13
|
+
"frontend",
|
|
14
|
+
"tsparticles",
|
|
15
|
+
"particles",
|
|
16
|
+
"particle",
|
|
17
|
+
"canvas",
|
|
18
|
+
"jsparticles",
|
|
19
|
+
"xparticles",
|
|
20
|
+
"particles-js",
|
|
21
|
+
"particles.js",
|
|
22
|
+
"particles-ts",
|
|
23
|
+
"particles.ts",
|
|
24
|
+
"typescript",
|
|
25
|
+
"javascript",
|
|
26
|
+
"animation",
|
|
27
|
+
"web",
|
|
28
|
+
"html5",
|
|
29
|
+
"web-design",
|
|
30
|
+
"webdesign",
|
|
31
|
+
"css",
|
|
32
|
+
"html",
|
|
33
|
+
"css3",
|
|
34
|
+
"animated",
|
|
35
|
+
"background",
|
|
36
|
+
"tsparticles-shape"
|
|
37
|
+
],
|
|
38
|
+
"author": "Matteo Bruni <matteo.bruni@me.com>",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/tsparticles/tsparticles/issues"
|
|
42
|
+
},
|
|
43
|
+
"sideEffects": false,
|
|
44
|
+
"jsdelivr": "tsparticles.shape.emoji.min.js",
|
|
45
|
+
"unpkg": "tsparticles.shape.emoji.min.js",
|
|
46
|
+
"browser": "browser/index.js",
|
|
47
|
+
"main": "cjs/index.js",
|
|
48
|
+
"module": "esm/index.js",
|
|
49
|
+
"types": "types/index.d.ts",
|
|
50
|
+
"exports": {
|
|
51
|
+
".": {
|
|
52
|
+
"types": "./types/index.d.ts",
|
|
53
|
+
"browser": "./browser/index.js",
|
|
54
|
+
"import": "./esm/index.js",
|
|
55
|
+
"require": "./cjs/index.js",
|
|
56
|
+
"umd": "./umd/index.js",
|
|
57
|
+
"default": "./cjs/index.js"
|
|
58
|
+
},
|
|
59
|
+
"./package.json": "./package.json"
|
|
60
|
+
},
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"@tsparticles/engine": "^3.0.0-beta.5"
|
|
63
|
+
},
|
|
64
|
+
"publishConfig": {
|
|
65
|
+
"access": "public"
|
|
66
|
+
}
|
|
67
|
+
}
|