@tsparticles/move-base 3.0.0-alpha.1 → 3.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/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  # tsParticles Standard Mover
4
4
 
5
- [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/tsparticles-move-base/badge)](https://www.jsdelivr.com/package/npm/tsparticles-move-base)
6
- [![npmjs](https://badge.fury.io/js/tsparticles-move-base.svg)](https://www.npmjs.com/package/tsparticles-move-base)
7
- [![npmjs](https://img.shields.io/npm/dt/tsparticles-move-base)](https://www.npmjs.com/package/tsparticles-move-base) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
5
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/@tsparticles/move-base/badge)](https://www.jsdelivr.com/package/npm/@tsparticles/move-base)
6
+ [![npmjs](https://badge.fury.io/js/@tsparticles/move-base.svg)](https://www.npmjs.com/package/@tsparticles/move-base)
7
+ [![npmjs](https://img.shields.io/npm/dt/@tsparticles/move-base)](https://www.npmjs.com/package/@tsparticles/move-base) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
8
8
 
9
9
  [tsParticles](https://github.com/matteobruni/tsparticles) move plugin for standard movement effect.
10
10
 
@@ -42,29 +42,33 @@ Once the scripts are loaded you can set up `tsParticles` and the interaction plu
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-move-base
45
+ $ npm install @tsparticles/move-base
46
46
  ```
47
47
 
48
48
  or
49
49
 
50
50
  ```shell
51
- $ yarn add tsparticles-move-base
51
+ $ yarn add @tsparticles/move-base
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 { loadBaseMover } = require("tsparticles-move-base");
57
+ const { tsParticles } = require("@tsparticles/engine");
58
+ const { loadBaseMover } = require("@tsparticles/move-base");
59
59
 
60
- loadBaseMover(tsParticles); // awaitable
60
+ (async () => {
61
+ await loadBaseMover(tsParticles);
62
+ })();
61
63
  ```
62
64
 
63
65
  or
64
66
 
65
67
  ```javascript
66
- import { tsParticles } from "tsparticles-engine";
67
- import { loadBaseMover } from "tsparticles-move-base";
68
+ import { tsParticles } from "@tsparticles/engine";
69
+ import { loadBaseMover } from "@tsparticles/move-base";
68
70
 
69
- loadBaseMover(tsParticles); // awaitable
71
+ (async () => {
72
+ await loadBaseMover(tsParticles);
73
+ })();
70
74
  ```
@@ -1,16 +1,14 @@
1
- import { getDistance, getRangeMax, getRangeValue } from "@tsparticles/engine";
2
- import { applyDistance, applyPath, getProximitySpeedFactor, spin } from "./Utils";
1
+ import { getDistance, getRangeMax, getRangeValue, } from "@tsparticles/engine";
2
+ import { applyDistance, getProximitySpeedFactor, move, spin } from "./Utils.js";
3
+ const diffFactor = 2;
3
4
  export class BaseMover {
4
- init(particle) {
5
- var _a;
6
- const container = particle.container, options = particle.options, gravityOptions = options.move.gravity, spinOptions = options.move.spin;
7
- particle.gravity = {
8
- enable: gravityOptions.enable,
9
- acceleration: getRangeValue(gravityOptions.acceleration),
10
- inverse: gravityOptions.inverse,
11
- };
12
- if (spinOptions.enable) {
13
- const spinPos = (_a = spinOptions.position) !== null && _a !== void 0 ? _a : { x: 50, y: 50 }, spinCenter = {
5
+ constructor() {
6
+ this._initSpin = (particle) => {
7
+ const container = particle.container, options = particle.options, spinOptions = options.move.spin;
8
+ if (!spinOptions.enable) {
9
+ return;
10
+ }
11
+ const spinPos = spinOptions.position ?? { x: 50, y: 50 }, spinCenter = {
14
12
  x: (spinPos.x / 100) * container.canvas.size.width,
15
13
  y: (spinPos.y / 100) * container.canvas.size.height,
16
14
  }, pos = particle.getPosition(), distance = getDistance(pos, spinCenter), spinAcceleration = getRangeValue(spinOptions.acceleration);
@@ -22,56 +20,32 @@ export class BaseMover {
22
20
  radius: distance,
23
21
  acceleration: particle.retina.spinAcceleration,
24
22
  };
25
- }
23
+ };
24
+ }
25
+ init(particle) {
26
+ const options = particle.options, gravityOptions = options.move.gravity;
27
+ particle.gravity = {
28
+ enable: gravityOptions.enable,
29
+ acceleration: getRangeValue(gravityOptions.acceleration),
30
+ inverse: gravityOptions.inverse,
31
+ };
32
+ this._initSpin(particle);
26
33
  }
27
34
  isEnabled(particle) {
28
35
  return !particle.destroyed && particle.options.move.enable;
29
36
  }
30
37
  move(particle, delta) {
31
- var _a, _b, _c;
32
- var _d, _e;
33
38
  const particleOptions = particle.options, moveOptions = particleOptions.move;
34
39
  if (!moveOptions.enable) {
35
40
  return;
36
41
  }
37
- const container = particle.container, slowFactor = getProximitySpeedFactor(particle), baseSpeed = ((_a = (_d = particle.retina).moveSpeed) !== null && _a !== void 0 ? _a : (_d.moveSpeed = getRangeValue(moveOptions.speed) * container.retina.pixelRatio)) *
38
- container.retina.reduceFactor, moveDrift = ((_b = (_e = particle.retina).moveDrift) !== null && _b !== void 0 ? _b : (_e.moveDrift = getRangeValue(particle.options.move.drift) * container.retina.pixelRatio)), maxSize = getRangeMax(particleOptions.size.value) * container.retina.pixelRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, speedFactor = sizeFactor * slowFactor * (delta.factor || 1), diffFactor = 2, moveSpeed = (baseSpeed * speedFactor) / diffFactor;
42
+ const container = particle.container, pxRatio = container.retina.pixelRatio, slowFactor = getProximitySpeedFactor(particle), baseSpeed = (particle.retina.moveSpeed ??= getRangeValue(moveOptions.speed) * pxRatio) *
43
+ container.retina.reduceFactor, moveDrift = (particle.retina.moveDrift ??= getRangeValue(particle.options.move.drift) * pxRatio), maxSize = getRangeMax(particleOptions.size.value) * pxRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, moveSpeed = (baseSpeed * sizeFactor * slowFactor * (delta.factor || 1)) / diffFactor, maxSpeed = particle.retina.maxSpeed ?? container.retina.maxSpeed;
39
44
  if (moveOptions.spin.enable) {
40
45
  spin(particle, moveSpeed);
41
46
  }
42
47
  else {
43
- applyPath(particle, delta);
44
- const gravityOptions = particle.gravity, gravityFactor = (gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && gravityOptions.inverse ? -1 : 1;
45
- if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && moveSpeed) {
46
- particle.velocity.y +=
47
- (gravityFactor * (gravityOptions.acceleration * delta.factor)) / (60 * moveSpeed);
48
- }
49
- if (moveDrift && moveSpeed) {
50
- particle.velocity.x += (moveDrift * delta.factor) / (60 * moveSpeed);
51
- }
52
- const decay = particle.moveDecay;
53
- if (decay != 1) {
54
- particle.velocity.multTo(decay);
55
- }
56
- const velocity = particle.velocity.mult(moveSpeed), maxSpeed = (_c = particle.retina.maxSpeed) !== null && _c !== void 0 ? _c : container.retina.maxSpeed;
57
- if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) &&
58
- maxSpeed > 0 &&
59
- ((!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed) ||
60
- (gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed))) {
61
- velocity.y = gravityFactor * maxSpeed;
62
- if (moveSpeed) {
63
- particle.velocity.y = velocity.y / moveSpeed;
64
- }
65
- }
66
- const zIndexOptions = particle.options.zIndex, zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate;
67
- if (zVelocityFactor != 1) {
68
- velocity.multTo(zVelocityFactor);
69
- }
70
- particle.position.addTo(velocity);
71
- if (moveOptions.vibrate) {
72
- particle.position.x += Math.sin(particle.position.x * Math.cos(particle.position.y));
73
- particle.position.y += Math.cos(particle.position.y * Math.sin(particle.position.x));
74
- }
48
+ move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta);
75
49
  }
76
50
  applyDistance(particle);
77
51
  }
package/browser/Utils.js CHANGED
@@ -1,6 +1,6 @@
1
- import { clamp, getDistances, getRandom } from "@tsparticles/engine";
1
+ import { clamp, getDistances, getRandom, } from "@tsparticles/engine";
2
2
  export function applyDistance(particle) {
3
- const initialPosition = particle.initialPosition, { dx, dy } = getDistances(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), hDistance = particle.retina.maxDistance.horizontal, vDistance = particle.retina.maxDistance.vertical;
3
+ const initialPosition = particle.initialPosition, { dx, dy } = getDistances(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), { maxDistance } = particle.retina, hDistance = maxDistance.horizontal, vDistance = maxDistance.vertical;
4
4
  if (!hDistance && !vDistance) {
5
5
  return;
6
6
  }
@@ -26,6 +26,36 @@ export function applyDistance(particle) {
26
26
  }
27
27
  }
28
28
  }
29
+ export function move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta) {
30
+ applyPath(particle, delta);
31
+ const gravityOptions = particle.gravity, gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -1 : 1;
32
+ if (moveDrift && moveSpeed) {
33
+ particle.velocity.x += (moveDrift * delta.factor) / (60 * moveSpeed);
34
+ }
35
+ if (gravityOptions?.enable && moveSpeed) {
36
+ particle.velocity.y += (gravityFactor * (gravityOptions.acceleration * delta.factor)) / (60 * moveSpeed);
37
+ }
38
+ const decay = particle.moveDecay;
39
+ particle.velocity.multTo(decay);
40
+ const velocity = particle.velocity.mult(moveSpeed);
41
+ if (gravityOptions?.enable &&
42
+ maxSpeed > 0 &&
43
+ ((!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed) ||
44
+ (gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed))) {
45
+ velocity.y = gravityFactor * maxSpeed;
46
+ if (moveSpeed) {
47
+ particle.velocity.y = velocity.y / moveSpeed;
48
+ }
49
+ }
50
+ const zIndexOptions = particle.options.zIndex, zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate;
51
+ velocity.multTo(zVelocityFactor);
52
+ const { position } = particle;
53
+ position.addTo(velocity);
54
+ if (moveOptions.vibrate) {
55
+ position.x += Math.sin(position.x * Math.cos(position.y));
56
+ position.y += Math.cos(position.y * Math.sin(position.x));
57
+ }
58
+ }
29
59
  export function spin(particle, moveSpeed) {
30
60
  const container = particle.container;
31
61
  if (!particle.spin) {
@@ -50,7 +80,6 @@ export function spin(particle, moveSpeed) {
50
80
  particle.spin.angle += (moveSpeed / 100) * (1 - particle.spin.radius / maxCanvasSize);
51
81
  }
52
82
  export function applyPath(particle, delta) {
53
- var _a;
54
83
  const particlesOptions = particle.options, pathOptions = particlesOptions.move.path, pathEnabled = pathOptions.enable;
55
84
  if (!pathEnabled) {
56
85
  return;
@@ -59,7 +88,7 @@ export function applyPath(particle, delta) {
59
88
  particle.lastPathTime += delta.value;
60
89
  return;
61
90
  }
62
- const path = (_a = particle.pathGenerator) === null || _a === void 0 ? void 0 : _a.generate(particle);
91
+ const path = particle.pathGenerator?.generate(particle, delta);
63
92
  if (path) {
64
93
  particle.velocity.addTo(path);
65
94
  }
package/browser/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { BaseMover } from "./BaseMover";
2
- export async function loadBaseMover(engine) {
3
- engine.addMover("base", () => new BaseMover());
1
+ import { BaseMover } from "./BaseMover.js";
2
+ export async function loadBaseMover(engine, refresh = true) {
3
+ await engine.addMover("base", () => new BaseMover(), refresh);
4
4
  }
@@ -0,0 +1 @@
1
+ { "type": "module" }
package/cjs/BaseMover.js CHANGED
@@ -2,18 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BaseMover = void 0;
4
4
  const engine_1 = require("@tsparticles/engine");
5
- const Utils_1 = require("./Utils");
5
+ const Utils_js_1 = require("./Utils.js");
6
+ const diffFactor = 2;
6
7
  class BaseMover {
7
- init(particle) {
8
- var _a;
9
- const container = particle.container, options = particle.options, gravityOptions = options.move.gravity, spinOptions = options.move.spin;
10
- particle.gravity = {
11
- enable: gravityOptions.enable,
12
- acceleration: (0, engine_1.getRangeValue)(gravityOptions.acceleration),
13
- inverse: gravityOptions.inverse,
14
- };
15
- if (spinOptions.enable) {
16
- const spinPos = (_a = spinOptions.position) !== null && _a !== void 0 ? _a : { x: 50, y: 50 }, spinCenter = {
8
+ constructor() {
9
+ this._initSpin = (particle) => {
10
+ const container = particle.container, options = particle.options, spinOptions = options.move.spin;
11
+ if (!spinOptions.enable) {
12
+ return;
13
+ }
14
+ const spinPos = spinOptions.position ?? { x: 50, y: 50 }, spinCenter = {
17
15
  x: (spinPos.x / 100) * container.canvas.size.width,
18
16
  y: (spinPos.y / 100) * container.canvas.size.height,
19
17
  }, pos = particle.getPosition(), distance = (0, engine_1.getDistance)(pos, spinCenter), spinAcceleration = (0, engine_1.getRangeValue)(spinOptions.acceleration);
@@ -25,58 +23,34 @@ class BaseMover {
25
23
  radius: distance,
26
24
  acceleration: particle.retina.spinAcceleration,
27
25
  };
28
- }
26
+ };
27
+ }
28
+ init(particle) {
29
+ const options = particle.options, gravityOptions = options.move.gravity;
30
+ particle.gravity = {
31
+ enable: gravityOptions.enable,
32
+ acceleration: (0, engine_1.getRangeValue)(gravityOptions.acceleration),
33
+ inverse: gravityOptions.inverse,
34
+ };
35
+ this._initSpin(particle);
29
36
  }
30
37
  isEnabled(particle) {
31
38
  return !particle.destroyed && particle.options.move.enable;
32
39
  }
33
40
  move(particle, delta) {
34
- var _a, _b, _c;
35
- var _d, _e;
36
41
  const particleOptions = particle.options, moveOptions = particleOptions.move;
37
42
  if (!moveOptions.enable) {
38
43
  return;
39
44
  }
40
- const container = particle.container, slowFactor = (0, Utils_1.getProximitySpeedFactor)(particle), baseSpeed = ((_a = (_d = particle.retina).moveSpeed) !== null && _a !== void 0 ? _a : (_d.moveSpeed = (0, engine_1.getRangeValue)(moveOptions.speed) * container.retina.pixelRatio)) *
41
- container.retina.reduceFactor, moveDrift = ((_b = (_e = particle.retina).moveDrift) !== null && _b !== void 0 ? _b : (_e.moveDrift = (0, engine_1.getRangeValue)(particle.options.move.drift) * container.retina.pixelRatio)), maxSize = (0, engine_1.getRangeMax)(particleOptions.size.value) * container.retina.pixelRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, speedFactor = sizeFactor * slowFactor * (delta.factor || 1), diffFactor = 2, moveSpeed = (baseSpeed * speedFactor) / diffFactor;
45
+ const container = particle.container, pxRatio = container.retina.pixelRatio, slowFactor = (0, Utils_js_1.getProximitySpeedFactor)(particle), baseSpeed = (particle.retina.moveSpeed ??= (0, engine_1.getRangeValue)(moveOptions.speed) * pxRatio) *
46
+ container.retina.reduceFactor, moveDrift = (particle.retina.moveDrift ??= (0, engine_1.getRangeValue)(particle.options.move.drift) * pxRatio), maxSize = (0, engine_1.getRangeMax)(particleOptions.size.value) * pxRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, moveSpeed = (baseSpeed * sizeFactor * slowFactor * (delta.factor || 1)) / diffFactor, maxSpeed = particle.retina.maxSpeed ?? container.retina.maxSpeed;
42
47
  if (moveOptions.spin.enable) {
43
- (0, Utils_1.spin)(particle, moveSpeed);
48
+ (0, Utils_js_1.spin)(particle, moveSpeed);
44
49
  }
45
50
  else {
46
- (0, Utils_1.applyPath)(particle, delta);
47
- const gravityOptions = particle.gravity, gravityFactor = (gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && gravityOptions.inverse ? -1 : 1;
48
- if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && moveSpeed) {
49
- particle.velocity.y +=
50
- (gravityFactor * (gravityOptions.acceleration * delta.factor)) / (60 * moveSpeed);
51
- }
52
- if (moveDrift && moveSpeed) {
53
- particle.velocity.x += (moveDrift * delta.factor) / (60 * moveSpeed);
54
- }
55
- const decay = particle.moveDecay;
56
- if (decay != 1) {
57
- particle.velocity.multTo(decay);
58
- }
59
- const velocity = particle.velocity.mult(moveSpeed), maxSpeed = (_c = particle.retina.maxSpeed) !== null && _c !== void 0 ? _c : container.retina.maxSpeed;
60
- if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) &&
61
- maxSpeed > 0 &&
62
- ((!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed) ||
63
- (gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed))) {
64
- velocity.y = gravityFactor * maxSpeed;
65
- if (moveSpeed) {
66
- particle.velocity.y = velocity.y / moveSpeed;
67
- }
68
- }
69
- const zIndexOptions = particle.options.zIndex, zVelocityFactor = Math.pow((1 - particle.zIndexFactor), zIndexOptions.velocityRate);
70
- if (zVelocityFactor != 1) {
71
- velocity.multTo(zVelocityFactor);
72
- }
73
- particle.position.addTo(velocity);
74
- if (moveOptions.vibrate) {
75
- particle.position.x += Math.sin(particle.position.x * Math.cos(particle.position.y));
76
- particle.position.y += Math.cos(particle.position.y * Math.sin(particle.position.x));
77
- }
51
+ (0, Utils_js_1.move)(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta);
78
52
  }
79
- (0, Utils_1.applyDistance)(particle);
53
+ (0, Utils_js_1.applyDistance)(particle);
80
54
  }
81
55
  }
82
56
  exports.BaseMover = BaseMover;
package/cjs/Utils.js CHANGED
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getProximitySpeedFactor = exports.applyPath = exports.spin = exports.applyDistance = void 0;
3
+ exports.getProximitySpeedFactor = exports.applyPath = exports.spin = exports.move = exports.applyDistance = void 0;
4
4
  const engine_1 = require("@tsparticles/engine");
5
5
  function applyDistance(particle) {
6
- const initialPosition = particle.initialPosition, { dx, dy } = (0, engine_1.getDistances)(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), hDistance = particle.retina.maxDistance.horizontal, vDistance = particle.retina.maxDistance.vertical;
6
+ const initialPosition = particle.initialPosition, { dx, dy } = (0, engine_1.getDistances)(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), { maxDistance } = particle.retina, hDistance = maxDistance.horizontal, vDistance = maxDistance.vertical;
7
7
  if (!hDistance && !vDistance) {
8
8
  return;
9
9
  }
@@ -30,6 +30,37 @@ function applyDistance(particle) {
30
30
  }
31
31
  }
32
32
  exports.applyDistance = applyDistance;
33
+ function move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta) {
34
+ applyPath(particle, delta);
35
+ const gravityOptions = particle.gravity, gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -1 : 1;
36
+ if (moveDrift && moveSpeed) {
37
+ particle.velocity.x += (moveDrift * delta.factor) / (60 * moveSpeed);
38
+ }
39
+ if (gravityOptions?.enable && moveSpeed) {
40
+ particle.velocity.y += (gravityFactor * (gravityOptions.acceleration * delta.factor)) / (60 * moveSpeed);
41
+ }
42
+ const decay = particle.moveDecay;
43
+ particle.velocity.multTo(decay);
44
+ const velocity = particle.velocity.mult(moveSpeed);
45
+ if (gravityOptions?.enable &&
46
+ maxSpeed > 0 &&
47
+ ((!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed) ||
48
+ (gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed))) {
49
+ velocity.y = gravityFactor * maxSpeed;
50
+ if (moveSpeed) {
51
+ particle.velocity.y = velocity.y / moveSpeed;
52
+ }
53
+ }
54
+ const zIndexOptions = particle.options.zIndex, zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate;
55
+ velocity.multTo(zVelocityFactor);
56
+ const { position } = particle;
57
+ position.addTo(velocity);
58
+ if (moveOptions.vibrate) {
59
+ position.x += Math.sin(position.x * Math.cos(position.y));
60
+ position.y += Math.cos(position.y * Math.sin(position.x));
61
+ }
62
+ }
63
+ exports.move = move;
33
64
  function spin(particle, moveSpeed) {
34
65
  const container = particle.container;
35
66
  if (!particle.spin) {
@@ -55,7 +86,6 @@ function spin(particle, moveSpeed) {
55
86
  }
56
87
  exports.spin = spin;
57
88
  function applyPath(particle, delta) {
58
- var _a;
59
89
  const particlesOptions = particle.options, pathOptions = particlesOptions.move.path, pathEnabled = pathOptions.enable;
60
90
  if (!pathEnabled) {
61
91
  return;
@@ -64,7 +94,7 @@ function applyPath(particle, delta) {
64
94
  particle.lastPathTime += delta.value;
65
95
  return;
66
96
  }
67
- const path = (_a = particle.pathGenerator) === null || _a === void 0 ? void 0 : _a.generate(particle);
97
+ const path = particle.pathGenerator?.generate(particle, delta);
68
98
  if (path) {
69
99
  particle.velocity.addTo(path);
70
100
  }
package/cjs/index.js CHANGED
@@ -1,19 +1,8 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.loadBaseMover = void 0;
13
- const BaseMover_1 = require("./BaseMover");
14
- function loadBaseMover(engine) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- engine.addMover("base", () => new BaseMover_1.BaseMover());
17
- });
4
+ const BaseMover_js_1 = require("./BaseMover.js");
5
+ async function loadBaseMover(engine, refresh = true) {
6
+ await engine.addMover("base", () => new BaseMover_js_1.BaseMover(), refresh);
18
7
  }
19
8
  exports.loadBaseMover = loadBaseMover;
@@ -0,0 +1 @@
1
+ { "type": "commonjs" }
package/esm/BaseMover.js CHANGED
@@ -1,16 +1,14 @@
1
- import { getDistance, getRangeMax, getRangeValue } from "@tsparticles/engine";
2
- import { applyDistance, applyPath, getProximitySpeedFactor, spin } from "./Utils";
1
+ import { getDistance, getRangeMax, getRangeValue, } from "@tsparticles/engine";
2
+ import { applyDistance, getProximitySpeedFactor, move, spin } from "./Utils.js";
3
+ const diffFactor = 2;
3
4
  export class BaseMover {
4
- init(particle) {
5
- var _a;
6
- const container = particle.container, options = particle.options, gravityOptions = options.move.gravity, spinOptions = options.move.spin;
7
- particle.gravity = {
8
- enable: gravityOptions.enable,
9
- acceleration: getRangeValue(gravityOptions.acceleration),
10
- inverse: gravityOptions.inverse,
11
- };
12
- if (spinOptions.enable) {
13
- const spinPos = (_a = spinOptions.position) !== null && _a !== void 0 ? _a : { x: 50, y: 50 }, spinCenter = {
5
+ constructor() {
6
+ this._initSpin = (particle) => {
7
+ const container = particle.container, options = particle.options, spinOptions = options.move.spin;
8
+ if (!spinOptions.enable) {
9
+ return;
10
+ }
11
+ const spinPos = spinOptions.position ?? { x: 50, y: 50 }, spinCenter = {
14
12
  x: (spinPos.x / 100) * container.canvas.size.width,
15
13
  y: (spinPos.y / 100) * container.canvas.size.height,
16
14
  }, pos = particle.getPosition(), distance = getDistance(pos, spinCenter), spinAcceleration = getRangeValue(spinOptions.acceleration);
@@ -22,56 +20,32 @@ export class BaseMover {
22
20
  radius: distance,
23
21
  acceleration: particle.retina.spinAcceleration,
24
22
  };
25
- }
23
+ };
24
+ }
25
+ init(particle) {
26
+ const options = particle.options, gravityOptions = options.move.gravity;
27
+ particle.gravity = {
28
+ enable: gravityOptions.enable,
29
+ acceleration: getRangeValue(gravityOptions.acceleration),
30
+ inverse: gravityOptions.inverse,
31
+ };
32
+ this._initSpin(particle);
26
33
  }
27
34
  isEnabled(particle) {
28
35
  return !particle.destroyed && particle.options.move.enable;
29
36
  }
30
37
  move(particle, delta) {
31
- var _a, _b, _c;
32
- var _d, _e;
33
38
  const particleOptions = particle.options, moveOptions = particleOptions.move;
34
39
  if (!moveOptions.enable) {
35
40
  return;
36
41
  }
37
- const container = particle.container, slowFactor = getProximitySpeedFactor(particle), baseSpeed = ((_a = (_d = particle.retina).moveSpeed) !== null && _a !== void 0 ? _a : (_d.moveSpeed = getRangeValue(moveOptions.speed) * container.retina.pixelRatio)) *
38
- container.retina.reduceFactor, moveDrift = ((_b = (_e = particle.retina).moveDrift) !== null && _b !== void 0 ? _b : (_e.moveDrift = getRangeValue(particle.options.move.drift) * container.retina.pixelRatio)), maxSize = getRangeMax(particleOptions.size.value) * container.retina.pixelRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, speedFactor = sizeFactor * slowFactor * (delta.factor || 1), diffFactor = 2, moveSpeed = (baseSpeed * speedFactor) / diffFactor;
42
+ const container = particle.container, pxRatio = container.retina.pixelRatio, slowFactor = getProximitySpeedFactor(particle), baseSpeed = (particle.retina.moveSpeed ??= getRangeValue(moveOptions.speed) * pxRatio) *
43
+ container.retina.reduceFactor, moveDrift = (particle.retina.moveDrift ??= getRangeValue(particle.options.move.drift) * pxRatio), maxSize = getRangeMax(particleOptions.size.value) * pxRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, moveSpeed = (baseSpeed * sizeFactor * slowFactor * (delta.factor || 1)) / diffFactor, maxSpeed = particle.retina.maxSpeed ?? container.retina.maxSpeed;
39
44
  if (moveOptions.spin.enable) {
40
45
  spin(particle, moveSpeed);
41
46
  }
42
47
  else {
43
- applyPath(particle, delta);
44
- const gravityOptions = particle.gravity, gravityFactor = (gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && gravityOptions.inverse ? -1 : 1;
45
- if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && moveSpeed) {
46
- particle.velocity.y +=
47
- (gravityFactor * (gravityOptions.acceleration * delta.factor)) / (60 * moveSpeed);
48
- }
49
- if (moveDrift && moveSpeed) {
50
- particle.velocity.x += (moveDrift * delta.factor) / (60 * moveSpeed);
51
- }
52
- const decay = particle.moveDecay;
53
- if (decay != 1) {
54
- particle.velocity.multTo(decay);
55
- }
56
- const velocity = particle.velocity.mult(moveSpeed), maxSpeed = (_c = particle.retina.maxSpeed) !== null && _c !== void 0 ? _c : container.retina.maxSpeed;
57
- if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) &&
58
- maxSpeed > 0 &&
59
- ((!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed) ||
60
- (gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed))) {
61
- velocity.y = gravityFactor * maxSpeed;
62
- if (moveSpeed) {
63
- particle.velocity.y = velocity.y / moveSpeed;
64
- }
65
- }
66
- const zIndexOptions = particle.options.zIndex, zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate;
67
- if (zVelocityFactor != 1) {
68
- velocity.multTo(zVelocityFactor);
69
- }
70
- particle.position.addTo(velocity);
71
- if (moveOptions.vibrate) {
72
- particle.position.x += Math.sin(particle.position.x * Math.cos(particle.position.y));
73
- particle.position.y += Math.cos(particle.position.y * Math.sin(particle.position.x));
74
- }
48
+ move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta);
75
49
  }
76
50
  applyDistance(particle);
77
51
  }
package/esm/Utils.js CHANGED
@@ -1,6 +1,6 @@
1
- import { clamp, getDistances, getRandom } from "@tsparticles/engine";
1
+ import { clamp, getDistances, getRandom, } from "@tsparticles/engine";
2
2
  export function applyDistance(particle) {
3
- const initialPosition = particle.initialPosition, { dx, dy } = getDistances(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), hDistance = particle.retina.maxDistance.horizontal, vDistance = particle.retina.maxDistance.vertical;
3
+ const initialPosition = particle.initialPosition, { dx, dy } = getDistances(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), { maxDistance } = particle.retina, hDistance = maxDistance.horizontal, vDistance = maxDistance.vertical;
4
4
  if (!hDistance && !vDistance) {
5
5
  return;
6
6
  }
@@ -26,6 +26,36 @@ export function applyDistance(particle) {
26
26
  }
27
27
  }
28
28
  }
29
+ export function move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta) {
30
+ applyPath(particle, delta);
31
+ const gravityOptions = particle.gravity, gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -1 : 1;
32
+ if (moveDrift && moveSpeed) {
33
+ particle.velocity.x += (moveDrift * delta.factor) / (60 * moveSpeed);
34
+ }
35
+ if (gravityOptions?.enable && moveSpeed) {
36
+ particle.velocity.y += (gravityFactor * (gravityOptions.acceleration * delta.factor)) / (60 * moveSpeed);
37
+ }
38
+ const decay = particle.moveDecay;
39
+ particle.velocity.multTo(decay);
40
+ const velocity = particle.velocity.mult(moveSpeed);
41
+ if (gravityOptions?.enable &&
42
+ maxSpeed > 0 &&
43
+ ((!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed) ||
44
+ (gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed))) {
45
+ velocity.y = gravityFactor * maxSpeed;
46
+ if (moveSpeed) {
47
+ particle.velocity.y = velocity.y / moveSpeed;
48
+ }
49
+ }
50
+ const zIndexOptions = particle.options.zIndex, zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate;
51
+ velocity.multTo(zVelocityFactor);
52
+ const { position } = particle;
53
+ position.addTo(velocity);
54
+ if (moveOptions.vibrate) {
55
+ position.x += Math.sin(position.x * Math.cos(position.y));
56
+ position.y += Math.cos(position.y * Math.sin(position.x));
57
+ }
58
+ }
29
59
  export function spin(particle, moveSpeed) {
30
60
  const container = particle.container;
31
61
  if (!particle.spin) {
@@ -50,7 +80,6 @@ export function spin(particle, moveSpeed) {
50
80
  particle.spin.angle += (moveSpeed / 100) * (1 - particle.spin.radius / maxCanvasSize);
51
81
  }
52
82
  export function applyPath(particle, delta) {
53
- var _a;
54
83
  const particlesOptions = particle.options, pathOptions = particlesOptions.move.path, pathEnabled = pathOptions.enable;
55
84
  if (!pathEnabled) {
56
85
  return;
@@ -59,7 +88,7 @@ export function applyPath(particle, delta) {
59
88
  particle.lastPathTime += delta.value;
60
89
  return;
61
90
  }
62
- const path = (_a = particle.pathGenerator) === null || _a === void 0 ? void 0 : _a.generate(particle);
91
+ const path = particle.pathGenerator?.generate(particle, delta);
63
92
  if (path) {
64
93
  particle.velocity.addTo(path);
65
94
  }
package/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { BaseMover } from "./BaseMover";
2
- export async function loadBaseMover(engine) {
3
- engine.addMover("base", () => new BaseMover());
1
+ import { BaseMover } from "./BaseMover.js";
2
+ export async function loadBaseMover(engine, refresh = true) {
3
+ await engine.addMover("base", () => new BaseMover(), refresh);
4
4
  }
@@ -0,0 +1 @@
1
+ { "type": "module" }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/move-base",
3
- "version": "3.0.0-alpha.1",
3
+ "version": "3.0.0-beta.1",
4
4
  "description": "tsParticles Base movement",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -68,15 +68,28 @@
68
68
  "bugs": {
69
69
  "url": "https://github.com/matteobruni/tsparticles/issues"
70
70
  },
71
- "main": "cjs/index.js",
71
+ "sideEffects": false,
72
72
  "jsdelivr": "tsparticles.move.base.min.js",
73
73
  "unpkg": "tsparticles.move.base.min.js",
74
+ "browser": "browser/index.js",
75
+ "main": "cjs/index.js",
74
76
  "module": "esm/index.js",
75
77
  "types": "types/index.d.ts",
76
- "publishConfig": {
77
- "access": "public"
78
+ "exports": {
79
+ ".": {
80
+ "types": "./types/index.d.ts",
81
+ "browser": "./browser/index.js",
82
+ "import": "./esm/index.js",
83
+ "require": "./cjs/index.js",
84
+ "umd": "./umd/index.js",
85
+ "default": "./cjs/index.js"
86
+ },
87
+ "./package.json": "./package.json"
78
88
  },
79
89
  "dependencies": {
80
- "@tsparticles/engine": "^3.0.0-alpha.1"
90
+ "@tsparticles/engine": "^3.0.0-beta.1"
91
+ },
92
+ "publishConfig": {
93
+ "access": "public"
81
94
  }
82
- }
95
+ }