diff options
| author | Eleanor Eng <eleanor_eng@brown.edu> | 2019-05-04 16:44:22 -0400 |
|---|---|---|
| committer | Eleanor Eng <eleanor_eng@brown.edu> | 2019-05-04 16:44:40 -0400 |
| commit | cecd09917f23fc83c87cffc4fddf5fe1f8331bac (patch) | |
| tree | ab7144d36046aaada287c2ce14d2fe7722585dce /src/new_fields/InkField.ts | |
| parent | 0bf0b028b1af8b9481e369c754277af5fb8b3fcd (diff) | |
| parent | 1ccabe155cb4f23c0aa7e37f91cd4a303008b8c7 (diff) | |
merge with master
Diffstat (limited to 'src/new_fields/InkField.ts')
| -rw-r--r-- | src/new_fields/InkField.ts | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/new_fields/InkField.ts b/src/new_fields/InkField.ts new file mode 100644 index 000000000..86a8bd18a --- /dev/null +++ b/src/new_fields/InkField.ts @@ -0,0 +1,44 @@ +import { Deserializable } from "../client/util/SerializationHelper"; +import { serializable, custom, createSimpleSchema, list, object, map } from "serializr"; +import { ObjectField, Copy } from "./ObjectField"; +import { number } from "prop-types"; +import { any } from "bluebird"; +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)) + } +} |
