@tsparticles/updater-out-modes 3.0.0-alpha.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.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +70 -0
  3. package/browser/BounceOutMode.js +36 -0
  4. package/browser/DestroyOutMode.js +33 -0
  5. package/browser/IBounceData.js +1 -0
  6. package/browser/IOutModeManager.js +1 -0
  7. package/browser/NoneOutMode.js +41 -0
  8. package/browser/OutOfCanvasUpdater.js +33 -0
  9. package/browser/OutOutMode.js +107 -0
  10. package/browser/Utils.js +71 -0
  11. package/browser/index.js +4 -0
  12. package/cjs/BounceOutMode.js +40 -0
  13. package/cjs/DestroyOutMode.js +37 -0
  14. package/cjs/IBounceData.js +2 -0
  15. package/cjs/IOutModeManager.js +2 -0
  16. package/cjs/NoneOutMode.js +45 -0
  17. package/cjs/OutOfCanvasUpdater.js +37 -0
  18. package/cjs/OutOutMode.js +111 -0
  19. package/cjs/Utils.js +76 -0
  20. package/cjs/index.js +19 -0
  21. package/esm/BounceOutMode.js +36 -0
  22. package/esm/DestroyOutMode.js +33 -0
  23. package/esm/IBounceData.js +1 -0
  24. package/esm/IOutModeManager.js +1 -0
  25. package/esm/NoneOutMode.js +41 -0
  26. package/esm/OutOfCanvasUpdater.js +33 -0
  27. package/esm/OutOutMode.js +107 -0
  28. package/esm/Utils.js +71 -0
  29. package/esm/index.js +4 -0
  30. package/package.json +82 -0
  31. package/report.html +39 -0
  32. package/tsparticles.updater.out-modes.js +440 -0
  33. package/tsparticles.updater.out-modes.min.js +2 -0
  34. package/tsparticles.updater.out-modes.min.js.LICENSE.txt +8 -0
  35. package/types/BounceOutMode.d.ts +9 -0
  36. package/types/DestroyOutMode.d.ts +9 -0
  37. package/types/IBounceData.d.ts +11 -0
  38. package/types/IOutModeManager.d.ts +5 -0
  39. package/types/NoneOutMode.d.ts +9 -0
  40. package/types/OutOfCanvasUpdater.d.ts +11 -0
  41. package/types/OutOutMode.d.ts +9 -0
  42. package/types/Utils.d.ts +3 -0
  43. package/types/index.d.ts +2 -0
  44. package/umd/BounceOutMode.js +50 -0
  45. package/umd/DestroyOutMode.js +47 -0
  46. package/umd/IBounceData.js +12 -0
  47. package/umd/IOutModeManager.js +12 -0
  48. package/umd/NoneOutMode.js +55 -0
  49. package/umd/OutOfCanvasUpdater.js +47 -0
  50. package/umd/OutOutMode.js +121 -0
  51. package/umd/Utils.js +86 -0
  52. package/umd/index.js +18 -0
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OutOutMode = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ class OutOutMode {
6
+ constructor(container) {
7
+ this.container = container;
8
+ this.modes = ["out"];
9
+ }
10
+ update(particle, direction, delta, outMode) {
11
+ if (!this.modes.includes(outMode)) {
12
+ return;
13
+ }
14
+ const container = this.container;
15
+ switch (particle.outType) {
16
+ case "inside": {
17
+ const { x: vx, y: vy } = particle.velocity;
18
+ const circVec = engine_1.Vector.origin;
19
+ circVec.length = particle.moveCenter.radius;
20
+ circVec.angle = particle.velocity.angle + Math.PI;
21
+ circVec.addTo(engine_1.Vector.create(particle.moveCenter));
22
+ const { dx, dy } = (0, engine_1.getDistances)(particle.position, circVec);
23
+ if ((vx <= 0 && dx >= 0) || (vy <= 0 && dy >= 0) || (vx >= 0 && dx <= 0) || (vy >= 0 && dy <= 0)) {
24
+ return;
25
+ }
26
+ particle.position.x = Math.floor((0, engine_1.randomInRange)({
27
+ min: 0,
28
+ max: container.canvas.size.width,
29
+ }));
30
+ particle.position.y = Math.floor((0, engine_1.randomInRange)({
31
+ min: 0,
32
+ max: container.canvas.size.height,
33
+ }));
34
+ const { dx: newDx, dy: newDy } = (0, engine_1.getDistances)(particle.position, particle.moveCenter);
35
+ particle.direction = Math.atan2(-newDy, -newDx);
36
+ particle.velocity.angle = particle.direction;
37
+ break;
38
+ }
39
+ default: {
40
+ if ((0, engine_1.isPointInside)(particle.position, container.canvas.size, engine_1.Vector.origin, particle.getRadius(), direction)) {
41
+ return;
42
+ }
43
+ switch (particle.outType) {
44
+ case "outside": {
45
+ particle.position.x =
46
+ Math.floor((0, engine_1.randomInRange)({
47
+ min: -particle.moveCenter.radius,
48
+ max: particle.moveCenter.radius,
49
+ })) + particle.moveCenter.x;
50
+ particle.position.y =
51
+ Math.floor((0, engine_1.randomInRange)({
52
+ min: -particle.moveCenter.radius,
53
+ max: particle.moveCenter.radius,
54
+ })) + particle.moveCenter.y;
55
+ const { dx, dy } = (0, engine_1.getDistances)(particle.position, particle.moveCenter);
56
+ if (particle.moveCenter.radius) {
57
+ particle.direction = Math.atan2(dy, dx);
58
+ particle.velocity.angle = particle.direction;
59
+ }
60
+ break;
61
+ }
62
+ case "normal": {
63
+ const wrap = particle.options.move.warp, canvasSize = container.canvas.size, newPos = {
64
+ bottom: canvasSize.height + particle.getRadius() + particle.offset.y,
65
+ left: -particle.getRadius() - particle.offset.x,
66
+ right: canvasSize.width + particle.getRadius() + particle.offset.x,
67
+ top: -particle.getRadius() - particle.offset.y,
68
+ }, sizeValue = particle.getRadius(), nextBounds = (0, engine_1.calculateBounds)(particle.position, sizeValue);
69
+ if (direction === "right" &&
70
+ nextBounds.left > canvasSize.width + particle.offset.x) {
71
+ particle.position.x = newPos.left;
72
+ particle.initialPosition.x = particle.position.x;
73
+ if (!wrap) {
74
+ particle.position.y = (0, engine_1.getRandom)() * canvasSize.height;
75
+ particle.initialPosition.y = particle.position.y;
76
+ }
77
+ }
78
+ else if (direction === "left" && nextBounds.right < -particle.offset.x) {
79
+ particle.position.x = newPos.right;
80
+ particle.initialPosition.x = particle.position.x;
81
+ if (!wrap) {
82
+ particle.position.y = (0, engine_1.getRandom)() * canvasSize.height;
83
+ particle.initialPosition.y = particle.position.y;
84
+ }
85
+ }
86
+ if (direction === "bottom" &&
87
+ nextBounds.top > canvasSize.height + particle.offset.y) {
88
+ if (!wrap) {
89
+ particle.position.x = (0, engine_1.getRandom)() * canvasSize.width;
90
+ particle.initialPosition.x = particle.position.x;
91
+ }
92
+ particle.position.y = newPos.top;
93
+ particle.initialPosition.y = particle.position.y;
94
+ }
95
+ else if (direction === "top" && nextBounds.bottom < -particle.offset.y) {
96
+ if (!wrap) {
97
+ particle.position.x = (0, engine_1.getRandom)() * canvasSize.width;
98
+ particle.initialPosition.x = particle.position.x;
99
+ }
100
+ particle.position.y = newPos.bottom;
101
+ particle.initialPosition.y = particle.position.y;
102
+ }
103
+ break;
104
+ }
105
+ }
106
+ break;
107
+ }
108
+ }
109
+ }
110
+ }
111
+ exports.OutOutMode = OutOutMode;
package/cjs/Utils.js ADDED
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bounceVertical = exports.bounceHorizontal = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ function bounceHorizontal(data) {
6
+ if (data.outMode !== "bounce" &&
7
+ data.outMode !== "bounce-horizontal" &&
8
+ data.outMode !== "bounceHorizontal" &&
9
+ data.outMode !== "split") {
10
+ return;
11
+ }
12
+ if (data.bounds.right < 0) {
13
+ data.particle.position.x = data.size + data.offset.x;
14
+ }
15
+ else if (data.bounds.left > data.canvasSize.width) {
16
+ data.particle.position.x = data.canvasSize.width - data.size - data.offset.x;
17
+ }
18
+ const velocity = data.particle.velocity.x;
19
+ let bounced = false;
20
+ if ((data.direction === "right" && data.bounds.right >= data.canvasSize.width && velocity > 0) ||
21
+ (data.direction === "left" && data.bounds.left <= 0 && velocity < 0)) {
22
+ const newVelocity = (0, engine_1.getValue)(data.particle.options.bounce.horizontal);
23
+ data.particle.velocity.x *= -newVelocity;
24
+ bounced = true;
25
+ }
26
+ if (!bounced) {
27
+ return;
28
+ }
29
+ const minPos = data.offset.x + data.size;
30
+ if (data.bounds.right >= data.canvasSize.width) {
31
+ data.particle.position.x = data.canvasSize.width - minPos;
32
+ }
33
+ else if (data.bounds.left <= 0) {
34
+ data.particle.position.x = minPos;
35
+ }
36
+ if (data.outMode === "split") {
37
+ data.particle.destroy();
38
+ }
39
+ }
40
+ exports.bounceHorizontal = bounceHorizontal;
41
+ function bounceVertical(data) {
42
+ if (data.outMode !== "bounce" &&
43
+ data.outMode !== "bounce-vertical" &&
44
+ data.outMode !== "bounceVertical" &&
45
+ data.outMode !== "split") {
46
+ return;
47
+ }
48
+ if (data.bounds.bottom < 0) {
49
+ data.particle.position.y = data.size + data.offset.y;
50
+ }
51
+ else if (data.bounds.top > data.canvasSize.height) {
52
+ data.particle.position.y = data.canvasSize.height - data.size - data.offset.y;
53
+ }
54
+ const velocity = data.particle.velocity.y;
55
+ let bounced = false;
56
+ if ((data.direction === "bottom" && data.bounds.bottom >= data.canvasSize.height && velocity > 0) ||
57
+ (data.direction === "top" && data.bounds.top <= 0 && velocity < 0)) {
58
+ const newVelocity = (0, engine_1.getValue)(data.particle.options.bounce.vertical);
59
+ data.particle.velocity.y *= -newVelocity;
60
+ bounced = true;
61
+ }
62
+ if (!bounced) {
63
+ return;
64
+ }
65
+ const minPos = data.offset.y + data.size;
66
+ if (data.bounds.bottom >= data.canvasSize.height) {
67
+ data.particle.position.y = data.canvasSize.height - minPos;
68
+ }
69
+ else if (data.bounds.top <= 0) {
70
+ data.particle.position.y = minPos;
71
+ }
72
+ if (data.outMode === "split") {
73
+ data.particle.destroy();
74
+ }
75
+ }
76
+ exports.bounceVertical = bounceVertical;
package/cjs/index.js ADDED
@@ -0,0 +1,19 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.loadOutModesUpdater = void 0;
13
+ const OutOfCanvasUpdater_1 = require("./OutOfCanvasUpdater");
14
+ function loadOutModesUpdater(engine) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ yield engine.addParticleUpdater("outModes", (container) => new OutOfCanvasUpdater_1.OutOfCanvasUpdater(container));
17
+ });
18
+ }
19
+ exports.loadOutModesUpdater = loadOutModesUpdater;
@@ -0,0 +1,36 @@
1
+ import { calculateBounds } from "@tsparticles/engine";
2
+ import { bounceHorizontal, bounceVertical } from "./Utils";
3
+ export class BounceOutMode {
4
+ constructor(container) {
5
+ this.container = container;
6
+ this.modes = [
7
+ "bounce",
8
+ "bounce-vertical",
9
+ "bounce-horizontal",
10
+ "bounceVertical",
11
+ "bounceHorizontal",
12
+ "split",
13
+ ];
14
+ }
15
+ update(particle, direction, delta, outMode) {
16
+ if (!this.modes.includes(outMode)) {
17
+ return;
18
+ }
19
+ const container = this.container;
20
+ let handled = false;
21
+ for (const [, plugin] of container.plugins) {
22
+ if (plugin.particleBounce !== undefined) {
23
+ handled = plugin.particleBounce(particle, delta, direction);
24
+ }
25
+ if (handled) {
26
+ break;
27
+ }
28
+ }
29
+ if (handled) {
30
+ return;
31
+ }
32
+ const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size;
33
+ bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, size });
34
+ bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, size });
35
+ }
36
+ }
@@ -0,0 +1,33 @@
1
+ import { Vector, getDistances, isPointInside } from "@tsparticles/engine";
2
+ export class DestroyOutMode {
3
+ constructor(container) {
4
+ this.container = container;
5
+ this.modes = ["destroy"];
6
+ }
7
+ update(particle, direction, delta, outMode) {
8
+ if (!this.modes.includes(outMode)) {
9
+ return;
10
+ }
11
+ const container = this.container;
12
+ switch (particle.outType) {
13
+ case "normal":
14
+ case "outside":
15
+ if (isPointInside(particle.position, container.canvas.size, Vector.origin, particle.getRadius(), direction)) {
16
+ return;
17
+ }
18
+ break;
19
+ case "inside": {
20
+ const { dx, dy } = getDistances(particle.position, particle.moveCenter);
21
+ const { x: vx, y: vy } = particle.velocity;
22
+ if ((vx < 0 && dx > particle.moveCenter.radius) ||
23
+ (vy < 0 && dy > particle.moveCenter.radius) ||
24
+ (vx >= 0 && dx < -particle.moveCenter.radius) ||
25
+ (vy >= 0 && dy < -particle.moveCenter.radius)) {
26
+ return;
27
+ }
28
+ break;
29
+ }
30
+ }
31
+ container.particles.remove(particle, undefined, true);
32
+ }
33
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,41 @@
1
+ import { Vector, isPointInside } from "@tsparticles/engine";
2
+ export class NoneOutMode {
3
+ constructor(container) {
4
+ this.container = container;
5
+ this.modes = ["none"];
6
+ }
7
+ update(particle, direction, delta, outMode) {
8
+ if (!this.modes.includes(outMode)) {
9
+ return;
10
+ }
11
+ if ((particle.options.move.distance.horizontal &&
12
+ (direction === "left" || direction === "right")) ||
13
+ (particle.options.move.distance.vertical &&
14
+ (direction === "top" || direction === "bottom"))) {
15
+ return;
16
+ }
17
+ const gravityOptions = particle.options.move.gravity, container = this.container;
18
+ const canvasSize = container.canvas.size;
19
+ const pRadius = particle.getRadius();
20
+ if (!gravityOptions.enable) {
21
+ if ((particle.velocity.y > 0 && particle.position.y <= canvasSize.height + pRadius) ||
22
+ (particle.velocity.y < 0 && particle.position.y >= -pRadius) ||
23
+ (particle.velocity.x > 0 && particle.position.x <= canvasSize.width + pRadius) ||
24
+ (particle.velocity.x < 0 && particle.position.x >= -pRadius)) {
25
+ return;
26
+ }
27
+ if (!isPointInside(particle.position, container.canvas.size, Vector.origin, pRadius, direction)) {
28
+ container.particles.remove(particle);
29
+ }
30
+ }
31
+ else {
32
+ const position = particle.position;
33
+ if ((!gravityOptions.inverse &&
34
+ position.y > canvasSize.height + pRadius &&
35
+ direction === "bottom") ||
36
+ (gravityOptions.inverse && position.y < -pRadius && direction === "top")) {
37
+ container.particles.remove(particle);
38
+ }
39
+ }
40
+ }
41
+ }
@@ -0,0 +1,33 @@
1
+ import { BounceOutMode } from "./BounceOutMode";
2
+ import { DestroyOutMode } from "./DestroyOutMode";
3
+ import { NoneOutMode } from "./NoneOutMode";
4
+ import { OutOutMode } from "./OutOutMode";
5
+ export class OutOfCanvasUpdater {
6
+ constructor(container) {
7
+ this.container = container;
8
+ this.updaters = [
9
+ new BounceOutMode(container),
10
+ new DestroyOutMode(container),
11
+ new OutOutMode(container),
12
+ new NoneOutMode(container),
13
+ ];
14
+ }
15
+ init() {
16
+ }
17
+ isEnabled(particle) {
18
+ return !particle.destroyed && !particle.spawning;
19
+ }
20
+ update(particle, delta) {
21
+ var _a, _b, _c, _d;
22
+ const outModes = particle.options.move.outModes;
23
+ this.updateOutMode(particle, delta, (_a = outModes.bottom) !== null && _a !== void 0 ? _a : outModes.default, "bottom");
24
+ this.updateOutMode(particle, delta, (_b = outModes.left) !== null && _b !== void 0 ? _b : outModes.default, "left");
25
+ this.updateOutMode(particle, delta, (_c = outModes.right) !== null && _c !== void 0 ? _c : outModes.default, "right");
26
+ this.updateOutMode(particle, delta, (_d = outModes.top) !== null && _d !== void 0 ? _d : outModes.default, "top");
27
+ }
28
+ updateOutMode(particle, delta, outMode, direction) {
29
+ for (const updater of this.updaters) {
30
+ updater.update(particle, direction, delta, outMode);
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,107 @@
1
+ import { Vector, calculateBounds, getDistances, getRandom, isPointInside, randomInRange, } from "@tsparticles/engine";
2
+ export class OutOutMode {
3
+ constructor(container) {
4
+ this.container = container;
5
+ this.modes = ["out"];
6
+ }
7
+ update(particle, direction, delta, outMode) {
8
+ if (!this.modes.includes(outMode)) {
9
+ return;
10
+ }
11
+ const container = this.container;
12
+ switch (particle.outType) {
13
+ case "inside": {
14
+ const { x: vx, y: vy } = particle.velocity;
15
+ const circVec = Vector.origin;
16
+ circVec.length = particle.moveCenter.radius;
17
+ circVec.angle = particle.velocity.angle + Math.PI;
18
+ circVec.addTo(Vector.create(particle.moveCenter));
19
+ const { dx, dy } = getDistances(particle.position, circVec);
20
+ if ((vx <= 0 && dx >= 0) || (vy <= 0 && dy >= 0) || (vx >= 0 && dx <= 0) || (vy >= 0 && dy <= 0)) {
21
+ return;
22
+ }
23
+ particle.position.x = Math.floor(randomInRange({
24
+ min: 0,
25
+ max: container.canvas.size.width,
26
+ }));
27
+ particle.position.y = Math.floor(randomInRange({
28
+ min: 0,
29
+ max: container.canvas.size.height,
30
+ }));
31
+ const { dx: newDx, dy: newDy } = getDistances(particle.position, particle.moveCenter);
32
+ particle.direction = Math.atan2(-newDy, -newDx);
33
+ particle.velocity.angle = particle.direction;
34
+ break;
35
+ }
36
+ default: {
37
+ if (isPointInside(particle.position, container.canvas.size, Vector.origin, particle.getRadius(), direction)) {
38
+ return;
39
+ }
40
+ switch (particle.outType) {
41
+ case "outside": {
42
+ particle.position.x =
43
+ Math.floor(randomInRange({
44
+ min: -particle.moveCenter.radius,
45
+ max: particle.moveCenter.radius,
46
+ })) + particle.moveCenter.x;
47
+ particle.position.y =
48
+ Math.floor(randomInRange({
49
+ min: -particle.moveCenter.radius,
50
+ max: particle.moveCenter.radius,
51
+ })) + particle.moveCenter.y;
52
+ const { dx, dy } = getDistances(particle.position, particle.moveCenter);
53
+ if (particle.moveCenter.radius) {
54
+ particle.direction = Math.atan2(dy, dx);
55
+ particle.velocity.angle = particle.direction;
56
+ }
57
+ break;
58
+ }
59
+ case "normal": {
60
+ const wrap = particle.options.move.warp, canvasSize = container.canvas.size, newPos = {
61
+ bottom: canvasSize.height + particle.getRadius() + particle.offset.y,
62
+ left: -particle.getRadius() - particle.offset.x,
63
+ right: canvasSize.width + particle.getRadius() + particle.offset.x,
64
+ top: -particle.getRadius() - particle.offset.y,
65
+ }, sizeValue = particle.getRadius(), nextBounds = calculateBounds(particle.position, sizeValue);
66
+ if (direction === "right" &&
67
+ nextBounds.left > canvasSize.width + particle.offset.x) {
68
+ particle.position.x = newPos.left;
69
+ particle.initialPosition.x = particle.position.x;
70
+ if (!wrap) {
71
+ particle.position.y = getRandom() * canvasSize.height;
72
+ particle.initialPosition.y = particle.position.y;
73
+ }
74
+ }
75
+ else if (direction === "left" && nextBounds.right < -particle.offset.x) {
76
+ particle.position.x = newPos.right;
77
+ particle.initialPosition.x = particle.position.x;
78
+ if (!wrap) {
79
+ particle.position.y = getRandom() * canvasSize.height;
80
+ particle.initialPosition.y = particle.position.y;
81
+ }
82
+ }
83
+ if (direction === "bottom" &&
84
+ nextBounds.top > canvasSize.height + particle.offset.y) {
85
+ if (!wrap) {
86
+ particle.position.x = getRandom() * canvasSize.width;
87
+ particle.initialPosition.x = particle.position.x;
88
+ }
89
+ particle.position.y = newPos.top;
90
+ particle.initialPosition.y = particle.position.y;
91
+ }
92
+ else if (direction === "top" && nextBounds.bottom < -particle.offset.y) {
93
+ if (!wrap) {
94
+ particle.position.x = getRandom() * canvasSize.width;
95
+ particle.initialPosition.x = particle.position.x;
96
+ }
97
+ particle.position.y = newPos.bottom;
98
+ particle.initialPosition.y = particle.position.y;
99
+ }
100
+ break;
101
+ }
102
+ }
103
+ break;
104
+ }
105
+ }
106
+ }
107
+ }
package/esm/Utils.js ADDED
@@ -0,0 +1,71 @@
1
+ import { getValue } from "@tsparticles/engine";
2
+ export function bounceHorizontal(data) {
3
+ if (data.outMode !== "bounce" &&
4
+ data.outMode !== "bounce-horizontal" &&
5
+ data.outMode !== "bounceHorizontal" &&
6
+ data.outMode !== "split") {
7
+ return;
8
+ }
9
+ if (data.bounds.right < 0) {
10
+ data.particle.position.x = data.size + data.offset.x;
11
+ }
12
+ else if (data.bounds.left > data.canvasSize.width) {
13
+ data.particle.position.x = data.canvasSize.width - data.size - data.offset.x;
14
+ }
15
+ const velocity = data.particle.velocity.x;
16
+ let bounced = false;
17
+ if ((data.direction === "right" && data.bounds.right >= data.canvasSize.width && velocity > 0) ||
18
+ (data.direction === "left" && data.bounds.left <= 0 && velocity < 0)) {
19
+ const newVelocity = getValue(data.particle.options.bounce.horizontal);
20
+ data.particle.velocity.x *= -newVelocity;
21
+ bounced = true;
22
+ }
23
+ if (!bounced) {
24
+ return;
25
+ }
26
+ const minPos = data.offset.x + data.size;
27
+ if (data.bounds.right >= data.canvasSize.width) {
28
+ data.particle.position.x = data.canvasSize.width - minPos;
29
+ }
30
+ else if (data.bounds.left <= 0) {
31
+ data.particle.position.x = minPos;
32
+ }
33
+ if (data.outMode === "split") {
34
+ data.particle.destroy();
35
+ }
36
+ }
37
+ export function bounceVertical(data) {
38
+ if (data.outMode !== "bounce" &&
39
+ data.outMode !== "bounce-vertical" &&
40
+ data.outMode !== "bounceVertical" &&
41
+ data.outMode !== "split") {
42
+ return;
43
+ }
44
+ if (data.bounds.bottom < 0) {
45
+ data.particle.position.y = data.size + data.offset.y;
46
+ }
47
+ else if (data.bounds.top > data.canvasSize.height) {
48
+ data.particle.position.y = data.canvasSize.height - data.size - data.offset.y;
49
+ }
50
+ const velocity = data.particle.velocity.y;
51
+ let bounced = false;
52
+ if ((data.direction === "bottom" && data.bounds.bottom >= data.canvasSize.height && velocity > 0) ||
53
+ (data.direction === "top" && data.bounds.top <= 0 && velocity < 0)) {
54
+ const newVelocity = getValue(data.particle.options.bounce.vertical);
55
+ data.particle.velocity.y *= -newVelocity;
56
+ bounced = true;
57
+ }
58
+ if (!bounced) {
59
+ return;
60
+ }
61
+ const minPos = data.offset.y + data.size;
62
+ if (data.bounds.bottom >= data.canvasSize.height) {
63
+ data.particle.position.y = data.canvasSize.height - minPos;
64
+ }
65
+ else if (data.bounds.top <= 0) {
66
+ data.particle.position.y = minPos;
67
+ }
68
+ if (data.outMode === "split") {
69
+ data.particle.destroy();
70
+ }
71
+ }
package/esm/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { OutOfCanvasUpdater } from "./OutOfCanvasUpdater";
2
+ export async function loadOutModesUpdater(engine) {
3
+ await engine.addParticleUpdater("outModes", (container) => new OutOfCanvasUpdater(container));
4
+ }
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@tsparticles/updater-out-modes",
3
+ "version": "3.0.0-alpha.0",
4
+ "description": "tsParticles particles out modes updater",
5
+ "homepage": "https://particles.js.org",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/matteobruni/tsparticles.git",
9
+ "directory": "updaters/outModes"
10
+ },
11
+ "keywords": [
12
+ "front-end",
13
+ "frontend",
14
+ "tsparticles",
15
+ "particles.js",
16
+ "particlesjs",
17
+ "particles",
18
+ "particle",
19
+ "canvas",
20
+ "jsparticles",
21
+ "xparticles",
22
+ "particles-js",
23
+ "particles-bg",
24
+ "particles-bg-vue",
25
+ "particles-ts",
26
+ "particles.ts",
27
+ "react-particles-js",
28
+ "react-particles.js",
29
+ "react-particles",
30
+ "react",
31
+ "reactjs",
32
+ "vue-particles",
33
+ "ngx-particles",
34
+ "angular-particles",
35
+ "particleground",
36
+ "vue",
37
+ "vuejs",
38
+ "preact",
39
+ "preactjs",
40
+ "jquery",
41
+ "angularjs",
42
+ "angular",
43
+ "typescript",
44
+ "javascript",
45
+ "animation",
46
+ "web",
47
+ "html5",
48
+ "web-design",
49
+ "webdesign",
50
+ "css",
51
+ "html",
52
+ "css3",
53
+ "animated",
54
+ "background",
55
+ "confetti",
56
+ "canvas",
57
+ "fireworks",
58
+ "fireworks-js",
59
+ "confetti-js",
60
+ "confettijs",
61
+ "fireworksjs",
62
+ "canvas-confetti",
63
+ "@tsparticles/plugin",
64
+ "@tsparticles/updater"
65
+ ],
66
+ "author": "Matteo Bruni <matteo.bruni@me.com>",
67
+ "license": "MIT",
68
+ "bugs": {
69
+ "url": "https://github.com/matteobruni/tsparticles/issues"
70
+ },
71
+ "main": "cjs/index.js",
72
+ "jsdelivr": "tsparticles.updater.out-modes.min.js",
73
+ "unpkg": "tsparticles.updater.out-modes.min.js",
74
+ "module": "esm/index.js",
75
+ "types": "types/index.d.ts",
76
+ "publishConfig": {
77
+ "access": "public"
78
+ },
79
+ "dependencies": {
80
+ "@tsparticles/engine": "^3.0.0-alpha.0"
81
+ }
82
+ }