@tsparticles/move-base 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.
- package/LICENSE +21 -0
- package/README.md +70 -0
- package/browser/BaseMover.js +78 -0
- package/browser/IParticleGravity.js +1 -0
- package/browser/IParticleSpin.js +1 -0
- package/browser/Types.js +1 -0
- package/browser/Utils.js +74 -0
- package/browser/index.js +4 -0
- package/cjs/BaseMover.js +82 -0
- package/cjs/IParticleGravity.js +2 -0
- package/cjs/IParticleSpin.js +2 -0
- package/cjs/Types.js +2 -0
- package/cjs/Utils.js +81 -0
- package/cjs/index.js +19 -0
- package/esm/BaseMover.js +78 -0
- package/esm/IParticleGravity.js +1 -0
- package/esm/IParticleSpin.js +1 -0
- package/esm/Types.js +1 -0
- package/esm/Utils.js +74 -0
- package/esm/index.js +4 -0
- package/package.json +82 -0
- package/report.html +39 -0
- package/tsparticles.move.base.js +287 -0
- package/tsparticles.move.base.min.js +2 -0
- package/tsparticles.move.base.min.js.LICENSE.txt +8 -0
- package/types/BaseMover.d.ts +7 -0
- package/types/IParticleGravity.d.ts +5 -0
- package/types/IParticleSpin.d.ts +8 -0
- package/types/Types.d.ts +10 -0
- package/types/Utils.d.ts +6 -0
- package/types/index.d.ts +2 -0
- package/umd/BaseMover.js +92 -0
- package/umd/IParticleGravity.js +12 -0
- package/umd/IParticleSpin.js +12 -0
- package/umd/Types.js +12 -0
- package/umd/Utils.js +91 -0
- package/umd/index.js +18 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Author : Matteo Bruni
|
|
3
|
+
* MIT license: https://opensource.org/licenses/MIT
|
|
4
|
+
* Demo / Generator : https://particles.js.org/
|
|
5
|
+
* GitHub : https://www.github.com/matteobruni/tsparticles
|
|
6
|
+
* How to use? : Check the GitHub README
|
|
7
|
+
* v3.0.0-alpha.0
|
|
8
|
+
*/
|
|
9
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
10
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
|
11
|
+
module.exports = factory(require("@tsparticles/engine"));
|
|
12
|
+
else if(typeof define === 'function' && define.amd)
|
|
13
|
+
define(["@tsparticles/engine"], factory);
|
|
14
|
+
else {
|
|
15
|
+
var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]);
|
|
16
|
+
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
|
|
17
|
+
}
|
|
18
|
+
})(this, (__WEBPACK_EXTERNAL_MODULE__533__) => {
|
|
19
|
+
return /******/ (() => { // webpackBootstrap
|
|
20
|
+
/******/ "use strict";
|
|
21
|
+
/******/ var __webpack_modules__ = ({
|
|
22
|
+
|
|
23
|
+
/***/ 533:
|
|
24
|
+
/***/ ((module) => {
|
|
25
|
+
|
|
26
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE__533__;
|
|
27
|
+
|
|
28
|
+
/***/ })
|
|
29
|
+
|
|
30
|
+
/******/ });
|
|
31
|
+
/************************************************************************/
|
|
32
|
+
/******/ // The module cache
|
|
33
|
+
/******/ var __webpack_module_cache__ = {};
|
|
34
|
+
/******/
|
|
35
|
+
/******/ // The require function
|
|
36
|
+
/******/ function __webpack_require__(moduleId) {
|
|
37
|
+
/******/ // Check if module is in cache
|
|
38
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
39
|
+
/******/ if (cachedModule !== undefined) {
|
|
40
|
+
/******/ return cachedModule.exports;
|
|
41
|
+
/******/ }
|
|
42
|
+
/******/ // Create a new module (and put it into the cache)
|
|
43
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
44
|
+
/******/ // no module.id needed
|
|
45
|
+
/******/ // no module.loaded needed
|
|
46
|
+
/******/ exports: {}
|
|
47
|
+
/******/ };
|
|
48
|
+
/******/
|
|
49
|
+
/******/ // Execute the module function
|
|
50
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
51
|
+
/******/
|
|
52
|
+
/******/ // Return the exports of the module
|
|
53
|
+
/******/ return module.exports;
|
|
54
|
+
/******/ }
|
|
55
|
+
/******/
|
|
56
|
+
/************************************************************************/
|
|
57
|
+
/******/ /* webpack/runtime/define property getters */
|
|
58
|
+
/******/ (() => {
|
|
59
|
+
/******/ // define getter functions for harmony exports
|
|
60
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
61
|
+
/******/ for(var key in definition) {
|
|
62
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
63
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
64
|
+
/******/ }
|
|
65
|
+
/******/ }
|
|
66
|
+
/******/ };
|
|
67
|
+
/******/ })();
|
|
68
|
+
/******/
|
|
69
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
70
|
+
/******/ (() => {
|
|
71
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
72
|
+
/******/ })();
|
|
73
|
+
/******/
|
|
74
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
75
|
+
/******/ (() => {
|
|
76
|
+
/******/ // define __esModule on exports
|
|
77
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
78
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
79
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
80
|
+
/******/ }
|
|
81
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
82
|
+
/******/ };
|
|
83
|
+
/******/ })();
|
|
84
|
+
/******/
|
|
85
|
+
/************************************************************************/
|
|
86
|
+
var __webpack_exports__ = {};
|
|
87
|
+
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
|
88
|
+
(() => {
|
|
89
|
+
// ESM COMPAT FLAG
|
|
90
|
+
__webpack_require__.r(__webpack_exports__);
|
|
91
|
+
|
|
92
|
+
// EXPORTS
|
|
93
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
94
|
+
"loadBaseMover": () => (/* binding */ loadBaseMover)
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
|
|
98
|
+
var engine_root_window_ = __webpack_require__(533);
|
|
99
|
+
;// CONCATENATED MODULE: ./dist/browser/Utils.js
|
|
100
|
+
|
|
101
|
+
function applyDistance(particle) {
|
|
102
|
+
const initialPosition = particle.initialPosition,
|
|
103
|
+
{
|
|
104
|
+
dx,
|
|
105
|
+
dy
|
|
106
|
+
} = (0,engine_root_window_.getDistances)(initialPosition, particle.position),
|
|
107
|
+
dxFixed = Math.abs(dx),
|
|
108
|
+
dyFixed = Math.abs(dy),
|
|
109
|
+
hDistance = particle.retina.maxDistance.horizontal,
|
|
110
|
+
vDistance = particle.retina.maxDistance.vertical;
|
|
111
|
+
if (!hDistance && !vDistance) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if ((hDistance && dxFixed >= hDistance || vDistance && dyFixed >= vDistance) && !particle.misplaced) {
|
|
115
|
+
particle.misplaced = !!hDistance && dxFixed > hDistance || !!vDistance && dyFixed > vDistance;
|
|
116
|
+
if (hDistance) {
|
|
117
|
+
particle.velocity.x = particle.velocity.y / 2 - particle.velocity.x;
|
|
118
|
+
}
|
|
119
|
+
if (vDistance) {
|
|
120
|
+
particle.velocity.y = particle.velocity.x / 2 - particle.velocity.y;
|
|
121
|
+
}
|
|
122
|
+
} else if ((!hDistance || dxFixed < hDistance) && (!vDistance || dyFixed < vDistance) && particle.misplaced) {
|
|
123
|
+
particle.misplaced = false;
|
|
124
|
+
} else if (particle.misplaced) {
|
|
125
|
+
const pos = particle.position,
|
|
126
|
+
vel = particle.velocity;
|
|
127
|
+
if (hDistance && (pos.x < initialPosition.x && vel.x < 0 || pos.x > initialPosition.x && vel.x > 0)) {
|
|
128
|
+
vel.x *= -(0,engine_root_window_.getRandom)();
|
|
129
|
+
}
|
|
130
|
+
if (vDistance && (pos.y < initialPosition.y && vel.y < 0 || pos.y > initialPosition.y && vel.y > 0)) {
|
|
131
|
+
vel.y *= -(0,engine_root_window_.getRandom)();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function spin(particle, moveSpeed) {
|
|
136
|
+
const container = particle.container;
|
|
137
|
+
if (!particle.spin) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const updateFunc = {
|
|
141
|
+
x: particle.spin.direction === "clockwise" ? Math.cos : Math.sin,
|
|
142
|
+
y: particle.spin.direction === "clockwise" ? Math.sin : Math.cos
|
|
143
|
+
};
|
|
144
|
+
particle.position.x = particle.spin.center.x + particle.spin.radius * updateFunc.x(particle.spin.angle);
|
|
145
|
+
particle.position.y = particle.spin.center.y + particle.spin.radius * updateFunc.y(particle.spin.angle);
|
|
146
|
+
particle.spin.radius += particle.spin.acceleration;
|
|
147
|
+
const maxCanvasSize = Math.max(container.canvas.size.width, container.canvas.size.height);
|
|
148
|
+
if (particle.spin.radius > maxCanvasSize / 2) {
|
|
149
|
+
particle.spin.radius = maxCanvasSize / 2;
|
|
150
|
+
particle.spin.acceleration *= -1;
|
|
151
|
+
} else if (particle.spin.radius < 0) {
|
|
152
|
+
particle.spin.radius = 0;
|
|
153
|
+
particle.spin.acceleration *= -1;
|
|
154
|
+
}
|
|
155
|
+
particle.spin.angle += moveSpeed / 100 * (1 - particle.spin.radius / maxCanvasSize);
|
|
156
|
+
}
|
|
157
|
+
function applyPath(particle, delta) {
|
|
158
|
+
var _a;
|
|
159
|
+
const particlesOptions = particle.options,
|
|
160
|
+
pathOptions = particlesOptions.move.path,
|
|
161
|
+
pathEnabled = pathOptions.enable;
|
|
162
|
+
if (!pathEnabled) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (particle.lastPathTime <= particle.pathDelay) {
|
|
166
|
+
particle.lastPathTime += delta.value;
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const path = (_a = particle.pathGenerator) === null || _a === void 0 ? void 0 : _a.generate(particle);
|
|
170
|
+
if (path) {
|
|
171
|
+
particle.velocity.addTo(path);
|
|
172
|
+
}
|
|
173
|
+
if (pathOptions.clamp) {
|
|
174
|
+
particle.velocity.x = (0,engine_root_window_.clamp)(particle.velocity.x, -1, 1);
|
|
175
|
+
particle.velocity.y = (0,engine_root_window_.clamp)(particle.velocity.y, -1, 1);
|
|
176
|
+
}
|
|
177
|
+
particle.lastPathTime -= particle.pathDelay;
|
|
178
|
+
}
|
|
179
|
+
function getProximitySpeedFactor(particle) {
|
|
180
|
+
return particle.slow.inRange ? particle.slow.factor : 1;
|
|
181
|
+
}
|
|
182
|
+
;// CONCATENATED MODULE: ./dist/browser/BaseMover.js
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
class BaseMover {
|
|
186
|
+
init(particle) {
|
|
187
|
+
var _a;
|
|
188
|
+
const container = particle.container,
|
|
189
|
+
options = particle.options,
|
|
190
|
+
gravityOptions = options.move.gravity,
|
|
191
|
+
spinOptions = options.move.spin;
|
|
192
|
+
particle.gravity = {
|
|
193
|
+
enable: gravityOptions.enable,
|
|
194
|
+
acceleration: (0,engine_root_window_.getRangeValue)(gravityOptions.acceleration),
|
|
195
|
+
inverse: gravityOptions.inverse
|
|
196
|
+
};
|
|
197
|
+
if (spinOptions.enable) {
|
|
198
|
+
const spinPos = (_a = spinOptions.position) !== null && _a !== void 0 ? _a : {
|
|
199
|
+
x: 50,
|
|
200
|
+
y: 50
|
|
201
|
+
},
|
|
202
|
+
spinCenter = {
|
|
203
|
+
x: spinPos.x / 100 * container.canvas.size.width,
|
|
204
|
+
y: spinPos.y / 100 * container.canvas.size.height
|
|
205
|
+
},
|
|
206
|
+
pos = particle.getPosition(),
|
|
207
|
+
distance = (0,engine_root_window_.getDistance)(pos, spinCenter),
|
|
208
|
+
spinAcceleration = (0,engine_root_window_.getRangeValue)(spinOptions.acceleration);
|
|
209
|
+
particle.retina.spinAcceleration = spinAcceleration * container.retina.pixelRatio;
|
|
210
|
+
particle.spin = {
|
|
211
|
+
center: spinCenter,
|
|
212
|
+
direction: particle.velocity.x >= 0 ? "clockwise" : "counter-clockwise",
|
|
213
|
+
angle: particle.velocity.angle,
|
|
214
|
+
radius: distance,
|
|
215
|
+
acceleration: particle.retina.spinAcceleration
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
isEnabled(particle) {
|
|
220
|
+
return !particle.destroyed && particle.options.move.enable;
|
|
221
|
+
}
|
|
222
|
+
move(particle, delta) {
|
|
223
|
+
var _a, _b, _c;
|
|
224
|
+
var _d, _e;
|
|
225
|
+
const particleOptions = particle.options,
|
|
226
|
+
moveOptions = particleOptions.move;
|
|
227
|
+
if (!moveOptions.enable) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const container = particle.container,
|
|
231
|
+
slowFactor = getProximitySpeedFactor(particle),
|
|
232
|
+
baseSpeed = ((_a = (_d = particle.retina).moveSpeed) !== null && _a !== void 0 ? _a : _d.moveSpeed = (0,engine_root_window_.getRangeValue)(moveOptions.speed) * container.retina.pixelRatio) * container.retina.reduceFactor,
|
|
233
|
+
moveDrift = (_b = (_e = particle.retina).moveDrift) !== null && _b !== void 0 ? _b : _e.moveDrift = (0,engine_root_window_.getRangeValue)(particle.options.move.drift) * container.retina.pixelRatio,
|
|
234
|
+
maxSize = (0,engine_root_window_.getRangeMax)(particleOptions.size.value) * container.retina.pixelRatio,
|
|
235
|
+
sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1,
|
|
236
|
+
speedFactor = sizeFactor * slowFactor * (delta.factor || 1),
|
|
237
|
+
diffFactor = 2,
|
|
238
|
+
moveSpeed = baseSpeed * speedFactor / diffFactor;
|
|
239
|
+
if (moveOptions.spin.enable) {
|
|
240
|
+
spin(particle, moveSpeed);
|
|
241
|
+
} else {
|
|
242
|
+
applyPath(particle, delta);
|
|
243
|
+
const gravityOptions = particle.gravity,
|
|
244
|
+
gravityFactor = (gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && gravityOptions.inverse ? -1 : 1;
|
|
245
|
+
if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && moveSpeed) {
|
|
246
|
+
particle.velocity.y += gravityFactor * (gravityOptions.acceleration * delta.factor) / (60 * moveSpeed);
|
|
247
|
+
}
|
|
248
|
+
if (moveDrift && moveSpeed) {
|
|
249
|
+
particle.velocity.x += moveDrift * delta.factor / (60 * moveSpeed);
|
|
250
|
+
}
|
|
251
|
+
const decay = particle.moveDecay;
|
|
252
|
+
if (decay != 1) {
|
|
253
|
+
particle.velocity.multTo(decay);
|
|
254
|
+
}
|
|
255
|
+
const velocity = particle.velocity.mult(moveSpeed),
|
|
256
|
+
maxSpeed = (_c = particle.retina.maxSpeed) !== null && _c !== void 0 ? _c : container.retina.maxSpeed;
|
|
257
|
+
if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && maxSpeed > 0 && (!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed || gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed)) {
|
|
258
|
+
velocity.y = gravityFactor * maxSpeed;
|
|
259
|
+
if (moveSpeed) {
|
|
260
|
+
particle.velocity.y = velocity.y / moveSpeed;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
const zIndexOptions = particle.options.zIndex,
|
|
264
|
+
zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate;
|
|
265
|
+
if (zVelocityFactor != 1) {
|
|
266
|
+
velocity.multTo(zVelocityFactor);
|
|
267
|
+
}
|
|
268
|
+
particle.position.addTo(velocity);
|
|
269
|
+
if (moveOptions.vibrate) {
|
|
270
|
+
particle.position.x += Math.sin(particle.position.x * Math.cos(particle.position.y));
|
|
271
|
+
particle.position.y += Math.cos(particle.position.y * Math.sin(particle.position.x));
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
applyDistance(particle);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
;// CONCATENATED MODULE: ./dist/browser/index.js
|
|
278
|
+
|
|
279
|
+
async function loadBaseMover(engine) {
|
|
280
|
+
engine.addMover("base", () => new BaseMover());
|
|
281
|
+
}
|
|
282
|
+
})();
|
|
283
|
+
|
|
284
|
+
/******/ return __webpack_exports__;
|
|
285
|
+
/******/ })()
|
|
286
|
+
;
|
|
287
|
+
});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see tsparticles.move.base.min.js.LICENSE.txt */
|
|
2
|
+
!function(e,i){if("object"==typeof exports&&"object"==typeof module)module.exports=i(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],i);else{var t="object"==typeof exports?i(require("@tsparticles/engine")):i(e.window);for(var n in t)("object"==typeof exports?exports:e)[n]=t[n]}}(this,(e=>(()=>{"use strict";var i={533:i=>{i.exports=e}},t={};function n(e){var o=t[e];if(void 0!==o)return o.exports;var a=t[e]={exports:{}};return i[e](a,a.exports,n),a.exports}n.d=(e,i)=>{for(var t in i)n.o(i,t)&&!n.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:i[t]})},n.o=(e,i)=>Object.prototype.hasOwnProperty.call(e,i),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{n.r(o),n.d(o,{loadBaseMover:()=>t});var e=n(533);class i{init(i){var t;const n=i.container,o=i.options,a=o.move.gravity,s=o.move.spin;if(i.gravity={enable:a.enable,acceleration:(0,e.getRangeValue)(a.acceleration),inverse:a.inverse},s.enable){const o=null!==(t=s.position)&&void 0!==t?t:{x:50,y:50},a={x:o.x/100*n.canvas.size.width,y:o.y/100*n.canvas.size.height},r=i.getPosition(),c=(0,e.getDistance)(r,a),l=(0,e.getRangeValue)(s.acceleration);i.retina.spinAcceleration=l*n.retina.pixelRatio,i.spin={center:a,direction:i.velocity.x>=0?"clockwise":"counter-clockwise",angle:i.velocity.angle,radius:c,acceleration:i.retina.spinAcceleration}}}isEnabled(e){return!e.destroyed&&e.options.move.enable}move(i,t){var n,o,a,s,r;const c=i.options,l=c.move;if(!l.enable)return;const p=i.container,v=function(e){return e.slow.inRange?e.slow.factor:1}(i),y=(null!==(n=(s=i.retina).moveSpeed)&&void 0!==n?n:s.moveSpeed=(0,e.getRangeValue)(l.speed)*p.retina.pixelRatio)*p.retina.reduceFactor,d=null!==(o=(r=i.retina).moveDrift)&&void 0!==o?o:r.moveDrift=(0,e.getRangeValue)(i.options.move.drift)*p.retina.pixelRatio,u=(0,e.getRangeMax)(c.size.value)*p.retina.pixelRatio,x=y*((l.size?i.getRadius()/u:1)*v*(t.factor||1))/2;if(l.spin.enable)!function(e,i){const t=e.container;if(!e.spin)return;const n={x:"clockwise"===e.spin.direction?Math.cos:Math.sin,y:"clockwise"===e.spin.direction?Math.sin:Math.cos};e.position.x=e.spin.center.x+e.spin.radius*n.x(e.spin.angle),e.position.y=e.spin.center.y+e.spin.radius*n.y(e.spin.angle),e.spin.radius+=e.spin.acceleration;const o=Math.max(t.canvas.size.width,t.canvas.size.height);e.spin.radius>o/2?(e.spin.radius=o/2,e.spin.acceleration*=-1):e.spin.radius<0&&(e.spin.radius=0,e.spin.acceleration*=-1),e.spin.angle+=i/100*(1-e.spin.radius/o)}(i,x);else{!function(i,t){var n;const o=i.options.move.path;if(!o.enable)return;if(i.lastPathTime<=i.pathDelay)return void(i.lastPathTime+=t.value);const a=null===(n=i.pathGenerator)||void 0===n?void 0:n.generate(i);a&&i.velocity.addTo(a),o.clamp&&(i.velocity.x=(0,e.clamp)(i.velocity.x,-1,1),i.velocity.y=(0,e.clamp)(i.velocity.y,-1,1)),i.lastPathTime-=i.pathDelay}(i,t);const n=i.gravity,o=(null==n?void 0:n.enable)&&n.inverse?-1:1;(null==n?void 0:n.enable)&&x&&(i.velocity.y+=o*(n.acceleration*t.factor)/(60*x)),d&&x&&(i.velocity.x+=d*t.factor/(60*x));const s=i.moveDecay;1!=s&&i.velocity.multTo(s);const r=i.velocity.mult(x),c=null!==(a=i.retina.maxSpeed)&&void 0!==a?a:p.retina.maxSpeed;(null==n?void 0:n.enable)&&c>0&&(!n.inverse&&r.y>=0&&r.y>=c||n.inverse&&r.y<=0&&r.y<=-c)&&(r.y=o*c,x&&(i.velocity.y=r.y/x));const v=i.options.zIndex,y=(1-i.zIndexFactor)**v.velocityRate;1!=y&&r.multTo(y),i.position.addTo(r),l.vibrate&&(i.position.x+=Math.sin(i.position.x*Math.cos(i.position.y)),i.position.y+=Math.cos(i.position.y*Math.sin(i.position.x)))}!function(i){const t=i.initialPosition,{dx:n,dy:o}=(0,e.getDistances)(t,i.position),a=Math.abs(n),s=Math.abs(o),r=i.retina.maxDistance.horizontal,c=i.retina.maxDistance.vertical;if(r||c)if((r&&a>=r||c&&s>=c)&&!i.misplaced)i.misplaced=!!r&&a>r||!!c&&s>c,r&&(i.velocity.x=i.velocity.y/2-i.velocity.x),c&&(i.velocity.y=i.velocity.x/2-i.velocity.y);else if((!r||a<r)&&(!c||s<c)&&i.misplaced)i.misplaced=!1;else if(i.misplaced){const n=i.position,o=i.velocity;r&&(n.x<t.x&&o.x<0||n.x>t.x&&o.x>0)&&(o.x*=-(0,e.getRandom)()),c&&(n.y<t.y&&o.y<0||n.y>t.y&&o.y>0)&&(o.y*=-(0,e.getRandom)())}}(i)}}async function t(e){e.addMover("base",(()=>new i))}})(),o})()));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { IDelta, IParticleMover, Particle } from "@tsparticles/engine";
|
|
2
|
+
import type { MoveParticle } from "./Types";
|
|
3
|
+
export declare class BaseMover implements IParticleMover {
|
|
4
|
+
init(particle: MoveParticle): void;
|
|
5
|
+
isEnabled(particle: Particle): boolean;
|
|
6
|
+
move(particle: MoveParticle, delta: IDelta): void;
|
|
7
|
+
}
|
package/types/Types.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IParticleGravity } from "./IParticleGravity";
|
|
2
|
+
import type { IParticleSpin } from "./IParticleSpin";
|
|
3
|
+
import type { Particle } from "@tsparticles/engine";
|
|
4
|
+
export type MoveParticle = Particle & {
|
|
5
|
+
gravity?: IParticleGravity;
|
|
6
|
+
retina: {
|
|
7
|
+
spinAcceleration?: number;
|
|
8
|
+
};
|
|
9
|
+
spin?: IParticleSpin;
|
|
10
|
+
};
|
package/types/Utils.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { IDelta, Particle } from "@tsparticles/engine";
|
|
2
|
+
import type { MoveParticle } from "./Types";
|
|
3
|
+
export declare function applyDistance(particle: MoveParticle): void;
|
|
4
|
+
export declare function spin(particle: MoveParticle, moveSpeed: number): void;
|
|
5
|
+
export declare function applyPath(particle: Particle, delta: IDelta): void;
|
|
6
|
+
export declare function getProximitySpeedFactor(particle: Particle): number;
|
package/types/index.d.ts
ADDED
package/umd/BaseMover.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
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", "./Utils"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.BaseMover = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
const Utils_1 = require("./Utils");
|
|
15
|
+
class BaseMover {
|
|
16
|
+
init(particle) {
|
|
17
|
+
var _a;
|
|
18
|
+
const container = particle.container, options = particle.options, gravityOptions = options.move.gravity, spinOptions = options.move.spin;
|
|
19
|
+
particle.gravity = {
|
|
20
|
+
enable: gravityOptions.enable,
|
|
21
|
+
acceleration: (0, engine_1.getRangeValue)(gravityOptions.acceleration),
|
|
22
|
+
inverse: gravityOptions.inverse,
|
|
23
|
+
};
|
|
24
|
+
if (spinOptions.enable) {
|
|
25
|
+
const spinPos = (_a = spinOptions.position) !== null && _a !== void 0 ? _a : { x: 50, y: 50 }, spinCenter = {
|
|
26
|
+
x: (spinPos.x / 100) * container.canvas.size.width,
|
|
27
|
+
y: (spinPos.y / 100) * container.canvas.size.height,
|
|
28
|
+
}, pos = particle.getPosition(), distance = (0, engine_1.getDistance)(pos, spinCenter), spinAcceleration = (0, engine_1.getRangeValue)(spinOptions.acceleration);
|
|
29
|
+
particle.retina.spinAcceleration = spinAcceleration * container.retina.pixelRatio;
|
|
30
|
+
particle.spin = {
|
|
31
|
+
center: spinCenter,
|
|
32
|
+
direction: particle.velocity.x >= 0 ? "clockwise" : "counter-clockwise",
|
|
33
|
+
angle: particle.velocity.angle,
|
|
34
|
+
radius: distance,
|
|
35
|
+
acceleration: particle.retina.spinAcceleration,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
isEnabled(particle) {
|
|
40
|
+
return !particle.destroyed && particle.options.move.enable;
|
|
41
|
+
}
|
|
42
|
+
move(particle, delta) {
|
|
43
|
+
var _a, _b, _c;
|
|
44
|
+
var _d, _e;
|
|
45
|
+
const particleOptions = particle.options, moveOptions = particleOptions.move;
|
|
46
|
+
if (!moveOptions.enable) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const container = particle.container, slowFactor = (0, Utils_1.getProximitySpeedFactor)(particle), baseSpeed = ((_a = (_d = particle.retina).moveSpeed) !== null && _a !== void 0 ? _a : (_d.moveSpeed = (0, engine_1.getRangeValue)(moveOptions.speed) * container.retina.pixelRatio)) *
|
|
50
|
+
container.retina.reduceFactor, moveDrift = ((_b = (_e = particle.retina).moveDrift) !== null && _b !== void 0 ? _b : (_e.moveDrift = (0, engine_1.getRangeValue)(particle.options.move.drift) * container.retina.pixelRatio)), maxSize = (0, engine_1.getRangeMax)(particleOptions.size.value) * container.retina.pixelRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, speedFactor = sizeFactor * slowFactor * (delta.factor || 1), diffFactor = 2, moveSpeed = (baseSpeed * speedFactor) / diffFactor;
|
|
51
|
+
if (moveOptions.spin.enable) {
|
|
52
|
+
(0, Utils_1.spin)(particle, moveSpeed);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
(0, Utils_1.applyPath)(particle, delta);
|
|
56
|
+
const gravityOptions = particle.gravity, gravityFactor = (gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && gravityOptions.inverse ? -1 : 1;
|
|
57
|
+
if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && moveSpeed) {
|
|
58
|
+
particle.velocity.y +=
|
|
59
|
+
(gravityFactor * (gravityOptions.acceleration * delta.factor)) / (60 * moveSpeed);
|
|
60
|
+
}
|
|
61
|
+
if (moveDrift && moveSpeed) {
|
|
62
|
+
particle.velocity.x += (moveDrift * delta.factor) / (60 * moveSpeed);
|
|
63
|
+
}
|
|
64
|
+
const decay = particle.moveDecay;
|
|
65
|
+
if (decay != 1) {
|
|
66
|
+
particle.velocity.multTo(decay);
|
|
67
|
+
}
|
|
68
|
+
const velocity = particle.velocity.mult(moveSpeed), maxSpeed = (_c = particle.retina.maxSpeed) !== null && _c !== void 0 ? _c : container.retina.maxSpeed;
|
|
69
|
+
if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) &&
|
|
70
|
+
maxSpeed > 0 &&
|
|
71
|
+
((!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed) ||
|
|
72
|
+
(gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed))) {
|
|
73
|
+
velocity.y = gravityFactor * maxSpeed;
|
|
74
|
+
if (moveSpeed) {
|
|
75
|
+
particle.velocity.y = velocity.y / moveSpeed;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate;
|
|
79
|
+
if (zVelocityFactor != 1) {
|
|
80
|
+
velocity.multTo(zVelocityFactor);
|
|
81
|
+
}
|
|
82
|
+
particle.position.addTo(velocity);
|
|
83
|
+
if (moveOptions.vibrate) {
|
|
84
|
+
particle.position.x += Math.sin(particle.position.x * Math.cos(particle.position.y));
|
|
85
|
+
particle.position.y += Math.cos(particle.position.y * Math.sin(particle.position.x));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
(0, Utils_1.applyDistance)(particle);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.BaseMover = BaseMover;
|
|
92
|
+
});
|
|
@@ -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,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
|
+
});
|
package/umd/Types.js
ADDED
|
@@ -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
|
+
});
|
package/umd/Utils.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
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.getProximitySpeedFactor = exports.applyPath = exports.spin = exports.applyDistance = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
function applyDistance(particle) {
|
|
15
|
+
const initialPosition = particle.initialPosition, { dx, dy } = (0, engine_1.getDistances)(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), hDistance = particle.retina.maxDistance.horizontal, vDistance = particle.retina.maxDistance.vertical;
|
|
16
|
+
if (!hDistance && !vDistance) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (((hDistance && dxFixed >= hDistance) || (vDistance && dyFixed >= vDistance)) && !particle.misplaced) {
|
|
20
|
+
particle.misplaced = (!!hDistance && dxFixed > hDistance) || (!!vDistance && dyFixed > vDistance);
|
|
21
|
+
if (hDistance) {
|
|
22
|
+
particle.velocity.x = particle.velocity.y / 2 - particle.velocity.x;
|
|
23
|
+
}
|
|
24
|
+
if (vDistance) {
|
|
25
|
+
particle.velocity.y = particle.velocity.x / 2 - particle.velocity.y;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else if ((!hDistance || dxFixed < hDistance) && (!vDistance || dyFixed < vDistance) && particle.misplaced) {
|
|
29
|
+
particle.misplaced = false;
|
|
30
|
+
}
|
|
31
|
+
else if (particle.misplaced) {
|
|
32
|
+
const pos = particle.position, vel = particle.velocity;
|
|
33
|
+
if (hDistance && ((pos.x < initialPosition.x && vel.x < 0) || (pos.x > initialPosition.x && vel.x > 0))) {
|
|
34
|
+
vel.x *= -(0, engine_1.getRandom)();
|
|
35
|
+
}
|
|
36
|
+
if (vDistance && ((pos.y < initialPosition.y && vel.y < 0) || (pos.y > initialPosition.y && vel.y > 0))) {
|
|
37
|
+
vel.y *= -(0, engine_1.getRandom)();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.applyDistance = applyDistance;
|
|
42
|
+
function spin(particle, moveSpeed) {
|
|
43
|
+
const container = particle.container;
|
|
44
|
+
if (!particle.spin) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const updateFunc = {
|
|
48
|
+
x: particle.spin.direction === "clockwise" ? Math.cos : Math.sin,
|
|
49
|
+
y: particle.spin.direction === "clockwise" ? Math.sin : Math.cos,
|
|
50
|
+
};
|
|
51
|
+
particle.position.x = particle.spin.center.x + particle.spin.radius * updateFunc.x(particle.spin.angle);
|
|
52
|
+
particle.position.y = particle.spin.center.y + particle.spin.radius * updateFunc.y(particle.spin.angle);
|
|
53
|
+
particle.spin.radius += particle.spin.acceleration;
|
|
54
|
+
const maxCanvasSize = Math.max(container.canvas.size.width, container.canvas.size.height);
|
|
55
|
+
if (particle.spin.radius > maxCanvasSize / 2) {
|
|
56
|
+
particle.spin.radius = maxCanvasSize / 2;
|
|
57
|
+
particle.spin.acceleration *= -1;
|
|
58
|
+
}
|
|
59
|
+
else if (particle.spin.radius < 0) {
|
|
60
|
+
particle.spin.radius = 0;
|
|
61
|
+
particle.spin.acceleration *= -1;
|
|
62
|
+
}
|
|
63
|
+
particle.spin.angle += (moveSpeed / 100) * (1 - particle.spin.radius / maxCanvasSize);
|
|
64
|
+
}
|
|
65
|
+
exports.spin = spin;
|
|
66
|
+
function applyPath(particle, delta) {
|
|
67
|
+
var _a;
|
|
68
|
+
const particlesOptions = particle.options, pathOptions = particlesOptions.move.path, pathEnabled = pathOptions.enable;
|
|
69
|
+
if (!pathEnabled) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (particle.lastPathTime <= particle.pathDelay) {
|
|
73
|
+
particle.lastPathTime += delta.value;
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const path = (_a = particle.pathGenerator) === null || _a === void 0 ? void 0 : _a.generate(particle);
|
|
77
|
+
if (path) {
|
|
78
|
+
particle.velocity.addTo(path);
|
|
79
|
+
}
|
|
80
|
+
if (pathOptions.clamp) {
|
|
81
|
+
particle.velocity.x = (0, engine_1.clamp)(particle.velocity.x, -1, 1);
|
|
82
|
+
particle.velocity.y = (0, engine_1.clamp)(particle.velocity.y, -1, 1);
|
|
83
|
+
}
|
|
84
|
+
particle.lastPathTime -= particle.pathDelay;
|
|
85
|
+
}
|
|
86
|
+
exports.applyPath = applyPath;
|
|
87
|
+
function getProximitySpeedFactor(particle) {
|
|
88
|
+
return particle.slow.inRange ? particle.slow.factor : 1;
|
|
89
|
+
}
|
|
90
|
+
exports.getProximitySpeedFactor = getProximitySpeedFactor;
|
|
91
|
+
});
|
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", "./BaseMover"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.loadBaseMover = void 0;
|
|
13
|
+
const BaseMover_1 = require("./BaseMover");
|
|
14
|
+
async function loadBaseMover(engine) {
|
|
15
|
+
engine.addMover("base", () => new BaseMover_1.BaseMover());
|
|
16
|
+
}
|
|
17
|
+
exports.loadBaseMover = loadBaseMover;
|
|
18
|
+
});
|