@tsparticles/path-branches 4.0.0-alpha.8 → 4.0.0-beta.1

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/138.min.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";(this.webpackChunk_tsparticles_path_branches=this.webpackChunk_tsparticles_path_branches||[]).push([[138],{138(e,t,n){n.d(t,{BranchesPathGenerator:()=>s});var i=n(303);let a={segmentLength:20,branchChance:.2,maxAngle:Math.PI/3,speedVariation:.3,inertia:{enable:!1,factor:.1}};class s{options;_container;_res;constructor(e){this._container=e,this._res=i.Vector.origin,this.options={...a,inertia:{...a.inertia}}}generate(e){let t=this.options;e.branching??={angle:(0,i.getRandom)()*i.doublePI,remaining:t.segmentLength,baseSpeed:e.velocity.length,speed:e.velocity.length};let n=e.branching;if(n.remaining<=0){let e=(0,i.getRandom)()<(t.branchChance??0),s=t.maxAngle??a.maxAngle,o=(2*(0,i.getRandom)()-1)*(e?s:.3*s);n.angle+=o,n.remaining=t.segmentLength;let r=1+(2*(0,i.getRandom)()-1)*(t.speedVariation??0);n.speed=n.baseSpeed*r}n.remaining-=n.speed;let s=Math.cos(n.angle)*n.speed,o=Math.sin(n.angle)*n.speed,r=t.inertia;if(r?.enable){let t=r.factor??.1;e.velocity.x+=(s-e.velocity.x)*t,e.velocity.y+=(o-e.velocity.y)*t,this._res.x=e.velocity.x,this._res.y=e.velocity.y}else e.velocity.x=0,e.velocity.y=0,this._res.x=s,this._res.y=o;return this._res}init(){let e=this._container.actualOptions.particles.move.path.options;this.options.segmentLength=e.segmentLength??this.options.segmentLength,this.options.branchChance=e.branchChance??this.options.branchChance,this.options.maxAngle=e.maxAngle??this.options.maxAngle,this.options.speedVariation=e.speedVariation??this.options.speedVariation;let t=e.inertia;if(t){let e={...a.inertia};e.enable=t.enable??e.enable,e.factor=t.factor??e.factor,this.options.inertia=e}}reset(e){delete e.branching}update(){}}}}]);
@@ -1,20 +1,32 @@
1
- import { Vector, getRandom } from "@tsparticles/engine";
1
+ import { Vector, doublePI, getRandom } from "@tsparticles/engine";
2
2
  const defaultOptions = {
3
3
  segmentLength: 20,
4
4
  branchChance: 0.2,
5
5
  maxAngle: Math.PI / 3,
6
6
  speedVariation: 0.3,
7
+ inertia: {
8
+ enable: false,
9
+ factor: 0.1,
10
+ },
7
11
  };
8
12
  export class BranchesPathGenerator {
13
+ options;
14
+ _container;
15
+ _res;
9
16
  constructor(container) {
10
17
  this._container = container;
11
- this.options = { ...defaultOptions };
18
+ this._res = Vector.origin;
19
+ this.options = {
20
+ ...defaultOptions,
21
+ inertia: { ...defaultOptions.inertia },
22
+ };
12
23
  }
13
24
  generate(p) {
14
25
  const opts = this.options;
15
26
  p.branching ??= {
16
- angle: getRandom() * Math.PI * 2,
27
+ angle: getRandom() * doublePI,
17
28
  remaining: opts.segmentLength,
29
+ baseSpeed: p.velocity.length,
18
30
  speed: p.velocity.length,
19
31
  };
20
32
  const b = p.branching;
@@ -23,14 +35,24 @@ export class BranchesPathGenerator {
23
35
  b.angle += delta;
24
36
  b.remaining = opts.segmentLength;
25
37
  const speedFactor = 1 + (getRandom() * 2 - 1) * (opts.speedVariation ?? 0);
26
- b.speed = p.velocity.length * speedFactor;
38
+ b.speed = b.baseSpeed * speedFactor;
27
39
  }
28
40
  b.remaining -= b.speed;
29
- const vx = Math.cos(b.angle) * b.speed;
30
- const vy = Math.sin(b.angle) * b.speed;
31
- p.velocity.x = 0;
32
- p.velocity.y = 0;
33
- return Vector.create(vx, vy);
41
+ const targetX = Math.cos(b.angle) * b.speed, targetY = Math.sin(b.angle) * b.speed, inertia = opts.inertia;
42
+ if (inertia?.enable) {
43
+ const factor = inertia.factor ?? 0.1;
44
+ p.velocity.x += (targetX - p.velocity.x) * factor;
45
+ p.velocity.y += (targetY - p.velocity.y) * factor;
46
+ this._res.x = p.velocity.x;
47
+ this._res.y = p.velocity.y;
48
+ }
49
+ else {
50
+ p.velocity.x = 0;
51
+ p.velocity.y = 0;
52
+ this._res.x = targetX;
53
+ this._res.y = targetY;
54
+ }
55
+ return this._res;
34
56
  }
35
57
  init() {
36
58
  const source = this._container.actualOptions.particles.move.path.options;
@@ -38,6 +60,13 @@ export class BranchesPathGenerator {
38
60
  this.options.branchChance = source["branchChance"] ?? this.options.branchChance;
39
61
  this.options.maxAngle = source["maxAngle"] ?? this.options.maxAngle;
40
62
  this.options.speedVariation = source["speedVariation"] ?? this.options.speedVariation;
63
+ const inertiaSource = source["inertia"];
64
+ if (inertiaSource) {
65
+ const inertiaOptions = { ...defaultOptions.inertia };
66
+ inertiaOptions.enable = inertiaSource.enable ?? inertiaOptions.enable;
67
+ inertiaOptions.factor = inertiaSource.factor ?? inertiaOptions.factor;
68
+ this.options.inertia = inertiaOptions;
69
+ }
41
70
  }
42
71
  reset(p) {
43
72
  delete p.branching;
package/browser/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  export const branchingPathName = "branchesPathGenerator";
2
2
  export async function loadBranchesPath(engine) {
3
- engine.checkVersion("4.0.0-alpha.8");
4
- await engine.register(e => {
5
- e.addPathGenerator(branchingPathName, async (container) => {
3
+ engine.checkVersion("4.0.0-beta.1");
4
+ await engine.pluginManager.register(async (e) => {
5
+ const { ensureBaseMoverLoaded } = await import("@tsparticles/plugin-move");
6
+ ensureBaseMoverLoaded(e);
7
+ e.pluginManager.addPathGenerator?.(branchingPathName, async (container) => {
6
8
  const { BranchesPathGenerator } = await import("./BranchesPathGenerator.js");
7
9
  return new BranchesPathGenerator(container);
8
10
  });
@@ -1,20 +1,32 @@
1
- import { Vector, getRandom } from "@tsparticles/engine";
1
+ import { Vector, doublePI, getRandom } from "@tsparticles/engine";
2
2
  const defaultOptions = {
3
3
  segmentLength: 20,
4
4
  branchChance: 0.2,
5
5
  maxAngle: Math.PI / 3,
6
6
  speedVariation: 0.3,
7
+ inertia: {
8
+ enable: false,
9
+ factor: 0.1,
10
+ },
7
11
  };
8
12
  export class BranchesPathGenerator {
13
+ options;
14
+ _container;
15
+ _res;
9
16
  constructor(container) {
10
17
  this._container = container;
11
- this.options = { ...defaultOptions };
18
+ this._res = Vector.origin;
19
+ this.options = {
20
+ ...defaultOptions,
21
+ inertia: { ...defaultOptions.inertia },
22
+ };
12
23
  }
13
24
  generate(p) {
14
25
  const opts = this.options;
15
26
  p.branching ??= {
16
- angle: getRandom() * Math.PI * 2,
27
+ angle: getRandom() * doublePI,
17
28
  remaining: opts.segmentLength,
29
+ baseSpeed: p.velocity.length,
18
30
  speed: p.velocity.length,
19
31
  };
20
32
  const b = p.branching;
@@ -23,14 +35,24 @@ export class BranchesPathGenerator {
23
35
  b.angle += delta;
24
36
  b.remaining = opts.segmentLength;
25
37
  const speedFactor = 1 + (getRandom() * 2 - 1) * (opts.speedVariation ?? 0);
26
- b.speed = p.velocity.length * speedFactor;
38
+ b.speed = b.baseSpeed * speedFactor;
27
39
  }
28
40
  b.remaining -= b.speed;
29
- const vx = Math.cos(b.angle) * b.speed;
30
- const vy = Math.sin(b.angle) * b.speed;
31
- p.velocity.x = 0;
32
- p.velocity.y = 0;
33
- return Vector.create(vx, vy);
41
+ const targetX = Math.cos(b.angle) * b.speed, targetY = Math.sin(b.angle) * b.speed, inertia = opts.inertia;
42
+ if (inertia?.enable) {
43
+ const factor = inertia.factor ?? 0.1;
44
+ p.velocity.x += (targetX - p.velocity.x) * factor;
45
+ p.velocity.y += (targetY - p.velocity.y) * factor;
46
+ this._res.x = p.velocity.x;
47
+ this._res.y = p.velocity.y;
48
+ }
49
+ else {
50
+ p.velocity.x = 0;
51
+ p.velocity.y = 0;
52
+ this._res.x = targetX;
53
+ this._res.y = targetY;
54
+ }
55
+ return this._res;
34
56
  }
35
57
  init() {
36
58
  const source = this._container.actualOptions.particles.move.path.options;
@@ -38,6 +60,13 @@ export class BranchesPathGenerator {
38
60
  this.options.branchChance = source["branchChance"] ?? this.options.branchChance;
39
61
  this.options.maxAngle = source["maxAngle"] ?? this.options.maxAngle;
40
62
  this.options.speedVariation = source["speedVariation"] ?? this.options.speedVariation;
63
+ const inertiaSource = source["inertia"];
64
+ if (inertiaSource) {
65
+ const inertiaOptions = { ...defaultOptions.inertia };
66
+ inertiaOptions.enable = inertiaSource.enable ?? inertiaOptions.enable;
67
+ inertiaOptions.factor = inertiaSource.factor ?? inertiaOptions.factor;
68
+ this.options.inertia = inertiaOptions;
69
+ }
41
70
  }
42
71
  reset(p) {
43
72
  delete p.branching;
package/cjs/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  export const branchingPathName = "branchesPathGenerator";
2
2
  export async function loadBranchesPath(engine) {
3
- engine.checkVersion("4.0.0-alpha.8");
4
- await engine.register(e => {
5
- e.addPathGenerator(branchingPathName, async (container) => {
3
+ engine.checkVersion("4.0.0-beta.1");
4
+ await engine.pluginManager.register(async (e) => {
5
+ const { ensureBaseMoverLoaded } = await import("@tsparticles/plugin-move");
6
+ ensureBaseMoverLoaded(e);
7
+ e.pluginManager.addPathGenerator?.(branchingPathName, async (container) => {
6
8
  const { BranchesPathGenerator } = await import("./BranchesPathGenerator.js");
7
9
  return new BranchesPathGenerator(container);
8
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.8
7
+ * v4.0.0-beta.1
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 */ BranchesPathGenerator: () => (/* binding */ BranchesPathGenerator)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nconst defaultOptions = {\n segmentLength: 20,\n branchChance: 0.2,\n maxAngle: Math.PI / 3,\n speedVariation: 0.3\n};\nclass BranchesPathGenerator {\n constructor(container) {\n this._container = container;\n this.options = {\n ...defaultOptions\n };\n }\n generate(p) {\n const opts = this.options;\n p.branching ??= {\n angle: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() * Math.PI * 2,\n remaining: opts.segmentLength,\n speed: p.velocity.length\n };\n const b = p.branching;\n if (b.remaining <= 0) {\n const branch = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() < (opts.branchChance ?? 0),\n maxAngle = opts.maxAngle ?? defaultOptions.maxAngle,\n delta = ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() * 2 - 1) * (branch ? maxAngle : maxAngle * 0.3);\n b.angle += delta;\n b.remaining = opts.segmentLength;\n const speedFactor = 1 + ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() * 2 - 1) * (opts.speedVariation ?? 0);\n b.speed = p.velocity.length * speedFactor;\n }\n b.remaining -= b.speed;\n const vx = Math.cos(b.angle) * b.speed;\n const vy = Math.sin(b.angle) * b.speed;\n p.velocity.x = 0;\n p.velocity.y = 0;\n return _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Vector.create(vx, vy);\n }\n init() {\n const source = this._container.actualOptions.particles.move.path.options;\n this.options.segmentLength = source[\"segmentLength\"] ?? this.options.segmentLength;\n this.options.branchChance = source[\"branchChance\"] ?? this.options.branchChance;\n this.options.maxAngle = source[\"maxAngle\"] ?? this.options.maxAngle;\n this.options.speedVariation = source[\"speedVariation\"] ?? this.options.speedVariation;\n }\n reset(p) {\n delete p.branching;\n }\n update() {}\n}\n\n//# sourceURL=webpack://@tsparticles/path-branches/./dist/browser/BranchesPathGenerator.js?\n}");
26
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ BranchesPathGenerator: () => (/* binding */ BranchesPathGenerator)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nconst defaultOptions = {\n segmentLength: 20,\n branchChance: 0.2,\n maxAngle: Math.PI / 3,\n speedVariation: 0.3,\n inertia: {\n enable: false,\n factor: 0.1\n }\n};\nclass BranchesPathGenerator {\n options;\n _container;\n _res;\n constructor(container){\n this._container = container;\n this._res = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Vector.origin;\n this.options = {\n ...defaultOptions,\n inertia: {\n ...defaultOptions.inertia\n }\n };\n }\n generate(p) {\n const opts = this.options;\n p.branching ??= {\n angle: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.doublePI,\n remaining: opts.segmentLength,\n baseSpeed: p.velocity.length,\n speed: p.velocity.length\n };\n const b = p.branching;\n if (b.remaining <= 0) {\n const branch = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() < (opts.branchChance ?? 0), maxAngle = opts.maxAngle ?? defaultOptions.maxAngle, delta = ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() * 2 - 1) * (branch ? maxAngle : maxAngle * 0.3);\n b.angle += delta;\n b.remaining = opts.segmentLength;\n const speedFactor = 1 + ((0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRandom)() * 2 - 1) * (opts.speedVariation ?? 0);\n b.speed = b.baseSpeed * speedFactor;\n }\n b.remaining -= b.speed;\n const targetX = Math.cos(b.angle) * b.speed, targetY = Math.sin(b.angle) * b.speed, inertia = opts.inertia;\n if (inertia?.enable) {\n const factor = inertia.factor ?? 0.1;\n p.velocity.x += (targetX - p.velocity.x) * factor;\n p.velocity.y += (targetY - p.velocity.y) * factor;\n this._res.x = p.velocity.x;\n this._res.y = p.velocity.y;\n } else {\n p.velocity.x = 0;\n p.velocity.y = 0;\n this._res.x = targetX;\n this._res.y = targetY;\n }\n return this._res;\n }\n init() {\n const source = this._container.actualOptions.particles.move.path.options;\n this.options.segmentLength = source[\"segmentLength\"] ?? this.options.segmentLength;\n this.options.branchChance = source[\"branchChance\"] ?? this.options.branchChance;\n this.options.maxAngle = source[\"maxAngle\"] ?? this.options.maxAngle;\n this.options.speedVariation = source[\"speedVariation\"] ?? this.options.speedVariation;\n const inertiaSource = source[\"inertia\"];\n if (inertiaSource) {\n const inertiaOptions = {\n ...defaultOptions.inertia\n };\n inertiaOptions.enable = inertiaSource.enable ?? inertiaOptions.enable;\n inertiaOptions.factor = inertiaSource.factor ?? inertiaOptions.factor;\n this.options.inertia = inertiaOptions;\n }\n }\n reset(p) {\n delete p.branching;\n }\n update() {}\n}\n\n\n//# sourceURL=webpack://@tsparticles/path-branches/./dist/browser/BranchesPathGenerator.js?\n}");
27
27
 
28
28
  /***/ }
29
29
 
@@ -1,20 +1,32 @@
1
- import { Vector, getRandom } from "@tsparticles/engine";
1
+ import { Vector, doublePI, getRandom } from "@tsparticles/engine";
2
2
  const defaultOptions = {
3
3
  segmentLength: 20,
4
4
  branchChance: 0.2,
5
5
  maxAngle: Math.PI / 3,
6
6
  speedVariation: 0.3,
7
+ inertia: {
8
+ enable: false,
9
+ factor: 0.1,
10
+ },
7
11
  };
8
12
  export class BranchesPathGenerator {
13
+ options;
14
+ _container;
15
+ _res;
9
16
  constructor(container) {
10
17
  this._container = container;
11
- this.options = { ...defaultOptions };
18
+ this._res = Vector.origin;
19
+ this.options = {
20
+ ...defaultOptions,
21
+ inertia: { ...defaultOptions.inertia },
22
+ };
12
23
  }
13
24
  generate(p) {
14
25
  const opts = this.options;
15
26
  p.branching ??= {
16
- angle: getRandom() * Math.PI * 2,
27
+ angle: getRandom() * doublePI,
17
28
  remaining: opts.segmentLength,
29
+ baseSpeed: p.velocity.length,
18
30
  speed: p.velocity.length,
19
31
  };
20
32
  const b = p.branching;
@@ -23,14 +35,24 @@ export class BranchesPathGenerator {
23
35
  b.angle += delta;
24
36
  b.remaining = opts.segmentLength;
25
37
  const speedFactor = 1 + (getRandom() * 2 - 1) * (opts.speedVariation ?? 0);
26
- b.speed = p.velocity.length * speedFactor;
38
+ b.speed = b.baseSpeed * speedFactor;
27
39
  }
28
40
  b.remaining -= b.speed;
29
- const vx = Math.cos(b.angle) * b.speed;
30
- const vy = Math.sin(b.angle) * b.speed;
31
- p.velocity.x = 0;
32
- p.velocity.y = 0;
33
- return Vector.create(vx, vy);
41
+ const targetX = Math.cos(b.angle) * b.speed, targetY = Math.sin(b.angle) * b.speed, inertia = opts.inertia;
42
+ if (inertia?.enable) {
43
+ const factor = inertia.factor ?? 0.1;
44
+ p.velocity.x += (targetX - p.velocity.x) * factor;
45
+ p.velocity.y += (targetY - p.velocity.y) * factor;
46
+ this._res.x = p.velocity.x;
47
+ this._res.y = p.velocity.y;
48
+ }
49
+ else {
50
+ p.velocity.x = 0;
51
+ p.velocity.y = 0;
52
+ this._res.x = targetX;
53
+ this._res.y = targetY;
54
+ }
55
+ return this._res;
34
56
  }
35
57
  init() {
36
58
  const source = this._container.actualOptions.particles.move.path.options;
@@ -38,6 +60,13 @@ export class BranchesPathGenerator {
38
60
  this.options.branchChance = source["branchChance"] ?? this.options.branchChance;
39
61
  this.options.maxAngle = source["maxAngle"] ?? this.options.maxAngle;
40
62
  this.options.speedVariation = source["speedVariation"] ?? this.options.speedVariation;
63
+ const inertiaSource = source["inertia"];
64
+ if (inertiaSource) {
65
+ const inertiaOptions = { ...defaultOptions.inertia };
66
+ inertiaOptions.enable = inertiaSource.enable ?? inertiaOptions.enable;
67
+ inertiaOptions.factor = inertiaSource.factor ?? inertiaOptions.factor;
68
+ this.options.inertia = inertiaOptions;
69
+ }
41
70
  }
42
71
  reset(p) {
43
72
  delete p.branching;
package/esm/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
  export const branchingPathName = "branchesPathGenerator";
2
2
  export async function loadBranchesPath(engine) {
3
- engine.checkVersion("4.0.0-alpha.8");
4
- await engine.register(e => {
5
- e.addPathGenerator(branchingPathName, async (container) => {
3
+ engine.checkVersion("4.0.0-beta.1");
4
+ await engine.pluginManager.register(async (e) => {
5
+ const { ensureBaseMoverLoaded } = await import("@tsparticles/plugin-move");
6
+ ensureBaseMoverLoaded(e);
7
+ e.pluginManager.addPathGenerator?.(branchingPathName, async (container) => {
6
8
  const { BranchesPathGenerator } = await import("./BranchesPathGenerator.js");
7
9
  return new BranchesPathGenerator(container);
8
10
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/path-branches",
3
- "version": "4.0.0-alpha.8",
3
+ "version": "4.0.0-beta.1",
4
4
  "description": "tsParticles branches path",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -104,7 +104,8 @@
104
104
  "./package.json": "./package.json"
105
105
  },
106
106
  "dependencies": {
107
- "@tsparticles/engine": "4.0.0-alpha.8"
107
+ "@tsparticles/engine": "4.0.0-beta.1",
108
+ "@tsparticles/plugin-move": "4.0.0-beta.1"
108
109
  },
109
110
  "type": "module"
110
111
  }