{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "scan-grid-background",
  "type": "registry:ui",
  "title": "ScanGridBackground",
  "description": "Animated landing-page background: a token-colored line grid with a scanning highlight band sweeping vertically or horizontally. 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/scan-grid-background/scan-grid-background.tsx",
      "type": "registry:file",
      "target": "~/components/dethink/components/scan-grid-background/scan-grid-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 ScanGridBackgroundDensity = \"sparse\" | \"normal\" | \"dense\";\nexport type ScanGridBackgroundDirection = \"vertical\" | \"horizontal\";\nexport type ScanGridBackgroundIntensity = \"faint\" | \"subtle\" | \"bold\";\nexport type ScanGridBackgroundSpeed = \"slow\" | \"normal\" | \"fast\";\nexport type ScanGridBackgroundTone = \"foreground\" | \"muted\" | \"primary\";\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 ScanGridBackgroundProps extends MotionSafeDivProps {\n  animate?: boolean;\n  children?: ReactNode;\n  density?: ScanGridBackgroundDensity;\n  direction?: ScanGridBackgroundDirection;\n  intensity?: ScanGridBackgroundIntensity;\n  seed?: number;\n  speed?: ScanGridBackgroundSpeed;\n  tone?: ScanGridBackgroundTone;\n}\n\nexport interface ScanGridBackgroundMotionConfig {\n  animateEnabled: boolean;\n  reducedMotion: boolean;\n  repeatDelay: number;\n  scanDuration: number;\n  transition: Transition;\n}\n\nexport interface ScanGridBackgroundGeometry {\n  delay: number;\n  staticOffset: number;\n}\n\nconst scanGridBackgroundSpeedSettings: Record<\n  ScanGridBackgroundSpeed,\n  { duration: number; repeatDelay: number }\n> = {\n  slow: { duration: 12, repeatDelay: 2.5 },\n  normal: { duration: 8, repeatDelay: 1.5 },\n  fast: { duration: 5, repeatDelay: 0.75 },\n};\n\nexport function getScanGridBackgroundMotionConfig(\n  speed: ScanGridBackgroundSpeed,\n  reducedMotion = false,\n): ScanGridBackgroundMotionConfig {\n  if (reducedMotion) {\n    return {\n      animateEnabled: false,\n      reducedMotion: true,\n      repeatDelay: 0,\n      scanDuration: 0,\n      transition: { duration: 0 },\n    };\n  }\n\n  const { duration, repeatDelay } = scanGridBackgroundSpeedSettings[speed];\n\n  return {\n    animateEnabled: true,\n    reducedMotion: false,\n    repeatDelay,\n    scanDuration: duration,\n    transition: {\n      duration,\n      ease: \"linear\",\n      repeat: Infinity,\n      repeatDelay,\n    },\n  };\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 getScanGridBackgroundGeometry(\n  seed: number,\n): ScanGridBackgroundGeometry {\n  const random = mulberry32(seed);\n\n  return {\n    delay: roundTo(seededRange(random, 0, 2), 2),\n    staticOffset: Math.round(seededRange(random, 20, 45)),\n  };\n}\n\nconst scanGridBackgroundRootClasses = \"relative isolate overflow-hidden\";\n\nconst scanGridBackgroundLayerClasses =\n  \"pointer-events-none absolute inset-0 select-none\";\n\nconst scanGridBackgroundContentClasses = \"relative z-10\";\n\nconst scanGridBackgroundPatternClasses =\n  \"absolute inset-0 [background-image:linear-gradient(to_right,currentColor_1px,transparent_1px),linear-gradient(to_bottom,currentColor_1px,transparent_1px)]\";\n\nconst scanGridBackgroundDensityClasses: Record<\n  ScanGridBackgroundDensity,\n  string\n> = {\n  sparse: \"[background-size:96px_96px]\",\n  normal: \"[background-size:56px_56px]\",\n  dense: \"[background-size:32px_32px]\",\n};\n\nconst scanGridBackgroundToneIntensityClasses: Record<\n  ScanGridBackgroundTone,\n  Record<ScanGridBackgroundIntensity, 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 scanGridBackgroundBandToneClasses: Record<\n  ScanGridBackgroundTone,\n  string\n> = {\n  foreground: \"text-foreground/20 dark:text-foreground/25\",\n  muted: \"text-muted-foreground/20 dark:text-muted-foreground/30\",\n  primary: \"text-primary/30 dark:text-primary/40\",\n};\n\nconst scanGridBackgroundBandClasses: Record<\n  ScanGridBackgroundDirection,\n  string\n> = {\n  vertical:\n    \"absolute inset-x-0 h-[20%] bg-gradient-to-b from-transparent via-current to-transparent\",\n  horizontal:\n    \"absolute inset-y-0 w-[20%] bg-gradient-to-r from-transparent via-current to-transparent\",\n};\n\nconst scanGridBackgroundEdgeClasses: Record<\n  ScanGridBackgroundDirection,\n  string\n> = {\n  vertical: \"absolute inset-x-0 bottom-0 h-px bg-current opacity-60\",\n  horizontal: \"absolute inset-y-0 right-0 w-px bg-current opacity-60\",\n};\n\nexport interface ScanGridBackgroundClassNamesOptions {\n  className?: string;\n}\n\nexport function scanGridBackgroundClassNames({\n  className,\n}: ScanGridBackgroundClassNamesOptions = {}) {\n  return cn(scanGridBackgroundRootClasses, className);\n}\n\nexport interface ScanGridBackgroundLayerClassNamesOptions {\n  className?: string;\n  intensity?: ScanGridBackgroundIntensity;\n  tone?: ScanGridBackgroundTone;\n}\n\nexport function scanGridBackgroundLayerClassNames({\n  className,\n  intensity = \"subtle\",\n  tone = \"muted\",\n}: ScanGridBackgroundLayerClassNamesOptions = {}) {\n  return cn(\n    scanGridBackgroundLayerClasses,\n    scanGridBackgroundToneIntensityClasses[tone][intensity],\n    className,\n  );\n}\n\nexport interface ScanGridBackgroundContentClassNamesOptions {\n  className?: string;\n}\n\nexport function scanGridBackgroundContentClassNames({\n  className,\n}: ScanGridBackgroundContentClassNamesOptions = {}) {\n  return cn(scanGridBackgroundContentClasses, 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 the scan loop while the background is scrolled offscreen. Fails open\n// (stays true) where IntersectionObserver is unavailable so the background\n// 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\nexport const ScanGridBackground = forwardRef(function ScanGridBackground(\n  {\n    animate = true,\n    children,\n    className,\n    density = \"normal\",\n    direction = \"vertical\",\n    intensity = \"subtle\",\n    seed = 1,\n    speed = \"normal\",\n    tone = \"muted\",\n    ...props\n  }: ScanGridBackgroundProps,\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 = getScanGridBackgroundMotionConfig(speed, reducedMotion);\n  const geometry = useMemo(() => getScanGridBackgroundGeometry(seed), [seed]);\n\n  const bandClassName = cn(\n    scanGridBackgroundBandClasses[direction],\n    scanGridBackgroundBandToneClasses[tone],\n  );\n  const staticBandStyle: CSSProperties =\n    direction === \"vertical\"\n      ? { top: `${geometry.staticOffset}%` }\n      : { left: `${geometry.staticOffset}%` };\n\n  return (\n    <MotionConfig reducedMotion={reducedMotion ? \"always\" : \"user\"}>\n      <div\n        {...props}\n        ref={composedRef}\n        data-slot=\"scan-grid-background\"\n        data-animate={animate ? \"true\" : \"false\"}\n        data-density={density}\n        data-direction={direction}\n        data-intensity={intensity}\n        data-speed={speed}\n        data-tone={tone}\n        data-reduced-motion={reducedMotion ? \"true\" : undefined}\n        className={scanGridBackgroundClassNames({ className })}\n      >\n        <div\n          aria-hidden=\"true\"\n          data-slot=\"scan-grid-background-layer\"\n          className={scanGridBackgroundLayerClassNames({ intensity, tone })}\n        >\n          <div\n            className={cn(\n              scanGridBackgroundPatternClasses,\n              scanGridBackgroundDensityClasses[density],\n            )}\n          />\n          {running ? (\n            <motionElement.div\n              data-slot=\"scan-grid-background-band\"\n              className={cn(\n                bandClassName,\n                direction === \"vertical\" ? \"top-0\" : \"left-0\",\n              )}\n              initial={\n                direction === \"vertical\" ? { y: \"-100%\" } : { x: \"-100%\" }\n              }\n              animate={direction === \"vertical\" ? { y: \"500%\" } : { x: \"500%\" }}\n              transition={{\n                ...motionConfig.transition,\n                delay: geometry.delay,\n              }}\n            >\n              <div className={scanGridBackgroundEdgeClasses[direction]} />\n            </motionElement.div>\n          ) : (\n            <div\n              data-slot=\"scan-grid-background-band\"\n              className={cn(bandClassName, \"opacity-50\")}\n              style={staticBandStyle}\n            >\n              <div className={scanGridBackgroundEdgeClasses[direction]} />\n            </div>\n          )}\n        </div>\n        <div\n          data-slot=\"scan-grid-background-content\"\n          className={scanGridBackgroundContentClassNames()}\n        >\n          {children}\n        </div>\n      </div>\n    </MotionConfig>\n  );\n});\n\nScanGridBackground.displayName = \"ScanGridBackground\";\n"
    },
    {
      "path": "packages/components/src/components/scan-grid-background/index.ts",
      "type": "registry:file",
      "target": "~/components/dethink/components/scan-grid-background/index.ts",
      "content": "export {\n  ScanGridBackground,\n  getScanGridBackgroundGeometry,\n  getScanGridBackgroundMotionConfig,\n  scanGridBackgroundClassNames,\n  scanGridBackgroundContentClassNames,\n  scanGridBackgroundLayerClassNames,\n  type ScanGridBackgroundClassNamesOptions,\n  type ScanGridBackgroundContentClassNamesOptions,\n  type ScanGridBackgroundDensity,\n  type ScanGridBackgroundDirection,\n  type ScanGridBackgroundGeometry,\n  type ScanGridBackgroundIntensity,\n  type ScanGridBackgroundLayerClassNamesOptions,\n  type ScanGridBackgroundMotionConfig,\n  type ScanGridBackgroundProps,\n  type ScanGridBackgroundSpeed,\n  type ScanGridBackgroundTone,\n} from \"./scan-grid-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"
    }
  ]
}
