# Prompt weight

Weight words in an image prompt by feel: the word itself grows heavier and takes on colour.

Also called: prompt weighting, weighted prompt.

> 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: Weight a prompt by feel. Pick a word and scroll, drag or use the arrows: it grows heavier and takes on colour as it gains weight, or thins and fades as it loses it, with its weight above it. Preview: https://chatcn.dev/preview/prompt-weight-demo

Pick a word and scroll, drag up or down, or use the arrow keys. The word grows heavier and takes on colour as it gains weight, or thins and fades as it loses it, pushing the words around it aside, with its weight above it. You can read the emphasis of the whole prompt at a glance, before you generate anything. Punctuation never takes weight.

## Installation

```bash
npx shadcn@latest add @chatcn-pro/prompt-weight
```

## Usage

```tsx
import { PromptWeight, weightedPrompt } from "@/components/ui/chatcn/pro/prompt-weight"

<PromptWeight prompt={prompt} weights={weights} onWeightsChange={setWeights} />
generate(weightedPrompt(prompt, weights)) // "a (misty:1.4) cliff"
```

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `prompt` | `string` |  |
| `weights` / `onWeightsChange` | `Record<number, number>` | By word index; missing is 1 |
| `min` / `max` | `number` | Default 0.5 and 1.6 |

## Keyboard

| Key | Action |
| --- | --- |
| `Arrow Up` / `Arrow Down` | Weight the focused word by 0.1 |
| `Home` / `0` | Back to 1 |

## Accessibility

- Each word is a slider with its weight as the value.

## Motion

- Size, weight and colour transition 200 ms. Reduced motion: they change at once.

Source: https://chatcn.dev/docs/components/prompt-weight