diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-05-28 23:12:46 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-05-28 23:12:46 +0200 |
| commit | ef2f7d38d64b2be9f388be3809ba1d07e2bc2282 (patch) | |
| tree | 3ea1776afa6c436433d4525aacf7aa95825f49af /src/web/pinch.js | |
| parent | cd7883d16956d80c67a91c4e07be5335f4de5c39 (diff) | |
timeline: fix pinch-zoom offset
Diffstat (limited to 'src/web/pinch.js')
| -rw-r--r-- | src/web/pinch.js | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/web/pinch.js b/src/web/pinch.js index 14f843a..935dfa0 100644 --- a/src/web/pinch.js +++ b/src/web/pinch.js @@ -4,6 +4,7 @@ class Pinch { this.previous_diff = null; this.onpinch = () => {}; this.onfinish = () => {}; + this.onstart = () => {}; element.onpointerdown = (e) => this.pointer_down_handler(e); element.onpointermove = (e) => this.pointer_move_handler(e); @@ -15,6 +16,15 @@ class Pinch { pointer_down_handler(event) { this.event_cache.push(event); + + if (this.event_cache.length === 2) { + const point = { + x: (this.event_cache[0].clientX + this.event_cache[1].clientX) / 2, + y: (this.event_cache[0].clientY + this.event_cache[1].clientY) / 2, + }; + + this.onstart({ point }); + } } pointer_move_handler(event) { @@ -38,7 +48,7 @@ class Pinch { }; const delta = this.previous_diff - diff; - this.onpinch(delta, point); + this.onpinch({ zoom_delta: delta, point }); } this.previous_diff = diff; @@ -46,6 +56,11 @@ class Pinch { } pointer_up_handler(event) { + let cleanup = false; + if (this.event_cache.length === 2) { + cleanup = true; + } + const index = this.event_cache.findIndex( (cached) => cached.pointerId === event.pointerId, ); @@ -55,6 +70,8 @@ class Pinch { this.previous_diff = null; } - this.onfinish(); + if (cleanup) { + this.onfinish(); + } } } |