{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "grid-beams-background",
  "type": "registry:ui",
  "title": "GridBeamsBackground",
  "description": "Animated landing-page background: a subtle token-colored line grid with seeded light beams tracing along grid lines. Motion-powered, SSR-deterministic, offscreen-paused, with a designed reduced-motion static fallback.",
  "dependencies": [
    "motion@^12.43.0"
  ],
  "devDependencies": [],
  "registryDependencies": [
    "https://components.dethink.co.uk/r/dethink-base.json"
  ],
  "files": [
    {
      "path": "packages/components/src/components/grid-beams-background/grid-beams-background.tsx",
      "type": "registry:file",
      "target": "~/components/dethink/components/grid-beams-background/grid-beams-background.tsx",
      "content": "import {\n  forwardRef,\n  useCallback,\n  useEffect,\n  useLayoutEffect,\n  useMemo,\n  useRef,\n  useState,\n  type CSSProperties,\n  type ForwardedRef,\n  type HTMLAttributes,\n  type ReactNode,\n} from \"react\";\nimport {\n  MotionConfig,\n  motion as motionElement,\n  useReducedMotion,\n  type Transition,\n} from \"motion/react\";\nimport { cn } from \"../../utils/cn\";\nimport { usePageVisible } from \"../../utils/use-page-visible\";\nimport { mulberry32, seededRange } from \"../../utils/seeded-random\";\n\nexport type GridBeamsBackgroundDensity = \"sparse\" | \"normal\" | \"dense\";\nexport type GridBeamsBackgroundIntensity = \"faint\" | \"subtle\" | \"bold\";\nexport type GridBeamsBackgroundSpeed = \"slow\" | \"normal\" | \"fast\";\nexport type GridBeamsBackgroundTone = \"foreground\" | \"muted\" | \"primary\";\nexport type GridBeamsBackgroundBeamAxis = \"x\" | \"y\";\n\ntype MotionBackedEventProps =\n  | \"onAnimationEnd\"\n  | \"onAnimationEndCapture\"\n  | \"onAnimationIteration\"\n  | \"onAnimationIterationCapture\"\n  | \"onAnimationStart\"\n  | \"onAnimationStartCapture\"\n  | \"onDrag\"\n  | \"onDragCapture\"\n  | \"onDragEnd\"\n  | \"onDragEndCapture\"\n  | \"onDragEnter\"\n  | \"onDragEnterCapture\"\n  | \"onDragExit\"\n  | \"onDragExitCapture\"\n  | \"onDragLeave\"\n  | \"onDragLeaveCapture\"\n  | \"onDragOver\"\n  | \"onDragOverCapture\"\n  | \"onDragStart\"\n  | \"onDragStartCapture\";\n\ntype MotionSafeDivProps = Omit<\n  HTMLAttributes<HTMLDivElement>,\n  MotionBackedEventProps\n>;\n\nexport interface GridBeamsBackgroundProps extends MotionSafeDivProps {\n  animate?: boolean;\n  children?: ReactNode;\n  density?: GridBeamsBackgroundDensity;\n  intensity?: GridBeamsBackgroundIntensity;\n  seed?: number;\n  speed?: GridBeamsBackgroundSpeed;\n  tone?: GridBeamsBackgroundTone;\n}\n\nexport interface GridBeamsBackgroundMotionConfig {\n  animateEnabled: boolean;\n  beamDuration: number;\n  reducedMotion: boolean;\n  transition: Transition;\n}\n\nexport interface GridBeamsBackgroundBeam {\n  axis: GridBeamsBackgroundBeamAxis;\n  delay: number;\n  position: number;\n  repeatDelay: number;\n  staticOffset: number;\n}\n\nconst gridBeamsBackgroundSpeedDurations: Record<\n  GridBeamsBackgroundSpeed,\n  number\n> = {\n  slow: 9,\n  normal: 6,\n  fast: 3.5,\n};\n\nexport function getGridBeamsBackgroundMotionConfig(\n  speed: GridBeamsBackgroundSpeed,\n  reducedMotion = false,\n): GridBeamsBackgroundMotionConfig {\n  if (reducedMotion) {\n    return {\n      animateEnabled: false,\n      beamDuration: 0,\n      reducedMotion: true,\n      transition: { duration: 0 },\n    };\n  }\n\n  const beamDuration = gridBeamsBackgroundSpeedDurations[speed];\n\n  return {\n    animateEnabled: true,\n    beamDuration,\n    reducedMotion: false,\n    transition: { duration: beamDuration, ease: \"linear\", repeat: Infinity },\n  };\n}\n\nconst gridBeamsBackgroundBeamCounts: Record<\n  GridBeamsBackgroundDensity,\n  number\n> = {\n  sparse: 3,\n  normal: 5,\n  dense: 7,\n};\n\nfunction roundTo(value: number, decimals: number): number {\n  const factor = 10 ** decimals;\n  return Math.round(value * factor) / factor;\n}\n\nexport function getGridBeamsBackgroundGeometry(\n  seed: number,\n  density: GridBeamsBackgroundDensity,\n): GridBeamsBackgroundBeam[] {\n  const random = mulberry32(seed);\n\n  return Array.from({ length: gridBeamsBackgroundBeamCounts[density] }, () => ({\n    axis: (random() > 0.5 ? \"x\" : \"y\") as GridBeamsBackgroundBeamAxis,\n    position: Math.round(seededRange(random, 8, 92)),\n    delay: roundTo(seededRange(random, 0, 4), 2),\n    repeatDelay: roundTo(seededRange(random, 1.5, 5), 2),\n    staticOffset: Math.round(seededRange(random, 10, 60)),\n  }));\n}\n\nconst gridBeamsBackgroundRootClasses = \"relative isolate overflow-hidden\";\n\nconst gridBeamsBackgroundLayerClasses =\n  \"pointer-events-none absolute inset-0 select-none\";\n\nconst gridBeamsBackgroundContentClasses = \"relative z-10\";\n\nconst gridBeamsBackgroundPatternClasses =\n  \"absolute inset-0 [background-image:linear-gradient(to_right,currentColor_1px,transparent_1px),linear-gradient(to_bottom,currentColor_1px,transparent_1px)]\";\n\nconst gridBeamsBackgroundDensityClasses: Record<\n  GridBeamsBackgroundDensity,\n  string\n> = {\n  sparse: \"[background-size:96px_96px]\",\n  normal: \"[background-size:56px_56px]\",\n  dense: \"[background-size:32px_32px]\",\n};\n\nconst gridBeamsBackgroundToneIntensityClasses: Record<\n  GridBeamsBackgroundTone,\n  Record<GridBeamsBackgroundIntensity, string>\n> = {\n  foreground: {\n    faint: \"text-foreground/5 dark:text-foreground/10\",\n    subtle: \"text-foreground/10 dark:text-foreground/15\",\n    bold: \"text-foreground/15 dark:text-foreground/25\",\n  },\n  muted: {\n    faint: \"text-muted-foreground/10 dark:text-muted-foreground/15\",\n    subtle: \"text-muted-foreground/15 dark:text-muted-foreground/25\",\n    bold: \"text-muted-foreground/25 dark:text-muted-foreground/40\",\n  },\n  primary: {\n    faint: \"text-primary/5 dark:text-primary/10\",\n    subtle: \"text-primary/10 dark:text-primary/20\",\n    bold: \"text-primary/20 dark:text-primary/30\",\n  },\n};\n\nconst gridBeamsBackgroundBeamToneClasses: Record<\n  GridBeamsBackgroundTone,\n  string\n> = {\n  foreground: \"text-foreground/40 dark:text-foreground/50\",\n  muted: \"text-muted-foreground/40 dark:text-muted-foreground/50\",\n  primary: \"text-primary/60 dark:text-primary/70\",\n};\n\nconst gridBeamsBackgroundRailClasses: Record<\n  GridBeamsBackgroundBeamAxis,\n  string\n> = {\n  x: \"absolute inset-x-0 h-px\",\n  y: \"absolute inset-y-0 w-px\",\n};\n\nconst gridBeamsBackgroundBeamClasses: Record<\n  GridBeamsBackgroundBeamAxis,\n  string\n> = {\n  x: \"absolute inset-y-0 w-[30%] bg-gradient-to-r from-transparent via-current to-transparent\",\n  y: \"absolute inset-x-0 h-[30%] bg-gradient-to-b from-transparent via-current to-transparent\",\n};\n\nexport interface GridBeamsBackgroundClassNamesOptions {\n  className?: string;\n}\n\nexport function gridBeamsBackgroundClassNames({\n  className,\n}: GridBeamsBackgroundClassNamesOptions = {}) {\n  return cn(gridBeamsBackgroundRootClasses, className);\n}\n\nexport interface GridBeamsBackgroundLayerClassNamesOptions {\n  className?: string;\n  intensity?: GridBeamsBackgroundIntensity;\n  tone?: GridBeamsBackgroundTone;\n}\n\nexport function gridBeamsBackgroundLayerClassNames({\n  className,\n  intensity = \"subtle\",\n  tone = \"muted\",\n}: GridBeamsBackgroundLayerClassNamesOptions = {}) {\n  return cn(\n    gridBeamsBackgroundLayerClasses,\n    gridBeamsBackgroundToneIntensityClasses[tone][intensity],\n    className,\n  );\n}\n\nexport interface GridBeamsBackgroundContentClassNamesOptions {\n  className?: string;\n}\n\nexport function gridBeamsBackgroundContentClassNames({\n  className,\n}: GridBeamsBackgroundContentClassNamesOptions = {}) {\n  return cn(gridBeamsBackgroundContentClasses, className);\n}\n\nconst useIsomorphicLayoutEffect =\n  typeof window === \"undefined\" ? useEffect : useLayoutEffect;\n\nfunction useHasHydrated() {\n  const [hasHydrated, setHasHydrated] = useState(false);\n\n  useIsomorphicLayoutEffect(() => {\n    setHasHydrated(true);\n  }, []);\n\n  return hasHydrated;\n}\n\n// Pauses looping animations while the background is scrolled offscreen.\n// Fails open (stays true) where IntersectionObserver is unavailable so the\n// background still animates in older browsers and jsdom.\nfunction useDecorativeInView(ref: { current: HTMLElement | null }) {\n  const [inView, setInView] = useState(true);\n\n  useEffect(() => {\n    const element = ref.current;\n\n    if (\n      !element ||\n      typeof window === \"undefined\" ||\n      !(\"IntersectionObserver\" in window)\n    ) {\n      return;\n    }\n\n    const observer = new window.IntersectionObserver(([entry]) => {\n      if (entry) {\n        setInView(entry.isIntersecting);\n      }\n    });\n\n    observer.observe(element);\n\n    return () => observer.disconnect();\n  }, [ref]);\n\n  return inView;\n}\n\nfunction railStyle(beam: GridBeamsBackgroundBeam): CSSProperties {\n  return beam.axis === \"x\"\n    ? { top: `${beam.position}%` }\n    : { left: `${beam.position}%` };\n}\n\nexport const GridBeamsBackground = forwardRef(function GridBeamsBackground(\n  {\n    animate = true,\n    children,\n    className,\n    density = \"normal\",\n    intensity = \"subtle\",\n    seed = 1,\n    speed = \"normal\",\n    tone = \"muted\",\n    ...props\n  }: GridBeamsBackgroundProps,\n  forwardedRef: ForwardedRef<HTMLDivElement>,\n) {\n  const localRef = useRef<HTMLDivElement | null>(null);\n  const composedRef = useCallback(\n    (node: HTMLDivElement | null) => {\n      localRef.current = node;\n\n      if (typeof forwardedRef === \"function\") {\n        forwardedRef(node);\n      } else if (forwardedRef) {\n        forwardedRef.current = node;\n      }\n    },\n    [forwardedRef],\n  );\n\n  const hasHydrated = useHasHydrated();\n  const prefersReducedMotion = useReducedMotion();\n  const inView = useDecorativeInView(localRef);\n  // OS preference is only trusted after hydration so the first client render\n  // matches the server render exactly; animate={false} is deterministic on\n  // both sides and applies immediately.\n  const reducedMotion =\n    !animate || (hasHydrated && prefersReducedMotion === true);\n  const pageVisible = usePageVisible();\n  const running = hasHydrated && !reducedMotion && inView && pageVisible;\n\n  const motionConfig = getGridBeamsBackgroundMotionConfig(speed, reducedMotion);\n  const beams = useMemo(\n    () => getGridBeamsBackgroundGeometry(seed, density),\n    [seed, density],\n  );\n\n  return (\n    <MotionConfig reducedMotion={reducedMotion ? \"always\" : \"user\"}>\n      <div\n        {...props}\n        ref={composedRef}\n        data-slot=\"grid-beams-background\"\n        data-animate={animate ? \"true\" : \"false\"}\n        data-density={density}\n        data-intensity={intensity}\n        data-speed={speed}\n        data-tone={tone}\n        data-reduced-motion={reducedMotion ? \"true\" : undefined}\n        className={gridBeamsBackgroundClassNames({ className })}\n      >\n        <div\n          aria-hidden=\"true\"\n          data-slot=\"grid-beams-background-layer\"\n          className={gridBeamsBackgroundLayerClassNames({ intensity, tone })}\n        >\n          <div\n            className={cn(\n              gridBeamsBackgroundPatternClasses,\n              gridBeamsBackgroundDensityClasses[density],\n            )}\n          />\n          {running\n            ? beams.map((beam, index) => (\n                <div\n                  key={index}\n                  className={gridBeamsBackgroundRailClasses[beam.axis]}\n                  style={railStyle(beam)}\n                >\n                  <motionElement.div\n                    data-slot=\"grid-beams-background-beam\"\n                    className={cn(\n                      gridBeamsBackgroundBeamClasses[beam.axis],\n                      gridBeamsBackgroundBeamToneClasses[tone],\n                      beam.axis === \"x\" ? \"left-0\" : \"top-0\",\n                    )}\n                    initial={\n                      beam.axis === \"x\" ? { x: \"-100%\" } : { y: \"-100%\" }\n                    }\n                    animate={beam.axis === \"x\" ? { x: \"433%\" } : { y: \"433%\" }}\n                    transition={{\n                      ...motionConfig.transition,\n                      delay: beam.delay,\n                      repeatDelay: beam.repeatDelay,\n                    }}\n                  />\n                </div>\n              ))\n            : beams.slice(0, 2).map((beam, index) => (\n                <div\n                  key={index}\n                  className={gridBeamsBackgroundRailClasses[beam.axis]}\n                  style={railStyle(beam)}\n                >\n                  <div\n                    data-slot=\"grid-beams-background-beam\"\n                    className={cn(\n                      gridBeamsBackgroundBeamClasses[beam.axis],\n                      gridBeamsBackgroundBeamToneClasses[tone],\n                      \"opacity-40\",\n                    )}\n                    style={\n                      beam.axis === \"x\"\n                        ? { left: `${beam.staticOffset}%` }\n                        : { top: `${beam.staticOffset}%` }\n                    }\n                  />\n                </div>\n              ))}\n        </div>\n        <div\n          data-slot=\"grid-beams-background-content\"\n          className={gridBeamsBackgroundContentClassNames()}\n        >\n          {children}\n        </div>\n      </div>\n    </MotionConfig>\n  );\n});\n\nGridBeamsBackground.displayName = \"GridBeamsBackground\";\n"
    },
    {
      "path": "packages/components/src/components/grid-beams-background/index.ts",
      "type": "registry:file",
      "target": "~/components/dethink/components/grid-beams-background/index.ts",
      "content": "export {\n  GridBeamsBackground,\n  getGridBeamsBackgroundGeometry,\n  getGridBeamsBackgroundMotionConfig,\n  gridBeamsBackgroundClassNames,\n  gridBeamsBackgroundContentClassNames,\n  gridBeamsBackgroundLayerClassNames,\n  type GridBeamsBackgroundBeam,\n  type GridBeamsBackgroundBeamAxis,\n  type GridBeamsBackgroundClassNamesOptions,\n  type GridBeamsBackgroundContentClassNamesOptions,\n  type GridBeamsBackgroundDensity,\n  type GridBeamsBackgroundIntensity,\n  type GridBeamsBackgroundLayerClassNamesOptions,\n  type GridBeamsBackgroundMotionConfig,\n  type GridBeamsBackgroundProps,\n  type GridBeamsBackgroundSpeed,\n  type GridBeamsBackgroundTone,\n} from \"./grid-beams-background\";\n"
    },
    {
      "path": "packages/components/src/utils/cn.ts",
      "type": "registry:file",
      "target": "~/components/dethink/utils/cn.ts",
      "content": "import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n"
    },
    {
      "path": "packages/components/src/utils/seeded-random.ts",
      "type": "registry:file",
      "target": "~/components/dethink/utils/seeded-random.ts",
      "content": "/**\n * Deterministic pseudo-random helpers for decorative components. Background\n * components must render identical markup on the server and every client\n * render, so all \"random\" placement flows through a caller-provided seed\n * instead of Math.random().\n */\nexport function mulberry32(seed: number): () => number {\n  let state = seed >>> 0;\n\n  return () => {\n    state = (state + 0x6d2b79f5) >>> 0;\n    let t = state;\n    t = Math.imul(t ^ (t >>> 15), t | 1);\n    t ^= t + Math.imul(t ^ (t >>> 7), t | 61);\n    return ((t ^ (t >>> 14)) >>> 0) / 4294967296;\n  };\n}\n\nexport function seededRange(\n  random: () => number,\n  min: number,\n  max: number,\n): number {\n  return min + (max - min) * random();\n}\n\nexport function seededPick<T>(random: () => number, values: readonly T[]): T {\n  return values[\n    Math.min(values.length - 1, Math.floor(random() * values.length))\n  ];\n}\n"
    }
  ]
}
