import { Color } from "@dt/core-ui"; import { IImageViewer } from "../Models/IImageViewer"; import { Bounds, PointLocation, Size } from "../Models/SelectionBoxTypes"; import { UndoCommandSupport } from "../Undo/Commands"; import { PaintExecuteOptions } from "../../plugins/PaintTools/Commands/PaintCommands"; export declare type LayersPanelModel = { layerIndex?: number; }; /** * MergeImageLayer undo command. **/ export declare class MergeImageLayerCommand implements UndoCommandSupport { newDataUrl: any; originalImageDataUrl: any; /** * Constructor. * @param newDataUrl * @param originalImageDataUrl */ constructor(newDataUrl: any, originalImageDataUrl: any); name: string; /** * Action implementation. * @param viewer **/ execute(viewer: IImageViewer): Promise; /** * Undo action implementation. * @param viewer **/ undo(viewer: IImageViewer): Promise; } /** * Image layer canvas. **/ export interface IImageLayer { /** * Image layer name. **/ get name(): string; /** * Image layer name. **/ set name(name: string); get size(): Size; clear(clearCache: boolean): any; dispose(): any; ensureBackground(): Promise; merge(): Promise; saveToDataURL(): Promise; /** * Call this method to draw the paint objects specified in the paintObjects array onto the canvas. **/ drawObjects(): Promise; /** * Run a temporary paint command on a separate temporary canvas layer. * This method should create and display the temporary canvas layer if it doesn't exist. **/ executeTempPaintCommand(cmd: IPaintCommand): any; /** * Get all temporary paint commands. **/ getTempPaintCommands(): IPaintCommand[]; /** * Clear all temporary paint commands, clear and dispose the temporary canvas layer. **/ clearTempPaintCommands(): any; /** * Canvas object to paint. **/ get mainCanvas(): HTMLCanvasElement; /** * Canvas object to paint. **/ get backCanvas(): HTMLCanvasElement; /** * Main 2D rendering context. **/ get mainCtx(): CanvasRenderingContext2D; /** * Background 2D rendering context. **/ get backCtx(): CanvasRenderingContext2D; /** * The objects in this array are drawn to the canvas. **/ get paintObjects(): IPaintObject[]; } /** * Paint point trigger type. **/ export declare type PointerTriggerType = "start" | "move" | "end"; /** * Paint command name. **/ export declare type PaintCommandName = "Pencil" | "Brush" | "Eraser" | "ErasePath2D" | "CloneStamp" | "TextPaintObject" | "RectanglePaintObject" | "LinePaintObject" | "ArrowPaintObject" | "EllipsePaintObject" | "BracketsPaintObject" | "UpdateObjectPosition" | "SetObjectProperty" | "DeleteObject" | "CopySelectedRegion" | "UpdateSelectedRegion" | "ResetSelectedRegion" | "CommitSelectedRegionImage" | "UndoSequenceMarker" | "ImagePaintObject" | "SelectObject" | "UnselectObject"; /** * Paint designer context. **/ export interface IPaintDesignerContext { /** * Get a reference to an array with object designers. **/ getPaintObjectDesigners(): any[]; get selectedObjectDesigners(): IPaintObjectDesigner[]; } /** * Paint command execution options. **/ export declare type IPaintExecuteOptions = { /** * Previous command. **/ prevCommand?: IPaintCommand; context: IPaintDesignerContext; }; /** * Represents a canvas paint command, optionally supporting serialization and undo operations. */ export interface IPaintCommand { /** * The name or type of the paint command. * Used to identify and group similar command operations. */ readonly name: PaintCommandName; /** * Optional point location (e.g. cursor or touch position) associated with the command. * This can be used for positioning or context-aware execution. */ point?: PointLocation; /** * The type of pointer trigger (e.g., mouse, touch, pen) that initiated this command. * Helps in distinguishing user input sources. */ trigger: PointerTriggerType; /** * Creates a deep copy of this command instance. * Useful for storing history or duplicating commands without side effects. * * @returns A new instance of the same command with cloned properties. */ clone(): IPaintCommand; /** * Executes the paint command using the provided rendering contexts. * * @param mainCtx The main canvas rendering context where new edits are applied. * @param backCtx The background rendering context, typically containing the base image or previous state. * @param options Additional configuration or context-specific options required during execution. */ execute(mainCtx: CanvasRenderingContext2D, backCtx: CanvasRenderingContext2D, options: IPaintExecuteOptions): void; } /** * Interface for commands that support undo operations. * Commands implementing this interface must define how to revert their effects. */ export interface IUndoableCommand { /** * Reverts the changes made by this command, restoring the previous state. * Should be side-effect-free beyond restoring canvas or model state. */ undo(options: PaintExecuteOptions): void; } /** * Paint object type name. */ export declare type PaintObjectType = "image" | "rectangle" | "text" | "circle" | "triangle" | "line" | "arrow" | "polygon" | "ellipse" | "brackets"; /** * Extended paint object parameters with additional rendering options */ export interface PaintObjectParameters { isDesignTime?: boolean; context: IImageLayer; pixelRatio?: number; selectionActive?: boolean; } /** * Complete set of paint object properties with strict typing */ export declare type PaintObjectPropertyName = "bounds" | "position" | "fontSize" | "fontFamily" | "fontWeight" | "fontStyle" | "opacity" | "text" | "lineWidth" | "lineColor" | "fillColor" | "rotation" | "shadowBlur" | "shadowColor" | "startPosition" | "endPosition" | "radius" | "points" | "fontName" | "fontColor" | "fontItalic" | "fontBold"; /** * Core interface representing a paint object that can be rendered on canvas. * @template T - The specific type of paint object (e.g., 'rectangle', 'line') */ export interface IPaintObject { /** * The type identifier of the paint object (e.g., 'line', 'rectangle') * @readonly */ readonly type: T; /** * The display name of the paint object * @readonly */ readonly name: string; /** * Gets the bounding rectangle of the object in canvas coordinates */ get bounds(): Bounds; /** * Sets the bounding rectangle of the object * @param bounds - New bounding rectangle dimensions and position */ set bounds(bounds: Bounds); startPosition: PointLocation; /** * Gets the end position (particularly relevant for line objects) */ get endPosition(): PointLocation; /** * Sets the end position (particularly relevant for line objects) * @param pos - New end position coordinates */ set endPosition(pos: PointLocation); rotation: number; /** * Returns the additional padding (in pixels) required around the object * to accommodate all visual elements like styled line caps. * This is useful for properly sizing the canvas when rendering this object. */ get canvasPadding(): number; /** * Renders the object to the specified canvas context * @param destCtx - Primary drawing context * @param mainCtx - Main canvas context (for composite operations) * @param backCtx - Background context (for layered rendering) * @param params - Optional rendering parameters */ draw(destCtx: CanvasRenderingContext2D, mainCtx: CanvasRenderingContext2D, backCtx: CanvasRenderingContext2D, params?: PaintObjectParameters): Promise; /** * Calculates the content dimensions of the object * @param ctx - Canvas context used for measurements (e.g., text metrics) * @returns Size object containing width and height */ getContentSize(ctx: CanvasRenderingContext2D): Size; /** * Retrieves a property value by name * @template K - Type of the property name * @param propertyName - Name of the property to retrieve * @returns The property value or undefined if not found */ getProperty(propertyName: K): any; /** * Updates a property value by name * @template K - Type of the property name * @param propertyName - Name of the property to set * @param value - New value for the property * @returns True if the property was changed, false otherwise */ setProperty(propertyName: K, value: any): boolean; /** * Resets all user-modified properties of the object * back to their registered factory default values. */ resetToFactoryDefaults(): void; } /** * Type mapping for all possible property values */ export declare type PaintObjectPropertyMap = { bounds: Bounds; position: PointLocation; fontSize: number; fontFamily: string; fontWeight: 'normal' | 'bold'; fontStyle: 'normal' | 'italic'; opacity: number; text: string; lineWidth: number; lineColor: Color; fillColor: Color; rotation: number; shadowBlur: number; shadowColor: string; endPosition: PointLocation; radius: number; points: PointLocation[]; }; /** * Paint object designer interface. */ export interface IPaintObjectDesigner { readonly id: string; readonly typeName: "PaintObjectDesigner" | "SelectedRegion"; /** * Gets/sets selected state. **/ selected: boolean; setSelected(selected: boolean, skipUndo: boolean): any; paintObject: IPaintObject | null; dispose(): any; invalidate(): any; /** * Gets paint object property value. * @param propertyName */ getPaintObjectProperty(propertyName: PaintObjectPropertyName): any | null; /** * Sets paint object property value. * Returns true if designer appearance changed. * @param propertyName * @param val * @param dirty **/ setPaintObjectProperty(propertyName: PaintObjectPropertyName, val: any, dirty?: boolean, caller?: string): boolean; finishInlineEdits(): any; onPointerStart(point: PointLocation): any; onPointerMove(point: PointLocation, keepSize?: boolean): any; /** * Returns a boolean value indicating whether the selection path is automatically closed. * @param point */ onPointerEnd(point: PointLocation): boolean; /** * Sets paint object canvas location. * Returns true if designer appearance changed. * @param point * @param moveDisatance */ updatePosition(point: PointLocation, moveDisatance?: { x: number; y: number; }): boolean; }