| 4 | import type { Page } from '../page'; |
| 5 | |
| 6 | export class PagePanning { |
| 7 | readonly page: Page; |
| 8 | |
| 9 | currentPos: Vec2 = new Vec2(); |
| 10 | |
| 11 | readonly react = reactive({ |
| 12 | active: false, |
| 13 | }); |
| 14 | |
| 15 | cancelPointerEvents?: () => void; |
| 16 | |
| 17 | constructor(input: { page: Page }) { |
| 18 | this.page = input.page; |
| 19 | } |
| 20 | |
| 21 | start(event: PointerEvent) { |
| 22 | this.currentPos = this.page.pos.eventToClient(event); |
| 23 | |
| 24 | this.cancelPointerEvents = listenPointerEvents(event, { |
| 25 | move: this._update, |
| 26 | up: this._finish, |
| 27 | }); |
| 28 | } |
| 29 | |
| 30 | private _update = (event: PointerEvent) => { |
| 31 | this.react.active = true; |
| 32 | |
| 33 | const clientPos = this.page.pos.eventToClient(event); |
| 34 | |
| 35 | this.page.camera.react.pos = this.page.camera.react.pos.sub( |
| 36 | clientPos.sub(this.currentPos).divScalar(this.page.camera.react.zoom), |
| 37 | ); |
| 38 | |
| 39 | this.currentPos = clientPos; |
| 40 | |
| 41 | this.page.fixDisplay(); |
| 42 | }; |
| 43 | |
| 44 | private _finish = () => { |
| 45 | // setTimeout necessary to prevent middle-click link opening |
| 46 | |
| 47 | setTimeout(() => { |
| 48 | this.react.active = false; |
| 49 | }); |
| 50 | }; |
| 51 | |
| 52 | cancel = () => { |
| 53 | this.cancelPointerEvents?.(); |
| 54 | |
| 55 | this._finish(); |
| 56 | }; |
| 57 | } |
nothing calls this directly
no test coverage detected