{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"hi-vis-nav","type":"registry:component","title":"Hi-Vis Nav","description":"A full-width bar that reads the ground under it, black, safety orange or bone, and swaps its ink and button to match; it tightens after the first scroll.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/hi-vis-nav.tsx","content":"\"use client\";\n\nimport { useEffect, useId, useRef, useState } from \"react\";\nimport type { CSSProperties, RefObject } from \"react\";\n\n\n/** Safety orange as a field colour. Black on it reads at 6.3:1. */\nconst HV_ORANGE = \"#FF5B14\";\n\n/** The hot highlight, for orange marks on black. */\nconst HV_HOT = \"#FF7A1A\";\n\nconst HV_BLACK = \"#0B0A09\";\n\nconst HV_BONE = \"#EFEBE4\";\n\n/**\n * The display face: Archivo's width axis does the shouting (wdth 62..125).\n * Load it as a variable font with the width axis and expose it as --font-hv,\n * e.g. in Next: Archivo({ subsets: [\"latin\"], axes: [\"wdth\"], variable: \"--font-hv\" }).\n */\nconst HV_DISPLAY = 'var(--font-hv, \"Archivo\"), \"Archivo\", \"Arial Narrow\", ui-sans-serif, system-ui, sans-serif';\n\n/** Labels and readouts: Geist Mono as --font-hv-mono (any monospace works). */\nconst HV_MONO = 'var(--font-hv-mono, \"Geist Mono\"), \"Geist Mono\", ui-monospace, \"SFMono-Regular\", Menlo, monospace';\n\n/** Which ground a section sits on; the nav reads it to pick its ink. */\ntype HvGround = \"black\" | \"orange\" | \"bone\";\n\nconst hvReducedSnap = () => typeof window !== \"undefined\" && typeof window.matchMedia === \"function\" && window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n\n/**\n * The scrolling box an element lives in: the nearest ancestor that actually\n * scrolls, or null for the window. Resolved on every frame, because a box only\n * becomes a scroller once its content is taller than it.\n */\nfunction hvScrollParent(el: Element | null): HTMLElement | null {\n  let n = el?.parentElement ?? null;\n  while (n && n !== document.body && n !== document.documentElement) {\n    const oy = getComputedStyle(n).overflowY;\n    if ((oy === \"auto\" || oy === \"scroll\" || oy === \"overlay\") && n.scrollHeight > n.clientHeight + 1) return n;\n    n = n.parentElement;\n  }\n  return null;\n}\n\ninterface HvFrame {\n  /** The element's box, in viewport pixels. */\n  rect: DOMRect;\n  /** The visible part of whatever scrolls it: the scroller's box, or the window. */\n  view: { top: number; height: number; left: number; width: number };\n}\n\n/**\n * Run `apply` with the element's position whenever anything scrolls or\n * resizes, at most once per frame. One capture-phase scroll listener hears\n * every scroller, so the same section works on a page and inside a scrolling\n * preview. `apply` writes to the DOM; nothing here re-renders React.\n */\nfunction useHvScrollFrame<T extends HTMLElement>(ref: RefObject<T | null>, apply: (f: HvFrame) => void) {\n  const applyRef = useRef(apply);\n  useEffect(() => {\n    applyRef.current = apply;\n  });\n  useEffect(() => {\n    let raf = 0;\n    const run = () => {\n      raf = 0;\n      const el = ref.current;\n      if (!el) return;\n      const sp = hvScrollParent(el);\n      const r = sp ? sp.getBoundingClientRect() : null;\n      const view = sp && r ? { top: r.top, height: sp.clientHeight, left: r.left, width: sp.clientWidth } : { top: 0, height: window.innerHeight, left: 0, width: window.innerWidth };\n      applyRef.current({ rect: el.getBoundingClientRect(), view });\n    };\n    const kick = () => {\n      if (!raf) raf = requestAnimationFrame(run);\n    };\n    document.addEventListener(\"scroll\", kick, { capture: true, passive: true });\n    window.addEventListener(\"resize\", kick);\n    const ro = typeof ResizeObserver !== \"undefined\" ? new ResizeObserver(kick) : null;\n    if (ref.current && ro) ro.observe(ref.current);\n    run();\n    return () => {\n      document.removeEventListener(\"scroll\", kick, { capture: true });\n      window.removeEventListener(\"resize\", kick);\n      ro?.disconnect();\n      if (raf) cancelAnimationFrame(raf);\n    };\n  }, [ref]);\n}\n\n/** Links built from props: https, http, mailto, same-site paths and anchors only (tabs and newlines stripped, backslashes refused). */\nfunction hvSafeHref(href: string): string {\n  const h = href.replace(/[\\t\\n\\r]/g, \"\").trim();\n  if (!h || h.includes(String.fromCharCode(92))) return \"#\";\n  if (h.startsWith(\"#\") || (h.startsWith(\"/\") && !h.startsWith(\"//\"))) return h;\n  return /^(https?:|mailto:)/i.test(h) ? h : \"#\";\n}\n\n/** Scroll whatever scrolls the link to a same-page anchor ([data-hv-anchor]); anything else is left to the browser. */\nfunction hvGo(e: { currentTarget: HTMLAnchorElement; preventDefault: () => void }) {\n  const href = e.currentTarget.getAttribute(\"href\") ?? \"\";\n  if (!href.startsWith(\"#\") || href.length < 2) return;\n  const root = e.currentTarget.closest(\"[data-hv-site]\") ?? document;\n  const target = root.querySelector<HTMLElement>('[data-hv-anchor=\"' + CSS.escape(href.slice(1)) + '\"]');\n  if (!target) return;\n  e.preventDefault();\n  const sp = hvScrollParent(target);\n  const smooth: ScrollBehavior = hvReducedSnap() ? \"auto\" : \"smooth\";\n  if (sp) sp.scrollTo({ top: sp.scrollTop + target.getBoundingClientRect().top - sp.getBoundingClientRect().top, behavior: smooth });\n  else window.scrollTo({ top: window.scrollY + target.getBoundingClientRect().top, behavior: smooth });\n}\n\n/**\n * The kit's scoped CSS: one focus ring (2px, offset 3px, in the ink of the\n * ground it sits on), tabular figures, the press, and transitions off for\n * anything a frame loop writes.\n */\nconst HV_CSS =\n  \".hv-scope{--hv-ring:\" + HV_HOT + \"}\" +\n  \".hv-scope[data-hv-ground=orange],.hv-scope [data-hv-ground=orange]{--hv-ring:\" + HV_BLACK + \"}\" +\n  \".hv-scope[data-hv-ground=bone],.hv-scope [data-hv-ground=bone]{--hv-ring:\" + HV_BLACK + \"}\" +\n  \".hv-scope :focus-visible{outline:2px solid var(--hv-ring)!important;outline-offset:3px!important}\" +\n  \".hv-scope .hv-num{font-variant-numeric:tabular-nums}\" +\n  \".hv-scope [data-hv-live]{transition:none!important}\" +\n  \".hv-scope .hv-press{transition:transform 160ms cubic-bezier(.2,.8,.2,1),background-color 160ms,color 160ms}\" +\n  \".hv-scope .hv-press:active{transform:scale(.97)}\" +\n  \".hv-scope .hv-arr{transition:transform 220ms cubic-bezier(.2,.8,.2,1)}.hv-scope a:hover .hv-arr,.hv-scope button:hover .hv-arr{transform:translateX(3px)}\" +\n  \"@media (prefers-reduced-motion:reduce){.hv-scope .hv-press,.hv-scope .hv-arr{transition:none}}\";\n\n/** The kit's arrow: slides on hover. */\nfunction HvArrow({ size = 14 }: { size?: number }) {\n  return (\n    <svg className=\"hv-arr\" width={size} height={size} viewBox=\"0 0 14 14\" aria-hidden>\n      <path d=\"M2 7h9M7.5 3.5L11 7l-3.5 3.5\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"square\" />\n    </svg>\n  );\n}\n\n/** Ardent's mark: a shock diamond, the bright knot in a rocket plume. Takes the current colour. */\nfunction HvMark({ size = 22 }: { size?: number }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 24 24\" aria-hidden>\n      <path d=\"M12 1.5 L19 12 L12 22.5 L5 12 Z\" fill=\"currentColor\" />\n      <path d=\"M12 7.2 L15.2 12 L12 16.8 L8.8 12 Z\" fill=\"var(--hv-mark-cut, #0B0A09)\" />\n    </svg>\n  );\n}\n\n/** Ink for each ground: text, the CTA's fill and its label. */\nconst NV_INK: Record<HvGround, { ink: string; cta: string; ctaInk: string; mark: string }> = {\n  black: { ink: HV_BONE, cta: HV_ORANGE, ctaInk: HV_BLACK, mark: HV_HOT },\n  orange: { ink: HV_BLACK, cta: HV_BLACK, ctaInk: HV_ORANGE, mark: HV_BLACK },\n  bone: { ink: HV_BLACK, cta: HV_ORANGE, ctaInk: HV_BLACK, mark: HV_ORANGE },\n};\n\n/** The bar fills with its ground once the page has scrolled, so nothing passes behind the links. */\nconst NV_GROUND: Record<HvGround, string> = { black: HV_BLACK, orange: HV_ORANGE, bone: HV_BONE };\n\nconst NV_CSS =\n  \".hv-nv{transition:color 220ms,background-color 220ms,height 260ms cubic-bezier(.2,.8,.2,1),box-shadow 220ms}\" +\n  \".hv-nv a,.hv-nv button{transition:color 220ms,background-color 220ms}\" +\n  \".hv-nv-link{position:relative;text-decoration:none}\" +\n  \".hv-nv-link::after{content:'';position:absolute;left:0;right:0;bottom:-5px;height:2px;background:currentColor;transform:scaleX(0);transform-origin:left;transition:transform 220ms cubic-bezier(.2,.8,.2,1)}\" +\n  \".hv-nv-link:hover::after,.hv-nv-link:focus-visible::after{transform:scaleX(1)}\" +\n  \".hv-nv-sheet{transition:clip-path 320ms cubic-bezier(.2,.8,.2,1)}\" +\n  \"@media (prefers-reduced-motion:reduce){.hv-nv,.hv-nv a,.hv-nv button,.hv-nv-sheet,.hv-nv-link::after{transition:none}}\";\n\nexport interface HiVisNavProps {\n  brand?: string;\n  /** \"sticky\" sticks to the top of its scroller; \"static\" leaves placement to you (the Ardent site floats it over the hero). */\n  position?: \"sticky\" | \"static\";\n  /** The ground to assume where no section under the bar carries data-hv-ground. */\n  fallback?: HvGround;\n  links?: { label: string; href: string }[];\n  cta?: { label: string; href: string };\n  className?: string;\n  style?: CSSProperties;\n}\n\n/**\n * HiVisNav — a full-width bar that reads the ground under it.\n */\nexport function HiVisNav({\n  brand = \"Ardent\",\n  links = [\n    { label: \"Engine\", href: \"#engine\" },\n    { label: \"Specs\", href: \"#specs\" },\n    { label: \"Manifest\", href: \"#manifest\" },\n    { label: \"Book\", href: \"#book\" },\n  ],\n  cta = { label: \"Book a slot\", href: \"#book\" },\n  position = \"sticky\",\n  fallback = \"black\",\n  className = \"\",\n  style,\n}: HiVisNavProps) {\n  const ref = useRef<HTMLElement>(null);\n  const [ground, setGround] = useState<HvGround>(fallback);\n  const [compact, setCompact] = useState(false);\n  const [open, setOpen] = useState(false);\n  const sheetId = useId();\n  const menuRef = useRef<HTMLButtonElement>(null);\n\n  // Which ground is under the bar: whatever the page shows at the bar's centre line, not the bar itself.\n  useHvScrollFrame(ref, () => {\n    const nav = ref.current;\n    if (!nav) return;\n    const r = nav.getBoundingClientRect();\n    const y = r.top + r.height / 2;\n    let g: HvGround = fallback;\n    for (const el of document.elementsFromPoint(r.left + r.width * 0.5, y)) {\n      if (nav.contains(el)) continue;\n      const host = el.closest<HTMLElement>(\"[data-hv-ground]\");\n      const v = host?.dataset.hvGround;\n      if (v === \"black\" || v === \"orange\" || v === \"bone\") {\n        g = v;\n        break;\n      }\n    }\n    setGround(g);\n    const sp = hvScrollParent(nav);\n    const top = sp ? sp.scrollTop : window.scrollY;\n    setCompact(top > 80);\n  });\n\n  // A section can change its ground after the scroll has stopped (the Ignition Hero's flood eases in), so listen for that too.\n  useEffect(() => {\n    const nav = ref.current;\n    if (!nav || typeof MutationObserver === \"undefined\") return;\n    let raf = 0;\n    const read = () => {\n      raf = 0;\n      const r = nav.getBoundingClientRect();\n      for (const el of document.elementsFromPoint(r.left + r.width * 0.5, r.top + r.height / 2)) {\n        if (nav.contains(el)) continue;\n        const v = el.closest<HTMLElement>(\"[data-hv-ground]\")?.dataset.hvGround;\n        if (v === \"black\" || v === \"orange\" || v === \"bone\") {\n          setGround(v);\n          return;\n        }\n      }\n    };\n    const mo = new MutationObserver(() => {\n      if (!raf) raf = requestAnimationFrame(read);\n    });\n    mo.observe(nav.closest(\"[data-hv-site]\") ?? document.body, { subtree: true, attributes: true, attributeFilter: [\"data-hv-ground\"] });\n    return () => {\n      mo.disconnect();\n      if (raf) cancelAnimationFrame(raf);\n    };\n  }, []);\n\n  useEffect(() => {\n    if (!open) return;\n    const key = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") {\n        setOpen(false);\n        menuRef.current?.focus();\n      }\n    };\n    document.addEventListener(\"keydown\", key);\n    return () => document.removeEventListener(\"keydown\", key);\n  }, [open]);\n\n  const c = NV_INK[ground];\n  const go = (e: { currentTarget: HTMLAnchorElement; preventDefault: () => void }) => {\n    setOpen(false);\n    hvGo(e);\n  };\n  return (\n    <nav\n      ref={ref}\n      aria-label=\"Main\"\n      data-hv-ground={ground}\n      className={\"hv-scope hv-nv @container w-full \" + (position === \"sticky\" ? \"sticky top-0 z-50 \" : \"relative \") + className}\n      style={{ color: c.ink, background: compact || open ? NV_GROUND[ground] : \"transparent\", height: compact ? 52 : 68, fontFamily: HV_DISPLAY, boxShadow: compact ? \"inset 0 -1px 0 color-mix(in oklab, currentColor 18%, transparent)\" : \"none\", ...style }}\n    >\n      <style>{HV_CSS + NV_CSS}</style>\n      <div className=\"flex h-full w-full items-center justify-between gap-6 px-5 @3xl:px-[3cqw]\">\n        <a href=\"#top\" onClick={go} className=\"flex items-center gap-2.5 no-underline\" style={{ color: \"inherit\", \"--hv-mark-cut\": ground === \"orange\" ? HV_ORANGE : ground === \"bone\" ? HV_BONE : HV_BLACK } as CSSProperties}>\n          <span style={{ color: c.mark }}>\n            <HvMark size={20} />\n          </span>\n          <span className=\"text-[19px] uppercase leading-none tracking-[0.02em]\" style={{ fontWeight: 850, fontVariationSettings: '\"wdth\" 112' }}>\n            {brand}\n          </span>\n        </a>\n        <ul className=\"m-0 hidden list-none items-center gap-8 p-0 @3xl:flex\">\n          {links.map((l) => (\n            <li key={l.label}>\n              <a href={hvSafeHref(l.href)} onClick={go} className=\"hv-nv-link text-[12px] font-medium uppercase tracking-[0.14em]\" style={{ color: \"inherit\", fontFamily: HV_MONO }}>\n                {l.label}\n              </a>\n            </li>\n          ))}\n        </ul>\n        <div className=\"flex items-center gap-2\">\n          <a\n            href={hvSafeHref(cta.href)}\n            onClick={go}\n            className=\"hv-press hidden h-10 items-center gap-2 px-4 text-[13px] font-bold uppercase tracking-[0.06em] no-underline @md:inline-flex\"\n            style={{ background: c.cta, color: c.ctaInk }}\n          >\n            {cta.label}\n            <HvArrow size={12} />\n          </a>\n          <button\n            ref={menuRef}\n            type=\"button\"\n            aria-expanded={open}\n            aria-controls={sheetId}\n            aria-label={open ? \"Close menu\" : \"Open menu\"}\n            onClick={() => setOpen((o) => !o)}\n            className=\"hv-press inline-flex h-10 w-10 items-center justify-center border-0 @3xl:hidden\"\n            style={{ background: \"transparent\", color: \"inherit\", boxShadow: \"inset 0 0 0 1.5px currentColor\" }}\n          >\n            <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" aria-hidden>\n              {open ? <path d=\"M3 3l10 10M13 3L3 13\" stroke=\"currentColor\" strokeWidth=\"2\" /> : <path d=\"M2 5h12M2 11h12\" stroke=\"currentColor\" strokeWidth=\"2\" />}\n            </svg>\n          </button>\n        </div>\n      </div>\n      <div\n        id={sheetId}\n        className=\"hv-nv-sheet absolute inset-x-0 top-full z-10 @3xl:hidden\"\n        style={{ background: ground === \"black\" ? HV_ORANGE : HV_BLACK, color: ground === \"black\" ? HV_BLACK : HV_ORANGE, clipPath: open ? \"inset(0 0 0 0)\" : \"inset(0 0 100% 0)\", visibility: open ? \"visible\" : \"hidden\" }}\n      >\n        <ul className=\"m-0 flex list-none flex-col p-0 px-5 py-4\">\n          {links.map((l) => (\n            <li key={l.label} style={{ boxShadow: \"inset 0 -1px 0 color-mix(in oklab, currentColor 22%, transparent)\" }}>\n              <a href={hvSafeHref(l.href)} onClick={go} className=\"flex items-center justify-between py-3 text-[34px] uppercase leading-none no-underline\" style={{ color: \"inherit\", fontWeight: 900, fontVariationSettings: '\"wdth\" 70' }}>\n                {l.label}\n                <HvArrow size={18} />\n              </a>\n            </li>\n          ))}\n          <li className=\"pt-4\">\n            <a href={hvSafeHref(cta.href)} onClick={go} className=\"hv-press inline-flex h-12 w-full items-center justify-center gap-2 text-[14px] font-bold uppercase tracking-[0.06em] no-underline\" style={{ background: ground === \"black\" ? HV_BLACK : HV_ORANGE, color: ground === \"black\" ? HV_ORANGE : HV_BLACK }}>\n              {cta.label}\n              <HvArrow />\n            </a>\n          </li>\n        </ul>\n      </div>\n    </nav>\n  );\n}\n","type":"registry:component","target":"components/viberdy/hi-vis-nav.tsx"}],"meta":{"tier":"free","tags":["navbar","navigation","header","sticky","adaptive color","mobile menu","orange"],"href":"https://viberdy.dev/library/hi-vis-nav","aiPrompt":"Build HiVisNav, a full-width bar that reads the ground under it. Style: Hi-Vis. Fixed palette, no theming: safety orange #FF5B14 as a flat field (black on it is 6.3:1; dim text on orange stays at 75%+ black), hot orange #FF7A1A for marks on black, warm black #0B0A09, bone #EFEBE4. Type: Archivo variable (wght 100-900, wdth 62-125) loaded with its wdth axis (next/font: Archivo({ subsets: [\"latin\"], axes: [\"wdth\"], variable: \"--font-hv\" })) and read as var(--font-hv, \"Archivo\"), display at weight 850-900, wdth 62-80, uppercase, line-height 0.84-0.9; Geist Mono (var(--font-hv-mono)) for labels at 11-12.5px, uppercase, tracking 0.12-0.16em. Square corners everywhere. Every section root carries data-hv-ground=\"black\" | \"orange\" | \"bone\". One focus ring: 2px solid, offset 3px, hot orange on black and black on orange or bone. Scroll-told parts are driven by one number p (0..1) that chases the measured scroll with v += (target - v) * 0.16 per frame, written straight to the DOM (no React state per frame); a capture-phase scroll listener on document hears any scroller, so it works on a page and inside a scrolling box. Reduced motion shows the settled end state. Links go through a safe-href helper (https, http, mailto, same-site paths and anchors only; backslashes refused). React 19, Tailwind v4 with container queries (@container on the root, @3xl = 768px for the desktop layout). No three.js, no images.\n\nOn each scroll frame the bar calls document.elementsFromPoint at its centre line, skips its own elements and reads the nearest [data-hv-ground] (\"black\" | \"orange\" | \"bone\"), so it follows sections that change colour mid-scroll. Inks: on black, bone text, a #FF7A1A mark and an orange CTA with black text; on orange, black text and a black CTA with orange text; on bone, black text and an orange CTA. Height 68px, tightening to 52px after 80px of scroll, when it also fills with its ground colour and draws a 1px hairline (18% ink) so nothing passes behind the links; 220-260ms transitions. Left: a shock-diamond mark (a rhombus with a rhombus cut) and the brand at 19px weight 850 wdth 112. Centre (desktop): mono 12px uppercase links with a 2px underline that grows from the left on hover. Right: CTA \"Book a slot\" (40px) and, under 768px, a 40px outlined menu button that opens a full-width sheet (clip-path inset reveal, 320ms) of 34px weight 900 wdth 70 links and a full-width CTA; Escape closes it. Same-page links glide to [data-hv-anchor] targets. position \"sticky\" (default) makes it sticky top-0 itself; \"static\" leaves placement to the page. fallback is the ground assumed where nothing under the bar is tagged. Props: brand, links, cta, position, fallback.","license":"https://viberdy.dev/license"}}