{"version":3,"file":"gesture.mjs","names":[],"sources":["../../../../package/common/calendar/gesture.ts"],"sourcesContent":["// Thresholds the library already settled on elsewhere, so a swipe or a long press feels the same\n// here as in Carousel, Toast and VirtualList.\n\n/** Touch movement before a press is read as a swipe or a scroll (carousel.tsx, useSwipeDismiss.ts). */\nexport const LOCK_DISTANCE = 10;\n/** Mouse movement before a press becomes a drag. */\nexport const MOUSE_DRAG_DISTANCE = 4;\n/** Hold before a touch picks something up (VirtualList's `longPressDelay`). */\nexport const LONG_PRESS_MS = 400;\n/** A touch this soon after a scroll is stopping momentum, not picking something up. */\nexport const RECENT_SCROLL_MS = 150;\n/** Share of the width a swipe must travel to page (carousel.tsx). */\nexport const COMMIT_RATIO = 0.2;\n/** px/ms a shorter flick must reach to page anyway (useSwipeDismiss.ts). */\nexport const COMMIT_VELOCITY = 0.5;\n/** How far back the flick velocity is measured. */\nexport const VELOCITY_WINDOW_MS = 100;\n/** Distance from a scroller's edge where a drag starts scrolling it (useRowDrag.ts). */\nexport const EDGE_ZONE = 48;\n/** px per frame at the very edge. */\nexport const EDGE_SPEED = 18;\n/** How long after a gesture the click it ends in is swallowed (useRowDrag.ts). */\nexport const CLICK_SUPPRESS_MS = 350;\n\n/** `1` to page forwards, `-1` back, `0` to return. A swipe to the left reveals the next period. */\nexport function pageStep(dx: number, width: number, velocity: number): -1 | 0 | 1 {\n  if (dx === 0) return 0;\n  const far = Math.abs(dx) >= width * COMMIT_RATIO;\n  const flicked = Math.abs(velocity) >= COMMIT_VELOCITY && Math.sign(velocity) === Math.sign(dx);\n  if (!far && !flicked) return 0;\n  return dx < 0 ? 1 : -1;\n}\n\n/** Scroll speed for a pointer at `y` in a scroller spanning `top` to `bottom`: negative scrolls up. */\nexport function edgeSpeed(y: number, top: number, bottom: number): number {\n  if (y < top + EDGE_ZONE) return -EDGE_SPEED * Math.min(1, (top + EDGE_ZONE - y) / EDGE_ZONE);\n  if (y > bottom - EDGE_ZONE) return EDGE_SPEED * Math.min(1, (y - (bottom - EDGE_ZONE)) / EDGE_ZONE);\n  return 0;\n}\n\nexport function snap(minutes: number, step: number): number {\n  return Math.round(minutes / step) * step;\n}\n\nexport function clamp(value: number, min: number, max: number): number {\n  return Math.min(Math.max(value, min), max);\n}\n\nexport interface VelocitySample {\n  time: number;\n  x: number;\n}\n\n/** px/ms over the samples of the last `VELOCITY_WINDOW_MS`. */\nexport function velocityOf(samples: readonly VelocitySample[], now: number): number {\n  const recent = samples.filter((sample) => now - sample.time <= VELOCITY_WINDOW_MS);\n  if (recent.length < 2) return 0;\n  const first = recent[0];\n  const last = recent[recent.length - 1];\n  const elapsed = last.time - first.time;\n  return elapsed > 0 ? (last.x - first.x) / elapsed : 0;\n}\n"],"mappings":"aAYA,IAAa,EAAe,GAEf,EAAkB,GAW/B,SAAgB,EAAS,EAAY,EAAe,EAA8B,CAKhF,OAJI,IAAO,GAGP,EAFQ,KAAK,IAAI,CAAE,GAAK,EAAA,KAEhB,EADI,KAAK,IAAI,CAAQ,GAAA,IAAwB,KAAK,KAAK,CAAQ,IAAM,KAAK,KAAK,CAAE,GAChE,EACtB,EAAK,EAAI,EAAI,EACtB,CAGA,SAAgB,EAAU,EAAW,EAAa,EAAwB,CAGxE,OAFI,EAAI,EAAA,GAAwB,IAAc,KAAK,IAAI,GAAI,EAAA,GAAkB,GAAA,EAAc,EACvF,EAAI,EAAA,GAAoB,GAAoB,KAAK,IAAI,GAAI,GAAK,EAAA,KAAA,EAAgC,EAC3F,CACT,CAEA,SAAgB,EAAK,EAAiB,EAAsB,CAC1D,OAAO,KAAK,MAAM,EAAU,CAAI,EAAI,CACtC,CAEA,SAAgB,EAAM,EAAe,EAAa,EAAqB,CACrE,OAAO,KAAK,IAAI,KAAK,IAAI,EAAO,CAAG,EAAG,CAAG,CAC3C,CAQA,SAAgB,EAAW,EAAoC,EAAqB,CAClF,IAAM,EAAS,EAAQ,OAAQ,GAAW,EAAM,EAAO,MAAA,GAA0B,EACjF,GAAI,EAAO,OAAS,EAAG,MAAO,GAC9B,IAAM,EAAQ,EAAO,GACf,EAAO,EAAO,EAAO,OAAS,GAC9B,EAAU,EAAK,KAAO,EAAM,KAClC,OAAO,EAAU,GAAK,EAAK,EAAI,EAAM,GAAK,EAAU,CACtD"}