figma-serialization

figma-serialization is a cursor rule for Cursor from hoshikitsunoda/figma-plugins-vibe-coding-template. It costs 0 tokens per session (524 once invoked), scanned A, original, MIT.

Guidance for converting Figma Plugin API values into JSON, a text format used to send or export structured data. It covers readonly arrays, color values, image references, and font names.

In plain words
What is it for?
Use it when sending Figma data with postMessage or exporting it, including converting colors to hexadecimal values and retrieving image bytes from an image hash.
Why use it?
It prevents common data-transfer problems, such as trying to modify readonly values or treating a Figma image reference as image bytes.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/hoshikitsunoda/figma-plugins-vibe-coding-template/figma-serialization
Clone the repo
git clone --depth 1 https://github.com/hoshikitsunoda/figma-plugins-vibe-coding-template

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for figma-serialization

README.md
[![agentmods](https://agentmods.dev/badge/rules/hoshikitsunoda/figma-plugins-vibe-coding-template/figma-serialization.svg)](https://agentmods.dev/rules/hoshikitsunoda/figma-plugins-vibe-coding-template/figma-serialization)
Your own site
<a href="https://agentmods.dev/rules/hoshikitsunoda/figma-plugins-vibe-coding-template/figma-serialization"><img src="https://agentmods.dev/badge/rules/hoshikitsunoda/figma-plugins-vibe-coding-template/figma-serialization.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 524 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00524
Opus 5 $0.00000 $0.00262
Sonnet 5 $0.00000 $0.00105
Haiku 4.5 $0.00000 $0.00052

Measured 5d ago against content hash 7aa710b7a9cf, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

figma-serialization scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/figma-serialization.mdc · 102 lines

What it actually says

Figma Serialization Patterns

Converting Plugin API data to JSON for postMessage or export.

Clone Readonly Arrays

Paint and effect arrays are readonly — clone before modifying or sending:

// ✓ Clone with JSON round-trip
const fills = JSON.parse(JSON.stringify(node.fills))

// ✓ Or use spread for shallow clone
const effects = [...node.effects]

Handle Special Types

Colors

Figma colors use 0-1 range, not 0-255:

interface Color {
  r: number // 0-1
  g: number // 0-1
  b: number // 0-1
}

// Convert to hex if needed
const toHex = (c: Color) =>
  '#' +
  [c.r, c.g, c.b]
    .map((v) => Math.round(v * 255).toString(16).padStart(2, '0'))
    .join('')

Image Paints

Image fills contain imageHash, not actual bytes:

if (fill.type === 'IMAGE') {
  // imageHash is a string reference
  const hash = fill.imageHash

  // To get actual bytes, use:
  const image = figma.getImageByHash(hash)
  const bytes = await image.getBytesAsync()
}

Font Names

if (node.type === 'TEXT') {
  // FontName is { family: string, style: string }
  const font = node.fontName
  // May be mixed — check for figma.mixed symbol
  if (font !== figma.mixed) {
    console.log(font.family, font.style)
  }
}

Skip Non-Serializable Properties

These will break JSON.stringify():

// ❌ Don't include in serialized output
node.parent // Circular reference
node.removed // Runtime state
node.reactions // Contains functions

// ✓ Extract only needed data
function serializeNode(node: SceneNode) {
  return {
    id: node.id,
    name: node.name,
    type: node.type,
    // ... other safe properties
  }
}

Mixed Values

Some properties can be figma.mixed when values vary (e.g., mixed fonts in text):

if (node.fontSize === figma.mixed) {
  // Handle mixed case
} else {
  // Use the value directly
}
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 102 lines · 0 tokens per session scan A 7aa710b7a9cf

Subscribe to this mod's changes

figma-serialization is a cursor rule published in the GitHub repository hoshikitsunoda/figma-plugins-vibe-coding-template (21 stars, last pushed 8mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 524 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.