{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"arc-frame","type":"registry:ui","title":"Arc Frame","description":"Wraps any element in crackling, glowing arcs of electricity that crawl around its edge.","dependencies":[],"registryDependencies":["utils"],"files":[{"path":"registry/ui/arc-frame.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef, type ReactNode } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface ArcFrameProps {\n  children: ReactNode;\n  color?: string;\n  /** Animation speed multiplier. */\n  speed?: number;\n  /** How far the arcs stray from the edge. */\n  chaos?: number;\n  /** Line width in px. */\n  thickness?: number;\n  /** Corner radius in px. */\n  radius?: number;\n  className?: string;\n}\n\nconst PAD = 48;\nconst HARMONICS = [3, 5, 8, 13, 21, 34, 55, 89];\n\n// Points along a rounded rect (centred on the element's edge) with outward normals.\nfunction outline(w: number, h: number, r: number, gap: number) {\n  r = Math.max(0, Math.min(r, w / 2, h / 2));\n  const pts: number[] = [];\n  const line = (x0: number, y0: number, x1: number, y1: number, nx: number, ny: number) => {\n    const n = Math.max(1, Math.round(Math.hypot(x1 - x0, y1 - y0) / gap));\n    for (let i = 0; i < n; i++) pts.push(x0 + ((x1 - x0) * i) / n, y0 + ((y1 - y0) * i) / n, nx, ny);\n  };\n  const arc = (cx: number, cy: number, a0: number) => {\n    const n = Math.max(1, Math.round((r * Math.PI) / 2 / gap));\n    for (let i = 0; i < n; i++) {\n      const a = a0 + ((Math.PI / 2) * i) / n;\n      pts.push(cx + Math.cos(a) * r, cy + Math.sin(a) * r, Math.cos(a), Math.sin(a));\n    }\n  };\n  line(r, 0, w - r, 0, 0, -1);\n  arc(w - r, r, -Math.PI / 2);\n  line(w, r, w, h - r, 1, 0);\n  arc(w - r, h - r, 0);\n  line(w - r, h, r, h, 0, 1);\n  arc(r, h - r, Math.PI / 2);\n  line(0, h - r, 0, r, -1, 0);\n  arc(r, r, Math.PI);\n  return pts;\n}\n\nexport function ArcFrame({\n  children,\n  color = \"#7df9ff\",\n  speed = 1,\n  chaos = 1,\n  thickness = 2,\n  radius = 24,\n  className,\n}: ArcFrameProps) {\n  const rootRef = useRef<HTMLDivElement>(null);\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n\n  useEffect(() => {\n    const root = rootRef.current!;\n    const canvas = canvasRef.current!;\n    const ctx = canvas.getContext(\"2d\")!;\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    // Two strands, each a sum of harmonics that divide the perimeter evenly, so the loop has no seam.\n    const strands = [0, 1].map((s) =>\n      HARMONICS.map((k, i) => ({\n        k,\n        amp: 1 / Math.pow(k, 0.55),\n        phase: (s * 7.3 + i * 2.39) % (Math.PI * 2),\n        vel: (i % 2 ? 1 : -1) * (1.2 + i * 0.55) * (s ? 1.35 : 1),\n      })),\n    );\n    const norm = strands[0].reduce((a, h) => a + h.amp, 0);\n    let pts: number[] = [];\n    let w = 0;\n    let h = 0;\n    let raf = 0;\n    let visible = true;\n\n    const draw = (now: number) => {\n      const t = reduced ? 0 : (now / 1000) * speed;\n      const n = pts.length / 4;\n      const amp = 7 * chaos;\n      ctx.clearRect(0, 0, w + PAD * 2, h + PAD * 2);\n      ctx.lineJoin = \"round\";\n      strands.forEach((harm, si) => {\n        ctx.beginPath();\n        for (let i = 0; i <= n; i++) {\n          const j = (i % n) * 4;\n          const u = (i / n) * Math.PI * 2;\n          let d = 0;\n          for (const hm of harm) d += hm.amp * Math.sin(hm.k * u + hm.phase + hm.vel * t);\n          d = (d / norm) * amp * (si ? 1.4 : 1);\n          const x = PAD + pts[j] + pts[j + 2] * d;\n          const y = PAD + pts[j + 1] + pts[j + 3] * d;\n          if (i) ctx.lineTo(x, y);\n          else ctx.moveTo(x, y);\n        }\n        const flicker = reduced ? 1 : 0.8 + Math.random() * 0.2;\n        ctx.shadowColor = color;\n        ctx.shadowBlur = 14;\n        ctx.strokeStyle = color;\n        ctx.globalAlpha = (si ? 0.45 : 1) * flicker;\n        ctx.lineWidth = thickness * (si ? 0.7 : 1);\n        ctx.stroke();\n        if (!si) {\n          // Hot white core on the main strand.\n          ctx.shadowBlur = 0;\n          ctx.strokeStyle = \"#fff\";\n          ctx.globalAlpha = 0.75 * flicker;\n          ctx.lineWidth = Math.max(0.6, thickness * 0.4);\n          ctx.stroke();\n        }\n      });\n      ctx.globalAlpha = 1;\n      ctx.shadowBlur = 0;\n    };\n\n    const loop = (now: number) => {\n      draw(now);\n      raf = visible && !reduced ? requestAnimationFrame(loop) : 0;\n    };\n\n    const ro = new ResizeObserver(() => {\n      const dpr = Math.min(window.devicePixelRatio || 1, 2);\n      w = root.offsetWidth;\n      h = root.offsetHeight;\n      canvas.width = (w + PAD * 2) * dpr;\n      canvas.height = (h + PAD * 2) * dpr;\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      pts = outline(w, h, radius, 3);\n      draw(performance.now());\n    });\n    ro.observe(root);\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible && !raf && !reduced) raf = requestAnimationFrame(loop);\n    });\n    io.observe(root);\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n    };\n  }, [color, speed, chaos, thickness, radius]);\n\n  return (\n    <div ref={rootRef} className={cn(\"relative\", className)} style={{ borderRadius: radius }}>\n      <div\n        aria-hidden\n        style={{\n          position: \"absolute\",\n          inset: 0,\n          borderRadius: radius,\n          pointerEvents: \"none\",\n          boxShadow: `0 0 32px -6px ${color}, inset 0 0 28px -12px ${color}`,\n          opacity: 0.6,\n        }}\n      />\n      <canvas\n        ref={canvasRef}\n        aria-hidden\n        style={{\n          position: \"absolute\",\n          left: -PAD,\n          top: -PAD,\n          width: `calc(100% + ${PAD * 2}px)`,\n          height: `calc(100% + ${PAD * 2}px)`,\n          pointerEvents: \"none\",\n          zIndex: 1,\n        }}\n      />\n      <div style={{ position: \"relative\", borderRadius: radius }}>{children}</div>\n    </div>\n  );\n}\n"}]}