> ## 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 (Footprints)

> Reconstructing a .kicad_mod for the clipboard and downloading the raw upstream footprint file.

Footprints can be **copied** as a reconstructed `.kicad_mod`, or the **raw upstream file**
can be downloaded for full fidelity. The clipboard builder is in `src/lib/clipboard.ts`.

## Clipboard reconstruction — `buildFootprintKicadMod`

```ts theme={null}
import { buildFootprintKicadMod, copyFootprintForClipboard } from "@/lib/clipboard";

const sexp = buildFootprintKicadMod({ name, library, pads });   // minimal valid .kicad_mod
await copyFootprintForClipboard({ name, library, pads });        // writes to clipboard
```

It lays the pads out in a square grid (`cols = ceil(sqrt(padCount))`, 1.27 mm spacing,
centered on origin), detects `smd` vs `thru_hole` from each pad's type, and tags the
generator `trace_footprints`. `FootprintActions` wires this to the "Copy to Clipboard"
button.

<Warning>
  Reconstruction is a **quick, editable** placeholder built from pad data — it does **not**
  reproduce real pad geometry, courtyard, silkscreen, or 3D model. For real geometry, use the
  raw download below.
</Warning>

## Raw download — `GET /api/download/[library]`

Serves the **raw original** `.kicad_mod` from the upstream Trace GitHub repo, preserving all
geometry and graphics.

<ParamField query="name" type="string" required>Footprint name (without extension).</ParamField>
<ParamField query="source" type="string" default="trace">`trace` or `cern`.</ParamField>

```
GET /api/download/Package_DFN_QFN?name=QFN-16-1EP_3x3mm_P0.5mm&source=trace
→ 200  Content-Type: application/octet-stream
       Content-Disposition: attachment; filename="QFN-16-1EP_3x3mm_P0.5mm.kicad_mod"
       Cache-Control: public, max-age=86400
```

Internally it fetches:
`https://raw.githubusercontent.com/buildwithtrace/trace-kicad-footprints-lib/main/{library}.pretty/{name}.kicad_mod`
(library + name are validated against a safe charset; no path traversal).

<Info>
  **CERN footprints are not mirrored** on the Trace GitHub repo. `source=cern` returns `404`
  ("Raw download unavailable for this source"), and the client falls back to clipboard
  reconstruction. `400` if `name` is missing.
</Info>
