{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "footer-ascii-rule",
  "title": "Footer ASCII Rule",
  "description": "A sitemap footer whose back-to-top control is a real instrument: an aria-hidden vertical rail beside it continuously reads actual scroll position, and the button drives a real spring back to the top rather than a jump. Grabbing the wheel mid-flight yields it immediately.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/core/footer-ascii-rule/component.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useRef } from \"react\";\n\n// ---------------------------------------------------------------------------\n// FooterAsciiRule — a footer whose \"back to top\" control is an honest\n// instrument, not a decoration: an aria-hidden vertical rail beside the\n// copyright line always reads real, continuous scroll position (a passive\n// scroll listener, not a fixed-duration animation on its own clock), and its\n// button drives a real semi-implicit-Euler spring toward scrollY=0 rather\n// than a native instant jump or CSS smooth-scroll. Because the rail's\n// position comes from window.scrollY every frame, a user who grabs the\n// wheel or a key mid-flight sees the car respond to what they're actually\n// doing — and the flight itself is cancelled the instant that happens,\n// rather than fighting the user for control of the page.\n// ---------------------------------------------------------------------------\n\nconst RAIL_ROWS = 6;\nconst SPRING_K = 120;\nconst SPRING_C = 22;\nconst SETTLE_POS_EPS = 0.6;\nconst SETTLE_VEL_EPS = 4;\nconst SETTLE_MS = 2500;\n\nexport interface FooterLinkItem {\n  label: string;\n  href: string;\n}\n\nexport interface FooterColumn {\n  heading: string;\n  links: FooterLinkItem[];\n}\n\nexport interface FooterAsciiRuleProps {\n  /** brand text on the left */\n  brand?: string;\n  /** the footer's link columns */\n  columns: FooterColumn[];\n  /** extra classes merged onto the rendered root element */\n  className?: string;\n}\n\nexport function FooterAsciiRule({ brand = \"ns-ui\", columns, className = \"\" }: FooterAsciiRuleProps) {\n  const railRef = useRef<HTMLPreElement>(null);\n  const buttonRef = useRef<HTMLButtonElement>(null);\n  const flightRef = useRef<{ raf: number; cancel: () => void } | null>(null);\n\n  // -- honest readout: the rail always reflects real scroll, all the time --\n  useEffect(() => {\n    const rail = railRef.current;\n    if (!rail) return;\n\n    const paint = () => {\n      const doc = document.documentElement;\n      const max = Math.max(1, doc.scrollHeight - window.innerHeight);\n      const progress = Math.min(1, Math.max(0, window.scrollY / max));\n      // progress 0 (at top) -> car at row 0; progress 1 (scrolled away) -> car at last row\n      const carRow = Math.round(progress * (RAIL_ROWS - 1));\n      const lines: string[] = [];\n      for (let i = 0; i < RAIL_ROWS; i++) lines.push(i === carRow ? \"●\" : \"│\");\n      rail.textContent = lines.join(\"\\n\");\n    };\n\n    let ticking = false;\n    const onScroll = () => {\n      if (ticking) return;\n      ticking = true;\n      requestAnimationFrame(() => {\n        ticking = false;\n        paint();\n      });\n    };\n    paint();\n    window.addEventListener(\"scroll\", onScroll, { passive: true });\n    window.addEventListener(\"resize\", onScroll);\n    return () => {\n      window.removeEventListener(\"scroll\", onScroll);\n      window.removeEventListener(\"resize\", onScroll);\n    };\n  }, []);\n\n  useEffect(() => {\n    return () => flightRef.current?.cancel();\n  }, []);\n\n  const backToTop = () => {\n    flightRef.current?.cancel();\n\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    if (reduced) {\n      window.scrollTo(0, 0);\n      return;\n    }\n\n    let y = window.scrollY;\n    let v = 0;\n    const deadline = performance.now() + SETTLE_MS;\n    let raf = 0;\n    let cancelled = false;\n\n    const stopInterrupt = () => {\n      window.removeEventListener(\"wheel\", onInterrupt);\n      window.removeEventListener(\"touchstart\", onInterrupt);\n      window.removeEventListener(\"keydown\", onKeyInterrupt);\n    };\n    const onInterrupt = () => cancel();\n    const onKeyInterrupt = (e: KeyboardEvent) => {\n      if ([\"ArrowUp\", \"ArrowDown\", \"PageUp\", \"PageDown\", \"Home\", \"End\", \" \"].includes(e.key)) cancel();\n    };\n\n    function cancel() {\n      if (cancelled) return;\n      cancelled = true;\n      cancelAnimationFrame(raf);\n      stopInterrupt();\n      flightRef.current = null;\n    }\n\n    window.addEventListener(\"wheel\", onInterrupt, { passive: true });\n    window.addEventListener(\"touchstart\", onInterrupt, { passive: true });\n    window.addEventListener(\"keydown\", onKeyInterrupt);\n\n    let last = performance.now();\n    const tick = (now: number) => {\n      if (cancelled) return;\n      const dt = Math.min(0.032, (now - last) / 1000);\n      last = now;\n      v += (-SPRING_K * y - SPRING_C * v) * dt;\n      y += v * dt;\n      const settled = Math.abs(y) < SETTLE_POS_EPS && Math.abs(v) < SETTLE_VEL_EPS;\n      if (settled || now >= deadline) {\n        window.scrollTo(0, 0);\n        cancel();\n        return;\n      }\n      window.scrollTo(0, Math.max(0, y));\n      raf = requestAnimationFrame(tick);\n    };\n    raf = requestAnimationFrame(tick);\n    flightRef.current = { raf, cancel };\n  };\n\n  return (\n    <footer data-footer-ascii-rule className={`border-t border-border bg-surface ${className}`}>\n      <div className=\"mx-auto max-w-5xl px-4 py-12 sm:px-6\">\n        <div aria-hidden className=\"select-none font-mono text-[11px] text-border\">\n          {\"─\".repeat(64)}\n        </div>\n\n        <div className=\"mt-8 grid grid-cols-2 gap-8 sm:grid-cols-4\">\n          {columns.map((col) => (\n            <div key={col.heading}>\n              <h2 className=\"font-mono text-xs font-semibold uppercase tracking-[0.15em] text-foreground\">\n                {col.heading}\n              </h2>\n              <ul className=\"mt-3 flex flex-col gap-2\">\n                {col.links.map((link) => (\n                  <li key={link.href}>\n                    <a\n                      href={link.href}\n                      className=\"rounded-sm text-sm text-ns-muted transition-colors hover:text-foreground focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ns-accent\"\n                    >\n                      {link.label}\n                    </a>\n                  </li>\n                ))}\n              </ul>\n            </div>\n          ))}\n        </div>\n\n        <div className=\"mt-10 flex items-center justify-between gap-4 border-t border-border pt-6\">\n          <p className=\"font-mono text-xs text-ns-muted\">\n            © {new Date().getFullYear()} {brand}\n          </p>\n\n          <button\n            ref={buttonRef}\n            type=\"button\"\n            onClick={backToTop}\n            aria-label=\"Back to top\"\n            className=\"group inline-flex items-center gap-2 rounded-sm border border-border px-2.5 py-1.5 font-mono text-xs text-foreground transition-colors hover:border-foreground/25 hover:text-ns-accent focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ns-accent\"\n          >\n            <pre\n              ref={railRef}\n              aria-hidden\n              className=\"pointer-events-none whitespace-pre text-center leading-[1.1] text-ns-muted transition-colors group-hover:text-ns-accent\"\n            />\n            <span>back to top</span>\n          </button>\n        </div>\n      </div>\n    </footer>\n  );\n}\n",
      "type": "registry:ui",
      "target": "components/ui/footer-ascii-rule.tsx"
    }
  ],
  "cssVars": {
    "theme": {
      "color-ns-muted": "var(--ns-muted)",
      "color-ns-accent": "var(--ns-accent)",
      "color-surface": "var(--surface)"
    },
    "light": {
      "ns-muted": "#4d4d4d",
      "ns-accent": "#006bff",
      "surface": "#fafafa"
    },
    "dark": {
      "ns-muted": "#8f8f8f",
      "surface": "#171717"
    }
  },
  "meta": {
    "collection": "core",
    "tags": [
      "footer",
      "sitemap",
      "back-to-top",
      "scroll",
      "spring",
      "ascii",
      "mono"
    ],
    "instruction": "Build <FooterAsciiRule brand? columns className?> where columns is FooterColumn[] ({heading, links: {label, href}[]}). STRUCTURE: a <footer data-footer-ascii-rule> with a static, decorative top rule (a repeated ─ character, aria-hidden — this is house-style dressing, not the mechanic), a responsive grid of sitemap columns (real <a> links, hover text-ns-muted to text-foreground, focus-visible:outline-2 outline-offset-2 outline-ns-accent), and a bottom row holding a copyright line (auto-computed year) and a 'back to top' button. THE MECHANIC — the one only a footer's job (closing the page and offering a way back) makes sense of: a 6-row aria-hidden <pre> rail sits beside the button and renders │ characters with one ● marking the current scroll position, mapped from window.scrollY / (scrollHeight − innerHeight) to a row index. This rail is driven by a passive, rAF-throttled scroll listener that runs continuously and unconditionally — not only while the button is mid-flight — so it is an honest, always-live readout of real scroll position, never a decoration animating on its own clock. Clicking the button does not call scrollIntoView or a native smooth scroll: it starts a semi-implicit-Euler spring (stiffness 120, damping 22, mass 1) seeded at the current scrollY with zero velocity (shortcut taken: release velocity isn't measured here, unlike drawer-counterweight's drag, since there is no drag gesture to sample it from) and integrates it in a requestAnimationFrame loop that calls window.scrollTo(0, y) every frame — which is itself what feeds the rail's existing scroll listener, so the car's motion during the flight is the same code path as at rest, not a duplicate animation. If the user grabs the wheel, touches the screen, or presses an arrow/Home/End/PageUp/PageDown/Space key while the spring is in flight, temporary listeners cancel the animation immediately and hand control back — the page never fights the user for who is scrolling it. The flight force-settles at 2.5s if the spring hasn't converged (a forced deadline, matching the pattern used elsewhere in this registry for spring-driven UI) and snaps to exactly 0 either way. prefers-reduced-motion skips the spring entirely and jumps straight to window.scrollTo(0, 0). Colors are token-only (--border, --foreground, --ns-muted, --ns-accent, --surface) with no hex, including the rail's plain-text glyphs which inherit currentColor from Tailwind text-* classes. Demo page is a real, moderately tall scroll ahead of the footer (not a scripted auto-scroll) so /preview stays the honest interactive reference."
  },
  "type": "registry:ui"
}