@learn-hunger/visual-gestures
Version:
VisualGestures.js is a package that empowers users to effortlessly control the cursor, including actions such as hover, click, drag, and drop, through precise finger movements in the air.
133 lines • 5.73 kB
JavaScript
import { VgPointerEnter } from "../custom-events/vg-pointer-enter";
import { VgPointerLeave } from "../custom-events/vg-pointer-leave";
import { VgPointerMove } from "../custom-events/vg-pointer-move";
import { VgPointerDown } from "../custom-events/vg-pointer-down";
import { VgPointerUp } from "../custom-events/vg-pointer-up";
import { VgPointerClick } from "../custom-events/vg-pointer-click";
import { VgPointerDrop } from "../custom-events/vg-pointer-drop";
import { VgPointerDrag } from "../custom-events/vg-pointer-drag";
/**
* spefically events are triggered here
* corresponding event callbacks are triggered here
*
*/
export class AVgPointerEvents {
/**
* common utility to trigger events
* @param element
* @param event
*/
dispatch(element, event) {
element === null || element === void 0 ? void 0 : element.dispatchEvent(event);
}
/**
* resetting the event callbacks
*/
dispose() {
this._onPointerEnterCallback = undefined;
this._onPointerLeaveCallback = undefined;
this._onPointerMoveCallback = undefined;
this._onPointerDownCallback = undefined;
this._onPointerUpCallback = undefined;
this._onPointerClickCallback = undefined;
this._onPointerDragCallback = undefined;
this._onPointerDropCallback = undefined;
}
set onPointerMove(callback) {
this._onPointerMoveCallback = callback;
}
get onPointerMove() {
return this._onPointerMoveCallback;
}
triggerMouseMove(mouseInit, props) {
var _a, _b;
this.vgPointerMove = new VgPointerMove(mouseInit, props);
this.dispatch((_b = (_a = this.vgPointerMove) === null || _a === void 0 ? void 0 : _a.element) === null || _b === void 0 ? void 0 : _b.from, this.vgPointerMove);
this.onPointerMove && this.onPointerMove(this.vgPointerMove);
}
set onPointerEnter(callback) {
this._onPointerEnterCallback = callback;
}
get onPointerEnter() {
return this._onPointerEnterCallback;
}
triggerMouseEnter(mouseInit, props) {
var _a, _b;
this.vgPointerEnter = new VgPointerEnter(mouseInit, props);
this.dispatch((_b = (_a = this.vgPointerEnter) === null || _a === void 0 ? void 0 : _a.element) === null || _b === void 0 ? void 0 : _b.to, this.vgPointerEnter);
this.onPointerEnter && this.onPointerEnter(this.vgPointerEnter);
}
set onPointerLeave(callback) {
this._onPointerLeaveCallback = callback;
}
get onPointerLeave() {
return this._onPointerLeaveCallback;
}
triggerMouseLeave(mouseInit, props) {
var _a, _b;
this.vgPointerLeave = new VgPointerLeave(mouseInit, props);
this.dispatch((_b = (_a = this.vgPointerLeave) === null || _a === void 0 ? void 0 : _a.element) === null || _b === void 0 ? void 0 : _b.from, this.vgPointerLeave);
this.onPointerLeave && this.onPointerLeave(this.vgPointerLeave);
}
set onPointerDown(callback) {
this._onPointerDownCallback = callback;
}
get onPointerDown() {
return this._onPointerDownCallback;
}
triggerMouseDown(mouseInit, props) {
var _a, _b;
this.vgPointerDown = new VgPointerDown(mouseInit, props);
this.dispatch((_b = (_a = this.vgPointerDown) === null || _a === void 0 ? void 0 : _a.element) === null || _b === void 0 ? void 0 : _b.from, this.vgPointerDown);
this.onPointerDown && this.onPointerDown(this.vgPointerDown);
}
set onPointerUp(callback) {
this._onPointerUpCallback = callback;
}
get onPointerUp() {
return this._onPointerUpCallback;
}
triggerMouseUp(mouseInit, props) {
var _a, _b;
this.vgPointerUp = new VgPointerUp(mouseInit, props);
this.dispatch((_b = (_a = this.vgPointerUp) === null || _a === void 0 ? void 0 : _a.element) === null || _b === void 0 ? void 0 : _b.from, this.vgPointerUp);
this.onPointerUp && this.onPointerUp(this.vgPointerUp);
}
set onPointerClick(callback) {
this._onPointerClickCallback = callback;
}
get onPointerClick() {
return this._onPointerClickCallback;
}
triggerMouseClick(mouseInit, props) {
var _a, _b;
this.vgPointerClick = new VgPointerClick(mouseInit, props);
this.dispatch((_b = (_a = this.vgPointerClick) === null || _a === void 0 ? void 0 : _a.element) === null || _b === void 0 ? void 0 : _b.clickElement, this.vgPointerClick);
this.onPointerClick && this.onPointerClick(this.vgPointerClick);
}
set onPointerDrop(callback) {
this._onPointerDropCallback = callback;
}
get onPointerDrop() {
return this._onPointerDropCallback;
}
triggerMouseDrop(mouseInit, props) {
var _a, _b;
this.vgPointerDrop = new VgPointerDrop(mouseInit, props);
this.dispatch((_b = (_a = this.vgPointerDrop) === null || _a === void 0 ? void 0 : _a.element) === null || _b === void 0 ? void 0 : _b.dropElement, this.vgPointerDrop);
this.onPointerDrop && this.onPointerDrop(this.vgPointerDrop);
}
set onPointerDrag(callback) {
this._onPointerDragCallback = callback;
}
get onPointerDrag() {
return this._onPointerDragCallback;
}
triggerMouseDrag(mouseInit, props) {
var _a, _b;
this.vgPointerDrag = new VgPointerDrag(mouseInit, props);
this.dispatch((_b = (_a = this.vgPointerDrag) === null || _a === void 0 ? void 0 : _a.element) === null || _b === void 0 ? void 0 : _b.dragElement, this.vgPointerDrag);
this.onPointerDrag && this.onPointerDrag(this.vgPointerDrag);
}
}
//# sourceMappingURL=vg-pointer-events.js.map