62 lines
2.7 KiB
JavaScript
62 lines
2.7 KiB
JavaScript
(function (factory) {
|
|
if (typeof module === "object" && typeof module.exports === "object") {
|
|
var v = factory(require, exports);
|
|
if (v !== undefined) module.exports = v;
|
|
}
|
|
else if (typeof define === "function" && define.amd) {
|
|
define(["require", "exports", "tsparticles-engine", "./Options/Classes/Slow"], factory);
|
|
}
|
|
})(function (require, exports) {
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.Slower = void 0;
|
|
const tsparticles_engine_1 = require("tsparticles-engine");
|
|
const Slow_1 = require("./Options/Classes/Slow");
|
|
class Slower extends tsparticles_engine_1.ExternalInteractorBase {
|
|
constructor(container) {
|
|
super(container);
|
|
}
|
|
clear(particle, delta, force) {
|
|
if (particle.slow.inRange && !force) {
|
|
return;
|
|
}
|
|
particle.slow.factor = 1;
|
|
}
|
|
init() {
|
|
const container = this.container, slow = container.actualOptions.interactivity.modes.slow;
|
|
if (!slow) {
|
|
return;
|
|
}
|
|
container.retina.slowModeRadius = slow.radius * container.retina.pixelRatio;
|
|
}
|
|
async interact() {
|
|
}
|
|
isEnabled(particle) {
|
|
var _a;
|
|
const container = this.container, mouse = container.interactivity.mouse, events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : container.actualOptions.interactivity).events;
|
|
return events.onHover.enable && !!mouse.position && (0, tsparticles_engine_1.isInArray)("slow", events.onHover.mode);
|
|
}
|
|
loadModeOptions(options, ...sources) {
|
|
if (!options.slow) {
|
|
options.slow = new Slow_1.Slow();
|
|
}
|
|
for (const source of sources) {
|
|
options.slow.load(source === null || source === void 0 ? void 0 : source.slow);
|
|
}
|
|
}
|
|
reset(particle) {
|
|
particle.slow.inRange = false;
|
|
const container = this.container, options = container.actualOptions, mousePos = container.interactivity.mouse.position, radius = container.retina.slowModeRadius, slow = options.interactivity.modes.slow;
|
|
if (!slow || !radius || radius < 0 || !mousePos) {
|
|
return;
|
|
}
|
|
const particlePos = particle.getPosition(), dist = (0, tsparticles_engine_1.getDistance)(mousePos, particlePos), proximityFactor = dist / radius, slowFactor = slow.factor;
|
|
if (dist <= radius) {
|
|
particle.slow.inRange = true;
|
|
particle.slow.factor = proximityFactor / slowFactor;
|
|
}
|
|
}
|
|
}
|
|
exports.Slower = Slower;
|
|
});
|