diff --git a/frontend/docs/artifact-zoom-feature.md b/frontend/docs/artifact-zoom-feature.md new file mode 100644 index 00000000..0c5393c8 --- /dev/null +++ b/frontend/docs/artifact-zoom-feature.md @@ -0,0 +1,149 @@ +# Artifact 缩放功能文档 + +## 功能概述 + +Artifact 缩放功能允许用户在预览 Markdown 和 HTML 内容时调整缩放比例(50% - 200%),提供更灵活的阅读体验。 + +## 文件结构 + +``` +frontend/src/ +├── components/ +│ └── workspace/ +│ └── artifacts/ +│ └── artifact-file-detail.tsx # 缩放组件定义与使用 +└── styles/ + └── globals.css # 缩放相关 CSS 变量 +``` + +## 核心实现 + +### 1. 缩放选择器组件 (`ArtifactZoomSelector`) + +**位置**: `artifact-file-detail.tsx` + +```tsx +// 缩放比例选项 +const ZOOM_LEVELS = [50, 60, 70, 80, 90, 100, 110, 120, 130, 150, 175, 200]; + +export const ArtifactZoomSelector = ({ + value = 100, + onChange, +}: ArtifactZoomSelectorProps) => { + // 放大/缩小逻辑 + // 返回: [ZoomOut图标] [百分比文本] [ZoomIn图标] +}; +``` + +**UI 设计**: +- 白色圆角容器,带轻微阴影和模糊效果 +- 水平三元素布局:缩小按钮 | 百分比显示 | 放大按钮 +- 支持深色模式 +- 边界值时按钮自动禁用 + +### 2. CSS 变量缩放 (`globals.css`) + +```css +/* 缩放变量,默认为 1 (100%) */ +:root { + --zoom-scale: 1; +} + +/* 字体大小使用 calc() 计算 */ +p { + font-size: calc(14px * var(--zoom-scale)); +} + +[data-streamdown="heading-1"] { + font-size: calc(20px * var(--zoom-scale)); +} + +[data-streamdown="heading-2"], +[data-streamdown="heading-3"] { + font-size: calc(16px * var(--zoom-scale)); +} +``` + +### 3. 预览组件集成 (`ArtifactFilePreview`) + +```tsx +export function ArtifactFilePreview({ + content, + language, + zoom = 100, +}: { + content: string; + language: string; + zoom?: number; +}) { + const zoomScale = zoom / 100; + + // Markdown: 使用 CSS 变量 + if (language === "markdown") { + return ( +
+ ... +
+ ); + } + + // HTML: 使用 CSS zoom 属性 + if (language === "html") { + return