# Camera capture

Point the camera at something and ask about it: the subject is outlined, the shot freezes into a crop, and the question goes with the picture.

> chatcn Pro: needs a Pro license (https://chatcn.dev/pro). Install from the `@chatcn-pro` registry with your license token; setup at https://chatcn.dev/docs/chatcn-pro.

Example: Camera capture. Take the photo, nudge the crop, ask. The cropped picture and the question land in the chat. Preview: https://chatcn.dev/preview/camera-capture-demo

## Installation

```bash
npx shadcn@latest add @chatcn-pro/camera-capture
```

## Usage

```tsx
import { CameraCapture } from "@/components/ui/chatcn/pro/camera-capture"

<CameraCapture
  stream={cameraStream}                          // from getUserMedia; or still={{ src, alt }} for demos
  subject={{ x: 0.1, y: 0.25, w: 0.78, h: 0.49 }} // from your detector, in fractions of the frame
  suggestions={["How do I replace the ribbon on this?", "What model is this?"]}
  onAsk={({ image, prompt }) => sendToChat(image, prompt)}
  onClose={closeCamera}
/>
```

Laid out like the phone's own camera: black bands with close and flash above, the viewfinder in the middle, the shutter below. When you pass a `subject` (from your own detector), it is outlined in the viewfinder. The shutter flashes and freezes exactly what the viewfinder showed; a crop box starts on the subject, or in the middle, with the rest dimmed. Drag the box or its corners, or focus it and use the arrow keys (Shift resizes). A suggested question sends at once, or type one. `onAsk` gets the cropped picture as a JPEG data URL at the camera's full resolution, the crop and the prompt. Retake goes back to the live view. With no `stream`, `still` stands in for the camera.

## Examples

### States

Example: States. At real phone width with no subject found: the crop starts in the middle. Preview: https://chatcn.dev/preview/camera-capture-states

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `stream` | `MediaStream | null` | A live camera |
| `still` | `{ src, alt }` | A photo standing in for the camera |
| `subject` | `{ x, y, w, h }` | In fractions of the frame; outlined and the crop starts there |
| `suggestions` | `string[]` | Question chips after the shot |
| `onAsk` | `(result) => void` | `{ image, crop, prompt }` |
| `onClose` | `() => void` | The close button |
| `labels` | `Partial<CameraCaptureLabels>` | Every string, for translation |

## Keyboard

| Key | Action |
| --- | --- |
| Arrow keys on the crop | Move it |
| Shift with arrow keys | Resize it |
| Enter in the field | Ask |

## Accessibility

- Every control is a named button; flash reports whether it is on.
- The crop is a focusable slider that says its size, with keyboard moves and resizing.
- The outlined subject is announced as Subject found.

## Motion

A white flash fades over 380 ms on the shutter. Under reduced motion there is no flash.

Source: https://chatcn.dev/docs/components/camera-capture