"use strict"; module.exports = function createClickTimer({ timeout }) { let timer; // NOTE: We have separate handling for mouseDown and click events, so that even if the user double-clicks, the response to initial click feels instant. return { mouseDown: function () { // returns: is first click return (timer == null); }, click: function () { // returns: is double click if (timer == null) { timer = setTimeout(() => { timer = null; }, timeout); return false; } else { timer = null; return true; } }, isRunning: function () { return (timer != null); } }; };