2020-03-17 20:55:40 +01:00
|
|
|
import { Point } from "../types";
|
2020-05-27 15:14:50 +02:00
|
|
|
import { FONT_FAMILY } from "../constants";
|
2020-03-17 20:55:40 +01:00
|
|
|
|
2020-12-11 13:13:23 +02:00
|
|
|
export type FillStyle = "hachure" | "cross-hatch" | "solid";
|
|
|
|
export type FontFamily = keyof typeof FONT_FAMILY;
|
|
|
|
export type FontString = string & { _brand: "fontString" };
|
2020-05-26 13:07:46 -07:00
|
|
|
export type GroupId = string;
|
2020-12-11 13:13:23 +02:00
|
|
|
export type PointerType = "mouse" | "pen" | "touch";
|
|
|
|
export type StrokeSharpness = "round" | "sharp";
|
|
|
|
export type StrokeStyle = "solid" | "dashed" | "dotted";
|
|
|
|
export type TextAlign = "left" | "center" | "right";
|
|
|
|
export type VerticalAlign = "top" | "middle";
|
2020-05-26 13:07:46 -07:00
|
|
|
|
2020-03-17 20:55:40 +01:00
|
|
|
type _ExcalidrawElementBase = Readonly<{
|
|
|
|
id: string;
|
|
|
|
x: number;
|
|
|
|
y: number;
|
|
|
|
strokeColor: string;
|
|
|
|
backgroundColor: string;
|
2020-12-11 13:13:23 +02:00
|
|
|
fillStyle: FillStyle;
|
2020-03-17 20:55:40 +01:00
|
|
|
strokeWidth: number;
|
2020-12-11 13:13:23 +02:00
|
|
|
strokeStyle: StrokeStyle;
|
|
|
|
strokeSharpness: StrokeSharpness;
|
2020-03-17 20:55:40 +01:00
|
|
|
roughness: number;
|
|
|
|
opacity: number;
|
|
|
|
width: number;
|
|
|
|
height: number;
|
2020-04-02 17:40:26 +09:00
|
|
|
angle: number;
|
2020-03-17 20:55:40 +01:00
|
|
|
seed: number;
|
|
|
|
version: number;
|
|
|
|
versionNonce: number;
|
|
|
|
isDeleted: boolean;
|
2020-05-30 22:48:57 +02:00
|
|
|
groupIds: readonly GroupId[];
|
2020-08-08 21:04:15 -07:00
|
|
|
boundElementIds: readonly ExcalidrawLinearElement["id"][] | null;
|
2020-03-17 20:55:40 +01:00
|
|
|
}>;
|
|
|
|
|
2020-05-28 11:41:34 +02:00
|
|
|
export type ExcalidrawSelectionElement = _ExcalidrawElementBase & {
|
|
|
|
type: "selection";
|
|
|
|
};
|
2020-08-08 21:04:15 -07:00
|
|
|
|
|
|
|
export type ExcalidrawRectangleElement = _ExcalidrawElementBase & {
|
|
|
|
type: "rectangle";
|
|
|
|
};
|
|
|
|
|
|
|
|
export type ExcalidrawDiamondElement = _ExcalidrawElementBase & {
|
|
|
|
type: "diamond";
|
|
|
|
};
|
|
|
|
|
|
|
|
export type ExcalidrawEllipseElement = _ExcalidrawElementBase & {
|
|
|
|
type: "ellipse";
|
|
|
|
};
|
|
|
|
|
2020-05-26 13:07:46 -07:00
|
|
|
/**
|
|
|
|
* These are elements that don't have any additional properties.
|
|
|
|
*/
|
2020-05-28 11:41:34 +02:00
|
|
|
export type ExcalidrawGenericElement =
|
|
|
|
| ExcalidrawSelectionElement
|
2020-08-08 21:04:15 -07:00
|
|
|
| ExcalidrawRectangleElement
|
|
|
|
| ExcalidrawDiamondElement
|
|
|
|
| ExcalidrawEllipseElement;
|
2020-01-06 19:34:22 +04:00
|
|
|
|
2020-03-08 10:20:55 -07:00
|
|
|
/**
|
|
|
|
* ExcalidrawElement should be JSON serializable and (eventually) contain
|
|
|
|
* no computed data. The list of all ExcalidrawElements should be shareable
|
|
|
|
* between peers and contain no state local to the peer.
|
|
|
|
*/
|
2020-03-17 20:55:40 +01:00
|
|
|
export type ExcalidrawElement =
|
|
|
|
| ExcalidrawGenericElement
|
|
|
|
| ExcalidrawTextElement
|
|
|
|
| ExcalidrawLinearElement;
|
2020-03-09 22:34:50 -07:00
|
|
|
|
2020-04-08 09:49:52 -07:00
|
|
|
export type NonDeleted<TElement extends ExcalidrawElement> = TElement & {
|
|
|
|
isDeleted: false;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type NonDeletedExcalidrawElement = NonDeleted<ExcalidrawElement>;
|
|
|
|
|
2020-03-17 20:55:40 +01:00
|
|
|
export type ExcalidrawTextElement = _ExcalidrawElementBase &
|
2020-03-10 20:11:02 -07:00
|
|
|
Readonly<{
|
|
|
|
type: "text";
|
2020-05-27 15:14:50 +02:00
|
|
|
fontSize: number;
|
|
|
|
fontFamily: FontFamily;
|
2020-03-10 20:11:02 -07:00
|
|
|
text: string;
|
|
|
|
baseline: number;
|
2020-04-08 21:00:27 +01:00
|
|
|
textAlign: TextAlign;
|
2020-06-25 21:21:27 +02:00
|
|
|
verticalAlign: VerticalAlign;
|
2020-03-10 20:11:02 -07:00
|
|
|
}>;
|
2020-03-09 22:34:50 -07:00
|
|
|
|
2020-08-08 21:04:15 -07:00
|
|
|
export type ExcalidrawBindableElement =
|
|
|
|
| ExcalidrawRectangleElement
|
|
|
|
| ExcalidrawDiamondElement
|
|
|
|
| ExcalidrawEllipseElement
|
|
|
|
| ExcalidrawTextElement;
|
|
|
|
|
|
|
|
export type PointBinding = {
|
|
|
|
elementId: ExcalidrawBindableElement["id"];
|
|
|
|
focus: number;
|
|
|
|
gap: number;
|
|
|
|
};
|
|
|
|
|
2020-12-11 17:17:28 +00:00
|
|
|
export type Arrowhead = "arrow" | "bar" | "dot";
|
2020-12-08 15:02:55 +00:00
|
|
|
|
2020-03-17 20:55:40 +01:00
|
|
|
export type ExcalidrawLinearElement = _ExcalidrawElementBase &
|
|
|
|
Readonly<{
|
2020-12-08 15:02:55 +00:00
|
|
|
type: "line" | "draw" | "arrow";
|
2020-06-01 11:35:44 +02:00
|
|
|
points: readonly Point[];
|
2020-07-28 23:40:06 +02:00
|
|
|
lastCommittedPoint: Point | null;
|
2020-08-08 21:04:15 -07:00
|
|
|
startBinding: PointBinding | null;
|
|
|
|
endBinding: PointBinding | null;
|
2020-12-08 15:02:55 +00:00
|
|
|
startArrowhead: Arrowhead | null;
|
|
|
|
endArrowhead: Arrowhead | null;
|
2020-03-17 20:55:40 +01:00
|
|
|
}>;
|