# Grounding: reading `get_design_context` + per-node fidelity Loaded by **figma-codegen step 1**. `get_design_context` (detail `full`, `dedupeComponents: true`) is the layout + binding source of truth — tokens resolved to names, styles deduped into `globalVars`, each instance's `mainComponent` / `componentProperties`. Trust it over the screenshot; never hand-resolve variable ids or read raw hex. This file is the detail: how to read the tree, the per-property fidelity catalog, and how to ground a page too big for one call. ## Reading the tree - **`componentSetError` on an instance means its variant is unknown, not that it has none.** Figma withholds `componentProperties` while the instance's component set has errors (two variants with the same values, or variants whose properties differ). Build it from its `mainComponent` and the screenshot, and tell the user that set needs fixing in Figma — never emit it as a prop-less default. - **`colorProfile: "DISPLAY_P3"` means every colour in the payload is a P3 colour.** It is the first key of a result from a Display P3 file, and absent otherwise. There, a hex (and any r/g/b) is P3 channels: `#CC6633` is what CSS writes as `color(display-p3 0.8 0.4 0.2)`, and emitted as the plain hex it renders visibly duller — measured against Figma's own render, the plain hex was up to 102/255 off on a saturated green and 20/255 on an orange, `color(display-p3 …)` within 1/255. So emit a raw colour as `color(display-p3 r g b)` with each channel the hex pair ÷ 255, rounded to 3 decimals (`/ a` for the alpha of an 8-digit hex, e.g. `color(display-p3 0 0 0 / 0.25)`; Tailwind `bg-[color(display-p3_0.8_0.4_0.2)]`) — fills, strokes, gradient stops and shadows alike. A token still wins: when the colour is a bound variable, or `projectTokens` / `token_map` match it to a project token, emit the token (the designer most likely meant the brand colour, and the file just happens to be P3) and say in your report that the design renders more saturated than that token does. Without `colorProfile`, a hex is the plain sRGB hex it reads as. - **Keep `dedupeComponents: true`, and do not depth-limit a tree you intend to build from.** Dedupe shows the **first** instance of each repeated component in full and collapses the rest to a `"deduped": true` stub — a 100-instance screen stays readable while every distinct component keeps one complete copy. A `deduped` (or `truncated`) sibling means "identical to the first one, reuse that structure"; a depth cap, by contrast, throws the structure away — the trap that makes repeated rows/cards look empty. - **Same structure, different content: read each deduped instance's `textOverrides`.** A `deduped` stub carries its own `textOverrides` (`{ name, characters }` for every visible TEXT it renders) — fill each repeated element's text from that, so cards/rows/form-fields get their distinct titles / labels / values without re-expanding the un-deduped tree or drilling per instance. - **…and its `propertyOverrides` for what it looks like differently.** The same stub lists each layer whose fill, stroke, effect, radius, corner smoothing, opacity, blend or visibility differs from the main component (`{ name, fills: […] }`, `{ name, visible: false }`) — apply those per instance (a prop, a class), or every card renders like the first. An entry's `variableModes` (`{ name, variableModes: { color: "Dark" } }`) is a layer switched to another mode inside that instance: its token names are the first instance's, its colours are that mode's (`{}` means it went back to inheriting). - **A variable's `codeSyntax` is the declared code name — prefer it over deriving one.** An entry in the top-level `variables` map may carry `codeSyntax` (`{ WEB: '--color-primary', … }`): the designer's own declaration of the code-side token, stronger than any name you'd derive from the Figma name (`Primary/500` → `primary-500`). Use the platform key matching the stack (WEB for css/Tailwind). It's a naming declaration, not a guarantee the token exists — when it matches a token in the project (theme file / `token_map`), use it verbatim; when it matches nothing (a stale declaration after a rename), trust the project's actual token found by value/name instead. - **`variableModes` says which theme a subtree is drawn in.** A node may carry `variableModes` (`{ color: "Dark" }`): every variable bound below it resolves in that mode, so its hex values are that mode's — but its **token names are the same as in the default mode**. A root carries every non-default mode in effect, even one set on a frame or page outside your read; deeper nodes carry only a mode set on them. So a frame with `{ color: "Dark" }` is the **dark variant**, not a dark design: keep the token references, and render the subtree inside the project's mechanism for that mode (`.dark` / `[data-theme="dark"]` / a `dark:` story — whatever `token_map`'s `figmaModes` pointed you to). Don't hardcode its hex (that freezes one theme), and don't emit it with plain token refs either (they would render the default theme). Two frames that differ only in `variableModes` are one component in two themes — implement it once; the second frame is a verification target. ## Per-node visual fidelity Each node exposes more than layout — translate **every** property to the stack's equivalent, not just the obvious ones. These are ordered by how easily they're silently dropped. - **Effects (`effects` / `styleIds.effect`).** Drop/inner shadow or blur. **The easiest fidelity to lose**: they come from a _shared effect style_, so they read as one field and quietly vanish. A card with a shadow in Figma but flat output is the classic miss (e.g. `DROP_SHADOW 0/4/8 #0000000D` → `shadow-[0_4px_7px_rgba(0,0,0,0.05)]`). **A Figma radius is not a CSS length — scale it** (measured against Figma's own renders): a shadow's blur is `radius × 0.85` in `box-shadow` (offsets and spread as they are), and every blur is `radius × 0.43` in `filter: blur()` / `backdrop-filter: blur()` — copying the radius makes a blur about twice too strong (at radius 8, 33/255 off against under 1). Figma is one Gaussian of σ = radius × 0.43 for blurs and shadows alike, fitted off blurred edges at 1x and 2x — and Figma's own Dev Mode CSS is off too (it halves a blur radius and copies a shadow's), so don't copy its numbers. A blur's `type` decides the CSS: `LAYER_BLUR` blurs the element itself (`filter: blur`), but `BACKGROUND_BLUR` blurs what shows through from behind (`backdrop-filter: blur` — the frosted-glass / glassmorphism pattern, typically paired with a semi-transparent fill); emitting it as `filter`, or dropping it, loses the glass look entirely. A `BACKGROUND_BLUR` marked **`drawn: false`** paints nothing in Figma: its node has no visible fill with any opacity, and Figma blurs only behind one (a fill at 1% already blurs the whole shape). A CSS `backdrop-filter` would still blur there, so emit none. - **`blurType: "PROGRESSIVE"`** ramps the blur from `startRadius` at `startOffset` to `radius` at `endOffset` (fractions of the node) — a header that blurs out toward one edge. A uniform blur is the wrong look (16–35/255 off). Emit `cssLayers` as given, bottom first, each its own `position: absolute; inset: 0; pointer-events: none` box: for `BACKGROUND_BLUR` overlays over the node's background, for `LAYER_BLUR` the first styles the content and every later one is an `aria-hidden` copy of that content stacked over it. Rendered against Figma: 0.9–2.9/255. An effect style carries no `cssLayers` (no node to size it on), only the ramp. - **`showShadowBehindNode: true`** (drop shadows only): the shadow also shows through the node's translucent areas. `box-shadow` draws only outside the box — exactly Figma's `false` — so draw this one as a box underneath the node instead: the shadow colour, moved by the offset, grown by the spread on every side, `filter: blur(radius × 0.43)`. A shadow `blendMode` has no `box-shadow` equivalent; keep the plain shadow unless the blend is the point. - **`GLASS`**: Frost is `radius`; Light (`lightIntensity` / `lightAngle`), `refraction`, `depth`, `dispersion` and `splay` bend and tint its edges. Render it as `backdrop-filter: blur(radius × 0.43)` with the node's fill — measured, that matches Figma's centre (1/255) but not its edges (13/255), where the refraction lives, and plain CSS cannot bend what shows through, so say so. Applying glass in Figma also drops the fill's opacity to 20%; the fill already reads that way. - **`TEXTURE`** roughens the edges of everything it covers (`noiseSizeVector` is the grain, `radius` how far it pushes, `clipToShape` keeps it inside the shape — clipped on a plain solid it shows no change). There is no CSS for it: export the composited render where the rough edge matters, and say what was dropped otherwise. - **Text / typography.** A TEXT node carries more than `characters` + font — and the rest reads as one quiet field each, so it vanishes and the model re-guesses it off the raster. The shared style attributes fold into the `textStyle` bundle in `globalVars`: `textCase` (`UPPER`/`LOWER`/`TITLE` → `uppercase`/`lowercase`/`capitalize` — **the characters in the tree are the original casing, so a dropped `UPPER` ships a lowercase button**), `textDecoration` (`UNDERLINE`/`STRIKETHROUGH` → `underline`/`line-through` — a link with no underline is the classic miss), `lineHeight` (`{unit,value}` → `leading-*`; absent = font default), `letterSpacing` (`{unit,value}` → `tracking-*`; absent = 0), `paragraphSpacing` (px between the paragraphs `characters` splits into at `\n` → margin between the `

`s you emit; absent = 0, the paragraphs butt together), `paragraphIndent` (px first-line indent → `text-indent`), `fontVariationSettings` — a variable font's axis values (`{ wght: 650, slnt: -4 }`), keyed by OpenType tag exactly like CSS `font-variation-settings`, so `wght` is the real weight and the named `fontStyle` beside it may still read `Regular`; **two bundles differing only here are two different weights, and taking the weight from `fontStyle` ships both at 400** — and `textWrapStyle` — Figma's values are CSS `text-wrap`'s verbatim, so `BALANCE` → `text-wrap: balance` (even line lengths; a designer sets it on headings and pull quotes) and `PRETTY` → `text-wrap: pretty` (no orphan last word); absent = `auto`, the browser default. Per-node (inline, not in the bundle): `textAlignHorizontal`/`Vertical` (`CENTER`/`RIGHT`/`JUSTIFIED` → `text-center`/`text-right`/ `text-justify`; absent = left/top), `textTruncation: 'ENDING'` + `maxLines` (→ `line-clamp-N` / `truncate`), and `textAutoResize` — how the text box sizes, the signal for whether its width/height are real constraints: absent = hug (the box is just the text's own rendered size — don't emit a width), `HEIGHT` = fixed width + auto height (the width is a wrap constraint — emit it), `NONE` = fixed box (emit both, mind clipping); inside auto-layout trust `layoutSizingHorizontal/Vertical` instead. Each is omitted when it's the no-op default, so anything present is real intent — translate it, don't drop it. - **Truncated at a height, not a line count.** `textTruncation: 'ENDING'` with no `maxLines` clamps at a height — a fixed box's own (`textAutoResize: 'TRUNCATE'`: its `height`), or an auto-height text's `maxHeight`. Figma shows each whole line whose box, rounded down to whole pixels, ends at most 1px past that height, and puts the ellipsis on the last one. So N = the largest k with ⌊k × lineHeight⌋ ≤ height + 1 (measured: Inter / Roboto / Georgia, 12–24px, 6,116 heights, whole and fractional, fixed boxes and `maxHeight`, no miss), where lineHeight is the line box — px as given, a percentage rounded to whole px, absent (`AUTO`) the font's own (about 1.2 × fontSize; 1.13–1.25 measured, so a height right at a boundary can come out one line off). Emit `line-clamp-N` — never `truncate`, which puts the text on one line — with the fixed box's height, or the `maxHeight` (while clamped, Figma's box stays that tall where the CSS one ends at N lines). - **`textWrapStyle` is per paragraph, not per node.** When a node's paragraphs disagree the node-level field is absent and the real values ride in `segments` (a run carries it only when it is not `auto`) — so a `segments` array whose runs differ only in `textWrapStyle` is one text block with per-paragraph wrapping, not inline rich text. - **Mixed (inline) styling → read `segments`.** When a value reads `"mixed"` (e.g. `fontSize` or `textDecoration`), the node carries `segments` — each a run of uniform styling with its own `characters`, `fontName` (with `variationSettings` when the family is variable), `fontSize`, `fills` (hex), `textDecoration`, `textCase` over offsets `start`/`end` (plus per-run `lineHeight`/`letterSpacing` when they differ). These describe runs **within** the node's `characters` (not extra text) — emit each as its own span: the underlined/coloured `Privacy Policy` inside a sentence, the bold word in a label, the smaller `/mo` after a price. Dropping them flattens the whole string to one style (a link with no underline, a price with no emphasis) — the classic mixed-text miss. - **Inline links & lists → `segments` carry structure, not just style.** A run may carry `hyperlink` (`{ type: 'URL' | 'NODE', value }`) → emit an `` (or router link for a `NODE` target); a partial link is the reason a whole node reads mixed. A run may carry `listOptions` (`ORDERED` / `UNORDERED`) with an `indentation` depth → emit real `

    `/`