mirror of
https://github.com/hanzoai/site.git
synced 2026-11-20 21:14:28 +00:00
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
15 lines
1.1 KiB
TypeScript
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 });
|
|
}
|