# Get the code out of a drawing

Draw's board is vector, so its code is a *reading* of the artwork — not a
screenshot of it, and not a second drawing made by hand. This page is the
whole handoff: the three presses that emit code, the record that travels with
a file, what a decline line means, and the one command that installs what you
exported.

Here is the boundary the app itself states before it reads anything, quoted
from the sentence it renders:

<!-- ⚠ 2026-11-05 — regenerated by hand: TE-24 added the seventh exit door
     (`plotter`, the cut profile) and it has no content reader, so
     `EXIT_DOOR_BOUNDARY` moved 6/3 → 7/4. The sentence is DERIVED (it counts
     `Object.keys` over draw-exit-boundary.ts's own tables), so the quote below
     must equal it byte-for-byte — draw-handoff-doc.test.ts reds otherwise.
     ⚠ 2026-11-20 — regenerated again: T581 added the Lottie `.json` arm (8/5)
     and then the `.excalidraw` scene (9/5 — it HAS a reader, so only the first
     number moved). Still derived; still quoted once.
     ⚠ 2026-11-21 — regenerated again: T581 batch 4 added six doors (two PPTX
     presses, the dotLottie container, the registry item, the DTCG tokens and
     the animation code files) — none readable here, so both numbers moved
     (11/7 → 17/13). Still derived; still quoted once.
     ⚠ 2026-11-21 (batch 5) — regenerated once more: the MP4/WebM video
     container joined as the eighteenth door and nothing here decodes a video
     back into elements, so both numbers moved (17/13 → 18/14). Still derived;
     still quoted once, and draw-handoff-doc.test.ts reds if this quote and the
     constant ever disagree.
     ⚠ 2026-11-21 (T595) — regenerated once more, and only a CLAUSE joined: the
     sentence now also states which exports can prove their board revision
     (3 / 1 / 14, from the per-door declaration table). The reader numbers did
     not move. Still derived; still quoted once. -->

> Reads 18 door types; 14 have no content reader. 3 can prove their board revision, 1 only on some presses, 14 cannot. Exits outside this set are not covered.

Eighteen kinds of exit exist. Fourteen of them — CSS, raster images,
animation, the plotter/cut profile, the Lottie animation, the two PDF rungs,
the two PPTX presses, the dotLottie container, the registry item, the DTCG
token document, the animation code files and the MP4/WebM video container —
can be written but not read back into elements, so nothing here claims to have
looked inside one. The four that answer for themselves are the two SVGs
(re-imported by this app's own reader), the JSX / Tailwind component (re-parsed
by the import door) and the `.excalidraw` scene (re-opened, and read per
feature). An exit outside that set is not covered by any reading, and no
reading here is a certificate: it reports what it can see.

The sentence states a second, different limit: whether the file can prove
**which board revision** it came from. A file can prove that only when an
artifact record (`.record.json`) is written beside it — the record carries the
board's revision digest, its element count and its membership. **Three exports
collect and write a record on every press:** PNG / JPEG / WebP, the GIF
animation (the APNG press collects one too) and the plotter/cut profile. **One
collects one only on some presses:** the editable SVG writes its record for a
cropped export and not for a whole-board one. **The other fourteen write no
record**, so their files cannot prove a revision: the plain SVG download, the
CSS / Tailwind handoff, the JSX / Tailwind structure, the Lottie animation, the
`.excalidraw` scene, both PDF rungs, both PPTX presses, the dotLottie
container, the shadcn registry item, the DTCG token document, the animation
code files and the MP4 / WebM container — the film press does collect a record
for a video, but the sidecar rule never writes it (an AI film's video is
marked, and that press asks for nothing), so no video file carries one. Open
**Verify this export** and the card answers for the door you picked before you
press, and lists the exports that cannot, by name.

## 1. Export → the Code tab

The top bar's **Export** opens the file menu; **Export…** opens the dialog
titled **Export options**. It has two tabs:

- **Raster** — PNG, JPEG (matte), PNG (transparent), WebP, with scale and an
  area arm.
- **Code** — the selection as code. It is the same read the inspector mounts,
  rendered by the same component, so the dialog and the inspector can never
  show two different readings of one selection.

The Code body is its own scroller and the footer becomes a single **Done** —
the copy arms live inside the read, so there is no disabled Export button
beside them. The tab is not remembered: reopening the dialog puts you back on
**Raster**, because a remembered tab would reopen on a body you did not ask
for.

## 2. Copy JSX / Copy CSS / Copy Tailwind

Inside the Code tab, the read arrives in up to three sections:

- **Spec + code** — usage code for the one thing you selected, with **Copy
  code**.
- **Handoff** — the selection as **CSS** and as **Tailwind**, with **Copy
  CSS** and **Copy Tailwind**, plus **Verify**, which re-reads the handoff:
  what emitted, what the dialect declined, which tokens resolved.
- **Structure** — the selection as a component, with **Copy JSX**. Layout
  intent becomes classes (a flow container emits `flex`, its children carry no
  offsets), tokens become `var(--pc-<role>)` declared once on the root, and
  text stays text. Components in the selection are defined in the same file,
  so each use is a tag, not an inlined copy.

The emission is token-aware in both directions: a bound field emits
`var(--pc-<role>)` with the scope block declaring the values, a literal stays
literal, and a kit role the emitter cannot resolve is named rather than
guessed. A copy arm exists only when there is code — a permanently dead
button teaches that the feature is broken.

## 3. The record pair: `.record.json` and `.record.md`

Under **Artifact record**, the **Save record** toggle decides whether the
export writes its record beside the file. The name is the file's own stem with
the last extension replaced: exporting `hero.png` writes `hero.record.json`
next to it. One exception is worth knowing — when an AI-marked board's bytes
cannot carry the mark, the record is written without asking, because a file
that cannot speak should not travel alone.

The record is a testimony, not a certificate: what the file carries (read off
the bytes), generation provenance with model ids and seeds where they exist,
the acceptance counts, the obstacles, and — as its final line — the boundary
sentence quoted above. It reports; it does not score, sign, or send anything.

**Check the record** opens the card where you can pick a `.record.json` you
already downloaded and cross-examine it against the file, claim by claim.
There the record's readable sibling lives: **Download .record.md** (or **Copy
readable record**) writes the same record as Markdown, for the places that
render text — a PR description, an issue, a chat message. Both come from the
same projection of the same record, so the Markdown cannot describe a
different record than the JSON or than the rows on screen.

## Reading a decline

A decline is one loss the emission named, for one element. It is never a count
in a header standing in for the detail, and it is never swallowed. What you
will see:

- In the read, per declined element: `Declined by the dialect: <kind>
  (<reason>)` — the kind of thing and the dialect's own reason. A classifier
  decline reads `Declined by the classifier: <reason> ×<count>`.
- In the JSX artifact's header, a line like `// Not carried in this dialect:
  <kind> ×2 (<reason>). Each ×N is that kind's element count.` — the count is
  *elements*, not rows, so one element with two losses counts once.
- The CSS read has a third channel, and it is a different fact: `This CSS is a
  flattened snapshot: … — none of that is in the code.` A container's layout
  rules, an element's participation in its parent's layout, and breakpoint
  patches do not survive flattening; the line names what did not.

A **defect** is not a decline. `Could not be read — a board defect, not a
dialect limit: <id> (<field>: <reason>)` means the element itself is broken,
and the remedy is to fix the board, not to try another door.

## Project files in git

A `.polydraw` is a zip, so git treats it as binary and a review shows
`Binary files a/board.polydraw and b/board.polydraw differ`. This repository
already declares the diff driver in `.gitattributes`:

```
*.polydraw diff=polydraw
```

**That declaration alone changes nothing.** Git attributes the file to a driver
that has no `textconv` configured, and the output is byte-identical to before.
The second half is the one that gets forgotten — run it once per clone:

```bash
git config diff.polydraw.textconv "node scripts/draw-diff.mjs"
```

Add `--global` if you want it in every repository, but the command names a path
inside **this** repository, so a repo that does not vendor `scripts/draw-diff.mjs`
needs its own copy. Setting it globally without that file makes `git diff` fail
to resolve the driver — worse than the binary line it replaces.

Then a revision reads as rows, not bytes. The textconv half prints one
`path = value` line per key, sorted, so git diffs two of those renderings:

```
 elements.el_7f2a.h = 90
 elements.el_7f2a.kind = "rect"
-elements.el_7f2a.w = 160
+elements.el_7f2a.w = 180
 elements.el_91bc.kind = "text"
-elements.el_91bc.text = "Old caption"
+elements.el_91bc.text = "New caption"
```

The second argument form answers a different question — what changed between
**two files**, not between two revisions of a tracked one:

```bash
npm run draw:diff -- before.polydraw after.polydraw
```

That form answers in review vocabulary instead of key-path diff lines — `+ added`,
`- removed`, and `~ <path>  <before> -> <after>` per changed row:

```
~ elements.el_7f2a.w  160 -> 180
~ elements.el_91bc.text  "Old caption" -> "New caption"
~ title  "Checkout map" -> "Checkout map (v2)"
```

It exits 0 when nothing changed, 1 when something did, and **2 when either
archive could not be read**. Exit 2 is not "unchanged": a file this build cannot
parse is a file it cannot compare, and the difference matters when the command
guards a check.

**What it will not tell you.** A revision that only reorders rows or rewrites a
zip entry prints an empty diff — the rendering is canonical and sorted, so a
change no reviewer could see is a change it does not report. It also never
claims a record is verified: the diff shows the rows, and the receipt beside the
export is what states who made the pixels.

## The install command

Draw can also emit a **shadcn registry item** — a JSON file meant to be
committed and reviewed like any other source. On a master's row in Inspector →
Components, open the **Package** door and press **Download item JSON**. That
one press writes **two** files:

```
draw-badge.json
draw-badge.receipt.json
```

Save both in the repo — `.polychat/` is the suggested home, which keeps
emitted items together and out of the component tree until they are installed.
Then, from the repository root:

```bash
npx shadcn add ./.polychat/draw-badge.json
```

`draw-badge` is the item's own `name`, here from a master called **Badge**.
The file the press writes and the path in that command are the same name,
always — save it somewhere else and the path changes, not the name.

That is the whole install. It will **not** add a registry entry to
`components.json`, make a network call (the CLI reads the local file, so the
install works air-gapped), require a credential, or update itself. The
component is your source now: re-installing a newer emission overwrites your
edits, so commit first.

The receipt beside the item is the same record in a different shape —
`draw.receipt/1`, naming what the item carries, what the emitter declined, the
boundary sentence above under `not_covered`, and one question: which file you
opened first. A human answers it or nobody does.

## See also

- [Draw & design systems](/docs/studio-draw-design) — the canvas and the
  design workspace the export reads from.
