@tsparticles/updater-out-modes 3.3.0 → 3.5.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.
@@ -1,11 +1,11 @@
1
- import { calculateBounds, } from "@tsparticles/engine";
1
+ import { OutMode, calculateBounds, } from "@tsparticles/engine";
2
2
  import { bounceHorizontal, bounceVertical } from "./Utils.js";
3
3
  export class BounceOutMode {
4
4
  constructor(container) {
5
5
  this.container = container;
6
6
  this.modes = [
7
- "bounce",
8
- "split",
7
+ OutMode.bounce,
8
+ OutMode.split,
9
9
  ];
10
10
  }
11
11
  update(particle, direction, delta, outMode) {
@@ -1,9 +1,9 @@
1
- import { Vector, getDistances, isPointInside, } from "@tsparticles/engine";
1
+ import { OutMode, ParticleOutType, Vector, getDistances, isPointInside, } from "@tsparticles/engine";
2
2
  const minVelocity = 0;
3
3
  export class DestroyOutMode {
4
4
  constructor(container) {
5
5
  this.container = container;
6
- this.modes = ["destroy"];
6
+ this.modes = [OutMode.destroy];
7
7
  }
8
8
  update(particle, direction, _delta, outMode) {
9
9
  if (!this.modes.includes(outMode)) {
@@ -11,13 +11,13 @@ export class DestroyOutMode {
11
11
  }
12
12
  const container = this.container;
13
13
  switch (particle.outType) {
14
- case "normal":
15
- case "outside":
14
+ case ParticleOutType.normal:
15
+ case ParticleOutType.outside:
16
16
  if (isPointInside(particle.position, container.canvas.size, Vector.origin, particle.getRadius(), direction)) {
17
17
  return;
18
18
  }
19
19
  break;
20
- case "inside": {
20
+ case ParticleOutType.inside: {
21
21
  const { dx, dy } = getDistances(particle.position, particle.moveCenter), { x: vx, y: vy } = particle.velocity;
22
22
  if ((vx < minVelocity && dx > particle.moveCenter.radius) ||
23
23
  (vy < minVelocity && dy > particle.moveCenter.radius) ||
@@ -1,18 +1,18 @@
1
- import { Vector, isPointInside, } from "@tsparticles/engine";
1
+ import { OutMode, OutModeDirection, Vector, isPointInside, } from "@tsparticles/engine";
2
2
  const minVelocity = 0;
3
3
  export class NoneOutMode {
4
4
  constructor(container) {
5
5
  this.container = container;
6
- this.modes = ["none"];
6
+ this.modes = [OutMode.none];
7
7
  }
8
8
  update(particle, direction, delta, outMode) {
9
9
  if (!this.modes.includes(outMode)) {
10
10
  return;
11
11
  }
12
12
  if ((particle.options.move.distance.horizontal &&
13
- (direction === "left" || direction === "right")) ??
13
+ (direction === OutModeDirection.left || direction === OutModeDirection.right)) ??
14
14
  (particle.options.move.distance.vertical &&
15
- (direction === "top" || direction === "bottom"))) {
15
+ (direction === OutModeDirection.top || direction === OutModeDirection.bottom))) {
16
16
  return;
17
17
  }
18
18
  const gravityOptions = particle.options.move.gravity, container = this.container, canvasSize = container.canvas.size, pRadius = particle.getRadius();
@@ -31,8 +31,8 @@ export class NoneOutMode {
31
31
  const position = particle.position;
32
32
  if ((!gravityOptions.inverse &&
33
33
  position.y > canvasSize.height + pRadius &&
34
- direction === "bottom") ||
35
- (gravityOptions.inverse && position.y < -pRadius && direction === "top")) {
34
+ direction === OutModeDirection.bottom) ||
35
+ (gravityOptions.inverse && position.y < -pRadius && direction === OutModeDirection.top)) {
36
36
  container.particles.remove(particle);
37
37
  }
38
38
  }
@@ -1,3 +1,4 @@
1
+ import { OutMode, OutModeDirection, } from "@tsparticles/engine";
1
2
  import { BounceOutMode } from "./BounceOutMode.js";
2
3
  import { DestroyOutMode } from "./DestroyOutMode.js";
3
4
  import { NoneOutMode } from "./NoneOutMode.js";
@@ -22,16 +23,16 @@ export class OutOfCanvasUpdater {
22
23
  init(particle) {
23
24
  this.updaters = [];
24
25
  const outModes = particle.options.move.outModes;
25
- if (checkOutMode(outModes, "bounce")) {
26
+ if (checkOutMode(outModes, OutMode.bounce)) {
26
27
  this.updaters.push(new BounceOutMode(this.container));
27
28
  }
28
- else if (checkOutMode(outModes, "out")) {
29
+ else if (checkOutMode(outModes, OutMode.out)) {
29
30
  this.updaters.push(new OutOutMode(this.container));
30
31
  }
31
- else if (checkOutMode(outModes, "destroy")) {
32
+ else if (checkOutMode(outModes, OutMode.destroy)) {
32
33
  this.updaters.push(new DestroyOutMode(this.container));
33
34
  }
34
- else if (checkOutMode(outModes, "none")) {
35
+ else if (checkOutMode(outModes, OutMode.none)) {
35
36
  this.updaters.push(new NoneOutMode(this.container));
36
37
  }
37
38
  }
@@ -40,9 +41,9 @@ export class OutOfCanvasUpdater {
40
41
  }
41
42
  update(particle, delta) {
42
43
  const outModes = particle.options.move.outModes;
43
- this._updateOutMode(particle, delta, outModes.bottom ?? outModes.default, "bottom");
44
- this._updateOutMode(particle, delta, outModes.left ?? outModes.default, "left");
45
- this._updateOutMode(particle, delta, outModes.right ?? outModes.default, "right");
46
- this._updateOutMode(particle, delta, outModes.top ?? outModes.default, "top");
44
+ this._updateOutMode(particle, delta, outModes.bottom ?? outModes.default, OutModeDirection.bottom);
45
+ this._updateOutMode(particle, delta, outModes.left ?? outModes.default, OutModeDirection.left);
46
+ this._updateOutMode(particle, delta, outModes.right ?? outModes.default, OutModeDirection.right);
47
+ this._updateOutMode(particle, delta, outModes.top ?? outModes.default, OutModeDirection.top);
47
48
  }
48
49
  }
@@ -1,9 +1,9 @@
1
- import { Vector, calculateBounds, getDistances, getRandom, isPointInside, randomInRange, } from "@tsparticles/engine";
1
+ import { OutMode, OutModeDirection, ParticleOutType, Vector, calculateBounds, getDistances, getRandom, isPointInside, randomInRange, } from "@tsparticles/engine";
2
2
  const minVelocity = 0, minDistance = 0;
3
3
  export class OutOutMode {
4
4
  constructor(container) {
5
5
  this.container = container;
6
- this.modes = ["out"];
6
+ this.modes = [OutMode.out];
7
7
  }
8
8
  update(particle, direction, delta, outMode) {
9
9
  if (!this.modes.includes(outMode)) {
@@ -11,7 +11,7 @@ export class OutOutMode {
11
11
  }
12
12
  const container = this.container;
13
13
  switch (particle.outType) {
14
- case "inside": {
14
+ case ParticleOutType.inside: {
15
15
  const { x: vx, y: vy } = particle.velocity;
16
16
  const circVec = Vector.origin;
17
17
  circVec.length = particle.moveCenter.radius;
@@ -42,7 +42,7 @@ export class OutOutMode {
42
42
  return;
43
43
  }
44
44
  switch (particle.outType) {
45
- case "outside": {
45
+ case ParticleOutType.outside: {
46
46
  particle.position.x =
47
47
  Math.floor(randomInRange({
48
48
  min: -particle.moveCenter.radius,
@@ -60,14 +60,14 @@ export class OutOutMode {
60
60
  }
61
61
  break;
62
62
  }
63
- case "normal": {
63
+ case ParticleOutType.normal: {
64
64
  const warp = particle.options.move.warp, canvasSize = container.canvas.size, newPos = {
65
65
  bottom: canvasSize.height + particle.getRadius() + particle.offset.y,
66
66
  left: -particle.getRadius() - particle.offset.x,
67
67
  right: canvasSize.width + particle.getRadius() + particle.offset.x,
68
68
  top: -particle.getRadius() - particle.offset.y,
69
69
  }, sizeValue = particle.getRadius(), nextBounds = calculateBounds(particle.position, sizeValue);
70
- if (direction === "right" &&
70
+ if (direction === OutModeDirection.right &&
71
71
  nextBounds.left > canvasSize.width + particle.offset.x) {
72
72
  particle.position.x = newPos.left;
73
73
  particle.initialPosition.x = particle.position.x;
@@ -76,7 +76,7 @@ export class OutOutMode {
76
76
  particle.initialPosition.y = particle.position.y;
77
77
  }
78
78
  }
79
- else if (direction === "left" && nextBounds.right < -particle.offset.x) {
79
+ else if (direction === OutModeDirection.left && nextBounds.right < -particle.offset.x) {
80
80
  particle.position.x = newPos.right;
81
81
  particle.initialPosition.x = particle.position.x;
82
82
  if (!warp) {
@@ -84,7 +84,7 @@ export class OutOutMode {
84
84
  particle.initialPosition.y = particle.position.y;
85
85
  }
86
86
  }
87
- if (direction === "bottom" &&
87
+ if (direction === OutModeDirection.bottom &&
88
88
  nextBounds.top > canvasSize.height + particle.offset.y) {
89
89
  if (!warp) {
90
90
  particle.position.x = getRandom() * canvasSize.width;
@@ -93,7 +93,7 @@ export class OutOutMode {
93
93
  particle.position.y = newPos.top;
94
94
  particle.initialPosition.y = particle.position.y;
95
95
  }
96
- else if (direction === "top" && nextBounds.bottom < -particle.offset.y) {
96
+ else if (direction === OutModeDirection.top && nextBounds.bottom < -particle.offset.y) {
97
97
  if (!warp) {
98
98
  particle.position.x = getRandom() * canvasSize.width;
99
99
  particle.initialPosition.x = particle.position.x;
package/browser/Utils.js CHANGED
@@ -1,22 +1,22 @@
1
- import { getRangeValue } from "@tsparticles/engine";
1
+ import { OutMode, OutModeDirection, getRangeValue } from "@tsparticles/engine";
2
2
  const minVelocity = 0, boundsMin = 0;
3
3
  export function bounceHorizontal(data) {
4
- if ((data.outMode !== "bounce" && data.outMode !== "split") ||
5
- (data.direction !== "left" && data.direction !== "right")) {
4
+ if ((data.outMode !== OutMode.bounce && data.outMode !== OutMode.split) ||
5
+ (data.direction !== OutModeDirection.left && data.direction !== OutModeDirection.right)) {
6
6
  return;
7
7
  }
8
- if (data.bounds.right < boundsMin && data.direction === "left") {
8
+ if (data.bounds.right < boundsMin && data.direction === OutModeDirection.left) {
9
9
  data.particle.position.x = data.size + data.offset.x;
10
10
  }
11
- else if (data.bounds.left > data.canvasSize.width && data.direction === "right") {
11
+ else if (data.bounds.left > data.canvasSize.width && data.direction === OutModeDirection.right) {
12
12
  data.particle.position.x = data.canvasSize.width - data.size - data.offset.x;
13
13
  }
14
14
  const velocity = data.particle.velocity.x;
15
15
  let bounced = false;
16
- if ((data.direction === "right" &&
16
+ if ((data.direction === OutModeDirection.right &&
17
17
  data.bounds.right >= data.canvasSize.width &&
18
18
  velocity > minVelocity) ||
19
- (data.direction === "left" && data.bounds.left <= boundsMin && velocity < minVelocity)) {
19
+ (data.direction === OutModeDirection.left && data.bounds.left <= boundsMin && velocity < minVelocity)) {
20
20
  const newVelocity = getRangeValue(data.particle.options.bounce.horizontal.value);
21
21
  data.particle.velocity.x *= -newVelocity;
22
22
  bounced = true;
@@ -25,33 +25,33 @@ export function bounceHorizontal(data) {
25
25
  return;
26
26
  }
27
27
  const minPos = data.offset.x + data.size;
28
- if (data.bounds.right >= data.canvasSize.width && data.direction === "right") {
28
+ if (data.bounds.right >= data.canvasSize.width && data.direction === OutModeDirection.right) {
29
29
  data.particle.position.x = data.canvasSize.width - minPos;
30
30
  }
31
- else if (data.bounds.left <= boundsMin && data.direction === "left") {
31
+ else if (data.bounds.left <= boundsMin && data.direction === OutModeDirection.left) {
32
32
  data.particle.position.x = minPos;
33
33
  }
34
- if (data.outMode === "split") {
34
+ if (data.outMode === OutMode.split) {
35
35
  data.particle.destroy();
36
36
  }
37
37
  }
38
38
  export function bounceVertical(data) {
39
- if ((data.outMode !== "bounce" && data.outMode !== "split") ||
40
- (data.direction !== "bottom" && data.direction !== "top")) {
39
+ if ((data.outMode !== OutMode.bounce && data.outMode !== OutMode.split) ||
40
+ (data.direction !== OutModeDirection.bottom && data.direction !== OutModeDirection.top)) {
41
41
  return;
42
42
  }
43
- if (data.bounds.bottom < boundsMin && data.direction === "top") {
43
+ if (data.bounds.bottom < boundsMin && data.direction === OutModeDirection.top) {
44
44
  data.particle.position.y = data.size + data.offset.y;
45
45
  }
46
- else if (data.bounds.top > data.canvasSize.height && data.direction === "bottom") {
46
+ else if (data.bounds.top > data.canvasSize.height && data.direction === OutModeDirection.bottom) {
47
47
  data.particle.position.y = data.canvasSize.height - data.size - data.offset.y;
48
48
  }
49
49
  const velocity = data.particle.velocity.y;
50
50
  let bounced = false;
51
- if ((data.direction === "bottom" &&
51
+ if ((data.direction === OutModeDirection.bottom &&
52
52
  data.bounds.bottom >= data.canvasSize.height &&
53
53
  velocity > minVelocity) ||
54
- (data.direction === "top" && data.bounds.top <= boundsMin && velocity < minVelocity)) {
54
+ (data.direction === OutModeDirection.top && data.bounds.top <= boundsMin && velocity < minVelocity)) {
55
55
  const newVelocity = getRangeValue(data.particle.options.bounce.vertical.value);
56
56
  data.particle.velocity.y *= -newVelocity;
57
57
  bounced = true;
@@ -60,13 +60,13 @@ export function bounceVertical(data) {
60
60
  return;
61
61
  }
62
62
  const minPos = data.offset.y + data.size;
63
- if (data.bounds.bottom >= data.canvasSize.height && data.direction === "bottom") {
63
+ if (data.bounds.bottom >= data.canvasSize.height && data.direction === OutModeDirection.bottom) {
64
64
  data.particle.position.y = data.canvasSize.height - minPos;
65
65
  }
66
- else if (data.bounds.top <= boundsMin && data.direction === "top") {
66
+ else if (data.bounds.top <= boundsMin && data.direction === OutModeDirection.top) {
67
67
  data.particle.position.y = minPos;
68
68
  }
69
- if (data.outMode === "split") {
69
+ if (data.outMode === OutMode.split) {
70
70
  data.particle.destroy();
71
71
  }
72
72
  }
package/browser/index.js CHANGED
@@ -1,6 +1,6 @@
1
+ import { OutOfCanvasUpdater } from "./OutOfCanvasUpdater.js";
1
2
  export async function loadOutModesUpdater(engine, refresh = true) {
2
- await engine.addParticleUpdater("outModes", async (container) => {
3
- const { OutOfCanvasUpdater } = await import("./OutOfCanvasUpdater.js");
4
- return new OutOfCanvasUpdater(container);
3
+ await engine.addParticleUpdater("outModes", container => {
4
+ return Promise.resolve(new OutOfCanvasUpdater(container));
5
5
  }, refresh);
6
6
  }
@@ -7,8 +7,8 @@ class BounceOutMode {
7
7
  constructor(container) {
8
8
  this.container = container;
9
9
  this.modes = [
10
- "bounce",
11
- "split",
10
+ engine_1.OutMode.bounce,
11
+ engine_1.OutMode.split,
12
12
  ];
13
13
  }
14
14
  update(particle, direction, delta, outMode) {
@@ -6,7 +6,7 @@ const minVelocity = 0;
6
6
  class DestroyOutMode {
7
7
  constructor(container) {
8
8
  this.container = container;
9
- this.modes = ["destroy"];
9
+ this.modes = [engine_1.OutMode.destroy];
10
10
  }
11
11
  update(particle, direction, _delta, outMode) {
12
12
  if (!this.modes.includes(outMode)) {
@@ -14,13 +14,13 @@ class DestroyOutMode {
14
14
  }
15
15
  const container = this.container;
16
16
  switch (particle.outType) {
17
- case "normal":
18
- case "outside":
17
+ case engine_1.ParticleOutType.normal:
18
+ case engine_1.ParticleOutType.outside:
19
19
  if ((0, engine_1.isPointInside)(particle.position, container.canvas.size, engine_1.Vector.origin, particle.getRadius(), direction)) {
20
20
  return;
21
21
  }
22
22
  break;
23
- case "inside": {
23
+ case engine_1.ParticleOutType.inside: {
24
24
  const { dx, dy } = (0, engine_1.getDistances)(particle.position, particle.moveCenter), { x: vx, y: vy } = particle.velocity;
25
25
  if ((vx < minVelocity && dx > particle.moveCenter.radius) ||
26
26
  (vy < minVelocity && dy > particle.moveCenter.radius) ||
@@ -6,16 +6,16 @@ const minVelocity = 0;
6
6
  class NoneOutMode {
7
7
  constructor(container) {
8
8
  this.container = container;
9
- this.modes = ["none"];
9
+ this.modes = [engine_1.OutMode.none];
10
10
  }
11
11
  update(particle, direction, delta, outMode) {
12
12
  if (!this.modes.includes(outMode)) {
13
13
  return;
14
14
  }
15
15
  if ((particle.options.move.distance.horizontal &&
16
- (direction === "left" || direction === "right")) ??
16
+ (direction === engine_1.OutModeDirection.left || direction === engine_1.OutModeDirection.right)) ??
17
17
  (particle.options.move.distance.vertical &&
18
- (direction === "top" || direction === "bottom"))) {
18
+ (direction === engine_1.OutModeDirection.top || direction === engine_1.OutModeDirection.bottom))) {
19
19
  return;
20
20
  }
21
21
  const gravityOptions = particle.options.move.gravity, container = this.container, canvasSize = container.canvas.size, pRadius = particle.getRadius();
@@ -34,8 +34,8 @@ class NoneOutMode {
34
34
  const position = particle.position;
35
35
  if ((!gravityOptions.inverse &&
36
36
  position.y > canvasSize.height + pRadius &&
37
- direction === "bottom") ||
38
- (gravityOptions.inverse && position.y < -pRadius && direction === "top")) {
37
+ direction === engine_1.OutModeDirection.bottom) ||
38
+ (gravityOptions.inverse && position.y < -pRadius && direction === engine_1.OutModeDirection.top)) {
39
39
  container.particles.remove(particle);
40
40
  }
41
41
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OutOfCanvasUpdater = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
4
5
  const BounceOutMode_js_1 = require("./BounceOutMode.js");
5
6
  const DestroyOutMode_js_1 = require("./DestroyOutMode.js");
6
7
  const NoneOutMode_js_1 = require("./NoneOutMode.js");
@@ -25,16 +26,16 @@ class OutOfCanvasUpdater {
25
26
  init(particle) {
26
27
  this.updaters = [];
27
28
  const outModes = particle.options.move.outModes;
28
- if (checkOutMode(outModes, "bounce")) {
29
+ if (checkOutMode(outModes, engine_1.OutMode.bounce)) {
29
30
  this.updaters.push(new BounceOutMode_js_1.BounceOutMode(this.container));
30
31
  }
31
- else if (checkOutMode(outModes, "out")) {
32
+ else if (checkOutMode(outModes, engine_1.OutMode.out)) {
32
33
  this.updaters.push(new OutOutMode_js_1.OutOutMode(this.container));
33
34
  }
34
- else if (checkOutMode(outModes, "destroy")) {
35
+ else if (checkOutMode(outModes, engine_1.OutMode.destroy)) {
35
36
  this.updaters.push(new DestroyOutMode_js_1.DestroyOutMode(this.container));
36
37
  }
37
- else if (checkOutMode(outModes, "none")) {
38
+ else if (checkOutMode(outModes, engine_1.OutMode.none)) {
38
39
  this.updaters.push(new NoneOutMode_js_1.NoneOutMode(this.container));
39
40
  }
40
41
  }
@@ -43,10 +44,10 @@ class OutOfCanvasUpdater {
43
44
  }
44
45
  update(particle, delta) {
45
46
  const outModes = particle.options.move.outModes;
46
- this._updateOutMode(particle, delta, outModes.bottom ?? outModes.default, "bottom");
47
- this._updateOutMode(particle, delta, outModes.left ?? outModes.default, "left");
48
- this._updateOutMode(particle, delta, outModes.right ?? outModes.default, "right");
49
- this._updateOutMode(particle, delta, outModes.top ?? outModes.default, "top");
47
+ this._updateOutMode(particle, delta, outModes.bottom ?? outModes.default, engine_1.OutModeDirection.bottom);
48
+ this._updateOutMode(particle, delta, outModes.left ?? outModes.default, engine_1.OutModeDirection.left);
49
+ this._updateOutMode(particle, delta, outModes.right ?? outModes.default, engine_1.OutModeDirection.right);
50
+ this._updateOutMode(particle, delta, outModes.top ?? outModes.default, engine_1.OutModeDirection.top);
50
51
  }
51
52
  }
52
53
  exports.OutOfCanvasUpdater = OutOfCanvasUpdater;
package/cjs/OutOutMode.js CHANGED
@@ -6,7 +6,7 @@ const minVelocity = 0, minDistance = 0;
6
6
  class OutOutMode {
7
7
  constructor(container) {
8
8
  this.container = container;
9
- this.modes = ["out"];
9
+ this.modes = [engine_1.OutMode.out];
10
10
  }
11
11
  update(particle, direction, delta, outMode) {
12
12
  if (!this.modes.includes(outMode)) {
@@ -14,7 +14,7 @@ class OutOutMode {
14
14
  }
15
15
  const container = this.container;
16
16
  switch (particle.outType) {
17
- case "inside": {
17
+ case engine_1.ParticleOutType.inside: {
18
18
  const { x: vx, y: vy } = particle.velocity;
19
19
  const circVec = engine_1.Vector.origin;
20
20
  circVec.length = particle.moveCenter.radius;
@@ -45,7 +45,7 @@ class OutOutMode {
45
45
  return;
46
46
  }
47
47
  switch (particle.outType) {
48
- case "outside": {
48
+ case engine_1.ParticleOutType.outside: {
49
49
  particle.position.x =
50
50
  Math.floor((0, engine_1.randomInRange)({
51
51
  min: -particle.moveCenter.radius,
@@ -63,14 +63,14 @@ class OutOutMode {
63
63
  }
64
64
  break;
65
65
  }
66
- case "normal": {
66
+ case engine_1.ParticleOutType.normal: {
67
67
  const warp = particle.options.move.warp, canvasSize = container.canvas.size, newPos = {
68
68
  bottom: canvasSize.height + particle.getRadius() + particle.offset.y,
69
69
  left: -particle.getRadius() - particle.offset.x,
70
70
  right: canvasSize.width + particle.getRadius() + particle.offset.x,
71
71
  top: -particle.getRadius() - particle.offset.y,
72
72
  }, sizeValue = particle.getRadius(), nextBounds = (0, engine_1.calculateBounds)(particle.position, sizeValue);
73
- if (direction === "right" &&
73
+ if (direction === engine_1.OutModeDirection.right &&
74
74
  nextBounds.left > canvasSize.width + particle.offset.x) {
75
75
  particle.position.x = newPos.left;
76
76
  particle.initialPosition.x = particle.position.x;
@@ -79,7 +79,7 @@ class OutOutMode {
79
79
  particle.initialPosition.y = particle.position.y;
80
80
  }
81
81
  }
82
- else if (direction === "left" && nextBounds.right < -particle.offset.x) {
82
+ else if (direction === engine_1.OutModeDirection.left && nextBounds.right < -particle.offset.x) {
83
83
  particle.position.x = newPos.right;
84
84
  particle.initialPosition.x = particle.position.x;
85
85
  if (!warp) {
@@ -87,7 +87,7 @@ class OutOutMode {
87
87
  particle.initialPosition.y = particle.position.y;
88
88
  }
89
89
  }
90
- if (direction === "bottom" &&
90
+ if (direction === engine_1.OutModeDirection.bottom &&
91
91
  nextBounds.top > canvasSize.height + particle.offset.y) {
92
92
  if (!warp) {
93
93
  particle.position.x = (0, engine_1.getRandom)() * canvasSize.width;
@@ -96,7 +96,7 @@ class OutOutMode {
96
96
  particle.position.y = newPos.top;
97
97
  particle.initialPosition.y = particle.position.y;
98
98
  }
99
- else if (direction === "top" && nextBounds.bottom < -particle.offset.y) {
99
+ else if (direction === engine_1.OutModeDirection.top && nextBounds.bottom < -particle.offset.y) {
100
100
  if (!warp) {
101
101
  particle.position.x = (0, engine_1.getRandom)() * canvasSize.width;
102
102
  particle.initialPosition.x = particle.position.x;
package/cjs/Utils.js CHANGED
@@ -1,25 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.bounceVertical = exports.bounceHorizontal = void 0;
3
+ exports.bounceHorizontal = bounceHorizontal;
4
+ exports.bounceVertical = bounceVertical;
4
5
  const engine_1 = require("@tsparticles/engine");
5
6
  const minVelocity = 0, boundsMin = 0;
6
7
  function bounceHorizontal(data) {
7
- if ((data.outMode !== "bounce" && data.outMode !== "split") ||
8
- (data.direction !== "left" && data.direction !== "right")) {
8
+ if ((data.outMode !== engine_1.OutMode.bounce && data.outMode !== engine_1.OutMode.split) ||
9
+ (data.direction !== engine_1.OutModeDirection.left && data.direction !== engine_1.OutModeDirection.right)) {
9
10
  return;
10
11
  }
11
- if (data.bounds.right < boundsMin && data.direction === "left") {
12
+ if (data.bounds.right < boundsMin && data.direction === engine_1.OutModeDirection.left) {
12
13
  data.particle.position.x = data.size + data.offset.x;
13
14
  }
14
- else if (data.bounds.left > data.canvasSize.width && data.direction === "right") {
15
+ else if (data.bounds.left > data.canvasSize.width && data.direction === engine_1.OutModeDirection.right) {
15
16
  data.particle.position.x = data.canvasSize.width - data.size - data.offset.x;
16
17
  }
17
18
  const velocity = data.particle.velocity.x;
18
19
  let bounced = false;
19
- if ((data.direction === "right" &&
20
+ if ((data.direction === engine_1.OutModeDirection.right &&
20
21
  data.bounds.right >= data.canvasSize.width &&
21
22
  velocity > minVelocity) ||
22
- (data.direction === "left" && data.bounds.left <= boundsMin && velocity < minVelocity)) {
23
+ (data.direction === engine_1.OutModeDirection.left && data.bounds.left <= boundsMin && velocity < minVelocity)) {
23
24
  const newVelocity = (0, engine_1.getRangeValue)(data.particle.options.bounce.horizontal.value);
24
25
  data.particle.velocity.x *= -newVelocity;
25
26
  bounced = true;
@@ -28,34 +29,33 @@ function bounceHorizontal(data) {
28
29
  return;
29
30
  }
30
31
  const minPos = data.offset.x + data.size;
31
- if (data.bounds.right >= data.canvasSize.width && data.direction === "right") {
32
+ if (data.bounds.right >= data.canvasSize.width && data.direction === engine_1.OutModeDirection.right) {
32
33
  data.particle.position.x = data.canvasSize.width - minPos;
33
34
  }
34
- else if (data.bounds.left <= boundsMin && data.direction === "left") {
35
+ else if (data.bounds.left <= boundsMin && data.direction === engine_1.OutModeDirection.left) {
35
36
  data.particle.position.x = minPos;
36
37
  }
37
- if (data.outMode === "split") {
38
+ if (data.outMode === engine_1.OutMode.split) {
38
39
  data.particle.destroy();
39
40
  }
40
41
  }
41
- exports.bounceHorizontal = bounceHorizontal;
42
42
  function bounceVertical(data) {
43
- if ((data.outMode !== "bounce" && data.outMode !== "split") ||
44
- (data.direction !== "bottom" && data.direction !== "top")) {
43
+ if ((data.outMode !== engine_1.OutMode.bounce && data.outMode !== engine_1.OutMode.split) ||
44
+ (data.direction !== engine_1.OutModeDirection.bottom && data.direction !== engine_1.OutModeDirection.top)) {
45
45
  return;
46
46
  }
47
- if (data.bounds.bottom < boundsMin && data.direction === "top") {
47
+ if (data.bounds.bottom < boundsMin && data.direction === engine_1.OutModeDirection.top) {
48
48
  data.particle.position.y = data.size + data.offset.y;
49
49
  }
50
- else if (data.bounds.top > data.canvasSize.height && data.direction === "bottom") {
50
+ else if (data.bounds.top > data.canvasSize.height && data.direction === engine_1.OutModeDirection.bottom) {
51
51
  data.particle.position.y = data.canvasSize.height - data.size - data.offset.y;
52
52
  }
53
53
  const velocity = data.particle.velocity.y;
54
54
  let bounced = false;
55
- if ((data.direction === "bottom" &&
55
+ if ((data.direction === engine_1.OutModeDirection.bottom &&
56
56
  data.bounds.bottom >= data.canvasSize.height &&
57
57
  velocity > minVelocity) ||
58
- (data.direction === "top" && data.bounds.top <= boundsMin && velocity < minVelocity)) {
58
+ (data.direction === engine_1.OutModeDirection.top && data.bounds.top <= boundsMin && velocity < minVelocity)) {
59
59
  const newVelocity = (0, engine_1.getRangeValue)(data.particle.options.bounce.vertical.value);
60
60
  data.particle.velocity.y *= -newVelocity;
61
61
  bounced = true;
@@ -64,14 +64,13 @@ function bounceVertical(data) {
64
64
  return;
65
65
  }
66
66
  const minPos = data.offset.y + data.size;
67
- if (data.bounds.bottom >= data.canvasSize.height && data.direction === "bottom") {
67
+ if (data.bounds.bottom >= data.canvasSize.height && data.direction === engine_1.OutModeDirection.bottom) {
68
68
  data.particle.position.y = data.canvasSize.height - minPos;
69
69
  }
70
- else if (data.bounds.top <= boundsMin && data.direction === "top") {
70
+ else if (data.bounds.top <= boundsMin && data.direction === engine_1.OutModeDirection.top) {
71
71
  data.particle.position.y = minPos;
72
72
  }
73
- if (data.outMode === "split") {
73
+ if (data.outMode === engine_1.OutMode.split) {
74
74
  data.particle.destroy();
75
75
  }
76
76
  }
77
- exports.bounceVertical = bounceVertical;
package/cjs/index.js CHANGED
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadOutModesUpdater = void 0;
3
+ exports.loadOutModesUpdater = loadOutModesUpdater;
4
+ const OutOfCanvasUpdater_js_1 = require("./OutOfCanvasUpdater.js");
4
5
  async function loadOutModesUpdater(engine, refresh = true) {
5
- await engine.addParticleUpdater("outModes", async (container) => {
6
- const { OutOfCanvasUpdater } = await import("./OutOfCanvasUpdater.js");
7
- return new OutOfCanvasUpdater(container);
6
+ await engine.addParticleUpdater("outModes", container => {
7
+ return Promise.resolve(new OutOfCanvasUpdater_js_1.OutOfCanvasUpdater(container));
8
8
  }, refresh);
9
9
  }
10
- exports.loadOutModesUpdater = loadOutModesUpdater;
@@ -1,11 +1,11 @@
1
- import { calculateBounds, } from "@tsparticles/engine";
1
+ import { OutMode, calculateBounds, } from "@tsparticles/engine";
2
2
  import { bounceHorizontal, bounceVertical } from "./Utils.js";
3
3
  export class BounceOutMode {
4
4
  constructor(container) {
5
5
  this.container = container;
6
6
  this.modes = [
7
- "bounce",
8
- "split",
7
+ OutMode.bounce,
8
+ OutMode.split,
9
9
  ];
10
10
  }
11
11
  update(particle, direction, delta, outMode) {
@@ -1,9 +1,9 @@
1
- import { Vector, getDistances, isPointInside, } from "@tsparticles/engine";
1
+ import { OutMode, ParticleOutType, Vector, getDistances, isPointInside, } from "@tsparticles/engine";
2
2
  const minVelocity = 0;
3
3
  export class DestroyOutMode {
4
4
  constructor(container) {
5
5
  this.container = container;
6
- this.modes = ["destroy"];
6
+ this.modes = [OutMode.destroy];
7
7
  }
8
8
  update(particle, direction, _delta, outMode) {
9
9
  if (!this.modes.includes(outMode)) {
@@ -11,13 +11,13 @@ export class DestroyOutMode {
11
11
  }
12
12
  const container = this.container;
13
13
  switch (particle.outType) {
14
- case "normal":
15
- case "outside":
14
+ case ParticleOutType.normal:
15
+ case ParticleOutType.outside:
16
16
  if (isPointInside(particle.position, container.canvas.size, Vector.origin, particle.getRadius(), direction)) {
17
17
  return;
18
18
  }
19
19
  break;
20
- case "inside": {
20
+ case ParticleOutType.inside: {
21
21
  const { dx, dy } = getDistances(particle.position, particle.moveCenter), { x: vx, y: vy } = particle.velocity;
22
22
  if ((vx < minVelocity && dx > particle.moveCenter.radius) ||
23
23
  (vy < minVelocity && dy > particle.moveCenter.radius) ||