{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"veil-resolve-heading","type":"registry:component","title":"Veil Resolve Heading","description":"A serif heading that arrives out of soft light: each word condenses from a blur into focus with an 80ms stagger while a glow blooms behind the words and fades as they sharpen.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/veil-resolve-heading.tsx","content":"\"use client\";\n\nimport { createContext, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from \"react\";\nimport type { CSSProperties, RefObject } from \"react\";\n\n/**\n * VeilResolveHeading — a serif heading that arrives out of soft light.\n *\n * When it scrolls into view each word condenses from a blur into focus,\n * rising a hair as it sharpens, with an 80ms stagger, while a soft glow\n * blooms behind the words and fades once they are sharp. It plays once.\n * Line breaks stack it and *asterisks* set words in italic; punctuation\n * stays with its word. The words are real text throughout; without script\n * or under reduced motion it is simply there.\n *\n * Part of the Diffused Glow kit: a warm bone day (#f6f1e6) and a jade room\n * (#0b120f); soft, grained halos in gold, rose or jade (or any #rrggbb), at\n * most two per view; a serif through var(--font-serif) over Geist. Respects\n * prefers-reduced-motion. No dependencies beyond React. Paste it as its own\n * file: it repeats the kit's small helpers, which would clash in one module.\n * For the serif, load Fraunces with next/font (variable: \"--font-serif\") on a parent.\n */\n\nconst SERIF = 'var(--font-serif, \"Fraunces\", \"Iowan Old Style\", \"Palatino Linotype\", Georgia, serif)';\n\nconst EASE = \"cubic-bezier(0.22, 1, 0.36, 1)\";\n\nconst RESOLVE = \"cubic-bezier(0.16, 1, 0.3, 1)\";\n\nconst HEX = /^#[0-9a-fA-F]{6}$/;\n\n/** The two grounds the kit is set on: the warm day and the jade room. */\nconst TONES = {\n  day: {\n    ground: \"#f6f1e6\",\n    panel: \"#efe7d6\",\n    raised: \"#fbf8f1\",\n    ink: \"rgba(34,31,26,0.92)\",\n    ink2: \"rgba(34,31,26,0.58)\",\n    ink3: \"rgba(34,31,26,0.4)\",\n    line: \"rgba(34,31,26,0.09)\",\n    line2: \"rgba(34,31,26,0.18)\",\n    shadow: \"0 30px 80px -20px rgba(40,30,10,0.14)\",\n  },\n  jewel: {\n    ground: \"#0b120f\",\n    panel: \"#101c17\",\n    raised: \"#16261f\",\n    ink: \"rgba(243,237,226,0.94)\",\n    ink2: \"rgba(243,237,226,0.63)\",\n    ink3: \"rgba(243,237,226,0.4)\",\n    line: \"rgba(243,237,226,0.08)\",\n    line2: \"rgba(243,237,226,0.16)\",\n    shadow: \"0 40px 100px -24px rgba(0,0,0,0.5)\",\n  },\n} as const;\n\nexport type DgTone = keyof typeof TONES;\n\n/** Halo colours. Gold and rose belong to the jade room; jade is the day's own light. */\nexport const DG_GLOWS = {\n  gold: \"#f5c48c\",\n  rose: \"#f2a39a\",\n  jade: \"#bcd9c8\",\n} as const;\n\nfunction own<T extends object>(map: T, key: string): key is Extract<keyof T, string> {\n  return Object.prototype.hasOwnProperty.call(map, key);\n}\n\n/** A named glow or a #rrggbb; anything else falls back to gold. */\nfunction glowHex(value: string): string {\n  if (own(DG_GLOWS, value)) return DG_GLOWS[value];\n  return HEX.test(value) ? value : DG_GLOWS.gold;\n}\n\nfunction toneOf(value: string) {\n  return own(TONES, value) ? TONES[value] : TONES.day;\n}\n\nfunction rgbOf(hex: string): [number, number, number] {\n  const n = parseInt(hex.slice(1), 16);\n  return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n}\n\nfunction rgba(hex: string, a: number): string {\n  const [r, g, b] = rgbOf(hex);\n  return `rgba(${r},${g},${b},${a})`;\n}\n\n/**\n * Grain as an SVG turbulence tile. It is only ever laid inside a light (masked\n * to the halo's shape), never over the whole page: grain belongs to the glow.\n */\nconst GRAIN_URL = `url(\"data:image/svg+xml,${encodeURIComponent(\n  \"<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='g'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.5  0 0 0 0 0.5  0 0 0 0 0.5  0 0 0 0.9 0'/></filter><rect width='160' height='160' filter='url(#g)'/></svg>\",\n)}\")`;\n\nfunction subscribeMotion(cb: () => void) {\n  const m = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n  m.addEventListener(\"change\", cb);\n  return () => m.removeEventListener(\"change\", cb);\n}\n\n/** True when the visitor asked for reduced motion. False on the server. */\nfunction useReducedMotion(): boolean {\n  return useSyncExternalStore(\n    subscribeMotion,\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\n/** The element that scrolls: null for the window, or the site itself in \"self\" mode. */\nconst ScrollRootContext = createContext<RefObject<HTMLElement | null> | null>(null);\n\nconst VEIL_CSS =\n  \"@keyframes dg-veil{0%{opacity:0;filter:blur(14px);transform:translateY(0.12em)}60%{opacity:1}100%{opacity:1;filter:blur(0);transform:none}}\" +\n  \"@keyframes dg-veil-glow{0%{opacity:0}35%{opacity:1}100%{opacity:0}}\" +\n  \"@media (prefers-reduced-motion: reduce){.dg-veil,.dg-veil-glow{animation:none!important;opacity:1!important;filter:none!important;transform:none!important}.dg-veil-glow{opacity:0!important}}\";\n\ntype Word = { text: string; italic: boolean; line: number; glue: boolean };\n\n/** Words with their line, whether they sit inside *asterisks*, and whether they follow the last word with no space (\"for*.\" keeps its full stop). */\nfunction wordsOf(text: string): Word[] {\n  const out: Word[] = [];\n  text.split(\"\\n\").forEach((line, li) => {\n    let spaced = true;\n    line.split(/(\\*[^*]+\\*)/g).forEach((part) => {\n      const italic = part.startsWith(\"*\") && part.endsWith(\"*\") && part.length > 2;\n      const body = italic ? part.slice(1, -1) : part;\n      body.split(/(\\s+)/).forEach((tok) => {\n        if (!tok) return;\n        if (/^\\s+$/.test(tok)) {\n          spaced = true;\n          return;\n        }\n        out.push({ text: tok, italic, line: li, glue: !spaced && out.length > 0 && out[out.length - 1].line === li });\n        spaced = false;\n      });\n    });\n  });\n  return out;\n}\n\nexport type VeilResolveHeadingProps = {\n  /** Line breaks stack it; *asterisks* set words in italic. */\n  text: string;\n  as?: \"h1\" | \"h2\" | \"h3\" | \"p\";\n  tone?: DgTone;\n  glow?: string;\n  align?: \"left\" | \"center\";\n  className?: string;\n  style?: CSSProperties;\n};\n\n/**\n * A serif heading that arrives out of soft light. When it scrolls into view,\n * each word condenses from a blur into focus, rising a hair as it sharpens,\n * one after another with an 80ms stagger; a soft glow blooms behind the words\n * as they form and fades once they are sharp, as if the light had turned into\n * type. It plays once. The words are real text throughout; without script,\n * or under reduced motion, it is simply there.\n */\nexport function VeilResolveHeading({ text, as: Tag = \"h2\", tone = \"day\", glow, align = \"left\", className, style }: VeilResolveHeadingProps) {\n  const t = toneOf(tone);\n  const light = glowHex(glow ?? (tone === \"jewel\" ? \"gold\" : \"jade\"));\n  const reduced = useReducedMotion();\n  const rootRef = useContext(ScrollRootContext);\n  const ref = useRef<HTMLElement | null>(null);\n  // \"idle\" before script, \"armed\" while waiting out of view, \"play\" once seen.\n  const [phase, setPhase] = useState<\"idle\" | \"armed\" | \"play\">(\"idle\");\n  const words = useMemo(() => wordsOf(text), [text]);\n\n  useEffect(() => {\n    const el = ref.current;\n    if (!el || reduced) return;\n    let armed = false;\n    const io = new IntersectionObserver(\n      (entries) => {\n        const e = entries[entries.length - 1];\n        // 40% of it, or 160px of a tall one: a heading bigger than its frame must still arrive.\n        if (e.isIntersecting && (e.intersectionRatio >= 0.4 || (e.intersectionRect?.height ?? 0) >= 160)) {\n          setPhase(\"play\");\n          io.disconnect();\n        } else if (!armed) {\n          armed = true;\n          setPhase(\"armed\");\n        }\n      },\n      { root: rootRef?.current ?? null, threshold: [0, 0.1, 0.2, 0.3, 0.4, 0.6, 1] },\n    );\n    io.observe(el);\n    return () => io.disconnect();\n  }, [reduced, rootRef, text]);\n\n  return (\n    <Tag\n      ref={(n: HTMLElement | null) => {\n        ref.current = n;\n      }}\n      className={\"dg-scope relative isolate m-0\" + (className ? \" \" + className : \"\")}\n      style={{\n        fontFamily: SERIF,\n        fontWeight: 380,\n        fontSize: \"clamp(38px, 5.6cqw, 76px)\",\n        textWrap: \"balance\",\n        lineHeight: 1.04,\n        letterSpacing: \"-0.012em\",\n        fontVariationSettings: '\"SOFT\" 50',\n        color: t.ink,\n        textAlign: align,\n        ...style,\n      }}\n    >\n      <style>{VEIL_CSS}</style>\n      {/* The light the words condense out of. */}\n      {phase === \"play\" && (\n        <span\n          aria-hidden\n          className=\"dg-veil-glow pointer-events-none absolute -inset-x-[8%] -inset-y-[30%] -z-10\"\n          style={{ animation: `dg-veil-glow ${1100 + words.length * 80}ms ${EASE} both` }}\n        >\n          <span\n            className=\"absolute inset-0\"\n            style={{ background: `radial-gradient(50% 60% at ${align === \"center\" ? \"50%\" : \"30%\"} 50%, ${rgba(light, tone === \"jewel\" ? 0.35 : 0.55)}, ${rgba(light, 0)} 70%)`, filter: \"blur(12px)\" }}\n          />\n          <span\n            className=\"absolute inset-0\"\n            style={{\n              backgroundImage: GRAIN_URL,\n              mixBlendMode: \"overlay\",\n              opacity: 0.55,\n              WebkitMaskImage: `radial-gradient(50% 60% at ${align === \"center\" ? \"50%\" : \"30%\"} 50%, #000, transparent 70%)`,\n              maskImage: `radial-gradient(50% 60% at ${align === \"center\" ? \"50%\" : \"30%\"} 50%, #000, transparent 70%)`,\n            }}\n          />\n        </span>\n      )}\n      {words.map((w, i) => {\n        const br = i > 0 && words[i - 1].line !== w.line;\n        const node = (\n          <span\n            className=\"dg-veil inline-block\"\n            style={\n              phase === \"idle\"\n                ? undefined\n                : phase === \"armed\"\n                  ? { opacity: 0, filter: \"blur(14px)\" }\n                  : { animation: `dg-veil 1100ms ${RESOLVE} ${i * 80}ms both` }\n            }\n          >\n            <span style={{ fontStyle: w.italic ? \"italic\" : undefined, fontWeight: w.italic ? 340 : undefined }}>{w.text}</span>\n          </span>\n        );\n        return (\n          <span key={i}>\n            {br && <br />}\n            {i > 0 && !br && !w.glue ? \" \" : \"\"}\n            {node}\n          </span>\n        );\n      })}\n    </Tag>\n  );\n}\n","type":"registry:component","target":"components/viberdy/veil-resolve-heading.tsx"}],"meta":{"tier":"free","tags":["text","heading","blur","reveal","serif","scroll","glow"],"href":"https://viberdy.dev/library/veil-resolve-heading","aiPrompt":"Build a React + Tailwind heading, `VeilResolveHeading({ text, as, tone, glow, align })`, a serif heading whose words condense out of soft light.\n\nParse the text into words: line breaks stack lines, *asterisk* runs are italic (weight 340), and a token that follows no whitespace glues to the previous word (so '*known for*.' keeps its full stop). Render each word as an inline-block span. State: idle (server and first paint: plain text), armed (script saw it out of view: opacity 0, blur 14px) and play (an IntersectionObserver at 40% visibility, root from a scroll context if one exists): each word runs a 1100ms keyframe from opacity 0, blur(14px) and translateY(0.12em) to sharp, on cubic-bezier(0.16, 1, 0.3, 1), delayed i x 80ms. In play, add an aria-hidden glow behind the words (a blurred radial of the light colour, isolate the heading so it stays behind) that fades in and out over the whole resolve. Serif clamp(38px, 5.6cqw, 76px) (container units, so it sizes to its section and falls back to the viewport) with text-wrap: balance at 380, 1.04 leading. Reduced motion: never armed.\n\nDiffused Glow grammar: two grounds, a warm bone day (#f6f1e6; panels #efe7d6, raised #fbf8f1; ink #221f1a at 92/58/40%; hairlines at 9% and 18%) and a near-black jade room (#0b120f; panels #101c17 and #16261f; ink #f3ede2 at 94/63/40%). Light is soft and grained: halos in gold #f5c48c, rose #f2a39a and, on the day ground, jade #bcd9c8 (or any #rrggbb validated against /^#[0-9a-fA-F]{6}$/), never more than two per view, each a wide gaussian skirt with a warmer core, and the grain lives inside the light (an SVG feTurbulence tile masked to the halo, or noise in the shader), never as a page overlay. In the jade room light is added (screen blend); on the day ground it pools as colour (the paper takes the tint). One bronze accent #c9a15e used as light and one jade fill #2f6f57 kept for the booking action; one filled action per view. A serif (Fraunces by default, through var(--font-serif, \"Fraunces\", Georgia, serif)) at 340-400 for display with 0.98-1.04 leading and *italic* accents, over Geist for UI and Geist Mono uppercase captions. Radii 24-28px on panels, pills for controls; feathered shadows only. Motion is slow: halos breathe on about 10s, drift on 36s or longer and settle toward the pointer over about 900ms (1 - e^(-3dt)); resolves run 700-1100ms out of a blur on cubic-bezier(0.16, 1, 0.3, 1); hovers under 450ms. Keyframes and a focus ring (a .dg-scope rule with border-radius: revert-layer) live in a small static <style> the component renders itself; nothing is interpolated into it. Respect prefers-reduced-motion. No dependencies beyond React.","license":"https://viberdy.dev/license"}}