@tsparticles/interaction-light 3.0.0-alpha.1 → 3.0.0-beta.1
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 +25 -19
- package/browser/ExternalLighter.js +15 -15
- package/browser/Options/Classes/Light.js +2 -2
- package/browser/Options/Classes/LightArea.js +1 -1
- package/browser/ParticlesLighter.js +12 -11
- package/browser/Utils.js +14 -16
- package/browser/index.js +13 -13
- package/browser/package.json +1 -0
- package/cjs/ExternalLighter.js +16 -27
- package/cjs/Options/Classes/Light.js +4 -4
- package/cjs/Options/Classes/LightArea.js +2 -2
- package/cjs/ParticlesLighter.js +13 -23
- package/cjs/Utils.js +14 -16
- package/cjs/index.js +13 -13
- package/cjs/package.json +1 -0
- package/esm/ExternalLighter.js +15 -15
- package/esm/Options/Classes/Light.js +2 -2
- package/esm/Options/Classes/LightArea.js +1 -1
- package/esm/ParticlesLighter.js +12 -11
- package/esm/Utils.js +14 -16
- package/esm/index.js +13 -13
- package/esm/package.json +1 -0
- package/package.json +23 -6
- package/report.html +4 -4
- package/tsparticles.interaction.light.js +49 -48
- package/tsparticles.interaction.light.min.js +1 -1
- package/tsparticles.interaction.light.min.js.LICENSE.txt +1 -8
- package/types/ExternalLighter.d.ts +3 -4
- package/types/Options/Classes/Light.d.ts +3 -3
- package/types/Options/Classes/LightArea.d.ts +2 -2
- package/types/Options/Classes/LightGradient.d.ts +1 -1
- package/types/Options/Classes/LightOptions.d.ts +1 -1
- package/types/Options/Classes/LightShadow.d.ts +2 -3
- package/types/Options/Interfaces/ILight.d.ts +2 -2
- package/types/Options/Interfaces/ILightArea.d.ts +1 -1
- package/types/ParticlesLighter.d.ts +1 -1
- package/types/Types.d.ts +3 -3
- package/types/Utils.d.ts +2 -2
- package/types/index.d.ts +9 -9
- package/umd/ExternalLighter.js +16 -16
- package/umd/Options/Classes/Light.js +5 -5
- package/umd/Options/Classes/LightArea.js +3 -3
- package/umd/ParticlesLighter.js +13 -12
- package/umd/Utils.js +14 -16
- package/umd/index.js +14 -14
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
# tsParticles Light Interaction
|
|
4
4
|
|
|
5
|
-
[](https://www.jsdelivr.com/package/npm/@tsparticles/interaction-light)
|
|
6
|
+
[](https://www.npmjs.com/package/@tsparticles/interaction-light)
|
|
7
|
+
[](https://www.npmjs.com/package/@tsparticles/interaction-light) [](https://github.com/sponsors/matteobruni)
|
|
8
8
|
|
|
9
9
|
[tsParticles](https://github.com/matteobruni/tsparticles) interaction plugin for light effect.
|
|
10
10
|
|
|
@@ -25,14 +25,16 @@ loadLightInteraction
|
|
|
25
25
|
Once the scripts are loaded you can set up `tsParticles` and the interaction plugin like this:
|
|
26
26
|
|
|
27
27
|
```javascript
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
28
|
+
(async () => {
|
|
29
|
+
await loadLightInteraction(tsParticles);
|
|
30
|
+
|
|
31
|
+
await tsParticles.load({
|
|
32
|
+
id: "tsparticles",
|
|
33
|
+
options: {
|
|
34
|
+
/* options */
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
})();
|
|
36
38
|
```
|
|
37
39
|
|
|
38
40
|
### ESM / CommonJS
|
|
@@ -40,29 +42,33 @@ tsParticles.load({
|
|
|
40
42
|
This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
|
|
41
43
|
|
|
42
44
|
```shell
|
|
43
|
-
$ npm install tsparticles
|
|
45
|
+
$ npm install @tsparticles/interaction-light
|
|
44
46
|
```
|
|
45
47
|
|
|
46
48
|
or
|
|
47
49
|
|
|
48
50
|
```shell
|
|
49
|
-
$ yarn add tsparticles
|
|
51
|
+
$ yarn add @tsparticles/interaction-light
|
|
50
52
|
```
|
|
51
53
|
|
|
52
54
|
Then you need to import it in the app, like this:
|
|
53
55
|
|
|
54
56
|
```javascript
|
|
55
|
-
const { tsParticles } = require("tsparticles
|
|
56
|
-
const { loadLightInteraction } = require("tsparticles
|
|
57
|
+
const { tsParticles } = require("@tsparticles/engine");
|
|
58
|
+
const { loadLightInteraction } = require("@tsparticles/interaction-light");
|
|
57
59
|
|
|
58
|
-
|
|
60
|
+
(async () => {
|
|
61
|
+
await loadLightInteraction(tsParticles);
|
|
62
|
+
})();
|
|
59
63
|
```
|
|
60
64
|
|
|
61
65
|
or
|
|
62
66
|
|
|
63
67
|
```javascript
|
|
64
|
-
import { tsParticles } from "tsparticles
|
|
65
|
-
import { loadLightInteraction } from "tsparticles
|
|
68
|
+
import { tsParticles } from "@tsparticles/engine";
|
|
69
|
+
import { loadLightInteraction } from "@tsparticles/interaction-light";
|
|
66
70
|
|
|
67
|
-
|
|
71
|
+
(async () => {
|
|
72
|
+
await loadLightInteraction(tsParticles);
|
|
73
|
+
})();
|
|
68
74
|
```
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ExternalInteractorBase, isInArray, rangeColorToRgb } from "@tsparticles/engine";
|
|
2
|
-
import { Light } from "./Options/Classes/Light";
|
|
3
|
-
import { drawLight } from "./Utils";
|
|
1
|
+
import { ExternalInteractorBase, isInArray, rangeColorToRgb, } from "@tsparticles/engine";
|
|
2
|
+
import { Light } from "./Options/Classes/Light.js";
|
|
3
|
+
import { drawLight } from "./Utils.js";
|
|
4
4
|
export class ExternalLighter extends ExternalInteractorBase {
|
|
5
5
|
constructor(container) {
|
|
6
6
|
super(container);
|
|
@@ -10,20 +10,20 @@ export class ExternalLighter extends ExternalInteractorBase {
|
|
|
10
10
|
init() {
|
|
11
11
|
}
|
|
12
12
|
async interact() {
|
|
13
|
-
const container = this.container, options = container.actualOptions;
|
|
14
|
-
if (options.interactivity.events.onHover.enable
|
|
15
|
-
|
|
16
|
-
if (!mousePos) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
container.canvas.draw((ctx) => {
|
|
20
|
-
drawLight(container, ctx, mousePos);
|
|
21
|
-
});
|
|
13
|
+
const container = this.container, options = container.actualOptions, interactivity = container.interactivity;
|
|
14
|
+
if (!options.interactivity.events.onHover.enable || interactivity.status !== "pointermove") {
|
|
15
|
+
return;
|
|
22
16
|
}
|
|
17
|
+
const mousePos = interactivity.mouse.position;
|
|
18
|
+
if (!mousePos) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
container.canvas.draw((ctx) => {
|
|
22
|
+
drawLight(container, ctx, mousePos);
|
|
23
|
+
});
|
|
23
24
|
}
|
|
24
25
|
isEnabled(particle) {
|
|
25
|
-
|
|
26
|
-
const container = this.container, mouse = container.interactivity.mouse, interactivity = (_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : container.actualOptions.interactivity, events = interactivity.events;
|
|
26
|
+
const container = this.container, mouse = container.interactivity.mouse, interactivity = particle?.interactivity ?? container.actualOptions.interactivity, events = interactivity.events;
|
|
27
27
|
if (!(events.onHover.enable && mouse.position)) {
|
|
28
28
|
return false;
|
|
29
29
|
}
|
|
@@ -42,7 +42,7 @@ export class ExternalLighter extends ExternalInteractorBase {
|
|
|
42
42
|
options.light = new Light();
|
|
43
43
|
}
|
|
44
44
|
for (const source of sources) {
|
|
45
|
-
options.light.load(source
|
|
45
|
+
options.light.load(source?.light);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
reset() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ParticlesInteractorBase, isInArray, rangeColorToRgb } from "@tsparticles/engine";
|
|
2
|
-
import { drawParticleShadow } from "./Utils";
|
|
2
|
+
import { drawParticleShadow } from "./Utils.js";
|
|
3
3
|
export class ParticlesLighter extends ParticlesInteractorBase {
|
|
4
4
|
constructor(container) {
|
|
5
5
|
super(container);
|
|
@@ -9,19 +9,20 @@ export class ParticlesLighter extends ParticlesInteractorBase {
|
|
|
9
9
|
init() {
|
|
10
10
|
}
|
|
11
11
|
async interact(particle) {
|
|
12
|
-
const container = this.container, options = container.actualOptions;
|
|
13
|
-
if (options.interactivity.events.onHover.enable
|
|
14
|
-
|
|
15
|
-
if (mousePos) {
|
|
16
|
-
container.canvas.draw((ctx) => {
|
|
17
|
-
drawParticleShadow(container, ctx, particle, mousePos);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
12
|
+
const container = this.container, options = container.actualOptions, interactivity = container.interactivity;
|
|
13
|
+
if (!options.interactivity.events.onHover.enable || interactivity.status !== "pointermove") {
|
|
14
|
+
return;
|
|
20
15
|
}
|
|
16
|
+
const mousePos = interactivity.mouse.position;
|
|
17
|
+
if (!mousePos) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
container.canvas.draw((ctx) => {
|
|
21
|
+
drawParticleShadow(container, ctx, particle, mousePos);
|
|
22
|
+
});
|
|
21
23
|
}
|
|
22
24
|
isEnabled(particle) {
|
|
23
|
-
|
|
24
|
-
const container = this.container, interactivity = (_a = particle.interactivity) !== null && _a !== void 0 ? _a : container.actualOptions.interactivity, mouse = container.interactivity.mouse, events = interactivity.events;
|
|
25
|
+
const container = this.container, interactivity = particle.interactivity ?? container.actualOptions.interactivity, mouse = container.interactivity.mouse, events = interactivity.events;
|
|
25
26
|
if (!(events.onHover.enable && mouse.position)) {
|
|
26
27
|
return false;
|
|
27
28
|
}
|
package/browser/Utils.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getStyleFromRgb } from "@tsparticles/engine";
|
|
2
2
|
export function drawLight(container, context, mousePos) {
|
|
3
|
-
|
|
4
|
-
const lightOptions = (_a = container.actualOptions.interactivity.modes.light) === null || _a === void 0 ? void 0 : _a.area;
|
|
3
|
+
const lightOptions = container.actualOptions.interactivity.modes.light?.area;
|
|
5
4
|
if (!lightOptions) {
|
|
6
5
|
return;
|
|
7
6
|
}
|
|
@@ -18,8 +17,7 @@ export function drawLight(container, context, mousePos) {
|
|
|
18
17
|
context.fill();
|
|
19
18
|
}
|
|
20
19
|
export function drawParticleShadow(container, context, particle, mousePos) {
|
|
21
|
-
|
|
22
|
-
const pos = particle.getPosition(), shadowOptions = (_a = container.actualOptions.interactivity.modes.light) === null || _a === void 0 ? void 0 : _a.shadow;
|
|
20
|
+
const pos = particle.getPosition(), shadowOptions = container.actualOptions.interactivity.modes.light?.shadow;
|
|
23
21
|
if (!shadowOptions) {
|
|
24
22
|
return;
|
|
25
23
|
}
|
|
@@ -36,22 +34,22 @@ export function drawParticleShadow(container, context, particle, mousePos) {
|
|
|
36
34
|
}
|
|
37
35
|
const points = [], shadowLength = shadowOptions.length;
|
|
38
36
|
for (const dot of dots) {
|
|
39
|
-
const dotAngle = Math.atan2(mousePos.y - dot.y, mousePos.x - dot.x),
|
|
37
|
+
const dotAngle = Math.atan2(mousePos.y - dot.y, mousePos.x - dot.x), end = {
|
|
38
|
+
x: dot.x + shadowLength * Math.sin(-dotAngle - Math.PI / 2),
|
|
39
|
+
y: dot.y + shadowLength * Math.cos(-dotAngle - Math.PI / 2),
|
|
40
|
+
};
|
|
40
41
|
points.push({
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
startX: dot.x,
|
|
44
|
-
startY: dot.y,
|
|
42
|
+
end: end,
|
|
43
|
+
start: dot,
|
|
45
44
|
});
|
|
46
45
|
}
|
|
47
|
-
const shadowColor = getStyleFromRgb(shadowRgb);
|
|
48
|
-
for (let i =
|
|
49
|
-
const n = i === points.length - 1 ? 0 : i + 1;
|
|
46
|
+
const shadowColor = getStyleFromRgb(shadowRgb), last = points.length - 1;
|
|
47
|
+
for (let i = last, n = 0; i >= 0; n = i--) {
|
|
50
48
|
context.beginPath();
|
|
51
|
-
context.moveTo(points[i].
|
|
52
|
-
context.lineTo(points[n].
|
|
53
|
-
context.lineTo(points[n].
|
|
54
|
-
context.lineTo(points[i].
|
|
49
|
+
context.moveTo(points[i].start.x, points[i].start.y);
|
|
50
|
+
context.lineTo(points[n].start.x, points[n].start.y);
|
|
51
|
+
context.lineTo(points[n].end.x, points[n].end.y);
|
|
52
|
+
context.lineTo(points[i].end.x, points[i].end.y);
|
|
55
53
|
context.fillStyle = shadowColor;
|
|
56
54
|
context.fill();
|
|
57
55
|
}
|
package/browser/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { ExternalLighter } from "./ExternalLighter";
|
|
2
|
-
import { ParticlesLighter } from "./ParticlesLighter";
|
|
3
|
-
export function loadLightInteraction(engine) {
|
|
4
|
-
engine.addInteractor("externalLight", (container) => new ExternalLighter(container));
|
|
5
|
-
engine.addInteractor("particlesLight", (container) => new ParticlesLighter(container));
|
|
1
|
+
import { ExternalLighter } from "./ExternalLighter.js";
|
|
2
|
+
import { ParticlesLighter } from "./ParticlesLighter.js";
|
|
3
|
+
export async function loadLightInteraction(engine, refresh = true) {
|
|
4
|
+
await engine.addInteractor("externalLight", (container) => new ExternalLighter(container), refresh);
|
|
5
|
+
await engine.addInteractor("particlesLight", (container) => new ParticlesLighter(container), refresh);
|
|
6
6
|
}
|
|
7
|
-
export * from "./Options/Classes/Light";
|
|
8
|
-
export * from "./Options/Classes/LightArea";
|
|
9
|
-
export * from "./Options/Classes/LightGradient";
|
|
10
|
-
export * from "./Options/Classes/LightShadow";
|
|
11
|
-
export * from "./Options/Interfaces/ILight";
|
|
12
|
-
export * from "./Options/Interfaces/ILightArea";
|
|
13
|
-
export * from "./Options/Interfaces/ILightGradient";
|
|
14
|
-
export * from "./Options/Interfaces/ILightShadow";
|
|
7
|
+
export * from "./Options/Classes/Light.js";
|
|
8
|
+
export * from "./Options/Classes/LightArea.js";
|
|
9
|
+
export * from "./Options/Classes/LightGradient.js";
|
|
10
|
+
export * from "./Options/Classes/LightShadow.js";
|
|
11
|
+
export * from "./Options/Interfaces/ILight.js";
|
|
12
|
+
export * from "./Options/Interfaces/ILightArea.js";
|
|
13
|
+
export * from "./Options/Interfaces/ILightGradient.js";
|
|
14
|
+
export * from "./Options/Interfaces/ILightShadow.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "module" }
|
package/cjs/ExternalLighter.js
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
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.ExternalLighter = void 0;
|
|
13
4
|
const engine_1 = require("@tsparticles/engine");
|
|
14
|
-
const
|
|
15
|
-
const
|
|
5
|
+
const Light_js_1 = require("./Options/Classes/Light.js");
|
|
6
|
+
const Utils_js_1 = require("./Utils.js");
|
|
16
7
|
class ExternalLighter extends engine_1.ExternalInteractorBase {
|
|
17
8
|
constructor(container) {
|
|
18
9
|
super(container);
|
|
@@ -21,23 +12,21 @@ class ExternalLighter extends engine_1.ExternalInteractorBase {
|
|
|
21
12
|
}
|
|
22
13
|
init() {
|
|
23
14
|
}
|
|
24
|
-
interact() {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
15
|
+
async interact() {
|
|
16
|
+
const container = this.container, options = container.actualOptions, interactivity = container.interactivity;
|
|
17
|
+
if (!options.interactivity.events.onHover.enable || interactivity.status !== "pointermove") {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const mousePos = interactivity.mouse.position;
|
|
21
|
+
if (!mousePos) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
container.canvas.draw((ctx) => {
|
|
25
|
+
(0, Utils_js_1.drawLight)(container, ctx, mousePos);
|
|
36
26
|
});
|
|
37
27
|
}
|
|
38
28
|
isEnabled(particle) {
|
|
39
|
-
|
|
40
|
-
const container = this.container, mouse = container.interactivity.mouse, interactivity = (_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : container.actualOptions.interactivity, events = interactivity.events;
|
|
29
|
+
const container = this.container, mouse = container.interactivity.mouse, interactivity = particle?.interactivity ?? container.actualOptions.interactivity, events = interactivity.events;
|
|
41
30
|
if (!(events.onHover.enable && mouse.position)) {
|
|
42
31
|
return false;
|
|
43
32
|
}
|
|
@@ -53,10 +42,10 @@ class ExternalLighter extends engine_1.ExternalInteractorBase {
|
|
|
53
42
|
}
|
|
54
43
|
loadModeOptions(options, ...sources) {
|
|
55
44
|
if (!options.light) {
|
|
56
|
-
options.light = new
|
|
45
|
+
options.light = new Light_js_1.Light();
|
|
57
46
|
}
|
|
58
47
|
for (const source of sources) {
|
|
59
|
-
options.light.load(source
|
|
48
|
+
options.light.load(source?.light);
|
|
60
49
|
}
|
|
61
50
|
}
|
|
62
51
|
reset() {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Light = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const LightArea_js_1 = require("./LightArea.js");
|
|
5
|
+
const LightShadow_js_1 = require("./LightShadow.js");
|
|
6
6
|
class Light {
|
|
7
7
|
constructor() {
|
|
8
|
-
this.area = new
|
|
9
|
-
this.shadow = new
|
|
8
|
+
this.area = new LightArea_js_1.LightArea();
|
|
9
|
+
this.shadow = new LightShadow_js_1.LightShadow();
|
|
10
10
|
}
|
|
11
11
|
load(data) {
|
|
12
12
|
if (!data) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LightArea = void 0;
|
|
4
|
-
const
|
|
4
|
+
const LightGradient_js_1 = require("./LightGradient.js");
|
|
5
5
|
class LightArea {
|
|
6
6
|
constructor() {
|
|
7
|
-
this.gradient = new
|
|
7
|
+
this.gradient = new LightGradient_js_1.LightGradient();
|
|
8
8
|
this.radius = 1000;
|
|
9
9
|
}
|
|
10
10
|
load(data) {
|
package/cjs/ParticlesLighter.js
CHANGED
|
@@ -1,17 +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.ParticlesLighter = void 0;
|
|
13
4
|
const engine_1 = require("@tsparticles/engine");
|
|
14
|
-
const
|
|
5
|
+
const Utils_js_1 = require("./Utils.js");
|
|
15
6
|
class ParticlesLighter extends engine_1.ParticlesInteractorBase {
|
|
16
7
|
constructor(container) {
|
|
17
8
|
super(container);
|
|
@@ -20,22 +11,21 @@ class ParticlesLighter extends engine_1.ParticlesInteractorBase {
|
|
|
20
11
|
}
|
|
21
12
|
init() {
|
|
22
13
|
}
|
|
23
|
-
interact(particle) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
14
|
+
async interact(particle) {
|
|
15
|
+
const container = this.container, options = container.actualOptions, interactivity = container.interactivity;
|
|
16
|
+
if (!options.interactivity.events.onHover.enable || interactivity.status !== "pointermove") {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const mousePos = interactivity.mouse.position;
|
|
20
|
+
if (!mousePos) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
container.canvas.draw((ctx) => {
|
|
24
|
+
(0, Utils_js_1.drawParticleShadow)(container, ctx, particle, mousePos);
|
|
34
25
|
});
|
|
35
26
|
}
|
|
36
27
|
isEnabled(particle) {
|
|
37
|
-
|
|
38
|
-
const container = this.container, interactivity = (_a = particle.interactivity) !== null && _a !== void 0 ? _a : container.actualOptions.interactivity, mouse = container.interactivity.mouse, events = interactivity.events;
|
|
28
|
+
const container = this.container, interactivity = particle.interactivity ?? container.actualOptions.interactivity, mouse = container.interactivity.mouse, events = interactivity.events;
|
|
39
29
|
if (!(events.onHover.enable && mouse.position)) {
|
|
40
30
|
return false;
|
|
41
31
|
}
|
package/cjs/Utils.js
CHANGED
|
@@ -3,8 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.drawParticleShadow = exports.drawLight = void 0;
|
|
4
4
|
const engine_1 = require("@tsparticles/engine");
|
|
5
5
|
function drawLight(container, context, mousePos) {
|
|
6
|
-
|
|
7
|
-
const lightOptions = (_a = container.actualOptions.interactivity.modes.light) === null || _a === void 0 ? void 0 : _a.area;
|
|
6
|
+
const lightOptions = container.actualOptions.interactivity.modes.light?.area;
|
|
8
7
|
if (!lightOptions) {
|
|
9
8
|
return;
|
|
10
9
|
}
|
|
@@ -22,8 +21,7 @@ function drawLight(container, context, mousePos) {
|
|
|
22
21
|
}
|
|
23
22
|
exports.drawLight = drawLight;
|
|
24
23
|
function drawParticleShadow(container, context, particle, mousePos) {
|
|
25
|
-
|
|
26
|
-
const pos = particle.getPosition(), shadowOptions = (_a = container.actualOptions.interactivity.modes.light) === null || _a === void 0 ? void 0 : _a.shadow;
|
|
24
|
+
const pos = particle.getPosition(), shadowOptions = container.actualOptions.interactivity.modes.light?.shadow;
|
|
27
25
|
if (!shadowOptions) {
|
|
28
26
|
return;
|
|
29
27
|
}
|
|
@@ -40,22 +38,22 @@ function drawParticleShadow(container, context, particle, mousePos) {
|
|
|
40
38
|
}
|
|
41
39
|
const points = [], shadowLength = shadowOptions.length;
|
|
42
40
|
for (const dot of dots) {
|
|
43
|
-
const dotAngle = Math.atan2(mousePos.y - dot.y, mousePos.x - dot.x),
|
|
41
|
+
const dotAngle = Math.atan2(mousePos.y - dot.y, mousePos.x - dot.x), end = {
|
|
42
|
+
x: dot.x + shadowLength * Math.sin(-dotAngle - Math.PI / 2),
|
|
43
|
+
y: dot.y + shadowLength * Math.cos(-dotAngle - Math.PI / 2),
|
|
44
|
+
};
|
|
44
45
|
points.push({
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
startX: dot.x,
|
|
48
|
-
startY: dot.y,
|
|
46
|
+
end: end,
|
|
47
|
+
start: dot,
|
|
49
48
|
});
|
|
50
49
|
}
|
|
51
|
-
const shadowColor = (0, engine_1.getStyleFromRgb)(shadowRgb);
|
|
52
|
-
for (let i =
|
|
53
|
-
const n = i === points.length - 1 ? 0 : i + 1;
|
|
50
|
+
const shadowColor = (0, engine_1.getStyleFromRgb)(shadowRgb), last = points.length - 1;
|
|
51
|
+
for (let i = last, n = 0; i >= 0; n = i--) {
|
|
54
52
|
context.beginPath();
|
|
55
|
-
context.moveTo(points[i].
|
|
56
|
-
context.lineTo(points[n].
|
|
57
|
-
context.lineTo(points[n].
|
|
58
|
-
context.lineTo(points[i].
|
|
53
|
+
context.moveTo(points[i].start.x, points[i].start.y);
|
|
54
|
+
context.lineTo(points[n].start.x, points[n].start.y);
|
|
55
|
+
context.lineTo(points[n].end.x, points[n].end.y);
|
|
56
|
+
context.lineTo(points[i].end.x, points[i].end.y);
|
|
59
57
|
context.fillStyle = shadowColor;
|
|
60
58
|
context.fill();
|
|
61
59
|
}
|
package/cjs/index.js
CHANGED
|
@@ -15,18 +15,18 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.loadLightInteraction = void 0;
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
function loadLightInteraction(engine) {
|
|
21
|
-
engine.addInteractor("externalLight", (container) => new
|
|
22
|
-
engine.addInteractor("particlesLight", (container) => new
|
|
18
|
+
const ExternalLighter_js_1 = require("./ExternalLighter.js");
|
|
19
|
+
const ParticlesLighter_js_1 = require("./ParticlesLighter.js");
|
|
20
|
+
async function loadLightInteraction(engine, refresh = true) {
|
|
21
|
+
await engine.addInteractor("externalLight", (container) => new ExternalLighter_js_1.ExternalLighter(container), refresh);
|
|
22
|
+
await engine.addInteractor("particlesLight", (container) => new ParticlesLighter_js_1.ParticlesLighter(container), refresh);
|
|
23
23
|
}
|
|
24
24
|
exports.loadLightInteraction = loadLightInteraction;
|
|
25
|
-
__exportStar(require("./Options/Classes/Light"), exports);
|
|
26
|
-
__exportStar(require("./Options/Classes/LightArea"), exports);
|
|
27
|
-
__exportStar(require("./Options/Classes/LightGradient"), exports);
|
|
28
|
-
__exportStar(require("./Options/Classes/LightShadow"), exports);
|
|
29
|
-
__exportStar(require("./Options/Interfaces/ILight"), exports);
|
|
30
|
-
__exportStar(require("./Options/Interfaces/ILightArea"), exports);
|
|
31
|
-
__exportStar(require("./Options/Interfaces/ILightGradient"), exports);
|
|
32
|
-
__exportStar(require("./Options/Interfaces/ILightShadow"), exports);
|
|
25
|
+
__exportStar(require("./Options/Classes/Light.js"), exports);
|
|
26
|
+
__exportStar(require("./Options/Classes/LightArea.js"), exports);
|
|
27
|
+
__exportStar(require("./Options/Classes/LightGradient.js"), exports);
|
|
28
|
+
__exportStar(require("./Options/Classes/LightShadow.js"), exports);
|
|
29
|
+
__exportStar(require("./Options/Interfaces/ILight.js"), exports);
|
|
30
|
+
__exportStar(require("./Options/Interfaces/ILightArea.js"), exports);
|
|
31
|
+
__exportStar(require("./Options/Interfaces/ILightGradient.js"), exports);
|
|
32
|
+
__exportStar(require("./Options/Interfaces/ILightShadow.js"), exports);
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "commonjs" }
|
package/esm/ExternalLighter.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ExternalInteractorBase, isInArray, rangeColorToRgb } from "@tsparticles/engine";
|
|
2
|
-
import { Light } from "./Options/Classes/Light";
|
|
3
|
-
import { drawLight } from "./Utils";
|
|
1
|
+
import { ExternalInteractorBase, isInArray, rangeColorToRgb, } from "@tsparticles/engine";
|
|
2
|
+
import { Light } from "./Options/Classes/Light.js";
|
|
3
|
+
import { drawLight } from "./Utils.js";
|
|
4
4
|
export class ExternalLighter extends ExternalInteractorBase {
|
|
5
5
|
constructor(container) {
|
|
6
6
|
super(container);
|
|
@@ -10,20 +10,20 @@ export class ExternalLighter extends ExternalInteractorBase {
|
|
|
10
10
|
init() {
|
|
11
11
|
}
|
|
12
12
|
async interact() {
|
|
13
|
-
const container = this.container, options = container.actualOptions;
|
|
14
|
-
if (options.interactivity.events.onHover.enable
|
|
15
|
-
|
|
16
|
-
if (!mousePos) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
container.canvas.draw((ctx) => {
|
|
20
|
-
drawLight(container, ctx, mousePos);
|
|
21
|
-
});
|
|
13
|
+
const container = this.container, options = container.actualOptions, interactivity = container.interactivity;
|
|
14
|
+
if (!options.interactivity.events.onHover.enable || interactivity.status !== "pointermove") {
|
|
15
|
+
return;
|
|
22
16
|
}
|
|
17
|
+
const mousePos = interactivity.mouse.position;
|
|
18
|
+
if (!mousePos) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
container.canvas.draw((ctx) => {
|
|
22
|
+
drawLight(container, ctx, mousePos);
|
|
23
|
+
});
|
|
23
24
|
}
|
|
24
25
|
isEnabled(particle) {
|
|
25
|
-
|
|
26
|
-
const container = this.container, mouse = container.interactivity.mouse, interactivity = (_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : container.actualOptions.interactivity, events = interactivity.events;
|
|
26
|
+
const container = this.container, mouse = container.interactivity.mouse, interactivity = particle?.interactivity ?? container.actualOptions.interactivity, events = interactivity.events;
|
|
27
27
|
if (!(events.onHover.enable && mouse.position)) {
|
|
28
28
|
return false;
|
|
29
29
|
}
|
|
@@ -42,7 +42,7 @@ export class ExternalLighter extends ExternalInteractorBase {
|
|
|
42
42
|
options.light = new Light();
|
|
43
43
|
}
|
|
44
44
|
for (const source of sources) {
|
|
45
|
-
options.light.load(source
|
|
45
|
+
options.light.load(source?.light);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
reset() {
|
package/esm/ParticlesLighter.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ParticlesInteractorBase, isInArray, rangeColorToRgb } from "@tsparticles/engine";
|
|
2
|
-
import { drawParticleShadow } from "./Utils";
|
|
2
|
+
import { drawParticleShadow } from "./Utils.js";
|
|
3
3
|
export class ParticlesLighter extends ParticlesInteractorBase {
|
|
4
4
|
constructor(container) {
|
|
5
5
|
super(container);
|
|
@@ -9,19 +9,20 @@ export class ParticlesLighter extends ParticlesInteractorBase {
|
|
|
9
9
|
init() {
|
|
10
10
|
}
|
|
11
11
|
async interact(particle) {
|
|
12
|
-
const container = this.container, options = container.actualOptions;
|
|
13
|
-
if (options.interactivity.events.onHover.enable
|
|
14
|
-
|
|
15
|
-
if (mousePos) {
|
|
16
|
-
container.canvas.draw((ctx) => {
|
|
17
|
-
drawParticleShadow(container, ctx, particle, mousePos);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
12
|
+
const container = this.container, options = container.actualOptions, interactivity = container.interactivity;
|
|
13
|
+
if (!options.interactivity.events.onHover.enable || interactivity.status !== "pointermove") {
|
|
14
|
+
return;
|
|
20
15
|
}
|
|
16
|
+
const mousePos = interactivity.mouse.position;
|
|
17
|
+
if (!mousePos) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
container.canvas.draw((ctx) => {
|
|
21
|
+
drawParticleShadow(container, ctx, particle, mousePos);
|
|
22
|
+
});
|
|
21
23
|
}
|
|
22
24
|
isEnabled(particle) {
|
|
23
|
-
|
|
24
|
-
const container = this.container, interactivity = (_a = particle.interactivity) !== null && _a !== void 0 ? _a : container.actualOptions.interactivity, mouse = container.interactivity.mouse, events = interactivity.events;
|
|
25
|
+
const container = this.container, interactivity = particle.interactivity ?? container.actualOptions.interactivity, mouse = container.interactivity.mouse, events = interactivity.events;
|
|
25
26
|
if (!(events.onHover.enable && mouse.position)) {
|
|
26
27
|
return false;
|
|
27
28
|
}
|