Socket
Socket
Sign inDemoInstall

event-from

Package Overview
Dependencies
0
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.0 to 0.5.0

13

dist/event-from.cjs.development.js

@@ -5,5 +5,3 @@ 'use strict';

var detectIt = require('detect-it');
var recentEventFrom = detectIt.primaryInput;
var recentEventFrom = 'key';
var recentTouch = false;

@@ -36,6 +34,3 @@ var recentFocusFrom = recentEventFrom;

recentTouch = false;
}, // if detect-it believes the deviceType is touchOnly
// then it is highly unlikely that there is a mouse (but not impossible),
// so wait 3*delay for mouse events after touch input before attributing them to mouse input
touchDelay * (detectIt.deviceType === 'touchOnly' ? 3 : 1));
}, touchDelay);
};

@@ -99,6 +94,6 @@

var listenerOptions = detectIt.supportsPassiveEvents ? {
var listenerOptions = {
capture: true,
passive: true
} : true;
};
var documentListeners = [['touchstart', /*#__PURE__*/handleTouchEvent(750)], ['touchend', /*#__PURE__*/handleTouchEvent(300)], ['touchcancel', /*#__PURE__*/handleTouchEvent(300)], ['pointerenter', /*#__PURE__*/handlePointerEvent(300)], ['pointerover', /*#__PURE__*/handlePointerEvent(300)], ['pointerout', /*#__PURE__*/handlePointerEvent(300)], ['pointerleave', /*#__PURE__*/handlePointerEvent(300)], ['pointerdown', /*#__PURE__*/handlePointerEvent(750)], ['pointerup', /*#__PURE__*/handlePointerEvent(300)], ['pointercancel', /*#__PURE__*/handlePointerEvent(300)], ['mouseenter', handleMouseEvent], ['mouseover', handleMouseEvent], ['mouseout', handleMouseEvent], ['mouseleave', handleMouseEvent], ['mousedown', handleMouseEvent], ['mouseup', handleMouseEvent], ['keydown', handleKeyEvent], ['keyup', handleKeyEvent], ['focus', handleDocumentFocusEvent]];

@@ -105,0 +100,0 @@

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t,o=require("detect-it"),n=o.primaryInput,u=!1,c=n,i=!1,r=function(t){u=!0,n="touch",window.clearTimeout(e),e=window.setTimeout((function(){u=!1}),t*("touchOnly"===o.deviceType?3:1))},s=function(e){return function(){return r(e)}},p=function(e){return function(t){switch(t.pointerType){case"mouse":n="mouse";break;case"pen":case"touch":r(e)}}},a=function(){u||(n="mouse")},d=function(){n="key"},f=!o.supportsPassiveEvents||{capture:!0,passive:!0};"undefined"!=typeof window&&"undefined"!=typeof document&&([["touchstart",s(750)],["touchend",s(300)],["touchcancel",s(300)],["pointerenter",p(300)],["pointerover",p(300)],["pointerout",p(300)],["pointerleave",p(300)],["pointerdown",p(750)],["pointerup",p(300)],["pointercancel",p(300)],["mouseenter",a],["mouseover",a],["mouseout",a],["mouseleave",a],["mousedown",a],["mouseup",a],["keydown",d],["keyup",d],["focus",function(){i||(c=n)}]].forEach((function(e){var t=e[0],o=e[1];document.addEventListener(t,o,f)})),window.addEventListener("focus",(function(e){e.target!==window&&e.target!==document||(i=!0,window.clearTimeout(t),t=window.setTimeout((function(){i=!1}),300))}),f));exports.eventFrom=function(e){switch(e.pointerType){case"mouse":n="mouse";break;case"pen":case"touch":u?n="touch":r(300)}return/mouse/.test(e.type)&&!u&&(n="mouse"),/touch/.test(e.type)&&(u?n="touch":r(300)),/focus/.test(e.type)?c:n},exports.setEventFrom=function(e){n=e,c=e};//# sourceMappingURL=event-from.cjs.production.js.map
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t,o="key",n=!1,u=o,c=!1,i=function(t){n=!0,o="touch",window.clearTimeout(e),e=window.setTimeout((function(){n=!1}),t)},r=function(e){return function(){return i(e)}},s=function(e){return function(t){switch(t.pointerType){case"mouse":o="mouse";break;case"pen":case"touch":i(e)}}},p=function(){n||(o="mouse")},a=function(){o="key"},d={capture:!0,passive:!0};"undefined"!=typeof window&&"undefined"!=typeof document&&([["touchstart",r(750)],["touchend",r(300)],["touchcancel",r(300)],["pointerenter",s(300)],["pointerover",s(300)],["pointerout",s(300)],["pointerleave",s(300)],["pointerdown",s(750)],["pointerup",s(300)],["pointercancel",s(300)],["mouseenter",p],["mouseover",p],["mouseout",p],["mouseleave",p],["mousedown",p],["mouseup",p],["keydown",a],["keyup",a],["focus",function(){c||(u=o)}]].forEach((function(e){var t=e[0],o=e[1];document.addEventListener(t,o,d)})),window.addEventListener("focus",(function(e){e.target!==window&&e.target!==document||(c=!0,window.clearTimeout(t),t=window.setTimeout((function(){c=!1}),300))}),d));exports.eventFrom=function(e){switch(e.pointerType){case"mouse":o="mouse";break;case"pen":case"touch":n?o="touch":i(300)}return/mouse/.test(e.type)&&!n&&(o="mouse"),/touch/.test(e.type)&&(n?o="touch":i(300)),/focus/.test(e.type)?u:o},exports.setEventFrom=function(e){o=e,u=e};//# sourceMappingURL=event-from.cjs.production.js.map

@@ -1,4 +0,2 @@

import { primaryInput, deviceType, supportsPassiveEvents } from 'detect-it';
var recentEventFrom = primaryInput;
var recentEventFrom = 'key';
var recentTouch = false;

@@ -31,6 +29,3 @@ var recentFocusFrom = recentEventFrom;

recentTouch = false;
}, // if detect-it believes the deviceType is touchOnly
// then it is highly unlikely that there is a mouse (but not impossible),
// so wait 3*delay for mouse events after touch input before attributing them to mouse input
touchDelay * (deviceType === 'touchOnly' ? 3 : 1));
}, touchDelay);
};

@@ -94,6 +89,6 @@

var listenerOptions = supportsPassiveEvents ? {
var listenerOptions = {
capture: true,
passive: true
} : true;
};
var documentListeners = [['touchstart', /*#__PURE__*/handleTouchEvent(750)], ['touchend', /*#__PURE__*/handleTouchEvent(300)], ['touchcancel', /*#__PURE__*/handleTouchEvent(300)], ['pointerenter', /*#__PURE__*/handlePointerEvent(300)], ['pointerover', /*#__PURE__*/handlePointerEvent(300)], ['pointerout', /*#__PURE__*/handlePointerEvent(300)], ['pointerleave', /*#__PURE__*/handlePointerEvent(300)], ['pointerdown', /*#__PURE__*/handlePointerEvent(750)], ['pointerup', /*#__PURE__*/handlePointerEvent(300)], ['pointercancel', /*#__PURE__*/handlePointerEvent(300)], ['mouseenter', handleMouseEvent], ['mouseover', handleMouseEvent], ['mouseout', handleMouseEvent], ['mouseleave', handleMouseEvent], ['mousedown', handleMouseEvent], ['mouseup', handleMouseEvent], ['keydown', handleKeyEvent], ['keyup', handleKeyEvent], ['focus', handleDocumentFocusEvent]];

@@ -100,0 +95,0 @@

@@ -7,82 +7,3 @@ (function (global, factory) {

// so it doesn't throw if no window or matchMedia
var w = typeof window !== 'undefined' ? window : {
screen: {},
navigator: {}
};
var matchMedia = w.matchMedia || function () {
return {
matches: false
};
}; // passive events test
// adapted from https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
var passiveOptionAccessed = false;
var options = {
get passive() {
return passiveOptionAccessed = true;
}
}; // have to set and remove a no-op listener instead of null
// (which was used previously), because Edge v15 throws an error
// when providing a null callback.
// https://github.com/rafgraph/detect-passive-events/pull/3
// eslint-disable-next-line @typescript-eslint/no-empty-function
var noop = function () {};
w.addEventListener && w.addEventListener('p', noop, options);
w.removeEventListener && w.removeEventListener('p', noop, false);
var supportsPassiveEvents = passiveOptionAccessed;
var onTouchStartInWindow = ('ontouchstart' in w);
var touchEventInWindow = ('TouchEvent' in w); // onTouchStartInWindow is the old-old-legacy way to determine a touch device
// and many websites interpreted it to mean that the device is a touch only phone,
// so today browsers on a desktop/laptop computer with a touch screen (primary input mouse)
// have onTouchStartInWindow as false (to prevent from being confused with a
// touchOnly phone) even though they support the TouchEvents API, so need to check
// both onTouchStartInWindow and touchEventInWindow for TouchEvent support,
// however, some browsers (chromium) support the TouchEvents API even when running on
// a mouse only device (touchEventInWindow true, but onTouchStartInWindow false)
// so the touchEventInWindow check needs to include an coarse pointer media query
var supportsTouchEvents = onTouchStartInWindow || touchEventInWindow && /*#__PURE__*/ /*#__PURE__*/matchMedia('(any-pointer: coarse)').matches;
var hasTouch = (w.navigator.maxTouchPoints || 0) > 0 || supportsTouchEvents; // userAgent is used as a backup to correct for known device/browser bugs
// and when the browser doesn't support interaction media queries (pointer and hover)
// see https://caniuse.com/css-media-interaction
var userAgent = w.navigator.userAgent || ''; // iPads now support a mouse that can hover, however the media query interaction
// feature results always say iPads only have a coarse pointer that can't hover
// even when a mouse is connected (anyFine and anyHover are always false),
// this unfortunately indicates a touch only device but iPads should
// be classified as a hybrid device, so determine if it is an iPad
// to indicate it should be treated as a hybrid device with anyHover true
var isIPad = /*#__PURE__*/ /*#__PURE__*/matchMedia('(pointer: coarse)').matches &&
/*#__PURE__*/
// both iPad and iPhone can "request desktop site", which sets the userAgent to Macintosh
// so need to check both userAgents to determine if it is an iOS device
// and screen size to separate iPad from iPhone
/iPad|Macintosh/.test(userAgent) && /*#__PURE__*/ /*#__PURE__*/Math.min(w.screen.width || 0, w.screen.height || 0) >= 768;
var hasCoarsePrimaryPointer = ( /*#__PURE__*/ /*#__PURE__*/matchMedia('(pointer: coarse)').matches || // if the pointer is not coarse and not fine then the browser doesn't support
// interaction media queries (see https://caniuse.com/css-media-interaction)
// so if it has onTouchStartInWindow assume it has a coarse primary pointer
! /*#__PURE__*/ /*#__PURE__*/matchMedia('(pointer: fine)').matches && onTouchStartInWindow) && // bug in firefox (as of v81) on hybrid windows devices where the interaction media queries
// always indicate a touch only device (only has a coarse pointer that can't hover)
// so assume that the primary pointer is not coarse for firefox windows
! /*#__PURE__*/ /Windows.*Firefox/.test(userAgent);
var hasAnyHoverOrAnyFinePointer = /*#__PURE__*/ /*#__PURE__*/matchMedia('(any-pointer: fine)').matches || /*#__PURE__*/ /*#__PURE__*/matchMedia('(any-hover: hover)').matches || // iPads might have an input device that can hover, so assume it has anyHover
isIPad || // if no onTouchStartInWindow then the browser is indicating that it is not a touch only device
// see above note for supportsTouchEvents
!onTouchStartInWindow; // a hybrid device is one that both hasTouch and
// any input can hover or has a fine pointer, or the primary pointer is not coarse
// if it's not a hybrid, then if it hasTouch it's touchOnly, otherwise it's mouseOnly
var deviceType = hasTouch && (hasAnyHoverOrAnyFinePointer || !hasCoarsePrimaryPointer) ? 'hybrid' : hasTouch ? 'touchOnly' : 'mouseOnly';
var primaryInput = deviceType === 'mouseOnly' ? 'mouse' : deviceType === 'touchOnly' ? 'touch' : // if the device is a hybrid, then if the primary pointer is coarse
// assume the primaryInput is touch, otherwise assume it's mouse
hasCoarsePrimaryPointer ? 'touch' : 'mouse';
var recentEventFrom = primaryInput;
var recentEventFrom = 'key';
var recentTouch = false;

@@ -115,6 +36,3 @@ var recentFocusFrom = recentEventFrom;

recentTouch = false;
}, // if detect-it believes the deviceType is touchOnly
// then it is highly unlikely that there is a mouse (but not impossible),
// so wait 3*delay for mouse events after touch input before attributing them to mouse input
touchDelay * (deviceType === 'touchOnly' ? 3 : 1));
}, touchDelay);
};

@@ -178,6 +96,6 @@

var listenerOptions = supportsPassiveEvents ? {
var listenerOptions = {
capture: true,
passive: true
} : true;
};
var documentListeners = [['touchstart', /*#__PURE__*/handleTouchEvent(750)], ['touchend', /*#__PURE__*/handleTouchEvent(300)], ['touchcancel', /*#__PURE__*/handleTouchEvent(300)], ['pointerenter', /*#__PURE__*/handlePointerEvent(300)], ['pointerover', /*#__PURE__*/handlePointerEvent(300)], ['pointerout', /*#__PURE__*/handlePointerEvent(300)], ['pointerleave', /*#__PURE__*/handlePointerEvent(300)], ['pointerdown', /*#__PURE__*/handlePointerEvent(750)], ['pointerup', /*#__PURE__*/handlePointerEvent(300)], ['pointercancel', /*#__PURE__*/handlePointerEvent(300)], ['mouseenter', handleMouseEvent], ['mouseover', handleMouseEvent], ['mouseout', handleMouseEvent], ['mouseleave', handleMouseEvent], ['mousedown', handleMouseEvent], ['mouseup', handleMouseEvent], ['keydown', handleKeyEvent], ['keyup', handleKeyEvent], ['focus', handleDocumentFocusEvent]];

@@ -184,0 +102,0 @@

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).EventFrom={})}(this,(function(e){"use strict";var t="undefined"!=typeof window?window:{screen:{},navigator:{}},n=t.matchMedia||function(){return{matches:!1}},o=!1,i={get passive(){return o=!0}},u=function(){};t.addEventListener&&t.addEventListener("p",u,i),t.removeEventListener&&t.removeEventListener("p",u,!1);var c,s,r=o,a="ontouchstart"in t,d=a||"TouchEvent"in t&&n("(any-pointer: coarse)").matches,f=(t.navigator.maxTouchPoints||0)>0||d,m=t.navigator.userAgent||"",p=n("(pointer: coarse)").matches&&/iPad|Macintosh/.test(m)&&Math.min(t.screen.width||0,t.screen.height||0)>=768,h=(n("(pointer: coarse)").matches||!n("(pointer: fine)").matches&&a)&&!/Windows.*Firefox/.test(m),v=n("(any-pointer: fine)").matches||n("(any-hover: hover)").matches||p||!a,w=!f||!v&&h?f?"touchOnly":"mouseOnly":"hybrid",y="mouseOnly"===w?"mouse":"touchOnly"===w||h?"touch":"mouse",l=!1,g=y,E=!1,T=function(e){l=!0,y="touch",window.clearTimeout(c),c=window.setTimeout((function(){l=!1}),e*("touchOnly"===w?3:1))},b=function(e){return function(){return T(e)}},L=function(e){return function(t){switch(t.pointerType){case"mouse":y="mouse";break;case"pen":case"touch":T(e)}}},O=function(){l||(y="mouse")},k=function(){y="key"},x=!r||{capture:!0,passive:!0};"undefined"!=typeof window&&"undefined"!=typeof document&&([["touchstart",b(750)],["touchend",b(300)],["touchcancel",b(300)],["pointerenter",L(300)],["pointerover",L(300)],["pointerout",L(300)],["pointerleave",L(300)],["pointerdown",L(750)],["pointerup",L(300)],["pointercancel",L(300)],["mouseenter",O],["mouseover",O],["mouseout",O],["mouseleave",O],["mousedown",O],["mouseup",O],["keydown",k],["keyup",k],["focus",function(){E||(g=y)}]].forEach((function(e){var t=e[0],n=e[1];document.addEventListener(t,n,x)})),window.addEventListener("focus",(function(e){e.target!==window&&e.target!==document||(E=!0,window.clearTimeout(s),s=window.setTimeout((function(){E=!1}),300))}),x));e.eventFrom=function(e){switch(e.pointerType){case"mouse":y="mouse";break;case"pen":case"touch":l?y="touch":T(300)}return/mouse/.test(e.type)&&!l&&(y="mouse"),/touch/.test(e.type)&&(l?y="touch":T(300)),/focus/.test(e.type)?g:y},e.setEventFrom=function(e){y=e,g=e},Object.defineProperty(e,"__esModule",{value:!0})}));//# sourceMappingURL=event-from.umd.production.js.map
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).EventFrom={})}(this,(function(e){"use strict";var t,o,n="key",u=!1,i=n,c=!1,s=function(e){u=!0,n="touch",window.clearTimeout(t),t=window.setTimeout((function(){u=!1}),e)},r=function(e){return function(){return s(e)}},f=function(e){return function(t){switch(t.pointerType){case"mouse":n="mouse";break;case"pen":case"touch":s(e)}}},d=function(){u||(n="mouse")},p=function(){n="key"},a={capture:!0,passive:!0};"undefined"!=typeof window&&"undefined"!=typeof document&&([["touchstart",r(750)],["touchend",r(300)],["touchcancel",r(300)],["pointerenter",f(300)],["pointerover",f(300)],["pointerout",f(300)],["pointerleave",f(300)],["pointerdown",f(750)],["pointerup",f(300)],["pointercancel",f(300)],["mouseenter",d],["mouseover",d],["mouseout",d],["mouseleave",d],["mousedown",d],["mouseup",d],["keydown",p],["keyup",p],["focus",function(){c||(i=n)}]].forEach((function(e){var t=e[0],o=e[1];document.addEventListener(t,o,a)})),window.addEventListener("focus",(function(e){e.target!==window&&e.target!==document||(c=!0,window.clearTimeout(o),o=window.setTimeout((function(){c=!1}),300))}),a));e.eventFrom=function(e){switch(e.pointerType){case"mouse":n="mouse";break;case"pen":case"touch":u?n="touch":s(300)}return/mouse/.test(e.type)&&!u&&(n="mouse"),/touch/.test(e.type)&&(u?n="touch":s(300)),/focus/.test(e.type)?i:n},e.setEventFrom=function(e){n=e,i=e},Object.defineProperty(e,"__esModule",{value:!0})}));//# sourceMappingURL=event-from.umd.production.js.map
{
"name": "event-from",
"version": "0.4.0",
"version": "0.5.0",
"description": "Determine if an event was caused by mouse, touch or key input.",

@@ -33,5 +33,2 @@ "main": "dist/event-from.cjs.js",

"homepage": "https://event-from.rafgraph.dev",
"dependencies": {
"detect-it": "^4.0.0"
},
"devDependencies": {

@@ -38,0 +35,0 @@ "lint-staged": "^10.5.3",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc