Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

detect-it

Package Overview
Dependencies
4
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.2.0

45

lib/index.js

@@ -29,7 +29,7 @@ 'use strict';

* deviceType: 'mouseOnly' / 'touchOnly' / 'hybrid',
* touchEventsApi: boolean,
* pointerEventsApi: boolean,
* pointerEventsPrefix(value) {return value, value will only have prefix if requiresPrefix},
* hasTouchEventsApi: boolean,
* hasPointerEventsApi: boolean,
* hasTouch: boolean,
* maxTouchPoints: number,
* primaryHover: 'hover' / 'none' / 'onDemand',
* primaryHover: 'hover' / 'none',
* primaryPointer: 'fine' / 'coarse' / 'none',

@@ -43,2 +43,3 @@ * state: {

* update() {...},
* pointerEventsPrefix(value) {return value, value will only have prefix if requiresPrefix},
* }

@@ -59,8 +60,4 @@ */

/*
* A hybrid device is one that both hasTouch and any input device can either hover
* or has a fine pointer. For example, the Galaxy Note with stylus registers
* that one of it's input devices has a fine pointer (i.e. the stylus), but
* only that it can hover on-demand (which can't be used as a determinant because
* all Android touch only devices also say they can hover on-demand
* because a hover state can be activated on Android via a long press)
* A hybrid device is one that both hasTouch and any input device can hover
* or has a fine pointer.
*/

@@ -94,8 +91,26 @@ if (hasTouch && (anyHover || anyFine)) return 'hybrid';

if (typeof window !== 'undefined') {
detectIt.deviceType = determineDeviceType(detectIt.state.detectTouchEvents.hasApi || detectIt.state.detectPointerEvents.hasTouch, detectIt.state.detectHover.anyHover, detectIt.state.detectPointer.anyFine);
detectIt.touchEventsApi = detectIt.state.detectTouchEvents.hasApi;
detectIt.pointerEventsApi = detectIt.state.detectPointerEvents.hasApi;
detectIt.hasTouch = detectIt.state.detectTouchEvents.hasApi || detectIt.state.detectPointerEvents.hasTouch || false;
detectIt.deviceType = determineDeviceType(detectIt.hasTouch, detectIt.state.detectHover.anyHover, detectIt.state.detectPointer.anyFine);
detectIt.hasTouchEventsApi = detectIt.state.detectTouchEvents.hasApi;
detectIt.hasPointerEventsApi = detectIt.state.detectPointerEvents.hasApi;
detectIt.maxTouchPoints = robustMax(detectIt.state.detectTouchEvents.maxTouchPoints, detectIt.state.detectPointerEvents.maxTouchPoints);
detectIt.primaryHover = detectIt.state.detectHover.hover && 'hover' || (detectIt.state.detectHover.none || detectIt.state.detectHover.onDemand) && 'none';
detectIt.primaryPointer = detectIt.state.detectPointer.fine && 'fine' || detectIt.state.detectPointer.coarse && 'coarse' || detectIt.state.detectPointer.none && 'none';
detectIt.primaryHover = detectIt.state.detectHover.hover && 'hover' || detectIt.state.detectHover.none && 'none' ||
// if it's a mouseOnly device that doesn't support level 4 media queries,
// then assume it hovers
detectIt.deviceType === 'mouseOnly' && 'hover' ||
// if it's a touchOnly device that doesn't support level 4 media queries,
// then assume it doesn't hover, otherwise it's undefined
detectIt.deviceType === 'touchOnly' && 'none' || undefined;
detectIt.primaryPointer = detectIt.state.detectPointer.fine && 'fine' || detectIt.state.detectPointer.coarse && 'coarse' || detectIt.state.detectPointer.none && 'none' ||
// if it's a mouseOnly device that doesn't support level 4 media queries,
// then assume it has a fine pointer
detectIt.deviceType === 'mouseOnly' && 'fine' ||
// if it's a touchOnly device that doesn't support level 4 media queries,
// then assume it has a coarse pointer, otherwise it's undefined
detectIt.deviceType === 'touchOnly' && 'coarse' || undefined;
}

@@ -102,0 +117,0 @@ },

{
"name": "detect-it",
"version": "0.1.0",
"version": "0.2.0",
"description": "Detect if a device is mouse only, touch only, or hybrid",

@@ -32,3 +32,3 @@ "main": "lib/index.js",

"dependencies": {
"detect-hover": "^0.1.1",
"detect-hover": "^0.2.0",
"detect-pointer": "^0.1.1",

@@ -35,0 +35,0 @@ "detect-pointer-events": "^0.1.1",

@@ -10,7 +10,7 @@ import detectHover from 'detect-hover';

* deviceType: 'mouseOnly' / 'touchOnly' / 'hybrid',
* touchEventsApi: boolean,
* pointerEventsApi: boolean,
* pointerEventsPrefix(value) {return value, value will only have prefix if requiresPrefix},
* hasTouchEventsApi: boolean,
* hasPointerEventsApi: boolean,
* hasTouch: boolean,
* maxTouchPoints: number,
* primaryHover: 'hover' / 'none' / 'onDemand',
* primaryHover: 'hover' / 'none',
* primaryPointer: 'fine' / 'coarse' / 'none',

@@ -24,2 +24,3 @@ * state: {

* update() {...},
* pointerEventsPrefix(value) {return value, value will only have prefix if requiresPrefix},
* }

@@ -38,8 +39,4 @@ */

/*
* A hybrid device is one that both hasTouch and any input device can either hover
* or has a fine pointer. For example, the Galaxy Note with stylus registers
* that one of it's input devices has a fine pointer (i.e. the stylus), but
* only that it can hover on-demand (which can't be used as a determinant because
* all Android touch only devices also say they can hover on-demand
* because a hover state can be activated on Android via a long press)
* A hybrid device is one that both hasTouch and any input device can hover
* or has a fine pointer.
*/

@@ -73,9 +70,16 @@ if (hasTouch && (anyHover || anyFine)) return 'hybrid';

if (typeof window !== 'undefined') {
detectIt.hasTouch =
detectIt.state.detectTouchEvents.hasApi ||
detectIt.state.detectPointerEvents.hasTouch ||
false;
detectIt.deviceType = determineDeviceType(
(detectIt.state.detectTouchEvents.hasApi || detectIt.state.detectPointerEvents.hasTouch),
detectIt.hasTouch,
detectIt.state.detectHover.anyHover,
detectIt.state.detectPointer.anyFine
);
detectIt.touchEventsApi = detectIt.state.detectTouchEvents.hasApi;
detectIt.pointerEventsApi = detectIt.state.detectPointerEvents.hasApi;
detectIt.hasTouchEventsApi = detectIt.state.detectTouchEvents.hasApi;
detectIt.hasPointerEventsApi = detectIt.state.detectPointerEvents.hasApi;
detectIt.maxTouchPoints = robustMax(

@@ -85,9 +89,23 @@ detectIt.state.detectTouchEvents.maxTouchPoints,

);
detectIt.primaryHover =
(detectIt.state.detectHover.hover && 'hover') ||
((detectIt.state.detectHover.none || detectIt.state.detectHover.onDemand) && 'none');
(detectIt.state.detectHover.none && 'none') ||
// if it's a mouseOnly device that doesn't support level 4 media queries,
// then assume it hovers
(detectIt.deviceType === 'mouseOnly' && 'hover') ||
// if it's a touchOnly device that doesn't support level 4 media queries,
// then assume it doesn't hover, otherwise it's undefined
(detectIt.deviceType === 'touchOnly' && 'none') || undefined;
detectIt.primaryPointer =
(detectIt.state.detectPointer.fine && 'fine') ||
(detectIt.state.detectPointer.coarse && 'coarse') ||
(detectIt.state.detectPointer.none && 'none');
(detectIt.state.detectPointer.none && 'none') ||
// if it's a mouseOnly device that doesn't support level 4 media queries,
// then assume it has a fine pointer
(detectIt.deviceType === 'mouseOnly' && 'fine') ||
// if it's a touchOnly device that doesn't support level 4 media queries,
// then assume it has a coarse pointer, otherwise it's undefined
(detectIt.deviceType === 'touchOnly' && 'coarse') || undefined;
}

@@ -94,0 +112,0 @@ },

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