# assemble

Thousands of lit particles fly out of the depth around the page and gather into a heading.

When the heading scrolls into view, a cloud of small glossy beads drifts in front of and behind the page, larger and softer the closer it is to the viewer, then streams along curved paths into the shapes of the letters, left to right, and settles without overshoot. As each letter fills, the real text fades in over its particles, so the heading ends as selectable DOM text with no jump. Tiles that tumble and glint, or streaks of light, can stand in for the beads, and the cloud can rise from below, burst out of a point deep behind the heading or pour in from both sides. With the hover trigger the heading stays made of beads, and the ones under the pointer or a finger lift towards the viewer and spring back.

Module `text`, category Text. Import `@dioramajs/text/assemble`. [Source](https://github.com/MasterKurosava/diorama/blob/main/packages/text/src/assemble.ts)

A planetarium headline that gathers out of a cloud of lit particles floating in front of and behind the page.

```html title="index.html"
<div class="as-hero">
  <p class="as-kicker">Planetarium · Winter season</p>
  <h2 class="as-headline" data-dio="assemble" data-dio-color="#e4ecff" data-dio-accent="#8fd3ff">Every star has a place</h2>
  <p class="as-lede">Forty minutes under a full dome, narrated live by our astronomers. Shows nightly at 7 and 9.</p>
</div>
```

## Usage

Put it on: a large heading or a short line of display text. Not img, video, canvas, svg or form fields. Text with text-shadow, a text stroke, background-clip: text or vertical writing stays as it is.

`start()` registers `assemble`, so the attribute alone puts it on an element.

```html
<h1 data-dio="assemble">Gather into light</h1>
```

In page transitions: Leaving a page, the text breaks back into particles that fly off into the depth; entering, they gather again.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-dio-style` | `'dots' \| 'squares' \| 'dashes'` | `'dots'` | dots are glossy beads lit from the upper left, for most headings; squares are flat tiles that tumble and glint, like glitter or gold leaf; dashes are streaks of light along the motion, for a fast tech look. |
| `from` (rebuilds) | `data-dio-from` | `'scatter' \| 'below' \| 'center' \| 'edges'` | `'scatter'` | scatter starts from a cloud around the heading, in front of and behind the page; below rises from under it; center bursts out of a point deep behind its middle; edges pours in from both sides. |
| `trigger` (rebuilds) | `data-dio-trigger` | `'view' \| 'scroll' \| 'hover'` | `'view'` | view gathers when the heading enters; scroll gathers it towards the middle of the viewport and scatters it again above; hover keeps it as beads the pointer lifts. |
| `density` (rebuilds) | `data-dio-density` | `number` 0.3 to 3 | `1` | Particles per area of the glyphs; 2 doubles them, up to the tier limit. At most low 0.6. |
| `dot` | `data-dio-dot` | `number` 1 to 6 px | `2.2` | Size of a particle once it has landed. |
| `duration` | `data-dio-duration` | `number` 0.3 to 4 s | `1.4` | Flight time of one particle from its start to its place. |
| `stagger` | `data-dio-stagger` | `number` 0 to 0.2 s | `0.03` | Delay between neighboring letters, so they fill in reading order. |
| `spread` | `data-dio-spread` | `number` 0 to 3 | `1` | How far from the text particles start; with the hover trigger, the pointer reach. |
| `delay` | `data-dio-delay` | `number` 0 to 2 s | `0` | Wait after the trigger, for a cascade. |
| `threshold` | `data-dio-threshold` | `number` 0 to 1 | `0.2` | Share of the element height in view, above the bottom tenth, before it plays. |
| `color` | `data-dio-color` | `color` | `'currentColor'` | Color of the particles in flight; currentColor keeps the color of the text. |
| `accent` | `data-dio-accent` | `color` | `'currentColor'` | Second color shimmering through particles in flight; currentColor for none. |
| `seed` (rebuilds) | `data-dio-seed` | `number` 1 to 100 | `1` | Picks the starts, paths and sizes; the same seed gathers the same way. |

Changing a param marked rebuilds re-runs the effect setup.

### Variants

- `style`: `dots`, `squares`, `dashes`
  - `dots` are glossy beads lit from the upper left, for most headings.
  - `squares` are flat tiles that tumble and glint, like glitter or gold leaf.
  - `dashes` are streaks of light along the motion, for a fast tech look.
- `trigger`: `view`, `scroll`, `hover`
  - `view` gathers when the heading enters.
  - `scroll` gathers it towards the middle of the viewport and scatters it again above.
  - `hover` keeps it as beads the pointer lifts.
- `from`: `scatter`, `below`, `center`, `edges`
  - `scatter` starts from a cloud around the heading, in front of and behind the page.
  - `below` rises from under it.
  - `center` bursts out of a point deep behind its middle.
  - `edges` pours in from both sides.

## Inputs and frames

Reads [`height`](/docs/api/inputs#input-height), [`presence`](/docs/api/inputs#presence), [`progress`](/docs/api/inputs#progress), [`size`](/docs/api/inputs#size), [`y`](/docs/api/inputs#input-y). Draws only while something on it moves, then stops. Only while particles fly, while scrolling with the scroll trigger and while lifted beads settle with the hover trigger; none at rest. See [how a frame is decided](/docs/concepts/frames).

## Reduced motion and touch

With reduced motion it is off and the element shows as plain HTML. Off: the text is shown as it is, and the engine does not load for it.

Runs on every device. The same as with a mouse; with the hover trigger the beads follow a finger while it presses on the heading.

```ts
import { start } from '@dioramajs/diorama'

start({ effects: { assemble: { reducedMotion: 'static' } } })
```

## Cost and quality

Loads 11.6 KB the first time a page uses it. GPU: One instanced draw of up to 14,000 small quads, and one instanced draw of a quad per letter for the crisp text. Memory: A canvas of the text at twice its CSS size, and about 80 bytes per particle: about 1.1 MB at the high tier.

- low: A quarter of the particles, density at most 0.6, and the text rastered at 1 device pixel per CSS pixel instead of 2.
- medium: About half of the particles.

See [the quality plugin](/docs/effects/quality).

## Recipes

### A heading made of beads

With `data-dio-trigger="hover"` the heading gathers once and then stays made of particles instead of handing back to the text. The beads under the pointer lift towards the viewer, part a little and spring back into place when it moves on; on a touch screen they follow a finger while it presses on the heading. An `accent` color tints the beads that are lifted. Move the pointer across the heading below.

A dark band with a heading of glossy beads that lift towards the viewer under the pointer and spring back.

```html title="index.html"
<section class="as-touch">
  <h2 class="as-touch-title" data-dio="assemble" data-dio-trigger="hover" data-dio-accent="#ff8fd8" data-dio-dot="2.6">Made of stardust</h2>
  <p class="as-touch-note">Move the pointer across the heading, or press and drag on a touch screen.</p>
</section>
```

`spread` sets how far the pointer reaches, in multiples of 80 px. The text stays real for screen readers, search and selection, but it shows as particles, so keep this trigger for a short display line rather than a heading people need to read at a glance.

### Section headings that form on scroll

With `data-dio-trigger="scroll"` a heading gathers as it rises towards the middle of the viewport, holds there as plain text, and breaks up again as it moves on towards the top. Streaks from both sides suit a tech product page; scrolling back plays it in reverse.

```html
<h2 data-dio="assemble" data-dio-trigger="scroll" data-dio-style="dashes" data-dio-from="edges">Signal and noise</h2>
```

### Gold leaf for a launch or an award

Tiles that tumble and catch the light, rising from below the heading, read like gold leaf or glitter. A warm `color` gives them their own tint in flight; they settle into the color of the text.

```html
<h1 data-dio="assemble" data-dio-style="squares" data-dio-from="below" data-dio-dot="3" data-dio-color="#ffcf6e">Launch day</h1>
```

## Notes

The particles are small objects in the 3D space around the page, seen through the same camera as the page itself. Those in front of the page are larger, brighter and a little out of focus, those far behind it smaller and dimmer, and their paths bend through depth on the way in. Each one is lit from the upper left: beads show a highlight, tiles glint as they turn.

Their positions come from the pixels of the heading’s own text, drawn the way the browser laid it out, and they take their color from the text, so mixed colors and weights inside the heading carry over. The real text fades in over the particles of each letter as it fills, and once the last letter is in the element is plain, selectable DOM text. Text on screen when the page opens is hidden until the effect is ready and then gathers, as with `text-reveal`.

The number of particles follows the area of the glyphs: about 5,000 for a 128 px heading of three words, at most 14,000 on fast devices, fewer on slower ones. `density` raises or lowers it within that limit, and `dot` sets the size they land at. Under reduced motion the effect is off and the text shows at once. Text with `text-shadow`, `-webkit-text-stroke`, `background-clip: text` or a vertical writing mode stays as it is, with a warning in development. `style`, `from`, `trigger`, `density` and `seed` rebuild the effect when they change.

## Related

- [blinds](/docs/effects/blinds.md): A heading printed across real 3D slats that turn over in a wave, lit and casting shadows, to show it.
- [counter](/docs/effects/counter.md): Stats count up to their value on real 3D mechanics: odometer drums, slot machine reels or flip cards.
- [dust](/docs/effects/dust.md): A heading crumbles into fine sand that lifts off the page and drifts away in depth as it scrolls out, or on a click.
- [emboss](/docs/effects/emboss.md): Letters pressed into or raised out of paper, leather, brushed metal, stone or plaster, lit by a light that follows the pointer.
- [extrude](/docs/effects/extrude.md): A headline becomes a solid 3D block: beveled letters with lit side walls, seen in perspective, that turn toward the pointer.
- [fire](/docs/effects/fire.md): The letters burn: flames rise from their tops, sparks drift up in depth and the firelight flickers on the page.
- [hologram](/docs/effects/hologram.md): A heading becomes a 3D hologram: projected from a glowing emitter, built of slices in depth, crossed by scan lines.
- [inflate](/docs/effects/inflate.md): Letters puff up into round 3D shapes, like balloons or soft clay, that dent and wobble under the pointer.
- [Reduced motion](/docs/guides/reduced-motion.md)
- [Performance and quality](/docs/guides/performance.md)
