@tsparticles/interaction-light 3.9.1 → 4.0.0-alpha.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 (38) hide show
  1. package/271.min.js +2 -0
  2. package/271.min.js.LICENSE.txt +1 -0
  3. package/547.min.js +2 -0
  4. package/547.min.js.LICENSE.txt +1 -0
  5. package/browser/ExternalLighter.js +1 -3
  6. package/browser/ParticlesLighter.js +1 -1
  7. package/browser/Utils.js +11 -7
  8. package/browser/index.js +12 -14
  9. package/cjs/ExternalLighter.js +9 -15
  10. package/cjs/Options/Classes/Light.js +7 -11
  11. package/cjs/Options/Classes/LightArea.js +5 -9
  12. package/cjs/Options/Classes/LightGradient.js +7 -11
  13. package/cjs/Options/Classes/LightOptions.js +1 -2
  14. package/cjs/Options/Classes/LightShadow.js +5 -9
  15. package/cjs/Options/Interfaces/ILight.js +1 -2
  16. package/cjs/Options/Interfaces/ILightArea.js +1 -2
  17. package/cjs/Options/Interfaces/ILightGradient.js +1 -2
  18. package/cjs/Options/Interfaces/ILightShadow.js +1 -2
  19. package/cjs/ParticlesLighter.js +7 -11
  20. package/cjs/Types.js +1 -2
  21. package/cjs/Utils.js +15 -16
  22. package/cjs/index.js +16 -35
  23. package/dist_browser_ExternalLighter_js.js +40 -0
  24. package/dist_browser_ParticlesLighter_js.js +40 -0
  25. package/esm/ExternalLighter.js +1 -3
  26. package/esm/ParticlesLighter.js +1 -1
  27. package/esm/Utils.js +11 -7
  28. package/esm/index.js +12 -14
  29. package/package.json +4 -3
  30. package/report.html +5 -4
  31. package/tsparticles.interaction.light.js +225 -66
  32. package/tsparticles.interaction.light.min.js +1 -1
  33. package/tsparticles.interaction.light.min.js.LICENSE.txt +1 -1
  34. package/types/index.d.ts +5 -5
  35. package/umd/ExternalLighter.js +1 -3
  36. package/umd/ParticlesLighter.js +1 -1
  37. package/umd/Utils.js +11 -7
  38. package/umd/index.js +36 -15
package/271.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 271.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_interaction_light=this.webpackChunk_tsparticles_interaction_light||[]).push([[271],{271(t,n,e){e.d(n,{ExternalLighter:()=>s});var i=e(303),o=e(324),a=e(831);class s extends i.ExternalInteractorBase{constructor(t,n){super(t),this._engine=n}clear(){}init(){}interact(){const t=this.container,n=t.actualOptions,e=t.interactivity;if(!n.interactivity.events.onHover.enable||"pointermove"!==e.status)return;const i=e.mouse.position;i&&t.canvas.draw((n=>{(0,o.tM)(t,n,i)}))}isEnabled(t){const n=this.container,e=n.interactivity.mouse,a=t?.interactivity??n.actualOptions.interactivity,s=a.events;if(!s.onHover.enable||!e.position)return!1;const r=(0,i.isInArray)(o.EF,s.onHover.mode);if(r&&a.modes.light){const t=a.modes.light.area.gradient;n.canvas.mouseLight={start:(0,i.rangeColorToRgb)(this._engine,t.start),stop:(0,i.rangeColorToRgb)(this._engine,t.stop)}}return r}loadModeOptions(t,...n){t.light??=new a.v;for(const e of n)t.light.load(e?.light)}reset(){}}},324(t,n,e){e.d(n,{EF:()=>l,No:()=>d,tM:()=>h});var i=e(303);const o=1,a=0,s=.5*Math.PI,r=2*Math.PI,c=.25*Math.PI,l="light";function h(t,n,e){const s=t.actualOptions.interactivity.modes.light?.area;if(!s)return;n.beginPath(),n.arc(e.x,e.y,s.radius,0,r);const c=n.createRadialGradient(e.x,e.y,0,e.x,e.y,s.radius),l=t.canvas.mouseLight;l?.start&&l.stop&&(c.addColorStop(a,(0,i.getStyleFromRgb)(l.start,t.hdr)),c.addColorStop(o,(0,i.getStyleFromRgb)(l.stop,t.hdr)),n.fillStyle=c,n.fill())}function d(t,n,e,o){const a=e.getPosition(),l=t.actualOptions.interactivity.modes.light?.shadow;if(!l)return;const h=e.lightShadow;if(!h)return;const d=e.getRadius(),g=e.sides,u=r/g,y=-e.rotation+c,p=[];for(let t=0;t<g;t++)p.push({x:a.x+d*Math.sin(y+u*t)*1,y:a.y+d*Math.cos(y+u*t)*1});const v=[],f=l.length;for(const t of p){const n=Math.atan2(o.y-t.y,o.x-t.x),e={x:t.x+f*Math.sin(-n-s),y:t.y+f*Math.cos(-n-s)};v.push({end:e,start:t})}const x=(0,i.getStyleFromRgb)(h,t.hdr);for(let t=v.length-1,e=0;t>=0;e=t--){n.beginPath();const i=v[t],o=v[e];i&&o&&(n.moveTo(i.start.x,i.start.y),n.lineTo(o.start.x,o.start.y),n.lineTo(o.end.x,o.end.y),n.lineTo(i.end.x,i.end.y),n.fillStyle=x,n.fill())}}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Light Interaction v4.0.0-alpha.1 by Matteo Bruni */
package/547.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 547.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_interaction_light=this.webpackChunk_tsparticles_interaction_light||[]).push([[547],{324(t,e,i){i.d(e,{EF:()=>l,No:()=>d,tM:()=>h});var n=i(303);const o=1,s=0,a=.5*Math.PI,r=2*Math.PI,c=.25*Math.PI,l="light";function h(t,e,i){const a=t.actualOptions.interactivity.modes.light?.area;if(!a)return;e.beginPath(),e.arc(i.x,i.y,a.radius,0,r);const c=e.createRadialGradient(i.x,i.y,0,i.x,i.y,a.radius),l=t.canvas.mouseLight;l?.start&&l.stop&&(c.addColorStop(s,(0,n.getStyleFromRgb)(l.start,t.hdr)),c.addColorStop(o,(0,n.getStyleFromRgb)(l.stop,t.hdr)),e.fillStyle=c,e.fill())}function d(t,e,i,o){const s=i.getPosition(),l=t.actualOptions.interactivity.modes.light?.shadow;if(!l)return;const h=i.lightShadow;if(!h)return;const d=i.getRadius(),g=i.sides,u=r/g,y=-i.rotation+c,p=[];for(let t=0;t<g;t++)p.push({x:s.x+d*Math.sin(y+u*t)*1,y:s.y+d*Math.cos(y+u*t)*1});const v=[],f=l.length;for(const t of p){const e=Math.atan2(o.y-t.y,o.x-t.x),i={x:t.x+f*Math.sin(-e-a),y:t.y+f*Math.cos(-e-a)};v.push({end:i,start:t})}const x=(0,n.getStyleFromRgb)(h,t.hdr);for(let t=v.length-1,i=0;t>=0;i=t--){e.beginPath();const n=v[t],o=v[i];n&&o&&(e.moveTo(n.start.x,n.start.y),e.lineTo(o.start.x,o.start.y),e.lineTo(o.end.x,o.end.y),e.lineTo(n.end.x,n.end.y),e.fillStyle=x,e.fill())}}},547(t,e,i){i.d(e,{ParticlesLighter:()=>s});var n=i(303),o=i(324);class s extends n.ParticlesInteractorBase{constructor(t,e){super(t),this._engine=e}clear(){}init(){}interact(t){const e=this.container,i=e.actualOptions,n=e.interactivity;if(!i.interactivity.events.onHover.enable||"pointermove"!==n.status)return;const s=n.mouse.position;s&&e.canvas.draw((i=>{(0,o.No)(e,i,t,s)}))}isEnabled(t){const e=this.container,i=t.interactivity,s=e.interactivity.mouse,a=i.events;if(!a.onHover.enable||!s.position)return!1;const r=(0,n.isInArray)(o.EF,a.onHover.mode);if(r&&i.modes.light){const e=i.modes.light.shadow;t.lightShadow=(0,n.rangeColorToRgb)(this._engine,e.color)}return r}reset(){}}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Light Interaction v4.0.0-alpha.1 by Matteo Bruni */
@@ -39,9 +39,7 @@ export class ExternalLighter extends ExternalInteractorBase {
39
39
  return res;
40
40
  }
41
41
  loadModeOptions(options, ...sources) {
42
- if (!options.light) {
43
- options.light = new Light();
44
- }
42
+ options.light ??= new Light();
45
43
  for (const source of sources) {
46
44
  options.light.load(source?.light);
47
45
  }
@@ -23,7 +23,7 @@ export class ParticlesLighter extends ParticlesInteractorBase {
23
23
  });
24
24
  }
25
25
  isEnabled(particle) {
26
- const container = this.container, interactivity = particle.interactivity ?? container.actualOptions.interactivity, mouse = container.interactivity.mouse, events = interactivity.events;
26
+ const container = this.container, interactivity = particle.interactivity, mouse = container.interactivity.mouse, events = interactivity.events;
27
27
  if (!(events.onHover.enable && mouse.position)) {
28
28
  return false;
29
29
  }
package/browser/Utils.js CHANGED
@@ -16,8 +16,8 @@ export function drawLight(container, context, mousePos) {
16
16
  if (!gradientRgb?.start || !gradientRgb.stop) {
17
17
  return;
18
18
  }
19
- gradientAmbientLight.addColorStop(gradientPos.min, getStyleFromRgb(gradientRgb.start));
20
- gradientAmbientLight.addColorStop(gradientPos.max, getStyleFromRgb(gradientRgb.stop));
19
+ gradientAmbientLight.addColorStop(gradientPos.min, getStyleFromRgb(gradientRgb.start, container.hdr));
20
+ gradientAmbientLight.addColorStop(gradientPos.max, getStyleFromRgb(gradientRgb.stop, container.hdr));
21
21
  context.fillStyle = gradientAmbientLight;
22
22
  context.fill();
23
23
  }
@@ -48,13 +48,17 @@ export function drawParticleShadow(container, context, particle, mousePos) {
48
48
  start: dot,
49
49
  });
50
50
  }
51
- const shadowColor = getStyleFromRgb(shadowRgb), lastOffset = 1, firstPos = 0, last = points.length - lastOffset;
51
+ const shadowColor = getStyleFromRgb(shadowRgb, container.hdr), lastOffset = 1, firstPos = 0, last = points.length - lastOffset;
52
52
  for (let i = last, n = 0; i >= firstPos; n = i--) {
53
53
  context.beginPath();
54
- context.moveTo(points[i].start.x, points[i].start.y);
55
- context.lineTo(points[n].start.x, points[n].start.y);
56
- context.lineTo(points[n].end.x, points[n].end.y);
57
- context.lineTo(points[i].end.x, points[i].end.y);
54
+ const iPoint = points[i], nPoint = points[n];
55
+ if (!iPoint || !nPoint) {
56
+ continue;
57
+ }
58
+ context.moveTo(iPoint.start.x, iPoint.start.y);
59
+ context.lineTo(nPoint.start.x, nPoint.start.y);
60
+ context.lineTo(nPoint.end.x, nPoint.end.y);
61
+ context.lineTo(iPoint.end.x, iPoint.end.y);
58
62
  context.fillStyle = shadowColor;
59
63
  context.fill();
60
64
  }
package/browser/index.js CHANGED
@@ -1,19 +1,17 @@
1
- import { ExternalLighter } from "./ExternalLighter.js";
2
- import { ParticlesLighter } from "./ParticlesLighter.js";
3
- export async function loadLightInteraction(engine, refresh = true) {
4
- engine.checkVersion("3.9.1");
5
- await engine.addInteractor("externalLight", container => {
6
- return Promise.resolve(new ExternalLighter(container, engine));
7
- }, refresh);
8
- await engine.addInteractor("particlesLight", container => {
9
- return Promise.resolve(new ParticlesLighter(container, engine));
10
- }, refresh);
1
+ export function loadLightInteraction(engine) {
2
+ engine.checkVersion("4.0.0-alpha.1");
3
+ engine.register(e => {
4
+ e.addInteractor("externalLight", async (container) => {
5
+ const { ExternalLighter } = await import("./ExternalLighter.js");
6
+ return new ExternalLighter(container, engine);
7
+ });
8
+ e.addInteractor("particlesLight", async (container) => {
9
+ const { ParticlesLighter } = await import("./ParticlesLighter.js");
10
+ return new ParticlesLighter(container, engine);
11
+ });
12
+ });
11
13
  }
12
14
  export * from "./Options/Classes/Light.js";
13
15
  export * from "./Options/Classes/LightArea.js";
14
16
  export * from "./Options/Classes/LightGradient.js";
15
17
  export * from "./Options/Classes/LightShadow.js";
16
- export * from "./Options/Interfaces/ILight.js";
17
- export * from "./Options/Interfaces/ILightArea.js";
18
- export * from "./Options/Interfaces/ILightGradient.js";
19
- export * from "./Options/Interfaces/ILightShadow.js";
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExternalLighter = void 0;
4
- const engine_1 = require("@tsparticles/engine");
5
- const Utils_js_1 = require("./Utils.js");
6
- const Light_js_1 = require("./Options/Classes/Light.js");
7
- class ExternalLighter extends engine_1.ExternalInteractorBase {
1
+ import { ExternalInteractorBase, isInArray, rangeColorToRgb, } from "@tsparticles/engine";
2
+ import { drawLight, lightMode } from "./Utils.js";
3
+ import { Light } from "./Options/Classes/Light.js";
4
+ export class ExternalLighter extends ExternalInteractorBase {
8
5
  constructor(container, engine) {
9
6
  super(container);
10
7
  this._engine = engine;
@@ -23,7 +20,7 @@ class ExternalLighter extends engine_1.ExternalInteractorBase {
23
20
  return;
24
21
  }
25
22
  container.canvas.draw(ctx => {
26
- (0, Utils_js_1.drawLight)(container, ctx, mousePos);
23
+ drawLight(container, ctx, mousePos);
27
24
  });
28
25
  }
29
26
  isEnabled(particle) {
@@ -31,20 +28,18 @@ class ExternalLighter extends engine_1.ExternalInteractorBase {
31
28
  if (!(events.onHover.enable && mouse.position)) {
32
29
  return false;
33
30
  }
34
- const res = (0, engine_1.isInArray)(Utils_js_1.lightMode, events.onHover.mode);
31
+ const res = isInArray(lightMode, events.onHover.mode);
35
32
  if (res && interactivity.modes.light) {
36
33
  const lightGradient = interactivity.modes.light.area.gradient;
37
34
  container.canvas.mouseLight = {
38
- start: (0, engine_1.rangeColorToRgb)(this._engine, lightGradient.start),
39
- stop: (0, engine_1.rangeColorToRgb)(this._engine, lightGradient.stop),
35
+ start: rangeColorToRgb(this._engine, lightGradient.start),
36
+ stop: rangeColorToRgb(this._engine, lightGradient.stop),
40
37
  };
41
38
  }
42
39
  return res;
43
40
  }
44
41
  loadModeOptions(options, ...sources) {
45
- if (!options.light) {
46
- options.light = new Light_js_1.Light();
47
- }
42
+ options.light ??= new Light();
48
43
  for (const source of sources) {
49
44
  options.light.load(source?.light);
50
45
  }
@@ -52,4 +47,3 @@ class ExternalLighter extends engine_1.ExternalInteractorBase {
52
47
  reset() {
53
48
  }
54
49
  }
55
- exports.ExternalLighter = ExternalLighter;
@@ -1,20 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Light = void 0;
4
- const engine_1 = require("@tsparticles/engine");
5
- const LightArea_js_1 = require("./LightArea.js");
6
- const LightShadow_js_1 = require("./LightShadow.js");
7
- class Light {
1
+ import { isNull } from "@tsparticles/engine";
2
+ import { LightArea } from "./LightArea.js";
3
+ import { LightShadow } from "./LightShadow.js";
4
+ export class Light {
8
5
  constructor() {
9
- this.area = new LightArea_js_1.LightArea();
10
- this.shadow = new LightShadow_js_1.LightShadow();
6
+ this.area = new LightArea();
7
+ this.shadow = new LightShadow();
11
8
  }
12
9
  load(data) {
13
- if ((0, engine_1.isNull)(data)) {
10
+ if (isNull(data)) {
14
11
  return;
15
12
  }
16
13
  this.area.load(data.area);
17
14
  this.shadow.load(data.shadow);
18
15
  }
19
16
  }
20
- exports.Light = Light;
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LightArea = void 0;
4
- const engine_1 = require("@tsparticles/engine");
5
- const LightGradient_js_1 = require("./LightGradient.js");
6
- class LightArea {
1
+ import { isNull } from "@tsparticles/engine";
2
+ import { LightGradient } from "./LightGradient.js";
3
+ export class LightArea {
7
4
  constructor() {
8
- this.gradient = new LightGradient_js_1.LightGradient();
5
+ this.gradient = new LightGradient();
9
6
  this.radius = 1000;
10
7
  }
11
8
  load(data) {
12
- if ((0, engine_1.isNull)(data)) {
9
+ if (isNull(data)) {
13
10
  return;
14
11
  }
15
12
  this.gradient.load(data.gradient);
@@ -18,4 +15,3 @@ class LightArea {
18
15
  }
19
16
  }
20
17
  }
21
- exports.LightArea = LightArea;
@@ -1,20 +1,16 @@
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 {
1
+ import { OptionsColor, isNull } from "@tsparticles/engine";
2
+ export class LightGradient {
6
3
  constructor() {
7
- this.start = new engine_1.OptionsColor();
8
- this.stop = new engine_1.OptionsColor();
4
+ this.start = new OptionsColor();
5
+ this.stop = new OptionsColor();
9
6
  this.start.value = "#ffffff";
10
7
  this.stop.value = "#000000";
11
8
  }
12
9
  load(data) {
13
- if ((0, engine_1.isNull)(data)) {
10
+ if (isNull(data)) {
14
11
  return;
15
12
  }
16
- this.start = engine_1.OptionsColor.create(this.start, data.start);
17
- this.stop = engine_1.OptionsColor.create(this.stop, data.stop);
13
+ this.start = OptionsColor.create(this.start, data.start);
14
+ this.stop = OptionsColor.create(this.stop, data.stop);
18
15
  }
19
16
  }
20
- exports.LightGradient = LightGradient;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,21 +1,17 @@
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 {
1
+ import { OptionsColor, isNull } from "@tsparticles/engine";
2
+ export class LightShadow {
6
3
  constructor() {
7
- this.color = new engine_1.OptionsColor();
4
+ this.color = new OptionsColor();
8
5
  this.color.value = "#000000";
9
6
  this.length = 2000;
10
7
  }
11
8
  load(data) {
12
- if ((0, engine_1.isNull)(data)) {
9
+ if (isNull(data)) {
13
10
  return;
14
11
  }
15
- this.color = engine_1.OptionsColor.create(this.color, data.color);
12
+ this.color = OptionsColor.create(this.color, data.color);
16
13
  if (data.length !== undefined) {
17
14
  this.length = data.length;
18
15
  }
19
16
  }
20
17
  }
21
- exports.LightShadow = LightShadow;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ParticlesLighter = void 0;
4
- const engine_1 = require("@tsparticles/engine");
5
- const Utils_js_1 = require("./Utils.js");
6
- class ParticlesLighter extends engine_1.ParticlesInteractorBase {
1
+ import { ParticlesInteractorBase, isInArray, rangeColorToRgb } from "@tsparticles/engine";
2
+ import { drawParticleShadow, lightMode } from "./Utils.js";
3
+ export class ParticlesLighter extends ParticlesInteractorBase {
7
4
  constructor(container, engine) {
8
5
  super(container);
9
6
  this._engine = engine;
@@ -22,22 +19,21 @@ class ParticlesLighter extends engine_1.ParticlesInteractorBase {
22
19
  return;
23
20
  }
24
21
  container.canvas.draw(ctx => {
25
- (0, Utils_js_1.drawParticleShadow)(container, ctx, particle, mousePos);
22
+ drawParticleShadow(container, ctx, particle, mousePos);
26
23
  });
27
24
  }
28
25
  isEnabled(particle) {
29
- const container = this.container, interactivity = particle.interactivity ?? container.actualOptions.interactivity, mouse = container.interactivity.mouse, events = interactivity.events;
26
+ const container = this.container, interactivity = particle.interactivity, mouse = container.interactivity.mouse, events = interactivity.events;
30
27
  if (!(events.onHover.enable && mouse.position)) {
31
28
  return false;
32
29
  }
33
- const res = (0, engine_1.isInArray)(Utils_js_1.lightMode, events.onHover.mode);
30
+ const res = isInArray(lightMode, events.onHover.mode);
34
31
  if (res && interactivity.modes.light) {
35
32
  const shadowOptions = interactivity.modes.light.shadow;
36
- particle.lightShadow = (0, engine_1.rangeColorToRgb)(this._engine, shadowOptions.color);
33
+ particle.lightShadow = rangeColorToRgb(this._engine, shadowOptions.color);
37
34
  }
38
35
  return res;
39
36
  }
40
37
  reset() {
41
38
  }
42
39
  }
43
- exports.ParticlesLighter = ParticlesLighter;
package/cjs/Types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
package/cjs/Utils.js CHANGED
@@ -1,15 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lightMode = void 0;
4
- exports.drawLight = drawLight;
5
- exports.drawParticleShadow = drawParticleShadow;
6
- const engine_1 = require("@tsparticles/engine");
1
+ import { getStyleFromRgb } from "@tsparticles/engine";
7
2
  const gradientPos = {
8
3
  max: 1,
9
4
  min: 0,
10
5
  }, half = 0.5, double = 2, halfPI = Math.PI * half, doublePI = Math.PI * double, quarter = 0.25, quarterPI = Math.PI * quarter, arcStart = 0;
11
- exports.lightMode = "light";
12
- function drawLight(container, context, mousePos) {
6
+ export const lightMode = "light";
7
+ export function drawLight(container, context, mousePos) {
13
8
  const lightOptions = container.actualOptions.interactivity.modes.light?.area;
14
9
  if (!lightOptions) {
15
10
  return;
@@ -21,12 +16,12 @@ function drawLight(container, context, mousePos) {
21
16
  if (!gradientRgb?.start || !gradientRgb.stop) {
22
17
  return;
23
18
  }
24
- gradientAmbientLight.addColorStop(gradientPos.min, (0, engine_1.getStyleFromRgb)(gradientRgb.start));
25
- gradientAmbientLight.addColorStop(gradientPos.max, (0, engine_1.getStyleFromRgb)(gradientRgb.stop));
19
+ gradientAmbientLight.addColorStop(gradientPos.min, getStyleFromRgb(gradientRgb.start, container.hdr));
20
+ gradientAmbientLight.addColorStop(gradientPos.max, getStyleFromRgb(gradientRgb.stop, container.hdr));
26
21
  context.fillStyle = gradientAmbientLight;
27
22
  context.fill();
28
23
  }
29
- function drawParticleShadow(container, context, particle, mousePos) {
24
+ export function drawParticleShadow(container, context, particle, mousePos) {
30
25
  const pos = particle.getPosition(), shadowOptions = container.actualOptions.interactivity.modes.light?.shadow;
31
26
  if (!shadowOptions) {
32
27
  return;
@@ -53,13 +48,17 @@ function drawParticleShadow(container, context, particle, mousePos) {
53
48
  start: dot,
54
49
  });
55
50
  }
56
- const shadowColor = (0, engine_1.getStyleFromRgb)(shadowRgb), lastOffset = 1, firstPos = 0, last = points.length - lastOffset;
51
+ const shadowColor = getStyleFromRgb(shadowRgb, container.hdr), lastOffset = 1, firstPos = 0, last = points.length - lastOffset;
57
52
  for (let i = last, n = 0; i >= firstPos; n = i--) {
58
53
  context.beginPath();
59
- context.moveTo(points[i].start.x, points[i].start.y);
60
- context.lineTo(points[n].start.x, points[n].start.y);
61
- context.lineTo(points[n].end.x, points[n].end.y);
62
- context.lineTo(points[i].end.x, points[i].end.y);
54
+ const iPoint = points[i], nPoint = points[n];
55
+ if (!iPoint || !nPoint) {
56
+ continue;
57
+ }
58
+ context.moveTo(iPoint.start.x, iPoint.start.y);
59
+ context.lineTo(nPoint.start.x, nPoint.start.y);
60
+ context.lineTo(nPoint.end.x, nPoint.end.y);
61
+ context.lineTo(iPoint.end.x, iPoint.end.y);
63
62
  context.fillStyle = shadowColor;
64
63
  context.fill();
65
64
  }
package/cjs/index.js CHANGED
@@ -1,36 +1,17 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.loadLightInteraction = loadLightInteraction;
18
- const ExternalLighter_js_1 = require("./ExternalLighter.js");
19
- const ParticlesLighter_js_1 = require("./ParticlesLighter.js");
20
- async function loadLightInteraction(engine, refresh = true) {
21
- engine.checkVersion("3.9.1");
22
- await engine.addInteractor("externalLight", container => {
23
- return Promise.resolve(new ExternalLighter_js_1.ExternalLighter(container, engine));
24
- }, refresh);
25
- await engine.addInteractor("particlesLight", container => {
26
- return Promise.resolve(new ParticlesLighter_js_1.ParticlesLighter(container, engine));
27
- }, refresh);
1
+ export function loadLightInteraction(engine) {
2
+ engine.checkVersion("4.0.0-alpha.1");
3
+ engine.register(e => {
4
+ e.addInteractor("externalLight", async (container) => {
5
+ const { ExternalLighter } = await import("./ExternalLighter.js");
6
+ return new ExternalLighter(container, engine);
7
+ });
8
+ e.addInteractor("particlesLight", async (container) => {
9
+ const { ParticlesLighter } = await import("./ParticlesLighter.js");
10
+ return new ParticlesLighter(container, engine);
11
+ });
12
+ });
28
13
  }
29
- __exportStar(require("./Options/Classes/Light.js"), exports);
30
- __exportStar(require("./Options/Classes/LightArea.js"), exports);
31
- __exportStar(require("./Options/Classes/LightGradient.js"), exports);
32
- __exportStar(require("./Options/Classes/LightShadow.js"), exports);
33
- __exportStar(require("./Options/Interfaces/ILight.js"), exports);
34
- __exportStar(require("./Options/Interfaces/ILightArea.js"), exports);
35
- __exportStar(require("./Options/Interfaces/ILightGradient.js"), exports);
36
- __exportStar(require("./Options/Interfaces/ILightShadow.js"), exports);
14
+ export * from "./Options/Classes/Light.js";
15
+ export * from "./Options/Classes/LightArea.js";
16
+ export * from "./Options/Classes/LightGradient.js";
17
+ export * from "./Options/Classes/LightShadow.js";
@@ -0,0 +1,40 @@
1
+ /*!
2
+ * Author : Matteo Bruni
3
+ * MIT license: https://opensource.org/licenses/MIT
4
+ * Demo / Generator : https://particles.js.org/
5
+ * GitHub : https://www.github.com/matteobruni/tsparticles
6
+ * How to use? : Check the GitHub README
7
+ * v4.0.0-alpha.1
8
+ */
9
+ "use strict";
10
+ /*
11
+ * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
12
+ * This devtool is neither made for production nor for readable output files.
13
+ * It uses "eval()" calls to create a separate source file in the browser devtools.
14
+ * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
15
+ * or disable the default devtool with "devtool: false".
16
+ * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
17
+ */
18
+ (this["webpackChunk_tsparticles_interaction_light"] = this["webpackChunk_tsparticles_interaction_light"] || []).push([["dist_browser_ExternalLighter_js"],{
19
+
20
+ /***/ "./dist/browser/ExternalLighter.js"
21
+ /*!*****************************************!*\
22
+ !*** ./dist/browser/ExternalLighter.js ***!
23
+ \*****************************************/
24
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
25
+
26
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ ExternalLighter: () => (/* binding */ ExternalLighter)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Utils.js */ \"./dist/browser/Utils.js\");\n/* harmony import */ var _Options_Classes_Light_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Options/Classes/Light.js */ \"./dist/browser/Options/Classes/Light.js\");\n\n\n\nclass ExternalLighter extends _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.ExternalInteractorBase {\n constructor(container, engine) {\n super(container);\n this._engine = engine;\n }\n clear() {}\n init() {}\n interact() {\n const container = this.container,\n options = container.actualOptions,\n interactivity = container.interactivity;\n if (!options.interactivity.events.onHover.enable || interactivity.status !== \"pointermove\") {\n return;\n }\n const mousePos = interactivity.mouse.position;\n if (!mousePos) {\n return;\n }\n container.canvas.draw(ctx => {\n (0,_Utils_js__WEBPACK_IMPORTED_MODULE_1__.drawLight)(container, ctx, mousePos);\n });\n }\n isEnabled(particle) {\n const container = this.container,\n mouse = container.interactivity.mouse,\n interactivity = particle?.interactivity ?? container.actualOptions.interactivity,\n events = interactivity.events;\n if (!(events.onHover.enable && mouse.position)) {\n return false;\n }\n const res = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(_Utils_js__WEBPACK_IMPORTED_MODULE_1__.lightMode, events.onHover.mode);\n if (res && interactivity.modes.light) {\n const lightGradient = interactivity.modes.light.area.gradient;\n container.canvas.mouseLight = {\n start: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.rangeColorToRgb)(this._engine, lightGradient.start),\n stop: (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.rangeColorToRgb)(this._engine, lightGradient.stop)\n };\n }\n return res;\n }\n loadModeOptions(options, ...sources) {\n options.light ??= new _Options_Classes_Light_js__WEBPACK_IMPORTED_MODULE_2__.Light();\n for (const source of sources) {\n options.light.load(source?.light);\n }\n }\n reset() {}\n}\n\n//# sourceURL=webpack://@tsparticles/interaction-light/./dist/browser/ExternalLighter.js?\n}");
27
+
28
+ /***/ },
29
+
30
+ /***/ "./dist/browser/Utils.js"
31
+ /*!*******************************!*\
32
+ !*** ./dist/browser/Utils.js ***!
33
+ \*******************************/
34
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
35
+
36
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ drawLight: () => (/* binding */ drawLight),\n/* harmony export */ drawParticleShadow: () => (/* binding */ drawParticleShadow),\n/* harmony export */ lightMode: () => (/* binding */ lightMode)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nconst gradientPos = {\n max: 1,\n min: 0\n },\n half = 0.5,\n double = 2,\n halfPI = Math.PI * half,\n doublePI = Math.PI * double,\n quarter = 0.25,\n quarterPI = Math.PI * quarter,\n arcStart = 0;\nconst lightMode = \"light\";\nfunction drawLight(container, context, mousePos) {\n const lightOptions = container.actualOptions.interactivity.modes.light?.area;\n if (!lightOptions) {\n return;\n }\n context.beginPath();\n context.arc(mousePos.x, mousePos.y, lightOptions.radius, arcStart, doublePI);\n const gradientAmbientLight = context.createRadialGradient(mousePos.x, mousePos.y, arcStart, mousePos.x, mousePos.y, lightOptions.radius);\n const gradientRgb = container.canvas.mouseLight;\n if (!gradientRgb?.start || !gradientRgb.stop) {\n return;\n }\n gradientAmbientLight.addColorStop(gradientPos.min, (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getStyleFromRgb)(gradientRgb.start, container.hdr));\n gradientAmbientLight.addColorStop(gradientPos.max, (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getStyleFromRgb)(gradientRgb.stop, container.hdr));\n context.fillStyle = gradientAmbientLight;\n context.fill();\n}\nfunction drawParticleShadow(container, context, particle, mousePos) {\n const pos = particle.getPosition(),\n shadowOptions = container.actualOptions.interactivity.modes.light?.shadow;\n if (!shadowOptions) {\n return;\n }\n const shadowRgb = particle.lightShadow;\n if (!shadowRgb) {\n return;\n }\n const radius = particle.getRadius(),\n sides = particle.sides,\n full = doublePI / sides,\n angle = -particle.rotation + quarterPI,\n factor = 1,\n dots = [];\n for (let i = 0; i < sides; i++) {\n dots.push({\n x: pos.x + radius * Math.sin(angle + full * i) * factor,\n y: pos.y + radius * Math.cos(angle + full * i) * factor\n });\n }\n const points = [],\n shadowLength = shadowOptions.length;\n for (const dot of dots) {\n const dotAngle = Math.atan2(mousePos.y - dot.y, mousePos.x - dot.x),\n end = {\n x: dot.x + shadowLength * Math.sin(-dotAngle - halfPI),\n y: dot.y + shadowLength * Math.cos(-dotAngle - halfPI)\n };\n points.push({\n end: end,\n start: dot\n });\n }\n const shadowColor = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getStyleFromRgb)(shadowRgb, container.hdr),\n lastOffset = 1,\n firstPos = 0,\n last = points.length - lastOffset;\n for (let i = last, n = 0; i >= firstPos; n = i--) {\n context.beginPath();\n const iPoint = points[i],\n nPoint = points[n];\n if (!iPoint || !nPoint) {\n continue;\n }\n context.moveTo(iPoint.start.x, iPoint.start.y);\n context.lineTo(nPoint.start.x, nPoint.start.y);\n context.lineTo(nPoint.end.x, nPoint.end.y);\n context.lineTo(iPoint.end.x, iPoint.end.y);\n context.fillStyle = shadowColor;\n context.fill();\n }\n}\n\n//# sourceURL=webpack://@tsparticles/interaction-light/./dist/browser/Utils.js?\n}");
37
+
38
+ /***/ }
39
+
40
+ }]);
@@ -0,0 +1,40 @@
1
+ /*!
2
+ * Author : Matteo Bruni
3
+ * MIT license: https://opensource.org/licenses/MIT
4
+ * Demo / Generator : https://particles.js.org/
5
+ * GitHub : https://www.github.com/matteobruni/tsparticles
6
+ * How to use? : Check the GitHub README
7
+ * v4.0.0-alpha.1
8
+ */
9
+ "use strict";
10
+ /*
11
+ * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
12
+ * This devtool is neither made for production nor for readable output files.
13
+ * It uses "eval()" calls to create a separate source file in the browser devtools.
14
+ * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
15
+ * or disable the default devtool with "devtool: false".
16
+ * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
17
+ */
18
+ (this["webpackChunk_tsparticles_interaction_light"] = this["webpackChunk_tsparticles_interaction_light"] || []).push([["dist_browser_ParticlesLighter_js"],{
19
+
20
+ /***/ "./dist/browser/ParticlesLighter.js"
21
+ /*!******************************************!*\
22
+ !*** ./dist/browser/ParticlesLighter.js ***!
23
+ \******************************************/
24
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
25
+
26
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ ParticlesLighter: () => (/* binding */ ParticlesLighter)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Utils.js */ \"./dist/browser/Utils.js\");\n\n\nclass ParticlesLighter extends _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.ParticlesInteractorBase {\n constructor(container, engine) {\n super(container);\n this._engine = engine;\n }\n clear() {}\n init() {}\n interact(particle) {\n const container = this.container,\n options = container.actualOptions,\n interactivity = container.interactivity;\n if (!options.interactivity.events.onHover.enable || interactivity.status !== \"pointermove\") {\n return;\n }\n const mousePos = interactivity.mouse.position;\n if (!mousePos) {\n return;\n }\n container.canvas.draw(ctx => {\n (0,_Utils_js__WEBPACK_IMPORTED_MODULE_1__.drawParticleShadow)(container, ctx, particle, mousePos);\n });\n }\n isEnabled(particle) {\n const container = this.container,\n interactivity = particle.interactivity,\n mouse = container.interactivity.mouse,\n events = interactivity.events;\n if (!(events.onHover.enable && mouse.position)) {\n return false;\n }\n const res = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(_Utils_js__WEBPACK_IMPORTED_MODULE_1__.lightMode, events.onHover.mode);\n if (res && interactivity.modes.light) {\n const shadowOptions = interactivity.modes.light.shadow;\n particle.lightShadow = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.rangeColorToRgb)(this._engine, shadowOptions.color);\n }\n return res;\n }\n reset() {}\n}\n\n//# sourceURL=webpack://@tsparticles/interaction-light/./dist/browser/ParticlesLighter.js?\n}");
27
+
28
+ /***/ },
29
+
30
+ /***/ "./dist/browser/Utils.js"
31
+ /*!*******************************!*\
32
+ !*** ./dist/browser/Utils.js ***!
33
+ \*******************************/
34
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
35
+
36
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ drawLight: () => (/* binding */ drawLight),\n/* harmony export */ drawParticleShadow: () => (/* binding */ drawParticleShadow),\n/* harmony export */ lightMode: () => (/* binding */ lightMode)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nconst gradientPos = {\n max: 1,\n min: 0\n },\n half = 0.5,\n double = 2,\n halfPI = Math.PI * half,\n doublePI = Math.PI * double,\n quarter = 0.25,\n quarterPI = Math.PI * quarter,\n arcStart = 0;\nconst lightMode = \"light\";\nfunction drawLight(container, context, mousePos) {\n const lightOptions = container.actualOptions.interactivity.modes.light?.area;\n if (!lightOptions) {\n return;\n }\n context.beginPath();\n context.arc(mousePos.x, mousePos.y, lightOptions.radius, arcStart, doublePI);\n const gradientAmbientLight = context.createRadialGradient(mousePos.x, mousePos.y, arcStart, mousePos.x, mousePos.y, lightOptions.radius);\n const gradientRgb = container.canvas.mouseLight;\n if (!gradientRgb?.start || !gradientRgb.stop) {\n return;\n }\n gradientAmbientLight.addColorStop(gradientPos.min, (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getStyleFromRgb)(gradientRgb.start, container.hdr));\n gradientAmbientLight.addColorStop(gradientPos.max, (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getStyleFromRgb)(gradientRgb.stop, container.hdr));\n context.fillStyle = gradientAmbientLight;\n context.fill();\n}\nfunction drawParticleShadow(container, context, particle, mousePos) {\n const pos = particle.getPosition(),\n shadowOptions = container.actualOptions.interactivity.modes.light?.shadow;\n if (!shadowOptions) {\n return;\n }\n const shadowRgb = particle.lightShadow;\n if (!shadowRgb) {\n return;\n }\n const radius = particle.getRadius(),\n sides = particle.sides,\n full = doublePI / sides,\n angle = -particle.rotation + quarterPI,\n factor = 1,\n dots = [];\n for (let i = 0; i < sides; i++) {\n dots.push({\n x: pos.x + radius * Math.sin(angle + full * i) * factor,\n y: pos.y + radius * Math.cos(angle + full * i) * factor\n });\n }\n const points = [],\n shadowLength = shadowOptions.length;\n for (const dot of dots) {\n const dotAngle = Math.atan2(mousePos.y - dot.y, mousePos.x - dot.x),\n end = {\n x: dot.x + shadowLength * Math.sin(-dotAngle - halfPI),\n y: dot.y + shadowLength * Math.cos(-dotAngle - halfPI)\n };\n points.push({\n end: end,\n start: dot\n });\n }\n const shadowColor = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getStyleFromRgb)(shadowRgb, container.hdr),\n lastOffset = 1,\n firstPos = 0,\n last = points.length - lastOffset;\n for (let i = last, n = 0; i >= firstPos; n = i--) {\n context.beginPath();\n const iPoint = points[i],\n nPoint = points[n];\n if (!iPoint || !nPoint) {\n continue;\n }\n context.moveTo(iPoint.start.x, iPoint.start.y);\n context.lineTo(nPoint.start.x, nPoint.start.y);\n context.lineTo(nPoint.end.x, nPoint.end.y);\n context.lineTo(iPoint.end.x, iPoint.end.y);\n context.fillStyle = shadowColor;\n context.fill();\n }\n}\n\n//# sourceURL=webpack://@tsparticles/interaction-light/./dist/browser/Utils.js?\n}");
37
+
38
+ /***/ }
39
+
40
+ }]);
@@ -39,9 +39,7 @@ export class ExternalLighter extends ExternalInteractorBase {
39
39
  return res;
40
40
  }
41
41
  loadModeOptions(options, ...sources) {
42
- if (!options.light) {
43
- options.light = new Light();
44
- }
42
+ options.light ??= new Light();
45
43
  for (const source of sources) {
46
44
  options.light.load(source?.light);
47
45
  }
@@ -23,7 +23,7 @@ export class ParticlesLighter extends ParticlesInteractorBase {
23
23
  });
24
24
  }
25
25
  isEnabled(particle) {
26
- const container = this.container, interactivity = particle.interactivity ?? container.actualOptions.interactivity, mouse = container.interactivity.mouse, events = interactivity.events;
26
+ const container = this.container, interactivity = particle.interactivity, mouse = container.interactivity.mouse, events = interactivity.events;
27
27
  if (!(events.onHover.enable && mouse.position)) {
28
28
  return false;
29
29
  }
package/esm/Utils.js CHANGED
@@ -16,8 +16,8 @@ export function drawLight(container, context, mousePos) {
16
16
  if (!gradientRgb?.start || !gradientRgb.stop) {
17
17
  return;
18
18
  }
19
- gradientAmbientLight.addColorStop(gradientPos.min, getStyleFromRgb(gradientRgb.start));
20
- gradientAmbientLight.addColorStop(gradientPos.max, getStyleFromRgb(gradientRgb.stop));
19
+ gradientAmbientLight.addColorStop(gradientPos.min, getStyleFromRgb(gradientRgb.start, container.hdr));
20
+ gradientAmbientLight.addColorStop(gradientPos.max, getStyleFromRgb(gradientRgb.stop, container.hdr));
21
21
  context.fillStyle = gradientAmbientLight;
22
22
  context.fill();
23
23
  }
@@ -48,13 +48,17 @@ export function drawParticleShadow(container, context, particle, mousePos) {
48
48
  start: dot,
49
49
  });
50
50
  }
51
- const shadowColor = getStyleFromRgb(shadowRgb), lastOffset = 1, firstPos = 0, last = points.length - lastOffset;
51
+ const shadowColor = getStyleFromRgb(shadowRgb, container.hdr), lastOffset = 1, firstPos = 0, last = points.length - lastOffset;
52
52
  for (let i = last, n = 0; i >= firstPos; n = i--) {
53
53
  context.beginPath();
54
- context.moveTo(points[i].start.x, points[i].start.y);
55
- context.lineTo(points[n].start.x, points[n].start.y);
56
- context.lineTo(points[n].end.x, points[n].end.y);
57
- context.lineTo(points[i].end.x, points[i].end.y);
54
+ const iPoint = points[i], nPoint = points[n];
55
+ if (!iPoint || !nPoint) {
56
+ continue;
57
+ }
58
+ context.moveTo(iPoint.start.x, iPoint.start.y);
59
+ context.lineTo(nPoint.start.x, nPoint.start.y);
60
+ context.lineTo(nPoint.end.x, nPoint.end.y);
61
+ context.lineTo(iPoint.end.x, iPoint.end.y);
58
62
  context.fillStyle = shadowColor;
59
63
  context.fill();
60
64
  }