@tsparticles/updater-wobble 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.
package/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  # tsParticles Wobble Updater
4
4
 
5
- [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/tsparticles-updater-wobble/badge)](https://www.jsdelivr.com/package/npm/tsparticles-updater-wobble)
6
- [![npmjs](https://badge.fury.io/js/tsparticles-updater-wobble.svg)](https://www.npmjs.com/package/tsparticles-updater-wobble)
7
- [![npmjs](https://img.shields.io/npm/dt/tsparticles-updater-wobble)](https://www.npmjs.com/package/tsparticles-updater-wobble) [![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-wobble/badge)](https://www.jsdelivr.com/package/npm/@tsparticles/updater-wobble)
6
+ [![npmjs](https://badge.fury.io/js/@tsparticles/updater-wobble.svg)](https://www.npmjs.com/package/@tsparticles/updater-wobble)
7
+ [![npmjs](https://img.shields.io/npm/dt/@tsparticles/updater-wobble)](https://www.npmjs.com/package/@tsparticles/updater-wobble) [![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 wobble 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 loadWobbleUpdater();
29
+ await loadWobbleUpdater(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-wobble
45
+ $ npm install @tsparticles/updater-wobble
46
46
  ```
47
47
 
48
48
  or
49
49
 
50
50
  ```shell
51
- $ yarn add tsparticles-updater-wobble
51
+ $ yarn add @tsparticles/updater-wobble
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 { loadWobbleUpdater } = require("tsparticles-updater-wobble");
57
+ const { tsParticles } = require("@tsparticles/engine");
58
+ const { loadWobbleUpdater } = require("@tsparticles/updater-wobble");
59
59
 
60
- loadWobbleUpdater(tsParticles);
60
+ (async () => {
61
+ await loadWobbleUpdater(tsParticles);
62
+ })();
61
63
  ```
62
64
 
63
65
  or
64
66
 
65
67
  ```javascript
66
- import { tsParticles } from "tsparticles-engine";
67
- import { loadWobbleUpdater } from "tsparticles-updater-wobble";
68
+ import { tsParticles } from "@tsparticles/engine";
69
+ import { loadWobbleUpdater } from "@tsparticles/updater-wobble";
68
70
 
69
- loadWobbleUpdater(tsParticles);
71
+ (async () => {
72
+ await loadWobbleUpdater(tsParticles);
73
+ })();
70
74
  ```
@@ -1,5 +1,5 @@
1
+ import { isNumber, setRangeValue, } from "@tsparticles/engine";
1
2
  import { WobbleSpeed } from "./WobbleSpeed";
2
- import { setRangeValue } from "@tsparticles/engine";
3
3
  export class Wobble {
4
4
  constructor() {
5
5
  this.distance = 5;
@@ -17,7 +17,7 @@ export class Wobble {
17
17
  this.enable = data.enable;
18
18
  }
19
19
  if (data.speed !== undefined) {
20
- if (typeof data.speed === "number") {
20
+ if (isNumber(data.speed)) {
21
21
  this.speed.load({ angle: data.speed });
22
22
  }
23
23
  else {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ export function updateWobble(particle, delta) {
2
+ const { wobble: wobbleOptions } = particle.options, { wobble } = particle;
3
+ if (!wobbleOptions?.enable || !wobble) {
4
+ return;
5
+ }
6
+ const angleSpeed = wobble.angleSpeed * delta.factor, moveSpeed = wobble.moveSpeed * delta.factor, distance = (moveSpeed * ((particle.retina.wobbleDistance ?? 0) * delta.factor)) / (1000 / 60), max = 2 * Math.PI, { position } = particle;
7
+ wobble.angle += angleSpeed;
8
+ if (wobble.angle > max) {
9
+ wobble.angle -= max;
10
+ }
11
+ position.x += distance * Math.cos(wobble.angle);
12
+ position.y += distance * Math.abs(Math.sin(wobble.angle));
13
+ }
@@ -1,27 +1,13 @@
1
- import { getRandom, getRangeValue } from "@tsparticles/engine";
1
+ import { getRandom, getRangeValue, } from "@tsparticles/engine";
2
2
  import { Wobble } from "./Options/Classes/Wobble";
3
- function updateWobble(particle, delta) {
4
- var _a;
5
- const wobble = particle.options.wobble;
6
- if (!(wobble === null || wobble === void 0 ? void 0 : wobble.enable) || !particle.wobble) {
7
- return;
8
- }
9
- const angleSpeed = particle.wobble.angleSpeed * delta.factor, moveSpeed = particle.wobble.moveSpeed * delta.factor, distance = (moveSpeed * (((_a = particle.retina.wobbleDistance) !== null && _a !== void 0 ? _a : 0) * delta.factor)) / (1000 / 60), max = 2 * Math.PI;
10
- particle.wobble.angle += angleSpeed;
11
- if (particle.wobble.angle > max) {
12
- particle.wobble.angle -= max;
13
- }
14
- particle.position.x += distance * Math.cos(particle.wobble.angle);
15
- particle.position.y += distance * Math.abs(Math.sin(particle.wobble.angle));
16
- }
3
+ import { updateWobble } from "./Utils";
17
4
  export class WobbleUpdater {
18
5
  constructor(container) {
19
6
  this.container = container;
20
7
  }
21
8
  init(particle) {
22
- var _a;
23
9
  const wobbleOpt = particle.options.wobble;
24
- if (wobbleOpt === null || wobbleOpt === void 0 ? void 0 : wobbleOpt.enable) {
10
+ if (wobbleOpt?.enable) {
25
11
  particle.wobble = {
26
12
  angle: getRandom() * Math.PI * 2,
27
13
  angleSpeed: getRangeValue(wobbleOpt.speed.angle) / 360,
@@ -35,18 +21,17 @@ export class WobbleUpdater {
35
21
  moveSpeed: 0,
36
22
  };
37
23
  }
38
- particle.retina.wobbleDistance = getRangeValue((_a = wobbleOpt === null || wobbleOpt === void 0 ? void 0 : wobbleOpt.distance) !== null && _a !== void 0 ? _a : 0) * this.container.retina.pixelRatio;
24
+ particle.retina.wobbleDistance = getRangeValue(wobbleOpt?.distance ?? 0) * this.container.retina.pixelRatio;
39
25
  }
40
26
  isEnabled(particle) {
41
- var _a;
42
- return !particle.destroyed && !particle.spawning && !!((_a = particle.options.wobble) === null || _a === void 0 ? void 0 : _a.enable);
27
+ return !particle.destroyed && !particle.spawning && !!particle.options.wobble?.enable;
43
28
  }
44
29
  loadOptions(options, ...sources) {
45
30
  if (!options.wobble) {
46
31
  options.wobble = new Wobble();
47
32
  }
48
33
  for (const source of sources) {
49
- options.wobble.load(source === null || source === void 0 ? void 0 : source.wobble);
34
+ options.wobble.load(source?.wobble);
50
35
  }
51
36
  }
52
37
  update(particle, delta) {
package/browser/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import { WobbleUpdater } from "./WobbleUpdater";
2
- export async function loadWobbleUpdater(engine) {
3
- await engine.addParticleUpdater("wobble", (container) => new WobbleUpdater(container));
2
+ export async function loadWobbleUpdater(engine, refresh = true) {
3
+ await engine.addParticleUpdater("wobble", (container) => new WobbleUpdater(container), refresh);
4
4
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Wobble = void 0;
4
- const WobbleSpeed_1 = require("./WobbleSpeed");
5
4
  const engine_1 = require("@tsparticles/engine");
5
+ const WobbleSpeed_1 = require("./WobbleSpeed");
6
6
  class Wobble {
7
7
  constructor() {
8
8
  this.distance = 5;
@@ -20,7 +20,7 @@ class Wobble {
20
20
  this.enable = data.enable;
21
21
  }
22
22
  if (data.speed !== undefined) {
23
- if (typeof data.speed === "number") {
23
+ if ((0, engine_1.isNumber)(data.speed)) {
24
24
  this.speed.load({ angle: data.speed });
25
25
  }
26
26
  else {
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,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateWobble = void 0;
4
+ function updateWobble(particle, delta) {
5
+ const { wobble: wobbleOptions } = particle.options, { wobble } = particle;
6
+ if (!wobbleOptions?.enable || !wobble) {
7
+ return;
8
+ }
9
+ const angleSpeed = wobble.angleSpeed * delta.factor, moveSpeed = wobble.moveSpeed * delta.factor, distance = (moveSpeed * ((particle.retina.wobbleDistance ?? 0) * delta.factor)) / (1000 / 60), max = 2 * Math.PI, { position } = particle;
10
+ wobble.angle += angleSpeed;
11
+ if (wobble.angle > max) {
12
+ wobble.angle -= max;
13
+ }
14
+ position.x += distance * Math.cos(wobble.angle);
15
+ position.y += distance * Math.abs(Math.sin(wobble.angle));
16
+ }
17
+ exports.updateWobble = updateWobble;
@@ -3,28 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WobbleUpdater = void 0;
4
4
  const engine_1 = require("@tsparticles/engine");
5
5
  const Wobble_1 = require("./Options/Classes/Wobble");
6
- function updateWobble(particle, delta) {
7
- var _a;
8
- const wobble = particle.options.wobble;
9
- if (!(wobble === null || wobble === void 0 ? void 0 : wobble.enable) || !particle.wobble) {
10
- return;
11
- }
12
- const angleSpeed = particle.wobble.angleSpeed * delta.factor, moveSpeed = particle.wobble.moveSpeed * delta.factor, distance = (moveSpeed * (((_a = particle.retina.wobbleDistance) !== null && _a !== void 0 ? _a : 0) * delta.factor)) / (1000 / 60), max = 2 * Math.PI;
13
- particle.wobble.angle += angleSpeed;
14
- if (particle.wobble.angle > max) {
15
- particle.wobble.angle -= max;
16
- }
17
- particle.position.x += distance * Math.cos(particle.wobble.angle);
18
- particle.position.y += distance * Math.abs(Math.sin(particle.wobble.angle));
19
- }
6
+ const Utils_1 = require("./Utils");
20
7
  class WobbleUpdater {
21
8
  constructor(container) {
22
9
  this.container = container;
23
10
  }
24
11
  init(particle) {
25
- var _a;
26
12
  const wobbleOpt = particle.options.wobble;
27
- if (wobbleOpt === null || wobbleOpt === void 0 ? void 0 : wobbleOpt.enable) {
13
+ if (wobbleOpt?.enable) {
28
14
  particle.wobble = {
29
15
  angle: (0, engine_1.getRandom)() * Math.PI * 2,
30
16
  angleSpeed: (0, engine_1.getRangeValue)(wobbleOpt.speed.angle) / 360,
@@ -38,25 +24,24 @@ class WobbleUpdater {
38
24
  moveSpeed: 0,
39
25
  };
40
26
  }
41
- particle.retina.wobbleDistance = (0, engine_1.getRangeValue)((_a = wobbleOpt === null || wobbleOpt === void 0 ? void 0 : wobbleOpt.distance) !== null && _a !== void 0 ? _a : 0) * this.container.retina.pixelRatio;
27
+ particle.retina.wobbleDistance = (0, engine_1.getRangeValue)(wobbleOpt?.distance ?? 0) * this.container.retina.pixelRatio;
42
28
  }
43
29
  isEnabled(particle) {
44
- var _a;
45
- return !particle.destroyed && !particle.spawning && !!((_a = particle.options.wobble) === null || _a === void 0 ? void 0 : _a.enable);
30
+ return !particle.destroyed && !particle.spawning && !!particle.options.wobble?.enable;
46
31
  }
47
32
  loadOptions(options, ...sources) {
48
33
  if (!options.wobble) {
49
34
  options.wobble = new Wobble_1.Wobble();
50
35
  }
51
36
  for (const source of sources) {
52
- options.wobble.load(source === null || source === void 0 ? void 0 : source.wobble);
37
+ options.wobble.load(source?.wobble);
53
38
  }
54
39
  }
55
40
  update(particle, delta) {
56
41
  if (!this.isEnabled(particle)) {
57
42
  return;
58
43
  }
59
- updateWobble(particle, delta);
44
+ (0, Utils_1.updateWobble)(particle, delta);
60
45
  }
61
46
  }
62
47
  exports.WobbleUpdater = WobbleUpdater;
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.loadWobbleUpdater = void 0;
13
4
  const WobbleUpdater_1 = require("./WobbleUpdater");
14
- function loadWobbleUpdater(engine) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- yield engine.addParticleUpdater("wobble", (container) => new WobbleUpdater_1.WobbleUpdater(container));
17
- });
5
+ async function loadWobbleUpdater(engine, refresh = true) {
6
+ await engine.addParticleUpdater("wobble", (container) => new WobbleUpdater_1.WobbleUpdater(container), refresh);
18
7
  }
19
8
  exports.loadWobbleUpdater = loadWobbleUpdater;
@@ -1,5 +1,5 @@
1
+ import { isNumber, setRangeValue, } from "@tsparticles/engine";
1
2
  import { WobbleSpeed } from "./WobbleSpeed";
2
- import { setRangeValue } from "@tsparticles/engine";
3
3
  export class Wobble {
4
4
  constructor() {
5
5
  this.distance = 5;
@@ -17,7 +17,7 @@ export class Wobble {
17
17
  this.enable = data.enable;
18
18
  }
19
19
  if (data.speed !== undefined) {
20
- if (typeof data.speed === "number") {
20
+ if (isNumber(data.speed)) {
21
21
  this.speed.load({ angle: data.speed });
22
22
  }
23
23
  else {
package/esm/Types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/esm/Utils.js ADDED
@@ -0,0 +1,13 @@
1
+ export function updateWobble(particle, delta) {
2
+ const { wobble: wobbleOptions } = particle.options, { wobble } = particle;
3
+ if (!wobbleOptions?.enable || !wobble) {
4
+ return;
5
+ }
6
+ const angleSpeed = wobble.angleSpeed * delta.factor, moveSpeed = wobble.moveSpeed * delta.factor, distance = (moveSpeed * ((particle.retina.wobbleDistance ?? 0) * delta.factor)) / (1000 / 60), max = 2 * Math.PI, { position } = particle;
7
+ wobble.angle += angleSpeed;
8
+ if (wobble.angle > max) {
9
+ wobble.angle -= max;
10
+ }
11
+ position.x += distance * Math.cos(wobble.angle);
12
+ position.y += distance * Math.abs(Math.sin(wobble.angle));
13
+ }
@@ -1,27 +1,13 @@
1
- import { getRandom, getRangeValue } from "@tsparticles/engine";
1
+ import { getRandom, getRangeValue, } from "@tsparticles/engine";
2
2
  import { Wobble } from "./Options/Classes/Wobble";
3
- function updateWobble(particle, delta) {
4
- var _a;
5
- const wobble = particle.options.wobble;
6
- if (!(wobble === null || wobble === void 0 ? void 0 : wobble.enable) || !particle.wobble) {
7
- return;
8
- }
9
- const angleSpeed = particle.wobble.angleSpeed * delta.factor, moveSpeed = particle.wobble.moveSpeed * delta.factor, distance = (moveSpeed * (((_a = particle.retina.wobbleDistance) !== null && _a !== void 0 ? _a : 0) * delta.factor)) / (1000 / 60), max = 2 * Math.PI;
10
- particle.wobble.angle += angleSpeed;
11
- if (particle.wobble.angle > max) {
12
- particle.wobble.angle -= max;
13
- }
14
- particle.position.x += distance * Math.cos(particle.wobble.angle);
15
- particle.position.y += distance * Math.abs(Math.sin(particle.wobble.angle));
16
- }
3
+ import { updateWobble } from "./Utils";
17
4
  export class WobbleUpdater {
18
5
  constructor(container) {
19
6
  this.container = container;
20
7
  }
21
8
  init(particle) {
22
- var _a;
23
9
  const wobbleOpt = particle.options.wobble;
24
- if (wobbleOpt === null || wobbleOpt === void 0 ? void 0 : wobbleOpt.enable) {
10
+ if (wobbleOpt?.enable) {
25
11
  particle.wobble = {
26
12
  angle: getRandom() * Math.PI * 2,
27
13
  angleSpeed: getRangeValue(wobbleOpt.speed.angle) / 360,
@@ -35,18 +21,17 @@ export class WobbleUpdater {
35
21
  moveSpeed: 0,
36
22
  };
37
23
  }
38
- particle.retina.wobbleDistance = getRangeValue((_a = wobbleOpt === null || wobbleOpt === void 0 ? void 0 : wobbleOpt.distance) !== null && _a !== void 0 ? _a : 0) * this.container.retina.pixelRatio;
24
+ particle.retina.wobbleDistance = getRangeValue(wobbleOpt?.distance ?? 0) * this.container.retina.pixelRatio;
39
25
  }
40
26
  isEnabled(particle) {
41
- var _a;
42
- return !particle.destroyed && !particle.spawning && !!((_a = particle.options.wobble) === null || _a === void 0 ? void 0 : _a.enable);
27
+ return !particle.destroyed && !particle.spawning && !!particle.options.wobble?.enable;
43
28
  }
44
29
  loadOptions(options, ...sources) {
45
30
  if (!options.wobble) {
46
31
  options.wobble = new Wobble();
47
32
  }
48
33
  for (const source of sources) {
49
- options.wobble.load(source === null || source === void 0 ? void 0 : source.wobble);
34
+ options.wobble.load(source?.wobble);
50
35
  }
51
36
  }
52
37
  update(particle, delta) {
package/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import { WobbleUpdater } from "./WobbleUpdater";
2
- export async function loadWobbleUpdater(engine) {
3
- await engine.addParticleUpdater("wobble", (container) => new WobbleUpdater(container));
2
+ export async function loadWobbleUpdater(engine, refresh = true) {
3
+ await engine.addParticleUpdater("wobble", (container) => new WobbleUpdater(container), refresh);
4
4
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/updater-wobble",
3
- "version": "3.0.0-alpha.0",
3
+ "version": "3.0.0-beta.0",
4
4
  "description": "tsParticles particles wobble updater",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -73,10 +73,11 @@
73
73
  "unpkg": "tsparticles.updater.wobble.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.0"
81
82
  }
82
- }
83
+ }