figma-use
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseuse_figma — Figma Plugin API Skill
use_figma — Figma Plugin API 技能
Use MCP to execute JavaScript in Figma files via the Plugin API. All detailed reference docs live in .
use_figmareferences/Always pass when calling . This is a logging parameter used to track skill usage — it does not affect execution.
skillNames: "figma-use"use_figmaIf the task involves building or updating a full page, screen, or multi-section layout in Figma from code, also load figma-generate-design. It provides the workflow for discovering design system components via , importing them, and assembling screens incrementally. Both skills work together: this one for the API rules, that one for the screen-building workflow.
search_design_systemBefore anything, load plugin-api-standalone.index.md to understand what is possible. When you are asked to write plugin API code, use this context to grep plugin-api-standalone.d.ts for relevant types, methods, and properties. This is the definitive source of truth for the API surface. It is a large typings file, so do not load it all at once, grep for relevant sections as needed.
IMPORTANT: Whenever you work with design systems, start with working-with-design-systems/wwds.md to understand the key concepts, processes, and guidelines for working with design systems in Figma. Then load the more specific references for components, variables, text styles, and effect styles as needed.
使用 MCP通过Plugin API在Figma文件中执行JavaScript。所有详细参考文档都位于目录下。
use_figmareferences/**调用时必须传入。**这是一个用于跟踪技能使用情况的日志参数——不会影响执行。
use_figmaskillNames: "figma-use"如果任务涉及从代码在Figma中构建或更新完整页面、屏幕或多节布局,还需加载figma-generate-design。它提供了通过发现设计系统组件、导入组件并逐步组装屏幕的工作流。这两个技能可以协同工作:本技能负责API规则,而另一个技能负责屏幕构建工作流。
search_design_system在开始任何操作之前,请先加载plugin-api-standalone.index.md以了解可实现的功能。当需要编写Plugin API代码时,请使用此上下文在plugin-api-standalone.d.ts中搜索相关类型、方法和属性。这是API接口的权威来源。这是一个大型类型定义文件,因此不要一次性全部加载,而是根据需要搜索相关部分。
重要提示:处理设计系统时,请先从working-with-design-systems/wwds.md开始,了解在Figma中处理设计系统的关键概念、流程和指南。然后根据需要加载关于组件、变量、文本样式和效果样式的更具体参考文档。
1. Critical Rules
1. 关键规则
- Use to send data back. The return value is JSON-serialized automatically (objects, arrays, strings, numbers). Do NOT call
returnor wrap code in an async IIFE — this is handled for you.figma.closePlugin() - Write plain JavaScript with top-level and
await. Code is automatically wrapped in an async context. Do NOT wrap inreturn.(async () => { ... })() - throws "not implemented" — never use it 3a.
figma.notify()/getPluginData()are not supported insetPluginData()— do not use them. Useuse_figma/getSharedPluginData()instead (these ARE supported), or track node IDs by returning them and passing them to subsequent calls.setSharedPluginData() - is NOT returned — use
console.log()for outputreturn - Work incrementally in small steps. Break large operations into multiple calls. Validate after each step. This is the single most important practice for avoiding bugs.
use_figma - Colors are 0–1 range (not 0–255): = red
{r: 1, g: 0, b: 0} - Fills/strokes are read-only arrays — clone, modify, reassign
- Font MUST be loaded before any text operation:
await figma.loadFontAsync({family, style}) - Pages load incrementally — use to switch pages and load their content (see Page Rules below)
await figma.setCurrentPageAsync(page) - returns a NEW paint — must capture and reassign
setBoundVariableForPaint - accepts collection object or ID string (object preferred)
createVariable - MUST be set AFTER
layoutSizingHorizontal/Vertical = 'FILL'— setting before append throws. Same applies toparent.appendChild(child)on non-auto-layout nodes.'HUG' - Position new top-level nodes away from (0,0). Nodes appended directly to the page default to (0,0). Scan to find a clear position (e.g., to the right of the rightmost node). This only applies to page-level nodes — nodes nested inside other frames or auto-layout containers are positioned by their parent. See Gotchas.
figma.currentPage.children - On error, STOP. Do NOT immediately retry. Failed scripts are atomic — if a script errors, it is not executed at all and no changes are made to the file. Read the error message carefully, fix the script, then retry. See Error Recovery.
use_figma - MUST ALL created/mutated node IDs. Whenever a script creates new nodes or mutates existing ones on the canvas, collect every affected node ID and return them in a structured object (e.g.
return). This is essential for subsequent calls to reference, validate, or clean up those nodes.return { createdNodeIds: [...], mutatedNodeIds: [...] } - Always set explicitly when creating variables. The default
variable.scopespollutes every property picker — almost never what you want. Use specific scopes likeALL_SCOPESfor backgrounds,["FRAME_FILL", "SHAPE_FILL"]for text colors,["TEXT_FILL"]for spacing, etc. See variable-patterns.md for the full list.["GAP"] - every Promise. Never leave a Promise unawaited — unawaited async calls (e.g.
awaitwithoutfigma.loadFontAsync(...), orawaitwithoutfigma.setCurrentPageAsync(page)) will fire-and-forget, causing silent failures or race conditions. The script may return before the async operation completes, leading to missing data or half-applied changes.await
For detailed WRONG/CORRECT examples of each rule, see Gotchas & Common Mistakes.
- 使用返回数据。返回值会自动序列化为JSON(对象、数组、字符串、数字)。请勿调用
return或将代码包装在异步立即执行函数(async IIFE)中——这些操作会自动处理。figma.closePlugin() - 编写包含顶级和
await的纯JavaScript代码。代码会自动包装在异步上下文中。请勿将代码包装在return中。(async () => { ... })() - 会抛出"not implemented"错误——绝对不要使用它 3a.
figma.notify()/getPluginData()在setPluginData()中不受支持——请勿使用。请改用use_figma/getSharedPluginData()(这些是受支持的),或者通过返回节点ID并在后续调用中传递来跟踪节点。setSharedPluginData() - 的输出不会返回——请使用
console.log()进行输出return - 逐步增量操作。将大型操作拆分为多个调用。每一步后进行验证。这是避免错误最重要的做法。
use_figma - 颜色值使用0–1范围(而非0–255):表示红色
{r: 1, g: 0, b: 0} - 填充/描边是只读数组——请克隆、修改后重新赋值
- 字体必须在任何文本操作前加载:
await figma.loadFontAsync({family, style}) - 页面增量加载——使用切换页面并加载其内容(见下文页面规则)
await figma.setCurrentPageAsync(page) - 会返回一个新的填充对象——必须捕获并重新赋值
setBoundVariableForPaint - 接受集合对象或ID字符串(优先使用对象)
createVariable - 必须在
layoutSizingHorizontal/Vertical = 'FILL'之后设置——在追加前设置会抛出错误。对于非自动布局节点设置parent.appendChild(child)也是如此。'HUG' - 将新的顶级节点放置在远离(0,0)的位置。直接追加到页面的节点默认位置是(0,0)。请扫描以找到一个空白位置(例如,最右侧节点的右侧)。这仅适用于页面级节点——嵌套在其他框架或自动布局容器中的节点由其父节点定位。详见注意事项。
figma.currentPage.children - 如果调用出错,请停止操作。不要立即重试。失败的脚本是原子性的——如果脚本出错,它根本不会执行,也不会对文件进行任何更改。请仔细阅读错误消息,修复脚本后再重试。详见错误恢复。
use_figma - 必须所有创建/修改的节点ID。每当脚本在画布上创建新节点或修改现有节点时,请收集所有受影响的节点ID并以结构化对象返回(例如
return)。这对于后续调用引用、验证或清理这些节点至关重要。return { createdNodeIds: [...], mutatedNodeIds: [...] } - 创建变量时必须显式设置。默认的
variable.scopes会污染每个属性选择器——几乎从来都不是你想要的结果。请使用特定范围,例如用于背景的ALL_SCOPES、用于文本颜色的["FRAME_FILL", "SHAPE_FILL"]、用于间距的["TEXT_FILL"]等。完整列表请见variable-patterns.md。["GAP"] - 所有Promise都必须。永远不要让Promise处于未等待状态——未等待的异步调用(例如不带
await的await,或不带figma.loadFontAsync(...)的await)会触发即发即弃,导致静默失败或竞态条件。脚本可能在异步操作完成前返回,导致数据缺失或部分应用的更改。figma.setCurrentPageAsync(page)
每个规则的详细错误/正确示例,请见注意事项与常见错误。
2. Page Rules (Critical)
2. 页面规则(关键)
Page context resets between calls — starts on the first page each time.
use_figmafigma.currentPageuse_figmafigma.currentPageSwitching pages
切换页面
Use to switch pages and load their content. The sync setter throws an error in runtimes.
await figma.setCurrentPageAsync(page)figma.currentPage = pageuse_figmajs
// Switch to a specific page (loads its content)
const targetPage = figma.root.children.find((p) => p.name === "My Page");
await figma.setCurrentPageAsync(targetPage);
// targetPage.children is now populated
// Iterate over all pages
for (const page of figma.root.children) {
await figma.setCurrentPageAsync(page);
// page.children is now loaded — read or modify them here
}使用切换页面并加载其内容。同步设置器在运行时会抛出错误。
await figma.setCurrentPageAsync(page)figma.currentPage = pageuse_figmajs
// 切换到指定页面(加载其内容)
const targetPage = figma.root.children.find((p) => p.name === "My Page");
await figma.setCurrentPageAsync(targetPage);
// 现在targetPage.children已加载完成
// 遍历所有页面
for (const page of figma.root.children) {
await figma.setCurrentPageAsync(page);
// page.children已加载——在此处读取或修改它们
}Across script runs
跨脚本调用
figma.currentPageuse_figmaawait figma.setCurrentPageAsync(page)You can call multiple times to incrementally build on the file state, or to retrieve information before writing another script. For example, write a script to get metadata about existing nodes, that data, then use it in a subsequent script to modify those nodes.
use_figmareturn每次调用开始时,都会重置为第一页。如果工作流跨多个调用且目标为非默认页面,请在每次调用开始时调用。
use_figmafigma.currentPageawait figma.setCurrentPageAsync(page)你可以多次调用以逐步构建文件状态,或在编写另一个脚本前检索信息。例如,先编写一个脚本获取现有节点的元数据,该数据,然后在后续脚本中使用它来修改这些节点。
use_figmareturn3. return
Is Your Output Channel
return3. return
是你的输出通道
returnThe agent sees ONLY the value you . Everything else is invisible.
return- Returning IDs (CRITICAL): Every script that creates or mutates canvas nodes MUST return all affected node IDs — e.g. . This is a hard requirement, not optional.
return { createdNodeIds: [...], mutatedNodeIds: [...] } - Progress reporting:
return { createdNodeIds: [...], count: 5, errors: [] } - Error info: Thrown errors are automatically captured and returned — just let them propagate or explicitly.
throw - output is never returned to the agent
console.log() - Always return actionable data (IDs, counts, status) so subsequent calls can reference created objects
Agent只能看到你的值。其他所有内容都是不可见的。
return- 返回ID(至关重要):每个创建或修改画布节点的脚本必须返回所有受影响的节点ID——例如。这是硬性要求,而非可选操作。
return { createdNodeIds: [...], mutatedNodeIds: [...] } - 进度报告:
return { createdNodeIds: [...], count: 5, errors: [] } - 错误信息:抛出的错误会自动捕获并返回——只需让错误传播或显式即可。
throw - 的输出永远不会返回给Agent
console.log() - 始终返回可操作的数据(ID、计数、状态),以便后续调用可以引用创建的对象
4. Editor Mode
4. 编辑器模式
use_figma"figma""figjam"Available in design mode: Rectangle, Frame, Component, Text, Ellipse, Star, Line, Vector, Polygon, BooleanOperation, Slice, Page, Section, TextPath.
Blocked in design mode: Sticky, Connector, ShapeWithText, CodeBlock, Slide, SlideRow, Webpage.
use_figma"figma""figjam"设计模式下可用的节点:Rectangle、Frame、Component、Text、Ellipse、Star、Line、Vector、Polygon、BooleanOperation、Slice、Page、Section、TextPath。
设计模式下被阻止的节点:Sticky、Connector、ShapeWithText、CodeBlock、Slide、SlideRow、Webpage。
5. Incremental Workflow (How to Avoid Bugs)
5. 增量工作流(如何避免错误)
The most common cause of bugs is trying to do too much in a single call. Work in small steps and validate after each one.
use_figma错误最常见的原因是试图在单个调用中完成过多操作。请分小步骤操作,并在每一步后进行验证。
use_figmaThe pattern
模式
- Inspect first. Before creating anything, run a read-only to discover what already exists in the file — pages, components, variables, naming conventions. Match what's there.
use_figma - Do one thing per call. Create variables in one call, create components in the next, compose layouts in another. Don't try to build an entire screen in one script.
- Return IDs from every call. Always created node IDs, variable IDs, collection IDs as objects (e.g.
return). You'll need these as inputs to subsequent calls.return { createdNodeIds: [...] } - Validate after each step. Use to verify structure (counts, names, hierarchy, positions). Use
get_metadataafter major milestones to catch visual issues.get_screenshot - Fix before moving on. If validation reveals a problem, fix it before proceeding to the next step. Don't build on a broken foundation.
- 先检查。在创建任何内容之前,运行一个只读的调用以发现文件中已有的内容——页面、组件、变量、命名约定。与现有内容保持一致。
use_figma - 每次调用完成一件事。在一个调用中创建变量,在下一个调用中创建组件,在另一个调用中组合布局。不要试图在一个脚本中构建整个屏幕。
- 每次调用都返回ID。始终以对象形式返回创建的节点ID、变量ID、集合ID(例如)。后续调用需要这些作为输入。
return { createdNodeIds: [...] } - 每一步后验证。使用验证结构(计数、名称、层级、位置)。在重要里程碑后使用
get_metadata捕获视觉问题。get_screenshot - 修复后再继续。如果验证发现问题,请在进行下一步前修复。不要在有问题的基础上继续构建。
Suggested step order for complex tasks
复杂任务的建议步骤顺序
Step 1: Inspect file — discover existing pages, components, variables, conventions
Step 2: Create tokens/variables (if needed)
→ validate with get_metadata
Step 3: Create individual components
→ validate with get_metadata + get_screenshot
Step 4: Compose layouts from component instances
→ validate with get_screenshot
Step 5: Final verification步骤1:检查文件——发现现有页面、组件、变量、命名约定
步骤2:创建令牌/变量(如果需要)
→ 使用get_metadata验证
步骤3:创建单个组件
→ 使用get_metadata + get_screenshot验证
步骤4:从组件实例组合布局
→ 使用get_screenshot验证
步骤5:最终验证What to validate at each step
每一步的验证内容
| After... | Check with | Check with |
|---|---|---|
| Creating variables | Collection count, variable count, mode names | — |
| Creating components | Child count, variant names, property definitions | Variants visible, not collapsed, grid readable |
| Binding variables | Node properties reflect bindings | Colors/tokens resolved correctly |
| Composing layouts | Instance nodes have mainComponent, hierarchy correct | No cropped/clipped text, no overlapping elements, correct spacing |
| 操作后... | 使用 | 使用 |
|---|---|---|
| 创建变量 | 集合数量、变量数量、模式名称 | — |
| 创建组件 | 子节点数量、变体名称、属性定义 | 变体可见、未折叠、网格可读 |
| 绑定变量 | 节点属性反映绑定关系 | 颜色/令牌解析正确 |
| 组合布局 | 实例节点包含mainComponent、层级正确 | 文本无裁剪、元素无重叠、间距正确 |
6. Error Recovery & Self-Correction
6. 错误恢复与自我修正
use_figma**是原子性的——失败的脚本不会执行。**如果脚本出错,不会对文件进行任何更改。文件会保持调用前的状态。这意味着不会有部分节点、失败脚本留下的孤立元素,修复后重试是安全的。
use_figmaWhen use_figma
returns an error
use_figma当use_figma
返回错误时
use_figma- STOP. Do not immediately fix the code and retry.
- Read the error message carefully. Understand exactly what went wrong — wrong API usage, missing font, invalid property value, etc.
- If the error is unclear, call or
get_metadatato understand the current file state.get_screenshot - Fix the script based on the error message.
- Retry the corrected script.
- 停止操作。不要立即修复代码并重试。
- 仔细阅读错误消息。准确理解出错原因——API使用错误、字体缺失、属性值无效等。
- 如果错误不明确,调用或
get_metadata以了解当前文件状态。get_screenshot - 根据错误消息修复脚本。
- 重试修正后的脚本。
Common self-correction patterns
常见自我修正模式
| Error message | Likely cause | How to fix |
|---|---|---|
| Used | Remove it — use |
| Set | Move |
| Used sync page setter | Use |
| Property value out of range | Color channel > 1 (used 0–255 instead of 0–1) | Divide by 255 |
| Node doesn't exist (wrong ID, wrong page) | Check page context, verify ID |
| Script hangs / no response | Infinite loop or unresolved promise | Check for |
| Parent instance was implicitly detached by a child | Re-discover nodes by traversal from a stable (non-instance) parent frame |
| 错误消息 | 可能原因 | 修复方法 |
|---|---|---|
| 使用了 | 删除它——使用 |
| 在追加到自动布局父节点前设置了 | 将 |
| 使用了同步页面设置器 | 使用 |
| 属性值超出范围 | 颜色通道值>1(使用了0–255而非0–1) | 将值除以255 |
| 节点不存在(错误的ID、错误的页面) | 检查页面上下文,验证ID |
| 脚本挂起/无响应 | 无限循环或未解决的Promise | 检查是否有 |
| 父实例被子节点的 | 从稳定的(非实例)父框架遍历重新发现节点 |
When the script succeeds but the result looks wrong
当脚本成功但结果看起来不正确时
- Call to check structural correctness (hierarchy, counts, positions).
get_metadata - Call to check visual correctness. Look closely for cropped/clipped text (line heights cutting off content) and overlapping elements — these are common and easy to miss.
get_screenshot - Identify the discrepancy — is it structural (wrong hierarchy, missing nodes) or visual (wrong colors, broken layout, clipped content)?
- Write a targeted fix script that modifies only the broken parts — don't recreate everything.
For the full validation workflow, see Validation & Error Recovery.
- 调用检查结构正确性(层级、计数、位置)。
get_metadata - 调用检查视觉正确性。仔细查看是否有文本裁剪(行高截断内容)和元素重叠——这些是常见且容易被忽略的问题。
get_screenshot - 识别差异——是结构问题(错误的层级、缺失节点)还是视觉问题(错误的颜色、布局损坏、内容裁剪)?
- 编写有针对性的修复脚本,仅修改有问题的部分——不要重新创建所有内容。
完整的验证工作流,请见验证与错误恢复。
7. Pre-Flight Checklist
7. 预检查清单
Before submitting ANY call, verify:
use_figma- Code uses to send data back (NOT
return)figma.closePlugin() - Code is NOT wrapped in an async IIFE (auto-wrapped for you)
- value includes structured data with actionable info (IDs, counts)
return - NO usage of anywhere
figma.notify() - NO usage of as output (use
console.log()instead)return - All colors use 0–1 range (not 0–255)
- Fills/strokes are reassigned as new arrays (not mutated in place)
- Page switches use (sync setter throws)
await figma.setCurrentPageAsync(page) - is set AFTER
layoutSizingVertical/Horizontal = 'FILL'parent.appendChild(child) - called BEFORE any text property changes
loadFontAsync() - /
lineHeightuseletterSpacingformat (not bare numbers){unit, value} - is called BEFORE setting sizing modes (resize resets them to FIXED)
resize() - For multi-step workflows: IDs from previous calls are passed as string literals (not variables)
- New top-level nodes are positioned away from (0,0) to avoid overlapping existing content
- ALL created/mutated node IDs are collected and included in the value
return - Every async call (,
loadFontAsync,setCurrentPageAsync, etc.) isimportComponentByKeyAsynced — no fire-and-forget Promisesawait
在提交任何调用之前,请验证:
use_figma- 代码使用返回数据(而非
return)figma.closePlugin() - 代码未包装在异步立即执行函数中(会自动包装)
- 返回值包含带有可操作信息的结构化数据(ID、计数)
- 未在任何地方使用
figma.notify() - 未将用作输出(请改用
console.log())return - 所有颜色使用0–1范围(而非0–255)
- 填充/描边被重新赋值为新数组(而非就地修改)
- 页面切换使用(同步设置器会抛出错误)
await figma.setCurrentPageAsync(page) - 在
layoutSizingVertical/Horizontal = 'FILL'之后设置parent.appendChild(child) - 在任何文本属性更改前调用了
loadFontAsync() - /
lineHeight使用letterSpacing格式(而非裸数字){unit, value} - 在设置大小模式前调用了(resize会将大小模式重置为FIXED)
resize() - 对于多步骤工作流:前一次调用的ID作为字符串字面量传递(而非变量)
- 新的顶级节点被放置在远离(0,0)的位置,以避免与现有内容重叠
- 所有创建/修改的节点ID都被收集并包含在返回值中
- 所有异步调用(、
loadFontAsync、setCurrentPageAsync等)都被importComponentByKeyAsync——没有即发即弃的Promiseawait
8. Discover Conventions Before Creating
8. 创建前先发现约定
Always inspect the Figma file before creating anything. Different files use different naming conventions, variable structures, and component patterns. Your code should match what's already there, not impose new conventions.
When in doubt about any convention (naming, scoping, structure), check the Figma file first, then the user's codebase. Only fall back to common patterns when neither exists.
**在创建任何内容之前,请始终检查Figma文件。**不同的文件使用不同的命名约定、变量结构和组件模式。你的代码应与现有内容保持一致,而非强加新约定。
对任何约定(命名、范围、结构)有疑问时,请先检查Figma文件,再检查用户的代码库。仅当两者都不存在时,才使用常见模式。
Quick inspection scripts
快速检查脚本
List all pages and top-level nodes:
js
const pages = figma.root.children.map(p => `${p.name} id=${p.id} children=${p.children.length}`);
return pages.join('\n');List existing components across all pages:
js
const results = [];
for (const page of figma.root.children) {
await figma.setCurrentPageAsync(page);
page.findAll(n => {
if (n.type === 'COMPONENT' || n.type === 'COMPONENT_SET')
results.push(`[${page.name}] ${n.name} (${n.type}) id=${n.id}`);
return false;
});
}
return results.join('\n');List existing variable collections and their conventions:
js
const collections = await figma.variables.getLocalVariableCollectionsAsync();
const results = collections.map(c => ({
name: c.name, id: c.id,
varCount: c.variableIds.length,
modes: c.modes.map(m => m.name)
}));
return results;列出所有页面和顶级节点:
js
const pages = figma.root.children.map(p => `${p.name} id=${p.id} children=${p.children.length}`);
return pages.join('\n');列出所有页面中的现有组件:
js
const results = [];
for (const page of figma.root.children) {
await figma.setCurrentPageAsync(page);
page.findAll(n => {
if (n.type === 'COMPONENT' || n.type === 'COMPONENT_SET')
results.push(`[${page.name}] ${n.name} (${n.type}) id=${n.id}`);
return false;
});
}
return results.join('\n');列出现有变量集合及其约定:
js
const collections = await figma.variables.getLocalVariableCollectionsAsync();
const results = collections.map(c => ({
name: c.name, id: c.id,
varCount: c.variableIds.length,
modes: c.modes.map(m => m.name)
}));
return results;9. Reference Docs
9. 参考文档
Load these as needed based on what your task involves:
| Doc | When to load | What it covers |
|---|---|---|
| gotchas.md | Before any | Every known pitfall with WRONG/CORRECT code examples |
| common-patterns.md | Need working code examples | Script scaffolds: shapes, text, auto-layout, variables, components, multi-step workflows |
| plugin-api-patterns.md | Creating/editing nodes | Fills, strokes, Auto Layout, effects, grouping, cloning, styles |
| api-reference.md | Need exact API surface | Node creation, variables API, core properties, what works and what doesn't |
| validation-and-recovery.md | Multi-step writes or error recovery | |
| component-patterns.md | Creating components/variants | combineAsVariants, component properties, INSTANCE_SWAP, variant layout, discovering existing components, metadata traversal |
| variable-patterns.md | Creating/binding variables | Collections, modes, scopes, aliasing, binding patterns, discovering existing variables |
| text-style-patterns.md | Creating/applying text styles | Type ramps, font probing, listing styles, applying styles to nodes |
| effect-style-patterns.md | Creating/applying effect styles | Drop shadows, listing styles, applying styles to nodes |
| plugin-api-standalone.index.md | Need to understand the full API surface | Index of all types, methods, and properties in the Plugin API |
| plugin-api-standalone.d.ts | Need exact type signatures | Full typings file — grep for specific symbols, don't load all at once |
根据任务需求按需加载以下文档:
| 文档 | 加载时机 | 涵盖内容 |
|---|---|---|
| gotchas.md | 任何 | 所有已知陷阱及错误/正确代码示例 |
| common-patterns.md | 需要可用代码示例时 | 脚本模板:形状、文本、自动布局、变量、组件、多步骤工作流 |
| plugin-api-patterns.md | 创建/编辑节点时 | 填充、描边、自动布局、效果、分组、克隆、样式 |
| api-reference.md | 需要精确API接口时 | 节点创建、变量API、核心属性、支持与不支持的功能 |
| validation-and-recovery.md | 多步骤写入或错误恢复时 | |
| component-patterns.md | 创建组件/变体时 | combineAsVariants、组件属性、INSTANCE_SWAP、变体布局、发现现有组件、元数据遍历 |
| variable-patterns.md | 创建/绑定变量时 | 集合、模式、范围、别名、绑定模式、发现现有变量 |
| text-style-patterns.md | 创建/应用文本样式时 | 类型阶梯、字体探测、列出样式、将样式应用到节点 |
| effect-style-patterns.md | 创建/应用效果样式时 | 阴影、列出样式、将样式应用到节点 |
| plugin-api-standalone.index.md | 需要了解完整API接口时 | Plugin API中所有类型、方法和属性的索引 |
| plugin-api-standalone.d.ts | 需要精确类型签名时 | 完整类型定义文件——搜索特定符号,不要一次性全部加载 |
10. Snippet examples
10. 代码片段示例
You will see snippets throughout documentation here. These snippets contain useful plugin API code that can be repurposed. Use them as is, or as starter code as you go. If there are key concepts that are best documented as generic snippets, call them out and write to disk so you can reuse in the future.
你会在此文档中看到各种代码片段。这些片段包含可复用的实用Plugin API代码。请直接使用它们,或将其作为起始代码。如果有最佳通过通用片段记录的关键概念,请标注出来并写入磁盘,以便将来复用。