@tsparticles/move-base 3.0.3 → 3.2.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/103.min.js +2 -0
- package/103.min.js.LICENSE.txt +1 -0
- package/460.min.js +2 -0
- package/460.min.js.LICENSE.txt +1 -0
- package/browser/BaseMover.js +15 -29
- package/browser/Utils.js +50 -26
- package/browser/index.js +4 -2
- package/cjs/BaseMover.js +39 -30
- package/cjs/Utils.js +51 -26
- package/cjs/index.js +27 -2
- package/dist_browser_BaseMover_js.js +30 -0
- package/dist_browser_Utils_js.js +30 -0
- package/esm/BaseMover.js +15 -29
- package/esm/Utils.js +50 -26
- package/esm/index.js +4 -2
- package/package.json +2 -2
- package/report.html +3 -3
- package/tsparticles.move.base.js +241 -211
- package/tsparticles.move.base.min.js +1 -1
- package/tsparticles.move.base.min.js.LICENSE.txt +1 -1
- package/types/BaseMover.d.ts +2 -3
- package/types/Utils.d.ts +3 -2
- package/umd/BaseMover.js +41 -31
- package/umd/Utils.js +51 -26
- package/umd/index.js +29 -3
package/esm/BaseMover.js
CHANGED
|
@@ -1,52 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
const diffFactor = 2;
|
|
1
|
+
import { getRangeMax, getRangeValue } from "@tsparticles/engine";
|
|
2
|
+
const diffFactor = 2, defaultSizeFactor = 1, defaultDeltaFactor = 1;
|
|
4
3
|
export class BaseMover {
|
|
5
|
-
|
|
6
|
-
this._initSpin = (particle) => {
|
|
7
|
-
const container = particle.container, options = particle.options, spinOptions = options.move.spin;
|
|
8
|
-
if (!spinOptions.enable) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
const spinPos = spinOptions.position ?? { x: 50, y: 50 }, spinCenter = {
|
|
12
|
-
x: spinPos.x * 0.01 * container.canvas.size.width,
|
|
13
|
-
y: spinPos.y * 0.01 * container.canvas.size.height,
|
|
14
|
-
}, pos = particle.getPosition(), distance = getDistance(pos, spinCenter), spinAcceleration = getRangeValue(spinOptions.acceleration);
|
|
15
|
-
particle.retina.spinAcceleration = spinAcceleration * container.retina.pixelRatio;
|
|
16
|
-
particle.spin = {
|
|
17
|
-
center: spinCenter,
|
|
18
|
-
direction: particle.velocity.x >= 0 ? "clockwise" : "counter-clockwise",
|
|
19
|
-
angle: particle.velocity.angle,
|
|
20
|
-
radius: distance,
|
|
21
|
-
acceleration: particle.retina.spinAcceleration,
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
init(particle) {
|
|
4
|
+
async init(particle) {
|
|
26
5
|
const options = particle.options, gravityOptions = options.move.gravity;
|
|
27
6
|
particle.gravity = {
|
|
28
7
|
enable: gravityOptions.enable,
|
|
29
8
|
acceleration: getRangeValue(gravityOptions.acceleration),
|
|
30
9
|
inverse: gravityOptions.inverse,
|
|
31
10
|
};
|
|
32
|
-
|
|
11
|
+
const { initSpin } = await import("./Utils.js");
|
|
12
|
+
initSpin(particle);
|
|
13
|
+
await Promise.resolve();
|
|
33
14
|
}
|
|
34
15
|
isEnabled(particle) {
|
|
35
16
|
return !particle.destroyed && particle.options.move.enable;
|
|
36
17
|
}
|
|
37
|
-
move(particle, delta) {
|
|
18
|
+
async move(particle, delta) {
|
|
38
19
|
const particleOptions = particle.options, moveOptions = particleOptions.move;
|
|
39
20
|
if (!moveOptions.enable) {
|
|
40
21
|
return;
|
|
41
22
|
}
|
|
42
|
-
const container = particle.container, pxRatio = container.retina.pixelRatio
|
|
43
|
-
|
|
23
|
+
const container = particle.container, pxRatio = container.retina.pixelRatio;
|
|
24
|
+
particle.retina.moveSpeed ??= getRangeValue(moveOptions.speed) * pxRatio;
|
|
25
|
+
particle.retina.moveDrift ??= getRangeValue(particle.options.move.drift) * pxRatio;
|
|
26
|
+
const { getProximitySpeedFactor } = await import("./Utils.js"), slowFactor = getProximitySpeedFactor(particle), baseSpeed = particle.retina.moveSpeed * container.retina.reduceFactor, moveDrift = particle.retina.moveDrift, maxSize = getRangeMax(particleOptions.size.value) * pxRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : defaultSizeFactor, deltaFactor = delta.factor || defaultDeltaFactor, moveSpeed = (baseSpeed * sizeFactor * slowFactor * deltaFactor) / diffFactor, maxSpeed = particle.retina.maxSpeed ?? container.retina.maxSpeed;
|
|
44
27
|
if (moveOptions.spin.enable) {
|
|
28
|
+
const { spin } = await import("./Utils.js");
|
|
45
29
|
spin(particle, moveSpeed);
|
|
46
30
|
}
|
|
47
31
|
else {
|
|
48
|
-
move
|
|
32
|
+
const { move } = await import("./Utils.js");
|
|
33
|
+
await move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta);
|
|
49
34
|
}
|
|
35
|
+
const { applyDistance } = await import("./Utils.js");
|
|
50
36
|
applyDistance(particle);
|
|
51
37
|
}
|
|
52
38
|
}
|
package/esm/Utils.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { clamp, getDistances, getRandom, } from "@tsparticles/engine";
|
|
1
|
+
import { clamp, getDistance, getDistances, getRandom, getRangeValue, } from "@tsparticles/engine";
|
|
2
|
+
const half = 0.5, minVelocity = 0, identity = 1, moveSpeedFactor = 60, minSpinRadius = 0, spinFactor = 0.01;
|
|
2
3
|
export function applyDistance(particle) {
|
|
3
4
|
const initialPosition = particle.initialPosition, { dx, dy } = getDistances(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), { maxDistance } = particle.retina, hDistance = maxDistance.horizontal, vDistance = maxDistance.vertical;
|
|
4
5
|
if (!hDistance && !vDistance) {
|
|
5
6
|
return;
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
+
const hasHDistance = (hDistance && dxFixed >= hDistance) ?? false, hasVDistance = (vDistance && dyFixed >= vDistance) ?? false;
|
|
9
|
+
if ((hasHDistance || hasVDistance) && !particle.misplaced) {
|
|
8
10
|
particle.misplaced = (!!hDistance && dxFixed > hDistance) || (!!vDistance && dyFixed > vDistance);
|
|
9
11
|
if (hDistance) {
|
|
10
|
-
particle.velocity.x = particle.velocity.y *
|
|
12
|
+
particle.velocity.x = particle.velocity.y * half - particle.velocity.x;
|
|
11
13
|
}
|
|
12
14
|
if (vDistance) {
|
|
13
|
-
particle.velocity.y = particle.velocity.x *
|
|
15
|
+
particle.velocity.y = particle.velocity.x * half - particle.velocity.y;
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
18
|
else if ((!hDistance || dxFixed < hDistance) && (!vDistance || dyFixed < vDistance) && particle.misplaced) {
|
|
@@ -18,36 +20,39 @@ export function applyDistance(particle) {
|
|
|
18
20
|
}
|
|
19
21
|
else if (particle.misplaced) {
|
|
20
22
|
const pos = particle.position, vel = particle.velocity;
|
|
21
|
-
if (hDistance &&
|
|
23
|
+
if (hDistance &&
|
|
24
|
+
((pos.x < initialPosition.x && vel.x < minVelocity) || (pos.x > initialPosition.x && vel.x > minVelocity))) {
|
|
22
25
|
vel.x *= -getRandom();
|
|
23
26
|
}
|
|
24
|
-
if (vDistance &&
|
|
27
|
+
if (vDistance &&
|
|
28
|
+
((pos.y < initialPosition.y && vel.y < minVelocity) || (pos.y > initialPosition.y && vel.y > minVelocity))) {
|
|
25
29
|
vel.y *= -getRandom();
|
|
26
30
|
}
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
|
-
export function move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta) {
|
|
30
|
-
applyPath(particle, delta);
|
|
31
|
-
const gravityOptions = particle.gravity, gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -
|
|
33
|
+
export async function move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta) {
|
|
34
|
+
await applyPath(particle, delta);
|
|
35
|
+
const gravityOptions = particle.gravity, gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -identity : identity;
|
|
32
36
|
if (moveDrift && moveSpeed) {
|
|
33
|
-
particle.velocity.x += (moveDrift * delta.factor) / (
|
|
37
|
+
particle.velocity.x += (moveDrift * delta.factor) / (moveSpeedFactor * moveSpeed);
|
|
34
38
|
}
|
|
35
39
|
if (gravityOptions?.enable && moveSpeed) {
|
|
36
|
-
particle.velocity.y +=
|
|
40
|
+
particle.velocity.y +=
|
|
41
|
+
(gravityFactor * (gravityOptions.acceleration * delta.factor)) / (moveSpeedFactor * moveSpeed);
|
|
37
42
|
}
|
|
38
43
|
const decay = particle.moveDecay;
|
|
39
44
|
particle.velocity.multTo(decay);
|
|
40
45
|
const velocity = particle.velocity.mult(moveSpeed);
|
|
41
46
|
if (gravityOptions?.enable &&
|
|
42
|
-
maxSpeed >
|
|
43
|
-
((!gravityOptions.inverse && velocity.y >=
|
|
44
|
-
(gravityOptions.inverse && velocity.y <=
|
|
47
|
+
maxSpeed > minVelocity &&
|
|
48
|
+
((!gravityOptions.inverse && velocity.y >= minVelocity && velocity.y >= maxSpeed) ||
|
|
49
|
+
(gravityOptions.inverse && velocity.y <= minVelocity && velocity.y <= -maxSpeed))) {
|
|
45
50
|
velocity.y = gravityFactor * maxSpeed;
|
|
46
51
|
if (moveSpeed) {
|
|
47
52
|
particle.velocity.y = velocity.y / moveSpeed;
|
|
48
53
|
}
|
|
49
54
|
}
|
|
50
|
-
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (
|
|
55
|
+
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (identity - particle.zIndexFactor) ** zIndexOptions.velocityRate;
|
|
51
56
|
velocity.multTo(zVelocityFactor);
|
|
52
57
|
const { position } = particle;
|
|
53
58
|
position.addTo(velocity);
|
|
@@ -68,18 +73,18 @@ export function spin(particle, moveSpeed) {
|
|
|
68
73
|
particle.position.x = particle.spin.center.x + particle.spin.radius * updateFunc.x(particle.spin.angle);
|
|
69
74
|
particle.position.y = particle.spin.center.y + particle.spin.radius * updateFunc.y(particle.spin.angle);
|
|
70
75
|
particle.spin.radius += particle.spin.acceleration;
|
|
71
|
-
const maxCanvasSize = Math.max(container.canvas.size.width, container.canvas.size.height), halfMaxSize = maxCanvasSize *
|
|
76
|
+
const maxCanvasSize = Math.max(container.canvas.size.width, container.canvas.size.height), halfMaxSize = maxCanvasSize * half;
|
|
72
77
|
if (particle.spin.radius > halfMaxSize) {
|
|
73
78
|
particle.spin.radius = halfMaxSize;
|
|
74
|
-
particle.spin.acceleration *= -
|
|
79
|
+
particle.spin.acceleration *= -identity;
|
|
75
80
|
}
|
|
76
|
-
else if (particle.spin.radius <
|
|
77
|
-
particle.spin.radius =
|
|
78
|
-
particle.spin.acceleration *= -
|
|
81
|
+
else if (particle.spin.radius < minSpinRadius) {
|
|
82
|
+
particle.spin.radius = minSpinRadius;
|
|
83
|
+
particle.spin.acceleration *= -identity;
|
|
79
84
|
}
|
|
80
|
-
particle.spin.angle += moveSpeed *
|
|
85
|
+
particle.spin.angle += moveSpeed * spinFactor * (identity - particle.spin.radius / maxCanvasSize);
|
|
81
86
|
}
|
|
82
|
-
export function applyPath(particle, delta) {
|
|
87
|
+
export async function applyPath(particle, delta) {
|
|
83
88
|
const particlesOptions = particle.options, pathOptions = particlesOptions.move.path, pathEnabled = pathOptions.enable;
|
|
84
89
|
if (!pathEnabled) {
|
|
85
90
|
return;
|
|
@@ -88,16 +93,35 @@ export function applyPath(particle, delta) {
|
|
|
88
93
|
particle.lastPathTime += delta.value;
|
|
89
94
|
return;
|
|
90
95
|
}
|
|
91
|
-
const path = particle.pathGenerator?.generate(particle, delta);
|
|
96
|
+
const path = await particle.pathGenerator?.generate(particle, delta);
|
|
92
97
|
if (path) {
|
|
93
98
|
particle.velocity.addTo(path);
|
|
94
99
|
}
|
|
95
100
|
if (pathOptions.clamp) {
|
|
96
|
-
particle.velocity.x = clamp(particle.velocity.x, -
|
|
97
|
-
particle.velocity.y = clamp(particle.velocity.y, -
|
|
101
|
+
particle.velocity.x = clamp(particle.velocity.x, -identity, identity);
|
|
102
|
+
particle.velocity.y = clamp(particle.velocity.y, -identity, identity);
|
|
98
103
|
}
|
|
99
104
|
particle.lastPathTime -= particle.pathDelay;
|
|
100
105
|
}
|
|
101
106
|
export function getProximitySpeedFactor(particle) {
|
|
102
|
-
return particle.slow.inRange ? particle.slow.factor :
|
|
107
|
+
return particle.slow.inRange ? particle.slow.factor : identity;
|
|
108
|
+
}
|
|
109
|
+
export function initSpin(particle) {
|
|
110
|
+
const container = particle.container, options = particle.options, spinOptions = options.move.spin;
|
|
111
|
+
if (!spinOptions.enable) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const spinPos = spinOptions.position ?? { x: 50, y: 50 }, spinFactor = 0.01, spinCenter = {
|
|
115
|
+
x: spinPos.x * spinFactor * container.canvas.size.width,
|
|
116
|
+
y: spinPos.y * spinFactor * container.canvas.size.height,
|
|
117
|
+
}, pos = particle.getPosition(), distance = getDistance(pos, spinCenter), spinAcceleration = getRangeValue(spinOptions.acceleration);
|
|
118
|
+
particle.retina.spinAcceleration = spinAcceleration * container.retina.pixelRatio;
|
|
119
|
+
const minVelocity = 0;
|
|
120
|
+
particle.spin = {
|
|
121
|
+
center: spinCenter,
|
|
122
|
+
direction: particle.velocity.x >= minVelocity ? "clockwise" : "counter-clockwise",
|
|
123
|
+
angle: particle.velocity.angle,
|
|
124
|
+
radius: distance,
|
|
125
|
+
acceleration: particle.retina.spinAcceleration,
|
|
126
|
+
};
|
|
103
127
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { BaseMover } from "./BaseMover.js";
|
|
2
1
|
export async function loadBaseMover(engine, refresh = true) {
|
|
3
|
-
await engine.addMover("base", () =>
|
|
2
|
+
await engine.addMover("base", async () => {
|
|
3
|
+
const { BaseMover } = await import("./BaseMover.js");
|
|
4
|
+
return new BaseMover();
|
|
5
|
+
}, refresh);
|
|
4
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/move-base",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "tsParticles Base movement",
|
|
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.0
|
|
90
|
+
"@tsparticles/engine": "^3.2.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/move-base [
|
|
6
|
+
<title>@tsparticles/move-base [31 Jan 2024 at 02:05]</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+TJIAYIShBkWwqIiC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kCwLCafvM4CeWPxfA8lNHcWZSoi8EwMAIciKX2Z4SWCMAa3snCZ/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>
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
<body>
|
|
32
32
|
<div id="app"></div>
|
|
33
33
|
<script>
|
|
34
|
-
window.chartData = [
|
|
35
|
-
window.entrypoints = ["tsparticles.move.base
|
|
34
|
+
window.chartData = [];
|
|
35
|
+
window.entrypoints = ["tsparticles.move.base.min"];
|
|
36
36
|
window.defaultSizes = "parsed";
|
|
37
37
|
</script>
|
|
38
38
|
</body>
|