diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-10-05 15:33:46 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-10-05 15:33:46 +0200 |
| commit | 02582cc490fc0d753dd153211cc172eb28fbee5d (patch) | |
| tree | 4add149d5e1ecf28cf20ecb497626fef85cdbd75 /src/web/pinch.js | |
| parent | 2f3199622d9e7a97da4b5c31a2d81b170b7cdaa6 (diff) | |
first sketch of wasm environment
Diffstat (limited to 'src/web/pinch.js')
| -rw-r--r-- | src/web/pinch.js | 82 |
1 files changed, 0 insertions, 82 deletions
diff --git a/src/web/pinch.js b/src/web/pinch.js deleted file mode 100644 index bb06b0d..0000000 --- a/src/web/pinch.js +++ /dev/null @@ -1,82 +0,0 @@ -class Pinch { - constructor(element) { - this.event_cache = []; - this.onpinch = () => {}; - this.onfinish = () => {}; - this.onstart = () => {}; - - element.onpointerdown = (e) => this.pointer_down_handler(e); - element.onpointermove = (e) => this.pointer_move_handler(e); - element.onpointerup = (e) => this.pointer_up_handler(e); - element.onpointercancel = (e) => this.pointer_up_handler(e); - element.onpointerout = (e) => this.pointer_up_handler(e); - element.onpointerleave = (e) => this.pointer_up_handler(e); - } - - pointer_down_handler(event) { - this.event_cache.push(event); - - if (this.event_cache.length === 2) { - const diff = Math.hypot( - this.event_cache[0].clientX - this.event_cache[1].clientX, - this.event_cache[0].clientY - this.event_cache[1].clientY, - ); - - 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, distance: diff }); - } - } - - pointer_move_handler(event) { - const index = this.event_cache.findIndex( - (cached) => cached.pointerId == event.pointerId, - ); - this.event_cache[index] = event; - - if (this.event_cache.length === 2) { - const diff = Math.hypot( - this.event_cache[0].clientX - this.event_cache[1].clientX, - this.event_cache[0].clientY - this.event_cache[1].clientY, - ); - - 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.onpinch({ distance: diff, point }); - } - } - - pointer_up_handler(event) { - let cleanup = false; - const ev = {}; - - if (this.event_cache.length === 2) { - ev['distance'] = Math.hypot( - this.event_cache[0].clientX - this.event_cache[1].clientX, - this.event_cache[0].clientY - this.event_cache[1].clientY, - ); - - ev['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, - }; - - cleanup = true; - } - - const index = this.event_cache.findIndex( - (cached) => cached.pointerId === event.pointerId, - ); - this.event_cache.splice(index, 1); - - if (cleanup) { - this.onfinish(ev); - } - } -} |