{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "video-text-mask-hero",
  "title": "Video Text Mask Hero",
  "description": "A hero where a video plays through one giant word. Press play and the letters rush past the camera to open up the full film; Close or Escape brings them back.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/video-text-mask-hero/video-text-mask-hero.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type VideoMaskTheme = \"dark\" | \"light\";\n\nexport interface VideoTextMaskHeroProps extends React.ComponentPropsWithoutRef<\"section\"> {\n  theme?: VideoMaskTheme;\n  /** The word the video plays through. Short words read best. */\n  word?: string;\n  eyebrow?: string;\n  /** Small text across from the eyebrow. */\n  meta?: string;\n  description?: string;\n  videoSrc?: string;\n  /** Still shown before the video loads and for visitors who prefer reduced motion. */\n  poster?: string;\n  /** Button that opens the letters up to the full video. Pass an empty string to hide it. */\n  watchLabel?: string;\n  closeLabel?: string;\n  /** Size of the word as a percentage of the width. Worked out from its length when left out. */\n  wordSize?: number;\n  /** Height from tablet width up, in px. */\n  minHeight?: number;\n  /** Called when the full video opens or closes. */\n  onOpenChange?: (open: boolean) => void;\n}\n\nconst PALETTES = {\n  dark: {\n    plate: \"#000000\",\n    letters: \"#FFFFFF\",\n    blend: \"multiply\" as const,\n    text: \"#FFFFFF\",\n    sub: \"rgba(255,255,255,0.66)\",\n    btn: \"#FFFFFF\",\n    btnText: \"#000000\",\n    video: \"none\",\n  },\n  light: {\n    plate: \"#FFFFFF\",\n    letters: \"#000000\",\n    blend: \"screen\" as const,\n    text: \"#0B0B0B\",\n    sub: \"rgba(11,11,11,0.62)\",\n    btn: \"#0B0B0B\",\n    btnText: \"#FFFFFF\",\n    // White letters of light would vanish on white, so the footage is pulled darker here.\n    video: \"brightness(0.62) contrast(1.25)\",\n  },\n};\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\nexport function VideoTextMaskHero({\n  theme = \"dark\",\n  word = \"MOVE\",\n  eyebrow = \"The spring film\",\n  meta = \"Four minutes, one take\",\n  description = \"Shot in a single afternoon with nothing but a floor, a light and someone who refused to stop.\",\n  videoSrc = \"/demo/16.mp4\",\n  poster,\n  watchLabel = \"Watch the film\",\n  closeLabel = \"Close\",\n  wordSize,\n  minHeight = 720,\n  onOpenChange,\n  className,\n  style,\n  ...props\n}: VideoTextMaskHeroProps) {\n  const pal = PALETTES[theme];\n  const reduce = useReducedMotion();\n  const rootRef = React.useRef<HTMLElement>(null);\n  const videoRef = React.useRef<HTMLVideoElement>(null);\n  const closeRef = React.useRef<HTMLButtonElement>(null);\n  const openRef = React.useRef<HTMLButtonElement>(null);\n  const wasOpen = React.useRef(false);\n  const [open, setOpen] = React.useState(false);\n  const size = wordSize ?? Math.min(36, 96 / (Math.max(word.length, 1) * 0.78));\n\n  const toggle = React.useCallback(\n    (next: boolean) => {\n      setOpen(next);\n      onOpenChange?.(next);\n    },\n    [onOpenChange],\n  );\n\n  // The video only runs while it is on screen.\n  React.useEffect(() => {\n    const root = rootRef.current;\n    const video = videoRef.current;\n    if (!root || !video) return;\n    if (reduce) {\n      video.pause();\n      return;\n    }\n    const io = new IntersectionObserver(([entry]) => {\n      if (entry.isIntersecting) video.play().catch(() => {});\n      else video.pause();\n    });\n    io.observe(root);\n    return () => io.disconnect();\n  }, [reduce]);\n\n  // Focus follows the film in and out, once the button it is going to can take it.\n  React.useEffect(() => {\n    if (open) closeRef.current?.focus();\n    else if (wasOpen.current) openRef.current?.focus();\n    wasOpen.current = open;\n  }, [open]);\n\n  React.useEffect(() => {\n    if (!open) return;\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") toggle(false);\n    };\n    window.addEventListener(\"keydown\", onKey);\n    return () => window.removeEventListener(\"keydown\", onKey);\n  }, [open, toggle]);\n\n  const fade = \"transition-opacity duration-500 motion-reduce:transition-none\";\n  return (\n    <section\n      ref={rootRef}\n      className={cn(\"@container relative w-full overflow-hidden\", className)}\n      style={\n        {\n          \"--h\": `${minHeight}px`,\n          background: pal.plate,\n          color: pal.text,\n          fontFamily: \"Inter, -apple-system, BlinkMacSystemFont, sans-serif\",\n          ...style,\n        } as React.CSSProperties\n      }\n      {...props}\n    >\n      <div className=\"relative isolate flex min-h-[540px] flex-col justify-between p-5 @[640px]:min-h-[var(--h)] @[640px]:p-9\">\n        <video\n          ref={videoRef}\n          src={videoSrc}\n          poster={poster}\n          muted\n          loop\n          playsInline\n          preload=\"auto\"\n          aria-hidden=\"true\"\n          className=\"absolute inset-0 size-full object-cover transition-[filter] duration-700\"\n          style={{ filter: open ? \"none\" : pal.video }}\n        />\n\n        {/* A plate blended over the video: it hides everything except the letters. */}\n        <div\n          className=\"pointer-events-none absolute inset-0 grid place-items-center overflow-hidden motion-safe:transition-[transform,opacity] motion-safe:ease-[cubic-bezier(0.7,0,0.2,1)]\"\n          style={{\n            background: pal.plate,\n            mixBlendMode: pal.blend,\n            transform: open ? \"scale(7)\" : \"none\",\n            opacity: open ? 0 : 1,\n            transitionDuration: \"1100ms, 700ms\",\n            transitionDelay: open ? \"0ms, 350ms\" : \"0ms, 0ms\",\n          }}\n        >\n          <h1\n            className=\"m-0 font-black whitespace-nowrap select-none\"\n            style={{\n              color: pal.letters,\n              fontSize: `${size}cqw`,\n              letterSpacing: \"-0.05em\",\n              lineHeight: 0.8,\n            }}\n          >\n            {word}\n          </h1>\n        </div>\n\n        <div\n          className={cn(\n            \"relative z-10 flex items-start justify-between gap-4 text-[13px] font-medium\",\n            fade,\n          )}\n          style={{ opacity: open ? 0 : 1 }}\n        >\n          <p className=\"m-0\">{eyebrow}</p>\n          <p className=\"m-0 text-right\" style={{ color: pal.sub }}>\n            {meta}\n          </p>\n        </div>\n\n        <div\n          inert={open}\n          className={cn(\n            \"relative z-10 flex flex-col gap-4 @[640px]:flex-row @[640px]:items-end @[640px]:justify-between\",\n            fade,\n          )}\n          style={{ opacity: open ? 0 : 1 }}\n        >\n          <p\n            className=\"m-0 max-w-[38ch] text-[15px] leading-snug\"\n            style={{ color: pal.sub }}\n          >\n            {description}\n          </p>\n          {watchLabel && (\n            <button\n              ref={openRef}\n              type=\"button\"\n              onClick={() => toggle(true)}\n              className=\"inline-flex h-11 shrink-0 cursor-pointer items-center gap-2.5 self-start rounded-full pr-5 pl-4 text-[14px] font-semibold transition-opacity hover:opacity-85 @[640px]:self-auto\"\n              style={{ background: pal.btn, color: pal.btnText }}\n            >\n              <svg\n                width=\"12\"\n                height=\"14\"\n                viewBox=\"0 0 12 14\"\n                fill=\"currentColor\"\n                aria-hidden=\"true\"\n              >\n                <path d=\"M1 1.6v10.8c0 .8.9 1.3 1.6.8l8.4-5.4c.6-.4.6-1.2 0-1.6L2.6.8C1.9.3 1 .8 1 1.6Z\" />\n              </svg>\n              {watchLabel}\n            </button>\n          )}\n        </div>\n\n        <button\n          ref={closeRef}\n          type=\"button\"\n          tabIndex={open ? 0 : -1}\n          aria-hidden={!open}\n          onClick={() => toggle(false)}\n          className={cn(\n            \"absolute top-5 right-5 z-20 flex h-10 cursor-pointer items-center gap-2 rounded-full bg-black/55 px-4 text-[13px] font-medium text-white backdrop-blur-md @[640px]:top-9 @[640px]:right-9\",\n            fade,\n            !open && \"pointer-events-none\",\n          )}\n          style={{ opacity: open ? 1 : 0 }}\n        >\n          <svg\n            width=\"11\"\n            height=\"11\"\n            viewBox=\"0 0 11 11\"\n            fill=\"none\"\n            stroke=\"currentColor\"\n            strokeWidth=\"1.8\"\n            strokeLinecap=\"round\"\n            aria-hidden=\"true\"\n          >\n            <path d=\"m1 1 9 9M10 1l-9 9\" />\n          </svg>\n          {closeLabel}\n        </button>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}