# Blueprint Reveal
*URL: https://www.grettech.com/components/blueprint-reveal*

A design blueprint that draws itself, then wipes into the finished UI on hover, scroll or click. Tells the story from wireframe to product.

- Wireframe draws itself when scrolled into view
- Reveals any content you pass as children, with a scan-line wipe
- Hover, in-view or click triggers, or fully controlled
- Blue, ink and paper tones; respects reduced motion

## Install with the shadcn CLI
```bash
npx shadcn@latest add https://www.grettech.com/api/registry/blueprint-reveal
```
With its demo: `npx shadcn@latest add https://www.grettech.com/api/registry/blueprint-reveal-demo`

**Dependencies:** npm: clsx, tailwind-merge, class-variance-authority

## Manual installation
**Step 1: Install dependencies**
Install the packages this component uses and the shadcn/ui components it builds on. It also needs the `cn` helper in `lib/utils.ts`, which `npx shadcn@latest init` adds.

```bash
npm install clsx tailwind-merge class-variance-authority
```

**Step 2: Copy the source code**
Add these files to your project components directory.

File: `components/ui/blueprint-reveal.tsx`
```tsx
"use client"

import { cn } from "@/lib/utils"
import { cva, type VariantProps } from "class-variance-authority"
import * as React from "react"

export interface BlueprintRegion {
  /** Position and size in % of the frame */
  x: number
  y: number
  w: number
  h: number
  /** How the wireframe draws it */
  kind?: "block" | "text" | "image" | "button"
  /** Annotation shown at its top-left, e.g. "Hero / H1" */
  label?: string
}

const blueprintVariants = cva(
  "group/blueprint relative isolate w-full overflow-hidden rounded-xl border focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:outline-none",
  {
    variants: {
      tone: {
        blue: "border-[#1e4c8f] bg-[#0b2f66] text-white [--bp-grid-major:rgba(255,255,255,0.16)] [--bp-grid:rgba(255,255,255,0.08)]",
        ink: "border-neutral-800 bg-neutral-950 text-white [--bp-grid-major:rgba(255,255,255,0.12)] [--bp-grid:rgba(255,255,255,0.06)]",
        paper:
          "border-neutral-200 bg-[#f7f6f2] text-neutral-700 [--bp-grid-major:rgba(0,0,0,0.1)] [--bp-grid:rgba(0,0,0,0.05)]",
      },
    },
    defaultVariants: { tone: "blue" },
  }
)

export interface BlueprintRevealProps
  extends
    Omit<React.HTMLAttributes<HTMLDivElement>, "children">,
    VariantProps<typeof blueprintVariants> {
  /** The finished UI revealed over the blueprint */
  children: React.ReactNode
  /** Layout drawn as the wireframe; match it to the finished UI */
  regions?: BlueprintRegion[]
  /** What reveals the finished UI */
  trigger?: "hover" | "inView" | "click"
  /** Controlled state: true shows the finished UI */
  revealed?: boolean
  onRevealedChange?: (revealed: boolean) => void
  /** CSS aspect ratio of the frame */
  aspectRatio?: string
  /** Size note on the top ruler, e.g. "1440 × 900" */
  dimensions?: string
  /** Accessible name of the frame */
  label?: string
}

export const DEFAULT_REGIONS: BlueprintRegion[] = [
  { x: 0, y: 0, w: 100, h: 10, kind: "block", label: "Nav" },
  { x: 6, y: 20, w: 42, h: 9, kind: "text", label: "H1" },
  { x: 6, y: 32, w: 36, h: 7, kind: "text" },
  { x: 6, y: 44, w: 15, h: 7, kind: "button", label: "CTA" },
  { x: 54, y: 18, w: 40, h: 40, kind: "image", label: "Hero image" },
  { x: 6, y: 66, w: 27, h: 26, kind: "block", label: "Card" },
  { x: 37, y: 66, w: 27, h: 26, kind: "block" },
  { x: 68, y: 66, w: 26, h: 26, kind: "block" },
]

/** "16 / 10" → 1.6 */
function ratioOf(aspectRatio: string) {
  const [a, b = 1] = aspectRatio.split("/").map((n) => parseFloat(n))
  return a > 0 && b > 0 ? a / b : 1.6
}

/**
 * One wireframe shape. pathLength 1 lets every stroke draw at the same pace.
 * The SVG has the frame's proportions (100 high, 100 × ratio wide) so strokes
 * stay even; non-scaling-stroke would break pathLength in Chrome.
 */
function Shape({
  r,
  delay,
  sx,
}: {
  r: BlueprintRegion
  delay: number
  sx: number
}) {
  const common = {
    pathLength: 1,
    strokeWidth: 0.3,
    className:
      "fill-none stroke-current [stroke-dasharray:1] [stroke-dashoffset:1] transition-[stroke-dashoffset] duration-[1200ms] ease-out group-data-[drawn=true]/blueprint:[stroke-dashoffset:0] motion-reduce:[stroke-dashoffset:0] motion-reduce:transition-none",
    style: { transitionDelay: `${delay}ms` },
  }
  const { y, h } = r
  const x = r.x * sx
  const w = r.w * sx
  const kind = r.kind ?? "block"
  return (
    <g>
      <rect
        x={x}
        y={y}
        width={w}
        height={h}
        rx={kind === "button" ? 1.5 : 0.6}
        {...common}
      />
      {kind === "image" && (
        <>
          <line x1={x} y1={y} x2={x + w} y2={y + h} {...common} />
          <line x1={x + w} y1={y} x2={x} y2={y + h} {...common} />
        </>
      )}
      {kind === "text" &&
        [0.35, 0.65].map((f) => (
          <line
            key={f}
            x1={x + 1.5}
            y1={y + h * f}
            x2={x + w * (f < 0.5 ? 0.9 : 0.6)}
            y2={y + h * f}
            {...common}
          />
        ))}
    </g>
  )
}

export const BlueprintReveal = React.forwardRef<
  HTMLDivElement,
  BlueprintRevealProps
>(
  (
    {
      children,
      regions = DEFAULT_REGIONS,
      trigger = "hover",
      revealed: controlledRevealed,
      onRevealedChange,
      aspectRatio = "16 / 10",
      dimensions = "1440 × 900",
      label = "Design blueprint. Reveal to see the finished page.",
      tone,
      className,
      style,
      ...props
    },
    forwardedRef
  ) => {
    const ratio = ratioOf(aspectRatio)
    const ref = React.useRef<HTMLDivElement>(null)
    React.useImperativeHandle(forwardedRef, () => ref.current!)
    const [drawn, setDrawn] = React.useState(false)
    const [internalRevealed, setInternalRevealed] = React.useState(false)
    const revealed = controlledRevealed ?? internalRevealed
    const setRevealed = React.useCallback(
      (next: boolean) => {
        setInternalRevealed(next)
        onRevealedChange?.(next)
      },
      [onRevealedChange]
    )

    // Draw the wireframe once it scrolls into view; "inView" then reveals
    React.useEffect(() => {
      const el = ref.current
      if (!el) return
      let timer: ReturnType<typeof setTimeout>
      const io = new IntersectionObserver(
        ([entry]) => {
          if (!entry.isIntersecting) return
          setDrawn(true)
          if (trigger === "inView") {
            timer = setTimeout(() => setRevealed(true), 1600)
          }
          io.disconnect()
        },
        { threshold: 0.5 }
      )
      io.observe(el)
      return () => {
        io.disconnect()
        clearTimeout(timer)
      }
    }, [trigger, setRevealed])

    // Sweep the scan line along the wipe, fading in and out at the ends
    const scanRef = React.useRef<HTMLDivElement>(null)
    const firstRender = React.useRef(true)
    React.useEffect(() => {
      if (firstRender.current) {
        firstRender.current = false
        return
      }
      const line = scanRef.current
      if (
        !line?.animate ||
        window.matchMedia("(prefers-reduced-motion: reduce)").matches
      )
        return
      const [from, to] = revealed ? ["0%", "100%"] : ["100%", "0%"]
      const animation = line.animate(
        [
          { left: from, opacity: 0 },
          { opacity: 1, offset: 0.1 },
          { opacity: 1, offset: 0.85 },
          { left: to, opacity: 0 },
        ],
        { duration: 900, easing: "cubic-bezier(0.65, 0, 0.35, 1)" }
      )
      return () => animation.cancel()
    }, [revealed])

    const hoverProps =
      trigger === "hover"
        ? {
            tabIndex: 0,
            onPointerEnter: () => setRevealed(true),
            onPointerLeave: () => setRevealed(false),
            onFocus: () => setRevealed(true),
            onBlur: () => setRevealed(false),
          }
        : {}

    return (
      <div
        ref={ref}
        role="group"
        aria-label={label}
        data-drawn={drawn}
        data-revealed={revealed}
        className={cn(blueprintVariants({ tone }), className)}
        style={{ aspectRatio, ...style }}
        {...hoverProps}
        {...props}
      >
        {/* Blueprint grid: minor lines every 4%, major every 20% */}
        <div
          aria-hidden="true"
          className="absolute inset-0 -z-10"
          style={{
            backgroundImage:
              "linear-gradient(var(--bp-grid-major) 1px, transparent 1px), linear-gradient(90deg, var(--bp-grid-major) 1px, transparent 1px), linear-gradient(var(--bp-grid) 1px, transparent 1px), linear-gradient(90deg, var(--bp-grid) 1px, transparent 1px)",
            backgroundSize: "20% 20%, 20% 20%, 4% 4%, 4% 4%",
          }}
        />

        <svg
          aria-hidden="true"
          viewBox={`0 0 ${100 * ratio} 100`}
          preserveAspectRatio="none"
          className="absolute inset-[4%] h-[92%] w-[92%] overflow-visible opacity-80"
        >
          {regions.map((r, i) => (
            <Shape key={i} r={r} delay={i * 120} sx={ratio} />
          ))}
        </svg>

        {/* Annotations sit in the same 4% inset as the drawing */}
        <div
          aria-hidden="true"
          className="pointer-events-none absolute inset-[4%] font-mono text-[9px] tracking-wide uppercase opacity-0 transition-opacity delay-700 duration-500 group-data-[drawn=true]/blueprint:opacity-70 motion-reduce:opacity-70"
        >
          {regions.map(
            (r, i) =>
              r.label && (
                <span
                  key={i}
                  className="absolute -translate-y-full pb-0.5"
                  style={{ left: `${r.x}%`, top: `${r.y}%` }}
                >
                  {r.label}
                </span>
              )
          )}
          {dimensions && (
            <span className="absolute -top-[3.2%] left-1/2 -translate-x-1/2 px-1">
              {dimensions}
            </span>
          )}
        </div>

        {/* Finished UI, wiped in from the left */}
        <div
          className="absolute inset-0 bg-background text-foreground transition-[clip-path] duration-[900ms] ease-[cubic-bezier(0.65,0,0.35,1)] [clip-path:inset(0_100%_0_0)] group-data-[revealed=true]/blueprint:[clip-path:inset(0_0_0_0)] motion-reduce:transition-none"
          aria-hidden={!revealed}
        >
          {children}
        </div>

        {/* Scan line riding the wipe's edge */}
        <div
          aria-hidden="true"
          ref={scanRef}
          className="pointer-events-none absolute inset-y-0 left-0 w-px bg-white opacity-0 shadow-[0_0_12px_2px_rgba(125,211,252,0.8)]"
        />

        {trigger === "click" && (
          <button
            type="button"
            aria-pressed={revealed}
            onClick={() => setRevealed(!revealed)}
            className="absolute right-3 bottom-3 z-10 rounded-full border border-white/20 bg-black/60 px-3 py-1 text-xs font-medium text-white backdrop-blur transition-colors hover:bg-black/80 focus-visible:ring-2 focus-visible:ring-white focus-visible:outline-none"
          >
            {revealed ? "Show blueprint" : "Show finished"}
          </button>
        )}
      </div>
    )
  }
)
BlueprintReveal.displayName = "BlueprintReveal"

```

**Step 3: Framework Adjustments (Optional)**
If you are manually copying this code into a Vite or Remix project (without using the CLI), make sure to remove the `"use client";` directive from the very top of the file.

## Props
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| `children` | `React.ReactNode` | - | Yes | The finished UI shown over the blueprint. Any content works: a screenshot, a mock or a real component. |
| `regions` | `BlueprintRegion[]` | `DEFAULT_REGIONS (nav, hero text, CTA, image, three cards)` | No | Layout drawn as the wireframe, in % of the frame. Match it to the finished UI. |
| `regions.x` | `number` | - | Yes | Left edge, 0–100. |
| `regions.y` | `number` | - | Yes | Top edge, 0–100. |
| `regions.w` | `number` | - | Yes | Width, 0–100. |
| `regions.h` | `number` | - | Yes | Height, 0–100. |
| `regions.kind` | `"block" \| "text" \| "image" \| "button"` | `"block"` | No | How the region is drawn: a box, lines of text, a crossed image or a rounded button. |
| `regions.label` | `string` | - | No | Annotation at its top-left, e.g. "H1". |
| `trigger` | `"hover" \| "inView" \| "click"` | `"hover"` | No | What reveals the finished UI. Hover also reveals on keyboard focus; click adds a toggle button. |
| `revealed` | `boolean` | - | No | Controlled state: true shows the finished UI. |
| `onRevealedChange` | `(revealed: boolean) => void` | - | No | Called when the state changes. |
| `tone` | `"blue" \| "ink" \| "paper"` | `"blue"` | No | Blueprint colours. |
| `aspectRatio` | `string` | `"16 / 10"` | No | CSS aspect ratio of the frame. |
| `dimensions` | `string` | `"1440 × 900"` | No | Size note on the top ruler. Pass an empty string to hide it. |
| `label` | `string` | `"Design blueprint. Reveal to see the finished page."` | No | Accessible name of the frame. |
| `className` | `string` | - | No | Extra classes for the frame. |
| `...props` | `React.HTMLAttributes<HTMLDivElement>` | - | No | Any other attributes, passed to the frame. |

## Usage
```tsx
"use client"

import {
  BlueprintReveal,
  DEFAULT_REGIONS,
  type BlueprintRegion,
} from "@/components/ui/blueprint-reveal"

/** The finished page, built from the same regions as the blueprint */
function FinishedRegion({ r }: { r: BlueprintRegion }) {
  const style = {
    left: `${4 + r.x * 0.92}%`,
    top: `${4 + r.y * 0.92}%`,
    width: `${r.w * 0.92}%`,
    height: `${r.h * 0.92}%`,
  }
  switch (r.kind) {
    case "text":
      return (
        <div
          style={style}
          className="absolute flex flex-col justify-center gap-1"
        >
          <div className="h-[35%] w-[90%] rounded-sm bg-neutral-900 dark:bg-neutral-100" />
          <div className="h-[25%] w-[60%] rounded-sm bg-neutral-300 dark:bg-neutral-600" />
        </div>
      )
    case "button":
      return (
        <div
          style={style}
          className="absolute rounded-md bg-neutral-900 shadow-sm dark:bg-white"
        />
      )
    case "image":
      return (
        <div
          style={style}
          className="absolute rounded-lg bg-linear-to-br from-sky-400 via-indigo-500 to-fuchsia-500"
        />
      )
    default:
      return r.y === 0 ? (
        <div
          style={{ ...style, left: 0, top: 0, width: "100%", height: "10%" }}
          className="absolute flex items-center gap-[2%] border-b px-[4%]"
        >
          <div className="h-[30%] w-[10%] rounded-sm bg-neutral-900 dark:bg-neutral-100" />
          <div className="ml-auto h-[20%] w-[30%] rounded-sm bg-neutral-200 dark:bg-neutral-700" />
        </div>
      ) : (
        <div
          style={style}
          className="absolute rounded-lg border bg-neutral-50 p-[3%] dark:bg-neutral-900"
        >
          <div className="size-[18%] rounded-md bg-indigo-500/80" />
          <div className="mt-[8%] h-[10%] w-[70%] rounded-sm bg-neutral-300 dark:bg-neutral-600" />
        </div>
      )
  }
}

export default function BlueprintRevealDemo() {
  return (
    <div className="w-full max-w-2xl p-4">
      <BlueprintReveal regions={DEFAULT_REGIONS}>
        {DEFAULT_REGIONS.map((r, i) => (
          <FinishedRegion key={i} r={r} />
        ))}
      </BlueprintReveal>
      <p className="mt-3 text-center text-xs text-muted-foreground">
        Hover or focus to see the finished page
      </p>
    </div>
  )
}

```
