# Espresso machine

A spring-lever group drawn as the linkage it is: lever, connecting rod, piston. The declining shot pressure is the spring paying its force back, not a curve somebody drew.

> For the complete index, see [llms.txt](https://robocn.dev/llms.txt). A Markdown version of any page is available by appending `.md` to its URL or by sending an `Accept: text/markdown` header.

## Install

```bash
bunx --bun shadcn@latest add https://robocn.dev/r/espresso-machine.json
```

Registry item: `espresso-machine` · [`https://robocn.dev/r/espresso-machine.json`](https://robocn.dev/r/espresso-machine.json)

## Notes

- The lever is a crank, the link is a connecting rod and the piston is the slider, so the piston position comes from `solveSliderCrank` — the same closed-loop solver the mud pump runs on. Pulling the lever down raises the piston and compresses the spring; letting it go is the shot.
- Pressure is the spring's force over the piston area and nothing else, which is why the gauge falls through the extraction. A lever machine's declining profile is a property of springs, not a shape anyone chose.
- Flow is Darcy's law through the puck, with a threshold below which nothing comes through at all, and what is in the cup is that flow integrated over the part of the shot that has happened — sampled rather than accumulated, so the same `shot` always gives the same cup.
- One number is the whole state, which is what lets the stream run because the piston is descending rather than because a timer said so.
- No temperature, no crema, no dose, no grind, no acoustics. The steam plume, the sight glass and the meniscus are drawing.
- A generic lever machine. No manufacturer, model, badge or café is reproduced here or in the demo.

## Usage

```tsx
import { EspressoMachine } from "@/components/ui/espresso-machine"

<EspressoMachine behavior="pull" cups={2} />

// Or scrub the shot and read the gauge off it.
<EspressoMachine shot={0.45} onPressureChange={setBar} />
<EspressoMachine interactive cutaway />
```

## Props

| name | type | default | description |
| --- | --- | --- | --- |
| `view` | `"plan" | "front" | "profile" | "iso"` | `"front"` | Where the camera stands. One machine, four projections: straight down, straight on, side elevation, or three-quarter from above. |
| `shot` | `number` | — | Controlled progress through one pull, 0 to 1: a fast charge, then the long extraction. Supplying it stops the loop. |
| `behavior` | `"pull" | "steam" | "idle" | "static"` | `"pull"` | Pull one shot per cycle, steam with the wand, or stand idle with the lever up. |
| `cups` | `1 | 2` | `1` | Cups under the spout. Two is one basket split, which is what a double is. |
| `wand` | `number` | `18` | Steam wand angle in degrees from vertical, clamped to ±40. |
| `cutaway` | `boolean` | `true` | Cut the group open so the piston, the spring, the rod and the water under the piston are visible. |
| `speed` | `number` | `0.22` | Shots per second. |
| `animate` | `boolean` | `true` | Off parks the machine at phase and stops rendering. A reduced-motion preference does the same. |
| `paused` | `boolean` | `false` | Freeze where it stands. |
| `phase` | `number` | `0` | Seconds of offset, so a row of machines breaks step. |
| `interactive` | `boolean` | `false` | Drag down the frame to pull the lever through a shot, or arrow-key it. |
| `onShotChange` | `(shot: number) => void` | — | Progress through the pull throughout a drag or a key press. |
| `onPressureChange` | `(bar: number) => void` | — | Group pressure in bar, to a tenth, whenever it changes. |
| `showGround` | `boolean` | `true` | Draw the contact shadow under the machine. |
| `label` | `string` | — | Caption under the drawing. |
| `variant` | `"solid" | "outline" | "blueprint" | "wire"` | `"solid"` | How the machine is painted. Geometry never changes between variants. |
| `size` | `"xs" | "sm" | "md" | "lg" | "xl" | number` | `"md"` | Rendered width in pixels, or a step on the scale. |
| `color` | `string` | `var(--robot-shell)` | Body panels — the colour the machine reads as. |
| `accent` | `string` | `var(--robot-accent)` | Status colour: tip light, live tool, readouts. |
| `metal` | `string` | `var(--robot-metal)` | Bare machined parts: collars, bolts, tool bodies. |
| `dark` | `string` | `var(--robot-dark)` | Cast joints, base, shadow side. |
| `palette` | `Partial<RobotPalette>` | — | Override any subset of roles at once, including glow and grid. |

## Source

- `src/components/ui/espresso-machine.tsx`
