text-to-design-mcp 0.3.1 → 0.5.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/README.md +19 -9
- package/dist/index.js +652 -386
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,19 +18,29 @@
|
|
|
18
18
|
|
|
19
19
|
**第一步:告诉 AI 工具**
|
|
20
20
|
|
|
21
|
-
后台服务不用手动安装,注册命令统一为 `npx -y text-to-design-mcp@latest`,任意 AI 工具都会自动化拉取运行。把下面需求丢给 AI
|
|
21
|
+
后台服务不用手动安装,注册命令统一为 `npx -y text-to-design-mcp@latest`,任意 AI 工具都会自动化拉取运行。把下面需求丢给 AI,它会自动注册并验证:
|
|
22
22
|
|
|
23
23
|
```
|
|
24
|
-
|
|
24
|
+
请帮我完成 text-to-design 安装,并按步骤汇报进度:
|
|
25
25
|
|
|
26
|
-
1.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
3. 验证服务能启动:
|
|
26
|
+
1. 注册 MCP 服务:用你工具原生的方式注册一个 stdio MCP server,
|
|
27
|
+
命令 npx -y text-to-design-mcp@latest(无需手动安装,npx 会自动拉取运行)。
|
|
28
|
+
|
|
29
|
+
2. 验证后台服务能启动:
|
|
31
30
|
timeout 5 npx -y text-to-design-mcp@latest
|
|
32
|
-
预期输出含 "[text-to-design-mcp] shim 模式" 或 "daemon 就绪"(首次会自动拉起常驻服务)
|
|
33
|
-
|
|
31
|
+
预期输出含 "[text-to-design-mcp] shim 模式" 或 "daemon 就绪"(首次会自动拉起常驻服务)。
|
|
32
|
+
|
|
33
|
+
3. 安装设计软件插件,下载并解压到用户目录:
|
|
34
|
+
cd ~ && npm pack text-to-design-ui
|
|
35
|
+
mkdir -p text-to-design-plugin
|
|
36
|
+
tar -xzf text-to-design-ui-*.tgz -C text-to-design-plugin --strip-components=1
|
|
37
|
+
|
|
38
|
+
4. 上述三步完成后,告知用户剩下两步需手动:
|
|
39
|
+
- 在即时设计里「插件 → 导入」,选择 ~/text-to-design-plugin/dist/manifest.json,
|
|
40
|
+
运行插件,面板显示「已连接」即就绪
|
|
41
|
+
- 重启 AI 会话,调用 jsd_ping 验证连通
|
|
42
|
+
|
|
43
|
+
5. 汇报完成情况。
|
|
34
44
|
```
|
|
35
45
|
|
|
36
46
|
若希望全局安装(装一次、不依赖联网拉取),可 `npm i -g text-to-design-mcp`,注册命令可简化为 `text-to-design-mcp`。
|
package/dist/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import { isTag } from "domhandler";
|
|
|
13
13
|
import { parseDocument } from "htmlparser2";
|
|
14
14
|
import Fuse from "fuse.js";
|
|
15
15
|
//#region package.json
|
|
16
|
-
var version = "0.
|
|
16
|
+
var version = "0.5.0";
|
|
17
17
|
//#endregion
|
|
18
18
|
//#region src/config.ts
|
|
19
19
|
var PORT = Number(process.env.TEXT_TO_DESIGN_MCP_PORT ?? 47812);
|
|
@@ -426,12 +426,175 @@ async function serveProxy(client) {
|
|
|
426
426
|
}
|
|
427
427
|
//#endregion
|
|
428
428
|
//#region ../shared/src/schemas.ts
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
var
|
|
429
|
+
var rgbSchema = z.object({
|
|
430
|
+
r: z.number().min(0).max(1).describe("红色通道,范围 0-1(0=无,1=满),如纯红为 1"),
|
|
431
|
+
g: z.number().min(0).max(1).describe("绿色通道,范围 0-1"),
|
|
432
|
+
b: z.number().min(0).max(1).describe("蓝色通道,范围 0-1")
|
|
433
|
+
});
|
|
434
|
+
var rgbaSchema = z.object({
|
|
435
|
+
r: z.number().min(0).max(1),
|
|
436
|
+
g: z.number().min(0).max(1),
|
|
437
|
+
b: z.number().min(0).max(1),
|
|
438
|
+
a: z.number().min(0).max(1)
|
|
439
|
+
});
|
|
440
|
+
var gradientStopSchema = z.object({
|
|
441
|
+
color: rgbaSchema,
|
|
442
|
+
position: z.number().min(0).max(1)
|
|
443
|
+
}).describe("渐变停止点,如 {color:{r:1,g:0,b:0,a:1}, position:0}(起点红色)和 {color:{r:0,g:0,b:1,a:1}, position:1}(终点蓝色)");
|
|
444
|
+
var transformSchema = z.tuple([z.tuple([
|
|
445
|
+
z.number(),
|
|
446
|
+
z.number(),
|
|
447
|
+
z.number()
|
|
448
|
+
]), z.tuple([
|
|
449
|
+
z.number(),
|
|
450
|
+
z.number(),
|
|
451
|
+
z.number()
|
|
452
|
+
])]).describe("变换矩阵,如 [[1,0,0],[0,1,0]] 表示无变换(Identity)");
|
|
453
|
+
var paintSchema = z.discriminatedUnion("type", [
|
|
454
|
+
z.object({
|
|
455
|
+
type: z.literal("SOLID"),
|
|
456
|
+
color: rgbSchema,
|
|
457
|
+
opacity: z.number().min(0).max(1).optional(),
|
|
458
|
+
visible: z.boolean().optional(),
|
|
459
|
+
blendMode: z.string().optional()
|
|
460
|
+
}),
|
|
461
|
+
z.object({
|
|
462
|
+
type: z.literal("GRADIENT_LINEAR"),
|
|
463
|
+
gradientStops: z.array(gradientStopSchema),
|
|
464
|
+
gradientTransform: transformSchema
|
|
465
|
+
}),
|
|
466
|
+
z.object({
|
|
467
|
+
type: z.literal("GRADIENT_RADIAL"),
|
|
468
|
+
gradientStops: z.array(gradientStopSchema),
|
|
469
|
+
gradientTransform: transformSchema
|
|
470
|
+
}),
|
|
471
|
+
z.object({
|
|
472
|
+
type: z.literal("GRADIENT_ANGULAR"),
|
|
473
|
+
gradientStops: z.array(gradientStopSchema),
|
|
474
|
+
gradientTransform: transformSchema
|
|
475
|
+
}),
|
|
476
|
+
z.object({
|
|
477
|
+
type: z.literal("IMAGE"),
|
|
478
|
+
imageHash: z.string(),
|
|
479
|
+
scaleMode: z.enum([
|
|
480
|
+
"FILL",
|
|
481
|
+
"FIT",
|
|
482
|
+
"CROP",
|
|
483
|
+
"TILE"
|
|
484
|
+
]).optional()
|
|
485
|
+
})
|
|
486
|
+
]);
|
|
487
|
+
var blendModeSchema = z.enum([
|
|
488
|
+
"PASS_THROUGH",
|
|
489
|
+
"NORMAL",
|
|
490
|
+
"DARKEN",
|
|
491
|
+
"MULTIPLY",
|
|
492
|
+
"COLOR_BURN",
|
|
493
|
+
"LIGHTEN",
|
|
494
|
+
"SCREEN",
|
|
495
|
+
"COLOR_DODGE",
|
|
496
|
+
"OVERLAY",
|
|
497
|
+
"SOFT_LIGHT",
|
|
498
|
+
"HARD_LIGHT",
|
|
499
|
+
"DIFFERENCE",
|
|
500
|
+
"EXCLUSION",
|
|
501
|
+
"HUE",
|
|
502
|
+
"SATURATION",
|
|
503
|
+
"COLOR",
|
|
504
|
+
"LUMINOSITY"
|
|
505
|
+
]);
|
|
506
|
+
var effectSchema = z.discriminatedUnion("type", [
|
|
507
|
+
z.object({
|
|
508
|
+
type: z.literal("DROP_SHADOW"),
|
|
509
|
+
color: rgbaSchema,
|
|
510
|
+
offset: z.object({
|
|
511
|
+
x: z.number(),
|
|
512
|
+
y: z.number()
|
|
513
|
+
}),
|
|
514
|
+
radius: z.number().min(0),
|
|
515
|
+
spread: z.number().optional(),
|
|
516
|
+
visible: z.boolean().optional(),
|
|
517
|
+
blendMode: blendModeSchema.default("NORMAL"),
|
|
518
|
+
showShadowBehindNode: z.boolean().optional()
|
|
519
|
+
}),
|
|
520
|
+
z.object({
|
|
521
|
+
type: z.literal("INNER_SHADOW"),
|
|
522
|
+
color: rgbaSchema,
|
|
523
|
+
offset: z.object({
|
|
524
|
+
x: z.number(),
|
|
525
|
+
y: z.number()
|
|
526
|
+
}),
|
|
527
|
+
radius: z.number().min(0),
|
|
528
|
+
spread: z.number().optional(),
|
|
529
|
+
visible: z.boolean().optional(),
|
|
530
|
+
blendMode: blendModeSchema.default("NORMAL")
|
|
531
|
+
}),
|
|
532
|
+
z.object({
|
|
533
|
+
type: z.literal("LAYER_BLUR"),
|
|
534
|
+
radius: z.number().min(0),
|
|
535
|
+
visible: z.boolean().optional()
|
|
536
|
+
}),
|
|
537
|
+
z.object({
|
|
538
|
+
type: z.literal("BACKGROUND_BLUR"),
|
|
539
|
+
radius: z.number().min(0),
|
|
540
|
+
visible: z.boolean().optional()
|
|
541
|
+
})
|
|
542
|
+
]);
|
|
543
|
+
var constraintTypeSchema = z.enum([
|
|
544
|
+
"MIN",
|
|
545
|
+
"MAX",
|
|
546
|
+
"STRETCH",
|
|
547
|
+
"CENTER",
|
|
548
|
+
"SCALE"
|
|
549
|
+
]);
|
|
550
|
+
var layoutGridSchema = z.object({
|
|
551
|
+
pattern: z.enum([
|
|
552
|
+
"ROWS",
|
|
553
|
+
"COLUMNS",
|
|
554
|
+
"GRID"
|
|
555
|
+
]).describe("网格类型:ROWS|COLUMNS|GRID"),
|
|
556
|
+
alignment: z.enum([
|
|
557
|
+
"MIN",
|
|
558
|
+
"MAX",
|
|
559
|
+
"CENTER",
|
|
560
|
+
"STRETCH"
|
|
561
|
+
]).optional().describe("对齐:MIN|MAX|CENTER|STRETCH"),
|
|
562
|
+
sectionSize: z.number().optional().describe("分节尺寸(px)"),
|
|
563
|
+
count: z.number().int().positive().optional().describe("网格数"),
|
|
564
|
+
gutterSize: z.number().optional().describe("沟槽尺寸(px)"),
|
|
565
|
+
offset: z.number().optional().describe("偏移(px)"),
|
|
566
|
+
visible: z.boolean().optional().describe("是否可见"),
|
|
567
|
+
color: rgbaSchema.optional().describe("网格颜色")
|
|
568
|
+
}).superRefine((val, ctx) => {
|
|
569
|
+
if (val.pattern === "GRID" && val.sectionSize == null) ctx.addIssue({
|
|
570
|
+
code: z.ZodIssueCode.custom,
|
|
571
|
+
message: "pattern 为 GRID 时,sectionSize 为必填项",
|
|
572
|
+
path: ["sectionSize"]
|
|
573
|
+
});
|
|
574
|
+
});
|
|
575
|
+
var vectorPathSchema = z.object({
|
|
576
|
+
data: z.string().describe("SVG path data,如 \"M0 0 L100 0 L100 100 Z\"(M=移动到,L=画线到,Z=闭合)"),
|
|
577
|
+
windingRule: z.enum(["NONZERO", "EVENODD"]).optional().describe("环绕规则:NONZERO|EVENODD")
|
|
578
|
+
});
|
|
579
|
+
var fontNameSchema = z.object({
|
|
580
|
+
family: z.string(),
|
|
581
|
+
style: z.string()
|
|
582
|
+
});
|
|
583
|
+
var lineHeightSchema = z.union([
|
|
584
|
+
z.object({
|
|
585
|
+
value: z.number(),
|
|
586
|
+
unit: z.literal("PIXELS")
|
|
587
|
+
}).describe("固定行高:{value: 数值, unit: \"PIXELS\"},如 {value: 24, unit: \"PIXELS\"}"),
|
|
588
|
+
z.object({
|
|
589
|
+
value: z.number(),
|
|
590
|
+
unit: z.literal("PERCENT")
|
|
591
|
+
}).describe("百分比行高:{value: 数值, unit: \"PERCENT\"},如 {value: 150, unit: \"PERCENT\"}"),
|
|
592
|
+
z.object({ unit: z.literal("AUTO") }).describe("自动行高:{unit: \"AUTO\"},无需传 value")
|
|
593
|
+
]);
|
|
594
|
+
var letterSpacingSchema = z.object({
|
|
595
|
+
value: z.number(),
|
|
596
|
+
unit: z.enum(["PIXELS", "PERCENT"])
|
|
597
|
+
});
|
|
435
598
|
var nodeTypeSchema = z.enum([
|
|
436
599
|
"SLICE",
|
|
437
600
|
"FRAME",
|
|
@@ -448,29 +611,135 @@ var nodeTypeSchema = z.enum([
|
|
|
448
611
|
"RECTANGLE",
|
|
449
612
|
"TEXT"
|
|
450
613
|
]);
|
|
451
|
-
var
|
|
452
|
-
|
|
614
|
+
var transformPropsSchema = z.object({
|
|
615
|
+
x: z.number().optional().describe("X 坐标(px)"),
|
|
616
|
+
y: z.number().optional().describe("Y 坐标(px)"),
|
|
617
|
+
width: z.number().optional().describe("宽度(px)"),
|
|
618
|
+
height: z.number().optional().describe("高度(px)"),
|
|
619
|
+
rotation: z.number().optional().describe("旋转角度(deg)"),
|
|
620
|
+
opacity: z.number().optional().describe("不透明度 0-1"),
|
|
621
|
+
visible: z.boolean().optional().describe("是否可见"),
|
|
622
|
+
locked: z.boolean().optional().describe("锁定图层")
|
|
623
|
+
});
|
|
624
|
+
var strokePropsSchema = z.object({
|
|
625
|
+
strokes: z.array(paintSchema).optional().describe("描边列表(Paint 数组)"),
|
|
626
|
+
strokeWeight: z.number().optional().describe("描边宽度(px)"),
|
|
627
|
+
strokeTopWeight: z.number().optional().describe("描边顶部宽(px)"),
|
|
628
|
+
strokeBottomWeight: z.number().optional().describe("描边底部宽(px)"),
|
|
629
|
+
strokeLeftWeight: z.number().optional().describe("描边左侧宽(px)"),
|
|
630
|
+
strokeRightWeight: z.number().optional().describe("描边右侧宽(px)"),
|
|
631
|
+
strokeAlign: z.enum([
|
|
632
|
+
"CENTER",
|
|
633
|
+
"INSIDE",
|
|
634
|
+
"OUTSIDE"
|
|
635
|
+
]).optional().describe("描边对齐:CENTER|INSIDE|OUTSIDE"),
|
|
636
|
+
strokeCap: z.enum([
|
|
637
|
+
"NONE",
|
|
638
|
+
"ROUND",
|
|
639
|
+
"SQUARE",
|
|
640
|
+
"ARROW_LINES",
|
|
641
|
+
"ARROW_EQUILATERAL"
|
|
642
|
+
]).optional().describe("描边端点:NONE|ROUND|SQUARE|ARROW_LINES|ARROW_EQUILATERAL"),
|
|
643
|
+
strokeJoin: z.enum([
|
|
644
|
+
"MITER",
|
|
645
|
+
"BEVEL",
|
|
646
|
+
"ROUND"
|
|
647
|
+
]).optional().describe("描边连接:MITER|BEVEL|ROUND"),
|
|
648
|
+
dashPattern: z.array(z.number()).optional().describe("虚线段数组,如 [4,4]")
|
|
649
|
+
});
|
|
650
|
+
var cornerPropsSchema = z.object({
|
|
651
|
+
cornerRadius: z.number().optional().describe("圆角半径(px),四角统一"),
|
|
652
|
+
topLeftRadius: z.number().optional().describe("左上圆角(px)"),
|
|
653
|
+
topRightRadius: z.number().optional().describe("右上圆角(px)"),
|
|
654
|
+
bottomLeftRadius: z.number().optional().describe("左下圆角(px)"),
|
|
655
|
+
bottomRightRadius: z.number().optional().describe("右下圆角(px)")
|
|
656
|
+
});
|
|
657
|
+
var textPropsSchema = z.object({
|
|
658
|
+
characters: z.string().optional().describe("文本内容"),
|
|
659
|
+
fontSize: z.number().optional().describe("字号(px)"),
|
|
660
|
+
fontName: fontNameSchema.optional().describe("字体:{family,style}"),
|
|
661
|
+
textAlignHorizontal: z.enum([
|
|
662
|
+
"LEFT",
|
|
663
|
+
"CENTER",
|
|
664
|
+
"RIGHT",
|
|
665
|
+
"JUSTIFIED"
|
|
666
|
+
]).optional().describe("水平对齐:LEFT|CENTER|RIGHT|JUSTIFIED"),
|
|
667
|
+
textAlignVertical: z.enum([
|
|
668
|
+
"TOP",
|
|
669
|
+
"CENTER",
|
|
670
|
+
"BOTTOM"
|
|
671
|
+
]).optional().describe("垂直对齐:TOP|CENTER|BOTTOM"),
|
|
672
|
+
textAutoResize: z.enum([
|
|
673
|
+
"NONE",
|
|
674
|
+
"WIDTH_AND_HEIGHT",
|
|
675
|
+
"HEIGHT",
|
|
676
|
+
"TRUNCATE"
|
|
677
|
+
]).optional().describe("文本自适应:NONE|WIDTH_AND_HEIGHT|HEIGHT|TRUNCATE"),
|
|
678
|
+
textCase: z.enum([
|
|
679
|
+
"ORIGINAL",
|
|
680
|
+
"UPPER",
|
|
681
|
+
"LOWER",
|
|
682
|
+
"TITLE"
|
|
683
|
+
]).optional().describe("文本大小写:ORIGINAL|UPPER|LOWER|TITLE"),
|
|
684
|
+
textDecoration: z.enum([
|
|
685
|
+
"NONE",
|
|
686
|
+
"UNDERLINE",
|
|
687
|
+
"STRIKETHROUGH"
|
|
688
|
+
]).optional().describe("文本装饰:NONE|UNDERLINE|STRIKETHROUGH"),
|
|
689
|
+
lineHeight: lineHeightSchema.optional().describe("行高:{value,unit}"),
|
|
690
|
+
letterSpacing: letterSpacingSchema.optional().describe("字距:{value,unit}")
|
|
691
|
+
});
|
|
692
|
+
var autoLayoutPropsSchema = z.object({
|
|
693
|
+
layoutMode: z.enum([
|
|
694
|
+
"NONE",
|
|
695
|
+
"HORIZONTAL",
|
|
696
|
+
"VERTICAL"
|
|
697
|
+
]).optional().describe("自动布局方向:NONE|HORIZONTAL|VERTICAL"),
|
|
453
698
|
itemSpacing: z.number().optional().describe("自动布局项间距(px)"),
|
|
454
|
-
padding: z.number().optional().describe("自动布局内边距,四边统一(px)"),
|
|
455
699
|
paddingTop: z.number().optional().describe("上内边距(px)"),
|
|
456
700
|
paddingRight: z.number().optional().describe("右内边距(px)"),
|
|
457
701
|
paddingBottom: z.number().optional().describe("下内边距(px)"),
|
|
458
702
|
paddingLeft: z.number().optional().describe("左内边距(px)"),
|
|
459
|
-
primaryAxisSizingMode:
|
|
460
|
-
counterAxisSizingMode:
|
|
461
|
-
primaryAxisAlignItems:
|
|
703
|
+
primaryAxisSizingMode: z.enum(["FIXED", "AUTO"]).optional().describe("主轴尺寸模式:FIXED|AUTO"),
|
|
704
|
+
counterAxisSizingMode: z.enum(["FIXED", "AUTO"]).optional().describe("交叉轴尺寸模式:FIXED|AUTO"),
|
|
705
|
+
primaryAxisAlignItems: z.enum([
|
|
462
706
|
"MIN",
|
|
463
707
|
"MAX",
|
|
464
708
|
"CENTER",
|
|
465
709
|
"SPACE_BETWEEN"
|
|
466
710
|
]).optional().describe("主轴对齐:MIN|MAX|CENTER|SPACE_BETWEEN"),
|
|
467
|
-
counterAxisAlignItems:
|
|
711
|
+
counterAxisAlignItems: z.enum([
|
|
468
712
|
"MIN",
|
|
469
713
|
"MAX",
|
|
470
714
|
"CENTER"
|
|
471
|
-
]).optional().describe("交叉轴对齐:MIN|MAX|CENTER")
|
|
715
|
+
]).optional().describe("交叉轴对齐:MIN|MAX|CENTER"),
|
|
716
|
+
layoutGrow: z.number().optional().describe("自动布局内伸缩系数"),
|
|
717
|
+
layoutAlign: z.enum([
|
|
718
|
+
"MIN",
|
|
719
|
+
"CENTER",
|
|
720
|
+
"MAX",
|
|
721
|
+
"STRETCH",
|
|
722
|
+
"INHERIT"
|
|
723
|
+
]).optional().describe("自动布局内对齐:MIN|CENTER|MAX|STRETCH|INHERIT")
|
|
472
724
|
});
|
|
473
|
-
var
|
|
725
|
+
var visualPropsSchema = z.object({
|
|
726
|
+
fills: z.array(paintSchema).optional().describe("填充列表(Paint 数组)"),
|
|
727
|
+
blendMode: blendModeSchema.optional().describe("混合模式"),
|
|
728
|
+
effects: z.array(effectSchema).optional().describe("效果列表(阴影/模糊,可多层叠加)"),
|
|
729
|
+
constraints: z.object({
|
|
730
|
+
horizontal: constraintTypeSchema.describe("水平约束:MIN|MAX|STRETCH|CENTER|SCALE"),
|
|
731
|
+
vertical: constraintTypeSchema.describe("垂直约束:MIN|MAX|STRETCH|CENTER|SCALE")
|
|
732
|
+
}).optional().describe("自动布局中的约束"),
|
|
733
|
+
clipsContent: z.boolean().optional().describe("是否裁剪溢出内容"),
|
|
734
|
+
cornerSmoothing: z.number().optional().describe("圆角平滑度 0-1"),
|
|
735
|
+
layoutGrids: z.array(layoutGridSchema).optional().describe("布局网格(参考线)"),
|
|
736
|
+
arcData: z.object({
|
|
737
|
+
startingAngle: z.number().describe("起始角度(radians)"),
|
|
738
|
+
endingAngle: z.number().describe("结束角度(radians)"),
|
|
739
|
+
innerRadius: z.number().describe("内半径(0-1 ratio)")
|
|
740
|
+
}).optional().describe("环形路径参数(弧线)")
|
|
741
|
+
});
|
|
742
|
+
var serializedNodeSchema = z.lazy(() => z.object({
|
|
474
743
|
id: z.string(),
|
|
475
744
|
name: z.string(),
|
|
476
745
|
type: nodeTypeSchema,
|
|
@@ -480,17 +749,16 @@ var serializedNodeSchema = z.object({
|
|
|
480
749
|
height: z.number().optional(),
|
|
481
750
|
rotation: z.number().optional(),
|
|
482
751
|
opacity: z.number().optional(),
|
|
752
|
+
visible: z.boolean().optional(),
|
|
483
753
|
locked: z.boolean().optional(),
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
stops: z.array(z.object({
|
|
488
|
-
color: z.string(),
|
|
489
|
-
position: z.number()
|
|
490
|
-
}))
|
|
491
|
-
}).optional(),
|
|
492
|
-
stroke: z.string().optional(),
|
|
754
|
+
parentId: z.string().optional(),
|
|
755
|
+
fills: z.array(paintSchema).optional(),
|
|
756
|
+
strokes: z.array(paintSchema).optional(),
|
|
493
757
|
strokeWeight: z.number().optional(),
|
|
758
|
+
strokeTopWeight: z.number().optional(),
|
|
759
|
+
strokeBottomWeight: z.number().optional(),
|
|
760
|
+
strokeLeftWeight: z.number().optional(),
|
|
761
|
+
strokeRightWeight: z.number().optional(),
|
|
494
762
|
strokeAlign: z.enum([
|
|
495
763
|
"CENTER",
|
|
496
764
|
"INSIDE",
|
|
@@ -510,61 +778,49 @@ var serializedNodeSchema = z.object({
|
|
|
510
778
|
]).optional(),
|
|
511
779
|
dashPattern: z.array(z.number()).optional(),
|
|
512
780
|
cornerSmoothing: z.number().optional(),
|
|
513
|
-
blendMode:
|
|
781
|
+
blendMode: blendModeSchema.optional(),
|
|
514
782
|
constraints: z.object({
|
|
515
|
-
horizontal:
|
|
516
|
-
|
|
517
|
-
"MAX",
|
|
518
|
-
"STRETCH",
|
|
519
|
-
"CENTER",
|
|
520
|
-
"SCALE"
|
|
521
|
-
]),
|
|
522
|
-
vertical: z.enum([
|
|
523
|
-
"MIN",
|
|
524
|
-
"MAX",
|
|
525
|
-
"STRETCH",
|
|
526
|
-
"CENTER",
|
|
527
|
-
"SCALE"
|
|
528
|
-
])
|
|
783
|
+
horizontal: constraintTypeSchema,
|
|
784
|
+
vertical: constraintTypeSchema
|
|
529
785
|
}).optional(),
|
|
530
|
-
layoutGrids: z.array(
|
|
531
|
-
pattern: z.enum([
|
|
532
|
-
"ROWS",
|
|
533
|
-
"COLUMNS",
|
|
534
|
-
"GRID"
|
|
535
|
-
]),
|
|
536
|
-
alignment: z.enum([
|
|
537
|
-
"MIN",
|
|
538
|
-
"MAX",
|
|
539
|
-
"STRETCH",
|
|
540
|
-
"CENTER"
|
|
541
|
-
]).optional(),
|
|
542
|
-
gutterSize: z.number().optional(),
|
|
543
|
-
count: z.number().optional(),
|
|
544
|
-
sectionSize: z.number().optional(),
|
|
545
|
-
offset: z.number().optional(),
|
|
546
|
-
visible: z.boolean().optional(),
|
|
547
|
-
color: z.string().optional()
|
|
548
|
-
})).optional(),
|
|
786
|
+
layoutGrids: z.array(layoutGridSchema).optional(),
|
|
549
787
|
clipsContent: z.boolean().optional(),
|
|
550
788
|
arcData: z.object({
|
|
551
789
|
startingAngle: z.number(),
|
|
552
790
|
endingAngle: z.number(),
|
|
553
791
|
innerRadius: z.number()
|
|
554
792
|
}).optional(),
|
|
555
|
-
|
|
556
|
-
x: z.number(),
|
|
557
|
-
y: z.number(),
|
|
558
|
-
radius: z.number(),
|
|
559
|
-
color: z.string()
|
|
560
|
-
}).optional(),
|
|
793
|
+
effects: z.array(effectSchema).optional(),
|
|
561
794
|
cornerRadius: z.number().optional(),
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
795
|
+
topLeftRadius: z.number().optional(),
|
|
796
|
+
topRightRadius: z.number().optional(),
|
|
797
|
+
bottomLeftRadius: z.number().optional(),
|
|
798
|
+
bottomRightRadius: z.number().optional(),
|
|
566
799
|
pointCount: z.number().optional(),
|
|
567
|
-
|
|
800
|
+
innerRadius: z.number().optional(),
|
|
801
|
+
layoutMode: z.enum([
|
|
802
|
+
"NONE",
|
|
803
|
+
"HORIZONTAL",
|
|
804
|
+
"VERTICAL"
|
|
805
|
+
]).optional(),
|
|
806
|
+
itemSpacing: z.number().optional(),
|
|
807
|
+
paddingTop: z.number().optional(),
|
|
808
|
+
paddingRight: z.number().optional(),
|
|
809
|
+
paddingBottom: z.number().optional(),
|
|
810
|
+
paddingLeft: z.number().optional(),
|
|
811
|
+
primaryAxisSizingMode: z.enum(["FIXED", "AUTO"]).optional(),
|
|
812
|
+
counterAxisSizingMode: z.enum(["FIXED", "AUTO"]).optional(),
|
|
813
|
+
primaryAxisAlignItems: z.enum([
|
|
814
|
+
"MIN",
|
|
815
|
+
"MAX",
|
|
816
|
+
"CENTER",
|
|
817
|
+
"SPACE_BETWEEN"
|
|
818
|
+
]).optional(),
|
|
819
|
+
counterAxisAlignItems: z.enum([
|
|
820
|
+
"MIN",
|
|
821
|
+
"MAX",
|
|
822
|
+
"CENTER"
|
|
823
|
+
]).optional(),
|
|
568
824
|
layoutGrow: z.number().optional(),
|
|
569
825
|
layoutAlign: z.enum([
|
|
570
826
|
"MIN",
|
|
@@ -574,11 +830,16 @@ var serializedNodeSchema = z.object({
|
|
|
574
830
|
"INHERIT"
|
|
575
831
|
]).optional(),
|
|
576
832
|
childCount: z.number().optional(),
|
|
577
|
-
children: z.array(
|
|
833
|
+
children: z.array(serializedNodeSchema).optional(),
|
|
578
834
|
characters: z.string().optional(),
|
|
579
835
|
fontSize: z.number().optional(),
|
|
580
|
-
|
|
581
|
-
|
|
836
|
+
fontName: fontNameSchema.optional(),
|
|
837
|
+
textAlignHorizontal: z.enum([
|
|
838
|
+
"LEFT",
|
|
839
|
+
"CENTER",
|
|
840
|
+
"RIGHT",
|
|
841
|
+
"JUSTIFIED"
|
|
842
|
+
]).optional(),
|
|
582
843
|
textAlignVertical: z.enum([
|
|
583
844
|
"TOP",
|
|
584
845
|
"CENTER",
|
|
@@ -601,14 +862,20 @@ var serializedNodeSchema = z.object({
|
|
|
601
862
|
"UNDERLINE",
|
|
602
863
|
"STRIKETHROUGH"
|
|
603
864
|
]).optional(),
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
865
|
+
lineHeight: lineHeightSchema.optional(),
|
|
866
|
+
letterSpacing: letterSpacingSchema.optional(),
|
|
867
|
+
vectorPaths: z.array(vectorPathSchema).optional(),
|
|
868
|
+
booleanOperation: z.enum([
|
|
869
|
+
"UNION",
|
|
870
|
+
"SUBTRACT",
|
|
871
|
+
"INTERSECT",
|
|
872
|
+
"EXCLUDE"
|
|
873
|
+
]).optional(),
|
|
874
|
+
isMask: z.boolean().optional(),
|
|
608
875
|
variantProperties: z.record(z.string(), z.string()).optional(),
|
|
609
876
|
mainComponentId: z.string().optional(),
|
|
610
877
|
variantGroupProperties: z.record(z.string(), z.array(z.string())).optional()
|
|
611
|
-
});
|
|
878
|
+
}));
|
|
612
879
|
var createdResultSchema = z.object({ created: z.union([serializedNodeSchema, z.array(serializedNodeSchema)]) });
|
|
613
880
|
var updatedResultSchema = z.object({ updated: z.array(serializedNodeSchema) });
|
|
614
881
|
var pingResultSchema = z.object({
|
|
@@ -655,37 +922,29 @@ var listFontsResultSchema = z.object({
|
|
|
655
922
|
count: z.number()
|
|
656
923
|
});
|
|
657
924
|
z.object({});
|
|
658
|
-
z.object({ depth: z.number().optional().describe("
|
|
659
|
-
var
|
|
660
|
-
"frame",
|
|
661
|
-
"rect",
|
|
662
|
-
"ellipse",
|
|
663
|
-
"line",
|
|
664
|
-
"polygon",
|
|
665
|
-
"star",
|
|
666
|
-
"vector",
|
|
667
|
-
"boolean",
|
|
668
|
-
"text"
|
|
669
|
-
]);
|
|
670
|
-
var executeNodeSchema = z.lazy(() => z.object({
|
|
671
|
-
op: executeOpSchema.optional().describe("操作类型:frame|rect|ellipse|line|text|vector|…(见 op 枚举,缺省 rect)"),
|
|
925
|
+
z.object({ depth: z.number().optional().describe("序列化深度:0=仅自身,1=含直接子节点,2=含孙节点;缺省 2") });
|
|
926
|
+
var baseNodeFields = {
|
|
672
927
|
name: z.string().optional().describe("图层名"),
|
|
673
928
|
x: z.number().optional().describe("X 坐标(px)"),
|
|
674
929
|
y: z.number().optional().describe("Y 坐标(px)"),
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
fill: z.string().optional().describe("填充色,hex(#ff0000)或 rgba(r,g,b,a)"),
|
|
678
|
-
radius: z.number().optional().describe("圆角半径(px),四角统一"),
|
|
679
|
-
radiusTopLeft: z.number().optional().describe("左上圆角(px)"),
|
|
680
|
-
radiusTopRight: z.number().optional().describe("右上圆角(px)"),
|
|
681
|
-
radiusBottomLeft: z.number().optional().describe("左下圆角(px)"),
|
|
682
|
-
radiusBottomRight: z.number().optional().describe("右下圆角(px)"),
|
|
930
|
+
width: z.number().optional().describe("宽度(px)"),
|
|
931
|
+
height: z.number().optional().describe("高度(px)"),
|
|
683
932
|
rotation: z.number().optional().describe("旋转角度(deg)"),
|
|
684
933
|
opacity: z.number().optional().describe("不透明度 0-1"),
|
|
934
|
+
visible: z.boolean().optional().describe("是否可见"),
|
|
685
935
|
locked: z.boolean().optional().describe("锁定图层"),
|
|
686
|
-
|
|
936
|
+
isMask: z.boolean().optional().describe("是否为蒙版"),
|
|
937
|
+
children: z.array(z.any()).max(10).optional().describe("子节点数组(GROUP/BOOLEAN_OPERATION 使用,递归嵌套,最多 10 个直接子节点)")
|
|
938
|
+
};
|
|
939
|
+
var visualFields = {
|
|
940
|
+
fills: z.array(paintSchema).optional().describe("填充列表(Paint 数组)"),
|
|
941
|
+
strokes: z.array(paintSchema).optional().describe("描边列表(Paint 数组)"),
|
|
687
942
|
strokeWeight: z.number().optional().describe("描边宽度(px)"),
|
|
688
|
-
|
|
943
|
+
strokeTopWeight: z.number().optional().describe("描边顶部宽(px)"),
|
|
944
|
+
strokeBottomWeight: z.number().optional().describe("描边底部宽(px)"),
|
|
945
|
+
strokeLeftWeight: z.number().optional().describe("描边左侧宽(px)"),
|
|
946
|
+
strokeRightWeight: z.number().optional().describe("描边右侧宽(px)"),
|
|
947
|
+
strokeAlign: z.enum([
|
|
689
948
|
"CENTER",
|
|
690
949
|
"INSIDE",
|
|
691
950
|
"OUTSIDE"
|
|
@@ -703,101 +962,126 @@ var executeNodeSchema = z.lazy(() => z.object({
|
|
|
703
962
|
"ROUND"
|
|
704
963
|
]).optional().describe("描边连接:MITER|BEVEL|ROUND"),
|
|
705
964
|
dashPattern: z.array(z.number()).optional().describe("虚线段数组,如 [4,4]"),
|
|
706
|
-
|
|
707
|
-
|
|
965
|
+
blendMode: blendModeSchema.optional().describe("混合模式"),
|
|
966
|
+
effects: z.array(effectSchema).optional().describe("效果列表(阴影/模糊,可多层叠加)"),
|
|
708
967
|
constraints: z.object({
|
|
709
|
-
horizontal:
|
|
710
|
-
|
|
711
|
-
"MAX",
|
|
712
|
-
"STRETCH",
|
|
713
|
-
"CENTER",
|
|
714
|
-
"SCALE"
|
|
715
|
-
]).describe("水平约束:MIN|MAX|STRETCH|CENTER|SCALE"),
|
|
716
|
-
vertical: pre([
|
|
717
|
-
"MIN",
|
|
718
|
-
"MAX",
|
|
719
|
-
"STRETCH",
|
|
720
|
-
"CENTER",
|
|
721
|
-
"SCALE"
|
|
722
|
-
]).describe("垂直约束:MIN|MAX|STRETCH|CENTER|SCALE")
|
|
968
|
+
horizontal: constraintTypeSchema.describe("水平约束:MIN|MAX|STRETCH|CENTER|SCALE"),
|
|
969
|
+
vertical: constraintTypeSchema.describe("垂直约束:MIN|MAX|STRETCH|CENTER|SCALE")
|
|
723
970
|
}).optional().describe("自动布局中的约束"),
|
|
724
|
-
layoutGrids: z.array(z.object({
|
|
725
|
-
pattern: z.enum([
|
|
726
|
-
"ROWS",
|
|
727
|
-
"COLUMNS",
|
|
728
|
-
"GRID"
|
|
729
|
-
]).describe("网格类型:ROWS|COLUMNS|GRID"),
|
|
730
|
-
alignment: z.enum([
|
|
731
|
-
"MIN",
|
|
732
|
-
"MAX",
|
|
733
|
-
"STRETCH",
|
|
734
|
-
"CENTER"
|
|
735
|
-
]).optional().describe("对齐:MIN|MAX|STRETCH|CENTER"),
|
|
736
|
-
gutterSize: z.number().optional().describe("沟槽尺寸(px)"),
|
|
737
|
-
count: z.number().optional().describe("网格数"),
|
|
738
|
-
sectionSize: z.number().optional().describe("分节尺寸(px)"),
|
|
739
|
-
offset: z.number().optional().describe("偏移(px)"),
|
|
740
|
-
visible: z.boolean().optional().describe("是否可见"),
|
|
741
|
-
color: z.string().optional().describe("网格颜色,hex"),
|
|
742
|
-
colorOpacity: z.number().optional().describe("网格颜色不透明度 0-1")
|
|
743
|
-
})).optional().describe("布局网格(参考线)"),
|
|
744
971
|
clipsContent: z.boolean().optional().describe("是否裁剪溢出内容"),
|
|
972
|
+
cornerSmoothing: z.number().optional().describe("圆角平滑度 0-1"),
|
|
973
|
+
layoutGrids: z.array(layoutGridSchema).optional().describe("布局网格(参考线)")
|
|
974
|
+
};
|
|
975
|
+
var frameNodeSchema = z.object({
|
|
976
|
+
type: z.literal("FRAME"),
|
|
977
|
+
...baseNodeFields,
|
|
978
|
+
layoutMode: z.enum([
|
|
979
|
+
"NONE",
|
|
980
|
+
"HORIZONTAL",
|
|
981
|
+
"VERTICAL"
|
|
982
|
+
]).optional().describe("自动布局方向:NONE=无布局,HORIZONTAL=水平排列,VERTICAL=垂直排列。传 itemSpacing/padding*/primaryAxis* 等布局属性前必须先设为 HORIZONTAL 或 VERTICAL"),
|
|
983
|
+
itemSpacing: z.number().optional().describe("自动布局项间距(px),需先设 layoutMode"),
|
|
984
|
+
paddingTop: z.number().optional().describe("上内边距(px)"),
|
|
985
|
+
paddingRight: z.number().optional().describe("右内边距(px)"),
|
|
986
|
+
paddingBottom: z.number().optional().describe("下内边距(px)"),
|
|
987
|
+
paddingLeft: z.number().optional().describe("左内边距(px)"),
|
|
988
|
+
primaryAxisSizingMode: z.enum(["FIXED", "AUTO"]).optional().describe("主轴尺寸模式:FIXED|AUTO"),
|
|
989
|
+
counterAxisSizingMode: z.enum(["FIXED", "AUTO"]).optional().describe("交叉轴尺寸模式:FIXED|AUTO"),
|
|
990
|
+
primaryAxisAlignItems: z.enum([
|
|
991
|
+
"MIN",
|
|
992
|
+
"MAX",
|
|
993
|
+
"CENTER",
|
|
994
|
+
"SPACE_BETWEEN"
|
|
995
|
+
]).optional().describe("主轴对齐:MIN|MAX|CENTER|SPACE_BETWEEN"),
|
|
996
|
+
counterAxisAlignItems: z.enum([
|
|
997
|
+
"MIN",
|
|
998
|
+
"MAX",
|
|
999
|
+
"CENTER"
|
|
1000
|
+
]).optional().describe("交叉轴对齐:MIN|MAX|CENTER"),
|
|
1001
|
+
layoutGrow: z.number().optional().describe("自动布局内伸缩系数"),
|
|
1002
|
+
layoutAlign: z.enum([
|
|
1003
|
+
"MIN",
|
|
1004
|
+
"CENTER",
|
|
1005
|
+
"MAX",
|
|
1006
|
+
"STRETCH",
|
|
1007
|
+
"INHERIT"
|
|
1008
|
+
]).optional().describe("自动布局内对齐:MIN|CENTER|MAX|STRETCH|INHERIT"),
|
|
1009
|
+
...visualFields
|
|
1010
|
+
}).superRefine((val, ctx) => {
|
|
1011
|
+
if ((val.itemSpacing != null || val.paddingTop != null || val.paddingRight != null || val.paddingBottom != null || val.paddingLeft != null || val.primaryAxisSizingMode != null || val.counterAxisSizingMode != null || val.primaryAxisAlignItems != null || val.counterAxisAlignItems != null) && (val.layoutMode == null || val.layoutMode === "NONE")) ctx.addIssue({
|
|
1012
|
+
code: z.ZodIssueCode.custom,
|
|
1013
|
+
message: "传 itemSpacing/padding*/primaryAxis*/counterAxis* 等布局属性前,layoutMode 必须设为 HORIZONTAL 或 VERTICAL",
|
|
1014
|
+
path: ["layoutMode"]
|
|
1015
|
+
});
|
|
1016
|
+
}).describe("FRAME=容器(可 auto-layout)");
|
|
1017
|
+
var rectangleNodeSchema = z.object({
|
|
1018
|
+
type: z.literal("RECTANGLE"),
|
|
1019
|
+
...baseNodeFields,
|
|
1020
|
+
cornerRadius: z.number().optional().describe("圆角半径(px),四角统一"),
|
|
1021
|
+
topLeftRadius: z.number().optional().describe("左上圆角(px)"),
|
|
1022
|
+
topRightRadius: z.number().optional().describe("右上圆角(px)"),
|
|
1023
|
+
bottomLeftRadius: z.number().optional().describe("左下圆角(px)"),
|
|
1024
|
+
bottomRightRadius: z.number().optional().describe("右下圆角(px)"),
|
|
1025
|
+
...visualFields
|
|
1026
|
+
}).describe("RECTANGLE=矩形");
|
|
1027
|
+
var ellipseNodeSchema = z.object({
|
|
1028
|
+
type: z.literal("ELLIPSE"),
|
|
1029
|
+
...baseNodeFields,
|
|
1030
|
+
cornerRadius: z.number().optional().describe("圆角半径(px)"),
|
|
745
1031
|
arcData: z.object({
|
|
746
|
-
startingAngle: z.number().describe("起始角度(
|
|
747
|
-
endingAngle: z.number().describe("结束角度(
|
|
748
|
-
innerRadius: z.number().describe("内半径(
|
|
749
|
-
}).optional().describe("环形路径参数(弧线)"),
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
fontFamily: z.string().optional().describe("字体族"),
|
|
794
|
-
characters: z.string().optional().describe("文本内容"),
|
|
795
|
-
textAlign: pre([
|
|
1032
|
+
startingAngle: z.number().describe("起始角度(radians)"),
|
|
1033
|
+
endingAngle: z.number().describe("结束角度(radians)"),
|
|
1034
|
+
innerRadius: z.number().describe("内半径(0-1 ratio)")
|
|
1035
|
+
}).optional().describe("环形路径参数(弧线),可画圆环"),
|
|
1036
|
+
...visualFields
|
|
1037
|
+
}).describe("ELLIPSE=椭圆(配合 arcData 可画环)");
|
|
1038
|
+
var lineNodeSchema = z.object({
|
|
1039
|
+
type: z.literal("LINE"),
|
|
1040
|
+
...baseNodeFields,
|
|
1041
|
+
...visualFields
|
|
1042
|
+
}).describe("LINE=线段");
|
|
1043
|
+
var polygonNodeSchema = z.object({
|
|
1044
|
+
type: z.literal("POLYGON"),
|
|
1045
|
+
...baseNodeFields,
|
|
1046
|
+
pointCount: z.number().describe("多边形角点数,如 6=六边形"),
|
|
1047
|
+
cornerRadius: z.number().optional().describe("圆角半径(px)"),
|
|
1048
|
+
topLeftRadius: z.number().optional().describe("左上圆角(px)"),
|
|
1049
|
+
topRightRadius: z.number().optional().describe("右上圆角(px)"),
|
|
1050
|
+
bottomLeftRadius: z.number().optional().describe("左下圆角(px)"),
|
|
1051
|
+
bottomRightRadius: z.number().optional().describe("右下圆角(px)"),
|
|
1052
|
+
...visualFields
|
|
1053
|
+
}).describe("POLYGON=多边形(配合 pointCount)");
|
|
1054
|
+
var starNodeSchema = z.object({
|
|
1055
|
+
type: z.literal("STAR"),
|
|
1056
|
+
...baseNodeFields,
|
|
1057
|
+
pointCount: z.number().describe("星形角点数,如 5=五角星"),
|
|
1058
|
+
innerRadius: z.number().describe("星形内半径(px),值越小角越尖锐"),
|
|
1059
|
+
cornerRadius: z.number().optional().describe("圆角半径(px)"),
|
|
1060
|
+
topLeftRadius: z.number().optional().describe("左上圆角(px)"),
|
|
1061
|
+
topRightRadius: z.number().optional().describe("右上圆角(px)"),
|
|
1062
|
+
bottomLeftRadius: z.number().optional().describe("左下圆角(px)"),
|
|
1063
|
+
bottomRightRadius: z.number().optional().describe("右下圆角(px)"),
|
|
1064
|
+
...visualFields
|
|
1065
|
+
}).describe("STAR=星形(配合 pointCount + innerRadius)");
|
|
1066
|
+
var vectorNodeSchema = z.object({
|
|
1067
|
+
type: z.literal("VECTOR"),
|
|
1068
|
+
...baseNodeFields,
|
|
1069
|
+
vectorPaths: z.array(vectorPathSchema).describe("矢量路径数组,每项含 SVG path data(如 \"M0 0 L100 100\")"),
|
|
1070
|
+
...visualFields
|
|
1071
|
+
}).describe("VECTOR=矢量(配合 vectorPaths 传 SVG path data)");
|
|
1072
|
+
var textNodeSchema = z.object({
|
|
1073
|
+
type: z.literal("TEXT"),
|
|
1074
|
+
...baseNodeFields,
|
|
1075
|
+
characters: z.string().describe("文本内容,如 \"Hello World\""),
|
|
1076
|
+
fontSize: z.number().optional().describe("字号(px),默认 16"),
|
|
1077
|
+
fontName: fontNameSchema.optional().describe("字体:{family,style},如 {family:\"PingFang SC\",style:\"Regular\"}"),
|
|
1078
|
+
textAlignHorizontal: z.enum([
|
|
796
1079
|
"LEFT",
|
|
797
1080
|
"CENTER",
|
|
798
|
-
"RIGHT"
|
|
799
|
-
|
|
800
|
-
|
|
1081
|
+
"RIGHT",
|
|
1082
|
+
"JUSTIFIED"
|
|
1083
|
+
]).optional().describe("水平对齐:LEFT|CENTER|RIGHT|JUSTIFIED"),
|
|
1084
|
+
textAlignVertical: z.enum([
|
|
801
1085
|
"TOP",
|
|
802
1086
|
"CENTER",
|
|
803
1087
|
"BOTTOM"
|
|
@@ -808,42 +1092,97 @@ var executeNodeSchema = z.lazy(() => z.object({
|
|
|
808
1092
|
"HEIGHT",
|
|
809
1093
|
"TRUNCATE"
|
|
810
1094
|
]).optional().describe("文本自适应:NONE|WIDTH_AND_HEIGHT|HEIGHT|TRUNCATE"),
|
|
811
|
-
textCase:
|
|
1095
|
+
textCase: z.enum([
|
|
812
1096
|
"ORIGINAL",
|
|
813
1097
|
"UPPER",
|
|
814
1098
|
"LOWER",
|
|
815
1099
|
"TITLE"
|
|
816
1100
|
]).optional().describe("文本大小写:ORIGINAL|UPPER|LOWER|TITLE"),
|
|
817
|
-
textDecoration:
|
|
1101
|
+
textDecoration: z.enum([
|
|
818
1102
|
"NONE",
|
|
819
1103
|
"UNDERLINE",
|
|
820
1104
|
"STRIKETHROUGH"
|
|
821
1105
|
]).optional().describe("文本装饰:NONE|UNDERLINE|STRIKETHROUGH"),
|
|
822
|
-
lineHeight:
|
|
823
|
-
letterSpacing:
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
1106
|
+
lineHeight: lineHeightSchema.optional().describe("行高:{value,unit},unit 为 PIXELS|PERCENT;或 {unit:\"AUTO\"}"),
|
|
1107
|
+
letterSpacing: letterSpacingSchema.optional().describe("字距:{value,unit},unit 为 PIXELS|PERCENT"),
|
|
1108
|
+
...visualFields
|
|
1109
|
+
}).describe("TEXT=文本(配合 characters/fontSize/fontName 等)");
|
|
1110
|
+
var groupNodeSchema = z.object({
|
|
1111
|
+
type: z.literal("GROUP"),
|
|
1112
|
+
...baseNodeFields,
|
|
1113
|
+
layoutMode: z.enum([
|
|
1114
|
+
"NONE",
|
|
1115
|
+
"HORIZONTAL",
|
|
1116
|
+
"VERTICAL"
|
|
1117
|
+
]).optional().describe("自动布局方向:NONE=纯归组,HORIZONTAL=水平,VERTICAL=垂直。传 itemSpacing/padding* 等布局属性前必须先设为 HORIZONTAL 或 VERTICAL"),
|
|
1118
|
+
itemSpacing: z.number().optional().describe("项间距(px),需先设 layoutMode"),
|
|
1119
|
+
paddingTop: z.number().optional().describe("上内边距(px)"),
|
|
1120
|
+
paddingRight: z.number().optional().describe("右内边距(px)"),
|
|
1121
|
+
paddingBottom: z.number().optional().describe("下内边距(px)"),
|
|
1122
|
+
paddingLeft: z.number().optional().describe("左内边距(px)"),
|
|
1123
|
+
primaryAxisSizingMode: z.enum(["FIXED", "AUTO"]).optional().describe("主轴尺寸模式:FIXED|AUTO"),
|
|
1124
|
+
counterAxisSizingMode: z.enum(["FIXED", "AUTO"]).optional().describe("交叉轴尺寸模式:FIXED|AUTO"),
|
|
1125
|
+
primaryAxisAlignItems: z.enum([
|
|
827
1126
|
"MIN",
|
|
1127
|
+
"MAX",
|
|
828
1128
|
"CENTER",
|
|
1129
|
+
"SPACE_BETWEEN"
|
|
1130
|
+
]).optional().describe("主轴对齐"),
|
|
1131
|
+
counterAxisAlignItems: z.enum([
|
|
1132
|
+
"MIN",
|
|
829
1133
|
"MAX",
|
|
830
|
-
"
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
1134
|
+
"CENTER"
|
|
1135
|
+
]).optional().describe("交叉轴对齐"),
|
|
1136
|
+
...visualFields
|
|
1137
|
+
}).superRefine((val, ctx) => {
|
|
1138
|
+
if ((val.itemSpacing != null || val.paddingTop != null || val.paddingRight != null || val.paddingBottom != null || val.paddingLeft != null || val.primaryAxisSizingMode != null || val.counterAxisSizingMode != null || val.primaryAxisAlignItems != null || val.counterAxisAlignItems != null) && (val.layoutMode == null || val.layoutMode === "NONE")) ctx.addIssue({
|
|
1139
|
+
code: z.ZodIssueCode.custom,
|
|
1140
|
+
message: "传 itemSpacing/padding*/primaryAxis*/counterAxis* 等布局属性前,layoutMode 必须设为 HORIZONTAL 或 VERTICAL",
|
|
1141
|
+
path: ["layoutMode"]
|
|
1142
|
+
});
|
|
1143
|
+
}).describe("GROUP=分组(内部用 Frame 实现)");
|
|
1144
|
+
var booleanOperationNodeSchema = z.object({
|
|
1145
|
+
type: z.literal("BOOLEAN_OPERATION"),
|
|
1146
|
+
...baseNodeFields,
|
|
1147
|
+
booleanOperation: z.enum([
|
|
1148
|
+
"UNION",
|
|
1149
|
+
"SUBTRACT",
|
|
1150
|
+
"INTERSECT",
|
|
1151
|
+
"EXCLUDE"
|
|
1152
|
+
]).describe("布尔运算:UNION=合并,SUBTRACT=减去,INTERSECT=相交,EXCLUDE=排除"),
|
|
1153
|
+
children: z.array(z.any()).min(2).describe("要合并的子节点数组(至少 2 个)"),
|
|
1154
|
+
...visualFields
|
|
1155
|
+
}).describe("BOOLEAN_OPERATION=布尔运算(合并子节点)");
|
|
1156
|
+
var executeNodeSchema = z.discriminatedUnion("type", [
|
|
1157
|
+
frameNodeSchema,
|
|
1158
|
+
rectangleNodeSchema,
|
|
1159
|
+
ellipseNodeSchema,
|
|
1160
|
+
lineNodeSchema,
|
|
1161
|
+
polygonNodeSchema,
|
|
1162
|
+
starNodeSchema,
|
|
1163
|
+
vectorNodeSchema,
|
|
1164
|
+
textNodeSchema,
|
|
1165
|
+
groupNodeSchema,
|
|
1166
|
+
booleanOperationNodeSchema
|
|
1167
|
+
]);
|
|
835
1168
|
var placementSchema = z.object({
|
|
836
1169
|
mode: z.enum([
|
|
837
1170
|
"center",
|
|
838
1171
|
"manual",
|
|
839
1172
|
"absolute"
|
|
840
|
-
]).optional().describe("
|
|
841
|
-
x: z.number().optional().describe("absolute 模式下的绝对 X
|
|
842
|
-
y: z.number().optional().describe("absolute 模式下的绝对 Y
|
|
1173
|
+
]).optional().describe("放置模式:center=居中画布/manual=保持节点原始坐标/absolute=使用 x/y 指定坐标(选 absolute 必须传 x 和 y)"),
|
|
1174
|
+
x: z.number().optional().describe("absolute 模式下的绝对 X 坐标,与 mode=\"absolute\" 配合使用"),
|
|
1175
|
+
y: z.number().optional().describe("absolute 模式下的绝对 Y 坐标,与 mode=\"absolute\" 配合使用")
|
|
1176
|
+
}).superRefine((val, ctx) => {
|
|
1177
|
+
if (val.mode === "absolute" && (val.x == null || val.y == null)) ctx.addIssue({
|
|
1178
|
+
code: z.ZodIssueCode.custom,
|
|
1179
|
+
message: "placement.mode 为 absolute 时,x 和 y 均为必填项",
|
|
1180
|
+
path: val.x == null ? ["x"] : ["y"]
|
|
1181
|
+
});
|
|
843
1182
|
});
|
|
844
1183
|
var executeSchema = z.object({
|
|
845
1184
|
ops: z.array(executeNodeSchema).describe("设计指令节点树"),
|
|
846
|
-
placement: placementSchema.optional().describe("放置方式,缺省 center
|
|
1185
|
+
placement: placementSchema.optional().describe("放置方式,缺省 center 居中。选 absolute 模式必须传 x 和 y 坐标")
|
|
847
1186
|
});
|
|
848
1187
|
var createSvgSchema = z.object({
|
|
849
1188
|
svg: z.string().describe("完整 SVG 字符串,如 <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"100\" height=\"100\"><path d=\"M0 0 L100 0 L100 100 Z\" fill=\"#ff0000\"/></svg>"),
|
|
@@ -854,178 +1193,29 @@ var htmlToDesignSchema = z.object({
|
|
|
854
1193
|
name: z.string().optional().describe("生成的图层名,默认 html-design")
|
|
855
1194
|
});
|
|
856
1195
|
var createIconSchema = z.object({
|
|
857
|
-
icon: z.string().describe("图标名/别名/语义描述,如 home、arrow-right、magnifier(搜索)
|
|
1196
|
+
icon: z.string().describe("图标名/别名/语义描述,如 home、arrow-right、search、magnifier(搜索);支持模糊匹配与别名联想,查无返回候选提示"),
|
|
858
1197
|
size: z.number().optional().describe("图标边长 px,默认 24"),
|
|
859
1198
|
color: z.string().optional().describe("描边颜色(十六进制),默认 #000000"),
|
|
860
1199
|
strokeWidth: z.number().optional().describe("描边宽度,默认 2"),
|
|
861
1200
|
name: z.string().optional().describe("生成的图层名,默认 icon-<图标名>")
|
|
862
1201
|
});
|
|
863
|
-
var
|
|
1202
|
+
var updateNodePropsSchema = z.object({
|
|
864
1203
|
name: z.string().optional().describe("图层名称"),
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
cornerRadius: z.number().optional().describe("四角统一圆角半径"),
|
|
871
|
-
radiusTopLeft: z.number().optional().describe("左上角圆角"),
|
|
872
|
-
radiusTopRight: z.number().optional().describe("右上角圆角"),
|
|
873
|
-
radiusBottomLeft: z.number().optional().describe("左下角圆角"),
|
|
874
|
-
radiusBottomRight: z.number().optional().describe("右下角圆角"),
|
|
875
|
-
visible: z.boolean().optional().describe("是否可见"),
|
|
876
|
-
rotation: z.number().optional().describe("旋转角度(度)"),
|
|
877
|
-
opacity: z.number().optional().describe("不透明度 0~1"),
|
|
878
|
-
locked: z.boolean().optional().describe("是否锁定"),
|
|
879
|
-
cornerSmoothing: z.number().optional().describe("圆角平滑度 0~1"),
|
|
880
|
-
blendMode: z.string().optional().describe("混合模式,如 MULTIPLY/SCREEN 等"),
|
|
881
|
-
clipsContent: z.boolean().optional().describe("frame 内容是否裁剪"),
|
|
882
|
-
constraints: z.object({
|
|
883
|
-
horizontal: pre([
|
|
884
|
-
"MIN",
|
|
885
|
-
"MAX",
|
|
886
|
-
"STRETCH",
|
|
887
|
-
"CENTER",
|
|
888
|
-
"SCALE"
|
|
889
|
-
]).describe("水平约束:MIN|MAX|STRETCH|CENTER|SCALE"),
|
|
890
|
-
vertical: pre([
|
|
891
|
-
"MIN",
|
|
892
|
-
"MAX",
|
|
893
|
-
"STRETCH",
|
|
894
|
-
"CENTER",
|
|
895
|
-
"SCALE"
|
|
896
|
-
]).describe("垂直约束:MIN|MAX|STRETCH|CENTER|SCALE")
|
|
897
|
-
}).optional().describe("响应式约束(图钉),如 {horizontal:MIN,vertical:TOP}"),
|
|
898
|
-
layoutGrids: z.array(z.object({
|
|
899
|
-
pattern: z.enum([
|
|
900
|
-
"ROWS",
|
|
901
|
-
"COLUMNS",
|
|
902
|
-
"GRID"
|
|
903
|
-
]).describe("网格类型:ROWS|COLUMNS|GRID"),
|
|
904
|
-
alignment: z.enum([
|
|
905
|
-
"MIN",
|
|
906
|
-
"MAX",
|
|
907
|
-
"STRETCH",
|
|
908
|
-
"CENTER"
|
|
909
|
-
]).optional().describe("对齐:MIN|MAX|STRETCH|CENTER"),
|
|
910
|
-
gutterSize: z.number().optional().describe("沟槽尺寸(px)"),
|
|
911
|
-
count: z.number().optional().describe("网格数"),
|
|
912
|
-
sectionSize: z.number().optional().describe("分节尺寸(px)"),
|
|
913
|
-
offset: z.number().optional().describe("偏移(px)"),
|
|
914
|
-
visible: z.boolean().optional().describe("是否可见"),
|
|
915
|
-
color: z.string().optional().describe("网格颜色,hex"),
|
|
916
|
-
colorOpacity: z.number().optional().describe("颜色不透明度 0-1")
|
|
917
|
-
})).optional().describe("网格参考线(网格布局)"),
|
|
918
|
-
arcData: z.object({
|
|
919
|
-
startingAngle: z.number().describe("起始角度(deg)"),
|
|
920
|
-
endingAngle: z.number().describe("结束角度(deg)"),
|
|
921
|
-
innerRadius: z.number().describe("内半径(px)")
|
|
922
|
-
}).optional().describe("椭圆/环形起止角度与内半径"),
|
|
923
|
-
characters: z.string().optional().describe("文本内容"),
|
|
924
|
-
fontSize: z.number().optional().describe("字号(px)"),
|
|
925
|
-
fontWeight: z.number().optional().describe("字重"),
|
|
926
|
-
fontFamily: z.string().optional().describe("字体族"),
|
|
927
|
-
textAlign: pre([
|
|
928
|
-
"LEFT",
|
|
929
|
-
"CENTER",
|
|
930
|
-
"RIGHT",
|
|
931
|
-
"JUSTIFIED"
|
|
932
|
-
]).optional().describe("文本对齐方式"),
|
|
933
|
-
textAlignVertical: pre([
|
|
934
|
-
"TOP",
|
|
935
|
-
"CENTER",
|
|
936
|
-
"BOTTOM"
|
|
937
|
-
]).optional().describe("文本垂直对齐"),
|
|
938
|
-
textAutoResize: z.enum([
|
|
939
|
-
"NONE",
|
|
940
|
-
"WIDTH_AND_HEIGHT",
|
|
941
|
-
"HEIGHT",
|
|
942
|
-
"TRUNCATE"
|
|
943
|
-
]).optional().describe("文本自动尺寸"),
|
|
944
|
-
textCase: pre([
|
|
945
|
-
"ORIGINAL",
|
|
946
|
-
"UPPER",
|
|
947
|
-
"LOWER",
|
|
948
|
-
"TITLE"
|
|
949
|
-
]).optional().describe("文本大小写"),
|
|
950
|
-
textDecoration: pre([
|
|
951
|
-
"NONE",
|
|
952
|
-
"UNDERLINE",
|
|
953
|
-
"STRIKETHROUGH"
|
|
954
|
-
]).optional().describe("文本装饰(下划线/删除线)"),
|
|
955
|
-
lineHeight: z.number().optional().describe("行高"),
|
|
956
|
-
letterSpacing: z.number().optional().describe("字距"),
|
|
957
|
-
stroke: z.string().optional().describe("描边颜色,如 #ffffff"),
|
|
958
|
-
strokeWeight: z.number().optional().describe("描边粗细"),
|
|
959
|
-
strokeAlign: pre([
|
|
960
|
-
"CENTER",
|
|
961
|
-
"INSIDE",
|
|
962
|
-
"OUTSIDE"
|
|
963
|
-
]).optional().describe("描边对齐"),
|
|
964
|
-
strokeCap: z.enum([
|
|
965
|
-
"NONE",
|
|
966
|
-
"ROUND",
|
|
967
|
-
"SQUARE",
|
|
968
|
-
"ARROW_LINES",
|
|
969
|
-
"ARROW_EQUILATERAL"
|
|
970
|
-
]).optional().describe("线帽/箭头"),
|
|
971
|
-
strokeJoin: z.enum([
|
|
972
|
-
"MITER",
|
|
973
|
-
"BEVEL",
|
|
974
|
-
"ROUND"
|
|
975
|
-
]).optional().describe("折角连接方式"),
|
|
976
|
-
dashPattern: z.array(z.number()).optional().describe("虚线模式,如 [4,4]"),
|
|
977
|
-
shadow: z.object({
|
|
978
|
-
color: z.string().optional().describe("阴影颜色"),
|
|
979
|
-
x: z.number().optional().describe("阴影 X 偏移"),
|
|
980
|
-
y: z.number().optional().describe("阴影 Y 偏移"),
|
|
981
|
-
radius: z.number().optional().describe("阴影模糊半径"),
|
|
982
|
-
spread: z.number().optional().describe("阴影扩展")
|
|
983
|
-
}).optional().describe("原生阴影(下拉阴影)"),
|
|
984
|
-
layoutMode: pre([
|
|
985
|
-
"NONE",
|
|
986
|
-
"HORIZONTAL",
|
|
987
|
-
"VERTICAL"
|
|
988
|
-
]).optional().describe("自动布局方向"),
|
|
989
|
-
primaryAxisSizingMode: pre(["FIXED", "AUTO"]).optional().describe("主轴尺寸模式(仅自动布局生效)"),
|
|
990
|
-
counterAxisSizingMode: pre(["FIXED", "AUTO"]).optional().describe("交叉轴尺寸模式(仅自动布局生效)"),
|
|
991
|
-
primaryAxisAlignItems: pre([
|
|
992
|
-
"MIN",
|
|
993
|
-
"MAX",
|
|
994
|
-
"CENTER",
|
|
995
|
-
"SPACE_BETWEEN"
|
|
996
|
-
]).optional().describe("主轴对齐方式(仅自动布局生效)"),
|
|
997
|
-
counterAxisAlignItems: pre([
|
|
998
|
-
"MIN",
|
|
999
|
-
"MAX",
|
|
1000
|
-
"CENTER"
|
|
1001
|
-
]).optional().describe("交叉轴对齐方式(仅自动布局生效)"),
|
|
1002
|
-
itemSpacing: z.number().optional().describe("自动布局项间距"),
|
|
1003
|
-
padding: z.number().optional().describe("自动布局内边距(四边统一)"),
|
|
1004
|
-
paddingTop: z.number().optional().describe("自动布局上内边距"),
|
|
1005
|
-
paddingRight: z.number().optional().describe("自动布局右内边距"),
|
|
1006
|
-
paddingBottom: z.number().optional().describe("自动布局下内边距"),
|
|
1007
|
-
paddingLeft: z.number().optional().describe("自动布局左内边距"),
|
|
1008
|
-
layoutGrow: z.number().optional().describe("子节点主轴填充 0=固定 1=填充(仅自动布局父容器内生效)"),
|
|
1009
|
-
layoutAlign: pre([
|
|
1010
|
-
"MIN",
|
|
1011
|
-
"CENTER",
|
|
1012
|
-
"MAX",
|
|
1013
|
-
"STRETCH",
|
|
1014
|
-
"INHERIT"
|
|
1015
|
-
]).optional().describe("子节点交叉轴对齐(仅自动布局父容器内生效)"),
|
|
1016
|
-
pointCount: z.number().optional().describe("多边形/星形角点数")
|
|
1017
|
-
});
|
|
1018
|
-
var updateSelectionSchema = z.object({
|
|
1019
|
-
ids: z.array(z.string()).optional().describe("指定节点 id,缺省用当前选中"),
|
|
1204
|
+
pointCount: z.number().optional().describe("多边形/星形角点数"),
|
|
1205
|
+
innerRadius: z.number().optional().describe("星形内半径(px)")
|
|
1206
|
+
}).and(transformPropsSchema).and(strokePropsSchema).and(cornerPropsSchema).and(textPropsSchema).and(autoLayoutPropsSchema).and(visualPropsSchema);
|
|
1207
|
+
var updateNodeSchema = z.object({
|
|
1208
|
+
ids: z.array(z.string()).optional().describe("指定节点 id"),
|
|
1020
1209
|
matchName: z.string().optional().describe("按节点 name 过滤,仅命中节点被修改"),
|
|
1021
1210
|
recursive: z.boolean().optional().describe("是否递归应用到子节点,默认 false"),
|
|
1022
|
-
props:
|
|
1211
|
+
props: updateNodePropsSchema.describe("要修改的属性")
|
|
1023
1212
|
});
|
|
1024
1213
|
var findSchema = z.object({
|
|
1214
|
+
ids: z.array(z.string()).optional().describe("按节点 id 精确查找,优先级最高"),
|
|
1025
1215
|
name: z.string().optional().describe("按名称模糊匹配(包含)"),
|
|
1026
|
-
type: z.string().optional().describe("
|
|
1216
|
+
type: z.string().optional().describe("节点类型过滤,支持:SLICE/FRAME/GROUP/COMPONENT_SET/COMPONENT/INSTANCE/BOOLEAN_OPERATION/VECTOR/STAR/LINE/ELLIPSE/POLYGON/RECTANGLE/TEXT"),
|
|
1027
1217
|
recursive: z.boolean().optional().describe("是否递归查找(默认 true)"),
|
|
1028
|
-
depth: z.number().optional().describe("
|
|
1218
|
+
depth: z.number().optional().describe("序列化深度:0=仅自身,1=含直接子节点;缺省 1")
|
|
1029
1219
|
});
|
|
1030
1220
|
var manageNodesSchema = z.discriminatedUnion("op", [
|
|
1031
1221
|
z.object({
|
|
@@ -1035,7 +1225,7 @@ var manageNodesSchema = z.discriminatedUnion("op", [
|
|
|
1035
1225
|
z.object({
|
|
1036
1226
|
op: z.literal("remove"),
|
|
1037
1227
|
ids: z.array(z.string()).optional().describe("要删除的节点 id 列表,缺省用当前选中"),
|
|
1038
|
-
matchName: z.string().optional().describe("
|
|
1228
|
+
matchName: z.string().optional().describe("在 ids(或当前选中)范围内,仅删除 name 精确匹配的节点")
|
|
1039
1229
|
}),
|
|
1040
1230
|
z.object({
|
|
1041
1231
|
op: z.literal("clone"),
|
|
@@ -1044,7 +1234,30 @@ var manageNodesSchema = z.discriminatedUnion("op", [
|
|
|
1044
1234
|
z.object({
|
|
1045
1235
|
op: z.literal("group"),
|
|
1046
1236
|
ids: z.array(z.string()).describe("要编组的节点 id 列表"),
|
|
1047
|
-
name: z.string().optional().describe("组名")
|
|
1237
|
+
name: z.string().optional().describe("组名"),
|
|
1238
|
+
layoutMode: z.enum([
|
|
1239
|
+
"NONE",
|
|
1240
|
+
"HORIZONTAL",
|
|
1241
|
+
"VERTICAL"
|
|
1242
|
+
]).optional().describe("自动布局方向:NONE=纯归组,子节点仅叠加,HORIZONTAL=水平排列,VERTICAL=垂直排列"),
|
|
1243
|
+
itemSpacing: z.number().optional().describe("自动布局项间距(px)"),
|
|
1244
|
+
paddingTop: z.number().optional().describe("上内边距(px)"),
|
|
1245
|
+
paddingRight: z.number().optional().describe("右内边距(px)"),
|
|
1246
|
+
paddingBottom: z.number().optional().describe("下内边距(px)"),
|
|
1247
|
+
paddingLeft: z.number().optional().describe("左内边距(px)"),
|
|
1248
|
+
primaryAxisSizingMode: z.enum(["FIXED", "AUTO"]).optional().describe("主轴尺寸模式:FIXED|AUTO"),
|
|
1249
|
+
counterAxisSizingMode: z.enum(["FIXED", "AUTO"]).optional().describe("交叉轴尺寸模式:FIXED|AUTO"),
|
|
1250
|
+
primaryAxisAlignItems: z.enum([
|
|
1251
|
+
"MIN",
|
|
1252
|
+
"MAX",
|
|
1253
|
+
"CENTER",
|
|
1254
|
+
"SPACE_BETWEEN"
|
|
1255
|
+
]).optional().describe("主轴对齐:MIN|MAX|CENTER|SPACE_BETWEEN"),
|
|
1256
|
+
counterAxisAlignItems: z.enum([
|
|
1257
|
+
"MIN",
|
|
1258
|
+
"MAX",
|
|
1259
|
+
"CENTER"
|
|
1260
|
+
]).optional().describe("交叉轴对齐:MIN|MAX|CENTER")
|
|
1048
1261
|
}),
|
|
1049
1262
|
z.object({
|
|
1050
1263
|
op: z.literal("ungroup"),
|
|
@@ -1064,7 +1277,7 @@ var manageNodesSchema = z.discriminatedUnion("op", [
|
|
|
1064
1277
|
parentId: z.string().optional().describe("目标父节点 id,缺省用当前选中第一个节点"),
|
|
1065
1278
|
index: z.number().optional().describe("插入位置,缺省追加到末尾")
|
|
1066
1279
|
}),
|
|
1067
|
-
z.object({ op: z.literal("repair").describe("
|
|
1280
|
+
z.object({ op: z.literal("repair").describe("清理画布中已损坏/失效的节点(读取失败的节点直接删除)") })
|
|
1068
1281
|
]);
|
|
1069
1282
|
var manageComponentsSchema = z.discriminatedUnion("op", [
|
|
1070
1283
|
z.object({
|
|
@@ -1082,7 +1295,7 @@ var manageComponentsSchema = z.discriminatedUnion("op", [
|
|
|
1082
1295
|
}),
|
|
1083
1296
|
z.object({
|
|
1084
1297
|
op: z.literal("import_component"),
|
|
1085
|
-
key: z.string().describe("
|
|
1298
|
+
key: z.string().describe("团队库组件的唯一标识 Key(从设计稿/团队库获取)"),
|
|
1086
1299
|
name: z.string().optional().describe("导入后的组件名")
|
|
1087
1300
|
}),
|
|
1088
1301
|
z.object({
|
|
@@ -1093,7 +1306,7 @@ var manageComponentsSchema = z.discriminatedUnion("op", [
|
|
|
1093
1306
|
z.object({
|
|
1094
1307
|
op: z.literal("set_instance_properties"),
|
|
1095
1308
|
ids: z.array(z.string()).describe("实例(INSTANCE)节点 id 列表"),
|
|
1096
|
-
properties: z.record(z.string(), z.string()).describe("变体属性名→值,如 {\"状态\":\"禁用\"}")
|
|
1309
|
+
properties: z.record(z.string(), z.string()).describe("变体属性名→值,如 {\"状态\":\"禁用\"}。可调属性列表需从 jsd_find/jsd_get_selection 返回的 variantGroupProperties 获取,属性名必须完全匹配")
|
|
1097
1310
|
}),
|
|
1098
1311
|
z.object({
|
|
1099
1312
|
op: z.literal("combine_as_variants"),
|
|
@@ -1113,10 +1326,6 @@ var exportSchema = z.object({
|
|
|
1113
1326
|
savePath: z.string().optional().describe("落盘文件绝对路径,如 /tmp/icon.png"),
|
|
1114
1327
|
includeDataUrl: z.boolean().optional().describe("是否同时返回 base64 dataURL,默认 false")
|
|
1115
1328
|
});
|
|
1116
|
-
var fillImageSchema = z.object({
|
|
1117
|
-
ids: z.array(z.string()).describe("要填充图片的节点 id 列表"),
|
|
1118
|
-
sourcePath: z.string().describe("本地图片文件绝对路径,如 /tmp/poster.png")
|
|
1119
|
-
});
|
|
1120
1329
|
z.object({});
|
|
1121
1330
|
//#endregion
|
|
1122
1331
|
//#region src/core/response.ts
|
|
@@ -1961,7 +2170,22 @@ function iconToSvg(def, size = 24, color = "#000000", strokeWidth = 2) {
|
|
|
1961
2170
|
/** 创建类:声明式节点 / SVG 导入 / HTML 转设计 */
|
|
1962
2171
|
function registerCreateTools(server, bridge) {
|
|
1963
2172
|
server.registerTool("jsd_execute", {
|
|
1964
|
-
description:
|
|
2173
|
+
description: `在画布创建节点(可递归嵌套子节点)。
|
|
2174
|
+
|
|
2175
|
+
节点类型 type:
|
|
2176
|
+
- FRAME=容器(可 auto-layout)
|
|
2177
|
+
- RECTANGLE=矩形
|
|
2178
|
+
- ELLIPSE=椭圆(配合 arcData 可画环)
|
|
2179
|
+
- LINE=线段
|
|
2180
|
+
- POLYGON=多边形(配合 pointCount)
|
|
2181
|
+
- STAR=星形(配合 pointCount + innerRadius)
|
|
2182
|
+
- VECTOR=矢量(配合 vectorPaths 传 SVG path data)
|
|
2183
|
+
- TEXT=文本(配合 characters/fontSize/fontName 等)
|
|
2184
|
+
- GROUP=分组(内部用 Frame 实现)
|
|
2185
|
+
- BOOLEAN_OPERATION=布尔运算(配合 booleanOperation:UNION|SUBTRACT|INTERSECT|EXCLUDE)
|
|
2186
|
+
|
|
2187
|
+
填充 fills/描边 strokes:每项为 {type:"SOLID", color:{r,g,b}} 或 {type:"GRADIENT_LINEAR",...},color 的 r/g/b 范围 0-1。
|
|
2188
|
+
放置 placement:mode=center 居中画布,manual=保持原始坐标,absolute=使用 x/y 坐标。`,
|
|
1965
2189
|
inputSchema: executeSchema,
|
|
1966
2190
|
outputSchema: createdResultSchema
|
|
1967
2191
|
}, async ({ ops, placement }) => {
|
|
@@ -2030,7 +2254,19 @@ function registerCreateTools(server, bridge) {
|
|
|
2030
2254
|
/** 管理类:节点结构操作 + 组件/实例操作 */
|
|
2031
2255
|
function registerManageTools(server, bridge) {
|
|
2032
2256
|
server.registerTool("jsd_manage_nodes", {
|
|
2033
|
-
description:
|
|
2257
|
+
description: `对节点执行结构操作(按 op 分发):
|
|
2258
|
+
|
|
2259
|
+
- select:设置当前选中
|
|
2260
|
+
- remove:删除(matchName 可在 ids/选中范围内进一步过滤)
|
|
2261
|
+
- clone:复制(右下偏移 24px)
|
|
2262
|
+
- group:编组(支持 auto-layout 参数 layoutMode/itemSpacing/padding*)
|
|
2263
|
+
- ungroup:取消编组
|
|
2264
|
+
- flatten:合并为单个矢量(至少 2 个节点)
|
|
2265
|
+
- outline_stroke:描边转矢量轮廓
|
|
2266
|
+
- reparent:移动到目标父节点下(parentId 缺省用当前选中第一个)
|
|
2267
|
+
- repair:清理画布中已损坏的节点
|
|
2268
|
+
|
|
2269
|
+
注意:修改属性(位置/尺寸/填充/文本等)请用 jsd_update_node。`,
|
|
2034
2270
|
inputSchema: manageNodesSchema,
|
|
2035
2271
|
outputSchema: manageNodesResultSchema
|
|
2036
2272
|
}, async (params) => {
|
|
@@ -2041,7 +2277,15 @@ function registerManageTools(server, bridge) {
|
|
|
2041
2277
|
}
|
|
2042
2278
|
});
|
|
2043
2279
|
server.registerTool("jsd_manage_components", {
|
|
2044
|
-
description:
|
|
2280
|
+
description: `组件/实例操作(按 op 分发):
|
|
2281
|
+
|
|
2282
|
+
- create_component:创建空壳组件(子节点需另用 reparent 归组)
|
|
2283
|
+
- create_instance:从组件生成实例
|
|
2284
|
+
- detach_instance:解绑实例(转为 Frame)
|
|
2285
|
+
- import_component:从团队库按 key 导入组件
|
|
2286
|
+
- swap_component:交换实例引用的组件
|
|
2287
|
+
- set_instance_properties:设置实例变体属性(可调属性从 find/selection 的 variantGroupProperties 获取)
|
|
2288
|
+
- combine_as_variants:合并为组件集(基于副本,原组件保留)`,
|
|
2045
2289
|
inputSchema: manageComponentsSchema,
|
|
2046
2290
|
outputSchema: manageComponentsResultSchema
|
|
2047
2291
|
}, async (params) => {
|
|
@@ -2056,13 +2300,21 @@ function registerManageTools(server, bridge) {
|
|
|
2056
2300
|
//#region src/tools/modify.ts
|
|
2057
2301
|
/** 修改类:选中属性修改 + 节点查找 */
|
|
2058
2302
|
function registerModifyTools(server, bridge) {
|
|
2059
|
-
server.registerTool("
|
|
2060
|
-
description:
|
|
2061
|
-
|
|
2303
|
+
server.registerTool("jsd_update_node", {
|
|
2304
|
+
description: `按 id 修改节点属性(位置/尺寸/填充/文本/效果等)。
|
|
2305
|
+
|
|
2306
|
+
参数说明:
|
|
2307
|
+
- ids:指定要修改的节点 id 列表(优先级高于当前选中)
|
|
2308
|
+
- matchName:在 ids 范围内进一步过滤,仅修改 name 精确匹配的节点
|
|
2309
|
+
- recursive:是否递归应用到子节点
|
|
2310
|
+
- props:要修改的属性对象,字段与枚举以 inputSchema 为准
|
|
2311
|
+
|
|
2312
|
+
注意:结构操作(分组/删除/移动)请用 jsd_manage_nodes。`,
|
|
2313
|
+
inputSchema: updateNodeSchema,
|
|
2062
2314
|
outputSchema: updatedResultSchema
|
|
2063
2315
|
}, async ({ ids, matchName, recursive, props }) => {
|
|
2064
2316
|
try {
|
|
2065
|
-
return structured(await bridge.request("
|
|
2317
|
+
return structured(await bridge.request("update_node", {
|
|
2066
2318
|
ids,
|
|
2067
2319
|
matchName,
|
|
2068
2320
|
recursive,
|
|
@@ -2073,7 +2325,7 @@ function registerModifyTools(server, bridge) {
|
|
|
2073
2325
|
}
|
|
2074
2326
|
});
|
|
2075
2327
|
server.registerTool("jsd_find", {
|
|
2076
|
-
description: "
|
|
2328
|
+
description: "在当前页面查找节点,可按 ids 精确查找(优先级最高)/名称模糊匹配/类型过滤,返回序列化节点列表(最多 100 条)",
|
|
2077
2329
|
inputSchema: findSchema,
|
|
2078
2330
|
outputSchema: findResultSchema
|
|
2079
2331
|
}, async (params) => {
|
|
@@ -2086,10 +2338,22 @@ function registerModifyTools(server, bridge) {
|
|
|
2086
2338
|
}
|
|
2087
2339
|
//#endregion
|
|
2088
2340
|
//#region src/tools/raw.ts
|
|
2341
|
+
var fillImageSchema = z.object({
|
|
2342
|
+
ids: z.array(z.string()).describe("要填充图片的节点 id 列表"),
|
|
2343
|
+
sourcePath: z.string().describe("本地图片文件绝对路径,如 /tmp/poster.png")
|
|
2344
|
+
});
|
|
2089
2345
|
/** 原始数据类:导出/填充图片/字体列表 */
|
|
2090
2346
|
function registerRawTools(server, bridge) {
|
|
2091
2347
|
server.registerTool("jsd_export", {
|
|
2092
|
-
description:
|
|
2348
|
+
description: `导出节点为图片/文件。
|
|
2349
|
+
|
|
2350
|
+
参数说明:
|
|
2351
|
+
- format:导出格式 PNG/JPG/SVG/PDF,默认 PNG
|
|
2352
|
+
- scale:缩放倍率(PNG/JPG),默认 1
|
|
2353
|
+
- savePath:落盘到本地文件路径(如 /tmp/icon.png),推荐在不支持图像的模型时使用
|
|
2354
|
+
- includeDataUrl:是否同时返回 base64 dataURL(供支持图像的模型直接查看)
|
|
2355
|
+
|
|
2356
|
+
两种输出方式可并存:传 savePath 落盘 + 不传 includeDataUrl 则仅落盘;传 includeDataUrl 则返回 base64。`,
|
|
2093
2357
|
inputSchema: exportSchema,
|
|
2094
2358
|
outputSchema: exportResultSchema
|
|
2095
2359
|
}, async ({ ids, format, scale, savePath, includeDataUrl }) => {
|
|
@@ -2172,7 +2436,9 @@ function registerSessionTools(server, bridge) {
|
|
|
2172
2436
|
}
|
|
2173
2437
|
});
|
|
2174
2438
|
server.registerTool("jsd_get_selection", {
|
|
2175
|
-
description:
|
|
2439
|
+
description: `获取画布当前选中的节点信息(名称/类型/尺寸/位置/填充/文本/子树结构)。
|
|
2440
|
+
|
|
2441
|
+
可选 depth 参数控制序列化深度:0=仅自身,1=含直接子节点,2=含孙节点,默认 2。`,
|
|
2176
2442
|
outputSchema: getSelectionResultSchema
|
|
2177
2443
|
}, async () => {
|
|
2178
2444
|
try {
|