# Dither veil

> A fine 8×8 Bayer privacy shield and secret field for API keys, signing secrets and balances: full-viewport optical veil, lazy on-demand fetch, copy-while-veiled and inherent edge-condensing auto-lock.

Hiding an API key, signing secret or bank balance usually forces bad trade-offs: bullet dots jump table widths, CSS blur leaks character shapes on screen-shares, and progress bars under secrets feel gimmicky. This ships two matched pieces built on one 1.5px 8×8 ordered Bayer layer. DitherSecret is a drop-in hairline secret field for real infrastructure: a single full-viewport frosted Bayer pane covers 100% of the secret slot edge-to-edge up to a crisp hairline divider and Reveal/Copy controls, concealing both the characters and the token length. Fetch plaintext lazily on demand via onReveal() while a cool optical Bayer scan sweeps edge-to-edge (never exposing the secret in initial HTML), or press Copy while veiled to write straight to the clipboard without mounting plaintext into the DOM, confirmed by an emerald Bayer sweep. DitherVeil is the inline <span> primitive for balances and figures inside <h1> and <td> with 0px layout shift and magnetic cursor peeking. When autoHideMs is set, there is no progress bar: the secret stays 100% clear while you read, then delicate Bayer frost condenses organically inward from both outer edges over the final two seconds before locking shut, and moving your pointer back over the secret dissolves the frost back out to hold it open.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/dither-veil.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): none
- Docs and live preview: https://hairlineui.com/ui/dither-veil
- Registry item (source): https://hairlineui.com/r/dither-veil.json

## Usage

```tsx
import { DitherSecret, DitherVeil } from "@/components/dither-veil";

// Real-infra API key / signing secret (full-viewport veil, lazy fetch + copy while veiled)
<DitherSecret
  label="Webhook signing secret"
  onReveal={() => fetch("/api/keys/wh_1/reveal", { method: "POST" }).then((r) => r.text())}
/>

// Inline figure with 0px layout shift
<span className="text-4xl font-medium tabular-nums">
  <DitherVeil label="Available balance" autoHideMs={5500}>$48,290.14</DitherVeil>
</span>
```

## Audit-logged secret reveal endpoint and dashboard privacy toggle

Keep plaintext keys off the initial page payload: render DitherSecret with an audit-logged onReveal endpoint so plaintext is fetched only when explicitly revealed or copied.

```tsx
"use client";
import { useState } from "react";
import { DitherSecret, DitherVeil } from "@/components/dither-veil";

export function SecurityPanel({ keyId, balance }: { keyId: string; balance: string }) {
  const [showFigures, setShowFigures] = useState(false);

  async function fetchSecret() {
    const res = await fetch(`/api/keys/${keyId}/reveal`, { method: "POST" });
    if (!res.ok) throw new Error("Re-authentication required to view this secret.");
    const { secret } = await res.json();
    return secret as string;
  }

  return (
    <div className="space-y-4">
      <div className="space-y-1.5">
        <span className="text-xs text-muted-foreground">Live signing secret</span>
        <DitherSecret
          label="Live signing secret"
          onReveal={fetchSecret}
          autoHideMs={8000}
          hideOnBlur
        />
      </div>

      <div className="flex items-baseline justify-between">
        <span className="text-3xl font-medium tabular-nums">
          <DitherVeil label="Account balance" revealed={showFigures} onRevealedChange={setShowFigures} hideOnBlur>
            {balance}
          </DitherVeil>
        </span>
        <button type="button" onClick={() => setShowFigures((v) => !v)} className="text-xs underline">
          {showFigures ? "Hide" : "Reveal"}
        </button>
      </div>
    </div>
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `DitherSecret: value / onReveal / onCopy` | `string / () => Promise<string> / (secret: string) => void` | – | Client-side value or lazy async backend fetch (runs an optical scan while pending, never mounts plaintext when copied while veiled, and surfaces errors inline), plus copy callback. |
| `DitherSecret: copyable / autoHideMs / hideOnBlur` | `boolean / number / boolean` | `true / 8000 / true` | Built-in Copy button (works even while veiled with emerald Bayer sweep), inherent edge-condensing auto-relock and tab-blur sealing. |
| `DitherVeil: children / revealed / defaultRevealed / onRevealedChange` | `ReactNode / boolean / boolean / (v) => void` | `false` | Inline primitive for figures and text inside <h1>, <p> and <td> with controlled or uncontrolled reveal state. |
| `DitherVeil: fill / peek / peekRadius / pending` | `boolean / boolean / number / boolean` | `false / true / 34 / false` | Full-viewport pane mode (used inside DitherSecret), magnetic circular cursor peek lens and pending optical scan state. |
| `tone / cellSize / label / sound` | `"ink" \| "primary" \| "spectral" / number / string / boolean` | `"ink" / 1.5 / – / false` | Active rim palette (resting veil stays refined neutral ink), Bayer grain pitch in CSS px, accessible name and opt-in Web Audio cues. |

## States

- **veiled**: A layered multi-tonal 1.5px 8×8 Bayer halftone flows softly across 100% of the viewport while masking underlying characters completely out (zero silhouette bleed and zero token-length leak).
- **fetching (pending)**: While async onReveal() is in flight, a crisp horizontal optical scan sweeps edge-to-edge through the Bayer grain until the secret arrives.
- **magnetic peek**: When client-side text is present, moving a pointer over the veil springs open a circular lens right under the cursor while compressed Bayer dots rim its edge; when plaintext is still server-side, hovering creates a tactile ferrofluid shimmer.
- **revealed**: A directional Bayer shutter sweeps cleanly from your click point and clears the canvas completely so text reads in 100% unobstructed, uniformly styled, selectable ink.
- **copy flash**: Clicking Copy (whether veiled or revealed) sweeps an emerald 8×8 Bayer wavefront edge-to-edge across the field while the icon swaps cleanly to a check.
- **inherent re-condensation**: In the final ~2.2s of autoHideMs, fine Bayer frost nucleates organically inward from both outer edges of the viewport before locking shut; hovering back over the secret pushes the frost out and resets the hold window.
- **reduced motion**: No shimmer, peek loop, sweep or condensation: reveals and re-veils cleanly in place while keeping autoHideMs timers intact.

## What it handles

In real production settings, secrets need more than a blur class: the field should conceal the full value and length, copy without exposing it on a call, fetch plaintext only on explicit action, and re-seal cleanly without gimmicky progress bars.

- **Full-viewport optical veil**: DitherSecret spans a single 1.5px 8×8 Bayer pane edge-to-edge across the entire secret slot up to a 1px hairline divider, avoiding half-masked patches and concealing token length.
- **Lazy on-demand secret fetch**: Pass onReveal: () => Promise<string> so plaintext is fetched only when revealed or copied, running a full-width optical Bayer scan while pending and dropping plaintext on re-seal.
- **Zero-DOM copy while veiled**: Pressing Copy while veiled fetches straight to the clipboard without mounting plaintext into React state or the DOM, confirming with an edge-to-edge emerald Bayer sweep.
- **Inherent edge-condensing auto-lock**: No cheap progress bar: revealed text stays 100% unobstructed, then delicate Bayer frost condenses softly inward from both outer walls before locking shut. Hovering dissolves it back out.
- **Magnetic pointer peek**: When client-side values are veiled, scrubbing a pointer parts a crisp circular lens through the Bayer grain with zero silhouette bleed; drag-selecting revealed text never accidentally re-veils.
- **Zero layout shift and blur safety**: DitherVeil renders strictly as <span> + <canvas> inside <h1>, <p> and <td>; Escape and optional hideOnBlur re-seal immediately.

## Replaces

API key secret field, privacy blur mask, bullet dot redaction, balance hide toggle, copy-secret input, framer-motion

## Where it fits

- **API keys and webhook secrets**: Use DitherSecret with async onReveal() and Copy-while-veiled so plaintext never sits in SSR HTML or leaks token length.
- **Banking and wallet balances**: Wrap figures in inline DitherVeil inside headings or tables with zero layout shift and magnetic cursor peek.
- **Virtual cards and recovery codes**: Scrub a magnetic lens across the full-viewport Bayer pane to peek digits, copy cleanly with an emerald flash and re-seal on tab blur.
- **Dashboard screen-share mode**: Drive multiple DitherVeil figures together from a single header Reveal / Hide toggle.

## Notes

- DitherSecret covers 100% of its value viewport edge-to-edge up to the hairline divider so neither character shapes nor secret length leak while veiled.
- When DitherSecret fetches lazily via onReveal(), copying while veiled writes straight to the clipboard without putting plaintext into React state or DOM, and revealing drops plaintext after re-sealing.
- When revealed, the canvas clears completely so text reads in 100% crisp unobstructed ink; drag-selecting revealed text will not accidentally re-veil the field.
- Auto-relock uses inherent Bayer edge-condensation from both viewport edges instead of a progress bar; moving the pointer back over the secret dissolves the condensing frost and holds the value open.
- Under prefers-reduced-motion: reduce, the canvas loop stops and states switch cleanly in place while autoHideMs timers still protect the value.

License: MIT (https://hairlineui.com/license#components)
