@interactjs/utils
Advanced tools
Comparing version 1.7.1 to 1.7.2
14
arr.d.ts
@@ -1,6 +0,8 @@ | ||
export declare function contains(array: any, target: any): boolean; | ||
export declare function remove(array: any, target: any): any; | ||
export declare function merge(target: any, source: any): any; | ||
export declare function from(source: any): any; | ||
export declare function findIndex(array: any, func: any): number; | ||
export declare function find(array: any, func: any): any; | ||
declare type Filter<T> = (element: T, index: number, array: T[]) => boolean; | ||
export declare function contains<T>(array: T[], target: T): boolean; | ||
export declare function remove<T>(array: T[], target: T): T[]; | ||
export declare function merge<T, U>(target: Array<T | U>, source: U[]): (T | U)[]; | ||
export declare function from<T = any>(source: ArrayLike<T>): T[]; | ||
export declare function findIndex<T>(array: T[], func: Filter<T>): number; | ||
export declare function find<T = any>(array: T[], func: Filter<T>): T; | ||
export {}; |
@@ -7,3 +7,3 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
import pExtend from "./pointerExtend.js"; | ||
import pointerUtils from "./pointerUtils.js"; | ||
import * as pointerUtils from "./pointerUtils.js"; | ||
const elements = []; | ||
@@ -10,0 +10,0 @@ const targets = []; |
import * as arr from './arr'; | ||
import * as dom from './domUtils'; | ||
import * as is from './is'; | ||
import * as pointer from './pointerUtils'; | ||
import * as rect from './rect'; | ||
import win from './window'; | ||
@@ -20,5 +22,3 @@ export declare function warnOnce<T>(this: T, method: (...args: any) => any, message: string): (this: T) => any; | ||
export { default as normalizeListeners } from './normalizeListeners'; | ||
export { default as pointer } from './pointerUtils'; | ||
export { default as raf } from './raf'; | ||
export { default as rect } from './rect'; | ||
export { win, arr, dom, is }; | ||
export { win, arr, dom, is, pointer, rect }; |
import * as arr from "./arr.js"; | ||
import * as dom from "./domUtils.js"; | ||
import * as is from "./is.js"; | ||
import * as pointer from "./pointerUtils.js"; | ||
import * as rect from "./rect.js"; | ||
import win from "./window.js"; | ||
@@ -46,6 +48,4 @@ export function warnOnce(method, message) { | ||
export { default as normalizeListeners } from "./normalizeListeners.js"; | ||
export { default as pointer } from "./pointerUtils.js"; | ||
export { default as raf } from "./raf.js"; | ||
export { default as rect } from "./rect.js"; | ||
export { win, arr, dom, is }; | ||
export { win, arr, dom, is, pointer, rect }; | ||
//# sourceMappingURL=index.js.map |
@@ -12,2 +12,2 @@ export declare const window: (thing: any) => thing is Window; | ||
export declare const plainObject: typeof object; | ||
export declare const array: (thing: any) => thing is any[]; | ||
export declare const array: <T extends unknown>(thing: any) => thing is T[]; |
{ | ||
"name": "@interactjs/utils", | ||
"version": "1.7.1", | ||
"version": "1.7.2", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
import pointerExtend from './pointerExtend'; | ||
declare const pointerUtils: { | ||
copyCoords(dest: any, src: any): void; | ||
setCoordDeltas(targetObj: any, prev: any, cur: any): void; | ||
setCoordVelocity(targetObj: any, delta: any): void; | ||
isNativePointer(pointer: any): boolean; | ||
getXY(type: any, pointer: any, xy: any): any; | ||
getPageXY(pointer: import("../types/types").PointerType, page?: import("../types/types").Point): import("../types/types").Point; | ||
getClientXY(pointer: any, client: any): any; | ||
getPointerId(pointer: any): any; | ||
setCoords(targetObj: any, pointers: any[], timeStamp: number): void; | ||
pointerExtend: typeof pointerExtend; | ||
getTouchPair(event: any): any[]; | ||
pointerAverage(pointers: PointerEvent[] | Event[]): { | ||
pageX: number; | ||
pageY: number; | ||
clientX: number; | ||
clientY: number; | ||
screenX: number; | ||
screenY: number; | ||
export declare function copyCoords(dest: any, src: any): void; | ||
export declare function setCoordDeltas(targetObj: any, prev: any, cur: any): void; | ||
export declare function setCoordVelocity(targetObj: any, delta: any): void; | ||
export declare function setZeroCoords(targetObj: ReturnType<typeof newCoords>): void; | ||
export declare function isNativePointer(pointer: any): boolean; | ||
export declare function getXY(type: any, pointer: any, xy: any): any; | ||
export declare function getPageXY(pointer: Interact.PointerType | Interact.InteractEvent, page?: Interact.Point): import("../types/types").Point; | ||
export declare function getClientXY(pointer: any, client: any): any; | ||
export declare function getPointerId(pointer: any): any; | ||
export declare function setCoords(targetObj: any, pointers: any[], timeStamp: number): void; | ||
export declare function getTouchPair(event: any): any[]; | ||
export declare function pointerAverage(pointers: PointerEvent[] | Event[]): { | ||
pageX: number; | ||
pageY: number; | ||
clientX: number; | ||
clientY: number; | ||
screenX: number; | ||
screenY: number; | ||
}; | ||
export declare function touchBBox(event: Event | Array<(Interact.PointerType) | TouchEvent>): { | ||
x: number; | ||
y: number; | ||
left: number; | ||
top: number; | ||
right: number; | ||
bottom: number; | ||
width: number; | ||
height: number; | ||
}; | ||
export declare function touchDistance(event: any, deltaSource: any): number; | ||
export declare function touchAngle(event: any, deltaSource: any): number; | ||
export declare function getPointerType(pointer: any): any; | ||
export declare function getEventTargets(event: any): any[]; | ||
export declare function newCoords(): { | ||
page: { | ||
x: number; | ||
y: number; | ||
}; | ||
touchBBox(event: Event | (MouseEvent | Touch | PointerEvent | import("../types/types").InteractEvent<any, any> | TouchEvent)[]): { | ||
client: { | ||
x: number; | ||
y: number; | ||
left: number; | ||
top: number; | ||
right: number; | ||
bottom: number; | ||
width: number; | ||
height: number; | ||
}; | ||
touchDistance(event: any, deltaSource: any): number; | ||
touchAngle(event: any, deltaSource: any): number; | ||
getPointerType(pointer: any): any; | ||
getEventTargets(event: any): any[]; | ||
newCoords(): { | ||
page: { | ||
x: number; | ||
y: number; | ||
}; | ||
client: { | ||
x: number; | ||
y: number; | ||
}; | ||
timeStamp: number; | ||
}; | ||
coordsToEvent(coords: MockCoords): ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & MouseEvent) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & MouseEvent & PointerEvent) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & MouseEvent & import("../types/types").InteractEvent<any, any>) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & MouseEvent & TouchEvent) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & Touch & MouseEvent) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & Touch & PointerEvent) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & Touch & import("../types/types").InteractEvent<any, any>) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & Touch & TouchEvent) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & PointerEvent & MouseEvent) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & PointerEvent) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & PointerEvent & import("../types/types").InteractEvent<any, any>) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & PointerEvent & TouchEvent) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & import("../types/types").InteractEvent<any, any> & MouseEvent) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & import("../types/types").InteractEvent<any, any> & PointerEvent) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & import("../types/types").InteractEvent<any, any>) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & import("../types/types").InteractEvent<any, any> & TouchEvent); | ||
timeStamp: number; | ||
}; | ||
export default pointerUtils; | ||
export declare function coordsToEvent(coords: MockCoords): ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & MouseEvent) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & MouseEvent & PointerEvent) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & MouseEvent & import("../types/types").InteractEvent<any, any>) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & MouseEvent & TouchEvent) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & Touch & MouseEvent) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & Touch & PointerEvent) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & Touch & import("../types/types").InteractEvent<any, any>) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & Touch & TouchEvent) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & PointerEvent & MouseEvent) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & PointerEvent) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & PointerEvent & import("../types/types").InteractEvent<any, any>) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & PointerEvent & TouchEvent) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & import("../types/types").InteractEvent<any, any> & MouseEvent) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & import("../types/types").InteractEvent<any, any> & PointerEvent) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & import("../types/types").InteractEvent<any, any>) | ({ | ||
coords: MockCoords; | ||
readonly page: any; | ||
readonly client: any; | ||
readonly timeStamp: any; | ||
readonly pageX: any; | ||
readonly pageY: any; | ||
readonly clientX: any; | ||
readonly clientY: any; | ||
readonly pointerId: any; | ||
readonly target: any; | ||
readonly type: any; | ||
readonly pointerType: any; | ||
readonly buttons: any; | ||
} & import("../types/types").InteractEvent<any, any> & TouchEvent); | ||
export interface MockCoords { | ||
@@ -284,1 +281,2 @@ page: Interact.Point; | ||
} | ||
export { pointerExtend }; |
@@ -7,264 +7,248 @@ import browser from "./browser.js"; | ||
import pointerExtend from "./pointerExtend.js"; | ||
const pointerUtils = { | ||
copyCoords(dest, src) { | ||
dest.page = dest.page || {}; | ||
dest.page.x = src.page.x; | ||
dest.page.y = src.page.y; | ||
dest.client = dest.client || {}; | ||
dest.client.x = src.client.x; | ||
dest.client.y = src.client.y; | ||
dest.timeStamp = src.timeStamp; | ||
}, | ||
export function copyCoords(dest, src) { | ||
dest.page = dest.page || {}; | ||
dest.page.x = src.page.x; | ||
dest.page.y = src.page.y; | ||
dest.client = dest.client || {}; | ||
dest.client.x = src.client.x; | ||
dest.client.y = src.client.y; | ||
dest.timeStamp = src.timeStamp; | ||
} | ||
export function setCoordDeltas(targetObj, prev, cur) { | ||
targetObj.page.x = cur.page.x - prev.page.x; | ||
targetObj.page.y = cur.page.y - prev.page.y; | ||
targetObj.client.x = cur.client.x - prev.client.x; | ||
targetObj.client.y = cur.client.y - prev.client.y; | ||
targetObj.timeStamp = cur.timeStamp - prev.timeStamp; | ||
} | ||
export function setCoordVelocity(targetObj, delta) { | ||
const dt = Math.max(delta.timeStamp / 1000, 0.001); | ||
targetObj.page.x = delta.page.x / dt; | ||
targetObj.page.y = delta.page.y / dt; | ||
targetObj.client.x = delta.client.x / dt; | ||
targetObj.client.y = delta.client.y / dt; | ||
targetObj.timeStamp = dt; | ||
} | ||
export function setZeroCoords(targetObj) { | ||
targetObj.page.x = 0; | ||
targetObj.page.y = 0; | ||
targetObj.client.x = 0; | ||
targetObj.client.y = 0; | ||
} | ||
export function isNativePointer(pointer) { | ||
return pointer instanceof dom.Event || pointer instanceof dom.Touch; | ||
} // Get specified X/Y coords for mouse or event.touches[0] | ||
setCoordDeltas(targetObj, prev, cur) { | ||
targetObj.page.x = cur.page.x - prev.page.x; | ||
targetObj.page.y = cur.page.y - prev.page.y; | ||
targetObj.client.x = cur.client.x - prev.client.x; | ||
targetObj.client.y = cur.client.y - prev.client.y; | ||
targetObj.timeStamp = cur.timeStamp - prev.timeStamp; | ||
}, | ||
export function getXY(type, pointer, xy) { | ||
xy = xy || {}; | ||
type = type || 'page'; | ||
xy.x = pointer[type + 'X']; | ||
xy.y = pointer[type + 'Y']; | ||
return xy; | ||
} | ||
export function getPageXY(pointer, page) { | ||
page = page || { | ||
x: 0, | ||
y: 0 | ||
}; // Opera Mobile handles the viewport and scrolling oddly | ||
setCoordVelocity(targetObj, delta) { | ||
const dt = Math.max(delta.timeStamp / 1000, 0.001); | ||
targetObj.page.x = delta.page.x / dt; | ||
targetObj.page.y = delta.page.y / dt; | ||
targetObj.client.x = delta.client.x / dt; | ||
targetObj.client.y = delta.client.y / dt; | ||
targetObj.timeStamp = dt; | ||
}, | ||
if (browser.isOperaMobile && isNativePointer(pointer)) { | ||
getXY('screen', pointer, page); | ||
page.x += window.scrollX; | ||
page.y += window.scrollY; | ||
} else { | ||
getXY('page', pointer, page); | ||
} | ||
isNativePointer(pointer) { | ||
return pointer instanceof dom.Event || pointer instanceof dom.Touch; | ||
}, | ||
return page; | ||
} | ||
export function getClientXY(pointer, client) { | ||
client = client || {}; | ||
// Get specified X/Y coords for mouse or event.touches[0] | ||
getXY(type, pointer, xy) { | ||
xy = xy || {}; | ||
type = type || 'page'; | ||
xy.x = pointer[type + 'X']; | ||
xy.y = pointer[type + 'Y']; | ||
return xy; | ||
}, | ||
if (browser.isOperaMobile && isNativePointer(pointer)) { | ||
// Opera Mobile handles the viewport and scrolling oddly | ||
getXY('screen', pointer, client); | ||
} else { | ||
getXY('client', pointer, client); | ||
} | ||
getPageXY(pointer, page) { | ||
page = page || { | ||
x: 0, | ||
y: 0 | ||
}; // Opera Mobile handles the viewport and scrolling oddly | ||
return client; | ||
} | ||
export function getPointerId(pointer) { | ||
return is.number(pointer.pointerId) ? pointer.pointerId : pointer.identifier; | ||
} | ||
export function setCoords(targetObj, pointers, timeStamp) { | ||
const pointer = pointers.length > 1 ? pointerAverage(pointers) : pointers[0]; | ||
const tmpXY = {}; | ||
getPageXY(pointer, tmpXY); | ||
targetObj.page.x = tmpXY.x; | ||
targetObj.page.y = tmpXY.y; | ||
getClientXY(pointer, tmpXY); | ||
targetObj.client.x = tmpXY.x; | ||
targetObj.client.y = tmpXY.y; | ||
targetObj.timeStamp = timeStamp; | ||
} | ||
export function getTouchPair(event) { | ||
const touches = []; // array of touches is supplied | ||
if (browser.isOperaMobile && pointerUtils.isNativePointer(pointer)) { | ||
pointerUtils.getXY('screen', pointer, page); | ||
page.x += window.scrollX; | ||
page.y += window.scrollY; | ||
} else { | ||
pointerUtils.getXY('page', pointer, page); | ||
} | ||
return page; | ||
}, | ||
getClientXY(pointer, client) { | ||
client = client || {}; | ||
if (browser.isOperaMobile && pointerUtils.isNativePointer(pointer)) { | ||
// Opera Mobile handles the viewport and scrolling oddly | ||
pointerUtils.getXY('screen', pointer, client); | ||
} else { | ||
pointerUtils.getXY('client', pointer, client); | ||
} | ||
return client; | ||
}, | ||
getPointerId(pointer) { | ||
return is.number(pointer.pointerId) ? pointer.pointerId : pointer.identifier; | ||
}, | ||
setCoords(targetObj, pointers, timeStamp) { | ||
const pointer = pointers.length > 1 ? pointerUtils.pointerAverage(pointers) : pointers[0]; | ||
const tmpXY = {}; | ||
pointerUtils.getPageXY(pointer, tmpXY); | ||
targetObj.page.x = tmpXY.x; | ||
targetObj.page.y = tmpXY.y; | ||
pointerUtils.getClientXY(pointer, tmpXY); | ||
targetObj.client.x = tmpXY.x; | ||
targetObj.client.y = tmpXY.y; | ||
targetObj.timeStamp = timeStamp; | ||
}, | ||
pointerExtend, | ||
getTouchPair(event) { | ||
const touches = []; // array of touches is supplied | ||
if (is.array(event)) { | ||
touches[0] = event[0]; | ||
touches[1] = event[1]; | ||
} // an event | ||
else { | ||
if (event.type === 'touchend') { | ||
if (event.touches.length === 1) { | ||
touches[0] = event.touches[0]; | ||
touches[1] = event.changedTouches[0]; | ||
} else if (event.touches.length === 0) { | ||
touches[0] = event.changedTouches[0]; | ||
touches[1] = event.changedTouches[1]; | ||
} | ||
} else { | ||
if (is.array(event)) { | ||
touches[0] = event[0]; | ||
touches[1] = event[1]; | ||
} // an event | ||
else { | ||
if (event.type === 'touchend') { | ||
if (event.touches.length === 1) { | ||
touches[0] = event.touches[0]; | ||
touches[1] = event.touches[1]; | ||
touches[1] = event.changedTouches[0]; | ||
} else if (event.touches.length === 0) { | ||
touches[0] = event.changedTouches[0]; | ||
touches[1] = event.changedTouches[1]; | ||
} | ||
} else { | ||
touches[0] = event.touches[0]; | ||
touches[1] = event.touches[1]; | ||
} | ||
} | ||
return touches; | ||
}, | ||
return touches; | ||
} | ||
export function pointerAverage(pointers) { | ||
const average = { | ||
pageX: 0, | ||
pageY: 0, | ||
clientX: 0, | ||
clientY: 0, | ||
screenX: 0, | ||
screenY: 0 | ||
}; | ||
pointerAverage(pointers) { | ||
const average = { | ||
pageX: 0, | ||
pageY: 0, | ||
clientX: 0, | ||
clientY: 0, | ||
screenX: 0, | ||
screenY: 0 | ||
}; | ||
for (const pointer of pointers) { | ||
for (const prop in average) { | ||
average[prop] += pointer[prop]; | ||
} | ||
} | ||
for (const pointer of pointers) { | ||
for (const prop in average) { | ||
average[prop] /= pointers.length; | ||
average[prop] += pointer[prop]; | ||
} | ||
} | ||
return average; | ||
}, | ||
for (const prop in average) { | ||
average[prop] /= pointers.length; | ||
} | ||
touchBBox(event) { | ||
if (!event.length && !(event.touches && event.touches.length > 1)) { | ||
return null; | ||
} | ||
return average; | ||
} | ||
export function touchBBox(event) { | ||
if (!event.length && !(event.touches && event.touches.length > 1)) { | ||
return null; | ||
} | ||
const touches = pointerUtils.getTouchPair(event); | ||
const minX = Math.min(touches[0].pageX, touches[1].pageX); | ||
const minY = Math.min(touches[0].pageY, touches[1].pageY); | ||
const maxX = Math.max(touches[0].pageX, touches[1].pageX); | ||
const maxY = Math.max(touches[0].pageY, touches[1].pageY); | ||
return { | ||
x: minX, | ||
y: minY, | ||
left: minX, | ||
top: minY, | ||
right: maxX, | ||
bottom: maxY, | ||
width: maxX - minX, | ||
height: maxY - minY | ||
}; | ||
}, | ||
const touches = getTouchPair(event); | ||
const minX = Math.min(touches[0].pageX, touches[1].pageX); | ||
const minY = Math.min(touches[0].pageY, touches[1].pageY); | ||
const maxX = Math.max(touches[0].pageX, touches[1].pageX); | ||
const maxY = Math.max(touches[0].pageY, touches[1].pageY); | ||
return { | ||
x: minX, | ||
y: minY, | ||
left: minX, | ||
top: minY, | ||
right: maxX, | ||
bottom: maxY, | ||
width: maxX - minX, | ||
height: maxY - minY | ||
}; | ||
} | ||
export function touchDistance(event, deltaSource) { | ||
const sourceX = deltaSource + 'X'; | ||
const sourceY = deltaSource + 'Y'; | ||
const touches = getTouchPair(event); | ||
const dx = touches[0][sourceX] - touches[1][sourceX]; | ||
const dy = touches[0][sourceY] - touches[1][sourceY]; | ||
return hypot(dx, dy); | ||
} | ||
export function touchAngle(event, deltaSource) { | ||
const sourceX = deltaSource + 'X'; | ||
const sourceY = deltaSource + 'Y'; | ||
const touches = getTouchPair(event); | ||
const dx = touches[1][sourceX] - touches[0][sourceX]; | ||
const dy = touches[1][sourceY] - touches[0][sourceY]; | ||
const angle = 180 * Math.atan2(dy, dx) / Math.PI; | ||
return angle; | ||
} | ||
export function getPointerType(pointer) { | ||
return is.string(pointer.pointerType) ? pointer.pointerType : is.number(pointer.pointerType) ? [undefined, undefined, 'touch', 'pen', 'mouse'][pointer.pointerType] // if the PointerEvent API isn't available, then the "pointer" must | ||
// be either a MouseEvent, TouchEvent, or Touch object | ||
: /touch/.test(pointer.type) || pointer instanceof dom.Touch ? 'touch' : 'mouse'; | ||
} // [ event.target, event.currentTarget ] | ||
touchDistance(event, deltaSource) { | ||
const sourceX = deltaSource + 'X'; | ||
const sourceY = deltaSource + 'Y'; | ||
const touches = pointerUtils.getTouchPair(event); | ||
const dx = touches[0][sourceX] - touches[1][sourceX]; | ||
const dy = touches[0][sourceY] - touches[1][sourceY]; | ||
return hypot(dx, dy); | ||
}, | ||
export function getEventTargets(event) { | ||
const path = is.func(event.composedPath) ? event.composedPath() : event.path; | ||
return [domUtils.getActualElement(path ? path[0] : event.target), domUtils.getActualElement(event.currentTarget)]; | ||
} | ||
export function newCoords() { | ||
return { | ||
page: { | ||
x: 0, | ||
y: 0 | ||
}, | ||
client: { | ||
x: 0, | ||
y: 0 | ||
}, | ||
timeStamp: 0 | ||
}; | ||
} | ||
export function coordsToEvent(coords) { | ||
const event = { | ||
coords, | ||
touchAngle(event, deltaSource) { | ||
const sourceX = deltaSource + 'X'; | ||
const sourceY = deltaSource + 'Y'; | ||
const touches = pointerUtils.getTouchPair(event); | ||
const dx = touches[1][sourceX] - touches[0][sourceX]; | ||
const dy = touches[1][sourceY] - touches[0][sourceY]; | ||
const angle = 180 * Math.atan2(dy, dx) / Math.PI; | ||
return angle; | ||
}, | ||
get page() { | ||
return this.coords.page; | ||
}, | ||
getPointerType(pointer) { | ||
return is.string(pointer.pointerType) ? pointer.pointerType : is.number(pointer.pointerType) ? [undefined, undefined, 'touch', 'pen', 'mouse'][pointer.pointerType] // if the PointerEvent API isn't available, then the "pointer" must | ||
// be either a MouseEvent, TouchEvent, or Touch object | ||
: /touch/.test(pointer.type) || pointer instanceof dom.Touch ? 'touch' : 'mouse'; | ||
}, | ||
get client() { | ||
return this.coords.client; | ||
}, | ||
// [ event.target, event.currentTarget ] | ||
getEventTargets(event) { | ||
const path = is.func(event.composedPath) ? event.composedPath() : event.path; | ||
return [domUtils.getActualElement(path ? path[0] : event.target), domUtils.getActualElement(event.currentTarget)]; | ||
}, | ||
get timeStamp() { | ||
return this.coords.timeStamp; | ||
}, | ||
newCoords() { | ||
return { | ||
page: { | ||
x: 0, | ||
y: 0 | ||
}, | ||
client: { | ||
x: 0, | ||
y: 0 | ||
}, | ||
timeStamp: 0 | ||
}; | ||
}, | ||
get pageX() { | ||
return this.coords.page.x; | ||
}, | ||
coordsToEvent(coords) { | ||
const event = { | ||
coords, | ||
get pageY() { | ||
return this.coords.page.y; | ||
}, | ||
get page() { | ||
return this.coords.page; | ||
}, | ||
get clientX() { | ||
return this.coords.client.x; | ||
}, | ||
get client() { | ||
return this.coords.client; | ||
}, | ||
get clientY() { | ||
return this.coords.client.y; | ||
}, | ||
get timeStamp() { | ||
return this.coords.timeStamp; | ||
}, | ||
get pointerId() { | ||
return this.coords.pointerId; | ||
}, | ||
get pageX() { | ||
return this.coords.page.x; | ||
}, | ||
get target() { | ||
return this.coords.target; | ||
}, | ||
get pageY() { | ||
return this.coords.page.y; | ||
}, | ||
get type() { | ||
return this.coords.type; | ||
}, | ||
get clientX() { | ||
return this.coords.client.x; | ||
}, | ||
get pointerType() { | ||
return this.coords.pointerType; | ||
}, | ||
get clientY() { | ||
return this.coords.client.y; | ||
}, | ||
get buttons() { | ||
return this.coords.buttons; | ||
} | ||
get pointerId() { | ||
return this.coords.pointerId; | ||
}, | ||
get target() { | ||
return this.coords.target; | ||
}, | ||
get type() { | ||
return this.coords.type; | ||
}, | ||
get pointerType() { | ||
return this.coords.pointerType; | ||
}, | ||
get buttons() { | ||
return this.coords.buttons; | ||
} | ||
}; | ||
return event; | ||
} | ||
}; | ||
export default pointerUtils; | ||
}; | ||
return event; | ||
} | ||
export { pointerExtend }; | ||
//# sourceMappingURL=pointerUtils.js.map |
@@ -9,9 +9,1 @@ export declare function getStringOptionResult(value: any, target: Interact.HasGetRect, element: any): any; | ||
export declare function tlbrToXywh(rect: any): any; | ||
declare const _default: { | ||
getStringOptionResult: typeof getStringOptionResult; | ||
resolveRectLike: typeof resolveRectLike; | ||
rectToXY: typeof rectToXY; | ||
xywhToTlbr: typeof xywhToTlbr; | ||
tlbrToXywh: typeof tlbrToXywh; | ||
}; | ||
export default _default; |
@@ -56,9 +56,2 @@ import { closest, getElementRect, parentNode } from "./domUtils.js"; | ||
} | ||
export default { | ||
getStringOptionResult, | ||
resolveRectLike, | ||
rectToXY, | ||
xywhToTlbr, | ||
tlbrToXywh | ||
}; | ||
//# sourceMappingURL=rect.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
140185
1549