aboutsummaryrefslogtreecommitdiff
path: root/src/new_fields/InkField.ts
diff options
context:
space:
mode:
authorTyler Schicke <tyler_schicke@brown.edu>2019-05-07 16:29:02 -0400
committerTyler Schicke <tyler_schicke@brown.edu>2019-05-07 16:29:02 -0400
commit14c776b6d30e0bc0d5b3712f28e4b9f1170eae3b (patch)
tree5255d8cce8a72a5b09cc1ad58661e2176295467a /src/new_fields/InkField.ts
parente19fdbba4cf672aee5bfb59b91b6162431d146d3 (diff)
parent26141a697ae52a7edf3cc6845ce2153111f8860e (diff)
Merge branch 'master' of github-tsch-brown:browngraphicslab/Dash-Web into new_search
Diffstat (limited to 'src/new_fields/InkField.ts')
-rw-r--r--src/new_fields/InkField.ts44
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))
+ }
+}