aboutsummaryrefslogtreecommitdiff
path: root/src/new_fields/InkField.ts
blob: 4e3b7abe0d23d2b467e2eec2185dea57caac0838 (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
38
39
40
41
42
43
44
45
46
47
48
import { Deserializable } from "../client/util/SerializationHelper";
import { serializable, custom, createSimpleSchema, list, object, map } from "serializr";
import { ObjectField } from "./ObjectField";
import { Copy, ToScriptString } from "./FieldSymbols";
import { deepCopy } from "../Utils";

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

    [Copy]() {
        return new InkField(deepCopy(this.inkData));
    }

    [ToScriptString]() {
        return "invalid";
    }
}