@tsparticles/updater-tilt 3.0.0-alpha.1 → 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.
package/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  # tsParticles Tilt Updater
4
4
 
5
- [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/tsparticles-updater-tilt/badge)](https://www.jsdelivr.com/package/npm/tsparticles-updater-tilt)
6
- [![npmjs](https://badge.fury.io/js/tsparticles-updater-tilt.svg)](https://www.npmjs.com/package/tsparticles-updater-tilt)
7
- [![npmjs](https://img.shields.io/npm/dt/tsparticles-updater-tilt)](https://www.npmjs.com/package/tsparticles-updater-tilt) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
5
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/@tsparticles/updater-tilt/badge)](https://www.jsdelivr.com/package/npm/@tsparticles/updater-tilt)
6
+ [![npmjs](https://badge.fury.io/js/@tsparticles/updater-tilt.svg)](https://www.npmjs.com/package/@tsparticles/updater-tilt)
7
+ [![npmjs](https://img.shields.io/npm/dt/@tsparticles/updater-tilt)](https://www.npmjs.com/package/@tsparticles/updater-tilt) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
8
8
 
9
9
  [tsParticles](https://github.com/matteobruni/tsparticles) updater plugin for tilt animations.
10
10
 
@@ -26,7 +26,7 @@ Once the scripts are loaded you can set up `tsParticles` and the updater plugin
26
26
 
27
27
  ```javascript
28
28
  (async () => {
29
- await loadTiltUpdater();
29
+ await loadTiltUpdater(tsParticles);
30
30
 
31
31
  await tsParticles.load({
32
32
  id: "tsparticles",
@@ -42,29 +42,33 @@ Once the scripts are loaded you can set up `tsParticles` and the updater plugin
42
42
  This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
43
43
 
44
44
  ```shell
45
- $ npm install tsparticles-updater-tilt
45
+ $ npm install @tsparticles/updater-tilt
46
46
  ```
47
47
 
48
48
  or
49
49
 
50
50
  ```shell
51
- $ yarn add tsparticles-updater-tilt
51
+ $ yarn add @tsparticles/updater-tilt
52
52
  ```
53
53
 
54
54
  Then you need to import it in the app, like this:
55
55
 
56
56
  ```javascript
57
- const { tsParticles } = require("tsparticles-engine");
58
- const { loadTiltUpdater } = require("tsparticles-updater-tilt");
57
+ const { tsParticles } = require("@tsparticles/engine");
58
+ const { loadTiltUpdater } = require("@tsparticles/updater-tilt");
59
59
 
60
- loadTiltUpdater(tsParticles);
60
+ (async () => {
61
+ await loadTiltUpdater(tsParticles);
62
+ })();
61
63
  ```
62
64
 
63
65
  or
64
66
 
65
67
  ```javascript
66
- import { tsParticles } from "tsparticles-engine";
67
- import { loadTiltUpdater } from "tsparticles-updater-tilt";
68
+ import { tsParticles } from "@tsparticles/engine";
69
+ import { loadTiltUpdater } from "@tsparticles/updater-tilt";
68
70
 
69
- loadTiltUpdater(tsParticles);
71
+ (async () => {
72
+ await loadTiltUpdater(tsParticles);
73
+ })();
70
74
  ```
@@ -1,5 +1,5 @@
1
- import { TiltAnimation } from "./TiltAnimation";
2
1
  import { ValueWithRandom } from "@tsparticles/engine";
2
+ import { TiltAnimation } from "./TiltAnimation";
3
3
  export class Tilt extends ValueWithRandom {
4
4
  constructor() {
5
5
  super();
@@ -1,47 +1,18 @@
1
- import { getRandom, getRangeValue } from "@tsparticles/engine";
1
+ import { getRandom, getRangeValue, } from "@tsparticles/engine";
2
2
  import { Tilt } from "./Options/Classes/Tilt";
3
- function updateTilt(particle, delta) {
4
- var _a, _b;
5
- if (!particle.tilt || !particle.options.tilt) {
6
- return;
7
- }
8
- const tilt = particle.options.tilt, tiltAnimation = tilt.animation, speed = ((_a = particle.tilt.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor, max = 2 * Math.PI, decay = (_b = particle.tilt.decay) !== null && _b !== void 0 ? _b : 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
- }
3
+ import { updateTilt } from "./Utils";
31
4
  export class TiltUpdater {
32
5
  constructor(container) {
33
6
  this.container = container;
34
7
  }
35
8
  getTransformValues(particle) {
36
- var _a;
37
- const tilt = ((_a = particle.tilt) === null || _a === void 0 ? void 0 : _a.enable) && particle.tilt;
9
+ const tilt = particle.tilt?.enable && particle.tilt;
38
10
  return {
39
11
  b: tilt ? Math.cos(tilt.value) * tilt.cosDirection : undefined,
40
12
  c: tilt ? Math.sin(tilt.value) * tilt.sinDirection : undefined,
41
13
  };
42
14
  }
43
15
  init(particle) {
44
- var _a;
45
16
  const tiltOptions = particle.options.tilt;
46
17
  if (!tiltOptions) {
47
18
  return;
@@ -66,8 +37,8 @@ export class TiltUpdater {
66
37
  particle.tilt.status = "increasing";
67
38
  break;
68
39
  }
69
- const tiltAnimation = (_a = particle.options.tilt) === null || _a === void 0 ? void 0 : _a.animation;
70
- if (tiltAnimation === null || tiltAnimation === void 0 ? void 0 : tiltAnimation.enable) {
40
+ const tiltAnimation = particle.options.tilt?.animation;
41
+ if (tiltAnimation?.enable) {
71
42
  particle.tilt.decay = 1 - getRangeValue(tiltAnimation.decay);
72
43
  particle.tilt.velocity = (getRangeValue(tiltAnimation.speed) / 360) * this.container.retina.reduceFactor;
73
44
  if (!tiltAnimation.sync) {
@@ -76,16 +47,15 @@ export class TiltUpdater {
76
47
  }
77
48
  }
78
49
  isEnabled(particle) {
79
- var _a;
80
- const tiltAnimation = (_a = particle.options.tilt) === null || _a === void 0 ? void 0 : _a.animation;
81
- return !particle.destroyed && !particle.spawning && !!(tiltAnimation === null || tiltAnimation === void 0 ? void 0 : tiltAnimation.enable);
50
+ const tiltAnimation = particle.options.tilt?.animation;
51
+ return !particle.destroyed && !particle.spawning && !!tiltAnimation?.enable;
82
52
  }
83
53
  loadOptions(options, ...sources) {
84
54
  if (!options.tilt) {
85
55
  options.tilt = new Tilt();
86
56
  }
87
57
  for (const source of sources) {
88
- options.tilt.load(source === null || source === void 0 ? void 0 : source.tilt);
58
+ options.tilt.load(source?.tilt);
89
59
  }
90
60
  }
91
61
  update(particle, delta) {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
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/browser/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import { TiltUpdater } from "./TiltUpdater";
2
- export async function loadTiltUpdater(engine) {
3
- await engine.addParticleUpdater("tilt", (container) => new TiltUpdater(container));
2
+ export async function loadTiltUpdater(engine, refresh = true) {
3
+ await engine.addParticleUpdater("tilt", (container) => new TiltUpdater(container), refresh);
4
4
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Tilt = void 0;
4
- const TiltAnimation_1 = require("./TiltAnimation");
5
4
  const engine_1 = require("@tsparticles/engine");
5
+ const TiltAnimation_1 = require("./TiltAnimation");
6
6
  class Tilt extends engine_1.ValueWithRandom {
7
7
  constructor() {
8
8
  super();
@@ -3,48 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TiltUpdater = void 0;
4
4
  const engine_1 = require("@tsparticles/engine");
5
5
  const Tilt_1 = require("./Options/Classes/Tilt");
6
- function updateTilt(particle, delta) {
7
- var _a, _b;
8
- if (!particle.tilt || !particle.options.tilt) {
9
- return;
10
- }
11
- const tilt = particle.options.tilt, tiltAnimation = tilt.animation, speed = ((_a = particle.tilt.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor, max = 2 * Math.PI, decay = (_b = particle.tilt.decay) !== null && _b !== void 0 ? _b : 1;
12
- if (!tiltAnimation.enable) {
13
- return;
14
- }
15
- switch (particle.tilt.status) {
16
- case "increasing":
17
- particle.tilt.value += speed;
18
- if (particle.tilt.value > max) {
19
- particle.tilt.value -= max;
20
- }
21
- break;
22
- case "decreasing":
23
- default:
24
- particle.tilt.value -= speed;
25
- if (particle.tilt.value < 0) {
26
- particle.tilt.value += max;
27
- }
28
- break;
29
- }
30
- if (particle.tilt.velocity && decay !== 1) {
31
- particle.tilt.velocity *= decay;
32
- }
33
- }
6
+ const Utils_1 = require("./Utils");
34
7
  class TiltUpdater {
35
8
  constructor(container) {
36
9
  this.container = container;
37
10
  }
38
11
  getTransformValues(particle) {
39
- var _a;
40
- const tilt = ((_a = particle.tilt) === null || _a === void 0 ? void 0 : _a.enable) && particle.tilt;
12
+ const tilt = particle.tilt?.enable && particle.tilt;
41
13
  return {
42
14
  b: tilt ? Math.cos(tilt.value) * tilt.cosDirection : undefined,
43
15
  c: tilt ? Math.sin(tilt.value) * tilt.sinDirection : undefined,
44
16
  };
45
17
  }
46
18
  init(particle) {
47
- var _a;
48
19
  const tiltOptions = particle.options.tilt;
49
20
  if (!tiltOptions) {
50
21
  return;
@@ -69,8 +40,8 @@ class TiltUpdater {
69
40
  particle.tilt.status = "increasing";
70
41
  break;
71
42
  }
72
- const tiltAnimation = (_a = particle.options.tilt) === null || _a === void 0 ? void 0 : _a.animation;
73
- if (tiltAnimation === null || tiltAnimation === void 0 ? void 0 : tiltAnimation.enable) {
43
+ const tiltAnimation = particle.options.tilt?.animation;
44
+ if (tiltAnimation?.enable) {
74
45
  particle.tilt.decay = 1 - (0, engine_1.getRangeValue)(tiltAnimation.decay);
75
46
  particle.tilt.velocity = ((0, engine_1.getRangeValue)(tiltAnimation.speed) / 360) * this.container.retina.reduceFactor;
76
47
  if (!tiltAnimation.sync) {
@@ -79,23 +50,22 @@ class TiltUpdater {
79
50
  }
80
51
  }
81
52
  isEnabled(particle) {
82
- var _a;
83
- const tiltAnimation = (_a = particle.options.tilt) === null || _a === void 0 ? void 0 : _a.animation;
84
- return !particle.destroyed && !particle.spawning && !!(tiltAnimation === null || tiltAnimation === void 0 ? void 0 : tiltAnimation.enable);
53
+ const tiltAnimation = particle.options.tilt?.animation;
54
+ return !particle.destroyed && !particle.spawning && !!tiltAnimation?.enable;
85
55
  }
86
56
  loadOptions(options, ...sources) {
87
57
  if (!options.tilt) {
88
58
  options.tilt = new Tilt_1.Tilt();
89
59
  }
90
60
  for (const source of sources) {
91
- options.tilt.load(source === null || source === void 0 ? void 0 : source.tilt);
61
+ options.tilt.load(source?.tilt);
92
62
  }
93
63
  }
94
64
  update(particle, delta) {
95
65
  if (!this.isEnabled(particle)) {
96
66
  return;
97
67
  }
98
- updateTilt(particle, delta);
68
+ (0, Utils_1.updateTilt)(particle, delta);
99
69
  }
100
70
  }
101
71
  exports.TiltUpdater = TiltUpdater;
package/cjs/Types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/Utils.js ADDED
@@ -0,0 +1,31 @@
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/cjs/index.js CHANGED
@@ -1,19 +1,8 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.loadTiltUpdater = void 0;
13
4
  const TiltUpdater_1 = require("./TiltUpdater");
14
- function loadTiltUpdater(engine) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- yield engine.addParticleUpdater("tilt", (container) => new TiltUpdater_1.TiltUpdater(container));
17
- });
5
+ async function loadTiltUpdater(engine, refresh = true) {
6
+ await engine.addParticleUpdater("tilt", (container) => new TiltUpdater_1.TiltUpdater(container), refresh);
18
7
  }
19
8
  exports.loadTiltUpdater = loadTiltUpdater;
@@ -1,5 +1,5 @@
1
- import { TiltAnimation } from "./TiltAnimation";
2
1
  import { ValueWithRandom } from "@tsparticles/engine";
2
+ import { TiltAnimation } from "./TiltAnimation";
3
3
  export class Tilt extends ValueWithRandom {
4
4
  constructor() {
5
5
  super();
@@ -1,47 +1,18 @@
1
- import { getRandom, getRangeValue } from "@tsparticles/engine";
1
+ import { getRandom, getRangeValue, } from "@tsparticles/engine";
2
2
  import { Tilt } from "./Options/Classes/Tilt";
3
- function updateTilt(particle, delta) {
4
- var _a, _b;
5
- if (!particle.tilt || !particle.options.tilt) {
6
- return;
7
- }
8
- const tilt = particle.options.tilt, tiltAnimation = tilt.animation, speed = ((_a = particle.tilt.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor, max = 2 * Math.PI, decay = (_b = particle.tilt.decay) !== null && _b !== void 0 ? _b : 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
- }
3
+ import { updateTilt } from "./Utils";
31
4
  export class TiltUpdater {
32
5
  constructor(container) {
33
6
  this.container = container;
34
7
  }
35
8
  getTransformValues(particle) {
36
- var _a;
37
- const tilt = ((_a = particle.tilt) === null || _a === void 0 ? void 0 : _a.enable) && particle.tilt;
9
+ const tilt = particle.tilt?.enable && particle.tilt;
38
10
  return {
39
11
  b: tilt ? Math.cos(tilt.value) * tilt.cosDirection : undefined,
40
12
  c: tilt ? Math.sin(tilt.value) * tilt.sinDirection : undefined,
41
13
  };
42
14
  }
43
15
  init(particle) {
44
- var _a;
45
16
  const tiltOptions = particle.options.tilt;
46
17
  if (!tiltOptions) {
47
18
  return;
@@ -66,8 +37,8 @@ export class TiltUpdater {
66
37
  particle.tilt.status = "increasing";
67
38
  break;
68
39
  }
69
- const tiltAnimation = (_a = particle.options.tilt) === null || _a === void 0 ? void 0 : _a.animation;
70
- if (tiltAnimation === null || tiltAnimation === void 0 ? void 0 : tiltAnimation.enable) {
40
+ const tiltAnimation = particle.options.tilt?.animation;
41
+ if (tiltAnimation?.enable) {
71
42
  particle.tilt.decay = 1 - getRangeValue(tiltAnimation.decay);
72
43
  particle.tilt.velocity = (getRangeValue(tiltAnimation.speed) / 360) * this.container.retina.reduceFactor;
73
44
  if (!tiltAnimation.sync) {
@@ -76,16 +47,15 @@ export class TiltUpdater {
76
47
  }
77
48
  }
78
49
  isEnabled(particle) {
79
- var _a;
80
- const tiltAnimation = (_a = particle.options.tilt) === null || _a === void 0 ? void 0 : _a.animation;
81
- return !particle.destroyed && !particle.spawning && !!(tiltAnimation === null || tiltAnimation === void 0 ? void 0 : tiltAnimation.enable);
50
+ const tiltAnimation = particle.options.tilt?.animation;
51
+ return !particle.destroyed && !particle.spawning && !!tiltAnimation?.enable;
82
52
  }
83
53
  loadOptions(options, ...sources) {
84
54
  if (!options.tilt) {
85
55
  options.tilt = new Tilt();
86
56
  }
87
57
  for (const source of sources) {
88
- options.tilt.load(source === null || source === void 0 ? void 0 : source.tilt);
58
+ options.tilt.load(source?.tilt);
89
59
  }
90
60
  }
91
61
  update(particle, delta) {
package/esm/Types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/esm/Utils.js ADDED
@@ -0,0 +1,27 @@
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/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import { TiltUpdater } from "./TiltUpdater";
2
- export async function loadTiltUpdater(engine) {
3
- await engine.addParticleUpdater("tilt", (container) => new TiltUpdater(container));
2
+ export async function loadTiltUpdater(engine, refresh = true) {
3
+ await engine.addParticleUpdater("tilt", (container) => new TiltUpdater(container), refresh);
4
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/updater-tilt",
3
- "version": "3.0.0-alpha.1",
3
+ "version": "3.0.0-beta.0",
4
4
  "description": "tsParticles particles tilt updater",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -73,10 +73,11 @@
73
73
  "unpkg": "tsparticles.updater.tilt.min.js",
74
74
  "module": "esm/index.js",
75
75
  "types": "types/index.d.ts",
76
+ "sideEffects": false,
77
+ "dependencies": {
78
+ "@tsparticles/engine": "^3.0.0-beta.0"
79
+ },
76
80
  "publishConfig": {
77
81
  "access": "public"
78
- },
79
- "dependencies": {
80
- "@tsparticles/engine": "^3.0.0-alpha.1"
81
82
  }
82
- }
83
+ }