Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pointer-tracker

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pointer-tracker - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

28

dist/index.d.ts

@@ -25,3 +25,3 @@ declare class Pointer {

declare type MoveCallback = (previousPointers: Pointer[], changedPointers: Pointer[], event: InputEvent) => void;
declare type EndCallback = (pointer: Pointer, event: InputEvent) => void;
declare type EndCallback = (pointer: Pointer, event: InputEvent, cancelled: boolean) => void;
interface PointerTrackerCallbacks {

@@ -31,4 +31,4 @@ /**

*
* @param pointer The new pointer.
* This pointer isn't included in this.currentPointers or this.startPointers yet.
* @param pointer The new pointer. This pointer isn't included in this.currentPointers or
* this.startPointers yet.
* @param event The event related to this pointer.

@@ -42,5 +42,4 @@ *

*
* @param previousPointers The state of the pointers before this event.
* This contains the same number of pointers, in the same order, as
* this.currentPointers and this.startPointers.
* @param previousPointers The state of the pointers before this event. This contains the same
* number of pointers, in the same order, as this.currentPointers and this.startPointers.
* @param changedPointers The pointers that have changed since the last move callback.

@@ -53,6 +52,7 @@ * @param event The event related to the pointer changes.

*
* @param pointer The final state of the pointer that ended. This
* pointer is now absent from this.currentPointers and
* this.startPointers.
* @param pointer The final state of the pointer that ended. This pointer is now absent from
* this.currentPointers and this.startPointers.
* @param event The event related to this pointer.
* @param cancelled Was the action cancelled? Actions are cancelled when the OS takes over pointer
* events, for actions such as scrolling.
*/

@@ -71,4 +71,4 @@ end?: EndCallback;

/**
* Latest state of the tracked pointers. Contains the same number
* of pointers, and in the same order as this.startPointers.
* Latest state of the tracked pointers. Contains the same number of pointers, and in the same
* order as this.startPointers.
*/

@@ -101,4 +101,3 @@ readonly currentPointers: Pointer[];

*
* @param event This will only be a MouseEvent if the browser doesn't support
* pointer events.
* @param event This will only be a MouseEvent if the browser doesn't support pointer events.
*/

@@ -125,4 +124,3 @@ private _pointerStart;

*
* @param event This will only be a MouseEvent if the browser doesn't support
* pointer events.
* @param event This will only be a MouseEvent if the browser doesn't support pointer events.
*/

@@ -129,0 +127,0 @@ private _pointerEnd;

@@ -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,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)}}}();
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),this._element.addEventListener("pointercancel",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);if(-1===n)return!1;this.currentPointers.splice(n,1),this.startPointers.splice(n,1);const i="touchcancel"===e.type||"pointercancel"===e.type;return this._endCallback(t,e,i),!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),this._element.removeEventListener("pointercancel",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),this._element.addEventListener("touchcancel",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("touchcancel",this._touchEnd),this._element.addEventListener("pointermove",this._move),this._element.addEventListener("pointerup",this._pointerEnd),this._element.addEventListener("pointercancel",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)}}}();

@@ -50,4 +50,4 @@ var PointerTracker = (function () {

/**
* Latest state of the tracked pointers. Contains the same number
* of pointers, and in the same order as this.startPointers.
* Latest state of the tracked pointers. Contains the same number of pointers, and in the same
* order as this.startPointers.
*/

@@ -58,4 +58,3 @@ this.currentPointers = [];

*
* @param event This will only be a MouseEvent if the browser doesn't support
* pointer events.
* @param event This will only be a MouseEvent if the browser doesn't support pointer events.
*/

@@ -76,2 +75,3 @@ this._pointerStart = (event) => {

this._element.addEventListener('pointerup', this._pointerEnd);
this._element.addEventListener('pointercancel', this._pointerEnd);
}

@@ -126,3 +126,4 @@ else {

this.startPointers.splice(index, 1);
this._endCallback(pointer, event);
const cancelled = event.type === 'touchcancel' || event.type === 'pointercancel';
this._endCallback(pointer, event, cancelled);
return true;

@@ -133,4 +134,3 @@ };

*
* @param event This will only be a MouseEvent if the browser doesn't support
* pointer events.
* @param event This will only be a MouseEvent if the browser doesn't support pointer events.
*/

@@ -145,2 +145,3 @@ this._pointerEnd = (event) => {

this._element.removeEventListener('pointerup', this._pointerEnd);
this._element.removeEventListener('pointercancel', this._pointerEnd);
}

@@ -175,2 +176,3 @@ else {

this._element.addEventListener('touchend', this._touchEnd);
this._element.addEventListener('touchcancel', this._touchEnd);
}

@@ -187,4 +189,6 @@ }

this._element.addEventListener('touchend', this._touchEnd);
this._element.addEventListener('touchcancel', this._touchEnd);
this._element.addEventListener('pointermove', this._move);
this._element.addEventListener('pointerup', this._pointerEnd);
this._element.addEventListener('pointercancel', this._pointerEnd);
window.addEventListener('mousemove', this._move);

@@ -191,0 +195,0 @@ window.addEventListener('mouseup', this._pointerEnd);

@@ -73,3 +73,7 @@ /**

) => void;
type EndCallback = (pointer: Pointer, event: InputEvent) => void;
type EndCallback = (
pointer: Pointer,
event: InputEvent,
cancelled: boolean,
) => void;

@@ -80,4 +84,4 @@ interface PointerTrackerCallbacks {

*
* @param pointer The new pointer.
* This pointer isn't included in this.currentPointers or this.startPointers yet.
* @param pointer The new pointer. This pointer isn't included in this.currentPointers or
* this.startPointers yet.
* @param event The event related to this pointer.

@@ -91,5 +95,4 @@ *

*
* @param previousPointers The state of the pointers before this event.
* This contains the same number of pointers, in the same order, as
* this.currentPointers and this.startPointers.
* @param previousPointers The state of the pointers before this event. This contains the same
* number of pointers, in the same order, as this.currentPointers and this.startPointers.
* @param changedPointers The pointers that have changed since the last move callback.

@@ -102,6 +105,7 @@ * @param event The event related to the pointer changes.

*
* @param pointer The final state of the pointer that ended. This
* pointer is now absent from this.currentPointers and
* this.startPointers.
* @param pointer The final state of the pointer that ended. This pointer is now absent from
* this.currentPointers and this.startPointers.
* @param event The event related to this pointer.
* @param cancelled Was the action cancelled? Actions are cancelled when the OS takes over pointer
* events, for actions such as scrolling.
*/

@@ -120,4 +124,4 @@ end?: EndCallback;

/**
* Latest state of the tracked pointers. Contains the same number
* of pointers, and in the same order as this.startPointers.
* Latest state of the tracked pointers. Contains the same number of pointers, and in the same
* order as this.startPointers.
*/

@@ -154,2 +158,3 @@ readonly currentPointers: Pointer[] = [];

this._element.addEventListener('touchend', this._touchEnd);
this._element.addEventListener('touchcancel', this._touchEnd);
}

@@ -167,4 +172,6 @@ }

this._element.addEventListener('touchend', this._touchEnd);
this._element.addEventListener('touchcancel', this._touchEnd);
this._element.addEventListener('pointermove', this._move);
this._element.addEventListener('pointerup', this._pointerEnd);
this._element.addEventListener('pointercancel', this._pointerEnd);
window.addEventListener('mousemove', this._move);

@@ -191,4 +198,3 @@ window.addEventListener('mouseup', this._pointerEnd);

*
* @param event This will only be a MouseEvent if the browser doesn't support
* pointer events.
* @param event This will only be a MouseEvent if the browser doesn't support pointer events.
*/

@@ -210,2 +216,3 @@ private _pointerStart = (event: PointerEvent | MouseEvent) => {

this._element.addEventListener('pointerup', this._pointerEnd);
this._element.addEventListener('pointercancel', this._pointerEnd);
} else {

@@ -268,3 +275,6 @@ // MouseEvent

this._endCallback(pointer, event);
const cancelled =
event.type === 'touchcancel' || event.type === 'pointercancel';
this._endCallback(pointer, event, cancelled);
return true;

@@ -276,4 +286,3 @@ };

*
* @param event This will only be a MouseEvent if the browser doesn't support
* pointer events.
* @param event This will only be a MouseEvent if the browser doesn't support pointer events.
*/

@@ -287,2 +296,3 @@ private _pointerEnd = (event: PointerEvent | MouseEvent) => {

this._element.removeEventListener('pointerup', this._pointerEnd);
this._element.removeEventListener('pointercancel', this._pointerEnd);
} else {

@@ -289,0 +299,0 @@ // MouseEvent

{
"name": "pointer-tracker",
"version": "2.1.0",
"version": "2.2.0",
"description": "Track mouse/touch/pointer events through one interface",

@@ -31,4 +31,4 @@ "main": "dist/PointerTracker.js",

"prettier": "1.19.1",
"rollup": "^1.32.0",
"rollup-plugin-terser": "^5.2.0",
"rollup": "^2.1.0",
"rollup-plugin-terser": "^5.3.0",
"rollup-plugin-typescript2": "^0.26.0",

@@ -35,0 +35,0 @@ "typescript": "^3.8.3"

@@ -26,7 +26,9 @@ # PointerTracker

},
end(pointer, event) {
end(pointer, event, cancelled) {
// Called when a pointer is released.
// pointer - The final state of the pointer that ended. This pointer is now absent from
// this.currentPointers and this.startPointers.
// this.currentPointers and this.startPointers.
// event - The event related to this pointer.
// cancelled - True if the event was cancelled. Actions are cancelled when the OS takes over
// pointer events, for actions such as scrolling.
},

@@ -74,2 +76,2 @@ });

- `dist/PointerTracker.js` - Plain JS. Exposes PointerTracker on the global.
- `dist/PointerTracker-min.js` - Minified plain JS. ~800 bytes gzipped.
- `dist/PointerTracker-min.js` - Minified plain JS. ~770 bytes brotli'd.

@@ -27,23 +27,21 @@ /**

input: 'dist/PointerTracker.mjs',
output: {
file: 'dist/PointerTracker.js',
format: 'iife',
name: 'PointerTracker',
},
};
const iffeMin = {
input: 'dist/PointerTracker.mjs',
plugins: [
terser({
compress: { ecma: 6 },
}),
output: [
{
file: 'dist/PointerTracker.js',
format: 'iife',
name: 'PointerTracker',
},
{
plugins: [
terser({
compress: { ecma: 6 },
}),
],
file: 'dist/PointerTracker-min.js',
format: 'iife',
name: 'PointerTracker',
},
],
output: {
file: 'dist/PointerTracker-min.js',
format: 'iife',
name: 'PointerTracker',
},
};
export default [esm, iffe, iffeMin];
export default [esm, iffe];

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc