~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/hud

A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts

0
0
35 lines · 1.3 KB Raw History
// A double-tap on a picture, as a photo app takes one to favorite what it
// shows (a story, a gallery): a tap waits a moment to be sure no second
// follows, and the second runs the double-tap at once instead; a heart
// bursts where it was (./Bursts.svelte).

/** How long a tap waits for a second, in milliseconds. */
export const DOUBLE = 250;

/** A click handler telling taps apart: `single` a moment after a tap no second followed, `double` at once on the second. */
export function taps<E>(single: (event: E) => void, double: (event: E) => void): (event: E) => void {
	let waiting: ReturnType<typeof setTimeout> | null = null;
	return (event) => {
		if (waiting === null) {
			waiting = setTimeout(() => ((waiting = null), single(event)), DOUBLE);
			return;
		}
		clearTimeout(waiting);
		waiting = null;
		double(event);
	};
}

/** Hearts bursting where double-taps were, each gone once it has. */
export class Hearts {
	shown: { id: number; x: number; y: number }[] = $state([]);
	#last = 0;

	/** A heart at `event`'s place in `over`, the box the hearts are drawn in. */
	add(event: MouseEvent, over: Element) {
		const box = over.getBoundingClientRect();
		const id = ++this.#last;
		this.shown.push({ id, x: event.clientX - box.left, y: event.clientY - box.top });
		setTimeout(() => (this.shown = this.shown.filter((b) => b.id !== id)), 900);
	}
}