# <motion-marker>

A highlighter stroke that sweeps behind a phrase from left to right. The
straight stroke follows text that wraps across lines; `shape="wave"` draws a
wavy stroke and keeps the text on one line. The text itself never changes.

**Use it for:** a key phrase in a headline or paragraph that the reader
should notice, such as a benefit, a result or a number.

**Avoid it for:** whole paragraphs, or more than one or two phrases per
screen, where the highlight loses its point. For a line under or through
text, use `motion-underline` or `motion-strike`.

**Accessibility:** the highlight is a background behind the text. The text
stays in the page, selectable, and read by screen readers unchanged. If the
highlight carries meaning, wrap the component in `<mark>`. Keep the color
transparent so the text keeps its contrast.

**Reduced motion:** the highlight appears fully drawn at once on the same
trigger, with no animation. With `loop` it stays drawn and never cycles.

**Common mistakes:** an opaque `--mc-marker-color`, which lowers the text
contrast. Setting `display: block` on the component, which removes the
highlight that follows each line. Using `shape="wave"` on a long phrase,
which stays on one line and can overflow a narrow screen.

Docs: https://www.motion-components.dev/docs/text/motion-marker/

## Install

```js
import 'motion-components/motion-marker'
```

Or without a build step:

```html
<script type="module" src="https://cdn.jsdelivr.net/npm/motion-components@1/dist/motion-marker.js/+esm"></script>
```

## Example

```html
<p>Ship motion that feels <motion-marker>physical</motion-marker>.</p>
<p>Makes <motion-marker loop hold="2">the code</motion-marker> feel alive.</p>
```

## Attributes

| Attribute | Type | Default | Description |
| --- | --- | --- | --- |
| `shape` | `'line' \| 'wave'` | `'line'` | `'line'`, a straight stroke that follows wrapping text, or `'wave'`, a wavy stroke that keeps the text on one line. |
| `trigger` | `'view' \| 'hover' \| 'mount'` | `'view'` | What draws the mark: `'view'` (scrolled into view), `'hover'` (pointer enter, undraws on leave) or `'mount'`. |
| `duration` | `number` | `0.6` | Spring duration of the drawing, in seconds. |
| `delay` | `number` | `0` | Seconds to wait before drawing. |
| `bounce` | `number` | `0` | Spring bounciness. `0` keeps the stroke from overshooting the text. |
| `loop` | `boolean` | `false` | Draw, hold, undraw, draw again on repeat. With `trigger="view"` the cycle runs while the mark is on screen. |
| `hold` | `number` | `1.6` | With `loop`, seconds the mark stays drawn before it undraws. |
| `gap` | `number` | `0.5` | With `loop`, seconds the mark stays undrawn before it draws again. |
| `pause-on-hover` | `boolean` | `false` | Pause the loop while the pointer is over the mark, resuming on leave. |
| `once` | `boolean` | `true` | With `trigger="view"`, draw only the first time. Set `once="false"` to undraw on leave and draw again on every entry. Ignored with `loop`. |
| `threshold` | `number` | `0.6` | Share of the element, from 0 to 1, that must be visible before it draws. |

## Properties

| Property | Type | Description |
| --- | --- | --- |
| `playState` | `'idle' \| 'running' \| 'paused' \| 'finished'` | Current state: `'idle'`, `'running'`, `'paused'` or `'finished'`. |
| `finished` | `Promise<void>` | Resolves when the current run settles. A new run replaces the promise. |

## Methods

| Method | Description |
| --- | --- |
| `play()` | Starts the animation, or resumes it when paused. Resolves once the run settles. Under `prefers-reduced-motion: reduce` the final state is applied immediately without animating. |
| `pause()` | Holds the animation at its current position. No-op unless running. |
| `finish()` | Jumps to the final state and settles. Fires `motion-finish`. |
| `cancel()` | Reverts to the initial state and returns to idle. Fires `motion-cancel`. |
| `replay()` | Draws the mark again from the start. |
| `sweep()` | Sweeps a drawn mark across: it erases from its start, so it leaves at its end, then draws in again from the start. Calls while a sweep runs, before the mark is drawn, or under reduced motion do nothing. |

## Events

The `motion-*` events bubble and are composed.

| Event | Description |
| --- | --- |
| `motion-start` | When a run starts. |
| `motion-finish` | When a run finishes, or `finish()` jumps to the end. |
| `motion-cancel` | When `cancel()` stops a run and resets it. |

## Slots

| Slot | Description |
| --- | --- |
| (default) | The phrase to highlight. It may wrap across lines, except with `shape="wave"`. |

## CSS custom properties

| Property | Description |
| --- | --- |
| `--mc-marker-color` | Color of the highlighter stroke. Default `rgb(250 204 21 / 0.4)`. |
