mta-mcp 1.0.3 → 1.0.4
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/package.json
CHANGED
|
@@ -52,7 +52,148 @@ function getLayerColor(layer) {
|
|
|
52
52
|
}
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
### 问题 2:
|
|
55
|
+
### 问题 2:fontWeight 数值不准确(重要)
|
|
56
|
+
|
|
57
|
+
**严重程度**: 🔴 高
|
|
58
|
+
|
|
59
|
+
**现象**:`layer.style.fontWeight` 返回的数值(如 8)不能直接映射到 Flutter/CSS 字重。
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
// ❌ 错误方式 - fontWeight 值不可靠
|
|
63
|
+
layer.style.fontWeight // 返回 8,但实际可能是 Semibold(w600) 而非 ExtraBold(w800)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**原因**:Sketch API 的 `fontWeight` 属性返回的是内部权重值,不是标准的 100-900 字重值。
|
|
67
|
+
|
|
68
|
+
**解决方案**:通过 `sketchObject.font()` 获取真实的 PostScript 字体名称:
|
|
69
|
+
|
|
70
|
+
```javascript
|
|
71
|
+
function getTextFontInfo(textLayer) {
|
|
72
|
+
const result = {
|
|
73
|
+
fontSize: textLayer.style.fontSize,
|
|
74
|
+
fontFamily: textLayer.style.fontFamily,
|
|
75
|
+
fontWeight: textLayer.style.fontWeight, // 仅供参考
|
|
76
|
+
fontName: null, // 关键:真实字体名称
|
|
77
|
+
displayName: null
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// 获取真实字体名称
|
|
81
|
+
if (textLayer.sketchObject && textLayer.sketchObject.font) {
|
|
82
|
+
const font = textLayer.sketchObject.font();
|
|
83
|
+
if (font) {
|
|
84
|
+
result.fontName = String(font.fontName()); // 如 "PingFangSC-Semibold"
|
|
85
|
+
result.displayName = String(font.displayName()); // 如 "苹方-简 中粗体"
|
|
86
|
+
result.familyName = String(font.familyName()); // 如 "PingFang SC"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**PostScript 字体名到 Flutter FontWeight 映射**:
|
|
95
|
+
|
|
96
|
+
| PostScript 后缀 | 中文名 | Flutter | CSS |
|
|
97
|
+
|----------------|--------|---------|-----|
|
|
98
|
+
| `-Thin` | 极细 | w100 | 100 |
|
|
99
|
+
| `-Ultralight` | 纤细 | w200 | 200 |
|
|
100
|
+
| `-Light` | 细体 | w300 | 300 |
|
|
101
|
+
| `-Regular` | 常规 | w400 | 400 |
|
|
102
|
+
| `-Medium` | 中等 | w500 | 500 |
|
|
103
|
+
| `-Semibold` | 中粗体 | w600 | 600 |
|
|
104
|
+
| `-Bold` | 粗体 | w700 | 700 |
|
|
105
|
+
| `-Heavy` | 特粗 | w800 | 800 |
|
|
106
|
+
| `-Black` | 黑体 | w900 | 900 |
|
|
107
|
+
|
|
108
|
+
### 问题 3:图标必须从设计稿导出
|
|
109
|
+
|
|
110
|
+
**严重程度**: 🔴 高
|
|
111
|
+
|
|
112
|
+
**现象**:AI 可能会自己生成图标 SVG,而不是从设计稿中提取。
|
|
113
|
+
|
|
114
|
+
**正确做法**:使用 `sketch.export` API 导出设计稿中的图标:
|
|
115
|
+
|
|
116
|
+
```javascript
|
|
117
|
+
const sketch = require('sketch');
|
|
118
|
+
|
|
119
|
+
function exportIconAsSVG(layer) {
|
|
120
|
+
// 导出为 Buffer
|
|
121
|
+
const buffer = sketch.export(layer, {
|
|
122
|
+
formats: 'svg',
|
|
123
|
+
output: false, // 关键:返回 Buffer 而非写文件
|
|
124
|
+
scales: '1'
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// Buffer 转字符串
|
|
128
|
+
const svgString = buffer.toString('utf-8');
|
|
129
|
+
|
|
130
|
+
// 清理 SVG(移除 Sketch 生成的多余属性)
|
|
131
|
+
return svgString
|
|
132
|
+
.replace(/id="[^"]*"/g, '')
|
|
133
|
+
.replace(/sketch:type="[^"]*"/g, '')
|
|
134
|
+
.replace(/xmlns:sketch="[^"]*"/g, '')
|
|
135
|
+
.replace(/\s+/g, ' ')
|
|
136
|
+
.trim();
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**在 Flutter 中使用导出的 SVG**:
|
|
141
|
+
|
|
142
|
+
```dart
|
|
143
|
+
// 方式1:内联 SVG(推荐小图标)
|
|
144
|
+
SvgPicture.string(
|
|
145
|
+
'''<svg>...</svg>''',
|
|
146
|
+
width: 24,
|
|
147
|
+
height: 24,
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
// 方式2:保存为文件(推荐大图标)
|
|
151
|
+
// 将导出的 SVG 保存到 assets/icons/ 目录
|
|
152
|
+
SvgPicture.asset('assets/icons/notification.svg')
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### 问题 4:列表项间距测量
|
|
156
|
+
|
|
157
|
+
**严重程度**: 🔴 高
|
|
158
|
+
|
|
159
|
+
**现象**:列表中多个同类元素的间距可能不一致,需要逐个测量。
|
|
160
|
+
|
|
161
|
+
**测量脚本**:
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
function measureListSpacing(container) {
|
|
165
|
+
const children = container.layers;
|
|
166
|
+
const spacings = [];
|
|
167
|
+
|
|
168
|
+
for (let i = 0; i < children.length - 1; i++) {
|
|
169
|
+
const current = children[i];
|
|
170
|
+
const next = children[i + 1];
|
|
171
|
+
|
|
172
|
+
// 垂直间距 = 下一个元素的 y - (当前元素的 y + 高度)
|
|
173
|
+
const spacing = next.frame.y - (current.frame.y + current.frame.height);
|
|
174
|
+
|
|
175
|
+
spacings.push({
|
|
176
|
+
between: `${current.name} → ${next.name}`,
|
|
177
|
+
spacing: Math.round(spacing)
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// 检查是否一致
|
|
182
|
+
const uniqueSpacings = [...new Set(spacings.map(s => s.spacing))];
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
spacings,
|
|
186
|
+
isConsistent: uniqueSpacings.length === 1,
|
|
187
|
+
recommendedSpacing: uniqueSpacings.length === 1
|
|
188
|
+
? uniqueSpacings[0]
|
|
189
|
+
: Math.round(spacings.reduce((a, b) => a + b.spacing, 0) / spacings.length)
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
**注意**:如果设计稿中间距不一致,应与设计师确认是故意还是误差。代码中应使用统一间距。
|
|
195
|
+
|
|
196
|
+
### 问题 5:Symbol 内部样式读取
|
|
56
197
|
|
|
57
198
|
**严重程度**: 🟡 中
|
|
58
199
|
|
|
@@ -69,7 +210,7 @@ if (layer.type === 'SymbolInstance') {
|
|
|
69
210
|
}
|
|
70
211
|
```
|
|
71
212
|
|
|
72
|
-
### 问题
|
|
213
|
+
### 问题 6:阴影数组顺序
|
|
73
214
|
|
|
74
215
|
**严重程度**: 🟢 低
|
|
75
216
|
|
|
@@ -346,4 +487,11 @@ function convertGradient(gradient, framework) {
|
|
|
346
487
|
|
|
347
488
|
**维护者**: MTA工作室
|
|
348
489
|
**创建日期**: 2026-01-20
|
|
349
|
-
**最后更新**: 2026-01-
|
|
490
|
+
**最后更新**: 2026-01-21
|
|
491
|
+
|
|
492
|
+
### 更新日志
|
|
493
|
+
|
|
494
|
+
| 版本 | 日期 | 更新内容 |
|
|
495
|
+
|------|------|---------|
|
|
496
|
+
| v1.0 | 2026-01-20 | 初始版本 |
|
|
497
|
+
| v1.1 | 2026-01-21 | 新增:fontWeight不可靠问题及fontName获取方案、图标导出规范、列表间距测量脚本 |
|
|
@@ -83,16 +83,53 @@ color: "#1C2B45" // 丢失透明度
|
|
|
83
83
|
|
|
84
84
|
设计稿中的字重名称需要映射为数值:
|
|
85
85
|
|
|
86
|
-
| 设计稿名称 | 数值 | Flutter | CSS |
|
|
87
|
-
|
|
88
|
-
| Thin | 100 | FontWeight.w100 | font-weight: 100 |
|
|
89
|
-
|
|
|
90
|
-
|
|
|
91
|
-
|
|
|
92
|
-
|
|
|
93
|
-
|
|
|
86
|
+
| 设计稿名称 | PostScript 后缀 | 数值 | Flutter | CSS |
|
|
87
|
+
|-----------|----------------|------|---------|-----|
|
|
88
|
+
| Thin | -Thin | 100 | FontWeight.w100 | font-weight: 100 |
|
|
89
|
+
| Ultralight | -Ultralight | 200 | FontWeight.w200 | font-weight: 200 |
|
|
90
|
+
| Light | -Light | 300 | FontWeight.w300 | font-weight: 300 |
|
|
91
|
+
| Regular | -Regular | 400 | FontWeight.w400 | font-weight: 400 |
|
|
92
|
+
| Medium | -Medium | 500 | FontWeight.w500 | font-weight: 500 |
|
|
93
|
+
| SemiBold | -Semibold | 600 | FontWeight.w600 | font-weight: 600 |
|
|
94
|
+
| Bold | -Bold | 700 | FontWeight.w700 | font-weight: 700 |
|
|
95
|
+
| Heavy/ExtraBold | -Heavy | 800 | FontWeight.w800 | font-weight: 800 |
|
|
96
|
+
| Black | -Black | 900 | FontWeight.w900 | font-weight: 900 |
|
|
94
97
|
|
|
95
|
-
|
|
98
|
+
> ⚠️ **重要**:Sketch API 的 `fontWeight` 属性返回的数值(如 8)不可靠!必须通过 `sketchObject.font().fontName()` 获取真实的 PostScript 字体名称(如 `PingFangSC-Semibold`),然后根据后缀映射。
|
|
99
|
+
|
|
100
|
+
#### 4. 图标必须从设计稿导出
|
|
101
|
+
|
|
102
|
+
**绝对禁止**:AI 自己生成图标 SVG
|
|
103
|
+
|
|
104
|
+
**正确做法**:使用设计工具 API 导出设计稿中的图标
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
// Sketch 导出示例
|
|
108
|
+
const buffer = sketch.export(iconLayer, {
|
|
109
|
+
formats: 'svg',
|
|
110
|
+
output: false,
|
|
111
|
+
scales: '1'
|
|
112
|
+
});
|
|
113
|
+
const svgString = buffer.toString('utf-8');
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**原因**:
|
|
117
|
+
- 设计师精心调整过图标的线条粗细、比例、细节
|
|
118
|
+
- AI 生成的图标风格可能与设计稿不一致
|
|
119
|
+
- 图标是品牌视觉的重要组成部分
|
|
120
|
+
|
|
121
|
+
#### 5. 列表间距必须逐个测量
|
|
122
|
+
|
|
123
|
+
**问题**:同一列表中的元素间距可能不完全一致
|
|
124
|
+
|
|
125
|
+
**正确做法**:测量每对相邻元素的间距,取多数值或与设计师确认
|
|
126
|
+
|
|
127
|
+
```javascript
|
|
128
|
+
// 间距计算公式
|
|
129
|
+
spacing = nextElement.y - (currentElement.y + currentElement.height)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
#### 6. 行高计算差异
|
|
96
133
|
|
|
97
134
|
不同框架对行高的处理不同:
|
|
98
135
|
|
|
@@ -356,6 +393,7 @@ function getFigmaColor(paint) {
|
|
|
356
393
|
| 版本 | 日期 | 更新内容 |
|
|
357
394
|
|------|------|---------|
|
|
358
395
|
| v1.0 | 2026-01-20 | 初始版本,包含渐变色读取问题解决方案 |
|
|
396
|
+
| v1.1 | 2026-01-21 | 新增:字重映射完整表(含PostScript后缀)、图标导出强制要求、列表间距测量规范 |
|
|
359
397
|
|
|
360
398
|
---
|
|
361
399
|
|