what-input 5.2.9 → 5.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 Jeremy Fields
3
+ Copyright (c) 2021 Jeremy Fields
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -221,9 +221,17 @@ _What Input_ works in all modern browsers.
221
221
 
222
222
  ## Changelog
223
223
 
224
- ### v5.2.8 - 5.2.9
224
+ ### v5.2.12
225
225
 
226
- - **Added:** TypeScript definitions via @greypants
226
+ - **Fixed:** Improved detection and respect for of `data-whatpersist` before `DOMContentLoaded`. Fix via [FanFataL](https://github.com/FanFataL).
227
+
228
+ ### v5.2.11
229
+
230
+ - **Fixed:** Adds `useCapture` so events can be detected before `preventDefault` cancels them on local listeners (h/t [jojo080889](https://github.com/jojo080889)).
231
+
232
+ ### v5.2.8 - 5.2.10
233
+
234
+ - **Added:** TypeScript definitions via [greypants](https://github.com/greypants).
227
235
 
228
236
  ### v5.2.7
229
237
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * what-input - A global utility for tracking the current input method (mouse, keyboard or touch).
3
- * @version v5.2.9
3
+ * @version v5.2.12
4
4
  * @link https://github.com/ten1seven/what-input
5
5
  * @license MIT
6
6
  */
@@ -115,7 +115,7 @@ return /******/ (function(modules) { // webpackBootstrap
115
115
  var currentTimestamp = Date.now();
116
116
 
117
117
  // check for a `data-whatpersist` attribute on either the `html` or `body` elements, defaults to `true`
118
- var shouldPersist = 'false';
118
+ var shouldPersist = false;
119
119
 
120
120
  // form input types
121
121
  var formInputs = ['button', 'input', 'select', 'textarea'];
@@ -195,26 +195,26 @@ return /******/ (function(modules) { // webpackBootstrap
195
195
  // `pointermove`, `MSPointerMove`, `mousemove` and mouse wheel event binding
196
196
  // can only demonstrate potential, but not actual, interaction
197
197
  // and are treated separately
198
- var options = supportsPassive ? { passive: true } : false;
198
+ var options = supportsPassive ? { passive: true, capture: true } : true;
199
199
 
200
- document.addEventListener('DOMContentLoaded', setPersist);
200
+ document.addEventListener('DOMContentLoaded', setPersist, true);
201
201
 
202
202
  // pointer events (mouse, pen, touch)
203
203
  if (window.PointerEvent) {
204
- window.addEventListener('pointerdown', setInput);
205
- window.addEventListener('pointermove', setIntent);
204
+ window.addEventListener('pointerdown', setInput, true);
205
+ window.addEventListener('pointermove', setIntent, true);
206
206
  } else if (window.MSPointerEvent) {
207
- window.addEventListener('MSPointerDown', setInput);
208
- window.addEventListener('MSPointerMove', setIntent);
207
+ window.addEventListener('MSPointerDown', setInput, true);
208
+ window.addEventListener('MSPointerMove', setIntent, true);
209
209
  } else {
210
210
  // mouse events
211
- window.addEventListener('mousedown', setInput);
212
- window.addEventListener('mousemove', setIntent);
211
+ window.addEventListener('mousedown', setInput, true);
212
+ window.addEventListener('mousemove', setIntent, true);
213
213
 
214
214
  // touch events
215
215
  if ('ontouchstart' in window) {
216
216
  window.addEventListener('touchstart', setInput, options);
217
- window.addEventListener('touchend', setInput);
217
+ window.addEventListener('touchend', setInput, true);
218
218
  }
219
219
  }
220
220
 
@@ -222,18 +222,18 @@ return /******/ (function(modules) { // webpackBootstrap
222
222
  window.addEventListener(detectWheel(), setIntent, options);
223
223
 
224
224
  // keyboard events
225
- window.addEventListener('keydown', setInput);
226
- window.addEventListener('keyup', setInput);
225
+ window.addEventListener('keydown', setInput, true);
226
+ window.addEventListener('keyup', setInput, true);
227
227
 
228
228
  // focus events
229
- window.addEventListener('focusin', setElement);
230
- window.addEventListener('focusout', clearElement);
229
+ window.addEventListener('focusin', setElement, true);
230
+ window.addEventListener('focusout', clearElement, true);
231
231
  };
232
232
 
233
233
  // checks if input persistence should happen and
234
234
  // get saved state from session storage if true (defaults to `false`)
235
235
  var setPersist = function setPersist() {
236
- shouldPersist = !(docElem.getAttribute('data-whatpersist') || document.body.getAttribute('data-whatpersist') === 'false');
236
+ shouldPersist = !(docElem.getAttribute('data-whatpersist') === 'false' || document.body.getAttribute('data-whatpersist') === 'false');
237
237
 
238
238
  if (shouldPersist) {
239
239
  // check for session variables and use if available
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * what-input - A global utility for tracking the current input method (mouse, keyboard or touch).
3
- * @version v5.2.9
3
+ * @version v5.2.12
4
4
  * @link https://github.com/ten1seven/what-input
5
5
  * @license MIT
6
6
  */
7
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("whatInput",[],t):"object"==typeof exports?exports.whatInput=t():e.whatInput=t()}(this,function(){return i={},n.m=o=[function(e,t){"use strict";e.exports=function(){if("undefined"==typeof document||"undefined"==typeof window)return{ask:function(){return"initial"},element:function(){return null},ignoreKeys:function(){},specificKeys:function(){},registerOnChange:function(){},unRegisterOnChange:function(){}};var t=document.documentElement,n=null,s="initial",u=s,o=Date.now(),i="false",d=["button","input","select","textarea"],r=[],c=[16,17,18,91,93],w=[],p={keydown:"keyboard",keyup:"keyboard",mousedown:"mouse",mousemove:"mouse",MSPointerDown:"pointer",MSPointerMove:"pointer",pointerdown:"pointer",pointermove:"pointer",touchstart:"touch",touchend:"touch"},a=!1,f={x:null,y:null},l={2:"touch",3:"touch",4:"mouse"},m=!1;try{var e=Object.defineProperty({},"passive",{get:function(){m=!0}});window.addEventListener("test",null,e)}catch(e){}var h=function(){var e=!!m&&{passive:!0};document.addEventListener("DOMContentLoaded",v),window.PointerEvent?(window.addEventListener("pointerdown",y),window.addEventListener("pointermove",E)):window.MSPointerEvent?(window.addEventListener("MSPointerDown",y),window.addEventListener("MSPointerMove",E)):(window.addEventListener("mousedown",y),window.addEventListener("mousemove",E),"ontouchstart"in window&&(window.addEventListener("touchstart",y,e),window.addEventListener("touchend",y))),window.addEventListener(O(),E,e),window.addEventListener("keydown",y),window.addEventListener("keyup",y),window.addEventListener("focusin",L),window.addEventListener("focusout",b)},v=function(){if(i=!(t.getAttribute("data-whatpersist")||"false"===document.body.getAttribute("data-whatpersist")))try{window.sessionStorage.getItem("what-input")&&(s=window.sessionStorage.getItem("what-input")),window.sessionStorage.getItem("what-intent")&&(u=window.sessionStorage.getItem("what-intent"))}catch(e){}g("input"),g("intent")},y=function(e){var t=e.which,n=p[e.type];"pointer"===n&&(n=S(e));var o=!w.length&&-1===c.indexOf(t),i=w.length&&-1!==w.indexOf(t),r="keyboard"===n&&t&&(o||i)||"mouse"===n||"touch"===n;if(M(n)&&(r=!1),r&&s!==n&&(x("input",s=n),g("input")),r&&u!==n){var a=document.activeElement;a&&a.nodeName&&(-1===d.indexOf(a.nodeName.toLowerCase())||"button"===a.nodeName.toLowerCase()&&!C(a,"form"))&&(x("intent",u=n),g("intent"))}},g=function(e){t.setAttribute("data-what"+e,"input"===e?s:u),k(e)},E=function(e){var t=p[e.type];"pointer"===t&&(t=S(e)),A(e),(!a&&!M(t)||a&&"wheel"===e.type||"mousewheel"===e.type||"DOMMouseScroll"===e.type)&&u!==t&&(x("intent",u=t),g("intent"))},L=function(e){e.target.nodeName?(n=e.target.nodeName.toLowerCase(),t.setAttribute("data-whatelement",n),e.target.classList&&e.target.classList.length&&t.setAttribute("data-whatclasses",e.target.classList.toString().replace(" ",","))):b()},b=function(){n=null,t.removeAttribute("data-whatelement"),t.removeAttribute("data-whatclasses")},x=function(e,t){if(i)try{window.sessionStorage.setItem("what-"+e,t)}catch(e){}},S=function(e){return"number"==typeof e.pointerType?l[e.pointerType]:"pen"===e.pointerType?"touch":e.pointerType},M=function(e){var t=Date.now(),n="mouse"===e&&"touch"===s&&t-o<200;return o=t,n},O=function(){return"onwheel"in document.createElement("div")?"wheel":void 0!==document.onmousewheel?"mousewheel":"DOMMouseScroll"},k=function(e){for(var t=0,n=r.length;t<n;t++)r[t].type===e&&r[t].fn.call(void 0,"input"===e?s:u)},A=function(e){f.x!==e.screenX||f.y!==e.screenY?(a=!1,f.x=e.screenX,f.y=e.screenY):a=!0},C=function(e,t){var n=window.Element.prototype;if(n.matches||(n.matches=n.msMatchesSelector||n.webkitMatchesSelector),n.closest)return e.closest(t);do{if(e.matches(t))return e;e=e.parentElement||e.parentNode}while(null!==e&&1===e.nodeType);return null};return"addEventListener"in window&&Array.prototype.indexOf&&(p[O()]="mouse",h()),{ask:function(e){return"intent"===e?u:s},element:function(){return n},ignoreKeys:function(e){c=e},specificKeys:function(e){w=e},registerOnChange:function(e,t){r.push({fn:e,type:t||"input"})},unRegisterOnChange:function(e){var t=function(e){for(var t=0,n=r.length;t<n;t++)if(r[t].fn===e)return t}(e);!t&&0!==t||r.splice(t,1)},clearStorage:function(){window.sessionStorage.clear()}}}()}],n.c=i,n.p="",n(0);function n(e){if(i[e])return i[e].exports;var t=i[e]={exports:{},id:e,loaded:!1};return o[e].call(t.exports,t,t.exports,n),t.loaded=!0,t.exports}var o,i});
7
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("whatInput",[],t):"object"==typeof exports?exports.whatInput=t():e.whatInput=t()}(this,function(){return i={},n.m=o=[function(e,t){"use strict";e.exports=function(){if("undefined"==typeof document||"undefined"==typeof window)return{ask:function(){return"initial"},element:function(){return null},ignoreKeys:function(){},specificKeys:function(){},registerOnChange:function(){},unRegisterOnChange:function(){}};var t=document.documentElement,n=null,u="initial",s=u,o=Date.now(),i=!1,d=["button","input","select","textarea"],r=[],c=[16,17,18,91,93],w=[],p={keydown:"keyboard",keyup:"keyboard",mousedown:"mouse",mousemove:"mouse",MSPointerDown:"pointer",MSPointerMove:"pointer",pointerdown:"pointer",pointermove:"pointer",touchstart:"touch",touchend:"touch"},a=!1,f={x:null,y:null},l={2:"touch",3:"touch",4:"mouse"},m=!1;try{var e=Object.defineProperty({},"passive",{get:function(){m=!0}});window.addEventListener("test",null,e)}catch(e){}var h=function(){var e=!m||{passive:!0,capture:!0};document.addEventListener("DOMContentLoaded",v,!0),window.PointerEvent?(window.addEventListener("pointerdown",y,!0),window.addEventListener("pointermove",E,!0)):window.MSPointerEvent?(window.addEventListener("MSPointerDown",y,!0),window.addEventListener("MSPointerMove",E,!0)):(window.addEventListener("mousedown",y,!0),window.addEventListener("mousemove",E,!0),"ontouchstart"in window&&(window.addEventListener("touchstart",y,e),window.addEventListener("touchend",y,!0))),window.addEventListener(O(),E,e),window.addEventListener("keydown",y,!0),window.addEventListener("keyup",y,!0),window.addEventListener("focusin",L,!0),window.addEventListener("focusout",b,!0)},v=function(){if(i=!("false"===t.getAttribute("data-whatpersist")||"false"===document.body.getAttribute("data-whatpersist")))try{window.sessionStorage.getItem("what-input")&&(u=window.sessionStorage.getItem("what-input")),window.sessionStorage.getItem("what-intent")&&(s=window.sessionStorage.getItem("what-intent"))}catch(e){}g("input"),g("intent")},y=function(e){var t=e.which,n=p[e.type];"pointer"===n&&(n=S(e));var o=!w.length&&-1===c.indexOf(t),i=w.length&&-1!==w.indexOf(t),r="keyboard"===n&&t&&(o||i)||"mouse"===n||"touch"===n;if(M(n)&&(r=!1),r&&u!==n&&(x("input",u=n),g("input")),r&&s!==n){var a=document.activeElement;a&&a.nodeName&&(-1===d.indexOf(a.nodeName.toLowerCase())||"button"===a.nodeName.toLowerCase()&&!C(a,"form"))&&(x("intent",s=n),g("intent"))}},g=function(e){t.setAttribute("data-what"+e,"input"===e?u:s),k(e)},E=function(e){var t=p[e.type];"pointer"===t&&(t=S(e)),A(e),(!a&&!M(t)||a&&"wheel"===e.type||"mousewheel"===e.type||"DOMMouseScroll"===e.type)&&s!==t&&(x("intent",s=t),g("intent"))},L=function(e){e.target.nodeName?(n=e.target.nodeName.toLowerCase(),t.setAttribute("data-whatelement",n),e.target.classList&&e.target.classList.length&&t.setAttribute("data-whatclasses",e.target.classList.toString().replace(" ",","))):b()},b=function(){n=null,t.removeAttribute("data-whatelement"),t.removeAttribute("data-whatclasses")},x=function(e,t){if(i)try{window.sessionStorage.setItem("what-"+e,t)}catch(e){}},S=function(e){return"number"==typeof e.pointerType?l[e.pointerType]:"pen"===e.pointerType?"touch":e.pointerType},M=function(e){var t=Date.now(),n="mouse"===e&&"touch"===u&&t-o<200;return o=t,n},O=function(){return"onwheel"in document.createElement("div")?"wheel":void 0!==document.onmousewheel?"mousewheel":"DOMMouseScroll"},k=function(e){for(var t=0,n=r.length;t<n;t++)r[t].type===e&&r[t].fn.call(void 0,"input"===e?u:s)},A=function(e){f.x!==e.screenX||f.y!==e.screenY?(a=!1,f.x=e.screenX,f.y=e.screenY):a=!0},C=function(e,t){var n=window.Element.prototype;if(n.matches||(n.matches=n.msMatchesSelector||n.webkitMatchesSelector),n.closest)return e.closest(t);do{if(e.matches(t))return e;e=e.parentElement||e.parentNode}while(null!==e&&1===e.nodeType);return null};return"addEventListener"in window&&Array.prototype.indexOf&&(p[O()]="mouse",h()),{ask:function(e){return"intent"===e?s:u},element:function(){return n},ignoreKeys:function(e){c=e},specificKeys:function(e){w=e},registerOnChange:function(e,t){r.push({fn:e,type:t||"input"})},unRegisterOnChange:function(e){var t=function(e){for(var t=0,n=r.length;t<n;t++)if(r[t].fn===e)return t}(e);!t&&0!==t||r.splice(t,1)},clearStorage:function(){window.sessionStorage.clear()}}}()}],n.c=i,n.p="",n(0);function n(e){if(i[e])return i[e].exports;var t=i[e]={exports:{},id:e,loaded:!1};return o[e].call(t.exports,t,t.exports,n),t.loaded=!0,t.exports}var o,i});
8
8
  //# sourceMappingURL=what-input.min.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["what-input.js"],"names":["root","factory","exports","module","define","amd","this","installedModules","__webpack_require__","m","modules","document","window","ask","element","ignoreKeys","specificKeys","registerOnChange","unRegisterOnChange","docElem","documentElement","currentElement","currentInput","currentIntent","currentTimestamp","Date","now","shouldPersist","formInputs","functionList","ignoreMap","specificMap","inputMap","keydown","keyup","mousedown","mousemove","MSPointerDown","MSPointerMove","pointerdown","pointermove","touchstart","touchend","isScrolling","mousePos","x","y","pointerMap","2","3","4","supportsPassive","opts","Object","defineProperty","get","addEventListener","e","addListeners","options","passive","setPersist","PointerEvent","setInput","setIntent","MSPointerEvent","detectWheel","setElement","clearElement","getAttribute","body","sessionStorage","getItem","doUpdate","event","eventKey","which","value","type","pointerType","ignoreMatch","length","indexOf","specificMatch","shouldUpdate","validateTouch","persistInput","activeElem","activeElement","nodeName","toLowerCase","checkClosest","setAttribute","fireFunctions","detectScrolling","target","classList","toString","replace","removeAttribute","setItem","timestamp","touchIsValid","createElement","undefined","onmousewheel","i","len","fn","call","screenX","screenY","elem","tag","ElementPrototype","Element","prototype","matches","msMatchesSelector","webkitMatchesSelector","closest","parentElement","parentNode","nodeType","Array","opt","arr","eventType","push","position","match","objPos","splice","clearStorage","clear","c","p","moduleId","id","loaded"],"mappings":";;;;;;CAAA,SAAAA,EAAAC,GACA,iBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,IACA,mBAAAG,QAAAA,OAAAC,IACAD,OAAA,YAAA,GAAAH,GACA,iBAAAC,QALAA,QAAA,UAAAD,IAEAD,EAAA,UAAAC,IAFA,CAGAK,KAAA,WACA,OAEAC,EAAA,GA4BAC,EAAAC,EA9BAC,EA0CA,CAEA,SAAAP,EAAAD,GAEA,aAEAC,EAAAD,QAAA,WAOA,GAAA,oBAAAS,UAAA,oBAAAC,OACA,MAAA,CAEAC,IAAA,WACA,MAAA,WAIAC,QAAA,WACA,OAAA,MAIAC,WAAA,aAGAC,aAAA,aAGAC,iBAAA,aAGAC,mBAAA,cASA,IAAAC,EAAAR,SAAAS,gBAGAC,EAAA,KAGAC,EAAA,UAGAC,EAAAD,EAGAE,EAAAC,KAAAC,MAGAC,EAAA,QAGAC,EAAA,CAAA,SAAA,QAAA,SAAA,YAGAC,EAAA,GAIAC,EAAA,CAAA,GACA,GACA,GACA,GACA,IAGAC,EAAA,GAGAC,EAAA,CACAC,QAAA,WACAC,MAAA,WACAC,UAAA,QACAC,UAAA,QACAC,cAAA,UACAC,cAAA,UACAC,YAAA,UACAC,YAAA,UACAC,WAAA,Q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AIA9G,aAAA,SAAA8G,GACA/F,EAAA+F,GAMA7G,iBAAA,SAAA2F,EAAAmB,GACAlG,EAAAmG,KAAA,CACApB,GAAAA,EACA9B,KAAAiD,GAAA,WAIA7G,mBAAA,SAAA0F,GACA,IAAAqB,EA3FA,SAAAC,GACA,IAAA,IAAAxB,EAAA,EAAAC,EAAA9E,EAAAoD,OAAAyB,EAAAC,EAAAD,IACA,GAAA7E,EAAA6E,GAAAE,KAAAsB,EACA,OAAAxB,EAwFAyB,CAAAvB,IAEAqB,GAAA,IAAAA,GACApG,EAAAuG,OAAAH,EAAA,IAIAI,aAAA,WACAzH,OAAA2D,eAAA+D,UA5bA,KAfA9H,EAAA+H,EAAAhI,EAGAC,EAAAgI,EAAA,GAGAhI,EAAA,GAlCA,SAAAA,EAAAiI,GAGA,GAAAlI,EAAAkI,GACA,OAAAlI,EAAAkI,GAAAvI,QAGA,IAAAC,EAAAI,EAAAkI,GAAA,CACAvI,QAAA,GACAwI,GAAAD,EACAE,QAAA,GAUA,OANAjI,EAAA+H,GAAA5B,KAAA1G,EAAAD,QAAAC,EAAAA,EAAAD,QAAAM,GAGAL,EAAAwI,QAAA,EAGAxI,EAAAD,QAzBA,IAAAQ,EAEAH","file":"what-input.min.js","sourcesContent":["/**\n * what-input - A global utility for tracking the current input method (mouse, keyboard or touch).\n * @version v5.2.9\n * @link https://github.com/ten1seven/what-input\n * @license MIT\n */\n(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"whatInput\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"whatInput\"] = factory();\n\telse\n\t\troot[\"whatInput\"] = factory();\n})(this, function() {\nreturn /******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n\n\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ (function(module, exports) {\n\n\t'use strict';\n\n\tmodule.exports = function () {\n\t /*\n\t * bail out if there is no document or window\n\t * (i.e. in a node/non-DOM environment)\n\t *\n\t * Return a stubbed API instead\n\t */\n\t if (typeof document === 'undefined' || typeof window === 'undefined') {\n\t return {\n\t // always return \"initial\" because no interaction will ever be detected\n\t ask: function ask() {\n\t return 'initial';\n\t },\n\n\t // always return null\n\t element: function element() {\n\t return null;\n\t },\n\n\t // no-op\n\t ignoreKeys: function ignoreKeys() {},\n\n\t // no-op\n\t specificKeys: function specificKeys() {},\n\n\t // no-op\n\t registerOnChange: function registerOnChange() {},\n\n\t // no-op\n\t unRegisterOnChange: function unRegisterOnChange() {}\n\t };\n\t }\n\n\t /*\n\t * variables\n\t */\n\n\t // cache document.documentElement\n\t var docElem = document.documentElement;\n\n\t // currently focused dom element\n\t var currentElement = null;\n\n\t // last used input type\n\t var currentInput = 'initial';\n\n\t // last used input intent\n\t var currentIntent = currentInput;\n\n\t // UNIX timestamp of current event\n\t var currentTimestamp = Date.now();\n\n\t // check for a `data-whatpersist` attribute on either the `html` or `body` elements, defaults to `true`\n\t var shouldPersist = 'false';\n\n\t // form input types\n\t var formInputs = ['button', 'input', 'select', 'textarea'];\n\n\t // empty array for holding callback functions\n\t var functionList = [];\n\n\t // list of modifier keys commonly used with the mouse and\n\t // can be safely ignored to prevent false keyboard detection\n\t var ignoreMap = [16, // shift\n\t 17, // control\n\t 18, // alt\n\t 91, // Windows key / left Apple cmd\n\t 93 // Windows menu / right Apple cmd\n\t ];\n\n\t var specificMap = [];\n\n\t // mapping of events to input types\n\t var inputMap = {\n\t keydown: 'keyboard',\n\t keyup: 'keyboard',\n\t mousedown: 'mouse',\n\t mousemove: 'mouse',\n\t MSPointerDown: 'pointer',\n\t MSPointerMove: 'pointer',\n\t pointerdown: 'pointer',\n\t pointermove: 'pointer',\n\t touchstart: 'touch',\n\t touchend: 'touch'\n\n\t // boolean: true if the page is being scrolled\n\t };var isScrolling = false;\n\n\t // store current mouse position\n\t var mousePos = {\n\t x: null,\n\t y: null\n\n\t // map of IE 10 pointer events\n\t };var pointerMap = {\n\t 2: 'touch',\n\t 3: 'touch', // treat pen like touch\n\t 4: 'mouse'\n\n\t // check support for passive event listeners\n\t };var supportsPassive = false;\n\n\t try {\n\t var opts = Object.defineProperty({}, 'passive', {\n\t get: function get() {\n\t supportsPassive = true;\n\t }\n\t });\n\n\t window.addEventListener('test', null, opts);\n\t } catch (e) {}\n\t // fail silently\n\n\n\t /*\n\t * set up\n\t */\n\n\t var setUp = function setUp() {\n\t // add correct mouse wheel event mapping to `inputMap`\n\t inputMap[detectWheel()] = 'mouse';\n\n\t addListeners();\n\t };\n\n\t /*\n\t * events\n\t */\n\n\t var addListeners = function addListeners() {\n\t // `pointermove`, `MSPointerMove`, `mousemove` and mouse wheel event binding\n\t // can only demonstrate potential, but not actual, interaction\n\t // and are treated separately\n\t var options = supportsPassive ? { passive: true } : false;\n\n\t document.addEventListener('DOMContentLoaded', setPersist);\n\n\t // pointer events (mouse, pen, touch)\n\t if (window.PointerEvent) {\n\t window.addEventListener('pointerdown', setInput);\n\t window.addEventListener('pointermove', setIntent);\n\t } else if (window.MSPointerEvent) {\n\t window.addEventListener('MSPointerDown', setInput);\n\t window.addEventListener('MSPointerMove', setIntent);\n\t } else {\n\t // mouse events\n\t window.addEventListener('mousedown', setInput);\n\t window.addEventListener('mousemove', setIntent);\n\n\t // touch events\n\t if ('ontouchstart' in window) {\n\t window.addEventListener('touchstart', setInput, options);\n\t window.addEventListener('touchend', setInput);\n\t }\n\t }\n\n\t // mouse wheel\n\t window.addEventListener(detectWheel(), setIntent, options);\n\n\t // keyboard events\n\t window.addEventListener('keydown', setInput);\n\t window.addEventListener('keyup', setInput);\n\n\t // focus events\n\t window.addEventListener('focusin', setElement);\n\t window.addEventListener('focusout', clearElement);\n\t };\n\n\t // checks if input persistence should happen and\n\t // get saved state from session storage if true (defaults to `false`)\n\t var setPersist = function setPersist() {\n\t shouldPersist = !(docElem.getAttribute('data-whatpersist') || document.body.getAttribute('data-whatpersist') === 'false');\n\n\t if (shouldPersist) {\n\t // check for session variables and use if available\n\t try {\n\t if (window.sessionStorage.getItem('what-input')) {\n\t currentInput = window.sessionStorage.getItem('what-input');\n\t }\n\n\t if (window.sessionStorage.getItem('what-intent')) {\n\t currentIntent = window.sessionStorage.getItem('what-intent');\n\t }\n\t } catch (e) {\n\t // fail silently\n\t }\n\t }\n\n\t // always run these so at least `initial` state is set\n\t doUpdate('input');\n\t doUpdate('intent');\n\t };\n\n\t // checks conditions before updating new input\n\t var setInput = function setInput(event) {\n\t var eventKey = event.which;\n\t var value = inputMap[event.type];\n\n\t if (value === 'pointer') {\n\t value = pointerType(event);\n\t }\n\n\t var ignoreMatch = !specificMap.length && ignoreMap.indexOf(eventKey) === -1;\n\n\t var specificMatch = specificMap.length && specificMap.indexOf(eventKey) !== -1;\n\n\t var shouldUpdate = value === 'keyboard' && eventKey && (ignoreMatch || specificMatch) || value === 'mouse' || value === 'touch';\n\n\t // prevent touch detection from being overridden by event execution order\n\t if (validateTouch(value)) {\n\t shouldUpdate = false;\n\t }\n\n\t if (shouldUpdate && currentInput !== value) {\n\t currentInput = value;\n\n\t persistInput('input', currentInput);\n\t doUpdate('input');\n\t }\n\n\t if (shouldUpdate && currentIntent !== value) {\n\t // preserve intent for keyboard interaction with form fields\n\t var activeElem = document.activeElement;\n\t var notFormInput = activeElem && activeElem.nodeName && (formInputs.indexOf(activeElem.nodeName.toLowerCase()) === -1 || activeElem.nodeName.toLowerCase() === 'button' && !checkClosest(activeElem, 'form'));\n\n\t if (notFormInput) {\n\t currentIntent = value;\n\n\t persistInput('intent', currentIntent);\n\t doUpdate('intent');\n\t }\n\t }\n\t };\n\n\t // updates the doc and `inputTypes` array with new input\n\t var doUpdate = function doUpdate(which) {\n\t docElem.setAttribute('data-what' + which, which === 'input' ? currentInput : currentIntent);\n\n\t fireFunctions(which);\n\t };\n\n\t // updates input intent for `mousemove` and `pointermove`\n\t var setIntent = function setIntent(event) {\n\t var value = inputMap[event.type];\n\n\t if (value === 'pointer') {\n\t value = pointerType(event);\n\t }\n\n\t // test to see if `mousemove` happened relative to the screen to detect scrolling versus mousemove\n\t detectScrolling(event);\n\n\t // only execute if scrolling isn't happening\n\t if ((!isScrolling && !validateTouch(value) || isScrolling && event.type === 'wheel' || event.type === 'mousewheel' || event.type === 'DOMMouseScroll') && currentIntent !== value) {\n\t currentIntent = value;\n\n\t persistInput('intent', currentIntent);\n\t doUpdate('intent');\n\t }\n\t };\n\n\t var setElement = function setElement(event) {\n\t if (!event.target.nodeName) {\n\t // If nodeName is undefined, clear the element\n\t // This can happen if click inside an <svg> element.\n\t clearElement();\n\t return;\n\t }\n\n\t currentElement = event.target.nodeName.toLowerCase();\n\t docElem.setAttribute('data-whatelement', currentElement);\n\n\t if (event.target.classList && event.target.classList.length) {\n\t docElem.setAttribute('data-whatclasses', event.target.classList.toString().replace(' ', ','));\n\t }\n\t };\n\n\t var clearElement = function clearElement() {\n\t currentElement = null;\n\n\t docElem.removeAttribute('data-whatelement');\n\t docElem.removeAttribute('data-whatclasses');\n\t };\n\n\t var persistInput = function persistInput(which, value) {\n\t if (shouldPersist) {\n\t try {\n\t window.sessionStorage.setItem('what-' + which, value);\n\t } catch (e) {\n\t // fail silently\n\t }\n\t }\n\t };\n\n\t /*\n\t * utilities\n\t */\n\n\t var pointerType = function pointerType(event) {\n\t if (typeof event.pointerType === 'number') {\n\t return pointerMap[event.pointerType];\n\t } else {\n\t // treat pen like touch\n\t return event.pointerType === 'pen' ? 'touch' : event.pointerType;\n\t }\n\t };\n\n\t // prevent touch detection from being overridden by event execution order\n\t var validateTouch = function validateTouch(value) {\n\t var timestamp = Date.now();\n\n\t var touchIsValid = value === 'mouse' && currentInput === 'touch' && timestamp - currentTimestamp < 200;\n\n\t currentTimestamp = timestamp;\n\n\t return touchIsValid;\n\t };\n\n\t // detect version of mouse wheel event to use\n\t // via https://developer.mozilla.org/en-US/docs/Web/API/Element/wheel_event\n\t var detectWheel = function detectWheel() {\n\t var wheelType = null;\n\n\t // Modern browsers support \"wheel\"\n\t if ('onwheel' in document.createElement('div')) {\n\t wheelType = 'wheel';\n\t } else {\n\t // Webkit and IE support at least \"mousewheel\"\n\t // or assume that remaining browsers are older Firefox\n\t wheelType = document.onmousewheel !== undefined ? 'mousewheel' : 'DOMMouseScroll';\n\t }\n\n\t return wheelType;\n\t };\n\n\t // runs callback functions\n\t var fireFunctions = function fireFunctions(type) {\n\t for (var i = 0, len = functionList.length; i < len; i++) {\n\t if (functionList[i].type === type) {\n\t functionList[i].fn.call(undefined, type === 'input' ? currentInput : currentIntent);\n\t }\n\t }\n\t };\n\n\t // finds matching element in an object\n\t var objPos = function objPos(match) {\n\t for (var i = 0, len = functionList.length; i < len; i++) {\n\t if (functionList[i].fn === match) {\n\t return i;\n\t }\n\t }\n\t };\n\n\t var detectScrolling = function detectScrolling(event) {\n\t if (mousePos.x !== event.screenX || mousePos.y !== event.screenY) {\n\t isScrolling = false;\n\n\t mousePos.x = event.screenX;\n\t mousePos.y = event.screenY;\n\t } else {\n\t isScrolling = true;\n\t }\n\t };\n\n\t // manual version of `closest()`\n\t var checkClosest = function checkClosest(elem, tag) {\n\t var ElementPrototype = window.Element.prototype;\n\n\t if (!ElementPrototype.matches) {\n\t ElementPrototype.matches = ElementPrototype.msMatchesSelector || ElementPrototype.webkitMatchesSelector;\n\t }\n\n\t if (!ElementPrototype.closest) {\n\t do {\n\t if (elem.matches(tag)) {\n\t return elem;\n\t }\n\n\t elem = elem.parentElement || elem.parentNode;\n\t } while (elem !== null && elem.nodeType === 1);\n\n\t return null;\n\t } else {\n\t return elem.closest(tag);\n\t }\n\t };\n\n\t /*\n\t * init\n\t */\n\n\t // don't start script unless browser cuts the mustard\n\t // (also passes if polyfills are used)\n\t if ('addEventListener' in window && Array.prototype.indexOf) {\n\t setUp();\n\t }\n\n\t /*\n\t * api\n\t */\n\n\t return {\n\t // returns string: the current input type\n\t // opt: 'intent'|'input'\n\t // 'input' (default): returns the same value as the `data-whatinput` attribute\n\t // 'intent': includes `data-whatintent` value if it's different than `data-whatinput`\n\t ask: function ask(opt) {\n\t return opt === 'intent' ? currentIntent : currentInput;\n\t },\n\n\t // returns string: the currently focused element or null\n\t element: function element() {\n\t return currentElement;\n\t },\n\n\t // overwrites ignored keys with provided array\n\t ignoreKeys: function ignoreKeys(arr) {\n\t ignoreMap = arr;\n\t },\n\n\t // overwrites specific char keys to update on\n\t specificKeys: function specificKeys(arr) {\n\t specificMap = arr;\n\t },\n\n\t // attach functions to input and intent \"events\"\n\t // funct: function to fire on change\n\t // eventType: 'input'|'intent'\n\t registerOnChange: function registerOnChange(fn, eventType) {\n\t functionList.push({\n\t fn: fn,\n\t type: eventType || 'input'\n\t });\n\t },\n\n\t unRegisterOnChange: function unRegisterOnChange(fn) {\n\t var position = objPos(fn);\n\n\t if (position || position === 0) {\n\t functionList.splice(position, 1);\n\t }\n\t },\n\n\t clearStorage: function clearStorage() {\n\t window.sessionStorage.clear();\n\t }\n\t };\n\t}();\n\n/***/ })\n/******/ ])\n});\n;"]}
1
+ {"version":3,"sources":["what-input.js"],"names":["root","factory","exports","module","define","amd","this","installedModules","__webpack_require__","m","modules","document","window","ask","element","ignoreKeys","specificKeys","registerOnChange","unRegisterOnChange","docElem","documentElement","currentElement","currentInput","currentIntent","currentTimestamp","Date","now","shouldPersist","formInputs","functionList","ignoreMap","specificMap","inputMap","keydown","keyup","mousedown","mousemove","MSPointerDown","MSPointerMove","pointerdown","pointermove","touchstart","touchend","isScrolling","mousePos","x","y","pointerMap","2","3","4","supportsPassive","opts","Object","defineProperty","get","addEventListener","e","addListeners","options","passive","capture","setPersist","PointerEvent","setInput","setIntent","MSPointerEvent","detectWheel","setElement","clearElement","getAttribute","body","sessionStorage","getItem","doUpdate","event","eventKey","which","value","type","pointerType","ignoreMatch","length","indexOf","specificMatch","shouldUpdate","validateTouch","persistInput","activeElem","activeElement","nodeName","toLowerCase","checkClosest","setAttribute","fireFunctions","detectScrolling","target","classList","toString","replace","removeAttribute","setItem","timestamp","touchIsValid","createElement","undefined","onmousewheel","i","len","fn","call","screenX","screenY","elem","tag","ElementPrototype","Element","prototype","matches","msMatchesSelector","webkitMatchesSelector","closest","parentElement","parentNode","nodeType","Array","opt","arr","eventType","push","position","match","objPos","splice","clearStorage","clear","c","p","moduleId","id","loaded"],"mappings":";;;;;;CAAA,SAAAA,EAAAC,GACA,iBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,IACA,mBAAAG,QAAAA,OAAAC,IACAD,OAAA,YAAA,GAAAH,GACA,iBAAAC,QALAA,QAAA,UAAAD,IAEAD,EAAA,UAAAC,IAFA,CAGAK,KAAA,WACA,OAEAC,EAAA,GA4BAC,EAAAC,EA9BAC,EA0CA,CAEA,SAAAP,EAAAD,GAEA,aAEAC,EAAAD,QAAA,WAOA,GAAA,oBAAAS,UAAA,oBAAAC,OACA,MAAA,CAEAC,IAAA,WAC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I,EAAAD,QAzBA,IAAAQ,EAEAH","file":"what-input.min.js","sourcesContent":["/**\n * what-input - A global utility for tracking the current input method (mouse, keyboard or touch).\n * @version v5.2.12\n * @link https://github.com/ten1seven/what-input\n * @license MIT\n */\n(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"whatInput\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"whatInput\"] = factory();\n\telse\n\t\troot[\"whatInput\"] = factory();\n})(this, function() {\nreturn /******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n\n\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ (function(module, exports) {\n\n\t'use strict';\n\n\tmodule.exports = function () {\n\t /*\n\t * bail out if there is no document or window\n\t * (i.e. in a node/non-DOM environment)\n\t *\n\t * Return a stubbed API instead\n\t */\n\t if (typeof document === 'undefined' || typeof window === 'undefined') {\n\t return {\n\t // always return \"initial\" because no interaction will ever be detected\n\t ask: function ask() {\n\t return 'initial';\n\t },\n\n\t // always return null\n\t element: function element() {\n\t return null;\n\t },\n\n\t // no-op\n\t ignoreKeys: function ignoreKeys() {},\n\n\t // no-op\n\t specificKeys: function specificKeys() {},\n\n\t // no-op\n\t registerOnChange: function registerOnChange() {},\n\n\t // no-op\n\t unRegisterOnChange: function unRegisterOnChange() {}\n\t };\n\t }\n\n\t /*\n\t * variables\n\t */\n\n\t // cache document.documentElement\n\t var docElem = document.documentElement;\n\n\t // currently focused dom element\n\t var currentElement = null;\n\n\t // last used input type\n\t var currentInput = 'initial';\n\n\t // last used input intent\n\t var currentIntent = currentInput;\n\n\t // UNIX timestamp of current event\n\t var currentTimestamp = Date.now();\n\n\t // check for a `data-whatpersist` attribute on either the `html` or `body` elements, defaults to `true`\n\t var shouldPersist = false;\n\n\t // form input types\n\t var formInputs = ['button', 'input', 'select', 'textarea'];\n\n\t // empty array for holding callback functions\n\t var functionList = [];\n\n\t // list of modifier keys commonly used with the mouse and\n\t // can be safely ignored to prevent false keyboard detection\n\t var ignoreMap = [16, // shift\n\t 17, // control\n\t 18, // alt\n\t 91, // Windows key / left Apple cmd\n\t 93 // Windows menu / right Apple cmd\n\t ];\n\n\t var specificMap = [];\n\n\t // mapping of events to input types\n\t var inputMap = {\n\t keydown: 'keyboard',\n\t keyup: 'keyboard',\n\t mousedown: 'mouse',\n\t mousemove: 'mouse',\n\t MSPointerDown: 'pointer',\n\t MSPointerMove: 'pointer',\n\t pointerdown: 'pointer',\n\t pointermove: 'pointer',\n\t touchstart: 'touch',\n\t touchend: 'touch'\n\n\t // boolean: true if the page is being scrolled\n\t };var isScrolling = false;\n\n\t // store current mouse position\n\t var mousePos = {\n\t x: null,\n\t y: null\n\n\t // map of IE 10 pointer events\n\t };var pointerMap = {\n\t 2: 'touch',\n\t 3: 'touch', // treat pen like touch\n\t 4: 'mouse'\n\n\t // check support for passive event listeners\n\t };var supportsPassive = false;\n\n\t try {\n\t var opts = Object.defineProperty({}, 'passive', {\n\t get: function get() {\n\t supportsPassive = true;\n\t }\n\t });\n\n\t window.addEventListener('test', null, opts);\n\t } catch (e) {}\n\t // fail silently\n\n\n\t /*\n\t * set up\n\t */\n\n\t var setUp = function setUp() {\n\t // add correct mouse wheel event mapping to `inputMap`\n\t inputMap[detectWheel()] = 'mouse';\n\n\t addListeners();\n\t };\n\n\t /*\n\t * events\n\t */\n\n\t var addListeners = function addListeners() {\n\t // `pointermove`, `MSPointerMove`, `mousemove` and mouse wheel event binding\n\t // can only demonstrate potential, but not actual, interaction\n\t // and are treated separately\n\t var options = supportsPassive ? { passive: true, capture: true } : true;\n\n\t document.addEventListener('DOMContentLoaded', setPersist, true);\n\n\t // pointer events (mouse, pen, touch)\n\t if (window.PointerEvent) {\n\t window.addEventListener('pointerdown', setInput, true);\n\t window.addEventListener('pointermove', setIntent, true);\n\t } else if (window.MSPointerEvent) {\n\t window.addEventListener('MSPointerDown', setInput, true);\n\t window.addEventListener('MSPointerMove', setIntent, true);\n\t } else {\n\t // mouse events\n\t window.addEventListener('mousedown', setInput, true);\n\t window.addEventListener('mousemove', setIntent, true);\n\n\t // touch events\n\t if ('ontouchstart' in window) {\n\t window.addEventListener('touchstart', setInput, options);\n\t window.addEventListener('touchend', setInput, true);\n\t }\n\t }\n\n\t // mouse wheel\n\t window.addEventListener(detectWheel(), setIntent, options);\n\n\t // keyboard events\n\t window.addEventListener('keydown', setInput, true);\n\t window.addEventListener('keyup', setInput, true);\n\n\t // focus events\n\t window.addEventListener('focusin', setElement, true);\n\t window.addEventListener('focusout', clearElement, true);\n\t };\n\n\t // checks if input persistence should happen and\n\t // get saved state from session storage if true (defaults to `false`)\n\t var setPersist = function setPersist() {\n\t shouldPersist = !(docElem.getAttribute('data-whatpersist') === 'false' || document.body.getAttribute('data-whatpersist') === 'false');\n\n\t if (shouldPersist) {\n\t // check for session variables and use if available\n\t try {\n\t if (window.sessionStorage.getItem('what-input')) {\n\t currentInput = window.sessionStorage.getItem('what-input');\n\t }\n\n\t if (window.sessionStorage.getItem('what-intent')) {\n\t currentIntent = window.sessionStorage.getItem('what-intent');\n\t }\n\t } catch (e) {\n\t // fail silently\n\t }\n\t }\n\n\t // always run these so at least `initial` state is set\n\t doUpdate('input');\n\t doUpdate('intent');\n\t };\n\n\t // checks conditions before updating new input\n\t var setInput = function setInput(event) {\n\t var eventKey = event.which;\n\t var value = inputMap[event.type];\n\n\t if (value === 'pointer') {\n\t value = pointerType(event);\n\t }\n\n\t var ignoreMatch = !specificMap.length && ignoreMap.indexOf(eventKey) === -1;\n\n\t var specificMatch = specificMap.length && specificMap.indexOf(eventKey) !== -1;\n\n\t var shouldUpdate = value === 'keyboard' && eventKey && (ignoreMatch || specificMatch) || value === 'mouse' || value === 'touch';\n\n\t // prevent touch detection from being overridden by event execution order\n\t if (validateTouch(value)) {\n\t shouldUpdate = false;\n\t }\n\n\t if (shouldUpdate && currentInput !== value) {\n\t currentInput = value;\n\n\t persistInput('input', currentInput);\n\t doUpdate('input');\n\t }\n\n\t if (shouldUpdate && currentIntent !== value) {\n\t // preserve intent for keyboard interaction with form fields\n\t var activeElem = document.activeElement;\n\t var notFormInput = activeElem && activeElem.nodeName && (formInputs.indexOf(activeElem.nodeName.toLowerCase()) === -1 || activeElem.nodeName.toLowerCase() === 'button' && !checkClosest(activeElem, 'form'));\n\n\t if (notFormInput) {\n\t currentIntent = value;\n\n\t persistInput('intent', currentIntent);\n\t doUpdate('intent');\n\t }\n\t }\n\t };\n\n\t // updates the doc and `inputTypes` array with new input\n\t var doUpdate = function doUpdate(which) {\n\t docElem.setAttribute('data-what' + which, which === 'input' ? currentInput : currentIntent);\n\n\t fireFunctions(which);\n\t };\n\n\t // updates input intent for `mousemove` and `pointermove`\n\t var setIntent = function setIntent(event) {\n\t var value = inputMap[event.type];\n\n\t if (value === 'pointer') {\n\t value = pointerType(event);\n\t }\n\n\t // test to see if `mousemove` happened relative to the screen to detect scrolling versus mousemove\n\t detectScrolling(event);\n\n\t // only execute if scrolling isn't happening\n\t if ((!isScrolling && !validateTouch(value) || isScrolling && event.type === 'wheel' || event.type === 'mousewheel' || event.type === 'DOMMouseScroll') && currentIntent !== value) {\n\t currentIntent = value;\n\n\t persistInput('intent', currentIntent);\n\t doUpdate('intent');\n\t }\n\t };\n\n\t var setElement = function setElement(event) {\n\t if (!event.target.nodeName) {\n\t // If nodeName is undefined, clear the element\n\t // This can happen if click inside an <svg> element.\n\t clearElement();\n\t return;\n\t }\n\n\t currentElement = event.target.nodeName.toLowerCase();\n\t docElem.setAttribute('data-whatelement', currentElement);\n\n\t if (event.target.classList && event.target.classList.length) {\n\t docElem.setAttribute('data-whatclasses', event.target.classList.toString().replace(' ', ','));\n\t }\n\t };\n\n\t var clearElement = function clearElement() {\n\t currentElement = null;\n\n\t docElem.removeAttribute('data-whatelement');\n\t docElem.removeAttribute('data-whatclasses');\n\t };\n\n\t var persistInput = function persistInput(which, value) {\n\t if (shouldPersist) {\n\t try {\n\t window.sessionStorage.setItem('what-' + which, value);\n\t } catch (e) {\n\t // fail silently\n\t }\n\t }\n\t };\n\n\t /*\n\t * utilities\n\t */\n\n\t var pointerType = function pointerType(event) {\n\t if (typeof event.pointerType === 'number') {\n\t return pointerMap[event.pointerType];\n\t } else {\n\t // treat pen like touch\n\t return event.pointerType === 'pen' ? 'touch' : event.pointerType;\n\t }\n\t };\n\n\t // prevent touch detection from being overridden by event execution order\n\t var validateTouch = function validateTouch(value) {\n\t var timestamp = Date.now();\n\n\t var touchIsValid = value === 'mouse' && currentInput === 'touch' && timestamp - currentTimestamp < 200;\n\n\t currentTimestamp = timestamp;\n\n\t return touchIsValid;\n\t };\n\n\t // detect version of mouse wheel event to use\n\t // via https://developer.mozilla.org/en-US/docs/Web/API/Element/wheel_event\n\t var detectWheel = function detectWheel() {\n\t var wheelType = null;\n\n\t // Modern browsers support \"wheel\"\n\t if ('onwheel' in document.createElement('div')) {\n\t wheelType = 'wheel';\n\t } else {\n\t // Webkit and IE support at least \"mousewheel\"\n\t // or assume that remaining browsers are older Firefox\n\t wheelType = document.onmousewheel !== undefined ? 'mousewheel' : 'DOMMouseScroll';\n\t }\n\n\t return wheelType;\n\t };\n\n\t // runs callback functions\n\t var fireFunctions = function fireFunctions(type) {\n\t for (var i = 0, len = functionList.length; i < len; i++) {\n\t if (functionList[i].type === type) {\n\t functionList[i].fn.call(undefined, type === 'input' ? currentInput : currentIntent);\n\t }\n\t }\n\t };\n\n\t // finds matching element in an object\n\t var objPos = function objPos(match) {\n\t for (var i = 0, len = functionList.length; i < len; i++) {\n\t if (functionList[i].fn === match) {\n\t return i;\n\t }\n\t }\n\t };\n\n\t var detectScrolling = function detectScrolling(event) {\n\t if (mousePos.x !== event.screenX || mousePos.y !== event.screenY) {\n\t isScrolling = false;\n\n\t mousePos.x = event.screenX;\n\t mousePos.y = event.screenY;\n\t } else {\n\t isScrolling = true;\n\t }\n\t };\n\n\t // manual version of `closest()`\n\t var checkClosest = function checkClosest(elem, tag) {\n\t var ElementPrototype = window.Element.prototype;\n\n\t if (!ElementPrototype.matches) {\n\t ElementPrototype.matches = ElementPrototype.msMatchesSelector || ElementPrototype.webkitMatchesSelector;\n\t }\n\n\t if (!ElementPrototype.closest) {\n\t do {\n\t if (elem.matches(tag)) {\n\t return elem;\n\t }\n\n\t elem = elem.parentElement || elem.parentNode;\n\t } while (elem !== null && elem.nodeType === 1);\n\n\t return null;\n\t } else {\n\t return elem.closest(tag);\n\t }\n\t };\n\n\t /*\n\t * init\n\t */\n\n\t // don't start script unless browser cuts the mustard\n\t // (also passes if polyfills are used)\n\t if ('addEventListener' in window && Array.prototype.indexOf) {\n\t setUp();\n\t }\n\n\t /*\n\t * api\n\t */\n\n\t return {\n\t // returns string: the current input type\n\t // opt: 'intent'|'input'\n\t // 'input' (default): returns the same value as the `data-whatinput` attribute\n\t // 'intent': includes `data-whatintent` value if it's different than `data-whatinput`\n\t ask: function ask(opt) {\n\t return opt === 'intent' ? currentIntent : currentInput;\n\t },\n\n\t // returns string: the currently focused element or null\n\t element: function element() {\n\t return currentElement;\n\t },\n\n\t // overwrites ignored keys with provided array\n\t ignoreKeys: function ignoreKeys(arr) {\n\t ignoreMap = arr;\n\t },\n\n\t // overwrites specific char keys to update on\n\t specificKeys: function specificKeys(arr) {\n\t specificMap = arr;\n\t },\n\n\t // attach functions to input and intent \"events\"\n\t // funct: function to fire on change\n\t // eventType: 'input'|'intent'\n\t registerOnChange: function registerOnChange(fn, eventType) {\n\t functionList.push({\n\t fn: fn,\n\t type: eventType || 'input'\n\t });\n\t },\n\n\t unRegisterOnChange: function unRegisterOnChange(fn) {\n\t var position = objPos(fn);\n\n\t if (position || position === 0) {\n\t functionList.splice(position, 1);\n\t }\n\t },\n\n\t clearStorage: function clearStorage() {\n\t window.sessionStorage.clear();\n\t }\n\t };\n\t}();\n\n/***/ })\n/******/ ])\n});\n;"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "what-input",
3
- "version": "5.2.9",
3
+ "version": "5.2.12",
4
4
  "description": "A global utility for tracking the current input method (mouse, keyboard or touch).",
5
5
  "main": "dist/what-input.js",
6
6
  "types": "src/scripts/what-input.d.ts",
@@ -82,7 +82,7 @@
82
82
 
83
83
  <p class="pull-right">
84
84
  Check out the project
85
- <a href="https://github.com/ten1seven/what-input">on Github</a>.
85
+ <a href="https://github.com/ten1seven/what-input">on GitHub</a>.
86
86
  </p>
87
87
  </footer>
88
88
  </div>
@@ -1,11 +1,15 @@
1
1
  declare const whatInput: {
2
- ask: (strategy?: "intent") => "pointer" | "keyboard" | "mouse" | "touch";
2
+ ask: (strategy?: Strategy) => InputMethod;
3
3
  element: () => string | null;
4
4
  ignoreKeys: (keyCodes: number[]) => void;
5
5
  specificKeys: (keyCodes: number[]) => void;
6
- registerOnChange: (callback: () => void, strategy?: "intent") => void;
7
- unRegisterOnChange: (callback: () => void) => void;
6
+ registerOnChange: (callback: (type: InputMethod) => void, strategy?: Strategy) => void;
7
+ unRegisterOnChange: (callback: (type: InputMethod) => void) => void;
8
8
  clearStorage: () => void;
9
9
  };
10
10
 
11
+ export type InputMethod = "initial" | "pointer" | "keyboard" | "mouse" | "touch";
12
+
13
+ export type Strategy = "input" | "intent";
14
+
11
15
  export default whatInput;
@@ -47,7 +47,7 @@ module.exports = (() => {
47
47
  let currentTimestamp = Date.now()
48
48
 
49
49
  // check for a `data-whatpersist` attribute on either the `html` or `body` elements, defaults to `true`
50
- let shouldPersist = 'false'
50
+ let shouldPersist = false
51
51
 
52
52
  // form input types
53
53
  const formInputs = ['button', 'input', 'select', 'textarea']
@@ -131,26 +131,26 @@ module.exports = (() => {
131
131
  // `pointermove`, `MSPointerMove`, `mousemove` and mouse wheel event binding
132
132
  // can only demonstrate potential, but not actual, interaction
133
133
  // and are treated separately
134
- const options = supportsPassive ? { passive: true } : false
134
+ const options = supportsPassive ? { passive: true, capture: true } : true
135
135
 
136
- document.addEventListener('DOMContentLoaded', setPersist)
136
+ document.addEventListener('DOMContentLoaded', setPersist, true)
137
137
 
138
138
  // pointer events (mouse, pen, touch)
139
139
  if (window.PointerEvent) {
140
- window.addEventListener('pointerdown', setInput)
141
- window.addEventListener('pointermove', setIntent)
140
+ window.addEventListener('pointerdown', setInput, true)
141
+ window.addEventListener('pointermove', setIntent, true)
142
142
  } else if (window.MSPointerEvent) {
143
- window.addEventListener('MSPointerDown', setInput)
144
- window.addEventListener('MSPointerMove', setIntent)
143
+ window.addEventListener('MSPointerDown', setInput, true)
144
+ window.addEventListener('MSPointerMove', setIntent, true)
145
145
  } else {
146
146
  // mouse events
147
- window.addEventListener('mousedown', setInput)
148
- window.addEventListener('mousemove', setIntent)
147
+ window.addEventListener('mousedown', setInput, true)
148
+ window.addEventListener('mousemove', setIntent, true)
149
149
 
150
150
  // touch events
151
151
  if ('ontouchstart' in window) {
152
152
  window.addEventListener('touchstart', setInput, options)
153
- window.addEventListener('touchend', setInput)
153
+ window.addEventListener('touchend', setInput, true)
154
154
  }
155
155
  }
156
156
 
@@ -158,19 +158,19 @@ module.exports = (() => {
158
158
  window.addEventListener(detectWheel(), setIntent, options)
159
159
 
160
160
  // keyboard events
161
- window.addEventListener('keydown', setInput)
162
- window.addEventListener('keyup', setInput)
161
+ window.addEventListener('keydown', setInput, true)
162
+ window.addEventListener('keyup', setInput, true)
163
163
 
164
164
  // focus events
165
- window.addEventListener('focusin', setElement)
166
- window.addEventListener('focusout', clearElement)
165
+ window.addEventListener('focusin', setElement, true)
166
+ window.addEventListener('focusout', clearElement, true)
167
167
  }
168
168
 
169
169
  // checks if input persistence should happen and
170
170
  // get saved state from session storage if true (defaults to `false`)
171
171
  const setPersist = () => {
172
172
  shouldPersist = !(
173
- docElem.getAttribute('data-whatpersist') ||
173
+ docElem.getAttribute('data-whatpersist') === 'false' ||
174
174
  document.body.getAttribute('data-whatpersist') === 'false'
175
175
  )
176
176
 
@@ -195,7 +195,7 @@ module.exports = (() => {
195
195
  }
196
196
 
197
197
  // checks conditions before updating new input
198
- const setInput = event => {
198
+ const setInput = (event) => {
199
199
  const eventKey = event.which
200
200
  let value = inputMap[event.type]
201
201
 
@@ -246,7 +246,7 @@ module.exports = (() => {
246
246
  }
247
247
 
248
248
  // updates the doc and `inputTypes` array with new input
249
- const doUpdate = which => {
249
+ const doUpdate = (which) => {
250
250
  docElem.setAttribute(
251
251
  'data-what' + which,
252
252
  which === 'input' ? currentInput : currentIntent
@@ -256,7 +256,7 @@ module.exports = (() => {
256
256
  }
257
257
 
258
258
  // updates input intent for `mousemove` and `pointermove`
259
- const setIntent = event => {
259
+ const setIntent = (event) => {
260
260
  let value = inputMap[event.type]
261
261
 
262
262
  if (value === 'pointer') {
@@ -269,9 +269,9 @@ module.exports = (() => {
269
269
  // only execute if scrolling isn't happening
270
270
  if (
271
271
  ((!isScrolling && !validateTouch(value)) ||
272
- ((isScrolling && event.type === 'wheel') ||
273
- event.type === 'mousewheel' ||
274
- event.type === 'DOMMouseScroll')) &&
272
+ (isScrolling && event.type === 'wheel') ||
273
+ event.type === 'mousewheel' ||
274
+ event.type === 'DOMMouseScroll') &&
275
275
  currentIntent !== value
276
276
  ) {
277
277
  currentIntent = value
@@ -281,7 +281,7 @@ module.exports = (() => {
281
281
  }
282
282
  }
283
283
 
284
- const setElement = event => {
284
+ const setElement = (event) => {
285
285
  if (!event.target.nodeName) {
286
286
  // If nodeName is undefined, clear the element
287
287
  // This can happen if click inside an <svg> element.
@@ -321,7 +321,7 @@ module.exports = (() => {
321
321
  * utilities
322
322
  */
323
323
 
324
- const pointerType = event => {
324
+ const pointerType = (event) => {
325
325
  if (typeof event.pointerType === 'number') {
326
326
  return pointerMap[event.pointerType]
327
327
  } else {
@@ -331,7 +331,7 @@ module.exports = (() => {
331
331
  }
332
332
 
333
333
  // prevent touch detection from being overridden by event execution order
334
- const validateTouch = value => {
334
+ const validateTouch = (value) => {
335
335
  const timestamp = Date.now()
336
336
 
337
337
  const touchIsValid =
@@ -363,7 +363,7 @@ module.exports = (() => {
363
363
  }
364
364
 
365
365
  // runs callback functions
366
- const fireFunctions = type => {
366
+ const fireFunctions = (type) => {
367
367
  for (let i = 0, len = functionList.length; i < len; i++) {
368
368
  if (functionList[i].type === type) {
369
369
  functionList[i].fn.call(
@@ -375,7 +375,7 @@ module.exports = (() => {
375
375
  }
376
376
 
377
377
  // finds matching element in an object
378
- const objPos = match => {
378
+ const objPos = (match) => {
379
379
  for (let i = 0, len = functionList.length; i < len; i++) {
380
380
  if (functionList[i].fn === match) {
381
381
  return i
@@ -383,7 +383,7 @@ module.exports = (() => {
383
383
  }
384
384
  }
385
385
 
386
- const detectScrolling = event => {
386
+ const detectScrolling = (event) => {
387
387
  if (mousePos.x !== event.screenX || mousePos.y !== event.screenY) {
388
388
  isScrolling = false
389
389
 
@@ -438,7 +438,7 @@ module.exports = (() => {
438
438
  // opt: 'intent'|'input'
439
439
  // 'input' (default): returns the same value as the `data-whatinput` attribute
440
440
  // 'intent': includes `data-whatintent` value if it's different than `data-whatinput`
441
- ask: opt => {
441
+ ask: (opt) => {
442
442
  return opt === 'intent' ? currentIntent : currentInput
443
443
  },
444
444
 
@@ -448,12 +448,12 @@ module.exports = (() => {
448
448
  },
449
449
 
450
450
  // overwrites ignored keys with provided array
451
- ignoreKeys: arr => {
451
+ ignoreKeys: (arr) => {
452
452
  ignoreMap = arr
453
453
  },
454
454
 
455
455
  // overwrites specific char keys to update on
456
- specificKeys: arr => {
456
+ specificKeys: (arr) => {
457
457
  specificMap = arr
458
458
  },
459
459
 
@@ -467,7 +467,7 @@ module.exports = (() => {
467
467
  })
468
468
  },
469
469
 
470
- unRegisterOnChange: fn => {
470
+ unRegisterOnChange: (fn) => {
471
471
  const position = objPos(fn)
472
472
 
473
473
  if (position || position === 0) {