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.4.0 to 2.5.0

12

dist/index.d.ts

@@ -57,4 +57,14 @@ declare class Pointer {

/**
* Avoid pointer events in favour of touch and mouse events?
*
* Even if the browser supports pointer events, you may want to force the browser to use
* mouse/touch fallbacks, to work around bugs such as
* https://bugs.webkit.org/show_bug.cgi?id=220196.
*/
avoidPointerEvents?: boolean;
/**
* Use raw pointer updates? Pointer events are usually synchronised to requestAnimationFrame.
* However, if you're targeting a desynchronised canvas, then faster 'raw' updates are better.
*
* This feature only applies to pointer events.
*/

@@ -87,3 +97,3 @@ rawUpdates?: boolean;

*/
constructor(_element: HTMLElement, { start, move, end, rawUpdates, }?: PointerTrackerOptions);
constructor(_element: HTMLElement, { start, move, end, rawUpdates, avoidPointerEvents, }?: PointerTrackerOptions);
/**

@@ -90,0 +100,0 @@ * Remove all listeners.

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=>self.PointerEvent&&e instanceof PointerEvent,n=()=>{};return class{constructor(i,{start:s=(()=>!0),move:r=n,end:o=n,rawUpdates:h=!1}={}){this._element=i,this.startPointers=[],this.currentPointers=[],this._pointerStart=n=>{if(0===n.button&&this._triggerPointerStart(new e(n),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=>{const n=this.currentPointers.slice(),i="changedTouches"in t?Array.from(t.changedTouches).map(t=>new e(t)):[new e(t)],s=[];for(const e of i){const t=this.currentPointers.findIndex(t=>t.id===e.id);-1!==t&&(s.push(e),this.currentPointers[t]=e)}0!==s.length&&this._moveCallback(n,s,t)},this._triggerPointerEnd=(e,t)=>{const n=this.currentPointers.findIndex(t=>t.id===e.id);if(-1===n)return!1;this.currentPointers.splice(n,1),this.startPointers.splice(n,1);const i="touchcancel"===t.type||"pointercancel"===t.type;return this._endCallback(e,t,i),!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=r,this._endCallback=o,this._rawUpdates=h&&"onpointerrawupdate"in window,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.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(){return"getCoalescedEvents"in this.nativePointer?this.nativePointer.getCoalescedEvents().map(t=>new e(t)):[this]}}const t=e=>self.PointerEvent&&e instanceof PointerEvent,n=()=>{};return class{constructor(i,{start:s=(()=>!0),move:r=n,end:o=n,rawUpdates:h=!1,avoidPointerEvents:a=!1}={}){this._element=i,this.startPointers=[],this.currentPointers=[],this._pointerStart=n=>{if(0===n.button&&this._triggerPointerStart(new e(n),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=>{const n=this.currentPointers.slice(),i="changedTouches"in t?Array.from(t.changedTouches).map(t=>new e(t)):[new e(t)],s=[];for(const e of i){const t=this.currentPointers.findIndex(t=>t.id===e.id);-1!==t&&(s.push(e),this.currentPointers[t]=e)}0!==s.length&&this._moveCallback(n,s,t)},this._triggerPointerEnd=(e,t)=>{const n=this.currentPointers.findIndex(t=>t.id===e.id);if(-1===n)return!1;this.currentPointers.splice(n,1),this.startPointers.splice(n,1);const i="touchcancel"===t.type||"pointercancel"===t.type;return this._endCallback(e,t,i),!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=r,this._endCallback=o,this._rawUpdates=h&&"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)}}}));

@@ -46,3 +46,3 @@ (function (global, factory) {

*/
constructor(_element, { start = () => true, move = noop, end = noop, rawUpdates = false, } = {}) {
constructor(_element, { start = () => true, move = noop, end = noop, rawUpdates = false, avoidPointerEvents = false, } = {}) {
this._element = _element;

@@ -166,3 +166,3 @@ /**

// Add listeners
if (self.PointerEvent) {
if (self.PointerEvent && !avoidPointerEvents) {
this._element.addEventListener('pointerdown', this._pointerStart);

@@ -169,0 +169,0 @@ }

@@ -110,4 +110,14 @@ /**

/**
* Avoid pointer events in favour of touch and mouse events?
*
* Even if the browser supports pointer events, you may want to force the browser to use
* mouse/touch fallbacks, to work around bugs such as
* https://bugs.webkit.org/show_bug.cgi?id=220196.
*/
avoidPointerEvents?: boolean;
/**
* Use raw pointer updates? Pointer events are usually synchronised to requestAnimationFrame.
* However, if you're targeting a desynchronised canvas, then faster 'raw' updates are better.
*
* This feature only applies to pointer events.
*/

@@ -149,2 +159,3 @@ rawUpdates?: boolean;

rawUpdates = false,
avoidPointerEvents = false,
}: PointerTrackerOptions = {},

@@ -158,3 +169,3 @@ ) {

// Add listeners
if (self.PointerEvent) {
if (self.PointerEvent && !avoidPointerEvents) {
this._element.addEventListener('pointerdown', this._pointerStart);

@@ -161,0 +172,0 @@ } else {

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

@@ -8,2 +8,10 @@ "main": "dist/PointerTracker.js",

"types": "dist/index.d.ts",
"exports": {
".": {
"require": "./dist/PointerTracker.js",
"import": "./dist/PointerTracker.mjs"
},
"./dist/*": "./dist/*",
"./package.json": "./package.json"
},
"scripts": {

@@ -10,0 +18,0 @@ "build": "rm -rf dist && rollup -c"

@@ -34,5 +34,14 @@ # PointerTracker

},
// Avoid pointer events in favour of touch and mouse events?
//
// Even if the browser supports pointer events, you may want to force the browser to use
// mouse/touch fallbacks, to work around bugs such as
// https://bugs.webkit.org/show_bug.cgi?id=220196.
//
// The default is false.
avoidPointerEvents: false,
// Use raw pointer updates? Pointer events are usually synchronised to requestAnimationFrame.
// However, if you're targeting a desynchronised canvas, then faster 'raw' updates are better.
// The default is false.
//
// This feature only applies to pointer events. The default is false.
rawUpdates: false,

@@ -39,0 +48,0 @@ });

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