import type { ComponentType, ReactNode } from "react"; /** A single atomic edit operation, recorded for undo/redo replay. */ export interface EditAction { type: string; params: Record; } /** * Registers a replay handler for a specific action type. * Must be a pure async function — no React hooks, no side-effect state. */ export interface ActionHandler { type: string; apply: (imageUrl: string, params: Record) => Promise; } /** Maps action type → replay function. Built by ImageEditor from the plugins array. */ export type ActionRegistry = Map; export interface ToolProviderProps { imageUrl: string; /** Called when the tool has produced a transformed image. */ onApply: (blob: Blob, actions: EditAction[]) => void; onCancel: () => void; children: ReactNode; } /** * A mode tool: activates a persistent editing state with its own canvas overlay and toolbar. * The Provider shares state between Overlay and Toolbar via React context. * `actions` registers replay handlers so the history can reconstruct any past state. */ export interface ToolPlugin { type: "tool"; id: string; label: string; Icon: ComponentType; Provider: ComponentType; Overlay: ComponentType; Toolbar: ComponentType; /** Replay handlers for every action type this tool can produce. */ actions: ActionHandler[]; } /** An action tool: executes a transform immediately without entering a persistent mode. */ export interface ActionPlugin { type: "action"; id: string; label: string; Icon: ComponentType; execute: (imageUrl: string) => Promise; } export type Plugin = ToolPlugin | ActionPlugin; /** * A view plugin: provides zoom/pan or other viewport transforms without modifying the image. * Wraps the main image area with gesture handling and contributes controls to the top toolbar. */ export interface ViewPlugin { type: "view"; id: string; Provider: ComponentType<{ children: ReactNode; }>; /** Wraps the main image; applies transforms and captures pinch/pan gestures. */ CanvasWrapper: ComponentType<{ children: ReactNode; panEnabled?: boolean; }>; /** Controls rendered in the top toolbar (e.g. zoom in/out/reset). */ TopBarControls: ComponentType<{ disabled?: boolean; isSmall?: boolean; }>; }