leafer-x-design-system 2.0.1
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 +300 -0
- package/assets/README.md +16 -0
- package/assets/assetswechat-qr.png +0 -0
- package/assets/icon.svg +14 -0
- package/assets/wechat-pay.png +0 -0
- package/cli.js +163 -0
- package/examples/basic-usage.js +163 -0
- package/examples/express-server.js +279 -0
- package/index.d.ts +232 -0
- package/index.js +106 -0
- package/leafer-ai-layout-plugin-v2.js +370 -0
- package/leafer-ai-layout-plugin.js +341 -0
- package/leafer-design-system-generator.js +1102 -0
- package/leafer-design-system-pro.js +1194 -0
- package/leafer-renderer-fixed.js +661 -0
- package/leafer-renderer-v2.js +791 -0
- package/leafer-x-design-system.js +140 -0
- package/mcp-adapter.js +142 -0
- package/mcp-server-starter.js +85 -0
- package/mcp-server.js +300 -0
- package/mcp-service-config.js +24 -0
- package/package.json +55 -0
- package/start-mcp-service-v2.js +239 -0
- package/start-mcp-service.js +157 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Leafer Design System Team
|
|
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
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
# 🎨 Leafer Design System
|
|
2
|
+
|
|
3
|
+
基于 LeaferJS 的高保真 UI 设计系统生成器,支持响应式设计、暗黑模式和丰富的组件库。
|
|
4
|
+
|
|
5
|
+
## ✨ 特性
|
|
6
|
+
|
|
7
|
+
- 🎯 **高保真渲染**: 基于 LeaferJS + Skia Canvas,输出像素级精准的 UI 原型
|
|
8
|
+
- 📱 **响应式设计**: 支持桌面端、移动端、平板多种设备尺寸
|
|
9
|
+
- 🌓 **双主题模式**: 内置亮色/暗色主题,一键切换
|
|
10
|
+
- 🧩 **丰富组件**: 按钮、输入框、表格、模态框、下拉菜单、标签页、开关等
|
|
11
|
+
- 🔤 **中文支持**: 完美支持中文字体渲染
|
|
12
|
+
- ⚡ **高性能**: 缓存机制,批量渲染更高效
|
|
13
|
+
- 🛠️ **CLI 工具**: 命令行快速生成和渲染
|
|
14
|
+
|
|
15
|
+
## 📦 安装
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# 全局安装
|
|
19
|
+
npm install -g leafer-design-system
|
|
20
|
+
|
|
21
|
+
# 或本地安装
|
|
22
|
+
npm install leafer-design-system
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 🚀 快速开始
|
|
26
|
+
|
|
27
|
+
### 方式一:使用 CLI
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# 生成设计系统
|
|
31
|
+
leafer-design generate "My App" "#667eea" "#764ba2"
|
|
32
|
+
|
|
33
|
+
# 渲染模板
|
|
34
|
+
leafer-design render ./templates/login.json
|
|
35
|
+
|
|
36
|
+
# 启动 MCP 服务
|
|
37
|
+
leafer-design serve 3001
|
|
38
|
+
|
|
39
|
+
# 查看帮助
|
|
40
|
+
leafer-design help
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 方式二:使用 API
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
const {
|
|
47
|
+
generateDesignSystem,
|
|
48
|
+
renderTemplate,
|
|
49
|
+
createGenerator
|
|
50
|
+
} = require('leafer-design-system');
|
|
51
|
+
|
|
52
|
+
// 快速生成设计系统
|
|
53
|
+
const designSystem = generateDesignSystem({
|
|
54
|
+
name: 'My App',
|
|
55
|
+
primaryColor: '#667eea',
|
|
56
|
+
secondaryColor: '#764ba2',
|
|
57
|
+
mode: 'light'
|
|
58
|
+
}, './output');
|
|
59
|
+
|
|
60
|
+
// 渲染单个模板
|
|
61
|
+
const template = require('./templates/login.json');
|
|
62
|
+
const result = await renderTemplate(template, {
|
|
63
|
+
outputDir: './output',
|
|
64
|
+
format: 'png'
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
console.log('图片已生成:', result.url);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### 方式三:高级自定义
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
const {
|
|
74
|
+
DesignSystemProGenerator,
|
|
75
|
+
AdvancedComponentGenerator,
|
|
76
|
+
createRenderer
|
|
77
|
+
} = require('leafer-design-system');
|
|
78
|
+
|
|
79
|
+
// 创建生成器
|
|
80
|
+
const generator = new DesignSystemProGenerator({
|
|
81
|
+
name: 'Custom Design System',
|
|
82
|
+
primaryColor: '#3b82f6',
|
|
83
|
+
secondaryColor: '#8b5cf6',
|
|
84
|
+
mode: 'dark'
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// 获取组件生成器
|
|
88
|
+
const componentGen = generator.componentGen;
|
|
89
|
+
|
|
90
|
+
// 生成自定义表格
|
|
91
|
+
const table = componentGen.generateTable(
|
|
92
|
+
['姓名', '邮箱', '角色'],
|
|
93
|
+
[
|
|
94
|
+
['张三', 'zhangsan@example.com', '管理员'],
|
|
95
|
+
['李四', 'lisi@example.com', '编辑']
|
|
96
|
+
],
|
|
97
|
+
{ width: 600 }
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
// 渲染
|
|
101
|
+
const renderer = createRenderer({ outputDir: './output' });
|
|
102
|
+
const result = await renderer.render({
|
|
103
|
+
width: 800,
|
|
104
|
+
height: 600,
|
|
105
|
+
elements: [table],
|
|
106
|
+
options: { format: 'png' }
|
|
107
|
+
});
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## 📋 组件列表
|
|
111
|
+
|
|
112
|
+
### 基础组件
|
|
113
|
+
|
|
114
|
+
- ✅ Button (7种变体: Primary, Secondary, Success, Warning, Error, Ghost, Outline)
|
|
115
|
+
- ✅ Input (多种状态: Default, Focused, Error, Disabled)
|
|
116
|
+
- ✅ Card
|
|
117
|
+
- ✅ Badge
|
|
118
|
+
- ✅ Avatar
|
|
119
|
+
- ✅ Progress
|
|
120
|
+
|
|
121
|
+
### 高级组件
|
|
122
|
+
|
|
123
|
+
- ✅ Table (表格)
|
|
124
|
+
- ✅ Modal (模态框)
|
|
125
|
+
- ✅ Dropdown (下拉菜单)
|
|
126
|
+
- ✅ Tabs (标签页)
|
|
127
|
+
- ✅ Switch (开关)
|
|
128
|
+
- ✅ Checkbox (复选框)
|
|
129
|
+
- ✅ Radio (单选按钮)
|
|
130
|
+
|
|
131
|
+
### 响应式模板
|
|
132
|
+
|
|
133
|
+
- ✅ Mobile Login (移动端登录)
|
|
134
|
+
- ✅ Mobile Home (移动端首页)
|
|
135
|
+
- ✅ Tablet Dashboard (平板仪表盘)
|
|
136
|
+
- ✅ Desktop Dashboard (桌面仪表盘)
|
|
137
|
+
- ✅ Desktop Showcase (组件展示)
|
|
138
|
+
|
|
139
|
+
## 🎨 主题配置
|
|
140
|
+
|
|
141
|
+
```javascript
|
|
142
|
+
{
|
|
143
|
+
// 颜色
|
|
144
|
+
colors: {
|
|
145
|
+
primary: '#667eea',
|
|
146
|
+
secondary: '#764ba2',
|
|
147
|
+
success: '#48bb78',
|
|
148
|
+
warning: '#ed8936',
|
|
149
|
+
error: '#f56565',
|
|
150
|
+
info: '#4299e1'
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
// 字体
|
|
154
|
+
typography: {
|
|
155
|
+
fontFamily: 'Microsoft YaHei',
|
|
156
|
+
fontSize: { xs: 12, sm: 14, base: 16, lg: 18, xl: 20 }
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
// 间距
|
|
160
|
+
spacing: { 0: 0, 1: 4, 2: 8, 3: 12, 4: 16, 5: 20 },
|
|
161
|
+
|
|
162
|
+
// 圆角
|
|
163
|
+
borderRadius: { none: 0, sm: 2, md: 4, lg: 8, xl: 12 },
|
|
164
|
+
|
|
165
|
+
// 阴影
|
|
166
|
+
shadows: {
|
|
167
|
+
sm: { x: 0, y: 1, blur: 2, color: '#0000000d' },
|
|
168
|
+
md: { x: 0, y: 4, blur: 6, color: '#0000001a' },
|
|
169
|
+
lg: { x: 0, y: 10, blur: 15, color: '#00000026' }
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## 🔌 MCP 服务 API
|
|
175
|
+
|
|
176
|
+
启动 MCP 服务后,可通过 HTTP API 调用:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
curl -X POST http://localhost:3001/api/v1/ui/render \
|
|
180
|
+
-H "Content-Type: application/json" \
|
|
181
|
+
-d '{
|
|
182
|
+
"width": 800,
|
|
183
|
+
"height": 600,
|
|
184
|
+
"elements": [
|
|
185
|
+
{
|
|
186
|
+
"type": "box",
|
|
187
|
+
"x": 100,
|
|
188
|
+
"y": 100,
|
|
189
|
+
"width": 200,
|
|
190
|
+
"height": 100,
|
|
191
|
+
"fill": "#667eea",
|
|
192
|
+
"cornerRadius": 8
|
|
193
|
+
}
|
|
194
|
+
]
|
|
195
|
+
}'
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### API 端点
|
|
199
|
+
|
|
200
|
+
| 端点 | 方法 | 描述 |
|
|
201
|
+
| ------------------------- | ---- | ----- |
|
|
202
|
+
| `/health` | GET | 健康检查 |
|
|
203
|
+
| `/api/v1/ui/render` | POST | 渲染 UI |
|
|
204
|
+
| `/api/v1/ui/batch-render` | POST | 批量渲染 |
|
|
205
|
+
| `/api/v1/cache/clear` | POST | 清空缓存 |
|
|
206
|
+
| `/api/v1/stats` | GET | 获取统计 |
|
|
207
|
+
| `/output/:filename` | GET | 获取图片 |
|
|
208
|
+
|
|
209
|
+
## 📁 项目结构
|
|
210
|
+
|
|
211
|
+
```
|
|
212
|
+
my-design-system/
|
|
213
|
+
├── design-system.json # 设计系统配置
|
|
214
|
+
├── components.json # 组件定义
|
|
215
|
+
└── templates/
|
|
216
|
+
├── desktop-login.json
|
|
217
|
+
├── desktop-dashboard.json
|
|
218
|
+
├── desktop-showcase.json
|
|
219
|
+
├── mobile-login.json
|
|
220
|
+
├── mobile-home.json
|
|
221
|
+
└── tablet-dashboard.json
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## 🖼️ 输出示例
|
|
225
|
+
|
|
226
|
+
生成的 UI 原型图:
|
|
227
|
+
|
|
228
|
+
- 移动端登录页: 375x812
|
|
229
|
+
- 移动端首页: 375x812
|
|
230
|
+
- 桌面仪表盘: 1200x800
|
|
231
|
+
- 组件展示: 1200x1600
|
|
232
|
+
|
|
233
|
+
## 🛠️ 开发
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
# 克隆项目
|
|
237
|
+
git clone https://github.com/yourusername/leafer-design-system.git
|
|
238
|
+
cd leafer-design-system
|
|
239
|
+
|
|
240
|
+
# 安装依赖
|
|
241
|
+
npm install
|
|
242
|
+
|
|
243
|
+
# 生成设计系统
|
|
244
|
+
npm run generate
|
|
245
|
+
|
|
246
|
+
# 渲染模板
|
|
247
|
+
npm run render
|
|
248
|
+
|
|
249
|
+
# 启动服务
|
|
250
|
+
npm start
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
## 📄 许可证
|
|
254
|
+
|
|
255
|
+
MIT License © 2024
|
|
256
|
+
|
|
257
|
+
## 🤝 贡献
|
|
258
|
+
|
|
259
|
+
欢迎提交 Issue 和 PR!
|
|
260
|
+
|
|
261
|
+
## 🔗 相关链接
|
|
262
|
+
|
|
263
|
+
- [LeaferJS 官网](https://www.leaferjs.com/)
|
|
264
|
+
- [LeaferJS GitHub](https://github.com/leaferjs/leafer)
|
|
265
|
+
- [Skia Canvas](https://github.com/samizdatco/skia-canvas)
|
|
266
|
+
|
|
267
|
+
***
|
|
268
|
+
|
|
269
|
+
## 🤝 支持与联系
|
|
270
|
+
|
|
271
|
+
如果您觉得本项目对您有帮助,欢迎请作者喝杯咖啡 ☕
|
|
272
|
+
|
|
273
|
+
<table>
|
|
274
|
+
<tr>
|
|
275
|
+
<td align="center">
|
|
276
|
+
<img src="./assets/wechat-pay.png" width="200" alt="微信支付"/>
|
|
277
|
+
<br />
|
|
278
|
+
<sub>微信支付</sub>
|
|
279
|
+
</td>
|
|
280
|
+
<td align="center">
|
|
281
|
+
<img src="./assets/wechat-qr.png" width="200" alt="联系作者"/>
|
|
282
|
+
<br />
|
|
283
|
+
<sub>联系作者</sub>
|
|
284
|
+
</td>
|
|
285
|
+
</tr>
|
|
286
|
+
</table>
|
|
287
|
+
|
|
288
|
+
### 联系方式
|
|
289
|
+
|
|
290
|
+
- **微信**: 尽为一土
|
|
291
|
+
- **邮箱**: spring60\@vip.qq.com
|
|
292
|
+
- **GitHub Issues**: [提交问题](https://github.com/yourusername/leafer-design-system/issues)
|
|
293
|
+
|
|
294
|
+
### 加入社区
|
|
295
|
+
|
|
296
|
+
欢迎加入我们的社区,一起交流 LeaferJS 和设计系统的相关技术!
|
|
297
|
+
|
|
298
|
+
***
|
|
299
|
+
|
|
300
|
+
**如果这个项目对你有帮助,请给我们一个 ⭐ Star!**
|
package/assets/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# 资源文件目录
|
|
2
|
+
|
|
3
|
+
此目录用于存放项目相关的图片资源。
|
|
4
|
+
|
|
5
|
+
## 文件说明
|
|
6
|
+
|
|
7
|
+
- `wechat-pay.png` - 微信支付二维码
|
|
8
|
+
- `wechat-qr.png` - 微信联系二维码
|
|
9
|
+
|
|
10
|
+
## 添加你的二维码
|
|
11
|
+
|
|
12
|
+
1. 将你的微信支付二维码截图保存为 `wechat-pay.png`
|
|
13
|
+
2. 将你的微信联系二维码截图保存为 `wechat-qr.png`
|
|
14
|
+
3. 放入此目录即可在 README 中显示
|
|
15
|
+
|
|
16
|
+
**提示**: 二维码图片建议尺寸为 400x400 像素,文件大小控制在 200KB 以内。
|
|
Binary file
|
package/assets/icon.svg
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<svg width="256" height="256" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
4
|
+
<stop offset="0%" style="stop-color:#3b82f6;stop-opacity:1" />
|
|
5
|
+
<stop offset="100%" style="stop-color:#2563eb;stop-opacity:1" />
|
|
6
|
+
</linearGradient>
|
|
7
|
+
</defs>
|
|
8
|
+
<rect width="256" height="256" rx="48" fill="url(#grad1)"/>
|
|
9
|
+
<g fill="none" stroke="#ffffff" stroke-width="12" stroke-linecap="round" stroke-linejoin="round">
|
|
10
|
+
<path d="M128 64 L128 192"/>
|
|
11
|
+
<path d="M64 128 L128 64 L192 128"/>
|
|
12
|
+
<circle cx="128" cy="192" r="16" fill="#ffffff"/>
|
|
13
|
+
</g>
|
|
14
|
+
</svg>
|
|
Binary file
|
package/cli.js
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Leafer Design System - CLI 工具
|
|
5
|
+
*
|
|
6
|
+
* 使用方法:
|
|
7
|
+
* leafer-design generate - 生成设计系统
|
|
8
|
+
* leafer-design render - 渲染模板
|
|
9
|
+
* leafer-design serve - 启动 MCP 服务
|
|
10
|
+
* leafer-design help - 显示帮助
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const fs = require('fs');
|
|
14
|
+
const path = require('path');
|
|
15
|
+
const { generateDesignSystem, renderTemplate } = require('./index');
|
|
16
|
+
|
|
17
|
+
const command = process.argv[2];
|
|
18
|
+
const args = process.argv.slice(3);
|
|
19
|
+
|
|
20
|
+
function showHelp() {
|
|
21
|
+
console.log(`
|
|
22
|
+
🎨 Leafer Design System CLI
|
|
23
|
+
|
|
24
|
+
使用方法:
|
|
25
|
+
leafer-design <command> [options]
|
|
26
|
+
|
|
27
|
+
命令:
|
|
28
|
+
generate [name] [primaryColor] [secondaryColor]
|
|
29
|
+
生成设计系统
|
|
30
|
+
示例: leafer-design generate "My App" "#667eea" "#764ba2"
|
|
31
|
+
|
|
32
|
+
render <template-file>
|
|
33
|
+
渲染模板为图片
|
|
34
|
+
示例: leafer-design render ./templates/login.json
|
|
35
|
+
|
|
36
|
+
serve [port]
|
|
37
|
+
启动 MCP 服务
|
|
38
|
+
示例: leafer-design serve 3001
|
|
39
|
+
|
|
40
|
+
help
|
|
41
|
+
显示此帮助信息
|
|
42
|
+
|
|
43
|
+
选项:
|
|
44
|
+
--output, -o 指定输出目录
|
|
45
|
+
--mode, -m 主题模式 (light/dark)
|
|
46
|
+
--format, -f 输出格式 (png/jpg)
|
|
47
|
+
`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function generateCommand() {
|
|
51
|
+
const name = args[0] || 'My Design System';
|
|
52
|
+
const primaryColor = args[1] || '#667eea';
|
|
53
|
+
const secondaryColor = args[2] || '#764ba2';
|
|
54
|
+
const outputDir = args.find((arg, i) => arg === '--output' || arg === '-o')
|
|
55
|
+
? args[args.indexOf(args.find(arg => arg === '--output' || arg === '-o')) + 1]
|
|
56
|
+
: './my-design-system';
|
|
57
|
+
const mode = args.find((arg, i) => arg === '--mode' || arg === '-m')
|
|
58
|
+
? args[args.indexOf(args.find(arg => arg === '--mode' || arg === '-m')) + 1]
|
|
59
|
+
: 'light';
|
|
60
|
+
|
|
61
|
+
console.log(`\n🎨 生成设计系统: ${name}`);
|
|
62
|
+
console.log(` 主色调: ${primaryColor}`);
|
|
63
|
+
console.log(` 次色调: ${secondaryColor}`);
|
|
64
|
+
console.log(` 主题模式: ${mode}\n`);
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const designSystem = generateDesignSystem({
|
|
68
|
+
name,
|
|
69
|
+
primaryColor,
|
|
70
|
+
secondaryColor,
|
|
71
|
+
mode
|
|
72
|
+
}, outputDir);
|
|
73
|
+
|
|
74
|
+
console.log(`\n✅ 设计系统生成成功!`);
|
|
75
|
+
console.log(`📁 输出目录: ${path.resolve(outputDir)}`);
|
|
76
|
+
console.log(`📦 包含 ${Object.keys(designSystem.templates).length} 个设备类型的模板`);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.error(`\n❌ 生成失败: ${error.message}`);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function renderCommand() {
|
|
84
|
+
const templateFile = args[0];
|
|
85
|
+
|
|
86
|
+
if (!templateFile) {
|
|
87
|
+
console.error('❌ 请指定模板文件路径');
|
|
88
|
+
console.log(' 示例: leafer-design render ./templates/login.json');
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (!fs.existsSync(templateFile)) {
|
|
93
|
+
console.error(`❌ 模板文件不存在: ${templateFile}`);
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const outputDir = args.find((arg, i) => arg === '--output' || arg === '-o')
|
|
98
|
+
? args[args.indexOf(args.find(arg => arg === '--output' || arg === '-o')) + 1]
|
|
99
|
+
: './output';
|
|
100
|
+
|
|
101
|
+
const format = args.find((arg, i) => arg === '--format' || arg === '-f')
|
|
102
|
+
? args[args.indexOf(args.find(arg => arg === '--format' || arg === '-f')) + 1]
|
|
103
|
+
: 'png';
|
|
104
|
+
|
|
105
|
+
console.log(`\n🖼️ 渲染模板: ${templateFile}`);
|
|
106
|
+
console.log(` 输出格式: ${format}\n`);
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
const template = JSON.parse(fs.readFileSync(templateFile, 'utf-8'));
|
|
110
|
+
const result = await renderTemplate(template, {
|
|
111
|
+
outputDir,
|
|
112
|
+
format
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
console.log(`\n✅ 渲染成功!`);
|
|
116
|
+
console.log(`📁 图片路径: ${result.url}`);
|
|
117
|
+
console.log(`⏱️ 渲染时间: ${result.renderTime}ms`);
|
|
118
|
+
} catch (error) {
|
|
119
|
+
console.error(`\n❌ 渲染失败: ${error.message}`);
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function serveCommand() {
|
|
125
|
+
const port = args[0] || 3001;
|
|
126
|
+
console.log(`\n🚀 启动 MCP 服务...`);
|
|
127
|
+
console.log(` 端口: ${port}\n`);
|
|
128
|
+
|
|
129
|
+
// 启动服务
|
|
130
|
+
require('./start-mcp-service-v2');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// 主程序
|
|
134
|
+
async function main() {
|
|
135
|
+
switch (command) {
|
|
136
|
+
case 'generate':
|
|
137
|
+
case 'g':
|
|
138
|
+
await generateCommand();
|
|
139
|
+
break;
|
|
140
|
+
case 'render':
|
|
141
|
+
case 'r':
|
|
142
|
+
await renderCommand();
|
|
143
|
+
break;
|
|
144
|
+
case 'serve':
|
|
145
|
+
case 's':
|
|
146
|
+
serveCommand();
|
|
147
|
+
break;
|
|
148
|
+
case 'help':
|
|
149
|
+
case 'h':
|
|
150
|
+
case '--help':
|
|
151
|
+
case '-h':
|
|
152
|
+
showHelp();
|
|
153
|
+
break;
|
|
154
|
+
default:
|
|
155
|
+
console.log('🎨 Leafer Design System v2.0.0\n');
|
|
156
|
+
showHelp();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
main().catch(error => {
|
|
161
|
+
console.error('❌ 错误:', error.message);
|
|
162
|
+
process.exit(1);
|
|
163
|
+
});
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 基础使用示例
|
|
3
|
+
*
|
|
4
|
+
* 演示如何在其他项目中使用 leafer-design-system
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
generateDesignSystem,
|
|
9
|
+
renderTemplate,
|
|
10
|
+
createGenerator,
|
|
11
|
+
createRenderer
|
|
12
|
+
} = require('../index');
|
|
13
|
+
|
|
14
|
+
async function basicExample() {
|
|
15
|
+
console.log('🎨 基础使用示例\n');
|
|
16
|
+
|
|
17
|
+
// 1. 快速生成设计系统
|
|
18
|
+
console.log('1️⃣ 生成设计系统...');
|
|
19
|
+
const designSystem = generateDesignSystem({
|
|
20
|
+
name: 'My Awesome App',
|
|
21
|
+
primaryColor: '#3b82f6',
|
|
22
|
+
secondaryColor: '#8b5cf6',
|
|
23
|
+
mode: 'light'
|
|
24
|
+
}, './output/my-app-design');
|
|
25
|
+
|
|
26
|
+
console.log('✅ 设计系统生成成功!');
|
|
27
|
+
console.log(` 名称: ${designSystem.name}`);
|
|
28
|
+
console.log(` 版本: ${designSystem.version}`);
|
|
29
|
+
console.log(` 模板数量: ${Object.keys(designSystem.templates).length}\n`);
|
|
30
|
+
|
|
31
|
+
// 2. 渲染移动端登录页
|
|
32
|
+
console.log('2️⃣ 渲染移动端登录页...');
|
|
33
|
+
const mobileLogin = designSystem.templates.mobile.login;
|
|
34
|
+
const result = await renderTemplate(mobileLogin, {
|
|
35
|
+
outputDir: './output/examples',
|
|
36
|
+
format: 'png'
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
console.log('✅ 渲染成功!');
|
|
40
|
+
console.log(` 图片路径: ${result.url}`);
|
|
41
|
+
console.log(` 渲染时间: ${result.renderTime}ms\n`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function advancedExample() {
|
|
45
|
+
console.log('🚀 高级自定义示例\n');
|
|
46
|
+
|
|
47
|
+
// 1. 创建自定义生成器
|
|
48
|
+
console.log('1️⃣ 创建自定义生成器...');
|
|
49
|
+
const generator = createGenerator({
|
|
50
|
+
name: 'Custom Design System',
|
|
51
|
+
primaryColor: '#10b981',
|
|
52
|
+
secondaryColor: '#f59e0b',
|
|
53
|
+
mode: 'dark'
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// 2. 获取组件生成器
|
|
57
|
+
const componentGen = generator.componentGen;
|
|
58
|
+
|
|
59
|
+
// 3. 生成自定义组件
|
|
60
|
+
console.log('2️⃣ 生成自定义组件...');
|
|
61
|
+
|
|
62
|
+
// 生成表格
|
|
63
|
+
const table = componentGen.generateTable(
|
|
64
|
+
['产品', '价格', '库存', '状态'],
|
|
65
|
+
[
|
|
66
|
+
['iPhone 15', '¥5999', '100', '有货'],
|
|
67
|
+
['iPad Pro', '¥7999', '50', '有货'],
|
|
68
|
+
['MacBook Pro', '¥14999', '20', '缺货']
|
|
69
|
+
],
|
|
70
|
+
{ width: 600, x: 50, y: 50 }
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
// 生成模态框
|
|
74
|
+
const modal = componentGen.generateModal(
|
|
75
|
+
'确认订单',
|
|
76
|
+
'您确定要提交此订单吗?总计: ¥28,997',
|
|
77
|
+
{ x: 200, y: 150 }
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
// 4. 渲染组件
|
|
81
|
+
console.log('3️⃣ 渲染组件...');
|
|
82
|
+
const renderer = createRenderer({ outputDir: './output/examples' });
|
|
83
|
+
|
|
84
|
+
// 渲染表格
|
|
85
|
+
const tableResult = await renderer.render({
|
|
86
|
+
width: 700,
|
|
87
|
+
height: 300,
|
|
88
|
+
elements: [table],
|
|
89
|
+
options: { format: 'png', backgroundColor: '#f9fafb' }
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
console.log('✅ 表格渲染成功!');
|
|
93
|
+
console.log(` 图片路径: ${tableResult.url}\n`);
|
|
94
|
+
|
|
95
|
+
// 渲染模态框
|
|
96
|
+
const modalResult = await renderer.render({
|
|
97
|
+
width: 800,
|
|
98
|
+
height: 600,
|
|
99
|
+
elements: [modal],
|
|
100
|
+
options: { format: 'png', backgroundColor: '#f3f4f6' }
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
console.log('✅ 模态框渲染成功!');
|
|
104
|
+
console.log(` 图片路径: ${modalResult.url}\n`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function batchRenderExample() {
|
|
108
|
+
console.log('📦 批量渲染示例\n');
|
|
109
|
+
|
|
110
|
+
// 1. 生成设计系统
|
|
111
|
+
const generator = createGenerator({
|
|
112
|
+
name: 'Batch Example',
|
|
113
|
+
primaryColor: '#ec4899',
|
|
114
|
+
secondaryColor: '#6366f1'
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const designSystem = generator.generate();
|
|
118
|
+
|
|
119
|
+
// 2. 准备批量渲染的模板
|
|
120
|
+
const templates = [
|
|
121
|
+
{ ...designSystem.templates.mobile.login, name: 'mobile-login' },
|
|
122
|
+
{ ...designSystem.templates.mobile.home, name: 'mobile-home' },
|
|
123
|
+
{ ...designSystem.templates.tablet.dashboard, name: 'tablet-dashboard' }
|
|
124
|
+
];
|
|
125
|
+
|
|
126
|
+
// 3. 批量渲染
|
|
127
|
+
console.log(`开始批量渲染 ${templates.length} 个模板...\n`);
|
|
128
|
+
|
|
129
|
+
const { renderTemplates } = require('../index');
|
|
130
|
+
const results = await renderTemplates(templates, {
|
|
131
|
+
outputDir: './output/examples/batch'
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// 4. 输出结果
|
|
135
|
+
console.log('📊 批量渲染结果:\n');
|
|
136
|
+
results.forEach((result, i) => {
|
|
137
|
+
if (result.success) {
|
|
138
|
+
console.log(`✅ ${result.template}: ${result.result.url}`);
|
|
139
|
+
} else {
|
|
140
|
+
console.log(`❌ ${result.template}: ${result.error}`);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// 运行示例
|
|
146
|
+
async function main() {
|
|
147
|
+
try {
|
|
148
|
+
await basicExample();
|
|
149
|
+
console.log('\n' + '='.repeat(50) + '\n');
|
|
150
|
+
|
|
151
|
+
await advancedExample();
|
|
152
|
+
console.log('\n' + '='.repeat(50) + '\n');
|
|
153
|
+
|
|
154
|
+
await batchRenderExample();
|
|
155
|
+
|
|
156
|
+
console.log('\n🎉 所有示例运行完成!');
|
|
157
|
+
} catch (error) {
|
|
158
|
+
console.error('❌ 错误:', error.message);
|
|
159
|
+
console.error(error.stack);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
main();
|