@tsparticles/updater-tilt 3.0.2 → 3.1.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.
@@ -1,6 +1,6 @@
1
- import { getRandom, getRangeValue, } from "@tsparticles/engine";
1
+ import { degToRad, getRandom, getRangeValue, halfRandom, updateAnimation, } from "@tsparticles/engine";
2
2
  import { Tilt } from "./Options/Classes/Tilt.js";
3
- import { updateTilt } from "./Utils.js";
3
+ const identity = 1, double = 2, doublePI = Math.PI * double, maxAngle = 360;
4
4
  export class TiltUpdater {
5
5
  constructor(container) {
6
6
  this.container = container;
@@ -19,14 +19,16 @@ export class TiltUpdater {
19
19
  }
20
20
  particle.tilt = {
21
21
  enable: tiltOptions.enable,
22
- value: (getRangeValue(tiltOptions.value) * Math.PI) / 180,
23
- sinDirection: getRandom() >= 0.5 ? 1 : -1,
24
- cosDirection: getRandom() >= 0.5 ? 1 : -1,
22
+ value: degToRad(getRangeValue(tiltOptions.value)),
23
+ sinDirection: getRandom() >= halfRandom ? identity : -identity,
24
+ cosDirection: getRandom() >= halfRandom ? identity : -identity,
25
+ min: 0,
26
+ max: doublePI,
25
27
  };
26
28
  let tiltDirection = tiltOptions.direction;
27
29
  if (tiltDirection === "random") {
28
- const index = Math.floor(getRandom() * 2);
29
- tiltDirection = index > 0 ? "counter-clockwise" : "clockwise";
30
+ const index = Math.floor(getRandom() * double), minIndex = 0;
31
+ tiltDirection = index > minIndex ? "counter-clockwise" : "clockwise";
30
32
  }
31
33
  switch (tiltDirection) {
32
34
  case "counter-clockwise":
@@ -39,8 +41,9 @@ export class TiltUpdater {
39
41
  }
40
42
  const tiltAnimation = particle.options.tilt?.animation;
41
43
  if (tiltAnimation?.enable) {
42
- particle.tilt.decay = 1 - getRangeValue(tiltAnimation.decay);
43
- particle.tilt.velocity = (getRangeValue(tiltAnimation.speed) / 360) * this.container.retina.reduceFactor;
44
+ particle.tilt.decay = identity - getRangeValue(tiltAnimation.decay);
45
+ particle.tilt.velocity =
46
+ (getRangeValue(tiltAnimation.speed) / maxAngle) * this.container.retina.reduceFactor;
44
47
  if (!tiltAnimation.sync) {
45
48
  particle.tilt.velocity *= getRandom();
46
49
  }
@@ -59,9 +62,9 @@ export class TiltUpdater {
59
62
  }
60
63
  }
61
64
  update(particle, delta) {
62
- if (!this.isEnabled(particle)) {
65
+ if (!this.isEnabled(particle) || !particle.tilt) {
63
66
  return;
64
67
  }
65
- updateTilt(particle, delta);
68
+ updateAnimation(particle, particle.tilt, false, "none", delta);
66
69
  }
67
70
  }
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TiltUpdater = void 0;
4
4
  const engine_1 = require("@tsparticles/engine");
5
5
  const Tilt_js_1 = require("./Options/Classes/Tilt.js");
6
- const Utils_js_1 = require("./Utils.js");
6
+ const identity = 1, double = 2, doublePI = Math.PI * double, maxAngle = 360;
7
7
  class TiltUpdater {
8
8
  constructor(container) {
9
9
  this.container = container;
@@ -22,14 +22,16 @@ class TiltUpdater {
22
22
  }
23
23
  particle.tilt = {
24
24
  enable: tiltOptions.enable,
25
- value: ((0, engine_1.getRangeValue)(tiltOptions.value) * Math.PI) / 180,
26
- sinDirection: (0, engine_1.getRandom)() >= 0.5 ? 1 : -1,
27
- cosDirection: (0, engine_1.getRandom)() >= 0.5 ? 1 : -1,
25
+ value: (0, engine_1.degToRad)((0, engine_1.getRangeValue)(tiltOptions.value)),
26
+ sinDirection: (0, engine_1.getRandom)() >= engine_1.halfRandom ? identity : -identity,
27
+ cosDirection: (0, engine_1.getRandom)() >= engine_1.halfRandom ? identity : -identity,
28
+ min: 0,
29
+ max: doublePI,
28
30
  };
29
31
  let tiltDirection = tiltOptions.direction;
30
32
  if (tiltDirection === "random") {
31
- const index = Math.floor((0, engine_1.getRandom)() * 2);
32
- tiltDirection = index > 0 ? "counter-clockwise" : "clockwise";
33
+ const index = Math.floor((0, engine_1.getRandom)() * double), minIndex = 0;
34
+ tiltDirection = index > minIndex ? "counter-clockwise" : "clockwise";
33
35
  }
34
36
  switch (tiltDirection) {
35
37
  case "counter-clockwise":
@@ -42,8 +44,9 @@ class TiltUpdater {
42
44
  }
43
45
  const tiltAnimation = particle.options.tilt?.animation;
44
46
  if (tiltAnimation?.enable) {
45
- particle.tilt.decay = 1 - (0, engine_1.getRangeValue)(tiltAnimation.decay);
46
- particle.tilt.velocity = ((0, engine_1.getRangeValue)(tiltAnimation.speed) / 360) * this.container.retina.reduceFactor;
47
+ particle.tilt.decay = identity - (0, engine_1.getRangeValue)(tiltAnimation.decay);
48
+ particle.tilt.velocity =
49
+ ((0, engine_1.getRangeValue)(tiltAnimation.speed) / maxAngle) * this.container.retina.reduceFactor;
47
50
  if (!tiltAnimation.sync) {
48
51
  particle.tilt.velocity *= (0, engine_1.getRandom)();
49
52
  }
@@ -62,10 +65,10 @@ class TiltUpdater {
62
65
  }
63
66
  }
64
67
  update(particle, delta) {
65
- if (!this.isEnabled(particle)) {
68
+ if (!this.isEnabled(particle) || !particle.tilt) {
66
69
  return;
67
70
  }
68
- (0, Utils_js_1.updateTilt)(particle, delta);
71
+ (0, engine_1.updateAnimation)(particle, particle.tilt, false, "none", delta);
69
72
  }
70
73
  }
71
74
  exports.TiltUpdater = TiltUpdater;
@@ -1,6 +1,6 @@
1
- import { getRandom, getRangeValue, } from "@tsparticles/engine";
1
+ import { degToRad, getRandom, getRangeValue, halfRandom, updateAnimation, } from "@tsparticles/engine";
2
2
  import { Tilt } from "./Options/Classes/Tilt.js";
3
- import { updateTilt } from "./Utils.js";
3
+ const identity = 1, double = 2, doublePI = Math.PI * double, maxAngle = 360;
4
4
  export class TiltUpdater {
5
5
  constructor(container) {
6
6
  this.container = container;
@@ -19,14 +19,16 @@ export class TiltUpdater {
19
19
  }
20
20
  particle.tilt = {
21
21
  enable: tiltOptions.enable,
22
- value: (getRangeValue(tiltOptions.value) * Math.PI) / 180,
23
- sinDirection: getRandom() >= 0.5 ? 1 : -1,
24
- cosDirection: getRandom() >= 0.5 ? 1 : -1,
22
+ value: degToRad(getRangeValue(tiltOptions.value)),
23
+ sinDirection: getRandom() >= halfRandom ? identity : -identity,
24
+ cosDirection: getRandom() >= halfRandom ? identity : -identity,
25
+ min: 0,
26
+ max: doublePI,
25
27
  };
26
28
  let tiltDirection = tiltOptions.direction;
27
29
  if (tiltDirection === "random") {
28
- const index = Math.floor(getRandom() * 2);
29
- tiltDirection = index > 0 ? "counter-clockwise" : "clockwise";
30
+ const index = Math.floor(getRandom() * double), minIndex = 0;
31
+ tiltDirection = index > minIndex ? "counter-clockwise" : "clockwise";
30
32
  }
31
33
  switch (tiltDirection) {
32
34
  case "counter-clockwise":
@@ -39,8 +41,9 @@ export class TiltUpdater {
39
41
  }
40
42
  const tiltAnimation = particle.options.tilt?.animation;
41
43
  if (tiltAnimation?.enable) {
42
- particle.tilt.decay = 1 - getRangeValue(tiltAnimation.decay);
43
- particle.tilt.velocity = (getRangeValue(tiltAnimation.speed) / 360) * this.container.retina.reduceFactor;
44
+ particle.tilt.decay = identity - getRangeValue(tiltAnimation.decay);
45
+ particle.tilt.velocity =
46
+ (getRangeValue(tiltAnimation.speed) / maxAngle) * this.container.retina.reduceFactor;
44
47
  if (!tiltAnimation.sync) {
45
48
  particle.tilt.velocity *= getRandom();
46
49
  }
@@ -59,9 +62,9 @@ export class TiltUpdater {
59
62
  }
60
63
  }
61
64
  update(particle, delta) {
62
- if (!this.isEnabled(particle)) {
65
+ if (!this.isEnabled(particle) || !particle.tilt) {
63
66
  return;
64
67
  }
65
- updateTilt(particle, delta);
68
+ updateAnimation(particle, particle.tilt, false, "none", delta);
66
69
  }
67
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/updater-tilt",
3
- "version": "3.0.2",
3
+ "version": "3.1.0",
4
4
  "description": "tsParticles particles tilt updater",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -87,7 +87,7 @@
87
87
  "./package.json": "./package.json"
88
88
  },
89
89
  "dependencies": {
90
- "@tsparticles/engine": "^3.0.2"
90
+ "@tsparticles/engine": "^3.1.0"
91
91
  },
92
92
  "publishConfig": {
93
93
  "access": "public"
package/report.html CHANGED
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <meta charset="UTF-8"/>
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
6
- <title>@tsparticles/updater-tilt [6 Dec 2023 at 17:47]</title>
6
+ <title>@tsparticles/updater-tilt [13 Jan 2024 at 23:09]</title>
7
7
  <link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAABrVBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+O1foceMD///+J0/qK1Pr7/v8Xdr/9///W8P4UdL7L7P0Scr2r4Pyj3vwad8D5/f/2/f+55f3E6f34+/2H0/ojfMKpzOd0rNgQcb3F3O/j9f7c8v6g3Pz0/P/w+v/q+P7n9v6T1/uQ1vuE0vqLut/y+v+Z2fvt+f+15Pzv9fuc2/vR7v2V2Pvd6/bg9P7I6/285/2y4/yp3/zp8vk8i8kqgMT7/P31+fyv4vxGkcz6/P6/6P3j7vfS5PNnpNUxhcbO7f7F6v3O4vHK3/DA2u631Ouy0eqXweKJud5wqthfoNMMbLvY8f73+v2dxeR8sNtTmdDx9/zX6PSjyeaCtd1YnNGX2PuQveCGt95Nls42h8dLlM3F4vBtAAAAM3RSTlMAAyOx0/sKBvik8opWGBMOAe3l1snDm2E9LSb06eHcu5JpHbarfHZCN9CBb08zzkdNS0kYaptYAAAFV0lEQVRYw92X51/aYBDHHS2O2qqttVbrqNq9m+TJIAYIShBkWwqIiCgoWvfeq7Z2/s29hyQNyUcR7LveGwVyXy6XH8/9rqxglLfUPLxVduUor3h0rfp2TYvpivk37929TkG037hffoX0+peVtZQc1589rigVUdXS/ABSAyEmGIO/1XfvldSK8vs3OqB6u3m0nxmIrvgB0dj7rr7Y9IbuF68hnfFaiHA/sxqm0wciIG43P60qKv9WXWc1RXGh/mFESFABTSBi0sNAKzqet17eCtOb3kZIDwxEEU0oAIJGYxNBDhBND29e0rtXXbcpuPmED9IhEAAQ/AXEaF8EPmnrrKsv0LvWR3fg5sWDNAFZOgAgaKvZDogHNU9MFwnnYROkc56RD5CjAbQX9Ow4g7upCsvYu55aSI/Nj0H1akgKQEUM94dwK65hYRmFU9MIcH/fqJYOZYcnuJSU/waKDgTOEVaVKhwrTRP5XzgSpAITYzom7UvkhFX5VutmxeNnWDjjswTKTyfgluNDGbUpWissXhF3s7mlSml+czWkg3D0l1nNjGNjz3myOQOa1KM/jOS6ebdbAVTCi4gljHSFrviza7tOgRWcS0MOUX9zdNgag5w7rRqA44Lzw0hr1WqES36dFliSJFlh2rXIae3FFcDDgKdxrUIDePr8jGcSClV1u7A9xeN0ModY/pHMxmR1EzRh8TJiwqsHmKW0l4FCEZI+jHio+JdPPE9qwQtTRxku2D8sIeRL2LnxWSllANCQGOIiqVHAz2ye2JR0DcH+HoxDkaADLjgxjKQ+AwCX/g0+DNgdG0ukYCONAe+dbc2IAc6fwt1ARoDSezNHxV2Cmzwv3O6lDMV55edBGwGK9n1+x2F8EDfAGCxug8MhpsMEcTEAWf3rx2vZhe/LAmtIn/6apE6PN0ULKgywD9mmdxbmFl3OvD5AS5fW5zLbv/YHmcsBTjf/afDz3MaZTVCfAP9z6/Bw6ycv8EUBWJIn9zYcoAWWlW9+OzO3vkTy8H+RANLmdrpOuYWdZYEXpo+TlCJrW5EARb7fF+bWdqf3hhyZI1nWJQHgznErZhbjoEsWqi8dQNoE294aldzFurwSABL2XXMf9+H1VQGke9exw5P/AnA5Pv5ngMul7LOvO922iwACu8WkCwLCafvM4CeWPxfA8lNHcWZSoi8EwMAIciKX2Z4SWCMAa3snCZ/G4EA8D6CMLNFsGQhkkz/gQNEBbPCbWsxGUpYVu3z8IyNAknwJkfPMEhLyrdi5RTyUVACkw4GSFRNWJNEW+fgPGwHD8/JxnRuLabN4CGNRkAE23na2+VmEAUmrYymSGjMAYqH84YUIyzgzs3XC7gNgH36Vcc4zKY9o9fgPBXUAiHHwVboBHGLiX6Zcjp1f2wu4tvzZKo0ecPnDtQYDQvJXaBeNzce45Fp28ZQLrEZVuFqgBwOalArKXnW1UzlnSusQKJqKYNuz4tOnI6sZG4zanpemv+7ySU2jbA9h6uhcgpfy6G2PahirDZ6zvq6zDduMVFTKvzw8wgyEdelwY9in3XkEPs3osJuwRQ4qTkfzifndg9Gfc4pdsu82+tTnHZTBa2EAMrqr2t43pguc8tNm7JQVQ2S0ukj2d22dhXYP0/veWtwKrCkNoNimAN5+Xr/oLrxswKbVJjteWrX7eR63o4j9q0GxnaBdWgGA5VStpanIjQmEhV0/nVt5VOFUvix6awJhPcAaTEShgrG+iGyvb5a0Ndb1YGHFPEwoqAinoaykaID1o1pdPNu7XsnCKQ3R+hwWIIhGvORcJUBYXe3Xa3vq/mF/N9V13ugufMkfXn+KHsRD0B8AAAAASUVORK5CYII=" type="image/x-icon" />
8
8
 
9
9
  <script>
@@ -31,7 +31,7 @@
31
31
  <body>
32
32
  <div id="app"></div>
33
33
  <script>
34
- window.chartData = [{"label":"tsparticles.updater.tilt.js","isAsset":true,"statSize":4336,"parsedSize":8257,"gzipSize":2369,"groups":[{"label":"dist/browser","path":"./dist/browser","statSize":4294,"groups":[{"id":878,"label":"index.js + 4 modules (concatenated)","path":"./dist/browser/index.js + 4 modules (concatenated)","statSize":4294,"parsedSize":8257,"gzipSize":2369,"concatenated":true,"groups":[{"label":"dist/browser","path":"./dist/browser/index.js + 4 modules (concatenated)/dist/browser","statSize":4294,"groups":[{"id":null,"label":"index.js","path":"./dist/browser/index.js + 4 modules (concatenated)/dist/browser/index.js","statSize":206,"parsedSize":396,"gzipSize":113,"inaccurateSizes":true},{"id":null,"label":"TiltUpdater.js","path":"./dist/browser/index.js + 4 modules (concatenated)/dist/browser/TiltUpdater.js","statSize":2129,"parsedSize":4093,"gzipSize":1174,"inaccurateSizes":true},{"label":"Options/Classes","path":"./dist/browser/index.js + 4 modules (concatenated)/dist/browser/Options/Classes","statSize":1159,"groups":[{"id":null,"label":"Tilt.js","path":"./dist/browser/index.js + 4 modules (concatenated)/dist/browser/Options/Classes/Tilt.js","statSize":588,"parsedSize":1130,"gzipSize":324,"inaccurateSizes":true},{"id":null,"label":"TiltAnimation.js","path":"./dist/browser/index.js + 4 modules (concatenated)/dist/browser/Options/Classes/TiltAnimation.js","statSize":571,"parsedSize":1097,"gzipSize":315,"inaccurateSizes":true}],"parsedSize":2228,"gzipSize":639,"inaccurateSizes":true},{"id":null,"label":"Utils.js","path":"./dist/browser/index.js + 4 modules (concatenated)/dist/browser/Utils.js","statSize":800,"parsedSize":1538,"gzipSize":441,"inaccurateSizes":true}],"parsedSize":8257,"gzipSize":2369,"inaccurateSizes":true}]}],"parsedSize":8257,"gzipSize":2369},{"label":"engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles","path":"./engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles","statSize":42,"groups":[{"id":533,"label":"engine\",\"root\":\"window\"}","path":"./engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles/engine\",\"root\":\"window\"}","statSize":42}],"parsedSize":0,"gzipSize":0}],"isInitialByEntrypoint":{"tsparticles.updater.tilt":true}}];
34
+ window.chartData = [{"label":"tsparticles.updater.tilt.js","isAsset":true,"statSize":3787,"parsedSize":7790,"gzipSize":2274,"groups":[{"label":"dist/browser","path":"./dist/browser","statSize":3745,"groups":[{"id":516,"label":"index.js + 3 modules (concatenated)","path":"./dist/browser/index.js + 3 modules (concatenated)","statSize":3745,"parsedSize":7790,"gzipSize":2274,"concatenated":true,"groups":[{"label":"dist/browser","path":"./dist/browser/index.js + 3 modules (concatenated)/dist/browser","statSize":3745,"groups":[{"id":null,"label":"index.js","path":"./dist/browser/index.js + 3 modules (concatenated)/dist/browser/index.js","statSize":206,"parsedSize":428,"gzipSize":125,"inaccurateSizes":true},{"id":null,"label":"TiltUpdater.js","path":"./dist/browser/index.js + 3 modules (concatenated)/dist/browser/TiltUpdater.js","statSize":2380,"parsedSize":4950,"gzipSize":1445,"inaccurateSizes":true},{"label":"Options/Classes","path":"./dist/browser/index.js + 3 modules (concatenated)/dist/browser/Options/Classes","statSize":1159,"groups":[{"id":null,"label":"Tilt.js","path":"./dist/browser/index.js + 3 modules (concatenated)/dist/browser/Options/Classes/Tilt.js","statSize":588,"parsedSize":1223,"gzipSize":357,"inaccurateSizes":true},{"id":null,"label":"TiltAnimation.js","path":"./dist/browser/index.js + 3 modules (concatenated)/dist/browser/Options/Classes/TiltAnimation.js","statSize":571,"parsedSize":1187,"gzipSize":346,"inaccurateSizes":true}],"parsedSize":2410,"gzipSize":703,"inaccurateSizes":true}],"parsedSize":7790,"gzipSize":2274,"inaccurateSizes":true}]}],"parsedSize":7790,"gzipSize":2274},{"label":"engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles","path":"./engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles","statSize":42,"groups":[{"id":533,"label":"engine\",\"root\":\"window\"}","path":"./engine\",\"commonjs2\":\"@tsparticles/engine\",\"amd\":\"@tsparticles/engine\",\"root\":\"window\"}","statSize":42}],"parsedSize":0,"gzipSize":0}],"isInitialByEntrypoint":{"tsparticles.updater.tilt":true}}];
35
35
  window.entrypoints = ["tsparticles.updater.tilt","tsparticles.updater.tilt.min"];
36
36
  window.defaultSizes = "parsed";
37
37
  </script>
@@ -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.2
7
+ * v3.1.0
8
8
  */
9
9
  (function webpackUniversalModuleDefinition(root, factory) {
10
10
  if(typeof exports === 'object' && typeof module === 'object')
@@ -148,42 +148,13 @@ class Tilt extends engine_root_window_.ValueWithRandom {
148
148
  }
149
149
  }
150
150
  }
151
- ;// CONCATENATED MODULE: ./dist/browser/Utils.js
152
- function updateTilt(particle, delta) {
153
- if (!particle.tilt || !particle.options.tilt) {
154
- return;
155
- }
156
- const tilt = particle.options.tilt,
157
- tiltAnimation = tilt.animation,
158
- speed = (particle.tilt.velocity ?? 0) * delta.factor,
159
- max = 2 * Math.PI,
160
- decay = particle.tilt.decay ?? 1;
161
- if (!tiltAnimation.enable) {
162
- return;
163
- }
164
- switch (particle.tilt.status) {
165
- case "increasing":
166
- particle.tilt.value += speed;
167
- if (particle.tilt.value > max) {
168
- particle.tilt.value -= max;
169
- }
170
- break;
171
- case "decreasing":
172
- default:
173
- particle.tilt.value -= speed;
174
- if (particle.tilt.value < 0) {
175
- particle.tilt.value += max;
176
- }
177
- break;
178
- }
179
- if (particle.tilt.velocity && decay !== 1) {
180
- particle.tilt.velocity *= decay;
181
- }
182
- }
183
151
  ;// CONCATENATED MODULE: ./dist/browser/TiltUpdater.js
184
152
 
185
153
 
186
-
154
+ const identity = 1,
155
+ TiltUpdater_double = 2,
156
+ doublePI = Math.PI * TiltUpdater_double,
157
+ maxAngle = 360;
187
158
  class TiltUpdater {
188
159
  constructor(container) {
189
160
  this.container = container;
@@ -202,14 +173,17 @@ class TiltUpdater {
202
173
  }
203
174
  particle.tilt = {
204
175
  enable: tiltOptions.enable,
205
- value: (0,engine_root_window_.getRangeValue)(tiltOptions.value) * Math.PI / 180,
206
- sinDirection: (0,engine_root_window_.getRandom)() >= 0.5 ? 1 : -1,
207
- cosDirection: (0,engine_root_window_.getRandom)() >= 0.5 ? 1 : -1
176
+ value: (0,engine_root_window_.degToRad)((0,engine_root_window_.getRangeValue)(tiltOptions.value)),
177
+ sinDirection: (0,engine_root_window_.getRandom)() >= engine_root_window_.halfRandom ? identity : -identity,
178
+ cosDirection: (0,engine_root_window_.getRandom)() >= engine_root_window_.halfRandom ? identity : -identity,
179
+ min: 0,
180
+ max: doublePI
208
181
  };
209
182
  let tiltDirection = tiltOptions.direction;
210
183
  if (tiltDirection === "random") {
211
- const index = Math.floor((0,engine_root_window_.getRandom)() * 2);
212
- tiltDirection = index > 0 ? "counter-clockwise" : "clockwise";
184
+ const index = Math.floor((0,engine_root_window_.getRandom)() * TiltUpdater_double),
185
+ minIndex = 0;
186
+ tiltDirection = index > minIndex ? "counter-clockwise" : "clockwise";
213
187
  }
214
188
  switch (tiltDirection) {
215
189
  case "counter-clockwise":
@@ -222,8 +196,8 @@ class TiltUpdater {
222
196
  }
223
197
  const tiltAnimation = particle.options.tilt?.animation;
224
198
  if (tiltAnimation?.enable) {
225
- particle.tilt.decay = 1 - (0,engine_root_window_.getRangeValue)(tiltAnimation.decay);
226
- particle.tilt.velocity = (0,engine_root_window_.getRangeValue)(tiltAnimation.speed) / 360 * this.container.retina.reduceFactor;
199
+ particle.tilt.decay = identity - (0,engine_root_window_.getRangeValue)(tiltAnimation.decay);
200
+ particle.tilt.velocity = (0,engine_root_window_.getRangeValue)(tiltAnimation.speed) / maxAngle * this.container.retina.reduceFactor;
227
201
  if (!tiltAnimation.sync) {
228
202
  particle.tilt.velocity *= (0,engine_root_window_.getRandom)();
229
203
  }
@@ -242,10 +216,10 @@ class TiltUpdater {
242
216
  }
243
217
  }
244
218
  update(particle, delta) {
245
- if (!this.isEnabled(particle)) {
219
+ if (!this.isEnabled(particle) || !particle.tilt) {
246
220
  return;
247
221
  }
248
- updateTilt(particle, delta);
222
+ (0,engine_root_window_.updateAnimation)(particle, particle.tilt, false, "none", delta);
249
223
  }
250
224
  }
251
225
  ;// CONCATENATED MODULE: ./dist/browser/index.js
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see tsparticles.updater.tilt.min.js.LICENSE.txt */
2
- !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],e);else{var i="object"==typeof exports?e(require("@tsparticles/engine")):e(t.window);for(var o in i)("object"==typeof exports?exports:t)[o]=i[o]}}(this,(t=>(()=>{"use strict";var e={533:e=>{e.exports=t}},i={};function o(t){var n=i[t];if(void 0!==n)return n.exports;var a=i[t]={exports:{}};return e[t](a,a.exports,o),a.exports}o.d=(t,e)=>{for(var i in e)o.o(e,i)&&!o.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),o.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{o.r(n),o.d(n,{loadTiltUpdater:()=>s});var t=o(533);class e{constructor(){this.enable=!1,this.speed=0,this.decay=0,this.sync=!1}load(e){e&&(void 0!==e.enable&&(this.enable=e.enable),void 0!==e.speed&&(this.speed=(0,t.setRangeValue)(e.speed)),void 0!==e.decay&&(this.decay=(0,t.setRangeValue)(e.decay)),void 0!==e.sync&&(this.sync=e.sync))}}class i extends t.ValueWithRandom{constructor(){super(),this.animation=new e,this.direction="clockwise",this.enable=!1,this.value=0}load(t){super.load(t),t&&(this.animation.load(t.animation),void 0!==t.direction&&(this.direction=t.direction),void 0!==t.enable&&(this.enable=t.enable))}}class a{constructor(t){this.container=t}getTransformValues(t){const e=t.tilt?.enable&&t.tilt;return{b:e?Math.cos(e.value)*e.cosDirection:void 0,c:e?Math.sin(e.value)*e.sinDirection:void 0}}init(e){const i=e.options.tilt;if(!i)return;e.tilt={enable:i.enable,value:(0,t.getRangeValue)(i.value)*Math.PI/180,sinDirection:(0,t.getRandom)()>=.5?1:-1,cosDirection:(0,t.getRandom)()>=.5?1:-1};let o=i.direction;if("random"===o){o=Math.floor(2*(0,t.getRandom)())>0?"counter-clockwise":"clockwise"}switch(o){case"counter-clockwise":case"counterClockwise":e.tilt.status="decreasing";break;case"clockwise":e.tilt.status="increasing"}const n=e.options.tilt?.animation;n?.enable&&(e.tilt.decay=1-(0,t.getRangeValue)(n.decay),e.tilt.velocity=(0,t.getRangeValue)(n.speed)/360*this.container.retina.reduceFactor,n.sync||(e.tilt.velocity*=(0,t.getRandom)()))}isEnabled(t){const e=t.options.tilt?.animation;return!t.destroyed&&!t.spawning&&!!e?.enable}loadOptions(t,...e){t.tilt||(t.tilt=new i);for(const i of e)t.tilt.load(i?.tilt)}update(t,e){this.isEnabled(t)&&function(t,e){if(!t.tilt||!t.options.tilt)return;const i=t.options.tilt.animation,o=(t.tilt.velocity??0)*e.factor,n=2*Math.PI,a=t.tilt.decay??1;i.enable&&("increasing"===t.tilt.status?(t.tilt.value+=o,t.tilt.value>n&&(t.tilt.value-=n)):(t.tilt.value-=o,t.tilt.value<0&&(t.tilt.value+=n)),t.tilt.velocity&&1!==a&&(t.tilt.velocity*=a))}(t,e)}}async function s(t,e=!0){await t.addParticleUpdater("tilt",(t=>new a(t)),e)}})(),n})()));
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,{loadTiltUpdater:()=>r});var e=n(533);class t{constructor(){this.enable=!1,this.speed=0,this.decay=0,this.sync=!1}load(t){t&&(void 0!==t.enable&&(this.enable=t.enable),void 0!==t.speed&&(this.speed=(0,e.setRangeValue)(t.speed)),void 0!==t.decay&&(this.decay=(0,e.setRangeValue)(t.decay)),void 0!==t.sync&&(this.sync=t.sync))}}class i extends e.ValueWithRandom{constructor(){super(),this.animation=new t,this.direction="clockwise",this.enable=!1,this.value=0}load(e){super.load(e),e&&(this.animation.load(e.animation),void 0!==e.direction&&(this.direction=e.direction),void 0!==e.enable&&(this.enable=e.enable))}}const a=2*Math.PI;class s{constructor(e){this.container=e}getTransformValues(e){const t=e.tilt?.enable&&e.tilt;return{b:t?Math.cos(t.value)*t.cosDirection:void 0,c:t?Math.sin(t.value)*t.sinDirection:void 0}}init(t){const i=t.options.tilt;if(!i)return;t.tilt={enable:i.enable,value:(0,e.degToRad)((0,e.getRangeValue)(i.value)),sinDirection:(0,e.getRandom)()>=e.halfRandom?1:-1,cosDirection:(0,e.getRandom)()>=e.halfRandom?1:-1,min:0,max:a};let n=i.direction;if("random"===n){n=Math.floor(2*(0,e.getRandom)())>0?"counter-clockwise":"clockwise"}switch(n){case"counter-clockwise":case"counterClockwise":t.tilt.status="decreasing";break;case"clockwise":t.tilt.status="increasing"}const o=t.options.tilt?.animation;o?.enable&&(t.tilt.decay=1-(0,e.getRangeValue)(o.decay),t.tilt.velocity=(0,e.getRangeValue)(o.speed)/360*this.container.retina.reduceFactor,o.sync||(t.tilt.velocity*=(0,e.getRandom)()))}isEnabled(e){const t=e.options.tilt?.animation;return!e.destroyed&&!e.spawning&&!!t?.enable}loadOptions(e,...t){e.tilt||(e.tilt=new i);for(const i of t)e.tilt.load(i?.tilt)}update(t,i){this.isEnabled(t)&&t.tilt&&(0,e.updateAnimation)(t,t.tilt,!1,"none",i)}}async function r(e,t=!0){await e.addParticleUpdater("tilt",(e=>new s(e)),t)}})(),o})()));
@@ -1 +1 @@
1
- /*! tsParticles Tilt Updater v3.0.2 by Matteo Bruni */
1
+ /*! tsParticles Tilt Updater v3.1.0 by Matteo Bruni */
@@ -1,8 +1,7 @@
1
1
  import { type IOptionLoader, type RecursivePartial, ValueWithRandom } from "@tsparticles/engine";
2
+ import { TiltDirection, type TiltDirectionAlt } from "../../TiltDirection.js";
2
3
  import type { ITilt } from "../Interfaces/ITilt.js";
3
4
  import { TiltAnimation } from "./TiltAnimation.js";
4
- import { TiltDirection } from "../../TiltDirection.js";
5
- import type { TiltDirectionAlt } from "../../TiltDirection.js";
6
5
  export declare class Tilt extends ValueWithRandom implements ITilt, IOptionLoader<ITilt> {
7
6
  animation: TiltAnimation;
8
7
  direction: TiltDirection | keyof typeof TiltDirection | TiltDirectionAlt;
@@ -1,4 +1,4 @@
1
- import { type Container, type IDelta, type IParticleTransformValues, type IParticleUpdater, type Particle, type RecursivePartial } from "@tsparticles/engine";
1
+ import { type Container, type IDelta, type IParticleTransformValues, type IParticleUpdater, type RecursivePartial } from "@tsparticles/engine";
2
2
  import type { ITiltParticlesOptions, TiltParticle, TiltParticlesOptions } from "./Types.js";
3
3
  export declare class TiltUpdater implements IParticleUpdater {
4
4
  private readonly container;
@@ -7,5 +7,5 @@ export declare class TiltUpdater implements IParticleUpdater {
7
7
  init(particle: TiltParticle): void;
8
8
  isEnabled(particle: TiltParticle): boolean;
9
9
  loadOptions(options: TiltParticlesOptions, ...sources: (RecursivePartial<ITiltParticlesOptions> | undefined)[]): void;
10
- update(particle: Particle, delta: IDelta): void;
10
+ update(particle: TiltParticle, delta: IDelta): void;
11
11
  }
package/types/Types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { IParticleValueAnimation, IParticlesOptions, Particle, ParticlesOptions } from "@tsparticles/engine";
1
+ import type { IParticleNumericValueAnimation, IParticlesOptions, Particle, ParticlesOptions } from "@tsparticles/engine";
2
2
  import type { ITilt } from "./Options/Interfaces/ITilt.js";
3
3
  import type { Tilt } from "./Options/Classes/Tilt.js";
4
- export interface IParticleTiltValueAnimation extends IParticleValueAnimation<number> {
4
+ export interface IParticleTiltValueAnimation extends IParticleNumericValueAnimation {
5
5
  cosDirection: number;
6
6
  sinDirection: number;
7
7
  }
@@ -4,7 +4,7 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "@tsparticles/engine", "./Options/Classes/Tilt.js", "./Utils.js"], factory);
7
+ define(["require", "exports", "@tsparticles/engine", "./Options/Classes/Tilt.js"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
@@ -12,7 +12,7 @@
12
12
  exports.TiltUpdater = void 0;
13
13
  const engine_1 = require("@tsparticles/engine");
14
14
  const Tilt_js_1 = require("./Options/Classes/Tilt.js");
15
- const Utils_js_1 = require("./Utils.js");
15
+ const identity = 1, double = 2, doublePI = Math.PI * double, maxAngle = 360;
16
16
  class TiltUpdater {
17
17
  constructor(container) {
18
18
  this.container = container;
@@ -31,14 +31,16 @@
31
31
  }
32
32
  particle.tilt = {
33
33
  enable: tiltOptions.enable,
34
- value: ((0, engine_1.getRangeValue)(tiltOptions.value) * Math.PI) / 180,
35
- sinDirection: (0, engine_1.getRandom)() >= 0.5 ? 1 : -1,
36
- cosDirection: (0, engine_1.getRandom)() >= 0.5 ? 1 : -1,
34
+ value: (0, engine_1.degToRad)((0, engine_1.getRangeValue)(tiltOptions.value)),
35
+ sinDirection: (0, engine_1.getRandom)() >= engine_1.halfRandom ? identity : -identity,
36
+ cosDirection: (0, engine_1.getRandom)() >= engine_1.halfRandom ? identity : -identity,
37
+ min: 0,
38
+ max: doublePI,
37
39
  };
38
40
  let tiltDirection = tiltOptions.direction;
39
41
  if (tiltDirection === "random") {
40
- const index = Math.floor((0, engine_1.getRandom)() * 2);
41
- tiltDirection = index > 0 ? "counter-clockwise" : "clockwise";
42
+ const index = Math.floor((0, engine_1.getRandom)() * double), minIndex = 0;
43
+ tiltDirection = index > minIndex ? "counter-clockwise" : "clockwise";
42
44
  }
43
45
  switch (tiltDirection) {
44
46
  case "counter-clockwise":
@@ -51,8 +53,9 @@
51
53
  }
52
54
  const tiltAnimation = particle.options.tilt?.animation;
53
55
  if (tiltAnimation?.enable) {
54
- particle.tilt.decay = 1 - (0, engine_1.getRangeValue)(tiltAnimation.decay);
55
- particle.tilt.velocity = ((0, engine_1.getRangeValue)(tiltAnimation.speed) / 360) * this.container.retina.reduceFactor;
56
+ particle.tilt.decay = identity - (0, engine_1.getRangeValue)(tiltAnimation.decay);
57
+ particle.tilt.velocity =
58
+ ((0, engine_1.getRangeValue)(tiltAnimation.speed) / maxAngle) * this.container.retina.reduceFactor;
56
59
  if (!tiltAnimation.sync) {
57
60
  particle.tilt.velocity *= (0, engine_1.getRandom)();
58
61
  }
@@ -71,10 +74,10 @@
71
74
  }
72
75
  }
73
76
  update(particle, delta) {
74
- if (!this.isEnabled(particle)) {
77
+ if (!this.isEnabled(particle) || !particle.tilt) {
75
78
  return;
76
79
  }
77
- (0, Utils_js_1.updateTilt)(particle, delta);
80
+ (0, engine_1.updateAnimation)(particle, particle.tilt, false, "none", delta);
78
81
  }
79
82
  }
80
83
  exports.TiltUpdater = TiltUpdater;
package/browser/Utils.js DELETED
@@ -1,27 +0,0 @@
1
- export function updateTilt(particle, delta) {
2
- if (!particle.tilt || !particle.options.tilt) {
3
- return;
4
- }
5
- const tilt = particle.options.tilt, tiltAnimation = tilt.animation, speed = (particle.tilt.velocity ?? 0) * delta.factor, max = 2 * Math.PI, decay = particle.tilt.decay ?? 1;
6
- if (!tiltAnimation.enable) {
7
- return;
8
- }
9
- switch (particle.tilt.status) {
10
- case "increasing":
11
- particle.tilt.value += speed;
12
- if (particle.tilt.value > max) {
13
- particle.tilt.value -= max;
14
- }
15
- break;
16
- case "decreasing":
17
- default:
18
- particle.tilt.value -= speed;
19
- if (particle.tilt.value < 0) {
20
- particle.tilt.value += max;
21
- }
22
- break;
23
- }
24
- if (particle.tilt.velocity && decay !== 1) {
25
- particle.tilt.velocity *= decay;
26
- }
27
- }
package/cjs/Utils.js DELETED
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateTilt = void 0;
4
- function updateTilt(particle, delta) {
5
- if (!particle.tilt || !particle.options.tilt) {
6
- return;
7
- }
8
- const tilt = particle.options.tilt, tiltAnimation = tilt.animation, speed = (particle.tilt.velocity ?? 0) * delta.factor, max = 2 * Math.PI, decay = particle.tilt.decay ?? 1;
9
- if (!tiltAnimation.enable) {
10
- return;
11
- }
12
- switch (particle.tilt.status) {
13
- case "increasing":
14
- particle.tilt.value += speed;
15
- if (particle.tilt.value > max) {
16
- particle.tilt.value -= max;
17
- }
18
- break;
19
- case "decreasing":
20
- default:
21
- particle.tilt.value -= speed;
22
- if (particle.tilt.value < 0) {
23
- particle.tilt.value += max;
24
- }
25
- break;
26
- }
27
- if (particle.tilt.velocity && decay !== 1) {
28
- particle.tilt.velocity *= decay;
29
- }
30
- }
31
- exports.updateTilt = updateTilt;
package/esm/Utils.js DELETED
@@ -1,27 +0,0 @@
1
- export function updateTilt(particle, delta) {
2
- if (!particle.tilt || !particle.options.tilt) {
3
- return;
4
- }
5
- const tilt = particle.options.tilt, tiltAnimation = tilt.animation, speed = (particle.tilt.velocity ?? 0) * delta.factor, max = 2 * Math.PI, decay = particle.tilt.decay ?? 1;
6
- if (!tiltAnimation.enable) {
7
- return;
8
- }
9
- switch (particle.tilt.status) {
10
- case "increasing":
11
- particle.tilt.value += speed;
12
- if (particle.tilt.value > max) {
13
- particle.tilt.value -= max;
14
- }
15
- break;
16
- case "decreasing":
17
- default:
18
- particle.tilt.value -= speed;
19
- if (particle.tilt.value < 0) {
20
- particle.tilt.value += max;
21
- }
22
- break;
23
- }
24
- if (particle.tilt.velocity && decay !== 1) {
25
- particle.tilt.velocity *= decay;
26
- }
27
- }
package/types/Utils.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { type IDelta } from "@tsparticles/engine";
2
- import type { TiltParticle } from "./Types.js";
3
- export declare function updateTilt(particle: TiltParticle, delta: IDelta): void;
package/umd/Utils.js DELETED
@@ -1,41 +0,0 @@
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
- exports.updateTilt = void 0;
13
- function updateTilt(particle, delta) {
14
- if (!particle.tilt || !particle.options.tilt) {
15
- return;
16
- }
17
- const tilt = particle.options.tilt, tiltAnimation = tilt.animation, speed = (particle.tilt.velocity ?? 0) * delta.factor, max = 2 * Math.PI, decay = particle.tilt.decay ?? 1;
18
- if (!tiltAnimation.enable) {
19
- return;
20
- }
21
- switch (particle.tilt.status) {
22
- case "increasing":
23
- particle.tilt.value += speed;
24
- if (particle.tilt.value > max) {
25
- particle.tilt.value -= max;
26
- }
27
- break;
28
- case "decreasing":
29
- default:
30
- particle.tilt.value -= speed;
31
- if (particle.tilt.value < 0) {
32
- particle.tilt.value += max;
33
- }
34
- break;
35
- }
36
- if (particle.tilt.velocity && decay !== 1) {
37
- particle.tilt.velocity *= decay;
38
- }
39
- }
40
- exports.updateTilt = updateTilt;
41
- });