{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"chrome-stomp-footswitch-toggle-with-jewel-lamp-on-a-powder-coated-pedal","type":"registry:component","title":"Chrome Stomp Footswitch Toggle with Jewel Lamp on a Powder-Coated Pedal","description":"On and off toggle drawn as a guitar pedal: press the chrome footswitch and an amber jewel lamp lights above it. Copy the React code or HTML version free.","dependencies":[],"files":[{"path":"components/we-inc/chrome-stomp-footswitch-toggle-with-jewel-lamp-on-a-powder-coated-pedal.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\n\n// What the switch controls, and the words printed on the box.\nconst effect = { name: \"Tremolo\", on: \"Engaged\", off: \"Bypassed\", print: \"TREMOLO\", foot: \"ON / BYPASS\" };\nconst BOX = [214, 68, 40]; // powder coat, as red, green, blue\nconst LAMP = [255, 176, 32]; // the jewel when lit\nconst W = 320, H = 470;\n\nexport default function ChromeStompFootswitchToggle() {\n  const canvas = useRef<HTMLCanvasElement>(null);\n  const [on, setOn] = useState(true);\n  const onRef = useRef(true);\n  const api = useRef<{ press: (down: boolean) => void; set: (v: boolean, pulse: boolean) => 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 dpr = Math.min(2, window.devicePixelRatio || 1) * 1.2;\n    cv.width = W * dpr; cv.height = H * dpr;\n    const BX = 44, BY = 26, BW = 232, BH = 376, BR = 26, DEPTH = 13;\n    const JX = 160, JY = 136, SXc = 160, SYc = 292;\n    const hasConic = typeof ctx.createConicGradient === \"function\";\n    const box = (k: number, a = 1) => `rgba(${Math.min(255, BOX[0] * k) | 0},${Math.min(255, BOX[1] * k) | 0},${Math.min(255, BOX[2] * k) | 0},${a})`;\n\n    const rr = (c: CanvasRenderingContext2D, x: number, y: number, w: number, h: number, r: number) => {\n      c.beginPath(); c.moveTo(x + r, y); c.arcTo(x + w, y, x + w, y + h, r); c.arcTo(x + w, y + h, x, y + h, r); c.arcTo(x, y + h, x, y, r); c.arcTo(x, y, x + w, y, r); c.closePath();\n    };\n    let seed = 23;\n    const rand = () => { seed = (seed * 16807) % 2147483647; return seed / 2147483647; };\n\n    // The die-cast box is painted once: side wall, top face, the orange-peel of the powder coat, rolled edges, print.\n    const still = document.createElement(\"canvas\");\n    still.width = cv.width; still.height = cv.height;\n    const sc = still.getContext(\"2d\");\n    if (sc) {\n      sc.scale(dpr, dpr);\n      // Jack sockets poke out of both sides, under the lip of the lid.\n      for (const dir of [-1, 1]) {\n        const jx = dir < 0 ? BX : BX + BW, jy = BY + 150;\n        const g = sc.createLinearGradient(0, jy - 13, 0, jy + 13);\n        g.addColorStop(0, \"#5d656c\"); g.addColorStop(0.18, \"#f5f8fa\"); g.addColorStop(0.36, \"#a3acb3\"); g.addColorStop(0.55, \"#41474d\"); g.addColorStop(0.7, box(0.55)); g.addColorStop(0.86, \"#d9dde0\"); g.addColorStop(1, \"#33383d\");\n        sc.fillStyle = g;\n        sc.save(); sc.shadowColor = \"rgba(20,26,36,0.5)\"; sc.shadowBlur = 5 * dpr; sc.shadowOffsetY = 5 * dpr;\n        sc.fillRect(dir < 0 ? jx - 7 : jx - 2, jy - 13, 9, 26); sc.restore();\n        sc.fillRect(dir < 0 ? jx - 15 : jx + 7, jy - 9, 8, 18);\n        sc.fillStyle = \"rgba(0,0,0,0.35)\"; sc.fillRect(dir < 0 ? jx - 7.6 : jx + 7, jy - 13, 0.6, 26);\n        for (let k = 0; k < 4; k++) { sc.fillStyle = \"rgba(0,0,0,0.3)\"; sc.fillRect(dir < 0 ? jx - 14 + k * 2 : jx + 8 + k * 2, jy - 9, 0.6, 18); }\n      }\n      sc.save(); sc.shadowColor = \"rgba(20,26,36,0.55)\"; sc.shadowBlur = 6 * dpr; sc.shadowOffsetY = 4 * dpr;\n      rr(sc, BX, BY + DEPTH, BW, BH, BR); sc.fillStyle = \"#000\"; sc.fill(); sc.restore();\n      const wall = sc.createLinearGradient(BX, 0, BX + BW, 0);\n      wall.addColorStop(0, box(0.42)); wall.addColorStop(0.12, box(0.66)); wall.addColorStop(0.5, box(0.56)); wall.addColorStop(0.9, box(0.44)); wall.addColorStop(1, box(0.3));\n      rr(sc, BX, BY + DEPTH, BW, BH, BR); sc.fillStyle = wall; sc.fill();\n      rr(sc, BX, BY, BW, BH, BR); sc.fillStyle = box(1); sc.fill();\n      sc.save(); rr(sc, BX, BY, BW, BH, BR); sc.clip();\n      for (let i = 0; i < 9000; i++) {\n        const v = rand(), r = 0.4 + rand() * 0.7;\n        sc.fillStyle = v > 0.5 ? `rgba(255,235,220,${(v - 0.5) * 0.2})` : `rgba(60,0,0,${(0.5 - v) * 0.26})`;\n        sc.beginPath(); sc.arc(BX + rand() * BW, BY + rand() * BH, r, 0, Math.PI * 2); sc.fill();\n      }\n      const wash = sc.createLinearGradient(BX, BY, BX + BW * 0.5, BY + BH);\n      wash.addColorStop(0, \"rgba(255,240,225,0.2)\"); wash.addColorStop(0.4, \"rgba(255,240,225,0.03)\"); wash.addColorStop(1, \"rgba(40,0,0,0.2)\");\n      sc.fillStyle = wash; sc.fillRect(BX, BY, BW, BH);\n      // Rolled edge: a few clipped strokes of falling width make a soft round-over.\n      const roll = sc.createLinearGradient(0, BY, 0, BY + BH);\n      roll.addColorStop(0, \"rgba(255,244,232,0.026)\"); roll.addColorStop(0.3, \"rgba(255,244,232,0.006)\"); roll.addColorStop(0.7, \"rgba(50,0,0,0.012)\"); roll.addColorStop(1, \"rgba(50,0,0,0.06)\");\n      for (let w = 30; w >= 1; w -= 1.5) { rr(sc, BX, BY, BW, BH, BR); sc.lineWidth = w; sc.strokeStyle = roll; sc.stroke(); }\n      rr(sc, BX + 0.5, BY + 0.5, BW - 1, BH - 1, BR - 0.5); sc.lineWidth = 1; sc.strokeStyle = \"rgba(255,236,222,0.35)\"; sc.stroke();\n      sc.restore();\n\n      // Screen print: white ink with the faintest edge under it.\n      const print = (text: string, y: number, size: number, gap: number) => {\n        sc.font = `700 ${size}px \"Helvetica Neue\", Helvetica, Arial, sans-serif`; sc.textBaseline = \"middle\"; sc.textAlign = \"left\";\n        const widths = [...text].map((ch) => sc.measureText(ch).width + gap), total = widths.reduce((a, b) => a + b, 0) - gap;\n        let x = 160 - total / 2;\n        [...text].forEach((ch, i) => { sc.fillStyle = \"rgba(70,10,0,0.35)\"; sc.fillText(ch, x, y + 0.9); sc.fillStyle = \"rgba(255,250,242,0.96)\"; sc.fillText(ch, x, y); x += widths[i]; });\n      };\n      print(effect.print, BY + 50, 19, 5.5);\n      print(effect.foot, BY + BH - 30, 8.5, 2.6);\n      sc.strokeStyle = \"rgba(255,250,242,0.9)\"; sc.lineWidth = 1.4;\n      sc.beginPath(); sc.moveTo(BX + 34, BY + 72); sc.lineTo(BX + BW - 34, BY + 72); sc.stroke();\n      sc.beginPath(); sc.arc(SXc, SYc, 62, Math.PI * 0.62, Math.PI * 2.38); sc.stroke();\n    }\n\n    const chrome = (c: CanvasRenderingContext2D, x: number, y: number, rot: number) => {\n      if (!hasConic) { const g = c.createLinearGradient(x - 40, y - 40, x + 40, y + 40); g.addColorStop(0, \"#fafcfd\"); g.addColorStop(0.5, \"#737b82\"); g.addColorStop(1, \"#e8edf0\"); return g; }\n      const g = c.createConicGradient(rot, x, y);\n      const stops: [number, string][] = [[0, \"#f7fafc\"], [0.06, \"#c4ccd2\"], [0.13, \"#5e666d\"], [0.2, \"#a7b0b7\"], [0.29, \"#eef2f5\"], [0.37, \"#8b949b\"], [0.46, \"#3c4248\"], [0.52, \"#9aa3aa\"], [0.6, \"#f9fbfc\"], [0.68, \"#a9b2b9\"], [0.77, \"#555c63\"], [0.86, \"#b9c1c7\"], [0.94, \"#e9eef1\"], [1, \"#f7fafc\"]];\n      for (const [p, col] of stops) g.addColorStop(p, col);\n      return g;\n    };\n    // A polished cylinder seen from the side: bands of sky, horizon and the red box.\n    const barrel = (x: number, r: number) => {\n      const g = ctx.createLinearGradient(x - r, 0, x + r, 0);\n      const stops: [number, string][] = [[0, \"#22262a\"], [0.06, \"#8d969d\"], [0.16, \"#f4f7f9\"], [0.27, \"#aab3ba\"], [0.4, \"#4a5057\"], [0.5, \"#2b2f34\"], [0.6, box(0.6)], [0.72, \"#c9a59b\"], [0.84, \"#f6f8fa\"], [0.94, \"#7c858c\"], [1, \"#1d2024\"]];\n      for (const [p, col] of stops) g.addColorStop(p, col);\n      return g;\n    };\n\n    const s = { x: 0, v: 0, held: false, pulse: 0, lamp: 1, lx: -0.42, ly: -0.5 };\n\n    const draw = () => {\n      ctx.setTransform(1, 0, 0, 1, 0, 0);\n      ctx.clearRect(0, 0, cv.width, cv.height);\n      ctx.drawImage(still, 0, 0);\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      const L = s.lamp, [lr, lg, lb] = LAMP;\n\n      // ---- Jewel lamp ----\n      if (L > 0.01) {\n        ctx.save(); ctx.globalCompositeOperation = \"lighter\";\n        const spill = ctx.createRadialGradient(JX, JY, 12, JX, JY, 96);\n        spill.addColorStop(0, `rgba(${lr},${lg},${lb},${0.5 * L})`); spill.addColorStop(0.35, `rgba(${lr},${lg},${lb},${0.14 * L})`); spill.addColorStop(1, `rgba(${lr},${lg},${lb},0)`);\n        rr(ctx, BX, BY, BW, BH, BR); ctx.clip(); ctx.fillStyle = spill; ctx.fillRect(JX - 96, JY - 96, 192, 192); ctx.restore();\n      }\n      ctx.save(); ctx.shadowColor = \"rgba(40,0,0,0.6)\"; ctx.shadowBlur = 7 * dpr; ctx.shadowOffsetY = 5 * dpr; ctx.shadowOffsetX = 2 * dpr;\n      ctx.beginPath(); ctx.arc(JX, JY, 28, 0, Math.PI * 2); ctx.fillStyle = \"#000\"; ctx.fill(); ctx.restore();\n      ctx.beginPath(); ctx.arc(JX, JY, 29, 0, Math.PI * 2); ctx.fillStyle = chrome(ctx, JX, JY, s.lx * 0.5 + 0.4); ctx.fill();\n      ctx.lineWidth = 0.7; ctx.strokeStyle = \"rgba(0,0,0,0.55)\"; ctx.stroke();\n      ctx.beginPath(); ctx.arc(JX, JY, 23.5, 0, Math.PI * 2); ctx.fillStyle = chrome(ctx, JX, JY, s.lx * 0.5 + 2.2); ctx.fill();\n      ctx.lineWidth = 0.6; ctx.strokeStyle = \"rgba(0,0,0,0.5)\"; ctx.stroke();\n      ctx.beginPath(); ctx.arc(JX, JY, 19.4, 0, Math.PI * 2); ctx.fillStyle = \"#0a0503\"; ctx.fill();\n      const R = 18.2;\n      const glass = ctx.createRadialGradient(JX, JY, 0, JX, JY, R);\n      const mix = (off: number, lit: number) => (off + (lit - off) * L) | 0;\n      glass.addColorStop(0, `rgb(${mix(150, 255)},${mix(60, 250)},${mix(6, 214)})`);\n      glass.addColorStop(0.45, `rgb(${mix(120, 255)},${mix(44, 190)},${mix(4, 52)})`);\n      glass.addColorStop(1, `rgb(${mix(62, 226)},${mix(20, 104)},${mix(2, 4)})`);\n      ctx.save(); if (L > 0.01) { ctx.shadowColor = `rgba(${lr},${lg},${lb},${L})`; ctx.shadowBlur = 26 * dpr; }\n      ctx.beginPath(); ctx.arc(JX, JY, R, 0, Math.PI * 2); ctx.fillStyle = glass; ctx.fill(); ctx.restore();\n      // Cut facets: an outer ring of wedges and an inner star, each catching the light differently.\n      ctx.save(); ctx.beginPath(); ctx.arc(JX, JY, R, 0, Math.PI * 2); ctx.clip();\n      const N = 14;\n      for (let ring = 0; ring < 2; ring++) for (let i = 0; i < N; i++) {\n        const a0 = ((i + ring * 0.5) / N) * Math.PI * 2, a1 = a0 + (Math.PI * 2) / N, am = (a0 + a1) / 2;\n        const r0 = ring ? 0 : 9.6, r1 = ring ? 9.6 : R;\n        const face = Math.cos(am - Math.atan2(s.ly, s.lx)), v = (i % 2 ? 0.5 : -0.5) + face * 0.6;\n        ctx.beginPath(); ctx.moveTo(JX + Math.cos(a0) * r0, JY + Math.sin(a0) * r0); ctx.lineTo(JX + Math.cos(a0) * r1, JY + Math.sin(a0) * r1); ctx.lineTo(JX + Math.cos(a1) * r1, JY + Math.sin(a1) * r1); ctx.lineTo(JX + Math.cos(a1) * r0, JY + Math.sin(a1) * r0); ctx.closePath();\n        ctx.fillStyle = v > 0 ? `rgba(255,${ring ? 250 : 226},${ring ? 200 : 150},${v * (0.2 + 0.24 * L)})` : `rgba(50,8,0,${-v * (0.42 - 0.2 * L)})`; ctx.fill();\n        ctx.strokeStyle = `rgba(255,236,190,${0.1 + 0.2 * L})`; ctx.lineWidth = 0.4; ctx.stroke();\n      }\n      const rim = ctx.createRadialGradient(JX, JY, R * 0.55, JX, JY, R);\n      rim.addColorStop(0, \"rgba(0,0,0,0)\"); rim.addColorStop(1, `rgba(40,6,0,${0.6 - 0.3 * L})`);\n      ctx.fillStyle = rim; ctx.fillRect(JX - R, JY - R, R * 2, R * 2);\n      ctx.restore();\n      ctx.save(); ctx.translate(JX + s.lx * 13.5, JY + s.ly * 13.5); ctx.rotate(-0.6); ctx.scale(1, 0.55);\n      const hot = ctx.createRadialGradient(0, 0, 0, 0, 0, 6.5); hot.addColorStop(0, \"rgba(255,255,255,0.95)\"); hot.addColorStop(0.5, \"rgba(255,255,255,0.3)\"); hot.addColorStop(1, \"rgba(255,255,255,0)\");\n      ctx.fillStyle = hot; ctx.fillRect(-7, -7, 14, 14); ctx.restore();\n\n      // ---- Footswitch ----\n      const x = SXc, y = SYc, press = Math.max(-0.15, Math.min(1.08, s.x));\n      const top = 14 + 15 * (1 - press); // how far the cap stands above the box\n      // Washer.\n      ctx.save(); ctx.shadowColor = \"rgba(40,0,0,0.55)\"; ctx.shadowBlur = 5 * dpr; ctx.shadowOffsetY = 3 * dpr; ctx.shadowOffsetX = 1.5 * dpr;\n      ctx.beginPath(); ctx.arc(x, y, 43, 0, Math.PI * 2); ctx.fillStyle = \"#000\"; ctx.fill(); ctx.restore();\n      ctx.beginPath(); ctx.arc(x, y, 43.5, 0, Math.PI * 2); ctx.fillStyle = chrome(ctx, x, y, 1.1 + s.lx * 0.4); ctx.fill();\n      ctx.lineWidth = 0.7; ctx.strokeStyle = \"rgba(0,0,0,0.5)\"; ctx.stroke();\n      ctx.beginPath(); ctx.arc(x, y, 42.4, 0, Math.PI * 2); ctx.lineWidth = 0.6; ctx.strokeStyle = \"rgba(255,255,255,0.6)\"; ctx.stroke();\n      // Long shadow of the switch across washer and box.\n      ctx.save(); ctx.shadowColor = \"rgba(30,0,0,0.5)\"; ctx.shadowBlur = 9 * dpr; ctx.shadowOffsetX = (4 + top * 0.3) * dpr; ctx.shadowOffsetY = (8 + top * 0.55) * dpr;\n      ctx.beginPath(); ctx.arc(x, y - 3, 30, 0, Math.PI * 2); ctx.fillStyle = \"#000\"; ctx.fill(); ctx.restore();\n      // Hex nut: the three sides that face us, then the top with its chamfer.\n      const HEXR = 36, NH = 8, pt = (i: number, lift: number): [number, number] => [x + Math.cos((i / 6) * Math.PI * 2 + 0.26) * HEXR, y + Math.sin((i / 6) * Math.PI * 2 + 0.26) * HEXR - lift];\n      for (let i = 0; i < 6; i++) {\n        const a = pt(i, 0), b = pt(i + 1, 0), nx = (a[0] + b[0]) / 2 - x, ny = (a[1] + b[1]) / 2 - y;\n        if (ny < 2) continue;\n        const a2 = pt(i, NH), b2 = pt(i + 1, NH);\n        const g = ctx.createLinearGradient(a[0], 0, b[0], 0), tone = 0.5 + 0.5 * (-nx / HEXR);\n        g.addColorStop(0, `rgb(${(70 + tone * 150) | 0},${(76 + tone * 150) | 0},${(82 + tone * 150) | 0})`); g.addColorStop(0.5, `rgb(${(160 + tone * 90) | 0},${(120 + tone * 110) | 0},${(112 + tone * 110) | 0})`); g.addColorStop(1, `rgb(${(50 + tone * 120) | 0},${(54 + tone * 120) | 0},${(60 + tone * 120) | 0})`);\n        ctx.beginPath(); ctx.moveTo(a[0], a[1]); ctx.lineTo(b[0], b[1]); ctx.lineTo(b2[0], b2[1]); ctx.lineTo(a2[0], a2[1]); ctx.closePath(); ctx.fillStyle = g; ctx.fill();\n        ctx.lineWidth = 0.5; ctx.strokeStyle = \"rgba(0,0,0,0.45)\"; ctx.stroke();\n      }\n      ctx.beginPath(); for (let i = 0; i < 6; i++) { const p = pt(i, NH); ctx.lineTo(p[0], p[1]); } ctx.closePath();\n      ctx.fillStyle = chrome(ctx, x, y - NH, 2.6 + s.lx * 0.5); ctx.fill(); ctx.lineWidth = 0.6; ctx.strokeStyle = \"rgba(255,255,255,0.75)\"; ctx.stroke();\n      ctx.beginPath(); ctx.arc(x, y - NH, 30.4, 0, Math.PI * 2); ctx.fillStyle = chrome(ctx, x, y - NH, 0.2 + s.lx * 0.5); ctx.fill();\n      ctx.lineWidth = 0.6; ctx.strokeStyle = \"rgba(0,0,0,0.4)\"; ctx.stroke();\n      // Threaded bush, then the plunger rising out of it.\n      const tube = (r: number, from: number, to: number, threads: boolean) => {\n        ctx.beginPath(); ctx.arc(x, y - from, r, 0, Math.PI); ctx.lineTo(x - r, y - to); ctx.arc(x, y - to, r, Math.PI, 0, true); ctx.closePath();\n        ctx.fillStyle = barrel(x, r); ctx.fill(); ctx.lineWidth = 0.5; ctx.strokeStyle = \"rgba(0,0,0,0.5)\"; ctx.stroke();\n        if (threads) for (let h = from + 1.2; h < to; h += 1.7) { ctx.beginPath(); ctx.arc(x, y - h, r, 0.06, Math.PI - 0.06); ctx.lineWidth = 0.6; ctx.strokeStyle = \"rgba(0,0,0,0.42)\"; ctx.stroke(); }\n      };\n      ctx.beginPath(); ctx.arc(x + 1.5, y - NH + 2.5, 24, 0, Math.PI * 2); ctx.fillStyle = \"rgba(0,0,0,0.42)\"; ctx.fill();\n      tube(22.5, NH, 14, true);\n      ctx.beginPath(); ctx.arc(x, y - 14, 22.5, 0, Math.PI * 2); ctx.fillStyle = chrome(ctx, x, y - 14, 1.7); ctx.fill(); ctx.lineWidth = 0.5; ctx.strokeStyle = \"rgba(0,0,0,0.5)\"; ctx.stroke();\n      ctx.beginPath(); ctx.arc(x + 1, y - 12.5, 19.6, 0, Math.PI * 2); ctx.fillStyle = \"rgba(0,0,0,0.55)\"; ctx.fill();\n      tube(18.6, 14, top, false);\n      // Domed cap: a convex mirror. The room is in the middle, the horizon is a dark ring, the red box wraps the rim.\n      const cy = y - top, CR = 18.6;\n      ctx.save(); ctx.beginPath(); ctx.arc(x, cy, CR, 0, Math.PI * 2); ctx.clip();\n      const dome = ctx.createRadialGradient(x + s.lx * 6, cy + s.ly * 6, 0, x, cy, CR);\n      dome.addColorStop(0, \"#ffffff\"); dome.addColorStop(0.3, \"#e3e9ed\"); dome.addColorStop(0.5, \"#aeb8bf\"); dome.addColorStop(0.64, \"#59616a\"); dome.addColorStop(0.73, \"#1c1f23\"); dome.addColorStop(0.8, box(0.5)); dome.addColorStop(0.9, box(1.08)); dome.addColorStop(0.97, \"#f0c9bd\"); dome.addColorStop(1, \"#40201a\");\n      ctx.fillStyle = dome; ctx.fillRect(x - CR, cy - CR, CR * 2, CR * 2);\n      // The lamp shows up in the cap as a small warm smear near the top edge.\n      if (L > 0.02) { const g = ctx.createRadialGradient(x, cy - CR * 0.78, 0, x, cy - CR * 0.78, 7); g.addColorStop(0, `rgba(${lr},${lg},${lb},${0.95 * L})`); g.addColorStop(1, `rgba(${lr},${lg},${lb},0)`); ctx.save(); ctx.translate(x, cy - CR * 0.78); ctx.scale(1.6, 0.5); ctx.translate(-x, -(cy - CR * 0.78)); ctx.fillStyle = g; ctx.fillRect(x - 8, cy - CR * 0.78 - 8, 16, 16); ctx.restore(); }\n      // A window, bent by the dome.\n      ctx.translate(x + s.lx * 8.5, cy + s.ly * 8.5); ctx.rotate(Math.atan2(s.ly, s.lx) + Math.PI / 2);\n      ctx.fillStyle = \"rgba(255,255,255,0.96)\";\n      ctx.beginPath(); ctx.ellipse(-2.7, 0, 2.3, 3.6, 0, 0, Math.PI * 2); ctx.fill();\n      ctx.beginPath(); ctx.ellipse(2.7, 0, 2.3, 3.6, 0, 0, Math.PI * 2); ctx.fill();\n      ctx.restore();\n      ctx.beginPath(); ctx.arc(x, cy, CR, 0, Math.PI * 2); ctx.lineWidth = 0.6; ctx.strokeStyle = \"rgba(0,0,0,0.6)\"; ctx.stroke();\n    };\n\n    let raf = 0, last = 0, seen = true, touched = -1e9, t0 = 0, nextDemo = 1.05;\n    const flip = (v: boolean) => { onRef.current = v; setOn(v); };\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      const t = (now - t0) / 1000;\n      if (now - touched > 5000 && !s.held) {\n        s.lx += (-0.42 + 0.3 * Math.sin(t * 0.9) - s.lx) * Math.min(1, dt * 3); s.ly += (-0.5 + 0.12 * Math.cos(t * 0.7) - s.ly) * Math.min(1, dt * 3);\n        if (t > nextDemo) { s.pulse = 0.17; flip(!onRef.current); nextDemo = t + 1.3; }\n      }\n      if (s.pulse > 0) s.pulse -= dt;\n      // Going down the spring is stiff and dead; coming back it is lighter and overshoots once.\n      const down = s.held || s.pulse > 0, k = down ? 1500 : 620, c = down ? 62 : 17;\n      s.v += (k * ((down ? 1 : 0) - s.x) - c * s.v) * dt; s.x += s.v * dt;\n      const want = onRef.current ? 1 : 0;\n      s.lamp += (want - s.lamp) * Math.min(1, dt * (want ? 24 : 9)); // a filament: quick to light, slower to fade\n      draw();\n      if (seen && !document.hidden) raf = requestAnimationFrame(frame);\n    };\n    const wake = () => { if (!raf && !reduce) { last = performance.now(); raf = requestAnimationFrame(frame); } };\n    const settle = () => { s.x = s.held ? 1 : 0; s.v = 0; s.lamp = onRef.current ? 1 : 0; draw(); };\n\n    api.current = {\n      press: (down) => { touched = performance.now(); s.held = down; if (reduce) settle(); else wake(); },\n      set: (v, pulse) => { touched = performance.now(); onRef.current = v; if (pulse) s.pulse = 0.14; if (reduce) settle(); else wake(); },\n    };\n    if (reduce) settle(); else wake();\n\n    const onMove = (e: PointerEvent) => {\n      const b = cv.getBoundingClientRect(), px = (e.clientX - b.left) / b.width - 0.5, py = (e.clientY - b.top) / b.height - 0.62;\n      const len = Math.max(0.35, Math.hypot(px, py));\n      touched = Math.max(touched, performance.now() - 3600);\n      s.lx += ((px / len) * 0.62 - s.lx) * 0.18; s.ly += ((py / len) * 0.62 - s.ly) * 0.18;\n      if (reduce) draw();\n    };\n    window.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 () => { cancelAnimationFrame(raf); api.current = null; window.removeEventListener(\"pointermove\", onMove); io.disconnect(); document.removeEventListener(\"visibilitychange\", onVis); };\n  }, []);\n\n  const held = useRef(false);\n  const toggle = () => { const next = !on; setOn(next); api.current?.set(next, !held.current); };\n\n  return (\n    <div className=\"flex min-h-[640px] w-full flex-col items-center justify-center bg-[#d3d9df] bg-[radial-gradient(95%_70%_at_50%_36%,#e9edf1_0%,#d3d9df_72%)] px-4 py-10 sm:min-h-[740px]\">\n      <div className=\"relative h-[470px] w-[320px] sm:my-8 sm:scale-[1.2]\">\n        <div aria-hidden=\"true\" className=\"absolute left-[58px] right-[46px] top-[330px] h-[110px] rounded-[40%] bg-[#1c2836] opacity-50 blur-2xl\" />\n        <canvas ref={canvas} aria-hidden=\"true\" className=\"absolute inset-0 h-full w-full\" />\n        <button\n          type=\"button\"\n          role=\"switch\"\n          aria-checked={on}\n          aria-label={effect.name}\n          onClick={toggle}\n          onPointerDown={() => { held.current = true; api.current?.press(true); }}\n          onPointerUp={() => { api.current?.press(false); window.setTimeout(() => { held.current = false; }, 0); }}\n          onPointerLeave={() => { if (held.current) { held.current = false; api.current?.press(false); } }}\n          onPointerCancel={() => { held.current = false; api.current?.press(false); }}\n          className=\"absolute left-[106px] top-[226px] h-[108px] w-[108px] cursor-pointer touch-manipulation rounded-full outline-none focus-visible:ring-[3px] focus-visible:ring-white focus-visible:ring-offset-2 focus-visible:ring-offset-[#d64428]\"\n        />\n      </div>\n      <p aria-live=\"polite\" className=\"mt-2 text-center font-mono text-[11px] uppercase tracking-[0.2em] text-slate-600 sm:mt-8\">\n        <span className=\"font-semibold text-slate-900\">{effect.name}</span>\n        <span className=\"mx-2 text-slate-400\">/</span>\n        {on ? effect.on : effect.off}\n      </p>\n    </div>\n  );\n}\n"}]}
