@thednp/shorty 1.0.1 → 1.0.2

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 (113) hide show
  1. package/README.md +12 -7
  2. package/dist/shorty.esm.js +379 -312
  3. package/dist/shorty.esm.min.js +2 -2
  4. package/dist/shorty.js +392 -319
  5. package/dist/shorty.min.js +2 -2
  6. package/package.json +11 -2
  7. package/src/attr/getAttribute.js +1 -1
  8. package/src/attr/getAttributeNS.js +1 -1
  9. package/src/attr/hasAttribute.js +1 -1
  10. package/src/attr/hasAttributeNS.js +1 -1
  11. package/src/attr/removeAttribute.js +1 -1
  12. package/src/attr/removeAttributeNS.js +1 -1
  13. package/src/attr/setAttribute.js +1 -1
  14. package/src/attr/setAttributeNS.js +1 -1
  15. package/src/boolean/isApple.js +2 -2
  16. package/src/boolean/isFirefox.js +2 -1
  17. package/src/boolean/isMobile.js +2 -2
  18. package/src/boolean/support3DTransform.js +2 -1
  19. package/src/boolean/supportAnimation.js +2 -1
  20. package/src/boolean/supportPassive.js +1 -1
  21. package/src/boolean/supportTouch.js +2 -1
  22. package/src/boolean/supportTransform.js +2 -1
  23. package/src/boolean/supportTransition.js +2 -1
  24. package/src/class/addClass.js +1 -1
  25. package/src/class/hasClass.js +1 -1
  26. package/src/class/removeClass.js +1 -1
  27. package/src/event/off.js +2 -6
  28. package/src/event/on.js +2 -6
  29. package/src/event/one.js +3 -6
  30. package/src/get/getBoundingClientRect.js +9 -5
  31. package/src/get/getDocument.js +8 -3
  32. package/src/get/getDocumentBody.js +2 -2
  33. package/src/get/getDocumentElement.js +2 -2
  34. package/src/get/getDocumentHead.js +2 -2
  35. package/src/get/getElementAnimationDelay.js +3 -3
  36. package/src/get/getElementAnimationDelayLegacy.js +3 -3
  37. package/src/get/getElementAnimationDuration.js +3 -3
  38. package/src/get/getElementAnimationDurationLegacy.js +3 -3
  39. package/src/get/getElementStyle.js +5 -3
  40. package/src/get/getElementTransitionDelay.js +3 -4
  41. package/src/get/getElementTransitionDelayLegacy.js +3 -3
  42. package/src/get/getElementTransitionDuration.js +3 -3
  43. package/src/get/getElementTransitionDurationLegacy.js +3 -3
  44. package/src/get/getNodeScroll.js +1 -1
  45. package/src/get/getParentNode.js +4 -5
  46. package/src/get/getRectRelativeToOffsetParent.js +7 -5
  47. package/src/get/getUID.js +1 -1
  48. package/src/get/getWindow.js +16 -7
  49. package/src/index.js +10 -6
  50. package/src/is/isArray.js +0 -1
  51. package/src/is/isCustomElement.js +1 -1
  52. package/src/is/isDocument.js +3 -2
  53. package/src/is/isElement.js +14 -1
  54. package/src/is/isElementInScrollRange.js +4 -2
  55. package/src/is/isElementInViewport.js +6 -2
  56. package/src/is/isElementsArray.js +3 -1
  57. package/src/is/isFunction.js +2 -3
  58. package/src/is/isHTMLCollection.js +1 -1
  59. package/src/is/isHTMLElement.js +2 -1
  60. package/src/is/isHTMLImageElement.js +1 -1
  61. package/src/is/isMedia.js +5 -3
  62. package/src/is/isNode.js +2 -1
  63. package/src/is/isNodeList.js +2 -1
  64. package/src/is/isNumber.js +8 -0
  65. package/src/is/isRTL.js +1 -1
  66. package/src/is/isSVGElement.js +4 -1
  67. package/src/is/isScaledElement.js +2 -0
  68. package/src/is/isShadowRoot.js +2 -5
  69. package/src/is/isString.js +2 -2
  70. package/src/is/isTableElement.js +5 -1
  71. package/src/is/isWindow.js +5 -5
  72. package/src/misc/ObjectEntries.js +7 -0
  73. package/src/misc/OriginalEvent.js +2 -1
  74. package/src/misc/createElement.js +3 -1
  75. package/src/misc/createElementNS.js +7 -3
  76. package/src/misc/data.js +16 -16
  77. package/src/misc/dispatchEvent.js +1 -1
  78. package/src/misc/emulateAnimationEnd.js +5 -2
  79. package/src/misc/emulateAnimationEndLegacy.js +9 -6
  80. package/src/misc/emulateTransitionEnd.js +5 -2
  81. package/src/misc/emulateTransitionEndLegacy.js +9 -6
  82. package/src/misc/focus.js +1 -2
  83. package/src/misc/normalizeOptions.js +2 -2
  84. package/src/misc/normalizeValue.js +8 -6
  85. package/src/misc/passiveHandlerLegacy.js +2 -1
  86. package/src/misc/reflow.js +1 -2
  87. package/src/misc/setElementStyle.js +12 -3
  88. package/src/misc/timer.js +16 -19
  89. package/src/misc/version.js +0 -1
  90. package/src/selectors/closest.js +3 -3
  91. package/src/selectors/getCustomElements.js +4 -5
  92. package/src/selectors/getElementById.js +6 -3
  93. package/src/selectors/getElementsByClassName.js +4 -3
  94. package/src/selectors/getElementsByTagName.js +4 -3
  95. package/src/selectors/matches.js +1 -1
  96. package/src/selectors/matchesLegacy.js +8 -8
  97. package/src/selectors/querySelector.js +9 -7
  98. package/src/selectors/querySelectorAll.js +4 -3
  99. package/src/strings/animationDelayLegacy.js +2 -1
  100. package/src/strings/animationDurationLegacy.js +2 -1
  101. package/src/strings/animationEndEventLegacy.js +2 -1
  102. package/src/strings/animationNameLegacy.js +2 -1
  103. package/src/strings/mouseHoverEvents.js +2 -1
  104. package/src/strings/transitionDelayLegacy.js +2 -1
  105. package/src/strings/transitionDurationLegacy.js +2 -1
  106. package/src/strings/transitionEndEventLegacy.js +2 -1
  107. package/src/strings/transitionPropertyLegacy.js +2 -2
  108. package/src/strings/userAgentData.js +0 -1
  109. package/types/index.d.ts +9 -3
  110. package/types/module/shorty.ts +2 -2
  111. package/types/shorty.d.ts +237 -224
  112. package/src/misc/tryWrapper.js +0 -11
  113. package/src/selectors/documentAll.js +0 -8
package/src/misc/data.js CHANGED
@@ -1,6 +1,6 @@
1
- import querySelector from '../selectors/querySelector';
1
+ import isHTMLElement from '../is/isHTMLElement';
2
2
 
3
- /** @type {Map<string, Map<HTMLElement | Element, Record<string, any>>>} */
3
+ /** @type {Map<string, Map<HTMLElement, Record<string, any>>>} */
4
4
  const componentData = new Map();
5
5
  /**
6
6
  * An interface for web components background data.
@@ -9,27 +9,27 @@ const componentData = new Map();
9
9
  const Data = {
10
10
  /**
11
11
  * Sets web components data.
12
- * @param {HTMLElement | Element | string} target target element
12
+ * @param {HTMLElement} element target element
13
13
  * @param {string} component the component's name or a unique key
14
14
  * @param {Record<string, any>} instance the component instance
15
15
  */
16
- set: (target, component, instance) => {
17
- const element = querySelector(target);
18
- if (!element) return;
16
+ set: (element, component, instance) => {
17
+ if (!isHTMLElement(element)) return;
19
18
 
19
+ /* istanbul ignore else */
20
20
  if (!componentData.has(component)) {
21
21
  componentData.set(component, new Map());
22
22
  }
23
23
 
24
24
  const instanceMap = componentData.get(component);
25
- // @ts-ignore - not undefined, but defined right above
25
+ // not undefined, but defined right above
26
26
  instanceMap.set(element, instance);
27
27
  },
28
28
 
29
29
  /**
30
30
  * Returns all instances for specified component.
31
31
  * @param {string} component the component's name or a unique key
32
- * @returns {Map<HTMLElement | Element, Record<string, any>>?} all the component instances
32
+ * @returns {Map<HTMLElement, Record<string, any>>?} all the component instances
33
33
  */
34
34
  getAllFor: (component) => {
35
35
  const instanceMap = componentData.get(component);
@@ -39,12 +39,12 @@ const Data = {
39
39
 
40
40
  /**
41
41
  * Returns the instance associated with the target.
42
- * @param {HTMLElement | Element | string} target target element
42
+ * @param {HTMLElement} element target element
43
43
  * @param {string} component the component's name or a unique key
44
44
  * @returns {Record<string, any>?} the instance
45
45
  */
46
- get: (target, component) => {
47
- const element = querySelector(target);
46
+ get: (element, component) => {
47
+ if (!isHTMLElement(element) || !component) return null;
48
48
  const allForC = Data.getAllFor(component);
49
49
  const instance = element && allForC && allForC.get(element);
50
50
 
@@ -53,16 +53,16 @@ const Data = {
53
53
 
54
54
  /**
55
55
  * Removes web components data.
56
- * @param {HTMLElement | Element | string} target target element
56
+ * @param {HTMLElement} element target element
57
57
  * @param {string} component the component's name or a unique key
58
58
  */
59
- remove: (target, component) => {
60
- const element = querySelector(target);
59
+ remove: (element, component) => {
61
60
  const instanceMap = componentData.get(component);
62
- if (!instanceMap || !element) return;
61
+ if (!instanceMap || !isHTMLElement(element)) return;
63
62
 
64
63
  instanceMap.delete(element);
65
64
 
65
+ /* istanbul ignore else */
66
66
  if (instanceMap.size === 0) {
67
67
  componentData.delete(component);
68
68
  }
@@ -71,7 +71,7 @@ const Data = {
71
71
 
72
72
  /**
73
73
  * An alias for `Data.get()`.
74
- * @type {SHORTER.getInstance<any>}
74
+ * @type {SHORTY.getInstance<any>}
75
75
  */
76
76
  export const getInstance = (target, component) => Data.get(target, component);
77
77
 
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Shortcut for the `Element.dispatchEvent(Event)` method.
3
3
  *
4
- * @param {HTMLElement | Element} element is the target
4
+ * @param {HTMLElement} element is the target
5
5
  * @param {Event} event is the `Event` object
6
6
  */
7
7
  const dispatchEvent = (element, event) => element.dispatchEvent(event);
@@ -1,12 +1,13 @@
1
1
  import animationEndEvent from '../strings/animationEndEvent';
2
2
  import getElementAnimationDelay from '../get/getElementAnimationDelay';
3
3
  import getElementAnimationDuration from '../get/getElementAnimationDuration';
4
+ import dispatchEvent from './dispatchEvent';
4
5
 
5
6
  /**
6
7
  * Utility to make sure callbacks are consistently
7
8
  * called when animation ends.
8
9
  *
9
- * @param {HTMLElement | Element} element target
10
+ * @param {HTMLElement} element target
10
11
  * @param {EventListener} handler `animationend` callback
11
12
  */
12
13
  export default function emulateAnimationEnd(element, handler) {
@@ -21,6 +22,7 @@ export default function emulateAnimationEnd(element, handler) {
21
22
  * @type {EventListener}
22
23
  */
23
24
  const animationEndWrapper = (e) => {
25
+ /* istanbul ignore else */
24
26
  if (e.target === element) {
25
27
  handler.apply(element, [e]);
26
28
  element.removeEventListener(animationEndEvent, animationEndWrapper);
@@ -29,7 +31,8 @@ export default function emulateAnimationEnd(element, handler) {
29
31
  };
30
32
  element.addEventListener(animationEndEvent, animationEndWrapper);
31
33
  setTimeout(() => {
32
- if (!called) element.dispatchEvent(endEvent);
34
+ /* istanbul ignore next */
35
+ if (!called) dispatchEvent(element, endEvent);
33
36
  }, duration + delay + 17);
34
37
  } else {
35
38
  handler.apply(element, [endEvent]);
@@ -1,18 +1,19 @@
1
1
  import supportAnimation from '../boolean/supportAnimation';
2
- import animationEndEvent from '../strings/animationEndEventLegacy';
2
+ import animationEndEventLegacy from '../strings/animationEndEventLegacy';
3
3
  import getElementAnimationDelay from '../get/getElementAnimationDelayLegacy';
4
4
  import getElementAnimationDuration from '../get/getElementAnimationDurationLegacy';
5
+ import dispatchEvent from './dispatchEvent';
5
6
 
6
7
  /**
7
8
  * Utility to make sure callbacks are consistently
8
9
  * called when animation ends.
9
10
  *
10
- * @param {HTMLElement | Element} element target
11
+ * @param {HTMLElement} element target
11
12
  * @param {EventListener} handler `animationend` callback
12
13
  */
13
14
  export default function emulateAnimationEnd(element, handler) {
14
15
  let called = 0;
15
- const endEvent = new Event(animationEndEvent);
16
+ const endEvent = new Event(animationEndEventLegacy);
16
17
  const duration = getElementAnimationDuration(element);
17
18
  const delay = getElementAnimationDelay(element);
18
19
 
@@ -22,15 +23,17 @@ export default function emulateAnimationEnd(element, handler) {
22
23
  * @param {Event} e Event object
23
24
  */
24
25
  const animationEndWrapper = (e) => {
26
+ /* istanbul ignore else */
25
27
  if (e.target === element) {
26
28
  handler.apply(element, [e]);
27
- element.removeEventListener(animationEndEvent, animationEndWrapper);
29
+ element.removeEventListener(animationEndEventLegacy, animationEndWrapper);
28
30
  called = 1;
29
31
  }
30
32
  };
31
- element.addEventListener(animationEndEvent, animationEndWrapper);
33
+ element.addEventListener(animationEndEventLegacy, animationEndWrapper);
32
34
  setTimeout(() => {
33
- if (!called) element.dispatchEvent(endEvent);
35
+ /* istanbul ignore next */
36
+ if (!called) dispatchEvent(element, endEvent);
34
37
  }, duration + delay + 17);
35
38
  } else {
36
39
  handler.apply(element, [endEvent]);
@@ -1,12 +1,13 @@
1
1
  import transitionEndEvent from '../strings/transitionEndEvent';
2
2
  import getElementTransitionDelay from '../get/getElementTransitionDelay';
3
3
  import getElementTransitionDuration from '../get/getElementTransitionDuration';
4
+ import dispatchEvent from './dispatchEvent';
4
5
 
5
6
  /**
6
7
  * Utility to make sure callbacks are consistently
7
8
  * called when transition ends.
8
9
  *
9
- * @param {HTMLElement | Element} element target
10
+ * @param {HTMLElement} element target
10
11
  * @param {EventListener} handler `transitionend` callback
11
12
  */
12
13
  export default function emulateTransitionEnd(element, handler) {
@@ -21,6 +22,7 @@ export default function emulateTransitionEnd(element, handler) {
21
22
  * @type {EventListener} e Event object
22
23
  */
23
24
  const transitionEndWrapper = (e) => {
25
+ /* istanbul ignore else */
24
26
  if (e.target === element) {
25
27
  handler.apply(element, [e]);
26
28
  element.removeEventListener(transitionEndEvent, transitionEndWrapper);
@@ -29,7 +31,8 @@ export default function emulateTransitionEnd(element, handler) {
29
31
  };
30
32
  element.addEventListener(transitionEndEvent, transitionEndWrapper);
31
33
  setTimeout(() => {
32
- if (!called) element.dispatchEvent(endEvent);
34
+ /* istanbul ignore next */
35
+ if (!called) dispatchEvent(element, endEvent);
33
36
  }, duration + delay + 17);
34
37
  } else {
35
38
  handler.apply(element, [endEvent]);
@@ -1,18 +1,19 @@
1
1
  import supportTransition from '../boolean/supportTransition';
2
- import transitionEndEvent from '../strings/transitionEndEventLegacy';
2
+ import transitionEndEventLegacy from '../strings/transitionEndEventLegacy';
3
3
  import getElementTransitionDelay from '../get/getElementTransitionDelayLegacy';
4
4
  import getElementTransitionDuration from '../get/getElementTransitionDurationLegacy';
5
+ import dispatchEvent from './dispatchEvent';
5
6
 
6
7
  /**
7
8
  * Utility to make sure callbacks are consistently
8
9
  * called when transition ends.
9
10
  *
10
- * @param {HTMLElement | Element} element target
11
+ * @param {HTMLElement} element target
11
12
  * @param {EventListener} handler `transitionend` callback
12
13
  */
13
14
  export default function emulateTransitionEnd(element, handler) {
14
15
  let called = 0;
15
- const endEvent = new Event(transitionEndEvent);
16
+ const endEvent = new Event(transitionEndEventLegacy);
16
17
  const duration = getElementTransitionDuration(element);
17
18
  const delay = getElementTransitionDelay(element);
18
19
 
@@ -22,15 +23,17 @@ export default function emulateTransitionEnd(element, handler) {
22
23
  * @param {Event} e Event object
23
24
  */
24
25
  const transitionEndWrapper = (e) => {
26
+ /* istanbul ignore else */
25
27
  if (e.target === element) {
26
28
  handler.apply(element, [e]);
27
- element.removeEventListener(transitionEndEvent, transitionEndWrapper);
29
+ element.removeEventListener(transitionEndEventLegacy, transitionEndWrapper);
28
30
  called = 1;
29
31
  }
30
32
  };
31
- element.addEventListener(transitionEndEvent, transitionEndWrapper);
33
+ element.addEventListener(transitionEndEventLegacy, transitionEndWrapper);
32
34
  setTimeout(() => {
33
- if (!called) element.dispatchEvent(endEvent);
35
+ /* istanbul ignore next */
36
+ if (!called) dispatchEvent(element, endEvent);
34
37
  }, duration + delay + 17);
35
38
  } else {
36
39
  handler.apply(element, [endEvent]);
package/src/misc/focus.js CHANGED
@@ -1,8 +1,7 @@
1
1
  /**
2
2
  * Utility to focus an `HTMLElement` target.
3
3
  *
4
- * @param {HTMLElement | Element} element is the target
4
+ * @param {HTMLElement} element is the target
5
5
  */
6
- // @ts-ignore -- `Element`s resulted from querySelector can focus too
7
6
  const focus = (element) => element.focus();
8
7
  export default focus;
@@ -6,14 +6,13 @@ import toLowerCase from './toLowerCase';
6
6
  /**
7
7
  * Utility to normalize component options.
8
8
  *
9
- * @param {HTMLElement | Element} element target
9
+ * @param {HTMLElement} element target
10
10
  * @param {Record<string, any>} defaultOps component default options
11
11
  * @param {Record<string, any>} inputOps component instance options
12
12
  * @param {string=} ns component namespace
13
13
  * @return {Record<string, any>} normalized component options object
14
14
  */
15
15
  export default function normalizeOptions(element, defaultOps, inputOps, ns) {
16
- // @ts-ignore -- our targets are always `HTMLElement`
17
16
  const data = { ...element.dataset };
18
17
  /** @type {Record<string, any>} */
19
18
  const normalOps = {};
@@ -34,6 +33,7 @@ export default function normalizeOptions(element, defaultOps, inputOps, ns) {
34
33
  });
35
34
 
36
35
  ObjectKeys(defaultOps).forEach((k) => {
36
+ /* istanbul ignore else */
37
37
  if (k in inputOps) {
38
38
  normalOps[k] = inputOps[k];
39
39
  } else if (k in dataOps) {
@@ -11,22 +11,24 @@
11
11
  * @return {niceValue} the normalized value
12
12
  */
13
13
  export default function normalizeValue(value) {
14
- if (value === 'true') { // boolean
14
+ if (['true', true].includes(value)) { // boolean
15
+ // if ('true' === value) { // boolean
15
16
  return true;
16
17
  }
17
18
 
18
- if (value === 'false') { // boolean
19
+ if (['false', false].includes(value)) { // boolean
20
+ // if ('false' === value) { // boolean
19
21
  return false;
20
22
  }
21
23
 
22
- if (!Number.isNaN(+value)) { // number
23
- return +value;
24
- }
25
-
26
24
  if (value === '' || value === 'null') { // null
27
25
  return null;
28
26
  }
29
27
 
28
+ if (value !== '' && !Number.isNaN(+value)) { // number
29
+ return +value;
30
+ }
31
+
30
32
  // string / function / HTMLElement / object
31
33
  return value;
32
34
  }
@@ -4,6 +4,7 @@ import supportPassive from '../boolean/supportPassive';
4
4
  * A global namespace for most scroll event listeners in legacy browsers.
5
5
  * @type {Partial<AddEventListenerOptions> | boolean}
6
6
  */
7
- const passiveHandler = supportPassive ? { passive: true } : false;
7
+ const passiveHandler = supportPassive ? { passive: true }
8
+ : /* istanbul ignore next */false;
8
9
 
9
10
  export default passiveHandler;
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * Utility to force re-paint of an `HTMLElement` target.
3
3
  *
4
- * @param {HTMLElement | Element} element is the target
4
+ * @param {HTMLElement} element is the target
5
5
  * @return {number} the `Element.offsetHeight` value
6
6
  */
7
- // @ts-ignore
8
7
  const reflow = (element) => element.offsetHeight;
9
8
  export default reflow;
@@ -1,10 +1,19 @@
1
1
  import ObjectAssign from './ObjectAssign';
2
+ import ObjectEntries from './ObjectEntries';
2
3
 
3
4
  /**
4
5
  * Shortcut for multiple uses of `HTMLElement.style.propertyName` method.
5
- * @param {HTMLElement | Element} element target element
6
+ * @param {HTMLElement} element target element
6
7
  * @param {Partial<CSSStyleDeclaration>} styles attribute value
7
8
  */
8
- // @ts-ignore
9
- const setElementStyle = (element, styles) => { ObjectAssign(element.style, styles); };
9
+ const setElementStyle = (element, styles) => {
10
+ ObjectEntries(styles).forEach(([key, value]) => {
11
+ if (key.includes('--')) {
12
+ element.style.setProperty(key, value);
13
+ } else {
14
+ const propObject = {}; propObject[key] = value;
15
+ ObjectAssign(element.style, propObject);
16
+ }
17
+ });
18
+ };
10
19
  export default setElementStyle;
package/src/misc/timer.js CHANGED
@@ -1,6 +1,6 @@
1
- import querySelector from '../selectors/querySelector';
1
+ import isHTMLElement from '../is/isHTMLElement';
2
2
 
3
- /** @type {Map<HTMLElement | Element, any>} */
3
+ /** @type {Map<HTMLElement, any>} */
4
4
  const TimeCache = new Map();
5
5
  /**
6
6
  * An interface for one or more `TimerHandler`s per `Element`.
@@ -9,17 +9,17 @@ const TimeCache = new Map();
9
9
  const Timer = {
10
10
  /**
11
11
  * Sets a new timeout timer for an element, or element -> key association.
12
- * @param {HTMLElement | Element | string} target target element
12
+ * @param {HTMLElement} element target element
13
13
  * @param {ReturnType<TimerHandler>} callback the callback
14
14
  * @param {number} delay the execution delay
15
15
  * @param {string=} key a unique key
16
16
  */
17
- set: (target, callback, delay, key) => {
18
- const element = querySelector(target);
19
-
20
- if (!element) return;
17
+ set: (element, callback, delay, key) => {
18
+ if (!isHTMLElement(element)) return;
21
19
 
20
+ /* istanbul ignore else */
22
21
  if (key && key.length) {
22
+ /* istanbul ignore else */
23
23
  if (!TimeCache.has(element)) {
24
24
  TimeCache.set(element, new Map());
25
25
  }
@@ -32,38 +32,35 @@ const Timer = {
32
32
 
33
33
  /**
34
34
  * Returns the timer associated with the target.
35
- * @param {HTMLElement | Element | string} target target element
35
+ * @param {HTMLElement} element target element
36
36
  * @param {string=} key a unique
37
37
  * @returns {number?} the timer
38
38
  */
39
- get: (target, key) => {
40
- const element = querySelector(target);
41
-
42
- if (!element) return null;
39
+ get: (element, key) => {
40
+ if (!isHTMLElement(element)) return null;
43
41
  const keyTimers = TimeCache.get(element);
44
42
 
45
43
  if (key && key.length && keyTimers && keyTimers.get) {
46
- return keyTimers.get(key) || null;
44
+ return keyTimers.get(key) || /* istanbul ignore next */null;
47
45
  }
48
46
  return keyTimers || null;
49
47
  },
50
48
 
51
49
  /**
52
50
  * Clears the element's timer.
53
- * @param {HTMLElement | Element | string} target target element
51
+ * @param {HTMLElement} element target element
54
52
  * @param {string=} key a unique key
55
53
  */
56
- clear: (target, key) => {
57
- const element = querySelector(target);
58
-
59
- if (!element) return;
54
+ clear: (element, key) => {
55
+ if (!isHTMLElement(element)) return;
60
56
 
61
57
  if (key && key.length) {
62
58
  const keyTimers = TimeCache.get(element);
63
-
59
+ /* istanbul ignore else */
64
60
  if (keyTimers && keyTimers.get) {
65
61
  clearTimeout(keyTimers.get(key));
66
62
  keyTimers.delete(key);
63
+ /* istanbul ignore else */
67
64
  if (keyTimers.size === 0) {
68
65
  TimeCache.delete(element);
69
66
  }
@@ -1,4 +1,3 @@
1
- // @ts-ignore
2
1
  import { version } from '../../package.json';
3
2
 
4
3
  /**
@@ -5,12 +5,12 @@
5
5
  *
6
6
  * @see https://stackoverflow.com/q/54520554/803358
7
7
  *
8
- * @param {HTMLElement | Element} element Element to look into
8
+ * @param {HTMLElement} element Element to look into
9
9
  * @param {string} selector the selector name
10
- * @return {(HTMLElement | Element)?} the query result
10
+ * @return {HTMLElement?} the query result
11
11
  */
12
12
  export default function closest(element, selector) {
13
13
  return element ? (element.closest(selector)
14
- // @ts-ignore -- break out of `ShadowRoot`
14
+ // break out of `ShadowRoot`
15
15
  || closest(element.getRootNode().host, selector)) : null;
16
16
  }
@@ -1,4 +1,3 @@
1
- import documentAll from './documentAll';
2
1
  import isCustomElement from '../is/isCustomElement';
3
2
  import getElementsByTagName from './getElementsByTagName';
4
3
 
@@ -7,11 +6,11 @@ import getElementsByTagName from './getElementsByTagName';
7
6
  * `CustomElement`.
8
7
  * @see https://stackoverflow.com/questions/27334365/how-to-get-list-of-registered-custom-elements
9
8
  *
10
- * @param {(HTMLElement | Element | Node | Document)=} parent parent to look into
11
- * @returns {Array<HTMLElement | Element>} the query result
9
+ * @param {ParentNode=} parent parent to look into
10
+ * @returns {Array<HTMLElement>} the query result
12
11
  */
13
12
  export default function getCustomElements(parent) {
14
- const collection = parent && typeof parent === 'object'
15
- ? getElementsByTagName('*', parent) : documentAll;
13
+ const collection = getElementsByTagName('*', parent);
14
+
16
15
  return [...collection].filter(isCustomElement);
17
16
  }
@@ -2,10 +2,13 @@ import getDocument from '../get/getDocument';
2
2
 
3
3
  /**
4
4
  * Returns an `Element` that matches the id in the document.
5
+ * Within multiple <iframe> elements, a `parent` parameter
6
+ * would decisively locate the correct element.
5
7
  *
6
8
  * @param {string} id
7
- * @returns {(HTMLElement | Element)?}
9
+ * @param {ParentNode=} context
10
+ * @returns {HTMLElement?}
8
11
  */
9
- export default function getElementById(id) {
10
- return getDocument().getElementById(id);
12
+ export default function getElementById(id, context) {
13
+ return getDocument(context).getElementById(id);
11
14
  }
@@ -1,14 +1,15 @@
1
1
  import getDocument from '../get/getDocument';
2
+ import isNode from '../is/isNode';
2
3
 
3
4
  /**
4
5
  * Shortcut for `HTMLElement.getElementsByClassName` method. Some `Node` elements
5
6
  * like `ShadowRoot` do not support `getElementsByClassName`.
6
7
  *
7
8
  * @param {string} selector the class name
8
- * @param {(HTMLElement | Element | Document)=} parent optional Element to look into
9
- * @return {HTMLCollectionOf<HTMLElement | Element>} the 'HTMLCollection'
9
+ * @param {ParentNode=} parent optional Element to look into
10
+ * @return {HTMLCollectionOf<HTMLElement>} the 'HTMLCollection'
10
11
  */
11
12
  export default function getElementsByClassName(selector, parent) {
12
- const lookUp = typeof parent !== 'object' ? getDocument() : parent;
13
+ const lookUp = isNode(parent) ? parent : getDocument();
13
14
  return lookUp.getElementsByClassName(selector);
14
15
  }
@@ -1,14 +1,15 @@
1
1
  import getDocument from '../get/getDocument';
2
+ import isNode from '../is/isNode';
2
3
 
3
4
  /**
4
5
  * Shortcut for `HTMLElement.getElementsByTagName` method. Some `Node` elements
5
6
  * like `ShadowRoot` do not support `getElementsByTagName`.
6
7
  *
7
8
  * @param {string} selector the tag name
8
- * @param {(HTMLElement | Element | Document)=} parent optional Element to look into
9
- * @return {HTMLCollectionOf<HTMLElement | Element>} the 'HTMLCollection'
9
+ * @param {ParentNode=} parent optional Element to look into
10
+ * @return {HTMLCollectionOf<HTMLElement>} the 'HTMLCollection'
10
11
  */
11
12
  export default function getElementsByTagName(selector, parent) {
12
- const lookUp = typeof parent !== 'object' ? getDocument() : parent;
13
+ const lookUp = isNode(parent) ? parent : getDocument();
13
14
  return lookUp.getElementsByTagName(selector);
14
15
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Check if element matches a CSS selector.
3
3
  *
4
- * @param {HTMLElement | Element} target
4
+ * @param {HTMLElement} target
5
5
  * @param {string} selector
6
6
  * @returns {boolean}
7
7
  */
@@ -1,12 +1,12 @@
1
- // @ts-nocheck
2
1
  const ElementProto = Element.prototype;
2
+
3
3
  const matchesFn = ElementProto.matches
4
- || ElementProto.matchesSelector
5
- || ElementProto.webkitMatchesSelector
6
- || ElementProto.mozMatchesSelector
7
- || ElementProto.msMatchesSelector
8
- || ElementProto.oMatchesSelector
9
- || function matchesNotSupported() {
4
+ || /* istanbul ignore next */ ElementProto.matchesSelector
5
+ || /* istanbul ignore next */ ElementProto.webkitMatchesSelector
6
+ || /* istanbul ignore next */ ElementProto.mozMatchesSelector
7
+ || /* istanbul ignore next */ ElementProto.msMatchesSelector
8
+ || /* istanbul ignore next */ ElementProto.oMatchesSelector
9
+ || /* istanbul ignore next */ function matchesNotSupported() {
10
10
  return false;
11
11
  };
12
12
 
@@ -14,7 +14,7 @@ const matchesFn = ElementProto.matches
14
14
  * Check if element matches a CSS selector,
15
15
  * supporting a range of legacy browsers.
16
16
  *
17
- * @param {HTMLElement | Element} target
17
+ * @param {HTMLElement} target
18
18
  * @param {string} selector
19
19
  * @returns {boolean}
20
20
  */
@@ -1,17 +1,19 @@
1
1
  import getDocument from '../get/getDocument';
2
+ import isNode from '../is/isNode';
2
3
 
3
4
  /**
4
5
  * Utility to check if target is typeof `HTMLElement`, `Element`, `Node`
5
6
  * or find one that matches a selector.
6
7
  *
7
- * @param {Node | HTMLElement | Element | string} selector the input selector or target element
8
- * @param {(Node | HTMLElement | Element | Document)=} parent optional node to look into
9
- * @return {(HTMLElement | Element)?} the `HTMLElement` or `querySelector` result
8
+ * @param {Node | string} selector the input selector or target element
9
+ * @param {ParentNode=} parent optional node to look into
10
+ * @return {HTMLElement?} the `HTMLElement` or `querySelector` result
10
11
  */
11
12
  export default function querySelector(selector, parent) {
12
- if (typeof selector === 'string') {
13
- const lookUp = typeof parent !== 'object' ? getDocument() : parent;
14
- return lookUp.querySelector(selector);
13
+ if (isNode(selector)) {
14
+ return selector;
15
15
  }
16
- return selector;
16
+ const lookUp = isNode(parent) ? parent : getDocument();
17
+
18
+ return lookUp.querySelector(selector);
17
19
  }
@@ -1,13 +1,14 @@
1
1
  import getDocument from '../get/getDocument';
2
+ import isNode from '../is/isNode';
2
3
 
3
4
  /**
4
5
  * A shortcut for `(document|Element).querySelectorAll`.
5
6
  *
6
7
  * @param {string} selector the input selector
7
- * @param {(HTMLElement | Element | Document | Node)=} parent optional node to look into
8
- * @return {NodeListOf<HTMLElement | Element>} the query result
8
+ * @param {ParentNode=} parent optional node to look into
9
+ * @return {NodeListOf<HTMLElement>} the query result
9
10
  */
10
11
  export default function querySelectorAll(selector, parent) {
11
- const lookUp = typeof parent !== 'object' ? getDocument() : parent;
12
+ const lookUp = isNode(parent) ? parent : getDocument();
12
13
  return lookUp.querySelectorAll(selector);
13
14
  }
@@ -4,5 +4,6 @@ import documentHead from '../blocks/documentHead';
4
4
  * A global namespace for 'animationDelay' string.
5
5
  * @type {string}
6
6
  */
7
- const animationDelay = 'webkitAnimation' in documentHead.style ? 'webkitAnimationDelay' : 'animationDelay';
7
+ const animationDelay = 'webkitAnimation' in documentHead.style ? 'webkitAnimationDelay'
8
+ : /* istanbul ignore next */'animationDelay';
8
9
  export default animationDelay;
@@ -4,5 +4,6 @@ import documentHead from '../blocks/documentHead';
4
4
  * A global namespace for 'animationDuration' string.
5
5
  * @type {string}
6
6
  */
7
- const animationDuration = 'webkitAnimation' in documentHead.style ? 'webkitAnimationDuration' : 'animationDuration';
7
+ const animationDuration = 'webkitAnimation' in documentHead.style ? 'webkitAnimationDuration'
8
+ : /* istanbul ignore next */'animationDuration';
8
9
  export default animationDuration;