@tsparticles/shape-emoji 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/477.min.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";(this.webpackChunk_tsparticles_shape_emoji=this.webpackChunk_tsparticles_shape_emoji||[]).push([[477],{477(e,t,a){a.d(t,{EmojiDrawer:()=>l});var i=a(303),n=a(183),o=a(425);let s='"Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif';class l{_emojiShapeDict=new Map;destroy(){for(let[e,t]of this._emojiShapeDict)t instanceof ImageBitmap&&t.close(),this._emojiShapeDict.delete(e)}draw(e){let t=e.particle.emojiDataKey;if(!t)return;let a=this._emojiShapeDict.get(t);a&&(0,n.j)(e,a)}async init(e){let t=e.actualOptions.particles.shape;if(!n.u.some(e=>(0,i.isInArray)(e,t.type)))return;let a=[(0,o.loadFont)(s)],l=n.u.map(e=>t.options[e])[0];(0,i.executeOnSingleOrMultiple)(l,e=>{e.font&&a.push((0,o.loadFont)(e.font))}),await Promise.all(a)}particleDestroy(e){e.emojiDataKey=void 0}particleInit(e,t){let a,n,o=t.shapeData;if(!o.value)return;let l=(0,i.itemFromSingleOrMultiple)(o.value,t.randomIndexData);if(!l)return;let r="string"==typeof l?{font:o.font??s,padding:o.padding??0,value:l}:{font:s,padding:0,...o,...l},p=r.font,c=r.value,m=`${c}_${p}`;if(this._emojiShapeDict.has(m)){t.emojiDataKey=m;return}let f=r.padding*i.double,u=(0,i.getRangeMax)(t.size.value),d=u+f,h=d*i.double;if("u"<typeof OffscreenCanvas){let t=(0,i.safeDocument)().createElement("canvas");t.width=h,t.height=h,n=t.getContext("2d",e.canvas.settings),a=t}else n=(a=new OffscreenCanvas(h,h)).getContext("2d",e.canvas.settings);if(!n)return;n.font=`400 ${(u*i.double).toString()}px ${p}`,n.textBaseline="middle",n.textAlign="center",n.fillText(c,d,d);let g=a instanceof HTMLCanvasElement?a:a.transferToImageBitmap();this._emojiShapeDict.set(m,g),t.emojiDataKey=m}}}}]);
@@ -1,11 +1,9 @@
1
- import { double, 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;
1
+ import { double, executeOnSingleOrMultiple, getRangeMax, isInArray, itemFromSingleOrMultiple, safeDocument, } from "@tsparticles/engine";
2
+ import { drawEmoji, validTypes } from "./Utils.js";
3
+ import { loadFont } from "@tsparticles/canvas-utils";
4
+ const defaultFont = '"Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif', noPadding = 0, firstItem = 0;
4
5
  export class EmojiDrawer {
5
- constructor() {
6
- this.validTypes = ["emoji"];
7
- this._emojiShapeDict = new Map();
8
- }
6
+ _emojiShapeDict = new Map();
9
7
  destroy() {
10
8
  for (const [key, data] of this._emojiShapeDict) {
11
9
  if (data instanceof ImageBitmap) {
@@ -26,11 +24,11 @@ export class EmojiDrawer {
26
24
  drawEmoji(data, image);
27
25
  }
28
26
  async init(container) {
29
- const options = container.actualOptions, { validTypes } = this;
30
- if (!validTypes.find(t => isInArray(t, options.particles.shape.type))) {
27
+ const options = container.actualOptions, shapeData = options.particles.shape;
28
+ if (!validTypes.some(t => isInArray(t, shapeData.type))) {
31
29
  return;
32
30
  }
33
- const promises = [loadFont(defaultFont)], shapeOptions = validTypes.map(t => options.particles.shape.options[t])[firstItem];
31
+ const promises = [loadFont(defaultFont)], shapeOptions = validTypes.map(t => shapeData.options[t])[firstItem];
34
32
  executeOnSingleOrMultiple(shapeOptions, shape => {
35
33
  if (shape.font) {
36
34
  promises.push(loadFont(shape.font));
@@ -41,7 +39,7 @@ export class EmojiDrawer {
41
39
  particleDestroy(particle) {
42
40
  particle.emojiDataKey = undefined;
43
41
  }
44
- particleInit(_container, particle) {
42
+ particleInit(container, particle) {
45
43
  const shapeData = particle.shapeData;
46
44
  if (!shapeData.value) {
47
45
  return;
@@ -61,40 +59,33 @@ export class EmojiDrawer {
61
59
  padding: noPadding,
62
60
  ...shapeData,
63
61
  ...emoji,
64
- }, font = emojiOptions.font, value = emojiOptions.value;
65
- const key = `${value}_${font}`;
66
- if (this._emojiShapeDict.has(key)) {
67
- particle.emojiDataKey = key;
62
+ }, font = emojiOptions.font, value = emojiOptions.value, cacheKey = `${value}_${font}`;
63
+ if (this._emojiShapeDict.has(cacheKey)) {
64
+ particle.emojiDataKey = cacheKey;
68
65
  return;
69
66
  }
70
67
  const padding = emojiOptions.padding * double, maxSize = getRangeMax(particle.size.value), fullSize = maxSize + padding, canvasSize = fullSize * double;
71
- let image;
72
- if (typeof OffscreenCanvas !== "undefined") {
73
- const canvas = new OffscreenCanvas(canvasSize, canvasSize), context = canvas.getContext("2d");
74
- if (!context) {
75
- return;
76
- }
77
- context.font = `400 ${(maxSize * double).toString()}px ${font}`;
78
- context.textBaseline = "middle";
79
- context.textAlign = "center";
80
- context.fillText(value, fullSize, fullSize);
81
- image = canvas.transferToImageBitmap();
82
- }
83
- else {
68
+ let cacheCanvas, context;
69
+ if (typeof OffscreenCanvas === "undefined") {
84
70
  const canvas = safeDocument().createElement("canvas");
85
71
  canvas.width = canvasSize;
86
72
  canvas.height = canvasSize;
87
- const context = canvas.getContext("2d");
88
- if (!context) {
89
- return;
90
- }
91
- context.font = `400 ${(maxSize * double).toString()}px ${font}`;
92
- context.textBaseline = "middle";
93
- context.textAlign = "center";
94
- context.fillText(value, fullSize, fullSize);
95
- image = canvas;
73
+ context = canvas.getContext("2d", container.canvas.settings);
74
+ cacheCanvas = canvas;
75
+ }
76
+ else {
77
+ cacheCanvas = new OffscreenCanvas(canvasSize, canvasSize);
78
+ context = cacheCanvas.getContext("2d", container.canvas.settings);
79
+ }
80
+ if (!context) {
81
+ return;
96
82
  }
97
- this._emojiShapeDict.set(key, image);
98
- particle.emojiDataKey = key;
83
+ context.font = `400 ${(maxSize * double).toString()}px ${font}`;
84
+ context.textBaseline = "middle";
85
+ context.textAlign = "center";
86
+ context.fillText(value, fullSize, fullSize);
87
+ const image = cacheCanvas instanceof HTMLCanvasElement ? cacheCanvas : cacheCanvas.transferToImageBitmap();
88
+ this._emojiShapeDict.set(cacheKey, image);
89
+ particle.emojiDataKey = cacheKey;
99
90
  }
100
91
  }
package/browser/Utils.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { half } from "@tsparticles/engine";
2
+ export const validTypes = ["emoji"];
2
3
  export function drawEmoji(data, image) {
3
4
  const { context, opacity } = data, previousAlpha = context.globalAlpha, diameter = image.width, radius = diameter * half;
4
5
  context.globalAlpha = opacity;
package/browser/index.js CHANGED
@@ -1,7 +1,10 @@
1
+ import { validTypes } from "./Utils.js";
1
2
  export async function loadEmojiShape(engine) {
2
- engine.checkVersion("4.0.0-alpha.5");
3
- await engine.register(async (e) => {
4
- const { EmojiDrawer } = await import("./EmojiDrawer.js");
5
- e.addShape(new EmojiDrawer());
3
+ engine.checkVersion("4.0.0-beta.0");
4
+ await engine.register(e => {
5
+ e.addShape(validTypes, async () => {
6
+ const { EmojiDrawer } = await import("./EmojiDrawer.js");
7
+ return new EmojiDrawer();
8
+ });
6
9
  });
7
10
  }
@@ -1,11 +1,9 @@
1
- import { double, 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;
1
+ import { double, executeOnSingleOrMultiple, getRangeMax, isInArray, itemFromSingleOrMultiple, safeDocument, } from "@tsparticles/engine";
2
+ import { drawEmoji, validTypes } from "./Utils.js";
3
+ import { loadFont } from "@tsparticles/canvas-utils";
4
+ const defaultFont = '"Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif', noPadding = 0, firstItem = 0;
4
5
  export class EmojiDrawer {
5
- constructor() {
6
- this.validTypes = ["emoji"];
7
- this._emojiShapeDict = new Map();
8
- }
6
+ _emojiShapeDict = new Map();
9
7
  destroy() {
10
8
  for (const [key, data] of this._emojiShapeDict) {
11
9
  if (data instanceof ImageBitmap) {
@@ -26,11 +24,11 @@ export class EmojiDrawer {
26
24
  drawEmoji(data, image);
27
25
  }
28
26
  async init(container) {
29
- const options = container.actualOptions, { validTypes } = this;
30
- if (!validTypes.find(t => isInArray(t, options.particles.shape.type))) {
27
+ const options = container.actualOptions, shapeData = options.particles.shape;
28
+ if (!validTypes.some(t => isInArray(t, shapeData.type))) {
31
29
  return;
32
30
  }
33
- const promises = [loadFont(defaultFont)], shapeOptions = validTypes.map(t => options.particles.shape.options[t])[firstItem];
31
+ const promises = [loadFont(defaultFont)], shapeOptions = validTypes.map(t => shapeData.options[t])[firstItem];
34
32
  executeOnSingleOrMultiple(shapeOptions, shape => {
35
33
  if (shape.font) {
36
34
  promises.push(loadFont(shape.font));
@@ -41,7 +39,7 @@ export class EmojiDrawer {
41
39
  particleDestroy(particle) {
42
40
  particle.emojiDataKey = undefined;
43
41
  }
44
- particleInit(_container, particle) {
42
+ particleInit(container, particle) {
45
43
  const shapeData = particle.shapeData;
46
44
  if (!shapeData.value) {
47
45
  return;
@@ -61,40 +59,33 @@ export class EmojiDrawer {
61
59
  padding: noPadding,
62
60
  ...shapeData,
63
61
  ...emoji,
64
- }, font = emojiOptions.font, value = emojiOptions.value;
65
- const key = `${value}_${font}`;
66
- if (this._emojiShapeDict.has(key)) {
67
- particle.emojiDataKey = key;
62
+ }, font = emojiOptions.font, value = emojiOptions.value, cacheKey = `${value}_${font}`;
63
+ if (this._emojiShapeDict.has(cacheKey)) {
64
+ particle.emojiDataKey = cacheKey;
68
65
  return;
69
66
  }
70
67
  const padding = emojiOptions.padding * double, maxSize = getRangeMax(particle.size.value), fullSize = maxSize + padding, canvasSize = fullSize * double;
71
- let image;
72
- if (typeof OffscreenCanvas !== "undefined") {
73
- const canvas = new OffscreenCanvas(canvasSize, canvasSize), context = canvas.getContext("2d");
74
- if (!context) {
75
- return;
76
- }
77
- context.font = `400 ${(maxSize * double).toString()}px ${font}`;
78
- context.textBaseline = "middle";
79
- context.textAlign = "center";
80
- context.fillText(value, fullSize, fullSize);
81
- image = canvas.transferToImageBitmap();
82
- }
83
- else {
68
+ let cacheCanvas, context;
69
+ if (typeof OffscreenCanvas === "undefined") {
84
70
  const canvas = safeDocument().createElement("canvas");
85
71
  canvas.width = canvasSize;
86
72
  canvas.height = canvasSize;
87
- const context = canvas.getContext("2d");
88
- if (!context) {
89
- return;
90
- }
91
- context.font = `400 ${(maxSize * double).toString()}px ${font}`;
92
- context.textBaseline = "middle";
93
- context.textAlign = "center";
94
- context.fillText(value, fullSize, fullSize);
95
- image = canvas;
73
+ context = canvas.getContext("2d", container.canvas.settings);
74
+ cacheCanvas = canvas;
75
+ }
76
+ else {
77
+ cacheCanvas = new OffscreenCanvas(canvasSize, canvasSize);
78
+ context = cacheCanvas.getContext("2d", container.canvas.settings);
79
+ }
80
+ if (!context) {
81
+ return;
96
82
  }
97
- this._emojiShapeDict.set(key, image);
98
- particle.emojiDataKey = key;
83
+ context.font = `400 ${(maxSize * double).toString()}px ${font}`;
84
+ context.textBaseline = "middle";
85
+ context.textAlign = "center";
86
+ context.fillText(value, fullSize, fullSize);
87
+ const image = cacheCanvas instanceof HTMLCanvasElement ? cacheCanvas : cacheCanvas.transferToImageBitmap();
88
+ this._emojiShapeDict.set(cacheKey, image);
89
+ particle.emojiDataKey = cacheKey;
99
90
  }
100
91
  }
package/cjs/Utils.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { half } from "@tsparticles/engine";
2
+ export const validTypes = ["emoji"];
2
3
  export function drawEmoji(data, image) {
3
4
  const { context, opacity } = data, previousAlpha = context.globalAlpha, diameter = image.width, radius = diameter * half;
4
5
  context.globalAlpha = opacity;
package/cjs/index.js CHANGED
@@ -1,7 +1,10 @@
1
+ import { validTypes } from "./Utils.js";
1
2
  export async function loadEmojiShape(engine) {
2
- engine.checkVersion("4.0.0-alpha.5");
3
- await engine.register(async (e) => {
4
- const { EmojiDrawer } = await import("./EmojiDrawer.js");
5
- e.addShape(new EmojiDrawer());
3
+ engine.checkVersion("4.0.0-beta.0");
4
+ await engine.register(e => {
5
+ e.addShape(validTypes, async () => {
6
+ const { EmojiDrawer } = await import("./EmojiDrawer.js");
7
+ return new EmojiDrawer();
8
+ });
6
9
  });
7
10
  }
@@ -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-alpha.5
7
+ * v4.0.0-beta.0
8
8
  */
9
9
  "use strict";
10
10
  /*
@@ -23,17 +23,7 @@
23
23
  \*************************************/
24
24
  (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
25
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 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 * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.double,\n maxSize = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeMax)(particle.size.value),\n fullSize = maxSize + padding,\n canvasSize = fullSize * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.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 * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.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 * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.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 */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nfunction drawEmoji(data, image) {\n const {\n context,\n opacity\n } = data,\n previousAlpha = context.globalAlpha,\n diameter = image.width,\n radius = diameter * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.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}");
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/* harmony import */ var _tsparticles_canvas_utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @tsparticles/canvas-utils */ \"@tsparticles/canvas-utils\");\n\n\n\nconst defaultFont = '\"Apple Color Emoji\", \"Segoe UI Emoji\", \"Noto Color Emoji\", sans-serif', noPadding = 0, firstItem = 0;\nclass EmojiDrawer {\n _emojiShapeDict = new Map();\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, shapeData = options.particles.shape;\n if (!_Utils_js__WEBPACK_IMPORTED_MODULE_1__.validTypes.some((t)=>(0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(t, shapeData.type))) {\n return;\n }\n const promises = [\n (0,_tsparticles_canvas_utils__WEBPACK_IMPORTED_MODULE_2__.loadFont)(defaultFont)\n ], shapeOptions = _Utils_js__WEBPACK_IMPORTED_MODULE_1__.validTypes.map((t)=>shapeData.options[t])[firstItem];\n (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.executeOnSingleOrMultiple)(shapeOptions, (shape)=>{\n if (shape.font) {\n promises.push((0,_tsparticles_canvas_utils__WEBPACK_IMPORTED_MODULE_2__.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 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 }, font = emojiOptions.font, value = emojiOptions.value, cacheKey = `${value}_${font}`;\n if (this._emojiShapeDict.has(cacheKey)) {\n particle.emojiDataKey = cacheKey;\n return;\n }\n const padding = emojiOptions.padding * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.double, maxSize = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeMax)(particle.size.value), fullSize = maxSize + padding, canvasSize = fullSize * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.double;\n let cacheCanvas, context;\n if (typeof OffscreenCanvas === \"undefined\") {\n const canvas = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeDocument)().createElement(\"canvas\");\n canvas.width = canvasSize;\n canvas.height = canvasSize;\n context = canvas.getContext(\"2d\", container.canvas.settings);\n cacheCanvas = canvas;\n } else {\n cacheCanvas = new OffscreenCanvas(canvasSize, canvasSize);\n context = cacheCanvas.getContext(\"2d\", container.canvas.settings);\n }\n if (!context) {\n return;\n }\n context.font = `400 ${(maxSize * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.double).toString()}px ${font}`;\n context.textBaseline = \"middle\";\n context.textAlign = \"center\";\n context.fillText(value, fullSize, fullSize);\n const image = cacheCanvas instanceof HTMLCanvasElement ? cacheCanvas : cacheCanvas.transferToImageBitmap();\n this._emojiShapeDict.set(cacheKey, image);\n particle.emojiDataKey = cacheKey;\n }\n}\n\n\n//# sourceURL=webpack://@tsparticles/shape-emoji/./dist/browser/EmojiDrawer.js?\n}");
37
27
 
38
28
  /***/ }
39
29
 
@@ -1,11 +1,9 @@
1
- import { double, 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;
1
+ import { double, executeOnSingleOrMultiple, getRangeMax, isInArray, itemFromSingleOrMultiple, safeDocument, } from "@tsparticles/engine";
2
+ import { drawEmoji, validTypes } from "./Utils.js";
3
+ import { loadFont } from "@tsparticles/canvas-utils";
4
+ const defaultFont = '"Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif', noPadding = 0, firstItem = 0;
4
5
  export class EmojiDrawer {
5
- constructor() {
6
- this.validTypes = ["emoji"];
7
- this._emojiShapeDict = new Map();
8
- }
6
+ _emojiShapeDict = new Map();
9
7
  destroy() {
10
8
  for (const [key, data] of this._emojiShapeDict) {
11
9
  if (data instanceof ImageBitmap) {
@@ -26,11 +24,11 @@ export class EmojiDrawer {
26
24
  drawEmoji(data, image);
27
25
  }
28
26
  async init(container) {
29
- const options = container.actualOptions, { validTypes } = this;
30
- if (!validTypes.find(t => isInArray(t, options.particles.shape.type))) {
27
+ const options = container.actualOptions, shapeData = options.particles.shape;
28
+ if (!validTypes.some(t => isInArray(t, shapeData.type))) {
31
29
  return;
32
30
  }
33
- const promises = [loadFont(defaultFont)], shapeOptions = validTypes.map(t => options.particles.shape.options[t])[firstItem];
31
+ const promises = [loadFont(defaultFont)], shapeOptions = validTypes.map(t => shapeData.options[t])[firstItem];
34
32
  executeOnSingleOrMultiple(shapeOptions, shape => {
35
33
  if (shape.font) {
36
34
  promises.push(loadFont(shape.font));
@@ -41,7 +39,7 @@ export class EmojiDrawer {
41
39
  particleDestroy(particle) {
42
40
  particle.emojiDataKey = undefined;
43
41
  }
44
- particleInit(_container, particle) {
42
+ particleInit(container, particle) {
45
43
  const shapeData = particle.shapeData;
46
44
  if (!shapeData.value) {
47
45
  return;
@@ -61,40 +59,33 @@ export class EmojiDrawer {
61
59
  padding: noPadding,
62
60
  ...shapeData,
63
61
  ...emoji,
64
- }, font = emojiOptions.font, value = emojiOptions.value;
65
- const key = `${value}_${font}`;
66
- if (this._emojiShapeDict.has(key)) {
67
- particle.emojiDataKey = key;
62
+ }, font = emojiOptions.font, value = emojiOptions.value, cacheKey = `${value}_${font}`;
63
+ if (this._emojiShapeDict.has(cacheKey)) {
64
+ particle.emojiDataKey = cacheKey;
68
65
  return;
69
66
  }
70
67
  const padding = emojiOptions.padding * double, maxSize = getRangeMax(particle.size.value), fullSize = maxSize + padding, canvasSize = fullSize * double;
71
- let image;
72
- if (typeof OffscreenCanvas !== "undefined") {
73
- const canvas = new OffscreenCanvas(canvasSize, canvasSize), context = canvas.getContext("2d");
74
- if (!context) {
75
- return;
76
- }
77
- context.font = `400 ${(maxSize * double).toString()}px ${font}`;
78
- context.textBaseline = "middle";
79
- context.textAlign = "center";
80
- context.fillText(value, fullSize, fullSize);
81
- image = canvas.transferToImageBitmap();
82
- }
83
- else {
68
+ let cacheCanvas, context;
69
+ if (typeof OffscreenCanvas === "undefined") {
84
70
  const canvas = safeDocument().createElement("canvas");
85
71
  canvas.width = canvasSize;
86
72
  canvas.height = canvasSize;
87
- const context = canvas.getContext("2d");
88
- if (!context) {
89
- return;
90
- }
91
- context.font = `400 ${(maxSize * double).toString()}px ${font}`;
92
- context.textBaseline = "middle";
93
- context.textAlign = "center";
94
- context.fillText(value, fullSize, fullSize);
95
- image = canvas;
73
+ context = canvas.getContext("2d", container.canvas.settings);
74
+ cacheCanvas = canvas;
75
+ }
76
+ else {
77
+ cacheCanvas = new OffscreenCanvas(canvasSize, canvasSize);
78
+ context = cacheCanvas.getContext("2d", container.canvas.settings);
79
+ }
80
+ if (!context) {
81
+ return;
96
82
  }
97
- this._emojiShapeDict.set(key, image);
98
- particle.emojiDataKey = key;
83
+ context.font = `400 ${(maxSize * double).toString()}px ${font}`;
84
+ context.textBaseline = "middle";
85
+ context.textAlign = "center";
86
+ context.fillText(value, fullSize, fullSize);
87
+ const image = cacheCanvas instanceof HTMLCanvasElement ? cacheCanvas : cacheCanvas.transferToImageBitmap();
88
+ this._emojiShapeDict.set(cacheKey, image);
89
+ particle.emojiDataKey = cacheKey;
99
90
  }
100
91
  }
package/esm/Utils.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { half } from "@tsparticles/engine";
2
+ export const validTypes = ["emoji"];
2
3
  export function drawEmoji(data, image) {
3
4
  const { context, opacity } = data, previousAlpha = context.globalAlpha, diameter = image.width, radius = diameter * half;
4
5
  context.globalAlpha = opacity;
package/esm/index.js CHANGED
@@ -1,7 +1,10 @@
1
+ import { validTypes } from "./Utils.js";
1
2
  export async function loadEmojiShape(engine) {
2
- engine.checkVersion("4.0.0-alpha.5");
3
- await engine.register(async (e) => {
4
- const { EmojiDrawer } = await import("./EmojiDrawer.js");
5
- e.addShape(new EmojiDrawer());
3
+ engine.checkVersion("4.0.0-beta.0");
4
+ await engine.register(e => {
5
+ e.addShape(validTypes, async () => {
6
+ const { EmojiDrawer } = await import("./EmojiDrawer.js");
7
+ return new EmojiDrawer();
8
+ });
6
9
  });
7
10
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/shape-emoji",
3
- "version": "4.0.0-alpha.5",
3
+ "version": "4.0.0-beta.0",
4
4
  "description": "tsParticles emoji shape",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -59,7 +59,8 @@
59
59
  "./package.json": "./package.json"
60
60
  },
61
61
  "dependencies": {
62
- "@tsparticles/engine": "4.0.0-alpha.5"
62
+ "@tsparticles/canvas-utils": "4.0.0-beta.0",
63
+ "@tsparticles/engine": "4.0.0-beta.0"
63
64
  },
64
65
  "publishConfig": {
65
66
  "access": "public"