> ## Documentation Index
> Fetch the complete documentation index at: https://docs.buildwithtrace.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Clipboard & Download (Symbols)

> The two .kicad_sym clipboard formats (canvas vs library), the clipboard builders, and the raw library download endpoint.

Symbols can be **copied** to the clipboard in two S-expression formats, or the whole library
can be **downloaded** as its raw `.kicad_sym` file. Clipboard building lives in
`src/lib/clipboard.ts` and runs entirely client-side from the symbol's pin data.

## Two clipboard formats

<CardGroup cols={2}>
  <Card title="Canvas" icon="object-group">
    `buildCanvasClipboardSexp(symbol)` → two-part block: `(lib_symbols …)` **+** a `(symbol …)`
    instance block (UUID, position, instances). Paste directly onto a KiCad/Trace schematic
    canvas. This is the default "Copy" action.
  </Card>

  <Card title="Library" icon="book">
    `buildKicadSymSexp(symbol)` → a standard `(kicad_symbol_lib …)` wrapper with one symbol.
    Paste into a `.kicad_sym` file or a library editor.
  </Card>
</CardGroup>

```ts theme={null}
import {
  buildCanvasClipboardSexp, buildKicadSymSexp,
  copySymbolForCanvas, copySymbolForLibrary,
} from "@/lib/clipboard";

await copySymbolForCanvas(symbol);    // writes canvas S-expr to navigator.clipboard
await copySymbolForLibrary(symbol);   // writes library S-expr
```

Both builders partition pins — **left:** `input`, `power_in`, `passive`; **right:**
everything else (50/50 split if untyped) — and size the body at `max(maxSide·2.54 + 2.54,
7.62) mm` on a 2.54 mm grid. Generator tag: `trace_symbols`.

<Warning>
  The canvas format **must** be two-part. A bare `(kicad_symbol_lib …)` block will not paste
  into the editor — it needs the `(lib_symbols …)` + `(symbol …)` instance block.
</Warning>

## Download the raw library — `GET /api/download/[library]`

Serves the **raw original** `.kicad_sym` from `data/` (or `data/cern-symbols/`), preserving
graphics, multi-unit symbols, and all properties. Falls back to the compiled per-library
JSON if no raw file exists.

```
GET /api/download/Amplifier_Operational
→ 200  Content-Type: application/x-kicad-sym
       Content-Disposition: attachment; filename="Amplifier_Operational.kicad_sym"
       Cache-Control: public, max-age=86400
```

<Info>
  Download serves the **full-fidelity** upstream file; the clipboard reconstructs from parsed
  pin data (quick, editable, but graphics-free). Use download when fidelity matters.
</Info>
