@mkmonkeycat/dom-utils 0.1.0
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/.eslintignore +2 -0
- package/.github/workflows/release.yml +39 -0
- package/.prettierignore +1 -0
- package/.prettierrc.yml +9 -0
- package/dist/dom/element.d.ts +104 -0
- package/dist/dom/events.d.ts +88 -0
- package/dist/dom/index.d.ts +5 -0
- package/dist/dom/observer.d.ts +66 -0
- package/dist/dom/style.d.ts +14 -0
- package/dist/dom/tag-internal.d.ts +13 -0
- package/dist/dom/win.d.ts +5 -0
- package/dist/index.d.ts +2 -0
- package/dist/main.d.ts +1 -0
- package/dist/mkdomutils.cjs.js +1 -0
- package/dist/mkdomutils.iife.js +1 -0
- package/dist/mkdomutils.js +283 -0
- package/dist/mkdomutils.umd.js +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/string.d.ts +12 -0
- package/dist/utils/tag.d.ts +20 -0
- package/dist/utils/timing.d.ts +58 -0
- package/dist/utils/types.d.ts +12 -0
- package/eslint.config.mjs +33 -0
- package/index.html +13 -0
- package/package.json +55 -0
- package/src/dom/element.ts +252 -0
- package/src/dom/events.ts +245 -0
- package/src/dom/index.ts +5 -0
- package/src/dom/observer.ts +197 -0
- package/src/dom/style.ts +23 -0
- package/src/dom/tag-internal.ts +19 -0
- package/src/dom/win.ts +21 -0
- package/src/index.ts +4 -0
- package/src/main.ts +0 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/string.ts +17 -0
- package/src/utils/tag.ts +31 -0
- package/src/utils/timing.ts +179 -0
- package/src/utils/types.ts +14 -0
- package/tsconfig.json +26 -0
- package/vite.config.ts +21 -0
- package/vitest.config.ts +12 -0
package/.eslintignore
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches:
|
|
5
|
+
- main
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
release:
|
|
12
|
+
name: Release
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
permissions:
|
|
15
|
+
contents: write
|
|
16
|
+
issues: write
|
|
17
|
+
pull-requests: write
|
|
18
|
+
id-token: write
|
|
19
|
+
steps:
|
|
20
|
+
- name: Checkout
|
|
21
|
+
uses: actions/checkout@v6
|
|
22
|
+
with:
|
|
23
|
+
fetch-depth: 0
|
|
24
|
+
|
|
25
|
+
- name: Setup Node.js
|
|
26
|
+
uses: actions/setup-node@v6
|
|
27
|
+
with:
|
|
28
|
+
node-version: lts/*
|
|
29
|
+
|
|
30
|
+
- name: Install dependencies
|
|
31
|
+
run: npm clean-install
|
|
32
|
+
|
|
33
|
+
- name: Verify the integrity of provenance attestations and registry signatures for installed dependencies
|
|
34
|
+
run: npm audit signatures
|
|
35
|
+
|
|
36
|
+
- name: Release
|
|
37
|
+
env:
|
|
38
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
39
|
+
run: npx semantic-release
|
package/.prettierignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
node_modules/
|
package/.prettierrc.yml
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses class names from various input formats into a flat array of class names.
|
|
3
|
+
* @param classNames - Class names as strings, arrays of strings, or undefined.
|
|
4
|
+
* @returns An array of individual class names.
|
|
5
|
+
*/
|
|
6
|
+
export declare const parseClass: (...classNames: (string | string[] | undefined)[]) => string[];
|
|
7
|
+
/**
|
|
8
|
+
* Creates an HTML element with specified attributes and children.
|
|
9
|
+
* @param tag - The tag name of the HTML element to create.
|
|
10
|
+
* @param attributes - An object containing attributes, styles, event handlers, and dataset entries to set on the element.
|
|
11
|
+
* @param children - Child nodes or strings to append to the created element.
|
|
12
|
+
* @returns The created HTML element.
|
|
13
|
+
*/
|
|
14
|
+
export declare const createElement: <K extends keyof HTMLElementTagNameMap>(tag: K, attributes?: ElementAttributes<HTMLElementTagNameMap[K]>, ...children: (Node | string)[]) => HTMLElementTagNameMap[K];
|
|
15
|
+
/**
|
|
16
|
+
* Creates a DocumentFragment for batch DOM operations.
|
|
17
|
+
* @param children - Child nodes or strings to add to the fragment.
|
|
18
|
+
* @returns A DocumentFragment containing the children.
|
|
19
|
+
*/
|
|
20
|
+
export declare const createFragment: (...children: (Node | string)[]) => DocumentFragment;
|
|
21
|
+
export type CSSProperties = Partial<CSSStyleDeclaration> | string;
|
|
22
|
+
export type EventHandlers = {
|
|
23
|
+
[K in keyof HTMLElementEventMap as `on${Capitalize<K>}`]?: (event: HTMLElementEventMap[K]) => void;
|
|
24
|
+
};
|
|
25
|
+
export type ElementAttributes<T extends HTMLElement = HTMLElement> = {
|
|
26
|
+
className?: string | string[];
|
|
27
|
+
class?: string | string[];
|
|
28
|
+
style?: CSSProperties;
|
|
29
|
+
dataset?: Record<string, string>;
|
|
30
|
+
} & EventHandlers & Partial<Omit<T, 'style' | 'children' | 'className' | 'classList' | 'dataset'>> & {
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Gets the width and height of an element (including padding and border).
|
|
35
|
+
* @param element - The element to measure.
|
|
36
|
+
* @returns An object with width and height properties.
|
|
37
|
+
*/
|
|
38
|
+
export declare const getSize: (element: HTMLElement) => {
|
|
39
|
+
width: number;
|
|
40
|
+
height: number;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Gets the offset position of an element relative to the document.
|
|
44
|
+
* @param element - The element to measure.
|
|
45
|
+
* @returns An object with top and left properties.
|
|
46
|
+
*/
|
|
47
|
+
export declare const getOffset: (element: HTMLElement) => {
|
|
48
|
+
top: number;
|
|
49
|
+
left: number;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Gets a computed style value for an element.
|
|
53
|
+
* @param element - The element to query.
|
|
54
|
+
* @param property - The CSS property name.
|
|
55
|
+
* @returns The computed style value.
|
|
56
|
+
*/
|
|
57
|
+
export declare const getComputedStyle: (element: HTMLElement, property: string) => string;
|
|
58
|
+
/**
|
|
59
|
+
* Scrolls the element to a specific position (or to view if no position specified).
|
|
60
|
+
* @param element - The element to scroll.
|
|
61
|
+
* @param options - Scroll behavior options.
|
|
62
|
+
*/
|
|
63
|
+
export declare const scrollTo: (element: HTMLElement, options?: ScrollToOptions | {
|
|
64
|
+
top?: number;
|
|
65
|
+
left?: number;
|
|
66
|
+
}) => void;
|
|
67
|
+
/**
|
|
68
|
+
* Scrolls the element into the viewport.
|
|
69
|
+
* @param element - The element to scroll into view.
|
|
70
|
+
* @param options - Scroll behavior options.
|
|
71
|
+
*/
|
|
72
|
+
export declare const scrollIntoView: (element: HTMLElement, options?: ScrollIntoViewOptions | boolean) => void;
|
|
73
|
+
/**
|
|
74
|
+
* Gets the inner size of an element (client width/height: includes padding, excludes border and scrollbar).
|
|
75
|
+
* @param element - The element to measure.
|
|
76
|
+
* @returns An object with width and height properties.
|
|
77
|
+
*/
|
|
78
|
+
export declare const getInnerSize: (element: HTMLElement) => {
|
|
79
|
+
width: number;
|
|
80
|
+
height: number;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Gets the outer size of an element (offset size). Optionally includes margins.
|
|
84
|
+
* @param element - The element to measure.
|
|
85
|
+
* @param includeMargin - Whether to include margins in the calculation.
|
|
86
|
+
* @returns An object with width and height properties.
|
|
87
|
+
*/
|
|
88
|
+
export declare const getOuterSize: (element: HTMLElement, includeMargin?: boolean) => {
|
|
89
|
+
width: number;
|
|
90
|
+
height: number;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Gets the bounding client rect of an element.
|
|
94
|
+
* @param element - The element to measure.
|
|
95
|
+
* @returns The DOMRect representing the element's bounding box.
|
|
96
|
+
*/
|
|
97
|
+
export declare const getRect: (element: HTMLElement) => DOMRect;
|
|
98
|
+
/**
|
|
99
|
+
* Creates an SVG element from an SVG string.
|
|
100
|
+
* @param svgString - The SVG markup as a string.
|
|
101
|
+
* @returns The parsed SVGElement.
|
|
102
|
+
* @throws Error if the SVG string is invalid or contains multiple root elements.
|
|
103
|
+
*/
|
|
104
|
+
export declare const createSVGFromString: (svgString: string) => SVGElement;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { SingleOrArray } from '../utils/types';
|
|
2
|
+
/**
|
|
3
|
+
* Options for onClickOutside function.
|
|
4
|
+
*/
|
|
5
|
+
export interface OnClickOutsideOptions {
|
|
6
|
+
/** Event type to listen for. Default: 'mousedown' */
|
|
7
|
+
event?: 'mousedown' | 'mouseup' | 'click';
|
|
8
|
+
/** Whether to capture the event. Default: true */
|
|
9
|
+
capture?: boolean;
|
|
10
|
+
/** Elements to exclude from the outside check */
|
|
11
|
+
exclude?: (HTMLElement | null)[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Attaches a listener that triggers when clicking outside the specified element.
|
|
15
|
+
* @param element - The element to watch.
|
|
16
|
+
* @param callback - The callback to invoke when clicking outside.
|
|
17
|
+
* @param options - Configuration options.
|
|
18
|
+
* @returns A function to remove the listener.
|
|
19
|
+
*/
|
|
20
|
+
export declare const onClickOutside: (element: HTMLElement, callback: (event: MouseEvent) => void, options?: OnClickOutsideOptions) => (() => void);
|
|
21
|
+
/**
|
|
22
|
+
* Options for onKeyPress function.
|
|
23
|
+
*/
|
|
24
|
+
export interface OnKeyPressOptions {
|
|
25
|
+
/** Whether to prevent default behavior. Default: false */
|
|
26
|
+
preventDefault?: boolean;
|
|
27
|
+
/** Whether to stop propagation. Default: false */
|
|
28
|
+
stopPropagation?: boolean;
|
|
29
|
+
/** Event type. Default: 'keydown' */
|
|
30
|
+
event?: 'keydown' | 'keyup' | 'keypress';
|
|
31
|
+
/** Target element. Default: document */
|
|
32
|
+
target?: HTMLElement | Document;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Attaches a listener for specific key presses.
|
|
36
|
+
* @param key - The key or keys to listen for (e.g., 'Escape', 'Enter', ['a', 'b']).
|
|
37
|
+
* @param callback - The callback to invoke when the key is pressed.
|
|
38
|
+
* @param options - Configuration options.
|
|
39
|
+
* @returns A function to remove the listener.
|
|
40
|
+
*/
|
|
41
|
+
export declare const onKeyPress: (key: string | string[], callback: (event: KeyboardEvent) => void, options?: OnKeyPressOptions) => (() => void);
|
|
42
|
+
/**
|
|
43
|
+
* Options for onEscape function.
|
|
44
|
+
*/
|
|
45
|
+
export interface OnEscapeOptions extends Omit<OnKeyPressOptions, 'event'> {
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Attaches a listener for the Escape key.
|
|
49
|
+
* @param callback - The callback to invoke when Escape is pressed.
|
|
50
|
+
* @param options - Configuration options.
|
|
51
|
+
* @returns A function to remove the listener.
|
|
52
|
+
*/
|
|
53
|
+
export declare const onEscape: (callback: (event: KeyboardEvent) => void, options?: OnEscapeOptions) => (() => void);
|
|
54
|
+
/**
|
|
55
|
+
* Options for onEnter function.
|
|
56
|
+
*/
|
|
57
|
+
export interface OnEnterOptions extends Omit<OnKeyPressOptions, 'event'> {
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Attaches a listener for the Enter key.
|
|
61
|
+
* @param callback - The callback to invoke when Enter is pressed.
|
|
62
|
+
* @param options - Configuration options.
|
|
63
|
+
* @returns A function to remove the listener.
|
|
64
|
+
*/
|
|
65
|
+
export declare const onEnter: (callback: (event: KeyboardEvent) => void, options?: OnEnterOptions) => (() => void);
|
|
66
|
+
/**
|
|
67
|
+
* Options for onLongPress function.
|
|
68
|
+
*/
|
|
69
|
+
export interface OnLongPressOptions {
|
|
70
|
+
/** Duration in milliseconds to trigger long press. Default: 500 */
|
|
71
|
+
duration?: number;
|
|
72
|
+
/** Threshold in pixels for movement tolerance. Default: 10 */
|
|
73
|
+
threshold?: number;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Attaches a listener for long press events.
|
|
77
|
+
* @param element - The element to watch.
|
|
78
|
+
* @param callback - The callback to invoke on long press.
|
|
79
|
+
* @param options - Configuration options.
|
|
80
|
+
* @returns A function to remove the listeners.
|
|
81
|
+
*/
|
|
82
|
+
export declare const onLongPress: (element: HTMLElement, callback: (event: MouseEvent | TouchEvent) => void, options?: OnLongPressOptions) => (() => void);
|
|
83
|
+
/**
|
|
84
|
+
* Attaches multiple event listeners to an element.
|
|
85
|
+
* @param element - The element to attach listeners to.
|
|
86
|
+
* @param events - An object mapping event types to handlers.
|
|
87
|
+
*/
|
|
88
|
+
export declare const addEventsListener: <E extends HTMLElement>(element: E, events: Partial<{ [K in Parameters<E["addEventListener"]>[0]]: SingleOrArray<Parameters<E["addEventListener"]>[1]>; }>, options?: AddEventListenerOptions) => (() => void);
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for waitForElement function.
|
|
3
|
+
*/
|
|
4
|
+
export interface WaitForElementOptions {
|
|
5
|
+
/** Maximum time to wait in milliseconds. Default: 5000 */
|
|
6
|
+
timeout?: number;
|
|
7
|
+
/** Root element to observe. Default: document.body */
|
|
8
|
+
root?: HTMLElement;
|
|
9
|
+
/** Check interval in milliseconds. Default: 100 */
|
|
10
|
+
interval?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Waits for an element matching the selector to appear in the DOM.
|
|
14
|
+
* @param selector - CSS selector to match.
|
|
15
|
+
* @param options - Configuration options.
|
|
16
|
+
* @returns A promise that resolves with the element when found.
|
|
17
|
+
*/
|
|
18
|
+
export declare const waitForElement: <T extends HTMLElement = HTMLElement>(selector: string, options?: WaitForElementOptions) => Promise<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Options for watchElementRemoval function.
|
|
21
|
+
*/
|
|
22
|
+
export interface WatchElementRemovalOptions {
|
|
23
|
+
/** Callback to invoke when the element is removed */
|
|
24
|
+
onRemove?: () => void;
|
|
25
|
+
/** Root element to observe. Default: document.body */
|
|
26
|
+
root?: HTMLElement;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Watches for an element to be removed from the DOM.
|
|
30
|
+
* @param element - The element to watch.
|
|
31
|
+
* @param options - Configuration options.
|
|
32
|
+
* @returns A function to stop watching.
|
|
33
|
+
*/
|
|
34
|
+
export declare const watchElementRemoval: (element: HTMLElement, options?: WatchElementRemovalOptions) => (() => void);
|
|
35
|
+
/**
|
|
36
|
+
* Returns a promise that resolves when the element is removed from the DOM.
|
|
37
|
+
* @param element - The element to watch.
|
|
38
|
+
* @param options - Configuration options.
|
|
39
|
+
* @returns A promise that resolves when the element is removed.
|
|
40
|
+
*/
|
|
41
|
+
export declare const waitForElementRemoval: (element: HTMLElement, options?: {
|
|
42
|
+
root?: HTMLElement;
|
|
43
|
+
timeout?: number;
|
|
44
|
+
}) => Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Options for watchElementChanges function.
|
|
47
|
+
*/
|
|
48
|
+
export interface WatchElementChangesOptions {
|
|
49
|
+
/** Watch for attribute changes. Default: true */
|
|
50
|
+
attributes?: boolean;
|
|
51
|
+
/** Watch for child node changes. Default: true */
|
|
52
|
+
childList?: boolean;
|
|
53
|
+
/** Watch for text content changes. Default: false */
|
|
54
|
+
characterData?: boolean;
|
|
55
|
+
/** Watch subtree. Default: false */
|
|
56
|
+
subtree?: boolean;
|
|
57
|
+
/** Callback for mutations */
|
|
58
|
+
onMutation?: (mutations: MutationRecord[]) => void;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Watches for changes to an element and its descendants.
|
|
62
|
+
* @param element - The element to watch.
|
|
63
|
+
* @param options - Configuration options.
|
|
64
|
+
* @returns A function to stop watching.
|
|
65
|
+
*/
|
|
66
|
+
export declare const watchElementChanges: (element: HTMLElement, options?: WatchElementChangesOptions) => (() => void);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Injects a <style> tag with the provided CSS into the document.
|
|
3
|
+
* @param css - The CSS text to inject.
|
|
4
|
+
* @param options - Optional configuration such as `id`, `nonce`, and target container.
|
|
5
|
+
* @returns An object containing the created style element and a `remove` function.
|
|
6
|
+
*/
|
|
7
|
+
export declare const injectStyle: (css: string, options?: {
|
|
8
|
+
id?: string;
|
|
9
|
+
nonce?: string;
|
|
10
|
+
target?: HTMLElement;
|
|
11
|
+
}) => {
|
|
12
|
+
style: HTMLStyleElement;
|
|
13
|
+
remove: () => void;
|
|
14
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TaggedFunction } from '../utils/tag';
|
|
2
|
+
/**
|
|
3
|
+
* Marks a function as an mk utils internal event handler.
|
|
4
|
+
* @param func - The function to mark.
|
|
5
|
+
* @returns The marked function.
|
|
6
|
+
*/
|
|
7
|
+
export declare const markAsEventFunc: <F extends CallableFunction>(func: F) => TaggedFunction<F, "__mkEvent">;
|
|
8
|
+
/**
|
|
9
|
+
* Checks if a function is marked as an mk utils internal event handler.
|
|
10
|
+
* @param func - The function to check.
|
|
11
|
+
* @returns True if the function is marked as an event handler, false otherwise.
|
|
12
|
+
*/
|
|
13
|
+
export declare const isEventFunc: <F extends CallableFunction>(func: F) => func is TaggedFunction<F, "__mkEvent">;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const globalWin: Win;
|
|
2
|
+
export declare const globalDoc: Document;
|
|
3
|
+
export declare function getWin(): Win;
|
|
4
|
+
export declare function getWin(target: Node | Event | ShadowRoot | Document | Window | null | undefined): Win | null;
|
|
5
|
+
export type Win = Window & typeof globalThis;
|
package/dist/index.d.ts
ADDED
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=(...e)=>e.flatMap(r=>typeof r=="string"?r.trim().split(/\s+/).filter(Boolean):r||[]),L=(e,r,...n)=>{const o=document.createElement(e);return r?(Object.entries(r).forEach(([s,t])=>{if(t!=null){if(s==="className"||s==="class"){const i=Array.isArray(t)?h(...t):h(t);o.className=i.join(" ");return}if(s==="style"){typeof t=="string"?o.style.cssText=t:typeof t=="object"&&Object.assign(o.style,t);return}if(s==="dataset"&&typeof t=="object"){Object.assign(o.dataset,t);return}if(s.startsWith("on")){const i=s.slice(2).toLowerCase();typeof t=="function"?o.addEventListener(i,t):Array.isArray(t)&&t.forEach(c=>{typeof c=="function"&&o.addEventListener(i,c)});return}s in o?o[s]=t:o.setAttribute(s,String(t))}}),b(o,n),o):(b(o,n),o)},A=(...e)=>{const r=document.createDocumentFragment();return e.forEach(n=>{typeof n=="string"?r.appendChild(document.createTextNode(n)):r.appendChild(n)}),r},b=(e,r)=>{r.forEach(n=>{typeof n=="string"?e.appendChild(document.createTextNode(n)):e.appendChild(n)})},F=e=>({width:e.offsetWidth,height:e.offsetHeight}),O=e=>({top:e.offsetTop,left:e.offsetLeft}),P=(e,r)=>window.getComputedStyle(e).getPropertyValue(r).trim(),I=(e,r)=>{e&&(e===document.documentElement||e===document.body?window.scrollTo(r):e.scrollTo?.(r))},M=(e,r)=>{e.scrollIntoView?.(r)},D=e=>({width:e.clientWidth,height:e.clientHeight}),j=(e,r=!1)=>{let n=e.offsetWidth,o=e.offsetHeight;if(r){const s=window.getComputedStyle(e),t=parseFloat(s.marginLeft||"0"),i=parseFloat(s.marginRight||"0"),c=parseFloat(s.marginTop||"0"),a=parseFloat(s.marginBottom||"0");n+=t+i,o+=c+a}return{width:n,height:o}},R=e=>e.getBoundingClientRect(),V=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml");if(n.documentElement.nodeName==="parsererror")throw new Error("Invalid SVG string: Failed to parse SVG");return n.documentElement},y=(e,r)=>(Object.defineProperty(e,r,{value:!0}),e),W=(e,r)=>!!e[r],p=e=>y(e,"__mkEvent"),x=(e,r,n={})=>{const{event:o="mousedown",capture:s=!0,exclude:t=[]}=n,i=p(c=>{const a=c.target;e.contains(a)||t.some(l=>l?.contains(a))||r(c)});return document.addEventListener(o,i,s),()=>document.removeEventListener(o,i,s)},g=(e,r,n={})=>{const{preventDefault:o=!1,stopPropagation:s=!1,event:t="keydown",target:i=document}=n,c=Array.isArray(e)?e:[e],a=p(l=>{c.includes(l.key)&&(o&&l.preventDefault(),s&&l.stopPropagation(),r(l))});return i.addEventListener(t,a),()=>i.removeEventListener(t,a)},z=(e,r={})=>g("Escape",e,r),$=(e,r={})=>g("Enter",e,r),K=(e,r,n={})=>{const{duration:o=500,threshold:s=10}=n;let t=null,i=0,c=0;const a=d=>"touches"in d?d.touches[0]:d,l=p(d=>{const f=a(d);i=f.clientX,c=f.clientY,t=setTimeout(()=>{r(d)},o)}),w=p(d=>{if(!t)return;const f=a(d),S=Math.abs(f.clientX-i),C=Math.abs(f.clientY-c);(S>s||C>s)&&u()}),u=p(()=>{t&&(clearTimeout(t),t=null)}),m=v(e,{mousedown:l,mousemove:w,mouseup:u,mouseleave:u,touchstart:l,touchmove:w,touchend:u,touchcancel:u});return()=>{m(),t&&clearTimeout(t)}},v=(e,r,n)=>{const o=[];return Object.entries(r).forEach(([s,t])=>{if(!t)return;const i=s;Array.isArray(t)?t.forEach(c=>{e.addEventListener(i,c,n),o.push([i,c])}):(e.addEventListener(i,t,n),o.push([i,t]))}),()=>{o.forEach(([s,t])=>{e.removeEventListener(s,t,n)})}},N=(e,r={})=>{const{timeout:n=5e3,root:o=document.body,interval:s=100}=r;return new Promise((t,i)=>{const c=o.querySelector(e);if(c){t(c);return}const a=new MutationObserver(()=>{const m=o.querySelector(e);m&&(u(),t(m))});a.observe(o,{childList:!0,subtree:!0});const l=setInterval(()=>{const m=o.querySelector(e);m&&(u(),t(m))},s),w=setTimeout(()=>{u(),i(new Error(`Timeout: Element "${e}" not found within ${n}ms`))},n),u=()=>{a.disconnect(),clearTimeout(w),clearInterval(l)}})},G=(e,r={})=>{const{onRemove:n,root:o=document.body}=r,s=new MutationObserver(()=>{o.contains(e)||(n?.(),s.disconnect())});return s.observe(o,{childList:!0,subtree:!0}),()=>s.disconnect()},X=(e,r={})=>{const{root:n=document.body,timeout:o}=r;return new Promise((s,t)=>{if(!n.contains(e)){s();return}let i;const c=new MutationObserver(()=>{n.contains(e)||(a(),s())});c.observe(n,{childList:!0,subtree:!0}),o&&(i=setTimeout(()=>{a(),t(new Error(`Timeout: Element not removed within ${o}ms`))},o));const a=()=>{c.disconnect(),i&&clearTimeout(i)}})},Y=(e,r={})=>{const{attributes:n=!0,childList:o=!0,characterData:s=!1,subtree:t=!1,onMutation:i}=r,c=new MutationObserver(a=>i?.(a));return c.observe(e,{attributes:n,childList:o,characterData:s,subtree:t}),()=>c.disconnect()},Z=(e,r={})=>{const{id:n,nonce:o,target:s=document.head}=r,t=document.createElement("style");return n&&(t.id=n),o&&t.setAttribute("nonce",o),t.textContent=e,s.appendChild(t),{style:t,remove:()=>{t.parentNode?.removeChild(t)}}},E=typeof unsafeWindow<"u"?unsafeWindow:window,q=E.document;function B(e){return e?e instanceof Window?e:e instanceof UIEvent&&e.view?e.view:e instanceof Document?e.defaultView:e instanceof ShadowRoot?e.host.ownerDocument?.defaultView??null:e instanceof Node?e.ownerDocument?.defaultView??null:null:E}const H=e=>e.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g,"$1-$2").toLowerCase(),_=e=>e.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g,"$1-$2").toLowerCase(),U=(e,r)=>{let n=null,o=null;const s=(...t)=>{o=t,n&&clearTimeout(n),n=setTimeout(()=>{e(...o),n=null,o=null},r)};return s.cancel=()=>{n&&clearTimeout(n),n=null,o=null},s.flush=()=>{n&&(e(...o),clearTimeout(n),n=null,o=null)},s},J=(e,r)=>{let n=null,o=null,s=0;const t=()=>{n&&(clearTimeout(n),n=null)},i=(...c)=>{const a=Date.now();if(o=c,s===0)e(...c),s=a;else{const l=a-s;l>=r?(e(...c),s=a,t()):(t(),n=setTimeout(()=>{e(...o),s=Date.now(),n=null},r-l))}};return i.cancel=()=>{t(),s=0,o=null},i.flush=()=>{s>0&&o!==null&&e(...o),t(),s=0,o=null},i},T=e=>new Promise(r=>setTimeout(r,e)),Q=e=>T(e),k=(e,r,n=`Operation timed out after ${r}ms`)=>Promise.race([e,new Promise((o,s)=>setTimeout(()=>s(new Error(n)),r))]),ee=()=>{},te=async(e,r={})=>{const{maxAttempts:n=3,delay:o=1e3,exponential:s=!1}=r;let t;for(let i=1;i<=n;i++)try{return await e()}catch(c){if(t=c instanceof Error?c:new Error(String(c)),i<n){const a=s?o*Math.pow(2,i-1):o;await new Promise(l=>setTimeout(l,a))}}throw t||new Error("Retry failed")};exports.addEventsListener=v;exports.camelToKebab=H;exports.createElement=L;exports.createFragment=A;exports.createSVGFromString=V;exports.debounce=U;exports.delay=T;exports.getComputedStyle=P;exports.getInnerSize=D;exports.getOffset=O;exports.getOuterSize=j;exports.getRect=R;exports.getSize=F;exports.getWin=B;exports.globalDoc=q;exports.globalWin=E;exports.injectStyle=Z;exports.isMarkedAs=W;exports.markFunc=y;exports.noop=ee;exports.onClickOutside=x;exports.onEnter=$;exports.onEscape=z;exports.onKeyPress=g;exports.onLongPress=K;exports.parseClass=h;exports.pascalToKebab=_;exports.retry=te;exports.scrollIntoView=M;exports.scrollTo=I;exports.sleep=Q;exports.throttle=J;exports.timeout=k;exports.waitForElement=N;exports.waitForElementRemoval=X;exports.watchElementChanges=Y;exports.watchElementRemoval=G;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var MKDomUtils=(function(i){"use strict";const E=(...e)=>e.flatMap(r=>typeof r=="string"?r.trim().split(/\s+/).filter(Boolean):r||[]),C=(e,r,...n)=>{const o=document.createElement(e);return r?(Object.entries(r).forEach(([s,t])=>{if(t!=null){if(s==="className"||s==="class"){const c=Array.isArray(t)?E(...t):E(t);o.className=c.join(" ");return}if(s==="style"){typeof t=="string"?o.style.cssText=t:typeof t=="object"&&Object.assign(o.style,t);return}if(s==="dataset"&&typeof t=="object"){Object.assign(o.dataset,t);return}if(s.startsWith("on")){const c=s.slice(2).toLowerCase();typeof t=="function"?o.addEventListener(c,t):Array.isArray(t)&&t.forEach(a=>{typeof a=="function"&&o.addEventListener(c,a)});return}s in o?o[s]=t:o.setAttribute(s,String(t))}}),v(o,n),o):(v(o,n),o)},L=(...e)=>{const r=document.createDocumentFragment();return e.forEach(n=>{typeof n=="string"?r.appendChild(document.createTextNode(n)):r.appendChild(n)}),r},v=(e,r)=>{r.forEach(n=>{typeof n=="string"?e.appendChild(document.createTextNode(n)):e.appendChild(n)})},A=e=>({width:e.offsetWidth,height:e.offsetHeight}),F=e=>({top:e.offsetTop,left:e.offsetLeft}),O=(e,r)=>window.getComputedStyle(e).getPropertyValue(r).trim(),P=(e,r)=>{e&&(e===document.documentElement||e===document.body?window.scrollTo(r):e.scrollTo?.(r))},I=(e,r)=>{e.scrollIntoView?.(r)},M=e=>({width:e.clientWidth,height:e.clientHeight}),D=(e,r=!1)=>{let n=e.offsetWidth,o=e.offsetHeight;if(r){const s=window.getComputedStyle(e),t=parseFloat(s.marginLeft||"0"),c=parseFloat(s.marginRight||"0"),a=parseFloat(s.marginTop||"0"),l=parseFloat(s.marginBottom||"0");n+=t+c,o+=a+l}return{width:n,height:o}},j=e=>e.getBoundingClientRect(),R=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml");if(n.documentElement.nodeName==="parsererror")throw new Error("Invalid SVG string: Failed to parse SVG");return n.documentElement},p=(e,r)=>(Object.defineProperty(e,r,{value:!0}),e),V=(e,r)=>!!e[r],w=e=>p(e,"__mkEvent"),W=(e,r,n={})=>{const{event:o="mousedown",capture:s=!0,exclude:t=[]}=n,c=w(a=>{const l=a.target;e.contains(l)||t.some(u=>u?.contains(l))||r(a)});return document.addEventListener(o,c,s),()=>document.removeEventListener(o,c,s)},b=(e,r,n={})=>{const{preventDefault:o=!1,stopPropagation:s=!1,event:t="keydown",target:c=document}=n,a=Array.isArray(e)?e:[e],l=w(u=>{a.includes(u.key)&&(o&&u.preventDefault(),s&&u.stopPropagation(),r(u))});return c.addEventListener(t,l),()=>c.removeEventListener(t,l)},z=(e,r={})=>b("Escape",e,r),K=(e,r={})=>b("Enter",e,r),$=(e,r,n={})=>{const{duration:o=500,threshold:s=10}=n;let t=null,c=0,a=0;const l=m=>"touches"in m?m.touches[0]:m,u=w(m=>{const h=l(m);c=h.clientX,a=h.clientY,t=setTimeout(()=>{r(m)},o)}),g=w(m=>{if(!t)return;const h=l(m),te=Math.abs(h.clientX-c),ne=Math.abs(h.clientY-a);(te>s||ne>s)&&d()}),d=w(()=>{t&&(clearTimeout(t),t=null)}),f=T(e,{mousedown:u,mousemove:g,mouseup:d,mouseleave:d,touchstart:u,touchmove:g,touchend:d,touchcancel:d});return()=>{f(),t&&clearTimeout(t)}},T=(e,r,n)=>{const o=[];return Object.entries(r).forEach(([s,t])=>{if(!t)return;const c=s;Array.isArray(t)?t.forEach(a=>{e.addEventListener(c,a,n),o.push([c,a])}):(e.addEventListener(c,t,n),o.push([c,t]))}),()=>{o.forEach(([s,t])=>{e.removeEventListener(s,t,n)})}},N=(e,r={})=>{const{timeout:n=5e3,root:o=document.body,interval:s=100}=r;return new Promise((t,c)=>{const a=o.querySelector(e);if(a){t(a);return}const l=new MutationObserver(()=>{const f=o.querySelector(e);f&&(d(),t(f))});l.observe(o,{childList:!0,subtree:!0});const u=setInterval(()=>{const f=o.querySelector(e);f&&(d(),t(f))},s),g=setTimeout(()=>{d(),c(new Error(`Timeout: Element "${e}" not found within ${n}ms`))},n),d=()=>{l.disconnect(),clearTimeout(g),clearInterval(u)}})},G=(e,r={})=>{const{onRemove:n,root:o=document.body}=r,s=new MutationObserver(()=>{o.contains(e)||(n?.(),s.disconnect())});return s.observe(o,{childList:!0,subtree:!0}),()=>s.disconnect()},X=(e,r={})=>{const{root:n=document.body,timeout:o}=r;return new Promise((s,t)=>{if(!n.contains(e)){s();return}let c;const a=new MutationObserver(()=>{n.contains(e)||(l(),s())});a.observe(n,{childList:!0,subtree:!0}),o&&(c=setTimeout(()=>{l(),t(new Error(`Timeout: Element not removed within ${o}ms`))},o));const l=()=>{a.disconnect(),c&&clearTimeout(c)}})},Y=(e,r={})=>{const{attributes:n=!0,childList:o=!0,characterData:s=!1,subtree:t=!1,onMutation:c}=r,a=new MutationObserver(l=>c?.(l));return a.observe(e,{attributes:n,childList:o,characterData:s,subtree:t}),()=>a.disconnect()},Z=(e,r={})=>{const{id:n,nonce:o,target:s=document.head}=r,t=document.createElement("style");return n&&(t.id=n),o&&t.setAttribute("nonce",o),t.textContent=e,s.appendChild(t),{style:t,remove:()=>{t.parentNode?.removeChild(t)}}},y=typeof unsafeWindow<"u"?unsafeWindow:window,q=y.document;function B(e){return e?e instanceof Window?e:e instanceof UIEvent&&e.view?e.view:e instanceof Document?e.defaultView:e instanceof ShadowRoot?e.host.ownerDocument?.defaultView??null:e instanceof Node?e.ownerDocument?.defaultView??null:null:y}const H=e=>e.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g,"$1-$2").toLowerCase(),_=e=>e.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g,"$1-$2").toLowerCase(),U=(e,r)=>{let n=null,o=null;const s=(...t)=>{o=t,n&&clearTimeout(n),n=setTimeout(()=>{e(...o),n=null,o=null},r)};return s.cancel=()=>{n&&clearTimeout(n),n=null,o=null},s.flush=()=>{n&&(e(...o),clearTimeout(n),n=null,o=null)},s},J=(e,r)=>{let n=null,o=null,s=0;const t=()=>{n&&(clearTimeout(n),n=null)},c=(...a)=>{const l=Date.now();if(o=a,s===0)e(...a),s=l;else{const u=l-s;u>=r?(e(...a),s=l,t()):(t(),n=setTimeout(()=>{e(...o),s=Date.now(),n=null},r-u))}};return c.cancel=()=>{t(),s=0,o=null},c.flush=()=>{s>0&&o!==null&&e(...o),t(),s=0,o=null},c},S=e=>new Promise(r=>setTimeout(r,e)),Q=e=>S(e),k=(e,r,n=`Operation timed out after ${r}ms`)=>Promise.race([e,new Promise((o,s)=>setTimeout(()=>s(new Error(n)),r))]),x=()=>{},ee=async(e,r={})=>{const{maxAttempts:n=3,delay:o=1e3,exponential:s=!1}=r;let t;for(let c=1;c<=n;c++)try{return await e()}catch(a){if(t=a instanceof Error?a:new Error(String(a)),c<n){const l=s?o*Math.pow(2,c-1):o;await new Promise(u=>setTimeout(u,l))}}throw t||new Error("Retry failed")};return i.addEventsListener=T,i.camelToKebab=H,i.createElement=C,i.createFragment=L,i.createSVGFromString=R,i.debounce=U,i.delay=S,i.getComputedStyle=O,i.getInnerSize=M,i.getOffset=F,i.getOuterSize=D,i.getRect=j,i.getSize=A,i.getWin=B,i.globalDoc=q,i.globalWin=y,i.injectStyle=Z,i.isMarkedAs=V,i.markFunc=p,i.noop=x,i.onClickOutside=W,i.onEnter=K,i.onEscape=z,i.onKeyPress=b,i.onLongPress=$,i.parseClass=E,i.pascalToKebab=_,i.retry=ee,i.scrollIntoView=I,i.scrollTo=P,i.sleep=Q,i.throttle=J,i.timeout=k,i.waitForElement=N,i.waitForElementRemoval=X,i.watchElementChanges=Y,i.watchElementRemoval=G,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"}),i})({});
|