---
title: "Tools & defaults — Vue"
description: "Change what each tool draws, add your own tools, and choose the cursor, the preview and what happens after drawing."
framework: "Vue"
source: "https://www.embedpdf.com/docs/headless/vue/annotations/tools"
---

# Tools & defaults

A tool says what a click or a drag on the page creates: the kind of annotation, its default
colors and sizes, the cursor, and whether a preview follows the pointer. Change the built-in
tools, or add your own, with the `tools` setting of `annotationPlugin()`:

```ts
annotationPlugin({
  tools: [
    { id: 'ink', defaults: { color: '#1e90ff', strokeWidth: 3 } },
    {
      id: 'arrow',
      extends: 'line',
      defaults: { lineEndings: { start: 'none', end: 'closed-arrow' } },
    },
  ],
});
```

The first entry changes the built-in `ink` tool. The second adds an `arrow` tool: a line with an
arrowhead. Activate a tool with `interaction.activateTool('arrow')`, as on the
[overview](../annotations#let-people-draw).

## Change the default color, width and font

A tool's `defaults` are the fields every annotation it draws starts with. They're the same fields
the annotation has, so the [engine's page for each kind](https://www.embedpdf.com/docs/engine/annotations) lists what you
can set:

```ts
annotationPlugin({
  tools: [
    { id: 'square', defaults: { color: '#dc143c', strokeWidth: 2, interiorColor: '#ffe4e1' } },
    { id: 'highlight', defaults: { color: '#90ee90', opacity: 0.6 } },
    { id: 'free-text', defaults: { fontFamily: 'helvetica', fontSize: 16, fontColor: '#1e1e1e' } },
    { id: 'note', defaults: { icon: 'help', color: '#ffd700' } },
  ],
});
```

Defaults can be any field except where the annotation goes (`box`, points, `rect`), since that
comes from the drawing. Flags are fields too: `{ id: 'note', defaults: { locked: true } }` makes
every new note locked.

A field the tool's kind doesn't have (a `fontSize` on a square) stops the app at startup with an
error that names the tool and the field.

## Make your own tool

`extends` starts from a tool and changes what you name. The new tool keeps everything else: its
kind, cursor, preview and behavior:

```ts
annotationPlugin({
  tools: [
    { id: 'red-pen', extends: 'ink', defaults: { color: '#ff0000', strokeWidth: 2 } },
    { id: 'marker', extends: 'ink-highlight', defaults: { color: '#ffa500' } },
    { id: 'todo', extends: 'note', defaults: { icon: 'key', contents: 'TODO' } },
    {
      id: 'docs-link',
      extends: 'link',
      defaults: { target: { kind: 'uri', uri: 'https://example.com/docs' } },
    },
  ],
});
```

Give a tool a label and an icon for your toolbar in `meta`. The plugin keeps it and never reads
it:

```ts
annotationPlugin({
  tools: [{ id: 'red-pen', extends: 'ink', meta: { label: 'Red pen', icon: 'pen' } }],
});
```

`annotation.tools.list()` returns every tool, so a toolbar can build itself from it.

**`App.vue`**

```vue
<script setup lang="ts">
import { DocumentGate, Viewer } from '@embedpdf/vue/runtime';
import type { OpenInput } from '@embedpdf/vue/runtime';
import { Stage, stagePlugin } from '@embedpdf/vue/stage';
import { RenderLayer, renderPlugin } from '@embedpdf/vue/render';
import { interactionPlugin } from '@embedpdf/vue/interaction';
import { AnnotationLayer, annotationPlugin } from '@embedpdf/vue/annotation';
import { localEngine } from '@embedpdf/engine';
import Toolbar from './Toolbar.vue';

import '../custom-tools.css';

const engine = localEngine();
// A blue pen, an arrow, and three tools of your own. `meta` is yours: the toolbar reads its label.
const plugins = [
  stagePlugin(),
  renderPlugin(),
  interactionPlugin(),
  annotationPlugin({
    tools: [
      { id: 'ink', defaults: { color: '#1e90ff', strokeWidth: 3 }, meta: { label: 'Blue pen' } },
      {
        id: 'arrow',
        extends: 'line',
        defaults: { lineEndings: { start: 'none', end: 'closed-arrow' } },
        meta: { label: 'Arrow' },
      },
      {
        id: 'red-pen',
        extends: 'ink',
        defaults: { color: '#ff0000', strokeWidth: 2 },
        meta: { label: 'Red pen' },
      },
      {
        id: 'marker',
        extends: 'ink-highlight',
        defaults: { color: '#ffa500' },
        meta: { label: 'Marker' },
      },
      {
        id: 'todo',
        extends: 'note',
        defaults: { icon: 'key', contents: 'TODO' },
        meta: { label: 'To do' },
      },
    ],
  }),
];

const ebook = async (): Promise<OpenInput> => {
  const response = await fetch('https://snippet.embedpdf.com/ebook.pdf');
  return { kind: 'bytes', id: 'ebook', bytes: new Uint8Array(await response.arrayBuffer()) };
};
</script>

<template>
  <Viewer :engine="engine" :plugins="plugins" :initial-documents="[{ source: ebook }]">
    <DocumentGate>
      <template #fallback><p class="loading">Loading…</p></template>
      <Toolbar />
      <Stage class="stage">
        <template #page>
          <RenderLayer />
          <AnnotationLayer />
        </template>
      </Stage>
    </DocumentGate>
  </Viewer>
</template>
```

**`custom-tools.css`**

```css
/* Colors */
:root {
  --ink: #1a2748;
  --text: #3b4b7a;
  --muted: #5a6b92;
  --line: #e6eaf2;
  --line-strong: #dce8fc;
  --surface: #ffffff;
  --tint: #f3f7fe;
  --canvas: #f7f9fc;
  --accent: #054fb3;
  --focus: #7db6ff;
  --shadow: rgb(7 32 76 / 0.04);
}

/* The controls, above the pages */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

/* One choice of a few: the pressed button is the current one */
.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  background: var(--tint);
  border: 1px solid var(--line);
  border-radius: 11px;
}

.segmented button {
  font: inherit;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}

.segmented button:hover {
  color: var(--ink);
}

.segmented button[aria-pressed='true'] {
  color: var(--accent);
  background: var(--surface);
  box-shadow: 0 1px 2px rgb(7 32 76 / 0.1);
}

.segmented button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* The pages */
.stage {
  height: 420px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--canvas);
  box-shadow:
    0 1px 2px var(--shadow),
    0 18px 40px -28px rgb(7 32 76 / 0.28);
}

.loading {
  margin: 0;
  padding: 24px 0;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
```

**`Toolbar.vue`**

```vue
<script setup lang="ts">
import { computed, watch } from 'vue';
import { usePageList } from '@embedpdf/vue/runtime';
import { useInteraction, useInteractionState } from '@embedpdf/vue/interaction';
import { useAnnotation, useAnnotationState } from '@embedpdf/vue/annotation';

// A toolbar that builds itself from the tools: every tool with a label gets a button.
const annotation = useAnnotation();
const interaction = useInteraction();
const { activeToolId } = useInteractionState();
const ready = useAnnotationState((state) => state.status === 'ready');
const pages = usePageList();
const cover = computed(() => pages.value[0]?.ref);
const labelled = computed(() =>
  annotation.tools.list().filter((tool) => typeof tool.meta?.label === 'string'),
);
let added = false;

// On load: an arrow drawn with the arrow tool's defaults, and the arrow tool active.
watch(
  [ready, cover],
  ([isReady, page]) => {
    if (!isReady || !page || added) return;
    added = true;
    void annotation.create(
      page,
      { subtype: 'line', linePoints: { start: { x: 520, y: 120 }, end: { x: 470, y: 230 } } },
      undefined,
      { tool: 'arrow' },
    );
    interaction.activateTool('arrow');
  },
  { immediate: true },
);
</script>

<template>
  <div class="toolbar">
    <div class="segmented" role="group" aria-label="Tool">
      <button
        type="button"
        :aria-pressed="activeToolId === 'pointer'"
        @click="interaction.activateTool('pointer')"
      >
        Select
      </button>
      <button
        v-for="tool in labelled"
        :key="tool.id"
        type="button"
        :aria-pressed="activeToolId === tool.id"
        @click="interaction.activateTool(tool.id)"
      >
        {{ String(tool.meta?.label) }}
      </button>
    </div>
  </div>
</template>
```

> **Try it:** every button but **Select** comes from a tool's `meta`. Draw with **Red pen**, then
> place a **To do** note.

Tools can also be added while the app runs. `register()` returns a function that removes the tool
again:

```ts
const remove = annotation.tools.register({
  id: 'green-pen',
  extends: 'ink',
  defaults: { color: '#00a000' },
});
```

## Let people change the defaults

A color picker or a width slider in your toolbar changes a tool's defaults for the drawings that
follow:

**`ink-color.vue`**

```vue
<script setup lang="ts">
import { computed } from 'vue';
import { useAnnotation, useAnnotationDefaults } from '@embedpdf/vue/annotation';

const annotation = useAnnotation();
const defaults = useAnnotationDefaults('ink');

const color = computed({
  get: () => defaults.value.color,
  set: (color) => annotation.tools.updateDefaults('ink', { color }),
});
</script>

<template>
  <input v-model="color" type="color" />
</template>
```

`useAnnotationDefaults()` updates when the defaults change, so the picker always
shows the current color. To build a whole style panel for any tool, ask for its fields; they come in
the same shape as a [style panel for the selection](selecting#a-style-panel):

```ts
const { properties, values } = annotation.tools.getProperties('ink'); // color, opacity, strokeWidth, …
```

Defaults belong to the person drawing: they're kept in this viewer and never shared with others on
the same document.

### Remember them

To keep a person's choices for next time, save them when they change:

**`remember.vue`**

```vue
<script setup lang="ts">
import { useAnnotationEvent } from '@embedpdf/vue/annotation';

useAnnotationEvent(
  (annotation) => annotation.tools.onDefaultsChanged,
  ({ toolId, defaults }) => {
    localStorage.setItem(`tool:${toolId}`, JSON.stringify(defaults));
  },
);
</script>
```

Then pass them back at startup:

```ts
annotationPlugin({
  tools: ['ink', 'highlight'].map((id) => ({
    id,
    defaults: JSON.parse(localStorage.getItem(`tool:${id}`) ?? '{}'),
  })),
});
```

**`App.vue`**

```vue
<script setup lang="ts">
import { DocumentGate, Viewer } from '@embedpdf/vue/runtime';
import type { OpenInput } from '@embedpdf/vue/runtime';
import { Stage, stagePlugin } from '@embedpdf/vue/stage';
import { RenderLayer, renderPlugin } from '@embedpdf/vue/render';
import { interactionPlugin } from '@embedpdf/vue/interaction';
import { AnnotationLayer, annotationPlugin } from '@embedpdf/vue/annotation';
import { localEngine } from '@embedpdf/engine';
import PenStyle from './PenStyle.vue';
import RememberDefaults from './RememberDefaults.vue';
import StartWithThePen from './StartWithThePen.vue';

import '../tool-defaults.css';

const engine = localEngine();
// The pen starts with what the reader picked last time: see RememberDefaults.vue.
const plugins = [
  stagePlugin(),
  renderPlugin(),
  interactionPlugin(),
  annotationPlugin({
    tools: [{ id: 'ink', defaults: JSON.parse(localStorage.getItem('tool:ink') ?? '{}') }],
  }),
];

const ebook = async (): Promise<OpenInput> => {
  const response = await fetch('https://snippet.embedpdf.com/ebook.pdf');
  return { kind: 'bytes', id: 'ebook', bytes: new Uint8Array(await response.arrayBuffer()) };
};
</script>

<template>
  <Viewer :engine="engine" :plugins="plugins" :initial-documents="[{ source: ebook }]">
    <DocumentGate>
      <template #fallback><p class="loading">Loading…</p></template>
      <StartWithThePen />
      <RememberDefaults />
      <PenStyle />
      <Stage class="stage">
        <template #page>
          <RenderLayer />
          <AnnotationLayer />
        </template>
      </Stage>
    </DocumentGate>
  </Viewer>
</template>
```

**`tool-defaults.css`**

```css
/* Colors */
:root {
  --ink: #1a2748;
  --text: #3b4b7a;
  --muted: #5a6b92;
  --line: #e6eaf2;
  --line-strong: #dce8fc;
  --surface: #ffffff;
  --tint: #f3f7fe;
  --canvas: #f7f9fc;
  --accent: #054fb3;
  --focus: #7db6ff;
  --shadow: rgb(7 32 76 / 0.04);
}

/* The controls, above the pages */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

/* Colors to pick from: the pressed one is the current one */
.swatches {
  display: inline-flex;
  gap: 6px;
}

.swatch {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 2px solid var(--surface);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--line);
  cursor: pointer;
}

.swatch[aria-pressed='true'] {
  box-shadow: 0 0 0 2px var(--ink);
}

.swatch:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Any color */
.color {
  width: 34px;
  height: 30px;
  padding: 2px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

/* A slider, with its label and its value */
.range {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 550;
  color: var(--ink);
}

.range input {
  width: 110px;
  accent-color: var(--accent);
}

.readout {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* The pages */
.stage {
  height: 420px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--canvas);
  box-shadow:
    0 1px 2px var(--shadow),
    0 18px 40px -28px rgb(7 32 76 / 0.28);
}

.loading {
  margin: 0;
  padding: 24px 0;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
```

**`PenStyle.vue`**

```vue
<script setup lang="ts">
import { useAnnotation, useAnnotationDefaults } from '@embedpdf/vue/annotation';

const COLORS = ['#e5484d', '#1e90ff', '#30a46c', '#1a2748'];

// The pen's color and width, for the strokes that follow.
const annotation = useAnnotation();
const defaults = useAnnotationDefaults('ink');

function pickColor(event: Event) {
  annotation.tools.updateDefaults('ink', { color: (event.target as HTMLInputElement).value });
}

function pickWidth(event: Event) {
  annotation.tools.updateDefaults('ink', {
    strokeWidth: Number((event.target as HTMLInputElement).value),
  });
}
</script>

<template>
  <div class="toolbar">
    <div class="swatches" role="group" aria-label="Pen color">
      <button
        v-for="color in COLORS"
        :key="color"
        type="button"
        class="swatch"
        :aria-label="color"
        :aria-pressed="defaults.color === color"
        :style="{ background: color }"
        @click="annotation.tools.updateDefaults('ink', { color })"
      />
    </div>
    <input
      type="color"
      class="color"
      aria-label="Any color"
      :value="defaults.color ?? '#000000'"
      @input="pickColor"
    />
    <label class="range">
      Width
      <input type="range" min="1" max="12" :value="defaults.strokeWidth ?? 1" @input="pickWidth" />
      <output class="readout">{{ defaults.strokeWidth }} pt</output>
    </label>
  </div>
</template>
```

**`RememberDefaults.vue`**

```vue
<script setup lang="ts">
import { useAnnotationEvent } from '@embedpdf/vue/annotation';

// Every change is kept for next time.
useAnnotationEvent(
  (annotation) => annotation.tools.onDefaultsChanged,
  ({ toolId, defaults }) => {
    localStorage.setItem(`tool:${toolId}`, JSON.stringify(defaults));
  },
);
</script>

<template></template>
```

**`StartWithThePen.vue`**

```vue
<script setup lang="ts">
import { computed, watch } from 'vue';
import { usePageList } from '@embedpdf/vue/runtime';
import { useInteraction } from '@embedpdf/vue/interaction';
import { useAnnotation, useAnnotationState } from '@embedpdf/vue/annotation';

// On load: the pen is active, with a stroke drawn in its current style.
const annotation = useAnnotation();
const interaction = useInteraction();
const ready = useAnnotationState((state) => state.status === 'ready');
const pages = usePageList();
const cover = computed(() => pages.value[0]?.ref);
let added = false;

watch(
  [ready, cover],
  ([isReady, page]) => {
    if (!isReady || !page || added) return;
    added = true;
    const wave = Array.from({ length: 24 }, (_, i) => ({
      x: 300 + i * 10,
      y: 540 + Math.sin(i / 2) * 14,
    }));
    void annotation.create(page, { subtype: 'ink', inkList: [wave] }, undefined, { tool: 'ink' });
    interaction.activateTool('ink');
  },
  { immediate: true },
);
</script>

<template></template>
```

> **Try it:** pick a color and a width, and draw. Reload the page: the pen still has them.

## What happens after drawing

By default the new annotation is selected, so its handles and your menu appear at once, and the
tool stays active, so people can draw another. Change it for every tool, or for one:

```ts
annotationPlugin({
  afterCreate: { select: false, tool: 'stay' }, // every tool: keep drawing, don't select
  tools: [
    { id: 'stamp', afterCreate: { select: true, tool: 'default' } }, // one stamp, then back
  ],
});
```

| Setting    | What it does                                                                                  | Default  |
| :--------- | :-------------------------------------------------------------------------------------------- | :------- |
| `select`   | Select the new annotation.                                                                    | `true`   |
| `tool`     | `'stay'` keeps the tool active. `'default'` goes back to the default tool, usually `pointer`. | `'stay'` |
| `editText` | For text boxes: start typing in the new box right away.                                       | `true`   |

A tool's own `afterCreate` wins over the one for every tool.

The setting can change while the app runs. A "keep tool" button in your toolbar is one call:

```ts
annotation.updateSettings({ afterCreate: { tool: keepTool ? 'stay' : 'default' } });
```

**`App.vue`**

```vue
<script setup lang="ts">
import { DocumentGate, Viewer } from '@embedpdf/vue/runtime';
import type { OpenInput } from '@embedpdf/vue/runtime';
import { Stage, stagePlugin } from '@embedpdf/vue/stage';
import { RenderLayer, renderPlugin } from '@embedpdf/vue/render';
import { interactionPlugin } from '@embedpdf/vue/interaction';
import { AnnotationLayer, annotationPlugin } from '@embedpdf/vue/annotation';
import { localEngine } from '@embedpdf/engine';
import AfterDrawing from './AfterDrawing.vue';

import '../after-create.css';

const engine = localEngine();
const plugins = [stagePlugin(), renderPlugin(), interactionPlugin(), annotationPlugin()];

const ebook = async (): Promise<OpenInput> => {
  const response = await fetch('https://snippet.embedpdf.com/ebook.pdf');
  return { kind: 'bytes', id: 'ebook', bytes: new Uint8Array(await response.arrayBuffer()) };
};
</script>

<template>
  <Viewer :engine="engine" :plugins="plugins" :initial-documents="[{ source: ebook }]">
    <DocumentGate>
      <template #fallback><p class="loading">Loading…</p></template>
      <AfterDrawing />
      <Stage class="stage">
        <template #page>
          <RenderLayer />
          <AnnotationLayer />
        </template>
      </Stage>
    </DocumentGate>
  </Viewer>
</template>
```

**`after-create.css`**

```css
/* Colors */
:root {
  --ink: #1a2748;
  --text: #3b4b7a;
  --muted: #5a6b92;
  --line: #e6eaf2;
  --line-strong: #dce8fc;
  --surface: #ffffff;
  --tint: #f3f7fe;
  --canvas: #f7f9fc;
  --accent: #054fb3;
  --focus: #7db6ff;
  --shadow: rgb(7 32 76 / 0.04);
}

/* The controls, above the pages */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  line-height: 1.1;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 12px;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 1px 2px var(--shadow);
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease;
}

.button:hover {
  background: var(--tint);
  border-color: var(--line-strong);
}

.button:active {
  transform: translateY(1px);
}

.button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.button[aria-pressed='true'] {
  color: var(--accent);
  background: var(--tint);
  border-color: var(--line-strong);
}

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* A switch: a checkbox with its label */
.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 550;
  color: var(--ink);
  cursor: pointer;
}

.check input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

/* Pushes what follows to the right */
.spacer {
  flex: 1 1 auto;
}

.readout {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* The pages */
.stage {
  height: 420px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--canvas);
  box-shadow:
    0 1px 2px var(--shadow),
    0 18px 40px -28px rgb(7 32 76 / 0.28);
}

.loading {
  margin: 0;
  padding: 24px 0;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
```

**`AfterDrawing.vue`**

```vue
<script setup lang="ts">
import { onMounted } from 'vue';
import { useInteraction, useInteractionState } from '@embedpdf/vue/interaction';
import { useAnnotation, useAnnotationSettings } from '@embedpdf/vue/annotation';

const annotation = useAnnotation();
const interaction = useInteraction();
const { activeToolId } = useInteractionState();
const { afterCreate } = useAnnotationSettings();

function selectIt(event: Event) {
  annotation.updateSettings({ afterCreate: { select: (event.target as HTMLInputElement).checked } });
}

function keepTheTool(event: Event) {
  annotation.updateSettings({
    afterCreate: { tool: (event.target as HTMLInputElement).checked ? 'stay' : 'default' },
  });
}

// The rectangle tool is active on load.
onMounted(() => interaction.activateTool('square'));
</script>

<template>
  <div class="toolbar">
    <button
      type="button"
      class="button"
      :aria-pressed="activeToolId === 'square'"
      @click="interaction.activateTool('square')"
    >
      Rectangle
    </button>
    <label class="check">
      <input type="checkbox" :checked="afterCreate.select" @change="selectIt" />
      Select it
    </label>
    <label class="check">
      <input type="checkbox" :checked="afterCreate.tool === 'stay'" @change="keepTheTool" />
      Keep the tool
    </label>
    <button type="button" class="button" @click="annotation.resetSettings()">Reset</button>
    <span class="spacer" />
    <output class="readout">{{ activeToolId === 'square' ? 'Drawing' : 'Selecting' }}</output>
  </div>
</template>
```

> **Try it:** draw a rectangle, then turn off **Keep the tool** and draw another: the tool goes back
> to selecting.

Annotations your code creates are never selected unless you ask for it; see
[Create an annotation](with-code#create-an-annotation).

## Click or drag

Most drawing tools also work with a single click: it places an annotation of a default size where
you click. `clickCreate` sets that size, or turns it off:

```ts
annotationPlugin({
  tools: [
    { id: 'square', clickCreate: { width: 120, height: 80 } },
    { id: 'line', clickCreate: { length: 100 } },
    { id: 'circle', clickCreate: false }, // drag only
  ],
});
```

| Tool                 | A click makes                                         |
| :------------------- | :---------------------------------------------------- |
| `square`, `circle`   | 80 × 60 points, centered on the click                 |
| `line`               | 80 points long, pointing right, centered on the click |
| `free-text`          | 180 × 40 points, its top-left at the click            |
| `note`, `attachment` | A 20 × 20 icon                                        |
| `stamp`              | The stamp, 150 points wide, centered on the click     |

`anchor` says which part of it lands on the click. A box takes `'center'` (the default) or
`'top-left'`; a line takes `'center'` (the default), `'start'` or `'end'`. A line's `rotation` turns it
clockwise from pointing right, in degrees. An arrow whose tip lands where you click, pointing down:

```ts
annotationPlugin({
  tools: [{ id: 'arrow', clickCreate: { length: 80, rotation: 90, anchor: 'end' } }],
});
```

**`App.vue`**

```vue
<script setup lang="ts">
import { DocumentGate, Viewer } from '@embedpdf/vue/runtime';
import type { OpenInput } from '@embedpdf/vue/runtime';
import { Stage, stagePlugin } from '@embedpdf/vue/stage';
import { RenderLayer, renderPlugin } from '@embedpdf/vue/render';
import { interactionPlugin } from '@embedpdf/vue/interaction';
import { AnnotationLayer, annotationPlugin } from '@embedpdf/vue/annotation';
import { localEngine } from '@embedpdf/engine';
import Toolbar from './Toolbar.vue';

import '../click-create.css';

const engine = localEngine();
// What one click makes: a 120 × 80 rectangle, an arrow pointing down at the click, and no circle.
const plugins = [
  stagePlugin(),
  renderPlugin(),
  interactionPlugin(),
  annotationPlugin({
    tools: [
      { id: 'square', clickCreate: { width: 120, height: 80 } },
      {
        id: 'arrow',
        extends: 'line',
        defaults: { lineEndings: { start: 'none', end: 'closed-arrow' } },
        clickCreate: { length: 80, rotation: 90, anchor: 'end' },
      },
      { id: 'circle', clickCreate: false }, // drag only
    ],
  }),
];

const ebook = async (): Promise<OpenInput> => {
  const response = await fetch('https://snippet.embedpdf.com/ebook.pdf');
  return { kind: 'bytes', id: 'ebook', bytes: new Uint8Array(await response.arrayBuffer()) };
};
</script>

<template>
  <Viewer :engine="engine" :plugins="plugins" :initial-documents="[{ source: ebook }]">
    <DocumentGate>
      <template #fallback><p class="loading">Loading…</p></template>
      <Toolbar />
      <Stage class="stage">
        <template #page>
          <RenderLayer />
          <AnnotationLayer />
        </template>
      </Stage>
    </DocumentGate>
  </Viewer>
</template>
```

**`click-create.css`**

```css
/* Colors */
:root {
  --ink: #1a2748;
  --text: #3b4b7a;
  --muted: #5a6b92;
  --line: #e6eaf2;
  --line-strong: #dce8fc;
  --surface: #ffffff;
  --tint: #f3f7fe;
  --canvas: #f7f9fc;
  --accent: #054fb3;
  --focus: #7db6ff;
  --shadow: rgb(7 32 76 / 0.04);
}

/* The controls, above the pages */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

/* One choice of a few: the pressed button is the current one */
.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  background: var(--tint);
  border: 1px solid var(--line);
  border-radius: 11px;
}

.segmented button {
  font: inherit;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}

.segmented button:hover {
  color: var(--ink);
}

.segmented button[aria-pressed='true'] {
  color: var(--accent);
  background: var(--surface);
  box-shadow: 0 1px 2px rgb(7 32 76 / 0.1);
}

.segmented button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.hint {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

/* The pages */
.stage {
  height: 420px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--canvas);
  box-shadow:
    0 1px 2px var(--shadow),
    0 18px 40px -28px rgb(7 32 76 / 0.28);
}

.loading {
  margin: 0;
  padding: 24px 0;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
```

**`Toolbar.vue`**

```vue
<script setup lang="ts">
import { computed, onMounted } from 'vue';
import { useInteraction, useInteractionState } from '@embedpdf/vue/interaction';

const TOOLS = [
  { id: 'square', label: 'Rectangle', hint: 'A click makes 120 × 80 points' },
  { id: 'arrow', label: 'Arrow', hint: 'A click points an arrow down at it' },
  { id: 'circle', label: 'Circle', hint: 'Drag only: a click does nothing' },
];

const interaction = useInteraction();
const { activeToolId } = useInteractionState();
const active = computed(() => TOOLS.find((tool) => tool.id === activeToolId.value));

// The rectangle tool is active on load: click the page.
onMounted(() => interaction.activateTool('square'));
</script>

<template>
  <div class="toolbar">
    <div class="segmented" role="group" aria-label="Tool">
      <button
        v-for="tool in TOOLS"
        :key="tool.id"
        type="button"
        :aria-pressed="activeToolId === tool.id"
        @click="interaction.activateTool(tool.id)"
      >
        {{ tool.label }}
      </button>
    </div>
    <p class="hint">{{ active?.hint ?? 'Pick a tool, then click the page' }}</p>
  </div>
</template>
```

> **Try it:** click the page with each tool. The arrow's tip lands where you click.

What a click makes always stays on the page: near an edge, it's moved inside.

## The cursor

While a tool is active, the pointer shows the tool's cursor. Over an annotation the viewer switches
to a move or resize cursor by itself, and over text to a text cursor, so people always see what a
click will do. You choose the cursor for the rest of the page. There are three steps, from simple
to fully yours.

**A standard cursor.** Any CSS cursor name:

```ts
annotationPlugin({ tools: [{ id: 'square', cursor: 'cell' }] });
```

**An image.** `svgCursor()`, from `@embedpdf/vue/interaction`, turns an SVG into a cursor. The
SVG needs a `width` and a `height`, and `hotspot` is the point in it that clicks:

```ts
annotationPlugin({
  tools: [{ id: 'ink', cursor: svgCursor({ svg: penIcon, hotspot: { x: 2, y: 22 } }) }],
});
```

**An image that follows the defaults.** `useToolCursor()` sets a tool's cursor from a component, so
it can change with the tool's color:

**`ink-cursor.vue`**

```vue
<script setup lang="ts">
import { useAnnotationDefaults } from '@embedpdf/vue/annotation';
import { useToolCursor } from '@embedpdf/vue/interaction';

import { penIcon } from './icons';

const defaults = useAnnotationDefaults('ink');

// A getter, so the cursor follows the color
useToolCursor(() => ({
  toolId: 'ink',
  cursors: { crosshair: { svg: penIcon(defaults.value.color), hotspot: { x: 2, y: 22 } } },
}));
</script>
```

`cursors` replaces cursors by name: `crosshair` is the ink tool's own cursor. Name `text` too to
replace the text cursor a markup tool shows over text. The cursor goes back to the tool's own when
the component is removed.

**`App.vue`**

```vue
<script setup lang="ts">
import { DocumentGate, Viewer } from '@embedpdf/vue/runtime';
import type { OpenInput } from '@embedpdf/vue/runtime';
import { Stage, stagePlugin } from '@embedpdf/vue/stage';
import { RenderLayer, renderPlugin } from '@embedpdf/vue/render';
import { interactionPlugin } from '@embedpdf/vue/interaction';
import { AnnotationLayer, annotationPlugin } from '@embedpdf/vue/annotation';
import { localEngine } from '@embedpdf/engine';
import InkCursor from './InkCursor.vue';
import Toolbar from './Toolbar.vue';

import '../cursor.css';

const engine = localEngine();
// A standard cursor for the rectangle tool: any CSS cursor name.
const plugins = [
  stagePlugin(),
  renderPlugin(),
  interactionPlugin(),
  annotationPlugin({ tools: [{ id: 'square', cursor: 'cell' }] }),
];

const ebook = async (): Promise<OpenInput> => {
  const response = await fetch('https://snippet.embedpdf.com/ebook.pdf');
  return { kind: 'bytes', id: 'ebook', bytes: new Uint8Array(await response.arrayBuffer()) };
};
</script>

<template>
  <Viewer :engine="engine" :plugins="plugins" :initial-documents="[{ source: ebook }]">
    <DocumentGate>
      <template #fallback><p class="loading">Loading…</p></template>
      <InkCursor />
      <Toolbar />
      <Stage class="stage">
        <template #page>
          <RenderLayer />
          <AnnotationLayer />
        </template>
      </Stage>
    </DocumentGate>
  </Viewer>
</template>
```

**`cursor.css`**

```css
/* Colors */
:root {
  --ink: #1a2748;
  --text: #3b4b7a;
  --muted: #5a6b92;
  --line: #e6eaf2;
  --line-strong: #dce8fc;
  --surface: #ffffff;
  --tint: #f3f7fe;
  --canvas: #f7f9fc;
  --accent: #054fb3;
  --focus: #7db6ff;
  --shadow: rgb(7 32 76 / 0.04);
}

/* The controls, above the pages */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  line-height: 1.1;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 12px;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 1px 2px var(--shadow);
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease;
}

.button:hover {
  background: var(--tint);
  border-color: var(--line-strong);
}

.button:active {
  transform: translateY(1px);
}

.button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.button[aria-pressed='true'] {
  color: var(--accent);
  background: var(--tint);
  border-color: var(--line-strong);
}

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* Colors to pick from: the pressed one is the current one */
.swatches {
  display: inline-flex;
  gap: 6px;
}

.swatch {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 2px solid var(--surface);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--line);
  cursor: pointer;
}

.swatch[aria-pressed='true'] {
  box-shadow: 0 0 0 2px var(--ink);
}

.swatch:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* The pages */
.stage {
  height: 420px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--canvas);
  box-shadow:
    0 1px 2px var(--shadow),
    0 18px 40px -28px rgb(7 32 76 / 0.28);
}

.loading {
  margin: 0;
  padding: 24px 0;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
```

**`InkCursor.vue`**

```vue
<script setup lang="ts">
import { useToolCursor } from '@embedpdf/vue/interaction';
import { useAnnotationDefaults } from '@embedpdf/vue/annotation';

// A pen, 24 × 24, in a color: its tip is the bottom-left corner.
const penIcon = (color: string) =>
  `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">` +
  `<path d="M3 21l1.5-5.5L16 4l4 4L8.5 19.5z" fill="${color}" stroke="#ffffff" stroke-width="1.5" stroke-linejoin="round"/>` +
  `</svg>`;

// The pen cursor follows the pen's color: a getter, so it's read again when the color changes.
const defaults = useAnnotationDefaults('ink');
useToolCursor(() => ({
  toolId: 'ink',
  cursors: {
    crosshair: { svg: penIcon(defaults.value.color ?? '#000000'), hotspot: { x: 2, y: 22 } },
  },
}));
</script>

<template></template>
```

**`Toolbar.vue`**

```vue
<script setup lang="ts">
import { onMounted } from 'vue';
import { useInteraction, useInteractionState } from '@embedpdf/vue/interaction';
import { useAnnotation, useAnnotationDefaults } from '@embedpdf/vue/annotation';

const COLORS = ['#e5484d', '#1e90ff', '#30a46c', '#1a2748'];

const annotation = useAnnotation();
const interaction = useInteraction();
const { activeToolId } = useInteractionState();
const defaults = useAnnotationDefaults('ink');

function pick(swatch: string) {
  annotation.tools.updateDefaults('ink', { color: swatch });
  interaction.activateTool('ink');
}

// The pen is active on load: move the pointer over the page.
onMounted(() => interaction.activateTool('ink'));
</script>

<template>
  <div class="toolbar">
    <button
      type="button"
      class="button"
      :aria-pressed="activeToolId === 'ink'"
      @click="interaction.activateTool('ink')"
    >
      Pen
    </button>
    <div class="swatches" role="group" aria-label="Pen color">
      <button
        v-for="swatch in COLORS"
        :key="swatch"
        type="button"
        class="swatch"
        :aria-label="swatch"
        :aria-pressed="defaults.color === swatch"
        :style="{ background: swatch }"
        @click="pick(swatch)"
      />
    </div>
    <button
      type="button"
      class="button"
      :aria-pressed="activeToolId === 'square'"
      @click="interaction.activateTool('square')"
    >
      Rectangle
    </button>
  </div>
</template>
```

> **Try it:** move the pointer over the page, then pick another color. **Rectangle** shows the
> standard `cell` cursor.

## Show a preview before placing

A **preview** (a ghost) is a see-through copy of what a click would place, following the pointer. It
shows exactly where the annotation will land and how big it will be:

```ts
annotationPlugin({
  tools: [
    { id: 'square', ghost: true },
    { id: 'note', ghost: { opacity: 0.3 } },
    { id: 'todo', extends: 'note', ghost: false },
  ],
});
```

The preview is the annotation the click will make, drawn with the tool's current defaults: its
color, its width, an arrow's head, a form field's border and background. Change a default and the
preview changes with it. It's half see-through unless you set `opacity`; `--epdf-ghost-opacity`
sets it from CSS for every tool (see [Colors & theming](../ui/theming)).

**`App.vue`**

```vue
<script setup lang="ts">
import { computed, ref } from 'vue';
import { DocumentGate, Viewer } from '@embedpdf/vue/runtime';
import type { OpenInput } from '@embedpdf/vue/runtime';
import { Stage, stagePlugin } from '@embedpdf/vue/stage';
import { RenderLayer, renderPlugin } from '@embedpdf/vue/render';
import { interactionPlugin } from '@embedpdf/vue/interaction';
import { AnnotationLayer, annotationPlugin } from '@embedpdf/vue/annotation';
import { localEngine } from '@embedpdf/engine';
import Toolbar from './Toolbar.vue';

import '../ghost.css';

const engine = localEngine();
// A preview for the rectangle (off by default for tools you drag), and a fainter one for notes.
const plugins = [
  stagePlugin(),
  renderPlugin(),
  interactionPlugin(),
  annotationPlugin({
    tools: [
      { id: 'square', ghost: true },
      { id: 'note', ghost: { opacity: 0.3 } },
    ],
  }),
];

const ebook = async (): Promise<OpenInput> => {
  const response = await fetch('https://snippet.embedpdf.com/ebook.pdf');
  return { kind: 'bytes', id: 'ebook', bytes: new Uint8Array(await response.arrayBuffer()) };
};

// `--epdf-ghost-opacity` from CSS wins over each tool's own opacity, for every tool.
const opacity = ref<number | null>(null);
const ghostOpacity = computed(() =>
  opacity.value === null ? undefined : { '--epdf-ghost-opacity': opacity.value },
);
</script>

<template>
  <Viewer :engine="engine" :plugins="plugins" :initial-documents="[{ source: ebook }]">
    <DocumentGate>
      <template #fallback><p class="loading">Loading…</p></template>
      <Toolbar v-model:opacity="opacity" />
      <Stage class="stage" :style="ghostOpacity">
        <template #page>
          <RenderLayer />
          <AnnotationLayer />
        </template>
      </Stage>
    </DocumentGate>
  </Viewer>
</template>
```

**`ghost.css`**

```css
/* Colors */
:root {
  --ink: #1a2748;
  --text: #3b4b7a;
  --muted: #5a6b92;
  --line: #e6eaf2;
  --line-strong: #dce8fc;
  --surface: #ffffff;
  --tint: #f3f7fe;
  --canvas: #f7f9fc;
  --accent: #054fb3;
  --focus: #7db6ff;
  --shadow: rgb(7 32 76 / 0.04);
}

/* The controls, above the pages */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

/* One choice of a few: the pressed button is the current one */
.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  background: var(--tint);
  border: 1px solid var(--line);
  border-radius: 11px;
}

.segmented button {
  font: inherit;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}

.segmented button:hover {
  color: var(--ink);
}

.segmented button[aria-pressed='true'] {
  color: var(--accent);
  background: var(--surface);
  box-shadow: 0 1px 2px rgb(7 32 76 / 0.1);
}

.segmented button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* A slider, with its label and its value */
.range {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 550;
  color: var(--ink);
}

.range input {
  width: 110px;
  accent-color: var(--accent);
}

.readout {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  line-height: 1.1;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 12px;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 1px 2px var(--shadow);
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease;
}

.button:hover {
  background: var(--tint);
  border-color: var(--line-strong);
}

.button:active {
  transform: translateY(1px);
}

.button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.button[aria-pressed='true'] {
  color: var(--accent);
  background: var(--tint);
  border-color: var(--line-strong);
}

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* The pages */
.stage {
  height: 420px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--canvas);
  box-shadow:
    0 1px 2px var(--shadow),
    0 18px 40px -28px rgb(7 32 76 / 0.28);
}

.loading {
  margin: 0;
  padding: 24px 0;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
```

**`Toolbar.vue`**

```vue
<script setup lang="ts">
import { onMounted } from 'vue';
import { useInteraction, useInteractionState } from '@embedpdf/vue/interaction';

const TOOLS = [
  { id: 'note', label: 'Note' },
  { id: 'square', label: 'Rectangle' },
];

/** The ghost opacity from CSS, or `null` for each tool's own. */
const opacity = defineModel<number | null>('opacity', { required: true });

const interaction = useInteraction();
const { activeToolId } = useInteractionState();

function slide(event: Event) {
  opacity.value = Number((event.target as HTMLInputElement).value);
}

// The note tool is active on load: move the pointer over the page.
onMounted(() => interaction.activateTool('note'));
</script>

<template>
  <div class="toolbar">
    <div class="segmented" role="group" aria-label="Tool">
      <button
        v-for="tool in TOOLS"
        :key="tool.id"
        type="button"
        :aria-pressed="activeToolId === tool.id"
        @click="interaction.activateTool(tool.id)"
      >
        {{ tool.label }}
      </button>
    </div>
    <label class="range">
      From CSS
      <input type="range" min="0.1" max="0.9" step="0.1" :value="opacity ?? 0.5" @input="slide" />
      <output class="readout">
        {{ opacity === null ? "each tool's own" : `${Math.round(opacity * 100)}%` }}
      </output>
    </label>
    <button type="button" class="button" :disabled="opacity === null" @click="opacity = null">
      Reset
    </button>
  </div>
</template>
```

> **Try it:** move the pointer over the page: the note follows it, faintly. Then move the slider.

It shows only where a click would place something. Over an annotation the click selects it, and
over text a text tool selects text, so the preview hides there. It hides too when the person may
not create annotations. A tool whose click makes nothing, like ink, a polygon, or a tool with
`clickCreate: false`, never shows one. While you press, the preview stays, since letting go is
still a click; once you drag, the drawing takes its place.

It's on by default for tools you use by clicking: stamps, notes, attachments, and the form
plugin's field tools, which show the field a click places (a radio button round, as it will be).
It's off for tools you mostly drag, like shapes and lines, since the size usually comes from the
drag. `ghost: true` turns it on for them.

The cursor and the preview do different jobs. The cursor says *which* tool is active; the preview
says *where* the annotation will land. You can use either, or both.

## Stamps and files

The `stamp` and `attachment` tools ask for a file after the click.

The file dialog comes from a small composable: call it once, in a component that's always
mounted, such as your toolbar:

**`file-picker.vue`**

```vue
<script setup lang="ts">
import { useFilePickerProvider } from '@embedpdf/vue/annotation';

useFilePickerProvider();
</script>

<template>
  <div role="toolbar"><!-- your tools --></div>
</template>
```

**`App.vue`**

```vue
<script setup lang="ts">
import { DocumentGate, Viewer } from '@embedpdf/vue/runtime';
import type { OpenInput } from '@embedpdf/vue/runtime';
import { Stage, stagePlugin } from '@embedpdf/vue/stage';
import { RenderLayer, renderPlugin } from '@embedpdf/vue/render';
import { interactionPlugin } from '@embedpdf/vue/interaction';
import { AnnotationLayer, annotationPlugin } from '@embedpdf/vue/annotation';
import { localEngine } from '@embedpdf/engine';
import StartWithAFile from './StartWithAFile.vue';
import Toolbar from './Toolbar.vue';

import '../file-picker.css';

const engine = localEngine();
const plugins = [stagePlugin(), renderPlugin(), interactionPlugin(), annotationPlugin()];

const ebook = async (): Promise<OpenInput> => {
  const response = await fetch('https://snippet.embedpdf.com/ebook.pdf');
  return { kind: 'bytes', id: 'ebook', bytes: new Uint8Array(await response.arrayBuffer()) };
};
</script>

<template>
  <Viewer :engine="engine" :plugins="plugins" :initial-documents="[{ source: ebook }]">
    <DocumentGate>
      <template #fallback><p class="loading">Loading…</p></template>
      <StartWithAFile />
      <Toolbar />
      <Stage class="stage">
        <template #page>
          <RenderLayer />
          <AnnotationLayer />
        </template>
      </Stage>
    </DocumentGate>
  </Viewer>
</template>
```

**`file-picker.css`**

```css
/* Colors */
:root {
  --ink: #1a2748;
  --text: #3b4b7a;
  --muted: #5a6b92;
  --line: #e6eaf2;
  --line-strong: #dce8fc;
  --surface: #ffffff;
  --tint: #f3f7fe;
  --canvas: #f7f9fc;
  --accent: #054fb3;
  --focus: #7db6ff;
  --shadow: rgb(7 32 76 / 0.04);
}

/* The controls, above the pages */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

/* One choice of a few: the pressed button is the current one */
.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  background: var(--tint);
  border: 1px solid var(--line);
  border-radius: 11px;
}

.segmented button {
  font: inherit;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}

.segmented button:hover {
  color: var(--ink);
}

.segmented button[aria-pressed='true'] {
  color: var(--accent);
  background: var(--surface);
  box-shadow: 0 1px 2px rgb(7 32 76 / 0.1);
}

.segmented button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.hint {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

/* The pages */
.stage {
  height: 420px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--canvas);
  box-shadow:
    0 1px 2px var(--shadow),
    0 18px 40px -28px rgb(7 32 76 / 0.28);
}

.loading {
  margin: 0;
  padding: 24px 0;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}
```

**`StartWithAFile.vue`**

```vue
<script setup lang="ts">
import { computed, watch } from 'vue';
import { usePageList } from '@embedpdf/vue/runtime';
import { useInteraction } from '@embedpdf/vue/interaction';
import { useAnnotation, useAnnotationState } from '@embedpdf/vue/annotation';

// On load: a text file pinned to the cover, and the stamp tool active.
const annotation = useAnnotation();
const interaction = useInteraction();
const ready = useAnnotationState((state) => state.status === 'ready');
const pages = usePageList();
const cover = computed(() => pages.value[0]?.ref);
let added = false;

watch(
  [ready, cover],
  ([isReady, page]) => {
    if (!isReady || !page || added) return;
    added = true;
    const notes = new File(['Questions for the next review.'], 'notes.txt', { type: 'text/plain' });
    void annotation.create(
      page,
      { subtype: 'file-attachment', rect: { x: 470, y: 232, width: 20, height: 20 } },
      { file: notes },
    );
    interaction.activateTool('stamp');
  },
  { immediate: true },
);
</script>

<template></template>
```

**`Toolbar.vue`**

```vue
<script setup lang="ts">
import { useInteraction, useInteractionState } from '@embedpdf/vue/interaction';
import { useFilePickerProvider } from '@embedpdf/vue/annotation';

const TOOLS = [
  { id: 'pointer', label: 'Select' },
  { id: 'stamp', label: 'Stamp' },
  { id: 'attachment', label: 'Attach a file' },
];

// The toolbar is always mounted, so it gives the stamp and attachment tools their file dialog.
useFilePickerProvider();
const interaction = useInteraction();
const { activeToolId } = useInteractionState();
</script>

<template>
  <div class="toolbar" role="toolbar">
    <div class="segmented" role="group" aria-label="Tool">
      <button
        v-for="tool in TOOLS"
        :key="tool.id"
        type="button"
        :aria-pressed="activeToolId === tool.id"
        @click="interaction.activateTool(tool.id)"
      >
        {{ tool.label }}
      </button>
    </div>
    <p class="hint">
      <template v-if="activeToolId === 'stamp'">Click the page, then pick a PNG or a JPEG</template>
      <template v-else-if="activeToolId === 'attachment'">Click the page, then pick any file</template>
    </p>
  </div>
</template>
```

> **Try it:** click the page with **Stamp**, and pick a PNG or a JPEG. The paper clip on the cover
> is a file attached from code.

To pick from your own library or a cloud drive instead, pass a function. It gets the tool and the
spot, and returns the file, or `null` to cancel:

**`file-picker-custom.vue`**

```vue
<script setup lang="ts">
import { useFilePickerProvider } from '@embedpdf/vue/annotation';

import { openStampLibrary } from './stamp-library';

useFilePickerProvider(async ({ toolId, page, point }) => {
  if (toolId === 'stamp') return { data: await openStampLibrary() };
  return null;
});
</script>

<template>
  <div role="toolbar"><!-- your tools --></div>
</template>
```

A stamp tool can also carry fixed bytes, so a click places it at once:

```ts
annotationPlugin({
  tools: [{ id: 'approved', extends: 'stamp', source: { kind: 'bytes', source: approvedPng } }],
});
```

For libraries of stamps, see [Stamps](stamps).

## Methods

What `useAnnotation()` gives you for tools and stamps: its `tools` and `stamps` parts. The rest is on
[Annotations in code](with-code#methods).

| Method                                  | What it does                                                                                                                                                                                             |
| :-------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `tools.list()`                          | Every tool, the built-in ones and yours, so a toolbar can build itself from it. [Make your own tool](#make-your-own-tool)                                                                                |
| `tools.get(id)`                         | One tool, or `null`                                                                                                                                                                                      |
| `tools.register(tool)`                  | Adds a tool while the app runs, or replaces the one with the same id, and returns a function that removes it                                                                                             |
| `tools.getDefaults(id)`                 | The fields a tool's next annotation starts with. In a component, use `useAnnotationDefaults(id)`. [Let people change the defaults](#let-people-change-the-defaults)                                      |
| `tools.updateDefaults(id, changes)`     | Changes a tool's defaults for the drawings that follow. They stay in this viewer and are never shared.                                                                                                   |
| `tools.getProperties(id)`               | What a style panel for the tool shows: `{ properties, values, mixed }`, the same shape as for the [selection](selecting#a-style-panel)                                                                   |
| `stamps.arm(stamp)`, `stamps.disarm()`  | Arms a stamp's bytes so the next click places them, as the `stamp` tool does after picking a file, or disarms them. For stamps from a library, use [Stamps](stamps).                                     |
| `stamps.isArmed()`                      | Whether a stamp is armed                                                                                                                                                                                 |
| `stamps.place(stamp, { page, center })` | Places a stamp's bytes with its middle on `center`, without a click. Resolves `{ annotation }`.                                                                                                          |
| `setFilePickerProvider(provider)`       | Sets the function that gives the `stamp` and `attachment` tools their file, and returns a function that removes it. In a component, use `useFilePickerProvider()`. [Stamps and files](#stamps-and-files) |

Every method that returns a promise also takes a `signal` in its options, to cancel it.

## Events

**`defaults-changed.vue`**

```vue
<script setup lang="ts">
import { useAnnotationEvent } from '@embedpdf/vue/annotation';

import { saveStyle } from './styles';

useAnnotationEvent(
  (annotation) => annotation.tools.onDefaultsChanged,
  ({ toolId, defaults }) => saveStyle(toolId, defaults),
);
</script>
```

| Event                     | Fires when                                           | Carries              |
| :------------------------ | :--------------------------------------------------- | :------------------- |
| `tools.onDefaultsChanged` | A tool's defaults changed, from your UI or your code | `toolId`, `defaults` |

## Good to know

### Rotated pages

On a rotated page, what a tool places looks the way its author saw it. Stamps and text boxes are
turned so they read upright. A clicked square or circle keeps its `clickCreate` size as the page
shows (it isn't turned, its sides swap), and a clicked line points the way its `clickCreate` says.
`upright: false` turns that off; `upright: true` turns it on for your own tools.

### Touch

On a touch screen, drawing tools take a single finger: it draws, and two fingers still scroll and
zoom. Click tools (notes, stamps) place with a tap, and a drag still scrolls.

### Every option

| Option        | What it is                                                                              |
| :------------ | :-------------------------------------------------------------------------------------- |
| `id`          | The tool's name, used with `interaction.activateTool(id)`.                              |
| `extends`     | A tool to start from.                                                                   |
| `subtype`     | The kind of annotation it draws, for a tool that doesn't extend another.                |
| `defaults`    | The fields every new annotation starts with.                                            |
| `cursor`      | The cursor while the tool is active.                                                    |
| `ghost`       | A preview that follows the pointer: `true`, `false` or `{ opacity }`.                   |
| `clickCreate` | What a single click makes, and which part lands on the click, or `false` for drag only. |
| `afterCreate` | Select the new annotation? Keep the tool? Start typing?                                 |
| `upright`     | Turn new annotations upright on rotated pages.                                          |
| `source`      | For stamp tools: fixed bytes, or ask for a file.                                        |
| `meta`        | Your own data, such as a label and an icon for a toolbar.                               |
