aboutsummaryrefslogtreecommitdiff
path: root/src/pen-gestures/GestureUtils.ts
blob: bf54750426fecfa563d2dc95dc2953704c08561a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { Rect } from 'react-measure';
import { Gestures, PointData } from './GestureTypes';
import { NDollarRecognizer } from './ndollar';

// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace GestureUtils {
    export class GestureEvent {
        readonly gesture: Gestures;
        readonly points: PointData[];
        readonly bounds: Rect;
        readonly text?: string;

        constructor(gesture: Gestures, points: PointData[], bounds: Rect, text?: string) {
            this.gesture = gesture;
            this.points = points;
            this.bounds = bounds;
            this.text = text;
        }
    }

    export interface GestureEventDisposer {
        (): void;
    }

    // eslint-disable-next-line no-undef
    export function MakeGestureTarget(element: HTMLElement, func: (e: Event, ge: GestureEvent) => void): GestureEventDisposer {
        const handler = (e: Event) => func(e, (e as CustomEvent<GestureEvent>).detail);
        element.addEventListener('dashOnGesture', handler);
        return () => element.removeEventListener('dashOnGesture', handler);
    }

    export const GestureRecognizer = new NDollarRecognizer(false);
}