@koine/dom 2.0.0-beta.1 → 2.0.0-beta.4
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/$$.js +19 -6
- package/$$.mjs +1 -2
- package/$.d.ts +1 -1
- package/$.js +19 -6
- package/$.mjs +1 -2
- package/$each.js +22 -17
- package/$each.mjs +3 -4
- package/_listen-delegation.d.ts +3 -2
- package/_listen-delegation.js +42 -49
- package/_listen-delegation.mjs +17 -23
- package/addClass.js +21 -10
- package/addClass.mjs +2 -5
- package/calculateFixedOffset.js +22 -9
- package/calculateFixedOffset.mjs +3 -4
- package/createElement.js +22 -15
- package/createElement.mjs +2 -3
- package/emitEvent.js +22 -12
- package/emitEvent.mjs +3 -7
- package/escapeSelector.js +19 -6
- package/escapeSelector.mjs +1 -2
- package/exists.js +19 -6
- package/exists.mjs +1 -2
- package/forEach.d.ts +4 -5
- package/forEach.js +22 -11
- package/forEach.mjs +4 -7
- package/getDataAttr.js +19 -6
- package/getDataAttr.mjs +1 -2
- package/getDocumentHeight.js +20 -7
- package/getDocumentHeight.mjs +2 -3
- package/getHeight.js +19 -6
- package/getHeight.mjs +1 -2
- package/getListeners.d.ts +1 -1
- package/getListeners.js +23 -16
- package/getListeners.mjs +4 -5
- package/getOffset.js +26 -10
- package/getOffset.mjs +8 -6
- package/getOffsetTop.js +21 -8
- package/getOffsetTop.mjs +3 -4
- package/getOffsetTopSlim.js +19 -6
- package/getOffsetTopSlim.mjs +1 -2
- package/getScrollbarWidth.js +19 -6
- package/getScrollbarWidth.mjs +1 -2
- package/getStyleValue.js +19 -6
- package/getStyleValue.mjs +1 -2
- package/getVisualBackgroundColor.js +26 -14
- package/getVisualBackgroundColor.mjs +8 -10
- package/index.js +191 -92
- package/injectCss.js +21 -10
- package/injectCss.mjs +2 -5
- package/isHidden.js +19 -6
- package/isHidden.mjs +1 -2
- package/isInViewport.js +21 -13
- package/isInViewport.mjs +3 -9
- package/isNodeList.js +21 -12
- package/isNodeList.mjs +3 -8
- package/isTotallyScrolled.js +19 -6
- package/isTotallyScrolled.mjs +1 -2
- package/listen.d.ts +2 -1
- package/listen.js +33 -25
- package/listen.mjs +11 -8
- package/listenLoaded.js +21 -12
- package/listenLoaded.mjs +2 -3
- package/listenOnce.js +24 -19
- package/listenOnce.mjs +2 -3
- package/listenResize.js +20 -11
- package/listenResize.mjs +1 -2
- package/listenResizeDebounced.js +48 -45
- package/listenResizeDebounced.mjs +28 -36
- package/listenResizeThrottled.js +21 -18
- package/listenResizeThrottled.mjs +1 -8
- package/listenScroll.js +21 -14
- package/listenScroll.mjs +2 -5
- package/listenScrollDebounced.js +21 -18
- package/listenScrollDebounced.mjs +1 -8
- package/listenScrollThrottled.js +21 -18
- package/listenScrollThrottled.mjs +1 -8
- package/off.d.ts +2 -2
- package/off.js +20 -11
- package/off.mjs +2 -5
- package/on.d.ts +2 -2
- package/on.js +25 -15
- package/on.mjs +5 -5
- package/onClickOutside.js +16 -12
- package/onClickOutside.mjs +5 -7
- package/once.js +25 -16
- package/once.mjs +3 -5
- package/package.json +14 -5
- package/removeClass.js +22 -11
- package/removeClass.mjs +3 -6
- package/scrollTo.js +31 -27
- package/scrollTo.mjs +13 -14
- package/setDataAttr.js +19 -6
- package/setDataAttr.mjs +1 -2
- package/setVendorCSS.js +20 -7
- package/setVendorCSS.mjs +2 -3
- package/siblings.js +22 -9
- package/siblings.mjs +4 -5
- package/toArray.js +19 -6
- package/toArray.mjs +1 -2
- package/types.d.ts +5 -0
- package/types.js +3 -1
- package/types.mjs +1 -1
- package/unlisten.d.ts +2 -1
- package/unlisten.js +34 -26
- package/unlisten.mjs +11 -9
- package/getVisualBackground.d.ts +0 -6
- package/getVisualBackground.js +0 -25
- package/getVisualBackground.mjs +0 -21
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.js
CHANGED
|
@@ -1,16 +1,30 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.siblings = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Finds siblings nodes of the passed node.
|
|
6
3
|
*
|
|
7
4
|
* @borrows @glidejs/glide/src/utils/dom (source)
|
|
8
|
-
*/
|
|
5
|
+
*/ "use strict";
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
function _export(target, all) {
|
|
10
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: all[name]
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
_export(exports, {
|
|
16
|
+
siblings: function() {
|
|
17
|
+
return siblings;
|
|
18
|
+
},
|
|
19
|
+
default: function() {
|
|
20
|
+
return _default;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
9
23
|
function siblings(node) {
|
|
10
24
|
if (node && node.parentNode) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
for
|
|
25
|
+
let n = node.parentNode.firstChild;
|
|
26
|
+
const matched = [];
|
|
27
|
+
for(; n; n = n.nextSibling){
|
|
14
28
|
if (n.nodeType === 1 && n !== node) {
|
|
15
29
|
matched.push(n);
|
|
16
30
|
}
|
|
@@ -19,5 +33,4 @@ function siblings(node) {
|
|
|
19
33
|
}
|
|
20
34
|
return [];
|
|
21
35
|
}
|
|
22
|
-
|
|
23
|
-
exports.default = siblings;
|
|
36
|
+
const _default = siblings;
|
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.js
CHANGED
|
@@ -1,13 +1,26 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toArray = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Node list to array
|
|
6
3
|
*
|
|
7
4
|
* @param nodeList
|
|
8
|
-
*/
|
|
5
|
+
*/ "use strict";
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
function _export(target, all) {
|
|
10
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: all[name]
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
_export(exports, {
|
|
16
|
+
toArray: function() {
|
|
17
|
+
return toArray;
|
|
18
|
+
},
|
|
19
|
+
default: function() {
|
|
20
|
+
return _default;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
9
23
|
function toArray(nodeList) {
|
|
10
24
|
return Array.prototype.slice.call(nodeList);
|
|
11
25
|
}
|
|
12
|
-
|
|
13
|
-
exports.default = toArray;
|
|
26
|
+
const _default = toArray;
|
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.js
CHANGED
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.js
CHANGED
|
@@ -1,37 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
function
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
unlisten: function() {
|
|
13
|
+
return unlisten;
|
|
14
|
+
},
|
|
15
|
+
default: function() {
|
|
16
|
+
return _default;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _listendelegation = require("./_listen-delegation");
|
|
20
|
+
const _off = require("./off");
|
|
21
|
+
function unlisten(types, // | `${TTypes},${TTypes}`
|
|
22
|
+
// | `${TTypes},${TTypes},${TTypes}`
|
|
23
|
+
// | `${TTypes},${TTypes},${TTypes},${TTypes}`
|
|
24
|
+
// | `${TTypes},${TTypes},${TTypes},${TTypes},${TTypes}`,
|
|
25
|
+
selector, callback) {
|
|
16
26
|
// Loop through each event type
|
|
17
|
-
types.split(",").forEach(function
|
|
27
|
+
types.split(",").forEach(function(type) {
|
|
18
28
|
// Remove whitespace
|
|
19
29
|
type = type.trim();
|
|
20
30
|
// if event type doesn't exist, bail
|
|
21
|
-
if (!
|
|
22
|
-
return;
|
|
31
|
+
if (!_listendelegation.activeEvents[type]) return;
|
|
23
32
|
// If it's the last event of it's type, remove entirely
|
|
24
|
-
if (
|
|
25
|
-
delete
|
|
26
|
-
(0,
|
|
33
|
+
if (_listendelegation.activeEvents[type].length < 2 || !selector) {
|
|
34
|
+
delete _listendelegation.activeEvents[type];
|
|
35
|
+
(0, _off.off)(window, type, _listendelegation.eventHandler, true);
|
|
27
36
|
return;
|
|
28
37
|
}
|
|
29
38
|
// Otherwise, remove event
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
39
|
+
// @ts-expect-error FIXME: type...
|
|
40
|
+
const index = (0, _listendelegation.getIndex)(_listendelegation.activeEvents[type], selector, callback);
|
|
41
|
+
if (index < 0) return;
|
|
42
|
+
_listendelegation.activeEvents[type].splice(index, 1);
|
|
34
43
|
});
|
|
35
44
|
}
|
|
36
|
-
|
|
37
|
-
exports.default = unlisten;
|
|
45
|
+
const _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/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;
|