{"version":3,"file":"dismissClick.mjs","names":[],"sources":["../../../../package/common/utils/dismissClick.ts"],"sourcesContent":["// A press outside a Popover closes it on release, and the click that follows still reaches what\n// was under the pointer, so a click on another event can open that one. A click that creates\n// something (Calendar's empty time) asks here first, so a click that only closed a popover does not\n// also open the next one.\n\nconst dismissClicks = new WeakSet<Event>();\nlet armed = false;\nlet listening = false;\n\nfunction onClick(event: Event) {\n  if (armed) dismissClicks.add(event);\n  armed = false;\n}\n\n// A release with no click after it, such as the end of a drag, must not mark a later click.\nfunction onPress() {\n  armed = false;\n}\n\n/** Records that the release just dispatched closed an overlay, which marks the click it raises. */\nexport function markDismiss(): void {\n  armed = true;\n  if (listening) return;\n  listening = true;\n  // Capturing on the window, so the click is marked before any handler below it runs.\n  window.addEventListener('click', onClick, true);\n  window.addEventListener('pointerdown', onPress, true);\n}\n\n/** Whether the click `event` ends a press that closed an overlay. */\nexport function isDismissClick(event: Event): boolean {\n  return dismissClicks.has(event);\n}\n"],"mappings":"aAKA,IAAM,EAAgB,IAAI,QACtB,EAAQ,GACR,EAAY,GAEhB,SAAS,EAAQ,EAAc,CACzB,GAAO,EAAc,IAAI,CAAK,EAClC,EAAQ,EACV,CAGA,SAAS,GAAU,CACjB,EAAQ,EACV,CAGA,SAAgB,GAAoB,CAClC,EAAQ,GACJ,KACJ,EAAY,GAEZ,OAAO,iBAAiB,QAAS,EAAS,EAAI,EAC9C,OAAO,iBAAiB,cAAe,EAAS,EAAI,EACtD,CAGA,SAAgB,EAAe,EAAuB,CACpD,OAAO,EAAc,IAAI,CAAK,CAChC"}