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

# Flip Name

A name whose letters are cubes that turn under the pointer, exported from `@fabiocv/ui/flip-name`.

```tsx
import type { CSSProperties } from 'react';

import { FlipName } from '@fabiocv/ui/flip-name';

<h1>
  <FlipName
    style={
      {
        '--flip-edge': '32px',
        fontSize: 28,
        fontWeight: 500,
        textTransform: 'uppercase',
      } as CSSProperties
    }
  >
    Fabio Azevedo
  </FlipName>
</h1>;
```

- `children` is text only. Each character becomes a cube, spaces included.
- It renders a `span` with no meaning of its own. The heading and the type are the page's.
- Set `--flip-edge`, the cube's height and depth, along with `font-size`. The two do not follow each other. A `FlipName` is a mark rather than text, so its size is not one of [the type's](https://ui.fabio.cv/typography/index.md).
- It is drawn for capitals. The lettering sits a pixel down, as capitals have no descenders to fill the line.
- It enters by turning letter by letter, once the font has loaded, then each letter turns to a shaded block as the pointer crosses it, and back a second after.
- A quick pointer turns every letter on its path, in the order it crossed them, even where the browser skipped samples. Touch turns none, as lifting a finger has no way out.
- It works in static HTML with no script, where hover alone turns the letters. So it moves on CSS transitions, and not on the [springs](https://ui.fabio.cv/motion/index.md).
- Copied, the name is one line of text. Printed, it is flat.
- With reduced motion the letters are still.

Set these on `style`. Values inherited from a parent are overridden by the defaults.

| Property                       | What it sets                                     | Default       |
| ------------------------------ | ------------------------------------------------ | ------------- |
| `--flip-edge`                  | The cube's height and depth                      | `16px`        |
| `--flip-face-bg`               | The faces' ground. Give it one for a solid plate | `transparent` |
| `--flip-in-delay`              | The hold before the first letter turns in        | `400ms`       |
| `--flip-in-stagger`            | The delay from one letter to the next            | `45ms`        |
| `--band-above`, `--band-below` | How far past the letters the pointer counts      | `0px`         |

`flipChars`, `flipCharsHtml`, `armFlip` and `holdForFont` are its parts, for markup written without React: `flipCharsHtml` writes the letters, to go inside a `<span class="flip-name">`, and `armFlip` follows the pointer over that span until the function it returns is called.

## Types of `@fabiocv/ui/flip-name`

```ts
/** A pointer sample, in client coordinates. */
export interface Point {
    x: number;
    y: number;
}

/** One character's horizontal extent — the cell the pointer path is tested against. */
export interface Cell {
    left: number;
    right: number;
}

/** The row's vertical extent, cube plus the bands above and below it. */
export interface Band {
    top: number;
    bottom: number;
}

/** Injected overlay contract keeps debug.ts out of bundles that do not use it. */
export interface FlipDebug {
    /** Whether the overlay is currently drawing. `armFlip` keeps its rAF loop alive while it is. */
    readonly on: boolean;
    /** Show, hide, or flip. Builds the DOM on first show. */
    toggle(next?: boolean): void;
    /** Re-position the boxes over the measured geometry. */
    layout(cells: Cell[], band: Band): void;
    /** Record one pointer segment and the cells it resolved to. */
    path(a: Point, b: Point, hits: number[]): void;
    /** Paint: box states from `state`, plus the recent path. */
    render(state: Int8Array): void;
    /** Remove the overlay from the document. */
    destroy(): void;
}

export interface FlipDebugContext {
    /** The character elements, in document order. */
    cubes: HTMLElement[];
    /** Ask `armFlip` for another frame — the overlay animates its trail independently. */
    wake(): void;
}

export type FlipDebugFactory = (context: FlipDebugContext) => FlipDebug;

export interface ArmFlipOptions {
    /** Debug overlay factory, omitted to keep it out of the bundle. Toggle with ?debug or Shift+D. */
    debug?: FlipDebugFactory;
}

/**
 * Arm the pointer trigger on one name.
 *
 * @param root the `.flip-name` element
 * @returns a teardown function, safe to call even when arming was declined
 */
export declare function armFlip(root: HTMLElement | null, options?: ArmFlipOptions): () => void;

/** Holds the entrance until the lettering font loads, since fallbacks differ in shape and metrics. Apps should also preload it. */
/**
 * @param root the `.flip-name` element
 * @returns a teardown that releases the hold, safe to call at any time
 */
export declare function holdForFont(root: HTMLElement | null): () => void;

export function flipChars(value: string): FlipChar[];

export function flipCharsHtml(value: string): string;

export type FlipChar = {
    /**
     * the character itself, spaces included
     */
    char: string;
    /**
     * its position, which `flip.css` multiplies out into
     * the animation delay that makes the name resolve left to right on load
     */
    index: number;
};

export interface FlipNameProps {
    /** Text only: each character becomes a cube. */
    children: string;
    /** Typography and flip.css custom properties. Set --flip-edge as well as font-size. */
    className?: string;
    /**
     * Runtime styling. Set custom properties here: element defaults override
     * values inherited from ancestors.
     */
    style?: CSSProperties;
}

/**
 * Per-character cubes with an entrance animation and pointer-triggered turns.
 * Always renders a span; consumers provide heading semantics and typography.
 * Pass the debug factory to armFlip to opt in.
 */
export declare const FlipName: ({ children, className, style }: FlipNameProps) => import("react").JSX.Element;
```

## Examples

### Default

```tsx
<FlipName
  style={{
    '--flip-edge': '32px',
    fontSize: 28,
    fontWeight: 500,
    textTransform: 'uppercase',
  }}
>
  Fabio Azevedo
</FlipName>
```

### On a plate

```tsx
<FlipName
  style={{
    '--flip-edge': '18px',
    '--flip-face-bg': 'var(--color-surface-subtle)',
    fontSize: 14,
    fontWeight: 500,
    textTransform: 'uppercase',
  }}
>
  Fabio Azevedo
</FlipName>
```

See it at https://ui.fabio.cv/flip-name/.
