diff --git a/apps/design-lab/README.md b/apps/design-lab/README.md new file mode 100644 index 0000000..5cbe56f --- /dev/null +++ b/apps/design-lab/README.md @@ -0,0 +1,27 @@ +# Personal Brand Design Lab + +Design Lab 是内部设计生产工具,用 `DesignSpec` 生成可预览、可校验的移动端 HTML 设计稿。 + +## 开发 + +```bash +pnpm --filter @personal-brand/design-lab dev +``` + +默认端口是 `3010`,可通过 `DESIGN_LAB_PORT` 覆盖。 + +## 验证 + +```bash +pnpm --filter @personal-brand/design-spec test +pnpm --filter @personal-brand/design-lab test +pnpm --filter @personal-brand/design-spec typecheck +pnpm --filter @personal-brand/design-lab typecheck +pnpm --filter @personal-brand/design-lab build +``` + +## 边界 + +- DesignSpec 是唯一源头。 +- HTML 是设计稿和转换依据,不直接进入线上项目。 +- Design Lab 不连接业务数据库,也不直接写入生产模板包。 diff --git a/apps/design-lab/index.html b/apps/design-lab/index.html new file mode 100644 index 0000000..ebdddc8 --- /dev/null +++ b/apps/design-lab/index.html @@ -0,0 +1,12 @@ + + + + + + Personal Brand Design Lab + + +
+ + + diff --git a/apps/design-lab/package.json b/apps/design-lab/package.json new file mode 100644 index 0000000..d732bee --- /dev/null +++ b/apps/design-lab/package.json @@ -0,0 +1,24 @@ +{ + "name": "@personal-brand/design-lab", + "private": true, + "type": "module", + "dependencies": { + "@personal-brand/design-spec": "workspace:*", + "react": "^19.3.0", + "react-dom": "^19.3.0" + }, + "scripts": { + "dev": "vite", + "build": "vite build", + "test": "node --experimental-strip-types --test test/*.test.mjs", + "lint": "eslint .", + "typecheck": "tsc -p tsconfig.json --noEmit", + "clean": "rimraf dist" + }, + "devDependencies": { + "@types/react": "^19.3.0", + "@types/react-dom": "^19.3.0", + "@vitejs/plugin-react": "^6.1.1", + "vite": "^8.3.0" + } +} diff --git a/apps/design-lab/src/App.css b/apps/design-lab/src/App.css new file mode 100644 index 0000000..76733fe --- /dev/null +++ b/apps/design-lab/src/App.css @@ -0,0 +1,74 @@ +:root { + font-family: system-ui, sans-serif; + color: #1f2328; + background: #f3f4f6; +} + +body { + margin: 0; +} + +.app { + display: grid; + grid-template-columns: minmax(360px, 34%) 1fr; + min-height: 100vh; +} + +.app aside { + display: flex; + flex-direction: column; + gap: 16px; + padding: 20px; + background: #ffffff; + border-right: 1px solid #e5e7eb; +} + +.app header { + display: flex; + align-items: center; + justify-content: space-between; +} + +textarea { + min-height: 420px; + resize: vertical; + border: 1px solid #d1d5db; + border-radius: 8px; + padding: 12px; + font-family: ui-monospace, monospace; + font-size: 13px; +} + +button { + border: 0; + border-radius: 8px; + background: #111827; + color: #ffffff; + font-size: 14px; + padding: 10px 16px; +} + +button:disabled { + background: #9ca3af; +} + +.errors { + margin: 0; + padding-left: 20px; + color: #dc2626; + font-size: 13px; +} + +main { + display: grid; + place-items: center; + padding: 32px; +} + +iframe { + width: 375px; + height: 720px; + border: 1px solid #d1d5db; + border-radius: 24px; + background: #ffffff; +} diff --git a/apps/design-lab/src/App.tsx b/apps/design-lab/src/App.tsx new file mode 100644 index 0000000..05a5235 --- /dev/null +++ b/apps/design-lab/src/App.tsx @@ -0,0 +1,57 @@ +import { useMemo, useState } from "react"; +import { + DESIGN_SPEC_VERSION, + renderDesignSpec, + validateDesignSpec, + type DesignSpec, +} from "@personal-brand/design-spec"; +import { sampleSpec } from "./samples"; +import "./App.css"; + +function App() { + const [specText, setSpecText] = useState(JSON.stringify(sampleSpec, null, 2)); + const [previewSrcDoc, setPreviewSrcDoc] = useState(() => renderDesignSpec(sampleSpec)); + + const parsed = useMemo(() => { + try { + return { value: JSON.parse(specText) as DesignSpec }; + } catch (error) { + return { error: error instanceof Error ? error.message : "JSON 解析失败" }; + } + }, [specText]); + const errors = "value" in parsed ? validateDesignSpec(parsed.value) : [parsed.error]; + + function handleRender() { + if (!("value" in parsed) || validateDesignSpec(parsed.value).length > 0) return; + setPreviewSrcDoc(renderDesignSpec(parsed.value)); + } + + return ( +
+