@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/cjs/index.js ADDED
@@ -0,0 +1,32 @@
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 = 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));
23
+ }
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);
@@ -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
+ }
package/esm/Types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/esm/Utils.js ADDED
@@ -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
+ }
package/esm/index.js ADDED
@@ -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";
package/package.json ADDED
@@ -0,0 +1,92 @@
1
+ {
2
+ "name": "@tsparticles/interaction-light",
3
+ "version": "3.0.0-alpha.0",
4
+ "description": "tsParticles Light interaction",
5
+ "homepage": "https://particles.js.org",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/matteobruni/tsparticles.git",
9
+ "directory": "interactions/light"
10
+ },
11
+ "keywords": [
12
+ "front-end",
13
+ "frontend",
14
+ "tsparticles",
15
+ "particles.js",
16
+ "particlesjs",
17
+ "particles",
18
+ "particle",
19
+ "canvas",
20
+ "jsparticles",
21
+ "xparticles",
22
+ "particles-js",
23
+ "particles-bg",
24
+ "particles-bg-vue",
25
+ "particles-ts",
26
+ "particles.ts",
27
+ "react-particles-js",
28
+ "react-particles.js",
29
+ "react-particles",
30
+ "react",
31
+ "reactjs",
32
+ "vue-particles",
33
+ "ngx-particles",
34
+ "angular-particles",
35
+ "particleground",
36
+ "vue",
37
+ "vuejs",
38
+ "preact",
39
+ "preactjs",
40
+ "jquery",
41
+ "angularjs",
42
+ "angular",
43
+ "typescript",
44
+ "javascript",
45
+ "animation",
46
+ "web",
47
+ "html5",
48
+ "web-design",
49
+ "webdesign",
50
+ "css",
51
+ "html",
52
+ "css3",
53
+ "animated",
54
+ "background",
55
+ "confetti",
56
+ "canvas",
57
+ "fireworks",
58
+ "fireworks-js",
59
+ "confetti-js",
60
+ "confettijs",
61
+ "fireworksjs",
62
+ "canvas-confetti",
63
+ "@tsparticles/plugin",
64
+ "@tsparticles/interaction"
65
+ ],
66
+ "author": "Matteo Bruni <matteo.bruni@me.com>",
67
+ "license": "MIT",
68
+ "bugs": {
69
+ "url": "https://github.com/matteobruni/tsparticles/issues"
70
+ },
71
+ "funding": [
72
+ {
73
+ "type": "github",
74
+ "url": "https://github.com/sponsors/matteobruni"
75
+ },
76
+ {
77
+ "type": "buymeacoffee",
78
+ "url": "https://www.buymeacoffee.com/matteobruni"
79
+ }
80
+ ],
81
+ "main": "cjs/index.js",
82
+ "jsdelivr": "tsparticles.interaction.light.min.js",
83
+ "unpkg": "tsparticles.interaction.light.min.js",
84
+ "module": "esm/index.js",
85
+ "types": "types/index.d.ts",
86
+ "publishConfig": {
87
+ "access": "public"
88
+ },
89
+ "dependencies": {
90
+ "@tsparticles/engine": "^3.0.0-alpha.0"
91
+ }
92
+ }