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.5.2 to 2.5.3

8

dist/index.d.ts

@@ -91,2 +91,10 @@ declare class Pointer {

/**
* Firefox has a bug where touch-based pointer events have a `buttons` of 0, when this shouldn't
* happen. https://bugzilla.mozilla.org/show_bug.cgi?id=1729440
*
* Usually we treat `buttons === 0` as no-longer-pressed. This set allows us to exclude these
* buggy Firefox events.
*/
private _excludeFromButtonsCheck;
/**
* Track pointers across a particular element

@@ -93,0 +101,0 @@ *

2

dist/PointerTracker-min.js

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PointerTracker=t()}(this,(function(){"use strict";class e{constructor(e){this.id=-1,this.nativePointer=e,this.pageX=e.pageX,this.pageY=e.pageY,this.clientX=e.clientX,this.clientY=e.clientY,self.Touch&&e instanceof Touch?this.id=e.identifier:t(e)&&(this.id=e.pointerId)}getCoalesced(){return"getCoalescedEvents"in this.nativePointer?this.nativePointer.getCoalescedEvents().map(t=>new e(t)):[this]}}const t=e=>"pointerId"in e,n=e=>"changedTouches"in e,i=()=>{};return class{constructor(r,{start:s=(()=>!0),move:o=i,end:h=i,rawUpdates:d=!1,avoidPointerEvents:a=!1}={}){this._element=r,this.startPointers=[],this.currentPointers=[],this._pointerStart=n=>{if(!(1&n.buttons))return;const i=new e(n);if(!this.currentPointers.some(e=>e.id===i.id)&&this._triggerPointerStart(i,n))if(t(n)){(n.target&&"setPointerCapture"in n.target?n.target:this._element).setPointerCapture(n.pointerId),this._element.addEventListener(this._rawUpdates?"pointerrawupdate":"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=t=>{for(const n of Array.from(t.changedTouches))this._triggerPointerStart(new e(n),t)},this._move=t=>{if(!n(t)&&0===t.buttons)return void this._pointerEnd(t);const i=this.currentPointers.slice(),r=n(t)?Array.from(t.changedTouches).map(t=>new e(t)):[new e(t)],s=[];for(const e of r){const t=this.currentPointers.findIndex(t=>t.id===e.id);-1!==t&&(s.push(e),this.currentPointers[t]=e)}0!==s.length&&this._moveCallback(i,s,t)},this._triggerPointerEnd=(e,t)=>{if(!n(t)&&1&t.buttons)return!1;const i=this.currentPointers.findIndex(t=>t.id===e.id);if(-1===i)return!1;this.currentPointers.splice(i,1),this.startPointers.splice(i,1);const r=!("mouseup"===t.type||"touchend"===t.type||"pointerup"===t.type);return this._endCallback(e,t,r),!0},this._pointerEnd=n=>{if(this._triggerPointerEnd(new e(n),n))if(t(n)){if(this.currentPointers.length)return;this._element.removeEventListener(this._rawUpdates?"pointerrawupdate":"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=t=>{for(const n of Array.from(t.changedTouches))this._triggerPointerEnd(new e(n),t)},this._startCallback=s,this._moveCallback=o,this._endCallback=h,this._rawUpdates=d&&"onpointerrawupdate"in window,self.PointerEvent&&!a?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.removeEventListener("pointerdown",this._pointerStart),this._element.removeEventListener("mousedown",this._pointerStart),this._element.removeEventListener("touchstart",this._touchStart),this._element.removeEventListener("touchmove",this._move),this._element.removeEventListener("touchend",this._touchEnd),this._element.removeEventListener("touchcancel",this._touchEnd),this._element.removeEventListener(this._rawUpdates?"pointerrawupdate":"pointermove",this._move),this._element.removeEventListener("pointerup",this._pointerEnd),this._element.removeEventListener("pointercancel",this._pointerEnd),window.removeEventListener("mousemove",this._move),window.removeEventListener("mouseup",this._pointerEnd)}_triggerPointerStart(e,t){return!!this._startCallback(e,t)&&(this.currentPointers.push(e),this.startPointers.push(e),!0)}}}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PointerTracker=t()}(this,(function(){"use strict";class e{constructor(e){this.id=-1,this.nativePointer=e,this.pageX=e.pageX,this.pageY=e.pageY,this.clientX=e.clientX,this.clientY=e.clientY,self.Touch&&e instanceof Touch?this.id=e.identifier:t(e)&&(this.id=e.pointerId)}getCoalesced(){if("getCoalescedEvents"in this.nativePointer){const t=this.nativePointer.getCoalescedEvents().map(t=>new e(t));if(t.length>0)return t}return[this]}}const t=e=>"pointerId"in e,n=e=>"changedTouches"in e,i=()=>{};return class{constructor(s,{start:r=(()=>!0),move:o=i,end:h=i,rawUpdates:d=!1,avoidPointerEvents:a=!1}={}){this._element=s,this.startPointers=[],this.currentPointers=[],this._excludeFromButtonsCheck=new Set,this._pointerStart=n=>{if(t(n)&&0===n.buttons)this._excludeFromButtonsCheck.add(n.pointerId);else if(!(1&n.buttons))return;const i=new e(n);if(!this.currentPointers.some(e=>e.id===i.id)&&this._triggerPointerStart(i,n))if(t(n)){(n.target&&"setPointerCapture"in n.target?n.target:this._element).setPointerCapture(n.pointerId),this._element.addEventListener(this._rawUpdates?"pointerrawupdate":"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=t=>{for(const n of Array.from(t.changedTouches))this._triggerPointerStart(new e(n),t)},this._move=i=>{if(!(n(i)||t(i)&&this._excludeFromButtonsCheck.has(i.pointerId)||0!==i.buttons))return void this._pointerEnd(i);const s=this.currentPointers.slice(),r=n(i)?Array.from(i.changedTouches).map(t=>new e(t)):[new e(i)],o=[];for(const e of r){const t=this.currentPointers.findIndex(t=>t.id===e.id);-1!==t&&(o.push(e),this.currentPointers[t]=e)}0!==o.length&&this._moveCallback(s,o,i)},this._triggerPointerEnd=(e,t)=>{if(!n(t)&&1&t.buttons)return!1;const i=this.currentPointers.findIndex(t=>t.id===e.id);if(-1===i)return!1;this.currentPointers.splice(i,1),this.startPointers.splice(i,1),this._excludeFromButtonsCheck.delete(e.id);const s=!("mouseup"===t.type||"touchend"===t.type||"pointerup"===t.type);return this._endCallback(e,t,s),!0},this._pointerEnd=n=>{if(this._triggerPointerEnd(new e(n),n))if(t(n)){if(this.currentPointers.length)return;this._element.removeEventListener(this._rawUpdates?"pointerrawupdate":"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=t=>{for(const n of Array.from(t.changedTouches))this._triggerPointerEnd(new e(n),t)},this._startCallback=r,this._moveCallback=o,this._endCallback=h,this._rawUpdates=d&&"onpointerrawupdate"in window,self.PointerEvent&&!a?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.removeEventListener("pointerdown",this._pointerStart),this._element.removeEventListener("mousedown",this._pointerStart),this._element.removeEventListener("touchstart",this._touchStart),this._element.removeEventListener("touchmove",this._move),this._element.removeEventListener("touchend",this._touchEnd),this._element.removeEventListener("touchcancel",this._touchEnd),this._element.removeEventListener(this._rawUpdates?"pointerrawupdate":"pointermove",this._move),this._element.removeEventListener("pointerup",this._pointerEnd),this._element.removeEventListener("pointercancel",this._pointerEnd),window.removeEventListener("mousemove",this._move),window.removeEventListener("mouseup",this._pointerEnd)}_triggerPointerStart(e,t){return!!this._startCallback(e,t)&&(this.currentPointers.push(e),this.startPointers.push(e),!0)}}}));

@@ -29,3 +29,9 @@ (function (global, factory) {

if ('getCoalescedEvents' in this.nativePointer) {
return this.nativePointer.getCoalescedEvents().map((p) => new Pointer(p));
const events = this.nativePointer
.getCoalescedEvents()
.map((p) => new Pointer(p));
// Firefox sometimes returns an empty list here. I'm not sure it's doing the right thing.
// https://github.com/w3c/pointerevents/issues/409
if (events.length > 0)
return events;
}

@@ -60,2 +66,10 @@ return [this];

/**
* Firefox has a bug where touch-based pointer events have a `buttons` of 0, when this shouldn't
* happen. https://bugzilla.mozilla.org/show_bug.cgi?id=1729440
*
* Usually we treat `buttons === 0` as no-longer-pressed. This set allows us to exclude these
* buggy Firefox events.
*/
this._excludeFromButtonsCheck = new Set();
/**
* Listener for mouse/pointer starts.

@@ -66,4 +80,9 @@ *

this._pointerStart = (event) => {
if (!(event.buttons & 1 /* LeftMouseOrTouchOrPenDown */))
if (isPointerEvent(event) && event.buttons === 0) {
// This is the buggy Firefox case. See _excludeFromButtonsCheck.
this._excludeFromButtonsCheck.add(event.pointerId);
}
else if (!(event.buttons & 1 /* LeftMouseOrTouchOrPenDown */)) {
return;
}
const pointer = new Pointer(event);

@@ -106,3 +125,6 @@ // If we're already tracking this pointer, ignore this event.

this._move = (event) => {
if (!isTouchEvent(event) && event.buttons === 0 /* None */) {
if (!isTouchEvent(event) &&
(!isPointerEvent(event) ||
!this._excludeFromButtonsCheck.has(event.pointerId)) &&
event.buttons === 0 /* None */) {
// This happens in a number of buggy cases where the browser failed to deliver a pointerup

@@ -150,2 +172,3 @@ // or pointercancel. If we see the pointer moving without any buttons down, synthesize an end.

this.startPointers.splice(index, 1);
this._excludeFromButtonsCheck.delete(pointer.id);
// The event.type might be a 'move' event due to workarounds for weird mouse behaviour.

@@ -152,0 +175,0 @@ // See _move for details.

@@ -52,3 +52,9 @@ /**

if ('getCoalescedEvents' in this.nativePointer) {
return this.nativePointer.getCoalescedEvents().map((p) => new Pointer(p));
const events = this.nativePointer
.getCoalescedEvents()
.map((p) => new Pointer(p));
// Firefox sometimes returns an empty list here. I'm not sure it's doing the right thing.
// https://github.com/w3c/pointerevents/issues/409
if (events.length > 0) return events;
// Otherwise, Firefox falls through…
}

@@ -151,2 +157,11 @@ return [this];

/**
* Firefox has a bug where touch-based pointer events have a `buttons` of 0, when this shouldn't
* happen. https://bugzilla.mozilla.org/show_bug.cgi?id=1729440
*
* Usually we treat `buttons === 0` as no-longer-pressed. This set allows us to exclude these
* buggy Firefox events.
*/
private _excludeFromButtonsCheck = new Set<number>();
/**
* Track pointers across a particular element

@@ -224,3 +239,8 @@ *

private _pointerStart = (event: PointerEvent | MouseEvent) => {
if (!(event.buttons & Buttons.LeftMouseOrTouchOrPenDown)) return;
if (isPointerEvent(event) && event.buttons === 0) {
// This is the buggy Firefox case. See _excludeFromButtonsCheck.
this._excludeFromButtonsCheck.add(event.pointerId);
} else if (!(event.buttons & Buttons.LeftMouseOrTouchOrPenDown)) {
return;
}
const pointer = new Pointer(event);

@@ -269,3 +289,8 @@ // If we're already tracking this pointer, ignore this event.

private _move = (event: PointerEvent | MouseEvent | TouchEvent) => {
if (!isTouchEvent(event) && event.buttons === Buttons.None) {
if (
!isTouchEvent(event) &&
(!isPointerEvent(event) ||
!this._excludeFromButtonsCheck.has(event.pointerId)) &&
event.buttons === Buttons.None
) {
// This happens in a number of buggy cases where the browser failed to deliver a pointerup

@@ -320,2 +345,3 @@ // or pointercancel. If we see the pointer moving without any buttons down, synthesize an end.

this.startPointers.splice(index, 1);
this._excludeFromButtonsCheck.delete(pointer.id);

@@ -322,0 +348,0 @@ // The event.type might be a 'move' event due to workarounds for weird mouse behaviour.

{
"name": "pointer-tracker",
"version": "2.5.2",
"version": "2.5.3",
"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

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