@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/getStyleValue.mjs
DELETED
|
@@ -1,10 +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
|
-
*/
|
|
7
|
-
export function getStyleValue(el, prop) {
|
|
8
|
-
return getComputedStyle(el, null).getPropertyValue(prop);
|
|
9
|
-
}
|
|
10
|
-
export default getStyleValue;
|
package/getVisualBackground.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get the background color of an element eventually looking recursively into
|
|
3
|
-
* its parents, if nothing is found it returns a `#fff` background
|
|
4
|
-
*/
|
|
5
|
-
export declare function getVisualBackgroundColor(elem?: null | HTMLElement): string;
|
|
6
|
-
export default getVisualBackgroundColor;
|
package/getVisualBackground.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getVisualBackgroundColor = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Get the background color of an element eventually looking recursively into
|
|
6
|
-
* its parents, if nothing is found it returns a `#fff` background
|
|
7
|
-
*/
|
|
8
|
-
function getVisualBackgroundColor(elem) {
|
|
9
|
-
if (!elem)
|
|
10
|
-
return "#fff";
|
|
11
|
-
var transparent = "rgba(0, 0, 0, 0)";
|
|
12
|
-
var transparentIE11 = "transparent";
|
|
13
|
-
// if (!elem) return transparent;
|
|
14
|
-
var bg = window.getComputedStyle(elem).backgroundColor;
|
|
15
|
-
if (bg === transparent || bg === transparentIE11) {
|
|
16
|
-
var parent_1 = elem.parentElement;
|
|
17
|
-
if (parent_1) {
|
|
18
|
-
return getVisualBackgroundColor(parent_1);
|
|
19
|
-
}
|
|
20
|
-
return "#fff";
|
|
21
|
-
}
|
|
22
|
-
return bg;
|
|
23
|
-
}
|
|
24
|
-
exports.getVisualBackgroundColor = getVisualBackgroundColor;
|
|
25
|
-
exports.default = getVisualBackgroundColor;
|
package/getVisualBackground.mjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get the background color of an element eventually looking recursively into
|
|
3
|
-
* its parents, if nothing is found it returns a `#fff` background
|
|
4
|
-
*/
|
|
5
|
-
export function getVisualBackgroundColor(elem) {
|
|
6
|
-
if (!elem)
|
|
7
|
-
return "#fff";
|
|
8
|
-
var transparent = "rgba(0, 0, 0, 0)";
|
|
9
|
-
var transparentIE11 = "transparent";
|
|
10
|
-
// if (!elem) return transparent;
|
|
11
|
-
var bg = window.getComputedStyle(elem).backgroundColor;
|
|
12
|
-
if (bg === transparent || bg === transparentIE11) {
|
|
13
|
-
var parent_1 = elem.parentElement;
|
|
14
|
-
if (parent_1) {
|
|
15
|
-
return getVisualBackgroundColor(parent_1);
|
|
16
|
-
}
|
|
17
|
-
return "#fff";
|
|
18
|
-
}
|
|
19
|
-
return bg;
|
|
20
|
-
}
|
|
21
|
-
export default getVisualBackgroundColor;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get the background color of an element eventually looking recursively into
|
|
3
|
-
* its parents, if nothing is found it returns a `#fff` background
|
|
4
|
-
*/
|
|
5
|
-
export function getVisualBackgroundColor(elem) {
|
|
6
|
-
if (!elem)
|
|
7
|
-
return "#fff";
|
|
8
|
-
var transparent = "rgba(0, 0, 0, 0)";
|
|
9
|
-
var transparentIE11 = "transparent";
|
|
10
|
-
// if (!elem) return transparent;
|
|
11
|
-
var bg = window.getComputedStyle(elem).backgroundColor;
|
|
12
|
-
if (bg === transparent || bg === transparentIE11) {
|
|
13
|
-
var parent_1 = elem.parentElement;
|
|
14
|
-
if (parent_1) {
|
|
15
|
-
return getVisualBackgroundColor(parent_1);
|
|
16
|
-
}
|
|
17
|
-
return "#fff";
|
|
18
|
-
}
|
|
19
|
-
return bg;
|
|
20
|
-
}
|
|
21
|
-
export default getVisualBackgroundColor;
|
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/injectCss.mjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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.mjs
DELETED
package/isInViewport.mjs
DELETED
|
@@ -1,18 +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
|
-
*/
|
|
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.mjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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;
|
package/isTotallyScrolled.mjs
DELETED
|
@@ -1,10 +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
|
-
*/
|
|
7
|
-
export function isTotallyScrolled(el) {
|
|
8
|
-
return el ? el.scrollHeight - el.scrollTop <= el.clientHeight : false;
|
|
9
|
-
}
|
|
10
|
-
export default isTotallyScrolled;
|
package/listen.mjs
DELETED
|
@@ -1,33 +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
|
-
*/
|
|
13
|
-
export function listen(types, selector, callback) {
|
|
14
|
-
// Make sure there's a selector and callback
|
|
15
|
-
if (!selector || !callback)
|
|
16
|
-
return;
|
|
17
|
-
// Loop through each event type
|
|
18
|
-
types.split(",").forEach(function (type) {
|
|
19
|
-
// Remove whitespace
|
|
20
|
-
type = type.trim();
|
|
21
|
-
// If no event of this type yet, setup
|
|
22
|
-
if (!activeEvents[type]) {
|
|
23
|
-
activeEvents[type] = [];
|
|
24
|
-
on(window, type, eventHandler, true);
|
|
25
|
-
}
|
|
26
|
-
// Push to active events
|
|
27
|
-
activeEvents[type].push({
|
|
28
|
-
selector: selector,
|
|
29
|
-
callback: callback,
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
export default listen;
|
package/listenLoaded.mjs
DELETED
|
@@ -1,11 +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
|
-
*/
|
|
7
|
-
export function listenLoaded(handler) {
|
|
8
|
-
on(document, "DOMContentLoaded", handler);
|
|
9
|
-
// document.addEventListener("DOMContentLoaded", setTimeout(handler, 4));
|
|
10
|
-
}
|
|
11
|
-
export default listenLoaded;
|
package/listenOnce.mjs
DELETED
|
@@ -1,20 +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
|
-
*/
|
|
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;
|
package/listenResize.mjs
DELETED
|
@@ -1,8 +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
|
-
*/
|
|
7
|
-
export var listenResize = function (handler, el) { return on(el || window, "resize", handler); };
|
|
8
|
-
export default listenResize;
|
|
@@ -1,42 +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
|
-
*/
|
|
8
|
-
export var listenResizeDebounced = function (el) {
|
|
9
|
-
var args = [];
|
|
10
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
11
|
-
args[_i - 1] = arguments[_i];
|
|
12
|
-
}
|
|
13
|
-
return listenResize(debounce.apply(void 0, args), el);
|
|
14
|
-
};
|
|
15
|
-
export default listenResizeDebounced;
|
|
16
|
-
// EXP: with too complex overload signature...
|
|
17
|
-
// import debounce from "@koine/utils/debounce";
|
|
18
|
-
// import isUndefined from "@koine/utils/isUndefined";
|
|
19
|
-
// import listenResize from "./listenResize";
|
|
20
|
-
// /**
|
|
21
|
-
// * Listen element's (`window` by default) _resize_ event debouncing the callback
|
|
22
|
-
// *
|
|
23
|
-
// * @returns An automatic unbinding function to run to deregister the listener upon call
|
|
24
|
-
// */
|
|
25
|
-
// export function listenResizeDebounced(
|
|
26
|
-
// ...args: Parameters<typeof debounce>
|
|
27
|
-
// ): ReturnType<typeof listenResize>;
|
|
28
|
-
// export function listenResizeDebounced(
|
|
29
|
-
// el: Parameters<typeof listenResize>[1],
|
|
30
|
-
// ...args: Parameters<typeof debounce>
|
|
31
|
-
// ): ReturnType<typeof listenResize>;
|
|
32
|
-
// export function listenResizeDebounced(
|
|
33
|
-
// ...args:
|
|
34
|
-
// | [Parameters<typeof listenResize>[1], ...Parameters<typeof debounce>]
|
|
35
|
-
// | Parameters<typeof debounce>
|
|
36
|
-
// ) {
|
|
37
|
-
// if (isUndefined(args[0])) {
|
|
38
|
-
// return listenResize(debounce(...args));
|
|
39
|
-
// }
|
|
40
|
-
// return listenResize(debounce(...args.slice(1)), args[0]);
|
|
41
|
-
// }
|
|
42
|
-
// export default listenResizeDebounced;
|
|
@@ -1,15 +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
|
-
*/
|
|
8
|
-
export var listenResizeThrottled = function (el) {
|
|
9
|
-
var args = [];
|
|
10
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
11
|
-
args[_i - 1] = arguments[_i];
|
|
12
|
-
}
|
|
13
|
-
return listenResize(throttle.apply(void 0, args), el);
|
|
14
|
-
};
|
|
15
|
-
export default listenResizeThrottled;
|
package/listenScroll.mjs
DELETED
|
@@ -1,13 +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
|
-
*/
|
|
7
|
-
export var listenScroll = function (handler, el) {
|
|
8
|
-
return on(el || window, "scroll", handler, {
|
|
9
|
-
capture: true,
|
|
10
|
-
passive: true,
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
export default listenScroll;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import debounce from "@koine/utils/debounce";
|
|
2
|
-
import { listenScroll } from "./listenScroll";
|
|
3
|
-
/**
|
|
4
|
-
* Listen element's (`window` by default) _scroll_ event debouncing the callback
|
|
5
|
-
*
|
|
6
|
-
* @returns An automatic unbinding function to run to deregister the listener upon call
|
|
7
|
-
*/
|
|
8
|
-
export var listenScrollDebounced = function (el) {
|
|
9
|
-
var args = [];
|
|
10
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
11
|
-
args[_i - 1] = arguments[_i];
|
|
12
|
-
}
|
|
13
|
-
return listenScroll(debounce.apply(void 0, args), el);
|
|
14
|
-
};
|
|
15
|
-
export default listenScrollDebounced;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import throttle from "@koine/utils/throttle";
|
|
2
|
-
import { listenScroll } from "./listenScroll";
|
|
3
|
-
/**
|
|
4
|
-
* Listen element's (`window` by default) _scroll_ event throttling the callback
|
|
5
|
-
*
|
|
6
|
-
* @returns An automatic unbinding function to run to deregister the listener upon call
|
|
7
|
-
*/
|
|
8
|
-
export var listenScrollThrottled = function (el) {
|
|
9
|
-
var args = [];
|
|
10
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
11
|
-
args[_i - 1] = arguments[_i];
|
|
12
|
-
}
|
|
13
|
-
return listenScroll(throttle.apply(void 0, args), el);
|
|
14
|
-
};
|
|
15
|
-
export default listenScrollThrottled;
|
package/off.mjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shortcut for `removeEventListener`
|
|
3
|
-
*/
|
|
4
|
-
export function off(el, type, handler, options) {
|
|
5
|
-
if (options === void 0) { options = false; }
|
|
6
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
7
|
-
if (!el) {
|
|
8
|
-
console.warn("[@koine/dom:off] unexisting DOM element");
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
if (el)
|
|
12
|
-
el.removeEventListener(type, handler, options);
|
|
13
|
-
}
|
|
14
|
-
export default off;
|
package/on.mjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import off from "./off";
|
|
2
|
-
/**
|
|
3
|
-
* Shortcut for `addEventListener`
|
|
4
|
-
*
|
|
5
|
-
* @returns An automatic unbinding function to run to deregister the listener upon call
|
|
6
|
-
*/
|
|
7
|
-
export function on(el, type, handler /* EventListener | */ /* ((event: Event) => void) */, options) {
|
|
8
|
-
if (options === void 0) { options = false; }
|
|
9
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
10
|
-
if (!el) {
|
|
11
|
-
console.warn("[@koine/dom:on] unexisting DOM element");
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
if (el) {
|
|
15
|
-
el.addEventListener(type, handler, options);
|
|
16
|
-
return function () { return off(el, type, handler); };
|
|
17
|
-
}
|
|
18
|
-
// return noop;
|
|
19
|
-
return function () { return void 0; };
|
|
20
|
-
}
|
|
21
|
-
export default on;
|
package/onClickOutside.mjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { on, off } from "./index";
|
|
2
|
-
export function onClickOutside(element, callback, autoUnbind) {
|
|
3
|
-
if (autoUnbind === void 0) { autoUnbind = false; }
|
|
4
|
-
var bind = function (event) {
|
|
5
|
-
// if (event.target.closest(element) === null) {
|
|
6
|
-
if (!element.contains(event.target)) {
|
|
7
|
-
callback(event);
|
|
8
|
-
if (autoUnbind)
|
|
9
|
-
unbind();
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
var unbind = function () {
|
|
13
|
-
off(document, "click", bind);
|
|
14
|
-
};
|
|
15
|
-
on(document, "click", bind);
|
|
16
|
-
return unbind;
|
|
17
|
-
}
|
package/once.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import on from "./on";
|
|
2
|
-
import off from "./off";
|
|
3
|
-
/**
|
|
4
|
-
* One shot listener, it `addEventListener` and removes it first time is called
|
|
5
|
-
* with `removeEventListener`
|
|
6
|
-
*/
|
|
7
|
-
export function once(el, type, handler, options) {
|
|
8
|
-
if (options === void 0) { options = false; }
|
|
9
|
-
var handlerWrapper = function (event) {
|
|
10
|
-
handler(event);
|
|
11
|
-
off(el, type, handlerWrapper);
|
|
12
|
-
};
|
|
13
|
-
return on(el, type, handlerWrapper, options);
|
|
14
|
-
}
|
|
15
|
-
export default once;
|
package/removeClass.mjs
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Remove class shortcut
|
|
3
|
-
*/
|
|
4
|
-
export function removeClass(el, className) {
|
|
5
|
-
if (className === void 0) { className = ""; }
|
|
6
|
-
if (process.env["NODE_ENV"] !== "production") {
|
|
7
|
-
if (!el) {
|
|
8
|
-
("[@koine/dom:removeClass] unexisting DOM element");
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
if (el)
|
|
13
|
-
el.classList.remove(className);
|
|
14
|
-
}
|
|
15
|
-
export default removeClass;
|
package/scrollTo.mjs
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { on } from "./on";
|
|
2
|
-
import { off } from "./off";
|
|
3
|
-
/**
|
|
4
|
-
* Native `scrollTo`, `"smooth"` and with callback
|
|
5
|
-
*
|
|
6
|
-
* @borrows https://stackoverflow.com/a/55686711/1938970
|
|
7
|
-
*
|
|
8
|
-
* @param offset - offset to scroll to
|
|
9
|
-
* @param callback - callback function
|
|
10
|
-
* @param [fallbackTimeout] - this appears to be needed in some hard to reproduce scenario on safari, where the callback seem to be never called
|
|
11
|
-
* @param [behavior="smooth"]
|
|
12
|
-
*/
|
|
13
|
-
export function scrollTo(destination, callback, fallbackTimeout, behavior) {
|
|
14
|
-
var fixedDestination = destination.toFixed();
|
|
15
|
-
if (callback) {
|
|
16
|
-
var callbackFired_1 = false;
|
|
17
|
-
var onScroll_1 = function () {
|
|
18
|
-
if (window.pageYOffset.toFixed() === fixedDestination) {
|
|
19
|
-
off(window, "scroll", onScroll_1);
|
|
20
|
-
callbackFired_1 = true;
|
|
21
|
-
callback();
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
on(window, "scroll", onScroll_1);
|
|
25
|
-
onScroll_1();
|
|
26
|
-
if (fallbackTimeout) {
|
|
27
|
-
setTimeout(function () {
|
|
28
|
-
if (!callbackFired_1) {
|
|
29
|
-
off(window, "scroll", onScroll_1);
|
|
30
|
-
callback();
|
|
31
|
-
}
|
|
32
|
-
}, fallbackTimeout);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
window.scrollTo({
|
|
36
|
-
top: destination,
|
|
37
|
-
behavior: behavior || "smooth",
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
export default scrollTo;
|
package/setDataAttr.mjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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
|
-
export function setDataAttr(element, attribute, value) {
|
|
9
|
-
if (value === null || typeof value === "undefined") {
|
|
10
|
-
// delete element.dataset[attribute];
|
|
11
|
-
// return;
|
|
12
|
-
element.removeAttribute("data-" + attribute);
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
// element.dataset[attribute] = value.toString();
|
|
16
|
-
element.setAttribute("data-" + attribute, value.toString());
|
|
17
|
-
}
|
|
18
|
-
export default setDataAttr;
|
package/setVendorCSS.mjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
export function setVendorCSS(element, prop, value) {
|
|
9
|
-
var propUpper = prop.charAt(0).toUpperCase() + prop.slice(1);
|
|
10
|
-
// @ts-expect-error nevermind now...
|
|
11
|
-
element.style["webkit" + propUpper] = value;
|
|
12
|
-
// @ts-expect-error nevermind now...
|
|
13
|
-
element.style["moz" + propUpper] = value;
|
|
14
|
-
// @ts-expect-error nevermind now...
|
|
15
|
-
element.style["ms" + propUpper] = value;
|
|
16
|
-
// @ts-expect-error nevermind now...
|
|
17
|
-
element.style["o" + propUpper] = value;
|
|
18
|
-
// @ts-expect-error nevermind now...
|
|
19
|
-
element.style[prop] = value;
|
|
20
|
-
}
|
|
21
|
-
export default setVendorCSS;
|
package/siblings.mjs
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Finds siblings nodes of the passed node.
|
|
3
|
-
*
|
|
4
|
-
* @borrows @glidejs/glide/src/utils/dom (source)
|
|
5
|
-
*/
|
|
6
|
-
export function siblings(node) {
|
|
7
|
-
if (node && node.parentNode) {
|
|
8
|
-
var n = node.parentNode.firstChild;
|
|
9
|
-
var matched = [];
|
|
10
|
-
for (; n; n = n.nextSibling) {
|
|
11
|
-
if (n.nodeType === 1 && n !== node) {
|
|
12
|
-
matched.push(n);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return matched;
|
|
16
|
-
}
|
|
17
|
-
return [];
|
|
18
|
-
}
|
|
19
|
-
export default siblings;
|
package/toArray.mjs
DELETED
package/types.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/unlisten.mjs
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { activeEvents, getIndex, eventHandler, } from "./_listen-delegation";
|
|
2
|
-
import { off } from "./off";
|
|
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
|
-
*/
|
|
12
|
-
export function unlisten(types, selector, callback) {
|
|
13
|
-
// Loop through each event type
|
|
14
|
-
types.split(",").forEach(function (type) {
|
|
15
|
-
// Remove whitespace
|
|
16
|
-
type = type.trim();
|
|
17
|
-
// if event type doesn't exist, bail
|
|
18
|
-
if (!activeEvents[type])
|
|
19
|
-
return;
|
|
20
|
-
// If it's the last event of it's type, remove entirely
|
|
21
|
-
if (activeEvents[type].length < 2 || !selector) {
|
|
22
|
-
delete activeEvents[type];
|
|
23
|
-
off(window, type, eventHandler, true);
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
// Otherwise, remove event
|
|
27
|
-
var index = getIndex(activeEvents[type], selector, callback);
|
|
28
|
-
if (index < 0)
|
|
29
|
-
return;
|
|
30
|
-
activeEvents[type].splice(index, 1);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
export default unlisten;
|