@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/umd/BaseMover.js
CHANGED
|
@@ -1,65 +1,75 @@
|
|
|
1
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
|
+
if (k2 === undefined) k2 = k;
|
|
3
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(o, k2, desc);
|
|
8
|
+
}) : (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
o[k2] = m[k];
|
|
11
|
+
}));
|
|
12
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
13
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
14
|
+
}) : function(o, v) {
|
|
15
|
+
o["default"] = v;
|
|
16
|
+
});
|
|
17
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
18
|
+
if (mod && mod.__esModule) return mod;
|
|
19
|
+
var result = {};
|
|
20
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
21
|
+
__setModuleDefault(result, mod);
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
1
24
|
(function (factory) {
|
|
2
25
|
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
26
|
var v = factory(require, exports);
|
|
4
27
|
if (v !== undefined) module.exports = v;
|
|
5
28
|
}
|
|
6
29
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "@tsparticles/engine"
|
|
30
|
+
define(["require", "exports", "@tsparticles/engine"], factory);
|
|
8
31
|
}
|
|
9
32
|
})(function (require, exports) {
|
|
10
33
|
"use strict";
|
|
34
|
+
var __syncRequire = typeof module === "object" && typeof module.exports === "object";
|
|
11
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
36
|
exports.BaseMover = void 0;
|
|
13
37
|
const engine_1 = require("@tsparticles/engine");
|
|
14
|
-
const
|
|
15
|
-
const diffFactor = 2;
|
|
38
|
+
const diffFactor = 2, defaultSizeFactor = 1, defaultDeltaFactor = 1;
|
|
16
39
|
class BaseMover {
|
|
17
|
-
|
|
18
|
-
this._initSpin = (particle) => {
|
|
19
|
-
const container = particle.container, options = particle.options, spinOptions = options.move.spin;
|
|
20
|
-
if (!spinOptions.enable) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const spinPos = spinOptions.position ?? { x: 50, y: 50 }, spinCenter = {
|
|
24
|
-
x: spinPos.x * 0.01 * container.canvas.size.width,
|
|
25
|
-
y: spinPos.y * 0.01 * container.canvas.size.height,
|
|
26
|
-
}, pos = particle.getPosition(), distance = (0, engine_1.getDistance)(pos, spinCenter), spinAcceleration = (0, engine_1.getRangeValue)(spinOptions.acceleration);
|
|
27
|
-
particle.retina.spinAcceleration = spinAcceleration * container.retina.pixelRatio;
|
|
28
|
-
particle.spin = {
|
|
29
|
-
center: spinCenter,
|
|
30
|
-
direction: particle.velocity.x >= 0 ? "clockwise" : "counter-clockwise",
|
|
31
|
-
angle: particle.velocity.angle,
|
|
32
|
-
radius: distance,
|
|
33
|
-
acceleration: particle.retina.spinAcceleration,
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
init(particle) {
|
|
40
|
+
async init(particle) {
|
|
38
41
|
const options = particle.options, gravityOptions = options.move.gravity;
|
|
39
42
|
particle.gravity = {
|
|
40
43
|
enable: gravityOptions.enable,
|
|
41
44
|
acceleration: (0, engine_1.getRangeValue)(gravityOptions.acceleration),
|
|
42
45
|
inverse: gravityOptions.inverse,
|
|
43
46
|
};
|
|
44
|
-
|
|
47
|
+
const { initSpin } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./Utils.js"))) : new Promise((resolve_1, reject_1) => { require(["./Utils.js"], resolve_1, reject_1); }).then(__importStar));
|
|
48
|
+
initSpin(particle);
|
|
49
|
+
await Promise.resolve();
|
|
45
50
|
}
|
|
46
51
|
isEnabled(particle) {
|
|
47
52
|
return !particle.destroyed && particle.options.move.enable;
|
|
48
53
|
}
|
|
49
|
-
move(particle, delta) {
|
|
54
|
+
async move(particle, delta) {
|
|
50
55
|
const particleOptions = particle.options, moveOptions = particleOptions.move;
|
|
51
56
|
if (!moveOptions.enable) {
|
|
52
57
|
return;
|
|
53
58
|
}
|
|
54
|
-
const container = particle.container, pxRatio = container.retina.pixelRatio
|
|
55
|
-
|
|
59
|
+
const container = particle.container, pxRatio = container.retina.pixelRatio;
|
|
60
|
+
particle.retina.moveSpeed ??= (0, engine_1.getRangeValue)(moveOptions.speed) * pxRatio;
|
|
61
|
+
particle.retina.moveDrift ??= (0, engine_1.getRangeValue)(particle.options.move.drift) * pxRatio;
|
|
62
|
+
const { getProximitySpeedFactor } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./Utils.js"))) : new Promise((resolve_2, reject_2) => { require(["./Utils.js"], resolve_2, reject_2); }).then(__importStar)), slowFactor = getProximitySpeedFactor(particle), baseSpeed = particle.retina.moveSpeed * container.retina.reduceFactor, moveDrift = particle.retina.moveDrift, maxSize = (0, engine_1.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;
|
|
56
63
|
if (moveOptions.spin.enable) {
|
|
57
|
-
(
|
|
64
|
+
const { spin } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./Utils.js"))) : new Promise((resolve_3, reject_3) => { require(["./Utils.js"], resolve_3, reject_3); }).then(__importStar));
|
|
65
|
+
spin(particle, moveSpeed);
|
|
58
66
|
}
|
|
59
67
|
else {
|
|
60
|
-
(
|
|
68
|
+
const { move } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./Utils.js"))) : new Promise((resolve_4, reject_4) => { require(["./Utils.js"], resolve_4, reject_4); }).then(__importStar));
|
|
69
|
+
await move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta);
|
|
61
70
|
}
|
|
62
|
-
(
|
|
71
|
+
const { applyDistance } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./Utils.js"))) : new Promise((resolve_5, reject_5) => { require(["./Utils.js"], resolve_5, reject_5); }).then(__importStar));
|
|
72
|
+
applyDistance(particle);
|
|
63
73
|
}
|
|
64
74
|
}
|
|
65
75
|
exports.BaseMover = BaseMover;
|
package/umd/Utils.js
CHANGED
|
@@ -9,20 +9,22 @@
|
|
|
9
9
|
})(function (require, exports) {
|
|
10
10
|
"use strict";
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getProximitySpeedFactor = exports.applyPath = exports.spin = exports.move = exports.applyDistance = void 0;
|
|
12
|
+
exports.initSpin = exports.getProximitySpeedFactor = exports.applyPath = exports.spin = exports.move = exports.applyDistance = void 0;
|
|
13
13
|
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
const half = 0.5, minVelocity = 0, identity = 1, moveSpeedFactor = 60, minSpinRadius = 0, spinFactor = 0.01;
|
|
14
15
|
function applyDistance(particle) {
|
|
15
16
|
const initialPosition = particle.initialPosition, { dx, dy } = (0, engine_1.getDistances)(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), { maxDistance } = particle.retina, hDistance = maxDistance.horizontal, vDistance = maxDistance.vertical;
|
|
16
17
|
if (!hDistance && !vDistance) {
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
+
const hasHDistance = (hDistance && dxFixed >= hDistance) ?? false, hasVDistance = (vDistance && dyFixed >= vDistance) ?? false;
|
|
21
|
+
if ((hasHDistance || hasVDistance) && !particle.misplaced) {
|
|
20
22
|
particle.misplaced = (!!hDistance && dxFixed > hDistance) || (!!vDistance && dyFixed > vDistance);
|
|
21
23
|
if (hDistance) {
|
|
22
|
-
particle.velocity.x = particle.velocity.y *
|
|
24
|
+
particle.velocity.x = particle.velocity.y * half - particle.velocity.x;
|
|
23
25
|
}
|
|
24
26
|
if (vDistance) {
|
|
25
|
-
particle.velocity.y = particle.velocity.x *
|
|
27
|
+
particle.velocity.y = particle.velocity.x * half - particle.velocity.y;
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
else if ((!hDistance || dxFixed < hDistance) && (!vDistance || dyFixed < vDistance) && particle.misplaced) {
|
|
@@ -30,37 +32,40 @@
|
|
|
30
32
|
}
|
|
31
33
|
else if (particle.misplaced) {
|
|
32
34
|
const pos = particle.position, vel = particle.velocity;
|
|
33
|
-
if (hDistance &&
|
|
35
|
+
if (hDistance &&
|
|
36
|
+
((pos.x < initialPosition.x && vel.x < minVelocity) || (pos.x > initialPosition.x && vel.x > minVelocity))) {
|
|
34
37
|
vel.x *= -(0, engine_1.getRandom)();
|
|
35
38
|
}
|
|
36
|
-
if (vDistance &&
|
|
39
|
+
if (vDistance &&
|
|
40
|
+
((pos.y < initialPosition.y && vel.y < minVelocity) || (pos.y > initialPosition.y && vel.y > minVelocity))) {
|
|
37
41
|
vel.y *= -(0, engine_1.getRandom)();
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
}
|
|
41
45
|
exports.applyDistance = applyDistance;
|
|
42
|
-
function move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta) {
|
|
43
|
-
applyPath(particle, delta);
|
|
44
|
-
const gravityOptions = particle.gravity, gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -
|
|
46
|
+
async function move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta) {
|
|
47
|
+
await applyPath(particle, delta);
|
|
48
|
+
const gravityOptions = particle.gravity, gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -identity : identity;
|
|
45
49
|
if (moveDrift && moveSpeed) {
|
|
46
|
-
particle.velocity.x += (moveDrift * delta.factor) / (
|
|
50
|
+
particle.velocity.x += (moveDrift * delta.factor) / (moveSpeedFactor * moveSpeed);
|
|
47
51
|
}
|
|
48
52
|
if (gravityOptions?.enable && moveSpeed) {
|
|
49
|
-
particle.velocity.y +=
|
|
53
|
+
particle.velocity.y +=
|
|
54
|
+
(gravityFactor * (gravityOptions.acceleration * delta.factor)) / (moveSpeedFactor * moveSpeed);
|
|
50
55
|
}
|
|
51
56
|
const decay = particle.moveDecay;
|
|
52
57
|
particle.velocity.multTo(decay);
|
|
53
58
|
const velocity = particle.velocity.mult(moveSpeed);
|
|
54
59
|
if (gravityOptions?.enable &&
|
|
55
|
-
maxSpeed >
|
|
56
|
-
((!gravityOptions.inverse && velocity.y >=
|
|
57
|
-
(gravityOptions.inverse && velocity.y <=
|
|
60
|
+
maxSpeed > minVelocity &&
|
|
61
|
+
((!gravityOptions.inverse && velocity.y >= minVelocity && velocity.y >= maxSpeed) ||
|
|
62
|
+
(gravityOptions.inverse && velocity.y <= minVelocity && velocity.y <= -maxSpeed))) {
|
|
58
63
|
velocity.y = gravityFactor * maxSpeed;
|
|
59
64
|
if (moveSpeed) {
|
|
60
65
|
particle.velocity.y = velocity.y / moveSpeed;
|
|
61
66
|
}
|
|
62
67
|
}
|
|
63
|
-
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (
|
|
68
|
+
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (identity - particle.zIndexFactor) ** zIndexOptions.velocityRate;
|
|
64
69
|
velocity.multTo(zVelocityFactor);
|
|
65
70
|
const { position } = particle;
|
|
66
71
|
position.addTo(velocity);
|
|
@@ -82,19 +87,19 @@
|
|
|
82
87
|
particle.position.x = particle.spin.center.x + particle.spin.radius * updateFunc.x(particle.spin.angle);
|
|
83
88
|
particle.position.y = particle.spin.center.y + particle.spin.radius * updateFunc.y(particle.spin.angle);
|
|
84
89
|
particle.spin.radius += particle.spin.acceleration;
|
|
85
|
-
const maxCanvasSize = Math.max(container.canvas.size.width, container.canvas.size.height), halfMaxSize = maxCanvasSize *
|
|
90
|
+
const maxCanvasSize = Math.max(container.canvas.size.width, container.canvas.size.height), halfMaxSize = maxCanvasSize * half;
|
|
86
91
|
if (particle.spin.radius > halfMaxSize) {
|
|
87
92
|
particle.spin.radius = halfMaxSize;
|
|
88
|
-
particle.spin.acceleration *= -
|
|
93
|
+
particle.spin.acceleration *= -identity;
|
|
89
94
|
}
|
|
90
|
-
else if (particle.spin.radius <
|
|
91
|
-
particle.spin.radius =
|
|
92
|
-
particle.spin.acceleration *= -
|
|
95
|
+
else if (particle.spin.radius < minSpinRadius) {
|
|
96
|
+
particle.spin.radius = minSpinRadius;
|
|
97
|
+
particle.spin.acceleration *= -identity;
|
|
93
98
|
}
|
|
94
|
-
particle.spin.angle += moveSpeed *
|
|
99
|
+
particle.spin.angle += moveSpeed * spinFactor * (identity - particle.spin.radius / maxCanvasSize);
|
|
95
100
|
}
|
|
96
101
|
exports.spin = spin;
|
|
97
|
-
function applyPath(particle, delta) {
|
|
102
|
+
async function applyPath(particle, delta) {
|
|
98
103
|
const particlesOptions = particle.options, pathOptions = particlesOptions.move.path, pathEnabled = pathOptions.enable;
|
|
99
104
|
if (!pathEnabled) {
|
|
100
105
|
return;
|
|
@@ -103,19 +108,39 @@
|
|
|
103
108
|
particle.lastPathTime += delta.value;
|
|
104
109
|
return;
|
|
105
110
|
}
|
|
106
|
-
const path = particle.pathGenerator?.generate(particle, delta);
|
|
111
|
+
const path = await particle.pathGenerator?.generate(particle, delta);
|
|
107
112
|
if (path) {
|
|
108
113
|
particle.velocity.addTo(path);
|
|
109
114
|
}
|
|
110
115
|
if (pathOptions.clamp) {
|
|
111
|
-
particle.velocity.x = (0, engine_1.clamp)(particle.velocity.x, -
|
|
112
|
-
particle.velocity.y = (0, engine_1.clamp)(particle.velocity.y, -
|
|
116
|
+
particle.velocity.x = (0, engine_1.clamp)(particle.velocity.x, -identity, identity);
|
|
117
|
+
particle.velocity.y = (0, engine_1.clamp)(particle.velocity.y, -identity, identity);
|
|
113
118
|
}
|
|
114
119
|
particle.lastPathTime -= particle.pathDelay;
|
|
115
120
|
}
|
|
116
121
|
exports.applyPath = applyPath;
|
|
117
122
|
function getProximitySpeedFactor(particle) {
|
|
118
|
-
return particle.slow.inRange ? particle.slow.factor :
|
|
123
|
+
return particle.slow.inRange ? particle.slow.factor : identity;
|
|
119
124
|
}
|
|
120
125
|
exports.getProximitySpeedFactor = getProximitySpeedFactor;
|
|
126
|
+
function initSpin(particle) {
|
|
127
|
+
const container = particle.container, options = particle.options, spinOptions = options.move.spin;
|
|
128
|
+
if (!spinOptions.enable) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const spinPos = spinOptions.position ?? { x: 50, y: 50 }, spinFactor = 0.01, spinCenter = {
|
|
132
|
+
x: spinPos.x * spinFactor * container.canvas.size.width,
|
|
133
|
+
y: spinPos.y * spinFactor * container.canvas.size.height,
|
|
134
|
+
}, pos = particle.getPosition(), distance = (0, engine_1.getDistance)(pos, spinCenter), spinAcceleration = (0, engine_1.getRangeValue)(spinOptions.acceleration);
|
|
135
|
+
particle.retina.spinAcceleration = spinAcceleration * container.retina.pixelRatio;
|
|
136
|
+
const minVelocity = 0;
|
|
137
|
+
particle.spin = {
|
|
138
|
+
center: spinCenter,
|
|
139
|
+
direction: particle.velocity.x >= minVelocity ? "clockwise" : "counter-clockwise",
|
|
140
|
+
angle: particle.velocity.angle,
|
|
141
|
+
radius: distance,
|
|
142
|
+
acceleration: particle.retina.spinAcceleration,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
exports.initSpin = initSpin;
|
|
121
146
|
});
|
package/umd/index.js
CHANGED
|
@@ -1,18 +1,44 @@
|
|
|
1
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
|
+
if (k2 === undefined) k2 = k;
|
|
3
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(o, k2, desc);
|
|
8
|
+
}) : (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
o[k2] = m[k];
|
|
11
|
+
}));
|
|
12
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
13
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
14
|
+
}) : function(o, v) {
|
|
15
|
+
o["default"] = v;
|
|
16
|
+
});
|
|
17
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
18
|
+
if (mod && mod.__esModule) return mod;
|
|
19
|
+
var result = {};
|
|
20
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
21
|
+
__setModuleDefault(result, mod);
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
1
24
|
(function (factory) {
|
|
2
25
|
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
26
|
var v = factory(require, exports);
|
|
4
27
|
if (v !== undefined) module.exports = v;
|
|
5
28
|
}
|
|
6
29
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports"
|
|
30
|
+
define(["require", "exports"], factory);
|
|
8
31
|
}
|
|
9
32
|
})(function (require, exports) {
|
|
10
33
|
"use strict";
|
|
34
|
+
var __syncRequire = typeof module === "object" && typeof module.exports === "object";
|
|
11
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
36
|
exports.loadBaseMover = void 0;
|
|
13
|
-
const BaseMover_js_1 = require("./BaseMover.js");
|
|
14
37
|
async function loadBaseMover(engine, refresh = true) {
|
|
15
|
-
await engine.addMover("base", () =>
|
|
38
|
+
await engine.addMover("base", async () => {
|
|
39
|
+
const { BaseMover } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./BaseMover.js"))) : new Promise((resolve_1, reject_1) => { require(["./BaseMover.js"], resolve_1, reject_1); }).then(__importStar));
|
|
40
|
+
return new BaseMover();
|
|
41
|
+
}, refresh);
|
|
16
42
|
}
|
|
17
43
|
exports.loadBaseMover = loadBaseMover;
|
|
18
44
|
});
|