{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"brass-doorbell-push-notification-with-walnut-door-chime-tubes-that-swing-shimmer-and-knock-together","type":"registry:component","title":"Brass Doorbell Push Notification with Walnut Door Chime Tubes That Swing, Shimmer and Knock Together","description":"Press an ivory bell push and brass chime tubes are struck in turn, swing and collide. A canvas notification piece with free React code and an HTML version.","dependencies":[],"files":[{"path":"components/we-inc/brass-doorbell-push-notification-with-walnut-door-chime-tubes-that-swing-shimmer-and-knock-together.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\nimport type { MouseEvent as ReactMouseEvent } from \"react\";\n\n// Everything a visitor is likely to change sits here.\nconst DOOR = \"Front door\"; // the name of the bell, read out and shown in the caption\n// What each ring reports, in order. After the last one it starts again.\nconst callers = [\n  \"Parcel from the bookshop\",\n  \"Neighbour returning a ladder\",\n  \"Window cleaner, back gate is open\",\n  \"Flowers for number nine\",\n];\n// The tubes, left to right. `length` is in drawing units, `note` is only used if SOUND is on.\nconst chimes = [\n  { length: 242, note: 392 },\n  { length: 200, note: 494 },\n  { length: 160, note: 587 },\n];\nconst ORDER = [2, 1, 0]; // which tube the hammer hits first, second, third\nconst BEAT = 0.36; // seconds between hammer strokes\nconst KICK = 0.3; // how hard each stroke sets a tube swinging\nconst SOUND = false; // silent as shipped. Set to true to hear three sine notes on each press.\nconst SELF_RING = 5.4; // seconds between rings while nobody is touching it, 0 to switch that off\n\nconst W = 340, H = 400; // drawing units: the canvas is scaled to whatever box it is given\nconst HANG_Y = 92, FIRST_X = 76, SPACING = 46, TUBE = 17, CORD = 19; // where the tubes hang\nconst PX = 276, PY = 236, PUSH = 1.2; // the bell push: where it is and how large\nconst clamp = (v: number, lo: number, hi: number) => Math.max(lo, Math.min(hi, v));\n\nexport default function BrassDoorbellWithChimeTubes() {\n  const canvas = useRef<HTMLCanvasElement>(null);\n  const stage = useRef<HTMLDivElement>(null);\n  const [rings, setRings] = useState(0);\n  const api = useRef<{ ring: () => void; press: (down: boolean) => void } | null>(null);\n\n  useEffect(() => {\n    const cv = canvas.current, box = stage.current;\n    if (!cv || !box) return;\n    const ctx = cv.getContext(\"2d\");\n    if (!ctx) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const k = 1.6 * Math.min(2, window.devicePixelRatio || 1); // sharp at its largest shown size\n    cv.width = W * k; cv.height = H * k;\n\n    // Brass runs from a brown-black shadow through ochre to a pale straw highlight.\n    const ramp: [number, number, number, number][] = [[0, 30, 20, 6], [60, 96, 66, 18], [120, 162, 118, 38], [180, 216, 172, 76], [226, 246, 218, 138], [255, 255, 250, 226]];\n    const brass = (v: number) => {\n      const c = clamp(v, 0, 255);\n      let i = 0;\n      while (i < ramp.length - 2 && c > ramp[i + 1][0]) i++;\n      const p = ramp[i], q = ramp[i + 1], t = (c - p[0]) / (q[0] - p[0]);\n      return `rgb(${(p[1] + (q[1] - p[1]) * t) | 0},${(p[2] + (q[2] - p[2]) * t) | 0},${(p[3] + (q[3] - p[3]) * t) | 0})`;\n    };\n    const lightAt = -2.2; // the room light comes from the upper left\n\n    // The walnut cover is painted once: body colour, grain, a rounded front and three sound slots.\n    const BOX = { x: FIRST_X - 35, y: 36, w: SPACING * (chimes.length - 1) + 70, h: 58, r: 11 };\n    const wood = document.createElement(\"canvas\");\n    wood.width = cv.width; wood.height = Math.ceil((BOX.y + BOX.h + 10) * k);\n    const wx = wood.getContext(\"2d\");\n    if (wx) {\n      wx.scale(k, k);\n      // The underside, which you see from below, then the front.\n      wx.beginPath(); wx.roundRect(BOX.x + 1.5, BOX.y + 6, BOX.w - 3, BOX.h, BOX.r); wx.fillStyle = \"#281306\"; wx.fill();\n      wx.beginPath(); wx.roundRect(BOX.x, BOX.y, BOX.w, BOX.h, BOX.r); wx.save(); wx.clip();\n      const body = wx.createLinearGradient(0, BOX.y, 0, BOX.y + BOX.h);\n      body.addColorStop(0, \"#9a6238\"); body.addColorStop(0.2, \"#7f4c28\"); body.addColorStop(0.7, \"#69391c\"); body.addColorStop(1, \"#4a2610\");\n      wx.fillStyle = body; wx.fillRect(BOX.x, BOX.y, BOX.w, BOX.h);\n      let seed = 23;\n      const rand = () => { seed = (seed * 16807) % 2147483647; return seed / 2147483647; };\n      for (let i = 0; i < 70; i++) {\n        const y = BOX.y + rand() * BOX.h, amp = 0.6 + rand() * 2.2, ph = rand() * 6, dark = rand() > 0.3;\n        wx.beginPath();\n        for (let x = BOX.x; x <= BOX.x + BOX.w; x += 4) { const yy = y + Math.sin(x * 0.035 + ph) * amp + Math.sin(x * 0.011 + ph * 2) * amp * 1.6; if (x === BOX.x) wx.moveTo(x, yy); else wx.lineTo(x, yy); }\n        wx.lineWidth = 0.35 + rand() * 0.8; wx.strokeStyle = dark ? `rgba(38,16,4,${0.1 + rand() * 0.3})` : `rgba(226,160,104,${0.05 + rand() * 0.14})`; wx.stroke();\n      }\n      // The front is bowed: darker towards both ends, with a soft band of light along the top.\n      const bow = wx.createLinearGradient(BOX.x, 0, BOX.x + BOX.w, 0);\n      bow.addColorStop(0, \"rgba(20,8,0,0.5)\"); bow.addColorStop(0.16, \"rgba(20,8,0,0)\"); bow.addColorStop(0.3, \"rgba(255,214,170,0.14)\"); bow.addColorStop(0.5, \"rgba(20,8,0,0)\"); bow.addColorStop(0.86, \"rgba(20,8,0,0.08)\"); bow.addColorStop(1, \"rgba(20,8,0,0.6)\");\n      wx.fillStyle = bow; wx.fillRect(BOX.x, BOX.y, BOX.w, BOX.h);\n      const gloss = wx.createLinearGradient(0, BOX.y, 0, BOX.y + BOX.h);\n      gloss.addColorStop(0, \"rgba(255,226,190,0.5)\"); gloss.addColorStop(0.07, \"rgba(255,226,190,0.2)\"); gloss.addColorStop(0.22, \"rgba(255,226,190,0)\"); gloss.addColorStop(0.9, \"rgba(10,4,0,0)\"); gloss.addColorStop(1, \"rgba(10,4,0,0.5)\");\n      wx.fillStyle = gloss; wx.fillRect(BOX.x, BOX.y, BOX.w, BOX.h);\n      const mid = BOX.x + BOX.w / 2;\n      for (let i = 0; i < 3; i++) {\n        const y = BOX.y + 19 + i * 8.5;\n        wx.beginPath(); wx.roundRect(mid - 34, y, 68, 3.6, 1.8); wx.fillStyle = \"#170a02\"; wx.fill();\n        wx.beginPath(); wx.roundRect(mid - 34, y + 3.4, 68, 1, 0.5); wx.fillStyle = \"rgba(255,210,160,0.34)\"; wx.fill();\n      }\n      // Two brass bands let into the front.\n      for (const bx of [BOX.x + 15, BOX.x + BOX.w - 19]) {\n        const band = wx.createLinearGradient(0, BOX.y, 0, BOX.y + BOX.h);\n        band.addColorStop(0, \"#fff3c4\"); band.addColorStop(0.12, \"#e2bc62\"); band.addColorStop(0.6, \"#a87c26\"); band.addColorStop(1, \"#5a3d0c\");\n        wx.fillStyle = \"rgba(20,8,0,0.7)\"; wx.fillRect(bx - 0.6, BOX.y, 5.2, BOX.h);\n        wx.fillStyle = band; wx.fillRect(bx, BOX.y, 4, BOX.h);\n        wx.fillStyle = \"rgba(255,250,220,0.55)\"; wx.fillRect(bx + 0.7, BOX.y, 0.8, BOX.h);\n      }\n      wx.restore();\n      wx.lineWidth = 0.8; wx.strokeStyle = \"rgba(30,12,2,0.7)\"; wx.beginPath(); wx.roundRect(BOX.x, BOX.y, BOX.w, BOX.h, BOX.r); wx.stroke();\n    }\n\n    type Tube = { x: number; len: number; a: number; w: number; hum: number; freq: number };\n    const tubes: Tube[] = chimes.map((c, i) => ({ x: FIRST_X + i * SPACING, len: c.length, a: 0, w: 0, hum: 0, freq: Math.sqrt(1500 / (c.length * 0.66 + CORD)) }));\n    const s = { press: 0, held: false, t: 0 };\n    let queue: { at: number; i: number }[] = [];\n    let audio: AudioContext | null = null;\n\n    // The chime hangs above eye level, so each tube shows a curved top edge and its open lower end.\n    const RY = 3.1;\n    const tubeShape = (t: Tube) => {\n      ctx.beginPath(); ctx.ellipse(0, CORD, TUBE / 2, RY, 0, Math.PI, Math.PI * 2);\n      ctx.lineTo(TUBE / 2, CORD + t.len); ctx.ellipse(0, CORD + t.len, TUBE / 2, RY, 0, 0, Math.PI); ctx.closePath();\n    };\n    const place = (t: Tube, lift = 0) => { ctx.setTransform(k, 0, 0, k, 0, -lift * k); ctx.translate(t.x, HANG_Y); ctx.rotate(-t.a); };\n\n    const draw = () => {\n      ctx.setTransform(k, 0, 0, k, 0, 0);\n      ctx.clearRect(0, 0, W, H);\n\n      // Shadows on the wall first: the tubes hang well clear of it, so theirs fall far to the side.\n      for (const t of tubes) {\n        place(t, 2000);\n        ctx.save(); ctx.shadowColor = \"rgba(34,48,60,0.34)\"; ctx.shadowBlur = 9 * k; ctx.shadowOffsetX = 17 * k; ctx.shadowOffsetY = (12 + 2000) * k;\n        tubeShape(t); ctx.fillStyle = \"#000\"; ctx.fill(); ctx.restore();\n      }\n      ctx.setTransform(k, 0, 0, k, 0, -2000 * k);\n      ctx.save(); ctx.shadowColor = \"rgba(30,44,58,0.42)\"; ctx.shadowBlur = 16 * k; ctx.shadowOffsetX = 9 * k; ctx.shadowOffsetY = (13 + 2000) * k;\n      ctx.beginPath(); ctx.roundRect(BOX.x, BOX.y, BOX.w, BOX.h, BOX.r); ctx.fillStyle = \"#000\"; ctx.fill(); ctx.restore();\n      ctx.save(); ctx.shadowColor = \"rgba(30,44,58,0.5)\"; ctx.shadowBlur = 10 * k; ctx.shadowOffsetX = 5 * k; ctx.shadowOffsetY = (8 + 2000) * k;\n      ctx.beginPath(); ctx.arc(PX, PY, 28 * PUSH, 0, Math.PI * 2); ctx.fillStyle = \"#000\"; ctx.fill(); ctx.restore();\n\n      // The tubes. Each is a polished cylinder whose reflections slide a little as it swings and blur while it rings.\n      for (const t of tubes) {\n        place(t);\n        ctx.lineCap = \"round\"; ctx.lineWidth = 1.5; ctx.strokeStyle = \"#2a2018\"; ctx.beginPath(); ctx.moveTo(0, -2); ctx.lineTo(0, CORD + 9); ctx.stroke();\n        const shake = t.hum * Math.sin(s.t * 96 + t.x) * 0.9;\n        const slide = clamp(t.a * 1.4, -0.09, 0.09);\n        const coat = (dx: number, alpha: number) => {\n          ctx.save(); ctx.globalAlpha = alpha; ctx.translate(dx, 0);\n          const g = ctx.createLinearGradient(-TUBE / 2, 0, TUBE / 2, 0);\n          const at = (p: number) => clamp(p + slide, 0.01, 0.99);\n          g.addColorStop(0, brass(18)); g.addColorStop(at(0.07), brass(84)); g.addColorStop(at(0.14), brass(168)); g.addColorStop(at(0.175), brass(255)); g.addColorStop(at(0.25), brass(250)); g.addColorStop(at(0.285), brass(176));\n          g.addColorStop(at(0.42), brass(118)); g.addColorStop(at(0.5), brass(52)); g.addColorStop(at(0.67), brass(40)); g.addColorStop(at(0.72), brass(128)); g.addColorStop(at(0.8), brass(206)); g.addColorStop(at(0.89), brass(236)); g.addColorStop(at(0.945), brass(120)); g.addColorStop(1, brass(18));\n          tubeShape(t); ctx.fillStyle = g; ctx.fill();\n          ctx.restore();\n        };\n        coat(0, 1);\n        if (t.hum > 0.02) { coat(shake, 0.4); coat(-shake, 0.4); }\n        ctx.save(); tubeShape(t); ctx.clip();\n        // Shade under the cover, a paler stretch lower down where the tube picks up the room, and a hole for the cord.\n        const fall = ctx.createLinearGradient(0, CORD, 0, CORD + t.len);\n        fall.addColorStop(0, \"rgba(20,10,0,0.62)\"); fall.addColorStop(Math.min(0.3, 34 / t.len), \"rgba(20,10,0,0)\"); fall.addColorStop(0.62, \"rgba(255,250,230,0)\"); fall.addColorStop(0.8, \"rgba(255,250,230,0.16)\"); fall.addColorStop(1, \"rgba(255,250,230,0.02)\");\n        ctx.fillStyle = fall; ctx.fillRect(-TUBE, CORD - RY, TUBE * 2, t.len + RY);\n        ctx.restore();\n        // The open end: you can see a little way up the inside.\n        const bore = ctx.createLinearGradient(0, CORD + t.len - RY, 0, CORD + t.len + RY);\n        bore.addColorStop(0, brass(150)); bore.addColorStop(0.45, brass(46)); bore.addColorStop(1, brass(6));\n        ctx.beginPath(); ctx.ellipse(0, CORD + t.len, TUBE / 2 - 0.5, RY - 0.3, 0, 0, Math.PI * 2); ctx.fillStyle = bore; ctx.fill();\n        ctx.lineWidth = 1.1; ctx.strokeStyle = brass(232); ctx.stroke();\n        ctx.lineWidth = 0.9; ctx.strokeStyle = \"rgba(255,250,226,0.9)\"; ctx.beginPath(); ctx.ellipse(0, CORD + t.len, TUBE / 2 - 0.5, RY - 0.3, 0, 0.5, 2.1); ctx.stroke();\n        ctx.beginPath(); ctx.ellipse(0, CORD + 9.4, 2.1, 2.5, 0, 0, Math.PI * 2); ctx.fillStyle = \"#120a02\"; ctx.fill();\n        ctx.lineWidth = 0.6; ctx.strokeStyle = \"rgba(255,244,210,0.6)\"; ctx.beginPath(); ctx.ellipse(0, CORD + 9.4, 2.7, 3.1, 0, 0.3, 2.2); ctx.stroke();\n        ctx.lineWidth = 0.5; ctx.strokeStyle = \"rgba(24,12,0,0.55)\"; ctx.beginPath(); ctx.ellipse(0, CORD, TUBE / 2, RY, 0, Math.PI, Math.PI * 2); ctx.moveTo(-TUBE / 2, CORD); ctx.lineTo(-TUBE / 2, CORD + t.len); ctx.moveTo(TUBE / 2, CORD); ctx.lineTo(TUBE / 2, CORD + t.len); ctx.stroke();\n      }\n\n      // The cover goes over the cords.\n      ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.drawImage(wood, 0, 0); ctx.setTransform(k, 0, 0, k, 0, 0);\n\n      // The bell push: a rolled brass rim, a polished dished ring with PRESS engraved in it, and an ivory button.\n      ctx.save(); ctx.translate(PX, PY); ctx.scale(PUSH, PUSH); ctx.translate(-PX, -PY);\n      const rimTone = (a: number) => brass(34 + 220 * Math.pow(Math.max(0, Math.cos(a - lightAt)), 1.3) + 60 * Math.pow(Math.max(0, Math.cos(a - lightAt - Math.PI)), 3));\n      const sweep = (r: number, width: number, flip: boolean) => {\n        ctx.lineWidth = width;\n        if (typeof ctx.createConicGradient === \"function\") {\n          const g = ctx.createConicGradient(0, PX, PY);\n          for (let i = 0; i <= 48; i++) g.addColorStop(i / 48, rimTone((i / 48) * Math.PI * 2 + (flip ? Math.PI : 0)));\n          ctx.strokeStyle = g;\n        } else ctx.strokeStyle = brass(150);\n        ctx.beginPath(); ctx.arc(PX, PY, r, 0, Math.PI * 2); ctx.stroke();\n      };\n      ctx.beginPath(); ctx.arc(PX, PY, 28, 0, Math.PI * 2); ctx.fillStyle = brass(40); ctx.fill();\n      sweep(25.6, 4.8, false);\n      const dishFill = ctx.createLinearGradient(PX - 20, PY - 20, PX + 20, PY + 20);\n      dishFill.addColorStop(0, brass(70)); dishFill.addColorStop(0.35, brass(150)); dishFill.addColorStop(0.62, brass(236)); dishFill.addColorStop(0.8, brass(250)); dishFill.addColorStop(1, brass(160));\n      ctx.beginPath(); ctx.arc(PX, PY, 23.2, 0, Math.PI * 2); ctx.fillStyle = dishFill; ctx.fill();\n      ctx.lineWidth = 0.7; ctx.strokeStyle = \"rgba(24,12,0,0.6)\"; ctx.stroke();\n      ctx.save(); ctx.translate(PX, PY); ctx.font = '700 5.4px ui-sans-serif, system-ui, -apple-system, \"Helvetica Neue\", Arial, sans-serif'; ctx.textAlign = \"center\"; ctx.textBaseline = \"middle\";\n      \"PRESS\".split(\"\").forEach((ch, i) => {\n        ctx.save(); ctx.rotate((i - 2) * 0.27);\n        ctx.fillStyle = \"rgba(255,246,214,0.7)\"; ctx.fillText(ch, 0.3, -18.2);\n        ctx.fillStyle = \"rgba(36,20,2,0.9)\"; ctx.fillText(ch, 0, -18.6);\n        ctx.restore();\n      });\n      ctx.restore();\n      sweep(14.4, 1.6, true);\n      ctx.beginPath(); ctx.arc(PX, PY, 13.6, 0, Math.PI * 2); ctx.fillStyle = \"#0e0802\"; ctx.fill();\n      // The button sinks and darkens as it is pushed.\n      const p = s.press, br = 12.2 - p * 0.9;\n      const ivory = ctx.createRadialGradient(PX - 4 + p * 2, PY - 5 + p * 3, 0.5, PX, PY, br);\n      ivory.addColorStop(0, p > 0.5 ? \"#f4ecda\" : \"#fffdf6\"); ivory.addColorStop(0.5, p > 0.5 ? \"#e2d7bf\" : \"#f1e8d4\"); ivory.addColorStop(0.9, \"#cabd9f\"); ivory.addColorStop(1, \"#8f8266\");\n      ctx.save(); ctx.beginPath(); ctx.arc(PX, PY, 13.6, 0, Math.PI * 2); ctx.clip();\n      ctx.shadowColor = \"rgba(0,0,0,0.8)\"; ctx.shadowBlur = (4 - 3 * p) * k; ctx.shadowOffsetX = (1.4 - p) * k; ctx.shadowOffsetY = (2.4 - 1.8 * p) * k;\n      ctx.beginPath(); ctx.arc(PX, PY, br, 0, Math.PI * 2); ctx.fillStyle = ivory; ctx.fill(); ctx.restore();\n      ctx.beginPath(); ctx.ellipse(PX - 3.6, PY - 4.6, 4.4, 2.6, -0.7, 0, Math.PI * 2); ctx.fillStyle = `rgba(255,255,255,${0.75 - 0.4 * p})`; ctx.fill();\n      ctx.fillStyle = `rgba(10,6,0,${0.2 * p})`; ctx.beginPath(); ctx.arc(PX, PY, br, 0, Math.PI * 2); ctx.fill();\n      ctx.restore();\n    };\n\n    const sing = (i: number) => {\n      if (!SOUND || !audio) return;\n      const now = audio.currentTime, gain = audio.createGain();\n      gain.gain.setValueAtTime(0.16, now); gain.gain.exponentialRampToValueAtTime(0.0005, now + 2.2); gain.connect(audio.destination);\n      for (const [mult, level] of [[1, 1], [2.76, 0.3]]) {\n        const osc = audio.createOscillator(), g = audio.createGain();\n        osc.frequency.value = chimes[i].note * mult; g.gain.value = level; osc.connect(g); g.connect(gain); osc.start(now); osc.stop(now + 2.3);\n      }\n    };\n    const strike = (i: number) => { const t = tubes[i]; t.w += KICK; t.hum = 1; sing(i); };\n\n    let raf = 0, last = 0, seen = true, touched = -1e9, t0 = 0, nextRing = 250;\n    const frame = (now: number) => {\n      raf = 0;\n      if (!t0) { t0 = now; last = now; }\n      const dt = Math.min(0.033, (now - last) / 1000); last = now;\n      s.t = (now - t0) / 1000;\n      queue = queue.filter((q) => { if (q.at > s.t) return true; strike(q.i); return false; });\n      if (SELF_RING > 0 && now - touched > 7000 && (now - t0) > nextRing) { ORDER.forEach((i, n) => queue.push({ at: s.t + n * BEAT, i })); nextRing = now - t0 + SELF_RING * 1000; }\n      for (let step = 0; step < 2; step++) {\n        const h = dt / 2;\n        for (const t of tubes) { t.w += (-t.freq * t.freq * Math.sin(t.a) - 0.42 * t.w) * h; t.a += t.w * h; }\n        // Neighbours that meet trade most of their speed and both ring a little.\n        for (let i = 0; i < tubes.length - 1; i++) {\n          const a = tubes[i], b = tubes[i + 1], reach = CORD + Math.min(a.len, b.len);\n          const gap = b.x + Math.sin(b.a) * reach - (a.x + Math.sin(a.a) * reach) - TUBE;\n          if (gap >= 0) continue;\n          const va = a.w * reach, vb = b.w * reach;\n          a.a += gap / reach / 2; b.a -= gap / reach / 2;\n          if (va - vb > 0) { a.w = (0.2 * va + 0.8 * vb) / reach; b.w = (0.8 * va + 0.2 * vb) / reach; const hit = clamp((va - vb) / 40, 0, 0.7); a.hum = Math.max(a.hum, hit); b.hum = Math.max(b.hum, hit); }\n        }\n      }\n      for (const t of tubes) t.hum *= Math.exp(-dt * 1.5);\n      s.press += ((s.held ? 1 : 0) - s.press) * Math.min(1, dt * (s.held ? 34 : 16));\n      draw();\n      if (seen && !document.hidden) raf = requestAnimationFrame(frame);\n    };\n    const wake = () => { if (!raf && !reduce) { last = performance.now(); raf = requestAnimationFrame(frame); } };\n\n    api.current = {\n      ring: () => {\n        touched = performance.now();\n        if (SOUND && !audio) { try { audio = new AudioContext(); } catch { audio = null; } }\n        if (reduce) { draw(); return; }\n        ORDER.forEach((i, n) => queue.push({ at: s.t + n * BEAT, i })); wake();\n      },\n      press: (down) => { s.held = down; if (reduce) { s.press = down ? 1 : 0; draw(); } else wake(); },\n    };\n    if (reduce) draw(); else wake();\n\n    // A pointer that sweeps across a tube pushes it.\n    let px = -1, py = -1, pt = 0;\n    const onMove = (e: PointerEvent) => {\n      const b = box.getBoundingClientRect(), x = ((e.clientX - b.left) / b.width) * W, y = ((e.clientY - b.top) / b.height) * H, now = performance.now();\n      if (px >= 0 && now - pt < 120 && !reduce) {\n        const speed = ((x - px) / Math.max(8, now - pt)) * 1000;\n        for (const t of tubes) {\n          const down = y - HANG_Y;\n          if (down < CORD || down > CORD + t.len + 4) continue;\n          const at = t.x + Math.sin(t.a) * down;\n          if ((px - at) * (x - at) <= 0 && Math.abs(speed) > 20) { t.w += clamp(speed / down, -0.7, 0.7) * 0.45; t.hum = Math.max(t.hum, 0.5); touched = now; wake(); }\n        }\n      }\n      px = x; py = y; pt = now;\n    };\n    box.addEventListener(\"pointermove\", onMove);\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      box.removeEventListener(\"pointermove\", onMove);\n      io.disconnect(); document.removeEventListener(\"visibilitychange\", onVis);\n      if (audio) void audio.close();\n    };\n  }, []);\n\n  const ring = () => { setRings((n) => n + 1); api.current?.ring(); };\n  // A click with no pointer behind it comes from the keyboard or a screen reader: give it a short press of its own.\n  const onClick = (e: ReactMouseEvent) => {\n    if (e.detail !== 0) return;\n    api.current?.press(true); window.setTimeout(() => api.current?.press(false), 150); ring();\n  };\n\n  return (\n    <div className=\"flex min-h-[640px] w-full flex-col items-center justify-center overflow-hidden bg-[#bac8d2] bg-[radial-gradient(110%_90%_at_26%_10%,#d3dee6_0%,#bac8d2_50%,#a3b3bf_100%)] px-0 py-10 sm:min-h-[720px]\">\n      <div ref={stage} className=\"relative h-[400px] w-[340px] sm:h-[640px] sm:w-[544px]\">\n        <canvas ref={canvas} aria-hidden=\"true\" className=\"absolute inset-0 h-full w-full\" />\n        <button\n          type=\"button\"\n          aria-label={`Ring the ${DOOR.toLowerCase()} bell`}\n          onPointerDown={(e) => { e.currentTarget.setPointerCapture(e.pointerId); api.current?.press(true); ring(); }}\n          onPointerUp={() => api.current?.press(false)}\n          onPointerCancel={() => api.current?.press(false)}\n          onClick={onClick}\n          style={{ left: `${((PX - 31 * PUSH) / W) * 100}%`, top: `${((PY - 31 * PUSH) / H) * 100}%`, width: `${((62 * PUSH) / W) * 100}%`, height: `${((62 * PUSH) / H) * 100}%` }}\n          className=\"absolute cursor-pointer touch-manipulation rounded-full outline-none focus-visible:ring-2 focus-visible:ring-slate-900 focus-visible:ring-offset-2 focus-visible:ring-offset-[#bac8d2]\"\n        />\n      </div>\n      <p aria-live=\"polite\" className=\"-mt-3 min-h-[20px] px-4 text-center font-mono text-[11px] uppercase leading-5 tracking-[0.16em] text-slate-700 sm:-mt-6\">\n        <span className=\"text-slate-950\">{DOOR}</span>\n        <span className=\"mx-2 text-slate-500\">/</span>\n        {rings === 0 ? \"Nobody yet\" : callers[(rings - 1) % callers.length]}\n      </p>\n    </div>\n  );\n}\n"}]}
