{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"film-clapperboard-call-to-action-with-sticks-that-snap-shut-chalked-scene-details-and-a-running-timecode-countdown","type":"registry:block","title":"Film Clapperboard Call to Action with Sticks That Snap Shut, Chalked Scene Details and a Running Timecode Countdown","description":"Clapperboard on a canvas: the stick snaps shut, chalk dust jumps and a timecode window counts down frame by frame. Copy the React code or the HTML free.","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/film-clapperboard-call-to-action-with-sticks-that-snap-shut-chalked-scene-details-and-a-running-timecode-countdown.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\n// Everything a visitor is likely to change sits here.\nconst SLATE = { production: \"First Light\", roll: \"A12\", scene: \"24C\", take: 3, director: \"M. Okafor\", camera: \"J. Lindqvist\", date: \"14 Mar\" };\nconst COUNT_FROM = 6; // seconds on the timecode window when the sticks meet\nconst FPS = 24; // frames a second shown in the last pair of digits\nconst OPEN = 20; // how far the top stick is held open, in degrees\nconst FIRST_CLAP_MS = 3900; // the demo waits this long so the open slate can be seen first\nconst TILT = -3.5; // the whole slate lies a little crooked on the table, in degrees\nconst LED = \"#ff3b21\";\nconst CHALK_FONT = 'Chalkduster, \"Bradley Hand\", \"Segoe Print\", \"Comic Sans MS\", cursive';\nconst LABEL_FONT = '\"Helvetica Neue\", Helvetica, Arial, sans-serif';\n\n// Design pixels. The lower stick's top-left corner is the origin.\nconst BW = 540, BH = 330, ST = 46, PIV = 26, SWEEP = 176, OY = (BH - SWEEP) / 2 + ST / 2;\nconst ROW = [ST, ST + 84, ST + 176, ST + 246, ST + BH];\nconst DIGITS: Record<string, string> = { \"0\": \"abcdef\", \"1\": \"bc\", \"2\": \"abged\", \"3\": \"abgcd\", \"4\": \"fgbc\", \"5\": \"afgcd\", \"6\": \"afgedc\", \"7\": \"abc\", \"8\": \"abcdefg\", \"9\": \"abcdfg\" };\n\nconst rng = (seed: number) => () => {\n  seed |= 0; seed = (seed + 0x6d2b79f5) | 0;\n  let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);\n  t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;\n  return ((t ^ (t >>> 14)) >>> 0) / 4294967296;\n};\ntype Ctx = CanvasRenderingContext2D;\nconst rr = (c: Ctx, 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\n/** One stick: painted wood with diagonal bars, a gloss along the top edge and a few chips. */\nfunction paintStick(c: Ctx, y: number, lean: 1 | -1, seed: number) {\n  const r = rng(seed);\n  c.save();\n  rr(c, 0, y, BW, ST, 4); c.clip();\n  c.fillStyle = \"#efe9dc\"; c.fillRect(0, y, BW, ST);\n  c.fillStyle = \"#161514\";\n  const SW = 51;\n  for (let i = -2; i * SW * 2 < BW + ST; i++) {\n    const x0 = i * SW * 2 + 18;\n    c.beginPath();\n    if (lean > 0) { c.moveTo(x0, y + ST); c.lineTo(x0 + SW, y + ST); c.lineTo(x0 + SW + ST, y); c.lineTo(x0 + ST, y); }\n    else { c.moveTo(x0, y); c.lineTo(x0 + SW, y); c.lineTo(x0 + SW + ST, y + ST); c.lineTo(x0 + ST, y + ST); }\n    c.closePath(); c.fill();\n  }\n  // brush marks in the paint\n  for (let i = 0; i < 90; i++) { c.fillStyle = `rgba(${r() > 0.5 ? \"255,255,255\" : \"0,0,0\"},${0.02 + r() * 0.04})`; c.fillRect(r() * BW, y + r() * ST, 30 + r() * 120, 0.7); }\n  // chips where the edges have knocked together\n  c.fillStyle = \"#b98f5a\";\n  for (let i = 0; i < 16; i++) { const x = r() * BW, e = r() > 0.5 ? y : y + ST, w = 2 + r() * 7, d = (1 + r() * 2.4) * (e === y ? 1 : -1); c.beginPath(); c.moveTo(x, e); c.lineTo(x + w, e); c.lineTo(x + w * 0.4, e + d); c.closePath(); c.fill(); }\n  const g = c.createLinearGradient(0, y, 0, y + ST);\n  g.addColorStop(0, \"rgba(255,255,255,0.34)\"); g.addColorStop(0.16, \"rgba(255,255,255,0.08)\"); g.addColorStop(0.6, \"rgba(0,0,0,0)\"); g.addColorStop(1, \"rgba(0,0,0,0.3)\");\n  c.fillStyle = g; c.fillRect(0, y, BW, ST);\n  c.restore();\n  c.strokeStyle = \"rgba(255,255,255,0.5)\"; c.lineWidth = 1; c.beginPath(); c.moveTo(4, y + 0.8); c.lineTo(BW - 4, y + 0.8); c.stroke();\n  c.strokeStyle = \"rgba(0,0,0,0.55)\"; c.beginPath(); c.moveTo(4, y + ST - 0.5); c.lineTo(BW - 4, y + ST - 0.5); c.stroke();\n}\n\n/** A steel hinge leaf with two slotted screws. */\nfunction paintLeaf(c: Ctx, y: number, seed: number) {\n  const r = rng(seed);\n  const g = c.createLinearGradient(0, y, 0, y + ST - 10);\n  g.addColorStop(0, \"#f1f2f4\"); g.addColorStop(0.3, \"#a9acb2\"); g.addColorStop(0.55, \"#d6d8dc\"); g.addColorStop(1, \"#6d7077\");\n  c.save(); c.shadowColor = \"rgba(0,0,0,0.6)\"; c.shadowBlur = 3; c.shadowOffsetY = 1.5;\n  rr(c, 5, y + 5, 62, ST - 10, 3); c.fillStyle = g; c.fill(); c.restore();\n  c.save(); rr(c, 5, y + 5, 62, ST - 10, 3); c.clip();\n  for (let i = 0; i < 40; i++) { c.fillStyle = `rgba(${r() > 0.5 ? \"255,255,255\" : \"0,0,0\"},${0.04 + r() * 0.07})`; c.fillRect(5, y + 5 + r() * (ST - 10), 62, 0.6); }\n  c.restore();\n  for (const sx of [46, 59]) {\n    const sy = y + ST / 2 + (sx === 46 ? -7 : 7);\n    const sg = c.createRadialGradient(sx - 1.2, sy - 1.2, 0.4, sx, sy, 4.4);\n    sg.addColorStop(0, \"#fafafa\"); sg.addColorStop(0.6, \"#8f9299\"); sg.addColorStop(1, \"#3c3e43\");\n    c.fillStyle = sg; c.beginPath(); c.arc(sx, sy, 4.2, 0, Math.PI * 2); c.fill();\n    c.strokeStyle = \"rgba(20,20,22,0.85)\"; c.lineWidth = 1.1; const a = r() * Math.PI; c.beginPath(); c.moveTo(sx - Math.cos(a) * 3.2, sy - Math.sin(a) * 3.2); c.lineTo(sx + Math.cos(a) * 3.2, sy + Math.sin(a) * 3.2); c.stroke();\n  }\n}\n\n/** Handwriting in chalk: two passes of the letters on a scratch layer, then grit knocked back out of them. */\nfunction chalk(c: Ctx, text: string, x: number, y: number, size: number, seed: number, k: number, align: CanvasTextAlign = \"left\") {\n  const r = rng(seed);\n  const font = `${size}px ${CHALK_FONT}`;\n  c.font = font;\n  const w = c.measureText(text).width, tw = w + 24, th = size * 1.7;\n  const tmp = document.createElement(\"canvas\");\n  tmp.width = Math.ceil(tw * k); tmp.height = Math.ceil(th * k);\n  const t = tmp.getContext(\"2d\");\n  if (!t) return;\n  t.setTransform(k, 0, 0, k, 12 * k, size * 1.2 * k);\n  t.font = font; t.textBaseline = \"alphabetic\";\n  t.fillStyle = \"rgba(246,242,232,0.92)\"; t.fillText(text, 0, 0);\n  t.fillStyle = \"rgba(246,242,232,0.3)\"; t.fillText(text, 0.7, 0.5);\n  t.globalCompositeOperation = \"destination-out\";\n  for (let i = 0; i < (w * size) / 8; i++) { t.globalAlpha = 0.25 + r() * 0.5; t.beginPath(); t.arc(r() * w, -r() * size * 0.95 + size * 0.12, 0.3 + r() * 0.8, 0, Math.PI * 2); t.fill(); }\n  t.lineWidth = 0.6; t.strokeStyle = \"#000\";\n  for (let i = 0; i < w / 5; i++) { t.globalAlpha = 0.25; const sx = r() * w, sy = -r() * size * 0.8; t.beginPath(); t.moveTo(sx, sy); t.lineTo(sx + 5 + r() * 8, sy - 2 - r() * 3); t.stroke(); }\n  c.save();\n  c.translate(x, y); c.rotate((r() - 0.5) * 0.05);\n  c.drawImage(tmp, (align === \"center\" ? -w / 2 : 0) - 12, -size * 1.2, tw, th);\n  c.restore();\n}\n\nfunction spaced(c: Ctx, text: string, x: number, y: number, gap: number) {\n  for (const ch of text) { c.fillText(ch, x, y); x += c.measureText(ch).width + gap; }\n}\n\nexport default function ClapperboardCountdown() {\n  const reduce = useReducedMotion();\n  const wrapRef = useRef<HTMLDivElement>(null);\n  const cvRef = useRef<HTMLCanvasElement>(null);\n  const btnRef = useRef<HTMLButtonElement>(null);\n  const api = useRef({ press: () => {}, hover: false });\n  const [take, setTake] = useState(SLATE.take);\n  const [status, setStatus] = useState(\"Sticks open.\");\n\n  useEffect(() => {\n    const wrap = wrapRef.current, cv = cvRef.current, btn = btnRef.current;\n    if (!wrap || !cv || !btn) return;\n    const ctx = cv.getContext(\"2d\");\n    if (!ctx) return;\n    let W = 0, H = 0, s = 1, k = 1, cx = 0, cy = 0, raf = 0, visible = true, last = performance.now();\n    const bg = document.createElement(\"canvas\"), slate = document.createElement(\"canvas\"), stick = document.createElement(\"canvas\"), takeCv = document.createElement(\"canvas\");\n    const PAD = 70; // room round the slate layer for its shadow\n    const st = { phase: \"open\" as \"open\" | \"drop\" | \"run\" | \"done\", theta: OPEN, omega: 0, hit: false, tClap: 0, tDone: 0, nextClap: last + FIRST_CLAP_MS, take: SLATE.take, bumped: false, alpha: 1, reveal: 1, parts: [] as { x: number; y: number; vx: number; vy: number; life: number; age: number; r: number }[] };\n    const rnd = rng(77);\n\n    const layer = (cvs: HTMLCanvasElement, w: number, h: number) => {\n      cvs.width = Math.ceil(w * k); cvs.height = Math.ceil(h * k);\n      const c = cvs.getContext(\"2d\")!; c.setTransform(k, 0, 0, k, 0, 0); c.clearRect(0, 0, w, h);\n      return c;\n    };\n\n    const paintTake = () => {\n      const c = layer(takeCv, 180, 92);\n      chalk(c, String(st.take), 96, 74, 50, 900 + st.take, k, \"center\");\n    };\n\n    const build = () => {\n      // The table: a sheet of saffron paper under one soft lamp.\n      const b = bg.getContext(\"2d\")!;\n      bg.width = cv.width; bg.height = cv.height;\n      const d = k / s;\n      b.setTransform(d, 0, 0, d, 0, 0);\n      const g = b.createRadialGradient(W * 0.4, H * 0.3, 20, W * 0.5, H * 0.5, Math.max(W, H) * 0.78);\n      g.addColorStop(0, \"#f0c35c\"); g.addColorStop(0.5, \"#deaa3c\"); g.addColorStop(1, \"#b98322\");\n      b.fillStyle = g; b.fillRect(0, 0, W, H);\n      const r = rng(5);\n      for (let i = 0; i < (W * H) / 70; i++) { b.fillStyle = `rgba(${r() > 0.5 ? \"255,240,200\" : \"70,40,0\"},${0.03 + r() * 0.05})`; b.fillRect(r() * W, r() * H, 1, 1); }\n      // a stub of chalk and its dust, when there is room beside the slate\n      if (W > 860) {\n        b.save(); b.translate(cx, cy); b.rotate((TILT * Math.PI) / 180); b.scale(s, s); b.translate(-BW / 2, -OY);\n        for (let i = 0; i < 120; i++) { const a = r() * Math.PI * 2, q = r() * r() * 46; b.fillStyle = `rgba(255,252,240,${0.1 + r() * 0.3})`; b.fillRect(BW + 86 + Math.cos(a) * q, ST + BH - 46 + Math.sin(a) * q * 0.7, 1.2, 1.2); }\n        b.translate(BW + 84, ST + BH - 50); b.rotate(0.5);\n        b.shadowColor = \"rgba(70,40,0,0.45)\"; b.shadowBlur = 9; b.shadowOffsetX = 4; b.shadowOffsetY = 7;\n        const cg = b.createLinearGradient(0, -7, 0, 7);\n        cg.addColorStop(0, \"#ffffff\"); cg.addColorStop(0.45, \"#f3efe4\"); cg.addColorStop(1, \"#bdb6a4\");\n        rr(b, -30, -7, 60, 14, 5); b.fillStyle = cg; b.fill();\n        b.shadowColor = \"transparent\"; b.fillStyle = \"rgba(120,110,90,0.25)\"; b.beginPath(); b.ellipse(27.5, 0, 2.6, 6.4, 0, 0, Math.PI * 2); b.fill();\n        b.restore();\n      }\n\n      // The slate: lower stick and board, baked with its shadow.\n      const c = layer(slate, BW + PAD * 2, ST + BH + PAD * 2);\n      c.translate(PAD, PAD);\n      c.save(); c.shadowColor = \"rgba(74,42,0,0.6)\"; c.shadowBlur = 34 * k; c.shadowOffsetX = 14 * k; c.shadowOffsetY = 26 * k; rr(c, 0, 0, BW, ST + BH, 6); c.fillStyle = \"#111\"; c.fill();\n      c.shadowColor = \"rgba(50,25,0,0.75)\"; c.shadowBlur = 7 * k; c.shadowOffsetX = 3 * k; c.shadowOffsetY = 5 * k; c.fill(); c.restore();\n      const bgr = c.createLinearGradient(0, ST, BW, ST + BH);\n      bgr.addColorStop(0, \"#232324\"); bgr.addColorStop(0.5, \"#161617\"); bgr.addColorStop(1, \"#0f0f10\");\n      rr(c, 0, ST - 6, BW, BH + 6, 6); c.fillStyle = bgr; c.fill();\n      c.save(); rr(c, 0, ST, BW, BH, 6); c.clip();\n      const r2 = rng(11);\n      // chalk haze left by an eraser, heavier where the take number keeps changing\n      for (let i = 0; i < 26; i++) {\n        const tk = i < 7, x = tk ? 400 + r2() * 110 : r2() * BW, y = tk ? ROW[1] + 20 + r2() * 60 : ST + r2() * BH, rx = 40 + r2() * 110, ry = 10 + r2() * 26;\n        c.save(); c.translate(x, y); c.rotate((r2() - 0.5) * 0.7); c.scale(1, ry / rx);\n        const hz = c.createRadialGradient(0, 0, 0, 0, 0, rx); hz.addColorStop(0, `rgba(240,236,226,${tk ? 0.05 : 0.035})`); hz.addColorStop(1, \"rgba(240,236,226,0)\");\n        c.fillStyle = hz; c.beginPath(); c.arc(0, 0, rx, 0, Math.PI * 2); c.fill(); c.restore();\n      }\n      for (let i = 0; i < 2600; i++) { c.fillStyle = `rgba(255,255,255,${0.02 + r2() * 0.06})`; c.fillRect(r2() * BW, ST + r2() * BH, 0.9, 0.9); }\n      // the lamp's soft reflection in the lacquer\n      const sheen = c.createLinearGradient(40, ST, 330, ST + BH); sheen.addColorStop(0, \"rgba(255,255,255,0.09)\"); sheen.addColorStop(0.35, \"rgba(255,255,255,0.03)\"); sheen.addColorStop(0.6, \"rgba(255,255,255,0)\");\n      c.fillStyle = sheen; c.fillRect(0, ST, BW, BH);\n      c.restore();\n      // painted rules\n      c.strokeStyle = \"rgba(236,231,220,0.9)\"; c.lineWidth = 2; c.lineCap = \"round\";\n      rr(c, 10, ST + 10, BW - 20, BH - 20, 2); c.stroke();\n      c.beginPath();\n      for (const y of [ROW[1], ROW[2], ROW[3]]) { c.moveTo(10, y); c.lineTo(BW - 10, y); }\n      c.moveTo(190, ROW[1]); c.lineTo(190, ROW[2]); c.moveTo(370, ROW[1]); c.lineTo(370, ROW[2]);\n      c.moveTo(270, ROW[2]); c.lineTo(270, ROW[3]); c.moveTo(190, ROW[3]); c.lineTo(190, ROW[4] - 10);\n      c.stroke();\n      // printed labels\n      c.fillStyle = \"rgba(236,231,220,0.86)\"; c.font = `700 9.5px ${LABEL_FONT}`; c.textBaseline = \"alphabetic\"; c.textAlign = \"left\";\n      for (const [t, x, y] of [[\"PROD.\", 22, ROW[0] + 28], [\"ROLL\", 22, ROW[1] + 19], [\"SCENE\", 202, ROW[1] + 19], [\"TAKE\", 382, ROW[1] + 19], [\"DIRECTOR\", 22, ROW[2] + 19], [\"CAMERA\", 282, ROW[2] + 19], [\"DATE\", 22, ROW[3] + 19], [\"TIMECODE\", 202, ROW[3] + 19]] as [string, number, number][]) spaced(c, t, x, y, 1.6);\n      c.fillStyle = \"rgba(236,231,220,0.5)\"; c.font = `600 7.5px ${LABEL_FONT}`; spaced(c, \"HR   MIN   SEC   FR\", BW - 138, ROW[3] + 19, 1.2);\n      // chalked details\n      chalk(c, SLATE.production, 84, ROW[1] - 22, 38, 1, k);\n      chalk(c, SLATE.roll, 100, ROW[2] - 20, 42, 2, k, \"center\");\n      chalk(c, SLATE.scene, 282, ROW[2] - 20, 42, 3, k, \"center\");\n      chalk(c, SLATE.director, 24, ROW[3] - 15, 23, 4, k);\n      chalk(c, SLATE.camera, 284, ROW[3] - 15, 23, 5, k);\n      chalk(c, SLATE.date, 24, ROW[4] - 26, 25, 6, k);\n      // the timecode window: a slot cut in the board with dark red glass over the digits\n      const wx = 202, wy = ROW[3] + 27, ww = BW - 22 - wx, wh = 43;\n      rr(c, wx - 2, wy - 2, ww + 4, wh + 4, 5); c.fillStyle = \"rgba(255,255,255,0.1)\"; c.fill();\n      rr(c, wx, wy, ww, wh, 4); const wg = c.createLinearGradient(0, wy, 0, wy + wh); wg.addColorStop(0, \"#090101\"); wg.addColorStop(1, \"#200605\"); c.fillStyle = wg; c.fill();\n      c.save(); rr(c, wx, wy, ww, wh, 4); c.clip();\n      const sh = c.createLinearGradient(0, wy, 0, wy + 12); sh.addColorStop(0, \"rgba(0,0,0,0.85)\"); sh.addColorStop(1, \"rgba(0,0,0,0)\"); c.fillStyle = sh; c.fillRect(wx, wy, ww, 12);\n      c.restore();\n      // board bevel, then the fixed stick and its hinge leaf\n      c.strokeStyle = \"rgba(255,255,255,0.16)\"; c.lineWidth = 1; c.beginPath(); c.moveTo(0.6, ST + BH - 6); c.lineTo(0.6, ST); c.stroke();\n      const eg = c.createLinearGradient(0, ST + BH - 5, 0, ST + BH); eg.addColorStop(0, \"#47474a\"); eg.addColorStop(0.3, \"#242425\"); eg.addColorStop(1, \"#060606\");\n      c.fillStyle = eg; c.fillRect(5, ST + BH - 5, BW - 10, 5);\n      const eg2 = c.createLinearGradient(BW - 4, 0, BW, 0); eg2.addColorStop(0, \"#3a3a3c\"); eg2.addColorStop(1, \"#070707\");\n      c.fillStyle = eg2; c.fillRect(BW - 4, ST + 4, 4, BH - 9);\n      paintStick(c, 0, -1, 21);\n      paintLeaf(c, 0, 31);\n\n      // The moving stick, on its own layer so it can turn about the hinge pin.\n      const u = layer(stick, BW + 40, ST + 40);\n      u.translate(20, 20 + ST); // the pivot row is the stick's bottom edge\n      paintStick(u, -ST, 1, 22);\n      paintLeaf(u, -ST, 32);\n      paintTake();\n    };\n\n    const digit = (ch: string, x: number, y: number, dw: number, dh: number, lit: boolean) => {\n      const th = 4.4, on = lit ? DIGITS[ch] || \"\" : \"\";\n      const bar = (seg: string, hx: number, hy: number, len: number, horiz: boolean) => {\n        const o = on.includes(seg);\n        ctx.fillStyle = o ? LED : \"rgba(255,60,30,0.1)\";\n        ctx.shadowColor = o ? LED : \"transparent\"; ctx.shadowBlur = o ? 7 * k : 0;\n        ctx.beginPath();\n        if (horiz) { ctx.moveTo(hx + th / 2, hy); ctx.lineTo(hx + len - th / 2, hy); ctx.lineTo(hx + len, hy + th / 2); ctx.lineTo(hx + len - th / 2, hy + th); ctx.lineTo(hx + th / 2, hy + th); ctx.lineTo(hx, hy + th / 2); }\n        else { ctx.moveTo(hx + th / 2, hy); ctx.lineTo(hx + th, hy + th / 2); ctx.lineTo(hx + th, hy + len - th / 2); ctx.lineTo(hx + th / 2, hy + len); ctx.lineTo(hx, hy + len - th / 2); ctx.lineTo(hx, hy + th / 2); }\n        ctx.closePath(); ctx.fill();\n      };\n      const half = (dh - th) / 2;\n      bar(\"a\", x + 1.2, y, dw - 2.4, true); bar(\"g\", x + 1.2, y + half, dw - 2.4, true); bar(\"d\", x + 1.2, y + dh - th, dw - 2.4, true);\n      bar(\"f\", x, y + 1.2, half + th - 2.4, false); bar(\"b\", x + dw - th, y + 1.2, half + th - 2.4, false);\n      bar(\"e\", x, y + half + 1.2, half + th - 2.4, false); bar(\"c\", x + dw - th, y + half + 1.2, half + th - 2.4, false);\n    };\n\n    const draw = (now: number) => {\n      ctx.setTransform(1, 0, 0, 1, 0, 0);\n      ctx.drawImage(bg, 0, 0);\n      const sinceHit = st.hit ? (now - st.tClap) / 1000 : 9;\n      const jolt = Math.exp(-9 * sinceHit);\n      ctx.setTransform(k, 0, 0, k, cx * (k / s), (cy + 5 * jolt * Math.cos(38 * sinceHit)) * (k / s));\n      ctx.rotate(((TILT + 0.5 * jolt * Math.sin(30 * sinceHit)) * Math.PI) / 180);\n      ctx.translate(-BW / 2, -OY);\n      // the top stick is drawn twice: first with its shadow, which the slate then covers, so the shadow only reaches the table\n      const topStick = (shadow: boolean) => {\n        ctx.save();\n        ctx.translate(PIV, 0); ctx.rotate((-st.theta * Math.PI) / 180);\n        if (shadow) { ctx.shadowColor = \"rgba(74,42,0,0.6)\"; ctx.shadowBlur = 20 * k; ctx.shadowOffsetX = 12 * k; ctx.shadowOffsetY = 22 * k; }\n        ctx.drawImage(stick, -PIV - 20, -ST - 20, BW + 40, ST + 40);\n        ctx.restore();\n      };\n      topStick(true);\n      ctx.drawImage(slate, -PAD, -PAD, BW + PAD * 2, ST + BH + PAD * 2);\n      // the take number, wiped and rewritten between takes\n      if (st.alpha > 0.01) {\n        ctx.save(); ctx.globalAlpha = st.alpha;\n        ctx.beginPath(); ctx.rect(372, ROW[1] + 2, 180 * st.reveal, 90); ctx.clip();\n        ctx.drawImage(takeCv, 366, ROW[1] + 1, 180, 92); ctx.restore();\n      }\n      // timecode\n      let rem = COUNT_FROM, lit = true;\n      if (st.hit && (st.phase === \"drop\" || st.phase === \"run\")) rem = Math.max(0, COUNT_FROM - sinceHit);\n      if (st.phase === \"done\") { const t = (now - st.tDone) / 1000; if (t < 1.3) { rem = 0; lit = Math.floor(t * 5) % 2 === 0; } }\n      const sec = Math.floor(rem), fr = Math.min(FPS - 1, Math.floor((rem - sec) * FPS));\n      const txt = `0000${String(sec).padStart(2, \"0\")}${String(fr).padStart(2, \"0\")}`;\n      ctx.save();\n      ctx.transform(1, 0, -0.08, 1, 0, 0);\n      const dw = 19, dh = 29, y0 = ROW[3] + 34;\n      let x = 232 + (y0 + dh / 2) * 0.08;\n      for (let i = 0; i < 8; i++) {\n        digit(txt[i], x, y0, dw, dh, lit);\n        x += dw + 7;\n        if (i % 2 === 1 && i < 7) {\n          ctx.fillStyle = lit ? LED : \"rgba(255,60,30,0.1)\"; ctx.shadowColor = lit ? LED : \"transparent\"; ctx.shadowBlur = lit ? 7 * k : 0;\n          ctx.fillRect(x + 1.5, y0 + 8, 3.6, 3.6); ctx.fillRect(x + 1.5, y0 + 18, 3.6, 3.6);\n          x += 13;\n        }\n      }\n      ctx.restore();\n      ctx.shadowColor = \"transparent\"; ctx.shadowBlur = 0;\n      // a slanted reflection across the window glass\n      const gl = ctx.createLinearGradient(202, ROW[3] + 27, 330, ROW[3] + 70);\n      gl.addColorStop(0, \"rgba(255,255,255,0)\"); gl.addColorStop(0.45, \"rgba(255,255,255,0.07)\"); gl.addColorStop(0.5, \"rgba(255,255,255,0)\");\n      ctx.fillStyle = gl; rr(ctx, 202, ROW[3] + 27, BW - 224, 43, 4); ctx.fill();\n      // the top stick\n      topStick(false);\n      // hinge pin\n      const pg = ctx.createRadialGradient(PIV - 2.5, -2.5, 1, PIV, 0, 10);\n      pg.addColorStop(0, \"#ffffff\"); pg.addColorStop(0.45, \"#aeb1b7\"); pg.addColorStop(1, \"#34363b\");\n      ctx.fillStyle = \"rgba(0,0,0,0.5)\"; ctx.beginPath(); ctx.arc(PIV + 0.8, 1.6, 10, 0, Math.PI * 2); ctx.fill();\n      ctx.fillStyle = pg; ctx.beginPath(); ctx.arc(PIV, 0, 9.4, 0, Math.PI * 2); ctx.fill();\n      ctx.fillStyle = \"#2a2c30\"; ctx.beginPath(); for (let i = 0; i < 6; i++) { const a = (i * Math.PI) / 3 + 0.4; ctx.lineTo(PIV + Math.cos(a) * 4, Math.sin(a) * 4); } ctx.closePath(); ctx.fill();\n      // chalk dust knocked loose by the clap\n      for (const p of st.parts) { const a = 1 - p.age / p.life; ctx.fillStyle = `rgba(255,251,240,${(0.5 * a).toFixed(3)})`; ctx.beginPath(); ctx.arc(p.x, p.y, p.r * (1.6 - a * 0.6), 0, Math.PI * 2); ctx.fill(); }\n    };\n\n    const clap = (now: number) => {\n      st.hit = true; st.tClap = now;\n      for (let i = 0; i < 46; i++) st.parts.push({ x: PIV + 40 + Math.pow(rnd(), 0.6) * (BW - PIV - 46), y: (rnd() - 0.5) * 4, vx: (rnd() - 0.3) * 60, vy: (rnd() - 0.5) * 190, life: 0.5 + rnd() * 0.9, age: 0, r: 0.7 + rnd() * 1.8 });\n      setStatus(`Take ${st.take} marked. Timecode counting down from ${COUNT_FROM} seconds.`);\n    };\n\n    const tick = (now: number) => {\n      const dt = Math.min(0.033, (now - last) / 1000); last = now;\n      if (st.phase === \"open\" || st.phase === \"done\") {\n        const t = (now - st.tDone) / 1000;\n        const held = st.phase === \"done\" && t < 0.4;\n        const target = held ? 0 : OPEN + (api.current.hover ? 4 : 0) + Math.sin(now / 900) * 0.6;\n        st.omega += (110 * (target - st.theta) - 14 * st.omega) * dt; st.theta = Math.max(0, st.theta + st.omega * dt);\n        if (st.phase === \"open\" && now > st.nextClap) { st.phase = \"drop\"; st.hit = false; st.omega = 0; }\n        if (st.phase === \"done\") {\n          if (!st.bumped) { st.alpha = 1 - Math.min(1, Math.max(0, (t - 0.8) / 0.45)); if (t > 1.3) { st.bumped = true; st.take += 1; paintTake(); setTake(st.take); st.reveal = 0; st.alpha = 1; } }\n          else st.reveal = Math.min(1, (t - 1.35) / 0.55);\n          if (t > 2.3) { st.phase = \"open\"; st.hit = false; st.nextClap = now + 2800; setStatus(`Sticks open for take ${st.take}.`); }\n        }\n      } else if (st.phase === \"drop\") {\n        st.omega -= 2600 * dt; st.theta += st.omega * dt;\n        if (st.theta <= 0) { st.theta = 0; if (!st.hit) clap(now); st.omega = -st.omega * 0.22; if (Math.abs(st.omega) < 30) { st.omega = 0; st.phase = \"run\"; } }\n      } else if (now - st.tClap > COUNT_FROM * 1000) { st.phase = \"done\"; st.tDone = now; st.bumped = false; }\n      for (const p of st.parts) { p.age += dt; p.x += p.vx * dt; p.y += p.vy * dt; p.vx *= 1 - 3 * dt; p.vy *= 1 - 3.4 * dt; }\n      st.parts = st.parts.filter((p) => p.age < p.life);\n      draw(now);\n      if (visible && !document.hidden) raf = requestAnimationFrame(tick);\n    };\n\n    const size = () => {\n      W = wrap.clientWidth;\n      s = Math.min(1, Math.max(0.5, (W - 36) / 600));\n      H = W < 640 ? Math.round((ST * 2 + BH + SWEEP) * s + 220) : 700;\n      wrap.style.height = `${H}px`;\n      const dpr = Math.min(2, window.devicePixelRatio || 1);\n      k = dpr * s;\n      cv.width = Math.round(W * dpr); cv.height = Math.round(H * dpr);\n      cx = W / 2; cy = H / 2 + (W < 640 ? -26 : -6);\n      // from here on, positions are in design pixels: divide the centre by the scale\n      const top = cy - (OY + ST + SWEEP) * s;\n      btn.style.left = `${cx - (BW * s) / 2}px`; btn.style.top = `${top}px`;\n      btn.style.width = `${BW * s}px`; btn.style.height = `${(ST * 2 + BH + SWEEP) * s}px`;\n      btn.style.transformOrigin = `50% ${cy - top}px`; btn.style.transform = `rotate(${TILT}deg)`;\n      build();\n      draw(performance.now());\n    };\n\n    api.current.press = () => {\n      const now = performance.now();\n      if (reduce) { st.theta = st.theta > 1 ? 0 : OPEN; if (st.theta === 0) { setStatus(`Take ${st.take} marked.`); } else { st.take += 1; paintTake(); setTake(st.take); setStatus(`Sticks open for take ${st.take}.`); } draw(now); return; }\n      if (st.phase === \"open\") { st.phase = \"drop\"; st.hit = false; st.omega = 0; }\n      else if (st.phase === \"run\") { st.phase = \"done\"; st.tDone = now - 400; st.bumped = false; }\n    };\n\n    size();\n    const ro = new ResizeObserver(size); ro.observe(wrap);\n    const start = () => { cancelAnimationFrame(raf); if (!reduce && visible && !document.hidden) { last = performance.now(); raf = requestAnimationFrame(tick); } };\n    const io = new IntersectionObserver(([e]) => { visible = e.isIntersecting; start(); });\n    io.observe(wrap);\n    document.addEventListener(\"visibilitychange\", start);\n    start();\n    return () => { cancelAnimationFrame(raf); ro.disconnect(); io.disconnect(); document.removeEventListener(\"visibilitychange\", start); };\n  }, [reduce]);\n\n  return (\n    <section ref={wrapRef} className=\"relative w-full overflow-hidden bg-[#deaa3c]\" style={{ height: 700 }}>\n      <canvas ref={cvRef} aria-hidden=\"true\" className=\"absolute inset-0 h-full w-full\" />\n      <button\n        ref={btnRef}\n        type=\"button\"\n        onClick={() => api.current.press()}\n        onPointerEnter={() => { api.current.hover = true; }}\n        onPointerLeave={() => { api.current.hover = false; }}\n        aria-label={`Clapperboard for ${SLATE.production}, scene ${SLATE.scene}, take ${take}. Press to snap the sticks and start the countdown.`}\n        className=\"absolute cursor-pointer rounded-md bg-transparent outline-none focus-visible:ring-2 focus-visible:ring-neutral-900 focus-visible:ring-offset-4 focus-visible:ring-offset-[#deaa3c]\"\n      />\n      <p className=\"absolute bottom-[76px] left-5 font-mono text-[11px] uppercase leading-relaxed tracking-[0.18em] text-[#2b1c03] sm:bottom-8 sm:left-8\">\n        <span className=\"font-semibold\">{SLATE.production} / Sc {SLATE.scene} / Take {take}</span>\n        <span className=\"block text-[#4a3207]\">Press the slate to mark it</span>\n      </p>\n      <a href=\"#\" className=\"absolute bottom-4 left-5 right-5 inline-flex h-11 items-center justify-center gap-2 sm:left-auto rounded-full bg-[#171514] px-5 text-[13px] font-medium text-[#f6f0e2] transition hover:bg-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-neutral-900 focus-visible:ring-offset-2 focus-visible:ring-offset-[#deaa3c] sm:bottom-7 sm:right-8\">\n        Book the premiere\n        <svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\"><path d=\"M4 10h12M11 5l5 5-5 5\" /></svg>\n      </a>\n      <p aria-live=\"polite\" className=\"sr-only\">{status}</p>\n    </section>\n  );\n}\n"}]}
