{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "corridor-carousel",
  "type": "registry:ui",
  "title": "Corridor Carousel",
  "description": "A gallery you fly down instead of scroll through: four walls - left, right, ceiling and floor - papered with the same run of pictures, drifting out of the vanishing point and past your head. Wheel, drag or arrow keys shove it faster and it coasts back to its drift. Pure CSS 3D on one moving transform, with depth fog painted in the page background, so the corridor never re-renders while it runs.",
  "files": [
    {
      "path": "registry/crafterui/ui/corridor-carousel.tsx",
      "type": "registry:ui",
      "content": "\"use client\"\n\n// A gallery you fly down instead of scroll through.\n//\n// Four walls - left, right, ceiling, floor - are papered with the same run of\n// pictures. The run drifts out of the vanishing point, swells as it reaches you\n// and slips off the edges of the frame. Wheel, drag or arrow keys shove it\n// faster; let go and it coasts back down to its drift.\n//\n// Nothing here is virtualised and nothing re-renders while it moves. Each wall\n// carries one cycle of pictures MORE than the depth it has to cover, which\n// makes the corridor periodic: travel exactly one cycle and the frame is, pixel\n// for pixel, the one you started on. So the animation never recycles a panel -\n// it advances one number, wraps it at the cycle length, and writes a single\n// transform to the one element every panel hangs off. The panels themselves get\n// static transforms the compositor is handed once.\n//\n// The camera is the section's own `perspective`, so the walls meet the frame's\n// edges exactly at the near plane and converge from there - the corridor is\n// always as wide as its container, at any size, with nothing to tune.\n//\n// Depth fog is one overlay: a radial wash of the page background centred on the\n// vanishing point, sized off the corridor's own far cross-section. It hides the\n// end of the run and does the shading that a per-panel filter would otherwise\n// cost a repaint a frame.\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport interface CorridorCarouselItem {\n  /** Art hung on the wall. Any src an <img> takes. */\n  image: string\n  /** Printed on the frame's label strip, and the picture's alt text. */\n  title?: string\n  /** Far end of the label strip - year, medium, city, whatever. */\n  meta?: string\n}\n\n/** The four planes of the corridor, in the order they are papered. */\nexport const CORRIDOR_WALLS = [\"left\", \"right\", \"ceiling\", \"floor\"] as const\n\nexport type CorridorWall = (typeof CORRIDOR_WALLS)[number]\n\nexport interface CorridorCarouselProps\n  extends Omit<React.ComponentPropsWithoutRef<\"section\">, \"children\"> {\n  /**\n   * Pictures, in the order they are hung. The run repeats down the corridor and\n   * around all four walls. A dozen or so is what a corridor holds; a longer run\n   * is trimmed to what its depth leaves room for.\n   */\n  items: CorridorCarouselItem[]\n  /** Which planes are papered. @default [\"left\",\"right\",\"ceiling\",\"floor\"] */\n  walls?: readonly CorridorWall[]\n  /** `out` brings the run toward you out of the vanishing point. @default \"out\" */\n  flow?: \"out\" | \"in\"\n  /** Drift, in corridor widths per second. @default 0.2 */\n  speed?: number\n  /** Depth of one frame, in corridor widths. @default 0.46 */\n  tile?: number\n  /** How far down the corridor is dressed, in corridor widths. @default 3.2 */\n  depth?: number\n  /** Seam between neighbouring frames, in corridor widths. @default 0.02 */\n  gap?: number\n  /** Camera distance, in corridor widths. Smaller is a wider lens. @default 0.82 */\n  lens?: number\n  /** How far the vanishing point follows the pointer, 0 to 1. @default 0.4 */\n  sway?: number\n  /** Wheel, drag and arrow keys drive the corridor. @default true */\n  scrub?: boolean\n  /** Print each picture's title and meta on its frame. @default true */\n  labels?: boolean\n  /** Extra classes on the corridor surface. @default undefined */\n  className?: string\n}\n\n/* Panels per wall. The corridor has to carry one whole cycle of pictures MORE\n   than the depth it shows - that surplus is what makes the wrap seamless - so\n   this budget is what caps the run. Depth is served first and the cycle takes\n   what is left, because a corridor with no distance to it is not a corridor.\n   Four walls of 26 is already 104 layers for the compositor. */\nconst MAX_SLOTS = 26\n\nconst DRAG = 2.2 // corridor widths travelled per width dragged\nconst FLICK = 0.45 // ... and how much of a drag's speed carries on after release\nconst WHEEL = 0.02 // widths per second added per pixel of wheel\nconst KEY = 1.4 // ... per arrow press\nconst DECAY = 3.4 // e-folds per second a shove dies away over\nconst MAX_PUSH = 7 // widths per second, however hard it is shoved\nconst SWAY_EASE = 5 // e-folds per second the vanishing point chases the pointer\n\nconst clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v))\n\nexport function CorridorCarousel({\n  items,\n  walls = CORRIDOR_WALLS,\n  flow = \"out\",\n  speed = 0.2,\n  tile = 0.46,\n  depth = 3.2,\n  gap = 0.02,\n  lens = 0.82,\n  sway = 0.4,\n  scrub = true,\n  labels = true,\n  className,\n  style,\n  ...props\n}: CorridorCarouselProps) {\n  const rootRef = React.useRef<HTMLElement | null>(null)\n  const trackRef = React.useRef<HTMLDivElement | null>(null)\n  const hazeRef = React.useRef<HTMLDivElement | null>(null)\n\n  // Everything is measured against the container, never the viewport: the\n  // corridor is the same corridor in a page column and full bleed.\n  const [size, setSize] = React.useState({ w: 0, h: 0 })\n  React.useEffect(() => {\n    const el = rootRef.current\n    if (!el) return\n    const observer = new ResizeObserver(([entry]) => {\n      const { width, height } = entry.contentRect\n      setSize((prev) =>\n        prev.w === width && prev.h === height ? prev : { w: width, h: height }\n      )\n    })\n    observer.observe(el)\n    return () => observer.disconnect()\n  }, [])\n\n  const stage = React.useMemo(() => {\n    const w = size.w\n    const h = size.h\n    const TILE = tile * w\n    const GAP = gap * w\n    // Slots of dressed depth, then the cycle of pictures that repeats through\n    // them. The cycle is what the wrap is measured in, so it has to fit inside\n    // the panel budget alongside the depth.\n    const reach = Math.max(2, Math.ceil(depth / tile))\n    const cycle = Math.max(1, Math.min(items.length, MAX_SLOTS - reach - 2))\n    const slots = Math.min(MAX_SLOTS, cycle + reach + 2)\n\n    // Half-width of the corridor where the run runs out, projected - measured\n    // off the slots actually hung, not the depth asked for, since the wrap\n    // leaves the far end a cycle shallower at its worst. The fog is opaque out\n    // to there and clear again long before the near frames reach it.\n    const vanish = (0.5 * lens) / (lens + reach * tile)\n    const haze = Math.max(vanish * 3.2, 0.22) * w\n    const solid = haze > 0 ? Math.round((vanish * 1.02 * w * 100) / haze) : 0\n    const fog =\n      `radial-gradient(circle ${haze.toFixed(1)}px at var(--corridor-x, 50%) var(--corridor-y, 50%),` +\n      ` var(--background) 0%, var(--background) ${solid}%, transparent 100%)`\n\n    const face = {\n      left: {\n        width: TILE - GAP,\n        height: h - GAP,\n        at: (z: number) => `translate3d(${-w / 2}px, 0px, ${z}px) rotateY(90deg)`,\n      },\n      right: {\n        width: TILE - GAP,\n        height: h - GAP,\n        at: (z: number) => `translate3d(${w / 2}px, 0px, ${z}px) rotateY(-90deg)`,\n      },\n      ceiling: {\n        width: w - GAP,\n        height: TILE - GAP,\n        at: (z: number) => `translate3d(0px, ${-h / 2}px, ${z}px) rotateX(-90deg)`,\n      },\n      floor: {\n        width: w - GAP,\n        height: TILE - GAP,\n        at: (z: number) => `translate3d(0px, ${h / 2}px, ${z}px) rotateX(90deg)`,\n      },\n    } as const\n\n    const panels: {\n      key: string\n      item: CorridorCarouselItem\n      lead: boolean\n      style: React.CSSProperties\n    }[] = []\n\n    if (w > 0 && h > 0 && items.length > 0) {\n      walls.forEach((wall, index) => {\n        // Opposite walls neither line up nor show the same picture, or the\n        // corridor reads as one image in a mirror box. Both offsets are\n        // constant per wall, so the run stays periodic.\n        const phase = (index / walls.length) * TILE\n        const shift = Math.round((index * cycle) / walls.length)\n        const plane = face[wall]\n        // Counting from -1 hangs one frame in FRONT of the corridor mouth. A\n        // wall whose phase has pushed its first frame back off the near plane\n        // would otherwise be bare there at low travel and dressed at high, and\n        // that difference - a band of background sliding in along one edge - is\n        // the one thing that would give the wrap away.\n        for (let k = -1; k < slots - 1; k++) {\n          panels.push({\n            key: `${wall}-${k}`,\n            item: items[(((k + shift) % cycle) + cycle) % cycle],\n            // One wall's first cycle carries the alt text; the rest of the\n            // corridor is the same pictures again, and is hidden from readers.\n            lead: index === 0 && k >= 0 && k < cycle,\n            style: {\n              width: `${plane.width}px`,\n              height: `${plane.height}px`,\n              transform: plane.at(-k * TILE - phase),\n            },\n          })\n        }\n      })\n    }\n\n    return {\n      w,\n      panels,\n      fog,\n      /** Travel that returns the corridor to the frame it started on. */\n      period: cycle * tile,\n      perspective: Math.max(1, lens * w),\n      // Type is set on the frame, so it recedes with the picture it labels.\n      fontSize: Math.max(8, TILE * 0.085),\n    }\n  }, [size.w, size.h, items, walls, tile, depth, gap, lens])\n\n  // Read by the frame loop, which is mounted once and never re-subscribed. Set\n  // after the commit rather than during the render, so a render React throws\n  // away cannot leave the loop running on props that never reached the DOM.\n  const view = React.useRef({ speed, flow, sway, w: stage.w, period: stage.period })\n  React.useEffect(() => {\n    view.current = { speed, flow, sway, w: stage.w, period: stage.period }\n  })\n\n  const run = React.useRef({\n    travel: 0, // corridor widths, wrapped at one cycle\n    push: 0, // widths per second, on top of the drift\n    nudge: 0, // widths handed over by a drag since the last frame\n    rate: 0, // ... as a speed, which is what a release throws\n    grab: 0,\n    dragging: false,\n    ox: 0,\n    oy: 0,\n    tx: 0,\n    ty: 0,\n  })\n\n  React.useEffect(() => {\n    const root = rootRef.current\n    const track = trackRef.current\n    const haze = hazeRef.current\n    if (!root || !track) return\n\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\")\n    let onscreen = true\n    let previous = 0\n    let frame = requestAnimationFrame(function tick(now) {\n      frame = requestAnimationFrame(tick)\n      const dt = previous ? Math.min(0.05, (now - previous) / 1000) : 0\n      previous = now\n      if (!onscreen) return\n\n      const v = view.current\n      const r = run.current\n      r.push = clamp(r.push * Math.exp(-DECAY * dt), -MAX_PUSH, MAX_PUSH)\n      const drift = reduce.matches ? 0 : v.speed * (v.flow === \"in\" ? -1 : 1)\n      const step = (drift + r.push) * dt + r.nudge\n      // The drag's speed, measured over the frame rather than over one pointer\n      // event: a 240Hz pointer reports a third of the movement per event that a\n      // 60Hz one does, and a finger held still reports none at all.\n      r.rate = dt > 0 ? r.nudge / dt : 0\n      r.nudge = 0\n      if (v.period > 0) {\n        r.travel = (((r.travel + step) % v.period) + v.period) % v.period\n      }\n      track.style.transform = `translate3d(0px, 0px, ${(r.travel * v.w).toFixed(2)}px)`\n\n      // The vanishing point leans toward the pointer. Written straight onto the\n      // section and onto the fog - never as an inherited custom property on the\n      // root, which would dirty the style of all ninety-odd panels under it.\n      const ease = 1 - Math.exp(-SWAY_EASE * dt)\n      r.ox += (r.tx - r.ox) * ease\n      r.oy += (r.ty - r.oy) * ease\n      const ox = `${(50 + r.ox * v.sway * 50).toFixed(2)}%`\n      const oy = `${(50 + r.oy * v.sway * 50).toFixed(2)}%`\n      root.style.perspectiveOrigin = `${ox} ${oy}`\n      if (haze) {\n        haze.style.setProperty(\"--corridor-x\", ox)\n        haze.style.setProperty(\"--corridor-y\", oy)\n      }\n    })\n\n    // Eighty-odd composited panels are not worth a frame while off screen.\n    const watcher = new IntersectionObserver(\n      ([entry]) => {\n        onscreen = entry.isIntersecting\n        previous = 0\n        if (!onscreen) run.current.push = 0\n      },\n      { threshold: 0 }\n    )\n    watcher.observe(root)\n\n    return () => {\n      cancelAnimationFrame(frame)\n      watcher.disconnect()\n    }\n  }, [])\n\n  React.useEffect(() => {\n    const el = rootRef.current\n    if (!el || !scrub) return\n    // Passive on purpose: the page keeps its scroll, and the wheel that scrolls\n    // it flies you down the corridor on the way past.\n    const onWheel = (event: WheelEvent) => {\n      const delta = event.deltaMode === 1 ? event.deltaY * 16 : event.deltaY\n      run.current.push += delta * WHEEL\n    }\n    el.addEventListener(\"wheel\", onWheel, { passive: true })\n    return () => el.removeEventListener(\"wheel\", onWheel)\n  }, [scrub])\n\n  const onPointerMove = (event: React.PointerEvent<HTMLElement>) => {\n    const r = run.current\n    const box = event.currentTarget.getBoundingClientRect()\n    r.tx = clamp(((event.clientX - box.left) / box.width - 0.5) * 2, -1, 1)\n    r.ty = clamp(((event.clientY - box.top) / box.height - 0.5) * 2, -1, 1)\n    if (!r.dragging || !stage.w) return\n    const dx = event.clientX - r.grab\n    r.grab = event.clientX\n    r.nudge += (-dx / stage.w) * DRAG\n  }\n\n  const stopDrag = (event: React.PointerEvent<HTMLElement>) => {\n    const r = run.current\n    if (!r.dragging) return\n    r.dragging = false\n    if (event.currentTarget.hasPointerCapture(event.pointerId)) {\n      event.currentTarget.releasePointerCapture(event.pointerId)\n    }\n    r.push += r.rate * FLICK\n    r.rate = 0\n  }\n\n  return (\n    <section\n      ref={rootRef}\n      aria-label=\"Picture corridor\"\n      tabIndex={scrub ? 0 : undefined}\n      className={cn(\n        \"bg-background text-foreground relative h-full min-h-[24rem] w-full touch-pan-y overflow-hidden outline-none select-none\",\n        \"focus-visible:outline-foreground focus-visible:outline-2 focus-visible:-outline-offset-4\",\n        scrub && \"cursor-grab active:cursor-grabbing\",\n        className\n      )}\n      style={{\n        perspective: `${stage.perspective}px`,\n        perspectiveOrigin: \"50% 50%\",\n        ...style,\n      }}\n      onPointerDown={(event) => {\n        if (!scrub || !event.isPrimary) return\n        event.currentTarget.setPointerCapture(event.pointerId)\n        const r = run.current\n        r.dragging = true\n        r.grab = event.clientX\n        r.push = 0\n        r.rate = 0\n      }}\n      onPointerMove={onPointerMove}\n      onPointerUp={stopDrag}\n      onPointerCancel={stopDrag}\n      onPointerLeave={(event) => {\n        stopDrag(event)\n        run.current.tx = 0\n        run.current.ty = 0\n      }}\n      onKeyDown={(event) => {\n        if (!scrub) return\n        const back = event.key === \"ArrowLeft\" || event.key === \"ArrowUp\"\n        const on = event.key === \"ArrowRight\" || event.key === \"ArrowDown\"\n        if (!back && !on) return\n        event.preventDefault()\n        run.current.push += on ? KEY : -KEY\n      }}\n      {...props}\n    >\n      {/* The one moving element. Every panel hangs off it with a static\n          transform, so a frame costs one matrix, not eighty-eight. */}\n      <div\n        ref={trackRef}\n        className=\"absolute inset-0 [transform-style:preserve-3d] [will-change:transform]\"\n      >\n        {stage.panels.map((panel) => (\n          <figure\n            key={panel.key}\n            aria-hidden={!panel.lead}\n            className=\"bg-muted absolute inset-0 m-auto overflow-hidden\"\n            style={{ ...panel.style, fontSize: `${stage.fontSize}px` }}\n          >\n            <img\n              src={panel.item.image}\n              alt={panel.lead ? (panel.item.title ?? \"\") : \"\"}\n              draggable={false}\n              decoding=\"async\"\n              className=\"size-full object-cover\"\n            />\n            {labels && (panel.item.title || panel.item.meta) ? (\n              <figcaption className=\"bg-background/85 absolute inset-x-0 bottom-0 flex items-baseline justify-between gap-[0.7em] px-[0.9em] py-[0.55em]\">\n                <span className=\"truncate font-medium tracking-tight\">\n                  {panel.item.title}\n                </span>\n                {panel.item.meta ? (\n                  <span className=\"text-muted-foreground shrink-0 tabular-nums\">\n                    {panel.item.meta}\n                  </span>\n                ) : null}\n              </figcaption>\n            ) : null}\n          </figure>\n        ))}\n      </div>\n\n      {/* Depth fog. Painted over the corridor rather than into it: the walls\n          never cross the axis, so the only thing under the wash is distance. */}\n      <div\n        ref={hazeRef}\n        aria-hidden=\"true\"\n        className=\"pointer-events-none absolute inset-0\"\n        style={{ background: stage.fog }}\n      />\n    </section>\n  )\n}\n"
    }
  ]
}
