@tsparticles/move-base 3.0.0-alpha.0 → 3.0.0-beta.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.
@@ -4,7 +4,7 @@
4
4
  * Demo / Generator : https://particles.js.org/
5
5
  * GitHub : https://www.github.com/matteobruni/tsparticles
6
6
  * How to use? : Check the GitHub README
7
- * v3.0.0-alpha.0
7
+ * v3.0.0-beta.0
8
8
  */
9
9
  (function webpackUniversalModuleDefinition(root, factory) {
10
10
  if(typeof exports === 'object' && typeof module === 'object')
@@ -91,7 +91,7 @@ __webpack_require__.r(__webpack_exports__);
91
91
 
92
92
  // EXPORTS
93
93
  __webpack_require__.d(__webpack_exports__, {
94
- "loadBaseMover": () => (/* binding */ loadBaseMover)
94
+ loadBaseMover: () => (/* binding */ loadBaseMover)
95
95
  });
96
96
 
97
97
  // EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
@@ -106,8 +106,11 @@ function applyDistance(particle) {
106
106
  } = (0,engine_root_window_.getDistances)(initialPosition, particle.position),
107
107
  dxFixed = Math.abs(dx),
108
108
  dyFixed = Math.abs(dy),
109
- hDistance = particle.retina.maxDistance.horizontal,
110
- vDistance = particle.retina.maxDistance.vertical;
109
+ {
110
+ maxDistance
111
+ } = particle.retina,
112
+ hDistance = maxDistance.horizontal,
113
+ vDistance = maxDistance.vertical;
111
114
  if (!hDistance && !vDistance) {
112
115
  return;
113
116
  }
@@ -132,6 +135,37 @@ function applyDistance(particle) {
132
135
  }
133
136
  }
134
137
  }
138
+ function move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta) {
139
+ applyPath(particle, delta);
140
+ const gravityOptions = particle.gravity,
141
+ gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -1 : 1;
142
+ if (moveDrift && moveSpeed) {
143
+ particle.velocity.x += moveDrift * delta.factor / (60 * moveSpeed);
144
+ }
145
+ if (gravityOptions?.enable && moveSpeed) {
146
+ particle.velocity.y += gravityFactor * (gravityOptions.acceleration * delta.factor) / (60 * moveSpeed);
147
+ }
148
+ const decay = particle.moveDecay;
149
+ particle.velocity.multTo(decay);
150
+ const velocity = particle.velocity.mult(moveSpeed);
151
+ if (gravityOptions?.enable && maxSpeed > 0 && (!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed || gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed)) {
152
+ velocity.y = gravityFactor * maxSpeed;
153
+ if (moveSpeed) {
154
+ particle.velocity.y = velocity.y / moveSpeed;
155
+ }
156
+ }
157
+ const zIndexOptions = particle.options.zIndex,
158
+ zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate;
159
+ velocity.multTo(zVelocityFactor);
160
+ const {
161
+ position
162
+ } = particle;
163
+ position.addTo(velocity);
164
+ if (moveOptions.vibrate) {
165
+ position.x += Math.sin(position.x * Math.cos(position.y));
166
+ position.y += Math.cos(position.y * Math.sin(position.x));
167
+ }
168
+ }
135
169
  function spin(particle, moveSpeed) {
136
170
  const container = particle.container;
137
171
  if (!particle.spin) {
@@ -155,7 +189,6 @@ function spin(particle, moveSpeed) {
155
189
  particle.spin.angle += moveSpeed / 100 * (1 - particle.spin.radius / maxCanvasSize);
156
190
  }
157
191
  function applyPath(particle, delta) {
158
- var _a;
159
192
  const particlesOptions = particle.options,
160
193
  pathOptions = particlesOptions.move.path,
161
194
  pathEnabled = pathOptions.enable;
@@ -166,7 +199,7 @@ function applyPath(particle, delta) {
166
199
  particle.lastPathTime += delta.value;
167
200
  return;
168
201
  }
169
- const path = (_a = particle.pathGenerator) === null || _a === void 0 ? void 0 : _a.generate(particle);
202
+ const path = particle.pathGenerator?.generate(particle, delta);
170
203
  if (path) {
171
204
  particle.velocity.addTo(path);
172
205
  }
@@ -182,20 +215,17 @@ function getProximitySpeedFactor(particle) {
182
215
  ;// CONCATENATED MODULE: ./dist/browser/BaseMover.js
183
216
 
184
217
 
218
+ const diffFactor = 2;
185
219
  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 : {
220
+ constructor() {
221
+ this._initSpin = particle => {
222
+ const container = particle.container,
223
+ options = particle.options,
224
+ spinOptions = options.move.spin;
225
+ if (!spinOptions.enable) {
226
+ return;
227
+ }
228
+ const spinPos = spinOptions.position ?? {
199
229
  x: 50,
200
230
  y: 50
201
231
  },
@@ -214,70 +244,48 @@ class BaseMover {
214
244
  radius: distance,
215
245
  acceleration: particle.retina.spinAcceleration
216
246
  };
217
- }
247
+ };
248
+ }
249
+ init(particle) {
250
+ const options = particle.options,
251
+ gravityOptions = options.move.gravity;
252
+ particle.gravity = {
253
+ enable: gravityOptions.enable,
254
+ acceleration: (0,engine_root_window_.getRangeValue)(gravityOptions.acceleration),
255
+ inverse: gravityOptions.inverse
256
+ };
257
+ this._initSpin(particle);
218
258
  }
219
259
  isEnabled(particle) {
220
260
  return !particle.destroyed && particle.options.move.enable;
221
261
  }
222
262
  move(particle, delta) {
223
- var _a, _b, _c;
224
- var _d, _e;
225
263
  const particleOptions = particle.options,
226
264
  moveOptions = particleOptions.move;
227
265
  if (!moveOptions.enable) {
228
266
  return;
229
267
  }
230
268
  const container = particle.container,
269
+ pxRatio = container.retina.pixelRatio,
231
270
  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,
271
+ baseSpeed = (particle.retina.moveSpeed ??= (0,engine_root_window_.getRangeValue)(moveOptions.speed) * pxRatio) * container.retina.reduceFactor,
272
+ moveDrift = particle.retina.moveDrift ??= (0,engine_root_window_.getRangeValue)(particle.options.move.drift) * pxRatio,
273
+ maxSize = (0,engine_root_window_.getRangeMax)(particleOptions.size.value) * pxRatio,
235
274
  sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1,
236
- speedFactor = sizeFactor * slowFactor * (delta.factor || 1),
237
- diffFactor = 2,
238
- moveSpeed = baseSpeed * speedFactor / diffFactor;
275
+ moveSpeed = baseSpeed * sizeFactor * slowFactor * (delta.factor || 1) / diffFactor,
276
+ maxSpeed = particle.retina.maxSpeed ?? container.retina.maxSpeed;
239
277
  if (moveOptions.spin.enable) {
240
278
  spin(particle, moveSpeed);
241
279
  } 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
- }
280
+ move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta);
273
281
  }
274
282
  applyDistance(particle);
275
283
  }
276
284
  }
277
285
  ;// CONCATENATED MODULE: ./dist/browser/index.js
278
286
 
279
- async function loadBaseMover(engine) {
280
- engine.addMover("base", () => new BaseMover());
287
+ async function loadBaseMover(engine, refresh = true) {
288
+ await engine.addMover("base", () => new BaseMover(), refresh);
281
289
  }
282
290
  })();
283
291
 
@@ -1,2 +1,2 @@
1
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})()));
2
+ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],t);else{var i="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var n in i)("object"==typeof exports?exports:e)[n]=i[n]}}(this,(e=>(()=>{"use strict";var t={533:t=>{t.exports=e}},i={};function n(e){var o=i[e];if(void 0!==o)return o.exports;var a=i[e]={exports:{}};return t[e](a,a.exports,n),a.exports}n.d=(e,t)=>{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),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:()=>a});var e=n(533);function t(t,i,n,o,a,s){!function(t,i){const n=t.options,o=n.move.path;if(!o.enable)return;if(t.lastPathTime<=t.pathDelay)return void(t.lastPathTime+=i.value);const a=t.pathGenerator?.generate(t,i);a&&t.velocity.addTo(a);o.clamp&&(t.velocity.x=(0,e.clamp)(t.velocity.x,-1,1),t.velocity.y=(0,e.clamp)(t.velocity.y,-1,1));t.lastPathTime-=t.pathDelay}(t,s);const c=t.gravity,r=c?.enable&&c.inverse?-1:1;a&&n&&(t.velocity.x+=a*s.factor/(60*n)),c?.enable&&n&&(t.velocity.y+=r*(c.acceleration*s.factor)/(60*n));const l=t.moveDecay;t.velocity.multTo(l);const p=t.velocity.mult(n);c?.enable&&o>0&&(!c.inverse&&p.y>=0&&p.y>=o||c.inverse&&p.y<=0&&p.y<=-o)&&(p.y=r*o,n&&(t.velocity.y=p.y/n));const y=t.options.zIndex,d=(1-t.zIndexFactor)**y.velocityRate;p.multTo(d);const{position:v}=t;v.addTo(p),i.vibrate&&(v.x+=Math.sin(v.x*Math.cos(v.y)),v.y+=Math.cos(v.y*Math.sin(v.x)))}class i{constructor(){this._initSpin=t=>{const i=t.container,n=t.options.move.spin;if(!n.enable)return;const o=n.position??{x:50,y:50},a={x:o.x/100*i.canvas.size.width,y:o.y/100*i.canvas.size.height},s=t.getPosition(),c=(0,e.getDistance)(s,a),r=(0,e.getRangeValue)(n.acceleration);t.retina.spinAcceleration=r*i.retina.pixelRatio,t.spin={center:a,direction:t.velocity.x>=0?"clockwise":"counter-clockwise",angle:t.velocity.angle,radius:c,acceleration:t.retina.spinAcceleration}}}init(t){const i=t.options.move.gravity;t.gravity={enable:i.enable,acceleration:(0,e.getRangeValue)(i.acceleration),inverse:i.inverse},this._initSpin(t)}isEnabled(e){return!e.destroyed&&e.options.move.enable}move(i,n){const o=i.options,a=o.move;if(!a.enable)return;const s=i.container,c=s.retina.pixelRatio,r=function(e){return e.slow.inRange?e.slow.factor:1}(i),l=(i.retina.moveSpeed??=(0,e.getRangeValue)(a.speed)*c)*s.retina.reduceFactor,p=i.retina.moveDrift??=(0,e.getRangeValue)(i.options.move.drift)*c,y=(0,e.getRangeMax)(o.size.value)*c,d=l*(a.size?i.getRadius()/y:1)*r*(n.factor||1)/2,v=i.retina.maxSpeed??s.retina.maxSpeed;a.spin.enable?function(e,t){const i=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(i.canvas.size.width,i.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+=t/100*(1-e.spin.radius/o)}(i,d):t(i,a,d,v,p,n),function(t){const i=t.initialPosition,{dx:n,dy:o}=(0,e.getDistances)(i,t.position),a=Math.abs(n),s=Math.abs(o),{maxDistance:c}=t.retina,r=c.horizontal,l=c.vertical;if(r||l)if((r&&a>=r||l&&s>=l)&&!t.misplaced)t.misplaced=!!r&&a>r||!!l&&s>l,r&&(t.velocity.x=t.velocity.y/2-t.velocity.x),l&&(t.velocity.y=t.velocity.x/2-t.velocity.y);else if((!r||a<r)&&(!l||s<l)&&t.misplaced)t.misplaced=!1;else if(t.misplaced){const n=t.position,o=t.velocity;r&&(n.x<i.x&&o.x<0||n.x>i.x&&o.x>0)&&(o.x*=-(0,e.getRandom)()),l&&(n.y<i.y&&o.y<0||n.y>i.y&&o.y>0)&&(o.y*=-(0,e.getRandom)())}}(i)}}async function a(e,t=!0){await e.addMover("base",(()=>new i),t)}})(),o})()));
@@ -1,8 +1 @@
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
- */
1
+ /*! tsParticles Base Move v3.0.0-beta.0 by Matteo Bruni */
@@ -1,7 +1,8 @@
1
- import type { IDelta, IParticleMover, Particle } from "@tsparticles/engine";
1
+ import { type IDelta, type IParticleMover, type Particle } from "@tsparticles/engine";
2
2
  import type { MoveParticle } from "./Types";
3
3
  export declare class BaseMover implements IParticleMover {
4
4
  init(particle: MoveParticle): void;
5
5
  isEnabled(particle: Particle): boolean;
6
6
  move(particle: MoveParticle, delta: IDelta): void;
7
+ private readonly _initSpin;
7
8
  }
package/types/Utils.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import type { IDelta, Particle } from "@tsparticles/engine";
1
+ import { type IDelta, type Move, type Particle } from "@tsparticles/engine";
2
2
  import type { MoveParticle } from "./Types";
3
3
  export declare function applyDistance(particle: MoveParticle): void;
4
+ export declare function move(particle: MoveParticle, moveOptions: Move, moveSpeed: number, maxSpeed: number, moveDrift: number, delta: IDelta): void;
4
5
  export declare function spin(particle: MoveParticle, moveSpeed: number): void;
5
6
  export declare function applyPath(particle: Particle, delta: IDelta): void;
6
7
  export declare function getProximitySpeedFactor(particle: Particle): number;
package/types/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import type { Engine } from "@tsparticles/engine";
2
- export declare function loadBaseMover(engine: Engine): Promise<void>;
2
+ export declare function loadBaseMover(engine: Engine, refresh?: boolean): Promise<void>;
package/umd/BaseMover.js CHANGED
@@ -12,17 +12,15 @@
12
12
  exports.BaseMover = void 0;
13
13
  const engine_1 = require("@tsparticles/engine");
14
14
  const Utils_1 = require("./Utils");
15
+ const diffFactor = 2;
15
16
  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 = {
17
+ constructor() {
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 = {
26
24
  x: (spinPos.x / 100) * container.canvas.size.width,
27
25
  y: (spinPos.y / 100) * container.canvas.size.height,
28
26
  }, pos = particle.getPosition(), distance = (0, engine_1.getDistance)(pos, spinCenter), spinAcceleration = (0, engine_1.getRangeValue)(spinOptions.acceleration);
@@ -34,56 +32,32 @@
34
32
  radius: distance,
35
33
  acceleration: particle.retina.spinAcceleration,
36
34
  };
37
- }
35
+ };
36
+ }
37
+ init(particle) {
38
+ const options = particle.options, gravityOptions = options.move.gravity;
39
+ particle.gravity = {
40
+ enable: gravityOptions.enable,
41
+ acceleration: (0, engine_1.getRangeValue)(gravityOptions.acceleration),
42
+ inverse: gravityOptions.inverse,
43
+ };
44
+ this._initSpin(particle);
38
45
  }
39
46
  isEnabled(particle) {
40
47
  return !particle.destroyed && particle.options.move.enable;
41
48
  }
42
49
  move(particle, delta) {
43
- var _a, _b, _c;
44
- var _d, _e;
45
50
  const particleOptions = particle.options, moveOptions = particleOptions.move;
46
51
  if (!moveOptions.enable) {
47
52
  return;
48
53
  }
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;
54
+ const container = particle.container, pxRatio = container.retina.pixelRatio, slowFactor = (0, Utils_1.getProximitySpeedFactor)(particle), baseSpeed = (particle.retina.moveSpeed ??= (0, engine_1.getRangeValue)(moveOptions.speed) * pxRatio) *
55
+ container.retina.reduceFactor, moveDrift = (particle.retina.moveDrift ??= (0, engine_1.getRangeValue)(particle.options.move.drift) * pxRatio), maxSize = (0, engine_1.getRangeMax)(particleOptions.size.value) * pxRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, moveSpeed = (baseSpeed * sizeFactor * slowFactor * (delta.factor || 1)) / diffFactor, maxSpeed = particle.retina.maxSpeed ?? container.retina.maxSpeed;
51
56
  if (moveOptions.spin.enable) {
52
57
  (0, Utils_1.spin)(particle, moveSpeed);
53
58
  }
54
59
  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
- }
60
+ (0, Utils_1.move)(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta);
87
61
  }
88
62
  (0, Utils_1.applyDistance)(particle);
89
63
  }
package/umd/Utils.js CHANGED
@@ -9,10 +9,10 @@
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.applyDistance = void 0;
12
+ exports.getProximitySpeedFactor = exports.applyPath = exports.spin = exports.move = exports.applyDistance = void 0;
13
13
  const engine_1 = require("@tsparticles/engine");
14
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;
15
+ 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
16
  if (!hDistance && !vDistance) {
17
17
  return;
18
18
  }
@@ -39,6 +39,37 @@
39
39
  }
40
40
  }
41
41
  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 ? -1 : 1;
45
+ if (moveDrift && moveSpeed) {
46
+ particle.velocity.x += (moveDrift * delta.factor) / (60 * moveSpeed);
47
+ }
48
+ if (gravityOptions?.enable && moveSpeed) {
49
+ particle.velocity.y += (gravityFactor * (gravityOptions.acceleration * delta.factor)) / (60 * moveSpeed);
50
+ }
51
+ const decay = particle.moveDecay;
52
+ particle.velocity.multTo(decay);
53
+ const velocity = particle.velocity.mult(moveSpeed);
54
+ if (gravityOptions?.enable &&
55
+ maxSpeed > 0 &&
56
+ ((!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed) ||
57
+ (gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed))) {
58
+ velocity.y = gravityFactor * maxSpeed;
59
+ if (moveSpeed) {
60
+ particle.velocity.y = velocity.y / moveSpeed;
61
+ }
62
+ }
63
+ const zIndexOptions = particle.options.zIndex, zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate;
64
+ velocity.multTo(zVelocityFactor);
65
+ const { position } = particle;
66
+ position.addTo(velocity);
67
+ if (moveOptions.vibrate) {
68
+ position.x += Math.sin(position.x * Math.cos(position.y));
69
+ position.y += Math.cos(position.y * Math.sin(position.x));
70
+ }
71
+ }
72
+ exports.move = move;
42
73
  function spin(particle, moveSpeed) {
43
74
  const container = particle.container;
44
75
  if (!particle.spin) {
@@ -64,7 +95,6 @@
64
95
  }
65
96
  exports.spin = spin;
66
97
  function applyPath(particle, delta) {
67
- var _a;
68
98
  const particlesOptions = particle.options, pathOptions = particlesOptions.move.path, pathEnabled = pathOptions.enable;
69
99
  if (!pathEnabled) {
70
100
  return;
@@ -73,7 +103,7 @@
73
103
  particle.lastPathTime += delta.value;
74
104
  return;
75
105
  }
76
- const path = (_a = particle.pathGenerator) === null || _a === void 0 ? void 0 : _a.generate(particle);
106
+ const path = particle.pathGenerator?.generate(particle, delta);
77
107
  if (path) {
78
108
  particle.velocity.addTo(path);
79
109
  }
package/umd/index.js CHANGED
@@ -11,8 +11,8 @@
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.loadBaseMover = void 0;
13
13
  const BaseMover_1 = require("./BaseMover");
14
- async function loadBaseMover(engine) {
15
- engine.addMover("base", () => new BaseMover_1.BaseMover());
14
+ async function loadBaseMover(engine, refresh = true) {
15
+ await engine.addMover("base", () => new BaseMover_1.BaseMover(), refresh);
16
16
  }
17
17
  exports.loadBaseMover = loadBaseMover;
18
18
  });