core/observers/panel.observer.ts

core/observers/panel.observer.ts is a file in Bane's Lab Site. 25 lines of code and 4 definitions.

import { PANEL_ARMED_CLASS, PANEL_ARM_MS } from "#configuration/constants/panel.constants";

export const observeArming = function observeArming(element: HTMLElement): () => boolean {
    let armed = false;
    let pending: ReturnType<typeof setTimeout> | null = null;
    const cancel = function cancel(): void {
        if (pending !== null) {
            clearTimeout(pending);
            pending = null;
        }
    };
    element.addEventListener("pointerenter", () => {
        cancel();
        pending = setTimeout(() => {
            armed = true;
            pending = null;
            element.classList.add(PANEL_ARMED_CLASS);
        }, PANEL_ARM_MS);
    });
    element.addEventListener("pointerleave", () => {
        cancel();
        armed = false;
        element.classList.remove(PANEL_ARMED_CLASS);
    });
    return () => armed;
};