text-to-design-mcp 0.13.3 → 0.13.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/dist/index.js +7 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{createRequire as e}from"node:module";import{appendFileSync as t,mkdirSync as n,readFileSync as r,rmSync as i,statSync as a,writeFileSync as o}from"node:fs";import{homedir as s,tmpdir as c}from"node:os";import{dirname as l,isAbsolute as u,join as d,resolve as f,sep as p}from"node:path";import{core as ee,z as m}from"zod";import{createServer as te}from"node:http";import{WebSocket as h,WebSocketServer as g}from"ws";import{Client as ne,StreamableHTTPClientTransport as re}from"@modelcontextprotocol/client";import{McpServer as ie,ResourceTemplate as ae,SUPPORTED_PROTOCOL_VERSIONS as _,createMcpHandler as oe,fromJsonSchema as se}from"@modelcontextprotocol/server";import{serveStdio as ce}from"@modelcontextprotocol/server/stdio";import{spawn as le,spawnSync as ue}from"node:child_process";import{localhostHostValidation as de,localhostOriginValidation as fe,toNodeHandler as pe}from"@modelcontextprotocol/node";import{readFile as me,stat as he}from"node:fs/promises";import{isTag as ge}from"domhandler";import{parseDocument as _e}from"htmlparser2";import ve from"fuse.js";var v=class extends Error{code;constructor(e,t){super(t),this.name=`BridgeError`,this.code=e}};function ye(e){return e instanceof v?e.code:`plugin_error`}var be=3e4,xe=4e3;2*be;var Se=3e4,Ce={styles:{kind:`propGate`,props:[`fillStyleId`,`strokeStyleId`,`textStyleId`,`effectStyleId`],labelKey:`capability.host.styles`},styleEnumeration:{kind:`flow`,labelKey:`capability.host.styleEnumeration`},styleEnumerationSync:{kind:`flow`,labelKey:`capability.host.styleEnumerationSync`},mainComponentSync:{kind:`flow`,labelKey:`capability.host.mainComponentSync`},textTruncation:{kind:`propGate`,props:[`textTruncation`,`maxLines`],labelKey:`capability.host.textTruncation`},componentProperties:{kind:`propGate`,props:[`componentProperties`],labelKey:`capability.host.componentProperties`},variables:{kind:`channel`,labelKey:`capability.host.variables`},documentScopeRead:{kind:`flow`,labelKey:`capability.host.documentScopeRead`},inPlaceVariants:{kind:`flow`,labelKey:`capability.host.inPlaceVariants`}};function we(e){return Object.keys(e)}var Te=we(Ce);Object.fromEntries(Object.entries(Ce).map(([e,t])=>[e,t.kind===`propGate`?t.props:[]]));var Ee=Object.fromEntries(Object.entries(Ce).flatMap(([e,t])=>t.kind===`propGate`?t.props.map(t=>[t,e]):[])),De=we({create:{labelKey:`capability.core.create`},modify:{labelKey:`capability.core.modify`},structure:{labelKey:`capability.core.structure`},component:{labelKey:`capability.core.component`},export:{labelKey:`capability.core.export`},image:{labelKey:`capability.core.image`}}),Oe={pointCount:[`POLYGON`,`STAR`],innerRadius:[`STAR`],arcData:[`ELLIPSE`],characters:[`TEXT`],fontSize:[`TEXT`],fontName:[`TEXT`],textAlignHorizontal:[`TEXT`],textAlignVertical:[`TEXT`],textAutoResize:[`TEXT`],textCase:[`TEXT`],textDecoration:[`TEXT`],lineHeight:[`TEXT`],letterSpacing:[`TEXT`],textTruncation:[`TEXT`],maxLines:[`TEXT`],layoutMode:[`FRAME`,`COMPONENT`,`COMPONENT_SET`],itemSpacing:[`FRAME`,`COMPONENT`,`COMPONENT_SET`],paddingTop:[`FRAME`,`COMPONENT`,`COMPONENT_SET`],paddingRight:[`FRAME`,`COMPONENT`,`COMPONENT_SET`],paddingBottom:[`FRAME`,`COMPONENT`,`COMPONENT_SET`],paddingLeft:[`FRAME`,`COMPONENT`,`COMPONENT_SET`],primaryAxisSizingMode:[`FRAME`,`COMPONENT`,`COMPONENT_SET`],counterAxisSizingMode:[`FRAME`,`COMPONENT`,`COMPONENT_SET`],primaryAxisAlignItems:[`FRAME`,`COMPONENT`,`COMPONENT_SET`],counterAxisAlignItems:[`FRAME`,`COMPONENT`,`COMPONENT_SET`],cornerRadius:[`FRAME`,`RECTANGLE`,`ELLIPSE`,`POLYGON`,`STAR`,`VECTOR`,`BOOLEAN_OPERATION`],cornerSmoothing:[`FRAME`,`RECTANGLE`,`ELLIPSE`,`POLYGON`,`STAR`,`VECTOR`,`BOOLEAN_OPERATION`],layoutGrids:[`FRAME`,`COMPONENT`,`COMPONENT_SET`,`INSTANCE`],clipsContent:[`FRAME`,`COMPONENT`,`COMPONENT_SET`,`INSTANCE`],topLeftRadius:[`FRAME`,`RECTANGLE`],topRightRadius:[`FRAME`,`RECTANGLE`],bottomLeftRadius:[`FRAME`,`RECTANGLE`],bottomRightRadius:[`FRAME`,`RECTANGLE`]};function ke(e,t){let n=Oe[e];return n==null||n.some(e=>e===t)}var Ae=[`PAINT`,`TEXT`,`EFFECT`,`GRID`,`STROKE_WIDTH`,`CORNER_RADIUS`,`PADDING`,`SPACING`],je=[`PASS_THROUGH`,`NORMAL`,`DARKEN`,`MULTIPLY`,`COLOR_BURN`,`LIGHTEN`,`SCREEN`,`COLOR_DODGE`,`OVERLAY`,`SOFT_LIGHT`,`HARD_LIGHT`,`DIFFERENCE`,`EXCLUSION`,`HUE`,`SATURATION`,`COLOR`,`LUMINOSITY`],Me=[`MIN`,`CENTER`,`MAX`,`STRETCH`,`INHERIT`],Ne=[`MIN`,`CENTER`,`MAX`,`SPACE_BETWEEN`],Pe=[`MIN`,`CENTER`,`MAX`],Fe=[`mastergo`],Ie={blendMode:je,layoutAlign:Me,primaryAxisAlignItems:Ne,counterAxisAlignItems:Pe},Le={jsdesign:{blendMode:{deny:[`PASS_THROUGH`]}},mastergo:{layoutAlign:{deny:[`MIN`,`CENTER`,`MAX`]},layoutGrow:{allow:[0,1]}}},Re={mastergo:{cornerRadius:[`ELLIPSE`],cornerSmoothing:[`ELLIPSE`]}},ze={figma:{layoutGrow:{allow:[0,1]}},jsdesign:{layoutAlign:{deny:[`MIN`,`CENTER`,`MAX`]},layoutGrow:{allow:[0,1]}},mastergo:{primaryAxisAlignItems:{deny:[`MAX`,`SPACE_BETWEEN`]},counterAxisAlignItems:{deny:[`MAX`]}}};function Be(e,t){if(e==null)return null;let n=ze[e]?.[t];if(n!=null)return{rule:n,kind:`runtime`};let r=Le[e]?.[t];return r==null?null:{rule:r,kind:`typings`}}function Ve(e,t,n){let r=Be(e,t);if(r==null)return!0;let{rule:i}=r;return i.allow==null?!(i.deny??[]).some(e=>e===n):i.allow.some(e=>e===n)}function He(e,t,n){if(e==null)return!0;let r=Re[e]?.[t];return r==null||!r.some(e=>e===n)}function Ue(e,t){let n=Be(e,t);if(n==null)return null;let{rule:r,kind:i}=n,a=r.allow==null?(Ie[t]??[]).filter(n=>Ve(e,t,n)):r.allow.map(String),o=[];return o.push(i===`runtime`?`运行时实测不接受(平台类型虽然声明支持)`:`本平台类型不支持`),a.length>0&&o.push(`实测/类型支持 ${a.join(` / `)}`),o.join(`;`)}var We=[`string`,`boolean`,`variableAlias`],Ge={jsdesign:{setProperties:{deny:[`boolean`,`variableAlias`]}},mastergo:{setProperties:{deny:[`variableAlias`]}}};function Ke(e,t){if(e==null)return null;let n=Ge[e]?.[t]?.deny??[];return We.filter(e=>!n.some(t=>t===e))}var qe=[`UNION`,`SUBTRACT`,`INTERSECT`,`EXCLUDE`],Je={UNION:`合并`,SUBTRACT:`减去`,INTERSECT:`相交`,EXCLUDE:`排除`},Ye=qe.join(`/`),Xe=`布尔运算:${qe.map(e=>`${e}=${Je[e]}`).join(`,`)}`;function Ze(e){let t=/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(e.trim());if(t==null)return null;let n=t[1];(n.length===3||n.length===4)&&(n=[...n].map(e=>e+e).join(``));let r=e=>Number.parseInt(e,16)/255,i={r:r(n.slice(0,2)),g:r(n.slice(2,4)),b:r(n.slice(4,6))};return n.length===8&&(i.a=r(n.slice(6,8))),i}var Qe=m.object({r:m.number().min(0).max(255,`颜色通道最大 255`).describe(`schema.base.r`),g:m.number().min(0).max(255,`颜色通道最大 255`).describe(`schema.base.g`),b:m.number().min(0).max(255,`颜色通道最大 255`).describe(`schema.base.b`),a:m.number().min(0).max(255,`alpha 通道最大 255`).optional().describe(`schema.base.a`)}).strict(),$e=`颜色需为 {r,g,b[,a]} 对象(通道 0-1;任一路 >1 视为 0-255,自动整组 /255)或 hex 字符串(#RGB/#RGBA/#RRGGBB/#RRGGBBAA,如 "#ff0000")`,et=m.unknown().superRefine((e,t)=>{if(typeof e==`string`){Ze(e)??t.addIssue({code:m.ZodIssueCode.custom,message:`无效 hex 颜色 "${e}"(${$e})`});return}let n=Qe.safeParse(e);if(!n.success)for(let e of n.error.issues)t.addIssue({code:m.ZodIssueCode.custom,path:e.path,message:e.message})}),tt=et.describe(`颜色:{r,g,b} 对象(通道 0-1,>1 视为 0-255 自动归一化)或 hex 字符串,如 "#ff0000"(带透明度可用 8 位 hex,其 alpha 会转为 paint 级 opacity)`),nt=et.describe(`RGBA 颜色:{r,g,b,a} 对象(通道 0-1,>1 视为 0-255 自动归一化;a 缺省按 1)或 hex 字符串,如 "#ff0000"、"#ff000080"`),rt=m.object({color:nt.describe(`schema.base.color`),position:m.number().min(0).max(1).describe(`schema.base.position`)}).describe(`渐变停止点,如 {color:{r:1,g:0,b:0,a:1}, position:0}(起点红色)和 {color:{r:0,g:0,b:1,a:1}, position:1}(终点蓝色)`),it=m.array(m.array(m.number()).length(3)).length(2).describe(`schema.base.transformSchema`),at=m.enum(je).describe(`混合模式:PASS_THROUGH=穿透 | NORMAL=正常 | DARKEN=变暗 | MULTIPLY=正片叠底 | COLOR_BURN=颜色加深 | LIGHTEN=变亮 | SCREEN=滤色 | COLOR_DODGE=颜色减淡 | OVERLAY=叠加 | SOFT_LIGHT=柔光 | HARD_LIGHT=强光 | DIFFERENCE=差值 | EXCLUSION=排除 | HUE=色相 | SATURATION=饱和度 | COLOR=颜色 | LUMINOSITY=明度`),ot=m.discriminatedUnion(`type`,[m.object({type:m.literal(`SOLID`).describe(`schema.base.type`),color:tt.describe(`纯色值,支持 {r,g,b} 对象(通道 0-1)或 hex 字符串,如 "#ff0000"`),opacity:m.number().min(0).max(1).optional().describe(`schema.base.opacity`),visible:m.boolean().optional().describe(`schema.base.visible`),blendMode:at.optional().describe(`schema.base.blendMode`)}).strict().describe(`schema.base.blendMode2`),m.object({type:m.literal(`GRADIENT_LINEAR`).describe(`schema.base.type2`),gradientStops:m.array(rt).describe(`schema.base.gradientStops`),gradientTransform:it}).strict().describe(`schema.base.gradientTransform`),m.object({type:m.literal(`GRADIENT_RADIAL`).describe(`schema.base.type3`),gradientStops:m.array(rt).describe(`schema.base.gradientStops2`),gradientTransform:it}).strict().describe(`schema.base.gradientTransform2`),m.object({type:m.literal(`GRADIENT_ANGULAR`).describe(`schema.base.type4`),gradientStops:m.array(rt).describe(`schema.base.gradientStops3`),gradientTransform:it}).strict().describe(`schema.base.gradientTransform3`),m.object({type:m.literal(`IMAGE`).describe(`schema.base.type5`),imageHash:m.string().describe(`schema.base.imageHash`),scaleMode:m.enum([`FILL`,`FIT`,`CROP`,`TILE`]).optional().describe(`schema.base.scaleMode`)}).strict().describe(`schema.base.scaleMode2`)]),st=m.discriminatedUnion(`type`,[m.object({type:m.literal(`DROP_SHADOW`).describe(`schema.base.type6`),color:nt.describe(`schema.base.color2`),offset:m.object({x:m.number().describe(`schema.base.x`),y:m.number().describe(`schema.base.y`)}).describe(`schema.base.y2`),radius:m.number().min(0).describe(`schema.base.radius`),spread:m.number().optional().describe(`schema.base.spread`),visible:m.boolean().optional().describe(`schema.base.visible2`),blendMode:at.default(`NORMAL`).describe(`schema.base.blendMode3`),showShadowBehindNode:m.boolean().optional().describe(`schema.base.showShadowBehindNode`)}).strict().describe(`schema.base.showShadowBehindNode2`),m.object({type:m.literal(`INNER_SHADOW`).describe(`schema.base.type7`),color:nt.describe(`schema.base.color3`),offset:m.object({x:m.number().describe(`schema.base.x2`),y:m.number().describe(`schema.base.y3`)}).describe(`schema.base.y4`),radius:m.number().min(0).describe(`schema.base.radius2`),spread:m.number().optional().describe(`schema.base.spread2`),visible:m.boolean().optional().describe(`schema.base.visible3`),blendMode:at.default(`NORMAL`).describe(`schema.base.blendMode4`)}).strict().describe(`schema.base.blendMode5`),m.object({type:m.literal(`LAYER_BLUR`).describe(`schema.base.type8`),radius:m.number().min(0).describe(`schema.base.radius3`),visible:m.boolean().optional().describe(`schema.base.visible4`)}).strict().describe(`schema.base.visible5`),m.object({type:m.literal(`BACKGROUND_BLUR`).describe(`schema.base.type9`),radius:m.number().min(0).describe(`schema.base.radius4`),visible:m.boolean().optional().describe(`schema.base.visible6`)}).strict().describe(`schema.base.visible7`)]),ct=m.enum([`MIN`,`MAX`,`STRETCH`,`CENTER`,`SCALE`]).describe(`约束类型:MIN=吸附左/上 | MAX=吸附右/下 | STRETCH=拉伸 | CENTER=居中 | SCALE=等比缩放`),lt=m.object({pattern:m.enum([`ROWS`,`COLUMNS`,`GRID`]).describe(`schema.base.pattern`),alignment:m.enum([`MIN`,`MAX`,`CENTER`,`STRETCH`]).optional().describe(`schema.base.alignment`),sectionSize:m.number().optional().describe(`schema.base.sectionSize`),count:m.number().int().positive().optional(),gutterSize:m.number().optional().describe(`schema.base.gutterSize`),offset:m.number().optional().describe(`schema.base.offset`),visible:m.boolean().optional(),color:nt.optional()}).superRefine((e,t)=>{if(e.pattern===`GRID`&&e.sectionSize==null&&t.addIssue({code:m.ZodIssueCode.custom,message:`pattern 为 GRID 时,sectionSize 为必填项`,path:[`sectionSize`]}),e.pattern===`ROWS`||e.pattern===`COLUMNS`)for(let n of[`count`,`gutterSize`])e[n]??t.addIssue({code:m.ZodIssueCode.custom,message:`pattern 为 ${e.pattern} 时,${n} 为必填项(三平台的 RowsColsLayoutGrid 都把它列为必填)`,path:[n]})}),ut=m.object({data:m.string().describe(`SVG path data,如 "M0 0 L100 0 L100 100 Z"(M=移动到,L=画线到,Z=闭合)。仅支持 M/L/Q/C/Z 指令(SVG 子集,不支持 A 圆弧等);完整 SVG 请改用 jsd_create_svg`),windingRule:m.enum([`NONZERO`,`EVENODD`,`NONE`]).default(`NONZERO`).describe(`schema.base.windingRule`)}),dt=m.object({family:m.string().describe(`字体族:用 jsd_list_fonts 的 fonts[].family 原样值,如 "SourceHanSansCN_family"(带 _family 后缀是平台列表的原始名)`),style:m.string().describe(`字型:必须是同一 family 的 fonts[].styles 里的**全名**,如 "SourceHanSansCN-Bold"(不是简称 "Bold")。写错不会报错,会静默退回默认字面(命中时结果 warnings 点名)`)}),ft=m.union([m.object({value:m.number().describe(`schema.base.value`),unit:m.literal(`PIXELS`).describe(`schema.base.unit`)}).describe(`固定行高:{value: 数值, unit: "PIXELS"},如 {value: 24, unit: "PIXELS"}`),m.object({value:m.number().describe(`schema.base.value2`),unit:m.literal(`PERCENT`).describe(`schema.base.unit2`)}).describe(`百分比行高:{value: 数值, unit: "PERCENT"},如 {value: 150, unit: "PERCENT"}`),m.object({unit:m.literal(`AUTO`).describe(`schema.base.unit3`)}).describe(`schema.base.unit4`)]),pt=m.object({value:m.number(),unit:m.enum([`PIXELS`,`PERCENT`]).describe(`schema.base.unit5`)}),mt=m.object({id:m.string().optional().describe(`步骤唯一标识,供后续步骤以双花括号占位符(id.字段路径)引用本步结果;缺省自动命名 step1/step2/…`),tool:m.string().describe(`要执行的 jsd_* 工具名,如 jsd_create_rectangle / jsd_find / jsd_set_fill_color`),args:m.record(m.string(),m.unknown()).optional().describe(`该工具的完整入参;任意位置的字符串值里可放双花括号占位符。两种来源:引用先前步骤结果(步骤id.字段路径),或按名字取文档里已有的资源 —— {{@comp:名称}} 给组件/变体集 id、{{@var:名称}} 给变量 id(读一次 jsd_get_page 的资源清单,同名多命中或零命中会点名中止整批)。注意:jsd_create_* 是单类型工具,节点类型已固化在工具名里(jsd_create_frame=FRAME),args 不必再传 type`),continueOnError:m.boolean().optional().describe(`本步【执行】失败时是否继续后续步骤;仅对执行失败生效,id 重复/未知工具/引用解析失败一律中止`)}),ht=m.object({calls:m.array(mt).max(50).optional().describe(`schema.batch.calls`),callsFile:m.string().optional().describe(`schema.batch.callsFile`),stopOnError:m.boolean().optional().describe(`全局失败策略,默认 true=任一步执行失败即停止,false=配合单步走完全部`),checkDrift:m.boolean().optional().describe(`是否对结构变更步骤做同层几何漂移复核,默认 true。步骤里含 remove/reparent/group/ungroup/flatten/repair 时:变更前记下受影响父层的子节点坐标,该步结束后再读一次比对,漂移写进结果 warnings(引擎会把没碰到的兄弟静默挪走)。代价是每步多两次读数;确定不需要时传 false`)}),gt=m.object({ok:m.boolean().describe(`schema.batch.ok`),executed:m.number().int().min(0).describe(`schema.batch.executed`),total:m.number().int().min(0).describe(`schema.batch.total`),results:m.array(m.object({id:m.string(),tool:m.string(),ok:m.boolean(),data:m.unknown().optional().describe(`成功时该工具的 structuredContent(已做回显摘要裁剪,见工具描述)`),error:m.string().optional().describe(`schema.batch.error`)})).describe(`schema.batch.error2`),echoTrimmed:m.boolean().optional(),echoNote:m.string().optional(),warnings:m.array(m.string()).optional()}),_t=m.record(m.string(),m.unknown()),vt=[`SLICE`,`FRAME`,`GROUP`,`COMPONENT_SET`,`COMPONENT`,`INSTANCE`,`BOOLEAN_OPERATION`,`VECTOR`,`STAR`,`LINE`,`ELLIPSE`,`POLYGON`,`RECTANGLE`,`TEXT`],yt={SLICE:`切片`,FRAME:`容器`,GROUP:`分组`,COMPONENT_SET:`组件集`,COMPONENT:`组件`,INSTANCE:`实例`,BOOLEAN_OPERATION:`布尔运算`,VECTOR:`矢量`,STAR:`星形`,LINE:`线段`,ELLIPSE:`椭圆`,POLYGON:`多边形`,RECTANGLE:`矩形`,TEXT:`文本`},bt=`节点类型:${vt.map(e=>`${e}=${yt[e]}`).join(` | `)}`,xt=[`TEXT_PATH`,`TRANSFORM_GROUP`,`STICKY`,`CONNECTOR`,`SHAPE_WITH_TEXT`,`CODE_BLOCK`,`STAMP`,`WIDGET`,`EMBED`,`LINK_UNFURL`,`MEDIA`,`SECTION`,`HIGHLIGHT`,`WASHI_TAPE`,`TABLE`,`SLIDE`,`SLIDE_ROW`,`SLIDE_GRID`,`SLOT`,`INTERACTIVE_SLIDE_ELEMENT`],St=[`INTELLIGENT_CONTAINER`],Ct=[...vt,...xt,...St],wt=m.enum(vt).describe(bt),Tt=m.enum(Ct).describe(`${bt};另有 Figma 独有只读类型(TEXT_PATH/STICKY/SECTION/TABLE/SLIDE 等 20 类)可能出现在读结果里,本仓不支持创建与修改它们`),Et=m.object({type:wt.describe(`schema.executeSchemas.type`),name:m.string().optional(),x:m.number().optional().describe(`schema.executeSchemas.x`),y:m.number().optional().describe(`schema.executeSchemas.y`),width:m.number().optional(),height:m.number().optional()}).catchall(m.unknown()),y={name:m.string().optional(),x:m.number().optional().describe(`schema.executeSchemas.x2`),y:m.number().optional().describe(`schema.executeSchemas.y2`),width:m.number().optional().describe(`schema.executeSchemas.width`),height:m.number().optional().describe(`schema.executeSchemas.height`),rotation:m.number().optional().describe(`schema.executeSchemas.rotation`),opacity:m.number().optional().describe(`schema.executeSchemas.opacity`),visible:m.boolean().optional(),locked:m.boolean().optional(),isMask:m.boolean().optional(),children:m.array(Et).max(100).optional().describe(`子节点数组(递归嵌套,最多 100 个直接子节点;更大的结构建议分批创建后用 jsd_manage_nodes op=reparent 归组)。子节点可使用的字段与顶层 create 入参一致(fills/strokes/cornerRadius/effects 等均可用);x/y 相对父节点,未传 x/y 会叠放在父节点原点(0,0)——非 auto-layout 容器需为每个子节点指定相对坐标`)},b={fills:m.array(ot).optional().describe(`填充列表(Paint 数组)。缺省时的引擎默认:FRAME 为白底;非 FRAME 图形若同时传了 strokes,则填充置空(纯描边,不再被引擎塞 #CCCCCC 灰底)——需要底色请显式传 fills`),strokes:m.array(ot).optional().describe(`schema.executeSchemas.strokes`),strokeWeight:m.number().optional().describe(`schema.executeSchemas.strokeWeight`),strokeTopWeight:m.number().optional().describe(`schema.executeSchemas.strokeTopWeight`),strokeBottomWeight:m.number().optional().describe(`schema.executeSchemas.strokeBottomWeight`),strokeLeftWeight:m.number().optional().describe(`schema.executeSchemas.strokeLeftWeight`),strokeRightWeight:m.number().optional().describe(`schema.executeSchemas.strokeRightWeight`),strokeAlign:m.enum([`CENTER`,`INSIDE`,`OUTSIDE`]).optional().describe(`schema.executeSchemas.strokeAlign`),strokeCap:m.enum([`NONE`,`ROUND`,`SQUARE`,`ARROW_LINES`,`ARROW_EQUILATERAL`]).optional().describe(`schema.executeSchemas.strokeCap`),strokeJoin:m.enum([`MITER`,`BEVEL`,`ROUND`]).optional().describe(`schema.executeSchemas.strokeJoin`),dashPattern:m.array(m.number()).optional().describe(`schema.executeSchemas.dashPattern`),blendMode:at.optional(),effects:m.array(st).optional().describe(`schema.executeSchemas.effects`),constraints:m.object({horizontal:ct.describe(`水平约束:MIN|MAX|STRETCH|CENTER|SCALE`),vertical:ct.describe(`垂直约束:MIN|MAX|STRETCH|CENTER|SCALE`)}).optional().describe(`schema.executeSchemas.vertical`),clipsContent:m.boolean().optional().describe(`schema.executeSchemas.clipsContent`),cornerSmoothing:m.number().optional().describe(`schema.executeSchemas.cornerSmoothing`),layoutGrids:m.array(lt).optional().describe(`schema.executeSchemas.layoutGrids`),fillStyleId:m.string().optional().describe(`schema.sharedProps.fillStyleId`),strokeStyleId:m.string().optional().describe(`schema.sharedProps.strokeStyleId`),textStyleId:m.string().optional().describe(`schema.sharedProps.textStyleId`),effectStyleId:m.string().optional().describe(`schema.sharedProps.effectStyleId`)},Dt={cornerRadius:m.number().optional().describe(`schema.executeSchemas.cornerRadius`),topLeftRadius:m.number().optional().describe(`schema.executeSchemas.topLeftRadius`),topRightRadius:m.number().optional().describe(`schema.executeSchemas.topRightRadius`),bottomLeftRadius:m.number().optional().describe(`schema.executeSchemas.bottomLeftRadius`),bottomRightRadius:m.number().optional().describe(`schema.executeSchemas.bottomRightRadius`)},Ot=m.object({type:m.literal(`FRAME`),...y,layoutMode:m.enum([`NONE`,`HORIZONTAL`,`VERTICAL`]).optional().describe(`自动布局方向:NONE=无布局,HORIZONTAL=水平排列,VERTICAL=垂直排列。传 itemSpacing/padding*/primaryAxis* 等布局属性前必须先设为 HORIZONTAL 或 VERTICAL`),itemSpacing:m.number().optional().describe(`自动布局项间距(px),需先设 layoutMode;primaryAxisAlignItems=SPACE_BETWEEN 时该项被忽略(子项均匀分布)`),paddingTop:m.number().optional().describe(`schema.executeSchemas.paddingTop`),paddingRight:m.number().optional().describe(`schema.executeSchemas.paddingRight`),paddingBottom:m.number().optional().describe(`schema.executeSchemas.paddingBottom`),paddingLeft:m.number().optional().describe(`schema.executeSchemas.paddingLeft`),primaryAxisSizingMode:m.enum([`FIXED`,`AUTO`]).optional().describe(`schema.executeSchemas.primaryAxisSizingMode`),counterAxisSizingMode:m.enum([`FIXED`,`AUTO`]).optional().describe(`schema.executeSchemas.counterAxisSizingMode`),primaryAxisAlignItems:m.enum([`MIN`,`MAX`,`CENTER`,`SPACE_BETWEEN`]).optional().describe(`主轴对齐:MIN|MAX|CENTER|SPACE_BETWEEN;设为 SPACE_BETWEEN 时 itemSpacing 被忽略(子项均匀分布)`),counterAxisAlignItems:m.enum([`MIN`,`MAX`,`CENTER`]).optional().describe(`schema.executeSchemas.counterAxisAlignItems`),layoutGrow:m.number().optional().describe(`schema.executeSchemas.layoutGrow`),layoutAlign:m.enum([`MIN`,`CENTER`,`MAX`,`STRETCH`,`INHERIT`]).optional().describe(`schema.executeSchemas.layoutAlign`),...Dt,...b}).strict().superRefine((e,t)=>{(e.itemSpacing!=null||e.paddingTop!=null||e.paddingRight!=null||e.paddingBottom!=null||e.paddingLeft!=null||e.primaryAxisSizingMode!=null||e.counterAxisSizingMode!=null||e.primaryAxisAlignItems!=null||e.counterAxisAlignItems!=null)&&(e.layoutMode==null||e.layoutMode===`NONE`)&&t.addIssue({code:m.ZodIssueCode.custom,message:`传 itemSpacing/padding*/primaryAxis*/counterAxis* 等布局属性前,layoutMode 必须设为 HORIZONTAL 或 VERTICAL`,path:[`layoutMode`]})}).strict().describe(`FRAME=容器(可 auto-layout)。注意:未显式传 fills 时引擎默认白底,透明容器请显式传 fills:[{type:"SOLID",color:{r:0,g:0,b:0},opacity:0}]`),kt=m.object({type:m.literal(`RECTANGLE`),...y,...Dt,...b}).strict().describe(`schema.executeSchemas.type2`),At=m.object({type:m.literal(`ELLIPSE`),...y,cornerRadius:m.number().optional().describe(`schema.executeSchemas.cornerRadius2`),arcData:m.object({startingAngle:m.number().describe(`schema.executeSchemas.startingAngle`),endingAngle:m.number().describe(`schema.executeSchemas.endingAngle`),innerRadius:m.number().describe(`schema.executeSchemas.innerRadius`)}).optional().describe(`schema.executeSchemas.innerRadius2`),...b}).strict().describe(`schema.executeSchemas.innerRadius3`),jt=m.object({type:m.literal(`LINE`),...y,...b}).strict().describe(`schema.executeSchemas.type3`),Mt=m.object({type:m.literal(`POLYGON`),...y,pointCount:m.number().describe(`schema.executeSchemas.pointCount`),cornerRadius:m.number().optional().describe(`schema.executeSchemas.cornerRadius3`),topLeftRadius:m.number().optional().describe(`schema.executeSchemas.topLeftRadius2`),topRightRadius:m.number().optional().describe(`schema.executeSchemas.topRightRadius2`),bottomLeftRadius:m.number().optional().describe(`schema.executeSchemas.bottomLeftRadius2`),bottomRightRadius:m.number().optional().describe(`schema.executeSchemas.bottomRightRadius2`),...b}).strict().describe(`schema.executeSchemas.bottomRightRadius3`),Nt=m.object({type:m.literal(`STAR`),...y,pointCount:m.number().describe(`schema.executeSchemas.pointCount2`),innerRadius:m.number().describe(`schema.executeSchemas.innerRadius4`),cornerRadius:m.number().optional().describe(`schema.executeSchemas.cornerRadius4`),topLeftRadius:m.number().optional().describe(`schema.executeSchemas.topLeftRadius3`),topRightRadius:m.number().optional().describe(`schema.executeSchemas.topRightRadius3`),bottomLeftRadius:m.number().optional().describe(`schema.executeSchemas.bottomLeftRadius3`),bottomRightRadius:m.number().optional().describe(`schema.executeSchemas.bottomRightRadius4`),...b}).strict().describe(`schema.executeSchemas.bottomRightRadius5`),Pt=m.object({type:m.literal(`VECTOR`),...y,vectorPaths:m.array(ut).describe(`schema.executeSchemas.vectorPaths`),...b}).strict().describe(`VECTOR=矢量(配合 vectorPaths 传 SVG path data)。注意:当前平台创建后 vectorPaths 偶发丢失/形变,短直线段建议改用 LINE+rotation 更稳定`),Ft=m.object({type:m.literal(`TEXT`),...y,characters:m.string().describe(`文本内容,如 "Hello World"。注意:个别 emoji 依赖客户端字体可能缺字(渲染为 ☒),上线前逐个目检`),fontSize:m.number().optional().describe(`schema.executeSchemas.fontSize`),fontName:dt.optional().describe(`字体:{family,style},如 {family:"PingFang SC",style:"Regular"};需精确匹配,建议先用 jsd_list_fonts 查可用字体(不可用时静默回退默认字体)`),textAlignHorizontal:m.enum([`LEFT`,`CENTER`,`RIGHT`,`JUSTIFIED`]).optional().describe(`schema.executeSchemas.textAlignHorizontal`),textAlignVertical:m.enum([`TOP`,`CENTER`,`BOTTOM`]).optional().describe(`schema.executeSchemas.textAlignVertical`),textAutoResize:m.enum([`NONE`,`WIDTH_AND_HEIGHT`,`HEIGHT`,`TRUNCATE`]).optional().describe(`文本自适应:NONE=固定尺寸|WIDTH_AND_HEIGHT=按内容撑开(缺省,此时显式 width/height 会被覆盖)|HEIGHT=固定宽自适应高|TRUNCATE=截断。要固定文本框尺寸必须设为 NONE`),textCase:m.enum([`ORIGINAL`,`UPPER`,`LOWER`,`TITLE`]).optional().describe(`schema.executeSchemas.textCase`),textDecoration:m.enum([`NONE`,`UNDERLINE`,`STRIKETHROUGH`]).optional().describe(`schema.executeSchemas.textDecoration`),lineHeight:ft.optional().describe(`schema.executeSchemas.lineHeight`),letterSpacing:pt.optional().describe(`schema.executeSchemas.letterSpacing`),...b}).strict().describe(`schema.executeSchemas.letterSpacing2`),It=m.object({type:m.literal(`GROUP`),...y,children:m.array(Et).min(2).max(100).describe(`schema.executeSchemas.children`),layoutMode:m.enum([`NONE`,`HORIZONTAL`,`VERTICAL`]).optional().describe(`自动布局方向:NONE=纯归组,HORIZONTAL=水平,VERTICAL=垂直。传 itemSpacing/padding* 等布局属性前必须先设为 HORIZONTAL 或 VERTICAL`),itemSpacing:m.number().optional().describe(`项间距(px),需先设 layoutMode;primaryAxisAlignItems=SPACE_BETWEEN 时该项被忽略(子项均匀分布)`),paddingTop:m.number().optional().describe(`schema.executeSchemas.paddingTop2`),paddingRight:m.number().optional().describe(`schema.executeSchemas.paddingRight2`),paddingBottom:m.number().optional().describe(`schema.executeSchemas.paddingBottom2`),paddingLeft:m.number().optional().describe(`schema.executeSchemas.paddingLeft2`),primaryAxisSizingMode:m.enum([`FIXED`,`AUTO`]).optional().describe(`schema.executeSchemas.primaryAxisSizingMode2`),counterAxisSizingMode:m.enum([`FIXED`,`AUTO`]).optional().describe(`schema.executeSchemas.counterAxisSizingMode2`),primaryAxisAlignItems:m.enum([`MIN`,`MAX`,`CENTER`,`SPACE_BETWEEN`]).optional().describe(`主轴对齐:MIN|MAX|CENTER|SPACE_BETWEEN;设为 SPACE_BETWEEN 时 itemSpacing 被忽略(子项均匀分布)`),counterAxisAlignItems:m.enum([`MIN`,`MAX`,`CENTER`]).optional().describe(`schema.executeSchemas.counterAxisAlignItems2`),...b}).strict().superRefine((e,t)=>{(e.itemSpacing!=null||e.paddingTop!=null||e.paddingRight!=null||e.paddingBottom!=null||e.paddingLeft!=null||e.primaryAxisSizingMode!=null||e.counterAxisSizingMode!=null||e.primaryAxisAlignItems!=null||e.counterAxisAlignItems!=null)&&(e.layoutMode==null||e.layoutMode===`NONE`)&&t.addIssue({code:m.ZodIssueCode.custom,message:`传 itemSpacing/padding*/primaryAxis*/counterAxis* 等布局属性前,layoutMode 必须设为 HORIZONTAL 或 VERTICAL`,path:[`layoutMode`]})}).describe(`schema.executeSchemas.path`),Lt=m.object({type:m.literal(`BOOLEAN_OPERATION`),...y,booleanOperation:m.enum(qe).describe(Xe),children:m.array(Et).min(2).describe(`schema.executeSchemas.children2`),...b}).strict().describe(`schema.executeSchemas.children3`),Rt=m.discriminatedUnion(`type`,[Ot,kt,At,jt,Mt,Nt,Pt,Ft,It,Lt]),zt=m.object({mode:m.enum([`center`,`manual`,`absolute`]).optional().describe(`放置模式:center=把每个根节点各自移到视口中心(缺省;会忽略 ops 内根节点自身的 x/y,多个根节点会互相叠放)|manual=保留 ops 内根节点自身的 x/y(按坐标布局用这个)|absolute=把所有根节点统一放到下方 x/y(必填,多根会叠在同一坐标)。建议一次调用只建一个根节点,层级结构用 children 表达`),x:m.number().optional().describe(`absolute 模式下所有根节点的 X 坐标,与 mode="absolute" 配合使用`),y:m.number().optional().describe(`absolute 模式下所有根节点的 Y 坐标,与 mode="absolute" 配合使用`)}).superRefine((e,t)=>{e.mode===`absolute`&&(e.x==null||e.y==null)&&t.addIssue({code:m.ZodIssueCode.custom,message:`placement.mode 为 absolute 时,x 和 y 均为必填项`,path:e.x==null?[`x`]:[`y`]})});m.object({ops:m.array(Rt).describe(`设计指令节点树;建议单一根节点(多个根节点会被 placement 统一摆放,可能互相叠放)`),placement:zt.optional().describe(`放置方式,缺省 center 居中且忽略 ops 内根节点的 x/y。需要按坐标摆放时传 mode:"manual"(保留 ops 内 x/y)或 "absolute"(顶层统一坐标)`)}).strict(),m.object({svg:m.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>`),name:m.string().optional().describe(`schema.execute.name`)});var Bt=m.object({svg:m.string().optional().describe(`完整 SVG 字符串(与 svgPath 二选一)`),svgPath:m.string().optional().describe(`本地 .svg 文件路径,由后台服务读取(与 svg 二选一)。**代码生成的大 SVG 走这条**`),name:m.string().optional().describe(`schema.execute.name`)}).strict().superRefine((e,t)=>{let n=e=>typeof e==`string`&&e.trim()!==``;n(e.svg)===n(e.svgPath)&&t.addIssue({code:m.ZodIssueCode.custom,message:n(e.svg)?`svg 与 svgPath 只能传一个:svgPath 是给「SVG 已在本地文件里」用的`:`必须传 svg(内联 SVG 字符串)或 svgPath(本地 .svg 文件路径),二选一`,path:[`svg`]})}),Vt=m.object({html:m.string().describe(`schema.execute.html`),name:m.string().optional().describe(`schema.execute.name2`)}),Ht=m.object({icon:m.string().describe(`图标名/别名/语义描述,如 home、arrow-right、search、magnifier(搜索);支持模糊匹配与别名联想,查无返回候选提示`),size:m.number().optional().describe(`schema.execute.size`),color:m.string().optional().describe(`schema.execute.color`),strokeWidth:m.number().optional().describe(`schema.execute.strokeWidth`),name:m.string().optional().describe(`schema.execute.name3`)});m.object({});var Ut=m.object({depth:m.number().optional().describe(`schema.executeOp.depth`)}),Wt=[`page`,`document`],Gt={"platform.jsdesign":`即时设计`,"platform.figma":`Figma`,"platform.mastergo":`MasterGo`,"capability.core.create":`创建`,"capability.core.modify":`修改`,"capability.core.structure":`结构操作`,"capability.core.component":`组件`,"capability.core.export":`导出`,"capability.core.image":`图片填充`,"capability.host.styles":`本地样式`,"capability.host.styleEnumeration":`本地样式清单(能列出有哪些样式)`,"capability.host.styleEnumerationSync":`样式枚举走同步入口(运行时的 *Async 成员不可用)`,"capability.host.mainComponentSync":`主组件走同步字段(运行时的 getMainComponentAsync 永不返回)`,"capability.host.textTruncation":`文本截断`,"capability.host.componentProperties":`组件属性`,"capability.host.documentScopeRead":`文档范围读(能读非当前页)`,"capability.host.variables":`变量`,"capability.host.inPlaceVariants":`原位合并变体`,"locale.system":`跟随系统`,"locale.zh-CN":`中文`,"locale.en":`English`,"locale.abbr.zh-CN":`中`,"locale.abbr.en":`EN`,"locale.menu":`界面语言`,"locale.title.followSystem":`界面语言:跟随系统(当前 {locale})`,"locale.title.fixed":`界面语言:{locale}`,"status.connected.label":`已连接`,"status.connected.title":`服务在线,插件与 AI 会话已连通`,"status.connecting.label":`连接中…`,"status.connecting.title":`已连上后台服务,等待它确认这条通道`,"status.waiting.label":`等待服务`,"status.waiting.title":`服务离线时无需手动操作,AI 调用会自动拉起`,"status.superseded.label":`已被接管`,"status.superseded.title":`另一个插件面板占用了通道;点「夺回」可切回本面板`,"header.retry":`重试`,"header.retry.title":`立即重连后台服务,不必等自动重连的退避间隔`,"header.reclaim":`夺回`,"header.reclaim.title":`夺回被另一个插件面板占用的通道`,"header.theme.toDark":`切换到暗色主题`,"header.theme.toLight":`切换到亮色主题`,"header.cameraLock.locked":`相机已锁定`,"header.cameraLock.unlocked":`相机跟随`,"header.cameraLock.title.locked":`相机已锁定:操作画布时不移动你的视口(点击改为跟随)`,"header.cameraLock.title.unlocked":`相机跟随:操作画布后视口滚动缩放到结果(点击锁定)`,"header.minimize":`最小化`,"header.minimize.title":`最小化面板,只留 logo;双击 logo 恢复`,"header.restore.title":`双击 logo 恢复面板`,"upgrade.title":`有新版本可用(点击查看升级步骤)`,"upgrade.modal.title":`升级到最新版本`,"upgrade.current":`当前 {version}`,"upgrade.latest":`最新 {version}`,"upgrade.plugin.label":`插件`,"upgrade.service.label":`后台服务`,"upgrade.step.service":`① 后台服务,重启 AI 会话就行。它跑的是 npx -y text-to-design-mcp@latest,每次都是最新的`,"upgrade.step.plugin.head":`② 插件要手动换。下载`,"upgrade.step.plugin.tail":`最新版解压,在设计软件里导入对应平台的 manifest`,"upgrade.step.verify":`③ 重新运行插件,顶部的升级图标没了就是对齐了`,"upgrade.copy":`复制给 AI 助手`,"upgrade.prompt":`我在用 text-to-design,插件 text-to-design-ui 当前 {ui}、最新 {uiLatest},后台服务 text-to-design-mcp 当前 {mcp}、最新 {mcpLatest}。帮我升到最新:① 确认 MCP 配置里的命令带 latest,然后重启 AI 会话;② 下载 text-to-design-ui 最新版(npm pack 或 GitHub Releases 的 zip)解压,告诉我即时设计 / Figma / MasterGo 分别该导入 dist 下哪份 manifest.json;③ 完成后回报两个版本号。`,"toast.copy.done":`已复制`,"toast.copy.failed":`复制失败`,"conn.connected":`已连接。选中画布节点后点「复制」,把内容发给 AI 助手——例如:「按这个节点样式帮我再做一张卡片」`,"conn.superseded":`通道已被另一个插件面板接管(同一时刻只服务一个面板),自动重连已停止。点顶部状态徽章旁的「夺回」切回本面板。`,"conn.disconnected.title":`尚未连接后台服务`,"conn.disconnected.tutorial":`安装教程`,"conn.copyAi":`① 复制给 AI 助手`,"conn.copyDaemon":`② 复制启动命令`,"conn.copyAi.hint":`发给 AI,让它调用 jsd_ping 唤醒后台服务`,"conn.daemon.note":`在本机终端执行即常驻到下次重启;重复执行安全(已有实例会自动跳过)。`,"conn.announce.connected":`已连接后台服务`,"conn.announce.connecting":`正在连接后台服务`,"conn.announce.superseded":`通道已被另一个插件面板接管`,"conn.announce.disconnected":`尚未连接后台服务`,"conn.wakeCmd":`请帮我连接 text-to-design 后台服务:
|
|
2
|
+
import{createRequire as e}from"node:module";import{appendFileSync as t,mkdirSync as n,readFileSync as r,rmSync as i,statSync as a,writeFileSync as o}from"node:fs";import{homedir as s,tmpdir as c}from"node:os";import{dirname as l,isAbsolute as u,join as d,resolve as f,sep as p}from"node:path";import{core as m,z as h}from"zod";import{createServer as ee}from"node:http";import{WebSocket as g,WebSocketServer as te}from"ws";import{Client as ne,StreamableHTTPClientTransport as re}from"@modelcontextprotocol/client";import{McpServer as ie,ResourceTemplate as ae,SUPPORTED_PROTOCOL_VERSIONS as _,createMcpHandler as oe,fromJsonSchema as se}from"@modelcontextprotocol/server";import{serveStdio as ce}from"@modelcontextprotocol/server/stdio";import{spawn as le,spawnSync as ue}from"node:child_process";import{localhostHostValidation as de,localhostOriginValidation as fe,toNodeHandler as pe}from"@modelcontextprotocol/node";import{readFile as me,stat as he}from"node:fs/promises";import{isTag as ge}from"domhandler";import{parseDocument as _e}from"htmlparser2";import ve from"fuse.js";var v=class extends Error{code;constructor(e,t){super(t),this.name=`BridgeError`,this.code=e}};function ye(e){return e instanceof v?e.code:`plugin_error`}var be=3e4,xe=4e3;2*be;var Se=3e4,Ce={styles:{kind:`propGate`,props:[`fillStyleId`,`strokeStyleId`,`textStyleId`,`effectStyleId`],labelKey:`capability.host.styles`},styleEnumeration:{kind:`flow`,labelKey:`capability.host.styleEnumeration`},styleEnumerationSync:{kind:`flow`,labelKey:`capability.host.styleEnumerationSync`},mainComponentSync:{kind:`flow`,labelKey:`capability.host.mainComponentSync`},textTruncation:{kind:`propGate`,props:[`textTruncation`,`maxLines`],labelKey:`capability.host.textTruncation`},componentProperties:{kind:`propGate`,props:[`componentProperties`],labelKey:`capability.host.componentProperties`},variables:{kind:`channel`,labelKey:`capability.host.variables`},documentScopeRead:{kind:`flow`,labelKey:`capability.host.documentScopeRead`},inPlaceVariants:{kind:`flow`,labelKey:`capability.host.inPlaceVariants`}};function we(e){return Object.keys(e)}var Te=we(Ce);Object.fromEntries(Object.entries(Ce).map(([e,t])=>[e,t.kind===`propGate`?t.props:[]]));var Ee=Object.fromEntries(Object.entries(Ce).flatMap(([e,t])=>t.kind===`propGate`?t.props.map(t=>[t,e]):[])),De=we({create:{labelKey:`capability.core.create`},modify:{labelKey:`capability.core.modify`},structure:{labelKey:`capability.core.structure`},component:{labelKey:`capability.core.component`},export:{labelKey:`capability.core.export`},image:{labelKey:`capability.core.image`}}),Oe={pointCount:[`POLYGON`,`STAR`],innerRadius:[`STAR`],arcData:[`ELLIPSE`],characters:[`TEXT`],fontSize:[`TEXT`],fontName:[`TEXT`],textAlignHorizontal:[`TEXT`],textAlignVertical:[`TEXT`],textAutoResize:[`TEXT`],textCase:[`TEXT`],textDecoration:[`TEXT`],lineHeight:[`TEXT`],letterSpacing:[`TEXT`],textTruncation:[`TEXT`],maxLines:[`TEXT`],layoutMode:[`FRAME`,`COMPONENT`,`COMPONENT_SET`],itemSpacing:[`FRAME`,`COMPONENT`,`COMPONENT_SET`],paddingTop:[`FRAME`,`COMPONENT`,`COMPONENT_SET`],paddingRight:[`FRAME`,`COMPONENT`,`COMPONENT_SET`],paddingBottom:[`FRAME`,`COMPONENT`,`COMPONENT_SET`],paddingLeft:[`FRAME`,`COMPONENT`,`COMPONENT_SET`],primaryAxisSizingMode:[`FRAME`,`COMPONENT`,`COMPONENT_SET`],counterAxisSizingMode:[`FRAME`,`COMPONENT`,`COMPONENT_SET`],primaryAxisAlignItems:[`FRAME`,`COMPONENT`,`COMPONENT_SET`],counterAxisAlignItems:[`FRAME`,`COMPONENT`,`COMPONENT_SET`],cornerRadius:[`FRAME`,`RECTANGLE`,`ELLIPSE`,`POLYGON`,`STAR`,`VECTOR`,`BOOLEAN_OPERATION`],cornerSmoothing:[`FRAME`,`RECTANGLE`,`ELLIPSE`,`POLYGON`,`STAR`,`VECTOR`,`BOOLEAN_OPERATION`],layoutGrids:[`FRAME`,`COMPONENT`,`COMPONENT_SET`,`INSTANCE`],clipsContent:[`FRAME`,`COMPONENT`,`COMPONENT_SET`,`INSTANCE`],topLeftRadius:[`FRAME`,`RECTANGLE`],topRightRadius:[`FRAME`,`RECTANGLE`],bottomLeftRadius:[`FRAME`,`RECTANGLE`],bottomRightRadius:[`FRAME`,`RECTANGLE`]};function ke(e,t){let n=Oe[e];return n==null||n.some(e=>e===t)}var Ae=[`PAINT`,`TEXT`,`EFFECT`,`GRID`,`STROKE_WIDTH`,`CORNER_RADIUS`,`PADDING`,`SPACING`],je=[`PASS_THROUGH`,`NORMAL`,`DARKEN`,`MULTIPLY`,`COLOR_BURN`,`LIGHTEN`,`SCREEN`,`COLOR_DODGE`,`OVERLAY`,`SOFT_LIGHT`,`HARD_LIGHT`,`DIFFERENCE`,`EXCLUSION`,`HUE`,`SATURATION`,`COLOR`,`LUMINOSITY`],Me=[`MIN`,`CENTER`,`MAX`,`STRETCH`,`INHERIT`],Ne=[`MIN`,`CENTER`,`MAX`,`SPACE_BETWEEN`],Pe=[`MIN`,`CENTER`,`MAX`],Fe=[`mastergo`],Ie={blendMode:je,layoutAlign:Me,primaryAxisAlignItems:Ne,counterAxisAlignItems:Pe},Le={jsdesign:{blendMode:{deny:[`PASS_THROUGH`]}},mastergo:{layoutAlign:{deny:[`MIN`,`CENTER`,`MAX`]},layoutGrow:{allow:[0,1]}}},Re={mastergo:{cornerRadius:[`ELLIPSE`],cornerSmoothing:[`ELLIPSE`]}},ze={figma:{layoutGrow:{allow:[0,1]}},jsdesign:{layoutAlign:{deny:[`MIN`,`CENTER`,`MAX`]},layoutGrow:{allow:[0,1]}},mastergo:{primaryAxisAlignItems:{deny:[`MAX`,`SPACE_BETWEEN`]},counterAxisAlignItems:{deny:[`MAX`]}}};function Be(e,t){if(e==null)return null;let n=ze[e]?.[t];if(n!=null)return{rule:n,kind:`runtime`};let r=Le[e]?.[t];return r==null?null:{rule:r,kind:`typings`}}function Ve(e,t,n){let r=Be(e,t);if(r==null)return!0;let{rule:i}=r;return i.allow==null?!(i.deny??[]).some(e=>e===n):i.allow.some(e=>e===n)}function He(e,t,n){if(e==null)return!0;let r=Re[e]?.[t];return r==null||!r.some(e=>e===n)}function Ue(e,t){let n=Be(e,t);if(n==null)return null;let{rule:r,kind:i}=n,a=r.allow==null?(Ie[t]??[]).filter(n=>Ve(e,t,n)):r.allow.map(String),o=[];return o.push(i===`runtime`?`运行时实测不接受(平台类型虽然声明支持)`:`本平台类型不支持`),a.length>0&&o.push(`实测/类型支持 ${a.join(` / `)}`),o.join(`;`)}var We=[`string`,`boolean`,`variableAlias`],Ge={jsdesign:{setProperties:{deny:[`boolean`,`variableAlias`]}},mastergo:{setProperties:{deny:[`variableAlias`]}}};function Ke(e,t){if(e==null)return null;let n=Ge[e]?.[t]?.deny??[];return We.filter(e=>!n.some(t=>t===e))}var qe=[`UNION`,`SUBTRACT`,`INTERSECT`,`EXCLUDE`],Je={UNION:`合并`,SUBTRACT:`减去`,INTERSECT:`相交`,EXCLUDE:`排除`},Ye=qe.join(`/`),Xe=`布尔运算:${qe.map(e=>`${e}=${Je[e]}`).join(`,`)}`;function Ze(e){let t=/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(e.trim());if(t==null)return null;let n=t[1];(n.length===3||n.length===4)&&(n=[...n].map(e=>e+e).join(``));let r=e=>Number.parseInt(e,16)/255,i={r:r(n.slice(0,2)),g:r(n.slice(2,4)),b:r(n.slice(4,6))};return n.length===8&&(i.a=r(n.slice(6,8))),i}var Qe=h.object({r:h.number().min(0).max(255,`颜色通道最大 255`).describe(`schema.base.r`),g:h.number().min(0).max(255,`颜色通道最大 255`).describe(`schema.base.g`),b:h.number().min(0).max(255,`颜色通道最大 255`).describe(`schema.base.b`),a:h.number().min(0).max(255,`alpha 通道最大 255`).optional().describe(`schema.base.a`)}).strict(),$e=`颜色需为 {r,g,b[,a]} 对象(通道 0-1;任一路 >1 视为 0-255,自动整组 /255)或 hex 字符串(#RGB/#RGBA/#RRGGBB/#RRGGBBAA,如 "#ff0000")`,et=h.unknown().superRefine((e,t)=>{if(typeof e==`string`){Ze(e)??t.addIssue({code:h.ZodIssueCode.custom,message:`无效 hex 颜色 "${e}"(${$e})`});return}let n=Qe.safeParse(e);if(!n.success)for(let e of n.error.issues)t.addIssue({code:h.ZodIssueCode.custom,path:e.path,message:e.message})}),tt=et.describe(`颜色:{r,g,b} 对象(通道 0-1,>1 视为 0-255 自动归一化)或 hex 字符串,如 "#ff0000"(带透明度可用 8 位 hex,其 alpha 会转为 paint 级 opacity)`),nt=et.describe(`RGBA 颜色:{r,g,b,a} 对象(通道 0-1,>1 视为 0-255 自动归一化;a 缺省按 1)或 hex 字符串,如 "#ff0000"、"#ff000080"`),rt=h.object({color:nt.describe(`schema.base.color`),position:h.number().min(0).max(1).describe(`schema.base.position`)}).describe(`渐变停止点,如 {color:{r:1,g:0,b:0,a:1}, position:0}(起点红色)和 {color:{r:0,g:0,b:1,a:1}, position:1}(终点蓝色)`),it=h.array(h.array(h.number()).length(3)).length(2).describe(`schema.base.transformSchema`),at=h.enum(je).describe(`混合模式:PASS_THROUGH=穿透 | NORMAL=正常 | DARKEN=变暗 | MULTIPLY=正片叠底 | COLOR_BURN=颜色加深 | LIGHTEN=变亮 | SCREEN=滤色 | COLOR_DODGE=颜色减淡 | OVERLAY=叠加 | SOFT_LIGHT=柔光 | HARD_LIGHT=强光 | DIFFERENCE=差值 | EXCLUSION=排除 | HUE=色相 | SATURATION=饱和度 | COLOR=颜色 | LUMINOSITY=明度`),ot=h.discriminatedUnion(`type`,[h.object({type:h.literal(`SOLID`).describe(`schema.base.type`),color:tt.describe(`纯色值,支持 {r,g,b} 对象(通道 0-1)或 hex 字符串,如 "#ff0000"`),opacity:h.number().min(0).max(1).optional().describe(`schema.base.opacity`),visible:h.boolean().optional().describe(`schema.base.visible`),blendMode:at.optional().describe(`schema.base.blendMode`)}).strict().describe(`schema.base.blendMode2`),h.object({type:h.literal(`GRADIENT_LINEAR`).describe(`schema.base.type2`),gradientStops:h.array(rt).describe(`schema.base.gradientStops`),gradientTransform:it}).strict().describe(`schema.base.gradientTransform`),h.object({type:h.literal(`GRADIENT_RADIAL`).describe(`schema.base.type3`),gradientStops:h.array(rt).describe(`schema.base.gradientStops2`),gradientTransform:it}).strict().describe(`schema.base.gradientTransform2`),h.object({type:h.literal(`GRADIENT_ANGULAR`).describe(`schema.base.type4`),gradientStops:h.array(rt).describe(`schema.base.gradientStops3`),gradientTransform:it}).strict().describe(`schema.base.gradientTransform3`),h.object({type:h.literal(`IMAGE`).describe(`schema.base.type5`),imageHash:h.string().describe(`schema.base.imageHash`),scaleMode:h.enum([`FILL`,`FIT`,`CROP`,`TILE`]).optional().describe(`schema.base.scaleMode`)}).strict().describe(`schema.base.scaleMode2`)]),st=h.discriminatedUnion(`type`,[h.object({type:h.literal(`DROP_SHADOW`).describe(`schema.base.type6`),color:nt.describe(`schema.base.color2`),offset:h.object({x:h.number().describe(`schema.base.x`),y:h.number().describe(`schema.base.y`)}).describe(`schema.base.y2`),radius:h.number().min(0).describe(`schema.base.radius`),spread:h.number().optional().describe(`schema.base.spread`),visible:h.boolean().optional().describe(`schema.base.visible2`),blendMode:at.default(`NORMAL`).describe(`schema.base.blendMode3`),showShadowBehindNode:h.boolean().optional().describe(`schema.base.showShadowBehindNode`)}).strict().describe(`schema.base.showShadowBehindNode2`),h.object({type:h.literal(`INNER_SHADOW`).describe(`schema.base.type7`),color:nt.describe(`schema.base.color3`),offset:h.object({x:h.number().describe(`schema.base.x2`),y:h.number().describe(`schema.base.y3`)}).describe(`schema.base.y4`),radius:h.number().min(0).describe(`schema.base.radius2`),spread:h.number().optional().describe(`schema.base.spread2`),visible:h.boolean().optional().describe(`schema.base.visible3`),blendMode:at.default(`NORMAL`).describe(`schema.base.blendMode4`)}).strict().describe(`schema.base.blendMode5`),h.object({type:h.literal(`LAYER_BLUR`).describe(`schema.base.type8`),radius:h.number().min(0).describe(`schema.base.radius3`),visible:h.boolean().optional().describe(`schema.base.visible4`)}).strict().describe(`schema.base.visible5`),h.object({type:h.literal(`BACKGROUND_BLUR`).describe(`schema.base.type9`),radius:h.number().min(0).describe(`schema.base.radius4`),visible:h.boolean().optional().describe(`schema.base.visible6`)}).strict().describe(`schema.base.visible7`)]),ct=h.enum([`MIN`,`MAX`,`STRETCH`,`CENTER`,`SCALE`]).describe(`约束类型:MIN=吸附左/上 | MAX=吸附右/下 | STRETCH=拉伸 | CENTER=居中 | SCALE=等比缩放`),lt=h.object({pattern:h.enum([`ROWS`,`COLUMNS`,`GRID`]).describe(`schema.base.pattern`),alignment:h.enum([`MIN`,`MAX`,`CENTER`,`STRETCH`]).optional().describe(`schema.base.alignment`),sectionSize:h.number().optional().describe(`schema.base.sectionSize`),count:h.number().int().positive().optional(),gutterSize:h.number().optional().describe(`schema.base.gutterSize`),offset:h.number().optional().describe(`schema.base.offset`),visible:h.boolean().optional(),color:nt.optional()}).superRefine((e,t)=>{if(e.pattern===`GRID`&&e.sectionSize==null&&t.addIssue({code:h.ZodIssueCode.custom,message:`pattern 为 GRID 时,sectionSize 为必填项`,path:[`sectionSize`]}),e.pattern===`ROWS`||e.pattern===`COLUMNS`)for(let n of[`count`,`gutterSize`])e[n]??t.addIssue({code:h.ZodIssueCode.custom,message:`pattern 为 ${e.pattern} 时,${n} 为必填项(三平台的 RowsColsLayoutGrid 都把它列为必填)`,path:[n]})}),ut=h.object({data:h.string().describe(`SVG path data,如 "M0 0 L100 0 L100 100 Z"(M=移动到,L=画线到,Z=闭合)。仅支持 M/L/Q/C/Z 指令(SVG 子集,不支持 A 圆弧等);完整 SVG 请改用 jsd_create_svg`),windingRule:h.enum([`NONZERO`,`EVENODD`,`NONE`]).default(`NONZERO`).describe(`schema.base.windingRule`)}),dt=h.object({family:h.string().describe(`字体族:用 jsd_list_fonts 的 fonts[].family 原样值,如 "SourceHanSansCN_family"(带 _family 后缀是平台列表的原始名)`),style:h.string().describe(`字型:必须是同一 family 的 fonts[].styles 里的**全名**,如 "SourceHanSansCN-Bold"(不是简称 "Bold")。写错不会报错,会静默退回默认字面(命中时结果 warnings 点名)`)}),ft=h.union([h.object({value:h.number().describe(`schema.base.value`),unit:h.literal(`PIXELS`).describe(`schema.base.unit`)}).describe(`固定行高:{value: 数值, unit: "PIXELS"},如 {value: 24, unit: "PIXELS"}`),h.object({value:h.number().describe(`schema.base.value2`),unit:h.literal(`PERCENT`).describe(`schema.base.unit2`)}).describe(`百分比行高:{value: 数值, unit: "PERCENT"},如 {value: 150, unit: "PERCENT"}`),h.object({unit:h.literal(`AUTO`).describe(`schema.base.unit3`)}).describe(`schema.base.unit4`)]),pt=h.object({value:h.number(),unit:h.enum([`PIXELS`,`PERCENT`]).describe(`schema.base.unit5`)}),mt=h.object({id:h.string().optional().describe(`步骤唯一标识,供后续步骤以双花括号占位符(id.字段路径)引用本步结果;缺省自动命名 step1/step2/…`),tool:h.string().describe(`要执行的 jsd_* 工具名,如 jsd_create_rectangle / jsd_find / jsd_set_fill_color`),args:h.record(h.string(),h.unknown()).optional().describe(`该工具的完整入参;任意位置的字符串值里可放双花括号占位符。两种来源:引用先前步骤结果(步骤id.字段路径),或按名字取文档里已有的资源 —— {{@comp:名称}} 给组件/变体集 id、{{@var:名称}} 给变量 id(读一次 jsd_get_page 的资源清单,同名多命中或零命中会点名中止整批)。注意:jsd_create_* 是单类型工具,节点类型已固化在工具名里(jsd_create_frame=FRAME),args 不必再传 type`),continueOnError:h.boolean().optional().describe(`本步【执行】失败时是否继续后续步骤;仅对执行失败生效,id 重复/未知工具/引用解析失败一律中止`)}),ht=h.object({calls:h.array(mt).max(50).optional().describe(`schema.batch.calls`),callsFile:h.string().optional().describe(`schema.batch.callsFile`),stopOnError:h.boolean().optional().describe(`全局失败策略,默认 true=任一步执行失败即停止,false=配合单步走完全部`),checkDrift:h.boolean().optional().describe(`是否对结构变更步骤做同层几何漂移复核,默认 true。步骤里含 remove/reparent/group/ungroup/flatten/repair 时:变更前记下受影响父层的子节点坐标,该步结束后再读一次比对,漂移写进结果 warnings(引擎会把没碰到的兄弟静默挪走)。代价是每步多两次读数;确定不需要时传 false`)}),gt=h.object({ok:h.boolean().describe(`schema.batch.ok`),executed:h.number().int().min(0).describe(`schema.batch.executed`),total:h.number().int().min(0).describe(`schema.batch.total`),results:h.array(h.object({id:h.string(),tool:h.string(),ok:h.boolean(),data:h.unknown().optional().describe(`成功时该工具的 structuredContent(已做回显摘要裁剪,见工具描述)`),error:h.string().optional().describe(`schema.batch.error`)})).describe(`schema.batch.error2`),echoTrimmed:h.boolean().optional(),echoNote:h.string().optional(),warnings:h.array(h.string()).optional()}),_t=h.record(h.string(),h.unknown()),vt=[`SLICE`,`FRAME`,`GROUP`,`COMPONENT_SET`,`COMPONENT`,`INSTANCE`,`BOOLEAN_OPERATION`,`VECTOR`,`STAR`,`LINE`,`ELLIPSE`,`POLYGON`,`RECTANGLE`,`TEXT`],yt={SLICE:`切片`,FRAME:`容器`,GROUP:`分组`,COMPONENT_SET:`组件集`,COMPONENT:`组件`,INSTANCE:`实例`,BOOLEAN_OPERATION:`布尔运算`,VECTOR:`矢量`,STAR:`星形`,LINE:`线段`,ELLIPSE:`椭圆`,POLYGON:`多边形`,RECTANGLE:`矩形`,TEXT:`文本`},bt=`节点类型:${vt.map(e=>`${e}=${yt[e]}`).join(` | `)}`,xt=[`TEXT_PATH`,`TRANSFORM_GROUP`,`STICKY`,`CONNECTOR`,`SHAPE_WITH_TEXT`,`CODE_BLOCK`,`STAMP`,`WIDGET`,`EMBED`,`LINK_UNFURL`,`MEDIA`,`SECTION`,`HIGHLIGHT`,`WASHI_TAPE`,`TABLE`,`SLIDE`,`SLIDE_ROW`,`SLIDE_GRID`,`SLOT`,`INTERACTIVE_SLIDE_ELEMENT`],St=[`INTELLIGENT_CONTAINER`],Ct=[...vt,...xt,...St],wt=h.enum(vt).describe(bt),Tt=h.enum(Ct).describe(`${bt};另有 Figma 独有只读类型(TEXT_PATH/STICKY/SECTION/TABLE/SLIDE 等 20 类)可能出现在读结果里,本仓不支持创建与修改它们`),Et=h.object({type:wt.describe(`schema.executeSchemas.type`),name:h.string().optional(),x:h.number().optional().describe(`schema.executeSchemas.x`),y:h.number().optional().describe(`schema.executeSchemas.y`),width:h.number().optional(),height:h.number().optional()}).catchall(h.unknown()),y={name:h.string().optional(),x:h.number().optional().describe(`schema.executeSchemas.x2`),y:h.number().optional().describe(`schema.executeSchemas.y2`),width:h.number().optional().describe(`schema.executeSchemas.width`),height:h.number().optional().describe(`schema.executeSchemas.height`),rotation:h.number().optional().describe(`schema.executeSchemas.rotation`),opacity:h.number().optional().describe(`schema.executeSchemas.opacity`),visible:h.boolean().optional(),locked:h.boolean().optional(),isMask:h.boolean().optional(),children:h.array(Et).max(100).optional().describe(`子节点数组(递归嵌套,最多 100 个直接子节点;更大的结构建议分批创建后用 jsd_manage_nodes op=reparent 归组)。子节点可使用的字段与顶层 create 入参一致(fills/strokes/cornerRadius/effects 等均可用);x/y 相对父节点,未传 x/y 会叠放在父节点原点(0,0)——非 auto-layout 容器需为每个子节点指定相对坐标`)},b={fills:h.array(ot).optional().describe(`填充列表(Paint 数组)。缺省时的引擎默认:FRAME 为白底;非 FRAME 图形若同时传了 strokes,则填充置空(纯描边,不再被引擎塞 #CCCCCC 灰底)——需要底色请显式传 fills`),strokes:h.array(ot).optional().describe(`schema.executeSchemas.strokes`),strokeWeight:h.number().optional().describe(`schema.executeSchemas.strokeWeight`),strokeTopWeight:h.number().optional().describe(`schema.executeSchemas.strokeTopWeight`),strokeBottomWeight:h.number().optional().describe(`schema.executeSchemas.strokeBottomWeight`),strokeLeftWeight:h.number().optional().describe(`schema.executeSchemas.strokeLeftWeight`),strokeRightWeight:h.number().optional().describe(`schema.executeSchemas.strokeRightWeight`),strokeAlign:h.enum([`CENTER`,`INSIDE`,`OUTSIDE`]).optional().describe(`schema.executeSchemas.strokeAlign`),strokeCap:h.enum([`NONE`,`ROUND`,`SQUARE`,`ARROW_LINES`,`ARROW_EQUILATERAL`]).optional().describe(`schema.executeSchemas.strokeCap`),strokeJoin:h.enum([`MITER`,`BEVEL`,`ROUND`]).optional().describe(`schema.executeSchemas.strokeJoin`),dashPattern:h.array(h.number()).optional().describe(`schema.executeSchemas.dashPattern`),blendMode:at.optional(),effects:h.array(st).optional().describe(`schema.executeSchemas.effects`),constraints:h.object({horizontal:ct.describe(`水平约束:MIN|MAX|STRETCH|CENTER|SCALE`),vertical:ct.describe(`垂直约束:MIN|MAX|STRETCH|CENTER|SCALE`)}).optional().describe(`schema.executeSchemas.vertical`),clipsContent:h.boolean().optional().describe(`schema.executeSchemas.clipsContent`),cornerSmoothing:h.number().optional().describe(`schema.executeSchemas.cornerSmoothing`),layoutGrids:h.array(lt).optional().describe(`schema.executeSchemas.layoutGrids`),fillStyleId:h.string().optional().describe(`schema.sharedProps.fillStyleId`),strokeStyleId:h.string().optional().describe(`schema.sharedProps.strokeStyleId`),textStyleId:h.string().optional().describe(`schema.sharedProps.textStyleId`),effectStyleId:h.string().optional().describe(`schema.sharedProps.effectStyleId`)},Dt={cornerRadius:h.number().optional().describe(`schema.executeSchemas.cornerRadius`),topLeftRadius:h.number().optional().describe(`schema.executeSchemas.topLeftRadius`),topRightRadius:h.number().optional().describe(`schema.executeSchemas.topRightRadius`),bottomLeftRadius:h.number().optional().describe(`schema.executeSchemas.bottomLeftRadius`),bottomRightRadius:h.number().optional().describe(`schema.executeSchemas.bottomRightRadius`)},Ot=h.object({type:h.literal(`FRAME`),...y,layoutMode:h.enum([`NONE`,`HORIZONTAL`,`VERTICAL`]).optional().describe(`自动布局方向:NONE=无布局,HORIZONTAL=水平排列,VERTICAL=垂直排列。传 itemSpacing/padding*/primaryAxis* 等布局属性前必须先设为 HORIZONTAL 或 VERTICAL`),itemSpacing:h.number().optional().describe(`自动布局项间距(px),需先设 layoutMode;primaryAxisAlignItems=SPACE_BETWEEN 时该项被忽略(子项均匀分布)`),paddingTop:h.number().optional().describe(`schema.executeSchemas.paddingTop`),paddingRight:h.number().optional().describe(`schema.executeSchemas.paddingRight`),paddingBottom:h.number().optional().describe(`schema.executeSchemas.paddingBottom`),paddingLeft:h.number().optional().describe(`schema.executeSchemas.paddingLeft`),primaryAxisSizingMode:h.enum([`FIXED`,`AUTO`]).optional().describe(`schema.executeSchemas.primaryAxisSizingMode`),counterAxisSizingMode:h.enum([`FIXED`,`AUTO`]).optional().describe(`schema.executeSchemas.counterAxisSizingMode`),primaryAxisAlignItems:h.enum([`MIN`,`MAX`,`CENTER`,`SPACE_BETWEEN`]).optional().describe(`主轴对齐:MIN|MAX|CENTER|SPACE_BETWEEN;设为 SPACE_BETWEEN 时 itemSpacing 被忽略(子项均匀分布)`),counterAxisAlignItems:h.enum([`MIN`,`MAX`,`CENTER`]).optional().describe(`schema.executeSchemas.counterAxisAlignItems`),layoutGrow:h.number().optional().describe(`schema.executeSchemas.layoutGrow`),layoutAlign:h.enum([`MIN`,`CENTER`,`MAX`,`STRETCH`,`INHERIT`]).optional().describe(`schema.executeSchemas.layoutAlign`),...Dt,...b}).strict().superRefine((e,t)=>{(e.itemSpacing!=null||e.paddingTop!=null||e.paddingRight!=null||e.paddingBottom!=null||e.paddingLeft!=null||e.primaryAxisSizingMode!=null||e.counterAxisSizingMode!=null||e.primaryAxisAlignItems!=null||e.counterAxisAlignItems!=null)&&(e.layoutMode==null||e.layoutMode===`NONE`)&&t.addIssue({code:h.ZodIssueCode.custom,message:`传 itemSpacing/padding*/primaryAxis*/counterAxis* 等布局属性前,layoutMode 必须设为 HORIZONTAL 或 VERTICAL`,path:[`layoutMode`]})}).strict().describe(`FRAME=容器(可 auto-layout)。注意:未显式传 fills 时引擎默认白底,透明容器请显式传 fills:[{type:"SOLID",color:{r:0,g:0,b:0},opacity:0}]`),kt=h.object({type:h.literal(`RECTANGLE`),...y,...Dt,...b}).strict().describe(`schema.executeSchemas.type2`),At=h.object({type:h.literal(`ELLIPSE`),...y,cornerRadius:h.number().optional().describe(`schema.executeSchemas.cornerRadius2`),arcData:h.object({startingAngle:h.number().describe(`schema.executeSchemas.startingAngle`),endingAngle:h.number().describe(`schema.executeSchemas.endingAngle`),innerRadius:h.number().describe(`schema.executeSchemas.innerRadius`)}).optional().describe(`schema.executeSchemas.innerRadius2`),...b}).strict().describe(`schema.executeSchemas.innerRadius3`),jt=h.object({type:h.literal(`LINE`),...y,...b}).strict().describe(`schema.executeSchemas.type3`),Mt=h.object({type:h.literal(`POLYGON`),...y,pointCount:h.number().describe(`schema.executeSchemas.pointCount`),cornerRadius:h.number().optional().describe(`schema.executeSchemas.cornerRadius3`),topLeftRadius:h.number().optional().describe(`schema.executeSchemas.topLeftRadius2`),topRightRadius:h.number().optional().describe(`schema.executeSchemas.topRightRadius2`),bottomLeftRadius:h.number().optional().describe(`schema.executeSchemas.bottomLeftRadius2`),bottomRightRadius:h.number().optional().describe(`schema.executeSchemas.bottomRightRadius2`),...b}).strict().describe(`schema.executeSchemas.bottomRightRadius3`),Nt=h.object({type:h.literal(`STAR`),...y,pointCount:h.number().describe(`schema.executeSchemas.pointCount2`),innerRadius:h.number().describe(`schema.executeSchemas.innerRadius4`),cornerRadius:h.number().optional().describe(`schema.executeSchemas.cornerRadius4`),topLeftRadius:h.number().optional().describe(`schema.executeSchemas.topLeftRadius3`),topRightRadius:h.number().optional().describe(`schema.executeSchemas.topRightRadius3`),bottomLeftRadius:h.number().optional().describe(`schema.executeSchemas.bottomLeftRadius3`),bottomRightRadius:h.number().optional().describe(`schema.executeSchemas.bottomRightRadius4`),...b}).strict().describe(`schema.executeSchemas.bottomRightRadius5`),Pt=h.object({type:h.literal(`VECTOR`),...y,vectorPaths:h.array(ut).describe(`schema.executeSchemas.vectorPaths`),...b}).strict().describe(`VECTOR=矢量(配合 vectorPaths 传 SVG path data)。注意:当前平台创建后 vectorPaths 偶发丢失/形变,短直线段建议改用 LINE+rotation 更稳定`),Ft=h.object({type:h.literal(`TEXT`),...y,characters:h.string().describe(`文本内容,如 "Hello World"。注意:个别 emoji 依赖客户端字体可能缺字(渲染为 ☒),上线前逐个目检`),fontSize:h.number().optional().describe(`schema.executeSchemas.fontSize`),fontName:dt.optional().describe(`字体:{family,style},如 {family:"PingFang SC",style:"Regular"};需精确匹配,建议先用 jsd_list_fonts 查可用字体(不可用时静默回退默认字体)`),textAlignHorizontal:h.enum([`LEFT`,`CENTER`,`RIGHT`,`JUSTIFIED`]).optional().describe(`schema.executeSchemas.textAlignHorizontal`),textAlignVertical:h.enum([`TOP`,`CENTER`,`BOTTOM`]).optional().describe(`schema.executeSchemas.textAlignVertical`),textAutoResize:h.enum([`NONE`,`WIDTH_AND_HEIGHT`,`HEIGHT`,`TRUNCATE`]).optional().describe(`文本自适应:NONE=固定尺寸|WIDTH_AND_HEIGHT=按内容撑开(缺省,此时显式 width/height 会被覆盖)|HEIGHT=固定宽自适应高|TRUNCATE=截断。要固定文本框尺寸必须设为 NONE`),textCase:h.enum([`ORIGINAL`,`UPPER`,`LOWER`,`TITLE`]).optional().describe(`schema.executeSchemas.textCase`),textDecoration:h.enum([`NONE`,`UNDERLINE`,`STRIKETHROUGH`]).optional().describe(`schema.executeSchemas.textDecoration`),lineHeight:ft.optional().describe(`schema.executeSchemas.lineHeight`),letterSpacing:pt.optional().describe(`schema.executeSchemas.letterSpacing`),...b}).strict().describe(`schema.executeSchemas.letterSpacing2`),It=h.object({type:h.literal(`GROUP`),...y,children:h.array(Et).min(2).max(100).describe(`schema.executeSchemas.children`),layoutMode:h.enum([`NONE`,`HORIZONTAL`,`VERTICAL`]).optional().describe(`自动布局方向:NONE=纯归组,HORIZONTAL=水平,VERTICAL=垂直。传 itemSpacing/padding* 等布局属性前必须先设为 HORIZONTAL 或 VERTICAL`),itemSpacing:h.number().optional().describe(`项间距(px),需先设 layoutMode;primaryAxisAlignItems=SPACE_BETWEEN 时该项被忽略(子项均匀分布)`),paddingTop:h.number().optional().describe(`schema.executeSchemas.paddingTop2`),paddingRight:h.number().optional().describe(`schema.executeSchemas.paddingRight2`),paddingBottom:h.number().optional().describe(`schema.executeSchemas.paddingBottom2`),paddingLeft:h.number().optional().describe(`schema.executeSchemas.paddingLeft2`),primaryAxisSizingMode:h.enum([`FIXED`,`AUTO`]).optional().describe(`schema.executeSchemas.primaryAxisSizingMode2`),counterAxisSizingMode:h.enum([`FIXED`,`AUTO`]).optional().describe(`schema.executeSchemas.counterAxisSizingMode2`),primaryAxisAlignItems:h.enum([`MIN`,`MAX`,`CENTER`,`SPACE_BETWEEN`]).optional().describe(`主轴对齐:MIN|MAX|CENTER|SPACE_BETWEEN;设为 SPACE_BETWEEN 时 itemSpacing 被忽略(子项均匀分布)`),counterAxisAlignItems:h.enum([`MIN`,`MAX`,`CENTER`]).optional().describe(`schema.executeSchemas.counterAxisAlignItems2`),...b}).strict().superRefine((e,t)=>{(e.itemSpacing!=null||e.paddingTop!=null||e.paddingRight!=null||e.paddingBottom!=null||e.paddingLeft!=null||e.primaryAxisSizingMode!=null||e.counterAxisSizingMode!=null||e.primaryAxisAlignItems!=null||e.counterAxisAlignItems!=null)&&(e.layoutMode==null||e.layoutMode===`NONE`)&&t.addIssue({code:h.ZodIssueCode.custom,message:`传 itemSpacing/padding*/primaryAxis*/counterAxis* 等布局属性前,layoutMode 必须设为 HORIZONTAL 或 VERTICAL`,path:[`layoutMode`]})}).describe(`schema.executeSchemas.path`),Lt=h.object({type:h.literal(`BOOLEAN_OPERATION`),...y,booleanOperation:h.enum(qe).describe(Xe),children:h.array(Et).min(2).describe(`schema.executeSchemas.children2`),...b}).strict().describe(`schema.executeSchemas.children3`),Rt=h.discriminatedUnion(`type`,[Ot,kt,At,jt,Mt,Nt,Pt,Ft,It,Lt]),zt=h.object({mode:h.enum([`center`,`manual`,`absolute`]).optional().describe(`放置模式:center=把每个根节点各自移到视口中心(缺省;会忽略 ops 内根节点自身的 x/y,多个根节点会互相叠放)|manual=保留 ops 内根节点自身的 x/y(按坐标布局用这个)|absolute=把所有根节点统一放到下方 x/y(必填,多根会叠在同一坐标)。建议一次调用只建一个根节点,层级结构用 children 表达`),x:h.number().optional().describe(`absolute 模式下所有根节点的 X 坐标,与 mode="absolute" 配合使用`),y:h.number().optional().describe(`absolute 模式下所有根节点的 Y 坐标,与 mode="absolute" 配合使用`)}).superRefine((e,t)=>{e.mode===`absolute`&&(e.x==null||e.y==null)&&t.addIssue({code:h.ZodIssueCode.custom,message:`placement.mode 为 absolute 时,x 和 y 均为必填项`,path:e.x==null?[`x`]:[`y`]})});h.object({ops:h.array(Rt).describe(`设计指令节点树;建议单一根节点(多个根节点会被 placement 统一摆放,可能互相叠放)`),placement:zt.optional().describe(`放置方式,缺省 center 居中且忽略 ops 内根节点的 x/y。需要按坐标摆放时传 mode:"manual"(保留 ops 内 x/y)或 "absolute"(顶层统一坐标)`)}).strict(),h.object({svg:h.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>`),name:h.string().optional().describe(`schema.execute.name`)});var Bt=h.object({svg:h.string().optional().describe(`完整 SVG 字符串(与 svgPath 二选一)`),svgPath:h.string().optional().describe(`本地 .svg 文件路径,由后台服务读取(与 svg 二选一)。**代码生成的大 SVG 走这条**`),name:h.string().optional().describe(`schema.execute.name`)}).strict().superRefine((e,t)=>{let n=e=>typeof e==`string`&&e.trim()!==``;n(e.svg)===n(e.svgPath)&&t.addIssue({code:h.ZodIssueCode.custom,message:n(e.svg)?`svg 与 svgPath 只能传一个:svgPath 是给「SVG 已在本地文件里」用的`:`必须传 svg(内联 SVG 字符串)或 svgPath(本地 .svg 文件路径),二选一`,path:[`svg`]})}),Vt=h.object({html:h.string().describe(`schema.execute.html`),name:h.string().optional().describe(`schema.execute.name2`)}),Ht=h.object({icon:h.string().describe(`图标名/别名/语义描述,如 home、arrow-right、search、magnifier(搜索);支持模糊匹配与别名联想,查无返回候选提示`),size:h.number().optional().describe(`schema.execute.size`),color:h.string().optional().describe(`schema.execute.color`),strokeWidth:h.number().optional().describe(`schema.execute.strokeWidth`),name:h.string().optional().describe(`schema.execute.name3`)});h.object({});var Ut=h.object({depth:h.number().optional().describe(`schema.executeOp.depth`)}),Wt=[`page`,`document`],Gt={"platform.jsdesign":`即时设计`,"platform.figma":`Figma`,"platform.mastergo":`MasterGo`,"capability.core.create":`创建`,"capability.core.modify":`修改`,"capability.core.structure":`结构操作`,"capability.core.component":`组件`,"capability.core.export":`导出`,"capability.core.image":`图片填充`,"capability.host.styles":`本地样式`,"capability.host.styleEnumeration":`本地样式清单(能列出有哪些样式)`,"capability.host.styleEnumerationSync":`样式枚举走同步入口(运行时的 *Async 成员不可用)`,"capability.host.mainComponentSync":`主组件走同步字段(运行时的 getMainComponentAsync 永不返回)`,"capability.host.textTruncation":`文本截断`,"capability.host.componentProperties":`组件属性`,"capability.host.documentScopeRead":`文档范围读(能读非当前页)`,"capability.host.variables":`变量`,"capability.host.inPlaceVariants":`原位合并变体`,"locale.system":`跟随系统`,"locale.zh-CN":`中文`,"locale.en":`English`,"locale.abbr.zh-CN":`中`,"locale.abbr.en":`EN`,"locale.menu":`界面语言`,"locale.title.followSystem":`界面语言:跟随系统(当前 {locale})`,"locale.title.fixed":`界面语言:{locale}`,"status.connected.label":`已连接`,"status.connected.title":`服务在线,插件与 AI 会话已连通`,"status.connecting.label":`连接中…`,"status.connecting.title":`已连上后台服务,等待它确认这条通道`,"status.waiting.label":`等待服务`,"status.waiting.title":`服务离线时无需手动操作,AI 调用会自动拉起`,"status.superseded.label":`已被接管`,"status.superseded.title":`另一个插件面板占用了通道;点「夺回」可切回本面板`,"header.retry":`重试`,"header.retry.title":`立即重连后台服务,不必等自动重连的退避间隔`,"header.reclaim":`夺回`,"header.reclaim.title":`夺回被另一个插件面板占用的通道`,"header.theme.toDark":`切换到暗色主题`,"header.theme.toLight":`切换到亮色主题`,"header.cameraLock.locked":`相机已锁定`,"header.cameraLock.unlocked":`相机跟随`,"header.cameraLock.title.locked":`相机已锁定:操作画布时不移动你的视口(点击改为跟随)`,"header.cameraLock.title.unlocked":`相机跟随:操作画布后视口滚动缩放到结果(点击锁定)`,"header.minimize":`最小化`,"header.minimize.title":`最小化面板,只留 logo;双击 logo 恢复`,"header.restore.title":`双击 logo 恢复面板`,"upgrade.title":`有新版本可用(点击查看升级步骤)`,"upgrade.modal.title":`升级到最新版本`,"upgrade.current":`当前 {version}`,"upgrade.latest":`最新 {version}`,"upgrade.plugin.label":`插件`,"upgrade.service.label":`后台服务`,"upgrade.step.service":`① 后台服务,重启 AI 会话就行。它跑的是 npx -y text-to-design-mcp@latest,每次都是最新的`,"upgrade.step.plugin.head":`② 插件要手动换。下载`,"upgrade.step.plugin.tail":`最新版解压,在设计软件里导入对应平台的 manifest`,"upgrade.step.verify":`③ 重新运行插件,顶部的升级图标没了就是对齐了`,"upgrade.copy":`复制给 AI 助手`,"upgrade.prompt":`我在用 text-to-design,插件 text-to-design-ui 当前 {ui}、最新 {uiLatest},后台服务 text-to-design-mcp 当前 {mcp}、最新 {mcpLatest}。帮我升到最新:① 确认 MCP 配置里的命令带 latest,然后重启 AI 会话;② 下载 text-to-design-ui 最新版(npm pack 或 GitHub Releases 的 zip)解压,告诉我即时设计 / Figma / MasterGo 分别该导入 dist 下哪份 manifest.json;③ 完成后回报两个版本号。`,"toast.copy.done":`已复制`,"toast.copy.failed":`复制失败`,"conn.connected":`已连接。选中画布节点后点「复制」,把内容发给 AI 助手——例如:「按这个节点样式帮我再做一张卡片」`,"conn.superseded":`通道已被另一个插件面板接管(同一时刻只服务一个面板),自动重连已停止。点顶部状态徽章旁的「夺回」切回本面板。`,"conn.disconnected.title":`尚未连接后台服务`,"conn.disconnected.tutorial":`安装教程`,"conn.copyAi":`① 复制给 AI 助手`,"conn.copyDaemon":`② 复制启动命令`,"conn.copyAi.hint":`发给 AI,让它调用 jsd_ping 唤醒后台服务`,"conn.daemon.note":`在本机终端执行即常驻到下次重启;重复执行安全(已有实例会自动跳过)。`,"conn.announce.connected":`已连接后台服务`,"conn.announce.connecting":`正在连接后台服务`,"conn.announce.superseded":`通道已被另一个插件面板接管`,"conn.announce.disconnected":`尚未连接后台服务`,"conn.wakeCmd":`请帮我连接 text-to-design 后台服务:
|
|
3
3
|
|
|
4
4
|
1. 若尚未注册 MCP 服务:用你工具原生的方式注册一个 stdio MCP server,
|
|
5
5
|
命令 npx -y text-to-design-mcp@latest(无需手动安装,npx 会自动拉取运行)。
|
|
@@ -16,7 +16,7 @@ import{createRequire as e}from"node:module";import{appendFileSync as t,mkdirSync
|
|
|
16
16
|
- 结果 warnings 一律读:它点名的都是「回显成功但没生效」的事实(平台能力门控字段被忽略、字段回读与请求不一致如 root x/y 被 placement 覆盖 / TEXT 的 textAutoResize 未声明却被置 NONE、fontName 组合不存在被静默忽略、结构变更后的同层漂移),不要当成普通提示跳过。字体写法:family 用 jsd_list_fonts 的 fonts[].family 原样、style 用同一项的**全名**(如 SourceHanSansCN-Bold,不是简称 "Bold")。
|
|
17
17
|
- ok=false 或「没找到 X 节点」:先 jsd_find 复核 id 是否已失效(可能被连坐删除),必要时 jsd_repair_nodes 清理后重试。
|
|
18
18
|
- 产出含 ≥2 个结构一致的同级单元时:先提 COMPONENT 再用 INSTANCE 铺开;命名走「组件族/状态」。
|
|
19
|
-
- 多步套路先读配方 prompt(prompts/list 里,名字无 jsd_ 前缀;取一条即把完整流程与产出标准注入上下文),别临场拼工具:画图表 / 数据可视化 → chart-by-code(折线、柱状、饼图 / 环形、散点、雷达、面积、仪表盘;自己写脚本算几何、落盘 SVG,再经 jsd_create_svg 的 svgPath 导入);HTML 转设计稿 → html-to-design;界面从零设计 → design-strategy;界面排布 / 自动布局(容器该不该上布局、两条落地路径、最易漏的分区)→ auto-layout;批量改文案 → text-replace-strategy;图标网格 → icon-grid;多步画布操作合并成一次调用 → script-ops;同类实例批量同步样式 → variant-sync;变体集构建 → variant-set;变量绑定与批量套用 → variable-binding;组件属性的定义与设值 → component-property。同一批配方也作为 MCP 资源提供:宿主若不注入本段(实测多数客户端如此),以资源为准 —— 读 jsd://recipes 取索引(含每条的何时用),读 jsd://recipes/<id> 取正文。`,"ping.title":`检查{client}插件连接`,"batch.description":'批量编排器:一次请求内顺序执行多个 jsd_* 步骤,前一步结果经双花括号占位符(内容为 步骤id.字段路径)注入后一步 args,中间 id 不回传模型,显著减少往返与上下文。\\n占位符独占一个参数值时保留原类型(数组可直接作 ids 用),嵌在字符串中按 JSON 文本展开;**占位符只在同一次调用的本批次内有效**(步骤表随调用结束即销毁,引用上一批次的步骤必报「占位符引用的步骤不存在或未成功」并中止整批 —— 跨批次请硬编码上一步回显里的真实 id);名字寻址是另一条路:`{{@comp:按钮}}` 取组件/变体集的 id、`{{@var:accent/blue}}` 取变量的 id,取值来自 jsd_get_page 的资源清单(每批最多读一次,同批复用同一份快照;精确名优先,再退忽略大小写),名字一律照清单里的**原样**写 —— 即时设计实测会把带 `/` 的组件名拆成「集合 / 成分」,`assets.components[].name` 只剩叶子名,照创建时那个路径写会不命中);零命中或多命中同名都点名中止、绝不猜(该平台读不到非当前页时清单只覆盖当前页);刚在本批里建出来的资源不在这份快照内,照旧用 {{id.created[0].id}};id 重复/未知工具/引用失败立即中止,工具执行失败默认也中止(stopOnError=false 或单步 continueOnError=true 可走完)。**清单装不下时用 `callsFile`**:给一个 JSON 文件的绝对路径(内容为 {"calls":[…]}(可带 stopOnError / checkDrift)或直接一个数组,与 calls 同形),id 就不必写进上下文 —— 该文件也能用 CLI `text-to-design-mcp exec <文件> [--json] [--dry-run]` 直接跑。\\n回显已做摘要裁剪:节点对象只留 id/name/type/x/y/width/height/z/parentId,vectorPaths(单条 >10KB、16 位小数)与 constraints 等渲染无关字段整键丢弃;裁剪后仍超 20K 字符的步骤降级为 id 清单,并把**整批完整明细**写成 JSONL 落盘(临时目录,一行一步 `{id,tool,ok,data}`),该步回显给 path 与 line(结果里 echoTrimmed=true,并附 echoNote 逐步点名);落盘超上限或写盘失败才退回纯 id 清单,warnings 点名。⚠ **批内回显不含子节点**:节点是整对象摘要化,children 与 characters / fills / *StyleId / vectorPaths 都不在回显里 —— 要读子树请读那个 JSONL 或把该工具**单独调用一次**,别当成「子节点没了 / 字段没生效」。占位符解析不受影响(内部仍用完整数据)。含图标的批次(jsd_create_icon / jsd_clone_node / jsd_create_vector)务必配一次 jsd_export 目视验收,别只看回显。\\n各工具返回键与占位符写法(键写错会报「无法解析占位符引用」并中止整批):\\n· created 为数组 → {{id.created[0].id}}:per-type create(jsd_create_rectangle / jsd_create_frame 等)、jsd_clone_node、jsd_outline_stroke、jsd_create_instance、jsd_detach_instance\\n· created 为单对象 → {{id.created.id}}:jsd_create_svg / jsd_create_icon / jsd_flatten_nodes / jsd_group_nodes / jsd_create_component / jsd_import_component / jsd_combine_as_variants / jsd_create_style\\n· jsd_find → {{id.nodes[0].id}};jsd_get_selection → {{id.selection[0].id}}\\n· 属性类 jsd_set_* → {{id.updated[0].id}};jsd_swap_component → {{id.swapped[0].id}};jsd_delete_style → {{id.removed[0]}}(id 字符串数组)\\\\n· jsd_platform_op → 回包**就是该 op 自己的返回**(没有 .data 那一层信封):figma_variables_create 取 {{id.variables[0].id}}、figma_style_variables_list 取 {{id.styles[0].boundVariables}}、mg_list_variables 取 {{id.variables[0].id}};每个 op 的返回形状写在 jsd_ping 的 platformOps 描述里\\n· jsd_manage_nodes 各 op:select→selected[](id 字符串)、remove→removed[](id 字符串)、clone/outline_stroke→created[](节点**数组**)、group/flatten→created(节点**单对象**,与 jsd_group_nodes / jsd_flatten_nodes 同形)、ungroup→ungrouped[](id 字符串)、reparent→moved[](与 updated[] 同义,两个键都回)、repair→cleaned[](id 字符串)—— id 字符串数组取 {{id.selected[0]}},节点数组取 {{id.created[0].id}},节点单对象取 {{id.created.id}}(单对象与单元素数组互认:`{{id.created[0].id}}` 与 `{{id.created.id}}` 都能解析;多元素数组直接取 `.字段` 仍中止)\\n· jsd_manage_components 各 op:create_component/create_instance/detach_instance/import_component/combine_as_variants→created(detach_instance 是数组,不是 updated)、swap_component→swapped[]、set_instance_properties→updated[]、copy_overrides→snapshotId、apply_overrides/sync_overrides→applied[]\\n· 拿不准某步的返回结构时,先单独调它一次看回显再拼进 batch —— 猜错会连带整批中止。\\n结构变更复核(默认开,checkDrift=false 可关):步骤里含 remove/reparent/group/ungroup/flatten/repair 时,变更前记下受影响父层(含 reparent 的目标父级与当前页顶层)的子节点坐标,收尾再读一次比对 —— 引擎在删改结构后会把**没碰到**的兄弟节点静默挪走(实测 (24,720)→(28,618):无报错、回显正常,渲染上像样式问题,极易走错排查方向)。漂移写进结果 warnings 并给出原值,照原值用 jsd_move_node 回填即可;覆盖面仅限本次操作触及的父层(协议没有整树读法,别的层漂移查不到)。多步套路(画图表 / 从零设计整页 / HTML 转设计稿 / 批量改文案 / 组件与变体 / 变量绑定)先读配方索引 jsd://recipes(ReadMcpResource),别临场拼工具;整页/整档的批量改造(一次调用吃多组、id 不进上下文、回读复核、按块切批)读 jsd://recipes/script-ops。\'',"manageNodes.description":`按 op 分发的节点结构操作聚合入口:select|remove|clone|group|ungroup|flatten|outline_stroke|reparent|repair。单次单操作请优先用对应小工具:jsd_select_nodes / jsd_delete_node / jsd_clone_node / jsd_group_nodes / jsd_ungroup_nodes / jsd_flatten_nodes / jsd_outline_stroke / jsd_reparent_nodes / jsd_repair_nodes(描述含平台缺陷与正确流程)。属性修改用 jsd_set_* 系列(含 jsd_set_shape);组件/实例操作用 jsd_manage_components 或 jsd_create_component / jsd_sync_overrides 等,两工具 op 不通用。\\n各 op 的返回键(在 jsd_batch 里用占位符引用时才不会写错,写错会中止整批):select→selected[](id 字符串)、remove→removed[](id 字符串)、clone/outline_stroke→created[](节点**数组**)、group/flatten→created(节点**单对象**:这两个 op 内部走的就是 jsd_group_nodes / jsd_flatten_nodes 那条路)、ungroup→ungrouped[](id 字符串)、reparent→moved[](同时附 updated[],两者同一份数组)、repair→cleaned[](id 字符串)。id 字符串数组取 {{步骤id.selected[0]}},节点数组取 {{步骤id.created[0].id}},节点单对象取 {{步骤id.created.id}}(单对象与单元素数组互认:{{步骤id.created[0].id}} 与 {{步骤id.created.id}} 都能解析;多元素数组直接取 .字段 仍中止)。'`,"createBooleanOperation.description":`创建单个 BOOLEAN_OPERATION 布尔运算节点,booleanOperation 运算方式({ops})与 children 必填且至少 2 个合并子节点。本工具只建一个根布尔节点。**name 必传且语义化**,不传会落成引擎默认名 node。建多个根节点/复杂树用 jsd_batch 编排`,"setFillColor.description":`设置填充色/渐变(fills 为 Paint 数组,整体替换非合并,需保留的现有填充项要一并传入)、混合模式与团队库填充样式。{warn}`,"setText.description":`修改文本(仅 TEXT 节点生效):**内容与排版** characters/fontSize/fontName/对齐/自适应/大小写/装饰/行高/字距、**颜色** fills/fillStyleId/blendMode、**尺寸** width/height(与 textAutoResize 搭配),以及 Figma 的截断与最大行数;位置 x/y 不在此工具,走 jsd_move_node / jsd_resize_node。字体先 jsd_list_fonts 取 fonts[] 里成对的 family + styles:family 用 fonts[].family 原样,style 用同一项的**全名**(如 SourceHanSansCN-Bold,不是简称 "Bold")——写错不报错、会静默退回默认字面,结果 warnings 会点名。要换行须 width + textAutoResize:"HEIGHT"(缺省 WIDTH_AND_HEIGHT 会按内容撑开;只给 width 不给 autoResize 会被引擎置成 NONE、高度不随内容重算 —— 这类「高度没跟着内容走」的文本,**重设一次 characters 就触发重排**(实测固定宽 200、height 回读 15 的长文本,重设后回读 82)。{warn};characters 内容覆盖在实例内也是正常生效的`,"ping.description":`检查插件是否在线(需先在{client}(即时设计或 Figma)中运行该插件并保持运行)。返回三个能力表:coreCapabilities 为核心能力(create/modify/structure/component/export/image,两平台一致);capabilities 只列平台差异超集(如 variables/componentProperties/textTruncation),即时设计通常只有 styles,Figma 还会有 variables/componentProperties 等;platformOps 列当前平台可用的特有操作(名/标题/参数说明),调 jsd_platform_op 前先读它。回包会被 daemon 缓存,后续可直接读 jsd://platform/state(不必重复 ping)`},x=[`jsdesign`,`figma`,`mastergo`],Kt={jsdesign:Gt[`platform.jsdesign`],figma:Gt[`platform.figma`],mastergo:Gt[`platform.mastergo`]},qt=m.enum(x),Jt=m.enum(Te),Yt=m.enum(De),Xt=m.object({name:m.string().describe(`schema.platform.name`),title:m.string(),description:m.string().describe(`schema.platform.description`)}),Zt=m.object({type:m.literal(`VARIABLE_ALIAS`),id:m.string()}),Qt=m.object({type:m.enum([`BOOLEAN`,`VARIANT`,`TEXT`,`INSTANCE_SWAP`,`SLOT`]),value:m.union([m.boolean(),m.string()]),preferredValues:m.array(m.object({type:m.enum([`COMPONENT`,`COMPONENT_SET`]),key:m.string()})).optional(),boundVariables:m.object({value:Zt.optional()}).optional(),variableId:m.string().optional()}),$t=m.object({type:m.enum([`BOOLEAN`,`TEXT`,`INSTANCE_SWAP`]),value:Zt}),en=m.object({visible:m.string().optional(),characters:m.string().optional(),mainComponent:m.string().optional()}),tn=m.union([m.string(),m.boolean(),Qt,$t]),nn=m.record(m.string(),m.union([Zt,m.array(Zt),m.record(m.string(),Zt)])),rn=Ct.slice(vt.length).join(`/`),an=m.object({ids:m.array(m.string()).optional().describe(`schema.inputs.ids`),name:m.string().optional().describe(`schema.inputs.name`),type:m.string().optional().describe(`节点类型过滤,支持:${vt.join(`/`)};Figma 下还可按画布里本来就有的只读类型筛(${rn}),这些类型能读不能建`),scope:m.enum(Wt).optional().describe(`查找范围:'page'=当前页(缺省)|'document'=跨页全文档(触发全量加载,大文档有一次性成本,结果 note 点名)。⚠ 读不到非当前页的平台(即时设计/MasterGo)会自动退回当前页并在 note 点名 —— 结果只含当前页,不是全文档`),recursive:m.boolean().optional().describe(`schema.inputs.recursive`),depth:m.number().optional().describe(`schema.inputs.depth`)}),on=[`create_component`,`create_instance`,`detach_instance`,`import_component`,`swap_component`,`set_instance_properties`,`combine_as_variants`,`copy_overrides`,`apply_overrides`,`sync_overrides`],sn=m.object({op:m.enum([`select`,`remove`,`clone`,`group`,`ungroup`,`flatten`,`outline_stroke`,`reparent`,`repair`],{error:e=>{let t=e.input,n=typeof t==`string`?t:``;return on.includes(n)?`"${n}" 是组件/实例操作,应使用 jsd_manage_components;本工具仅支持:select|remove|clone|group|ungroup|flatten|outline_stroke|reparent|repair`:`无效 op${n===``?`(缺省)`:` "${n}"`},本工具支持:select|remove|clone|group|ungroup|flatten|outline_stroke|reparent|repair(组件/实例操作在 jsd_manage_components)`}}).describe(`节点结构操作类型:select 设当前选中 | remove 删除(matchName 可再过滤) | clone 复制(右下偏移) | group 编组(可带 layoutMode/itemSpacing/padding* 参数) | ungroup 解组 | flatten 合并为矢量(至少 2 节点) | outline_stroke 描边转轮廓 | reparent 移到 parentId 下(缺省当前选中第一个) | repair 清理已损坏节点`),ids:m.array(m.string()).optional().describe(`节点 id 列表;除 remove/repair 外全部 op 必填(remove 缺省用当前选中)`),matchName:m.string().optional().describe(`仅 remove:在 ids(或当前选中)范围内,仅删除 name 精确匹配的节点`),name:m.string().optional().describe(`schema.inputs.name2`),layoutMode:m.enum([`NONE`,`HORIZONTAL`,`VERTICAL`]).optional().describe(`仅 group。自动布局方向:NONE=纯归组,子节点仅叠加,HORIZONTAL=水平排列,VERTICAL=垂直排列`),itemSpacing:m.number().optional().describe(`仅 group。自动布局项间距(px);primaryAxisAlignItems=SPACE_BETWEEN 时该项被忽略(子项均匀分布)`),paddingTop:m.number().optional().describe(`schema.inputs.paddingTop`),paddingRight:m.number().optional().describe(`schema.inputs.paddingRight`),paddingBottom:m.number().optional().describe(`schema.inputs.paddingBottom`),paddingLeft:m.number().optional().describe(`schema.inputs.paddingLeft`),primaryAxisSizingMode:m.enum([`FIXED`,`AUTO`]).optional().describe(`schema.inputs.primaryAxisSizingMode`),counterAxisSizingMode:m.enum([`FIXED`,`AUTO`]).optional().describe(`schema.inputs.counterAxisSizingMode`),primaryAxisAlignItems:m.enum([`MIN`,`MAX`,`CENTER`,`SPACE_BETWEEN`]).optional().describe(`仅 group。主轴对齐:MIN|MAX|CENTER|SPACE_BETWEEN;设为 SPACE_BETWEEN 时 itemSpacing 被忽略(子项均匀分布)`),counterAxisAlignItems:m.enum([`MIN`,`MAX`,`CENTER`]).optional().describe(`schema.inputs.counterAxisAlignItems`),parentId:m.string().optional().describe(`仅 reparent:目标父节点 id,缺省用当前选中第一个节点。跨父级移动保持节点绝对位置(内部自动换算成新父下的 x/y),无需手动修正;移入 auto-layout 容器时位置由布局接管`),index:m.number().optional().describe(`仅 reparent:插入位置 = children 下标(0 = 最底层,末位 = 最上层,即序列化里的 z);缺省追加到末尾(最上层)。节点已在该父级下时用它调层序;auto-layout 容器同样支持`)}).superRefine((e,t)=>{let n=n=>{t.addIssue({code:`custom`,path:[n],message:`op=${e.op} 缺少必填字段 ${n}`})},r=Array.isArray(e.ids)&&e.ids.length>0&&e.ids.every(e=>typeof e==`string`);switch(e.op){case`select`:case`clone`:case`group`:case`ungroup`:case`flatten`:case`outline_stroke`:case`reparent`:r||n(`ids`)}e.op===`flatten`&&r&&Array.isArray(e.ids)&&e.ids.length<2&&t.addIssue({code:`custom`,path:[`ids`],message:`op=flatten 至少需要 2 个节点 id`})}),cn=m.object({op:m.enum([`create_component`,`create_instance`,`detach_instance`,`import_component`,`swap_component`,`set_instance_properties`,`combine_as_variants`,`copy_overrides`,`apply_overrides`,`sync_overrides`]).describe(`组件操作类型;注意 combine_as_variants/detach_instance 在当前即时设计引擎有内部崩溃,已内置多姿势/副本兜底,仍失败时详见 jsd_manage_components 工具描述`),ids:m.array(m.string()).optional().describe(`节点 id 列表;除 import_component 外全部 op 必填(create_component 为要固化的节点,其余为实例/组件节点)`),name:m.string().optional().describe(`名称;create_component/import_component/combine_as_variants 可选`),key:m.string().optional().describe(`schema.inputs.key`),componentId:m.string().optional().describe(`schema.inputs.componentId`),properties:m.record(m.string(),tn).optional().describe(`属性名→值:变体属性传字符串(如 {"状态":"禁用"}),布尔属性传布尔,需要显式类型或换绑候选时传 {"type":"INSTANCE_SWAP","value":"1:2"}(仅 set_instance_properties 必填);属性名从 jsd_find/jsd_get_selection 返回的 variantProperties(变体)与 componentProperties(布尔/文本/换绑)里取,必须完全匹配`),sourceId:m.string().optional().describe(`源实例(INSTANCE)节点 id;copy_overrides/apply_overrides/sync_overrides 必填`),swapToSource:m.boolean().optional().describe(`套用时是否把目标实例 swap 成源组件,默认 false(swap 会丢失目标既有覆盖,需显式开启)`)}).superRefine((e,t)=>{let n=n=>{t.addIssue({code:`custom`,path:[n],message:`op=${e.op} 缺少必填字段 ${n}`})},r=Array.isArray(e.ids)&&e.ids.length>0&&e.ids.every(e=>typeof e==`string`);switch(e.op){case`create_component`:case`create_instance`:case`detach_instance`:case`swap_component`:case`set_instance_properties`:case`combine_as_variants`:r||n(`ids`);break;case`import_component`:(typeof e.key!=`string`||e.key.length===0)&&n(`key`);break;case`copy_overrides`:(typeof e.sourceId!=`string`||e.sourceId.length===0)&&n(`sourceId`);break;case`apply_overrides`:r||n(`ids`),(typeof e.sourceId!=`string`||e.sourceId.length===0)&&n(`sourceId`);break;case`sync_overrides`:r||n(`ids`),(typeof e.sourceId!=`string`||e.sourceId.length===0)&&n(`sourceId`)}e.op===`swap_component`&&typeof e.componentId!=`string`&&n(`componentId`),e.op===`set_instance_properties`&&(e.properties==null||typeof e.properties!=`object`)&&n(`properties`)}),ln=m.object({ids:m.array(m.string()).min(1).describe(`必填。要导出的节点 id 列表(数组);只导一个节点也要写成数组,如 ["123:456"]。字段名是 ids,不是 nodeId。`),format:m.enum([`PNG`,`JPG`,`SVG`,`PDF`]).optional().describe(`schema.inputs.format`),scale:m.number().optional().describe(`schema.inputs.scale`),savePath:m.string().optional().describe(`schema.inputs.savePath`),includeDataUrl:m.boolean().optional().describe(`schema.inputs.includeDataUrl`)}),un=m.object({family:m.string().optional().describe(`schema.inputs.family`),offset:m.number().int().min(0).optional().describe(`schema.inputs.offset`),limit:m.number().int().min(1).max(500).optional().describe(`schema.inputs.limit`)});m.object({});var dn=m.object({}),fn=m.object({ids:m.array(m.string()).describe(`schema.inputs.ids2`),sourcePath:m.string().describe(`schema.inputs.sourcePath`)}),pn=m.object({op:m.string().describe(`平台特有操作名(如 figma_variables_create)。先 jsd_ping 读 platformOps 名单,照名单里的名字传,不要猜`),params:m.record(m.string(),m.unknown()).optional().describe(`schema.inputs.params`)}),S=m.lazy(()=>m.object({id:m.string(),name:m.string(),type:Tt,x:m.number(),y:m.number(),width:m.number().optional(),height:m.number().optional(),rotation:m.number().optional(),opacity:m.number().optional(),visible:m.boolean().optional(),locked:m.boolean().optional(),parentId:m.string().optional(),z:m.number().optional().describe(`在父级 children 里的下标 = 绘制顺序,0 = 最底层、数值越大越靠上;判断遮挡读它,不用记数组方向`),fills:m.array(ot).optional(),strokes:m.array(ot).optional(),strokeWeight:m.number().optional(),strokeTopWeight:m.number().optional(),strokeBottomWeight:m.number().optional(),strokeLeftWeight:m.number().optional(),strokeRightWeight:m.number().optional(),strokeAlign:m.enum([`CENTER`,`INSIDE`,`OUTSIDE`]).optional(),strokeCap:m.enum([`NONE`,`ROUND`,`SQUARE`,`ARROW_LINES`,`ARROW_EQUILATERAL`]).optional(),strokeJoin:m.enum([`MITER`,`BEVEL`,`ROUND`]).optional(),dashPattern:m.array(m.number()).optional(),cornerSmoothing:m.number().optional(),blendMode:at.optional(),constraints:m.object({horizontal:ct,vertical:ct}).optional(),layoutGrids:m.array(lt).optional(),clipsContent:m.boolean().optional(),arcData:m.object({startingAngle:m.number(),endingAngle:m.number(),innerRadius:m.number()}).optional(),effects:m.array(st).optional(),cornerRadius:m.number().optional(),topLeftRadius:m.number().optional(),topRightRadius:m.number().optional(),bottomLeftRadius:m.number().optional(),bottomRightRadius:m.number().optional(),pointCount:m.number().optional(),innerRadius:m.number().optional(),layoutMode:m.enum([`NONE`,`HORIZONTAL`,`VERTICAL`]).optional(),itemSpacing:m.number().optional(),paddingTop:m.number().optional(),paddingRight:m.number().optional(),paddingBottom:m.number().optional(),paddingLeft:m.number().optional(),primaryAxisSizingMode:m.enum([`FIXED`,`AUTO`]).optional(),counterAxisSizingMode:m.enum([`FIXED`,`AUTO`]).optional(),primaryAxisAlignItems:m.enum([`MIN`,`MAX`,`CENTER`,`SPACE_BETWEEN`]).optional(),counterAxisAlignItems:m.enum([`MIN`,`MAX`,`CENTER`]).optional(),layoutGrow:m.number().optional(),layoutAlign:m.enum([`MIN`,`CENTER`,`MAX`,`STRETCH`,`INHERIT`]).optional(),childCount:m.number().optional(),children:m.array(S).optional(),characters:m.string().optional(),fontSize:m.number().optional(),fontName:dt.optional(),textAlignHorizontal:m.enum([`LEFT`,`CENTER`,`RIGHT`,`JUSTIFIED`]).optional(),textAlignVertical:m.enum([`TOP`,`CENTER`,`BOTTOM`]).optional(),textAutoResize:m.enum([`NONE`,`WIDTH_AND_HEIGHT`,`HEIGHT`,`TRUNCATE`]).optional(),textCase:m.enum([`ORIGINAL`,`UPPER`,`LOWER`,`TITLE`]).optional(),textDecoration:m.enum([`NONE`,`UNDERLINE`,`STRIKETHROUGH`]).optional(),lineHeight:ft.optional(),letterSpacing:pt.optional(),vectorPaths:m.array(ut).optional(),booleanOperation:m.enum(qe).optional(),isMask:m.boolean().optional(),variantProperties:m.record(m.string(),m.string()).optional(),mainComponentId:m.string().optional(),variantGroupProperties:m.record(m.string(),m.array(m.string())).optional(),textTruncation:m.enum([`DISABLED`,`ENDING`]).optional(),maxLines:m.number().optional(),fillStyleId:m.string().optional(),strokeStyleId:m.string().optional(),textStyleId:m.string().optional(),effectStyleId:m.string().optional(),componentProperties:m.record(m.string(),Qt).optional(),componentPropertyReferences:en.optional(),boundVariables:nn.optional()})),mn=m.object({created:m.union([S,m.array(S)]),warnings:m.array(m.string()).optional()}),hn=m.object({updated:m.array(S),warnings:m.array(m.string()).optional()}),gn=m.object({connected:m.boolean(),platform:qt.optional(),capabilities:m.array(Jt).optional().describe(`schema.results.capabilities`),coreCapabilities:m.array(Yt).optional().describe(`所有平台都具备的核心能力(create/modify/structure/component/export/image),不随平台变化`),platformOps:m.array(Xt).optional().describe(`当前平台可用的特有操作名单(名/标题/参数说明)。调用 jsd_platform_op 前先看这里,不要猜 op 名`),error:m.string().optional()}),_n=m.object({selection:m.array(S),pageName:m.string()}),vn=m.object({nodes:m.array(S),total:m.number(),scope:m.enum(Wt).optional(),note:m.string().optional()}),yn=m.object({selected:m.array(m.string()).optional(),removed:m.array(m.string()).optional(),ungrouped:m.array(m.string()).optional(),moved:m.array(S).optional(),updated:m.array(S).optional(),cleaned:m.array(m.string()).optional(),created:m.union([S,m.array(S)]).optional(),warnings:m.array(m.string()).optional()}),bn=m.object({variantProperties:m.record(m.string(),m.string()).optional(),componentProperties:m.record(m.string(),Qt).optional(),propsSummary:m.array(m.string()).optional()}),xn=m.object({instanceId:m.string(),instanceName:m.string(),ok:m.boolean(),message:m.string().optional()}),Sn=m.object({created:m.union([S,m.array(S)]).optional(),swapped:m.array(S).optional(),updated:m.array(S).optional(),snapshotId:m.string().optional(),sourceName:m.string().optional(),captured:bn.optional(),applied:m.array(xn).optional(),source:bn.optional(),failed:m.array(m.object({id:m.string(),message:m.string()})).optional(),warnings:m.array(m.string()).optional()}),Cn=m.object({exports:m.array(m.object({id:m.string(),name:m.string(),format:m.enum([`PNG`,`JPG`,`SVG`,`PDF`]),mimeType:m.string(),size:m.number(),path:m.string().optional(),dataUrl:m.string().optional()}))}),wn=m.object({families:m.array(m.string()).describe(`schema.results.families`),fonts:m.array(m.object({family:m.string().describe(`schema.results.family`),styles:m.array(m.string()).describe(`schema.results.styles`)})).optional().describe(`family → 可用 style 明细。写 fontName 前照这份清单取组合(family+style 需精确匹配,猜错会静默退回默认字重)`),count:m.number().describe(`schema.results.count`),total:m.number().optional().describe(`schema.results.total`),offset:m.number().optional().describe(`schema.results.offset`),truncated:m.boolean().optional().describe(`schema.results.truncated`)}),Tn=m.object({id:m.string(),name:m.string()}),En=Tn.extend({properties:m.record(m.string(),m.array(m.string())).optional().describe(`维度 → 可选值,如 {"状态":["默认","禁用"]};平台读不到该字段时整个键省略`)}),Dn=Tn.extend({type:m.enum([`PAINT`,`TEXT`,`EFFECT`,`GRID`])}),On=m.object({summary:m.object({components:m.number(),variants:m.number(),styles:m.number(),variables:m.number()}),components:m.array(Tn),variants:m.array(En),styles:m.array(Dn),variables:m.array(Tn)}),kn=m.object({pageName:m.string(),nodes:m.array(m.object({id:m.string(),name:m.string(),type:Tt,x:m.number(),y:m.number(),width:m.number().optional(),height:m.number().optional()})),count:m.number(),assets:On.optional(),pages:m.array(m.object({name:m.string(),childCount:m.number()})).optional(),note:m.string().optional()});m.object({styles:m.array(m.object({id:m.string(),name:m.string(),type:m.enum(Ae)})),count:m.number(),note:m.string().optional()});var An=m.object({created:m.object({id:m.string(),name:m.string(),type:m.enum(Ae)})}),jn=m.object({removed:m.array(m.string()),failed:m.array(m.object({id:m.string(),reason:m.string().describe(`这一条没删掉的原因(通常是样式 id 不存在)`)}))}),C=m.object({x:m.number().optional().describe(`X 坐标(px,相对父节点;auto-layout 子节点的位置由父容器接管,修改可能被布局覆盖)`),y:m.number().optional().describe(`Y 坐标(px,相对父节点;auto-layout 子节点的位置由父容器接管,修改可能被布局覆盖)`),width:m.number().optional().describe(`schema.sharedProps.width`),height:m.number().optional().describe(`schema.sharedProps.height`),rotation:m.number().optional().describe(`schema.sharedProps.rotation`),opacity:m.number().optional().describe(`schema.sharedProps.opacity`),visible:m.boolean().optional(),locked:m.boolean().optional()}),Mn=m.object({width:m.number().min(0).optional().describe(`宽度(px)。横线(高度为 0 的 LINE)传 0;其他类型最低 0.01(引擎 resize 校验),低于会明确报错`),height:m.number().min(0).optional().describe(`高度(px)。竖线(宽度为 0 的 LINE)传 0;其他类型最低 0.01(引擎 resize 校验),低于会明确报错`)}),Nn=m.object({pointCount:m.number().optional().describe(`schema.sharedProps.pointCount`),innerRadius:m.number().optional().describe(`schema.sharedProps.innerRadius`)}),Pn=m.object({strokes:m.array(ot).optional().describe(`schema.sharedProps.strokes`),strokeWeight:m.number().optional().describe(`schema.sharedProps.strokeWeight`),strokeTopWeight:m.number().optional().describe(`schema.sharedProps.strokeTopWeight`),strokeBottomWeight:m.number().optional().describe(`schema.sharedProps.strokeBottomWeight`),strokeLeftWeight:m.number().optional().describe(`schema.sharedProps.strokeLeftWeight`),strokeRightWeight:m.number().optional().describe(`schema.sharedProps.strokeRightWeight`),strokeAlign:m.enum([`CENTER`,`INSIDE`,`OUTSIDE`]).optional().describe(`schema.sharedProps.strokeAlign`),strokeCap:m.enum([`NONE`,`ROUND`,`SQUARE`,`ARROW_LINES`,`ARROW_EQUILATERAL`]).optional().describe(`schema.sharedProps.strokeCap`),strokeJoin:m.enum([`MITER`,`BEVEL`,`ROUND`]).optional().describe(`schema.sharedProps.strokeJoin`),dashPattern:m.array(m.number()).optional().describe(`schema.sharedProps.dashPattern`),strokeStyleId:m.string().optional().describe(`schema.sharedProps.strokeStyleId`)}),Fn=m.object({cornerRadius:m.number().optional().describe(`圆角半径(px),四角统一;仅 FRAME/RECTANGLE/ELLIPSE/POLYGON/STAR/VECTOR/BOOLEAN_OPERATION 生效(LINE/TEXT 无圆角)`),topLeftRadius:m.number().optional().describe(`schema.sharedProps.topLeftRadius`),topRightRadius:m.number().optional().describe(`schema.sharedProps.topRightRadius`),bottomLeftRadius:m.number().optional().describe(`schema.sharedProps.bottomLeftRadius`),bottomRightRadius:m.number().optional().describe(`schema.sharedProps.bottomRightRadius`)}),In=m.object({characters:m.string().optional().describe(`schema.sharedProps.characters`),fontSize:m.number().optional().describe(`schema.sharedProps.fontSize`),fontName:dt.optional().describe(`字体:{family,style};需精确匹配,建议先用 jsd_list_fonts 查可用字体(不可用时静默回退默认字体)`),textAlignHorizontal:m.enum([`LEFT`,`CENTER`,`RIGHT`,`JUSTIFIED`]).optional().describe(`schema.sharedProps.textAlignHorizontal`),textAlignVertical:m.enum([`TOP`,`CENTER`,`BOTTOM`]).optional().describe(`schema.sharedProps.textAlignVertical`),textAutoResize:m.enum([`NONE`,`WIDTH_AND_HEIGHT`,`HEIGHT`,`TRUNCATE`]).optional().describe(`文本自适应:NONE=固定尺寸|WIDTH_AND_HEIGHT=按内容撑开(缺省,此时修改 width/height 会被覆盖)|HEIGHT=固定宽自适应高|TRUNCATE=截断。要固定文本框尺寸必须设为 NONE`),textCase:m.enum([`ORIGINAL`,`UPPER`,`LOWER`,`TITLE`]).optional().describe(`schema.sharedProps.textCase`),textDecoration:m.enum([`NONE`,`UNDERLINE`,`STRIKETHROUGH`]).optional().describe(`schema.sharedProps.textDecoration`),lineHeight:ft.optional().describe(`schema.sharedProps.lineHeight`),letterSpacing:pt.optional().describe(`schema.sharedProps.letterSpacing`),textStyleId:m.string().optional().describe(`schema.sharedProps.textStyleId`),textTruncation:m.enum([`DISABLED`,`ENDING`]).optional().describe(`schema.sharedProps.textTruncation`),maxLines:m.number().optional().describe(`schema.sharedProps.maxLines`)}),Ln=m.object({layoutMode:m.enum([`NONE`,`HORIZONTAL`,`VERTICAL`]).optional().describe(`自动布局方向:NONE|HORIZONTAL|VERTICAL,FRAME / COMPONENT / COMPONENT_SET 生效。传 itemSpacing/padding*/primaryAxis* 等布局属性前必须先设为 HORIZONTAL 或 VERTICAL`),itemSpacing:m.number().optional().describe(`自动布局项间距(px);primaryAxisAlignItems=SPACE_BETWEEN 时该项被忽略(子项均匀分布)`),paddingTop:m.number().optional().describe(`schema.sharedProps.paddingTop`),paddingRight:m.number().optional().describe(`schema.sharedProps.paddingRight`),paddingBottom:m.number().optional().describe(`schema.sharedProps.paddingBottom`),paddingLeft:m.number().optional().describe(`schema.sharedProps.paddingLeft`),primaryAxisSizingMode:m.enum([`FIXED`,`AUTO`]).optional().describe(`schema.sharedProps.primaryAxisSizingMode`),counterAxisSizingMode:m.enum([`FIXED`,`AUTO`]).optional().describe(`schema.sharedProps.counterAxisSizingMode`),primaryAxisAlignItems:m.enum(Ne).optional().describe(`主轴对齐:MIN|MAX|CENTER|SPACE_BETWEEN;设为 SPACE_BETWEEN 时 itemSpacing 被忽略(子项均匀分布)`),counterAxisAlignItems:m.enum(Pe).optional().describe(`schema.sharedProps.counterAxisAlignItems`),layoutGrow:m.number().optional().describe(`schema.sharedProps.layoutGrow`),layoutAlign:m.enum(Me).optional().describe(`schema.sharedProps.layoutAlign`)}),w=m.object({fills:m.array(ot).optional().describe(`填充列表(Paint 数组;整体替换,非合并,需保留的现有填充项要一并传入)`),fillStyleId:m.string().optional().describe(`schema.sharedProps.fillStyleId`),blendMode:at.optional(),effectStyleId:m.string().optional().describe(`schema.sharedProps.effectStyleId`),effects:m.array(st).optional().describe(`schema.sharedProps.effects`),constraints:m.object({horizontal:ct.describe(`水平约束:MIN|MAX|STRETCH|CENTER|SCALE`),vertical:ct.describe(`垂直约束:MIN|MAX|STRETCH|CENTER|SCALE`)}).optional().describe(`schema.sharedProps.vertical`),clipsContent:m.boolean().optional().describe(`schema.sharedProps.clipsContent`),cornerSmoothing:m.number().optional().describe(`schema.sharedProps.cornerSmoothing`),layoutGrids:m.array(lt).optional().describe(`schema.sharedProps.layoutGrids`),arcData:m.object({startingAngle:m.number().describe(`schema.sharedProps.startingAngle`),endingAngle:m.number().describe(`schema.sharedProps.endingAngle`),innerRadius:m.number().describe(`schema.sharedProps.innerRadius2`)}).optional().describe(`schema.sharedProps.innerRadius3`)}),Rn={ids:m.array(m.string()).min(1).optional().describe(`schema.splitOps.ids`),matchName:m.string().optional().describe(`schema.splitOps.matchName`),recursive:m.boolean().optional().describe(`是否递归应用到子树,默认 false。recursive 只作用于**后代**,不含目标节点自身:给容器 FRAME 传它刷色,容器自己不会被改(容器自身加描边会渲染成方框)。目标是无子节点的叶子时,自身即整棵子树,仍会改。要把容器自己也算进去再传 includeSelf=true`),includeSelf:m.boolean().optional().describe(`仅 recursive=true 时有意义:是否连目标节点自身一起改,默认 false。传 true 且目标是容器时结果会带 warnings 点名「容器自身也被修改」`)},T=(e,t=1)=>m.array(m.string()).min(t).describe(e),zn=m.object({ids:T(`要设为当前选中的节点 id 列表`)}).strict(),Bn=m.object({ids:m.array(m.string()).optional().describe(`schema.splitOps.ids2`),matchName:m.string().optional().describe(`schema.splitOps.matchName2`)}).strict(),Vn=m.object({ids:T(`要复制的节点 id 列表(新副本右下偏移放置)`)}).strict(),Hn=m.object({ids:T(`要编组的节点 id 列表,至少 2 个`,2),name:m.string().optional().describe(`schema.splitOps.name`),layoutMode:m.enum([`NONE`,`HORIZONTAL`,`VERTICAL`]).optional().describe(`自动布局方向:NONE=纯归组(子节点仅叠加,不排布),HORIZONTAL=水平排列,VERTICAL=垂直排列`),itemSpacing:m.number().optional().describe(`自动布局项间距(px);primaryAxisAlignItems=SPACE_BETWEEN 时该项被忽略(子项均匀分布)`),paddingTop:m.number().optional().describe(`schema.splitOps.paddingTop`),paddingRight:m.number().optional().describe(`schema.splitOps.paddingRight`),paddingBottom:m.number().optional().describe(`schema.splitOps.paddingBottom`),paddingLeft:m.number().optional().describe(`schema.splitOps.paddingLeft`),primaryAxisSizingMode:m.enum([`FIXED`,`AUTO`]).optional().describe(`schema.splitOps.primaryAxisSizingMode`),counterAxisSizingMode:m.enum([`FIXED`,`AUTO`]).optional().describe(`schema.splitOps.counterAxisSizingMode`),primaryAxisAlignItems:m.enum([`MIN`,`MAX`,`CENTER`,`SPACE_BETWEEN`]).optional().describe(`主轴对齐:MIN|MAX|CENTER|SPACE_BETWEEN;设为 SPACE_BETWEEN 时 itemSpacing 被忽略(子项均匀分布)`),counterAxisAlignItems:m.enum([`MIN`,`MAX`,`CENTER`]).optional().describe(`schema.splitOps.counterAxisAlignItems`)}).strict(),Un=m.object({ids:T(`要解组的节点 id 列表`)}).strict(),Wn=m.object({ids:T(`要合并为单一矢量的节点 id 列表,至少 2 个`,2)}).strict(),Gn=m.object({ids:T(`要把描边转成轮廓矢量的节点 id 列表`)}).strict(),Kn=m.object({ids:T(`要移动的节点 id 列表`),parentId:m.string().optional().describe(`目标父节点 id。**强烈建议显式传**:只给 index 不给 parentId 时,缺省父级取「当前选中里第一个不是被移动节点的节点」——当前选中为空或不含父容器时该值不可靠(历史上因此报过「没有找到目标父节点」,或把节点误移进另一个被选中的节点下)。不传 parentId 的可用姿势:①先用 jsd_select_nodes 选中目标容器;②只给 index 且 ids 里含被调整节点本身 → 按被调整节点的原父级在此处调层序。跨父级移动**保持节点绝对位置**:内部按页面系记账并自动换算成新父下的 x/y,不要按「相对系重解释」手动摆回(那会把节点推走)。唯一例外是移入 auto-layout 容器 —— 位置由布局接管,要调排布改 itemSpacing / 对齐`),index:m.number().optional().describe(`目标在父节点 children 数组里的最终下标;缺省追加到末尾。语义 = 绘制顺序(也就是序列化里的 z):0 是最底层,末位是最上层。节点已在该父级下时,本参数用于调整层序(不传则原地不动);auto-layout 容器同样支持(内部临时关掉布局插入后恢复),若引擎没落位会明确报错`)}).strict(),qn=m.object({ids:m.array(m.string()).optional().describe(`schema.splitOps.ids3`)}).strict(),Jn=m.object({ids:m.array(m.string()).optional().describe(`要固化为组件的节点 id 列表;给了就先校验存在(不改动这些节点)`),name:m.string().optional().describe(`schema.splitOps.name2`),children:m.array(Et).max(100).optional().describe(`组件内容:子节点数组(递归嵌套,最多 100 个直接子节点),字段与 jsd_create_frame 的 children 一致;给了就一次建成带内容的组件,不必再 reparent 搬子节点`),width:m.number().optional().describe(`组件宽度(px);在子节点插完之后压,避免被布局重算吃掉`),height:m.number().optional().describe(`组件高度(px);同上`)}).strict(),Yn=m.object({ids:T(`要生成实例的组件(COMPONENT)节点 id 列表`)}).strict(),Xn=m.object({ids:T(`要取消实例链接的实例(INSTANCE)节点 id 列表`)}).strict(),Zn=m.object({key:m.string().describe(`schema.splitOps.key`),name:m.string().optional().describe(`schema.splitOps.name3`)}).strict(),Qn=m.object({ids:T(`要换绑的实例(INSTANCE)节点 id 列表`),componentId:m.string().describe(`schema.splitOps.componentId`)}).strict(),$n=m.object({ids:T(`要设置变体/组件属性的实例(INSTANCE)节点 id 列表`),properties:m.record(m.string(),tn).describe('属性名→值:变体属性传字符串(如 {"状态":"禁用"}),布尔属性传布尔(如 {"显示图标":false}),需要显式类型或换绑候选时传 {"type":"INSTANCE_SWAP","value":"1:2"}。属性名取 jsd_find / jsd_get_selection 的 variantProperties(变体)与 componentProperties(布尔/文本/换绑):**变体属性传名字即可;组件属性传带 `#` 后缀的完整键**(如 `标题#32:0`)—— 组件属性在引擎侧只认完整键,短名会报 `Could not find a component property with name`(真机实测,三种类型都如此)。传短名时 core 只在基名**唯一**命中时替你补全,有歧义直接报错并列出候选,不做猜测。**选哪个键之前先读 componentPropertyReferences**:它标明「哪个图层由哪个属性驱动」,属性成对存在时只有连着可见层的那一组会改画面')}).strict(),er=m.object({ids:T(`要合并为变体集(分量)的组件(COMPONENT)节点 id 列表;实例不能直接合成,须先 jsd_detach_instance 或重建为组件`),name:m.string().optional().describe(`schema.splitOps.name4`)}).strict(),tr=m.object({kind:m.enum(Ae).describe("样式类别。八项是三家 `StyleType` 的并集:**PAINT / TEXT / EFFECT / GRID 三家都有**;`STROKE_WIDTH / CORNER_RADIUS / PADDING / SPACING` **只 MasterGo 能建**—— 在 Figma / 即时设计传这四类会被写前点名拒(不静默、不 fallthrough 建成别的类)。MG 上和另四类一样是「从取值节点抄」,所以间距类要那节点是自动布局容器、圆角类要它真有圆角,读不出值时前置检查就会拦下"),name:m.string().min(1).describe("样式名,建议用「分组/名称」两层(如 `色板/主色`)"),description:m.string().optional().describe(`样式说明,建后可在 jsd://styles 里回读`),fromNodeId:m.string().describe(`**取值来源节点**(必填):三平台唯一都成立的形状 —— MG 的原生入口就是「从这个图层抄」,Figma / jsDesign 由本仓把该节点的 fills / effects / layoutGrids / 文本排版字段灌进新样式。PAINT 类 fills 优先,节点只有描边时退到 strokes`)}).strict(),nr=m.object({ids:m.array(m.string().min(1)).min(1).describe(`要删的本地样式 id 列表(取自 jsd://styles 或 jsd_get_page 的 assets.styles);按 id 不按名 —— 同名样式可以并存,按名删等于猜`)}).strict(),rr=m.object({sourceId:m.string().describe(`源实例(INSTANCE)节点 id,要复制其覆盖(变体/组件属性/可见样式文本)`)}).strict(),ir={ids:T(`要套用覆盖快照的目标实例(INSTANCE)节点 id 列表`),sourceId:m.string().describe(`schema.splitOps.sourceId`),swapToSource:m.boolean().optional().describe(`套用时是否把目标实例 swap 成源组件,默认 false(swap 会丢失目标既有覆盖,需显式开启)`)},ar=m.object(ir).strict(),or=m.object(ir).strict(),sr={fills:w.shape.fills,fillStyleId:w.shape.fillStyleId,blendMode:w.shape.blendMode},cr={...Pn.shape},lr={cornerRadius:Fn.shape.cornerRadius,topLeftRadius:Fn.shape.topLeftRadius,topRightRadius:Fn.shape.topRightRadius,bottomLeftRadius:Fn.shape.bottomLeftRadius,bottomRightRadius:Fn.shape.bottomRightRadius,cornerSmoothing:w.shape.cornerSmoothing},ur={...In.shape,fills:w.shape.fills,fillStyleId:w.shape.fillStyleId,blendMode:w.shape.blendMode,width:Mn.shape.width,height:Mn.shape.height},dr={x:C.shape.x,y:C.shape.y,rotation:C.shape.rotation},fr={...Mn.shape,x:C.shape.x,y:C.shape.y},pr={...Ln.shape,constraints:w.shape.constraints},mr={effects:w.shape.effects,effectStyleId:w.shape.effectStyleId,clipsContent:w.shape.clipsContent,layoutGrids:w.shape.layoutGrids,arcData:w.shape.arcData},hr={opacity:C.shape.opacity,visible:C.shape.visible,locked:C.shape.locked},gr={name:m.string().describe(`schema.splitOps.name5`)},_r={...Nn.shape};function E(e){return m.object({...Rn,...e}).strict()}var vr=E(sr),yr=E(cr),br=E(lr),xr=E(ur),Sr=E(dr),Cr=E(fr),wr=E(pr),Tr=E(mr),Er=E(hr),Dr=E(gr),Or=E(_r),kr={set_fill:Object.keys(sr),set_stroke:Object.keys(cr),set_corner_radius:Object.keys(lr),set_text:Object.keys(ur),move:Object.keys(dr),resize:Object.keys(fr),set_layout:Object.keys(pr),set_effects:Object.keys(mr),set_visibility:Object.keys(hr),rename:Object.keys(gr),set_shape:Object.keys(_r)};function D(e){return m.object({...Rn,props:m.object(e).strict()}).strict()}D(sr),D(cr),D(lr),D(ur),D(dr),D(fr),D(pr),D(mr),D(hr),D(gr),D(_r);function Ar(e,t,n){let r=e.ctx.platform;return r==null?null:He(r,t,e.node.type)?Ve(r,t,n)?null:`value`:`type`}function jr(e,t,n){let r=Ar(e,t,n);if(r==null)return!0;let i=e.ctx.platform;if(i==null)return!0;let a=Kt[i];if(e.outcome.ignored.add(t),r===`type`)return e.outcome.warnings.push(`${t} 在 ${a} 的「${e.node.type}」上没有对应字段(该平台的这类节点不含这个属性的 mixin),本次已跳过:不是写失败,是这种节点上不存在该属性。要用它就换本平台支持该属性的节点类型;不去写的话结果里不会再回显它。`),!1;let o=Ue(i,t)??`该取值本平台无法表达`;return e.outcome.warnings.push(`${t} 的值 ${JSON.stringify(n)} 无法在 ${a} 表达(${o}),本次已跳过:不是写失败,是平台没有这个取值。请改用本平台支持的取值,或把该差异留给调用方处理。`),!1}function Mr(e,t){return e[t]}function Nr(e,t,n){e[t]=n}function Pr(e,t,n){return n==null||!(t in e)?!1:(Nr(e,t,n),!0)}function Fr(e,t,n,r){return Ir(e,t,n,r)?Pr(t,n,r):!1}function Ir(e,t,n,r){return!(r==null||!ke(n,t.type)||!jr(e,n,r))}var Lr={id:`layout`,keys:[`layoutMode`,`itemSpacing`,`paddingTop`,`paddingRight`,`paddingBottom`,`paddingLeft`,`primaryAxisSizingMode`,`counterAxisSizingMode`,`primaryAxisAlignItems`,`counterAxisAlignItems`],write(e){let{node:t,src:n,create:r}=e,i=n.layoutMode;if(i!=null&&Br(t),r){if(i==null)return;Fr(e,t,`layoutMode`,i);let r=n;Fr(e,t,`itemSpacing`,r.itemSpacing??0);for(let n of[`paddingTop`,`paddingRight`,`paddingBottom`,`paddingLeft`])Fr(e,t,n,r[n]??0);for(let n of[`primaryAxisAlignItems`,`counterAxisAlignItems`])Fr(e,t,n,r[n]);Ur(e);return}for(let r of Lr.keys)Fr(e,t,r,n[r])},settle(e){let{node:t,src:n}=e;for(let r of[`primaryAxisAlignItems`,`counterAxisAlignItems`]){let i=n[r];i!=null&&ke(r,t.type)&&Ar(e,r,i)==null&&(r in t&&t[r]!==i&&Nr(t,r,i),e.outcome.readback.push({key:r,ok:!(r in t)||t[r]===i}))}for(let r of[`itemSpacing`,`paddingTop`,`paddingRight`,`paddingBottom`,`paddingLeft`]){let i=n[r],a=i;e.create&&(a=n.layoutMode==null?void 0:i??0),a!=null&&ke(r,t.type)&&Ar(e,r,a)==null&&(r in t&&Mr(t,r)!==a&&Nr(t,r,a),e.outcome.readback.push({key:r,ok:!(r in t)||Mr(t,r)===a}))}for(let r of[`primaryAxisSizingMode`,`counterAxisSizingMode`]){let i=n[r];i!=null&&(e.create&&n.layoutMode==null||ke(r,t.type)&&Ar(e,r,i)==null&&(r in t&&Mr(t,r)!==i&&Nr(t,r,i),e.outcome.readback.push({key:r,ok:!(r in t)||Mr(t,r)===i})))}if(n.layoutMode==null||!ke(`layoutMode`,t.type))return;let r=n.layoutMode;`layoutMode`in t&&t.layoutMode!==r&&(t.layoutMode=r);let i=!(`layoutMode`in t)||t.layoutMode===r;e.outcome.readback.push({key:`layoutMode`,ok:i})}};function Rr(e){try{let t=e.children;return Array.isArray(t)?t.map(e=>e.id):[]}catch{return[]}}var zr=new WeakMap;function Br(e){let t=e;zr.set(e,{order:Rr(e),width:typeof t.width==`number`?t.width:void 0,height:typeof t.height==`number`?t.height:void 0})}var Vr=new WeakMap;function Hr(e,t){let n=Vr.get(e)??new Set;n.add(t),Vr.set(e,n)}function Ur(e){let{node:t,src:n}=e;if(n.layoutMode==null)return;let r=Wr(n,e.outermost),i=n.layoutMode===`HORIZONTAL`;for(let e of[`primaryAxisSizingMode`,`counterAxisSizingMode`]){let a=r[e];a!=null&&n[e]==null&&e in t&&(Nr(t,e,a),a===`AUTO`&&Hr(t,e===`primaryAxisSizingMode`===i?`width`:`height`))}}function Wr(e,t){let n=e.layoutMode;if(n!==`HORIZONTAL`&&n!==`VERTICAL`)return{};let r=n===`HORIZONTAL`,i=e=>e===`height`&&!t?`AUTO`:`FIXED`,a={};return(r?e.width!=null:e.height!=null)&&(a.primaryAxisSizingMode=i(r?`width`:`height`)),(r?e.height!=null:e.width!=null)&&(a.counterAxisSizingMode=i(r?`height`:`width`)),a}Object.keys(Ee).filter(e=>e!==`componentProperties`);var Gr=new Set(`fills.strokes.strokeWeight.strokeTopWeight.strokeBottomWeight.strokeLeftWeight.strokeRightWeight.strokeAlign.strokeCap.strokeJoin.dashPattern.blendMode.effects.cornerRadius.topLeftRadius.topRightRadius.bottomLeftRadius.bottomRightRadius.cornerSmoothing.fontName.fontSize.lineHeight.letterSpacing.textCase.textDecoration.textAlignHorizontal.textAlignVertical`.split(`.`));new Set([...new Set([`fills`,`strokes`,`strokeWeight`,`strokeTopWeight`,`strokeBottomWeight`,`strokeLeftWeight`,`strokeRightWeight`,`strokeAlign`,`strokeCap`,`strokeJoin`,`dashPattern`,`blendMode`,`effects`,`cornerRadius`,`topLeftRadius`,`topRightRadius`,`bottomLeftRadius`,`bottomRightRadius`,`cornerSmoothing`,`clipsContent`,`layoutGrids`,`arcData`])].filter(e=>Gr.has(e)));function Kr(){return[`⚠ 对位于 INSTANCE 内的子节点改样式有平台风险:回显是新值,渲染却可能仍是组件原样式(实测 ${[...Gr].slice(0,2).join(` / `)},其余样式同类风险);`,`命中时本次结果会带 warnings 并给出主组件里对应子节点的 id —— 改它即所有实例继承;`,`只要单个实例不同,先 jsd_detach_instance 再改。`].join(``)}var qr={"zh-CN":Gt,en:{"platform.jsdesign":`jsDesign`,"platform.figma":`Figma`,"platform.mastergo":`MasterGo`,"capability.core.create":`Create`,"capability.core.modify":`Modify`,"capability.core.structure":`Structure`,"capability.core.component":`Component`,"capability.core.export":`Export`,"capability.core.image":`Image fill`,"capability.host.styles":`Local styles`,"capability.host.styleEnumeration":`Local style listing (can enumerate which styles exist)`,"capability.host.styleEnumerationSync":`Style enumeration uses the sync entry (runtime *Async members are unusable)`,"capability.host.mainComponentSync":`Main component read via the sync field (runtime getMainComponentAsync never settles)`,"capability.host.textTruncation":`Text truncation`,"capability.host.componentProperties":`Component properties`,"capability.host.documentScopeRead":`Document-scope read (can read pages other than the current one)`,"capability.host.variables":`Variables`,"capability.host.inPlaceVariants":`In-place variants`,"locale.system":`System`,"locale.zh-CN":`中文`,"locale.en":`English`,"locale.abbr.zh-CN":`中`,"locale.abbr.en":`EN`,"locale.menu":`Language`,"locale.title.followSystem":`Language: follow system (currently {locale})`,"locale.title.fixed":`Language: {locale}`,"status.connected.label":`Connected`,"status.connected.title":`Service is online; plugin and AI session are connected`,"status.connecting.label":`Connecting…`,"status.connecting.title":`Connected to the background service; waiting for it to confirm this channel`,"status.waiting.label":`Waiting`,"status.waiting.title":`No manual action needed while the service is offline — an AI call starts it`,"status.superseded.label":`Taken over`,"status.superseded.title":`Another plugin panel holds the channel; click "Reclaim" to switch back to this panel`,"header.retry":`Retry`,"header.retry.title":`Reconnect to the background service now instead of waiting for the backoff`,"header.reclaim":`Reclaim`,"header.reclaim.title":`Reclaim the channel from the other plugin panel`,"header.theme.toDark":`Switch to dark theme`,"header.theme.toLight":`Switch to light theme`,"header.cameraLock.locked":`Camera locked`,"header.cameraLock.unlocked":`Camera follows`,"header.cameraLock.title.locked":`Camera locked: canvas operations do not move your viewport (click to follow)`,"header.cameraLock.title.unlocked":`Camera follows: canvas operations scroll and zoom to the result (click to lock)`,"header.minimize":`Minimize`,"header.minimize.title":`Minimize the panel to just the logo; double-click the logo to restore`,"header.restore.title":`Double-click the logo to restore the panel`,"upgrade.title":`A newer version is available (click for upgrade steps)`,"upgrade.modal.title":`Upgrade to the latest version`,"upgrade.current":`Current {version}`,"upgrade.latest":`Latest {version}`,"upgrade.plugin.label":`Plugin`,"upgrade.service.label":`Service`,"upgrade.step.service":`① Service, just restart the AI session. It runs npx -y text-to-design-mcp@latest, so it is always the newest`,"upgrade.step.plugin.head":`② Plugin is a manual swap. Download the latest`,"upgrade.step.plugin.tail":`, unzip it, then import the manifest for your platform`,"upgrade.step.verify":`③ Run the plugin again. No upgrade icon up top means both sides match`,"upgrade.copy":`Copy for AI assistant`,"upgrade.prompt":`I use text-to-design. Plugin text-to-design-ui is {ui}, latest {uiLatest}; service text-to-design-mcp is {mcp}, latest {mcpLatest}. Help me get both to the latest: ① check the MCP config command pins latest, then restart the AI session; ② download and unzip the latest text-to-design-ui (npm pack, or the zip from GitHub Releases), and tell me which manifest.json under dist/ to import for jsDesign / Figma / MasterGo; ③ report both version numbers when done.`,"toast.copy.done":`Copied`,"toast.copy.failed":`Copy failed`,"conn.connected":`Connected. Select nodes on the canvas, click "Copy", then paste into your AI assistant — e.g. "make me another card in this node style"`,"conn.superseded":`Another plugin panel has taken over this channel (only one panel is served at a time), so auto-reconnect has stopped. Click "Reclaim" next to the status badge to switch back to this panel.`,"conn.disconnected.title":`Not connected to the background service`,"conn.disconnected.tutorial":`Install guide`,"conn.copyAi":`① Copy prompt for AI`,"conn.copyDaemon":`② Copy start command`,"conn.copyAi.hint":`Send it to your AI so it calls jsd_ping to wake the service`,"conn.daemon.note":`Running it in a local terminal keeps the service alive until the next reboot; running it again is safe (an existing instance is skipped).`,"conn.announce.connected":`Connected to the background service`,"conn.announce.connecting":`Connecting to the background service`,"conn.announce.superseded":`Another plugin panel took over the channel`,"conn.announce.disconnected":`Not connected to the background service`,"conn.wakeCmd":`Please connect me to the text-to-design background service:
|
|
19
|
+
- 多步套路先读配方 prompt(prompts/list 里,名字无 jsd_ 前缀;取一条即把完整流程与产出标准注入上下文),别临场拼工具:画图表 / 数据可视化 → chart-by-code(折线、柱状、饼图 / 环形、散点、雷达、面积、仪表盘;自己写脚本算几何、落盘 SVG,再经 jsd_create_svg 的 svgPath 导入);HTML 转设计稿 → html-to-design;界面从零设计 → design-strategy;界面排布 / 自动布局(容器该不该上布局、两条落地路径、最易漏的分区)→ auto-layout;批量改文案 → text-replace-strategy;图标网格 → icon-grid;多步画布操作合并成一次调用 → script-ops;同类实例批量同步样式 → variant-sync;变体集构建 → variant-set;变量绑定与批量套用 → variable-binding;组件属性的定义与设值 → component-property。同一批配方也作为 MCP 资源提供:宿主若不注入本段(实测多数客户端如此),以资源为准 —— 读 jsd://recipes 取索引(含每条的何时用),读 jsd://recipes/<id> 取正文。`,"ping.title":`检查{client}插件连接`,"batch.description":'批量编排器:一次请求内顺序执行多个 jsd_* 步骤,前一步结果经双花括号占位符(内容为 步骤id.字段路径)注入后一步 args,中间 id 不回传模型,显著减少往返与上下文。\\n占位符独占一个参数值时保留原类型(数组可直接作 ids 用),嵌在字符串中按 JSON 文本展开;**占位符只在同一次调用的本批次内有效**(步骤表随调用结束即销毁,引用上一批次的步骤必报「占位符引用的步骤不存在或未成功」并中止整批 —— 跨批次请硬编码上一步回显里的真实 id);名字寻址是另一条路:`{{@comp:按钮}}` 取组件/变体集的 id、`{{@var:accent/blue}}` 取变量的 id,取值来自 jsd_get_page 的资源清单(每批最多读一次,同批复用同一份快照;精确名优先,再退忽略大小写),名字一律照清单里的**原样**写 —— 即时设计实测会把带 `/` 的组件名拆成「集合 / 成分」,`assets.components[].name` 只剩叶子名,照创建时那个路径写会不命中);零命中或多命中同名都点名中止、绝不猜(该平台读不到非当前页时清单只覆盖当前页);刚在本批里建出来的资源不在这份快照内,照旧用 {{id.created[0].id}};id 重复/未知工具/引用失败立即中止,工具执行失败默认也中止(stopOnError=false 或单步 continueOnError=true 可走完)。**清单装不下时用 `callsFile`**:给一个 JSON 文件的绝对路径(内容为 {"calls":[…]}(可带 stopOnError / checkDrift)或直接一个数组,与 calls 同形),id 就不必写进上下文 —— 该文件也能用 CLI `text-to-design-mcp exec <文件> [--json] [--dry-run]` 直接跑。\\n回显已做摘要裁剪:节点对象只留 id/name/type/x/y/width/height/z/parentId,vectorPaths(单条 >10KB、16 位小数)与 constraints 等渲染无关字段整键丢弃;裁剪后仍超 20K 字符的步骤降级为 id 清单,并把**整批完整明细**写成 JSONL 落盘(临时目录,一行一步 `{id,tool,ok,data}`),该步回显给 path 与 line(结果里 echoTrimmed=true,并附 echoNote 逐步点名);落盘超上限或写盘失败才退回纯 id 清单,warnings 点名。⚠ **批内回显不含子节点**:节点是整对象摘要化,children 与 characters / fills / *StyleId / vectorPaths 都不在回显里 —— 要读子树请读那个 JSONL 或把该工具**单独调用一次**,别当成「子节点没了 / 字段没生效」。占位符解析不受影响(内部仍用完整数据)。含图标的批次(jsd_create_icon / jsd_clone_node / jsd_create_vector)务必配一次 jsd_export 目视验收,别只看回显。\\n各工具返回键与占位符写法(键写错会报「无法解析占位符引用」并中止整批):\\n· created 为数组 → {{id.created[0].id}}:per-type create(jsd_create_rectangle / jsd_create_frame 等)、jsd_clone_node、jsd_outline_stroke、jsd_create_instance、jsd_detach_instance\\n· created 为单对象 → {{id.created.id}}:jsd_create_svg / jsd_create_icon / jsd_flatten_nodes / jsd_group_nodes / jsd_create_component / jsd_import_component / jsd_combine_as_variants / jsd_create_style\\n· jsd_find → {{id.nodes[0].id}};jsd_get_selection → {{id.selection[0].id}}\\n· 属性类 jsd_set_* → {{id.updated[0].id}};jsd_swap_component → {{id.swapped[0].id}};jsd_delete_style → {{id.removed[0]}}(id 字符串数组)\\\\n· jsd_platform_op → 回包**就是该 op 自己的返回**(没有 .data 那一层信封):figma_variables_create 取 {{id.variables[0].id}}、figma_style_variables_list 取 {{id.styles[0].boundVariables}}、mg_list_variables 取 {{id.variables[0].id}};每个 op 的返回形状写在 jsd_ping 的 platformOps 描述里\\n· jsd_manage_nodes 各 op:select→selected[](id 字符串)、remove→removed[](id 字符串)、clone/outline_stroke→created[](节点**数组**)、group/flatten→created(节点**单对象**,与 jsd_group_nodes / jsd_flatten_nodes 同形)、ungroup→ungrouped[](id 字符串)、reparent→moved[](与 updated[] 同义,两个键都回)、repair→cleaned[](id 字符串)—— id 字符串数组取 {{id.selected[0]}},节点数组取 {{id.created[0].id}},节点单对象取 {{id.created.id}}(单对象与单元素数组互认:`{{id.created[0].id}}` 与 `{{id.created.id}}` 都能解析;多元素数组直接取 `.字段` 仍中止)\\n· jsd_manage_components 各 op:create_component/create_instance/detach_instance/import_component/combine_as_variants→created(detach_instance 是数组,不是 updated)、swap_component→swapped[]、set_instance_properties→updated[]、copy_overrides→snapshotId、apply_overrides/sync_overrides→applied[]\\n· 拿不准某步的返回结构时,先单独调它一次看回显再拼进 batch —— 猜错会连带整批中止。\\n结构变更复核(默认开,checkDrift=false 可关):步骤里含 remove/reparent/group/ungroup/flatten/repair 时,变更前记下受影响父层(含 reparent 的目标父级与当前页顶层)的子节点坐标,收尾再读一次比对 —— 引擎在删改结构后会把**没碰到**的兄弟节点静默挪走(实测 (24,720)→(28,618):无报错、回显正常,渲染上像样式问题,极易走错排查方向)。漂移写进结果 warnings 并给出原值,照原值用 jsd_move_node 回填即可;覆盖面仅限本次操作触及的父层(协议没有整树读法,别的层漂移查不到)。多步套路(画图表 / 从零设计整页 / HTML 转设计稿 / 批量改文案 / 组件与变体 / 变量绑定)先读配方索引 jsd://recipes(ReadMcpResource),别临场拼工具;整页/整档的批量改造(一次调用吃多组、id 不进上下文、回读复核、按块切批)读 jsd://recipes/script-ops。\'',"manageNodes.description":`按 op 分发的节点结构操作聚合入口:select|remove|clone|group|ungroup|flatten|outline_stroke|reparent|repair。单次单操作请优先用对应小工具:jsd_select_nodes / jsd_delete_node / jsd_clone_node / jsd_group_nodes / jsd_ungroup_nodes / jsd_flatten_nodes / jsd_outline_stroke / jsd_reparent_nodes / jsd_repair_nodes(描述含平台缺陷与正确流程)。属性修改用 jsd_set_* 系列(含 jsd_set_shape);组件/实例操作用 jsd_manage_components 或 jsd_create_component / jsd_sync_overrides 等,两工具 op 不通用。\\n各 op 的返回键(在 jsd_batch 里用占位符引用时才不会写错,写错会中止整批):select→selected[](id 字符串)、remove→removed[](id 字符串)、clone/outline_stroke→created[](节点**数组**)、group/flatten→created(节点**单对象**:这两个 op 内部走的就是 jsd_group_nodes / jsd_flatten_nodes 那条路)、ungroup→ungrouped[](id 字符串)、reparent→moved[](同时附 updated[],两者同一份数组)、repair→cleaned[](id 字符串)。id 字符串数组取 {{步骤id.selected[0]}},节点数组取 {{步骤id.created[0].id}},节点单对象取 {{步骤id.created.id}}(单对象与单元素数组互认:{{步骤id.created[0].id}} 与 {{步骤id.created.id}} 都能解析;多元素数组直接取 .字段 仍中止)。'`,"createBooleanOperation.description":`创建单个 BOOLEAN_OPERATION 布尔运算节点,booleanOperation 运算方式({ops})与 children 必填且至少 2 个合并子节点。本工具只建一个根布尔节点。**name 必传且语义化**,不传会落成引擎默认名 node。建多个根节点/复杂树用 jsd_batch 编排`,"setFillColor.description":`设置填充色/渐变(fills 为 Paint 数组,整体替换非合并,需保留的现有填充项要一并传入)、混合模式与团队库填充样式。{warn}`,"setText.description":`修改文本(仅 TEXT 节点生效):**内容与排版** characters/fontSize/fontName/对齐/自适应/大小写/装饰/行高/字距、**颜色** fills/fillStyleId/blendMode、**尺寸** width/height(与 textAutoResize 搭配),以及 Figma 的截断与最大行数;位置 x/y 不在此工具,走 jsd_move_node / jsd_resize_node。字体先 jsd_list_fonts 取 fonts[] 里成对的 family + styles:family 用 fonts[].family 原样,style 用同一项的**全名**(如 SourceHanSansCN-Bold,不是简称 "Bold")——写错不报错、会静默退回默认字面,结果 warnings 会点名。要换行须 width + textAutoResize:"HEIGHT"(缺省 WIDTH_AND_HEIGHT 会按内容撑开;只给 width 不给 autoResize 会被引擎置成 NONE、高度不随内容重算 —— 这类「高度没跟着内容走」的文本,**重设一次 characters 就触发重排**(实测固定宽 200、height 回读 15 的长文本,重设后回读 82)。{warn};characters 内容覆盖在实例内也是正常生效的`,"ping.description":`检查插件是否在线(需先在{client}(即时设计或 Figma)中运行该插件并保持运行)。返回三个能力表:coreCapabilities 为核心能力(create/modify/structure/component/export/image,两平台一致);capabilities 只列平台差异超集(如 variables/componentProperties/textTruncation),即时设计通常只有 styles,Figma 还会有 variables/componentProperties 等;platformOps 列当前平台可用的特有操作(名/标题/参数说明),调 jsd_platform_op 前先读它。回包会被 daemon 缓存,后续可直接读 jsd://platform/state(不必重复 ping)`},x=[`jsdesign`,`figma`,`mastergo`],Kt={jsdesign:Gt[`platform.jsdesign`],figma:Gt[`platform.figma`],mastergo:Gt[`platform.mastergo`]},qt=h.enum(x),Jt=h.enum(Te),Yt=h.enum(De),Xt=h.object({name:h.string().describe(`schema.platform.name`),title:h.string(),description:h.string().describe(`schema.platform.description`)}),Zt=h.object({type:h.literal(`VARIABLE_ALIAS`),id:h.string()}),Qt=h.object({type:h.enum([`BOOLEAN`,`VARIANT`,`TEXT`,`INSTANCE_SWAP`,`SLOT`]),value:h.union([h.boolean(),h.string()]),preferredValues:h.array(h.object({type:h.enum([`COMPONENT`,`COMPONENT_SET`]),key:h.string()})).optional(),boundVariables:h.object({value:Zt.optional()}).optional(),variableId:h.string().optional()}),$t=h.object({type:h.enum([`BOOLEAN`,`TEXT`,`INSTANCE_SWAP`]),value:Zt}),en=h.object({visible:h.string().optional(),characters:h.string().optional(),mainComponent:h.string().optional()}),tn=h.union([h.string(),h.boolean(),Qt,$t]),nn=h.record(h.string(),h.union([Zt,h.array(Zt),h.record(h.string(),Zt)])),rn=Ct.slice(vt.length).join(`/`),an=h.object({ids:h.array(h.string()).optional().describe(`schema.inputs.ids`),name:h.string().optional().describe(`schema.inputs.name`),type:h.string().optional().describe(`节点类型过滤,支持:${vt.join(`/`)};Figma 下还可按画布里本来就有的只读类型筛(${rn}),这些类型能读不能建`),scope:h.enum(Wt).optional().describe(`查找范围:'page'=当前页(缺省)|'document'=跨页全文档(触发全量加载,大文档有一次性成本,结果 note 点名)。⚠ 读不到非当前页的平台(即时设计/MasterGo)会自动退回当前页并在 note 点名 —— 结果只含当前页,不是全文档`),recursive:h.boolean().optional().describe(`schema.inputs.recursive`),depth:h.number().optional().describe(`schema.inputs.depth`)}),on=[`create_component`,`create_instance`,`detach_instance`,`import_component`,`swap_component`,`set_instance_properties`,`combine_as_variants`,`copy_overrides`,`apply_overrides`,`sync_overrides`],sn=h.object({op:h.enum([`select`,`remove`,`clone`,`group`,`ungroup`,`flatten`,`outline_stroke`,`reparent`,`repair`],{error:e=>{let t=e.input,n=typeof t==`string`?t:``;return on.includes(n)?`"${n}" 是组件/实例操作,应使用 jsd_manage_components;本工具仅支持:select|remove|clone|group|ungroup|flatten|outline_stroke|reparent|repair`:`无效 op${n===``?`(缺省)`:` "${n}"`},本工具支持:select|remove|clone|group|ungroup|flatten|outline_stroke|reparent|repair(组件/实例操作在 jsd_manage_components)`}}).describe(`节点结构操作类型:select 设当前选中 | remove 删除(matchName 可再过滤) | clone 复制(右下偏移) | group 编组(可带 layoutMode/itemSpacing/padding* 参数) | ungroup 解组 | flatten 合并为矢量(至少 2 节点) | outline_stroke 描边转轮廓 | reparent 移到 parentId 下(缺省当前选中第一个) | repair 清理已损坏节点`),ids:h.array(h.string()).optional().describe(`节点 id 列表;除 remove/repair 外全部 op 必填(remove 缺省用当前选中)`),matchName:h.string().optional().describe(`仅 remove:在 ids(或当前选中)范围内,仅删除 name 精确匹配的节点`),name:h.string().optional().describe(`schema.inputs.name2`),layoutMode:h.enum([`NONE`,`HORIZONTAL`,`VERTICAL`]).optional().describe(`仅 group。自动布局方向:NONE=纯归组,子节点仅叠加,HORIZONTAL=水平排列,VERTICAL=垂直排列`),itemSpacing:h.number().optional().describe(`仅 group。自动布局项间距(px);primaryAxisAlignItems=SPACE_BETWEEN 时该项被忽略(子项均匀分布)`),paddingTop:h.number().optional().describe(`schema.inputs.paddingTop`),paddingRight:h.number().optional().describe(`schema.inputs.paddingRight`),paddingBottom:h.number().optional().describe(`schema.inputs.paddingBottom`),paddingLeft:h.number().optional().describe(`schema.inputs.paddingLeft`),primaryAxisSizingMode:h.enum([`FIXED`,`AUTO`]).optional().describe(`schema.inputs.primaryAxisSizingMode`),counterAxisSizingMode:h.enum([`FIXED`,`AUTO`]).optional().describe(`schema.inputs.counterAxisSizingMode`),primaryAxisAlignItems:h.enum([`MIN`,`MAX`,`CENTER`,`SPACE_BETWEEN`]).optional().describe(`仅 group。主轴对齐:MIN|MAX|CENTER|SPACE_BETWEEN;设为 SPACE_BETWEEN 时 itemSpacing 被忽略(子项均匀分布)`),counterAxisAlignItems:h.enum([`MIN`,`MAX`,`CENTER`]).optional().describe(`schema.inputs.counterAxisAlignItems`),parentId:h.string().optional().describe(`仅 reparent:目标父节点 id,缺省用当前选中第一个节点。跨父级移动保持节点绝对位置(内部自动换算成新父下的 x/y),无需手动修正;移入 auto-layout 容器时位置由布局接管`),index:h.number().optional().describe(`仅 reparent:插入位置 = children 下标(0 = 最底层,末位 = 最上层,即序列化里的 z);缺省追加到末尾(最上层)。节点已在该父级下时用它调层序;auto-layout 容器同样支持`)}).superRefine((e,t)=>{let n=n=>{t.addIssue({code:`custom`,path:[n],message:`op=${e.op} 缺少必填字段 ${n}`})},r=Array.isArray(e.ids)&&e.ids.length>0&&e.ids.every(e=>typeof e==`string`);switch(e.op){case`select`:case`clone`:case`group`:case`ungroup`:case`flatten`:case`outline_stroke`:case`reparent`:r||n(`ids`)}e.op===`flatten`&&r&&Array.isArray(e.ids)&&e.ids.length<2&&t.addIssue({code:`custom`,path:[`ids`],message:`op=flatten 至少需要 2 个节点 id`})}),cn=h.object({op:h.enum([`create_component`,`create_instance`,`detach_instance`,`import_component`,`swap_component`,`set_instance_properties`,`combine_as_variants`,`copy_overrides`,`apply_overrides`,`sync_overrides`]).describe(`组件操作类型;注意 combine_as_variants/detach_instance 在当前即时设计引擎有内部崩溃,已内置多姿势/副本兜底,仍失败时详见 jsd_manage_components 工具描述`),ids:h.array(h.string()).optional().describe(`节点 id 列表;除 import_component 外全部 op 必填(create_component 为要固化的节点,其余为实例/组件节点)`),name:h.string().optional().describe(`名称;create_component/import_component/combine_as_variants 可选`),key:h.string().optional().describe(`schema.inputs.key`),componentId:h.string().optional().describe(`schema.inputs.componentId`),properties:h.record(h.string(),tn).optional().describe(`属性名→值:变体属性传字符串(如 {"状态":"禁用"}),布尔属性传布尔,需要显式类型或换绑候选时传 {"type":"INSTANCE_SWAP","value":"1:2"}(仅 set_instance_properties 必填);属性名从 jsd_find/jsd_get_selection 返回的 variantProperties(变体)与 componentProperties(布尔/文本/换绑)里取,必须完全匹配`),sourceId:h.string().optional().describe(`源实例(INSTANCE)节点 id;copy_overrides/apply_overrides/sync_overrides 必填`),swapToSource:h.boolean().optional().describe(`套用时是否把目标实例 swap 成源组件,默认 false(swap 会丢失目标既有覆盖,需显式开启)`)}).superRefine((e,t)=>{let n=n=>{t.addIssue({code:`custom`,path:[n],message:`op=${e.op} 缺少必填字段 ${n}`})},r=Array.isArray(e.ids)&&e.ids.length>0&&e.ids.every(e=>typeof e==`string`);switch(e.op){case`create_component`:case`create_instance`:case`detach_instance`:case`swap_component`:case`set_instance_properties`:case`combine_as_variants`:r||n(`ids`);break;case`import_component`:(typeof e.key!=`string`||e.key.length===0)&&n(`key`);break;case`copy_overrides`:(typeof e.sourceId!=`string`||e.sourceId.length===0)&&n(`sourceId`);break;case`apply_overrides`:r||n(`ids`),(typeof e.sourceId!=`string`||e.sourceId.length===0)&&n(`sourceId`);break;case`sync_overrides`:r||n(`ids`),(typeof e.sourceId!=`string`||e.sourceId.length===0)&&n(`sourceId`)}e.op===`swap_component`&&typeof e.componentId!=`string`&&n(`componentId`),e.op===`set_instance_properties`&&(e.properties==null||typeof e.properties!=`object`)&&n(`properties`)}),ln=h.object({ids:h.array(h.string()).min(1).describe(`必填。要导出的节点 id 列表(数组);只导一个节点也要写成数组,如 ["123:456"]。字段名是 ids,不是 nodeId。`),format:h.enum([`PNG`,`JPG`,`SVG`,`PDF`]).optional().describe(`schema.inputs.format`),scale:h.number().optional().describe(`schema.inputs.scale`),savePath:h.string().optional().describe(`schema.inputs.savePath`),includeDataUrl:h.boolean().optional().describe(`schema.inputs.includeDataUrl`)}),un=h.object({family:h.string().optional().describe(`schema.inputs.family`),offset:h.number().int().min(0).optional().describe(`schema.inputs.offset`),limit:h.number().int().min(1).max(500).optional().describe(`schema.inputs.limit`)});h.object({});var dn=h.object({}),fn=h.object({ids:h.array(h.string()).describe(`schema.inputs.ids2`),sourcePath:h.string().describe(`schema.inputs.sourcePath`)}),pn=h.object({op:h.string().describe(`平台特有操作名(如 figma_variables_create)。先 jsd_ping 读 platformOps 名单,照名单里的名字传,不要猜`),params:h.record(h.string(),h.unknown()).optional().describe(`schema.inputs.params`)}),S=h.lazy(()=>h.object({id:h.string(),name:h.string(),type:Tt,x:h.number(),y:h.number(),width:h.number().optional(),height:h.number().optional(),rotation:h.number().optional(),opacity:h.number().optional(),visible:h.boolean().optional(),locked:h.boolean().optional(),parentId:h.string().optional(),z:h.number().optional().describe(`在父级 children 里的下标 = 绘制顺序,0 = 最底层、数值越大越靠上;判断遮挡读它,不用记数组方向`),fills:h.array(ot).optional(),strokes:h.array(ot).optional(),strokeWeight:h.number().optional(),strokeTopWeight:h.number().optional(),strokeBottomWeight:h.number().optional(),strokeLeftWeight:h.number().optional(),strokeRightWeight:h.number().optional(),strokeAlign:h.enum([`CENTER`,`INSIDE`,`OUTSIDE`]).optional(),strokeCap:h.enum([`NONE`,`ROUND`,`SQUARE`,`ARROW_LINES`,`ARROW_EQUILATERAL`]).optional(),strokeJoin:h.enum([`MITER`,`BEVEL`,`ROUND`]).optional(),dashPattern:h.array(h.number()).optional(),cornerSmoothing:h.number().optional(),blendMode:at.optional(),constraints:h.object({horizontal:ct,vertical:ct}).optional(),layoutGrids:h.array(lt).optional(),clipsContent:h.boolean().optional(),arcData:h.object({startingAngle:h.number(),endingAngle:h.number(),innerRadius:h.number()}).optional(),effects:h.array(st).optional(),cornerRadius:h.number().optional(),topLeftRadius:h.number().optional(),topRightRadius:h.number().optional(),bottomLeftRadius:h.number().optional(),bottomRightRadius:h.number().optional(),pointCount:h.number().optional(),innerRadius:h.number().optional(),layoutMode:h.enum([`NONE`,`HORIZONTAL`,`VERTICAL`]).optional(),itemSpacing:h.number().optional(),paddingTop:h.number().optional(),paddingRight:h.number().optional(),paddingBottom:h.number().optional(),paddingLeft:h.number().optional(),primaryAxisSizingMode:h.enum([`FIXED`,`AUTO`]).optional(),counterAxisSizingMode:h.enum([`FIXED`,`AUTO`]).optional(),primaryAxisAlignItems:h.enum([`MIN`,`MAX`,`CENTER`,`SPACE_BETWEEN`]).optional(),counterAxisAlignItems:h.enum([`MIN`,`MAX`,`CENTER`]).optional(),layoutGrow:h.number().optional(),layoutAlign:h.enum([`MIN`,`CENTER`,`MAX`,`STRETCH`,`INHERIT`]).optional(),childCount:h.number().optional(),children:h.array(S).optional(),characters:h.string().optional(),fontSize:h.number().optional(),fontName:dt.optional(),textAlignHorizontal:h.enum([`LEFT`,`CENTER`,`RIGHT`,`JUSTIFIED`]).optional(),textAlignVertical:h.enum([`TOP`,`CENTER`,`BOTTOM`]).optional(),textAutoResize:h.enum([`NONE`,`WIDTH_AND_HEIGHT`,`HEIGHT`,`TRUNCATE`]).optional(),textCase:h.enum([`ORIGINAL`,`UPPER`,`LOWER`,`TITLE`]).optional(),textDecoration:h.enum([`NONE`,`UNDERLINE`,`STRIKETHROUGH`]).optional(),lineHeight:ft.optional(),letterSpacing:pt.optional(),vectorPaths:h.array(ut).optional(),booleanOperation:h.enum(qe).optional(),isMask:h.boolean().optional(),variantProperties:h.record(h.string(),h.string()).optional(),mainComponentId:h.string().optional(),variantGroupProperties:h.record(h.string(),h.array(h.string())).optional(),textTruncation:h.enum([`DISABLED`,`ENDING`]).optional(),maxLines:h.number().optional(),fillStyleId:h.string().optional(),strokeStyleId:h.string().optional(),textStyleId:h.string().optional(),effectStyleId:h.string().optional(),componentProperties:h.record(h.string(),Qt).optional(),componentPropertyReferences:en.optional(),boundVariables:nn.optional()})),mn=h.object({created:h.union([S,h.array(S)]),warnings:h.array(h.string()).optional()}),hn=h.object({updated:h.array(S),warnings:h.array(h.string()).optional()}),gn=h.object({connected:h.boolean(),platform:qt.optional(),capabilities:h.array(Jt).optional().describe(`schema.results.capabilities`),coreCapabilities:h.array(Yt).optional().describe(`所有平台都具备的核心能力(create/modify/structure/component/export/image),不随平台变化`),platformOps:h.array(Xt).optional().describe(`当前平台可用的特有操作名单(名/标题/参数说明)。调用 jsd_platform_op 前先看这里,不要猜 op 名`),error:h.string().optional()}),_n=h.object({selection:h.array(S),pageName:h.string()}),vn=h.object({nodes:h.array(S),total:h.number(),scope:h.enum(Wt).optional(),note:h.string().optional()}),yn=h.object({selected:h.array(h.string()).optional(),removed:h.array(h.string()).optional(),ungrouped:h.array(h.string()).optional(),moved:h.array(S).optional(),updated:h.array(S).optional(),cleaned:h.array(h.string()).optional(),created:h.union([S,h.array(S)]).optional(),warnings:h.array(h.string()).optional()}),bn=h.object({variantProperties:h.record(h.string(),h.string()).optional(),componentProperties:h.record(h.string(),Qt).optional(),propsSummary:h.array(h.string()).optional()}),xn=h.object({instanceId:h.string(),instanceName:h.string(),ok:h.boolean(),message:h.string().optional()}),Sn=h.object({created:h.union([S,h.array(S)]).optional(),swapped:h.array(S).optional(),updated:h.array(S).optional(),snapshotId:h.string().optional(),sourceName:h.string().optional(),captured:bn.optional(),applied:h.array(xn).optional(),source:bn.optional(),failed:h.array(h.object({id:h.string(),message:h.string()})).optional(),warnings:h.array(h.string()).optional()}),Cn=h.object({exports:h.array(h.object({id:h.string(),name:h.string(),format:h.enum([`PNG`,`JPG`,`SVG`,`PDF`]),mimeType:h.string(),size:h.number(),path:h.string().optional(),dataUrl:h.string().optional()}))}),wn=h.object({families:h.array(h.string()).describe(`schema.results.families`),fonts:h.array(h.object({family:h.string().describe(`schema.results.family`),styles:h.array(h.string()).describe(`schema.results.styles`)})).optional().describe(`family → 可用 style 明细。写 fontName 前照这份清单取组合(family+style 需精确匹配,猜错会静默退回默认字重)`),count:h.number().describe(`schema.results.count`),total:h.number().optional().describe(`schema.results.total`),offset:h.number().optional().describe(`schema.results.offset`),truncated:h.boolean().optional().describe(`schema.results.truncated`)}),Tn=h.object({id:h.string(),name:h.string()}),En=Tn.extend({properties:h.record(h.string(),h.array(h.string())).optional().describe(`维度 → 可选值,如 {"状态":["默认","禁用"]};平台读不到该字段时整个键省略`)}),Dn=Tn.extend({type:h.enum([`PAINT`,`TEXT`,`EFFECT`,`GRID`])}),On=h.object({summary:h.object({components:h.number(),variants:h.number(),styles:h.number(),variables:h.number()}),components:h.array(Tn),variants:h.array(En),styles:h.array(Dn),variables:h.array(Tn)}),kn=h.object({pageName:h.string(),nodes:h.array(h.object({id:h.string(),name:h.string(),type:Tt,x:h.number(),y:h.number(),width:h.number().optional(),height:h.number().optional()})),count:h.number(),assets:On.optional(),pages:h.array(h.object({name:h.string(),childCount:h.number()})).optional(),note:h.string().optional()});h.object({styles:h.array(h.object({id:h.string(),name:h.string(),type:h.enum(Ae)})),count:h.number(),note:h.string().optional()});var An=h.object({created:h.object({id:h.string(),name:h.string(),type:h.enum(Ae)})}),jn=h.object({removed:h.array(h.string()),failed:h.array(h.object({id:h.string(),reason:h.string().describe(`这一条没删掉的原因(通常是样式 id 不存在)`)}))}),C=h.object({x:h.number().optional().describe(`X 坐标(px,相对父节点;auto-layout 子节点的位置由父容器接管,修改可能被布局覆盖)`),y:h.number().optional().describe(`Y 坐标(px,相对父节点;auto-layout 子节点的位置由父容器接管,修改可能被布局覆盖)`),width:h.number().optional().describe(`schema.sharedProps.width`),height:h.number().optional().describe(`schema.sharedProps.height`),rotation:h.number().optional().describe(`schema.sharedProps.rotation`),opacity:h.number().optional().describe(`schema.sharedProps.opacity`),visible:h.boolean().optional(),locked:h.boolean().optional()}),Mn=h.object({width:h.number().min(0).optional().describe(`宽度(px)。横线(高度为 0 的 LINE)传 0;其他类型最低 0.01(引擎 resize 校验),低于会明确报错`),height:h.number().min(0).optional().describe(`高度(px)。竖线(宽度为 0 的 LINE)传 0;其他类型最低 0.01(引擎 resize 校验),低于会明确报错`)}),Nn=h.object({pointCount:h.number().optional().describe(`schema.sharedProps.pointCount`),innerRadius:h.number().optional().describe(`schema.sharedProps.innerRadius`)}),Pn=h.object({strokes:h.array(ot).optional().describe(`schema.sharedProps.strokes`),strokeWeight:h.number().optional().describe(`schema.sharedProps.strokeWeight`),strokeTopWeight:h.number().optional().describe(`schema.sharedProps.strokeTopWeight`),strokeBottomWeight:h.number().optional().describe(`schema.sharedProps.strokeBottomWeight`),strokeLeftWeight:h.number().optional().describe(`schema.sharedProps.strokeLeftWeight`),strokeRightWeight:h.number().optional().describe(`schema.sharedProps.strokeRightWeight`),strokeAlign:h.enum([`CENTER`,`INSIDE`,`OUTSIDE`]).optional().describe(`schema.sharedProps.strokeAlign`),strokeCap:h.enum([`NONE`,`ROUND`,`SQUARE`,`ARROW_LINES`,`ARROW_EQUILATERAL`]).optional().describe(`schema.sharedProps.strokeCap`),strokeJoin:h.enum([`MITER`,`BEVEL`,`ROUND`]).optional().describe(`schema.sharedProps.strokeJoin`),dashPattern:h.array(h.number()).optional().describe(`schema.sharedProps.dashPattern`),strokeStyleId:h.string().optional().describe(`schema.sharedProps.strokeStyleId`)}),Fn=h.object({cornerRadius:h.number().optional().describe(`圆角半径(px),四角统一;仅 FRAME/RECTANGLE/ELLIPSE/POLYGON/STAR/VECTOR/BOOLEAN_OPERATION 生效(LINE/TEXT 无圆角)`),topLeftRadius:h.number().optional().describe(`schema.sharedProps.topLeftRadius`),topRightRadius:h.number().optional().describe(`schema.sharedProps.topRightRadius`),bottomLeftRadius:h.number().optional().describe(`schema.sharedProps.bottomLeftRadius`),bottomRightRadius:h.number().optional().describe(`schema.sharedProps.bottomRightRadius`)}),In=h.object({characters:h.string().optional().describe(`schema.sharedProps.characters`),fontSize:h.number().optional().describe(`schema.sharedProps.fontSize`),fontName:dt.optional().describe(`字体:{family,style};需精确匹配,建议先用 jsd_list_fonts 查可用字体(不可用时静默回退默认字体)`),textAlignHorizontal:h.enum([`LEFT`,`CENTER`,`RIGHT`,`JUSTIFIED`]).optional().describe(`schema.sharedProps.textAlignHorizontal`),textAlignVertical:h.enum([`TOP`,`CENTER`,`BOTTOM`]).optional().describe(`schema.sharedProps.textAlignVertical`),textAutoResize:h.enum([`NONE`,`WIDTH_AND_HEIGHT`,`HEIGHT`,`TRUNCATE`]).optional().describe(`文本自适应:NONE=固定尺寸|WIDTH_AND_HEIGHT=按内容撑开(缺省,此时修改 width/height 会被覆盖)|HEIGHT=固定宽自适应高|TRUNCATE=截断。要固定文本框尺寸必须设为 NONE`),textCase:h.enum([`ORIGINAL`,`UPPER`,`LOWER`,`TITLE`]).optional().describe(`schema.sharedProps.textCase`),textDecoration:h.enum([`NONE`,`UNDERLINE`,`STRIKETHROUGH`]).optional().describe(`schema.sharedProps.textDecoration`),lineHeight:ft.optional().describe(`schema.sharedProps.lineHeight`),letterSpacing:pt.optional().describe(`schema.sharedProps.letterSpacing`),textStyleId:h.string().optional().describe(`schema.sharedProps.textStyleId`),textTruncation:h.enum([`DISABLED`,`ENDING`]).optional().describe(`schema.sharedProps.textTruncation`),maxLines:h.number().optional().describe(`schema.sharedProps.maxLines`)}),Ln=h.object({layoutMode:h.enum([`NONE`,`HORIZONTAL`,`VERTICAL`]).optional().describe(`自动布局方向:NONE|HORIZONTAL|VERTICAL,FRAME / COMPONENT / COMPONENT_SET 生效。传 itemSpacing/padding*/primaryAxis* 等布局属性前必须先设为 HORIZONTAL 或 VERTICAL`),itemSpacing:h.number().optional().describe(`自动布局项间距(px);primaryAxisAlignItems=SPACE_BETWEEN 时该项被忽略(子项均匀分布)`),paddingTop:h.number().optional().describe(`schema.sharedProps.paddingTop`),paddingRight:h.number().optional().describe(`schema.sharedProps.paddingRight`),paddingBottom:h.number().optional().describe(`schema.sharedProps.paddingBottom`),paddingLeft:h.number().optional().describe(`schema.sharedProps.paddingLeft`),primaryAxisSizingMode:h.enum([`FIXED`,`AUTO`]).optional().describe(`schema.sharedProps.primaryAxisSizingMode`),counterAxisSizingMode:h.enum([`FIXED`,`AUTO`]).optional().describe(`schema.sharedProps.counterAxisSizingMode`),primaryAxisAlignItems:h.enum(Ne).optional().describe(`主轴对齐:MIN|MAX|CENTER|SPACE_BETWEEN;设为 SPACE_BETWEEN 时 itemSpacing 被忽略(子项均匀分布)`),counterAxisAlignItems:h.enum(Pe).optional().describe(`schema.sharedProps.counterAxisAlignItems`),layoutGrow:h.number().optional().describe(`schema.sharedProps.layoutGrow`),layoutAlign:h.enum(Me).optional().describe(`schema.sharedProps.layoutAlign`)}),w=h.object({fills:h.array(ot).optional().describe(`填充列表(Paint 数组;整体替换,非合并,需保留的现有填充项要一并传入)`),fillStyleId:h.string().optional().describe(`schema.sharedProps.fillStyleId`),blendMode:at.optional(),effectStyleId:h.string().optional().describe(`schema.sharedProps.effectStyleId`),effects:h.array(st).optional().describe(`schema.sharedProps.effects`),constraints:h.object({horizontal:ct.describe(`水平约束:MIN|MAX|STRETCH|CENTER|SCALE`),vertical:ct.describe(`垂直约束:MIN|MAX|STRETCH|CENTER|SCALE`)}).optional().describe(`schema.sharedProps.vertical`),clipsContent:h.boolean().optional().describe(`schema.sharedProps.clipsContent`),cornerSmoothing:h.number().optional().describe(`schema.sharedProps.cornerSmoothing`),layoutGrids:h.array(lt).optional().describe(`schema.sharedProps.layoutGrids`),arcData:h.object({startingAngle:h.number().describe(`schema.sharedProps.startingAngle`),endingAngle:h.number().describe(`schema.sharedProps.endingAngle`),innerRadius:h.number().describe(`schema.sharedProps.innerRadius2`)}).optional().describe(`schema.sharedProps.innerRadius3`)}),Rn={ids:h.array(h.string()).min(1).optional().describe(`schema.splitOps.ids`),matchName:h.string().optional().describe(`schema.splitOps.matchName`),recursive:h.boolean().optional().describe(`是否递归应用到子树,默认 false。recursive 只作用于**后代**,不含目标节点自身:给容器 FRAME 传它刷色,容器自己不会被改(容器自身加描边会渲染成方框)。目标是无子节点的叶子时,自身即整棵子树,仍会改。要把容器自己也算进去再传 includeSelf=true`),includeSelf:h.boolean().optional().describe(`仅 recursive=true 时有意义:是否连目标节点自身一起改,默认 false。传 true 且目标是容器时结果会带 warnings 点名「容器自身也被修改」`)},T=(e,t=1)=>h.array(h.string()).min(t).describe(e),zn=h.object({ids:T(`要设为当前选中的节点 id 列表`)}).strict(),Bn=h.object({ids:h.array(h.string()).optional().describe(`schema.splitOps.ids2`),matchName:h.string().optional().describe(`schema.splitOps.matchName2`)}).strict(),Vn=h.object({ids:T(`要复制的节点 id 列表(新副本右下偏移放置)`)}).strict(),Hn=h.object({ids:T(`要编组的节点 id 列表,至少 2 个`,2),name:h.string().optional().describe(`schema.splitOps.name`),layoutMode:h.enum([`NONE`,`HORIZONTAL`,`VERTICAL`]).optional().describe(`自动布局方向:NONE=纯归组(子节点仅叠加,不排布),HORIZONTAL=水平排列,VERTICAL=垂直排列`),itemSpacing:h.number().optional().describe(`自动布局项间距(px);primaryAxisAlignItems=SPACE_BETWEEN 时该项被忽略(子项均匀分布)`),paddingTop:h.number().optional().describe(`schema.splitOps.paddingTop`),paddingRight:h.number().optional().describe(`schema.splitOps.paddingRight`),paddingBottom:h.number().optional().describe(`schema.splitOps.paddingBottom`),paddingLeft:h.number().optional().describe(`schema.splitOps.paddingLeft`),primaryAxisSizingMode:h.enum([`FIXED`,`AUTO`]).optional().describe(`schema.splitOps.primaryAxisSizingMode`),counterAxisSizingMode:h.enum([`FIXED`,`AUTO`]).optional().describe(`schema.splitOps.counterAxisSizingMode`),primaryAxisAlignItems:h.enum([`MIN`,`MAX`,`CENTER`,`SPACE_BETWEEN`]).optional().describe(`主轴对齐:MIN|MAX|CENTER|SPACE_BETWEEN;设为 SPACE_BETWEEN 时 itemSpacing 被忽略(子项均匀分布)`),counterAxisAlignItems:h.enum([`MIN`,`MAX`,`CENTER`]).optional().describe(`schema.splitOps.counterAxisAlignItems`)}).strict(),Un=h.object({ids:T(`要解组的节点 id 列表`)}).strict(),Wn=h.object({ids:T(`要合并为单一矢量的节点 id 列表,至少 2 个`,2)}).strict(),Gn=h.object({ids:T(`要把描边转成轮廓矢量的节点 id 列表`)}).strict(),Kn=h.object({ids:T(`要移动的节点 id 列表`),parentId:h.string().optional().describe(`目标父节点 id。**强烈建议显式传**:只给 index 不给 parentId 时,缺省父级取「当前选中里第一个不是被移动节点的节点」——当前选中为空或不含父容器时该值不可靠(历史上因此报过「没有找到目标父节点」,或把节点误移进另一个被选中的节点下)。不传 parentId 的可用姿势:①先用 jsd_select_nodes 选中目标容器;②只给 index 且 ids 里含被调整节点本身 → 按被调整节点的原父级在此处调层序。跨父级移动**保持节点绝对位置**:内部按页面系记账并自动换算成新父下的 x/y,不要按「相对系重解释」手动摆回(那会把节点推走)。唯一例外是移入 auto-layout 容器 —— 位置由布局接管,要调排布改 itemSpacing / 对齐`),index:h.number().optional().describe(`目标在父节点 children 数组里的最终下标;缺省追加到末尾。语义 = 绘制顺序(也就是序列化里的 z):0 是最底层,末位是最上层。节点已在该父级下时,本参数用于调整层序(不传则原地不动);auto-layout 容器同样支持(内部临时关掉布局插入后恢复),若引擎没落位会明确报错`)}).strict(),qn=h.object({ids:h.array(h.string()).optional().describe(`schema.splitOps.ids3`)}).strict(),Jn=h.object({ids:h.array(h.string()).optional().describe(`要固化为组件的节点 id 列表;给了就先校验存在(不改动这些节点)`),name:h.string().optional().describe(`schema.splitOps.name2`),children:h.array(Et).max(100).optional().describe(`组件内容:子节点数组(递归嵌套,最多 100 个直接子节点),字段与 jsd_create_frame 的 children 一致;给了就一次建成带内容的组件,不必再 reparent 搬子节点`),width:h.number().optional().describe(`组件宽度(px);在子节点插完之后压,避免被布局重算吃掉`),height:h.number().optional().describe(`组件高度(px);同上`)}).strict(),Yn=h.object({ids:T(`要生成实例的组件(COMPONENT)节点 id 列表`)}).strict(),Xn=h.object({ids:T(`要取消实例链接的实例(INSTANCE)节点 id 列表`)}).strict(),Zn=h.object({key:h.string().describe(`schema.splitOps.key`),name:h.string().optional().describe(`schema.splitOps.name3`)}).strict(),Qn=h.object({ids:T(`要换绑的实例(INSTANCE)节点 id 列表`),componentId:h.string().describe(`schema.splitOps.componentId`)}).strict(),$n=h.object({ids:T(`要设置变体/组件属性的实例(INSTANCE)节点 id 列表`),properties:h.record(h.string(),tn).describe('属性名→值:变体属性传字符串(如 {"状态":"禁用"}),布尔属性传布尔(如 {"显示图标":false}),需要显式类型或换绑候选时传 {"type":"INSTANCE_SWAP","value":"1:2"}。属性名取 jsd_find / jsd_get_selection 的 variantProperties(变体)与 componentProperties(布尔/文本/换绑):**变体属性传名字即可;组件属性传带 `#` 后缀的完整键**(如 `标题#32:0`)—— 组件属性在引擎侧只认完整键,短名会报 `Could not find a component property with name`(真机实测,三种类型都如此)。传短名时 core 只在基名**唯一**命中时替你补全,有歧义直接报错并列出候选,不做猜测。**选哪个键之前先读 componentPropertyReferences**:它标明「哪个图层由哪个属性驱动」,属性成对存在时只有连着可见层的那一组会改画面')}).strict(),er=h.object({ids:T(`要合并为变体集(分量)的组件(COMPONENT)节点 id 列表;实例不能直接合成,须先 jsd_detach_instance 或重建为组件`),name:h.string().optional().describe(`schema.splitOps.name4`)}).strict(),tr=h.object({kind:h.enum(Ae).describe("样式类别。八项是三家 `StyleType` 的并集:**PAINT / TEXT / EFFECT / GRID 三家都有**;`STROKE_WIDTH / CORNER_RADIUS / PADDING / SPACING` **只 MasterGo 能建**—— 在 Figma / 即时设计传这四类会被写前点名拒(不静默、不 fallthrough 建成别的类)。MG 上和另四类一样是「从取值节点抄」,所以间距类要那节点是自动布局容器、圆角类要它真有圆角,读不出值时前置检查就会拦下"),name:h.string().min(1).describe("样式名,建议用「分组/名称」两层(如 `色板/主色`)"),description:h.string().optional().describe(`样式说明,建后可在 jsd://styles 里回读`),fromNodeId:h.string().describe(`**取值来源节点**(必填):三平台唯一都成立的形状 —— MG 的原生入口就是「从这个图层抄」,Figma / jsDesign 由本仓把该节点的 fills / effects / layoutGrids / 文本排版字段灌进新样式。PAINT 类 fills 优先,节点只有描边时退到 strokes`)}).strict(),nr=h.object({ids:h.array(h.string().min(1)).min(1).describe(`要删的本地样式 id 列表(取自 jsd://styles 或 jsd_get_page 的 assets.styles);按 id 不按名 —— 同名样式可以并存,按名删等于猜`)}).strict(),rr=h.object({sourceId:h.string().describe(`源实例(INSTANCE)节点 id,要复制其覆盖(变体/组件属性/可见样式文本)`)}).strict(),ir={ids:T(`要套用覆盖快照的目标实例(INSTANCE)节点 id 列表`),sourceId:h.string().describe(`schema.splitOps.sourceId`),swapToSource:h.boolean().optional().describe(`套用时是否把目标实例 swap 成源组件,默认 false(swap 会丢失目标既有覆盖,需显式开启)`)},ar=h.object(ir).strict(),or=h.object(ir).strict(),sr={fills:w.shape.fills,fillStyleId:w.shape.fillStyleId,blendMode:w.shape.blendMode},cr={...Pn.shape},lr={cornerRadius:Fn.shape.cornerRadius,topLeftRadius:Fn.shape.topLeftRadius,topRightRadius:Fn.shape.topRightRadius,bottomLeftRadius:Fn.shape.bottomLeftRadius,bottomRightRadius:Fn.shape.bottomRightRadius,cornerSmoothing:w.shape.cornerSmoothing},ur={...In.shape,fills:w.shape.fills,fillStyleId:w.shape.fillStyleId,blendMode:w.shape.blendMode,width:Mn.shape.width,height:Mn.shape.height},dr={x:C.shape.x,y:C.shape.y,rotation:C.shape.rotation},fr={...Mn.shape,x:C.shape.x,y:C.shape.y},pr={...Ln.shape,constraints:w.shape.constraints},mr={effects:w.shape.effects,effectStyleId:w.shape.effectStyleId,clipsContent:w.shape.clipsContent,layoutGrids:w.shape.layoutGrids,arcData:w.shape.arcData},hr={opacity:C.shape.opacity,visible:C.shape.visible,locked:C.shape.locked},gr={name:h.string().describe(`schema.splitOps.name5`)},_r={...Nn.shape};function E(e){return h.object({...Rn,...e}).strict()}var vr=E(sr),yr=E(cr),br=E(lr),xr=E(ur),Sr=E(dr),Cr=E(fr),wr=E(pr),Tr=E(mr),Er=E(hr),Dr=E(gr),Or=E(_r),kr={set_fill:Object.keys(sr),set_stroke:Object.keys(cr),set_corner_radius:Object.keys(lr),set_text:Object.keys(ur),move:Object.keys(dr),resize:Object.keys(fr),set_layout:Object.keys(pr),set_effects:Object.keys(mr),set_visibility:Object.keys(hr),rename:Object.keys(gr),set_shape:Object.keys(_r)};function D(e){return h.object({...Rn,props:h.object(e).strict()}).strict()}D(sr),D(cr),D(lr),D(ur),D(dr),D(fr),D(pr),D(mr),D(hr),D(gr),D(_r);function Ar(e,t,n){let r=e.ctx.platform;return r==null?null:He(r,t,e.node.type)?Ve(r,t,n)?null:`value`:`type`}function jr(e,t,n){let r=Ar(e,t,n);if(r==null)return!0;let i=e.ctx.platform;if(i==null)return!0;let a=Kt[i];if(e.outcome.ignored.add(t),r===`type`)return e.outcome.warnings.push(`${t} 在 ${a} 的「${e.node.type}」上没有对应字段(该平台的这类节点不含这个属性的 mixin),本次已跳过:不是写失败,是这种节点上不存在该属性。要用它就换本平台支持该属性的节点类型;不去写的话结果里不会再回显它。`),!1;let o=Ue(i,t)??`该取值本平台无法表达`;return e.outcome.warnings.push(`${t} 的值 ${JSON.stringify(n)} 无法在 ${a} 表达(${o}),本次已跳过:不是写失败,是平台没有这个取值。请改用本平台支持的取值,或把该差异留给调用方处理。`),!1}function Mr(e,t){return e[t]}function Nr(e,t,n){e[t]=n}function Pr(e,t,n){return n==null||!(t in e)?!1:(Nr(e,t,n),!0)}function Fr(e,t,n,r){return Ir(e,t,n,r)?Pr(t,n,r):!1}function Ir(e,t,n,r){return!(r==null||!ke(n,t.type)||!jr(e,n,r))}var Lr={id:`layout`,keys:[`layoutMode`,`itemSpacing`,`paddingTop`,`paddingRight`,`paddingBottom`,`paddingLeft`,`primaryAxisSizingMode`,`counterAxisSizingMode`,`primaryAxisAlignItems`,`counterAxisAlignItems`],write(e){let{node:t,src:n,create:r}=e,i=n.layoutMode;if(i!=null&&Br(t),r){if(i==null)return;Fr(e,t,`layoutMode`,i);let r=n;Fr(e,t,`itemSpacing`,r.itemSpacing??0);for(let n of[`paddingTop`,`paddingRight`,`paddingBottom`,`paddingLeft`])Fr(e,t,n,r[n]??0);for(let n of[`primaryAxisAlignItems`,`counterAxisAlignItems`])Fr(e,t,n,r[n]);Ur(e);return}for(let r of Lr.keys)Fr(e,t,r,n[r])},settle(e){let{node:t,src:n}=e;for(let r of[`primaryAxisAlignItems`,`counterAxisAlignItems`]){let i=n[r];i!=null&&ke(r,t.type)&&Ar(e,r,i)==null&&(r in t&&t[r]!==i&&Nr(t,r,i),e.outcome.readback.push({key:r,ok:!(r in t)||t[r]===i}))}for(let r of[`itemSpacing`,`paddingTop`,`paddingRight`,`paddingBottom`,`paddingLeft`]){let i=n[r],a=i;e.create&&(a=n.layoutMode==null?void 0:i??0),a!=null&&ke(r,t.type)&&Ar(e,r,a)==null&&(r in t&&Mr(t,r)!==a&&Nr(t,r,a),e.outcome.readback.push({key:r,ok:!(r in t)||Mr(t,r)===a}))}for(let r of[`primaryAxisSizingMode`,`counterAxisSizingMode`]){let i=n[r];i!=null&&(e.create&&n.layoutMode==null||ke(r,t.type)&&Ar(e,r,i)==null&&(r in t&&Mr(t,r)!==i&&Nr(t,r,i),e.outcome.readback.push({key:r,ok:!(r in t)||Mr(t,r)===i})))}if(n.layoutMode==null||!ke(`layoutMode`,t.type))return;let r=n.layoutMode;`layoutMode`in t&&t.layoutMode!==r&&(t.layoutMode=r);let i=!(`layoutMode`in t)||t.layoutMode===r;e.outcome.readback.push({key:`layoutMode`,ok:i})}};function Rr(e){try{let t=e.children;return Array.isArray(t)?t.map(e=>e.id):[]}catch{return[]}}var zr=new WeakMap;function Br(e){let t=e;zr.set(e,{order:Rr(e),width:typeof t.width==`number`?t.width:void 0,height:typeof t.height==`number`?t.height:void 0})}var Vr=new WeakMap;function Hr(e,t){let n=Vr.get(e)??new Set;n.add(t),Vr.set(e,n)}function Ur(e){let{node:t,src:n}=e;if(n.layoutMode==null)return;let r=Wr(n,e.outermost),i=n.layoutMode===`HORIZONTAL`;for(let e of[`primaryAxisSizingMode`,`counterAxisSizingMode`]){let a=r[e];a!=null&&n[e]==null&&e in t&&(Nr(t,e,a),a===`AUTO`&&Hr(t,e===`primaryAxisSizingMode`===i?`width`:`height`))}}function Wr(e,t){let n=e.layoutMode;if(n!==`HORIZONTAL`&&n!==`VERTICAL`)return{};let r=n===`HORIZONTAL`,i=e=>e===`height`&&!t?`AUTO`:`FIXED`,a={};return(r?e.width!=null:e.height!=null)&&(a.primaryAxisSizingMode=i(r?`width`:`height`)),(r?e.height!=null:e.width!=null)&&(a.counterAxisSizingMode=i(r?`height`:`width`)),a}Object.keys(Ee).filter(e=>e!==`componentProperties`);var Gr=new Set(`fills.strokes.strokeWeight.strokeTopWeight.strokeBottomWeight.strokeLeftWeight.strokeRightWeight.strokeAlign.strokeCap.strokeJoin.dashPattern.blendMode.effects.cornerRadius.topLeftRadius.topRightRadius.bottomLeftRadius.bottomRightRadius.cornerSmoothing.fontName.fontSize.lineHeight.letterSpacing.textCase.textDecoration.textAlignHorizontal.textAlignVertical`.split(`.`));new Set([...new Set([`fills`,`strokes`,`strokeWeight`,`strokeTopWeight`,`strokeBottomWeight`,`strokeLeftWeight`,`strokeRightWeight`,`strokeAlign`,`strokeCap`,`strokeJoin`,`dashPattern`,`blendMode`,`effects`,`cornerRadius`,`topLeftRadius`,`topRightRadius`,`bottomLeftRadius`,`bottomRightRadius`,`cornerSmoothing`,`clipsContent`,`layoutGrids`,`arcData`])].filter(e=>Gr.has(e)));function Kr(){return[`⚠ 对位于 INSTANCE 内的子节点改样式有平台风险:回显是新值,渲染却可能仍是组件原样式(实测 ${[...Gr].slice(0,2).join(` / `)},其余样式同类风险);`,`命中时本次结果会带 warnings 并给出主组件里对应子节点的 id —— 改它即所有实例继承;`,`只要单个实例不同,先 jsd_detach_instance 再改。`].join(``)}var qr={"zh-CN":Gt,en:{"platform.jsdesign":`jsDesign`,"platform.figma":`Figma`,"platform.mastergo":`MasterGo`,"capability.core.create":`Create`,"capability.core.modify":`Modify`,"capability.core.structure":`Structure`,"capability.core.component":`Component`,"capability.core.export":`Export`,"capability.core.image":`Image fill`,"capability.host.styles":`Local styles`,"capability.host.styleEnumeration":`Local style listing (can enumerate which styles exist)`,"capability.host.styleEnumerationSync":`Style enumeration uses the sync entry (runtime *Async members are unusable)`,"capability.host.mainComponentSync":`Main component read via the sync field (runtime getMainComponentAsync never settles)`,"capability.host.textTruncation":`Text truncation`,"capability.host.componentProperties":`Component properties`,"capability.host.documentScopeRead":`Document-scope read (can read pages other than the current one)`,"capability.host.variables":`Variables`,"capability.host.inPlaceVariants":`In-place variants`,"locale.system":`System`,"locale.zh-CN":`中文`,"locale.en":`English`,"locale.abbr.zh-CN":`中`,"locale.abbr.en":`EN`,"locale.menu":`Language`,"locale.title.followSystem":`Language: follow system (currently {locale})`,"locale.title.fixed":`Language: {locale}`,"status.connected.label":`Connected`,"status.connected.title":`Service is online; plugin and AI session are connected`,"status.connecting.label":`Connecting…`,"status.connecting.title":`Connected to the background service; waiting for it to confirm this channel`,"status.waiting.label":`Waiting`,"status.waiting.title":`No manual action needed while the service is offline — an AI call starts it`,"status.superseded.label":`Taken over`,"status.superseded.title":`Another plugin panel holds the channel; click "Reclaim" to switch back to this panel`,"header.retry":`Retry`,"header.retry.title":`Reconnect to the background service now instead of waiting for the backoff`,"header.reclaim":`Reclaim`,"header.reclaim.title":`Reclaim the channel from the other plugin panel`,"header.theme.toDark":`Switch to dark theme`,"header.theme.toLight":`Switch to light theme`,"header.cameraLock.locked":`Camera locked`,"header.cameraLock.unlocked":`Camera follows`,"header.cameraLock.title.locked":`Camera locked: canvas operations do not move your viewport (click to follow)`,"header.cameraLock.title.unlocked":`Camera follows: canvas operations scroll and zoom to the result (click to lock)`,"header.minimize":`Minimize`,"header.minimize.title":`Minimize the panel to just the logo; double-click the logo to restore`,"header.restore.title":`Double-click the logo to restore the panel`,"upgrade.title":`A newer version is available (click for upgrade steps)`,"upgrade.modal.title":`Upgrade to the latest version`,"upgrade.current":`Current {version}`,"upgrade.latest":`Latest {version}`,"upgrade.plugin.label":`Plugin`,"upgrade.service.label":`Service`,"upgrade.step.service":`① Service, just restart the AI session. It runs npx -y text-to-design-mcp@latest, so it is always the newest`,"upgrade.step.plugin.head":`② Plugin is a manual swap. Download the latest`,"upgrade.step.plugin.tail":`, unzip it, then import the manifest for your platform`,"upgrade.step.verify":`③ Run the plugin again. No upgrade icon up top means both sides match`,"upgrade.copy":`Copy for AI assistant`,"upgrade.prompt":`I use text-to-design. Plugin text-to-design-ui is {ui}, latest {uiLatest}; service text-to-design-mcp is {mcp}, latest {mcpLatest}. Help me get both to the latest: ① check the MCP config command pins latest, then restart the AI session; ② download and unzip the latest text-to-design-ui (npm pack, or the zip from GitHub Releases), and tell me which manifest.json under dist/ to import for jsDesign / Figma / MasterGo; ③ report both version numbers when done.`,"toast.copy.done":`Copied`,"toast.copy.failed":`Copy failed`,"conn.connected":`Connected. Select nodes on the canvas, click "Copy", then paste into your AI assistant — e.g. "make me another card in this node style"`,"conn.superseded":`Another plugin panel has taken over this channel (only one panel is served at a time), so auto-reconnect has stopped. Click "Reclaim" next to the status badge to switch back to this panel.`,"conn.disconnected.title":`Not connected to the background service`,"conn.disconnected.tutorial":`Install guide`,"conn.copyAi":`① Copy prompt for AI`,"conn.copyDaemon":`② Copy start command`,"conn.copyAi.hint":`Send it to your AI so it calls jsd_ping to wake the service`,"conn.daemon.note":`Running it in a local terminal keeps the service alive until the next reboot; running it again is safe (an existing instance is skipped).`,"conn.announce.connected":`Connected to the background service`,"conn.announce.connecting":`Connecting to the background service`,"conn.announce.superseded":`Another plugin panel took over the channel`,"conn.announce.disconnected":`Not connected to the background service`,"conn.wakeCmd":`Please connect me to the text-to-design background service:
|
|
20
20
|
|
|
21
21
|
1. If the MCP server is not registered yet: register a stdio MCP server the native way for your tool,
|
|
22
22
|
with the command \`npx -y text-to-design-mcp@latest\` (no manual install; npx fetches and runs it).
|
|
@@ -34,8 +34,8 @@ import{createRequire as e}from"node:module";import{appendFileSync as t,mkdirSync
|
|
|
34
34
|
- ok=false or "node X not found": first jsd_find to check whether the id is gone (it may have been deleted as collateral), then jsd_repair_nodes if needed and retry.
|
|
35
35
|
- When producing ≥2 sibling units that share one structure: make a COMPONENT first, then spread it with INSTANCE; name them "component family/state".
|
|
36
36
|
- For multi-step work read the matching recipe prompt first (they live in prompts/list, names carry no jsd_ prefix; fetching one injects the full flow and acceptance criteria) instead of improvising with tools: charts / data visualization → chart-by-code (line, bar, pie / donut, scatter, radar, area, gauge — compute the geometry in a script, write the SVG to disk, import it via svgPath on jsd_create_svg); HTML to design → html-to-design; designing a screen from scratch → design-strategy; laying out screen sections / auto layout (should a container use it, the two adoption paths, the sections usually missed) → auto-layout; bulk text edits → text-replace-strategy; icon grid → icon-grid; merging multi-step canvas ops into one call → script-ops; syncing styles across sibling instances → variant-sync; variant set construction → variant-set; binding variables in bulk → variable-binding; defining and setting component properties → component-property. The same recipes are also exposed as MCP resources: when a host does not inject this section (observed on most clients), go by the resources instead — read jsd://recipes for the index (with when-to-use per entry) and jsd://recipes/<id> for the body.`,"ping.title":`Check {client} plugin connection`,"batch.description":'Batch orchestrator: runs several jsd_* steps in order inside one request. Earlier results are injected into later args through double-brace placeholders (content = step id + field path); intermediate ids never reach the model, which cuts round-trips and context a lot.\nA placeholder that occupies a whole argument keeps its type (an array can be used directly as ids); embedded in a string it is expanded as JSON text. Placeholders are valid only inside the same call (the step table is destroyed when the call ends; referencing a previous batch aborts the whole batch). Name addressing is a separate route: {{@comp:Button}} resolves to a component / variant-set id and {{@var:accent/blue}} to a variable id, both looked up in the jsd_get_page asset list (read at most once per batch and shared across the steps of that batch; exact names win, then case-insensitive), write the name exactly as the list stores it — on jsDesign a component named with "/" is split into set + member, so assets.components[].name keeps only the leaf and the creation-time path will not match) and a miss or a duplicate name aborts with the candidates named rather than guessing (platforms that cannot read other pages list only the current page). Resources created inside this batch are not in that snapshot — keep using {{id.created[0].id}} for them. Duplicate ids, unknown tools or unresolvable references abort immediately; a failing step aborts by default (stopOnError=false, or per-step continueOnError=true, lets it finish). **When the list does not fit, use `callsFile`**: pass the absolute path of a JSON file holding {"calls":[…]}(optionally with stopOnError / checkDrift) or a bare array — same shape as calls — and the ids never enter the context. That file can also be run directly with the CLI: `text-to-design-mcp exec <file> [--json] [--dry-run]`.\nEchoes are trimmed: node objects keep id/name/type/x/y/width/height/z/parentId; vectorPaths and constraints are dropped entirely. Steps still over 20K chars after trimming degrade to an id list, and the full detail of the whole batch is spilled to a JSONL file (temp dir, one line per step `{id,tool,ok,data}`) with the step echo carrying path and line (echoTrimmed=true, plus an echoNote naming each affected step); only an over-limit or failed write falls back to a bare id list, named in warnings. Note: echoes never carry child nodes — a node is summarized as a whole, so children plus characters / fills / *StyleId / vectorPaths are absent; read the JSONL or call the tool alone to read a subtree instead of assuming the children are gone or the write failed. Resolution is unaffected (the full data is used internally). Batches containing icons must be verified visually with one jsd_export — an echo is not proof.\nResult keys and placeholder syntax per tool (a wrong key aborts the batch; a single object and a one-element array are interchangeable, so {{id.created[0].id}} and {{id.created.id}} both resolve — reading .field straight off a multi-element array still aborts): created is an array for per-type create / jsd_clone_node / jsd_outline_stroke / jsd_create_instance / jsd_detach_instance and a single object for jsd_create_svg / jsd_create_icon / jsd_flatten_nodes / jsd_group_nodes / jsd_create_component / jsd_import_component / jsd_combine_as_variants / jsd_create_style; jsd_find -> nodes; jsd_get_selection -> selection; jsd_set_* -> updated; jsd_swap_component -> swapped; jsd_delete_style -> removed[] (array of id strings, so {{id.removed[0]}})\\\\n· jsd_platform_op -> the step result IS the op payload (no .data envelope): {{id.variables[0].id}} for figma_variables_create, {{id.styles[0].boundVariables}} for figma_style_variables_list; each op documents its own shape in jsd_ping platformOps; jsd_manage_nodes ops: select/remove/ungroup/repair -> id string arrays, clone/outline_stroke -> created[group/flatten -> created (single object), reparent -> moved[].\nStructure drift review is on by default (checkDrift=false disables it): steps containing remove/reparent/group/ungroup/flatten/repair record sibling coordinates before the change and report any node that moved on its own. For multi-step recipes (charts, designing a screen from scratch, HTML to design, bulk copy edits, components and variants, variable binding) read the recipe index jsd://recipes first (ReadMcpResource) instead of improvising tool calls; for whole-page / whole-file bulk edits (many groups per call, ids kept out of the context, read-back verification, chunking by block) read jsd://recipes/script-ops.',"manageNodes.description":`Aggregate entrypoint for node structure operations dispatched by op: select | remove | clone | group | ungroup | flatten | outline_stroke | reparent | repair. For a single operation prefer the matching small tool: jsd_select_nodes / jsd_delete_node / jsd_clone_node / jsd_group_nodes / jsd_ungroup_nodes / jsd_flatten_nodes / jsd_outline_stroke / jsd_reparent_nodes / jsd_repair_nodes (their descriptions carry platform caveats and the correct flow). Property edits belong to jsd_set_* (incl. jsd_set_shape); component/instance work belongs to jsd_manage_components or jsd_create_component / jsd_sync_overrides — ops are not interchangeable.
|
|
37
|
-
Result keys per op (needed to write correct jsd_batch placeholders; a wrong key aborts the batch): select -> selected[and remove -> removed[are id strings; clone/outline_stroke -> created[is an array of nodes; group/flatten -> created is a single node object; ungroup -> ungrouped[is id strings; reparent -> moved[(updated[mirrors it); repair -> cleaned[is id strings.`,"createBooleanOperation.description":`Create a single BOOLEAN_OPERATION node: the booleanOperation mode ({ops}) and children (at least 2 merged child nodes) are required. Only one root boolean node. Always pass a semantic name; unnamed nodes fall back to the engine default name node. Use jsd_batch for multiple roots or complex trees`,"setFillColor.description":`Set fill color/gradient (fills is a Paint array, replaced wholesale rather than merged — pass existing fills you want to keep), blend mode and team-library fill styles. {warn}`,"setText.description":`Modify text (TEXT nodes only): **content and typography** characters/fontSize/fontName, alignment/auto-resize/case/decoration/line-height/letter-spacing, **colour** fills/fillStyleId/blendMode, **size** width/height (pair with textAutoResize), plus Figma truncation and max lines; position x/y is not here — use jsd_move_node / jsd_resize_node. Resolve fonts with jsd_list_fonts first: family verbatim from fonts[].family, style the full name from the same entry (e.g. SourceHanSansCN-Bold, not the short "Bold") — a wrong value fails silently and falls back to the default face, and the result warnings name it. For wrapping pass width + textAutoResize:"HEIGHT" (the default WIDTH_AND_HEIGHT grows with content; width alone gets forced to NONE and the height stops tracking content — for such text, setting characters again reflows it (measured: a fixed-width-200 text whose height read back 15 re-read 82). {warn}; characters overrides work normally inside instances too`,"ping.description":`Check whether the plugin is online (you must first run it inside {client} — Instant Design or Figma — and keep it running). Returns three capability tables: coreCapabilities (create/modify/structure/component/export/image, identical on both platforms); capabilities lists only the platform-difference superset (e.g. variables/componentProperties/textTruncation) — Instant Design usually has only styles while Figma also has variables/componentProperties; platformOps lists platform-specific ops available now (name/title/parameter description) — read it before calling jsd_platform_op. The reply is cached by the daemon, so you can read jsd://platform/state afterwards instead of pinging again`}},Jr=/\{(\w+)\}/g;function Yr(e){let t=qr[e]??qr.en,n=qr[`zh-CN`];return(e,r)=>{let i=t[e]??n[e]??e;return r==null?i:i.replace(Jr,(e,t)=>{let n=r[t];return n==null?e:String(n)})}}var Xr=/^zh([-_]|$)/i,Zr=/^en([-_]|$)/i;function Qr(e){if(typeof e!=`string`)return;let t=e.trim();if(t!==``){if(Xr.test(t))return`zh-CN`;if(Zr.test(t))return`en`}}var $r={debug:0,info:1,warn:2,error:3},ei={variables:`variables`,components:`componentProperties`,variants:`inPlaceVariants`},O=`@jsdesigndeveloper/plugin-typings@1.0.12 plugin-api.d.ts`,k=`@figma/plugin-typings@1.139.0 plugin-api.d.ts`,A=`@mastergo/plugin-typings@2.19.2 dist/index.d.ts`,ti={jsdesign:{variables:{read:null,readShape:null,write:[],nativeUnwired:[],fallback:"两条路,都不是变量那种玩法:① **本地样式** —— `jsd_create_style` 从一个既有节点抄出样式(本平台四类:PAINT / TEXT / EFFECT / GRID;契约的类别是三家 `StyleType` 的八项并集,余下四类本平台没有工厂,传过去会被写前点名拒),回 id;绑上去用 jsd_set_fill_color 的 fillStyleId / jsd_set_text 的 textStyleId / jsd_set_effects 的 effectStyleId / jsd_set_stroke 的 strokeStyleId。**⚠ 本平台未声明 `styleEnumeration`,样式清单(`jsd://styles` / `assets.styles`)恒空、列不出来**:已有样式的 id 只能从正用着它的节点上读(`*StyleId` 字段),新建的 id 从 `jsd_create_style` 回包记账(建重复了用 `jsd_delete_style` 删)。一条样式改一次,全档跟随。② **结构继承** —— 抽成 COMPONENT 后改主件,实例自动继承(批量套覆盖走 variant-sync 配方)。",evidence:[`${O}(全文无 variable 声明:grep -in variable 零命中)`,`packages/ui/src/code/jsdesign/meta.ts capabilities=[styles](按 id 应用样式是有的;**不声明 styleEnumeration** —— 列不出样式,见 0043)`,`packages/shared/src/core/access.ts:174(listStylesAsync 在未声明 styleEnumeration 时直接返回空,四个 getter 一次都不调)`,"packages/ui/src/code/jsdesign/host.ts:48(createStyle 已接:`jsd_create_style` 走 jsDesign.createPaintStyle 等四工厂;四类样式的共同契约在 packages/shared/src/core/styles.ts)",`${O}:88-91(createPaintStyle / createTextStyle / createEffectStyle / createGridStyle)`,`${O}:1137-1143 StyleType 四类 / BaseStyle 只有 id+type+name+remove,无 collectionId、collectionName`]},components:{read:null,readShape:null,write:[`jsd_set_instance_properties`],nativeUnwired:[`Page.importComponentSetByKeyAsync(:111) —— 团队库「组件集」导入入口,本仓只接了组件那半(:110);拿到集合节点是目前唯一的非画布来源`,`Page.createNodeFromJSXAsync(:119) —— JSX 建节点,是否支持组件/集合标签未验(typings 无声明,只有 any)`],fallback:`jsd_swap_component(换绑到目标组件)+ jsd_set_fill_color / jsd_set_text(直接写可见样式)`,evidence:[`${O}:1093 setProperties 只收 string`,`${O}:1081-1085 ComponentNode(createInstance / instances)`,`packages/ui/src/code/jsdesign/sync-guarantee.ts:97 反向断言 componentProperties 缺席`,`packages/ui/src/code/jsdesign/sync-guarantee.ts:367-393 setProperties 签名只收字符串;真机 2026-10-14 的运行期行为:给**没有变体属性**的 INSTANCE 调它不是点名报错,而是挂到转发超时(25s)—— 没有变体集时别拿它当切状态的通道`,"packages/shared/src/core/component.ts setInstanceProperties 的属性面守卫 —— 2026-10-19 真机复现同一条(未知属性名 `Foo` → 25077ms 后失败、错误只有「插件响应超时」):能力位不含 componentProperties 且变体表 / variantProperties 都拿不到键时,写前点名拒,不再落到引擎空转","packages/shared/src/core/access.ts resolveMainComponent 的选路 —— 2026-10-19 真机隔离:typings 未声明的 `getMainComponentAsync` 在即时设计运行时**存在且永不 settle**(与 `*Async` 样式枚举同一模式),`?.` 探测让 `jsd_copy_overrides`(只读快照、不写属性)挂到 25109ms;改由 `mainComponentSync` 声明只问同步 `mainComponent`","packages/ui/src/code/jsdesign/ops.ts jsd_component_facts —— 2026-10-20 三页官方文档核对(js.design/developer-doc/plugin/api/node/{ComponentNode,InstanceNode,ComponentSetNode}):**成员与 typings 1.0.12 逐字一致,没有多出来的 API**;文档确认而契约缺的字段(ComponentNode.instances / key / remote / description / expanded / getPublishStatusAsync、InstanceNode.scaleFactor、ComponentSetNode.defaultVariant / variantGroupProperties / children)由本 op 透出。`getPublishStatusAsync` 单独可选:同族 async 成员有永不 settle 的先例(dec e1e66f0a)",`packages/ui/src/code/jsdesign/ops.ts jsd_component_facts 真机(2026-10-20,重载后):COMPONENT 的 instances 可读且准确(建组件+2 实例 → instanceCount 2 / instanceIds 两条)、key 是空串、remote=false;description **可写**且回读一致(PublishableMixin :838);getPublishStatusAsync **21ms 返回、不永挂**(与 getMainComponentAsync 不同),但对非团队库节点回的是**错误串** "Failed to get node publish status" 而不是 PublishStatus 三值 ⇒ op 里三值才认,其余落 publishStatusError`,'packages/ui/src/code/jsdesign/ops.ts jsd_component_facts 的 INSTANCE 分支 + core/assets.ts readVariantProperties —— 真机 2026-10-20 两条:① `variantGroupProperties.values` 元素**不保证是字符串**(单成员集合 ["ccc"],两成员集合 [{"name":"默认"}]),撞穿 assets.variants.properties 的 string[] 校验使 `get_page` **整条失败**,故 projection 与 op 都按名字归一;② 对真实变体实例调 setProperties **11~15ms 就抛** `in setProperties: i.setProperties is not a function`(typings :1093 与文档都声明了它)⇒ 符号是否真在由 op 的 `setPropertiesAvailable` 回报复核',"packages/ui/src/code/jsdesign/host.ts combineAsVariants 的显式绑定 —— 官方 API 参考页(js.design/developer-doc/plugin/api/reference/jsDesign)确认语义「将任意数量的组件合并为变体」、签名 (nodes, parent, index?);真机 2026-10-20 逐项排除:receiver 绑回全局后报错逐字相同、组件名改成 `状态=默认/禁用` 仍败、带子层仍败、先 reparent 进 FRAME 仍败 ⇒ **引擎实现缺陷,不是调用方式**",`packages/shared/src/core/component.ts combineAsVariantsNodes 的姿势顺序 —— 真机 2026-10-20:合并失败会**毁入参组件**(用户组件 13:100 变损坏节点、repair 直接删),故「原位合并」只在平台声明 inPlaceVariants 时才尝试(Figma 声明、顺序不变);jsDesign 只跑两条克隆姿势,失败也不伤原组件`,`packages/ui/src/code/jsdesign/host.ts combineAsVariants 的**单姿势隔离实验** —— 真机 2026-10-20(即时设计,干净画布,只跑原位姿势,传入真 COMPONENT、类型完全合规):仍抛 in get_booleanOperation: Value is not a string;后果是入参组件 13:332 被就地改成 BOOLEAN_OPERATION、13:333 幸存 ⇒ 坐实引擎实现缺陷,并排除两个替代解释:①「clone 返回 INSTANCE 导致参数类型不符才是根因」(原位传合规类型照样崩);②「被克隆两式弄脏画布才连带失败」(干净画布单跑照样崩)`,`packages/ui/src/code/jsdesign/host.ts combineAsVariants 的**裸调实验** —— 真机 2026-10-20(即时设计,画板 3 下 4 个真 COMPONENT,取消 core 的姿势选择 / clone 类型校验 / 父容器校验 / 跨父级校验 / 返回类型校验,直接 host.combineAsVariants(components, parent)):引擎**成功返回一个 type=BOOLEAN_OPERATION 的节点**(id 13:446),读它的 name 抛 in get_name: Value is not a string;四个原 COMPONENT **被搬进该布尔节点下**(parentId=13:446),画板 3 随即变空 ⇒ 坐实「引擎把合并路由成布尔运算」,并排除「core 的某个前置判断改变了入参」这一解释(裸调无任何判断,行为一致)。事后可用 jsd_reparent_nodes 把组件搬回原容器,损坏节点由 repair 清`,"packages/shared/src/core/access.ts resolveNodes 的返回身份 —— 真机 2026-10-20(即时设计,只读探针,未执行合并):四个 COMPONENT 逐个比对 `=== jsDesign.getNodeById(id)`,**全部 true**(即返回的是原生对象本身,不是包装或代理);成员核验 nodes 各有 createInstance(ComponentNode 独有)、无 setProperties(那是 InstanceNode 的),parent 有 children/appendChild/insertChild 且无 createInstance、且不等于 currentPage ⇒ 入参**完全满足** combineAsVariants(nodes: ReadonlyArray<ComponentNode>, parent: BaseNode & ChildrenMixin) 的签名。故「参数类型不满足」这一解释被排除:类型层面的 `as never` 只是掩盖了静态证明,运行时要传的对象是对的",`packages/shared/src/core/component.ts / jsd_reparent_nodes —— 真机 2026-10-20:RECTANGLE 可 reparent 进 COMPONENT(文档 ComponentNode 继承 BaseFrameMixin → appendChild :711),childCount 0→1,且**两个实例的 childCount 同步变 1**(主件加子层实时传播)`,`packages/shared/src/core/component.ts setInstanceProperties / swapComponents / detachInstanceNodes + packages/shared/src/core/nodes.ts cloneNodes + packages/shared/src/core/variant.ts —— 真机 2026-10-20(即时设计,逐条隔离):① **变体集成员**上 createInstance 必抛 in createInstance: The node with id undefined does not exist(集合内 8 个成员全复现;独立 COMPONENT 正常),clone() 返回 undefined;② swapComponent 必抛 in swapComponent: Cannot read properties of undefined (reading type)(独立组件之间 / 成员之间 / 克隆实例上全复现);③ detachInstance **原位返回同一个 INSTANCE**(type 仍 INSTANCE、mainComponentId 照旧)⇒ 静默 no-op;④ 集合维度键 状态 与成员键 分类1 **不是同一套**,只按集合键校验会把合法的成员键写入拒掉`]},variants:{read:`variantProperties`,readShape:`map`,write:[`jsd_combine_as_variants`],nativeUnwired:[`Page.importComponentSetByKeyAsync(:111) —— 未接;这是「不经画布拿到集合节点」的唯一路径`,`ComponentSetNode.appendChild / insertChild(:711-712,继承自 BaseFrameMixin)—— 类型上能追加成员,但没有创建入口 ⇒ 拿不到集合节点,这一面实际不可达`],fallback:`多主件:每个状态各建一个 COMPONENT,按「族名 / 状态」命名(如 Nav / Inbox、Nav / Me);实例侧切值本平台运行期无入口(setProperties 不是函数、swapComponent 抛内部错误,真机 2026-10-20),变体取值只能在画布上手工切换`,evidence:[`${O}:899-900 VariantMixin.variantProperties(readonly)`,`${O}:1074-1079 ComponentSetNode 自身只多 clone / defaultVariant / variantGroupProperties;但 :1074 继承 BaseFrameMixin(:851)→ 带 appendChild / insertChild(:711-712)`,`packages/shared/src/core/variant.ts + core/serialize.ts + core/assets.ts —— 真机 2026-10-20:variantGroupProperties.values 元素**不保证是字符串**(单成员集合 ["ccc"],两成员集合 [{"name":"默认"},{"name":"禁用"}]),不归一会撞穿线格式 string[] 并让 get_page / jsd_find **整条失败**(不是少字段,是这次只读调用报废);variantProperties 同理。归一实现单点(两个投影点共用),serializeNode 另加一层「getter 抛也省略该字段」的保护`,"packages/ui/src/code/jsdesign/host.ts / core/component.ts combineAsVariants 兜底 —— 真机 2026-10-19 复核(即时设计,重载后):72ms 抛「三种姿势均失败…in get_booleanOperation: Value is not a string」**与 09-24/10-14 逐字一致**;残留形态这次是 **3 个 BOOLEAN_OPERATION(原 COMPONENT 被就地改成 BOOLEAN_OPERATION、id 保留)+ 1 个幸存 COMPONENT,没有 COMPONENT_SET**(10-14 那次是留下畸形 COMPONENT_SET),`assets.variants` 回到 0 ⇒ 残留形态不稳定,清理一律走 `jsd_manage_nodes op=repair`(实测 `cleaned: 3 个`)",`${O}:127 combineAsVariants 是 ComponentSetNode 的唯一产出路径`,`packages/shared/src/core/component.ts:245-256 三种姿势全败的兜底与分流`,`packages/shared/src/core/nodes.ts:1006 repairNodes 是清残骸的唯一入口(jsd_delete_node 对它们报「没有要删除的节点」);真机 2026-10-14(即时设计):合成抛错后 assets.variants 从 0 变 1(畸形集合,成员 jsd_create_instance 报「node with id undefined does not exist」),另有 3 个 BOOLEAN_OPERATION 残骸`]}},figma:{variables:{read:`boundVariables / figma_variables_list / figma_style_variables_list`,readShape:`map`,write:[`figma_variables_create`,`figma_variables_apply`,`figma_variables_remove`,`figma_style_variables_apply`],nativeUnwired:[`Variable.setValueForMode / rename(改变量值与生命周期里的改名,本仓未接;删除已接成 figma_variables_remove)`,`VariableCollection 的模式增删改名(addMode / renameMode / removeMode)`,`样式的反查面 StyleConsumers / getStyleConsumersAsync(:12387)——「这条样式被哪些节点用着」未接,改样式前只能靠名字猜影响面`],fallback:null,evidence:[`packages/ui/src/code/figma/ops.ts figma_variables_create / figma_variables_apply(dec 0040 起带 unbind;dec 7165f370 起一次吃 bindings[] 多组)/ figma_variables_list / figma_variables_remove`,`packages/shared/src/schemas/platform.ts:90-118 boundVariables 线格式`,`${k}:2149 getLocalVariablesAsync / :2160 getLocalVariableCollectionsAsync`,`${k}:6817-6852 VariableBindableNodeField / TextField(paint 与 effect / grid 项是另外三个入口,故 boundProperty 分三档)`,`${k}:6855-6861 VariableBindablePaintStyleField / EffectStyleField / GridStyleField = paints / effects / layoutGrids,ComponentPropertyField = value —— 样式级与组件属性级绑定各一套字段,不在节点那三档里`,`${k}:12432 / :12496 / :12521 / :12537 四类样式的 boundVariables;:12507 TextStyle.setBoundVariable(唯一有 setter 的那类)`,`packages/ui/src/code/figma/ops.ts figma_style_variables_apply / figma_style_variables_list(样式 ↔ 变量的读写两端)`,`${k}:11571 VariableResolvedDataType 六种里没有 VARIANT,也没有「一组值」的样式类型 —— Figma 的样式是**独立资源**,靠自身 boundVariables 引变量;这一点与 MG 相反(见 mastergo.variables)`,`docs/design-decisions/0024-变量绑定进入读路径:boundVariables-按引擎词汇原样透传,不引入归一化层.md`]},components:{read:`componentProperties`,readShape:`map`,write:[`figma_component_property_add`,`jsd_set_instance_properties`],nativeUnwired:[],fallback:null,evidence:[`${k}:11127 readonly componentProperties`,`${k}:11123 setProperties(string | boolean | VariableAlias)`,`${k}:2214 createVariableAliasByIdAsync(官方给的「属性值绑变量」构造入口)`,`${k}:11571 VariableResolvedDataType 无 VARIANT —— 变体属性值绑不了变量`,`${k}:10985 ComponentPropertyType 五项(BOOLEAN|TEXT|INSTANCE_SWAP|VARIANT|SLOT)`,`${k}:11121 setProperties 不收 SLOT,抛 cannotSetSlotProperty`,`${k}:9577 componentPropertyDefinitions / :9581 addComponentProperty`,`packages/shared/src/core/component.ts:124-160 读形态 → 写形态单点映射(0023)`]},variants:{read:`variantProperties`,readShape:`map`,write:[`jsd_combine_as_variants`,`jsd_set_instance_properties`],nativeUnwired:[],fallback:null,evidence:[`${k}:9560 variantProperties 对实例已 @deprecated(指向 componentProperties)`,`${k}:11040 variantGroupProperties 已 @deprecated(指向 componentPropertyDefinitions)`,`${k}:1822 combineAsVariants`,`packages/ui/src/code/figma/meta.ts capabilities 声明 inPlaceVariants`]}},mastergo:{variables:{read:`mg.variables.getVariables()`,readShape:`array`,write:[`mg_variables_create`,`mg_variables_apply`,`mg_variables_remove`],nativeUnwired:[`mg.variables 的 Mode 管理:addMode / renameMode / deleteMode / setVariableMode / setPageVariableMode(读侧已给 getModes,见 mg_list_variables)`,`mg.variables 的分组管理:getGroupList / createGroup / addVariablesToGroup / removeVariablesFromGroup / renameGroup / disbandGroup / deleteGroup`,`mg.variables.createVariableInLayer(一步建变量 + 绑图层;与 create + apply 的组合重叠,未接)`,`mg.variables.setVariableReference / unlinkVariable(变量引用变量、跨类型别名与复合样式变量的子属性引用)`,`mg.variables 的作用域与代码语法:setVariableScopes / setCodeSyntax / getVariableIndexes / addVariableValue(复合变量补子项)`,`mg.getLocalStrokeWidthStyles / getLocalCornerRadiusStyles / getLocalPaddingStyles / getLocalSpacingStyles(:1517-1520):四类样式的样式侧枚举未接(它们改由 assets.variables 那侧可见)`],fallback:null,evidence:[`${A}:1522 readonly variables: VariableAPI`,`${A}:1098-1108 VariableAPI(Collection / Mode)`,`${A}:1176 getVariables() / :1874 Variable{id,name,…}`,`${A}:1832 VariableType 十二项(八项与 :1810 StyleType 逐字重名)/ :2079 type Style 联合含 Variable / :1990 BaseStyle.collectionName`,`${A}:1920 VariableValue(含 :1901 TextVariableValue 与 Record<string,unknown>):复合样式变量走**部分更新**,不传的子项就是空样式`,"packages/ui/src/code/mastergo/ops.ts MG_VARIABLE_TYPES_UNSUPPORTED —— 真机:`mg_variables_create type=SPACING` 抛 `Unsupported variable type: SPACING`;官方文档的 PluginVariableType 11 项才是引擎实况,typings 的 VariableType 十二项含幻影","packages/ui/src/code/mastergo/ops.ts createVariables 的回读分支 —— 真机:复合样式变量**不进 `getVariables()` 列表**(按 collectionId、按 type 两种筛法当次与下一次都列不出),但 `getVariableById(id)` 读得到 ⇒ 回读判据必须是按 id 查;两条都读不到才落 `pendingReadback`(判成失败会让调用方重试、攒出重复变量)","packages/ui/src/code/mastergo/ops.ts listVariablesOp 的取变量分支 —— 真机:`mg.variables.getVariables(undefined)` 抛 `Cannot read properties of undefined (reading collectionId)`:typings 把 options 标成可选,引擎实现不判空,空筛选必须一个参数都不传","packages/ui/src/code/mastergo/host.ts createStyle 的八工厂分支 —— 真机:`jsd_create_style` 的四类新 kind 建得出(id 6:12~6:15),但它们进的是 `assets.variables` 而不是 `assets.styles`;反向 `mg_variables_create type=PAINT`(id 6:45)只进 `assets.styles`,`mg_variables_remove` 对它无效并点名走 `jsd_delete_style`(删后回读判据生效,不再假报 removed)。⇒ 两份清单是同一批资源的两个视角,**按创建路径随机可见**,只有 id 是可靠判据","packages/ui/src/code/mastergo/meta.ts capabilities 声明 styleEnumeration —— 真机:`assets.styles` 列得出来(PAINT / EFFECT 三条,不退超时),0043 的「MG 是否也这样」那一半结掉",`packages/ui/src/code/mastergo/ops.ts 三个变量 op 与槽位表(官方文档 URL 见该文件头注释;mg_variables_apply 与 Figma 同形:形制对齐见 dec 0040,一次吃 bindings[] 多组见 dec 7165f370)`,`${A}:1832 VariableType 十二项里没有 VARIANT —— 变体属性无从绑变量`,`packages/ui/src/code/mastergo/ops.ts removeVariables 的三档 —— 真机 2026-10-19(重载后两轮):单值变量的 deleteVariable **跨执行才生效**(同执行内删两遍 + 回读仍全失败,下一次调用立刻 removed),故同执行回读判失败会把成功报成失败(10-15 那 5 条 failed 即此形态);复合样式变量(PAINT)的 deleteVariable 是 **no-op**(跨多次执行仍在:列表 / assets.variables / 拿它绑图层三面都证明它还活着,同 id 走 jsd_delete_style 一次删掉)`,`packages/ui/src/code/mastergo/ops.ts createVariables 的 values —— 真机 2026-10-19:setVariableValue 的返回 modes **时有时无**(同批里有的带 bool / floatData,有的只有 {modeId},默认双模式集合回空对象);STRING 变量在列表 / 按 id / 写返回三个读面都只有 {modeId} ⇒ 值不可验证,values 只原样透传不作判据`,`packages/ui/src/code/mastergo/meta.ts capabilities 声明 variables(0040 起)`]},components:{read:`componentProperties`,readShape:`map`,write:[`mg_add_component_property`,`mg_bind_component_property`,`mg_edit_component_property`,`mg_delete_component_property`,`jsd_set_instance_properties`],nativeUnwired:[`把组件属性绑成变量:MG 只在读侧给 variableId(:3001),写侧没有任何入口 —— 要绑只能在设计器里手动做,插件只能验证它存不存在`],fallback:null,evidence:[`${A}:3096 readonly componentProperties: Array<ComponentProperties>`,`${A}:3097 setProperties({ [propertyId: string]: string | boolean })——**不收变量别名**,值绑变量只此 Figma 一家(dicts/platform-value-domain.ts 的第四类表按平台 deny)`,`${A}:3001 ComponentPropertyValue.variableId —— 属性 ↔ 变量的**只读**证据(仅组件侧;实例侧 :3030 无此字段)`,`${A}:2965-2980 ComponentPropertiesMixin(add / edit / delete)`,`${A}:3004 ComponentPropertyType 四项,没有 Figma 的 SLOT(:10985)`,`packages/ui/src/code/mastergo/meta.ts:12-14 写侧真机未验,故不 claim`]},variants:{read:`variantProperties`,readShape:`array`,write:[`jsd_combine_as_variants`,`jsd_set_instance_properties`],setLevelOps:[`mg_list_variant_properties`,`mg_create_variant_property`,`mg_create_variant_component`,`mg_edit_variant_property`,`mg_edit_variant_property_value`,`mg_delete_variant_property`],nativeUnwired:[`ComponentSetNode.editVariantPropertiesAlias`,`ComponentSetNode.editVariantPropertyValuesAlias`],fallback:null,evidence:[`${A}:3056 / :3092 readonly variantProperties: Array<VariantProperty> | undefined`,`${A}:1415 combineAsVariants(nodes)(无 parent / index 参数)`,`${A}:3072-3085 ComponentSetNode 的集合级 op 名单(5 个已接 + 2 个别名未接)`,`${A}:3011-3026 ComponentPropertyValue.variantOptions / variantOptionsAlias —— MG 无 variantGroupProperties,维度只能从这里读`,`packages/ui/src/code/mastergo/ops.ts 集合级 op 组(写完回读校验)`,`packages/ui/src/code/mastergo/node-facade.ts:536-543 实例侧两条原生写入运行时静默无效,只有换绑有效`,`docs/design-decisions/0018-实例变体写入:MG上改为集合内换绑加回读校验.md`,`docs/design-decisions/0033-MG-集合级变体管理接入-platformOps:原生建维改值替代改名副作用.md`]}}};function j(e,t){return e==null?null:ti[e][t]}var ni={ui:`text-to-design-ui`,mcp:`text-to-design-mcp`},ri=`https://registry.npmjs.org`;function ii(e){return`${ri}/${e}/latest`}var ai=4e3,oi=process.env.TEXT_TO_DESIGN_MCP_LOG??d(c(),`text-to-design-mcp.log`),si=$r,ci=process.env.TEXT_TO_DESIGN_MCP_LOG_LEVEL??`info`,li=null;function ui(e){li=e}function di(e,n){if(si[e]>=si[ci])try{t(oi,`${new Date().toISOString()} [${e.toUpperCase()}] [text-to-design-mcp] ${n}\n`)}catch{}try{li?.(e,n)}catch{}}function M(e){di(`info`,e)}function N(e){di(`debug`,e)}function P(e){di(`warn`,e)}function F(e){di(`error`,e)}var fi=Se,pi=class{pending=new Map;seq=0;binaryTarget=null;sendFn;constructor(e){this.sendFn=e}request(e,t,n={}){let r=n.timeout??fi,i=n.signal,a=`r${++this.seq}`,o=t&&typeof t==`object`&&`bytes`in t?t.bytes:null,s=o==null?{type:`request`,id:a,method:e,params:t}:{type:`request`,id:a,method:e,params:{...t,hasBinary:!0,bytes:void 0}};return new Promise((t,n)=>{let c=Date.now(),l={id:a,method:e,resolve:t,reject:n,timer:null,waitBinary:!1,binaryCount:0,buffers:[],startedAt:c};if(l.timer=setTimeout(()=>{this.pending.delete(a),this.detachAbort(l),P(`请求超时: ${a} ${e} 耗时=${Date.now()-c}ms`),n(new v(`plugin_timeout`,`请求超时: ${e}`))},r),i){if(i.aborted){clearTimeout(l.timer),n(new v(`cancelled`,`请求已取消: ${e}`));return}l.abort={signal:i,listener:()=>{this.pending.delete(a)&&(clearTimeout(l.timer),this.detachAbort(l),M(`请求取消: ${a} ${e} 耗时=${Date.now()-c}ms`),n(new v(`cancelled`,`请求已取消: ${e}`)))}},i.addEventListener(`abort`,l.abort.listener,{once:!0})}this.pending.set(a,l),M(`发出请求: ${a} ${e}${o==null?``:` +binary(${o.byteLength}B)`}`),this.sendFn(JSON.stringify(s),o==null?void 0:Buffer.from(o))})}detachAbort(e){e.abort&&=(e.abort.signal.removeEventListener(`abort`,e.abort.listener),void 0)}onText(e){let t;try{t=JSON.parse(e.toString())}catch(t){P(`WS 文本解析失败(${t instanceof Error?t.message:String(t)}): ${e.toString().slice(0,100)}`);return}if(t.type===`request`){t.method===`ping`?(M(`收到 ping 请求: ${t.id} (自动回 pong)`),this.sendFn(JSON.stringify({type:`response`,id:t.id,ok:!0,data:{pong:!0}}))):M(`收到未知请求: ${t.id} ${t.method} (忽略)`);return}if(t.type!==`response`){M(`收到非响应消息: type=${t.type}`);return}let n=this.pending.get(t.id);if(!n){P(`未匹配响应: id=${t.id}(客户端已取消回收,或来源不明)`);return}if(t.hasBinary&&(t.binaryCount??1)>0){if(M(`二进制响应开始: id=${t.id} count=${t.binaryCount??1}`),this.binaryTarget){let e=this.binaryTarget;this.binaryTarget=null,P(`二进制响应被覆盖: 旧 id=${e.id}(${e.buffers.length}/${e.binaryCount} 帧未收齐),新 id=${t.id}`)}n.waitBinary=!0,n.binaryCount=t.binaryCount??1,n.data=t.data,this.binaryTarget=n;return}this.pending.delete(t.id),clearTimeout(n.timer),this.detachAbort(n);let r=`响应: ${n.id} ${n.method} ok=${t.ok} 耗时=${Date.now()-n.startedAt}ms${t.ok?``:` error=${t.error?.code??``}`}`;t.ok?M(r):F(r),t.ok?n.resolve(t.data):n.reject(t.error?new v(t.error.code,t.error.message):new v(`plugin_error`,`plugin error`))}onBinary(e){if(!this.binaryTarget){P(`孤儿二进制帧 len=${e.byteLength}(无待组装响应,已丢弃)`);return}if(this.binaryTarget.buffers.push(e),M(`二进制帧: id=${this.binaryTarget.id} ${this.binaryTarget.buffers.length}/${this.binaryTarget.binaryCount}`),this.binaryTarget.buffers.length>=this.binaryTarget.binaryCount){let e=this.binaryTarget;this.binaryTarget=null;let t=e.buffers.reduce((e,t)=>e+t.byteLength,0);M(`二进制组装完成: id=${e.id} ${e.buffers.length} 帧 ${t}B 耗时=${Date.now()-e.startedAt}ms`),this.settle(e)}}rejectAll(e){for(let[,t]of this.pending)clearTimeout(t.timer),this.detachAbort(t),t.reject(new v(`not_connected`,e.message));this.pending.clear()}clear(){for(let[,e]of this.pending)clearTimeout(e.timer),this.detachAbort(e);this.pending.clear(),this.binaryTarget=null}settle(e){this.pending.delete(e.id),clearTimeout(e.timer),this.detachAbort(e),e.resolve(mi(e.data,e.buffers))}};function mi(e,t){let n=t.length===1?t[0]:t;if(!e||typeof e!=`object`)return n;let r=e;if(r.exports&&typeof r.exports==`object`){let e=r.exports,n={};return Object.entries(e).forEach(([e,r],i)=>{n[e]={...r,bytes:t[i]}}),{...r,exports:n}}return{...r,bytes:n}}var hi=`0.13.3`,gi=Number(process.env.TEXT_TO_DESIGN_MCP_PORT??47812),I=Number(process.env.TEXT_TO_DESIGN_MCP_HTTP_PORT??47820),_i=`text-to-design-mcp-server`,L=hi,vi=Date.now(),yi=15e3,bi=6e3,xi=5e3,Si=6e4,Ci=3e5,wi=Number(process.env.TEXT_TO_DESIGN_MCP_MAX_INLINE_DATA_URL_BYTES??524288),Ti=12e4,Ei=Number(process.env.TEXT_TO_DESIGN_MCP_MAX_CALLS_FILE_BYTES??8388608),Di=Number(process.env.TEXT_TO_DESIGN_MCP_MAX_BATCH_SPILL_BYTES??33554432),Oi=Number(process.env.TEXT_TO_DESIGN_MCP_MAX_SVG_BYTES??4194304),ki={label:`设计客户端`,runtime:`设计工具`,toolPrefix:`jsd`},R=null,Ai=null;function ji(){return R}function Mi(){let e=R?.platform;if(e==null)return{label:ki.label,runtime:ki.runtime};let t=Kt[e];return{label:`${t}客户端`,runtime:t}}function Ni(e){R!=null&&(R=null,N(`平台状态已清空(${e})`))}function Pi(e){return Ai??=(async()=>{try{let t=await e.request(`ping`,{},{timeout:xi});if(t?.platform==null){N(`平台探测:回包缺 platform,保持未探测状态(判定 fail-open)`);return}R={platform:t.platform,capabilities:t.capabilities??[],coreCapabilities:t.coreCapabilities??[],platformOps:t.platformOps??[],at:Date.now()},M(`平台状态已缓存: ${Kt[R.platform]}(平台差异能力 ${R.capabilities.length} 项 / 特有操作 ${R.platformOps.length} 个)`)}catch(e){N(`平台探测失败(保持未探测状态,判定 fail-open): ${e instanceof Error?e.message:String(e)}`)}finally{Ai=null}})(),Ai}function Fi(e){if(e.platforms==null)return!0;let t=R?.platform;return t==null?null:e.platforms.includes(t)}function Ii(e){if(Fi(e)!==!1)return null;let t=R?.platform;if(t==null||e.platforms==null)return null;let n=e.platforms.map(e=>Kt[e]).join(` / `);return[`工具 ${e.name} 仅适用于 ${n},当前插件平台是 ${Kt[t]},已拒绝执行(未向插件发起请求)。`,e.platformNote==null?``:`${e.platformNote}`,`平台能力与可用特有操作可读 jsd://platform/state 或调 jsd_ping 复核。`].join(``)}function Li(e){return e===4e3?`被新面板顶替`:e===1e3?`正常关闭`:e===1001?`对端离开(页面卸载 / iframe 被回收)`:e===1005?`无关闭码(对端未发关闭帧)`:e===1006?`异常中断(进程被杀 / 代理掐线 / 页面被冻结)`:`其他关闭码`}var Ri=class{wss=null;http=null;client=null;heartbeat=null;_port=0;takeovers=0;onMessage=null;onConnect=null;onDisconnect=null;get port(){return this._port}async start(e){if(this.http=te(),this.wss=new g({server:this.http}),this.wss.on(`error`,e=>{P(`WS server 错误: ${e instanceof Error?e.message:String(e)}`)}),this.heartbeat=setInterval(()=>this.heartbeatTick(),be),this.wss.on(`connection`,(e,t)=>this.attach(e,t)),!await this.tryListen(e))throw this.http.close(),Error(`插件 WS 端口 ${e} 已被占用。若确实是残留的 text-to-design-mcp,先 \`curl -X POST http://127.0.0.1:${I}/shutdown\` 收掉它;否则用 \`ss -tlnp | grep ${e}\` 找出占用者`);this._port=e}stop(){this.heartbeat&&clearInterval(this.heartbeat),this.heartbeat=null,this.client=null,this.wss?.close(),this.http?.close()}get isConnected(){return this.client!==null&&this.client.readyState===h.OPEN}send(e){this.client&&this.client.readyState===h.OPEN?(this.client.send(e),N(`发送 WS 消息 len=${e.length} bin=${typeof e!=`string`}`)):P(`发送失败: 无客户端连接(${e.length} 字节被丢弃)`)}sendPush(e){this.client&&this.client.readyState===h.OPEN&&this.client.send(e)}attach(e,t){let n=`${t.socket.remoteAddress??`?`}:${t.socket.remotePort??`?`}`,r=this.client;r&&r!==e&&(this.takeovers+=1,P(`插件通道被新连接顶替(累计 ${this.takeovers} 次),关闭旧通道`),this.sendStatus(r,`superseded`),r.close(xe,`superseded`)),this.client=e,M(`插件已连接(peer=${n})`);try{this.onConnect?.()}catch(e){M(`onConnect 回调异常: ${e instanceof Error?e.message:String(e)}`)}this.sendStatus(e,`ready`),e.on(`message`,(e,t)=>{let n=Buffer.isBuffer(e)?e:Buffer.from(e);N(`收到 WS 消息 len=${n.length} bin=${t}`),this.onMessage?.(n,t)}),e.on(`close`,(t,r)=>{if(this.client!==e){N(`旧通道关闭(已被顶替),忽略`);return}this.client=null,M(`插件断开: code=${t}${r.length>0?` reason=${r.toString()}`:``} peer=${n} (${Li(t)})`),this.onDisconnect?.(Error(`plugin disconnected (code=${t})`))}),e.on(`error`,t=>{this.client===e&&(this.client=null,M(`插件通道错误: ${t.message} peer=${n}`),this.onDisconnect?.(Error(`plugin connection error: ${t.message}`)))})}heartbeatTick(){let e=this.client;e&&e.readyState===h.OPEN&&(this.sendStatus(e,`ready`),N(`心跳: 下发状态确认`))}sendStatus(e,t){if(e.readyState!==h.OPEN)return;let n={type:`status`,state:t,version:hi};try{e.send(JSON.stringify(n)),N(`已下发状态帧(${t})`)}catch(e){P(`状态帧下发失败(${t}): ${e instanceof Error?e.message:String(e)}`)}}tryListen(e){return new Promise(t=>{let n=()=>{i(),t(!1)},r=()=>{i(),t(!0)},i=()=>{this.http?.off(`error`,n),this.http?.off(`listening`,r)};this.http?.once(`error`,n),this.http?.once(`listening`,r),this.http?.listen(e)})}},zi=200,Bi=class{transport=new Ri;pending;logRing=[];onConnectionChange=null;onPluginConnect=null;constructor(){this.pending=new pi((e,t)=>{this.transport.send(e),t&&this.transport.send(t)}),this.transport.onMessage=(e,t)=>{t?this.pending.onBinary(e):this.pending.onText(e)},this.transport.onConnect=()=>{this.replayLogs(),this.onPluginConnect?.(),this.onConnectionChange?.(!0)},this.transport.onDisconnect=e=>{this.pending.rejectAll(e),this.onConnectionChange?.(!1)}}get port(){return this.transport.port}start(e){return this.transport.start(e)}stop(){this.pending.clear(),this.logRing=[],this.transport.stop()}get isConnected(){return this.transport.isConnected}request(e,t,n={}){return this.transport.isConnected?this.pending.request(e,t,n):(P(`请求被拒(插件未连接): ${e}`),Promise.reject(new v(`not_connected`,`${Mi().runtime} 插件未连接。请先在${Mi().label}中运行该插件。`)))}notifyLog(e,t){let n={type:`log`,level:e,line:t};if(!this.transport.isConnected){this.logRing.length>=zi&&this.logRing.shift(),this.logRing.push(n);return}this.sendLogPush(n)}pushVersion(e){if(this.transport.isConnected)try{this.transport.sendPush(JSON.stringify(e))}catch(e){P(`版本推送失败: ${e instanceof Error?e.message:String(e)}`)}}replayLogs(){if(this.logRing.length===0)return;let e=this.logRing;this.logRing=[],M(`回放离线日志 ${e.length} 条`);for(let t of e)this.sendLogPush(t)}sendLogPush(e){try{this.transport.sendPush(JSON.stringify(e))}catch(e){P(`日志推送失败: ${e instanceof Error?e.message:String(e)}`)}}};async function Vi(){try{let e=await fetch(`http://127.0.0.1:${I}/health`,{signal:AbortSignal.timeout(800)});if(!e.ok)return null;let t=await e.json();return t.name&&t.version?{name:t.name,version:t.version,...typeof t.startedAt==`number`?{startedAt:t.startedAt}:{}}:null}catch{return null}}var Hi=!1;async function Ui(){if(Hi)return;Hi=!0;let e=process.argv[1];if(!e)return;let t;try{t=a(e).mtimeMs}catch{return}let n=await Vi();n?.startedAt==null||n.startedAt>=t||P(`常驻 daemon 跑在旧构建上(daemon 启动 ${new Date(n.startedAt).toISOString()} < 产物 ${new Date(t).toISOString()}),本次代码改动未生效。收掉它:curl -X POST http://127.0.0.1:${I}/shutdown,再重新拉起`)}async function Wi(){let e=await Vi();if(e&&e.version!==L){M(`检测到旧版 daemon (${e.version} → ${L}),正在替换...`),await fetch(`http://127.0.0.1:${I}/shutdown`,{method:`POST`}).catch(()=>{});let t=Date.now()+bi;for(;Date.now()<t&&(await Gi(250),await Vi()!==null););return await Vi()===null?{state:`none`}:(M(`旧版 daemon 尚未释放端口,等待下一轮探测`),{state:`starting`})}let t=new ne({name:`text-to-design-proxy`,version:L},{versionNegotiation:{mode:`auto`}});try{await t.connect(new re(new URL(`http://127.0.0.1:${I}/mcp`)));let{tools:e}=await t.listTools();return e.length===0||!e.every(e=>e.name.startsWith(`jsd_`))?(await t.close(),{state:`foreign`}):{state:`proxy`,client:t}}catch{return await t.close().catch(()=>{}),await Vi()===null?{state:`none`}:{state:`starting`}}}function Gi(e){return new Promise(t=>setTimeout(t,e))}var Ki=3,qi=4,Ji=240,Yi=16,Xi=8;function z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Zi(e,t){if(!e.startsWith(`#/`))return;let n={$defs:t};for(let t of e.slice(2).split(`/`)){let e=decodeURIComponent(t).replace(/~1/g,`/`).replace(/~0/g,`~`);if(!z(n))return;n=n[e]}return n}function Qi(e){let t=e.type;if(typeof t==`string`)return t;if(Array.isArray(t)){let e=t.filter(e=>typeof e==`string`&&e!==`object`&&e!==`array`);return e.length>0?e.join(`,`):void 0}}function $i(e){let t=new Set,n=[];for(let r of e){let e=JSON.stringify(r);if(!t.has(e)&&(t.add(e),n.push(r),n.length>=qi))break}return n}function ea(e,t,n){if(!z(e))return{};if(typeof e.$ref==`string`){if(t>Xi)return{};let r=Zi(e.$ref,n.defs);return r===void 0?{}:ea(r,t,n)}let r={};if(t===0){let t=e.description;typeof t==`string`&&t.length>0&&(r.description=t.length>Ji?`${t.slice(0,Ji)}…`:t)}let i=Qi(e);i!=null&&(r.type=i);for(let i of[`anyOf`,`oneOf`,`allOf`]){let a=e[i];Array.isArray(a)&&a.length>0&&(r[i]=$i(a.map(e=>ea(e,t,n))))}let a=t>=Ki&&z(e.properties);if(z(e.items)&&(r.items=a?{}:ea(e.items,t+1,n)),z(e.properties)&&!a){let i=Object.keys(e.properties),a=t===0?i:i.slice(0,Yi),o={};for(let r of a)o[r]=ea(e.properties[r],t+1,n);if(r.properties=o,t===0&&Array.isArray(e.required)){let t=e.required.filter(e=>typeof e==`string`&&e in o);t.length>0&&(r.required=t)}}return(r.type===`object`||z(r.properties)||z(e.items)&&r.type!==`array`)&&(r.additionalProperties=!0),r}function ta(e){if(!z(e))return e;let t=ea(e,0,{defs:z(e.$defs)?e.$defs:{}});return z(t)&&Object.keys(t).length===0?{type:`object`,additionalProperties:!0}:t}function na(e){let t=e.properties;if(typeof t!=`object`||!t)return null;for(let e of Object.values(t))if(typeof e==`object`&&e){if(`const`in e&&e.const!=null)return String(e.const);if(Array.isArray(e.enum)&&e.enum.length>0)return String(e.enum[0])}return null}function ra(e){let t=[e.oneOf,e.anyOf].find(e=>Array.isArray(e)&&e.length>0);return t==null?null:t.map((e,t)=>{let n=e??{},r=na(n)??`分支#${t}`,i=Array.isArray(n.required)?n.required.filter(e=>e!==`op`):[];return i.length>0?`${r}(需 ${i.join(`, `)})`:`${r}(无必填)`}).join(` | `)}function ia(e){if(typeof e!=`object`||!e||Array.isArray(e))return JSON.stringify(e)??String(e);let t=Object.keys(e);return t.length>0?`字段 [${t.join(`, `)}]`:`空对象 {}`}function aa(e,t){if(t.oneOf!=null||t.anyOf!=null)return null;let n=t.properties;if(typeof n!=`object`||!n||typeof e!=`object`||!e||Array.isArray(e))return null;let r=new Set(Object.keys(n)),i=Object.keys(e).filter(e=>!r.has(e));return i.length>0?i:null}function oa(e){let t=se(e)[`~standard`],n=ra(e);return{"~standard":{...t,validate(r){let i=t.validate(r);if(!(`issues`in i))return i;let a=``;if(typeof r==`object`&&r&&!Array.isArray(r)){let e=r.op;typeof e==`string`&&(a=`, op='${e}'`)}let o=i.issues.map(e=>typeof e?.message==`string`?e.message:``).filter(Boolean).join(`; `).slice(0,300),s=n==null?``:`该工具按判别字段分发,可选值: ${n}。`,c=aa(r,e);if(c!=null){let t=Object.keys(e.properties);return{issues:[{message:`入参校验失败: 字段 [${c.join(`, `)}] 不被该工具接受,请删掉后重试(其余字段本身合法)。该工具接受: [${t.join(`, `)}]。原始校验: ${o}`}]}}return{issues:[{message:`入参校验失败: 实际收到${ia(r)}${a}。${s}请补齐对应必填字段后重试。原始校验: ${o}`}]}}}}}function sa(e){let t=le(process.execPath,[...process.execArgv,...e??process.argv.slice(1)],{detached:!0,stdio:`ignore`,env:{...process.env,TEXT_TO_DESIGN_MCP_ROLE:`daemon`}});t.unref(),t.on(`error`,e=>{F(`拉起 daemon 失败: ${e.message}`)})}var ca=1500,la=2e4,ua=6e4,da=6e5,fa=5e5,pa=5e3;function ma(e){if(e.length===0)return;let t=e.reduce((e,t)=>e+t.bytes,0),n=e.reduce((e,t)=>t.outputBytes>e.outputBytes?t:e);M(`目录体积: ${e.length} 个工具 / ${(t/1024).toFixed(0)} KB(出参最大 ${n.name} ${(n.outputBytes/1024).toFixed(1)} KB)`);let r=[...t>fa?[`合计 ${(t/1024).toFixed(0)} KB > ${fa/1024} KB`]:[],...e.filter(e=>e.outputBytes>pa).map(e=>`出参 ${e.name} ${(e.outputBytes/1024).toFixed(1)} KB`)];r.length>0&&P(`目录体积超预算(${r.join(` / `)}):下游可能丢工具,检查 compact-schema 的投影深度与工具定义`)}function ha(e){let t=e instanceof Error?e.message:String(e);return/fetch failed|ECONNREFUSED|ECONNRESET|EPIPE|socket hang up|terminated|closed/i.test(t)}function ga(e){let t={};for(let n of e??[]){let e=m.string().describe(n.description??``);t[n.name]=n.required===!0?e:e.optional()}return m.object(t)}async function _a(e){let t=e,n=!1,r=null,i=new ie({name:_i,version:L},{supportedProtocolVersions:[`2026-07-28`,..._],...e.getInstructions()?{instructions:e.getInstructions()}:{},cacheHints:{"tools/list":{ttlMs:0,cacheScope:`private`},"prompts/list":{ttlMs:0,cacheScope:`private`},"resources/list":{ttlMs:0,cacheScope:`private`},"resources/templates/list":{ttlMs:0,cacheScope:`private`},"resources/read":{ttlMs:0,cacheScope:`private`}}}),a=new Map,o=new Map,s=new Map,c=new Map,l=async e=>{try{return await e(t)}catch(r){if(n||!ha(r))throw r;return P(`shim: 上游请求失败,触发重连后重放`),await ee(),e(t)}};async function u(){let{tools:e}=await l(e=>e.listTools()),t=new Set,n=[];for(let r of e){t.add(r.name);let e=r.outputSchema?ta(r.outputSchema):void 0,o={title:r.title,description:r.description,annotations:r.annotations,...r.inputSchema?{inputSchema:oa(r.inputSchema)}:{},...e===void 0?{}:{outputSchema:se(e)}},s=JSON.stringify({title:r.title,description:r.description,annotations:r.annotations,inputSchema:r.inputSchema,outputSchema:e});n.push({name:r.name,bytes:s.length,outputBytes:e===void 0?0:JSON.stringify(e).length});let c=a.get(r.name);if(c&&c.raw===s)continue;c?.handle.remove(),a.delete(r.name);let u=i.registerTool.bind(i);try{let e=u(r.name,o,async e=>l(t=>t.callTool({name:r.name,arguments:e??{}})));a.set(r.name,{handle:e,raw:s})}catch(e){P(`工具注册失败(${r.name}): ${e instanceof Error?e.message:String(e)}`)}}ma(n);for(let[e,n]of[...a])t.has(e)||(n.handle.remove(),a.delete(e))}async function d(){let{prompts:e}=await l(e=>e.listPrompts()),t=new Set;for(let n of e){t.add(n.name);let e=JSON.stringify(n),r=o.get(n.name);if(r&&r.raw===e)continue;r?.handle.remove(),o.delete(n.name);let a=i.registerPrompt(n.name,{title:n.title,description:n.description,argsSchema:ga(n.arguments)},e=>l(t=>t.getPrompt({name:n.name,...e?{arguments:e}:{}})));o.set(n.name,{handle:a,raw:e})}for(let[e,n]of[...o])t.has(e)||(n.handle.remove(),o.delete(e))}async function f(){let[{resources:e},{resourceTemplates:t}]=await Promise.all([l(e=>e.listResources()),l(e=>e.listResourceTemplates())]),n=new Set;for(let t of e){let e=t.uri;n.add(e);let r=JSON.stringify(t),a=s.get(e);if(a&&a.raw===r)continue;a?.handle.remove(),s.delete(e);let o=i.registerResource(t.name,e,{title:t.title,description:t.description,mimeType:t.mimeType},async e=>l(t=>t.readResource({uri:e.href})));s.set(e,{handle:o,raw:r})}for(let[e,t]of[...s])n.has(e)||(t.handle.remove(),s.delete(e));let r=new Set;for(let e of t){let t=String(e.uriTemplate);r.add(t);let n=JSON.stringify(e),a=c.get(t);if(a&&a.raw===n)continue;a?.handle.remove(),c.delete(t);let o=i.registerResource(e.name,new ae(t,{list:void 0}),{title:e.title,description:e.description,mimeType:e.mimeType},async(e,t)=>l(t=>t.readResource({uri:e.href})));c.set(t,{handle:o,raw:n})}for(let[e,t]of[...c])r.has(e)||(t.handle.remove(),c.delete(e))}let p=async()=>{let e=await Promise.allSettled([u(),d(),f()]);for(let t of e)t.status===`rejected`&&P(`同步清单失败: ${String(t.reason).slice(0,120)}`)},ee=()=>r||(r=(async()=>{let e=Date.now()+la,n=null;for(;Date.now()<e;){try{let e=await Wi();if(e.state===`proxy`){t=e.client,m(t),M(`shim: 上游已恢复`),await p();return}e.state===`none`&&sa()}catch(e){n=e}await Gi(ca)}throw n??Error(`上游重连超时(${la}ms)`)})().finally(()=>{r=null}),r),m=e=>{e.onclose=()=>{n||(P(`shim: 上游断开,自动重连`),ee().catch(()=>{}))},e.setNotificationHandler(`notifications/tools/list_changed`,async()=>u().catch(()=>{})),e.setNotificationHandler(`notifications/prompts/list_changed`,async()=>d().catch(()=>{})),e.setNotificationHandler(`notifications/resources/list_changed`,async()=>f().catch(()=>{})),e.setNotificationHandler(`notifications/resources/updated`,async e=>{let t=e.params;t?.uri!=null&&await i.server.sendResourceUpdated({uri:t.uri}).catch(()=>{})})};m(t);let te=ce(async()=>(await p(),i)),h=L,g=null,ne=null,re=async()=>{let e=await Vi();e!=null&&e.version!==h&&(M(`上游版本变化(${h} → ${e.version}),全量重同步目录`),h=e.version,await p())},oe=()=>{n||(g=setTimeout(()=>{n||re().finally(oe)},ua),g.unref())},le=()=>{n||(ne=setTimeout(()=>{n||p().finally(le)},da),ne.unref())};oe(),le(),M(`shim 模式: stdio → 动态同步,共享 daemon`),process.on(`SIGINT`,async()=>{n=!0,g&&clearTimeout(g),ne&&clearTimeout(ne),await te.close().catch(e=>{P(`关闭 stdio 失败(忽略): ${e instanceof Error?e.message:String(e)}`)}),await t.close().catch(()=>{}),process.exit(0)})}function va(e=process.env.TEXT_TO_DESIGN_LANG){return Qr(e)??`zh-CN`}function ya(e=va()){return{locale:e,t:Yr(e)}}function B(e){throw Error(e)}var ba=50;async function xa(e){let t=e.trim();t===``&&B(`callsFile 是空路径。请给步骤清单 JSON 的绝对路径。`),u(t)||B(`callsFile 必须是绝对路径(收到「${t}」)。daemon 是常驻进程,相对路径会解析到它自己的工作目录而不是你的项目 —— 所以这里不做推断,请写全路径。`);let n=await he(t).catch(e=>{B(`读不到 callsFile「${t}」:${e instanceof Error?e.message:String(e)}。路径写错了,或文件还没生成。`)});n.isFile()||B(`callsFile「${t}」不是文件(是目录或特殊文件)。`),n.size>Ei&&B(`callsFile「${t}」${(n.size/1024/1024).toFixed(2)} MB,超过上限 ${(Ei/1024/1024).toFixed(0)} MB(可用 TEXT_TO_DESIGN_MCP_MAX_CALLS_FILE_BYTES 覆盖)。请把清单拆成多份分开调用。`);let r=await me(t,`utf8`).catch(e=>{B(`读 callsFile「${t}」失败:${e instanceof Error?e.message:String(e)}。`)}),i;try{i=JSON.parse(r)}catch(e){B(`callsFile「${t}」不是合法 JSON:${e instanceof Error?e.message:String(e)}。文件内容应为 {"calls":[…]} 或直接一个数组。`)}let a=Array.isArray(i)?{calls:i}:i;(typeof a!=`object`||!a||Array.isArray(i))&&B(`callsFile「${t}」的顶层既不是数组也不是对象。两种合法形状:直接给步骤数组,或给 {"calls":[…]}。`);let o=a.calls;Array.isArray(o)||B(`callsFile「${t}」里没有 calls 数组(实际类型 ${o===void 0?`undefined`:typeof o})。文件内容应为 {"calls":[…]} 或直接一个数组。`),o.length===0&&B(`callsFile「${t}」的 calls 是空数组,没有步骤可执行。`),o.length>ba&&B(`callsFile「${t}」有 ${o.length} 步,超过单批上限 ${ba} 步。文件省的是参数体积、不是步骤数预算 —— 请拆成多份清单分开调用(整页改造按块切批还能换来回显清晰与失败隔离)。`);let s=[];for(let[e,n]of o.entries()){let r=mt.safeParse(n);if(!r.success){let n=r.error.issues.map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`).join(`; `);B(`callsFile「${t}」第 ${e+1} 步形状不对:${n}`)}s.push(r.data)}let c=typeof a.stopOnError==`boolean`?a.stopOnError:void 0,l=typeof a.checkDrift==`boolean`?a.checkDrift:void 0;return M(`jsd_batch 从文件读入步骤清单:${t}(${s.length} 步${c===!1?`,stopOnError=false`:``})`),{calls:s,stopOnError:c,checkDrift:l,path:t}}function Sa(e){let t=e.def;if(typeof t==`object`&&t)return t;let n=e._def;return typeof n==`object`&&n?n:void 0}function Ca(e){let t=e.description;if(typeof t==`string`&&t!==``)return t;let n=Sa(e)?.description;return typeof n==`string`&&n!==``?n:void 0}function wa(e,t){ee.globalRegistry.add(e,{description:t})}function Ta(e){let t=[];for(let n of[`innerType`,`element`,`valueType`,`keyType`,`in`,`out`,`catchall`,`rest`]){let r=e[n];typeof r==`object`&&r&&t.push(r)}if(Array.isArray(e.options))for(let n of e.options)typeof n==`object`&&n&&t.push(n);if(Array.isArray(e.items))for(let n of e.items)typeof n==`object`&&n&&t.push(n);if(Array.isArray(e.type))for(let n of e.type)typeof n==`object`&&n&&t.push(n);let n=e.shape;if(typeof n==`object`&&n)for(let e of Object.values(n))typeof e==`object`&&e&&t.push(e);if(typeof e.getter==`function`)try{let n=e.getter();typeof n==`object`&&n&&t.push(n)}catch{}return t}function Ea(e,t){let n=new Set,r=e=>{if(typeof e!=`object`||!e||n.has(e))return;n.add(e);let i=e;t(i);let a=Sa(i);if(a!=null)for(let e of Ta(a))r(e)};r(e)}function Da(e,t){return Ea(e,e=>{let n=Ca(e);if(n==null)return;let r=t(n);r!==n&&wa(e,r)}),e}function Oa(e){return{content:[{type:`text`,text:typeof e==`string`?e:JSON.stringify(e,null,2)}]}}function ka(e){return e._def?.typeName}function Aa(e,t){return e._def?.[t]}function ja(e,t){return e._def?.[t]}function V(e){switch(ka(e)){case`ZodObject`:{let t=e.shape;if(typeof t!=`function`)return;let n={};for(let[e,r]of Object.entries(t()))n[e]=V(r);return n}case`ZodArray`:return[];case`ZodBoolean`:return!1;case`ZodNumber`:return 0;case`ZodString`:return``;case`ZodLiteral`:return ja(e,`value`);case`ZodEnum`:return ja(e,`values`)?.[0];case`ZodOptional`:case`ZodDefault`:{let t=Aa(e,`innerType`);return t?V(t):void 0}case`ZodEffects`:{let t=Aa(e,`schema`);return t?V(t):void 0}case`ZodUnion`:{let t=ja(e,`options`)??[],n=t.find(e=>ka(e)===`ZodArray`);return n?V(n):t[0]?V(t[0]):void 0}case`ZodLazy`:{let t=e._def?.getter;return t?V(t()):void 0}default:return}}var Ma={not_connected:{type:`prompt`,prompt:`在当前设计客户端里运行 text-to-design 插件,并确认面板显示「已连接」后重试。`}};function Na(e,t,n){let r=Ma[ye(e)]??n,i={content:[{type:`text`,text:`错误: ${e instanceof Error?e.message:String(e)}`}],isError:!0};return r!==void 0&&(i.followUp=r),t?{...i,structuredContent:V(t)}:i}function Pa(e,t,n,r){if(t){let i=t.safeParse(e);return i.success?{content:[...n??[],...Oa(e).content],structuredContent:i.data,...r===void 0?{}:{followUp:r}}:{content:[{type:`text`,text:`错误: 结果未通过本工具的输出校验 —— ${i.error.issues.map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`).slice(0,8).join(`; `)}\n原始返回:\n${JSON.stringify(e,null,2)}`}],structuredContent:V(t),isError:!0,...r===void 0?{}:{followUp:r}}}return{content:[...n??[],...Oa(e).content],structuredContent:e,...r===void 0?{}:{followUp:r}}}var Fa=new Map;function Ia(e){return Fa.get(e)}function La(){return[...Fa.keys()].sort()}var Ra=8,za=20;function Ba(e){let t=e.shape;if(typeof t!=`object`||!t)return null;let n=Object.keys(t);return n.length>0?n:null}function Va(e,t,n){let r=Ba(e);if(r==null||typeof t!=`object`||!t||Array.isArray(t))return n;let i=Object.keys(t),a=new Set(r),o=i.filter(e=>!a.has(e));return o.length===0?n:`字段 [${o.slice(0,Ra).join(`, `)}]${o.length>Ra?` 等 ${o.length} 个`:``} 不被该工具接受,请删掉后重试(其余字段本身合法)。${r.length<=za?`该工具接受: [${r.join(`, `)}]。`:`该工具接受 ${r.length} 个字段(完整清单见其 schema),本次收到的 [${i.join(`, `)}] 里只有上述字段越界。`}原始校验: ${n}`}function H(e){return(t,n,r)=>{let i=t.registerTool.bind(t),a=e=>e==null||e.type!==`tool`||e.description==null?e:{...e,description:r.t(e.description)},o=async(t,r,i)=>{try{let o=Ii(e);if(o!=null)return F(`工具 ${e.name} 在当前平台不可用,已拦截`),Na(new v(`platform_unsupported`,o),e.outputSchema,a(e.followUp));if(e.inputSchema!=null){let n=e.inputSchema.safeParse(t);if(!n.success){let r=n.error.issues.map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`).join(`; `);throw new v(`invalid_args`,`参数校验失败(${e.name}): ${Va(e.inputSchema,t,r)}`)}t=n.data}let s={...r==null?{}:{signal:r},...e.timeout==null?{}:{timeout:e.timeout}},c=i?.skipHooks===!0?void 0:e.hook?.();if(c?.before!=null)try{await c.before(t)}catch(t){P(`工具 ${e.name} 的前置钩子失败(已忽略): ${t instanceof Error?t.message:String(t)}`)}let l;l=e.run?await e.run(t,n,r??new AbortController().signal):await n.request(e.method,e.payload?e.payload(t):t,s);let u=e.extraContent?e.extraContent(l,t):[],d=[],f=l?.warnings;if(Array.isArray(f))for(let e of f)typeof e==`string`&&e!==``&&d.push(e);if(c?.after!=null)try{let e=await c.after(t,l)??[];for(let t of e)d.push(t),u.push({type:`text`,text:t})}catch(t){let n=`⚠ 工具 ${e.name} 的后置钩子失败(不影响本次结果): ${t instanceof Error?t.message:String(t)}`;d.push(n),u.push({type:`text`,text:n})}let p=Pa(l,e.outputSchema,u.length>0?u:void 0,a(e.followUp));return d.length>0?{...p,warnings:d}:p}catch(t){let n=t instanceof Error?t.message:String(t);return F(`工具 ${e.name} 执行失败: ${n.slice(0,200)}`),Na(t,e.outputSchema,a(e.followUp))}};Fa.set(e.name,o);let{t:s}=r,c=i(e.name,{title:s(e.title),description:e.platformNote==null?s(e.description):`${s(e.description)}${s(e.platformNote)}`,...e.inputSchema?{inputSchema:Da(e.inputSchema,s)}:{},outputSchema:Da(e.outputSchema,s),annotations:e.annotations},async(...t)=>{let n=e.inputSchema!=null,r=t[0],i=t[1],a=n?r??{}:{},s=n?i:r,c=s?.mcpReq?.signal??s?.signal;return o(a,c)});return c.alwaysEnabled=e.alwaysEnabled??!1,c}}function Ha(e,t){let n=e;for(let e of t.split(`.`)){let t=/^([\w$\u4e00-\u9fff-]*)((?:\[\d+\])*)$/.exec(e.trim());if(t==null)return{ok:!1};if(t[1]!==``){if(Array.isArray(n)&&n.length===1&&(n=n[0]),typeof n!=`object`||!n)return{ok:!1};n=n[t[1]]}if(t[2]!==``)for(let e of t[2].matchAll(/\[(\d+)\]/g)){let t=Number(e[1]);if(!Array.isArray(n)){if(t===0&&typeof n==`object`&&n)continue;return{ok:!1}}n=n[t]}}return{ok:!0,value:n}}var Ua=class extends Error{constructor(e){super(e),this.name=`StepFailedRefError`}};function Wa(e,t,n){let r=e.indexOf(`.`),i=r===-1?e:e.slice(0,r),a=r===-1?``:e.slice(r+1);if(!t.has(i)){let r=[...t.keys()].join(`, `)||`无`;throw n.has(i)?new Ua(`占位符「${e}」引用的步骤「${i}」执行失败,本步未执行。修掉那一步,或用 stopOnError=false / 该步 continueOnError=true 跳过引用它的步骤(已成功的步骤: ${r})`):Error(`占位符引用的步骤不存在或未成功:「${e}」(已完成: ${r})`)}let o=t.get(i);if(a===``)return o;let s=Ha(o,a);if(!s.ok)throw Error(`无法解析占位符引用「${e}」:请核对步骤 ${i} 的返回结构`);return s.value}var Ga=/^@(comp|var):([\s\S]+)$/;function Ka(e,t,n){let r=t.trim(),i=e===`comp`?`组件/变体集`:`变量`,a=n.filter(e=>e.name===r),o=a.length>0?a:n.filter(e=>e.name.trim().toLowerCase()===r.toLowerCase());if(o.length===1)return o[0].id;if(o.length>1)throw Error(`按名字取${i}「${t}」撞上 ${o.length} 个同名资源:${o.map(e=>`${e.name}(${e.id})`).join(`、`)}。名字不唯一时改用 id 直接写,或先重命名(0041:不确定就点名,绝不猜)。`);let s=n.slice(0,30).map(e=>e.name);throw Error(`按名字取${i}「${t}」没命中。${s.length===0?`这一面当前读不到任何${i}(两种原因都可能:本平台未声明该能力面,或本平台读不到非当前页 —— 到底哪种见 jsd_get_page 回包的 note)`:`现有${i}:${s.join(`、`)}${n.length>s.length?` …`:``}`};也可以直接写 id。`)}async function qa(e,t,n){let r=await n();return Ka(e,t,e===`comp`?[...r.components??[],...r.variants??[]]:r.variables??[])}var Ja=/\{\{\s*([^{}]+?)\s*\}\}/g,Ya=/^\{\{\s*([^{}]+?)\s*\}\}$/,Xa=[`id`,`name`,`type`,`x`,`y`,`width`,`height`,`z`,`parentId`],Za=new Set([`vectorPaths`,`constraints`,`absoluteBoundingBox`,`absoluteRenderBounds`]),Qa=2e4;function $a(e){try{return JSON.stringify(e)?.length??0}catch{return 0}}var eo=[`x`,`y`,`width`,`height`,`parentId`];function to(e){return typeof e.id!=`string`||typeof e.type!=`string`||typeof e.name!=`string`?!1:eo.some(t=>e[t]!==void 0)}function no(e){if(Array.isArray(e))return e.map(no);if(typeof e!=`object`||!e)return e;let t=e;if(to(t)){let e={};for(let n of Xa)t[n]!==void 0&&(e[n]=t[n]);return e}let n={};for(let[e,r]of Object.entries(t))Za.has(e)||(n[e]=no(r));return n}function ro(e,t){if(Array.isArray(e)){for(let n of e)ro(n,t);return}if(typeof e==`object`&&e)for(let[n,r]of Object.entries(e)){if(n===`id`&&typeof r==`string`){t.push(r);continue}ro(r,t)}}function io(e,t){let n=no(e),r=$a(n);if(r<=Qa)return{data:n,trimmed:r!==$a(e),omitted:!1};let i=[];return ro(n,i),{data:{echoOmitted:!0,note:`本步回显裁剪后仍 ${r} 字符,已省略明细;需要细节请把 ${t} 单独调用一次`,ids:[...new Set(i)]},trimmed:!0,omitted:!0}}function ao(e,t,n){let r=[`回显已裁剪:${e.length} 步(${e.join(` / `)})的节点只保留 id/name/type/x/y/width/height/z/parentId`,` —— 子节点、characters、fills、*StyleId、vectorPaths 等字段不在回显里。`,`要读这些字段,请把对应工具**单独调用一次**;批内回显不是验收证据。`,"占位符 `{{步骤id.…}}` 不受影响,它取的是裁剪前的完整数据。"];return t.length>0&&r.push(n==null?`其中 ${t.length} 步(${t.join(` / `)})连摘要都超预算,已降级为 id 清单,步骤内的 note 已点名工具名。`:`其中 ${t.length} 步(${t.join(` / `)})连摘要都超预算,完整明细已落盘到 ${n.path}(${n.bytes} 字节,JSONL 一行一步),按各步 data 里的 line 读即可。`),r.join(``)}var oo=0;function so(e,t){let n=[],r=new Map;for(let i of e)r.set(i.id,n.length+1),n.push(JSON.stringify(i.ok?{id:i.id,tool:i.tool,ok:!0,data:t.get(i.id)}:{id:i.id,tool:i.tool,ok:!1,error:i.error}));let i=`${n.join(`
|
|
38
|
-
`)}\n`,a=Buffer.byteLength(i,`utf8`);if(a>Di)return{error:`明细 ${a} 字节 > 上限 ${Di} 字节`};let s=d(c(),`jsd-batch-${Date.now().toString(36)}-${++oo}.jsonl`);try{o(s,i,`utf8`)}catch(e){return{error:`写盘失败:${e instanceof Error?e.message:String(e)}`}}return{path:s,bytes:a,line:r}}async function co(e,t,n,r){let i=async e=>{let i=Ga.exec(e.trim());return i==null?Wa(e,t,r):qa(i[1],i[2],n)};if(typeof e==`string`){let t=Ya.exec(e.trim());if(t!=null)return i(t[1]);let n=``,r=0;for(let t of e.matchAll(Ja)){n+=e.slice(r,t.index);let a=await i(t[1]);n+=typeof a==`string`?a:JSON.stringify(a),r=(t.index??0)+t[0].length}return r===0?e:n+e.slice(r)}if(Array.isArray(e)){let i=[];for(let a of e)i.push(await co(a,t,n,r));return i}if(typeof e==`object`&&e){let i={};for(let[a,o]of Object.entries(e))i[a]=await co(o,t,n,r);return i}return e}function lo(e,t,n){return[H({name:`jsd_batch`,title:`batch.title`,description:`batch.description`,inputSchema:ht,outputSchema:gt,annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_get_selection`,description:`batch.followUp`},timeout:Ti,run:async(e,t,n)=>{let{calls:r,callsFile:i,stopOnError:a,checkDrift:o}=e,s=i==null||i.trim()===``?null:await xa(i);if(s!=null&&r!=null)throw Error(`calls 与 callsFile 只能给一个:calls 在本批内直接执行,callsFile 从文件读同一份清单。两个都给会让「哪份生效」变成猜。`);if(s==null&&r==null)throw Error(`需要 calls 或 callsFile 其中一个(都缺省时没有步骤可执行)。参数体大到写不进上下文时,把清单写进 JSON 文件、这里只传它的绝对路径。`);let c=s?.calls??r??[],l=s?.stopOnError??a,u=s?.checkDrift??o,d=new Map,f=[],p=!1,
|
|
37
|
+
Result keys per op (needed to write correct jsd_batch placeholders; a wrong key aborts the batch): select -> selected[and remove -> removed[are id strings; clone/outline_stroke -> created[is an array of nodes; group/flatten -> created is a single node object; ungroup -> ungrouped[is id strings; reparent -> moved[(updated[mirrors it); repair -> cleaned[is id strings.`,"createBooleanOperation.description":`Create a single BOOLEAN_OPERATION node: the booleanOperation mode ({ops}) and children (at least 2 merged child nodes) are required. Only one root boolean node. Always pass a semantic name; unnamed nodes fall back to the engine default name node. Use jsd_batch for multiple roots or complex trees`,"setFillColor.description":`Set fill color/gradient (fills is a Paint array, replaced wholesale rather than merged — pass existing fills you want to keep), blend mode and team-library fill styles. {warn}`,"setText.description":`Modify text (TEXT nodes only): **content and typography** characters/fontSize/fontName, alignment/auto-resize/case/decoration/line-height/letter-spacing, **colour** fills/fillStyleId/blendMode, **size** width/height (pair with textAutoResize), plus Figma truncation and max lines; position x/y is not here — use jsd_move_node / jsd_resize_node. Resolve fonts with jsd_list_fonts first: family verbatim from fonts[].family, style the full name from the same entry (e.g. SourceHanSansCN-Bold, not the short "Bold") — a wrong value fails silently and falls back to the default face, and the result warnings name it. For wrapping pass width + textAutoResize:"HEIGHT" (the default WIDTH_AND_HEIGHT grows with content; width alone gets forced to NONE and the height stops tracking content — for such text, setting characters again reflows it (measured: a fixed-width-200 text whose height read back 15 re-read 82). {warn}; characters overrides work normally inside instances too`,"ping.description":`Check whether the plugin is online (you must first run it inside {client} — Instant Design or Figma — and keep it running). Returns three capability tables: coreCapabilities (create/modify/structure/component/export/image, identical on both platforms); capabilities lists only the platform-difference superset (e.g. variables/componentProperties/textTruncation) — Instant Design usually has only styles while Figma also has variables/componentProperties; platformOps lists platform-specific ops available now (name/title/parameter description) — read it before calling jsd_platform_op. The reply is cached by the daemon, so you can read jsd://platform/state afterwards instead of pinging again`}},Jr=/\{(\w+)\}/g;function Yr(e){let t=qr[e]??qr.en,n=qr[`zh-CN`];return(e,r)=>{let i=t[e]??n[e]??e;return r==null?i:i.replace(Jr,(e,t)=>{let n=r[t];return n==null?e:String(n)})}}var Xr=/^zh([-_]|$)/i,Zr=/^en([-_]|$)/i;function Qr(e){if(typeof e!=`string`)return;let t=e.trim();if(t!==``){if(Xr.test(t))return`zh-CN`;if(Zr.test(t))return`en`}}var $r={debug:0,info:1,warn:2,error:3},ei={variables:`variables`,components:`componentProperties`,variants:`inPlaceVariants`},O=`@jsdesigndeveloper/plugin-typings@1.0.12 plugin-api.d.ts`,k=`@figma/plugin-typings@1.139.0 plugin-api.d.ts`,A=`@mastergo/plugin-typings@2.19.2 dist/index.d.ts`,ti={jsdesign:{variables:{read:null,readShape:null,write:[],nativeUnwired:[],fallback:"两条路,都不是变量那种玩法:① **本地样式** —— `jsd_create_style` 从一个既有节点抄出样式(本平台四类:PAINT / TEXT / EFFECT / GRID;契约的类别是三家 `StyleType` 的八项并集,余下四类本平台没有工厂,传过去会被写前点名拒),回 id;绑上去用 jsd_set_fill_color 的 fillStyleId / jsd_set_text 的 textStyleId / jsd_set_effects 的 effectStyleId / jsd_set_stroke 的 strokeStyleId。**⚠ 本平台未声明 `styleEnumeration`,样式清单(`jsd://styles` / `assets.styles`)恒空、列不出来**:已有样式的 id 只能从正用着它的节点上读(`*StyleId` 字段),新建的 id 从 `jsd_create_style` 回包记账(建重复了用 `jsd_delete_style` 删)。一条样式改一次,全档跟随。② **结构继承** —— 抽成 COMPONENT 后改主件,实例自动继承(批量套覆盖走 variant-sync 配方)。",evidence:[`${O}(全文无 variable 声明:grep -in variable 零命中)`,`packages/ui/src/code/jsdesign/meta.ts capabilities=[styles](按 id 应用样式是有的;**不声明 styleEnumeration** —— 列不出样式,见 0043)`,`packages/shared/src/core/access.ts:174(listStylesAsync 在未声明 styleEnumeration 时直接返回空,四个 getter 一次都不调)`,"packages/ui/src/code/jsdesign/host.ts:48(createStyle 已接:`jsd_create_style` 走 jsDesign.createPaintStyle 等四工厂;四类样式的共同契约在 packages/shared/src/core/styles.ts)",`${O}:88-91(createPaintStyle / createTextStyle / createEffectStyle / createGridStyle)`,`${O}:1137-1143 StyleType 四类 / BaseStyle 只有 id+type+name+remove,无 collectionId、collectionName`]},components:{read:null,readShape:null,write:[`jsd_set_instance_properties`],nativeUnwired:[`Page.importComponentSetByKeyAsync(:111) —— 团队库「组件集」导入入口,本仓只接了组件那半(:110);拿到集合节点是目前唯一的非画布来源`,`Page.createNodeFromJSXAsync(:119) —— JSX 建节点,是否支持组件/集合标签未验(typings 无声明,只有 any)`],fallback:`jsd_swap_component(换绑到目标组件)+ jsd_set_fill_color / jsd_set_text(直接写可见样式)`,evidence:[`${O}:1093 setProperties 只收 string`,`${O}:1081-1085 ComponentNode(createInstance / instances)`,`packages/ui/src/code/jsdesign/sync-guarantee.ts:97 反向断言 componentProperties 缺席`,`packages/ui/src/code/jsdesign/sync-guarantee.ts:367-393 setProperties 签名只收字符串;真机 2026-10-14 的运行期行为:给**没有变体属性**的 INSTANCE 调它不是点名报错,而是挂到转发超时(25s)—— 没有变体集时别拿它当切状态的通道`,"packages/shared/src/core/component.ts setInstanceProperties 的属性面守卫 —— 2026-10-19 真机复现同一条(未知属性名 `Foo` → 25077ms 后失败、错误只有「插件响应超时」):能力位不含 componentProperties 且变体表 / variantProperties 都拿不到键时,写前点名拒,不再落到引擎空转","packages/shared/src/core/access.ts resolveMainComponent 的选路 —— 2026-10-19 真机隔离:typings 未声明的 `getMainComponentAsync` 在即时设计运行时**存在且永不 settle**(与 `*Async` 样式枚举同一模式),`?.` 探测让 `jsd_copy_overrides`(只读快照、不写属性)挂到 25109ms;改由 `mainComponentSync` 声明只问同步 `mainComponent`","packages/ui/src/code/jsdesign/ops.ts jsd_component_facts —— 2026-10-20 三页官方文档核对(js.design/developer-doc/plugin/api/node/{ComponentNode,InstanceNode,ComponentSetNode}):**成员与 typings 1.0.12 逐字一致,没有多出来的 API**;文档确认而契约缺的字段(ComponentNode.instances / key / remote / description / expanded / getPublishStatusAsync、InstanceNode.scaleFactor、ComponentSetNode.defaultVariant / variantGroupProperties / children)由本 op 透出。`getPublishStatusAsync` 单独可选:同族 async 成员有永不 settle 的先例(dec e1e66f0a)",`packages/ui/src/code/jsdesign/ops.ts jsd_component_facts 真机(2026-10-20,重载后):COMPONENT 的 instances 可读且准确(建组件+2 实例 → instanceCount 2 / instanceIds 两条)、key 是空串、remote=false;description **可写**且回读一致(PublishableMixin :838);getPublishStatusAsync **21ms 返回、不永挂**(与 getMainComponentAsync 不同),但对非团队库节点回的是**错误串** "Failed to get node publish status" 而不是 PublishStatus 三值 ⇒ op 里三值才认,其余落 publishStatusError`,'packages/ui/src/code/jsdesign/ops.ts jsd_component_facts 的 INSTANCE 分支 + core/assets.ts readVariantProperties —— 真机 2026-10-20 两条:① `variantGroupProperties.values` 元素**不保证是字符串**(单成员集合 ["ccc"],两成员集合 [{"name":"默认"}]),撞穿 assets.variants.properties 的 string[] 校验使 `get_page` **整条失败**,故 projection 与 op 都按名字归一;② 对真实变体实例调 setProperties **11~15ms 就抛** `in setProperties: i.setProperties is not a function`(typings :1093 与文档都声明了它)⇒ 符号是否真在由 op 的 `setPropertiesAvailable` 回报复核',"packages/ui/src/code/jsdesign/host.ts combineAsVariants 的显式绑定 —— 官方 API 参考页(js.design/developer-doc/plugin/api/reference/jsDesign)确认语义「将任意数量的组件合并为变体」、签名 (nodes, parent, index?);真机 2026-10-20 逐项排除:receiver 绑回全局后报错逐字相同、组件名改成 `状态=默认/禁用` 仍败、带子层仍败、先 reparent 进 FRAME 仍败 ⇒ **引擎实现缺陷,不是调用方式**",`packages/shared/src/core/component.ts combineAsVariantsNodes 的姿势顺序 —— 真机 2026-10-20:合并失败会**毁入参组件**(用户组件 13:100 变损坏节点、repair 直接删),故「原位合并」只在平台声明 inPlaceVariants 时才尝试(Figma 声明、顺序不变);jsDesign 只跑两条克隆姿势,失败也不伤原组件`,`packages/ui/src/code/jsdesign/host.ts combineAsVariants 的**单姿势隔离实验** —— 真机 2026-10-20(即时设计,干净画布,只跑原位姿势,传入真 COMPONENT、类型完全合规):仍抛 in get_booleanOperation: Value is not a string;后果是入参组件 13:332 被就地改成 BOOLEAN_OPERATION、13:333 幸存 ⇒ 坐实引擎实现缺陷,并排除两个替代解释:①「clone 返回 INSTANCE 导致参数类型不符才是根因」(原位传合规类型照样崩);②「被克隆两式弄脏画布才连带失败」(干净画布单跑照样崩)`,`packages/ui/src/code/jsdesign/host.ts combineAsVariants 的**裸调实验** —— 真机 2026-10-20(即时设计,画板 3 下 4 个真 COMPONENT,取消 core 的姿势选择 / clone 类型校验 / 父容器校验 / 跨父级校验 / 返回类型校验,直接 host.combineAsVariants(components, parent)):引擎**成功返回一个 type=BOOLEAN_OPERATION 的节点**(id 13:446),读它的 name 抛 in get_name: Value is not a string;四个原 COMPONENT **被搬进该布尔节点下**(parentId=13:446),画板 3 随即变空 ⇒ 坐实「引擎把合并路由成布尔运算」,并排除「core 的某个前置判断改变了入参」这一解释(裸调无任何判断,行为一致)。事后可用 jsd_reparent_nodes 把组件搬回原容器,损坏节点由 repair 清`,"packages/shared/src/core/access.ts resolveNodes 的返回身份 —— 真机 2026-10-20(即时设计,只读探针,未执行合并):四个 COMPONENT 逐个比对 `=== jsDesign.getNodeById(id)`,**全部 true**(即返回的是原生对象本身,不是包装或代理);成员核验 nodes 各有 createInstance(ComponentNode 独有)、无 setProperties(那是 InstanceNode 的),parent 有 children/appendChild/insertChild 且无 createInstance、且不等于 currentPage ⇒ 入参**完全满足** combineAsVariants(nodes: ReadonlyArray<ComponentNode>, parent: BaseNode & ChildrenMixin) 的签名。故「参数类型不满足」这一解释被排除:类型层面的 `as never` 只是掩盖了静态证明,运行时要传的对象是对的",`packages/shared/src/core/component.ts / jsd_reparent_nodes —— 真机 2026-10-20:RECTANGLE 可 reparent 进 COMPONENT(文档 ComponentNode 继承 BaseFrameMixin → appendChild :711),childCount 0→1,且**两个实例的 childCount 同步变 1**(主件加子层实时传播)`,`packages/shared/src/core/component.ts setInstanceProperties / swapComponents / detachInstanceNodes + packages/shared/src/core/nodes.ts cloneNodes + packages/shared/src/core/variant.ts —— 真机 2026-10-20(即时设计,逐条隔离):① **变体集成员**上 createInstance 必抛 in createInstance: The node with id undefined does not exist(集合内 8 个成员全复现;独立 COMPONENT 正常),clone() 返回 undefined;② swapComponent 必抛 in swapComponent: Cannot read properties of undefined (reading type)(独立组件之间 / 成员之间 / 克隆实例上全复现);③ detachInstance **原位返回同一个 INSTANCE**(type 仍 INSTANCE、mainComponentId 照旧)⇒ 静默 no-op;④ 集合维度键 状态 与成员键 分类1 **不是同一套**,只按集合键校验会把合法的成员键写入拒掉`]},variants:{read:`variantProperties`,readShape:`map`,write:[`jsd_combine_as_variants`],nativeUnwired:[`Page.importComponentSetByKeyAsync(:111) —— 未接;这是「不经画布拿到集合节点」的唯一路径`,`ComponentSetNode.appendChild / insertChild(:711-712,继承自 BaseFrameMixin)—— 类型上能追加成员,但没有创建入口 ⇒ 拿不到集合节点,这一面实际不可达`],fallback:`多主件:每个状态各建一个 COMPONENT,按「族名 / 状态」命名(如 Nav / Inbox、Nav / Me);实例侧切值本平台运行期无入口(setProperties 不是函数、swapComponent 抛内部错误,真机 2026-10-20),变体取值只能在画布上手工切换`,evidence:[`${O}:899-900 VariantMixin.variantProperties(readonly)`,`${O}:1074-1079 ComponentSetNode 自身只多 clone / defaultVariant / variantGroupProperties;但 :1074 继承 BaseFrameMixin(:851)→ 带 appendChild / insertChild(:711-712)`,`packages/shared/src/core/variant.ts + core/serialize.ts + core/assets.ts —— 真机 2026-10-20:variantGroupProperties.values 元素**不保证是字符串**(单成员集合 ["ccc"],两成员集合 [{"name":"默认"},{"name":"禁用"}]),不归一会撞穿线格式 string[] 并让 get_page / jsd_find **整条失败**(不是少字段,是这次只读调用报废);variantProperties 同理。归一实现单点(两个投影点共用),serializeNode 另加一层「getter 抛也省略该字段」的保护`,"packages/ui/src/code/jsdesign/host.ts / core/component.ts combineAsVariants 兜底 —— 真机 2026-10-19 复核(即时设计,重载后):72ms 抛「三种姿势均失败…in get_booleanOperation: Value is not a string」**与 09-24/10-14 逐字一致**;残留形态这次是 **3 个 BOOLEAN_OPERATION(原 COMPONENT 被就地改成 BOOLEAN_OPERATION、id 保留)+ 1 个幸存 COMPONENT,没有 COMPONENT_SET**(10-14 那次是留下畸形 COMPONENT_SET),`assets.variants` 回到 0 ⇒ 残留形态不稳定,清理一律走 `jsd_manage_nodes op=repair`(实测 `cleaned: 3 个`)",`${O}:127 combineAsVariants 是 ComponentSetNode 的唯一产出路径`,`packages/shared/src/core/component.ts:245-256 三种姿势全败的兜底与分流`,`packages/shared/src/core/nodes.ts:1006 repairNodes 是清残骸的唯一入口(jsd_delete_node 对它们报「没有要删除的节点」);真机 2026-10-14(即时设计):合成抛错后 assets.variants 从 0 变 1(畸形集合,成员 jsd_create_instance 报「node with id undefined does not exist」),另有 3 个 BOOLEAN_OPERATION 残骸`]}},figma:{variables:{read:`boundVariables / figma_variables_list / figma_style_variables_list`,readShape:`map`,write:[`figma_variables_create`,`figma_variables_apply`,`figma_variables_remove`,`figma_style_variables_apply`],nativeUnwired:[`Variable.setValueForMode / rename(改变量值与生命周期里的改名,本仓未接;删除已接成 figma_variables_remove)`,`VariableCollection 的模式增删改名(addMode / renameMode / removeMode)`,`样式的反查面 StyleConsumers / getStyleConsumersAsync(:12387)——「这条样式被哪些节点用着」未接,改样式前只能靠名字猜影响面`],fallback:null,evidence:[`packages/ui/src/code/figma/ops.ts figma_variables_create / figma_variables_apply(dec 0040 起带 unbind;dec 7165f370 起一次吃 bindings[] 多组)/ figma_variables_list / figma_variables_remove`,`packages/shared/src/schemas/platform.ts:90-118 boundVariables 线格式`,`${k}:2149 getLocalVariablesAsync / :2160 getLocalVariableCollectionsAsync`,`${k}:6817-6852 VariableBindableNodeField / TextField(paint 与 effect / grid 项是另外三个入口,故 boundProperty 分三档)`,`${k}:6855-6861 VariableBindablePaintStyleField / EffectStyleField / GridStyleField = paints / effects / layoutGrids,ComponentPropertyField = value —— 样式级与组件属性级绑定各一套字段,不在节点那三档里`,`${k}:12432 / :12496 / :12521 / :12537 四类样式的 boundVariables;:12507 TextStyle.setBoundVariable(唯一有 setter 的那类)`,`packages/ui/src/code/figma/ops.ts figma_style_variables_apply / figma_style_variables_list(样式 ↔ 变量的读写两端)`,`${k}:11571 VariableResolvedDataType 六种里没有 VARIANT,也没有「一组值」的样式类型 —— Figma 的样式是**独立资源**,靠自身 boundVariables 引变量;这一点与 MG 相反(见 mastergo.variables)`,`docs/design-decisions/0024-变量绑定进入读路径:boundVariables-按引擎词汇原样透传,不引入归一化层.md`]},components:{read:`componentProperties`,readShape:`map`,write:[`figma_component_property_add`,`jsd_set_instance_properties`],nativeUnwired:[],fallback:null,evidence:[`${k}:11127 readonly componentProperties`,`${k}:11123 setProperties(string | boolean | VariableAlias)`,`${k}:2214 createVariableAliasByIdAsync(官方给的「属性值绑变量」构造入口)`,`${k}:11571 VariableResolvedDataType 无 VARIANT —— 变体属性值绑不了变量`,`${k}:10985 ComponentPropertyType 五项(BOOLEAN|TEXT|INSTANCE_SWAP|VARIANT|SLOT)`,`${k}:11121 setProperties 不收 SLOT,抛 cannotSetSlotProperty`,`${k}:9577 componentPropertyDefinitions / :9581 addComponentProperty`,`packages/shared/src/core/component.ts:124-160 读形态 → 写形态单点映射(0023)`]},variants:{read:`variantProperties`,readShape:`map`,write:[`jsd_combine_as_variants`,`jsd_set_instance_properties`],nativeUnwired:[],fallback:null,evidence:[`${k}:9560 variantProperties 对实例已 @deprecated(指向 componentProperties)`,`${k}:11040 variantGroupProperties 已 @deprecated(指向 componentPropertyDefinitions)`,`${k}:1822 combineAsVariants`,`packages/ui/src/code/figma/meta.ts capabilities 声明 inPlaceVariants`]}},mastergo:{variables:{read:`mg.variables.getVariables()`,readShape:`array`,write:[`mg_variables_create`,`mg_variables_apply`,`mg_variables_remove`],nativeUnwired:[`mg.variables 的 Mode 管理:addMode / renameMode / deleteMode / setVariableMode / setPageVariableMode(读侧已给 getModes,见 mg_list_variables)`,`mg.variables 的分组管理:getGroupList / createGroup / addVariablesToGroup / removeVariablesFromGroup / renameGroup / disbandGroup / deleteGroup`,`mg.variables.createVariableInLayer(一步建变量 + 绑图层;与 create + apply 的组合重叠,未接)`,`mg.variables.setVariableReference / unlinkVariable(变量引用变量、跨类型别名与复合样式变量的子属性引用)`,`mg.variables 的作用域与代码语法:setVariableScopes / setCodeSyntax / getVariableIndexes / addVariableValue(复合变量补子项)`,`mg.getLocalStrokeWidthStyles / getLocalCornerRadiusStyles / getLocalPaddingStyles / getLocalSpacingStyles(:1517-1520):四类样式的样式侧枚举未接(它们改由 assets.variables 那侧可见)`],fallback:null,evidence:[`${A}:1522 readonly variables: VariableAPI`,`${A}:1098-1108 VariableAPI(Collection / Mode)`,`${A}:1176 getVariables() / :1874 Variable{id,name,…}`,`${A}:1832 VariableType 十二项(八项与 :1810 StyleType 逐字重名)/ :2079 type Style 联合含 Variable / :1990 BaseStyle.collectionName`,`${A}:1920 VariableValue(含 :1901 TextVariableValue 与 Record<string,unknown>):复合样式变量走**部分更新**,不传的子项就是空样式`,"packages/ui/src/code/mastergo/ops.ts MG_VARIABLE_TYPES_UNSUPPORTED —— 真机:`mg_variables_create type=SPACING` 抛 `Unsupported variable type: SPACING`;官方文档的 PluginVariableType 11 项才是引擎实况,typings 的 VariableType 十二项含幻影","packages/ui/src/code/mastergo/ops.ts createVariables 的回读分支 —— 真机:复合样式变量**不进 `getVariables()` 列表**(按 collectionId、按 type 两种筛法当次与下一次都列不出),但 `getVariableById(id)` 读得到 ⇒ 回读判据必须是按 id 查;两条都读不到才落 `pendingReadback`(判成失败会让调用方重试、攒出重复变量)","packages/ui/src/code/mastergo/ops.ts listVariablesOp 的取变量分支 —— 真机:`mg.variables.getVariables(undefined)` 抛 `Cannot read properties of undefined (reading collectionId)`:typings 把 options 标成可选,引擎实现不判空,空筛选必须一个参数都不传","packages/ui/src/code/mastergo/host.ts createStyle 的八工厂分支 —— 真机:`jsd_create_style` 的四类新 kind 建得出(id 6:12~6:15),但它们进的是 `assets.variables` 而不是 `assets.styles`;反向 `mg_variables_create type=PAINT`(id 6:45)只进 `assets.styles`,`mg_variables_remove` 对它无效并点名走 `jsd_delete_style`(删后回读判据生效,不再假报 removed)。⇒ 两份清单是同一批资源的两个视角,**按创建路径随机可见**,只有 id 是可靠判据","packages/ui/src/code/mastergo/meta.ts capabilities 声明 styleEnumeration —— 真机:`assets.styles` 列得出来(PAINT / EFFECT 三条,不退超时),0043 的「MG 是否也这样」那一半结掉",`packages/ui/src/code/mastergo/ops.ts 三个变量 op 与槽位表(官方文档 URL 见该文件头注释;mg_variables_apply 与 Figma 同形:形制对齐见 dec 0040,一次吃 bindings[] 多组见 dec 7165f370)`,`${A}:1832 VariableType 十二项里没有 VARIANT —— 变体属性无从绑变量`,`packages/ui/src/code/mastergo/ops.ts removeVariables 的三档 —— 真机 2026-10-19(重载后两轮):单值变量的 deleteVariable **跨执行才生效**(同执行内删两遍 + 回读仍全失败,下一次调用立刻 removed),故同执行回读判失败会把成功报成失败(10-15 那 5 条 failed 即此形态);复合样式变量(PAINT)的 deleteVariable 是 **no-op**(跨多次执行仍在:列表 / assets.variables / 拿它绑图层三面都证明它还活着,同 id 走 jsd_delete_style 一次删掉)`,`packages/ui/src/code/mastergo/ops.ts createVariables 的 values —— 真机 2026-10-19:setVariableValue 的返回 modes **时有时无**(同批里有的带 bool / floatData,有的只有 {modeId},默认双模式集合回空对象);STRING 变量在列表 / 按 id / 写返回三个读面都只有 {modeId} ⇒ 值不可验证,values 只原样透传不作判据`,`packages/ui/src/code/mastergo/meta.ts capabilities 声明 variables(0040 起)`]},components:{read:`componentProperties`,readShape:`map`,write:[`mg_add_component_property`,`mg_bind_component_property`,`mg_edit_component_property`,`mg_delete_component_property`,`jsd_set_instance_properties`],nativeUnwired:[`把组件属性绑成变量:MG 只在读侧给 variableId(:3001),写侧没有任何入口 —— 要绑只能在设计器里手动做,插件只能验证它存不存在`],fallback:null,evidence:[`${A}:3096 readonly componentProperties: Array<ComponentProperties>`,`${A}:3097 setProperties({ [propertyId: string]: string | boolean })——**不收变量别名**,值绑变量只此 Figma 一家(dicts/platform-value-domain.ts 的第四类表按平台 deny)`,`${A}:3001 ComponentPropertyValue.variableId —— 属性 ↔ 变量的**只读**证据(仅组件侧;实例侧 :3030 无此字段)`,`${A}:2965-2980 ComponentPropertiesMixin(add / edit / delete)`,`${A}:3004 ComponentPropertyType 四项,没有 Figma 的 SLOT(:10985)`,`packages/ui/src/code/mastergo/meta.ts:12-14 写侧真机未验,故不 claim`]},variants:{read:`variantProperties`,readShape:`array`,write:[`jsd_combine_as_variants`,`jsd_set_instance_properties`],setLevelOps:[`mg_list_variant_properties`,`mg_create_variant_property`,`mg_create_variant_component`,`mg_edit_variant_property`,`mg_edit_variant_property_value`,`mg_delete_variant_property`],nativeUnwired:[`ComponentSetNode.editVariantPropertiesAlias`,`ComponentSetNode.editVariantPropertyValuesAlias`],fallback:null,evidence:[`${A}:3056 / :3092 readonly variantProperties: Array<VariantProperty> | undefined`,`${A}:1415 combineAsVariants(nodes)(无 parent / index 参数)`,`${A}:3072-3085 ComponentSetNode 的集合级 op 名单(5 个已接 + 2 个别名未接)`,`${A}:3011-3026 ComponentPropertyValue.variantOptions / variantOptionsAlias —— MG 无 variantGroupProperties,维度只能从这里读`,`packages/ui/src/code/mastergo/ops.ts 集合级 op 组(写完回读校验)`,`packages/ui/src/code/mastergo/node-facade.ts:536-543 实例侧两条原生写入运行时静默无效,只有换绑有效`,`docs/design-decisions/0018-实例变体写入:MG上改为集合内换绑加回读校验.md`,`docs/design-decisions/0033-MG-集合级变体管理接入-platformOps:原生建维改值替代改名副作用.md`]}}};function j(e,t){return e==null?null:ti[e][t]}var ni={ui:`text-to-design-ui`,mcp:`text-to-design-mcp`},ri=`https://registry.npmjs.org`;function ii(e){return`${ri}/${e}/latest`}var ai=4e3,oi=process.env.TEXT_TO_DESIGN_MCP_LOG??d(c(),`text-to-design-mcp.log`),si=$r,ci=process.env.TEXT_TO_DESIGN_MCP_LOG_LEVEL??`info`,li=null;function ui(e){li=e}function di(e,n){if(si[e]>=si[ci])try{t(oi,`${new Date().toISOString()} [${e.toUpperCase()}] [text-to-design-mcp] ${n}\n`)}catch{}try{li?.(e,n)}catch{}}function M(e){di(`info`,e)}function N(e){di(`debug`,e)}function P(e){di(`warn`,e)}function F(e){di(`error`,e)}var fi=Se,pi=class{pending=new Map;seq=0;binaryTarget=null;sendFn;constructor(e){this.sendFn=e}request(e,t,n={}){let r=n.timeout??fi,i=n.signal,a=`r${++this.seq}`,o=t&&typeof t==`object`&&`bytes`in t?t.bytes:null,s=o==null?{type:`request`,id:a,method:e,params:t}:{type:`request`,id:a,method:e,params:{...t,hasBinary:!0,bytes:void 0}};return new Promise((t,n)=>{let c=Date.now(),l={id:a,method:e,resolve:t,reject:n,timer:null,waitBinary:!1,binaryCount:0,buffers:[],startedAt:c};if(l.timer=setTimeout(()=>{this.pending.delete(a),this.detachAbort(l),P(`请求超时: ${a} ${e} 耗时=${Date.now()-c}ms`),n(new v(`plugin_timeout`,`请求超时: ${e}`))},r),i){if(i.aborted){clearTimeout(l.timer),n(new v(`cancelled`,`请求已取消: ${e}`));return}l.abort={signal:i,listener:()=>{this.pending.delete(a)&&(clearTimeout(l.timer),this.detachAbort(l),M(`请求取消: ${a} ${e} 耗时=${Date.now()-c}ms`),n(new v(`cancelled`,`请求已取消: ${e}`)))}},i.addEventListener(`abort`,l.abort.listener,{once:!0})}this.pending.set(a,l),M(`发出请求: ${a} ${e}${o==null?``:` +binary(${o.byteLength}B)`}`),this.sendFn(JSON.stringify(s),o==null?void 0:Buffer.from(o))})}detachAbort(e){e.abort&&=(e.abort.signal.removeEventListener(`abort`,e.abort.listener),void 0)}onText(e){let t;try{t=JSON.parse(e.toString())}catch(t){P(`WS 文本解析失败(${t instanceof Error?t.message:String(t)}): ${e.toString().slice(0,100)}`);return}if(t.type===`request`){t.method===`ping`?(M(`收到 ping 请求: ${t.id} (自动回 pong)`),this.sendFn(JSON.stringify({type:`response`,id:t.id,ok:!0,data:{pong:!0}}))):M(`收到未知请求: ${t.id} ${t.method} (忽略)`);return}if(t.type!==`response`){M(`收到非响应消息: type=${t.type}`);return}let n=this.pending.get(t.id);if(!n){P(`未匹配响应: id=${t.id}(客户端已取消回收,或来源不明)`);return}if(t.hasBinary&&(t.binaryCount??1)>0){if(M(`二进制响应开始: id=${t.id} count=${t.binaryCount??1}`),this.binaryTarget){let e=this.binaryTarget;this.binaryTarget=null,P(`二进制响应被覆盖: 旧 id=${e.id}(${e.buffers.length}/${e.binaryCount} 帧未收齐),新 id=${t.id}`)}n.waitBinary=!0,n.binaryCount=t.binaryCount??1,n.data=t.data,this.binaryTarget=n;return}this.pending.delete(t.id),clearTimeout(n.timer),this.detachAbort(n);let r=`响应: ${n.id} ${n.method} ok=${t.ok} 耗时=${Date.now()-n.startedAt}ms${t.ok?``:` error=${t.error?.code??``}`}`;t.ok?M(r):F(r),t.ok?n.resolve(t.data):n.reject(t.error?new v(t.error.code,t.error.message):new v(`plugin_error`,`plugin error`))}onBinary(e){if(!this.binaryTarget){P(`孤儿二进制帧 len=${e.byteLength}(无待组装响应,已丢弃)`);return}if(this.binaryTarget.buffers.push(e),M(`二进制帧: id=${this.binaryTarget.id} ${this.binaryTarget.buffers.length}/${this.binaryTarget.binaryCount}`),this.binaryTarget.buffers.length>=this.binaryTarget.binaryCount){let e=this.binaryTarget;this.binaryTarget=null;let t=e.buffers.reduce((e,t)=>e+t.byteLength,0);M(`二进制组装完成: id=${e.id} ${e.buffers.length} 帧 ${t}B 耗时=${Date.now()-e.startedAt}ms`),this.settle(e)}}rejectAll(e){for(let[,t]of this.pending)clearTimeout(t.timer),this.detachAbort(t),t.reject(new v(`not_connected`,e.message));this.pending.clear()}clear(){for(let[,e]of this.pending)clearTimeout(e.timer),this.detachAbort(e);this.pending.clear(),this.binaryTarget=null}settle(e){this.pending.delete(e.id),clearTimeout(e.timer),this.detachAbort(e),e.resolve(mi(e.data,e.buffers))}};function mi(e,t){let n=t.length===1?t[0]:t;if(!e||typeof e!=`object`)return n;let r=e;if(r.exports&&typeof r.exports==`object`){let e=r.exports,n={};return Object.entries(e).forEach(([e,r],i)=>{n[e]={...r,bytes:t[i]}}),{...r,exports:n}}return{...r,bytes:n}}var hi=`0.13.4`,gi=Number(process.env.TEXT_TO_DESIGN_MCP_PORT??47812),I=Number(process.env.TEXT_TO_DESIGN_MCP_HTTP_PORT??47820),_i=`text-to-design-mcp-server`,L=hi,vi=Date.now(),yi=15e3,bi=6e3,xi=5e3,Si=6e4,Ci=3e5,wi=Number(process.env.TEXT_TO_DESIGN_MCP_MAX_INLINE_DATA_URL_BYTES??524288),Ti=12e4,Ei=Number(process.env.TEXT_TO_DESIGN_MCP_MAX_CALLS_FILE_BYTES??8388608),Di=Number(process.env.TEXT_TO_DESIGN_MCP_MAX_BATCH_SPILL_BYTES??33554432),Oi=Number(process.env.TEXT_TO_DESIGN_MCP_MAX_SVG_BYTES??4194304),ki={label:`设计客户端`,runtime:`设计工具`,toolPrefix:`jsd`},R=null,Ai=null;function ji(){return R}function Mi(){let e=R?.platform;if(e==null)return{label:ki.label,runtime:ki.runtime};let t=Kt[e];return{label:`${t}客户端`,runtime:t}}function Ni(e){R!=null&&(R=null,N(`平台状态已清空(${e})`))}function Pi(e){return Ai??=(async()=>{try{let t=await e.request(`ping`,{},{timeout:xi});if(t?.platform==null){N(`平台探测:回包缺 platform,保持未探测状态(判定 fail-open)`);return}R={platform:t.platform,capabilities:t.capabilities??[],coreCapabilities:t.coreCapabilities??[],platformOps:t.platformOps??[],at:Date.now()},M(`平台状态已缓存: ${Kt[R.platform]}(平台差异能力 ${R.capabilities.length} 项 / 特有操作 ${R.platformOps.length} 个)`)}catch(e){N(`平台探测失败(保持未探测状态,判定 fail-open): ${e instanceof Error?e.message:String(e)}`)}finally{Ai=null}})(),Ai}function Fi(e){if(e.platforms==null)return!0;let t=R?.platform;return t==null?null:e.platforms.includes(t)}function Ii(e){if(Fi(e)!==!1)return null;let t=R?.platform;if(t==null||e.platforms==null)return null;let n=e.platforms.map(e=>Kt[e]).join(` / `);return[`工具 ${e.name} 仅适用于 ${n},当前插件平台是 ${Kt[t]},已拒绝执行(未向插件发起请求)。`,e.platformNote==null?``:`${e.platformNote}`,`平台能力与可用特有操作可读 jsd://platform/state 或调 jsd_ping 复核。`].join(``)}function Li(e){return e===4e3?`被新面板顶替`:e===1e3?`正常关闭`:e===1001?`对端离开(页面卸载 / iframe 被回收)`:e===1005?`无关闭码(对端未发关闭帧)`:e===1006?`异常中断(进程被杀 / 代理掐线 / 页面被冻结)`:`其他关闭码`}var Ri=class{wss=null;http=null;client=null;heartbeat=null;_port=0;takeovers=0;onMessage=null;onConnect=null;onDisconnect=null;get port(){return this._port}async start(e){if(this.http=ee(),this.wss=new te({server:this.http}),this.wss.on(`error`,e=>{P(`WS server 错误: ${e instanceof Error?e.message:String(e)}`)}),this.heartbeat=setInterval(()=>this.heartbeatTick(),be),this.wss.on(`connection`,(e,t)=>this.attach(e,t)),!await this.tryListen(e))throw this.http.close(),Error(`插件 WS 端口 ${e} 已被占用。若确实是残留的 text-to-design-mcp,先 \`curl -X POST http://127.0.0.1:${I}/shutdown\` 收掉它;否则用 \`ss -tlnp | grep ${e}\` 找出占用者`);this._port=e}stop(){this.heartbeat&&clearInterval(this.heartbeat),this.heartbeat=null,this.client=null,this.wss?.close(),this.http?.close()}get isConnected(){return this.client!==null&&this.client.readyState===g.OPEN}send(e){this.client&&this.client.readyState===g.OPEN?(this.client.send(e),N(`发送 WS 消息 len=${e.length} bin=${typeof e!=`string`}`)):P(`发送失败: 无客户端连接(${e.length} 字节被丢弃)`)}sendPush(e){this.client&&this.client.readyState===g.OPEN&&this.client.send(e)}attach(e,t){let n=`${t.socket.remoteAddress??`?`}:${t.socket.remotePort??`?`}`,r=this.client;r&&r!==e&&(this.takeovers+=1,P(`插件通道被新连接顶替(累计 ${this.takeovers} 次),关闭旧通道`),this.sendStatus(r,`superseded`),r.close(xe,`superseded`)),this.client=e,M(`插件已连接(peer=${n})`);try{this.onConnect?.()}catch(e){M(`onConnect 回调异常: ${e instanceof Error?e.message:String(e)}`)}this.sendStatus(e,`ready`),e.on(`message`,(e,t)=>{let n=Buffer.isBuffer(e)?e:Buffer.from(e);N(`收到 WS 消息 len=${n.length} bin=${t}`),this.onMessage?.(n,t)}),e.on(`close`,(t,r)=>{if(this.client!==e){N(`旧通道关闭(已被顶替),忽略`);return}this.client=null,M(`插件断开: code=${t}${r.length>0?` reason=${r.toString()}`:``} peer=${n} (${Li(t)})`),this.onDisconnect?.(Error(`plugin disconnected (code=${t})`))}),e.on(`error`,t=>{this.client===e&&(this.client=null,M(`插件通道错误: ${t.message} peer=${n}`),this.onDisconnect?.(Error(`plugin connection error: ${t.message}`)))})}heartbeatTick(){let e=this.client;e&&e.readyState===g.OPEN&&(this.sendStatus(e,`ready`),N(`心跳: 下发状态确认`))}sendStatus(e,t){if(e.readyState!==g.OPEN)return;let n={type:`status`,state:t,version:hi};try{e.send(JSON.stringify(n)),N(`已下发状态帧(${t})`)}catch(e){P(`状态帧下发失败(${t}): ${e instanceof Error?e.message:String(e)}`)}}tryListen(e){return new Promise(t=>{let n=()=>{i(),t(!1)},r=()=>{i(),t(!0)},i=()=>{this.http?.off(`error`,n),this.http?.off(`listening`,r)};this.http?.once(`error`,n),this.http?.once(`listening`,r),this.http?.listen(e)})}},zi=200,Bi=class{transport=new Ri;pending;logRing=[];onConnectionChange=null;onPluginConnect=null;constructor(){this.pending=new pi((e,t)=>{this.transport.send(e),t&&this.transport.send(t)}),this.transport.onMessage=(e,t)=>{t?this.pending.onBinary(e):this.pending.onText(e)},this.transport.onConnect=()=>{this.replayLogs(),this.onPluginConnect?.(),this.onConnectionChange?.(!0)},this.transport.onDisconnect=e=>{this.pending.rejectAll(e),this.onConnectionChange?.(!1)}}get port(){return this.transport.port}start(e){return this.transport.start(e)}stop(){this.pending.clear(),this.logRing=[],this.transport.stop()}get isConnected(){return this.transport.isConnected}request(e,t,n={}){return this.transport.isConnected?this.pending.request(e,t,n):(P(`请求被拒(插件未连接): ${e}`),Promise.reject(new v(`not_connected`,`${Mi().runtime} 插件未连接。请先在${Mi().label}中运行该插件。`)))}notifyLog(e,t){let n={type:`log`,level:e,line:t};if(!this.transport.isConnected){this.logRing.length>=zi&&this.logRing.shift(),this.logRing.push(n);return}this.sendLogPush(n)}pushVersion(e){if(this.transport.isConnected)try{this.transport.sendPush(JSON.stringify(e))}catch(e){P(`版本推送失败: ${e instanceof Error?e.message:String(e)}`)}}notifyActivity(e,t){if(!this.transport.isConnected)return;let n=t==null?{type:`activity`,phase:e}:{type:`activity`,phase:e,tool:t};try{this.transport.sendPush(JSON.stringify(n))}catch(e){P(`活动推送失败: ${e instanceof Error?e.message:String(e)}`)}}replayLogs(){if(this.logRing.length===0)return;let e=this.logRing;this.logRing=[],M(`回放离线日志 ${e.length} 条`);for(let t of e)this.sendLogPush(t)}sendLogPush(e){try{this.transport.sendPush(JSON.stringify(e))}catch(e){P(`日志推送失败: ${e instanceof Error?e.message:String(e)}`)}}};async function Vi(){try{let e=await fetch(`http://127.0.0.1:${I}/health`,{signal:AbortSignal.timeout(800)});if(!e.ok)return null;let t=await e.json();return t.name&&t.version?{name:t.name,version:t.version,...typeof t.startedAt==`number`?{startedAt:t.startedAt}:{}}:null}catch{return null}}var Hi=!1;async function Ui(){if(Hi)return;Hi=!0;let e=process.argv[1];if(!e)return;let t;try{t=a(e).mtimeMs}catch{return}let n=await Vi();n?.startedAt==null||n.startedAt>=t||P(`常驻 daemon 跑在旧构建上(daemon 启动 ${new Date(n.startedAt).toISOString()} < 产物 ${new Date(t).toISOString()}),本次代码改动未生效。收掉它:curl -X POST http://127.0.0.1:${I}/shutdown,再重新拉起`)}async function Wi(){let e=await Vi();if(e&&e.version!==L){M(`检测到旧版 daemon (${e.version} → ${L}),正在替换...`),await fetch(`http://127.0.0.1:${I}/shutdown`,{method:`POST`}).catch(()=>{});let t=Date.now()+bi;for(;Date.now()<t&&(await Gi(250),await Vi()!==null););return await Vi()===null?{state:`none`}:(M(`旧版 daemon 尚未释放端口,等待下一轮探测`),{state:`starting`})}let t=new ne({name:`text-to-design-proxy`,version:L},{versionNegotiation:{mode:`auto`}});try{await t.connect(new re(new URL(`http://127.0.0.1:${I}/mcp`)));let{tools:e}=await t.listTools();return e.length===0||!e.every(e=>e.name.startsWith(`jsd_`))?(await t.close(),{state:`foreign`}):{state:`proxy`,client:t}}catch{return await t.close().catch(()=>{}),await Vi()===null?{state:`none`}:{state:`starting`}}}function Gi(e){return new Promise(t=>setTimeout(t,e))}var Ki=3,qi=4,Ji=240,Yi=16,Xi=8;function z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Zi(e,t){if(!e.startsWith(`#/`))return;let n={$defs:t};for(let t of e.slice(2).split(`/`)){let e=decodeURIComponent(t).replace(/~1/g,`/`).replace(/~0/g,`~`);if(!z(n))return;n=n[e]}return n}function Qi(e){let t=e.type;if(typeof t==`string`)return t;if(Array.isArray(t)){let e=t.filter(e=>typeof e==`string`&&e!==`object`&&e!==`array`);return e.length>0?e.join(`,`):void 0}}function $i(e){let t=new Set,n=[];for(let r of e){let e=JSON.stringify(r);if(!t.has(e)&&(t.add(e),n.push(r),n.length>=qi))break}return n}function ea(e,t,n){if(!z(e))return{};if(typeof e.$ref==`string`){if(t>Xi)return{};let r=Zi(e.$ref,n.defs);return r===void 0?{}:ea(r,t,n)}let r={};if(t===0){let t=e.description;typeof t==`string`&&t.length>0&&(r.description=t.length>Ji?`${t.slice(0,Ji)}…`:t)}let i=Qi(e);i!=null&&(r.type=i);for(let i of[`anyOf`,`oneOf`,`allOf`]){let a=e[i];Array.isArray(a)&&a.length>0&&(r[i]=$i(a.map(e=>ea(e,t,n))))}let a=t>=Ki&&z(e.properties);if(z(e.items)&&(r.items=a?{}:ea(e.items,t+1,n)),z(e.properties)&&!a){let i=Object.keys(e.properties),a=t===0?i:i.slice(0,Yi),o={};for(let r of a)o[r]=ea(e.properties[r],t+1,n);if(r.properties=o,t===0&&Array.isArray(e.required)){let t=e.required.filter(e=>typeof e==`string`&&e in o);t.length>0&&(r.required=t)}}return(r.type===`object`||z(r.properties)||z(e.items)&&r.type!==`array`)&&(r.additionalProperties=!0),r}function ta(e){if(!z(e))return e;let t=ea(e,0,{defs:z(e.$defs)?e.$defs:{}});return z(t)&&Object.keys(t).length===0?{type:`object`,additionalProperties:!0}:t}function na(e){let t=e.properties;if(typeof t!=`object`||!t)return null;for(let e of Object.values(t))if(typeof e==`object`&&e){if(`const`in e&&e.const!=null)return String(e.const);if(Array.isArray(e.enum)&&e.enum.length>0)return String(e.enum[0])}return null}function ra(e){let t=[e.oneOf,e.anyOf].find(e=>Array.isArray(e)&&e.length>0);return t==null?null:t.map((e,t)=>{let n=e??{},r=na(n)??`分支#${t}`,i=Array.isArray(n.required)?n.required.filter(e=>e!==`op`):[];return i.length>0?`${r}(需 ${i.join(`, `)})`:`${r}(无必填)`}).join(` | `)}function ia(e){if(typeof e!=`object`||!e||Array.isArray(e))return JSON.stringify(e)??String(e);let t=Object.keys(e);return t.length>0?`字段 [${t.join(`, `)}]`:`空对象 {}`}function aa(e,t){if(t.oneOf!=null||t.anyOf!=null)return null;let n=t.properties;if(typeof n!=`object`||!n||typeof e!=`object`||!e||Array.isArray(e))return null;let r=new Set(Object.keys(n)),i=Object.keys(e).filter(e=>!r.has(e));return i.length>0?i:null}function oa(e){let t=se(e)[`~standard`],n=ra(e);return{"~standard":{...t,validate(r){let i=t.validate(r);if(!(`issues`in i))return i;let a=``;if(typeof r==`object`&&r&&!Array.isArray(r)){let e=r.op;typeof e==`string`&&(a=`, op='${e}'`)}let o=i.issues.map(e=>typeof e?.message==`string`?e.message:``).filter(Boolean).join(`; `).slice(0,300),s=n==null?``:`该工具按判别字段分发,可选值: ${n}。`,c=aa(r,e);if(c!=null){let t=Object.keys(e.properties);return{issues:[{message:`入参校验失败: 字段 [${c.join(`, `)}] 不被该工具接受,请删掉后重试(其余字段本身合法)。该工具接受: [${t.join(`, `)}]。原始校验: ${o}`}]}}return{issues:[{message:`入参校验失败: 实际收到${ia(r)}${a}。${s}请补齐对应必填字段后重试。原始校验: ${o}`}]}}}}}function sa(e){let t=le(process.execPath,[...process.execArgv,...e??process.argv.slice(1)],{detached:!0,stdio:`ignore`,env:{...process.env,TEXT_TO_DESIGN_MCP_ROLE:`daemon`}});t.unref(),t.on(`error`,e=>{F(`拉起 daemon 失败: ${e.message}`)})}var ca=1500,la=2e4,ua=6e4,da=6e5,fa=5e5,pa=5e3;function ma(e){if(e.length===0)return;let t=e.reduce((e,t)=>e+t.bytes,0),n=e.reduce((e,t)=>t.outputBytes>e.outputBytes?t:e);M(`目录体积: ${e.length} 个工具 / ${(t/1024).toFixed(0)} KB(出参最大 ${n.name} ${(n.outputBytes/1024).toFixed(1)} KB)`);let r=[...t>fa?[`合计 ${(t/1024).toFixed(0)} KB > ${fa/1024} KB`]:[],...e.filter(e=>e.outputBytes>pa).map(e=>`出参 ${e.name} ${(e.outputBytes/1024).toFixed(1)} KB`)];r.length>0&&P(`目录体积超预算(${r.join(` / `)}):下游可能丢工具,检查 compact-schema 的投影深度与工具定义`)}function ha(e){let t=e instanceof Error?e.message:String(e);return/fetch failed|ECONNREFUSED|ECONNRESET|EPIPE|socket hang up|terminated|closed/i.test(t)}function ga(e){let t={};for(let n of e??[]){let e=h.string().describe(n.description??``);t[n.name]=n.required===!0?e:e.optional()}return h.object(t)}async function _a(e){let t=e,n=!1,r=null,i=new ie({name:_i,version:L},{supportedProtocolVersions:[`2026-07-28`,..._],...e.getInstructions()?{instructions:e.getInstructions()}:{},cacheHints:{"tools/list":{ttlMs:0,cacheScope:`private`},"prompts/list":{ttlMs:0,cacheScope:`private`},"resources/list":{ttlMs:0,cacheScope:`private`},"resources/templates/list":{ttlMs:0,cacheScope:`private`},"resources/read":{ttlMs:0,cacheScope:`private`}}}),a=new Map,o=new Map,s=new Map,c=new Map,l=async e=>{try{return await e(t)}catch(r){if(n||!ha(r))throw r;return P(`shim: 上游请求失败,触发重连后重放`),await m(),e(t)}};async function u(){let{tools:e}=await l(e=>e.listTools()),t=new Set,n=[];for(let r of e){t.add(r.name);let e=r.outputSchema?ta(r.outputSchema):void 0,o={title:r.title,description:r.description,annotations:r.annotations,...r.inputSchema?{inputSchema:oa(r.inputSchema)}:{},...e===void 0?{}:{outputSchema:se(e)}},s=JSON.stringify({title:r.title,description:r.description,annotations:r.annotations,inputSchema:r.inputSchema,outputSchema:e});n.push({name:r.name,bytes:s.length,outputBytes:e===void 0?0:JSON.stringify(e).length});let c=a.get(r.name);if(c&&c.raw===s)continue;c?.handle.remove(),a.delete(r.name);let u=i.registerTool.bind(i);try{let e=u(r.name,o,async e=>l(t=>t.callTool({name:r.name,arguments:e??{}})));a.set(r.name,{handle:e,raw:s})}catch(e){P(`工具注册失败(${r.name}): ${e instanceof Error?e.message:String(e)}`)}}ma(n);for(let[e,n]of[...a])t.has(e)||(n.handle.remove(),a.delete(e))}async function d(){let{prompts:e}=await l(e=>e.listPrompts()),t=new Set;for(let n of e){t.add(n.name);let e=JSON.stringify(n),r=o.get(n.name);if(r&&r.raw===e)continue;r?.handle.remove(),o.delete(n.name);let a=i.registerPrompt(n.name,{title:n.title,description:n.description,argsSchema:ga(n.arguments)},e=>l(t=>t.getPrompt({name:n.name,...e?{arguments:e}:{}})));o.set(n.name,{handle:a,raw:e})}for(let[e,n]of[...o])t.has(e)||(n.handle.remove(),o.delete(e))}async function f(){let[{resources:e},{resourceTemplates:t}]=await Promise.all([l(e=>e.listResources()),l(e=>e.listResourceTemplates())]),n=new Set;for(let t of e){let e=t.uri;n.add(e);let r=JSON.stringify(t),a=s.get(e);if(a&&a.raw===r)continue;a?.handle.remove(),s.delete(e);let o=i.registerResource(t.name,e,{title:t.title,description:t.description,mimeType:t.mimeType},async e=>l(t=>t.readResource({uri:e.href})));s.set(e,{handle:o,raw:r})}for(let[e,t]of[...s])n.has(e)||(t.handle.remove(),s.delete(e));let r=new Set;for(let e of t){let t=String(e.uriTemplate);r.add(t);let n=JSON.stringify(e),a=c.get(t);if(a&&a.raw===n)continue;a?.handle.remove(),c.delete(t);let o=i.registerResource(e.name,new ae(t,{list:void 0}),{title:e.title,description:e.description,mimeType:e.mimeType},async(e,t)=>l(t=>t.readResource({uri:e.href})));c.set(t,{handle:o,raw:n})}for(let[e,t]of[...c])r.has(e)||(t.handle.remove(),c.delete(e))}let p=async()=>{let e=await Promise.allSettled([u(),d(),f()]);for(let t of e)t.status===`rejected`&&P(`同步清单失败: ${String(t.reason).slice(0,120)}`)},m=()=>r||(r=(async()=>{let e=Date.now()+la,n=null;for(;Date.now()<e;){try{let e=await Wi();if(e.state===`proxy`){t=e.client,h(t),M(`shim: 上游已恢复`),await p();return}e.state===`none`&&sa()}catch(e){n=e}await Gi(ca)}throw n??Error(`上游重连超时(${la}ms)`)})().finally(()=>{r=null}),r),h=e=>{e.onclose=()=>{n||(P(`shim: 上游断开,自动重连`),m().catch(()=>{}))},e.setNotificationHandler(`notifications/tools/list_changed`,async()=>u().catch(()=>{})),e.setNotificationHandler(`notifications/prompts/list_changed`,async()=>d().catch(()=>{})),e.setNotificationHandler(`notifications/resources/list_changed`,async()=>f().catch(()=>{})),e.setNotificationHandler(`notifications/resources/updated`,async e=>{let t=e.params;t?.uri!=null&&await i.server.sendResourceUpdated({uri:t.uri}).catch(()=>{})})};h(t);let ee=ce(async()=>(await p(),i)),g=L,te=null,ne=null,re=async()=>{let e=await Vi();e!=null&&e.version!==g&&(M(`上游版本变化(${g} → ${e.version}),全量重同步目录`),g=e.version,await p())},oe=()=>{n||(te=setTimeout(()=>{n||re().finally(oe)},ua),te.unref())},le=()=>{n||(ne=setTimeout(()=>{n||p().finally(le)},da),ne.unref())};oe(),le(),M(`shim 模式: stdio → 动态同步,共享 daemon`),process.on(`SIGINT`,async()=>{n=!0,te&&clearTimeout(te),ne&&clearTimeout(ne),await ee.close().catch(e=>{P(`关闭 stdio 失败(忽略): ${e instanceof Error?e.message:String(e)}`)}),await t.close().catch(()=>{}),process.exit(0)})}function va(e=process.env.TEXT_TO_DESIGN_LANG){return Qr(e)??`zh-CN`}function ya(e=va()){return{locale:e,t:Yr(e)}}function B(e){throw Error(e)}var ba=50;async function xa(e){let t=e.trim();t===``&&B(`callsFile 是空路径。请给步骤清单 JSON 的绝对路径。`),u(t)||B(`callsFile 必须是绝对路径(收到「${t}」)。daemon 是常驻进程,相对路径会解析到它自己的工作目录而不是你的项目 —— 所以这里不做推断,请写全路径。`);let n=await he(t).catch(e=>{B(`读不到 callsFile「${t}」:${e instanceof Error?e.message:String(e)}。路径写错了,或文件还没生成。`)});n.isFile()||B(`callsFile「${t}」不是文件(是目录或特殊文件)。`),n.size>Ei&&B(`callsFile「${t}」${(n.size/1024/1024).toFixed(2)} MB,超过上限 ${(Ei/1024/1024).toFixed(0)} MB(可用 TEXT_TO_DESIGN_MCP_MAX_CALLS_FILE_BYTES 覆盖)。请把清单拆成多份分开调用。`);let r=await me(t,`utf8`).catch(e=>{B(`读 callsFile「${t}」失败:${e instanceof Error?e.message:String(e)}。`)}),i;try{i=JSON.parse(r)}catch(e){B(`callsFile「${t}」不是合法 JSON:${e instanceof Error?e.message:String(e)}。文件内容应为 {"calls":[…]} 或直接一个数组。`)}let a=Array.isArray(i)?{calls:i}:i;(typeof a!=`object`||!a||Array.isArray(i))&&B(`callsFile「${t}」的顶层既不是数组也不是对象。两种合法形状:直接给步骤数组,或给 {"calls":[…]}。`);let o=a.calls;Array.isArray(o)||B(`callsFile「${t}」里没有 calls 数组(实际类型 ${o===void 0?`undefined`:typeof o})。文件内容应为 {"calls":[…]} 或直接一个数组。`),o.length===0&&B(`callsFile「${t}」的 calls 是空数组,没有步骤可执行。`),o.length>ba&&B(`callsFile「${t}」有 ${o.length} 步,超过单批上限 ${ba} 步。文件省的是参数体积、不是步骤数预算 —— 请拆成多份清单分开调用(整页改造按块切批还能换来回显清晰与失败隔离)。`);let s=[];for(let[e,n]of o.entries()){let r=mt.safeParse(n);if(!r.success){let n=r.error.issues.map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`).join(`; `);B(`callsFile「${t}」第 ${e+1} 步形状不对:${n}`)}s.push(r.data)}let c=typeof a.stopOnError==`boolean`?a.stopOnError:void 0,l=typeof a.checkDrift==`boolean`?a.checkDrift:void 0;return M(`jsd_batch 从文件读入步骤清单:${t}(${s.length} 步${c===!1?`,stopOnError=false`:``})`),{calls:s,stopOnError:c,checkDrift:l,path:t}}function Sa(e){let t=e.def;if(typeof t==`object`&&t)return t;let n=e._def;return typeof n==`object`&&n?n:void 0}function Ca(e){let t=e.description;if(typeof t==`string`&&t!==``)return t;let n=Sa(e)?.description;return typeof n==`string`&&n!==``?n:void 0}function wa(e,t){m.globalRegistry.add(e,{description:t})}function Ta(e){let t=[];for(let n of[`innerType`,`element`,`valueType`,`keyType`,`in`,`out`,`catchall`,`rest`]){let r=e[n];typeof r==`object`&&r&&t.push(r)}if(Array.isArray(e.options))for(let n of e.options)typeof n==`object`&&n&&t.push(n);if(Array.isArray(e.items))for(let n of e.items)typeof n==`object`&&n&&t.push(n);if(Array.isArray(e.type))for(let n of e.type)typeof n==`object`&&n&&t.push(n);let n=e.shape;if(typeof n==`object`&&n)for(let e of Object.values(n))typeof e==`object`&&e&&t.push(e);if(typeof e.getter==`function`)try{let n=e.getter();typeof n==`object`&&n&&t.push(n)}catch{}return t}function Ea(e,t){let n=new Set,r=e=>{if(typeof e!=`object`||!e||n.has(e))return;n.add(e);let i=e;t(i);let a=Sa(i);if(a!=null)for(let e of Ta(a))r(e)};r(e)}function Da(e,t){return Ea(e,e=>{let n=Ca(e);if(n==null)return;let r=t(n);r!==n&&wa(e,r)}),e}function Oa(e){return{content:[{type:`text`,text:typeof e==`string`?e:JSON.stringify(e,null,2)}]}}function ka(e){return e._def?.typeName}function Aa(e,t){return e._def?.[t]}function ja(e,t){return e._def?.[t]}function V(e){switch(ka(e)){case`ZodObject`:{let t=e.shape;if(typeof t!=`function`)return;let n={};for(let[e,r]of Object.entries(t()))n[e]=V(r);return n}case`ZodArray`:return[];case`ZodBoolean`:return!1;case`ZodNumber`:return 0;case`ZodString`:return``;case`ZodLiteral`:return ja(e,`value`);case`ZodEnum`:return ja(e,`values`)?.[0];case`ZodOptional`:case`ZodDefault`:{let t=Aa(e,`innerType`);return t?V(t):void 0}case`ZodEffects`:{let t=Aa(e,`schema`);return t?V(t):void 0}case`ZodUnion`:{let t=ja(e,`options`)??[],n=t.find(e=>ka(e)===`ZodArray`);return n?V(n):t[0]?V(t[0]):void 0}case`ZodLazy`:{let t=e._def?.getter;return t?V(t()):void 0}default:return}}var Ma={not_connected:{type:`prompt`,prompt:`在当前设计客户端里运行 text-to-design 插件,并确认面板显示「已连接」后重试。`}};function Na(e,t,n){let r=Ma[ye(e)]??n,i={content:[{type:`text`,text:`错误: ${e instanceof Error?e.message:String(e)}`}],isError:!0};return r!==void 0&&(i.followUp=r),t?{...i,structuredContent:V(t)}:i}function Pa(e,t,n,r){if(t){let i=t.safeParse(e);return i.success?{content:[...n??[],...Oa(e).content],structuredContent:i.data,...r===void 0?{}:{followUp:r}}:{content:[{type:`text`,text:`错误: 结果未通过本工具的输出校验 —— ${i.error.issues.map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`).slice(0,8).join(`; `)}\n原始返回:\n${JSON.stringify(e,null,2)}`}],structuredContent:V(t),isError:!0,...r===void 0?{}:{followUp:r}}}return{content:[...n??[],...Oa(e).content],structuredContent:e,...r===void 0?{}:{followUp:r}}}var Fa=new Map;function Ia(e){return Fa.get(e)}function La(){return[...Fa.keys()].sort()}var Ra=8,za=20;function Ba(e){let t=e.shape;if(typeof t!=`object`||!t)return null;let n=Object.keys(t);return n.length>0?n:null}function Va(e,t,n){let r=Ba(e);if(r==null||typeof t!=`object`||!t||Array.isArray(t))return n;let i=Object.keys(t),a=new Set(r),o=i.filter(e=>!a.has(e));return o.length===0?n:`字段 [${o.slice(0,Ra).join(`, `)}]${o.length>Ra?` 等 ${o.length} 个`:``} 不被该工具接受,请删掉后重试(其余字段本身合法)。${r.length<=za?`该工具接受: [${r.join(`, `)}]。`:`该工具接受 ${r.length} 个字段(完整清单见其 schema),本次收到的 [${i.join(`, `)}] 里只有上述字段越界。`}原始校验: ${n}`}function H(e){return(t,n,r)=>{let i=t.registerTool.bind(t),a=e=>e==null||e.type!==`tool`||e.description==null?e:{...e,description:r.t(e.description)},o=(e,t)=>{try{n.notifyActivity(e,t)}catch(e){P(`活动提醒推送失败(已忽略): ${e instanceof Error?e.message:String(e)}`)}},s=async(t,r,i)=>{try{let s=Ii(e);if(s!=null)return F(`工具 ${e.name} 在当前平台不可用,已拦截`),Na(new v(`platform_unsupported`,s),e.outputSchema,a(e.followUp));if(e.inputSchema!=null){let n=e.inputSchema.safeParse(t);if(!n.success){let r=n.error.issues.map(e=>`${e.path.join(`.`)||`(root)`}: ${e.message}`).join(`; `);throw new v(`invalid_args`,`参数校验失败(${e.name}): ${Va(e.inputSchema,t,r)}`)}t=n.data}let c={...r==null?{}:{signal:r},...e.timeout==null?{}:{timeout:e.timeout}};o(`running`,e.name);let l=i?.skipHooks===!0?void 0:e.hook?.();if(l?.before!=null)try{await l.before(t)}catch(t){P(`工具 ${e.name} 的前置钩子失败(已忽略): ${t instanceof Error?t.message:String(t)}`)}let u;u=e.run?await e.run(t,n,r??new AbortController().signal):await n.request(e.method,e.payload?e.payload(t):t,c);let d=e.extraContent?e.extraContent(u,t):[],f=[],p=u?.warnings;if(Array.isArray(p))for(let e of p)typeof e==`string`&&e!==``&&f.push(e);if(l?.after!=null)try{let e=await l.after(t,u)??[];for(let t of e)f.push(t),d.push({type:`text`,text:t})}catch(t){let n=`⚠ 工具 ${e.name} 的后置钩子失败(不影响本次结果): ${t instanceof Error?t.message:String(t)}`;f.push(n),d.push({type:`text`,text:n})}let m=Pa(u,e.outputSchema,d.length>0?d:void 0,a(e.followUp));return o(`success`,e.name),f.length>0?{...m,warnings:f}:m}catch(t){let n=t instanceof Error?t.message:String(t);return F(`工具 ${e.name} 执行失败: ${n.slice(0,200)}`),o(`error`,e.name),Na(t,e.outputSchema,a(e.followUp))}};Fa.set(e.name,s);let{t:c}=r,l=i(e.name,{title:c(e.title),description:e.platformNote==null?c(e.description):`${c(e.description)}${c(e.platformNote)}`,...e.inputSchema?{inputSchema:Da(e.inputSchema,c)}:{},outputSchema:Da(e.outputSchema,c),annotations:e.annotations},async(...t)=>{let n=e.inputSchema!=null,r=t[0],i=t[1],a=n?r??{}:{},o=n?i:r,c=o?.mcpReq?.signal??o?.signal;return s(a,c)});return l.alwaysEnabled=e.alwaysEnabled??!1,l}}function Ha(e,t){let n=e;for(let e of t.split(`.`)){let t=/^([\w$\u4e00-\u9fff-]*)((?:\[\d+\])*)$/.exec(e.trim());if(t==null)return{ok:!1};if(t[1]!==``){if(Array.isArray(n)&&n.length===1&&(n=n[0]),typeof n!=`object`||!n)return{ok:!1};n=n[t[1]]}if(t[2]!==``)for(let e of t[2].matchAll(/\[(\d+)\]/g)){let t=Number(e[1]);if(!Array.isArray(n)){if(t===0&&typeof n==`object`&&n)continue;return{ok:!1}}n=n[t]}}return{ok:!0,value:n}}var Ua=class extends Error{constructor(e){super(e),this.name=`StepFailedRefError`}};function Wa(e,t,n){let r=e.indexOf(`.`),i=r===-1?e:e.slice(0,r),a=r===-1?``:e.slice(r+1);if(!t.has(i)){let r=[...t.keys()].join(`, `)||`无`;throw n.has(i)?new Ua(`占位符「${e}」引用的步骤「${i}」执行失败,本步未执行。修掉那一步,或用 stopOnError=false / 该步 continueOnError=true 跳过引用它的步骤(已成功的步骤: ${r})`):Error(`占位符引用的步骤不存在或未成功:「${e}」(已完成: ${r})`)}let o=t.get(i);if(a===``)return o;let s=Ha(o,a);if(!s.ok)throw Error(`无法解析占位符引用「${e}」:请核对步骤 ${i} 的返回结构`);return s.value}var Ga=/^@(comp|var):([\s\S]+)$/;function Ka(e,t,n){let r=t.trim(),i=e===`comp`?`组件/变体集`:`变量`,a=n.filter(e=>e.name===r),o=a.length>0?a:n.filter(e=>e.name.trim().toLowerCase()===r.toLowerCase());if(o.length===1)return o[0].id;if(o.length>1)throw Error(`按名字取${i}「${t}」撞上 ${o.length} 个同名资源:${o.map(e=>`${e.name}(${e.id})`).join(`、`)}。名字不唯一时改用 id 直接写,或先重命名(0041:不确定就点名,绝不猜)。`);let s=n.slice(0,30).map(e=>e.name);throw Error(`按名字取${i}「${t}」没命中。${s.length===0?`这一面当前读不到任何${i}(两种原因都可能:本平台未声明该能力面,或本平台读不到非当前页 —— 到底哪种见 jsd_get_page 回包的 note)`:`现有${i}:${s.join(`、`)}${n.length>s.length?` …`:``}`};也可以直接写 id。`)}async function qa(e,t,n){let r=await n();return Ka(e,t,e===`comp`?[...r.components??[],...r.variants??[]]:r.variables??[])}var Ja=/\{\{\s*([^{}]+?)\s*\}\}/g,Ya=/^\{\{\s*([^{}]+?)\s*\}\}$/,Xa=[`id`,`name`,`type`,`x`,`y`,`width`,`height`,`z`,`parentId`],Za=new Set([`vectorPaths`,`constraints`,`absoluteBoundingBox`,`absoluteRenderBounds`]),Qa=2e4;function $a(e){try{return JSON.stringify(e)?.length??0}catch{return 0}}var eo=[`x`,`y`,`width`,`height`,`parentId`];function to(e){return typeof e.id!=`string`||typeof e.type!=`string`||typeof e.name!=`string`?!1:eo.some(t=>e[t]!==void 0)}function no(e){if(Array.isArray(e))return e.map(no);if(typeof e!=`object`||!e)return e;let t=e;if(to(t)){let e={};for(let n of Xa)t[n]!==void 0&&(e[n]=t[n]);return e}let n={};for(let[e,r]of Object.entries(t))Za.has(e)||(n[e]=no(r));return n}function ro(e,t){if(Array.isArray(e)){for(let n of e)ro(n,t);return}if(typeof e==`object`&&e)for(let[n,r]of Object.entries(e)){if(n===`id`&&typeof r==`string`){t.push(r);continue}ro(r,t)}}function io(e,t){let n=no(e),r=$a(n);if(r<=Qa)return{data:n,trimmed:r!==$a(e),omitted:!1};let i=[];return ro(n,i),{data:{echoOmitted:!0,note:`本步回显裁剪后仍 ${r} 字符,已省略明细;需要细节请把 ${t} 单独调用一次`,ids:[...new Set(i)]},trimmed:!0,omitted:!0}}function ao(e,t,n){let r=[`回显已裁剪:${e.length} 步(${e.join(` / `)})的节点只保留 id/name/type/x/y/width/height/z/parentId`,` —— 子节点、characters、fills、*StyleId、vectorPaths 等字段不在回显里。`,`要读这些字段,请把对应工具**单独调用一次**;批内回显不是验收证据。`,"占位符 `{{步骤id.…}}` 不受影响,它取的是裁剪前的完整数据。"];return t.length>0&&r.push(n==null?`其中 ${t.length} 步(${t.join(` / `)})连摘要都超预算,已降级为 id 清单,步骤内的 note 已点名工具名。`:`其中 ${t.length} 步(${t.join(` / `)})连摘要都超预算,完整明细已落盘到 ${n.path}(${n.bytes} 字节,JSONL 一行一步),按各步 data 里的 line 读即可。`),r.join(``)}var oo=0;function so(e,t){let n=[],r=new Map;for(let i of e)r.set(i.id,n.length+1),n.push(JSON.stringify(i.ok?{id:i.id,tool:i.tool,ok:!0,data:t.get(i.id)}:{id:i.id,tool:i.tool,ok:!1,error:i.error}));let i=`${n.join(`
|
|
38
|
+
`)}\n`,a=Buffer.byteLength(i,`utf8`);if(a>Di)return{error:`明细 ${a} 字节 > 上限 ${Di} 字节`};let s=d(c(),`jsd-batch-${Date.now().toString(36)}-${++oo}.jsonl`);try{o(s,i,`utf8`)}catch(e){return{error:`写盘失败:${e instanceof Error?e.message:String(e)}`}}return{path:s,bytes:a,line:r}}async function co(e,t,n,r){let i=async e=>{let i=Ga.exec(e.trim());return i==null?Wa(e,t,r):qa(i[1],i[2],n)};if(typeof e==`string`){let t=Ya.exec(e.trim());if(t!=null)return i(t[1]);let n=``,r=0;for(let t of e.matchAll(Ja)){n+=e.slice(r,t.index);let a=await i(t[1]);n+=typeof a==`string`?a:JSON.stringify(a),r=(t.index??0)+t[0].length}return r===0?e:n+e.slice(r)}if(Array.isArray(e)){let i=[];for(let a of e)i.push(await co(a,t,n,r));return i}if(typeof e==`object`&&e){let i={};for(let[a,o]of Object.entries(e))i[a]=await co(o,t,n,r);return i}return e}function lo(e,t,n){return[H({name:`jsd_batch`,title:`batch.title`,description:`batch.description`,inputSchema:ht,outputSchema:gt,annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_get_selection`,description:`batch.followUp`},timeout:Ti,run:async(e,t,n)=>{let{calls:r,callsFile:i,stopOnError:a,checkDrift:o}=e,s=i==null||i.trim()===``?null:await xa(i);if(s!=null&&r!=null)throw Error(`calls 与 callsFile 只能给一个:calls 在本批内直接执行,callsFile 从文件读同一份清单。两个都给会让「哪份生效」变成猜。`);if(s==null&&r==null)throw Error(`需要 calls 或 callsFile 其中一个(都缺省时没有步骤可执行)。参数体大到写不进上下文时,把清单写进 JSON 文件、这里只传它的绝对路径。`);let c=s?.calls??r??[],l=s?.stopOnError??a,u=s?.checkDrift??o,d=new Map,f=[],p=!1,m=[],h=[],ee=u===!1,g=[],te,ne=()=>(te??=(async()=>(await t.request(`get_page`,{},{...n==null?{}:{signal:n}}))?.assets??{})(),te),re=new Set;for(let e=0;e<c.length;e++){let t=c[e],r=t.id==null||t.id.trim()===``?`step${e+1}`:t.id.trim(),i=e=>{re.add(r),f.push({id:r,tool:t.tool,ok:!1,error:e})};if(d.has(r)||f.some(e=>e.id===r)){i(`步骤 id "${r}" 重复`);break}let a=Ia(t.tool);if(a==null){i(`未知工具 ${t.tool},可用: ${La().join(`, `)}`);break}let o;try{o=await co(t.args??{},d,ne,re)}catch(e){if(i(e instanceof Error?e.message:String(e)),e instanceof Ua&&(l===!1||t.continueOnError===!0))continue;break}let s=await a(o,n,{skipHooks:ee});if(s.isError===!0){if(i((s.content?.find(e=>e.type===`text`)?.text??`工具返回错误`).slice(0,300)),l!==!1&&t.continueOnError!==!0)break;continue}let u=io(s.structuredContent,t.tool);u.trimmed&&(p=!0,m.push(r)),u.omitted&&h.push(r),d.set(r,s.structuredContent),s.warnings!=null&&g.push(...s.warnings),f.push({id:r,tool:t.tool,ok:!0,data:u.data})}let ie=f.length===c.length,ae=g,_=h.length===0?void 0:so(f,d),oe=_!=null&&`error`in _?void 0:_;if(_!=null&&`error`in _&&ae.push(`本批有 ${h.length} 步回显超预算,但完整明细未落盘(${_.error});已保留 id 清单,要明细请把对应工具单独调用一次。`),oe!=null)for(let e of f){if(!h.includes(e.id))continue;let t=e.data,n=oe.line.get(e.id);t!=null&&t.echoOmitted===!0&&n!=null&&(e.data={...t,path:oe.path,line:n,note:`本步明细已随整批落盘(第 ${n} 行);也可把 ${e.tool} 单独调用一次。`})}return{ok:ie&&f.every(e=>e.ok),executed:f.length,total:c.length,results:f,...p?{echoTrimmed:!0}:{},...p?{echoNote:ao(m,h,oe)}:{},...ae.length>0?{warnings:ae}:{}}}})(e,t,n)]}function uo(e){return e==null?x:[e]}function U(e){return Kt[e]}function fo(e,t){return j(e,t)?.fallback??`(替代路径未登记 —— 能力位与事实表不一致,请复核)`}function po(e,t){let n=e=>{let t=e==null?null:j(e,`variants`)?.setLevelOps;return t==null||t.length===0?``:`造新维度/新取值不用绕实例:本平台有集合级管理入口(${t.join(` / `)})—— 先 mg_list_variant_properties 看现状,再建维度/加成分/改取值,每个 op 都写完回读(各自的行为注意写在它的描述里,调用前读一眼);换绑(jsd_set_instance_properties)只负责切到**已有**成分。`};if(e!=null&&t!=null){let r=j(e,`variants`),i=r?.read,a=r?.write.includes(`jsd_set_instance_properties`)===!0,o=i==null?``:a?`文档里**已有**的变体集不受影响:\`${i}\` 与组件集上的维度取值照常读得到,已有取值照常用 jsd_set_instance_properties 切 —— 缺的只是「用脚本造一个新的」;`:`文档里**已有**的变体集读得到:\`${i}\` 与组件集上的维度取值照常可读,但**实例侧切值本平台运行期没有可用入口**(引擎声明了 setProperties / swapComponent,实测分别是「not a function」与内部错误)—— 变体取值只能在画布上手工切换;**读得到 ≠ 切得动**;`,s=t?`${U(e)}声明了原位合并(inPlaceVariants) ⇒ 直接调用即可:并入集合的就是实例所指的 COMPONENT 本身,已有实例链接不断、页面不残留冗余原件,不需要先克隆。`:`${U(e)}未声明原位合并(inPlaceVariants),合成路径在本平台做不出来 —— 别重试、也别去改组件结构。${o}替代路径:${fo(e,`variants`)}。`,c=n(e);return c===``?s:`${s}${c}`}let r=x.filter(e=>j(e,`variants`)?.fallback!=null),i=x.filter(e=>!r.includes(e));return[`按能力位 ${ei.variants} 分流(当前平台声明了没有,以 jsd_ping 的 capabilities 或 jsd://platform/state 为准):`,`声明了它的平台走原位合并,直接调即可(如 ${i.map(U).join(` / `)});`,`未声明的平台(如 ${r.map(U).join(` / `)} 这类)合成路径做不出来,别重试也别去改组件结构,改用替代路径:${r.length>0?fo(r[0],`variants`):`(未登记)`}`,`。另外,有的平台还提供**集合级**管理入口(建维度 / 加成分 / 改取值 / 删维度),名单在 jsd_ping 的 platformOps 里 —— 有它就别靠「改成分名字」这类副作用去造新值。`].join(``)}function mo(e){if(e==null)return uo(null).map(e=>{let t=Ke(e,`setProperties`),n=j(e,`components`),r=n?.read==null?`读不到 componentProperties`:`读 ${n.read}`;return`${U(e)} 收 ${t?.join(` / `)??`(未探测)`}(${r})`}).join(`;`);let t=j(e,`components`),n=Ke(e,`setProperties`),r=[n==null?`值形态未探测(先读 jsd://platform/state)`:`setProperties 签名收 ${n.join(` / `)}`];return t!=null&&(r.push(t.write.length>0?`写入口:${t.write.join(` / `)}`:`没有可用写入口`),r.push(t.read==null?`读侧无 componentProperties(能力位 ${ei.components} 未声明),只能读 variantProperties`:`读侧读 ${t.read} —— 组件属性传读到的**完整键**(短名只在基名唯一时被 core 补齐),变体属性传名字`),t.fallback!=null&&r.push(`替代路径:${t.fallback}`)),r.join(`;`)}function ho(e){if(e!=null){let t=j(e,`variables`);if(t==null)return`${U(e)}的变量面未登记。`;if(t.write.length>0)return`${U(e)}有变量面:读路径 \`${t.read}\`,写入口 ${t.write.map(e=>`\`${e}\``).join(` → `)}。`;if(t.nativeUnwired.length>0){let n=t.read==null?``:`本仓只接了**只读枚举**(读路径 \`${t.read}\`,进 jsd_get_page 的资源清单),`;return`${U(e)}的 typings 里有变量 API(${t.nativeUnwired.length} 类入口),${n}**写入口一个都没接** —— 属「可以接、只是还没接」,不是平台没有。替代路径:${fo(e,`variables`)}`}return`${U(e)}**没有变量能力面**(typings 里没有任何变量声明),别去找变量 op。替代路径:${fo(e,`variables`)}`}let t=x.filter(e=>(j(e,`variables`)?.write.length??0)>0),n=x.filter(e=>(j(e,`variables`)?.write.length??0)===0&&(j(e,`variables`)?.nativeUnwired.length??0)>0),r=x.filter(e=>!t.includes(e)&&!n.includes(e));return[`变量三平台差别最大,别一句话糊过去:读写都通的 —— ${t.map(e=>{let t=j(e,`variables`),n=(t?.write??[]).map(e=>`\`${e}\``).join(` → `);return`${U(e)} 读 \`${t?.read}\`、写 ${n||`(无)`}`}).join(`;`)};`,`typings 有 API 但本仓未接的(${n.map(U).join(` / `)||`无`})—— 属「可以接」;`,`连 API 都没有的(${r.map(U).join(` / `)||`无`})—— 属「接不了」。`,`别把后两者当一回事:前者换个版本就能接,后者得换平台。`].join(``)}function go(e){return e===`mastergo`?"- 一次调用带多组:`bindings: [{ nodeIds, property, value, variableId?, index?, unbind? }]`,一组 = 一个变量 × 一个槽位 × 一批节点;槽位取值见 `mg_variables_apply` 的描述,传错会在入参校验就点名,数组型属性另给 `index`,不要一个节点一次调用;":e===`figma`?"- 一次调用带多组:`bindings: [{ nodeIds, boundProperty, variableId?, subField?, index?, unbind? }]`,一组 = 一个变量 × 一个字段 × 一批节点,不要一个节点一次调用;节点级字段直接写字段名,fills / strokes 绑在 paint 上,index 省略即该数组全部 SOLID 项,effects / layoutGrids 另给 `subField` + `index`;":"- 绑定一次传多个 `nodeIds`,参数词汇以本平台变量面给的为准,不要一个节点一次调用;"}function _o(e){return e===`mastergo`?["- ⚠ MG **没有**「图层属性 ↔ 变量」的反读接口:回读只能拿到该图层用到的集合与模式(见 `mg_list_variables`),它证明「集合挂上了」、证不了「挂在该属性上」;","- 所以绑数组属性(fills / effects / grids)**必须**自己给 `index`,并 jsd_export({ids:[节点id], scale=0.5}) 目视确认渲染真的变了 —— 这一条别省。"].join(`
|
|
39
39
|
`):e===`figma`?[`- 回读节点上的绑定,比对里面的 variableId 与你要绑的是同一个 —— **回显成功不等于绑上了**;`,`- 涉及视觉的改动再 jsd_export({ids:[节点id], scale=0.5}) 导小图目检一次;`].join(`
|
|
40
40
|
`):`- 回读本平台提供的绑定读面,比对里面的 variableId 与你要绑的是同一个 —— **回显成功不等于绑上了**;`}function vo(e){return e===`mastergo`?["- MG 的节点上**没有**绑定字段可读:`mg_list_variables` 给出集合 / 模式 / 变量及它们的值,某图层用了哪些集合看 `getLayerVariableModes`;","- 变量 id 取自 `mg_list_variables` 或 `jsd_get_page` 的 `assets.variables`,**可直接回喂**写入口,不用改名、不用补名称。"].join(`
|
|
41
41
|
`):e===`figma`?[`- 读节点上的变量绑定(字段名见上一节):键是引擎的可绑定字段名,值的三态由引擎决定 —— 标量字段是单个别名;fills / strokes / effects / layoutGrids / textRangeFills 是别名数组;componentProperties 是按属性名索引的别名表。**键在 = 至少有一条绑定**(无绑定或平台不提供该字段时整个键省略)。`,"- 库存与模式走 `figma_variables_list`(集合 / 模式 / 各变量的值);读路径就是写侧的 `boundProperty` 词汇,值里的 id **可直接回喂**写入口,不用改名、不用补名称。",`- 引擎口径原样保留:有**独立圆角**的节点上,圆角绑定会表现为 topLeftRadius / topRightRadius / bottomLeftRadius / bottomRightRadius 四条(不归一成 cornerRadius)。`].join(`
|
|
@@ -53,7 +53,7 @@ Result keys per op (needed to write correct jsd_batch placeholders; a wrong key
|
|
|
53
53
|
`).map(e=>e.trim()).filter(Boolean);e.w=Math.min(o,Math.max(...r.map(e=>zo(e,t)),t)),e.h=r.length*Po(n,t),c=e.h}else{let t=Fo(n),i=Io(n),o=Lo(n),l=K(n,`width`),u=K(n,`height`);if(l!=null&&(s=Math.max(0,l-r.left-r.right-a.width*2)),t&&i===`row`){let t=0,n=0;for(let i of e.children){let e=Wo(i,s-t);i.x=t+r.left+a.width,i.y=r.top+a.width,i.isText&&Ro(i.style)!==`left`&&(i.w=s-t),t+=e.width,t+=o,n=Math.max(n,e.height)}c=n,e.w=t-(e.children.length?o:0)}else{let t=0,n=0;for(let i of e.children){let e=Wo(i,s);i.x=r.left+a.width,i.y=t+r.top+a.width,i.isText&&Ro(i.style)!==`left`&&(i.w=s),t+=e.height,t+=o,n=Math.max(n,e.width)}c=t-(e.children.length?o:0),e.w=n}e.w=l??e.w,e.h=u??c,c=u??c}let l=r.left+r.right+a.width*2,u=r.top+r.bottom+a.width*2;return K(n,`width`)??(e.w+=l),K(n,`height`)==null&&!e.isText&&(e.h+=u),{width:e.w+i.left+i.right,height:e.h+i.top+i.bottom}}function Go(e){let t=ko(e.style);e.x+=t.left,e.y+=t.top}function Ko(e,t,n){let r=[];return qo(e,r,0,0),`<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${n}" viewBox="0 0 ${t} ${n}">${r.join(``)}</svg>`}function qo(e,t,n,r){let i=e.style,a=n+e.x,o=r+e.y,s=e.w,c=e.h;if(e.isText){let n=Mo(i),r=Oo(i.color,`#000000`),c=i[`font-family`]??`sans-serif`,l=No(i),u=Ro(i),d=u===`center`?`middle`:u===`right`?`end`:`start`,f=u===`center`?a+s/2:u===`right`?a+s:a,p=Po(i,n);(e.text??``).split(`
|
|
54
54
|
`).filter(e=>e.trim()).forEach((e,i)=>{t.push(`<text x="${f.toFixed(1)}" y="${(o+p*i+n).toFixed(1)}" font-size="${n}" font-family="${c}" font-weight="${l}" fill="${r}" text-anchor="${d}">${Jo(e)}</text>`)});return}let l=Oo(i.background??i[`background-color`],e.tag===`img`?Eo:void 0),u=jo(i),d=G(i[`border-radius`])??0,f=l&&l!==`none`;if(e.tag===`img`||f||u.width>0){let e=[`x="${a.toFixed(1)}"`,`y="${o.toFixed(1)}"`,`width="${Math.max(0,s).toFixed(1)}"`,`height="${Math.max(0,c).toFixed(1)}"`];d>0&&e.push(`rx="${d}"`),f&&e.push(`fill="${l}"`),u.width>0&&e.push(`stroke="${u.color}" stroke-width="${u.width}"`),t.push(`<rect ${e.join(` `)} />`)}for(let n of e.children)Go(n),qo(n,t,a,o)}function Jo(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`)}function Yo(e){let t=_e(e,{decodeEntities:!0}).children.filter(e=>ge(e)),n=t.find(e=>e.tagName===`body`)??t[0];if(!n)return`<svg xmlns="http://www.w3.org/2000/svg" width="1" height="1" viewBox="0 0 1 1"></svg>`;let r=Ho(n,!0),i=Do(n.attribs.style),a=K(i,`width`),o=K(i,`height`),s=Wo(r,a??800),c=a??Math.min(s.width,1600),l=o??s.height;return r.x=0,r.y=0,a??(r.w=c),o??(r.h=l),Ko(r,c,l)}var Xo={"activity-square":`square-activity`,"alarm-check":`alarm-clock-check`,"alarm-minus":`alarm-clock-minus`,"alarm-plus":`alarm-clock-plus`,album:`square-bookmark`,"alert-circle":`circle-alert`,"alert-octagon":`octagon-alert`,"alert-triangle":`triangle-alert`,"align-center":`text-align-center`,"align-justify":`text-align-justify`,"align-left":`text-align-start`,"align-right":`text-align-end`,angry:`face-angry`,annoyed:`face-expressionless`,"area-chart":`chart-area`,"arrow-down-01":`arrow-down-0-1`,"arrow-down-10":`arrow-down-1-0`,"arrow-down-az":`arrow-down-a-z`,"arrow-down-circle":`circle-arrow-down`,"arrow-down-left-from-circle":`circle-arrow-out-down-left`,"arrow-down-left-from-square":`square-arrow-out-down-left`,"arrow-down-left-square":`square-arrow-down-left`,"arrow-down-right-from-circle":`circle-arrow-out-down-right`,"arrow-down-right-from-square":`square-arrow-out-down-right`,"arrow-down-right-square":`square-arrow-down-right`,"arrow-down-square":`square-arrow-down`,"arrow-down-za":`arrow-down-z-a`,"arrow-left-circle":`circle-arrow-left`,"arrow-left-square":`square-arrow-left`,"arrow-right-circle":`circle-arrow-right`,"arrow-right-square":`square-arrow-right`,"arrow-up-01":`arrow-up-0-1`,"arrow-up-10":`arrow-up-1-0`,"arrow-up-az":`arrow-up-a-z`,"arrow-up-circle":`circle-arrow-up`,"arrow-up-left-from-circle":`circle-arrow-out-up-left`,"arrow-up-left-from-square":`square-arrow-out-up-left`,"arrow-up-left-square":`square-arrow-up-left`,"arrow-up-right-from-circle":`circle-arrow-out-up-right`,"arrow-up-right-from-square":`square-arrow-out-up-right`,"arrow-up-right-square":`square-arrow-up-right`,"arrow-up-square":`square-arrow-up`,"arrow-up-za":`arrow-up-z-a`,"asterisk-square":`square-asterisk`,"axis-3-d":`axis-3d`,"badge-help":`badge-question-mark`,"bar-chart":`chart-no-axes-column-increasing`,"bar-chart-2":`chart-no-axes-column`,"bar-chart-3":`chart-column`,"bar-chart-4":`chart-column-increasing`,"bar-chart-big":`chart-column-big`,"bar-chart-horizontal":`chart-bar`,"bar-chart-horizontal-big":`chart-bar-big`,"between-horizonal-end":`between-horizontal-end`,"between-horizonal-start":`between-horizontal-start`,"book-marked":`book-bookmark`,"book-template":`book-dashed`,"box-select":`square-dashed`,"building-2":`building-complex`,"candlestick-chart":`chart-candlestick`,"check-circle":`circle-check-big`,"check-circle-2":`circle-check`,"check-square":`square-check-big`,"check-square-2":`square-check`,"chevron-down-circle":`circle-chevron-down`,"chevron-down-square":`square-chevron-down`,"chevron-left-circle":`circle-chevron-left`,"chevron-left-square":`square-chevron-left`,"chevron-right-circle":`circle-chevron-right`,"chevron-right-square":`square-chevron-right`,"chevron-up-circle":`circle-chevron-up`,"chevron-up-square":`square-chevron-up`,"circle-help":`circle-question-mark`,"circle-slashed":`circle-slash-2`,"clipboard-edit":`clipboard-pen`,"clipboard-signature":`clipboard-pen-line`,"code-2":`code-xml`,"code-square":`square-code`,columns:`columns-2`,"columns-settings":`columns-3-cog`,"contact-2":`contact-round`,"curly-braces":`braces`,"divide-circle":`circle-divide`,"divide-square":`square-divide`,"dot-square":`square-dot`,"download-cloud":`cloud-download`,edit:`square-pen`,"edit-2":`pen`,"edit-3":`pen-line`,"equal-square":`square-equal`,"file-audio":`file-headphone`,"file-audio-2":`file-headphone`,"file-axis-3-d":`file-axis-3d`,"file-badge-2":`file-badge`,"file-bar-chart":`file-chart-column-increasing`,"file-bar-chart-2":`file-chart-column`,"file-check-2":`file-check-corner`,"file-code-2":`file-code-corner`,"file-cog-2":`file-cog`,"file-edit":`file-pen`,"file-json":`file-braces`,"file-json-2":`file-braces-corner`,"file-key-2":`file-key`,"file-line-chart":`file-chart-line`,"file-lock-2":`file-lock`,"file-minus-2":`file-minus-corner`,"file-pie-chart":`file-chart-pie`,"file-plus-2":`file-plus-corner`,"file-question":`file-question-mark`,"file-search-2":`file-search-corner`,"file-signature":`file-pen-line`,"file-type-2":`file-type-corner`,"file-video":`file-play`,"file-video-2":`file-video-camera`,"file-volume-2":`file-signal`,"file-warning":`file-exclamation-point`,"file-x-2":`file-x-corner`,filter:`funnel`,"filter-x":`funnel-x`,fingerprint:`fingerprint-pattern`,"flip-horizontal":`square-centerline-dashed-horizontal`,"flip-horizontal-2":`triangles-centerline-dashed-horizontal`,"flip-vertical":`square-centerline-dashed-vertical`,"flip-vertical-2":`triangles-centerline-dashed-vertical`,"folder-cog-2":`folder-cog`,"folder-edit":`folder-pen`,"fork-knife":`utensils`,"fork-knife-crossed":`utensils-crossed`,"form-input":`rectangle-ellipsis`,frown:`face-slightly-frowning`,"function-square":`square-function`,"gantt-chart":`chart-no-axes-gantt`,"gantt-chart-square":`square-chart-gantt`,"gauge-circle":`circle-gauge`,"git-commit":`git-commit-horizontal`,"globe-2":`earth`,grab:`hand-grab`,grid:`grid-3x3`,"grid-2-x-2":`grid-2x2`,"grid-2-x-2-check":`grid-2x2-check`,"grid-2-x-2-plus":`grid-2x2-plus`,"grid-2-x-2-x":`grid-2x2-x`,"grid-3-x-3":`grid-3x3`,"help-circle":`circle-question-mark`,"helping-hand":`hand-helping`,history:`rotate-ccw-clock`,home:`house`,"ice-cream":`ice-cream-cone`,"ice-cream-2":`ice-cream-bowl`,indent:`list-indent-increase`,"indent-decrease":`list-indent-decrease`,"indent-increase":`list-indent-increase`,inspect:`square-mouse-pointer`,"kanban-square":`square-kanban`,"kanban-square-dashed":`square-dashed-kanban`,"laptop-2":`laptop-minimal`,laugh:`face-grinning`,"layers-3":`layers`,layout:`panels-top-left`,"letter-text":`text-initial`,"library-square":`square-library`,"line-chart":`chart-line`,"loader-2":`loader-circle`,"location-edit":`map-pin-pen`,"m-square":`square-m`,"mail-question":`mail-question-mark`,meh:`face-neutral`,"menu-square":`square-menu`,"message-circle-question":`message-circle-question-mark`,"mic-2":`mic-vocal`,"minus-circle":`circle-minus`,"minus-square":`square-minus`,"more-horizontal":`ellipsis`,"more-vertical":`ellipsis-vertical`,"mouse-pointer-square-dashed":`square-dashed-mouse-pointer`,"move-3-d":`move-3d`,outdent:`list-indent-decrease`,"paintbrush-2":`paintbrush-vertical`,palmtree:`tree-palm`,"panel-bottom-inactive":`panel-bottom-dashed`,"panel-left-inactive":`panel-left-dashed`,"panel-right-inactive":`panel-right-dashed`,"panel-top-inactive":`panel-top-dashed`,"panels-left-right":`columns-3`,"panels-top-bottom":`rows-3`,"parking-circle":`circle-parking`,"parking-circle-off":`circle-parking-off`,"parking-square":`square-parking`,"parking-square-off":`square-parking-off`,"pause-circle":`circle-pause`,"pause-octagon":`octagon-pause`,"pen-box":`square-pen`,"pen-square":`square-pen`,"percent-circle":`circle-percent`,"percent-diamond":`diamond-percent`,"percent-square":`square-percent`,"pi-square":`square-pi`,"pie-chart":`chart-pie`,"pilcrow-square":`square-pilcrow`,"play-circle":`circle-play`,"play-square":`square-play`,"plug-zap-2":`plug-zap`,"plus-circle":`circle-plus`,"plus-square":`square-plus`,podcast:`mic-signal`,"power-circle":`circle-power`,"power-square":`square-power`,"rotate-3-d":`rotate-3d`,rows:`rows-2`,"scale-3-d":`scale-3d`,"scatter-chart":`chart-scatter`,"school-2":`university`,"scissors-square":`square-scissors`,"scissors-square-dashed-bottom":`square-bottom-dashed-scissors`,"send-horizonal":`send-horizontal`,"shield-close":`shield-x`,"shield-question":`shield-question-mark`,sidebar:`panel-left`,"sidebar-close":`panel-left-close`,"sidebar-open":`panel-left-open`,"sigma-square":`square-sigma`,"slash-square":`square-slash`,sliders:`sliders-vertical`,smile:`face-slightly-smiling`,"smile-plus":`face-slightly-smiling-plus`,"sort-asc":`arrow-up-narrow-wide`,"sort-desc":`arrow-down-wide-narrow`,"split-square-horizontal":`square-split-horizontal`,"split-square-vertical":`square-split-vertical`,"square-gantt-chart":`square-chart-gantt`,stars:`sparkles`,"stop-circle":`circle-stop`,subtitles:`captions`,"table-config":`columns-3-cog`,"terminal-square":`square-terminal`,"test-tube-2":`test-tube-diagonal`,text:`text-align-start`,"text-select":`square-dashed-text`,"text-selection":`square-dashed-text`,train:`tram-front`,"trash-2":`trash`,"tv-2":`tv-minimal`,unlock:`lock-open`,"unlock-keyhole":`lock-keyhole-open`,"upload-cloud":`cloud-upload`,"user-2":`user-round`,"user-check-2":`user-round-check`,"user-circle":`circle-user`,"user-circle-2":`circle-user-round`,"user-cog-2":`user-round-cog`,"user-minus-2":`user-round-minus`,"user-plus-2":`user-round-plus`,"user-square":`square-user`,"user-square-2":`square-user-round`,"user-x-2":`user-round-x`,"users-2":`users-round`,verified:`badge-check`,"wallet-2":`wallet-minimal`,"wand-2":`wand-sparkles`,waves:`waves-horizontal`,"wrap-text":`text-wrap`,"x-circle":`circle-x`,"x-octagon":`octagon-x`,"x-square":`square-x`},Zo=e(import.meta.url);function Qo(e){return e.toLowerCase().replace(/[^a-z0-9]/g,``)}var $o=JSON.parse(r(Zo.resolve(`lucide-static/icon-nodes.json`),`utf8`)),es=JSON.parse(r(Zo.resolve(`lucide-static/tags.json`),`utf8`)),q=new Map;for(let[e,t]of Object.entries($o))q.set(e,{name:e,nodes:t,keywords:es[e]??[]});q.size;var ts=new Map;for(let[e,t]of Object.entries(es))t.forEach((t,n)=>{let r=ts.get(t)??[];r.push({name:e,idx:n}),ts.set(t,r)});var ns=new ve([...q.values()],{keys:[{name:`name`,weight:1}],threshold:.45,ignoreLocation:!0,minMatchCharLength:2,includeScore:!0});function rs(e,t){let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;return n}function is(e){let t=e.trim().toLowerCase();if(!t)return null;let n=q.get(t);if(n)return n;let r=Xo[t];if(r){let e=q.get(r);if(e)return e}let i=Qo(t),a=ns.search(t,{limit:8}).filter(e=>{let t=e.score??1;return t<=.05||t<=.3&&rs(i,Qo(e.item.name))>=3});if(a.length)return a[0].item;let o=ts.get(t);if(o?.length){let e=o.slice().sort((e,t)=>e.idx-t.idx||Qo(e.name).length-Qo(t.name).length)[0];return q.get(e.name)??null}let s=ns.search(t,{limit:8}).filter(e=>rs(i,Qo(e.item.name))>=2)[0];return s?s.item:null}function as(e,t=20){let n=e.trim();if(!n)return[];let r=new Map,i=q.get(n);i&&r.set(n,i);let a=Xo[n];if(a&&!r.has(a)){let e=q.get(a);e&&r.set(e.name,e)}for(let{name:e}of ts.get(n)??[]){let n=q.get(e);if(n&&r.set(n.name,n),r.size>=t)break}for(let e of ns.search(n,{limit:t}))r.set(e.item.name,e.item);return[...r.values()].slice(0,t)}function os(e,t=24,n=`#000000`,r=2){let i=e.nodes.map(([e,t])=>`<${e} ${Object.entries(t).map(([e,t])=>`${e}="${t}"`).join(` `)}/>`).join(`
|
|
55
55
|
`);return[`<svg xmlns="http://www.w3.org/2000/svg"`,` width="${t}" height="${t}" viewBox="0 0 24 24"`,` fill="none" stroke="${n}" stroke-width="${r}"`,` stroke-linecap="round" stroke-linejoin="round">`,` ${i}`,`</svg>`].join(`
|
|
56
|
-
`)}var ss={FRAME:Ot,RECTANGLE:kt,ELLIPSE:At,LINE:jt,POLYGON:Mt,STAR:Nt,VECTOR:Pt,TEXT:Ft,GROUP:It,BOOLEAN_OPERATION:Lt};function cs(e){let t={...ss[e].shape,type:m.literal(e).optional()};return m.object({...t,placement:zt.optional()}).strict()}function J(e,t){return{method:`execute`,inputSchema:cs(e),outputSchema:mn,payload:t=>{let{placement:n,...r}=t;delete r.type;let i=[{type:e,...r}];return n===void 0?{ops:i}:{ops:i,placement:n}},annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},...t}}var Y={type:`tool`,tool:`jsd_batch`,description:`一次建多个根节点或编排后续步骤(jsd_create_nodes 已并入 jsd_batch)`};function ls(e,t,n){let i=[J(`FRAME`,{name:`jsd_create_frame`,title:`createFrame.title`,description:`createFrame.description`,followUp:Y}),J(`RECTANGLE`,{name:`jsd_create_rectangle`,title:`createRectangle.title`,description:`createRectangle.description`,followUp:Y}),J(`TEXT`,{name:`jsd_create_text`,title:`createText.title`,description:`createText.description`,followUp:Y}),J(`ELLIPSE`,{name:`jsd_create_ellipse`,title:`createEllipse.title`,description:`createEllipse.description`,followUp:Y}),J(`LINE`,{name:`jsd_create_line`,title:`createLine.title`,description:`createLine.description`,followUp:Y}),J(`POLYGON`,{name:`jsd_create_polygon`,title:`createPolygon.title`,description:`createPolygon.description`,followUp:Y}),J(`STAR`,{name:`jsd_create_star`,title:`createStar.title`,description:`createStar.description`,followUp:Y}),J(`VECTOR`,{name:`jsd_create_vector`,title:`createVector.title`,description:`createVector.description`,platforms:[`jsdesign`,`figma`],platformNote:`(MasterGo 的矢量节点是 PenNode,路径为 penNetwork 顶点模型,与本工具的 vectorPaths(SVG path data)不同形;该平台暂不支持建矢量)`,followUp:Y}),J(`GROUP`,{name:`jsd_create_group`,title:`createGroup.title`,description:`createGroup.description`,followUp:Y}),J(`BOOLEAN_OPERATION`,{name:`jsd_create_boolean_operation`,title:`createBooleanOperation.title`,description:n.t(`createBooleanOperation.description`,{ops:Ye}),followUp:Y})],a=H({name:`jsd_create_svg`,title:`createSvg.title`,description:`createSvg.description`,inputSchema:Bt,outputSchema:mn,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},timeout:Si,run:async(e,t,n)=>{let{svg:i,svgPath:a,name:o}=e,s;if(a!=null&&a.trim()!==``)try{s=r(a,`utf8`)}catch(e){throw Error(`读取 SVG 文件失败(${a}): ${e instanceof Error?e.message:String(e)}`)}else s=i??``;if(s.trim()===``)throw Error(a==null?`svg 为空字符串;要导入本地文件请改用 svgPath`:`SVG 文件是空的:${a}(脚本可能没写成功,或写到了另一个路径)`);if(s.length>Oi)throw Error(`SVG 源码 ${s.length} 字节 > 上限 ${Oi}:先瘦身再导入(散点抽稀 / 合并 path / 去掉逐点坐标),或调大 TEXT_TO_DESIGN_MCP_MAX_SVG_BYTES`);return t.request(`create_svg`,{svg:s,name:o??`svg-design`},{signal:n,timeout:Si})},followUp:Y}),o=H({name:`jsd_create_icon`,title:`createIcon.title`,description:`按名称/别名/语义模糊匹配并插入 Lucide 内置图标;查无时返回候选名。默认 24px 黑色描边 2px。建多个根节点/复杂树用 jsd_batch 编排`,inputSchema:Ht,outputSchema:mn,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},run:async(e,t,n)=>{let{icon:r,size:i,color:a,strokeWidth:o,name:s}=e,c=is(r);if(!c){let e=as(r,8),t=e.length?`,可尝试:${e.map(e=>e.name).join(`, `)}`:``;throw Error(`未知图标:${r}${t}`)}let l=os(c,i??24,a??`#000000`,o??2);return t.request(`create_svg`,{svg:l,name:s??`icon-${c.name}`},{signal:n})},followUp:Y}),s=H({name:`jsd_html_to_design`,title:`htmlToDesign.title`,description:`htmlToDesign.description`,inputSchema:Vt,outputSchema:mn,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},run:async(e,t,n)=>{let{html:r,name:i}=e,a=Yo(r);return t.request(`create_svg`,{svg:a,name:i??`html-design`},{signal:n})},followUp:Y});return[...i.map(r=>H(r)(e,t,n)),a(e,t,n),o(e,t,n),s(e,t,n)]}var us=`(page)`,ds=8,fs=200,ps=5,ms=new Set([`remove`,`reparent`,`group`,`ungroup`,`flatten`,`repair`]);function hs(e){let t=e.op;return typeof t==`string`&&ms.has(t)}function gs(e){return e.op===`reparent`}function _s(e,t){if(typeof e==`object`&&e)for(let[n,r]of Object.entries(e)){if(n===`ids`&&Array.isArray(r)){for(let e of r)typeof e==`string`&&e!==``&&t.add(e);continue}(n===`parentId`||n===`nodeId`||n===`componentId`)&&typeof r==`string`&&r!==``&&t.add(r)}}function vs(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e):[]}function ys(e){if(typeof e!=`object`||!e)return null;let t=e;return typeof t.id!=`string`||typeof t.x!=`number`||typeof t.y!=`number`?null:{id:t.id,name:typeof t.name==`string`?t.name:t.id,x:t.x,y:t.y}}async function bs(e,t){let n=Ia(e);if(n==null)return null;let r=await n(t,void 0);if(r?.isError===!0)return null;let i=r?.structuredContent;return typeof i==`object`&&i?i:null}async function xs(e){let t=new Map;if(e===us){let e=await bs(`jsd_get_page`,{});if(e==null)return null;for(let n of vs(e.nodes).slice(0,fs)){let e=ys(n);e!=null&&t.set(e.id,e)}return t}let n=await bs(`jsd_find`,{ids:[e],depth:1});if(n==null)return null;let r=vs(n.nodes)[0];if(r==null)return null;for(let e of vs(r.children).slice(0,fs)){let n=ys(e);n!=null&&t.set(n.id,n)}return t}var Ss=class{snapshots=new Map;dead=new Set;engaged=!1;async before(e){if(e.op===void 0||hs(e)){this.engaged=!0;try{let t=new Set;if(_s(e,t),t.size===0)return;let n=await bs(`jsd_find`,{ids:[...t],depth:0}),r=new Set,i=!1;for(let e of vs(n?.nodes)){let t=typeof e.parentId==`string`?e.parentId:``;t===``?i=!0:r.add(t)}gs(e)&&typeof e.parentId==`string`&&r.add(e.parentId),i&&r.add(us);for(let e of r){if(this.snapshots.has(e)||this.dead.has(e))continue;if(this.snapshots.size>=ds){this.dead.add(e);continue}let t=await xs(e);if(t==null){this.dead.add(e);continue}this.snapshots.set(e,t)}}catch{}}}async after(){if(!this.engaged)return[];let e=[];for(let[t,n]of this.snapshots)try{let r=await xs(t);if(r==null)continue;let i=[];for(let[e,t]of n){let n=r.get(e);n!=null&&(n.x!==t.x||n.y!==t.y)&&i.push({from:t,to:n})}if(i.length===0)continue;let a=i.slice(0,ps).map(e=>`${e.from.name}(${e.from.id}) (${e.from.x},${e.from.y}) → (${e.to.x},${e.to.y})`),o=i.length>ps?` 等 ${i.length} 个节点`:``;e.push([`同层几何漂移(平台缺陷):${t===us?`当前页顶层`:`父级 ${t}`} 内有未被本次操作触及的节点自行移位:${a.join(`、`)}${o}。`,`根因疑似删除/移父后引擎重算同层约束(无报错、回显正常),别当成样式问题排查。`,`处理:用 jsd_move_node 按上述原值回填,或先 jsd_find 复核该层全部节点 x/y。`].join(``))}catch{}return e}},Cs=()=>new Ss;function ws(e,t,n){let r=H({name:`jsd_manage_nodes`,title:`manageNodes.title`,description:`manageNodes.description`,method:`node_op`,inputSchema:sn,outputSchema:yn,annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!1},hook:Cs,followUp:{type:`tool`,tool:`jsd_set_layout`,description:`manageNodes.followUp`}}),i=H({name:`jsd_manage_components`,title:`manageComponents.title`,description:`manageComponents.description`,method:`component_op`,inputSchema:cn,outputSchema:Sn,annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_instance_properties`,description:`manageComponents.description2`}});return[r(e,t,n),i(e,t,n)]}function Ts(e,t,n){return[H({name:`jsd_find`,title:`find.title`,description:'在当前页面查找节点:ids 精确匹配优先,name 模糊,type 过滤;返回序列化节点列表(最多 100 条)。scope:"document" 跨页全文档查找(触发一次全量页加载,大文档有一次性成本,结果 note 点名;默认 page 只查当前页)。⚠ 每个节点带 `z` = 它在父级 children 里的下标 = **绘制顺序**(0 = 最底层,越大越靠上);判断遮挡/层序读 z 即可,children 数组顺序与 z 一致。大区域查询先 depth:0 拿节点清单,再按 ids/name 定向小范围查,避免大响应被截断丢尾部节点 id',method:`find`,inputSchema:an,outputSchema:vn,annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_select_nodes`,description:`find.description`}})(e,t,n)]}function X(e,t){return{method:`node_op`,outputSchema:yn,payload:t=>({op:e,...t}),...ms.has(e)?{tags:[`structural`],hook:Cs}:{},...t}}function Es(e,t,n){return[X(`select`,{name:`jsd_select_nodes`,title:`selectNodes.title`,description:`把指定节点设为当前选中,后续不传 ids 的工具会作用于它们。只读类工具(jsd_get_selection/jsd_find)不用它——那些工具直接接受 ids`,inputSchema:zn,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_move_node`,description:`selectNodes.description`}}),X(`remove`,{name:`jsd_delete_node`,title:`deleteNode.title`,description:`删除节点(破坏性,仅编辑器 undo 可回退)。ids 缺省删当前选中;matchName 可在范围内再按 name 精确过滤。多个删除动作建议用 jsd_batch 串起来`,inputSchema:Bn,annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_find`,description:`deleteNode.description`}}),X(`clone`,{name:`jsd_clone_node`,title:`cloneNode.title`,description:`复制节点,新副本右下偏移放置并返回新 id。注意:克隆 COMPONENT 得到的是 INSTANCE,不是可编辑副本;文本批量替换前先用它留安全底稿`,inputSchema:Vn,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_move_node`,description:`cloneNode.description`}}),X(`group`,{name:`jsd_group_nodes`,title:`groupNodes.title`,description:`把多个节点编组(内部用 Frame 实现),可同时设置 auto-layout(layoutMode/itemSpacing/padding*/主轴对齐);只归组不排布时 layoutMode=NONE。复杂结构建议先用 per-type create 工具(jsd_create_frame 等)平铺建好再编组`,inputSchema:Hn,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_layout`,description:`groupNodes.description`}}),X(`ungroup`,{name:`jsd_ungroup_nodes`,title:`ungroupNodes.title`,description:`解散分组,子节点回到原父节点下(坐标变为相对新父,可能需要重新摆位)`,platforms:[`jsdesign`,`figma`],platformNote:`(MasterGo 未提供解组 API;该平台请改用拆分/重排替代)`,inputSchema:Un,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_move_node`,description:`ungroupNodes.description`}}),X(`flatten`,{name:`jsd_flatten_nodes`,title:`flattenNodes.title`,description:`把至少 2 个节点合并为单一矢量(破坏性,原节点层级消失),常用于把文本/图标烘焙成不可编辑图形`,inputSchema:Wn,annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_fill_color`,description:`flattenNodes.description`}}),X(`outline_stroke`,{name:`jsd_outline_stroke`,title:`outlineStroke.title`,description:`把描边转成轮廓矢量(几何被烘焙,原描边属性不再可改)。改描边颜色/宽度请用 jsd_set_stroke`,inputSchema:Gn,annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_stroke`,description:`outlineStroke.description`}}),X(`reparent`,{name:`jsd_reparent_nodes`,title:`reparentNodes.title`,description:"把节点移入 parentId 成为其子节点,可指定插入位置。⚠ **实例不能当 parentId**:引擎直接拒(`in insertChild: Cannot move node. New parent is an instance or is inside of an instance`),往实例里加东西请先 jsd_detach_instance 拆链接。⚠ **parentId 请显式传**:缺省值取「当前选中里第一个不是被移动节点的节点」——当前选中为空或不含父容器时该值不可靠(会报「没有找到目标父节点」,或把节点误移进另一个被选中的节点下)。需要依赖缺省时的两种姿势:①先 jsd_select_nodes 选中目标容器;②只调层序 → 传 index 且 ids 里含被调整节点本身,此时缺省父级 = 该节点的原父级。⚠ 层序语义:index 是 children 数组下标(0 = 最底层),children 顺序即绘制顺序(末位 = 最上层),序列化里对应字段是 z —— 判断遮挡读 z,调层序就用本工具 + index。节点已在该父级下时本工具只调层序,x/y 不变;auto-layout 容器同样支持(index 会在内部临时关掉布局插入再恢复),若引擎没落位会明确报错并提示改 itemSpacing / 对齐。⚠ **跨父级移动保持节点绝对位置**:内部按页面系记账(移动前取绝对原点,移动后换算成新父下的 x/y),不要再按「相对系重新解释」手动摆回 —— 那会把节点推走。唯一例外是移入 auto-layout 容器:位置由布局接管,写 x/y 无效,想调排布改 itemSpacing / 对齐。确需手工定位(按坐标排布等)时用 jsd_resize_node 传 x/y(可与 width/height 一次改完)或 jsd_move_node",inputSchema:Kn,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_move_node`,description:`reparentNodes.description`}}),X(`repair`,{name:`jsd_repair_nodes`,title:`repairNodes.title`,description:`清理已损坏节点(破坏性)。ids 缺省时清理当前页全部损坏节点;批量删除后报「没找到 X 节点」时先复核 jsd_find 再修`,inputSchema:qn,annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_find`,description:`repairNodes.description`}})].map(r=>H(r)(e,t,n))}function Ds(e,t,n){return[H({name:`jsd_platform_op`,title:`platformOp.title`,description:`platformOp.description`,platforms:[`figma`,`mastergo`,`jsdesign`],platformNote:`(平台特有 op 名单以 jsd_ping 的 platformOps 为准 —— 有的平台该名单是空数组,此时没有平台 op 可调;本地样式读 jsd://styles(只读资源,没有同名工具);变体值读 jsd_find 的 variantProperties、切已存在的值用 jsd_set_instance_properties;**变体集本身**(建维度/加成分/改取值/删维度)只有提供集合级 op 的平台才改得动,名单同样在 platformOps 里 —— 没这组 op 的平台只能靠主件命名承载。${xo(null)}${mo(null)}。变量面:${ho(null)})`,method:`platform_op`,inputSchema:pn,outputSchema:_t,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_get_selection`,description:`platformOp.description2`}})(e,t,n)]}function Os(e,t){let n=e.registerPrompt(`html-to-design`,{title:t.t(`prompt.htmlToDesign.title`),description:t.t(`prompt.htmlToDesign.description`),argsSchema:m.object({html:m.string().describe(`要转换的 HTML 片段`),name:m.string().optional().describe(`生成节点的名称,默认 html-design`)})},({html:e,name:t})=>({messages:[{role:`user`,content:{type:`text`,text:js(String(e),t==null?void 0:String(t))}}]})),r=e.registerPrompt(`icon-grid`,{title:t.t(`prompt.iconGrid.title`),description:t.t(`prompt.iconGrid.description`),argsSchema:m.object({icons:m.string().describe(`图标名列表,逗号分隔,如 house,search,settings`),size:m.string().optional().describe(`单个图标边长 px 数字字符串,默认 "24"`),gap:m.string().optional().describe(`图标间距 px 数字字符串,默认 "16"`)})},({icons:e,size:t,gap:n})=>({messages:[{role:`user`,content:{type:`text`,text:Ms(String(e),Number(t)||24,Number(n)||16)}}]})),i=e.registerPrompt(`script-ops`,{title:t.t(`prompt.scriptOps.title`),description:`把多步画布操作合并为一次 ops 数组或一段宿主脚本执行,减少工具往返与上下文占用`,argsSchema:m.object({task:m.string().optional().describe(`要完成的任务描述(可选,留空只返回脚本化调用纪律)`)})},({task:e})=>({messages:[{role:`user`,content:{type:`text`,text:Ns(e==null?void 0:String(e))}}]})),a=e.registerPrompt(`design-strategy`,{title:t.t(`prompt.designStrategy.title`),description:`画布创作的通用纪律:先查可复用件(组件/变体/样式/变量怎么选、怎么复用)、再摸底、结构分层(成品该多深就多深,调用才分批)、语义化命名、归组后再布局(auto-layout 判据 + 最容易漏掉的分区清单)、间距与字号阶梯、出错回滚,附示例结构树`,argsSchema:m.object({screen:m.string().optional().describe(`要设计的界面名称,如「登录页」;留空只返回通用纪律`)})},({screen:e})=>({messages:[{role:`assistant`,content:{type:`text`,text:Ps(e==null?void 0:String(e),Z())}}]})),o=e.registerPrompt(`text-replace-strategy`,{title:t.t(`prompt.textReplace.title`),description:`大改文案的安全流程:jsd_clone_node 留底 → 按语义分块 → jsd_set_text ids 批量替换 → 逐块导小图复核`,argsSchema:m.object({rootId:m.string().optional().describe(`根节点 id;留空取当前选中`)})},({rootId:e})=>({messages:[{role:`assistant`,content:{type:`text`,text:Is(e==null?void 0:String(e))}}]})),s=e.registerPrompt(`variant-sync`,{title:t.t(`prompt.variantSync.title`),description:`把一个实例的样式/文案批量套用到多个同类实例(卡片组/列表项/表单组),变体属性走组件操作`,argsSchema:m.object({sourceId:m.string().optional().describe(`源实例 id;留空取当前选中`),targetType:m.string().optional().describe(`目标实例的类型过滤,如 INSTANCE;留空按名称匹配`)})},({sourceId:e,targetType:t})=>({messages:[{role:`assistant`,content:{type:`text`,text:Ls(e==null?void 0:String(e),t==null?void 0:String(t))}}]})),c=e.registerPrompt(`variable-binding`,{title:t.t(`prompt.variableBinding.title`),description:`变量绑定与批量套用:先看本平台有没有变量能力面,再读绑定、建变量、批量绑定;没有变量面的平台给替代路径`,argsSchema:m.object({target:m.string().optional().describe(`要绑定的节点或范围描述;留空只返回做法与分流`)})},({target:e})=>({messages:[{role:`assistant`,content:{type:`text`,text:Rs(e==null?void 0:String(e),Z())}}]})),l=e.registerPrompt(`variant-set`,{title:t.t(`prompt.variantSet.title`),description:`变体集构建:按能力位 inPlaceVariants 分流(原位合并 / 多主件兜底),含命名与建后回读复核`,argsSchema:m.object({family:m.string().optional().describe(`组件族名,如 Nav;留空只返回做法与分流`)})},({family:e})=>({messages:[{role:`assistant`,content:{type:`text`,text:zs(e==null?void 0:String(e),Z())}}]})),u=e.registerPrompt(`component-property`,{title:t.t(`prompt.componentProperty.title`),description:`组件属性的定义与设值:定义走平台 op、设值走 jsd_set_instance_properties,并按当前平台给出能收的值形态`,argsSchema:m.object({target:m.string().optional().describe(`组件或实例 id;留空只返回做法与分流`)})},({target:e})=>({messages:[{role:`assistant`,content:{type:`text`,text:Bs(e==null?void 0:String(e),Z())}}]}));return[n,r,i,a,e.registerPrompt(`auto-layout`,{title:t.t(`prompt.autoLayout.title`),description:t.t(`prompt.autoLayout.description`),argsSchema:m.object({target:m.string().optional().describe(`要上布局的容器 / 分区描述,如「标签栏」「参数行」;留空返回通用纪律`)})},({target:e})=>({messages:[{role:`assistant`,content:{type:`text`,text:Fs(e==null?void 0:String(e),Z())}}]})),o,s,c,l,u,e.registerPrompt(`chart-by-code`,{title:t.t(`prompt.chartByCode.title`),description:t.t(`prompt.chartByCode.description`),argsSchema:m.object({chart:m.string().describe(`要画什么图 / 数据可视化(种类 + 数据 + 口径),如「按月的毛利率与净利率双轴折线」「各地区销售额占比环形图」「日活趋势面积图」`),svgPath:m.string().optional().describe(`生成的 .svg 落盘路径,缺省 /tmp/chart.svg`)})},({chart:e,svgPath:t})=>({messages:[{role:`user`,content:{type:`text`,text:Hs(String(e),t==null?void 0:String(t))}}]}))].map(e=>Object.assign(e,{alwaysEnabled:!0}))}function Z(){return ji()?.platform??null}function ks(e,t){return e.split(`
|
|
56
|
+
`)}var ss={FRAME:Ot,RECTANGLE:kt,ELLIPSE:At,LINE:jt,POLYGON:Mt,STAR:Nt,VECTOR:Pt,TEXT:Ft,GROUP:It,BOOLEAN_OPERATION:Lt};function cs(e){let t={...ss[e].shape,type:h.literal(e).optional()};return h.object({...t,placement:zt.optional()}).strict()}function J(e,t){return{method:`execute`,inputSchema:cs(e),outputSchema:mn,payload:t=>{let{placement:n,...r}=t;delete r.type;let i=[{type:e,...r}];return n===void 0?{ops:i}:{ops:i,placement:n}},annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},...t}}var Y={type:`tool`,tool:`jsd_batch`,description:`一次建多个根节点或编排后续步骤(jsd_create_nodes 已并入 jsd_batch)`};function ls(e,t,n){let i=[J(`FRAME`,{name:`jsd_create_frame`,title:`createFrame.title`,description:`createFrame.description`,followUp:Y}),J(`RECTANGLE`,{name:`jsd_create_rectangle`,title:`createRectangle.title`,description:`createRectangle.description`,followUp:Y}),J(`TEXT`,{name:`jsd_create_text`,title:`createText.title`,description:`createText.description`,followUp:Y}),J(`ELLIPSE`,{name:`jsd_create_ellipse`,title:`createEllipse.title`,description:`createEllipse.description`,followUp:Y}),J(`LINE`,{name:`jsd_create_line`,title:`createLine.title`,description:`createLine.description`,followUp:Y}),J(`POLYGON`,{name:`jsd_create_polygon`,title:`createPolygon.title`,description:`createPolygon.description`,followUp:Y}),J(`STAR`,{name:`jsd_create_star`,title:`createStar.title`,description:`createStar.description`,followUp:Y}),J(`VECTOR`,{name:`jsd_create_vector`,title:`createVector.title`,description:`createVector.description`,platforms:[`jsdesign`,`figma`],platformNote:`(MasterGo 的矢量节点是 PenNode,路径为 penNetwork 顶点模型,与本工具的 vectorPaths(SVG path data)不同形;该平台暂不支持建矢量)`,followUp:Y}),J(`GROUP`,{name:`jsd_create_group`,title:`createGroup.title`,description:`createGroup.description`,followUp:Y}),J(`BOOLEAN_OPERATION`,{name:`jsd_create_boolean_operation`,title:`createBooleanOperation.title`,description:n.t(`createBooleanOperation.description`,{ops:Ye}),followUp:Y})],a=H({name:`jsd_create_svg`,title:`createSvg.title`,description:`createSvg.description`,inputSchema:Bt,outputSchema:mn,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},timeout:Si,run:async(e,t,n)=>{let{svg:i,svgPath:a,name:o}=e,s;if(a!=null&&a.trim()!==``)try{s=r(a,`utf8`)}catch(e){throw Error(`读取 SVG 文件失败(${a}): ${e instanceof Error?e.message:String(e)}`)}else s=i??``;if(s.trim()===``)throw Error(a==null?`svg 为空字符串;要导入本地文件请改用 svgPath`:`SVG 文件是空的:${a}(脚本可能没写成功,或写到了另一个路径)`);if(s.length>Oi)throw Error(`SVG 源码 ${s.length} 字节 > 上限 ${Oi}:先瘦身再导入(散点抽稀 / 合并 path / 去掉逐点坐标),或调大 TEXT_TO_DESIGN_MCP_MAX_SVG_BYTES`);return t.request(`create_svg`,{svg:s,name:o??`svg-design`},{signal:n,timeout:Si})},followUp:Y}),o=H({name:`jsd_create_icon`,title:`createIcon.title`,description:`按名称/别名/语义模糊匹配并插入 Lucide 内置图标;查无时返回候选名。默认 24px 黑色描边 2px。建多个根节点/复杂树用 jsd_batch 编排`,inputSchema:Ht,outputSchema:mn,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},run:async(e,t,n)=>{let{icon:r,size:i,color:a,strokeWidth:o,name:s}=e,c=is(r);if(!c){let e=as(r,8),t=e.length?`,可尝试:${e.map(e=>e.name).join(`, `)}`:``;throw Error(`未知图标:${r}${t}`)}let l=os(c,i??24,a??`#000000`,o??2);return t.request(`create_svg`,{svg:l,name:s??`icon-${c.name}`},{signal:n})},followUp:Y}),s=H({name:`jsd_html_to_design`,title:`htmlToDesign.title`,description:`htmlToDesign.description`,inputSchema:Vt,outputSchema:mn,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},run:async(e,t,n)=>{let{html:r,name:i}=e,a=Yo(r);return t.request(`create_svg`,{svg:a,name:i??`html-design`},{signal:n})},followUp:Y});return[...i.map(r=>H(r)(e,t,n)),a(e,t,n),o(e,t,n),s(e,t,n)]}var us=`(page)`,ds=8,fs=200,ps=5,ms=new Set([`remove`,`reparent`,`group`,`ungroup`,`flatten`,`repair`]);function hs(e){let t=e.op;return typeof t==`string`&&ms.has(t)}function gs(e){return e.op===`reparent`}function _s(e,t){if(typeof e==`object`&&e)for(let[n,r]of Object.entries(e)){if(n===`ids`&&Array.isArray(r)){for(let e of r)typeof e==`string`&&e!==``&&t.add(e);continue}(n===`parentId`||n===`nodeId`||n===`componentId`)&&typeof r==`string`&&r!==``&&t.add(r)}}function vs(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e):[]}function ys(e){if(typeof e!=`object`||!e)return null;let t=e;return typeof t.id!=`string`||typeof t.x!=`number`||typeof t.y!=`number`?null:{id:t.id,name:typeof t.name==`string`?t.name:t.id,x:t.x,y:t.y}}async function bs(e,t){let n=Ia(e);if(n==null)return null;let r=await n(t,void 0);if(r?.isError===!0)return null;let i=r?.structuredContent;return typeof i==`object`&&i?i:null}async function xs(e){let t=new Map;if(e===us){let e=await bs(`jsd_get_page`,{});if(e==null)return null;for(let n of vs(e.nodes).slice(0,fs)){let e=ys(n);e!=null&&t.set(e.id,e)}return t}let n=await bs(`jsd_find`,{ids:[e],depth:1});if(n==null)return null;let r=vs(n.nodes)[0];if(r==null)return null;for(let e of vs(r.children).slice(0,fs)){let n=ys(e);n!=null&&t.set(n.id,n)}return t}var Ss=class{snapshots=new Map;dead=new Set;engaged=!1;async before(e){if(e.op===void 0||hs(e)){this.engaged=!0;try{let t=new Set;if(_s(e,t),t.size===0)return;let n=await bs(`jsd_find`,{ids:[...t],depth:0}),r=new Set,i=!1;for(let e of vs(n?.nodes)){let t=typeof e.parentId==`string`?e.parentId:``;t===``?i=!0:r.add(t)}gs(e)&&typeof e.parentId==`string`&&r.add(e.parentId),i&&r.add(us);for(let e of r){if(this.snapshots.has(e)||this.dead.has(e))continue;if(this.snapshots.size>=ds){this.dead.add(e);continue}let t=await xs(e);if(t==null){this.dead.add(e);continue}this.snapshots.set(e,t)}}catch{}}}async after(){if(!this.engaged)return[];let e=[];for(let[t,n]of this.snapshots)try{let r=await xs(t);if(r==null)continue;let i=[];for(let[e,t]of n){let n=r.get(e);n!=null&&(n.x!==t.x||n.y!==t.y)&&i.push({from:t,to:n})}if(i.length===0)continue;let a=i.slice(0,ps).map(e=>`${e.from.name}(${e.from.id}) (${e.from.x},${e.from.y}) → (${e.to.x},${e.to.y})`),o=i.length>ps?` 等 ${i.length} 个节点`:``;e.push([`同层几何漂移(平台缺陷):${t===us?`当前页顶层`:`父级 ${t}`} 内有未被本次操作触及的节点自行移位:${a.join(`、`)}${o}。`,`根因疑似删除/移父后引擎重算同层约束(无报错、回显正常),别当成样式问题排查。`,`处理:用 jsd_move_node 按上述原值回填,或先 jsd_find 复核该层全部节点 x/y。`].join(``))}catch{}return e}},Cs=()=>new Ss;function ws(e,t,n){let r=H({name:`jsd_manage_nodes`,title:`manageNodes.title`,description:`manageNodes.description`,method:`node_op`,inputSchema:sn,outputSchema:yn,annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!1},hook:Cs,followUp:{type:`tool`,tool:`jsd_set_layout`,description:`manageNodes.followUp`}}),i=H({name:`jsd_manage_components`,title:`manageComponents.title`,description:`manageComponents.description`,method:`component_op`,inputSchema:cn,outputSchema:Sn,annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_instance_properties`,description:`manageComponents.description2`}});return[r(e,t,n),i(e,t,n)]}function Ts(e,t,n){return[H({name:`jsd_find`,title:`find.title`,description:'在当前页面查找节点:ids 精确匹配优先,name 模糊,type 过滤;返回序列化节点列表(最多 100 条)。scope:"document" 跨页全文档查找(触发一次全量页加载,大文档有一次性成本,结果 note 点名;默认 page 只查当前页)。⚠ 每个节点带 `z` = 它在父级 children 里的下标 = **绘制顺序**(0 = 最底层,越大越靠上);判断遮挡/层序读 z 即可,children 数组顺序与 z 一致。大区域查询先 depth:0 拿节点清单,再按 ids/name 定向小范围查,避免大响应被截断丢尾部节点 id',method:`find`,inputSchema:an,outputSchema:vn,annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_select_nodes`,description:`find.description`}})(e,t,n)]}function X(e,t){return{method:`node_op`,outputSchema:yn,payload:t=>({op:e,...t}),...ms.has(e)?{tags:[`structural`],hook:Cs}:{},...t}}function Es(e,t,n){return[X(`select`,{name:`jsd_select_nodes`,title:`selectNodes.title`,description:`把指定节点设为当前选中,后续不传 ids 的工具会作用于它们。只读类工具(jsd_get_selection/jsd_find)不用它——那些工具直接接受 ids`,inputSchema:zn,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_move_node`,description:`selectNodes.description`}}),X(`remove`,{name:`jsd_delete_node`,title:`deleteNode.title`,description:`删除节点(破坏性,仅编辑器 undo 可回退)。ids 缺省删当前选中;matchName 可在范围内再按 name 精确过滤。多个删除动作建议用 jsd_batch 串起来`,inputSchema:Bn,annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_find`,description:`deleteNode.description`}}),X(`clone`,{name:`jsd_clone_node`,title:`cloneNode.title`,description:`复制节点,新副本右下偏移放置并返回新 id。注意:克隆 COMPONENT 得到的是 INSTANCE,不是可编辑副本;文本批量替换前先用它留安全底稿`,inputSchema:Vn,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_move_node`,description:`cloneNode.description`}}),X(`group`,{name:`jsd_group_nodes`,title:`groupNodes.title`,description:`把多个节点编组(内部用 Frame 实现),可同时设置 auto-layout(layoutMode/itemSpacing/padding*/主轴对齐);只归组不排布时 layoutMode=NONE。复杂结构建议先用 per-type create 工具(jsd_create_frame 等)平铺建好再编组`,inputSchema:Hn,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_layout`,description:`groupNodes.description`}}),X(`ungroup`,{name:`jsd_ungroup_nodes`,title:`ungroupNodes.title`,description:`解散分组,子节点回到原父节点下(坐标变为相对新父,可能需要重新摆位)`,platforms:[`jsdesign`,`figma`],platformNote:`(MasterGo 未提供解组 API;该平台请改用拆分/重排替代)`,inputSchema:Un,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_move_node`,description:`ungroupNodes.description`}}),X(`flatten`,{name:`jsd_flatten_nodes`,title:`flattenNodes.title`,description:`把至少 2 个节点合并为单一矢量(破坏性,原节点层级消失),常用于把文本/图标烘焙成不可编辑图形`,inputSchema:Wn,annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_fill_color`,description:`flattenNodes.description`}}),X(`outline_stroke`,{name:`jsd_outline_stroke`,title:`outlineStroke.title`,description:`把描边转成轮廓矢量(几何被烘焙,原描边属性不再可改)。改描边颜色/宽度请用 jsd_set_stroke`,inputSchema:Gn,annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_stroke`,description:`outlineStroke.description`}}),X(`reparent`,{name:`jsd_reparent_nodes`,title:`reparentNodes.title`,description:"把节点移入 parentId 成为其子节点,可指定插入位置。⚠ **实例不能当 parentId**:引擎直接拒(`in insertChild: Cannot move node. New parent is an instance or is inside of an instance`),往实例里加东西请先 jsd_detach_instance 拆链接。⚠ **parentId 请显式传**:缺省值取「当前选中里第一个不是被移动节点的节点」——当前选中为空或不含父容器时该值不可靠(会报「没有找到目标父节点」,或把节点误移进另一个被选中的节点下)。需要依赖缺省时的两种姿势:①先 jsd_select_nodes 选中目标容器;②只调层序 → 传 index 且 ids 里含被调整节点本身,此时缺省父级 = 该节点的原父级。⚠ 层序语义:index 是 children 数组下标(0 = 最底层),children 顺序即绘制顺序(末位 = 最上层),序列化里对应字段是 z —— 判断遮挡读 z,调层序就用本工具 + index。节点已在该父级下时本工具只调层序,x/y 不变;auto-layout 容器同样支持(index 会在内部临时关掉布局插入再恢复),若引擎没落位会明确报错并提示改 itemSpacing / 对齐。⚠ **跨父级移动保持节点绝对位置**:内部按页面系记账(移动前取绝对原点,移动后换算成新父下的 x/y),不要再按「相对系重新解释」手动摆回 —— 那会把节点推走。唯一例外是移入 auto-layout 容器:位置由布局接管,写 x/y 无效,想调排布改 itemSpacing / 对齐。确需手工定位(按坐标排布等)时用 jsd_resize_node 传 x/y(可与 width/height 一次改完)或 jsd_move_node",inputSchema:Kn,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_move_node`,description:`reparentNodes.description`}}),X(`repair`,{name:`jsd_repair_nodes`,title:`repairNodes.title`,description:`清理已损坏节点(破坏性)。ids 缺省时清理当前页全部损坏节点;批量删除后报「没找到 X 节点」时先复核 jsd_find 再修`,inputSchema:qn,annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_find`,description:`repairNodes.description`}})].map(r=>H(r)(e,t,n))}function Ds(e,t,n){return[H({name:`jsd_platform_op`,title:`platformOp.title`,description:`platformOp.description`,platforms:[`figma`,`mastergo`,`jsdesign`],platformNote:`(平台特有 op 名单以 jsd_ping 的 platformOps 为准 —— 有的平台该名单是空数组,此时没有平台 op 可调;本地样式读 jsd://styles(只读资源,没有同名工具);变体值读 jsd_find 的 variantProperties、切已存在的值用 jsd_set_instance_properties;**变体集本身**(建维度/加成分/改取值/删维度)只有提供集合级 op 的平台才改得动,名单同样在 platformOps 里 —— 没这组 op 的平台只能靠主件命名承载。${xo(null)}${mo(null)}。变量面:${ho(null)})`,method:`platform_op`,inputSchema:pn,outputSchema:_t,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_get_selection`,description:`platformOp.description2`}})(e,t,n)]}function Os(e,t){let n=e.registerPrompt(`html-to-design`,{title:t.t(`prompt.htmlToDesign.title`),description:t.t(`prompt.htmlToDesign.description`),argsSchema:h.object({html:h.string().describe(`要转换的 HTML 片段`),name:h.string().optional().describe(`生成节点的名称,默认 html-design`)})},({html:e,name:t})=>({messages:[{role:`user`,content:{type:`text`,text:js(String(e),t==null?void 0:String(t))}}]})),r=e.registerPrompt(`icon-grid`,{title:t.t(`prompt.iconGrid.title`),description:t.t(`prompt.iconGrid.description`),argsSchema:h.object({icons:h.string().describe(`图标名列表,逗号分隔,如 house,search,settings`),size:h.string().optional().describe(`单个图标边长 px 数字字符串,默认 "24"`),gap:h.string().optional().describe(`图标间距 px 数字字符串,默认 "16"`)})},({icons:e,size:t,gap:n})=>({messages:[{role:`user`,content:{type:`text`,text:Ms(String(e),Number(t)||24,Number(n)||16)}}]})),i=e.registerPrompt(`script-ops`,{title:t.t(`prompt.scriptOps.title`),description:`把多步画布操作合并为一次 ops 数组或一段宿主脚本执行,减少工具往返与上下文占用`,argsSchema:h.object({task:h.string().optional().describe(`要完成的任务描述(可选,留空只返回脚本化调用纪律)`)})},({task:e})=>({messages:[{role:`user`,content:{type:`text`,text:Ns(e==null?void 0:String(e))}}]})),a=e.registerPrompt(`design-strategy`,{title:t.t(`prompt.designStrategy.title`),description:`画布创作的通用纪律:先查可复用件(组件/变体/样式/变量怎么选、怎么复用)、再摸底、结构分层(成品该多深就多深,调用才分批)、语义化命名、归组后再布局(auto-layout 判据 + 最容易漏掉的分区清单)、间距与字号阶梯、出错回滚,附示例结构树`,argsSchema:h.object({screen:h.string().optional().describe(`要设计的界面名称,如「登录页」;留空只返回通用纪律`)})},({screen:e})=>({messages:[{role:`assistant`,content:{type:`text`,text:Ps(e==null?void 0:String(e),Z())}}]})),o=e.registerPrompt(`text-replace-strategy`,{title:t.t(`prompt.textReplace.title`),description:`大改文案的安全流程:jsd_clone_node 留底 → 按语义分块 → jsd_set_text ids 批量替换 → 逐块导小图复核`,argsSchema:h.object({rootId:h.string().optional().describe(`根节点 id;留空取当前选中`)})},({rootId:e})=>({messages:[{role:`assistant`,content:{type:`text`,text:Is(e==null?void 0:String(e))}}]})),s=e.registerPrompt(`variant-sync`,{title:t.t(`prompt.variantSync.title`),description:`把一个实例的样式/文案批量套用到多个同类实例(卡片组/列表项/表单组),变体属性走组件操作`,argsSchema:h.object({sourceId:h.string().optional().describe(`源实例 id;留空取当前选中`),targetType:h.string().optional().describe(`目标实例的类型过滤,如 INSTANCE;留空按名称匹配`)})},({sourceId:e,targetType:t})=>({messages:[{role:`assistant`,content:{type:`text`,text:Ls(e==null?void 0:String(e),t==null?void 0:String(t))}}]})),c=e.registerPrompt(`variable-binding`,{title:t.t(`prompt.variableBinding.title`),description:`变量绑定与批量套用:先看本平台有没有变量能力面,再读绑定、建变量、批量绑定;没有变量面的平台给替代路径`,argsSchema:h.object({target:h.string().optional().describe(`要绑定的节点或范围描述;留空只返回做法与分流`)})},({target:e})=>({messages:[{role:`assistant`,content:{type:`text`,text:Rs(e==null?void 0:String(e),Z())}}]})),l=e.registerPrompt(`variant-set`,{title:t.t(`prompt.variantSet.title`),description:`变体集构建:按能力位 inPlaceVariants 分流(原位合并 / 多主件兜底),含命名与建后回读复核`,argsSchema:h.object({family:h.string().optional().describe(`组件族名,如 Nav;留空只返回做法与分流`)})},({family:e})=>({messages:[{role:`assistant`,content:{type:`text`,text:zs(e==null?void 0:String(e),Z())}}]})),u=e.registerPrompt(`component-property`,{title:t.t(`prompt.componentProperty.title`),description:`组件属性的定义与设值:定义走平台 op、设值走 jsd_set_instance_properties,并按当前平台给出能收的值形态`,argsSchema:h.object({target:h.string().optional().describe(`组件或实例 id;留空只返回做法与分流`)})},({target:e})=>({messages:[{role:`assistant`,content:{type:`text`,text:Bs(e==null?void 0:String(e),Z())}}]}));return[n,r,i,a,e.registerPrompt(`auto-layout`,{title:t.t(`prompt.autoLayout.title`),description:t.t(`prompt.autoLayout.description`),argsSchema:h.object({target:h.string().optional().describe(`要上布局的容器 / 分区描述,如「标签栏」「参数行」;留空返回通用纪律`)})},({target:e})=>({messages:[{role:`assistant`,content:{type:`text`,text:Fs(e==null?void 0:String(e),Z())}}]})),o,s,c,l,u,e.registerPrompt(`chart-by-code`,{title:t.t(`prompt.chartByCode.title`),description:t.t(`prompt.chartByCode.description`),argsSchema:h.object({chart:h.string().describe(`要画什么图 / 数据可视化(种类 + 数据 + 口径),如「按月的毛利率与净利率双轴折线」「各地区销售额占比环形图」「日活趋势面积图」`),svgPath:h.string().optional().describe(`生成的 .svg 落盘路径,缺省 /tmp/chart.svg`)})},({chart:e,svgPath:t})=>({messages:[{role:`user`,content:{type:`text`,text:Hs(String(e),t==null?void 0:String(t))}}]}))].map(e=>Object.assign(e,{alwaysEnabled:!0}))}function Z(){return ji()?.platform??null}function ks(e,t){return e.split(`
|
|
57
57
|
`).map(e=>e===``?e:t+e).join(`
|
|
58
58
|
`)}function As(e){return ji()?.capabilities.includes(e)===!0}function js(e,t){return`请把下面的 HTML 转成设计稿。默认走 jsd_html_to_design(SVG 保真,忽略复杂样式);需要可编辑图层时才改用 per-type create 工具(jsd_create_frame 等)手工映射(容器→FRAME、文本→TEXT、图形→VECTOR)后 reparent 归组。\n\nHTML:\n\`\`\`\n${e}\n\`\`\`${t==null?``:`\n节点名:${t}`}`}function Ms(e,t=24,n=16){return`请插入图标网格:1) jsd_create_frame 建一个 FRAME 容器;2) 每个图标各调一次 jsd_create_icon(size=${t});3) jsd_reparent_nodes 把全部图标移入容器;4) jsd_set_layout 给容器设 auto-layout(layoutMode=HORIZONTAL,itemSpacing=${n},counterAxisAlignItems=CENTER)。\n图标列表: ${e}`}function Ns(e){return`${e==null?`请按以下「脚本化」纪律调用 text-to-design 工具:`:`请用「脚本化」方式完成下面的任务:\n${e}\n\n执行要求:`}
|
|
59
59
|
1) 多步流程一次成型:优先 jsd_batch 编排(create→reparent→update、find→批量修改、图标×N 等);宿主有代码执行工具时也可写一段脚本连续 await 多个 tools.jsd_*。
|
|
@@ -410,8 +410,8 @@ ${Vs}
|
|
|
410
410
|
- [ ] \`jsd_create_svg\` 结果里有 \`created.id\`(没有=没真导入);
|
|
411
411
|
- [ ] 导入后 \`jsd_find({ ids:[created.id], depth:2 })\` 看过层级:有子层就用,只有一层就按第 6 节另建要改的原生节点;
|
|
412
412
|
- [ ] \`jsd_export\` 出的图肉眼过一遍:轴、刻度、文字都在,没有元素跑到画布外;
|
|
413
|
-
- [ ] 文字要不要可编辑(见第 6 节)—— 要就把标题/图例另建原生节点,别全塞进 SVG 图层。`}function Us(e,t,n=[]){let r=e,i=r?.updated??[],a=[];i.length>0&&a.push({type:`text`,text:`已更新 ${i.length} 个节点`});let o=r?.warnings??[];for(let e of o)a.push({type:`text`,text:`⚠ ${e}`});if(i.length===0&&t.length===0&&a.push({type:`text`,text:`未传入任何属性,本次未修改`}),n.length>0){let e=new Set(i.map(e=>e.id)),t=n.filter(t=>!e.has(t));t.length>0&&a.push({type:`text`,text:`以下节点未更新(可能已失效/被连坐删除): ${t.join(`, `)}。可用 jsd_find 复核后重试`})}return a}var Ws=`⚠ recursive=true 只作用于**后代**,不含目标节点自身(给图标/容器传 recursive 刷色,容器自己不再被印上方框);无子节点的叶子自身即整棵子树,仍会改。要把容器自己也算上才显式传 includeSelf=true,那时结果会带 warnings 点名「容器自身也被修改」。`;function Q(e){let t=kr[e.method],n=e=>t.filter(t=>e[t]!==void 0&&Oe[t]!==void 0),r=e=>{let t=e.ids??[];return e.recursive===!0&&e.includeSelf!==!0?[]:t};return{name:e.name,title:e.title,description:e.description+Ws,inputSchema:e.inputSchema,outputSchema:hn,annotations:e.annotations,method:e.method,payload:e=>{let{ids:t,matchName:n,recursive:r,includeSelf:i,...a}=e,o={props:a};return t!==void 0&&(o.ids=t),n!==void 0&&(o.matchName=n),r!==void 0&&(o.recursive=r),i!==void 0&&(o.includeSelf=i),o},...e.followUp===void 0?{}:{followUp:e.followUp},extraContent:(e,t)=>Us(e,n(t),r(t))}}var Gs=Kr();function Ks(e,t,n){return[Q({name:`jsd_set_fill_color`,title:`setFillColor.title`,description:n.t(`setFillColor.description`,{warn:Gs}),method:`set_fill`,inputSchema:vr,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_stroke`,description:`setFillColor.followUp`}}),Q({name:`jsd_set_stroke`,title:`setStroke.title`,description:`设置描边列表、宽度(可四边分开)、对齐/端点/连接、虚线模式与团队库描边样式。strokes 整体替换非合并。把描边烘焙成矢量用 jsd_outline_stroke。`+Gs,method:`set_stroke`,inputSchema:yr,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_fill_color`,description:`setStroke.description`}}),Q({name:`jsd_set_cornerRadius`,title:`setCornerRadius.title`,description:`设置圆角半径(corners 四角可分开)与圆角平滑度。仅 FRAME/RECTANGLE/ELLIPSE/POLYGON/STAR/VECTOR/BOOLEAN_OPERATION 生效,LINE/TEXT 无圆角。`+Gs,method:`set_corner_radius`,inputSchema:br,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_effects`,description:`setCornerRadius.description`}}),Q({name:`jsd_set_text`,title:`setText.title`,description:n.t(`setText.description`,{warn:Gs}),method:`set_text`,inputSchema:xr,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_rename_node`,description:`setText.followUp`}}),Q({name:`jsd_move_node`,title:`moveNode.title`,description:`设置节点 x/y(相对父节点)与 rotation(绕左上角原点)。auto-layout 子节点的位置由父容器接管,修改可能被布局覆盖——那种情况请改 jsd_set_layout 的间距/对齐`,method:`move`,inputSchema:Sr,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_resize_node`,description:`moveNode.description`}}),Q({name:`jsd_resize_node`,title:`resizeNode.title`,description:`设置节点 width/height,并可同时传 x/y 一步完成「改尺寸 + 定位」(按坐标排布、批量摆位时常用,避免分两次调用让中间态被引擎自动尺寸/约束改写;reparent 已自动保持绝对位置,不需要用本工具摆回)。TEXT 默认自适应(WIDTH_AND_HEIGHT)时会覆盖显式尺寸,要固定文本框先 jsd_set_text 设 textAutoResize=NONE。横线/竖线用 LINE:零轴会被兜到 0.01 过引擎校验(存回读仍是 0);其他类型低于 0.01 会明确报错(引擎 resize 下限)`,method:`resize`,inputSchema:Cr,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_visibility`,description:`resizeNode.description`}}),Q({name:`jsd_set_layout`,title:`setLayout.title`,description:`设置容器的 auto-layout:layoutMode 与 itemSpacing/padding*/主轴交叉轴尺寸和对齐/约束/伸缩可在同一次调用里一起传(引擎先应用 layoutMode 再应用间距)。适用 FRAME / COMPONENT / COMPONENT_SET —— 变体集内变体重叠时用它排布(三平台节点均继承 frame 的自动布局能力)。建议建节点时不要混着传,归组并摆好后再单独设;但⚠ 开布局会按内容重算容器尺寸(有子节点时主轴被翻成 AUTO:实测 400×300 的容器 + 一个 200×60 子节点 → 200×60,而 sizingMode 字段回读仍是 FIXED,只有结果 warnings 点名),要保住尺寸就把 layoutMode 与 primaryAxisSizingMode / counterAxisSizingMode **放同一次调用里一起传 FIXED**(实测保得住)。只管布局语义:改节点宽高用 jsd_resize_node,本工具不接受 width/height`,method:`set_layout`,inputSchema:wr,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_reparent_nodes`,description:`setLayout.description`}}),Q({name:`jsd_set_effects`,title:`setEffects.title`,description:`设置阴影/模糊效果(可多层叠加,整体替换)、团队库效果样式、溢出裁剪、布局网格(参考线)与椭圆环形参数(仅 ELLIPSE)。`+Gs,method:`set_effects`,inputSchema:Tr,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_visibility`,description:`setEffects.description`}}),Q({name:`jsd_set_visibility`,title:`setVisibility.title`,description:`设置不透明度 opacity(0-1)、visible 显示开关与 locked 锁定。锁定后节点不能被选中或编辑`,method:`set_visibility`,inputSchema:Er,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_get_selection`,description:`setVisibility.description`}}),Q({name:`jsd_rename_node`,title:`renameNode.title`,description:`重命名节点。命名建议说明用途(如「登录页/邮箱输入/主按钮」),不用「矩形 1」「Frame 2」;批量替换文案用 jsd_set_text`,method:`rename`,inputSchema:Dr,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_text`,description:`renameNode.description`}}),Q({name:`jsd_set_shape`,title:`setShape.title`,description:`设置形状参数(承接原 jsd_update_node 的长尾字段):pointCount 多边形/星形角点数(仅 POLYGON/STAR 生效)、innerRadius 星形内半径比例(0-1,仅 STAR 生效)。改尺寸/圆角用 jsd_resize_node / jsd_set_cornerRadius`,method:`set_shape`,inputSchema:Or,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_fill_color`,description:`setShape.description`}})].map(r=>H(r)(e,t,n))}function qs(e,t){let n=typeof t==`string`?t.toLowerCase():``;if(n===`png`||n===`svg`||n===`pdf`)return n;if(n===`jpg`||n===`jpeg`)return`jpg`;let r=(e??``).toLowerCase();return r.includes(`png`)?`png`:r.includes(`jpeg`)||r.includes(`jpg`)?`jpg`:r.includes(`svg`)?`svg`:r.includes(`pdf`)?`pdf`:`bin`}function Js(e,t,i){let a=H({name:`jsd_export`,title:`export.title`,description:`export.description`,inputSchema:ln,outputSchema:Cn,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},timeout:Si,followUp:{type:`tool`,tool:`jsd_fill_image`,description:`export.description2`},run:async(e,t,r)=>{let{ids:i,format:a,scale:s,savePath:u,includeDataUrl:f}=e,p=(await t.request(`export`,{ids:i,format:a,scale:s},{signal:r,timeout:6e4})).exports??{},ee=[],m=[];for(let[e,t]of Object.entries(p)){let r=t.bytes,i=t.mimeType,a={id:e,name:t.name,format:t.format,mimeType:i,size:r.byteLength};if(u&&(n(l(u),{recursive:!0}),o(u,r),a.path=u),f){if(r.byteLength>wi){let n=u??d(c(),`jsd-export-${e.replace(/[^a-zA-Z0-9_-]/g,`_`)}-${Date.now()}.${qs(i,t.format)}`);u||o(n,r),a.path=n,m.push(`${e}(实际 ${r.byteLength} 字节 > 上限 ${wi} 字节)已落盘:${n}`)}else a.dataUrl=`data:${i};base64,${r.toString(`base64`)}`}ee.push(a)}return{exports:ee,dataUrlOverflow:m}},extraContent:(e,t)=>{let n=t.ids??[],r=e.exports??[],i=e.dataUrlOverflow??[],a=[];r.length>0&&a.push({type:`text`,text:`已导出 ${r.length} 个节点`});for(let e of i)a.push({type:`text`,text:`⚠️ 图片超过内联上限,未返回 base64,${e}。需要图片内容请读取该文件路径,或调小 scale 后重试。`});if(n.length>0){let e=new Set(r.map(e=>e.id)),t=n.filter(t=>!e.has(t));t.length>0&&a.push({type:`text`,text:`导出失败(节点可能已失效): ${t.join(`, `)}。可用 jsd_find 复核`})}return a}}),s=H({name:`jsd_fill_image`,title:`fillImage.title`,description:`fillImage.description`,inputSchema:fn,outputSchema:hn,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},timeout:Si,followUp:{type:`tool`,tool:`jsd_get_selection`,description:`fillImage.description2`},run:async(e,t,n)=>{let{ids:i,sourcePath:a}=e,o;try{o=r(a)}catch(e){throw Error(`读取文件失败: ${e instanceof Error?e.message:String(e)}`)}return t.request(`fill_image`,{ids:i,bytes:new Uint8Array(o)},{signal:n,timeout:Si})}}),u=H({name:`jsd_list_fonts`,title:`listFonts.title`,description:`按家族名过滤、分页列出可用字体与各族的可用字型(返回 families 与 fonts:[{family,styles}])。**默认只回第一页**(50 族,上限 500):字体库规模随平台差一个量级——MasterGo 实测约 1900 族 / 整表 322 KB,整表必然撑爆上下文。结果里的 total 是过滤后的家族总数、truncated 表示还有下一页;按名字找字体传 family(不区分大小写的子串),翻页传 offset/limit。写 fontName 时 family 用 fonts[].family 原样、style 用同一项的**全名**(如 SourceHanSansCN-Bold,不是简称 "Bold")——组合不存在时不报错、会静默退回默认字面(命中时结果 warnings 点名);引擎解析成功会把 family/style 规范化成短名,回读短名属正常`,method:`list_fonts`,inputSchema:un,outputSchema:wn,annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_text`,description:`listFonts.description`}}),f=H({name:`jsd_create_style`,title:`createStyle.title`,description:`createStyle.description`,method:`create_style`,inputSchema:tr,outputSchema:An,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_fill_color`,description:`createStyle.followUp`}}),p=H({name:`jsd_delete_style`,title:`deleteStyle.title`,description:`deleteStyle.description`,method:`delete_style`,inputSchema:nr,outputSchema:jn,annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_get_page`,description:`deleteStyle.followUp`}});return[a(e,t,i),s(e,t,i),u(e,t,i),f(e,t,i),p(e,t,i)]}var Ys=`jsd://recipes`,Xs=`jsd://recipes/{id}`,Zs=[{id:`design-strategy`,uri:`jsd://recipes/design-strategy`,titleKey:`prompt.designStrategy.title`,whenToUse:"画布创作的通用纪律。**从零设计整页 / 界面之前先读这一条**:先查可复用件(按「要复用的是什么」选件类 —— 结构走组件、状态走变体、固定视觉走样式、语义 token 走变量,含各平台复用入口与「命中就复用 / 改源头不逐个改实例」的纪律,以及**什么时候别抽组件**:差异落在实例子节点上、平台未声明 inPlaceVariants、往返预算压不住)、**样式落地流程**(归一化 → 建样式 → 绑 `*StyleId`,含即时设计的样式 id 记账与文本宽度归零的复核纪律),再摸底、结构分层(成品该多深就多深,调用才分批)、语义化命名、归组后再布局(**auto-layout 判据 + 最容易漏掉的分区清单**,机制见 `jsd://recipes/auto-layout`)、图形区走 SVG 还是原生图元的分流、间距与字号阶梯、层序与遮挡、出错回滚,附示例结构树",render:()=>Ps(void 0,Z())},{id:`auto-layout`,uri:`jsd://recipes/auto-layout`,titleKey:`prompt.autoLayout.title`,whenToUse:`**屏内分区排布一律先读这一条**。容器该不该上 auto-layout(判据 + 复核清单:标签栏 / 胶囊组 / 卡片头 / 列表行 / 整屏纵向分区 —— 这些恰是间距唯一靠手调坐标凑的地方)、两条落地路径(建容器时带 sizingMode=推荐 / 事后 set_layout 再用 resize 钉回尺寸)、执行顺序、平台硬约束(layoutWrap 等 Figma 字段本平台没有)、验收四条判据与常见坑(容器被 hug、TEXT 宽度被钉成 1px、手摆坐标在布局里不显形)`,argsHint:`参数 target(要上布局的容器 / 分区描述,如「标签栏」;留空返回通用纪律)`,render:()=>Fs(void 0,Z())},{id:`chart-by-code`,uri:`jsd://recipes/chart-by-code`,titleKey:`prompt.chartByCode.title`,whenToUse:`画图表 / 数据可视化(折线、柱状、饼图 / 环形、散点、雷达、面积、桑基、仪表盘、看板……)。自己写脚本算几何、落盘 SVG,再经 jsd_create_svg 的 svgPath 导入;含零依赖示例与引擎侧硬约束。不适合三类:要吃 auto-layout、要绑变量/样式、要复用成组件 —— 那些用原生节点`,argsHint:`参数 chart(要画什么图:种类 + 数据 + 口径)、svgPath(落盘路径,缺省 /tmp/chart.svg)`,render:()=>Hs(`<在此写明图表种类 + 数据 + 口径>`,void 0)},{id:`html-to-design`,uri:`jsd://recipes/html-to-design`,titleKey:`prompt.htmlToDesign.title`,whenToUse:`把 HTML 片段转成设计稿。默认走 jsd_html_to_design(SVG 保真、忽略复杂样式);要可编辑图层才改 per-type create 手工映射后 reparent 归组`,argsHint:`参数 html(完整 HTML 片段)、name(生成节点名,可省)`,render:()=>js(`<在此粘贴完整 HTML 片段>`)},{id:`icon-grid`,uri:`jsd://recipes/icon-grid`,titleKey:`prompt.iconGrid.title`,whenToUse:`批量插入 Lucide 图标并排成 auto-layout 网格`,argsHint:`参数 icons(逗号分隔的图标名)、size(默认 24)、gap(默认 16)`,render:()=>Ms(`<图标名1,图标名2,…>`)},{id:`script-ops`,uri:`jsd://recipes/script-ops`,titleKey:`prompt.scriptOps.title`,whenToUse:`把多步画布操作合并成一次 jsd_batch 编排或一段宿主脚本;步骤多、往返多、上下文吃紧时读它。也覆盖**整页/整档批量改造**(先摸底、确认现状形态、id 的三种来源、按块切批、清单装不下时用 callsFile 或 CLI exec、回读复核与点名类错误不重试)`,argsHint:`参数 task(要完成的任务,留空只返回脚本化调用纪律)`,render:()=>Ns(void 0)},{id:`text-replace-strategy`,uri:`jsd://recipes/text-replace-strategy`,titleKey:`prompt.textReplace.title`,whenToUse:`批量改文案:在一棵子树里定位并替换文本,含命中范围、命名与回显复核纪律`,argsHint:`参数 rootId(子树根节点 id,留空用当前选中)`,render:()=>Is(void 0)},{id:`variant-sync`,uri:`jsd://recipes/variant-sync`,titleKey:`prompt.variantSync.title`,whenToUse:`同类实例的样式批量同步。改一处要影响全部实例时走它 —— 改主组件而不是逐个改实例(含实例子节点覆盖不生效的处置)`,argsHint:`参数 sourceId(样板节点 id)、targetType(目标节点类型)`,render:()=>Ls(void 0,void 0)},{id:`variable-binding`,uri:`jsd://recipes/variable-binding`,titleKey:`prompt.variableBinding.title`,whenToUse:`变量绑定与批量套用(按当前平台变量面分流)`,argsHint:`参数 target(目标节点 id,留空用当前选中)`,render:()=>Rs(void 0,Z())},{id:`variant-set`,uri:`jsd://recipes/variant-set`,titleKey:`prompt.variantSet.title`,whenToUse:`变体集构建:把同族组件合成 COMPONENT_SET 并设变体属性(按平台能力位分流)`,argsHint:`参数 family(组件族名)`,render:()=>zs(void 0,Z())},{id:`component-property`,uri:`jsd://recipes/component-property`,titleKey:`prompt.componentProperty.title`,whenToUse:`组件属性的定义与设值(值形态 / 写入口 / 读侧 / 替代路径四件套,按平台分流)`,argsHint:`参数 target(组件或实例 id,留空只返回做法与分流)`,render:()=>Bs(void 0,Z())}];function Qs(e){return Zs.find(t=>t.id===e)}function $s(){return[`# text-to-design 配方索引`,``,"多步套路不要临场拼工具 —— 先照配方走。用 `ReadMcpResource` 读下面任意一条的正文(按需读取,不占常驻上下文)。",``,...Zs.map(e=>`- \`${e.uri}\` — ${e.whenToUse}${e.argsHint==null?``:`\n - ${e.argsHint}`}`),``,"只想概览纪律、没有具体任务时,先读 `jsd://recipes/design-strategy`。"].join(`
|
|
414
|
-
`)}function ec(e,t){return{contents:[{uri:typeof e==`string`?e:e.href,mimeType:`text/markdown`,text:t}]}}function tc(e){let t=Zs.map(e=>e.id).join(` / `);return[e.registerResource(`recipes`,Ys,{title:`resources.title7`,description:`多步套路配方索引(**操作手册,不是画布状态**):画图表 / 数据可视化、从零设计整页、HTML 转设计稿、批量改文案、组件与变体、变量绑定。动手做多步任务前先按任务读对应正文;只想概览通用纪律就先读 design-strategy。可用条目:${t}`,mimeType:`text/markdown`},async()=>ec(Ys,$s())),e.registerResource(`recipe`,new ae(Xs,{list:void 0}),{title:`resources.title8`,description:`按 id 读取配方正文(markdown),如 ${Xs.replace(`{id}`,`chart-by-code`)}。可用 id:${t};索引与「何时用」见 ${Ys}`,mimeType:`text/markdown`},async(e,n)=>{let r=n.id,i=Array.isArray(r)?r[0]:r,a=i==null?void 0:Qs(String(i));if(!a)throw Error(`未知配方:${e.href}(可用 id:${t})`);return ec(e,a.render())})]}function nc(e,t){return{contents:[{uri:typeof e==`string`?e:e.href,mimeType:`application/json`,text:JSON.stringify(t,null,2)}]}}function rc(e,t){return[e.registerResource(`canvas-selection`,`jsd://canvas/selection`,{title:`resources.title`,description:`当前选中节点的序列化树(含直接子节点),实时从插件读取;等价于 jsd_get_selection depth=2。⚠ 每个节点带 z = 在父级 children 里的下标 = 绘制顺序(0 = 最底层,越大越靠上)`,mimeType:`application/json`},async()=>nc(`jsd://canvas/selection`,await t.request(`get_selection`,{depth:2}))),e.registerResource(`fonts`,`jsd://fonts`,{title:`resources.title2`,description:`当前环境可用的字体族与各族的可用字型(families / fonts:[{family,styles}]),实时从插件读取。**只回第一页**并给出 total/truncated —— 字体库实测可达约 1900 族,整表会撑爆上下文;要按名字找或翻页请用 jsd_list_fonts 的 family/offset/limit`,mimeType:`application/json`},async()=>nc(`jsd://fonts`,await t.request(`list_fonts`,{}))),e.registerResource(`styles`,`jsd://styles`,{title:`resources.title3`,description:`当前文档可复用的本地样式(PAINT/TEXT/EFFECT/GRID),含 id/name/type;按名应用样式前先读这里拿准确样式名。⚠ 空清单不等于没有样式:本平台未声明样式枚举能力时恒空,回包会带 note 说明`,mimeType:`application/json`},async()=>nc(`jsd://styles`,await t.request(`list_styles`,{}))),e.registerResource(`page`,`jsd://page`,{title:`resources.title4`,description:`**当前页**概览:①第一层节点的几何(id/名称/类型/宽高/x/y,不递归);②可复用资源清单(assets.summary 给四类计数;组件、变体集(带维度→可选值)、样式(PAINT/TEXT/EFFECT/GRID)、变量,每项含 id+名称)。范围:样式与变量是文档级;组件与变体在只读得到当前页的平台(即时设计/MasterGo)**只覆盖当前页**,note 会点名。**设计前先读这里:命中的一律复用,禁止新建重复件**。等价于 jsd_get_page`,mimeType:`application/json`},async()=>nc(`jsd://page`,await t.request(`get_page`,{}))),e.registerResource(`node`,new ae(`jsd://node/{id}`,{list:void 0}),{title:`resources.title5`,description:`按 id 读取节点的序列化结构,如 jsd://node/12:3;等价于 jsd_find ids 精确查找`,mimeType:`application/json`},async(e,n)=>{let r=n.id,i=Array.isArray(r)?r[0]:r;if(!i)throw Error(`缺少节点 id: ${e.href}`);return nc(e,await t.request(`find`,{ids:[i]}))}),e.registerResource(`platform-state`,`jsd://platform/state`,{title:`resources.title6`,description:`daemon 缓存的插件平台状态(platform / capabilities / coreCapabilities / platformOps),取自最近一次 jsd_ping 回包;插件离线或尚未探测到平台时为空(此时先调 jsd_ping)。读缓存不发插件请求 —— 用它判断「当前平台支持什么、有哪些特有 op」比每次 ping 便宜`,mimeType:`application/json`},async()=>nc(`jsd://platform/state`,ji()??{platform:null,note:`尚未探测到平台(插件未连接或刚重连),请先调用 jsd_ping`}))]}function ic(e,t,n){let r=H({name:`jsd_ping`,title:n.t(`ping.title`,{client:ki.label}),description:n.t(`ping.description`,{client:ki.label}),outputSchema:gn,annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},alwaysEnabled:!0,timeout:xi,followUp:{type:`tool`,tool:`jsd_get_selection`,description:`ping.followUp`},run:async()=>{try{let e=await t.request(`ping`,{},{timeout:xi});return{connected:!0,platform:e?.platform,capabilities:e?.capabilities,coreCapabilities:e?.coreCapabilities,platformOps:e?.platformOps}}catch(e){return{connected:!1,error:e instanceof Error?e.message:String(e)}}}}),i=H({name:`jsd_get_selection`,title:`getSelection.title`,description:`getSelection.description`,method:`get_selection`,inputSchema:Ut,outputSchema:_n,annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_find`,description:`getSelection.description2`}}),a=H({name:`jsd_get_page`,title:`getPage.title`,description:`getPage.description`,method:`get_page`,inputSchema:dn,outputSchema:kn,annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_find`,description:`getPage.followUp`}});return[r(e,t,n),i(e,t,n),a(e,t,n)]}var ac=[ic,ls,Ts,Es,Co,Ks,ws,Js,lo,Ds,rc,tc,(e,t,n)=>Os(e,n)];function oc(e,t=ya()){let n=new ie({name:_i,version:L},{supportedProtocolVersions:[`2026-07-28`,..._],instructions:t.t(`mcp.instructions`),cacheHints:{"tools/list":{ttlMs:Ci,cacheScope:`private`},"prompts/list":{ttlMs:Ci,cacheScope:`private`},"resources/list":{ttlMs:Ci,cacheScope:`private`},"resources/templates/list":{ttlMs:Ci,cacheScope:`private`},"resources/read":{ttlMs:0,cacheScope:`private`}}});for(let r of ac)r(n,e,t);return n}var sc=null;async function cc(e){let t=new AbortController,n=setTimeout(()=>t.abort(),ai);try{let n=await fetch(ii(e),{signal:t.signal});if(!n.ok)return P(`查询 ${e} 最新版本失败: HTTP ${n.status}(本次不提示升级)`),null;let r=await n.json();return typeof r.version==`string`?r.version:(P(`查询 ${e} 最新版本失败: 响应无 version 字段(本次不提示升级)`),null)}catch(t){return P(`查询 ${e} 最新版本失败(${t instanceof Error?t.message:String(t)}):本次不提示升级`),null}finally{clearTimeout(n)}}async function lc(){let e=Date.now();if(sc!=null&&e-sc.at<18e5)return sc.latest;let[t,n]=await Promise.all([cc(ni.ui),cc(ni.mcp)]);return N(`npm 最新版本: ui=${t??`未知`} mcp=${n??`未知`}`),sc={at:e,latest:{ui:t,mcp:n}},sc.latest}async function uc(){let e=Date.now()+yi;do{let e=await Wi();if(e.state===`proxy`)return await e.client.close().catch(()=>{}),M(`已有 daemon 在运行,本次启动跳过`),!1;if(e.state===`foreign`&&(F(`端口 ${I} 被非 text-to-design MCP 服务占用,请先释放`),process.exit(1)),e.state===`none`)return!0;await Gi(250)}while(Date.now()<e);return await Vi()===null||(M(`已有 daemon 持有端口,本次启动跳过`),!1)}async function dc(e){if(!await uc()){await Ui();return}await e.start(gi),M(`daemon: 插件 WS ws://localhost:${e.port}`);let t=null,n=oe(()=>t??=oc(e),{legacy:`reject`}),r=pe(n),i=de(),a=fe(),o=null,s=null,c=()=>{lc().then(t=>{let n=`ui=${t.ui??`未查到`} mcp=${t.mcp??`未查到`}`;if(!e.isConnected){M(`版本同步: ${n} (面板未连接,只更新缓存)`);return}e.pushVersion({type:`version`,latest:t}),M(`版本同步: ${n} (已推送面板)`)})};e.onPluginConnect=c;let l=t=>{M(`daemon 退出: ${t}`),s!=null&&clearInterval(s),n.close().catch(e=>{N(`关闭 MCP handler 失败(忽略): ${e instanceof Error?e.message:String(e)}`)}),e.stop(),o?.close(),process.exit(0)};await new Promise((e,t)=>{o=
|
|
413
|
+
- [ ] 文字要不要可编辑(见第 6 节)—— 要就把标题/图例另建原生节点,别全塞进 SVG 图层。`}function Us(e,t,n=[]){let r=e,i=r?.updated??[],a=[];i.length>0&&a.push({type:`text`,text:`已更新 ${i.length} 个节点`});let o=r?.warnings??[];for(let e of o)a.push({type:`text`,text:`⚠ ${e}`});if(i.length===0&&t.length===0&&a.push({type:`text`,text:`未传入任何属性,本次未修改`}),n.length>0){let e=new Set(i.map(e=>e.id)),t=n.filter(t=>!e.has(t));t.length>0&&a.push({type:`text`,text:`以下节点未更新(可能已失效/被连坐删除): ${t.join(`, `)}。可用 jsd_find 复核后重试`})}return a}var Ws=`⚠ recursive=true 只作用于**后代**,不含目标节点自身(给图标/容器传 recursive 刷色,容器自己不再被印上方框);无子节点的叶子自身即整棵子树,仍会改。要把容器自己也算上才显式传 includeSelf=true,那时结果会带 warnings 点名「容器自身也被修改」。`;function Q(e){let t=kr[e.method],n=e=>t.filter(t=>e[t]!==void 0&&Oe[t]!==void 0),r=e=>{let t=e.ids??[];return e.recursive===!0&&e.includeSelf!==!0?[]:t};return{name:e.name,title:e.title,description:e.description+Ws,inputSchema:e.inputSchema,outputSchema:hn,annotations:e.annotations,method:e.method,payload:e=>{let{ids:t,matchName:n,recursive:r,includeSelf:i,...a}=e,o={props:a};return t!==void 0&&(o.ids=t),n!==void 0&&(o.matchName=n),r!==void 0&&(o.recursive=r),i!==void 0&&(o.includeSelf=i),o},...e.followUp===void 0?{}:{followUp:e.followUp},extraContent:(e,t)=>Us(e,n(t),r(t))}}var Gs=Kr();function Ks(e,t,n){return[Q({name:`jsd_set_fill_color`,title:`setFillColor.title`,description:n.t(`setFillColor.description`,{warn:Gs}),method:`set_fill`,inputSchema:vr,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_stroke`,description:`setFillColor.followUp`}}),Q({name:`jsd_set_stroke`,title:`setStroke.title`,description:`设置描边列表、宽度(可四边分开)、对齐/端点/连接、虚线模式与团队库描边样式。strokes 整体替换非合并。把描边烘焙成矢量用 jsd_outline_stroke。`+Gs,method:`set_stroke`,inputSchema:yr,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_fill_color`,description:`setStroke.description`}}),Q({name:`jsd_set_cornerRadius`,title:`setCornerRadius.title`,description:`设置圆角半径(corners 四角可分开)与圆角平滑度。仅 FRAME/RECTANGLE/ELLIPSE/POLYGON/STAR/VECTOR/BOOLEAN_OPERATION 生效,LINE/TEXT 无圆角。`+Gs,method:`set_corner_radius`,inputSchema:br,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_effects`,description:`setCornerRadius.description`}}),Q({name:`jsd_set_text`,title:`setText.title`,description:n.t(`setText.description`,{warn:Gs}),method:`set_text`,inputSchema:xr,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_rename_node`,description:`setText.followUp`}}),Q({name:`jsd_move_node`,title:`moveNode.title`,description:`设置节点 x/y(相对父节点)与 rotation(绕左上角原点)。auto-layout 子节点的位置由父容器接管,修改可能被布局覆盖——那种情况请改 jsd_set_layout 的间距/对齐`,method:`move`,inputSchema:Sr,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_resize_node`,description:`moveNode.description`}}),Q({name:`jsd_resize_node`,title:`resizeNode.title`,description:`设置节点 width/height,并可同时传 x/y 一步完成「改尺寸 + 定位」(按坐标排布、批量摆位时常用,避免分两次调用让中间态被引擎自动尺寸/约束改写;reparent 已自动保持绝对位置,不需要用本工具摆回)。TEXT 默认自适应(WIDTH_AND_HEIGHT)时会覆盖显式尺寸,要固定文本框先 jsd_set_text 设 textAutoResize=NONE。横线/竖线用 LINE:零轴会被兜到 0.01 过引擎校验(存回读仍是 0);其他类型低于 0.01 会明确报错(引擎 resize 下限)`,method:`resize`,inputSchema:Cr,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_visibility`,description:`resizeNode.description`}}),Q({name:`jsd_set_layout`,title:`setLayout.title`,description:`设置容器的 auto-layout:layoutMode 与 itemSpacing/padding*/主轴交叉轴尺寸和对齐/约束/伸缩可在同一次调用里一起传(引擎先应用 layoutMode 再应用间距)。适用 FRAME / COMPONENT / COMPONENT_SET —— 变体集内变体重叠时用它排布(三平台节点均继承 frame 的自动布局能力)。建议建节点时不要混着传,归组并摆好后再单独设;但⚠ 开布局会按内容重算容器尺寸(有子节点时主轴被翻成 AUTO:实测 400×300 的容器 + 一个 200×60 子节点 → 200×60,而 sizingMode 字段回读仍是 FIXED,只有结果 warnings 点名),要保住尺寸就把 layoutMode 与 primaryAxisSizingMode / counterAxisSizingMode **放同一次调用里一起传 FIXED**(实测保得住)。只管布局语义:改节点宽高用 jsd_resize_node,本工具不接受 width/height`,method:`set_layout`,inputSchema:wr,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_reparent_nodes`,description:`setLayout.description`}}),Q({name:`jsd_set_effects`,title:`setEffects.title`,description:`设置阴影/模糊效果(可多层叠加,整体替换)、团队库效果样式、溢出裁剪、布局网格(参考线)与椭圆环形参数(仅 ELLIPSE)。`+Gs,method:`set_effects`,inputSchema:Tr,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_visibility`,description:`setEffects.description`}}),Q({name:`jsd_set_visibility`,title:`setVisibility.title`,description:`设置不透明度 opacity(0-1)、visible 显示开关与 locked 锁定。锁定后节点不能被选中或编辑`,method:`set_visibility`,inputSchema:Er,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_get_selection`,description:`setVisibility.description`}}),Q({name:`jsd_rename_node`,title:`renameNode.title`,description:`重命名节点。命名建议说明用途(如「登录页/邮箱输入/主按钮」),不用「矩形 1」「Frame 2」;批量替换文案用 jsd_set_text`,method:`rename`,inputSchema:Dr,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_text`,description:`renameNode.description`}}),Q({name:`jsd_set_shape`,title:`setShape.title`,description:`设置形状参数(承接原 jsd_update_node 的长尾字段):pointCount 多边形/星形角点数(仅 POLYGON/STAR 生效)、innerRadius 星形内半径比例(0-1,仅 STAR 生效)。改尺寸/圆角用 jsd_resize_node / jsd_set_cornerRadius`,method:`set_shape`,inputSchema:Or,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_fill_color`,description:`setShape.description`}})].map(r=>H(r)(e,t,n))}function qs(e,t){let n=typeof t==`string`?t.toLowerCase():``;if(n===`png`||n===`svg`||n===`pdf`)return n;if(n===`jpg`||n===`jpeg`)return`jpg`;let r=(e??``).toLowerCase();return r.includes(`png`)?`png`:r.includes(`jpeg`)||r.includes(`jpg`)?`jpg`:r.includes(`svg`)?`svg`:r.includes(`pdf`)?`pdf`:`bin`}function Js(e,t,i){let a=H({name:`jsd_export`,title:`export.title`,description:`export.description`,inputSchema:ln,outputSchema:Cn,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},timeout:Si,followUp:{type:`tool`,tool:`jsd_fill_image`,description:`export.description2`},run:async(e,t,r)=>{let{ids:i,format:a,scale:s,savePath:u,includeDataUrl:f}=e,p=(await t.request(`export`,{ids:i,format:a,scale:s},{signal:r,timeout:6e4})).exports??{},m=[],h=[];for(let[e,t]of Object.entries(p)){let r=t.bytes,i=t.mimeType,a={id:e,name:t.name,format:t.format,mimeType:i,size:r.byteLength};if(u&&(n(l(u),{recursive:!0}),o(u,r),a.path=u),f){if(r.byteLength>wi){let n=u??d(c(),`jsd-export-${e.replace(/[^a-zA-Z0-9_-]/g,`_`)}-${Date.now()}.${qs(i,t.format)}`);u||o(n,r),a.path=n,h.push(`${e}(实际 ${r.byteLength} 字节 > 上限 ${wi} 字节)已落盘:${n}`)}else a.dataUrl=`data:${i};base64,${r.toString(`base64`)}`}m.push(a)}return{exports:m,dataUrlOverflow:h}},extraContent:(e,t)=>{let n=t.ids??[],r=e.exports??[],i=e.dataUrlOverflow??[],a=[];r.length>0&&a.push({type:`text`,text:`已导出 ${r.length} 个节点`});for(let e of i)a.push({type:`text`,text:`⚠️ 图片超过内联上限,未返回 base64,${e}。需要图片内容请读取该文件路径,或调小 scale 后重试。`});if(n.length>0){let e=new Set(r.map(e=>e.id)),t=n.filter(t=>!e.has(t));t.length>0&&a.push({type:`text`,text:`导出失败(节点可能已失效): ${t.join(`, `)}。可用 jsd_find 复核`})}return a}}),s=H({name:`jsd_fill_image`,title:`fillImage.title`,description:`fillImage.description`,inputSchema:fn,outputSchema:hn,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},timeout:Si,followUp:{type:`tool`,tool:`jsd_get_selection`,description:`fillImage.description2`},run:async(e,t,n)=>{let{ids:i,sourcePath:a}=e,o;try{o=r(a)}catch(e){throw Error(`读取文件失败: ${e instanceof Error?e.message:String(e)}`)}return t.request(`fill_image`,{ids:i,bytes:new Uint8Array(o)},{signal:n,timeout:Si})}}),u=H({name:`jsd_list_fonts`,title:`listFonts.title`,description:`按家族名过滤、分页列出可用字体与各族的可用字型(返回 families 与 fonts:[{family,styles}])。**默认只回第一页**(50 族,上限 500):字体库规模随平台差一个量级——MasterGo 实测约 1900 族 / 整表 322 KB,整表必然撑爆上下文。结果里的 total 是过滤后的家族总数、truncated 表示还有下一页;按名字找字体传 family(不区分大小写的子串),翻页传 offset/limit。写 fontName 时 family 用 fonts[].family 原样、style 用同一项的**全名**(如 SourceHanSansCN-Bold,不是简称 "Bold")——组合不存在时不报错、会静默退回默认字面(命中时结果 warnings 点名);引擎解析成功会把 family/style 规范化成短名,回读短名属正常`,method:`list_fonts`,inputSchema:un,outputSchema:wn,annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_text`,description:`listFonts.description`}}),f=H({name:`jsd_create_style`,title:`createStyle.title`,description:`createStyle.description`,method:`create_style`,inputSchema:tr,outputSchema:An,annotations:{readOnlyHint:!1,destructiveHint:!1,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_set_fill_color`,description:`createStyle.followUp`}}),p=H({name:`jsd_delete_style`,title:`deleteStyle.title`,description:`deleteStyle.description`,method:`delete_style`,inputSchema:nr,outputSchema:jn,annotations:{readOnlyHint:!1,destructiveHint:!0,idempotentHint:!1,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_get_page`,description:`deleteStyle.followUp`}});return[a(e,t,i),s(e,t,i),u(e,t,i),f(e,t,i),p(e,t,i)]}var Ys=`jsd://recipes`,Xs=`jsd://recipes/{id}`,Zs=[{id:`design-strategy`,uri:`jsd://recipes/design-strategy`,titleKey:`prompt.designStrategy.title`,whenToUse:"画布创作的通用纪律。**从零设计整页 / 界面之前先读这一条**:先查可复用件(按「要复用的是什么」选件类 —— 结构走组件、状态走变体、固定视觉走样式、语义 token 走变量,含各平台复用入口与「命中就复用 / 改源头不逐个改实例」的纪律,以及**什么时候别抽组件**:差异落在实例子节点上、平台未声明 inPlaceVariants、往返预算压不住)、**样式落地流程**(归一化 → 建样式 → 绑 `*StyleId`,含即时设计的样式 id 记账与文本宽度归零的复核纪律),再摸底、结构分层(成品该多深就多深,调用才分批)、语义化命名、归组后再布局(**auto-layout 判据 + 最容易漏掉的分区清单**,机制见 `jsd://recipes/auto-layout`)、图形区走 SVG 还是原生图元的分流、间距与字号阶梯、层序与遮挡、出错回滚,附示例结构树",render:()=>Ps(void 0,Z())},{id:`auto-layout`,uri:`jsd://recipes/auto-layout`,titleKey:`prompt.autoLayout.title`,whenToUse:`**屏内分区排布一律先读这一条**。容器该不该上 auto-layout(判据 + 复核清单:标签栏 / 胶囊组 / 卡片头 / 列表行 / 整屏纵向分区 —— 这些恰是间距唯一靠手调坐标凑的地方)、两条落地路径(建容器时带 sizingMode=推荐 / 事后 set_layout 再用 resize 钉回尺寸)、执行顺序、平台硬约束(layoutWrap 等 Figma 字段本平台没有)、验收四条判据与常见坑(容器被 hug、TEXT 宽度被钉成 1px、手摆坐标在布局里不显形)`,argsHint:`参数 target(要上布局的容器 / 分区描述,如「标签栏」;留空返回通用纪律)`,render:()=>Fs(void 0,Z())},{id:`chart-by-code`,uri:`jsd://recipes/chart-by-code`,titleKey:`prompt.chartByCode.title`,whenToUse:`画图表 / 数据可视化(折线、柱状、饼图 / 环形、散点、雷达、面积、桑基、仪表盘、看板……)。自己写脚本算几何、落盘 SVG,再经 jsd_create_svg 的 svgPath 导入;含零依赖示例与引擎侧硬约束。不适合三类:要吃 auto-layout、要绑变量/样式、要复用成组件 —— 那些用原生节点`,argsHint:`参数 chart(要画什么图:种类 + 数据 + 口径)、svgPath(落盘路径,缺省 /tmp/chart.svg)`,render:()=>Hs(`<在此写明图表种类 + 数据 + 口径>`,void 0)},{id:`html-to-design`,uri:`jsd://recipes/html-to-design`,titleKey:`prompt.htmlToDesign.title`,whenToUse:`把 HTML 片段转成设计稿。默认走 jsd_html_to_design(SVG 保真、忽略复杂样式);要可编辑图层才改 per-type create 手工映射后 reparent 归组`,argsHint:`参数 html(完整 HTML 片段)、name(生成节点名,可省)`,render:()=>js(`<在此粘贴完整 HTML 片段>`)},{id:`icon-grid`,uri:`jsd://recipes/icon-grid`,titleKey:`prompt.iconGrid.title`,whenToUse:`批量插入 Lucide 图标并排成 auto-layout 网格`,argsHint:`参数 icons(逗号分隔的图标名)、size(默认 24)、gap(默认 16)`,render:()=>Ms(`<图标名1,图标名2,…>`)},{id:`script-ops`,uri:`jsd://recipes/script-ops`,titleKey:`prompt.scriptOps.title`,whenToUse:`把多步画布操作合并成一次 jsd_batch 编排或一段宿主脚本;步骤多、往返多、上下文吃紧时读它。也覆盖**整页/整档批量改造**(先摸底、确认现状形态、id 的三种来源、按块切批、清单装不下时用 callsFile 或 CLI exec、回读复核与点名类错误不重试)`,argsHint:`参数 task(要完成的任务,留空只返回脚本化调用纪律)`,render:()=>Ns(void 0)},{id:`text-replace-strategy`,uri:`jsd://recipes/text-replace-strategy`,titleKey:`prompt.textReplace.title`,whenToUse:`批量改文案:在一棵子树里定位并替换文本,含命中范围、命名与回显复核纪律`,argsHint:`参数 rootId(子树根节点 id,留空用当前选中)`,render:()=>Is(void 0)},{id:`variant-sync`,uri:`jsd://recipes/variant-sync`,titleKey:`prompt.variantSync.title`,whenToUse:`同类实例的样式批量同步。改一处要影响全部实例时走它 —— 改主组件而不是逐个改实例(含实例子节点覆盖不生效的处置)`,argsHint:`参数 sourceId(样板节点 id)、targetType(目标节点类型)`,render:()=>Ls(void 0,void 0)},{id:`variable-binding`,uri:`jsd://recipes/variable-binding`,titleKey:`prompt.variableBinding.title`,whenToUse:`变量绑定与批量套用(按当前平台变量面分流)`,argsHint:`参数 target(目标节点 id,留空用当前选中)`,render:()=>Rs(void 0,Z())},{id:`variant-set`,uri:`jsd://recipes/variant-set`,titleKey:`prompt.variantSet.title`,whenToUse:`变体集构建:把同族组件合成 COMPONENT_SET 并设变体属性(按平台能力位分流)`,argsHint:`参数 family(组件族名)`,render:()=>zs(void 0,Z())},{id:`component-property`,uri:`jsd://recipes/component-property`,titleKey:`prompt.componentProperty.title`,whenToUse:`组件属性的定义与设值(值形态 / 写入口 / 读侧 / 替代路径四件套,按平台分流)`,argsHint:`参数 target(组件或实例 id,留空只返回做法与分流)`,render:()=>Bs(void 0,Z())}];function Qs(e){return Zs.find(t=>t.id===e)}function $s(){return[`# text-to-design 配方索引`,``,"多步套路不要临场拼工具 —— 先照配方走。用 `ReadMcpResource` 读下面任意一条的正文(按需读取,不占常驻上下文)。",``,...Zs.map(e=>`- \`${e.uri}\` — ${e.whenToUse}${e.argsHint==null?``:`\n - ${e.argsHint}`}`),``,"只想概览纪律、没有具体任务时,先读 `jsd://recipes/design-strategy`。"].join(`
|
|
414
|
+
`)}function ec(e,t){return{contents:[{uri:typeof e==`string`?e:e.href,mimeType:`text/markdown`,text:t}]}}function tc(e){let t=Zs.map(e=>e.id).join(` / `);return[e.registerResource(`recipes`,Ys,{title:`resources.title7`,description:`多步套路配方索引(**操作手册,不是画布状态**):画图表 / 数据可视化、从零设计整页、HTML 转设计稿、批量改文案、组件与变体、变量绑定。动手做多步任务前先按任务读对应正文;只想概览通用纪律就先读 design-strategy。可用条目:${t}`,mimeType:`text/markdown`},async()=>ec(Ys,$s())),e.registerResource(`recipe`,new ae(Xs,{list:void 0}),{title:`resources.title8`,description:`按 id 读取配方正文(markdown),如 ${Xs.replace(`{id}`,`chart-by-code`)}。可用 id:${t};索引与「何时用」见 ${Ys}`,mimeType:`text/markdown`},async(e,n)=>{let r=n.id,i=Array.isArray(r)?r[0]:r,a=i==null?void 0:Qs(String(i));if(!a)throw Error(`未知配方:${e.href}(可用 id:${t})`);return ec(e,a.render())})]}function nc(e,t){return{contents:[{uri:typeof e==`string`?e:e.href,mimeType:`application/json`,text:JSON.stringify(t,null,2)}]}}function rc(e,t){return[e.registerResource(`canvas-selection`,`jsd://canvas/selection`,{title:`resources.title`,description:`当前选中节点的序列化树(含直接子节点),实时从插件读取;等价于 jsd_get_selection depth=2。⚠ 每个节点带 z = 在父级 children 里的下标 = 绘制顺序(0 = 最底层,越大越靠上)`,mimeType:`application/json`},async()=>nc(`jsd://canvas/selection`,await t.request(`get_selection`,{depth:2}))),e.registerResource(`fonts`,`jsd://fonts`,{title:`resources.title2`,description:`当前环境可用的字体族与各族的可用字型(families / fonts:[{family,styles}]),实时从插件读取。**只回第一页**并给出 total/truncated —— 字体库实测可达约 1900 族,整表会撑爆上下文;要按名字找或翻页请用 jsd_list_fonts 的 family/offset/limit`,mimeType:`application/json`},async()=>nc(`jsd://fonts`,await t.request(`list_fonts`,{}))),e.registerResource(`styles`,`jsd://styles`,{title:`resources.title3`,description:`当前文档可复用的本地样式(PAINT/TEXT/EFFECT/GRID),含 id/name/type;按名应用样式前先读这里拿准确样式名。⚠ 空清单不等于没有样式:本平台未声明样式枚举能力时恒空,回包会带 note 说明`,mimeType:`application/json`},async()=>nc(`jsd://styles`,await t.request(`list_styles`,{}))),e.registerResource(`page`,`jsd://page`,{title:`resources.title4`,description:`**当前页**概览:①第一层节点的几何(id/名称/类型/宽高/x/y,不递归);②可复用资源清单(assets.summary 给四类计数;组件、变体集(带维度→可选值)、样式(PAINT/TEXT/EFFECT/GRID)、变量,每项含 id+名称)。范围:样式与变量是文档级;组件与变体在只读得到当前页的平台(即时设计/MasterGo)**只覆盖当前页**,note 会点名。**设计前先读这里:命中的一律复用,禁止新建重复件**。等价于 jsd_get_page`,mimeType:`application/json`},async()=>nc(`jsd://page`,await t.request(`get_page`,{}))),e.registerResource(`node`,new ae(`jsd://node/{id}`,{list:void 0}),{title:`resources.title5`,description:`按 id 读取节点的序列化结构,如 jsd://node/12:3;等价于 jsd_find ids 精确查找`,mimeType:`application/json`},async(e,n)=>{let r=n.id,i=Array.isArray(r)?r[0]:r;if(!i)throw Error(`缺少节点 id: ${e.href}`);return nc(e,await t.request(`find`,{ids:[i]}))}),e.registerResource(`platform-state`,`jsd://platform/state`,{title:`resources.title6`,description:`daemon 缓存的插件平台状态(platform / capabilities / coreCapabilities / platformOps),取自最近一次 jsd_ping 回包;插件离线或尚未探测到平台时为空(此时先调 jsd_ping)。读缓存不发插件请求 —— 用它判断「当前平台支持什么、有哪些特有 op」比每次 ping 便宜`,mimeType:`application/json`},async()=>nc(`jsd://platform/state`,ji()??{platform:null,note:`尚未探测到平台(插件未连接或刚重连),请先调用 jsd_ping`}))]}function ic(e,t,n){let r=H({name:`jsd_ping`,title:n.t(`ping.title`,{client:ki.label}),description:n.t(`ping.description`,{client:ki.label}),outputSchema:gn,annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},alwaysEnabled:!0,timeout:xi,followUp:{type:`tool`,tool:`jsd_get_selection`,description:`ping.followUp`},run:async()=>{try{let e=await t.request(`ping`,{},{timeout:xi});return{connected:!0,platform:e?.platform,capabilities:e?.capabilities,coreCapabilities:e?.coreCapabilities,platformOps:e?.platformOps}}catch(e){return{connected:!1,error:e instanceof Error?e.message:String(e)}}}}),i=H({name:`jsd_get_selection`,title:`getSelection.title`,description:`getSelection.description`,method:`get_selection`,inputSchema:Ut,outputSchema:_n,annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_find`,description:`getSelection.description2`}}),a=H({name:`jsd_get_page`,title:`getPage.title`,description:`getPage.description`,method:`get_page`,inputSchema:dn,outputSchema:kn,annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0,openWorldHint:!1},followUp:{type:`tool`,tool:`jsd_find`,description:`getPage.followUp`}});return[r(e,t,n),i(e,t,n),a(e,t,n)]}var ac=[ic,ls,Ts,Es,Co,Ks,ws,Js,lo,Ds,rc,tc,(e,t,n)=>Os(e,n)];function oc(e,t=ya()){let n=new ie({name:_i,version:L},{supportedProtocolVersions:[`2026-07-28`,..._],instructions:t.t(`mcp.instructions`),cacheHints:{"tools/list":{ttlMs:Ci,cacheScope:`private`},"prompts/list":{ttlMs:Ci,cacheScope:`private`},"resources/list":{ttlMs:Ci,cacheScope:`private`},"resources/templates/list":{ttlMs:Ci,cacheScope:`private`},"resources/read":{ttlMs:0,cacheScope:`private`}}});for(let r of ac)r(n,e,t);return n}var sc=null;async function cc(e){let t=new AbortController,n=setTimeout(()=>t.abort(),ai);try{let n=await fetch(ii(e),{signal:t.signal});if(!n.ok)return P(`查询 ${e} 最新版本失败: HTTP ${n.status}(本次不提示升级)`),null;let r=await n.json();return typeof r.version==`string`?r.version:(P(`查询 ${e} 最新版本失败: 响应无 version 字段(本次不提示升级)`),null)}catch(t){return P(`查询 ${e} 最新版本失败(${t instanceof Error?t.message:String(t)}):本次不提示升级`),null}finally{clearTimeout(n)}}async function lc(){let e=Date.now();if(sc!=null&&e-sc.at<18e5)return sc.latest;let[t,n]=await Promise.all([cc(ni.ui),cc(ni.mcp)]);return N(`npm 最新版本: ui=${t??`未知`} mcp=${n??`未知`}`),sc={at:e,latest:{ui:t,mcp:n}},sc.latest}async function uc(){let e=Date.now()+yi;do{let e=await Wi();if(e.state===`proxy`)return await e.client.close().catch(()=>{}),M(`已有 daemon 在运行,本次启动跳过`),!1;if(e.state===`foreign`&&(F(`端口 ${I} 被非 text-to-design MCP 服务占用,请先释放`),process.exit(1)),e.state===`none`)return!0;await Gi(250)}while(Date.now()<e);return await Vi()===null||(M(`已有 daemon 持有端口,本次启动跳过`),!1)}async function dc(e){if(!await uc()){await Ui();return}await e.start(gi),M(`daemon: 插件 WS ws://localhost:${e.port}`);let t=null,n=oe(()=>t??=oc(e),{legacy:`reject`}),r=pe(n),i=de(),a=fe(),o=null,s=null,c=()=>{lc().then(t=>{let n=`ui=${t.ui??`未查到`} mcp=${t.mcp??`未查到`}`;if(!e.isConnected){M(`版本同步: ${n} (面板未连接,只更新缓存)`);return}e.pushVersion({type:`version`,latest:t}),M(`版本同步: ${n} (已推送面板)`)})};e.onPluginConnect=c;let l=t=>{M(`daemon 退出: ${t}`),s!=null&&clearInterval(s),n.close().catch(e=>{N(`关闭 MCP handler 失败(忽略): ${e instanceof Error?e.message:String(e)}`)}),e.stop(),o?.close(),process.exit(0)};await new Promise((e,t)=>{o=ee((e,t)=>{if(!i(e,t)||!a(e,t))return;let n=Date.now(),o=e.url??``;if(t.on(`finish`,()=>{let r=`HTTP ${e.method} ${o} → ${t.statusCode} (${Date.now()-n}ms)`;t.statusCode>=400?M(r):N(r)}),e.method===`GET`&&o===`/health`){t.writeHead(200,{"content-type":`application/json`}),t.end(JSON.stringify({name:_i,version:L,pid:process.pid,startedAt:vi}));return}if(e.method===`POST`&&o===`/shutdown`){t.writeHead(200,{"content-type":`application/json`}),t.end(JSON.stringify({ok:!0})),setTimeout(()=>l(`收到 /shutdown 请求`),100);return}r(e,t)}),o.once(`error`,t),o.listen(I,`127.0.0.1`,()=>e())}),M(`daemon: MCP HTTP http://127.0.0.1:${I}/mcp`),M(`daemon 就绪,常驻运行(更新时由版本自检自动替换)`),s=setInterval(c,be),c(),process.on(`SIGINT`,()=>l(`SIGINT`))}async function fc(){await Ui();let e=await Wi();if(e.state===`foreign`)F(`端口 ${I} 被非 text-to-design MCP 服务占用,请先释放`),process.exit(1);else if(e.state===`proxy`){await _a(e.client);return}e.state===`none`?(M(`未发现 daemon,自动拉起...`),sa()):M(`daemon 正在启动,等待就绪...`);let t=Date.now()+yi;for(;Date.now()<t;){await Gi(250);let e=await Wi();if(e.state===`proxy`){await _a(e.client);return}e.state===`foreign`&&(F(`端口 ${I} 被非 text-to-design MCP 服务占用,请先释放`),process.exit(1))}F(`daemon 启动超时(${yi/1e3}s),请检查残留进程后重试`),process.exit(1)}var $=`text-to-design-mcp`;function pc(e){return e.includes(` `)?`"${e}"`:e}function mc(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`)}function hc(){let e=f(process.argv[1]??``),t=process.execPath;return e?e.endsWith(`.ts`)?{problem:`当前是开发态(tsx 直接跑 TS 源码),不能注册自启。请改用构建产物(pnpm build 后 node dist/index.js install-service)或全局安装的 text-to-design-mcp`}:e.split(p).includes(`_npx`)?{problem:`入口位于 npx 缓存目录(${e}),该目录会被 npm 清理,注册后必然失效。请先 npm i -g text-to-design-mcp,再用全局命令重跑 install-service`}:{exe:t,script:e}:{problem:`无法定位入口脚本(process.argv[1] 为空)`}}function gc(e,t){return[{kind:`write`,path:d(s(),`.config/systemd/user`,`${$}.service`),content:`[Unit]
|
|
415
415
|
Description=${_i} (design plugin bridge: WS ${gi} / MCP HTTP ${I})
|
|
416
416
|
Documentation=https://github.com/wzrove/text-to-design
|
|
417
417
|
After=network.target
|