pointer-tracker
Advanced tools
Comparing version 2.0.3 to 2.1.0
@@ -82,2 +82,6 @@ declare class Pointer { | ||
/** | ||
* Remove all listeners. | ||
*/ | ||
stop(): void; | ||
/** | ||
* Call the start callback for this pointer, and track it if the user wants. | ||
@@ -91,3 +95,3 @@ * | ||
/** | ||
* Listener for mouse/pointer starts. Bound to the class in the constructor. | ||
* Listener for mouse/pointer starts. | ||
* | ||
@@ -99,3 +103,3 @@ * @param event This will only be a MouseEvent if the browser doesn't support | ||
/** | ||
* Listener for touchstart. Bound to the class in the constructor. | ||
* Listener for touchstart. | ||
* Only used if the browser doesn't support pointer events. | ||
@@ -106,3 +110,2 @@ */ | ||
* Listener for pointer/mouse/touch move events. | ||
* Bound to the class in the constructor. | ||
*/ | ||
@@ -118,3 +121,4 @@ private _move; | ||
/** | ||
* Listener for mouse/pointer ends. Bound to the class in the constructor. | ||
* Listener for mouse/pointer ends. | ||
* | ||
* @param event This will only be a MouseEvent if the browser doesn't support | ||
@@ -125,3 +129,3 @@ * pointer events. | ||
/** | ||
* Listener for touchend. Bound to the class in the constructor. | ||
* Listener for touchend. | ||
* Only used if the browser doesn't support pointer events. | ||
@@ -128,0 +132,0 @@ */ |
@@ -1,1 +0,1 @@ | ||
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,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),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))}_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)}}}(); | ||
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,n=()=>{};return class{constructor(i,s){this._element=i,this.startPointers=[],this.currentPointers=[],this._pointerStart=n=>{if(0===n.button&&this._triggerPointerStart(new t(n),n))if(e(n)){(n.target&&"setPointerCapture"in n.target?n.target:this._element).setPointerCapture(n.pointerId),this._element.addEventListener("pointermove",this._move),this._element.addEventListener("pointerup",this._pointerEnd)}else window.addEventListener("mousemove",this._move),window.addEventListener("mouseup",this._pointerEnd)},this._touchStart=e=>{for(const n of Array.from(e.changedTouches))this._triggerPointerStart(new t(n),e)},this._move=e=>{const n=this.currentPointers.slice(),i="changedTouches"in e?Array.from(e.changedTouches).map(e=>new t(e)):[new t(e)],s=[];for(const t of i){const e=this.currentPointers.findIndex(e=>e.id===t.id);-1!==e&&(s.push(t),this.currentPointers[e]=t)}0!==s.length&&this._moveCallback(n,s,e)},this._triggerPointerEnd=(t,e)=>{const n=this.currentPointers.findIndex(e=>e.id===t.id);return-1!==n&&(this.currentPointers.splice(n,1),this.startPointers.splice(n,1),this._endCallback(t,e),!0)},this._pointerEnd=n=>{if(this._triggerPointerEnd(new t(n),n))if(e(n)){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)},this._touchEnd=e=>{for(const n of Array.from(e.changedTouches))this._triggerPointerEnd(new t(n),e)};const{start:r=(()=>!0),move:o=n,end:h=n}=s;this._startCallback=r,this._moveCallback=o,this._endCallback=h,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))}stop(){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._element.addEventListener("pointermove",this._move),this._element.addEventListener("pointerup",this._pointerEnd),window.addEventListener("mousemove",this._move),window.addEventListener("mouseup",this._pointerEnd)}_triggerPointerStart(t,e){return!!this._startCallback(t,e)&&(this.currentPointers.push(t),this.startPointers.push(t),!0)}}}(); |
@@ -16,3 +16,4 @@ var PointerTracker = (function () { | ||
} | ||
else if (isPointerEvent(nativePointer)) { // is PointerEvent | ||
else if (isPointerEvent(nativePointer)) { | ||
// is PointerEvent | ||
this.id = nativePointer.pointerId; | ||
@@ -54,13 +55,108 @@ } | ||
this.currentPointers = []; | ||
const { start = () => true, move = noop, end = noop, } = callbacks; | ||
/** | ||
* Listener for mouse/pointer starts. | ||
* | ||
* @param event This will only be a MouseEvent if the browser doesn't support | ||
* pointer events. | ||
*/ | ||
this._pointerStart = (event) => { | ||
if (event.button !== 0 /* Left */) | ||
return; | ||
if (!this._triggerPointerStart(new Pointer(event), event)) | ||
return; | ||
// Add listeners for additional events. | ||
// The listeners may already exist, but no harm in adding them again. | ||
if (isPointerEvent(event)) { | ||
const capturingElement = event.target && 'setPointerCapture' in event.target | ||
? event.target | ||
: this._element; | ||
capturingElement.setPointerCapture(event.pointerId); | ||
this._element.addEventListener('pointermove', this._move); | ||
this._element.addEventListener('pointerup', this._pointerEnd); | ||
} | ||
else { | ||
// MouseEvent | ||
window.addEventListener('mousemove', this._move); | ||
window.addEventListener('mouseup', this._pointerEnd); | ||
} | ||
}; | ||
/** | ||
* Listener for touchstart. | ||
* Only used if the browser doesn't support pointer events. | ||
*/ | ||
this._touchStart = (event) => { | ||
for (const touch of Array.from(event.changedTouches)) { | ||
this._triggerPointerStart(new Pointer(touch), event); | ||
} | ||
}; | ||
/** | ||
* Listener for pointer/mouse/touch move events. | ||
*/ | ||
this._move = (event) => { | ||
const previousPointers = this.currentPointers.slice(); | ||
const changedPointers = 'changedTouches' in event // Shortcut for 'is touch event'. | ||
? Array.from(event.changedTouches).map(t => new Pointer(t)) | ||
: [new Pointer(event)]; | ||
const trackedChangedPointers = []; | ||
for (const pointer of changedPointers) { | ||
const index = this.currentPointers.findIndex(p => p.id === pointer.id); | ||
if (index === -1) | ||
continue; // Not a pointer we're tracking | ||
trackedChangedPointers.push(pointer); | ||
this.currentPointers[index] = pointer; | ||
} | ||
if (trackedChangedPointers.length === 0) | ||
return; | ||
this._moveCallback(previousPointers, trackedChangedPointers, event); | ||
}; | ||
/** | ||
* Call the end callback for this pointer. | ||
* | ||
* @param pointer Pointer | ||
* @param event Related event | ||
*/ | ||
this._triggerPointerEnd = (pointer, event) => { | ||
const index = this.currentPointers.findIndex(p => p.id === pointer.id); | ||
// Not a pointer we're interested in? | ||
if (index === -1) | ||
return false; | ||
this.currentPointers.splice(index, 1); | ||
this.startPointers.splice(index, 1); | ||
this._endCallback(pointer, event); | ||
return true; | ||
}; | ||
/** | ||
* Listener for mouse/pointer ends. | ||
* | ||
* @param event This will only be a MouseEvent if the browser doesn't support | ||
* pointer events. | ||
*/ | ||
this._pointerEnd = (event) => { | ||
if (!this._triggerPointerEnd(new Pointer(event), event)) | ||
return; | ||
if (isPointerEvent(event)) { | ||
if (this.currentPointers.length) | ||
return; | ||
this._element.removeEventListener('pointermove', this._move); | ||
this._element.removeEventListener('pointerup', this._pointerEnd); | ||
} | ||
else { | ||
// MouseEvent | ||
window.removeEventListener('mousemove', this._move); | ||
window.removeEventListener('mouseup', this._pointerEnd); | ||
} | ||
}; | ||
/** | ||
* Listener for touchend. | ||
* Only used if the browser doesn't support pointer events. | ||
*/ | ||
this._touchEnd = (event) => { | ||
for (const touch of Array.from(event.changedTouches)) { | ||
this._triggerPointerEnd(new Pointer(touch), event); | ||
} | ||
}; | ||
const { start = () => true, move = noop, end = noop } = callbacks; | ||
this._startCallback = start; | ||
this._moveCallback = move; | ||
this._endCallback = end; | ||
// Bind methods | ||
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); | ||
// Add listeners | ||
@@ -78,2 +174,16 @@ if (self.PointerEvent) { | ||
/** | ||
* Remove all listeners. | ||
*/ | ||
stop() { | ||
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._element.addEventListener('pointermove', this._move); | ||
this._element.addEventListener('pointerup', this._pointerEnd); | ||
window.addEventListener('mousemove', this._move); | ||
window.addEventListener('mouseup', this._pointerEnd); | ||
} | ||
/** | ||
* Call the start callback for this pointer, and track it if the user wants. | ||
@@ -92,99 +202,2 @@ * | ||
} | ||
/** | ||
* Listener for mouse/pointer starts. Bound to the class in the constructor. | ||
* | ||
* @param event This will only be a MouseEvent if the browser doesn't support | ||
* pointer events. | ||
*/ | ||
_pointerStart(event) { | ||
if (event.button !== 0 /* Left */) | ||
return; | ||
if (!this._triggerPointerStart(new Pointer(event), event)) | ||
return; | ||
// Add listeners for additional events. | ||
// The listeners may already exist, but no harm in adding them again. | ||
if (isPointerEvent(event)) { | ||
this._element.setPointerCapture(event.pointerId); | ||
this._element.addEventListener('pointermove', this._move); | ||
this._element.addEventListener('pointerup', this._pointerEnd); | ||
} | ||
else { // MouseEvent | ||
window.addEventListener('mousemove', this._move); | ||
window.addEventListener('mouseup', this._pointerEnd); | ||
} | ||
} | ||
/** | ||
* Listener for touchstart. Bound to the class in the constructor. | ||
* Only used if the browser doesn't support pointer events. | ||
*/ | ||
_touchStart(event) { | ||
for (const touch of Array.from(event.changedTouches)) { | ||
this._triggerPointerStart(new Pointer(touch), event); | ||
} | ||
} | ||
/** | ||
* Listener for pointer/mouse/touch move events. | ||
* Bound to the class in the constructor. | ||
*/ | ||
_move(event) { | ||
const previousPointers = this.currentPointers.slice(); | ||
const changedPointers = ('changedTouches' in event) ? // Shortcut for 'is touch event'. | ||
Array.from(event.changedTouches).map(t => new Pointer(t)) : | ||
[new Pointer(event)]; | ||
const trackedChangedPointers = []; | ||
for (const pointer of changedPointers) { | ||
const index = this.currentPointers.findIndex(p => p.id === pointer.id); | ||
if (index === -1) | ||
continue; // Not a pointer we're tracking | ||
trackedChangedPointers.push(pointer); | ||
this.currentPointers[index] = pointer; | ||
} | ||
if (trackedChangedPointers.length === 0) | ||
return; | ||
this._moveCallback(previousPointers, trackedChangedPointers, event); | ||
} | ||
/** | ||
* Call the end callback for this pointer. | ||
* | ||
* @param pointer Pointer | ||
* @param event Related event | ||
*/ | ||
_triggerPointerEnd(pointer, event) { | ||
const index = this.currentPointers.findIndex(p => p.id === pointer.id); | ||
// Not a pointer we're interested in? | ||
if (index === -1) | ||
return false; | ||
this.currentPointers.splice(index, 1); | ||
this.startPointers.splice(index, 1); | ||
this._endCallback(pointer, event); | ||
return true; | ||
} | ||
/** | ||
* Listener for mouse/pointer ends. Bound to the class in the constructor. | ||
* @param event This will only be a MouseEvent if the browser doesn't support | ||
* pointer events. | ||
*/ | ||
_pointerEnd(event) { | ||
if (!this._triggerPointerEnd(new Pointer(event), event)) | ||
return; | ||
if (isPointerEvent(event)) { | ||
if (this.currentPointers.length) | ||
return; | ||
this._element.removeEventListener('pointermove', this._move); | ||
this._element.removeEventListener('pointerup', this._pointerEnd); | ||
} | ||
else { // MouseEvent | ||
window.removeEventListener('mousemove', this._move); | ||
window.removeEventListener('mouseup', this._pointerEnd); | ||
} | ||
} | ||
/** | ||
* Listener for touchend. Bound to the class in the constructor. | ||
* Only used if the browser doesn't support pointer events. | ||
*/ | ||
_touchEnd(event) { | ||
for (const touch of Array.from(event.changedTouches)) { | ||
this._triggerPointerEnd(new Pointer(touch), event); | ||
} | ||
} | ||
} | ||
@@ -191,0 +204,0 @@ |
112
lib/index.ts
@@ -1,2 +0,16 @@ | ||
const enum Button { Left } | ||
/** | ||
* Copyright 2020 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
const enum Button { | ||
Left, | ||
} | ||
@@ -17,3 +31,3 @@ class Pointer { | ||
constructor (nativePointer: Touch | PointerEvent | MouseEvent) { | ||
constructor(nativePointer: Touch | PointerEvent | MouseEvent) { | ||
this.nativePointer = nativePointer; | ||
@@ -27,3 +41,4 @@ this.pageX = nativePointer.pageX; | ||
this.id = nativePointer.identifier; | ||
} else if (isPointerEvent(nativePointer)) { // is PointerEvent | ||
} else if (isPointerEvent(nativePointer)) { | ||
// is PointerEvent | ||
this.id = nativePointer.pointerId; | ||
@@ -118,8 +133,7 @@ } | ||
*/ | ||
constructor (private _element: HTMLElement, callbacks: PointerTrackerCallbacks) { | ||
const { | ||
start = () => true, | ||
move = noop, | ||
end = noop, | ||
} = callbacks; | ||
constructor( | ||
private _element: HTMLElement, | ||
callbacks: PointerTrackerCallbacks, | ||
) { | ||
const { start = () => true, move = noop, end = noop } = callbacks; | ||
@@ -130,10 +144,2 @@ this._startCallback = start; | ||
// Bind methods | ||
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); | ||
// Add listeners | ||
@@ -151,2 +157,17 @@ if (self.PointerEvent) { | ||
/** | ||
* Remove all listeners. | ||
*/ | ||
stop() { | ||
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._element.addEventListener('pointermove', this._move); | ||
this._element.addEventListener('pointerup', this._pointerEnd); | ||
window.addEventListener('mousemove', this._move); | ||
window.addEventListener('mouseup', this._pointerEnd); | ||
} | ||
/** | ||
* Call the start callback for this pointer, and track it if the user wants. | ||
@@ -166,3 +187,3 @@ * | ||
/** | ||
* Listener for mouse/pointer starts. Bound to the class in the constructor. | ||
* Listener for mouse/pointer starts. | ||
* | ||
@@ -172,3 +193,3 @@ * @param event This will only be a MouseEvent if the browser doesn't support | ||
*/ | ||
private _pointerStart(event: PointerEvent | MouseEvent) { | ||
private _pointerStart = (event: PointerEvent | MouseEvent) => { | ||
if (event.button !== Button.Left) return; | ||
@@ -180,30 +201,36 @@ if (!this._triggerPointerStart(new Pointer(event), event)) return; | ||
if (isPointerEvent(event)) { | ||
this._element.setPointerCapture(event.pointerId); | ||
const capturingElement = | ||
event.target && 'setPointerCapture' in event.target | ||
? event.target | ||
: this._element; | ||
capturingElement.setPointerCapture(event.pointerId); | ||
this._element.addEventListener('pointermove', this._move); | ||
this._element.addEventListener('pointerup', this._pointerEnd); | ||
} else { // MouseEvent | ||
} else { | ||
// MouseEvent | ||
window.addEventListener('mousemove', this._move); | ||
window.addEventListener('mouseup', this._pointerEnd); | ||
} | ||
} | ||
}; | ||
/** | ||
* Listener for touchstart. Bound to the class in the constructor. | ||
* Listener for touchstart. | ||
* Only used if the browser doesn't support pointer events. | ||
*/ | ||
private _touchStart(event: TouchEvent) { | ||
private _touchStart = (event: TouchEvent) => { | ||
for (const touch of Array.from(event.changedTouches)) { | ||
this._triggerPointerStart(new Pointer(touch), event); | ||
} | ||
} | ||
}; | ||
/** | ||
* Listener for pointer/mouse/touch move events. | ||
* Bound to the class in the constructor. | ||
*/ | ||
private _move(event: PointerEvent | MouseEvent | TouchEvent) { | ||
private _move = (event: PointerEvent | MouseEvent | TouchEvent) => { | ||
const previousPointers = this.currentPointers.slice(); | ||
const changedPointers = ('changedTouches' in event) ? // Shortcut for 'is touch event'. | ||
Array.from(event.changedTouches).map(t => new Pointer(t)) : | ||
[new Pointer(event)]; | ||
const changedPointers = | ||
'changedTouches' in event // Shortcut for 'is touch event'. | ||
? Array.from(event.changedTouches).map(t => new Pointer(t)) | ||
: [new Pointer(event)]; | ||
const trackedChangedPointers = []; | ||
@@ -221,3 +248,3 @@ | ||
this._moveCallback(previousPointers, trackedChangedPointers, event); | ||
} | ||
}; | ||
@@ -230,3 +257,6 @@ /** | ||
*/ | ||
private _triggerPointerEnd(pointer: Pointer, event: InputEvent): boolean { | ||
private _triggerPointerEnd = ( | ||
pointer: Pointer, | ||
event: InputEvent, | ||
): boolean => { | ||
const index = this.currentPointers.findIndex(p => p.id === pointer.id); | ||
@@ -241,10 +271,11 @@ // Not a pointer we're interested in? | ||
return true; | ||
} | ||
}; | ||
/** | ||
* Listener for mouse/pointer ends. Bound to the class in the constructor. | ||
* Listener for mouse/pointer ends. | ||
* | ||
* @param event This will only be a MouseEvent if the browser doesn't support | ||
* pointer events. | ||
*/ | ||
private _pointerEnd(event: PointerEvent | MouseEvent) { | ||
private _pointerEnd = (event: PointerEvent | MouseEvent) => { | ||
if (!this._triggerPointerEnd(new Pointer(event), event)) return; | ||
@@ -256,17 +287,18 @@ | ||
this._element.removeEventListener('pointerup', this._pointerEnd); | ||
} else { // MouseEvent | ||
} else { | ||
// MouseEvent | ||
window.removeEventListener('mousemove', this._move); | ||
window.removeEventListener('mouseup', this._pointerEnd); | ||
} | ||
} | ||
}; | ||
/** | ||
* Listener for touchend. Bound to the class in the constructor. | ||
* Listener for touchend. | ||
* Only used if the browser doesn't support pointer events. | ||
*/ | ||
private _touchEnd(event: TouchEvent) { | ||
private _touchEnd = (event: TouchEvent) => { | ||
for (const touch of Array.from(event.changedTouches)) { | ||
this._triggerPointerEnd(new Pointer(touch), event); | ||
} | ||
} | ||
}; | ||
} |
@@ -0,1 +1,13 @@ | ||
/** | ||
* Copyright 2020 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
// TypeScript, you make me sad. | ||
@@ -2,0 +14,0 @@ // https://github.com/Microsoft/TypeScript/issues/18756 |
{ | ||
"name": "pointer-tracker", | ||
"version": "2.0.3", | ||
"version": "2.1.0", | ||
"description": "Track mouse/touch/pointer events through one interface", | ||
@@ -28,10 +28,19 @@ "main": "dist/PointerTracker.js", | ||
"devDependencies": { | ||
"rollup": "^0.66.6", | ||
"rollup-plugin-terser": "^3.0.0", | ||
"rollup-plugin-typescript2": "^0.17.2", | ||
"tslint": "^5.11.0", | ||
"tslint-config-airbnb": "^5.11.0", | ||
"tslint-react": "^3.6.0", | ||
"typescript": "^3.1.4" | ||
"husky": "^4.2.3", | ||
"lint-staged": "^10.0.8", | ||
"prettier": "1.19.1", | ||
"rollup": "^1.32.0", | ||
"rollup-plugin-terser": "^5.2.0", | ||
"rollup-plugin-typescript2": "^0.26.0", | ||
"typescript": "^3.8.3" | ||
}, | ||
"dependencies": {}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged" | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.{js,css,md,ts}": "prettier --write" | ||
} | ||
} |
@@ -31,3 +31,3 @@ # PointerTracker | ||
// event - The event related to this pointer. | ||
} | ||
}, | ||
}); | ||
@@ -40,2 +40,4 @@ | ||
pointerTracker.currentPointers; | ||
// Remove all listeners. Call this when you're done tracking. | ||
pointerTracker.stop(); | ||
``` | ||
@@ -70,5 +72,5 @@ | ||
* `lib/index.ts` - Original TypeScript. | ||
* `dist/PointerTracker.mjs` - JS module. Default exports PointerTracker. | ||
* `dist/PointerTracker.js` - Plain JS. Exposes PointerTracker on the global. | ||
* `dist/PointerTracker-min.js` - Minified plain JS. ~800 bytes gzipped. | ||
- `lib/index.ts` - Original TypeScript. | ||
- `dist/PointerTracker.mjs` - JS module. Default exports PointerTracker. | ||
- `dist/PointerTracker.js` - Plain JS. Exposes PointerTracker on the global. | ||
- `dist/PointerTracker-min.js` - Minified plain JS. ~800 bytes gzipped. |
@@ -0,10 +1,22 @@ | ||
/** | ||
* Copyright 2020 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import typescript from 'rollup-plugin-typescript2'; | ||
import { terser } from "rollup-plugin-terser"; | ||
import { terser } from 'rollup-plugin-terser'; | ||
const esm = { | ||
plugins: [ typescript({ useTsconfigDeclarationDir: false }) ], | ||
plugins: [typescript({ useTsconfigDeclarationDir: false })], | ||
input: 'lib/index.ts', | ||
output: { | ||
file: 'dist/PointerTracker.mjs', | ||
format: 'esm' | ||
format: 'esm', | ||
}, | ||
@@ -18,3 +30,3 @@ }; | ||
format: 'iife', | ||
name: 'PointerTracker' | ||
name: 'PointerTracker', | ||
}, | ||
@@ -28,3 +40,3 @@ }; | ||
compress: { ecma: 6 }, | ||
}) | ||
}), | ||
], | ||
@@ -34,3 +46,3 @@ output: { | ||
format: 'iife', | ||
name: 'PointerTracker' | ||
name: 'PointerTracker', | ||
}, | ||
@@ -37,0 +49,0 @@ }; |
Sorry, the diff of this file is not supported yet
50906
13
882
74