aboutsummaryrefslogtreecommitdiff
path: root/src/pen-gestures/GestureUtils.ts
blob: c7051c87c30e8c2b5c11e51efc7e36ab24fb9073 (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
import { Rect } from 'react-measure';
import { Gestures, PointData } from './GestureTypes';
import { NDollarRecognizer } from './ndollar';

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);
}