{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "video-player",
  "title": "Video Player",
  "author": "AlgorizeTech",
  "description": "Ask the user to pick one of 4 video player variants: https://avaraui.com/view/video-player. This item holds 2 of them as looks of one component (modal, inline). Skip the question if the user already named one. A video hero with thumbnail and glow that plays in a modal, inline in the card, or directly on load — behind a YouTube embed or a native HTML5 video.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "src/components/custom/blocks/VideoPlayerBlock.tsx",
      "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport { Play, Sparkles, X } from \"lucide-react\";\nimport React, { useCallback, useEffect, useRef, useState } from \"react\";\nimport { springLinear } from \"./motion-curves\";\n\n/** Which player renders `videoUrl`. */\nexport type VideoSource = \"youtube\" | \"video\";\n\n/**\n * How the player is revealed.\n *\n * - `modal`  — poster hero, player opens in a centered dialog (the default).\n * - `inline` — poster hero, the player swaps in *inside the card* on click. No\n *   overlay and no scroll lock, so it can sit inside a scrolling column.\n * - `direct` — no poster at all: the player renders immediately. A native\n *   player is introduced by a title at the foot of the frame that moves to a\n *   hover-only top bar once played; an embed is left to its own title chrome.\n */\nexport type VideoPlaybackMode = \"modal\" | \"inline\" | \"direct\";\n\nexport interface VideoPlayerProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onPlay\"> {\n  /**\n   * The media URL. For `source=\"youtube\"` this is an embed URL\n   * (`https://www.youtube.com/embed/<id>`); for `source=\"video\"` it is a file\n   * the browser plays natively (mp4/webm/ogg).\n   */\n  videoUrl?: string;\n  thumbnailUrl?: string;\n  thumbnailAlt?: string;\n  badge?: string;\n  title?: string;\n  subtitle?: string;\n  playButtonLabel?: string;\n  aspectRatio?: \"16/9\" | \"21/9\" | \"4/3\" | \"1/1\";\n  modalSize?: \"md\" | \"lg\" | \"xl\" | \"full\";\n  enableGlow?: boolean;\n  /** Reveal strategy. Defaults to the modal hero. */\n  playbackMode?: VideoPlaybackMode;\n  /** Player implementation. Defaults to a YouTube (or any embed) iframe. */\n  source?: VideoSource;\n  /** MIME type for `source=\"video\"`, e.g. `video/mp4`. */\n  videoType?: string;\n  /**\n   * Start playing without a click. Only meaningful for `playbackMode=\"direct\"`\n   * — the other two modes are already user-initiated and always autoplay.\n   * Browsers block unmuted autoplay, so the native player mutes itself when\n   * this is set.\n   */\n  autoPlay?: boolean;\n  loop?: boolean;\n  muted?: boolean;\n  /** Native `<video>` controls. Ignored for `source=\"youtube\"`. */\n  controls?: boolean;\n  /**\n   * The title/subtitle laid over the frame in `playbackMode=\"direct\"`: at the\n   * foot until the video is first played, then a hover-only bar at the top.\n   *\n   * Only applies to `source=\"video\"`. A third-party embed draws its own title\n   * bar, so the overlay stays off for `source=\"youtube\"` rather than stacking\n   * a second one on it.\n   */\n  showOverlay?: boolean;\n  onPlay?: () => void;\n  onClose?: () => void;\n}\n\nconst aspectRatios = {\n  \"16/9\": \"aspect-video\",\n  \"21/9\": \"aspect-[21/9]\",\n  \"4/3\": \"aspect-[4/3]\",\n  \"1/1\": \"aspect-square\",\n};\n\nconst modalSizes = {\n  md: \"max-w-3xl\",\n  lg: \"max-w-5xl\",\n  xl: \"max-w-6xl\",\n  full: \"max-w-[95vw] h-[90vh]\",\n};\n\n// Modal motion: the backdrop fades over 0.2s (ease-out); the dialog springs\n// (stiffness 300, damping 25) between 90% scale, 20px low and transparent and\n// its resting place — the same spring both ways, as a CSS `linear()` curve.\n// @starting-style is where a freshly mounted modal starts from.\nconst DIALOG_SPRING = springLinear({ stiffness: 300, damping: 25 });\n\nconst MODAL_CSS = `\n.video-player-backdrop { transition: opacity 0.2s cubic-bezier(0, 0, 0.58, 1); }\n.video-player-backdrop[data-state=\"closed\"] { opacity: 0; }\n.video-player-dialog {\n  transition:\n    transform ${DIALOG_SPRING.duration}ms ${DIALOG_SPRING.easing},\n    opacity ${DIALOG_SPRING.duration}ms ${DIALOG_SPRING.easing};\n}\n.video-player-dialog[data-state=\"closed\"] {\n  opacity: 0;\n  transform: translateY(20px) scale(0.9);\n}\n@starting-style {\n  .video-player-backdrop[data-state=\"open\"] { opacity: 0; }\n  .video-player-dialog[data-state=\"open\"] {\n    opacity: 0;\n    transform: translateY(20px) scale(0.9);\n  }\n}\n`;\n\n/**\n * Sets or clears `autoplay=1` on an embed URL.\n *\n * The prop is a boolean but YouTube reads a query parameter, so the two have to\n * be reconciled somewhere. Doing it here means `playbackMode=\"direct\"` cannot\n * autoplay by accident just because the URL it was handed still carries the\n * `?autoplay=1` the modal variant needs.\n */\nfunction withAutoplay(url: string, autoplay: boolean): string {\n  if (!/^https?:\\/\\//i.test(url)) return url;\n  try {\n    const parsed = new URL(url);\n    if (autoplay) parsed.searchParams.set(\"autoplay\", \"1\");\n    else parsed.searchParams.delete(\"autoplay\");\n    return parsed.toString();\n  } catch {\n    return url;\n  }\n}\n\n/**\n * The player with no hero chrome around it. The inline swap and the modal both\n * render this, which is why an embed and a native file behave identically in\n * every mode.\n */\nfunction PlayerFrame({\n  source,\n  videoUrl,\n  videoType,\n  title,\n  poster,\n  autoplay,\n  loop,\n  muted,\n  controls,\n  onFirstPlay,\n}: {\n  source: VideoSource;\n  videoUrl: string;\n  videoType?: string;\n  title?: string;\n  poster?: string;\n  autoplay: boolean;\n  loop: boolean;\n  muted: boolean;\n  controls: boolean;\n  /**\n   * Fires the first time the viewer starts watching. Native player only — a\n   * cross-origin embed reports no playback events.\n   */\n  onFirstPlay?: () => void;\n}) {\n  if (source === \"video\") {\n    return (\n      <video\n        // Remounting on a changed src is what makes a swapped source load at\n        // all: <video> ignores the attribute once it already has metadata.\n        key={videoUrl}\n        className=\"h-full w-full bg-black object-contain\"\n        poster={poster}\n        controls={controls}\n        autoPlay={autoplay}\n        loop={loop}\n        muted={muted || autoplay}\n        playsInline\n        preload=\"metadata\"\n        onPlay={onFirstPlay}\n      >\n        <source src={videoUrl} type={videoType} />\n        Your browser does not support the video tag.\n      </video>\n    );\n  }\n\n  return (\n    <iframe\n      src={withAutoplay(videoUrl, autoplay)}\n      title={title || \"Video player\"}\n      className=\"h-full w-full border-0\"\n      allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\"\n      allowFullScreen\n    />\n  );\n}\n\n/**\n * Title and subtitle laid over the frame, following the convention YouTube set.\n *\n * Before anything has played the copy sits at the FOOT of the frame and stays\n * there: nothing is happening yet, so it is free to introduce the video, and a\n * viewer should not have to hover to find out what they are about to watch.\n * Its bottom padding keeps it clear of the control bar, so the gradient reaches\n * the bottom edge but the text stops above the scrubber.\n *\n * Once playback has started that is no longer true — the picture is the point,\n * and a permanent caption is in the way. So the copy moves to the TOP of the\n * frame and only appears on hover, where it overlaps nothing that matters and\n * stays available for anyone who wants to check what they are watching.\n *\n * `pointer-events-none` keeps every click going through to the player in both\n * positions.\n */\nfunction MediaOverlay({\n  title,\n  subtitle,\n  hasPlayed,\n}: {\n  title?: string;\n  subtitle?: string;\n  /** Whether the viewer has started watching. Drives the whole treatment. */\n  hasPlayed?: boolean;\n}) {\n  if (!title && !subtitle) return null;\n\n  const copy = (\n    <>\n      {title && (\n        <h3 className=\"line-clamp-1 text-base font-semibold tracking-tight text-white drop-shadow-sm sm:text-xl md:text-2xl\">\n          {title}\n        </h3>\n      )}\n      {subtitle && (\n        <p className=\"mt-0.5 line-clamp-1 text-[11px] text-zinc-300 sm:text-xs md:text-sm\">\n          {subtitle}\n        </p>\n      )}\n    </>\n  );\n\n  if (hasPlayed) {\n    return (\n      <div className=\"pointer-events-none absolute inset-x-0 top-0 z-10 bg-gradient-to-b from-black/85 via-black/40 to-transparent px-4 pt-4 pb-16 opacity-0 transition-opacity duration-300 group-hover/frame:opacity-100 group-focus-within/frame:opacity-100 sm:px-6 sm:pt-5 sm:pb-20\">\n        {copy}\n      </div>\n    );\n  }\n\n  return (\n    <div className=\"pointer-events-none absolute inset-x-0 bottom-0 z-10 bg-gradient-to-t from-black/90 via-black/50 to-transparent px-4 pt-16 pb-14 transition-opacity duration-300 sm:px-6 sm:pt-24 sm:pb-16\">\n      {copy}\n    </div>\n  );\n}\n\n/** Close affordance shared by the inline swap and the modal. */\nfunction CloseButton({\n  onClick,\n  buttonRef,\n  label = \"Close video\",\n}: {\n  onClick: () => void;\n  buttonRef?: React.Ref<HTMLButtonElement>;\n  label?: string;\n}) {\n  return (\n    <button\n      ref={buttonRef}\n      onClick={onClick}\n      type=\"button\"\n      className=\"cursor-pointer rounded-full border border-white/10 bg-black/60 p-2 text-white/80 shadow-lg backdrop-blur-md transition-all duration-200 hover:bg-black/80 hover:text-white active:scale-95 sm:p-2.5\"\n      aria-label={label}\n    >\n      <X className=\"h-4 w-4 sm:h-5 sm:w-5\" />\n    </button>\n  );\n}\n\nexport const VideoPlayer = React.forwardRef<\n  HTMLDivElement,\n  VideoPlayerProps\n>(\n  (\n    {\n      videoUrl = \"https://www.youtube.com/embed/LXb3EKWsInQ?autoplay=1\",\n      thumbnailUrl = \"https://res.cloudinary.com/dodndg7ai/image/upload/f_webp,q_auto,w_1920,c_limit/v1790146210/photo-1506744038136-46273834b3fb-1790146212208.jpg\",\n      thumbnailAlt = \"Nature Wilderness Video Thumbnail\",\n      badge = \"Wilderness Exploration\",\n      title = \"Experience Untouched Nature in 4K\",\n      subtitle = \"Embark on an immersive journey through serene mountain vistas, ancient forests, and cascading waterfalls.\",\n      playButtonLabel = \"Watch Nature Documentary\",\n      aspectRatio = \"16/9\",\n      modalSize = \"lg\",\n      enableGlow = true,\n      playbackMode = \"modal\",\n      source = \"youtube\",\n      videoType,\n      autoPlay = false,\n      loop = false,\n      muted = false,\n      controls = true,\n      showOverlay = true,\n      onPlay,\n      onClose,\n      className,\n      ...props\n    },\n    ref,\n  ) => {\n    const [isOpen, setIsOpen] = useState(false);\n    // Latches on the first play and never goes back: the title treatment is\n    // about \"has this viewer started watching\", not about the current paused\n    // state, so pausing must not bring the bottom caption back over the video.\n    // An autoplaying direct player is already watching by the time it paints.\n    const [hasPlayed, setHasPlayed] = useState(\n      () => playbackMode === \"direct\" && autoPlay,\n    );\n    const handleFirstPlay = useCallback(() => setHasPlayed(true), []);\n    const containerRef = useRef<HTMLDivElement>(null);\n    // Where focus returns when the player is dismissed. Without it a keyboard\n    // user who closes the modal lands back at the top of the document.\n    const triggerRef = useRef<HTMLButtonElement>(null);\n    const closeRef = useRef<HTMLButtonElement>(null);\n\n    React.useImperativeHandle(\n      ref,\n      () => containerRef.current as HTMLDivElement,\n    );\n\n    const isDirect = playbackMode === \"direct\";\n\n    // The modal stays mounted after closing until its exit has played.\n    const modalOpen = playbackMode === \"modal\" && isOpen;\n    const [modalMounted, setModalMounted] = useState(modalOpen);\n    if (modalOpen && !modalMounted) setModalMounted(true);\n\n    useEffect(() => {\n      if (modalOpen || !modalMounted) return;\n      // Backstop for when no transitionend arrives (e.g. a hidden tab).\n      const timer = setTimeout(\n        () => setModalMounted(false),\n        DIALOG_SPRING.duration + 100,\n      );\n      return () => clearTimeout(timer);\n    }, [modalOpen, modalMounted]);\n\n    const handleOpen = () => {\n      if (isDirect) return;\n      setIsOpen(true);\n      onPlay?.();\n    };\n\n    const handleClose = useCallback(() => {\n      setIsOpen(false);\n      onClose?.();\n      triggerRef.current?.focus();\n    }, [onClose]);\n\n    useEffect(() => {\n      if (isDirect || !isOpen) return;\n      // Resolve the window the player actually lives in (supports iframe rendering).\n      const win = containerRef.current?.ownerDocument.defaultView ?? window;\n      const handleKeyDown = (e: KeyboardEvent) => {\n        if (e.key === \"Escape\") handleClose();\n      };\n      win.addEventListener(\"keydown\", handleKeyDown);\n      return () => win.removeEventListener(\"keydown\", handleKeyDown);\n    }, [isOpen, isDirect, handleClose]);\n\n    // The modal covers the page, so what is behind it must not scroll. Scoped\n    // to the owning document so a player rendered inside a preview iframe locks\n    // that iframe rather than the host page.\n    useEffect(() => {\n      if (playbackMode !== \"modal\" || !isOpen) return;\n      const doc = document;\n      const previous = doc.body.style.overflow;\n      doc.body.style.overflow = \"hidden\";\n      closeRef.current?.focus();\n      return () => {\n        doc.body.style.overflow = previous;\n      };\n    }, [isOpen, playbackMode]);\n\n    const frame = (\n      <PlayerFrame\n        source={source}\n        videoUrl={videoUrl}\n        videoType={videoType}\n        title={title}\n        poster={thumbnailUrl}\n        // modal and inline are click-initiated, so playback starts immediately.\n        // direct renders on load and only autoplays when explicitly asked to.\n        autoplay={isDirect ? autoPlay : true}\n        loop={loop}\n        muted={muted}\n        controls={controls}\n        onFirstPlay={handleFirstPlay}\n      />\n    );\n\n    const glow = enableGlow ? (\n      <div className=\"pointer-events-none absolute -inset-4 z-0 rounded-3xl bg-gradient-to-tr from-primary/20 via-primary/20 to-primary/10 opacity-80 blur-3xl transition-opacity duration-500 dark:opacity-50\" />\n    ) : null;\n\n    const badgePill = badge ? (\n      <div className=\"inline-flex items-center gap-1.5 rounded-2xl border border-white/20 bg-white/10 px-3 py-1.5 text-[10px] font-semibold tracking-wider text-white uppercase shadow-sm backdrop-blur-md sm:gap-2 sm:px-4 sm:text-xs dark:bg-black/40\">\n        <Sparkles className=\"h-3 w-3 shrink-0 animate-pulse text-amber-400 sm:h-3.5 sm:w-3.5\" />\n        <span className=\"max-w-[180px] truncate sm:max-w-none\">{badge}</span>\n      </div>\n    ) : null;\n\n    /* ── direct: the player is the hero, the copy sits over it ────────────── */\n    if (isDirect) {\n      return (\n        <div\n          ref={containerRef}\n          className={cn(\"relative w-full\", className)}\n          {...props}\n        >\n          {glow}\n          <div className=\"relative z-10 w-full overflow-hidden rounded-xl border border-border/80 bg-zinc-900 shadow-2xl sm:rounded-2xl md:rounded-3xl\">\n            <div\n              className={cn(\n                \"group/frame relative w-full overflow-hidden bg-black\",\n                aspectRatios[aspectRatio],\n              )}\n            >\n              {frame}\n              {/* Native player only. A YouTube (or any third-party) embed\n                  already draws its own title bar over the picture, so a second\n                  one on top of it is duplicate chrome — and the parent document\n                  cannot see across the origin boundary to know when the embed\n                  started playing anyway. `title` still reaches the iframe as\n                  its accessible name. */}\n              {showOverlay && source === \"video\" && (\n                <MediaOverlay\n                  title={title}\n                  subtitle={subtitle}\n                  hasPlayed={hasPlayed}\n                />\n              )}\n            </div>\n          </div>\n        </div>\n      );\n    }\n\n    /* ── modal + inline: poster hero with a play CTA ──────────────────────── */\n    const showInlinePlayer = playbackMode === \"inline\" && isOpen;\n\n    return (\n      <div\n        ref={containerRef}\n        className={cn(\"relative w-full\", className)}\n        {...props}\n      >\n        {/* Ambient GPU Glow */}\n        {glow}\n\n        {/* Hero Card Container with Fluid Mobile Min-Height */}\n        <div\n          className={cn(\n            \"group relative z-10 flex min-h-[220px] w-full flex-col justify-between overflow-hidden rounded-xl border border-border/80 bg-zinc-900 shadow-2xl sm:min-h-[280px] sm:rounded-2xl md:rounded-3xl lg:min-h-0\",\n            aspectRatios[aspectRatio],\n            !showInlinePlayer && \"cursor-pointer\",\n          )}\n          onClick={showInlinePlayer ? undefined : handleOpen}\n        >\n          {showInlinePlayer ? (\n            <>\n              <div className=\"absolute inset-0 bg-black\">{frame}</div>\n              <div className=\"absolute top-2.5 right-2.5 z-20 sm:top-4 sm:right-4\">\n                <CloseButton\n                  onClick={handleClose}\n                  buttonRef={closeRef}\n                  label=\"Close video and return to the poster\"\n                />\n              </div>\n            </>\n          ) : (\n            <>\n              {/* Background Thumbnail */}\n              <img\n                src={thumbnailUrl}\n                alt={thumbnailAlt}\n                className=\"absolute inset-0 h-full w-full object-cover\"\n                loading=\"lazy\"\n              />\n\n              {/* Dark Vignette Overlay */}\n              <div className=\"absolute inset-0 bg-gradient-to-t from-black/85 via-black/30 to-black/40 transition-opacity duration-300 group-hover:opacity-90\" />\n\n              {/* Content Overlay with Responsive Padding & Typography */}\n              <div className=\"absolute inset-0 z-20 flex flex-col justify-between p-4 sm:p-8 md:p-12\">\n                {/* Top Badge */}\n                <div className=\"flex justify-start\">{badgePill}</div>\n\n                {/* Center Play Button — a real <button>, so the hero is\n                    reachable by keyboard. The card keeps its own click handler\n                    for mice, and the button stops that from firing twice. */}\n                <div className=\"my-auto flex items-center justify-center py-2 sm:py-0\">\n                  <button\n                    ref={triggerRef}\n                    type=\"button\"\n                    onClick={(e) => {\n                      e.stopPropagation();\n                      handleOpen();\n                    }}\n                    aria-haspopup={\n                      playbackMode === \"modal\" ? \"dialog\" : undefined\n                    }\n                    className=\"group/btn relative flex transform cursor-pointer items-center gap-2.5 rounded-2xl border border-white/30 bg-white/15 px-5 py-3 shadow-[0_8px_32px_rgba(0,0,0,0.3)] backdrop-blur-xl transition-all duration-300 group-hover:scale-105 hover:bg-white/25 focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-offset-2 focus-visible:ring-offset-black focus-visible:outline-none sm:gap-4 sm:px-7 sm:py-4 dark:border-white/15 dark:bg-black/30 dark:hover:bg-black/50\"\n                  >\n                    <span className=\"flex h-8 w-8 shrink-0 items-center justify-center rounded-xl bg-[var(--theme-color,var(--primary))] shadow-lg transition-colors duration-200 sm:h-12 sm:w-12\">\n                      <Play className=\"ml-0.5 h-3.5 w-3.5 fill-primary-foreground text-primary-foreground sm:h-5 sm:w-5\" />\n                    </span>\n                    <span className=\"pr-1 text-xs font-extrabold tracking-tight text-white sm:pr-2 sm:text-base md:text-lg\">\n                      {playButtonLabel}\n                    </span>\n                  </button>\n                </div>\n\n                {/* Bottom Narrative Typography */}\n                <div className=\"max-w-2xl\">\n                  {title && (\n                    <h3 className=\"mb-1 line-clamp-2 text-base leading-snug font-extrabold tracking-tight text-white drop-shadow-sm sm:mb-2 sm:text-2xl sm:leading-tight md:text-3xl lg:text-4xl\">\n                      {title}\n                    </h3>\n                  )}\n                  {subtitle && (\n                    <p className=\"line-clamp-1 text-[11px] leading-relaxed font-normal text-zinc-300 sm:line-clamp-2 sm:text-xs md:text-base\">\n                      {subtitle}\n                    </p>\n                  )}\n                </div>\n              </div>\n            </>\n          )}\n        </div>\n\n        {/* Modal Dialog */}\n        {modalMounted && (\n          <>\n            <style>{MODAL_CSS}</style>\n            <div\n              data-state={modalOpen ? \"open\" : \"closed\"}\n              className=\"video-player-backdrop fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-3 backdrop-blur-sm sm:p-6 md:p-10\"\n              onClick={handleClose}\n            >\n              {/* Modal Content Box */}\n              <div\n                role=\"dialog\"\n                aria-modal=\"true\"\n                aria-label={title || \"Video player\"}\n                data-state={modalOpen ? \"open\" : \"closed\"}\n                onTransitionEnd={(e) => {\n                  if (e.target === e.currentTarget && !modalOpen) {\n                    setModalMounted(false);\n                  }\n                }}\n                className={cn(\n                  \"video-player-dialog relative z-50 flex min-h-[220px] w-full flex-col overflow-hidden rounded-xl border border-zinc-800 bg-zinc-950 shadow-2xl sm:min-h-0 sm:rounded-2xl md:rounded-3xl\",\n                  modalSizes[modalSize],\n                  modalSize === \"full\" ? \"h-[90vh]\" : aspectRatios[aspectRatio],\n                )}\n                onClick={(e) => e.stopPropagation()}\n              >\n                {/* Modal Header Bar */}\n                <div className=\"absolute top-2.5 right-2.5 z-20 flex items-center gap-2 sm:top-4 sm:right-4\">\n                  <CloseButton\n                    onClick={handleClose}\n                    buttonRef={closeRef}\n                    label=\"Close modal\"\n                  />\n                </div>\n\n                {/* Video Player Embed / Frame */}\n                <div className=\"relative h-full w-full flex-1 bg-black\">\n                  {frame}\n                </div>\n              </div>\n            </div>\n          </>\n        )}\n      </div>\n    );\n  },\n);\n\nVideoPlayer.displayName = \"VideoPlayer\";\n",
      "type": "registry:component",
      "target": "components/custom/blocks/VideoPlayerBlock.tsx"
    },
    {
      "path": "src/components/custom/blocks/motion-curves.ts",
      "content": "/**\n * Motion curves with no animation library behind them.\n *\n * The components here ship as CSS, GSAP or Motion builds that must move\n * identically, so the curves are computed once, from the same numbers, and\n * handed to whichever engine runs them:\n *\n *   - `cubicBezier(x1, y1, x2, y2)` → an easing function (GSAP accepts any\n *     `(progress) => value` as `ease`), exact for Motion's `ease: [..]` arrays\n *     and for CSS `cubic-bezier()`.\n *   - `spring({ stiffness, damping, mass })` → the analytic solution Motion\n *     Motion uses, as an easing function plus the time it takes to settle, or\n *     as a CSS `linear()` string for a fixed start and end.\n *   - `createSpringFollower` → a value that chases a moving target through the\n *     same spring every frame, like Motion's `useSpring`, for pointer-driven\n *     motion that no fixed curve can describe.\n */\n\n// ---------------------------------------------------------------------------\n// Cubic bezier\n// ---------------------------------------------------------------------------\n\n/**\n * The CSS / Motion cubic-bezier as a function of progress. Newton-Raphson\n * with a bisection fallback, the same solver browsers use.\n */\nexport function cubicBezier(x1: number, y1: number, x2: number, y2: number) {\n  if (x1 === y1 && x2 === y2) return (t: number) => t;\n\n  const a = (p1: number, p2: number) => 1 - 3 * p2 + 3 * p1;\n  const b = (p1: number, p2: number) => 3 * p2 - 6 * p1;\n  const c = (p1: number) => 3 * p1;\n  const at = (t: number, p1: number, p2: number) =>\n    ((a(p1, p2) * t + b(p1, p2)) * t + c(p1)) * t;\n  const slope = (t: number, p1: number, p2: number) =>\n    3 * a(p1, p2) * t * t + 2 * b(p1, p2) * t + c(p1);\n\n  const solveX = (x: number) => {\n    let t = x;\n    for (let i = 0; i < 8; i++) {\n      const s = slope(t, x1, x2);\n      if (Math.abs(s) < 1e-6) break;\n      const err = at(t, x1, x2) - x;\n      if (Math.abs(err) < 1e-7) return t;\n      t -= err / s;\n    }\n    let lo = 0;\n    let hi = 1;\n    t = x;\n    for (let i = 0; i < 30 && hi - lo > 1e-7; i++) {\n      const value = at(t, x1, x2);\n      if (value < x) lo = t;\n      else hi = t;\n      t = (lo + hi) / 2;\n    }\n    return t;\n  };\n\n  return (x: number) => (x <= 0 ? 0 : x >= 1 ? 1 : at(solveX(x), y1, y2));\n}\n\n/** Motion's named eases, as the cubic-beziers they are. */\nexport const MOTION_EASE = {\n  linear: [0, 0, 1, 1],\n  easeIn: [0.42, 0, 1, 1],\n  easeOut: [0, 0, 0.58, 1],\n  easeInOut: [0.42, 0, 0.58, 1],\n  circIn: [0.55, 0, 1, 0.45],\n  circOut: [0.55, 0, 0.45, 1],\n  circInOut: [0.85, 0, 0.15, 1],\n  backIn: [0.31, 0.01, 0.66, -0.59],\n  backOut: [0.33, 1.53, 0.69, 0.99],\n  anticipate: [0.66, -0.56, 0.34, 1.35],\n} as const;\n\n/**\n * Motion's default layout transition (`layout` / `layoutId`):\n * `{ duration: 0.45, ease: [0.4, 0, 0.1, 1] }`.\n */\nexport const LAYOUT_TRANSITION = { duration: 0.45, ease: [0.4, 0, 0.1, 1] as const };\n\n// ---------------------------------------------------------------------------\n// Spring\n// ---------------------------------------------------------------------------\n\nexport interface SpringOptions {\n  /** Motion default 100. */\n  stiffness?: number;\n  /** Motion default 10. */\n  damping?: number;\n  /** Motion default 1. */\n  mass?: number;\n  /** Starting velocity, in units of the whole distance per second. */\n  velocity?: number;\n  /** How close to the end counts as settled, as a fraction of the distance. */\n  restDelta?: number;\n}\n\n/**\n * Normalised position (0 → 1) of a spring released from 0 towards 1, at time\n * `t` seconds. The closed-form solution Motion's `spring()` generator\n * uses for the under-, critically and over-damped cases.\n */\nexport function springAt(options: SpringOptions = {}) {\n  const { stiffness = 100, damping = 10, mass = 1, velocity = 0 } = options;\n  const zeta = damping / (2 * Math.sqrt(stiffness * mass));\n  const omega0 = Math.sqrt(stiffness / mass);\n  // Motion's convention: distance still to cover, velocity toward it negated.\n  const delta = 1;\n  const v0 = -velocity;\n\n  if (zeta < 1) {\n    const omegaD = omega0 * Math.sqrt(1 - zeta * zeta);\n    return (t: number) => {\n      const envelope = Math.exp(-zeta * omega0 * t);\n      return (\n        1 -\n        envelope *\n          (((v0 + zeta * omega0 * delta) / omegaD) * Math.sin(omegaD * t) +\n            delta * Math.cos(omegaD * t))\n      );\n    };\n  }\n  if (zeta === 1) {\n    return (t: number) => 1 - Math.exp(-omega0 * t) * (delta + (v0 + omega0 * delta) * t);\n  }\n  const omegaD = omega0 * Math.sqrt(zeta * zeta - 1);\n  return (t: number) => {\n    const envelope = Math.exp(-zeta * omega0 * t);\n    const freq = Math.min(omegaD * t, 300);\n    return (\n      1 -\n      (envelope *\n        ((v0 + zeta * omega0 * delta) * Math.sinh(freq) + omegaD * delta * Math.cosh(freq))) /\n        omegaD\n    );\n  };\n}\n\n/** Seconds until the spring stays within `restDelta` of its end. */\nexport function springDuration(options: SpringOptions = {}) {\n  const at = springAt(options);\n  const restDelta = options.restDelta ?? 0.001;\n  const step = 1 / 240;\n  let lastOutside = 0;\n  for (let t = 0; t <= 10; t += step) {\n    if (Math.abs(1 - at(t)) > restDelta) lastOutside = t;\n    else if (t - lastOutside > 0.1) break;\n  }\n  return Math.max(lastOutside + step, step);\n}\n\n/**\n * A spring as a duration and an easing function over it — what GSAP takes:\n *\n *   const { duration, ease } = springEase({ stiffness: 300, damping: 20 });\n *   gsap.to(el, { y: 0, duration, ease });\n *\n * Exact for a fixed start and end; a spring that has to react mid-flight to a\n * new target needs `createSpringFollower` instead.\n */\nexport function springEase(options: SpringOptions = {}) {\n  const duration = springDuration(options);\n  const at = springAt(options);\n  return {\n    duration,\n    ease: (progress: number) => (progress >= 1 ? 1 : at(progress * duration)),\n  };\n}\n\n/**\n * A spring as a CSS `linear()` easing and its duration in ms, for\n * `transition` / `animation` with a fixed start and end.\n *\n *   const { easing, duration } = springLinear({ stiffness: 400, damping: 30 });\n *   el.style.transition = `transform ${duration}ms ${easing}`;\n */\nexport function springLinear(options: SpringOptions = {}, pointsPerSecond = 60) {\n  const duration = springDuration(options);\n  const at = springAt(options);\n  const count = Math.max(Math.ceil(duration * pointsPerSecond), 8);\n  const points: string[] = [];\n  for (let i = 0; i <= count; i++) {\n    const t = (i / count) * duration;\n    points.push(String(Math.round((i === count ? 1 : at(t)) * 10000) / 10000));\n  }\n  return { easing: `linear(${points.join(\", \")})`, duration: Math.round(duration * 1000) };\n}\n\n// ---------------------------------------------------------------------------\n// Spring follower (useSpring equivalent)\n// ---------------------------------------------------------------------------\n\n/** Something that calls back once per frame with the time since the last, in ms. */\nexport interface FrameTicker {\n  add: (callback: (deltaMs: number) => void) => () => void;\n}\n\n/** requestAnimationFrame as a ticker — the library-free default. */\nexport const rafTicker: FrameTicker = {\n  add(callback) {\n    let last = performance.now();\n    let frame = requestAnimationFrame(function tick(now) {\n      callback(now - last);\n      last = now;\n      frame = requestAnimationFrame(tick);\n    });\n    return () => cancelAnimationFrame(frame);\n  },\n};\n\nexport interface SpringFollower {\n  /** Chase a new target from wherever the value is now, keeping its velocity. */\n  set: (target: number) => void;\n  /** Move to a value instantly, with no motion. */\n  jump: (value: number) => void;\n  get: () => number;\n  destroy: () => void;\n}\n\n/**\n * A value that follows its target through a spring, integrating the same\n * equation of motion Motion's `useSpring` solves — so a pointer-driven spring\n * reads the same in every build. Runs only while moving; `onUpdate` receives\n * each new value.\n */\nexport function createSpringFollower(\n  initial: number,\n  onUpdate: (value: number) => void,\n  options: SpringOptions & { restSpeed?: number; ticker?: FrameTicker } = {},\n): SpringFollower {\n  const { stiffness = 100, damping = 10, mass = 1, ticker = rafTicker } = options;\n  const restDelta = options.restDelta ?? 0.01;\n  const restSpeed = options.restSpeed ?? 0.01;\n  let value = initial;\n  let target = initial;\n  let velocity = 0;\n  let stop: (() => void) | null = null;\n\n  const step = (deltaMs: number) => {\n    // Fixed 1ms sub-steps keep the integration stable for stiff springs and\n    // independent of the frame rate.\n    const steps = Math.min(Math.max(Math.round(deltaMs), 1), 250);\n    for (let i = 0; i < steps; i++) {\n      const force = -stiffness * (value - target) - damping * velocity;\n      velocity += (force / mass) * 0.001;\n      value += velocity * 0.001;\n    }\n    if (Math.abs(target - value) < restDelta && Math.abs(velocity) < restSpeed) {\n      value = target;\n      velocity = 0;\n      stop?.();\n      stop = null;\n    }\n    onUpdate(value);\n  };\n\n  return {\n    set(next) {\n      target = next;\n      if (!stop && value !== target) stop = ticker.add(step);\n    },\n    jump(next) {\n      stop?.();\n      stop = null;\n      value = target = next;\n      velocity = 0;\n      onUpdate(value);\n    },\n    get: () => value,\n    destroy() {\n      stop?.();\n      stop = null;\n    },\n  };\n}\n",
      "type": "registry:component",
      "target": "components/custom/blocks/motion-curves.ts"
    }
  ],
  "docs": "Named export: VideoPlayer. `videoUrl` and `thumbnailUrl` drive it; `playbackMode` is modal | inline | direct and `source` is youtube | video (a native <video>). `aspectRatio` is 16/9 | 21/9 | 4/3 | 1/1 and `modalSize` is md | lg | xl | full. `onPlay` and `onClose` hook into analytics. In modal and inline the media only loads on click, so it stays off the initial page weight; `direct` renders it immediately and honours `autoPlay` / `muted` / `loop`.",
  "categories": [
    "marketing",
    "media"
  ],
  "type": "registry:component"
}
