aboutsummaryrefslogtreecommitdiff
path: root/src/new_fields/InkField.ts
blob: f95952c2ef384312e51a03d435be0520206ade78 (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
34
35
36
37
import { Deserializable } from "../client/util/SerializationHelper";
import { serializable, custom, createSimpleSchema, list, object, map } from "serializr";
import { ObjectField } from "./ObjectField";

export enum InkTool {
    None,
    Pen,
    Highlighter,
    Eraser
}
export interface StrokeData {
    pathData: Array<{ x: number, y: number }>;
    color: string;
    width: string;
    tool: InkTool;
    page: number;
}

const pointSchema = createSimpleSchema({
    x: true, y: true
});

const strokeDataSchema = createSimpleSchema({
    pathData: list(object(pointSchema)),
    "*": true
});

@Deserializable("ink")
export class InkField extends ObjectField {
    @serializable(map(object(strokeDataSchema)))
    readonly inkData: Map<string, StrokeData>;

    constructor(data?: Map<string, StrokeData>) {
        super();
        this.inkData = data || new Map;
    }
}