{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bokeh",
  "type": "registry:ui",
  "title": "Bokeh",
  "description": "Dreamy out-of-focus lights: a parallax field of soft circular light discs — each with a brighter aperture rim — drifting slowly through the dark, sized and layered by depth like night lights through a defocused lens, with a few sharp in-focus specks. 2D canvas with additive blending, seeded PRNG for a deterministic scatter, pauses offscreen, honors prefers-reduced-motion with a still scatter.",
  "dependencies": [],
  "registryDependencies": [
    "https://crucibleui.com/r/use-visibility-pause.json",
    "https://crucibleui.com/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/default/backgrounds/bokeh/bokeh.tsx",
      "type": "registry:ui",
      "target": "components/crucible/bokeh.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { useReducedMotion } from \"@/hooks/use-reduced-motion\";\nimport { useVisibilityPause } from \"@/hooks/use-visibility-pause\";\n\nexport interface BokehProps extends React.ComponentPropsWithoutRef<\"div\"> {\n  /**\n   * Light colors, sampled across the depth field. Defaults to a warm-neutral\n   * palette — champagne, soft amber, warm ivory with one cool accent — so it\n   * reads like city lights through a defocused lens. Pass any palette; e.g.\n   * `[\"#5eead4\", \"#818cf8\", \"#f0abfc\"]` for a cool jewel look.\n   * @default [\"#ffdca8\", \"#ffe7cf\", \"#f3e2c4\", \"#bcd0ff\"]\n   */\n  colors?: string[];\n  /** Number of light discs in the field. Clamped 8–140. @default 40 */\n  density?: number;\n  /** Drift-speed multiplier. 1 = default, 2 = twice as fast. @default 1 */\n  speed?: number;\n  /** Overall brightness / bloom, 0–2. @default 1 */\n  intensity?: number;\n  /** Deterministic seed — the same seed always renders the same scatter. @default 1 */\n  seed?: number;\n  /** Freeze the field at a still, aesthetic scatter. @default false */\n  paused?: boolean;\n  /** devicePixelRatio ceiling. Clamped 1–2. @default 2 */\n  dpr?: number;\n}\n\nconst DEFAULT_COLORS = [\"#ffdca8\", \"#ffe7cf\", \"#f3e2c4\", \"#bcd0ff\"];\n// Warm near-black bed the lights glow against — never flat #000.\nconst BG: [number, number, number] = [9, 8, 10];\n\n/** Deterministic mulberry32 PRNG — same seed always produces the same sequence. */\nfunction mulberry32(seed: number): () => number {\n  let a = seed >>> 0;\n  return () => {\n    a |= 0;\n    a = (a + 0x6d2b79f5) | 0;\n    let t = Math.imul(a ^ (a >>> 15), 1 | a);\n    t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;\n    return ((t ^ (t >>> 14)) >>> 0) / 4294967296;\n  };\n}\n\n/** Normalize any CSS color string to [r,g,b] using a throwaway 1×1 fill. */\nfunction colorToRgb(ctx: CanvasRenderingContext2D, color: string): [number, number, number] {\n  ctx.clearRect(0, 0, 1, 1);\n  ctx.fillStyle = color;\n  ctx.fillRect(0, 0, 1, 1);\n  const d = ctx.getImageData(0, 0, 1, 1).data;\n  return [d[0], d[1], d[2]];\n}\n\n/**\n * Pre-render one soft out-of-focus bokeh disc per palette color: a gently lit\n * flat interior with a slightly brighter aperture rim near the edge, fading to\n * transparent — the signature look of a light thrown out of focus by a fast\n * lens. Drawn additively so overlapping discs bloom.\n */\nfunction makeDisc(rgb: [number, number, number], D: number): HTMLCanvasElement {\n  const c = document.createElement(\"canvas\");\n  c.width = D;\n  c.height = D;\n  const g = c.getContext(\"2d\")!;\n  const cx = D / 2;\n  const [r, gg, b] = rgb;\n  // Rim pushed a little toward white — the brighter aperture edge.\n  const rr = Math.round(r * 0.55 + 255 * 0.45);\n  const rg = Math.round(gg * 0.55 + 255 * 0.45);\n  const rb = Math.round(b * 0.55 + 255 * 0.45);\n  const grad = g.createRadialGradient(cx, cx, 0, cx, cx, cx);\n  grad.addColorStop(0, `rgba(${r},${gg},${b},0.26)`);\n  grad.addColorStop(0.5, `rgba(${r},${gg},${b},0.3)`);\n  grad.addColorStop(0.78, `rgba(${rr},${rg},${rb},0.46)`);\n  grad.addColorStop(0.9, `rgba(${r},${gg},${b},0.2)`);\n  grad.addColorStop(1, `rgba(${r},${gg},${b},0)`);\n  g.fillStyle = grad;\n  g.fillRect(0, 0, D, D);\n  return c;\n}\n\n/**\n * Pre-render one sharp in-focus speck per palette color: a hot white core in a\n * tight colored glow. A few of these punctuate the soft field.\n */\nfunction makeSpeck(rgb: [number, number, number], D: number): HTMLCanvasElement {\n  const c = document.createElement(\"canvas\");\n  c.width = D;\n  c.height = D;\n  const g = c.getContext(\"2d\")!;\n  const cx = D / 2;\n  const [r, gg, b] = rgb;\n  const grad = g.createRadialGradient(cx, cx, 0, cx, cx, cx);\n  grad.addColorStop(0, `rgba(255,255,255,1)`);\n  grad.addColorStop(0.18, `rgba(${Math.round(r * 0.4 + 153)},${Math.round(gg * 0.4 + 153)},${Math.round(b * 0.4 + 153)},0.9)`);\n  grad.addColorStop(0.5, `rgba(${r},${gg},${b},0.35)`);\n  grad.addColorStop(1, `rgba(${r},${gg},${b},0)`);\n  g.fillStyle = grad;\n  g.fillRect(0, 0, D, D);\n  return c;\n}\n\ninterface Disc {\n  x: number; // device px\n  y: number; // device px\n  z: number; // depth 0 (far/small) → 1 (near/large & softer)\n  size: number; // draw diameter, device px\n  colorIndex: number;\n  focus: boolean; // sharp in-focus speck?\n  bright: number; // base brightness\n  vx: number; // drift, device px/s (before speed mult)\n  vy: number;\n  swayAmp: number; // gentle orbital sway amplitude, device px\n  swayFreq: number;\n  swayPhase: number;\n  twinkleAmp: number;\n  twinkleFreq: number;\n  twinklePhase: number;\n}\n\nfunction makeDisc_(rand: () => number, w: number, h: number, scale: number, paletteLen: number): Disc {\n  // Bias depth toward \"far\" so many small soft lights sit behind a few big ones.\n  const z = rand() * rand();\n  // ~14% are sharp in-focus specks — the bright punctuation.\n  const focus = rand() < 0.14;\n  const size = focus\n    ? (5 + rand() * 9) * scale\n    : (34 + z * 150) * scale; // out-of-focus discs are large and grow with depth\n  // Parallax: nearer (bigger) lights drift faster across the frame.\n  const drift = (6 + z * 26) * scale;\n  const ang = rand() * Math.PI * 2;\n  return {\n    x: rand() * w,\n    y: rand() * h,\n    z,\n    size,\n    colorIndex: Math.floor(rand() * paletteLen),\n    focus,\n    bright: focus ? 0.7 + rand() * 0.3 : 0.28 + z * 0.45,\n    vx: Math.cos(ang) * drift,\n    vy: Math.sin(ang) * drift * 0.7,\n    swayAmp: (4 + z * 16) * scale,\n    swayFreq: 0.05 + rand() * 0.14,\n    swayPhase: rand() * Math.PI * 2,\n    twinkleAmp: focus ? 0.28 : 0.12,\n    twinkleFreq: focus ? 0.6 + rand() * 1.4 : 0.15 + rand() * 0.4,\n    twinklePhase: rand() * Math.PI * 2,\n  };\n}\n\nfunction buildField(density: number, seed: number, w: number, h: number, scale: number, paletteLen: number): Disc[] {\n  const count = Math.min(140, Math.max(8, Math.round(density)));\n  const rand = mulberry32(seed);\n  const out: Disc[] = [];\n  for (let i = 0; i < count; i++) out.push(makeDisc_(rand, w, h, scale, paletteLen));\n  // Sort far → near so big near discs layer over small far ones.\n  out.sort((a, b) => a.z - b.z);\n  return out;\n}\n\ninterface Internals {\n  ctx: CanvasRenderingContext2D;\n  w: number;\n  h: number;\n  scale: number;\n  discs: HTMLCanvasElement[];\n  specks: HTMLCanvasElement[];\n  field: Disc[];\n  intensity: number;\n  last: number;\n}\n\nfunction paintBackground(it: Internals) {\n  const { ctx } = it;\n  ctx.globalCompositeOperation = \"source-over\";\n  ctx.globalAlpha = 1;\n  // Very dark warm-neutral base with a faint vertical lift so it never reads dead.\n  const grad = ctx.createLinearGradient(0, 0, 0, it.h);\n  grad.addColorStop(0, `rgb(${BG[0] + 3},${BG[1] + 2},${BG[2] + 4})`);\n  grad.addColorStop(1, `rgb(${BG[0]},${BG[1]},${BG[2]})`);\n  ctx.fillStyle = grad;\n  ctx.fillRect(0, 0, it.w, it.h);\n}\n\nfunction drawDisc(it: Internals, d: Disc, t: number, animate: boolean) {\n  const twinkle = animate ? 1 + d.twinkleAmp * Math.sin(d.twinklePhase + t * d.twinkleFreq * Math.PI * 2) : 1;\n  const alpha = Math.max(0, Math.min(1, d.bright * twinkle * it.intensity));\n  if (alpha <= 0.002) return;\n  const sprite = d.focus ? it.specks[d.colorIndex] : it.discs[d.colorIndex];\n  const sway = animate ? d.swayAmp * Math.sin(d.swayPhase + t * d.swayFreq * Math.PI * 2) : 0;\n  const swayY = animate ? d.swayAmp * 0.6 * Math.cos(d.swayPhase * 1.3 + t * d.swayFreq * Math.PI * 2) : 0;\n  const { ctx } = it;\n  ctx.globalCompositeOperation = \"lighter\";\n  ctx.globalAlpha = alpha;\n  const s = d.size;\n  ctx.drawImage(sprite, d.x + sway - s / 2, d.y + swayY - s / 2, s, s);\n}\n\n/** One animated frame: clear, advance drift with edge-wrap, draw additively. */\nfunction tickFrame(it: Internals, dt: number, t: number, speedFactor: number) {\n  paintBackground(it);\n  for (const d of it.field) {\n    const m = d.size; // wrap margin = draw size so discs never pop\n    d.x += d.vx * speedFactor * dt;\n    d.y += d.vy * speedFactor * dt;\n    if (d.x < -m) d.x = it.w + m;\n    else if (d.x > it.w + m) d.x = -m;\n    if (d.y < -m) d.y = it.h + m;\n    else if (d.y > it.h + m) d.y = -m;\n    drawDisc(it, d, t, true);\n  }\n}\n\n/** Still, handsome scatter for paused / reduced-motion — lights at rest. */\nfunction drawStatic(it: Internals) {\n  paintBackground(it);\n  for (const d of it.field) drawDisc(it, d, 0, false);\n}\n\n/**\n * Bokeh — dreamy out-of-focus lights. A parallax field of soft circular light\n * discs drifting slowly through the dark, each a gently-lit disc with a brighter\n * aperture rim, sized and layered by depth so the frame reads volumetric — like\n * night lights seen through a defocused fast lens. A handful of sharp in-focus\n * specks punctuate the softness. 2D canvas with additive blending; seeded PRNG\n * for a deterministic scatter (no hydration mismatch), pauses offscreen and on\n * hidden tabs, and honors prefers-reduced-motion with a still scatter of lights.\n * Warm-neutral by default; pass `colors` for any palette. Drop it inside any\n * `relative` container.\n */\nexport function Bokeh({\n  colors = DEFAULT_COLORS,\n  density = 40,\n  speed = 1,\n  intensity = 1,\n  seed = 1,\n  paused = false,\n  dpr = 2,\n  className,\n  style,\n  ...props\n}: BokehProps) {\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n  const internalsRef = React.useRef<Internals | null>(null);\n  const reducedMotion = useReducedMotion();\n\n  const speedFactor = Math.max(speed, 0);\n  const frozen = paused || reducedMotion;\n  const colorsKey = colors.join(\",\");\n\n  const tick = React.useCallback(\n    (elapsed: number) => {\n      const it = internalsRef.current;\n      if (!it) return;\n      let dt = elapsed - it.last;\n      it.last = elapsed;\n      if (dt > 0.05) dt = 0.05; // clamp tab-restore jumps\n      if (dt <= 0) return;\n      tickFrame(it, dt, elapsed, speedFactor);\n    },\n    [speedFactor]\n  );\n\n  const containerRef = useVisibilityPause<HTMLDivElement>(tick, { paused: frozen });\n\n  // Set up canvas, sprites and the field; rebuild on size / palette / seed / density.\n  React.useEffect(() => {\n    const canvas = canvasRef.current;\n    const container = containerRef.current;\n    if (!canvas || !container) return;\n\n    const ctx = canvas.getContext(\"2d\", { alpha: false });\n    if (!ctx) return;\n\n    const scale = Math.min(\n      typeof window !== \"undefined\" ? window.devicePixelRatio || 1 : 1,\n      Math.min(Math.max(dpr, 1), 2)\n    );\n    const palette = colors.length ? colors : DEFAULT_COLORS;\n    const rgbs = palette.map((c) => colorToRgb(ctx, c));\n    // Soft discs are big; specks are tiny. Sprite resolution is generous but fixed.\n    const discSprites = rgbs.map((c) => makeDisc(c, Math.max(64, Math.round(220 * scale))));\n    const speckSprites = rgbs.map((c) => makeSpeck(c, Math.max(24, Math.round(48 * scale))));\n\n    const build = () => {\n      const w = Math.max(1, Math.round(container.clientWidth * scale));\n      const h = Math.max(1, Math.round(container.clientHeight * scale));\n      canvas.width = w;\n      canvas.height = h;\n      const it: Internals = {\n        ctx,\n        w,\n        h,\n        scale,\n        discs: discSprites,\n        specks: speckSprites,\n        field: buildField(density, seed, w, h, scale, rgbs.length),\n        intensity: Math.max(intensity, 0),\n        last: internalsRef.current?.last ?? 0,\n      };\n      internalsRef.current = it;\n      // Paint one frame immediately so mount/resize never flashes empty.\n      if (frozen) drawStatic(it);\n      else {\n        paintBackground(it);\n        for (const d of it.field) drawDisc(it, d, 0, false);\n      }\n    };\n\n    const ro = new ResizeObserver(build);\n    ro.observe(container);\n    build();\n\n    return () => {\n      ro.disconnect();\n      internalsRef.current = null;\n    };\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [density, seed, colorsKey, dpr]);\n\n  // Re-render the still frame in place when frozen toggles / intensity tweaks.\n  React.useEffect(() => {\n    const it = internalsRef.current;\n    if (!it) return;\n    it.intensity = Math.max(intensity, 0);\n    if (frozen) drawStatic(it);\n  }, [frozen, intensity]);\n\n  return (\n    <div\n      ref={containerRef}\n      aria-hidden\n      data-crucible=\"bokeh\"\n      className={cn(\"absolute inset-0 -z-10 overflow-hidden\", className)}\n      style={style}\n      {...props}\n    >\n      <canvas ref={canvasRef} className=\"block h-full w-full\" />\n    </div>\n  );\n}\n"
    }
  ]
}