14 lines
1.2 KiB
TypeScript
14 lines
1.2 KiB
TypeScript
/**
|
|
* 将节点文本数据转换为React内联CSS的纯函数。统一卡片与纯文本的默认外观,不修改原数据或编辑状态。
|
|
*/
|
|
import type { CSSProperties } from "react";
|
|
import type { CanvasNodeData } from "@/lib/canvas-elements";
|
|
/** 字号优先data.fontSize,纯文本默认24、卡片默认13;布尔样式映射为明确的CSS值。
|
|
* 字体家族只识别serif/mono,其它继承外层;颜色、背景、对齐与行高使用各自默认值。
|
|
* 使用||回退,因此0和空字符串也走默认;这里是显示映射,不承担schema校验。 */
|
|
export function textAppearance(data: CanvasNodeData): CSSProperties {
|
|
const style = data.textStyle || {};
|
|
return { fontSize: data.fontSize || (data.kind === "plain-text" ? 24 : 13), color: style.color || "#37352f", fontWeight: style.bold ? 700 : 400, fontStyle: style.italic ? "italic" : "normal", textDecoration: style.underline ? "underline" : "none", textAlign: style.align || "left", lineHeight: style.lineHeight || 1.5,
|
|
fontFamily: style.fontFamily === "serif" ? 'Georgia, "Songti SC", serif' : style.fontFamily === "mono" ? 'ui-monospace, "SFMono-Regular", monospace' : "inherit", backgroundColor: style.background || "transparent" };
|
|
}
|