Line data Source code
1 : import { LGraphCanvas } from '@/lib/litegraph/src/litegraph'
2 :
3 : import { canvasOrReport } from './touchCanvasAccess'
4 :
5 : /** Touch gesture state shared by the canvas pointer guards and the touch listeners. */
6 2355 : export const touchGesture = { count: 0, zooming: false }
7 :
8 2355 : let installed = false
9 :
10 : /**
11 : * Wraps `LGraphCanvas.prototype.processMouseDown` and `processMouseMove` so
12 : * canvas pointer handling yields to touch gestures. Later calls are no-ops.
13 : */
14 2355 : export function installTouchPointerGuards() {
15 2355 : if (installed) return
16 2355 : installed = true
17 :
18 2355 : const processMouseDown = LGraphCanvas.prototype.processMouseDown
19 2355 : LGraphCanvas.prototype.processMouseDown = function (e: PointerEvent) {
20 : const startsFreshTouch = e.pointerType === 'touch' && e.isPrimary
21 1083 : if (startsFreshTouch) {
22 0 : touchGesture.count = 0
23 0 : touchGesture.zooming = false
24 : }
25 :
26 1083 : if (touchGesture.zooming || touchGesture.count) {
27 0 : return
28 : }
29 1083 : canvasOrReport('processMouseDown', e)
30 1083 : this.pointer.isDown = false
31 1083 : return processMouseDown.apply(this, [e])
32 : }
33 :
34 2355 : const processMouseMove = LGraphCanvas.prototype.processMouseMove
35 2355 : LGraphCanvas.prototype.processMouseMove = function (e: PointerEvent) {
36 3993 : if (touchGesture.zooming || touchGesture.count > 1) {
37 0 : return
38 : }
39 3993 : return processMouseMove.apply(this, [e])
40 : }
41 : }
|