{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "hero-carousel",
  "type": "registry:ui",
  "title": "Hero Carousel",
  "description": "A full-bleed editorial hero driven by a filmstrip: cards share one top edge, the focused card unfurls to full height while its neighbours stay clipped to half, and the whole background re-grades to the focused photo. Wheel, drag, click and arrow keys.",
  "dependencies": [
    "motion"
  ],
  "files": [
    {
      "path": "registry/crafterui/ui/hero-carousel.tsx",
      "type": "registry:ui",
      "content": "\"use client\"\n\n// A full-bleed editorial hero driven by a filmstrip.\n//\n// Every card shares one top edge. The focused card unfurls to full height while\n// its neighbours stay clipped to half, so the strip reads as a row of cropped\n// heads with one complete portrait standing in the middle of it. Changing the\n// focus re-grades the whole background to that image.\n//\n// Geometry is measured, never hard-coded: one ResizeObserver reads the stage and\n// every size below is a ratio of it, so the same component is pixel-identical in\n// a 600px preview box and on a 4K display.\nimport * as React from \"react\"\nimport {\n  AnimatePresence,\n  animate,\n  motion,\n  useMotionValue,\n  useReducedMotion,\n} from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport interface HeroCarouselItem {\n  /** Stable key; falls back to the index. @default undefined */\n  id?: string | number\n  /** Headline for the active slide. Newlines become separate reveal lines. */\n  title: string\n  /** Image URL, used both in the card and as the graded background. */\n  image: string\n  /** Byline printed beside the headline, e.g. \"BY AURELIA STUDIO.\" @default undefined */\n  credit?: string\n  /** Right-aligned facts, e.g. [\"SAT NOV 15\", \"5-10 PM\", \"MIAMI\"]. @default undefined */\n  meta?: string[]\n  /**\n   * CSS colour the background is graded to. The photo keeps its luminance and\n   * takes this hue, which is what makes the backdrop swing on every change.\n   * @default \"#8a8a8a\"\n   */\n  accent?: string\n}\n\nexport interface HeroCarouselProps {\n  /** Slides, in strip order. */\n  items: HeroCarouselItem[]\n  /** Focused slide when controlled. Leave unset for internal state. @default undefined */\n  index?: number\n  /** Focused slide on mount when uncontrolled. @default 0 */\n  defaultIndex?: number\n  /** Fires on every focus change, from any input. @default undefined */\n  onIndexChange?: (index: number) => void\n  /** Wordmark in the middle of the top bar. @default undefined */\n  brand?: React.ReactNode\n  /** Renders the \"Back\" control when provided. @default undefined */\n  onBack?: () => void\n  /** Renders the \"Menu\" control when provided. @default undefined */\n  onMenu?: () => void\n  /** Advance on a timer. Pauses on hover, drag and focus. @default false */\n  autoplay?: boolean\n  /** Milliseconds between autoplay steps. @default 4000 */\n  autoplayDelay?: number\n  /** Extra classes for the stage. @default undefined */\n  className?: string\n}\n\n/* Ratios lifted from the reference layout, all relative to the stage box. */\nconst CARD_H = 0.264 // active card height ÷ stage height\nconst CARD_AR = 0.75 // active card is 3:4\nconst GAP = 0.038 // gap ÷ card width\nconst STRIP_TOP = 0.5 // strip's shared top edge, down the stage\nconst TITLE = 0.067 // headline cap size ÷ stage height\nconst LABEL = 0.0103 // small mono label ÷ stage height\nconst PAD = 0.017 // page gutter ÷ stage width\nconst RAIL = 0.2 // progress rail width ÷ stage width\n\n/** Wheel distance that commits to a step, and the lockout after one. */\nconst WHEEL_THRESHOLD = 60\nconst WHEEL_COOLDOWN = 420\n\n/* Film grain, as a self-contained SVG so the component carries no assets. */\nconst GRAIN =\n  \"url(\\\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.82' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E\\\")\"\n\nconst clamp = (n: number, min: number, max: number) =>\n  Math.min(max, Math.max(min, n))\n\nexport function HeroCarousel({\n  items,\n  index: controlled,\n  defaultIndex = 0,\n  onIndexChange,\n  brand,\n  onBack,\n  onMenu,\n  autoplay = false,\n  autoplayDelay = 4000,\n  className,\n}: HeroCarouselProps) {\n  const stageRef = React.useRef<HTMLDivElement>(null)\n  const [box, setBox] = React.useState({ w: 0, h: 0 })\n  const [uncontrolled, setUncontrolled] = React.useState(defaultIndex)\n  const [dragging, setDragging] = React.useState(false)\n  const [paused, setPaused] = React.useState(false)\n  const reduced = useReducedMotion()\n\n  const last = items.length - 1\n  const index = clamp(controlled ?? uncontrolled, 0, Math.max(0, last))\n\n  const go = React.useCallback(\n    (next: number) => {\n      const clamped = clamp(next, 0, Math.max(0, last))\n      if (controlled === undefined) setUncontrolled(clamped)\n      if (clamped !== index) onIndexChange?.(clamped)\n    },\n    [controlled, index, last, onIndexChange]\n  )\n\n  // One observer feeds every measurement below.\n  React.useEffect(() => {\n    const stage = stageRef.current\n    if (!stage) return\n    const read = () =>\n      setBox({ w: stage.clientWidth, h: stage.clientHeight })\n    read()\n    const ro = new ResizeObserver(read)\n    ro.observe(stage)\n    return () => ro.disconnect()\n  }, [])\n\n  const fullH = clamp(box.h * CARD_H, 96, 360)\n  const halfH = fullH / 2\n  const cardW = fullH * CARD_AR\n  const gap = Math.max(4, Math.round(cardW * GAP))\n  const step = cardW + gap\n  const pad = Math.max(16, Math.round(box.w * PAD))\n  const label = Math.max(9, Math.round(box.h * LABEL))\n\n  // Centre the focused card: the track slides, the card never moves itself.\n  const xFor = React.useCallback(\n    (i: number) => box.w / 2 - (i * step + cardW / 2),\n    [box.w, step, cardW]\n  )\n  const x = useMotionValue(0)\n  const target = xFor(index)\n\n  const swing = reduced\n    ? { duration: 0 }\n    : { duration: 0.7, ease: \"easeOut\" as const }\n  const spring = reduced\n    ? { duration: 0 }\n    : { type: \"spring\" as const, stiffness: 260, damping: 34, mass: 0.9 }\n\n  // The track is driven by a motion value rather than an `animate` prop so a\n  // drag that starts mid-spring reads the real position, not where the spring\n  // was headed - otherwise the release snaps a card off.\n  React.useEffect(() => {\n    if (dragging) return\n    const run = animate(x, target, spring)\n    return () => run.stop()\n    // `spring` is a literal, so `reduced` (all it derives from) stands in for it.\n  }, [target, dragging, reduced, x]) // eslint-disable-line react-hooks/exhaustive-deps\n\n  // Wheel and trackpad. Both axes step the strip.\n  React.useEffect(() => {\n    const stage = stageRef.current\n    if (!stage) return\n    let acc = 0\n    let until = 0\n\n    const onWheel = (e: WheelEvent) => {\n      // Trackpads report the dominant axis; take whichever is stronger.\n      const delta = Math.abs(e.deltaX) > Math.abs(e.deltaY) ? e.deltaX : e.deltaY\n      // Scroll chaining: once the strip is against an end, hand the gesture\n      // back to the page. Without this a full-height carousel is a scroll trap\n      // with no way past it.\n      const stuck = (delta > 0 && index === last) || (delta < 0 && index === 0)\n      if (stuck) {\n        acc = 0\n        return\n      }\n      e.preventDefault()\n      const now = e.timeStamp\n      if (now < until) return\n      acc += delta\n      if (Math.abs(acc) < WHEEL_THRESHOLD) return\n      go(index + Math.sign(acc))\n      acc = 0\n      until = now + WHEEL_COOLDOWN\n    }\n\n    stage.addEventListener(\"wheel\", onWheel, { passive: false })\n    return () => stage.removeEventListener(\"wheel\", onWheel)\n  }, [go, index])\n\n  React.useEffect(() => {\n    if (!autoplay || paused || dragging || items.length < 2) return\n    const id = window.setTimeout(\n      () => go(index === last ? 0 : index + 1),\n      autoplayDelay\n    )\n    return () => window.clearTimeout(id)\n  }, [autoplay, autoplayDelay, dragging, go, index, items.length, last, paused])\n\n  const active = items[index]\n  if (!active) return null\n\n  const lines = active.title.split(\"\\n\")\n  const accent = active.accent ?? \"#8a8a8a\"\n\n  return (\n    <div\n      ref={stageRef}\n      tabIndex={0}\n      role=\"group\"\n      aria-roledescription=\"carousel\"\n      aria-label=\"Featured looks\"\n      onKeyDown={(e) => {\n        const keys: Record<string, number> = {\n          ArrowLeft: index - 1,\n          ArrowRight: index + 1,\n          Home: 0,\n          End: last,\n        }\n        if (!(e.key in keys)) return\n        e.preventDefault()\n        go(keys[e.key]!)\n      }}\n      onPointerEnter={() => setPaused(true)}\n      onPointerLeave={() => setPaused(false)}\n      onFocus={() => setPaused(true)}\n      onBlur={() => setPaused(false)}\n      className={cn(\n        \"relative h-full min-h-[24rem] w-full overflow-hidden bg-black text-white select-none\",\n        \"outline-none focus-visible:ring-1 focus-visible:ring-white/40 focus-visible:ring-inset\",\n        className\n      )}\n    >\n      {/* ── Background: the focused photo, blown up and re-hued to its accent ── */}\n      <AnimatePresence initial={false}>\n        <motion.div\n          key={index}\n          className=\"absolute inset-0\"\n          initial={{ opacity: 0 }}\n          animate={{ opacity: 1 }}\n          exit={{ opacity: 0 }}\n          transition={swing}\n        >\n          <motion.img\n            src={active.image}\n            alt=\"\"\n            aria-hidden\n            draggable={false}\n            className=\"absolute inset-0 h-full w-full object-cover\"\n            initial={{ scale: reduced ? 1.28 : 1.42 }}\n            animate={{ scale: 1.28 }}\n            transition={reduced ? { duration: 0 } : { duration: 6, ease: \"linear\" }}\n          />\n          {/* Keep the photo's luminance, take the accent's hue. */}\n          <div\n            className=\"absolute inset-0\"\n            style={{ backgroundColor: accent, mixBlendMode: \"color\" }}\n          />\n          <div\n            className=\"absolute inset-0 opacity-55\"\n            style={{ backgroundColor: accent, mixBlendMode: \"multiply\" }}\n          />\n        </motion.div>\n      </AnimatePresence>\n\n      {/* Legibility wash + grain, above the swap so they never flicker. */}\n      <div className=\"absolute inset-0 bg-gradient-to-b from-black/40 via-transparent to-black/45\" />\n      <div\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0 opacity-[0.22] mix-blend-overlay\"\n        style={{ backgroundImage: GRAIN, backgroundSize: \"180px 180px\" }}\n      />\n\n      {/* ── Top bar: a centred cluster, not edge-to-edge ── */}\n      <div\n        className=\"absolute inset-x-0 flex items-center justify-center\"\n        style={{ top: Math.max(16, box.h * 0.029), gap: `${Math.max(20, box.w * 0.06)}px` }}\n      >\n        {onBack ? (\n          <button\n            type=\"button\"\n            onClick={onBack}\n            className=\"opacity-90 transition-opacity hover:opacity-100\"\n            style={{ fontSize: label * 1.15 }}\n          >\n            <span aria-hidden>↖</span> Back\n          </button>\n        ) : null}\n        {brand ? (\n          <div\n            className=\"font-semibold tracking-[0.06em]\"\n            style={{ fontSize: label * 1.35 }}\n          >\n            {brand}\n          </div>\n        ) : null}\n        {onMenu ? (\n          <button\n            type=\"button\"\n            onClick={onMenu}\n            className=\"opacity-90 transition-opacity hover:opacity-100\"\n            style={{ fontSize: label * 1.15 }}\n          >\n            Menu <span aria-hidden>☰</span>\n          </button>\n        ) : null}\n      </div>\n\n      {/* ── Headline block, sitting just above the strip's top edge ── */}\n      <div\n        className=\"absolute inset-x-0 top-0 flex flex-col justify-end\"\n        style={{\n          height: `${STRIP_TOP * 100}%`,\n          paddingLeft: pad,\n          paddingRight: pad,\n          paddingBottom: Math.round(box.h * 0.028),\n        }}\n      >\n        <div className=\"flex w-full flex-wrap items-end gap-x-[6vw] gap-y-2\">\n          <AnimatePresence mode=\"popLayout\" initial={false}>\n            <motion.h2\n              key={index}\n              className=\"font-semibold leading-[0.88] tracking-[-0.03em]\"\n              style={{ fontSize: Math.max(24, Math.round(box.h * TITLE)) }}\n              initial={{ opacity: 0 }}\n              animate={{ opacity: 1 }}\n              exit={{ opacity: 0, transition: { duration: 0.18 } }}\n            >\n              {lines.map((line, i) => (\n                // Each line wipes up from behind its own edge.\n                <span key={i} className=\"block overflow-hidden\">\n                  <motion.span\n                    className=\"block\"\n                    initial={{ y: \"110%\" }}\n                    animate={{ y: 0 }}\n                    transition={\n                      reduced\n                        ? { duration: 0 }\n                        : { duration: 0.62, delay: i * 0.07, ease: [0.22, 1, 0.36, 1] }\n                    }\n                  >\n                    {line}\n                  </motion.span>\n                </span>\n              ))}\n            </motion.h2>\n          </AnimatePresence>\n\n          {active.credit ? (\n            <motion.p\n              key={`credit-${index}`}\n              className=\"font-mono uppercase tracking-[0.14em] opacity-80\"\n              style={{ fontSize: label }}\n              initial={{ opacity: 0 }}\n              animate={{ opacity: 0.8 }}\n              transition={{ duration: 0.5, delay: 0.1 }}\n            >\n              {active.credit}\n            </motion.p>\n          ) : null}\n\n          {active.meta?.length ? (\n            <div\n              className=\"ml-auto flex items-end\"\n              style={{ gap: `${Math.max(16, box.w * 0.055)}px` }}\n            >\n              {active.meta.map((fact, i) => (\n                <motion.span\n                  key={`${index}-${fact}`}\n                  className=\"font-mono whitespace-nowrap uppercase tracking-[0.14em] opacity-80\"\n                  style={{ fontSize: label }}\n                  initial={{ opacity: 0, y: 6 }}\n                  animate={{ opacity: 0.8, y: 0 }}\n                  transition={\n                    reduced ? { duration: 0 } : { duration: 0.45, delay: 0.12 + i * 0.06 }\n                  }\n                >\n                  {fact}\n                </motion.span>\n              ))}\n            </div>\n          ) : null}\n        </div>\n      </div>\n\n      {/* ── The strip: one shared top edge, the focused card twice as tall ── */}\n      <div\n        className=\"absolute inset-x-0\"\n        style={{ top: `${STRIP_TOP * 100}%`, height: fullH }}\n      >\n        <motion.div\n          className=\"flex items-start\"\n          style={{ gap, x, cursor: dragging ? \"grabbing\" : \"grab\" }}\n          drag=\"x\"\n          dragMomentum={false}\n          dragElastic={0.08}\n          dragConstraints={{ left: xFor(last), right: xFor(0) }}\n          onDragStart={() => setDragging(true)}\n          onDragEnd={(_, info) => {\n            setDragging(false)\n            // Land on whatever card the release sits nearest, nudged by throw\n            // velocity so a flick clears more than one card.\n            const thrown = x.get() + info.velocity.x * 0.12\n            go(Math.round((box.w / 2 - thrown - cardW / 2) / step))\n          }}\n        >\n          {items.map((item, i) => (\n            <motion.button\n              key={item.id ?? i}\n              type=\"button\"\n              aria-label={item.title.replace(/\\n/g, \" \")}\n              aria-current={i === index}\n              onClick={() => go(i)}\n              className=\"relative shrink-0 overflow-hidden rounded-none bg-white/5\"\n              style={{ width: cardW }}\n              animate={{ height: i === index ? fullH : halfH }}\n              transition={spring}\n            >\n              {/* The focused card is exactly 3:4, so object-position does\n                  nothing to it - it only picks which band of the portrait the\n                  half-height neighbours keep. Anchored just above centre so a\n                  clipped card still shows a face, not a forehead. */}\n              <img\n                src={item.image}\n                alt=\"\"\n                draggable={false}\n                className=\"h-full w-full object-cover\"\n                style={{ objectPosition: \"50% 26%\" }}\n              />\n              {/* Unfocused cards sit back a touch without going grey. */}\n              <motion.span\n                aria-hidden\n                className=\"absolute inset-0 bg-black\"\n                animate={{ opacity: i === index ? 0 : 0.12 }}\n                transition={spring}\n              />\n            </motion.button>\n          ))}\n        </motion.div>\n      </div>\n\n      {/* ── Position rail ── */}\n      <div\n        className=\"absolute\"\n        style={{ left: pad, bottom: Math.max(14, box.h * 0.022), width: box.w * RAIL }}\n      >\n        <div\n          className=\"flex justify-between font-mono tabular-nums opacity-80\"\n          style={{ fontSize: label }}\n        >\n          <span>{String(index + 1).padStart(2, \"0\")}</span>\n          <span>{String(items.length).padStart(2, \"0\")}</span>\n        </div>\n        <div className=\"relative mt-2 h-px w-full bg-white/25\">\n          <motion.div\n            className=\"absolute inset-y-0 bg-white\"\n            style={{ width: `${100 / items.length}%` }}\n            animate={{ left: `${(index / items.length) * 100}%` }}\n            transition={spring}\n          />\n        </div>\n      </div>\n    </div>\n  )\n}\n"
    }
  ]
}
