{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "electric-waveform",
  "title": "Electric Waveform",
  "description": "One electric line across the width: a crackling, white-hot trace with a tall glow, forks off the peaks and sparks. Follows the frequency bands as a smooth wave, or the signal itself like an oscilloscope.",
  "registryDependencies": [
    "@audiocn/core",
    "@audiocn/electric",
    "@audiocn/use-frame-source",
    "@audiocn/use-reduced-motion",
    "@audiocn/use-visibility"
  ],
  "files": [
    {
      "path": "components/ui/electric-waveform.tsx",
      "content": "\"use client\";\n\nimport {\n  useCallback,\n  useEffect,\n  useEffectEvent,\n  useImperativeHandle,\n  useRef,\n} from \"react\";\nimport type { ComponentProps, Ref } from \"react\";\n\nimport { useFrameSource } from \"@/hooks/use-frame-source\";\nimport { useReducedMotion } from \"@/hooks/use-reduced-motion\";\nimport { useVisibility } from \"@/hooks/use-visibility\";\nimport { clamp } from \"@/lib/audio/decibels\";\nimport { subscribeFrame } from \"@/lib/audio/frame-loop\";\nimport type { FrameSource, VisualFrame } from \"@/lib/audio/types\";\nimport { WAVE_LINE_MAX_POINTS, createWaveLine } from \"@/lib/audio/wave-line\";\nimport type { WaveLineMode } from \"@/lib/audio/wave-line\";\nimport {\n  ELECTRIC_CANVAS_CLASS,\n  ELECTRIC_GLOW_CLASS,\n  clearElectricCanvas,\n  createElectricSparks,\n  createRandom,\n  displace,\n  emitSpark,\n  fitElectricCanvases,\n  moveSparks,\n  readElectricColors,\n  strokeSparks,\n} from \"@/lib/electric\";\nimport type {\n  ElectricCanvasSize,\n  ElectricColors,\n  ElectricSparks,\n} from \"@/lib/electric\";\nimport { cn } from \"@/lib/utils\";\n\nconst DEFAULT_INTENSITY = 0.6;\nconst DEFAULT_LINE_WIDTH = 3;\nconst REDUCED_MOTION_INTERVAL_MS = 250;\nconst COLOR_REFRESH_FRAMES = 30;\nconst MS_PER_SECOND = 1000;\nconst FRAME_MS = 16.67;\nconst MAX_STEP_SECONDS = 0.05;\n/** Width of the faded ends, in pixels. */\nconst FADE_PX = 24;\n\n/** One point every this many pixels along the line. */\nconst POINT_SPACING_PX = 4;\n/** Crackle is built in short chunks of 2^2 segments that share their ends. */\nconst CHUNK = 2 ** 2;\nconst MIN_POINTS = CHUNK * 8 + 1;\nconst MAX_POINTS = WAVE_LINE_MAX_POINTS;\n/** How much each finer split of the crackle bends compared with the one before. */\nconst ROUGHNESS = 0.8;\n/** Each jagged shape holds at least this long, so the crackle never strobes. */\nconst JITTER_MS = 42;\n/** Brightness flicker, at most 12%. */\nconst FLICKER = 0.12;\n/** Crackle at rest, in pixels at full intensity. */\nconst HUM_PX = 1.5;\n/** Extra crackle at full level, in pixels at full intensity. */\nconst CRACKLE_PX = 6;\n\nconst MAX_BRANCHES = 3;\nconst BRANCH_POINTS = 2 ** 3 + 1;\n/** A point must be this far from the middle to throw a fork. */\nconst BRANCH_THRESHOLD = 0.3;\nconst BRANCH_CHANCE = 0.6;\nconst BRANCH_CANDIDATES = 3;\nconst BRANCH_MIN_PX = 10;\nconst BRANCH_MAX_PX = 30;\nconst BRANCH_MIN_MS = 60;\nconst BRANCH_MAX_MS = 140;\n/** How far a fork bends, relative to its length. */\nconst BRANCH_BOW = 0.35;\n\nconst MAX_SPARKS = 48;\n/** A rise in loudness this big in one frame throws sparks. */\nconst SPARK_RISE = 0.1;\nconst SPARK_MIN_LEVEL = 0.3;\nconst SPARK_COOLDOWN_MS = 90;\n/** Pixels per second squared. */\nconst SPARK_GRAVITY = 520;\n/** Pixels per second. */\nconst SPARK_SPEED = 170;\n/** Pixels per second, sideways. */\nconst SPARK_SPREAD = 90;\nconst SPARK_MIN_MS = 260;\nconst SPARK_MAX_MS = 560;\nconst SPARK_TRAIL_SECONDS = 0.03;\n\nexport type ElectricWaveformMode = WaveLineMode;\n\nexport interface ElectricWaveformActions {\n  /** Paint a frame directly. */\n  paint: (frame: VisualFrame) => void;\n  /** Forget the last frame, so the line falls flat. */\n  clear: () => void;\n}\n\nexport interface ElectricWaveformProps extends ComponentProps<\"div\"> {\n  source?: FrameSource<VisualFrame> | null;\n  /**\n   * `wave` draws a smooth wave shaped by the frequency bands. `scope` draws\n   * the signal itself, like an oscilloscope. Default `wave`.\n   */\n  mode?: ElectricWaveformMode;\n  /** Runs a pulse along the line, for connecting or thinking states. Default false. */\n  loading?: boolean;\n  /** How jagged and restless the line is, 0..1. Default 0.6. */\n  intensity?: number;\n  /** Forks of lightning branch off the peaks. Default true. */\n  arcs?: boolean;\n  /** Sparks fly off the peaks on sudden rises. Default true. */\n  sparks?: boolean;\n  /** Visual gain. Default 1. */\n  sensitivity?: number;\n  /** Line width in pixels. Default 3. */\n  lineWidth?: number;\n  /** Fade the left and right ends. Default true. */\n  fadeEdges?: boolean;\n  actionsRef?: Ref<ElectricWaveformActions>;\n}\n\n/** A fork of lightning off the line. */\nexport interface ElectricBranch {\n  /** The point on the line it leaves from. */\n  point: number;\n  /** 1 up, −1 down: away from the middle. */\n  direction: number;\n  /** Pixels. */\n  length: number;\n  /** Sideways drift of the far end, relative to the length. */\n  lean: number;\n  bornMs: number;\n  /** 0 when the fork is gone. */\n  lifeMs: number;\n  /** Bend at each point, in units of the fork's bow. */\n  jitter: Float32Array;\n}\n\nexport interface ElectricTraceGeometry {\n  /** CSS pixels. */\n  width: number;\n  height: number;\n  lineWidth: number;\n}\n\nexport interface ElectricTraceOptions {\n  mode: ElectricWaveformMode;\n  loading: boolean;\n  intensity: number;\n  arcs: boolean;\n  sparks: boolean;\n  sensitivity: number;\n  /** A still line: no crackle, forks, sparks or drift. */\n  reducedMotion: boolean;\n  /** Makes the crackle repeatable. Each trace gets its own by default. */\n  seed?: number;\n}\n\nexport interface ElectricTrace {\n  /** Points in use along the width. */\n  count: number;\n  /** Height of the line at each point, −1..1, up positive. */\n  heights: Float32Array;\n  /** Crackle at each point, in units of its amplitude. */\n  crackle: Float32Array;\n  /** How loud the line is, 0..1. */\n  loudness: number;\n  /** Brightness, 0.88..1. */\n  flicker: number;\n  branches: ElectricBranch[];\n  sparks: ElectricSparks;\n  /** Advances to `nowMs` with the latest frame. Returns true when there is a signal. */\n  step: (\n    nowMs: number,\n    frame: VisualFrame | null,\n    geometry: ElectricTraceGeometry\n  ) => boolean;\n}\n\n/** Points for a width: one every few pixels, in whole crackle chunks. */\nconst pointCountFor = (width: number) =>\n  clamp(\n    Math.round(width / POINT_SPACING_PX / CHUNK) * CHUNK + 1,\n    MIN_POINTS,\n    MAX_POINTS\n  );\n\nconst middleOf = (geometry: ElectricTraceGeometry) => geometry.height / 2;\n\n/** Pixels from the middle to a height of 1, leaving room for the line. */\nconst reachOf = (geometry: ElectricTraceGeometry) =>\n  Math.max(0, geometry.height / 2 - Math.max(geometry.lineWidth * 2, 6));\n\nconst xOf = (geometry: ElectricTraceGeometry, count: number, point: number) =>\n  (point / (count - 1)) * geometry.width;\n\n/** Crackle in pixels at a point: louder lines and higher peaks crackle more. */\nconst crackleAt = (trace: ElectricTrace, intensity: number, point: number) =>\n  intensity *\n  (HUM_PX +\n    CRACKLE_PX *\n      (0.4 * trace.loudness + 0.6 * Math.abs(trace.heights[point] ?? 0)));\n\n/** Where a point of the line is drawn, in pixels down from the top. */\nconst yOf = (\n  trace: ElectricTrace,\n  geometry: ElectricTraceGeometry,\n  intensity: number,\n  point: number,\n  scale = 1,\n  crackleShare = 1\n) =>\n  middleOf(geometry) -\n  (trace.heights[point] ?? 0) * scale * reachOf(geometry) -\n  (trace.crackle[point] ?? 0) *\n    crackleAt(trace, intensity, point) *\n    crackleShare;\n\nlet traceCount = 0;\n\n/**\n * The moving parts of the electric line, apart from any canvas: its shape,\n * crackle, forks and sparks. With reduced motion it is a still, smooth line.\n */\nexport const createElectricTrace = ({\n  arcs,\n  intensity,\n  loading,\n  mode,\n  reducedMotion,\n  seed,\n  sensitivity,\n  sparks,\n}: ElectricTraceOptions): ElectricTrace => {\n  traceCount += 1;\n  const random = createRandom(seed ?? traceCount);\n  const signed = () => random() * 2 - 1;\n  const line = createWaveLine({ loading, mode, reducedMotion, sensitivity });\n  let lastMs = 0;\n  let lastJitterMs = -Infinity;\n  let lastSparkMs = -Infinity;\n  let lastStepSeconds = 0;\n  let previousPeak = 0;\n  let primed = false;\n\n  const trace: ElectricTrace = {\n    branches: Array.from({ length: MAX_BRANCHES }, () => ({\n      bornMs: 0,\n      direction: 1,\n      jitter: new Float32Array(BRANCH_POINTS),\n      lean: 0,\n      length: 0,\n      lifeMs: 0,\n      point: 0,\n    })),\n    count: MIN_POINTS,\n    crackle: new Float32Array(MAX_POINTS),\n    flicker: 1,\n    heights: line.heights,\n    loudness: 0,\n    sparks: createElectricSparks(MAX_SPARKS),\n    step: () => false,\n  };\n\n  const rerollCrackle = () => {\n    trace.crackle[0] = signed() * 0.5;\n    for (let start = 0; start + CHUNK < trace.count; start += CHUNK) {\n      displace(\n        trace.crackle,\n        start,\n        CHUNK + 1,\n        [trace.crackle[start] ?? 0, signed() * 0.5],\n        random,\n        ROUGHNESS\n      );\n    }\n    trace.flicker = 1 - FLICKER * random();\n  };\n\n  /** Picks the highest of a few random points, so forks favour the peaks. */\n  const pickPeak = () => {\n    let best = Math.floor(random() * trace.count);\n    for (let candidate = 1; candidate < BRANCH_CANDIDATES; candidate += 1) {\n      const point = Math.floor(random() * trace.count);\n      if (\n        Math.abs(trace.heights[point] ?? 0) > Math.abs(trace.heights[best] ?? 0)\n      ) {\n        best = point;\n      }\n    }\n    return best;\n  };\n\n  const updateBranches = (nowMs: number) => {\n    const point = pickPeak();\n    const height = trace.heights[point] ?? 0;\n    const charged =\n      Math.abs(height) >= BRANCH_THRESHOLD &&\n      random() < BRANCH_CHANCE * intensity * Math.abs(height);\n    const free = trace.branches.find((branch) => branch.lifeMs === 0);\n    if (charged && free) {\n      free.point = point;\n      free.direction = height >= 0 ? 1 : -1;\n      free.length =\n        (BRANCH_MIN_PX + random() * (BRANCH_MAX_PX - BRANCH_MIN_PX)) *\n        (0.6 + 0.8 * intensity);\n      free.lean = signed() * 0.6;\n      free.bornMs = nowMs;\n      free.lifeMs = BRANCH_MIN_MS + random() * (BRANCH_MAX_MS - BRANCH_MIN_MS);\n    }\n    for (const branch of trace.branches) {\n      if (branch.lifeMs > 0) {\n        displace(\n          branch.jitter,\n          0,\n          BRANCH_POINTS,\n          [0, signed() * 0.5],\n          random,\n          ROUGHNESS\n        );\n      }\n    }\n  };\n\n  const expireBranches = (nowMs: number) => {\n    for (const branch of trace.branches) {\n      if (branch.lifeMs > 0 && nowMs - branch.bornMs >= branch.lifeMs) {\n        branch.lifeMs = 0;\n      }\n    }\n  };\n\n  const throwSparks = (nowMs: number, geometry: ElectricTraceGeometry) => {\n    const rise = line.peak - previousPeak;\n    const rested = nowMs - lastSparkMs >= SPARK_COOLDOWN_MS;\n    if (rise < SPARK_RISE || line.peak < SPARK_MIN_LEVEL || !rested) {\n      return;\n    }\n    lastSparkMs = nowMs;\n    let peak = 0;\n    for (let point = 1; point < trace.count; point += 1) {\n      if (\n        Math.abs(trace.heights[point] ?? 0) > Math.abs(trace.heights[peak] ?? 0)\n      ) {\n        peak = point;\n      }\n    }\n    const upward = (trace.heights[peak] ?? 0) >= 0 ? -1 : 1;\n    const x = xOf(geometry, trace.count, peak);\n    const y = yOf(trace, geometry, intensity, peak);\n    const count = 3 + Math.floor(random() * 3);\n    for (let spark = 0; spark < count; spark += 1) {\n      emitSpark(trace.sparks, {\n        lifeMs: SPARK_MIN_MS + random() * (SPARK_MAX_MS - SPARK_MIN_MS),\n        vx: signed() * SPARK_SPREAD,\n        vy: upward * SPARK_SPEED * (0.5 + random()) * (0.5 + intensity),\n        x,\n        y,\n      });\n    }\n  };\n\n  const animate = (nowMs: number, geometry: ElectricTraceGeometry) => {\n    if (nowMs - lastJitterMs >= JITTER_MS) {\n      lastJitterMs = nowMs;\n      rerollCrackle();\n      if (arcs) {\n        updateBranches(nowMs);\n      }\n    }\n    expireBranches(nowMs);\n    if (sparks) {\n      if (primed) {\n        throwSparks(nowMs, geometry);\n      }\n      moveSparks(trace.sparks, lastStepSeconds, SPARK_GRAVITY);\n    }\n  };\n\n  trace.step = (nowMs, frame, geometry) => {\n    const elapsedMs = lastMs === 0 ? FRAME_MS : nowMs - lastMs;\n    lastMs = nowMs;\n    lastStepSeconds = clamp(elapsedMs / MS_PER_SECOND, 0, MAX_STEP_SECONDS);\n    const active = line.step(nowMs, frame, pointCountFor(geometry.width));\n    trace.count = line.count;\n    trace.loudness = line.loudness;\n    if (!reducedMotion) {\n      animate(nowMs, geometry);\n    }\n    previousPeak = line.peak;\n    primed = true;\n    return active;\n  };\n\n  return trace;\n};\n\ninterface PaintInput {\n  trace: ElectricTrace;\n  geometry: ElectricTraceGeometry;\n  colors: ElectricColors;\n  intensity: number;\n  nowMs: number;\n}\n\nconst traceLine = (\n  context: CanvasRenderingContext2D,\n  { geometry, intensity, trace }: PaintInput,\n  scale: number,\n  crackleShare: number\n) => {\n  context.beginPath();\n  for (let point = 0; point < trace.count; point += 1) {\n    const x = xOf(geometry, trace.count, point);\n    const y = yOf(trace, geometry, intensity, point, scale, crackleShare);\n    if (point === 0) {\n      context.moveTo(x, y);\n    } else {\n      context.lineTo(x, y);\n    }\n  }\n};\n\n/** The band between two scaled copies of the line, for the tall glow. */\nconst traceRibbon = (\n  context: CanvasRenderingContext2D,\n  { geometry, intensity, trace }: PaintInput,\n  inner: number,\n  outer: number\n) => {\n  context.beginPath();\n  for (let point = 0; point < trace.count; point += 1) {\n    const x = xOf(geometry, trace.count, point);\n    const y = yOf(trace, geometry, intensity, point, outer, 0.35);\n    if (point === 0) {\n      context.moveTo(x, y);\n    } else {\n      context.lineTo(x, y);\n    }\n  }\n  for (let point = trace.count - 1; point >= 0; point -= 1) {\n    const x = xOf(geometry, trace.count, point);\n    context.lineTo(x, yOf(trace, geometry, intensity, point, inner, 0.35));\n  }\n  context.closePath();\n};\n\nconst traceBranch = (\n  context: CanvasRenderingContext2D,\n  { geometry, intensity, trace }: PaintInput,\n  branch: ElectricBranch\n) => {\n  const point = Math.min(branch.point, trace.count - 1);\n  const x = xOf(geometry, trace.count, point);\n  const y = yOf(trace, geometry, intensity, point);\n  const dx = branch.lean * branch.length;\n  const dy = -branch.direction * branch.length;\n  const length = Math.hypot(dx, dy) || 1;\n  const bow = length * BRANCH_BOW;\n  context.beginPath();\n  for (let index = 0; index < BRANCH_POINTS; index += 1) {\n    const progress = index / (BRANCH_POINTS - 1);\n    const bend = (branch.jitter[index] ?? 0) * bow;\n    const px = x + dx * progress - (dy / length) * bend;\n    const py = y + dy * progress + (dx / length) * bend;\n    if (index === 0) {\n      context.moveTo(px, py);\n    } else {\n      context.lineTo(px, py);\n    }\n  }\n};\n\nconst strokeBranches = (\n  context: CanvasRenderingContext2D,\n  input: PaintInput,\n  lineWidth: number,\n  alpha: number\n) => {\n  context.lineWidth = lineWidth;\n  for (const branch of input.trace.branches) {\n    if (branch.lifeMs > 0) {\n      const age = (input.nowMs - branch.bornMs) / branch.lifeMs;\n      context.globalAlpha = clamp(alpha * (1 - age * age), 0, 1);\n      traceBranch(context, input, branch);\n      context.stroke();\n    }\n  }\n};\n\n/** Cuts the ends away with a gradient, so the line fades in and out. */\nconst fadeEnds = (\n  context: CanvasRenderingContext2D,\n  geometry: ElectricTraceGeometry\n) => {\n  const edge = Math.min(FADE_PX, geometry.width / 2);\n  context.globalAlpha = 1;\n  context.globalCompositeOperation = \"destination-out\";\n  const left = context.createLinearGradient(0, 0, edge, 0);\n  left.addColorStop(0, \"rgba(0, 0, 0, 1)\");\n  left.addColorStop(1, \"rgba(0, 0, 0, 0)\");\n  context.fillStyle = left;\n  context.fillRect(0, 0, edge, geometry.height);\n  const right = context.createLinearGradient(\n    geometry.width - edge,\n    0,\n    geometry.width,\n    0\n  );\n  right.addColorStop(0, \"rgba(0, 0, 0, 0)\");\n  right.addColorStop(1, \"rgba(0, 0, 0, 1)\");\n  context.fillStyle = right;\n  context.fillRect(geometry.width - edge, 0, edge, geometry.height);\n  context.globalCompositeOperation = \"source-over\";\n};\n\n/**\n * The tall, soft glow: bands that echo the wave above and below it, and a\n * wide stroke. The canvas is blurred with CSS, far cheaper than `shadowBlur`.\n */\nconst paintGlow = (context: CanvasRenderingContext2D, input: PaintInput) => {\n  const { geometry, trace } = input;\n  const strength = (0.4 + 0.6 * trace.loudness) * trace.flicker;\n  context.fillStyle = input.colors.glow;\n  context.strokeStyle = input.colors.glow;\n  context.globalAlpha = 0.22 * strength;\n  traceRibbon(context, input, 0.2, 2.6);\n  context.fill();\n  context.globalAlpha = 0.4 * strength;\n  traceRibbon(context, input, 0.6, 1.6);\n  context.fill();\n  context.globalAlpha = 0.6 * strength;\n  context.lineWidth = geometry.lineWidth * 4;\n  traceLine(context, input, 1, 0.6);\n  context.stroke();\n  strokeBranches(context, input, geometry.lineWidth * 1.5, 0.7);\n};\n\nconst paintMain = (context: CanvasRenderingContext2D, input: PaintInput) => {\n  const { geometry, trace } = input;\n  context.strokeStyle = input.colors.body;\n  context.globalAlpha = 0.9 * trace.flicker;\n  context.lineWidth = geometry.lineWidth;\n  traceLine(context, input, 1, 0.6);\n  context.stroke();\n  context.lineJoin = \"miter\";\n  strokeBranches(context, input, Math.max(1.5, geometry.lineWidth * 0.5), 0.7);\n  context.strokeStyle = input.colors.core;\n  context.globalAlpha = trace.flicker;\n  context.lineWidth = Math.max(1.5, geometry.lineWidth * 0.5);\n  traceLine(context, input, 1, 1);\n  context.stroke();\n  strokeBranches(context, input, 1, 1);\n  strokeSparks(\n    context,\n    trace.sparks,\n    Math.max(1, geometry.lineWidth * 0.4),\n    SPARK_TRAIL_SECONDS\n  );\n};\n\nexport const ElectricWaveform = ({\n  source,\n  mode = \"wave\",\n  loading = false,\n  intensity = DEFAULT_INTENSITY,\n  arcs = true,\n  sparks = true,\n  sensitivity = 1,\n  lineWidth = DEFAULT_LINE_WIDTH,\n  fadeEdges = true,\n  actionsRef,\n  className,\n  ref,\n  ...props\n}: ElectricWaveformProps) => {\n  const reducedMotion = useReducedMotion();\n  const rootRef = useRef<HTMLDivElement | null>(null);\n  const visibleRef = useVisibility(rootRef);\n  const glowRef = useRef<HTMLCanvasElement | null>(null);\n  const mainRef = useRef<HTMLCanvasElement | null>(null);\n  const frameRef = useRef<VisualFrame | null>(null);\n\n  const paint = useCallback((frame: VisualFrame) => {\n    frameRef.current = frame;\n  }, []);\n\n  useFrameSource(source, paint);\n\n  useImperativeHandle(\n    actionsRef,\n    () => ({\n      clear: () => {\n        frameRef.current = null;\n      },\n      paint,\n    }),\n    [paint]\n  );\n\n  // Stroke options are read each paint, so changing them doesn't rebuild the\n  // trace and reset its sparks, forks and loudness.\n  const readStroke = useEffectEvent(() => ({\n    fade: fadeEdges,\n    width: lineWidth,\n  }));\n\n  useEffect(() => {\n    const root = rootRef.current;\n    const main = mainRef.current;\n    const glow = glowRef.current;\n    const mainContext = main?.getContext(\"2d\");\n    const glowContext = glow?.getContext(\"2d\");\n    if (!(root && main && glow && mainContext && glowContext)) {\n      return;\n    }\n    const strength = clamp(intensity, 0, 1);\n    const trace = createElectricTrace({\n      arcs,\n      intensity: strength,\n      loading,\n      mode,\n      reducedMotion,\n      sensitivity,\n      sparks,\n    });\n    let size: ElectricCanvasSize = {\n      glowRatio: 1,\n      height: 0,\n      ratio: 1,\n      width: 0,\n    };\n    let colors = readElectricColors(main, glow);\n    let framesSinceColor = 0;\n    let lastPaintMs = 0;\n    let active = false;\n\n    const resize = () => {\n      size = fitElectricCanvases(main, glow);\n    };\n    resize();\n    const observer = new ResizeObserver(resize);\n    observer.observe(main);\n\n    const tick = (nowMs: number) => {\n      if (!visibleRef.current || size.width === 0) {\n        return;\n      }\n      framesSinceColor += 1;\n      if (framesSinceColor >= COLOR_REFRESH_FRAMES) {\n        framesSinceColor = 0;\n        colors = readElectricColors(main, glow);\n      }\n      if (reducedMotion && nowMs - lastPaintMs < REDUCED_MOTION_INTERVAL_MS) {\n        return;\n      }\n      lastPaintMs = nowMs;\n      const stroke = readStroke();\n      const geometry: ElectricTraceGeometry = {\n        height: size.height,\n        lineWidth: stroke.width,\n        width: size.width,\n      };\n      const nextActive = trace.step(nowMs, frameRef.current, geometry);\n      if (nextActive !== active) {\n        active = nextActive;\n        root.toggleAttribute(\"data-active\", active);\n      }\n      const input: PaintInput = {\n        colors,\n        geometry,\n        intensity: reducedMotion ? 0 : strength,\n        nowMs,\n        trace,\n      };\n      clearElectricCanvas(glowContext, size, size.glowRatio);\n      paintGlow(glowContext, input);\n      clearElectricCanvas(mainContext, size, size.ratio);\n      paintMain(mainContext, input);\n      if (stroke.fade) {\n        fadeEnds(glowContext, geometry);\n        fadeEnds(mainContext, geometry);\n      }\n    };\n\n    const unsubscribe = subscribeFrame(tick);\n    return () => {\n      unsubscribe();\n      observer.disconnect();\n      delete root.dataset.active;\n    };\n  }, [\n    arcs,\n    intensity,\n    loading,\n    mode,\n    reducedMotion,\n    sensitivity,\n    sparks,\n    visibleRef,\n  ]);\n\n  const setRootRef = useCallback(\n    (node: HTMLDivElement | null) => {\n      rootRef.current = node;\n      if (typeof ref === \"function\") {\n        ref(node);\n      } else if (ref) {\n        ref.current = node;\n      }\n    },\n    [ref]\n  );\n\n  return (\n    <div\n      aria-label=\"Audio waveform\"\n      className={cn(\"relative h-24 w-full\", className)}\n      data-loading={loading ? \"\" : undefined}\n      data-mode={mode}\n      data-slot=\"electric-waveform\"\n      role=\"img\"\n      {...props}\n      ref={setRootRef}\n    >\n      <canvas\n        aria-hidden\n        className={ELECTRIC_GLOW_CLASS}\n        data-slot=\"electric-waveform-glow\"\n        ref={glowRef}\n      />\n      <canvas\n        aria-hidden\n        className={ELECTRIC_CANVAS_CLASS}\n        data-slot=\"electric-waveform-canvas\"\n        ref={mainRef}\n      />\n    </div>\n  );\n};\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}