# <motion-scramble>

Decode-style text scramble. Cycles each character through random glyphs,
locking them in left-to-right until the original text resolves.

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

## Install

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

Or without a build step:

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

## Example

```html
<motion-scramble interval="0.035" iterations="3" trigger="hover">
  DECODE_ME
</motion-scramble>
```

## Attributes

| Attribute | Type | Default | Description |
| --- | --- | --- | --- |
| `interval` | `number` | `0.04` | Time between glyph swaps, in seconds. |
| `delay` | `number` | `0` | Delay before scrambling starts, in seconds. |
| `iterations` | `number` | `2` | Number of random-glyph frames per character before locking in. |
| `once` | `boolean` | `true` | When `true`, only scramble the first time the element enters view. Set `once="false"` to turn it off. Ignored with `loop`. |
| `loop` | `boolean` | `false` | Scramble to the original text, hold, wait, then scramble again on repeat. |
| `hold` | `number` | `1.6` | With `loop`, seconds the resolved text stays visible before it scrambles again. |
| `gap` | `number` | `0.5` | With `loop`, seconds between cycles, while the text is already resolved. |
| `pause-on-hover` | `boolean` | `false` | Pause the loop while the pointer is over the text. |
| `trigger` | `'view' \| 'hover'` | `'view'` | What starts the scramble: `'view'` (when scrolled into view) or `'hover'`. |

## 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 |
| --- | --- |
| `replay()` | Re-runs the scramble animation. |
| `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`. |

## 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 text to scramble. Plain text only — read once on connect. |
