Your Name c7ffcda87b
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
feat: add infinite canvas feature with AI image generation
- Add canvas project and node database tables
- Create canvas workspace with drag, resize, zoom and pan
- Add ImageNode with background removal, enhance, extend, angle edit, scene fusion
- Add VideoNode with playback controls
- Add TextNode for text editing
- Integrate AI image generation API (Gemini/Alibaba)
- Implement viewport culling for performance optimization
- Add canvas entry in top navigation bar
2026-01-24 19:48:13 +08:00

163 lines
3.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 画布节点类型定义
export type NodeType = 'message' | 'image' | 'video' | 'text' | 'scene-fusion';
export type NodeStatus = 'pending' | 'generating' | 'completed' | 'failed';
export type ToolType = 'select' | 'pan' | 'draw' | 'text';
// 画布节点位置
export interface Position {
x: number;
y: number;
}
// 画布节点尺寸
export interface Size {
width: number;
height: number;
}
// 视口状态
export interface Viewport {
x: number;
y: number;
zoom: number;
}
// 消息节点数据
export interface MessageNodeData {
role: 'user' | 'assistant';
content: string;
attachments?: Attachment[];
}
// 图片节点数据
export interface ImageNodeData {
src: string;
prompt?: string;
model?: string;
status: NodeStatus;
metadata?: Record<string, any>;
// 图片编辑相关
originalSrc?: string;
editHistory?: ImageEditAction[];
}
// 视频节点数据
export interface VideoNodeData {
src: string;
thumbnail?: string;
prompt?: string;
model?: string;
status: NodeStatus;
duration?: number;
progress?: number; // 生成进度百分比
coverImage?: string; // 用于生成视频的封面图
}
// 文本节点数据
export interface TextNodeData {
content: string;
fontSize?: number;
color?: string;
fontWeight?: string;
}
// 场景裂变节点数据
export interface SceneFusionNodeData {
productImage: string;
backgroundImages: string[];
productName?: string;
results: string[];
status: NodeStatus;
}
// 画布节点
export interface CanvasNode {
id: string;
type: NodeType;
position: Position;
size: Size;
data: MessageNodeData | ImageNodeData | VideoNodeData | TextNodeData | SceneFusionNodeData;
connections: string[]; // 连接的节点 ID
parentId?: string; // 父节点 ID(用于对话上下文)
createdAt: Date;
updatedAt: Date;
}
// 画布连接线
export interface CanvasEdge {
id: string;
source: string;
target: string;
type?: 'default' | 'conversation' | 'reference';
}
// 画布状态
export interface CanvasState {
nodes: CanvasNode[];
edges: CanvasEdge[];
selectedNodeIds: string[];
viewport: Viewport;
tool: ToolType;
}
// 画布项目
export interface CanvasProject {
id: string;
userId: string;
title: string;
description?: string;
thumbnail?: string;
canvasData: CanvasState;
createdAt: Date;
updatedAt: Date;
}
// 附件类型
export interface Attachment {
type: 'image' | 'file';
url: string;
name?: string;
mimeType?: string;
}
// 图片编辑操作
export interface ImageEditAction {
type: 'rmbg' | 'enhance' | 'extend' | 'resize' | 'angle-edit' | 'scene-fusion' | 'annotate';
timestamp: Date;
params?: Record<string, any>;
resultUrl?: string;
}
// 图片操作菜单项
export interface ImageAction {
label: string;
action: string;
icon?: React.ComponentType<{ className?: string }>;
api?: string;
component?: React.ComponentType<any>;
tool?: string;
}
// AI 生成参数
export interface GenerationParams {
prompt: string;
model: string;
negativePrompt?: string;
size?: string;
style?: string;
referenceImage?: string;
// 图片生成特有
aspectRatio?: string;
// 视频生成特有
duration?: number;
fps?: number;
}
// API 响应类型
export interface CanvasApiResponse<T = any> {
success: boolean;
data?: T;
error?: string;
}