pointer-tracker
Advanced tools
Comparing version 1.0.0 to 2.0.0
@@ -1,2 +0,2 @@ | ||
export declare class Pointer { | ||
declare class Pointer { | ||
/** x offset from the top of the document */ | ||
@@ -10,3 +10,3 @@ pageX: number; | ||
clientY: number; | ||
/** ID for this pointer */ | ||
/** Unique ID for this pointer */ | ||
id: number; | ||
@@ -21,2 +21,4 @@ /** The platform object used to create this Pointer */ | ||
} | ||
declare type PointerType = Pointer; | ||
export { PointerType as Pointer }; | ||
export declare type InputEvent = TouchEvent | PointerEvent | MouseEvent; | ||
@@ -60,3 +62,3 @@ declare type StartCallback = (pointer: Pointer, event: InputEvent) => boolean; | ||
*/ | ||
export declare class PointerTracker { | ||
export default class PointerTracker { | ||
private _element; | ||
@@ -126,2 +128,1 @@ /** | ||
} | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
var PointerTracker=function(t){"use strict";class e{constructor(t){this.id=-1,this.nativePointer=t,this.pageX=t.pageX,this.pageY=t.pageY,this.clientX=t.clientX,this.clientY=t.clientY,self.Touch&&t instanceof Touch?this.id=t.identifier:i(t)&&(this.id=t.pointerId)}getCoalesced(){return"getCoalescedEvents"in this.nativePointer?this.nativePointer.getCoalescedEvents().map(t=>new e(t)):[this]}}const i=t=>self.PointerEvent&&t instanceof PointerEvent,n=()=>{};return t.Pointer=e,t.PointerTracker=class{constructor(t,e){this._element=t,this.startPointers=[],this.currentPointers=[];const{start:i=(()=>!0),move:r=n,end:s=n}=e;this._startCallback=i,this._moveCallback=r,this._endCallback=s,self.PointerEvent?this._element.addEventListener("pointerdown",this._pointerStart):(this._element.addEventListener("mousedown",this._pointerStart),this._element.addEventListener("touchstart",this._touchStart),this._element.addEventListener("touchmove",this._move),this._element.addEventListener("touchend",this._touchEnd)),this._pointerStart=this._pointerStart.bind(this),this._touchStart=this._touchStart.bind(this),this._move=this._move.bind(this),this._triggerPointerEnd=this._triggerPointerEnd.bind(this),this._pointerEnd=this._pointerEnd.bind(this),this._touchEnd=this._touchEnd.bind(this)}_triggerPointerStart(t,e){return!!this._startCallback(t,e)&&(this.currentPointers.push(t),this.startPointers.push(t),!0)}_pointerStart(t){0===t.button&&this._triggerPointerStart(new e(t),t)&&(i(t)?(this._element.setPointerCapture(t.pointerId),this._element.addEventListener("pointermove",this._move),this._element.addEventListener("pointerup",this._pointerEnd)):(window.addEventListener("mousemove",this._move),window.addEventListener("mouseup",this._pointerEnd)))}_touchStart(t){for(const i of Array.from(t.changedTouches))this._triggerPointerStart(new e(i),t)}_move(t){const i=this.currentPointers.slice(),n="changedTouches"in t?Array.from(t.changedTouches).map(t=>new e(t)):[new e(t)],r=[];for(const t of n){const e=this.currentPointers.findIndex(e=>e.id===t.id);-1!==e&&(r.push(t),this.currentPointers[e]=t)}0!==r.length&&this._moveCallback(i,r,t)}_triggerPointerEnd(t,e){const i=this.currentPointers.findIndex(e=>e.id===t.id);return-1!==i&&(this.currentPointers.splice(i,1),this.startPointers.splice(i,1),this._endCallback(t,e),!0)}_pointerEnd(t){if(this._triggerPointerEnd(new e(t),t))if(i(t)){if(this.currentPointers.length)return;this._element.removeEventListener("pointermove",this._move),this._element.removeEventListener("pointerup",this._pointerEnd)}else window.removeEventListener("mousemove",this._move),window.removeEventListener("mouseup",this._pointerEnd)}_touchEnd(t){for(const i of Array.from(t.changedTouches))this._triggerPointerEnd(new e(i),t)}},t}({}); | ||
var PointerTracker=function(){"use strict";class t{constructor(t){this.id=-1,this.nativePointer=t,this.pageX=t.pageX,this.pageY=t.pageY,this.clientX=t.clientX,this.clientY=t.clientY,self.Touch&&t instanceof Touch?this.id=t.identifier:e(t)&&(this.id=t.pointerId)}getCoalesced(){return"getCoalescedEvents"in this.nativePointer?this.nativePointer.getCoalescedEvents().map(e=>new t(e)):[this]}}const e=t=>self.PointerEvent&&t instanceof PointerEvent,i=()=>{};return class{constructor(t,e){this._element=t,this.startPointers=[],this.currentPointers=[];const{start:n=(()=>!0),move:s=i,end:r=i}=e;this._startCallback=n,this._moveCallback=s,this._endCallback=r,self.PointerEvent?this._element.addEventListener("pointerdown",this._pointerStart):(this._element.addEventListener("mousedown",this._pointerStart),this._element.addEventListener("touchstart",this._touchStart),this._element.addEventListener("touchmove",this._move),this._element.addEventListener("touchend",this._touchEnd)),this._pointerStart=this._pointerStart.bind(this),this._touchStart=this._touchStart.bind(this),this._move=this._move.bind(this),this._triggerPointerEnd=this._triggerPointerEnd.bind(this),this._pointerEnd=this._pointerEnd.bind(this),this._touchEnd=this._touchEnd.bind(this)}_triggerPointerStart(t,e){return!!this._startCallback(t,e)&&(this.currentPointers.push(t),this.startPointers.push(t),!0)}_pointerStart(i){0===i.button&&this._triggerPointerStart(new t(i),i)&&(e(i)?(this._element.setPointerCapture(i.pointerId),this._element.addEventListener("pointermove",this._move),this._element.addEventListener("pointerup",this._pointerEnd)):(window.addEventListener("mousemove",this._move),window.addEventListener("mouseup",this._pointerEnd)))}_touchStart(e){for(const i of Array.from(e.changedTouches))this._triggerPointerStart(new t(i),e)}_move(e){const i=this.currentPointers.slice(),n="changedTouches"in e?Array.from(e.changedTouches).map(e=>new t(e)):[new t(e)],s=[];for(const t of n){const e=this.currentPointers.findIndex(e=>e.id===t.id);-1!==e&&(s.push(t),this.currentPointers[e]=t)}0!==s.length&&this._moveCallback(i,s,e)}_triggerPointerEnd(t,e){const i=this.currentPointers.findIndex(e=>e.id===t.id);return-1!==i&&(this.currentPointers.splice(i,1),this.startPointers.splice(i,1),this._endCallback(t,e),!0)}_pointerEnd(i){if(this._triggerPointerEnd(new t(i),i))if(e(i)){if(this.currentPointers.length)return;this._element.removeEventListener("pointermove",this._move),this._element.removeEventListener("pointerup",this._pointerEnd)}else window.removeEventListener("mousemove",this._move),window.removeEventListener("mouseup",this._pointerEnd)}_touchEnd(e){for(const i of Array.from(e.changedTouches))this._triggerPointerEnd(new t(i),e)}}}(); |
@@ -1,2 +0,2 @@ | ||
var PointerTracker = (function (exports) { | ||
var PointerTracker = (function () { | ||
'use strict'; | ||
@@ -6,3 +6,3 @@ | ||
constructor(nativePointer) { | ||
/** ID for this pointer */ | ||
/** Unique ID for this pointer */ | ||
this.id = -1; | ||
@@ -189,7 +189,4 @@ this.nativePointer = nativePointer; | ||
exports.Pointer = Pointer; | ||
exports.PointerTracker = PointerTracker; | ||
return PointerTracker; | ||
return exports; | ||
}({})); | ||
}()); |
const enum Button { Left } | ||
export class Pointer { | ||
class Pointer { | ||
/** x offset from the top of the document */ | ||
@@ -12,3 +12,3 @@ pageX: number; | ||
clientY: number; | ||
/** ID for this pointer */ | ||
/** Unique ID for this pointer */ | ||
id: number = -1; | ||
@@ -43,2 +43,6 @@ /** The platform object used to create this Pointer */ | ||
// Export the typing, but keep the class private. | ||
type PointerType = Pointer; | ||
export { PointerType as Pointer }; | ||
const isPointerEvent = (event: any): event is PointerEvent => | ||
@@ -93,3 +97,3 @@ self.PointerEvent && event instanceof PointerEvent; | ||
*/ | ||
export class PointerTracker { | ||
export default class PointerTracker { | ||
/** | ||
@@ -96,0 +100,0 @@ * State of the tracked pointers when they were pressed/touched. |
{ | ||
"name": "pointer-tracker", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Track mouse/touch/pointer events through one interface", | ||
@@ -5,0 +5,0 @@ "main": "dist/PointerTracker.js", |
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
46691
810