@tsparticles/path-polygon 3.0.0-alpha.0 → 3.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/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  # tsParticles Polygon Path
4
4
 
5
- [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/tsparticles-path-polygon/badge)](https://www.jsdelivr.com/package/npm/tsparticles-path-polygon)
6
- [![npmjs](https://badge.fury.io/js/tsparticles-path-polygon.svg)](https://www.npmjs.com/package/tsparticles-path-polygon)
7
- [![npmjs](https://img.shields.io/npm/dt/tsparticles-path-polygon)](https://www.npmjs.com/package/tsparticles-path-polygon) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
5
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/@tsparticles/path-polygon/badge)](https://www.jsdelivr.com/package/npm/@tsparticles/path-polygon)
6
+ [![npmjs](https://badge.fury.io/js/@tsparticles/path-polygon.svg)](https://www.npmjs.com/package/@tsparticles/path-polygon)
7
+ [![npmjs](https://img.shields.io/npm/dt/@tsparticles/path-polygon)](https://www.npmjs.com/package/@tsparticles/path-polygon) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
8
8
 
9
9
  [tsParticles](https://github.com/matteobruni/tsparticles) path plugin for polygon movement.
10
10
 
@@ -42,29 +42,33 @@ Once the scripts are loaded you can set up `tsParticles` and the path plugin lik
42
42
  This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
43
43
 
44
44
  ```shell
45
- $ npm install tsparticles-path-polygon
45
+ $ npm install @tsparticles/path-polygon
46
46
  ```
47
47
 
48
48
  or
49
49
 
50
50
  ```shell
51
- $ yarn add tsparticles-path-polygon
51
+ $ yarn add @tsparticles/path-polygon
52
52
  ```
53
53
 
54
54
  Then you need to import it in the app, like this:
55
55
 
56
56
  ```javascript
57
- const { tsParticles } = require("tsparticles-engine");
58
- const { loadPolygonPath } = require("tsparticles-path-polygon");
57
+ const { tsParticles } = require("@tsparticles/engine");
58
+ const { loadPolygonPath } = require("@tsparticles/path-polygon");
59
59
 
60
- loadPolygonPath(tsParticles);
60
+ (async () => {
61
+ await loadPolygonPath(tsParticles);
62
+ })();
61
63
  ```
62
64
 
63
65
  or
64
66
 
65
67
  ```javascript
66
- import { tsParticles } from "tsparticles-engine";
67
- import { loadPolygonPath } from "tsparticles-path-polygon";
68
+ import { tsParticles } from "@tsparticles/engine";
69
+ import { loadPolygonPath } from "@tsparticles/path-polygon";
68
70
 
69
- loadPolygonPath(tsParticles);
71
+ (async () => {
72
+ await loadPolygonPath(tsParticles);
73
+ })();
70
74
  ```
@@ -1,6 +1,13 @@
1
1
  import { Vector, getRandom } from "@tsparticles/engine";
2
2
  export class PolygonPathGenerator {
3
3
  constructor() {
4
+ this._createDirs = () => {
5
+ this.dirsList = [];
6
+ for (let i = 0; i < 360; i += 360 / this.options.sides) {
7
+ const angle = this.options.angle + i;
8
+ this.dirsList.push(Vector.create(Math.cos((angle * Math.PI) / 180), Math.sin((angle * Math.PI) / 180)));
9
+ }
10
+ };
4
11
  this.dirsList = [];
5
12
  this.options = {
6
13
  sides: 6,
@@ -9,34 +16,31 @@ export class PolygonPathGenerator {
9
16
  };
10
17
  }
11
18
  generate(p) {
19
+ const { sides } = this.options;
12
20
  if (p.hexStep === undefined) {
13
21
  p.hexStep = 0;
14
22
  }
15
23
  if (p.hexDirection === undefined) {
16
- p.hexDirection =
17
- this.options.sides === 6 ? ((getRandom() * 3) | 0) * 2 : (getRandom() * this.options.sides) | 0;
24
+ p.hexDirection = sides === 6 ? ((getRandom() * 3) | 0) * 2 : (getRandom() * sides) | 0;
18
25
  }
19
26
  if (p.hexSpeed === undefined) {
20
27
  p.hexSpeed = p.velocity.length;
21
28
  }
22
29
  if (p.hexStep % this.options.turnSteps === 0) {
23
- p.hexDirection =
24
- getRandom() > 0.5
25
- ? (p.hexDirection + 1) % this.options.sides
26
- : (p.hexDirection + this.options.sides - 1) % this.options.sides;
30
+ p.hexDirection = getRandom() > 0.5 ? (p.hexDirection + 1) % sides : (p.hexDirection + sides - 1) % sides;
27
31
  }
28
32
  p.velocity.x = 0;
29
33
  p.velocity.y = 0;
30
34
  p.hexStep++;
31
- return Vector.create(this.dirsList[p.hexDirection].x * p.hexSpeed, this.dirsList[p.hexDirection].y * p.hexSpeed);
35
+ const direction = this.dirsList[p.hexDirection];
36
+ return Vector.create(direction.x * p.hexSpeed, direction.y * p.hexSpeed);
32
37
  }
33
38
  init(container) {
34
- var _a;
35
39
  const options = container.actualOptions.particles.move.path.options;
36
40
  this.options.sides = options.sides > 0 ? options.sides : 6;
37
- this.options.angle = (_a = options.angle) !== null && _a !== void 0 ? _a : 30;
41
+ this.options.angle = options.angle ?? 30;
38
42
  this.options.turnSteps = options.turnSteps >= 0 ? options.turnSteps : 20;
39
- this.createDirs();
43
+ this._createDirs();
40
44
  }
41
45
  reset(particle) {
42
46
  delete particle.hexStep;
@@ -45,11 +49,4 @@ export class PolygonPathGenerator {
45
49
  }
46
50
  update() {
47
51
  }
48
- createDirs() {
49
- this.dirsList = [];
50
- for (let i = 0; i < 360; i += 360 / this.options.sides) {
51
- const angle = this.options.angle + i;
52
- this.dirsList.push(Vector.create(Math.cos((angle * Math.PI) / 180), Math.sin((angle * Math.PI) / 180)));
53
- }
54
- }
55
52
  }
package/browser/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PolygonPathGenerator } from "./PolygonPathGenerator";
2
2
  export const polygonPathName = "polygonPathGenerator";
3
- export function loadPolygonPath(engine) {
4
- engine.addPathGenerator(polygonPathName, new PolygonPathGenerator());
3
+ export async function loadPolygonPath(engine, refresh = true) {
4
+ await engine.addPathGenerator(polygonPathName, new PolygonPathGenerator(), refresh);
5
5
  }
@@ -4,6 +4,13 @@ exports.PolygonPathGenerator = void 0;
4
4
  const engine_1 = require("@tsparticles/engine");
5
5
  class PolygonPathGenerator {
6
6
  constructor() {
7
+ this._createDirs = () => {
8
+ this.dirsList = [];
9
+ for (let i = 0; i < 360; i += 360 / this.options.sides) {
10
+ const angle = this.options.angle + i;
11
+ this.dirsList.push(engine_1.Vector.create(Math.cos((angle * Math.PI) / 180), Math.sin((angle * Math.PI) / 180)));
12
+ }
13
+ };
7
14
  this.dirsList = [];
8
15
  this.options = {
9
16
  sides: 6,
@@ -12,34 +19,31 @@ class PolygonPathGenerator {
12
19
  };
13
20
  }
14
21
  generate(p) {
22
+ const { sides } = this.options;
15
23
  if (p.hexStep === undefined) {
16
24
  p.hexStep = 0;
17
25
  }
18
26
  if (p.hexDirection === undefined) {
19
- p.hexDirection =
20
- this.options.sides === 6 ? (((0, engine_1.getRandom)() * 3) | 0) * 2 : ((0, engine_1.getRandom)() * this.options.sides) | 0;
27
+ p.hexDirection = sides === 6 ? (((0, engine_1.getRandom)() * 3) | 0) * 2 : ((0, engine_1.getRandom)() * sides) | 0;
21
28
  }
22
29
  if (p.hexSpeed === undefined) {
23
30
  p.hexSpeed = p.velocity.length;
24
31
  }
25
32
  if (p.hexStep % this.options.turnSteps === 0) {
26
- p.hexDirection =
27
- (0, engine_1.getRandom)() > 0.5
28
- ? (p.hexDirection + 1) % this.options.sides
29
- : (p.hexDirection + this.options.sides - 1) % this.options.sides;
33
+ p.hexDirection = (0, engine_1.getRandom)() > 0.5 ? (p.hexDirection + 1) % sides : (p.hexDirection + sides - 1) % sides;
30
34
  }
31
35
  p.velocity.x = 0;
32
36
  p.velocity.y = 0;
33
37
  p.hexStep++;
34
- return engine_1.Vector.create(this.dirsList[p.hexDirection].x * p.hexSpeed, this.dirsList[p.hexDirection].y * p.hexSpeed);
38
+ const direction = this.dirsList[p.hexDirection];
39
+ return engine_1.Vector.create(direction.x * p.hexSpeed, direction.y * p.hexSpeed);
35
40
  }
36
41
  init(container) {
37
- var _a;
38
42
  const options = container.actualOptions.particles.move.path.options;
39
43
  this.options.sides = options.sides > 0 ? options.sides : 6;
40
- this.options.angle = (_a = options.angle) !== null && _a !== void 0 ? _a : 30;
44
+ this.options.angle = options.angle ?? 30;
41
45
  this.options.turnSteps = options.turnSteps >= 0 ? options.turnSteps : 20;
42
- this.createDirs();
46
+ this._createDirs();
43
47
  }
44
48
  reset(particle) {
45
49
  delete particle.hexStep;
@@ -48,12 +52,5 @@ class PolygonPathGenerator {
48
52
  }
49
53
  update() {
50
54
  }
51
- createDirs() {
52
- this.dirsList = [];
53
- for (let i = 0; i < 360; i += 360 / this.options.sides) {
54
- const angle = this.options.angle + i;
55
- this.dirsList.push(engine_1.Vector.create(Math.cos((angle * Math.PI) / 180), Math.sin((angle * Math.PI) / 180)));
56
- }
57
- }
58
55
  }
59
56
  exports.PolygonPathGenerator = PolygonPathGenerator;
package/cjs/index.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.loadPolygonPath = exports.polygonPathName = void 0;
4
4
  const PolygonPathGenerator_1 = require("./PolygonPathGenerator");
5
5
  exports.polygonPathName = "polygonPathGenerator";
6
- function loadPolygonPath(engine) {
7
- engine.addPathGenerator(exports.polygonPathName, new PolygonPathGenerator_1.PolygonPathGenerator());
6
+ async function loadPolygonPath(engine, refresh = true) {
7
+ await engine.addPathGenerator(exports.polygonPathName, new PolygonPathGenerator_1.PolygonPathGenerator(), refresh);
8
8
  }
9
9
  exports.loadPolygonPath = loadPolygonPath;
@@ -1,6 +1,13 @@
1
1
  import { Vector, getRandom } from "@tsparticles/engine";
2
2
  export class PolygonPathGenerator {
3
3
  constructor() {
4
+ this._createDirs = () => {
5
+ this.dirsList = [];
6
+ for (let i = 0; i < 360; i += 360 / this.options.sides) {
7
+ const angle = this.options.angle + i;
8
+ this.dirsList.push(Vector.create(Math.cos((angle * Math.PI) / 180), Math.sin((angle * Math.PI) / 180)));
9
+ }
10
+ };
4
11
  this.dirsList = [];
5
12
  this.options = {
6
13
  sides: 6,
@@ -9,34 +16,31 @@ export class PolygonPathGenerator {
9
16
  };
10
17
  }
11
18
  generate(p) {
19
+ const { sides } = this.options;
12
20
  if (p.hexStep === undefined) {
13
21
  p.hexStep = 0;
14
22
  }
15
23
  if (p.hexDirection === undefined) {
16
- p.hexDirection =
17
- this.options.sides === 6 ? ((getRandom() * 3) | 0) * 2 : (getRandom() * this.options.sides) | 0;
24
+ p.hexDirection = sides === 6 ? ((getRandom() * 3) | 0) * 2 : (getRandom() * sides) | 0;
18
25
  }
19
26
  if (p.hexSpeed === undefined) {
20
27
  p.hexSpeed = p.velocity.length;
21
28
  }
22
29
  if (p.hexStep % this.options.turnSteps === 0) {
23
- p.hexDirection =
24
- getRandom() > 0.5
25
- ? (p.hexDirection + 1) % this.options.sides
26
- : (p.hexDirection + this.options.sides - 1) % this.options.sides;
30
+ p.hexDirection = getRandom() > 0.5 ? (p.hexDirection + 1) % sides : (p.hexDirection + sides - 1) % sides;
27
31
  }
28
32
  p.velocity.x = 0;
29
33
  p.velocity.y = 0;
30
34
  p.hexStep++;
31
- return Vector.create(this.dirsList[p.hexDirection].x * p.hexSpeed, this.dirsList[p.hexDirection].y * p.hexSpeed);
35
+ const direction = this.dirsList[p.hexDirection];
36
+ return Vector.create(direction.x * p.hexSpeed, direction.y * p.hexSpeed);
32
37
  }
33
38
  init(container) {
34
- var _a;
35
39
  const options = container.actualOptions.particles.move.path.options;
36
40
  this.options.sides = options.sides > 0 ? options.sides : 6;
37
- this.options.angle = (_a = options.angle) !== null && _a !== void 0 ? _a : 30;
41
+ this.options.angle = options.angle ?? 30;
38
42
  this.options.turnSteps = options.turnSteps >= 0 ? options.turnSteps : 20;
39
- this.createDirs();
43
+ this._createDirs();
40
44
  }
41
45
  reset(particle) {
42
46
  delete particle.hexStep;
@@ -45,11 +49,4 @@ export class PolygonPathGenerator {
45
49
  }
46
50
  update() {
47
51
  }
48
- createDirs() {
49
- this.dirsList = [];
50
- for (let i = 0; i < 360; i += 360 / this.options.sides) {
51
- const angle = this.options.angle + i;
52
- this.dirsList.push(Vector.create(Math.cos((angle * Math.PI) / 180), Math.sin((angle * Math.PI) / 180)));
53
- }
54
- }
55
52
  }
package/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PolygonPathGenerator } from "./PolygonPathGenerator";
2
2
  export const polygonPathName = "polygonPathGenerator";
3
- export function loadPolygonPath(engine) {
4
- engine.addPathGenerator(polygonPathName, new PolygonPathGenerator());
3
+ export async function loadPolygonPath(engine, refresh = true) {
4
+ await engine.addPathGenerator(polygonPathName, new PolygonPathGenerator(), refresh);
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/path-polygon",
3
- "version": "3.0.0-alpha.0",
3
+ "version": "3.0.0-beta.0",
4
4
  "description": "tsParticles polygon path",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -63,6 +63,9 @@
63
63
  "@tsparticles/plugin",
64
64
  "@tsparticles/path"
65
65
  ],
66
+ "publishConfig": {
67
+ "access": "public"
68
+ },
66
69
  "author": "Matteo Bruni <matteo.bruni@me.com>",
67
70
  "license": "MIT",
68
71
  "bugs": {
@@ -73,6 +76,10 @@
73
76
  "type": "github",
74
77
  "url": "https://github.com/sponsors/matteobruni"
75
78
  },
79
+ {
80
+ "type": "github",
81
+ "url": "https://github.com/sponsors/tsparticles"
82
+ },
76
83
  {
77
84
  "type": "buymeacoffee",
78
85
  "url": "https://www.buymeacoffee.com/matteobruni"
@@ -83,10 +90,8 @@
83
90
  "unpkg": "tsparticles.path.polygon.min.js",
84
91
  "module": "esm/index.js",
85
92
  "types": "types/index.d.ts",
86
- "publishConfig": {
87
- "access": "public"
88
- },
93
+ "sideEffects": false,
89
94
  "dependencies": {
90
- "@tsparticles/engine": "^3.0.0-alpha.0"
95
+ "@tsparticles/engine": "^3.0.0-beta.0"
91
96
  }
92
- }
97
+ }