81 lines
3.6 KiB
JavaScript
81 lines
3.6 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/Trail"], factory);
|
|
}
|
|
})(function (require, exports) {
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.TrailMaker = void 0;
|
|
const tsparticles_engine_1 = require("tsparticles-engine");
|
|
const Trail_1 = require("./Options/Classes/Trail");
|
|
class TrailMaker extends tsparticles_engine_1.ExternalInteractorBase {
|
|
constructor(container) {
|
|
super(container);
|
|
this._delay = 0;
|
|
}
|
|
clear() {
|
|
}
|
|
init() {
|
|
}
|
|
async interact(delta) {
|
|
var _a, _b, _c, _d;
|
|
if (!this.container.retina.reduceFactor) {
|
|
return;
|
|
}
|
|
const container = this.container, options = container.actualOptions, trailOptions = options.interactivity.modes.trail;
|
|
if (!trailOptions) {
|
|
return;
|
|
}
|
|
const optDelay = (trailOptions.delay * 1000) / this.container.retina.reduceFactor;
|
|
if (this._delay < optDelay) {
|
|
this._delay += delta.value;
|
|
}
|
|
if (this._delay < optDelay) {
|
|
return;
|
|
}
|
|
let canEmit = true;
|
|
if (trailOptions.pauseOnStop) {
|
|
if (container.interactivity.mouse.position === this._lastPosition ||
|
|
(((_a = container.interactivity.mouse.position) === null || _a === void 0 ? void 0 : _a.x) === ((_b = this._lastPosition) === null || _b === void 0 ? void 0 : _b.x) &&
|
|
((_c = container.interactivity.mouse.position) === null || _c === void 0 ? void 0 : _c.y) === ((_d = this._lastPosition) === null || _d === void 0 ? void 0 : _d.y))) {
|
|
canEmit = false;
|
|
}
|
|
}
|
|
if (container.interactivity.mouse.position) {
|
|
this._lastPosition = {
|
|
x: container.interactivity.mouse.position.x,
|
|
y: container.interactivity.mouse.position.y,
|
|
};
|
|
}
|
|
else {
|
|
delete this._lastPosition;
|
|
}
|
|
if (canEmit) {
|
|
container.particles.push(trailOptions.quantity, container.interactivity.mouse, trailOptions.particles);
|
|
}
|
|
this._delay -= optDelay;
|
|
}
|
|
isEnabled(particle) {
|
|
var _a;
|
|
const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : options.interactivity).events;
|
|
return ((mouse.clicking && mouse.inside && !!mouse.position && (0, tsparticles_engine_1.isInArray)("trail", events.onClick.mode)) ||
|
|
(mouse.inside && !!mouse.position && (0, tsparticles_engine_1.isInArray)("trail", events.onHover.mode)));
|
|
}
|
|
loadModeOptions(options, ...sources) {
|
|
if (!options.trail) {
|
|
options.trail = new Trail_1.Trail();
|
|
}
|
|
for (const source of sources) {
|
|
options.trail.load(source === null || source === void 0 ? void 0 : source.trail);
|
|
}
|
|
}
|
|
reset() {
|
|
}
|
|
}
|
|
exports.TrailMaker = TrailMaker;
|
|
});
|