{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"sundial-shadow-heading","type":"registry:component","title":"Sundial Shadow Heading","description":"A heading whose letters cast soft shadows that swing like a sundial as the page scrolls: the sun crosses with the scroll, the long shadows turn from right to left, and a faint warm band of light slides across the ink.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/sundial-shadow-heading.tsx","content":"\"use client\";\n\nimport { createContext, useContext, useEffect, useRef } from \"react\";\nimport type { CSSProperties, RefObject } from \"react\";\n\n/**\n * SundialShadowHeading — a heading whose letters cast shadows that swing like a sundial.\n *\n * Each letter stands a little off the paper with a tight contact shadow and\n * a long soft one cast by a low sun. As the heading travels through the view\n * the sun crosses the sky, bound to the scroll with no easing: the long\n * shadows swing from falling right, through short, to falling left, and a\n * faint warm band slides across the ink. CSS text-shadow and one gradient.\n *\n * Part of the Modern Minimal kit: a paper-white room (#f5f5f2, surfaces\n * #ffffff, ink #141412) and one light, dawn #ffa64d, only ever as light.\n * Two-layer shadows from one light above; scroll binds values directly,\n * with no easing. Inter Tight through var(--font-inter-tight) for display\n * over Geist. Respects prefers-reduced-motion. No dependencies beyond React.\n * Paste it as its own file: it repeats the kit's small helpers, which would\n * clash in one module. Load Inter Tight with next/font (variable:\n * \"--font-inter-tight\") on a parent, or from Google Fonts or @fontsource.\n */\n\nconst DISPLAY = 'var(--font-inter-tight, \"Inter Tight\", var(--font-sans, \"Geist\"), ui-sans-serif, system-ui, sans-serif)';\n\n/** A paper-white room and one light. */\nconst PAPER = {\n  ground: \"#f5f5f2\",\n  surface: \"#ffffff\",\n  well: \"#ecebe6\",\n  solid: \"#141412\",\n  ink: \"rgba(20,20,18,0.92)\",\n  ink2: \"rgba(20,20,18,0.6)\",\n  ink3: \"rgba(20,20,18,0.38)\",\n  line: \"rgba(20,20,18,0.08)\",\n  line2: \"rgba(20,20,18,0.14)\",\n  dawn: \"#ffa64d\",\n  night: \"#0e0f11\",\n} as const;\n\nfunction clamp(v: number, lo: number, hi: number): number {\n  return v < lo ? lo : v > hi ? hi : v;\n}\n\n/**\n * The element that scrolls: null for the window, or a frame. Every scroll-bound part also takes a\n * `scroller` ref, which wins over this context, so parts pasted as separate files can share one frame.\n */\nexport const ScrollRootContext = createContext<RefObject<HTMLElement | null> | null>(null);\n\n/** Calls `fn` on scroll (of the scroll root or the window) and on resize; returns the cleanup. */\nfunction onScrollOf(root: HTMLElement | null, fn: () => void): () => void {\n  const target: HTMLElement | Window = root ?? window;\n  target.addEventListener(\"scroll\", fn, { passive: true });\n  window.addEventListener(\"resize\", fn);\n  return () => {\n    target.removeEventListener(\"scroll\", fn);\n    window.removeEventListener(\"resize\", fn);\n  };\n}\n\n/** How far an element has come through the view: 0 as its top meets the bottom, 1 as its bottom meets the top. */\nfunction throughView(el: HTMLElement, root: HTMLElement | null): number {\n  const r = el.getBoundingClientRect();\n  const top = root ? root.getBoundingClientRect().top : 0;\n  const h = root ? root.clientHeight : window.innerHeight;\n  return clamp((top + h - r.top) / Math.max(1, h + r.height), 0, 1);\n}\n\n/**\n * Binds a value to scroll with no easing: `read` is called on every scroll\n * and resize (and once at mount) and `apply` writes the result straight to the\n * DOM, so the value moves exactly with the scroll, like scrubbing film.\n */\nfunction useScrollBind(\n  ref: RefObject<HTMLElement | null>,\n  read: (el: HTMLElement, root: HTMLElement | null) => number,\n  apply: (v: number) => void,\n  scroller?: RefObject<HTMLElement | null> | null,\n) {\n  const ctx = useContext(ScrollRootContext);\n  const rootRef = scroller ?? ctx;\n  const readRef = useRef(read);\n  const applyRef = useRef(apply);\n  const runRef = useRef<() => void>(() => undefined);\n  // A render may change what is read (a held progress): apply it then, not only on the next scroll.\n  useEffect(() => {\n    readRef.current = read;\n    applyRef.current = apply;\n    runRef.current();\n  });\n  useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const root = rootRef?.current ?? null;\n    let raf = 0;\n    const run = () => {\n      raf = 0;\n      applyRef.current(readRef.current(el, root));\n    };\n    const onScroll = () => {\n      if (!raf) raf = requestAnimationFrame(run);\n    };\n    run();\n    runRef.current = onScroll;\n    const off = onScrollOf(root, onScroll);\n    return () => {\n      off();\n      cancelAnimationFrame(raf);\n      raf = 0;\n      runRef.current = () => undefined;\n    };\n  }, [ref, rootRef]);\n}\n\n/**\n * SundialShadowHeading — a heading whose letters cast soft shadows that\n * swing like a sundial as the page scrolls.\n *\n * Each letter stands a little off the paper: a tight contact shadow and a\n * long soft one, both cast by a low sun. As the heading travels through the\n * view the sun crosses the sky, bound to the scroll with no easing, so the\n * long shadows swing from falling right (morning) through short (noon) to\n * falling left (evening), and a faint band of warm light slides across the\n * ink with it. A `progress` prop holds the sun at a moment. Real text; CSS\n * text-shadow and one gradient, nothing else. Its default size,\n * clamp(44px, 8cqw, 120px), reads the nearest @container and falls back to\n * the viewport; pass fontSize in `style` for a narrow column.\n */\nexport function SundialShadowHeading({\n  lines = \"Light, / not noise.\",\n  as = \"h2\",\n  progress,\n  depth = 1,\n  scroller,\n  className = \"\",\n  style,\n}: {\n  /** \"/\" breaks a line. */\n  lines?: string;\n  as?: \"h1\" | \"h2\" | \"h3\";\n  /** 0 morning to 1 evening; holds the sun instead of following the scroll. */\n  progress?: number;\n  /** How far the letters stand off the paper (0.5-2). */\n  depth?: number;\n  /** The element that scrolls, when it isn't the window (wins over ScrollRootContext). */\n  scroller?: RefObject<HTMLElement | null>;\n  className?: string;\n  style?: CSSProperties;\n}) {\n  const Tag = as;\n  const ref = useRef<HTMLHeadingElement>(null);\n  const shadowRef = useRef<HTMLSpanElement>(null);\n  const parts = lines.split(\"/\").map((l) => l.trim()).filter(Boolean);\n  const cast = (v: number) => {\n    const el = ref.current;\n    const sh = shadowRef.current;\n    if (!el || !sh) return;\n    const a = (v - 0.5) * Math.PI * 0.8;\n    const len = (6 + 22 * Math.abs(Math.sin(a))) * clamp(depth, 0.5, 2);\n    const dx = -Math.sin(a) * len;\n    const dy = Math.cos(a) * 4 + 3;\n    sh.style.textShadow = `0 1px 0.5px rgba(20,20,18,0.16), ${dx.toFixed(1)}px ${dy.toFixed(1)}px ${(10 + len * 0.45).toFixed(1)}px rgba(20,20,18,${(0.1 + 0.06 * Math.abs(Math.sin(a))).toFixed(3)})`;\n    el.style.setProperty(\"--mm-sun\", `${(100 - v * 100).toFixed(1)}%`);\n  };\n  useScrollBind(\n    ref,\n    (el, root) => (progress !== undefined ? clamp(progress, 0, 1) : throughView(el, root)),\n    cast,\n    scroller,\n  );\n  const text = parts.map((p, i) => (\n    <span key={i} className=\"block\">\n      {p}\n    </span>\n  ));\n  return (\n    <Tag\n      ref={ref}\n      className={\"relative m-0 font-semibold leading-[0.98] \" + className}\n      style={{ fontFamily: DISPLAY, letterSpacing: \"-0.035em\", fontSize: \"clamp(44px, 8cqw, 120px)\", color: PAPER.solid, ...style }}\n    >\n      {/* The shadows live on a copy behind: text-shadow on gradient-clipped type would paint inside the letters. */}\n      <span ref={shadowRef} aria-hidden className=\"pointer-events-none absolute inset-0 select-none\" style={{ color: \"transparent\", textShadow: \"0 1px 0.5px rgba(20,20,18,0.16), 0 7px 13px rgba(20,20,18,0.1)\" }}>\n        {text}\n      </span>\n      <span\n        className=\"relative block\"\n        style={\n          {\n            backgroundImage: `linear-gradient(100deg, ${PAPER.solid} 0%, ${PAPER.solid} calc(var(--mm-sun, 50%) - 14%), #4a3a26 var(--mm-sun, 50%), ${PAPER.solid} calc(var(--mm-sun, 50%) + 14%), ${PAPER.solid} 100%)`,\n            WebkitBackgroundClip: \"text\",\n            backgroundClip: \"text\",\n            WebkitTextFillColor: \"transparent\",\n          } as CSSProperties\n        }\n      >\n        {text}\n      </span>\n    </Tag>\n  );\n}\n","type":"registry:component","target":"components/viberdy/sundial-shadow-heading.tsx"}],"meta":{"tier":"free","tags":["text effect","shadow","scroll","heading","light","css"],"href":"https://viberdy.dev/library/sundial-shadow-heading","aiPrompt":"Build a React + Tailwind heading, `SundialShadowHeading({ lines, as, progress, depth, className, style })`.\n\nRender the lines twice in the heading: an aria-hidden copy behind with transparent colour that carries the shadows, and the visible type on top with a gradient clipped to the text (ink with a faint warm #4a3a26 band 28% wide at var(--mm-sun)). On every scroll (no easing), v = how far the heading has come through the view (or the progress prop); the sun angle a = (v - 0.5) x 0.8 pi; the long shadow's length is (6 + 22 |sin a|) x depth, offset x = -sin(a) x length, y = 4 cos(a) + 3, blur 10 + 0.45 x length, alpha 0.1 + 0.06 |sin a|, after a contact shadow 0 1px 0.5px at 16%; --mm-sun = 100 - v x 100 %. Inter Tight 600 at -0.035em.\n\nModern Minimal grammar: a paper-white room, ground #f5f5f2 (surfaces #ffffff that lift, a recessed well #ecebe6), ink #141412 at 92/60/38% (never grey-400 body copy), hairlines at 8% and 14%; one light, dawn #ffa64d, only ever as light (the lamp's glow, a lit state), never as a fill. Shadows come from one light above in two layers: a contact 0 1px 2px rgba(20,20,18,0.06) and an ambient 0 24px 48px -12px rgba(20,20,18,0.1), both falling the same way; a pressed thing loses the ambient, a lifted one widens it. Type: Inter Tight through var(--font-inter-tight, \"Inter Tight\", ...) for display at 600 with -0.035em tracking and 0.98 leading (tracking tightens only at display sizes), Geist for reading at 16-17px/1.55, Geist Mono uppercase at 11-12px for readouts. Radii 12px controls (pills for buttons), 20px cards, 28px media. Motion: scroll binds values directly with no easing (a value moves exactly with the scroll, like scrubbing film); discrete hover and press states take 150-260ms with a spring back past rest; ambient loops 40s or more. Respect prefers-reduced-motion (ambient scenes hold still; scroll-bound values still follow the scroll, which the visitor drives). No dependencies beyond React.","license":"https://viberdy.dev/license"}}