@koine/dom 2.0.0-beta.14 → 2.0.0-beta.15
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 +0 -11
- package/$.js +4 -0
- package/$all.d.ts +2 -0
- package/$all.js +4 -0
- package/$each.d.ts +0 -9
- package/$each.js +8 -0
- package/_listen-delegation.d.ts +1 -30
- package/_listen-delegation.js +46 -0
- package/addClass.d.ts +0 -3
- package/{addClass.mjs → addClass.js} +4 -4
- package/calculateFixedOffset.js +10 -0
- package/createElement.d.ts +0 -7
- package/createElement.js +9 -0
- package/emitEvent.d.ts +0 -3
- package/emitEvent.js +11 -0
- package/escapeSelector.d.ts +0 -6
- package/escapeSelector.js +4 -0
- package/exists.d.ts +0 -5
- package/exists.js +7 -0
- package/forEach.d.ts +0 -5
- package/forEach.js +6 -0
- package/getDataAttr.d.ts +0 -6
- package/getDataAttr.js +4 -0
- package/getDocumentHeight.d.ts +0 -5
- package/{getDocumentHeight.mjs → getDocumentHeight.js} +2 -6
- package/getHeight.d.ts +0 -3
- package/{getHeight.mjs → getHeight.js} +1 -3
- package/getListeners.d.ts +0 -7
- package/getListeners.js +9 -0
- package/getOffset.d.ts +0 -6
- package/getOffset.js +11 -0
- package/getOffsetTop.d.ts +0 -8
- package/getOffsetTop.js +11 -0
- package/getOffsetTopSlim.d.ts +0 -9
- package/getOffsetTopSlim.js +4 -0
- package/getScrollbarWidth.d.ts +0 -3
- package/{getScrollbarWidth.mjs → getScrollbarWidth.js} +1 -3
- package/getStyleValue.d.ts +0 -6
- package/getStyleValue.js +4 -0
- package/getVisualBackgroundColor.d.ts +0 -4
- package/getVisualBackgroundColor.js +16 -0
- package/index.d.ts +46 -46
- package/index.js +45 -0
- package/injectCss.d.ts +0 -3
- package/{injectCss.mjs → injectCss.js} +4 -4
- package/isHidden.d.ts +0 -3
- package/{isHidden.mjs → isHidden.js} +1 -3
- package/isInViewport.d.ts +0 -8
- package/isInViewport.js +10 -0
- package/isNodeList.d.ts +0 -5
- package/isNodeList.js +9 -0
- package/isTotallyScrolled.d.ts +0 -6
- package/isTotallyScrolled.js +4 -0
- package/listen.d.ts +2 -11
- package/listen.js +19 -0
- package/listenLoaded.d.ts +0 -5
- package/listenLoaded.js +5 -0
- package/listenOnce.d.ts +1 -10
- package/listenOnce.js +11 -0
- package/listenResize.d.ts +1 -6
- package/listenResize.js +3 -0
- package/listenResizeDebounced.d.ts +1 -6
- package/listenResizeDebounced.js +10 -0
- package/listenResizeThrottled.d.ts +1 -6
- package/listenResizeThrottled.js +10 -0
- package/listenScroll.d.ts +1 -6
- package/listenScroll.js +8 -0
- package/listenScrollDebounced.d.ts +1 -6
- package/listenScrollDebounced.js +10 -0
- package/listenScrollThrottled.d.ts +1 -6
- package/listenScrollThrottled.js +10 -0
- package/off.d.ts +1 -4
- package/{off.mjs → off.js} +4 -4
- package/on.d.ts +1 -6
- package/on.js +15 -0
- package/onClickOutside.js +16 -0
- package/once.d.ts +1 -5
- package/once.js +11 -0
- package/package.json +148 -7
- package/removeClass.d.ts +0 -3
- package/removeClass.js +12 -0
- package/scrollTo.d.ts +0 -10
- package/scrollTo.js +30 -0
- package/setDataAttr.d.ts +0 -7
- package/setDataAttr.js +8 -0
- package/setVendorCSS.d.ts +0 -7
- package/setVendorCSS.js +9 -0
- package/siblings.d.ts +0 -5
- package/siblings.js +14 -0
- package/toArray.d.ts +0 -5
- package/toArray.js +4 -0
- package/types.d.ts +0 -4
- package/types.js +1 -0
- package/unlisten.d.ts +2 -11
- package/unlisten.js +19 -0
- package/$$.d.ts +0 -10
- package/$$.mjs +0 -11
- package/$.mjs +0 -14
- package/$each.mjs +0 -16
- package/README.md +0 -1
- package/_listen-delegation.mjs +0 -77
- package/calculateFixedOffset.mjs +0 -9
- package/createElement.mjs +0 -15
- package/emitEvent.mjs +0 -10
- package/escapeSelector.mjs +0 -9
- package/exists.mjs +0 -11
- package/forEach.mjs +0 -34
- package/getDataAttr.mjs +0 -12
- package/getListeners.mjs +0 -17
- package/getOffset.mjs +0 -20
- package/getOffsetTop.mjs +0 -19
- package/getOffsetTopSlim.mjs +0 -12
- package/getStyleValue.mjs +0 -9
- package/getVisualBackgroundColor.mjs +0 -19
- package/index.mjs +0 -45
- package/isInViewport.mjs +0 -12
- package/isNodeList.mjs +0 -9
- package/isTotallyScrolled.mjs +0 -9
- package/listen.mjs +0 -36
- package/listenLoaded.mjs +0 -10
- package/listenOnce.mjs +0 -19
- package/listenResize.mjs +0 -7
- package/listenResizeDebounced.mjs +0 -34
- package/listenResizeThrottled.mjs +0 -8
- package/listenScroll.mjs +0 -10
- package/listenScrollDebounced.mjs +0 -8
- package/listenScrollThrottled.mjs +0 -8
- package/on.mjs +0 -21
- package/onClickOutside.mjs +0 -15
- package/once.mjs +0 -13
- package/removeClass.mjs +0 -12
- package/scrollTo.mjs +0 -39
- package/setDataAttr.mjs +0 -17
- package/setVendorCSS.mjs +0 -20
- package/siblings.mjs +0 -18
- package/toArray.mjs +0 -8
- package/types.mjs +0 -1
- package/unlisten.mjs +0 -35
package/siblings.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function siblings(node) {
|
|
2
|
+
if (node && node.parentNode) {
|
|
3
|
+
var n = node.parentNode.firstChild;
|
|
4
|
+
var matched = [];
|
|
5
|
+
for (; n; n = n.nextSibling) {
|
|
6
|
+
if (n.nodeType === 1 && n !== node) {
|
|
7
|
+
matched.push(n);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return matched;
|
|
11
|
+
}
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
export default siblings;
|
package/toArray.d.ts
CHANGED
package/toArray.js
ADDED
package/types.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { LiteralUnion } from "type-fest";
|
|
2
2
|
import type { AnythingFalsy } from "@koine/utils/types";
|
|
3
3
|
export type AnyDOMEventTarget = Window | Document | HTMLElement | Element;
|
|
4
|
-
/**
|
|
5
|
-
* We use it either throwing an error on unexisting element or falling back
|
|
6
|
-
* to `window` in case of _scroll_ or _resize_ events
|
|
7
|
-
*/
|
|
8
4
|
export type AnyDOMEventTargetLoose = AnyDOMEventTarget | AnythingFalsy;
|
|
9
5
|
type StandardDOMEventTypes = keyof GlobalEventHandlersEventMap;
|
|
10
6
|
export type AnyDOMEventType = LiteralUnion<StandardDOMEventTypes | "storage" | "popstate", string>;
|
package/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/unlisten.d.ts
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
import { type EventCallback } from "./_listen-delegation";
|
|
2
|
-
import type { AnyDOMEventTarget, AnyDOMEventType } from "./types";
|
|
3
|
-
/**
|
|
4
|
-
* Stop listening for an event
|
|
5
|
-
*
|
|
6
|
-
* @category listen-delegation
|
|
7
|
-
*
|
|
8
|
-
* @param types The event type or types (comma separated)
|
|
9
|
-
* @param selector The selector to remove the event from
|
|
10
|
-
* @param callback The function to remove
|
|
11
|
-
*/
|
|
1
|
+
import { type EventCallback } from "./_listen-delegation.js";
|
|
2
|
+
import type { AnyDOMEventTarget, AnyDOMEventType } from "./types.js";
|
|
12
3
|
export declare function unlisten<TTypes extends AnyDOMEventType, TTarget extends AnyDOMEventTarget = AnyDOMEventTarget>(types: TTypes, selector: string, callback: EventCallback<TTarget, TTypes>): void;
|
|
13
4
|
export default unlisten;
|
package/unlisten.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { activeEvents, eventHandler, getIndex, } from "./_listen-delegation.js";
|
|
2
|
+
import { off } from "./off.js";
|
|
3
|
+
export function unlisten(types, selector, callback) {
|
|
4
|
+
types.split(",").forEach(function (type) {
|
|
5
|
+
type = type.trim();
|
|
6
|
+
if (!activeEvents[type])
|
|
7
|
+
return;
|
|
8
|
+
if (activeEvents[type].length < 2 || !selector) {
|
|
9
|
+
delete activeEvents[type];
|
|
10
|
+
off(window, type, eventHandler, true);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
var index = getIndex(activeEvents[type], selector, callback);
|
|
14
|
+
if (index < 0)
|
|
15
|
+
return;
|
|
16
|
+
activeEvents[type].splice(index, 1);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export default unlisten;
|
package/$$.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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?: Element | HTMLElement | Document | null, avoidEscape?: boolean): NodeListOf<T>;
|
|
10
|
-
export default $$;
|
package/$$.mjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
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
|
-
*/ export function $$(selector, parent, avoidEscape) {
|
|
9
|
-
return (parent ? parent : document).querySelectorAll(avoidEscape ? selector : selector.replace(/:/g, "\\:"));
|
|
10
|
-
}
|
|
11
|
-
export default $$;
|
package/$.mjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
*/ export function $(selector, parent, avoidEscape) {
|
|
12
|
-
return (parent ? parent : document).querySelector(avoidEscape ? selector : selector.replace(/:/g, "\\:"));
|
|
13
|
-
}
|
|
14
|
-
export default $;
|
package/$each.mjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
*/ export function $each(selector, callback, parent, scope) {
|
|
11
|
-
const nodes = $$(selector, parent);
|
|
12
|
-
for(let i = 0; i < nodes.length; i++){
|
|
13
|
-
callback.call(scope, nodes[i], i);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export default $each;
|
package/README.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# @koine/dom
|
package/_listen-delegation.mjs
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
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
|
-
*/ import isString from "@koine/utils/isString";
|
|
10
|
-
import escapeSelector from "./escapeSelector";
|
|
11
|
-
/**
|
|
12
|
-
* Active events
|
|
13
|
-
*
|
|
14
|
-
* @internal
|
|
15
|
-
*/ export const activeEvents = {};
|
|
16
|
-
/**
|
|
17
|
-
* Get the index for the listener
|
|
18
|
-
*
|
|
19
|
-
* @internal
|
|
20
|
-
*/ export function getIndex(arr, selector, callback) {
|
|
21
|
-
for(let i = 0; i < arr.length; i++){
|
|
22
|
-
if (arr[i].selector === selector && arr[i].callback.toString() === callback.toString()) return i;
|
|
23
|
-
}
|
|
24
|
-
return -1;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Check if the listener callback should run or not
|
|
28
|
-
*
|
|
29
|
-
* @internal
|
|
30
|
-
* @param target The event.target
|
|
31
|
-
* @param selector The selector/element to check the target against
|
|
32
|
-
* @return If not false, run listener and pass the targeted element to use in the callback
|
|
33
|
-
*/ export function getRunTarget(target, selector) {
|
|
34
|
-
// @ts-expect-error FIXME: type
|
|
35
|
-
if ([
|
|
36
|
-
"*",
|
|
37
|
-
"window",
|
|
38
|
-
window
|
|
39
|
-
].includes(selector)) {
|
|
40
|
-
return window;
|
|
41
|
-
}
|
|
42
|
-
if ([
|
|
43
|
-
"document",
|
|
44
|
-
"document.documentElement",
|
|
45
|
-
document,
|
|
46
|
-
document.documentElement
|
|
47
|
-
].includes(selector)) return document;
|
|
48
|
-
if (isString(selector)) {
|
|
49
|
-
return target.closest(escapeSelector(selector));
|
|
50
|
-
}
|
|
51
|
-
// @ts-expect-error FIXME: type
|
|
52
|
-
if (typeof selector !== "string" && selector.contains) {
|
|
53
|
-
if (selector === target) {
|
|
54
|
-
return target;
|
|
55
|
-
}
|
|
56
|
-
// @ts-expect-error FIXME: type
|
|
57
|
-
if (selector.contains(target)) {
|
|
58
|
-
return selector;
|
|
59
|
-
}
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Handle listeners after event fires
|
|
66
|
-
*
|
|
67
|
-
* @internal
|
|
68
|
-
*/ export function eventHandler(event) {
|
|
69
|
-
// if (!activeEvents[event.type]) return;
|
|
70
|
-
activeEvents[event.type]?.forEach(function(listener) {
|
|
71
|
-
const target = getRunTarget(event.target, listener.selector);
|
|
72
|
-
if (!target) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
listener.callback(event, target);
|
|
76
|
-
});
|
|
77
|
-
}
|
package/calculateFixedOffset.mjs
DELETED
package/createElement.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
*/ export function createElement(type, className) {
|
|
9
|
-
const el = document.createElement(type);
|
|
10
|
-
if (className) {
|
|
11
|
-
addClass(el, className);
|
|
12
|
-
}
|
|
13
|
-
return el;
|
|
14
|
-
}
|
|
15
|
-
export default createElement;
|
package/emitEvent.mjs
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Emit event (use only if the targeted browser supports `CustomEvent`s)
|
|
3
|
-
*/ export function emitEvent(type = "customEvent", detail = {}) {
|
|
4
|
-
if (typeof window.CustomEvent !== "function") return;
|
|
5
|
-
document.dispatchEvent(new CustomEvent(type, {
|
|
6
|
-
bubbles: true,
|
|
7
|
-
detail
|
|
8
|
-
}));
|
|
9
|
-
}
|
|
10
|
-
export default emitEvent;
|
package/escapeSelector.mjs
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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
|
-
*/ export function escapeSelector(selector) {
|
|
7
|
-
return selector.replace(/:/g, "\\:");
|
|
8
|
-
}
|
|
9
|
-
export default escapeSelector;
|
package/exists.mjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if passed node exist and is a valid element.
|
|
3
|
-
*
|
|
4
|
-
* @borrows @glidejs/glide/src/utils/dom (source)
|
|
5
|
-
*/ export function exists(node) {
|
|
6
|
-
if (node && node instanceof window.HTMLElement) {
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
export default exists;
|
package/forEach.mjs
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* For each, iterate through a `NodeList` or an `array` of `HTMLElement`s
|
|
3
|
-
*
|
|
4
|
-
* @param scope The optional `this` of the callback function
|
|
5
|
-
*/ export function forEach(nodes, callback, scope) {
|
|
6
|
-
for(let i = 0; i < nodes.length; i++){
|
|
7
|
-
callback.call(scope, nodes[i], i);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export default forEach; // /**
|
|
11
|
-
// * For each, iterate through a `NodeList` or an `array` of `HTMLElement`s
|
|
12
|
-
// *
|
|
13
|
-
// * @param scope The optional `this` of the callback function
|
|
14
|
-
// */
|
|
15
|
-
// export function forEach<TScope = object>(
|
|
16
|
-
// nodes: HTMLElement[],
|
|
17
|
-
// callback: (this: TScope, $element: HTMLElement, index: number) => any,
|
|
18
|
-
// scope?: TScope
|
|
19
|
-
// ): void;
|
|
20
|
-
// export function forEach<TScope = object>(
|
|
21
|
-
// nodes: NodeListOf<HTMLElement> | HTMLElement[],
|
|
22
|
-
// callback: (this: TScope, $element: HTMLElement, index: number) => any,
|
|
23
|
-
// scope?: TScope
|
|
24
|
-
// ): void;
|
|
25
|
-
// export function forEach<T extends Element, TScope = object>(
|
|
26
|
-
// nodes: NodeListOf<T> | HTMLElement[],
|
|
27
|
-
// callback: (this: TScope, $element: T, index: number) => any,
|
|
28
|
-
// scope?: TScope
|
|
29
|
-
// ) {
|
|
30
|
-
// for (let i = 0; i < nodes.length; i++) {
|
|
31
|
-
// callback.call(scope as TScope, nodes[i] as T, i);
|
|
32
|
-
// }
|
|
33
|
-
// }
|
|
34
|
-
// export default forEach;
|
package/getDataAttr.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
*/ export function getDataAttr(element, attribute) {
|
|
9
|
-
// return element.dataset[attribute];
|
|
10
|
-
return element.getAttribute("data-" + attribute);
|
|
11
|
-
}
|
|
12
|
-
export default getDataAttr;
|
package/getListeners.mjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
*/ export function getListeners() {
|
|
9
|
-
const obj = {};
|
|
10
|
-
for(const type in activeEvents){
|
|
11
|
-
// if (activeEvents.hasOwnProperty(type)) {
|
|
12
|
-
obj[type] = activeEvents[type];
|
|
13
|
-
// }
|
|
14
|
-
}
|
|
15
|
-
return obj;
|
|
16
|
-
}
|
|
17
|
-
export default getListeners;
|
package/getOffset.mjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
*/ export function getOffset(elem) {
|
|
7
|
-
let left = 0;
|
|
8
|
-
let top = 0;
|
|
9
|
-
while(elem && !isNaN(elem.offsetLeft) && !isNaN(elem.offsetTop)){
|
|
10
|
-
left += elem.offsetLeft - elem.scrollLeft;
|
|
11
|
-
top += elem.offsetTop - elem.scrollTop;
|
|
12
|
-
// @ts-expect-error nevermind?
|
|
13
|
-
elem = elem.offsetParent;
|
|
14
|
-
}
|
|
15
|
-
return {
|
|
16
|
-
top,
|
|
17
|
-
left
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
export default getOffset;
|
package/getOffsetTop.mjs
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
*/ export function getOffsetTop(elem) {
|
|
9
|
-
let location = 0;
|
|
10
|
-
if (elem.offsetParent) {
|
|
11
|
-
while(elem){
|
|
12
|
-
location += elem.offsetTop;
|
|
13
|
-
// @ts-expect-error nevermind?
|
|
14
|
-
elem = elem.offsetParent;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return location >= 0 ? location : 0;
|
|
18
|
-
}
|
|
19
|
-
export default getOffsetTop;
|
package/getOffsetTopSlim.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get an element's distance from the top of the Document (using more modern/performant
|
|
3
|
-
* technique compared to {@link ./getOffsetTop})
|
|
4
|
-
*
|
|
5
|
-
* @see https://stackoverflow.com/q/5598743/1938970
|
|
6
|
-
*
|
|
7
|
-
* @param elem The HTML node element
|
|
8
|
-
* @return Distance from the top in pixels
|
|
9
|
-
*/ export function getOffsetTopSlim(elem) {
|
|
10
|
-
return elem.getBoundingClientRect().top + window.scrollY;
|
|
11
|
-
}
|
|
12
|
-
export default getOffsetTopSlim;
|
package/getStyleValue.mjs
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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
|
-
*/ export function getStyleValue(el, prop) {
|
|
7
|
-
return getComputedStyle(el, null).getPropertyValue(prop);
|
|
8
|
-
}
|
|
9
|
-
export default getStyleValue;
|
|
@@ -1,19 +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
|
-
*/ export function getVisualBackgroundColor(elem) {
|
|
5
|
-
if (!elem) return "#fff";
|
|
6
|
-
const transparent = "rgba(0, 0, 0, 0)";
|
|
7
|
-
const transparentIE11 = "transparent";
|
|
8
|
-
// if (!elem) return transparent;
|
|
9
|
-
const bg = window.getComputedStyle(elem).backgroundColor;
|
|
10
|
-
if (bg === transparent || bg === transparentIE11) {
|
|
11
|
-
const parent = elem.parentElement;
|
|
12
|
-
if (parent) {
|
|
13
|
-
return getVisualBackgroundColor(parent);
|
|
14
|
-
}
|
|
15
|
-
return "#fff";
|
|
16
|
-
}
|
|
17
|
-
return bg;
|
|
18
|
-
}
|
|
19
|
-
export default getVisualBackgroundColor;
|
package/index.mjs
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export { $$ } from "./$$";
|
|
2
|
-
export { $each } from "./$each";
|
|
3
|
-
export { $ } from "./$";
|
|
4
|
-
export { addClass } from "./addClass";
|
|
5
|
-
export { calculateFixedOffset } from "./calculateFixedOffset";
|
|
6
|
-
export { createElement } from "./createElement";
|
|
7
|
-
export { emitEvent } from "./emitEvent";
|
|
8
|
-
export { escapeSelector } from "./escapeSelector";
|
|
9
|
-
export { exists } from "./exists";
|
|
10
|
-
export { forEach } from "./forEach";
|
|
11
|
-
export { getDataAttr } from "./getDataAttr";
|
|
12
|
-
export { getDocumentHeight } from "./getDocumentHeight";
|
|
13
|
-
export { getHeight } from "./getHeight";
|
|
14
|
-
export { getListeners } from "./getListeners";
|
|
15
|
-
export { getOffset } from "./getOffset";
|
|
16
|
-
export { getOffsetTop } from "./getOffsetTop";
|
|
17
|
-
export { getOffsetTopSlim } from "./getOffsetTopSlim";
|
|
18
|
-
export { getScrollbarWidth } from "./getScrollbarWidth";
|
|
19
|
-
export { getStyleValue } from "./getStyleValue";
|
|
20
|
-
export { getVisualBackgroundColor } from "./getVisualBackgroundColor";
|
|
21
|
-
export { injectCss } from "./injectCss";
|
|
22
|
-
export { isHidden } from "./isHidden";
|
|
23
|
-
export { isInViewport } from "./isInViewport";
|
|
24
|
-
export { isNodeList } from "./isNodeList";
|
|
25
|
-
export { isTotallyScrolled } from "./isTotallyScrolled";
|
|
26
|
-
export { listenLoaded } from "./listenLoaded";
|
|
27
|
-
export { listenOnce } from "./listenOnce";
|
|
28
|
-
export { listenResize } from "./listenResize";
|
|
29
|
-
export { listenResizeDebounced } from "./listenResizeDebounced";
|
|
30
|
-
export { listenResizeThrottled } from "./listenResizeThrottled";
|
|
31
|
-
export { listenScroll } from "./listenScroll";
|
|
32
|
-
export { listenScrollDebounced } from "./listenScrollDebounced";
|
|
33
|
-
export { listenScrollThrottled } from "./listenScrollThrottled";
|
|
34
|
-
export { listen } from "./listen";
|
|
35
|
-
export { off } from "./off";
|
|
36
|
-
export { once } from "./once";
|
|
37
|
-
export { onClickOutside } from "./onClickOutside";
|
|
38
|
-
export { on } from "./on";
|
|
39
|
-
export { removeClass } from "./removeClass";
|
|
40
|
-
export { scrollTo } from "./scrollTo";
|
|
41
|
-
export { setDataAttr } from "./setDataAttr";
|
|
42
|
-
export { setVendorCSS } from "./setVendorCSS";
|
|
43
|
-
export { siblings } from "./siblings";
|
|
44
|
-
export { toArray } from "./toArray";
|
|
45
|
-
export { unlisten } from "./unlisten";
|
package/isInViewport.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Determine if an element is in the viewport
|
|
3
|
-
*
|
|
4
|
-
* @borrows (c) 2017 Chris Ferdinandi, MIT License, https://gomakethings.com
|
|
5
|
-
*
|
|
6
|
-
* @param elem The element
|
|
7
|
-
* @return Returns true if element is in the viewport
|
|
8
|
-
*/ export function isInViewport(elem) {
|
|
9
|
-
const distance = elem.getBoundingClientRect();
|
|
10
|
-
return distance.top >= 0 && distance.left >= 0 && distance.bottom <= (window.innerHeight || document.documentElement.clientHeight) && distance.right <= (window.innerWidth || document.documentElement.clientWidth);
|
|
11
|
-
}
|
|
12
|
-
export default isInViewport;
|
package/isNodeList.mjs
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Is node list
|
|
3
|
-
*
|
|
4
|
-
* @param nodes The object to check
|
|
5
|
-
*/ export function isNodeList(nodes) {
|
|
6
|
-
const stringRepr = Object.prototype.toString.call(nodes);
|
|
7
|
-
return typeof nodes === "object" && /^\[object (HTMLCollection|NodeList|Object)\]$/.test(stringRepr) && typeof nodes.length === "number" && (nodes.length === 0 || typeof nodes[0] === "object" && nodes[0].nodeType > 0);
|
|
8
|
-
}
|
|
9
|
-
export default isNodeList;
|
package/isTotallyScrolled.mjs
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Is element totally scrolled
|
|
3
|
-
*
|
|
4
|
-
* @see https://github.com/willmcpo/body-scroll-lock/blob/master/src/bodyScrollLock.js#L116
|
|
5
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight#Problems_and_solutions
|
|
6
|
-
*/ export function isTotallyScrolled(el) {
|
|
7
|
-
return el ? el.scrollHeight - el.scrollTop <= el.clientHeight : false;
|
|
8
|
-
}
|
|
9
|
-
export default isTotallyScrolled;
|
package/listen.mjs
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { activeEvents, eventHandler } from "./_listen-delegation";
|
|
2
|
-
import { on } from "./on";
|
|
3
|
-
// import { off } from "./off";
|
|
4
|
-
/**
|
|
5
|
-
* Listen an event
|
|
6
|
-
*
|
|
7
|
-
* @category listen-delegation
|
|
8
|
-
*
|
|
9
|
-
* @param types The event type or types (comma separated)
|
|
10
|
-
* @param selector The selector to run the event on
|
|
11
|
-
* @param callback The function to run when the event fires
|
|
12
|
-
*/ export function listen(types, // | `${TTypes},${TTypes}`
|
|
13
|
-
// | `${TTypes},${TTypes},${TTypes}`
|
|
14
|
-
// | `${TTypes},${TTypes},${TTypes},${TTypes}`
|
|
15
|
-
// | `${TTypes},${TTypes},${TTypes},${TTypes},${TTypes}`,
|
|
16
|
-
selector, callback) {
|
|
17
|
-
// Make sure there's a selector and callback
|
|
18
|
-
if (!selector || !callback) return;
|
|
19
|
-
// Loop through each event type
|
|
20
|
-
types.split(",").forEach(function(type) {
|
|
21
|
-
// Remove whitespace
|
|
22
|
-
type = type.trim();
|
|
23
|
-
// If no event of this type yet, setup
|
|
24
|
-
if (!activeEvents[type]) {
|
|
25
|
-
activeEvents[type] = [];
|
|
26
|
-
on(window, type, eventHandler, true);
|
|
27
|
-
}
|
|
28
|
-
// Push to active events
|
|
29
|
-
activeEvents[type]?.push({
|
|
30
|
-
selector: selector,
|
|
31
|
-
// @ts-expect-error FIXME: type...
|
|
32
|
-
callback: callback
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
export default listen;
|
package/listenLoaded.mjs
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { on } from "./on";
|
|
2
|
-
/**
|
|
3
|
-
* Fires a callback when the DOM content is loaded
|
|
4
|
-
*
|
|
5
|
-
* @see https://mathiasbynens.be/notes/settimeout-onload
|
|
6
|
-
*/ export function listenLoaded(handler) {
|
|
7
|
-
on(document, "DOMContentLoaded", handler);
|
|
8
|
-
// document.addEventListener("DOMContentLoaded", setTimeout(handler, 4));
|
|
9
|
-
}
|
|
10
|
-
export default listenLoaded;
|
package/listenOnce.mjs
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { getRunTarget } from "./_listen-delegation";
|
|
2
|
-
import { listen } from "./listen";
|
|
3
|
-
import { unlisten } from "./unlisten";
|
|
4
|
-
/**
|
|
5
|
-
* Listen an event, and automatically unlisten it after it's first run
|
|
6
|
-
*
|
|
7
|
-
* @category listen-delegation
|
|
8
|
-
*
|
|
9
|
-
* @param types The event type or types (comma separated)
|
|
10
|
-
* @param selector The selector to run the event on
|
|
11
|
-
* @param callback The function to run when the event fires
|
|
12
|
-
*/ export function listenOnce(types, selector, callback) {
|
|
13
|
-
listen(types, selector, function temp(event) {
|
|
14
|
-
const target = getRunTarget(event.target, selector);
|
|
15
|
-
callback(event, target || window);
|
|
16
|
-
unlisten(types, selector, temp);
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
export default listenOnce;
|
package/listenResize.mjs
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { on } from "./on";
|
|
2
|
-
/**
|
|
3
|
-
* Listen element's (`window` by default) _scroll_ event
|
|
4
|
-
*
|
|
5
|
-
* @returns An automatic unbinding function to run to deregister the listener upon call
|
|
6
|
-
*/ export const listenResize = (handler, el)=>on(el || window, "resize", handler);
|
|
7
|
-
export default listenResize;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import debounce from "@koine/utils/debounce";
|
|
2
|
-
import listenResize from "./listenResize";
|
|
3
|
-
/**
|
|
4
|
-
* Listen element's (`window` by default) _resize_ event debouncing the callback
|
|
5
|
-
*
|
|
6
|
-
* @returns An automatic unbinding function to run to deregister the listener upon call
|
|
7
|
-
*/ export const listenResizeDebounced = (el, ...args)=>listenResize(debounce(...args), el);
|
|
8
|
-
export default listenResizeDebounced; // EXP: with too complex overload signature...
|
|
9
|
-
// import debounce from "@koine/utils/debounce";
|
|
10
|
-
// import isUndefined from "@koine/utils/isUndefined";
|
|
11
|
-
// import listenResize from "./listenResize";
|
|
12
|
-
// /**
|
|
13
|
-
// * Listen element's (`window` by default) _resize_ event debouncing the callback
|
|
14
|
-
// *
|
|
15
|
-
// * @returns An automatic unbinding function to run to deregister the listener upon call
|
|
16
|
-
// */
|
|
17
|
-
// export function listenResizeDebounced(
|
|
18
|
-
// ...args: Parameters<typeof debounce>
|
|
19
|
-
// ): ReturnType<typeof listenResize>;
|
|
20
|
-
// export function listenResizeDebounced(
|
|
21
|
-
// el: Parameters<typeof listenResize>[1],
|
|
22
|
-
// ...args: Parameters<typeof debounce>
|
|
23
|
-
// ): ReturnType<typeof listenResize>;
|
|
24
|
-
// export function listenResizeDebounced(
|
|
25
|
-
// ...args:
|
|
26
|
-
// | [Parameters<typeof listenResize>[1], ...Parameters<typeof debounce>]
|
|
27
|
-
// | Parameters<typeof debounce>
|
|
28
|
-
// ) {
|
|
29
|
-
// if (isUndefined(args[0])) {
|
|
30
|
-
// return listenResize(debounce(...args));
|
|
31
|
-
// }
|
|
32
|
-
// return listenResize(debounce(...args.slice(1)), args[0]);
|
|
33
|
-
// }
|
|
34
|
-
// export default listenResizeDebounced;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import throttle from "@koine/utils/throttle";
|
|
2
|
-
import { listenResize } from "./listenResize";
|
|
3
|
-
/**
|
|
4
|
-
* Listen element's (`window` by default) _resize_ event throttling the callback
|
|
5
|
-
*
|
|
6
|
-
* @returns An automatic unbinding function to run to deregister the listener upon call
|
|
7
|
-
*/ export const listenResizeThrottled = (el, ...args)=>listenResize(throttle(...args), el);
|
|
8
|
-
export default listenResizeThrottled;
|
package/listenScroll.mjs
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { on } from "./on";
|
|
2
|
-
/**
|
|
3
|
-
* Listen element's (`window` by default) _scroll_ event
|
|
4
|
-
*
|
|
5
|
-
* @returns An automatic unbinding function to run to deregister the listener upon call
|
|
6
|
-
*/ export const listenScroll = (handler, el)=>on(el || window, "scroll", handler, {
|
|
7
|
-
capture: true,
|
|
8
|
-
passive: true
|
|
9
|
-
});
|
|
10
|
-
export default listenScroll;
|