MCPcopy Create free account
hub / github.com/anomalyco/opencode / wait

Function wait

packages/app/src/utils/aim.ts:53–90  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

51 }
52
53 const wait = () => {
54 if (!props.enabled()) return 0
55 if (!props.active()) return 0
56
57 const el = props.el()
58 if (!el) return 0
59 if (state.locs.length < 2) return 0
60
61 const rect = el.getBoundingClientRect()
62 const loc = state.locs[state.locs.length - 1]
63 if (!loc) return 0
64
65 const prev = state.locs[0] ?? loc
66 if (prev.x < rect.left || prev.x > rect.right || prev.y < rect.top || prev.y > rect.bottom) return 0
67 if (state.last && loc.x === state.last.x && loc.y === state.last.y) return 0
68
69 if (rect.right - loc.x <= edge) {
70 state.last = loc
71 return delay
72 }
73
74 const upper = { x: rect.right, y: rect.top - tolerance }
75 const lower = { x: rect.right, y: rect.bottom + tolerance }
76 const slope = (a: Point, b: Point) => (b.y - a.y) / (b.x - a.x)
77
78 const decreasing = slope(loc, upper)
79 const increasing = slope(loc, lower)
80 const prevDecreasing = slope(prev, upper)
81 const prevIncreasing = slope(prev, lower)
82
83 if (decreasing < prevDecreasing && increasing > prevIncreasing) {
84 state.last = loc
85 return delay
86 }
87
88 state.last = undefined
89 return 0
90 }
91
92 const activate = (id: string) => {
93 cancel()

Callers 1

requestFunction · 0.70

Calls 3

slopeFunction · 0.85
enabledMethod · 0.80
activeMethod · 0.80

Tested by

no test coverage detected