@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.
- package/LICENSE +21 -0
- package/README.md +68 -0
- package/browser/ExternalLighter.js +50 -0
- package/browser/Options/Classes/Light.js +15 -0
- package/browser/Options/Classes/LightArea.js +16 -0
- package/browser/Options/Classes/LightGradient.js +16 -0
- package/browser/Options/Classes/LightOptions.js +1 -0
- package/browser/Options/Classes/LightShadow.js +17 -0
- package/browser/Options/Interfaces/ILight.js +1 -0
- package/browser/Options/Interfaces/ILightArea.js +1 -0
- package/browser/Options/Interfaces/ILightGradient.js +1 -0
- package/browser/Options/Interfaces/ILightShadow.js +1 -0
- package/browser/ParticlesLighter.js +37 -0
- package/browser/Types.js +1 -0
- package/browser/Utils.js +58 -0
- package/browser/index.js +14 -0
- package/cjs/ExternalLighter.js +65 -0
- package/cjs/Options/Classes/Light.js +19 -0
- package/cjs/Options/Classes/LightArea.js +20 -0
- package/cjs/Options/Classes/LightGradient.js +20 -0
- package/cjs/Options/Classes/LightOptions.js +2 -0
- package/cjs/Options/Classes/LightShadow.js +21 -0
- package/cjs/Options/Interfaces/ILight.js +2 -0
- package/cjs/Options/Interfaces/ILightArea.js +2 -0
- package/cjs/Options/Interfaces/ILightGradient.js +2 -0
- package/cjs/Options/Interfaces/ILightShadow.js +2 -0
- package/cjs/ParticlesLighter.js +52 -0
- package/cjs/Types.js +2 -0
- package/cjs/Utils.js +63 -0
- package/cjs/index.js +32 -0
- package/esm/ExternalLighter.js +50 -0
- package/esm/Options/Classes/Light.js +15 -0
- package/esm/Options/Classes/LightArea.js +16 -0
- package/esm/Options/Classes/LightGradient.js +16 -0
- package/esm/Options/Classes/LightOptions.js +1 -0
- package/esm/Options/Classes/LightShadow.js +17 -0
- package/esm/Options/Interfaces/ILight.js +1 -0
- package/esm/Options/Interfaces/ILightArea.js +1 -0
- package/esm/Options/Interfaces/ILightGradient.js +1 -0
- package/esm/Options/Interfaces/ILightShadow.js +1 -0
- package/esm/ParticlesLighter.js +37 -0
- package/esm/Types.js +1 -0
- package/esm/Utils.js +58 -0
- package/esm/index.js +14 -0
- package/package.json +92 -0
- package/report.html +39 -0
- package/tsparticles.interaction.light.js +350 -0
- package/tsparticles.interaction.light.min.js +2 -0
- package/tsparticles.interaction.light.min.js.LICENSE.txt +8 -0
- package/types/ExternalLighter.d.ts +13 -0
- package/types/Options/Classes/Light.d.ts +10 -0
- package/types/Options/Classes/LightArea.d.ts +9 -0
- package/types/Options/Classes/LightGradient.d.ts +9 -0
- package/types/Options/Classes/LightOptions.d.ts +12 -0
- package/types/Options/Classes/LightShadow.d.ts +9 -0
- package/types/Options/Interfaces/ILight.d.ts +6 -0
- package/types/Options/Interfaces/ILightArea.d.ts +5 -0
- package/types/Options/Interfaces/ILightGradient.d.ts +5 -0
- package/types/Options/Interfaces/ILightShadow.d.ts +5 -0
- package/types/ParticlesLighter.d.ts +10 -0
- package/types/Types.d.ts +26 -0
- package/types/Utils.d.ts +4 -0
- package/types/index.d.ts +10 -0
- package/umd/ExternalLighter.js +64 -0
- package/umd/Options/Classes/Light.js +29 -0
- package/umd/Options/Classes/LightArea.js +30 -0
- package/umd/Options/Classes/LightGradient.js +30 -0
- package/umd/Options/Classes/LightOptions.js +12 -0
- package/umd/Options/Classes/LightShadow.js +31 -0
- package/umd/Options/Interfaces/ILight.js +12 -0
- package/umd/Options/Interfaces/ILightArea.js +12 -0
- package/umd/Options/Interfaces/ILightGradient.js +12 -0
- package/umd/Options/Interfaces/ILightShadow.js +12 -0
- package/umd/ParticlesLighter.js +51 -0
- package/umd/Types.js +12 -0
- package/umd/Utils.js +73 -0
- package/umd/index.js +42 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LightGradient = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
class LightGradient {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.start = new engine_1.OptionsColor();
|
|
17
|
+
this.stop = new engine_1.OptionsColor();
|
|
18
|
+
this.start.value = "#ffffff";
|
|
19
|
+
this.stop.value = "#000000";
|
|
20
|
+
}
|
|
21
|
+
load(data) {
|
|
22
|
+
if (!data) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
this.start = engine_1.OptionsColor.create(this.start, data.start);
|
|
26
|
+
this.stop = engine_1.OptionsColor.create(this.stop, data.stop);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.LightGradient = LightGradient;
|
|
30
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LightShadow = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
class LightShadow {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.color = new engine_1.OptionsColor();
|
|
17
|
+
this.color.value = "#000000";
|
|
18
|
+
this.length = 2000;
|
|
19
|
+
}
|
|
20
|
+
load(data) {
|
|
21
|
+
if (!data) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
this.color = engine_1.OptionsColor.create(this.color, data.color);
|
|
25
|
+
if (data.length !== undefined) {
|
|
26
|
+
this.length = data.length;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.LightShadow = LightShadow;
|
|
31
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine", "./Utils"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
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
|
+
async interact(particle) {
|
|
24
|
+
const container = this.container, options = container.actualOptions;
|
|
25
|
+
if (options.interactivity.events.onHover.enable && container.interactivity.status === "pointermove") {
|
|
26
|
+
const mousePos = this.container.interactivity.mouse.position;
|
|
27
|
+
if (mousePos) {
|
|
28
|
+
container.canvas.draw((ctx) => {
|
|
29
|
+
(0, Utils_1.drawParticleShadow)(container, ctx, particle, mousePos);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
isEnabled(particle) {
|
|
35
|
+
var _a;
|
|
36
|
+
const container = this.container, interactivity = (_a = particle.interactivity) !== null && _a !== void 0 ? _a : container.actualOptions.interactivity, mouse = container.interactivity.mouse, events = interactivity.events;
|
|
37
|
+
if (!(events.onHover.enable && mouse.position)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const res = (0, engine_1.isInArray)("light", events.onHover.mode);
|
|
41
|
+
if (res && interactivity.modes.light) {
|
|
42
|
+
const shadowOptions = interactivity.modes.light.shadow;
|
|
43
|
+
particle.lightShadow = (0, engine_1.rangeColorToRgb)(shadowOptions.color);
|
|
44
|
+
}
|
|
45
|
+
return res;
|
|
46
|
+
}
|
|
47
|
+
reset() {
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.ParticlesLighter = ParticlesLighter;
|
|
51
|
+
});
|
package/umd/Types.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
package/umd/Utils.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
(function (factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
+
var v = factory(require, exports);
|
|
4
|
+
if (v !== undefined) module.exports = v;
|
|
5
|
+
}
|
|
6
|
+
else if (typeof define === "function" && define.amd) {
|
|
7
|
+
define(["require", "exports", "@tsparticles/engine"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.drawParticleShadow = exports.drawLight = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
function drawLight(container, context, mousePos) {
|
|
15
|
+
var _a;
|
|
16
|
+
const lightOptions = (_a = container.actualOptions.interactivity.modes.light) === null || _a === void 0 ? void 0 : _a.area;
|
|
17
|
+
if (!lightOptions) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
context.beginPath();
|
|
21
|
+
context.arc(mousePos.x, mousePos.y, lightOptions.radius, 0, 2 * Math.PI);
|
|
22
|
+
const gradientAmbientLight = context.createRadialGradient(mousePos.x, mousePos.y, 0, mousePos.x, mousePos.y, lightOptions.radius);
|
|
23
|
+
const gradientRgb = container.canvas.mouseLight;
|
|
24
|
+
if (!gradientRgb || !gradientRgb.start || !gradientRgb.stop) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
gradientAmbientLight.addColorStop(0, (0, engine_1.getStyleFromRgb)(gradientRgb.start));
|
|
28
|
+
gradientAmbientLight.addColorStop(1, (0, engine_1.getStyleFromRgb)(gradientRgb.stop));
|
|
29
|
+
context.fillStyle = gradientAmbientLight;
|
|
30
|
+
context.fill();
|
|
31
|
+
}
|
|
32
|
+
exports.drawLight = drawLight;
|
|
33
|
+
function drawParticleShadow(container, context, particle, mousePos) {
|
|
34
|
+
var _a;
|
|
35
|
+
const pos = particle.getPosition(), shadowOptions = (_a = container.actualOptions.interactivity.modes.light) === null || _a === void 0 ? void 0 : _a.shadow;
|
|
36
|
+
if (!shadowOptions) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const shadowRgb = particle.lightShadow;
|
|
40
|
+
if (!shadowRgb) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const radius = particle.getRadius(), sides = particle.sides, full = (Math.PI * 2) / sides, angle = -particle.rotation + Math.PI / 4, factor = 1, dots = [];
|
|
44
|
+
for (let i = 0; i < sides; i++) {
|
|
45
|
+
dots.push({
|
|
46
|
+
x: pos.x + radius * Math.sin(angle + full * i) * factor,
|
|
47
|
+
y: pos.y + radius * Math.cos(angle + full * i) * factor,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const points = [], shadowLength = shadowOptions.length;
|
|
51
|
+
for (const dot of dots) {
|
|
52
|
+
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);
|
|
53
|
+
points.push({
|
|
54
|
+
endX: endX,
|
|
55
|
+
endY: endY,
|
|
56
|
+
startX: dot.x,
|
|
57
|
+
startY: dot.y,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const shadowColor = (0, engine_1.getStyleFromRgb)(shadowRgb);
|
|
61
|
+
for (let i = points.length - 1; i >= 0; i--) {
|
|
62
|
+
const n = i === points.length - 1 ? 0 : i + 1;
|
|
63
|
+
context.beginPath();
|
|
64
|
+
context.moveTo(points[i].startX, points[i].startY);
|
|
65
|
+
context.lineTo(points[n].startX, points[n].startY);
|
|
66
|
+
context.lineTo(points[n].endX, points[n].endY);
|
|
67
|
+
context.lineTo(points[i].endX, points[i].endY);
|
|
68
|
+
context.fillStyle = shadowColor;
|
|
69
|
+
context.fill();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.drawParticleShadow = drawParticleShadow;
|
|
73
|
+
});
|
package/umd/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
|
+
if (k2 === undefined) k2 = k;
|
|
3
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(o, k2, desc);
|
|
8
|
+
}) : (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
o[k2] = m[k];
|
|
11
|
+
}));
|
|
12
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
13
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
14
|
+
};
|
|
15
|
+
(function (factory) {
|
|
16
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
17
|
+
var v = factory(require, exports);
|
|
18
|
+
if (v !== undefined) module.exports = v;
|
|
19
|
+
}
|
|
20
|
+
else if (typeof define === "function" && define.amd) {
|
|
21
|
+
define(["require", "exports", "./ExternalLighter", "./ParticlesLighter", "./Options/Classes/Light", "./Options/Classes/LightArea", "./Options/Classes/LightGradient", "./Options/Classes/LightShadow", "./Options/Interfaces/ILight", "./Options/Interfaces/ILightArea", "./Options/Interfaces/ILightGradient", "./Options/Interfaces/ILightShadow"], factory);
|
|
22
|
+
}
|
|
23
|
+
})(function (require, exports) {
|
|
24
|
+
"use strict";
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.loadLightInteraction = void 0;
|
|
27
|
+
const ExternalLighter_1 = require("./ExternalLighter");
|
|
28
|
+
const ParticlesLighter_1 = require("./ParticlesLighter");
|
|
29
|
+
function loadLightInteraction(engine) {
|
|
30
|
+
engine.addInteractor("externalLight", (container) => new ExternalLighter_1.ExternalLighter(container));
|
|
31
|
+
engine.addInteractor("particlesLight", (container) => new ParticlesLighter_1.ParticlesLighter(container));
|
|
32
|
+
}
|
|
33
|
+
exports.loadLightInteraction = loadLightInteraction;
|
|
34
|
+
__exportStar(require("./Options/Classes/Light"), exports);
|
|
35
|
+
__exportStar(require("./Options/Classes/LightArea"), exports);
|
|
36
|
+
__exportStar(require("./Options/Classes/LightGradient"), exports);
|
|
37
|
+
__exportStar(require("./Options/Classes/LightShadow"), exports);
|
|
38
|
+
__exportStar(require("./Options/Interfaces/ILight"), exports);
|
|
39
|
+
__exportStar(require("./Options/Interfaces/ILightArea"), exports);
|
|
40
|
+
__exportStar(require("./Options/Interfaces/ILightGradient"), exports);
|
|
41
|
+
__exportStar(require("./Options/Interfaces/ILightShadow"), exports);
|
|
42
|
+
});
|