hermes-agent/apps/desktop/src/lib/trackpad-gestures.ts
Brooklyn Nicholson dec44994a5 feat(desktop): Memory Graph — playable radial timeline of memories + skills
A top-down Memory Graph panel: memories and skills on a radial time axis
(core = oldest, outer rings = newer) with a playable / scrubbable timeline
that builds the map up over time.

- Reveal lives off the React tree (a ref drives the canvas, a nanostore atom
  drives the timeline + legend), so a play-through or scrub never re-renders
  the panel; paint is coalesced to one rAF and playback is abortable, so even
  frantic scrubbing stays responsive.
- Adaptive dated rings: one equal-width ring per POPULATED calendar bucket,
  a "nice-tick" count scaled to the span. Constant (orthographic) core/band
  scale — more data grows the disk outward (more rings), never thinner.
- A bucket's nodes fill the band inside their ring and ignite staggered by
  real timestamp across it (no end-dump), with an EVE-style warp-in; the
  camera steps out band-by-band as rings are reached.
- ASCII "computing" core, theme-aware palette with a distinct memory hue,
  shared trackpad-gesture primitives.
- Shareable WoW-style "loadout" codes on a generic, reusable codec
  (@/lib/loadout: bitstream + DEFLATE + version/checksum frame + base64url).
- Opens from the statusbar and command palette; i18n across all locales.

Deps: d3-force, fflate (drops unused react-force-graph-2d).
2026-06-30 00:54:21 -05:00

50 lines
1.7 KiB
TypeScript

// Trackpad / pointer gesture primitives shared across canvas + DOM surfaces.
//
// macOS quirk (Chromium/Electron): both pinch-zoom and "smart zoom" arrive as
// `wheel` events with `ctrlKey` synthetically set — there is no dedicated DOM
// event for either. They're disambiguated by their deltas:
// - pinch-to-zoom: ctrlKey + a non-zero delta
// - smart zoom: ctrlKey + zero deltas (the two-finger double-tap)
// Plain two-finger scroll has ctrlKey === false. Centralising this here keeps
// every zoom/pan surface from re-deriving the same OS trivia (and getting it
// wrong, which makes smart-zoom read as a zoom-in).
export interface WheelLike {
ctrlKey: boolean
deltaX: number
deltaY: number
}
/** macOS "smart zoom" (two-finger double-tap): a ctrl-wheel with no delta. */
export function isSmartZoomWheel(e: WheelLike): boolean {
return e.ctrlKey && e.deltaX === 0 && e.deltaY === 0
}
/** Pinch-to-zoom (or ctrl + mouse wheel): a ctrl-wheel carrying a delta. */
export function isPinchZoomWheel(e: WheelLike): boolean {
return e.ctrlKey && (e.deltaX !== 0 || e.deltaY !== 0)
}
export const DOUBLE_TAP_MS = 300
/**
* Stateful double-tap detector for surfaces where a real `dblclick` may never
* fire (e.g. a trackpad with tap-to-click off). Call it once per discrete tap;
* it returns true when two taps land within `thresholdMs` of each other, then
* resets so a third tap starts a fresh pair.
*/
export function createDoubleTapDetector(thresholdMs: number = DOUBLE_TAP_MS): (now?: number) => boolean {
let last = 0
return (now: number = Date.now()): boolean => {
if (now - last < thresholdMs) {
last = 0
return true
}
last = now
return false
}
}