import { Point, Rect } from "@noya-app/noya-geometry"; import { KeyMap } from "@noya-app/noya-keymap"; import React from "react"; import { IdentifiablePoint } from "../utils/pointUtils"; import { BaseMode } from "./PluginSystem"; export type BaseContextProperties = { getMode: () => M; setMode: (mode: React.SetStateAction) => void; getData: () => D; setData: (data: React.SetStateAction) => void; }; export type HandleKeyboardEventProperties = { handleKeyboardEvent: (keyMap: KeyMap) => (event: React.KeyboardEvent) => void; setShouldHandleKeyboardEvents: (shouldHandleKeyboardEvents: boolean) => void; setReadOnly: (readOnly: boolean) => void; }; export type CanvasRefProperties = { canvasRef: React.RefObject; }; export type EventWithPointAndTarget = Pick< MouseEvent, "target" | "clientX" | "clientY" >; export type ScreenPointProperties = { /** * Get the clicked point in the screen coordinate system */ getScreenPoint: (input: EventWithPointAndTarget) => Point; /** * Get the clicked point in the canvas coordinate system */ getCanvasPoint: (input: EventWithPointAndTarget) => Point; /** * Convert a point between the screen and canvas coordinate systems */ convertPoint: ( point: Point, targetCoordinateSystem: "screen" | "canvas" ) => Point; }; export type PointerCaptureProperties = { setPointerCapture: (pointerId: number) => void; releasePointerCapture: (pointerId: number) => void; }; export type GetElementsOptions = { at?: Rect | Point; predicate?: (element: CanvasElement) => boolean; }; export type ElementProperties = { getElementId: (element: CanvasElement) => string; filterElements: ( options: GetElementsOptions ) => CanvasElement[]; }; export type GetPointsOptions = { at?: Rect; predicate?: (point: IdentifiablePoint) => boolean; }; export type PointProperties = { filterPoints: (options: GetPointsOptions) => IdentifiablePoint[]; highlightedPointId?: string; }; export type SelectableProperties = { isSelectable?: (element: CanvasElement) => boolean; }; export type MovableProperties = { isMovable?: (element: CanvasElement) => boolean; }; export type ScalableProperties = { isScalable?: (element: CanvasElement) => boolean; }; export type HighlightableProperties = { isHighlightable?: (element: CanvasElement) => boolean; }; export type PointHighlightableProperties = { isPointHighlightable?: (point: IdentifiablePoint) => boolean; }; export type TextEditableProperties = { isTextEditable?: (element: CanvasElement) => boolean; }; export type FocusProperties = { focus: () => void; }; export type DOMContextProperties = PointerCaptureProperties & ScreenPointProperties & HandleKeyboardEventProperties & CanvasRefProperties;