// 创建图片卡片的工厂函数
function createImageCard(
id: string,
src: string,
position: { x: number; y: number },
size: { width: number; height: number },
): Extract<CardData, { type: 'image' }> {
return {
id,
type: 'image',
src,
x: position.x,
y: position.y,
width: size.width,
height: size.height,
};
}
// 创建文本卡片的工厂函数
function createTextCard(
id: string,
text: string,
position: { x: number; y: number },
style: {
fontSize: number;
fontFamily: string;
color: string;
fontWeight?: string;
fontStyle?: 'normal' | 'italic';
decoration?: 'none' | 'underline' | 'line-through';
},
): Extract<CardData, { type: 'text' }> {
return {
id,
type: 'text',
text,
x: position.x,
y: position.y,
width: 300, // 默认宽度
height: 100, // 默认高度
fontSize: style.fontSize,
fontFamily: style.fontFamily,
color: style.color,
fontWeight: style.fontWeight || 'normal',
fontStyle: style.fontStyle || 'normal',
decoration: style.decoration || 'none',
};
}