@instructure/ui-dom-utils 8.33.1 → 8.33.2-snapshot-5

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.
Files changed (59) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/es/InputModeListener.js +1 -22
  3. package/es/addEventListener.js +1 -3
  4. package/es/addInputModeListener.js +1 -29
  5. package/es/addPositionChangeListener.js +1 -7
  6. package/es/addResizeListener.js +1 -8
  7. package/es/contains.js +2 -8
  8. package/es/containsActiveElement.js +1 -2
  9. package/es/elementMatches.js +3 -4
  10. package/es/findDOMNode.js +4 -11
  11. package/es/findFocusable.js +1 -12
  12. package/es/findTabbable.js +1 -3
  13. package/es/getActiveElement.js +4 -4
  14. package/es/getBoundingClientRect.js +1 -13
  15. package/es/getClassList.js +2 -7
  16. package/es/getComputedStyle.js +1 -5
  17. package/es/getFontSize.js +5 -8
  18. package/es/getOffsetParents.js +5 -11
  19. package/es/getScrollParents.js +8 -20
  20. package/es/handleMouseOverOut.js +2 -3
  21. package/es/isActiveElement.js +1 -2
  22. package/es/isDefinedCustomElement.js +0 -1
  23. package/es/isVisible.js +11 -18
  24. package/es/matchMedia.js +1 -4
  25. package/es/ownerDocument.js +1 -4
  26. package/es/ownerWindow.js +1 -2
  27. package/es/requestAnimationFrame.js +2 -5
  28. package/es/transformSelection.js +4 -10
  29. package/lib/InputModeListener.js +1 -26
  30. package/lib/addEventListener.js +0 -4
  31. package/lib/addInputModeListener.js +1 -32
  32. package/lib/addPositionChangeListener.js +0 -10
  33. package/lib/addResizeListener.js +0 -11
  34. package/lib/canUseDOM.js +0 -1
  35. package/lib/contains.js +1 -10
  36. package/lib/containsActiveElement.js +0 -5
  37. package/lib/elementMatches.js +2 -5
  38. package/lib/findDOMNode.js +4 -13
  39. package/lib/findFocusable.js +1 -13
  40. package/lib/findTabbable.js +1 -4
  41. package/lib/getActiveElement.js +2 -5
  42. package/lib/getBoundingClientRect.js +0 -17
  43. package/lib/getClassList.js +2 -9
  44. package/lib/getComputedStyle.js +0 -8
  45. package/lib/getFontSize.js +6 -12
  46. package/lib/getOffsetParents.js +4 -15
  47. package/lib/getScrollParents.js +7 -23
  48. package/lib/handleMouseOverOut.js +0 -4
  49. package/lib/index.js +0 -26
  50. package/lib/isActiveElement.js +0 -4
  51. package/lib/isDefinedCustomElement.js +0 -2
  52. package/lib/isVisible.js +10 -20
  53. package/lib/matchMedia.js +0 -7
  54. package/lib/ownerDocument.js +0 -5
  55. package/lib/ownerWindow.js +0 -4
  56. package/lib/requestAnimationFrame.js +1 -6
  57. package/lib/transformSelection.js +4 -11
  58. package/package.json +5 -5
  59. package/tsconfig.build.tsbuildinfo +1 -1
@@ -21,6 +21,7 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
+
24
25
  import { findDOMNode } from './findDOMNode';
25
26
  const apiForEmptyNode = {
26
27
  toArray: () => [],
@@ -28,6 +29,7 @@ const apiForEmptyNode = {
28
29
  add: () => {},
29
30
  remove: () => {}
30
31
  };
32
+
31
33
  /**
32
34
  * ---
33
35
  * category: utilities/DOM
@@ -42,7 +44,6 @@ const apiForEmptyNode = {
42
44
  * @param { Node | Window | React.ReactElement | React.Component | function } element - component or DOM node
43
45
  * @return {Object} object containing classList functions 'contains', 'add', and 'remove'
44
46
  */
45
-
46
47
  function getClassList(element) {
47
48
  const node = findDOMNode(element);
48
49
  if (!node) return apiForEmptyNode;
@@ -50,26 +51,20 @@ function getClassList(element) {
50
51
  toArray() {
51
52
  return [...node.classList];
52
53
  },
53
-
54
54
  contains: () => false,
55
55
  add: () => {},
56
56
  remove: () => {}
57
57
  };
58
-
59
58
  classListApi['add'] = className => {
60
59
  return node.classList.add(className);
61
60
  };
62
-
63
61
  classListApi['remove'] = className => {
64
62
  return node.classList.remove(className);
65
63
  };
66
-
67
64
  classListApi['contains'] = className => {
68
65
  return node.classList.contains(className);
69
66
  };
70
-
71
67
  return classListApi;
72
68
  }
73
-
74
69
  export default getClassList;
75
70
  export { getClassList };
@@ -21,10 +21,10 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
+
24
25
  import { findDOMNode } from './findDOMNode';
25
26
  import { ownerWindow } from './ownerWindow';
26
27
  import { canUseDOM } from './canUseDOM';
27
-
28
28
  /**
29
29
  * ---
30
30
  * category: utilities/DOM
@@ -40,18 +40,14 @@ import { canUseDOM } from './canUseDOM';
40
40
  */
41
41
  function getComputedStyle(el, pseudoElt) {
42
42
  let style = {};
43
-
44
43
  if (canUseDOM) {
45
44
  const node = el && findDOMNode(el);
46
-
47
45
  if (node) {
48
46
  const window = ownerWindow(el);
49
47
  style = window !== null ? window.getComputedStyle(node, pseudoElt) : {};
50
48
  }
51
49
  }
52
-
53
50
  return style;
54
51
  }
55
-
56
52
  export default getComputedStyle;
57
53
  export { getComputedStyle };
package/es/getFontSize.js CHANGED
@@ -25,6 +25,7 @@ import { canUseDOM } from './canUseDOM';
25
25
  import { ownerDocument } from './ownerDocument';
26
26
  import { getComputedStyle } from './getComputedStyle';
27
27
  const COMPUTED_CACHE = new WeakMap();
28
+
28
29
  /**
29
30
  * ---
30
31
  * category: utilities/DOM
@@ -37,27 +38,23 @@ const COMPUTED_CACHE = new WeakMap();
37
38
  * @param { boolean } ignoreCache
38
39
  * @returns { number } font size in px
39
40
  */
40
-
41
41
  function getFontSize(el) {
42
42
  let ignoreCache = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
43
-
44
43
  if (!canUseDOM) {
45
44
  return 16;
46
45
  }
46
+ const container = el || ownerDocument(el).documentElement;
47
47
 
48
- const container = el || ownerDocument(el).documentElement; // return the cached font size if it's there
49
-
48
+ // return the cached font size if it's there
50
49
  const cachedValue = COMPUTED_CACHE.get(container);
51
-
52
50
  if (!ignoreCache && cachedValue) {
53
51
  return cachedValue;
54
52
  }
53
+ const fontSize = parseInt(getComputedStyle(container).getPropertyValue('font-size'));
55
54
 
56
- const fontSize = parseInt(getComputedStyle(container).getPropertyValue('font-size')); // cache the computed font size so that we don't have to compute it again
57
-
55
+ // cache the computed font size so that we don't have to compute it again
58
56
  COMPUTED_CACHE.set(container, fontSize);
59
57
  return fontSize;
60
58
  }
61
-
62
59
  export default getFontSize;
63
60
  export { getFontSize };
@@ -21,11 +21,11 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
+
24
25
  import { findDOMNode } from './findDOMNode';
25
26
  import { canUseDOM } from './canUseDOM';
26
27
  import { getComputedStyle } from './getComputedStyle';
27
28
  import { ownerDocument } from './ownerDocument';
28
-
29
29
  /**
30
30
  * ---
31
31
  * category: utilities/DOM
@@ -41,32 +41,26 @@ import { ownerDocument } from './ownerDocument';
41
41
  */
42
42
  function getOffsetParents(el) {
43
43
  const parents = [];
44
-
45
44
  if (!canUseDOM) {
46
45
  return parents;
47
46
  }
48
-
49
47
  const node = el && findDOMNode(el);
50
-
51
48
  if (node) {
52
- let parent = node; // eslint-disable-next-line no-cond-assign
49
+ let parent = node;
53
50
 
51
+ // eslint-disable-next-line no-cond-assign
54
52
  while ((parent = parent.parentNode) && parent && parent.nodeType === 1 && parent.tagName !== 'BODY') {
55
53
  const style = getComputedStyle(parent);
56
- const transform = style.getPropertyValue('-webkit-transform') || style.getPropertyValue('-moz-transform') || style.getPropertyValue('-ms-transform') || style.getPropertyValue('-o-transform') || style.getPropertyValue('transform') || 'none'; // initial value of transform can be 'none' or a matrix equivalent
57
-
54
+ const transform = style.getPropertyValue('-webkit-transform') || style.getPropertyValue('-moz-transform') || style.getPropertyValue('-ms-transform') || style.getPropertyValue('-o-transform') || style.getPropertyValue('transform') || 'none';
55
+ // initial value of transform can be 'none' or a matrix equivalent
58
56
  const transformDefault = transform === 'none' || transform === 'matrix(1, 0, 0, 1, 0, 0)' ? true : false;
59
-
60
57
  if (style.position !== 'static' || !transformDefault) {
61
58
  parents.push(parent);
62
59
  }
63
60
  }
64
-
65
61
  parents.push(ownerDocument(node).body);
66
62
  }
67
-
68
63
  return parents;
69
64
  }
70
-
71
65
  export default getOffsetParents;
72
66
  export { getOffsetParents };
@@ -21,10 +21,10 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
+
24
25
  import { findDOMNode } from './findDOMNode';
25
26
  import { canUseDOM } from './canUseDOM';
26
27
  import { getComputedStyle } from './getComputedStyle';
27
-
28
28
  /**
29
29
  * ---
30
30
  * category: utilities/DOM
@@ -41,64 +41,52 @@ import { getComputedStyle } from './getComputedStyle';
41
41
  */
42
42
  function getScrollParents(el) {
43
43
  const parents = [];
44
-
45
44
  if (!canUseDOM) {
46
45
  return parents;
47
46
  }
48
-
49
47
  const node = el && findDOMNode(el);
50
-
51
48
  if (node) {
52
49
  // In firefox if the element is inside an iframe with display: none; window.getComputedStyle() will return null;
53
50
  // https://bugzilla.mozilla.org/show_bug.cgi?id=548397
54
51
  const computedStyle = getComputedStyle(node) || {};
55
52
  const position = computedStyle.position;
56
-
57
53
  if (position === 'fixed') {
58
54
  return [node.ownerDocument];
59
55
  }
60
-
61
- let parent = node; // eslint-disable-next-line no-cond-assign
62
-
56
+ let parent = node;
57
+ // eslint-disable-next-line no-cond-assign
63
58
  while (parent && parent.nodeType === 1 && (parent = parent.parentNode)) {
64
59
  let style;
65
-
66
60
  try {
67
61
  style = getComputedStyle(parent);
68
62
  } catch (err) {} // eslint-disable-line no-empty
69
63
 
70
-
71
64
  if (typeof style === 'undefined' || style === null) {
72
65
  parents.push(parent);
73
66
  return parents;
74
67
  }
75
-
76
68
  const _ref = style,
77
- overflow = _ref.overflow,
78
- overflowX = _ref.overflowX,
79
- overflowY = _ref.overflowY;
80
-
69
+ overflow = _ref.overflow,
70
+ overflowX = _ref.overflowX,
71
+ overflowY = _ref.overflowY;
81
72
  if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) {
82
73
  if (position !== 'absolute' || ['relative', 'absolute', 'fixed'].indexOf(style.position) >= 0) {
83
74
  parents.push(parent);
84
75
  }
85
76
  }
86
77
  }
87
-
88
78
  const ownerDocument = node.ownerDocument;
89
-
90
79
  if (ownerDocument) {
91
- parents.push(ownerDocument.body); // If the node is within a frame, account for the parent window scroll
80
+ parents.push(ownerDocument.body);
92
81
 
82
+ // If the node is within a frame, account for the parent window scroll
93
83
  if (ownerDocument !== document) {
94
84
  // ownerDocument.defaultView can be null
95
85
  parents.push(ownerDocument.defaultView);
96
86
  }
97
87
  }
98
88
  }
99
-
100
89
  return parents;
101
90
  }
102
-
103
91
  export default getScrollParents;
104
92
  export { getScrollParents };
@@ -21,7 +21,9 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
+
24
25
  import { contains } from './contains';
26
+
25
27
  /**
26
28
  * ---
27
29
  * category: utilities/DOM
@@ -36,15 +38,12 @@ import { contains } from './contains';
36
38
  * @param handler {function} Callback function for handling the event
37
39
  * @param event {Event} The DOM Event that was fired
38
40
  */
39
-
40
41
  function handleMouseOverOut(handler, event) {
41
42
  const target = event.currentTarget;
42
43
  const related = event.relatedTarget;
43
-
44
44
  if (!related || related !== target && !contains(target, related)) {
45
45
  handler(event);
46
46
  }
47
47
  }
48
-
49
48
  export default handleMouseOverOut;
50
49
  export { handleMouseOverOut };
@@ -21,9 +21,9 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
+
24
25
  import { findDOMNode } from './findDOMNode';
25
26
  import { getActiveElement } from './getActiveElement';
26
-
27
27
  /**
28
28
  * ---
29
29
  * category: utilities/DOM
@@ -38,6 +38,5 @@ function isActiveElement(el) {
38
38
  const node = el && findDOMNode(el);
39
39
  return node ? getActiveElement() === node : false;
40
40
  }
41
-
42
41
  export default isActiveElement;
43
42
  export { isActiveElement };
@@ -35,6 +35,5 @@
35
35
  function isDefinedCustomElement(el) {
36
36
  return Boolean(el.tagName.includes('-') && customElements.get(el.tagName.toLowerCase()));
37
37
  }
38
-
39
38
  export { isDefinedCustomElement };
40
39
  export default isDefinedCustomElement;
package/es/isVisible.js CHANGED
@@ -21,9 +21,9 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
+
24
25
  import { findDOMNode } from './findDOMNode';
25
26
  import { getComputedStyle } from './getComputedStyle';
26
-
27
27
  /**
28
28
  * ---
29
29
  * category: utilities/DOM
@@ -40,30 +40,26 @@ import { getComputedStyle } from './getComputedStyle';
40
40
  */
41
41
  function isVisible(el) {
42
42
  let recursive = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
43
- const node = el && findDOMNode(el); // skip document or window nodes
44
-
43
+ const node = el && findDOMNode(el);
44
+ // skip document or window nodes
45
45
  if (node === window || node === document || node === document.body) {
46
46
  return true;
47
47
  }
48
-
49
- const parent = node.parentNode; // skip text node, check parent
50
-
48
+ const parent = node.parentNode;
49
+ // skip text node, check parent
51
50
  if (node.nodeType === 3) {
52
51
  return isVisible(parent, recursive);
53
52
  }
54
-
55
- const style = node ? getComputedStyle(node) : {}; // physically and visually hidden
56
-
53
+ const style = node ? getComputedStyle(node) : {};
54
+ // physically and visually hidden
57
55
  if (style.display === 'none') {
58
56
  return false;
59
- } // visually hidden
60
-
61
-
57
+ }
58
+ // visually hidden
62
59
  if (style.visibility === 'hidden' || style.opacity === '0') {
63
60
  return false;
64
- } // hidden by clipping
65
-
66
-
61
+ }
62
+ // hidden by clipping
67
63
  if (style.overflow === 'hidden' && style.position === 'absolute' && style.clip !== 'auto') {
68
64
  const rect = style.clip.substring(5).slice(0, -1).split(', ');
69
65
  let zeros = true;
@@ -72,12 +68,10 @@ function isVisible(el) {
72
68
  zeros = false;
73
69
  }
74
70
  });
75
-
76
71
  if (zeros) {
77
72
  return false;
78
73
  }
79
74
  }
80
-
81
75
  if (recursive && parent) {
82
76
  // recursively check parent visibility
83
77
  return isVisible(parent);
@@ -85,6 +79,5 @@ function isVisible(el) {
85
79
  return true;
86
80
  }
87
81
  }
88
-
89
82
  export default isVisible;
90
83
  export { isVisible };
package/es/matchMedia.js CHANGED
@@ -21,10 +21,10 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
+
24
25
  import { canUseDOM } from './canUseDOM';
25
26
  import { findDOMNode } from './findDOMNode';
26
27
  import { ownerWindow } from './ownerWindow';
27
-
28
28
  /**
29
29
  * ---
30
30
  * category: utilities/DOM
@@ -40,14 +40,11 @@ import { ownerWindow } from './ownerWindow';
40
40
  */
41
41
  function matchMedia(query, el) {
42
42
  const node = findDOMNode(el) || document;
43
-
44
43
  if (canUseDOM) {
45
44
  const window = ownerWindow(node);
46
45
  return window && window.matchMedia(query);
47
46
  }
48
-
49
47
  return null;
50
48
  }
51
-
52
49
  export default matchMedia;
53
50
  export { matchMedia };
@@ -21,8 +21,8 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
- import { findDOMNode } from './findDOMNode';
25
24
 
25
+ import { findDOMNode } from './findDOMNode';
26
26
  /**
27
27
  * ---
28
28
  * category: utilities/DOM
@@ -36,13 +36,10 @@ import { findDOMNode } from './findDOMNode';
36
36
  function ownerDocument(el) {
37
37
  const node = el && findDOMNode(el);
38
38
  let ownerDocument;
39
-
40
39
  if (node && 'ownerDocument' in node) {
41
40
  ownerDocument = node.ownerDocument;
42
41
  }
43
-
44
42
  return ownerDocument || document;
45
43
  }
46
-
47
44
  export default ownerDocument;
48
45
  export { ownerDocument };
package/es/ownerWindow.js CHANGED
@@ -21,9 +21,9 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
+
24
25
  import { findDOMNode } from './findDOMNode';
25
26
  import { ownerDocument } from './ownerDocument';
26
-
27
27
  /**
28
28
  * ---
29
29
  * category: utilities/DOM
@@ -39,6 +39,5 @@ function ownerWindow(el) {
39
39
  const doc = ownerDocument(node);
40
40
  return doc && doc.defaultView;
41
41
  }
42
-
43
42
  export default ownerWindow;
44
43
  export { ownerWindow };
@@ -21,8 +21,8 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
- import { canUseDOM } from './canUseDOM';
25
24
 
25
+ import { canUseDOM } from './canUseDOM';
26
26
  /**
27
27
  * ---
28
28
  * category: utilities/DOM
@@ -37,8 +37,8 @@ import { canUseDOM } from './canUseDOM';
37
37
  */
38
38
  const requestAnimationFrame = function () {
39
39
  let requestAnimationFrame;
40
- /* istanbul ignore else */
41
40
 
41
+ /* istanbul ignore else */
42
42
  if (canUseDOM && window.requestAnimationFrame && window.cancelAnimationFrame) {
43
43
  requestAnimationFrame = cb => {
44
44
  const id = window.requestAnimationFrame(cb);
@@ -49,7 +49,6 @@ const requestAnimationFrame = function () {
49
49
  } else {
50
50
  /* https://github.com/component/raf */
51
51
  let prev = new Date().getTime();
52
-
53
52
  requestAnimationFrame = cb => {
54
53
  const curr = new Date().getTime();
55
54
  const ms = Math.max(0, 16 - (curr - prev));
@@ -60,9 +59,7 @@ const requestAnimationFrame = function () {
60
59
  };
61
60
  };
62
61
  }
63
-
64
62
  return requestAnimationFrame;
65
63
  }();
66
-
67
64
  export default requestAnimationFrame;
68
65
  export { requestAnimationFrame };
@@ -36,15 +36,16 @@
36
36
  */
37
37
  function transformSelection(element, cleanedValue) {
38
38
  const selectionStart = element.selectionStart,
39
- selectionEnd = element.selectionEnd,
40
- selectionDirection = element.selectionDirection,
41
- value = element.value;
39
+ selectionEnd = element.selectionEnd,
40
+ selectionDirection = element.selectionDirection,
41
+ value = element.value;
42
42
  return {
43
43
  selectionStart: transformCursor(selectionStart, value, cleanedValue),
44
44
  selectionEnd: transformCursor(selectionEnd, value, cleanedValue),
45
45
  selectionDirection
46
46
  };
47
47
  }
48
+
48
49
  /**
49
50
  * Calculate the resulting cursor position
50
51
  * within a string when some characters are removed
@@ -54,29 +55,22 @@ function transformSelection(element, cleanedValue) {
54
55
  * @param {string} cleanedValue - original string with some characters removed
55
56
  * @returns {number} resulting cursor index
56
57
  */
57
-
58
-
59
58
  function transformCursor(cursorIndex, dirtyValue, cleanedValue) {
60
59
  if (dirtyValue.length === cleanedValue.length) {
61
60
  return cursorIndex;
62
61
  }
63
-
64
62
  if (cursorIndex === 0) {
65
63
  return 0;
66
64
  }
67
-
68
65
  if (cursorIndex === dirtyValue.length) {
69
66
  return cleanedValue.length;
70
67
  }
71
-
72
68
  return dirtyValue.split('').slice(0, cursorIndex).reduce((result, value) => {
73
69
  if (value === cleanedValue[result]) {
74
70
  return result + 1;
75
71
  }
76
-
77
72
  return result;
78
73
  }, 0);
79
74
  }
80
-
81
75
  export default transformSelection;
82
76
  export { transformCursor, transformSelection };
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = exports.MODES = exports.InputModeListener = void 0;
7
-
8
7
  var _console = require("@instructure/console");
9
-
10
8
  var _addEventListener = require("./addEventListener");
11
-
12
9
  var _canUseDOM = require("./canUseDOM");
13
-
14
10
  /*
15
11
  * The MIT License (MIT)
16
12
  *
@@ -34,40 +30,33 @@ var _canUseDOM = require("./canUseDOM");
34
30
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35
31
  * SOFTWARE.
36
32
  */
33
+
37
34
  const MODES = {
38
35
  keyboard: 'keyboard',
39
36
  pointer: 'pointer'
40
37
  };
41
38
  exports.MODES = MODES;
42
-
43
39
  class InputModeListenerImpl {
44
40
  constructor() {
45
41
  this._listeners = [];
46
42
  this._initialized = false;
47
43
  this._mode = MODES.keyboard;
48
-
49
44
  this.onInitialPointerMove = event => {
50
45
  var _event$target, _event$target$nodeNam;
51
-
52
46
  // Work around a Safari quirk that fires a mousemove on <html> whenever the
53
47
  // window blurs, even if you're tabbing out of the page. ¯\_(ツ)_/¯
54
48
  if ((event === null || event === void 0 ? void 0 : (_event$target = event.target) === null || _event$target === void 0 ? void 0 : (_event$target$nodeNam = _event$target.nodeName) === null || _event$target$nodeNam === void 0 ? void 0 : _event$target$nodeNam.toLowerCase()) === 'html') {
55
49
  return;
56
50
  }
57
-
58
51
  this._mode = MODES.pointer;
59
-
60
52
  this._listeners.forEach(listener => listener.remove());
61
53
  };
62
-
63
54
  this.onKeyDown = () => {
64
55
  this._mode = MODES.keyboard;
65
56
  };
66
-
67
57
  this.onPointerDown = () => {
68
58
  this._mode = MODES.pointer;
69
59
  };
70
-
71
60
  this.init = () => {
72
61
  if (!_canUseDOM.canUseDOM || this._initialized) return;
73
62
  (0, _addEventListener.addEventListener)(document, 'keydown', this.onKeyDown, true);
@@ -77,43 +66,29 @@ class InputModeListenerImpl {
77
66
  this.addInitialPointerMoveListeners();
78
67
  this._initialized = true;
79
68
  };
80
-
81
69
  (0, _console.logWarn)(false, `[InputModeListener] is deprecated and will be removed in version 7.0.0. Use addInputModeListener instead.`);
82
70
  this.init();
83
71
  }
84
-
85
72
  addInitialPointerMoveListeners() {
86
73
  this._listeners.push((0, _addEventListener.addEventListener)(document, 'mousemove', this.onInitialPointerMove, true));
87
-
88
74
  this._listeners.push((0, _addEventListener.addEventListener)(document, 'mousedown', this.onInitialPointerMove, true));
89
-
90
75
  this._listeners.push((0, _addEventListener.addEventListener)(document, 'mouseup', this.onInitialPointerMove, true));
91
-
92
76
  this._listeners.push((0, _addEventListener.addEventListener)(document, 'pointermove', this.onInitialPointerMove, true));
93
-
94
77
  this._listeners.push((0, _addEventListener.addEventListener)(document, 'pointerdown', this.onInitialPointerMove, true));
95
-
96
78
  this._listeners.push((0, _addEventListener.addEventListener)(document, 'pointerup', this.onInitialPointerMove, true));
97
-
98
79
  this._listeners.push((0, _addEventListener.addEventListener)(document, 'touchmove', this.onInitialPointerMove, true));
99
-
100
80
  this._listeners.push((0, _addEventListener.addEventListener)(document, 'touchstart', this.onInitialPointerMove, true));
101
-
102
81
  this._listeners.push((0, _addEventListener.addEventListener)(document, 'touchend', this.onInitialPointerMove, true));
103
82
  }
104
-
105
83
  get mode() {
106
84
  this.init();
107
85
  return this._mode;
108
86
  }
109
-
110
87
  isKeyboardMode() {
111
88
  this.init();
112
89
  return this._mode === MODES.keyboard;
113
90
  }
114
-
115
91
  }
116
-
117
92
  const InputModeListener = new InputModeListenerImpl();
118
93
  exports.InputModeListener = InputModeListener;
119
94
  var _default = InputModeListener;
@@ -5,9 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.addEventListener = addEventListener;
7
7
  exports.default = void 0;
8
-
9
8
  var _findDOMNode = require("./findDOMNode");
10
-
11
9
  /*
12
10
  * The MIT License (MIT)
13
11
  *
@@ -51,9 +49,7 @@ function addEventListener(el, event, handler, capture) {
51
49
  remove() {
52
50
  node === null || node === void 0 ? void 0 : node.removeEventListener(event, handler, capture);
53
51
  }
54
-
55
52
  };
56
53
  }
57
-
58
54
  var _default = addEventListener;
59
55
  exports.default = _default;