{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"hazard-tape-marquee","type":"registry:component","title":"Hazard Tape Marquee","description":"Two crossed lengths of hazard tape, safety orange with chevron rails over black with a reflective stripe, pulled along in opposite directions by the page's scroll.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/hazard-tape-marquee.tsx","content":"\"use client\";\n\nimport { useCallback, useEffect, useRef, useSyncExternalStore } 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/** Which ground a section sits on; the nav reads it to pick its ink. */\ntype HvGround = \"black\" | \"orange\" | \"bone\";\n\nfunction hvReducedSub(fn: () => void) {\n  if (typeof window === \"undefined\" || typeof window.matchMedia !== \"function\") return () => {};\n  const mq = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n  mq.addEventListener(\"change\", fn);\n  return () => mq.removeEventListener(\"change\", fn);\n}\n\nconst hvReducedSnap = () => typeof window !== \"undefined\" && typeof window.matchMedia === \"function\" && window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n\n/** True when the reader asked for reduced motion. Live: follows the system setting as it changes. */\nfunction useHvReduced(): boolean {\n  return useSyncExternalStore(hvReducedSub, hvReducedSnap, () => false);\n}\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/**\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\nconst HT_CSS =\n  \".hv-ht-rail{height:9px;background:repeating-linear-gradient(-45deg,\" + HV_BLACK + \" 0 9px,\" + HV_ORANGE + \" 9px 18px)}\" +\n  \".hv-ht-track{display:flex;width:max-content;will-change:transform}\" +\n  \".hv-ht-unit{display:flex;align-items:center;gap:.5em;padding-right:.5em;white-space:nowrap}\" +\n  \".hv-ht-sheen{background:linear-gradient(90deg,#8d8a86 0,#cfccc6 18%,#f6f4ef 24%,#cfccc6 30%,#8d8a86 48%,#8d8a86 100%);background-size:200% 100%}\";\n\nexport interface HazardTapeMarqueeProps {\n  /** The phrase the orange tape repeats. */\n  text?: string;\n  /** The phrase the black tape repeats. */\n  backText?: string;\n  /** The section's ground under the tapes. */\n  ground?: HvGround;\n  /** Tilt of the front tape in degrees (the back tape leans the other way). */\n  angle?: number;\n  /** Pixels of tape per pixel of scroll. */\n  speed?: number;\n  className?: string;\n  style?: CSSProperties;\n}\n\n/**\n * HazardTapeMarquee — two crossed tapes pulled along by the page's scroll.\n */\nexport function HazardTapeMarquee({\n  text = \"Hot fire in progress\",\n  backText = \"Keep clear of the stand\",\n  ground = \"orange\",\n  angle = -4,\n  speed = 0.7,\n  className = \"\",\n  style,\n}: HazardTapeMarqueeProps) {\n  const ref = useRef<HTMLElement>(null);\n  const reduced = useHvReduced();\n  const live = useRef({ scroll: 0, drift: 0, speed });\n  useEffect(() => {\n    live.current.speed = speed;\n  });\n\n  const place = useCallback(() => {\n    const root = ref.current;\n    if (!root) return;\n    const L = live.current;\n    root.querySelectorAll<HTMLElement>(\"[data-ht-track]\").forEach((track, i) => {\n      const unit = track.firstElementChild as HTMLElement | null;\n      const w = unit?.offsetWidth ?? 0;\n      if (!w) return;\n      const dir = i === 0 ? -1 : 1;\n      const x = (L.scroll * L.speed + L.drift) * dir;\n      const m = ((x % w) + w) % w;\n      track.style.transform = \"translate3d(\" + (-m).toFixed(2) + \"px,0,0)\";\n    });\n    const sheen = root.querySelector<HTMLElement>(\"[data-ht-sheen]\");\n    if (sheen) sheen.style.backgroundPosition = (((L.scroll * 0.25) % 200) - 100).toFixed(1) + \"% 0\";\n  }, []);\n\n  // The tapes move with the scroll (both ways, so scrolling back pulls them back).\n  useHvScrollFrame(ref, (f) => {\n    live.current.scroll = f.view.top + f.view.height - f.rect.top;\n    place();\n  });\n\n  // And creep a little on their own, as tape in a draught does. Off under reduced motion.\n  useEffect(() => {\n    if (reduced) return;\n    const root = ref.current;\n    if (!root) return;\n    let raf = 0;\n    let on = false;\n    let last = 0;\n    const tick = (now: number) => {\n      raf = 0;\n      if (!on) return;\n      const dt = last ? Math.min(0.05, (now - last) / 1000) : 0;\n      last = now;\n      live.current.drift += dt * 22;\n      place();\n      raf = requestAnimationFrame(tick);\n    };\n    const io = new IntersectionObserver((es) => {\n      on = !!es[es.length - 1]?.isIntersecting;\n      last = 0;\n      if (on && !raf) raf = requestAnimationFrame(tick);\n    });\n    io.observe(root);\n    return () => {\n      on = false;\n      io.disconnect();\n      if (raf) cancelAnimationFrame(raf);\n    };\n  }, [reduced, place]);\n\n  const bg = ground === \"orange\" ? HV_ORANGE : ground === \"bone\" ? HV_BONE : HV_BLACK;\n  const units = (phrase: string, mark: string) =>\n    Array.from({ length: 8 }, (_, k) => (\n      <span key={k} className=\"hv-ht-unit\" aria-hidden={k > 0 ? true : undefined}>\n        <span>{phrase}</span>\n        <svg width=\"0.62em\" height=\"0.62em\" viewBox=\"0 0 24 24\" aria-hidden style={{ color: mark }}>\n          <path d=\"M12 1.5 L19 12 L12 22.5 L5 12 Z\" fill=\"currentColor\" />\n        </svg>\n      </span>\n    ));\n  return (\n    <section ref={ref} data-hv-ground={ground} aria-label={text} className={\"hv-scope @container relative w-full overflow-hidden \" + className} style={{ background: bg, fontFamily: HV_DISPLAY, height: \"clamp(200px, 26cqw, 320px)\", containerType: \"inline-size\", ...style }}>\n      <style>{HV_CSS + HT_CSS}</style>\n      {/* The back tape: black, a silver reflective stripe whose sheen moves with the scroll. */}\n      <div aria-hidden className=\"absolute left-[-10%] top-1/2 w-[120%]\" style={{ transform: \"translateY(-50%) rotate(\" + -angle * 1.15 + \"deg)\", background: HV_BLACK, color: HV_HOT, boxShadow: \"0 18px 40px -18px rgba(0,0,0,.6)\" }}>\n        <div data-ht-sheen=\"\" data-hv-live=\"\" className=\"hv-ht-sheen h-[5px]\" />\n        <div className=\"overflow-hidden py-2.5\">\n          <div data-ht-track=\"\" data-hv-live=\"\" className=\"hv-ht-track text-[clamp(18px,2.6cqw,30px)] uppercase leading-none tracking-[0.02em]\" style={{ fontWeight: 850, fontVariationSettings: '\"wdth\" 112' }}>\n            {units(backText, HV_ORANGE)}\n          </div>\n        </div>\n        <div className=\"hv-ht-sheen h-[5px]\" style={{ backgroundPosition: \"60% 0\" }} />\n      </div>\n      {/* The front tape: safety orange, chevron rails, black stencil-weight type. */}\n      <div className=\"absolute left-[-10%] top-1/2 w-[120%]\" style={{ transform: \"translateY(-50%) rotate(\" + angle + \"deg)\", background: HV_ORANGE, color: HV_BLACK, boxShadow: \"0 0 0 2px \" + HV_BLACK + \", 0 24px 50px -20px rgba(0,0,0,.55)\" }}>\n        <div className=\"hv-ht-rail\" />\n        <div className=\"overflow-hidden py-3\">\n          <div data-ht-track=\"\" data-hv-live=\"\" className=\"hv-ht-track text-[clamp(30px,5.2cqw,64px)] uppercase leading-none tracking-[-0.01em]\" style={{ fontWeight: 900, fontVariationSettings: '\"wdth\" 68' }}>\n            {units(text, HV_BLACK)}\n          </div>\n        </div>\n        <div className=\"hv-ht-rail\" style={{ backgroundPosition: \"9px 0\" }} />\n      </div>\n    </section>\n  );\n}\n","type":"registry:component","target":"components/viberdy/hazard-tape-marquee.tsx"}],"meta":{"tier":"free","tags":["marquee","ticker","hazard tape","divider","scroll animation","chevron","orange","industrial"],"href":"https://viberdy.dev/library/hazard-tape-marquee","aiPrompt":"Build HazardTapeMarquee, a section divider of two crossed hazard tapes pulled along by the scroll. 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\nSection: overflow hidden, ground prop (orange, black, bone) as its background and data-hv-ground. Front tape: rotated by angle (default -4deg), full bleed (wider than the section, centred), safety orange with a 9px chevron rail top and bottom (repeating-linear-gradient(-45deg, black 0 9px, orange 9px 18px)), the phrase in heavy condensed black uppercase, each repeat followed by a shock-diamond mark. Back tape: tilted the other way, black with orange type, edged by a silver retroreflective stripe (a grey gradient at 200% size whose background-position slides with the scroll). Each tape is a track of eight repeated units moved with translate3d and wrapped by one unit's measured width (offsetWidth), so it never runs out. Position = (the section's distance into the viewport) * speed (default 0.7) + a 22px/s creep; the front moves left, the back right, and scrolling back pulls them back. A capture-phase scroll listener on document hears any scroller; the creep pauses off screen and stops under reduced motion. The section is labelled by the front phrase and the repeats are aria-hidden. Props: text, backText, ground, angle, speed.","license":"https://viberdy.dev/license"}}