@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.
Files changed (45) hide show
  1. package/README.md +25 -19
  2. package/browser/ExternalLighter.js +15 -15
  3. package/browser/Options/Classes/Light.js +2 -2
  4. package/browser/Options/Classes/LightArea.js +1 -1
  5. package/browser/ParticlesLighter.js +12 -11
  6. package/browser/Utils.js +14 -16
  7. package/browser/index.js +13 -13
  8. package/browser/package.json +1 -0
  9. package/cjs/ExternalLighter.js +16 -27
  10. package/cjs/Options/Classes/Light.js +4 -4
  11. package/cjs/Options/Classes/LightArea.js +2 -2
  12. package/cjs/ParticlesLighter.js +13 -23
  13. package/cjs/Utils.js +14 -16
  14. package/cjs/index.js +13 -13
  15. package/cjs/package.json +1 -0
  16. package/esm/ExternalLighter.js +15 -15
  17. package/esm/Options/Classes/Light.js +2 -2
  18. package/esm/Options/Classes/LightArea.js +1 -1
  19. package/esm/ParticlesLighter.js +12 -11
  20. package/esm/Utils.js +14 -16
  21. package/esm/index.js +13 -13
  22. package/esm/package.json +1 -0
  23. package/package.json +23 -6
  24. package/report.html +4 -4
  25. package/tsparticles.interaction.light.js +49 -48
  26. package/tsparticles.interaction.light.min.js +1 -1
  27. package/tsparticles.interaction.light.min.js.LICENSE.txt +1 -8
  28. package/types/ExternalLighter.d.ts +3 -4
  29. package/types/Options/Classes/Light.d.ts +3 -3
  30. package/types/Options/Classes/LightArea.d.ts +2 -2
  31. package/types/Options/Classes/LightGradient.d.ts +1 -1
  32. package/types/Options/Classes/LightOptions.d.ts +1 -1
  33. package/types/Options/Classes/LightShadow.d.ts +2 -3
  34. package/types/Options/Interfaces/ILight.d.ts +2 -2
  35. package/types/Options/Interfaces/ILightArea.d.ts +1 -1
  36. package/types/ParticlesLighter.d.ts +1 -1
  37. package/types/Types.d.ts +3 -3
  38. package/types/Utils.d.ts +2 -2
  39. package/types/index.d.ts +9 -9
  40. package/umd/ExternalLighter.js +16 -16
  41. package/umd/Options/Classes/Light.js +5 -5
  42. package/umd/Options/Classes/LightArea.js +3 -3
  43. package/umd/ParticlesLighter.js +13 -12
  44. package/umd/Utils.js +14 -16
  45. package/umd/index.js +14 -14
package/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  # tsParticles Light Interaction
4
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)
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
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
- loadLightInteraction(tsParticles);
29
-
30
- tsParticles.load({
31
- id: "tsparticles",
32
- options: {
33
- /* options */
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-interaction-light
45
+ $ npm install @tsparticles/interaction-light
44
46
  ```
45
47
 
46
48
  or
47
49
 
48
50
  ```shell
49
- $ yarn add tsparticles-interaction-light
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-engine");
56
- const { loadLightInteraction } = require("tsparticles-interaction-light");
57
+ const { tsParticles } = require("@tsparticles/engine");
58
+ const { loadLightInteraction } = require("@tsparticles/interaction-light");
57
59
 
58
- loadLightInteraction(tsParticles);
60
+ (async () => {
61
+ await loadLightInteraction(tsParticles);
62
+ })();
59
63
  ```
60
64
 
61
65
  or
62
66
 
63
67
  ```javascript
64
- import { tsParticles } from "tsparticles-engine";
65
- import { loadLightInteraction } from "tsparticles-interaction-light";
68
+ import { tsParticles } from "@tsparticles/engine";
69
+ import { loadLightInteraction } from "@tsparticles/interaction-light";
66
70
 
67
- loadLightInteraction(tsParticles);
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 && 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
- });
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
- 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;
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 === null || source === void 0 ? void 0 : source.light);
45
+ options.light.load(source?.light);
46
46
  }
47
47
  }
48
48
  reset() {
@@ -1,5 +1,5 @@
1
- import { LightArea } from "./LightArea";
2
- import { LightShadow } from "./LightShadow";
1
+ import { LightArea } from "./LightArea.js";
2
+ import { LightShadow } from "./LightShadow.js";
3
3
  export class Light {
4
4
  constructor() {
5
5
  this.area = new LightArea();
@@ -1,4 +1,4 @@
1
- import { LightGradient } from "./LightGradient";
1
+ import { LightGradient } from "./LightGradient.js";
2
2
  export class LightArea {
3
3
  constructor() {
4
4
  this.gradient = new LightGradient();
@@ -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 && 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
- }
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
- 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
+ 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
- var _a;
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
- var _a;
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), endX = dot.x + shadowLength * Math.sin(-dotAngle - Math.PI / 2), endY = dot.y + shadowLength * Math.cos(-dotAngle - Math.PI / 2);
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
- endX: endX,
42
- endY: endY,
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 = points.length - 1; i >= 0; 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].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);
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" }
@@ -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 Light_1 = require("./Options/Classes/Light");
15
- const Utils_1 = require("./Utils");
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
- 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
- }
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
- 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;
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 Light_1.Light();
45
+ options.light = new Light_js_1.Light();
57
46
  }
58
47
  for (const source of sources) {
59
- options.light.load(source === null || source === void 0 ? void 0 : source.light);
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 LightArea_1 = require("./LightArea");
5
- const LightShadow_1 = require("./LightShadow");
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 LightArea_1.LightArea();
9
- this.shadow = new LightShadow_1.LightShadow();
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 LightGradient_1 = require("./LightGradient");
4
+ const LightGradient_js_1 = require("./LightGradient.js");
5
5
  class LightArea {
6
6
  constructor() {
7
- this.gradient = new LightGradient_1.LightGradient();
7
+ this.gradient = new LightGradient_js_1.LightGradient();
8
8
  this.radius = 1000;
9
9
  }
10
10
  load(data) {
@@ -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 Utils_1 = require("./Utils");
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
- 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
- }
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
- 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;
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
- var _a;
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
- var _a;
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), endX = dot.x + shadowLength * Math.sin(-dotAngle - Math.PI / 2), endY = dot.y + shadowLength * Math.cos(-dotAngle - Math.PI / 2);
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
- endX: endX,
46
- endY: endY,
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 = points.length - 1; i >= 0; 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].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);
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 ExternalLighter_1 = require("./ExternalLighter");
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));
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);
@@ -0,0 +1 @@
1
+ { "type": "commonjs" }
@@ -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 && 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
- });
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
- 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;
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 === null || source === void 0 ? void 0 : source.light);
45
+ options.light.load(source?.light);
46
46
  }
47
47
  }
48
48
  reset() {
@@ -1,5 +1,5 @@
1
- import { LightArea } from "./LightArea";
2
- import { LightShadow } from "./LightShadow";
1
+ import { LightArea } from "./LightArea.js";
2
+ import { LightShadow } from "./LightShadow.js";
3
3
  export class Light {
4
4
  constructor() {
5
5
  this.area = new LightArea();
@@ -1,4 +1,4 @@
1
- import { LightGradient } from "./LightGradient";
1
+ import { LightGradient } from "./LightGradient.js";
2
2
  export class LightArea {
3
3
  constructor() {
4
4
  this.gradient = new LightGradient();
@@ -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 && 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
- }
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
- 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
+ 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
  }