@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,12 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ });
@@ -0,0 +1,55 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "@tsparticles/engine"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.NoneOutMode = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ class NoneOutMode {
15
+ constructor(container) {
16
+ this.container = container;
17
+ this.modes = ["none"];
18
+ }
19
+ update(particle, direction, delta, outMode) {
20
+ if (!this.modes.includes(outMode)) {
21
+ return;
22
+ }
23
+ if ((particle.options.move.distance.horizontal &&
24
+ (direction === "left" || direction === "right")) ||
25
+ (particle.options.move.distance.vertical &&
26
+ (direction === "top" || direction === "bottom"))) {
27
+ return;
28
+ }
29
+ const gravityOptions = particle.options.move.gravity, container = this.container;
30
+ const canvasSize = container.canvas.size;
31
+ const pRadius = particle.getRadius();
32
+ if (!gravityOptions.enable) {
33
+ if ((particle.velocity.y > 0 && particle.position.y <= canvasSize.height + pRadius) ||
34
+ (particle.velocity.y < 0 && particle.position.y >= -pRadius) ||
35
+ (particle.velocity.x > 0 && particle.position.x <= canvasSize.width + pRadius) ||
36
+ (particle.velocity.x < 0 && particle.position.x >= -pRadius)) {
37
+ return;
38
+ }
39
+ if (!(0, engine_1.isPointInside)(particle.position, container.canvas.size, engine_1.Vector.origin, pRadius, direction)) {
40
+ container.particles.remove(particle);
41
+ }
42
+ }
43
+ else {
44
+ const position = particle.position;
45
+ if ((!gravityOptions.inverse &&
46
+ position.y > canvasSize.height + pRadius &&
47
+ direction === "bottom") ||
48
+ (gravityOptions.inverse && position.y < -pRadius && direction === "top")) {
49
+ container.particles.remove(particle);
50
+ }
51
+ }
52
+ }
53
+ }
54
+ exports.NoneOutMode = NoneOutMode;
55
+ });
@@ -0,0 +1,47 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "./BounceOutMode", "./DestroyOutMode", "./NoneOutMode", "./OutOutMode"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.OutOfCanvasUpdater = void 0;
13
+ const BounceOutMode_1 = require("./BounceOutMode");
14
+ const DestroyOutMode_1 = require("./DestroyOutMode");
15
+ const NoneOutMode_1 = require("./NoneOutMode");
16
+ const OutOutMode_1 = require("./OutOutMode");
17
+ class OutOfCanvasUpdater {
18
+ constructor(container) {
19
+ this.container = container;
20
+ this.updaters = [
21
+ new BounceOutMode_1.BounceOutMode(container),
22
+ new DestroyOutMode_1.DestroyOutMode(container),
23
+ new OutOutMode_1.OutOutMode(container),
24
+ new NoneOutMode_1.NoneOutMode(container),
25
+ ];
26
+ }
27
+ init() {
28
+ }
29
+ isEnabled(particle) {
30
+ return !particle.destroyed && !particle.spawning;
31
+ }
32
+ update(particle, delta) {
33
+ var _a, _b, _c, _d;
34
+ const outModes = particle.options.move.outModes;
35
+ this.updateOutMode(particle, delta, (_a = outModes.bottom) !== null && _a !== void 0 ? _a : outModes.default, "bottom");
36
+ this.updateOutMode(particle, delta, (_b = outModes.left) !== null && _b !== void 0 ? _b : outModes.default, "left");
37
+ this.updateOutMode(particle, delta, (_c = outModes.right) !== null && _c !== void 0 ? _c : outModes.default, "right");
38
+ this.updateOutMode(particle, delta, (_d = outModes.top) !== null && _d !== void 0 ? _d : outModes.default, "top");
39
+ }
40
+ updateOutMode(particle, delta, outMode, direction) {
41
+ for (const updater of this.updaters) {
42
+ updater.update(particle, direction, delta, outMode);
43
+ }
44
+ }
45
+ }
46
+ exports.OutOfCanvasUpdater = OutOfCanvasUpdater;
47
+ });
@@ -0,0 +1,121 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "@tsparticles/engine"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.OutOutMode = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ class OutOutMode {
15
+ constructor(container) {
16
+ this.container = container;
17
+ this.modes = ["out"];
18
+ }
19
+ update(particle, direction, delta, outMode) {
20
+ if (!this.modes.includes(outMode)) {
21
+ return;
22
+ }
23
+ const container = this.container;
24
+ switch (particle.outType) {
25
+ case "inside": {
26
+ const { x: vx, y: vy } = particle.velocity;
27
+ const circVec = engine_1.Vector.origin;
28
+ circVec.length = particle.moveCenter.radius;
29
+ circVec.angle = particle.velocity.angle + Math.PI;
30
+ circVec.addTo(engine_1.Vector.create(particle.moveCenter));
31
+ const { dx, dy } = (0, engine_1.getDistances)(particle.position, circVec);
32
+ if ((vx <= 0 && dx >= 0) || (vy <= 0 && dy >= 0) || (vx >= 0 && dx <= 0) || (vy >= 0 && dy <= 0)) {
33
+ return;
34
+ }
35
+ particle.position.x = Math.floor((0, engine_1.randomInRange)({
36
+ min: 0,
37
+ max: container.canvas.size.width,
38
+ }));
39
+ particle.position.y = Math.floor((0, engine_1.randomInRange)({
40
+ min: 0,
41
+ max: container.canvas.size.height,
42
+ }));
43
+ const { dx: newDx, dy: newDy } = (0, engine_1.getDistances)(particle.position, particle.moveCenter);
44
+ particle.direction = Math.atan2(-newDy, -newDx);
45
+ particle.velocity.angle = particle.direction;
46
+ break;
47
+ }
48
+ default: {
49
+ if ((0, engine_1.isPointInside)(particle.position, container.canvas.size, engine_1.Vector.origin, particle.getRadius(), direction)) {
50
+ return;
51
+ }
52
+ switch (particle.outType) {
53
+ case "outside": {
54
+ particle.position.x =
55
+ Math.floor((0, engine_1.randomInRange)({
56
+ min: -particle.moveCenter.radius,
57
+ max: particle.moveCenter.radius,
58
+ })) + particle.moveCenter.x;
59
+ particle.position.y =
60
+ Math.floor((0, engine_1.randomInRange)({
61
+ min: -particle.moveCenter.radius,
62
+ max: particle.moveCenter.radius,
63
+ })) + particle.moveCenter.y;
64
+ const { dx, dy } = (0, engine_1.getDistances)(particle.position, particle.moveCenter);
65
+ if (particle.moveCenter.radius) {
66
+ particle.direction = Math.atan2(dy, dx);
67
+ particle.velocity.angle = particle.direction;
68
+ }
69
+ break;
70
+ }
71
+ case "normal": {
72
+ const wrap = particle.options.move.warp, canvasSize = container.canvas.size, newPos = {
73
+ bottom: canvasSize.height + particle.getRadius() + particle.offset.y,
74
+ left: -particle.getRadius() - particle.offset.x,
75
+ right: canvasSize.width + particle.getRadius() + particle.offset.x,
76
+ top: -particle.getRadius() - particle.offset.y,
77
+ }, sizeValue = particle.getRadius(), nextBounds = (0, engine_1.calculateBounds)(particle.position, sizeValue);
78
+ if (direction === "right" &&
79
+ nextBounds.left > canvasSize.width + particle.offset.x) {
80
+ particle.position.x = newPos.left;
81
+ particle.initialPosition.x = particle.position.x;
82
+ if (!wrap) {
83
+ particle.position.y = (0, engine_1.getRandom)() * canvasSize.height;
84
+ particle.initialPosition.y = particle.position.y;
85
+ }
86
+ }
87
+ else if (direction === "left" && nextBounds.right < -particle.offset.x) {
88
+ particle.position.x = newPos.right;
89
+ particle.initialPosition.x = particle.position.x;
90
+ if (!wrap) {
91
+ particle.position.y = (0, engine_1.getRandom)() * canvasSize.height;
92
+ particle.initialPosition.y = particle.position.y;
93
+ }
94
+ }
95
+ if (direction === "bottom" &&
96
+ nextBounds.top > canvasSize.height + particle.offset.y) {
97
+ if (!wrap) {
98
+ particle.position.x = (0, engine_1.getRandom)() * canvasSize.width;
99
+ particle.initialPosition.x = particle.position.x;
100
+ }
101
+ particle.position.y = newPos.top;
102
+ particle.initialPosition.y = particle.position.y;
103
+ }
104
+ else if (direction === "top" && nextBounds.bottom < -particle.offset.y) {
105
+ if (!wrap) {
106
+ particle.position.x = (0, engine_1.getRandom)() * canvasSize.width;
107
+ particle.initialPosition.x = particle.position.x;
108
+ }
109
+ particle.position.y = newPos.bottom;
110
+ particle.initialPosition.y = particle.position.y;
111
+ }
112
+ break;
113
+ }
114
+ }
115
+ break;
116
+ }
117
+ }
118
+ }
119
+ }
120
+ exports.OutOutMode = OutOutMode;
121
+ });
package/umd/Utils.js ADDED
@@ -0,0 +1,86 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "@tsparticles/engine"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.bounceVertical = exports.bounceHorizontal = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ function bounceHorizontal(data) {
15
+ if (data.outMode !== "bounce" &&
16
+ data.outMode !== "bounce-horizontal" &&
17
+ data.outMode !== "bounceHorizontal" &&
18
+ data.outMode !== "split") {
19
+ return;
20
+ }
21
+ if (data.bounds.right < 0) {
22
+ data.particle.position.x = data.size + data.offset.x;
23
+ }
24
+ else if (data.bounds.left > data.canvasSize.width) {
25
+ data.particle.position.x = data.canvasSize.width - data.size - data.offset.x;
26
+ }
27
+ const velocity = data.particle.velocity.x;
28
+ let bounced = false;
29
+ if ((data.direction === "right" && data.bounds.right >= data.canvasSize.width && velocity > 0) ||
30
+ (data.direction === "left" && data.bounds.left <= 0 && velocity < 0)) {
31
+ const newVelocity = (0, engine_1.getValue)(data.particle.options.bounce.horizontal);
32
+ data.particle.velocity.x *= -newVelocity;
33
+ bounced = true;
34
+ }
35
+ if (!bounced) {
36
+ return;
37
+ }
38
+ const minPos = data.offset.x + data.size;
39
+ if (data.bounds.right >= data.canvasSize.width) {
40
+ data.particle.position.x = data.canvasSize.width - minPos;
41
+ }
42
+ else if (data.bounds.left <= 0) {
43
+ data.particle.position.x = minPos;
44
+ }
45
+ if (data.outMode === "split") {
46
+ data.particle.destroy();
47
+ }
48
+ }
49
+ exports.bounceHorizontal = bounceHorizontal;
50
+ function bounceVertical(data) {
51
+ if (data.outMode !== "bounce" &&
52
+ data.outMode !== "bounce-vertical" &&
53
+ data.outMode !== "bounceVertical" &&
54
+ data.outMode !== "split") {
55
+ return;
56
+ }
57
+ if (data.bounds.bottom < 0) {
58
+ data.particle.position.y = data.size + data.offset.y;
59
+ }
60
+ else if (data.bounds.top > data.canvasSize.height) {
61
+ data.particle.position.y = data.canvasSize.height - data.size - data.offset.y;
62
+ }
63
+ const velocity = data.particle.velocity.y;
64
+ let bounced = false;
65
+ if ((data.direction === "bottom" && data.bounds.bottom >= data.canvasSize.height && velocity > 0) ||
66
+ (data.direction === "top" && data.bounds.top <= 0 && velocity < 0)) {
67
+ const newVelocity = (0, engine_1.getValue)(data.particle.options.bounce.vertical);
68
+ data.particle.velocity.y *= -newVelocity;
69
+ bounced = true;
70
+ }
71
+ if (!bounced) {
72
+ return;
73
+ }
74
+ const minPos = data.offset.y + data.size;
75
+ if (data.bounds.bottom >= data.canvasSize.height) {
76
+ data.particle.position.y = data.canvasSize.height - minPos;
77
+ }
78
+ else if (data.bounds.top <= 0) {
79
+ data.particle.position.y = minPos;
80
+ }
81
+ if (data.outMode === "split") {
82
+ data.particle.destroy();
83
+ }
84
+ }
85
+ exports.bounceVertical = bounceVertical;
86
+ });
package/umd/index.js ADDED
@@ -0,0 +1,18 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "./OutOfCanvasUpdater"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.loadOutModesUpdater = void 0;
13
+ const OutOfCanvasUpdater_1 = require("./OutOfCanvasUpdater");
14
+ async function loadOutModesUpdater(engine) {
15
+ await engine.addParticleUpdater("outModes", (container) => new OutOfCanvasUpdater_1.OutOfCanvasUpdater(container));
16
+ }
17
+ exports.loadOutModesUpdater = loadOutModesUpdater;
18
+ });