{"version":3,"file":"press-aware-auto-update.mjs","names":[],"sources":["../../../src/components/Tour/press-aware-auto-update.ts"],"sourcesContent":["import { autoUpdate, type ReferenceType } from '@floating-ui/react';\n\nexport function pressAwareAutoUpdate(\n  reference: ReferenceType,\n  floating: HTMLElement,\n  update: () => void\n) {\n  const target = reference instanceof Element ? reference : null;\n  let pressed = false;\n  let pending = false;\n  let frame = -1;\n\n  const handlePointerDown = () => {\n    pressed = true;\n  };\n\n  const handlePointerUp = () => {\n    if (!pressed) {\n      return;\n    }\n\n    pressed = false;\n\n    if (pending) {\n      pending = false;\n      frame = requestAnimationFrame(update);\n    }\n  };\n\n  target?.addEventListener('pointerdown', handlePointerDown);\n  window.addEventListener('pointerup', handlePointerUp, true);\n  window.addEventListener('pointercancel', handlePointerUp, true);\n\n  const cleanup = autoUpdate(reference, floating, () => {\n    if (pressed) {\n      pending = true;\n    } else {\n      update();\n    }\n  });\n\n  return () => {\n    cleanup();\n    cancelAnimationFrame(frame);\n    target?.removeEventListener('pointerdown', handlePointerDown);\n    window.removeEventListener('pointerup', handlePointerUp, true);\n    window.removeEventListener('pointercancel', handlePointerUp, true);\n  };\n}\n"],"mappings":";;;AAEA,SAAgB,qBACd,WACA,UACA,QACA;CACA,MAAM,SAAS,qBAAqB,UAAU,YAAY;CAC1D,IAAI,UAAU;CACd,IAAI,UAAU;CACd,IAAI,QAAQ;CAEZ,MAAM,0BAA0B;EAC9B,UAAU;CACZ;CAEA,MAAM,wBAAwB;EAC5B,IAAI,CAAC,SACH;EAGF,UAAU;EAEV,IAAI,SAAS;GACX,UAAU;GACV,QAAQ,sBAAsB,MAAM;EACtC;CACF;CAEA,QAAQ,iBAAiB,eAAe,iBAAiB;CACzD,OAAO,iBAAiB,aAAa,iBAAiB,IAAI;CAC1D,OAAO,iBAAiB,iBAAiB,iBAAiB,IAAI;CAE9D,MAAM,UAAU,WAAW,WAAW,gBAAgB;EACpD,IAAI,SACF,UAAU;OAEV,OAAO;CAEX,CAAC;CAED,aAAa;EACX,QAAQ;EACR,qBAAqB,KAAK;EAC1B,QAAQ,oBAAoB,eAAe,iBAAiB;EAC5D,OAAO,oBAAoB,aAAa,iBAAiB,IAAI;EAC7D,OAAO,oBAAoB,iBAAiB,iBAAiB,IAAI;CACnE;AACF"}