@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
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOffsetTop = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Get an element's distance from the top of the Document.
|
|
6
|
+
*
|
|
7
|
+
* @see https://vanillajstoolkit.com/helpers/getoffsettop/
|
|
8
|
+
*
|
|
9
|
+
* @param elem The HTML node element
|
|
10
|
+
* @return Distance from the top in pixels
|
|
11
|
+
*/
|
|
12
|
+
function getOffsetTop(elem) {
|
|
13
|
+
var location = 0;
|
|
14
|
+
if (elem.offsetParent) {
|
|
15
|
+
while (elem) {
|
|
16
|
+
location += elem.offsetTop;
|
|
17
|
+
// @ts-expect-error nevermind?
|
|
18
|
+
elem = elem.offsetParent;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return location >= 0 ? location : 0;
|
|
22
|
+
}
|
|
23
|
+
exports.getOffsetTop = getOffsetTop;
|
|
24
|
+
exports.default = getOffsetTop;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getScrollbarWidth = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Get scrollbar's current width
|
|
6
|
+
*/
|
|
7
|
+
function getScrollbarWidth(element) {
|
|
8
|
+
return window.innerWidth - (element || document.documentElement).clientWidth;
|
|
9
|
+
}
|
|
10
|
+
exports.getScrollbarWidth = getScrollbarWidth;
|
|
11
|
+
exports.default = getScrollbarWidth;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getStyleValue = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Return the current style value for an element CSS property
|
|
6
|
+
*
|
|
7
|
+
* @param el The element to compute
|
|
8
|
+
* @param prop The style property
|
|
9
|
+
*/
|
|
10
|
+
function getStyleValue(el, prop) {
|
|
11
|
+
return getComputedStyle(el, null).getPropertyValue(prop);
|
|
12
|
+
}
|
|
13
|
+
exports.getStyleValue = getStyleValue;
|
|
14
|
+
exports.default = getStyleValue;
|
package/node/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./$$"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./$each"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./$"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./addClass"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./calculateFixedOffset"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./createElement"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./emitEvent"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./escapeSelector"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./exists"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./forEach"), exports);
|
|
14
|
+
tslib_1.__exportStar(require("./getDataAttr"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./getDocumentHeight"), exports);
|
|
16
|
+
tslib_1.__exportStar(require("./getHeight"), exports);
|
|
17
|
+
tslib_1.__exportStar(require("./getListeners"), exports);
|
|
18
|
+
tslib_1.__exportStar(require("./getOffsetTop"), exports);
|
|
19
|
+
tslib_1.__exportStar(require("./getOffset"), exports);
|
|
20
|
+
tslib_1.__exportStar(require("./getScrollbarWidth"), exports);
|
|
21
|
+
tslib_1.__exportStar(require("./getStyleValue"), exports);
|
|
22
|
+
tslib_1.__exportStar(require("./index"), exports);
|
|
23
|
+
tslib_1.__exportStar(require("./injectCss"), exports);
|
|
24
|
+
tslib_1.__exportStar(require("./isHidden"), exports);
|
|
25
|
+
tslib_1.__exportStar(require("./isInViewport"), exports);
|
|
26
|
+
tslib_1.__exportStar(require("./isNodeList"), exports);
|
|
27
|
+
tslib_1.__exportStar(require("./isTotallyScrolled"), exports);
|
|
28
|
+
tslib_1.__exportStar(require("./listenLoaded"), exports);
|
|
29
|
+
tslib_1.__exportStar(require("./listenOnce"), exports);
|
|
30
|
+
tslib_1.__exportStar(require("./listenResize"), exports);
|
|
31
|
+
tslib_1.__exportStar(require("./listenScroll"), exports);
|
|
32
|
+
tslib_1.__exportStar(require("./listen"), exports);
|
|
33
|
+
tslib_1.__exportStar(require("./off"), exports);
|
|
34
|
+
tslib_1.__exportStar(require("./once"), exports);
|
|
35
|
+
tslib_1.__exportStar(require("./onClickOutside"), exports);
|
|
36
|
+
tslib_1.__exportStar(require("./on"), exports);
|
|
37
|
+
tslib_1.__exportStar(require("./removeClass"), exports);
|
|
38
|
+
tslib_1.__exportStar(require("./scrollTo"), exports);
|
|
39
|
+
tslib_1.__exportStar(require("./setDataAttr"), exports);
|
|
40
|
+
tslib_1.__exportStar(require("./setVendorCSS"), exports);
|
|
41
|
+
tslib_1.__exportStar(require("./siblings"), exports);
|
|
42
|
+
tslib_1.__exportStar(require("./toArray"), exports);
|
|
43
|
+
tslib_1.__exportStar(require("./unlisten"), exports);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.injectCss = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Inject css
|
|
6
|
+
*/
|
|
7
|
+
function injectCss(id, cssString, root) {
|
|
8
|
+
if (cssString === void 0) { cssString = ""; }
|
|
9
|
+
if (root === void 0) { root = document; }
|
|
10
|
+
var styleblock;
|
|
11
|
+
styleblock = root.getElementById(id);
|
|
12
|
+
if (!styleblock) {
|
|
13
|
+
styleblock = root.createElement("style");
|
|
14
|
+
styleblock.id = id;
|
|
15
|
+
root.body.appendChild(styleblock);
|
|
16
|
+
}
|
|
17
|
+
styleblock.innerHTML = cssString;
|
|
18
|
+
}
|
|
19
|
+
exports.injectCss = injectCss;
|
|
20
|
+
exports.default = injectCss;
|
package/node/isHidden.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isHidden = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Is element hidden?
|
|
6
|
+
*/
|
|
7
|
+
function isHidden(el) {
|
|
8
|
+
return !el || el.offsetParent === null;
|
|
9
|
+
}
|
|
10
|
+
exports.isHidden = isHidden;
|
|
11
|
+
exports.default = isHidden;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isInViewport = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Determine if an element is in the viewport
|
|
6
|
+
*
|
|
7
|
+
* @borrows (c) 2017 Chris Ferdinandi, MIT License, https://gomakethings.com
|
|
8
|
+
*
|
|
9
|
+
* @param elem The element
|
|
10
|
+
* @return Returns true if element is in the viewport
|
|
11
|
+
*/
|
|
12
|
+
function isInViewport(elem) {
|
|
13
|
+
var distance = elem.getBoundingClientRect();
|
|
14
|
+
return (distance.top >= 0 &&
|
|
15
|
+
distance.left >= 0 &&
|
|
16
|
+
distance.bottom <=
|
|
17
|
+
(window.innerHeight || document.documentElement.clientHeight) &&
|
|
18
|
+
distance.right <=
|
|
19
|
+
(window.innerWidth || document.documentElement.clientWidth));
|
|
20
|
+
}
|
|
21
|
+
exports.isInViewport = isInViewport;
|
|
22
|
+
exports.default = isInViewport;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isNodeList = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Is node list
|
|
6
|
+
*
|
|
7
|
+
* @param nodes The object to check
|
|
8
|
+
*/
|
|
9
|
+
function isNodeList(nodes) {
|
|
10
|
+
var stringRepr = Object.prototype.toString.call(nodes);
|
|
11
|
+
return (typeof nodes === "object" &&
|
|
12
|
+
/^\[object (HTMLCollection|NodeList|Object)\]$/.test(stringRepr) &&
|
|
13
|
+
typeof nodes.length === "number" &&
|
|
14
|
+
(nodes.length === 0 ||
|
|
15
|
+
(typeof nodes[0] === "object" && nodes[0].nodeType > 0)));
|
|
16
|
+
}
|
|
17
|
+
exports.isNodeList = isNodeList;
|
|
18
|
+
exports.default = isNodeList;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isTotallyScrolled = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Is element totally scrolled
|
|
6
|
+
*
|
|
7
|
+
* @see https://github.com/willmcpo/body-scroll-lock/blob/master/src/bodyScrollLock.js#L116
|
|
8
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight#Problems_and_solutions
|
|
9
|
+
*/
|
|
10
|
+
function isTotallyScrolled(el) {
|
|
11
|
+
return el ? el.scrollHeight - el.scrollTop <= el.clientHeight : false;
|
|
12
|
+
}
|
|
13
|
+
exports.isTotallyScrolled = isTotallyScrolled;
|
|
14
|
+
exports.default = isTotallyScrolled;
|
package/node/listen.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listen = void 0;
|
|
4
|
+
var _listen_delegation_1 = require("./_listen-delegation");
|
|
5
|
+
var on_1 = require("./on");
|
|
6
|
+
/**
|
|
7
|
+
* Listen an event
|
|
8
|
+
*
|
|
9
|
+
* @category listen-delegation
|
|
10
|
+
*
|
|
11
|
+
* @param types The event type or types (comma separated)
|
|
12
|
+
* @param selector The selector to run the event on
|
|
13
|
+
* @param callback The function to run when the event fires
|
|
14
|
+
*/
|
|
15
|
+
function listen(types, selector, callback) {
|
|
16
|
+
// Make sure there's a selector and callback
|
|
17
|
+
if (!selector || !callback)
|
|
18
|
+
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 (!_listen_delegation_1.activeEvents[type]) {
|
|
25
|
+
_listen_delegation_1.activeEvents[type] = [];
|
|
26
|
+
(0, on_1.on)(window, type, _listen_delegation_1.eventHandler, true);
|
|
27
|
+
}
|
|
28
|
+
// Push to active events
|
|
29
|
+
_listen_delegation_1.activeEvents[type].push({
|
|
30
|
+
selector: selector,
|
|
31
|
+
callback: callback,
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
exports.listen = listen;
|
|
36
|
+
exports.default = listen;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listenLoaded = void 0;
|
|
4
|
+
var on_1 = require("./on");
|
|
5
|
+
/**
|
|
6
|
+
* Fires a callback when the DOM content is loaded
|
|
7
|
+
*
|
|
8
|
+
* @see https://mathiasbynens.be/notes/settimeout-onload
|
|
9
|
+
*/
|
|
10
|
+
function listenLoaded(handler) {
|
|
11
|
+
(0, on_1.on)(document, "DOMContentLoaded", handler);
|
|
12
|
+
// document.addEventListener("DOMContentLoaded", setTimeout(handler, 4));
|
|
13
|
+
}
|
|
14
|
+
exports.listenLoaded = listenLoaded;
|
|
15
|
+
exports.default = listenLoaded;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listenOnce = void 0;
|
|
4
|
+
var _listen_delegation_1 = require("./_listen-delegation");
|
|
5
|
+
var listen_1 = require("./listen");
|
|
6
|
+
var unlisten_1 = require("./unlisten");
|
|
7
|
+
/**
|
|
8
|
+
* Listen an event, and automatically unlisten it after it's first run
|
|
9
|
+
*
|
|
10
|
+
* @category listen-delegation
|
|
11
|
+
*
|
|
12
|
+
* @param types The event type or types (comma separated)
|
|
13
|
+
* @param selector The selector to run the event on
|
|
14
|
+
* @param callback The function to run when the event fires
|
|
15
|
+
*/
|
|
16
|
+
function listenOnce(types, selector, callback) {
|
|
17
|
+
(0, listen_1.listen)(types, selector, function temp(event) {
|
|
18
|
+
var target = (0, _listen_delegation_1.getRunTarget)(event.target, selector);
|
|
19
|
+
callback(event, target || window);
|
|
20
|
+
(0, unlisten_1.unlisten)(types, selector, temp);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
exports.listenOnce = listenOnce;
|
|
24
|
+
exports.default = listenOnce;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listenResize = void 0;
|
|
4
|
+
var utils_1 = require("@koine/utils");
|
|
5
|
+
var on_1 = require("./on");
|
|
6
|
+
var off_1 = require("./off");
|
|
7
|
+
/**
|
|
8
|
+
* Listen window resize event debouncing the given handler
|
|
9
|
+
*
|
|
10
|
+
* @returns An automatic unbinding function to run to deregister the listener upon call
|
|
11
|
+
*/
|
|
12
|
+
function listenResize() {
|
|
13
|
+
var args = [];
|
|
14
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
15
|
+
args[_i] = arguments[_i];
|
|
16
|
+
}
|
|
17
|
+
var handler = utils_1.debounce.apply(void 0, args);
|
|
18
|
+
(0, on_1.on)(window, "resize", handler);
|
|
19
|
+
/**
|
|
20
|
+
* Unbind the previously attached scroll handler
|
|
21
|
+
*/
|
|
22
|
+
function unbinder() {
|
|
23
|
+
handler.cancel();
|
|
24
|
+
(0, off_1.off)(window, "resize", handler);
|
|
25
|
+
}
|
|
26
|
+
return unbinder;
|
|
27
|
+
}
|
|
28
|
+
exports.listenResize = listenResize;
|
|
29
|
+
exports.default = listenResize;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listenScroll = void 0;
|
|
4
|
+
var utils_1 = require("@koine/utils");
|
|
5
|
+
var on_1 = require("./on");
|
|
6
|
+
var off_1 = require("./off");
|
|
7
|
+
/**
|
|
8
|
+
* Listen window scroll event debouncing the given handler
|
|
9
|
+
*
|
|
10
|
+
* @returns An automatic unbinding function to run to deregister the listener upon call
|
|
11
|
+
*/
|
|
12
|
+
function listenScroll() {
|
|
13
|
+
var args = [];
|
|
14
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
15
|
+
args[_i] = arguments[_i];
|
|
16
|
+
}
|
|
17
|
+
var handler = utils_1.debounce.apply(void 0, args);
|
|
18
|
+
(0, on_1.on)(window, "scroll", handler, {
|
|
19
|
+
capture: true,
|
|
20
|
+
passive: true,
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* Unbind the previously attached scroll handler
|
|
24
|
+
*/
|
|
25
|
+
function unbinder() {
|
|
26
|
+
handler.cancel();
|
|
27
|
+
(0, off_1.off)(window, "scroll", handler);
|
|
28
|
+
}
|
|
29
|
+
return unbinder;
|
|
30
|
+
}
|
|
31
|
+
exports.listenScroll = listenScroll;
|
|
32
|
+
exports.default = listenScroll;
|
package/node/off.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.off = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Shortcut for `removeEventListener`
|
|
6
|
+
*/
|
|
7
|
+
function off(el, type, handler, options) {
|
|
8
|
+
if (options === void 0) { options = false; }
|
|
9
|
+
if (process.env["NODE_ENV"] !== "production") {
|
|
10
|
+
if (!el) {
|
|
11
|
+
console.warn("[@koine/dom:off] unexisting DOM element");
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
if (el)
|
|
16
|
+
el.removeEventListener(type, handler, options);
|
|
17
|
+
}
|
|
18
|
+
exports.off = off;
|
|
19
|
+
exports.default = off;
|
package/node/on.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.on = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Shortcut for `addEventListener`
|
|
6
|
+
*/
|
|
7
|
+
function on(el, type, handler, 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
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
if (el)
|
|
16
|
+
el.addEventListener(type, handler, options);
|
|
17
|
+
}
|
|
18
|
+
exports.on = on;
|
|
19
|
+
exports.default = on;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.onClickOutside = void 0;
|
|
4
|
+
var index_1 = require("./index");
|
|
5
|
+
function onClickOutside(element, callback, autoUnbind) {
|
|
6
|
+
if (autoUnbind === void 0) { autoUnbind = false; }
|
|
7
|
+
var bind = function (event) {
|
|
8
|
+
// if (event.target.closest(element) === null) {
|
|
9
|
+
if (!element.contains(event.target)) {
|
|
10
|
+
callback(event);
|
|
11
|
+
if (autoUnbind)
|
|
12
|
+
unbind();
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var unbind = function () {
|
|
16
|
+
(0, index_1.off)(document, "click", bind);
|
|
17
|
+
};
|
|
18
|
+
(0, index_1.on)(document, "click", bind);
|
|
19
|
+
return unbind;
|
|
20
|
+
}
|
|
21
|
+
exports.onClickOutside = onClickOutside;
|
package/node/once.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.once = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var on_1 = tslib_1.__importDefault(require("./on"));
|
|
6
|
+
var off_1 = tslib_1.__importDefault(require("./off"));
|
|
7
|
+
/**
|
|
8
|
+
* One shot listener, it `addEventListener` and removes it first time is called
|
|
9
|
+
* with `removeEventListener`
|
|
10
|
+
*/
|
|
11
|
+
function once(el, type, handler, options) {
|
|
12
|
+
if (options === void 0) { options = false; }
|
|
13
|
+
var handlerWrapper = function (event) {
|
|
14
|
+
handler(event);
|
|
15
|
+
(0, off_1.default)(el, type, handlerWrapper);
|
|
16
|
+
};
|
|
17
|
+
(0, on_1.default)(el, type, handlerWrapper, options);
|
|
18
|
+
}
|
|
19
|
+
exports.once = once;
|
|
20
|
+
exports.default = once;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeClass = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Remove class shortcut
|
|
6
|
+
*/
|
|
7
|
+
function removeClass(el, className) {
|
|
8
|
+
if (className === void 0) { className = ""; }
|
|
9
|
+
if (process.env["NODE_ENV"] !== "production") {
|
|
10
|
+
if (!el) {
|
|
11
|
+
("[@koine/dom:removeClass] unexisting DOM element");
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
if (el)
|
|
16
|
+
el.classList.remove(className);
|
|
17
|
+
}
|
|
18
|
+
exports.removeClass = removeClass;
|
|
19
|
+
exports.default = removeClass;
|
package/node/scrollTo.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.scrollTo = void 0;
|
|
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
|
+
*/
|
|
14
|
+
function scrollTo(offset, callback) {
|
|
15
|
+
var fixedOffset = offset.toFixed();
|
|
16
|
+
if (callback) {
|
|
17
|
+
var onScroll_1 = function () {
|
|
18
|
+
if (window.pageYOffset.toFixed() === fixedOffset) {
|
|
19
|
+
(0, off_1.off)(window, "scroll", onScroll_1);
|
|
20
|
+
callback();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
(0, on_1.on)(window, "scroll", onScroll_1);
|
|
24
|
+
onScroll_1();
|
|
25
|
+
}
|
|
26
|
+
window.scrollTo({
|
|
27
|
+
top: offset,
|
|
28
|
+
behavior: "smooth",
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
exports.scrollTo = scrollTo;
|
|
32
|
+
exports.default = scrollTo;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
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) {
|
|
12
|
+
if (value === null || typeof value === "undefined") {
|
|
13
|
+
// delete element.dataset[attribute];
|
|
14
|
+
// return;
|
|
15
|
+
element.removeAttribute("data-" + attribute);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
// element.dataset[attribute] = value.toString();
|
|
19
|
+
element.setAttribute("data-" + attribute, value.toString());
|
|
20
|
+
}
|
|
21
|
+
exports.setDataAttr = setDataAttr;
|
|
22
|
+
exports.default = setDataAttr;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
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) {
|
|
12
|
+
var propUpper = prop.charAt(0).toUpperCase() + prop.slice(1);
|
|
13
|
+
// @ts-expect-error nevermind now...
|
|
14
|
+
element.style["webkit" + propUpper] = value;
|
|
15
|
+
// @ts-expect-error nevermind now...
|
|
16
|
+
element.style["moz" + propUpper] = value;
|
|
17
|
+
// @ts-expect-error nevermind now...
|
|
18
|
+
element.style["ms" + propUpper] = value;
|
|
19
|
+
// @ts-expect-error nevermind now...
|
|
20
|
+
element.style["o" + propUpper] = value;
|
|
21
|
+
// @ts-expect-error nevermind now...
|
|
22
|
+
element.style[prop] = value;
|
|
23
|
+
}
|
|
24
|
+
exports.setVendorCSS = setVendorCSS;
|
|
25
|
+
exports.default = setVendorCSS;
|
package/node/siblings.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
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) {
|
|
10
|
+
if (node && node.parentNode) {
|
|
11
|
+
var n = node.parentNode.firstChild;
|
|
12
|
+
var matched = [];
|
|
13
|
+
for (; n; n = n.nextSibling) {
|
|
14
|
+
if (n.nodeType === 1 && n !== node) {
|
|
15
|
+
matched.push(n);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return matched;
|
|
19
|
+
}
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
exports.siblings = siblings;
|
|
23
|
+
exports.default = siblings;
|
package/node/toArray.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
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) {
|
|
10
|
+
return Array.prototype.slice.call(nodeList);
|
|
11
|
+
}
|
|
12
|
+
exports.toArray = toArray;
|
|
13
|
+
exports.default = toArray;
|
package/node/unlisten.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unlisten = void 0;
|
|
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
|
|
17
|
+
types.split(",").forEach(function (type) {
|
|
18
|
+
// Remove whitespace
|
|
19
|
+
type = type.trim();
|
|
20
|
+
// if event type doesn't exist, bail
|
|
21
|
+
if (!_listen_delegation_1.activeEvents[type])
|
|
22
|
+
return;
|
|
23
|
+
// If it's the last event of it's type, remove entirely
|
|
24
|
+
if (_listen_delegation_1.activeEvents[type].length < 2 || !selector) {
|
|
25
|
+
delete _listen_delegation_1.activeEvents[type];
|
|
26
|
+
(0, off_1.off)(window, type, _listen_delegation_1.eventHandler, true);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// Otherwise, remove event
|
|
30
|
+
var index = (0, _listen_delegation_1.getIndex)(_listen_delegation_1.activeEvents[type], selector, callback);
|
|
31
|
+
if (index < 0)
|
|
32
|
+
return;
|
|
33
|
+
_listen_delegation_1.activeEvents[type].splice(index, 1);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
exports.unlisten = unlisten;
|
|
37
|
+
exports.default = unlisten;
|
package/off.d.ts
ADDED
package/off.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
if (el)
|
|
13
|
+
el.removeEventListener(type, handler, options);
|
|
14
|
+
}
|
|
15
|
+
export default off;
|
package/on.d.ts
ADDED
package/on.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shortcut for `addEventListener`
|
|
3
|
+
*/
|
|
4
|
+
export function on(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:on] unexisting DOM element");
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
if (el)
|
|
13
|
+
el.addEventListener(type, handler, options);
|
|
14
|
+
}
|
|
15
|
+
export default on;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function onClickOutside(element: HTMLElement, callback: (event: Event) => any, autoUnbind?: boolean): () => void;
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
}
|