/** * Fire `fn` after `count` taps/clicks land on `node` within `windowMs` of * each other — a quiet way to hide a shortcut behind a bit of fidgeting. * Returns an unbind. */ export function onTapCode(node, fn, { count = 7, windowMs = 1500 } = {}) { let n = 0; let timer = null; const onClick = () => { n += 1; clearTimeout(timer); timer = setTimeout(() => (n = 0), windowMs); if (n >= count) { n = 0; fn(); } }; node.addEventListener('click', onClick); return () => { clearTimeout(timer); node.removeEventListener('click', onClick); }; }