@koine/dom 2.0.0-beta.1 → 2.0.0-beta.4

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 (109) hide show
  1. package/$$.d.ts +1 -1
  2. package/$$.js +19 -6
  3. package/$$.mjs +1 -2
  4. package/$.d.ts +1 -1
  5. package/$.js +19 -6
  6. package/$.mjs +1 -2
  7. package/$each.js +22 -17
  8. package/$each.mjs +3 -4
  9. package/_listen-delegation.d.ts +3 -2
  10. package/_listen-delegation.js +42 -49
  11. package/_listen-delegation.mjs +17 -23
  12. package/addClass.js +21 -10
  13. package/addClass.mjs +2 -5
  14. package/calculateFixedOffset.js +22 -9
  15. package/calculateFixedOffset.mjs +3 -4
  16. package/createElement.js +22 -15
  17. package/createElement.mjs +2 -3
  18. package/emitEvent.js +22 -12
  19. package/emitEvent.mjs +3 -7
  20. package/escapeSelector.js +19 -6
  21. package/escapeSelector.mjs +1 -2
  22. package/exists.js +19 -6
  23. package/exists.mjs +1 -2
  24. package/forEach.d.ts +4 -5
  25. package/forEach.js +22 -11
  26. package/forEach.mjs +4 -7
  27. package/getDataAttr.js +19 -6
  28. package/getDataAttr.mjs +1 -2
  29. package/getDocumentHeight.js +20 -7
  30. package/getDocumentHeight.mjs +2 -3
  31. package/getHeight.js +19 -6
  32. package/getHeight.mjs +1 -2
  33. package/getListeners.d.ts +1 -1
  34. package/getListeners.js +23 -16
  35. package/getListeners.mjs +4 -5
  36. package/getOffset.js +26 -10
  37. package/getOffset.mjs +8 -6
  38. package/getOffsetTop.js +21 -8
  39. package/getOffsetTop.mjs +3 -4
  40. package/getOffsetTopSlim.js +19 -6
  41. package/getOffsetTopSlim.mjs +1 -2
  42. package/getScrollbarWidth.js +19 -6
  43. package/getScrollbarWidth.mjs +1 -2
  44. package/getStyleValue.js +19 -6
  45. package/getStyleValue.mjs +1 -2
  46. package/getVisualBackgroundColor.js +26 -14
  47. package/getVisualBackgroundColor.mjs +8 -10
  48. package/index.js +191 -92
  49. package/injectCss.js +21 -10
  50. package/injectCss.mjs +2 -5
  51. package/isHidden.js +19 -6
  52. package/isHidden.mjs +1 -2
  53. package/isInViewport.js +21 -13
  54. package/isInViewport.mjs +3 -9
  55. package/isNodeList.js +21 -12
  56. package/isNodeList.mjs +3 -8
  57. package/isTotallyScrolled.js +19 -6
  58. package/isTotallyScrolled.mjs +1 -2
  59. package/listen.d.ts +2 -1
  60. package/listen.js +33 -25
  61. package/listen.mjs +11 -8
  62. package/listenLoaded.js +21 -12
  63. package/listenLoaded.mjs +2 -3
  64. package/listenOnce.js +24 -19
  65. package/listenOnce.mjs +2 -3
  66. package/listenResize.js +20 -11
  67. package/listenResize.mjs +1 -2
  68. package/listenResizeDebounced.js +48 -45
  69. package/listenResizeDebounced.mjs +28 -36
  70. package/listenResizeThrottled.js +21 -18
  71. package/listenResizeThrottled.mjs +1 -8
  72. package/listenScroll.js +21 -14
  73. package/listenScroll.mjs +2 -5
  74. package/listenScrollDebounced.js +21 -18
  75. package/listenScrollDebounced.mjs +1 -8
  76. package/listenScrollThrottled.js +21 -18
  77. package/listenScrollThrottled.mjs +1 -8
  78. package/off.d.ts +2 -2
  79. package/off.js +20 -11
  80. package/off.mjs +2 -5
  81. package/on.d.ts +2 -2
  82. package/on.js +25 -15
  83. package/on.mjs +5 -5
  84. package/onClickOutside.js +16 -12
  85. package/onClickOutside.mjs +5 -7
  86. package/once.js +25 -16
  87. package/once.mjs +3 -5
  88. package/package.json +14 -5
  89. package/removeClass.js +22 -11
  90. package/removeClass.mjs +3 -6
  91. package/scrollTo.js +31 -27
  92. package/scrollTo.mjs +13 -14
  93. package/setDataAttr.js +19 -6
  94. package/setDataAttr.mjs +1 -2
  95. package/setVendorCSS.js +20 -7
  96. package/setVendorCSS.mjs +2 -3
  97. package/siblings.js +22 -9
  98. package/siblings.mjs +4 -5
  99. package/toArray.js +19 -6
  100. package/toArray.mjs +1 -2
  101. package/types.d.ts +5 -0
  102. package/types.js +3 -1
  103. package/types.mjs +1 -1
  104. package/unlisten.d.ts +2 -1
  105. package/unlisten.js +34 -26
  106. package/unlisten.mjs +11 -9
  107. package/getVisualBackground.d.ts +0 -6
  108. package/getVisualBackground.js +0 -25
  109. package/getVisualBackground.mjs +0 -21
package/setVendorCSS.mjs CHANGED
@@ -4,9 +4,8 @@
4
4
  * @param element A single HTMLElement
5
5
  * @param prop CSS rule proerty
6
6
  * @param value The CSS value to set, it will be automatically vendor prefixed
7
- */
8
- export function setVendorCSS(element, prop, value) {
9
- var propUpper = prop.charAt(0).toUpperCase() + prop.slice(1);
7
+ */ export function setVendorCSS(element, prop, value) {
8
+ const propUpper = prop.charAt(0).toUpperCase() + prop.slice(1);
10
9
  // @ts-expect-error nevermind now...
11
10
  element.style["webkit" + propUpper] = value;
12
11
  // @ts-expect-error nevermind now...
package/siblings.js CHANGED
@@ -1,16 +1,30 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.siblings = void 0;
4
1
  /**
5
2
  * Finds siblings nodes of the passed node.
6
3
  *
7
4
  * @borrows @glidejs/glide/src/utils/dom (source)
8
- */
5
+ */ "use strict";
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ function _export(target, all) {
10
+ for(var name in all)Object.defineProperty(target, name, {
11
+ enumerable: true,
12
+ get: all[name]
13
+ });
14
+ }
15
+ _export(exports, {
16
+ siblings: function() {
17
+ return siblings;
18
+ },
19
+ default: function() {
20
+ return _default;
21
+ }
22
+ });
9
23
  function siblings(node) {
10
24
  if (node && node.parentNode) {
11
- var n = node.parentNode.firstChild;
12
- var matched = [];
13
- for (; n; n = n.nextSibling) {
25
+ let n = node.parentNode.firstChild;
26
+ const matched = [];
27
+ for(; n; n = n.nextSibling){
14
28
  if (n.nodeType === 1 && n !== node) {
15
29
  matched.push(n);
16
30
  }
@@ -19,5 +33,4 @@ function siblings(node) {
19
33
  }
20
34
  return [];
21
35
  }
22
- exports.siblings = siblings;
23
- exports.default = siblings;
36
+ const _default = siblings;
package/siblings.mjs CHANGED
@@ -2,12 +2,11 @@
2
2
  * Finds siblings nodes of the passed node.
3
3
  *
4
4
  * @borrows @glidejs/glide/src/utils/dom (source)
5
- */
6
- export function siblings(node) {
5
+ */ export function siblings(node) {
7
6
  if (node && node.parentNode) {
8
- var n = node.parentNode.firstChild;
9
- var matched = [];
10
- for (; n; n = n.nextSibling) {
7
+ let n = node.parentNode.firstChild;
8
+ const matched = [];
9
+ for(; n; n = n.nextSibling){
11
10
  if (n.nodeType === 1 && n !== node) {
12
11
  matched.push(n);
13
12
  }
package/toArray.js CHANGED
@@ -1,13 +1,26 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toArray = void 0;
4
1
  /**
5
2
  * Node list to array
6
3
  *
7
4
  * @param nodeList
8
- */
5
+ */ "use strict";
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ function _export(target, all) {
10
+ for(var name in all)Object.defineProperty(target, name, {
11
+ enumerable: true,
12
+ get: all[name]
13
+ });
14
+ }
15
+ _export(exports, {
16
+ toArray: function() {
17
+ return toArray;
18
+ },
19
+ default: function() {
20
+ return _default;
21
+ }
22
+ });
9
23
  function toArray(nodeList) {
10
24
  return Array.prototype.slice.call(nodeList);
11
25
  }
12
- exports.toArray = toArray;
13
- exports.default = toArray;
26
+ const _default = toArray;
package/toArray.mjs CHANGED
@@ -2,8 +2,7 @@
2
2
  * Node list to array
3
3
  *
4
4
  * @param nodeList
5
- */
6
- export function toArray(nodeList) {
5
+ */ export function toArray(nodeList) {
7
6
  return Array.prototype.slice.call(nodeList);
8
7
  }
9
8
  export default toArray;
package/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { LiteralUnion } from "type-fest";
1
2
  import type { AnythingFalsy } from "@koine/utils/types";
2
3
  export type AnyDOMEventTarget = Window | Document | HTMLElement | Element;
3
4
  /**
@@ -5,3 +6,7 @@ export type AnyDOMEventTarget = Window | Document | HTMLElement | Element;
5
6
  * to `window` in case of _scroll_ or _resize_ events
6
7
  */
7
8
  export type AnyDOMEventTargetLoose = AnyDOMEventTarget | AnythingFalsy;
9
+ type StandardDOMEventTypes = keyof GlobalEventHandlersEventMap;
10
+ export type AnyDOMEventType = LiteralUnion<StandardDOMEventTypes | "storage" | "popstate", string>;
11
+ export type AnyDOMEvent<TType extends AnyDOMEventType> = TType extends StandardDOMEventTypes ? GlobalEventHandlersEventMap[TType] : TType extends "storage" ? StorageEvent : TType extends "popstate" ? PopStateEvent : Event;
12
+ export {};
package/types.js CHANGED
@@ -1,2 +1,4 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
package/types.mjs CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export { };
package/unlisten.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { type EventCallback } from "./_listen-delegation";
2
+ import type { AnyDOMEventTarget, AnyDOMEventType } from "./types";
2
3
  /**
3
4
  * Stop listening for an event
4
5
  *
@@ -8,5 +9,5 @@ import { type EventCallback } from "./_listen-delegation";
8
9
  * @param selector The selector to remove the event from
9
10
  * @param callback The function to remove
10
11
  */
11
- export declare function unlisten(types: string, selector: string, callback: EventCallback): void;
12
+ export declare function unlisten<TTypes extends AnyDOMEventType, TTarget extends AnyDOMEventTarget = AnyDOMEventTarget>(types: TTypes, selector: string, callback: EventCallback<TTarget, TTypes>): void;
12
13
  export default unlisten;
package/unlisten.js CHANGED
@@ -1,37 +1,45 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.unlisten = void 0;
4
- var _listen_delegation_1 = require("./_listen-delegation");
5
- var off_1 = require("./off");
6
- /**
7
- * Stop listening for an event
8
- *
9
- * @category listen-delegation
10
- *
11
- * @param types The event type or types (comma separated)
12
- * @param selector The selector to remove the event from
13
- * @param callback The function to remove
14
- */
15
- function unlisten(types, selector, callback) {
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ unlisten: function() {
13
+ return unlisten;
14
+ },
15
+ default: function() {
16
+ return _default;
17
+ }
18
+ });
19
+ const _listendelegation = require("./_listen-delegation");
20
+ const _off = require("./off");
21
+ function unlisten(types, // | `${TTypes},${TTypes}`
22
+ // | `${TTypes},${TTypes},${TTypes}`
23
+ // | `${TTypes},${TTypes},${TTypes},${TTypes}`
24
+ // | `${TTypes},${TTypes},${TTypes},${TTypes},${TTypes}`,
25
+ selector, callback) {
16
26
  // Loop through each event type
17
- types.split(",").forEach(function (type) {
27
+ types.split(",").forEach(function(type) {
18
28
  // Remove whitespace
19
29
  type = type.trim();
20
30
  // if event type doesn't exist, bail
21
- if (!_listen_delegation_1.activeEvents[type])
22
- return;
31
+ if (!_listendelegation.activeEvents[type]) return;
23
32
  // If it's the last event of it's type, remove entirely
24
- if (_listen_delegation_1.activeEvents[type].length < 2 || !selector) {
25
- delete _listen_delegation_1.activeEvents[type];
26
- (0, off_1.off)(window, type, _listen_delegation_1.eventHandler, true);
33
+ if (_listendelegation.activeEvents[type].length < 2 || !selector) {
34
+ delete _listendelegation.activeEvents[type];
35
+ (0, _off.off)(window, type, _listendelegation.eventHandler, true);
27
36
  return;
28
37
  }
29
38
  // Otherwise, remove event
30
- var index = (0, _listen_delegation_1.getIndex)(_listen_delegation_1.activeEvents[type], selector, callback);
31
- if (index < 0)
32
- return;
33
- _listen_delegation_1.activeEvents[type].splice(index, 1);
39
+ // @ts-expect-error FIXME: type...
40
+ const index = (0, _listendelegation.getIndex)(_listendelegation.activeEvents[type], selector, callback);
41
+ if (index < 0) return;
42
+ _listendelegation.activeEvents[type].splice(index, 1);
34
43
  });
35
44
  }
36
- exports.unlisten = unlisten;
37
- exports.default = unlisten;
45
+ const _default = unlisten;
package/unlisten.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { activeEvents, getIndex, eventHandler, } from "./_listen-delegation";
1
+ import { activeEvents, eventHandler, getIndex } from "./_listen-delegation";
2
2
  import { off } from "./off";
3
3
  /**
4
4
  * Stop listening for an event
@@ -8,15 +8,17 @@ import { off } from "./off";
8
8
  * @param types The event type or types (comma separated)
9
9
  * @param selector The selector to remove the event from
10
10
  * @param callback The function to remove
11
- */
12
- export function unlisten(types, selector, callback) {
11
+ */ export function unlisten(types, // | `${TTypes},${TTypes}`
12
+ // | `${TTypes},${TTypes},${TTypes}`
13
+ // | `${TTypes},${TTypes},${TTypes},${TTypes}`
14
+ // | `${TTypes},${TTypes},${TTypes},${TTypes},${TTypes}`,
15
+ selector, callback) {
13
16
  // Loop through each event type
14
- types.split(",").forEach(function (type) {
17
+ types.split(",").forEach(function(type) {
15
18
  // Remove whitespace
16
19
  type = type.trim();
17
20
  // if event type doesn't exist, bail
18
- if (!activeEvents[type])
19
- return;
21
+ if (!activeEvents[type]) return;
20
22
  // If it's the last event of it's type, remove entirely
21
23
  if (activeEvents[type].length < 2 || !selector) {
22
24
  delete activeEvents[type];
@@ -24,9 +26,9 @@ export function unlisten(types, selector, callback) {
24
26
  return;
25
27
  }
26
28
  // Otherwise, remove event
27
- var index = getIndex(activeEvents[type], selector, callback);
28
- if (index < 0)
29
- return;
29
+ // @ts-expect-error FIXME: type...
30
+ const index = getIndex(activeEvents[type], selector, callback);
31
+ if (index < 0) return;
30
32
  activeEvents[type].splice(index, 1);
31
33
  });
32
34
  }
@@ -1,6 +0,0 @@
1
- /**
2
- * Get the background color of an element eventually looking recursively into
3
- * its parents, if nothing is found it returns a `#fff` background
4
- */
5
- export declare function getVisualBackgroundColor(elem?: null | HTMLElement): string;
6
- export default getVisualBackgroundColor;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getVisualBackgroundColor = void 0;
4
- /**
5
- * Get the background color of an element eventually looking recursively into
6
- * its parents, if nothing is found it returns a `#fff` background
7
- */
8
- function getVisualBackgroundColor(elem) {
9
- if (!elem)
10
- return "#fff";
11
- var transparent = "rgba(0, 0, 0, 0)";
12
- var transparentIE11 = "transparent";
13
- // if (!elem) return transparent;
14
- var bg = window.getComputedStyle(elem).backgroundColor;
15
- if (bg === transparent || bg === transparentIE11) {
16
- var parent_1 = elem.parentElement;
17
- if (parent_1) {
18
- return getVisualBackgroundColor(parent_1);
19
- }
20
- return "#fff";
21
- }
22
- return bg;
23
- }
24
- exports.getVisualBackgroundColor = getVisualBackgroundColor;
25
- exports.default = getVisualBackgroundColor;
@@ -1,21 +0,0 @@
1
- /**
2
- * Get the background color of an element eventually looking recursively into
3
- * its parents, if nothing is found it returns a `#fff` background
4
- */
5
- export function getVisualBackgroundColor(elem) {
6
- if (!elem)
7
- return "#fff";
8
- var transparent = "rgba(0, 0, 0, 0)";
9
- var transparentIE11 = "transparent";
10
- // if (!elem) return transparent;
11
- var bg = window.getComputedStyle(elem).backgroundColor;
12
- if (bg === transparent || bg === transparentIE11) {
13
- var parent_1 = elem.parentElement;
14
- if (parent_1) {
15
- return getVisualBackgroundColor(parent_1);
16
- }
17
- return "#fff";
18
- }
19
- return bg;
20
- }
21
- export default getVisualBackgroundColor;