@tsparticles/shape-emoji 3.9.1 → 4.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/508.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 508.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_shape_emoji=this.webpackChunk_tsparticles_shape_emoji||[]).push([[508],{508(e,t,i){i.d(t,{EmojiDrawer:()=>n});var a=i(303);const o='"Twemoji Mozilla", Apple Color Emoji, "Segoe UI Emoji", "Noto Color Emoji", "EmojiOne Color"';class n{constructor(){this.validTypes=["emoji"],this._emojiShapeDict=new Map}destroy(){for(const[e,t]of this._emojiShapeDict)t instanceof ImageBitmap&&t.close(),this._emojiShapeDict.delete(e)}draw(e){const t=e.particle.emojiDataKey;if(!t)return;const i=this._emojiShapeDict.get(t);i&&function(e,t){const{context:i,opacity:a}=e,o=i.globalAlpha,n=t.width,s=.5*n;i.globalAlpha=a,i.drawImage(t,-s,-s,n,n),i.globalAlpha=o}(e,i)}async init(e){const t=e.actualOptions,{validTypes:i}=this;if(!i.find((e=>(0,a.isInArray)(e,t.particles.shape.type))))return;const n=[(0,a.loadFont)(o)],s=i.map((e=>t.particles.shape.options[e]))[0];(0,a.executeOnSingleOrMultiple)(s,(e=>{e.font&&n.push((0,a.loadFont)(e.font))})),await Promise.all(n)}particleDestroy(e){e.emojiDataKey=void 0}particleInit(e,t){const i=t.shapeData;if(!i.value)return;const n=(0,a.itemFromSingleOrMultiple)(i.value,t.randomIndexData);if(!n)return;const s="string"==typeof n?{font:i.font??o,padding:i.padding??0,value:n}:{font:o,padding:0,...i,...n},l=s.font,r=s.value,c=`${r}_${l}`;if(this._emojiShapeDict.has(c))return void(t.emojiDataKey=c);const p=2*s.padding,h=(0,a.getRangeMax)(t.size.value),m=h+p,d=2*m;let f;if("undefined"!=typeof OffscreenCanvas){const e=new OffscreenCanvas(d,d),t=e.getContext("2d");if(!t)return;t.font=`400 ${(2*h).toString()}px ${l}`,t.textBaseline="middle",t.textAlign="center",t.fillText(r,m,m),f=e.transferToImageBitmap()}else{const e=(0,a.safeDocument)().createElement("canvas");e.width=d,e.height=d;const t=e.getContext("2d");if(!t)return;t.font=`400 ${(2*h).toString()}px ${l}`,t.textBaseline="middle",t.textAlign="center",t.fillText(r,m,m),f=e}this._emojiShapeDict.set(c,f),t.emojiDataKey=c}}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Emoji Shape v4.0.0-alpha.0 by Matteo Bruni */
@@ -1,6 +1,6 @@
1
- import { executeOnSingleOrMultiple, getRangeMax, isInArray, itemFromSingleOrMultiple, loadFont, } from "@tsparticles/engine";
1
+ import { executeOnSingleOrMultiple, getRangeMax, isInArray, itemFromSingleOrMultiple, loadFont, safeDocument, } from "@tsparticles/engine";
2
2
  import { drawEmoji } from "./Utils.js";
3
- const defaultFont = '"Twemoji Mozilla", Apple Color Emoji, "Segoe UI Emoji", "Noto Color Emoji", "EmojiOne Color"', noPadding = 0;
3
+ const defaultFont = '"Twemoji Mozilla", Apple Color Emoji, "Segoe UI Emoji", "Noto Color Emoji", "EmojiOne Color"', noPadding = 0, firstItem = 0;
4
4
  export class EmojiDrawer {
5
5
  constructor() {
6
6
  this.validTypes = ["emoji"];
@@ -9,7 +9,7 @@ export class EmojiDrawer {
9
9
  destroy() {
10
10
  for (const [key, data] of this._emojiShapeDict) {
11
11
  if (data instanceof ImageBitmap) {
12
- data?.close();
12
+ data.close();
13
13
  }
14
14
  this._emojiShapeDict.delete(key);
15
15
  }
@@ -30,16 +30,12 @@ export class EmojiDrawer {
30
30
  if (!validTypes.find(t => isInArray(t, options.particles.shape.type))) {
31
31
  return;
32
32
  }
33
- const promises = [loadFont(defaultFont)], shapeOptions = validTypes
34
- .map(t => options.particles.shape.options[t])
35
- .find(t => !!t);
36
- if (shapeOptions) {
37
- executeOnSingleOrMultiple(shapeOptions, shape => {
38
- if (shape.font) {
39
- promises.push(loadFont(shape.font));
40
- }
41
- });
42
- }
33
+ const promises = [loadFont(defaultFont)], shapeOptions = validTypes.map(t => options.particles.shape.options[t])[firstItem];
34
+ executeOnSingleOrMultiple(shapeOptions, shape => {
35
+ if (shape.font) {
36
+ promises.push(loadFont(shape.font));
37
+ }
38
+ });
43
39
  await Promise.all(promises);
44
40
  }
45
41
  particleDestroy(particle) {
@@ -47,7 +43,7 @@ export class EmojiDrawer {
47
43
  }
48
44
  particleInit(_container, particle) {
49
45
  const double = 2, shapeData = particle.shapeData;
50
- if (!shapeData?.value) {
46
+ if (!shapeData.value) {
51
47
  return;
52
48
  }
53
49
  const emoji = itemFromSingleOrMultiple(shapeData.value, particle.randomIndexData);
@@ -78,21 +74,21 @@ export class EmojiDrawer {
78
74
  if (!context) {
79
75
  return;
80
76
  }
81
- context.font = `400 ${maxSize * double}px ${font}`;
77
+ context.font = `400 ${(maxSize * double).toString()}px ${font}`;
82
78
  context.textBaseline = "middle";
83
79
  context.textAlign = "center";
84
80
  context.fillText(value, fullSize, fullSize);
85
81
  image = canvas.transferToImageBitmap();
86
82
  }
87
83
  else {
88
- const canvas = document.createElement("canvas");
84
+ const canvas = safeDocument().createElement("canvas");
89
85
  canvas.width = canvasSize;
90
86
  canvas.height = canvasSize;
91
87
  const context = canvas.getContext("2d");
92
88
  if (!context) {
93
89
  return;
94
90
  }
95
- context.font = `400 ${maxSize * double}px ${font}`;
91
+ context.font = `400 ${(maxSize * double).toString()}px ${font}`;
96
92
  context.textBaseline = "middle";
97
93
  context.textAlign = "center";
98
94
  context.fillText(value, fullSize, fullSize);
package/browser/Utils.js CHANGED
@@ -1,9 +1,5 @@
1
1
  export function drawEmoji(data, image) {
2
- const { context, opacity } = data, half = 0.5, previousAlpha = context.globalAlpha;
3
- if (!image) {
4
- return;
5
- }
6
- const diameter = image.width, radius = diameter * half;
2
+ const { context, opacity } = data, half = 0.5, previousAlpha = context.globalAlpha, diameter = image.width, radius = diameter * half;
7
3
  context.globalAlpha = opacity;
8
4
  context.drawImage(image, -radius, -radius, diameter, diameter);
9
5
  context.globalAlpha = previousAlpha;
package/browser/index.js CHANGED
@@ -1,5 +1,7 @@
1
- import { EmojiDrawer } from "./EmojiDrawer.js";
2
- export async function loadEmojiShape(engine, refresh = true) {
3
- engine.checkVersion("3.9.1");
4
- await engine.addShape(new EmojiDrawer(), refresh);
1
+ export function loadEmojiShape(engine) {
2
+ engine.checkVersion("4.0.0-alpha.0");
3
+ engine.register(async (e) => {
4
+ const { EmojiDrawer } = await import("./EmojiDrawer.js");
5
+ e.addShape(new EmojiDrawer());
6
+ });
5
7
  }
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EmojiDrawer = void 0;
4
- const engine_1 = require("@tsparticles/engine");
5
- const Utils_js_1 = require("./Utils.js");
6
- const defaultFont = '"Twemoji Mozilla", Apple Color Emoji, "Segoe UI Emoji", "Noto Color Emoji", "EmojiOne Color"', noPadding = 0;
7
- class EmojiDrawer {
1
+ import { executeOnSingleOrMultiple, getRangeMax, isInArray, itemFromSingleOrMultiple, loadFont, safeDocument, } from "@tsparticles/engine";
2
+ import { drawEmoji } from "./Utils.js";
3
+ const defaultFont = '"Twemoji Mozilla", Apple Color Emoji, "Segoe UI Emoji", "Noto Color Emoji", "EmojiOne Color"', noPadding = 0, firstItem = 0;
4
+ export class EmojiDrawer {
8
5
  constructor() {
9
6
  this.validTypes = ["emoji"];
10
7
  this._emojiShapeDict = new Map();
@@ -12,7 +9,7 @@ class EmojiDrawer {
12
9
  destroy() {
13
10
  for (const [key, data] of this._emojiShapeDict) {
14
11
  if (data instanceof ImageBitmap) {
15
- data?.close();
12
+ data.close();
16
13
  }
17
14
  this._emojiShapeDict.delete(key);
18
15
  }
@@ -26,23 +23,19 @@ class EmojiDrawer {
26
23
  if (!image) {
27
24
  return;
28
25
  }
29
- (0, Utils_js_1.drawEmoji)(data, image);
26
+ drawEmoji(data, image);
30
27
  }
31
28
  async init(container) {
32
29
  const options = container.actualOptions, { validTypes } = this;
33
- if (!validTypes.find(t => (0, engine_1.isInArray)(t, options.particles.shape.type))) {
30
+ if (!validTypes.find(t => isInArray(t, options.particles.shape.type))) {
34
31
  return;
35
32
  }
36
- const promises = [(0, engine_1.loadFont)(defaultFont)], shapeOptions = validTypes
37
- .map(t => options.particles.shape.options[t])
38
- .find(t => !!t);
39
- if (shapeOptions) {
40
- (0, engine_1.executeOnSingleOrMultiple)(shapeOptions, shape => {
41
- if (shape.font) {
42
- promises.push((0, engine_1.loadFont)(shape.font));
43
- }
44
- });
45
- }
33
+ const promises = [loadFont(defaultFont)], shapeOptions = validTypes.map(t => options.particles.shape.options[t])[firstItem];
34
+ executeOnSingleOrMultiple(shapeOptions, shape => {
35
+ if (shape.font) {
36
+ promises.push(loadFont(shape.font));
37
+ }
38
+ });
46
39
  await Promise.all(promises);
47
40
  }
48
41
  particleDestroy(particle) {
@@ -50,10 +43,10 @@ class EmojiDrawer {
50
43
  }
51
44
  particleInit(_container, particle) {
52
45
  const double = 2, shapeData = particle.shapeData;
53
- if (!shapeData?.value) {
46
+ if (!shapeData.value) {
54
47
  return;
55
48
  }
56
- const emoji = (0, engine_1.itemFromSingleOrMultiple)(shapeData.value, particle.randomIndexData);
49
+ const emoji = itemFromSingleOrMultiple(shapeData.value, particle.randomIndexData);
57
50
  if (!emoji) {
58
51
  return;
59
52
  }
@@ -74,28 +67,28 @@ class EmojiDrawer {
74
67
  particle.emojiDataKey = key;
75
68
  return;
76
69
  }
77
- const padding = emojiOptions.padding * double, maxSize = (0, engine_1.getRangeMax)(particle.size.value), fullSize = maxSize + padding, canvasSize = fullSize * double;
70
+ const padding = emojiOptions.padding * double, maxSize = getRangeMax(particle.size.value), fullSize = maxSize + padding, canvasSize = fullSize * double;
78
71
  let image;
79
72
  if (typeof OffscreenCanvas !== "undefined") {
80
73
  const canvas = new OffscreenCanvas(canvasSize, canvasSize), context = canvas.getContext("2d");
81
74
  if (!context) {
82
75
  return;
83
76
  }
84
- context.font = `400 ${maxSize * double}px ${font}`;
77
+ context.font = `400 ${(maxSize * double).toString()}px ${font}`;
85
78
  context.textBaseline = "middle";
86
79
  context.textAlign = "center";
87
80
  context.fillText(value, fullSize, fullSize);
88
81
  image = canvas.transferToImageBitmap();
89
82
  }
90
83
  else {
91
- const canvas = document.createElement("canvas");
84
+ const canvas = safeDocument().createElement("canvas");
92
85
  canvas.width = canvasSize;
93
86
  canvas.height = canvasSize;
94
87
  const context = canvas.getContext("2d");
95
88
  if (!context) {
96
89
  return;
97
90
  }
98
- context.font = `400 ${maxSize * double}px ${font}`;
91
+ context.font = `400 ${(maxSize * double).toString()}px ${font}`;
99
92
  context.textBaseline = "middle";
100
93
  context.textAlign = "center";
101
94
  context.fillText(value, fullSize, fullSize);
@@ -105,4 +98,3 @@ class EmojiDrawer {
105
98
  particle.emojiDataKey = key;
106
99
  }
107
100
  }
108
- exports.EmojiDrawer = EmojiDrawer;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/cjs/Utils.js CHANGED
@@ -1,12 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.drawEmoji = drawEmoji;
4
- function drawEmoji(data, image) {
5
- const { context, opacity } = data, half = 0.5, previousAlpha = context.globalAlpha;
6
- if (!image) {
7
- return;
8
- }
9
- const diameter = image.width, radius = diameter * half;
1
+ export function drawEmoji(data, image) {
2
+ const { context, opacity } = data, half = 0.5, previousAlpha = context.globalAlpha, diameter = image.width, radius = diameter * half;
10
3
  context.globalAlpha = opacity;
11
4
  context.drawImage(image, -radius, -radius, diameter, diameter);
12
5
  context.globalAlpha = previousAlpha;
package/cjs/index.js CHANGED
@@ -1,8 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadEmojiShape = loadEmojiShape;
4
- const EmojiDrawer_js_1 = require("./EmojiDrawer.js");
5
- async function loadEmojiShape(engine, refresh = true) {
6
- engine.checkVersion("3.9.1");
7
- await engine.addShape(new EmojiDrawer_js_1.EmojiDrawer(), refresh);
1
+ export function loadEmojiShape(engine) {
2
+ engine.checkVersion("4.0.0-alpha.0");
3
+ engine.register(async (e) => {
4
+ const { EmojiDrawer } = await import("./EmojiDrawer.js");
5
+ e.addShape(new EmojiDrawer());
6
+ });
8
7
  }
@@ -0,0 +1,40 @@
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
+ * v4.0.0-alpha.0
8
+ */
9
+ "use strict";
10
+ /*
11
+ * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
12
+ * This devtool is neither made for production nor for readable output files.
13
+ * It uses "eval()" calls to create a separate source file in the browser devtools.
14
+ * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
15
+ * or disable the default devtool with "devtool: false".
16
+ * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
17
+ */
18
+ (this["webpackChunk_tsparticles_shape_emoji"] = this["webpackChunk_tsparticles_shape_emoji"] || []).push([["dist_browser_EmojiDrawer_js"],{
19
+
20
+ /***/ "./dist/browser/EmojiDrawer.js"
21
+ /*!*************************************!*\
22
+ !*** ./dist/browser/EmojiDrawer.js ***!
23
+ \*************************************/
24
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
25
+
26
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ EmojiDrawer: () => (/* binding */ EmojiDrawer)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Utils.js */ \"./dist/browser/Utils.js\");\n\n\nconst defaultFont = '\"Twemoji Mozilla\", Apple Color Emoji, \"Segoe UI Emoji\", \"Noto Color Emoji\", \"EmojiOne Color\"',\n noPadding = 0,\n firstItem = 0;\nclass EmojiDrawer {\n constructor() {\n this.validTypes = [\"emoji\"];\n this._emojiShapeDict = new Map();\n }\n destroy() {\n for (const [key, data] of this._emojiShapeDict) {\n if (data instanceof ImageBitmap) {\n data.close();\n }\n this._emojiShapeDict.delete(key);\n }\n }\n draw(data) {\n const key = data.particle.emojiDataKey;\n if (!key) {\n return;\n }\n const image = this._emojiShapeDict.get(key);\n if (!image) {\n return;\n }\n (0,_Utils_js__WEBPACK_IMPORTED_MODULE_1__.drawEmoji)(data, image);\n }\n async init(container) {\n const options = container.actualOptions,\n {\n validTypes\n } = this;\n if (!validTypes.find(t => (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(t, options.particles.shape.type))) {\n return;\n }\n const promises = [(0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.loadFont)(defaultFont)],\n shapeOptions = validTypes.map(t => options.particles.shape.options[t])[firstItem];\n (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.executeOnSingleOrMultiple)(shapeOptions, shape => {\n if (shape.font) {\n promises.push((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.loadFont)(shape.font));\n }\n });\n await Promise.all(promises);\n }\n particleDestroy(particle) {\n particle.emojiDataKey = undefined;\n }\n particleInit(_container, particle) {\n const double = 2,\n shapeData = particle.shapeData;\n if (!shapeData.value) {\n return;\n }\n const emoji = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.itemFromSingleOrMultiple)(shapeData.value, particle.randomIndexData);\n if (!emoji) {\n return;\n }\n const emojiOptions = typeof emoji === \"string\" ? {\n font: shapeData.font ?? defaultFont,\n padding: shapeData.padding ?? noPadding,\n value: emoji\n } : {\n font: defaultFont,\n padding: noPadding,\n ...shapeData,\n ...emoji\n },\n font = emojiOptions.font,\n value = emojiOptions.value;\n const key = `${value}_${font}`;\n if (this._emojiShapeDict.has(key)) {\n particle.emojiDataKey = key;\n return;\n }\n const padding = emojiOptions.padding * double,\n maxSize = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeMax)(particle.size.value),\n fullSize = maxSize + padding,\n canvasSize = fullSize * double;\n let image;\n if (typeof OffscreenCanvas !== \"undefined\") {\n const canvas = new OffscreenCanvas(canvasSize, canvasSize),\n context = canvas.getContext(\"2d\");\n if (!context) {\n return;\n }\n context.font = `400 ${(maxSize * double).toString()}px ${font}`;\n context.textBaseline = \"middle\";\n context.textAlign = \"center\";\n context.fillText(value, fullSize, fullSize);\n image = canvas.transferToImageBitmap();\n } else {\n const canvas = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeDocument)().createElement(\"canvas\");\n canvas.width = canvasSize;\n canvas.height = canvasSize;\n const context = canvas.getContext(\"2d\");\n if (!context) {\n return;\n }\n context.font = `400 ${(maxSize * double).toString()}px ${font}`;\n context.textBaseline = \"middle\";\n context.textAlign = \"center\";\n context.fillText(value, fullSize, fullSize);\n image = canvas;\n }\n this._emojiShapeDict.set(key, image);\n particle.emojiDataKey = key;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/shape-emoji/./dist/browser/EmojiDrawer.js?\n}");
27
+
28
+ /***/ },
29
+
30
+ /***/ "./dist/browser/Utils.js"
31
+ /*!*******************************!*\
32
+ !*** ./dist/browser/Utils.js ***!
33
+ \*******************************/
34
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
35
+
36
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ drawEmoji: () => (/* binding */ drawEmoji)\n/* harmony export */ });\nfunction drawEmoji(data, image) {\n const {\n context,\n opacity\n } = data,\n half = 0.5,\n previousAlpha = context.globalAlpha,\n diameter = image.width,\n radius = diameter * half;\n context.globalAlpha = opacity;\n context.drawImage(image, -radius, -radius, diameter, diameter);\n context.globalAlpha = previousAlpha;\n}\n\n//# sourceURL=webpack://@tsparticles/shape-emoji/./dist/browser/Utils.js?\n}");
37
+
38
+ /***/ }
39
+
40
+ }]);
@@ -1,6 +1,6 @@
1
- import { executeOnSingleOrMultiple, getRangeMax, isInArray, itemFromSingleOrMultiple, loadFont, } from "@tsparticles/engine";
1
+ import { executeOnSingleOrMultiple, getRangeMax, isInArray, itemFromSingleOrMultiple, loadFont, safeDocument, } from "@tsparticles/engine";
2
2
  import { drawEmoji } from "./Utils.js";
3
- const defaultFont = '"Twemoji Mozilla", Apple Color Emoji, "Segoe UI Emoji", "Noto Color Emoji", "EmojiOne Color"', noPadding = 0;
3
+ const defaultFont = '"Twemoji Mozilla", Apple Color Emoji, "Segoe UI Emoji", "Noto Color Emoji", "EmojiOne Color"', noPadding = 0, firstItem = 0;
4
4
  export class EmojiDrawer {
5
5
  constructor() {
6
6
  this.validTypes = ["emoji"];
@@ -9,7 +9,7 @@ export class EmojiDrawer {
9
9
  destroy() {
10
10
  for (const [key, data] of this._emojiShapeDict) {
11
11
  if (data instanceof ImageBitmap) {
12
- data?.close();
12
+ data.close();
13
13
  }
14
14
  this._emojiShapeDict.delete(key);
15
15
  }
@@ -30,16 +30,12 @@ export class EmojiDrawer {
30
30
  if (!validTypes.find(t => isInArray(t, options.particles.shape.type))) {
31
31
  return;
32
32
  }
33
- const promises = [loadFont(defaultFont)], shapeOptions = validTypes
34
- .map(t => options.particles.shape.options[t])
35
- .find(t => !!t);
36
- if (shapeOptions) {
37
- executeOnSingleOrMultiple(shapeOptions, shape => {
38
- if (shape.font) {
39
- promises.push(loadFont(shape.font));
40
- }
41
- });
42
- }
33
+ const promises = [loadFont(defaultFont)], shapeOptions = validTypes.map(t => options.particles.shape.options[t])[firstItem];
34
+ executeOnSingleOrMultiple(shapeOptions, shape => {
35
+ if (shape.font) {
36
+ promises.push(loadFont(shape.font));
37
+ }
38
+ });
43
39
  await Promise.all(promises);
44
40
  }
45
41
  particleDestroy(particle) {
@@ -47,7 +43,7 @@ export class EmojiDrawer {
47
43
  }
48
44
  particleInit(_container, particle) {
49
45
  const double = 2, shapeData = particle.shapeData;
50
- if (!shapeData?.value) {
46
+ if (!shapeData.value) {
51
47
  return;
52
48
  }
53
49
  const emoji = itemFromSingleOrMultiple(shapeData.value, particle.randomIndexData);
@@ -78,21 +74,21 @@ export class EmojiDrawer {
78
74
  if (!context) {
79
75
  return;
80
76
  }
81
- context.font = `400 ${maxSize * double}px ${font}`;
77
+ context.font = `400 ${(maxSize * double).toString()}px ${font}`;
82
78
  context.textBaseline = "middle";
83
79
  context.textAlign = "center";
84
80
  context.fillText(value, fullSize, fullSize);
85
81
  image = canvas.transferToImageBitmap();
86
82
  }
87
83
  else {
88
- const canvas = document.createElement("canvas");
84
+ const canvas = safeDocument().createElement("canvas");
89
85
  canvas.width = canvasSize;
90
86
  canvas.height = canvasSize;
91
87
  const context = canvas.getContext("2d");
92
88
  if (!context) {
93
89
  return;
94
90
  }
95
- context.font = `400 ${maxSize * double}px ${font}`;
91
+ context.font = `400 ${(maxSize * double).toString()}px ${font}`;
96
92
  context.textBaseline = "middle";
97
93
  context.textAlign = "center";
98
94
  context.fillText(value, fullSize, fullSize);
package/esm/Utils.js CHANGED
@@ -1,9 +1,5 @@
1
1
  export function drawEmoji(data, image) {
2
- const { context, opacity } = data, half = 0.5, previousAlpha = context.globalAlpha;
3
- if (!image) {
4
- return;
5
- }
6
- const diameter = image.width, radius = diameter * half;
2
+ const { context, opacity } = data, half = 0.5, previousAlpha = context.globalAlpha, diameter = image.width, radius = diameter * half;
7
3
  context.globalAlpha = opacity;
8
4
  context.drawImage(image, -radius, -radius, diameter, diameter);
9
5
  context.globalAlpha = previousAlpha;
package/esm/index.js CHANGED
@@ -1,5 +1,7 @@
1
- import { EmojiDrawer } from "./EmojiDrawer.js";
2
- export async function loadEmojiShape(engine, refresh = true) {
3
- engine.checkVersion("3.9.1");
4
- await engine.addShape(new EmojiDrawer(), refresh);
1
+ export function loadEmojiShape(engine) {
2
+ engine.checkVersion("4.0.0-alpha.0");
3
+ engine.register(async (e) => {
4
+ const { EmojiDrawer } = await import("./EmojiDrawer.js");
5
+ e.addShape(new EmojiDrawer());
6
+ });
5
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/shape-emoji",
3
- "version": "3.9.1",
3
+ "version": "4.0.0-alpha.0",
4
4
  "description": "tsParticles emoji shape",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -59,9 +59,10 @@
59
59
  "./package.json": "./package.json"
60
60
  },
61
61
  "dependencies": {
62
- "@tsparticles/engine": "3.9.1"
62
+ "@tsparticles/engine": "4.0.0-alpha.0"
63
63
  },
64
64
  "publishConfig": {
65
65
  "access": "public"
66
- }
66
+ },
67
+ "type": "module"
67
68
  }