@tsparticles/updater-tilt 3.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +70 -0
- package/browser/Options/Classes/Tilt.js +24 -0
- package/browser/Options/Classes/TiltAnimation.js +26 -0
- package/browser/Options/Interfaces/ITilt.js +1 -0
- package/browser/Options/Interfaces/ITiltAnimation.js +1 -0
- package/browser/TiltDirection.js +1 -0
- package/browser/TiltUpdater.js +97 -0
- package/browser/index.js +4 -0
- package/cjs/Options/Classes/Tilt.js +28 -0
- package/cjs/Options/Classes/TiltAnimation.js +30 -0
- package/cjs/Options/Interfaces/ITilt.js +2 -0
- package/cjs/Options/Interfaces/ITiltAnimation.js +2 -0
- package/cjs/TiltDirection.js +2 -0
- package/cjs/TiltUpdater.js +101 -0
- package/cjs/index.js +19 -0
- package/esm/Options/Classes/Tilt.js +24 -0
- package/esm/Options/Classes/TiltAnimation.js +26 -0
- package/esm/Options/Interfaces/ITilt.js +1 -0
- package/esm/Options/Interfaces/ITiltAnimation.js +1 -0
- package/esm/TiltDirection.js +1 -0
- package/esm/TiltUpdater.js +97 -0
- package/esm/index.js +4 -0
- package/package.json +82 -0
- package/report.html +39 -0
- package/tsparticles.updater.tilt.js +263 -0
- package/tsparticles.updater.tilt.min.js +2 -0
- package/tsparticles.updater.tilt.min.js.LICENSE.txt +8 -0
- package/types/Options/Classes/Tilt.d.ts +13 -0
- package/types/Options/Classes/TiltAnimation.d.ts +10 -0
- package/types/Options/Interfaces/ITilt.d.ts +8 -0
- package/types/Options/Interfaces/ITiltAnimation.d.ts +7 -0
- package/types/TiltDirection.d.ts +6 -0
- package/types/TiltUpdater.d.ts +27 -0
- package/types/index.d.ts +2 -0
- package/umd/Options/Classes/Tilt.js +38 -0
- package/umd/Options/Classes/TiltAnimation.js +40 -0
- package/umd/Options/Interfaces/ITilt.js +12 -0
- package/umd/Options/Interfaces/ITiltAnimation.js +12 -0
- package/umd/TiltDirection.js +12 -0
- package/umd/TiltUpdater.js +111 -0
- package/umd/index.js +18 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Matteo Bruni
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
[](https://particles.js.org)
|
|
2
|
+
|
|
3
|
+
# tsParticles Tilt Updater
|
|
4
|
+
|
|
5
|
+
[](https://www.jsdelivr.com/package/npm/tsparticles-updater-tilt)
|
|
6
|
+
[](https://www.npmjs.com/package/tsparticles-updater-tilt)
|
|
7
|
+
[](https://www.npmjs.com/package/tsparticles-updater-tilt) [](https://github.com/sponsors/matteobruni)
|
|
8
|
+
|
|
9
|
+
[tsParticles](https://github.com/matteobruni/tsparticles) updater plugin for tilt animations.
|
|
10
|
+
|
|
11
|
+
## How to use it
|
|
12
|
+
|
|
13
|
+
### CDN / Vanilla JS / jQuery
|
|
14
|
+
|
|
15
|
+
The CDN/Vanilla version JS has one required file in vanilla configuration:
|
|
16
|
+
|
|
17
|
+
Including the `tsparticles.updater.tilt.min.js` file will export the function to load the updater plugin:
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
loadTiltUpdater;
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Usage
|
|
24
|
+
|
|
25
|
+
Once the scripts are loaded you can set up `tsParticles` and the updater plugin like this:
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
(async () => {
|
|
29
|
+
await loadTiltUpdater();
|
|
30
|
+
|
|
31
|
+
await tsParticles.load({
|
|
32
|
+
id: "tsparticles",
|
|
33
|
+
options: {
|
|
34
|
+
/* options */
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
})();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### ESM / CommonJS
|
|
41
|
+
|
|
42
|
+
This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
|
|
43
|
+
|
|
44
|
+
```shell
|
|
45
|
+
$ npm install tsparticles-updater-tilt
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
or
|
|
49
|
+
|
|
50
|
+
```shell
|
|
51
|
+
$ yarn add tsparticles-updater-tilt
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Then you need to import it in the app, like this:
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
const { tsParticles } = require("tsparticles-engine");
|
|
58
|
+
const { loadTiltUpdater } = require("tsparticles-updater-tilt");
|
|
59
|
+
|
|
60
|
+
loadTiltUpdater(tsParticles);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
or
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
import { tsParticles } from "tsparticles-engine";
|
|
67
|
+
import { loadTiltUpdater } from "tsparticles-updater-tilt";
|
|
68
|
+
|
|
69
|
+
loadTiltUpdater(tsParticles);
|
|
70
|
+
```
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TiltAnimation } from "./TiltAnimation";
|
|
2
|
+
import { ValueWithRandom } from "@tsparticles/engine";
|
|
3
|
+
export class Tilt extends ValueWithRandom {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
6
|
+
this.animation = new TiltAnimation();
|
|
7
|
+
this.direction = "clockwise";
|
|
8
|
+
this.enable = false;
|
|
9
|
+
this.value = 0;
|
|
10
|
+
}
|
|
11
|
+
load(data) {
|
|
12
|
+
super.load(data);
|
|
13
|
+
if (!data) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
this.animation.load(data.animation);
|
|
17
|
+
if (data.direction !== undefined) {
|
|
18
|
+
this.direction = data.direction;
|
|
19
|
+
}
|
|
20
|
+
if (data.enable !== undefined) {
|
|
21
|
+
this.enable = data.enable;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { setRangeValue } from "@tsparticles/engine";
|
|
2
|
+
export class TiltAnimation {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.enable = false;
|
|
5
|
+
this.speed = 0;
|
|
6
|
+
this.decay = 0;
|
|
7
|
+
this.sync = false;
|
|
8
|
+
}
|
|
9
|
+
load(data) {
|
|
10
|
+
if (!data) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (data.enable !== undefined) {
|
|
14
|
+
this.enable = data.enable;
|
|
15
|
+
}
|
|
16
|
+
if (data.speed !== undefined) {
|
|
17
|
+
this.speed = setRangeValue(data.speed);
|
|
18
|
+
}
|
|
19
|
+
if (data.decay !== undefined) {
|
|
20
|
+
this.decay = setRangeValue(data.decay);
|
|
21
|
+
}
|
|
22
|
+
if (data.sync !== undefined) {
|
|
23
|
+
this.sync = data.sync;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { getRandom, getRangeValue } from "@tsparticles/engine";
|
|
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
|
+
}
|
|
31
|
+
export class TiltUpdater {
|
|
32
|
+
constructor(container) {
|
|
33
|
+
this.container = container;
|
|
34
|
+
}
|
|
35
|
+
getTransformValues(particle) {
|
|
36
|
+
var _a;
|
|
37
|
+
const tilt = ((_a = particle.tilt) === null || _a === void 0 ? void 0 : _a.enable) && particle.tilt;
|
|
38
|
+
return {
|
|
39
|
+
b: tilt ? Math.cos(tilt.value) * tilt.cosDirection : undefined,
|
|
40
|
+
c: tilt ? Math.sin(tilt.value) * tilt.sinDirection : undefined,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
init(particle) {
|
|
44
|
+
var _a;
|
|
45
|
+
const tiltOptions = particle.options.tilt;
|
|
46
|
+
if (!tiltOptions) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
particle.tilt = {
|
|
50
|
+
enable: tiltOptions.enable,
|
|
51
|
+
value: (getRangeValue(tiltOptions.value) * Math.PI) / 180,
|
|
52
|
+
sinDirection: getRandom() >= 0.5 ? 1 : -1,
|
|
53
|
+
cosDirection: getRandom() >= 0.5 ? 1 : -1,
|
|
54
|
+
};
|
|
55
|
+
let tiltDirection = tiltOptions.direction;
|
|
56
|
+
if (tiltDirection === "random") {
|
|
57
|
+
const index = Math.floor(getRandom() * 2);
|
|
58
|
+
tiltDirection = index > 0 ? "counter-clockwise" : "clockwise";
|
|
59
|
+
}
|
|
60
|
+
switch (tiltDirection) {
|
|
61
|
+
case "counter-clockwise":
|
|
62
|
+
case "counterClockwise":
|
|
63
|
+
particle.tilt.status = "decreasing";
|
|
64
|
+
break;
|
|
65
|
+
case "clockwise":
|
|
66
|
+
particle.tilt.status = "increasing";
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
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) {
|
|
71
|
+
particle.tilt.decay = 1 - getRangeValue(tiltAnimation.decay);
|
|
72
|
+
particle.tilt.velocity = (getRangeValue(tiltAnimation.speed) / 360) * this.container.retina.reduceFactor;
|
|
73
|
+
if (!tiltAnimation.sync) {
|
|
74
|
+
particle.tilt.velocity *= getRandom();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
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);
|
|
82
|
+
}
|
|
83
|
+
loadOptions(options, ...sources) {
|
|
84
|
+
if (!options.tilt) {
|
|
85
|
+
options.tilt = new Tilt();
|
|
86
|
+
}
|
|
87
|
+
for (const source of sources) {
|
|
88
|
+
options.tilt.load(source === null || source === void 0 ? void 0 : source.tilt);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
update(particle, delta) {
|
|
92
|
+
if (!this.isEnabled(particle)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
updateTilt(particle, delta);
|
|
96
|
+
}
|
|
97
|
+
}
|
package/browser/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Tilt = void 0;
|
|
4
|
+
const TiltAnimation_1 = require("./TiltAnimation");
|
|
5
|
+
const engine_1 = require("@tsparticles/engine");
|
|
6
|
+
class Tilt extends engine_1.ValueWithRandom {
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
this.animation = new TiltAnimation_1.TiltAnimation();
|
|
10
|
+
this.direction = "clockwise";
|
|
11
|
+
this.enable = false;
|
|
12
|
+
this.value = 0;
|
|
13
|
+
}
|
|
14
|
+
load(data) {
|
|
15
|
+
super.load(data);
|
|
16
|
+
if (!data) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
this.animation.load(data.animation);
|
|
20
|
+
if (data.direction !== undefined) {
|
|
21
|
+
this.direction = data.direction;
|
|
22
|
+
}
|
|
23
|
+
if (data.enable !== undefined) {
|
|
24
|
+
this.enable = data.enable;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.Tilt = Tilt;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TiltAnimation = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
class TiltAnimation {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.enable = false;
|
|
8
|
+
this.speed = 0;
|
|
9
|
+
this.decay = 0;
|
|
10
|
+
this.sync = false;
|
|
11
|
+
}
|
|
12
|
+
load(data) {
|
|
13
|
+
if (!data) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (data.enable !== undefined) {
|
|
17
|
+
this.enable = data.enable;
|
|
18
|
+
}
|
|
19
|
+
if (data.speed !== undefined) {
|
|
20
|
+
this.speed = (0, engine_1.setRangeValue)(data.speed);
|
|
21
|
+
}
|
|
22
|
+
if (data.decay !== undefined) {
|
|
23
|
+
this.decay = (0, engine_1.setRangeValue)(data.decay);
|
|
24
|
+
}
|
|
25
|
+
if (data.sync !== undefined) {
|
|
26
|
+
this.sync = data.sync;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.TiltAnimation = TiltAnimation;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TiltUpdater = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
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
|
+
}
|
|
34
|
+
class TiltUpdater {
|
|
35
|
+
constructor(container) {
|
|
36
|
+
this.container = container;
|
|
37
|
+
}
|
|
38
|
+
getTransformValues(particle) {
|
|
39
|
+
var _a;
|
|
40
|
+
const tilt = ((_a = particle.tilt) === null || _a === void 0 ? void 0 : _a.enable) && particle.tilt;
|
|
41
|
+
return {
|
|
42
|
+
b: tilt ? Math.cos(tilt.value) * tilt.cosDirection : undefined,
|
|
43
|
+
c: tilt ? Math.sin(tilt.value) * tilt.sinDirection : undefined,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
init(particle) {
|
|
47
|
+
var _a;
|
|
48
|
+
const tiltOptions = particle.options.tilt;
|
|
49
|
+
if (!tiltOptions) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
particle.tilt = {
|
|
53
|
+
enable: tiltOptions.enable,
|
|
54
|
+
value: ((0, engine_1.getRangeValue)(tiltOptions.value) * Math.PI) / 180,
|
|
55
|
+
sinDirection: (0, engine_1.getRandom)() >= 0.5 ? 1 : -1,
|
|
56
|
+
cosDirection: (0, engine_1.getRandom)() >= 0.5 ? 1 : -1,
|
|
57
|
+
};
|
|
58
|
+
let tiltDirection = tiltOptions.direction;
|
|
59
|
+
if (tiltDirection === "random") {
|
|
60
|
+
const index = Math.floor((0, engine_1.getRandom)() * 2);
|
|
61
|
+
tiltDirection = index > 0 ? "counter-clockwise" : "clockwise";
|
|
62
|
+
}
|
|
63
|
+
switch (tiltDirection) {
|
|
64
|
+
case "counter-clockwise":
|
|
65
|
+
case "counterClockwise":
|
|
66
|
+
particle.tilt.status = "decreasing";
|
|
67
|
+
break;
|
|
68
|
+
case "clockwise":
|
|
69
|
+
particle.tilt.status = "increasing";
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
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) {
|
|
74
|
+
particle.tilt.decay = 1 - (0, engine_1.getRangeValue)(tiltAnimation.decay);
|
|
75
|
+
particle.tilt.velocity = ((0, engine_1.getRangeValue)(tiltAnimation.speed) / 360) * this.container.retina.reduceFactor;
|
|
76
|
+
if (!tiltAnimation.sync) {
|
|
77
|
+
particle.tilt.velocity *= (0, engine_1.getRandom)();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
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);
|
|
85
|
+
}
|
|
86
|
+
loadOptions(options, ...sources) {
|
|
87
|
+
if (!options.tilt) {
|
|
88
|
+
options.tilt = new Tilt_1.Tilt();
|
|
89
|
+
}
|
|
90
|
+
for (const source of sources) {
|
|
91
|
+
options.tilt.load(source === null || source === void 0 ? void 0 : source.tilt);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
update(particle, delta) {
|
|
95
|
+
if (!this.isEnabled(particle)) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
updateTilt(particle, delta);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.TiltUpdater = TiltUpdater;
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.loadTiltUpdater = void 0;
|
|
13
|
+
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
|
+
});
|
|
18
|
+
}
|
|
19
|
+
exports.loadTiltUpdater = loadTiltUpdater;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TiltAnimation } from "./TiltAnimation";
|
|
2
|
+
import { ValueWithRandom } from "@tsparticles/engine";
|
|
3
|
+
export class Tilt extends ValueWithRandom {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
6
|
+
this.animation = new TiltAnimation();
|
|
7
|
+
this.direction = "clockwise";
|
|
8
|
+
this.enable = false;
|
|
9
|
+
this.value = 0;
|
|
10
|
+
}
|
|
11
|
+
load(data) {
|
|
12
|
+
super.load(data);
|
|
13
|
+
if (!data) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
this.animation.load(data.animation);
|
|
17
|
+
if (data.direction !== undefined) {
|
|
18
|
+
this.direction = data.direction;
|
|
19
|
+
}
|
|
20
|
+
if (data.enable !== undefined) {
|
|
21
|
+
this.enable = data.enable;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { setRangeValue } from "@tsparticles/engine";
|
|
2
|
+
export class TiltAnimation {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.enable = false;
|
|
5
|
+
this.speed = 0;
|
|
6
|
+
this.decay = 0;
|
|
7
|
+
this.sync = false;
|
|
8
|
+
}
|
|
9
|
+
load(data) {
|
|
10
|
+
if (!data) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (data.enable !== undefined) {
|
|
14
|
+
this.enable = data.enable;
|
|
15
|
+
}
|
|
16
|
+
if (data.speed !== undefined) {
|
|
17
|
+
this.speed = setRangeValue(data.speed);
|
|
18
|
+
}
|
|
19
|
+
if (data.decay !== undefined) {
|
|
20
|
+
this.decay = setRangeValue(data.decay);
|
|
21
|
+
}
|
|
22
|
+
if (data.sync !== undefined) {
|
|
23
|
+
this.sync = data.sync;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { getRandom, getRangeValue } from "@tsparticles/engine";
|
|
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
|
+
}
|
|
31
|
+
export class TiltUpdater {
|
|
32
|
+
constructor(container) {
|
|
33
|
+
this.container = container;
|
|
34
|
+
}
|
|
35
|
+
getTransformValues(particle) {
|
|
36
|
+
var _a;
|
|
37
|
+
const tilt = ((_a = particle.tilt) === null || _a === void 0 ? void 0 : _a.enable) && particle.tilt;
|
|
38
|
+
return {
|
|
39
|
+
b: tilt ? Math.cos(tilt.value) * tilt.cosDirection : undefined,
|
|
40
|
+
c: tilt ? Math.sin(tilt.value) * tilt.sinDirection : undefined,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
init(particle) {
|
|
44
|
+
var _a;
|
|
45
|
+
const tiltOptions = particle.options.tilt;
|
|
46
|
+
if (!tiltOptions) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
particle.tilt = {
|
|
50
|
+
enable: tiltOptions.enable,
|
|
51
|
+
value: (getRangeValue(tiltOptions.value) * Math.PI) / 180,
|
|
52
|
+
sinDirection: getRandom() >= 0.5 ? 1 : -1,
|
|
53
|
+
cosDirection: getRandom() >= 0.5 ? 1 : -1,
|
|
54
|
+
};
|
|
55
|
+
let tiltDirection = tiltOptions.direction;
|
|
56
|
+
if (tiltDirection === "random") {
|
|
57
|
+
const index = Math.floor(getRandom() * 2);
|
|
58
|
+
tiltDirection = index > 0 ? "counter-clockwise" : "clockwise";
|
|
59
|
+
}
|
|
60
|
+
switch (tiltDirection) {
|
|
61
|
+
case "counter-clockwise":
|
|
62
|
+
case "counterClockwise":
|
|
63
|
+
particle.tilt.status = "decreasing";
|
|
64
|
+
break;
|
|
65
|
+
case "clockwise":
|
|
66
|
+
particle.tilt.status = "increasing";
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
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) {
|
|
71
|
+
particle.tilt.decay = 1 - getRangeValue(tiltAnimation.decay);
|
|
72
|
+
particle.tilt.velocity = (getRangeValue(tiltAnimation.speed) / 360) * this.container.retina.reduceFactor;
|
|
73
|
+
if (!tiltAnimation.sync) {
|
|
74
|
+
particle.tilt.velocity *= getRandom();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
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);
|
|
82
|
+
}
|
|
83
|
+
loadOptions(options, ...sources) {
|
|
84
|
+
if (!options.tilt) {
|
|
85
|
+
options.tilt = new Tilt();
|
|
86
|
+
}
|
|
87
|
+
for (const source of sources) {
|
|
88
|
+
options.tilt.load(source === null || source === void 0 ? void 0 : source.tilt);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
update(particle, delta) {
|
|
92
|
+
if (!this.isEnabled(particle)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
updateTilt(particle, delta);
|
|
96
|
+
}
|
|
97
|
+
}
|
package/esm/index.js
ADDED