Skip to content

A lightweight Clip Studio Paint alternative with real-time multiplayer collaborative drawing. Built with Tauri and React.

3.1 KB
Raw Blame
import React from 'react';
import {
  ToolType,
  BrushSettings,
  Point,
  CanvasDimensions,
  CanvasSelection,
  HistoryActionType,
  CanvasColorMode,
  DirtyRect,
  DocumentStateDelta,
  LayerItem,
  LayerTreeDelta,
  TileDelta,
  VectorStroke,
} from '../../types/editor';
import { CanvasNavigationHandle } from '../useCanvasNavigation';
import { PerspectiveRuler, StraightRuler, ConstraintAxis } from '../../types/perspective';

export interface ExtendedPointerEvent extends React.PointerEvent<HTMLElement> {
  coalescedEvents?: PointerEvent[];
  predictedEvents?: PointerEvent[];
}

export interface LastStrokeEndState {
  x: number;
  y: number;
  pressure: number;
  width: number;
  layerId: string;
}

export type ApplyLayerTreeDeltaFn = (
  delta: LayerTreeDelta,
  direction: 'undo' | 'redo'
) => {
  nextLayers: LayerItem[];
  nextActiveLayerId: string | null;
  removedLayerIds: string[];
  addedLayers: LayerItem[];
};

export type ApplyDocumentStateDeltaFn = (
  delta: DocumentStateDelta,
  direction: 'undo' | 'redo'
) => void;

export type PushHistoryStepFn = (
  actionType: HistoryActionType,
  label: string,
  beforeData: ImageData | null,
  afterData: ImageData | null,
  targetLayerId: string,
  dirtyRect?: DirtyRect,
  explicitTileDeltas?: TileDelta[],
  vectorDelta?: { before: VectorStroke[]; after: VectorStroke[] },
  peerId?: string | number,
  strokeId?: string,
  isMaskEdit?: boolean,
  layerTreeDelta?: LayerTreeDelta,
  documentStateDelta?: DocumentStateDelta
) => void;

export interface UseCanvasDrawingProps {
  tool?: ToolType;
  brushSettings?: BrushSettings;
  dimensions: CanvasDimensions;
  selection?: CanvasSelection | null;
  colorMode?: CanvasColorMode;
  disabled?: boolean;
  viewportRef: React.RefObject<HTMLDivElement | null>;
  pan: { x: number; y: number };
  zoom: number;
  rotation: number;
  flipX?: boolean;
  flipY?: boolean;
  navigation?: CanvasNavigationHandle;
  activeLayerId: string;
  activeLayerLocked?: boolean;
  activeLayerVisible?: boolean;
  layers?: LayerItem[];
  onUpdateLayerThumbnail: (layerId: string, immediate?: boolean) => void;
  onApplyLayerTreeDelta?: ApplyLayerTreeDeltaFn;
  onApplyDocumentStateDelta?: ApplyDocumentStateDeltaFn;
  isMaskMode?: boolean;
  onUpdateMaskThumbnail?: (
    layerId: string,
    immediate?: boolean,
    skipVersionBump?: boolean
  ) => void;
  onCollabStrokeStart?: (
    strokeId: string,
    layerId: string,
    brushSettings: BrushSettings,
    tool: ToolType,
    startPoint: Point
  ) => void;
  onCollabStrokeChunk?: (strokeId: string, points: Point[]) => void;
  onCollabStrokeFinish?: (
    strokeId: string,
    layerId: string,
    endPoint: Point,
    dirtyRect?: DirtyRect,
    vectorStroke?: VectorStroke
  ) => void;
  onCollabCursorMove?: (x: number, y: number, isDrawing: boolean, tool: ToolType) => void;
  perspectiveRuler?: PerspectiveRuler | null;
  straightRuler?: StraightRuler | null;
  onActiveConstraintAxisChange?: (axis: ConstraintAxis | null) => void;
  activeSessionId?: string | null;
}

export function isBackgroundLayerId(id: string): boolean {
  return id === 'layer-bg' || id.startsWith('layer-bg');
}