{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"heat-haze-heading","type":"registry:component","title":"Heat Haze Heading","description":"A line of type set edge to edge and seen through rising heat: an SVG turbulence field moves up through the letters, and the pointer turns the heat up.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/heat-haze-heading.tsx","content":"\"use client\";\n\nimport { useEffect, useId, useLayoutEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport type { CSSProperties } from \"react\";\n\n\n/** Safety orange as a field colour. Black on it reads at 6.3:1. */\nconst HV_ORANGE = \"#FF5B14\";\n\nconst HV_BLACK = \"#0B0A09\";\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\nconst hvClamp = (v: number, a = 0, b = 1) => (v < a ? a : v > b ? b : v);\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\nexport interface HeatHazeHeadingProps {\n  text?: string;\n  /** Heading level for the page outline. */\n  as?: \"h1\" | \"h2\" | \"h3\" | \"p\";\n  /** The ground it sits on: orange type on black, or black type on orange. */\n  ground?: \"black\" | \"orange\";\n  /** How hard the air shimmers at rest, 0..1. The pointer adds more where it is. */\n  intensity?: number;\n  /** Width axis, 62 (condensed) to 125 (wide). */\n  width?: number;\n  className?: string;\n  style?: CSSProperties;\n}\n\n/**\n * HeatHazeHeading — a line of type that sits in rising heat.\n *\n * The type is SVG text fitted to its box (the viewBox is the text's own\n * bounds, so it always runs edge to edge). An SVG filter pushes it through a\n * turbulence field, and that field rises: the filtered group is moved up\n * every frame while the text inside is moved back down, so the text stays\n * put and only the air moves through it. The pointer turns the heat up.\n * Reduced motion: crisp, still type.\n */\nexport function HeatHazeHeading({ text = \"Ardent\", as: Tag = \"h2\", ground = \"black\", intensity = 0.5, width = 72, className = \"\", style }: HeatHazeHeadingProps) {\n  const id = useId().replace(/:/g, \"\");\n  const svgRef = useRef<SVGSVGElement>(null);\n  const textRef = useRef<SVGTextElement>(null);\n  const gRef = useRef<SVGGElement>(null);\n  const filterRef = useRef<SVGFilterElement>(null);\n  const mapRef = useRef<SVGFEDisplacementMapElement>(null);\n  // A first guess at the text's bounds (cap height ~145 of 200, ~0.62em per letter at wdth 100), replaced once measured.\n  const [box, setBox] = useState<[number, number, number, number]>(() => [0, -146, Math.max(1, text.length) * 124 * (hvClamp(width, 62, 125) / 100), 148]);\n  const boxRef = useRef(box);\n  useEffect(() => {\n    boxRef.current = box;\n  }, [box]);\n  const reduced = useHvReduced();\n  const live = useRef({ intensity, heat: 0, ptr: 0 });\n  useEffect(() => {\n    live.current.intensity = intensity;\n  });\n\n  // Fit the viewBox to the text's own bounds, again once the face has loaded.\n  useLayoutEffect(() => {\n    const t = textRef.current;\n    if (!t) return;\n    let alive = true;\n    const fit = () => {\n      if (!alive) return;\n      try {\n        const b = t.getBBox();\n        if (b.width > 0) setBox([b.x, b.y, b.width, b.height]);\n      } catch {\n        // not rendered yet\n      }\n    };\n    fit();\n    document.fonts?.ready.then(fit);\n    return () => {\n      alive = false;\n    };\n  }, [text, width]);\n\n  useEffect(() => {\n    const svg = svgRef.current;\n    const g = gRef.current;\n    const t = textRef.current;\n    const f = filterRef.current;\n    const map = mapRef.current;\n    if (!svg || !g || !t || !f || !map) return;\n    if (reduced) {\n      map.setAttribute(\"scale\", \"0\");\n      g.removeAttribute(\"transform\");\n      t.removeAttribute(\"transform\");\n      return;\n    }\n    let raf = 0;\n    let on = false;\n    let last = 0;\n    let rise = 0;\n    const L = live.current;\n    const frame = (now: number) => {\n      raf = 0;\n      if (!on) return;\n      if (last && now - last < 30) {\n        raf = requestAnimationFrame(frame);\n        return;\n      }\n      const dt = last ? Math.min(0.06, (now - last) / 1000) : 0;\n      last = now;\n      const [, by, , bh] = boxRef.current;\n      // The air rises a little under one line height a second.\n      rise += dt * bh * 0.55;\n      L.heat += (L.ptr - L.heat) * Math.min(1, dt * 4);\n      g.setAttribute(\"transform\", \"translate(0 \" + (-rise).toFixed(2) + \")\");\n      t.setAttribute(\"transform\", \"translate(0 \" + rise.toFixed(2) + \")\");\n      f.setAttribute(\"y\", (by - bh * 0.3 + rise).toFixed(2));\n      map.setAttribute(\"scale\", (bh * (0.01 * hvClamp(L.intensity * 4) + 0.032 * hvClamp(L.intensity) + 0.06 * L.heat)).toFixed(2));\n      raf = requestAnimationFrame(frame);\n    };\n    const io = new IntersectionObserver((es) => {\n      on = !!es[es.length - 1]?.isIntersecting;\n      last = 0;\n      if (on && !raf) raf = requestAnimationFrame(frame);\n    });\n    io.observe(svg);\n    const move = (e: PointerEvent) => {\n      const r = svg.getBoundingClientRect();\n      const dx = (e.clientX - hvClamp(e.clientX, r.left, r.right)) / Math.max(1, r.height);\n      const dy = (e.clientY - hvClamp(e.clientY, r.top, r.bottom)) / Math.max(1, r.height);\n      L.ptr = Math.exp(-(dx * dx + dy * dy) * 3);\n    };\n    const leave = () => {\n      L.ptr = 0;\n    };\n    window.addEventListener(\"pointermove\", move, { passive: true });\n    document.documentElement.addEventListener(\"pointerleave\", leave);\n    return () => {\n      on = false;\n      if (raf) cancelAnimationFrame(raf);\n      io.disconnect();\n      window.removeEventListener(\"pointermove\", move);\n      document.documentElement.removeEventListener(\"pointerleave\", leave);\n    };\n  }, [reduced]);\n\n  const [bx, by, bw, bh] = box;\n  const fill = ground === \"black\" ? HV_ORANGE : HV_BLACK;\n  const base = ground === \"black\" ? \"#FF9A4D\" : \"#3A1200\";\n  return (\n    <Tag className={\"hv-scope m-0 w-full \" + className} style={{ fontFamily: HV_DISPLAY, ...style }}>\n      <span className=\"sr-only\">{text}</span>\n      <svg ref={svgRef} aria-hidden viewBox={bx + \" \" + (by - bh * 0.06) + \" \" + bw + \" \" + bh * 1.12} className=\"block h-auto w-full overflow-visible\" preserveAspectRatio=\"xMidYMid meet\">\n        <defs>\n          <linearGradient id={id + \"g\"} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n            <stop offset=\"0\" stopColor={fill} />\n            <stop offset=\"0.84\" stopColor={fill} />\n            <stop offset=\"1\" stopColor={base} />\n          </linearGradient>\n          <filter ref={filterRef} id={id + \"f\"} filterUnits=\"userSpaceOnUse\" primitiveUnits=\"userSpaceOnUse\" x={bx - bh * 0.3} y={by - bh * 0.3} width={bw + bh * 0.6} height={bh * 1.6} colorInterpolationFilters=\"sRGB\">\n            <feTurbulence type=\"fractalNoise\" baseFrequency={(1.4 / bh).toFixed(5) + \" \" + (5.2 / bh).toFixed(5)} numOctaves={2} seed={7} result=\"air\" />\n            <feDisplacementMap ref={mapRef} in=\"SourceGraphic\" in2=\"air\" scale={reduced ? 0 : bh * 0.06} xChannelSelector=\"R\" yChannelSelector=\"G\" />\n          </filter>\n        </defs>\n        <g ref={gRef} filter={\"url(#\" + id + \"f)\"}>\n          <text\n            ref={textRef}\n            x=\"0\"\n            y=\"0\"\n            fill={\"url(#\" + id + \"g)\"}\n            style={{ fontFamily: HV_DISPLAY, fontWeight: 900, fontSize: 200, letterSpacing: \"-0.02em\", textTransform: \"uppercase\", fontVariationSettings: '\"wdth\" ' + hvClamp(width, 62, 125) }}\n          >\n            {text}\n          </text>\n        </g>\n      </svg>\n    </Tag>\n  );\n}\n","type":"registry:component","target":"components/viberdy/heat-haze-heading.tsx"}],"meta":{"tier":"free","tags":["text effect","svg filter","heat","distortion","displacement","wordmark","orange","headline"],"href":"https://viberdy.dev/library/heat-haze-heading","aiPrompt":"Build HeatHazeHeading, a line of type seen through rising heat. 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\nThe word is SVG text (weight 900, font-size 200 user units, uppercase, tracking -0.02em, wdth prop 62-125) whose viewBox is the text's own getBBox (refit when fonts load), so it always spans the full width; a vertical gradient fill keeps the colour (orange on black, black on orange) down to 72% and warms to #FFC27A (or #5A1A00) at the foot. An SVG filter in userSpaceOnUse: feTurbulence fractalNoise, baseFrequency (1.4 / textHeight, 5.2 / textHeight), 2 octaves, then feDisplacementMap on the R and G channels. The rising air is a coordinate-space trick: every frame the filtered group is translated up by rise and the text inside it down by rise (rise += dt x 0.55 x text height), and the filter region's y follows, so the turbulence flows upward through type that stays put. Displacement scale = text height x (0.015 + 0.05 intensity + 0.08 heat), heat easing toward exp(-3 d^2) of the pointer's distance from the box (in box heights). Runs only while on screen; reduced motion sets the scale to 0. The visible SVG is aria-hidden and the heading holds the text as sr-only. Props: text, as (h1/h2/h3/p), ground, intensity, width.","license":"https://viberdy.dev/license"}}