@koine/dom 1.0.80
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/$$.d.ts +10 -0
- package/$$.js +12 -0
- package/$.d.ts +13 -0
- package/$.js +15 -0
- package/$each.d.ts +11 -0
- package/$each.js +17 -0
- package/README.md +1 -0
- package/_listen-delegation.d.ts +38 -0
- package/_listen-delegation.js +83 -0
- package/addClass.d.ts +5 -0
- package/addClass.js +15 -0
- package/calculateFixedOffset.d.ts +2 -0
- package/calculateFixedOffset.js +10 -0
- package/createElement.d.ts +9 -0
- package/createElement.js +16 -0
- package/emitEvent.d.ts +5 -0
- package/emitEvent.js +14 -0
- package/escapeSelector.d.ts +8 -0
- package/escapeSelector.js +10 -0
- package/exists.d.ts +7 -0
- package/exists.js +12 -0
- package/forEach.d.ts +9 -0
- package/forEach.js +13 -0
- package/getDataAttr.d.ts +8 -0
- package/getDataAttr.js +13 -0
- package/getDocumentHeight.d.ts +7 -0
- package/getDocumentHeight.js +10 -0
- package/getHeight.d.ts +5 -0
- package/getHeight.js +7 -0
- package/getListeners.d.ts +9 -0
- package/getListeners.js +18 -0
- package/getOffset.d.ts +11 -0
- package/getOffset.js +18 -0
- package/getOffsetTop.d.ts +10 -0
- package/getOffsetTop.js +20 -0
- package/getScrollbarWidth.d.ts +5 -0
- package/getScrollbarWidth.js +7 -0
- package/getStyleValue.d.ts +8 -0
- package/getStyleValue.js +10 -0
- package/index.d.ts +40 -0
- package/index.js +40 -0
- package/injectCss.d.ts +5 -0
- package/injectCss.js +16 -0
- package/isHidden.d.ts +5 -0
- package/isHidden.js +7 -0
- package/isInViewport.d.ts +10 -0
- package/isInViewport.js +18 -0
- package/isNodeList.d.ts +7 -0
- package/isNodeList.js +14 -0
- package/isTotallyScrolled.d.ts +8 -0
- package/isTotallyScrolled.js +10 -0
- package/listen.d.ts +12 -0
- package/listen.js +32 -0
- package/listenLoaded.d.ts +7 -0
- package/listenLoaded.js +11 -0
- package/listenOnce.d.ts +12 -0
- package/listenOnce.js +20 -0
- package/listenResize.d.ts +8 -0
- package/listenResize.js +25 -0
- package/listenScroll.d.ts +8 -0
- package/listenScroll.js +28 -0
- package/node/$$.js +16 -0
- package/node/$.js +19 -0
- package/node/$each.js +22 -0
- package/node/_listen-delegation.js +89 -0
- package/node/addClass.js +19 -0
- package/node/calculateFixedOffset.js +14 -0
- package/node/createElement.js +21 -0
- package/node/emitEvent.js +18 -0
- package/node/escapeSelector.js +14 -0
- package/node/exists.js +16 -0
- package/node/forEach.js +17 -0
- package/node/getDataAttr.js +17 -0
- package/node/getDocumentHeight.js +14 -0
- package/node/getHeight.js +11 -0
- package/node/getListeners.js +22 -0
- package/node/getOffset.js +22 -0
- package/node/getOffsetTop.js +24 -0
- package/node/getScrollbarWidth.js +11 -0
- package/node/getStyleValue.js +14 -0
- package/node/index.js +43 -0
- package/node/injectCss.js +20 -0
- package/node/isHidden.js +11 -0
- package/node/isInViewport.js +22 -0
- package/node/isNodeList.js +18 -0
- package/node/isTotallyScrolled.js +14 -0
- package/node/listen.js +36 -0
- package/node/listenLoaded.js +15 -0
- package/node/listenOnce.js +24 -0
- package/node/listenResize.js +29 -0
- package/node/listenScroll.js +32 -0
- package/node/off.js +19 -0
- package/node/on.js +19 -0
- package/node/onClickOutside.js +21 -0
- package/node/once.js +20 -0
- package/node/removeClass.js +19 -0
- package/node/scrollTo.js +32 -0
- package/node/setDataAttr.js +22 -0
- package/node/setVendorCSS.js +25 -0
- package/node/siblings.js +23 -0
- package/node/toArray.js +13 -0
- package/node/unlisten.js +37 -0
- package/off.d.ts +5 -0
- package/off.js +15 -0
- package/on.d.ts +5 -0
- package/on.js +15 -0
- package/onClickOutside.d.ts +1 -0
- package/onClickOutside.js +17 -0
- package/once.d.ts +6 -0
- package/once.js +15 -0
- package/package.json +16 -0
- package/removeClass.d.ts +5 -0
- package/removeClass.js +15 -0
- package/scrollTo.d.ts +10 -0
- package/scrollTo.js +28 -0
- package/setDataAttr.d.ts +9 -0
- package/setDataAttr.js +18 -0
- package/setVendorCSS.d.ts +9 -0
- package/setVendorCSS.js +21 -0
- package/siblings.d.ts +7 -0
- package/siblings.js +19 -0
- package/toArray.d.ts +7 -0
- package/toArray.js +9 -0
- package/typings.d.ts +0 -0
- package/unlisten.d.ts +12 -0
- package/unlisten.js +33 -0
package/$$.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sizzle/jQuery like DOM nodes shortcut for `document.querySelectorAll`
|
|
3
|
+
* To avoid an extra function call we inline the above `escape`
|
|
4
|
+
*
|
|
5
|
+
* @param string selector DOM selector
|
|
6
|
+
* @param parent It falls back to `window.document`
|
|
7
|
+
* @param avoidEscape Whether to avoid escaping `:` in the selector string
|
|
8
|
+
*/
|
|
9
|
+
export declare function $$<T extends Element = HTMLElement>(selector: string, parent?: HTMLElement | Document, avoidEscape?: boolean): NodeListOf<T>;
|
|
10
|
+
export default $$;
|
package/$$.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sizzle/jQuery like DOM nodes shortcut for `document.querySelectorAll`
|
|
3
|
+
* To avoid an extra function call we inline the above `escape`
|
|
4
|
+
*
|
|
5
|
+
* @param string selector DOM selector
|
|
6
|
+
* @param parent It falls back to `window.document`
|
|
7
|
+
* @param avoidEscape Whether to avoid escaping `:` in the selector string
|
|
8
|
+
*/
|
|
9
|
+
export function $$(selector, parent, avoidEscape) {
|
|
10
|
+
return (parent ? parent : document).querySelectorAll(avoidEscape ? selector : selector.replace(/:/g, "\\:"));
|
|
11
|
+
}
|
|
12
|
+
export default $$;
|
package/$.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sizzle/jQuery like DOM nodes shortcut for `document.querySelector`
|
|
3
|
+
* To avoid an extra function call we inline the above `escape`
|
|
4
|
+
*
|
|
5
|
+
* @param selector DOM selector
|
|
6
|
+
* @param parent It falls back to `window.document`
|
|
7
|
+
* @param avoidEscape Whether to avoid escaping `:` in the selector string
|
|
8
|
+
* @example <caption>Basic DOM selection</caption>
|
|
9
|
+
* const $container = $(".my-section:");
|
|
10
|
+
* const $el = $("[data-some-attr]", $container);
|
|
11
|
+
*/
|
|
12
|
+
export declare function $<T extends Element = HTMLElement>(selector: string, parent?: HTMLElement | Document, avoidEscape?: boolean): T;
|
|
13
|
+
export default $;
|
package/$.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sizzle/jQuery like DOM nodes shortcut for `document.querySelector`
|
|
3
|
+
* To avoid an extra function call we inline the above `escape`
|
|
4
|
+
*
|
|
5
|
+
* @param selector DOM selector
|
|
6
|
+
* @param parent It falls back to `window.document`
|
|
7
|
+
* @param avoidEscape Whether to avoid escaping `:` in the selector string
|
|
8
|
+
* @example <caption>Basic DOM selection</caption>
|
|
9
|
+
* const $container = $(".my-section:");
|
|
10
|
+
* const $el = $("[data-some-attr]", $container);
|
|
11
|
+
*/
|
|
12
|
+
export function $(selector, parent, avoidEscape) {
|
|
13
|
+
return (parent ? parent : document).querySelector(avoidEscape ? selector : selector.replace(/:/g, "\\:"));
|
|
14
|
+
}
|
|
15
|
+
export default $;
|
package/$each.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Each shortcut, iterate through a NodeList of HTMLElements retrieved with the
|
|
3
|
+
* given selector (and optionally a parent container passed as thrid arguement)
|
|
4
|
+
*
|
|
5
|
+
* @param selector DOM selector
|
|
6
|
+
* @param callback
|
|
7
|
+
* @param parent It falls back to `window.document`
|
|
8
|
+
* @param scope
|
|
9
|
+
*/
|
|
10
|
+
export declare function $each<T extends Element = HTMLElement>(selector: string, callback: ($element: T, index: number) => any, parent?: HTMLElement, scope?: object): void;
|
|
11
|
+
export default $each;
|
package/$each.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import $$ from "./$$";
|
|
2
|
+
/**
|
|
3
|
+
* Each shortcut, iterate through a NodeList of HTMLElements retrieved with the
|
|
4
|
+
* given selector (and optionally a parent container passed as thrid arguement)
|
|
5
|
+
*
|
|
6
|
+
* @param selector DOM selector
|
|
7
|
+
* @param callback
|
|
8
|
+
* @param parent It falls back to `window.document`
|
|
9
|
+
* @param scope
|
|
10
|
+
*/
|
|
11
|
+
export function $each(selector, callback, parent, scope) {
|
|
12
|
+
var nodes = $$(selector, parent);
|
|
13
|
+
for (var i = 0; i < nodes.length; i++) {
|
|
14
|
+
callback.call(scope, nodes[i], i);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export default $each;
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @koine/dom
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
*/
|
|
4
|
+
export declare type EventCallback = (event: Event, desiredTarget: Window | Document | Element) => any;
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare type ListenEvent = {
|
|
9
|
+
selector: string;
|
|
10
|
+
callback: EventCallback;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Active events
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export declare const activeEvents: Record<Event["type"], ListenEvent[]>;
|
|
18
|
+
/**
|
|
19
|
+
* Get the index for the listener
|
|
20
|
+
*
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export declare function getIndex(arr: ListenEvent[], selector: string, callback: EventCallback): number;
|
|
24
|
+
/**
|
|
25
|
+
* Check if the listener callback should run or not
|
|
26
|
+
*
|
|
27
|
+
* @internal
|
|
28
|
+
* @param target The event.target
|
|
29
|
+
* @param selector The selector/element to check the target against
|
|
30
|
+
* @return If not false, run listener and pass the targeted element to use in the callback
|
|
31
|
+
*/
|
|
32
|
+
export declare function getRunTarget(target: Element, selector: string | Window | Document | Element): false | Element | Document | Window | null;
|
|
33
|
+
/**
|
|
34
|
+
* Handle listeners after event fires
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
export declare function eventHandler(event: Event): void;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Listen: events delegation system
|
|
3
|
+
*
|
|
4
|
+
* From:
|
|
5
|
+
* https://github.com/cferdinandi/events
|
|
6
|
+
* https://github.com/cferdinandi/events/blob/master/src/js/events/events.js
|
|
7
|
+
*
|
|
8
|
+
* @fileoverview
|
|
9
|
+
*/
|
|
10
|
+
import { isString } from "@koine/utils";
|
|
11
|
+
import { escapeSelector } from "./escapeSelector";
|
|
12
|
+
/**
|
|
13
|
+
* Active events
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export var activeEvents = {};
|
|
18
|
+
/**
|
|
19
|
+
* Get the index for the listener
|
|
20
|
+
*
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export function getIndex(arr, selector, callback) {
|
|
24
|
+
for (var i = 0; i < arr.length; i++) {
|
|
25
|
+
if (arr[i].selector === selector &&
|
|
26
|
+
arr[i].callback.toString() === callback.toString())
|
|
27
|
+
return i;
|
|
28
|
+
}
|
|
29
|
+
return -1;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Check if the listener callback should run or not
|
|
33
|
+
*
|
|
34
|
+
* @internal
|
|
35
|
+
* @param target The event.target
|
|
36
|
+
* @param selector The selector/element to check the target against
|
|
37
|
+
* @return If not false, run listener and pass the targeted element to use in the callback
|
|
38
|
+
*/
|
|
39
|
+
export function getRunTarget(target, selector) {
|
|
40
|
+
// @ts-expect-error FIXME: type
|
|
41
|
+
if (["*", "window", window].includes(selector)) {
|
|
42
|
+
return window;
|
|
43
|
+
}
|
|
44
|
+
if ([
|
|
45
|
+
"document",
|
|
46
|
+
"document.documentElement",
|
|
47
|
+
document,
|
|
48
|
+
document.documentElement,
|
|
49
|
+
// @ts-expect-error FIXME: type
|
|
50
|
+
].includes(selector))
|
|
51
|
+
return document;
|
|
52
|
+
if (isString(selector)) {
|
|
53
|
+
return target.closest(escapeSelector(selector));
|
|
54
|
+
}
|
|
55
|
+
// @ts-expect-error FIXME: type
|
|
56
|
+
if (typeof selector !== "string" && selector.contains) {
|
|
57
|
+
if (selector === target) {
|
|
58
|
+
return target;
|
|
59
|
+
}
|
|
60
|
+
// @ts-expect-error FIXME: type
|
|
61
|
+
if (selector.contains(target)) {
|
|
62
|
+
return selector;
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Handle listeners after event fires
|
|
70
|
+
*
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
export function eventHandler(event) {
|
|
74
|
+
if (!activeEvents[event.type])
|
|
75
|
+
return;
|
|
76
|
+
activeEvents[event.type].forEach(function (listener) {
|
|
77
|
+
var target = getRunTarget(event.target, listener.selector);
|
|
78
|
+
if (!target) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
listener.callback(event, target);
|
|
82
|
+
});
|
|
83
|
+
}
|
package/addClass.d.ts
ADDED
package/addClass.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Add class shortcut
|
|
3
|
+
*/
|
|
4
|
+
export function addClass(el, className) {
|
|
5
|
+
if (className === void 0) { className = ""; }
|
|
6
|
+
if (process.env["NODE_ENV"] !== "production") {
|
|
7
|
+
if (!el) {
|
|
8
|
+
console.warn("[@koine/dom:addClass] unexisting DOM element");
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
if (el)
|
|
13
|
+
el.classList.add(className);
|
|
14
|
+
}
|
|
15
|
+
export default addClass;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { $each } from "./$each";
|
|
2
|
+
export function calculateFixedOffset(selector) {
|
|
3
|
+
if (selector === void 0) { selector = "[data-fixed]"; }
|
|
4
|
+
var fixedOffset = 0;
|
|
5
|
+
$each(selector, function ($el) {
|
|
6
|
+
fixedOffset += $el.offsetHeight;
|
|
7
|
+
});
|
|
8
|
+
return fixedOffset;
|
|
9
|
+
}
|
|
10
|
+
export default calculateFixedOffset;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shortcut for `document.createElement`, allowing to to create an HTML element
|
|
3
|
+
* with a given className directly (a very common use case)
|
|
4
|
+
*
|
|
5
|
+
* @param type
|
|
6
|
+
* @param className
|
|
7
|
+
*/
|
|
8
|
+
export declare function createElement(type: string, className?: string): HTMLElement;
|
|
9
|
+
export default createElement;
|
package/createElement.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import addClass from "./addClass";
|
|
2
|
+
/**
|
|
3
|
+
* Shortcut for `document.createElement`, allowing to to create an HTML element
|
|
4
|
+
* with a given className directly (a very common use case)
|
|
5
|
+
*
|
|
6
|
+
* @param type
|
|
7
|
+
* @param className
|
|
8
|
+
*/
|
|
9
|
+
export function createElement(type, className) {
|
|
10
|
+
var el = document.createElement(type);
|
|
11
|
+
if (className) {
|
|
12
|
+
addClass(el, className);
|
|
13
|
+
}
|
|
14
|
+
return el;
|
|
15
|
+
}
|
|
16
|
+
export default createElement;
|
package/emitEvent.d.ts
ADDED
package/emitEvent.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Emit event (use only if the targeted browser supports `CustomEvent`s)
|
|
3
|
+
*/
|
|
4
|
+
export function emitEvent(type, detail) {
|
|
5
|
+
if (type === void 0) { type = "customEvent"; }
|
|
6
|
+
if (detail === void 0) { detail = {}; }
|
|
7
|
+
if (typeof window.CustomEvent !== "function")
|
|
8
|
+
return;
|
|
9
|
+
document.dispatchEvent(new CustomEvent(type, {
|
|
10
|
+
bubbles: true,
|
|
11
|
+
detail: detail,
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
export default emitEvent;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Escape colons to allow use class names as `.module:block__element`
|
|
3
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector#Escaping_special_characters
|
|
4
|
+
*
|
|
5
|
+
* @param selector
|
|
6
|
+
*/
|
|
7
|
+
export declare function escapeSelector(selector: string): string;
|
|
8
|
+
export default escapeSelector;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Escape colons to allow use class names as `.module:block__element`
|
|
3
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector#Escaping_special_characters
|
|
4
|
+
*
|
|
5
|
+
* @param selector
|
|
6
|
+
*/
|
|
7
|
+
export function escapeSelector(selector) {
|
|
8
|
+
return selector.replace(/:/g, "\\:");
|
|
9
|
+
}
|
|
10
|
+
export default escapeSelector;
|
package/exists.d.ts
ADDED
package/exists.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if passed node exist and is a valid element.
|
|
3
|
+
*
|
|
4
|
+
* @borrows @glidejs/glide/src/utils/dom (source)
|
|
5
|
+
*/
|
|
6
|
+
export function exists(node) {
|
|
7
|
+
if (node && node instanceof window.HTMLElement) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
export default exists;
|
package/forEach.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* For each, iterate through a NodeList of HTMLElements
|
|
3
|
+
*
|
|
4
|
+
* @param nodes DOM nodes collection
|
|
5
|
+
* @param callback
|
|
6
|
+
* @param scope
|
|
7
|
+
*/
|
|
8
|
+
export declare function forEach<T extends Element = HTMLElement, TScope = object>(nodes: NodeList, callback: (this: TScope, $element: T, index: number) => any, scope?: TScope): void;
|
|
9
|
+
export default forEach;
|
package/forEach.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* For each, iterate through a NodeList of HTMLElements
|
|
3
|
+
*
|
|
4
|
+
* @param nodes DOM nodes collection
|
|
5
|
+
* @param callback
|
|
6
|
+
* @param scope
|
|
7
|
+
*/
|
|
8
|
+
export function forEach(nodes, callback, scope) {
|
|
9
|
+
for (var i = 0; i < nodes.length; i++) {
|
|
10
|
+
callback.call(scope, nodes[i], i);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export default forEach;
|
package/getDataAttr.d.ts
ADDED
package/getDataAttr.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// TODO: maybe move to `dataset` API but consider the comment about Safari here
|
|
2
|
+
// https://stackoverflow.com/a/9201264/1938970
|
|
3
|
+
/**
|
|
4
|
+
* Get data attribute
|
|
5
|
+
*
|
|
6
|
+
* @param element
|
|
7
|
+
* @param attribute The name of the `data-{attr}`
|
|
8
|
+
*/
|
|
9
|
+
export function getDataAttr(element, attribute) {
|
|
10
|
+
// return element.dataset[attribute];
|
|
11
|
+
return element.getAttribute("data-" + attribute);
|
|
12
|
+
}
|
|
13
|
+
export default getDataAttr;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determine the document's height
|
|
3
|
+
*
|
|
4
|
+
* @see https://github.com/cferdinandi/smooth-scroll (credits)
|
|
5
|
+
*/
|
|
6
|
+
export function getDocumentHeight() {
|
|
7
|
+
var body = document.body, documentElement = document.documentElement;
|
|
8
|
+
return Math.max(body.scrollHeight, documentElement.scrollHeight, body.offsetHeight, documentElement.offsetHeight, body.clientHeight, documentElement.clientHeight);
|
|
9
|
+
}
|
|
10
|
+
export default getDocumentHeight;
|
package/getHeight.d.ts
ADDED
package/getHeight.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get an immutable copy of all active event listeners
|
|
3
|
+
*
|
|
4
|
+
* @category listen-delegation
|
|
5
|
+
*
|
|
6
|
+
* @return Active event listeners
|
|
7
|
+
*/
|
|
8
|
+
export declare function getListeners(): Record<string, import("./_listen-delegation").ListenEvent[]>;
|
|
9
|
+
export default getListeners;
|
package/getListeners.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { activeEvents } from "./_listen-delegation";
|
|
2
|
+
/**
|
|
3
|
+
* Get an immutable copy of all active event listeners
|
|
4
|
+
*
|
|
5
|
+
* @category listen-delegation
|
|
6
|
+
*
|
|
7
|
+
* @return Active event listeners
|
|
8
|
+
*/
|
|
9
|
+
export function getListeners() {
|
|
10
|
+
var obj = {};
|
|
11
|
+
for (var type in activeEvents) {
|
|
12
|
+
// if (activeEvents.hasOwnProperty(type)) {
|
|
13
|
+
obj[type] = activeEvents[type];
|
|
14
|
+
// }
|
|
15
|
+
}
|
|
16
|
+
return obj;
|
|
17
|
+
}
|
|
18
|
+
export default getListeners;
|
package/getOffset.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get an element's distance from the top and left of the Document.
|
|
3
|
+
*
|
|
4
|
+
* @param elem The HTML node element
|
|
5
|
+
* @return Distance from the top and left in pixels
|
|
6
|
+
*/
|
|
7
|
+
export declare function getOffset(elem: HTMLElement): {
|
|
8
|
+
top: number;
|
|
9
|
+
left: number;
|
|
10
|
+
};
|
|
11
|
+
export default getOffset;
|
package/getOffset.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get an element's distance from the top and left of the Document.
|
|
3
|
+
*
|
|
4
|
+
* @param elem The HTML node element
|
|
5
|
+
* @return Distance from the top and left in pixels
|
|
6
|
+
*/
|
|
7
|
+
export function getOffset(elem) {
|
|
8
|
+
var left = 0;
|
|
9
|
+
var top = 0;
|
|
10
|
+
while (elem && !isNaN(elem.offsetLeft) && !isNaN(elem.offsetTop)) {
|
|
11
|
+
left += elem.offsetLeft - elem.scrollLeft;
|
|
12
|
+
top += elem.offsetTop - elem.scrollTop;
|
|
13
|
+
// @ts-expect-error nevermind?
|
|
14
|
+
elem = elem.offsetParent;
|
|
15
|
+
}
|
|
16
|
+
return { top: top, left: left };
|
|
17
|
+
}
|
|
18
|
+
export default getOffset;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get an element's distance from the top of the Document.
|
|
3
|
+
*
|
|
4
|
+
* @see https://vanillajstoolkit.com/helpers/getoffsettop/
|
|
5
|
+
*
|
|
6
|
+
* @param elem The HTML node element
|
|
7
|
+
* @return Distance from the top in pixels
|
|
8
|
+
*/
|
|
9
|
+
export declare function getOffsetTop(elem: HTMLElement): number;
|
|
10
|
+
export default getOffsetTop;
|
package/getOffsetTop.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get an element's distance from the top of the Document.
|
|
3
|
+
*
|
|
4
|
+
* @see https://vanillajstoolkit.com/helpers/getoffsettop/
|
|
5
|
+
*
|
|
6
|
+
* @param elem The HTML node element
|
|
7
|
+
* @return Distance from the top in pixels
|
|
8
|
+
*/
|
|
9
|
+
export function getOffsetTop(elem) {
|
|
10
|
+
var location = 0;
|
|
11
|
+
if (elem.offsetParent) {
|
|
12
|
+
while (elem) {
|
|
13
|
+
location += elem.offsetTop;
|
|
14
|
+
// @ts-expect-error nevermind?
|
|
15
|
+
elem = elem.offsetParent;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return location >= 0 ? location : 0;
|
|
19
|
+
}
|
|
20
|
+
export default getOffsetTop;
|
package/getStyleValue.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Return the current style value for an element CSS property
|
|
3
|
+
*
|
|
4
|
+
* @param el The element to compute
|
|
5
|
+
* @param prop The style property
|
|
6
|
+
*/
|
|
7
|
+
export function getStyleValue(el, prop) {
|
|
8
|
+
return getComputedStyle(el, null).getPropertyValue(prop);
|
|
9
|
+
}
|
|
10
|
+
export default getStyleValue;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export * from "./$$";
|
|
2
|
+
export * from "./$each";
|
|
3
|
+
export * from "./$";
|
|
4
|
+
export * from "./addClass";
|
|
5
|
+
export * from "./calculateFixedOffset";
|
|
6
|
+
export * from "./createElement";
|
|
7
|
+
export * from "./emitEvent";
|
|
8
|
+
export * from "./escapeSelector";
|
|
9
|
+
export * from "./exists";
|
|
10
|
+
export * from "./forEach";
|
|
11
|
+
export * from "./getDataAttr";
|
|
12
|
+
export * from "./getDocumentHeight";
|
|
13
|
+
export * from "./getHeight";
|
|
14
|
+
export * from "./getListeners";
|
|
15
|
+
export * from "./getOffsetTop";
|
|
16
|
+
export * from "./getOffset";
|
|
17
|
+
export * from "./getScrollbarWidth";
|
|
18
|
+
export * from "./getStyleValue";
|
|
19
|
+
export * from "./index";
|
|
20
|
+
export * from "./injectCss";
|
|
21
|
+
export * from "./isHidden";
|
|
22
|
+
export * from "./isInViewport";
|
|
23
|
+
export * from "./isNodeList";
|
|
24
|
+
export * from "./isTotallyScrolled";
|
|
25
|
+
export * from "./listenLoaded";
|
|
26
|
+
export * from "./listenOnce";
|
|
27
|
+
export * from "./listenResize";
|
|
28
|
+
export * from "./listenScroll";
|
|
29
|
+
export * from "./listen";
|
|
30
|
+
export * from "./off";
|
|
31
|
+
export * from "./once";
|
|
32
|
+
export * from "./onClickOutside";
|
|
33
|
+
export * from "./on";
|
|
34
|
+
export * from "./removeClass";
|
|
35
|
+
export * from "./scrollTo";
|
|
36
|
+
export * from "./setDataAttr";
|
|
37
|
+
export * from "./setVendorCSS";
|
|
38
|
+
export * from "./siblings";
|
|
39
|
+
export * from "./toArray";
|
|
40
|
+
export * from "./unlisten";
|
package/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export * from "./$$";
|
|
2
|
+
export * from "./$each";
|
|
3
|
+
export * from "./$";
|
|
4
|
+
export * from "./addClass";
|
|
5
|
+
export * from "./calculateFixedOffset";
|
|
6
|
+
export * from "./createElement";
|
|
7
|
+
export * from "./emitEvent";
|
|
8
|
+
export * from "./escapeSelector";
|
|
9
|
+
export * from "./exists";
|
|
10
|
+
export * from "./forEach";
|
|
11
|
+
export * from "./getDataAttr";
|
|
12
|
+
export * from "./getDocumentHeight";
|
|
13
|
+
export * from "./getHeight";
|
|
14
|
+
export * from "./getListeners";
|
|
15
|
+
export * from "./getOffsetTop";
|
|
16
|
+
export * from "./getOffset";
|
|
17
|
+
export * from "./getScrollbarWidth";
|
|
18
|
+
export * from "./getStyleValue";
|
|
19
|
+
export * from "./index";
|
|
20
|
+
export * from "./injectCss";
|
|
21
|
+
export * from "./isHidden";
|
|
22
|
+
export * from "./isInViewport";
|
|
23
|
+
export * from "./isNodeList";
|
|
24
|
+
export * from "./isTotallyScrolled";
|
|
25
|
+
export * from "./listenLoaded";
|
|
26
|
+
export * from "./listenOnce";
|
|
27
|
+
export * from "./listenResize";
|
|
28
|
+
export * from "./listenScroll";
|
|
29
|
+
export * from "./listen";
|
|
30
|
+
export * from "./off";
|
|
31
|
+
export * from "./once";
|
|
32
|
+
export * from "./onClickOutside";
|
|
33
|
+
export * from "./on";
|
|
34
|
+
export * from "./removeClass";
|
|
35
|
+
export * from "./scrollTo";
|
|
36
|
+
export * from "./setDataAttr";
|
|
37
|
+
export * from "./setVendorCSS";
|
|
38
|
+
export * from "./siblings";
|
|
39
|
+
export * from "./toArray";
|
|
40
|
+
export * from "./unlisten";
|