{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"capture-loop-card","type":"registry:component","title":"Capture Loop Card","description":"A bento tile whose picture is a tightly cropped loop of your product, still until someone hovers or presses play, with a hairline that tracks the loop.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/capture-loop-card.tsx","content":"\"use client\";\n\nimport { useEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport type { CSSProperties, PointerEvent as ReactPointerEvent, ReactNode } from \"react\";\n\n/**\n * CaptureLoopCard — a bento tile whose picture is a tightly cropped loop of\n * the product itself: a few seconds of a real screen, cut down to the one\n * detail that proves the feature.\n *\n * It holds still until someone shows interest. A mouse over the tile plays\n * the loop and leaving pauses it; on touch and from the keyboard a small\n * play and pause control does the same, and it is always there, so motion\n * can be stopped at any time. A hairline under the picture tracks the loop.\n * The loop pauses when the tile leaves the screen, and hover never starts it\n * under reduced motion (the control still does).\n *\n * Give it a muted MP4 or WebM (4–8s, cropped tight) and a poster frame. Or\n * draw the capture in code as children: the picture sets --clc-play to\n * \"running\" or \"paused\", so a CSS animation with\n * `animation-play-state: var(--clc-play)` plays and pauses with the tile.\n *\n * Needs Tailwind v4. No dependencies beyond React.\n */\n\nexport type CaptureLoopCardProps = {\n  /** Small mono label above the title. */\n  label?: string;\n  title: string;\n  body?: string;\n  /** Makes the whole tile a link (the control stays its own button). */\n  href?: string;\n  /** Video sources, most efficient first, e.g. [{ src: \"/loop.webm\", type: \"video/webm\" }]. Paths are relative or http(s). */\n  sources?: { src: string; type?: string }[];\n  poster?: string;\n  /** Video only: where the crop centres, as CSS object-position, e.g. \"30% 20%\". */\n  focus?: string;\n  /** Video only: zoom into the focus point for a tighter crop, 1 to 2. */\n  zoom?: number;\n  /** Describes what the loop shows. Without it the picture is decorative. */\n  alt?: string;\n  /** Loop length for code-drawn captures, in ms (the video reports its own). */\n  loopMs?: number;\n  /** \"lg\" for a 2x2 hero tile: a larger title and body. */\n  size?: \"md\" | \"lg\";\n  /** A code-drawn capture, used when there are no sources. */\n  children?: ReactNode;\n  className?: string;\n};\n\nconst MONO = \"var(--font-mono, var(--font-geist-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace))\";\n\n/** Allow relative paths, fragments, http(s), mailto and tel; anything else becomes \"#\". */\nfunction safeHref(href: string): string {\n  const v = href.replace(/[\\t\\n\\r]/g, \"\").trim();\n  if (v.indexOf(String.fromCharCode(92)) !== -1) return \"#\";\n  if (/^(https?:|mailto:|tel:)/i.test(v)) return v;\n  if (/^[/#?]/.test(v) && !/^\\/\\//.test(v)) return v;\n  return \"#\";\n}\n\n/** Media URLs: http(s) or a relative path (no other scheme, not //); anything else is dropped. */\nfunction safeSrc(src: string | undefined): string | undefined {\n  if (!src) return undefined;\n  const v = src.replace(/[\\t\\n\\r]/g, \"\").trim();\n  if (!v || v.indexOf(String.fromCharCode(92)) !== -1) return undefined;\n  if (/^https?:\\/\\//i.test(v)) return v;\n  if (!/^[^/?#]*:/.test(v) && !/^\\/\\//.test(v)) return v;\n  return undefined;\n}\n\nconst RM = \"(prefers-reduced-motion: reduce)\";\nfunction onMotionChange(cb: () => void) {\n  const mq = window.matchMedia(RM);\n  mq.addEventListener(\"change\", cb);\n  return () => mq.removeEventListener(\"change\", cb);\n}\n\nexport function CaptureLoopCard({\n  label,\n  title,\n  body,\n  href,\n  sources,\n  poster,\n  focus = \"50% 50%\",\n  zoom = 1,\n  alt,\n  loopMs = 6000,\n  size = \"md\",\n  children,\n  className = \"\",\n}: CaptureLoopCardProps) {\n  const cardRef = useRef<HTMLElement>(null);\n  const videoRef = useRef<HTMLVideoElement>(null);\n  const barRef = useRef<HTMLSpanElement>(null);\n  const light = useRef({ x: 0, y: 0, raf: 0 });\n\n  // Playing is derived: pinned by the control, or hovered by a mouse (unless\n  // the control just paused it, until the pointer leaves).\n  const [pinned, setPinned] = useState(false);\n  const [hover, setHover] = useState(false);\n  const [held, setHeld] = useState(false);\n  const motionOk = useSyncExternalStore(\n    onMotionChange,\n    () => !window.matchMedia(RM).matches,\n    () => true,\n  );\n  const playing = pinned || (hover && !held && motionOk);\n\n  const clean = (sources ?? []).map((s) => ({ src: safeSrc(s.src), type: s.type })).filter((s) => s.src);\n  const video = clean.length > 0;\n  const z = Math.min(2, Math.max(1, zoom));\n\n  // Off screen, the loop stops and forgets the pin, the hover and the hold\n  // (scrolling with a wheel under a still pointer fires no pointerleave).\n  useEffect(() => {\n    const el = cardRef.current;\n    if (!el || typeof IntersectionObserver === \"undefined\") return;\n    const io = new IntersectionObserver(([e]) => {\n      if (!e.isIntersecting) {\n        setPinned(false);\n        setHover(false);\n        setHeld(false);\n      }\n    });\n    io.observe(el);\n    return () => io.disconnect();\n  }, []);\n\n  // Video: play and pause it, and draw the hairline from its clock.\n  useEffect(() => {\n    const v = videoRef.current;\n    const bar = barRef.current;\n    if (!video || !v) return;\n    let raf = 0;\n    const draw = () => {\n      if (bar && v.duration) bar.style.transform = \"scaleX(\" + (v.currentTime / v.duration).toFixed(4) + \")\";\n      raf = requestAnimationFrame(draw);\n    };\n    let live = true;\n    if (playing) {\n      const p = v.play();\n      if (p)\n        p.catch(() => {\n          if (live) setPinned(false);\n        });\n      raf = requestAnimationFrame(draw);\n    } else v.pause();\n    return () => {\n      live = false;\n      cancelAnimationFrame(raf);\n    };\n  }, [playing, video]);\n\n  // Code-drawn: the hairline is one animation that plays and pauses with it.\n  const barAnim = useRef<Animation | null>(null);\n  useEffect(() => {\n    const bar = barRef.current;\n    if (video || !bar) return;\n    const a = bar.animate([{ transform: \"scaleX(0)\" }, { transform: \"scaleX(1)\" }], {\n      duration: Math.max(500, loopMs),\n      iterations: Infinity,\n      easing: \"linear\",\n    });\n    a.pause();\n    barAnim.current = a;\n    return () => {\n      a.cancel();\n      barAnim.current = null;\n    };\n  }, [video, loopMs]);\n  useEffect(() => {\n    const a = barAnim.current;\n    if (!a) return;\n    if (playing) a.play();\n    else a.pause();\n  }, [playing]);\n\n  useEffect(() => {\n    const l = light.current;\n    return () => cancelAnimationFrame(l.raf);\n  }, []);\n\n  function onMove(e: ReactPointerEvent<HTMLElement>) {\n    light.current.x = e.clientX;\n    light.current.y = e.clientY;\n    if (light.current.raf) return;\n    const el = e.currentTarget;\n    light.current.raf = requestAnimationFrame(() => {\n      light.current.raf = 0;\n      const r = el.getBoundingClientRect();\n      const k = el.offsetWidth / (r.width || 1);\n      el.style.setProperty(\"--clc-x\", ((light.current.x - r.left) * k).toFixed(1) + \"px\");\n      el.style.setProperty(\"--clc-y\", ((light.current.y - r.top) * k).toFixed(1) + \"px\");\n      el.style.setProperty(\"--clc-o\", \"1\");\n    });\n  }\n\n  function toggle() {\n    if (playing) {\n      setPinned(false);\n      setHeld(true);\n    } else {\n      setHeld(false);\n      setPinned(true);\n    }\n  }\n\n  const lg = size === \"lg\";\n\n  return (\n    <article\n      ref={cardRef}\n      className={\"group relative flex h-full min-h-0 flex-col overflow-hidden rounded-[20px] bg-[#0f1012] p-1.5 text-white \" + className}\n      style={{ boxShadow: \"inset 0 0 0 1px rgba(255,255,255,0.08)\", \"--clc-o\": \"0\" } as CSSProperties}\n      onPointerMove={onMove}\n      onPointerEnter={(e) => {\n        if (e.pointerType === \"mouse\") {\n          setHover(true);\n          setHeld(false);\n        }\n      }}\n      onPointerLeave={(e) => {\n        cancelAnimationFrame(light.current.raf);\n        light.current.raf = 0;\n        e.currentTarget.style.setProperty(\"--clc-o\", \"0\");\n        setHover(false);\n        setHeld(false);\n      }}\n    >\n      {/* The pointer light: a lit hairline ring and a faint glow. */}\n      <span\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0 z-20 rounded-[20px] transition-opacity duration-200\"\n        style={{\n          opacity: \"var(--clc-o)\",\n          padding: 1,\n          background: \"radial-gradient(180px circle at var(--clc-x, -999px) var(--clc-y, -999px), rgba(255,255,255,0.7), rgba(255,255,255,0) 70%)\",\n          WebkitMask: \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n          WebkitMaskComposite: \"xor\",\n          mask: \"linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0)\",\n        }}\n      />\n      <span\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0 z-20 rounded-[20px] transition-opacity duration-200\"\n        style={{\n          opacity: \"var(--clc-o)\",\n          background: \"radial-gradient(260px circle at var(--clc-x, -999px) var(--clc-y, -999px), rgba(255,255,255,0.07), rgba(255,255,255,0) 70%)\",\n        }}\n      />\n\n      {/* The capture, cropped tight. */}\n      <div\n        role={alt ? \"img\" : undefined}\n        aria-label={alt}\n        aria-hidden={alt ? undefined : true}\n        data-playing={playing ? \"\" : undefined}\n        onClick={href ? undefined : toggle}\n        className={\"relative min-h-0 flex-1 overflow-hidden rounded-[14px] bg-[#131417]\" + (href ? \"\" : \" cursor-pointer\")}\n        style={{ \"--clc-play\": playing ? \"running\" : \"paused\" } as CSSProperties}\n      >\n        {video ? (\n          <video\n            ref={videoRef}\n            muted\n            loop\n            playsInline\n            preload=\"metadata\"\n            poster={safeSrc(poster)}\n            aria-hidden\n            className=\"absolute inset-0 h-full w-full object-cover\"\n            style={{ objectPosition: focus, transform: z > 1 ? \"scale(\" + z + \")\" : undefined, transformOrigin: focus }}\n          >\n            {clean.map((s) => (\n              <source key={s.src} src={s.src} type={s.type} />\n            ))}\n          </video>\n        ) : (\n          <div className=\"absolute inset-0\">{children}</div>\n        )}\n        <span aria-hidden className=\"pointer-events-none absolute inset-0 rounded-[14px]\" style={{ boxShadow: \"inset 0 0 0 1px rgba(255,255,255,0.06)\" }} />\n        <span aria-hidden className=\"pointer-events-none absolute inset-x-0 bottom-0 h-px bg-white/10\">\n          <span ref={barRef} className=\"absolute inset-0 origin-left bg-white/70\" style={{ transform: \"scaleX(0)\" }} />\n        </span>\n      </div>\n\n      <div className={lg ? \"px-4 pt-5 pb-4\" : \"px-3 pt-4 pb-3\"}>\n        {label && (\n          <p className=\"text-[11px] uppercase tracking-[0.12em] text-white/50\" style={{ fontFamily: MONO }}>\n            {label}\n          </p>\n        )}\n        <h3 className={(lg ? \"mt-2 text-[24px] leading-[1.15]\" : \"mt-1.5 text-[17px] leading-snug\") + \" font-semibold tracking-[-0.015em]\"}>\n          {href ? (\n            <a\n              href={safeHref(href)}\n              className=\"rounded-[6px] outline-none after:absolute after:inset-0 after:z-10 after:rounded-[20px] focus-visible:after:ring-2 focus-visible:after:ring-inset focus-visible:after:ring-white/80\"\n            >\n              {title}\n            </a>\n          ) : (\n            title\n          )}\n        </h3>\n        {body && <p className={(lg ? \"mt-2 max-w-[46ch] text-[15px]\" : \"mt-1.5 text-[13px]\") + \" leading-snug text-white/55\"}>{body}</p>}\n      </div>\n\n      {/* Always there, so the motion can always be stopped. */}\n      <button\n        type=\"button\"\n        aria-label={playing ? \"Pause loop\" : \"Play loop\"}\n        onClick={toggle}\n        className=\"absolute top-3 right-3 z-30 grid size-8 place-items-center rounded-[8px] bg-[#0f1012] text-white/80 outline-none transition-colors duration-200 hover:bg-[#16171a] hover:text-white focus-visible:ring-2 focus-visible:ring-white/80 motion-reduce:transition-none\"\n        style={{ boxShadow: \"inset 0 0 0 1px rgba(255,255,255,0.12)\" }}\n      >\n        <svg aria-hidden width=\"12\" height=\"12\" viewBox=\"0 0 12 12\">\n          {playing ? (\n            <path d=\"M3.5 2.5v7M8.5 2.5v7\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" />\n          ) : (\n            <path d=\"M3.5 2.2v7.6L9.6 6z\" fill=\"currentColor\" />\n          )}\n        </svg>\n      </button>\n    </article>\n  );\n}\n","type":"registry:component","target":"components/viberdy/capture-loop-card.tsx"}],"meta":{"tier":"free","tags":["bento","video card","screen recording","product demo","feature tile","hover to play"],"href":"https://viberdy.dev/library/capture-loop-card","aiPrompt":"Create a React + Tailwind v4 client component, CaptureLoopCard: a dark bento tile whose picture is a tightly cropped, muted loop of the product (a few seconds of a real screen), which plays only when someone shows interest.\n\nProps: label? (mono), title, body?, href? (the whole tile becomes a link through a stretched ::after on the title link; the play control stays above it as its own button), sources? ({ src, type? }[], most efficient first), poster?, focus (video only; CSS object-position, default \"50% 50%\"), zoom (video only; 1–2, clamped: scale the video from the focus point for a tighter crop), alt? (describes the loop; without it the picture is aria-hidden), loopMs (default 6000, for code-drawn captures), size (\"md\" | \"lg\"; lg is for a 2x2 hero: 24px title, 15px body), children (a code-drawn capture used when there are no sources), className. Links are sanitised (strip tabs and newlines, reject backslashes, allow http(s), mailto, tel and relative paths starting / # ? but not //); media URLs allow http(s) and relative paths (no other scheme before the first / ? or #, not //, no backslashes).\n\nKit tokens: tile #0f1012 with an inset 1px hairline at white 0.08, radius 20, filling its grid cell (h-full, flex column); the picture sits 6px inside (radius 14, concentric) on #131417 with its own 0.06 inset hairline; mono label 11px uppercase +0.12em at white 50% in var(--font-mono, var(--font-geist-mono, ui-monospace, …)); title 17px/600 (md), body 13px at 55% white; no shadows, no lift. The pointer light: on pointermove, coalesced to one write per animation frame, set --clc-x/--clc-y in layout pixels (rect scaled by offsetWidth / rect width) and --clc-o 1 (0 on leave); a hairline ring lit by radial-gradient(180px circle, white 0.7 → transparent 70%) (padding 1px, mask-composite exclude) and a glow (radial 260px, white 0.07), both at opacity var(--clc-o) with 200ms transitions, pointer-events none.\n\nPlaying is derived, never stored: playing = pinned || (hovered by a mouse && not held && motion allowed). Mouse pointerenter sets hovered and clears held; pointerleave clears hovered and held (and cancels a pending light frame). The control (a 32px button 6px inside the picture's corner, so 12px from the tile's edge, radius 8, concentric with the picture's 14, #0f1012 with a 0.12 hairline, play and pause glyphs drawn in SVG; its aria-label says what it will do, \"Play loop\" or \"Pause loop\", with no aria-pressed alongside a changing label) toggles: if playing, unpin and hold (so hover does not restart it until the pointer leaves); otherwise pin. When the tile is not a link, a click on the picture toggles too. Read prefers-reduced-motion with useSyncExternalStore; under it, hover never plays, but the control still does. An IntersectionObserver clears pinned, hovered and held when the tile leaves the screen (a wheel scroll under a still pointer fires no pointerleave).\n\nVideo: muted, loop, playsInline, preload=\"metadata\", poster, object-fit cover at the focus point; play() when playing (catch the promise and unpin on failure, but only if that effect run is still current), pause() otherwise. A hairline under the picture (1px at white 10%, filled at white 70% from the left) tracks progress: for video, scaleX(currentTime / duration) on requestAnimationFrame while playing; for code-drawn captures, one infinite linear Web Animation of scaleX 0 → 1 over loopMs that is paused and played with the tile. The picture sets the custom property --clc-play to \"running\" or \"paused\" (and data-playing), so a code-drawn capture's CSS animations use animation-play-state: var(--clc-play).\n\nOutput one self-contained \"use client\" TSX file with no dependencies beyond React. Build strings with + rather than template literals.","license":"https://viberdy.dev/license"}}