MCPcopy Index your code
hub / github.com/codeaashu/claude-code / animatedMove

Function animatedMove

src/utils/computerUse/executor.ts:217–255  ·  view source on GitHub ↗

* Port of Cowork's `animateMouseMovement` + `animatedMove`. Ease-out-cubic at * 60fps; distance-proportional duration at 2000 px/sec, capped at 0.5s. When * the sub-gate is off (or distance < ~2 frames), falls through to * `moveAndSettle`. Called only from `drag` for the press→to motion — target

(
  input: Input,
  targetX: number,
  targetY: number,
  mouseAnimationEnabled: boolean,
)

Source from the content-addressed store, hash-verified

215 * intermediate positions (scrollbars, window resizes).
216 */
217async function animatedMove(
218 input: Input,
219 targetX: number,
220 targetY: number,
221 mouseAnimationEnabled: boolean,
222): Promise<void> {
223 if (!mouseAnimationEnabled) {
224 await moveAndSettle(input, targetX, targetY)
225 return
226 }
227 const start = await input.mouseLocation()
228 const deltaX = targetX - start.x
229 const deltaY = targetY - start.y
230 const distance = Math.hypot(deltaX, deltaY)
231 if (distance < 1) return
232 const durationSec = Math.min(distance / 2000, 0.5)
233 if (durationSec < 0.03) {
234 await moveAndSettle(input, targetX, targetY)
235 return
236 }
237 const frameRate = 60
238 const frameIntervalMs = 1000 / frameRate
239 const totalFrames = Math.floor(durationSec * frameRate)
240 for (let frame = 1; frame <= totalFrames; frame++) {
241 const t = frame / totalFrames
242 const eased = 1 - Math.pow(1 - t, 3)
243 await input.moveMouse(
244 Math.round(start.x + deltaX * eased),
245 Math.round(start.y + deltaY * eased),
246 false,
247 )
248 if (frame < totalFrames) {
249 await sleep(frameIntervalMs)
250 }
251 }
252 // Last frame has no trailing sleep — same HID round-trip before the
253 // caller's mouseButton reads NSEvent.mouseLocation.
254 await sleep(MOVE_SETTLE_MS)
255}
256
257// ── Factory ───────────────────────────────────────────────────────────────
258

Callers 1

dragFunction · 0.85

Calls 2

moveAndSettleFunction · 0.85
sleepFunction · 0.50

Tested by

no test coverage detected