@koine/dom 2.0.0-beta.1 → 2.0.0-beta.11
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 -1
- package/$$.mjs +1 -2
- package/$.d.ts +1 -1
- package/$.mjs +1 -2
- package/$each.mjs +3 -4
- package/_listen-delegation.d.ts +3 -2
- package/_listen-delegation.mjs +17 -23
- package/addClass.mjs +2 -5
- package/calculateFixedOffset.mjs +3 -4
- package/createElement.mjs +2 -3
- package/emitEvent.mjs +3 -7
- package/escapeSelector.mjs +1 -2
- package/exists.mjs +1 -2
- package/forEach.d.ts +3 -5
- package/forEach.mjs +29 -8
- package/getDataAttr.mjs +1 -2
- package/getDocumentHeight.mjs +2 -3
- package/getHeight.mjs +1 -2
- package/getListeners.d.ts +1 -1
- package/getListeners.mjs +4 -5
- package/getOffset.mjs +8 -6
- package/getOffsetTop.mjs +3 -4
- package/getOffsetTopSlim.mjs +1 -2
- package/getScrollbarWidth.mjs +1 -2
- package/getStyleValue.mjs +1 -2
- package/getVisualBackgroundColor.mjs +8 -10
- package/injectCss.mjs +2 -5
- package/isHidden.mjs +1 -2
- package/isInViewport.mjs +3 -9
- package/isNodeList.mjs +3 -8
- package/isTotallyScrolled.mjs +1 -2
- package/listen.d.ts +2 -1
- package/listen.mjs +11 -8
- package/listenLoaded.mjs +2 -3
- package/listenOnce.mjs +2 -3
- package/listenResize.mjs +1 -2
- package/listenResizeDebounced.mjs +28 -36
- package/listenResizeThrottled.mjs +1 -8
- package/listenScroll.mjs +2 -5
- package/listenScrollDebounced.mjs +1 -8
- package/listenScrollThrottled.mjs +1 -8
- package/off.d.ts +2 -2
- package/off.mjs +2 -5
- package/on.d.ts +2 -2
- package/on.mjs +5 -5
- package/onClickOutside.mjs +5 -7
- package/once.mjs +3 -5
- package/package.json +8 -5
- package/removeClass.mjs +3 -6
- package/scrollTo.mjs +13 -14
- package/setDataAttr.mjs +1 -2
- package/setVendorCSS.mjs +2 -3
- package/siblings.mjs +4 -5
- package/toArray.mjs +1 -2
- package/types.d.ts +5 -0
- package/types.mjs +1 -1
- package/unlisten.d.ts +2 -1
- package/unlisten.mjs +11 -9
- package/$$.js +0 -16
- package/$.js +0 -19
- package/$each.js +0 -22
- package/_listen-delegation.js +0 -90
- package/addClass.js +0 -19
- package/calculateFixedOffset.js +0 -14
- package/createElement.js +0 -21
- package/emitEvent.js +0 -18
- package/escapeSelector.js +0 -14
- package/exists.js +0 -16
- package/forEach.js +0 -17
- package/getDataAttr.js +0 -17
- package/getDocumentHeight.js +0 -14
- package/getHeight.js +0 -11
- package/getListeners.js +0 -22
- package/getOffset.js +0 -22
- package/getOffsetTop.js +0 -24
- package/getOffsetTopSlim.js +0 -17
- package/getScrollbarWidth.js +0 -11
- package/getStyleValue.js +0 -14
- package/getVisualBackground.d.ts +0 -6
- package/getVisualBackground.js +0 -25
- package/getVisualBackground.mjs +0 -21
- package/getVisualBackgroundColor.js +0 -25
- package/index.js +0 -93
- package/injectCss.js +0 -20
- package/isHidden.js +0 -11
- package/isInViewport.js +0 -22
- package/isNodeList.js +0 -18
- package/isTotallyScrolled.js +0 -14
- package/listen.js +0 -37
- package/listenLoaded.js +0 -15
- package/listenOnce.js +0 -24
- package/listenResize.js +0 -12
- package/listenResizeDebounced.js +0 -47
- package/listenResizeThrottled.js +0 -20
- package/listenScroll.js +0 -17
- package/listenScrollDebounced.js +0 -20
- package/listenScrollThrottled.js +0 -20
- package/off.js +0 -18
- package/on.js +0 -26
- package/onClickOutside.js +0 -21
- package/once.js +0 -20
- package/removeClass.js +0 -19
- package/scrollTo.js +0 -44
- package/setDataAttr.js +0 -22
- package/setVendorCSS.js +0 -25
- package/siblings.js +0 -23
- package/toArray.js +0 -13
- package/types.js +0 -2
- package/unlisten.js +0 -37
|
@@ -4,39 +4,31 @@ import listenResize from "./listenResize";
|
|
|
4
4
|
* Listen element's (`window` by default) _resize_ event debouncing the callback
|
|
5
5
|
*
|
|
6
6
|
* @returns An automatic unbinding function to run to deregister the listener upon call
|
|
7
|
-
*/
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
//
|
|
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;
|
|
7
|
+
*/ export const listenResizeDebounced = (el, ...args)=>listenResize(debounce(...args), el);
|
|
8
|
+
export default listenResizeDebounced; // EXP: with too complex overload signature...
|
|
9
|
+
// import debounce from "@koine/utils/debounce";
|
|
10
|
+
// import isUndefined from "@koine/utils/isUndefined";
|
|
11
|
+
// import listenResize from "./listenResize";
|
|
12
|
+
// /**
|
|
13
|
+
// * Listen element's (`window` by default) _resize_ event debouncing the callback
|
|
14
|
+
// *
|
|
15
|
+
// * @returns An automatic unbinding function to run to deregister the listener upon call
|
|
16
|
+
// */
|
|
17
|
+
// export function listenResizeDebounced(
|
|
18
|
+
// ...args: Parameters<typeof debounce>
|
|
19
|
+
// ): ReturnType<typeof listenResize>;
|
|
20
|
+
// export function listenResizeDebounced(
|
|
21
|
+
// el: Parameters<typeof listenResize>[1],
|
|
22
|
+
// ...args: Parameters<typeof debounce>
|
|
23
|
+
// ): ReturnType<typeof listenResize>;
|
|
24
|
+
// export function listenResizeDebounced(
|
|
25
|
+
// ...args:
|
|
26
|
+
// | [Parameters<typeof listenResize>[1], ...Parameters<typeof debounce>]
|
|
27
|
+
// | Parameters<typeof debounce>
|
|
28
|
+
// ) {
|
|
29
|
+
// if (isUndefined(args[0])) {
|
|
30
|
+
// return listenResize(debounce(...args));
|
|
31
|
+
// }
|
|
32
|
+
// return listenResize(debounce(...args.slice(1)), args[0]);
|
|
33
|
+
// }
|
|
34
|
+
// export default listenResizeDebounced;
|
|
@@ -4,12 +4,5 @@ import { listenResize } from "./listenResize";
|
|
|
4
4
|
* Listen element's (`window` by default) _resize_ event throttling the callback
|
|
5
5
|
*
|
|
6
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
|
-
};
|
|
7
|
+
*/ export const listenResizeThrottled = (el, ...args)=>listenResize(throttle(...args), el);
|
|
15
8
|
export default listenResizeThrottled;
|
package/listenScroll.mjs
CHANGED
|
@@ -3,11 +3,8 @@ import { on } from "./on";
|
|
|
3
3
|
* Listen element's (`window` by default) _scroll_ event
|
|
4
4
|
*
|
|
5
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, {
|
|
6
|
+
*/ export const listenScroll = (handler, el)=>on(el || window, "scroll", handler, {
|
|
9
7
|
capture: true,
|
|
10
|
-
passive: true
|
|
8
|
+
passive: true
|
|
11
9
|
});
|
|
12
|
-
};
|
|
13
10
|
export default listenScroll;
|
|
@@ -4,12 +4,5 @@ import { listenScroll } from "./listenScroll";
|
|
|
4
4
|
* Listen element's (`window` by default) _scroll_ event debouncing the callback
|
|
5
5
|
*
|
|
6
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
|
-
};
|
|
7
|
+
*/ export const listenScrollDebounced = (el, ...args)=>listenScroll(debounce(...args), el);
|
|
15
8
|
export default listenScrollDebounced;
|
|
@@ -4,12 +4,5 @@ import { listenScroll } from "./listenScroll";
|
|
|
4
4
|
* Listen element's (`window` by default) _scroll_ event throttling the callback
|
|
5
5
|
*
|
|
6
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
|
-
};
|
|
7
|
+
*/ export const listenScrollThrottled = (el, ...args)=>listenScroll(throttle(...args), el);
|
|
15
8
|
export default listenScrollThrottled;
|
package/off.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { AnyDOMEventTargetLoose } from "./types";
|
|
1
|
+
import type { AnyDOMEvent, AnyDOMEventTargetLoose, AnyDOMEventType } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* Shortcut for `removeEventListener`
|
|
4
4
|
*/
|
|
5
|
-
export declare function off(el: AnyDOMEventTargetLoose, type:
|
|
5
|
+
export declare function off<TType extends AnyDOMEventType>(el: AnyDOMEventTargetLoose, type: TType, handler: (event: AnyDOMEvent<TType>) => void, options?: EventListenerOptions | boolean): void;
|
|
6
6
|
export default off;
|
package/off.mjs
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shortcut for `removeEventListener`
|
|
3
|
-
*/
|
|
4
|
-
export function off(el, type, handler, options) {
|
|
5
|
-
if (options === void 0) { options = false; }
|
|
3
|
+
*/ export function off(el, type, handler, options = false) {
|
|
6
4
|
if (process.env["NODE_ENV"] !== "production") {
|
|
7
5
|
if (!el) {
|
|
8
6
|
console.warn("[@koine/dom:off] unexisting DOM element");
|
|
9
7
|
}
|
|
10
8
|
}
|
|
11
|
-
if (el)
|
|
12
|
-
el.removeEventListener(type, handler, options);
|
|
9
|
+
if (el) el.removeEventListener(type, handler, options);
|
|
13
10
|
}
|
|
14
11
|
export default off;
|
package/on.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { AnyDOMEventTargetLoose } from "./types";
|
|
1
|
+
import type { AnyDOMEvent, AnyDOMEventTargetLoose, AnyDOMEventType } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* Shortcut for `addEventListener`
|
|
4
4
|
*
|
|
5
5
|
* @returns An automatic unbinding function to run to deregister the listener upon call
|
|
6
6
|
*/
|
|
7
|
-
export declare function on<
|
|
7
|
+
export declare function on<TType extends AnyDOMEventType>(el: AnyDOMEventTargetLoose, type: TType, handler: (event: AnyDOMEvent<TType>) => void, options?: AddEventListenerOptions | boolean): () => void;
|
|
8
8
|
export default on;
|
package/on.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
// import noop from "@koine/utils/noop"; FIXME: build breaks with this import
|
|
1
2
|
import off from "./off";
|
|
2
3
|
/**
|
|
3
4
|
* Shortcut for `addEventListener`
|
|
4
5
|
*
|
|
5
6
|
* @returns An automatic unbinding function to run to deregister the listener upon call
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
if (options === void 0) { options = false; }
|
|
7
|
+
*/ export function on(el, type, handler, // handler: THandler /* EventListener | */ /* ((event: Event) => void) */,
|
|
8
|
+
options = false) {
|
|
9
9
|
if (process.env["NODE_ENV"] !== "production") {
|
|
10
10
|
if (!el) {
|
|
11
11
|
console.warn("[@koine/dom:on] unexisting DOM element");
|
|
@@ -13,9 +13,9 @@ export function on(el, type, handler /* EventListener | */ /* ((event: Event) =
|
|
|
13
13
|
}
|
|
14
14
|
if (el) {
|
|
15
15
|
el.addEventListener(type, handler, options);
|
|
16
|
-
return
|
|
16
|
+
return ()=>off(el, type, handler);
|
|
17
17
|
}
|
|
18
18
|
// return noop;
|
|
19
|
-
return
|
|
19
|
+
return ()=>void 0;
|
|
20
20
|
}
|
|
21
21
|
export default on;
|
package/onClickOutside.mjs
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export function onClickOutside(element, callback, autoUnbind) {
|
|
3
|
-
|
|
4
|
-
var bind = function (event) {
|
|
1
|
+
import { off, on } from "./index";
|
|
2
|
+
export function onClickOutside(element, callback, autoUnbind = false) {
|
|
3
|
+
const bind = (event)=>{
|
|
5
4
|
// if (event.target.closest(element) === null) {
|
|
6
5
|
if (!element.contains(event.target)) {
|
|
7
6
|
callback(event);
|
|
8
|
-
if (autoUnbind)
|
|
9
|
-
unbind();
|
|
7
|
+
if (autoUnbind) unbind();
|
|
10
8
|
}
|
|
11
9
|
};
|
|
12
|
-
|
|
10
|
+
const unbind = ()=>{
|
|
13
11
|
off(document, "click", bind);
|
|
14
12
|
};
|
|
15
13
|
on(document, "click", bind);
|
package/once.mjs
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import on from "./on";
|
|
2
1
|
import off from "./off";
|
|
2
|
+
import on from "./on";
|
|
3
3
|
/**
|
|
4
4
|
* One shot listener, it `addEventListener` and removes it first time is called
|
|
5
5
|
* with `removeEventListener`
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
if (options === void 0) { options = false; }
|
|
9
|
-
var handlerWrapper = function (event) {
|
|
6
|
+
*/ export function once(el, type, handler, options = false) {
|
|
7
|
+
const handlerWrapper = (event)=>{
|
|
10
8
|
handler(event);
|
|
11
9
|
off(el, type, handlerWrapper);
|
|
12
10
|
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koine/dom",
|
|
3
3
|
"sideEffects": false,
|
|
4
|
-
"
|
|
5
|
-
"
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"@koine/utils": "2.0.0-beta.11"
|
|
6
6
|
},
|
|
7
|
+
"module": "./index.mjs",
|
|
7
8
|
"main": "./index.js",
|
|
8
9
|
"types": "./index.d.ts",
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
}
|
|
10
|
+
"peerDependencies": {
|
|
11
|
+
"type-fest": "^4.1.0"
|
|
12
|
+
},
|
|
13
|
+
"version": "2.0.0-beta.11"
|
|
14
|
+
}
|
package/removeClass.mjs
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Remove class shortcut
|
|
3
|
-
*/
|
|
4
|
-
export function removeClass(el, className) {
|
|
5
|
-
if (className === void 0) { className = ""; }
|
|
3
|
+
*/ export function removeClass(el, className = "") {
|
|
6
4
|
if (process.env["NODE_ENV"] !== "production") {
|
|
7
5
|
if (!el) {
|
|
8
|
-
|
|
6
|
+
"[@koine/dom:removeClass] unexisting DOM element";
|
|
9
7
|
return;
|
|
10
8
|
}
|
|
11
9
|
}
|
|
12
|
-
if (el)
|
|
13
|
-
el.classList.remove(className);
|
|
10
|
+
if (el) el.classList.remove(className);
|
|
14
11
|
}
|
|
15
12
|
export default removeClass;
|
package/scrollTo.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { on } from "./on";
|
|
2
1
|
import { off } from "./off";
|
|
2
|
+
import { on } from "./on";
|
|
3
3
|
/**
|
|
4
4
|
* Native `scrollTo`, `"smooth"` and with callback
|
|
5
5
|
*
|
|
@@ -9,24 +9,23 @@ import { off } from "./off";
|
|
|
9
9
|
* @param callback - callback function
|
|
10
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
11
|
* @param [behavior="smooth"]
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
var fixedDestination = destination.toFixed();
|
|
12
|
+
*/ export function scrollTo(destination, callback, fallbackTimeout, behavior) {
|
|
13
|
+
const fixedDestination = destination.toFixed();
|
|
15
14
|
if (callback) {
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
let callbackFired = false;
|
|
16
|
+
const onScroll = function() {
|
|
18
17
|
if (window.pageYOffset.toFixed() === fixedDestination) {
|
|
19
|
-
off(window, "scroll",
|
|
20
|
-
|
|
18
|
+
off(window, "scroll", onScroll);
|
|
19
|
+
callbackFired = true;
|
|
21
20
|
callback();
|
|
22
21
|
}
|
|
23
22
|
};
|
|
24
|
-
on(window, "scroll",
|
|
25
|
-
|
|
23
|
+
on(window, "scroll", onScroll);
|
|
24
|
+
onScroll();
|
|
26
25
|
if (fallbackTimeout) {
|
|
27
|
-
setTimeout(
|
|
28
|
-
if (!
|
|
29
|
-
off(window, "scroll",
|
|
26
|
+
setTimeout(()=>{
|
|
27
|
+
if (!callbackFired) {
|
|
28
|
+
off(window, "scroll", onScroll);
|
|
30
29
|
callback();
|
|
31
30
|
}
|
|
32
31
|
}, fallbackTimeout);
|
|
@@ -34,7 +33,7 @@ export function scrollTo(destination, callback, fallbackTimeout, behavior) {
|
|
|
34
33
|
}
|
|
35
34
|
window.scrollTo({
|
|
36
35
|
top: destination,
|
|
37
|
-
behavior: behavior || "smooth"
|
|
36
|
+
behavior: behavior || "smooth"
|
|
38
37
|
});
|
|
39
38
|
}
|
|
40
39
|
export default scrollTo;
|
package/setDataAttr.mjs
CHANGED
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
* @param element
|
|
5
5
|
* @param attribute The name of the `data-{attr}`
|
|
6
6
|
* @param value The value to set, `null` or `undefined` will remove the attribute
|
|
7
|
-
*/
|
|
8
|
-
export function setDataAttr(element, attribute, value) {
|
|
7
|
+
*/ export function setDataAttr(element, attribute, value) {
|
|
9
8
|
if (value === null || typeof value === "undefined") {
|
|
10
9
|
// delete element.dataset[attribute];
|
|
11
10
|
// return;
|
package/setVendorCSS.mjs
CHANGED
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
* @param element A single HTMLElement
|
|
5
5
|
* @param prop CSS rule proerty
|
|
6
6
|
* @param value The CSS value to set, it will be automatically vendor prefixed
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
var propUpper = prop.charAt(0).toUpperCase() + prop.slice(1);
|
|
7
|
+
*/ export function setVendorCSS(element, prop, value) {
|
|
8
|
+
const propUpper = prop.charAt(0).toUpperCase() + prop.slice(1);
|
|
10
9
|
// @ts-expect-error nevermind now...
|
|
11
10
|
element.style["webkit" + propUpper] = value;
|
|
12
11
|
// @ts-expect-error nevermind now...
|
package/siblings.mjs
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
* Finds siblings nodes of the passed node.
|
|
3
3
|
*
|
|
4
4
|
* @borrows @glidejs/glide/src/utils/dom (source)
|
|
5
|
-
*/
|
|
6
|
-
export function siblings(node) {
|
|
5
|
+
*/ export function siblings(node) {
|
|
7
6
|
if (node && node.parentNode) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
for
|
|
7
|
+
let n = node.parentNode.firstChild;
|
|
8
|
+
const matched = [];
|
|
9
|
+
for(; n; n = n.nextSibling){
|
|
11
10
|
if (n.nodeType === 1 && n !== node) {
|
|
12
11
|
matched.push(n);
|
|
13
12
|
}
|
package/toArray.mjs
CHANGED
package/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LiteralUnion } from "type-fest";
|
|
1
2
|
import type { AnythingFalsy } from "@koine/utils/types";
|
|
2
3
|
export type AnyDOMEventTarget = Window | Document | HTMLElement | Element;
|
|
3
4
|
/**
|
|
@@ -5,3 +6,7 @@ export type AnyDOMEventTarget = Window | Document | HTMLElement | Element;
|
|
|
5
6
|
* to `window` in case of _scroll_ or _resize_ events
|
|
6
7
|
*/
|
|
7
8
|
export type AnyDOMEventTargetLoose = AnyDOMEventTarget | AnythingFalsy;
|
|
9
|
+
type StandardDOMEventTypes = keyof GlobalEventHandlersEventMap;
|
|
10
|
+
export type AnyDOMEventType = LiteralUnion<StandardDOMEventTypes | "storage" | "popstate", string>;
|
|
11
|
+
export type AnyDOMEvent<TType extends AnyDOMEventType> = TType extends StandardDOMEventTypes ? GlobalEventHandlersEventMap[TType] : TType extends "storage" ? StorageEvent : TType extends "popstate" ? PopStateEvent : Event;
|
|
12
|
+
export {};
|
package/types.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export { };
|
package/unlisten.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type EventCallback } from "./_listen-delegation";
|
|
2
|
+
import type { AnyDOMEventTarget, AnyDOMEventType } from "./types";
|
|
2
3
|
/**
|
|
3
4
|
* Stop listening for an event
|
|
4
5
|
*
|
|
@@ -8,5 +9,5 @@ import { type EventCallback } from "./_listen-delegation";
|
|
|
8
9
|
* @param selector The selector to remove the event from
|
|
9
10
|
* @param callback The function to remove
|
|
10
11
|
*/
|
|
11
|
-
export declare function unlisten(types:
|
|
12
|
+
export declare function unlisten<TTypes extends AnyDOMEventType, TTarget extends AnyDOMEventTarget = AnyDOMEventTarget>(types: TTypes, selector: string, callback: EventCallback<TTarget, TTypes>): void;
|
|
12
13
|
export default unlisten;
|
package/unlisten.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { activeEvents,
|
|
1
|
+
import { activeEvents, eventHandler, getIndex } from "./_listen-delegation";
|
|
2
2
|
import { off } from "./off";
|
|
3
3
|
/**
|
|
4
4
|
* Stop listening for an event
|
|
@@ -8,15 +8,17 @@ import { off } from "./off";
|
|
|
8
8
|
* @param types The event type or types (comma separated)
|
|
9
9
|
* @param selector The selector to remove the event from
|
|
10
10
|
* @param callback The function to remove
|
|
11
|
-
*/
|
|
12
|
-
|
|
11
|
+
*/ export function unlisten(types, // | `${TTypes},${TTypes}`
|
|
12
|
+
// | `${TTypes},${TTypes},${TTypes}`
|
|
13
|
+
// | `${TTypes},${TTypes},${TTypes},${TTypes}`
|
|
14
|
+
// | `${TTypes},${TTypes},${TTypes},${TTypes},${TTypes}`,
|
|
15
|
+
selector, callback) {
|
|
13
16
|
// Loop through each event type
|
|
14
|
-
types.split(",").forEach(function
|
|
17
|
+
types.split(",").forEach(function(type) {
|
|
15
18
|
// Remove whitespace
|
|
16
19
|
type = type.trim();
|
|
17
20
|
// if event type doesn't exist, bail
|
|
18
|
-
if (!activeEvents[type])
|
|
19
|
-
return;
|
|
21
|
+
if (!activeEvents[type]) return;
|
|
20
22
|
// If it's the last event of it's type, remove entirely
|
|
21
23
|
if (activeEvents[type].length < 2 || !selector) {
|
|
22
24
|
delete activeEvents[type];
|
|
@@ -24,9 +26,9 @@ export function unlisten(types, selector, callback) {
|
|
|
24
26
|
return;
|
|
25
27
|
}
|
|
26
28
|
// Otherwise, remove event
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
// @ts-expect-error FIXME: type...
|
|
30
|
+
const index = getIndex(activeEvents[type], selector, callback);
|
|
31
|
+
if (index < 0) return;
|
|
30
32
|
activeEvents[type].splice(index, 1);
|
|
31
33
|
});
|
|
32
34
|
}
|
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/$.js
DELETED
|
@@ -1,19 +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.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/$each.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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;
|
package/_listen-delegation.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.eventHandler = exports.getRunTarget = exports.getIndex = exports.activeEvents = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
/**
|
|
6
|
-
* Listen: events delegation system
|
|
7
|
-
*
|
|
8
|
-
* From:
|
|
9
|
-
* https://github.com/cferdinandi/events
|
|
10
|
-
* https://github.com/cferdinandi/events/blob/master/src/js/events/events.js
|
|
11
|
-
*
|
|
12
|
-
* @fileoverview
|
|
13
|
-
*/
|
|
14
|
-
var isString_1 = tslib_1.__importDefault(require("@koine/utils/isString"));
|
|
15
|
-
var escapeSelector_1 = tslib_1.__importDefault(require("./escapeSelector"));
|
|
16
|
-
/**
|
|
17
|
-
* Active events
|
|
18
|
-
*
|
|
19
|
-
* @internal
|
|
20
|
-
*/
|
|
21
|
-
exports.activeEvents = {};
|
|
22
|
-
/**
|
|
23
|
-
* Get the index for the listener
|
|
24
|
-
*
|
|
25
|
-
* @internal
|
|
26
|
-
*/
|
|
27
|
-
function getIndex(arr, selector, callback) {
|
|
28
|
-
for (var i = 0; i < arr.length; i++) {
|
|
29
|
-
if (arr[i].selector === selector &&
|
|
30
|
-
arr[i].callback.toString() === callback.toString())
|
|
31
|
-
return i;
|
|
32
|
-
}
|
|
33
|
-
return -1;
|
|
34
|
-
}
|
|
35
|
-
exports.getIndex = getIndex;
|
|
36
|
-
/**
|
|
37
|
-
* Check if the listener callback should run or not
|
|
38
|
-
*
|
|
39
|
-
* @internal
|
|
40
|
-
* @param target The event.target
|
|
41
|
-
* @param selector The selector/element to check the target against
|
|
42
|
-
* @return If not false, run listener and pass the targeted element to use in the callback
|
|
43
|
-
*/
|
|
44
|
-
function getRunTarget(target, selector) {
|
|
45
|
-
// @ts-expect-error FIXME: type
|
|
46
|
-
if (["*", "window", window].includes(selector)) {
|
|
47
|
-
return window;
|
|
48
|
-
}
|
|
49
|
-
if ([
|
|
50
|
-
"document",
|
|
51
|
-
"document.documentElement",
|
|
52
|
-
document,
|
|
53
|
-
document.documentElement,
|
|
54
|
-
// @ts-expect-error FIXME: type
|
|
55
|
-
].includes(selector))
|
|
56
|
-
return document;
|
|
57
|
-
if ((0, isString_1.default)(selector)) {
|
|
58
|
-
return target.closest((0, escapeSelector_1.default)(selector));
|
|
59
|
-
}
|
|
60
|
-
// @ts-expect-error FIXME: type
|
|
61
|
-
if (typeof selector !== "string" && selector.contains) {
|
|
62
|
-
if (selector === target) {
|
|
63
|
-
return target;
|
|
64
|
-
}
|
|
65
|
-
// @ts-expect-error FIXME: type
|
|
66
|
-
if (selector.contains(target)) {
|
|
67
|
-
return selector;
|
|
68
|
-
}
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
exports.getRunTarget = getRunTarget;
|
|
74
|
-
/**
|
|
75
|
-
* Handle listeners after event fires
|
|
76
|
-
*
|
|
77
|
-
* @internal
|
|
78
|
-
*/
|
|
79
|
-
function eventHandler(event) {
|
|
80
|
-
if (!exports.activeEvents[event.type])
|
|
81
|
-
return;
|
|
82
|
-
exports.activeEvents[event.type].forEach(function (listener) {
|
|
83
|
-
var target = getRunTarget(event.target, listener.selector);
|
|
84
|
-
if (!target) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
listener.callback(event, target);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
exports.eventHandler = eventHandler;
|
package/addClass.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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;
|
package/calculateFixedOffset.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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;
|