@tsparticles/plugin-emitters-shape-path 3.9.0 → 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/699.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 699.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_plugin_emitters_shape_path=this.webpackChunk_tsparticles_plugin_emitters_shape_path||[]).push([[699],{699(t,e,n){n.d(e,{EmittersPathShapeGenerator:()=>l});var o=n(526),i=n(303);const s=.5;const h=.5;class r extends o.EmitterShapeBase{constructor(t,e,n,o){super(t,e,n,o);const s=(0,i.safeDocument)().createElement("canvas").getContext("2d");if(!s)throw new Error("No 2d context available");this.checkContext=s,this.points=o.points;const r=this.points,a=new Path2D,c=t.x-e.width*h,p=t.y-e.height*h;for(const[t,n]of r.entries()){const o={x:c+n.x*e.width/i.percentDenominator,y:p+n.y*e.height/i.percentDenominator};t?a.lineTo(o.x,o.y):a.moveTo(o.x,o.y)}const l=r[0];if(!l)throw new Error("No path data available");const x={x:c+l.x*e.width/i.percentDenominator,y:p+l.y*e.height/i.percentDenominator};a.lineTo(x.x,x.y),this.path=a}async init(){}randomPosition(){const t=this.checkContext,e=this.position,n=this.size,o=this.fill,h=this.path,r=o?function(t,e,n,o){let h=null;for(let r=0;r<100;r++){const r={x:n.x+(0,i.getRandom)()*o.width-o.width*s,y:n.y+(0,i.getRandom)()*o.height-o.height*s};if(t.isPointInPath(e,r.x,r.y)){h=r;break}}return h}(t,h,e,n):function(t,e,n,o){let h=null;for(let r=0;r<100;r++){const r={x:n.x+(0,i.getRandom)()*o.width-o.width*s,y:n.y+(0,i.getRandom)()*o.height-o.height*s};if(t.isPointInStroke(e,r.x,r.y)){h=r;break}}return h}(t,h,e,n);return r?{position:r}:null}resize(t,e){super.resize(t,e);const n=this.points,o=new Path2D,s=t.x-e.width*h,r=t.y-e.height*h;for(const[t,h]of n.entries()){const n={x:s+h.x*e.width/i.percentDenominator,y:r+h.y*e.height/i.percentDenominator};t?o.lineTo(n.x,n.y):o.moveTo(n.x,n.y)}const a=n[0];if(!a)throw new Error("No path data available");const c={x:s+a.x*e.width/i.percentDenominator,y:r+a.y*e.height/i.percentDenominator};o.lineTo(c.x,c.y),this.path=o}}const a=50,c=50;class p{constructor(){this.points=[]}load(t){(0,i.isNull)(t)||void 0!==t.points&&(this.points=t.points.map((t=>({x:t.x??a,y:t.y??c}))))}}class l{generate(t,e,n,o){const i=new p;return i.load(o),new r(t,e,n,i)}}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Emitters Shape Path Plugin v4.0.0-alpha.0 by Matteo Bruni */
@@ -1,13 +1,13 @@
1
1
  import { EmitterShapeBase } from "@tsparticles/plugin-emitters";
2
- import { errorPrefix, percentDenominator } from "@tsparticles/engine";
2
+ import { percentDenominator, safeDocument } from "@tsparticles/engine";
3
3
  import { generateRandomPointOnPathPerimeter, generateRandomPointWithinPath } from "./utils.js";
4
4
  const half = 0.5;
5
5
  export class EmittersPathShape extends EmitterShapeBase {
6
6
  constructor(position, size, fill, options) {
7
7
  super(position, size, fill, options);
8
- const ctx = document.createElement("canvas").getContext("2d");
8
+ const ctx = safeDocument().createElement("canvas").getContext("2d");
9
9
  if (!ctx) {
10
- throw new Error(`${errorPrefix} No 2d context available`);
10
+ throw new Error(`No 2d context available`);
11
11
  }
12
12
  this.checkContext = ctx;
13
13
  this.points = options.points;
@@ -28,13 +28,14 @@ export class EmittersPathShape extends EmitterShapeBase {
28
28
  }
29
29
  }
30
30
  const firstIndex = 0, firstPathData = pathData[firstIndex];
31
- if (firstPathData) {
32
- const coords = {
33
- x: offset.x + (firstPathData.x * size.width) / percentDenominator,
34
- y: offset.y + (firstPathData.y * size.height) / percentDenominator,
35
- };
36
- path.lineTo(coords.x, coords.y);
31
+ if (!firstPathData) {
32
+ throw new Error(`No path data available`);
37
33
  }
34
+ const coords = {
35
+ x: offset.x + (firstPathData.x * size.width) / percentDenominator,
36
+ y: offset.y + (firstPathData.y * size.height) / percentDenominator,
37
+ };
38
+ path.lineTo(coords.x, coords.y);
38
39
  this.path = path;
39
40
  }
40
41
  async init() {
@@ -64,13 +65,14 @@ export class EmittersPathShape extends EmitterShapeBase {
64
65
  }
65
66
  }
66
67
  const firstIndex = 0, firstPathData = pathData[firstIndex];
67
- if (firstPathData) {
68
- const coords = {
69
- x: offset.x + (firstPathData.x * size.width) / percentDenominator,
70
- y: offset.y + (firstPathData.y * size.height) / percentDenominator,
71
- };
72
- path.lineTo(coords.x, coords.y);
68
+ if (!firstPathData) {
69
+ throw new Error(`No path data available`);
73
70
  }
71
+ const coords = {
72
+ x: offset.x + (firstPathData.x * size.width) / percentDenominator,
73
+ y: offset.y + (firstPathData.y * size.height) / percentDenominator,
74
+ };
75
+ path.lineTo(coords.x, coords.y);
74
76
  this.path = path;
75
77
  }
76
78
  }
package/browser/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { EmittersPathShapeGenerator } from "./EmittersPathShapeGenerator.js";
2
- export async function loadEmittersShapePath(engine, refresh = true) {
3
- const emittersEngine = engine;
4
- emittersEngine.checkVersion("3.9.0");
5
- emittersEngine.addEmitterShapeGenerator?.("path", new EmittersPathShapeGenerator());
6
- await emittersEngine.refresh(refresh);
1
+ export function loadEmittersShapePath(engine) {
2
+ engine.checkVersion("4.0.0-alpha.0");
3
+ engine.register(async (emittersEngine) => {
4
+ const { EmittersPathShapeGenerator } = await import("./EmittersPathShapeGenerator.js");
5
+ emittersEngine.addEmitterShapeGenerator?.("path", new EmittersPathShapeGenerator());
6
+ });
7
7
  }
@@ -1,16 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EmittersPathShape = void 0;
4
- const plugin_emitters_1 = require("@tsparticles/plugin-emitters");
5
- const engine_1 = require("@tsparticles/engine");
6
- const utils_js_1 = require("./utils.js");
1
+ import { EmitterShapeBase } from "@tsparticles/plugin-emitters";
2
+ import { percentDenominator, safeDocument } from "@tsparticles/engine";
3
+ import { generateRandomPointOnPathPerimeter, generateRandomPointWithinPath } from "./utils.js";
7
4
  const half = 0.5;
8
- class EmittersPathShape extends plugin_emitters_1.EmitterShapeBase {
5
+ export class EmittersPathShape extends EmitterShapeBase {
9
6
  constructor(position, size, fill, options) {
10
7
  super(position, size, fill, options);
11
- const ctx = document.createElement("canvas").getContext("2d");
8
+ const ctx = safeDocument().createElement("canvas").getContext("2d");
12
9
  if (!ctx) {
13
- throw new Error(`${engine_1.errorPrefix} No 2d context available`);
10
+ throw new Error(`No 2d context available`);
14
11
  }
15
12
  this.checkContext = ctx;
16
13
  this.points = options.points;
@@ -20,8 +17,8 @@ class EmittersPathShape extends plugin_emitters_1.EmitterShapeBase {
20
17
  };
21
18
  for (const [index, point] of pathData.entries()) {
22
19
  const coords = {
23
- x: offset.x + (point.x * size.width) / engine_1.percentDenominator,
24
- y: offset.y + (point.y * size.height) / engine_1.percentDenominator,
20
+ x: offset.x + (point.x * size.width) / percentDenominator,
21
+ y: offset.y + (point.y * size.height) / percentDenominator,
25
22
  };
26
23
  if (!index) {
27
24
  path.moveTo(coords.x, coords.y);
@@ -31,21 +28,22 @@ class EmittersPathShape extends plugin_emitters_1.EmitterShapeBase {
31
28
  }
32
29
  }
33
30
  const firstIndex = 0, firstPathData = pathData[firstIndex];
34
- if (firstPathData) {
35
- const coords = {
36
- x: offset.x + (firstPathData.x * size.width) / engine_1.percentDenominator,
37
- y: offset.y + (firstPathData.y * size.height) / engine_1.percentDenominator,
38
- };
39
- path.lineTo(coords.x, coords.y);
31
+ if (!firstPathData) {
32
+ throw new Error(`No path data available`);
40
33
  }
34
+ const coords = {
35
+ x: offset.x + (firstPathData.x * size.width) / percentDenominator,
36
+ y: offset.y + (firstPathData.y * size.height) / percentDenominator,
37
+ };
38
+ path.lineTo(coords.x, coords.y);
41
39
  this.path = path;
42
40
  }
43
41
  async init() {
44
42
  }
45
43
  randomPosition() {
46
44
  const ctx = this.checkContext, position = this.position, size = this.size, fill = this.fill, path = this.path, res = fill
47
- ? (0, utils_js_1.generateRandomPointWithinPath)(ctx, path, position, size)
48
- : (0, utils_js_1.generateRandomPointOnPathPerimeter)(ctx, path, position, size);
45
+ ? generateRandomPointWithinPath(ctx, path, position, size)
46
+ : generateRandomPointOnPathPerimeter(ctx, path, position, size);
49
47
  return res ? { position: res } : null;
50
48
  }
51
49
  resize(position, size) {
@@ -56,8 +54,8 @@ class EmittersPathShape extends plugin_emitters_1.EmitterShapeBase {
56
54
  };
57
55
  for (const [index, point] of pathData.entries()) {
58
56
  const coords = {
59
- x: offset.x + (point.x * size.width) / engine_1.percentDenominator,
60
- y: offset.y + (point.y * size.height) / engine_1.percentDenominator,
57
+ x: offset.x + (point.x * size.width) / percentDenominator,
58
+ y: offset.y + (point.y * size.height) / percentDenominator,
61
59
  };
62
60
  if (!index) {
63
61
  path.moveTo(coords.x, coords.y);
@@ -67,14 +65,14 @@ class EmittersPathShape extends plugin_emitters_1.EmitterShapeBase {
67
65
  }
68
66
  }
69
67
  const firstIndex = 0, firstPathData = pathData[firstIndex];
70
- if (firstPathData) {
71
- const coords = {
72
- x: offset.x + (firstPathData.x * size.width) / engine_1.percentDenominator,
73
- y: offset.y + (firstPathData.y * size.height) / engine_1.percentDenominator,
74
- };
75
- path.lineTo(coords.x, coords.y);
68
+ if (!firstPathData) {
69
+ throw new Error(`No path data available`);
76
70
  }
71
+ const coords = {
72
+ x: offset.x + (firstPathData.x * size.width) / percentDenominator,
73
+ y: offset.y + (firstPathData.y * size.height) / percentDenominator,
74
+ };
75
+ path.lineTo(coords.x, coords.y);
77
76
  this.path = path;
78
77
  }
79
78
  }
80
- exports.EmittersPathShape = EmittersPathShape;
@@ -1,13 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EmittersPathShapeGenerator = void 0;
4
- const EmittersPathShape_js_1 = require("./EmittersPathShape.js");
5
- const EmittersPathShapeOptions_js_1 = require("./Options/Classes/EmittersPathShapeOptions.js");
6
- class EmittersPathShapeGenerator {
1
+ import { EmittersPathShape } from "./EmittersPathShape.js";
2
+ import { EmittersPathShapeOptions } from "./Options/Classes/EmittersPathShapeOptions.js";
3
+ export class EmittersPathShapeGenerator {
7
4
  generate(position, size, fill, options) {
8
- const shapeOptions = new EmittersPathShapeOptions_js_1.EmittersPathShapeOptions();
5
+ const shapeOptions = new EmittersPathShapeOptions();
9
6
  shapeOptions.load(options);
10
- return new EmittersPathShape_js_1.EmittersPathShape(position, size, fill, shapeOptions);
7
+ return new EmittersPathShape(position, size, fill, shapeOptions);
11
8
  }
12
9
  }
13
- exports.EmittersPathShapeGenerator = EmittersPathShapeGenerator;
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EmittersPathShapeOptions = void 0;
4
- const engine_1 = require("@tsparticles/engine");
1
+ import { isNull } from "@tsparticles/engine";
5
2
  const defaultPosition = { x: 50, y: 50 };
6
- class EmittersPathShapeOptions {
3
+ export class EmittersPathShapeOptions {
7
4
  constructor() {
8
5
  this.points = [];
9
6
  }
10
7
  load(data) {
11
- if ((0, engine_1.isNull)(data)) {
8
+ if (isNull(data)) {
12
9
  return;
13
10
  }
14
11
  if (data.points !== undefined) {
@@ -16,4 +13,3 @@ class EmittersPathShapeOptions {
16
13
  }
17
14
  }
18
15
  }
19
- exports.EmittersPathShapeOptions = EmittersPathShapeOptions;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/cjs/index.js CHANGED
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadEmittersShapePath = loadEmittersShapePath;
4
- const EmittersPathShapeGenerator_js_1 = require("./EmittersPathShapeGenerator.js");
5
- async function loadEmittersShapePath(engine, refresh = true) {
6
- const emittersEngine = engine;
7
- emittersEngine.checkVersion("3.9.0");
8
- emittersEngine.addEmitterShapeGenerator?.("path", new EmittersPathShapeGenerator_js_1.EmittersPathShapeGenerator());
9
- await emittersEngine.refresh(refresh);
1
+ export function loadEmittersShapePath(engine) {
2
+ engine.checkVersion("4.0.0-alpha.0");
3
+ engine.register(async (emittersEngine) => {
4
+ const { EmittersPathShapeGenerator } = await import("./EmittersPathShapeGenerator.js");
5
+ emittersEngine.addEmitterShapeGenerator?.("path", new EmittersPathShapeGenerator());
6
+ });
10
7
  }
package/cjs/utils.js CHANGED
@@ -1,15 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateRandomPointWithinPath = generateRandomPointWithinPath;
4
- exports.generateRandomPointOnPathPerimeter = generateRandomPointOnPathPerimeter;
5
- const engine_1 = require("@tsparticles/engine");
1
+ import { getRandom } from "@tsparticles/engine";
6
2
  const maxAttempts = 100, half = 0.5;
7
- function generateRandomPointWithinPath(ctx, path, center, size) {
3
+ export function generateRandomPointWithinPath(ctx, path, center, size) {
8
4
  let randomPoint = null;
9
5
  for (let attempts = 0; attempts < maxAttempts; attempts++) {
10
6
  const tmpPoint = {
11
- x: center.x + (0, engine_1.getRandom)() * size.width - size.width * half,
12
- y: center.y + (0, engine_1.getRandom)() * size.height - size.height * half,
7
+ x: center.x + getRandom() * size.width - size.width * half,
8
+ y: center.y + getRandom() * size.height - size.height * half,
13
9
  };
14
10
  if (ctx.isPointInPath(path, tmpPoint.x, tmpPoint.y)) {
15
11
  randomPoint = tmpPoint;
@@ -18,12 +14,12 @@ function generateRandomPointWithinPath(ctx, path, center, size) {
18
14
  }
19
15
  return randomPoint;
20
16
  }
21
- function generateRandomPointOnPathPerimeter(ctx, path, center, size) {
17
+ export function generateRandomPointOnPathPerimeter(ctx, path, center, size) {
22
18
  let randomPoint = null;
23
19
  for (let attempts = 0; attempts < maxAttempts; attempts++) {
24
20
  const tmpPoint = {
25
- x: center.x + (0, engine_1.getRandom)() * size.width - size.width * half,
26
- y: center.y + (0, engine_1.getRandom)() * size.height - size.height * half,
21
+ x: center.x + getRandom() * size.width - size.width * half,
22
+ y: center.y + getRandom() * size.height - size.height * half,
27
23
  };
28
24
  if (ctx.isPointInStroke(path, tmpPoint.x, tmpPoint.y)) {
29
25
  randomPoint = tmpPoint;
@@ -0,0 +1,60 @@
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_plugin_emitters_shape_path"] = this["webpackChunk_tsparticles_plugin_emitters_shape_path"] || []).push([["dist_browser_EmittersPathShapeGenerator_js"],{
19
+
20
+ /***/ "./dist/browser/EmittersPathShape.js"
21
+ /*!*******************************************!*\
22
+ !*** ./dist/browser/EmittersPathShape.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 */ EmittersPathShape: () => (/* binding */ EmittersPathShape)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_plugin_emitters__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/plugin-emitters */ \"@tsparticles/plugin-emitters\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./utils.js */ \"./dist/browser/utils.js\");\n\n\n\nconst half = 0.5;\nclass EmittersPathShape extends _tsparticles_plugin_emitters__WEBPACK_IMPORTED_MODULE_0__.EmitterShapeBase {\n constructor(position, size, fill, options) {\n super(position, size, fill, options);\n const ctx = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__.safeDocument)().createElement(\"canvas\").getContext(\"2d\");\n if (!ctx) {\n throw new Error(`No 2d context available`);\n }\n this.checkContext = ctx;\n this.points = options.points;\n const pathData = this.points,\n path = new Path2D(),\n offset = {\n x: position.x - size.width * half,\n y: position.y - size.height * half\n };\n for (const [index, point] of pathData.entries()) {\n const coords = {\n x: offset.x + point.x * size.width / _tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__.percentDenominator,\n y: offset.y + point.y * size.height / _tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__.percentDenominator\n };\n if (!index) {\n path.moveTo(coords.x, coords.y);\n } else {\n path.lineTo(coords.x, coords.y);\n }\n }\n const firstIndex = 0,\n firstPathData = pathData[firstIndex];\n if (!firstPathData) {\n throw new Error(`No path data available`);\n }\n const coords = {\n x: offset.x + firstPathData.x * size.width / _tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__.percentDenominator,\n y: offset.y + firstPathData.y * size.height / _tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__.percentDenominator\n };\n path.lineTo(coords.x, coords.y);\n this.path = path;\n }\n async init() {}\n randomPosition() {\n const ctx = this.checkContext,\n position = this.position,\n size = this.size,\n fill = this.fill,\n path = this.path,\n res = fill ? (0,_utils_js__WEBPACK_IMPORTED_MODULE_2__.generateRandomPointWithinPath)(ctx, path, position, size) : (0,_utils_js__WEBPACK_IMPORTED_MODULE_2__.generateRandomPointOnPathPerimeter)(ctx, path, position, size);\n return res ? {\n position: res\n } : null;\n }\n resize(position, size) {\n super.resize(position, size);\n const pathData = this.points,\n path = new Path2D(),\n offset = {\n x: position.x - size.width * half,\n y: position.y - size.height * half\n };\n for (const [index, point] of pathData.entries()) {\n const coords = {\n x: offset.x + point.x * size.width / _tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__.percentDenominator,\n y: offset.y + point.y * size.height / _tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__.percentDenominator\n };\n if (!index) {\n path.moveTo(coords.x, coords.y);\n } else {\n path.lineTo(coords.x, coords.y);\n }\n }\n const firstIndex = 0,\n firstPathData = pathData[firstIndex];\n if (!firstPathData) {\n throw new Error(`No path data available`);\n }\n const coords = {\n x: offset.x + firstPathData.x * size.width / _tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__.percentDenominator,\n y: offset.y + firstPathData.y * size.height / _tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__.percentDenominator\n };\n path.lineTo(coords.x, coords.y);\n this.path = path;\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters-shape-path/./dist/browser/EmittersPathShape.js?\n}");
27
+
28
+ /***/ },
29
+
30
+ /***/ "./dist/browser/EmittersPathShapeGenerator.js"
31
+ /*!****************************************************!*\
32
+ !*** ./dist/browser/EmittersPathShapeGenerator.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 */ EmittersPathShapeGenerator: () => (/* binding */ EmittersPathShapeGenerator)\n/* harmony export */ });\n/* harmony import */ var _EmittersPathShape_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./EmittersPathShape.js */ \"./dist/browser/EmittersPathShape.js\");\n/* harmony import */ var _Options_Classes_EmittersPathShapeOptions_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Options/Classes/EmittersPathShapeOptions.js */ \"./dist/browser/Options/Classes/EmittersPathShapeOptions.js\");\n\n\nclass EmittersPathShapeGenerator {\n generate(position, size, fill, options) {\n const shapeOptions = new _Options_Classes_EmittersPathShapeOptions_js__WEBPACK_IMPORTED_MODULE_1__.EmittersPathShapeOptions();\n shapeOptions.load(options);\n return new _EmittersPathShape_js__WEBPACK_IMPORTED_MODULE_0__.EmittersPathShape(position, size, fill, shapeOptions);\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters-shape-path/./dist/browser/EmittersPathShapeGenerator.js?\n}");
37
+
38
+ /***/ },
39
+
40
+ /***/ "./dist/browser/Options/Classes/EmittersPathShapeOptions.js"
41
+ /*!******************************************************************!*\
42
+ !*** ./dist/browser/Options/Classes/EmittersPathShapeOptions.js ***!
43
+ \******************************************************************/
44
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
45
+
46
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ EmittersPathShapeOptions: () => (/* binding */ EmittersPathShapeOptions)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nconst defaultPosition = {\n x: 50,\n y: 50\n};\nclass EmittersPathShapeOptions {\n constructor() {\n this.points = [];\n }\n load(data) {\n if ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNull)(data)) {\n return;\n }\n if (data.points !== undefined) {\n this.points = data.points.map(t => ({\n x: t.x ?? defaultPosition.x,\n y: t.y ?? defaultPosition.y\n }));\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters-shape-path/./dist/browser/Options/Classes/EmittersPathShapeOptions.js?\n}");
47
+
48
+ /***/ },
49
+
50
+ /***/ "./dist/browser/utils.js"
51
+ /*!*******************************!*\
52
+ !*** ./dist/browser/utils.js ***!
53
+ \*******************************/
54
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
55
+
56
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ generateRandomPointOnPathPerimeter: () => (/* binding */ generateRandomPointOnPathPerimeter),\n/* harmony export */ generateRandomPointWithinPath: () => (/* binding */ generateRandomPointWithinPath)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nconst maxAttempts = 100,\n half = 0.5;\nfunction generateRandomPointWithinPath(ctx, path, center, size) {\n let randomPoint = null;\n for (let attempts = 0; attempts < maxAttempts; attempts++) {\n const tmpPoint = {\n x: center.x + (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() * size.width - size.width * half,\n y: center.y + (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() * size.height - size.height * half\n };\n if (ctx.isPointInPath(path, tmpPoint.x, tmpPoint.y)) {\n randomPoint = tmpPoint;\n break;\n }\n }\n return randomPoint;\n}\nfunction generateRandomPointOnPathPerimeter(ctx, path, center, size) {\n let randomPoint = null;\n for (let attempts = 0; attempts < maxAttempts; attempts++) {\n const tmpPoint = {\n x: center.x + (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() * size.width - size.width * half,\n y: center.y + (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() * size.height - size.height * half\n };\n if (ctx.isPointInStroke(path, tmpPoint.x, tmpPoint.y)) {\n randomPoint = tmpPoint;\n break;\n }\n }\n return randomPoint;\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters-shape-path/./dist/browser/utils.js?\n}");
57
+
58
+ /***/ }
59
+
60
+ }]);
@@ -1,13 +1,13 @@
1
1
  import { EmitterShapeBase } from "@tsparticles/plugin-emitters";
2
- import { errorPrefix, percentDenominator } from "@tsparticles/engine";
2
+ import { percentDenominator, safeDocument } from "@tsparticles/engine";
3
3
  import { generateRandomPointOnPathPerimeter, generateRandomPointWithinPath } from "./utils.js";
4
4
  const half = 0.5;
5
5
  export class EmittersPathShape extends EmitterShapeBase {
6
6
  constructor(position, size, fill, options) {
7
7
  super(position, size, fill, options);
8
- const ctx = document.createElement("canvas").getContext("2d");
8
+ const ctx = safeDocument().createElement("canvas").getContext("2d");
9
9
  if (!ctx) {
10
- throw new Error(`${errorPrefix} No 2d context available`);
10
+ throw new Error(`No 2d context available`);
11
11
  }
12
12
  this.checkContext = ctx;
13
13
  this.points = options.points;
@@ -28,13 +28,14 @@ export class EmittersPathShape extends EmitterShapeBase {
28
28
  }
29
29
  }
30
30
  const firstIndex = 0, firstPathData = pathData[firstIndex];
31
- if (firstPathData) {
32
- const coords = {
33
- x: offset.x + (firstPathData.x * size.width) / percentDenominator,
34
- y: offset.y + (firstPathData.y * size.height) / percentDenominator,
35
- };
36
- path.lineTo(coords.x, coords.y);
31
+ if (!firstPathData) {
32
+ throw new Error(`No path data available`);
37
33
  }
34
+ const coords = {
35
+ x: offset.x + (firstPathData.x * size.width) / percentDenominator,
36
+ y: offset.y + (firstPathData.y * size.height) / percentDenominator,
37
+ };
38
+ path.lineTo(coords.x, coords.y);
38
39
  this.path = path;
39
40
  }
40
41
  async init() {
@@ -64,13 +65,14 @@ export class EmittersPathShape extends EmitterShapeBase {
64
65
  }
65
66
  }
66
67
  const firstIndex = 0, firstPathData = pathData[firstIndex];
67
- if (firstPathData) {
68
- const coords = {
69
- x: offset.x + (firstPathData.x * size.width) / percentDenominator,
70
- y: offset.y + (firstPathData.y * size.height) / percentDenominator,
71
- };
72
- path.lineTo(coords.x, coords.y);
68
+ if (!firstPathData) {
69
+ throw new Error(`No path data available`);
73
70
  }
71
+ const coords = {
72
+ x: offset.x + (firstPathData.x * size.width) / percentDenominator,
73
+ y: offset.y + (firstPathData.y * size.height) / percentDenominator,
74
+ };
75
+ path.lineTo(coords.x, coords.y);
74
76
  this.path = path;
75
77
  }
76
78
  }
package/esm/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { EmittersPathShapeGenerator } from "./EmittersPathShapeGenerator.js";
2
- export async function loadEmittersShapePath(engine, refresh = true) {
3
- const emittersEngine = engine;
4
- emittersEngine.checkVersion("3.9.0");
5
- emittersEngine.addEmitterShapeGenerator?.("path", new EmittersPathShapeGenerator());
6
- await emittersEngine.refresh(refresh);
1
+ export function loadEmittersShapePath(engine) {
2
+ engine.checkVersion("4.0.0-alpha.0");
3
+ engine.register(async (emittersEngine) => {
4
+ const { EmittersPathShapeGenerator } = await import("./EmittersPathShapeGenerator.js");
5
+ emittersEngine.addEmitterShapeGenerator?.("path", new EmittersPathShapeGenerator());
6
+ });
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/plugin-emitters-shape-path",
3
- "version": "3.9.0",
3
+ "version": "4.0.0-alpha.0",
4
4
  "description": "tsParticles emitters shape path plugin",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -100,10 +100,11 @@
100
100
  "./package.json": "./package.json"
101
101
  },
102
102
  "dependencies": {
103
- "@tsparticles/engine": "3.9.0",
104
- "@tsparticles/plugin-emitters": "3.9.0"
103
+ "@tsparticles/engine": "4.0.0-alpha.0",
104
+ "@tsparticles/plugin-emitters": "4.0.0-alpha.0"
105
105
  },
106
106
  "publishConfig": {
107
107
  "access": "public"
108
- }
108
+ },
109
+ "type": "module"
109
110
  }