mta-mcp 2.17.0 → 3.0.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.
Files changed (38) hide show
  1. package/agents/flutter.agent.md +23 -64
  2. package/agents/mta.agent.md +226 -0
  3. package/agents/vue3.agent.md +24 -0
  4. package/agents/wechat-miniprogram.agent.md +23 -0
  5. package/dist/index.js +1 -1
  6. package/dist/index.js.map +1 -1
  7. package/package.json +2 -4
  8. package/standards/mcp-tools/sketch-mcp.md +497 -0
  9. package/standards/patterns/design-system-restoration.md +570 -0
  10. package/standards/syntax-mapping.md +256 -0
  11. package/standards/workflows/design-restoration.md +401 -0
  12. package/templates/README.md +14 -0
  13. package/templates/design-measurement/README.md +81 -0
  14. package/templates/design-measurement/component-measurement.js +52 -0
  15. package/templates/design-measurement/gap-measurement.js +79 -0
  16. package/templates/design-measurement/style-extraction.js +109 -0
  17. package/common/i18n.md +0 -385
  18. package/common/typescript-strict.md +0 -186
  19. package/troubleshooting/README.md +0 -368
  20. package/troubleshooting/USAGE_GUIDE.md +0 -289
  21. package/troubleshooting/flutter/clip-/351/230/264/345/275/261/350/243/201/345/211/252.md +0 -244
  22. package/troubleshooting/flutter/input-/345/255/227/346/256/265/347/274/272/345/244/261.md +0 -240
  23. package/troubleshooting/flutter/input-/350/276/271/346/241/206/351/227/256/351/242/230.md +0 -236
  24. package/troubleshooting/flutter/layout-/345/260/272/345/257/270/344/270/215/345/214/271/351/205/215.md +0 -214
  25. package/troubleshooting/flutter/shadow-/351/200/217/345/207/272/351/227/256/351/242/230.md +0 -172
  26. package/troubleshooting/flutter/sketch-/345/210/227/350/241/250item/345/214/272/345/237/237.md +0 -212
  27. package/troubleshooting/flutter/sketch-/345/233/276/346/240/207/345/260/272/345/257/270.md +0 -135
  28. package/troubleshooting/flutter/sketch-/345/256/214/346/225/264/346/217/220/345/217/226.md +0 -201
  29. package/troubleshooting/flutter/sketch-/345/261/236/346/200/247/346/234/252/344/275/277/347/224/250.md +0 -139
  30. package/troubleshooting/flutter/sketch-/350/203/214/346/231/257/345/261/202/351/253/230/345/272/246.md +0 -264
  31. package/troubleshooting/flutter/svg-/346/234/252/345/261/205/344/270/255.md +0 -120
  32. package/troubleshooting/flutter/svg-/351/242/234/350/211/262/345/274/202/345/270/270.md +0 -117
  33. package/troubleshooting/flutter/tabbar-/345/212/250/347/224/273/345/220/214/346/255/245.md +0 -107
  34. package/troubleshooting/flutter/withopacity-/345/274/203/347/224/250.md +0 -81
  35. package/troubleshooting/vue3/cascader-/350/257/257/346/233/277/346/215/242.md +0 -130
  36. package/troubleshooting/vue3/drawer-input-/346/240/267/345/274/217.md +0 -181
  37. package/troubleshooting/vue3/table-/347/274/226/350/276/221/345/217/226/346/266/210.md +0 -148
  38. package/troubleshooting/vue3/table-/350/276/271/346/241/206/351/227/256/351/242/230.md +0 -178
@@ -1,172 +0,0 @@
1
- # Flutter 阴影透出问题
2
-
3
- > **问题标签**: `shadow`, `neumorphism`, `transparency`, `boxshadow`
4
- > **框架**: Flutter
5
- > **严重程度**: 中等(视觉问题)
6
-
7
- ---
8
-
9
- ## 🔍 问题识别
10
-
11
- ### 自动检测特征
12
-
13
- ```dart
14
- // 代码模式匹配
15
- BoxShadow(
16
- color: Color(0x??000000), // 包含黑色阴影
17
- // ...
18
- )
19
- // + 半透明背景
20
- color: Color(0x??FFFFFF)
21
- ```
22
-
23
- ### 用户描述关键词
24
- - "阴影透出来了"
25
- - "容器比设计稿暗"
26
- - "失去通透感"
27
- - "新拟态效果不对"
28
- - "毛玻璃效果变灰"
29
-
30
- ### 问题特征
31
- - [ ] 半透明容器颜色比设计稿更暗
32
- - [ ] 容器有 BoxShadow 阴影
33
- - [ ] 阴影包含深色(黑色/灰色)
34
- - [ ] 视觉上失去"玻璃感"或"通透感"
35
-
36
- ---
37
-
38
- ## ❌ 常见错误排查路线(避免重复)
39
-
40
- | 尝试方向 | 为什么无效 | 浪费时间 |
41
- |----------|-----------|---------|
42
- | 降低容器透明度 | 治标不治本,破坏设计稿规格 | 1-2 轮对话 |
43
- | 修改全局主题 fillColor | 问题不在主题层 | 2-3 轮对话 |
44
- | 调整阴影颜色/大小 | 只要阴影在下方就会透出 | 2-3 轮对话 |
45
- | 使用深色背景模拟 | Hack 方案,不同背景下失效 | 1-2 轮对话 |
46
-
47
- **总计浪费**: 6-10 轮对话
48
-
49
- ---
50
-
51
- ## ✅ 正确解决方案
52
-
53
- ### 核心原理
54
-
55
- Flutter `BoxShadow` 绘制在容器**下方**,当容器背景半透明时,阴影颜色会透过容器显示出来。
56
-
57
- ```
58
- ┌─────────────────────────┐
59
- │ 阴影层(黑色) │ ← 最底层
60
- ├─────────────────────────┤
61
- │ 容器层(55%白色) │ ← 半透明,下面的黑色透出来
62
- ├─────────────────────────┤
63
- │ 内容层 │
64
- └─────────────────────────┘
65
-
66
- 结果: 55%白色 + 黑色阴影 = 偏暗的灰色
67
- ```
68
-
69
- ### 解决方法:空心阴影 (Hollow Shadow)
70
-
71
- 使用 `CustomPainter` 绘制阴影,但裁剪掉中间的容器区域。
72
-
73
- ```dart
74
- import 'dart:ui' as ui;
75
-
76
- class HollowShadowPainter extends CustomPainter {
77
- final List<BoxShadow> shadows;
78
- final double radius;
79
-
80
- HollowShadowPainter({required this.shadows, required this.radius});
81
-
82
- @override
83
- void paint(Canvas canvas, Size size) {
84
- final RRect shape = RRect.fromRectAndRadius(
85
- Rect.fromLTWH(0, 0, size.width, size.height),
86
- Radius.circular(radius),
87
- );
88
-
89
- final Path shapePath = Path()..addRRect(shape);
90
- final Path canvasPath = Path()
91
- ..addRect(Rect.fromLTWH(-500, -500, size.width + 1000, size.height + 1000));
92
-
93
- // 关键:挖空中间区域
94
- final Path outerPath = Path.combine(
95
- ui.PathOperation.difference,
96
- canvasPath,
97
- shapePath,
98
- );
99
-
100
- canvas.save();
101
- canvas.clipPath(outerPath); // 只在外部绘制
102
-
103
- for (final shadow in shadows) {
104
- final Paint shadowPaint = Paint()
105
- ..color = shadow.color
106
- ..maskFilter = MaskFilter.blur(
107
- BlurStyle.normal,
108
- shadow.blurRadius * 0.57735 + 0.5,
109
- );
110
- canvas.drawRRect(
111
- shape.inflate(shadow.spreadRadius).shift(shadow.offset),
112
- shadowPaint,
113
- );
114
- }
115
-
116
- canvas.restore();
117
- }
118
-
119
- @override
120
- bool shouldRepaint(covariant HollowShadowPainter oldDelegate) {
121
- return oldDelegate.shadows != shadows || oldDelegate.radius != radius;
122
- }
123
- }
124
- ```
125
-
126
- ### 使用示例
127
-
128
- ```dart
129
- Widget _buildNeumorphicContainer({required Widget child, double height = 54}) {
130
- return CustomPaint(
131
- painter: HollowShadowPainter(
132
- radius: 16,
133
- shadows: const [
134
- BoxShadow(color: Color(0x0D000000), blurRadius: 3, offset: Offset(0, 1)),
135
- BoxShadow(color: Color(0x14000000), blurRadius: 5, offset: Offset(2, 2)),
136
- BoxShadow(color: Color(0xE6FFFFFF), blurRadius: 5, offset: Offset(-2, -2)),
137
- ],
138
- ),
139
- child: Container(
140
- height: height,
141
- decoration: BoxDecoration(
142
- color: const Color(0x8CFFFFFF), // 可以放心使用设计稿透明度
143
- borderRadius: BorderRadius.circular(16),
144
- border: Border.all(color: const Color(0x99FFFFFF), width: 1),
145
- ),
146
- child: child,
147
- ),
148
- );
149
- }
150
- ```
151
-
152
- ---
153
-
154
- ## 📋 适用场景
155
-
156
- - ✅ 新拟态 (Neumorphism) 设计
157
- - ✅ 毛玻璃/磨砂玻璃效果
158
- - ✅ 任何需要半透明背景 + 阴影的场景
159
- - ✅ iOS 风格 UI
160
-
161
- ---
162
-
163
- ## 🔗 相关案例
164
-
165
- - [layout-尺寸不匹配.md](./layout-尺寸不匹配.md) - 新拟态容器尺寸调整
166
- - [input-字段缺失.md](./input-字段缺失.md) - CustomPainter 配合输入框使用
167
-
168
- ---
169
-
170
- **来源**: my_flutter 项目实战经验
171
- **创建日期**: 2025-12-31
172
- **最后验证**: 2026-01-16
@@ -1,212 +0,0 @@
1
- # Sketch 列表 Item 区域高度不一致问题
2
-
3
- > **问题标签**: `sketch`, `list`, `menu`, `item`, `padding`, `divider`
4
- > **框架**: Flutter
5
- > **严重程度**: 中等(导致列表布局细节偏差)
6
-
7
- ---
8
-
9
- ## 🔍 问题识别
10
-
11
- ### 用户描述关键词
12
- - "第一个/最后一个 item 高度不对"
13
- - "列表 padding 不均匀"
14
- - "divider 位置偏移"
15
- - "底部/顶部留白太多/太少"
16
-
17
- ### 问题特征
18
- - [ ] 列表首尾 item 与中间 item 高度不同
19
- - [ ] 使用统一 padding 导致视觉不平衡
20
- - [ ] 忽略 divider 在高度计算中的影响
21
- - [ ] 假设所有 item 高度相同
22
-
23
- ---
24
-
25
- ## 🎯 核心原理
26
-
27
- **根本原因**:设计稿中列表的首个和末尾 item 通常有不同的 padding,以平衡与容器边缘的视觉关系。
28
-
29
- ### 典型 Sketch 测量结果
30
-
31
- ```
32
- Menu Card_background: 350px
33
-
34
- Divider 位置:
35
- - Divider 1: y=63
36
- - Divider 2: y=119
37
- - Divider 3: y=175
38
- - Divider 4: y=231
39
- - Divider 5: y=287
40
-
41
- 区域高度计算:
42
- - Item 1: 0 → 63 = 63px
43
- - Item 2: 63 → 119 = 56px
44
- - Item 3: 119 → 175 = 56px
45
- - Item 4: 175 → 231 = 56px
46
- - Item 5: 231 → 287 = 56px
47
- - Item 6: 287 → 350 = 63px
48
- ```
49
-
50
- **结论**: 首尾 item 63px,中间 item 56px,**不是**统一高度!
51
-
52
- ---
53
-
54
- ## ❌ 常见错误
55
-
56
- ```dart
57
- // ❌ 错误: 统一 padding
58
- Padding(
59
- padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 16),
60
- child: MenuItem(),
61
- )
62
- ```
63
-
64
- ---
65
-
66
- ## ✅ 正确解决方案
67
-
68
- ### 1. 测量 Icon 精确位置
69
-
70
- ```javascript
71
- // 测量所有 icon 的 y 坐标
72
- const icons = sketch.find('[name*="Icon BG"]', menuCard);
73
- icons.forEach(icon => {
74
- if (icon.frame.height === 36) {
75
- console.log(`${icon.name}: y=${icon.frame.y}`);
76
- }
77
- });
78
-
79
- // 结果:
80
- // Item 1 Icon: y=20
81
- // Item 2 Icon: y=76
82
- // Item 3 Icon: y=132
83
- // ...
84
- ```
85
-
86
- ### 2. 计算每个 item 的 padding
87
-
88
- ```
89
- Item 1 (区域 0→63):
90
- - region_start = 0
91
- - icon_y = 20 → top = 20
92
- - icon_bottom = 56
93
- - divider_y = 63 → bottom = 63 - 56 - 1 = 6
94
- - 验证: 20 + 36 + 6 + 1 = 63 ✅
95
-
96
- Item 2 (区域 64→119):
97
- - region_start = 64 (divider1 + 1)
98
- - icon_y = 76 → top = 76 - 64 = 12
99
- - icon_bottom = 112
100
- - divider_y = 119 → bottom = 119 - 112 - 1 = 6
101
- - 验证: 12 + 36 + 6 + 1 = 55...
102
-
103
- 等等,56 - 1(divider) = 55,但 12+36+6=54?
104
- 让我重新计算:区域 = 56px 含 divider
105
- 内容区 = 55px,12 + 36 + 7 = 55 ✅
106
- ```
107
-
108
- ### 3. Flutter 精确实现
109
-
110
- ```dart
111
- Widget _buildMenuItem(int index, MenuItem item) {
112
- // Sketch 测量 (背景层 350px):
113
- // - Item 1: 区域 63px = top:20 + icon:36 + bottom:6 + divider:1
114
- // - Item 2-5: 区域 56px = top:12 + icon:36 + bottom:7 + divider:1
115
- // - Item 6: 区域 63px = top:12 + icon:36 + bottom:15 (无 divider)
116
-
117
- final isFirst = index == 0;
118
- final isLast = index == 5; // 6 个 item
119
-
120
- return Column(
121
- mainAxisSize: MainAxisSize.min,
122
- children: [
123
- Padding(
124
- padding: EdgeInsets.fromLTRB(
125
- 16,
126
- isFirst ? 20 : 12, // 首 item top 更大
127
- 16,
128
- isFirst ? 6 : (isLast ? 15 : 7), // 尾 item bottom 更大
129
- ),
130
- child: Row(
131
- children: [
132
- Icon(size: 36),
133
- SizedBox(width: 16),
134
- Expanded(child: Text(item.title)),
135
- ArrowIcon(),
136
- ],
137
- ),
138
- ),
139
-
140
- // Divider (最后一个不需要)
141
- if (!isLast)
142
- Container(
143
- margin: EdgeInsets.only(left: 68, right: 20),
144
- height: 1,
145
- color: Color(0x0F1C2B45),
146
- ),
147
- ],
148
- );
149
- }
150
- ```
151
-
152
- ---
153
-
154
- ## 🔑 关键公式
155
-
156
- ### 从 Sketch 测量计算 padding
157
-
158
- ```
159
- top_padding = icon.y - region_start
160
- bottom_padding = region_end - icon.bottom - divider_height
161
- ```
162
-
163
- 其中:
164
- - `region_start` = 上一个 divider.y + 1 (首 item 为 0)
165
- - `region_end` = 当前 divider.y (尾 item 为 background.height)
166
- - `icon.bottom` = icon.y + icon.height
167
- - `divider_height` = 1 (尾 item 为 0)
168
-
169
- ### 验证公式
170
-
171
- ```
172
- 区域高度 = top_padding + icon_height + bottom_padding + divider_height
173
- ```
174
-
175
- ---
176
-
177
- ## 📊 真实案例数据
178
-
179
- ### Profile Menu Card (350px)
180
-
181
- | Item | 区域 | Top | Icon | Bottom | Divider | 总计 |
182
- |------|------|-----|------|--------|---------|------|
183
- | 1 | 0→63 | 20 | 36 | 6 | 1 | 63 |
184
- | 2 | 63→119 | 12 | 36 | 7 | 1 | 56 |
185
- | 3 | 119→175 | 12 | 36 | 7 | 1 | 56 |
186
- | 4 | 175→231 | 12 | 36 | 7 | 1 | 56 |
187
- | 5 | 231→287 | 12 | 36 | 7 | 1 | 56 |
188
- | 6 | 287→350 | 12 | 36 | 15 | 0 | 63 |
189
-
190
- **总计**: 63 + 56×4 + 63 = 350px ✅
191
-
192
- ---
193
-
194
- ## ⚠️ 预防措施
195
-
196
- 1. **不要假设统一高度**: 始终测量首、中、尾三种 item
197
- 2. **测量 icon 实际 y 坐标**: 不要只看区域高度
198
- 3. **区分有无 divider**: 尾 item 通常无 divider
199
- 4. **使用背景层边界**: 不要用 Frame 高度
200
-
201
- ---
202
-
203
- ## 🔗 相关问题
204
-
205
- - [sketch-背景层高度.md](./sketch-背景层高度.md) - 背景层 vs Frame 高度
206
- - [layout-尺寸不匹配.md](./layout-尺寸不匹配.md) - 通用布局问题
207
-
208
- ---
209
-
210
- **创建日期**: 2026-01-19
211
- **最后更新**: 2026-01-19
212
- **来源**: Profile 页面 Menu Item 布局调试实战
@@ -1,135 +0,0 @@
1
- # Sketch 图标尺寸提取问题
2
-
3
- > **问题标签**: `sketch`, `icon`, `size`, `group`, `shape`
4
- > **框架**: Flutter
5
- > **严重程度**: 中等(还原精度)
6
-
7
- ---
8
-
9
- ## 🔍 问题识别
10
-
11
- ### 用户描述关键词
12
- - "图标尺寸与设计稿不符"
13
- - "设置了尺寸但没效果"
14
- - "Group 和 Shape 尺寸不一样"
15
- - "提取的尺寸是外层容器的"
16
-
17
- ### 问题特征
18
- - [ ] 从 Sketch 提取了图标尺寸
19
- - [ ] 实际显示比预期大或小
20
- - [ ] Sketch 中图标有 Group 包裹
21
- - [ ] Group 尺寸与内部 Shape 尺寸不同
22
-
23
- ---
24
-
25
- ## 🎯 核心原理
26
-
27
- **根本原因**:Sketch 中图标通常有两层结构,外层 Group 用于布局定位,内层 Shape 才是实际视觉尺寸。
28
-
29
- ```
30
- Sketch 图标结构:
31
- ├─ Group "Tab Icon" (22x22) ← 外层容器,用于布局
32
- │ └─ Shape "Icon_path" (14.67x14.67) ← 内部实际图形
33
- ```
34
-
35
- 如果提取外层 Group 的尺寸,图标会比设计稿看起来大。
36
-
37
- ---
38
-
39
- ## ✅ 正确解决方案
40
-
41
- ### 使用脚本提取内部 Shape 尺寸
42
-
43
- ```javascript
44
- // Sketch 脚本:提取图标的内部实际尺寸
45
- const sketch = require('sketch');
46
- const document = sketch.getSelectedDocument();
47
- const page = document.selectedPage;
48
-
49
- function extractIconInternalSize(frameName) {
50
- const frame = sketch.find(`[name="${frameName}"]`, page)[0];
51
- if (!frame) return console.log('Frame not found');
52
-
53
- function traverse(layer, parentY = 0) {
54
- const f = layer.frame;
55
- const absY = parentY + f.y;
56
-
57
- if (layer.type === 'Group' && layer.name.includes('Icon')) {
58
- console.log(`\n📦 ${layer.name} (外层 Group): ${f.width}x${f.height}`);
59
- layer.layers?.forEach(child => {
60
- if (child.type === 'Shape' || child.type === 'ShapePath') {
61
- const cf = child.frame;
62
- console.log(` └─ ${child.name} (内部图形): ${cf.width.toFixed(1)}x${cf.height.toFixed(1)} ← 使用这个`);
63
- }
64
- });
65
- }
66
- if (layer.layers) layer.layers.forEach(child => traverse(child, absY));
67
- }
68
- traverse(frame);
69
- }
70
-
71
- extractIconInternalSize('Frame Name');
72
- ```
73
-
74
- ### 输出示例
75
-
76
- ```
77
- 📦 Tab Recipient Icon (外层 Group): 22x22
78
- └─ Tab Recipient Icon_path_0 (内部图形): 14.7x14.7 ← 使用这个尺寸
79
- ```
80
-
81
- ### Flutter 中使用正确尺寸
82
-
83
- ```dart
84
- // ✅ 使用内部图形的实际尺寸
85
- SvgPicture.asset(
86
- 'assets/icons/recipient.svg',
87
- width: 15.0, // 14.7 取整
88
- height: 15.0,
89
- )
90
-
91
- // ❌ 错误:使用外层 Group 尺寸
92
- SvgPicture.asset(
93
- 'assets/icons/recipient.svg',
94
- width: 22.0, // 这是 Group 尺寸,图标会偏大
95
- height: 22.0,
96
- )
97
- ```
98
-
99
- ---
100
-
101
- ## 📝 验证检查清单
102
-
103
- 1. **确认提取的是 Shape 尺寸**
104
- - 不是 Group、Frame、Artboard 的尺寸
105
- - 查看脚本输出中带 ← 标记的行
106
-
107
- 2. **视觉对比验证**
108
- - 在模拟器/设备上与设计稿截图对比
109
- - 图标边缘应与设计稿完全重合
110
-
111
- 3. **属性使用验证**
112
- ```bash
113
- # 搜索确认尺寸属性被使用
114
- grep -n "iconSize" lib/widgets/my_widget.dart
115
- ```
116
-
117
- ---
118
-
119
- ## ❌ 常见错误排查路线(避免重复)
120
-
121
- | 尝试方向 | 为什么无效 | 浪费时间 |
122
- |----------|-----------|---------|
123
- | 调整 Flutter 中的尺寸 | 如果基准就错了,调来调去 | 3-5 轮对话 |
124
- | 添加 transform scale | Hack 方案,难以精确 | 2-3 轮对话 |
125
- | 重新导出 SVG | 如果不知道问题在哪,重复错误 | 2-3 轮对话 |
126
-
127
- **最佳做法**:先用脚本确认正确尺寸,再修改代码
128
-
129
- ---
130
-
131
- ## 📁 适用场景
132
-
133
- - ✅ TabBar 图标
134
- - ✅ 按钮内图标
135
- - ✅ 任何从 Sketch 导出的图标
@@ -1,201 +0,0 @@
1
- # Sketch 设计稿样式不完整提取问题
2
-
3
- > **问题标签**: `sketch`, `design`, `extraction`, `incomplete`, `一次性提取`
4
- > **框架**: Flutter
5
- > **严重程度**: 高(导致多轮对话和返工)
6
-
7
- ---
8
-
9
- ## 🔍 问题识别
10
-
11
- ### 用户描述关键词
12
- - "漏了xxx属性"
13
- - "渐变怎么还原"
14
- - "阴影参数是多少"
15
- - "这个图标是圆形的吗"
16
- - "设计稿上的圆角多大"
17
-
18
- ### 问题特征
19
- - [ ] AI 每次只查询单个属性(颜色、尺寸、阴影等)
20
- - [ ] 需要多轮对话才能获取完整样式信息
21
- - [ ] 使用近似值代替精确值(如 Material Icons 代替 SVG)
22
- - [ ] 假设属性而非验证(假设是圆形、假设颜色相同等)
23
-
24
- ---
25
-
26
- ## 🎯 核心原理
27
-
28
- **根本原因**:分散查询导致信息不完整,浪费时间。
29
-
30
- | 问题 | 表现 | 根因 |
31
- |------|------|------|
32
- | 属性读取不完整 | 漏读渐变、圆角、阴影参数 | 只读取部分属性 |
33
- | 假设而非验证 | 假设圆形/颜色/图标 | 未从设计稿验证 |
34
- | 使用近似值 | 用 Material Icons 代替 | 未导出原始 SVG |
35
- | 分散查询 | 多轮对话才获取完整信息 | 每次只查一个属性 |
36
-
37
- ---
38
-
39
- ## ✅ 正确解决方案
40
-
41
- ### 强制执行:一次性完整提取脚本
42
-
43
- **在还原任何 UI 元素前,必须使用以下脚本一次性提取所有属性:**
44
-
45
- ```javascript
46
- // Sketch 完整样式提取脚本 - 必须使用
47
- const sketch = require('sketch');
48
- const document = sketch.getSelectedDocument();
49
- const page = document.selectedPage;
50
-
51
- function extractFullStyle(layerName) {
52
- const layer = sketch.find(`[name="${layerName}"]`, page)[0];
53
- if (!layer) return console.log(`Layer "${layerName}" not found`);
54
-
55
- console.log('=== 基本信息 ===');
56
- console.log(`Name: ${layer.name} (${layer.type})`);
57
- console.log(`Frame: ${layer.frame.width}x${layer.frame.height} @ (${layer.frame.x}, ${layer.frame.y})`);
58
-
59
- const style = layer.style;
60
-
61
- // 1. 填充(颜色/渐变)
62
- console.log('=== 填充 ===');
63
- if (style.fills?.length) {
64
- style.fills.forEach((fill, i) => {
65
- console.log(`Fill ${i}: Type=${fill.fillType}, Enabled=${fill.enabled}`);
66
- if (fill.fillType === 'Color') {
67
- console.log(` Color: ${fill.color}`);
68
- } else if (fill.fillType === 'Gradient') {
69
- console.log(` Gradient: ${fill.gradient.gradientType}`);
70
- console.log(` From: (${fill.gradient.from.x.toFixed(2)}, ${fill.gradient.from.y.toFixed(2)})`);
71
- console.log(` To: (${fill.gradient.to.x.toFixed(2)}, ${fill.gradient.to.y.toFixed(2)})`);
72
- fill.gradient.stops.forEach((stop, j) => {
73
- console.log(` Stop ${j}: ${stop.color} @ ${stop.position}`);
74
- });
75
- }
76
- });
77
- } else {
78
- console.log('No fills');
79
- }
80
-
81
- // 2. 边框
82
- console.log('=== 边框 ===');
83
- if (style.borders?.length) {
84
- style.borders.forEach((border, i) => {
85
- console.log(`Border ${i}: Color=${border.color}, Width=${border.thickness}, Position=${border.position}, Enabled=${border.enabled}`);
86
- });
87
- } else {
88
- console.log('No borders');
89
- }
90
-
91
- // 3. 阴影
92
- console.log('=== 阴影 ===');
93
- if (style.shadows?.length) {
94
- style.shadows.forEach((s, i) => {
95
- console.log(`Shadow ${i}: Color=${s.color}, Offset=(${s.x}, ${s.y}), Blur=${s.blur}, Spread=${s.spread}`);
96
- });
97
- } else {
98
- console.log('No shadows');
99
- }
100
-
101
- // 4. 内阴影
102
- console.log('=== 内阴影 ===');
103
- if (style.innerShadows?.length) {
104
- style.innerShadows.forEach((s, i) => {
105
- console.log(`InnerShadow ${i}: Color=${s.color}, Offset=(${s.x}, ${s.y}), Blur=${s.blur}, Spread=${s.spread}`);
106
- });
107
- } else {
108
- console.log('No inner shadows');
109
- }
110
-
111
- // 5. 圆角
112
- console.log('=== 圆角 ===');
113
- if (layer.layers?.[0]?.points) {
114
- const points = layer.layers[0].points;
115
- const radii = points.map(p => p.cornerRadius);
116
- const allSame = radii.every(r => r === radii[0]);
117
- if (allSame) {
118
- console.log(`CornerRadius: ${radii[0]} (all corners)`);
119
- } else {
120
- console.log(`CornerRadius: [${radii.join(', ')}] (TL, TR, BR, BL)`);
121
- }
122
- } else if (layer.points) {
123
- const radii = layer.points.map(p => p.cornerRadius);
124
- console.log(`CornerRadius: ${radii[0]}`);
125
- } else {
126
- console.log('No corner radius (circle or custom shape)');
127
- }
128
-
129
- // 6. 不透明度
130
- console.log('=== 不透明度 ===');
131
- console.log(`Opacity: ${style.opacity}`);
132
-
133
- // 7. 子元素(如果是 Group)
134
- if (layer.layers?.length) {
135
- console.log('=== 子元素 ===');
136
- layer.layers.forEach(child => {
137
- console.log(`- ${child.name} (${child.type}): ${child.frame.width}x${child.frame.height}`);
138
- });
139
- }
140
- }
141
-
142
- // 使用示例
143
- extractFullStyle('Button Background');
144
- extractFullStyle('Icon');
145
- ```
146
-
147
- ### 图标导出:必须使用 SVG
148
-
149
- **禁止使用 Material Icons 或其他近似图标:**
150
-
151
- ```javascript
152
- // 导出图标 SVG
153
- const sketch = require('sketch');
154
- const layer = sketch.find('[name="Icon Name"]', sketch.getSelectedDocument().selectedPage)[0];
155
- if (layer) {
156
- const svg = sketch.export(layer, { formats: 'svg', output: false });
157
- console.log(svg.toString());
158
- }
159
- ```
160
-
161
- ### 还原检查清单(强制)
162
-
163
- 在还原任何 UI 元素前,必须确认以下所有属性:
164
-
165
- | 属性 | 检查项 | Flutter 对应 |
166
- |------|--------|--------------|
167
- | 尺寸 | width, height | `SizedBox(width:, height:)` |
168
- | 位置 | x, y | `Positioned(left:, top:)` |
169
- | 颜色/渐变 | fills[0] | `BoxDecoration(color:, gradient:)` |
170
- | 圆角 | cornerRadius | `BorderRadius.circular()` |
171
- | 边框 | borders | `Border.all()` |
172
- | 阴影 | shadows | `BoxShadow()` |
173
- | 透明度 | opacity | `Opacity(opacity:)` |
174
-
175
- ---
176
-
177
- ## ❌ 常见错误排查路线(避免重复)
178
-
179
- | 尝试方向 | 为什么无效 | 浪费时间 |
180
- |----------|-----------|---------|
181
- | 每次只查一个属性 | 需要多轮对话才能获取完整信息 | 5-10 轮 |
182
- | 假设是圆形 | 未验证 cornerRadius,可能是圆角矩形 | 2-3 轮 |
183
- | 使用 Material Icons | 与设计稿不完全一致 | 3-5 轮 |
184
- | 忽略渐变参数 | 只看到 from/to,未读取 stops | 2-4 轮 |
185
-
186
- ---
187
-
188
- ## 📁 适用场景
189
-
190
- - ✅ 从 Sketch 设计稿还原任何 UI 元素
191
- - ✅ 需要获取完整样式信息
192
- - ✅ 包含渐变、阴影、复杂圆角的设计
193
- - ✅ 图标还原(必须导出 SVG)
194
-
195
- ---
196
-
197
- ## 🔗 相关案例
198
-
199
- - [sketch-图标尺寸.md](./sketch-图标尺寸.md) - 图标尺寸提取错误
200
- - [svg-颜色异常.md](./svg-颜色异常.md) - SVG 颜色处理问题
201
- - [svg-未居中.md](./svg-未居中.md) - SVG 居中问题