2021-05-14 22:56:41 +00:00
|
|
|
import * as monaco from "monaco-editor/esm/vs/editor/editor.api"
|
|
|
|
|
2021-05-12 21:11:17 +00:00
|
|
|
import React from "react"
|
|
|
|
|
2021-05-09 21:22:25 +00:00
|
|
|
export interface Data {
|
2021-05-13 06:44:52 +00:00
|
|
|
isReadOnly: boolean
|
2021-05-14 22:56:41 +00:00
|
|
|
settings: {
|
|
|
|
fontSize: number
|
|
|
|
darkMode: boolean
|
|
|
|
}
|
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-12 11:27:33 +00:00
|
|
|
selectedIds: Set<string>
|
2021-05-10 12:16:57 +00:00
|
|
|
pointedId?: string
|
2021-05-14 22:56:41 +00:00
|
|
|
hoveredId?: string
|
2021-05-16 08:33:08 +00:00
|
|
|
currentPageId: string
|
|
|
|
currentCodeFileId: string
|
2021-05-09 21:22:25 +00:00
|
|
|
document: {
|
|
|
|
pages: Record<string, Page>
|
2021-05-14 22:56:41 +00:00
|
|
|
code: Record<string, CodeFile>
|
2021-05-09 21:22:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-14 22:56:41 +00:00
|
|
|
export interface CodeFile {
|
|
|
|
id: string
|
|
|
|
name: string
|
|
|
|
code: string
|
|
|
|
}
|
|
|
|
|
2021-05-09 21:22:25 +00:00
|
|
|
export interface Page {
|
|
|
|
id: string
|
|
|
|
type: "page"
|
|
|
|
childIndex: number
|
|
|
|
name: string
|
|
|
|
shapes: Record<string, Shape>
|
|
|
|
}
|
|
|
|
|
|
|
|
export enum ShapeType {
|
2021-05-11 10:13:07 +00:00
|
|
|
Dot = "dot",
|
2021-05-09 21:22:25 +00:00
|
|
|
Circle = "circle",
|
|
|
|
Ellipse = "ellipse",
|
|
|
|
Line = "line",
|
|
|
|
Ray = "ray",
|
2021-05-12 21:11:17 +00:00
|
|
|
Polyline = "polyline",
|
2021-05-11 10:13:07 +00:00
|
|
|
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
|
2021-05-15 13:02:13 +00:00
|
|
|
isGenerated: boolean
|
2021-05-09 21:22:25 +00:00
|
|
|
name: string
|
2021-05-12 09:18:11 +00:00
|
|
|
point: number[]
|
2021-05-13 18:22:16 +00:00
|
|
|
rotation: number
|
2021-05-12 21:11:17 +00:00
|
|
|
style: Partial<React.SVGProps<SVGUseElement>>
|
2021-05-09 21:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface DotShape extends BaseShape {
|
|
|
|
type: ShapeType.Dot
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface CircleShape extends BaseShape {
|
|
|
|
type: ShapeType.Circle
|
|
|
|
radius: number
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface EllipseShape extends BaseShape {
|
|
|
|
type: ShapeType.Ellipse
|
|
|
|
radiusX: number
|
|
|
|
radiusY: number
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface LineShape extends BaseShape {
|
|
|
|
type: ShapeType.Line
|
2021-05-14 21:05:21 +00:00
|
|
|
direction: number[]
|
2021-05-09 21:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface RayShape extends BaseShape {
|
|
|
|
type: ShapeType.Ray
|
2021-05-14 21:05:21 +00:00
|
|
|
direction: number[]
|
2021-05-09 21:22:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 09:18:11 +00:00
|
|
|
export interface PolylineShape extends BaseShape {
|
|
|
|
type: ShapeType.Polyline
|
|
|
|
points: number[][]
|
2021-05-09 21:22:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface RectangleShape extends BaseShape {
|
|
|
|
type: ShapeType.Rectangle
|
|
|
|
size: number[]
|
2021-05-09 13:04:42 +00:00
|
|
|
}
|
2021-05-09 21:22:25 +00:00
|
|
|
|
|
|
|
export type Shape =
|
2021-05-11 10:13:07 +00:00
|
|
|
| DotShape
|
2021-05-09 21:22:25 +00:00
|
|
|
| CircleShape
|
|
|
|
| EllipseShape
|
|
|
|
| LineShape
|
|
|
|
| RayShape
|
2021-05-12 09:18:11 +00:00
|
|
|
| PolylineShape
|
2021-05-09 21:22:25 +00:00
|
|
|
| RectangleShape
|
2021-05-10 12:16:57 +00:00
|
|
|
|
|
|
|
export interface Bounds {
|
|
|
|
minX: number
|
|
|
|
minY: number
|
|
|
|
maxX: number
|
|
|
|
maxY: number
|
|
|
|
width: number
|
|
|
|
height: number
|
|
|
|
}
|
2021-05-11 10:13:07 +00:00
|
|
|
|
2021-05-14 12:44:23 +00:00
|
|
|
export interface ShapeBounds extends Bounds {
|
|
|
|
id: string
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface PointSnapshot extends Bounds {
|
|
|
|
nx: number
|
|
|
|
nmx: number
|
|
|
|
ny: number
|
|
|
|
nmy: number
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface BoundsSnapshot extends PointSnapshot {
|
|
|
|
nw: number
|
|
|
|
nh: number
|
|
|
|
}
|
|
|
|
|
2021-05-11 10:13:07 +00:00
|
|
|
export interface Shapes extends Record<ShapeType, Shape> {
|
|
|
|
[ShapeType.Dot]: DotShape
|
|
|
|
[ShapeType.Circle]: CircleShape
|
|
|
|
[ShapeType.Ellipse]: EllipseShape
|
|
|
|
[ShapeType.Line]: LineShape
|
|
|
|
[ShapeType.Ray]: RayShape
|
2021-05-12 09:18:11 +00:00
|
|
|
[ShapeType.Polyline]: PolylineShape
|
2021-05-11 10:13:07 +00:00
|
|
|
[ShapeType.Rectangle]: RectangleShape
|
|
|
|
}
|
2021-05-12 09:48:35 +00:00
|
|
|
|
|
|
|
export type Difference<A, B> = A extends B ? never : A
|
|
|
|
|
|
|
|
export type ShapeSpecificProps<T extends Shape> = Pick<
|
|
|
|
T,
|
|
|
|
Difference<keyof T, keyof BaseShape>
|
|
|
|
>
|
|
|
|
|
2021-05-12 11:27:33 +00:00
|
|
|
export type ShapeIndicatorProps<T extends Shape> = ShapeSpecificProps<T>
|
2021-05-12 21:11:17 +00:00
|
|
|
|
2021-05-14 12:44:23 +00:00
|
|
|
export type ShapeUtil<K extends Shape> = {
|
2021-05-13 18:22:16 +00:00
|
|
|
create(props: Partial<K>): K
|
|
|
|
getBounds(shape: K): Bounds
|
|
|
|
hitTest(shape: K, test: number[]): boolean
|
|
|
|
hitTestBounds(shape: K, bounds: Bounds): boolean
|
|
|
|
rotate(shape: K): K
|
|
|
|
translate(shape: K, delta: number[]): K
|
|
|
|
scale(shape: K, scale: number): K
|
|
|
|
stretch(shape: K, scaleX: number, scaleY: number): K
|
|
|
|
render(shape: K): JSX.Element
|
2021-05-12 21:11:17 +00:00
|
|
|
}
|
2021-05-13 06:44:52 +00:00
|
|
|
|
|
|
|
export interface PointerInfo {
|
2021-05-13 10:13:14 +00:00
|
|
|
target: string
|
2021-05-13 06:44:52 +00:00
|
|
|
pointerId: number
|
|
|
|
origin: number[]
|
|
|
|
point: number[]
|
|
|
|
shiftKey: boolean
|
|
|
|
ctrlKey: boolean
|
|
|
|
metaKey: boolean
|
|
|
|
altKey: boolean
|
|
|
|
}
|
2021-05-14 12:44:23 +00:00
|
|
|
|
|
|
|
export enum TransformEdge {
|
|
|
|
Top = "top_edge",
|
|
|
|
Right = "right_edge",
|
|
|
|
Bottom = "bottom_edge",
|
|
|
|
Left = "left_edge",
|
|
|
|
}
|
|
|
|
|
|
|
|
export enum TransformCorner {
|
|
|
|
TopLeft = "top_left_corner",
|
|
|
|
TopRight = "top_right_corner",
|
|
|
|
BottomRight = "bottom_right_corner",
|
|
|
|
BottomLeft = "bottom_left_corner",
|
|
|
|
}
|
2021-05-14 22:56:41 +00:00
|
|
|
|
|
|
|
export type IMonaco = typeof monaco
|
|
|
|
|
|
|
|
export type IMonacoEditor = monaco.editor.IStandaloneCodeEditor
|