@melonbuild/create 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +72 -2
- package/SKILL.md +146 -0
- package/bin/create.mjs +143 -0
- package/package.json +44 -4
- package/references/ast.md +53 -0
- package/references/fidelity.md +82 -0
- package/scripts/mb.mjs +732 -0
- package/src/agents.mjs +55 -0
- package/src/install.mjs +116 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 鹅鹅鹅
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,73 @@
|
|
|
1
|
-
#
|
|
1
|
+
# MelonBuild Skill
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Turn Figma designs into production-ready code in any AI coding agent: structured DOM, real flex layouts, components and state merging, following your project's own conventions.
|
|
4
|
+
|
|
5
|
+
Website: [melonbuild.com](https://www.melonbuild.com) · [中文说明](#中文)
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Requires Node.js **22.15 or later**.
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm init @melonbuild
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The installer:
|
|
16
|
+
|
|
17
|
+
1. Detects the AI coding agents on your computer.
|
|
18
|
+
2. Installs the Skill into the shared `~/.agents/skills/melonbuild` folder, and into each detected agent's own skills folder when it doesn't read the shared one.
|
|
19
|
+
3. Signs you in to MelonBuild with your Figma account.
|
|
20
|
+
|
|
21
|
+
Run the same command again to update. Options (pass them after `--`, e.g. `npm init @melonbuild -- --project`):
|
|
22
|
+
|
|
23
|
+
| Option | What it does |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| `--project` | Install into the current project instead of your user folders |
|
|
26
|
+
| `--agents claude-code,cursor` | Install only for these agents, detected or not |
|
|
27
|
+
| `--all` | Install for every supported agent |
|
|
28
|
+
| `--dir <path>` | Install into a specific skills folder |
|
|
29
|
+
| `--list` | List supported agents and what was detected |
|
|
30
|
+
| `--no-login` | Skip signing in |
|
|
31
|
+
| `-y`, `--yes` | Don't ask for confirmation |
|
|
32
|
+
| `--uninstall` | Remove the MelonBuild Skill from every location |
|
|
33
|
+
|
|
34
|
+
You can also install straight from GitHub with any Agent Skills installer that reads `SKILL.md` from a repository.
|
|
35
|
+
|
|
36
|
+
## Supported agents
|
|
37
|
+
|
|
38
|
+
Claude Code, OpenAI Codex, Cursor, GitHub Copilot, Windsurf, Gemini CLI, Google Antigravity, OpenCode, Cline, Kilo Code, Augment, Amp, Factory Droid, Goose, JetBrains Junie, Zed, Warp, Kiro, Continue, Crush, Trae, Qoder, Trae CN, Lingma 通义灵码, CodeBuddy, Qwen Code, Kimi Code, Comate 文心快码, ZCode, JoyCode, MiniMax Code, CodeArts Agent and more.
|
|
39
|
+
|
|
40
|
+
Any other agent that supports Agent Skills and can run shell commands works too: copy `SKILL.md`, `references/` and `scripts/` into a `melonbuild` folder inside its skills directory.
|
|
41
|
+
|
|
42
|
+
To add an agent to the installer, add one entry to [`src/agents.mjs`](src/agents.mjs). Research notes and sources are in [`docs/agents-research.md`](docs/agents-research.md).
|
|
43
|
+
|
|
44
|
+
## Use
|
|
45
|
+
|
|
46
|
+
Share a Figma link with your agent and describe what you need:
|
|
47
|
+
|
|
48
|
+
```text
|
|
49
|
+
Use melonbuild to build this signup page: https://www.figma.com/design/FILEKEY/xxx?node-id=12-34
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Your agent fetches the structured design once through [`@melonbuild/cli`](https://www.npmjs.com/package/@melonbuild/cli), plans components and states, downloads only the images it needs and writes the code in your project's framework. Empty projects default to Vite + React + TypeScript + CSS Modules.
|
|
53
|
+
|
|
54
|
+
## Contents
|
|
55
|
+
|
|
56
|
+
- `SKILL.md` — how the agent works and the rules it must follow
|
|
57
|
+
- `references/` — AST structure and how style fields map to CSS
|
|
58
|
+
- `scripts/mb.mjs` — zero-dependency tool for querying the AST in small slices
|
|
59
|
+
- `bin/create.mjs`, `src/` — the installer
|
|
60
|
+
|
|
61
|
+
## 中文
|
|
62
|
+
|
|
63
|
+
在任何 AI 编程工具里,把 Figma 设计稿做成可上线的代码。安装:
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
npm init @melonbuild
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
安装程序会识别你电脑上的 AI 编程工具,把 Skill 装进每一个,并用 Figma 账号登录 MelonBuild。再次运行即可更新。选项需写在 `--` 之后,例如 `npm init @melonbuild -- --project`。完整使用指南见 [melonbuild.com/zh/docs](https://www.melonbuild.com/zh/docs)。
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
MIT
|
package/SKILL.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: melonbuild
|
|
3
|
+
description: 把 Figma 设计稿变成可直接合进项目的生产级代码:组件化、状态合并、真实交互、语义化、像素级还原,同时尽量少耗 token、尽量快。用户给出 Figma 链接要转代码/生码/还原页面/实现设计稿,或要基于设计稿开发功能、拆组件、分析页面结构与交互流程时使用。依赖 MelonBuild 命令行工具 @melonbuild/cli(获取 AST)和本 skill 自带的 scripts/mb.mjs(按需查询 AST)。Use when the user shares a Figma link and wants it built as code, implemented as a page or component, or analyzed for structure and interactions.
|
|
4
|
+
metadata:
|
|
5
|
+
version: 0.2.0
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# MelonBuild:把设计稿做成能上线的页面
|
|
9
|
+
|
|
10
|
+
## 你的角色
|
|
11
|
+
|
|
12
|
+
你是一位经验丰富的资深前端工程师。用户带着一份设计稿来找你完成需求,交出去的代码要达到能直接上线的质量。平时接到这样的活你会怎么做,这次就怎么做:
|
|
13
|
+
|
|
14
|
+
- **先把整份稿子看懂**:有哪些页面、哪些状态、页面之间怎么跳转,设计师想表达什么。
|
|
15
|
+
- **画面上的东西一丝不苟地还原**:颜色、尺寸、间距、字体、图片,设计师画成什么样就是什么样。
|
|
16
|
+
- **把画好的状态串成一个用起来顺畅的产品**:设计稿画的是一个个静止的状态,让每个状态在对的时机、对的地方出现,用的都是稿子里已有的东西。
|
|
17
|
+
- **发现稿子前后矛盾,或者拿不准设计师的意思,先问用户,不要自己猜**:用户代表设计和产品这一方。把问题攒到一起,动手前一次问清。
|
|
18
|
+
- **交出去的代码要能直接合进项目、长期维护**:一个界面一份代码,多个状态帧合并成同一份代码的不同状态,组件拆得合理,状态由数据驱动,跟随项目已有的约定。
|
|
19
|
+
|
|
20
|
+
MelonBuild 的 AST 和工具已经替你把设计稿整理好了:结构、样式、图片、各个状态都在里面,不用再去 Figma 里一点点量。下面的内容是这套工具的用法和必须守住的底线,不是做事清单;没说到的地方,照你的经验来。
|
|
21
|
+
|
|
22
|
+
`MB` 指本 skill 目录下的 `scripts/mb.mjs`(`node <skill目录>/scripts/mb.mjs`)。
|
|
23
|
+
|
|
24
|
+
`melonbuild` 指 MelonBuild 命令行工具。准备阶段确认它是否可用;不可用时,下文所有 `melonbuild …` 命令一律改用 `npx -y @melonbuild/cli@0 …`,不需要全局安装。
|
|
25
|
+
|
|
26
|
+
与用户沟通时使用用户的语言。
|
|
27
|
+
|
|
28
|
+
## 硬规则
|
|
29
|
+
|
|
30
|
+
1. **不读 AST 原文件。** AST 动辄几百 KB,一律通过 `MB` 查询:先 `outline`,再按需 `show` / `diff`。
|
|
31
|
+
2. **每个任务只取一次数**,产物落在 `.melonbuild/` 下。已有就复用;用户说设计改了才加 `--force-refresh`。
|
|
32
|
+
3. **每个模板只读一次**,读完写成组件;页面里的模板引用保持折叠,状态之间只看 `diff`。要一起看的东西一次读完:`show` 可以接多个目标,`--expand` 会把子组件内联展开,不要一个个分开调用。
|
|
33
|
+
4. **静态视觉以设计稿为准**:AST 写了什么就还原什么,设计稿里没有的视觉样式(圆角、阴影等)不凭空添加。字段怎么落 CSS 见 [references/fidelity.md](references/fidelity.md);第一次写样式前读一遍。
|
|
34
|
+
5. **代码由你逐个组件判断后手写。** 脚本只用来取数、查询、核对,不用脚本批量生成页面代码。
|
|
35
|
+
6. **已有项目跟随项目,新项目用默认方案。** 已有项目:框架、样式方案、组件库、数据层与 mock 方案、目录结构、命名、lint 规则都以现状为准,项目没有的依赖不擅自引入,只改这次需要改的代码。新项目或空目录:用下文的默认方案。
|
|
36
|
+
|
|
37
|
+
## 工作流
|
|
38
|
+
|
|
39
|
+
### 1. 准备(并行做)
|
|
40
|
+
|
|
41
|
+
- CLI:`melonbuild --version`;找不到命令时改用 `npx -y @melonbuild/cli@0`(见上文),不要擅自全局安装。
|
|
42
|
+
- 登录:`melonbuild whoami --json`。退出码 2 表示未登录,请用户自己在终端运行 `npx -y @melonbuild/cli@0 login`(要在浏览器里确认),不要替用户操作。
|
|
43
|
+
- 已有项目:读 `package.json`、样式方案(Tailwind / CSS Modules / styled / Less…)、组件库、已有的 token 或主题文件、接口层和 mock 方案、组件和资源目录约定。
|
|
44
|
+
- 新项目或空目录:先搭好骨架,默认 Vite + React + TypeScript + CSS Modules。安装依赖放到后台,和取数、规划同时进行,不要干等。
|
|
45
|
+
|
|
46
|
+
### 2. 取数(先只拿结构)
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
melonbuild node-ast "<Figma链接>" --reuse components -q -o .melonbuild/<模块名>.remote.json
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`<模块名>` 用英文短横线形式的功能名(如 `dating`)。这一步不下载图片,AST 里是图片的远程链接,等第 3 步确定实现范围后再下载。
|
|
53
|
+
|
|
54
|
+
- `--reuse components` 最贴近真实组件:`Cn` 是组件候选,`Sn` 是屏幕外壳,参数、变体、插槽都已抽好。
|
|
55
|
+
- 多页、整个画板时拉**一次全量**,不要逐页拉:跨页复用的组件只有在同一份 AST 里才能识别出来。
|
|
56
|
+
- 照片需要更高清时加 `--image-scale 2`。
|
|
57
|
+
- 退出码:3 表示额度或体积超限,告诉用户原因和订阅链接;429 限流时把 CLI 给出的原因原样转告用户。
|
|
58
|
+
- 建议把 `.melonbuild/` 加进 `.gitignore`。
|
|
59
|
+
|
|
60
|
+
### 3. 规划(只用 outline 和 tokens,先不 show)
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
node MB outline .melonbuild/<模块名>.remote.json # 分区、状态组与基准帧、同名组件、宿主外观、组件排行、连线、注释
|
|
64
|
+
node MB tokens .melonbuild/<模块名>.remote.json # 颜色 / 字体 / 圆角 / 间距 / 阴影,开头会提示倍率
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
outline 先把这些归纳好了,用它来规划:
|
|
68
|
+
|
|
69
|
+
| outline 里的 | 意思 | 怎么用 |
|
|
70
|
+
|---|---|---|
|
|
71
|
+
| `REGION <名称>` / `[<行标题>]` | 画布上的分区(大背景圈出的范围)和其中的一排屏幕 | 只实现正式分区里的屏幕 |
|
|
72
|
+
| `REGION ⚠ 不在任何分区里` | 可能是旧稿、备选方案或附件 | 规划时问用户是否需要 |
|
|
73
|
+
| `state groups` 的 `base=` | 同一界面的不同状态,以及写代码时的基准帧 | 先 show 基准帧,再处理其它帧 |
|
|
74
|
+
| `diff 对比:` / `单独 show:` | 和基准结构相近 / 差异大 | 前者 `diff <base> <id>`,后者单独 `show` |
|
|
75
|
+
| `same name, drawn differently` | 同一个组件被画成了好几版 | 设计稿里的每一版都要实现,做成 variant,由数据或 props 选择;用 `diff <base> <other>` 看各版差异 |
|
|
76
|
+
| `host chrome` | 状态栏、小程序胶囊等运行环境外观 | 照设计稿实现,单独封装成宿主外观组件,和页面内容分开(接入真实宿主时可以整体去掉) |
|
|
77
|
+
| `notes (requirements)` | 设计师写的需求注释 | 当作需求实现 |
|
|
78
|
+
| `small parts` 里的规则说明帧(如「8个字以上 小字号」) | 逻辑规格 | 落成代码里的规则,不是独立组件 |
|
|
79
|
+
|
|
80
|
+
在回复里用几行写出规划(页面与路由、每组状态由什么驱动、组件清单与命名、token、尺寸策略)。有要问用户的问题,和规划一起提出来,等用户回答后再开工;没有就直接开工。
|
|
81
|
+
|
|
82
|
+
- **组件**:按 outline 的组件排行给 `Cn` 起语义化名称;`same skeleton` 里的几个模板合并成一个组件加 variant;能用项目已有组件或组件库的直接用。
|
|
83
|
+
- **token**:按 tokens 开头的提示换算倍率。
|
|
84
|
+
- **尺寸策略**:页面宽度和页面这一级的文档流,见 fidelity.md 的「生产化调整」。
|
|
85
|
+
|
|
86
|
+
**下载图片**:范围一定就下,之后所有 `show` / `diff` 都在本地 AST 上做,图片显示为文件名,可以直接 import。
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
node MB subset .melonbuild/<模块名>.remote.json <要实现的单元id…> -o .melonbuild/<模块名>.scope.json
|
|
90
|
+
melonbuild download-images .melonbuild/<模块名>.scope.json -q \
|
|
91
|
+
--image-dir <项目资源目录>/<模块名> --output .melonbuild/<模块名>.json
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
- 图片按 Figma 图层命名,内容相同的只存一份。`show` 只显示文件名,文件都在 `--image-dir` 目录里;写 import 时用项目别名或相对组件文件的路径(如 `@/assets/dating/icon-定位-3637b8db.svg`)。
|
|
95
|
+
- 退出码 4 表示部分图片失败,按提示重跑 `download-images` 补下载,不会重新生成。
|
|
96
|
+
|
|
97
|
+
### 4. 实现(自底向上)
|
|
98
|
+
|
|
99
|
+
1. **token**:写进项目已有的主题或变量文件,没有就新建 CSS 变量文件。
|
|
100
|
+
2. **组件**:`node MB show <ast> C16 --expand` 一次看到组件和它内部的子组件;几个相关组件用 `node MB show <ast> C2 C3 C9` 一起读,样式块只输出一次。写组件时,props 来自 `params`,按内容起名,不用 `text1` 这类名字;`variants` 对应 variant 或布尔 props;`slotN` 对应 children 或具名插槽。
|
|
101
|
+
3. **页面**:先选一个最完整的状态作为基准,`node MB show <ast> <单元id> --depth 4` 浏览,`node MB show <ast> <路径>` 下钻局部;同组的其他状态用 `node MB diff <ast> <基准> <状态>` 只看差异,不要整屏重读。
|
|
102
|
+
4. **交互**:连线、注释、状态差异落成事件、状态和路由(见下文)。
|
|
103
|
+
5. 写完一个文件就继续下一个,不回读刚写的文件。
|
|
104
|
+
|
|
105
|
+
### 5. 验证
|
|
106
|
+
|
|
107
|
+
- 运行项目自己的 typecheck / lint / build,这次新增和修改的代码要全部通过;项目原有的报错不去改,在汇报里列出。
|
|
108
|
+
- `node MB check <ast> src --unit <单元id>`:检查文案和图片是否都已落进代码。缺失项逐条判断:拼接出来的文案(`292人已报名`)、CSS 截断的文案都属于正常情况。
|
|
109
|
+
- `node MB prune .melonbuild/<模块名>.json src --apply`:删掉这次下载、但代码没用到的图片(没实现的状态),资源目录里原有的文件不受影响。
|
|
110
|
+
|
|
111
|
+
## 状态合并(核心)
|
|
112
|
+
|
|
113
|
+
设计稿习惯把一个界面画成多帧:默认、hover、选中、展开、空态、加载、报错、弹窗、步骤 1/2/3。**它们是同一份代码的不同状态,不能生成多个页面。**
|
|
114
|
+
|
|
115
|
+
**识别信号**:
|
|
116
|
+
- outline 里的 `≈gN` 分组(同前缀的帧名、结构相似、同一个 `Sn` 外壳)和 `~` 相似提示;
|
|
117
|
+
- 帧名带 hover、选中、空、骨架、loading、加载中、失败、到底、刷新、展开、step;
|
|
118
|
+
- 连线(`点击X → 某帧`);
|
|
119
|
+
- 设计师注释(outline 的 `notes (requirements):`,如「hover 时…」「点击后…」)。注释就是需求,要实现。
|
|
120
|
+
|
|
121
|
+
**数据与预览**:每个状态都要能由数据驱动出来,不能做成多个页面。已有项目接入它的接口层和 mock 方案,mock 覆盖到各个场景。新项目把数据放进类型化的 mock 文件(如 `xxx.mock.ts`),由 mock 层按 URL 参数返回对应场景(如 `?mock=empty`),方便逐个预览;页面代码本身不知道自己处在预览中。
|
|
122
|
+
|
|
123
|
+
**状态差异的含义**:
|
|
124
|
+
|
|
125
|
+
| diff 结果 | 意味着什么 |
|
|
126
|
+
|---|---|
|
|
127
|
+
| `+` / `-` 子树 | 这块内容只在某些状态下出现 |
|
|
128
|
+
| `~ fills` / `strokes` / `fontStyle` | 同一个元素的样式随状态变化 |
|
|
129
|
+
| `~ text` / `src` | 内容不同,来自数据 |
|
|
130
|
+
| `~ variant` / `~ <参数> (<作用的图层>)` | 同一组件的不同变体或参数;两边都是最终生效的值 |
|
|
131
|
+
| 尺寸 / 位置变化 | 布局随内容或状态变化 |
|
|
132
|
+
|
|
133
|
+
## 读懂这些数据
|
|
134
|
+
|
|
135
|
+
- `Cn` 是组件候选,`Sn` 是页面或区块外壳,`Tn` 只是压缩片段,展开写即可。
|
|
136
|
+
- 连线 `from --label--> to`:label 是触发条件,`to` 是目标;目标是另一屏就是页面跳转,是同屏的状态就是状态切换。
|
|
137
|
+
- 布局结构以 AST 为准:没有任何样式的纯包裹层可以去掉,承载 layout、fills、strokes、effects 的节点要保留。
|
|
138
|
+
|
|
139
|
+
## 大稿提速
|
|
140
|
+
|
|
141
|
+
界面超过 5 个时:先完成 token 和共享组件,再按界面分批实现。环境支持子 agent 时,可以把每个界面交给一个子 agent 并行写,交接内容包括 AST 路径、单元 id 和状态组、已有组件清单及其 props、token 文件路径、`MB` 用法和本 skill 的硬规则。
|
|
142
|
+
|
|
143
|
+
## 参考
|
|
144
|
+
|
|
145
|
+
- [references/ast.md](references/ast.md):AST 结构、模板与参数、连线、SECTION、MASK。读不懂 `show` 的输出时看。
|
|
146
|
+
- [references/fidelity.md](references/fidelity.md):五类样式逐字段落 CSS 的规则和常见陷阱。写样式前读。
|
package/bin/create.mjs
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// npm init @melonbuild — installs the MelonBuild Skill into every AI coding agent on this computer
|
|
3
|
+
// and signs in to MelonBuild.
|
|
4
|
+
import {readFileSync} from 'node:fs';
|
|
5
|
+
import {homedir} from 'node:os';
|
|
6
|
+
import {dirname,join,resolve} from 'node:path';
|
|
7
|
+
import {fileURLToPath} from 'node:url';
|
|
8
|
+
import {spawnSync} from 'node:child_process';
|
|
9
|
+
import {createInterface} from 'node:readline/promises';
|
|
10
|
+
import {AGENTS} from '../src/agents.mjs';
|
|
11
|
+
import {detect,install,plan,uninstall} from '../src/install.mjs';
|
|
12
|
+
|
|
13
|
+
const source=resolve(dirname(fileURLToPath(import.meta.url)),'..');
|
|
14
|
+
const version=JSON.parse(readFileSync(join(source,'package.json'),'utf8')).version;
|
|
15
|
+
const CLI_PACKAGE='@melonbuild/cli@0';
|
|
16
|
+
const zh=/^zh/i.test(process.env.LC_ALL||process.env.LC_MESSAGES||process.env.LANG||Intl.DateTimeFormat().resolvedOptions().locale||'');
|
|
17
|
+
const M=zh?{
|
|
18
|
+
title:`MelonBuild Skill ${version}`,
|
|
19
|
+
usage:`用法:npm init @melonbuild [-- 选项]
|
|
20
|
+
|
|
21
|
+
(无选项) 检测本机的 AI 编程工具,把 Skill 装进每一个并登录
|
|
22
|
+
--project 装到当前项目(.agents/skills 及各工具的项目目录)
|
|
23
|
+
--agents <id,...> 只装到指定工具(不论是否检测到),id 见 --list
|
|
24
|
+
--all 装到清单里的全部工具
|
|
25
|
+
--dir <目录> 装到指定的 skills 目录下
|
|
26
|
+
--list 列出支持的工具及检测结果
|
|
27
|
+
--no-login 跳过登录
|
|
28
|
+
-y, --yes 不询问,直接安装
|
|
29
|
+
--uninstall 从所有位置移除 MelonBuild Skill(加 --project 同时清理当前项目)
|
|
30
|
+
-h, --help 显示帮助`,
|
|
31
|
+
node:v=>`需要 Node.js 22.15 或更高版本,当前为 ${v}。请先升级 Node.js:https://nodejs.org`,
|
|
32
|
+
found:n=>`检测到 ${n} 个 AI 编程工具:`,none:'没有检测到已知的 AI 编程工具,将安装到共享目录 ~/.agents/skills(Codex、Copilot、Gemini CLI、OpenCode 等会读取)。',
|
|
33
|
+
where:'将安装到:',confirm:'继续安装?(Y/n) ',cancelled:'已取消。',
|
|
34
|
+
installed:'已安装',updated:'已更新',skipped:'已跳过',exists:'目录已存在且不是 MelonBuild Skill,未改动',
|
|
35
|
+
unknown:id=>`未知的工具 id:${id}。运行 npm init @melonbuild -- --list 查看全部。`,
|
|
36
|
+
listHead:'支持的工具(✓ 表示本机已检测到):',
|
|
37
|
+
checking:'正在检查 MelonBuild 登录状态…',signedIn:name=>`已登录:${name}`,loginAsk:'现在用 Figma 账号登录 MelonBuild?(Y/n) ',
|
|
38
|
+
loginLater:'稍后可运行:npx -y @melonbuild/cli login',cliFailed:'无法运行 MelonBuild 命令行工具,请检查网络后重试:npx -y @melonbuild/cli login',
|
|
39
|
+
done:'完成!重启你的 AI 工具,然后发送 Figma 链接,例如:',
|
|
40
|
+
prompt:'用 melonbuild 把这个设计稿实现成可上线的页面:https://www.figma.com/design/FILEKEY/xxx?node-id=12-34',
|
|
41
|
+
docs:'使用指南:https://www.melonbuild.com/zh/docs',
|
|
42
|
+
removed:n=>n?`已移除 ${n} 处 MelonBuild Skill:`:'没有找到已安装的 MelonBuild Skill。',
|
|
43
|
+
}:{
|
|
44
|
+
title:`MelonBuild Skill ${version}`,
|
|
45
|
+
usage:`Usage: npm init @melonbuild [-- options]
|
|
46
|
+
|
|
47
|
+
(no options) Detect AI coding agents on this computer, install the Skill into each, and sign in
|
|
48
|
+
--project Install into the current project (.agents/skills and each agent's project folder)
|
|
49
|
+
--agents <id,...> Install only for these agents (detected or not); see --list for ids
|
|
50
|
+
--all Install for every agent in the registry
|
|
51
|
+
--dir <path> Install into this skills directory
|
|
52
|
+
--list List supported agents and what was detected
|
|
53
|
+
--no-login Skip signing in
|
|
54
|
+
-y, --yes Don't ask for confirmation
|
|
55
|
+
--uninstall Remove the MelonBuild Skill everywhere (add --project to include this project)
|
|
56
|
+
-h, --help Show this help`,
|
|
57
|
+
node:v=>`MelonBuild needs Node.js 22.15 or later (found ${v}). Please upgrade: https://nodejs.org`,
|
|
58
|
+
found:n=>`Found ${n} AI coding agent${n===1?'':'s'}:`,none:'No known AI coding agent found. Installing into the shared ~/.agents/skills folder (read by Codex, Copilot, Gemini CLI, OpenCode and others).',
|
|
59
|
+
where:'Install locations:',confirm:'Continue? (Y/n) ',cancelled:'Cancelled.',
|
|
60
|
+
installed:'installed',updated:'updated',skipped:'skipped',exists:'folder exists and is not the MelonBuild Skill; left unchanged',
|
|
61
|
+
unknown:id=>`Unknown agent id: ${id}. Run npm init @melonbuild -- --list to see all.`,
|
|
62
|
+
listHead:'Supported agents (✓ = detected on this computer):',
|
|
63
|
+
checking:'Checking your MelonBuild sign-in…',signedIn:name=>`Signed in as ${name}`,loginAsk:'Sign in to MelonBuild with Figma now? (Y/n) ',
|
|
64
|
+
loginLater:'You can sign in later: npx -y @melonbuild/cli login',cliFailed:'Could not run the MelonBuild command-line tool. Check your network, then run: npx -y @melonbuild/cli login',
|
|
65
|
+
done:'Done! Restart your AI agent, then share a Figma link, for example:',
|
|
66
|
+
prompt:'Use melonbuild to build this design as production-ready code: https://www.figma.com/design/FILEKEY/xxx?node-id=12-34',
|
|
67
|
+
docs:'Guide: https://www.melonbuild.com/docs',
|
|
68
|
+
removed:n=>n?`Removed the MelonBuild Skill from ${n} location${n===1?'':'s'}:`:'No installed MelonBuild Skill found.',
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
function parse(argv) {
|
|
72
|
+
const o={project:false,all:false,list:false,login:true,yes:false,uninstall:false,help:false,agents:null,dir:null};
|
|
73
|
+
for(let i=0;i<argv.length;i++) {
|
|
74
|
+
const a=argv[i];
|
|
75
|
+
if(a==='--project')o.project=true;else if(a==='--all')o.all=true;else if(a==='--list')o.list=true;
|
|
76
|
+
else if(a==='--no-login')o.login=false;else if(a==='-y'||a==='--yes')o.yes=true;else if(a==='--uninstall')o.uninstall=true;
|
|
77
|
+
else if(a==='-h'||a==='--help')o.help=true;
|
|
78
|
+
else if(a==='--agents'||a.startsWith('--agents=')){o.agents=(a.includes('=')?a.split('=')[1]:argv[++i]??'').split(',').map(s=>s.trim()).filter(Boolean);}
|
|
79
|
+
else if(a==='--dir'||a.startsWith('--dir=')){o.dir=a.includes('=')?a.split('=')[1]:argv[++i];}
|
|
80
|
+
else throw new Error((zh?'未知参数:':'Unknown option: ')+a+'\n\n'+M.usage);
|
|
81
|
+
}
|
|
82
|
+
return o;
|
|
83
|
+
}
|
|
84
|
+
async function ask(question) {
|
|
85
|
+
if(!process.stdin.isTTY)return true;
|
|
86
|
+
const rl=createInterface({input:process.stdin,output:process.stdout});
|
|
87
|
+
try{return !/^n/i.test((await rl.question(question)).trim());}finally{rl.close();}
|
|
88
|
+
}
|
|
89
|
+
const home=(p)=>p.startsWith(homedir())?'~'+p.slice(homedir().length):p;
|
|
90
|
+
|
|
91
|
+
/** Runs the MelonBuild CLI: a global `melonbuild` if present, otherwise npx. */
|
|
92
|
+
function cli(args,stdio) {
|
|
93
|
+
const win=process.platform==='win32';
|
|
94
|
+
const local=spawnSync(win?'melonbuild.cmd':'melonbuild',['--version'],{encoding:'utf8',shell:win});
|
|
95
|
+
const [cmd,base]=local.status===0?[win?'melonbuild.cmd':'melonbuild',[]]:[win?'npx.cmd':'npx',['-y',CLI_PACKAGE]];
|
|
96
|
+
return spawnSync(cmd,[...base,...args],{stdio,encoding:'utf8',shell:win});
|
|
97
|
+
}
|
|
98
|
+
async function signIn(yes) {
|
|
99
|
+
console.log('\n'+M.checking);
|
|
100
|
+
const who=cli(['whoami','--json'],['ignore','pipe','pipe']);
|
|
101
|
+
if(who.status===0){let name='';try{const d=JSON.parse(who.stdout);name=d.actor?.displayName??'';}catch{}console.log(M.signedIn(name||'✓'));return;}
|
|
102
|
+
if(who.status!==2){let detail='';try{detail=JSON.parse(who.stdout).error?.message??'';}catch{}console.log(M.cliFailed+(detail?'\n '+detail:''));return;}
|
|
103
|
+
// Signing in needs a person at the browser; never start it from scripts or CI.
|
|
104
|
+
if(!process.stdin.isTTY||(!yes&&!(await ask(M.loginAsk)))){console.log(M.loginLater);return;}
|
|
105
|
+
const login=cli(['login'],'inherit');
|
|
106
|
+
if(login.status!==0)console.log(M.loginLater);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function main() {
|
|
110
|
+
const o=parse(process.argv.slice(2));
|
|
111
|
+
console.log(M.title+'\n');
|
|
112
|
+
if(o.help){console.log(M.usage);return;}
|
|
113
|
+
const [major,minor]=process.versions.node.split('.').map(Number);
|
|
114
|
+
if(major<22||(major===22&&minor<15)){console.error(M.node(process.versions.node));process.exitCode=1;return;}
|
|
115
|
+
const ctx={home:homedir(),env:process.env,platform:process.platform,cwd:process.cwd()};
|
|
116
|
+
if(o.uninstall){const removed=uninstall(ctx,{project:o.project});console.log(M.removed(removed.length));for(const r of removed)console.log(' '+home(r));return;}
|
|
117
|
+
const found=detect(ctx);
|
|
118
|
+
if(o.list){console.log(M.listHead);for(const a of AGENTS)console.log(` ${found.includes(a)?'✓':' '} ${a.id.padEnd(16)} ${a.name}`);return;}
|
|
119
|
+
|
|
120
|
+
let selected=found,targets;
|
|
121
|
+
if(o.dir)targets=[{dir:resolve(o.dir),agents:[]}];
|
|
122
|
+
else {
|
|
123
|
+
if(o.all)selected=AGENTS;
|
|
124
|
+
else if(o.agents) {
|
|
125
|
+
const bad=o.agents.find(id=>!AGENTS.some(a=>a.id===id));
|
|
126
|
+
if(bad)throw new Error(M.unknown(bad));
|
|
127
|
+
selected=AGENTS.filter(a=>o.agents.includes(a.id));
|
|
128
|
+
}
|
|
129
|
+
console.log(selected.length?M.found(selected.length)+' '+selected.map(a=>a.name).join(', '):M.none);
|
|
130
|
+
targets=plan(selected,ctx,{project:o.project});
|
|
131
|
+
}
|
|
132
|
+
console.log('\n'+M.where);
|
|
133
|
+
for(const t of targets)console.log(` ${home(join(t.dir,'melonbuild'))}${t.agents.length?' ('+t.agents.join(', ')+')':''}`);
|
|
134
|
+
if(!o.yes&&!(await ask('\n'+M.confirm))){console.log(M.cancelled);return;}
|
|
135
|
+
|
|
136
|
+
const results=install(targets,source);
|
|
137
|
+
console.log('');
|
|
138
|
+
for(const r of results)console.log(` ${r.status==='skipped'?'!':'✓'} ${home(r.dest)} — ${M[r.status]}${r.reason==='exists'?' ('+M.exists+')':r.reason?' ('+r.reason+')':''}`);
|
|
139
|
+
if(results.every(r=>r.status==='skipped')){process.exitCode=1;return;}
|
|
140
|
+
if(o.login)await signIn(o.yes);
|
|
141
|
+
console.log('\n'+M.done+'\n\n '+M.prompt+'\n\n'+M.docs);
|
|
142
|
+
}
|
|
143
|
+
main().catch(e=>{console.error(e?.message??e);process.exitCode=1;});
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@melonbuild/create",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Install the MelonBuild Skill into every AI coding agent on your computer: npm init @melonbuild",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"create": "bin/create.mjs"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"src",
|
|
12
|
+
"SKILL.md",
|
|
13
|
+
"references",
|
|
14
|
+
"scripts",
|
|
15
|
+
"README.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=22.15.0"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"figma",
|
|
23
|
+
"design-to-code",
|
|
24
|
+
"agent-skills",
|
|
25
|
+
"skill",
|
|
26
|
+
"claude-code",
|
|
27
|
+
"codex",
|
|
28
|
+
"cursor",
|
|
29
|
+
"qoder",
|
|
30
|
+
"trae",
|
|
31
|
+
"melonbuild"
|
|
32
|
+
],
|
|
33
|
+
"homepage": "https://www.melonbuild.com",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/1977474741/melonbuild-skill.git"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"registry": "https://registry.npmjs.org/",
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"scripts": {
|
|
44
|
+
"test": "node --test test/*.test.mjs"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# AST 结构
|
|
2
|
+
|
|
3
|
+
`node-ast` 输出紧凑 JSON:`{name, fileKey, connectors?, nodes, templates, globalStyles}`。所有查询都通过 `mb.mjs` 完成,本文只说明它输出的东西是什么意思。
|
|
4
|
+
|
|
5
|
+
## 节点
|
|
6
|
+
|
|
7
|
+
`{tag, id?, name?, text?, children?, ...属性}`。`tag` 是 Figma 类型,全大写:
|
|
8
|
+
|
|
9
|
+
| tag | 含义 / 落点 |
|
|
10
|
+
|---|---|
|
|
11
|
+
| FRAME / GROUP / INSTANCE / COMPONENT | 容器。没有名字的 FRAME 是纯布局的行或列,照 layout 写成 div |
|
|
12
|
+
| SECTION | 画板。大画板的子节点是一个个相互独立的界面;屏幕大小的 SECTION 本身就是一屏,子节点是这一屏的部件(导航栏、列表、tab 栏) |
|
|
13
|
+
| TEXT | 文本,内容在 `text` |
|
|
14
|
+
| RECTANGLE / ELLIPSE / LINE | 用 CSS 画的形状或装饰层 |
|
|
15
|
+
| IMAGE-SVG | 整张导出的图片叶子,用 `<img src>`。它不带 fills、strokes、effects、opacity、圆角;不要给它额外套包裹层,但 AST 里本来就有的外层盒子要保留。显示尺寸一律取节点的 `width` / `height`:图片文件按导出倍率渲染,像素尺寸是它的整数倍(2 倍稿里 375×64 的节点,文件是 750×128),不能拿文件尺寸推断它占多宽 |
|
|
16
|
+
| IMAGE-BG | 旋转、裁切或模糊过的背景图:外层容器 absolute + `pointer-events:none`,内部的 `<img>` 子节点承载 src,其 layout 字段原样照抄 |
|
|
17
|
+
| MASK | 少见。裁剪原语(`path` 用于 clip-path),不是图片 |
|
|
18
|
+
|
|
19
|
+
**节点上的内联属性**(实例级):`width`、`height`、`borderRadius`、`inset`、`locationRelativeToParent{x,y}`(absolute 定位的 left/top)、`marginLeft` / `marginTop` / `marginRight` / `marginBottom`(流里的位置:不等的间距、偏移,照写成 margin)、`opacity`、`rotate`、`matrix`、`strokeFit`、`scrollTop`/`scrollLeft`、`src`、`canvasXY`(画布坐标,只用于排布画板;节点本身是内容撑开、没有 width/height 时,这里会带上设计稿上的宽高,供判断屏宽参考)。
|
|
20
|
+
|
|
21
|
+
**`opacity:0` 的节点**是占位盒子(常叫 Spacing),要保留,不要改写成 margin。
|
|
22
|
+
|
|
23
|
+
**五类样式引用**:`layout`、`fills`、`fontStyle`、`strokes`、`effects` 的值是 `globalStyles` 里的 key。`mb show` 会在输出末尾的 `styles:` 段列出解析好的值(`extends` 已合并)。
|
|
24
|
+
|
|
25
|
+
## 模板(`--reuse components`)
|
|
26
|
+
|
|
27
|
+
- 实例:`{t:"C2", id?, args?, children?}`。`children` 只会是插槽 `{tag:"slotN", children}`。
|
|
28
|
+
- 模板:`templates.C2 = {body, params?, variants?, uses}`。
|
|
29
|
+
- body 里的 `{"$param":"text1"}` 是占位符,`mb show` 里显示为 `{text1}`。
|
|
30
|
+
- 展开顺序:取 `params` 默认值 → 用 `variants[args.variant]` 覆盖 → 用实例 `args` 覆盖。值为 `null` 表示该属性不存在:比如位置参数为 null,就是这个实例没有绝对定位,按父容器的排布摆放。
|
|
31
|
+
- 参数名按类型编号(`text1`、`src1`、`width1`、`pos1`、`fills1`、`layout1`…),没有业务含义,封装时要按内容重新起名。
|
|
32
|
+
- 多个属性一起变化时会收成一个 variant,通常对应组件状态(选中、禁用、成功、失败)。
|
|
33
|
+
- `slotN` 是插槽位置,实例传入的节点就是该容器的子节点。
|
|
34
|
+
- 前缀:`Cn` 是组件候选;`Sn` 超过 50 个节点,是屏幕或区块外壳;`Tn` 少于 3 个节点,是压缩片段。`uses` 是展开后在全稿出现的次数。
|
|
35
|
+
- 同一模板的不同实例只在 `args` 上有差异,没有其他覆写通道。
|
|
36
|
+
- 节点 `id` 只在根、分组层、单元、连线端点上出现,其他节点用 `mb` 的路径寻址:`<id>/<子序号>/…`。
|
|
37
|
+
|
|
38
|
+
## 蒙版
|
|
39
|
+
|
|
40
|
+
被蒙版裁剪的内容是容器的子节点,裁剪写在容器上:`overflow:hidden` + `borderRadius`,或 layout 的 `clipPath`(照写成 `clip-path`),或节点上的 `maskFills`(引用 fill 样式,落成 `mask-image/size/position/repeat`)。
|
|
41
|
+
|
|
42
|
+
## 连线 `connectors`
|
|
43
|
+
|
|
44
|
+
`{id, label, from, to, fromRaw?, fromName?, toRaw?, toName?, fromUnresolved?, arrow?}`:设计师画的交互流程线,**不参与渲染和布局**。
|
|
45
|
+
|
|
46
|
+
- `label` 是触发条件(如「点击提交」)。
|
|
47
|
+
- `from` 或 `to` 里带 `/` 时,表示端点在模板实例里,从外到内逐层定位。
|
|
48
|
+
- 有 `fromName` 时,说明端点被上溯到了某个祖先节点,要按 `fromName` 判断意图(例如 `fromName="按钮 Button"` 指的是那个按钮,不是整个容器)。
|
|
49
|
+
|
|
50
|
+
## 画板与注释
|
|
51
|
+
|
|
52
|
+
- SECTION 里与界面并列的 TEXT 节点通常是设计师注释(`mb outline` 列在 `notes:` 里),描述交互、边界情况和动效,要当作需求实现。
|
|
53
|
+
- 只有还原整张画板时才用 `canvasXY` 做 absolute 排布;生成产品代码时,每个界面独立成为页面或组件。
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# 样式字段 → CSS
|
|
2
|
+
|
|
3
|
+
值大多已经可以直接当 CSS 用,数值保留 2 位小数。**有就照写,没有就不补**;缺字段不等于 CSS 默认值。全局使用 `box-sizing: border-box`。
|
|
4
|
+
|
|
5
|
+
## layout
|
|
6
|
+
|
|
7
|
+
| 字段 | CSS |
|
|
8
|
+
|---|---|
|
|
9
|
+
| `mode` row / column / grid / none | `display:flex` + direction / `display:grid` / 无 flex,子节点全部 absolute |
|
|
10
|
+
| `justifyContent` `alignItems` `alignSelf` `wrap` `padding` | 直译。flex 容器的 `alignItems` 总会给出;没给就不写,因为 CSS 默认的 stretch 不等于 Figma 的默认值 |
|
|
11
|
+
| `gap` | 直译;**负值**改成后续子项的负 margin(`> * + * { margin-left:-4px }`) |
|
|
12
|
+
| `sizing` `"水平/垂直"` | `fixed` 用节点的 width/height;`hug` 用 fit-content;`fill` 由 `flexGrow`、`flexBasis`、`alignSelf` 承载,节点上给了 width/height 时照写(父级是 `hug` 时由它定实际尺寸,否则会被内容撑开) |
|
|
13
|
+
| `flexGrow` / `noShrink` / `flexBasis` / `minWidth` | `flex-grow:1` / `flex-shrink:0` / `flex-basis:0` / `min-width`,各写各的,**不要合并成 flex 简写**;没有 noShrink 就不写 shrink |
|
|
14
|
+
| `position` | `relative` 只表示它是定位上下文,节点本身仍在 flex 流里;只有 `absolute` 或父节点 `mode:none` 时才脱离文档流 |
|
|
15
|
+
| `locationRelativeToParent` / `inset` | `position:absolute; left; top` / `inset:0`,坐标相对父节点外边缘 |
|
|
16
|
+
| `margin*` | 直译。`auto` 在 layout 里;具体数值写在节点上(同坐标一样是实例级) |
|
|
17
|
+
| `overflow` | `hidden` 只裁剪不滚动;`x-auto` 表示 `overflow-x:auto`,另一个轴按 hidden 处理 |
|
|
18
|
+
| `clipPath` | 照写成 `clip-path`;节点上同时有 `borderRadius` 时两个都写,裁剪叠加生效 |
|
|
19
|
+
| `scrollTop` / `scrollLeft`(节点上) | 渲染后用 JS 设置初始滚动位置,不要用负 top 模拟 |
|
|
20
|
+
| `zIndex:-1` + 父节点 `isolation:isolate` | 背景层沉底,两个字段必须配对写 |
|
|
21
|
+
| `pointerEvents:none` | 装饰层不拦截点击 |
|
|
22
|
+
| `gridTemplate*` / `gridRow` / `gridColumn` | 直接透传 |
|
|
23
|
+
|
|
24
|
+
每个容器都要落它的 layout。漏写 `display:flex` 会让 gap 和对齐静默失效。
|
|
25
|
+
|
|
26
|
+
**生产化调整**(只改尺寸策略,不改视觉):
|
|
27
|
+
|
|
28
|
+
- **倍率**:移动端稿屏宽 750 / 828 / 1125 是 2x / 2x / 3x 稿,所有数值(尺寸、字号、间距、圆角、描边、阴影)统一换算成 CSS px(÷2 或 ÷3);项目有 rem / vw 适配方案时按项目方案换算。375 / 390 / 414 宽是 1x,不换算。**倍率按每一屏各自判断**,同一个文件里可能混着 1x 帧和 2x 帧。
|
|
29
|
+
- 页面根节点的固定宽度改为 `width:100%` + `max-width`(取设计稿的逻辑宽度:750 宽的 2x 稿是 375px),或跟随项目的布局容器;`fill` 的部分自然自适应;组件内部的固定尺寸保持不变。
|
|
30
|
+
- **吸顶 / 固定层要不透明**:把头部、tab 栏、底栏改成 `sticky` / `fixed` 后,列表会滚到它们下面,这是设计稿里没有的重叠。设计稿里这些层叠在页面底色上,可能只是一张半透明的渐变图或一层半透明色;改成吸顶后必须把原来垫在下面的底色一起写上(如 `background: url(头部背景.png) …, var(--页面底色)`),否则滚动内容会从透明处透出来。
|
|
31
|
+
- **页面这一级的绝对定位转文档流**:屏幕根节点下按坐标摆放的区块,从上到下改成文档流,重复的卡片、列表行用数组 `.map` 加 gap(取相邻坐标差减去尺寸),顶部栏和底部栏用 sticky 或 fixed。判断标准是内容变长、数据条数变化时布局不能坏。
|
|
32
|
+
|
|
33
|
+
## fills
|
|
34
|
+
|
|
35
|
+
值是数组(单个元素时也可能是对象)。**index 0 在最上层**,和 CSS 多重背景顺序一致,每一层都要写。
|
|
36
|
+
|
|
37
|
+
- 颜色串逐字照抄,包括 alpha,不要凭观感改成实色。
|
|
38
|
+
- `{gradient}` 原样写,不要修改角度。
|
|
39
|
+
- `{backgroundImage, backgroundSize, backgroundPosition, backgroundRepeat}` 四个字段照抄成背景。内容图(随数据变化、要有 alt 或加载失败态)改用 `<img>` 时,`backgroundSize` / `backgroundPosition` 换成 `object-fit` / `object-position`(`cover` → `object-fit: cover`),否则图片会被拉伸变形。`backgroundSize` 是 `100% 100%` 且图片是 SVG 时,在文件的 `<svg>` 上加 `preserveAspectRatio="none"`,否则它会保持自身比例、两边留白。如果带 `opacity`,那只是这层图片的透明度,需要单独的伪元素承载。
|
|
40
|
+
- 多层填充时,**颜色不能写在非最后一层**,否则整条声明失效:最底层的纯色放 `background-color`,其他层用 `linear-gradient(c,c)` 写进 `background-image`。
|
|
41
|
+
- TEXT 节点的颜色只取 `fontStyle.color`。
|
|
42
|
+
|
|
43
|
+
`maskFills`(节点上):与 fills 同格式的 fill 样式引用,落成 `mask-image` / `mask-size` / `mask-position` / `mask-repeat`,作用于整个容器。
|
|
44
|
+
|
|
45
|
+
## fontStyle
|
|
46
|
+
|
|
47
|
+
`family`、`weight`、`size`、`lineHeight`、`letterSpacing`、`textCase`(text-transform)、`textAlign`、`textDecoration`、`color` 直译。
|
|
48
|
+
|
|
49
|
+
- 字体:设计稿用了项目里没有的字体(如商用付费字体)时,写 `font-family` 加上合理的回退字体,并在汇报里说明,不要擅自下载或引入字体文件。
|
|
50
|
+
|
|
51
|
+
- `textWrap`:`nowrap` → `white-space:nowrap`;`wrap` 按宽度换行;`truncate` → nowrap + hidden + ellipsis;`clamp` → `-webkit-line-clamp:maxLines` 三件套。
|
|
52
|
+
- 渐变文字:`backgroundClip:text` + `webkitTextFillColor:transparent` + `background` 三个一起写。
|
|
53
|
+
- TEXT 节点的 `layout` 同样要落,`fill` 宽度的文字负责撑满剩余空间。
|
|
54
|
+
|
|
55
|
+
## strokes
|
|
56
|
+
|
|
57
|
+
`{colors, strokeWeight, strokeAlign?, strokeDashes?}`,`strokeAlign` 省略表示 INSIDE。节点上的 `strokeFit` 指定画法:
|
|
58
|
+
|
|
59
|
+
| 情况 | 写法 |
|
|
60
|
+
|---|---|
|
|
61
|
+
| `strokeFit=border` | `border: w solid c` |
|
|
62
|
+
| `strokeFit=inset` | `box-shadow: inset 0 0 0 w c` |
|
|
63
|
+
| `strokeFit=inset-cover` | `::after` 覆盖层:`content:""; position:absolute; inset:0; border-radius:inherit; box-shadow:inset 0 0 0 w c` |
|
|
64
|
+
| `strokeFit=ring` 或颜色是渐变 | 环形伪元素:透明 border 宽 w,背景写渐变(`border-box`),`mask-composite:exclude`,`border-radius:inherit` |
|
|
65
|
+
| OUTSIDE | `box-shadow: 0 0 0 w c` |
|
|
66
|
+
| CENTER | `box-shadow: inset 0 0 0 w/2 c, 0 0 0 w/2 c` |
|
|
67
|
+
| 逐边 `"0px 0px 1px"`(上 右 下 左) | 按边各写一条:下边 `inset 0 -1px 0 0`、上边 `inset 0 1px 0 0`、左边 `inset 1px 0 0 0`、右边 `inset -1px 0 0 0` |
|
|
68
|
+
| 虚线 `strokeDashes` | `border: w dashed c` |
|
|
69
|
+
|
|
70
|
+
描边和 `effects.boxShadow` 都落在 box-shadow 上时,**合并成一条声明**(描边在前),否则后写的会覆盖前写的。伪元素画法的描边除外。描边线条某个轴为 0 时,那个轴是厚度轴,厚度取 strokeWeight。
|
|
71
|
+
|
|
72
|
+
**TEXT 节点上的描边**(文字描边,不是盒子描边):`-webkit-text-stroke: <w> <c>`。OUTSIDE 描边写成 2 倍宽度,再加 `paint-order: stroke fill`,让描边只露在外侧;INSIDE 和 CENTER 直接写原宽度。
|
|
73
|
+
|
|
74
|
+
## effects
|
|
75
|
+
|
|
76
|
+
`boxShadow`、`filter`、`backdropFilter` 直译。
|
|
77
|
+
|
|
78
|
+
- 设计师用一层「错位的同文字图层」来模拟阴影(同文本、同字体,只是位置偏移,常叫「投影」)时,合并成主文字的 `text-shadow`,不要渲染成两份文字。
|
|
79
|
+
|
|
80
|
+
## 旋转与镜像
|
|
81
|
+
|
|
82
|
+
只看 `rotate`(如 `-60deg`)或 `matrix`(`a,b,c,d,0,0`,镜像时用),都是直接读取。width 和 height 是旋转前的尺寸,照写后再加 transform;不要换成外接框尺寸,没有这两个字段的节点也不要自己补角度。IMAGE-SVG 导出的图里已经包含朝向,不要再变换一次。
|