{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "particle-canvas",
  "title": "Particle Canvas",
  "author": "AlgorizeTech",
  "description": "Ask the user to pick one of 2 particle canvas variants: https://avaraui.com/view/particle-canvas. This item holds 2 of them as looks of one component (repel, wordmark-glow). Skip the question if the user already named one. A high-performance text canvas component with organic repulsion physics and wordmark glow variants featuring cursor tracking and scroll-driven rising animations.",
  "dependencies": [
    "next-themes"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "src/components/custom/blocks/ParticleCanvasBlock.tsx",
      "content": "\"use client\";\n\nimport React, { useEffect, useRef, useCallback, useState, useSyncExternalStore } from \"react\";\n\n/**\n * False while server-rendering and during hydration, true afterwards — without\n * the extra render an effect-flipped useState costs.\n */\nconst subscribeToNothing = () => () => {};\nconst useIsMounted = () =>\n  useSyncExternalStore(\n    subscribeToNothing,\n    () => true,\n    () => false,\n  );\n\nimport { useTheme } from \"next-themes\";\nimport { cn } from \"@/lib/utils\";\nimport { accentStyle, resolveAccent } from \"@/lib/accent\";\nimport { springTiming, useInView, usePrefersReducedMotion } from \"@/lib/animate\";\n\nconst LETTER_SPRING = springTiming({ stiffness: 95, damping: 14, mass: 1.25 });\n\n/** A wordmark letter rising into place, each one 80ms after the one before. */\nfunction letterStyle(inView: boolean, index: number): React.CSSProperties {\n  if (!inView) return { opacity: 0, transform: \"translateY(75%) scale(0.94)\" };\n  const timing = `${LETTER_SPRING.duration}ms ${LETTER_SPRING.easing} ${index * 80}ms`;\n  return { opacity: 1, transition: `transform ${timing}, opacity ${timing}` };\n}\n\nexport interface ParticleCanvasProps extends React.HTMLAttributes<HTMLDivElement> {\n  content?: string;\n  variant?: \"repel\" | \"wordmark-glow\" | (string & {});\n  particleSize?: number;\n  particleGap?: number;\n  speed?: number;\n  color?: string;\n  backgroundColor?: string;\n  interactive?: boolean;\n  fontSize?: number;\n  fontFamily?: string;\n  className?: string;\n}\n\ninterface Particle {\n  x: number;\n  y: number;\n  originX: number;\n  originY: number;\n  targetX: number;\n  targetY: number;\n  vx: number;\n  vy: number;\n  size: number;\n  color: string;\n  scatterSeed: number;\n  forceMult: number;\n}\n\nconst PRESET_ACCENT_HEX: Record<string, string> = {\n  lavender: \"#9b8afb\",\n  indigo: \"#6366f1\",\n  rose: \"#f43f5e\",\n  emerald: \"#10b981\",\n  zinc: \"#18181b\",\n  amber: \"#f59e0b\",\n  blue: \"#3b82f6\",\n  violet: \"#8b5cf6\",\n  purple: \"#a855f7\",\n  cyan: \"#06b6d4\",\n  teal: \"#14b8a6\",\n  orange: \"#f97316\",\n  red: \"#ef4444\",\n  pink: \"#ec4899\",\n  yellow: \"#eab308\",\n  green: \"#22c55e\",\n};\n\n/** Turns a preset accent name or custom hex string into a CSS color, or null for default theme. */\nfunction resolveColorAccent(color?: string): string | null {\n  if (!color || color === \"primary\" || color === \"default\") return null;\n  const normalized = color.toLowerCase();\n  return PRESET_ACCENT_HEX[normalized] ?? resolveAccent(color) ?? color;\n}\n\nexport interface WordmarkGlowProps extends React.HTMLAttributes<HTMLDivElement> {\n  content?: string;\n  color?: string;\n  className?: string;\n}\n\nexport function WordmarkGlowCanvas({\n  content = \"AlgorizeTech\",\n  color,\n  className,\n  style,\n  ...props\n}: WordmarkGlowProps) {\n  const wrapRef = useRef<HTMLDivElement>(null);\n  const measureRef = useRef<HTMLSpanElement>(null);\n  const [fontSize, setFontSize] = useState<number | null>(null);\n  const reduceMotion = usePrefersReducedMotion();\n  const lettersRef = useRef<HTMLParagraphElement>(null);\n  const lettersInView = useInView(lettersRef, { amount: 0.25 });\n\n  const updateFontSize = useCallback(() => {\n    if (!wrapRef.current || !measureRef.current) return;\n    const containerWidth = wrapRef.current.clientWidth;\n    const widthAt100 = measureRef.current.offsetWidth;\n    if (containerWidth > 0 && widthAt100 > 0) {\n      // Fill full width edge-to-edge safely without any clipping on left or right\n      const targetWidth = Math.min(containerWidth - 24, containerWidth * 0.95);\n      const computedSize = (targetWidth / widthAt100) * 100;\n      setFontSize(Math.min(Math.max(computedSize, 16), 340));\n    }\n  }, []);\n\n  useEffect(() => {\n    updateFontSize();\n    if (typeof document !== \"undefined\" && document.fonts) {\n      document.fonts.ready.then(updateFontSize);\n    }\n    const node = wrapRef.current;\n    if (!node) return;\n    const observer = new ResizeObserver(() => updateFontSize());\n    observer.observe(node);\n    return () => observer.disconnect();\n  }, [updateFontSize, content]);\n\n  // Writes pointer position as --mx / --my for the radial glow\n  useEffect(() => {\n    const node = wrapRef.current;\n    if (!node || typeof window === \"undefined\" || !window.matchMedia(\"(hover: hover) and (pointer: fine)\").matches) return undefined;\n    let frame = 0;\n    let x = 0;\n    let y = 0;\n    const onMove = (event: PointerEvent) => {\n      const rect = node.getBoundingClientRect();\n      x = event.clientX - rect.left;\n      y = event.clientY - rect.top;\n      if (frame) return;\n      frame = requestAnimationFrame(() => {\n        frame = 0;\n        node.style.setProperty(\"--mx\", `${x}px`);\n        node.style.setProperty(\"--my\", `${y}px`);\n      });\n    };\n    node.addEventListener(\"pointermove\", onMove);\n    return () => {\n      node.removeEventListener(\"pointermove\", onMove);\n      cancelAnimationFrame(frame);\n    };\n  }, []);\n\n  const dynamicAccent = accentStyle(color);\n  const charRatio = content ? Math.max(content.length * 0.58, 2.5) : 4.5;\n\n  return (\n    <div\n      ref={wrapRef}\n      style={{ ...dynamicAccent, ...style }}\n      className={cn(\n        \"group/word relative isolate flex w-full h-full min-h-[240px] items-end justify-center overflow-hidden px-3 pt-10 pb-0 select-none bg-background text-foreground transition-colors [container-type:inline-size]\",\n        className\n      )}\n      {...props}\n    >\n      {/* Invisible measurement element to compute 100% exact full-width font scaling */}\n      <span\n        ref={measureRef}\n        aria-hidden=\"true\"\n        className=\"invisible absolute left-0 top-0 pointer-events-none select-none whitespace-nowrap font-semibold leading-[0.82] tracking-[-0.035em]\"\n        style={{ fontSize: \"100px\" }}\n      >\n        {[...content].map((letter, i) => (\n          <span key={i} className=\"inline-block px-[0.02em] last:pr-[0.14em]\">\n            {letter}\n          </span>\n        ))}\n      </span>\n\n      {/* Glow behind the letters; follows mouse pointer and glows with active theme / primary color */}\n      <div\n        aria-hidden=\"true\"\n        className=\"pointer-events-none absolute inset-0 -z-10 bg-[radial-gradient(380px_circle_at_var(--mx,50%)_var(--my,65%),color-mix(in_oklab,var(--primary)_45%,transparent),transparent_70%)] opacity-60 transition-opacity duration-300 group-hover/word:opacity-100\"\n      />\n\n      <p\n        ref={lettersRef}\n        aria-hidden=\"true\"\n        style={{\n          fontSize: fontSize ? `${fontSize}px` : `clamp(1.75rem, calc(92cqi / ${charRatio}), 19rem)`,\n        }}\n        className=\"pointer-events-none mb-[-0.025em] flex w-full max-w-full select-none justify-center whitespace-nowrap font-semibold leading-[0.82] tracking-[-0.035em]\"\n      >\n        {[...content].map((letter, index) => (\n          <span\n            key={index}\n            style={reduceMotion ? undefined : letterStyle(lettersInView, index)}\n            className=\"inline-block px-[0.02em] last:pr-[0.14em] bg-gradient-to-b from-foreground/25 to-foreground/[0.03] to-85% bg-clip-text text-transparent\"\n          >\n            {letter}\n          </span>\n        ))}\n      </p>\n    </div>\n  );\n}\n\nfunction StandardParticleCanvas({\n  content = \"AlgorizeTech\",\n  variant = \"repel\",\n  particleSize = 2.5,\n  particleGap = 5,\n  speed = 1,\n  color,\n  backgroundColor = \"transparent\",\n  interactive = true,\n  fontSize,\n  fontFamily = \"system-ui, -apple-system, sans-serif\",\n  className,\n  style,\n  ...props\n}: ParticleCanvasProps) {\n  const { resolvedTheme } = useTheme();\n  const mounted = useIsMounted();\n  const [themePrimaryColor, setThemePrimaryColor] = useState<string>(\"currentColor\");\n\n  // Real-time semantic CSS theme color resolver (supports standard CSS vars and Shadcn HSL variables)\n  const getActivePrimaryColor = (): string => {\n    if (typeof window === \"undefined\") return resolvedTheme === \"light\" ? \"#18181b\" : \"#3b82f6\";\n    try {\n      // 1. Direct CSS variable evaluation\n      const dummy = document.createElement(\"div\");\n      dummy.style.color = \"var(--primary)\";\n      dummy.style.position = \"absolute\";\n      dummy.style.visibility = \"hidden\";\n      dummy.style.pointerEvents = \"none\";\n      document.body.appendChild(dummy);\n      let computedColor = window.getComputedStyle(dummy).color;\n      document.body.removeChild(dummy);\n\n      if (computedColor && computedColor !== \"rgba(0, 0, 0, 0)\" && computedColor !== \"transparent\") {\n        return computedColor;\n      }\n\n      // 2. Shadcn HSL CSS variable format fallback (hsl(var(--primary)))\n      const dummyHsl = document.createElement(\"div\");\n      dummyHsl.style.color = \"hsl(var(--primary))\";\n      dummyHsl.style.position = \"absolute\";\n      dummyHsl.style.visibility = \"hidden\";\n      dummyHsl.style.pointerEvents = \"none\";\n      document.body.appendChild(dummyHsl);\n      computedColor = window.getComputedStyle(dummyHsl).color;\n      document.body.removeChild(dummyHsl);\n\n      if (computedColor && computedColor !== \"rgba(0, 0, 0, 0)\" && computedColor !== \"transparent\") {\n        return computedColor;\n      }\n    } catch {\n      // Colour could not be resolved; fallback used below\n    }\n    return resolvedTheme === \"light\" ? \"#18181b\" : \"#3b82f6\";\n  };\n\n  // Dynamically observe and resolve exact active site theme --primary CSS color variable\n  useEffect(() => {\n    if (typeof window === \"undefined\" || !mounted) return;\n\n    const updateThemeColor = () => {\n      const activeColor = getActivePrimaryColor();\n      setThemePrimaryColor(activeColor);\n    };\n\n    updateThemeColor();\n\n    const observer = new MutationObserver(() => updateThemeColor());\n    observer.observe(document.documentElement, {\n      attributes: true,\n      attributeFilter: [\"class\", \"style\", \"data-theme\"],\n    });\n\n    return () => observer.disconnect();\n  }, [mounted, resolvedTheme]);\n\n  // Resolve picked color from color picker or fallback to exact active header primary theme color\n  const resolvedPickerColor = resolveColorAccent(color);\n  const effectiveColor =\n    resolvedPickerColor ||\n    (themePrimaryColor !== \"currentColor\"\n      ? themePrimaryColor\n      : getActivePrimaryColor());\n\n  const canvasRef = useRef<HTMLCanvasElement | null>(null);\n  const containerRef = useRef<HTMLDivElement | null>(null);\n  const animationFrameRef = useRef<number | null>(null);\n  const particlesRef = useRef<Particle[]>([]);\n  const mouseRef = useRef<{ x: number; y: number; active: boolean }>({\n    x: -9999,\n    y: -9999,\n    active: false,\n  });\n\n  const sampleParticles = useCallback(\n    (width: number, height: number): Promise<{ x: number; y: number }[]> => {\n      return new Promise((resolve) => {\n        const offscreen = document.createElement(\"canvas\");\n        offscreen.width = width;\n        offscreen.height = height;\n        const ctx = offscreen.getContext(\"2d\", { willReadFrequently: true });\n\n        if (!ctx) {\n          resolve([]);\n          return;\n        }\n\n        const sampled: { x: number; y: number }[] = [];\n\n        // Device Breakpoint Gap Rules:\n        // Small (< 768px): gap = 3.0px\n        // MD (768px - 1023px): gap = 4.0px\n        // Large (>= 1024px): gap = 5.0px (or particleGap prop)\n        let currentGap: number;\n        if (width < 768) {\n          currentGap = 3;\n        } else if (width < 1024) {\n          currentGap = 4;\n        } else {\n          currentGap = Math.max(2, Math.round(particleGap));\n        }\n\n        ctx.clearRect(0, 0, width, height);\n        ctx.fillStyle = \"#000000\";\n        ctx.textAlign = \"center\";\n        ctx.textBaseline = \"middle\";\n\n        const maxTextWidth = Math.max(40, width * (width < 768 ? 0.86 : 0.9));\n        let calcFontSize = fontSize || Math.min(maxTextWidth / (content.length * 0.58), height * 0.42);\n        ctx.font = `bold ${calcFontSize}px ${fontFamily}`;\n\n        // Ensure text never clips on the left or right on small screens\n        if (!fontSize) {\n          const measuredWidth = ctx.measureText(content).width;\n          if (measuredWidth > maxTextWidth && measuredWidth > 0) {\n            calcFontSize = Math.floor(calcFontSize * (maxTextWidth / measuredWidth));\n            ctx.font = `bold ${calcFontSize}px ${fontFamily}`;\n          }\n        }\n\n        ctx.fillText(content, width / 2, height / 2);\n\n        const imgData = ctx.getImageData(0, 0, width, height);\n        const data = imgData.data;\n\n        for (let y = 0; y < height; y += currentGap) {\n          for (let x = 0; x < width; x += currentGap) {\n            const index = (Math.floor(y) * width + Math.floor(x)) * 4;\n            const alpha = data[index + 3];\n            if (alpha > 128) {\n              sampled.push({ x: Math.floor(x), y: Math.floor(y) });\n            }\n          }\n        }\n        resolve(sampled);\n      });\n    },\n    [content, particleGap, fontSize, fontFamily]\n  );\n\n  const initParticles = useCallback(\n    async (width: number, height: number) => {\n      const targets = await sampleParticles(width, height);\n      const newParticles: Particle[] = [];\n\n      targets.forEach((target) => {\n        newParticles.push({\n          x: target.x,\n          y: target.y,\n          originX: target.x,\n          originY: target.y,\n          targetX: target.x,\n          targetY: target.y,\n          vx: 0,\n          vy: 0,\n          size: particleSize,\n          color: effectiveColor,\n          scatterSeed: (Math.random() - 0.5) * 0.7,\n          forceMult: 0.6 + Math.random() * 0.8,\n        });\n      });\n\n      particlesRef.current = newParticles;\n    },\n    [sampleParticles, particleSize]\n  );\n\n  // Update existing particles' color dynamically without resetting position/scatter\n  useEffect(() => {\n    particlesRef.current.forEach((p) => {\n      p.color = effectiveColor;\n    });\n  }, [effectiveColor]);\n\n  useEffect(() => {\n    const canvas = canvasRef.current;\n    const container = containerRef.current;\n    if (!canvas || !container) return;\n\n    const ctx = canvas.getContext(\"2d\");\n    if (!ctx) return;\n\n    let width = (canvas.width = container.clientWidth);\n    let height = (canvas.height = container.clientHeight);\n\n    const handleResize = () => {\n      if (!container || !canvas) return;\n      width = canvas.width = container.clientWidth;\n      height = canvas.height = container.clientHeight;\n      initParticles(width, height);\n    };\n\n    const resizeObserver = new ResizeObserver(() => {\n      handleResize();\n    });\n    resizeObserver.observe(container);\n\n    initParticles(width, height);\n\n    const render = () => {\n      ctx.clearRect(0, 0, width, height);\n\n      if (backgroundColor && backgroundColor !== \"transparent\") {\n        ctx.fillStyle = backgroundColor;\n        ctx.fillRect(0, 0, width, height);\n      }\n\n      const particles = particlesRef.current;\n      const mouse = mouseRef.current;\n\n      // Device Breakpoint Size Rules:\n      // Small (< 768px): particleSize = 1.5px\n      // MD (768px - 1023px): particleSize = 2.0px\n      // Large (>= 1024px): particleSize = 2.5px\n      let currentParticleSize: number;\n      let currentRadius: number;\n\n      if (width < 768) {\n        currentParticleSize = 1.5;\n        currentRadius = 45;\n      } else if (width < 1024) {\n        currentParticleSize = 2.0;\n        currentRadius = 65;\n      } else {\n        currentParticleSize = particleSize;\n        currentRadius = 85;\n      }\n\n      // Lock global alpha to 1.0 for 100% solid, identical color brightness across ALL dots\n      ctx.globalAlpha = 1.0;\n      ctx.fillStyle = effectiveColor;\n\n      for (let i = 0; i < particles.length; i++) {\n        const p = particles[i];\n\n        // Smooth fluid spring return to origin\n        const dx = p.originX - p.x;\n        const dy = p.originY - p.y;\n        p.x += dx * 0.09 * speed;\n        p.y += dy * 0.09 * speed;\n\n        // Organic staggered repulsion force (\"chorai chitai jabe\")\n        if (interactive && mouse.active) {\n          const mdx = p.x - mouse.x;\n          const mdy = p.y - mouse.y;\n          const dist = Math.sqrt(mdx * mdx + mdy * mdy);\n\n          if (dist < currentRadius) {\n            const force = (currentRadius - dist) / currentRadius;\n            // Add unique scatter angle perturbation and staggered velocity per particle\n            const angle = Math.atan2(mdy, mdx) + p.scatterSeed * force;\n            const push = force * 35 * p.forceMult * speed;\n            p.x += Math.cos(angle) * push;\n            p.y += Math.sin(angle) * push;\n          }\n        }\n\n        // Render distinct circular particle\n        ctx.beginPath();\n        ctx.arc(p.x, p.y, currentParticleSize, 0, Math.PI * 2);\n        ctx.fill();\n      }\n\n      animationFrameRef.current = requestAnimationFrame(render);\n    };\n\n    animationFrameRef.current = requestAnimationFrame(render);\n\n    return () => {\n      if (animationFrameRef.current) {\n        cancelAnimationFrame(animationFrameRef.current);\n      }\n      resizeObserver.disconnect();\n    };\n  }, [initParticles, backgroundColor, speed, interactive, effectiveColor, particleSize]);\n\n  const handleMouseMove = (e: React.MouseEvent<HTMLDivElement>) => {\n    if (!containerRef.current || !interactive) return;\n    const rect = containerRef.current.getBoundingClientRect();\n    const x = e.clientX - rect.left;\n    const y = e.clientY - rect.top;\n    mouseRef.current.x = x;\n    mouseRef.current.y = y;\n    mouseRef.current.active = true;\n    containerRef.current.style.setProperty(\"--mx\", `${x}px`);\n    containerRef.current.style.setProperty(\"--my\", `${y}px`);\n  };\n\n  const handleMouseLeave = () => {\n    mouseRef.current.active = false;\n    mouseRef.current.x = -9999;\n    mouseRef.current.y = -9999;\n    if (containerRef.current) {\n      containerRef.current.style.removeProperty(\"--mx\");\n      containerRef.current.style.removeProperty(\"--my\");\n    }\n  };\n\n  const handleTouchMove = (e: React.TouchEvent<HTMLDivElement>) => {\n    if (!containerRef.current || !interactive || e.touches.length === 0) return;\n    const rect = containerRef.current.getBoundingClientRect();\n    const x = e.touches[0].clientX - rect.left;\n    const y = e.touches[0].clientY - rect.top;\n    mouseRef.current.x = x;\n    mouseRef.current.y = y;\n    mouseRef.current.active = true;\n    containerRef.current.style.setProperty(\"--mx\", `${x}px`);\n    containerRef.current.style.setProperty(\"--my\", `${y}px`);\n  };\n\n  const dynamicAccent = accentStyle(color);\n\n  return (\n    <div\n      ref={containerRef}\n      onMouseMove={handleMouseMove}\n      onMouseLeave={handleMouseLeave}\n      onTouchMove={handleTouchMove}\n      onTouchEnd={handleMouseLeave}\n      style={{ ...dynamicAccent, ...style }}\n      className={cn(\n        \"group/canvas relative w-full h-full min-h-[600px] overflow-hidden select-none cursor-crosshair transition-colors\",\n        className\n      )}\n      {...props}\n    >\n      <canvas ref={canvasRef} className=\"block w-full h-full\" />\n    </div>\n  );\n}\n\nexport function ParticleCanvas(props: ParticleCanvasProps) {\n  if (props.variant === \"wordmark-glow\") {\n    return <WordmarkGlowCanvas {...props} />;\n  }\n  return <StandardParticleCanvas {...props} />;\n}\n\nexport default ParticleCanvas;\n",
      "type": "registry:component",
      "target": "components/custom/blocks/ParticleCanvasBlock.tsx"
    },
    {
      "path": "src/lib/accent.ts",
      "content": "import type { CSSProperties } from \"react\";\n\n/**\n * Bridging the docs colour picker into a preview.\n *\n * Most blocks are already written against the `--primary` token (`bg-primary`,\n * `ring-primary/30`, `text-primary-foreground`…). Rather than teaching each one a\n * bespoke `color` prop, a demo can repoint that token for its own subtree and\n * every one of those classes follows along.\n */\n\n/** The swatches the picker offers, as concrete CSS colours. */\nconst PRESET_HEX: Record<string, string> = {\n  lavender: \"#9b8afb\",\n  indigo: \"#6366f1\",\n  rose: \"#f43f5e\",\n  emerald: \"#10b981\",\n  zinc: \"#18181b\",\n};\n\n/** True when the picker sits on \"Default\" — the page theme should win. */\nexport function isDefaultAccent(color?: string): boolean {\n  return !color || color === \"primary\" || color === \"default\";\n}\n\n/**\n * Turns a picker value into a CSS colour, or null for \"Default\" — meaning\n * nothing should be overridden, so the theme (and the sidebar customizer)\n * keeps control.\n */\nexport function resolveAccent(color?: string): string | null {\n  if (isDefaultAccent(color)) return null;\n  return PRESET_HEX[color as string] ?? (color as string);\n}\n\n/**\n * The picker value in a form every block accepts. Blocks know the older swatch\n * names but not \"lavender\" — and since that is also a CSS named colour\n * (#e6e6fa), a block that passes unknown names straight through would paint\n * the wrong shade, while others fall back to a different palette. Demos that\n * hand the picker value to such a block run it through this first. Every\n * other value is returned untouched.\n */\nexport function toBlockColor(color: string): string;\nexport function toBlockColor(color: string | undefined): string | undefined;\nexport function toBlockColor(color?: string): string | undefined {\n  return color === \"lavender\" ? PRESET_HEX.lavender : color;\n}\n\nfunction parseHex(input: string): [number, number, number] | null {\n  const hex = input.trim().replace(/^#/, \"\");\n  if (/^[a-f\\d]{3}$/i.test(hex)) {\n    const [r, g, b] = hex.split(\"\");\n    return [parseInt(r + r, 16), parseInt(g + g, 16), parseInt(b + b, 16)];\n  }\n  if (/^[a-f\\d]{6}$/i.test(hex)) {\n    return [\n      parseInt(hex.slice(0, 2), 16),\n      parseInt(hex.slice(2, 4), 16),\n      parseInt(hex.slice(4, 6), 16),\n    ];\n  }\n  return null;\n}\n\n/** Legible foreground for content sitting on a filled `color` swatch. */\nexport function accentForeground(color: string): string {\n  const rgb = parseHex(color);\n  if (!rgb) return \"#ffffff\";\n  const channel = (v: number) => {\n    const c = v / 255;\n    return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);\n  };\n  const luminance =\n    0.2126 * channel(rgb[0]) +\n    0.7152 * channel(rgb[1]) +\n    0.0722 * channel(rgb[2]);\n  return luminance > 0.45 ? \"#09090b\" : \"#ffffff\";\n}\n\n/** The theme tokens a picked accent repoints, as `--name` → value. */\nexport function accentTokens(color?: string): Record<string, string> {\n  const resolved = resolveAccent(color);\n  if (!resolved) return {};\n  return {\n    \"--primary\": resolved,\n    \"--primary-foreground\": accentForeground(resolved),\n    \"--ring\": resolved,\n  };\n}\n\n/**\n * Inline style repointing `--primary` at the picked accent for one subtree.\n * `--primary-foreground` is derived alongside it, otherwise a light pick leaves\n * `text-primary-foreground` content unreadable on its own fill. Returns `{}` on\n * \"Default\" so the page theme still wins.\n */\nexport function accentStyle(color?: string): CSSProperties {\n  return accentTokens(color) as CSSProperties;\n}\n",
      "type": "registry:component",
      "target": "lib/accent.ts"
    },
    {
      "path": "src/lib/animate.ts",
      "content": "import { useEffect, useState, useSyncExternalStore, type RefObject } from \"react\";\n\n/**\n * Animation helpers for components that need no animation library: spring\n * easings for CSS transitions and the Web Animations API, plus the two browser\n * checks those components share. Installed alongside any component that uses it.\n */\n\nexport type SpringOptions = {\n  stiffness?: number;\n  damping?: number;\n  mass?: number;\n};\n\n/** A spring as a CSS timing: `duration` in milliseconds, `easing` as `linear(…)`. */\nexport type Timing = { duration: number; easing: string };\n\n/** How many points of the spring's curve the easing samples. */\nconst SAMPLES = 48;\n\n/** The time constant multiple at which a spring is within 0.1% of its target. */\nconst SETTLED = Math.log(1000);\n\n/**\n * Browsers without `linear()` get a plain ease instead: the Web Animations API\n * throws on an easing it can't parse, rather than ignoring it as CSS would.\n */\nconst supportsLinearEasing = () =>\n  typeof CSS === \"undefined\" || CSS.supports(\"transition-timing-function\", \"linear(0, 1)\");\n\n/** The response of a spring released from rest, as a CSS easing. */\nexport function springTiming({ stiffness = 100, damping = 10, mass = 1 }: SpringOptions = {}): Timing {\n  const natural = Math.sqrt(stiffness / mass);\n  const ratio = Math.min(damping / (2 * Math.sqrt(stiffness * mass)), 1);\n  const decay = ratio * natural;\n  const seconds = SETTLED / decay;\n  if (!supportsLinearEasing()) return { duration: Math.round(seconds * 1000), easing: \"ease-out\" };\n\n  const damped = natural * Math.sqrt(1 - ratio * ratio);\n  const position = (t: number) =>\n    ratio < 1\n      ? 1 - Math.exp(-decay * t) * (Math.cos(damped * t) + (decay / damped) * Math.sin(damped * t))\n      : 1 - Math.exp(-natural * t) * (1 + natural * t);\n\n  const points = Array.from({ length: SAMPLES + 1 }, (_, i) =>\n    i === SAMPLES ? \"1\" : position((i / SAMPLES) * seconds).toFixed(4),\n  );\n  return { duration: Math.round(seconds * 1000), easing: `linear(${points.join(\",\")})` };\n}\n\n/** A spring described by how long it takes and how much it bounces (0 to 1). */\nexport function bounceTiming(seconds: number, bounce: number): Timing {\n  const ratio = 1 - bounce;\n  const natural = SETTLED / (ratio * seconds);\n  return springTiming({ stiffness: natural * natural, damping: 2 * ratio * natural });\n}\n\nconst REDUCED_MOTION = \"(prefers-reduced-motion: reduce)\";\n\nconst subscribeToReducedMotion = (onChange: () => void) => {\n  const query = window.matchMedia(REDUCED_MOTION);\n  query.addEventListener(\"change\", onChange);\n  return () => query.removeEventListener(\"change\", onChange);\n};\n\n/** Whether the visitor asked for less motion. False during server rendering. */\nexport const usePrefersReducedMotion = () =>\n  useSyncExternalStore(\n    subscribeToReducedMotion,\n    () => window.matchMedia(REDUCED_MOTION).matches,\n    () => false,\n  );\n\n/** The same check, for code running outside render. */\nexport const prefersReducedMotion = () =>\n  typeof window !== \"undefined\" && window.matchMedia(REDUCED_MOTION).matches;\n\n/**\n * Whether an element is on screen. `amount` is the share of it that must show.\n * With `once` it stays true after the first time.\n */\nexport function useInView(\n  ref: RefObject<Element | null>,\n  { amount = 0, once = false }: { amount?: number; once?: boolean } = {},\n): boolean {\n  const [inView, setInView] = useState(false);\n\n  useEffect(() => {\n    const node = ref.current;\n    if (!node) return;\n    const observer = new IntersectionObserver(\n      ([entry]) => {\n        setInView(entry.isIntersecting);\n        if (entry.isIntersecting && once) observer.disconnect();\n      },\n      { threshold: amount },\n    );\n    observer.observe(node);\n    return () => observer.disconnect();\n  }, [ref, amount, once]);\n\n  return inView;\n}\n",
      "type": "registry:component",
      "target": "lib/animate.ts"
    }
  ],
  "docs": "Named exports: ParticleCanvas, WordmarkGlowCanvas. Default export: ParticleCanvas. Variants: repel | wordmark-glow. Features 2D particle physics, cursor repulsion, scroll-timeline rising letters, and pointer-following radial glow.",
  "categories": [
    "media",
    "data-display"
  ],
  "type": "registry:component"
}
