Commit 3d9e99c4 by Lin

功能(d2c):更新依赖项并增强 Figma 集成

- 添加了 `@nuxtjs/tailwindcss` 并将其版本更新至 6.14.0。
- 在 pnpm-lock 和 workspace 文件中将 `nuxt` 版本更新至 3.21.4。
- 通过新的端点改进了 Figma API 集成以获取图片。
- 在 d2c 项目中引入了新的设计提示以提升前端美观度。
- 重构了 app.vue 以优化结构和一致性。
- 更新 package.json 以使用依赖项的目录引用。
- 在 .env.example 文件中添加了示例 Figma 令牌以增强功能。
1 parent 071ca81d
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# Figma(调用 Figma REST API 时必填) # Figma(调用 Figma REST API 时必填)
# 获取: Figma -> Settings -> Security -> Personal access tokens # 获取: Figma -> Settings -> Security -> Personal access tokens
# ============================================================ # ============================================================
FIGMA_PERSONAL_ACCESS_TOKEN= FIGMA_PERSONAL_ACCESS_TOKEN=figd_Cs0tDjz-UVojDvRlC2c-_4g5xR-hSwm7xP6kFzwd
# 或使用: NUXT_FIGMA_TOKEN= # 或使用: NUXT_FIGMA_TOKEN=
# ============================================================ # ============================================================
......
...@@ -11,13 +11,13 @@ ...@@ -11,13 +11,13 @@
"generate": "nuxt generate" "generate": "nuxt generate"
}, },
"dependencies": { "dependencies": {
"nuxt": "^3.15.0", "nuxt": "catalog:",
"vue": "^3.5.13", "vue": "catalog:",
"vue-router": "^4.5.0" "vue-router": "catalog:"
}, },
"devDependencies": { "devDependencies": {
"@nuxtjs/tailwindcss": "^6.12.2", "@nuxtjs/tailwindcss": "catalog:",
"typescript": "^5.7.2" "typescript": "catalog:"
}, },
"engines": { "engines": {
"node": ">=20.10.0" "node": ">=20.10.0"
......
---
name: frontend-design
description: Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
license: Complete terms in LICENSE.txt
---
This skill guides creation of distinctive, production-grade frontend interfaces that avoid generic "AI slop" aesthetics. Implement real working code with exceptional attention to aesthetic details and creative choices.
The user provides frontend requirements: a component, page, application, or interface to build. They may include context about the purpose, audience, or technical constraints.
## Design Thinking
Before coding, understand the context and commit to a BOLD aesthetic direction:
- **Purpose**: What problem does this interface solve? Who uses it?
- **Tone**: Pick an extreme: brutally minimal, maximalist chaos, retro-futuristic, organic/natural, luxury/refined, playful/toy-like, editorial/magazine, brutalist/raw, art deco/geometric, soft/pastel, industrial/utilitarian, etc. There are so many flavors to choose from. Use these for inspiration but design one that is true to the aesthetic direction.
- **Constraints**: Technical requirements (framework, performance, accessibility).
- **Differentiation**: What makes this UNFORGETTABLE? What's the one thing someone will remember?
**CRITICAL**: Choose a clear conceptual direction and execute it with precision. Bold maximalism and refined minimalism both work - the key is intentionality, not intensity.
Then implement working code (HTML/CSS/JS, React, Vue, etc.) that is:
- Production-grade and functional
- Visually striking and memorable
- Cohesive with a clear aesthetic point-of-view
- Meticulously refined in every detail
## Frontend Aesthetics Guidelines
Focus on:
- **Typography**: Choose fonts that are beautiful, unique, and interesting. Avoid generic fonts like Arial and Inter; opt instead for distinctive choices that elevate the frontend's aesthetics; unexpected, characterful font choices. Pair a distinctive display font with a refined body font.
- **Color & Theme**: Commit to a cohesive aesthetic. Use CSS variables for consistency. Dominant colors with sharp accents outperform timid, evenly-distributed palettes.
- **Motion**: Use animations for effects and micro-interactions. Prioritize CSS-only solutions for HTML. Use Motion library for React when available. Focus on high-impact moments: one well-orchestrated page load with staggered reveals (animation-delay) creates more delight than scattered micro-interactions. Use scroll-triggering and hover states that surprise.
- **Spatial Composition**: Unexpected layouts. Asymmetry. Overlap. Diagonal flow. Grid-breaking elements. Generous negative space OR controlled density.
- **Backgrounds & Visual Details**: Create atmosphere and depth rather than defaulting to solid colors. Add contextual effects and textures that match the overall aesthetic. Apply creative forms like gradient meshes, noise textures, geometric patterns, layered transparencies, dramatic shadows, decorative borders, custom cursors, and grain overlays.
NEVER use generic AI-generated aesthetics like overused font families (Inter, Roboto, Arial, system fonts), cliched color schemes (particularly purple gradients on white backgrounds), predictable layouts and component patterns, and cookie-cutter design that lacks context-specific character.
Interpret creatively and make unexpected choices that feel genuinely designed for the context. No design should be the same. Vary between light and dark themes, different fonts, different aesthetics. NEVER converge on common choices (Space Grotesk, for example) across generations.
**IMPORTANT**: Match implementation complexity to the aesthetic vision. Maximalist designs need elaborate code with extensive animations and effects. Minimalist or refined designs need restraint, precision, and careful attention to spacing, typography, and subtle details. Elegance comes from executing the vision well.
Remember: Claude is capable of extraordinary creative work. Don't hold back, show what can truly be created when thinking outside the box and committing fully to a distinctive vision.
import {
parseFigmaUrl,
resolveScreenshotNodeId,
fetchFigmaNodeImageUrl,
} from '../../utils/figmaParser'
/**
* POST /api/figma/image
* 使用 Figma REST:GET /v1/images/:fileKey?ids=:nodeId 获取节点 PNG(或其它格式)导出 URL。
*/
export default defineEventHandler(async (event) => {
const body = await readBody<{
figmaUrl?: string
scale?: number
format?: 'png' | 'jpg' | 'svg' | 'pdf'
}>(event)
const { figmaUrl, scale = 2, format = 'png' } = body ?? {}
if (!figmaUrl?.trim()) {
throw createError({ statusCode: 400, message: '请提供有效的 figmaUrl 参数' })
}
const config = useRuntimeConfig()
const token = config.figmaToken as string
if (!token) {
throw createError({
statusCode: 500,
message: '服务端未配置 FIGMA_PERSONAL_ACCESS_TOKEN,请在 .env 文件中设置',
})
}
try {
const { fileKey, nodeId } = parseFigmaUrl(figmaUrl.trim())
const renderNodeId = await resolveScreenshotNodeId(fileKey, token, nodeId)
const imageUrl = await fetchFigmaNodeImageUrl(fileKey, token, renderNodeId, {
format,
scale,
})
return {
imageUrl,
fileKey,
/** URL 查询中的节点(若有) */
figmaNodeIdFromUrl: nodeId,
/** 实际用于导出的节点 ID */
renderNodeId,
format,
scale,
}
} catch (err: unknown) {
const message = err instanceof Error ? err.message : '获取设计稿截图失败'
throw createError({ statusCode: 500, message })
}
})
...@@ -66,6 +66,79 @@ export async function fetchFigmaFile( ...@@ -66,6 +66,79 @@ export async function fetchFigmaFile(
} }
/** /**
* 解析用于导出的截图节点 ID(与 DSL 目标节点一致)。
* 未指定 URL 中的 node-id 时,取首页第一个子节点(整帧/画板级预览)。
*/
export async function resolveScreenshotNodeId(
fileKey: string,
token: string,
nodeId: string | null,
): Promise<string> {
if (nodeId) return nodeId
const figmaData = await fetchFigmaFile(fileKey, token, null)
const node = findTargetNode(figmaData, null)
if (!node?.id) {
throw new Error('无法解析截图节点:文件中未找到可用节点')
}
return node.id
}
export type FigmaImageFormat = 'png' | 'jpg' | 'svg' | 'pdf'
/**
* GET /v1/images/:fileKey?ids=:nodeId → 节点渲染图 URL(PNG 等)
* 大图异步导出时 images[id] 可能短暂为 null,会做有限次重试。
*/
export async function fetchFigmaNodeImageUrl(
fileKey: string,
token: string,
renderNodeId: string,
options?: { format?: FigmaImageFormat; scale?: number },
): Promise<string> {
const format = options?.format ?? 'png'
const scale = options?.scale ?? 2
const baseUrl = 'https://api.figma.com/v1'
const query = new URLSearchParams({
ids: renderNodeId,
format,
scale: String(scale),
})
const url = `${baseUrl}/images/${fileKey}?${query.toString()}`
const maxAttempts = 5
const delayMs = 1200
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
const res = await fetch(url, {
headers: { 'X-Figma-Token': token },
})
if (!res.ok) {
const errText = await res.text()
throw new Error(`Figma Images API 请求失败 (HTTP ${res.status}):${errText}`)
}
const data = (await res.json()) as {
err?: string | null
images?: Record<string, string | null>
}
if (data.err) {
throw new Error(`Figma Images API:${data.err}`)
}
const imageUrl = data.images?.[renderNodeId]
if (imageUrl) return imageUrl
if (attempt < maxAttempts) {
await new Promise(r => setTimeout(r, delayMs))
}
}
throw new Error('Figma 截图尚未就绪或导出失败,请稍后重试')
}
/**
* 将 Figma 原始节点转换为精简的 DSL 节点 * 将 Figma 原始节点转换为精简的 DSL 节点
* 去除噪声字段,保留布局/尺寸/颜色/文本/圆角等关键属性 * 去除噪声字段,保留布局/尺寸/颜色/文本/圆角等关键属性
*/ */
......
This diff could not be displayed because it is too large.
...@@ -21,6 +21,7 @@ packages: ...@@ -21,6 +21,7 @@ packages:
- scripts/**/* - scripts/**/*
- docs - docs
- example - example
- d2c
catalog: catalog:
"eslint-plugin-wxml": ^0.8.0 "eslint-plugin-wxml": ^0.8.0
...@@ -37,6 +38,7 @@ catalog: ...@@ -37,6 +38,7 @@ catalog:
"@iconify/json": ^2.2.354 "@iconify/json": ^2.2.354
"@iconify/tailwind": ^1.2.0 "@iconify/tailwind": ^1.2.0
"@manypkg/get-packages": ^3.0.0 "@manypkg/get-packages": ^3.0.0
"@nuxtjs/tailwindcss": ^6.12.2
"@playwright/test": ^1.53.2 "@playwright/test": ^1.53.2
"@stylistic/stylelint-plugin": ^3.1.3 "@stylistic/stylelint-plugin": ^3.1.3
"@tailwindcss/nesting": 0.0.0-insiders.565cd3e "@tailwindcss/nesting": 0.0.0-insiders.565cd3e
...@@ -102,6 +104,7 @@ catalog: ...@@ -102,6 +104,7 @@ catalog:
lefthook: ^1.11.14 lefthook: ^1.11.14
lucide-vue-next: ^0.507.0 lucide-vue-next: ^0.507.0
nprogress: ^0.2.0 nprogress: ^0.2.0
nuxt: ^3.15.0
ora: ^8.2.0 ora: ^8.2.0
pinia: ^3.0.3 pinia: ^3.0.3
pinia-plugin-persistedstate: ^4.4.1 pinia-plugin-persistedstate: ^4.4.1
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!