@koine/dom 2.0.0-beta.2 → 2.0.0-beta.21
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 +1 -12
- package/$.js +2 -17
- package/$all.d.ts +2 -0
- package/$all.js +4 -0
- package/$each.d.ts +0 -9
- package/$each.js +4 -18
- package/_listen-delegation.d.ts +3 -31
- package/_listen-delegation.js +10 -54
- package/addClass.d.ts +0 -3
- package/addClass.js +3 -10
- package/calculateFixedOffset.d.ts +0 -0
- package/calculateFixedOffset.js +4 -8
- package/createElement.d.ts +2 -8
- package/createElement.js +4 -16
- package/emitEvent.d.ts +0 -3
- package/emitEvent.js +2 -9
- package/escapeSelector.d.ts +0 -6
- package/escapeSelector.js +2 -12
- package/exists.d.ts +0 -5
- package/exists.js +2 -11
- package/forEach.d.ts +1 -8
- package/forEach.js +2 -13
- package/getDataAttr.d.ts +0 -6
- package/getDataAttr.js +2 -15
- package/getDocumentHeight.d.ts +0 -5
- package/getDocumentHeight.js +2 -11
- package/getHeight.d.ts +0 -3
- package/getHeight.js +2 -9
- package/getListeners.d.ts +1 -8
- package/getListeners.js +5 -18
- package/getOffset.d.ts +0 -6
- package/getOffset.js +2 -13
- package/getOffsetTop.d.ts +0 -8
- package/getOffsetTop.js +2 -15
- package/getOffsetTopSlim.d.ts +0 -9
- package/getOffsetTopSlim.js +2 -15
- package/getScrollbarWidth.d.ts +0 -3
- package/getScrollbarWidth.js +2 -9
- package/getStyleValue.d.ts +0 -6
- package/getStyleValue.js +2 -12
- package/getVisualBackgroundColor.d.ts +0 -4
- package/getVisualBackgroundColor.js +2 -11
- package/index.d.ts +46 -46
- package/index.js +45 -93
- package/injectCss.d.ts +0 -3
- package/injectCss.js +2 -9
- package/isHidden.d.ts +0 -3
- package/isHidden.js +2 -9
- package/isInViewport.d.ts +0 -8
- package/isInViewport.js +2 -14
- package/isNodeList.d.ts +1 -6
- package/isNodeList.js +2 -11
- package/isTotallyScrolled.d.ts +0 -6
- package/isTotallyScrolled.js +2 -12
- package/listen.d.ts +3 -11
- package/listen.js +9 -27
- package/listenLoaded.d.ts +0 -5
- package/listenLoaded.js +4 -14
- package/listenOnce.d.ts +1 -10
- package/listenOnce.js +8 -21
- package/listenResize.d.ts +1 -6
- package/listenResize.js +3 -12
- package/listenResizeDebounced.d.ts +1 -6
- package/listenResizeDebounced.js +6 -42
- package/listenResizeThrottled.d.ts +1 -6
- package/listenResizeThrottled.js +6 -15
- package/listenScroll.d.ts +1 -6
- package/listenScroll.js +4 -13
- package/listenScrollDebounced.d.ts +1 -6
- package/listenScrollDebounced.js +6 -15
- package/listenScrollThrottled.d.ts +1 -6
- package/listenScrollThrottled.js +6 -15
- package/off.d.ts +2 -5
- package/off.js +3 -10
- package/on.d.ts +2 -7
- package/on.js +5 -16
- package/onClickOutside.d.ts +0 -0
- package/onClickOutside.js +4 -9
- package/once.d.ts +1 -5
- package/once.js +6 -15
- package/package.json +148 -9
- package/removeClass.d.ts +0 -3
- package/removeClass.js +3 -10
- package/scrollTo.d.ts +0 -10
- package/scrollTo.js +7 -21
- package/setDataAttr.d.ts +0 -7
- package/setDataAttr.js +2 -16
- package/setVendorCSS.d.ts +0 -7
- package/setVendorCSS.js +2 -18
- package/siblings.d.ts +0 -5
- package/siblings.js +2 -11
- package/toArray.d.ts +0 -5
- package/toArray.js +2 -11
- package/types.d.ts +6 -5
- package/types.js +1 -2
- package/unlisten.d.ts +3 -11
- package/unlisten.js +10 -28
- package/$$.d.ts +0 -10
- package/$$.js +0 -16
- package/$$.mjs +0 -12
- package/$.mjs +0 -15
- package/$each.mjs +0 -17
- package/README.md +0 -1
- package/_listen-delegation.mjs +0 -83
- package/addClass.mjs +0 -15
- package/calculateFixedOffset.mjs +0 -10
- package/createElement.mjs +0 -16
- package/emitEvent.mjs +0 -14
- package/escapeSelector.mjs +0 -10
- package/exists.mjs +0 -12
- package/forEach.mjs +0 -13
- package/getDataAttr.mjs +0 -13
- package/getDocumentHeight.mjs +0 -10
- package/getHeight.mjs +0 -7
- package/getListeners.mjs +0 -18
- package/getOffset.mjs +0 -18
- package/getOffsetTop.mjs +0 -20
- package/getOffsetTopSlim.mjs +0 -13
- package/getScrollbarWidth.mjs +0 -7
- package/getStyleValue.mjs +0 -10
- package/getVisualBackground.d.ts +0 -6
- package/getVisualBackground.js +0 -25
- package/getVisualBackground.mjs +0 -21
- package/getVisualBackgroundColor.mjs +0 -21
- package/index.mjs +0 -45
- package/injectCss.mjs +0 -16
- package/isHidden.mjs +0 -7
- package/isInViewport.mjs +0 -18
- package/isNodeList.mjs +0 -14
- package/isTotallyScrolled.mjs +0 -10
- package/listen.mjs +0 -33
- package/listenLoaded.mjs +0 -11
- package/listenOnce.mjs +0 -20
- package/listenResize.mjs +0 -8
- package/listenResizeDebounced.mjs +0 -42
- package/listenResizeThrottled.mjs +0 -15
- package/listenScroll.mjs +0 -13
- package/listenScrollDebounced.mjs +0 -15
- package/listenScrollThrottled.mjs +0 -15
- package/off.mjs +0 -14
- package/on.mjs +0 -21
- package/onClickOutside.mjs +0 -17
- package/once.mjs +0 -15
- package/removeClass.mjs +0 -15
- package/scrollTo.mjs +0 -40
- package/setDataAttr.mjs +0 -18
- package/setVendorCSS.mjs +0 -21
- package/siblings.mjs +0 -19
- package/toArray.mjs +0 -9
- package/types.mjs +0 -1
- package/unlisten.mjs +0 -33
package/scrollTo.js
CHANGED
|
@@ -1,35 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var on_1 = require("./on");
|
|
5
|
-
var off_1 = require("./off");
|
|
6
|
-
/**
|
|
7
|
-
* Native `scrollTo`, `"smooth"` and with callback
|
|
8
|
-
*
|
|
9
|
-
* @borrows https://stackoverflow.com/a/55686711/1938970
|
|
10
|
-
*
|
|
11
|
-
* @param offset - offset to scroll to
|
|
12
|
-
* @param callback - callback function
|
|
13
|
-
* @param [fallbackTimeout] - this appears to be needed in some hard to reproduce scenario on safari, where the callback seem to be never called
|
|
14
|
-
* @param [behavior="smooth"]
|
|
15
|
-
*/
|
|
16
|
-
function scrollTo(destination, callback, fallbackTimeout, behavior) {
|
|
1
|
+
import { off } from "./off.js";
|
|
2
|
+
import { on } from "./on.js";
|
|
3
|
+
export function scrollTo(destination, callback, fallbackTimeout, behavior) {
|
|
17
4
|
var fixedDestination = destination.toFixed();
|
|
18
5
|
if (callback) {
|
|
19
6
|
var callbackFired_1 = false;
|
|
20
7
|
var onScroll_1 = function () {
|
|
21
8
|
if (window.pageYOffset.toFixed() === fixedDestination) {
|
|
22
|
-
|
|
9
|
+
off(window, "scroll", onScroll_1);
|
|
23
10
|
callbackFired_1 = true;
|
|
24
11
|
callback();
|
|
25
12
|
}
|
|
26
13
|
};
|
|
27
|
-
|
|
14
|
+
on(window, "scroll", onScroll_1);
|
|
28
15
|
onScroll_1();
|
|
29
16
|
if (fallbackTimeout) {
|
|
30
17
|
setTimeout(function () {
|
|
31
18
|
if (!callbackFired_1) {
|
|
32
|
-
|
|
19
|
+
off(window, "scroll", onScroll_1);
|
|
33
20
|
callback();
|
|
34
21
|
}
|
|
35
22
|
}, fallbackTimeout);
|
|
@@ -40,5 +27,4 @@ function scrollTo(destination, callback, fallbackTimeout, behavior) {
|
|
|
40
27
|
behavior: behavior || "smooth",
|
|
41
28
|
});
|
|
42
29
|
}
|
|
43
|
-
|
|
44
|
-
exports.default = scrollTo;
|
|
30
|
+
export default scrollTo;
|
package/setDataAttr.d.ts
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Set data attribute
|
|
3
|
-
*
|
|
4
|
-
* @param element
|
|
5
|
-
* @param attribute The name of the `data-{attr}`
|
|
6
|
-
* @param value The value to set, `null` or `undefined` will remove the attribute
|
|
7
|
-
*/
|
|
8
1
|
export declare function setDataAttr(element: Element, attribute: string, value?: string | number | null | boolean): void;
|
|
9
2
|
export default setDataAttr;
|
package/setDataAttr.js
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setDataAttr = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Set data attribute
|
|
6
|
-
*
|
|
7
|
-
* @param element
|
|
8
|
-
* @param attribute The name of the `data-{attr}`
|
|
9
|
-
* @param value The value to set, `null` or `undefined` will remove the attribute
|
|
10
|
-
*/
|
|
11
|
-
function setDataAttr(element, attribute, value) {
|
|
1
|
+
export function setDataAttr(element, attribute, value) {
|
|
12
2
|
if (value === null || typeof value === "undefined") {
|
|
13
|
-
// delete element.dataset[attribute];
|
|
14
|
-
// return;
|
|
15
3
|
element.removeAttribute("data-" + attribute);
|
|
16
4
|
return;
|
|
17
5
|
}
|
|
18
|
-
// element.dataset[attribute] = value.toString();
|
|
19
6
|
element.setAttribute("data-" + attribute, value.toString());
|
|
20
7
|
}
|
|
21
|
-
|
|
22
|
-
exports.default = setDataAttr;
|
|
8
|
+
export default setDataAttr;
|
package/setVendorCSS.d.ts
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Set vendor CSS rule
|
|
3
|
-
*
|
|
4
|
-
* @param element A single HTMLElement
|
|
5
|
-
* @param prop CSS rule proerty
|
|
6
|
-
* @param value The CSS value to set, it will be automatically vendor prefixed
|
|
7
|
-
*/
|
|
8
1
|
export declare function setVendorCSS(element: HTMLElement, prop: string, value: string | number | boolean): void;
|
|
9
2
|
export default setVendorCSS;
|
package/setVendorCSS.js
CHANGED
|
@@ -1,25 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setVendorCSS = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Set vendor CSS rule
|
|
6
|
-
*
|
|
7
|
-
* @param element A single HTMLElement
|
|
8
|
-
* @param prop CSS rule proerty
|
|
9
|
-
* @param value The CSS value to set, it will be automatically vendor prefixed
|
|
10
|
-
*/
|
|
11
|
-
function setVendorCSS(element, prop, value) {
|
|
1
|
+
export function setVendorCSS(element, prop, value) {
|
|
12
2
|
var propUpper = prop.charAt(0).toUpperCase() + prop.slice(1);
|
|
13
|
-
// @ts-expect-error nevermind now...
|
|
14
3
|
element.style["webkit" + propUpper] = value;
|
|
15
|
-
// @ts-expect-error nevermind now...
|
|
16
4
|
element.style["moz" + propUpper] = value;
|
|
17
|
-
// @ts-expect-error nevermind now...
|
|
18
5
|
element.style["ms" + propUpper] = value;
|
|
19
|
-
// @ts-expect-error nevermind now...
|
|
20
6
|
element.style["o" + propUpper] = value;
|
|
21
|
-
// @ts-expect-error nevermind now...
|
|
22
7
|
element.style[prop] = value;
|
|
23
8
|
}
|
|
24
|
-
|
|
25
|
-
exports.default = setVendorCSS;
|
|
9
|
+
export default setVendorCSS;
|
package/siblings.d.ts
CHANGED
package/siblings.js
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.siblings = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Finds siblings nodes of the passed node.
|
|
6
|
-
*
|
|
7
|
-
* @borrows @glidejs/glide/src/utils/dom (source)
|
|
8
|
-
*/
|
|
9
|
-
function siblings(node) {
|
|
1
|
+
export function siblings(node) {
|
|
10
2
|
if (node && node.parentNode) {
|
|
11
3
|
var n = node.parentNode.firstChild;
|
|
12
4
|
var matched = [];
|
|
@@ -19,5 +11,4 @@ function siblings(node) {
|
|
|
19
11
|
}
|
|
20
12
|
return [];
|
|
21
13
|
}
|
|
22
|
-
|
|
23
|
-
exports.default = siblings;
|
|
14
|
+
export default siblings;
|
package/toArray.d.ts
CHANGED
package/toArray.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toArray = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Node list to array
|
|
6
|
-
*
|
|
7
|
-
* @param nodeList
|
|
8
|
-
*/
|
|
9
|
-
function toArray(nodeList) {
|
|
1
|
+
export function toArray(nodeList) {
|
|
10
2
|
return Array.prototype.slice.call(nodeList);
|
|
11
3
|
}
|
|
12
|
-
|
|
13
|
-
exports.default = toArray;
|
|
4
|
+
export default toArray;
|
package/types.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { LiteralUnion } from "type-fest";
|
|
2
|
+
import type { AnythingFalsy } from "@koine/utils";
|
|
2
3
|
export type AnyDOMEventTarget = Window | Document | HTMLElement | Element;
|
|
3
|
-
/**
|
|
4
|
-
* We use it either throwing an error on unexisting element or falling back
|
|
5
|
-
* to `window` in case of _scroll_ or _resize_ events
|
|
6
|
-
*/
|
|
7
4
|
export type AnyDOMEventTargetLoose = AnyDOMEventTarget | AnythingFalsy;
|
|
5
|
+
type StandardDOMEventTypes = keyof GlobalEventHandlersEventMap;
|
|
6
|
+
export type AnyDOMEventType = LiteralUnion<StandardDOMEventTypes | "storage" | "popstate", string>;
|
|
7
|
+
export type AnyDOMEvent<TType extends AnyDOMEventType> = TType extends StandardDOMEventTypes ? GlobalEventHandlersEventMap[TType] : TType extends "storage" ? StorageEvent : TType extends "popstate" ? PopStateEvent : Event;
|
|
8
|
+
export {};
|
package/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/unlisten.d.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import { type EventCallback } from "./_listen-delegation";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
5
|
-
* @category listen-delegation
|
|
6
|
-
*
|
|
7
|
-
* @param types The event type or types (comma separated)
|
|
8
|
-
* @param selector The selector to remove the event from
|
|
9
|
-
* @param callback The function to remove
|
|
10
|
-
*/
|
|
11
|
-
export declare function unlisten(types: string, selector: string, callback: EventCallback): void;
|
|
1
|
+
import { type EventCallback } from "./_listen-delegation.js";
|
|
2
|
+
import type { AnyDOMEventTarget, AnyDOMEventType } from "./types.js";
|
|
3
|
+
export declare function unlisten<TTypes extends AnyDOMEventType, TTarget extends AnyDOMEventTarget = AnyDOMEventTarget>(types: TTypes, selector: string, callback: EventCallback<TTarget, TTypes>): void;
|
|
12
4
|
export default unlisten;
|
package/unlisten.js
CHANGED
|
@@ -1,37 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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) {
|
|
16
|
-
// Loop through each event type
|
|
1
|
+
import { activeEvents, eventHandler, getIndex, } from "./_listen-delegation.js";
|
|
2
|
+
import { off } from "./off.js";
|
|
3
|
+
export function unlisten(types, selector, callback) {
|
|
17
4
|
types.split(",").forEach(function (type) {
|
|
18
|
-
// Remove whitespace
|
|
19
5
|
type = type.trim();
|
|
20
|
-
|
|
21
|
-
if (!_listen_delegation_1.activeEvents[type])
|
|
6
|
+
if (!activeEvents[type])
|
|
22
7
|
return;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
(0, off_1.off)(window, type, _listen_delegation_1.eventHandler, true);
|
|
8
|
+
if (activeEvents[type].length < 2 || !selector) {
|
|
9
|
+
delete activeEvents[type];
|
|
10
|
+
off(window, type, eventHandler, true);
|
|
27
11
|
return;
|
|
28
12
|
}
|
|
29
|
-
|
|
30
|
-
var index = (0, _listen_delegation_1.getIndex)(_listen_delegation_1.activeEvents[type], selector, callback);
|
|
13
|
+
var index = getIndex(activeEvents[type], selector, callback);
|
|
31
14
|
if (index < 0)
|
|
32
15
|
return;
|
|
33
|
-
|
|
16
|
+
activeEvents[type].splice(index, 1);
|
|
34
17
|
});
|
|
35
18
|
}
|
|
36
|
-
|
|
37
|
-
exports.default = unlisten;
|
|
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?: HTMLElement | Document, avoidEscape?: boolean): NodeListOf<T>;
|
|
10
|
-
export default $$;
|
package/$$.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.$$ = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Sizzle/jQuery like DOM nodes shortcut for `document.querySelectorAll`
|
|
6
|
-
* To avoid an extra function call we inline the above `escape`
|
|
7
|
-
*
|
|
8
|
-
* @param string selector DOM selector
|
|
9
|
-
* @param parent It falls back to `window.document`
|
|
10
|
-
* @param avoidEscape Whether to avoid escaping `:` in the selector string
|
|
11
|
-
*/
|
|
12
|
-
function $$(selector, parent, avoidEscape) {
|
|
13
|
-
return (parent ? parent : document).querySelectorAll(avoidEscape ? selector : selector.replace(/:/g, "\\:"));
|
|
14
|
-
}
|
|
15
|
-
exports.$$ = $$;
|
|
16
|
-
exports.default = $$;
|
package/$$.mjs
DELETED
|
@@ -1,12 +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 function $$(selector, parent, avoidEscape) {
|
|
10
|
-
return (parent ? parent : document).querySelectorAll(avoidEscape ? selector : selector.replace(/:/g, "\\:"));
|
|
11
|
-
}
|
|
12
|
-
export default $$;
|
package/$.mjs
DELETED
|
@@ -1,15 +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
|
-
*/
|
|
12
|
-
export function $(selector, parent, avoidEscape) {
|
|
13
|
-
return (parent ? parent : document).querySelector(avoidEscape ? selector : selector.replace(/:/g, "\\:"));
|
|
14
|
-
}
|
|
15
|
-
export default $;
|
package/$each.mjs
DELETED
|
@@ -1,17 +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
|
-
*/
|
|
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
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# @koine/dom
|
package/_listen-delegation.mjs
DELETED
|
@@ -1,83 +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
|
-
*/
|
|
10
|
-
import isString from "@koine/utils/isString";
|
|
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.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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;
|
package/calculateFixedOffset.mjs
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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;
|
package/createElement.mjs
DELETED
|
@@ -1,16 +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
|
-
*/
|
|
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.mjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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;
|
package/escapeSelector.mjs
DELETED
|
@@ -1,10 +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
|
-
*/
|
|
7
|
-
export function escapeSelector(selector) {
|
|
8
|
-
return selector.replace(/:/g, "\\:");
|
|
9
|
-
}
|
|
10
|
-
export default escapeSelector;
|
package/exists.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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.mjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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.mjs
DELETED
|
@@ -1,13 +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
|
-
*/
|
|
9
|
-
export function getDataAttr(element, attribute) {
|
|
10
|
-
// return element.dataset[attribute];
|
|
11
|
-
return element.getAttribute("data-" + attribute);
|
|
12
|
-
}
|
|
13
|
-
export default getDataAttr;
|
package/getDocumentHeight.mjs
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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.mjs
DELETED
package/getListeners.mjs
DELETED
|
@@ -1,18 +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
|
-
*/
|
|
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.mjs
DELETED
|
@@ -1,18 +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
|
-
*/
|
|
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;
|
package/getOffsetTop.mjs
DELETED
|
@@ -1,20 +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
|
-
*/
|
|
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/getOffsetTopSlim.mjs
DELETED
|
@@ -1,13 +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
|
-
*/
|
|
10
|
-
export function getOffsetTopSlim(elem) {
|
|
11
|
-
return elem.getBoundingClientRect().top + window.scrollY;
|
|
12
|
-
}
|
|
13
|
-
export default getOffsetTopSlim;
|