@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/injectCss.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inject css
|
|
3
|
+
*/
|
|
4
|
+
export function injectCss(id, cssString, root) {
|
|
5
|
+
if (cssString === void 0) { cssString = ""; }
|
|
6
|
+
if (root === void 0) { root = document; }
|
|
7
|
+
var styleblock;
|
|
8
|
+
styleblock = root.getElementById(id);
|
|
9
|
+
if (!styleblock) {
|
|
10
|
+
styleblock = root.createElement("style");
|
|
11
|
+
styleblock.id = id;
|
|
12
|
+
root.body.appendChild(styleblock);
|
|
13
|
+
}
|
|
14
|
+
styleblock.innerHTML = cssString;
|
|
15
|
+
}
|
|
16
|
+
export default injectCss;
|
package/isHidden.d.ts
ADDED
package/isHidden.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
*/
|
|
9
|
+
export declare function isInViewport(elem: Element): boolean;
|
|
10
|
+
export default isInViewport;
|
package/isInViewport.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
*/
|
|
9
|
+
export function isInViewport(elem) {
|
|
10
|
+
var distance = elem.getBoundingClientRect();
|
|
11
|
+
return (distance.top >= 0 &&
|
|
12
|
+
distance.left >= 0 &&
|
|
13
|
+
distance.bottom <=
|
|
14
|
+
(window.innerHeight || document.documentElement.clientHeight) &&
|
|
15
|
+
distance.right <=
|
|
16
|
+
(window.innerWidth || document.documentElement.clientWidth));
|
|
17
|
+
}
|
|
18
|
+
export default isInViewport;
|
package/isNodeList.d.ts
ADDED
package/isNodeList.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Is node list
|
|
3
|
+
*
|
|
4
|
+
* @param nodes The object to check
|
|
5
|
+
*/
|
|
6
|
+
export function isNodeList(nodes) {
|
|
7
|
+
var stringRepr = Object.prototype.toString.call(nodes);
|
|
8
|
+
return (typeof nodes === "object" &&
|
|
9
|
+
/^\[object (HTMLCollection|NodeList|Object)\]$/.test(stringRepr) &&
|
|
10
|
+
typeof nodes.length === "number" &&
|
|
11
|
+
(nodes.length === 0 ||
|
|
12
|
+
(typeof nodes[0] === "object" && nodes[0].nodeType > 0)));
|
|
13
|
+
}
|
|
14
|
+
export default isNodeList;
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
*/
|
|
7
|
+
export declare function isTotallyScrolled(el?: HTMLElement): boolean;
|
|
8
|
+
export default isTotallyScrolled;
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
*/
|
|
7
|
+
export function isTotallyScrolled(el) {
|
|
8
|
+
return el ? el.scrollHeight - el.scrollTop <= el.clientHeight : false;
|
|
9
|
+
}
|
|
10
|
+
export default isTotallyScrolled;
|
package/listen.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type EventCallback } from "./_listen-delegation";
|
|
2
|
+
/**
|
|
3
|
+
* Listen an event
|
|
4
|
+
*
|
|
5
|
+
* @category listen-delegation
|
|
6
|
+
*
|
|
7
|
+
* @param types The event type or types (comma separated)
|
|
8
|
+
* @param selector The selector to run the event on
|
|
9
|
+
* @param callback The function to run when the event fires
|
|
10
|
+
*/
|
|
11
|
+
export declare function listen(types: string, selector: string, callback: EventCallback): void;
|
|
12
|
+
export default listen;
|
package/listen.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { activeEvents, eventHandler, } from "./_listen-delegation";
|
|
2
|
+
import { on } from "./on";
|
|
3
|
+
/**
|
|
4
|
+
* Listen an event
|
|
5
|
+
*
|
|
6
|
+
* @category listen-delegation
|
|
7
|
+
*
|
|
8
|
+
* @param types The event type or types (comma separated)
|
|
9
|
+
* @param selector The selector to run the event on
|
|
10
|
+
* @param callback The function to run when the event fires
|
|
11
|
+
*/
|
|
12
|
+
export function listen(types, selector, callback) {
|
|
13
|
+
// Make sure there's a selector and callback
|
|
14
|
+
if (!selector || !callback)
|
|
15
|
+
return;
|
|
16
|
+
// Loop through each event type
|
|
17
|
+
types.split(",").forEach(function (type) {
|
|
18
|
+
// Remove whitespace
|
|
19
|
+
type = type.trim();
|
|
20
|
+
// If no event of this type yet, setup
|
|
21
|
+
if (!activeEvents[type]) {
|
|
22
|
+
activeEvents[type] = [];
|
|
23
|
+
on(window, type, eventHandler, true);
|
|
24
|
+
}
|
|
25
|
+
// Push to active events
|
|
26
|
+
activeEvents[type].push({
|
|
27
|
+
selector: selector,
|
|
28
|
+
callback: callback,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export default listen;
|
package/listenLoaded.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
*/
|
|
7
|
+
export function listenLoaded(handler) {
|
|
8
|
+
on(document, "DOMContentLoaded", handler);
|
|
9
|
+
// document.addEventListener("DOMContentLoaded", setTimeout(handler, 4));
|
|
10
|
+
}
|
|
11
|
+
export default listenLoaded;
|
package/listenOnce.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type EventCallback } from "./_listen-delegation";
|
|
2
|
+
/**
|
|
3
|
+
* Listen an event, and automatically unlisten it after it's first run
|
|
4
|
+
*
|
|
5
|
+
* @category listen-delegation
|
|
6
|
+
*
|
|
7
|
+
* @param types The event type or types (comma separated)
|
|
8
|
+
* @param selector The selector to run the event on
|
|
9
|
+
* @param callback The function to run when the event fires
|
|
10
|
+
*/
|
|
11
|
+
export declare function listenOnce(types: string, selector: string, callback: EventCallback): void;
|
|
12
|
+
export default listenOnce;
|
package/listenOnce.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
*/
|
|
13
|
+
export function listenOnce(types, selector, callback) {
|
|
14
|
+
listen(types, selector, function temp(event) {
|
|
15
|
+
var target = getRunTarget(event.target, selector);
|
|
16
|
+
callback(event, target || window);
|
|
17
|
+
unlisten(types, selector, temp);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export default listenOnce;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { debounce } from "@koine/utils";
|
|
2
|
+
/**
|
|
3
|
+
* Listen window resize event debouncing the given handler
|
|
4
|
+
*
|
|
5
|
+
* @returns An automatic unbinding function to run to deregister the listener upon call
|
|
6
|
+
*/
|
|
7
|
+
export declare function listenResize(...args: Parameters<typeof debounce>): () => void;
|
|
8
|
+
export default listenResize;
|
package/listenResize.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { debounce } from "@koine/utils";
|
|
2
|
+
import { on } from "./on";
|
|
3
|
+
import { off } from "./off";
|
|
4
|
+
/**
|
|
5
|
+
* Listen window resize event debouncing the given handler
|
|
6
|
+
*
|
|
7
|
+
* @returns An automatic unbinding function to run to deregister the listener upon call
|
|
8
|
+
*/
|
|
9
|
+
export function listenResize() {
|
|
10
|
+
var args = [];
|
|
11
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
12
|
+
args[_i] = arguments[_i];
|
|
13
|
+
}
|
|
14
|
+
var handler = debounce.apply(void 0, args);
|
|
15
|
+
on(window, "resize", handler);
|
|
16
|
+
/**
|
|
17
|
+
* Unbind the previously attached scroll handler
|
|
18
|
+
*/
|
|
19
|
+
function unbinder() {
|
|
20
|
+
handler.cancel();
|
|
21
|
+
off(window, "resize", handler);
|
|
22
|
+
}
|
|
23
|
+
return unbinder;
|
|
24
|
+
}
|
|
25
|
+
export default listenResize;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { debounce } from "@koine/utils";
|
|
2
|
+
/**
|
|
3
|
+
* Listen window scroll event debouncing the given handler
|
|
4
|
+
*
|
|
5
|
+
* @returns An automatic unbinding function to run to deregister the listener upon call
|
|
6
|
+
*/
|
|
7
|
+
export declare function listenScroll(...args: Parameters<typeof debounce>): () => void;
|
|
8
|
+
export default listenScroll;
|
package/listenScroll.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { debounce } from "@koine/utils";
|
|
2
|
+
import { on } from "./on";
|
|
3
|
+
import { off } from "./off";
|
|
4
|
+
/**
|
|
5
|
+
* Listen window scroll event debouncing the given handler
|
|
6
|
+
*
|
|
7
|
+
* @returns An automatic unbinding function to run to deregister the listener upon call
|
|
8
|
+
*/
|
|
9
|
+
export function listenScroll() {
|
|
10
|
+
var args = [];
|
|
11
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
12
|
+
args[_i] = arguments[_i];
|
|
13
|
+
}
|
|
14
|
+
var handler = debounce.apply(void 0, args);
|
|
15
|
+
on(window, "scroll", handler, {
|
|
16
|
+
capture: true,
|
|
17
|
+
passive: true,
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* Unbind the previously attached scroll handler
|
|
21
|
+
*/
|
|
22
|
+
function unbinder() {
|
|
23
|
+
handler.cancel();
|
|
24
|
+
off(window, "scroll", handler);
|
|
25
|
+
}
|
|
26
|
+
return unbinder;
|
|
27
|
+
}
|
|
28
|
+
export default listenScroll;
|
package/node/$$.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
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/node/$.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.$ = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Sizzle/jQuery like DOM nodes shortcut for `document.querySelector`
|
|
6
|
+
* To avoid an extra function call we inline the above `escape`
|
|
7
|
+
*
|
|
8
|
+
* @param selector DOM selector
|
|
9
|
+
* @param parent It falls back to `window.document`
|
|
10
|
+
* @param avoidEscape Whether to avoid escaping `:` in the selector string
|
|
11
|
+
* @example <caption>Basic DOM selection</caption>
|
|
12
|
+
* const $container = $(".my-section:");
|
|
13
|
+
* const $el = $("[data-some-attr]", $container);
|
|
14
|
+
*/
|
|
15
|
+
function $(selector, parent, avoidEscape) {
|
|
16
|
+
return (parent ? parent : document).querySelector(avoidEscape ? selector : selector.replace(/:/g, "\\:"));
|
|
17
|
+
}
|
|
18
|
+
exports.$ = $;
|
|
19
|
+
exports.default = $;
|
package/node/$each.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.$each = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var __1 = tslib_1.__importDefault(require("./$$"));
|
|
6
|
+
/**
|
|
7
|
+
* Each shortcut, iterate through a NodeList of HTMLElements retrieved with the
|
|
8
|
+
* given selector (and optionally a parent container passed as thrid arguement)
|
|
9
|
+
*
|
|
10
|
+
* @param selector DOM selector
|
|
11
|
+
* @param callback
|
|
12
|
+
* @param parent It falls back to `window.document`
|
|
13
|
+
* @param scope
|
|
14
|
+
*/
|
|
15
|
+
function $each(selector, callback, parent, scope) {
|
|
16
|
+
var nodes = (0, __1.default)(selector, parent);
|
|
17
|
+
for (var i = 0; i < nodes.length; i++) {
|
|
18
|
+
callback.call(scope, nodes[i], i);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.$each = $each;
|
|
22
|
+
exports.default = $each;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.eventHandler = exports.getRunTarget = exports.getIndex = exports.activeEvents = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Listen: events delegation system
|
|
6
|
+
*
|
|
7
|
+
* From:
|
|
8
|
+
* https://github.com/cferdinandi/events
|
|
9
|
+
* https://github.com/cferdinandi/events/blob/master/src/js/events/events.js
|
|
10
|
+
*
|
|
11
|
+
* @fileoverview
|
|
12
|
+
*/
|
|
13
|
+
var utils_1 = require("@koine/utils");
|
|
14
|
+
var escapeSelector_1 = require("./escapeSelector");
|
|
15
|
+
/**
|
|
16
|
+
* Active events
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
exports.activeEvents = {};
|
|
21
|
+
/**
|
|
22
|
+
* Get the index for the listener
|
|
23
|
+
*
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
function getIndex(arr, selector, callback) {
|
|
27
|
+
for (var i = 0; i < arr.length; i++) {
|
|
28
|
+
if (arr[i].selector === selector &&
|
|
29
|
+
arr[i].callback.toString() === callback.toString())
|
|
30
|
+
return i;
|
|
31
|
+
}
|
|
32
|
+
return -1;
|
|
33
|
+
}
|
|
34
|
+
exports.getIndex = getIndex;
|
|
35
|
+
/**
|
|
36
|
+
* Check if the listener callback should run or not
|
|
37
|
+
*
|
|
38
|
+
* @internal
|
|
39
|
+
* @param target The event.target
|
|
40
|
+
* @param selector The selector/element to check the target against
|
|
41
|
+
* @return If not false, run listener and pass the targeted element to use in the callback
|
|
42
|
+
*/
|
|
43
|
+
function getRunTarget(target, selector) {
|
|
44
|
+
// @ts-expect-error FIXME: type
|
|
45
|
+
if (["*", "window", window].includes(selector)) {
|
|
46
|
+
return window;
|
|
47
|
+
}
|
|
48
|
+
if ([
|
|
49
|
+
"document",
|
|
50
|
+
"document.documentElement",
|
|
51
|
+
document,
|
|
52
|
+
document.documentElement,
|
|
53
|
+
// @ts-expect-error FIXME: type
|
|
54
|
+
].includes(selector))
|
|
55
|
+
return document;
|
|
56
|
+
if ((0, utils_1.isString)(selector)) {
|
|
57
|
+
return target.closest((0, escapeSelector_1.escapeSelector)(selector));
|
|
58
|
+
}
|
|
59
|
+
// @ts-expect-error FIXME: type
|
|
60
|
+
if (typeof selector !== "string" && selector.contains) {
|
|
61
|
+
if (selector === target) {
|
|
62
|
+
return target;
|
|
63
|
+
}
|
|
64
|
+
// @ts-expect-error FIXME: type
|
|
65
|
+
if (selector.contains(target)) {
|
|
66
|
+
return selector;
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
exports.getRunTarget = getRunTarget;
|
|
73
|
+
/**
|
|
74
|
+
* Handle listeners after event fires
|
|
75
|
+
*
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
function eventHandler(event) {
|
|
79
|
+
if (!exports.activeEvents[event.type])
|
|
80
|
+
return;
|
|
81
|
+
exports.activeEvents[event.type].forEach(function (listener) {
|
|
82
|
+
var target = getRunTarget(event.target, listener.selector);
|
|
83
|
+
if (!target) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
listener.callback(event, target);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
exports.eventHandler = eventHandler;
|
package/node/addClass.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addClass = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Add class shortcut
|
|
6
|
+
*/
|
|
7
|
+
function addClass(el, className) {
|
|
8
|
+
if (className === void 0) { className = ""; }
|
|
9
|
+
if (process.env["NODE_ENV"] !== "production") {
|
|
10
|
+
if (!el) {
|
|
11
|
+
console.warn("[@koine/dom:addClass] unexisting DOM element");
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
if (el)
|
|
16
|
+
el.classList.add(className);
|
|
17
|
+
}
|
|
18
|
+
exports.addClass = addClass;
|
|
19
|
+
exports.default = addClass;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateFixedOffset = void 0;
|
|
4
|
+
var _each_1 = require("./$each");
|
|
5
|
+
function calculateFixedOffset(selector) {
|
|
6
|
+
if (selector === void 0) { selector = "[data-fixed]"; }
|
|
7
|
+
var fixedOffset = 0;
|
|
8
|
+
(0, _each_1.$each)(selector, function ($el) {
|
|
9
|
+
fixedOffset += $el.offsetHeight;
|
|
10
|
+
});
|
|
11
|
+
return fixedOffset;
|
|
12
|
+
}
|
|
13
|
+
exports.calculateFixedOffset = calculateFixedOffset;
|
|
14
|
+
exports.default = calculateFixedOffset;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createElement = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var addClass_1 = tslib_1.__importDefault(require("./addClass"));
|
|
6
|
+
/**
|
|
7
|
+
* Shortcut for `document.createElement`, allowing to to create an HTML element
|
|
8
|
+
* with a given className directly (a very common use case)
|
|
9
|
+
*
|
|
10
|
+
* @param type
|
|
11
|
+
* @param className
|
|
12
|
+
*/
|
|
13
|
+
function createElement(type, className) {
|
|
14
|
+
var el = document.createElement(type);
|
|
15
|
+
if (className) {
|
|
16
|
+
(0, addClass_1.default)(el, className);
|
|
17
|
+
}
|
|
18
|
+
return el;
|
|
19
|
+
}
|
|
20
|
+
exports.createElement = createElement;
|
|
21
|
+
exports.default = createElement;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.emitEvent = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Emit event (use only if the targeted browser supports `CustomEvent`s)
|
|
6
|
+
*/
|
|
7
|
+
function emitEvent(type, detail) {
|
|
8
|
+
if (type === void 0) { type = "customEvent"; }
|
|
9
|
+
if (detail === void 0) { detail = {}; }
|
|
10
|
+
if (typeof window.CustomEvent !== "function")
|
|
11
|
+
return;
|
|
12
|
+
document.dispatchEvent(new CustomEvent(type, {
|
|
13
|
+
bubbles: true,
|
|
14
|
+
detail: detail,
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
17
|
+
exports.emitEvent = emitEvent;
|
|
18
|
+
exports.default = emitEvent;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.escapeSelector = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Escape colons to allow use class names as `.module:block__element`
|
|
6
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector#Escaping_special_characters
|
|
7
|
+
*
|
|
8
|
+
* @param selector
|
|
9
|
+
*/
|
|
10
|
+
function escapeSelector(selector) {
|
|
11
|
+
return selector.replace(/:/g, "\\:");
|
|
12
|
+
}
|
|
13
|
+
exports.escapeSelector = escapeSelector;
|
|
14
|
+
exports.default = escapeSelector;
|
package/node/exists.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exists = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Checks if passed node exist and is a valid element.
|
|
6
|
+
*
|
|
7
|
+
* @borrows @glidejs/glide/src/utils/dom (source)
|
|
8
|
+
*/
|
|
9
|
+
function exists(node) {
|
|
10
|
+
if (node && node instanceof window.HTMLElement) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
exports.exists = exists;
|
|
16
|
+
exports.default = exists;
|
package/node/forEach.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.forEach = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* For each, iterate through a NodeList of HTMLElements
|
|
6
|
+
*
|
|
7
|
+
* @param nodes DOM nodes collection
|
|
8
|
+
* @param callback
|
|
9
|
+
* @param scope
|
|
10
|
+
*/
|
|
11
|
+
function forEach(nodes, callback, scope) {
|
|
12
|
+
for (var i = 0; i < nodes.length; i++) {
|
|
13
|
+
callback.call(scope, nodes[i], i);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.forEach = forEach;
|
|
17
|
+
exports.default = forEach;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// TODO: maybe move to `dataset` API but consider the comment about Safari here
|
|
3
|
+
// https://stackoverflow.com/a/9201264/1938970
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.getDataAttr = void 0;
|
|
6
|
+
/**
|
|
7
|
+
* Get data attribute
|
|
8
|
+
*
|
|
9
|
+
* @param element
|
|
10
|
+
* @param attribute The name of the `data-{attr}`
|
|
11
|
+
*/
|
|
12
|
+
function getDataAttr(element, attribute) {
|
|
13
|
+
// return element.dataset[attribute];
|
|
14
|
+
return element.getAttribute("data-" + attribute);
|
|
15
|
+
}
|
|
16
|
+
exports.getDataAttr = getDataAttr;
|
|
17
|
+
exports.default = getDataAttr;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDocumentHeight = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Determine the document's height
|
|
6
|
+
*
|
|
7
|
+
* @see https://github.com/cferdinandi/smooth-scroll (credits)
|
|
8
|
+
*/
|
|
9
|
+
function getDocumentHeight() {
|
|
10
|
+
var body = document.body, documentElement = document.documentElement;
|
|
11
|
+
return Math.max(body.scrollHeight, documentElement.scrollHeight, body.offsetHeight, documentElement.offsetHeight, body.clientHeight, documentElement.clientHeight);
|
|
12
|
+
}
|
|
13
|
+
exports.getDocumentHeight = getDocumentHeight;
|
|
14
|
+
exports.default = getDocumentHeight;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHeight = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Get element height
|
|
6
|
+
*/
|
|
7
|
+
function getHeight(element) {
|
|
8
|
+
return parseInt(window.getComputedStyle(element).height, 10);
|
|
9
|
+
}
|
|
10
|
+
exports.getHeight = getHeight;
|
|
11
|
+
exports.default = getHeight;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getListeners = void 0;
|
|
4
|
+
var _listen_delegation_1 = require("./_listen-delegation");
|
|
5
|
+
/**
|
|
6
|
+
* Get an immutable copy of all active event listeners
|
|
7
|
+
*
|
|
8
|
+
* @category listen-delegation
|
|
9
|
+
*
|
|
10
|
+
* @return Active event listeners
|
|
11
|
+
*/
|
|
12
|
+
function getListeners() {
|
|
13
|
+
var obj = {};
|
|
14
|
+
for (var type in _listen_delegation_1.activeEvents) {
|
|
15
|
+
// if (activeEvents.hasOwnProperty(type)) {
|
|
16
|
+
obj[type] = _listen_delegation_1.activeEvents[type];
|
|
17
|
+
// }
|
|
18
|
+
}
|
|
19
|
+
return obj;
|
|
20
|
+
}
|
|
21
|
+
exports.getListeners = getListeners;
|
|
22
|
+
exports.default = getListeners;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOffset = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Get an element's distance from the top and left of the Document.
|
|
6
|
+
*
|
|
7
|
+
* @param elem The HTML node element
|
|
8
|
+
* @return Distance from the top and left in pixels
|
|
9
|
+
*/
|
|
10
|
+
function getOffset(elem) {
|
|
11
|
+
var left = 0;
|
|
12
|
+
var top = 0;
|
|
13
|
+
while (elem && !isNaN(elem.offsetLeft) && !isNaN(elem.offsetTop)) {
|
|
14
|
+
left += elem.offsetLeft - elem.scrollLeft;
|
|
15
|
+
top += elem.offsetTop - elem.scrollTop;
|
|
16
|
+
// @ts-expect-error nevermind?
|
|
17
|
+
elem = elem.offsetParent;
|
|
18
|
+
}
|
|
19
|
+
return { top: top, left: left };
|
|
20
|
+
}
|
|
21
|
+
exports.getOffset = getOffset;
|
|
22
|
+
exports.default = getOffset;
|