@tsparticles/updater-roll 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/Roll.js +30 -0
- package/browser/Options/Classes/RollLight.js +18 -0
- package/browser/Options/Interfaces/IRoll.js +1 -0
- package/browser/Options/Interfaces/IRollLight.js +1 -0
- package/browser/RollMode.js +1 -0
- package/browser/RollUpdater.js +84 -0
- package/browser/index.js +4 -0
- package/cjs/Options/Classes/Roll.js +34 -0
- package/cjs/Options/Classes/RollLight.js +22 -0
- package/cjs/Options/Interfaces/IRoll.js +2 -0
- package/cjs/Options/Interfaces/IRollLight.js +2 -0
- package/cjs/RollMode.js +2 -0
- package/cjs/RollUpdater.js +88 -0
- package/cjs/index.js +19 -0
- package/esm/Options/Classes/Roll.js +30 -0
- package/esm/Options/Classes/RollLight.js +18 -0
- package/esm/Options/Interfaces/IRoll.js +1 -0
- package/esm/Options/Interfaces/IRollLight.js +1 -0
- package/esm/RollMode.js +1 -0
- package/esm/RollUpdater.js +84 -0
- package/esm/index.js +4 -0
- package/package.json +82 -0
- package/report.html +39 -0
- package/tsparticles.updater.roll.js +243 -0
- package/tsparticles.updater.roll.min.js +2 -0
- package/tsparticles.updater.roll.min.js.LICENSE.txt +8 -0
- package/types/Options/Classes/Roll.d.ts +15 -0
- package/types/Options/Classes/RollLight.d.ts +8 -0
- package/types/Options/Interfaces/IRoll.d.ts +11 -0
- package/types/Options/Interfaces/IRollLight.d.ts +5 -0
- package/types/RollMode.d.ts +5 -0
- package/types/RollUpdater.d.ts +20 -0
- package/types/index.d.ts +2 -0
- package/umd/Options/Classes/Roll.js +44 -0
- package/umd/Options/Classes/RollLight.js +32 -0
- package/umd/Options/Interfaces/IRoll.js +12 -0
- package/umd/Options/Interfaces/IRollLight.js +12 -0
- package/umd/RollMode.js +12 -0
- package/umd/RollUpdater.js +98 -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 Roll Updater
|
|
4
|
+
|
|
5
|
+
[](https://www.jsdelivr.com/package/npm/tsparticles-updater-roll)
|
|
6
|
+
[](https://www.npmjs.com/package/tsparticles-updater-roll)
|
|
7
|
+
[](https://www.npmjs.com/package/tsparticles-updater-roll) [](https://github.com/sponsors/matteobruni)
|
|
8
|
+
|
|
9
|
+
[tsParticles](https://github.com/matteobruni/tsparticles) updater plugin for roll 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.roll.min.js` file will export the function to load the updater plugin:
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
loadRollUpdater;
|
|
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 loadRollUpdater();
|
|
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-roll
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
or
|
|
49
|
+
|
|
50
|
+
```shell
|
|
51
|
+
$ yarn add tsparticles-updater-roll
|
|
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 { loadRollUpdater } = require("tsparticles-updater-roll");
|
|
59
|
+
|
|
60
|
+
loadRollUpdater(tsParticles);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
or
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
import { tsParticles } from "tsparticles-engine";
|
|
67
|
+
import { loadRollUpdater } from "tsparticles-updater-roll";
|
|
68
|
+
|
|
69
|
+
loadRollUpdater(tsParticles);
|
|
70
|
+
```
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { OptionsColor, setRangeValue } from "@tsparticles/engine";
|
|
2
|
+
import { RollLight } from "./RollLight";
|
|
3
|
+
export class Roll {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.darken = new RollLight();
|
|
6
|
+
this.enable = false;
|
|
7
|
+
this.enlighten = new RollLight();
|
|
8
|
+
this.mode = "vertical";
|
|
9
|
+
this.speed = 25;
|
|
10
|
+
}
|
|
11
|
+
load(data) {
|
|
12
|
+
if (!data) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (data.backColor !== undefined) {
|
|
16
|
+
this.backColor = OptionsColor.create(this.backColor, data.backColor);
|
|
17
|
+
}
|
|
18
|
+
this.darken.load(data.darken);
|
|
19
|
+
if (data.enable !== undefined) {
|
|
20
|
+
this.enable = data.enable;
|
|
21
|
+
}
|
|
22
|
+
this.enlighten.load(data.enlighten);
|
|
23
|
+
if (data.mode !== undefined) {
|
|
24
|
+
this.mode = data.mode;
|
|
25
|
+
}
|
|
26
|
+
if (data.speed !== undefined) {
|
|
27
|
+
this.speed = setRangeValue(data.speed);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { setRangeValue } from "@tsparticles/engine";
|
|
2
|
+
export class RollLight {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.enable = false;
|
|
5
|
+
this.value = 0;
|
|
6
|
+
}
|
|
7
|
+
load(data) {
|
|
8
|
+
if (!data) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (data.enable !== undefined) {
|
|
12
|
+
this.enable = data.enable;
|
|
13
|
+
}
|
|
14
|
+
if (data.value !== undefined) {
|
|
15
|
+
this.value = setRangeValue(data.value);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { getRandom, getRangeValue, rangeColorToHsl } from "@tsparticles/engine";
|
|
2
|
+
import { Roll } from "./Options/Classes/Roll";
|
|
3
|
+
function updateRoll(particle, delta) {
|
|
4
|
+
const roll = particle.options.roll;
|
|
5
|
+
if (!particle.roll || !(roll === null || roll === void 0 ? void 0 : roll.enable)) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const speed = particle.roll.speed * delta.factor, max = 2 * Math.PI;
|
|
9
|
+
particle.roll.angle += speed;
|
|
10
|
+
if (particle.roll.angle > max) {
|
|
11
|
+
particle.roll.angle -= max;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export class RollUpdater {
|
|
15
|
+
getTransformValues(particle) {
|
|
16
|
+
var _a;
|
|
17
|
+
const roll = ((_a = particle.roll) === null || _a === void 0 ? void 0 : _a.enable) && particle.roll, rollHorizontal = roll && roll.horizontal, rollVertical = roll && roll.vertical;
|
|
18
|
+
return {
|
|
19
|
+
a: rollHorizontal ? Math.cos(roll.angle) : undefined,
|
|
20
|
+
d: rollVertical ? Math.sin(roll.angle) : undefined,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
init(particle) {
|
|
24
|
+
const rollOpt = particle.options.roll;
|
|
25
|
+
if (rollOpt === null || rollOpt === void 0 ? void 0 : rollOpt.enable) {
|
|
26
|
+
particle.roll = {
|
|
27
|
+
enable: rollOpt.enable,
|
|
28
|
+
horizontal: rollOpt.mode === "horizontal" || rollOpt.mode === "both",
|
|
29
|
+
vertical: rollOpt.mode === "vertical" || rollOpt.mode === "both",
|
|
30
|
+
angle: getRandom() * Math.PI * 2,
|
|
31
|
+
speed: getRangeValue(rollOpt.speed) / 360,
|
|
32
|
+
};
|
|
33
|
+
if (rollOpt.backColor) {
|
|
34
|
+
particle.backColor = rangeColorToHsl(rollOpt.backColor);
|
|
35
|
+
}
|
|
36
|
+
else if (rollOpt.darken.enable && rollOpt.enlighten.enable) {
|
|
37
|
+
const alterType = getRandom() >= 0.5 ? "darken" : "enlighten";
|
|
38
|
+
particle.roll.alter = {
|
|
39
|
+
type: alterType,
|
|
40
|
+
value: getRangeValue(alterType === "darken" ? rollOpt.darken.value : rollOpt.enlighten.value),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
else if (rollOpt.darken.enable) {
|
|
44
|
+
particle.roll.alter = {
|
|
45
|
+
type: "darken",
|
|
46
|
+
value: getRangeValue(rollOpt.darken.value),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
else if (rollOpt.enlighten.enable) {
|
|
50
|
+
particle.roll.alter = {
|
|
51
|
+
type: "enlighten",
|
|
52
|
+
value: getRangeValue(rollOpt.enlighten.value),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
particle.roll = {
|
|
58
|
+
enable: false,
|
|
59
|
+
horizontal: false,
|
|
60
|
+
vertical: false,
|
|
61
|
+
angle: 0,
|
|
62
|
+
speed: 0,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
isEnabled(particle) {
|
|
67
|
+
const roll = particle.options.roll;
|
|
68
|
+
return !particle.destroyed && !particle.spawning && !!(roll === null || roll === void 0 ? void 0 : roll.enable);
|
|
69
|
+
}
|
|
70
|
+
loadOptions(options, ...sources) {
|
|
71
|
+
if (!options.roll) {
|
|
72
|
+
options.roll = new Roll();
|
|
73
|
+
}
|
|
74
|
+
for (const source of sources) {
|
|
75
|
+
options.roll.load(source === null || source === void 0 ? void 0 : source.roll);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
update(particle, delta) {
|
|
79
|
+
if (!this.isEnabled(particle)) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
updateRoll(particle, delta);
|
|
83
|
+
}
|
|
84
|
+
}
|
package/browser/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Roll = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
const RollLight_1 = require("./RollLight");
|
|
6
|
+
class Roll {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.darken = new RollLight_1.RollLight();
|
|
9
|
+
this.enable = false;
|
|
10
|
+
this.enlighten = new RollLight_1.RollLight();
|
|
11
|
+
this.mode = "vertical";
|
|
12
|
+
this.speed = 25;
|
|
13
|
+
}
|
|
14
|
+
load(data) {
|
|
15
|
+
if (!data) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (data.backColor !== undefined) {
|
|
19
|
+
this.backColor = engine_1.OptionsColor.create(this.backColor, data.backColor);
|
|
20
|
+
}
|
|
21
|
+
this.darken.load(data.darken);
|
|
22
|
+
if (data.enable !== undefined) {
|
|
23
|
+
this.enable = data.enable;
|
|
24
|
+
}
|
|
25
|
+
this.enlighten.load(data.enlighten);
|
|
26
|
+
if (data.mode !== undefined) {
|
|
27
|
+
this.mode = data.mode;
|
|
28
|
+
}
|
|
29
|
+
if (data.speed !== undefined) {
|
|
30
|
+
this.speed = (0, engine_1.setRangeValue)(data.speed);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.Roll = Roll;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RollLight = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
class RollLight {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.enable = false;
|
|
8
|
+
this.value = 0;
|
|
9
|
+
}
|
|
10
|
+
load(data) {
|
|
11
|
+
if (!data) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (data.enable !== undefined) {
|
|
15
|
+
this.enable = data.enable;
|
|
16
|
+
}
|
|
17
|
+
if (data.value !== undefined) {
|
|
18
|
+
this.value = (0, engine_1.setRangeValue)(data.value);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.RollLight = RollLight;
|
package/cjs/RollMode.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RollUpdater = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
const Roll_1 = require("./Options/Classes/Roll");
|
|
6
|
+
function updateRoll(particle, delta) {
|
|
7
|
+
const roll = particle.options.roll;
|
|
8
|
+
if (!particle.roll || !(roll === null || roll === void 0 ? void 0 : roll.enable)) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const speed = particle.roll.speed * delta.factor, max = 2 * Math.PI;
|
|
12
|
+
particle.roll.angle += speed;
|
|
13
|
+
if (particle.roll.angle > max) {
|
|
14
|
+
particle.roll.angle -= max;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
class RollUpdater {
|
|
18
|
+
getTransformValues(particle) {
|
|
19
|
+
var _a;
|
|
20
|
+
const roll = ((_a = particle.roll) === null || _a === void 0 ? void 0 : _a.enable) && particle.roll, rollHorizontal = roll && roll.horizontal, rollVertical = roll && roll.vertical;
|
|
21
|
+
return {
|
|
22
|
+
a: rollHorizontal ? Math.cos(roll.angle) : undefined,
|
|
23
|
+
d: rollVertical ? Math.sin(roll.angle) : undefined,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
init(particle) {
|
|
27
|
+
const rollOpt = particle.options.roll;
|
|
28
|
+
if (rollOpt === null || rollOpt === void 0 ? void 0 : rollOpt.enable) {
|
|
29
|
+
particle.roll = {
|
|
30
|
+
enable: rollOpt.enable,
|
|
31
|
+
horizontal: rollOpt.mode === "horizontal" || rollOpt.mode === "both",
|
|
32
|
+
vertical: rollOpt.mode === "vertical" || rollOpt.mode === "both",
|
|
33
|
+
angle: (0, engine_1.getRandom)() * Math.PI * 2,
|
|
34
|
+
speed: (0, engine_1.getRangeValue)(rollOpt.speed) / 360,
|
|
35
|
+
};
|
|
36
|
+
if (rollOpt.backColor) {
|
|
37
|
+
particle.backColor = (0, engine_1.rangeColorToHsl)(rollOpt.backColor);
|
|
38
|
+
}
|
|
39
|
+
else if (rollOpt.darken.enable && rollOpt.enlighten.enable) {
|
|
40
|
+
const alterType = (0, engine_1.getRandom)() >= 0.5 ? "darken" : "enlighten";
|
|
41
|
+
particle.roll.alter = {
|
|
42
|
+
type: alterType,
|
|
43
|
+
value: (0, engine_1.getRangeValue)(alterType === "darken" ? rollOpt.darken.value : rollOpt.enlighten.value),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
else if (rollOpt.darken.enable) {
|
|
47
|
+
particle.roll.alter = {
|
|
48
|
+
type: "darken",
|
|
49
|
+
value: (0, engine_1.getRangeValue)(rollOpt.darken.value),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
else if (rollOpt.enlighten.enable) {
|
|
53
|
+
particle.roll.alter = {
|
|
54
|
+
type: "enlighten",
|
|
55
|
+
value: (0, engine_1.getRangeValue)(rollOpt.enlighten.value),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
particle.roll = {
|
|
61
|
+
enable: false,
|
|
62
|
+
horizontal: false,
|
|
63
|
+
vertical: false,
|
|
64
|
+
angle: 0,
|
|
65
|
+
speed: 0,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
isEnabled(particle) {
|
|
70
|
+
const roll = particle.options.roll;
|
|
71
|
+
return !particle.destroyed && !particle.spawning && !!(roll === null || roll === void 0 ? void 0 : roll.enable);
|
|
72
|
+
}
|
|
73
|
+
loadOptions(options, ...sources) {
|
|
74
|
+
if (!options.roll) {
|
|
75
|
+
options.roll = new Roll_1.Roll();
|
|
76
|
+
}
|
|
77
|
+
for (const source of sources) {
|
|
78
|
+
options.roll.load(source === null || source === void 0 ? void 0 : source.roll);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
update(particle, delta) {
|
|
82
|
+
if (!this.isEnabled(particle)) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
updateRoll(particle, delta);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.RollUpdater = RollUpdater;
|
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.loadRollUpdater = void 0;
|
|
13
|
+
const RollUpdater_1 = require("./RollUpdater");
|
|
14
|
+
function loadRollUpdater(engine) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
yield engine.addParticleUpdater("roll", () => new RollUpdater_1.RollUpdater());
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
exports.loadRollUpdater = loadRollUpdater;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { OptionsColor, setRangeValue } from "@tsparticles/engine";
|
|
2
|
+
import { RollLight } from "./RollLight";
|
|
3
|
+
export class Roll {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.darken = new RollLight();
|
|
6
|
+
this.enable = false;
|
|
7
|
+
this.enlighten = new RollLight();
|
|
8
|
+
this.mode = "vertical";
|
|
9
|
+
this.speed = 25;
|
|
10
|
+
}
|
|
11
|
+
load(data) {
|
|
12
|
+
if (!data) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (data.backColor !== undefined) {
|
|
16
|
+
this.backColor = OptionsColor.create(this.backColor, data.backColor);
|
|
17
|
+
}
|
|
18
|
+
this.darken.load(data.darken);
|
|
19
|
+
if (data.enable !== undefined) {
|
|
20
|
+
this.enable = data.enable;
|
|
21
|
+
}
|
|
22
|
+
this.enlighten.load(data.enlighten);
|
|
23
|
+
if (data.mode !== undefined) {
|
|
24
|
+
this.mode = data.mode;
|
|
25
|
+
}
|
|
26
|
+
if (data.speed !== undefined) {
|
|
27
|
+
this.speed = setRangeValue(data.speed);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { setRangeValue } from "@tsparticles/engine";
|
|
2
|
+
export class RollLight {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.enable = false;
|
|
5
|
+
this.value = 0;
|
|
6
|
+
}
|
|
7
|
+
load(data) {
|
|
8
|
+
if (!data) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (data.enable !== undefined) {
|
|
12
|
+
this.enable = data.enable;
|
|
13
|
+
}
|
|
14
|
+
if (data.value !== undefined) {
|
|
15
|
+
this.value = setRangeValue(data.value);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/RollMode.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { getRandom, getRangeValue, rangeColorToHsl } from "@tsparticles/engine";
|
|
2
|
+
import { Roll } from "./Options/Classes/Roll";
|
|
3
|
+
function updateRoll(particle, delta) {
|
|
4
|
+
const roll = particle.options.roll;
|
|
5
|
+
if (!particle.roll || !(roll === null || roll === void 0 ? void 0 : roll.enable)) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
const speed = particle.roll.speed * delta.factor, max = 2 * Math.PI;
|
|
9
|
+
particle.roll.angle += speed;
|
|
10
|
+
if (particle.roll.angle > max) {
|
|
11
|
+
particle.roll.angle -= max;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export class RollUpdater {
|
|
15
|
+
getTransformValues(particle) {
|
|
16
|
+
var _a;
|
|
17
|
+
const roll = ((_a = particle.roll) === null || _a === void 0 ? void 0 : _a.enable) && particle.roll, rollHorizontal = roll && roll.horizontal, rollVertical = roll && roll.vertical;
|
|
18
|
+
return {
|
|
19
|
+
a: rollHorizontal ? Math.cos(roll.angle) : undefined,
|
|
20
|
+
d: rollVertical ? Math.sin(roll.angle) : undefined,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
init(particle) {
|
|
24
|
+
const rollOpt = particle.options.roll;
|
|
25
|
+
if (rollOpt === null || rollOpt === void 0 ? void 0 : rollOpt.enable) {
|
|
26
|
+
particle.roll = {
|
|
27
|
+
enable: rollOpt.enable,
|
|
28
|
+
horizontal: rollOpt.mode === "horizontal" || rollOpt.mode === "both",
|
|
29
|
+
vertical: rollOpt.mode === "vertical" || rollOpt.mode === "both",
|
|
30
|
+
angle: getRandom() * Math.PI * 2,
|
|
31
|
+
speed: getRangeValue(rollOpt.speed) / 360,
|
|
32
|
+
};
|
|
33
|
+
if (rollOpt.backColor) {
|
|
34
|
+
particle.backColor = rangeColorToHsl(rollOpt.backColor);
|
|
35
|
+
}
|
|
36
|
+
else if (rollOpt.darken.enable && rollOpt.enlighten.enable) {
|
|
37
|
+
const alterType = getRandom() >= 0.5 ? "darken" : "enlighten";
|
|
38
|
+
particle.roll.alter = {
|
|
39
|
+
type: alterType,
|
|
40
|
+
value: getRangeValue(alterType === "darken" ? rollOpt.darken.value : rollOpt.enlighten.value),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
else if (rollOpt.darken.enable) {
|
|
44
|
+
particle.roll.alter = {
|
|
45
|
+
type: "darken",
|
|
46
|
+
value: getRangeValue(rollOpt.darken.value),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
else if (rollOpt.enlighten.enable) {
|
|
50
|
+
particle.roll.alter = {
|
|
51
|
+
type: "enlighten",
|
|
52
|
+
value: getRangeValue(rollOpt.enlighten.value),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
particle.roll = {
|
|
58
|
+
enable: false,
|
|
59
|
+
horizontal: false,
|
|
60
|
+
vertical: false,
|
|
61
|
+
angle: 0,
|
|
62
|
+
speed: 0,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
isEnabled(particle) {
|
|
67
|
+
const roll = particle.options.roll;
|
|
68
|
+
return !particle.destroyed && !particle.spawning && !!(roll === null || roll === void 0 ? void 0 : roll.enable);
|
|
69
|
+
}
|
|
70
|
+
loadOptions(options, ...sources) {
|
|
71
|
+
if (!options.roll) {
|
|
72
|
+
options.roll = new Roll();
|
|
73
|
+
}
|
|
74
|
+
for (const source of sources) {
|
|
75
|
+
options.roll.load(source === null || source === void 0 ? void 0 : source.roll);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
update(particle, delta) {
|
|
79
|
+
if (!this.isEnabled(particle)) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
updateRoll(particle, delta);
|
|
83
|
+
}
|
|
84
|
+
}
|
package/esm/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tsparticles/updater-roll",
|
|
3
|
+
"version": "3.0.0-alpha.0",
|
|
4
|
+
"description": "tsParticles particles roll updater",
|
|
5
|
+
"homepage": "https://particles.js.org",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/matteobruni/tsparticles.git",
|
|
9
|
+
"directory": "updaters/roll"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"front-end",
|
|
13
|
+
"frontend",
|
|
14
|
+
"tsparticles",
|
|
15
|
+
"particles.js",
|
|
16
|
+
"particlesjs",
|
|
17
|
+
"particles",
|
|
18
|
+
"particle",
|
|
19
|
+
"canvas",
|
|
20
|
+
"jsparticles",
|
|
21
|
+
"xparticles",
|
|
22
|
+
"particles-js",
|
|
23
|
+
"particles-bg",
|
|
24
|
+
"particles-bg-vue",
|
|
25
|
+
"particles-ts",
|
|
26
|
+
"particles.ts",
|
|
27
|
+
"react-particles-js",
|
|
28
|
+
"react-particles.js",
|
|
29
|
+
"react-particles",
|
|
30
|
+
"react",
|
|
31
|
+
"reactjs",
|
|
32
|
+
"vue-particles",
|
|
33
|
+
"ngx-particles",
|
|
34
|
+
"angular-particles",
|
|
35
|
+
"particleground",
|
|
36
|
+
"vue",
|
|
37
|
+
"vuejs",
|
|
38
|
+
"preact",
|
|
39
|
+
"preactjs",
|
|
40
|
+
"jquery",
|
|
41
|
+
"angularjs",
|
|
42
|
+
"angular",
|
|
43
|
+
"typescript",
|
|
44
|
+
"javascript",
|
|
45
|
+
"animation",
|
|
46
|
+
"web",
|
|
47
|
+
"html5",
|
|
48
|
+
"web-design",
|
|
49
|
+
"webdesign",
|
|
50
|
+
"css",
|
|
51
|
+
"html",
|
|
52
|
+
"css3",
|
|
53
|
+
"animated",
|
|
54
|
+
"background",
|
|
55
|
+
"confetti",
|
|
56
|
+
"canvas",
|
|
57
|
+
"fireworks",
|
|
58
|
+
"fireworks-js",
|
|
59
|
+
"confetti-js",
|
|
60
|
+
"confettijs",
|
|
61
|
+
"fireworksjs",
|
|
62
|
+
"canvas-confetti",
|
|
63
|
+
"@tsparticles/plugin",
|
|
64
|
+
"@tsparticles/updater"
|
|
65
|
+
],
|
|
66
|
+
"author": "Matteo Bruni <matteo.bruni@me.com>",
|
|
67
|
+
"license": "MIT",
|
|
68
|
+
"bugs": {
|
|
69
|
+
"url": "https://github.com/matteobruni/tsparticles/issues"
|
|
70
|
+
},
|
|
71
|
+
"main": "cjs/index.js",
|
|
72
|
+
"jsdelivr": "tsparticles.updater.roll.min.js",
|
|
73
|
+
"unpkg": "tsparticles.updater.roll.min.js",
|
|
74
|
+
"module": "esm/index.js",
|
|
75
|
+
"types": "types/index.d.ts",
|
|
76
|
+
"publishConfig": {
|
|
77
|
+
"access": "public"
|
|
78
|
+
},
|
|
79
|
+
"dependencies": {
|
|
80
|
+
"@tsparticles/engine": "^3.0.0-alpha.0"
|
|
81
|
+
}
|
|
82
|
+
}
|