> A guide to [@fabiocv/ui](https://ui.fabio.cv/). Every guide is listed at https://ui.fabio.cv/llms.txt.

# Flow Gradient

An animated gradient behind the page, drawn in WebGL and exported from `@fabiocv/ui/flow-gradient`.

```tsx
import { FlowGradient } from '@fabiocv/ui/flow-gradient';

<FlowGradient />;
<FlowGradient config={{ cellSize: 1 }} />;
```

- It is a canvas fixed over the whole window, behind the page's content. It takes no pointer and is hidden from assistive technology.
- To hold it in a box, give the box `position: relative`, `isolation: isolate` and `contain: paint`.
- Waves of colour arrive from past the top-left corner and dissolve before they cross the page, drawn in square blocks of `cellSize`. The default `18` is as tall as a `FlipName` with an `18px` edge. `1` has no blocks.
- It arrives over `introDuration`, `4s`, on first paint.
- `config` takes any of the values below, merged over the defaults one level deep, so a `warp` replaces all of it. It can change while it runs, but for `introDuration`.
- The palette has no white. White is where the effect is absent, so it would read as a break rather than a fade. Keep the last colour close to the first, or the seam shows.
- Keep `warp.strength` under about `0.3`. Past that, rings appear in the middle of the frame.
- It stops while the tab is hidden. With reduced motion it is one still frame. Without WebGL2 the canvas is transparent, so the page has to work without it.
- It is the same in light and dark. Set `washout` below `1` to hold it back.

## Types of `@fabiocv/ui/flow-gradient`

```ts
/**
 * One noise field's contribution to the shape of the gradient: how far it
 * pushes, how large its features are, and how fast it evolves.
 */
export interface NoiseLayer {
    /** How much this layer displaces what it is applied to. */
    strength: number;
    /** Feature size — higher is busier, lower is broader. */
    scale: number;
    /** How fast the field morphs, in noise units per second. */
    speed: number;
}

export interface Vec2 {
    x: number;
    y: number;
}

/**
 * Everything about the look. All fields reach the GPU as uniforms except
 * `palette` (its length is baked into the shader) and `timeOffset`/`maxPixelRatio`.
 */
export interface FlowGradientConfig {
    /** The colour ramp as `#rrggbb` strings, walked cyclically; the last stop should sit close to the first or the seam shows. */
    palette: string[];
    /**
     * Where the waves come from, in clip-ish space (y up, x scaled by aspect).
     * `x` is `-0.5 * aspect + xOffset`; keep both outside the frame or the origin shows as a bullseye.
     */
    focal: {
        xOffset: number;
        y: number;
    };
    /** Low-frequency displacement of space itself, before distance is measured. */
    warp: NoiseLayer;
    /** Higher-frequency wobble added to the measured distance. */
    detail: NoiseLayer;
    /** Distance scaling per axis — compress x and stretch y to drape the bands. */
    anisotropy: Vec2;
    /** Bands per unit of distance. Higher packs more waves into the frame. */
    fieldScale: number;
    /** How fast the ramp travels outward, in ramp cycles per second. */
    waveSpeed: number;
    /** Distances at which the effect starts and finishes dissolving away. */
    fade: {
        start: number;
        end: number;
    };
    /** Global strength, 0–1. Below 1 the whole effect sits back from the page. */
    washout: number;
    /** Seconds the effect takes to arrive on first paint, easing in from a blank page. 0 skips it. */
    introDuration: number;
    /** Seconds of animation to skip, so the first frame is already settled. */
    timeOffset: number;
    /** Ceiling on devicePixelRatio. The effect is soft; 2 is already generous. */
    maxPixelRatio: number;
    /** Tile edge in CSS pixels, multiplied by the clamped DPR for the shader. */
    cellSize: number;
}

/**
 * A fresh config each call, so a caller cannot mutate another's defaults. The
 * palette has no white: white is the absence of the effect, so it would read as
 * a break rather than a fade.
 */
export declare const createDefaultConfig: () => FlowGradientConfig;

export interface FlowGradientProps {
    className?: string;
    /** Overrides merged over the defaults, and live. `introDuration` is read only on mount. */
    config?: Partial<FlowGradientConfig>;
}

/** The animated page background: a WebGL2 shader in a fixed layer, hidden from assistive technology and pointer events. */
export declare const FlowGradient: FC<FlowGradientProps>;
```

## Examples

### Default

```tsx
<FlowGradient />
```

### Without blocks

```tsx
<FlowGradient config={{ cellSize: 1 }} />
```

See it at https://ui.fabio.cv/flow-gradient/.
