@tsparticles/interaction-light 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 +25 -19
- package/browser/ExternalLighter.js +13 -13
- package/browser/ParticlesLighter.js +11 -10
- package/browser/Utils.js +14 -16
- package/browser/index.js +3 -3
- package/cjs/ExternalLighter.js +13 -24
- package/cjs/ParticlesLighter.js +12 -22
- package/cjs/Utils.js +14 -16
- package/cjs/index.js +3 -3
- package/esm/ExternalLighter.js +13 -13
- package/esm/ParticlesLighter.js +11 -10
- package/esm/Utils.js +14 -16
- package/esm/index.js +3 -3
- package/package.json +10 -5
- 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 +1 -2
- package/types/Options/Classes/LightShadow.d.ts +1 -2
- package/types/Utils.d.ts +1 -1
- package/types/index.d.ts +1 -1
- package/umd/ExternalLighter.js +12 -12
- package/umd/ParticlesLighter.js +11 -10
- package/umd/Utils.js +14 -16
- package/umd/index.js +3 -3
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,4 +1,4 @@
|
|
|
1
|
-
import { ExternalInteractorBase, isInArray, rangeColorToRgb } from "@tsparticles/engine";
|
|
1
|
+
import { ExternalInteractorBase, isInArray, rangeColorToRgb, } from "@tsparticles/engine";
|
|
2
2
|
import { Light } from "./Options/Classes/Light";
|
|
3
3
|
import { drawLight } from "./Utils";
|
|
4
4
|
export class ExternalLighter extends ExternalInteractorBase {
|
|
@@ -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() {
|
|
@@ -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,8 +1,8 @@
|
|
|
1
1
|
import { ExternalLighter } from "./ExternalLighter";
|
|
2
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));
|
|
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
7
|
export * from "./Options/Classes/Light";
|
|
8
8
|
export * from "./Options/Classes/LightArea";
|
package/cjs/ExternalLighter.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
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");
|
|
@@ -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_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
|
}
|
|
@@ -56,7 +45,7 @@ class ExternalLighter extends engine_1.ExternalInteractorBase {
|
|
|
56
45
|
options.light = new Light_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() {
|
package/cjs/ParticlesLighter.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
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");
|
|
@@ -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_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
|
@@ -17,9 +17,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.loadLightInteraction = void 0;
|
|
18
18
|
const ExternalLighter_1 = require("./ExternalLighter");
|
|
19
19
|
const ParticlesLighter_1 = require("./ParticlesLighter");
|
|
20
|
-
function loadLightInteraction(engine) {
|
|
21
|
-
engine.addInteractor("externalLight", (container) => new ExternalLighter_1.ExternalLighter(container));
|
|
22
|
-
engine.addInteractor("particlesLight", (container) => new ParticlesLighter_1.ParticlesLighter(container));
|
|
20
|
+
async function loadLightInteraction(engine, refresh = true) {
|
|
21
|
+
await engine.addInteractor("externalLight", (container) => new ExternalLighter_1.ExternalLighter(container), refresh);
|
|
22
|
+
await engine.addInteractor("particlesLight", (container) => new ParticlesLighter_1.ParticlesLighter(container), refresh);
|
|
23
23
|
}
|
|
24
24
|
exports.loadLightInteraction = loadLightInteraction;
|
|
25
25
|
__exportStar(require("./Options/Classes/Light"), exports);
|
package/esm/ExternalLighter.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExternalInteractorBase, isInArray, rangeColorToRgb } from "@tsparticles/engine";
|
|
1
|
+
import { ExternalInteractorBase, isInArray, rangeColorToRgb, } from "@tsparticles/engine";
|
|
2
2
|
import { Light } from "./Options/Classes/Light";
|
|
3
3
|
import { drawLight } from "./Utils";
|
|
4
4
|
export class ExternalLighter extends ExternalInteractorBase {
|
|
@@ -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
|
@@ -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/esm/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/esm/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ExternalLighter } from "./ExternalLighter";
|
|
2
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));
|
|
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
7
|
export * from "./Options/Classes/Light";
|
|
8
8
|
export * from "./Options/Classes/LightArea";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/interaction-light",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.0",
|
|
4
4
|
"description": "tsParticles Light interaction",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -73,6 +73,10 @@
|
|
|
73
73
|
"type": "github",
|
|
74
74
|
"url": "https://github.com/sponsors/matteobruni"
|
|
75
75
|
},
|
|
76
|
+
{
|
|
77
|
+
"type": "github",
|
|
78
|
+
"url": "https://github.com/sponsors/tsparticles"
|
|
79
|
+
},
|
|
76
80
|
{
|
|
77
81
|
"type": "buymeacoffee",
|
|
78
82
|
"url": "https://www.buymeacoffee.com/matteobruni"
|
|
@@ -83,10 +87,11 @@
|
|
|
83
87
|
"unpkg": "tsparticles.interaction.light.min.js",
|
|
84
88
|
"module": "esm/index.js",
|
|
85
89
|
"types": "types/index.d.ts",
|
|
90
|
+
"sideEffects": false,
|
|
91
|
+
"dependencies": {
|
|
92
|
+
"@tsparticles/engine": "^3.0.0-beta.0"
|
|
93
|
+
},
|
|
86
94
|
"publishConfig": {
|
|
87
95
|
"access": "public"
|
|
88
|
-
},
|
|
89
|
-
"dependencies": {
|
|
90
|
-
"@tsparticles/engine": "^3.0.0-alpha.0"
|
|
91
96
|
}
|
|
92
|
-
}
|
|
97
|
+
}
|