@koine/dom 1.0.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/$$.d.ts +10 -0
- package/$$.js +12 -0
- package/$.d.ts +13 -0
- package/$.js +15 -0
- package/$each.d.ts +11 -0
- package/$each.js +17 -0
- package/README.md +1 -0
- package/_listen-delegation.d.ts +38 -0
- package/_listen-delegation.js +83 -0
- package/addClass.d.ts +5 -0
- package/addClass.js +15 -0
- package/calculateFixedOffset.d.ts +2 -0
- package/calculateFixedOffset.js +10 -0
- package/createElement.d.ts +9 -0
- package/createElement.js +16 -0
- package/emitEvent.d.ts +5 -0
- package/emitEvent.js +14 -0
- package/escapeSelector.d.ts +8 -0
- package/escapeSelector.js +10 -0
- package/exists.d.ts +7 -0
- package/exists.js +12 -0
- package/forEach.d.ts +9 -0
- package/forEach.js +13 -0
- package/getDataAttr.d.ts +8 -0
- package/getDataAttr.js +13 -0
- package/getDocumentHeight.d.ts +7 -0
- package/getDocumentHeight.js +10 -0
- package/getHeight.d.ts +5 -0
- package/getHeight.js +7 -0
- package/getListeners.d.ts +9 -0
- package/getListeners.js +18 -0
- package/getOffset.d.ts +11 -0
- package/getOffset.js +18 -0
- package/getOffsetTop.d.ts +10 -0
- package/getOffsetTop.js +20 -0
- package/getScrollbarWidth.d.ts +5 -0
- package/getScrollbarWidth.js +7 -0
- package/getStyleValue.d.ts +8 -0
- package/getStyleValue.js +10 -0
- package/index.d.ts +40 -0
- package/index.js +40 -0
- package/injectCss.d.ts +5 -0
- package/injectCss.js +16 -0
- package/isHidden.d.ts +5 -0
- package/isHidden.js +7 -0
- package/isInViewport.d.ts +10 -0
- package/isInViewport.js +18 -0
- package/isNodeList.d.ts +7 -0
- package/isNodeList.js +14 -0
- package/isTotallyScrolled.d.ts +8 -0
- package/isTotallyScrolled.js +10 -0
- package/listen.d.ts +12 -0
- package/listen.js +32 -0
- package/listenLoaded.d.ts +7 -0
- package/listenLoaded.js +11 -0
- package/listenOnce.d.ts +12 -0
- package/listenOnce.js +20 -0
- package/listenResize.d.ts +8 -0
- package/listenResize.js +25 -0
- package/listenScroll.d.ts +8 -0
- package/listenScroll.js +28 -0
- package/node/$$.js +16 -0
- package/node/$.js +19 -0
- package/node/$each.js +22 -0
- package/node/_listen-delegation.js +89 -0
- package/node/addClass.js +19 -0
- package/node/calculateFixedOffset.js +14 -0
- package/node/createElement.js +21 -0
- package/node/emitEvent.js +18 -0
- package/node/escapeSelector.js +14 -0
- package/node/exists.js +16 -0
- package/node/forEach.js +17 -0
- package/node/getDataAttr.js +17 -0
- package/node/getDocumentHeight.js +14 -0
- package/node/getHeight.js +11 -0
- package/node/getListeners.js +22 -0
- package/node/getOffset.js +22 -0
- package/node/getOffsetTop.js +24 -0
- package/node/getScrollbarWidth.js +11 -0
- package/node/getStyleValue.js +14 -0
- package/node/index.js +43 -0
- package/node/injectCss.js +20 -0
- package/node/isHidden.js +11 -0
- package/node/isInViewport.js +22 -0
- package/node/isNodeList.js +18 -0
- package/node/isTotallyScrolled.js +14 -0
- package/node/listen.js +36 -0
- package/node/listenLoaded.js +15 -0
- package/node/listenOnce.js +24 -0
- package/node/listenResize.js +29 -0
- package/node/listenScroll.js +32 -0
- package/node/off.js +19 -0
- package/node/on.js +19 -0
- package/node/onClickOutside.js +21 -0
- package/node/once.js +20 -0
- package/node/removeClass.js +19 -0
- package/node/scrollTo.js +32 -0
- package/node/setDataAttr.js +22 -0
- package/node/setVendorCSS.js +25 -0
- package/node/siblings.js +23 -0
- package/node/toArray.js +13 -0
- package/node/unlisten.js +37 -0
- package/off.d.ts +5 -0
- package/off.js +15 -0
- package/on.d.ts +5 -0
- package/on.js +15 -0
- package/onClickOutside.d.ts +1 -0
- package/onClickOutside.js +17 -0
- package/once.d.ts +6 -0
- package/once.js +15 -0
- package/package.json +16 -0
- package/removeClass.d.ts +5 -0
- package/removeClass.js +15 -0
- package/scrollTo.d.ts +10 -0
- package/scrollTo.js +28 -0
- package/setDataAttr.d.ts +9 -0
- package/setDataAttr.js +18 -0
- package/setVendorCSS.d.ts +9 -0
- package/setVendorCSS.js +21 -0
- package/siblings.d.ts +7 -0
- package/siblings.js +19 -0
- package/toArray.d.ts +7 -0
- package/toArray.js +9 -0
- package/typings.d.ts +0 -0
- package/unlisten.d.ts +12 -0
- package/unlisten.js +33 -0
package/once.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One shot listener, it `addEventListener` and removes it first time is called
|
|
3
|
+
* with `removeEventListener`
|
|
4
|
+
*/
|
|
5
|
+
export declare function once(el: Window | Document | HTMLElement, type: string, handler: EventListener, options?: EventListenerOptions | boolean): void;
|
|
6
|
+
export default once;
|
package/once.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
on(el, type, handlerWrapper, options);
|
|
14
|
+
}
|
|
15
|
+
export default once;
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@koine/dom",
|
|
3
|
+
"sideEffects": false,
|
|
4
|
+
"main": "./node/index.js",
|
|
5
|
+
"typings": "./index.d.ts",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@koine/utils": "1.0.80",
|
|
8
|
+
"ts-debounce": "^4.0.0",
|
|
9
|
+
"date-fns-tz": "^1.3.7",
|
|
10
|
+
"tslib": "^2.4.0"
|
|
11
|
+
},
|
|
12
|
+
"peerDependencies": {},
|
|
13
|
+
"version": "1.0.80",
|
|
14
|
+
"module": "./index.js",
|
|
15
|
+
"types": "./index.d.ts"
|
|
16
|
+
}
|
package/removeClass.d.ts
ADDED
package/removeClass.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
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.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native `scrollTo`, `"smooth"` and with callback
|
|
3
|
+
*
|
|
4
|
+
* @borrows https://stackoverflow.com/a/55686711/1938970
|
|
5
|
+
*
|
|
6
|
+
* @param offset - offset to scroll to
|
|
7
|
+
* @param callback - callback function
|
|
8
|
+
*/
|
|
9
|
+
export declare function scrollTo(offset: number, callback?: () => void): void;
|
|
10
|
+
export default scrollTo;
|
package/scrollTo.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
*/
|
|
11
|
+
export function scrollTo(offset, callback) {
|
|
12
|
+
var fixedOffset = offset.toFixed();
|
|
13
|
+
if (callback) {
|
|
14
|
+
var onScroll_1 = function () {
|
|
15
|
+
if (window.pageYOffset.toFixed() === fixedOffset) {
|
|
16
|
+
off(window, "scroll", onScroll_1);
|
|
17
|
+
callback();
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
on(window, "scroll", onScroll_1);
|
|
21
|
+
onScroll_1();
|
|
22
|
+
}
|
|
23
|
+
window.scrollTo({
|
|
24
|
+
top: offset,
|
|
25
|
+
behavior: "smooth",
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export default scrollTo;
|
package/setDataAttr.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
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 declare function setDataAttr(element: Element, attribute: string, value?: string | number | null | boolean): void;
|
|
9
|
+
export default setDataAttr;
|
package/setDataAttr.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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;
|
|
@@ -0,0 +1,9 @@
|
|
|
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 declare function setVendorCSS(element: HTMLElement, prop: string, value: string | number | boolean): void;
|
|
9
|
+
export default setVendorCSS;
|
package/setVendorCSS.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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.d.ts
ADDED
package/siblings.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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.d.ts
ADDED
package/toArray.js
ADDED
package/typings.d.ts
ADDED
|
File without changes
|
package/unlisten.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type EventCallback } from "./_listen-delegation";
|
|
2
|
+
/**
|
|
3
|
+
* Stop listening for an event
|
|
4
|
+
*
|
|
5
|
+
* @category listen-delegation
|
|
6
|
+
*
|
|
7
|
+
* @param types The event type or types (comma separated)
|
|
8
|
+
* @param selector The selector to remove the event from
|
|
9
|
+
* @param callback The function to remove
|
|
10
|
+
*/
|
|
11
|
+
export declare function unlisten(types: string, selector: string, callback: EventCallback): void;
|
|
12
|
+
export default unlisten;
|
package/unlisten.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
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;
|