{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"ink-drop-progress-indicator-that-blooms-through-a-glass-of-water-one-drop-per-step","type":"registry:component","title":"Ink Drop Progress Indicator That Blooms Through a Glass of Water, One Drop per Step","description":"Progress indicator on a canvas: a dropper lets ink fall into a glass of water, each drop blooms and the water darkens per step. Free React and HTML code.","dependencies":[],"files":[{"path":"components/we-inc/ink-drop-progress-indicator-that-blooms-through-a-glass-of-water-one-drop-per-step.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\n\n// Everything a visitor is likely to change sits here.\nconst TASK = \"Sending proof sheets\";\nconst DONE = \"Sent\";\nconst STEPS = 5; // drops of ink it takes to reach 100%\nconst VALUE: number | null = null; // 0 to 1 shows real progress (one drop per 1/STEPS); null plays the demo\nconst INK = \"#1c2cab\";\nconst EVERY = 2.7; // seconds between drops in the demo\n\nconst W = 560, H = 580, CX = 280, TOP = 150, BOT = 494, RT = 114, RB = 100, WALL = 5, BASE = 26, TIP = 88;\nconst rgb = (hex: string) => [parseInt(hex.slice(1, 3), 16), parseInt(hex.slice(3, 5), 16), parseInt(hex.slice(5, 7), 16)];\nconst mix = (a: string, b: string, t: number, al = 1) => {\n  const p = rgb(a), q = rgb(b);\n  return `rgba(${p.map((v, i) => Math.round(v + (q[i] - v) * t)).join(\",\")},${al})`;\n};\nconst BLUE = \"#\" + rgb(INK).map((v) => Math.round(v + (255 - v) * 0.18).toString(16).padStart(2, \"0\")).join(\"\"); // the ink thinned by water\nconst clamp = (v: number, a = 0, b = 1) => Math.max(a, Math.min(b, v));\ntype Ctx = CanvasRenderingContext2D;\ntype Pair = { x: number; y: number; dx: number; dy: number; g: number; a: number; age: number; gen: number; split: boolean };\n\nexport default function InkDropProgressGlass() {\n  const canvas = useRef<HTMLCanvasElement>(null);\n  const [pct, setPct] = useState(VALUE === null ? 40 : Math.round(VALUE * 100));\n  const api = useRef<{ add: () => void } | null>(null);\n\n  useEffect(() => {\n    const cv = canvas.current;\n    if (!cv) return;\n    const ctx = cv.getContext(\"2d\");\n    if (!ctx) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const yF = BOT - BASE, yS = TOP + 50; // the floor of the glass and the surface of the water\n    const rO = (y: number) => RT + ((RB - RT) * (y - TOP)) / (BOT - TOP);\n    const rI = (y: number) => rO(y) - WALL;\n    const ec = (y: number) => 0.17 + (0.07 * (y - TOP)) / (BOT - TOP);\n    const slab = (c: Ctx, y0: number, y1: number, rf: (y: number) => number) => {\n      c.beginPath(); c.moveTo(CX - rf(y0), y0); c.lineTo(CX - rf(y1), y1);\n      c.ellipse(CX, y1, rf(y1), rf(y1) * ec(y1), 0, Math.PI, 0, true);\n      c.lineTo(CX + rf(y0), y0); c.ellipse(CX, y0, rf(y0), rf(y0) * ec(y0), 0, 0, Math.PI, true); c.closePath();\n    };\n    let k = 1, seed = 7;\n    const rand = () => { seed = (seed * 16807) % 2147483647; return seed / 2147483647; };\n\n    // One soft dot of ink, stamped a couple of thousand times a frame.\n    const dot = document.createElement(\"canvas\"); dot.width = dot.height = 64;\n    {\n      const c = dot.getContext(\"2d\");\n      if (c) {\n        const g = c.createRadialGradient(32, 32, 0, 32, 32, 32);\n        g.addColorStop(0, mix(INK, \"#000000\", 0.1, 1)); g.addColorStop(0.35, mix(INK, \"#ffffff\", 0, 0.62)); g.addColorStop(0.7, mix(INK, \"#ffffff\", 0.06, 0.16)); g.addColorStop(1, mix(INK, \"#ffffff\", 0.1, 0));\n        c.fillStyle = g; c.fillRect(0, 0, 64, 64);\n      }\n    }\n    const ink = document.createElement(\"canvas\");\n    const iX = CX - RT, iY = yS - 8, iW = RT * 2, iH = yF - yS + 44;\n    let ictx: Ctx | null = null, kq = 1;\n    const fit = () => {\n      const b = cv.getBoundingClientRect(), dpr = Math.min(2, window.devicePixelRatio || 1);\n      cv.width = Math.max(2, Math.round(b.width * dpr)); cv.height = Math.round((cv.width * H) / W); k = cv.width / W;\n      kq = Math.min(k, 1.2) * 0.75; /* ink is soft, so it is painted small and scaled up */ ink.width = Math.ceil(iW * kq); ink.height = Math.ceil(iH * kq); ictx = ink.getContext(\"2d\");\n    };\n\n    // The ink is a cloud of points carried by sinking vortex pairs. A pair rolls the ink into a mushroom, then\n    // breaks into two smaller pairs, which is what makes a real drop branch like a chandelier.\n    const N = 380, MAX = N * STEPS;\n    const px = new Float32Array(MAX), py = new Float32Array(MAX), pa = new Float32Array(MAX);\n    let count = 0;\n    let pairs: Pair[] = [];\n    const xs = [-10, 30, -44, 12, 52, -26, 40, -6];\n    const s = {\n      t: 0, landed: 0, shown: 0, next: 0.4, held: 0, clear: 0, light: 0, lightTo: 0, pip: CX + xs[0],\n      drop: { on: 0, t: 0, x: 0, y: 0, v: 0 }, rip: [] as { x: number; t: number }[], mx: 0, my: 0, mvx: 0, mvy: 0, min: false,\n    };\n\n    const land = (x: number) => {\n      const from = count >= MAX ? 0 : count;\n      if (count >= MAX) count = 0;\n      for (let i = 0; i < N; i++) {\n        const a = rand() * Math.PI * 2, stem = i % 5 === 0, d = Math.sqrt(rand()) * (stem ? 2.4 : 6.5);\n        px[from + i] = x + Math.cos(a) * d; py[from + i] = yS + (stem ? 4 + rand() * 30 : 10 + Math.sin(a) * d * 0.8); pa[from + i] = rand() * 0.2;\n      }\n      count = Math.max(count, from + N);\n      pairs.push({ x, y: yS + 9, dx: (rand() - 0.5) * 0.16, dy: 1, g: 1900, a: 8, age: 0, gen: 0, split: false });\n      s.rip.push({ x, t: 0 }); s.landed++;\n    };\n\n    const step = (dt: number) => {\n      const born: Pair[] = [];\n      for (const p of pairs) {\n        p.age += dt;\n        const room = clamp((yF - 26 - p.y) / 60), sp = (p.g / (2 * p.a)) * room;\n        p.x += p.dx * sp * dt; p.y += p.dy * sp * dt;\n        p.g *= Math.exp(-dt / (p.gen ? 2.3 : 1.9)); p.a += (3.5 + 34 * (1 - room)) * dt;\n        const lim = rI(p.y) - p.a - 10; p.x = clamp(p.x, CX - lim, CX + lim);\n        if (!p.split && p.gen < 3 && p.age > 0.6 + p.gen * 0.25) {\n          p.split = true;\n          for (const sgn of [-1, 1]) {\n            const turn = sgn * (0.36 + rand() * 0.34), c = Math.cos(turn), sn = Math.sin(turn);\n            born.push({ x: p.x - p.dy * p.a * sgn * -1, y: p.y + p.dx * p.a * sgn * -1 + 4, dx: p.dx * c - p.dy * sn, dy: Math.max(0.5, p.dx * sn + p.dy * c), g: p.g * 0.6, a: p.a * 0.6, age: 0, gen: p.gen + 1, split: false });\n          }\n          p.g *= 0.34;\n        }\n      }\n      pairs = pairs.concat(born).filter((p) => p.g > 6);\n      const n = pairs.length, t = s.t;\n      for (let i = 0; i < count; i++) {\n        const x = px[i], y = py[i];\n        const wall = rI(y) - Math.abs(x - CX); // ink is eased off the glass so it never stacks up in a hard line\n        let u = 3 * Math.cos(x * 0.021 + t * 0.31) * Math.sin(y * 0.017 - t * 0.2) + (wall < 26 ? (x > CX ? -1 : 1) * (26 - wall) * 0.9 : 0), v = -4 * Math.sin(x * 0.021 + t * 0.31) * Math.cos(y * 0.017 - t * 0.2) + (4 + 30 * ((i * 0.618) % 1) ** 2) * Math.exp(-pa[i] / 9); // ink is heavier than water, and uneven sinking pulls a cloud out into threads\n        for (let j = 0; j < n; j++) {\n          const p = pairs[j], ox = -p.dy * p.a, oy = p.dx * p.a, core = p.a * p.a * 0.3;\n          let ax = x - (p.x + ox), ay = y - (p.y + oy), r2 = ax * ax + ay * ay + core;\n          u -= (p.g * ay) / r2; v += (p.g * ax) / r2;\n          ax = x - (p.x - ox); ay = y - (p.y - oy); r2 = ax * ax + ay * ay + core;\n          u += (p.g * ay) / r2; v -= (p.g * ax) / r2;\n        }\n        if (s.min) { const ax = x - s.mx, ay = y - s.my, w = Math.exp(-(ax * ax + ay * ay) / 1700); u += s.mvx * w * 0.8; v += s.mvy * w * 0.8; }\n        const jit = Math.sqrt(dt) * 3; // a little diffusion, so threads stay threads and do not bead up\n        let nx = x + clamp(u, -260, 260) * dt + (Math.random() - 0.5) * jit, ny = y + clamp(v, -260, 260) * dt + (Math.random() - 0.5) * jit;\n        ny = clamp(ny, yS + 3, yF + 6);\n        const lim = rI(ny) - 5 - (ny > yF - 12 ? (ny - yF + 12) * 1.5 : 0);\n        nx = clamp(nx, CX - lim, CX + lim);\n        px[i] = nx; py[i] = ny; pa[i] += dt;\n      }\n    };\n\n    const side = (d: number, y0: number, y1: number, w: number, col: string, dir: number) => {\n      ctx.beginPath(); ctx.moveTo(CX + dir * (rO(y0) - d), y0); ctx.lineTo(CX + dir * (rO(y1) - d), y1); ctx.lineWidth = w; ctx.strokeStyle = col; ctx.stroke();\n    };\n\n    const draw = () => {\n      ctx.setTransform(k, 0, 0, k, 0, 0); ctx.clearRect(0, 0, W, H);\n      const lx = s.light * 10, live = 1 - s.clear, tint = s.shown * live, blue = BLUE;\n      let g: CanvasGradient;\n\n      // On the table: shade, a contact line, and the bright smear a glass of water throws beside itself.\n      const floorY = BOT + RB * ec(BOT) * 0.55;\n      ctx.save(); ctx.translate(CX + 40, floorY + 5); ctx.scale(1, 0.2);\n      g = ctx.createRadialGradient(0, 0, 10, 0, 0, 250);\n      g.addColorStop(0, \"rgba(38,54,74,0.42)\"); g.addColorStop(0.45, \"rgba(38,54,74,0.17)\"); g.addColorStop(1, \"rgba(38,54,74,0)\");\n      ctx.fillStyle = g; ctx.beginPath(); ctx.arc(0, 0, 250, 0, Math.PI * 2); ctx.fill(); ctx.restore();\n      ctx.save(); ctx.translate(CX + 4, floorY + 1); ctx.scale(1, 0.24);\n      g = ctx.createRadialGradient(0, 0, RB * 0.6, 0, 0, RB * 1.22);\n      g.addColorStop(0, \"rgba(24,36,52,0.6)\"); g.addColorStop(1, \"rgba(24,36,52,0)\");\n      ctx.fillStyle = g; ctx.beginPath(); ctx.arc(0, 0, RB * 1.22, 0, Math.PI * 2); ctx.fill(); ctx.restore();\n      for (const [ox, len, al] of [[128, 96, 0.95], [150, 58, 0.6]]) {\n        ctx.save(); ctx.translate(CX + ox, floorY + 10); ctx.rotate(-0.04); ctx.scale(1, 0.13);\n        g = ctx.createRadialGradient(0, 0, 0, 0, 0, len);\n        g.addColorStop(0, mix(\"#ffffff\", blue, tint * 0.8, al)); g.addColorStop(0.4, mix(\"#ffffff\", blue, tint, al * 0.5)); g.addColorStop(1, mix(\"#ffffff\", blue, tint, 0));\n        ctx.fillStyle = g; ctx.beginPath(); ctx.arc(0, 0, len, 0, Math.PI * 2); ctx.fill(); ctx.restore();\n      }\n\n      // The far wall.\n      slab(ctx, TOP, BOT, rO);\n      g = ctx.createLinearGradient(CX - RT, 0, CX + RT, 0);\n      g.addColorStop(0, \"rgba(96,116,136,0.3)\"); g.addColorStop(0.15, \"rgba(255,255,255,0.5)\"); g.addColorStop(0.5, \"rgba(255,255,255,0.24)\"); g.addColorStop(0.85, \"rgba(226,236,244,0.34)\"); g.addColorStop(1, \"rgba(90,110,130,0.34)\");\n      ctx.fillStyle = g; ctx.fill();\n\n      // The water, then the ink in it.\n      ctx.save(); slab(ctx, yS, yF, rI); ctx.clip();\n      g = ctx.createLinearGradient(CX - RT, 0, CX + RT, 0);\n      g.addColorStop(0, \"rgba(150,186,206,0.6)\"); g.addColorStop(0.2, \"rgba(232,244,250,0.5)\"); g.addColorStop(0.55, \"rgba(246,251,253,0.42)\"); g.addColorStop(0.86, \"rgba(206,228,240,0.5)\"); g.addColorStop(1, \"rgba(140,176,198,0.66)\");\n      ctx.fillStyle = g; ctx.fillRect(CX - RT, yS - 30, RT * 2, yF - yS + 80);\n      g = ctx.createLinearGradient(0, yS, 0, yF);\n      g.addColorStop(0, mix(INK, \"#ffffff\", 0.3, tint * 0.3)); g.addColorStop(1, mix(INK, \"#ffffff\", 0.12, tint * 0.62));\n      ctx.fillStyle = g; ctx.fillRect(CX - RT, yS - 30, RT * 2, yF - yS + 80);\n      if (ictx && count) {\n        ictx.setTransform(kq, 0, 0, kq, 0, 0); ictx.clearRect(0, 0, iW, iH);\n        for (let i = 0; i < count; i++) {\n          const age = pa[i], r = 2.8 + age * 0.27 + age * age * 0.032, al = Math.min(0.3, 2.6 / (r * r));\n          if (al < 0.03) continue; // by now this ink is part of the even tint of the water\n          const rr = Math.min(r, 40) * 2.1; ictx.globalAlpha = al; ictx.drawImage(dot, px[i] - iX - rr, py[i] - iY - rr, rr * 2, rr * 2);\n          if (i % 6 === 0) { const hr = rr * 2.6; ictx.globalAlpha = clamp(al * 0.3, 0.04, 0.09); ictx.drawImage(dot, px[i] - iX - hr, py[i] - iY - hr, hr * 2, hr * 2); } // a veil of thinner ink round the dense threads\n        }\n        ctx.globalAlpha = live; ctx.drawImage(ink, iX, iY, iW, iH); ctx.globalAlpha = 1;\n      }\n      // Water in a round glass: dark where the wall turns away, one soft column of light, deeper toward the floor.\n      g = ctx.createLinearGradient(CX - RT, 0, CX + RT, 0);\n      g.addColorStop(0, \"rgba(30,60,84,0.42)\"); g.addColorStop(0.05, \"rgba(30,60,84,0.1)\"); g.addColorStop(0.1, \"rgba(255,255,255,0.3)\"); g.addColorStop(0.2, \"rgba(255,255,255,0)\");\n      g.addColorStop(0.8, \"rgba(255,255,255,0)\"); g.addColorStop(0.9, \"rgba(255,255,255,0.22)\"); g.addColorStop(0.95, \"rgba(30,60,84,0.12)\"); g.addColorStop(1, \"rgba(30,60,84,0.46)\");\n      ctx.fillStyle = g; ctx.fillRect(CX - RT, yS - 30, RT * 2, yF - yS + 80);\n      g = ctx.createLinearGradient(0, yS, 0, yF + 20);\n      g.addColorStop(0, \"rgba(255,255,255,0.34)\"); g.addColorStop(0.07, \"rgba(255,255,255,0)\"); g.addColorStop(0.7, \"rgba(20,50,80,0)\"); g.addColorStop(1, \"rgba(20,50,80,0.16)\");\n      ctx.fillStyle = g; ctx.fillRect(CX - RT, yS - 30, RT * 2, yF - yS + 80);\n      ctx.restore();\n\n      // The surface, seen a little from above, with the rings a landing drop sends out.\n      const rs = rI(yS), ry = rs * ec(yS);\n      ctx.save(); ctx.beginPath(); ctx.ellipse(CX, yS, rs, ry, 0, 0, Math.PI * 2); ctx.clip();\n      g = ctx.createLinearGradient(0, yS - ry, 0, yS + ry);\n      g.addColorStop(0, mix(\"#c3d6e2\", blue, tint * 0.5, 0.78)); g.addColorStop(0.5, mix(\"#eef6fa\", blue, tint * 0.4, 0.66)); g.addColorStop(1, mix(\"#ffffff\", blue, tint * 0.3, 0.8));\n      ctx.fillStyle = g; ctx.fillRect(CX - rs, yS - ry, rs * 2, ry * 2);\n      ctx.beginPath(); ctx.ellipse(CX - rs * 0.34 + lx, yS - ry * 0.16, rs * 0.36, ry * 0.3, 0, 0, Math.PI * 2); ctx.fillStyle = \"rgba(255,255,255,0.6)\"; ctx.fill();\n      for (const r of s.rip) for (let j = 0; j < 2; j++) {\n        const q = clamp(r.t / 1.3 - j * 0.22); if (q <= 0) continue;\n        ctx.beginPath(); ctx.ellipse(r.x, yS + 1, 5 + q * rs * 0.9, (5 + q * rs * 0.9) * ec(yS), 0, 0, Math.PI * 2);\n        ctx.lineWidth = 2.2 * (1 - q) + 0.4; ctx.strokeStyle = `rgba(40,70,110,${0.4 * (1 - q)})`; ctx.stroke();\n        ctx.beginPath(); ctx.ellipse(r.x, yS + 2.4, 5 + q * rs * 0.9, (5 + q * rs * 0.9) * ec(yS), 0, 0, Math.PI * 2);\n        ctx.lineWidth = 1.6 * (1 - q) + 0.3; ctx.strokeStyle = `rgba(255,255,255,${0.85 * (1 - q)})`; ctx.stroke();\n      }\n      ctx.restore();\n      ctx.beginPath(); ctx.ellipse(CX, yS, rs - 0.5, ry - 0.4, 0, 0.04 * Math.PI, 0.96 * Math.PI); ctx.lineWidth = 1.8; ctx.strokeStyle = \"rgba(255,255,255,0.95)\"; ctx.stroke();\n      ctx.beginPath(); ctx.ellipse(CX, yS, rs - 0.5, ry - 0.4, 0, 1.04 * Math.PI, 1.96 * Math.PI); ctx.lineWidth = 1; ctx.strokeStyle = \"rgba(70,100,128,0.5)\"; ctx.stroke();\n\n      // A drop on its way down.\n      const d = s.drop;\n      if (d.on) {\n        const r = d.on === 1 ? 5.4 * clamp(d.t / 0.42) : 5.4, stretch = d.on === 2 ? 1 + Math.min(0.5, d.v / 1500) : 1.12;\n        ctx.beginPath(); ctx.moveTo(d.x, d.y - r * stretch * 1.5);\n        ctx.bezierCurveTo(d.x + r * 0.5, d.y - r * 0.7, d.x + r, d.y - r * 0.1, d.x + r, d.y + r * 0.25);\n        ctx.arc(d.x, d.y + r * 0.25, r, 0, Math.PI);\n        ctx.bezierCurveTo(d.x - r, d.y - r * 0.1, d.x - r * 0.5, d.y - r * 0.7, d.x, d.y - r * stretch * 1.5);\n        ctx.fillStyle = mix(INK, \"#000000\", 0.25); ctx.fill();\n        ctx.beginPath(); ctx.ellipse(d.x - r * 0.35, d.y, r * 0.2, r * 0.36, 0.3, 0, Math.PI * 2); ctx.fillStyle = \"rgba(255,255,255,0.75)\"; ctx.fill();\n      }\n\n      // The heavy foot: a lens that picks up the colour of the water above it.\n      const rF = rO(yF);\n      ctx.save();\n      ctx.beginPath(); ctx.moveTo(CX - rF, yF); ctx.lineTo(CX - RB, BOT); ctx.ellipse(CX, BOT, RB, RB * ec(BOT), 0, Math.PI, 0, true); ctx.lineTo(CX + rF, yF);\n      ctx.ellipse(CX, yF, rF, rF * ec(yF), 0, 0, Math.PI, false); ctx.closePath(); ctx.clip();\n      const mid = mix(\"#dfeaf1\", blue, tint * 0.75, 0.62);\n      g = ctx.createLinearGradient(CX - RB, 0, CX + RB, 0);\n      g.addColorStop(0, \"rgba(54,72,92,0.66)\"); g.addColorStop(0.05, \"rgba(255,255,255,0.92)\"); g.addColorStop(0.15, \"rgba(176,196,212,0.55)\"); g.addColorStop(0.32, mid);\n      g.addColorStop(0.64, mid); g.addColorStop(0.8, \"rgba(255,255,255,0.86)\"); g.addColorStop(0.92, \"rgba(190,208,222,0.6)\"); g.addColorStop(1, \"rgba(54,72,92,0.7)\");\n      ctx.fillStyle = g; ctx.fillRect(CX - RT, yF, RT * 2, BASE + 44);\n      g = ctx.createLinearGradient(0, yF + 8, 0, BOT + RB * ec(BOT));\n      g.addColorStop(0, \"rgba(30,50,72,0.3)\"); g.addColorStop(0.4, \"rgba(30,50,72,0)\"); g.addColorStop(0.75, \"rgba(255,255,255,0)\"); g.addColorStop(1, \"rgba(255,255,255,0.7)\");\n      ctx.fillStyle = g; ctx.fillRect(CX - RT, yF, RT * 2, BASE + 44);\n      ctx.beginPath(); ctx.ellipse(CX + 20 + lx, BOT - 6, RB * 0.52, RB * ec(BOT) * 0.5, 0, 0.1 * Math.PI, 0.9 * Math.PI); ctx.lineWidth = 3; ctx.strokeStyle = mix(\"#ffffff\", blue, tint * 0.5, 0.9); ctx.stroke();\n      ctx.restore();\n      ctx.beginPath(); ctx.ellipse(CX, yF, rF - 1, (rF - 1) * ec(yF), 0, 0.04 * Math.PI, 0.96 * Math.PI); ctx.lineWidth = 1.2; ctx.strokeStyle = \"rgba(255,255,255,0.7)\"; ctx.stroke();\n      ctx.beginPath(); ctx.ellipse(CX, yF + 1.6, rF - 1, (rF - 1) * ec(yF), 0, 0.06 * Math.PI, 0.94 * Math.PI); ctx.lineWidth = 0.9; ctx.strokeStyle = \"rgba(40,62,86,0.34)\"; ctx.stroke();\n      ctx.beginPath(); ctx.ellipse(CX, BOT, RB - 0.8, (RB - 0.8) * ec(BOT), 0, 0.03 * Math.PI, 0.97 * Math.PI); ctx.lineWidth = 1.6; ctx.strokeStyle = \"rgba(255,255,255,0.85)\"; ctx.stroke();\n\n      // The wall: a dark line at each silhouette, a lit line inside it, and the studio window down the left.\n      ctx.lineCap = \"round\";\n      for (const dir of [-1, 1]) {\n        side(0.6, TOP, BOT, 1.3, \"rgba(52,70,90,0.62)\", dir); side(2.6, TOP + 3, BOT - 3, 1.6, \"rgba(255,255,255,0.85)\", dir); side(WALL + 0.8, TOP + 6, yF - 4, 1, \"rgba(44,64,86,0.24)\", dir);\n      }\n      const streak = (d0: number, d1: number, y0: number, y1: number, al: number) => {\n        ctx.beginPath(); ctx.moveTo(CX - rO(y0) + d0 + lx, y0); ctx.lineTo(CX - rO(y0) + d1 + lx, y0); ctx.lineTo(CX - rO(y1) + d1 * 0.86 + lx, y1); ctx.lineTo(CX - rO(y1) + d0 * 0.86 + lx, y1); ctx.closePath();\n        const q = ctx.createLinearGradient(0, y0, 0, y1);\n        q.addColorStop(0, \"rgba(255,255,255,0)\"); q.addColorStop(0.07, `rgba(255,255,255,${al})`); q.addColorStop(0.5, `rgba(255,255,255,${al * 0.7})`); q.addColorStop(0.93, `rgba(255,255,255,${al * 0.5})`); q.addColorStop(1, \"rgba(255,255,255,0)\");\n        ctx.fillStyle = q; ctx.fill();\n      };\n      streak(18, 33, TOP + 16, yF - 10, 0.8); streak(38, 41.5, TOP + 22, yF - 26, 0.46); streak(RT * 2 - 31, RT * 2 - 27, TOP + 18, yF - 14, 0.55);\n      streak(RT * 2 - 84, RT * 2 - 50, TOP + 26, TOP + 170, 0.14);\n      // The rim.\n      ctx.beginPath(); ctx.ellipse(CX, TOP, RT - 0.6, RT * ec(TOP), 0, 0, Math.PI * 2); ctx.lineWidth = 3.4; ctx.strokeStyle = \"rgba(240,246,250,0.9)\"; ctx.stroke();\n      ctx.lineWidth = 1; ctx.strokeStyle = \"rgba(60,80,102,0.5)\"; ctx.beginPath(); ctx.ellipse(CX, TOP, RT + 1, RT * ec(TOP) + 1, 0, 0, Math.PI * 2); ctx.stroke();\n      ctx.beginPath(); ctx.ellipse(CX, TOP, RT - 3.4, RT * ec(TOP) - 2.2, 0, 0, Math.PI * 2); ctx.strokeStyle = \"rgba(60,80,102,0.32)\"; ctx.stroke();\n      ctx.beginPath(); ctx.ellipse(CX, TOP, RT - 0.8, RT * ec(TOP) - 0.2, 0, 1.12 * Math.PI + s.light * 0.2, 1.52 * Math.PI + s.light * 0.2); ctx.lineWidth = 2.4; ctx.strokeStyle = \"#ffffff\"; ctx.stroke();\n      ctx.beginPath(); ctx.ellipse(CX, TOP, RT - 0.8, RT * ec(TOP) - 0.2, 0, 0.2 * Math.PI, 0.44 * Math.PI); ctx.lineWidth = 2; ctx.strokeStyle = \"rgba(255,255,255,0.95)\"; ctx.stroke();\n\n      // The glass dropper the ink comes from.\n      const x = s.pip, tube = (w0: number, w1: number) => {\n        ctx.beginPath(); ctx.moveTo(x - w0, -8); ctx.lineTo(x - w0, 46); ctx.bezierCurveTo(x - w0, 66, x - w1, 70, x - w1, TIP); ctx.lineTo(x + w1, TIP);\n        ctx.bezierCurveTo(x + w1, 70, x + w0, 66, x + w0, 46); ctx.lineTo(x + w0, -8); ctx.closePath();\n      };\n      tube(10.5, 3.2); ctx.fillStyle = \"rgba(236,243,248,0.7)\"; ctx.fill();\n      ctx.save(); tube(8, 1.9); ctx.clip();\n      g = ctx.createLinearGradient(x - 7, 0, x + 7, 0);\n      g.addColorStop(0, mix(INK, \"#000000\", 0.45)); g.addColorStop(0.3, mix(INK, \"#ffffff\", 0.12)); g.addColorStop(1, mix(INK, \"#000000\", 0.5));\n      ctx.fillStyle = g; ctx.fillRect(x - 11, 14 + s.landed * 5 * live, 22, TIP);\n      ctx.restore();\n      tube(10.5, 3.2); ctx.lineWidth = 1.1; ctx.strokeStyle = \"rgba(56,74,96,0.6)\"; ctx.stroke();\n      g = ctx.createLinearGradient(0, -8, 0, TIP);\n      g.addColorStop(0, \"rgba(255,255,255,0.9)\"); g.addColorStop(0.55, \"rgba(255,255,255,0.85)\"); g.addColorStop(1, \"rgba(255,255,255,0)\");\n      ctx.fillStyle = g; ctx.fillRect(x - 7.6, -8, 2.6, 60); ctx.fillStyle = \"rgba(255,255,255,0.4)\"; ctx.fillRect(x + 5.8, -8, 1.3, 56);\n    };\n\n    let lastPct = -1;\n    const say = () => { const p = Math.round(s.shown * (1 - s.clear) * 100); if (p !== lastPct) { lastPct = p; setPct(p); } };\n    const release = () => { if (!s.drop.on && s.landed < STEPS && !s.clear) { s.drop.on = 1; s.drop.t = 0; s.drop.x = CX + xs[s.landed % xs.length]; return true; } return false; };\n    const tick = (dt: number) => {\n      s.t += dt;\n      const d = s.drop, goal = CX + xs[s.landed % xs.length];\n      s.pip += (goal - s.pip) * Math.min(1, dt * 7);\n      if (d.on === 1) { d.t += dt; d.x = s.pip; d.y = TIP + 3 + 5.4 * clamp(d.t / 0.42); if (d.t > 0.5 && Math.abs(goal - s.pip) < 1.5) { d.on = 2; d.v = 40; } }\n      else if (d.on === 2) { d.v += 2300 * dt; d.y += d.v * dt; if (d.y > yS - 2) { d.on = 0; land(d.x); s.next = s.t + EVERY; } }\n      step(dt);\n      for (const r of s.rip) r.t += dt;\n      s.rip = s.rip.filter((r) => r.t < 1.6);\n      const want = VALUE === null ? s.landed / STEPS : clamp(VALUE);\n      s.shown += (want - s.shown) * Math.min(1, dt * 0.9);\n      if (Math.abs(want - s.shown) < 0.004) s.shown = want;\n      if (VALUE !== null) { if (s.landed < Math.round(clamp(VALUE) * STEPS)) release(); }\n      else if (s.clear) {\n        s.clear = Math.min(1, s.clear + dt / 1.5);\n        if (s.clear >= 1) { count = 0; pairs = []; s.landed = 0; s.shown = 0; s.clear = 0; s.next = s.t + 0.5; }\n      } else if (s.landed >= STEPS) { s.held += dt; if (s.held > 4.2) { s.held = 0; s.clear = 0.001; } }\n      else if (s.t > s.next) release();\n      s.mvx *= Math.exp(-dt * 5); s.mvy *= Math.exp(-dt * 5);\n      s.light += (s.lightTo - s.light) * Math.min(1, dt * 5);\n    };\n\n    // Start part of the way through, so the first thing anyone sees is ink already in bloom.\n    const warm = (drops: number, gap: number, tail: number) => {\n      for (let i = 0; i < drops; i++) { land(CX + xs[i % xs.length]); for (let j = 0; j < gap * 30; j++) { s.t += 1 / 30; step(1 / 30); } }\n      for (let j = 0; j < tail * 30; j++) { s.t += 1 / 30; step(1 / 30); }\n      s.rip = []; s.shown = s.landed / STEPS; s.pip = CX + xs[s.landed % xs.length];\n    };\n    if (reduce) warm(VALUE === null ? STEPS : Math.round(clamp(VALUE) * STEPS), 1.6, 3);\n    else if (VALUE === null) { warm(1, 2.4, 0); warm(1, 1.5, 0); s.next = s.t + 0.15; }\n\n    let raf = 0, last = 0, seen = true;\n    const frame = (now: number) => {\n      raf = 0;\n      if (!last) last = now;\n      const dt = Math.min(0.04, (now - last) / 1000); last = now;\n      tick(dt); say(); draw();\n      if (seen && !document.hidden) raf = requestAnimationFrame(frame);\n    };\n    const wake = () => { if (reduce) { say(); draw(); } else if (!raf) { last = 0; raf = requestAnimationFrame(frame); } };\n    api.current = {\n      add: () => {\n        if (VALUE !== null) return;\n        if (reduce) { // no animation: each press shows the next still\n          if (s.landed >= STEPS) { count = 0; pairs = []; s.landed = 0; s.shown = 0; } else warm(1, 2, 0);\n          say(); draw(); return;\n        }\n        if (s.landed >= STEPS) { if (!s.clear) { s.held = 0; s.clear = 0.001; } } else if (release()) s.next = s.t + EVERY + 1;\n        wake();\n      },\n    };\n    fit(); wake();\n\n    const host = cv.parentElement;\n    let lt = 0;\n    const onMove = (e: PointerEvent) => {\n      const b = cv.getBoundingClientRect(), x = ((e.clientX - b.left) / b.width) * W, y = ((e.clientY - b.top) / b.height) * H, now = performance.now();\n      s.lightTo = clamp((x / W) * 2 - 1, -1, 1);\n      if (s.min && now - lt < 120) { const dt = Math.max(8, now - lt) / 1000; s.mvx = clamp((x - s.mx) / dt, -420, 420); s.mvy = clamp((y - s.my) / dt, -420, 420); }\n      s.mx = x; s.my = y; lt = now; s.min = y > yS && y < yF + 10 && Math.abs(x - CX) < RT;\n    };\n    const onLeave = () => { s.lightTo = 0; s.min = false; };\n    host?.addEventListener(\"pointermove\", onMove); host?.addEventListener(\"pointerleave\", onLeave);\n    const ro = new ResizeObserver(() => { fit(); if (reduce) draw(); });\n    ro.observe(cv);\n    const io = new IntersectionObserver(([entry]) => { seen = entry.isIntersecting; if (seen) wake(); });\n    io.observe(cv);\n    const onVis = () => { if (!document.hidden) wake(); };\n    document.addEventListener(\"visibilitychange\", onVis);\n    return () => {\n      cancelAnimationFrame(raf); api.current = null;\n      host?.removeEventListener(\"pointermove\", onMove); host?.removeEventListener(\"pointerleave\", onLeave);\n      ro.disconnect(); io.disconnect(); document.removeEventListener(\"visibilitychange\", onVis);\n    };\n  }, []);\n\n  const done = pct >= 100;\n  return (\n    <div className=\"flex min-h-[640px] w-full flex-col items-center justify-center bg-[#e3e9ee] bg-[radial-gradient(120%_85%_at_50%_34%,#fbfcfd_0%,#e6ecf1_50%,#c6d0d9_100%)] px-4 py-8 sm:min-h-[760px]\">\n      <div className=\"relative w-full\" style={{ maxWidth: 640, aspectRatio: `${W} / ${H}` }}>\n        <canvas ref={canvas} aria-hidden=\"true\" className=\"absolute inset-0 h-full w-full\" />\n        <button\n          type=\"button\"\n          aria-label={done ? \"Start again with clean water\" : \"Add a drop of ink\"}\n          onClick={() => api.current?.add()}\n          className=\"absolute left-1/2 top-[25%] h-[63%] w-[44%] -translate-x-1/2 cursor-pointer touch-manipulation rounded-[28px] outline-none focus-visible:ring-2 focus-visible:ring-slate-900/70 focus-visible:ring-offset-4 focus-visible:ring-offset-transparent\"\n        />\n      </div>\n      <div\n        role=\"progressbar\"\n        aria-label={TASK}\n        aria-valuemin={0}\n        aria-valuemax={100}\n        aria-valuenow={pct}\n        className=\"flex items-baseline gap-3 font-mono text-[11px] uppercase tracking-[0.2em] text-slate-600\"\n      >\n        <span className=\"text-slate-900\">{done ? DONE : TASK}</span>\n        <span aria-hidden=\"true\" className=\"text-slate-400\">/</span>\n        <span className=\"w-[4ch] text-right tabular-nums text-slate-900\">{pct}%</span>\n      </div>\n    </div>\n  );\n}\n"}]}
