{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"pin-tumbler-lock-cutaway-password-strength-field-where-each-rule-sets-a-pin-and-the-key-turns-the-plug","type":"registry:component","title":"Pin Tumbler Lock Cutaway Password Strength Field Where Each Rule Sets a Pin and the Key Turns the Plug","description":"Password field with a strength meter drawn as a brass lock in section: each rule you meet sets a pin, then the key turns. Free React and HTML code to copy.","dependencies":[],"files":[{"path":"components/we-inc/pin-tumbler-lock-cutaway-password-strength-field-where-each-rule-sets-a-pin-and-the-key-turns-the-plug.tsx","type":"registry:component","content":"import { useEffect, useId, useRef, useState } from \"react\";\n\n// One pin per rule, front of the lock to the back. Four to six rules fit.\nconst rules: { label: string; test: (p: string) => boolean }[] = [\n  { label: \"10 characters\", test: (p) => p.length >= 10 },\n  { label: \"Capital letter\", test: (p) => /[A-Z]/.test(p) },\n  { label: \"Small letter\", test: (p) => /[a-z]/.test(p) },\n  { label: \"Number\", test: (p) => /[0-9]/.test(p) },\n  { label: \"Symbol\", test: (p) => /[^A-Za-z0-9]/.test(p) },\n];\nconst DEMO = \"Brass-Otter-42\"; // what the lock types by itself until someone clicks into the field\nconst LAMP = \"#6ee7b7\"; // lamp above a set pin, and the line the pins meet on\nconst CUTS = [8, 24, 14, 30, 18, 22]; // how deep each cut in the key ends up\n\nconst N = rules.length;\nconst W = 760, H = 400, AX = 246, PR = 52, SH = AX - PR, KT = SH + 30, KB = KT + 58, SX0 = 252, SX1 = 620, TOP = 56, CH = 82;\nconst pinX = (i: number) => 322 + (N === 1 ? 124 : (i * 248) / (N - 1));\nconst check = (p: string) => rules.map((r) => r.test(p));\n\nexport default function PinTumblerPasswordField() {\n  const wrap = useRef<HTMLDivElement>(null);\n  const canvas = useRef<HTMLCanvasElement>(null);\n  const [value, setValue] = useState(DEMO);\n  const [show, setShow] = useState(false);\n  const met = check(value);\n  const metRef = useRef<boolean[]>(met);\n  const api = useRef<{ type: (v: string) => void; stop: () => boolean } | null>(null);\n  const id = useId();\n  const count = met.filter(Boolean).length, strong = count === N;\n\n  useEffect(() => {\n    const cv = canvas.current, box = wrap.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    let K = 1;\n    const s = { cut: CUTS.slice(0, N), cutV: rules.map(() => 0), hop: 0, hopV: 0, kx: 0, kxV: 0, turn: 0, turnV: 0, bolt: 1, boltV: 0, glint: -1, lamp: rules.map(() => 1) };\n\n    const rr = (x: number, y: number, w: number, h: number, r: number) => {\n      ctx.beginPath(); ctx.moveTo(x + r, y); ctx.lineTo(x + w - r, y); ctx.quadraticCurveTo(x + w, y, x + w, y + r);\n      ctx.lineTo(x + w, y + h - r); ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h); ctx.lineTo(x + r, y + h);\n      ctx.quadraticCurveTo(x, y + h, x, y + h - r); ctx.lineTo(x, y + r); ctx.quadraticCurveTo(x, y, x + r, y); ctx.closePath();\n    };\n    const lin = (x0: number, y0: number, x1: number, y1: number, stops: [number, string][]) => { const g = ctx.createLinearGradient(x0, y0, x1, y1); for (const [p, c] of stops) g.addColorStop(p, c); return g; };\n    const shadow = (shape: () => void, blur: number, dx: number, dy: number, alpha: number) => {\n      ctx.save(); ctx.shadowColor = `rgba(0,0,0,${alpha})`; ctx.shadowBlur = blur * K; ctx.shadowOffsetX = (dx + 3000) * K; ctx.shadowOffsetY = dy * K;\n      ctx.translate(-3000, 0); ctx.fillStyle = \"#000\"; shape(); ctx.restore();\n    };\n    // Section hatching, the draughtsman's way of saying \"this face has been cut\".\n    const hatch = (x: number, y: number, w: number, h: number, lean: number, alpha: number) => {\n      ctx.save(); ctx.beginPath(); ctx.rect(x, y, w, h); ctx.clip(); ctx.lineWidth = 1;\n      for (let d = -h; d < w + h; d += 8) {\n        ctx.beginPath(); ctx.moveTo(x + d, lean > 0 ? y + h : y); ctx.lineTo(x + d + h, lean > 0 ? y : y + h);\n        ctx.strokeStyle = `rgba(70,44,6,${alpha})`; ctx.stroke();\n        ctx.beginPath(); ctx.moveTo(x + d + 1, lean > 0 ? y + h : y); ctx.lineTo(x + d + h + 1, lean > 0 ? y : y + h);\n        ctx.strokeStyle = `rgba(255,240,196,${alpha * 0.7})`; ctx.stroke();\n      }\n      ctx.restore();\n    };\n    const STEEL: [number, string][] = [[0, \"#565b62\"], [0.22, \"#dfe4e8\"], [0.36, \"#ffffff\"], [0.55, \"#aab1b8\"], [0.82, \"#646a72\"], [1, \"#33363b\"]];\n    const COPPER: [number, string][] = [[0, \"#5c2408\"], [0.22, \"#e9955a\"], [0.36, \"#ffd2ae\"], [0.55, \"#c9682f\"], [0.82, \"#84360f\"], [1, \"#43190a\"]];\n    const depth = (x: number) => { let d = 0; for (let i = 0; i < N; i++) d = Math.max(d, Math.min(s.cut[i], s.cut[i] - (Math.abs(x - pinX(i)) - 6))); return Math.max(0, d); };\n\n    const draw = () => {\n      ctx.setTransform(K, 0, 0, K, 0, 0); ctx.clearRect(0, 0, W, H); ctx.lineCap = \"round\"; ctx.lineJoin = \"round\";\n      const turned = Math.max(0, Math.min(1, s.turn)), phi = (turned * Math.PI) / 2, flat = Math.max(0.13, Math.cos(phi)), inside = Math.max(0, Math.min(1, Math.cos(phi) * 1.5));\n      const allSet = s.lamp.reduce((a, b) => a + b, 0) / N;\n      const throwOut = Math.max(0, s.bolt);\n\n      shadow(() => { ctx.beginPath(); ctx.ellipse(430, 352, 250, 13, 0, 0, Math.PI * 2); ctx.fill(); }, 22, 0, 0, 0.75);\n\n      // Behind the cylinder: tailpiece, bolt case and the bolt it throws.\n      const tail = 6 + 9 * Math.sin(phi);\n      ctx.fillStyle = lin(0, AX - tail, 0, AX + tail, STEEL); ctx.fillRect(SX1, AX - tail, 40, tail * 2);\n      ctx.fillStyle = lin(0, AX - 19, 0, AX + 19, STEEL); rr(700, AX - 19, 12 + 34 * throwOut, 38, 4); ctx.fill();\n      ctx.fillStyle = \"rgba(0,0,0,0.3)\"; ctx.fillRect(700, AX - 19, 8, 38);\n      rr(650, AX - 46, 56, 92, 7); ctx.fillStyle = lin(0, AX - 46, 0, AX + 46, [[0, \"#4a4e55\"], [0.08, \"#2c2f34\"], [0.6, \"#1a1c1f\"], [1, \"#0b0c0d\"]]); ctx.fill();\n      ctx.strokeStyle = \"rgba(255,255,255,0.14)\"; ctx.lineWidth = 1; rr(650.5, AX - 45.5, 55, 91, 7); ctx.stroke();\n      for (const sy of [AX - 34, AX + 34]) { ctx.beginPath(); ctx.arc(678, sy, 4, 0, Math.PI * 2); ctx.fillStyle = \"#0a0a0b\"; ctx.fill(); ctx.beginPath(); ctx.arc(678, sy - 0.6, 3, 0, Math.PI * 2); ctx.fillStyle = \"#565a61\"; ctx.fill(); ctx.fillStyle = \"#111\"; ctx.fillRect(675.4, sy - 1.1, 5.2, 1.2); }\n\n      // The brass shell, cut down the middle.\n      rr(SX0, TOP, SX1 - SX0, AX + PR + 18 - TOP, 14);\n      ctx.fillStyle = lin(0, TOP, 0, AX + PR + 18, [[0, \"#f1d68c\"], [0.05, \"#deb964\"], [0.5, \"#c59a45\"], [0.92, \"#a67c2d\"], [1, \"#7c5a1a\"]]); ctx.fill();\n      hatch(SX0, TOP, SX1 - SX0, AX + PR + 18 - TOP, 1, 0.16);\n      ctx.save(); rr(SX0, TOP, SX1 - SX0, AX + PR + 18 - TOP, 14); ctx.clip();\n      const bloom = ctx.createRadialGradient(330, TOP + 20, 10, 330, TOP + 20, 300); bloom.addColorStop(0, \"rgba(255,250,224,0.42)\"); bloom.addColorStop(1, \"rgba(255,250,224,0)\");\n      ctx.fillStyle = bloom; ctx.fillRect(SX0, TOP, SX1 - SX0, 300);\n      // the turned outside of the shell shows as a polished lip top and bottom\n      ctx.fillStyle = lin(0, TOP, 0, TOP + 9, [[0, \"#fff6cf\"], [0.5, \"#e9c877\"], [1, \"#8a651c\"]]); ctx.fillRect(SX0, TOP, SX1 - SX0, 9);\n      ctx.fillStyle = lin(0, AX + PR + 9, 0, AX + PR + 18, [[0, \"#3d2a06\"], [0.4, \"#a37a2a\"], [1, \"#5f4410\"]]); ctx.fillRect(SX0, AX + PR + 9, SX1 - SX0, 9);\n      ctx.fillStyle = lin(0, SH - 12, 0, SH, [[0, \"rgba(50,28,0,0)\"], [1, \"rgba(50,28,0,0.4)\"]]); ctx.fillRect(SX0, SH - 12, SX1 - SX0, 12);\n      ctx.fillStyle = lin(SX1 - 16, 0, SX1, 0, [[0, \"rgba(50,28,0,0)\"], [1, \"rgba(50,28,0,0.45)\"]]); ctx.fillRect(SX1 - 16, TOP, 16, 300);\n      ctx.restore();\n\n      // Pin chambers, each with a lamp above it.\n      for (let i = 0; i < N; i++) {\n        const x = pinX(i), on = s.lamp[i];\n        ctx.fillStyle = lin(x - 12, 0, x + 12, 0, [[0, \"#070504\"], [0.3, \"#1b1409\"], [0.8, \"#241a0b\"], [1, \"#0d0906\"]]); ctx.save(); ctx.shadowColor = \"rgba(40,22,0,0.7)\"; ctx.shadowBlur = 7 * K; rr(x - 12, CH - 4, 24, SH - CH + 5, 3); ctx.fill(); ctx.restore();\n        ctx.fillStyle = \"rgba(255,240,200,0.35)\"; ctx.fillRect(x + 12, CH, 1, SH - CH);\n        ctx.beginPath(); ctx.arc(x, TOP + 12, 4.4, 0, Math.PI * 2); ctx.fillStyle = \"#2a1c05\"; ctx.fill();\n        ctx.save(); ctx.shadowColor = LAMP; ctx.shadowBlur = 14 * on * K; ctx.globalAlpha = 0.12 + 0.88 * on;\n        ctx.beginPath(); ctx.arc(x, TOP + 12, 3.1, 0, Math.PI * 2); ctx.fillStyle = LAMP; ctx.fill(); ctx.restore();\n        ctx.beginPath(); ctx.arc(x - 1, TOP + 11, 0.9, 0, Math.PI * 2); ctx.fillStyle = `rgba(255,255,255,${0.2 + 0.6 * on})`; ctx.fill();\n      }\n\n      // The plug: a redder brass so the line it shears on is easy to find.\n      ctx.fillStyle = lin(0, SH, 0, AX + PR, [[0, \"#e7b872\"], [0.5, \"#c98f47\"], [1, \"#9a6526\"]]); ctx.fillRect(SX0, SH, SX1 - SX0 + 4, PR * 2);\n      hatch(SX0, SH, SX1 - SX0 + 4, PR * 2, -1, 0.14);\n      ctx.fillStyle = lin(0, SH, 0, SH + 14, [[0, \"rgba(50,24,0,0.38)\"], [1, \"rgba(50,24,0,0)\"]]); ctx.fillRect(SX0, SH, SX1 - SX0 + 4, 14);\n      ctx.fillStyle = lin(0, AX + PR - 16, 0, AX + PR, [[0, \"rgba(50,24,0,0)\"], [1, \"rgba(50,24,0,0.45)\"]]); ctx.fillRect(SX0, AX + PR - 16, SX1 - SX0 + 4, 16);\n      ctx.fillStyle = \"rgba(30,16,0,0.85)\"; ctx.fillRect(SX0, SH - 0.9, SX1 - SX0, 1.8); ctx.fillRect(SX0, AX + PR - 0.7, SX1 - SX0, 1.4);\n      ctx.save(); ctx.globalAlpha = allSet * allSet; ctx.shadowColor = LAMP; ctx.shadowBlur = 10 * K; ctx.fillStyle = LAMP; ctx.fillRect(SX0 + 6, SH - 0.7, SX1 - SX0 - 12, 1.4); ctx.restore();\n\n      // Everything that lives in the plug turns with it: keyway, lower chambers, key pins and the key.\n      ctx.save(); ctx.translate(0, AX); ctx.scale(1, flat); ctx.translate(0, -AX);\n      ctx.save(); ctx.globalAlpha = inside;\n      ctx.fillStyle = \"#120c05\"; ctx.fillRect(SX0, KT - 3, SX1 - SX0 - 10, KB - KT + 6);\n      for (let i = 0; i < N; i++) { const x = pinX(i); ctx.fillStyle = lin(x - 12, 0, x + 12, 0, [[0, \"#070504\"], [0.3, \"#1b1409\"], [0.8, \"#241a0b\"], [1, \"#0d0906\"]]); ctx.fillRect(x - 12, SH + 1, 24, KT - SH); }\n      ctx.restore();\n\n      // The key.\n      ctx.save(); ctx.translate(s.kx, 0);\n      const metal = lin(0, AX - 70, 0, AX + 76, [[0, \"#fbfcfc\"], [0.12, \"#d5dade\"], [0.5, \"#a3aab1\"], [0.86, \"#70767d\"], [1, \"#3f4348\"]]);\n      shadow(() => { rr(58, AX - 60, 164, 134, 56); ctx.fill(); }, 16, 5, 9, 0.55);\n      ctx.fillStyle = metal;\n      rr(58, AX - 60, 164, 134, 56); ctx.fill(); ctx.fillRect(206, KT, 50, KB - KT);\n      ctx.beginPath(); ctx.moveTo(250, KT);\n      for (let x = 252; x <= 588; x += 2) ctx.lineTo(x, KT + depth(x));\n      ctx.lineTo(598, KT + 22); ctx.lineTo(608, KT + 38); ctx.lineTo(596, KB); ctx.lineTo(250, KB); ctx.closePath(); ctx.fill();\n      // bright milled edge along the cuts, two long grooves, bevel round the bow\n      ctx.beginPath(); ctx.moveTo(252, KT + 0.8); for (let x = 252; x <= 588; x += 2) ctx.lineTo(x, KT + depth(x) + 0.8); ctx.lineTo(598, KT + 22.8);\n      ctx.strokeStyle = \"rgba(255,255,255,0.7)\"; ctx.lineWidth = 1; ctx.stroke();\n      for (const gy of [KT + 34, KT + 45]) { ctx.fillStyle = \"rgba(20,24,28,0.5)\"; ctx.fillRect(236, gy, 362, 1.6); ctx.fillStyle = \"rgba(255,255,255,0.55)\"; ctx.fillRect(236, gy + 1.6, 362, 1); }\n      ctx.fillStyle = \"rgba(20,22,26,0.35)\"; ctx.fillRect(250, KB - 2, 346, 2);\n      ctx.save(); rr(58, AX - 60, 164, 134, 56); ctx.clip();\n      ctx.fillStyle = lin(70, AX - 60, 200, AX + 74, [[0, \"rgba(255,255,255,0)\"], [0.3, \"rgba(255,255,255,0.42)\"], [0.4, \"rgba(255,255,255,0.06)\"], [0.62, \"rgba(255,255,255,0)\"], [0.72, \"rgba(255,255,255,0.2)\"], [0.8, \"rgba(255,255,255,0)\"], [1, \"rgba(0,0,0,0.22)\"]]); ctx.fillRect(58, AX - 60, 164, 134);\n      ctx.restore();\n      ctx.lineWidth = 2; ctx.strokeStyle = \"rgba(255,255,255,0.7)\"; rr(60, AX - 58, 160, 130, 54); ctx.stroke();\n      ctx.lineWidth = 1.2; ctx.strokeStyle = \"rgba(30,34,40,0.4)\"; rr(69, AX - 49, 142, 112, 46); ctx.stroke();\n      ctx.strokeStyle = \"rgba(255,255,255,0.5)\"; rr(70, AX - 48, 140, 110, 45); ctx.stroke();\n      ctx.beginPath(); ctx.arc(100, AX + 7, 17, 0, Math.PI * 2); ctx.fillStyle = \"#0e1110\"; ctx.fill();\n      ctx.lineWidth = 2.4; ctx.strokeStyle = \"rgba(40,44,50,0.9)\"; ctx.stroke();\n      ctx.beginPath(); ctx.arc(100, AX + 7, 18.6, 0.2, Math.PI * 0.9); ctx.lineWidth = 1.3; ctx.strokeStyle = \"rgba(255,255,255,0.85)\"; ctx.stroke();\n      ctx.font = \"700 13px ui-monospace, SFMono-Regular, Menlo, monospace\"; ctx.textAlign = \"center\"; ctx.textBaseline = \"middle\";\n      ctx.fillStyle = \"rgba(255,255,255,0.7)\"; ctx.fillText(`${N} PIN`, 163, AX + 8.9); ctx.fillStyle = \"rgba(38,42,48,0.85)\"; ctx.fillText(`${N} PIN`, 163, AX + 8);\n      ctx.restore();\n\n      // Key pins ride on the cuts.\n      const lift = Math.max(0, s.hop);\n      const tops: number[] = [];\n      for (let i = 0; i < N; i++) {\n        const x = pinX(i), len = 30 + CUTS[i], tip = KT + s.cut[i] - lift * (3 + (i % 3) * 2), top = tip - len;\n        tops.push(top);\n        ctx.save(); ctx.globalAlpha = inside;\n        ctx.beginPath(); ctx.moveTo(x - 10, top + 2); ctx.quadraticCurveTo(x - 10, top, x - 8, top); ctx.lineTo(x + 8, top); ctx.quadraticCurveTo(x + 10, top, x + 10, top + 2);\n        ctx.lineTo(x + 10, tip - 9); ctx.lineTo(x + 3, tip); ctx.lineTo(x - 3, tip); ctx.lineTo(x - 10, tip - 9); ctx.closePath();\n        ctx.fillStyle = lin(x - 10, 0, x + 10, 0, STEEL); ctx.fill();\n        ctx.fillStyle = \"rgba(0,0,0,0.28)\"; ctx.fillRect(x - 10, tip - 10.5, 20, 1.5);\n        ctx.restore();\n      }\n      ctx.restore();\n\n      // Drivers and springs stay in the shell. A driver that straddles the line is what stops the plug.\n      for (let i = 0; i < N; i++) {\n        const x = pinX(i), bottom = turned > 0.02 ? SH : tops[i], top = bottom - 36;\n        const coils = 6, span = top - (CH + 2);\n        ctx.lineWidth = 2.3;\n        for (let j = 0; j < coils; j++) {\n          const y0 = CH + 2 + (span * j) / coils, y1 = CH + 2 + (span * (j + 0.5)) / coils, y2 = CH + 2 + (span * (j + 1)) / coils;\n          ctx.strokeStyle = \"#4d525a\"; ctx.beginPath(); ctx.moveTo(x + 9, y1); ctx.lineTo(x - 9, y2); ctx.stroke();\n          ctx.strokeStyle = \"#e8ecef\"; ctx.beginPath(); ctx.moveTo(x - 9, y0); ctx.lineTo(x + 9, y1); ctx.stroke();\n        }\n        rr(x - 10, top, 20, 36, 2.5); ctx.fillStyle = lin(x - 10, 0, x + 10, 0, COPPER); ctx.fill();\n        ctx.fillStyle = \"rgba(255,255,255,0.35)\"; ctx.fillRect(x - 9, top + 0.6, 18, 1);\n        ctx.fillStyle = \"rgba(0,0,0,0.3)\"; ctx.fillRect(x - 10, bottom - 2, 20, 2);\n      }\n\n      // A slow band of light crossing the brass keeps the still lock alive.\n      if (s.glint >= 0) {\n        const gx = SX0 - 160 + s.glint * (SX1 - SX0 + 320);\n        ctx.save(); rr(SX0, TOP, SX1 - SX0, AX + PR + 18 - TOP, 14); ctx.clip(); ctx.globalCompositeOperation = \"lighter\";\n        ctx.fillStyle = lin(gx - 70, 0, gx + 70, 60, [[0, \"rgba(255,244,210,0)\"], [0.5, \"rgba(255,244,210,0.2)\"], [1, \"rgba(255,244,210,0)\"]]); ctx.fillRect(SX0, TOP, SX1 - SX0, 320); ctx.restore();\n      }\n\n      // Collar where the plug meets the door.\n      rr(SX0 - 16, TOP - 8, 18, AX + PR + 34 - TOP, 5);\n      ctx.fillStyle = lin(SX0 - 16, 0, SX0 + 2, 0, [[0, \"#6f5118\"], [0.25, \"#f6dfa0\"], [0.5, \"#d2aa52\"], [1, \"#7d5c1c\"]]); ctx.fill();\n      ctx.fillStyle = \"#0e0a05\"; ctx.fillRect(SX0 - 16, AX - Math.max(3, 31 * flat), 18, Math.max(6, 62 * flat));\n    };\n\n    let raf = 0, last = 0, t0 = 0, seen = true, demo = !reduce, at = 3600, idx = DEMO.length, pulse = -1, bolted = metRef.current.every(Boolean);\n    const snap = () => {\n      const all = metRef.current.every(Boolean);\n      s.cut = metRef.current.map((m, i) => (m ? CUTS[i] : 0)); s.turn = 0; s.bolt = all ? 1 : 0; s.lamp = metRef.current.map((m) => (m ? 1 : 0)); s.hop = 0; s.kx = 0; draw();\n    };\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, m = metRef.current, all = m.every(Boolean);\n      let settled = true;\n      for (let i = 0; i < N; i++) {\n        const want = s.turn > 0.12 || m[i] ? CUTS[i] : 0;\n        s.cutV[i] += (300 * (want - s.cut[i]) - 15 * s.cutV[i]) * dt; s.cut[i] += s.cutV[i] * dt;\n        if (Math.abs(want - s.cut[i]) > 0.8) settled = false;\n        s.lamp[i] += ((m[i] ? 1 : 0) - s.lamp[i]) * Math.min(1, dt * 12);\n      }\n      // Once every stack agrees the key makes one quarter turn, throws the bolt and comes back upright.\n      if (all && settled && !bolted && pulse < 0) pulse = t + 1150;\n      if (!all) { bolted = false; if (pulse > t) pulse = t; }\n      if (pulse > 0 && s.turn > 0.9) bolted = true;\n      if (pulse > 0 && t >= pulse && s.turn < 0.04) pulse = -1;\n      s.turnV += (80 * ((pulse > t ? 1 : 0) - s.turn) - 15 * s.turnV) * dt; s.turn += s.turnV * dt;\n      s.boltV += (150 * ((bolted ? 1 : 0) - s.bolt) - 15 * s.boltV) * dt; s.bolt += s.boltV * dt;\n      s.glint = ((t + 2600) % 5200) / 2400; if (s.glint > 1) s.glint = -1;\n      s.hopV += (-420 * s.hop - 16 * s.hopV) * dt; s.hop += s.hopV * dt;\n      s.kxV += (-600 * s.kx - 30 * s.kxV) * dt; s.kx += s.kxV * dt;\n      if (demo && t > at) {\n        if (idx >= DEMO.length) { idx = 0; type(\"\"); setValue(\"\"); at = t + 1300; }\n        else { idx += 1; const v = DEMO.slice(0, idx); type(v); setValue(v); at = t + (idx >= DEMO.length ? 5200 : 150); }\n      }\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 type = (v: string) => {\n      metRef.current = check(v);\n      if (reduce) { snap(); return; }\n      if (s.turn < 0.2) { s.hopV = 26; s.kxV = 90; }\n      wake();\n    };\n    const size = () => {\n      const w = box.clientWidth, dpr = Math.min(2, window.devicePixelRatio || 1);\n      cv.width = Math.round(w * dpr); cv.height = Math.round((w * H) / W * dpr); K = cv.width / W; draw();\n    };\n    const ro = new ResizeObserver(size); ro.observe(box); size();\n    api.current = { type, stop: () => { const was = demo; demo = false; return was; } };\n    wake();\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; ro.disconnect(); io.disconnect(); document.removeEventListener(\"visibilitychange\", onVis); };\n  }, []);\n\n  const change = (v: string) => { api.current?.stop(); setValue(v); api.current?.type(v); };\n\n  return (\n    <div className=\"flex min-h-[640px] w-full flex-col items-center justify-center bg-[#0e1110] bg-[radial-gradient(80%_60%_at_50%_36%,#222926_0%,#0e1110_70%)] px-4 py-10 sm:min-h-[720px]\">\n      <div ref={wrap} className=\"w-full max-w-[860px]\" style={{ aspectRatio: `${W} / ${H}` }}>\n        <canvas ref={canvas} aria-hidden=\"true\" className=\"h-full w-full\" />\n      </div>\n      <form className=\"mt-4 w-full max-w-[420px]\" onSubmit={(e) => e.preventDefault()}>\n        <label htmlFor={id} className=\"block font-mono text-[11px] font-semibold uppercase tracking-[0.2em] text-stone-300\">New password</label>\n        <div className=\"mt-2 flex items-stretch rounded-lg border border-[#3a3324] bg-[#171a18] focus-within:border-[#d9b35c] focus-within:ring-1 focus-within:ring-[#d9b35c]\">\n          <input\n            id={id}\n            type={show ? \"text\" : \"password\"}\n            value={value}\n            onFocus={() => { if (api.current?.stop()) change(\"\"); }}\n            onChange={(e) => change(e.target.value)}\n            autoComplete=\"new-password\"\n            spellCheck={false}\n            aria-describedby={`${id}-state`}\n            className=\"h-12 min-w-0 flex-1 rounded-l-lg bg-transparent px-4 font-mono text-[16px] tracking-[0.08em] text-stone-100 outline-none placeholder:text-stone-500\"\n            placeholder=\"Type to cut the key\"\n          />\n          <button type=\"button\" aria-pressed={show} onClick={() => setShow((v) => !v)} className=\"rounded-r-lg px-4 font-mono text-[11px] font-semibold uppercase tracking-[0.16em] text-[#e3c070] outline-none hover:text-[#f6e3ab] focus-visible:ring-2 focus-visible:ring-[#d9b35c]\">\n            {show ? \"Hide\" : \"Show\"}\n          </button>\n        </div>\n        <ul className=\"mt-3 flex flex-wrap gap-x-4 gap-y-1.5\">\n          {rules.map((r, i) => (\n            <li key={r.label} className={`flex items-center gap-2 font-mono text-[11px] uppercase tracking-[0.12em] transition-colors duration-300 motion-reduce:transition-none ${met[i] ? \"text-stone-100\" : \"text-stone-400\"}`}>\n              <span aria-hidden=\"true\" className=\"h-1.5 w-1.5 rounded-full transition-colors duration-300 motion-reduce:transition-none\" style={{ backgroundColor: met[i] ? LAMP : \"#4a4f4c\" }} />\n              {r.label}\n              <span className=\"sr-only\">{met[i] ? \", done\" : \", still needed\"}</span>\n            </li>\n          ))}\n        </ul>\n        <p id={`${id}-state`} aria-live=\"polite\" className=\"mt-4 font-mono text-[11px] uppercase leading-5 tracking-[0.16em] text-stone-400\">\n          <span className=\"font-semibold text-stone-100\">{count} of {N} pins set</span>\n          <span className=\"mx-2 text-stone-600\">/</span>\n          {strong ? \"Bolt thrown\" : \"A driver still blocks the line\"}\n        </p>\n      </form>\n    </div>\n  );\n}\n"}]}
