{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"ink-cloud-blooming-in-water-background","type":"registry:block","title":"Ink Cloud Blooming in Water","description":"","dependencies":[],"files":[{"path":"components/we-inc/ink-cloud-blooming-in-water-background.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\n// Ink colours as [r, g, b]: indigo, sepia and a deep teal.\nconst INKS = [\n  [38, 50, 98],\n  [112, 72, 46],\n  [24, 82, 92],\n];\n// The water and paper behind the ink.\nconst WATER = [238, 233, 224];\n// Seconds one bloom takes to open, spread and fade.\nconst LIFE = 16;\n// How dark the ink can get. Keep it modest so the text stays readable.\nconst STRENGTH = 1.7;\n// Where blooms start, as fractions of width and height (kept away from the headline).\nconst SPOTS = [\n  [0.78, 0.32], [0.62, 0.78], [0.92, 0.64], [0.7, 0.12], [0.86, 0.92], [0.56, 0.45],\n];\n\nconst css = `\n.ink-grain{background-image:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url%28%23g%29'/%3E%3C/svg%3E\");mix-blend-mode:multiply;opacity:.3}\n`;\n\ntype Bloom = { x: number; y: number; born: number; size: number; ink: number[] };\n\nexport default function InkCloudBloomingInWater() {\n  const rootRef = useRef<HTMLElement>(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    if (!root || !canvas || !ctx) return;\n    const still = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    // Drawn at low resolution and stretched smoothly by the browser.\n    const W = 140;\n    let H = 70;\n    let aspect = 1.6;\n    let narrow = false;\n    let img = ctx.createImageData(W, H);\n    let raf = 0;\n    let onScreen = true;\n    let next = 0;\n    const clock = () => performance.now() / 1000;\n    const spawn = (born: number): Bloom => {\n      const [sx, sy] = SPOTS[next % SPOTS.length];\n      const ink = INKS[next % INKS.length];\n      next += 1;\n      // On narrow screens the text fills the width, so ink rises from the bottom edge instead.\n      const x = narrow ? 0.15 + ((sx - 0.5) / 0.45) * 0.7 : sx;\n      const y = narrow ? 0.78 + sy * 0.25 : sy;\n      return { x: x + (Math.random() - 0.5) * 0.06, y, born, size: 0.16 + Math.random() * 0.08, ink };\n    };\n    let blooms: Bloom[] = [];\n    const seed = () => {\n      const now = clock();\n      next = 0;\n      // Start mid-story: blooms at different ages so the first frame is already full.\n      blooms = [0, 1, 2, 3, 4].map((k) => spawn(now - LIFE * (0.15 + k * 0.17)));\n    };\n\n    const draw = (t: number) => {\n      const d = img.data;\n      let o = 0;\n      for (const b of blooms) if (t - b.born > LIFE) Object.assign(b, spawn(t));\n      const live = blooms.map((b) => {\n        const a = Math.min(1, Math.max(0, (t - b.born) / LIFE));\n        const sigma = b.size * (0.3 + 1.1 * Math.sqrt(a));\n        return { x: b.x * aspect, y: b.y, amp: Math.pow(1 - a, 1.4) * Math.min(1, a * 7), k: 1 / (sigma * sigma), ink: b.ink };\n      });\n      for (let y = 0; y < H; y++) {\n        const ny = y / (H - 1);\n        for (let x = 0; x < W; x++) {\n          const nx = (x / (W - 1)) * aspect;\n          // Curl the sample point so blooms grow feathered edges instead of perfect circles.\n          const wx = nx + 0.05 * Math.sin(ny * 9 + t * 0.21) + 0.03 * Math.sin(ny * 27 - t * 0.4) + 0.012 * Math.sin((nx + ny) * 61 + t * 0.5);\n          const wy = ny + 0.05 * Math.cos(nx * 7 - t * 0.17) + 0.03 * Math.cos(nx * 23 + t * 0.33) + 0.012 * Math.cos((nx - ny) * 57 - t * 0.45);\n          let ar = 0, ag = 0, ab = 0;\n          for (const b of live) {\n            const dx = wx - b.x, dy = wy - b.y;\n            // A darker rim where the spreading edge meets clear water.\n            const q = (dx * dx + dy * dy) * b.k;\n            const v = b.amp * Math.exp(-q) * (0.75 + 0.5 * Math.exp(-Math.abs(q - 1.2) * 3));\n            ar += v * (1 - b.ink[0] / 255); ag += v * (1 - b.ink[1] / 255); ab += v * (1 - b.ink[2] / 255);\n          }\n          d[o] = WATER[0] * Math.exp(-ar * STRENGTH);\n          d[o + 1] = WATER[1] * Math.exp(-ag * STRENGTH);\n          d[o + 2] = WATER[2] * Math.exp(-ab * STRENGTH);\n          d[o + 3] = 255;\n          o += 4;\n        }\n      }\n      ctx.putImageData(img, 0, 0);\n    };\n\n    const loop = () => {\n      draw(clock());\n      if (onScreen && !still) raf = requestAnimationFrame(loop);\n    };\n    const resize = () => {\n      const box = root.getBoundingClientRect();\n      aspect = Math.max(0.4, box.width / Math.max(1, box.height));\n      const wasNarrow = narrow;\n      narrow = box.width < 700;\n      H = Math.max(30, Math.min(180, Math.round(W / aspect)));\n      canvas.width = W; canvas.height = H;\n      img = ctx.createImageData(W, H);\n      if (!blooms.length || wasNarrow !== narrow) seed();\n      draw(clock());\n    };\n    const ro = new ResizeObserver(resize);\n    ro.observe(root);\n    const io = new IntersectionObserver(([e]) => {\n      onScreen = e.isIntersecting;\n      cancelAnimationFrame(raf);\n      if (onScreen && !still) raf = requestAnimationFrame(loop);\n    });\n    io.observe(root);\n    resize();\n    return () => { cancelAnimationFrame(raf); ro.disconnect(); io.disconnect(); };\n  }, []);\n\n  return (\n    <section ref={rootRef} className=\"relative isolate flex min-h-[600px] items-center overflow-hidden bg-[#eee9e0]\">\n      <style>{css}</style>\n      <canvas ref={canvasRef} aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 -z-10 h-full w-full\" />\n      <div aria-hidden=\"true\" className=\"ink-grain pointer-events-none absolute inset-0 -z-10\" />\n      <div className=\"mx-auto w-full max-w-5xl px-6 pb-[200px] pt-20 sm:px-10 md:py-24\">\n        <p className=\"text-[13px] font-semibold uppercase tracking-[0.18em] text-[#3a4466]\">Sumi &amp; Water Studio</p>\n        <h1 className=\"mt-4 max-w-[34rem] font-serif text-[34px] font-medium leading-[1.1] text-[#161b2a] sm:text-[54px]\">Brush lettering for beginners, taught at one long wooden table.</h1>\n        <p className=\"mt-5 max-w-[28rem] text-lg leading-relaxed text-[#363c4d]\">Two-hour evening classes with ground ink, real brushes and paper that forgives a shaky first stroke.</p>\n        <a href=\"#\" className=\"mt-8 inline-flex h-12 items-center rounded-md bg-[#1c2440] px-6 text-[15px] font-semibold text-[#f3efe7] hover:bg-[#2a3458] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#1c2440] focus-visible:ring-offset-2 focus-visible:ring-offset-[#eee9e0]\">Reserve a seat</a>\n      </div>\n    </section>\n  );\n}\n"}]}
