@tsparticles/interaction-light 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.
Files changed (77) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +68 -0
  3. package/browser/ExternalLighter.js +50 -0
  4. package/browser/Options/Classes/Light.js +15 -0
  5. package/browser/Options/Classes/LightArea.js +16 -0
  6. package/browser/Options/Classes/LightGradient.js +16 -0
  7. package/browser/Options/Classes/LightOptions.js +1 -0
  8. package/browser/Options/Classes/LightShadow.js +17 -0
  9. package/browser/Options/Interfaces/ILight.js +1 -0
  10. package/browser/Options/Interfaces/ILightArea.js +1 -0
  11. package/browser/Options/Interfaces/ILightGradient.js +1 -0
  12. package/browser/Options/Interfaces/ILightShadow.js +1 -0
  13. package/browser/ParticlesLighter.js +37 -0
  14. package/browser/Types.js +1 -0
  15. package/browser/Utils.js +58 -0
  16. package/browser/index.js +14 -0
  17. package/cjs/ExternalLighter.js +65 -0
  18. package/cjs/Options/Classes/Light.js +19 -0
  19. package/cjs/Options/Classes/LightArea.js +20 -0
  20. package/cjs/Options/Classes/LightGradient.js +20 -0
  21. package/cjs/Options/Classes/LightOptions.js +2 -0
  22. package/cjs/Options/Classes/LightShadow.js +21 -0
  23. package/cjs/Options/Interfaces/ILight.js +2 -0
  24. package/cjs/Options/Interfaces/ILightArea.js +2 -0
  25. package/cjs/Options/Interfaces/ILightGradient.js +2 -0
  26. package/cjs/Options/Interfaces/ILightShadow.js +2 -0
  27. package/cjs/ParticlesLighter.js +52 -0
  28. package/cjs/Types.js +2 -0
  29. package/cjs/Utils.js +63 -0
  30. package/cjs/index.js +32 -0
  31. package/esm/ExternalLighter.js +50 -0
  32. package/esm/Options/Classes/Light.js +15 -0
  33. package/esm/Options/Classes/LightArea.js +16 -0
  34. package/esm/Options/Classes/LightGradient.js +16 -0
  35. package/esm/Options/Classes/LightOptions.js +1 -0
  36. package/esm/Options/Classes/LightShadow.js +17 -0
  37. package/esm/Options/Interfaces/ILight.js +1 -0
  38. package/esm/Options/Interfaces/ILightArea.js +1 -0
  39. package/esm/Options/Interfaces/ILightGradient.js +1 -0
  40. package/esm/Options/Interfaces/ILightShadow.js +1 -0
  41. package/esm/ParticlesLighter.js +37 -0
  42. package/esm/Types.js +1 -0
  43. package/esm/Utils.js +58 -0
  44. package/esm/index.js +14 -0
  45. package/package.json +92 -0
  46. package/report.html +39 -0
  47. package/tsparticles.interaction.light.js +350 -0
  48. package/tsparticles.interaction.light.min.js +2 -0
  49. package/tsparticles.interaction.light.min.js.LICENSE.txt +8 -0
  50. package/types/ExternalLighter.d.ts +13 -0
  51. package/types/Options/Classes/Light.d.ts +10 -0
  52. package/types/Options/Classes/LightArea.d.ts +9 -0
  53. package/types/Options/Classes/LightGradient.d.ts +9 -0
  54. package/types/Options/Classes/LightOptions.d.ts +12 -0
  55. package/types/Options/Classes/LightShadow.d.ts +9 -0
  56. package/types/Options/Interfaces/ILight.d.ts +6 -0
  57. package/types/Options/Interfaces/ILightArea.d.ts +5 -0
  58. package/types/Options/Interfaces/ILightGradient.d.ts +5 -0
  59. package/types/Options/Interfaces/ILightShadow.d.ts +5 -0
  60. package/types/ParticlesLighter.d.ts +10 -0
  61. package/types/Types.d.ts +26 -0
  62. package/types/Utils.d.ts +4 -0
  63. package/types/index.d.ts +10 -0
  64. package/umd/ExternalLighter.js +64 -0
  65. package/umd/Options/Classes/Light.js +29 -0
  66. package/umd/Options/Classes/LightArea.js +30 -0
  67. package/umd/Options/Classes/LightGradient.js +30 -0
  68. package/umd/Options/Classes/LightOptions.js +12 -0
  69. package/umd/Options/Classes/LightShadow.js +31 -0
  70. package/umd/Options/Interfaces/ILight.js +12 -0
  71. package/umd/Options/Interfaces/ILightArea.js +12 -0
  72. package/umd/Options/Interfaces/ILightGradient.js +12 -0
  73. package/umd/Options/Interfaces/ILightShadow.js +12 -0
  74. package/umd/ParticlesLighter.js +51 -0
  75. package/umd/Types.js +12 -0
  76. package/umd/Utils.js +73 -0
  77. package/umd/index.js +42 -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,68 @@
1
+ [![banner](https://particles.js.org/images/banner3.png)](https://particles.js.org)
2
+
3
+ # tsParticles Light Interaction
4
+
5
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/tsparticles-interaction-light/badge)](https://www.jsdelivr.com/package/npm/tsparticles-interaction-light)
6
+ [![npmjs](https://badge.fury.io/js/tsparticles-interaction-light.svg)](https://www.npmjs.com/package/tsparticles-interaction-light)
7
+ [![npmjs](https://img.shields.io/npm/dt/tsparticles-interaction-light)](https://www.npmjs.com/package/tsparticles-interaction-light) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
8
+
9
+ [tsParticles](https://github.com/matteobruni/tsparticles) interaction plugin for light effect.
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.interaction.light.min.js` file will export the function to load the interaction plugin:
18
+
19
+ ```text
20
+ loadLightInteraction
21
+ ```
22
+
23
+ ### Usage
24
+
25
+ Once the scripts are loaded you can set up `tsParticles` and the interaction plugin like this:
26
+
27
+ ```javascript
28
+ loadLightInteraction(tsParticles);
29
+
30
+ tsParticles.load({
31
+ id: "tsparticles",
32
+ options: {
33
+ /* options */
34
+ },
35
+ });
36
+ ```
37
+
38
+ ### ESM / CommonJS
39
+
40
+ This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
41
+
42
+ ```shell
43
+ $ npm install tsparticles-interaction-light
44
+ ```
45
+
46
+ or
47
+
48
+ ```shell
49
+ $ yarn add tsparticles-interaction-light
50
+ ```
51
+
52
+ Then you need to import it in the app, like this:
53
+
54
+ ```javascript
55
+ const { tsParticles } = require("tsparticles-engine");
56
+ const { loadLightInteraction } = require("tsparticles-interaction-light");
57
+
58
+ loadLightInteraction(tsParticles);
59
+ ```
60
+
61
+ or
62
+
63
+ ```javascript
64
+ import { tsParticles } from "tsparticles-engine";
65
+ import { loadLightInteraction } from "tsparticles-interaction-light";
66
+
67
+ loadLightInteraction(tsParticles);
68
+ ```
@@ -0,0 +1,50 @@
1
+ import { ExternalInteractorBase, isInArray, rangeColorToRgb } from "@tsparticles/engine";
2
+ import { Light } from "./Options/Classes/Light";
3
+ import { drawLight } from "./Utils";
4
+ export class ExternalLighter extends ExternalInteractorBase {
5
+ constructor(container) {
6
+ super(container);
7
+ }
8
+ clear() {
9
+ }
10
+ init() {
11
+ }
12
+ async interact() {
13
+ const container = this.container, options = container.actualOptions;
14
+ if (options.interactivity.events.onHover.enable && container.interactivity.status === "pointermove") {
15
+ const mousePos = container.interactivity.mouse.position;
16
+ if (!mousePos) {
17
+ return;
18
+ }
19
+ container.canvas.draw((ctx) => {
20
+ drawLight(container, ctx, mousePos);
21
+ });
22
+ }
23
+ }
24
+ isEnabled(particle) {
25
+ var _a;
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;
27
+ if (!(events.onHover.enable && mouse.position)) {
28
+ return false;
29
+ }
30
+ const res = isInArray("light", events.onHover.mode);
31
+ if (res && interactivity.modes.light) {
32
+ const lightGradient = interactivity.modes.light.area.gradient;
33
+ container.canvas.mouseLight = {
34
+ start: rangeColorToRgb(lightGradient.start),
35
+ stop: rangeColorToRgb(lightGradient.stop),
36
+ };
37
+ }
38
+ return res;
39
+ }
40
+ loadModeOptions(options, ...sources) {
41
+ if (!options.light) {
42
+ options.light = new Light();
43
+ }
44
+ for (const source of sources) {
45
+ options.light.load(source === null || source === void 0 ? void 0 : source.light);
46
+ }
47
+ }
48
+ reset() {
49
+ }
50
+ }
@@ -0,0 +1,15 @@
1
+ import { LightArea } from "./LightArea";
2
+ import { LightShadow } from "./LightShadow";
3
+ export class Light {
4
+ constructor() {
5
+ this.area = new LightArea();
6
+ this.shadow = new LightShadow();
7
+ }
8
+ load(data) {
9
+ if (!data) {
10
+ return;
11
+ }
12
+ this.area.load(data.area);
13
+ this.shadow.load(data.shadow);
14
+ }
15
+ }
@@ -0,0 +1,16 @@
1
+ import { LightGradient } from "./LightGradient";
2
+ export class LightArea {
3
+ constructor() {
4
+ this.gradient = new LightGradient();
5
+ this.radius = 1000;
6
+ }
7
+ load(data) {
8
+ if (!data) {
9
+ return;
10
+ }
11
+ this.gradient.load(data.gradient);
12
+ if (data.radius !== undefined) {
13
+ this.radius = data.radius;
14
+ }
15
+ }
16
+ }
@@ -0,0 +1,16 @@
1
+ import { OptionsColor } from "@tsparticles/engine";
2
+ export class LightGradient {
3
+ constructor() {
4
+ this.start = new OptionsColor();
5
+ this.stop = new OptionsColor();
6
+ this.start.value = "#ffffff";
7
+ this.stop.value = "#000000";
8
+ }
9
+ load(data) {
10
+ if (!data) {
11
+ return;
12
+ }
13
+ this.start = OptionsColor.create(this.start, data.start);
14
+ this.stop = OptionsColor.create(this.stop, data.stop);
15
+ }
16
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import { OptionsColor } from "@tsparticles/engine";
2
+ export class LightShadow {
3
+ constructor() {
4
+ this.color = new OptionsColor();
5
+ this.color.value = "#000000";
6
+ this.length = 2000;
7
+ }
8
+ load(data) {
9
+ if (!data) {
10
+ return;
11
+ }
12
+ this.color = OptionsColor.create(this.color, data.color);
13
+ if (data.length !== undefined) {
14
+ this.length = data.length;
15
+ }
16
+ }
17
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,37 @@
1
+ import { ParticlesInteractorBase, isInArray, rangeColorToRgb } from "@tsparticles/engine";
2
+ import { drawParticleShadow } from "./Utils";
3
+ export class ParticlesLighter extends ParticlesInteractorBase {
4
+ constructor(container) {
5
+ super(container);
6
+ }
7
+ clear() {
8
+ }
9
+ init() {
10
+ }
11
+ async interact(particle) {
12
+ const container = this.container, options = container.actualOptions;
13
+ if (options.interactivity.events.onHover.enable && container.interactivity.status === "pointermove") {
14
+ const mousePos = this.container.interactivity.mouse.position;
15
+ if (mousePos) {
16
+ container.canvas.draw((ctx) => {
17
+ drawParticleShadow(container, ctx, particle, mousePos);
18
+ });
19
+ }
20
+ }
21
+ }
22
+ isEnabled(particle) {
23
+ var _a;
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
+ if (!(events.onHover.enable && mouse.position)) {
26
+ return false;
27
+ }
28
+ const res = isInArray("light", events.onHover.mode);
29
+ if (res && interactivity.modes.light) {
30
+ const shadowOptions = interactivity.modes.light.shadow;
31
+ particle.lightShadow = rangeColorToRgb(shadowOptions.color);
32
+ }
33
+ return res;
34
+ }
35
+ reset() {
36
+ }
37
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,58 @@
1
+ import { getStyleFromRgb } from "@tsparticles/engine";
2
+ export function drawLight(container, context, mousePos) {
3
+ var _a;
4
+ const lightOptions = (_a = container.actualOptions.interactivity.modes.light) === null || _a === void 0 ? void 0 : _a.area;
5
+ if (!lightOptions) {
6
+ return;
7
+ }
8
+ context.beginPath();
9
+ context.arc(mousePos.x, mousePos.y, lightOptions.radius, 0, 2 * Math.PI);
10
+ const gradientAmbientLight = context.createRadialGradient(mousePos.x, mousePos.y, 0, mousePos.x, mousePos.y, lightOptions.radius);
11
+ const gradientRgb = container.canvas.mouseLight;
12
+ if (!gradientRgb || !gradientRgb.start || !gradientRgb.stop) {
13
+ return;
14
+ }
15
+ gradientAmbientLight.addColorStop(0, getStyleFromRgb(gradientRgb.start));
16
+ gradientAmbientLight.addColorStop(1, getStyleFromRgb(gradientRgb.stop));
17
+ context.fillStyle = gradientAmbientLight;
18
+ context.fill();
19
+ }
20
+ export function drawParticleShadow(container, context, particle, mousePos) {
21
+ var _a;
22
+ const pos = particle.getPosition(), shadowOptions = (_a = container.actualOptions.interactivity.modes.light) === null || _a === void 0 ? void 0 : _a.shadow;
23
+ if (!shadowOptions) {
24
+ return;
25
+ }
26
+ const shadowRgb = particle.lightShadow;
27
+ if (!shadowRgb) {
28
+ return;
29
+ }
30
+ const radius = particle.getRadius(), sides = particle.sides, full = (Math.PI * 2) / sides, angle = -particle.rotation + Math.PI / 4, factor = 1, dots = [];
31
+ for (let i = 0; i < sides; i++) {
32
+ dots.push({
33
+ x: pos.x + radius * Math.sin(angle + full * i) * factor,
34
+ y: pos.y + radius * Math.cos(angle + full * i) * factor,
35
+ });
36
+ }
37
+ const points = [], shadowLength = shadowOptions.length;
38
+ for (const dot of dots) {
39
+ const dotAngle = Math.atan2(mousePos.y - dot.y, mousePos.x - dot.x), endX = dot.x + shadowLength * Math.sin(-dotAngle - Math.PI / 2), endY = dot.y + shadowLength * Math.cos(-dotAngle - Math.PI / 2);
40
+ points.push({
41
+ endX: endX,
42
+ endY: endY,
43
+ startX: dot.x,
44
+ startY: dot.y,
45
+ });
46
+ }
47
+ const shadowColor = getStyleFromRgb(shadowRgb);
48
+ for (let i = points.length - 1; i >= 0; i--) {
49
+ const n = i === points.length - 1 ? 0 : i + 1;
50
+ context.beginPath();
51
+ context.moveTo(points[i].startX, points[i].startY);
52
+ context.lineTo(points[n].startX, points[n].startY);
53
+ context.lineTo(points[n].endX, points[n].endY);
54
+ context.lineTo(points[i].endX, points[i].endY);
55
+ context.fillStyle = shadowColor;
56
+ context.fill();
57
+ }
58
+ }
@@ -0,0 +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));
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";
@@ -0,0 +1,65 @@
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.ExternalLighter = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ const Light_1 = require("./Options/Classes/Light");
15
+ const Utils_1 = require("./Utils");
16
+ class ExternalLighter extends engine_1.ExternalInteractorBase {
17
+ constructor(container) {
18
+ super(container);
19
+ }
20
+ clear() {
21
+ }
22
+ init() {
23
+ }
24
+ interact() {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const container = this.container, options = container.actualOptions;
27
+ if (options.interactivity.events.onHover.enable && container.interactivity.status === "pointermove") {
28
+ const mousePos = container.interactivity.mouse.position;
29
+ if (!mousePos) {
30
+ return;
31
+ }
32
+ container.canvas.draw((ctx) => {
33
+ (0, Utils_1.drawLight)(container, ctx, mousePos);
34
+ });
35
+ }
36
+ });
37
+ }
38
+ isEnabled(particle) {
39
+ var _a;
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;
41
+ if (!(events.onHover.enable && mouse.position)) {
42
+ return false;
43
+ }
44
+ const res = (0, engine_1.isInArray)("light", events.onHover.mode);
45
+ if (res && interactivity.modes.light) {
46
+ const lightGradient = interactivity.modes.light.area.gradient;
47
+ container.canvas.mouseLight = {
48
+ start: (0, engine_1.rangeColorToRgb)(lightGradient.start),
49
+ stop: (0, engine_1.rangeColorToRgb)(lightGradient.stop),
50
+ };
51
+ }
52
+ return res;
53
+ }
54
+ loadModeOptions(options, ...sources) {
55
+ if (!options.light) {
56
+ options.light = new Light_1.Light();
57
+ }
58
+ for (const source of sources) {
59
+ options.light.load(source === null || source === void 0 ? void 0 : source.light);
60
+ }
61
+ }
62
+ reset() {
63
+ }
64
+ }
65
+ exports.ExternalLighter = ExternalLighter;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Light = void 0;
4
+ const LightArea_1 = require("./LightArea");
5
+ const LightShadow_1 = require("./LightShadow");
6
+ class Light {
7
+ constructor() {
8
+ this.area = new LightArea_1.LightArea();
9
+ this.shadow = new LightShadow_1.LightShadow();
10
+ }
11
+ load(data) {
12
+ if (!data) {
13
+ return;
14
+ }
15
+ this.area.load(data.area);
16
+ this.shadow.load(data.shadow);
17
+ }
18
+ }
19
+ exports.Light = Light;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LightArea = void 0;
4
+ const LightGradient_1 = require("./LightGradient");
5
+ class LightArea {
6
+ constructor() {
7
+ this.gradient = new LightGradient_1.LightGradient();
8
+ this.radius = 1000;
9
+ }
10
+ load(data) {
11
+ if (!data) {
12
+ return;
13
+ }
14
+ this.gradient.load(data.gradient);
15
+ if (data.radius !== undefined) {
16
+ this.radius = data.radius;
17
+ }
18
+ }
19
+ }
20
+ exports.LightArea = LightArea;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LightGradient = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ class LightGradient {
6
+ constructor() {
7
+ this.start = new engine_1.OptionsColor();
8
+ this.stop = new engine_1.OptionsColor();
9
+ this.start.value = "#ffffff";
10
+ this.stop.value = "#000000";
11
+ }
12
+ load(data) {
13
+ if (!data) {
14
+ return;
15
+ }
16
+ this.start = engine_1.OptionsColor.create(this.start, data.start);
17
+ this.stop = engine_1.OptionsColor.create(this.stop, data.stop);
18
+ }
19
+ }
20
+ exports.LightGradient = LightGradient;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LightShadow = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ class LightShadow {
6
+ constructor() {
7
+ this.color = new engine_1.OptionsColor();
8
+ this.color.value = "#000000";
9
+ this.length = 2000;
10
+ }
11
+ load(data) {
12
+ if (!data) {
13
+ return;
14
+ }
15
+ this.color = engine_1.OptionsColor.create(this.color, data.color);
16
+ if (data.length !== undefined) {
17
+ this.length = data.length;
18
+ }
19
+ }
20
+ }
21
+ exports.LightShadow = LightShadow;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,52 @@
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.ParticlesLighter = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ const Utils_1 = require("./Utils");
15
+ class ParticlesLighter extends engine_1.ParticlesInteractorBase {
16
+ constructor(container) {
17
+ super(container);
18
+ }
19
+ clear() {
20
+ }
21
+ init() {
22
+ }
23
+ interact(particle) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const container = this.container, options = container.actualOptions;
26
+ if (options.interactivity.events.onHover.enable && container.interactivity.status === "pointermove") {
27
+ const mousePos = this.container.interactivity.mouse.position;
28
+ if (mousePos) {
29
+ container.canvas.draw((ctx) => {
30
+ (0, Utils_1.drawParticleShadow)(container, ctx, particle, mousePos);
31
+ });
32
+ }
33
+ }
34
+ });
35
+ }
36
+ isEnabled(particle) {
37
+ var _a;
38
+ const container = this.container, interactivity = (_a = particle.interactivity) !== null && _a !== void 0 ? _a : container.actualOptions.interactivity, mouse = container.interactivity.mouse, events = interactivity.events;
39
+ if (!(events.onHover.enable && mouse.position)) {
40
+ return false;
41
+ }
42
+ const res = (0, engine_1.isInArray)("light", events.onHover.mode);
43
+ if (res && interactivity.modes.light) {
44
+ const shadowOptions = interactivity.modes.light.shadow;
45
+ particle.lightShadow = (0, engine_1.rangeColorToRgb)(shadowOptions.color);
46
+ }
47
+ return res;
48
+ }
49
+ reset() {
50
+ }
51
+ }
52
+ exports.ParticlesLighter = ParticlesLighter;
package/cjs/Types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/Utils.js ADDED
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.drawParticleShadow = exports.drawLight = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ function drawLight(container, context, mousePos) {
6
+ var _a;
7
+ const lightOptions = (_a = container.actualOptions.interactivity.modes.light) === null || _a === void 0 ? void 0 : _a.area;
8
+ if (!lightOptions) {
9
+ return;
10
+ }
11
+ context.beginPath();
12
+ context.arc(mousePos.x, mousePos.y, lightOptions.radius, 0, 2 * Math.PI);
13
+ const gradientAmbientLight = context.createRadialGradient(mousePos.x, mousePos.y, 0, mousePos.x, mousePos.y, lightOptions.radius);
14
+ const gradientRgb = container.canvas.mouseLight;
15
+ if (!gradientRgb || !gradientRgb.start || !gradientRgb.stop) {
16
+ return;
17
+ }
18
+ gradientAmbientLight.addColorStop(0, (0, engine_1.getStyleFromRgb)(gradientRgb.start));
19
+ gradientAmbientLight.addColorStop(1, (0, engine_1.getStyleFromRgb)(gradientRgb.stop));
20
+ context.fillStyle = gradientAmbientLight;
21
+ context.fill();
22
+ }
23
+ exports.drawLight = drawLight;
24
+ function drawParticleShadow(container, context, particle, mousePos) {
25
+ var _a;
26
+ const pos = particle.getPosition(), shadowOptions = (_a = container.actualOptions.interactivity.modes.light) === null || _a === void 0 ? void 0 : _a.shadow;
27
+ if (!shadowOptions) {
28
+ return;
29
+ }
30
+ const shadowRgb = particle.lightShadow;
31
+ if (!shadowRgb) {
32
+ return;
33
+ }
34
+ const radius = particle.getRadius(), sides = particle.sides, full = (Math.PI * 2) / sides, angle = -particle.rotation + Math.PI / 4, factor = 1, dots = [];
35
+ for (let i = 0; i < sides; i++) {
36
+ dots.push({
37
+ x: pos.x + radius * Math.sin(angle + full * i) * factor,
38
+ y: pos.y + radius * Math.cos(angle + full * i) * factor,
39
+ });
40
+ }
41
+ const points = [], shadowLength = shadowOptions.length;
42
+ for (const dot of dots) {
43
+ const dotAngle = Math.atan2(mousePos.y - dot.y, mousePos.x - dot.x), endX = dot.x + shadowLength * Math.sin(-dotAngle - Math.PI / 2), endY = dot.y + shadowLength * Math.cos(-dotAngle - Math.PI / 2);
44
+ points.push({
45
+ endX: endX,
46
+ endY: endY,
47
+ startX: dot.x,
48
+ startY: dot.y,
49
+ });
50
+ }
51
+ const shadowColor = (0, engine_1.getStyleFromRgb)(shadowRgb);
52
+ for (let i = points.length - 1; i >= 0; i--) {
53
+ const n = i === points.length - 1 ? 0 : i + 1;
54
+ context.beginPath();
55
+ context.moveTo(points[i].startX, points[i].startY);
56
+ context.lineTo(points[n].startX, points[n].startY);
57
+ context.lineTo(points[n].endX, points[n].endY);
58
+ context.lineTo(points[i].endX, points[i].endY);
59
+ context.fillStyle = shadowColor;
60
+ context.fill();
61
+ }
62
+ }
63
+ exports.drawParticleShadow = drawParticleShadow;