first commit

This commit is contained in:
douboer@gmail.com
2026-03-03 13:23:14 +08:00
commit 3b7c1d558a
161 changed files with 28120 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
import type { IDisposable } from "../types";
export const ENTER_KEY = "Enter",
TAB_KEY = "Tab",
ARROW_UP_KEY = "ArrowUp",
ARROW_DOWN_KEY = "ArrowDown";
/**
* Attaches an event listener to the element returning a disposable object
* to remove the event listener
*/
export function addEvent(
el: Element | Document | Window | VisualViewport | EventTarget,
type: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
handler: (e: any) => void,
opt?: boolean | AddEventListenerOptions
): IDisposable {
el.addEventListener(type, handler, opt);
let disposed = false;
return {
dispose() {
if (disposed) return;
el.removeEventListener(type, handler, opt);
disposed = true;
}
};
}