source: imaps-frontend/node_modules/@use-gesture/core/src/engines/WheelEngine.ts

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.2 KB
Line 
1import { CoordinatesEngine } from './CoordinatesEngine'
2import { wheelValues } from '../utils/events'
3import { V } from '../utils/maths'
4import { clampStateInternalMovementToBounds } from '../utils/state'
5
6export interface WheelEngine extends CoordinatesEngine<'wheel'> {
7 wheel(this: WheelEngine, event: WheelEvent): void
8 wheelChange(this: WheelEngine, event: WheelEvent): void
9 wheelEnd(this: WheelEngine): void
10}
11
12export class WheelEngine extends CoordinatesEngine<'wheel'> {
13 ingKey = 'wheeling' as const
14
15 wheel(event: WheelEvent) {
16 if (!this.state._active) this.start(event)
17 this.wheelChange(event)
18 this.timeoutStore.add('wheelEnd', this.wheelEnd.bind(this))
19 }
20
21 wheelChange(event: WheelEvent) {
22 const state = this.state
23 state._delta = wheelValues(event)
24 V.addTo(state._movement, state._delta)
25
26 // _movement rolls back to when it passed the bounds.
27 clampStateInternalMovementToBounds(state)
28
29 this.compute(event)
30 this.emit()
31 }
32
33 wheelEnd() {
34 if (!this.state._active) return
35 this.state._active = false
36 this.compute()
37 this.emit()
38 }
39
40 bind(bindFunction: any) {
41 bindFunction('wheel', '', this.wheel.bind(this))
42 }
43}
Note: See TracBrowser for help on using the repository browser.