Files
zeekayandGitHub e751c17b82 Type lib under strict (#7)
Describe the live catalog, the plan ladder, the open-source read, the
Sigil maths, the tilt and the sound kit with real types. Sound is now off
until the visitor sets localStorage hz-sound to "on".

Claude-Session: https://claude.ai/code/session_015XYKLix9PSyn6Jw2HWKprk
2026-11-14 00:35:05 -08:00

15 lines
1.1 KiB
TypeScript

/* A press on a link to a page of this site is taken over by the page transition (components/Morph.jsx), at the top of the
capture phase, and stopped there: a handler on the link, or on anything below the document, never hears it. A moment that
belongs to such a link is read where the transition reads it, on the document in the capture phase, like the funnel's
own (components/Telemetry.jsx). `on` is a selector or an element; `fire(el, event)` hears each press on a match.
Returns the cleanup, so an effect can hand it back. */
export function press(on: string | Element | null | undefined, fire: (el: Element, event: MouseEvent) => void) {
const click = (e: MouseEvent) => {
const target = e.target as Element | null; // a click's target on the document is an element, or the document itself
const el = typeof on === 'string' ? target?.closest?.(on) : on?.contains(target) ? on : null;
if (el) fire(el, e);
};
document.addEventListener('click', click, { capture: true });
return () => document.removeEventListener('click', click, { capture: true });
}