# <motion-strike>

A line that draws itself through a phrase, from left to right. Use it for
an old price, a removed step or a word you replace.

**Use it for:** an old price, a removed step or a replaced word, often
followed by the new value marked with `motion-marker` and a `delay`.

**Avoid it for:** text the reader still needs to read, because text with a
line through it is harder to read.

**Accessibility:** the line alone does not tell screen readers that the
text is removed. Wrap the component in `<del>`, and the new value in
`<ins>`. Browsers then draw their own line through `<del>`, so set
`text-decoration: none` on it.

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

**Common mistakes:** a `<del>` around the component with its default
`text-decoration`, so two lines show.

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

## Install

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

Or without a build step:

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

## Example

```html
<del><motion-strike>€49</motion-strike></del> <ins>€29</ins>
```

## Attributes

| Attribute | Type | Default | Description |
| --- | --- | --- | --- |
| `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 strike through. It may wrap across lines. |

## CSS custom properties

| Property | Description |
| --- | --- |
| `--mc-mark-color` | Color of the line. Default `currentColor`. |
| `--mc-mark-thickness` | Thickness of the line. Default `2px`. |
