@tsparticles/updater-out-modes 3.2.2 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/BounceOutMode.js +7 -6
- package/browser/DestroyOutMode.js +6 -7
- package/browser/NoneOutMode.js +7 -8
- package/browser/OutOfCanvasUpdater.js +17 -16
- package/browser/OutOutMode.js +10 -11
- package/browser/Utils.js +19 -19
- package/browser/index.js +3 -3
- package/cjs/BounceOutMode.js +8 -30
- package/cjs/DestroyOutMode.js +5 -6
- package/cjs/NoneOutMode.js +6 -7
- package/cjs/OutOfCanvasUpdater.js +21 -43
- package/cjs/OutOutMode.js +9 -10
- package/cjs/Utils.js +18 -18
- package/cjs/index.js +3 -26
- package/esm/BounceOutMode.js +7 -6
- package/esm/DestroyOutMode.js +6 -7
- package/esm/NoneOutMode.js +7 -8
- package/esm/OutOfCanvasUpdater.js +17 -16
- package/esm/OutOutMode.js +10 -11
- package/esm/Utils.js +19 -19
- package/esm/index.js +3 -3
- package/package.json +2 -2
- package/report.html +1 -1
- package/tsparticles.updater.out-modes.js +62 -200
- package/tsparticles.updater.out-modes.min.js +1 -1
- package/tsparticles.updater.out-modes.min.js.LICENSE.txt +1 -1
- package/types/BounceOutMode.d.ts +1 -1
- package/types/DestroyOutMode.d.ts +1 -1
- package/types/IOutModeManager.d.ts +1 -1
- package/types/NoneOutMode.d.ts +1 -1
- package/types/OutOfCanvasUpdater.d.ts +2 -2
- package/types/OutOutMode.d.ts +1 -1
- package/umd/BounceOutMode.js +9 -32
- package/umd/DestroyOutMode.js +5 -6
- package/umd/NoneOutMode.js +6 -7
- package/umd/OutOfCanvasUpdater.js +22 -45
- package/umd/OutOutMode.js +9 -10
- package/umd/Utils.js +18 -18
- package/umd/index.js +4 -28
- package/103.min.js +0 -2
- package/103.min.js.LICENSE.txt +0 -1
- package/388.min.js +0 -2
- package/388.min.js.LICENSE.txt +0 -1
- package/53.min.js +0 -2
- package/53.min.js.LICENSE.txt +0 -1
- package/569.min.js +0 -2
- package/569.min.js.LICENSE.txt +0 -1
- package/886.min.js +0 -2
- package/886.min.js.LICENSE.txt +0 -1
- package/920.min.js +0 -2
- package/920.min.js.LICENSE.txt +0 -1
- package/dist_browser_BounceOutMode_js.js +0 -30
- package/dist_browser_DestroyOutMode_js.js +0 -30
- package/dist_browser_NoneOutMode_js.js +0 -30
- package/dist_browser_OutOfCanvasUpdater_js.js +0 -30
- package/dist_browser_OutOutMode_js.js +0 -30
- package/dist_browser_Utils_js.js +0 -30
package/cjs/OutOutMode.js
CHANGED
|
@@ -6,15 +6,15 @@ const minVelocity = 0, minDistance = 0;
|
|
|
6
6
|
class OutOutMode {
|
|
7
7
|
constructor(container) {
|
|
8
8
|
this.container = container;
|
|
9
|
-
this.modes = [
|
|
9
|
+
this.modes = [engine_1.OutMode.out];
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
update(particle, direction, delta, outMode) {
|
|
12
12
|
if (!this.modes.includes(outMode)) {
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
const container = this.container;
|
|
16
16
|
switch (particle.outType) {
|
|
17
|
-
case
|
|
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
|
|
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
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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;
|
|
@@ -110,7 +110,6 @@ class OutOutMode {
|
|
|
110
110
|
break;
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
|
-
await Promise.resolve();
|
|
114
113
|
}
|
|
115
114
|
}
|
|
116
115
|
exports.OutOutMode = OutOutMode;
|
package/cjs/Utils.js
CHANGED
|
@@ -4,22 +4,22 @@ exports.bounceVertical = exports.bounceHorizontal = void 0;
|
|
|
4
4
|
const engine_1 = require("@tsparticles/engine");
|
|
5
5
|
const minVelocity = 0, boundsMin = 0;
|
|
6
6
|
function bounceHorizontal(data) {
|
|
7
|
-
if ((data.outMode !==
|
|
8
|
-
(data.direction !==
|
|
7
|
+
if ((data.outMode !== engine_1.OutMode.bounce && data.outMode !== engine_1.OutMode.split) ||
|
|
8
|
+
(data.direction !== engine_1.OutModeDirection.left && data.direction !== engine_1.OutModeDirection.right)) {
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
|
-
if (data.bounds.right < boundsMin && data.direction ===
|
|
11
|
+
if (data.bounds.right < boundsMin && data.direction === engine_1.OutModeDirection.left) {
|
|
12
12
|
data.particle.position.x = data.size + data.offset.x;
|
|
13
13
|
}
|
|
14
|
-
else if (data.bounds.left > data.canvasSize.width && data.direction ===
|
|
14
|
+
else if (data.bounds.left > data.canvasSize.width && data.direction === engine_1.OutModeDirection.right) {
|
|
15
15
|
data.particle.position.x = data.canvasSize.width - data.size - data.offset.x;
|
|
16
16
|
}
|
|
17
17
|
const velocity = data.particle.velocity.x;
|
|
18
18
|
let bounced = false;
|
|
19
|
-
if ((data.direction ===
|
|
19
|
+
if ((data.direction === engine_1.OutModeDirection.right &&
|
|
20
20
|
data.bounds.right >= data.canvasSize.width &&
|
|
21
21
|
velocity > minVelocity) ||
|
|
22
|
-
(data.direction ===
|
|
22
|
+
(data.direction === engine_1.OutModeDirection.left && data.bounds.left <= boundsMin && velocity < minVelocity)) {
|
|
23
23
|
const newVelocity = (0, engine_1.getRangeValue)(data.particle.options.bounce.horizontal.value);
|
|
24
24
|
data.particle.velocity.x *= -newVelocity;
|
|
25
25
|
bounced = true;
|
|
@@ -28,34 +28,34 @@ function bounceHorizontal(data) {
|
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
30
|
const minPos = data.offset.x + data.size;
|
|
31
|
-
if (data.bounds.right >= data.canvasSize.width && data.direction ===
|
|
31
|
+
if (data.bounds.right >= data.canvasSize.width && data.direction === engine_1.OutModeDirection.right) {
|
|
32
32
|
data.particle.position.x = data.canvasSize.width - minPos;
|
|
33
33
|
}
|
|
34
|
-
else if (data.bounds.left <= boundsMin && data.direction ===
|
|
34
|
+
else if (data.bounds.left <= boundsMin && data.direction === engine_1.OutModeDirection.left) {
|
|
35
35
|
data.particle.position.x = minPos;
|
|
36
36
|
}
|
|
37
|
-
if (data.outMode ===
|
|
37
|
+
if (data.outMode === engine_1.OutMode.split) {
|
|
38
38
|
data.particle.destroy();
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
exports.bounceHorizontal = bounceHorizontal;
|
|
42
42
|
function bounceVertical(data) {
|
|
43
|
-
if ((data.outMode !==
|
|
44
|
-
(data.direction !==
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
55
|
+
if ((data.direction === engine_1.OutModeDirection.bottom &&
|
|
56
56
|
data.bounds.bottom >= data.canvasSize.height &&
|
|
57
57
|
velocity > minVelocity) ||
|
|
58
|
-
(data.direction ===
|
|
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,13 +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 ===
|
|
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 ===
|
|
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 ===
|
|
73
|
+
if (data.outMode === engine_1.OutMode.split) {
|
|
74
74
|
data.particle.destroy();
|
|
75
75
|
}
|
|
76
76
|
}
|
package/cjs/index.js
CHANGED
|
@@ -1,33 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.loadOutModesUpdater = void 0;
|
|
4
|
+
const OutOfCanvasUpdater_js_1 = require("./OutOfCanvasUpdater.js");
|
|
27
5
|
async function loadOutModesUpdater(engine, refresh = true) {
|
|
28
|
-
await engine.addParticleUpdater("outModes",
|
|
29
|
-
|
|
30
|
-
return new OutOfCanvasUpdater(container);
|
|
6
|
+
await engine.addParticleUpdater("outModes", container => {
|
|
7
|
+
return Promise.resolve(new OutOfCanvasUpdater_js_1.OutOfCanvasUpdater(container));
|
|
31
8
|
}, refresh);
|
|
32
9
|
}
|
|
33
10
|
exports.loadOutModesUpdater = loadOutModesUpdater;
|
package/esm/BounceOutMode.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { calculateBounds, } from "@tsparticles/engine";
|
|
1
|
+
import { OutMode, calculateBounds, } from "@tsparticles/engine";
|
|
2
|
+
import { bounceHorizontal, bounceVertical } from "./Utils.js";
|
|
2
3
|
export class BounceOutMode {
|
|
3
4
|
constructor(container) {
|
|
4
5
|
this.container = container;
|
|
5
6
|
this.modes = [
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
OutMode.bounce,
|
|
8
|
+
OutMode.split,
|
|
8
9
|
];
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
+
update(particle, direction, delta, outMode) {
|
|
11
12
|
if (!this.modes.includes(outMode)) {
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
@@ -15,7 +16,7 @@ export class BounceOutMode {
|
|
|
15
16
|
let handled = false;
|
|
16
17
|
for (const [, plugin] of container.plugins) {
|
|
17
18
|
if (plugin.particleBounce !== undefined) {
|
|
18
|
-
handled =
|
|
19
|
+
handled = plugin.particleBounce(particle, delta, direction);
|
|
19
20
|
}
|
|
20
21
|
if (handled) {
|
|
21
22
|
break;
|
|
@@ -24,7 +25,7 @@ export class BounceOutMode {
|
|
|
24
25
|
if (handled) {
|
|
25
26
|
return;
|
|
26
27
|
}
|
|
27
|
-
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size
|
|
28
|
+
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size;
|
|
28
29
|
bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
29
30
|
bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
30
31
|
}
|
package/esm/DestroyOutMode.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
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 = [
|
|
6
|
+
this.modes = [OutMode.destroy];
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
update(particle, direction, _delta, outMode) {
|
|
9
9
|
if (!this.modes.includes(outMode)) {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
12
|
const container = this.container;
|
|
13
13
|
switch (particle.outType) {
|
|
14
|
-
case
|
|
15
|
-
case
|
|
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
|
|
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) ||
|
|
@@ -29,6 +29,5 @@ export class DestroyOutMode {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
container.particles.remove(particle, undefined, true);
|
|
32
|
-
await Promise.resolve();
|
|
33
32
|
}
|
|
34
33
|
}
|
package/esm/NoneOutMode.js
CHANGED
|
@@ -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 = [
|
|
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 ===
|
|
13
|
+
(direction === OutModeDirection.left || direction === OutModeDirection.right)) ??
|
|
14
14
|
(particle.options.move.distance.vertical &&
|
|
15
|
-
(direction ===
|
|
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,11 +31,10 @@ export class NoneOutMode {
|
|
|
31
31
|
const position = particle.position;
|
|
32
32
|
if ((!gravityOptions.inverse &&
|
|
33
33
|
position.y > canvasSize.height + pRadius &&
|
|
34
|
-
direction ===
|
|
35
|
-
(gravityOptions.inverse && position.y < -pRadius && direction ===
|
|
34
|
+
direction === OutModeDirection.bottom) ||
|
|
35
|
+
(gravityOptions.inverse && position.y < -pRadius && direction === OutModeDirection.top)) {
|
|
36
36
|
container.particles.remove(particle);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
await Promise.resolve();
|
|
40
39
|
}
|
|
41
40
|
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import { OutMode, OutModeDirection, } from "@tsparticles/engine";
|
|
2
|
+
import { BounceOutMode } from "./BounceOutMode.js";
|
|
3
|
+
import { DestroyOutMode } from "./DestroyOutMode.js";
|
|
4
|
+
import { NoneOutMode } from "./NoneOutMode.js";
|
|
5
|
+
import { OutOutMode } from "./OutOutMode.js";
|
|
1
6
|
const checkOutMode = (outModes, outMode) => {
|
|
2
7
|
return (outModes.default === outMode ||
|
|
3
8
|
outModes.bottom === outMode ||
|
|
@@ -7,42 +12,38 @@ const checkOutMode = (outModes, outMode) => {
|
|
|
7
12
|
};
|
|
8
13
|
export class OutOfCanvasUpdater {
|
|
9
14
|
constructor(container) {
|
|
10
|
-
this._updateOutMode =
|
|
15
|
+
this._updateOutMode = (particle, delta, outMode, direction) => {
|
|
11
16
|
for (const updater of this.updaters) {
|
|
12
|
-
|
|
17
|
+
updater.update(particle, direction, delta, outMode);
|
|
13
18
|
}
|
|
14
19
|
};
|
|
15
20
|
this.container = container;
|
|
16
21
|
this.updaters = [];
|
|
17
22
|
}
|
|
18
|
-
|
|
23
|
+
init(particle) {
|
|
19
24
|
this.updaters = [];
|
|
20
25
|
const outModes = particle.options.move.outModes;
|
|
21
|
-
if (checkOutMode(outModes,
|
|
22
|
-
const { BounceOutMode } = await import("./BounceOutMode.js");
|
|
26
|
+
if (checkOutMode(outModes, OutMode.bounce)) {
|
|
23
27
|
this.updaters.push(new BounceOutMode(this.container));
|
|
24
28
|
}
|
|
25
|
-
else if (checkOutMode(outModes,
|
|
26
|
-
const { OutOutMode } = await import("./OutOutMode.js");
|
|
29
|
+
else if (checkOutMode(outModes, OutMode.out)) {
|
|
27
30
|
this.updaters.push(new OutOutMode(this.container));
|
|
28
31
|
}
|
|
29
|
-
else if (checkOutMode(outModes,
|
|
30
|
-
const { DestroyOutMode } = await import("./DestroyOutMode.js");
|
|
32
|
+
else if (checkOutMode(outModes, OutMode.destroy)) {
|
|
31
33
|
this.updaters.push(new DestroyOutMode(this.container));
|
|
32
34
|
}
|
|
33
|
-
else if (checkOutMode(outModes,
|
|
34
|
-
const { NoneOutMode } = await import("./NoneOutMode.js");
|
|
35
|
+
else if (checkOutMode(outModes, OutMode.none)) {
|
|
35
36
|
this.updaters.push(new NoneOutMode(this.container));
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
isEnabled(particle) {
|
|
39
40
|
return !particle.destroyed && !particle.spawning;
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
+
update(particle, delta) {
|
|
42
43
|
const outModes = particle.options.move.outModes;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
}
|
package/esm/OutOutMode.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
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 = [
|
|
6
|
+
this.modes = [OutMode.out];
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
update(particle, direction, delta, outMode) {
|
|
9
9
|
if (!this.modes.includes(outMode)) {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
12
|
const container = this.container;
|
|
13
13
|
switch (particle.outType) {
|
|
14
|
-
case
|
|
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
|
|
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
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
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;
|
|
@@ -107,6 +107,5 @@ export class OutOutMode {
|
|
|
107
107
|
break;
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
await Promise.resolve();
|
|
111
110
|
}
|
|
112
111
|
}
|
package/esm/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 !==
|
|
5
|
-
(data.direction !==
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
16
|
+
if ((data.direction === OutModeDirection.right &&
|
|
17
17
|
data.bounds.right >= data.canvasSize.width &&
|
|
18
18
|
velocity > minVelocity) ||
|
|
19
|
-
(data.direction ===
|
|
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 ===
|
|
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 ===
|
|
31
|
+
else if (data.bounds.left <= boundsMin && data.direction === OutModeDirection.left) {
|
|
32
32
|
data.particle.position.x = minPos;
|
|
33
33
|
}
|
|
34
|
-
if (data.outMode ===
|
|
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 !==
|
|
40
|
-
(data.direction !==
|
|
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 ===
|
|
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 ===
|
|
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 ===
|
|
51
|
+
if ((data.direction === OutModeDirection.bottom &&
|
|
52
52
|
data.bounds.bottom >= data.canvasSize.height &&
|
|
53
53
|
velocity > minVelocity) ||
|
|
54
|
-
(data.direction ===
|
|
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 ===
|
|
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 ===
|
|
66
|
+
else if (data.bounds.top <= boundsMin && data.direction === OutModeDirection.top) {
|
|
67
67
|
data.particle.position.y = minPos;
|
|
68
68
|
}
|
|
69
|
-
if (data.outMode ===
|
|
69
|
+
if (data.outMode === OutMode.split) {
|
|
70
70
|
data.particle.destroy();
|
|
71
71
|
}
|
|
72
72
|
}
|
package/esm/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",
|
|
3
|
-
|
|
4
|
-
return new OutOfCanvasUpdater(container);
|
|
3
|
+
await engine.addParticleUpdater("outModes", container => {
|
|
4
|
+
return Promise.resolve(new OutOfCanvasUpdater(container));
|
|
5
5
|
}, refresh);
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/updater-out-modes",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "tsParticles particles out modes updater",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"./package.json": "./package.json"
|
|
88
88
|
},
|
|
89
89
|
"dependencies": {
|
|
90
|
-
"@tsparticles/engine": "^3.
|
|
90
|
+
"@tsparticles/engine": "^3.4.0"
|
|
91
91
|
},
|
|
92
92
|
"publishConfig": {
|
|
93
93
|
"access": "public"
|
package/report.html
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8"/>
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
6
|
-
<title>@tsparticles/updater-out-modes [
|
|
6
|
+
<title>@tsparticles/updater-out-modes [13 May 2024 at 00:14]</title>
|
|
7
7
|
<link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAABrVBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+O1foceMD///+J0/qK1Pr7/v8Xdr/9///W8P4UdL7L7P0Scr2r4Pyj3vwad8D5/f/2/f+55f3E6f34+/2H0/ojfMKpzOd0rNgQcb3F3O/j9f7c8v6g3Pz0/P/w+v/q+P7n9v6T1/uQ1vuE0vqLut/y+v+Z2fvt+f+15Pzv9fuc2/vR7v2V2Pvd6/bg9P7I6/285/2y4/yp3/zp8vk8i8kqgMT7/P31+fyv4vxGkcz6/P6/6P3j7vfS5PNnpNUxhcbO7f7F6v3O4vHK3/DA2u631Ouy0eqXweKJud5wqthfoNMMbLvY8f73+v2dxeR8sNtTmdDx9/zX6PSjyeaCtd1YnNGX2PuQveCGt95Nls42h8dLlM3F4vBtAAAAM3RSTlMAAyOx0/sKBvik8opWGBMOAe3l1snDm2E9LSb06eHcu5JpHbarfHZCN9CBb08zzkdNS0kYaptYAAAFV0lEQVRYw92X51/aYBDHHS2O2qqttVbrqNq9m+TJIAYIShBkWwqIiCgoWvfeq7Z2/s29hyQNyUcR7LveGwVyXy6XH8/9rqxglLfUPLxVduUor3h0rfp2TYvpivk37929TkG037hffoX0+peVtZQc1589rigVUdXS/ABSAyEmGIO/1XfvldSK8vs3OqB6u3m0nxmIrvgB0dj7rr7Y9IbuF68hnfFaiHA/sxqm0wciIG43P60qKv9WXWc1RXGh/mFESFABTSBi0sNAKzqet17eCtOb3kZIDwxEEU0oAIJGYxNBDhBND29e0rtXXbcpuPmED9IhEAAQ/AXEaF8EPmnrrKsv0LvWR3fg5sWDNAFZOgAgaKvZDogHNU9MFwnnYROkc56RD5CjAbQX9Ow4g7upCsvYu55aSI/Nj0H1akgKQEUM94dwK65hYRmFU9MIcH/fqJYOZYcnuJSU/waKDgTOEVaVKhwrTRP5XzgSpAITYzom7UvkhFX5VutmxeNnWDjjswTKTyfgluNDGbUpWissXhF3s7mlSml+czWkg3D0l1nNjGNjz3myOQOa1KM/jOS6ebdbAVTCi4gljHSFrviza7tOgRWcS0MOUX9zdNgag5w7rRqA44Lzw0hr1WqES36dFliSJFlh2rXIae3FFcDDgKdxrUIDePr8jGcSClV1u7A9xeN0ModY/pHMxmR1EzRh8TJiwqsHmKW0l4FCEZI+jHio+JdPPE9qwQtTRxku2D8sIeRL2LnxWSllANCQGOIiqVHAz2ye2JR0DcH+HoxDkaADLjgxjKQ+AwCX/g0+DNgdG0ukYCONAe+dbc2IAc6fwt1ARoDSezNHxV2Cmzwv3O6lDMV55edBGwGK9n1+x2F8EDfAGCxug8MhpsMEcTEAWf3rx2vZhe/LAmtIn/6apE6PN0ULKgywD9mmdxbmFl3OvD5AS5fW5zLbv/YHmcsBTjf/afDz3MaZTVCfAP9z6/Bw6ycv8EUBWJIn9zYcoAWWlW9+OzO3vkTy8H+RANLmdrpOuYWdZYEXpo+TlCJrW5EARb7fF+bWdqf3hhyZI1nWJQHgznErZhbjoEsWqi8dQNoE294aldzFurwSABL2XXMf9+H1VQGke9exw5P/AnA5Pv5ngMul7LOvO922iwACu8WkCwLCafvM4CeWPxfA8lNHcWZSoi8EwMAIciKX2Z4SWCMAa3snCZ/G4EA8D6CMLNFsGQhkkz/gQNEBbPCbWsxGUpYVu3z8IyNAknwJkfPMEhLyrdi5RTyUVACkw4GSFRNWJNEW+fgPGwHD8/JxnRuLabN4CGNRkAE23na2+VmEAUmrYymSGjMAYqH84YUIyzgzs3XC7gNgH36Vcc4zKY9o9fgPBXUAiHHwVboBHGLiX6Zcjp1f2wu4tvzZKo0ecPnDtQYDQvJXaBeNzce45Fp28ZQLrEZVuFqgBwOalArKXnW1UzlnSusQKJqKYNuz4tOnI6sZG4zanpemv+7ySU2jbA9h6uhcgpfy6G2PahirDZ6zvq6zDduMVFTKvzw8wgyEdelwY9in3XkEPs3osJuwRQ4qTkfzifndg9Gfc4pdsu82+tTnHZTBa2EAMrqr2t43pguc8tNm7JQVQ2S0ukj2d22dhXYP0/veWtwKrCkNoNimAN5+Xr/oLrxswKbVJjteWrX7eR63o4j9q0GxnaBdWgGA5VStpanIjQmEhV0/nVt5VOFUvix6awJhPcAaTEShgrG+iGyvb5a0Ndb1YGHFPEwoqAinoaykaID1o1pdPNu7XsnCKQ3R+hwWIIhGvORcJUBYXe3Xa3vq/mF/N9V13ugufMkfXn+KHsRD0B8AAAAASUVORK5CYII=" type="image/x-icon" />
|
|
8
8
|
|
|
9
9
|
<script>
|