@tsparticles/plugin-emitters-shape-path 4.0.0-alpha.2 → 4.0.0-alpha.20
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/795.min.js +1 -0
- package/browser/EmittersPathShape.js +6 -4
- package/browser/EmittersPathShapeGenerator.js +2 -2
- package/browser/Options/Classes/EmittersPathShapeOptions.js +1 -0
- package/browser/index.js +6 -4
- package/browser/utils.js +2 -2
- package/cjs/EmittersPathShape.js +6 -4
- package/cjs/EmittersPathShapeGenerator.js +2 -2
- package/cjs/Options/Classes/EmittersPathShapeOptions.js +1 -0
- package/cjs/index.js +6 -4
- package/cjs/utils.js +2 -2
- package/dist_browser_EmittersPathShapeGenerator_js.js +5 -5
- package/esm/EmittersPathShape.js +6 -4
- package/esm/EmittersPathShapeGenerator.js +2 -2
- package/esm/Options/Classes/EmittersPathShapeOptions.js +1 -0
- package/esm/index.js +6 -4
- package/esm/utils.js +2 -2
- package/package.json +3 -3
- package/report.html +3 -3
- package/tsparticles.plugin.emitters.shape.path.js +41 -11
- package/tsparticles.plugin.emitters.shape.path.min.js +2 -2
- package/types/EmittersPathShape.d.ts +2 -2
- package/types/EmittersPathShapeGenerator.d.ts +2 -2
- package/types/index.d.ts +1 -1
- package/umd/EmittersPathShape.js +11 -9
- package/umd/EmittersPathShapeGenerator.js +2 -2
- package/umd/Options/Classes/EmittersPathShapeOptions.js +1 -0
- package/umd/index.js +7 -5
- package/umd/utils.js +5 -5
- package/699.min.js +0 -2
- package/699.min.js.LICENSE.txt +0 -1
- package/tsparticles.plugin.emitters.shape.path.min.js.LICENSE.txt +0 -1
package/795.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(this.webpackChunk_tsparticles_plugin_emitters_shape_path=this.webpackChunk_tsparticles_plugin_emitters_shape_path||[]).push([[795],{795(t,e,i){i.d(e,{EmittersPathShapeGenerator:()=>s});var n=i(303),o=i(526);class h extends o.EmitterShapeBase{checkContext;path;points;constructor(t,e,i,o,h){super(e,i,o,h);const a=(0,n.safeDocument)().createElement("canvas").getContext("2d",t.canvas.settings);if(!a)throw Error("No 2d context available");this.checkContext=a,this.points=h.points;const s=this.points,r=new Path2D,l={x:e.x-i.width*n.half,y:e.y-i.height*n.half};for(const[t,e]of s.entries()){const o={x:l.x+e.x*i.width/n.percentDenominator,y:l.y+e.y*i.height/n.percentDenominator};t?r.lineTo(o.x,o.y):r.moveTo(o.x,o.y)}const p=s[0];if(!p)throw Error("No path data available");const c={x:l.x+p.x*i.width/n.percentDenominator,y:l.y+p.y*i.height/n.percentDenominator};r.lineTo(c.x,c.y),this.path=r}async init(){}randomPosition(){let t=this.checkContext,e=this.position,i=this.size,o=this.fill,h=this.path,a=o?function(t,e,i,o){let h=null;for(let a=0;a<100;a++){let a={x:i.x+(0,n.getRandom)()*o.width-o.width*n.half,y:i.y+(0,n.getRandom)()*o.height-o.height*n.half};if(t.isPointInPath(e,a.x,a.y)){h=a;break}}return h}(t,h,e,i):function(t,e,i,o){let h=null;for(let a=0;a<100;a++){let a={x:i.x+(0,n.getRandom)()*o.width-o.width*n.half,y:i.y+(0,n.getRandom)()*o.height-o.height*n.half};if(t.isPointInStroke(e,a.x,a.y)){h=a;break}}return h}(t,h,e,i);return a?{position:a}:null}resize(t,e){super.resize(t,e);let i=this.points,o=new Path2D,h={x:t.x-e.width*n.half,y:t.y-e.height*n.half};for(let[t,a]of i.entries()){let i={x:h.x+a.x*e.width/n.percentDenominator,y:h.y+a.y*e.height/n.percentDenominator};t?o.lineTo(i.x,i.y):o.moveTo(i.x,i.y)}let a=i[0];if(!a)throw Error("No path data available");let s={x:h.x+a.x*e.width/n.percentDenominator,y:h.y+a.y*e.height/n.percentDenominator};o.lineTo(s.x,s.y),this.path=o}}class a{points;constructor(){this.points=[]}load(t){(0,n.isNull)(t)||void 0!==t.points&&(this.points=t.points.map(t=>({x:t.x??50,y:t.y??50})))}}class s{generate(t,e,i,n,o){let s=new a;return s.load(o),new h(t,e,i,n,s)}}}}]);
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { half, percentDenominator, safeDocument, } from "@tsparticles/engine";
|
|
1
2
|
import { EmitterShapeBase } from "@tsparticles/plugin-emitters";
|
|
2
|
-
import { percentDenominator, safeDocument } from "@tsparticles/engine";
|
|
3
3
|
import { generateRandomPointOnPathPerimeter, generateRandomPointWithinPath } from "./utils.js";
|
|
4
|
-
const half = 0.5;
|
|
5
4
|
export class EmittersPathShape extends EmitterShapeBase {
|
|
6
|
-
|
|
5
|
+
checkContext;
|
|
6
|
+
path;
|
|
7
|
+
points;
|
|
8
|
+
constructor(container, position, size, fill, options) {
|
|
7
9
|
super(position, size, fill, options);
|
|
8
|
-
const ctx = safeDocument().createElement("canvas").getContext("2d");
|
|
10
|
+
const ctx = safeDocument().createElement("canvas").getContext("2d", container.canvas.settings);
|
|
9
11
|
if (!ctx) {
|
|
10
12
|
throw new Error(`No 2d context available`);
|
|
11
13
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { EmittersPathShape } from "./EmittersPathShape.js";
|
|
2
2
|
import { EmittersPathShapeOptions } from "./Options/Classes/EmittersPathShapeOptions.js";
|
|
3
3
|
export class EmittersPathShapeGenerator {
|
|
4
|
-
generate(position, size, fill, options) {
|
|
4
|
+
generate(container, position, size, fill, options) {
|
|
5
5
|
const shapeOptions = new EmittersPathShapeOptions();
|
|
6
6
|
shapeOptions.load(options);
|
|
7
|
-
return new EmittersPathShape(position, size, fill, shapeOptions);
|
|
7
|
+
return new EmittersPathShape(container, position, size, fill, shapeOptions);
|
|
8
8
|
}
|
|
9
9
|
}
|
package/browser/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export function loadEmittersShapePath(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-alpha.
|
|
3
|
-
engine.register(async (
|
|
1
|
+
export async function loadEmittersShapePath(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.20");
|
|
3
|
+
await engine.register(async (e) => {
|
|
4
|
+
const { ensureEmittersPluginLoaded } = await import("@tsparticles/plugin-emitters");
|
|
5
|
+
ensureEmittersPluginLoaded(e);
|
|
4
6
|
const { EmittersPathShapeGenerator } = await import("./EmittersPathShapeGenerator.js");
|
|
5
|
-
|
|
7
|
+
e.addEmitterShapeGenerator?.("path", new EmittersPathShapeGenerator());
|
|
6
8
|
});
|
|
7
9
|
}
|
package/browser/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getRandom } from "@tsparticles/engine";
|
|
2
|
-
const maxAttempts = 100
|
|
1
|
+
import { getRandom, half } from "@tsparticles/engine";
|
|
2
|
+
const maxAttempts = 100;
|
|
3
3
|
export function generateRandomPointWithinPath(ctx, path, center, size) {
|
|
4
4
|
let randomPoint = null;
|
|
5
5
|
for (let attempts = 0; attempts < maxAttempts; attempts++) {
|
package/cjs/EmittersPathShape.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { half, percentDenominator, safeDocument, } from "@tsparticles/engine";
|
|
1
2
|
import { EmitterShapeBase } from "@tsparticles/plugin-emitters";
|
|
2
|
-
import { percentDenominator, safeDocument } from "@tsparticles/engine";
|
|
3
3
|
import { generateRandomPointOnPathPerimeter, generateRandomPointWithinPath } from "./utils.js";
|
|
4
|
-
const half = 0.5;
|
|
5
4
|
export class EmittersPathShape extends EmitterShapeBase {
|
|
6
|
-
|
|
5
|
+
checkContext;
|
|
6
|
+
path;
|
|
7
|
+
points;
|
|
8
|
+
constructor(container, position, size, fill, options) {
|
|
7
9
|
super(position, size, fill, options);
|
|
8
|
-
const ctx = safeDocument().createElement("canvas").getContext("2d");
|
|
10
|
+
const ctx = safeDocument().createElement("canvas").getContext("2d", container.canvas.settings);
|
|
9
11
|
if (!ctx) {
|
|
10
12
|
throw new Error(`No 2d context available`);
|
|
11
13
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { EmittersPathShape } from "./EmittersPathShape.js";
|
|
2
2
|
import { EmittersPathShapeOptions } from "./Options/Classes/EmittersPathShapeOptions.js";
|
|
3
3
|
export class EmittersPathShapeGenerator {
|
|
4
|
-
generate(position, size, fill, options) {
|
|
4
|
+
generate(container, position, size, fill, options) {
|
|
5
5
|
const shapeOptions = new EmittersPathShapeOptions();
|
|
6
6
|
shapeOptions.load(options);
|
|
7
|
-
return new EmittersPathShape(position, size, fill, shapeOptions);
|
|
7
|
+
return new EmittersPathShape(container, position, size, fill, shapeOptions);
|
|
8
8
|
}
|
|
9
9
|
}
|
package/cjs/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export function loadEmittersShapePath(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-alpha.
|
|
3
|
-
engine.register(async (
|
|
1
|
+
export async function loadEmittersShapePath(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.20");
|
|
3
|
+
await engine.register(async (e) => {
|
|
4
|
+
const { ensureEmittersPluginLoaded } = await import("@tsparticles/plugin-emitters");
|
|
5
|
+
ensureEmittersPluginLoaded(e);
|
|
4
6
|
const { EmittersPathShapeGenerator } = await import("./EmittersPathShapeGenerator.js");
|
|
5
|
-
|
|
7
|
+
e.addEmitterShapeGenerator?.("path", new EmittersPathShapeGenerator());
|
|
6
8
|
});
|
|
7
9
|
}
|
package/cjs/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getRandom } from "@tsparticles/engine";
|
|
2
|
-
const maxAttempts = 100
|
|
1
|
+
import { getRandom, half } from "@tsparticles/engine";
|
|
2
|
+
const maxAttempts = 100;
|
|
3
3
|
export function generateRandomPointWithinPath(ctx, path, center, size) {
|
|
4
4
|
let randomPoint = null;
|
|
5
5
|
for (let attempts = 0; attempts < maxAttempts; attempts++) {
|
|
@@ -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.
|
|
7
|
+
* v4.0.0-alpha.20
|
|
8
8
|
*/
|
|
9
9
|
"use strict";
|
|
10
10
|
/*
|
|
@@ -23,7 +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 */ EmittersPathShape: () => (/* binding */ EmittersPathShape)\n/* harmony export */ });\n/* harmony import */ var
|
|
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_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_plugin_emitters__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @tsparticles/plugin-emitters */ \"@tsparticles/plugin-emitters\");\n/* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./utils.js */ \"./dist/browser/utils.js\");\n\n\n\nclass EmittersPathShape extends _tsparticles_plugin_emitters__WEBPACK_IMPORTED_MODULE_1__.EmitterShapeBase {\n checkContext;\n path;\n points;\n constructor(container, position, size, fill, options){\n super(position, size, fill, options);\n const ctx = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeDocument)().createElement(\"canvas\").getContext(\"2d\", container.canvas.settings);\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, path = new Path2D(), offset = {\n x: position.x - size.width * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half,\n y: position.y - size.height * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.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_0__.percentDenominator,\n y: offset.y + point.y * size.height / _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.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, 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_0__.percentDenominator,\n y: offset.y + firstPathData.y * size.height / _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.percentDenominator\n };\n path.lineTo(coords.x, coords.y);\n this.path = path;\n }\n async init() {}\n randomPosition() {\n const ctx = this.checkContext, position = this.position, size = this.size, fill = this.fill, path = this.path, 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, path = new Path2D(), offset = {\n x: position.x - size.width * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half,\n y: position.y - size.height * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.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_0__.percentDenominator,\n y: offset.y + point.y * size.height / _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.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, 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_0__.percentDenominator,\n y: offset.y + firstPathData.y * size.height / _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.percentDenominator\n };\n path.lineTo(coords.x, coords.y);\n this.path = path;\n }\n}\n\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters-shape-path/./dist/browser/EmittersPathShape.js?\n}");
|
|
27
27
|
|
|
28
28
|
/***/ },
|
|
29
29
|
|
|
@@ -33,7 +33,7 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
|
|
|
33
33
|
\****************************************************/
|
|
34
34
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
35
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
|
|
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(container, 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(container, position, size, fill, shapeOptions);\n }\n}\n\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters-shape-path/./dist/browser/EmittersPathShapeGenerator.js?\n}");
|
|
37
37
|
|
|
38
38
|
/***/ },
|
|
39
39
|
|
|
@@ -43,7 +43,7 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
|
|
|
43
43
|
\******************************************************************/
|
|
44
44
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
45
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
|
|
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 points;\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\n//# sourceURL=webpack://@tsparticles/plugin-emitters-shape-path/./dist/browser/Options/Classes/EmittersPathShapeOptions.js?\n}");
|
|
47
47
|
|
|
48
48
|
/***/ },
|
|
49
49
|
|
|
@@ -53,7 +53,7 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
|
|
|
53
53
|
\*******************************/
|
|
54
54
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
55
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
|
|
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;\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 * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half,\n y: center.y + (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() * size.height - size.height * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.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 * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half,\n y: center.y + (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() * size.height - size.height * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.half\n };\n if (ctx.isPointInStroke(path, tmpPoint.x, tmpPoint.y)) {\n randomPoint = tmpPoint;\n break;\n }\n }\n return randomPoint;\n}\n\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters-shape-path/./dist/browser/utils.js?\n}");
|
|
57
57
|
|
|
58
58
|
/***/ }
|
|
59
59
|
|
package/esm/EmittersPathShape.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { half, percentDenominator, safeDocument, } from "@tsparticles/engine";
|
|
1
2
|
import { EmitterShapeBase } from "@tsparticles/plugin-emitters";
|
|
2
|
-
import { percentDenominator, safeDocument } from "@tsparticles/engine";
|
|
3
3
|
import { generateRandomPointOnPathPerimeter, generateRandomPointWithinPath } from "./utils.js";
|
|
4
|
-
const half = 0.5;
|
|
5
4
|
export class EmittersPathShape extends EmitterShapeBase {
|
|
6
|
-
|
|
5
|
+
checkContext;
|
|
6
|
+
path;
|
|
7
|
+
points;
|
|
8
|
+
constructor(container, position, size, fill, options) {
|
|
7
9
|
super(position, size, fill, options);
|
|
8
|
-
const ctx = safeDocument().createElement("canvas").getContext("2d");
|
|
10
|
+
const ctx = safeDocument().createElement("canvas").getContext("2d", container.canvas.settings);
|
|
9
11
|
if (!ctx) {
|
|
10
12
|
throw new Error(`No 2d context available`);
|
|
11
13
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { EmittersPathShape } from "./EmittersPathShape.js";
|
|
2
2
|
import { EmittersPathShapeOptions } from "./Options/Classes/EmittersPathShapeOptions.js";
|
|
3
3
|
export class EmittersPathShapeGenerator {
|
|
4
|
-
generate(position, size, fill, options) {
|
|
4
|
+
generate(container, position, size, fill, options) {
|
|
5
5
|
const shapeOptions = new EmittersPathShapeOptions();
|
|
6
6
|
shapeOptions.load(options);
|
|
7
|
-
return new EmittersPathShape(position, size, fill, shapeOptions);
|
|
7
|
+
return new EmittersPathShape(container, position, size, fill, shapeOptions);
|
|
8
8
|
}
|
|
9
9
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export function loadEmittersShapePath(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-alpha.
|
|
3
|
-
engine.register(async (
|
|
1
|
+
export async function loadEmittersShapePath(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.20");
|
|
3
|
+
await engine.register(async (e) => {
|
|
4
|
+
const { ensureEmittersPluginLoaded } = await import("@tsparticles/plugin-emitters");
|
|
5
|
+
ensureEmittersPluginLoaded(e);
|
|
4
6
|
const { EmittersPathShapeGenerator } = await import("./EmittersPathShapeGenerator.js");
|
|
5
|
-
|
|
7
|
+
e.addEmitterShapeGenerator?.("path", new EmittersPathShapeGenerator());
|
|
6
8
|
});
|
|
7
9
|
}
|
package/esm/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getRandom } from "@tsparticles/engine";
|
|
2
|
-
const maxAttempts = 100
|
|
1
|
+
import { getRandom, half } from "@tsparticles/engine";
|
|
2
|
+
const maxAttempts = 100;
|
|
3
3
|
export function generateRandomPointWithinPath(ctx, path, center, size) {
|
|
4
4
|
let randomPoint = null;
|
|
5
5
|
for (let attempts = 0; attempts < maxAttempts; attempts++) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/plugin-emitters-shape-path",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.20",
|
|
4
4
|
"description": "tsParticles emitters shape path plugin",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -100,8 +100,8 @@
|
|
|
100
100
|
"./package.json": "./package.json"
|
|
101
101
|
},
|
|
102
102
|
"dependencies": {
|
|
103
|
-
"@tsparticles/engine": "4.0.0-alpha.
|
|
104
|
-
"@tsparticles/plugin-emitters": "4.0.0-alpha.
|
|
103
|
+
"@tsparticles/engine": "4.0.0-alpha.20",
|
|
104
|
+
"@tsparticles/plugin-emitters": "4.0.0-alpha.20"
|
|
105
105
|
},
|
|
106
106
|
"publishConfig": {
|
|
107
107
|
"access": "public"
|