import React from "react" export interface Data { isReadOnly: boolean camera: { point: number[] zoom: number } brush?: Bounds currentPageId: string selectedIds: Set pointedId?: string document: { pages: Record } } export interface Page { id: string type: "page" childIndex: number name: string shapes: Record } export enum ShapeType { Dot = "dot", Circle = "circle", Ellipse = "ellipse", Line = "line", Ray = "ray", Polyline = "polyline", Rectangle = "rectangle", // Glob = "glob", // Spline = "spline", // Cubic = "cubic", // Conic = "conic", } export interface BaseShape { id: string type: ShapeType parentId: string childIndex: number name: string point: number[] rotation: number style: Partial> } 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 vector: number[] } export interface RayShape extends BaseShape { type: ShapeType.Ray vector: number[] } export interface PolylineShape extends BaseShape { type: ShapeType.Polyline points: number[][] } export interface RectangleShape extends BaseShape { type: ShapeType.Rectangle size: number[] } export type Shape = | DotShape | CircleShape | EllipseShape | LineShape | RayShape | PolylineShape | RectangleShape export interface Bounds { minX: number minY: number maxX: number maxY: number width: number height: number } 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 } export interface Shapes extends Record { [ShapeType.Dot]: DotShape [ShapeType.Circle]: CircleShape [ShapeType.Ellipse]: EllipseShape [ShapeType.Line]: LineShape [ShapeType.Ray]: RayShape [ShapeType.Polyline]: PolylineShape [ShapeType.Rectangle]: RectangleShape } export type Difference = A extends B ? never : A export type ShapeSpecificProps = Pick< T, Difference > export type ShapeIndicatorProps = ShapeSpecificProps export type ShapeUtil = { create(props: Partial): 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 } export interface PointerInfo { target: string pointerId: number origin: number[] point: number[] shiftKey: boolean ctrlKey: boolean metaKey: boolean altKey: boolean } 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", }