跳转到内容

Styles

管理本地颜色、文字、效果和网格样式。

Type reference
// Styles are named, reusable design properties that can be applied to nodes. Four types:
// paint: named PaintStyle.paints (applied to fills/strokes), text: typography settings, effect: shadows/blurs, grid: layout grids.
// All ID params accept both IDs and display names (case-insensitive). Use whichever you have.
// ---
// leadingTrim: "CAP_HEIGHT" trims line-height to cap height (tighter text boxes), "NONE" is default.
// fontStyle: font variant name like "Bold", "Italic", "Bold Italic". Use fonts.list to find available styles.
// Paint styles: create/update paints: Paint[] authoring accepts only SOLID and gradients (GRADIENT_LINEAR/RADIAL/ANGULAR/DIAMOND).
// Use gradientTransform + gradientStops; for a basic left-to-right gradient use gradientTransform:[[1,0,0],[0,1,0]]. Do not use CSS gradients, REST gradientHandlePositions, or top-level gradient boundVariables.
// styles.get/list readback may include IMAGE/VIDEO/PATTERN metadata from existing Figma content, but those are readback-only and cannot be passed back to create/update Paint[] authoring. Use imageUrl/images for image authoring on nodes; VIDEO/PATTERN authoring is not supported here.
// For VariableAlias ids in Paint[] (SOLID boundVariables.color or gradientStops[].boundVariables.color), inspect variables.get/list or variable_collections.get. Prefer colorVariableName/fillVariableName where available.
// Backward-compatible color/colorVariableName create/update shorthands still create a single SOLID paint.
//
// Effect object shape (for effect styles):
// { type: "DROP_SHADOW"|"INNER_SHADOW"|"LAYER_BLUR"|"BACKGROUND_BLUR",
// color?: Color, offset?: {x, y}, radius: number, spread?: number,
// visible?: boolean, blendMode?: string }
// DROP_SHADOW/INNER_SHADOW require color, offset, radius. LAYER_BLUR/BACKGROUND_BLUR require radius only.
// Example: { type: "DROP_SHADOW", color: "#00000040", offset: {x:0,y:4}, radius: 8 }
//
// LayoutGrid object shape (for grid styles) follows Figma Plugin API conditional shapes:
// Grid: { pattern:"GRID", sectionSize:number, visible?:boolean, color?:Color }
// Rows/Columns: { pattern:"ROWS"|"COLUMNS", alignment?:"MIN"|"MAX"|"STRETCH"|"CENTER", gutterSize?:number, count?:number, offset?:number, sectionSize?:number, visible?:boolean, color?:Color }
// Important: alignment:"STRETCH" must omit sectionSize because Figma computes stretched row/column sizes. Use sectionSize only with fixed rows/columns (MIN/MAX/CENTER) or GRID.
// Examples: stretch columns {pattern:"COLUMNS", alignment:"STRETCH", count:12, gutterSize:24, offset:80}; fixed columns {pattern:"COLUMNS", alignment:"MIN", count:12, gutterSize:24, offset:80, sectionSize:72}; square grid {pattern:"GRID", sectionSize:8}.
// Shared types:
// Color: hex "#RGB"|"#RGBA"|"#RRGGBB"|"#RRGGBBAA" or {r: 0-1, g: 0-1, b: 0-1, a?: 0-1}
// VariableAlias: {type: "VARIABLE_ALIAS", id: string}. The id must be a Figma VariableID; discover it via variables.get/list or variable_collections.get. Prefer colorVariableName/fillVariableName/strokeVariableName when available; Paint[] VariableAlias is mainly for precise Paint[] round-trips and gradient stop bindings.
// Transform: [[number, number, number], [number, number, number]] (Figma Plugin API 2×3 matrix)
// BlendMode: "PASS_THROUGH"|"NORMAL"|"DARKEN"|"MULTIPLY"|"LINEAR_BURN"|"COLOR_BURN"|"LIGHTEN"|"SCREEN"|"LINEAR_DODGE"|"COLOR_DODGE"|"OVERLAY"|"SOFT_LIGHT"|"HARD_LIGHT"|"DIFFERENCE"|"EXCLUSION"|"HUE"|"SATURATION"|"COLOR"|"LUMINOSITY"
// ColorStop: {position: 0-1, color: Color, boundVariables?: {color?: VariableAlias}}
// GradientPaint: {type: "GRADIENT_LINEAR"|"GRADIENT_RADIAL"|"GRADIENT_ANGULAR"|"GRADIENT_DIAMOND", gradientTransform: Transform, gradientStops: ColorStop[], visible?: boolean, opacity?: number, blendMode?: BlendMode}. Use gradientTransform + gradientStops (basic left-to-right: [[1,0,0],[0,1,0]]); do not use CSS gradients or REST gradientHandlePositions.
// Effect: {type: "DROP_SHADOW"|"INNER_SHADOW"|"LAYER_BLUR"|"BACKGROUND_BLUR", radius: number, color?: {r,g,b,a} (0-1), offset?: {x, y}, spread?: number, visible?: boolean}
// Paint: Paint[] authoring accepts only SOLID and GRADIENT_LINEAR/GRADIENT_RADIAL/GRADIENT_ANGULAR/GRADIENT_DIAMOND. SolidPaint: {type: "SOLID", color: Color, visible?: boolean, opacity?: number, blendMode?: BlendMode, boundVariables?: {color?: VariableAlias}}. GradientPaint authoring: {type: GRADIENT_*, gradientTransform: Transform, gradientStops: ColorStop[], visible?, opacity?, blendMode?}; bind variables on gradientStops[].boundVariables.color, not top-level gradient boundVariables. Do not pass IMAGE/VIDEO/PATTERN to create/update Paint[]; those may appear only in readback metadata from existing Figma content. Use imageUrl/images for image authoring. VIDEO/PATTERN authoring is not supported here. Do not use CSS gradients or REST gradientHandlePositions.
// LayoutGrid is conditional: GridLayoutGrid {pattern:"GRID", sectionSize:number, visible?:boolean, color?:Color}; RowsColsLayoutGrid {pattern:"ROWS"|"COLUMNS", alignment?:"MIN"|"MAX"|"CENTER"|"STRETCH", gutterSize?:number, count?:number, offset?:number, sectionSize?:number, visible?:boolean, color?:Color}. For alignment:"STRETCH", omit sectionSize; Figma computes stretched row/column sizes. Use sectionSize only with fixed rows/columns (MIN/MAX/CENTER) or GRID.

5 methods available.

List local styles with optional type filter

ParameterTypeRequiredDescription
type"paint" | "text" | "effect" | "grid"Filter by style type
fieldsstring[]Property whitelist. Identity fields (id, name, type) always included. Omit for stubs on list, full on get. Pass ["*"] for all.
offsetnumberSkip N items for pagination (default 0) (default: 0)
limitnumberMax items per page (default 100) (default: 100)

Response

FieldTypeDescription
totalCountnumberTotal matching items
returnednumberItems in this page
offsetnumber
limitnumber
itemsobject[]
idstring
namestring
typestring

Get full style detail by ID

ParameterTypeRequiredDescription
idstringStyle ID or name
fieldsstring[]Property whitelist. Identity fields (id, name, type) always included. Omit for stubs on list, full on get. Pass ["*"] for all.

Response

FieldTypeDescription
idstring
namestring
typestringPAINT | TEXT | EFFECT | GRID
paintsobject[]PaintStyle.paints for PAINT styles. Readback returns Figma Plugin API Paint[]; gradients include gradientTransform, gradientStops, opacity/blendMode, and stop boundVariables. Existing Figma content may return IMAGE/VIDEO/PATTERN metadata, but those are readback-only and cannot be passed to create/update Paint[] authoring, which accepts only SOLID and gradients.
boundVariablesobjectPaintStyle.boundVariables, e.g. {paints:[{type:'VARIABLE_ALIAS', id:'...'}]}
fontFamilystringFont family (TEXT styles)
fontSizenumberFont size (TEXT styles)
effectsarrayEffects array (EFFECT styles)
layoutGridsarrayLayout grids (GRID styles)

Create local styles

Example

styles(method:"create", type:"paint", items:[{name:"Gradient/Primary", paints:[{type:"GRADIENT_LINEAR", gradientTransform:[[1,0,0],[0,1,0]], gradientStops:[{position:0,color:"#7D58ED"},{position:1,color:"#207CE5"}]}]}])

Type-specific fields go inside items[]; do not pass them at the top level.

ParameterTypeRequiredDescription
type"paint" | "text" | "effect" | "grid"Selects which item shape to use
itemsobject[]One or more type-specific item objects. Put fields from the selected type table inside each item; do not pass them at top level.

Discriminated by type. Available types:

Each table below describes one object inside items[] for that type.

Paint/color style

styles(method:"create", type:"paint", items:[{name:"Surface/Primary", colorVariableName:"bg/surface"}])
ParameterTypeRequiredDescription
namestringStyle name
paintsobject[]PaintStyle.paints authoring array. Accepts only SOLID and GRADIENT_LINEAR/RADIAL/ANGULAR/DIAMOND, using gradientTransform + gradientStops, opacity/blendMode, and gradientStops[].boundVariables.color. Mutually exclusive with color/colorVariableName shorthands. Do not pass IMAGE/VIDEO/PATTERN, CSS gradients, REST gradientHandlePositions, or top-level gradient boundVariables. Use imageUrl/images for image authoring on nodes; VIDEO/PATTERN authoring is not supported here. For examples call styles(method:"help", topic:"create").
colorstringSingle-solid shorthand color. Optional when colorVariableName or paints is provided.
colorVariableNamestringSingle-solid shorthand: bind to a COLOR variable by name (style tracks the variable). Can be used alone — color is resolved from the variable.
descriptionstringStyle description

Text style

styles(method:"create", type:"text", items:[{name:"Heading/Medium", fontFamily:"Inter", fontStyle:"Medium", fontSize:20, lineHeight:{value:28, unit:"PIXELS"}}, {name:"Body/Regular", fontFamily:"Inter", fontSize:14, lineHeight:{value:20, unit:"PIXELS"}}, {name:"Body/Medium", fontFamily:"Inter", fontStyle:"Medium", fontSize:14, lineHeight:{value:20, unit:"PIXELS"}}])
ParameterTypeRequiredDescription
namestringStyle name
fontFamilystringFont family
fontStylestringFont style (default: Regular)
fontSizenumberFont size
lineHeightanynumber | {value, unit: "PIXELS"|"PERCENT"|"AUTO"}
letterSpacinganynumber | {value, unit: "PIXELS"|"PERCENT"}
textCase"ORIGINAL" | "UPPER" | "LOWER" | "TITLE" | "SMALL_CAPS" | "SMALL_CAPS_FORCED"
textDecoration"NONE" | "UNDERLINE" | "STRIKETHROUGH"
paragraphIndentnumberParagraph indent (px)
paragraphSpacingnumberParagraph spacing (px)
leadingTrim"CAP_HEIGHT" | "NONE"Leading trim mode
descriptionstringStyle description

Effect style

styles(method:"create", type:"effect", items:[{name:"Shadow/Medium", effects:[{type:"DROP_SHADOW", color:"#00000040", offset:{x:0,y:4}, radius:8}]}])
ParameterTypeRequiredDescription
namestringStyle name
effectsarrayArray of Effect objects
descriptionstringStyle description

Grid/layout grid style

styles(method:"create", type:"grid", items:[{name:"Grid/Desktop 12", layoutGrids:[{pattern:"COLUMNS", alignment:"STRETCH", count:12, gutterSize:24, offset:80}]}])
ParameterTypeRequiredDescription
namestringStyle name
layoutGridsarrayArray of LayoutGrid objects. Conditional shapes: GRID requires sectionSize and does not use alignment/count/gutterSize/offset; ROWS/COLUMNS use alignment/count/gutterSize/offset, and sectionSize only for fixed alignments MIN/MAX/CENTER. For alignment:STRETCH, omit sectionSize.
descriptionstringStyle description

Response

FieldTypeDescription
resultsobject[]One entry per input item
idstring

Update styles by ID or name

Example

styles(method:"update", items:[{id:"Gradient/Primary", paints:[{type:"GRADIENT_LINEAR", gradientTransform:[[1,0,0],[0,1,0]], gradientStops:[{position:0,color:"#7D58ED"},{position:1,color:"#207CE5"}]}]}])
ParameterTypeRequiredDescription
type"paint" | "text" | "effect" | "grid"Style type hint for strict validation (optional, auto-detected)
itemsobject[]Array of {id, ...fields} to update
idstringStyle ID or name
namestringRename the style
descriptionstringStyle description
paintsobject[]Replace PaintStyle.paints. Accepts only SOLID and GRADIENT_LINEAR/RADIAL/ANGULAR/DIAMOND, using gradientTransform + gradientStops, opacity/blendMode, and gradientStops[].boundVariables.color. Mutually exclusive with color/colorVariableName. Do not pass IMAGE/VIDEO/PATTERN, CSS gradients, REST gradientHandlePositions, or top-level gradient boundVariables. Use imageUrl/images for image authoring on nodes; VIDEO/PATTERN authoring is not supported here. For examples call styles(method:"help", topic:"update").
colorstringNew single-solid color shorthand (paint styles)
colorVariableNamestringBind to a COLOR variable by name using single-solid shorthand (paint styles)
fontFamilystring
fontStylestring
fontSizenumber
lineHeightanynumber | {value, unit: "PIXELS"|"PERCENT"|"AUTO"}
letterSpacinganynumber | {value, unit: "PIXELS"|"PERCENT"}
textCase"ORIGINAL" | "UPPER" | "LOWER" | "TITLE" | "SMALL_CAPS" | "SMALL_CAPS_FORCED"
textDecoration"NONE" | "UNDERLINE" | "STRIKETHROUGH"
paragraphIndentnumberParagraph indent (px)
paragraphSpacingnumberParagraph spacing (px)
leadingTrim"CAP_HEIGHT" | "NONE"
effectsarrayArray of Effect objects
layoutGridsarrayArray of LayoutGrid objects (grid styles). Conditional shapes: GRID requires sectionSize and does not use alignment/count/gutterSize/offset; ROWS/COLUMNS use alignment/count/gutterSize/offset, and sectionSize only for fixed alignments MIN/MAX/CENTER. For alignment:STRETCH, omit sectionSize.

Response

FieldTypeDescription
resultsany[]Array of "ok" or {error} per item

Delete styles

ParameterTypeRequiredDescription
idstringStyle ID or name
itemsobject[]Batch: [{id}, ...]
idstringStyle ID or name

Response

FieldTypeDescription
resultsstring[]Array of "ok" per item