Skip to content

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

16.1 KB
Raw Blame
import { BrushPresetId, ToolType } from './editor';
import type { AppearanceConfig } from './appearance';

export type DockPanelId =
  | 'tools'
  | 'subtool'
  | 'tool-property'
  | 'brush-size'
  | 'navigator'
  | 'sub-view'
  | 'info'
  | 'color'
  | 'color-sliders'
  | 'color-sets'
  | 'color-history'
  | 'layers'
  | 'history'
  | 'quick-access'
  | 'auto-actions';

export type DockSide = 'left' | 'right' | 'bottom';

export const BOTTOM_DOCK_COL_ID = 'dock-bottom' as const;
export const BOTTOM_DOCK_MIN_HEIGHT = 96;
export const BOTTOM_DOCK_MAX_HEIGHT = 420;
export const BOTTOM_DOCK_DEFAULT_HEIGHT = 184;

export interface WorkspaceLocks {
  /** Disables horizontal column width and side-by-side split width resizers */
  lockWidth: boolean;
  /** Disables vertical row/group split height and bottom dock height resizers */
  lockHeight: boolean;
  /** Disables tab dragging, docking drops, and floating panel movement */
  lockMove: boolean;
}

export type WorkspaceLockKey = keyof WorkspaceLocks;

export const DEFAULT_WORKSPACE_LOCKS: WorkspaceLocks = {
  lockWidth: false,
  lockHeight: false,
  lockMove: false,
};

export type BuiltInWorkspacePresetId =
  | 'default-illustration'
  | 'photoshop-studio'
  | 'clip-studio'
  | 'manga-studio'
  | 'minimalist-tablet';

export type WorkspacePresetId = BuiltInWorkspacePresetId | 'custom';

export const BUILT_IN_WORKSPACE_PRESET_IDS: readonly BuiltInWorkspacePresetId[] = [
  'default-illustration',
  'photoshop-studio',
  'clip-studio',
  'manga-studio',
  'minimalist-tablet',
] as const;

export interface StatusBarModulesConfig {
  toolInfo: boolean;
  canvasInfo: boolean;
  valueCheck: boolean;
  cursorCoords: boolean;
  pressureMeter: boolean;
  rotationZoom: boolean;
}

export type StatusBarModuleId = keyof StatusBarModulesConfig;

export const DEFAULT_STATUS_BAR_MODULES: StatusBarModulesConfig = {
  toolInfo: true,
  canvasInfo: true,
  valueCheck: true,
  cursorCoords: true,
  pressureMeter: true,
  rotationZoom: true,
};

export interface SavedWorkspaceProfile {
  id: string;
  name: string;
  createdAt: string;
  updatedAt: string;
  layout: WorkspaceLayout;
  leftHandedMode: boolean;
  showToolOptionsBar: boolean;
  showStatusBar: boolean;
  showDocumentTabs: boolean;
  showCommandBar: boolean;
  statusBarModules?: StatusBarModulesConfig;
  workspaceLocks?: WorkspaceLocks;
  /** Optional bundled Appearance Studio preset */
  appearance?: AppearanceConfig;
}

export const INK_WORKSPACE_FORMAT_ID = 'ink-studio-workspace' as const;
export const INK_WORKSPACE_SCHEMA_VERSION = 1 as const;

export interface InkWorkspaceBundleFile {
  format: typeof INK_WORKSPACE_FORMAT_ID;
  version: typeof INK_WORKSPACE_SCHEMA_VERSION;
  name: string;
  author?: string;
  createdAt?: string;
  layout: WorkspaceLayout;
  leftHandedMode: boolean;
  showToolOptionsBar: boolean;
  showStatusBar: boolean;
  showDocumentTabs: boolean;
  showCommandBar: boolean;
  statusBarModules?: StatusBarModulesConfig;
  workspaceLocks?: WorkspaceLocks;
  appearance?: AppearanceConfig;
}

export type ParseWorkspaceBundleResult =
  | { ok: true; bundle: InkWorkspaceBundleFile; warnings: string[] }
  | { ok: false; error: string };

export interface DockSplitCell {
  id: string;
  panelIds: DockPanelId[];
  activePanelId: DockPanelId;
  /** Horizontal width share within its equal-height split row or bottom dock (normalized to sum ~1) */
  widthRatio: number;
  /** Optional cell-level collapsed state */
  collapsed?: boolean;
}

export interface DockGroup {
  id: string;
  panelIds: DockPanelId[];
  activePanelId: DockPanelId;
  heightRatio: number;
  /** When true, the docked group/row collapses to its header bar */
  collapsed?: boolean;
  /**
   * Optional horizontal side-by-side cells (2, 3, or more) sharing this row's exact equal height.
   * When absent (legacy/single-cell groups), the group renders as one full-width cell.
   */
  splitCells?: DockSplitCell[];
}

export interface DockColumn {
  id: string;
  width: number;
  collapsed: boolean;
  groups: DockGroup[];
}

export interface DockBottomZone {
  height: number;
  collapsed: boolean;
  cells: DockSplitCell[];
}

export interface FloatingPanelLastDock {
  side: DockSide;
  colId?: string;
  groupId?: string;
  cellId?: string;
}

export interface FloatingPanelState {
  id: string;
  panelIds: DockPanelId[];
  activePanelId: DockPanelId;
  x: number;
  y: number;
  width: number;
  height: number;
  /** When true, hides the panel body leaving only the floating title bar (CSP shade mode) */
  collapsed: boolean;
  zIndex: number;
  lastDock?: FloatingPanelLastDock;
}

export interface WorkspaceLayout {
  leftDocks: DockColumn[];
  rightDocks: DockColumn[];
  /** Optional bottom dock zone beneath the canvas viewport (supports side-by-side split palettes) */
  bottomDock?: DockBottomZone;
  floatingPanels?: FloatingPanelState[];
}

export type CommandActionId =
  | 'undo'
  | 'redo'
  | 'save'
  | 'save-as'
  | 'new-layer'
  | 'duplicate-layer'
  | 'clear-layer'
  | 'merge-down'
  | 'flip-h'
  | 'flip-v'
  | 'value-check'
  | 'reset-zoom'
  | 'zoom-100'
  | 'reset-rotation'
  | 'transform'
  | 'deselect'
  | 'toggle-palettes'
  | 'toggle-quick-brushes'
  | 'swap-colors'
  | 'transparent-ink'
  | 'eyedropper'
  | 'selection'
  | 'fullscreen';

export type FocusHudPresetId = 'atelier-hud' | 'pure-canvas' | 'custom';

export type FocusHudWidgetId = 'brushSliders' | 'quickActionDock' | 'colorWheel' | 'toolRail';

export interface FocusHudPoint {
  x: number;
  y: number;
}

export type FocusHudPositions = Partial<Record<FocusHudWidgetId, FocusHudPoint>>;

export interface FocusHudConfig {
  preset: FocusHudPresetId;
  /** Slim single-column floating/edge tool strip (respects leftHandedMode) */
  showToolRail: boolean;
  /** Draggable floating matte card with Brush Size, Opacity, Flow/Ink + Undo/Redo/Brush/Eraser */
  showBrushSlidersHud: boolean;
  /** Bottom-center draggable horizontal quick action capsule customizable from COMMAND_CATALOG */
  showQuickActionDock: boolean;
  /** Draggable & collapsible floating Color Wheel card */
  showFloatingColorWheel: boolean;
  /** Keep Quick Brush Panel visible during Focus Mode (synced with quickBrushPanel.keepVisibleWhenPalettesHidden) */
  keepQuickBrushPanel: boolean;
  /** Hide top Header bar when Focus Mode is active for full-bleed canvas */
  hideHeaderInFocus: boolean;
  /** Gently dims floating HUDs to 0.22 opacity during active stylus strokes without pointer blocking */
  autoFadeWhileDrawing: boolean;
  /** Ordered command IDs displayed in FocusQuickActionDock */
  quickActionIds: CommandActionId[];
  /** Custom dragged viewport coordinates per Focus HUD widget */
  hudPositions: FocusHudPositions;
}

export type NavigatorPreviewMode = 'color' | 'bw' | 'split';

export type QuickAccessItemKind = 'command' | 'tool' | 'color' | 'brush';

export interface QuickAccessItem {
  id: string;
  kind: QuickAccessItemKind;
  label: string;
  commandId?: CommandActionId;
  toolId?: ToolType;
  color?: string;
  brushPresetId?: BrushPresetId;
}

export type QuickAccessViewMode = 'grid' | 'list';

export type QuickBrushPanelOrientation = 'vertical' | 'horizontal';
export type QuickBrushTileSize = 'compact' | 'medium' | 'large';
export type QuickBrushPreviewStyle = 'tip' | 'stroke';

export interface QuickBrushPanelState {
  visible: boolean;
  orientation: QuickBrushPanelOrientation;
  /** Fixed viewport coordinates once dragged, or null for automatic canvas-edge anchoring */
  position: { x: number; y: number } | null;
  locked: boolean;
  /** Keep visible when all other palettes are hidden via Tab */
  keepVisibleWhenPalettesHidden: boolean;
  tileSize: QuickBrushTileSize;
  /** Number of columns (vertical mode) or rows (horizontal mode) */
  columns: 1 | 2;
  previewStyle: QuickBrushPreviewStyle;
  showNames: boolean;
  showTitle: boolean;
  title: string;
  showCategoryColors: boolean;
  /** Panel surface opacity between 0.4 and 1.0 */
  opacity: number;
  /** Show an extra quick Hide/Show All UI (Tab) button directly on the quick brush bar */
  showHideUiButton: boolean;
  brushIds: BrushPresetId[];
}

export interface PersistedWorkspaceState {
  version: 1;
  activePreset: WorkspacePresetId;
  activeSavedWorkspaceId?: string | null;
  layout: WorkspaceLayout;
  savedCustomLayout: WorkspaceLayout | null;
  savedWorkspaces?: SavedWorkspaceProfile[];
  leftHandedMode?: boolean;
  quickAccessItems: QuickAccessItem[];
  quickAccessViewMode: QuickAccessViewMode;
  quickBrushPanel?: QuickBrushPanelState;
  focusHud?: FocusHudConfig;
  commandBarIds: CommandActionId[];
  showStatusBar: boolean;
  showDocumentTabs: boolean;
  showCommandBar: boolean;
  showToolOptionsBar?: boolean;
  statusBarModules?: StatusBarModulesConfig;
  workspaceLocks?: WorkspaceLocks;
  navigatorPreviewMode?: NavigatorPreviewMode;
  navigatorSplitRatio?: number;
  migratedPanels?: DockPanelId[];
  migratedQuickBrushDefaults?: boolean;
}

export interface DockPanelMeta {
  id: DockPanelId;
  title: string;
  shortTitle: string;
  defaultSide: DockSide;
  defaultWidth: number;
  minWidth: number;
  maxWidth: number;
  defaultFloatWidth: number;
  defaultFloatHeight: number;
  minFloatHeight: number;
}

export const ALL_DOCK_PANEL_IDS: DockPanelId[] = [
  'tools',
  'subtool',
  'tool-property',
  'brush-size',
  'navigator',
  'sub-view',
  'info',
  'color',
  'color-sliders',
  'color-sets',
  'color-history',
  'layers',
  'history',
  'quick-access',
  'auto-actions',
];

export const DOCK_PANEL_META: Record<DockPanelId, DockPanelMeta> = {
  tools: {
    id: 'tools',
    title: 'Tool',
    shortTitle: 'Tool',
    defaultSide: 'left',
    defaultWidth: 46,
    minWidth: 44,
    maxWidth: 96,
    defaultFloatWidth: 108,
    defaultFloatHeight: 380,
    minFloatHeight: 160,
  },
  subtool: {
    id: 'subtool',
    title: 'Sub Tool',
    shortTitle: 'Sub',
    defaultSide: 'left',
    defaultWidth: 196,
    minWidth: 140,
    maxWidth: 340,
    defaultFloatWidth: 240,
    defaultFloatHeight: 340,
    minFloatHeight: 160,
  },
  'tool-property': {
    id: 'tool-property',
    title: 'Tool Property',
    shortTitle: 'Prop',
    defaultSide: 'left',
    defaultWidth: 196,
    minWidth: 148,
    maxWidth: 340,
    defaultFloatWidth: 256,
    defaultFloatHeight: 380,
    minFloatHeight: 160,
  },
  'brush-size': {
    id: 'brush-size',
    title: 'Brush Size',
    shortTitle: 'Size',
    defaultSide: 'left',
    defaultWidth: 196,
    minWidth: 148,
    maxWidth: 340,
    defaultFloatWidth: 236,
    defaultFloatHeight: 280,
    minFloatHeight: 150,
  },
  navigator: {
    id: 'navigator',
    title: 'Navigator',
    shortTitle: 'Nav',
    defaultSide: 'right',
    defaultWidth: 224,
    minWidth: 176,
    maxWidth: 380,
    defaultFloatWidth: 268,
    defaultFloatHeight: 250,
    minFloatHeight: 170,
  },
  'sub-view': {
    id: 'sub-view',
    title: 'References',
    shortTitle: 'Refs',
    defaultSide: 'right',
    defaultWidth: 224,
    minWidth: 176,
    maxWidth: 440,
    defaultFloatWidth: 360,
    defaultFloatHeight: 380,
    minFloatHeight: 180,
  },
  info: {
    id: 'info',
    title: 'Info',
    shortTitle: 'Info',
    defaultSide: 'right',
    defaultWidth: 224,
    minWidth: 176,
    maxWidth: 380,
    defaultFloatWidth: 248,
    defaultFloatHeight: 220,
    minFloatHeight: 140,
  },
  color: {
    id: 'color',
    title: 'Color Wheel',
    shortTitle: 'Color',
    defaultSide: 'right',
    defaultWidth: 224,
    minWidth: 168,
    maxWidth: 360,
    defaultFloatWidth: 264,
    defaultFloatHeight: 320,
    minFloatHeight: 200,
  },
  'color-sliders': {
    id: 'color-sliders',
    title: 'Color Sliders',
    shortTitle: 'Sliders',
    defaultSide: 'right',
    defaultWidth: 224,
    minWidth: 168,
    maxWidth: 380,
    defaultFloatWidth: 264,
    defaultFloatHeight: 272,
    minFloatHeight: 184,
  },
  'color-sets': {
    id: 'color-sets',
    title: 'Color Sets',
    shortTitle: 'Sets',
    defaultSide: 'right',
    defaultWidth: 224,
    minWidth: 96,
    maxWidth: 400,
    defaultFloatWidth: 248,
    defaultFloatHeight: 300,
    minFloatHeight: 150,
  },
  'color-history': {
    id: 'color-history',
    title: 'Color History',
    shortTitle: 'Recent',
    defaultSide: 'right',
    defaultWidth: 224,
    minWidth: 72,
    maxWidth: 380,
    defaultFloatWidth: 236,
    defaultFloatHeight: 240,
    minFloatHeight: 130,
  },
  layers: {
    id: 'layers',
    title: 'Layer',
    shortTitle: 'Layer',
    defaultSide: 'right',
    defaultWidth: 224,
    minWidth: 176,
    maxWidth: 380,
    defaultFloatWidth: 272,
    defaultFloatHeight: 420,
    minFloatHeight: 200,
  },
  history: {
    id: 'history',
    title: 'History',
    shortTitle: 'Hist',
    defaultSide: 'right',
    defaultWidth: 224,
    minWidth: 160,
    maxWidth: 340,
    defaultFloatWidth: 248,
    defaultFloatHeight: 320,
    minFloatHeight: 160,
  },
  'quick-access': {
    id: 'quick-access',
    title: 'Quick Access',
    shortTitle: 'Quick',
    defaultSide: 'right',
    defaultWidth: 184,
    minWidth: 136,
    maxWidth: 320,
    defaultFloatWidth: 228,
    defaultFloatHeight: 300,
    minFloatHeight: 150,
  },
  'auto-actions': {
    id: 'auto-actions',
    title: 'Auto Action',
    shortTitle: 'Actions',
    defaultSide: 'right',
    defaultWidth: 224,
    minWidth: 176,
    maxWidth: 360,
    defaultFloatWidth: 256,
    defaultFloatHeight: 310,
    minFloatHeight: 160,
  },
};

export interface CommandCatalogEntry {
  id: CommandActionId;
  label: string;
  shortLabel: string;
  shortcut?: string;
}

export const COMMAND_CATALOG: CommandCatalogEntry[] = [
  { id: 'save', label: 'Save', shortLabel: 'Save', shortcut: 'Ctrl+S' },
  { id: 'save-as', label: 'Save As', shortLabel: 'Save As', shortcut: 'Ctrl+Shift+S' },
  { id: 'undo', label: 'Undo', shortLabel: 'Undo', shortcut: 'Ctrl+Z' },
  { id: 'redo', label: 'Redo', shortLabel: 'Redo', shortcut: 'Ctrl+Y' },
  { id: 'flip-h', label: 'Flip Horizontal', shortLabel: 'Flip H', shortcut: 'Shift+H' },
  { id: 'flip-v', label: 'Flip Vertical', shortLabel: 'Flip V', shortcut: 'Shift+V' },
  { id: 'value-check', label: 'Value Check (Live B/W)', shortLabel: 'Value', shortcut: 'Shift+Y' },
  { id: 'clear-layer', label: 'Clear Layer', shortLabel: 'Clear' },
  { id: 'merge-down', label: 'Merge Down', shortLabel: 'Merge' },
  { id: 'new-layer', label: 'New Layer', shortLabel: 'New Lyr', shortcut: 'Ctrl+Shift+N' },
  { id: 'duplicate-layer', label: 'Duplicate Layer', shortLabel: 'Dup Lyr', shortcut: 'Ctrl+J' },
  { id: 'transform', label: 'Free Transform', shortLabel: 'Transf', shortcut: 'Ctrl+T' },
  { id: 'deselect', label: 'Deselect', shortLabel: 'Desel', shortcut: 'Ctrl+D' },
  { id: 'reset-zoom', label: 'Reset Zoom', shortLabel: 'Fit', shortcut: 'Ctrl+0' },
  { id: 'zoom-100', label: 'Reset Zoom to 100%', shortLabel: '100%', shortcut: 'Ctrl+1' },
  { id: 'reset-rotation', label: 'Reset Rotation', shortLabel: '0°', shortcut: 'Ctrl+Alt+0' },
  { id: 'swap-colors', label: 'Swap Colors', shortLabel: 'Swap', shortcut: 'X' },
  { id: 'transparent-ink', label: 'Transparent Ink', shortLabel: 'Transp', shortcut: 'C' },
  { id: 'eyedropper', label: 'Eyedropper', shortLabel: 'Pick', shortcut: 'I' },
  { id: 'selection', label: 'Lasso Selection', shortLabel: 'Select', shortcut: 'L' },
  { id: 'fullscreen', label: 'Toggle Fullscreen', shortLabel: 'Full', shortcut: 'F11' },
  { id: 'toggle-palettes', label: 'Focus Mode (Hide Palettes)', shortLabel: 'Focus', shortcut: 'Tab' },
  { id: 'toggle-quick-brushes', label: 'Quick Brush Panel', shortLabel: 'Brushes', shortcut: 'Shift+B' },
];

export const WORKSPACE_PRESET_LABELS: Record<WorkspacePresetId, string> = {
  'default-illustration': 'Default Illustration',
  'photoshop-studio': 'Photoshop Studio',
  'clip-studio': 'Clip Studio',
  'manga-studio': 'Manga Studio',
  'minimalist-tablet': 'Minimalist Tablet',
  custom: 'Custom',
};

export const WORKSPACE_PRESET_DESCRIPTIONS: Record<BuiltInWorkspacePresetId, string> = {
  'default-illustration': 'Balanced Atelier layout with brushes left & color/layers right',
  'photoshop-studio': 'Slim left tool rail, right Color/Brushes/Layers stack & top Options Bar',
  'clip-studio': 'Classic CSP SubTool / Property / Size left + Navigator / Color / Layers right',
  'manga-studio': 'Inking-first panels with dedicated Quick Access & Brush Size stack',
  'minimalist-tablet': 'Collapsed icon rails for maximum pen-display canvas space',
};