aboutsummaryrefslogtreecommitdiff
path: root/src/pen-gestures/GestureUtils.ts
blob: 41917aac9e52b60e6b951bac8536ba9034118120 (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 { PointData } from '../fields/InkField';
import { NDollarRecognizer } from './ndollar';

export namespace GestureUtils {
    export class GestureEvent {
        constructor(readonly gesture: Gestures, readonly points: PointData[], readonly bounds: Rect, readonly text?: any) {}
    }

    export interface GestureEventDisposer {
        (): void;
    }

    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 enum Gestures {
        Line = 'line',
        Stroke = 'stroke',
        Scribble = 'scribble',
        Text = 'text',
        Triangle = 'triangle',
        Circle = 'circle',
        Rectangle = 'rectangle',
        Arrow = 'arrow',
    }

    export const GestureRecognizer = new NDollarRecognizer(false);
}