{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "rotor-window-bank",
  "title": "Rotor Window Bank",
  "description": "Full-bleed hero backdrop modeled on a rotor cipher machine's stepping mechanism: three letter-wheel windows where the right wheel ticks steadily, kicks the middle wheel once per revolution, and the middle wheel occasionally double-steps, moving twice in one beat and dragging the left wheel with it, the real Enigma-family stepping anomaly compressed to a 9-position ring so it recurs roughly every minute instead of every eleven.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/loud/rotor-window-bank/component.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useId, useRef } from \"react\";\n\n// ---------------------------------------------------------------------------\n// RotorWindowBank — a full-bleed ambient hero backdrop modeled on the rotor\n// stepping mechanism of an electromechanical rotor cipher machine\n// (Enigma-family), not the electrical scrambling it fed. Three letter-wheel\n// windows sit side by side; a pawl advances the right wheel one position on\n// a fixed tick, and when the right wheel completes a full revolution it\n// kicks the middle wheel forward. The middle wheel carries the historical\n// \"double-step\" anomaly: if the middle wheel is itself sitting on one of its\n// own notch positions at the instant it would be kicked, it steps TWICE that\n// beat and also drags the left wheel forward with it — the mechanical quirk\n// that gave the real machine a period of 26x25x26 instead of a clean 26^3.\n//\n// COMPRESSED, NOT LITERAL. The real ring is 26 positions; a double-step on a\n// single-notch 26-ring machine recurs roughly once every 676 ticks (~11\n// minutes at 1 tick/s) — invisible at showpiece timescales. This component\n// compresses the ring to RING=9 positions and gives the middle wheel TWO\n// notches (0 and 4, an uneven split) so the double-step — the entire reason\n// this mechanism is interesting to look at — recurs roughly every 50-65s\n// instead. Ring size and notch count are a stated departure from the\n// historical 26-position, single-notch rotor, not a fidelity claim.\n//\n// Positions are driven by a small event-queue simulation, not CSS\n// `animation: infinite`: the right wheel's position is a pure function of\n// elapsed sim time (deterministic, replayable), while the middle and left\n// wheels only move in response to discrete \"kick\" events computed\n// incrementally as the right wheel's tick counter crosses each multiple of\n// RING. This lets the double-step choreography (two 220ms steps with a 90ms\n// hold between them, then a delayed left-wheel kick) be scheduled exactly\n// once per event rather than re-derived from scratch every frame.\n//\n// Direct-DOM rAF: no React state on the hot path. Every wheel's three\n// visible glyph rows are plain refs; transform/opacity are written straight\n// to style each frame. Colour comes entirely from Tailwind classes bound to\n// the --background/--foreground/--border tokens (currentColor + opacity),\n// so theme flips repaint for free with zero JS token reads — there is\n// nothing here that touches canvas or a shader, so no getComputedStyle pass\n// is needed at all.\n// ---------------------------------------------------------------------------\n\nexport interface RotorWindowBankProps {\n  className?: string;\n  style?: React.CSSProperties;\n}\n\nconst RING = 9; // compressed from the historical 26-position ring\nconst GLYPHS = [\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", \"I\"];\nconst MIDDLE_NOTCHES = [0, 4]; // two notches (vs. the historical single notch)\nconst TICK_MS = 1400; // right wheel: 1 tick / 1.4s\nconst STEP_MS = 220; // single-wheel step transition\nconst HOLD_MS = 90; // hold between a double-step's two moves\n\n// The frozen reduced-motion frame: right wheel at position 4, middle wheel\n// one tick past a notch, left wheel one position advanced — the frame that\n// shows all three wheels having just moved relative to each other, not the\n// default single-wheel idle state.\nconst STATIC_RIGHT = 4;\nconst STATIC_MIDDLE = 1;\nconst STATIC_LEFT = 1;\n\nfunction easeOutCubic(t: number): number {\n  const c = Math.max(0, Math.min(1, t));\n  return 1 - Math.pow(1 - c, 3);\n}\n\ninterface QueueEvent {\n  atMs: number;\n  fromPos: number;\n  toPos: number;\n}\n\n/** Advance a settled-position + pending-transition queue and return the\n * current continuous position (integer part = ring position, fractional\n * part = in-flight transition progress). Committing an event pops it and\n * updates settledPos in place; a queue can hold at most two entries (the\n * two halves of a double-step) so this never grows unbounded. */\nfunction stepQueue(\n  queue: QueueEvent[],\n  settledPos: { current: number },\n  simMs: number\n): number {\n  while (queue.length && queue[0].atMs + STEP_MS <= simMs) {\n    settledPos.current = queue[0].toPos;\n    queue.shift();\n  }\n  if (queue.length && queue[0].atMs <= simMs) {\n    const ev = queue[0];\n    const frac = easeOutCubic((simMs - ev.atMs) / STEP_MS);\n    return ev.fromPos + (ev.toPos - ev.fromPos) * frac;\n  }\n  return settledPos.current;\n}\n\n/** Row centring weight for a row at relative index r (0,1,2 = base-1,base,\n * base+1) given continuous position frac (0..1 into the current step). */\nfunction centerness(r: number, frac: number): number {\n  return Math.max(0, 1 - Math.abs(1 + frac - r));\n}\n\ninterface WheelRows {\n  rows: HTMLDivElement[]; // exactly 3, relative index -1, 0, +1\n}\n\n// Window is 1.6 row-heights tall so the neighbour above/below the centred\n// glyph peeks in at its edges (the \"next glyph creeping into frame\" cue).\n// Row r's own height equals one row-height, so translateY in % of its own\n// box is resolution-independent — no px math needed in JS.\nfunction paintWheel(wheel: WheelRows | null, continuousPos: number) {\n  if (!wheel) return;\n  const base = Math.floor(continuousPos);\n  const frac = continuousPos - base;\n  for (let r = 0; r < 3; r++) {\n    const el = wheel.rows[r];\n    if (!el) continue;\n    const ringIndex = (((base - 1 + r) % RING) + RING) % RING;\n    const glyph = GLYPHS[ringIndex];\n    if (el.textContent !== glyph) el.textContent = glyph;\n    const w = centerness(r, frac);\n    el.style.opacity = String(0.35 + 0.55 * w);\n    el.style.transform = `translateY(${(r - 0.7 - frac) * 100}%)`;\n  }\n}\n\nexport function RotorWindowBank({ className = \"\", style }: RotorWindowBankProps) {\n  const uid = useId();\n  const wrapRef = useRef<HTMLDivElement>(null);\n  const stripRefs = useRef<(HTMLDivElement | null)[]>([null, null, null]);\n  const rightRows = useRef<(HTMLDivElement | null)[]>([null, null, null]);\n  const middleRows = useRef<(HTMLDivElement | null)[]>([null, null, null]);\n  const leftRows = useRef<(HTMLDivElement | null)[]>([null, null, null]);\n\n  useEffect(() => {\n    const wrap = wrapRef.current;\n    if (!wrap) return;\n\n    let disposed = false;\n    let running = false;\n    let raf = 0;\n    let lastMs = 0;\n    // Random phase offset so a fresh mount never lands on a clean idle\n    // state — the loop is already \"mid-machine\" from the first frame.\n    let simMs = Math.random() * TICK_MS;\n\n    const middleQueue: QueueEvent[] = [];\n    const leftQueue: QueueEvent[] = [];\n    const middleSettled = { current: 0 };\n    const leftSettled = { current: 0 };\n    let middleStepsCum = 0;\n    let leftStepsCum = 0;\n    let kicksProcessed = 0;\n    let lastTickIndex = -1;\n\n    const processKicks = (tickIndex: number) => {\n      const kicksNow = Math.floor(tickIndex / RING);\n      while (kicksProcessed < kicksNow) {\n        kicksProcessed++;\n        const kickTickIndex = kicksProcessed * RING;\n        const kickAtMs = kickTickIndex * TICK_MS;\n        const beforePos = middleStepsCum % RING;\n        const isDouble = MIDDLE_NOTCHES.includes(beforePos);\n\n        middleQueue.push({ atMs: kickAtMs, fromPos: middleStepsCum, toPos: middleStepsCum + 1 });\n        middleStepsCum += 1;\n\n        if (isDouble) {\n          const secondAt = kickAtMs + STEP_MS + HOLD_MS;\n          middleQueue.push({ atMs: secondAt, fromPos: middleStepsCum, toPos: middleStepsCum + 1 });\n          middleStepsCum += 1;\n\n          const leftAt = secondAt + STEP_MS; // after the middle wheel's second step lands\n          leftQueue.push({ atMs: leftAt, fromPos: leftStepsCum, toPos: leftStepsCum + 1 });\n          leftStepsCum += 1;\n        }\n      }\n    };\n\n    const draw = (ms: number) => {\n      const tickIndex = Math.floor(ms / TICK_MS);\n      if (tickIndex !== lastTickIndex) {\n        processKicks(tickIndex);\n        lastTickIndex = tickIndex;\n      }\n      const tLocal = ms - tickIndex * TICK_MS;\n      const rightPos =\n        tLocal < STEP_MS\n          ? tickIndex - 1 + easeOutCubic(tLocal / STEP_MS)\n          : tickIndex;\n      const middlePos = stepQueue(middleQueue, middleSettled, ms);\n      const leftPos = stepQueue(leftQueue, leftSettled, ms);\n\n      paintWheel({ rows: rightRows.current as HTMLDivElement[] }, rightPos);\n      paintWheel({ rows: middleRows.current as HTMLDivElement[] }, middlePos);\n      paintWheel({ rows: leftRows.current as HTMLDivElement[] }, leftPos);\n    };\n\n    const drawStatic = () => {\n      paintWheel({ rows: leftRows.current as HTMLDivElement[] }, STATIC_LEFT);\n      paintWheel({ rows: middleRows.current as HTMLDivElement[] }, STATIC_MIDDLE);\n      paintWheel({ rows: rightRows.current as HTMLDivElement[] }, STATIC_RIGHT);\n    };\n\n    let staticMode = false;\n\n    const loopFrame = (now: number) => {\n      if (!running) return;\n      if (!lastMs) lastMs = now;\n      const dt = Math.min(100, now - lastMs); // clamp so a tab-switch gap can't leap the sim\n      lastMs = now;\n      simMs += dt;\n      draw(simMs);\n      raf = requestAnimationFrame(loopFrame);\n    };\n\n    const wake = () => {\n      if (running || disposed || staticMode) return;\n      running = true;\n      lastMs = 0;\n      raf = requestAnimationFrame(loopFrame);\n    };\n    const sleep = () => {\n      running = false;\n      if (raf) cancelAnimationFrame(raf);\n      raf = 0;\n    };\n\n    // Paint synchronously before anything async (rAF, observers) can run so\n    // there is never a blank first frame while waiting on the loop to wake.\n    draw(simMs);\n\n    const mq = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    const applyMode = () => {\n      if (mq.matches) {\n        staticMode = true;\n        sleep();\n        drawStatic();\n      } else {\n        staticMode = false;\n        wake();\n      }\n    };\n    const onMq = () => applyMode();\n    mq.addEventListener(\"change\", onMq);\n\n    let onScreen = true;\n    const io = new IntersectionObserver(\n      (entries) => {\n        onScreen = entries.some((en) => en.isIntersecting);\n        if (!onScreen) sleep();\n        else if (!staticMode && !document.hidden) wake();\n      },\n      { threshold: 0 }\n    );\n    io.observe(wrap);\n\n    const onVis = () => {\n      if (document.hidden) sleep();\n      else if (!staticMode && onScreen) wake();\n    };\n    document.addEventListener(\"visibilitychange\", onVis);\n\n    // Geometry derives from the container's smaller dimension so this reads\n    // correctly at card scale, not only full-bleed.\n    const applySize = () => {\n      const rect = wrap.getBoundingClientRect();\n      const base = Math.max(1, Math.min(rect.width, rect.height));\n      const rowH = base / 5;\n      wrap.style.setProperty(\"--rotor-row-h\", `${rowH}px`);\n    };\n    const ro = new ResizeObserver(applySize);\n    ro.observe(wrap);\n    applySize();\n\n    applyMode();\n\n    return () => {\n      disposed = true;\n      sleep();\n      ro.disconnect();\n      io.disconnect();\n      mq.removeEventListener(\"change\", onMq);\n      document.removeEventListener(\"visibilitychange\", onVis);\n    };\n  }, []);\n\n  const wheel = (rowsRef: React.MutableRefObject<(HTMLDivElement | null)[]>, key: string) => (\n    <div\n      className=\"relative overflow-hidden\"\n      style={{ width: \"calc(var(--rotor-row-h) * 0.9)\", height: \"calc(var(--rotor-row-h) * 1.6)\" }}\n    >\n      {[0, 1, 2].map((r) => (\n        <div\n          key={`${key}-${r}`}\n          ref={(el) => {\n            rowsRef.current[r] = el;\n          }}\n          className=\"absolute inset-x-0 top-0 flex items-center justify-center font-mono text-foreground\"\n          style={{\n            height: \"var(--rotor-row-h)\",\n            fontSize: \"calc(var(--rotor-row-h) * 0.55)\",\n          }}\n        />\n      ))}\n    </div>\n  );\n\n  return (\n    <div\n      ref={wrapRef}\n      data-rotor-window-bank={uid}\n      aria-hidden=\"true\"\n      className={`relative flex h-full w-full items-center justify-center gap-[calc(var(--rotor-row-h)*0.35)] overflow-hidden bg-background ${className}`}\n      style={{ ...style, [\"--rotor-row-h\" as string]: \"48px\" }}\n    >\n      <div className=\"flex items-stretch divide-x divide-border border border-border\">\n        <div className=\"p-[calc(var(--rotor-row-h)*0.25)]\">{wheel(leftRows, \"left\")}</div>\n        <div className=\"p-[calc(var(--rotor-row-h)*0.25)]\">{wheel(middleRows, \"middle\")}</div>\n        <div className=\"p-[calc(var(--rotor-row-h)*0.25)]\">{wheel(rightRows, \"right\")}</div>\n      </div>\n    </div>\n  );\n}\n\nRotorWindowBank.displayName = \"RotorWindowBank\";\n",
      "type": "registry:ui",
      "target": "components/ui/rotor-window-bank.tsx"
    }
  ],
  "meta": {
    "collection": "loud",
    "tags": [
      "hero",
      "background",
      "rotor",
      "cipher-machine",
      "dom",
      "ambient",
      "mechanical"
    ],
    "instruction": "Build a full-bleed DOM-only (no canvas/WebGL) hero backdrop showing three rotor-machine letter-wheel windows side by side (left, middle, right), each an overflow-hidden window 1.6 row-heights tall over a 3-row glyph strip, row-height = min(containerWidth, containerHeight) / 5 recomputed on a ResizeObserver so it reads at card scale as well as full-bleed. RING=9 positions per wheel cycling glyphs A-I (compressed from the historical 26-position Enigma-family ring, documented in a code comment as a stated departure, not a fidelity claim). MOTION: the right wheel advances one position every TICK_MS=1400ms via a 220ms ease-out-cubic step transition then holds; every 9th right-wheel tick (one full revolution) it kicks the middle wheel forward one position. The middle wheel carries TWO notches (positions 0 and 4 of its own 9-position ring, an uneven split so the interval between recurrences is irregular, not a fixed multiple): if the middle wheel sits on either notch at the instant it would be kicked, that beat plays as a double-step instead of a single step — two back-to-back 220ms transitions with a 90ms hold between them (the middle wheel visibly moves, pauses, moves again), and a left-wheel kick (its own 220ms step) fires starting immediately after the middle wheel's second step transition completes, never simultaneously with it. With these numbers the double-step recurs roughly every 50-65s (alternating 4-kick and 5-kick gaps at 12.6s/kick), which is the entire visible point of the mechanism, so DO NOT compress the ring further or the anomaly stops reading as an event. Drive all three wheels from a single rAF loop accumulating real elapsed ms into a `simMs` counter (dt clamped to 100ms so a tab-switch gap can't skip ticks); the right wheel's position is a pure function of simMs, while the middle/left wheels are driven by a small per-wheel queue of at most two pending step events, computed incrementally exactly once each time the right wheel's tick counter crosses a multiple of 9 (never recomputed from t=0, so this stays cheap over an arbitrarily long mount). RENDERING: each wheel's 3 rows are refs updated with direct style writes (textContent, opacity, transform: translateY in % of the row's own height, formula `(r - 0.7 - frac) * 100` for relative row index r in {0,1,2} and continuous fractional step position frac) — zero React state on the hot path. Row opacity = 0.35 + 0.55 * max(0, 1 - |1 + frac - r|), giving the centred glyph ~0.9 opacity and the peeking neighbours above/below ~0.35, crossfading continuously through a step rather than a hard cut. On mount, simMs starts at a random offset in [0, 1400) so a fresh load never lands on a clean idle frame, and draw(simMs) is called synchronously before the rAF loop starts so there is no blank first frame. COLOUR: every visible surface uses Tailwind classes bound to --background/--foreground/--border tokens (text-foreground for glyphs, border-border/divide-border for the wheel-window frame and dividers, bg-background for the field) — no JS colour reads needed since this is pure DOM/CSS, no accent anywhere (this is a non-interactive ambient background). LIFECYCLE: pause the rAF loop via IntersectionObserver (threshold 0) when scrolled offscreen and on document visibilitychange when hidden, resuming exactly where simMs left off; disconnect every observer and cancel the rAF on unmount. REDUCED MOTION: a `prefers-reduced-motion` matchMedia listener freezes on STATIC_RIGHT=4, STATIC_MIDDLE=1, STATIC_LEFT=1 (the frame right after a double-step resolves, showing all three wheels having just moved relative to one another) with no rAF running at all. The whole element is `aria-hidden` and non-interactive; no click/hover affordance of any kind."
  },
  "type": "registry:ui"
}