ziko
Version:
A versatile JavaScript library offering a rich set of Hyperscript Based UI components, advanced mathematical utilities, interactivity ,animations, client side routing and more ...
45 lines (41 loc) • 1.49 kB
JavaScript
import { getCoordinates } from "./utils/index.js";
const CATEGORY = 'ptr';
export const PtrListeners = {
onPtrDown(callback, useNormalizedCoordinates = false){
return this.on(
'pointerdown', callback,
{ category : CATEGORY, details_setter : (ctx)=> {
const {x, y} = getCoordinates(ctx, useNormalizedCoordinates);
ctx.dx = x;
ctx.dy = y;
ctx.isDown = true;
ctx.isDragging = ctx.isMoving ?? false
}}
)
},
onPtrMove(callback, useNormalizedCoordinates = false){
return this.on(
'pointermove', callback,
{ category : CATEGORY, details_setter : (ctx)=> {
const {x, y} = getCoordinates(ctx, useNormalizedCoordinates);
ctx.mx = x;
ctx.my = y;
ctx.isMoving = true;
ctx.isDragging = ctx.isDown ?? false
}}
)
},
onPtrUp(callback, useNormalizedCoordinates = false){
return this.on(
'pointerup', callback,
{ category : CATEGORY, details_setter : (ctx)=> {
const {x, y} = getCoordinates(ctx, useNormalizedCoordinates);
ctx.ux = x;
ctx.uy = y;
ctx.isDown = false;
ctx.isMoving = false;
ctx.isDragging = false;
}}
)
}
}