tldraw/types.ts

115 lines
2 KiB
TypeScript
Raw Normal View History

2021-05-09 21:22:25 +00:00
export interface Data {
2021-05-09 13:04:42 +00:00
camera: {
point: number[]
zoom: number
}
2021-05-10 12:16:57 +00:00
brush?: Bounds
2021-05-09 21:22:25 +00:00
currentPageId: string
selectedIds: string[]
2021-05-10 12:16:57 +00:00
pointedId?: string
2021-05-09 21:22:25 +00:00
document: {
pages: Record<string, Page>
}
}
export interface Page {
id: string
type: "page"
childIndex: number
name: string
shapes: Record<string, Shape>
}
export enum ShapeType {
Dot = "dot",
2021-05-09 21:22:25 +00:00
Circle = "circle",
Ellipse = "ellipse",
Line = "line",
Ray = "ray",
LineSegment = "lineSegment",
Rectangle = "rectangle",
// Glob = "glob",
// Spline = "spline",
// Cubic = "cubic",
// Conic = "conic",
2021-05-09 21:22:25 +00:00
}
export interface BaseShape {
id: string
type: ShapeType
parentId: string
childIndex: number
name: string
rotation: 0
}
export interface DotShape extends BaseShape {
type: ShapeType.Dot
point: number[]
}
export interface CircleShape extends BaseShape {
type: ShapeType.Circle
point: number[]
radius: number
}
export interface EllipseShape extends BaseShape {
type: ShapeType.Ellipse
point: number[]
radiusX: number
radiusY: number
}
export interface LineShape extends BaseShape {
type: ShapeType.Line
point: number[]
vector: number[]
}
export interface RayShape extends BaseShape {
type: ShapeType.Ray
point: number[]
vector: number[]
}
export interface LineSegmentShape extends BaseShape {
type: ShapeType.LineSegment
start: number[]
end: number[]
}
export interface RectangleShape extends BaseShape {
type: ShapeType.Rectangle
point: number[]
size: number[]
2021-05-09 13:04:42 +00:00
}
2021-05-09 21:22:25 +00:00
export type Shape =
| DotShape
2021-05-09 21:22:25 +00:00
| CircleShape
| EllipseShape
| LineShape
| RayShape
| LineSegmentShape
| RectangleShape
2021-05-10 12:16:57 +00:00
export interface Bounds {
minX: number
minY: number
maxX: number
maxY: number
width: number
height: number
}
export interface Shapes extends Record<ShapeType, Shape> {
[ShapeType.Dot]: DotShape
[ShapeType.Circle]: CircleShape
[ShapeType.Ellipse]: EllipseShape
[ShapeType.Line]: LineShape
[ShapeType.Ray]: RayShape
[ShapeType.LineSegment]: LineSegmentShape
[ShapeType.Rectangle]: RectangleShape
}